apps 0.0.1-beta.5 → 0.0.1-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 (66) hide show
  1. package/README.md +65 -43
  2. package/framework-reference.json +1 -1
  3. package/js/{chunk-FWQC6I3C.js → chunk-5T57N25Q.js} +13 -1
  4. package/js/{chunk-TDNYXSIX.js → chunk-72JNVHPK.js} +21 -9
  5. package/js/{chunk-UDDE5KOR.js → chunk-CMYUWAX7.js} +26 -7
  6. package/js/chunk-FL2QR3XW.js +507 -0
  7. package/js/{chunk-G7T27IWB.js → chunk-MKWZPDR6.js} +1 -1
  8. package/js/{chunk-CYYBFC2K.js → chunk-NKLWZJLE.js} +1 -1
  9. package/js/{chunk-67EVWIGJ.js → chunk-OCYUEU47.js} +4 -4
  10. package/js/{chunk-YEPYT6SD.js → chunk-R3EV5FTO.js} +12 -0
  11. package/js/{chunk-XHO2ZX6W.js → chunk-RFVIONFX.js} +27 -10
  12. package/js/{chunk-LUVSFETN.js → chunk-UESPOTUI.js} +127 -231
  13. package/js/{chunk-DQAZTA4I.js → chunk-WLE7WX2U.js} +290 -20
  14. package/js/{chunk-C3VAOK5B.js → chunk-YXQHV65J.js} +53 -26
  15. package/js/chunk-Z5M2LQOZ.js +209 -0
  16. package/js/client.js +1 -1
  17. package/js/contracts.js +34 -11
  18. package/js/effect.js +9 -11
  19. package/js/graphql.js +25 -32
  20. package/js/host.js +9 -11
  21. package/js/index.js +194 -192
  22. package/js/mcp/effect.js +11 -13
  23. package/js/mcp/stdio.js +15 -17
  24. package/js/mcp.js +50 -36
  25. package/js/openapi.js +166 -108
  26. package/js/skills.js +6 -7
  27. package/package.json +1 -1
  28. package/runtime.json +1 -1
  29. package/types/apps/src/contracts/app.d.ts +2 -5
  30. package/types/apps/src/contracts/host.d.ts +19 -7
  31. package/types/apps/src/contracts/mcp.d.ts +16 -0
  32. package/types/apps/src/contracts/openapi.d.ts +4 -0
  33. package/types/apps/src/contracts/operations.d.ts +0 -5
  34. package/types/apps/src/contracts/protocol-version.d.ts +2 -2
  35. package/types/apps/src/contracts/protocols/4.d.ts +1229 -0
  36. package/types/apps/src/contracts/protocols/5.d.ts +1090 -0
  37. package/types/apps/src/contracts/provider.d.ts +51 -5
  38. package/types/apps/src/contracts/router.d.ts +59 -0
  39. package/types/apps/src/graphql.d.ts +1 -3
  40. package/types/apps/src/implementation/account-router.d.ts +12 -0
  41. package/types/apps/src/implementation/app.d.ts +5 -4
  42. package/types/apps/src/implementation/catalog-cache.d.ts +9 -2
  43. package/types/apps/src/implementation/graphql-catalog.d.ts +1 -4
  44. package/types/apps/src/implementation/mcp-catalog.d.ts +1 -4
  45. package/types/apps/src/implementation/mcp-client.d.ts +35 -19
  46. package/types/apps/src/implementation/mcp.d.ts +35 -19
  47. package/types/apps/src/implementation/openapi-compile.d.ts +2 -1
  48. package/types/apps/src/implementation/openapi-source.d.ts +2 -6
  49. package/types/apps/src/implementation/operations.d.ts +26 -3
  50. package/types/apps/src/implementation/protocol-operations.d.ts +3 -4
  51. package/types/apps/src/implementation/provider.d.ts +9 -4
  52. package/types/apps/src/implementation/router-catalog.d.ts +225 -0
  53. package/types/apps/src/implementation/router.d.ts +59 -0
  54. package/types/apps/src/implementation/schema.d.ts +5 -1
  55. package/types/apps/src/implementation/workflow-context.d.ts +1 -1
  56. package/types/apps/src/index.d.ts +5 -4
  57. package/types/apps/src/mcp-stdio.d.ts +2 -5
  58. package/types/apps/src/mcp.d.ts +5 -4
  59. package/types/apps/src/openapi.d.ts +6 -6
  60. package/js/chunk-3XKZDQLM.js +0 -93
  61. package/js/chunk-4M277YTM.js +0 -136
  62. package/js/chunk-SB3V4YVR.js +0 -18
  63. package/js/chunk-W4DMKWAB.js +0 -35
  64. package/types/apps/src/contracts/dynamic-tools.d.ts +0 -13
  65. package/types/apps/src/implementation/account-operations.d.ts +0 -151
  66. package/types/apps/src/implementation/dynamic-tools.d.ts +0 -8
@@ -5,18 +5,14 @@ import {
5
5
  } from "./chunk-N7YDVXYJ.js";
6
6
  import {
7
7
  CacheCommand,
8
- CacheReply
9
- } from "./chunk-YEPYT6SD.js";
8
+ CacheReply,
9
+ ProviderError
10
+ } from "./chunk-R3EV5FTO.js";
10
11
  import {
12
+ AppSkillName,
11
13
  AppSkills,
12
14
  SkillLoadFailed
13
15
  } from "./chunk-JU7VHODU.js";
14
- import {
15
- OpenapiResponseError
16
- } from "./chunk-W4DMKWAB.js";
17
- import {
18
- ProviderError
19
- } from "./chunk-SB3V4YVR.js";
20
16
  import {
21
17
  AccountId,
22
18
  HttpUrl,
@@ -78,6 +74,30 @@ import {
78
74
  withDefault
79
75
  } from "./chunk-CDL5PM2Q.js";
80
76
 
77
+ // src/contracts/router.ts
78
+ var reservedRouterKeys = /* @__PURE__ */ new Set([
79
+ "__proto__",
80
+ "constructor",
81
+ "prototype"
82
+ ]);
83
+ var RouterKey = Schema_exports.String.check(
84
+ Schema_exports.isPattern(/^[A-Za-z_][A-Za-z0-9_-]{0,99}$/),
85
+ Schema_exports.makeFilter((key) => !reservedRouterKeys.has(key))
86
+ );
87
+ var RouterIcon = Schema_exports.Struct({
88
+ src: Schema_exports.NonEmptyString,
89
+ mimeType: Schema_exports.optionalKey(Schema_exports.String),
90
+ sizes: Schema_exports.optionalKey(Schema_exports.Array(Schema_exports.String)),
91
+ theme: Schema_exports.optionalKey(Schema_exports.Literals(["light", "dark"]))
92
+ });
93
+ var RouterMeta = Schema_exports.Struct({
94
+ title: Schema_exports.optionalKey(Schema_exports.String),
95
+ description: Schema_exports.optionalKey(Schema_exports.String),
96
+ instructions: Schema_exports.optionalKey(Schema_exports.String),
97
+ icons: Schema_exports.optionalKey(Schema_exports.Array(RouterIcon)),
98
+ tags: Schema_exports.optionalKey(Schema_exports.Record(Schema_exports.NonEmptyString, Schema_exports.String))
99
+ });
100
+
81
101
  // src/contracts/tools.ts
82
102
  var ToolAnnotations = Schema_exports.Struct({
83
103
  title: Schema_exports.optionalKey(Schema_exports.String),
@@ -130,6 +150,15 @@ var McpToolMetadata = Schema_exports.Struct({
130
150
  annotations: Schema_exports.optional(ToolAnnotations),
131
151
  _meta: Schema_exports.optional(JsonObject2)
132
152
  });
153
+ var McpServerHeader = Schema_exports.Struct({
154
+ name: Schema_exports.optionalKey(Schema_exports.String),
155
+ title: Schema_exports.optionalKey(Schema_exports.String),
156
+ version: Schema_exports.optionalKey(Schema_exports.String),
157
+ description: Schema_exports.optionalKey(Schema_exports.String),
158
+ websiteUrl: Schema_exports.optionalKey(Schema_exports.String),
159
+ icons: Schema_exports.optionalKey(Schema_exports.Array(RouterIcon)),
160
+ instructions: Schema_exports.optionalKey(Schema_exports.String)
161
+ });
133
162
  var McpError = class extends Schema_exports.TaggedError()("McpError", {
134
163
  phase: Schema_exports.Literals(["connect", "discover", "call", "schema", "transport"]),
135
164
  reason: Schema_exports.Literals([
@@ -152,6 +181,31 @@ var ProcessConfig = Schema_exports.Struct({
152
181
  )
153
182
  });
154
183
 
184
+ // src/contracts/api-response-error.ts
185
+ var ApiErrorRecovery = Schema_exports.Struct({
186
+ action: Schema_exports.NonEmptyString.check(Schema_exports.isMaxLength(1024)),
187
+ instructions: Schema_exports.NonEmptyString.check(Schema_exports.isMaxLength(4096))
188
+ });
189
+ var ApiErrorResponse = Schema_exports.Struct({
190
+ code: Schema_exports.NonEmptyString.check(Schema_exports.isMaxLength(128)),
191
+ status: Schema_exports.Int.check(Schema_exports.isBetween({ minimum: 400, maximum: 599 })),
192
+ message: Schema_exports.NonEmptyString.check(Schema_exports.isMaxLength(4096)),
193
+ recovery: Schema_exports.optionalKey(ApiErrorRecovery)
194
+ });
195
+ var OpenapiResponseError = class extends Schema_exports.TaggedError()(
196
+ "OpenapiResponseError",
197
+ ApiErrorResponse.fields
198
+ ) {
199
+ };
200
+ var OpenapiErrorLimits = Schema_exports.Struct({
201
+ maxBodyBytes: Schema_exports.Int.check(Schema_exports.isGreaterThan(0)),
202
+ readTimeoutMs: Schema_exports.Int.check(Schema_exports.isGreaterThan(0))
203
+ });
204
+ var defaultOpenapiErrorLimits = OpenapiErrorLimits.make({
205
+ maxBodyBytes: 65536,
206
+ readTimeoutMs: 2e3
207
+ });
208
+
155
209
  // src/contracts/failure.ts
156
210
  var maxFailureMessageLength = 2048;
157
211
  var FailureSource = Schema_exports.Literals(["app", "storage", "service"]);
@@ -1833,6 +1887,16 @@ var OAuth2Method = class extends Data_exports.TaggedClass(
1833
1887
  "oauth2"
1834
1888
  ) {
1835
1889
  };
1890
+ var displayText = Schema_exports.String.check(Schema_exports.isMinLength(1), Schema_exports.isMaxLength(255));
1891
+ var AccountInfo = Schema_exports.Struct({
1892
+ externalId: Schema_exports.optionalKey(displayText),
1893
+ displayName: Schema_exports.optionalKey(displayText),
1894
+ username: Schema_exports.optionalKey(displayText),
1895
+ email: Schema_exports.optionalKey(displayText),
1896
+ avatarUrl: Schema_exports.optionalKey(HttpUrl),
1897
+ profileUrl: Schema_exports.optionalKey(HttpUrl)
1898
+ });
1899
+ var AccountCheckResult = Schema_exports.Struct({ accountInfo: Schema_exports.optionalKey(AccountInfo) });
1836
1900
  var Provider = class extends Data_exports.Class {
1837
1901
  /** Declare zero or more accounts from this provider without performing I/O. */
1838
1902
  many() {
@@ -1843,7 +1907,7 @@ var ManyAccounts = class extends Data_exports.TaggedClass("many") {
1843
1907
  };
1844
1908
 
1845
1909
  // src/contracts/protocol-version.ts
1846
- var frameworkProtocol = 3;
1910
+ var frameworkProtocol = 5;
1847
1911
 
1848
1912
  // src/contracts/schedules.ts
1849
1913
  var minimumIntervalMilliseconds = 6e4;
@@ -2215,8 +2279,184 @@ var protocol3 = {
2215
2279
  }
2216
2280
  };
2217
2281
 
2218
- // src/contracts/operations.ts
2219
- var OperationToolPrefixes = { query: "queries.", mutate: "mutations." };
2282
+ // src/contracts/protocols/4.ts
2283
+ var HostedTool2 = Schema_exports.Struct({
2284
+ schedules: Schema_exports.optionalKey(Schema_exports.Array(OperationSchedule)),
2285
+ name: Schema_exports.NonEmptyString,
2286
+ router: Schema_exports.optionalKey(Schema_exports.NonEmptyString),
2287
+ tags: Schema_exports.optionalKey(Schema_exports.Array(Schema_exports.NonEmptyString)),
2288
+ description: Schema_exports.String,
2289
+ inputSchema: JsonObject2,
2290
+ readOnly: Schema_exports.optionalKey(Schema_exports.Boolean),
2291
+ title: Schema_exports.optionalKey(Schema_exports.String),
2292
+ outputSchema: Schema_exports.optionalKey(JsonObject2),
2293
+ annotations: Schema_exports.optionalKey(ToolAnnotations),
2294
+ _meta: Schema_exports.optionalKey(JsonObject2)
2295
+ });
2296
+ var HostedToolSummary2 = HostedTool2.mapFields(
2297
+ ({ inputSchema: _input, outputSchema: _output, _meta, ...fields }) => fields
2298
+ );
2299
+ var HostRouterError = Schema_exports.Union([
2300
+ ProviderError,
2301
+ McpError,
2302
+ SkillLoadFailed,
2303
+ HostDeclarationInvalid2,
2304
+ HostEvaluationFailed2
2305
+ ]);
2306
+ var HostedRouter = Schema_exports.Struct({
2307
+ path: Schema_exports.String,
2308
+ title: Schema_exports.optionalKey(Schema_exports.String),
2309
+ description: Schema_exports.optionalKey(Schema_exports.String),
2310
+ icons: Schema_exports.optionalKey(Schema_exports.Array(RouterIcon)),
2311
+ tags: Schema_exports.optionalKey(Schema_exports.Record(Schema_exports.NonEmptyString, Schema_exports.String)),
2312
+ skill: Schema_exports.optionalKey(AppSkillName),
2313
+ error: Schema_exports.optionalKey(HostRouterError)
2314
+ });
2315
+ var HostedCatalog = Schema_exports.Struct({
2316
+ tools: Schema_exports.Array(HostedTool2),
2317
+ routers: Schema_exports.Array(HostedRouter)
2318
+ });
2319
+ var HostedCatalogSummary = Schema_exports.Struct({
2320
+ tools: Schema_exports.Array(HostedToolSummary2),
2321
+ routers: Schema_exports.Array(HostedRouter)
2322
+ });
2323
+ var ToolKind = Schema_exports.Literals(["query", "mutation"]);
2324
+ var HostRequest2 = Schema_exports.Union([
2325
+ WorkflowCommand,
2326
+ WebhookCommand,
2327
+ Schema_exports.Struct({ operation: Schema_exports.Literal("requirements") }),
2328
+ Schema_exports.Struct({
2329
+ operation: Schema_exports.Literal("inspect"),
2330
+ /** Omit schemas. Only builds that declare the toolIndex capability accept this. */
2331
+ detail: Schema_exports.optionalKey(Schema_exports.Literal("summary")),
2332
+ /** Describe only these tools. Only builds that declare the toolIndex capability accept this. */
2333
+ tools: Schema_exports.optionalKey(Schema_exports.Array(Schema_exports.NonEmptyString)),
2334
+ /**
2335
+ * Describe only declared operations that have schedules, without dynamic tool discovery.
2336
+ * Only builds that declare the scheduledTools capability accept this.
2337
+ */
2338
+ scheduled: Schema_exports.optionalKey(Schema_exports.Literal(true))
2339
+ }),
2340
+ Schema_exports.Struct({
2341
+ operation: Schema_exports.Literal("skills"),
2342
+ /** Answer with SkillSources. Only builds that declare the skillSources capability accept this. */
2343
+ sources: Schema_exports.optionalKey(Schema_exports.Literal(true))
2344
+ }),
2345
+ Schema_exports.Struct({
2346
+ operation: Schema_exports.Literal("query"),
2347
+ name: Schema_exports.NonEmptyString,
2348
+ input: JsonValue
2349
+ }),
2350
+ Schema_exports.Struct({
2351
+ operation: Schema_exports.Literal("mutate"),
2352
+ name: Schema_exports.NonEmptyString,
2353
+ input: JsonValue
2354
+ }),
2355
+ Schema_exports.Struct({
2356
+ operation: Schema_exports.Literal("call"),
2357
+ tool: Schema_exports.NonEmptyString,
2358
+ /**
2359
+ * The caller's claim; the bundle rejects a call whose tool has the other kind. The host omits
2360
+ * it for a tool its catalog does not list, and then opens storage for writing.
2361
+ */
2362
+ kind: Schema_exports.optionalKey(ToolKind),
2363
+ input: JsonValue
2364
+ })
2365
+ ]);
2366
+ var HostKindMismatch = class extends Schema_exports.TaggedError()("HostKindMismatch", {
2367
+ tool: Schema_exports.NonEmptyString,
2368
+ requested: ToolKind,
2369
+ actual: ToolKind
2370
+ }) {
2371
+ };
2372
+ var HostError3 = Schema_exports.Union([...HostError2.members, HostKindMismatch]);
2373
+ var HostResponse3 = Schema_exports.Union([
2374
+ Schema_exports.Struct({
2375
+ ok: Schema_exports.Literal(true),
2376
+ value: JsonValue,
2377
+ toolError: Schema_exports.optionalKey(Schema_exports.Literal(true))
2378
+ }),
2379
+ Schema_exports.Struct({ ok: Schema_exports.Literal(false), error: HostError3 })
2380
+ ]);
2381
+ var HostInvocation2 = Schema_exports.Struct({
2382
+ command: HostRequest2,
2383
+ accounts: ResolvedAccounts,
2384
+ approval: Schema_exports.optionalKey(TrustedToolApproval),
2385
+ replay: Schema_exports.optionalKey(WorkflowReplay),
2386
+ deadline: Schema_exports.optionalKey(InvocationDeadline),
2387
+ workflowRun: Schema_exports.optionalKey(WorkflowRunId)
2388
+ });
2389
+ var protocol4 = {
2390
+ version: 4,
2391
+ schemas: {
2392
+ invocation: HostInvocation2,
2393
+ request: HostRequest2,
2394
+ response: HostResponse3,
2395
+ requirements: DeclaredRequirements,
2396
+ catalog: HostedCatalog,
2397
+ catalogSummary: HostedCatalogSummary,
2398
+ skills: SkillCatalogResponse2,
2399
+ elicitationRequest: FormElicitation,
2400
+ elicitationReply: ElicitationReply,
2401
+ workflowStep: WorkflowRpcCommand,
2402
+ workflowStepReply: WorkflowRpcResult,
2403
+ workflowControl: WorkflowControlCommand,
2404
+ cacheCommand: CacheCommand,
2405
+ cacheReply: CacheReply
2406
+ }
2407
+ };
2408
+
2409
+ // src/contracts/protocols/5.ts
2410
+ var DeclaredRequirements2 = Schema_exports.Struct({
2411
+ /** Protocol support of this retained framework build, not an author-declared requirement. */
2412
+ capabilities: Schema_exports.optionalKey(
2413
+ Schema_exports.Struct({
2414
+ skills: Schema_exports.Literal(true),
2415
+ toolIndex: Schema_exports.optionalKey(Schema_exports.Literal(true)),
2416
+ skillSources: Schema_exports.optionalKey(Schema_exports.Literal(true)),
2417
+ scheduledTools: Schema_exports.optionalKey(Schema_exports.Literal(true))
2418
+ })
2419
+ ),
2420
+ database: Schema_exports.optionalKey(DatabaseSchema),
2421
+ accounts: Schema_exports.Record(
2422
+ Schema_exports.NonEmptyString,
2423
+ Schema_exports.Struct({
2424
+ definition: DeclaredProvider,
2425
+ cardinality: Schema_exports.Literals(["one", "many"]),
2426
+ /**
2427
+ * The slot's provider defines an account check. Kept beside the definition, not in it, so
2428
+ * adding or editing a check never changes the provider's identity.
2429
+ */
2430
+ health: Schema_exports.optionalKey(Schema_exports.Literal(true))
2431
+ })
2432
+ )
2433
+ });
2434
+ var AccountCheckCommand = Schema_exports.Struct({
2435
+ operation: Schema_exports.Literal("account-check"),
2436
+ requirement: Schema_exports.NonEmptyString
2437
+ });
2438
+ var HostRequest3 = Schema_exports.Union([
2439
+ ...protocol4.schemas.request.members,
2440
+ AccountCheckCommand
2441
+ ]);
2442
+ var HostInvocation3 = Schema_exports.Struct({
2443
+ command: HostRequest3,
2444
+ accounts: ResolvedAccounts,
2445
+ approval: Schema_exports.optionalKey(TrustedToolApproval),
2446
+ replay: Schema_exports.optionalKey(WorkflowReplay),
2447
+ deadline: Schema_exports.optionalKey(InvocationDeadline),
2448
+ workflowRun: Schema_exports.optionalKey(WorkflowRunId)
2449
+ });
2450
+ var protocol5 = {
2451
+ version: 5,
2452
+ schemas: {
2453
+ ...protocol4.schemas,
2454
+ invocation: HostInvocation3,
2455
+ request: HostRequest3,
2456
+ requirements: DeclaredRequirements2,
2457
+ accountCheck: AccountCheckResult
2458
+ }
2459
+ };
2220
2460
 
2221
2461
  // src/contracts/host.ts
2222
2462
  var skillsCommand = (sources) => sources ? { operation: "skills", sources: true } : { operation: "skills" };
@@ -2227,7 +2467,7 @@ var inspectCommand = (tools, scheduled) => ({
2227
2467
  ...scheduled === void 0 ? {} : { scheduled }
2228
2468
  });
2229
2469
  var indexCommand = { operation: "inspect", detail: "summary" };
2230
- var selectTools = (tools) => (all) => tools === void 0 ? all : all.filter((tool) => tools.includes(tool.name));
2470
+ var selectTools = (tools) => (catalog) => tools === void 0 ? catalog : { ...catalog, tools: catalog.tools.filter((tool) => tools.includes(tool.name)) };
2231
2471
  var HostRequirementsError = Schema_exports.Union([
2232
2472
  HostRequestInvalid,
2233
2473
  HostDeclarationInvalid2,
@@ -2248,6 +2488,7 @@ var HostCallError = Schema_exports.Union([
2248
2488
  HostInspectError,
2249
2489
  HostToolNotFound,
2250
2490
  HostOperationNotFound,
2491
+ HostKindMismatch,
2251
2492
  HostOperationFailed2,
2252
2493
  DatabaseLimitExceeded,
2253
2494
  HostInputInvalid,
@@ -2257,6 +2498,16 @@ var HostCallError = Schema_exports.Union([
2257
2498
  HostToolPolicyFailed,
2258
2499
  ElicitationFailed
2259
2500
  ]);
2501
+ var HostAccountCheckError = Schema_exports.Union([
2502
+ ProviderError,
2503
+ WorkflowFailure,
2504
+ HostRequestInvalid,
2505
+ HostDeclarationInvalid2,
2506
+ HostAccountsInvalid,
2507
+ HostOperationNotFound,
2508
+ HostOperationFailed2,
2509
+ HostOutputInvalid
2510
+ ]);
2260
2511
  var HostDataError = HostCallError;
2261
2512
  var ToolResultObservation = Context_exports.Reference(
2262
2513
  "apps/ToolResultObservation",
@@ -2271,8 +2522,14 @@ export {
2271
2522
  OAuth2Config,
2272
2523
  OAuth2AccessToken,
2273
2524
  OAuth2Method,
2525
+ AccountInfo,
2526
+ AccountCheckResult,
2274
2527
  Provider,
2275
2528
  ManyAccounts,
2529
+ reservedRouterKeys,
2530
+ RouterKey,
2531
+ RouterIcon,
2532
+ RouterMeta,
2276
2533
  ToolAnnotations,
2277
2534
  McpClientLimits,
2278
2535
  defaultMcpClientLimits,
@@ -2280,8 +2537,13 @@ export {
2280
2537
  McpToolsOptions,
2281
2538
  McpToolResult,
2282
2539
  McpToolMetadata,
2540
+ McpServerHeader,
2283
2541
  McpError,
2284
2542
  ProcessConfig,
2543
+ ApiErrorRecovery,
2544
+ ApiErrorResponse,
2545
+ OpenapiResponseError,
2546
+ defaultOpenapiErrorLimits,
2285
2547
  maxFailureMessageLength,
2286
2548
  FailureSource,
2287
2549
  FailureName,
@@ -2331,14 +2593,10 @@ export {
2331
2593
  OperationSchedule,
2332
2594
  DeclaredAuthMethod,
2333
2595
  DeclaredProvider,
2334
- DeclaredRequirements,
2335
2596
  ResolvedAccount,
2336
2597
  ResolvedAccounts,
2337
2598
  TrustedToolApproval,
2338
2599
  InvocationDeadline,
2339
- HostedTool,
2340
- HostedToolSummary,
2341
- HostRequest,
2342
2600
  HostRequestInvalid,
2343
2601
  HostAccountsInvalid,
2344
2602
  HostOperationNotFound,
@@ -2350,7 +2608,6 @@ export {
2350
2608
  HostToolApprovalRequired,
2351
2609
  HostToolPolicyFailed,
2352
2610
  HostOutputInvalid,
2353
- HostInvocation,
2354
2611
  protocol1,
2355
2612
  SkillSources2 as SkillSources,
2356
2613
  SkillCatalogResponse2 as SkillCatalogResponse,
@@ -2358,10 +2615,22 @@ export {
2358
2615
  HostDeclarationInvalid2 as HostDeclarationInvalid,
2359
2616
  HostEvaluationFailed2 as HostEvaluationFailed,
2360
2617
  HostOperationFailed2 as HostOperationFailed,
2361
- HostError2 as HostError,
2362
- HostResponse2 as HostResponse,
2363
2618
  protocol3,
2364
- OperationToolPrefixes,
2619
+ HostedTool2 as HostedTool,
2620
+ HostedToolSummary2 as HostedToolSummary,
2621
+ HostRouterError,
2622
+ HostedRouter,
2623
+ HostedCatalog,
2624
+ HostedCatalogSummary,
2625
+ HostKindMismatch,
2626
+ HostError3 as HostError,
2627
+ HostResponse3 as HostResponse,
2628
+ protocol4,
2629
+ DeclaredRequirements2 as DeclaredRequirements,
2630
+ AccountCheckCommand,
2631
+ HostRequest3 as HostRequest,
2632
+ HostInvocation3 as HostInvocation,
2633
+ protocol5,
2365
2634
  skillsCommand,
2366
2635
  skillCatalog,
2367
2636
  inspectCommand,
@@ -2370,6 +2639,7 @@ export {
2370
2639
  HostRequirementsError,
2371
2640
  HostInspectError,
2372
2641
  HostCallError,
2642
+ HostAccountCheckError,
2373
2643
  HostDataError,
2374
2644
  ToolResultObservation
2375
2645
  };
@@ -2,12 +2,14 @@ import {
2
2
  promiseTable
3
3
  } from "./chunk-ZQINWV4W.js";
4
4
  import {
5
+ declaredOperations,
5
6
  fromPromise,
6
- nativeOperation
7
- } from "./chunk-3XKZDQLM.js";
7
+ nativeOperation,
8
+ nativeRouter
9
+ } from "./chunk-Z5M2LQOZ.js";
8
10
  import {
9
11
  ScheduleTiming
10
- } from "./chunk-DQAZTA4I.js";
12
+ } from "./chunk-WLE7WX2U.js";
11
13
  import {
12
14
  DatabaseSchema
13
15
  } from "./chunk-N7YDVXYJ.js";
@@ -15,7 +17,7 @@ import {
15
17
  decoderOf,
16
18
  isSchema,
17
19
  storageFieldOf
18
- } from "./chunk-FWQC6I3C.js";
20
+ } from "./chunk-5T57N25Q.js";
19
21
  import {
20
22
  AppStorageUnavailable
21
23
  } from "./chunk-PZB6T6KU.js";
@@ -27,6 +29,24 @@ import {
27
29
  Schema_exports
28
30
  } from "./chunk-CDL5PM2Q.js";
29
31
 
32
+ // src/contracts/http.ts
33
+ var ResponseStatusError = class extends Schema_exports.TaggedError()(
34
+ "ResponseStatusError",
35
+ { status: Schema_exports.Number }
36
+ ) {
37
+ get message() {
38
+ return `Request failed with status ${this.status}`;
39
+ }
40
+ };
41
+ var ResponseDecodeError = class extends Schema_exports.TaggedError()(
42
+ "ResponseDecodeError",
43
+ {}
44
+ ) {
45
+ get message() {
46
+ return "Response body did not match the expected schema";
47
+ }
48
+ };
49
+
30
50
  // src/implementation/workflows.ts
31
51
  var NativeWorkflow = /* @__PURE__ */ Symbol("apps.Workflow");
32
52
  var workflow = (options, run) => ({
@@ -50,8 +70,12 @@ var nativeWorkflow = (value) => {
50
70
  var InternalApp = /* @__PURE__ */ Symbol("apps.App");
51
71
  var isApp = (value) => typeof value === "object" && value !== null && InternalApp in value;
52
72
  var toEffectApp = (app) => app[InternalApp];
73
+ function rejectCatalogs(definition) {
74
+ if ("queries" in definition || "mutations" in definition)
75
+ throw new Error("Put queries and mutations in a router under tools");
76
+ }
53
77
  function adaptDefinition(definition) {
54
- if ("tools" in definition) throw new Error("Use queries and mutations instead of tools");
78
+ rejectCatalogs(definition);
55
79
  const webhooks = definition.webhooks === void 0 ? {} : {
56
80
  webhooks: Object.fromEntries(
57
81
  Object.entries(definition.webhooks).map(([name, webhook]) => [
@@ -67,42 +91,42 @@ function adaptDefinition(definition) {
67
91
  ])
68
92
  )
69
93
  };
70
- const operations = (kind, catalog) => Object.fromEntries(
71
- Object.entries(catalog).map(([name, value]) => {
72
- const operation = nativeOperation(value);
73
- if (operation === void 0 || operation.kind !== kind)
74
- throw new Error("Invalid app data operation");
75
- return [name, operation];
76
- })
77
- );
78
94
  const workflows = definition.workflows === void 0 ? {} : {
79
95
  workflows: Object.fromEntries(
80
96
  Object.entries(definition.workflows).map(([name, value]) => {
81
- const declared = nativeWorkflow(value);
82
- if (declared === void 0) throw new Error("Invalid workflow declaration");
83
- return [name, declared];
97
+ const declared2 = nativeWorkflow(value);
98
+ if (declared2 === void 0) throw new Error("Invalid workflow declaration");
99
+ return [name, declared2];
84
100
  })
85
101
  )
86
102
  };
87
- const data = {
88
- ...definition.queries === void 0 ? {} : { queries: operations("query", definition.queries) },
89
- ...definition.mutations === void 0 ? {} : { mutations: operations("mutation", definition.mutations) }
90
- };
103
+ const root = definition.tools === void 0 ? void 0 : nativeRouter(definition.tools);
104
+ if (definition.tools !== void 0 && root === void 0)
105
+ throw new Error("tools must be a router");
106
+ const data = root === void 0 ? {} : { tools: root };
107
+ const declared = root?.kind === "router" ? declaredOperations(root) : [];
108
+ const mutations = /* @__PURE__ */ new Set();
109
+ for (const { operation } of declared) {
110
+ if (operation.kind !== "mutation") continue;
111
+ if (mutations.has(operation))
112
+ throw new Error("A mutation can be mounted at only one path in tools");
113
+ mutations.add(operation);
114
+ }
91
115
  const schedules = definition.schedules === void 0 ? {} : {
92
116
  schedules: Object.fromEntries(
93
117
  Object.entries(definition.schedules).map(([name, schedule]) => {
94
- const matches = Object.entries(definition.mutations ?? {}).filter(
95
- ([, operation]) => operation === schedule.operation
118
+ const target = nativeOperation(schedule.operation);
119
+ const match = declared.find(
120
+ ({ operation }) => operation === target && operation.kind === "mutation"
96
121
  );
97
- const match = matches[0];
98
- if (match === void 0 || matches.length !== 1)
99
- throw new Error("A schedule must reference exactly one named mutation in this app");
122
+ if (match === void 0)
123
+ throw new Error("A schedule must reference a mutation in this app's tools");
100
124
  return [
101
125
  name,
102
126
  {
103
127
  timing: Schema_exports.decodeUnknownSync(ScheduleTiming)(schedule.timing),
104
128
  input: Schema_exports.decodeUnknownSync(JsonValue)(schedule.input),
105
- tool: `mutations.${match[0]}`
129
+ tool: match.name
106
130
  }
107
131
  ];
108
132
  })
@@ -117,6 +141,7 @@ function adaptDefinition(definition) {
117
141
  };
118
142
  }
119
143
  var defineApp = (requirements, definition) => {
144
+ if (typeof definition !== "function") rejectCatalogs(definition);
120
145
  const evaluate = typeof definition === "function" ? definition : async () => definition;
121
146
  const factory = fromPromise(evaluate);
122
147
  const native = {
@@ -204,6 +229,8 @@ var unavailableStorage = {
204
229
  };
205
230
 
206
231
  export {
232
+ ResponseStatusError,
233
+ ResponseDecodeError,
207
234
  workflow,
208
235
  isApp,
209
236
  toEffectApp,