apps 0.0.1-beta.4 → 0.0.1-beta.40
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-QKHR7BMF.js → chunk-3MMG2H6M.js} +89 -53
- package/js/chunk-4TLZGG4B.js +729 -0
- package/js/chunk-6KABJTDO.js +255 -0
- package/js/{chunk-FDNTX5QJ.js → chunk-CQD3WSYH.js} +2 -2
- package/js/{chunk-EQB7JMAL.js → chunk-DHX2OI2X.js} +146 -31
- package/js/{chunk-EVJUVWN2.js → chunk-DKUEYTYD.js} +463 -218
- package/js/chunk-EM4UL26F.js +118 -0
- package/js/{chunk-WFSQXYUT.js → chunk-GHXRRFZA.js} +418 -52
- package/js/{chunk-5MQZEB6Y.js → chunk-KANDIVIH.js} +40 -12
- package/js/chunk-KAQD3DTI.js +16 -0
- package/js/chunk-KIM5HXNK.js +49 -0
- package/js/{chunk-FW5HBOIK.js → chunk-MXDKXAY4.js} +19117 -18309
- package/js/{chunk-2VPJHFOU.js → chunk-MYF7KWUB.js} +128 -24
- package/js/{chunk-T2LAZCAD.js → chunk-NKWWPJYX.js} +3 -3
- package/js/chunk-OD3KFKZD.js +1617 -0
- package/js/{chunk-3M2MEDNL.js → chunk-OTCLXFLL.js} +1337 -188
- package/js/chunk-P7MGDPFD.js +240 -0
- package/js/chunk-PDS2E2OZ.js +42 -0
- package/js/{chunk-ZCAMUXSG.js → chunk-PNVCCB4L.js} +432 -79
- package/js/{chunk-D47C7KG5.js → chunk-RIXVGVA6.js} +2 -2
- package/js/{chunk-6VRYO2BG.js → chunk-SALJXSS3.js} +779 -251
- package/js/{chunk-NQ3OMCA5.js → chunk-TT6OU4UG.js} +2 -2
- package/js/{chunk-YEJOQEII.js → chunk-UOZMSUJ2.js} +61 -9
- package/js/{chunk-G7ZIRKMK.js → chunk-VIU2XXA7.js} +228 -264
- package/js/{chunk-HDJH3RPR.js → chunk-VJQXXOQ3.js} +4 -4
- package/js/chunk-XDGUGB2A.js +156 -0
- package/js/{chunk-SATWJKN6.js → chunk-YQ35E7KS.js} +2 -2
- package/js/chunk-ZUKBIHMK.js +92 -0
- package/js/client.js +122 -88
- package/js/contracts.js +116 -25
- package/js/effect.js +19 -20
- package/js/{es-APDZKREY.js → es-DIULA3ZF.js} +62 -1659
- package/js/graphql.js +57 -55
- package/js/host.js +19 -20
- package/js/index.js +245 -212
- package/js/mcp/effect.js +23 -22
- package/js/mcp/stdio.js +34 -30
- package/js/mcp.js +104 -68
- package/js/openapi.js +4087 -1503
- package/js/react.js +2 -3
- package/js/skills/effect.js +6 -3
- package/js/skills.js +147 -65
- package/js/storage/facet.js +1 -540
- 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 +8517 -214
- package/package.json +2 -3
- package/runtime.json +1 -1
- package/types/app-data/src/contracts/database.d.ts +33 -6
- package/types/apps/src/contracts/api-response-error.d.ts +4 -0
- package/types/apps/src/contracts/app.d.ts +7 -8
- package/types/apps/src/contracts/cache.d.ts +14 -0
- package/types/apps/src/contracts/context.d.ts +12 -11
- package/types/apps/src/contracts/elicitation.d.ts +6 -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 +44 -17
- package/types/apps/src/contracts/live.d.ts +2 -0
- package/types/apps/src/contracts/mcp.d.ts +96 -10
- package/types/apps/src/contracts/network.d.ts +84 -0
- package/types/apps/src/contracts/openapi-compile.d.ts +32 -3
- package/types/apps/src/contracts/openapi.d.ts +45 -9
- package/types/apps/src/contracts/operations.d.ts +8 -9
- package/types/apps/src/contracts/protocol-version.d.ts +2 -2
- package/types/apps/src/contracts/protocols/1.d.ts +263 -74
- package/types/apps/src/contracts/protocols/10.d.ts +1450 -0
- package/types/apps/src/contracts/protocols/2.d.ts +66 -24
- package/types/apps/src/contracts/protocols/3.d.ts +715 -0
- package/types/apps/src/contracts/protocols/4.d.ts +1297 -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 +1130 -0
- package/types/apps/src/contracts/protocols/9.d.ts +1106 -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 +39 -9
- package/types/apps/src/contracts/sql.d.ts +58 -0
- package/types/apps/src/contracts/ui.d.ts +19 -1
- package/types/apps/src/contracts/workflows.d.ts +40 -3
- package/types/apps/src/facet.d.ts +4 -5
- 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 +32 -5
- package/types/apps/src/implementation/elicitation.d.ts +9 -9
- package/types/apps/src/implementation/failure-detail.d.ts +47 -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/input-problems.d.ts +4 -1
- package/types/apps/src/implementation/live.d.ts +2 -2
- 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 +46 -19
- 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/optimistic.d.ts +1 -1
- 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/query-commit.d.ts +1 -1
- package/types/apps/src/implementation/router-catalog.d.ts +223 -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 +86 -11
- package/types/apps/src/implementation/skills.d.ts +18 -24
- package/types/apps/src/implementation/sql.d.ts +66 -0
- package/types/apps/src/implementation/ui-account-notice.d.ts +9 -0
- package/types/apps/src/implementation/ui-auth.d.ts +1 -1
- 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 +11 -5
- 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 +30 -13
- 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/react.d.ts +1 -1
- package/types/apps/src/skills.d.ts +10 -8
- package/types/telemetry/src/app-records.d.ts +42 -0
- package/types/telemetry/src/browser-operations.d.ts +6 -3
- package/types/telemetry/src/browser.d.ts +2 -2
- package/types/telemetry/src/config.d.ts +2 -2
- package/types/telemetry/src/layer.d.ts +2 -2
- package/types/telemetry/src/recorded-failure.d.ts +20 -0
- package/types/telemetry/src/relay.d.ts +2 -2
- package/types/telemetry/src/transport.d.ts +8 -1
- package/types/utils/src/api-error.d.ts +53 -0
- package/types/utils/src/recorded-message.d.ts +15 -0
- package/js/chunk-BMOIAIVR.js +0 -138
- package/js/chunk-DHUDODG5.js +0 -213
- package/js/chunk-FZJOYIZO.js +0 -19
- package/js/chunk-LGIYBDWA.js +0 -85
- package/js/chunk-M6ZRRIBI.js +0 -877
- package/js/chunk-PLCMJREA.js +0 -590
- 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/app-data/src/implementation/cursor.d.ts +0 -10
- package/types/app-data/src/implementation/index-key.d.ts +0 -7
- package/types/app-data/src/implementation/promise.d.ts +0 -68
- package/types/app-data/src/implementation/range.d.ts +0 -8
- package/types/app-data/src/implementation/schema.d.ts +0 -33
- package/types/app-data/src/implementation/sqlite.d.ts +0 -11
- package/types/app-data/src/index.d.ts +0 -4
- package/types/apps/src/contracts/dynamic-tools.d.ts +0 -13
- package/types/apps/src/contracts/storage.d.ts +0 -68
- package/types/apps/src/implementation/account-operations.d.ts +0 -151
- package/types/apps/src/implementation/dynamic-tools.d.ts +0 -8
- package/types/apps/src/implementation/storage.d.ts +0 -13
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HostedTool,
|
|
3
|
+
RouterKey,
|
|
4
|
+
RouterMeta,
|
|
5
|
+
reservedRouterKeys
|
|
6
|
+
} from "./chunk-OTCLXFLL.js";
|
|
7
|
+
import {
|
|
8
|
+
decoderOf,
|
|
9
|
+
schemaArgument
|
|
10
|
+
} from "./chunk-GHXRRFZA.js";
|
|
11
|
+
import {
|
|
12
|
+
Effect_exports,
|
|
13
|
+
Schema_exports
|
|
14
|
+
} from "./chunk-MXDKXAY4.js";
|
|
15
|
+
|
|
16
|
+
// src/implementation/authoring.ts
|
|
17
|
+
var NativeCallback = /* @__PURE__ */ Symbol("apps.NativeCallback");
|
|
18
|
+
var fromPromise = (callback) => (...args) => {
|
|
19
|
+
if (NativeCallback in callback) {
|
|
20
|
+
const native = callback[NativeCallback];
|
|
21
|
+
return native(...args);
|
|
22
|
+
}
|
|
23
|
+
return Effect_exports.tryPromise({ try: () => callback(...args), catch: (error) => error });
|
|
24
|
+
};
|
|
25
|
+
var toPromise = (operation, signal) => {
|
|
26
|
+
const native = (...args) => Effect_exports.suspend(() => {
|
|
27
|
+
if (signal === void 0) return operation(...args);
|
|
28
|
+
if (signal.aborted) return Effect_exports.interrupt;
|
|
29
|
+
const cancelled = Effect_exports.callback((resume) => {
|
|
30
|
+
if (signal.aborted) {
|
|
31
|
+
resume(Effect_exports.interrupt);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const abort = () => resume(Effect_exports.interrupt);
|
|
35
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
36
|
+
return Effect_exports.sync(() => signal.removeEventListener("abort", abort));
|
|
37
|
+
});
|
|
38
|
+
return Effect_exports.raceFirst(
|
|
39
|
+
cancelled,
|
|
40
|
+
Effect_exports.suspend(() => operation(...args))
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
return Object.assign((...args) => Effect_exports.runPromise(native(...args)), {
|
|
44
|
+
[NativeCallback]: native
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/implementation/operations.ts
|
|
49
|
+
var NativeOperation = /* @__PURE__ */ Symbol("apps.Operation");
|
|
50
|
+
var NativeRouterKey = /* @__PURE__ */ Symbol("apps.Router");
|
|
51
|
+
var operationDeclaration = (operation) => ({
|
|
52
|
+
kind: operation.kind,
|
|
53
|
+
[NativeOperation]: operation
|
|
54
|
+
});
|
|
55
|
+
var nativeOperation = (value) => {
|
|
56
|
+
if (typeof value !== "object" || value === null || !(NativeOperation in value)) return void 0;
|
|
57
|
+
return value[NativeOperation];
|
|
58
|
+
};
|
|
59
|
+
var operationOptions = (options) => {
|
|
60
|
+
const approval = options.approval;
|
|
61
|
+
return {
|
|
62
|
+
...options.description === void 0 ? {} : { description: options.description },
|
|
63
|
+
...options.title === void 0 ? {} : { title: options.title },
|
|
64
|
+
...options.annotations === void 0 ? {} : { annotations: options.annotations },
|
|
65
|
+
...options._meta === void 0 ? {} : { _meta: options._meta },
|
|
66
|
+
input: decoderOf(options.input),
|
|
67
|
+
...approval === void 0 ? {} : {
|
|
68
|
+
approval: (context) => Effect_exports.tryPromise({ try: async () => approval(context), catch: (error) => error })
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
var approvedOperation = (operation, approval) => {
|
|
73
|
+
const copy = Object.defineProperties({}, Object.getOwnPropertyDescriptors(operation));
|
|
74
|
+
return Object.defineProperty(copy, "approval", {
|
|
75
|
+
enumerable: true,
|
|
76
|
+
value: (context) => Effect_exports.tryPromise({ try: async () => approval(context), catch: (error) => error })
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
var withApproval = (operation, approval) => ({
|
|
80
|
+
...operation,
|
|
81
|
+
[NativeOperation]: approvedOperation(operation[NativeOperation], approval)
|
|
82
|
+
});
|
|
83
|
+
var toolAnnotations = (operation) => nativeOperation(operation)?.annotations;
|
|
84
|
+
var make = (kind, options, run) => operationDeclaration({
|
|
85
|
+
...operationOptions({ ...options, input: schemaArgument(options.input, `The ${kind} input`) }),
|
|
86
|
+
kind,
|
|
87
|
+
// The host always validates JSON serialization, even without a stronger output declaration.
|
|
88
|
+
...options.output === void 0 ? {} : { output: decoderOf(schemaArgument(options.output, `The ${kind} output`)) },
|
|
89
|
+
run: (context, input) => Effect_exports.tryPromise({
|
|
90
|
+
// SAFETY: defineApp checks the handler context against its requirements.
|
|
91
|
+
// The host validates account bindings and creates the matching storage facade.
|
|
92
|
+
try: () => run(context, input),
|
|
93
|
+
catch: (error) => error
|
|
94
|
+
})
|
|
95
|
+
});
|
|
96
|
+
var query = (options, run) => make("query", options, run);
|
|
97
|
+
var mutation = (options, run) => make("mutation", options, run);
|
|
98
|
+
|
|
99
|
+
// src/implementation/router.ts
|
|
100
|
+
var routerDeclaration = (node) => ({
|
|
101
|
+
[NativeRouterKey]: node
|
|
102
|
+
});
|
|
103
|
+
var nativeRouter = (value) => {
|
|
104
|
+
if (typeof value !== "object" || value === null || !(NativeRouterKey in value)) return void 0;
|
|
105
|
+
return value[NativeRouterKey];
|
|
106
|
+
};
|
|
107
|
+
var nativeNode = (value) => nativeOperation(value) ?? nativeRouter(value);
|
|
108
|
+
var metaOf = (options) => {
|
|
109
|
+
if (options === void 0) return void 0;
|
|
110
|
+
const defined = Object.fromEntries(
|
|
111
|
+
Object.entries(options).filter(([, value]) => value !== void 0)
|
|
112
|
+
);
|
|
113
|
+
return Object.keys(defined).length === 0 ? void 0 : Schema_exports.decodeUnknownSync(RouterMeta)(defined);
|
|
114
|
+
};
|
|
115
|
+
var mergeMeta = (base, override) => base === void 0 ? override : override === void 0 ? base : { ...base, ...override };
|
|
116
|
+
function router(children, options) {
|
|
117
|
+
const meta = metaOf(options);
|
|
118
|
+
const existing = nativeRouter(children);
|
|
119
|
+
if (existing !== void 0)
|
|
120
|
+
return routerDeclaration(
|
|
121
|
+
existing.kind === "router" ? { ...existing, ...withMeta(mergeMeta(existing.meta, meta)) } : { ...existing, ...withOverrides(mergeMeta(existing.overrides, meta)) }
|
|
122
|
+
);
|
|
123
|
+
const nodes = {};
|
|
124
|
+
for (const [key, value] of Object.entries(children)) {
|
|
125
|
+
if (reservedRouterKeys.has(key)) throw new Error(`Router key "${key}" is reserved`);
|
|
126
|
+
if (!Schema_exports.is(RouterKey)(key))
|
|
127
|
+
throw new Error(`Router key "${key}" must start with a letter or _ and contain no dots`);
|
|
128
|
+
const node = nativeNode(value);
|
|
129
|
+
if (node === void 0)
|
|
130
|
+
throw new Error(`Router key "${key}" must be a query, mutation or router`);
|
|
131
|
+
nodes[key] = node;
|
|
132
|
+
}
|
|
133
|
+
return routerDeclaration({ kind: "router", ...withMeta(meta), children: nodes });
|
|
134
|
+
}
|
|
135
|
+
var withMeta = (meta) => meta === void 0 ? {} : { meta };
|
|
136
|
+
var withOverrides = (overrides) => overrides === void 0 ? {} : { overrides };
|
|
137
|
+
var dynamicRouter = (source) => {
|
|
138
|
+
const meta = source.meta;
|
|
139
|
+
return routerDeclaration({
|
|
140
|
+
kind: "dynamic",
|
|
141
|
+
...meta === void 0 ? {} : {
|
|
142
|
+
meta: () => fromPromise(async () => meta())().pipe(
|
|
143
|
+
Effect_exports.flatMap((options) => Schema_exports.decodeUnknownEffect(RouterMeta)(options))
|
|
144
|
+
)
|
|
145
|
+
},
|
|
146
|
+
list: () => fromPromise(async () => source.list())().pipe(
|
|
147
|
+
Effect_exports.flatMap(Schema_exports.decodeUnknownEffect(Schema_exports.Array(HostedTool)))
|
|
148
|
+
),
|
|
149
|
+
resolve: (name) => fromPromise(async () => source.resolve(name))().pipe(
|
|
150
|
+
Effect_exports.map((value) => {
|
|
151
|
+
if (value === void 0) return void 0;
|
|
152
|
+
const operation = nativeOperation(value);
|
|
153
|
+
if (operation === void 0) throw new Error("Expected an operation declaration");
|
|
154
|
+
return operation;
|
|
155
|
+
})
|
|
156
|
+
)
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
var joinPath = (path, name) => path === "" ? name : `${path}.${name}`;
|
|
160
|
+
var locate = (root, name) => {
|
|
161
|
+
if (root?.kind === "dynamic") return { kind: "dynamic", source: root, router: "", name };
|
|
162
|
+
let current = root;
|
|
163
|
+
let path = "";
|
|
164
|
+
let rest = name;
|
|
165
|
+
while (current !== void 0) {
|
|
166
|
+
const dot = rest.indexOf(".");
|
|
167
|
+
const key = dot < 0 ? rest : rest.slice(0, dot);
|
|
168
|
+
const child = Object.hasOwn(current.children, key) ? current.children[key] : void 0;
|
|
169
|
+
if (child === void 0) return void 0;
|
|
170
|
+
const remaining = dot < 0 ? void 0 : rest.slice(dot + 1);
|
|
171
|
+
switch (child.kind) {
|
|
172
|
+
case "query":
|
|
173
|
+
case "mutation":
|
|
174
|
+
return remaining === void 0 ? { kind: "operation", operation: child, router: path } : void 0;
|
|
175
|
+
case "dynamic":
|
|
176
|
+
return remaining === void 0 || remaining === "" ? void 0 : { kind: "dynamic", source: child, router: joinPath(path, key), name: remaining };
|
|
177
|
+
case "router":
|
|
178
|
+
if (remaining === void 0) return void 0;
|
|
179
|
+
current = child;
|
|
180
|
+
path = joinPath(path, key);
|
|
181
|
+
rest = remaining;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return void 0;
|
|
185
|
+
};
|
|
186
|
+
var declaredOperations = (root, path = "") => Object.entries(root?.children ?? {}).flatMap(([key, child]) => {
|
|
187
|
+
const name = joinPath(path, key);
|
|
188
|
+
switch (child.kind) {
|
|
189
|
+
case "query":
|
|
190
|
+
case "mutation":
|
|
191
|
+
return [{ name, router: path, operation: child }];
|
|
192
|
+
case "router":
|
|
193
|
+
return declaredOperations(child, name);
|
|
194
|
+
case "dynamic":
|
|
195
|
+
return [];
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
var withApprovals = (source, policy) => {
|
|
199
|
+
const native = nativeRouter(source);
|
|
200
|
+
if (native === void 0) throw new Error("withApprovals expects a router");
|
|
201
|
+
const operation = (node, name) => {
|
|
202
|
+
const approval = policy(operationDeclaration(node), name);
|
|
203
|
+
return approval === void 0 ? node : approvedOperation(node, approval);
|
|
204
|
+
};
|
|
205
|
+
const child = (node, name) => {
|
|
206
|
+
switch (node.kind) {
|
|
207
|
+
case "query":
|
|
208
|
+
case "mutation":
|
|
209
|
+
return operation(node, name);
|
|
210
|
+
case "router":
|
|
211
|
+
case "dynamic":
|
|
212
|
+
return walk(node, name);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
const walk = (node, path) => node.kind === "dynamic" ? {
|
|
216
|
+
...node,
|
|
217
|
+
resolve: (name) => node.resolve(name).pipe(
|
|
218
|
+
Effect_exports.flatMap(
|
|
219
|
+
(resolved) => resolved === void 0 ? Effect_exports.succeed(void 0) : Effect_exports.try({
|
|
220
|
+
try: () => operation(resolved, joinPath(path, name)),
|
|
221
|
+
catch: (error) => error
|
|
222
|
+
})
|
|
223
|
+
)
|
|
224
|
+
)
|
|
225
|
+
} : {
|
|
226
|
+
...node,
|
|
227
|
+
children: Object.fromEntries(
|
|
228
|
+
Object.entries(node.children).map(([key, value]) => [
|
|
229
|
+
key,
|
|
230
|
+
child(value, joinPath(path, key))
|
|
231
|
+
])
|
|
232
|
+
)
|
|
233
|
+
};
|
|
234
|
+
return routerDeclaration(walk(native, ""));
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
export {
|
|
238
|
+
fromPromise,
|
|
239
|
+
toPromise,
|
|
240
|
+
operationDeclaration,
|
|
241
|
+
nativeOperation,
|
|
242
|
+
withApproval,
|
|
243
|
+
toolAnnotations,
|
|
244
|
+
query,
|
|
245
|
+
mutation,
|
|
246
|
+
routerDeclaration,
|
|
247
|
+
nativeRouter,
|
|
248
|
+
mergeMeta,
|
|
249
|
+
router,
|
|
250
|
+
dynamicRouter,
|
|
251
|
+
joinPath,
|
|
252
|
+
locate,
|
|
253
|
+
declaredOperations,
|
|
254
|
+
withApprovals
|
|
255
|
+
};
|
|
@@ -5,11 +5,11 @@ import {
|
|
|
5
5
|
SkillDefinitionInvalid,
|
|
6
6
|
SkillFile,
|
|
7
7
|
SkillFilePath
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-UOZMSUJ2.js";
|
|
9
9
|
import {
|
|
10
10
|
Effect_exports,
|
|
11
11
|
Schema_exports
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-MXDKXAY4.js";
|
|
13
13
|
|
|
14
14
|
// src/implementation/skill-files.ts
|
|
15
15
|
var skillFromFiles = (input, source = {}) => Effect_exports.gen(function* () {
|
|
@@ -1,37 +1,52 @@
|
|
|
1
1
|
import {
|
|
2
2
|
adaptMcpTools,
|
|
3
|
+
answeredError,
|
|
3
4
|
mcpClient,
|
|
4
5
|
mcpJsonSchemaValidator
|
|
5
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-MYF7KWUB.js";
|
|
7
|
+
import {
|
|
8
|
+
failOnNetworkRefusal
|
|
9
|
+
} from "./chunk-KIM5HXNK.js";
|
|
6
10
|
import {
|
|
7
11
|
accountProviderError,
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
bodyUpstreamError,
|
|
13
|
+
httpProviderError,
|
|
14
|
+
providerErrorDetail
|
|
15
|
+
} from "./chunk-EM4UL26F.js";
|
|
10
16
|
import {
|
|
17
|
+
McpCredentialsUnverified,
|
|
11
18
|
McpError,
|
|
19
|
+
McpHealthInput,
|
|
12
20
|
McpToolsOptions,
|
|
13
|
-
defaultMcpClientLimits
|
|
14
|
-
|
|
21
|
+
defaultMcpClientLimits,
|
|
22
|
+
mcpHealthReserveMs
|
|
23
|
+
} from "./chunk-OTCLXFLL.js";
|
|
15
24
|
import {
|
|
25
|
+
NetworkRefused,
|
|
16
26
|
ProviderError
|
|
17
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-P7MGDPFD.js";
|
|
18
28
|
import {
|
|
19
29
|
captureTelemetry
|
|
20
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-PNVCCB4L.js";
|
|
21
31
|
import {
|
|
22
32
|
FetchHttpClient_exports
|
|
23
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-VJQXXOQ3.js";
|
|
24
34
|
import {
|
|
25
35
|
HttpClientRequest_exports,
|
|
26
36
|
HttpClient_exports
|
|
27
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-3MMG2H6M.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-MXDKXAY4.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,41 @@ 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
|
-
|
|
87
|
-
headers: response.headers
|
|
88
|
-
}
|
|
141
|
+
const session = new Headers(init?.headers).has("mcp-session-id");
|
|
142
|
+
yield* Ref_exports.update(
|
|
143
|
+
answered,
|
|
144
|
+
(responses) => new Map(responses).set(response.status, { upstream, session })
|
|
89
145
|
);
|
|
146
|
+
return new Response(body, { status: response.status, headers: response.headers });
|
|
90
147
|
}).pipe(
|
|
91
148
|
Effect_exports.provide(FetchHttpClient_exports.layer),
|
|
92
149
|
Effect_exports.provideService(FetchHttpClient_exports.RequestInit, { redirect: "manual" }),
|
|
@@ -104,15 +161,34 @@ var transportFetch = (connection, telemetry, rejected) => (url, init) => Effect_
|
|
|
104
161
|
),
|
|
105
162
|
init?.signal ? { signal: init.signal } : {}
|
|
106
163
|
);
|
|
164
|
+
var explain = (error, phase, responses) => {
|
|
165
|
+
if (Schema_exports.is(ProviderError)(error)) return providerErrorDetail(error, { phase });
|
|
166
|
+
if (!Schema_exports.is(McpError)(error) || error.status === void 0) return error;
|
|
167
|
+
const response = responses.get(error.status);
|
|
168
|
+
if (response === void 0 || (error.upstream !== void 0 || response.upstream === void 0) && !response.session)
|
|
169
|
+
return error;
|
|
170
|
+
const upstream = error.upstream ?? response.upstream;
|
|
171
|
+
return new McpError({
|
|
172
|
+
phase: error.phase,
|
|
173
|
+
reason: error.reason,
|
|
174
|
+
status: error.status,
|
|
175
|
+
...upstream === void 0 ? {} : { upstream },
|
|
176
|
+
...response.session ? { session: true } : {}
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
var explained = (phase, answered) => (error) => Ref_exports.get(answered).pipe(
|
|
180
|
+
Effect_exports.flatMap((responses) => Effect_exports.fail(explain(error, phase, responses)))
|
|
181
|
+
);
|
|
107
182
|
function withClient(connection, mode, use, changed) {
|
|
108
183
|
const attempt = (kind) => Effect_exports.scoped(
|
|
109
184
|
Effect_exports.gen(function* () {
|
|
110
185
|
const telemetry = yield* captureTelemetry;
|
|
111
186
|
const rejected = yield* Deferred_exports.make();
|
|
187
|
+
const answered = yield* Ref_exports.make(/* @__PURE__ */ new Map());
|
|
112
188
|
const pending = /* @__PURE__ */ new Set();
|
|
113
189
|
const { client, transport } = yield* Effect_exports.acquireRelease(
|
|
114
190
|
Effect_exports.sync(() => {
|
|
115
|
-
const fetch = transportFetch(connection, telemetry, rejected);
|
|
191
|
+
const fetch = transportFetch(connection, telemetry, rejected, answered);
|
|
116
192
|
const client2 = new Client(
|
|
117
193
|
{ name: "executor-apps", version: "0.1.0" },
|
|
118
194
|
{
|
|
@@ -168,10 +244,14 @@ function withClient(connection, mode, use, changed) {
|
|
|
168
244
|
catch: (error) => failure("connect", error)
|
|
169
245
|
}).pipe(
|
|
170
246
|
Effect_exports.raceFirst(Deferred_exports.await(rejected)),
|
|
247
|
+
Effect_exports.catch(explained("connect", answered)),
|
|
171
248
|
Effect_exports.timeout(connection.timeoutMs),
|
|
172
249
|
Effect_exports.withSpan("provider.mcp.connect")
|
|
173
250
|
);
|
|
174
|
-
return yield* use(client).pipe(
|
|
251
|
+
return yield* use(client).pipe(
|
|
252
|
+
Effect_exports.raceFirst(Deferred_exports.await(rejected)),
|
|
253
|
+
Effect_exports.catch(explained(mode, answered))
|
|
254
|
+
);
|
|
175
255
|
})
|
|
176
256
|
).pipe(
|
|
177
257
|
Effect_exports.withSpan("provider.mcp.session", {
|
|
@@ -216,9 +296,44 @@ var mcpClientEffect = (input, changed) => Effect_exports.gen(function* () {
|
|
|
216
296
|
failure
|
|
217
297
|
);
|
|
218
298
|
});
|
|
299
|
+
var refusesCredentials = (error) => Schema_exports.is(ProviderError)(error) && Match_exports.value(error.reason).pipe(
|
|
300
|
+
Match_exports.whenOr("unauthorized", "forbidden", "rejected", () => true),
|
|
301
|
+
Match_exports.whenOr("rate_limited", "unavailable", () => false),
|
|
302
|
+
Match_exports.exhaustive
|
|
303
|
+
);
|
|
304
|
+
var mcpHealthEffect = (check, options) => Effect_exports.gen(function* () {
|
|
305
|
+
const { deadline, timeoutMs, ...parsed } = yield* Schema_exports.decodeUnknownEffect(McpHealthInput)({
|
|
306
|
+
...options,
|
|
307
|
+
accountId: check.account.id,
|
|
308
|
+
signal: check.signal,
|
|
309
|
+
deadline: check.deadline
|
|
310
|
+
}).pipe(Effect_exports.mapError(() => new McpError({ phase: "connect", reason: "invalid_input" })));
|
|
311
|
+
const end = Math.min(
|
|
312
|
+
(yield* Clock_exports.currentTimeMillis) + (timeoutMs ?? defaultMcpClientLimits.timeoutMs),
|
|
313
|
+
deadline === void 0 ? Number.POSITIVE_INFINITY : deadline - mcpHealthReserveMs
|
|
314
|
+
);
|
|
315
|
+
const remaining = Effect_exports.flatMap(
|
|
316
|
+
Clock_exports.currentTimeMillis,
|
|
317
|
+
(now) => end - now >= 1 ? Effect_exports.succeed(Math.floor(end - now)) : Effect_exports.fail(new McpError({ phase: "transport", reason: "timeout" }))
|
|
318
|
+
);
|
|
319
|
+
yield* (yield* mcpClientEffect({ ...parsed, timeoutMs: yield* remaining })).check;
|
|
320
|
+
return yield* remaining.pipe(
|
|
321
|
+
Effect_exports.flatMap(
|
|
322
|
+
(timeoutMs2) => mcpClientEffect({ url: parsed.url, signal: parsed.signal, timeoutMs: timeoutMs2 })
|
|
323
|
+
),
|
|
324
|
+
Effect_exports.flatMap((anonymous) => anonymous.check),
|
|
325
|
+
Effect_exports.matchEffect({
|
|
326
|
+
onSuccess: () => Effect_exports.fail(new McpCredentialsUnverified({ anonymous: "answered" })),
|
|
327
|
+
// Executor's network refused the attempt, so the server never answered it.
|
|
328
|
+
onFailure: (error) => Schema_exports.is(NetworkRefused)(error) ? Effect_exports.fail(error) : refusesCredentials(error) ? Effect_exports.void : Effect_exports.fail(new McpCredentialsUnverified({ anonymous: error }))
|
|
329
|
+
}),
|
|
330
|
+
Effect_exports.withSpan("provider.mcp.anonymous")
|
|
331
|
+
);
|
|
332
|
+
}).pipe(Effect_exports.withSpan("provider.mcp.health"));
|
|
219
333
|
var mcpToolsEffect = (input) => mcpClientEffect(input).pipe(Effect_exports.flatMap(adaptMcpTools));
|
|
220
334
|
|
|
221
335
|
export {
|
|
222
336
|
mcpClientEffect,
|
|
337
|
+
mcpHealthEffect,
|
|
223
338
|
mcpToolsEffect
|
|
224
339
|
};
|