apps 0.0.1-beta.3 → 0.0.1-beta.30
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.
- package/README.md +68 -44
- package/framework-reference.json +1 -1
- package/js/{chunk-G7ZIRKMK.js → chunk-2D2PKLGQ.js} +118 -197
- package/js/chunk-3SPRHIEE.js +42 -0
- package/js/{chunk-FDNTX5QJ.js → chunk-4N26L465.js} +2 -2
- package/js/chunk-5ZHHO4OM.js +92 -0
- package/js/{chunk-EVJUVWN2.js → chunk-65SZ23BK.js} +2 -2
- package/js/{chunk-M6ZRRIBI.js → chunk-6JBTHTI5.js} +1 -1
- package/js/{chunk-J7O55ZV7.js → chunk-6NK26ONC.js} +332 -187
- package/js/chunk-6VWYEQ4X.js +254 -0
- package/js/{chunk-RN2MXB4R.js → chunk-AE4FWJQU.js} +128 -24
- package/js/{chunk-HDJH3RPR.js → chunk-BBTELEAN.js} +2 -2
- package/js/{chunk-LGIYBDWA.js → chunk-BRGF7VFN.js} +65 -1
- package/js/{chunk-MYYEW3RA.js → chunk-BSRU52RU.js} +984 -61
- package/js/{chunk-FZJOYIZO.js → chunk-BTJMXW4I.js} +1 -1
- package/js/{chunk-HDTGZWP2.js → chunk-IMCEF6KE.js} +139 -32
- package/js/chunk-KQCMHI3K.js +118 -0
- package/js/{chunk-BMOIAIVR.js → chunk-M2KEEOIQ.js} +49 -1
- package/js/{chunk-YEJOQEII.js → chunk-MYCVMDWI.js} +45 -7
- package/js/{chunk-FW5HBOIK.js → chunk-NXTXZ635.js} +1841 -1701
- package/js/chunk-OD3KFKZD.js +1617 -0
- package/js/{chunk-JN55AYQH.js → chunk-OI5CKSBU.js} +61 -32
- package/js/{chunk-NQ3OMCA5.js → chunk-P46HIAX6.js} +2 -2
- package/js/chunk-PUC24GZP.js +801 -0
- package/js/{chunk-SATWJKN6.js → chunk-PWF2DRJ3.js} +1 -1
- package/js/{chunk-D47C7KG5.js → chunk-VUVBMNKC.js} +2 -2
- package/js/{chunk-ZCAMUXSG.js → chunk-WGBI5MVX.js} +3 -4
- package/js/{chunk-T2LAZCAD.js → chunk-WQ5MVBTP.js} +1 -1
- package/js/{chunk-PLCMJREA.js → chunk-XBQTJP76.js} +60 -20
- package/js/{chunk-QKHR7BMF.js → chunk-XGN5IFOZ.js} +3 -3
- package/js/{chunk-WFSQXYUT.js → chunk-YML53Z7H.js} +42 -5
- package/js/{chunk-5MQZEB6Y.js → chunk-ZZOCEUTB.js} +37 -12
- package/js/client.js +120 -84
- package/js/contracts.js +110 -16
- package/js/effect.js +20 -20
- package/js/{es-APDZKREY.js → es-DIULA3ZF.js} +62 -1659
- package/js/graphql.js +58 -54
- package/js/host.js +20 -20
- package/js/index.js +247 -204
- package/js/mcp/effect.js +24 -22
- package/js/mcp/stdio.js +35 -30
- package/js/mcp.js +105 -68
- package/js/openapi.js +4087 -1503
- package/js/react.js +3 -3
- package/js/skills/effect.js +5 -3
- package/js/skills.js +15 -15
- package/js/storage/facet.js +4 -4
- package/js/ui/auth/contracts.js +2 -2
- package/js/ui/auth.js +5 -5
- package/js/ui/contracts.js +5 -4
- package/js/ui/serving.js +8516 -214
- package/package.json +1 -1
- package/runtime.json +1 -1
- package/types/app-data/src/contracts/database.d.ts +33 -6
- package/types/app-data/src/implementation/schema.d.ts +2 -17
- package/types/apps/src/contracts/api-response-error.d.ts +4 -0
- package/types/apps/src/contracts/app.d.ts +7 -6
- package/types/apps/src/contracts/failure.d.ts +54 -0
- package/types/apps/src/contracts/graphql.d.ts +2 -1
- package/types/apps/src/contracts/host.d.ts +34 -11
- package/types/apps/src/contracts/mcp.d.ts +91 -10
- package/types/apps/src/contracts/network.d.ts +84 -0
- package/types/apps/src/contracts/openapi-compile.d.ts +31 -3
- package/types/apps/src/contracts/openapi.d.ts +45 -9
- package/types/apps/src/contracts/operations.d.ts +5 -6
- package/types/apps/src/contracts/protocol-version.d.ts +2 -2
- package/types/apps/src/contracts/protocols/1.d.ts +251 -69
- package/types/apps/src/contracts/protocols/2.d.ts +710 -0
- package/types/apps/src/contracts/protocols/3.d.ts +716 -0
- package/types/apps/src/contracts/protocols/4.d.ts +1298 -0
- package/types/apps/src/contracts/protocols/5.d.ts +1174 -0
- package/types/apps/src/contracts/protocols/6.d.ts +1620 -0
- package/types/apps/src/contracts/protocols/7.d.ts +1784 -0
- package/types/apps/src/contracts/protocols/8.d.ts +1119 -0
- package/types/apps/src/contracts/protocols/oauth.d.ts +89 -0
- package/types/apps/src/contracts/provider-error.d.ts +9 -0
- package/types/apps/src/contracts/provider.d.ts +115 -10
- package/types/apps/src/contracts/router.d.ts +59 -0
- package/types/apps/src/contracts/skills.d.ts +18 -5
- package/types/apps/src/contracts/storage.d.ts +3 -3
- package/types/apps/src/contracts/ui.d.ts +18 -0
- package/types/apps/src/contracts/workflows.d.ts +34 -3
- package/types/apps/src/graphql.d.ts +1 -3
- package/types/apps/src/implementation/account-router.d.ts +12 -0
- package/types/apps/src/implementation/app.d.ts +5 -4
- package/types/apps/src/implementation/browser-scripts.gen.d.ts +6 -0
- package/types/apps/src/implementation/catalog-cache.d.ts +34 -4
- package/types/apps/src/implementation/elicitation.d.ts +9 -9
- package/types/apps/src/implementation/failure-detail.d.ts +46 -0
- package/types/apps/src/implementation/graphql-catalog.d.ts +4 -7
- package/types/apps/src/implementation/graphql.d.ts +4 -3
- package/types/apps/src/implementation/mcp-call.d.ts +6 -5
- package/types/apps/src/implementation/mcp-catalog.d.ts +7 -8
- package/types/apps/src/implementation/mcp-client.d.ts +49 -25
- package/types/apps/src/implementation/mcp-stdio.d.ts +1 -1
- package/types/apps/src/implementation/mcp-tools.d.ts +2 -1
- package/types/apps/src/implementation/mcp.d.ts +52 -25
- package/types/apps/src/implementation/network.d.ts +16 -0
- package/types/apps/src/implementation/openapi-compile.d.ts +27 -6
- package/types/apps/src/implementation/openapi-document.d.ts +35 -8
- package/types/apps/src/implementation/openapi-names.d.ts +9 -4
- package/types/apps/src/implementation/openapi-request.d.ts +10 -2
- package/types/apps/src/implementation/openapi-source.d.ts +8 -6
- package/types/apps/src/implementation/openapi-upgrade.d.ts +4 -0
- package/types/apps/src/implementation/operations.d.ts +36 -3
- package/types/apps/src/implementation/protocol-operations.d.ts +6 -4
- package/types/apps/src/implementation/provider-error.d.ts +28 -1
- package/types/apps/src/implementation/provider.d.ts +19 -5
- package/types/apps/src/implementation/router-catalog.d.ts +224 -0
- package/types/apps/src/implementation/router.d.ts +68 -0
- package/types/apps/src/implementation/runtime-yield.d.ts +7 -0
- package/types/apps/src/implementation/schema.d.ts +52 -1
- package/types/apps/src/implementation/skills.d.ts +2 -2
- package/types/apps/src/implementation/storage.d.ts +5 -3
- package/types/apps/src/implementation/ui-account-notice.d.ts +9 -0
- package/types/apps/src/implementation/ui-client.d.ts +2 -2
- package/types/apps/src/implementation/ui-document.d.ts +5 -0
- package/types/apps/src/implementation/ui-errors.d.ts +1 -1
- package/types/apps/src/implementation/ui-serving.d.ts +10 -4
- package/types/apps/src/implementation/ui-watch.d.ts +1 -1
- package/types/apps/src/implementation/upstream-error.d.ts +7 -0
- package/types/apps/src/implementation/webhooks.d.ts +1 -1
- package/types/apps/src/implementation/workflow-context.d.ts +11 -3
- package/types/apps/src/index.d.ts +29 -11
- package/types/apps/src/mcp-stdio.d.ts +2 -5
- package/types/apps/src/mcp.d.ts +25 -5
- package/types/apps/src/openapi.d.ts +6 -6
- package/types/apps/src/skills.d.ts +4 -4
- package/types/telemetry/src/browser-operations.d.ts +5 -2
- package/types/telemetry/src/config.d.ts +2 -2
- package/types/utils/src/api-error.d.ts +48 -0
- package/js/chunk-PYUYJRSK.js +0 -93
- package/js/chunk-SWPD52J7.js +0 -35
- package/js/chunk-W7D7WVSY.js +0 -18
- package/js/chunk-Z5NMEGJN.js +0 -29
- package/js/chunk-ZJWDMTE3.js +0 -63
- package/types/apps/src/contracts/dynamic-tools.d.ts +0 -13
- package/types/apps/src/implementation/account-operations.d.ts +0 -151
- package/types/apps/src/implementation/dynamic-tools.d.ts +0 -8
|
@@ -1,37 +1,52 @@
|
|
|
1
1
|
import {
|
|
2
2
|
adaptMcpTools,
|
|
3
|
+
answeredError,
|
|
3
4
|
mcpClient,
|
|
4
5
|
mcpJsonSchemaValidator
|
|
5
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-AE4FWJQU.js";
|
|
7
|
+
import {
|
|
8
|
+
failOnNetworkRefusal
|
|
9
|
+
} from "./chunk-PUC24GZP.js";
|
|
6
10
|
import {
|
|
7
11
|
accountProviderError,
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
bodyUpstreamError,
|
|
13
|
+
httpProviderError,
|
|
14
|
+
providerErrorDetail
|
|
15
|
+
} from "./chunk-KQCMHI3K.js";
|
|
10
16
|
import {
|
|
17
|
+
McpCredentialsUnverified,
|
|
11
18
|
McpError,
|
|
19
|
+
McpHealthInput,
|
|
12
20
|
McpToolsOptions,
|
|
13
|
-
|
|
14
|
-
|
|
21
|
+
NetworkRefused,
|
|
22
|
+
defaultMcpClientLimits,
|
|
23
|
+
mcpHealthReserveMs
|
|
24
|
+
} from "./chunk-BSRU52RU.js";
|
|
15
25
|
import {
|
|
16
26
|
ProviderError
|
|
17
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-BRGF7VFN.js";
|
|
18
28
|
import {
|
|
19
29
|
captureTelemetry
|
|
20
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-WGBI5MVX.js";
|
|
21
31
|
import {
|
|
22
32
|
FetchHttpClient_exports
|
|
23
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-BBTELEAN.js";
|
|
24
34
|
import {
|
|
25
35
|
HttpClientRequest_exports,
|
|
26
36
|
HttpClient_exports
|
|
27
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-XGN5IFOZ.js";
|
|
28
38
|
import {
|
|
39
|
+
Clock_exports,
|
|
29
40
|
Deferred_exports,
|
|
30
41
|
Effect_exports,
|
|
42
|
+
Match_exports,
|
|
43
|
+
Option_exports,
|
|
44
|
+
Predicate_exports,
|
|
31
45
|
Redacted_exports,
|
|
46
|
+
Ref_exports,
|
|
32
47
|
Schema_exports,
|
|
33
48
|
Stream_exports
|
|
34
|
-
} from "./chunk-
|
|
49
|
+
} from "./chunk-NXTXZ635.js";
|
|
35
50
|
|
|
36
51
|
// src/implementation/mcp.ts
|
|
37
52
|
import { UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
@@ -46,18 +61,45 @@ import {
|
|
|
46
61
|
StreamableHTTPClientTransport,
|
|
47
62
|
StreamableHTTPError
|
|
48
63
|
} from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
64
|
+
var unreadable = (error) => error instanceof SyntaxError || error instanceof Error && Predicate_exports.hasProperty(error, "issues") && Array.isArray(error.issues);
|
|
49
65
|
var failure = (phase, error) => {
|
|
50
|
-
if (Schema_exports.is(ProviderError)(error) || Schema_exports.is(McpError)(error)
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
66
|
+
if (Schema_exports.is(ProviderError)(error) || Schema_exports.is(McpError)(error) || Schema_exports.is(NetworkRefused)(error))
|
|
67
|
+
return error;
|
|
68
|
+
const code = error instanceof UnauthorizedError ? 401 : error instanceof StreamableHTTPError || error instanceof SseError ? error.code : void 0;
|
|
69
|
+
if (code !== void 0 && code >= 300 && code <= 599)
|
|
70
|
+
return httpProviderError(code) ?? new McpError({ phase, reason: "request", status: code });
|
|
71
|
+
const upstream = answeredError(error);
|
|
54
72
|
return new McpError({
|
|
55
73
|
phase,
|
|
56
|
-
reason: error instanceof ProtocolError && error.code === ErrorCode.RequestTimeout ? "timeout" : "request",
|
|
57
|
-
...
|
|
74
|
+
reason: code !== void 0 || unreadable(error) ? "invalid_response" : error instanceof ProtocolError && error.code === ErrorCode.RequestTimeout ? "timeout" : "request",
|
|
75
|
+
...upstream === void 0 ? {} : { upstream }
|
|
58
76
|
});
|
|
59
77
|
};
|
|
60
|
-
var
|
|
78
|
+
var errorBodyLimits = { maxBytes: 65536, readTimeoutMs: 2e3 };
|
|
79
|
+
var errorBody = (response) => Effect_exports.gen(function* () {
|
|
80
|
+
const json = /^application\/(?:[\w.-]+\+)?json$/i.test(
|
|
81
|
+
response.headers["content-type"]?.split(";")[0]?.trim() ?? ""
|
|
82
|
+
);
|
|
83
|
+
const length = response.headers["content-length"];
|
|
84
|
+
if (!json || length !== void 0 && Number(length) > errorBodyLimits.maxBytes)
|
|
85
|
+
return { body: Stream_exports.toReadableStream(response.stream), upstream: void 0 };
|
|
86
|
+
const unreadable2 = new McpError({ phase: "transport", reason: "invalid_response" });
|
|
87
|
+
const read = yield* response.stream.pipe(
|
|
88
|
+
Stream_exports.mapError(() => unreadable2),
|
|
89
|
+
Stream_exports.limitBytes(errorBodyLimits.maxBytes, () => Stream_exports.fail(unreadable2)),
|
|
90
|
+
Stream_exports.decodeText,
|
|
91
|
+
Stream_exports.mkString,
|
|
92
|
+
Effect_exports.timeout(errorBodyLimits.readTimeoutMs),
|
|
93
|
+
Effect_exports.option
|
|
94
|
+
);
|
|
95
|
+
if (Option_exports.isNone(read)) return { body: null, upstream: void 0 };
|
|
96
|
+
const parsed = Schema_exports.decodeUnknownOption(Schema_exports.fromJsonString(Schema_exports.Json))(read.value);
|
|
97
|
+
return {
|
|
98
|
+
body: read.value,
|
|
99
|
+
upstream: Option_exports.isSome(parsed) ? bodyUpstreamError(parsed.value) : void 0
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
var transportFetch = (connection, telemetry, rejected, answered) => (url, init) => Effect_exports.runPromiseWith(telemetry.context)(
|
|
61
103
|
Effect_exports.gen(function* () {
|
|
62
104
|
const target = yield* Effect_exports.try({
|
|
63
105
|
try: () => new URL(url),
|
|
@@ -67,26 +109,37 @@ var transportFetch = (connection, telemetry, rejected) => (url, init) => Effect_
|
|
|
67
109
|
return yield* new McpError({ phase: "transport", reason: "invalid_input" });
|
|
68
110
|
if (target.origin !== connection.url.origin || target.username || target.password)
|
|
69
111
|
return yield* new McpError({ phase: "transport", reason: "invalid_response" });
|
|
70
|
-
const headers = new Headers(Redacted_exports.value(connection.headers));
|
|
71
|
-
new Headers(init?.headers).forEach((value, name) => headers.set(name, value));
|
|
72
112
|
const request = yield* Effect_exports.try({
|
|
73
|
-
try: () =>
|
|
74
|
-
|
|
113
|
+
try: () => {
|
|
114
|
+
const headers = new Headers(Redacted_exports.value(connection.headers));
|
|
115
|
+
new Headers(init?.headers).forEach((value, name) => headers.set(name, value));
|
|
116
|
+
return HttpClientRequest_exports.fromWeb(new Request(target, { ...init, headers }));
|
|
117
|
+
},
|
|
118
|
+
// The provider's headers cannot form an HTTP request, such as a name with a space.
|
|
119
|
+
catch: () => new McpError({ phase: "transport", reason: "invalid_input" })
|
|
75
120
|
});
|
|
76
121
|
const client = yield* HttpClient_exports.HttpClient;
|
|
77
122
|
const response = yield* client.execute(request);
|
|
123
|
+
yield* failOnNetworkRefusal(response).pipe(
|
|
124
|
+
Effect_exports.tapError((refused) => Deferred_exports.fail(rejected, refused))
|
|
125
|
+
);
|
|
126
|
+
if (response.status < 400)
|
|
127
|
+
return new Response(
|
|
128
|
+
[204, 205, 304].includes(response.status) ? null : Stream_exports.toReadableStream(response.stream),
|
|
129
|
+
{
|
|
130
|
+
status: response.status,
|
|
131
|
+
headers: response.headers
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
const { body, upstream } = yield* errorBody(response);
|
|
78
135
|
const provider = httpProviderError(response.status, response.headers);
|
|
79
136
|
if (provider !== void 0) {
|
|
80
|
-
|
|
81
|
-
|
|
137
|
+
const refused = providerErrorDetail(provider, { upstream });
|
|
138
|
+
yield* Deferred_exports.fail(rejected, refused);
|
|
139
|
+
return yield* refused;
|
|
82
140
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
{
|
|
86
|
-
status: response.status,
|
|
87
|
-
headers: response.headers
|
|
88
|
-
}
|
|
89
|
-
);
|
|
141
|
+
yield* Ref_exports.set(answered, { status: response.status, upstream });
|
|
142
|
+
return new Response(body, { status: response.status, headers: response.headers });
|
|
90
143
|
}).pipe(
|
|
91
144
|
Effect_exports.provide(FetchHttpClient_exports.layer),
|
|
92
145
|
Effect_exports.provideService(FetchHttpClient_exports.RequestInit, { redirect: "manual" }),
|
|
@@ -104,15 +157,30 @@ var transportFetch = (connection, telemetry, rejected) => (url, init) => Effect_
|
|
|
104
157
|
),
|
|
105
158
|
init?.signal ? { signal: init.signal } : {}
|
|
106
159
|
);
|
|
160
|
+
var explain = (error, phase, response) => {
|
|
161
|
+
if (Schema_exports.is(ProviderError)(error)) return providerErrorDetail(error, { phase });
|
|
162
|
+
if (!Schema_exports.is(McpError)(error) || error.upstream !== void 0 || error.status === void 0 || response?.status !== error.status || response.upstream === void 0)
|
|
163
|
+
return error;
|
|
164
|
+
return new McpError({
|
|
165
|
+
phase: error.phase,
|
|
166
|
+
reason: error.reason,
|
|
167
|
+
status: error.status,
|
|
168
|
+
upstream: response.upstream
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
var explained = (phase, answered) => (error) => Ref_exports.get(answered).pipe(
|
|
172
|
+
Effect_exports.flatMap((response) => Effect_exports.fail(explain(error, phase, response)))
|
|
173
|
+
);
|
|
107
174
|
function withClient(connection, mode, use, changed) {
|
|
108
175
|
const attempt = (kind) => Effect_exports.scoped(
|
|
109
176
|
Effect_exports.gen(function* () {
|
|
110
177
|
const telemetry = yield* captureTelemetry;
|
|
111
178
|
const rejected = yield* Deferred_exports.make();
|
|
179
|
+
const answered = yield* Ref_exports.make(void 0);
|
|
112
180
|
const pending = /* @__PURE__ */ new Set();
|
|
113
181
|
const { client, transport } = yield* Effect_exports.acquireRelease(
|
|
114
182
|
Effect_exports.sync(() => {
|
|
115
|
-
const fetch = transportFetch(connection, telemetry, rejected);
|
|
183
|
+
const fetch = transportFetch(connection, telemetry, rejected, answered);
|
|
116
184
|
const client2 = new Client(
|
|
117
185
|
{ name: "executor-apps", version: "0.1.0" },
|
|
118
186
|
{
|
|
@@ -168,10 +236,14 @@ function withClient(connection, mode, use, changed) {
|
|
|
168
236
|
catch: (error) => failure("connect", error)
|
|
169
237
|
}).pipe(
|
|
170
238
|
Effect_exports.raceFirst(Deferred_exports.await(rejected)),
|
|
239
|
+
Effect_exports.catch(explained("connect", answered)),
|
|
171
240
|
Effect_exports.timeout(connection.timeoutMs),
|
|
172
241
|
Effect_exports.withSpan("provider.mcp.connect")
|
|
173
242
|
);
|
|
174
|
-
return yield* use(client).pipe(
|
|
243
|
+
return yield* use(client).pipe(
|
|
244
|
+
Effect_exports.raceFirst(Deferred_exports.await(rejected)),
|
|
245
|
+
Effect_exports.catch(explained(mode, answered))
|
|
246
|
+
);
|
|
175
247
|
})
|
|
176
248
|
).pipe(
|
|
177
249
|
Effect_exports.withSpan("provider.mcp.session", {
|
|
@@ -216,9 +288,44 @@ var mcpClientEffect = (input, changed) => Effect_exports.gen(function* () {
|
|
|
216
288
|
failure
|
|
217
289
|
);
|
|
218
290
|
});
|
|
291
|
+
var refusesCredentials = (error) => Schema_exports.is(ProviderError)(error) && Match_exports.value(error.reason).pipe(
|
|
292
|
+
Match_exports.whenOr("unauthorized", "forbidden", "rejected", () => true),
|
|
293
|
+
Match_exports.whenOr("rate_limited", "unavailable", () => false),
|
|
294
|
+
Match_exports.exhaustive
|
|
295
|
+
);
|
|
296
|
+
var mcpHealthEffect = (check, options) => Effect_exports.gen(function* () {
|
|
297
|
+
const { deadline, timeoutMs, ...parsed } = yield* Schema_exports.decodeUnknownEffect(McpHealthInput)({
|
|
298
|
+
...options,
|
|
299
|
+
accountId: check.account.id,
|
|
300
|
+
signal: check.signal,
|
|
301
|
+
deadline: check.deadline
|
|
302
|
+
}).pipe(Effect_exports.mapError(() => new McpError({ phase: "connect", reason: "invalid_input" })));
|
|
303
|
+
const end = Math.min(
|
|
304
|
+
(yield* Clock_exports.currentTimeMillis) + (timeoutMs ?? defaultMcpClientLimits.timeoutMs),
|
|
305
|
+
deadline === void 0 ? Number.POSITIVE_INFINITY : deadline - mcpHealthReserveMs
|
|
306
|
+
);
|
|
307
|
+
const remaining = Effect_exports.flatMap(
|
|
308
|
+
Clock_exports.currentTimeMillis,
|
|
309
|
+
(now) => end - now >= 1 ? Effect_exports.succeed(Math.floor(end - now)) : Effect_exports.fail(new McpError({ phase: "transport", reason: "timeout" }))
|
|
310
|
+
);
|
|
311
|
+
yield* (yield* mcpClientEffect({ ...parsed, timeoutMs: yield* remaining })).check;
|
|
312
|
+
return yield* remaining.pipe(
|
|
313
|
+
Effect_exports.flatMap(
|
|
314
|
+
(timeoutMs2) => mcpClientEffect({ url: parsed.url, signal: parsed.signal, timeoutMs: timeoutMs2 })
|
|
315
|
+
),
|
|
316
|
+
Effect_exports.flatMap((anonymous) => anonymous.check),
|
|
317
|
+
Effect_exports.matchEffect({
|
|
318
|
+
onSuccess: () => Effect_exports.fail(new McpCredentialsUnverified({ anonymous: "answered" })),
|
|
319
|
+
// Executor's network refused the attempt, so the server never answered it.
|
|
320
|
+
onFailure: (error) => Schema_exports.is(NetworkRefused)(error) ? Effect_exports.fail(error) : refusesCredentials(error) ? Effect_exports.void : Effect_exports.fail(new McpCredentialsUnverified({ anonymous: error }))
|
|
321
|
+
}),
|
|
322
|
+
Effect_exports.withSpan("provider.mcp.anonymous")
|
|
323
|
+
);
|
|
324
|
+
}).pipe(Effect_exports.withSpan("provider.mcp.health"));
|
|
219
325
|
var mcpToolsEffect = (input) => mcpClientEffect(input).pipe(Effect_exports.flatMap(adaptMcpTools));
|
|
220
326
|
|
|
221
327
|
export {
|
|
222
328
|
mcpClientEffect,
|
|
329
|
+
mcpHealthEffect,
|
|
223
330
|
mcpToolsEffect
|
|
224
331
|
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ProviderError,
|
|
3
|
+
maxUpstreamMessageLength
|
|
4
|
+
} from "./chunk-BRGF7VFN.js";
|
|
5
|
+
import {
|
|
6
|
+
AccountId
|
|
7
|
+
} from "./chunk-PWF2DRJ3.js";
|
|
8
|
+
import {
|
|
9
|
+
Option_exports,
|
|
10
|
+
Schema_exports
|
|
11
|
+
} from "./chunk-NXTXZ635.js";
|
|
12
|
+
|
|
13
|
+
// src/implementation/upstream-error.ts
|
|
14
|
+
var ErrorToken = Schema_exports.String.check(Schema_exports.isPattern(/^[A-Za-z0-9._-]{1,128}$/));
|
|
15
|
+
var JsonRpcError = Schema_exports.Struct({
|
|
16
|
+
error: Schema_exports.Struct({ code: Schema_exports.Int, message: Schema_exports.String })
|
|
17
|
+
});
|
|
18
|
+
var OAuthError = Schema_exports.Struct({
|
|
19
|
+
error: ErrorToken,
|
|
20
|
+
error_description: Schema_exports.optional(Schema_exports.String)
|
|
21
|
+
});
|
|
22
|
+
var bounded = (message) => message.length <= maxUpstreamMessageLength ? message : `${message.slice(0, maxUpstreamMessageLength - 1)}\u2026`;
|
|
23
|
+
var isShortenedUpstream = (message) => message.length === maxUpstreamMessageLength && message.endsWith("\u2026");
|
|
24
|
+
var stated = (code, message) => ({
|
|
25
|
+
code,
|
|
26
|
+
...message === void 0 || message === "" ? {} : { message: bounded(message) }
|
|
27
|
+
});
|
|
28
|
+
var bodyUpstreamError = (json) => {
|
|
29
|
+
const rpc = Schema_exports.decodeUnknownOption(JsonRpcError)(json);
|
|
30
|
+
if (Option_exports.isSome(rpc)) return stated(rpc.value.error.code, rpc.value.error.message);
|
|
31
|
+
const oauth = Schema_exports.decodeUnknownOption(OAuthError)(json);
|
|
32
|
+
if (Option_exports.isSome(oauth)) return stated(oauth.value.error, oauth.value.error_description);
|
|
33
|
+
return void 0;
|
|
34
|
+
};
|
|
35
|
+
var authParam = /([A-Za-z][A-Za-z0-9_-]*)\s*=\s*(?:"((?:[^"\\]|\\.)*)"|([^\s,"]+))/g;
|
|
36
|
+
var challengeUpstreamError = (header) => {
|
|
37
|
+
const bearer = header === void 0 ? -1 : header.search(/\bBearer\b/i);
|
|
38
|
+
if (header === void 0 || bearer === -1) return void 0;
|
|
39
|
+
const params = /* @__PURE__ */ new Map();
|
|
40
|
+
for (const [, name, quoted, token] of header.slice(bearer + "Bearer".length).matchAll(authParam))
|
|
41
|
+
if (name !== void 0 && !params.has(name.toLowerCase()))
|
|
42
|
+
params.set(name.toLowerCase(), quoted?.replace(/\\(.)/g, "$1") ?? token ?? "");
|
|
43
|
+
const code = Schema_exports.decodeUnknownOption(ErrorToken)(params.get("error"));
|
|
44
|
+
return Option_exports.isNone(code) ? void 0 : stated(code.value, params.get("error_description"));
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/implementation/provider-error.ts
|
|
48
|
+
var providerError = ({
|
|
49
|
+
reason,
|
|
50
|
+
status,
|
|
51
|
+
accountId,
|
|
52
|
+
phase,
|
|
53
|
+
upstream
|
|
54
|
+
}) => new ProviderError({
|
|
55
|
+
reason,
|
|
56
|
+
...status === void 0 ? {} : { status },
|
|
57
|
+
...accountId === void 0 ? {} : { accountId },
|
|
58
|
+
...phase === void 0 ? {} : { phase },
|
|
59
|
+
...upstream === void 0 ? {} : { upstream }
|
|
60
|
+
});
|
|
61
|
+
function parseProviderError(error) {
|
|
62
|
+
return Schema_exports.decodeUnknownOption(ProviderError)(error).pipe(Option_exports.map(providerError));
|
|
63
|
+
}
|
|
64
|
+
function providerErrorDetail(error, detail) {
|
|
65
|
+
return providerError({
|
|
66
|
+
...error,
|
|
67
|
+
phase: error.phase ?? detail.phase,
|
|
68
|
+
upstream: error.upstream ?? detail.upstream
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function httpProviderError(status, headers = {}) {
|
|
72
|
+
const upstream = challengeUpstreamError(headers["www-authenticate"]);
|
|
73
|
+
if (status >= 500 && status <= 599)
|
|
74
|
+
return providerError({ reason: "unavailable", status, upstream });
|
|
75
|
+
if (status === 401) return providerError({ reason: "unauthorized", status, upstream });
|
|
76
|
+
if (status === 429) return providerError({ reason: "rate_limited", status, upstream });
|
|
77
|
+
if (status !== 403) return void 0;
|
|
78
|
+
const retry = headers["retry-after"];
|
|
79
|
+
if (headers["x-ratelimit-remaining"] === "0" || retry !== void 0 && (/^\d+$/.test(retry) || Number.isFinite(Date.parse(retry))))
|
|
80
|
+
return providerError({ reason: "rate_limited", status, upstream });
|
|
81
|
+
if (typeof upstream?.code === "string" && upstream.code.toLowerCase() === "insufficient_scope")
|
|
82
|
+
return providerError({ reason: "forbidden", status, upstream });
|
|
83
|
+
return providerError({ reason: "rejected", status, upstream });
|
|
84
|
+
}
|
|
85
|
+
function accountProviderError(error, accountId) {
|
|
86
|
+
const parsed = parseProviderError(error);
|
|
87
|
+
const account = Schema_exports.decodeUnknownOption(AccountId)(accountId);
|
|
88
|
+
if (Option_exports.isNone(parsed) || Option_exports.isNone(account)) return error;
|
|
89
|
+
return providerError({ ...parsed.value, accountId: account.value });
|
|
90
|
+
}
|
|
91
|
+
function graphqlProviderError(errors, status) {
|
|
92
|
+
const codes = errors.flatMap((error) => {
|
|
93
|
+
const parsed = Schema_exports.decodeUnknownOption(
|
|
94
|
+
Schema_exports.Struct({
|
|
95
|
+
type: Schema_exports.optional(Schema_exports.String),
|
|
96
|
+
extensions: Schema_exports.optional(Schema_exports.Struct({ code: Schema_exports.optional(Schema_exports.String) }))
|
|
97
|
+
})
|
|
98
|
+
)(error);
|
|
99
|
+
return Option_exports.isSome(parsed) ? [parsed.value.type, parsed.value.extensions?.code] : [];
|
|
100
|
+
});
|
|
101
|
+
if (codes.includes("RATE_LIMITED") || codes.includes("TOO_MANY_REQUESTS"))
|
|
102
|
+
return new ProviderError({ reason: "rate_limited", status });
|
|
103
|
+
if (codes.includes("UNAUTHENTICATED"))
|
|
104
|
+
return new ProviderError({ reason: "unauthorized", status });
|
|
105
|
+
if (codes.includes("FORBIDDEN")) return new ProviderError({ reason: "forbidden", status });
|
|
106
|
+
return void 0;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export {
|
|
110
|
+
isShortenedUpstream,
|
|
111
|
+
bodyUpstreamError,
|
|
112
|
+
providerError,
|
|
113
|
+
parseProviderError,
|
|
114
|
+
providerErrorDetail,
|
|
115
|
+
httpProviderError,
|
|
116
|
+
accountProviderError,
|
|
117
|
+
graphqlProviderError
|
|
118
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Schema_exports
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-NXTXZ635.js";
|
|
4
4
|
|
|
5
5
|
// ../app-data/src/contracts/database.ts
|
|
6
6
|
var DataName = Schema_exports.String.check(
|
|
@@ -113,6 +113,51 @@ var defaultDatabaseLimits = {
|
|
|
113
113
|
valueBytes: 64 * 1024,
|
|
114
114
|
indexBytes: 2048
|
|
115
115
|
};
|
|
116
|
+
var DatabaseLimit = Schema_exports.Literals([
|
|
117
|
+
"scanCalls",
|
|
118
|
+
"directGets",
|
|
119
|
+
"rowsRead",
|
|
120
|
+
"rowsReturned",
|
|
121
|
+
"pageSize",
|
|
122
|
+
"bytesRead",
|
|
123
|
+
"writes",
|
|
124
|
+
"valueBytes"
|
|
125
|
+
]);
|
|
126
|
+
var count = (value) => value.toLocaleString("en-US");
|
|
127
|
+
var limitMessages = {
|
|
128
|
+
scanCalls: (maximum, requested) => `This invocation made ${count(requested)} index queries; the limit is ${count(maximum)}. Each first(), take(), collect(), count() or paginate() call on withIndex(...) counts once. Read related rows with one take() or paginate() over a shared index prefix instead of one first() per item, use get(id) for known IDs, or split the work across workflow steps.`,
|
|
129
|
+
directGets: (maximum, requested) => `This invocation made ${count(requested)} get(id) calls, including those made by update and delete; the limit is ${count(maximum)}. Split the work across workflow steps or mutations.`,
|
|
130
|
+
rowsRead: (maximum, requested) => `This invocation scanned ${count(requested)} rows; the limit is ${count(maximum)}. Narrow the index range, or page with paginate() across calls or workflow steps.`,
|
|
131
|
+
rowsReturned: (maximum, requested) => `This invocation returned ${count(requested)} rows; the limit is ${count(maximum)}. collect() fails rather than truncating. Page with paginate() across calls or workflow steps.`,
|
|
132
|
+
pageSize: (maximum, requested) => `One call asked for ${count(requested)} rows; take(n) and paginate({ numItems }) accept at most ${count(maximum)}. Page with paginate() across calls or workflow steps.`,
|
|
133
|
+
bytesRead: (maximum, requested) => `This invocation read ${count(requested)} bytes; the limit is ${count(maximum)}. Read fewer or smaller rows per call, or page with paginate() across calls or workflow steps.`,
|
|
134
|
+
writes: (maximum, requested) => `This mutation made ${count(requested)} writes; the limit is ${count(maximum)}. Split large ingests into batches, one batch per mutation or workflow step.`,
|
|
135
|
+
valueBytes: (maximum, requested) => `A row encodes to ${count(requested)} bytes; each row may use at most ${count(maximum)}. Store large content outside the row or split it across rows.`
|
|
136
|
+
};
|
|
137
|
+
var DatabaseLimitExceeded = class extends Schema_exports.TaggedError()(
|
|
138
|
+
"DatabaseLimitExceeded",
|
|
139
|
+
{
|
|
140
|
+
limit: DatabaseLimit,
|
|
141
|
+
maximum: Schema_exports.Int,
|
|
142
|
+
requested: Schema_exports.Int
|
|
143
|
+
}
|
|
144
|
+
) {
|
|
145
|
+
get message() {
|
|
146
|
+
return limitMessages[this.limit](this.maximum, this.requested);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
var reservedFieldNames = ["id", "createdAt", "updatedAt"];
|
|
150
|
+
var DatabaseFieldReserved = class extends Schema_exports.TaggedError()(
|
|
151
|
+
"DatabaseFieldReserved",
|
|
152
|
+
{
|
|
153
|
+
table: Schema_exports.String,
|
|
154
|
+
field: Schema_exports.Literals(reservedFieldNames)
|
|
155
|
+
}
|
|
156
|
+
) {
|
|
157
|
+
get message() {
|
|
158
|
+
return `Table "${this.table}" declares "${this.field}", which is reserved: the host adds id, createdAt and updatedAt to every row. Rename the field, or use the row's own ${this.field}.`;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
116
161
|
var DatabaseRuntimeLimits = Schema_exports.Struct({
|
|
117
162
|
maxCursorChars: Schema_exports.Int.check(Schema_exports.isGreaterThan(0)),
|
|
118
163
|
connectionCacheCapacity: Schema_exports.Int.check(Schema_exports.isGreaterThan(0)),
|
|
@@ -134,5 +179,8 @@ export {
|
|
|
134
179
|
AppDatabaseError,
|
|
135
180
|
DatabaseLimits,
|
|
136
181
|
defaultDatabaseLimits,
|
|
182
|
+
DatabaseLimitExceeded,
|
|
183
|
+
reservedFieldNames,
|
|
184
|
+
DatabaseFieldReserved,
|
|
137
185
|
defaultDatabaseRuntimeLimits
|
|
138
186
|
};
|
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
import {
|
|
2
|
+
SchemaGetter_exports,
|
|
2
3
|
Schema_exports
|
|
3
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-NXTXZ635.js";
|
|
5
|
+
|
|
6
|
+
// ../utils/src/api-error.ts
|
|
7
|
+
var MessageField = Schema_exports.String.pipe(
|
|
8
|
+
Schema_exports.decodeTo(Schema_exports.optionalKey(Schema_exports.String), {
|
|
9
|
+
decode: SchemaGetter_exports.omit(),
|
|
10
|
+
encode: SchemaGetter_exports.passthrough()
|
|
11
|
+
})
|
|
12
|
+
);
|
|
13
|
+
function withFields(definition) {
|
|
14
|
+
const fields = definition.fields;
|
|
15
|
+
const message = definition.message;
|
|
16
|
+
const documentation = typeof message === "string" ? { description: message } : {};
|
|
17
|
+
const DefinedError = Schema_exports.Error(definition.tag)(
|
|
18
|
+
Schema_exports.TaggedStruct(definition.tag, { ...fields, message: MessageField }).annotate(
|
|
19
|
+
documentation
|
|
20
|
+
),
|
|
21
|
+
{ httpApiStatus: definition.status, ...documentation }
|
|
22
|
+
);
|
|
23
|
+
Object.defineProperty(DefinedError.prototype, "message", {
|
|
24
|
+
get() {
|
|
25
|
+
return typeof message === "string" ? message : message(this);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return DefinedError;
|
|
29
|
+
}
|
|
30
|
+
function define(definition) {
|
|
31
|
+
return "fields" in definition ? withFields(definition) : withFields({ ...definition, fields: {} });
|
|
32
|
+
}
|
|
33
|
+
var ApiError = { define };
|
|
4
34
|
|
|
5
35
|
// src/contracts/skills.ts
|
|
6
36
|
var SkillFilePath = Schema_exports.NonEmptyString.check(
|
|
@@ -45,9 +75,18 @@ var AppSkillSource = Schema_exports.Struct({
|
|
|
45
75
|
)
|
|
46
76
|
)
|
|
47
77
|
});
|
|
48
|
-
var
|
|
49
|
-
|
|
50
|
-
{
|
|
78
|
+
var skillDefinitionFailures = {
|
|
79
|
+
files: (file) => `The skill files of \u201C${file}\u201D are invalid: each needs a unique relative path, text content and a SKILL.md document.`,
|
|
80
|
+
directory: (file) => `\u201C${file}\u201D is not a valid skill directory. Skill directory names use lowercase letters and digits separated by single hyphens.`,
|
|
81
|
+
"missing-document": (file) => `\u201C${file}\u201D is missing.`,
|
|
82
|
+
frontmatter: (file) => `\u201C${file}\u201D must start with valid YAML frontmatter between --- lines.`,
|
|
83
|
+
metadata: (file) => `The frontmatter of \u201C${file}\u201D needs a valid name and description within the Agent Skills limits.`,
|
|
84
|
+
"name-mismatch": (file) => `The name in \u201C${file}\u201D does not match its skill directory.`
|
|
85
|
+
};
|
|
86
|
+
var SkillDefinitionInvalid = ApiError.define({
|
|
87
|
+
tag: "SkillDefinitionInvalid",
|
|
88
|
+
status: 400,
|
|
89
|
+
fields: {
|
|
51
90
|
file: SkillFilePath,
|
|
52
91
|
reason: Schema_exports.Literals([
|
|
53
92
|
"files",
|
|
@@ -58,9 +97,8 @@ var SkillDefinitionInvalid = class extends Schema_exports.TaggedError()(
|
|
|
58
97
|
"name-mismatch"
|
|
59
98
|
])
|
|
60
99
|
},
|
|
61
|
-
{
|
|
62
|
-
)
|
|
63
|
-
};
|
|
100
|
+
message: ({ file, reason }) => skillDefinitionFailures[reason](file)
|
|
101
|
+
});
|
|
64
102
|
var AppSkills = Schema_exports.Array(AppSkillSource).check(
|
|
65
103
|
Schema_exports.makeFilter((skills) => new Set(skills.map((skill) => skill.name)).size === skills.length)
|
|
66
104
|
);
|