apps 0.0.1-beta.0 → 0.0.1-beta.2

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 (114) hide show
  1. package/README.md +97 -4
  2. package/framework-reference.json +1 -1
  3. package/js/browser-XIPJGLH2.js +65 -0
  4. package/js/{chunk-SBKHUC5L.js → chunk-4LPG6RCH.js} +2 -2
  5. package/js/chunk-5MQZEB6Y.js +172 -0
  6. package/js/{chunk-7JXHF5IF.js → chunk-BMOIAIVR.js} +1 -1
  7. package/js/chunk-CZ7CSFO4.js +39 -0
  8. package/js/chunk-D47C7KG5.js +172 -0
  9. package/js/{chunk-YDR4CPJA.js → chunk-EVJUVWN2.js} +8 -8
  10. package/js/chunk-FDNTX5QJ.js +78 -0
  11. package/js/{chunk-2OTCEKL2.js → chunk-FW5HBOIK.js} +2352 -1493
  12. package/js/{chunk-EP6AEUZO.js → chunk-FZJOYIZO.js} +1 -1
  13. package/js/{chunk-VFUZI3NY.js → chunk-HDJH3RPR.js} +4 -4
  14. package/js/{chunk-WIDTG42X.js → chunk-HDTGZWP2.js} +79 -26
  15. package/js/{chunk-Q2FD5IBM.js → chunk-J7O55ZV7.js} +298 -37
  16. package/js/{chunk-X3YBZCJW.js → chunk-JN55AYQH.js} +8 -41
  17. package/js/chunk-LGIYBDWA.js +85 -0
  18. package/js/{chunk-D6BKYP2L.js → chunk-M6ZRRIBI.js} +4 -4
  19. package/js/{chunk-HP7E42X6.js → chunk-MYYEW3RA.js} +767 -249
  20. package/js/{chunk-3ANFZFCV.js → chunk-OHRT55C4.js} +15 -15
  21. package/js/{chunk-R6JMJSVT.js → chunk-PLCMJREA.js} +2 -2
  22. package/js/{chunk-C24KEZXR.js → chunk-PYUYJRSK.js} +36 -2
  23. package/js/{chunk-W7Q5EOTS.js → chunk-QKHR7BMF.js} +32 -32
  24. package/js/{chunk-KWTCHVLT.js → chunk-RN2MXB4R.js} +47 -51
  25. package/js/{chunk-36DNRFZQ.js → chunk-SATWJKN6.js} +1 -1
  26. package/js/chunk-SWPD52J7.js +35 -0
  27. package/js/{chunk-BKVL7XAJ.js → chunk-TE4KO4HI.js} +1 -1
  28. package/js/chunk-UVL56Z6E.js +6641 -0
  29. package/js/chunk-W7D7WVSY.js +18 -0
  30. package/js/{chunk-BPEFS4YF.js → chunk-WFSQXYUT.js} +109 -17
  31. package/js/chunk-YEJOQEII.js +104 -0
  32. package/js/{chunk-LOKGDT6B.js → chunk-Z5NMEGJN.js} +5 -4
  33. package/js/{chunk-OWD2YICM.js → chunk-ZCAMUXSG.js} +116 -87
  34. package/js/chunk-ZJWDMTE3.js +63 -0
  35. package/js/client.js +11 -11
  36. package/js/contracts.js +88 -25
  37. package/js/effect.js +21 -15
  38. package/js/es-APDZKREY.js +40968 -0
  39. package/js/graphql.js +224 -121
  40. package/js/host.js +76 -19
  41. package/js/index.js +193 -51
  42. package/js/mcp/effect.js +25 -17
  43. package/js/mcp/stdio.js +23 -17
  44. package/js/mcp.js +110 -24
  45. package/js/openapi.js +3045 -105
  46. package/js/operations/approval.js +1 -1
  47. package/js/react.js +4 -4
  48. package/js/skills/effect.js +11 -0
  49. package/js/skills.js +894 -0
  50. package/js/storage/facet.js +7 -7
  51. package/js/ui/auth/contracts.js +6 -6
  52. package/js/ui/auth.js +8 -8
  53. package/js/ui/contracts.js +5 -5
  54. package/js/ui/serving.js +12 -12
  55. package/package.json +9 -1
  56. package/runtime.json +1 -1
  57. package/types/app-cache/src/contracts/cache.d.ts +119 -0
  58. package/types/app-cache/src/index.d.ts +93 -0
  59. package/types/apps/src/contracts/api-response-error.d.ts +43 -0
  60. package/types/apps/src/contracts/app.d.ts +11 -0
  61. package/types/apps/src/contracts/cache.d.ts +44 -0
  62. package/types/apps/src/contracts/dynamic-skills.d.ts +10 -0
  63. package/types/apps/src/contracts/dynamic-tools.d.ts +13 -0
  64. package/types/apps/src/contracts/graphql.d.ts +18 -1
  65. package/types/apps/src/contracts/host.d.ts +54 -525
  66. package/types/apps/src/contracts/mcp.d.ts +3 -1
  67. package/types/apps/src/contracts/openapi-compile.d.ts +11 -0
  68. package/types/apps/src/contracts/openapi-document.d.ts +53 -0
  69. package/types/apps/src/contracts/openapi.d.ts +156 -30
  70. package/types/apps/src/contracts/protocol-version.d.ts +6 -0
  71. package/types/apps/src/contracts/protocols/1.d.ts +1575 -0
  72. package/types/apps/src/contracts/provider-error.d.ts +15 -0
  73. package/types/apps/src/contracts/provider.d.ts +18 -1
  74. package/types/apps/src/contracts/skills.d.ts +122 -0
  75. package/types/apps/src/contracts/swagger-client.d.ts +29 -0
  76. package/types/apps/src/graphql.d.ts +6 -6
  77. package/types/apps/src/host.d.ts +1 -0
  78. package/types/apps/src/implementation/account-operations.d.ts +122 -3
  79. package/types/apps/src/implementation/app.d.ts +1 -1
  80. package/types/apps/src/implementation/cache-session.d.ts +7 -0
  81. package/types/apps/src/implementation/cache.d.ts +8 -0
  82. package/types/apps/src/implementation/catalog-cache.d.ts +29 -0
  83. package/types/apps/src/implementation/dynamic-skills.d.ts +7 -0
  84. package/types/apps/src/implementation/dynamic-tools.d.ts +8 -0
  85. package/types/apps/src/implementation/elicitation.d.ts +12 -12
  86. package/types/apps/src/implementation/git.d.ts +25 -0
  87. package/types/apps/src/implementation/graphql-catalog.d.ts +10 -0
  88. package/types/apps/src/implementation/graphql.d.ts +81 -3
  89. package/types/apps/src/implementation/inflate.d.ts +16 -0
  90. package/types/apps/src/implementation/input-problems.d.ts +3 -0
  91. package/types/apps/src/implementation/mcp-call.d.ts +3 -2
  92. package/types/apps/src/implementation/mcp-catalog.d.ts +12 -0
  93. package/types/apps/src/implementation/mcp-client.d.ts +9 -8
  94. package/types/apps/src/implementation/mcp-stdio.d.ts +1 -1
  95. package/types/apps/src/implementation/mcp-tools.d.ts +6 -3
  96. package/types/apps/src/implementation/mcp.d.ts +39 -2
  97. package/types/apps/src/implementation/openapi-compile.d.ts +119 -0
  98. package/types/apps/src/implementation/openapi-document.d.ts +51 -0
  99. package/types/apps/src/implementation/openapi-names.d.ts +18 -0
  100. package/types/apps/src/implementation/openapi-request.d.ts +10 -4
  101. package/types/apps/src/implementation/openapi-source.d.ts +40 -0
  102. package/types/apps/src/implementation/openapi.d.ts +39 -3
  103. package/types/apps/src/implementation/provider-error.d.ts +10 -0
  104. package/types/apps/src/implementation/schema.d.ts +6 -5
  105. package/types/apps/src/implementation/skill-files.d.ts +10 -0
  106. package/types/apps/src/implementation/skills.d.ts +43 -0
  107. package/types/apps/src/implementation/swagger-client.d.ts +28 -0
  108. package/types/apps/src/index.d.ts +7 -0
  109. package/types/apps/src/mcp.d.ts +5 -5
  110. package/types/apps/src/openapi.d.ts +3 -1
  111. package/types/apps/src/skills.d.ts +75 -0
  112. package/types/telemetry/src/config.d.ts +2 -0
  113. package/js/chunk-22WRQZT7.js +0 -389
  114. package/js/chunk-MLKGABMK.js +0 -9
package/js/graphql.js CHANGED
@@ -1,46 +1,56 @@
1
+ import {
2
+ catalogCache
3
+ } from "./chunk-5MQZEB6Y.js";
1
4
  import {
2
5
  protocolOperations
3
- } from "./chunk-LOKGDT6B.js";
6
+ } from "./chunk-Z5NMEGJN.js";
4
7
  import "./chunk-BCSNKUAC.js";
5
- import "./chunk-Q2FD5IBM.js";
6
- import "./chunk-X3YBZCJW.js";
7
- import "./chunk-R6JMJSVT.js";
8
- import "./chunk-C24KEZXR.js";
9
- import "./chunk-22WRQZT7.js";
10
- import "./chunk-HP7E42X6.js";
11
- import "./chunk-7JXHF5IF.js";
12
- import "./chunk-OWD2YICM.js";
8
+ import "./chunk-J7O55ZV7.js";
9
+ import {
10
+ cacheKey
11
+ } from "./chunk-D47C7KG5.js";
12
+ import "./chunk-FDNTX5QJ.js";
13
+ import "./chunk-JN55AYQH.js";
14
+ import "./chunk-PLCMJREA.js";
15
+ import {
16
+ nativeOperation
17
+ } from "./chunk-PYUYJRSK.js";
18
+ import {
19
+ accountProviderError,
20
+ graphqlProviderError,
21
+ httpProviderError
22
+ } from "./chunk-ZJWDMTE3.js";
23
+ import "./chunk-MYYEW3RA.js";
24
+ import "./chunk-BMOIAIVR.js";
25
+ import "./chunk-LGIYBDWA.js";
26
+ import "./chunk-YEJOQEII.js";
27
+ import "./chunk-SWPD52J7.js";
28
+ import {
29
+ ProviderError
30
+ } from "./chunk-W7D7WVSY.js";
31
+ import "./chunk-ZCAMUXSG.js";
13
32
  import {
14
33
  FetchHttpClient_exports
15
- } from "./chunk-VFUZI3NY.js";
34
+ } from "./chunk-HDJH3RPR.js";
16
35
  import {
17
36
  HttpClientRequest_exports,
18
37
  HttpClient_exports
19
- } from "./chunk-W7Q5EOTS.js";
38
+ } from "./chunk-QKHR7BMF.js";
20
39
  import {
21
40
  jsonSchemaDecoder
22
- } from "./chunk-BPEFS4YF.js";
23
- import "./chunk-EP6AEUZO.js";
41
+ } from "./chunk-WFSQXYUT.js";
42
+ import "./chunk-FZJOYIZO.js";
24
43
  import {
44
+ AccountId,
25
45
  HttpUrl,
26
46
  JsonObject
27
- } from "./chunk-36DNRFZQ.js";
47
+ } from "./chunk-SATWJKN6.js";
28
48
  import {
29
49
  Effect_exports,
30
50
  Redacted_exports,
31
51
  Schema_exports
32
- } from "./chunk-2OTCEKL2.js";
33
- import "./chunk-MLKGABMK.js";
34
-
35
- // src/implementation/graphql.ts
36
- import {
37
- getIntrospectionQuery,
38
- Kind as Kind2,
39
- OperationTypeNode,
40
- parse,
41
- parseType,
42
- print
43
- } from "graphql";
52
+ } from "./chunk-FW5HBOIK.js";
53
+ import "./chunk-CZ7CSFO4.js";
44
54
 
45
55
  // src/contracts/graphql.ts
46
56
  var GraphqlClientLimits = Schema_exports.Struct({
@@ -53,6 +63,7 @@ var defaultGraphqlClientLimits = GraphqlClientLimits.make({
53
63
  });
54
64
  var GraphqlToolsOptions = Schema_exports.Struct({
55
65
  url: HttpUrl,
66
+ accountId: Schema_exports.optional(AccountId),
56
67
  headers: Schema_exports.optional(Schema_exports.Record(Schema_exports.String, Schema_exports.String)),
57
68
  signal: Schema_exports.optional(Schema_exports.instanceOf(AbortSignal)),
58
69
  timeoutMs: Schema_exports.optional(
@@ -121,8 +132,26 @@ var GraphqlResponse = Schema_exports.Struct({
121
132
  data: Schema_exports.optional(Schema_exports.NullOr(JsonObject)),
122
133
  errors: Schema_exports.optional(Schema_exports.Array(JsonObject))
123
134
  });
135
+ var GraphqlToolDefinition = Schema_exports.Struct({
136
+ name: Name,
137
+ kind: Schema_exports.Literals(["query", "mutation"]),
138
+ field: Name,
139
+ description: Schema_exports.String,
140
+ arguments: Schema_exports.Array(Schema_exports.Struct({ name: Name, type: Schema_exports.String })),
141
+ inputSchema: JsonObject,
142
+ composite: Schema_exports.Boolean,
143
+ selection: Schema_exports.String
144
+ });
124
145
 
125
146
  // src/implementation/graphql.ts
147
+ import {
148
+ getIntrospectionQuery,
149
+ Kind as Kind2,
150
+ OperationTypeNode,
151
+ parse,
152
+ parseType,
153
+ print
154
+ } from "graphql";
126
155
  function wrapped(type) {
127
156
  if (!type.ofType) throw new GraphqlError({ phase: "discover", reason: "invalid_response" });
128
157
  return type.ofType;
@@ -136,8 +165,7 @@ function typeName(type) {
136
165
  if (!type.name) throw new GraphqlError({ phase: "discover", reason: "invalid_response" });
137
166
  return type.name;
138
167
  }
139
- function fieldInput(field, catalog) {
140
- const types = new Map(catalog.__schema.types.map((type) => [type.name, type]));
168
+ function fieldInput(field, types) {
141
169
  const definitions = /* @__PURE__ */ new Map();
142
170
  const convert = (ref) => ref.kind === "NON_NULL" ? nonNull(wrapped(ref)) : { anyOf: [nonNull(ref), { type: "null" }] };
143
171
  const nonNull = (ref) => {
@@ -221,7 +249,7 @@ function selection(text) {
221
249
  throw new GraphqlError({ phase: "call", reason: "invalid_input" });
222
250
  return field.selectionSet;
223
251
  }
224
- var graphqlToolsEffect = (input) => Effect_exports.gen(function* () {
252
+ var graphqlClientEffect = (input) => Effect_exports.gen(function* () {
225
253
  const options = yield* Schema_exports.decodeUnknownEffect(GraphqlToolsOptions)(input).pipe(
226
254
  Effect_exports.mapError(() => new GraphqlError({ phase: "discover", reason: "invalid_input" }))
227
255
  );
@@ -234,23 +262,21 @@ var graphqlToolsEffect = (input) => Effect_exports.gen(function* () {
234
262
  const client = yield* HttpClient_exports.HttpClient;
235
263
  const response = yield* HttpClient_exports.withScope(client).execute(
236
264
  HttpClientRequest_exports.post(url.href).pipe(
265
+ // GitHub requires this header; Workers do not supply one by default.
266
+ HttpClientRequest_exports.setHeader("user-agent", "Executor"),
237
267
  HttpClientRequest_exports.setHeaders(Redacted_exports.value(headers)),
238
268
  HttpClientRequest_exports.bodyJsonUnsafe({ query, variables })
239
269
  )
240
270
  );
241
271
  if (response.status < 200 || response.status >= 300)
242
- return yield* new GraphqlError({
243
- phase,
244
- reason: [401, 403].includes(response.status) ? "unauthorized" : "request",
245
- status: response.status
246
- });
272
+ return yield* httpProviderError(response.status, response.headers) ?? new GraphqlError({ phase, reason: "request", status: response.status });
247
273
  const result = yield* response.json.pipe(
248
274
  Effect_exports.withSpan("provider.http.response.read"),
249
275
  Effect_exports.flatMap(Schema_exports.decodeUnknownEffect(GraphqlResponse)),
250
276
  Effect_exports.mapError(() => new GraphqlError({ phase, reason: "invalid_response" }))
251
277
  );
252
278
  if (result.errors?.length)
253
- return yield* new GraphqlError({ phase, reason: "execution", status: response.status });
279
+ return yield* graphqlProviderError(result.errors, response.status) ?? new GraphqlError({ phase, reason: "execution", status: response.status });
254
280
  if (result.data == null)
255
281
  return yield* new GraphqlError({ phase, reason: "invalid_response" });
256
282
  return result.data;
@@ -270,15 +296,19 @@ var graphqlToolsEffect = (input) => Effect_exports.gen(function* () {
270
296
  orElse: () => Effect_exports.fail(new GraphqlError({ phase, reason: "timeout" }))
271
297
  }),
272
298
  Effect_exports.mapError(
273
- (error) => error instanceof GraphqlError ? error : new GraphqlError({ phase, reason: "request" })
299
+ (error) => error instanceof ProviderError && options.accountId !== void 0 ? accountProviderError(error, options.accountId) : error instanceof GraphqlError || error instanceof ProviderError ? error : new GraphqlError({ phase, reason: "request" })
274
300
  )
275
301
  );
276
- const catalog = yield* request("discover", getIntrospectionQuery()).pipe(
302
+ const discover = request("discover", getIntrospectionQuery()).pipe(
277
303
  Effect_exports.flatMap(Schema_exports.decodeUnknownEffect(GraphqlIntrospection)),
278
304
  Effect_exports.mapError(
279
- (error) => error instanceof GraphqlError ? error : new GraphqlError({ phase: "discover", reason: "invalid_response" })
305
+ (error) => error instanceof GraphqlError || error instanceof ProviderError ? error : new GraphqlError({ phase: "discover", reason: "invalid_response" })
280
306
  )
281
307
  );
308
+ return { request, discover };
309
+ });
310
+ var graphqlDefinitions = (catalog) => Effect_exports.gen(function* () {
311
+ const types = new Map(catalog.__schema.types.map((type) => [type.name, type]));
282
312
  const roots = [
283
313
  { kind: OperationTypeNode.QUERY, type: catalog.__schema.queryType },
284
314
  { kind: OperationTypeNode.MUTATION, type: catalog.__schema.mutationType }
@@ -287,103 +317,176 @@ var graphqlToolsEffect = (input) => Effect_exports.gen(function* () {
287
317
  (field) => ({ kind, field })
288
318
  )
289
319
  );
290
- const entries = yield* Effect_exports.forEach(
320
+ return yield* Effect_exports.forEach(
291
321
  roots,
292
322
  ({ kind, field }) => Effect_exports.gen(function* () {
293
323
  const definition = yield* Effect_exports.try({
294
- try: () => fieldInput(field, catalog),
324
+ try: () => fieldInput(field, types),
295
325
  catch: () => new GraphqlError({ phase: "discover", reason: "invalid_response" })
296
326
  });
297
- const decoder = yield* jsonSchemaDecoder(definition.schema).pipe(
298
- Effect_exports.mapError(
299
- () => new GraphqlError({ phase: "discover", reason: "invalid_response" })
300
- )
327
+ return yield* Effect_exports.try({
328
+ try: () => ({
329
+ name: kind + "_" + field.name,
330
+ kind,
331
+ field: field.name,
332
+ description: field.description ?? field.name,
333
+ arguments: field.args.map((arg) => ({ name: arg.name, type: typeName(arg.type) })),
334
+ inputSchema: definition.schema,
335
+ composite: definition.composite,
336
+ selection: definition.selection
337
+ }),
338
+ catch: () => new GraphqlError({ phase: "discover", reason: "invalid_response" })
339
+ });
340
+ })
341
+ );
342
+ });
343
+ var adaptGraphqlTool = (client, definition) => Effect_exports.gen(function* () {
344
+ const decoder = yield* jsonSchemaDecoder(definition.inputSchema).pipe(
345
+ Effect_exports.mapError(() => new GraphqlError({ phase: "discover", reason: "invalid_response" }))
346
+ );
347
+ const kind = definition.kind === "query" ? OperationTypeNode.QUERY : OperationTypeNode.MUTATION;
348
+ const name = definition.name;
349
+ const tool = {
350
+ description: definition.description,
351
+ readOnly: kind === OperationTypeNode.QUERY,
352
+ input: decoder,
353
+ run: (_context, input) => Effect_exports.gen(function* () {
354
+ const args = yield* Schema_exports.decodeUnknownEffect(decoder)(input).pipe(
355
+ Effect_exports.flatMap(Schema_exports.decodeUnknownEffect(JsonObject)),
356
+ Effect_exports.mapError(() => new GraphqlError({ phase: "call", reason: "invalid_input" }))
357
+ );
358
+ const variables = yield* Schema_exports.decodeUnknownEffect(JsonObject)(
359
+ args.arguments ?? {}
360
+ ).pipe(
361
+ Effect_exports.mapError(() => new GraphqlError({ phase: "call", reason: "invalid_input" }))
301
362
  );
302
- const name = kind + "_" + field.name;
303
- const tool = {
304
- description: field.description ?? field.name,
305
- readOnly: kind === OperationTypeNode.QUERY,
306
- input: decoder,
307
- run: (_context, input2) => Effect_exports.gen(function* () {
308
- const args = yield* Schema_exports.decodeUnknownEffect(decoder)(input2).pipe(
309
- Effect_exports.flatMap(Schema_exports.decodeUnknownEffect(JsonObject)),
310
- Effect_exports.mapError(() => new GraphqlError({ phase: "call", reason: "invalid_input" }))
311
- );
312
- const variables = yield* Schema_exports.decodeUnknownEffect(JsonObject)(
313
- args.arguments ?? {}
314
- ).pipe(
315
- Effect_exports.mapError(() => new GraphqlError({ phase: "call", reason: "invalid_input" }))
316
- );
317
- const query = yield* Effect_exports.try({
318
- try: () => {
319
- const used = field.args.filter((arg) => Object.hasOwn(variables, arg.name));
320
- return print({
321
- kind: Kind2.DOCUMENT,
322
- definitions: [
323
- {
324
- kind: Kind2.OPERATION_DEFINITION,
325
- operation: kind,
326
- variableDefinitions: used.map((arg) => ({
327
- kind: Kind2.VARIABLE_DEFINITION,
328
- variable: {
329
- kind: Kind2.VARIABLE,
330
- name: { kind: Kind2.NAME, value: arg.name }
331
- },
332
- type: parseType(typeName(arg.type))
333
- })),
334
- selectionSet: {
335
- kind: Kind2.SELECTION_SET,
336
- selections: [
337
- {
338
- kind: Kind2.FIELD,
339
- name: { kind: Kind2.NAME, value: field.name },
340
- arguments: used.map((arg) => ({
341
- kind: Kind2.ARGUMENT,
342
- name: { kind: Kind2.NAME, value: arg.name },
343
- value: {
344
- kind: Kind2.VARIABLE,
345
- name: { kind: Kind2.NAME, value: arg.name }
346
- }
347
- })),
348
- ...definition.composite ? {
349
- selectionSet: selection(
350
- typeof args.select === "string" ? args.select : definition.selection
351
- )
352
- } : {}
363
+ const query = yield* Effect_exports.try({
364
+ try: () => {
365
+ const used = definition.arguments.filter((arg) => Object.hasOwn(variables, arg.name));
366
+ return print({
367
+ kind: Kind2.DOCUMENT,
368
+ definitions: [
369
+ {
370
+ kind: Kind2.OPERATION_DEFINITION,
371
+ operation: kind,
372
+ variableDefinitions: used.map((arg) => ({
373
+ kind: Kind2.VARIABLE_DEFINITION,
374
+ variable: {
375
+ kind: Kind2.VARIABLE,
376
+ name: { kind: Kind2.NAME, value: arg.name }
377
+ },
378
+ type: parseType(arg.type)
379
+ })),
380
+ selectionSet: {
381
+ kind: Kind2.SELECTION_SET,
382
+ selections: [
383
+ {
384
+ kind: Kind2.FIELD,
385
+ name: { kind: Kind2.NAME, value: definition.field },
386
+ arguments: used.map((arg) => ({
387
+ kind: Kind2.ARGUMENT,
388
+ name: { kind: Kind2.NAME, value: arg.name },
389
+ value: {
390
+ kind: Kind2.VARIABLE,
391
+ name: { kind: Kind2.NAME, value: arg.name }
353
392
  }
354
- ]
393
+ })),
394
+ ...definition.composite ? {
395
+ selectionSet: selection(
396
+ typeof args.select === "string" ? args.select : definition.selection
397
+ )
398
+ } : {}
355
399
  }
356
- }
357
- ]
358
- });
359
- },
360
- catch: () => new GraphqlError({ phase: "call", reason: "invalid_input" })
400
+ ]
401
+ }
402
+ }
403
+ ]
361
404
  });
362
- const data = yield* request("call", query, variables);
363
- const value = Object.hasOwn(data, field.name) ? data[field.name] : void 0;
364
- if (value === void 0)
365
- return yield* new GraphqlError({ phase: "call", reason: "invalid_response" });
366
- return value;
367
- }).pipe(
368
- Effect_exports.withSpan("provider.graphql.call", {
369
- attributes: {
370
- "graphql.operation.type": kind,
371
- "executor.tool.name": name
372
- }
373
- })
374
- )
375
- };
376
- return [name, tool];
377
- })
405
+ },
406
+ catch: () => new GraphqlError({ phase: "call", reason: "invalid_input" })
407
+ });
408
+ const data = yield* client.request("call", query, variables);
409
+ const value = Object.hasOwn(data, definition.field) ? data[definition.field] : void 0;
410
+ if (value === void 0)
411
+ return yield* new GraphqlError({ phase: "call", reason: "invalid_response" });
412
+ return value;
413
+ }).pipe(
414
+ Effect_exports.withSpan("provider.graphql.call", {
415
+ attributes: {
416
+ "graphql.operation.type": kind,
417
+ "executor.tool.name": name
418
+ }
419
+ })
420
+ )
421
+ };
422
+ return tool;
423
+ });
424
+
425
+ // src/implementation/graphql-catalog.ts
426
+ var GraphqlToolSummary = GraphqlToolDefinition.mapFields(({ name, kind, description }) => ({
427
+ name,
428
+ kind,
429
+ description
430
+ }));
431
+ var graphqlCatalog = (options, kinds) => Effect_exports.gen(function* () {
432
+ const parsed = yield* Schema_exports.decodeUnknownEffect(GraphqlToolsOptions)(options).pipe(
433
+ Effect_exports.mapError(() => new GraphqlError({ phase: "discover", reason: "invalid_input" }))
378
434
  );
379
- return Object.fromEntries(entries);
435
+ const headers = {};
436
+ new Headers(parsed.headers).forEach((value, name) => {
437
+ headers[name] = value;
438
+ });
439
+ const id = yield* cacheKey({ url: parsed.url, headers, accountId: parsed.accountId ?? null });
440
+ const client = yield* graphqlClientEffect(parsed);
441
+ const catalog = yield* catalogCache({
442
+ ...options,
443
+ prefix: ["graphql-catalog-v2", id],
444
+ schema: GraphqlToolDefinition,
445
+ summary: {
446
+ schema: GraphqlToolSummary,
447
+ of: ({ name, kind, description }) => ({ name, kind, description })
448
+ },
449
+ load: (context) => (context === void 0 ? Effect_exports.succeed(client) : graphqlClientEffect({ ...parsed, signal: context.signal })).pipe(
450
+ Effect_exports.flatMap((source) => source.discover),
451
+ Effect_exports.flatMap(graphqlDefinitions)
452
+ )
453
+ });
454
+ const kindOf = (tool) => Object.hasOwn(kinds, tool.name) ? kinds[tool.name] ?? "mutation" : tool.kind;
455
+ const qualified = (tool) => `${kindOf(tool) === "query" ? "queries" : "mutations"}.${tool.name}`;
456
+ const summarize = (tool) => ({
457
+ name: qualified(tool),
458
+ description: tool.description,
459
+ readOnly: kindOf(tool) === "query"
460
+ });
461
+ const describe = (tool) => ({
462
+ ...summarize(tool),
463
+ inputSchema: tool.inputSchema
464
+ });
465
+ const selected = (name) => Effect_exports.gen(function* () {
466
+ if (!name.startsWith("queries.") && !name.startsWith("mutations.")) return void 0;
467
+ const tool = yield* catalog.resolve(name.slice(name.indexOf(".") + 1));
468
+ return tool === void 0 || qualified(tool) !== name ? void 0 : tool;
469
+ });
470
+ const dynamicTools = {
471
+ list: () => catalog.list().pipe(Effect_exports.map((tools) => tools.map(describe))),
472
+ summaries: () => catalog.summaries().pipe(Effect_exports.map((tools) => tools.map(summarize))),
473
+ describe: (name) => selected(name).pipe(
474
+ Effect_exports.map((tool) => tool === void 0 ? void 0 : describe(tool))
475
+ ),
476
+ resolve: (name) => Effect_exports.gen(function* () {
477
+ const tool = yield* selected(name);
478
+ if (tool === void 0) return void 0;
479
+ const adapted = yield* adaptGraphqlTool(client, tool);
480
+ const operations = protocolOperations({ selected: adapted }, { selected: kindOf(tool) });
481
+ return nativeOperation(operations.queries.selected ?? operations.mutations.selected);
482
+ })
483
+ };
484
+ return { dynamicTools };
380
485
  });
381
486
 
382
487
  // src/graphql.ts
383
488
  var graphqlOperations = (options, kinds = {}) => Effect_exports.runPromise(
384
- graphqlToolsEffect(options).pipe(
385
- Effect_exports.map((operations) => protocolOperations(operations, kinds))
386
- ),
489
+ graphqlCatalog(options, kinds),
387
490
  options.signal === void 0 ? {} : { signal: options.signal }
388
491
  );
389
492
  export {
package/js/host.js CHANGED
@@ -1,43 +1,99 @@
1
1
  import {
2
2
  createAppHandler
3
- } from "./chunk-Q2FD5IBM.js";
4
- import "./chunk-X3YBZCJW.js";
5
- import "./chunk-R6JMJSVT.js";
6
- import "./chunk-C24KEZXR.js";
3
+ } from "./chunk-J7O55ZV7.js";
4
+ import "./chunk-D47C7KG5.js";
5
+ import "./chunk-FDNTX5QJ.js";
6
+ import "./chunk-JN55AYQH.js";
7
+ import "./chunk-PLCMJREA.js";
8
+ import "./chunk-PYUYJRSK.js";
9
+ import "./chunk-ZJWDMTE3.js";
7
10
  import {
11
+ ElicitationFailed,
12
+ ElicitationReply,
8
13
  HostAccountsInvalid,
9
14
  HostInputInvalid,
10
15
  HostResponse,
11
16
  ResolvedAccounts,
12
- TrustedToolApproval
13
- } from "./chunk-22WRQZT7.js";
14
- import {
15
- ElicitationFailed,
16
- ElicitationReply,
17
+ TrustedToolApproval,
17
18
  WorkflowFailure,
18
19
  WorkflowRpcResult,
19
20
  WorkflowRun,
20
21
  WorkflowRunId,
21
22
  WorkflowRunPage
22
- } from "./chunk-HP7E42X6.js";
23
- import "./chunk-7JXHF5IF.js";
23
+ } from "./chunk-MYYEW3RA.js";
24
+ import "./chunk-BMOIAIVR.js";
25
+ import {
26
+ CacheCommand,
27
+ CacheError,
28
+ CacheReply
29
+ } from "./chunk-LGIYBDWA.js";
30
+ import "./chunk-YEJOQEII.js";
31
+ import "./chunk-SWPD52J7.js";
32
+ import "./chunk-W7D7WVSY.js";
24
33
  import {
25
34
  collectTelemetry,
26
35
  withRemoteSpan
27
- } from "./chunk-OWD2YICM.js";
28
- import "./chunk-VFUZI3NY.js";
29
- import "./chunk-W7Q5EOTS.js";
30
- import "./chunk-BPEFS4YF.js";
31
- import "./chunk-EP6AEUZO.js";
32
- import "./chunk-36DNRFZQ.js";
36
+ } from "./chunk-ZCAMUXSG.js";
37
+ import "./chunk-HDJH3RPR.js";
38
+ import "./chunk-QKHR7BMF.js";
39
+ import "./chunk-WFSQXYUT.js";
40
+ import "./chunk-FZJOYIZO.js";
41
+ import "./chunk-SATWJKN6.js";
33
42
  import {
34
43
  Cause_exports,
35
44
  Effect_exports,
36
45
  Redacted_exports,
37
46
  Scheduler_exports,
38
47
  Schema_exports
39
- } from "./chunk-2OTCEKL2.js";
40
- import "./chunk-MLKGABMK.js";
48
+ } from "./chunk-FW5HBOIK.js";
49
+ import "./chunk-CZ7CSFO4.js";
50
+
51
+ // src/implementation/cache-session.ts
52
+ var isolatedCacheSession = (callback) => {
53
+ const controller = new AbortController();
54
+ const pending = /* @__PURE__ */ new Set();
55
+ const cache = {
56
+ transport: (command) => Effect_exports.tryPromise({
57
+ try: () => callback(Schema_exports.encodeSync(CacheCommand)(command)),
58
+ catch: () => new CacheError({ reason: "storage" })
59
+ }).pipe(
60
+ Effect_exports.flatMap(Schema_exports.decodeUnknownEffect(CacheReply)),
61
+ Effect_exports.mapError(() => new CacheError({ reason: "storage" })),
62
+ Effect_exports.flatMap(
63
+ (reply) => reply.ok ? Effect_exports.succeed(reply.value) : Effect_exports.fail(reply.error)
64
+ )
65
+ ),
66
+ background: (task) => Effect_exports.gen(function* () {
67
+ const services = yield* Effect_exports.context();
68
+ const promise = Effect_exports.runPromiseWith(services)(
69
+ task.pipe(
70
+ Effect_exports.timeout("30 seconds"),
71
+ Effect_exports.catchCause(() => Effect_exports.logWarning("App cache refresh failed"))
72
+ ),
73
+ { signal: controller.signal }
74
+ ).then(
75
+ () => {
76
+ pending.delete(promise);
77
+ },
78
+ () => {
79
+ pending.delete(promise);
80
+ }
81
+ );
82
+ pending.add(promise);
83
+ })
84
+ };
85
+ const drain = async () => {
86
+ while (pending.size > 0) await Promise.all(pending);
87
+ };
88
+ return {
89
+ cache,
90
+ drain,
91
+ cancel: async () => {
92
+ controller.abort();
93
+ await drain();
94
+ }
95
+ };
96
+ };
41
97
 
42
98
  // src/implementation/workflow-rpc.ts
43
99
  var isolatedWorkflowExecution = (run, deliver, signal) => {
@@ -187,6 +243,7 @@ export {
187
243
  createAppHandler2 as createAppHandler,
188
244
  createIsolatedAppHandler,
189
245
  hostContext,
246
+ isolatedCacheSession,
190
247
  isolatedElicitation,
191
248
  isolatedWorkflowControls,
192
249
  isolatedWorkflowExecution