@composable-os/cli 0.0.0-stage → 0.1.0-beta.7

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 (139) hide show
  1. package/LICENSE +109 -0
  2. package/README.md +24 -2
  3. package/dist/blocks-HVTAQ5W2.js +233 -0
  4. package/dist/chunk-2ABSVMGB.js +13 -0
  5. package/dist/chunk-2P4AZTFL.js +358 -0
  6. package/dist/chunk-2S7375SC.js +802 -0
  7. package/dist/chunk-5KSXSK7Y.js +47 -0
  8. package/dist/chunk-6UWRT4VM.js +220 -0
  9. package/dist/chunk-BEKL3CA2.js +28975 -0
  10. package/dist/chunk-E5JLTLRM.js +50 -0
  11. package/dist/chunk-HDIOVFAZ.js +544 -0
  12. package/dist/chunk-KGHA67HG.js +765 -0
  13. package/dist/chunk-MAXLUQKB.js +1287 -0
  14. package/dist/chunk-MINQ46RU.js +16485 -0
  15. package/dist/chunk-STJZJIRA.js +11378 -0
  16. package/dist/chunk-VL62IMBN.js +1423 -0
  17. package/dist/chunk-X6I2LWB3.js +24319 -0
  18. package/dist/chunk-Y7PQ7NIL.js +1178 -0
  19. package/dist/chunk-ZRWF6QZS.js +2357 -0
  20. package/dist/cli-BRSACHSG.js +31393 -0
  21. package/dist/cli-XHC6QBQW.js +121 -0
  22. package/dist/cli.js +25 -0
  23. package/dist/client-repo-G55G4OLV.js +55 -0
  24. package/dist/create.js +25 -0
  25. package/dist/fields-64BQJA62.js +48 -0
  26. package/dist/invoke-5SR5ZWW7.js +26 -0
  27. package/dist/person-AZFEPZOE.js +58 -0
  28. package/dist/platform/migrations/0001_init.sql +59 -0
  29. package/dist/platform/migrations/0002_users_settings.sql +34 -0
  30. package/dist/platform/migrations/0003_people_organisations.sql +225 -0
  31. package/dist/platform/migrations/0004_activities_tasks.sql +88 -0
  32. package/dist/platform/migrations/0005_views_audit.sql +79 -0
  33. package/dist/platform/migrations/0006_search.sql +223 -0
  34. package/dist/platform/migrations/0007_crm_views.sql +141 -0
  35. package/dist/platform/migrations/0008_audit_redaction.sql +116 -0
  36. package/dist/platform/migrations/0010_approval_queue.sql +90 -0
  37. package/dist/platform/migrations/0011_connected_apps.sql +36 -0
  38. package/dist/platform/migrations/0020_extensions.sql +373 -0
  39. package/dist/platform/migrations/0030_extension_proposals.sql +29 -0
  40. package/dist/platform/migrations/0050_live_row_indexes.sql +32 -0
  41. package/dist/platform/migrations/0060_audit_read_counts.sql +31 -0
  42. package/dist/platform/migrations/0061_audit_retention.sql +95 -0
  43. package/dist/platform/migrations/0062_run_history_retention.sql +6 -0
  44. package/dist/platform/migrations/0063_pending_action_compaction.sql +18 -0
  45. package/dist/platform/migrations/0064_drop_rate_limit.sql +6 -0
  46. package/dist/platform/migrations/0065_storage_stats.sql +13 -0
  47. package/dist/platform/migrations/0070_drop_proposals_ext_idx.sql +9 -0
  48. package/dist/platform/migrations/0080_views_dashboards.sql +46 -0
  49. package/dist/platform/migrations/0100_stage_history.sql +54 -0
  50. package/dist/platform/migrations/0110_integrations.sql +103 -0
  51. package/dist/platform/migrations/0111_email_calendar_sync.sql +137 -0
  52. package/dist/platform/migrations/0112_sync_item_occurred_at.sql +8 -0
  53. package/dist/platform/migrations/0130_automations.sql +113 -0
  54. package/dist/platform/migrations/0131_notifications.sql +29 -0
  55. package/dist/platform/migrations/0132_automation_runtime.sql +14 -0
  56. package/dist/platform/migrations/0150_ai_summaries_embeddings.sql +48 -0
  57. package/dist/platform/migrations/0160_releases.sql +41 -0
  58. package/dist/platform/migrations/0161_setup_wizard.sql +30 -0
  59. package/dist/platform/migrations/0170_automation_connections.sql +32 -0
  60. package/dist/platform/migrations/0171_automation_outbox.sql +23 -0
  61. package/dist/platform/migrations/0172_notification_delivery.sql +46 -0
  62. package/dist/platform/migrations/0200_assistant_conversations.sql +25 -0
  63. package/dist/platform/migrations/0205_policy_adjudicator.sql +61 -0
  64. package/dist/platform/migrations/0210_daily_digest.sql +33 -0
  65. package/dist/platform/migrations/0220_entitlements.sql +13 -0
  66. package/dist/platform/migrations/0221_support_grants.sql +33 -0
  67. package/dist/platform/migrations/0250_judge.sql +11 -0
  68. package/dist/platform/migrations/0251_adjudication_judgement.sql +8 -0
  69. package/dist/platform/migrations/0252_judge_usage.sql +14 -0
  70. package/dist/platform/migrations/0255_summary_checks.sql +9 -0
  71. package/dist/platform/migrations/0256_outbound_check.sql +9 -0
  72. package/dist/platform/migrations/0260_ai_usage.sql +20 -0
  73. package/dist/platform/migrations/0270_assistant_conversation_refs.sql +29 -0
  74. package/dist/platform/migrations/0310_assignment_rules.sql +54 -0
  75. package/dist/platform/migrations/0320_duplicates.sql +41 -0
  76. package/dist/platform/migrations/0330_erase_completeness.sql +54 -0
  77. package/dist/platform/migrations/0350_assistant_thread.sql +38 -0
  78. package/dist/platform/migrations/0351_assistant_model_roles.sql +26 -0
  79. package/dist/platform/migrations/0352_assistant_memory.sql +74 -0
  80. package/dist/platform/migrations/0358_ai_cache_observation.sql +24 -0
  81. package/dist/platform/migrations/0359_ai_compaction_decision.sql +25 -0
  82. package/dist/platform/migrations/0360_ai_cache_estimate.sql +35 -0
  83. package/dist/platform/migrations/0361_voice_preferences.sql +27 -0
  84. package/dist/platform/migrations/0362_voice_usage.sql +17 -0
  85. package/dist/platform/migrations/0365_routines.sql +38 -0
  86. package/dist/platform/migrations/0370_approval_execution.sql +20 -0
  87. package/dist/platform/migrations/0371_agent_jobs.sql +65 -0
  88. package/dist/platform/migrations/0380_rec_views.sql +94 -0
  89. package/dist/platform/migrations/0400_customer_audit_actor.sql +142 -0
  90. package/dist/platform/migrations/0401_customer_accounts.sql +61 -0
  91. package/dist/platform/migrations/0402_erase_requests.sql +34 -0
  92. package/dist/platform/migrations/0410_idempotency_keys.sql +45 -0
  93. package/dist/platform/migrations/0411_device_sessions.sql +33 -0
  94. package/dist/platform/migrations/0420_transition_history.sql +100 -0
  95. package/dist/platform/migrations/0421_orders.sql +134 -0
  96. package/dist/platform/migrations/0422_order_payments.sql +109 -0
  97. package/dist/platform/migrations/0440_capacity.sql +100 -0
  98. package/dist/platform/migrations/0441_capacity_views.sql +40 -0
  99. package/dist/platform/migrations/0450_order_grants.sql +21 -0
  100. package/dist/platform/migrations/0451_pack_roles.sql +18 -0
  101. package/dist/platform/migrations/0460_content.sql +59 -0
  102. package/dist/platform/migrations/0461_media.sql +52 -0
  103. package/dist/platform/migrations/0470_publish_versions.sql +36 -0
  104. package/dist/platform/migrations/0471_permission_grants.sql +18 -0
  105. package/dist/platform/migrations/0490_staff_invites.sql +40 -0
  106. package/dist/platform/migrations/0491_sign_in_mail_kind.sql +10 -0
  107. package/dist/platform/migrations/0492_email_confirmation_and_sign_in_confirm.sql +30 -0
  108. package/dist/platform/migrations/0500_published_media_field.sql +25 -0
  109. package/dist/platform/migrations/0501_import_keys.sql +23 -0
  110. package/dist/platform/sdk/automation-check.ts +534 -0
  111. package/dist/platform/sdk/automation.ts +743 -0
  112. package/dist/platform/sdk/behaviour.ts +215 -0
  113. package/dist/platform/sdk/capacity.ts +112 -0
  114. package/dist/platform/sdk/contract.ts +766 -0
  115. package/dist/platform/sdk/document.ts +788 -0
  116. package/dist/platform/sdk/field-types.ts +106 -0
  117. package/dist/platform/sdk/formula/ast.ts +72 -0
  118. package/dist/platform/sdk/formula/compile.ts +454 -0
  119. package/dist/platform/sdk/formula/index.ts +4 -0
  120. package/dist/platform/sdk/formula/parser.ts +417 -0
  121. package/dist/platform/sdk/index.ts +33 -0
  122. package/dist/platform/sdk/manifest.ts +1484 -0
  123. package/dist/platform/sdk/media.ts +46 -0
  124. package/dist/platform/sdk/permissions.ts +60 -0
  125. package/dist/platform/sdk/renamed.ts +63 -0
  126. package/dist/platform/sdk/rich-text-fixture.ts +68 -0
  127. package/dist/platform/sdk/rich-text.ts +173 -0
  128. package/dist/platform/sdk/runtime.ts +410 -0
  129. package/dist/platform/sdk/sellable.ts +396 -0
  130. package/dist/platform/sdk/slug.ts +25 -0
  131. package/dist/platform/sdk/states.ts +162 -0
  132. package/dist/platform/sdk/testing.ts +836 -0
  133. package/dist/products-2H5DR232.js +11 -0
  134. package/dist/run-4JNFLYXV.js +847 -0
  135. package/dist/src-J27WXNLY.js +270 -0
  136. package/dist/src-SSVOBH6L.js +31 -0
  137. package/dist/token-MOJUA2U6.js +70 -0
  138. package/dist/token-util-TENRN4V7.js +6 -0
  139. package/package.json +33 -4
@@ -0,0 +1,765 @@
1
+ #!/usr/bin/env node
2
+
3
+ // ../core/src/ai/roles.ts
4
+ var MODEL_ROLES = [
5
+ "build",
6
+ // Stage 17 (ADR 0351): the front agent and the background agents replace `assistant`.
7
+ "assistant.core",
8
+ "assistant.subagent",
9
+ "summarise",
10
+ "extract",
11
+ "classify",
12
+ "embed",
13
+ "vision",
14
+ "review",
15
+ "dictation.cleanup",
16
+ // Speech (ADR 0349, ADR 0351): not text models; their own capability checks and price units.
17
+ "transcribe",
18
+ "speak"
19
+ ];
20
+ var SPEECH_ROLES = ["transcribe", "speak"];
21
+ function isSpeechRole(role) {
22
+ return SPEECH_ROLES.includes(role);
23
+ }
24
+ function isModelRole(value) {
25
+ return typeof value === "string" && MODEL_ROLES.includes(value);
26
+ }
27
+ var LEGACY_ROLES = { assistant: "assistant.core" };
28
+ function normalizeRole(value) {
29
+ if (isModelRole(value)) return value;
30
+ return typeof value === "string" ? LEGACY_ROLES[value] ?? null : null;
31
+ }
32
+ var warnedLegacy = /* @__PURE__ */ new Set();
33
+ function warnLegacyRole(name, where) {
34
+ if (warnedLegacy.has(`${where}:${name}`)) return;
35
+ warnedLegacy.add(`${where}:${name}`);
36
+ console.warn(
37
+ `${where}: the model role "${name}" is deprecated; use "${LEGACY_ROLES[name]}" (ADR 0351)`
38
+ );
39
+ }
40
+ var PROVIDERS = [
41
+ "workers-ai",
42
+ "platform",
43
+ "openai",
44
+ "google",
45
+ "openrouter",
46
+ "deepseek",
47
+ "anthropic",
48
+ "openai-compatible",
49
+ "custom",
50
+ // Speech only (ADR 0349): speech-to-text and text-to-speech, one key.
51
+ "assemblyai"
52
+ ];
53
+ var PROVIDER_INFO = {
54
+ "workers-ai": {
55
+ id: "workers-ai",
56
+ label: "Workers AI",
57
+ needsKey: false,
58
+ gatewaySlug: "workers-ai"
59
+ },
60
+ // Platform AI (ADR 0213 amendment): the AI a hosted deployment's plan pays for. Workers AI's
61
+ // models (`@cf/…`, the same catalogue entries), called through the one shared platform gateway
62
+ // with a tenant tag. Only on hosted deployments, where every Workers AI role becomes this.
63
+ platform: {
64
+ id: "platform",
65
+ label: "Platform AI",
66
+ needsKey: false
67
+ },
68
+ openai: {
69
+ id: "openai",
70
+ label: "OpenAI",
71
+ needsKey: true,
72
+ secretName: "AI_KEY_OPENAI",
73
+ baseURL: "https://api.openai.com/v1",
74
+ gatewaySlug: "openai"
75
+ },
76
+ google: {
77
+ id: "google",
78
+ label: "Google AI Studio",
79
+ needsKey: true,
80
+ secretName: "AI_KEY_GOOGLE",
81
+ baseURL: "https://generativelanguage.googleapis.com/v1beta/openai",
82
+ gatewaySlug: "google-ai-studio"
83
+ },
84
+ openrouter: {
85
+ id: "openrouter",
86
+ label: "OpenRouter",
87
+ needsKey: true,
88
+ secretName: "AI_KEY_OPENROUTER",
89
+ baseURL: "https://openrouter.ai/api/v1",
90
+ gatewaySlug: "openrouter"
91
+ },
92
+ // A built-in AI Gateway provider, slug `deepseek`
93
+ // (https://developers.cloudflare.com/ai-gateway/usage/providers/deepseek/), OpenAI-compatible
94
+ // at https://api.deepseek.com. Optional: a deployment chooses it (the `deepseek-flash` preset,
95
+ // ADR 0192). Never a shipped default.
96
+ deepseek: {
97
+ id: "deepseek",
98
+ label: "DeepSeek",
99
+ needsKey: true,
100
+ secretName: "AI_KEY_DEEPSEEK",
101
+ baseURL: "https://api.deepseek.com",
102
+ gatewaySlug: "deepseek"
103
+ },
104
+ // Optional, admin-configured only. Never a default for any role.
105
+ anthropic: {
106
+ id: "anthropic",
107
+ label: "Anthropic",
108
+ needsKey: true,
109
+ secretName: "AI_KEY_ANTHROPIC",
110
+ baseURL: "https://api.anthropic.com/v1",
111
+ gatewaySlug: "anthropic"
112
+ },
113
+ // Any OpenAI-compatible endpoint; base URL from deploy config (AI_PROVIDERS).
114
+ "openai-compatible": {
115
+ id: "openai-compatible",
116
+ label: "OpenAI-compatible endpoint",
117
+ needsKey: true,
118
+ secretName: "AI_KEY_CUSTOM"
119
+ },
120
+ // An AI Gateway custom provider (ADR 0180, ADR 0203). The model id names it, exactly as the
121
+ // gateway's unified endpoint wants it: `custom-<slug>/<model>`. Only reachable through the
122
+ // gateway, and its key is BYOK, stored under the provider slug `custom-<slug>`. Models must
123
+ // declare their capabilities.
124
+ custom: {
125
+ id: "custom",
126
+ label: "AI Gateway custom provider",
127
+ needsKey: true,
128
+ gatewayOnly: true
129
+ },
130
+ // AssemblyAI (ADR 0349): Universal-Streaming speech-to-text and AssemblyAI-TTS-1 text-to-speech
131
+ // over streaming WebSockets. Configured when the AI_KEY_ASSEMBLYAI secret is set. Called
132
+ // directly (no gateway slug): AI Gateway cannot carry these sockets (ADR 0349's amendment), so
133
+ // usage is logged by us in core_voice_usage.
134
+ assemblyai: {
135
+ id: "assemblyai",
136
+ label: "AssemblyAI",
137
+ needsKey: true,
138
+ secretName: "AI_KEY_ASSEMBLYAI",
139
+ baseURL: "https://api.assemblyai.com",
140
+ speechOnly: true
141
+ }
142
+ };
143
+ var CUSTOM_MODEL = /^(custom-[a-z0-9][a-z0-9-]*)\/(.+)$/;
144
+ function customProviderSlug(model) {
145
+ return CUSTOM_MODEL.exec(model.trim())?.[1] ?? null;
146
+ }
147
+ var chat = (contextTokens, extra = {}) => ({
148
+ chat: true,
149
+ toolUse: false,
150
+ jsonSchema: false,
151
+ vision: false,
152
+ embedding: false,
153
+ contextTokens,
154
+ ...extra
155
+ });
156
+ var speech = (extra) => ({
157
+ chat: false,
158
+ toolUse: false,
159
+ jsonSchema: false,
160
+ vision: false,
161
+ embedding: false,
162
+ contextTokens: 0,
163
+ ...extra
164
+ });
165
+ var embedding = (dimensions, contextTokens) => ({
166
+ chat: false,
167
+ toolUse: false,
168
+ jsonSchema: false,
169
+ vision: false,
170
+ embedding: true,
171
+ contextTokens,
172
+ dimensions,
173
+ maxBatch: 100
174
+ });
175
+ var MODEL_CATALOGUE = [
176
+ {
177
+ provider: "workers-ai",
178
+ model: "@cf/openai/gpt-oss-120b",
179
+ label: "gpt-oss 120B",
180
+ capabilities: chat(128e3, { toolUse: true, jsonSchema: true }),
181
+ price: { input: 0.35, output: 0.75 }
182
+ },
183
+ {
184
+ provider: "workers-ai",
185
+ model: "@cf/openai/gpt-oss-20b",
186
+ label: "gpt-oss 20B",
187
+ capabilities: chat(128e3, { toolUse: true, jsonSchema: true }),
188
+ price: { input: 0.2, output: 0.3 }
189
+ },
190
+ {
191
+ provider: "workers-ai",
192
+ model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
193
+ label: "Llama 3.3 70B (fast)",
194
+ capabilities: chat(24e3, { toolUse: true, jsonSchema: true }),
195
+ price: { input: 0.293, output: 2.253 }
196
+ },
197
+ {
198
+ provider: "workers-ai",
199
+ model: "@cf/meta/llama-4-scout-17b-16e-instruct",
200
+ label: "Llama 4 Scout",
201
+ capabilities: chat(131e3, { toolUse: true, jsonSchema: true, vision: true }),
202
+ price: { input: 0.27, output: 0.85 }
203
+ },
204
+ {
205
+ provider: "workers-ai",
206
+ model: "@cf/moonshotai/kimi-k2.6",
207
+ label: "Kimi K2.6",
208
+ capabilities: chat(262144, { toolUse: true, jsonSchema: true, vision: true }),
209
+ note: "Needs the Workers Paid plan."
210
+ },
211
+ {
212
+ provider: "workers-ai",
213
+ model: "@cf/zai-org/glm-4.7-flash",
214
+ label: "GLM 4.7 Flash",
215
+ capabilities: chat(131072, { toolUse: true, jsonSchema: true }),
216
+ price: { input: 0.06, output: 0.4 }
217
+ },
218
+ {
219
+ provider: "workers-ai",
220
+ model: "@cf/qwen/qwen3-30b-a3b-fp8",
221
+ label: "Qwen3 30B A3B",
222
+ capabilities: chat(32768, { toolUse: true, jsonSchema: true }),
223
+ price: { input: 0.051, output: 0.335 }
224
+ },
225
+ {
226
+ provider: "workers-ai",
227
+ model: "@cf/ibm-granite/granite-4.0-h-micro",
228
+ label: "Granite 4.0 Micro",
229
+ capabilities: chat(131e3, { toolUse: true, jsonSchema: true }),
230
+ price: { input: 0.017, output: 0.112 }
231
+ },
232
+ {
233
+ provider: "workers-ai",
234
+ model: "@cf/google/gemma-4-26b-a4b-it",
235
+ label: "Gemma 4 26B",
236
+ capabilities: chat(256e3, { toolUse: true, jsonSchema: true, vision: true }),
237
+ price: { input: 0.1, output: 0.3 }
238
+ },
239
+ {
240
+ provider: "workers-ai",
241
+ model: "@cf/qwen/qwen2.5-coder-32b-instruct",
242
+ label: "Qwen2.5 Coder 32B",
243
+ capabilities: chat(32768)
244
+ },
245
+ {
246
+ provider: "workers-ai",
247
+ model: "@cf/meta/llama-3.2-11b-vision-instruct",
248
+ label: "Llama 3.2 11B Vision",
249
+ capabilities: chat(128e3, { vision: true }),
250
+ price: { input: 0.049, output: 0.676 }
251
+ },
252
+ {
253
+ provider: "workers-ai",
254
+ model: "@cf/baai/bge-small-en-v1.5",
255
+ label: "BGE small (384)",
256
+ capabilities: embedding(384, 512),
257
+ price: { input: 0.02, output: 0 }
258
+ },
259
+ {
260
+ provider: "workers-ai",
261
+ model: "@cf/baai/bge-base-en-v1.5",
262
+ label: "BGE base (768)",
263
+ capabilities: embedding(768, 512),
264
+ price: { input: 0.067, output: 0 }
265
+ },
266
+ {
267
+ provider: "workers-ai",
268
+ model: "@cf/baai/bge-large-en-v1.5",
269
+ label: "BGE large (1024)",
270
+ capabilities: embedding(1024, 512),
271
+ price: { input: 0.204, output: 0 }
272
+ },
273
+ {
274
+ provider: "openai",
275
+ model: "gpt-4.1-mini",
276
+ label: "GPT-4.1 mini",
277
+ capabilities: chat(1e6, { toolUse: true, jsonSchema: true, vision: true }),
278
+ // https://openai.com/api/pricing/: cached input is a quarter of input, with no separate write
279
+ // price. OpenAI publishes no fixed cache lifetime, so the learner estimates it (ADR 0341).
280
+ price: { input: 0.4, cachedInput: 0.1, output: 1.6 }
281
+ },
282
+ {
283
+ provider: "openai",
284
+ model: "text-embedding-3-small",
285
+ label: "text-embedding-3-small",
286
+ capabilities: { ...embedding(1536, 8191), maxBatch: 2048 }
287
+ },
288
+ // Probed against https://api.deepseek.com on 2026-11-05 (ADR 0192). `GET /models` lists a
289
+ // 1,048,576-token context, 393,216 max output tokens and text + image input. Tool calls work.
290
+ // `json_object` works, but `json_schema` is refused ("This response_format type is unavailable
291
+ // now"). A base64 PNG is read correctly. `deepseek-flash` is an alias that tracks DeepSeek's
292
+ // latest Flash (V4.1 Flash on that date); the platform has no dated id. It is a reasoning
293
+ // model: thinking tokens count against max_tokens unless `params.thinking` is false.
294
+ {
295
+ provider: "deepseek",
296
+ model: "deepseek-flash",
297
+ label: "DeepSeek V4.1 Flash",
298
+ capabilities: chat(1048576, { toolUse: true, jsonObject: true, vision: true }),
299
+ // https://api-docs.deepseek.com/quick_start/pricing/, read 2026-11-07. These are the peak
300
+ // rates; off-peak is half. Budgets use peak so a spend limit is never reached late.
301
+ price: { input: 0.3, cachedInput: 6e-3, output: 1.2 },
302
+ note: "An alias for DeepSeek's latest Flash model. JSON mode only (no json_schema). Thinks by default."
303
+ },
304
+ {
305
+ provider: "google",
306
+ model: "gemini-2.5-flash",
307
+ label: "Gemini 2.5 Flash",
308
+ capabilities: chat(1e6, { toolUse: true, jsonSchema: true, vision: true })
309
+ },
310
+ // Speech (ADR 0349). No prices until checked against AssemblyAI's pricing page; usage is still
311
+ // counted.
312
+ {
313
+ provider: "assemblyai",
314
+ model: "universal-streaming",
315
+ label: "AssemblyAI Universal-Streaming",
316
+ capabilities: speech({ streamingAudioIn: true }),
317
+ note: "Streaming speech-to-text with its own end-of-turn detection."
318
+ },
319
+ {
320
+ provider: "assemblyai",
321
+ model: "assemblyai-tts-1",
322
+ label: "AssemblyAI TTS-1",
323
+ capabilities: speech({ voicesOut: true, supportsSpeed: false }),
324
+ note: "Streaming text-to-speech with word timestamps. No speed control at launch."
325
+ }
326
+ ];
327
+ var ROLE_REQUIREMENTS = {
328
+ build: {
329
+ description: "Writes widgets, extension code summaries and other build output as JSON",
330
+ chat: true,
331
+ // widget.describe parses the reply and validates the widget, retrying once (ADR 0192).
332
+ json: true,
333
+ minContextTokens: 16e3
334
+ },
335
+ "assistant.core": {
336
+ description: "The assistant you chat with: answers, calls the CRM's tools and hands longer work to agents",
337
+ chat: true,
338
+ // Its structured output is the tool calls themselves (ADR 0192).
339
+ toolUse: true,
340
+ minContextTokens: 64e3
341
+ },
342
+ "assistant.subagent": {
343
+ description: "Agents the assistant starts for longer work in the background",
344
+ chat: true,
345
+ toolUse: true,
346
+ minContextTokens: 64e3
347
+ },
348
+ summarise: {
349
+ description: "Record summaries, meeting prep, activity one-liners, change-set summaries",
350
+ chat: true,
351
+ minContextTokens: 16e3
352
+ },
353
+ extract: {
354
+ description: "Pulls structured fields out of text (extension code)",
355
+ chat: true,
356
+ // codemode:ai's extract parses the first JSON object in the reply (ADR 0192).
357
+ json: true,
358
+ minContextTokens: 8e3
359
+ },
360
+ classify: {
361
+ description: "Picks one label for a text (extension code)",
362
+ chat: true,
363
+ minContextTokens: 4e3
364
+ },
365
+ embed: {
366
+ description: "Embeddings for semantic search (Vectorize)",
367
+ embedding: true,
368
+ minContextTokens: 256
369
+ },
370
+ vision: {
371
+ description: "Reads images",
372
+ chat: true,
373
+ vision: true,
374
+ minContextTokens: 8e3
375
+ },
376
+ review: {
377
+ description: "The policy adjudicator (stage 7b): judges pending changes against the policy",
378
+ chat: true,
379
+ // A verdict is parsed and validated, and one that fails escalates (ADR 0192).
380
+ json: true,
381
+ minContextTokens: 16e3
382
+ },
383
+ "dictation.cleanup": {
384
+ description: "Tidies dictated text: removes fillers, fixes punctuation, applies self-corrections",
385
+ chat: true,
386
+ minContextTokens: 4e3
387
+ },
388
+ transcribe: {
389
+ description: "Speech to text for voice chat and dictation (streaming)",
390
+ streamingAudioIn: true,
391
+ minContextTokens: 0
392
+ },
393
+ speak: {
394
+ description: "Text to speech for voice chat",
395
+ voicesOut: true,
396
+ minContextTokens: 0
397
+ }
398
+ };
399
+ var THINKING_LEVELS = ["low", "medium", "high"];
400
+ var SHIPPED_ROLES = {
401
+ build: {
402
+ provider: "workers-ai",
403
+ model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
404
+ params: { maxTokens: 1200, temperature: 0.1 },
405
+ fallback: { provider: "workers-ai", model: "@cf/openai/gpt-oss-120b" }
406
+ },
407
+ "assistant.core": {
408
+ provider: "workers-ai",
409
+ model: "@cf/moonshotai/kimi-k2.6",
410
+ params: { maxTokens: 2e3, temperature: 0.2 },
411
+ fallback: { provider: "workers-ai", model: "@cf/openai/gpt-oss-120b" }
412
+ },
413
+ // The same as the front agent unless a deployment chooses otherwise (ADR 0351).
414
+ "assistant.subagent": {
415
+ provider: "workers-ai",
416
+ model: "@cf/moonshotai/kimi-k2.6",
417
+ params: { maxTokens: 2e3, temperature: 0.2 },
418
+ fallback: { provider: "workers-ai", model: "@cf/openai/gpt-oss-120b" }
419
+ },
420
+ summarise: {
421
+ provider: "workers-ai",
422
+ model: "@cf/zai-org/glm-4.7-flash",
423
+ params: { maxTokens: 500, temperature: 0.2 },
424
+ fallback: { provider: "workers-ai", model: "@cf/openai/gpt-oss-20b" }
425
+ },
426
+ extract: {
427
+ provider: "workers-ai",
428
+ model: "@cf/zai-org/glm-4.7-flash",
429
+ params: { maxTokens: 512, temperature: 0 },
430
+ fallback: { provider: "workers-ai", model: "@cf/openai/gpt-oss-20b" }
431
+ },
432
+ classify: {
433
+ provider: "workers-ai",
434
+ model: "@cf/ibm-granite/granite-4.0-h-micro",
435
+ params: { maxTokens: 64, temperature: 0 },
436
+ fallback: { provider: "workers-ai", model: "@cf/zai-org/glm-4.7-flash" }
437
+ },
438
+ embed: {
439
+ provider: "workers-ai",
440
+ model: "@cf/baai/bge-small-en-v1.5",
441
+ fallback: null
442
+ },
443
+ vision: {
444
+ provider: "workers-ai",
445
+ model: "@cf/meta/llama-4-scout-17b-16e-instruct",
446
+ params: { maxTokens: 800, temperature: 0.1 },
447
+ fallback: null
448
+ },
449
+ review: {
450
+ provider: "workers-ai",
451
+ model: "@cf/openai/gpt-oss-120b",
452
+ params: { maxTokens: 400, temperature: 0 },
453
+ fallback: { provider: "workers-ai", model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast" }
454
+ },
455
+ // Quick and literal: thinking off (ADR 0351).
456
+ "dictation.cleanup": {
457
+ provider: "workers-ai",
458
+ model: "@cf/zai-org/glm-4.7-flash",
459
+ params: { maxTokens: 1e3, temperature: 0, thinking: false },
460
+ fallback: { provider: "workers-ai", model: "@cf/openai/gpt-oss-20b" }
461
+ },
462
+ // Voice is off until AI_KEY_ASSEMBLYAI is set (ADR 0349).
463
+ transcribe: { provider: "assemblyai", model: "universal-streaming", fallback: null },
464
+ speak: { provider: "assemblyai", model: "assemblyai-tts-1", fallback: null }
465
+ };
466
+ function catalogueModel(provider, model) {
467
+ const listed = provider === "platform" ? "workers-ai" : provider;
468
+ return MODEL_CATALOGUE.find((m) => m.provider === listed && m.model === model);
469
+ }
470
+ function onPlatform(roles) {
471
+ const out = {};
472
+ for (const role of MODEL_ROLES) {
473
+ const r = roles[role];
474
+ out[role] = {
475
+ ...platformRef(r),
476
+ fallback: r.fallback ? platformRef(r.fallback) : null
477
+ };
478
+ }
479
+ return out;
480
+ }
481
+ function platformRef(ref) {
482
+ return ref.provider === "workers-ai" ? { ...ref, provider: "platform" } : ref;
483
+ }
484
+ function capabilitiesOf(ref) {
485
+ return catalogueModel(ref.provider, ref.model)?.capabilities ?? ref.capabilities ?? null;
486
+ }
487
+ function capabilityProblems(role, ref, options = {}) {
488
+ if (!PROVIDERS.includes(ref.provider)) {
489
+ if (ref.provider === "jev") {
490
+ return ['"jev" is no longer a model provider: Jev is the judge (Settings \u2192 AI, Judge)'];
491
+ }
492
+ return [`unknown provider "${ref.provider}"`];
493
+ }
494
+ if (!ref.model?.trim()) return ["no model given"];
495
+ if (ref.provider === "custom" && !customProviderSlug(ref.model)) {
496
+ return [
497
+ `an AI Gateway custom provider's model is written custom-<slug>/<model> (got "${ref.model}")`
498
+ ];
499
+ }
500
+ const caps = capabilitiesOf(ref);
501
+ const name = `${PROVIDER_INFO[ref.provider].label} ${ref.model}`;
502
+ if (!caps) {
503
+ return [
504
+ `${name} is not in the model catalogue; declare its capabilities (tool use, JSON schema, context size, vision) to use it`
505
+ ];
506
+ }
507
+ const need = ROLE_REQUIREMENTS[role];
508
+ const problems = [];
509
+ if (need.embedding && !caps.embedding) problems.push(`${name} is not an embedding model`);
510
+ if (!need.embedding && caps.embedding) problems.push(`${name} is an embedding model`);
511
+ if (need.chat && !caps.chat) problems.push(`${name} cannot generate text`);
512
+ if (need.toolUse && !caps.toolUse) problems.push(`${name} does not support tool use`);
513
+ if (need.jsonSchema && !caps.jsonSchema) {
514
+ problems.push(`${name} does not support JSON schema output`);
515
+ }
516
+ const jsonOutput = caps.jsonSchema || caps.jsonObject === true;
517
+ if (need.json && !need.jsonSchema && !jsonOutput) {
518
+ problems.push(`${name} does not support JSON output`);
519
+ }
520
+ if (need.vision && !caps.vision) problems.push(`${name} cannot read images`);
521
+ if (need.streamingAudioIn && !caps.streamingAudioIn) {
522
+ problems.push(`${name} cannot transcribe streaming audio`);
523
+ }
524
+ if (need.voicesOut && !caps.voicesOut) problems.push(`${name} cannot speak`);
525
+ if (caps.contextTokens < need.minContextTokens) {
526
+ problems.push(
527
+ `${name} has a ${caps.contextTokens.toLocaleString("en")}-token context; the ${role} role needs at least ${need.minContextTokens.toLocaleString("en")}`
528
+ );
529
+ }
530
+ if (need.embedding && options.vectorDimensions !== void 0 && caps.dimensions !== void 0 && caps.dimensions !== options.vectorDimensions) {
531
+ problems.push(
532
+ `${name} makes ${caps.dimensions}-dimension vectors but the search index has ${options.vectorDimensions}; create a new index to change the embedding size`
533
+ );
534
+ }
535
+ return problems;
536
+ }
537
+ function modelPricing(ref) {
538
+ const listed = catalogueModel(ref.provider, ref.model);
539
+ const price = listed?.price ?? ref.price;
540
+ const lifetime = listed?.cacheLifetimeSeconds ?? ref.cacheLifetimeSeconds;
541
+ const cacheLifetimeSeconds = typeof lifetime === "number" && Number.isFinite(lifetime) && lifetime > 0 ? lifetime : null;
542
+ if (!price) return null;
543
+ const cacheKnown = typeof price.cachedInput === "number";
544
+ return {
545
+ input: price.input,
546
+ cacheWrite: price.cacheWrite ?? price.input,
547
+ cachedInput: price.cachedInput ?? price.input,
548
+ output: price.output,
549
+ cacheKnown,
550
+ cacheLifetimeSeconds
551
+ };
552
+ }
553
+ var DEFAULT_PARAMS = { maxTokens: 800, temperature: 0.2 };
554
+ function mergeRole(base, layer) {
555
+ if (!layer) return base;
556
+ const switched = layer.provider !== void 0 && layer.provider !== base.provider || layer.model !== void 0 && layer.model !== base.model;
557
+ return {
558
+ provider: layer.provider ?? base.provider,
559
+ model: layer.model ?? base.model,
560
+ ...layer.capabilities ?? (switched ? void 0 : base.capabilities) ? { capabilities: layer.capabilities ?? base.capabilities } : {},
561
+ params: { ...base.params, ...layer.params },
562
+ fallback: layer.fallback !== void 0 ? layer.fallback : base.fallback
563
+ };
564
+ }
565
+ var FOLLOWS_ASSISTANT_CORE = ["assistant.subagent", "dictation.cleanup"];
566
+ function withInheritedRoles(layer) {
567
+ const core = layer?.["assistant.core"];
568
+ if (!layer || !core || core.provider === void 0 && core.model === void 0) return layer;
569
+ const out = { ...layer };
570
+ for (const role of FOLLOWS_ASSISTANT_CORE) {
571
+ if (out[role]) continue;
572
+ out[role] = role === "dictation.cleanup" ? { ...core, params: { ...SHIPPED_ROLES[role].params } } : { ...core };
573
+ }
574
+ return out;
575
+ }
576
+ function resolveRoles(layers = {}, options = {}) {
577
+ const out = {};
578
+ for (const role of MODEL_ROLES) {
579
+ let config = SHIPPED_ROLES[role];
580
+ let source = "shipped";
581
+ const ignored = [];
582
+ for (const [layer, values] of [
583
+ ["deploy", withInheritedRoles(layers.deploy)],
584
+ ["admin", withInheritedRoles(layers.admin)]
585
+ ]) {
586
+ const next = mergeRole(config, values?.[role]);
587
+ if (next === config) continue;
588
+ const problems = capabilityProblems(role, next, options);
589
+ if (problems.length) {
590
+ ignored.push({ layer, problems });
591
+ continue;
592
+ }
593
+ config = next;
594
+ source = layer;
595
+ }
596
+ const capabilities = capabilitiesOf(config);
597
+ let fallback = null;
598
+ if (config.fallback) {
599
+ const problems = capabilityProblems(role, config.fallback, options);
600
+ if (problems.length) ignored.push({ layer: source, problems });
601
+ else {
602
+ fallback = {
603
+ ...config.fallback,
604
+ capabilities: capabilitiesOf(config.fallback)
605
+ };
606
+ }
607
+ }
608
+ out[role] = {
609
+ role,
610
+ provider: config.provider,
611
+ model: config.model,
612
+ capabilities,
613
+ params: { ...DEFAULT_PARAMS, ...config.params },
614
+ fallback,
615
+ pricing: modelPricing(config),
616
+ source,
617
+ ignored
618
+ };
619
+ }
620
+ return out;
621
+ }
622
+ function parseRoleLayer(json, where = "AI_MODEL_ROLES") {
623
+ if (!json?.trim()) return {};
624
+ try {
625
+ const value = JSON.parse(json);
626
+ if (!value || typeof value !== "object" || Array.isArray(value)) return {};
627
+ const out = {};
628
+ const entries = Object.entries(value);
629
+ for (const [name, config] of entries) {
630
+ const role = normalizeRole(name);
631
+ if (!role || !config || typeof config !== "object") continue;
632
+ if (role !== name) {
633
+ warnLegacyRole(name, where);
634
+ if (entries.some(([other]) => other === role)) continue;
635
+ }
636
+ out[role] = config;
637
+ }
638
+ return out;
639
+ } catch {
640
+ return {};
641
+ }
642
+ }
643
+ function onDeepSeekFlash(role, params) {
644
+ return {
645
+ provider: "deepseek",
646
+ model: "deepseek-flash",
647
+ params,
648
+ fallback: { provider: "workers-ai", model: SHIPPED_ROLES[role].model }
649
+ };
650
+ }
651
+ var ROLE_PRESETS = {
652
+ // Every text role on deepseek-flash, with thinking off where a short, direct answer is wanted
653
+ // (it costs tokens and latency, and counts against maxTokens). The assistant, its agents and
654
+ // the reviewer keep thinking, with room for it. `embed` stays on Workers AI (bge-small, 384
655
+ // dims), because DeepSeek has no embedding model; the speech roles stay on AssemblyAI.
656
+ "deepseek-flash": {
657
+ description: "DeepSeek V4.1 Flash for every text role, each with its Workers AI default as the fallback; embed stays on Workers AI and voice on AssemblyAI",
658
+ roles: {
659
+ build: onDeepSeekFlash("build", { maxTokens: 1200, temperature: 0.1, thinking: false }),
660
+ "assistant.core": onDeepSeekFlash("assistant.core", { maxTokens: 8e3, temperature: 0.2 }),
661
+ "assistant.subagent": onDeepSeekFlash("assistant.subagent", {
662
+ maxTokens: 8e3,
663
+ temperature: 0.2
664
+ }),
665
+ summarise: onDeepSeekFlash("summarise", {
666
+ maxTokens: 500,
667
+ temperature: 0.2,
668
+ thinking: false
669
+ }),
670
+ extract: onDeepSeekFlash("extract", { maxTokens: 512, temperature: 0, thinking: false }),
671
+ classify: onDeepSeekFlash("classify", { maxTokens: 64, temperature: 0, thinking: false }),
672
+ vision: onDeepSeekFlash("vision", { maxTokens: 800, temperature: 0.1, thinking: false }),
673
+ review: onDeepSeekFlash("review", { maxTokens: 4e3, temperature: 0 }),
674
+ "dictation.cleanup": onDeepSeekFlash("dictation.cleanup", {
675
+ maxTokens: 1e3,
676
+ temperature: 0,
677
+ thinking: false
678
+ })
679
+ }
680
+ }
681
+ };
682
+ function reviewIndependence(roles) {
683
+ const { review, "assistant.core": assistant } = roles;
684
+ if (review.provider !== assistant.provider || review.model.trim() !== assistant.model.trim()) {
685
+ return { ok: true };
686
+ }
687
+ return {
688
+ ok: false,
689
+ message: `The review role uses the same model as the assistant (${PROVIDER_INFO[review.provider].label} ${review.model}), so the policy adjudicator is not independent of the agent it reviews. Choose a different model for one of them.`
690
+ };
691
+ }
692
+ var RoleLayerError = class extends Error {
693
+ name = "RoleLayerError";
694
+ problems;
695
+ constructor(problems) {
696
+ super(`Model roles: ${problems.join("; ")}`);
697
+ this.problems = problems;
698
+ }
699
+ };
700
+ function modelRolesVar(input, options = {}) {
701
+ const text = input.trim();
702
+ if (!text || text === "default") return "";
703
+ const preset = ROLE_PRESETS[text];
704
+ let value = preset?.roles;
705
+ if (!preset) {
706
+ if (!/^[[{]/.test(text)) {
707
+ throw new RoleLayerError([
708
+ `unknown preset "${text}" (presets: ${Object.keys(ROLE_PRESETS).join(", ")}, or default)`
709
+ ]);
710
+ }
711
+ try {
712
+ value = JSON.parse(text);
713
+ } catch (error) {
714
+ throw new RoleLayerError([`not valid JSON: ${error.message}`]);
715
+ }
716
+ }
717
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
718
+ throw new RoleLayerError(["expected a JSON object of role \u2192 configuration"]);
719
+ }
720
+ const problems = [];
721
+ const layer = {};
722
+ const entries = Object.entries(value);
723
+ for (const [name, config] of entries) {
724
+ const role = normalizeRole(name);
725
+ if (!role) problems.push(`unknown role "${name}"`);
726
+ else if (!config || typeof config !== "object" || Array.isArray(config)) {
727
+ problems.push(`${name}: expected an object`);
728
+ } else {
729
+ if (role !== name) {
730
+ warnLegacyRole(name, "AI_MODEL_ROLES");
731
+ if (entries.some(([other]) => other === role)) continue;
732
+ }
733
+ layer[role] = config;
734
+ }
735
+ }
736
+ if (problems.length) throw new RoleLayerError(problems);
737
+ const resolved = resolveRoles({ deploy: layer }, options);
738
+ for (const role of MODEL_ROLES) {
739
+ for (const ignored of resolved[role].ignored) {
740
+ problems.push(`${role}: ${ignored.problems.join(", ")}`);
741
+ }
742
+ }
743
+ if (problems.length) throw new RoleLayerError(problems);
744
+ return JSON.stringify(layer);
745
+ }
746
+
747
+ export {
748
+ MODEL_ROLES,
749
+ isSpeechRole,
750
+ isModelRole,
751
+ PROVIDERS,
752
+ PROVIDER_INFO,
753
+ MODEL_CATALOGUE,
754
+ ROLE_REQUIREMENTS,
755
+ THINKING_LEVELS,
756
+ onPlatform,
757
+ platformRef,
758
+ capabilityProblems,
759
+ resolveRoles,
760
+ parseRoleLayer,
761
+ ROLE_PRESETS,
762
+ reviewIndependence,
763
+ RoleLayerError,
764
+ modelRolesVar
765
+ };