apps 1.0.0-beta.4 → 2.0.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +10 -48
  2. package/check-publish.mjs +7 -0
  3. package/package.json +27 -56
  4. package/src/Access.ts +37 -0
  5. package/src/Accounts.ts +468 -0
  6. package/src/App.ts +11 -0
  7. package/src/Ask.ts +156 -0
  8. package/src/Changes.ts +13 -0
  9. package/src/Http.ts +30 -0
  10. package/src/Provider.ts +146 -0
  11. package/src/Session.ts +52 -0
  12. package/src/Settings.ts +164 -0
  13. package/src/contract.ts +852 -0
  14. package/src/css-modules.d.ts +2 -0
  15. package/src/desktop/Desktop.ts +192 -0
  16. package/src/desktop/bridge.ts +62 -0
  17. package/src/desktop/errors.ts +88 -0
  18. package/src/desktop/index.ts +15 -0
  19. package/src/entry.ts +48 -0
  20. package/src/index.ts +16 -4
  21. package/src/internal/defects.ts +62 -0
  22. package/src/internal/files.ts +369 -0
  23. package/src/internal/host.ts +17 -0
  24. package/src/internal/query.ts +114 -0
  25. package/src/internal/records.ts +838 -0
  26. package/src/internal/retention.ts +87 -0
  27. package/src/internal/retries.ts +185 -0
  28. package/src/internal/telemetry.ts +167 -0
  29. package/src/migrations.ts +110 -0
  30. package/src/page/Accounts.ts +27 -0
  31. package/src/page/Changes.ts +126 -0
  32. package/src/page/Session.ts +46 -0
  33. package/src/page/client.ts +107 -0
  34. package/src/page/errors.ts +15 -0
  35. package/src/page/http.ts +21 -0
  36. package/src/page/index.ts +18 -0
  37. package/src/page/paths.ts +22 -0
  38. package/src/providers/anthropic.ts +26 -0
  39. package/src/providers/github.ts +49 -0
  40. package/src/providers/google.ts +67 -0
  41. package/src/providers/openai.ts +62 -0
  42. package/src/providers/slack.ts +81 -0
  43. package/src/runtime.ts +1540 -0
  44. package/src/testing.ts +660 -0
  45. package/src/text-modules.d.ts +5 -0
  46. package/src/theme.css +50 -0
  47. package/dist/authoring/index.d.ts +0 -422
  48. package/dist/authoring/index.js +0 -36
  49. package/dist/chunk-2DVKSPQH.js +0 -312
  50. package/dist/chunk-4OZFMCTT.js +0 -17
  51. package/dist/chunk-535V5K64.js +0 -155
  52. package/dist/chunk-B7NEUIJL.js +0 -14
  53. package/dist/chunk-DP6UJCMX.js +0 -27
  54. package/dist/chunk-QA72XJZU.js +0 -41
  55. package/dist/chunk-S5KFP4JQ.js +0 -20
  56. package/dist/chunk-XYT6GZ7M.js +0 -99
  57. package/dist/http/index.d.ts +0 -9
  58. package/dist/http/index.js +0 -6
  59. package/dist/index.d.ts +0 -4
  60. package/dist/index.js +0 -48
  61. package/dist/manifest/contract.d.ts +0 -63
  62. package/dist/manifest/contract.js +0 -8
  63. package/dist/manifest/index.d.ts +0 -20
  64. package/dist/manifest/index.js +0 -16
  65. package/dist/mcp/client.d.ts +0 -9
  66. package/dist/mcp/index.d.ts +0 -11
  67. package/dist/mcp/index.js +0 -7
  68. package/dist/openapi/index.d.ts +0 -14
  69. package/dist/openapi/index.js +0 -7
  70. package/dist/openapi/mapper.d.ts +0 -7
  71. package/dist/runner/index.d.ts +0 -4
  72. package/dist/runner/index.js +0 -66
  73. package/dist/runner/protocol.d.ts +0 -33
  74. package/dist/runner/protocol.js +0 -8
  75. package/dist/runtime/index.d.ts +0 -83
  76. package/dist/runtime/index.js +0 -12
  77. package/dist/workerd/index.d.ts +0 -7
  78. package/dist/workerd/index.js +0 -10
  79. package/src/authoring/index.ts +0 -686
  80. package/src/http/index.ts +0 -26
  81. package/src/manifest/contract.ts +0 -64
  82. package/src/manifest/index.ts +0 -156
  83. package/src/mcp/client.ts +0 -59
  84. package/src/mcp/index.ts +0 -42
  85. package/src/openapi/index.ts +0 -70
  86. package/src/openapi/mapper.ts +0 -25
  87. package/src/runner/index.ts +0 -80
  88. package/src/runner/protocol.ts +0 -54
  89. package/src/runtime/index.ts +0 -554
  90. package/src/workerd/index.ts +0 -17
@@ -1,312 +0,0 @@
1
- // src/runtime/index.ts
2
- var failure = (kind, reason) => ({
3
- ok: false,
4
- kind,
5
- reason
6
- });
7
- var errorMessage = (error) => error instanceof Error ? error.message : String(error);
8
- var isJsonValue = (value) => {
9
- if (value === null || typeof value === "string" || typeof value === "boolean") return true;
10
- if (typeof value === "number") return Number.isFinite(value);
11
- if (Array.isArray(value)) return value.every(isJsonValue);
12
- if (typeof value !== "object") return false;
13
- return Object.values(value).every(isJsonValue);
14
- };
15
- var standardJsonSchemaOf = (input) => "~standard" in input ? input["~standard"].jsonSchema : void 0;
16
- var strictify = (node) => {
17
- if (typeof node !== "object" || node === null) return node;
18
- if (Array.isArray(node)) return node.map(strictify);
19
- const object = { ...node };
20
- if (object.type === "object" && object.additionalProperties === void 0)
21
- object.additionalProperties = false;
22
- for (const key of ["items", "anyOf", "oneOf", "allOf"])
23
- if (key in object) object[key] = strictify(object[key]);
24
- for (const key of ["properties", "$defs"])
25
- if (object[key] !== void 0 && typeof object[key] === "object" && object[key] !== null)
26
- object[key] = Object.fromEntries(
27
- Object.entries(object[key]).map(([name, value]) => [
28
- name,
29
- strictify(value)
30
- ])
31
- );
32
- return object;
33
- };
34
- var compileInputSchema = (input, where) => {
35
- const standard = standardJsonSchemaOf(input);
36
- if ("~standard" in input && typeof standard?.input !== "function")
37
- return {
38
- problem: `${where}: input is a Standard Schema without the jsonSchema extension \u2014 use a library that implements it (zod 4+, effect Schema) or pass raw JSON schema`
39
- };
40
- try {
41
- const compiled = strictify(
42
- typeof standard?.input === "function" ? standard.input({ target: "draft-2020-12" }) : structuredClone(input)
43
- );
44
- if (typeof compiled !== "object" || compiled === null || Array.isArray(compiled) || !isJsonValue(compiled))
45
- throw new Error("expected a JSON object");
46
- return { value: compiled };
47
- } catch (error) {
48
- return {
49
- problem: `${where}: input schema could not compile to JSON schema (${errorMessage(error)})`
50
- };
51
- }
52
- };
53
- var requirementKey = Symbol.for("executor/apps/requirement");
54
- var requirementSpecOf = (value) => typeof value === "object" && value !== null && requirementKey in value ? value[requirementKey] : void 0;
55
- var segmentOf = (file) => {
56
- const name = file.slice(file.lastIndexOf("/") + 1);
57
- return name.endsWith(".ts") ? name.slice(0, -3) : name;
58
- };
59
- var canonicalJson = (value) => {
60
- const sortKeys = (node) => {
61
- if (Array.isArray(node)) return node.map(sortKeys);
62
- if (typeof node === "object" && node !== null)
63
- return Object.fromEntries(
64
- Object.entries(node).sort(([left], [right]) => left.localeCompare(right)).map(([key, child]) => [key, sortKeys(child)])
65
- );
66
- return node;
67
- };
68
- return JSON.stringify(sortKeys(value));
69
- };
70
- var collectRegistry = (registry) => {
71
- const problems = registry.problems.map((problem) => problem.message);
72
- const app = registry.app;
73
- const claims = /* @__PURE__ */ new Map();
74
- for (const [origin, registered] of registry.services) {
75
- if (registered.file !== "app.ts") continue;
76
- const { decl } = registered;
77
- claims.set(origin, {
78
- origin,
79
- reach: decl.reach ?? [],
80
- params: decl.params ?? {},
81
- auth: decl.auth ?? {}
82
- });
83
- }
84
- const collectRequirement = (role, requirement, where) => {
85
- const spec = requirementSpecOf(requirement);
86
- if (spec === void 0) {
87
- problems.push(`${where}: requirement '${role}' is not a service/requirement value`);
88
- return void 0;
89
- }
90
- const origin = spec.service.origin;
91
- if (!claims.has(origin))
92
- problems.push(`${where}: requirement '${role}' names ${origin}, which app.ts does not declare`);
93
- if (spec.grant !== void 0 && !(spec.grant in (spec.service.auth ?? {})))
94
- problems.push(
95
- `${where}: requirement '${role}' pins grant '${spec.grant}', not a auth method on ${origin}`
96
- );
97
- return {
98
- role,
99
- service: origin,
100
- arity: spec.arity,
101
- ...spec.grant === void 0 ? {} : { grant: spec.grant },
102
- ...spec.description === void 0 ? {} : { description: spec.description }
103
- };
104
- };
105
- if (app === void 0) problems.push("app.ts must call defineApp({...})");
106
- else if (typeof app.description !== "string" || app.description.trim().length === 0)
107
- problems.push("app.ts: app description must not be empty");
108
- for (const [file, summary] of registry.toolFiles) {
109
- if (summary.definitions > 1 && summary.hasUnnamedTool)
110
- problems.push(`${file}: multi-tool files must name every tool`);
111
- if (registry.dynamic.has(file))
112
- problems.push(`${file}: a file claims a dynamic tool set or defines tools, never both`);
113
- }
114
- const tools = [];
115
- if (app !== void 0) {
116
- for (const [name, registered] of registry.tools) {
117
- const { spec, file } = registered;
118
- const address = `${app.key}/${name}`;
119
- if (typeof spec.description !== "string" || spec.description.trim().length === 0)
120
- problems.push(`${file}: tool '${name}' description must not be empty`);
121
- const requires = Object.entries(spec.requirements ?? {}).flatMap(([role, requirement]) => {
122
- const collected = collectRequirement(role, requirement, address);
123
- return collected === void 0 ? [] : [collected];
124
- }).sort((left, right) => left.role.localeCompare(right.role));
125
- const compiled = compileInputSchema(spec.input, address);
126
- if ("problem" in compiled) {
127
- problems.push(compiled.problem);
128
- continue;
129
- }
130
- tools.push({
131
- address,
132
- name,
133
- description: spec.description,
134
- inputSchema: compiled.value,
135
- annotations: spec.annotations ?? {},
136
- requires,
137
- file
138
- });
139
- }
140
- }
141
- const dynamic = [];
142
- const seenSegments = /* @__PURE__ */ new Map();
143
- for (const [file, registered] of registry.dynamic) {
144
- const segment = segmentOf(file);
145
- const where = `${file}: dynamic tool set '${segment}'`;
146
- const existing = seenSegments.get(segment);
147
- if (existing !== void 0) {
148
- problems.push(`${where}: segment already claimed by ${existing}`);
149
- continue;
150
- }
151
- seenSegments.set(segment, file);
152
- const requires = Object.entries(registered.spec.requirements ?? {}).flatMap(([role, requirement]) => {
153
- const collected = collectRequirement(role, requirement, where);
154
- return collected === void 0 ? [] : [collected];
155
- }).sort((left, right) => left.role.localeCompare(right.role));
156
- dynamic.push({
157
- segment,
158
- description: registered.spec.description,
159
- requires,
160
- file
161
- });
162
- }
163
- if (problems.length > 0 || app === void 0) return { problems };
164
- const services = [...claims.values()].sort(
165
- (left, right) => left.origin.localeCompare(right.origin)
166
- );
167
- const sortedTools = [...tools].sort((left, right) => left.address.localeCompare(right.address));
168
- const sortedDynamic = [...dynamic].sort(
169
- (left, right) => left.segment.localeCompare(right.segment)
170
- );
171
- const appResult = { key: app.key, label: app.label, description: app.description };
172
- const manifest = {
173
- app: appResult,
174
- services,
175
- tools: sortedTools,
176
- dynamic: sortedDynamic
177
- };
178
- return { problems: [], manifest, canonical: canonicalJson(manifest) };
179
- };
180
- var digestOf = async (canonical) => {
181
- const bytes = new Uint8Array(
182
- await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(canonical))
183
- );
184
- return Array.from(bytes.slice(0, 8), (byte) => byte.toString(16).padStart(2, "0")).join("");
185
- };
186
- var manifestOf = async (registry) => {
187
- const collected = collectRegistry(registry);
188
- if (collected.problems.length > 0) return { ok: false, problems: collected.problems };
189
- if (!("manifest" in collected))
190
- return { ok: false, problems: ["validated registry projection unexpectedly missing"] };
191
- return {
192
- ok: true,
193
- result: { digest: `snap:${await digestOf(collected.canonical)}`, ...collected.manifest }
194
- };
195
- };
196
- var standardValidateOf = (input) => "~standard" in input && typeof input["~standard"].validate === "function" ? input["~standard"].validate : void 0;
197
- var parseInput = async (schema, input) => {
198
- const validate = standardValidateOf(schema);
199
- if (validate === void 0)
200
- return { ok: false, reason: "input schema does not implement Standard Schema validate" };
201
- try {
202
- const result = await validate(input);
203
- if (result.issues !== void 0)
204
- return {
205
- ok: false,
206
- reason: `invalid input (${result.issues.map((issue) => issue.message).join("; ")})`
207
- };
208
- return { ok: true, value: result.value };
209
- } catch (error) {
210
- return { ok: false, reason: `input validation threw (${errorMessage(error)})` };
211
- }
212
- };
213
- var splitDynamicAddress = (address) => {
214
- const slash = address.indexOf("/");
215
- if (slash <= 0 || slash === address.length - 1) return void 0;
216
- return { segment: address.slice(0, slash), name: address.slice(slash + 1) };
217
- };
218
- var dynamicFor = (registry, segment) => {
219
- for (const [file, registered] of registry.dynamic)
220
- if (segmentOf(file) === segment) return registered.spec;
221
- return void 0;
222
- };
223
- var discoveredSpecs = /* @__PURE__ */ new WeakMap();
224
- var callTool = async (registry, address, input, ctx, detail) => {
225
- const dynamic = splitDynamicAddress(address);
226
- if (dynamic === void 0) {
227
- if (detail !== void 0)
228
- return failure("handler", "a static tool takes no discovery detail");
229
- const registered = registry.tools.get(address);
230
- if (registered === void 0) return failure("handler", "unknown tool");
231
- const parsed2 = await parseInput(registered.spec.input, input);
232
- if (!parsed2.ok) return failure("input", parsed2.reason);
233
- try {
234
- const handler = registered.spec.handler;
235
- return { ok: true, value: await handler({ input: parsed2.value, ctx }) };
236
- } catch (error) {
237
- return failure("handler", `handler failed (${errorMessage(error)})`);
238
- }
239
- }
240
- if (detail === void 0)
241
- return failure("handler", "a dynamic tool requires discovery detail");
242
- const pair = dynamicFor(registry, dynamic.segment);
243
- if (pair === void 0)
244
- return failure("handler", `unknown dynamic tool set '${dynamic.segment}'`);
245
- const discovered = discoveredSpecs.get(registry)?.get(dynamic.segment)?.get(dynamic.name);
246
- if (discovered === void 0)
247
- return failure(
248
- "input",
249
- `dynamic tool '${dynamic.name}' has no compiled discovery descriptor`
250
- );
251
- const parsed = await parseInput(discovered.input, input);
252
- if (!parsed.ok) return failure("input", parsed.reason);
253
- try {
254
- const call = pair.call;
255
- return {
256
- ok: true,
257
- value: await call({
258
- tool: { name: dynamic.name, detail },
259
- input: parsed.value,
260
- ctx
261
- })
262
- };
263
- } catch (error) {
264
- return failure("handler", `dynamic call failed (${errorMessage(error)})`);
265
- }
266
- };
267
- var discoverTool = async (registry, segment, ctx) => {
268
- const pair = dynamicFor(registry, segment);
269
- if (pair === void 0)
270
- return { ok: false, reason: `unknown dynamic tool set '${segment}'` };
271
- discoveredSpecs.get(registry)?.delete(segment);
272
- let emitted;
273
- try {
274
- const discover = pair.discover;
275
- emitted = await discover({ ctx });
276
- } catch (error) {
277
- return { ok: false, reason: `discover failed (${errorMessage(error)})` };
278
- }
279
- const tools = [];
280
- const live = /* @__PURE__ */ new Map();
281
- for (const tool of emitted) {
282
- if (live.has(tool.name))
283
- return { ok: false, reason: `discover emitted duplicate tool '${tool.name}'` };
284
- const compiled = compileInputSchema(tool.input, `${segment}/${tool.name}`);
285
- if ("problem" in compiled) return { ok: false, reason: compiled.problem };
286
- live.set(tool.name, tool);
287
- tools.push({
288
- segment,
289
- name: tool.name,
290
- descriptor: {
291
- description: tool.description,
292
- inputSchema: compiled.value,
293
- annotations: {
294
- ...tool.annotations?.readOnly === void 0 ? {} : { readOnly: tool.annotations.readOnly },
295
- ...tool.annotations?.destructive === void 0 ? {} : { destructive: tool.annotations.destructive }
296
- }
297
- },
298
- detail: tool.detail ?? null
299
- });
300
- }
301
- const registryDiscoveries = discoveredSpecs.get(registry) ?? /* @__PURE__ */ new Map();
302
- registryDiscoveries.set(segment, live);
303
- discoveredSpecs.set(registry, registryDiscoveries);
304
- return { ok: true, value: tools.sort((left, right) => left.name.localeCompare(right.name)) };
305
- };
306
-
307
- export {
308
- compileInputSchema,
309
- manifestOf,
310
- callTool,
311
- discoverTool
312
- };
@@ -1,17 +0,0 @@
1
- // src/runner/protocol.ts
2
- import { Data } from "effect";
3
- var CallError = class extends Data.TaggedError("CallError") {
4
- get message() {
5
- return `${this.target}: ${this.reason}`;
6
- }
7
- };
8
- var DiscoverError = class extends Data.TaggedError("DiscoverError") {
9
- get message() {
10
- return `${this.segment}: ${this.reason}`;
11
- }
12
- };
13
-
14
- export {
15
- CallError,
16
- DiscoverError
17
- };
@@ -1,155 +0,0 @@
1
- // src/authoring/index.ts
2
- var bearer = (opts) => ({ kind: "bearer", ...opts });
3
- var basic = (opts) => ({ kind: "basic", ...opts });
4
- var secrets = (opts) => ({ kind: "secrets", ...opts });
5
- var oauth = (opts) => ({ kind: "oauth", ...opts });
6
- var RequirementKey = Symbol.for("executor/apps/requirement");
7
- var ServiceDeclKey = Symbol.for("executor/apps/service-decl");
8
- var recordAuthoringProblem = (message) => {
9
- const file = sourceFileFor("wrapper");
10
- activeRegistry.problems.push({ message: `${file}: ${message}` });
11
- };
12
- var DynamicKey = Symbol.for("executor/apps/dynamic");
13
- var dynamicSpecOf = (value) => typeof value === "object" && value !== null && DynamicKey in value ? value[DynamicKey] : void 0;
14
- var defineDynamicTools = (decl) => {
15
- const spec = decl;
16
- const file = sourceFileFor("defineDynamicTools(...)");
17
- const problems = [];
18
- if (typeof spec.description !== "string" || spec.description.trim().length === 0)
19
- problems.push("dynamic tool set description must not be empty");
20
- const roles = Object.entries(spec.requirements ?? {});
21
- if (roles.length > 1) problems.push("a dynamic tool set takes exactly one requirement role");
22
- else if (roles.length === 1) {
23
- const [role, value] = roles[0];
24
- const requirementSpec = requirementSpecOf(value);
25
- if (requirementSpec === void 0)
26
- problems.push(`requirement '${role}' is not a service/requirement value`);
27
- else if (requirementSpec.arity === "many")
28
- problems.push(
29
- `requirement '${role}' cannot be .array() \u2014 multiple accounts expand the catalog per connection, never merge one list`
30
- );
31
- }
32
- if (problems.length > 0) {
33
- activeRegistry.problems.push(...problems.map((message) => ({ message: `${file}: ${message}` })));
34
- return { [DynamicKey]: void 0 };
35
- }
36
- if (activeRegistry.dynamic.has(file))
37
- activeRegistry.problems.push({
38
- message: `${file}: one dynamic tool set per file \u2014 its address segment is the file's name`
39
- });
40
- else activeRegistry.dynamic.set(file, { spec, file });
41
- return { [DynamicKey]: spec };
42
- };
43
- var newRegistry = () => ({
44
- app: void 0,
45
- services: /* @__PURE__ */ new Map(),
46
- tools: /* @__PURE__ */ new Map(),
47
- dynamic: /* @__PURE__ */ new Map(),
48
- problems: [],
49
- toolFiles: /* @__PURE__ */ new Map()
50
- });
51
- var activeRegistry = newRegistry();
52
- var currentFile;
53
- var setActiveRegistry = (registry) => {
54
- const previous = activeRegistry;
55
- activeRegistry = registry;
56
- return previous;
57
- };
58
- var __enterFile = (path) => {
59
- currentFile = path;
60
- };
61
- var __leaveFile = () => {
62
- currentFile = void 0;
63
- };
64
- var sourceFileFor = (claim) => {
65
- if (currentFile !== void 0) return currentFile;
66
- activeRegistry.problems.push({
67
- message: `${claim} called outside an authored module import`
68
- });
69
- return "<unattributed>";
70
- };
71
- var makeTerminal = (spec) => ({
72
- [RequirementKey]: spec,
73
- describe: (text) => makeTerminal({ ...spec, description: text })
74
- });
75
- var service = (decl) => {
76
- const file = sourceFileFor("service(...)");
77
- const makePinned = (spec) => ({
78
- [RequirementKey]: spec,
79
- optional: () => makeTerminal({ ...spec, arity: "optional" }),
80
- array: () => makeTerminal({ ...spec, arity: "many" }),
81
- describe: (text) => makePinned({ ...spec, description: text })
82
- });
83
- const make = (spec) => ({
84
- [RequirementKey]: spec,
85
- [ServiceDeclKey]: decl,
86
- auth: Object.fromEntries(
87
- Object.keys(decl.auth ?? {}).map((name) => [
88
- name,
89
- makePinned({ ...spec, grant: name })
90
- ])
91
- ),
92
- optional: () => makeTerminal({ ...spec, arity: "optional" }),
93
- array: () => makeTerminal({ ...spec, arity: "many" }),
94
- describe: (text) => make({ ...spec, description: text })
95
- });
96
- const value = make({ service: decl, arity: "one" });
97
- if (!activeRegistry.services.has(decl.origin))
98
- activeRegistry.services.set(decl.origin, { decl, file });
99
- return value;
100
- };
101
- var isRequirement = (value) => typeof value === "object" && value !== null && RequirementKey in value;
102
- var isService = (value) => isRequirement(value) && ServiceDeclKey in value;
103
- var requirementSpecOf = (value) => isService(value) || isRequirement(value) ? value[RequirementKey] : void 0;
104
- var defineApp = (manifest) => {
105
- const file = sourceFileFor("defineApp(...)");
106
- const value = { kind: "executor-app", ...manifest };
107
- if (activeRegistry.app === void 0) activeRegistry.app = value;
108
- else activeRegistry.problems.push({ message: `${file}: duplicate defineApp(...)` });
109
- return value;
110
- };
111
- var ToolKey = Symbol.for("executor/apps/tool");
112
- var defineTool = (decl) => {
113
- const spec = decl;
114
- return registerTool(spec);
115
- };
116
- var registerTool = (spec) => {
117
- const file = sourceFileFor("defineTool(...)");
118
- const value = { [ToolKey]: spec };
119
- const fileName = file.slice(file.lastIndexOf("/") + 1);
120
- const stem = fileName.endsWith(".ts") ? fileName.slice(0, -3) : fileName;
121
- const name = spec.name ?? stem;
122
- const fileSummary = activeRegistry.toolFiles.get(file);
123
- activeRegistry.toolFiles.set(file, {
124
- definitions: (fileSummary?.definitions ?? 0) + 1,
125
- hasUnnamedTool: fileSummary?.hasUnnamedTool === true || spec.name === void 0
126
- });
127
- const existing = activeRegistry.tools.get(name);
128
- if (existing !== void 0) {
129
- activeRegistry.problems.push({
130
- message: `${file}: tool name '${name}' is already defined in ${existing.file}`
131
- });
132
- } else activeRegistry.tools.set(name, { spec, file });
133
- return value;
134
- };
135
- var isTool = (value) => typeof value === "object" && value !== null && ToolKey in value;
136
- var toolSpecOf = (value) => isTool(value) ? value[ToolKey] : void 0;
137
-
138
- export {
139
- bearer,
140
- basic,
141
- secrets,
142
- oauth,
143
- recordAuthoringProblem,
144
- dynamicSpecOf,
145
- defineDynamicTools,
146
- newRegistry,
147
- setActiveRegistry,
148
- __enterFile,
149
- __leaveFile,
150
- service,
151
- requirementSpecOf,
152
- defineApp,
153
- defineTool,
154
- toolSpecOf
155
- };
@@ -1,14 +0,0 @@
1
- // src/manifest/contract.ts
2
- import { Data, Schema } from "effect";
3
- var JsonSchemaObject = Schema.Record(Schema.String, Schema.Json);
4
- var PublishError = class extends Data.TaggedError("PublishError") {
5
- get message() {
6
- return `publish failed:
7
- ${this.problems.map((problem) => ` - ${problem}`).join("\n")}`;
8
- }
9
- };
10
-
11
- export {
12
- JsonSchemaObject,
13
- PublishError
14
- };
@@ -1,27 +0,0 @@
1
- import {
2
- defineDynamicTools
3
- } from "./chunk-535V5K64.js";
4
-
5
- // src/mcp/client.ts
6
- var mcpDiscover = async (_endpoint, _ctx, _auth, _operations) => {
7
- throw new Error("mcp client not built yet");
8
- };
9
- var mcpCall = async (_endpoint, _tool, _input, _ctx, _auth) => {
10
- throw new Error("mcp client not built yet");
11
- };
12
-
13
- // src/mcp/index.ts
14
- function fromMCP(endpoint, options) {
15
- const auth = options?.auth;
16
- const operations = options?.operations;
17
- return defineDynamicTools({
18
- description: `Tools served by the MCP server at ${endpoint}.`,
19
- ...options?.requirements === void 0 ? {} : { requirements: options.requirements },
20
- discover: ({ ctx }) => mcpDiscover(endpoint, ctx, auth, operations),
21
- call: ({ tool, input, ctx }) => mcpCall(endpoint, tool.name, input, ctx, auth)
22
- });
23
- }
24
-
25
- export {
26
- fromMCP
27
- };
@@ -1,41 +0,0 @@
1
- import {
2
- defineDynamicTools,
3
- recordAuthoringProblem,
4
- requirementSpecOf
5
- } from "./chunk-535V5K64.js";
6
-
7
- // src/openapi/mapper.ts
8
- var openapiDiscover = async (_spec, _ctx, _auth, _operations) => {
9
- throw new Error("openapi mapper not built yet");
10
- };
11
- var openapiCall = async (_tool, _input, _ctx, _auth) => {
12
- throw new Error("openapi mapper not built yet");
13
- };
14
-
15
- // src/openapi/index.ts
16
- var enforceSecretsPlacement = (requirements, auth) => {
17
- if (auth !== void 0) return;
18
- for (const value of Object.values(requirements ?? {})) {
19
- const spec = requirementSpecOf(value);
20
- const methods = spec?.grant === void 0 ? Object.values(spec?.service.auth ?? {}) : [spec.service.auth?.[spec.grant]].filter((method) => method !== void 0);
21
- if (methods.some((method) => method.kind === "secrets"))
22
- recordAuthoringProblem(
23
- "fromOpenAPI: the service offers a secrets() auth method, so 'auth' must state how the credential rides"
24
- );
25
- }
26
- };
27
- function fromOpenAPI(spec, options) {
28
- enforceSecretsPlacement(options?.requirements, options?.auth);
29
- const auth = options?.auth;
30
- const operations = options?.operations;
31
- return defineDynamicTools({
32
- description: typeof spec === "string" && spec.startsWith("https://") ? `Operations from the OpenAPI document at ${spec}.` : "Operations from an OpenAPI document shipped with the app.",
33
- ...options?.requirements === void 0 ? {} : { requirements: options.requirements },
34
- discover: ({ ctx }) => openapiDiscover(spec, ctx, auth, operations),
35
- call: ({ tool, input, ctx }) => openapiCall(tool, input, ctx, auth)
36
- });
37
- }
38
-
39
- export {
40
- fromOpenAPI
41
- };
@@ -1,20 +0,0 @@
1
- // src/http/index.ts
2
- var authHeaders = (role) => {
3
- switch (role.kind) {
4
- case "bearer":
5
- case "oauth":
6
- return { authorization: `Bearer ${role.token}` };
7
- case "basic":
8
- return { authorization: `Basic ${base64(`${role.username}:${role.password}`)}` };
9
- }
10
- };
11
- var base64 = (value) => {
12
- const bytes = new TextEncoder().encode(value);
13
- let binary = "";
14
- for (const byte of bytes) binary += String.fromCharCode(byte);
15
- return btoa(binary);
16
- };
17
-
18
- export {
19
- authHeaders
20
- };
@@ -1,99 +0,0 @@
1
- import {
2
- manifestOf
3
- } from "./chunk-2DVKSPQH.js";
4
- import {
5
- PublishError
6
- } from "./chunk-B7NEUIJL.js";
7
- import {
8
- __enterFile,
9
- __leaveFile,
10
- newRegistry,
11
- setActiveRegistry
12
- } from "./chunk-535V5K64.js";
13
-
14
- // src/manifest/index.ts
15
- import { fileURLToPath, pathToFileURL } from "node:url";
16
- import { Effect, FileSystem, MutableRef, Semaphore } from "effect";
17
- var moduleProblem = (where, error) => `${where}: failed to execute (${error instanceof Error ? error.message : String(error)})`;
18
- var loadPermit = Semaphore.makeUnsafe(1);
19
- var runNonce = MutableRef.make(0);
20
- var importedAppUrls = MutableRef.make(/* @__PURE__ */ new Set());
21
- var canonicalModuleUrl = (path, where) => FileSystem.FileSystem.pipe(
22
- Effect.flatMap((fs) => fs.realPath(path)),
23
- Effect.map(pathToFileURL),
24
- Effect.mapError((error) => new PublishError({ problems: [moduleProblem(where, error)] }))
25
- );
26
- var importModule = (specifier, where) => Effect.tryPromise({
27
- try: () => import(specifier),
28
- catch: (error) => new PublishError({ problems: [moduleProblem(where, error)] })
29
- }).pipe(Effect.asVoid);
30
- var executeModule = (registry, where, load) => Effect.suspend(() => {
31
- __enterFile(where);
32
- return load;
33
- }).pipe(
34
- Effect.catchTag(
35
- "PublishError",
36
- (error) => Effect.sync(() => {
37
- registry.problems.push(...error.problems.map((message) => ({ message })));
38
- })
39
- )
40
- );
41
- var appEntrySpecifier = (appUrl, nonce) => {
42
- const seen = MutableRef.get(importedAppUrls);
43
- if (!seen.has(appUrl.href)) {
44
- MutableRef.set(importedAppUrls, /* @__PURE__ */ new Set([...seen, appUrl.href]));
45
- return appUrl.href;
46
- }
47
- return `${fileURLToPath(appUrl)}?m=${nonce}`;
48
- };
49
- var executeModules = (appDir, files) => loadPermit.withPermit(
50
- Effect.acquireUseRelease(
51
- Effect.sync(() => {
52
- const registry = newRegistry();
53
- return { registry, previous: setActiveRegistry(registry) };
54
- }),
55
- ({ registry }) => Effect.gen(function* () {
56
- const nonce = MutableRef.incrementAndGet(runNonce);
57
- yield* executeModule(
58
- registry,
59
- "app.ts",
60
- canonicalModuleUrl(`${appDir}/app.ts`, "app.ts").pipe(
61
- Effect.flatMap((appUrl) => importModule(appEntrySpecifier(appUrl, nonce), "app.ts"))
62
- )
63
- );
64
- for (const file of files) {
65
- const where = `tools/${file}`;
66
- yield* executeModule(
67
- registry,
68
- where,
69
- canonicalModuleUrl(`${appDir}/tools/${file}`, where).pipe(
70
- Effect.flatMap((url) => importModule(`${fileURLToPath(url)}?m=${nonce}`, where))
71
- )
72
- );
73
- }
74
- return registry;
75
- }),
76
- ({ previous }) => Effect.sync(() => {
77
- __leaveFile();
78
- setActiveRegistry(previous);
79
- })
80
- )
81
- );
82
- var toolFiles = (appDir) => FileSystem.FileSystem.pipe(
83
- Effect.flatMap((fs) => fs.readDirectory(`${appDir}/tools`)),
84
- Effect.mapError((error) => new PublishError({ problems: [`tools/: ${error.message}`] })),
85
- Effect.map((entries) => entries.filter((file) => file.endsWith(".ts")).sort())
86
- );
87
- var loadApp = (appDir) => Effect.gen(function* () {
88
- const files = yield* toolFiles(appDir);
89
- const registry = yield* executeModules(appDir, files);
90
- const outcome = yield* Effect.promise(() => manifestOf(registry));
91
- if (!outcome.ok) return yield* new PublishError({ problems: outcome.problems });
92
- return { registry, result: outcome.result };
93
- });
94
- var manifest = (appDir) => Effect.map(loadApp(appDir), ({ result }) => result);
95
-
96
- export {
97
- loadApp,
98
- manifest
99
- };