apps 1.0.0-beta.2 → 1.0.0-beta.4
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/dist/authoring/index.d.ts +254 -37
- package/dist/authoring/index.js +11 -1
- package/dist/{chunk-OGCPVWAZ.js → chunk-2DVKSPQH.js} +134 -13
- package/dist/{chunk-NFLNA2SC.js → chunk-4OZFMCTT.js} +7 -1
- package/dist/{chunk-LWKQDDLZ.js → chunk-535V5K64.js} +61 -4
- package/dist/chunk-DP6UJCMX.js +27 -0
- package/dist/chunk-QA72XJZU.js +41 -0
- package/dist/chunk-S5KFP4JQ.js +20 -0
- package/dist/{chunk-646MS7DD.js → chunk-XYT6GZ7M.js} +7 -7
- package/dist/http/index.d.ts +9 -0
- package/dist/http/index.js +6 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +23 -1
- package/dist/manifest/contract.d.ts +8 -0
- package/dist/manifest/index.js +3 -3
- package/dist/mcp/client.d.ts +9 -0
- package/dist/mcp/index.d.ts +11 -0
- package/dist/mcp/index.js +7 -0
- package/dist/openapi/index.d.ts +14 -0
- package/dist/openapi/index.js +7 -0
- package/dist/openapi/mapper.d.ts +7 -0
- package/dist/runner/index.js +29 -15
- package/dist/runner/protocol.d.ts +18 -5
- package/dist/runner/protocol.js +5 -3
- package/dist/runtime/index.d.ts +42 -5
- package/dist/runtime/index.js +3 -1
- package/dist/workerd/index.d.ts +1 -1
- package/dist/workerd/index.js +1 -1
- package/package.json +13 -6
- package/src/authoring/index.ts +395 -49
- package/src/http/index.ts +26 -0
- package/src/index.ts +3 -0
- package/src/manifest/contract.ts +9 -0
- package/src/mcp/client.ts +59 -0
- package/src/mcp/index.ts +42 -0
- package/src/openapi/index.ts +70 -0
- package/src/openapi/mapper.ts +25 -0
- package/src/runner/index.ts +35 -12
- package/src/runner/protocol.ts +32 -7
- package/src/runtime/index.ts +216 -25
- package/src/workerd/index.ts +2 -0
|
@@ -1,8 +1,45 @@
|
|
|
1
1
|
// src/authoring/index.ts
|
|
2
|
+
var bearer = (opts) => ({ kind: "bearer", ...opts });
|
|
3
|
+
var basic = (opts) => ({ kind: "basic", ...opts });
|
|
2
4
|
var secrets = (opts) => ({ kind: "secrets", ...opts });
|
|
3
5
|
var oauth = (opts) => ({ kind: "oauth", ...opts });
|
|
4
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
|
+
};
|
|
5
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
|
+
};
|
|
6
43
|
var newRegistry = () => ({
|
|
7
44
|
app: void 0,
|
|
8
45
|
services: /* @__PURE__ */ new Map(),
|
|
@@ -37,12 +74,23 @@ var makeTerminal = (spec) => ({
|
|
|
37
74
|
});
|
|
38
75
|
var service = (decl) => {
|
|
39
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
|
+
});
|
|
40
83
|
const make = (spec) => ({
|
|
41
84
|
[RequirementKey]: spec,
|
|
42
|
-
decl,
|
|
85
|
+
[ServiceDeclKey]: decl,
|
|
86
|
+
auth: Object.fromEntries(
|
|
87
|
+
Object.keys(decl.auth ?? {}).map((name) => [
|
|
88
|
+
name,
|
|
89
|
+
makePinned({ ...spec, grant: name })
|
|
90
|
+
])
|
|
91
|
+
),
|
|
43
92
|
optional: () => makeTerminal({ ...spec, arity: "optional" }),
|
|
44
93
|
array: () => makeTerminal({ ...spec, arity: "many" }),
|
|
45
|
-
grant: (name) => make({ ...spec, grant: name }),
|
|
46
94
|
describe: (text) => make({ ...spec, description: text })
|
|
47
95
|
});
|
|
48
96
|
const value = make({ service: decl, arity: "one" });
|
|
@@ -51,7 +99,7 @@ var service = (decl) => {
|
|
|
51
99
|
return value;
|
|
52
100
|
};
|
|
53
101
|
var isRequirement = (value) => typeof value === "object" && value !== null && RequirementKey in value;
|
|
54
|
-
var isService = (value) => isRequirement(value) &&
|
|
102
|
+
var isService = (value) => isRequirement(value) && ServiceDeclKey in value;
|
|
55
103
|
var requirementSpecOf = (value) => isService(value) || isRequirement(value) ? value[RequirementKey] : void 0;
|
|
56
104
|
var defineApp = (manifest) => {
|
|
57
105
|
const file = sourceFileFor("defineApp(...)");
|
|
@@ -61,7 +109,11 @@ var defineApp = (manifest) => {
|
|
|
61
109
|
return value;
|
|
62
110
|
};
|
|
63
111
|
var ToolKey = Symbol.for("executor/apps/tool");
|
|
64
|
-
var defineTool = (
|
|
112
|
+
var defineTool = (decl) => {
|
|
113
|
+
const spec = decl;
|
|
114
|
+
return registerTool(spec);
|
|
115
|
+
};
|
|
116
|
+
var registerTool = (spec) => {
|
|
65
117
|
const file = sourceFileFor("defineTool(...)");
|
|
66
118
|
const value = { [ToolKey]: spec };
|
|
67
119
|
const fileName = file.slice(file.lastIndexOf("/") + 1);
|
|
@@ -84,8 +136,13 @@ var isTool = (value) => typeof value === "object" && value !== null && ToolKey i
|
|
|
84
136
|
var toolSpecOf = (value) => isTool(value) ? value[ToolKey] : void 0;
|
|
85
137
|
|
|
86
138
|
export {
|
|
139
|
+
bearer,
|
|
140
|
+
basic,
|
|
87
141
|
secrets,
|
|
88
142
|
oauth,
|
|
143
|
+
recordAuthoringProblem,
|
|
144
|
+
dynamicSpecOf,
|
|
145
|
+
defineDynamicTools,
|
|
89
146
|
newRegistry,
|
|
90
147
|
setActiveRegistry,
|
|
91
148
|
__enterFile,
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
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,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
newRegistry,
|
|
5
|
-
setActiveRegistry
|
|
6
|
-
} from "./chunk-LWKQDDLZ.js";
|
|
2
|
+
manifestOf
|
|
3
|
+
} from "./chunk-2DVKSPQH.js";
|
|
7
4
|
import {
|
|
8
5
|
PublishError
|
|
9
6
|
} from "./chunk-B7NEUIJL.js";
|
|
10
7
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
__enterFile,
|
|
9
|
+
__leaveFile,
|
|
10
|
+
newRegistry,
|
|
11
|
+
setActiveRegistry
|
|
12
|
+
} from "./chunk-535V5K64.js";
|
|
13
13
|
|
|
14
14
|
// src/manifest/index.ts
|
|
15
15
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** HTTP credential placement helpers for kind-bearing connected roles. */
|
|
2
|
+
import type { RoleMaterial } from "../authoring/index";
|
|
3
|
+
export type HttpSpendableRole = Extract<RoleMaterial, {
|
|
4
|
+
kind: "bearer" | "oauth" | "basic";
|
|
5
|
+
}>;
|
|
6
|
+
/** Build the protocol-defined Authorization header for a connected role. */
|
|
7
|
+
export declare const authHeaders: (role: HttpSpendableRole) => {
|
|
8
|
+
readonly authorization: string;
|
|
9
|
+
};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,23 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fromOpenAPI
|
|
3
|
+
} from "./chunk-QA72XJZU.js";
|
|
4
|
+
import {
|
|
5
|
+
authHeaders
|
|
6
|
+
} from "./chunk-S5KFP4JQ.js";
|
|
7
|
+
import {
|
|
8
|
+
fromMCP
|
|
9
|
+
} from "./chunk-DP6UJCMX.js";
|
|
1
10
|
import {
|
|
2
11
|
__enterFile,
|
|
3
12
|
__leaveFile,
|
|
13
|
+
basic,
|
|
14
|
+
bearer,
|
|
4
15
|
defineApp,
|
|
16
|
+
defineDynamicTools,
|
|
5
17
|
defineTool,
|
|
18
|
+
dynamicSpecOf,
|
|
6
19
|
newRegistry,
|
|
7
20
|
oauth,
|
|
21
|
+
recordAuthoringProblem,
|
|
8
22
|
requirementSpecOf,
|
|
9
23
|
secrets,
|
|
10
24
|
service,
|
|
11
25
|
setActiveRegistry,
|
|
12
26
|
toolSpecOf
|
|
13
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-535V5K64.js";
|
|
14
28
|
export {
|
|
15
29
|
__enterFile,
|
|
16
30
|
__leaveFile,
|
|
31
|
+
authHeaders,
|
|
32
|
+
basic,
|
|
33
|
+
bearer,
|
|
17
34
|
defineApp,
|
|
35
|
+
defineDynamicTools,
|
|
18
36
|
defineTool,
|
|
37
|
+
dynamicSpecOf,
|
|
38
|
+
fromMCP,
|
|
39
|
+
fromOpenAPI,
|
|
19
40
|
newRegistry,
|
|
20
41
|
oauth,
|
|
42
|
+
recordAuthoringProblem,
|
|
21
43
|
requirementSpecOf,
|
|
22
44
|
secrets,
|
|
23
45
|
service,
|
|
@@ -32,6 +32,13 @@ export interface ManifestTool {
|
|
|
32
32
|
readonly requires: readonly CollectedRequirement[];
|
|
33
33
|
readonly file: string;
|
|
34
34
|
}
|
|
35
|
+
/** A dynamic address segment projected without endpoint or specification data. */
|
|
36
|
+
export interface ManifestDynamic {
|
|
37
|
+
readonly segment: string;
|
|
38
|
+
readonly description: string;
|
|
39
|
+
readonly requires: readonly CollectedRequirement[];
|
|
40
|
+
readonly file: string;
|
|
41
|
+
}
|
|
35
42
|
/** The deterministic public description of an executor app. */
|
|
36
43
|
export interface AppManifestResult {
|
|
37
44
|
readonly digest: string;
|
|
@@ -42,6 +49,7 @@ export interface AppManifestResult {
|
|
|
42
49
|
};
|
|
43
50
|
readonly services: readonly CollectedClaim[];
|
|
44
51
|
readonly tools: readonly ManifestTool[];
|
|
52
|
+
readonly dynamic: readonly ManifestDynamic[];
|
|
45
53
|
}
|
|
46
54
|
declare const PublishError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
47
55
|
readonly _tag: "PublishError";
|
package/dist/manifest/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
loadApp,
|
|
3
3
|
manifest
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-XYT6GZ7M.js";
|
|
5
|
+
import "../chunk-2DVKSPQH.js";
|
|
6
6
|
import {
|
|
7
7
|
JsonSchemaObject,
|
|
8
8
|
PublishError
|
|
9
9
|
} from "../chunk-B7NEUIJL.js";
|
|
10
|
-
import "../chunk-
|
|
10
|
+
import "../chunk-535V5K64.js";
|
|
11
11
|
export {
|
|
12
12
|
JsonSchemaObject,
|
|
13
13
|
PublishError,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Stub-contract MCP client used by the fromMCP dynamic pair. */
|
|
2
|
+
import type { AuthComposeFn, DiscoveredToolSpec, OperationSelection } from "../authoring/index";
|
|
3
|
+
/** Normalize authored placement, or apply MCP's bearer default. */
|
|
4
|
+
export declare const composePlacement: (auth: AuthComposeFn<never> | undefined, ctx: unknown) => {
|
|
5
|
+
headers: Headers;
|
|
6
|
+
searchParams: URLSearchParams;
|
|
7
|
+
};
|
|
8
|
+
export declare const mcpDiscover: (_endpoint: string, _ctx: unknown, _auth: AuthComposeFn<never> | undefined, _operations: OperationSelection | undefined) => Promise<readonly DiscoveredToolSpec[]>;
|
|
9
|
+
export declare const mcpCall: (_endpoint: string, _tool: string, _input: unknown, _ctx: unknown, _auth: AuthComposeFn<never> | undefined) => Promise<unknown>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** fromMCP sugar over the authored dynamic-tools primitive. */
|
|
2
|
+
import { type AuthComposeFn, type DynamicToolSet, type OperationSelection, type Requirement } from "../authoring/index";
|
|
3
|
+
export type FromMCPOptions<Reqs extends Readonly<Record<string, Requirement>>> = {
|
|
4
|
+
readonly requirements: Reqs;
|
|
5
|
+
readonly auth?: AuthComposeFn<NoInfer<Reqs>>;
|
|
6
|
+
readonly operations?: OperationSelection;
|
|
7
|
+
};
|
|
8
|
+
export declare function fromMCP<const Reqs extends Readonly<Record<string, Requirement>>>(endpoint: string, options: FromMCPOptions<Reqs>): DynamicToolSet;
|
|
9
|
+
export declare function fromMCP(endpoint: string, options?: {
|
|
10
|
+
readonly operations?: OperationSelection;
|
|
11
|
+
}): DynamicToolSet;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** fromOpenAPI sugar over the authored dynamic-tools primitive. */
|
|
2
|
+
import { type AuthComposeFn, type DynamicToolSet, type OperationSelection, type Requirement, type RequiresAuthCompose } from "../authoring/index";
|
|
3
|
+
export type FromOpenAPIOptions<Reqs extends Readonly<Record<string, Requirement>>> = {
|
|
4
|
+
readonly requirements: Reqs;
|
|
5
|
+
readonly auth?: AuthComposeFn<NoInfer<Reqs>>;
|
|
6
|
+
readonly operations?: OperationSelection;
|
|
7
|
+
} & (RequiresAuthCompose<Reqs> extends true ? {
|
|
8
|
+
readonly auth: AuthComposeFn<NoInfer<Reqs>>;
|
|
9
|
+
} : unknown);
|
|
10
|
+
export type OpenAPIDocumentInput = string | Readonly<Record<string, unknown>>;
|
|
11
|
+
export declare function fromOpenAPI<const Reqs extends Readonly<Record<string, Requirement>>>(spec: OpenAPIDocumentInput, options: FromOpenAPIOptions<Reqs>): DynamicToolSet;
|
|
12
|
+
export declare function fromOpenAPI(spec: OpenAPIDocumentInput, options?: {
|
|
13
|
+
readonly operations?: OperationSelection;
|
|
14
|
+
}): DynamicToolSet;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Stub-contract OpenAPI discovery and call mapper. */
|
|
2
|
+
import type { AuthComposeFn, DiscoveredToolSpec, OperationSelection } from "../authoring/index";
|
|
3
|
+
export declare const openapiDiscover: (_spec: string | Readonly<Record<string, unknown>>, _ctx: unknown, _auth: AuthComposeFn<never> | undefined, _operations: OperationSelection | undefined) => Promise<readonly DiscoveredToolSpec[]>;
|
|
4
|
+
export declare const openapiCall: (_tool: {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly detail: unknown;
|
|
7
|
+
}, _input: unknown, _ctx: unknown, _auth: AuthComposeFn<never> | undefined) => Promise<unknown>;
|
package/dist/runner/index.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
loadApp
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-LWKQDDLZ.js";
|
|
5
|
-
import "../chunk-B7NEUIJL.js";
|
|
6
|
-
import {
|
|
7
|
-
CallError
|
|
8
|
-
} from "../chunk-NFLNA2SC.js";
|
|
3
|
+
} from "../chunk-XYT6GZ7M.js";
|
|
9
4
|
import {
|
|
10
5
|
callTool,
|
|
11
6
|
discoverTool
|
|
12
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-2DVKSPQH.js";
|
|
8
|
+
import "../chunk-B7NEUIJL.js";
|
|
9
|
+
import {
|
|
10
|
+
CallError,
|
|
11
|
+
DiscoverError
|
|
12
|
+
} from "../chunk-4OZFMCTT.js";
|
|
13
|
+
import "../chunk-535V5K64.js";
|
|
13
14
|
|
|
14
15
|
// src/runner/index.ts
|
|
15
16
|
import { Effect } from "effect";
|
|
@@ -28,25 +29,38 @@ var localRunner = (appDir) => {
|
|
|
28
29
|
const registryFor = (target) => loaded().pipe(
|
|
29
30
|
Effect.map(({ registry }) => registry),
|
|
30
31
|
Effect.mapError(
|
|
31
|
-
(error) => new CallError({
|
|
32
|
+
(error) => new CallError({
|
|
33
|
+
target,
|
|
34
|
+
kind: "handler",
|
|
35
|
+
reason: `app failed to load (${error.message})`
|
|
36
|
+
})
|
|
32
37
|
)
|
|
33
38
|
);
|
|
34
|
-
const settle = (target, outcome) => outcome.ok ? Effect.succeed(outcome.value) : Effect.fail(new CallError({
|
|
39
|
+
const settle = (target, outcome) => outcome.ok ? Effect.succeed(outcome.value) : Effect.fail(new CallError({
|
|
40
|
+
target,
|
|
41
|
+
kind: outcome.kind,
|
|
42
|
+
reason: outcome.reason
|
|
43
|
+
}));
|
|
44
|
+
const settleDiscovery = (segment, outcome) => outcome.ok ? Effect.succeed(outcome.value) : Effect.fail(new DiscoverError({ segment, reason: outcome.reason }));
|
|
35
45
|
return {
|
|
36
46
|
manifest: () => Effect.map(loaded(), ({ result }) => result),
|
|
37
|
-
call: (
|
|
38
|
-
Effect.flatMap(
|
|
39
|
-
|
|
47
|
+
call: (address, input, ctx, detail) => registryFor(address).pipe(
|
|
48
|
+
Effect.flatMap(
|
|
49
|
+
(registry) => Effect.promise(() => callTool(registry, address, input, ctx, detail))
|
|
50
|
+
),
|
|
51
|
+
Effect.flatMap((outcome) => settle(address, outcome))
|
|
40
52
|
),
|
|
41
|
-
discover: (
|
|
53
|
+
discover: (segment, ctx) => registryFor(segment).pipe(
|
|
54
|
+
Effect.mapError((error) => new DiscoverError({ segment, reason: error.reason })),
|
|
42
55
|
Effect.flatMap(
|
|
43
|
-
(registry) => Effect.promise(() => discoverTool(registry,
|
|
56
|
+
(registry) => Effect.promise(() => discoverTool(registry, segment, ctx))
|
|
44
57
|
),
|
|
45
|
-
Effect.flatMap((outcome) =>
|
|
58
|
+
Effect.flatMap((outcome) => settleDiscovery(segment, outcome))
|
|
46
59
|
)
|
|
47
60
|
};
|
|
48
61
|
};
|
|
49
62
|
export {
|
|
50
63
|
CallError,
|
|
64
|
+
DiscoverError,
|
|
51
65
|
localRunner
|
|
52
66
|
};
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
import { type Effect, FileSystem } from "effect";
|
|
2
2
|
import type { AppManifestResult, PublishError } from "../manifest/contract";
|
|
3
|
-
import type { ToolCtx } from "../runtime/index";
|
|
4
|
-
export type { ToolCtx, ToolCtxEntry } from "../runtime/index";
|
|
3
|
+
import type { CallFailureKind, DiscoveredTool, ToolCtx } from "../runtime/index";
|
|
4
|
+
export type { DiscoveredTool, ToolCtx, ToolCtxEntry, ToolDescriptor, } from "../runtime/index";
|
|
5
|
+
/** Which invocation phase failed. */
|
|
6
|
+
export type CallErrorKind = CallFailureKind;
|
|
5
7
|
declare const CallError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
6
8
|
readonly _tag: "CallError";
|
|
7
9
|
} & Readonly<A>;
|
|
8
|
-
/** A runner operation failure associated with its target. */
|
|
10
|
+
/** A runner operation failure associated with its target and phase. */
|
|
9
11
|
export declare class CallError extends CallError_base<{
|
|
10
12
|
readonly target: string;
|
|
13
|
+
readonly kind: CallErrorKind;
|
|
14
|
+
readonly reason: string;
|
|
15
|
+
}> {
|
|
16
|
+
get message(): string;
|
|
17
|
+
}
|
|
18
|
+
declare const DiscoverError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
19
|
+
readonly _tag: "DiscoverError";
|
|
20
|
+
} & Readonly<A>;
|
|
21
|
+
/** A discovery failure associated with one dynamic segment. */
|
|
22
|
+
export declare class DiscoverError extends DiscoverError_base<{
|
|
23
|
+
readonly segment: string;
|
|
11
24
|
readonly reason: string;
|
|
12
25
|
}> {
|
|
13
26
|
get message(): string;
|
|
@@ -15,6 +28,6 @@ export declare class CallError extends CallError_base<{
|
|
|
15
28
|
/** The platform protocol implemented by an app execution environment. */
|
|
16
29
|
export interface AppRunner {
|
|
17
30
|
manifest(): Effect.Effect<AppManifestResult, PublishError, FileSystem.FileSystem>;
|
|
18
|
-
call(
|
|
19
|
-
discover(
|
|
31
|
+
call(address: string, input: unknown, ctx: ToolCtx, detail?: unknown): Effect.Effect<unknown, CallError, FileSystem.FileSystem>;
|
|
32
|
+
discover(segment: string, ctx: ToolCtx): Effect.Effect<readonly DiscoveredTool[], DiscoverError, FileSystem.FileSystem>;
|
|
20
33
|
}
|
package/dist/runner/protocol.js
CHANGED
package/dist/runtime/index.d.ts
CHANGED
|
@@ -12,11 +12,14 @@
|
|
|
12
12
|
* and workerd all provide.
|
|
13
13
|
*/
|
|
14
14
|
import type { Registry } from "../authoring/index";
|
|
15
|
-
import type { AppManifestResult } from "../manifest/contract";
|
|
15
|
+
import type { AppManifestResult, JsonSchemaObject } from "../manifest/contract";
|
|
16
16
|
/** The capability exposed to one tool requirement role. */
|
|
17
17
|
export interface ToolCtxEntry {
|
|
18
18
|
readonly grant: string;
|
|
19
|
+
readonly kind: "bearer" | "basic" | "secrets" | "oauth";
|
|
19
20
|
readonly token?: string;
|
|
21
|
+
readonly username?: string;
|
|
22
|
+
readonly password?: string;
|
|
20
23
|
readonly secrets?: Readonly<Record<string, string>>;
|
|
21
24
|
fetch(path: string, init?: RequestInit): Promise<Response>;
|
|
22
25
|
}
|
|
@@ -30,17 +33,51 @@ export type ManifestOutcome = {
|
|
|
30
33
|
readonly ok: false;
|
|
31
34
|
readonly problems: readonly string[];
|
|
32
35
|
};
|
|
36
|
+
/** Which invocation phase failed. */
|
|
37
|
+
export type CallFailureKind = "input" | "handler";
|
|
33
38
|
/** One tool invocation's result envelope. */
|
|
34
39
|
export type CallOutcome = {
|
|
35
40
|
readonly ok: true;
|
|
36
41
|
readonly value: unknown;
|
|
37
42
|
} | {
|
|
38
43
|
readonly ok: false;
|
|
44
|
+
readonly kind: CallFailureKind;
|
|
39
45
|
readonly reason: string;
|
|
40
46
|
};
|
|
47
|
+
/** Agent-facing descriptor compiled from one discovery result. */
|
|
48
|
+
export interface ToolDescriptor {
|
|
49
|
+
readonly description: string;
|
|
50
|
+
readonly inputSchema: JsonSchemaObject;
|
|
51
|
+
readonly annotations: {
|
|
52
|
+
readonly readOnly?: boolean;
|
|
53
|
+
readonly destructive?: boolean;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** One tool emitted by a dynamic segment discovery. */
|
|
57
|
+
export interface DiscoveredTool {
|
|
58
|
+
readonly segment: string;
|
|
59
|
+
readonly name: string;
|
|
60
|
+
readonly descriptor: ToolDescriptor;
|
|
61
|
+
readonly detail: unknown;
|
|
62
|
+
}
|
|
63
|
+
/** One dynamic discovery result envelope. */
|
|
64
|
+
export type DiscoverOutcome = {
|
|
65
|
+
readonly ok: true;
|
|
66
|
+
readonly value: readonly DiscoveredTool[];
|
|
67
|
+
} | {
|
|
68
|
+
readonly ok: false;
|
|
69
|
+
readonly reason: string;
|
|
70
|
+
};
|
|
71
|
+
type InputSchemaCompilation = {
|
|
72
|
+
readonly value: JsonSchemaObject;
|
|
73
|
+
} | {
|
|
74
|
+
readonly problem: string;
|
|
75
|
+
};
|
|
76
|
+
export declare const compileInputSchema: (input: object, where: string) => InputSchemaCompilation;
|
|
41
77
|
/** Project a loaded registry into the app's deterministic manifest. */
|
|
42
78
|
export declare const manifestOf: (registry: Registry) => Promise<ManifestOutcome>;
|
|
43
|
-
/** Validate input and run one
|
|
44
|
-
export declare const callTool: (registry: Registry,
|
|
45
|
-
/** Discover one dynamic
|
|
46
|
-
export declare const discoverTool: (
|
|
79
|
+
/** Validate input and run one static or dynamic tool handler. */
|
|
80
|
+
export declare const callTool: (registry: Registry, address: string, input: unknown, ctx: ToolCtx, detail?: unknown) => Promise<CallOutcome>;
|
|
81
|
+
/** Discover and compile one dynamic segment. */
|
|
82
|
+
export declare const discoverTool: (registry: Registry, segment: string, ctx: ToolCtx) => Promise<DiscoverOutcome>;
|
|
83
|
+
export {};
|
package/dist/runtime/index.js
CHANGED
package/dist/workerd/index.d.ts
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* exposes these verbs over RPC; the logic itself lives in ../runtime
|
|
5
5
|
* and is identical to what the local runner executes. @internal
|
|
6
6
|
*/
|
|
7
|
-
export { callTool, discoverTool, manifestOf, type CallOutcome, type ManifestOutcome, type ToolCtx, type ToolCtxEntry, } from "../runtime/index";
|
|
7
|
+
export { callTool, discoverTool, manifestOf, type CallOutcome, type DiscoverOutcome, type DiscoveredTool, type ManifestOutcome, type ToolCtx, type ToolCtxEntry, } from "../runtime/index";
|