apps 0.0.1-beta.0 → 0.0.1-beta.1

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