create-cf-open-agents-api 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +25 -0
  3. package/README.md +96 -0
  4. package/dist/answers.d.ts +30 -0
  5. package/dist/answers.js +83 -0
  6. package/dist/answers.js.map +1 -0
  7. package/dist/cli.d.ts +2 -0
  8. package/dist/cli.js +31 -0
  9. package/dist/cli.js.map +1 -0
  10. package/dist/commands/doctor.d.ts +51 -0
  11. package/dist/commands/doctor.js +26 -0
  12. package/dist/commands/doctor.js.map +1 -0
  13. package/dist/commands/init.d.ts +177 -0
  14. package/dist/commands/init.js +85 -0
  15. package/dist/commands/init.js.map +1 -0
  16. package/dist/commands/setup.d.ts +67 -0
  17. package/dist/commands/setup.js +31 -0
  18. package/dist/commands/setup.js.map +1 -0
  19. package/dist/commands/vendor.d.ts +69 -0
  20. package/dist/commands/vendor.js +37 -0
  21. package/dist/commands/vendor.js.map +1 -0
  22. package/dist/doctor.d.ts +26 -0
  23. package/dist/doctor.js +136 -0
  24. package/dist/doctor.js.map +1 -0
  25. package/dist/exec.d.ts +16 -0
  26. package/dist/exec.js +33 -0
  27. package/dist/exec.js.map +1 -0
  28. package/dist/fs.d.ts +24 -0
  29. package/dist/fs.js +54 -0
  30. package/dist/fs.js.map +1 -0
  31. package/dist/index.d.ts +16 -0
  32. package/dist/index.js +17 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/init.d.ts +37 -0
  35. package/dist/init.js +179 -0
  36. package/dist/init.js.map +1 -0
  37. package/dist/jsonc.d.ts +17 -0
  38. package/dist/jsonc.js +55 -0
  39. package/dist/jsonc.js.map +1 -0
  40. package/dist/plan.d.ts +23 -0
  41. package/dist/plan.js +36 -0
  42. package/dist/plan.js.map +1 -0
  43. package/dist/project.d.ts +62 -0
  44. package/dist/project.js +52 -0
  45. package/dist/project.js.map +1 -0
  46. package/dist/setup.d.ts +26 -0
  47. package/dist/setup.js +139 -0
  48. package/dist/setup.js.map +1 -0
  49. package/dist/steps/agents-file.d.ts +5 -0
  50. package/dist/steps/agents-file.js +19 -0
  51. package/dist/steps/agents-file.js.map +1 -0
  52. package/dist/steps/dev-vars.d.ts +17 -0
  53. package/dist/steps/dev-vars.js +65 -0
  54. package/dist/steps/dev-vars.js.map +1 -0
  55. package/dist/steps/entry.d.ts +7 -0
  56. package/dist/steps/entry.js +36 -0
  57. package/dist/steps/entry.js.map +1 -0
  58. package/dist/steps/gitignore.d.ts +5 -0
  59. package/dist/steps/gitignore.js +20 -0
  60. package/dist/steps/gitignore.js.map +1 -0
  61. package/dist/steps/package-json.d.ts +12 -0
  62. package/dist/steps/package-json.js +45 -0
  63. package/dist/steps/package-json.js.map +1 -0
  64. package/dist/steps/standalone.d.ts +8 -0
  65. package/dist/steps/standalone.js +18 -0
  66. package/dist/steps/standalone.js.map +1 -0
  67. package/dist/steps/tsconfig.d.ts +4 -0
  68. package/dist/steps/tsconfig.js +18 -0
  69. package/dist/steps/tsconfig.js.map +1 -0
  70. package/dist/steps/vendor.d.ts +30 -0
  71. package/dist/steps/vendor.js +158 -0
  72. package/dist/steps/vendor.js.map +1 -0
  73. package/dist/steps/wrangler.d.ts +35 -0
  74. package/dist/steps/wrangler.js +197 -0
  75. package/dist/steps/wrangler.js.map +1 -0
  76. package/dist/templates/agents.d.ts +27 -0
  77. package/dist/templates/agents.js +265 -0
  78. package/dist/templates/agents.js.map +1 -0
  79. package/dist/templates/standalone.d.ts +12 -0
  80. package/dist/templates/standalone.js +44 -0
  81. package/dist/templates/standalone.js.map +1 -0
  82. package/dist/token.d.ts +3 -0
  83. package/dist/token.js +7 -0
  84. package/dist/token.js.map +1 -0
  85. package/dist/ui.d.ts +33 -0
  86. package/dist/ui.js +82 -0
  87. package/dist/ui.js.map +1 -0
  88. package/dist/vendor.d.ts +9 -0
  89. package/dist/vendor.js +14 -0
  90. package/dist/vendor.js.map +1 -0
  91. package/dist/versions.d.ts +30 -0
  92. package/dist/versions.js +33 -0
  93. package/dist/versions.js.map +1 -0
  94. package/package.json +54 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,25 @@
1
+ CF-Open-Agents-API
2
+ Copyright 2026 inaridiy and contributors
3
+
4
+ This project is licensed under Apache-2.0 (see LICENSE).
5
+
6
+ The repository includes development guidance derived from the following projects.
7
+ These files are not included in the npm package. License copies are kept alongside
8
+ each installed skill; skills-lock.json retains installer provenance.
9
+
10
+ Cloudflare skills — https://github.com/cloudflare/skills
11
+ License: Apache-2.0
12
+ Files: .agents/skills/durable-objects/, sandbox-next/,
13
+ workers-best-practices/, wrangler/
14
+ License verified at b052c32bab7dd493513260228a36c88294f343f1.
15
+ These installed copies include adaptations to this project's versions, testing
16
+ guidance and runtime conventions; they are not unmodified upstream releases.
17
+
18
+ Effect-TS skills — https://github.com/Effect-TS/skills
19
+ License: MIT
20
+ Files: .agents/skills/effect-ts/
21
+ License verified at 2309e6f27d9955b434c0e3f394b945c136e89fd2.
22
+ The full copyright and permission notice is retained in that directory's LICENSE.
23
+
24
+ Runtime dependencies are distributed separately under their own package licenses.
25
+ No ownership of upstream trademarks or endorsement by their owners is implied.
package/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # create-cf-open-agents-api
2
+
3
+ Adds the [CF-Open-Agents-API](https://github.com/inaridiy/CF-Open-Agents-API) to a Cloudflare Workers project you already have, or creates a new Worker for it. One run writes the bindings, the composition, the Docker image snapshot and the local secrets; a second command provisions the R2 buckets and production secrets.
4
+
5
+ The library and this CLI are pre-release. Until they are on npm's `latest` tag, run them with the `@alpha` tag and see [Before the packages are published](#before-the-packages-are-published).
6
+
7
+ ## Add the API to an existing Workers project
8
+
9
+ Run it in the directory that holds `wrangler.jsonc` (a Vite + `@cloudflare/vite-plugin` project, a Hono Worker, anything Wrangler deploys):
10
+
11
+ ```sh
12
+ pnpm dlx create-cf-open-agents-api@alpha init
13
+ pnpm install
14
+ pnpm exec wrangler login
15
+ pnpm dev # or: pnpm exec wrangler dev — Docker must be running
16
+ ```
17
+
18
+ `init` asks for the model provider (OpenAI, Anthropic, Workers AI or an OpenAI-compatible endpoint), the native runtimes to expose as presets (Codex, Claude Code, OpenCode), whether to add a Workers AI preset next to your provider and whether to enable programmatic tool calling. `--yes` takes every default. Then it writes, idempotently:
19
+
20
+ | File | Change |
21
+ | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
22
+ | `wrangler.jsonc` | Comments kept. Adds `nodejs_compat` (and `enable_ctx_exports` for a compatibility date before 2025-11-17), the four SQLite Durable Objects and their migration, the two containers built from the snapshot, the `CHECKPOINTS` and `BACKUP_BUCKET` R2 buckets with `vars.BACKUP_BUCKET_NAME`, the `MODEL_GATEWAY` and `AGENTS` self Service Bindings, `CODE_LOADER`, and `ai` for Workers AI |
23
+ | `src/agents.ts` | The composition: presets, the model gateway registry and `defineAgentWorker`. Sits next to your Wrangler entry (`--agents-file` moves it) |
24
+ | your entry (`main`) | One appended line re-exporting `Agents`, `Models`, `SessionDO`, `TenantCatalogDO`, `HarnessDO`, `SandboxDO` and `ContainerProxy`; your default export is untouched |
25
+ | `.cf-open-agents-api/` | The repository snapshot the two Dockerfiles build from (`docker/`, `packages/`, the lockfile). Git-ignored and restored by the `postinstall` hook |
26
+ | `.dev.vars`, `.dev.vars.example` | A random `API_TOKEN` (32+ characters), the provider key line and `LOCAL_BACKUPS=true` for local development |
27
+ | `package.json` | `cf-open-agents-api` with its peers `effect`, `openai`, `ai`, `zod`, the provider package, this CLI as a devDependency and `postinstall: create-cf-open-agents-api vendor`. Other versions you already pinned are kept (`--force` overwrites) |
28
+ | `.gitignore`, `tsconfig.json` | Ignore the snapshot and `.dev.vars`; exclude the snapshot from a broad `include` |
29
+
30
+ Your Worker reaches the API through the `AGENTS` binding, which points at this Worker's `Agents` entrypoint:
31
+
32
+ ```ts
33
+ // Hono, in your entry
34
+ app.all("/v1/*", (c) => c.env.AGENTS.fetch(c.req.raw));
35
+ // or the typed RPC surface
36
+ const session = await c.env.AGENTS.createSession("tenant", {
37
+ agent: { model: "coding" },
38
+ environment: { type: "openai_hosted" },
39
+ });
40
+ ```
41
+
42
+ Binding names are fixed by the library (`SESSIONS`, `CATALOG`, `HARNESS`, `SANDBOX`, `CHECKPOINTS`, `BACKUP_BUCKET`, `MODEL_GATEWAY`, `CODE_LOADER`, `AI`). An existing binding with one of these names but another class stops the run before anything is written. `wrangler.toml` is not supported; convert it to `wrangler.jsonc` first.
43
+
44
+ ## Create a new Worker
45
+
46
+ In an empty directory `init` writes a minimal project (`package.json`, `tsconfig.json`, `wrangler.jsonc`, `src/index.ts` exporting `Agents` as the default export) and then applies the same changes. It is the repository's `examples/worker`, generated. `--public` sets `workers_dev: true`; the default keeps the API private to Service Bindings.
47
+
48
+ ```sh
49
+ mkdir my-agents && cd my-agents
50
+ pnpm dlx create-cf-open-agents-api@alpha init --yes
51
+ pnpm install && pnpm exec wrangler login && pnpm dev
52
+ curl -X POST http://localhost:8787/v1/agents/sessions \
53
+ -H "Authorization: Bearer $(grep ^API_TOKEN= .dev.vars | cut -d= -f2)" \
54
+ -H "Content-Type: application/json" -H "Idempotency-Key: first" \
55
+ -d '{"agent":{"model":"coding"},"environment":{"type":"openai_hosted"},"input":"Write /workspace/outputs/hello.txt"}'
56
+ ```
57
+
58
+ ## Commands
59
+
60
+ | Command | Purpose |
61
+ | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
62
+ | `init [directory]` (default) | Retrofit or create, as above. Flags: `--yes`, `--force`, `--dry-run`, `--dir`, `--name`, `--provider`, `--base-url`, `--model`, `--harnesses codex,claude-code,opencode`, `--workers-ai`, `--no-code-loader`, `--public`, `--agents-file`, `--install`, `--ref`, `--source`, `--library`, `--cli-package` |
63
+ | `setup [directory]` | Production: `wrangler r2 bucket create` for both buckets (existing ones are skipped), then `wrangler secret bulk` with `API_TOKEN`, the provider key, `R2_ACCESS_KEY_ID`, `R2_SECRET_ACCESS_KEY` and `CLOUDFLARE_R2_ACCOUNT_ID` in one call. Values are prompted, or read from the environment with `--from-env`. `--dry-run` prints the commands |
64
+ | `doctor [directory]` | Checks only: Node 24, wrangler, a reachable Docker engine, `wrangler login`, the binding agreement rules (`MODEL_GATEWAY` and `AGENTS` point at this Worker, `BACKUP_BUCKET_NAME` equals the bucket, SQLite migrations, snapshot Dockerfiles), the snapshot version and the `.dev.vars` token length. `--json`, `--offline` |
65
+ | `vendor [directory]` | Refreshes `.cf-open-agents-api/` from the tag matching this CLI's version (`--ref` for another ref, `--source` for a local checkout). The `postinstall` hook runs it; `CF_OPEN_AGENTS_API_SKIP_VENDOR=1` skips it and `CF_OPEN_AGENTS_API_SOURCE` names a checkout |
66
+
67
+ Every command reports what it created, updated and skipped, and explains each decision in Notes. `--dry-run` computes the same plan without writing.
68
+
69
+ ## Production
70
+
71
+ ```sh
72
+ pnpm dlx create-cf-open-agents-api@alpha doctor
73
+ pnpm dlx create-cf-open-agents-api@alpha setup # buckets and secrets
74
+ pnpm exec wrangler deploy # builds and pushes both images; several minutes the first time
75
+ ```
76
+
77
+ Containers need the Workers Paid plan. The R2 API token (`R2_ACCESS_KEY_ID`, `R2_SECRET_ACCESS_KEY`) comes from the Cloudflare dashboard, R2 → Manage R2 API Tokens, with Object Read & Write on the workspaces bucket; `setup` tells you when it needs it. `LOCAL_BACKUPS` stays out of production.
78
+
79
+ ## Before the packages are published
80
+
81
+ `init` pins `cf-open-agents-api` and this CLI to its own version; `pnpm install` needs them on npm. Until then, build both from a checkout and point the CLI at the tarballs:
82
+
83
+ ```sh
84
+ git clone https://github.com/inaridiy/CF-Open-Agents-API.git && cd CF-Open-Agents-API
85
+ pnpm install --frozen-lockfile && pnpm build
86
+ pnpm --filter cf-open-agents-api pack --pack-destination /tmp/cfo
87
+ pnpm --filter create-cf-open-agents-api pack --pack-destination /tmp/cfo
88
+ node packages/create-cf-open-agents-api/dist/cli.js init <your-project> \
89
+ --source "$PWD" --library /tmp/cfo/cf-open-agents-api-0.2.0.tgz --cli-package /tmp/cfo/create-cf-open-agents-api-0.2.0.tgz
90
+ ```
91
+
92
+ `--source` snapshots the checkout instead of downloading a tag archive; `--library` and `--cli-package` write `file:` dependencies.
93
+
94
+ ## Requirements
95
+
96
+ Node 24, a package manager (pnpm, npm, yarn or bun; detected from the lockfile), `tar` on `PATH` for the archive download, Docker for local development and Wrangler 4.131 or newer. Windows is untested. Named Wrangler environments (`env.*`) are neither changed nor checked.
@@ -0,0 +1,30 @@
1
+ import type { Project } from "./project.js";
2
+ import { type Harness, type Provider } from "./templates/agents.js";
3
+ import type { Prompter } from "./ui.js";
4
+ /** Flags that pre-answer questions; anything missing is asked or defaulted. */
5
+ export interface InitPreferences {
6
+ name?: string;
7
+ provider?: Provider;
8
+ baseURL?: string;
9
+ model?: string;
10
+ harnesses?: readonly Harness[];
11
+ workersAi?: boolean;
12
+ codeLoader?: boolean;
13
+ publicRoute?: boolean;
14
+ install?: boolean;
15
+ }
16
+ export interface InitAnswers {
17
+ name: string;
18
+ provider: Provider;
19
+ baseURL?: string;
20
+ model?: string;
21
+ harnesses: Harness[];
22
+ workersAi: boolean;
23
+ codeLoader: boolean;
24
+ publicRoute: boolean;
25
+ install: boolean;
26
+ }
27
+ export declare function parseProvider(value: string): Provider;
28
+ export declare function parseHarnesses(value: string): Harness[];
29
+ /** Asks what the flags left open, in the order a first-time user needs. */
30
+ export declare function collectAnswers(project: Project, configName: string | undefined, preferences: InitPreferences, prompter: Prompter): Promise<InitAnswers>;
@@ -0,0 +1,83 @@
1
+ import { workerNameFrom } from "./project.js";
2
+ import { HARNESSES, PROVIDERS } from "./templates/agents.js";
3
+ const PROVIDER_CHOICES = [
4
+ {
5
+ value: "openai",
6
+ label: "OpenAI",
7
+ hint: "Codex natively, Claude Code and OpenCode through the AI SDK",
8
+ },
9
+ {
10
+ value: "anthropic",
11
+ label: "Anthropic",
12
+ hint: "Claude Code natively, Codex and OpenCode through the AI SDK",
13
+ },
14
+ {
15
+ value: "workers-ai",
16
+ label: "Workers AI",
17
+ hint: "no provider key; billed to your Cloudflare account",
18
+ },
19
+ {
20
+ value: "openai-compatible",
21
+ label: "OpenAI-compatible endpoint",
22
+ hint: "any Chat Completions URL",
23
+ },
24
+ ];
25
+ const HARNESS_CHOICES = [
26
+ { value: "codex", label: "Codex" },
27
+ { value: "claude-code", label: "Claude Code" },
28
+ { value: "opencode", label: "OpenCode" },
29
+ ];
30
+ export function parseProvider(value) {
31
+ if (PROVIDERS.includes(value))
32
+ return value;
33
+ throw new Error(`Unknown provider ${value}; expected one of ${PROVIDERS.join(", ")}`);
34
+ }
35
+ export function parseHarnesses(value) {
36
+ const names = value
37
+ .split(",")
38
+ .map((name) => name.trim())
39
+ .filter(Boolean);
40
+ const unknown = names.find((name) => !HARNESSES.includes(name));
41
+ if (unknown)
42
+ throw new Error(`Unknown harness ${unknown}; expected ${HARNESSES.join(", ")}`);
43
+ return HARNESSES.filter((harness) => names.includes(harness));
44
+ }
45
+ /** Asks what the flags left open, in the order a first-time user needs. */
46
+ export async function collectAnswers(project, configName, preferences, prompter) {
47
+ const name = preferences.name ??
48
+ configName ??
49
+ (await prompter.text("Worker name", workerNameFrom(project.root)));
50
+ const provider = preferences.provider ?? (await prompter.select("Model provider", PROVIDER_CHOICES, "openai"));
51
+ const compatible = provider === "openai-compatible" ? await compatibleAnswers(preferences, prompter) : {};
52
+ const harnesses = preferences.harnesses ??
53
+ (await prompter.multiselect("Native runtimes to expose as presets", HARNESS_CHOICES, HARNESSES));
54
+ const workersAi = provider === "workers-ai"
55
+ ? false
56
+ : (preferences.workersAi ??
57
+ (await prompter.confirm("Also add a Workers AI preset (no provider key, billed to Cloudflare)?", false)));
58
+ const codeLoader = preferences.codeLoader ??
59
+ (await prompter.confirm("Enable programmatic tool calling (Dynamic Workers)?", true));
60
+ const publicRoute = project.mode === "standalone"
61
+ ? (preferences.publicRoute ??
62
+ (await prompter.confirm("Expose the HTTP API on workers.dev? (No = Service Binding only)", false)))
63
+ : false;
64
+ const install = preferences.install ?? (await prompter.confirm("Install dependencies now?", false));
65
+ return {
66
+ name,
67
+ provider,
68
+ ...compatible,
69
+ harnesses: harnesses.length > 0 ? [...harnesses] : [...HARNESSES],
70
+ workersAi,
71
+ codeLoader,
72
+ publicRoute,
73
+ install,
74
+ };
75
+ }
76
+ async function compatibleAnswers(preferences, prompter) {
77
+ return {
78
+ baseURL: preferences.baseURL ??
79
+ (await prompter.text("Chat Completions base URL", "https://api.example.com/v1")),
80
+ model: preferences.model ?? (await prompter.text("Model id", "model")),
81
+ };
82
+ }
83
+ //# sourceMappingURL=answers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"answers.js","sourceRoot":"","sources":["../src/answers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAgB,SAAS,EAAiB,SAAS,EAAE,MAAM,uBAAuB,CAAC;AA4B1F,MAAM,gBAAgB,GAAG;IACvB;QACE,KAAK,EAAE,QAAQ;QACf,KAAK,EAAE,QAAQ;QACf,IAAI,EAAE,6DAA6D;KACpE;IACD;QACE,KAAK,EAAE,WAAW;QAClB,KAAK,EAAE,WAAW;QAClB,IAAI,EAAE,6DAA6D;KACpE;IACD;QACE,KAAK,EAAE,YAAY;QACnB,KAAK,EAAE,YAAY;QACnB,IAAI,EAAE,oDAAoD;KAC3D;IACD;QACE,KAAK,EAAE,mBAAmB;QAC1B,KAAK,EAAE,4BAA4B;QACnC,IAAI,EAAE,0BAA0B;KACjC;CAC6E,CAAC;AACjF,MAAM,eAAe,GAAG;IACtB,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE;IAClC,EAAE,KAAK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QACT,UAAU;QACV,WAAW;QACX,OAAO;KACR,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,iBAAiB,CAC9B,WAA4B,EAC5B,QAAkB;IAElB,OAAO;QACL,OAAO,EACL,WAAW,CAAC,OAAO;YACnB,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,2BAA2B,EAAE,4BAA4B,CAAC,CAAC;QAClF,KAAK,EAAE,WAAW,CAAC,KAAK,IAAI,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;KACvE,CAAC;AACJ,CAAC"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+ import { cli } from "gunshi";
3
+ import { doctorCommand } from "./commands/doctor.js";
4
+ import { initCommand } from "./commands/init.js";
5
+ import { setupCommand } from "./commands/setup.js";
6
+ import { vendorCommand } from "./commands/vendor.js";
7
+ import { CliError } from "./plan.js";
8
+ import { CLI_NAME, CLI_VERSION } from "./versions.js";
9
+ async function main() {
10
+ await cli(process.argv.slice(2), initCommand, {
11
+ name: CLI_NAME,
12
+ version: CLI_VERSION,
13
+ description: "Set up the CF-Open-Agents-API in a Cloudflare Workers project",
14
+ subCommands: {
15
+ init: initCommand,
16
+ setup: setupCommand,
17
+ doctor: doctorCommand,
18
+ vendor: vendorCommand,
19
+ },
20
+ // The commands print their own intro; gunshi's header would repeat it on every run.
21
+ renderHeader: null,
22
+ });
23
+ }
24
+ main().catch((error) => {
25
+ if (error instanceof CliError)
26
+ console.error(`✖ ${error.message}`);
27
+ else
28
+ console.error(error);
29
+ process.exitCode = 1;
30
+ });
31
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEtD,KAAK,UAAU,IAAI;IACjB,MAAM,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE;QAC5C,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,WAAW;QACpB,WAAW,EAAE,+DAA+D;QAC5E,WAAW,EAAE;YACX,IAAI,EAAE,WAAW;YACjB,KAAK,EAAE,YAAY;YACnB,MAAM,EAAE,aAAa;YACrB,MAAM,EAAE,aAAa;SACtB;QACD,oFAAoF;QACpF,YAAY,EAAE,IAAI;KACnB,CAAC,CAAC;AACL,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC9B,IAAI,KAAK,YAAY,QAAQ;QAAE,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;;QAC9D,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC1B,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,51 @@
1
+ export declare const doctorCommand: {
2
+ examples?: string | import("gunshi").CommandExamplesFetcher<import("gunshi").DefaultGunshiParams> | undefined;
3
+ toKebab?: boolean;
4
+ internal?: boolean;
5
+ entry?: boolean;
6
+ rendering?: import("gunshi").RenderingOptions<import("gunshi").DefaultGunshiParams> | undefined;
7
+ subCommands?: Record<string, import("gunshi").SubCommandable> | Map<string, import("gunshi").SubCommandable>;
8
+ name: string;
9
+ description: string;
10
+ args: {
11
+ directory: {
12
+ type: "positional";
13
+ required: false;
14
+ description: string;
15
+ };
16
+ dir: {
17
+ type: "string";
18
+ description: string;
19
+ };
20
+ json: {
21
+ type: "boolean";
22
+ description: string;
23
+ };
24
+ offline: {
25
+ type: "boolean";
26
+ description: string;
27
+ };
28
+ };
29
+ run: (ctx: Readonly<import("gunshi").CommandContext<{
30
+ args: {
31
+ directory: {
32
+ type: "positional";
33
+ required: false;
34
+ description: string;
35
+ };
36
+ dir: {
37
+ type: "string";
38
+ description: string;
39
+ };
40
+ json: {
41
+ type: "boolean";
42
+ description: string;
43
+ };
44
+ offline: {
45
+ type: "boolean";
46
+ description: string;
47
+ };
48
+ };
49
+ extensions: {};
50
+ }>>) => void;
51
+ };
@@ -0,0 +1,26 @@
1
+ import { define } from "gunshi";
2
+ import { renderReport, runDoctor } from "../doctor.js";
3
+ export const doctorCommand = define({
4
+ name: "doctor",
5
+ description: "Check the toolchain, the Wrangler configuration and the local secrets without changing anything",
6
+ args: {
7
+ directory: {
8
+ type: "positional",
9
+ required: false,
10
+ description: "Project directory (default: current directory)",
11
+ },
12
+ dir: { type: "string", description: "Project directory, as an option" },
13
+ json: { type: "boolean", description: "Print the report as JSON" },
14
+ offline: { type: "boolean", description: "Skip the docker and wrangler checks" },
15
+ },
16
+ run: (ctx) => {
17
+ const report = runDoctor({
18
+ dir: ctx.values.dir ?? ctx.values.directory ?? process.cwd(),
19
+ offline: Boolean(ctx.values.offline),
20
+ });
21
+ console.log(ctx.values.json ? JSON.stringify(report, null, 2) : renderReport(report));
22
+ if (!report.ok)
23
+ process.exitCode = 1;
24
+ },
25
+ });
26
+ //# sourceMappingURL=doctor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"doctor.js","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,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