apps 0.0.1-beta.13 → 0.0.1-beta.132

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 (205) hide show
  1. package/README.md +60 -42
  2. package/framework-reference.json +1 -1
  3. package/js/{chunk-M3B3DE4K.js → chunk-2XDCAXAR.js} +612 -246
  4. package/js/{chunk-IPI4MFSN.js → chunk-34RH47V5.js} +2 -2
  5. package/js/{chunk-RFVIONFX.js → chunk-36COQXTI.js} +136 -45
  6. package/js/{chunk-ODEIDRGW.js → chunk-3PIXIKHR.js} +1152 -504
  7. package/js/chunk-5SSWQNLR.js +449 -0
  8. package/js/{chunk-KUMBKVJD.js → chunk-6QZVXLF2.js} +2 -2
  9. package/js/chunk-7MPPHKRW.js +5418 -0
  10. package/js/chunk-AYXVIAPV.js +335 -0
  11. package/js/chunk-H2K7OZ47.js +90 -0
  12. package/js/chunk-I6QAWNUM.js +161 -0
  13. package/js/chunk-IMTTIZID.js +576 -0
  14. package/js/chunk-JYH7YLV7.js +49 -0
  15. package/js/{chunk-QS6CAHKC.js → chunk-KVZRGT5A.js} +4 -3
  16. package/js/chunk-LSOHA2RH.js +88 -0
  17. package/js/{chunk-UK573G7W.js → chunk-MB6L5YZE.js} +1817 -632
  18. package/js/chunk-OBT33ZDK.js +95 -0
  19. package/js/chunk-OD3KFKZD.js +1617 -0
  20. package/js/chunk-PZQCBLMC.js +175 -0
  21. package/js/{chunk-JU7VHODU.js → chunk-QTX7OUFH.js} +65 -10
  22. package/js/{chunk-VFZKSM3T.js → chunk-VX36SA7Y.js} +3 -3
  23. package/js/{chunk-5T57N25Q.js → chunk-WXHRUWNT.js} +651 -70
  24. package/js/chunk-XNDA3277.js +724 -0
  25. package/js/{chunk-CDL5PM2Q.js → chunk-YFSOSNF3.js} +17265 -12477
  26. package/js/chunk-YRAKYZJP.js +1945 -0
  27. package/js/{chunk-IJX4CYZO.js → chunk-YVN2AMAU.js} +976 -447
  28. package/js/chunk-YYLI5HVR.js +1016 -0
  29. package/js/client.js +234 -92
  30. package/js/contracts.js +154 -21
  31. package/js/effect.js +18 -19
  32. package/js/{es-APDZKREY.js → es-DIULA3ZF.js} +62 -1659
  33. package/js/graphql.js +231 -188
  34. package/js/host.js +138 -80
  35. package/js/index.js +153 -300
  36. package/js/mcp/effect.js +21 -21
  37. package/js/mcp.js +91 -57
  38. package/js/openapi.js +4357 -1415
  39. package/js/react.js +2 -3
  40. package/js/skills/effect.js +6 -3
  41. package/js/skills.js +220 -81
  42. package/js/storage/facet.js +1 -540
  43. package/js/ui/auth/contracts.js +2 -2
  44. package/js/ui/auth.js +5 -5
  45. package/js/ui/contracts.js +9 -8
  46. package/js/ui/serving.js +8618 -235
  47. package/package.json +3 -8
  48. package/runtime.json +1 -1
  49. package/types/app-cache/src/contracts/cache.d.ts +18 -0
  50. package/types/app-cache/src/index.d.ts +34 -2
  51. package/types/apps/src/contracts/api-response-error.d.ts +4 -0
  52. package/types/apps/src/contracts/app.d.ts +56 -11
  53. package/types/apps/src/contracts/cache.d.ts +20 -0
  54. package/types/apps/src/contracts/context.d.ts +60 -17
  55. package/types/apps/src/contracts/elicitation.d.ts +23 -7
  56. package/types/apps/src/contracts/events.d.ts +94 -0
  57. package/types/apps/src/contracts/failure.d.ts +30 -1
  58. package/types/apps/src/contracts/graphql.d.ts +40 -2
  59. package/types/apps/src/contracts/help-text.d.ts +31 -0
  60. package/types/apps/src/contracts/host.d.ts +1493 -20
  61. package/types/apps/src/contracts/icons.d.ts +28 -0
  62. package/types/apps/src/contracts/live.d.ts +2 -0
  63. package/types/apps/src/contracts/mcp.d.ts +81 -20
  64. package/types/apps/src/contracts/network.d.ts +120 -0
  65. package/types/apps/src/contracts/openapi-compile.d.ts +82 -3
  66. package/types/apps/src/contracts/openapi-document.d.ts +1 -1
  67. package/types/apps/src/contracts/openapi.d.ts +40 -8
  68. package/types/apps/src/contracts/operations.d.ts +14 -7
  69. package/types/apps/src/contracts/placement.d.ts +102 -0
  70. package/types/apps/src/contracts/protocol-version.d.ts +2 -2
  71. package/types/apps/src/contracts/protocols/1.d.ts +513 -15
  72. package/types/apps/src/contracts/protocols/10.d.ts +1450 -0
  73. package/types/apps/src/contracts/protocols/11.d.ts +1149 -0
  74. package/types/apps/src/contracts/protocols/12.d.ts +3310 -0
  75. package/types/apps/src/contracts/protocols/13.d.ts +6001 -0
  76. package/types/apps/src/contracts/protocols/2.d.ts +9 -8
  77. package/types/apps/src/contracts/protocols/3.d.ts +73 -15
  78. package/types/apps/src/contracts/protocols/4.d.ts +22 -15
  79. package/types/apps/src/contracts/protocols/5.d.ts +37 -11
  80. package/types/apps/src/contracts/protocols/6.d.ts +1629 -0
  81. package/types/apps/src/contracts/protocols/7.d.ts +1785 -0
  82. package/types/apps/src/contracts/protocols/8.d.ts +1182 -0
  83. package/types/apps/src/contracts/protocols/9.d.ts +1104 -0
  84. package/types/apps/src/contracts/protocols/current.d.ts +7114 -0
  85. package/types/apps/src/contracts/protocols/oauth-6.d.ts +74 -0
  86. package/types/apps/src/contracts/protocols/oauth.d.ts +134 -0
  87. package/types/apps/src/contracts/provider-error.d.ts +9 -0
  88. package/types/apps/src/contracts/provider.d.ts +56 -0
  89. package/types/apps/src/contracts/router.d.ts +2 -1
  90. package/types/apps/src/contracts/schedules.d.ts +7 -1
  91. package/types/apps/src/contracts/schema.d.ts +21 -0
  92. package/types/apps/src/contracts/shared-catalog.d.ts +11 -0
  93. package/types/apps/src/contracts/skills.d.ts +50 -13
  94. package/types/apps/src/contracts/sql.d.ts +63 -0
  95. package/types/apps/src/contracts/ui.d.ts +70 -30
  96. package/types/apps/src/contracts/webhooks.d.ts +24 -7
  97. package/types/apps/src/contracts/workflows.d.ts +56 -34
  98. package/types/apps/src/facet.d.ts +4 -5
  99. package/types/apps/src/host.d.ts +5 -0
  100. package/types/apps/src/implementation/account-router.d.ts +20 -3
  101. package/types/apps/src/implementation/app.d.ts +41 -14
  102. package/types/apps/src/implementation/authoring.d.ts +25 -5
  103. package/types/apps/src/implementation/browser-scripts.gen.d.ts +6 -0
  104. package/types/apps/src/implementation/cache.d.ts +29 -2
  105. package/types/apps/src/implementation/catalog-cache.d.ts +35 -4
  106. package/types/apps/src/implementation/elicitation.d.ts +16 -13
  107. package/types/apps/src/implementation/events.d.ts +64 -0
  108. package/types/apps/src/implementation/failure-detail.d.ts +28 -5
  109. package/types/apps/src/implementation/graphql-catalog.d.ts +3 -3
  110. package/types/apps/src/implementation/graphql.d.ts +4 -3
  111. package/types/apps/src/implementation/help-text.d.ts +5 -0
  112. package/types/apps/src/implementation/input-problems.d.ts +6 -2
  113. package/types/apps/src/implementation/invocation-timing.d.ts +18 -0
  114. package/types/apps/src/implementation/live.d.ts +2 -2
  115. package/types/apps/src/implementation/mcp-call.d.ts +6 -5
  116. package/types/apps/src/implementation/mcp-catalog.d.ts +6 -4
  117. package/types/apps/src/implementation/mcp-client.d.ts +17 -9
  118. package/types/apps/src/implementation/mcp-tools.d.ts +2 -1
  119. package/types/apps/src/implementation/mcp.d.ts +20 -9
  120. package/types/apps/src/implementation/network.d.ts +16 -0
  121. package/types/apps/src/implementation/openapi-compile.d.ts +38 -7
  122. package/types/apps/src/implementation/openapi-document.d.ts +50 -20
  123. package/types/apps/src/implementation/openapi-names.d.ts +9 -4
  124. package/types/apps/src/implementation/openapi-request.d.ts +10 -2
  125. package/types/apps/src/implementation/openapi-source.d.ts +23 -1
  126. package/types/apps/src/implementation/openapi-upgrade.d.ts +4 -0
  127. package/types/apps/src/implementation/operations.d.ts +58 -7
  128. package/types/apps/src/implementation/optimistic.d.ts +1 -1
  129. package/types/apps/src/implementation/placement.d.ts +60 -0
  130. package/types/apps/src/implementation/protocol-operations.d.ts +3 -0
  131. package/types/apps/src/implementation/provider-error.d.ts +28 -1
  132. package/types/apps/src/implementation/provider.d.ts +20 -4
  133. package/types/apps/src/implementation/query-commit.d.ts +1 -1
  134. package/types/apps/src/implementation/router-catalog.d.ts +22 -97
  135. package/types/apps/src/implementation/router.d.ts +26 -6
  136. package/types/apps/src/implementation/runtime-yield.d.ts +7 -0
  137. package/types/apps/src/implementation/schedules.d.ts +39 -8
  138. package/types/apps/src/implementation/schema.d.ts +125 -17
  139. package/types/apps/src/implementation/skills.d.ts +18 -24
  140. package/types/apps/src/implementation/sql.d.ts +71 -0
  141. package/types/apps/src/implementation/ui-account-notice.d.ts +9 -0
  142. package/types/apps/src/implementation/ui-auth.d.ts +1 -1
  143. package/types/apps/src/implementation/ui-client.d.ts +3 -3
  144. package/types/apps/src/implementation/ui-document.d.ts +5 -0
  145. package/types/apps/src/implementation/ui-errors.d.ts +1 -1
  146. package/types/apps/src/implementation/ui-serving.d.ts +38 -12
  147. package/types/apps/src/implementation/upstream-error.d.ts +17 -0
  148. package/types/apps/src/implementation/webhooks.d.ts +15 -6
  149. package/types/apps/src/implementation/workflow-context.d.ts +6 -2
  150. package/types/apps/src/implementation/workflows.d.ts +11 -4
  151. package/types/apps/src/index.d.ts +67 -17
  152. package/types/apps/src/mcp.d.ts +20 -1
  153. package/types/apps/src/openapi.d.ts +22 -1
  154. package/types/apps/src/react.d.ts +1 -1
  155. package/types/apps/src/skills.d.ts +10 -8
  156. package/types/apps/src/ui-serving.d.ts +1 -2
  157. package/types/telemetry/src/app-records.d.ts +42 -0
  158. package/types/telemetry/src/browser-operations.d.ts +2 -2
  159. package/types/telemetry/src/browser.d.ts +8 -3
  160. package/types/telemetry/src/config.d.ts +2 -2
  161. package/types/telemetry/src/index.d.ts +3 -2
  162. package/types/telemetry/src/keepalive.d.ts +36 -0
  163. package/types/telemetry/src/layer.d.ts +10 -4
  164. package/types/telemetry/src/measurements.d.ts +6 -2
  165. package/types/telemetry/src/ownership.d.ts +60 -0
  166. package/types/telemetry/src/recorded-failure.d.ts +29 -0
  167. package/types/telemetry/src/relay.d.ts +32 -7
  168. package/types/telemetry/src/span-attributes.d.ts +22 -3
  169. package/types/telemetry/src/transport.d.ts +8 -1
  170. package/types/utils/src/api-error.d.ts +55 -0
  171. package/types/utils/src/connection-failure.d.ts +33 -0
  172. package/types/utils/src/legacy-keys.d.ts +20 -0
  173. package/types/utils/src/random-uuid.d.ts +6 -0
  174. package/types/utils/src/recorded-message.d.ts +18 -0
  175. package/types/utils/src/schema-definitions.d.ts +13 -0
  176. package/types/utils/src/user-facing-error.d.ts +83 -0
  177. package/js/chunk-27F7W2LG.js +0 -34
  178. package/js/chunk-4ASNKGCV.js +0 -242
  179. package/js/chunk-4DWF4ZWI.js +0 -1280
  180. package/js/chunk-57RKNWL2.js +0 -75
  181. package/js/chunk-6HSH75OI.js +0 -2688
  182. package/js/chunk-G4FT53I7.js +0 -224
  183. package/js/chunk-MKWZPDR6.js +0 -63
  184. package/js/chunk-N7YDVXYJ.js +0 -186
  185. package/js/chunk-NKLWZJLE.js +0 -172
  186. package/js/chunk-PJJ24GU7.js +0 -877
  187. package/js/chunk-PZB6T6KU.js +0 -19
  188. package/js/chunk-R3EV5FTO.js +0 -97
  189. package/js/chunk-S73JGVR5.js +0 -507
  190. package/js/chunk-TG6DOCRO.js +0 -299
  191. package/js/chunk-YPKG2QO5.js +0 -209
  192. package/js/chunk-ZQINWV4W.js +0 -630
  193. package/js/mcp/stdio.js +0 -128
  194. package/types/app-data/src/implementation/cursor.d.ts +0 -10
  195. package/types/app-data/src/implementation/index-key.d.ts +0 -7
  196. package/types/app-data/src/implementation/promise.d.ts +0 -68
  197. package/types/app-data/src/implementation/range.d.ts +0 -8
  198. package/types/app-data/src/implementation/schema.d.ts +0 -18
  199. package/types/app-data/src/implementation/sqlite.d.ts +0 -11
  200. package/types/app-data/src/index.d.ts +0 -4
  201. package/types/apps/src/contracts/storage.d.ts +0 -68
  202. package/types/apps/src/implementation/mcp-stdio.d.ts +0 -4
  203. package/types/apps/src/implementation/storage.d.ts +0 -15
  204. package/types/apps/src/implementation/ui-watch.d.ts +0 -2
  205. package/types/apps/src/mcp-stdio.d.ts +0 -5
@@ -0,0 +1,576 @@
1
+ import {
2
+ accountProviderError,
3
+ fromPromise
4
+ } from "./chunk-PZQCBLMC.js";
5
+ import {
6
+ HostedTool,
7
+ HostedToolSummary,
8
+ RouterKey,
9
+ RouterMeta,
10
+ reservedRouterKeys
11
+ } from "./chunk-7MPPHKRW.js";
12
+ import {
13
+ combineJsonSchemas,
14
+ decoderOf,
15
+ importedJsonSchema,
16
+ once,
17
+ schemaArgument,
18
+ withLazyJsonSchemaDocument
19
+ } from "./chunk-WXHRUWNT.js";
20
+ import {
21
+ JsonObject
22
+ } from "./chunk-H2K7OZ47.js";
23
+ import {
24
+ Effect_exports,
25
+ Result_exports,
26
+ Schema_exports
27
+ } from "./chunk-YFSOSNF3.js";
28
+
29
+ // src/implementation/operations.ts
30
+ var NativeOperation = /* @__PURE__ */ Symbol("apps.Operation");
31
+ var NativeRouterKey = /* @__PURE__ */ Symbol("apps.Router");
32
+ var operationDeclaration = (operation) => ({
33
+ kind: operation.kind,
34
+ [NativeOperation]: operation
35
+ });
36
+ var nativeOperation = (value) => {
37
+ if (typeof value !== "object" || value === null || !(NativeOperation in value)) return void 0;
38
+ return value[NativeOperation];
39
+ };
40
+ var operationOptions = (options) => {
41
+ const approval = options.approval;
42
+ return {
43
+ ...options.description === void 0 ? {} : { description: options.description },
44
+ ...options.title === void 0 ? {} : { title: options.title },
45
+ ...options.annotations === void 0 ? {} : { annotations: options.annotations },
46
+ ...options._meta === void 0 ? {} : { _meta: options._meta },
47
+ input: decoderOf(options.input),
48
+ ...approval === void 0 ? {} : {
49
+ approval: (context) => fromPromise(async () => approval(context), "approval")()
50
+ }
51
+ };
52
+ };
53
+ var approvedOperation = (operation, approval) => {
54
+ const copy = Object.defineProperties({}, Object.getOwnPropertyDescriptors(operation));
55
+ return Object.defineProperty(copy, "approval", {
56
+ enumerable: true,
57
+ value: (context) => fromPromise(async () => approval(context), "approval")()
58
+ });
59
+ };
60
+ var withApproval = (operation, approval) => (
61
+ // SAFETY: `Approved` is a type-only mark; the native operation now carries the approval.
62
+ {
63
+ ...operation,
64
+ [NativeOperation]: approvedOperation(operation[NativeOperation], approval)
65
+ }
66
+ );
67
+ var toolAnnotations = (operation) => nativeOperation(operation)?.annotations;
68
+ var make = (kind, options, run) => operationDeclaration({
69
+ ...operationOptions({ ...options, input: schemaArgument(options.input, `The ${kind} input`) }),
70
+ kind,
71
+ // The host always validates JSON serialization, even without a stronger output declaration.
72
+ ...options.output === void 0 ? {} : { output: decoderOf(schemaArgument(options.output, `The ${kind} output`)) },
73
+ // SAFETY: defineApp checks the handler context against its requirements.
74
+ // The host validates account bindings and creates the matching storage facade.
75
+ run: (context, input) => fromPromise(run, "handler")(context, input)
76
+ });
77
+ var query = (options, run) => make("query", options, run);
78
+ function mutation(options, run) {
79
+ return make("mutation", options, run);
80
+ }
81
+
82
+ // src/implementation/router.ts
83
+ var routerDeclaration = (node) => ({
84
+ [NativeRouterKey]: node
85
+ });
86
+ var nativeRouter = (value) => {
87
+ if (typeof value !== "object" || value === null || !(NativeRouterKey in value)) return void 0;
88
+ return value[NativeRouterKey];
89
+ };
90
+ var nativeNode = (value) => nativeOperation(value) ?? nativeRouter(value);
91
+ var metaOf = (options) => {
92
+ if (options === void 0) return void 0;
93
+ const defined = Object.fromEntries(
94
+ Object.entries(options).filter(([, value]) => value !== void 0)
95
+ );
96
+ return Object.keys(defined).length === 0 ? void 0 : Schema_exports.decodeUnknownSync(RouterMeta)(defined);
97
+ };
98
+ var mergeMeta = (base, override) => base === void 0 ? override : override === void 0 ? base : { ...base, ...override };
99
+ function router(children, options) {
100
+ const meta = metaOf(options);
101
+ const existing = nativeRouter(children);
102
+ if (existing !== void 0)
103
+ return routerDeclaration(
104
+ existing.kind === "router" ? { ...existing, ...withMeta(mergeMeta(existing.meta, meta)) } : { ...existing, ...withOverrides(mergeMeta(existing.overrides, meta)) }
105
+ );
106
+ const nodes = {};
107
+ for (const [key, value] of Object.entries(children)) {
108
+ if (reservedRouterKeys.has(key)) throw new Error(`Router key "${key}" is reserved`);
109
+ if (!Schema_exports.is(RouterKey)(key))
110
+ throw new Error(`Router key "${key}" must start with a letter or _ and contain no dots`);
111
+ const node = nativeNode(value);
112
+ if (node === void 0)
113
+ throw new Error(`Router key "${key}" must be a query, mutation or router`);
114
+ nodes[key] = node;
115
+ }
116
+ return routerDeclaration({ kind: "router", ...withMeta(meta), children: nodes });
117
+ }
118
+ var withMeta = (meta) => meta === void 0 ? {} : { meta };
119
+ var withOverrides = (overrides) => overrides === void 0 ? {} : { overrides };
120
+ var dynamicRouter = (source) => {
121
+ const meta = source.meta;
122
+ return routerDeclaration({
123
+ kind: "dynamic",
124
+ ...meta === void 0 ? {} : {
125
+ meta: () => fromPromise(async () => meta(), "router")().pipe(
126
+ Effect_exports.flatMap((options) => Schema_exports.decodeUnknownEffect(RouterMeta)(options))
127
+ )
128
+ },
129
+ list: () => fromPromise(async () => source.list(), "router")().pipe(
130
+ Effect_exports.flatMap(Schema_exports.decodeUnknownEffect(Schema_exports.Array(HostedTool)))
131
+ ),
132
+ resolve: (name) => fromPromise(async () => source.resolve(name), "router")().pipe(
133
+ Effect_exports.map((value) => {
134
+ if (value === void 0) return void 0;
135
+ const operation = nativeOperation(value);
136
+ if (operation === void 0) throw new Error("Expected an operation declaration");
137
+ return operation;
138
+ })
139
+ )
140
+ });
141
+ };
142
+ var joinPath = (path, name) => path === "" ? name : `${path}.${name}`;
143
+ var locate = (root, name) => {
144
+ if (root?.kind === "dynamic") return { kind: "dynamic", source: root, router: "", name };
145
+ let current = root;
146
+ let path = "";
147
+ let rest = name;
148
+ while (current !== void 0) {
149
+ const dot = rest.indexOf(".");
150
+ const key = dot < 0 ? rest : rest.slice(0, dot);
151
+ const child = Object.hasOwn(current.children, key) ? current.children[key] : void 0;
152
+ if (child === void 0) return void 0;
153
+ const remaining = dot < 0 ? void 0 : rest.slice(dot + 1);
154
+ switch (child.kind) {
155
+ case "query":
156
+ case "mutation":
157
+ return remaining === void 0 ? { kind: "operation", operation: child, router: path } : void 0;
158
+ case "dynamic":
159
+ return remaining === void 0 || remaining === "" ? void 0 : { kind: "dynamic", source: child, router: joinPath(path, key), name: remaining };
160
+ case "router":
161
+ if (remaining === void 0) return void 0;
162
+ current = child;
163
+ path = joinPath(path, key);
164
+ rest = remaining;
165
+ }
166
+ }
167
+ return void 0;
168
+ };
169
+ var declaredOperations = (root, path = "") => Object.entries(root?.children ?? {}).flatMap(([key, child]) => {
170
+ const name = joinPath(path, key);
171
+ switch (child.kind) {
172
+ case "query":
173
+ case "mutation":
174
+ return [{ name, router: path, operation: child }];
175
+ case "router":
176
+ return declaredOperations(child, name);
177
+ case "dynamic":
178
+ return [];
179
+ }
180
+ });
181
+ var withApprovals = (source, policy) => {
182
+ const native = nativeRouter(source);
183
+ if (native === void 0) throw new Error("withApprovals expects a router");
184
+ const operation = (node, name) => {
185
+ const approval = policy(operationDeclaration(node), name);
186
+ return approval === void 0 ? node : approvedOperation(node, approval);
187
+ };
188
+ const child = (node, name) => {
189
+ switch (node.kind) {
190
+ case "query":
191
+ case "mutation":
192
+ return operation(node, name);
193
+ case "router":
194
+ case "dynamic":
195
+ return walk(node, name);
196
+ }
197
+ };
198
+ const walk = (node, path) => node.kind === "dynamic" ? {
199
+ ...node,
200
+ resolve: (name) => node.resolve(name).pipe(
201
+ Effect_exports.flatMap(
202
+ (resolved) => resolved === void 0 ? Effect_exports.succeed(void 0) : Effect_exports.try({
203
+ try: () => operation(resolved, joinPath(path, name)),
204
+ catch: (error) => error
205
+ })
206
+ )
207
+ )
208
+ } : {
209
+ ...node,
210
+ children: Object.fromEntries(
211
+ Object.entries(node.children).map(([key, value]) => [
212
+ key,
213
+ child(value, joinPath(path, key))
214
+ ])
215
+ )
216
+ };
217
+ return routerDeclaration(walk(native, ""));
218
+ };
219
+ var renameTools = (source, rename) => {
220
+ const native = nativeRouter(source);
221
+ if (native?.kind !== "dynamic") throw new Error("renameTools expects a protocol router");
222
+ const exposed = (tools) => {
223
+ const seen = /* @__PURE__ */ new Set();
224
+ return tools.flatMap((tool) => {
225
+ const name = rename(tool.name);
226
+ if (name === void 0 || seen.has(name)) return [];
227
+ seen.add(name);
228
+ return [{ ...tool, name, source: tool.name }];
229
+ });
230
+ };
231
+ const listed = native.summaries ?? native.list;
232
+ const original = (name) => listed().pipe(Effect_exports.map((tools) => exposed(tools).find((tool) => tool.name === name)?.source));
233
+ const strip = ({
234
+ source: _source,
235
+ ...tool
236
+ }) => tool;
237
+ return routerDeclaration({
238
+ ...native,
239
+ list: () => native.list().pipe(Effect_exports.map((tools) => exposed(tools).map(strip))),
240
+ ...native.summaries === void 0 ? {} : {
241
+ summaries: () => listed().pipe(Effect_exports.map((tools) => exposed(tools).map(strip)))
242
+ },
243
+ describe: (name) => original(name).pipe(
244
+ Effect_exports.flatMap(
245
+ (found) => found === void 0 ? Effect_exports.succeed(void 0) : native.describe?.(found) ?? native.list().pipe(Effect_exports.map((tools) => tools.find((tool) => tool.name === found)))
246
+ ),
247
+ Effect_exports.map((tool) => tool === void 0 ? void 0 : { ...tool, name })
248
+ ),
249
+ resolve: (name) => original(name).pipe(
250
+ Effect_exports.flatMap(
251
+ (found) => found === void 0 ? Effect_exports.succeed(void 0) : native.resolve(found)
252
+ )
253
+ )
254
+ });
255
+ };
256
+
257
+ // src/implementation/account-router.ts
258
+ var PartialListing = class extends Schema_exports.TaggedError()("PartialListing", {
259
+ tools: Schema_exports.Array(Schema_exports.Unknown),
260
+ error: Schema_exports.Unknown
261
+ }) {
262
+ };
263
+ var decoderDocument = (decoder) => {
264
+ const imported = importedJsonSchema(decoder);
265
+ if (imported !== void 0) return Schema_exports.decodeUnknownSync(JsonObject)(imported);
266
+ const document = Schema_exports.toJsonSchemaDocument(decoder);
267
+ return Schema_exports.decodeUnknownSync(JsonObject)({ ...document.schema, $defs: document.definitions });
268
+ };
269
+ var accountBranches = (variants) => {
270
+ const groups = /* @__PURE__ */ new Map();
271
+ for (const [accountId, schema] of variants) {
272
+ const key = JSON.stringify(schema);
273
+ const group = groups.get(key);
274
+ if (group === void 0) groups.set(key, { schema, first: accountId, rest: [] });
275
+ else group.rest.push(accountId);
276
+ }
277
+ const branches = [...groups.values()];
278
+ const { $defs, schemas } = combineJsonSchemas(
279
+ branches.map(({ schema }) => schema),
280
+ (index) => `#/anyOf/${index}/properties/input`
281
+ );
282
+ return {
283
+ type: "object",
284
+ ...$defs === void 0 ? {} : { $defs },
285
+ anyOf: schemas.map((input, index) => {
286
+ const { first, rest } = branches[index];
287
+ return {
288
+ type: "object",
289
+ properties: {
290
+ accountId: rest.length === 0 ? { type: "string", const: first } : { type: "string", enum: [first, ...rest] },
291
+ input
292
+ },
293
+ required: ["accountId", "input"]
294
+ };
295
+ })
296
+ };
297
+ };
298
+ var outputBranches = (outputs) => {
299
+ const { $defs, schemas } = combineJsonSchemas(
300
+ [...new Map(outputs.map((output) => [JSON.stringify(output), output])).values()],
301
+ (index) => `#/anyOf/${index}`
302
+ );
303
+ return { ...$defs === void 0 ? {} : { $defs }, anyOf: schemas };
304
+ };
305
+ var declaresOutput = (operation) => {
306
+ if (operation.output !== void 0) return true;
307
+ const property = Object.getOwnPropertyDescriptor(operation, "outputSchema");
308
+ return property !== void 0 && (property.get !== void 0 || property.value !== void 0);
309
+ };
310
+ var outputDocument = (operation) => operation.output === void 0 ? operation.outputSchema : decoderDocument(operation.output);
311
+ var combineOperation = (accounts, failed = /* @__PURE__ */ new Map()) => {
312
+ const variants = [...accounts.values()];
313
+ const first = variants[0];
314
+ if (first === void 0) throw new Error("An account operation must have at least one account");
315
+ const kind = variants.every((operation) => operation.kind === "query") ? "query" : "mutation";
316
+ const select = (input2) => {
317
+ const operation = accounts.get(input2.accountId);
318
+ if (operation === void 0)
319
+ throw new Error("Account selection must be decoded before execution");
320
+ return operation;
321
+ };
322
+ const input = Schema_exports.Union([
323
+ ...[...accounts].map(
324
+ ([accountId, operation]) => Schema_exports.Struct({ accountId: Schema_exports.Literal(accountId), input: operation.input })
325
+ ),
326
+ ...[...failed.keys()].map(
327
+ (accountId) => Schema_exports.Struct({ accountId: Schema_exports.Literal(accountId), input: Schema_exports.Unknown })
328
+ )
329
+ ]);
330
+ const inputSchema = () => accountBranches(
331
+ [...accounts].map(([accountId, operation]) => [accountId, decoderDocument(operation.input)])
332
+ );
333
+ const declaration = operationDeclaration({
334
+ kind,
335
+ ...first.description === void 0 ? {} : { description: first.description },
336
+ ...first.title === void 0 ? {} : { title: first.title },
337
+ ...first.annotations === void 0 || !variants.every(
338
+ (operation) => JSON.stringify(operation.annotations) === JSON.stringify(first.annotations)
339
+ ) ? {} : { annotations: first.annotations },
340
+ ...first._meta === void 0 || !variants.every((operation) => JSON.stringify(operation._meta) === JSON.stringify(first._meta)) ? {} : { _meta: first._meta },
341
+ input: withLazyJsonSchemaDocument(input, inputSchema),
342
+ approval: (context) => {
343
+ if (failed.has(context.toolInput.accountId)) return Effect_exports.succeed("approved");
344
+ const operation = select(context.toolInput);
345
+ return operation.approval === void 0 ? Effect_exports.succeed("approved") : operation.approval({ ...context, toolInput: context.toolInput.input });
346
+ },
347
+ run: (context, input2) => {
348
+ if (failed.has(input2.accountId))
349
+ return Effect_exports.fail(accountProviderError(failed.get(input2.accountId), input2.accountId));
350
+ const operation = select(input2);
351
+ return operation.run(context, input2.input).pipe(
352
+ Effect_exports.mapError((error) => accountProviderError(error, input2.accountId)),
353
+ Effect_exports.flatMap(
354
+ (output) => operation.output === void 0 ? Effect_exports.succeed(output) : Schema_exports.decodeUnknownEffect(operation.output)(output)
355
+ )
356
+ );
357
+ }
358
+ });
359
+ if (variants.every(declaresOutput)) {
360
+ const outputSchema = once(
361
+ () => outputBranches(
362
+ variants.flatMap((operation) => {
363
+ const output = outputDocument(operation);
364
+ return output === void 0 ? [] : [output];
365
+ })
366
+ )
367
+ );
368
+ const native2 = nativeOperation(declaration);
369
+ if (native2 !== void 0)
370
+ Object.defineProperty(native2, "outputSchema", { enumerable: true, get: outputSchema });
371
+ }
372
+ const native = nativeOperation(declaration);
373
+ if (native === void 0) throw new Error("Expected a combined operation");
374
+ return native;
375
+ };
376
+ var sameAcross = (key, variants) => {
377
+ const first = variants[0]?.[1][key];
378
+ return first !== void 0 && variants.every(([, tool]) => JSON.stringify(tool[key]) === JSON.stringify(first)) ? { [key]: first } : {};
379
+ };
380
+ var mergeSummary = (name, variants) => {
381
+ const first = variants[0]?.[1];
382
+ if (first === void 0) throw new Error("Expected a source operation");
383
+ return Schema_exports.decodeUnknownSync(HostedToolSummary)({
384
+ name,
385
+ description: first.description,
386
+ ...first.title === void 0 ? {} : { title: first.title },
387
+ readOnly: variants.every(([, tool]) => tool.readOnly === true),
388
+ ...variants.every(([, tool]) => tool.kindConfirmed === true) ? { kindConfirmed: true } : {},
389
+ ...sameAcross("annotations", variants)
390
+ });
391
+ };
392
+ var merge = (name, variants) => Schema_exports.decodeUnknownSync(HostedTool)({
393
+ ...mergeSummary(name, variants),
394
+ inputSchema: accountBranches(
395
+ variants.map(([accountId, tool]) => [accountId, tool.inputSchema])
396
+ ),
397
+ ...variants.every(([, tool]) => tool.outputSchema !== void 0) ? {
398
+ outputSchema: outputBranches(
399
+ variants.flatMap(
400
+ ([, tool]) => tool.outputSchema === void 0 ? [] : [tool.outputSchema]
401
+ )
402
+ )
403
+ } : {},
404
+ ...sameAcross("_meta", variants)
405
+ });
406
+ var accountConcurrency = 8;
407
+ var eachAccount = (sources, read) => Effect_exports.gen(function* () {
408
+ const results = yield* Effect_exports.forEach(
409
+ sources,
410
+ ([accountId, source]) => Effect_exports.result(
411
+ read(source).pipe(Effect_exports.mapError((error) => accountProviderError(error, accountId)))
412
+ ).pipe(Effect_exports.map((result) => [accountId, result])),
413
+ { concurrency: accountConcurrency }
414
+ );
415
+ const values = /* @__PURE__ */ new Map();
416
+ const failed = /* @__PURE__ */ new Map();
417
+ for (const [accountId, result] of results)
418
+ if (Result_exports.isSuccess(result)) values.set(accountId, result.success);
419
+ else failed.set(accountId, result.failure);
420
+ return { values, failed };
421
+ });
422
+ var firstFailure = (failed) => [...failed.values()][0];
423
+ var combineDynamic = (sources) => {
424
+ const first = [...sources.values()][0];
425
+ const grouped = (read, merged) => Effect_exports.gen(function* () {
426
+ const { values: listed, failed } = yield* eachAccount(sources, read);
427
+ if (listed.size === 0 && failed.size > 0) return yield* Effect_exports.fail(firstFailure(failed));
428
+ const groups = /* @__PURE__ */ new Map();
429
+ for (const [accountId, tools2] of listed)
430
+ for (const tool of tools2) {
431
+ const variants = groups.get(tool.name) ?? [];
432
+ if (variants.some(([id]) => id === accountId))
433
+ return yield* Effect_exports.die(new Error("Duplicate source operation"));
434
+ variants.push([accountId, tool]);
435
+ groups.set(tool.name, variants);
436
+ }
437
+ const tools = [...groups].map(([name, variants]) => merged(name, variants));
438
+ if (failed.size === 0) return tools;
439
+ return yield* new PartialListing({ tools, error: firstFailure(failed) });
440
+ });
441
+ return {
442
+ kind: "dynamic",
443
+ // Accounts share one source, so the first account that can describe it describes the router.
444
+ ...first?.meta === void 0 ? {} : {
445
+ meta: () => Effect_exports.gen(function* () {
446
+ const failures = [];
447
+ for (const source of sources.values()) {
448
+ if (source.meta === void 0) continue;
449
+ const result = yield* Effect_exports.result(source.meta());
450
+ if (Result_exports.isSuccess(result)) return result.success;
451
+ failures.push(result.failure);
452
+ }
453
+ return yield* Effect_exports.fail(failures[0]);
454
+ })
455
+ },
456
+ ...first?.overrides === void 0 ? {} : { overrides: first.overrides },
457
+ list: () => grouped((source) => source.list(), merge),
458
+ summaries: () => grouped(
459
+ (source) => source.summaries === void 0 ? source.list() : source.summaries(),
460
+ mergeSummary
461
+ ),
462
+ describe: (name) => eachAccount(
463
+ sources,
464
+ (source) => source.describe === void 0 ? source.list().pipe(Effect_exports.map((tools) => tools.find((tool) => tool.name === name))) : source.describe(name)
465
+ ).pipe(
466
+ Effect_exports.flatMap(({ values, failed }) => {
467
+ const variants = [...values].flatMap(
468
+ ([accountId, tool]) => tool === void 0 ? [] : [[accountId, tool]]
469
+ );
470
+ if (variants.length === 0)
471
+ return failed.size > 0 ? Effect_exports.fail(firstFailure(failed)) : Effect_exports.succeed(void 0);
472
+ return Effect_exports.succeed(merge(name, variants));
473
+ })
474
+ ),
475
+ resolve: (name) => eachAccount(sources, (source) => source.resolve(name)).pipe(
476
+ Effect_exports.flatMap(({ values, failed }) => {
477
+ const operations = new Map(
478
+ [...values].flatMap(
479
+ ([accountId, operation]) => operation === void 0 ? [] : [[accountId, operation]]
480
+ )
481
+ );
482
+ if (operations.size === 0)
483
+ return failed.size > 0 ? Effect_exports.fail(firstFailure(failed)) : Effect_exports.succeed(void 0);
484
+ return Effect_exports.succeed(combineOperation(operations, failed));
485
+ })
486
+ )
487
+ };
488
+ };
489
+ var combineNode = (variants) => {
490
+ const nodes = [...variants.values()];
491
+ const first = nodes[0];
492
+ if (first === void 0) throw new Error("An account operation must have at least one account");
493
+ switch (first.kind) {
494
+ case "query":
495
+ case "mutation":
496
+ return combineOperation(
497
+ narrow(
498
+ variants,
499
+ (node) => node.kind === "query" || node.kind === "mutation"
500
+ )
501
+ );
502
+ case "dynamic":
503
+ return combineDynamic(
504
+ narrow(variants, (node) => node.kind === "dynamic")
505
+ );
506
+ case "router": {
507
+ const routers = narrow(variants, (node) => node.kind === "router");
508
+ const keys = new Set([...routers.values()].flatMap((router2) => Object.keys(router2.children)));
509
+ return {
510
+ kind: "router",
511
+ ...first.meta === void 0 ? {} : { meta: first.meta },
512
+ children: Object.fromEntries(
513
+ [...keys].map((key) => {
514
+ const children = /* @__PURE__ */ new Map();
515
+ for (const [accountId, router2] of routers) {
516
+ const child = Object.hasOwn(router2.children, key) ? router2.children[key] : void 0;
517
+ if (child !== void 0) children.set(accountId, child);
518
+ }
519
+ return [key, combineNode(children)];
520
+ })
521
+ )
522
+ };
523
+ }
524
+ }
525
+ };
526
+ var narrow = (variants, is) => {
527
+ const narrowed = /* @__PURE__ */ new Map();
528
+ for (const [accountId, node] of variants) {
529
+ if (!is(node)) throw new Error("Each account's router must have the same shape");
530
+ narrowed.set(accountId, node);
531
+ }
532
+ return narrowed;
533
+ };
534
+ var accountRouter = (accounts, discover, options) => Effect_exports.runPromise(
535
+ Effect_exports.gen(function* () {
536
+ const routers = /* @__PURE__ */ new Map();
537
+ for (const account of accounts) {
538
+ const declaration = yield* Effect_exports.tryPromise({
539
+ try: async () => discover(account),
540
+ catch: (error) => accountProviderError(error, account.id)
541
+ });
542
+ if (routers.has(account.id))
543
+ return yield* Effect_exports.die(new Error("Account selections must be unique"));
544
+ const router2 = nativeRouter(declaration);
545
+ if (router2 === void 0) return yield* Effect_exports.die(new Error("Expected a protocol router"));
546
+ routers.set(account.id, router2);
547
+ }
548
+ if (routers.size === 0) return routerDeclaration({ kind: "router", children: {} });
549
+ const combined = combineNode(routers);
550
+ if (combined.kind !== "router" && combined.kind !== "dynamic")
551
+ return yield* Effect_exports.die(new Error("Expected a protocol router"));
552
+ return routerDeclaration(combined);
553
+ }),
554
+ options
555
+ );
556
+
557
+ export {
558
+ operationDeclaration,
559
+ nativeOperation,
560
+ withApproval,
561
+ toolAnnotations,
562
+ query,
563
+ mutation,
564
+ routerDeclaration,
565
+ nativeRouter,
566
+ mergeMeta,
567
+ router,
568
+ dynamicRouter,
569
+ joinPath,
570
+ locate,
571
+ declaredOperations,
572
+ withApprovals,
573
+ renameTools,
574
+ PartialListing,
575
+ accountRouter
576
+ };
@@ -0,0 +1,49 @@
1
+ import {
2
+ FetchOptionUnsupported,
3
+ NetworkRefusedHeader,
4
+ RestrictedFetchOption,
5
+ networkRefusalHeader,
6
+ networkRefusalStatus,
7
+ supportedFetchOptions
8
+ } from "./chunk-7MPPHKRW.js";
9
+ import {
10
+ invocationFetch
11
+ } from "./chunk-3PIXIKHR.js";
12
+ import {
13
+ Effect_exports,
14
+ Schema_exports
15
+ } from "./chunk-YFSOSNF3.js";
16
+
17
+ // src/implementation/network.ts
18
+ var refusalHeader = (status, header) => status === networkRefusalStatus && header !== null && header !== void 0 ? header : void 0;
19
+ var failOnNetworkRefusal = (response) => {
20
+ const header = refusalHeader(response.status, response.headers[networkRefusalHeader]);
21
+ return header === void 0 ? Effect_exports.void : Schema_exports.decodeUnknownEffect(NetworkRefusedHeader)(header).pipe(
22
+ Effect_exports.orDie,
23
+ Effect_exports.flatMap(Effect_exports.fail)
24
+ );
25
+ };
26
+ var unsupportedOption = (init) => {
27
+ for (const option of RestrictedFetchOption.literals) {
28
+ const value = init?.[option];
29
+ const supported = supportedFetchOptions[option];
30
+ if (value !== void 0 && !supported.includes(value))
31
+ return new FetchOptionUnsupported({ option, value: String(value), supported });
32
+ }
33
+ return void 0;
34
+ };
35
+ var appFetch = (fetch) => async (input, init) => {
36
+ const unsupported = unsupportedOption(init);
37
+ if (unsupported !== void 0) throw unsupported;
38
+ const response = await fetch(input, init);
39
+ const header = refusalHeader(response.status, response.headers.get(networkRefusalHeader));
40
+ if (header === void 0) return response;
41
+ await response.body?.cancel();
42
+ throw Schema_exports.decodeUnknownSync(NetworkRefusedHeader)(header);
43
+ };
44
+ var appInvocationFetch = (signal) => invocationFetch(signal).pipe(Effect_exports.map(appFetch));
45
+
46
+ export {
47
+ failOnNetworkRefusal,
48
+ appInvocationFetch
49
+ };
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  fixedRouter
3
- } from "./chunk-S73JGVR5.js";
3
+ } from "./chunk-YYLI5HVR.js";
4
4
  import {
5
5
  nativeOperation,
6
6
  operationDeclaration,
7
7
  routerDeclaration
8
- } from "./chunk-YPKG2QO5.js";
8
+ } from "./chunk-IMTTIZID.js";
9
9
 
10
10
  // src/implementation/protocol-operations.ts
11
11
  var protocolOperations = (operations, kinds = {}) => {
@@ -18,10 +18,11 @@ var protocolOperations = (operations, kinds = {}) => {
18
18
  ...operation.annotations === void 0 ? {} : { annotations: operation.annotations },
19
19
  ...operation._meta === void 0 ? {} : { _meta: operation._meta },
20
20
  input: operation.input,
21
+ ...operation.output === void 0 ? {} : { output: operation.output },
21
22
  run: operation.run
22
23
  };
23
24
  const output = Object.getOwnPropertyDescriptor(operation, "outputSchema");
24
- const withOutput = (target) => output === void 0 || output.get === void 0 && output.value === void 0 ? target : Object.defineProperty(target, "outputSchema", { ...output, enumerable: true });
25
+ const withOutput = (target) => operation.output !== void 0 || output === void 0 || output.get === void 0 && output.value === void 0 ? target : Object.defineProperty(target, "outputSchema", { ...output, enumerable: true });
25
26
  declared[name] = operationDeclaration(withOutput({ ...native, kind }));
26
27
  }
27
28
  return declared;