apps 0.0.1-beta.13 → 0.0.1-beta.130
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 +60 -42
- package/framework-reference.json +1 -1
- package/js/{chunk-M3B3DE4K.js → chunk-2XDCAXAR.js} +612 -246
- package/js/{chunk-IPI4MFSN.js → chunk-34RH47V5.js} +2 -2
- package/js/chunk-3ICMSVNC.js +175 -0
- package/js/chunk-4SIYTPIK.js +724 -0
- package/js/{chunk-KUMBKVJD.js → chunk-6QZVXLF2.js} +2 -2
- package/js/chunk-7MPPHKRW.js +5418 -0
- package/js/chunk-AR22I6UO.js +1016 -0
- package/js/chunk-BMHEVNGF.js +49 -0
- package/js/{chunk-RFVIONFX.js → chunk-BSSBP57D.js} +136 -45
- package/js/{chunk-ODEIDRGW.js → chunk-DWYOLPWT.js} +1133 -503
- package/js/chunk-H2K7OZ47.js +90 -0
- package/js/chunk-I6QAWNUM.js +161 -0
- package/js/{chunk-QS6CAHKC.js → chunk-J52LZT2Y.js} +4 -3
- package/js/chunk-JLW4LQS7.js +335 -0
- package/js/chunk-L2RUGQAM.js +576 -0
- package/js/chunk-LSOHA2RH.js +88 -0
- package/js/{chunk-UK573G7W.js → chunk-MB6L5YZE.js} +1817 -632
- package/js/chunk-OBT33ZDK.js +95 -0
- package/js/chunk-OD3KFKZD.js +1617 -0
- package/js/{chunk-JU7VHODU.js → chunk-QTX7OUFH.js} +65 -10
- package/js/chunk-T7MXJSCW.js +1945 -0
- package/js/{chunk-VFZKSM3T.js → chunk-VX36SA7Y.js} +3 -3
- package/js/chunk-WX773GGX.js +449 -0
- package/js/{chunk-5T57N25Q.js → chunk-WXHRUWNT.js} +651 -70
- package/js/{chunk-CDL5PM2Q.js → chunk-YFSOSNF3.js} +17265 -12477
- package/js/{chunk-IJX4CYZO.js → chunk-YVN2AMAU.js} +976 -447
- package/js/client.js +234 -92
- package/js/contracts.js +154 -21
- package/js/effect.js +18 -19
- package/js/{es-APDZKREY.js → es-DIULA3ZF.js} +62 -1659
- package/js/graphql.js +231 -188
- package/js/host.js +138 -80
- package/js/index.js +153 -300
- package/js/mcp/effect.js +21 -21
- package/js/mcp.js +91 -57
- package/js/openapi.js +4357 -1415
- package/js/react.js +2 -3
- package/js/skills/effect.js +6 -3
- package/js/skills.js +220 -81
- 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 +9 -8
- package/js/ui/serving.js +8618 -235
- package/package.json +3 -8
- package/runtime.json +1 -1
- package/types/app-cache/src/contracts/cache.d.ts +18 -0
- package/types/app-cache/src/index.d.ts +34 -2
- package/types/apps/src/contracts/api-response-error.d.ts +4 -0
- package/types/apps/src/contracts/app.d.ts +56 -11
- package/types/apps/src/contracts/cache.d.ts +20 -0
- package/types/apps/src/contracts/context.d.ts +60 -17
- package/types/apps/src/contracts/elicitation.d.ts +23 -7
- package/types/apps/src/contracts/events.d.ts +94 -0
- package/types/apps/src/contracts/failure.d.ts +30 -1
- package/types/apps/src/contracts/graphql.d.ts +40 -2
- package/types/apps/src/contracts/help-text.d.ts +31 -0
- package/types/apps/src/contracts/host.d.ts +1493 -20
- package/types/apps/src/contracts/icons.d.ts +28 -0
- package/types/apps/src/contracts/live.d.ts +2 -0
- package/types/apps/src/contracts/mcp.d.ts +81 -20
- package/types/apps/src/contracts/network.d.ts +120 -0
- package/types/apps/src/contracts/openapi-compile.d.ts +82 -3
- package/types/apps/src/contracts/openapi-document.d.ts +1 -1
- package/types/apps/src/contracts/openapi.d.ts +40 -8
- package/types/apps/src/contracts/operations.d.ts +14 -7
- package/types/apps/src/contracts/placement.d.ts +102 -0
- package/types/apps/src/contracts/protocol-version.d.ts +2 -2
- package/types/apps/src/contracts/protocols/1.d.ts +513 -15
- package/types/apps/src/contracts/protocols/10.d.ts +1450 -0
- package/types/apps/src/contracts/protocols/11.d.ts +1149 -0
- package/types/apps/src/contracts/protocols/12.d.ts +3310 -0
- package/types/apps/src/contracts/protocols/13.d.ts +6001 -0
- package/types/apps/src/contracts/protocols/2.d.ts +9 -8
- package/types/apps/src/contracts/protocols/3.d.ts +73 -15
- package/types/apps/src/contracts/protocols/4.d.ts +22 -15
- package/types/apps/src/contracts/protocols/5.d.ts +37 -11
- package/types/apps/src/contracts/protocols/6.d.ts +1629 -0
- package/types/apps/src/contracts/protocols/7.d.ts +1785 -0
- package/types/apps/src/contracts/protocols/8.d.ts +1182 -0
- package/types/apps/src/contracts/protocols/9.d.ts +1104 -0
- package/types/apps/src/contracts/protocols/current.d.ts +7114 -0
- package/types/apps/src/contracts/protocols/oauth-6.d.ts +74 -0
- package/types/apps/src/contracts/protocols/oauth.d.ts +134 -0
- package/types/apps/src/contracts/provider-error.d.ts +9 -0
- package/types/apps/src/contracts/provider.d.ts +56 -0
- package/types/apps/src/contracts/router.d.ts +2 -1
- package/types/apps/src/contracts/schedules.d.ts +7 -1
- package/types/apps/src/contracts/schema.d.ts +21 -0
- package/types/apps/src/contracts/shared-catalog.d.ts +11 -0
- package/types/apps/src/contracts/skills.d.ts +50 -13
- package/types/apps/src/contracts/sql.d.ts +63 -0
- package/types/apps/src/contracts/ui.d.ts +70 -30
- package/types/apps/src/contracts/webhooks.d.ts +24 -7
- package/types/apps/src/contracts/workflows.d.ts +56 -34
- package/types/apps/src/facet.d.ts +4 -5
- package/types/apps/src/host.d.ts +5 -0
- package/types/apps/src/implementation/account-router.d.ts +20 -3
- package/types/apps/src/implementation/app.d.ts +41 -14
- package/types/apps/src/implementation/authoring.d.ts +25 -5
- package/types/apps/src/implementation/browser-scripts.gen.d.ts +6 -0
- package/types/apps/src/implementation/cache.d.ts +29 -2
- package/types/apps/src/implementation/catalog-cache.d.ts +35 -4
- package/types/apps/src/implementation/elicitation.d.ts +16 -13
- package/types/apps/src/implementation/events.d.ts +64 -0
- package/types/apps/src/implementation/failure-detail.d.ts +28 -5
- package/types/apps/src/implementation/graphql-catalog.d.ts +3 -3
- package/types/apps/src/implementation/graphql.d.ts +4 -3
- package/types/apps/src/implementation/help-text.d.ts +5 -0
- package/types/apps/src/implementation/input-problems.d.ts +6 -2
- package/types/apps/src/implementation/invocation-timing.d.ts +18 -0
- 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 +6 -4
- package/types/apps/src/implementation/mcp-client.d.ts +17 -9
- package/types/apps/src/implementation/mcp-tools.d.ts +2 -1
- package/types/apps/src/implementation/mcp.d.ts +20 -9
- package/types/apps/src/implementation/network.d.ts +16 -0
- package/types/apps/src/implementation/openapi-compile.d.ts +38 -7
- package/types/apps/src/implementation/openapi-document.d.ts +50 -20
- 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 +23 -1
- package/types/apps/src/implementation/openapi-upgrade.d.ts +4 -0
- package/types/apps/src/implementation/operations.d.ts +58 -7
- package/types/apps/src/implementation/optimistic.d.ts +1 -1
- package/types/apps/src/implementation/placement.d.ts +60 -0
- package/types/apps/src/implementation/protocol-operations.d.ts +3 -0
- package/types/apps/src/implementation/provider-error.d.ts +28 -1
- package/types/apps/src/implementation/provider.d.ts +20 -4
- package/types/apps/src/implementation/query-commit.d.ts +1 -1
- package/types/apps/src/implementation/router-catalog.d.ts +22 -97
- package/types/apps/src/implementation/router.d.ts +26 -6
- package/types/apps/src/implementation/runtime-yield.d.ts +7 -0
- package/types/apps/src/implementation/schedules.d.ts +39 -8
- package/types/apps/src/implementation/schema.d.ts +125 -17
- package/types/apps/src/implementation/skills.d.ts +18 -24
- package/types/apps/src/implementation/sql.d.ts +71 -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 +3 -3
- 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 +38 -12
- package/types/apps/src/implementation/upstream-error.d.ts +17 -0
- package/types/apps/src/implementation/webhooks.d.ts +15 -6
- package/types/apps/src/implementation/workflow-context.d.ts +6 -2
- package/types/apps/src/implementation/workflows.d.ts +11 -4
- package/types/apps/src/index.d.ts +67 -17
- package/types/apps/src/mcp.d.ts +20 -1
- package/types/apps/src/openapi.d.ts +22 -1
- package/types/apps/src/react.d.ts +1 -1
- package/types/apps/src/skills.d.ts +10 -8
- package/types/apps/src/ui-serving.d.ts +1 -2
- package/types/telemetry/src/app-records.d.ts +42 -0
- package/types/telemetry/src/browser-operations.d.ts +2 -2
- package/types/telemetry/src/browser.d.ts +8 -3
- package/types/telemetry/src/config.d.ts +2 -2
- package/types/telemetry/src/index.d.ts +3 -2
- package/types/telemetry/src/keepalive.d.ts +36 -0
- package/types/telemetry/src/layer.d.ts +10 -4
- package/types/telemetry/src/measurements.d.ts +6 -2
- package/types/telemetry/src/ownership.d.ts +60 -0
- package/types/telemetry/src/recorded-failure.d.ts +29 -0
- package/types/telemetry/src/relay.d.ts +25 -7
- package/types/telemetry/src/span-attributes.d.ts +22 -3
- package/types/telemetry/src/transport.d.ts +8 -1
- package/types/utils/src/api-error.d.ts +55 -0
- package/types/utils/src/connection-failure.d.ts +33 -0
- package/types/utils/src/legacy-keys.d.ts +20 -0
- package/types/utils/src/random-uuid.d.ts +6 -0
- package/types/utils/src/recorded-message.d.ts +18 -0
- package/types/utils/src/schema-definitions.d.ts +13 -0
- package/types/utils/src/user-facing-error.d.ts +83 -0
- package/js/chunk-27F7W2LG.js +0 -34
- package/js/chunk-4ASNKGCV.js +0 -242
- package/js/chunk-4DWF4ZWI.js +0 -1280
- package/js/chunk-57RKNWL2.js +0 -75
- package/js/chunk-6HSH75OI.js +0 -2688
- package/js/chunk-G4FT53I7.js +0 -224
- package/js/chunk-MKWZPDR6.js +0 -63
- package/js/chunk-N7YDVXYJ.js +0 -186
- package/js/chunk-NKLWZJLE.js +0 -172
- package/js/chunk-PJJ24GU7.js +0 -877
- package/js/chunk-PZB6T6KU.js +0 -19
- package/js/chunk-R3EV5FTO.js +0 -97
- package/js/chunk-S73JGVR5.js +0 -507
- package/js/chunk-TG6DOCRO.js +0 -299
- package/js/chunk-YPKG2QO5.js +0 -209
- package/js/chunk-ZQINWV4W.js +0 -630
- package/js/mcp/stdio.js +0 -128
- 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 -18
- 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/storage.d.ts +0 -68
- package/types/apps/src/implementation/mcp-stdio.d.ts +0 -4
- package/types/apps/src/implementation/storage.d.ts +0 -15
- package/types/apps/src/implementation/ui-watch.d.ts +0 -2
- package/types/apps/src/mcp-stdio.d.ts +0 -5
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
import {
|
|
2
|
+
accountProviderError,
|
|
3
|
+
fromPromise
|
|
4
|
+
} from "./chunk-3ICMSVNC.js";
|
|
5
|
+
import {
|
|
6
|
+
HostedTool,
|
|
7
|
+
HostedToolSummary,
|
|
8
|
+
RouterKey,
|
|
9
|
+
RouterMeta,
|
|
10
|
+
reservedRouterKeys
|
|
11
|
+
} from "./chunk-7MPPHKRW.js";
|
|
12
|
+
import {
|
|
13
|
+
combineJsonSchemas,
|
|
14
|
+
decoderOf,
|
|
15
|
+
importedJsonSchema,
|
|
16
|
+
once,
|
|
17
|
+
schemaArgument,
|
|
18
|
+
withLazyJsonSchemaDocument
|
|
19
|
+
} from "./chunk-WXHRUWNT.js";
|
|
20
|
+
import {
|
|
21
|
+
JsonObject
|
|
22
|
+
} from "./chunk-H2K7OZ47.js";
|
|
23
|
+
import {
|
|
24
|
+
Effect_exports,
|
|
25
|
+
Result_exports,
|
|
26
|
+
Schema_exports
|
|
27
|
+
} from "./chunk-YFSOSNF3.js";
|
|
28
|
+
|
|
29
|
+
// src/implementation/operations.ts
|
|
30
|
+
var NativeOperation = /* @__PURE__ */ Symbol("apps.Operation");
|
|
31
|
+
var NativeRouterKey = /* @__PURE__ */ Symbol("apps.Router");
|
|
32
|
+
var operationDeclaration = (operation) => ({
|
|
33
|
+
kind: operation.kind,
|
|
34
|
+
[NativeOperation]: operation
|
|
35
|
+
});
|
|
36
|
+
var nativeOperation = (value) => {
|
|
37
|
+
if (typeof value !== "object" || value === null || !(NativeOperation in value)) return void 0;
|
|
38
|
+
return value[NativeOperation];
|
|
39
|
+
};
|
|
40
|
+
var operationOptions = (options) => {
|
|
41
|
+
const approval = options.approval;
|
|
42
|
+
return {
|
|
43
|
+
...options.description === void 0 ? {} : { description: options.description },
|
|
44
|
+
...options.title === void 0 ? {} : { title: options.title },
|
|
45
|
+
...options.annotations === void 0 ? {} : { annotations: options.annotations },
|
|
46
|
+
...options._meta === void 0 ? {} : { _meta: options._meta },
|
|
47
|
+
input: decoderOf(options.input),
|
|
48
|
+
...approval === void 0 ? {} : {
|
|
49
|
+
approval: (context) => fromPromise(async () => approval(context), "approval")()
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
var approvedOperation = (operation, approval) => {
|
|
54
|
+
const copy = Object.defineProperties({}, Object.getOwnPropertyDescriptors(operation));
|
|
55
|
+
return Object.defineProperty(copy, "approval", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
value: (context) => fromPromise(async () => approval(context), "approval")()
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
var withApproval = (operation, approval) => (
|
|
61
|
+
// SAFETY: `Approved` is a type-only mark; the native operation now carries the approval.
|
|
62
|
+
{
|
|
63
|
+
...operation,
|
|
64
|
+
[NativeOperation]: approvedOperation(operation[NativeOperation], approval)
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
var toolAnnotations = (operation) => nativeOperation(operation)?.annotations;
|
|
68
|
+
var make = (kind, options, run) => operationDeclaration({
|
|
69
|
+
...operationOptions({ ...options, input: schemaArgument(options.input, `The ${kind} input`) }),
|
|
70
|
+
kind,
|
|
71
|
+
// The host always validates JSON serialization, even without a stronger output declaration.
|
|
72
|
+
...options.output === void 0 ? {} : { output: decoderOf(schemaArgument(options.output, `The ${kind} output`)) },
|
|
73
|
+
// SAFETY: defineApp checks the handler context against its requirements.
|
|
74
|
+
// The host validates account bindings and creates the matching storage facade.
|
|
75
|
+
run: (context, input) => fromPromise(run, "handler")(context, input)
|
|
76
|
+
});
|
|
77
|
+
var query = (options, run) => make("query", options, run);
|
|
78
|
+
function mutation(options, run) {
|
|
79
|
+
return make("mutation", options, run);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/implementation/router.ts
|
|
83
|
+
var routerDeclaration = (node) => ({
|
|
84
|
+
[NativeRouterKey]: node
|
|
85
|
+
});
|
|
86
|
+
var nativeRouter = (value) => {
|
|
87
|
+
if (typeof value !== "object" || value === null || !(NativeRouterKey in value)) return void 0;
|
|
88
|
+
return value[NativeRouterKey];
|
|
89
|
+
};
|
|
90
|
+
var nativeNode = (value) => nativeOperation(value) ?? nativeRouter(value);
|
|
91
|
+
var metaOf = (options) => {
|
|
92
|
+
if (options === void 0) return void 0;
|
|
93
|
+
const defined = Object.fromEntries(
|
|
94
|
+
Object.entries(options).filter(([, value]) => value !== void 0)
|
|
95
|
+
);
|
|
96
|
+
return Object.keys(defined).length === 0 ? void 0 : Schema_exports.decodeUnknownSync(RouterMeta)(defined);
|
|
97
|
+
};
|
|
98
|
+
var mergeMeta = (base, override) => base === void 0 ? override : override === void 0 ? base : { ...base, ...override };
|
|
99
|
+
function router(children, options) {
|
|
100
|
+
const meta = metaOf(options);
|
|
101
|
+
const existing = nativeRouter(children);
|
|
102
|
+
if (existing !== void 0)
|
|
103
|
+
return routerDeclaration(
|
|
104
|
+
existing.kind === "router" ? { ...existing, ...withMeta(mergeMeta(existing.meta, meta)) } : { ...existing, ...withOverrides(mergeMeta(existing.overrides, meta)) }
|
|
105
|
+
);
|
|
106
|
+
const nodes = {};
|
|
107
|
+
for (const [key, value] of Object.entries(children)) {
|
|
108
|
+
if (reservedRouterKeys.has(key)) throw new Error(`Router key "${key}" is reserved`);
|
|
109
|
+
if (!Schema_exports.is(RouterKey)(key))
|
|
110
|
+
throw new Error(`Router key "${key}" must start with a letter or _ and contain no dots`);
|
|
111
|
+
const node = nativeNode(value);
|
|
112
|
+
if (node === void 0)
|
|
113
|
+
throw new Error(`Router key "${key}" must be a query, mutation or router`);
|
|
114
|
+
nodes[key] = node;
|
|
115
|
+
}
|
|
116
|
+
return routerDeclaration({ kind: "router", ...withMeta(meta), children: nodes });
|
|
117
|
+
}
|
|
118
|
+
var withMeta = (meta) => meta === void 0 ? {} : { meta };
|
|
119
|
+
var withOverrides = (overrides) => overrides === void 0 ? {} : { overrides };
|
|
120
|
+
var dynamicRouter = (source) => {
|
|
121
|
+
const meta = source.meta;
|
|
122
|
+
return routerDeclaration({
|
|
123
|
+
kind: "dynamic",
|
|
124
|
+
...meta === void 0 ? {} : {
|
|
125
|
+
meta: () => fromPromise(async () => meta(), "router")().pipe(
|
|
126
|
+
Effect_exports.flatMap((options) => Schema_exports.decodeUnknownEffect(RouterMeta)(options))
|
|
127
|
+
)
|
|
128
|
+
},
|
|
129
|
+
list: () => fromPromise(async () => source.list(), "router")().pipe(
|
|
130
|
+
Effect_exports.flatMap(Schema_exports.decodeUnknownEffect(Schema_exports.Array(HostedTool)))
|
|
131
|
+
),
|
|
132
|
+
resolve: (name) => fromPromise(async () => source.resolve(name), "router")().pipe(
|
|
133
|
+
Effect_exports.map((value) => {
|
|
134
|
+
if (value === void 0) return void 0;
|
|
135
|
+
const operation = nativeOperation(value);
|
|
136
|
+
if (operation === void 0) throw new Error("Expected an operation declaration");
|
|
137
|
+
return operation;
|
|
138
|
+
})
|
|
139
|
+
)
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
var joinPath = (path, name) => path === "" ? name : `${path}.${name}`;
|
|
143
|
+
var locate = (root, name) => {
|
|
144
|
+
if (root?.kind === "dynamic") return { kind: "dynamic", source: root, router: "", name };
|
|
145
|
+
let current = root;
|
|
146
|
+
let path = "";
|
|
147
|
+
let rest = name;
|
|
148
|
+
while (current !== void 0) {
|
|
149
|
+
const dot = rest.indexOf(".");
|
|
150
|
+
const key = dot < 0 ? rest : rest.slice(0, dot);
|
|
151
|
+
const child = Object.hasOwn(current.children, key) ? current.children[key] : void 0;
|
|
152
|
+
if (child === void 0) return void 0;
|
|
153
|
+
const remaining = dot < 0 ? void 0 : rest.slice(dot + 1);
|
|
154
|
+
switch (child.kind) {
|
|
155
|
+
case "query":
|
|
156
|
+
case "mutation":
|
|
157
|
+
return remaining === void 0 ? { kind: "operation", operation: child, router: path } : void 0;
|
|
158
|
+
case "dynamic":
|
|
159
|
+
return remaining === void 0 || remaining === "" ? void 0 : { kind: "dynamic", source: child, router: joinPath(path, key), name: remaining };
|
|
160
|
+
case "router":
|
|
161
|
+
if (remaining === void 0) return void 0;
|
|
162
|
+
current = child;
|
|
163
|
+
path = joinPath(path, key);
|
|
164
|
+
rest = remaining;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return void 0;
|
|
168
|
+
};
|
|
169
|
+
var declaredOperations = (root, path = "") => Object.entries(root?.children ?? {}).flatMap(([key, child]) => {
|
|
170
|
+
const name = joinPath(path, key);
|
|
171
|
+
switch (child.kind) {
|
|
172
|
+
case "query":
|
|
173
|
+
case "mutation":
|
|
174
|
+
return [{ name, router: path, operation: child }];
|
|
175
|
+
case "router":
|
|
176
|
+
return declaredOperations(child, name);
|
|
177
|
+
case "dynamic":
|
|
178
|
+
return [];
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
var withApprovals = (source, policy) => {
|
|
182
|
+
const native = nativeRouter(source);
|
|
183
|
+
if (native === void 0) throw new Error("withApprovals expects a router");
|
|
184
|
+
const operation = (node, name) => {
|
|
185
|
+
const approval = policy(operationDeclaration(node), name);
|
|
186
|
+
return approval === void 0 ? node : approvedOperation(node, approval);
|
|
187
|
+
};
|
|
188
|
+
const child = (node, name) => {
|
|
189
|
+
switch (node.kind) {
|
|
190
|
+
case "query":
|
|
191
|
+
case "mutation":
|
|
192
|
+
return operation(node, name);
|
|
193
|
+
case "router":
|
|
194
|
+
case "dynamic":
|
|
195
|
+
return walk(node, name);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
const walk = (node, path) => node.kind === "dynamic" ? {
|
|
199
|
+
...node,
|
|
200
|
+
resolve: (name) => node.resolve(name).pipe(
|
|
201
|
+
Effect_exports.flatMap(
|
|
202
|
+
(resolved) => resolved === void 0 ? Effect_exports.succeed(void 0) : Effect_exports.try({
|
|
203
|
+
try: () => operation(resolved, joinPath(path, name)),
|
|
204
|
+
catch: (error) => error
|
|
205
|
+
})
|
|
206
|
+
)
|
|
207
|
+
)
|
|
208
|
+
} : {
|
|
209
|
+
...node,
|
|
210
|
+
children: Object.fromEntries(
|
|
211
|
+
Object.entries(node.children).map(([key, value]) => [
|
|
212
|
+
key,
|
|
213
|
+
child(value, joinPath(path, key))
|
|
214
|
+
])
|
|
215
|
+
)
|
|
216
|
+
};
|
|
217
|
+
return routerDeclaration(walk(native, ""));
|
|
218
|
+
};
|
|
219
|
+
var renameTools = (source, rename) => {
|
|
220
|
+
const native = nativeRouter(source);
|
|
221
|
+
if (native?.kind !== "dynamic") throw new Error("renameTools expects a protocol router");
|
|
222
|
+
const exposed = (tools) => {
|
|
223
|
+
const seen = /* @__PURE__ */ new Set();
|
|
224
|
+
return tools.flatMap((tool) => {
|
|
225
|
+
const name = rename(tool.name);
|
|
226
|
+
if (name === void 0 || seen.has(name)) return [];
|
|
227
|
+
seen.add(name);
|
|
228
|
+
return [{ ...tool, name, source: tool.name }];
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
const listed = native.summaries ?? native.list;
|
|
232
|
+
const original = (name) => listed().pipe(Effect_exports.map((tools) => exposed(tools).find((tool) => tool.name === name)?.source));
|
|
233
|
+
const strip = ({
|
|
234
|
+
source: _source,
|
|
235
|
+
...tool
|
|
236
|
+
}) => tool;
|
|
237
|
+
return routerDeclaration({
|
|
238
|
+
...native,
|
|
239
|
+
list: () => native.list().pipe(Effect_exports.map((tools) => exposed(tools).map(strip))),
|
|
240
|
+
...native.summaries === void 0 ? {} : {
|
|
241
|
+
summaries: () => listed().pipe(Effect_exports.map((tools) => exposed(tools).map(strip)))
|
|
242
|
+
},
|
|
243
|
+
describe: (name) => original(name).pipe(
|
|
244
|
+
Effect_exports.flatMap(
|
|
245
|
+
(found) => found === void 0 ? Effect_exports.succeed(void 0) : native.describe?.(found) ?? native.list().pipe(Effect_exports.map((tools) => tools.find((tool) => tool.name === found)))
|
|
246
|
+
),
|
|
247
|
+
Effect_exports.map((tool) => tool === void 0 ? void 0 : { ...tool, name })
|
|
248
|
+
),
|
|
249
|
+
resolve: (name) => original(name).pipe(
|
|
250
|
+
Effect_exports.flatMap(
|
|
251
|
+
(found) => found === void 0 ? Effect_exports.succeed(void 0) : native.resolve(found)
|
|
252
|
+
)
|
|
253
|
+
)
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
// src/implementation/account-router.ts
|
|
258
|
+
var PartialListing = class extends Schema_exports.TaggedError()("PartialListing", {
|
|
259
|
+
tools: Schema_exports.Array(Schema_exports.Unknown),
|
|
260
|
+
error: Schema_exports.Unknown
|
|
261
|
+
}) {
|
|
262
|
+
};
|
|
263
|
+
var decoderDocument = (decoder) => {
|
|
264
|
+
const imported = importedJsonSchema(decoder);
|
|
265
|
+
if (imported !== void 0) return Schema_exports.decodeUnknownSync(JsonObject)(imported);
|
|
266
|
+
const document = Schema_exports.toJsonSchemaDocument(decoder);
|
|
267
|
+
return Schema_exports.decodeUnknownSync(JsonObject)({ ...document.schema, $defs: document.definitions });
|
|
268
|
+
};
|
|
269
|
+
var accountBranches = (variants) => {
|
|
270
|
+
const groups = /* @__PURE__ */ new Map();
|
|
271
|
+
for (const [accountId, schema] of variants) {
|
|
272
|
+
const key = JSON.stringify(schema);
|
|
273
|
+
const group = groups.get(key);
|
|
274
|
+
if (group === void 0) groups.set(key, { schema, first: accountId, rest: [] });
|
|
275
|
+
else group.rest.push(accountId);
|
|
276
|
+
}
|
|
277
|
+
const branches = [...groups.values()];
|
|
278
|
+
const { $defs, schemas } = combineJsonSchemas(
|
|
279
|
+
branches.map(({ schema }) => schema),
|
|
280
|
+
(index) => `#/anyOf/${index}/properties/input`
|
|
281
|
+
);
|
|
282
|
+
return {
|
|
283
|
+
type: "object",
|
|
284
|
+
...$defs === void 0 ? {} : { $defs },
|
|
285
|
+
anyOf: schemas.map((input, index) => {
|
|
286
|
+
const { first, rest } = branches[index];
|
|
287
|
+
return {
|
|
288
|
+
type: "object",
|
|
289
|
+
properties: {
|
|
290
|
+
accountId: rest.length === 0 ? { type: "string", const: first } : { type: "string", enum: [first, ...rest] },
|
|
291
|
+
input
|
|
292
|
+
},
|
|
293
|
+
required: ["accountId", "input"]
|
|
294
|
+
};
|
|
295
|
+
})
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
var outputBranches = (outputs) => {
|
|
299
|
+
const { $defs, schemas } = combineJsonSchemas(
|
|
300
|
+
[...new Map(outputs.map((output) => [JSON.stringify(output), output])).values()],
|
|
301
|
+
(index) => `#/anyOf/${index}`
|
|
302
|
+
);
|
|
303
|
+
return { ...$defs === void 0 ? {} : { $defs }, anyOf: schemas };
|
|
304
|
+
};
|
|
305
|
+
var declaresOutput = (operation) => {
|
|
306
|
+
if (operation.output !== void 0) return true;
|
|
307
|
+
const property = Object.getOwnPropertyDescriptor(operation, "outputSchema");
|
|
308
|
+
return property !== void 0 && (property.get !== void 0 || property.value !== void 0);
|
|
309
|
+
};
|
|
310
|
+
var outputDocument = (operation) => operation.output === void 0 ? operation.outputSchema : decoderDocument(operation.output);
|
|
311
|
+
var combineOperation = (accounts, failed = /* @__PURE__ */ new Map()) => {
|
|
312
|
+
const variants = [...accounts.values()];
|
|
313
|
+
const first = variants[0];
|
|
314
|
+
if (first === void 0) throw new Error("An account operation must have at least one account");
|
|
315
|
+
const kind = variants.every((operation) => operation.kind === "query") ? "query" : "mutation";
|
|
316
|
+
const select = (input2) => {
|
|
317
|
+
const operation = accounts.get(input2.accountId);
|
|
318
|
+
if (operation === void 0)
|
|
319
|
+
throw new Error("Account selection must be decoded before execution");
|
|
320
|
+
return operation;
|
|
321
|
+
};
|
|
322
|
+
const input = Schema_exports.Union([
|
|
323
|
+
...[...accounts].map(
|
|
324
|
+
([accountId, operation]) => Schema_exports.Struct({ accountId: Schema_exports.Literal(accountId), input: operation.input })
|
|
325
|
+
),
|
|
326
|
+
...[...failed.keys()].map(
|
|
327
|
+
(accountId) => Schema_exports.Struct({ accountId: Schema_exports.Literal(accountId), input: Schema_exports.Unknown })
|
|
328
|
+
)
|
|
329
|
+
]);
|
|
330
|
+
const inputSchema = () => accountBranches(
|
|
331
|
+
[...accounts].map(([accountId, operation]) => [accountId, decoderDocument(operation.input)])
|
|
332
|
+
);
|
|
333
|
+
const declaration = operationDeclaration({
|
|
334
|
+
kind,
|
|
335
|
+
...first.description === void 0 ? {} : { description: first.description },
|
|
336
|
+
...first.title === void 0 ? {} : { title: first.title },
|
|
337
|
+
...first.annotations === void 0 || !variants.every(
|
|
338
|
+
(operation) => JSON.stringify(operation.annotations) === JSON.stringify(first.annotations)
|
|
339
|
+
) ? {} : { annotations: first.annotations },
|
|
340
|
+
...first._meta === void 0 || !variants.every((operation) => JSON.stringify(operation._meta) === JSON.stringify(first._meta)) ? {} : { _meta: first._meta },
|
|
341
|
+
input: withLazyJsonSchemaDocument(input, inputSchema),
|
|
342
|
+
approval: (context) => {
|
|
343
|
+
if (failed.has(context.toolInput.accountId)) return Effect_exports.succeed("approved");
|
|
344
|
+
const operation = select(context.toolInput);
|
|
345
|
+
return operation.approval === void 0 ? Effect_exports.succeed("approved") : operation.approval({ ...context, toolInput: context.toolInput.input });
|
|
346
|
+
},
|
|
347
|
+
run: (context, input2) => {
|
|
348
|
+
if (failed.has(input2.accountId))
|
|
349
|
+
return Effect_exports.fail(accountProviderError(failed.get(input2.accountId), input2.accountId));
|
|
350
|
+
const operation = select(input2);
|
|
351
|
+
return operation.run(context, input2.input).pipe(
|
|
352
|
+
Effect_exports.mapError((error) => accountProviderError(error, input2.accountId)),
|
|
353
|
+
Effect_exports.flatMap(
|
|
354
|
+
(output) => operation.output === void 0 ? Effect_exports.succeed(output) : Schema_exports.decodeUnknownEffect(operation.output)(output)
|
|
355
|
+
)
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
if (variants.every(declaresOutput)) {
|
|
360
|
+
const outputSchema = once(
|
|
361
|
+
() => outputBranches(
|
|
362
|
+
variants.flatMap((operation) => {
|
|
363
|
+
const output = outputDocument(operation);
|
|
364
|
+
return output === void 0 ? [] : [output];
|
|
365
|
+
})
|
|
366
|
+
)
|
|
367
|
+
);
|
|
368
|
+
const native2 = nativeOperation(declaration);
|
|
369
|
+
if (native2 !== void 0)
|
|
370
|
+
Object.defineProperty(native2, "outputSchema", { enumerable: true, get: outputSchema });
|
|
371
|
+
}
|
|
372
|
+
const native = nativeOperation(declaration);
|
|
373
|
+
if (native === void 0) throw new Error("Expected a combined operation");
|
|
374
|
+
return native;
|
|
375
|
+
};
|
|
376
|
+
var sameAcross = (key, variants) => {
|
|
377
|
+
const first = variants[0]?.[1][key];
|
|
378
|
+
return first !== void 0 && variants.every(([, tool]) => JSON.stringify(tool[key]) === JSON.stringify(first)) ? { [key]: first } : {};
|
|
379
|
+
};
|
|
380
|
+
var mergeSummary = (name, variants) => {
|
|
381
|
+
const first = variants[0]?.[1];
|
|
382
|
+
if (first === void 0) throw new Error("Expected a source operation");
|
|
383
|
+
return Schema_exports.decodeUnknownSync(HostedToolSummary)({
|
|
384
|
+
name,
|
|
385
|
+
description: first.description,
|
|
386
|
+
...first.title === void 0 ? {} : { title: first.title },
|
|
387
|
+
readOnly: variants.every(([, tool]) => tool.readOnly === true),
|
|
388
|
+
...variants.every(([, tool]) => tool.kindConfirmed === true) ? { kindConfirmed: true } : {},
|
|
389
|
+
...sameAcross("annotations", variants)
|
|
390
|
+
});
|
|
391
|
+
};
|
|
392
|
+
var merge = (name, variants) => Schema_exports.decodeUnknownSync(HostedTool)({
|
|
393
|
+
...mergeSummary(name, variants),
|
|
394
|
+
inputSchema: accountBranches(
|
|
395
|
+
variants.map(([accountId, tool]) => [accountId, tool.inputSchema])
|
|
396
|
+
),
|
|
397
|
+
...variants.every(([, tool]) => tool.outputSchema !== void 0) ? {
|
|
398
|
+
outputSchema: outputBranches(
|
|
399
|
+
variants.flatMap(
|
|
400
|
+
([, tool]) => tool.outputSchema === void 0 ? [] : [tool.outputSchema]
|
|
401
|
+
)
|
|
402
|
+
)
|
|
403
|
+
} : {},
|
|
404
|
+
...sameAcross("_meta", variants)
|
|
405
|
+
});
|
|
406
|
+
var accountConcurrency = 8;
|
|
407
|
+
var eachAccount = (sources, read) => Effect_exports.gen(function* () {
|
|
408
|
+
const results = yield* Effect_exports.forEach(
|
|
409
|
+
sources,
|
|
410
|
+
([accountId, source]) => Effect_exports.result(
|
|
411
|
+
read(source).pipe(Effect_exports.mapError((error) => accountProviderError(error, accountId)))
|
|
412
|
+
).pipe(Effect_exports.map((result) => [accountId, result])),
|
|
413
|
+
{ concurrency: accountConcurrency }
|
|
414
|
+
);
|
|
415
|
+
const values = /* @__PURE__ */ new Map();
|
|
416
|
+
const failed = /* @__PURE__ */ new Map();
|
|
417
|
+
for (const [accountId, result] of results)
|
|
418
|
+
if (Result_exports.isSuccess(result)) values.set(accountId, result.success);
|
|
419
|
+
else failed.set(accountId, result.failure);
|
|
420
|
+
return { values, failed };
|
|
421
|
+
});
|
|
422
|
+
var firstFailure = (failed) => [...failed.values()][0];
|
|
423
|
+
var combineDynamic = (sources) => {
|
|
424
|
+
const first = [...sources.values()][0];
|
|
425
|
+
const grouped = (read, merged) => Effect_exports.gen(function* () {
|
|
426
|
+
const { values: listed, failed } = yield* eachAccount(sources, read);
|
|
427
|
+
if (listed.size === 0 && failed.size > 0) return yield* Effect_exports.fail(firstFailure(failed));
|
|
428
|
+
const groups = /* @__PURE__ */ new Map();
|
|
429
|
+
for (const [accountId, tools2] of listed)
|
|
430
|
+
for (const tool of tools2) {
|
|
431
|
+
const variants = groups.get(tool.name) ?? [];
|
|
432
|
+
if (variants.some(([id]) => id === accountId))
|
|
433
|
+
return yield* Effect_exports.die(new Error("Duplicate source operation"));
|
|
434
|
+
variants.push([accountId, tool]);
|
|
435
|
+
groups.set(tool.name, variants);
|
|
436
|
+
}
|
|
437
|
+
const tools = [...groups].map(([name, variants]) => merged(name, variants));
|
|
438
|
+
if (failed.size === 0) return tools;
|
|
439
|
+
return yield* new PartialListing({ tools, error: firstFailure(failed) });
|
|
440
|
+
});
|
|
441
|
+
return {
|
|
442
|
+
kind: "dynamic",
|
|
443
|
+
// Accounts share one source, so the first account that can describe it describes the router.
|
|
444
|
+
...first?.meta === void 0 ? {} : {
|
|
445
|
+
meta: () => Effect_exports.gen(function* () {
|
|
446
|
+
const failures = [];
|
|
447
|
+
for (const source of sources.values()) {
|
|
448
|
+
if (source.meta === void 0) continue;
|
|
449
|
+
const result = yield* Effect_exports.result(source.meta());
|
|
450
|
+
if (Result_exports.isSuccess(result)) return result.success;
|
|
451
|
+
failures.push(result.failure);
|
|
452
|
+
}
|
|
453
|
+
return yield* Effect_exports.fail(failures[0]);
|
|
454
|
+
})
|
|
455
|
+
},
|
|
456
|
+
...first?.overrides === void 0 ? {} : { overrides: first.overrides },
|
|
457
|
+
list: () => grouped((source) => source.list(), merge),
|
|
458
|
+
summaries: () => grouped(
|
|
459
|
+
(source) => source.summaries === void 0 ? source.list() : source.summaries(),
|
|
460
|
+
mergeSummary
|
|
461
|
+
),
|
|
462
|
+
describe: (name) => eachAccount(
|
|
463
|
+
sources,
|
|
464
|
+
(source) => source.describe === void 0 ? source.list().pipe(Effect_exports.map((tools) => tools.find((tool) => tool.name === name))) : source.describe(name)
|
|
465
|
+
).pipe(
|
|
466
|
+
Effect_exports.flatMap(({ values, failed }) => {
|
|
467
|
+
const variants = [...values].flatMap(
|
|
468
|
+
([accountId, tool]) => tool === void 0 ? [] : [[accountId, tool]]
|
|
469
|
+
);
|
|
470
|
+
if (variants.length === 0)
|
|
471
|
+
return failed.size > 0 ? Effect_exports.fail(firstFailure(failed)) : Effect_exports.succeed(void 0);
|
|
472
|
+
return Effect_exports.succeed(merge(name, variants));
|
|
473
|
+
})
|
|
474
|
+
),
|
|
475
|
+
resolve: (name) => eachAccount(sources, (source) => source.resolve(name)).pipe(
|
|
476
|
+
Effect_exports.flatMap(({ values, failed }) => {
|
|
477
|
+
const operations = new Map(
|
|
478
|
+
[...values].flatMap(
|
|
479
|
+
([accountId, operation]) => operation === void 0 ? [] : [[accountId, operation]]
|
|
480
|
+
)
|
|
481
|
+
);
|
|
482
|
+
if (operations.size === 0)
|
|
483
|
+
return failed.size > 0 ? Effect_exports.fail(firstFailure(failed)) : Effect_exports.succeed(void 0);
|
|
484
|
+
return Effect_exports.succeed(combineOperation(operations, failed));
|
|
485
|
+
})
|
|
486
|
+
)
|
|
487
|
+
};
|
|
488
|
+
};
|
|
489
|
+
var combineNode = (variants) => {
|
|
490
|
+
const nodes = [...variants.values()];
|
|
491
|
+
const first = nodes[0];
|
|
492
|
+
if (first === void 0) throw new Error("An account operation must have at least one account");
|
|
493
|
+
switch (first.kind) {
|
|
494
|
+
case "query":
|
|
495
|
+
case "mutation":
|
|
496
|
+
return combineOperation(
|
|
497
|
+
narrow(
|
|
498
|
+
variants,
|
|
499
|
+
(node) => node.kind === "query" || node.kind === "mutation"
|
|
500
|
+
)
|
|
501
|
+
);
|
|
502
|
+
case "dynamic":
|
|
503
|
+
return combineDynamic(
|
|
504
|
+
narrow(variants, (node) => node.kind === "dynamic")
|
|
505
|
+
);
|
|
506
|
+
case "router": {
|
|
507
|
+
const routers = narrow(variants, (node) => node.kind === "router");
|
|
508
|
+
const keys = new Set([...routers.values()].flatMap((router2) => Object.keys(router2.children)));
|
|
509
|
+
return {
|
|
510
|
+
kind: "router",
|
|
511
|
+
...first.meta === void 0 ? {} : { meta: first.meta },
|
|
512
|
+
children: Object.fromEntries(
|
|
513
|
+
[...keys].map((key) => {
|
|
514
|
+
const children = /* @__PURE__ */ new Map();
|
|
515
|
+
for (const [accountId, router2] of routers) {
|
|
516
|
+
const child = Object.hasOwn(router2.children, key) ? router2.children[key] : void 0;
|
|
517
|
+
if (child !== void 0) children.set(accountId, child);
|
|
518
|
+
}
|
|
519
|
+
return [key, combineNode(children)];
|
|
520
|
+
})
|
|
521
|
+
)
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
var narrow = (variants, is) => {
|
|
527
|
+
const narrowed = /* @__PURE__ */ new Map();
|
|
528
|
+
for (const [accountId, node] of variants) {
|
|
529
|
+
if (!is(node)) throw new Error("Each account's router must have the same shape");
|
|
530
|
+
narrowed.set(accountId, node);
|
|
531
|
+
}
|
|
532
|
+
return narrowed;
|
|
533
|
+
};
|
|
534
|
+
var accountRouter = (accounts, discover, options) => Effect_exports.runPromise(
|
|
535
|
+
Effect_exports.gen(function* () {
|
|
536
|
+
const routers = /* @__PURE__ */ new Map();
|
|
537
|
+
for (const account of accounts) {
|
|
538
|
+
const declaration = yield* Effect_exports.tryPromise({
|
|
539
|
+
try: async () => discover(account),
|
|
540
|
+
catch: (error) => accountProviderError(error, account.id)
|
|
541
|
+
});
|
|
542
|
+
if (routers.has(account.id))
|
|
543
|
+
return yield* Effect_exports.die(new Error("Account selections must be unique"));
|
|
544
|
+
const router2 = nativeRouter(declaration);
|
|
545
|
+
if (router2 === void 0) return yield* Effect_exports.die(new Error("Expected a protocol router"));
|
|
546
|
+
routers.set(account.id, router2);
|
|
547
|
+
}
|
|
548
|
+
if (routers.size === 0) return routerDeclaration({ kind: "router", children: {} });
|
|
549
|
+
const combined = combineNode(routers);
|
|
550
|
+
if (combined.kind !== "router" && combined.kind !== "dynamic")
|
|
551
|
+
return yield* Effect_exports.die(new Error("Expected a protocol router"));
|
|
552
|
+
return routerDeclaration(combined);
|
|
553
|
+
}),
|
|
554
|
+
options
|
|
555
|
+
);
|
|
556
|
+
|
|
557
|
+
export {
|
|
558
|
+
operationDeclaration,
|
|
559
|
+
nativeOperation,
|
|
560
|
+
withApproval,
|
|
561
|
+
toolAnnotations,
|
|
562
|
+
query,
|
|
563
|
+
mutation,
|
|
564
|
+
routerDeclaration,
|
|
565
|
+
nativeRouter,
|
|
566
|
+
mergeMeta,
|
|
567
|
+
router,
|
|
568
|
+
dynamicRouter,
|
|
569
|
+
joinPath,
|
|
570
|
+
locate,
|
|
571
|
+
declaredOperations,
|
|
572
|
+
withApprovals,
|
|
573
|
+
renameTools,
|
|
574
|
+
PartialListing,
|
|
575
|
+
accountRouter
|
|
576
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Predicate_exports
|
|
3
|
+
} from "./chunk-YFSOSNF3.js";
|
|
4
|
+
|
|
5
|
+
// ../utils/src/recorded-message.ts
|
|
6
|
+
var RecordedMessage = /* @__PURE__ */ Symbol.for("@executor-js/utils/RecordedMessage");
|
|
7
|
+
var recordedMessage = (error) => {
|
|
8
|
+
if (Predicate_exports.hasProperty(error, RecordedMessage)) {
|
|
9
|
+
const message = error[RecordedMessage];
|
|
10
|
+
return typeof message === "string" ? message : void 0;
|
|
11
|
+
}
|
|
12
|
+
return protocolErrorMessage(error) ?? sqlErrorMessage(error);
|
|
13
|
+
};
|
|
14
|
+
var jsonRpcMeanings = {
|
|
15
|
+
[-32700]: "Parse error",
|
|
16
|
+
[-32600]: "Invalid request",
|
|
17
|
+
[-32601]: "Method not found",
|
|
18
|
+
[-32602]: "Invalid params",
|
|
19
|
+
[-32603]: "Internal error",
|
|
20
|
+
[-32002]: "Resource not found"
|
|
21
|
+
};
|
|
22
|
+
var protocolErrorMessage = (error) => {
|
|
23
|
+
if (!Predicate_exports.isTagged(error, "ProtocolError") || !Predicate_exports.hasProperty(error, "code") || typeof error.code !== "number" || !Predicate_exports.hasProperty(error, "message") || !Predicate_exports.isString(error.message))
|
|
24
|
+
return void 0;
|
|
25
|
+
const code = error.code;
|
|
26
|
+
const refusal = /^Tool '.*' not found$/s.test(error.message) ? ": the requested tool does not exist" : error.message.startsWith("Invalid parameters for tool '") ? ": the tool's arguments failed validation" : "";
|
|
27
|
+
const meaning = jsonRpcMeanings[code];
|
|
28
|
+
const kind = meaning === void 0 ? "JSON-RPC error with an unlisted code" : `${meaning} (${code})`;
|
|
29
|
+
return kind + refusal;
|
|
30
|
+
};
|
|
31
|
+
var sqlReasons = /* @__PURE__ */ new Set([
|
|
32
|
+
"ConnectionError",
|
|
33
|
+
"AuthenticationError",
|
|
34
|
+
"AuthorizationError",
|
|
35
|
+
"SqlSyntaxError",
|
|
36
|
+
"UniqueViolation",
|
|
37
|
+
"ConstraintError",
|
|
38
|
+
"DeadlockError",
|
|
39
|
+
"SerializationError",
|
|
40
|
+
"LockTimeoutError",
|
|
41
|
+
"StatementTimeoutError",
|
|
42
|
+
"UnknownError"
|
|
43
|
+
]);
|
|
44
|
+
var sqlMessages = new Set(
|
|
45
|
+
[
|
|
46
|
+
"A pipelined query completed out of order",
|
|
47
|
+
"Connection closed",
|
|
48
|
+
"Connection closed during startup",
|
|
49
|
+
"Connection is closed",
|
|
50
|
+
"Connection timed out",
|
|
51
|
+
"Failed to connect",
|
|
52
|
+
"Failed to decode row",
|
|
53
|
+
"Failed to encode query",
|
|
54
|
+
"Failed to negotiate TLS",
|
|
55
|
+
"Failed to parse SSLRequest error response",
|
|
56
|
+
"Failed to parse server messages",
|
|
57
|
+
"Failed to parse server response",
|
|
58
|
+
"Failed to write query",
|
|
59
|
+
"Failed to write query batch",
|
|
60
|
+
"Invalid SSLRequest response",
|
|
61
|
+
"MD5 authentication failed",
|
|
62
|
+
"No password configured",
|
|
63
|
+
"Protocol desync",
|
|
64
|
+
"Query cancellation timed out",
|
|
65
|
+
"Query failed",
|
|
66
|
+
"SCRAM authentication failed",
|
|
67
|
+
"SCRAM exchange did not complete",
|
|
68
|
+
"SCRAM server verification failed",
|
|
69
|
+
"Server refused TLS",
|
|
70
|
+
"Socket error",
|
|
71
|
+
"Stream cancellation timed out",
|
|
72
|
+
"The server reported an error",
|
|
73
|
+
"Unsupported authentication method"
|
|
74
|
+
].map((message) => `PgConnection: ${message}`)
|
|
75
|
+
);
|
|
76
|
+
var sqlErrorMessage = (error) => {
|
|
77
|
+
if (!Predicate_exports.isTagged(error, "SqlError") || !Predicate_exports.hasProperty(error, "reason"))
|
|
78
|
+
return void 0;
|
|
79
|
+
const reason = error.reason;
|
|
80
|
+
const kind = Predicate_exports.hasProperty(reason, "_tag") && Predicate_exports.isString(reason._tag) && sqlReasons.has(reason._tag) ? reason._tag : "an unlisted kind";
|
|
81
|
+
const message = Predicate_exports.hasProperty(reason, "message") && Predicate_exports.isString(reason.message) && sqlMessages.has(reason.message) ? `: ${reason.message}` : "";
|
|
82
|
+
return `The database failed (${kind})${message}`;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export {
|
|
86
|
+
RecordedMessage,
|
|
87
|
+
recordedMessage
|
|
88
|
+
};
|