apps 0.0.1-beta.3 → 0.0.1-beta.30

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/README.md +68 -44
  2. package/framework-reference.json +1 -1
  3. package/js/{chunk-G7ZIRKMK.js → chunk-2D2PKLGQ.js} +118 -197
  4. package/js/chunk-3SPRHIEE.js +42 -0
  5. package/js/{chunk-FDNTX5QJ.js → chunk-4N26L465.js} +2 -2
  6. package/js/chunk-5ZHHO4OM.js +92 -0
  7. package/js/{chunk-EVJUVWN2.js → chunk-65SZ23BK.js} +2 -2
  8. package/js/{chunk-M6ZRRIBI.js → chunk-6JBTHTI5.js} +1 -1
  9. package/js/{chunk-J7O55ZV7.js → chunk-6NK26ONC.js} +332 -187
  10. package/js/chunk-6VWYEQ4X.js +254 -0
  11. package/js/{chunk-RN2MXB4R.js → chunk-AE4FWJQU.js} +128 -24
  12. package/js/{chunk-HDJH3RPR.js → chunk-BBTELEAN.js} +2 -2
  13. package/js/{chunk-LGIYBDWA.js → chunk-BRGF7VFN.js} +65 -1
  14. package/js/{chunk-MYYEW3RA.js → chunk-BSRU52RU.js} +984 -61
  15. package/js/{chunk-FZJOYIZO.js → chunk-BTJMXW4I.js} +1 -1
  16. package/js/{chunk-HDTGZWP2.js → chunk-IMCEF6KE.js} +139 -32
  17. package/js/chunk-KQCMHI3K.js +118 -0
  18. package/js/{chunk-BMOIAIVR.js → chunk-M2KEEOIQ.js} +49 -1
  19. package/js/{chunk-YEJOQEII.js → chunk-MYCVMDWI.js} +45 -7
  20. package/js/{chunk-FW5HBOIK.js → chunk-NXTXZ635.js} +1841 -1701
  21. package/js/chunk-OD3KFKZD.js +1617 -0
  22. package/js/{chunk-JN55AYQH.js → chunk-OI5CKSBU.js} +61 -32
  23. package/js/{chunk-NQ3OMCA5.js → chunk-P46HIAX6.js} +2 -2
  24. package/js/chunk-PUC24GZP.js +801 -0
  25. package/js/{chunk-SATWJKN6.js → chunk-PWF2DRJ3.js} +1 -1
  26. package/js/{chunk-D47C7KG5.js → chunk-VUVBMNKC.js} +2 -2
  27. package/js/{chunk-ZCAMUXSG.js → chunk-WGBI5MVX.js} +3 -4
  28. package/js/{chunk-T2LAZCAD.js → chunk-WQ5MVBTP.js} +1 -1
  29. package/js/{chunk-PLCMJREA.js → chunk-XBQTJP76.js} +60 -20
  30. package/js/{chunk-QKHR7BMF.js → chunk-XGN5IFOZ.js} +3 -3
  31. package/js/{chunk-WFSQXYUT.js → chunk-YML53Z7H.js} +42 -5
  32. package/js/{chunk-5MQZEB6Y.js → chunk-ZZOCEUTB.js} +37 -12
  33. package/js/client.js +120 -84
  34. package/js/contracts.js +110 -16
  35. package/js/effect.js +20 -20
  36. package/js/{es-APDZKREY.js → es-DIULA3ZF.js} +62 -1659
  37. package/js/graphql.js +58 -54
  38. package/js/host.js +20 -20
  39. package/js/index.js +247 -204
  40. package/js/mcp/effect.js +24 -22
  41. package/js/mcp/stdio.js +35 -30
  42. package/js/mcp.js +105 -68
  43. package/js/openapi.js +4087 -1503
  44. package/js/react.js +3 -3
  45. package/js/skills/effect.js +5 -3
  46. package/js/skills.js +15 -15
  47. package/js/storage/facet.js +4 -4
  48. package/js/ui/auth/contracts.js +2 -2
  49. package/js/ui/auth.js +5 -5
  50. package/js/ui/contracts.js +5 -4
  51. package/js/ui/serving.js +8516 -214
  52. package/package.json +1 -1
  53. package/runtime.json +1 -1
  54. package/types/app-data/src/contracts/database.d.ts +33 -6
  55. package/types/app-data/src/implementation/schema.d.ts +2 -17
  56. package/types/apps/src/contracts/api-response-error.d.ts +4 -0
  57. package/types/apps/src/contracts/app.d.ts +7 -6
  58. package/types/apps/src/contracts/failure.d.ts +54 -0
  59. package/types/apps/src/contracts/graphql.d.ts +2 -1
  60. package/types/apps/src/contracts/host.d.ts +34 -11
  61. package/types/apps/src/contracts/mcp.d.ts +91 -10
  62. package/types/apps/src/contracts/network.d.ts +84 -0
  63. package/types/apps/src/contracts/openapi-compile.d.ts +31 -3
  64. package/types/apps/src/contracts/openapi.d.ts +45 -9
  65. package/types/apps/src/contracts/operations.d.ts +5 -6
  66. package/types/apps/src/contracts/protocol-version.d.ts +2 -2
  67. package/types/apps/src/contracts/protocols/1.d.ts +251 -69
  68. package/types/apps/src/contracts/protocols/2.d.ts +710 -0
  69. package/types/apps/src/contracts/protocols/3.d.ts +716 -0
  70. package/types/apps/src/contracts/protocols/4.d.ts +1298 -0
  71. package/types/apps/src/contracts/protocols/5.d.ts +1174 -0
  72. package/types/apps/src/contracts/protocols/6.d.ts +1620 -0
  73. package/types/apps/src/contracts/protocols/7.d.ts +1784 -0
  74. package/types/apps/src/contracts/protocols/8.d.ts +1119 -0
  75. package/types/apps/src/contracts/protocols/oauth.d.ts +89 -0
  76. package/types/apps/src/contracts/provider-error.d.ts +9 -0
  77. package/types/apps/src/contracts/provider.d.ts +115 -10
  78. package/types/apps/src/contracts/router.d.ts +59 -0
  79. package/types/apps/src/contracts/skills.d.ts +18 -5
  80. package/types/apps/src/contracts/storage.d.ts +3 -3
  81. package/types/apps/src/contracts/ui.d.ts +18 -0
  82. package/types/apps/src/contracts/workflows.d.ts +34 -3
  83. package/types/apps/src/graphql.d.ts +1 -3
  84. package/types/apps/src/implementation/account-router.d.ts +12 -0
  85. package/types/apps/src/implementation/app.d.ts +5 -4
  86. package/types/apps/src/implementation/browser-scripts.gen.d.ts +6 -0
  87. package/types/apps/src/implementation/catalog-cache.d.ts +34 -4
  88. package/types/apps/src/implementation/elicitation.d.ts +9 -9
  89. package/types/apps/src/implementation/failure-detail.d.ts +46 -0
  90. package/types/apps/src/implementation/graphql-catalog.d.ts +4 -7
  91. package/types/apps/src/implementation/graphql.d.ts +4 -3
  92. package/types/apps/src/implementation/mcp-call.d.ts +6 -5
  93. package/types/apps/src/implementation/mcp-catalog.d.ts +7 -8
  94. package/types/apps/src/implementation/mcp-client.d.ts +49 -25
  95. package/types/apps/src/implementation/mcp-stdio.d.ts +1 -1
  96. package/types/apps/src/implementation/mcp-tools.d.ts +2 -1
  97. package/types/apps/src/implementation/mcp.d.ts +52 -25
  98. package/types/apps/src/implementation/network.d.ts +16 -0
  99. package/types/apps/src/implementation/openapi-compile.d.ts +27 -6
  100. package/types/apps/src/implementation/openapi-document.d.ts +35 -8
  101. package/types/apps/src/implementation/openapi-names.d.ts +9 -4
  102. package/types/apps/src/implementation/openapi-request.d.ts +10 -2
  103. package/types/apps/src/implementation/openapi-source.d.ts +8 -6
  104. package/types/apps/src/implementation/openapi-upgrade.d.ts +4 -0
  105. package/types/apps/src/implementation/operations.d.ts +36 -3
  106. package/types/apps/src/implementation/protocol-operations.d.ts +6 -4
  107. package/types/apps/src/implementation/provider-error.d.ts +28 -1
  108. package/types/apps/src/implementation/provider.d.ts +19 -5
  109. package/types/apps/src/implementation/router-catalog.d.ts +224 -0
  110. package/types/apps/src/implementation/router.d.ts +68 -0
  111. package/types/apps/src/implementation/runtime-yield.d.ts +7 -0
  112. package/types/apps/src/implementation/schema.d.ts +52 -1
  113. package/types/apps/src/implementation/skills.d.ts +2 -2
  114. package/types/apps/src/implementation/storage.d.ts +5 -3
  115. package/types/apps/src/implementation/ui-account-notice.d.ts +9 -0
  116. package/types/apps/src/implementation/ui-client.d.ts +2 -2
  117. package/types/apps/src/implementation/ui-document.d.ts +5 -0
  118. package/types/apps/src/implementation/ui-errors.d.ts +1 -1
  119. package/types/apps/src/implementation/ui-serving.d.ts +10 -4
  120. package/types/apps/src/implementation/ui-watch.d.ts +1 -1
  121. package/types/apps/src/implementation/upstream-error.d.ts +7 -0
  122. package/types/apps/src/implementation/webhooks.d.ts +1 -1
  123. package/types/apps/src/implementation/workflow-context.d.ts +11 -3
  124. package/types/apps/src/index.d.ts +29 -11
  125. package/types/apps/src/mcp-stdio.d.ts +2 -5
  126. package/types/apps/src/mcp.d.ts +25 -5
  127. package/types/apps/src/openapi.d.ts +6 -6
  128. package/types/apps/src/skills.d.ts +4 -4
  129. package/types/telemetry/src/browser-operations.d.ts +5 -2
  130. package/types/telemetry/src/config.d.ts +2 -2
  131. package/types/utils/src/api-error.d.ts +48 -0
  132. package/js/chunk-PYUYJRSK.js +0 -93
  133. package/js/chunk-SWPD52J7.js +0 -35
  134. package/js/chunk-W7D7WVSY.js +0 -18
  135. package/js/chunk-Z5NMEGJN.js +0 -29
  136. package/js/chunk-ZJWDMTE3.js +0 -63
  137. package/types/apps/src/contracts/dynamic-tools.d.ts +0 -13
  138. package/types/apps/src/implementation/account-operations.d.ts +0 -151
  139. package/types/apps/src/implementation/dynamic-tools.d.ts +0 -8
package/js/index.js CHANGED
@@ -1,27 +1,37 @@
1
1
  import {
2
+ ResponseDecodeError,
3
+ ResponseStatusError,
2
4
  defineApp,
3
5
  defineDatabase,
4
6
  table,
5
7
  workflow
6
- } from "./chunk-JN55AYQH.js";
7
- import "./chunk-PLCMJREA.js";
8
+ } from "./chunk-OI5CKSBU.js";
9
+ import "./chunk-XBQTJP76.js";
8
10
  import {
11
+ dynamicRouter,
9
12
  fromPromise,
10
13
  mutation,
11
14
  nativeOperation,
15
+ nativeRouter,
12
16
  operationDeclaration,
13
17
  query,
14
- withApproval
15
- } from "./chunk-PYUYJRSK.js";
18
+ router,
19
+ routerDeclaration,
20
+ toolAnnotations,
21
+ withApproval,
22
+ withApprovals
23
+ } from "./chunk-6VWYEQ4X.js";
16
24
  import {
17
25
  accountProviderError
18
- } from "./chunk-ZJWDMTE3.js";
26
+ } from "./chunk-KQCMHI3K.js";
19
27
  import {
20
28
  CalendarSchedule,
21
29
  ElicitationFailed,
30
+ FetchOptionUnsupported,
22
31
  HostedTool,
23
32
  HostedToolSummary,
24
33
  Interval,
34
+ NetworkRefused,
25
35
  NonRetryableError,
26
36
  OAuth2AccessToken,
27
37
  OAuth2Config,
@@ -30,22 +40,21 @@ import {
30
40
  ScheduleTiming,
31
41
  SecretsMethod,
32
42
  WorkflowFailure
33
- } from "./chunk-MYYEW3RA.js";
34
- import "./chunk-BMOIAIVR.js";
35
- import {
36
- CacheError
37
- } from "./chunk-LGIYBDWA.js";
38
- import "./chunk-YEJOQEII.js";
39
- import "./chunk-SWPD52J7.js";
43
+ } from "./chunk-BSRU52RU.js";
44
+ import "./chunk-M2KEEOIQ.js";
40
45
  import {
46
+ CacheError,
41
47
  ProviderError
42
- } from "./chunk-W7D7WVSY.js";
48
+ } from "./chunk-BRGF7VFN.js";
49
+ import "./chunk-MYCVMDWI.js";
43
50
  import {
44
51
  array,
45
52
  boolean,
46
53
  decoderOf,
54
+ fieldExposure,
47
55
  id,
48
56
  importedJsonSchema,
57
+ isSchema,
49
58
  json,
50
59
  jsonSchema,
51
60
  literal,
@@ -54,42 +63,28 @@ import {
54
63
  object,
55
64
  once,
56
65
  parse,
66
+ plain,
67
+ raw,
57
68
  record,
58
69
  string,
59
70
  userId,
60
71
  withLazyJsonSchemaDocument,
61
72
  wrap
62
- } from "./chunk-WFSQXYUT.js";
63
- import "./chunk-FZJOYIZO.js";
73
+ } from "./chunk-YML53Z7H.js";
74
+ import "./chunk-BTJMXW4I.js";
64
75
  import {
65
76
  JsonObject,
66
77
  JsonValue,
67
78
  ValidationError
68
- } from "./chunk-SATWJKN6.js";
79
+ } from "./chunk-PWF2DRJ3.js";
80
+ import "./chunk-2D2PKLGQ.js";
81
+ import "./chunk-XGN5IFOZ.js";
69
82
  import {
70
83
  Effect_exports,
71
84
  Schema_exports
72
- } from "./chunk-FW5HBOIK.js";
85
+ } from "./chunk-NXTXZ635.js";
73
86
  import "./chunk-CZ7CSFO4.js";
74
87
 
75
- // src/contracts/http.ts
76
- var ResponseStatusError = class extends Schema_exports.TaggedError()(
77
- "ResponseStatusError",
78
- { status: Schema_exports.Number }
79
- ) {
80
- get message() {
81
- return `Request failed with status ${this.status}`;
82
- }
83
- };
84
- var ResponseDecodeError = class extends Schema_exports.TaggedError()(
85
- "ResponseDecodeError",
86
- {}
87
- ) {
88
- get message() {
89
- return "Response body did not match the expected schema";
90
- }
91
- };
92
-
93
88
  // src/implementation/http.ts
94
89
  var decodeJson = (response, schema) => Effect_exports.gen(function* () {
95
90
  if (response.status < 200 || response.status >= 300) {
@@ -101,86 +96,101 @@ var decodeJson = (response, schema) => Effect_exports.gen(function* () {
101
96
 
102
97
  // src/implementation/provider.ts
103
98
  var secrets = (options) => new SecretsMethod(options);
104
- var oauth2 = (config, response) => parse(OAuth2Config, config).pipe(Effect_exports.map((config2) => new OAuth2Method({ config: config2, response })));
105
- var defineProvider = (options) => new Provider(options);
99
+ var oauth2 = (config, response, exposure) => parse(OAuth2Config, config).pipe(
100
+ Effect_exports.map(
101
+ (config2) => new OAuth2Method({ config: config2, response, ...exposure === void 0 ? {} : { exposure } })
102
+ )
103
+ );
104
+ var defineProvider = ({
105
+ health,
106
+ ...options
107
+ }) => {
108
+ if (health === void 0) return new Provider(options);
109
+ const run = fromPromise(health);
110
+ return new Provider({ ...options, health: { run } });
111
+ };
106
112
 
107
- // src/implementation/account-operations.ts
108
- var inputDocument = (operation) => {
109
- const imported = importedJsonSchema(operation.input);
113
+ // src/implementation/account-router.ts
114
+ var decoderDocument = (decoder) => {
115
+ const imported = importedJsonSchema(decoder);
110
116
  if (imported !== void 0) return Schema_exports.decodeUnknownSync(JsonObject)(imported);
111
- const document = Schema_exports.toJsonSchemaDocument(operation.input);
117
+ const document = Schema_exports.toJsonSchemaDocument(decoder);
112
118
  return Schema_exports.decodeUnknownSync(JsonObject)({ ...document.schema, $defs: document.definitions });
113
119
  };
114
120
  var declaresOutput = (operation) => {
121
+ if (operation.output !== void 0) return true;
115
122
  const property = Object.getOwnPropertyDescriptor(operation, "outputSchema");
116
123
  return property !== void 0 && (property.get !== void 0 || property.value !== void 0);
117
124
  };
118
- var combine = (kind, groups) => Object.fromEntries(
119
- [...groups].map(([name, accounts]) => {
120
- const variants = [...accounts.values()];
121
- const first = variants[0];
122
- if (first === void 0)
123
- throw new Error("An account operation must have at least one account");
124
- const select = (input2) => {
125
- const operation = accounts.get(input2.accountId);
126
- if (operation === void 0)
127
- throw new Error("Account selection must be decoded before execution");
128
- return operation;
129
- };
130
- const input = Schema_exports.Union(
131
- [...accounts].map(
132
- ([accountId, operation]) => Schema_exports.Struct({ accountId: Schema_exports.Literal(accountId), input: operation.input })
133
- )
134
- );
135
- const inputSchema = () => ({
125
+ var outputDocument = (operation) => operation.output === void 0 ? operation.outputSchema : decoderDocument(operation.output);
126
+ var combineOperation = (accounts) => {
127
+ const variants = [...accounts.values()];
128
+ const first = variants[0];
129
+ if (first === void 0) throw new Error("An account operation must have at least one account");
130
+ const kind = variants.every((operation) => operation.kind === "query") ? "query" : "mutation";
131
+ const select = (input2) => {
132
+ const operation = accounts.get(input2.accountId);
133
+ if (operation === void 0)
134
+ throw new Error("Account selection must be decoded before execution");
135
+ return operation;
136
+ };
137
+ const input = Schema_exports.Union(
138
+ [...accounts].map(
139
+ ([accountId, operation]) => Schema_exports.Struct({ accountId: Schema_exports.Literal(accountId), input: operation.input })
140
+ )
141
+ );
142
+ const inputSchema = () => ({
143
+ type: "object",
144
+ anyOf: [...accounts].map(([accountId, operation], index) => ({
136
145
  type: "object",
137
- anyOf: [...accounts].map(([accountId, operation], index) => ({
138
- type: "object",
139
- properties: {
140
- accountId: { type: "string", const: accountId },
141
- input: nestJsonSchema(inputDocument(operation), `#/anyOf/${index}/properties/input`)
142
- },
143
- required: ["accountId", "input"]
144
- }))
145
- });
146
- const declaration2 = operationDeclaration({
147
- kind,
148
- ...first.description === void 0 ? {} : { description: first.description },
149
- ...first.title === void 0 ? {} : { title: first.title },
150
- ...first.annotations === void 0 || !variants.every(
151
- (operation) => JSON.stringify(operation.annotations) === JSON.stringify(first.annotations)
152
- ) ? {} : { annotations: first.annotations },
153
- ...first._meta === void 0 || !variants.every(
154
- (operation) => JSON.stringify(operation._meta) === JSON.stringify(first._meta)
155
- ) ? {} : { _meta: first._meta },
156
- input: withLazyJsonSchemaDocument(input, inputSchema),
157
- approval: (context) => {
158
- const operation = select(context.toolInput);
159
- return operation.approval === void 0 ? Effect_exports.succeed("approved") : operation.approval({ ...context, toolInput: context.toolInput.input });
146
+ properties: {
147
+ accountId: { type: "string", const: accountId },
148
+ input: nestJsonSchema(
149
+ decoderDocument(operation.input),
150
+ `#/anyOf/${index}/properties/input`
151
+ )
160
152
  },
161
- run: (context, input2) => {
162
- const operation = select(input2);
163
- return operation.run(context, input2.input).pipe(
164
- Effect_exports.mapError((error) => accountProviderError(error, input2.accountId)),
165
- Effect_exports.flatMap(
166
- (output) => operation.output === void 0 ? Effect_exports.succeed(output) : Schema_exports.decodeUnknownEffect(operation.output)(output)
167
- )
168
- );
169
- }
170
- });
171
- if (variants.every(declaresOutput)) {
172
- const outputSchema = once(() => ({
173
- anyOf: variants.flatMap(
174
- (operation) => operation.outputSchema === void 0 ? [] : [operation.outputSchema]
175
- ).map((output, index) => nestJsonSchema(output, `#/anyOf/${index}`))
176
- }));
177
- const native = nativeOperation(declaration2);
178
- if (native !== void 0)
179
- Object.defineProperty(native, "outputSchema", { enumerable: true, get: outputSchema });
153
+ required: ["accountId", "input"]
154
+ }))
155
+ });
156
+ const declaration2 = operationDeclaration({
157
+ kind,
158
+ ...first.description === void 0 ? {} : { description: first.description },
159
+ ...first.title === void 0 ? {} : { title: first.title },
160
+ ...first.annotations === void 0 || !variants.every(
161
+ (operation) => JSON.stringify(operation.annotations) === JSON.stringify(first.annotations)
162
+ ) ? {} : { annotations: first.annotations },
163
+ ...first._meta === void 0 || !variants.every((operation) => JSON.stringify(operation._meta) === JSON.stringify(first._meta)) ? {} : { _meta: first._meta },
164
+ input: withLazyJsonSchemaDocument(input, inputSchema),
165
+ approval: (context) => {
166
+ const operation = select(context.toolInput);
167
+ return operation.approval === void 0 ? Effect_exports.succeed("approved") : operation.approval({ ...context, toolInput: context.toolInput.input });
168
+ },
169
+ run: (context, input2) => {
170
+ const operation = select(input2);
171
+ return operation.run(context, input2.input).pipe(
172
+ Effect_exports.mapError((error) => accountProviderError(error, input2.accountId)),
173
+ Effect_exports.flatMap(
174
+ (output) => operation.output === void 0 ? Effect_exports.succeed(output) : Schema_exports.decodeUnknownEffect(operation.output)(output)
175
+ )
176
+ );
180
177
  }
181
- return [name, declaration2];
182
- })
183
- );
178
+ });
179
+ if (variants.every(declaresOutput)) {
180
+ const outputSchema = once(() => ({
181
+ anyOf: variants.flatMap((operation) => {
182
+ const output = outputDocument(operation);
183
+ return output === void 0 ? [] : [output];
184
+ }).map((output, index) => nestJsonSchema(output, `#/anyOf/${index}`))
185
+ }));
186
+ const native2 = nativeOperation(declaration2);
187
+ if (native2 !== void 0)
188
+ Object.defineProperty(native2, "outputSchema", { enumerable: true, get: outputSchema });
189
+ }
190
+ const native = nativeOperation(declaration2);
191
+ if (native === void 0) throw new Error("Expected a combined operation");
192
+ return native;
193
+ };
184
194
  var sameAcross = (key, variants) => {
185
195
  const first = variants[0]?.[1][key];
186
196
  return first !== void 0 && variants.every(([, tool]) => JSON.stringify(tool[key]) === JSON.stringify(first)) ? { [key]: first } : {};
@@ -192,7 +202,7 @@ var mergeSummary = (name, variants) => {
192
202
  name,
193
203
  description: first.description,
194
204
  ...first.title === void 0 ? {} : { title: first.title },
195
- readOnly: name.startsWith("queries."),
205
+ readOnly: variants.every(([, tool]) => tool.readOnly === true),
196
206
  ...sameAcross("annotations", variants)
197
207
  });
198
208
  };
@@ -218,112 +228,123 @@ var merge = (name, variants) => Schema_exports.decodeUnknownSync(HostedTool)({
218
228
  } : {},
219
229
  ...sameAcross("_meta", variants)
220
230
  });
221
- var accountOperations = (accounts, discover, options) => Effect_exports.runPromise(
231
+ var combineDynamic = (sources) => {
232
+ const first = [...sources.values()][0];
233
+ const grouped = (read) => Effect_exports.gen(function* () {
234
+ const groups = /* @__PURE__ */ new Map();
235
+ for (const [accountId, source] of sources) {
236
+ const tools = yield* read(source).pipe(
237
+ Effect_exports.mapError((error) => accountProviderError(error, accountId))
238
+ );
239
+ for (const tool of tools) {
240
+ const variants = groups.get(tool.name) ?? [];
241
+ if (variants.some(([id2]) => id2 === accountId))
242
+ return yield* Effect_exports.die(new Error("Duplicate source operation"));
243
+ variants.push([accountId, tool]);
244
+ groups.set(tool.name, variants);
245
+ }
246
+ }
247
+ return groups;
248
+ });
249
+ return {
250
+ kind: "dynamic",
251
+ // Accounts share one source, so the first account describes the router.
252
+ ...first?.meta === void 0 ? {} : { meta: first.meta },
253
+ ...first?.overrides === void 0 ? {} : { overrides: first.overrides },
254
+ list: () => grouped((source) => source.list()).pipe(
255
+ Effect_exports.map((groups) => [...groups].map(([name, variants]) => merge(name, variants)))
256
+ ),
257
+ summaries: () => grouped(
258
+ (source) => source.summaries === void 0 ? source.list() : source.summaries()
259
+ ).pipe(
260
+ Effect_exports.map((groups) => [...groups].map(([name, variants]) => mergeSummary(name, variants)))
261
+ ),
262
+ describe: (name) => Effect_exports.gen(function* () {
263
+ const variants = [];
264
+ for (const [accountId, source] of sources) {
265
+ 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)));
266
+ if (tool !== void 0) variants.push([accountId, tool]);
267
+ }
268
+ return variants.length === 0 ? void 0 : merge(name, variants);
269
+ }),
270
+ resolve: (name) => Effect_exports.gen(function* () {
271
+ const operations = /* @__PURE__ */ new Map();
272
+ for (const [accountId, source] of sources) {
273
+ const operation = yield* source.resolve(name).pipe(Effect_exports.mapError((error) => accountProviderError(error, accountId)));
274
+ if (operation !== void 0) operations.set(accountId, operation);
275
+ }
276
+ return operations.size === 0 ? void 0 : combineOperation(operations);
277
+ })
278
+ };
279
+ };
280
+ var combineNode = (variants) => {
281
+ const nodes = [...variants.values()];
282
+ const first = nodes[0];
283
+ if (first === void 0) throw new Error("An account operation must have at least one account");
284
+ switch (first.kind) {
285
+ case "query":
286
+ case "mutation":
287
+ return combineOperation(
288
+ narrow(
289
+ variants,
290
+ (node) => node.kind === "query" || node.kind === "mutation"
291
+ )
292
+ );
293
+ case "dynamic":
294
+ return combineDynamic(
295
+ narrow(variants, (node) => node.kind === "dynamic")
296
+ );
297
+ case "router": {
298
+ const routers = narrow(variants, (node) => node.kind === "router");
299
+ const keys = new Set([...routers.values()].flatMap((router2) => Object.keys(router2.children)));
300
+ return {
301
+ kind: "router",
302
+ ...first.meta === void 0 ? {} : { meta: first.meta },
303
+ children: Object.fromEntries(
304
+ [...keys].map((key) => {
305
+ const children = /* @__PURE__ */ new Map();
306
+ for (const [accountId, router2] of routers) {
307
+ const child = Object.hasOwn(router2.children, key) ? router2.children[key] : void 0;
308
+ if (child !== void 0) children.set(accountId, child);
309
+ }
310
+ return [key, combineNode(children)];
311
+ })
312
+ )
313
+ };
314
+ }
315
+ }
316
+ };
317
+ var narrow = (variants, is) => {
318
+ const narrowed = /* @__PURE__ */ new Map();
319
+ for (const [accountId, node] of variants) {
320
+ if (!is(node)) throw new Error("Each account's router must have the same shape");
321
+ narrowed.set(accountId, node);
322
+ }
323
+ return narrowed;
324
+ };
325
+ var accountRouter = (accounts, discover, options) => Effect_exports.runPromise(
222
326
  Effect_exports.gen(function* () {
223
- const queries = /* @__PURE__ */ new Map();
224
- const mutations = /* @__PURE__ */ new Map();
225
- const sources = /* @__PURE__ */ new Map();
327
+ const routers = /* @__PURE__ */ new Map();
226
328
  for (const account of accounts) {
227
- const operations = yield* Effect_exports.tryPromise({
329
+ const declaration2 = yield* Effect_exports.tryPromise({
228
330
  try: () => discover(account),
229
331
  catch: (error) => accountProviderError(error, account.id)
230
332
  });
231
- if (sources.has(account.id))
333
+ if (routers.has(account.id))
232
334
  return yield* Effect_exports.die(new Error("Account selections must be unique"));
233
- if (operations.dynamicTools !== void 0) sources.set(account.id, operations.dynamicTools);
234
- for (const [source, target] of [
235
- [operations.queries, queries],
236
- [operations.mutations, mutations]
237
- ]) {
238
- for (const [name, declaration2] of Object.entries(source ?? {})) {
239
- const operation = nativeOperation(declaration2);
240
- if (operation === void 0)
241
- return yield* Effect_exports.die(new Error("Expected a protocol operation"));
242
- const group = target.get(name) ?? /* @__PURE__ */ new Map();
243
- if (group.has(account.id))
244
- return yield* Effect_exports.die(new Error("Account selections must be unique"));
245
- group.set(account.id, operation);
246
- target.set(name, group);
247
- }
248
- }
335
+ const router2 = nativeRouter(declaration2);
336
+ if (router2 === void 0) return yield* Effect_exports.die(new Error("Expected a protocol router"));
337
+ routers.set(account.id, router2);
249
338
  }
250
- const declared = {
251
- queries: combine("query", queries),
252
- mutations: combine("mutation", mutations)
253
- };
254
- if (sources.size === 0) return declared;
255
- const grouped = (read) => Effect_exports.gen(function* () {
256
- const groups = /* @__PURE__ */ new Map();
257
- for (const [accountId, source] of sources) {
258
- const tools = yield* read(source).pipe(
259
- Effect_exports.mapError((error) => accountProviderError(error, accountId))
260
- );
261
- for (const tool of tools) {
262
- const variants = groups.get(tool.name) ?? [];
263
- if (variants.some(([id2]) => id2 === accountId))
264
- return yield* Effect_exports.die(new Error("Duplicate source operation"));
265
- variants.push([accountId, tool]);
266
- groups.set(tool.name, variants);
267
- }
268
- }
269
- return groups;
270
- });
271
- return {
272
- ...declared,
273
- dynamicTools: {
274
- list: () => grouped((source) => source.list()).pipe(
275
- Effect_exports.map((groups) => [...groups].map(([name, variants]) => merge(name, variants)))
276
- ),
277
- summaries: () => grouped(
278
- (source) => source.summaries === void 0 ? source.list() : source.summaries()
279
- ).pipe(
280
- Effect_exports.map(
281
- (groups) => [...groups].map(([name, variants]) => mergeSummary(name, variants))
282
- )
283
- ),
284
- describe: (name) => Effect_exports.gen(function* () {
285
- const variants = [];
286
- for (const [accountId, source] of sources) {
287
- 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)));
288
- if (tool !== void 0) variants.push([accountId, tool]);
289
- }
290
- return variants.length === 0 ? void 0 : merge(name, variants);
291
- }),
292
- resolve: (name) => Effect_exports.gen(function* () {
293
- const kind = name.startsWith("queries.") ? "query" : "mutation";
294
- const operations = /* @__PURE__ */ new Map();
295
- for (const [accountId, source] of sources) {
296
- const operation = yield* source.resolve(name).pipe(Effect_exports.mapError((error) => accountProviderError(error, accountId)));
297
- if (operation !== void 0) {
298
- if (operation.kind !== kind)
299
- return yield* Effect_exports.die(new Error("Operation kind changed"));
300
- operations.set(accountId, operation);
301
- }
302
- }
303
- if (operations.size === 0) return void 0;
304
- return nativeOperation(combine(kind, /* @__PURE__ */ new Map([[name, operations]]))[name]);
305
- })
306
- }
307
- };
339
+ if (routers.size === 0) return routerDeclaration({ kind: "router", children: {} });
340
+ const combined = combineNode(routers);
341
+ if (combined.kind !== "router" && combined.kind !== "dynamic")
342
+ return yield* Effect_exports.die(new Error("Expected a protocol router"));
343
+ return routerDeclaration(combined);
308
344
  }),
309
345
  options
310
346
  );
311
347
 
312
- // src/implementation/dynamic-tools.ts
313
- var dynamicTools = (source) => ({
314
- list: () => fromPromise(source.list)().pipe(
315
- Effect_exports.flatMap(Schema_exports.decodeUnknownEffect(Schema_exports.Array(HostedTool)))
316
- ),
317
- resolve: (name) => fromPromise(source.resolve)(name).pipe(
318
- Effect_exports.map((value) => {
319
- if (value === void 0) return void 0;
320
- const operation = nativeOperation(value);
321
- if (operation === void 0) throw new Error("Expected an operation declaration");
322
- return operation;
323
- })
324
- )
325
- });
326
-
327
348
  // src/implementation/dynamic-skills.ts
328
349
  var dynamicSkills = (source) => ({
329
350
  list: fromPromise(async () => source.list())
@@ -365,11 +386,26 @@ var cron = (calendar, operation, input) => declaration(
365
386
  );
366
387
 
367
388
  // src/index.ts
389
+ var isFields = (value) => typeof value === "object" && value !== null && Object.values(value).every(isSchema);
390
+ var accountDecoder = (schema) => (
391
+ // SAFETY: the brand exists only in types; secret values are strings at runtime.
392
+ decoderOf(schema)
393
+ );
394
+ var exposureOf = (schema) => {
395
+ const marked = "fields" in schema && isFields(schema.fields) ? fieldExposure(schema.fields) : {};
396
+ return Object.keys(marked).length === 0 ? {} : { exposure: marked };
397
+ };
368
398
  var OAuth2AccessToken2 = wrap(OAuth2AccessToken, false);
369
- var secrets2 = (options) => secrets({ label: options.label, fields: decoderOf(options.fields) });
399
+ var secrets2 = (options) => secrets({
400
+ label: options.label,
401
+ fields: accountDecoder(options.fields),
402
+ ...exposureOf(options.fields)
403
+ });
370
404
  function oauth22(options) {
371
405
  const { response = OAuth2AccessToken2, ...config } = options;
372
- return Effect_exports.runSync(oauth2(config, decoderOf(response)));
406
+ return Effect_exports.runSync(
407
+ oauth2(config, accountDecoder(response), exposureOf(response).exposure)
408
+ );
373
409
  }
374
410
  var decodeJson2 = (response, schema) => {
375
411
  const native = {
@@ -388,6 +424,8 @@ var decodeJson2 = (response, schema) => {
388
424
  export {
389
425
  CacheError,
390
426
  ElicitationFailed,
427
+ FetchOptionUnsupported,
428
+ NetworkRefused,
391
429
  NonRetryableError,
392
430
  NotImplemented,
393
431
  OAuth2AccessToken2 as OAuth2AccessToken,
@@ -396,7 +434,7 @@ export {
396
434
  ResponseStatusError,
397
435
  ValidationError,
398
436
  WorkflowFailure,
399
- accountOperations,
437
+ accountRouter,
400
438
  array,
401
439
  boolean,
402
440
  cron,
@@ -404,8 +442,8 @@ export {
404
442
  defineApp,
405
443
  defineDatabase,
406
444
  defineProvider,
445
+ dynamicRouter,
407
446
  dynamicSkills,
408
- dynamicTools,
409
447
  id,
410
448
  interval,
411
449
  json,
@@ -415,12 +453,17 @@ export {
415
453
  number,
416
454
  oauth22 as oauth2,
417
455
  object,
456
+ plain,
418
457
  query,
458
+ raw,
419
459
  record,
460
+ router,
420
461
  secrets2 as secrets,
421
462
  string,
422
463
  table,
464
+ toolAnnotations,
423
465
  userId,
424
466
  withApproval,
467
+ withApprovals,
425
468
  workflow
426
469
  };
package/js/mcp/effect.js CHANGED
@@ -1,31 +1,33 @@
1
1
  import {
2
2
  mcpClientEffect,
3
+ mcpHealthEffect,
3
4
  mcpToolsEffect
4
- } from "../chunk-HDTGZWP2.js";
5
- import "../chunk-RN2MXB4R.js";
5
+ } from "../chunk-IMCEF6KE.js";
6
+ import "../chunk-AE4FWJQU.js";
6
7
  import "../chunk-BCSNKUAC.js";
7
- import "../chunk-J7O55ZV7.js";
8
- import "../chunk-D47C7KG5.js";
9
- import "../chunk-FDNTX5QJ.js";
10
- import "../chunk-JN55AYQH.js";
11
- import "../chunk-PLCMJREA.js";
12
- import "../chunk-PYUYJRSK.js";
13
- import "../chunk-ZJWDMTE3.js";
14
- import "../chunk-MYYEW3RA.js";
15
- import "../chunk-BMOIAIVR.js";
16
- import "../chunk-LGIYBDWA.js";
17
- import "../chunk-YEJOQEII.js";
18
- import "../chunk-SWPD52J7.js";
19
- import "../chunk-W7D7WVSY.js";
20
- import "../chunk-ZCAMUXSG.js";
21
- import "../chunk-HDJH3RPR.js";
22
- import "../chunk-QKHR7BMF.js";
23
- import "../chunk-WFSQXYUT.js";
24
- import "../chunk-FZJOYIZO.js";
25
- import "../chunk-SATWJKN6.js";
26
- import "../chunk-FW5HBOIK.js";
8
+ import "../chunk-6NK26ONC.js";
9
+ import "../chunk-VUVBMNKC.js";
10
+ import "../chunk-PUC24GZP.js";
11
+ import "../chunk-4N26L465.js";
12
+ import "../chunk-OI5CKSBU.js";
13
+ import "../chunk-XBQTJP76.js";
14
+ import "../chunk-6VWYEQ4X.js";
15
+ import "../chunk-KQCMHI3K.js";
16
+ import "../chunk-BSRU52RU.js";
17
+ import "../chunk-M2KEEOIQ.js";
18
+ import "../chunk-BRGF7VFN.js";
19
+ import "../chunk-MYCVMDWI.js";
20
+ import "../chunk-WGBI5MVX.js";
21
+ import "../chunk-BBTELEAN.js";
22
+ import "../chunk-YML53Z7H.js";
23
+ import "../chunk-BTJMXW4I.js";
24
+ import "../chunk-PWF2DRJ3.js";
25
+ import "../chunk-2D2PKLGQ.js";
26
+ import "../chunk-XGN5IFOZ.js";
27
+ import "../chunk-NXTXZ635.js";
27
28
  import "../chunk-CZ7CSFO4.js";
28
29
  export {
29
30
  mcpClientEffect,
31
+ mcpHealthEffect,
30
32
  mcpToolsEffect
31
33
  };