apps 0.0.1-beta.24 → 0.0.1-beta.25

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 (70) hide show
  1. package/framework-reference.json +1 -1
  2. package/js/{chunk-IJX4CYZO.js → chunk-2TP7C25K.js} +3 -3
  3. package/js/{chunk-KUMBKVJD.js → chunk-3YN4UDPB.js} +2 -2
  4. package/js/{chunk-M3B3DE4K.js → chunk-AAAMPT6F.js} +2 -2
  5. package/js/chunk-DAIW2WM3.js +118 -0
  6. package/js/{chunk-CDL5PM2Q.js → chunk-DM5U7G7V.js} +124 -124
  7. package/js/{chunk-ODEIDRGW.js → chunk-DUEZ2XCO.js} +3 -3
  8. package/js/{chunk-K2QATKIF.js → chunk-GG4IFBN3.js} +77 -22
  9. package/js/{chunk-N7YDVXYJ.js → chunk-GH6PY5BQ.js} +1 -1
  10. package/js/{chunk-PZB6T6KU.js → chunk-HQKIPKM5.js} +1 -1
  11. package/js/{chunk-66JAEDTE.js → chunk-IE6W5RNN.js} +2 -2
  12. package/js/{chunk-WFEUCUFF.js → chunk-J3RUZMLO.js} +88 -26
  13. package/js/{chunk-JWNSH5CA.js → chunk-K3MQX2KO.js} +2 -2
  14. package/js/{chunk-27F7W2LG.js → chunk-KKGRSXUK.js} +1 -1
  15. package/js/{chunk-57RKNWL2.js → chunk-KNJAOYV4.js} +2 -2
  16. package/js/{chunk-ZQINWV4W.js → chunk-LPN4ONWW.js} +2 -2
  17. package/js/{chunk-A5BSZKFF.js → chunk-NXO2GN2T.js} +8 -8
  18. package/js/{chunk-UK573G7W.js → chunk-OBXHLFGQ.js} +1 -1
  19. package/js/{chunk-IPI4MFSN.js → chunk-PC5RHPUP.js} +2 -2
  20. package/js/{chunk-VFZKSM3T.js → chunk-SUY33XAY.js} +1 -1
  21. package/js/{chunk-R3EV5FTO.js → chunk-T7WRQJUF.js} +55 -3
  22. package/js/{chunk-JU7VHODU.js → chunk-TACLXEAE.js} +1 -1
  23. package/js/{chunk-2KZ7GG43.js → chunk-VGEPL4BV.js} +146 -53
  24. package/js/{chunk-B3T7CZOH.js → chunk-VSLWGXPW.js} +29 -7
  25. package/js/{chunk-3HH4OZR3.js → chunk-VWU6I23D.js} +23 -25
  26. package/js/{chunk-S47NFEWF.js → chunk-WPKXOTKM.js} +3 -3
  27. package/js/{chunk-PJJ24GU7.js → chunk-XBG3M64K.js} +1 -1
  28. package/js/{chunk-AK54RD3A.js → chunk-XIRAIB3P.js} +4 -4
  29. package/js/{chunk-NKLWZJLE.js → chunk-ZVMZWXVF.js} +2 -2
  30. package/js/client.js +10 -10
  31. package/js/contracts.js +36 -14
  32. package/js/effect.js +19 -19
  33. package/js/graphql.js +21 -21
  34. package/js/host.js +19 -19
  35. package/js/index.js +12 -12
  36. package/js/mcp/effect.js +21 -21
  37. package/js/mcp/stdio.js +30 -25
  38. package/js/mcp.js +23 -23
  39. package/js/openapi.js +15 -15
  40. package/js/react.js +3 -3
  41. package/js/skills/effect.js +3 -3
  42. package/js/skills.js +11 -11
  43. package/js/storage/facet.js +4 -4
  44. package/js/ui/auth/contracts.js +2 -2
  45. package/js/ui/auth.js +5 -5
  46. package/js/ui/contracts.js +4 -4
  47. package/js/ui/serving.js +8 -8
  48. package/package.json +1 -1
  49. package/runtime.json +1 -1
  50. package/types/apps/src/contracts/api-response-error.d.ts +4 -0
  51. package/types/apps/src/contracts/failure.d.ts +30 -1
  52. package/types/apps/src/contracts/host.d.ts +5 -4
  53. package/types/apps/src/contracts/mcp.d.ts +8 -1
  54. package/types/apps/src/contracts/protocol-version.d.ts +2 -2
  55. package/types/apps/src/contracts/protocols/1.d.ts +16 -2
  56. package/types/apps/src/contracts/protocols/2.d.ts +1 -1
  57. package/types/apps/src/contracts/protocols/3.d.ts +1 -3
  58. package/types/apps/src/contracts/protocols/4.d.ts +1 -2
  59. package/types/apps/src/contracts/protocols/5.d.ts +3 -3
  60. package/types/apps/src/contracts/protocols/6.d.ts +3 -3
  61. package/types/apps/src/contracts/protocols/7.d.ts +3 -3
  62. package/types/apps/src/contracts/protocols/8.d.ts +1119 -0
  63. package/types/apps/src/contracts/provider-error.d.ts +9 -0
  64. package/types/apps/src/implementation/failure-detail.d.ts +22 -3
  65. package/types/apps/src/implementation/mcp-client.d.ts +6 -0
  66. package/types/apps/src/implementation/provider-error.d.ts +28 -1
  67. package/types/apps/src/implementation/router-catalog.d.ts +2 -3
  68. package/types/apps/src/implementation/upstream-error.d.ts +7 -0
  69. package/types/telemetry/src/config.d.ts +2 -2
  70. package/js/chunk-MKWZPDR6.js +0 -63
@@ -1,37 +1,42 @@
1
1
  import {
2
2
  adaptMcpTools,
3
+ answeredError,
3
4
  mcpClient,
4
5
  mcpJsonSchemaValidator
5
- } from "./chunk-B3T7CZOH.js";
6
+ } from "./chunk-VSLWGXPW.js";
6
7
  import {
7
8
  accountProviderError,
8
- httpProviderError
9
- } from "./chunk-MKWZPDR6.js";
9
+ bodyUpstreamError,
10
+ httpProviderError,
11
+ providerErrorDetail
12
+ } from "./chunk-DAIW2WM3.js";
10
13
  import {
11
14
  McpError,
12
15
  McpToolsOptions,
13
16
  defaultMcpClientLimits
14
- } from "./chunk-2KZ7GG43.js";
17
+ } from "./chunk-VGEPL4BV.js";
15
18
  import {
16
19
  ProviderError
17
- } from "./chunk-R3EV5FTO.js";
20
+ } from "./chunk-T7WRQJUF.js";
18
21
  import {
19
22
  captureTelemetry
20
- } from "./chunk-ODEIDRGW.js";
23
+ } from "./chunk-DUEZ2XCO.js";
21
24
  import {
22
25
  FetchHttpClient_exports
23
- } from "./chunk-57RKNWL2.js";
26
+ } from "./chunk-KNJAOYV4.js";
24
27
  import {
25
28
  HttpClientRequest_exports,
26
29
  HttpClient_exports
27
- } from "./chunk-UK573G7W.js";
30
+ } from "./chunk-OBXHLFGQ.js";
28
31
  import {
29
32
  Deferred_exports,
30
33
  Effect_exports,
34
+ Option_exports,
31
35
  Redacted_exports,
36
+ Ref_exports,
32
37
  Schema_exports,
33
38
  Stream_exports
34
- } from "./chunk-CDL5PM2Q.js";
39
+ } from "./chunk-DM5U7G7V.js";
35
40
 
36
41
  // src/implementation/mcp.ts
37
42
  import { UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js";
@@ -51,13 +56,39 @@ var failure = (phase, error) => {
51
56
  const status = error instanceof UnauthorizedError ? 401 : error instanceof StreamableHTTPError || error instanceof SseError ? error.code : void 0;
52
57
  const provider = status === void 0 ? void 0 : httpProviderError(status);
53
58
  if (provider !== void 0) return provider;
59
+ const upstream = answeredError(error);
54
60
  return new McpError({
55
61
  phase,
56
62
  reason: error instanceof ProtocolError && error.code === ErrorCode.RequestTimeout ? "timeout" : "request",
57
- ...status === void 0 ? {} : { status }
63
+ ...status === void 0 ? {} : { status },
64
+ ...upstream === void 0 ? {} : { upstream }
58
65
  });
59
66
  };
60
- var transportFetch = (connection, telemetry, rejected) => (url, init) => Effect_exports.runPromiseWith(telemetry.context)(
67
+ var errorBodyLimits = { maxBytes: 65536, readTimeoutMs: 2e3 };
68
+ var errorBody = (response) => Effect_exports.gen(function* () {
69
+ const json = /^application\/(?:[\w.-]+\+)?json$/i.test(
70
+ response.headers["content-type"]?.split(";")[0]?.trim() ?? ""
71
+ );
72
+ const length = response.headers["content-length"];
73
+ if (!json || length !== void 0 && Number(length) > errorBodyLimits.maxBytes)
74
+ return { body: Stream_exports.toReadableStream(response.stream), upstream: void 0 };
75
+ const unreadable = new McpError({ phase: "transport", reason: "invalid_response" });
76
+ const read = yield* response.stream.pipe(
77
+ Stream_exports.mapError(() => unreadable),
78
+ Stream_exports.limitBytes(errorBodyLimits.maxBytes, () => Stream_exports.fail(unreadable)),
79
+ Stream_exports.decodeText,
80
+ Stream_exports.mkString,
81
+ Effect_exports.timeout(errorBodyLimits.readTimeoutMs),
82
+ Effect_exports.option
83
+ );
84
+ if (Option_exports.isNone(read)) return { body: null, upstream: void 0 };
85
+ const parsed = Schema_exports.decodeUnknownOption(Schema_exports.fromJsonString(Schema_exports.Json))(read.value);
86
+ return {
87
+ body: read.value,
88
+ upstream: Option_exports.isSome(parsed) ? bodyUpstreamError(parsed.value) : void 0
89
+ };
90
+ });
91
+ var transportFetch = (connection, telemetry, rejected, answered) => (url, init) => Effect_exports.runPromiseWith(telemetry.context)(
61
92
  Effect_exports.gen(function* () {
62
93
  const target = yield* Effect_exports.try({
63
94
  try: () => new URL(url),
@@ -75,18 +106,23 @@ var transportFetch = (connection, telemetry, rejected) => (url, init) => Effect_
75
106
  });
76
107
  const client = yield* HttpClient_exports.HttpClient;
77
108
  const response = yield* client.execute(request);
109
+ if (response.status < 400)
110
+ return new Response(
111
+ [204, 205, 304].includes(response.status) ? null : Stream_exports.toReadableStream(response.stream),
112
+ {
113
+ status: response.status,
114
+ headers: response.headers
115
+ }
116
+ );
117
+ const { body, upstream } = yield* errorBody(response);
78
118
  const provider = httpProviderError(response.status, response.headers);
79
119
  if (provider !== void 0) {
80
- yield* Deferred_exports.fail(rejected, provider);
81
- return yield* provider;
120
+ const refused = providerErrorDetail(provider, { upstream });
121
+ yield* Deferred_exports.fail(rejected, refused);
122
+ return yield* refused;
82
123
  }
83
- return new Response(
84
- [204, 205, 304].includes(response.status) ? null : Stream_exports.toReadableStream(response.stream),
85
- {
86
- status: response.status,
87
- headers: response.headers
88
- }
89
- );
124
+ yield* Ref_exports.set(answered, { status: response.status, upstream });
125
+ return new Response(body, { status: response.status, headers: response.headers });
90
126
  }).pipe(
91
127
  Effect_exports.provide(FetchHttpClient_exports.layer),
92
128
  Effect_exports.provideService(FetchHttpClient_exports.RequestInit, { redirect: "manual" }),
@@ -104,15 +140,30 @@ var transportFetch = (connection, telemetry, rejected) => (url, init) => Effect_
104
140
  ),
105
141
  init?.signal ? { signal: init.signal } : {}
106
142
  );
143
+ var explain = (error, phase, response) => {
144
+ if (Schema_exports.is(ProviderError)(error)) return providerErrorDetail(error, { phase });
145
+ if (!Schema_exports.is(McpError)(error) || error.upstream !== void 0 || error.status === void 0 || response?.status !== error.status || response.upstream === void 0)
146
+ return error;
147
+ return new McpError({
148
+ phase: error.phase,
149
+ reason: error.reason,
150
+ status: error.status,
151
+ upstream: response.upstream
152
+ });
153
+ };
154
+ var explained = (phase, answered) => (error) => Ref_exports.get(answered).pipe(
155
+ Effect_exports.flatMap((response) => Effect_exports.fail(explain(error, phase, response)))
156
+ );
107
157
  function withClient(connection, mode, use, changed) {
108
158
  const attempt = (kind) => Effect_exports.scoped(
109
159
  Effect_exports.gen(function* () {
110
160
  const telemetry = yield* captureTelemetry;
111
161
  const rejected = yield* Deferred_exports.make();
162
+ const answered = yield* Ref_exports.make(void 0);
112
163
  const pending = /* @__PURE__ */ new Set();
113
164
  const { client, transport } = yield* Effect_exports.acquireRelease(
114
165
  Effect_exports.sync(() => {
115
- const fetch = transportFetch(connection, telemetry, rejected);
166
+ const fetch = transportFetch(connection, telemetry, rejected, answered);
116
167
  const client2 = new Client(
117
168
  { name: "executor-apps", version: "0.1.0" },
118
169
  {
@@ -168,10 +219,14 @@ function withClient(connection, mode, use, changed) {
168
219
  catch: (error) => failure("connect", error)
169
220
  }).pipe(
170
221
  Effect_exports.raceFirst(Deferred_exports.await(rejected)),
222
+ Effect_exports.catch(explained("connect", answered)),
171
223
  Effect_exports.timeout(connection.timeoutMs),
172
224
  Effect_exports.withSpan("provider.mcp.connect")
173
225
  );
174
- return yield* use(client).pipe(Effect_exports.raceFirst(Deferred_exports.await(rejected)));
226
+ return yield* use(client).pipe(
227
+ Effect_exports.raceFirst(Deferred_exports.await(rejected)),
228
+ Effect_exports.catch(explained(mode, answered))
229
+ );
175
230
  })
176
231
  ).pipe(
177
232
  Effect_exports.withSpan("provider.mcp.session", {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Schema_exports
3
- } from "./chunk-CDL5PM2Q.js";
3
+ } from "./chunk-DM5U7G7V.js";
4
4
 
5
5
  // ../app-data/src/contracts/database.ts
6
6
  var DataName = Schema_exports.String.check(
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Schema_exports
3
- } from "./chunk-CDL5PM2Q.js";
3
+ } from "./chunk-DM5U7G7V.js";
4
4
 
5
5
  // src/contracts/storage.ts
6
6
  var StorageName = Schema_exports.NonEmptyString.check(Schema_exports.isMaxLength(200));
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  JsonObject,
3
3
  ValidationError
4
- } from "./chunk-27F7W2LG.js";
4
+ } from "./chunk-KKGRSXUK.js";
5
5
  import {
6
6
  Cause_exports,
7
7
  Effect_exports,
@@ -10,7 +10,7 @@ import {
10
10
  SchemaIssue_exports,
11
11
  SchemaParser_exports,
12
12
  Schema_exports
13
- } from "./chunk-CDL5PM2Q.js";
13
+ } from "./chunk-DM5U7G7V.js";
14
14
 
15
15
  // ../../node_modules/.bun/@cfworker+json-schema@4.1.1/node_modules/@cfworker/json-schema/dist/esm/deep-compare-strict.js
16
16
  function deepCompareStrict(a, b) {
@@ -1,13 +1,15 @@
1
1
  import {
2
2
  skillFromFiles
3
- } from "./chunk-IPI4MFSN.js";
3
+ } from "./chunk-PC5RHPUP.js";
4
4
  import {
5
5
  joinPath,
6
6
  mergeMeta
7
- } from "./chunk-S47NFEWF.js";
7
+ } from "./chunk-WPKXOTKM.js";
8
8
  import {
9
- parseProviderError
10
- } from "./chunk-MKWZPDR6.js";
9
+ isShortenedUpstream,
10
+ parseProviderError,
11
+ providerError
12
+ } from "./chunk-DAIW2WM3.js";
11
13
  import {
12
14
  ApiErrorResponse,
13
15
  HostDeclarationInvalid,
@@ -15,31 +17,36 @@ import {
15
17
  HostedRouter,
16
18
  HostedTool,
17
19
  HostedToolSummary,
18
- McpError,
19
- maxFailureMessageLength
20
- } from "./chunk-2KZ7GG43.js";
20
+ McpError
21
+ } from "./chunk-VGEPL4BV.js";
21
22
  import {
22
23
  AppDatabaseError
23
- } from "./chunk-N7YDVXYJ.js";
24
+ } from "./chunk-GH6PY5BQ.js";
24
25
  import {
25
- CacheError
26
- } from "./chunk-R3EV5FTO.js";
26
+ CacheError,
27
+ FailureCode,
28
+ FailureFieldName,
29
+ maxFailureFieldLength,
30
+ maxFailureFields,
31
+ maxFailureMessageLength,
32
+ maxUpstreamMessageLength
33
+ } from "./chunk-T7WRQJUF.js";
27
34
  import {
28
35
  SkillLoadFailed,
29
36
  skillFormatLimits
30
- } from "./chunk-JU7VHODU.js";
37
+ } from "./chunk-TACLXEAE.js";
31
38
  import {
32
39
  jsonSchemaDocument
33
- } from "./chunk-66JAEDTE.js";
40
+ } from "./chunk-IE6W5RNN.js";
34
41
  import {
35
42
  AppStorageError,
36
43
  AppStorageUnavailable
37
- } from "./chunk-PZB6T6KU.js";
44
+ } from "./chunk-HQKIPKM5.js";
38
45
  import {
39
46
  AccountId,
40
47
  HttpUrl,
41
48
  JsonObject
42
- } from "./chunk-27F7W2LG.js";
49
+ } from "./chunk-KKGRSXUK.js";
43
50
  import {
44
51
  Cause_exports,
45
52
  Effect_exports,
@@ -48,7 +55,7 @@ import {
48
55
  Redacted_exports,
49
56
  Result_exports,
50
57
  Schema_exports
51
- } from "./chunk-CDL5PM2Q.js";
58
+ } from "./chunk-DM5U7G7V.js";
52
59
 
53
60
  // src/contracts/openapi.ts
54
61
  var OpenapiErrorResponse = Schema_exports.Struct({
@@ -204,12 +211,63 @@ var accountFieldSecrets = (accounts) => {
204
211
  return [...found].sort((a, b) => b.length - a.length);
205
212
  };
206
213
  var accountSecrets = (accounts) => accountFieldSecrets(Redacted_exports.value(accounts));
207
- var boundFailureMessage = (message, secrets) => {
208
- let redacted = message;
214
+ var replaceSecrets = (text, secrets) => {
215
+ let redacted = text;
209
216
  for (const secret of secrets) redacted = redacted.split(secret).join("[redacted]");
210
- return redacted.length <= maxFailureMessageLength ? redacted : `${redacted.slice(0, maxFailureMessageLength - 1)}\u2026`;
217
+ return redacted;
211
218
  };
219
+ var bound = (text, maximum) => text.length <= maximum ? text : `${text.slice(0, maximum - 1)}\u2026`;
220
+ var boundText = (text, secrets, maximum) => bound(replaceSecrets(text, secrets), maximum);
221
+ var replaceSecretStart = (text, secrets) => {
222
+ let longest = 0;
223
+ for (const secret of secrets)
224
+ for (let length = Math.min(secret.length - 1, text.length); length > longest; length--)
225
+ if (text.endsWith(secret.slice(0, length))) {
226
+ longest = length;
227
+ break;
228
+ }
229
+ return longest === 0 ? text : `${text.slice(0, -longest)}[redacted]`;
230
+ };
231
+ var boundFailureMessage = (message, secrets) => boundText(message, secrets, maxFailureMessageLength);
232
+ var redactUpstream = (upstream, secrets) => {
233
+ if (upstream?.message === void 0) return upstream;
234
+ const message = isShortenedUpstream(upstream.message) ? `${replaceSecretStart(replaceSecrets(upstream.message.slice(0, -1), secrets), secrets)}\u2026` : replaceSecrets(upstream.message, secrets);
235
+ return { code: upstream.code, message: bound(message, maxUpstreamMessageLength) };
236
+ };
237
+ var leavingProviderError = (error, secrets, phase) => providerError({
238
+ ...error,
239
+ phase: error.phase ?? phase,
240
+ upstream: redactUpstream(error.upstream, secrets)
241
+ });
242
+ var parseMcpError = (error, secrets) => Schema_exports.decodeUnknownOption(McpError)(error).pipe(
243
+ Option_exports.map(({ phase, reason, status, upstream }) => {
244
+ const stated = redactUpstream(upstream, secrets);
245
+ return new McpError({
246
+ phase,
247
+ reason,
248
+ ...status === void 0 ? {} : { status },
249
+ ...stated === void 0 ? {} : { upstream: stated }
250
+ });
251
+ })
252
+ );
212
253
  var errorName = (error) => (error.name.length > 0 ? error.name : "Error").slice(0, 128);
254
+ var ownCode = (error, secrets) => Predicate_exports.hasProperty(error, "code") && Schema_exports.is(FailureCode)(error.code) && error.code !== "" ? boundText(error.code, secrets, 128) : void 0;
255
+ var reservedFields = /* @__PURE__ */ new Set(["name", "message", "stack", "cause", "_tag"]);
256
+ var ownFields = (error, code, secrets) => {
257
+ const fields = {};
258
+ let count = 0;
259
+ for (const [key, value] of Object.entries(error)) {
260
+ if (count === maxFailureFields) break;
261
+ if (reservedFields.has(key) || key === "code" && code !== void 0) continue;
262
+ if (!Schema_exports.is(FailureFieldName)(key)) continue;
263
+ if (typeof value === "string") fields[key] = boundText(value, secrets, maxFailureFieldLength);
264
+ else if (typeof value === "boolean" || typeof value === "number" && Number.isFinite(value))
265
+ fields[key] = value;
266
+ else continue;
267
+ count++;
268
+ }
269
+ return count === 0 ? void 0 : fields;
270
+ };
213
271
  var ownMessage = (error) => {
214
272
  const cause = error.cause;
215
273
  const suffix = cause instanceof Error && cause.message.length > 0 ? ` (caused by ${errorName(cause)}: ${cause.message})` : "";
@@ -250,15 +308,20 @@ var failureDetail = (error, secrets) => {
250
308
  code: error.reason,
251
309
  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
310
  };
253
- if (error instanceof Error)
311
+ if (error instanceof Error) {
312
+ const code = ownCode(error, secrets);
313
+ const fields = ownFields(error, code, secrets);
254
314
  return {
255
315
  source: "app",
256
316
  errorName: errorName(error),
317
+ ...code === void 0 ? {} : { code },
257
318
  message: boundFailureMessage(
258
319
  ownMessage(error) ?? `${errorName(error)} was thrown without a message.`,
259
320
  secrets
260
- )
321
+ ),
322
+ ...fields === void 0 ? {} : { fields }
261
323
  };
324
+ }
262
325
  if (typeof error === "string")
263
326
  return { source: "app", errorName: "string", message: boundFailureMessage(error, secrets) };
264
327
  return {
@@ -271,7 +334,7 @@ var failureDetail = (error, secrets) => {
271
334
  // src/implementation/router-catalog.ts
272
335
  var safeFailure = (error, secrets) => {
273
336
  const provider = parseProviderError(error);
274
- if (Option_exports.isSome(provider)) return provider.value;
337
+ if (Option_exports.isSome(provider)) return leavingProviderError(provider.value, secrets, "discover");
275
338
  const skills = Schema_exports.decodeUnknownOption(SkillLoadFailed)(error);
276
339
  if (Option_exports.isSome(skills)) {
277
340
  const { reason, message, status } = skills.value;
@@ -281,11 +344,8 @@ var safeFailure = (error, secrets) => {
281
344
  ...status === void 0 ? {} : { status }
282
345
  });
283
346
  }
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
- }
347
+ const mcp = parseMcpError(error, secrets);
348
+ if (Option_exports.isSome(mcp)) return mcp.value;
289
349
  if (Schema_exports.is(HostDeclarationInvalid)(error)) return error;
290
350
  return new HostEvaluationFailed(failureDetail(error, secrets));
291
351
  };
@@ -516,6 +576,8 @@ export {
516
576
  openapiMediaKind,
517
577
  accountSecrets,
518
578
  boundFailureMessage,
579
+ leavingProviderError,
580
+ parseMcpError,
519
581
  describeFailure,
520
582
  failureDetail,
521
583
  operationDescription,
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  fixedRouter
3
- } from "./chunk-WFEUCUFF.js";
3
+ } from "./chunk-J3RUZMLO.js";
4
4
  import {
5
5
  nativeOperation,
6
6
  operationDeclaration,
7
7
  routerDeclaration
8
- } from "./chunk-S47NFEWF.js";
8
+ } from "./chunk-WPKXOTKM.js";
9
9
 
10
10
  // src/implementation/protocol-operations.ts
11
11
  var protocolOperations = (operations, kinds = {}) => {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Schema_exports
3
- } from "./chunk-CDL5PM2Q.js";
3
+ } from "./chunk-DM5U7G7V.js";
4
4
 
5
5
  // src/contracts/schema.ts
6
6
  var JsonValue = Schema_exports.Json;
@@ -4,7 +4,7 @@ import {
4
4
  fromWeb,
5
5
  layerMergedContext,
6
6
  make2 as make
7
- } from "./chunk-UK573G7W.js";
7
+ } from "./chunk-OBXHLFGQ.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-CDL5PM2Q.js";
20
+ } from "./chunk-DM5U7G7V.js";
21
21
  import {
22
22
  __export
23
23
  } from "./chunk-CZ7CSFO4.js";
@@ -12,7 +12,7 @@ import {
12
12
  defaultDatabaseLimits,
13
13
  defaultDatabaseRuntimeLimits,
14
14
  reservedFieldNames
15
- } from "./chunk-N7YDVXYJ.js";
15
+ } from "./chunk-GH6PY5BQ.js";
16
16
  import {
17
17
  Cause_exports,
18
18
  Clock_exports,
@@ -20,7 +20,7 @@ import {
20
20
  Encoding_exports,
21
21
  Schema_exports,
22
22
  Semaphore_exports
23
- } from "./chunk-CDL5PM2Q.js";
23
+ } from "./chunk-DM5U7G7V.js";
24
24
 
25
25
  // ../app-data/src/implementation/schema.ts
26
26
  var metadata = new Set(reservedFieldNames);
@@ -1,33 +1,33 @@
1
1
  import {
2
2
  promiseTable
3
- } from "./chunk-ZQINWV4W.js";
3
+ } from "./chunk-LPN4ONWW.js";
4
4
  import {
5
5
  declaredOperations,
6
6
  fromPromise,
7
7
  nativeOperation,
8
8
  nativeRouter
9
- } from "./chunk-S47NFEWF.js";
9
+ } from "./chunk-WPKXOTKM.js";
10
10
  import {
11
11
  ScheduleTiming
12
- } from "./chunk-2KZ7GG43.js";
12
+ } from "./chunk-VGEPL4BV.js";
13
13
  import {
14
14
  DatabaseSchema
15
- } from "./chunk-N7YDVXYJ.js";
15
+ } from "./chunk-GH6PY5BQ.js";
16
16
  import {
17
17
  decoderOf,
18
18
  isSchema,
19
19
  storageFieldOf
20
- } from "./chunk-66JAEDTE.js";
20
+ } from "./chunk-IE6W5RNN.js";
21
21
  import {
22
22
  AppStorageUnavailable
23
- } from "./chunk-PZB6T6KU.js";
23
+ } from "./chunk-HQKIPKM5.js";
24
24
  import {
25
25
  JsonValue
26
- } from "./chunk-27F7W2LG.js";
26
+ } from "./chunk-KKGRSXUK.js";
27
27
  import {
28
28
  Effect_exports,
29
29
  Schema_exports
30
- } from "./chunk-CDL5PM2Q.js";
30
+ } from "./chunk-DM5U7G7V.js";
31
31
 
32
32
  // src/contracts/http.ts
33
33
  var ResponseStatusError = class extends Schema_exports.TaggedError()(
@@ -211,7 +211,7 @@ import {
211
211
  withFiber,
212
212
  withParentSpan,
213
213
  zero2 as zero
214
- } from "./chunk-CDL5PM2Q.js";
214
+ } from "./chunk-DM5U7G7V.js";
215
215
  import {
216
216
  __export
217
217
  } from "./chunk-CZ7CSFO4.js";
@@ -5,11 +5,11 @@ import {
5
5
  SkillDefinitionInvalid,
6
6
  SkillFile,
7
7
  SkillFilePath
8
- } from "./chunk-JU7VHODU.js";
8
+ } from "./chunk-TACLXEAE.js";
9
9
  import {
10
10
  Effect_exports,
11
11
  Schema_exports
12
- } from "./chunk-CDL5PM2Q.js";
12
+ } from "./chunk-DM5U7G7V.js";
13
13
 
14
14
  // src/implementation/skill-files.ts
15
15
  var skillFromFiles = (input, source = {}) => Effect_exports.gen(function* () {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Schema_exports
3
- } from "./chunk-CDL5PM2Q.js";
3
+ } from "./chunk-DM5U7G7V.js";
4
4
 
5
5
  // src/contracts/ui-auth.ts
6
6
  var AppSignInId = Schema_exports.String.check(Schema_exports.isPattern(/^[a-f0-9]{64}$/)).pipe(
@@ -1,15 +1,53 @@
1
1
  import {
2
2
  AccountId
3
- } from "./chunk-27F7W2LG.js";
3
+ } from "./chunk-KKGRSXUK.js";
4
4
  import {
5
5
  Schema_exports
6
- } from "./chunk-CDL5PM2Q.js";
6
+ } from "./chunk-DM5U7G7V.js";
7
+
8
+ // src/contracts/failure.ts
9
+ var maxFailureMessageLength = 2048;
10
+ var FailureSource = Schema_exports.Literals(["app", "storage", "service"]);
11
+ var FailureName = Schema_exports.String.check(Schema_exports.isMaxLength(128));
12
+ var FailureCode = Schema_exports.String.check(Schema_exports.isMaxLength(128));
13
+ var FailureMessage = Schema_exports.String.check(Schema_exports.isMaxLength(maxFailureMessageLength));
14
+ var maxFailureFields = 8;
15
+ var maxFailureFieldLength = 256;
16
+ var FailureFieldName = Schema_exports.String.check(
17
+ Schema_exports.isPattern(/^[A-Za-z_$][A-Za-z0-9_$]{0,63}$/)
18
+ );
19
+ var FailureFieldValue = Schema_exports.Union([
20
+ Schema_exports.String.check(Schema_exports.isMaxLength(maxFailureFieldLength)),
21
+ Schema_exports.Finite,
22
+ Schema_exports.Boolean
23
+ ]);
24
+ var FailureFields = Schema_exports.Record(FailureFieldName, FailureFieldValue).check(
25
+ Schema_exports.isMaxProperties(maxFailureFields)
26
+ );
27
+ var FailureDetail = {
28
+ source: Schema_exports.optionalKey(FailureSource),
29
+ errorName: Schema_exports.optionalKey(FailureName),
30
+ code: Schema_exports.optionalKey(FailureCode),
31
+ message: Schema_exports.optionalKey(FailureMessage),
32
+ fields: Schema_exports.optionalKey(FailureFields)
33
+ };
34
+ var maxUpstreamMessageLength = 1024;
35
+ var UpstreamError = Schema_exports.Struct({
36
+ code: Schema_exports.Union([
37
+ Schema_exports.Int,
38
+ Schema_exports.String.check(Schema_exports.isMinLength(1), Schema_exports.isMaxLength(128))
39
+ ]),
40
+ message: Schema_exports.optionalKey(Schema_exports.String.check(Schema_exports.isMaxLength(maxUpstreamMessageLength)))
41
+ });
42
+ var FailurePhase = Schema_exports.Literals(["connect", "discover", "call"]);
7
43
 
8
44
  // src/contracts/provider-error.ts
9
45
  var ProviderError = class extends Schema_exports.TaggedError()("ProviderError", {
10
46
  reason: Schema_exports.Literals(["unauthorized", "forbidden", "rate_limited", "unavailable", "rejected"]),
11
47
  status: Schema_exports.optional(Schema_exports.Int.check(Schema_exports.isBetween({ minimum: 100, maximum: 599 }))),
12
- accountId: Schema_exports.optional(AccountId)
48
+ accountId: Schema_exports.optional(AccountId),
49
+ phase: Schema_exports.optional(FailurePhase),
50
+ upstream: Schema_exports.optional(UpstreamError)
13
51
  }) {
14
52
  };
15
53
 
@@ -87,6 +125,20 @@ var CacheReply = Schema_exports.Union([
87
125
  ]);
88
126
 
89
127
  export {
128
+ maxFailureMessageLength,
129
+ FailureSource,
130
+ FailureName,
131
+ FailureCode,
132
+ FailureMessage,
133
+ maxFailureFields,
134
+ maxFailureFieldLength,
135
+ FailureFieldName,
136
+ FailureFieldValue,
137
+ FailureFields,
138
+ FailureDetail,
139
+ maxUpstreamMessageLength,
140
+ UpstreamError,
141
+ FailurePhase,
90
142
  ProviderError,
91
143
  CacheError,
92
144
  cacheLimits,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Schema_exports
3
- } from "./chunk-CDL5PM2Q.js";
3
+ } from "./chunk-DM5U7G7V.js";
4
4
 
5
5
  // src/contracts/skills.ts
6
6
  var SkillFilePath = Schema_exports.NonEmptyString.check(