apps 0.0.1-beta.26 → 0.0.1-beta.27

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 (56) hide show
  1. package/README.md +6 -6
  2. package/framework-reference.json +1 -1
  3. package/js/{chunk-BTRBOOTD.js → chunk-3TEX4ZND.js} +23 -17
  4. package/js/{chunk-OI7OI2U3.js → chunk-4OD7PHQL.js} +2 -2
  5. package/js/{chunk-AAAMPT6F.js → chunk-65SZ23BK.js} +2 -2
  6. package/js/{chunk-XBG3M64K.js → chunk-6JBTHTI5.js} +1 -1
  7. package/js/{chunk-EXDR4HVM.js → chunk-7AZNPMQH.js} +53 -11
  8. package/js/{chunk-VGEPL4BV.js → chunk-7R5JY5H7.js} +19 -5
  9. package/js/{chunk-4CMJD7AB.js → chunk-AHI26TO6.js} +24 -8
  10. package/js/{chunk-OBXHLFGQ.js → chunk-B5YJQU45.js} +1 -1
  11. package/js/{chunk-T7WRQJUF.js → chunk-BRGF7VFN.js} +2 -2
  12. package/js/{chunk-HQKIPKM5.js → chunk-BTJMXW4I.js} +1 -1
  13. package/js/{chunk-HIYRKEWP.js → chunk-HIJW4LWC.js} +64 -21
  14. package/js/{chunk-DAIW2WM3.js → chunk-KQCMHI3K.js} +3 -3
  15. package/js/{chunk-GH6PY5BQ.js → chunk-M2KEEOIQ.js} +1 -1
  16. package/js/{chunk-TACLXEAE.js → chunk-NSBRV4FJ.js} +1 -1
  17. package/js/{chunk-DM5U7G7V.js → chunk-NXTXZ635.js} +1842 -1840
  18. package/js/{chunk-3YN4UDPB.js → chunk-PTUZSCEV.js} +2 -2
  19. package/js/{chunk-KKGRSXUK.js → chunk-PWF2DRJ3.js} +1 -1
  20. package/js/{chunk-2TP7C25K.js → chunk-SDLIDQXG.js} +3 -3
  21. package/js/{chunk-NXO2GN2T.js → chunk-T2UFJKZR.js} +8 -8
  22. package/js/{chunk-PC5RHPUP.js → chunk-TSLG2WPA.js} +2 -2
  23. package/js/{chunk-WPKXOTKM.js → chunk-TX2XCAL6.js} +3 -3
  24. package/js/{chunk-KNJAOYV4.js → chunk-V2I3MMPM.js} +2 -2
  25. package/js/{chunk-ZVMZWXVF.js → chunk-VUVBMNKC.js} +2 -2
  26. package/js/{chunk-SUY33XAY.js → chunk-WQ5MVBTP.js} +1 -1
  27. package/js/{chunk-LPN4ONWW.js → chunk-XBQTJP76.js} +2 -2
  28. package/js/{chunk-IE6W5RNN.js → chunk-YML53Z7H.js} +2 -2
  29. package/js/{chunk-DUEZ2XCO.js → chunk-YXKXKGN6.js} +3 -3
  30. package/js/{chunk-XIRAIB3P.js → chunk-ZZOCEUTB.js} +4 -4
  31. package/js/client.js +10 -10
  32. package/js/contracts.js +7 -7
  33. package/js/effect.js +19 -19
  34. package/js/graphql.js +21 -21
  35. package/js/host.js +19 -19
  36. package/js/index.js +12 -12
  37. package/js/mcp/effect.js +23 -21
  38. package/js/mcp/stdio.js +21 -21
  39. package/js/mcp.js +29 -24
  40. package/js/openapi.js +15 -15
  41. package/js/react.js +3 -3
  42. package/js/skills/effect.js +3 -3
  43. package/js/skills.js +11 -11
  44. package/js/storage/facet.js +4 -4
  45. package/js/ui/auth/contracts.js +2 -2
  46. package/js/ui/auth.js +5 -5
  47. package/js/ui/contracts.js +4 -4
  48. package/js/ui/serving.js +8 -8
  49. package/package.json +1 -1
  50. package/runtime.json +1 -1
  51. package/types/apps/src/contracts/mcp.d.ts +49 -3
  52. package/types/apps/src/contracts/provider.d.ts +6 -0
  53. package/types/apps/src/implementation/failure-detail.d.ts +3 -2
  54. package/types/apps/src/implementation/mcp-client.d.ts +1 -0
  55. package/types/apps/src/implementation/mcp.d.ts +11 -1
  56. package/types/apps/src/mcp.d.ts +20 -1
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  makeCache
3
- } from "./chunk-ZVMZWXVF.js";
3
+ } from "./chunk-VUVBMNKC.js";
4
4
  import {
5
5
  accountSecrets,
6
6
  boundFailureMessage,
@@ -10,32 +10,32 @@ import {
10
10
  parseMcpError,
11
11
  readCatalog,
12
12
  routerSkills
13
- } from "./chunk-EXDR4HVM.js";
13
+ } from "./chunk-7AZNPMQH.js";
14
14
  import {
15
15
  folderSkillsEffect
16
- } from "./chunk-PC5RHPUP.js";
16
+ } from "./chunk-TSLG2WPA.js";
17
17
  import {
18
18
  ResponseStatusError,
19
19
  authorDatabase,
20
20
  isApp,
21
21
  toEffectApp,
22
22
  unavailableStorage
23
- } from "./chunk-NXO2GN2T.js";
23
+ } from "./chunk-T2UFJKZR.js";
24
24
  import {
25
25
  parseDatabaseSchema
26
- } from "./chunk-LPN4ONWW.js";
26
+ } from "./chunk-XBQTJP76.js";
27
27
  import {
28
28
  declaredOperations,
29
29
  fromPromise,
30
30
  locate,
31
31
  nativeOperation,
32
32
  toPromise
33
- } from "./chunk-WPKXOTKM.js";
33
+ } from "./chunk-TX2XCAL6.js";
34
34
  import {
35
35
  accountProviderError,
36
36
  httpProviderError,
37
37
  parseProviderError
38
- } from "./chunk-DAIW2WM3.js";
38
+ } from "./chunk-KQCMHI3K.js";
39
39
  import {
40
40
  AccountCheckResult,
41
41
  DeclaredProvider,
@@ -82,29 +82,29 @@ import {
82
82
  defaultWebhookTransportLimits,
83
83
  maxInputProblems,
84
84
  workflowDurationMillis
85
- } from "./chunk-VGEPL4BV.js";
85
+ } from "./chunk-7R5JY5H7.js";
86
86
  import {
87
87
  CacheError
88
- } from "./chunk-T7WRQJUF.js";
88
+ } from "./chunk-BRGF7VFN.js";
89
89
  import {
90
90
  AppSkills,
91
91
  SkillFile,
92
92
  SkillLoadFailed
93
- } from "./chunk-TACLXEAE.js";
93
+ } from "./chunk-NSBRV4FJ.js";
94
94
  import {
95
95
  captureTelemetry,
96
96
  invocationFetch
97
- } from "./chunk-DUEZ2XCO.js";
97
+ } from "./chunk-YXKXKGN6.js";
98
98
  import {
99
99
  decoderOf,
100
100
  importedJsonSchema,
101
101
  jsonSchemaDecoder,
102
102
  jsonSchemaDocument
103
- } from "./chunk-IE6W5RNN.js";
103
+ } from "./chunk-YML53Z7H.js";
104
104
  import {
105
105
  JsonObject,
106
106
  JsonValue
107
- } from "./chunk-KKGRSXUK.js";
107
+ } from "./chunk-PWF2DRJ3.js";
108
108
  import {
109
109
  Cause_exports,
110
110
  Clock_exports,
@@ -116,7 +116,7 @@ import {
116
116
  SchemaIssue_exports,
117
117
  Schema_exports,
118
118
  Stream_exports
119
- } from "./chunk-DM5U7G7V.js";
119
+ } from "./chunk-NXTXZ635.js";
120
120
 
121
121
  // src/implementation/elicitation.ts
122
122
  var prepareElicitation = (input) => Effect_exports.gen(function* () {
@@ -805,7 +805,8 @@ function dispatch(app, request, context, signal) {
805
805
  declared,
806
806
  request.requirement,
807
807
  context,
808
- invocationSignal
808
+ invocationSignal,
809
+ deadline
809
810
  ).pipe(withinDeadline);
810
811
  let running;
811
812
  let transactionOpen = false;
@@ -1155,7 +1156,7 @@ function dispatch(app, request, context, signal) {
1155
1156
  })
1156
1157
  );
1157
1158
  }
1158
- function checkAccount(slots, declared, requirement, context, signal) {
1159
+ function checkAccount(slots, declared, requirement, context, signal, deadline) {
1159
1160
  return Effect_exports.gen(function* () {
1160
1161
  const selection = Object.hasOwn(slots, requirement) ? slots[requirement] : void 0;
1161
1162
  const slot = Object.hasOwn(declared.accounts, requirement) ? declared.accounts[requirement] : void 0;
@@ -1172,7 +1173,12 @@ function checkAccount(slots, declared, requirement, context, signal) {
1172
1173
  if (account === void 0 || !("id" in account)) return yield* new HostAccountsInvalid();
1173
1174
  const result = yield* Effect_exports.suspend(
1174
1175
  () => Effect_exports.gen(function* () {
1175
- return yield* health.run({ account, fetch: yield* invocationFetch(signal), signal });
1176
+ return yield* health.run({
1177
+ account,
1178
+ fetch: yield* invocationFetch(signal),
1179
+ signal,
1180
+ ...deadline === void 0 ? {} : { deadline }
1181
+ });
1176
1182
  })
1177
1183
  ).pipe(
1178
1184
  Effect_exports.catchCause((cause) => {
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  fixedRouter
3
- } from "./chunk-EXDR4HVM.js";
3
+ } from "./chunk-7AZNPMQH.js";
4
4
  import {
5
5
  nativeOperation,
6
6
  operationDeclaration,
7
7
  routerDeclaration
8
- } from "./chunk-WPKXOTKM.js";
8
+ } from "./chunk-TX2XCAL6.js";
9
9
 
10
10
  // src/implementation/protocol-operations.ts
11
11
  var protocolOperations = (operations, kinds = {}) => {
@@ -3,7 +3,7 @@ import {
3
3
  invalidate,
4
4
  layer,
5
5
  mutation
6
- } from "./chunk-XBG3M64K.js";
6
+ } from "./chunk-6JBTHTI5.js";
7
7
  import {
8
8
  Boolean,
9
9
  Cause,
@@ -158,7 +158,7 @@ import {
158
158
  void_2,
159
159
  whileLoop,
160
160
  zipRight
161
- } from "./chunk-DM5U7G7V.js";
161
+ } from "./chunk-NXTXZ635.js";
162
162
  import {
163
163
  __export
164
164
  } from "./chunk-CZ7CSFO4.js";
@@ -58,7 +58,7 @@ import {
58
58
  useSpan,
59
59
  void_2 as void_,
60
60
  withFiber
61
- } from "./chunk-DM5U7G7V.js";
61
+ } from "./chunk-NXTXZ635.js";
62
62
 
63
63
  // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/reactivity/Reactivity.js
64
64
  var TypeId = "~effect/reactivity/Reactivity";
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  skillFromFiles
3
- } from "./chunk-PC5RHPUP.js";
3
+ } from "./chunk-TSLG2WPA.js";
4
4
  import {
5
5
  joinPath,
6
6
  mergeMeta
7
- } from "./chunk-WPKXOTKM.js";
7
+ } from "./chunk-TX2XCAL6.js";
8
8
  import {
9
9
  isShortenedUpstream,
10
10
  parseProviderError,
11
11
  providerError
12
- } from "./chunk-DAIW2WM3.js";
12
+ } from "./chunk-KQCMHI3K.js";
13
13
  import {
14
14
  ApiErrorResponse,
15
15
  HostDeclarationInvalid,
@@ -17,11 +17,12 @@ import {
17
17
  HostedRouter,
18
18
  HostedTool,
19
19
  HostedToolSummary,
20
+ McpCredentialsUnverified,
20
21
  McpError
21
- } from "./chunk-VGEPL4BV.js";
22
+ } from "./chunk-7R5JY5H7.js";
22
23
  import {
23
24
  AppDatabaseError
24
- } from "./chunk-GH6PY5BQ.js";
25
+ } from "./chunk-M2KEEOIQ.js";
25
26
  import {
26
27
  CacheError,
27
28
  FailureCode,
@@ -30,32 +31,33 @@ import {
30
31
  maxFailureFields,
31
32
  maxFailureMessageLength,
32
33
  maxUpstreamMessageLength
33
- } from "./chunk-T7WRQJUF.js";
34
+ } from "./chunk-BRGF7VFN.js";
34
35
  import {
35
36
  SkillLoadFailed,
36
37
  skillFormatLimits
37
- } from "./chunk-TACLXEAE.js";
38
+ } from "./chunk-NSBRV4FJ.js";
38
39
  import {
39
40
  jsonSchemaDocument
40
- } from "./chunk-IE6W5RNN.js";
41
+ } from "./chunk-YML53Z7H.js";
41
42
  import {
42
43
  AppStorageError,
43
44
  AppStorageUnavailable
44
- } from "./chunk-HQKIPKM5.js";
45
+ } from "./chunk-BTJMXW4I.js";
45
46
  import {
46
47
  AccountId,
47
48
  HttpUrl,
48
49
  JsonObject
49
- } from "./chunk-KKGRSXUK.js";
50
+ } from "./chunk-PWF2DRJ3.js";
50
51
  import {
51
52
  Cause_exports,
52
53
  Effect_exports,
54
+ Match_exports,
53
55
  Option_exports,
54
56
  Predicate_exports,
55
57
  Redacted_exports,
56
58
  Result_exports,
57
59
  Schema_exports
58
- } from "./chunk-DM5U7G7V.js";
60
+ } from "./chunk-NXTXZ635.js";
59
61
 
60
62
  // src/contracts/openapi.ts
61
63
  var OpenapiErrorResponse = Schema_exports.Struct({
@@ -272,6 +274,32 @@ var cacheMessages = {
272
274
  storage: "The app cache failed to complete the operation.",
273
275
  timeout: "The app cache did not respond in time."
274
276
  };
277
+ var mcpStages = {
278
+ connect: "connecting",
279
+ transport: "connecting",
280
+ discover: "listing its tools",
281
+ schema: "reading a tool's schema",
282
+ call: "calling a tool"
283
+ };
284
+ var mcpMessage = ({ phase, reason, status }) => {
285
+ const stage = mcpStages[phase];
286
+ return Match_exports.value(reason).pipe(
287
+ Match_exports.when("timeout", () => `The MCP server did not respond in time while ${stage}.`),
288
+ Match_exports.when("unauthorized", () => `The MCP server rejected the credentials while ${stage}.`),
289
+ Match_exports.when(
290
+ "invalid_response",
291
+ () => `The MCP server returned a response Executor could not use while ${stage}, such as an unreadable message or an address on another origin.`
292
+ ),
293
+ Match_exports.when("invalid_input", () => "The MCP server URL or connection settings are invalid."),
294
+ // Only a transport failure has no answer from the server; a JSON-RPC error is an answer.
295
+ Match_exports.when(
296
+ "request",
297
+ () => status !== void 0 ? `The MCP server answered HTTP ${status} while ${stage}.` : phase === "transport" ? `Executor could not reach the MCP server while ${stage}.` : `The request to the MCP server failed while ${stage}.`
298
+ ),
299
+ Match_exports.exhaustive
300
+ );
301
+ };
302
+ var unverifiedMessage = ({ anonymous }) => anonymous === "answered" ? "This MCP server answers without credentials, so Executor can't check this account. A refused key will show up when a tool is called." : `The MCP server accepted the credentials, but the same check without them failed, so Executor can't tell whether it requires them. ${Schema_exports.is(McpError)(anonymous) ? mcpMessage(anonymous) : anonymous.status === void 0 ? "The MCP server could not answer the request." : `The MCP server answered HTTP ${anonymous.status}.`}`;
275
303
  var minimumSecretLength = 6;
276
304
  var secretValues = (value, found) => {
277
305
  if (typeof value === "string") {
@@ -388,6 +416,20 @@ var failureDetail = (error, secrets) => {
388
416
  code: error.reason,
389
417
  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."
390
418
  };
419
+ if (Schema_exports.is(McpError)(error))
420
+ return {
421
+ source: "service",
422
+ errorName: "McpError",
423
+ code: error.reason,
424
+ message: mcpMessage(error)
425
+ };
426
+ if (Schema_exports.is(McpCredentialsUnverified)(error))
427
+ return {
428
+ source: "service",
429
+ errorName: "McpCredentialsUnverified",
430
+ code: error.anonymous === "answered" ? "anonymous_access" : error.anonymous.reason,
431
+ message: unverifiedMessage(error)
432
+ };
391
433
  if (Schema_exports.is(OpenapiCompileError)(error))
392
434
  return {
393
435
  source: "app",
@@ -2,7 +2,7 @@ import {
2
2
  DatabaseFieldReserved,
3
3
  DatabaseLimitExceeded,
4
4
  DatabaseSchema
5
- } from "./chunk-GH6PY5BQ.js";
5
+ } from "./chunk-M2KEEOIQ.js";
6
6
  import {
7
7
  CacheCommand,
8
8
  CacheReply,
@@ -13,18 +13,18 @@ import {
13
13
  FailureSource,
14
14
  ProviderError,
15
15
  UpstreamError
16
- } from "./chunk-T7WRQJUF.js";
16
+ } from "./chunk-BRGF7VFN.js";
17
17
  import {
18
18
  AppSkillName,
19
19
  AppSkills,
20
20
  SkillLoadFailed
21
- } from "./chunk-TACLXEAE.js";
21
+ } from "./chunk-NSBRV4FJ.js";
22
22
  import {
23
23
  AccountId,
24
24
  HttpUrl,
25
25
  JsonObject as JsonObject2,
26
26
  JsonValue
27
- } from "./chunk-KKGRSXUK.js";
27
+ } from "./chunk-PWF2DRJ3.js";
28
28
  import {
29
29
  Any,
30
30
  ArraySchema,
@@ -78,7 +78,7 @@ import {
78
78
  transformOptional,
79
79
  withConstructorDefault,
80
80
  withDefault
81
- } from "./chunk-DM5U7G7V.js";
81
+ } from "./chunk-NXTXZ635.js";
82
82
 
83
83
  // src/contracts/router.ts
84
84
  var reservedRouterKeys = /* @__PURE__ */ new Set([
@@ -141,6 +141,12 @@ var McpToolsOptions = Schema_exports.Struct({
141
141
  )
142
142
  )
143
143
  });
144
+ var McpHealthInput = Schema_exports.Struct({
145
+ ...McpToolsOptions.fields,
146
+ headers: Schema_exports.Record(Schema_exports.String, Schema_exports.String),
147
+ deadline: Schema_exports.optional(Schema_exports.Finite)
148
+ });
149
+ var mcpHealthReserveMs = 2 * defaultMcpClientLimits.cleanupTimeoutMs + 250;
144
150
  var McpToolResult = Schema_exports.Struct({
145
151
  content: Schema_exports.Array(JsonObject2),
146
152
  structuredContent: Schema_exports.optionalKey(JsonObject2),
@@ -178,6 +184,11 @@ var McpError = class extends Schema_exports.TaggedError()("McpError", {
178
184
  upstream: Schema_exports.optional(UpstreamError)
179
185
  }) {
180
186
  };
187
+ var McpCredentialsUnverified = class extends Schema_exports.TaggedError()(
188
+ "McpCredentialsUnverified",
189
+ { anonymous: Schema_exports.Union([Schema_exports.Literal("answered"), McpError, ProviderError]) }
190
+ ) {
191
+ };
181
192
  var ProcessConfig = Schema_exports.Struct({
182
193
  command: Schema_exports.NonEmptyString,
183
194
  args: Schema_exports.Array(Schema_exports.String),
@@ -2945,10 +2956,13 @@ export {
2945
2956
  defaultMcpClientLimits,
2946
2957
  mcpSdkTimerCeilingMs,
2947
2958
  McpToolsOptions,
2959
+ McpHealthInput,
2960
+ mcpHealthReserveMs,
2948
2961
  McpToolResult,
2949
2962
  McpToolMetadata,
2950
2963
  McpServerHeader,
2951
2964
  McpError,
2965
+ McpCredentialsUnverified,
2952
2966
  ProcessConfig,
2953
2967
  maxApiErrorInstructionsLength,
2954
2968
  ApiErrorRecovery,
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  prepareElicitation
3
- } from "./chunk-BTRBOOTD.js";
3
+ } from "./chunk-3TEX4ZND.js";
4
4
  import {
5
5
  fromPromise
6
- } from "./chunk-WPKXOTKM.js";
6
+ } from "./chunk-TX2XCAL6.js";
7
7
  import {
8
8
  bodyUpstreamError
9
- } from "./chunk-DAIW2WM3.js";
9
+ } from "./chunk-KQCMHI3K.js";
10
10
  import {
11
11
  ElicitationFailed,
12
12
  McpError,
@@ -18,15 +18,15 @@ import {
18
18
  defaultElicitationLimits,
19
19
  defaultMcpClientLimits,
20
20
  mcpSdkTimerCeilingMs
21
- } from "./chunk-VGEPL4BV.js";
21
+ } from "./chunk-7R5JY5H7.js";
22
22
  import {
23
23
  jsonSchemaDecoder,
24
24
  nestJsonSchema,
25
25
  preparedJsonSchemaDecoder
26
- } from "./chunk-IE6W5RNN.js";
26
+ } from "./chunk-YML53Z7H.js";
27
27
  import {
28
28
  JsonObject
29
- } from "./chunk-KKGRSXUK.js";
29
+ } from "./chunk-PWF2DRJ3.js";
30
30
  import {
31
31
  Clock_exports,
32
32
  Deferred_exports,
@@ -35,7 +35,7 @@ import {
35
35
  Option_exports,
36
36
  Queue_exports,
37
37
  Schema_exports
38
- } from "./chunk-DM5U7G7V.js";
38
+ } from "./chunk-NXTXZ635.js";
39
39
 
40
40
  // src/implementation/mcp-tools.ts
41
41
  var resultFields = {
@@ -353,10 +353,26 @@ function mcpClient(withClient, timeoutMs, failure) {
353
353
  };
354
354
  })
355
355
  ).pipe(Effect_exports.withSpan("provider.mcp.discover"));
356
+ const check = withClient(
357
+ "discover",
358
+ (client) => Effect_exports.tryPromise({
359
+ try: (signal) => client.request({ method: "tools/list", params: {} }, ListToolsResultSchema, {
360
+ signal,
361
+ timeout: timeoutMs
362
+ }),
363
+ catch: (error) => failure("discover", error)
364
+ }).pipe(
365
+ Effect_exports.asVoid,
366
+ Effect_exports.withSpan("provider.mcp.request", {
367
+ kind: "client",
368
+ attributes: { "rpc.system.name": "jsonrpc", "rpc.method": "tools/list" }
369
+ })
370
+ )
371
+ ).pipe(Effect_exports.withSpan("provider.mcp.check"));
356
372
  const call = (name, input, context) => withClient("call", (client) => mcpCall(client, name, input, context, timeoutMs, failure)).pipe(
357
373
  Effect_exports.withSpan("provider.mcp.call", { attributes: { "mcp.tool.name": name } })
358
374
  );
359
- return { list, call };
375
+ return { list, check, call };
360
376
  }
361
377
 
362
378
  export {
@@ -211,7 +211,7 @@ import {
211
211
  withFiber,
212
212
  withParentSpan,
213
213
  zero2 as zero
214
- } from "./chunk-DM5U7G7V.js";
214
+ } from "./chunk-NXTXZ635.js";
215
215
  import {
216
216
  __export
217
217
  } from "./chunk-CZ7CSFO4.js";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  AccountId
3
- } from "./chunk-KKGRSXUK.js";
3
+ } from "./chunk-PWF2DRJ3.js";
4
4
  import {
5
5
  Schema_exports
6
- } from "./chunk-DM5U7G7V.js";
6
+ } from "./chunk-NXTXZ635.js";
7
7
 
8
8
  // src/contracts/failure.ts
9
9
  var maxFailureMessageLength = 2048;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Schema_exports
3
- } from "./chunk-DM5U7G7V.js";
3
+ } from "./chunk-NXTXZ635.js";
4
4
 
5
5
  // src/contracts/storage.ts
6
6
  var StorageName = Schema_exports.NonEmptyString.check(Schema_exports.isMaxLength(200));
@@ -3,40 +3,46 @@ import {
3
3
  answeredError,
4
4
  mcpClient,
5
5
  mcpJsonSchemaValidator
6
- } from "./chunk-4CMJD7AB.js";
6
+ } from "./chunk-AHI26TO6.js";
7
7
  import {
8
8
  accountProviderError,
9
9
  bodyUpstreamError,
10
10
  httpProviderError,
11
11
  providerErrorDetail
12
- } from "./chunk-DAIW2WM3.js";
12
+ } from "./chunk-KQCMHI3K.js";
13
13
  import {
14
+ McpCredentialsUnverified,
14
15
  McpError,
16
+ McpHealthInput,
15
17
  McpToolsOptions,
16
- defaultMcpClientLimits
17
- } from "./chunk-VGEPL4BV.js";
18
+ defaultMcpClientLimits,
19
+ mcpHealthReserveMs
20
+ } from "./chunk-7R5JY5H7.js";
18
21
  import {
19
22
  ProviderError
20
- } from "./chunk-T7WRQJUF.js";
23
+ } from "./chunk-BRGF7VFN.js";
21
24
  import {
22
25
  captureTelemetry
23
- } from "./chunk-DUEZ2XCO.js";
26
+ } from "./chunk-YXKXKGN6.js";
24
27
  import {
25
28
  FetchHttpClient_exports
26
- } from "./chunk-KNJAOYV4.js";
29
+ } from "./chunk-V2I3MMPM.js";
27
30
  import {
28
31
  HttpClientRequest_exports,
29
32
  HttpClient_exports
30
- } from "./chunk-OBXHLFGQ.js";
33
+ } from "./chunk-B5YJQU45.js";
31
34
  import {
35
+ Clock_exports,
32
36
  Deferred_exports,
33
37
  Effect_exports,
38
+ Match_exports,
34
39
  Option_exports,
40
+ Predicate_exports,
35
41
  Redacted_exports,
36
42
  Ref_exports,
37
43
  Schema_exports,
38
44
  Stream_exports
39
- } from "./chunk-DM5U7G7V.js";
45
+ } from "./chunk-NXTXZ635.js";
40
46
 
41
47
  // src/implementation/mcp.ts
42
48
  import { UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js";
@@ -51,16 +57,16 @@ import {
51
57
  StreamableHTTPClientTransport,
52
58
  StreamableHTTPError
53
59
  } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
60
+ var unreadable = (error) => error instanceof SyntaxError || error instanceof Error && Predicate_exports.hasProperty(error, "issues") && Array.isArray(error.issues);
54
61
  var failure = (phase, error) => {
55
62
  if (Schema_exports.is(ProviderError)(error) || Schema_exports.is(McpError)(error)) return error;
56
- const status = error instanceof UnauthorizedError ? 401 : error instanceof StreamableHTTPError || error instanceof SseError ? error.code : void 0;
57
- const provider = status === void 0 ? void 0 : httpProviderError(status);
58
- if (provider !== void 0) return provider;
63
+ const code = error instanceof UnauthorizedError ? 401 : error instanceof StreamableHTTPError || error instanceof SseError ? error.code : void 0;
64
+ if (code !== void 0 && code >= 300 && code <= 599)
65
+ return httpProviderError(code) ?? new McpError({ phase, reason: "request", status: code });
59
66
  const upstream = answeredError(error);
60
67
  return new McpError({
61
68
  phase,
62
- reason: error instanceof ProtocolError && error.code === ErrorCode.RequestTimeout ? "timeout" : "request",
63
- ...status === void 0 ? {} : { status },
69
+ reason: code !== void 0 || unreadable(error) ? "invalid_response" : error instanceof ProtocolError && error.code === ErrorCode.RequestTimeout ? "timeout" : "request",
64
70
  ...upstream === void 0 ? {} : { upstream }
65
71
  });
66
72
  };
@@ -72,10 +78,10 @@ var errorBody = (response) => Effect_exports.gen(function* () {
72
78
  const length = response.headers["content-length"];
73
79
  if (!json || length !== void 0 && Number(length) > errorBodyLimits.maxBytes)
74
80
  return { body: Stream_exports.toReadableStream(response.stream), upstream: void 0 };
75
- const unreadable = new McpError({ phase: "transport", reason: "invalid_response" });
81
+ const unreadable2 = new McpError({ phase: "transport", reason: "invalid_response" });
76
82
  const read = yield* response.stream.pipe(
77
- Stream_exports.mapError(() => unreadable),
78
- Stream_exports.limitBytes(errorBodyLimits.maxBytes, () => Stream_exports.fail(unreadable)),
83
+ Stream_exports.mapError(() => unreadable2),
84
+ Stream_exports.limitBytes(errorBodyLimits.maxBytes, () => Stream_exports.fail(unreadable2)),
79
85
  Stream_exports.decodeText,
80
86
  Stream_exports.mkString,
81
87
  Effect_exports.timeout(errorBodyLimits.readTimeoutMs),
@@ -98,11 +104,14 @@ var transportFetch = (connection, telemetry, rejected, answered) => (url, init)
98
104
  return yield* new McpError({ phase: "transport", reason: "invalid_input" });
99
105
  if (target.origin !== connection.url.origin || target.username || target.password)
100
106
  return yield* new McpError({ phase: "transport", reason: "invalid_response" });
101
- const headers = new Headers(Redacted_exports.value(connection.headers));
102
- new Headers(init?.headers).forEach((value, name) => headers.set(name, value));
103
107
  const request = yield* Effect_exports.try({
104
- try: () => HttpClientRequest_exports.fromWeb(new Request(target, { ...init, headers })),
105
- catch: () => failure("transport", void 0)
108
+ try: () => {
109
+ const headers = new Headers(Redacted_exports.value(connection.headers));
110
+ new Headers(init?.headers).forEach((value, name) => headers.set(name, value));
111
+ return HttpClientRequest_exports.fromWeb(new Request(target, { ...init, headers }));
112
+ },
113
+ // The provider's headers cannot form an HTTP request, such as a name with a space.
114
+ catch: () => new McpError({ phase: "transport", reason: "invalid_input" })
106
115
  });
107
116
  const client = yield* HttpClient_exports.HttpClient;
108
117
  const response = yield* client.execute(request);
@@ -271,9 +280,43 @@ var mcpClientEffect = (input, changed) => Effect_exports.gen(function* () {
271
280
  failure
272
281
  );
273
282
  });
283
+ var refusesCredentials = (error) => Schema_exports.is(ProviderError)(error) && Match_exports.value(error.reason).pipe(
284
+ Match_exports.whenOr("unauthorized", "forbidden", "rejected", () => true),
285
+ Match_exports.whenOr("rate_limited", "unavailable", () => false),
286
+ Match_exports.exhaustive
287
+ );
288
+ var mcpHealthEffect = (check, options) => Effect_exports.gen(function* () {
289
+ const { deadline, timeoutMs, ...parsed } = yield* Schema_exports.decodeUnknownEffect(McpHealthInput)({
290
+ ...options,
291
+ accountId: check.account.id,
292
+ signal: check.signal,
293
+ deadline: check.deadline
294
+ }).pipe(Effect_exports.mapError(() => new McpError({ phase: "connect", reason: "invalid_input" })));
295
+ const end = Math.min(
296
+ (yield* Clock_exports.currentTimeMillis) + (timeoutMs ?? defaultMcpClientLimits.timeoutMs),
297
+ deadline === void 0 ? Number.POSITIVE_INFINITY : deadline - mcpHealthReserveMs
298
+ );
299
+ const remaining = Effect_exports.flatMap(
300
+ Clock_exports.currentTimeMillis,
301
+ (now) => end - now >= 1 ? Effect_exports.succeed(Math.floor(end - now)) : Effect_exports.fail(new McpError({ phase: "transport", reason: "timeout" }))
302
+ );
303
+ yield* (yield* mcpClientEffect({ ...parsed, timeoutMs: yield* remaining })).check;
304
+ return yield* remaining.pipe(
305
+ Effect_exports.flatMap(
306
+ (timeoutMs2) => mcpClientEffect({ url: parsed.url, signal: parsed.signal, timeoutMs: timeoutMs2 })
307
+ ),
308
+ Effect_exports.flatMap((anonymous) => anonymous.check),
309
+ Effect_exports.matchEffect({
310
+ onSuccess: () => Effect_exports.fail(new McpCredentialsUnverified({ anonymous: "answered" })),
311
+ onFailure: (error) => refusesCredentials(error) ? Effect_exports.void : Effect_exports.fail(new McpCredentialsUnverified({ anonymous: error }))
312
+ }),
313
+ Effect_exports.withSpan("provider.mcp.anonymous")
314
+ );
315
+ }).pipe(Effect_exports.withSpan("provider.mcp.health"));
274
316
  var mcpToolsEffect = (input) => mcpClientEffect(input).pipe(Effect_exports.flatMap(adaptMcpTools));
275
317
 
276
318
  export {
277
319
  mcpClientEffect,
320
+ mcpHealthEffect,
278
321
  mcpToolsEffect
279
322
  };
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  ProviderError,
3
3
  maxUpstreamMessageLength
4
- } from "./chunk-T7WRQJUF.js";
4
+ } from "./chunk-BRGF7VFN.js";
5
5
  import {
6
6
  AccountId
7
- } from "./chunk-KKGRSXUK.js";
7
+ } from "./chunk-PWF2DRJ3.js";
8
8
  import {
9
9
  Option_exports,
10
10
  Schema_exports
11
- } from "./chunk-DM5U7G7V.js";
11
+ } from "./chunk-NXTXZ635.js";
12
12
 
13
13
  // src/implementation/upstream-error.ts
14
14
  var ErrorToken = Schema_exports.String.check(Schema_exports.isPattern(/^[A-Za-z0-9._-]{1,128}$/));
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Schema_exports
3
- } from "./chunk-DM5U7G7V.js";
3
+ } from "./chunk-NXTXZ635.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-DM5U7G7V.js";
3
+ } from "./chunk-NXTXZ635.js";
4
4
 
5
5
  // src/contracts/skills.ts
6
6
  var SkillFilePath = Schema_exports.NonEmptyString.check(