apps 0.0.1-beta.1 → 0.0.1-beta.11

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 (118) hide show
  1. package/README.md +65 -43
  2. package/framework-reference.json +1 -1
  3. package/js/browser-XIPJGLH2.js +65 -0
  4. package/js/{chunk-SATWJKN6.js → chunk-27F7W2LG.js} +1 -1
  5. package/js/{chunk-HDJH3RPR.js → chunk-57RKNWL2.js} +2 -2
  6. package/js/{chunk-2HHMABB6.js → chunk-5T57N25Q.js} +61 -13
  7. package/js/{chunk-FW5HBOIK.js → chunk-CDL5PM2Q.js} +307 -169
  8. package/js/{chunk-X7SFGU4Q.js → chunk-EFAPIRVB.js} +28 -9
  9. package/js/chunk-GPFVWWDZ.js +209 -0
  10. package/js/{chunk-OHRT55C4.js → chunk-IJX4CYZO.js} +3 -6
  11. package/js/{chunk-ZTFQHGEB.js → chunk-IPI4MFSN.js} +3 -5
  12. package/js/{chunk-YEJOQEII.js → chunk-JU7VHODU.js} +1 -1
  13. package/js/{chunk-IHQ4ML7K.js → chunk-KRSCJDTW.js} +586 -111
  14. package/js/chunk-KUMBKVJD.js +39 -0
  15. package/js/{chunk-EVJUVWN2.js → chunk-M3B3DE4K.js} +2 -2
  16. package/js/{chunk-ZJWDMTE3.js → chunk-MKWZPDR6.js} +3 -3
  17. package/js/{chunk-BMOIAIVR.js → chunk-N7YDVXYJ.js} +49 -1
  18. package/js/chunk-NKLWZJLE.js +172 -0
  19. package/js/{chunk-ZCAMUXSG.js → chunk-ODEIDRGW.js} +3 -4
  20. package/js/{chunk-M6ZRRIBI.js → chunk-PJJ24GU7.js} +1 -1
  21. package/js/{chunk-FZJOYIZO.js → chunk-PZB6T6KU.js} +1 -1
  22. package/js/chunk-R3EV5FTO.js +97 -0
  23. package/js/{chunk-KOXMLKTM.js → chunk-RELFXUOO.js} +308 -316
  24. package/js/{chunk-6YBRWRK3.js → chunk-RFVIONFX.js} +43 -14
  25. package/js/{chunk-RBAC33PQ.js → chunk-TYVDBQSI.js} +58 -83
  26. package/js/{chunk-QKHR7BMF.js → chunk-UK573G7W.js} +1 -1
  27. package/js/{chunk-NCYXZN2G.js → chunk-UVL56Z6E.js} +390 -23
  28. package/js/{chunk-4LPG6RCH.js → chunk-VFZKSM3T.js} +5 -25
  29. package/js/{chunk-6IIO4NPI.js → chunk-WVVV4TX2.js} +21 -9
  30. package/js/{chunk-G7IE6BKC.js → chunk-YBRC463S.js} +8 -8
  31. package/js/chunk-Z2QY3YTF.js +507 -0
  32. package/js/{chunk-PLCMJREA.js → chunk-ZQINWV4W.js} +60 -20
  33. package/js/client.js +10 -26
  34. package/js/contracts.js +70 -15
  35. package/js/effect.js +19 -19
  36. package/js/es-APDZKREY.js +40968 -0
  37. package/js/graphql.js +34 -39
  38. package/js/host.js +23 -23
  39. package/js/index.js +199 -195
  40. package/js/mcp/effect.js +21 -21
  41. package/js/mcp/stdio.js +25 -25
  42. package/js/mcp.js +60 -44
  43. package/js/openapi.js +826 -41682
  44. package/js/react.js +3 -3
  45. package/js/skills/effect.js +3 -4
  46. package/js/skills.js +53 -17
  47. package/js/storage/facet.js +4 -4
  48. package/js/ui/auth/contracts.js +8 -9
  49. package/js/ui/auth.js +16 -14
  50. package/js/ui/contracts.js +4 -4
  51. package/js/ui/serving.js +9 -8
  52. package/package.json +1 -1
  53. package/runtime.json +1 -1
  54. package/types/app-cache/src/contracts/cache.d.ts +42 -2
  55. package/types/app-cache/src/index.d.ts +59 -1
  56. package/types/app-data/src/contracts/database.d.ts +33 -6
  57. package/types/app-data/src/implementation/schema.d.ts +2 -17
  58. package/types/apps/src/contracts/app.d.ts +7 -6
  59. package/types/apps/src/contracts/cache.d.ts +4 -1
  60. package/types/apps/src/contracts/failure.d.ts +25 -0
  61. package/types/apps/src/contracts/host.d.ts +34 -679
  62. package/types/apps/src/contracts/mcp.d.ts +16 -0
  63. package/types/apps/src/contracts/openapi.d.ts +11 -1
  64. package/types/apps/src/contracts/operations.d.ts +0 -5
  65. package/types/apps/src/contracts/protocol-version.d.ts +6 -0
  66. package/types/apps/src/contracts/protocols/1.d.ts +1589 -0
  67. package/types/apps/src/contracts/protocols/2.d.ts +668 -0
  68. package/types/apps/src/contracts/protocols/3.d.ts +676 -0
  69. package/types/apps/src/contracts/protocols/4.d.ts +1229 -0
  70. package/types/apps/src/contracts/protocols/5.d.ts +1090 -0
  71. package/types/apps/src/contracts/provider.d.ts +56 -5
  72. package/types/apps/src/contracts/router.d.ts +59 -0
  73. package/types/apps/src/contracts/skills.d.ts +17 -8
  74. package/types/apps/src/contracts/storage.d.ts +3 -3
  75. package/types/apps/src/contracts/ui-auth.d.ts +6 -14
  76. package/types/apps/src/contracts/workflows.d.ts +34 -3
  77. package/types/apps/src/graphql.d.ts +1 -3
  78. package/types/apps/src/implementation/account-router.d.ts +12 -0
  79. package/types/apps/src/implementation/app.d.ts +5 -4
  80. package/types/apps/src/implementation/cache.d.ts +3 -1
  81. package/types/apps/src/implementation/catalog-cache.d.ts +9 -2
  82. package/types/apps/src/implementation/elicitation.d.ts +1 -1
  83. package/types/apps/src/implementation/failure-detail.d.ts +25 -0
  84. package/types/apps/src/implementation/graphql-catalog.d.ts +1 -4
  85. package/types/apps/src/implementation/mcp-catalog.d.ts +1 -4
  86. package/types/apps/src/implementation/mcp-client.d.ts +35 -19
  87. package/types/apps/src/implementation/mcp.d.ts +35 -19
  88. package/types/apps/src/implementation/openapi-compile.d.ts +3 -2
  89. package/types/apps/src/implementation/openapi-document.d.ts +0 -2
  90. package/types/apps/src/implementation/openapi-names.d.ts +18 -0
  91. package/types/apps/src/implementation/openapi-request.d.ts +0 -1
  92. package/types/apps/src/implementation/openapi-source.d.ts +7 -7
  93. package/types/apps/src/implementation/operations.d.ts +26 -3
  94. package/types/apps/src/implementation/protocol-operations.d.ts +3 -4
  95. package/types/apps/src/implementation/provider.d.ts +9 -4
  96. package/types/apps/src/implementation/router-catalog.d.ts +225 -0
  97. package/types/apps/src/implementation/router.d.ts +59 -0
  98. package/types/apps/src/implementation/schema.d.ts +5 -6
  99. package/types/apps/src/implementation/storage.d.ts +5 -3
  100. package/types/apps/src/implementation/swagger-client.d.ts +28 -0
  101. package/types/apps/src/implementation/ui-auth.d.ts +11 -5
  102. package/types/apps/src/implementation/ui-serving.d.ts +4 -2
  103. package/types/apps/src/implementation/webhooks.d.ts +1 -1
  104. package/types/apps/src/implementation/workflow-context.d.ts +11 -3
  105. package/types/apps/src/index.d.ts +21 -6
  106. package/types/apps/src/mcp-stdio.d.ts +2 -5
  107. package/types/apps/src/mcp.d.ts +5 -4
  108. package/types/apps/src/openapi.d.ts +6 -6
  109. package/types/apps/src/skills.d.ts +6 -3
  110. package/types/apps/src/ui-auth.d.ts +2 -2
  111. package/types/telemetry/src/browser-operations.d.ts +5 -2
  112. package/js/chunk-PZ36XMXW.js +0 -93
  113. package/js/chunk-SWPD52J7.js +0 -35
  114. package/js/chunk-TE4KO4HI.js +0 -47
  115. package/js/chunk-W7D7WVSY.js +0 -18
  116. package/types/apps/src/contracts/dynamic-tools.d.ts +0 -13
  117. package/types/apps/src/implementation/account-operations.d.ts +0 -151
  118. package/types/apps/src/implementation/dynamic-tools.d.ts +0 -8
package/js/index.js CHANGED
@@ -1,22 +1,27 @@
1
1
  import {
2
- CacheError,
2
+ ResponseDecodeError,
3
+ ResponseStatusError,
3
4
  defineApp,
4
5
  defineDatabase,
5
6
  table,
6
7
  workflow
7
- } from "./chunk-RBAC33PQ.js";
8
- import "./chunk-PLCMJREA.js";
8
+ } from "./chunk-TYVDBQSI.js";
9
+ import "./chunk-ZQINWV4W.js";
9
10
  import {
11
+ dynamicRouter,
10
12
  fromPromise,
11
13
  mutation,
12
14
  nativeOperation,
15
+ nativeRouter,
13
16
  operationDeclaration,
14
17
  query,
18
+ router,
19
+ routerDeclaration,
15
20
  withApproval
16
- } from "./chunk-PZ36XMXW.js";
21
+ } from "./chunk-GPFVWWDZ.js";
17
22
  import {
18
23
  accountProviderError
19
- } from "./chunk-ZJWDMTE3.js";
24
+ } from "./chunk-MKWZPDR6.js";
20
25
  import {
21
26
  CalendarSchedule,
22
27
  ElicitationFailed,
@@ -31,13 +36,13 @@ import {
31
36
  ScheduleTiming,
32
37
  SecretsMethod,
33
38
  WorkflowFailure
34
- } from "./chunk-IHQ4ML7K.js";
35
- import "./chunk-BMOIAIVR.js";
36
- import "./chunk-YEJOQEII.js";
37
- import "./chunk-SWPD52J7.js";
39
+ } from "./chunk-KRSCJDTW.js";
40
+ import "./chunk-N7YDVXYJ.js";
38
41
  import {
42
+ CacheError,
39
43
  ProviderError
40
- } from "./chunk-W7D7WVSY.js";
44
+ } from "./chunk-R3EV5FTO.js";
45
+ import "./chunk-JU7VHODU.js";
41
46
  import {
42
47
  array,
43
48
  boolean,
@@ -57,37 +62,19 @@ import {
57
62
  userId,
58
63
  withLazyJsonSchemaDocument,
59
64
  wrap
60
- } from "./chunk-2HHMABB6.js";
61
- import "./chunk-FZJOYIZO.js";
65
+ } from "./chunk-5T57N25Q.js";
66
+ import "./chunk-PZB6T6KU.js";
62
67
  import {
63
68
  JsonObject,
64
69
  JsonValue,
65
70
  ValidationError
66
- } from "./chunk-SATWJKN6.js";
71
+ } from "./chunk-27F7W2LG.js";
67
72
  import {
68
73
  Effect_exports,
69
74
  Schema_exports
70
- } from "./chunk-FW5HBOIK.js";
75
+ } from "./chunk-CDL5PM2Q.js";
71
76
  import "./chunk-CZ7CSFO4.js";
72
77
 
73
- // src/contracts/http.ts
74
- var ResponseStatusError = class extends Schema_exports.TaggedError()(
75
- "ResponseStatusError",
76
- { status: Schema_exports.Number }
77
- ) {
78
- get message() {
79
- return `Request failed with status ${this.status}`;
80
- }
81
- };
82
- var ResponseDecodeError = class extends Schema_exports.TaggedError()(
83
- "ResponseDecodeError",
84
- {}
85
- ) {
86
- get message() {
87
- return "Response body did not match the expected schema";
88
- }
89
- };
90
-
91
78
  // src/implementation/http.ts
92
79
  var decodeJson = (response, schema) => Effect_exports.gen(function* () {
93
80
  if (response.status < 200 || response.status >= 300) {
@@ -100,9 +87,16 @@ var decodeJson = (response, schema) => Effect_exports.gen(function* () {
100
87
  // src/implementation/provider.ts
101
88
  var secrets = (options) => new SecretsMethod(options);
102
89
  var oauth2 = (config, response) => parse(OAuth2Config, config).pipe(Effect_exports.map((config2) => new OAuth2Method({ config: config2, response })));
103
- var defineProvider = (options) => new Provider(options);
90
+ var defineProvider = ({
91
+ health,
92
+ ...options
93
+ }) => {
94
+ if (health === void 0) return new Provider(options);
95
+ const run = fromPromise(health);
96
+ return new Provider({ ...options, health: { run } });
97
+ };
104
98
 
105
- // src/implementation/account-operations.ts
99
+ // src/implementation/account-router.ts
106
100
  var inputDocument = (operation) => {
107
101
  const imported = importedJsonSchema(operation.input);
108
102
  if (imported !== void 0) return Schema_exports.decodeUnknownSync(JsonObject)(imported);
@@ -113,72 +107,70 @@ var declaresOutput = (operation) => {
113
107
  const property = Object.getOwnPropertyDescriptor(operation, "outputSchema");
114
108
  return property !== void 0 && (property.get !== void 0 || property.value !== void 0);
115
109
  };
116
- var combine = (kind, groups) => Object.fromEntries(
117
- [...groups].map(([name, accounts]) => {
118
- const variants = [...accounts.values()];
119
- const first = variants[0];
120
- if (first === void 0)
121
- throw new Error("An account operation must have at least one account");
122
- const select = (input2) => {
123
- const operation = accounts.get(input2.accountId);
124
- if (operation === void 0)
125
- throw new Error("Account selection must be decoded before execution");
126
- return operation;
127
- };
128
- const input = Schema_exports.Union(
129
- [...accounts].map(
130
- ([accountId, operation]) => Schema_exports.Struct({ accountId: Schema_exports.Literal(accountId), input: operation.input })
131
- )
132
- );
133
- const inputSchema = () => ({
110
+ var combineOperation = (accounts) => {
111
+ const variants = [...accounts.values()];
112
+ const first = variants[0];
113
+ if (first === void 0) throw new Error("An account operation must have at least one account");
114
+ const kind = variants.every((operation) => operation.kind === "query") ? "query" : "mutation";
115
+ const select = (input2) => {
116
+ const operation = accounts.get(input2.accountId);
117
+ if (operation === void 0)
118
+ throw new Error("Account selection must be decoded before execution");
119
+ return operation;
120
+ };
121
+ const input = Schema_exports.Union(
122
+ [...accounts].map(
123
+ ([accountId, operation]) => Schema_exports.Struct({ accountId: Schema_exports.Literal(accountId), input: operation.input })
124
+ )
125
+ );
126
+ const inputSchema = () => ({
127
+ type: "object",
128
+ anyOf: [...accounts].map(([accountId, operation], index) => ({
134
129
  type: "object",
135
- anyOf: [...accounts].map(([accountId, operation], index) => ({
136
- type: "object",
137
- properties: {
138
- accountId: { type: "string", const: accountId },
139
- input: nestJsonSchema(inputDocument(operation), `#/anyOf/${index}/properties/input`)
140
- },
141
- required: ["accountId", "input"]
142
- }))
143
- });
144
- const declaration2 = operationDeclaration({
145
- kind,
146
- ...first.description === void 0 ? {} : { description: first.description },
147
- ...first.title === void 0 ? {} : { title: first.title },
148
- ...first.annotations === void 0 || !variants.every(
149
- (operation) => JSON.stringify(operation.annotations) === JSON.stringify(first.annotations)
150
- ) ? {} : { annotations: first.annotations },
151
- ...first._meta === void 0 || !variants.every(
152
- (operation) => JSON.stringify(operation._meta) === JSON.stringify(first._meta)
153
- ) ? {} : { _meta: first._meta },
154
- input: withLazyJsonSchemaDocument(input, inputSchema),
155
- approval: (context) => {
156
- const operation = select(context.toolInput);
157
- return operation.approval === void 0 ? Effect_exports.succeed("approved") : operation.approval({ ...context, toolInput: context.toolInput.input });
130
+ properties: {
131
+ accountId: { type: "string", const: accountId },
132
+ input: nestJsonSchema(inputDocument(operation), `#/anyOf/${index}/properties/input`)
158
133
  },
159
- run: (context, input2) => {
160
- const operation = select(input2);
161
- return operation.run(context, input2.input).pipe(
162
- Effect_exports.mapError((error) => accountProviderError(error, input2.accountId)),
163
- Effect_exports.flatMap(
164
- (output) => operation.output === void 0 ? Effect_exports.succeed(output) : Schema_exports.decodeUnknownEffect(operation.output)(output)
165
- )
166
- );
167
- }
168
- });
169
- if (variants.every(declaresOutput)) {
170
- const outputSchema = once(() => ({
171
- anyOf: variants.flatMap(
172
- (operation) => operation.outputSchema === void 0 ? [] : [operation.outputSchema]
173
- ).map((output, index) => nestJsonSchema(output, `#/anyOf/${index}`))
174
- }));
175
- const native = nativeOperation(declaration2);
176
- if (native !== void 0)
177
- Object.defineProperty(native, "outputSchema", { enumerable: true, get: outputSchema });
134
+ required: ["accountId", "input"]
135
+ }))
136
+ });
137
+ const declaration2 = operationDeclaration({
138
+ kind,
139
+ ...first.description === void 0 ? {} : { description: first.description },
140
+ ...first.title === void 0 ? {} : { title: first.title },
141
+ ...first.annotations === void 0 || !variants.every(
142
+ (operation) => JSON.stringify(operation.annotations) === JSON.stringify(first.annotations)
143
+ ) ? {} : { annotations: first.annotations },
144
+ ...first._meta === void 0 || !variants.every((operation) => JSON.stringify(operation._meta) === JSON.stringify(first._meta)) ? {} : { _meta: first._meta },
145
+ input: withLazyJsonSchemaDocument(input, inputSchema),
146
+ approval: (context) => {
147
+ const operation = select(context.toolInput);
148
+ return operation.approval === void 0 ? Effect_exports.succeed("approved") : operation.approval({ ...context, toolInput: context.toolInput.input });
149
+ },
150
+ run: (context, input2) => {
151
+ const operation = select(input2);
152
+ return operation.run(context, input2.input).pipe(
153
+ Effect_exports.mapError((error) => accountProviderError(error, input2.accountId)),
154
+ Effect_exports.flatMap(
155
+ (output) => operation.output === void 0 ? Effect_exports.succeed(output) : Schema_exports.decodeUnknownEffect(operation.output)(output)
156
+ )
157
+ );
178
158
  }
179
- return [name, declaration2];
180
- })
181
- );
159
+ });
160
+ if (variants.every(declaresOutput)) {
161
+ const outputSchema = once(() => ({
162
+ anyOf: variants.flatMap(
163
+ (operation) => operation.outputSchema === void 0 ? [] : [operation.outputSchema]
164
+ ).map((output, index) => nestJsonSchema(output, `#/anyOf/${index}`))
165
+ }));
166
+ const native2 = nativeOperation(declaration2);
167
+ if (native2 !== void 0)
168
+ Object.defineProperty(native2, "outputSchema", { enumerable: true, get: outputSchema });
169
+ }
170
+ const native = nativeOperation(declaration2);
171
+ if (native === void 0) throw new Error("Expected a combined operation");
172
+ return native;
173
+ };
182
174
  var sameAcross = (key, variants) => {
183
175
  const first = variants[0]?.[1][key];
184
176
  return first !== void 0 && variants.every(([, tool]) => JSON.stringify(tool[key]) === JSON.stringify(first)) ? { [key]: first } : {};
@@ -190,7 +182,7 @@ var mergeSummary = (name, variants) => {
190
182
  name,
191
183
  description: first.description,
192
184
  ...first.title === void 0 ? {} : { title: first.title },
193
- readOnly: name.startsWith("queries."),
185
+ readOnly: variants.every(([, tool]) => tool.readOnly === true),
194
186
  ...sameAcross("annotations", variants)
195
187
  });
196
188
  };
@@ -216,112 +208,123 @@ var merge = (name, variants) => Schema_exports.decodeUnknownSync(HostedTool)({
216
208
  } : {},
217
209
  ...sameAcross("_meta", variants)
218
210
  });
219
- var accountOperations = (accounts, discover, options) => Effect_exports.runPromise(
211
+ var combineDynamic = (sources) => {
212
+ const first = [...sources.values()][0];
213
+ const grouped = (read) => Effect_exports.gen(function* () {
214
+ const groups = /* @__PURE__ */ new Map();
215
+ for (const [accountId, source] of sources) {
216
+ const tools = yield* read(source).pipe(
217
+ Effect_exports.mapError((error) => accountProviderError(error, accountId))
218
+ );
219
+ for (const tool of tools) {
220
+ const variants = groups.get(tool.name) ?? [];
221
+ if (variants.some(([id2]) => id2 === accountId))
222
+ return yield* Effect_exports.die(new Error("Duplicate source operation"));
223
+ variants.push([accountId, tool]);
224
+ groups.set(tool.name, variants);
225
+ }
226
+ }
227
+ return groups;
228
+ });
229
+ return {
230
+ kind: "dynamic",
231
+ // Accounts share one source, so the first account describes the router.
232
+ ...first?.meta === void 0 ? {} : { meta: first.meta },
233
+ ...first?.overrides === void 0 ? {} : { overrides: first.overrides },
234
+ list: () => grouped((source) => source.list()).pipe(
235
+ Effect_exports.map((groups) => [...groups].map(([name, variants]) => merge(name, variants)))
236
+ ),
237
+ summaries: () => grouped(
238
+ (source) => source.summaries === void 0 ? source.list() : source.summaries()
239
+ ).pipe(
240
+ Effect_exports.map((groups) => [...groups].map(([name, variants]) => mergeSummary(name, variants)))
241
+ ),
242
+ describe: (name) => Effect_exports.gen(function* () {
243
+ const variants = [];
244
+ for (const [accountId, source] of sources) {
245
+ const tool = yield* (source.describe === void 0 ? source.list().pipe(Effect_exports.map((tools) => tools.find((tool2) => tool2.name === name))) : source.describe(name)).pipe(Effect_exports.mapError((error) => accountProviderError(error, accountId)));
246
+ if (tool !== void 0) variants.push([accountId, tool]);
247
+ }
248
+ return variants.length === 0 ? void 0 : merge(name, variants);
249
+ }),
250
+ resolve: (name) => Effect_exports.gen(function* () {
251
+ const operations = /* @__PURE__ */ new Map();
252
+ for (const [accountId, source] of sources) {
253
+ const operation = yield* source.resolve(name).pipe(Effect_exports.mapError((error) => accountProviderError(error, accountId)));
254
+ if (operation !== void 0) operations.set(accountId, operation);
255
+ }
256
+ return operations.size === 0 ? void 0 : combineOperation(operations);
257
+ })
258
+ };
259
+ };
260
+ var combineNode = (variants) => {
261
+ const nodes = [...variants.values()];
262
+ const first = nodes[0];
263
+ if (first === void 0) throw new Error("An account operation must have at least one account");
264
+ switch (first.kind) {
265
+ case "query":
266
+ case "mutation":
267
+ return combineOperation(
268
+ narrow(
269
+ variants,
270
+ (node) => node.kind === "query" || node.kind === "mutation"
271
+ )
272
+ );
273
+ case "dynamic":
274
+ return combineDynamic(
275
+ narrow(variants, (node) => node.kind === "dynamic")
276
+ );
277
+ case "router": {
278
+ const routers = narrow(variants, (node) => node.kind === "router");
279
+ const keys = new Set([...routers.values()].flatMap((router2) => Object.keys(router2.children)));
280
+ return {
281
+ kind: "router",
282
+ ...first.meta === void 0 ? {} : { meta: first.meta },
283
+ children: Object.fromEntries(
284
+ [...keys].map((key) => {
285
+ const children = /* @__PURE__ */ new Map();
286
+ for (const [accountId, router2] of routers) {
287
+ const child = Object.hasOwn(router2.children, key) ? router2.children[key] : void 0;
288
+ if (child !== void 0) children.set(accountId, child);
289
+ }
290
+ return [key, combineNode(children)];
291
+ })
292
+ )
293
+ };
294
+ }
295
+ }
296
+ };
297
+ var narrow = (variants, is) => {
298
+ const narrowed = /* @__PURE__ */ new Map();
299
+ for (const [accountId, node] of variants) {
300
+ if (!is(node)) throw new Error("Each account's router must have the same shape");
301
+ narrowed.set(accountId, node);
302
+ }
303
+ return narrowed;
304
+ };
305
+ var accountRouter = (accounts, discover, options) => Effect_exports.runPromise(
220
306
  Effect_exports.gen(function* () {
221
- const queries = /* @__PURE__ */ new Map();
222
- const mutations = /* @__PURE__ */ new Map();
223
- const sources = /* @__PURE__ */ new Map();
307
+ const routers = /* @__PURE__ */ new Map();
224
308
  for (const account of accounts) {
225
- const operations = yield* Effect_exports.tryPromise({
309
+ const declaration2 = yield* Effect_exports.tryPromise({
226
310
  try: () => discover(account),
227
311
  catch: (error) => accountProviderError(error, account.id)
228
312
  });
229
- if (sources.has(account.id))
313
+ if (routers.has(account.id))
230
314
  return yield* Effect_exports.die(new Error("Account selections must be unique"));
231
- if (operations.dynamicTools !== void 0) sources.set(account.id, operations.dynamicTools);
232
- for (const [source, target] of [
233
- [operations.queries, queries],
234
- [operations.mutations, mutations]
235
- ]) {
236
- for (const [name, declaration2] of Object.entries(source ?? {})) {
237
- const operation = nativeOperation(declaration2);
238
- if (operation === void 0)
239
- return yield* Effect_exports.die(new Error("Expected a protocol operation"));
240
- const group = target.get(name) ?? /* @__PURE__ */ new Map();
241
- if (group.has(account.id))
242
- return yield* Effect_exports.die(new Error("Account selections must be unique"));
243
- group.set(account.id, operation);
244
- target.set(name, group);
245
- }
246
- }
315
+ const router2 = nativeRouter(declaration2);
316
+ if (router2 === void 0) return yield* Effect_exports.die(new Error("Expected a protocol router"));
317
+ routers.set(account.id, router2);
247
318
  }
248
- const declared = {
249
- queries: combine("query", queries),
250
- mutations: combine("mutation", mutations)
251
- };
252
- if (sources.size === 0) return declared;
253
- const grouped = (read) => Effect_exports.gen(function* () {
254
- const groups = /* @__PURE__ */ new Map();
255
- for (const [accountId, source] of sources) {
256
- const tools = yield* read(source).pipe(
257
- Effect_exports.mapError((error) => accountProviderError(error, accountId))
258
- );
259
- for (const tool of tools) {
260
- const variants = groups.get(tool.name) ?? [];
261
- if (variants.some(([id2]) => id2 === accountId))
262
- return yield* Effect_exports.die(new Error("Duplicate source operation"));
263
- variants.push([accountId, tool]);
264
- groups.set(tool.name, variants);
265
- }
266
- }
267
- return groups;
268
- });
269
- return {
270
- ...declared,
271
- dynamicTools: {
272
- list: () => grouped((source) => source.list()).pipe(
273
- Effect_exports.map((groups) => [...groups].map(([name, variants]) => merge(name, variants)))
274
- ),
275
- summaries: () => grouped(
276
- (source) => source.summaries === void 0 ? source.list() : source.summaries()
277
- ).pipe(
278
- Effect_exports.map(
279
- (groups) => [...groups].map(([name, variants]) => mergeSummary(name, variants))
280
- )
281
- ),
282
- describe: (name) => Effect_exports.gen(function* () {
283
- const variants = [];
284
- for (const [accountId, source] of sources) {
285
- const tool = yield* (source.describe === void 0 ? source.list().pipe(Effect_exports.map((tools) => tools.find((tool2) => tool2.name === name))) : source.describe(name)).pipe(Effect_exports.mapError((error) => accountProviderError(error, accountId)));
286
- if (tool !== void 0) variants.push([accountId, tool]);
287
- }
288
- return variants.length === 0 ? void 0 : merge(name, variants);
289
- }),
290
- resolve: (name) => Effect_exports.gen(function* () {
291
- const kind = name.startsWith("queries.") ? "query" : "mutation";
292
- const operations = /* @__PURE__ */ new Map();
293
- for (const [accountId, source] of sources) {
294
- const operation = yield* source.resolve(name).pipe(Effect_exports.mapError((error) => accountProviderError(error, accountId)));
295
- if (operation !== void 0) {
296
- if (operation.kind !== kind)
297
- return yield* Effect_exports.die(new Error("Operation kind changed"));
298
- operations.set(accountId, operation);
299
- }
300
- }
301
- if (operations.size === 0) return void 0;
302
- return nativeOperation(combine(kind, /* @__PURE__ */ new Map([[name, operations]]))[name]);
303
- })
304
- }
305
- };
319
+ if (routers.size === 0) return routerDeclaration({ kind: "router", children: {} });
320
+ const combined = combineNode(routers);
321
+ if (combined.kind !== "router" && combined.kind !== "dynamic")
322
+ return yield* Effect_exports.die(new Error("Expected a protocol router"));
323
+ return routerDeclaration(combined);
306
324
  }),
307
325
  options
308
326
  );
309
327
 
310
- // src/implementation/dynamic-tools.ts
311
- var dynamicTools = (source) => ({
312
- list: () => fromPromise(source.list)().pipe(
313
- Effect_exports.flatMap(Schema_exports.decodeUnknownEffect(Schema_exports.Array(HostedTool)))
314
- ),
315
- resolve: (name) => fromPromise(source.resolve)(name).pipe(
316
- Effect_exports.map((value) => {
317
- if (value === void 0) return void 0;
318
- const operation = nativeOperation(value);
319
- if (operation === void 0) throw new Error("Expected an operation declaration");
320
- return operation;
321
- })
322
- )
323
- });
324
-
325
328
  // src/implementation/dynamic-skills.ts
326
329
  var dynamicSkills = (source) => ({
327
330
  list: fromPromise(async () => source.list())
@@ -394,7 +397,7 @@ export {
394
397
  ResponseStatusError,
395
398
  ValidationError,
396
399
  WorkflowFailure,
397
- accountOperations,
400
+ accountRouter,
398
401
  array,
399
402
  boolean,
400
403
  cron,
@@ -402,8 +405,8 @@ export {
402
405
  defineApp,
403
406
  defineDatabase,
404
407
  defineProvider,
408
+ dynamicRouter,
405
409
  dynamicSkills,
406
- dynamicTools,
407
410
  id,
408
411
  interval,
409
412
  json,
@@ -415,6 +418,7 @@ export {
415
418
  object,
416
419
  query,
417
420
  record,
421
+ router,
418
422
  secrets2 as secrets,
419
423
  string,
420
424
  table,
package/js/mcp/effect.js CHANGED
@@ -1,28 +1,28 @@
1
1
  import {
2
2
  mcpClientEffect,
3
3
  mcpToolsEffect
4
- } from "../chunk-G7IE6BKC.js";
5
- import "../chunk-X7SFGU4Q.js";
4
+ } from "../chunk-YBRC463S.js";
5
+ import "../chunk-EFAPIRVB.js";
6
6
  import "../chunk-BCSNKUAC.js";
7
- import "../chunk-KOXMLKTM.js";
8
- import "../chunk-ZTFQHGEB.js";
9
- import "../chunk-NCYXZN2G.js";
10
- import "../chunk-RBAC33PQ.js";
11
- import "../chunk-PLCMJREA.js";
12
- import "../chunk-PZ36XMXW.js";
13
- import "../chunk-ZJWDMTE3.js";
14
- import "../chunk-IHQ4ML7K.js";
15
- import "../chunk-BMOIAIVR.js";
16
- import "../chunk-YEJOQEII.js";
17
- import "../chunk-SWPD52J7.js";
18
- import "../chunk-W7D7WVSY.js";
19
- import "../chunk-ZCAMUXSG.js";
20
- import "../chunk-HDJH3RPR.js";
21
- import "../chunk-QKHR7BMF.js";
22
- import "../chunk-2HHMABB6.js";
23
- import "../chunk-FZJOYIZO.js";
24
- import "../chunk-SATWJKN6.js";
25
- import "../chunk-FW5HBOIK.js";
7
+ import "../chunk-RELFXUOO.js";
8
+ import "../chunk-NKLWZJLE.js";
9
+ import "../chunk-Z2QY3YTF.js";
10
+ import "../chunk-IPI4MFSN.js";
11
+ import "../chunk-TYVDBQSI.js";
12
+ import "../chunk-ZQINWV4W.js";
13
+ import "../chunk-GPFVWWDZ.js";
14
+ import "../chunk-MKWZPDR6.js";
15
+ import "../chunk-KRSCJDTW.js";
16
+ import "../chunk-N7YDVXYJ.js";
17
+ import "../chunk-R3EV5FTO.js";
18
+ import "../chunk-JU7VHODU.js";
19
+ import "../chunk-ODEIDRGW.js";
20
+ import "../chunk-57RKNWL2.js";
21
+ import "../chunk-UK573G7W.js";
22
+ import "../chunk-5T57N25Q.js";
23
+ import "../chunk-PZB6T6KU.js";
24
+ import "../chunk-27F7W2LG.js";
25
+ import "../chunk-CDL5PM2Q.js";
26
26
  import "../chunk-CZ7CSFO4.js";
27
27
  export {
28
28
  mcpClientEffect,
package/js/mcp/stdio.js CHANGED
@@ -2,36 +2,36 @@ import {
2
2
  adaptMcpTools,
3
3
  mcpClient,
4
4
  mcpJsonSchemaValidator
5
- } from "../chunk-X7SFGU4Q.js";
5
+ } from "../chunk-EFAPIRVB.js";
6
6
  import {
7
- protocolOperations
8
- } from "../chunk-6IIO4NPI.js";
7
+ protocolRouter
8
+ } from "../chunk-WVVV4TX2.js";
9
9
  import "../chunk-BCSNKUAC.js";
10
- import "../chunk-KOXMLKTM.js";
11
- import "../chunk-ZTFQHGEB.js";
12
- import "../chunk-NCYXZN2G.js";
13
- import "../chunk-RBAC33PQ.js";
14
- import "../chunk-PLCMJREA.js";
15
- import "../chunk-PZ36XMXW.js";
16
- import "../chunk-ZJWDMTE3.js";
10
+ import "../chunk-RELFXUOO.js";
11
+ import "../chunk-NKLWZJLE.js";
12
+ import "../chunk-Z2QY3YTF.js";
13
+ import "../chunk-IPI4MFSN.js";
14
+ import "../chunk-TYVDBQSI.js";
15
+ import "../chunk-ZQINWV4W.js";
16
+ import "../chunk-GPFVWWDZ.js";
17
+ import "../chunk-MKWZPDR6.js";
17
18
  import {
18
19
  McpError,
19
20
  ProcessConfig
20
- } from "../chunk-IHQ4ML7K.js";
21
- import "../chunk-BMOIAIVR.js";
22
- import "../chunk-YEJOQEII.js";
23
- import "../chunk-SWPD52J7.js";
24
- import "../chunk-W7D7WVSY.js";
25
- import "../chunk-ZCAMUXSG.js";
26
- import "../chunk-HDJH3RPR.js";
27
- import "../chunk-QKHR7BMF.js";
28
- import "../chunk-2HHMABB6.js";
29
- import "../chunk-FZJOYIZO.js";
30
- import "../chunk-SATWJKN6.js";
21
+ } from "../chunk-KRSCJDTW.js";
22
+ import "../chunk-N7YDVXYJ.js";
23
+ import "../chunk-R3EV5FTO.js";
24
+ import "../chunk-JU7VHODU.js";
25
+ import "../chunk-ODEIDRGW.js";
26
+ import "../chunk-57RKNWL2.js";
27
+ import "../chunk-UK573G7W.js";
28
+ import "../chunk-5T57N25Q.js";
29
+ import "../chunk-PZB6T6KU.js";
30
+ import "../chunk-27F7W2LG.js";
31
31
  import {
32
32
  Effect_exports,
33
33
  Schema_exports
34
- } from "../chunk-FW5HBOIK.js";
34
+ } from "../chunk-CDL5PM2Q.js";
35
35
  import "../chunk-CZ7CSFO4.js";
36
36
 
37
37
  // src/implementation/mcp-stdio.ts
@@ -118,11 +118,11 @@ var stdioToolsEffect = (input) => Effect_exports.gen(function* () {
118
118
  });
119
119
 
120
120
  // src/mcp-stdio.ts
121
- var stdioOperations = (config, signal, kinds = {}) => Effect_exports.runPromise(
122
- stdioToolsEffect(config).pipe(Effect_exports.map((tools) => protocolOperations(tools, kinds))),
121
+ var stdioRouter = (config, signal, kinds = {}) => Effect_exports.runPromise(
122
+ stdioToolsEffect(config).pipe(Effect_exports.map((tools) => protocolRouter(tools, kinds))),
123
123
  signal === void 0 ? {} : { signal }
124
124
  );
125
125
  export {
126
126
  McpError,
127
- stdioOperations
127
+ stdioRouter
128
128
  };