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.
- package/README.md +10 -48
- package/check-publish.mjs +7 -0
- package/package.json +27 -56
- package/src/Access.ts +37 -0
- package/src/Accounts.ts +468 -0
- package/src/App.ts +11 -0
- package/src/Ask.ts +156 -0
- package/src/Changes.ts +13 -0
- package/src/Http.ts +30 -0
- package/src/Provider.ts +146 -0
- package/src/Session.ts +52 -0
- package/src/Settings.ts +164 -0
- package/src/contract.ts +852 -0
- package/src/css-modules.d.ts +2 -0
- package/src/desktop/Desktop.ts +192 -0
- package/src/desktop/bridge.ts +62 -0
- package/src/desktop/errors.ts +88 -0
- package/src/desktop/index.ts +15 -0
- package/src/entry.ts +48 -0
- package/src/index.ts +16 -4
- package/src/internal/defects.ts +62 -0
- package/src/internal/files.ts +369 -0
- package/src/internal/host.ts +17 -0
- package/src/internal/query.ts +114 -0
- package/src/internal/records.ts +838 -0
- package/src/internal/retention.ts +87 -0
- package/src/internal/retries.ts +185 -0
- package/src/internal/telemetry.ts +167 -0
- package/src/migrations.ts +110 -0
- package/src/page/Accounts.ts +27 -0
- package/src/page/Changes.ts +126 -0
- package/src/page/Session.ts +46 -0
- package/src/page/client.ts +107 -0
- package/src/page/errors.ts +15 -0
- package/src/page/http.ts +21 -0
- package/src/page/index.ts +18 -0
- package/src/page/paths.ts +22 -0
- package/src/providers/anthropic.ts +26 -0
- package/src/providers/github.ts +49 -0
- package/src/providers/google.ts +67 -0
- package/src/providers/openai.ts +62 -0
- package/src/providers/slack.ts +81 -0
- package/src/runtime.ts +1540 -0
- package/src/testing.ts +660 -0
- package/src/text-modules.d.ts +5 -0
- package/src/theme.css +50 -0
- package/dist/authoring/index.d.ts +0 -422
- package/dist/authoring/index.js +0 -36
- package/dist/chunk-2DVKSPQH.js +0 -312
- package/dist/chunk-4OZFMCTT.js +0 -17
- package/dist/chunk-535V5K64.js +0 -155
- package/dist/chunk-B7NEUIJL.js +0 -14
- package/dist/chunk-DP6UJCMX.js +0 -27
- package/dist/chunk-QA72XJZU.js +0 -41
- package/dist/chunk-S5KFP4JQ.js +0 -20
- package/dist/chunk-XYT6GZ7M.js +0 -99
- package/dist/http/index.d.ts +0 -9
- package/dist/http/index.js +0 -6
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -48
- package/dist/manifest/contract.d.ts +0 -63
- package/dist/manifest/contract.js +0 -8
- package/dist/manifest/index.d.ts +0 -20
- package/dist/manifest/index.js +0 -16
- package/dist/mcp/client.d.ts +0 -9
- package/dist/mcp/index.d.ts +0 -11
- package/dist/mcp/index.js +0 -7
- package/dist/openapi/index.d.ts +0 -14
- package/dist/openapi/index.js +0 -7
- package/dist/openapi/mapper.d.ts +0 -7
- package/dist/runner/index.d.ts +0 -4
- package/dist/runner/index.js +0 -66
- package/dist/runner/protocol.d.ts +0 -33
- package/dist/runner/protocol.js +0 -8
- package/dist/runtime/index.d.ts +0 -83
- package/dist/runtime/index.js +0 -12
- package/dist/workerd/index.d.ts +0 -7
- package/dist/workerd/index.js +0 -10
- package/src/authoring/index.ts +0 -686
- package/src/http/index.ts +0 -26
- package/src/manifest/contract.ts +0 -64
- package/src/manifest/index.ts +0 -156
- package/src/mcp/client.ts +0 -59
- package/src/mcp/index.ts +0 -42
- package/src/openapi/index.ts +0 -70
- package/src/openapi/mapper.ts +0 -25
- package/src/runner/index.ts +0 -80
- package/src/runner/protocol.ts +0 -54
- package/src/runtime/index.ts +0 -554
- package/src/workerd/index.ts +0 -17
package/src/http/index.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/** HTTP credential placement helpers for kind-bearing connected roles. */
|
|
2
|
-
|
|
3
|
-
import type { RoleMaterial } from "../authoring/index";
|
|
4
|
-
|
|
5
|
-
export type HttpSpendableRole = Extract<
|
|
6
|
-
RoleMaterial,
|
|
7
|
-
{ kind: "bearer" | "oauth" | "basic" }
|
|
8
|
-
>;
|
|
9
|
-
|
|
10
|
-
/** Build the protocol-defined Authorization header for a connected role. */
|
|
11
|
-
export const authHeaders = (role: HttpSpendableRole): { readonly authorization: string } => {
|
|
12
|
-
switch (role.kind) {
|
|
13
|
-
case "bearer":
|
|
14
|
-
case "oauth":
|
|
15
|
-
return { authorization: `Bearer ${role.token}` };
|
|
16
|
-
case "basic":
|
|
17
|
-
return { authorization: `Basic ${base64(`${role.username}:${role.password}`)}` };
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const base64 = (value: string): string => {
|
|
22
|
-
const bytes = new TextEncoder().encode(value);
|
|
23
|
-
let binary = "";
|
|
24
|
-
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
25
|
-
return btoa(binary);
|
|
26
|
-
};
|
package/src/manifest/contract.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Data, Schema } from "effect";
|
|
2
|
-
import type { AuthMethod, ParamSpec } from "../authoring/index";
|
|
3
|
-
|
|
4
|
-
/** A service claim projected from a registered declaration. */
|
|
5
|
-
export interface CollectedClaim {
|
|
6
|
-
readonly origin: string;
|
|
7
|
-
readonly reach: readonly string[];
|
|
8
|
-
readonly params: Readonly<Record<string, ParamSpec>>;
|
|
9
|
-
readonly auth: Readonly<Record<string, AuthMethod>>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** A tool requirement projected from an authoring value. */
|
|
13
|
-
export interface CollectedRequirement {
|
|
14
|
-
readonly role: string;
|
|
15
|
-
readonly service: string;
|
|
16
|
-
readonly arity: "one" | "optional" | "many";
|
|
17
|
-
readonly grant?: string;
|
|
18
|
-
readonly description?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** JSON object accepted for a persisted tool input schema. */
|
|
22
|
-
export const JsonSchemaObject = Schema.Record(Schema.String, Schema.Json);
|
|
23
|
-
export type JsonSchemaObject = typeof JsonSchemaObject.Type;
|
|
24
|
-
|
|
25
|
-
/** A validated, publishable tool row. */
|
|
26
|
-
export interface ManifestTool {
|
|
27
|
-
readonly address: string;
|
|
28
|
-
readonly name: string;
|
|
29
|
-
readonly description: string;
|
|
30
|
-
readonly inputSchema: JsonSchemaObject;
|
|
31
|
-
readonly annotations: {
|
|
32
|
-
readonly readOnly?: boolean;
|
|
33
|
-
readonly destructive?: boolean;
|
|
34
|
-
readonly scopes?: readonly string[];
|
|
35
|
-
};
|
|
36
|
-
readonly requires: readonly CollectedRequirement[];
|
|
37
|
-
readonly file: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** A dynamic address segment projected without endpoint or specification data. */
|
|
41
|
-
export interface ManifestDynamic {
|
|
42
|
-
readonly segment: string;
|
|
43
|
-
readonly description: string;
|
|
44
|
-
readonly requires: readonly CollectedRequirement[];
|
|
45
|
-
readonly file: string;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** The deterministic public description of an executor app. */
|
|
49
|
-
export interface AppManifestResult {
|
|
50
|
-
readonly digest: string;
|
|
51
|
-
readonly app: { readonly key: string; readonly label: string; readonly description: string };
|
|
52
|
-
readonly services: readonly CollectedClaim[];
|
|
53
|
-
readonly tools: readonly ManifestTool[];
|
|
54
|
-
readonly dynamic: readonly ManifestDynamic[];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** All publish-time authoring problems from one registry load. */
|
|
58
|
-
export class PublishError extends Data.TaggedError("PublishError")<{
|
|
59
|
-
readonly problems: readonly string[];
|
|
60
|
-
}> {
|
|
61
|
-
override get message(): string {
|
|
62
|
-
return `publish failed:\n${this.problems.map((problem) => ` - ${problem}`).join("\n")}`;
|
|
63
|
-
}
|
|
64
|
-
}
|
package/src/manifest/index.ts
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Manifest: execute an authored app folder and project its registry.
|
|
3
|
-
* This module owns exactly what differs on a host with a filesystem —
|
|
4
|
-
* finding and importing authored modules. Everything after the modules
|
|
5
|
-
* load (validation, canonicalization, digesting) is the shared
|
|
6
|
-
* execution core in ../runtime; sandboxed guests run that same core.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
10
|
-
import { Effect, FileSystem, MutableRef, Semaphore } from "effect";
|
|
11
|
-
import {
|
|
12
|
-
__enterFile,
|
|
13
|
-
__leaveFile,
|
|
14
|
-
newRegistry,
|
|
15
|
-
setActiveRegistry,
|
|
16
|
-
type Registry,
|
|
17
|
-
} from "../authoring/index";
|
|
18
|
-
import { manifestOf } from "../runtime/index";
|
|
19
|
-
import { PublishError, type AppManifestResult } from "./contract";
|
|
20
|
-
|
|
21
|
-
export * from "./contract";
|
|
22
|
-
|
|
23
|
-
const moduleProblem = (where: string, error: unknown): string =>
|
|
24
|
-
`${where}: failed to execute (${error instanceof Error ? error.message : String(error)})`;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Module execution is process-global twice over: the authoring
|
|
28
|
-
* registry is a singleton the imported modules write into, and the
|
|
29
|
-
* ESM module cache is shared. One permit serializes loads; the nonce
|
|
30
|
-
* and first-import memo make re-imports observable across runs.
|
|
31
|
-
* Module-scoped by necessity — this state IS process state.
|
|
32
|
-
*/
|
|
33
|
-
const loadPermit = Semaphore.makeUnsafe(1);
|
|
34
|
-
const runNonce = MutableRef.make(0);
|
|
35
|
-
const importedAppUrls = MutableRef.make<ReadonlySet<string>>(new Set());
|
|
36
|
-
|
|
37
|
-
const canonicalModuleUrl = (
|
|
38
|
-
path: string,
|
|
39
|
-
where: string,
|
|
40
|
-
): Effect.Effect<URL, PublishError, FileSystem.FileSystem> =>
|
|
41
|
-
FileSystem.FileSystem.pipe(
|
|
42
|
-
Effect.flatMap((fs) => fs.realPath(path)),
|
|
43
|
-
Effect.map(pathToFileURL),
|
|
44
|
-
Effect.mapError((error) => new PublishError({ problems: [moduleProblem(where, error)] })),
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
const importModule = (specifier: string, where: string): Effect.Effect<void, PublishError> =>
|
|
48
|
-
Effect.tryPromise({
|
|
49
|
-
try: () => import(specifier),
|
|
50
|
-
catch: (error) => new PublishError({ problems: [moduleProblem(where, error)] }),
|
|
51
|
-
}).pipe(Effect.asVoid);
|
|
52
|
-
|
|
53
|
-
/** Import one authored module, converting failure into registry problems. */
|
|
54
|
-
const executeModule = (
|
|
55
|
-
registry: Registry,
|
|
56
|
-
where: string,
|
|
57
|
-
load: Effect.Effect<void, PublishError, FileSystem.FileSystem>,
|
|
58
|
-
): Effect.Effect<void, never, FileSystem.FileSystem> =>
|
|
59
|
-
Effect.suspend(() => {
|
|
60
|
-
__enterFile(where);
|
|
61
|
-
return load;
|
|
62
|
-
}).pipe(
|
|
63
|
-
Effect.catchTag("PublishError", (error) =>
|
|
64
|
-
Effect.sync(() => {
|
|
65
|
-
registry.problems.push(...error.problems.map((message) => ({ message })));
|
|
66
|
-
}),
|
|
67
|
-
),
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* The app entry loads through its plain canonical URL the first time
|
|
72
|
-
* so relative imports resolve normally, and through a nonce query on
|
|
73
|
-
* every later run so edits are observed instead of served stale from
|
|
74
|
-
* the module cache.
|
|
75
|
-
*/
|
|
76
|
-
const appEntrySpecifier = (appUrl: URL, nonce: number): string => {
|
|
77
|
-
const seen = MutableRef.get(importedAppUrls);
|
|
78
|
-
if (!seen.has(appUrl.href)) {
|
|
79
|
-
MutableRef.set(importedAppUrls, new Set([...seen, appUrl.href]));
|
|
80
|
-
return appUrl.href;
|
|
81
|
-
}
|
|
82
|
-
return `${fileURLToPath(appUrl)}?m=${nonce}`;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const executeModules = (
|
|
86
|
-
appDir: string,
|
|
87
|
-
files: readonly string[],
|
|
88
|
-
): Effect.Effect<Registry, never, FileSystem.FileSystem> =>
|
|
89
|
-
loadPermit.withPermit(
|
|
90
|
-
Effect.acquireUseRelease(
|
|
91
|
-
Effect.sync(() => {
|
|
92
|
-
const registry = newRegistry();
|
|
93
|
-
return { registry, previous: setActiveRegistry(registry) };
|
|
94
|
-
}),
|
|
95
|
-
({ registry }) =>
|
|
96
|
-
Effect.gen(function* () {
|
|
97
|
-
const nonce = MutableRef.incrementAndGet(runNonce);
|
|
98
|
-
yield* executeModule(
|
|
99
|
-
registry,
|
|
100
|
-
"app.ts",
|
|
101
|
-
canonicalModuleUrl(`${appDir}/app.ts`, "app.ts").pipe(
|
|
102
|
-
Effect.flatMap((appUrl) => importModule(appEntrySpecifier(appUrl, nonce), "app.ts")),
|
|
103
|
-
),
|
|
104
|
-
);
|
|
105
|
-
for (const file of files) {
|
|
106
|
-
const where = `tools/${file}`;
|
|
107
|
-
yield* executeModule(
|
|
108
|
-
registry,
|
|
109
|
-
where,
|
|
110
|
-
canonicalModuleUrl(`${appDir}/tools/${file}`, where).pipe(
|
|
111
|
-
Effect.flatMap((url) => importModule(`${fileURLToPath(url)}?m=${nonce}`, where)),
|
|
112
|
-
),
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
return registry;
|
|
116
|
-
}),
|
|
117
|
-
({ previous }) =>
|
|
118
|
-
Effect.sync(() => {
|
|
119
|
-
__leaveFile();
|
|
120
|
-
setActiveRegistry(previous);
|
|
121
|
-
}),
|
|
122
|
-
),
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
const toolFiles = (
|
|
126
|
-
appDir: string,
|
|
127
|
-
): Effect.Effect<readonly string[], PublishError, FileSystem.FileSystem> =>
|
|
128
|
-
FileSystem.FileSystem.pipe(
|
|
129
|
-
Effect.flatMap((fs) => fs.readDirectory(`${appDir}/tools`)),
|
|
130
|
-
Effect.mapError((error) => new PublishError({ problems: [`tools/: ${error.message}`] })),
|
|
131
|
-
Effect.map((entries) => entries.filter((file) => file.endsWith(".ts")).sort()),
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
/** A registry and its validated public projection. @internal */
|
|
135
|
-
export interface LoadedApp {
|
|
136
|
-
readonly registry: Registry;
|
|
137
|
-
readonly result: AppManifestResult;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/** Loads an app once and returns both its live registry and manifest. @internal */
|
|
141
|
-
export const loadApp = (
|
|
142
|
-
appDir: string,
|
|
143
|
-
): Effect.Effect<LoadedApp, PublishError, FileSystem.FileSystem> =>
|
|
144
|
-
Effect.gen(function* () {
|
|
145
|
-
const files = yield* toolFiles(appDir);
|
|
146
|
-
const registry = yield* executeModules(appDir, files);
|
|
147
|
-
const outcome = yield* Effect.promise(() => manifestOf(registry));
|
|
148
|
-
if (!outcome.ok) return yield* new PublishError({ problems: outcome.problems });
|
|
149
|
-
return { registry, result: outcome.result };
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
/** Executes an app and returns its deterministic publish manifest. */
|
|
153
|
-
export const manifest = (
|
|
154
|
-
appDir: string,
|
|
155
|
-
): Effect.Effect<AppManifestResult, PublishError, FileSystem.FileSystem> =>
|
|
156
|
-
Effect.map(loadApp(appDir), ({ result }) => result);
|
package/src/mcp/client.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/** Stub-contract MCP client used by the fromMCP dynamic pair. */
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
AuthComposeFn,
|
|
5
|
-
DiscoveredToolSpec,
|
|
6
|
-
OperationSelection,
|
|
7
|
-
} from "../authoring/index";
|
|
8
|
-
|
|
9
|
-
/** Normalize authored placement, or apply MCP's bearer default. */
|
|
10
|
-
export const composePlacement = (
|
|
11
|
-
auth: AuthComposeFn<never> | undefined,
|
|
12
|
-
ctx: unknown,
|
|
13
|
-
): { headers: Headers; searchParams: URLSearchParams } => {
|
|
14
|
-
const headers = new Headers();
|
|
15
|
-
const searchParams = new URLSearchParams();
|
|
16
|
-
const roles = ctx as Record<string, { token?: string }> | undefined;
|
|
17
|
-
|
|
18
|
-
if (auth === undefined) {
|
|
19
|
-
const role = roles === undefined ? undefined : Object.values(roles)[0];
|
|
20
|
-
if (role?.token !== undefined) headers.set("authorization", `Bearer ${role.token}`);
|
|
21
|
-
return { headers, searchParams };
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const placement = (auth as (roles: unknown) => unknown)(roles ?? {});
|
|
25
|
-
if (placement !== undefined && placement !== null && typeof placement === "object") {
|
|
26
|
-
const normalized = placement as {
|
|
27
|
-
readonly headers?: HeadersInit;
|
|
28
|
-
readonly searchParams?: URLSearchParams | Readonly<Record<string, string>>;
|
|
29
|
-
};
|
|
30
|
-
if (normalized.headers !== undefined)
|
|
31
|
-
new Headers(normalized.headers).forEach((value, key) => headers.set(key, value));
|
|
32
|
-
if (normalized.searchParams !== undefined)
|
|
33
|
-
new URLSearchParams(
|
|
34
|
-
normalized.searchParams instanceof URLSearchParams
|
|
35
|
-
? normalized.searchParams
|
|
36
|
-
: { ...normalized.searchParams },
|
|
37
|
-
).forEach((value, key) => searchParams.set(key, value));
|
|
38
|
-
}
|
|
39
|
-
return { headers, searchParams };
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export const mcpDiscover = async (
|
|
43
|
-
_endpoint: string,
|
|
44
|
-
_ctx: unknown,
|
|
45
|
-
_auth: AuthComposeFn<never> | undefined,
|
|
46
|
-
_operations: OperationSelection | undefined,
|
|
47
|
-
): Promise<readonly DiscoveredToolSpec[]> => {
|
|
48
|
-
throw new Error("mcp client not built yet");
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export const mcpCall = async (
|
|
52
|
-
_endpoint: string,
|
|
53
|
-
_tool: string,
|
|
54
|
-
_input: unknown,
|
|
55
|
-
_ctx: unknown,
|
|
56
|
-
_auth: AuthComposeFn<never> | undefined,
|
|
57
|
-
): Promise<unknown> => {
|
|
58
|
-
throw new Error("mcp client not built yet");
|
|
59
|
-
};
|
package/src/mcp/index.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/** fromMCP sugar over the authored dynamic-tools primitive. */
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
defineDynamicTools,
|
|
5
|
-
type AuthComposeFn,
|
|
6
|
-
type DynamicToolSet,
|
|
7
|
-
type OperationSelection,
|
|
8
|
-
type Requirement,
|
|
9
|
-
} from "../authoring/index";
|
|
10
|
-
import { mcpCall, mcpDiscover } from "./client";
|
|
11
|
-
|
|
12
|
-
export type FromMCPOptions<Reqs extends Readonly<Record<string, Requirement>>> = {
|
|
13
|
-
readonly requirements: Reqs;
|
|
14
|
-
readonly auth?: AuthComposeFn<NoInfer<Reqs>>;
|
|
15
|
-
readonly operations?: OperationSelection;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export function fromMCP<const Reqs extends Readonly<Record<string, Requirement>>>(
|
|
19
|
-
endpoint: string,
|
|
20
|
-
options: FromMCPOptions<Reqs>,
|
|
21
|
-
): DynamicToolSet;
|
|
22
|
-
export function fromMCP(
|
|
23
|
-
endpoint: string,
|
|
24
|
-
options?: { readonly operations?: OperationSelection },
|
|
25
|
-
): DynamicToolSet;
|
|
26
|
-
export function fromMCP(
|
|
27
|
-
endpoint: string,
|
|
28
|
-
options?: {
|
|
29
|
-
readonly requirements?: Readonly<Record<string, Requirement>>;
|
|
30
|
-
readonly auth?: AuthComposeFn<never>;
|
|
31
|
-
readonly operations?: OperationSelection;
|
|
32
|
-
},
|
|
33
|
-
): DynamicToolSet {
|
|
34
|
-
const auth = options?.auth;
|
|
35
|
-
const operations = options?.operations;
|
|
36
|
-
return defineDynamicTools({
|
|
37
|
-
description: `Tools served by the MCP server at ${endpoint}.`,
|
|
38
|
-
...(options?.requirements === undefined ? {} : { requirements: options.requirements }),
|
|
39
|
-
discover: ({ ctx }) => mcpDiscover(endpoint, ctx, auth, operations),
|
|
40
|
-
call: ({ tool, input, ctx }) => mcpCall(endpoint, tool.name, input, ctx, auth),
|
|
41
|
-
});
|
|
42
|
-
}
|
package/src/openapi/index.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/** fromOpenAPI sugar over the authored dynamic-tools primitive. */
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
defineDynamicTools,
|
|
5
|
-
recordAuthoringProblem,
|
|
6
|
-
requirementSpecOf,
|
|
7
|
-
type AuthComposeFn,
|
|
8
|
-
type DynamicToolSet,
|
|
9
|
-
type OperationSelection,
|
|
10
|
-
type Requirement,
|
|
11
|
-
type RequiresAuthCompose,
|
|
12
|
-
} from "../authoring/index";
|
|
13
|
-
import { openapiCall, openapiDiscover } from "./mapper";
|
|
14
|
-
|
|
15
|
-
export type FromOpenAPIOptions<Reqs extends Readonly<Record<string, Requirement>>> = {
|
|
16
|
-
readonly requirements: Reqs;
|
|
17
|
-
readonly auth?: AuthComposeFn<NoInfer<Reqs>>;
|
|
18
|
-
readonly operations?: OperationSelection;
|
|
19
|
-
} & (RequiresAuthCompose<Reqs> extends true
|
|
20
|
-
? { readonly auth: AuthComposeFn<NoInfer<Reqs>> }
|
|
21
|
-
: unknown);
|
|
22
|
-
|
|
23
|
-
const enforceSecretsPlacement = (
|
|
24
|
-
requirements: Readonly<Record<string, Requirement>> | undefined,
|
|
25
|
-
auth: AuthComposeFn<never> | undefined,
|
|
26
|
-
): void => {
|
|
27
|
-
if (auth !== undefined) return;
|
|
28
|
-
for (const value of Object.values(requirements ?? {})) {
|
|
29
|
-
const spec = requirementSpecOf(value);
|
|
30
|
-
const methods = spec?.grant === undefined
|
|
31
|
-
? Object.values(spec?.service.auth ?? {})
|
|
32
|
-
: [spec.service.auth?.[spec.grant]].filter((method) => method !== undefined);
|
|
33
|
-
if (methods.some((method) => method.kind === "secrets"))
|
|
34
|
-
recordAuthoringProblem(
|
|
35
|
-
"fromOpenAPI: the service offers a secrets() auth method, so 'auth' must state how the credential rides",
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export type OpenAPIDocumentInput = string | Readonly<Record<string, unknown>>;
|
|
41
|
-
|
|
42
|
-
export function fromOpenAPI<const Reqs extends Readonly<Record<string, Requirement>>>(
|
|
43
|
-
spec: OpenAPIDocumentInput,
|
|
44
|
-
options: FromOpenAPIOptions<Reqs>,
|
|
45
|
-
): DynamicToolSet;
|
|
46
|
-
export function fromOpenAPI(
|
|
47
|
-
spec: OpenAPIDocumentInput,
|
|
48
|
-
options?: { readonly operations?: OperationSelection },
|
|
49
|
-
): DynamicToolSet;
|
|
50
|
-
export function fromOpenAPI(
|
|
51
|
-
spec: OpenAPIDocumentInput,
|
|
52
|
-
options?: {
|
|
53
|
-
readonly requirements?: Readonly<Record<string, Requirement>>;
|
|
54
|
-
readonly auth?: AuthComposeFn<never>;
|
|
55
|
-
readonly operations?: OperationSelection;
|
|
56
|
-
},
|
|
57
|
-
): DynamicToolSet {
|
|
58
|
-
enforceSecretsPlacement(options?.requirements, options?.auth);
|
|
59
|
-
const auth = options?.auth;
|
|
60
|
-
const operations = options?.operations;
|
|
61
|
-
return defineDynamicTools({
|
|
62
|
-
description:
|
|
63
|
-
typeof spec === "string" && spec.startsWith("https://")
|
|
64
|
-
? `Operations from the OpenAPI document at ${spec}.`
|
|
65
|
-
: "Operations from an OpenAPI document shipped with the app.",
|
|
66
|
-
...(options?.requirements === undefined ? {} : { requirements: options.requirements }),
|
|
67
|
-
discover: ({ ctx }) => openapiDiscover(spec, ctx, auth, operations),
|
|
68
|
-
call: ({ tool, input, ctx }) => openapiCall(tool, input, ctx, auth),
|
|
69
|
-
});
|
|
70
|
-
}
|
package/src/openapi/mapper.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/** Stub-contract OpenAPI discovery and call mapper. */
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
AuthComposeFn,
|
|
5
|
-
DiscoveredToolSpec,
|
|
6
|
-
OperationSelection,
|
|
7
|
-
} from "../authoring/index";
|
|
8
|
-
|
|
9
|
-
export const openapiDiscover = async (
|
|
10
|
-
_spec: string | Readonly<Record<string, unknown>>,
|
|
11
|
-
_ctx: unknown,
|
|
12
|
-
_auth: AuthComposeFn<never> | undefined,
|
|
13
|
-
_operations: OperationSelection | undefined,
|
|
14
|
-
): Promise<readonly DiscoveredToolSpec[]> => {
|
|
15
|
-
throw new Error("openapi mapper not built yet");
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const openapiCall = async (
|
|
19
|
-
_tool: { readonly name: string; readonly detail: unknown },
|
|
20
|
-
_input: unknown,
|
|
21
|
-
_ctx: unknown,
|
|
22
|
-
_auth: AuthComposeFn<never> | undefined,
|
|
23
|
-
): Promise<unknown> => {
|
|
24
|
-
throw new Error("openapi mapper not built yet");
|
|
25
|
-
};
|
package/src/runner/index.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { Effect, FileSystem } from "effect";
|
|
2
|
-
import {
|
|
3
|
-
loadApp,
|
|
4
|
-
type LoadedApp,
|
|
5
|
-
type PublishError,
|
|
6
|
-
} from "../manifest/index";
|
|
7
|
-
import {
|
|
8
|
-
callTool,
|
|
9
|
-
discoverTool,
|
|
10
|
-
type CallOutcome,
|
|
11
|
-
type DiscoverOutcome,
|
|
12
|
-
} from "../runtime/index";
|
|
13
|
-
import { CallError, DiscoverError, type AppRunner } from "./protocol";
|
|
14
|
-
|
|
15
|
-
export * from "./protocol";
|
|
16
|
-
|
|
17
|
-
/** Creates a permissive in-process runner for local development and tests. */
|
|
18
|
-
export const localRunner = (appDir: string): AppRunner => {
|
|
19
|
-
let cachedLoad:
|
|
20
|
-
| Effect.Effect<LoadedApp, PublishError, FileSystem.FileSystem>
|
|
21
|
-
| undefined;
|
|
22
|
-
|
|
23
|
-
const loaded = (): Effect.Effect<LoadedApp, PublishError, FileSystem.FileSystem> =>
|
|
24
|
-
Effect.suspend(() => {
|
|
25
|
-
if (cachedLoad !== undefined) return cachedLoad;
|
|
26
|
-
return Effect.flatMap(Effect.cached(loadApp(appDir)), (effect) =>
|
|
27
|
-
Effect.sync(() => {
|
|
28
|
-
cachedLoad = effect;
|
|
29
|
-
return effect;
|
|
30
|
-
}).pipe(Effect.flatten),
|
|
31
|
-
);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const registryFor = (target: string) =>
|
|
35
|
-
loaded().pipe(
|
|
36
|
-
Effect.map(({ registry }) => registry),
|
|
37
|
-
Effect.mapError(
|
|
38
|
-
(error) => new CallError({
|
|
39
|
-
target,
|
|
40
|
-
kind: "handler",
|
|
41
|
-
reason: `app failed to load (${error.message})`,
|
|
42
|
-
}),
|
|
43
|
-
),
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
const settle = (target: string, outcome: CallOutcome): Effect.Effect<unknown, CallError> =>
|
|
47
|
-
outcome.ok
|
|
48
|
-
? Effect.succeed(outcome.value)
|
|
49
|
-
: Effect.fail(new CallError({
|
|
50
|
-
target,
|
|
51
|
-
kind: outcome.kind,
|
|
52
|
-
reason: outcome.reason,
|
|
53
|
-
}));
|
|
54
|
-
|
|
55
|
-
const settleDiscovery = (
|
|
56
|
-
segment: string,
|
|
57
|
-
outcome: DiscoverOutcome,
|
|
58
|
-
) => outcome.ok
|
|
59
|
-
? Effect.succeed(outcome.value)
|
|
60
|
-
: Effect.fail(new DiscoverError({ segment, reason: outcome.reason }));
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
manifest: () => Effect.map(loaded(), ({ result }) => result),
|
|
64
|
-
call: (address, input, ctx, detail) =>
|
|
65
|
-
registryFor(address).pipe(
|
|
66
|
-
Effect.flatMap((registry) =>
|
|
67
|
-
Effect.promise(() => callTool(registry, address, input, ctx, detail)),
|
|
68
|
-
),
|
|
69
|
-
Effect.flatMap((outcome) => settle(address, outcome)),
|
|
70
|
-
),
|
|
71
|
-
discover: (segment, ctx) =>
|
|
72
|
-
registryFor(segment).pipe(
|
|
73
|
-
Effect.mapError((error) => new DiscoverError({ segment, reason: error.reason })),
|
|
74
|
-
Effect.flatMap((registry) =>
|
|
75
|
-
Effect.promise(() => discoverTool(registry, segment, ctx)),
|
|
76
|
-
),
|
|
77
|
-
Effect.flatMap((outcome) => settleDiscovery(segment, outcome)),
|
|
78
|
-
),
|
|
79
|
-
};
|
|
80
|
-
};
|
package/src/runner/protocol.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { Data, type Effect, FileSystem } from "effect";
|
|
2
|
-
import type { AppManifestResult, PublishError } from "../manifest/contract";
|
|
3
|
-
import type {
|
|
4
|
-
CallFailureKind,
|
|
5
|
-
DiscoveredTool,
|
|
6
|
-
ToolCtx,
|
|
7
|
-
ToolCtxEntry,
|
|
8
|
-
} from "../runtime/index";
|
|
9
|
-
|
|
10
|
-
export type {
|
|
11
|
-
DiscoveredTool,
|
|
12
|
-
ToolCtx,
|
|
13
|
-
ToolCtxEntry,
|
|
14
|
-
ToolDescriptor,
|
|
15
|
-
} from "../runtime/index";
|
|
16
|
-
|
|
17
|
-
/** Which invocation phase failed. */
|
|
18
|
-
export type CallErrorKind = CallFailureKind;
|
|
19
|
-
|
|
20
|
-
/** A runner operation failure associated with its target and phase. */
|
|
21
|
-
export class CallError extends Data.TaggedError("CallError")<{
|
|
22
|
-
readonly target: string;
|
|
23
|
-
readonly kind: CallErrorKind;
|
|
24
|
-
readonly reason: string;
|
|
25
|
-
}> {
|
|
26
|
-
override get message(): string {
|
|
27
|
-
return `${this.target}: ${this.reason}`;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** A discovery failure associated with one dynamic segment. */
|
|
32
|
-
export class DiscoverError extends Data.TaggedError("DiscoverError")<{
|
|
33
|
-
readonly segment: string;
|
|
34
|
-
readonly reason: string;
|
|
35
|
-
}> {
|
|
36
|
-
override get message(): string {
|
|
37
|
-
return `${this.segment}: ${this.reason}`;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** The platform protocol implemented by an app execution environment. */
|
|
42
|
-
export interface AppRunner {
|
|
43
|
-
manifest(): Effect.Effect<AppManifestResult, PublishError, FileSystem.FileSystem>;
|
|
44
|
-
call(
|
|
45
|
-
address: string,
|
|
46
|
-
input: unknown,
|
|
47
|
-
ctx: ToolCtx,
|
|
48
|
-
detail?: unknown,
|
|
49
|
-
): Effect.Effect<unknown, CallError, FileSystem.FileSystem>;
|
|
50
|
-
discover(
|
|
51
|
-
segment: string,
|
|
52
|
-
ctx: ToolCtx,
|
|
53
|
-
): Effect.Effect<readonly DiscoveredTool[], DiscoverError, FileSystem.FileSystem>;
|
|
54
|
-
}
|