Cloudflare Mbt Worker Bundleのロゴ

Cloudflare Mbt Worker Bundle

コミュニティ
mizchi
cloudflare-mbt-worker-bundle

MoonBitのコアコードとTypeScriptのエントリーポイントを組み合わせたCloudflare Workerをバンドルします。wranglerでMoonBit製のJavaScriptモジュールと手書きのTypeScriptを一緒に配布し、FFIを書き換えたうえでビルド後にバンドルを検証する場合に使用します。

Add to TypingMind

概要

公開者mizchi
リポジトリskills
スキル名cloudflare-mbt-worker-bundle
スター
333
フォーク
4
同梱ファイル
6
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 6個の同梱ファイル

    モデルが作業中に読み取れるスクリプト、テンプレート、参考資料です。ファイルは読み取り専用で、実行されることはありません。

  • オープンソース

    mizchiがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Cloudflare Mbt Worker Bundle」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/mizchi/skills/tree/main/cloudflare-mbt-worker-bundle
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/mizchi/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/cloudflare-mbt-worker-bundle .claude/skills/cloudflare-mbt-worker-bundle
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでCloudflare Mbt Worker Bundleを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にCloudflare Mbt Worker Bundleを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Cloudflare Mbt Worker Bundleは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

Cloudflare Workers + MoonBit bundle pipeline

The canonical way to ship a Cloudflare Worker where the bulk of the request handler is MoonBit code (compiled to JS via moon build --target js --release) but the entry shim is hand-written TypeScript.

When to invoke

Use when you're:

  • Setting up a new MoonBit → Cloudflare Workers project.
  • Migrating an existing project from a hand-written dist/worker.mjs shim to wrangler-native TS bundling.
  • Diagnosing a Worker that hangs on the first await after startup (FFI rewrite missed; see references).

Key facts about wrangler + MoonBit

  1. wrangler bundles TS natively. As of wrangler 4.x, main: "src/worker.ts" in wrangler.jsonc is enough — wrangler's built-in esbuild integration transpiles + bundles + emits a single JS file on every wrangler dev / wrangler deploy. No separate tsc emit step is needed for the worker.
  2. MoonBit output is plain ESM JS. moon build --target js --release writes _build/js/release/build/<package>.js. wrangler can import it from a TS entry — no bridging needed except for the side-effect import (the moon module registers globals at module init).
  3. Two MoonBit-specific source rewrites are mandatory. These are not optional and cannot move into TS:
    • moonbitlang$async$internal$event_loop$$reschedule() → the mangled _M0FP...event__loop10reschedule() name. The legacy hook only drains the deque once; the new name re-pumps via setTimeout(0). Without the rewrite, every await past startup hangs.
    • Module-scope random seed → a constant. Workers reject random in module init. Both must happen between moon build and wrangler deploy, applied to the moon JS output. See assets/scripts/prepare-worker.ts.template.

Pipeline shape

clean → db:verify → vite build (if frontend) → moon build → prepare-worker → wrangler deploy
                                                            ↓
                                                            (writes src/_generated/<pkg>-core.js
                                                             with FFI rewrites applied; wrangler's
                                                             esbuild picks it up as part of the src/ tree)

For a project without frontend / FFI rewrites (no MoonBit), the pipeline is even simpler: wrangler deploy against src/worker.ts is sufficient. The starter kit cloudflare-starterkit-mbt ships with a slim version of this.

What's in here

assets/templates/worker.ts.template

A minimal src/worker.ts entry that:

  1. Side-effect imports the prepared moon core (registers globalThis.__appServerFetch).
  2. Imports telemetry + utels wrappers from ./telemetry-runtime.ts.
  3. Exports { fetch, scheduled } for wrangler.

Rename __appServerFetch to match your moon module's register_cloudflare_fetch call.

assets/scripts/prepare-worker.ts.template

The pre-bundle step. Reads moon output, applies the two FFI rewrites with requiredReplace (fails loudly if the target string isn't found — silent no-op was a real production hang), writes to src/_generated/<pkg>-core.js.

assets/scripts/check-worker-bundle.ts

Post-build sanity check on the final bundle. Catches:

  • Stray \x1f control bytes (wasm-host text corruption, sqlc-gen-moonbit #17 family).
  • Bundle too small (moon emitted a stub).
  • Required markers missing (extend REQUIRED_MARKERS per project — e.g. globalThis.__appCronTick for scheduled handlers).

assets/templates/wrangler.jsonc.template

Skeleton with env.staging block, the name/main/compatibility_date shape, and inline comments on where to paste D1 IDs / R2 / Vectorize bindings.

Why this pipeline (over alternatives)

AlternativeTrade-off
Pre-bundle everything to dist/ with tsc + a hand-written worker.mjs shimUsed to be required before wrangler 4 TS support. Adds a separate emit + a shim file to maintain. Drop in favor of wrangler-native bundling unless you have a niche need to inspect dist/.
Use Vite as the bundlerWorks for non-Worker code. For Workers the runtime constraints (no setTimeout > 0, no module-init random, no eval in some paths) need wrangler's awareness. Sticking with wrangler's esbuild is safer.
Drop MoonBit, write the worker fully in TSLoses the typed handler / mars routing / static check guarantees. Use when MoonBit isn't already on the team.

References

Source

The runtime reference is in mizchi/cloudflare-starterkit-mbt. A larger example with the FFI rewrites + editor-assets runtime is in mizchi/mnemo under mnemo-server/.

同梱ファイル

スキルが読み込まれている間、モデルは必要に応じてこれらを読み取ります。読み取り可能なファイルとして提供され、実行されることはありません。

よくある質問

AIスキル「Cloudflare Mbt Worker Bundle」では何ができますか?

MoonBitのコアコードとTypeScriptのエントリーポイントを組み合わせたCloudflare Workerをバンドルします。wranglerでMoonBit製のJavaScriptモジュールと手書きのTypeScriptを一緒に配布し、FFIを書き換えたうえでビルド後にバンドルを検証する場合に使用します。

TypingMindでCloudflare Mbt Worker Bundleを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Cloudflare Mbt Worker Bundleはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにCloudflare Mbt Worker Bundleをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/mizchi/skills/tree/main/cloudflare-mbt-worker-bundleを貼り付けてください。TypingMindがSKILL.mdを読み込み、関連ファイルをまとめて、チャットごとに有効にできるスキルとしてインストールします。

Cloudflare Mbt Worker Bundleを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Cloudflare Mbt Worker Bundleで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもCloudflare Mbt Worker Bundleを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Cloudflare Mbt Worker Bundle」は無料ですか?

mizchiがGitHubで公開しています。ライセンス条件はリポジトリでご確認ください。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇