apps 0.0.1-beta.2 → 0.0.1-beta.21

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 (119) hide show
  1. package/README.md +68 -44
  2. package/framework-reference.json +1 -1
  3. package/js/{chunk-SATWJKN6.js → chunk-27F7W2LG.js} +1 -1
  4. package/js/{chunk-WFSQXYUT.js → chunk-4QQ62BVS.js} +37 -3
  5. package/js/{chunk-HDJH3RPR.js → chunk-57RKNWL2.js} +2 -2
  6. package/js/chunk-625MBYU4.js +524 -0
  7. package/js/{chunk-RN2MXB4R.js → chunk-BLI53LPN.js} +28 -9
  8. package/js/{chunk-FW5HBOIK.js → chunk-CDL5PM2Q.js} +307 -169
  9. package/js/{chunk-J7O55ZV7.js → chunk-CHAK4P5C.js} +317 -176
  10. package/js/{chunk-HDTGZWP2.js → chunk-CMRKLZZY.js} +8 -8
  11. package/js/{chunk-OHRT55C4.js → chunk-IJX4CYZO.js} +3 -6
  12. package/js/{chunk-FDNTX5QJ.js → chunk-IPI4MFSN.js} +2 -2
  13. package/js/{chunk-YEJOQEII.js → chunk-JU7VHODU.js} +1 -1
  14. package/js/chunk-KUMBKVJD.js +39 -0
  15. package/js/{chunk-EVJUVWN2.js → chunk-M3B3DE4K.js} +2 -2
  16. package/js/{chunk-ZJWDMTE3.js → chunk-MKWZPDR6.js} +3 -3
  17. package/js/{chunk-BMOIAIVR.js → chunk-N7YDVXYJ.js} +49 -1
  18. package/js/{chunk-D47C7KG5.js → chunk-NKLWZJLE.js} +2 -2
  19. package/js/chunk-NMKHTJOQ.js +254 -0
  20. package/js/chunk-OD3KFKZD.js +1617 -0
  21. package/js/{chunk-ZCAMUXSG.js → chunk-ODEIDRGW.js} +3 -4
  22. package/js/{chunk-5MQZEB6Y.js → chunk-OZ4UK3CD.js} +37 -12
  23. package/js/{chunk-M6ZRRIBI.js → chunk-PJJ24GU7.js} +1 -1
  24. package/js/{chunk-FZJOYIZO.js → chunk-PZB6T6KU.js} +1 -1
  25. package/js/{chunk-LGIYBDWA.js → chunk-R3EV5FTO.js} +13 -1
  26. package/js/{chunk-Z5NMEGJN.js → chunk-RAAPJMVZ.js} +21 -9
  27. package/js/{chunk-QKHR7BMF.js → chunk-UK573G7W.js} +1 -1
  28. package/js/{chunk-4LPG6RCH.js → chunk-VFZKSM3T.js} +5 -25
  29. package/js/{chunk-MYYEW3RA.js → chunk-VXWY44LE.js} +780 -55
  30. package/js/{chunk-JN55AYQH.js → chunk-XNCYIB4D.js} +61 -32
  31. package/js/{chunk-PLCMJREA.js → chunk-ZQINWV4W.js} +60 -20
  32. package/js/client.js +10 -26
  33. package/js/contracts.js +74 -16
  34. package/js/effect.js +19 -20
  35. package/js/{es-APDZKREY.js → es-DIULA3ZF.js} +62 -1659
  36. package/js/graphql.js +47 -49
  37. package/js/host.js +19 -20
  38. package/js/index.js +232 -201
  39. package/js/mcp/effect.js +21 -22
  40. package/js/mcp/stdio.js +25 -26
  41. package/js/mcp.js +74 -56
  42. package/js/openapi.js +3428 -1276
  43. package/js/react.js +3 -3
  44. package/js/skills/effect.js +3 -3
  45. package/js/skills.js +12 -13
  46. package/js/storage/facet.js +4 -4
  47. package/js/ui/auth/contracts.js +8 -9
  48. package/js/ui/auth.js +16 -14
  49. package/js/ui/contracts.js +4 -4
  50. package/js/ui/serving.js +71 -218
  51. package/package.json +1 -1
  52. package/runtime.json +1 -1
  53. package/types/app-data/src/contracts/database.d.ts +33 -6
  54. package/types/app-data/src/implementation/schema.d.ts +2 -17
  55. package/types/apps/src/contracts/app.d.ts +7 -6
  56. package/types/apps/src/contracts/failure.d.ts +25 -0
  57. package/types/apps/src/contracts/host.d.ts +31 -10
  58. package/types/apps/src/contracts/mcp.d.ts +16 -0
  59. package/types/apps/src/contracts/openapi.d.ts +5 -1
  60. package/types/apps/src/contracts/operations.d.ts +0 -5
  61. package/types/apps/src/contracts/protocol-version.d.ts +2 -2
  62. package/types/apps/src/contracts/protocols/1.d.ts +235 -67
  63. package/types/apps/src/contracts/protocols/2.d.ts +710 -0
  64. package/types/apps/src/contracts/protocols/3.d.ts +718 -0
  65. package/types/apps/src/contracts/protocols/4.d.ts +1299 -0
  66. package/types/apps/src/contracts/protocols/5.d.ts +1174 -0
  67. package/types/apps/src/contracts/protocols/6.d.ts +1620 -0
  68. package/types/apps/src/contracts/protocols/7.d.ts +1784 -0
  69. package/types/apps/src/contracts/protocols/oauth.d.ts +89 -0
  70. package/types/apps/src/contracts/provider.d.ts +109 -10
  71. package/types/apps/src/contracts/router.d.ts +59 -0
  72. package/types/apps/src/contracts/storage.d.ts +3 -3
  73. package/types/apps/src/contracts/ui-auth.d.ts +6 -14
  74. package/types/apps/src/contracts/ui.d.ts +18 -0
  75. package/types/apps/src/contracts/workflows.d.ts +34 -3
  76. package/types/apps/src/graphql.d.ts +1 -3
  77. package/types/apps/src/implementation/account-router.d.ts +12 -0
  78. package/types/apps/src/implementation/app.d.ts +5 -4
  79. package/types/apps/src/implementation/browser-scripts.gen.d.ts +6 -0
  80. package/types/apps/src/implementation/catalog-cache.d.ts +34 -4
  81. package/types/apps/src/implementation/elicitation.d.ts +2 -2
  82. package/types/apps/src/implementation/failure-detail.d.ts +26 -0
  83. package/types/apps/src/implementation/graphql-catalog.d.ts +4 -7
  84. package/types/apps/src/implementation/mcp-catalog.d.ts +7 -8
  85. package/types/apps/src/implementation/mcp-client.d.ts +35 -19
  86. package/types/apps/src/implementation/mcp.d.ts +35 -19
  87. package/types/apps/src/implementation/openapi-compile.d.ts +9 -5
  88. package/types/apps/src/implementation/openapi-document.d.ts +15 -2
  89. package/types/apps/src/implementation/openapi-request.d.ts +8 -1
  90. package/types/apps/src/implementation/openapi-source.d.ts +2 -6
  91. package/types/apps/src/implementation/openapi-upgrade.d.ts +4 -0
  92. package/types/apps/src/implementation/operations.d.ts +36 -3
  93. package/types/apps/src/implementation/protocol-operations.d.ts +3 -4
  94. package/types/apps/src/implementation/provider.d.ts +19 -5
  95. package/types/apps/src/implementation/router-catalog.d.ts +225 -0
  96. package/types/apps/src/implementation/router.d.ts +68 -0
  97. package/types/apps/src/implementation/runtime-yield.d.ts +7 -0
  98. package/types/apps/src/implementation/schema.d.ts +44 -1
  99. package/types/apps/src/implementation/storage.d.ts +5 -3
  100. package/types/apps/src/implementation/ui-account-notice.d.ts +9 -0
  101. package/types/apps/src/implementation/ui-auth.d.ts +11 -5
  102. package/types/apps/src/implementation/ui-errors.d.ts +1 -1
  103. package/types/apps/src/implementation/ui-serving.d.ts +10 -4
  104. package/types/apps/src/implementation/ui-watch.d.ts +1 -1
  105. package/types/apps/src/implementation/webhooks.d.ts +1 -1
  106. package/types/apps/src/implementation/workflow-context.d.ts +11 -3
  107. package/types/apps/src/index.d.ts +28 -11
  108. package/types/apps/src/mcp-stdio.d.ts +2 -5
  109. package/types/apps/src/mcp.d.ts +5 -4
  110. package/types/apps/src/openapi.d.ts +6 -6
  111. package/types/apps/src/ui-auth.d.ts +2 -2
  112. package/types/telemetry/src/browser-operations.d.ts +5 -2
  113. package/js/chunk-PYUYJRSK.js +0 -93
  114. package/js/chunk-SWPD52J7.js +0 -35
  115. package/js/chunk-TE4KO4HI.js +0 -47
  116. package/js/chunk-W7D7WVSY.js +0 -18
  117. package/types/apps/src/contracts/dynamic-tools.d.ts +0 -13
  118. package/types/apps/src/implementation/account-operations.d.ts +0 -151
  119. package/types/apps/src/implementation/dynamic-tools.d.ts +0 -8
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Schema_exports
3
- } from "./chunk-FW5HBOIK.js";
3
+ } from "./chunk-CDL5PM2Q.js";
4
4
 
5
5
  // src/contracts/schema.ts
6
6
  var JsonValue = Schema_exports.Json;
@@ -1,6 +1,7 @@
1
1
  import {
2
+ JsonObject,
2
3
  ValidationError
3
- } from "./chunk-SATWJKN6.js";
4
+ } from "./chunk-27F7W2LG.js";
4
5
  import {
5
6
  Cause_exports,
6
7
  Effect_exports,
@@ -9,7 +10,7 @@ import {
9
10
  SchemaIssue_exports,
10
11
  SchemaParser_exports,
11
12
  Schema_exports
12
- } from "./chunk-FW5HBOIK.js";
13
+ } from "./chunk-CDL5PM2Q.js";
13
14
 
14
15
  // ../../node_modules/.bun/@cfworker+json-schema@4.1.1/node_modules/@cfworker/json-schema/dist/esm/deep-compare-strict.js
15
16
  function deepCompareStrict(a, b) {
@@ -1144,6 +1145,25 @@ function object(fields) {
1144
1145
  ) : Schema_exports.Struct(Object.fromEntries(entries));
1145
1146
  return { ...wrap(decoder, false), fields: Object.freeze({ ...fields }) };
1146
1147
  }
1148
+ var Exposure = /* @__PURE__ */ Symbol("apps.FieldExposure");
1149
+ var exposureOf = (schema) => Exposure in schema && (schema[Exposure] === "plain" || schema[Exposure] === "raw") ? schema[Exposure] : void 0;
1150
+ var expose = (schema, exposure) => (
1151
+ // SAFETY: the copy keeps every member of S, and `optional` and `default` keep the marking.
1152
+ {
1153
+ ...schema,
1154
+ [Exposure]: exposure,
1155
+ optional: () => expose(schema.optional(), exposure),
1156
+ default: (value) => expose(schema.default(value), exposure)
1157
+ }
1158
+ );
1159
+ var plain = (schema) => expose(schema, "plain");
1160
+ var raw = (schema) => expose(schema, "raw");
1161
+ var fieldExposure = (fields) => Object.fromEntries(
1162
+ Object.entries(fields).flatMap(([name, field]) => {
1163
+ const exposure = exposureOf(field);
1164
+ return exposure === void 0 ? [] : [[name, exposure]];
1165
+ })
1166
+ );
1147
1167
  var ImportedJsonSchema = /* @__PURE__ */ Symbol("apps.JsonSchemaDocument");
1148
1168
  var importedJsonSchema = (decoder) => ImportedJsonSchema in decoder ? decoder[ImportedJsonSchema] : void 0;
1149
1169
  var withJsonSchemaDocument = (decoder, document) => Object.assign(decoder, { [ImportedJsonSchema]: document });
@@ -1387,6 +1407,16 @@ var jsonSchema = (input) => {
1387
1407
  var storageFieldOf = (schema) => schema[StorageField];
1388
1408
  var id = (table) => wrap(Schema_exports.NonEmptyString, false, { kind: "id", references: table });
1389
1409
  var userId = () => wrap(Schema_exports.NonEmptyString, false, { kind: "userId" });
1410
+ var jsonSchemaDocument = (decoder) => {
1411
+ const imported = importedJsonSchema(decoder);
1412
+ if (imported !== void 0) return Schema_exports.decodeUnknownEffect(JsonObject)(imported);
1413
+ const document = Schema_exports.toJsonSchemaDocument(decoder);
1414
+ return Schema_exports.decodeUnknownEffect(JsonObject)({
1415
+ ...document.schema,
1416
+ $defs: document.definitions,
1417
+ $schema: "https://json-schema.org/draft/2020-12/schema"
1418
+ });
1419
+ };
1390
1420
 
1391
1421
  export {
1392
1422
  decoderOf,
@@ -1401,6 +1431,9 @@ export {
1401
1431
  literal,
1402
1432
  array,
1403
1433
  object,
1434
+ plain,
1435
+ raw,
1436
+ fieldExposure,
1404
1437
  importedJsonSchema,
1405
1438
  once,
1406
1439
  withLazyJsonSchemaDocument,
@@ -1411,5 +1444,6 @@ export {
1411
1444
  jsonSchema,
1412
1445
  storageFieldOf,
1413
1446
  id,
1414
- userId
1447
+ userId,
1448
+ jsonSchemaDocument
1415
1449
  };
@@ -4,7 +4,7 @@ import {
4
4
  fromWeb,
5
5
  layerMergedContext,
6
6
  make2 as make
7
- } from "./chunk-QKHR7BMF.js";
7
+ } from "./chunk-UK573G7W.js";
8
8
  import {
9
9
  Reference,
10
10
  Service,
@@ -17,7 +17,7 @@ import {
17
17
  succeed4 as succeed,
18
18
  toReadableStreamEffect,
19
19
  tryPromise
20
- } from "./chunk-FW5HBOIK.js";
20
+ } from "./chunk-CDL5PM2Q.js";
21
21
  import {
22
22
  __export
23
23
  } from "./chunk-CZ7CSFO4.js";
@@ -0,0 +1,524 @@
1
+ import {
2
+ skillFromFiles
3
+ } from "./chunk-IPI4MFSN.js";
4
+ import {
5
+ joinPath,
6
+ mergeMeta
7
+ } from "./chunk-NMKHTJOQ.js";
8
+ import {
9
+ parseProviderError
10
+ } from "./chunk-MKWZPDR6.js";
11
+ import {
12
+ ApiErrorResponse,
13
+ HostDeclarationInvalid,
14
+ HostEvaluationFailed,
15
+ HostedRouter,
16
+ HostedTool,
17
+ HostedToolSummary,
18
+ McpError,
19
+ maxFailureMessageLength
20
+ } from "./chunk-VXWY44LE.js";
21
+ import {
22
+ AppDatabaseError
23
+ } from "./chunk-N7YDVXYJ.js";
24
+ import {
25
+ CacheError
26
+ } from "./chunk-R3EV5FTO.js";
27
+ import {
28
+ SkillLoadFailed,
29
+ skillFormatLimits
30
+ } from "./chunk-JU7VHODU.js";
31
+ import {
32
+ jsonSchemaDocument
33
+ } from "./chunk-4QQ62BVS.js";
34
+ import {
35
+ AppStorageError,
36
+ AppStorageUnavailable
37
+ } from "./chunk-PZB6T6KU.js";
38
+ import {
39
+ AccountId,
40
+ HttpUrl,
41
+ JsonObject
42
+ } from "./chunk-27F7W2LG.js";
43
+ import {
44
+ Cause_exports,
45
+ Effect_exports,
46
+ Option_exports,
47
+ Predicate_exports,
48
+ Redacted_exports,
49
+ Result_exports,
50
+ Schema_exports
51
+ } from "./chunk-CDL5PM2Q.js";
52
+
53
+ // src/contracts/openapi.ts
54
+ var OpenapiErrorResponse = Schema_exports.Struct({
55
+ code: ApiErrorResponse.fields.code,
56
+ status: ApiErrorResponse.fields.status,
57
+ message: Schema_exports.Union([
58
+ Schema_exports.Struct({ source: Schema_exports.Literal("body") }),
59
+ Schema_exports.Struct({ source: Schema_exports.Literal("schema"), value: ApiErrorResponse.fields.message })
60
+ ]),
61
+ schema: JsonObject
62
+ });
63
+ var OpenapiParameter = Schema_exports.Struct({
64
+ name: Schema_exports.String,
65
+ in: Schema_exports.Literals(["path", "query", "header", "cookie"]),
66
+ required: Schema_exports.optionalKey(Schema_exports.Boolean),
67
+ schema: Schema_exports.optionalKey(JsonObject),
68
+ style: Schema_exports.optionalKey(Schema_exports.String),
69
+ explode: Schema_exports.optionalKey(Schema_exports.Boolean),
70
+ allowReserved: Schema_exports.optionalKey(Schema_exports.Boolean),
71
+ allowEmptyValue: Schema_exports.optionalKey(Schema_exports.Boolean),
72
+ content: Schema_exports.optionalKey(JsonObject)
73
+ });
74
+ var OpenapiRequestBody = Schema_exports.Struct({
75
+ required: Schema_exports.optionalKey(Schema_exports.Boolean),
76
+ content: Schema_exports.Record(
77
+ Schema_exports.String,
78
+ Schema_exports.Struct({
79
+ schema: Schema_exports.optionalKey(JsonObject),
80
+ encoding: Schema_exports.optionalKey(JsonObject)
81
+ })
82
+ )
83
+ });
84
+ var OpenapiOperation = Schema_exports.Struct({
85
+ /** The tool name after `queries.` or `mutations.`, grouped as `<group>.<leaf>`. */
86
+ name: Schema_exports.NonEmptyString,
87
+ /** The document's operationId, when it declares one. `kinds` overrides are keyed by it. */
88
+ operationId: Schema_exports.optionalKey(Schema_exports.String),
89
+ description: Schema_exports.String,
90
+ method: Schema_exports.Literals(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"]),
91
+ path: Schema_exports.String,
92
+ baseUrl: HttpUrl,
93
+ openapi: Schema_exports.String,
94
+ securitySchemes: Schema_exports.Record(Schema_exports.String, JsonObject),
95
+ /** The resolved OpenAPI Operation Object; Executor schemas remain separate. */
96
+ request: Schema_exports.Struct({
97
+ parameters: Schema_exports.Array(OpenapiParameter),
98
+ requestBody: Schema_exports.optionalKey(OpenapiRequestBody),
99
+ security: Schema_exports.Array(Schema_exports.Record(Schema_exports.String, Schema_exports.Array(Schema_exports.String))),
100
+ responses: Schema_exports.Record(Schema_exports.String, JsonObject)
101
+ }),
102
+ /** Streams remain in the metadata but cannot run through a single-result tool call. */
103
+ streaming: Schema_exports.optionalKey(Schema_exports.Literal(true)),
104
+ /** The operation's OpenAPI tags, shown to agents as labels within its router. */
105
+ tags: Schema_exports.optionalKey(Schema_exports.Array(Schema_exports.NonEmptyString)),
106
+ input: JsonObject,
107
+ outputSchema: Schema_exports.optionalKey(JsonObject),
108
+ errorResponses: Schema_exports.optionalKey(Schema_exports.Array(OpenapiErrorResponse))
109
+ });
110
+ var CredentialBinding = Schema_exports.Struct({
111
+ scheme: Schema_exports.String,
112
+ field: Schema_exports.String,
113
+ part: Schema_exports.Literals(["value", "username", "password"]),
114
+ prefix: Schema_exports.String
115
+ });
116
+ var OpenapiAccount = Schema_exports.Struct({
117
+ id: Schema_exports.optional(AccountId),
118
+ method: Schema_exports.String,
119
+ fields: Schema_exports.Record(Schema_exports.String, Schema_exports.Unknown)
120
+ });
121
+ var OpenapiParameterDefaults = Schema_exports.Struct({
122
+ path: Schema_exports.optionalKey(Schema_exports.Record(Schema_exports.String, Schema_exports.String)),
123
+ query: Schema_exports.optionalKey(Schema_exports.Record(Schema_exports.String, Schema_exports.String)),
124
+ headers: Schema_exports.optionalKey(Schema_exports.Record(Schema_exports.String, Schema_exports.String))
125
+ });
126
+ var OpenapiToolsOptions = Schema_exports.Struct({
127
+ operations: Schema_exports.Array(OpenapiOperation),
128
+ /**
129
+ * Component schemas stored once per app and referenced as `#/$defs/<name>`. Operations
130
+ * generated before shared definitions carry their own `$defs` and omit this.
131
+ */
132
+ definitions: Schema_exports.optional(Schema_exports.Record(Schema_exports.String, JsonObject)),
133
+ methods: Schema_exports.Record(Schema_exports.String, Schema_exports.Array(CredentialBinding)),
134
+ oauth: Schema_exports.Array(Schema_exports.String),
135
+ account: Schema_exports.optional(OpenapiAccount),
136
+ parameterDefaults: Schema_exports.optional(OpenapiParameterDefaults),
137
+ signal: Schema_exports.optional(Schema_exports.instanceOf(AbortSignal)),
138
+ fetch: Schema_exports.optional(
139
+ Schema_exports.declare((value) => typeof value === "function")
140
+ )
141
+ });
142
+ var OpenapiError = class extends Schema_exports.TaggedError()("OpenapiError", {
143
+ reason: Schema_exports.Literals(["invalid_definition", "invalid_input", "request"]),
144
+ status: Schema_exports.optional(Schema_exports.Number)
145
+ }) {
146
+ };
147
+ var defaultOpenapiResponseLimits = {
148
+ maxBodyBytes: 16777216,
149
+ readTimeoutMs: 3e4
150
+ };
151
+ var isOpenapiTextMedia = (type) => /^(?:text\/|application\/(?:[\w.-]+\+)?(?:json|xml)|application\/(?:javascript|x-ndjson|x-www-form-urlencoded))/i.test(
152
+ type
153
+ );
154
+ var isOpenapiFileSchema = (shape) => shape.contentMediaType !== void 0 && shape.contentEncoding === void 0 || shape.type === "string" && shape.format === "binary";
155
+ var openapiBinaryResultSchema = {
156
+ type: "object",
157
+ properties: {
158
+ base64: { type: "string", contentEncoding: "base64" },
159
+ contentType: { type: "string" }
160
+ },
161
+ required: ["base64", "contentType"],
162
+ additionalProperties: false
163
+ };
164
+ var openapiMediaKind = (type) => type.includes("json") && !type.includes("ndjson") ? "json" : type === "application/x-www-form-urlencoded" ? "form" : type === "multipart/form-data" ? "multipart" : isOpenapiTextMedia(type) ? "text" : "binary";
165
+
166
+ // src/implementation/failure-detail.ts
167
+ var storageMessages = {
168
+ schema: "The app's database schema is invalid.",
169
+ schema_changed: "The app's database schema changed during this operation. Retry it.",
170
+ table: "The operation used a table the app's database schema does not declare.",
171
+ index: "The operation used an index the table does not declare, or used it incorrectly.",
172
+ range: "The index range is invalid for the declared index.",
173
+ value: "A value does not match the table's declared field schema.",
174
+ readonly: "Queries cannot write. Move writes into a mutation.",
175
+ cursor: "The pagination cursor is invalid or belongs to a different query.",
176
+ limit: "The operation exceeded a per-invocation app data limit.",
177
+ closed: "The database session closed before this operation finished.",
178
+ storage: "App storage failed to complete the operation.",
179
+ replay: "A workflow step replayed with different input than its first run."
180
+ };
181
+ var cacheMessages = {
182
+ capacity: "A cache key, value or batch exceeded the app cache's size limits.",
183
+ invalid: "The app made a cache request the app cache could not accept.",
184
+ unavailable: "The app cache is not available on this host.",
185
+ storage: "The app cache failed to complete the operation.",
186
+ timeout: "The app cache did not respond in time."
187
+ };
188
+ var minimumSecretLength = 6;
189
+ var secretValues = (value, found) => {
190
+ if (typeof value === "string") {
191
+ if (value.length >= minimumSecretLength) found.add(value);
192
+ } else if (Array.isArray(value)) for (const item of value) secretValues(item, found);
193
+ else if (Predicate_exports.isObject(value))
194
+ for (const item of Object.values(value)) secretValues(item, found);
195
+ return found;
196
+ };
197
+ var accountFieldSecrets = (accounts) => {
198
+ const found = /* @__PURE__ */ new Set();
199
+ if (Predicate_exports.isObject(accounts)) {
200
+ for (const slot of Object.values(accounts))
201
+ for (const account of Array.isArray(slot) ? slot : [slot])
202
+ if (Predicate_exports.hasProperty(account, "fields")) secretValues(account.fields, found);
203
+ }
204
+ return [...found].sort((a, b) => b.length - a.length);
205
+ };
206
+ var accountSecrets = (accounts) => accountFieldSecrets(Redacted_exports.value(accounts));
207
+ var boundFailureMessage = (message, secrets) => {
208
+ let redacted = message;
209
+ for (const secret of secrets) redacted = redacted.split(secret).join("[redacted]");
210
+ return redacted.length <= maxFailureMessageLength ? redacted : `${redacted.slice(0, maxFailureMessageLength - 1)}\u2026`;
211
+ };
212
+ var errorName = (error) => (error.name.length > 0 ? error.name : "Error").slice(0, 128);
213
+ var ownMessage = (error) => {
214
+ const cause = error.cause;
215
+ const suffix = cause instanceof Error && cause.message.length > 0 ? ` (caused by ${errorName(cause)}: ${cause.message})` : "";
216
+ return error.message.length > 0 ? `${error.message}${suffix}` : void 0;
217
+ };
218
+ var describeFailure = (error) => error instanceof Error ? `${errorName(error)}: ${ownMessage(error) ?? "(no message)"}` : typeof error === "string" ? error : `A non-Error ${error === null ? "null" : typeof error} value was thrown`;
219
+ var failureDetail = (error, secrets) => {
220
+ if (Schema_exports.is(CacheError)(error))
221
+ return {
222
+ source: "storage",
223
+ errorName: "CacheError",
224
+ code: error.reason,
225
+ message: cacheMessages[error.reason]
226
+ };
227
+ if (Schema_exports.is(AppDatabaseError)(error))
228
+ return {
229
+ source: "storage",
230
+ errorName: "AppDatabaseError",
231
+ code: error.reason,
232
+ message: boundFailureMessage(ownMessage(error) ?? storageMessages[error.reason], secrets)
233
+ };
234
+ if (Schema_exports.is(AppStorageUnavailable)(error))
235
+ return {
236
+ source: "storage",
237
+ errorName: "AppStorageUnavailable",
238
+ message: "App storage is not available on this host."
239
+ };
240
+ if (Schema_exports.is(AppStorageError)(error))
241
+ return {
242
+ source: "storage",
243
+ errorName: "AppStorageError",
244
+ message: "App storage failed to complete the operation."
245
+ };
246
+ if (Schema_exports.is(OpenapiError)(error))
247
+ return {
248
+ source: "service",
249
+ errorName: "OpenapiError",
250
+ code: error.reason,
251
+ message: error.reason === "request" ? error.status === void 0 ? "The API request failed before a response arrived." : `The API responded with HTTP ${error.status}, which its OpenAPI document does not declare as an error with a message.` : error.reason === "invalid_input" ? "The input could not be encoded as a request for this API operation." : "The API's OpenAPI definition for this operation is invalid."
252
+ };
253
+ if (error instanceof Error)
254
+ return {
255
+ source: "app",
256
+ errorName: errorName(error),
257
+ message: boundFailureMessage(
258
+ ownMessage(error) ?? `${errorName(error)} was thrown without a message.`,
259
+ secrets
260
+ )
261
+ };
262
+ if (typeof error === "string")
263
+ return { source: "app", errorName: "string", message: boundFailureMessage(error, secrets) };
264
+ return {
265
+ source: "app",
266
+ errorName: typeof error,
267
+ message: `A non-Error ${error === null ? "null" : typeof error} value was thrown.`
268
+ };
269
+ };
270
+
271
+ // src/implementation/router-catalog.ts
272
+ var safeFailure = (error, secrets) => {
273
+ const provider = parseProviderError(error);
274
+ if (Option_exports.isSome(provider)) return provider.value;
275
+ const skills = Schema_exports.decodeUnknownOption(SkillLoadFailed)(error);
276
+ if (Option_exports.isSome(skills)) {
277
+ const { reason, message, status } = skills.value;
278
+ return new SkillLoadFailed({
279
+ reason,
280
+ ...message ? { message } : {},
281
+ ...status === void 0 ? {} : { status }
282
+ });
283
+ }
284
+ const mcp = Schema_exports.decodeUnknownOption(McpError)(error);
285
+ if (Option_exports.isSome(mcp)) {
286
+ const { phase, reason, status } = mcp.value;
287
+ return new McpError({ phase, reason, ...status === void 0 ? {} : { status } });
288
+ }
289
+ if (Schema_exports.is(HostDeclarationInvalid)(error)) return error;
290
+ return new HostEvaluationFailed(failureDetail(error, secrets));
291
+ };
292
+ var sourced = (work, secrets) => Effect_exports.suspend(work).pipe(
293
+ Effect_exports.catchCause(
294
+ (cause) => Cause_exports.hasInterrupts(cause) ? Effect_exports.interrupt : Effect_exports.fail(safeFailure(Cause_exports.squash(cause), secrets))
295
+ )
296
+ );
297
+ var routerMeta = (node, secrets) => node.kind === "router" ? Effect_exports.succeed(node.meta) : node.meta === void 0 ? Effect_exports.succeed(node.overrides) : sourced(node.meta, secrets).pipe(Effect_exports.map((meta) => mergeMeta(meta, node.overrides)));
298
+ var routerSkillPrefix = "tools";
299
+ var plainSegment = /^[a-z][a-z0-9]*$/;
300
+ var pathHash = (path) => {
301
+ let hash = 2166136261;
302
+ for (let index = 0; index < path.length; index++)
303
+ hash = Math.imul(hash ^ path.charCodeAt(index), 16777619) >>> 0;
304
+ return hash.toString().padStart(10, "0");
305
+ };
306
+ var routerSkillName = (path) => {
307
+ if (path === "") return routerSkillPrefix;
308
+ const segments = path.split(".");
309
+ const plain = [routerSkillPrefix, ...segments].join("-");
310
+ if (segments.every((segment) => plainSegment.test(segment)) && plain.length <= skillFormatLimits.nameCharacters)
311
+ return plain;
312
+ const hash = pathHash(path);
313
+ const slug = path.toLowerCase().replace(/[^a-z0-9]+/g, "-").slice(0, skillFormatLimits.nameCharacters - routerSkillPrefix.length - hash.length - 2).replace(/^-+|-+$/g, "");
314
+ return [routerSkillPrefix, slug, hash].filter((part) => part !== "").join("-");
315
+ };
316
+ var entry = (path, meta, error) => Schema_exports.decodeUnknownEffect(HostedRouter)({
317
+ path,
318
+ ...meta?.title === void 0 ? {} : { title: meta.title },
319
+ ...meta?.description === void 0 ? {} : { description: meta.description },
320
+ ...meta?.icons === void 0 ? {} : { icons: meta.icons },
321
+ ...meta?.tags === void 0 ? {} : { tags: meta.tags },
322
+ ...meta?.instructions === void 0 ? {} : { skill: routerSkillName(path) },
323
+ ...error === void 0 ? {} : { error }
324
+ }).pipe(Effect_exports.mapError(() => new HostDeclarationInvalid()));
325
+ var invalid = (work) => work.pipe(
326
+ Effect_exports.catchCause(
327
+ (cause) => Cause_exports.hasInterrupts(cause) ? Effect_exports.interrupt : Effect_exports.fail(new HostDeclarationInvalid())
328
+ )
329
+ );
330
+ var summaryFields = (name, router, operation, schedules) => {
331
+ const readOnly = operation.kind === "query";
332
+ return {
333
+ name,
334
+ ...router === "" ? {} : { router },
335
+ ...schedules === void 0 ? {} : { schedules },
336
+ description: operation.description ?? `${readOnly ? "Query" : "Mutate"} ${name}`,
337
+ ...operation.title === void 0 ? {} : { title: operation.title },
338
+ readOnly,
339
+ annotations: { ...operation.annotations, readOnlyHint: readOnly }
340
+ };
341
+ };
342
+ var operationSummary = (name, router, operation, schedules) => invalid(
343
+ Schema_exports.decodeUnknownEffect(HostedToolSummary)(
344
+ summaryFields(name, router, operation, schedules)
345
+ )
346
+ );
347
+ var operationDescription = (name, router, operation, schedules) => invalid(
348
+ Effect_exports.gen(function* () {
349
+ return yield* Schema_exports.decodeUnknownEffect(HostedTool)({
350
+ ...summaryFields(name, router, operation, schedules),
351
+ inputSchema: yield* jsonSchemaDocument(operation.input),
352
+ ...operation.output === void 0 ? operation.outputSchema === void 0 ? {} : { outputSchema: operation.outputSchema } : { outputSchema: yield* jsonSchemaDocument(operation.output) },
353
+ ...operation._meta === void 0 ? {} : { _meta: operation._meta }
354
+ });
355
+ })
356
+ );
357
+ var fixedRouter = (operations, meta) => ({
358
+ kind: "dynamic",
359
+ ...meta === void 0 ? {} : { meta: () => Effect_exports.succeed(meta) },
360
+ list: () => Effect_exports.forEach(
361
+ Object.entries(operations),
362
+ ([name, operation]) => operationDescription(name, "", operation)
363
+ ),
364
+ summaries: () => Effect_exports.forEach(
365
+ Object.entries(operations),
366
+ ([name, operation]) => operationSummary(name, "", operation)
367
+ ),
368
+ describe: (name) => {
369
+ const operation = Object.hasOwn(operations, name) ? operations[name] : void 0;
370
+ return operation === void 0 ? Effect_exports.succeed(void 0) : operationDescription(name, "", operation);
371
+ },
372
+ resolve: (name) => Effect_exports.succeed(Object.hasOwn(operations, name) ? operations[name] : void 0)
373
+ });
374
+ var within = (wanted, path) => [...wanted].flatMap(
375
+ (name) => path === "" ? [name] : name.startsWith(`${path}.`) ? [name.slice(path.length + 1)] : []
376
+ );
377
+ var readCatalog = (root, options) => Effect_exports.gen(function* () {
378
+ const tools = [];
379
+ const routers = [];
380
+ const { wanted, secrets } = options;
381
+ const readSource = (source, path, relative) => Effect_exports.gen(function* () {
382
+ const describe = source.describe;
383
+ const [meta, listed] = yield* Effect_exports.all(
384
+ [
385
+ routerMeta(source, secrets),
386
+ options.summary && source.summaries !== void 0 ? sourced(source.summaries, secrets) : relative !== void 0 && describe !== void 0 ? sourced(
387
+ () => Effect_exports.forEach(relative, (name) => describe(name), {
388
+ concurrency: "unbounded"
389
+ }),
390
+ secrets
391
+ ).pipe(Effect_exports.map((tools2) => tools2.filter((tool) => tool !== void 0))) : sourced(source.list, secrets)
392
+ ],
393
+ { concurrency: "unbounded" }
394
+ );
395
+ const parsed = yield* Schema_exports.decodeUnknownEffect(
396
+ Schema_exports.Array(options.summary ? HostedToolSummary : HostedTool)
397
+ )(listed).pipe(Effect_exports.mapError(() => new HostDeclarationInvalid()));
398
+ const names = /* @__PURE__ */ new Set();
399
+ const found = [];
400
+ for (const tool of parsed) {
401
+ if (names.has(tool.name)) return yield* new HostDeclarationInvalid();
402
+ names.add(tool.name);
403
+ if (relative !== void 0 && !relative.includes(tool.name)) continue;
404
+ const readOnly = tool.readOnly === true;
405
+ found.push({
406
+ ...tool,
407
+ name: joinPath(path, tool.name),
408
+ ...path === "" ? {} : { router: path },
409
+ readOnly,
410
+ annotations: { ...tool.annotations, readOnlyHint: readOnly }
411
+ });
412
+ }
413
+ return { meta, found };
414
+ });
415
+ const include = (source, path, relative) => Effect_exports.gen(function* () {
416
+ if (path === "") {
417
+ const { meta, found } = yield* readSource(source, path, relative);
418
+ tools.push(...found);
419
+ return { meta, error: void 0 };
420
+ }
421
+ const result = yield* Effect_exports.result(readSource(source, path, relative));
422
+ if (Result_exports.isFailure(result)) return { meta: source.overrides, error: result.failure };
423
+ tools.push(...result.success.found);
424
+ return { meta: result.success.meta, error: void 0 };
425
+ });
426
+ const visit = (node, path) => Effect_exports.gen(function* () {
427
+ if (path !== "" || wanted === void 0 && node.meta !== void 0)
428
+ routers.push(yield* entry(path, node.meta));
429
+ for (const [key, child] of Object.entries(node.children)) {
430
+ const name = joinPath(path, key);
431
+ switch (child.kind) {
432
+ case "query":
433
+ case "mutation":
434
+ if (options.scheduled === true && options.schedules(name).length === 0) break;
435
+ if (wanted === void 0 || wanted.has(name))
436
+ tools.push(
437
+ options.summary ? yield* operationSummary(name, path, child, options.schedules(name)) : yield* operationDescription(name, path, child, options.schedules(name))
438
+ );
439
+ break;
440
+ case "router":
441
+ if (wanted === void 0 || within(wanted, name).length > 0)
442
+ yield* visit(child, name);
443
+ break;
444
+ case "dynamic": {
445
+ if (options.scheduled === true) break;
446
+ const relative = wanted === void 0 ? void 0 : within(wanted, name);
447
+ if (relative !== void 0 && relative.length === 0) break;
448
+ const read = yield* include(child, name, relative);
449
+ routers.push(yield* entry(name, read.meta, read.error));
450
+ }
451
+ }
452
+ }
453
+ });
454
+ if (root?.kind === "router") yield* visit(root, "");
455
+ else if (root?.kind === "dynamic" && options.scheduled !== true) {
456
+ const read = yield* include(root, "", wanted === void 0 ? void 0 : [...wanted]);
457
+ if (wanted === void 0 && read.meta !== void 0)
458
+ routers.push(yield* entry("", read.meta));
459
+ }
460
+ return { tools, routers };
461
+ });
462
+ var routerSkills = (root) => Effect_exports.gen(function* () {
463
+ const nodes = [];
464
+ const collect = (node, path) => {
465
+ nodes.push({ path, node });
466
+ if (node.kind === "router") {
467
+ for (const [key, child] of Object.entries(node.children))
468
+ if (child.kind === "router" || child.kind === "dynamic")
469
+ collect(child, joinPath(path, key));
470
+ }
471
+ };
472
+ if (root !== void 0) collect(root, "");
473
+ const skills = yield* Effect_exports.forEach(
474
+ nodes,
475
+ ({ path, node }) => (
476
+ // Skills that fail are skipped, so their failures are never reported.
477
+ routerMeta(node, []).pipe(
478
+ Effect_exports.flatMap((meta) => routerSkill(path, meta)),
479
+ Effect_exports.orElseSucceed(() => void 0)
480
+ )
481
+ ),
482
+ { concurrency: "unbounded" }
483
+ );
484
+ const names = /* @__PURE__ */ new Set();
485
+ return skills.filter((skill) => {
486
+ if (skill === void 0 || names.has(skill.name)) return false;
487
+ names.add(skill.name);
488
+ return true;
489
+ });
490
+ });
491
+ var routerSkill = (path, meta) => Effect_exports.gen(function* () {
492
+ if (meta?.instructions === void 0) return void 0;
493
+ const name = routerSkillName(path);
494
+ const description = ([meta.description, meta.title].find((text) => text !== void 0 && text.trim() !== "") ?? (path === "" ? "How to use this app's tools" : `How to use the ${path} tools`)).slice(0, skillFormatLimits.descriptionCharacters);
495
+ const content = `---
496
+ name: ${name}
497
+ description: ${JSON.stringify(description)}
498
+ ---
499
+
500
+ ${meta.instructions}
501
+ `;
502
+ return yield* skillFromFiles([{ path: "SKILL.md", content }], { name });
503
+ });
504
+
505
+ export {
506
+ OpenapiErrorResponse,
507
+ OpenapiParameter,
508
+ OpenapiRequestBody,
509
+ OpenapiOperation,
510
+ OpenapiToolsOptions,
511
+ OpenapiError,
512
+ defaultOpenapiResponseLimits,
513
+ isOpenapiTextMedia,
514
+ isOpenapiFileSchema,
515
+ openapiBinaryResultSchema,
516
+ openapiMediaKind,
517
+ accountSecrets,
518
+ boundFailureMessage,
519
+ describeFailure,
520
+ failureDetail,
521
+ fixedRouter,
522
+ readCatalog,
523
+ routerSkills
524
+ };