@amalgm/shell 0.1.112 → 0.1.114
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/PURPOSE.md +75 -6
- package/README.md +36 -7
- package/dist/authorization/device-key.d.ts +19 -0
- package/dist/authorization/device-key.js +81 -0
- package/dist/authorization/device-key.js.map +1 -0
- package/dist/authorization/index.d.ts +65 -0
- package/dist/authorization/index.js +63 -0
- package/dist/authorization/index.js.map +1 -0
- package/dist/authorization/issuer.d.ts +11 -0
- package/dist/authorization/issuer.js +76 -0
- package/dist/authorization/issuer.js.map +1 -0
- package/dist/authorization/key-store.d.ts +15 -0
- package/dist/authorization/key-store.js +148 -0
- package/dist/authorization/key-store.js.map +1 -0
- package/dist/authorization/recovery-client.d.ts +19 -0
- package/dist/authorization/recovery-client.js +102 -0
- package/dist/authorization/recovery-client.js.map +1 -0
- package/dist/authorization/recovery-host.d.ts +28 -0
- package/dist/authorization/recovery-host.js +93 -0
- package/dist/authorization/recovery-host.js.map +1 -0
- package/dist/authorization/recovery.d.ts +13 -0
- package/dist/authorization/recovery.js +27 -0
- package/dist/authorization/recovery.js.map +1 -0
- package/dist/authorization/secret-process.d.ts +2 -0
- package/dist/authorization/secret-process.js +32 -0
- package/dist/authorization/secret-process.js.map +1 -0
- package/dist/boot.d.ts +19 -11
- package/dist/boot.js +34 -25
- package/dist/boot.js.map +1 -1
- package/dist/builtin-agents.d.ts +3 -0
- package/dist/builtin-agents.js +15 -0
- package/dist/builtin-agents.js.map +1 -0
- package/dist/chat-composition.d.ts +19 -0
- package/dist/chat-composition.js +83 -0
- package/dist/chat-composition.js.map +1 -0
- package/dist/chat-host.d.ts +9 -25
- package/dist/chat-host.js +12 -158
- package/dist/chat-host.js.map +1 -1
- package/dist/cli.js +21 -13
- package/dist/cli.js.map +1 -1
- package/dist/content-cache-host.d.ts +7 -0
- package/dist/content-cache-host.js +23 -1
- package/dist/content-cache-host.js.map +1 -1
- package/dist/credentials-host.d.ts +1 -5
- package/dist/credentials-host.js +1 -5
- package/dist/credentials-host.js.map +1 -1
- package/dist/entity-record-store.d.ts +2 -0
- package/dist/entity-record-store.js +15 -0
- package/dist/entity-record-store.js.map +1 -1
- package/dist/forward.js +1 -1
- package/dist/forward.js.map +1 -1
- package/dist/index.d.ts +7 -6
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/machine-host.d.ts +29 -0
- package/dist/machine-host.js +240 -10
- package/dist/machine-host.js.map +1 -1
- package/dist/parity.d.ts +1 -5
- package/dist/parity.js +4 -41
- package/dist/parity.js.map +1 -1
- package/dist/registry-graph.d.ts +61 -0
- package/dist/registry-graph.js +156 -0
- package/dist/registry-graph.js.map +1 -0
- package/dist/release-catalog.js +7 -4
- package/dist/release-catalog.js.map +1 -1
- package/dist/runtime-command-host.d.ts +11 -0
- package/dist/runtime-command-host.js +65 -0
- package/dist/runtime-command-host.js.map +1 -1
- package/dist/user-ground-host.d.ts +13 -0
- package/dist/user-ground-host.js +449 -205
- package/dist/user-ground-host.js.map +1 -1
- package/dist/wire-client.js +1 -1
- package/package.json +15 -6
- package/dist/chat-payloads-host.d.ts +0 -8
- package/dist/chat-payloads-host.js +0 -76
- package/dist/chat-payloads-host.js.map +0 -1
- package/dist/chat-relay-host.d.ts +0 -24
- package/dist/chat-relay-host.js +0 -90
- package/dist/chat-relay-host.js.map +0 -1
- package/dist/drivers/claude-code.d.ts +0 -27
- package/dist/drivers/claude-code.js +0 -72
- package/dist/drivers/claude-code.js.map +0 -1
- package/dist/paged-mutation-submit.d.ts +0 -28
- package/dist/paged-mutation-submit.js +0 -61
- package/dist/paged-mutation-submit.js.map +0 -1
package/dist/wire-client.js
CHANGED
package/package.json
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amalgm/shell",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "The Amalgm
|
|
3
|
+
"version": "0.1.114",
|
|
4
|
+
"description": "The Amalgm runtime host assembled from the published @amalgm SDK capabilities.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"license": "UNLICENSED",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/amalgm-inc/amalgm-shell.git"
|
|
11
|
+
},
|
|
8
12
|
"main": "./dist/index.js",
|
|
9
13
|
"types": "./dist/index.d.ts",
|
|
10
14
|
"exports": {
|
|
11
15
|
".": {
|
|
12
16
|
"types": "./dist/index.d.ts",
|
|
13
17
|
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./authorization": {
|
|
20
|
+
"types": "./dist/authorization/index.d.ts",
|
|
21
|
+
"default": "./dist/authorization/index.js"
|
|
14
22
|
}
|
|
15
23
|
},
|
|
16
24
|
"files": [
|
|
@@ -30,17 +38,18 @@
|
|
|
30
38
|
"scripts": {
|
|
31
39
|
"build": "node --input-type=module -e \"import { rmSync } from 'node:fs'; rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.json",
|
|
32
40
|
"test": "npm run build && node --test --test-concurrency=1",
|
|
41
|
+
"test:released-package": "node scripts/released-package-e2e.mjs",
|
|
33
42
|
"parity": "npm run build && node scripts/parity-report.js",
|
|
34
43
|
"prepublishOnly": "npm test"
|
|
35
44
|
},
|
|
36
45
|
"dependencies": {
|
|
37
|
-
"@amalgm/agents": "0.
|
|
46
|
+
"@amalgm/agents": "0.2.0",
|
|
38
47
|
"@amalgm/apps": "0.1.1",
|
|
39
48
|
"@amalgm/automations": "0.1.2",
|
|
40
49
|
"@amalgm/browser": "0.1.0",
|
|
41
|
-
"@amalgm/chat": "0.1
|
|
42
|
-
"@amalgm/core": "0.2
|
|
43
|
-
"@amalgm/live": "0.2.
|
|
50
|
+
"@amalgm/chat": "0.2.1",
|
|
51
|
+
"@amalgm/core": "0.3.2",
|
|
52
|
+
"@amalgm/live": "0.2.54",
|
|
44
53
|
"@amalgm/tools": "0.1.3",
|
|
45
54
|
"@anthropic-ai/claude-agent-sdk": "^0.3.224",
|
|
46
55
|
"@homebridge/node-pty-prebuilt-multiarch": "0.13.1",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { BrickMount } from "./gateway.js";
|
|
2
|
-
/**
|
|
3
|
-
* Host effects for the chat brick's machine-payload API. The engine stores
|
|
4
|
-
* this map in SQLite `local_meta`; the shell preserves the same durable map
|
|
5
|
-
* contract in its existing system state directory. Record, GC, and HTTP laws
|
|
6
|
-
* remain in @amalgm/chat.
|
|
7
|
-
*/
|
|
8
|
-
export declare function chatPayloadsMount(stateDir: string): BrickMount;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { mkdirSync, readFileSync, renameSync, writeFileSync, } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { createChatPayloadApi } from "@amalgm/chat/api";
|
|
4
|
-
import { ChatPayloadStore } from "@amalgm/chat/warm";
|
|
5
|
-
const FILE_NAME = "chat-payloads.json";
|
|
6
|
-
/**
|
|
7
|
-
* Host effects for the chat brick's machine-payload API. The engine stores
|
|
8
|
-
* this map in SQLite `local_meta`; the shell preserves the same durable map
|
|
9
|
-
* contract in its existing system state directory. Record, GC, and HTTP laws
|
|
10
|
-
* remain in @amalgm/chat.
|
|
11
|
-
*/
|
|
12
|
-
export function chatPayloadsMount(stateDir) {
|
|
13
|
-
const api = createChatPayloadApi(new ChatPayloadStore({
|
|
14
|
-
store: fileStore(stateDir),
|
|
15
|
-
clockIso: () => new Date().toISOString(),
|
|
16
|
-
clockMs: () => Date.now(),
|
|
17
|
-
}));
|
|
18
|
-
return {
|
|
19
|
-
prefix: "/chat-payloads",
|
|
20
|
-
stream: async (req, res, pathname) => {
|
|
21
|
-
const url = new URL(req.url ?? "/", "http://localhost");
|
|
22
|
-
const request = new Request(`http://chat.local${pathname}${url.search}`, {
|
|
23
|
-
method: req.method ?? "GET",
|
|
24
|
-
headers: requestHeaders(req),
|
|
25
|
-
body: await requestBody(req),
|
|
26
|
-
});
|
|
27
|
-
await writeResponse(res, await api(request));
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function fileStore(stateDir) {
|
|
32
|
-
const path = join(stateDir, FILE_NAME);
|
|
33
|
-
return {
|
|
34
|
-
read() {
|
|
35
|
-
try {
|
|
36
|
-
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
37
|
-
return parsed && typeof parsed === "object" && !Array.isArray(parsed)
|
|
38
|
-
? parsed
|
|
39
|
-
: {};
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
return {};
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
write(payloads) {
|
|
46
|
-
mkdirSync(stateDir, { recursive: true });
|
|
47
|
-
const temporary = `${path}.${process.pid}.tmp`;
|
|
48
|
-
writeFileSync(temporary, JSON.stringify(payloads), "utf8");
|
|
49
|
-
renameSync(temporary, path);
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function requestHeaders(req) {
|
|
54
|
-
const headers = new Headers();
|
|
55
|
-
for (const [name, value] of Object.entries(req.headers)) {
|
|
56
|
-
if (typeof value === "string")
|
|
57
|
-
headers.set(name, value);
|
|
58
|
-
else if (value)
|
|
59
|
-
for (const item of value)
|
|
60
|
-
headers.append(name, item);
|
|
61
|
-
}
|
|
62
|
-
return headers;
|
|
63
|
-
}
|
|
64
|
-
async function requestBody(req) {
|
|
65
|
-
if (req.method === "GET" || req.method === "HEAD")
|
|
66
|
-
return undefined;
|
|
67
|
-
const chunks = [];
|
|
68
|
-
for await (const chunk of req)
|
|
69
|
-
chunks.push(chunk);
|
|
70
|
-
return chunks.length ? Buffer.concat(chunks).toString("utf8") : undefined;
|
|
71
|
-
}
|
|
72
|
-
async function writeResponse(res, response) {
|
|
73
|
-
res.writeHead(response.status, Object.fromEntries(response.headers.entries()));
|
|
74
|
-
res.end(Buffer.from(await response.arrayBuffer()));
|
|
75
|
-
}
|
|
76
|
-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IAAI,KAAK;gBAAE,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,KAAK,UAAU,WAAW,CAAC,GAAoB;IAC7C,IAAI,GAAG,CAAC,MAAM,KAAK,KAAK,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM;QAAE,OAAO,SAAS,CAAC;IACpE,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG;QAAE,MAAM,CAAC,IAAI,CAAC,KAAe,CAAC,CAAC;IAC5D,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC5E,CAAC;AAED,KAAK,UAAU,aAAa,CAAC,GAAmB,EAAE,QAAkB;IAClE,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAC/E,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { ChatRelayContract, ChatRelayTurn, RelayFetchPort } from "@amalgm/chat/relay";
|
|
2
|
-
import type { BrickMount } from "./gateway.js";
|
|
3
|
-
export interface ChatRelayHostConfig {
|
|
4
|
-
readonly proxyCredentials: () => Promise<{
|
|
5
|
-
readonly baseUrl: string;
|
|
6
|
-
readonly token: string;
|
|
7
|
-
}>;
|
|
8
|
-
readonly contractForInput?: (input: Record<string, unknown>) => ChatRelayContract | null;
|
|
9
|
-
readonly turnForSession: (sessionId: string) => ChatRelayTurn | null;
|
|
10
|
-
readonly defaultMcpServer?: (contract: ChatRelayContract) => unknown;
|
|
11
|
-
readonly fetch?: RelayFetchPort;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Node sockets and the frozen-contract registry for Chat's portable relay API.
|
|
15
|
-
* Destination, authentication, and header laws remain in @amalgm/chat.
|
|
16
|
-
*/
|
|
17
|
-
export declare class ChatRelayHost {
|
|
18
|
-
#private;
|
|
19
|
-
constructor(config: ChatRelayHostConfig);
|
|
20
|
-
/** First registration owns relay authority for the lifetime of a session. */
|
|
21
|
-
registerInput(input: Record<string, unknown>, sessionId: string): ChatRelayContract | null;
|
|
22
|
-
forget(sessionId: string): void;
|
|
23
|
-
mounts(): BrickMount[];
|
|
24
|
-
}
|
package/dist/chat-relay-host.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { createChatRelayApi } from "@amalgm/chat/relay";
|
|
2
|
-
/**
|
|
3
|
-
* Node sockets and the frozen-contract registry for Chat's portable relay API.
|
|
4
|
-
* Destination, authentication, and header laws remain in @amalgm/chat.
|
|
5
|
-
*/
|
|
6
|
-
export class ChatRelayHost {
|
|
7
|
-
#contracts = new Map();
|
|
8
|
-
#contractForInput;
|
|
9
|
-
#api;
|
|
10
|
-
constructor(config) {
|
|
11
|
-
this.#contractForInput = config.contractForInput;
|
|
12
|
-
this.#api = createChatRelayApi({
|
|
13
|
-
contractForSession: (sessionId) => this.#contracts.get(sessionId) ?? null,
|
|
14
|
-
turnForSession: config.turnForSession,
|
|
15
|
-
proxyCredentials: config.proxyCredentials,
|
|
16
|
-
defaultMcpServer: config.defaultMcpServer,
|
|
17
|
-
fetch: config.fetch ?? globalThis.fetch,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
/** First registration owns relay authority for the lifetime of a session. */
|
|
21
|
-
registerInput(input, sessionId) {
|
|
22
|
-
const next = this.#contractForInput?.(input) ?? null;
|
|
23
|
-
if (!next?.sessionId)
|
|
24
|
-
return null;
|
|
25
|
-
if (next.sessionId !== sessionId)
|
|
26
|
-
return next;
|
|
27
|
-
const existing = this.#contracts.get(next.sessionId);
|
|
28
|
-
if (existing)
|
|
29
|
-
return existing;
|
|
30
|
-
this.#contracts.set(next.sessionId, next);
|
|
31
|
-
return next;
|
|
32
|
-
}
|
|
33
|
-
forget(sessionId) {
|
|
34
|
-
this.#contracts.delete(sessionId);
|
|
35
|
-
}
|
|
36
|
-
mounts() {
|
|
37
|
-
return ["/egress", "/mcp-relay"].map((prefix) => ({
|
|
38
|
-
prefix,
|
|
39
|
-
stream: async (req, res, pathname) => this.#serve(req, res, pathname),
|
|
40
|
-
}));
|
|
41
|
-
}
|
|
42
|
-
async #serve(req, res, pathname) {
|
|
43
|
-
try {
|
|
44
|
-
const response = await this.#api(await fetchRequest(req, pathname));
|
|
45
|
-
res.writeHead(response.status, Object.fromEntries(response.headers.entries()));
|
|
46
|
-
if (!response.body) {
|
|
47
|
-
res.end();
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const reader = response.body.getReader();
|
|
51
|
-
while (!res.destroyed) {
|
|
52
|
-
const chunk = await reader.read();
|
|
53
|
-
if (chunk.done)
|
|
54
|
-
break;
|
|
55
|
-
res.write(Buffer.from(chunk.value));
|
|
56
|
-
}
|
|
57
|
-
if (!res.writableEnded)
|
|
58
|
-
res.end();
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
if (res.headersSent || res.destroyed)
|
|
62
|
-
return;
|
|
63
|
-
res.writeHead(500, { "content-type": "application/json" });
|
|
64
|
-
res.end(JSON.stringify({ error: error instanceof Error ? error.message : "internal error" }));
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
async function fetchRequest(req, pathname) {
|
|
69
|
-
const url = new URL(req.url ?? pathname, "http://chat.local");
|
|
70
|
-
const headers = new Headers();
|
|
71
|
-
for (const [name, value] of Object.entries(req.headers)) {
|
|
72
|
-
if (Array.isArray(value))
|
|
73
|
-
for (const item of value)
|
|
74
|
-
headers.append(name, item);
|
|
75
|
-
else if (value !== undefined)
|
|
76
|
-
headers.set(name, value);
|
|
77
|
-
}
|
|
78
|
-
const method = req.method ?? "GET";
|
|
79
|
-
const chunks = [];
|
|
80
|
-
if (method !== "GET" && method !== "HEAD") {
|
|
81
|
-
for await (const chunk of req)
|
|
82
|
-
chunks.push(chunk);
|
|
83
|
-
}
|
|
84
|
-
return new Request(`http://chat.local${pathname}${url.search}`, {
|
|
85
|
-
method,
|
|
86
|
-
headers,
|
|
87
|
-
body: chunks.length ? Buffer.concat(chunks) : undefined,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
//# sourceMappingURL=chat-relay-host.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chat-relay-host.js","sourceRoot":"","sources":["../src/chat-relay-host.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAiBxD;;;GAGG;AACH,MAAM,OAAO,aAAa;IACf,UAAU,GAAG,IAAI,GAAG,EAA6B,CAAC;IAClD,iBAAiB,CAA2C;IAC5D,IAAI,CAAwC;IAErD,YAAY,MAA2B;QACrC,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC,gBAAgB,CAAC;QACjD,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;YAC7B,kBAAkB,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,IAAI;YACzE,cAAc,EAAE,MAAM,CAAC,cAAc;YACrC,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;YACzC,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;YACzC,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK;SACxC,CAAC,CAAC;IACL,CAAC;IAED,6EAA6E;IAC7E,aAAa,CAAC,KAA8B,EAAE,SAAiB;QAC7D,MAAM,IAAI,GAAG,IAAI,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BAAE,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;aAC1E,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACzD,CAAC;IACD,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,KAAK,CAAC;IACnC,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,MAAM,KAAK,KAAK,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QAC1C,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG;YAAE,MAAM,CAAC,IAAI,CAAC,KAAe,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,IAAI,OAAO,CAAC,oBAAoB,QAAQ,GAAG,GAAG,CAAC,MAAM,EAAE,EAAE;QAC9D,MAAM;QACN,OAAO;QACP,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS;KACxD,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { ChatDriver } from "../chat-host.js";
|
|
2
|
-
/** The SDK surface the driver consumes: a prompt in, a message stream out. */
|
|
3
|
-
export type ClaudeQuery = (input: {
|
|
4
|
-
prompt: string;
|
|
5
|
-
options?: Record<string, unknown>;
|
|
6
|
-
}) => AsyncIterable<Record<string, unknown>>;
|
|
7
|
-
export interface ClaudeCodeDriverOptions {
|
|
8
|
-
/**
|
|
9
|
-
* The turn-running query function. Defaults to the real
|
|
10
|
-
* @anthropic-ai/claude-agent-sdk `query` — the same SDK the engine's
|
|
11
|
-
* claude adapter calls. Inject a fake to test the wiring without a model.
|
|
12
|
-
*/
|
|
13
|
-
query?: ClaudeQuery;
|
|
14
|
-
/** Extra SDK options merged over the defaults (model, cwd, mcpServers…). */
|
|
15
|
-
queryOptions?: Record<string, unknown>;
|
|
16
|
-
cwd?: string;
|
|
17
|
-
clockMs?: () => number;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* The real chat driver: the engine's claude adapter loop
|
|
21
|
-
* (chat-core/adapters/claude.js:99-161) composed from brick law. Every SDK
|
|
22
|
-
* message goes through the chat brick's Claude normalizer; the result
|
|
23
|
-
* message becomes usageFinal records, an error event when the turn failed,
|
|
24
|
-
* and done — the same order the engine yields them. Provider sessions are
|
|
25
|
-
* remembered per amalgm session so follow-up turns resume.
|
|
26
|
-
*/
|
|
27
|
-
export declare function createClaudeCodeDriver(options?: ClaudeCodeDriverOptions): ChatDriver;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { createEventConstructors } from "@amalgm/chat/events";
|
|
2
|
-
import { createClaudeNormalizer } from "@amalgm/chat/normalizers";
|
|
3
|
-
/**
|
|
4
|
-
* The real chat driver: the engine's claude adapter loop
|
|
5
|
-
* (chat-core/adapters/claude.js:99-161) composed from brick law. Every SDK
|
|
6
|
-
* message goes through the chat brick's Claude normalizer; the result
|
|
7
|
-
* message becomes usageFinal records, an error event when the turn failed,
|
|
8
|
-
* and done — the same order the engine yields them. Provider sessions are
|
|
9
|
-
* remembered per amalgm session so follow-up turns resume.
|
|
10
|
-
*/
|
|
11
|
-
export function createClaudeCodeDriver(options = {}) {
|
|
12
|
-
const events = createEventConstructors({ clockMs: options.clockMs ?? (() => Date.now()) });
|
|
13
|
-
const normalizer = createClaudeNormalizer(events);
|
|
14
|
-
const providerSessions = new Map();
|
|
15
|
-
return {
|
|
16
|
-
async run(input, emit) {
|
|
17
|
-
const query = options.query ??
|
|
18
|
-
(await import("@anthropic-ai/claude-agent-sdk")).query;
|
|
19
|
-
const resume = providerSessions.get(input.sessionId);
|
|
20
|
-
const state = { providerSessionId: resume ?? null };
|
|
21
|
-
emit(events.reasoningStarted({ providerSessionId: state.providerSessionId }));
|
|
22
|
-
const stream = query({
|
|
23
|
-
prompt: input.prompt,
|
|
24
|
-
options: {
|
|
25
|
-
cwd: options.cwd ?? process.cwd(),
|
|
26
|
-
permissionMode: "bypassPermissions",
|
|
27
|
-
includePartialMessages: true,
|
|
28
|
-
...(resume ? { resume } : {}),
|
|
29
|
-
...options.queryOptions,
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
for await (const message of stream) {
|
|
33
|
-
if (typeof message.session_id === "string" && message.session_id) {
|
|
34
|
-
providerSessions.set(input.sessionId, message.session_id);
|
|
35
|
-
state.providerSessionId = message.session_id;
|
|
36
|
-
}
|
|
37
|
-
const normalized = normalizer.normalizeClaudeMessage(message, state);
|
|
38
|
-
if (normalized.length > 0) {
|
|
39
|
-
for (const event of normalized)
|
|
40
|
-
emit(event);
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
if (message.type === "result") {
|
|
44
|
-
const raw = { source: "claude.sdk.message", method: "claude/result", payload: message };
|
|
45
|
-
const usageRecords = normalizer.usageRecordsFromClaudeResult(message, undefined);
|
|
46
|
-
if (usageRecords.length === 0) {
|
|
47
|
-
usageRecords.push(normalizer.usageFromClaude(message.usage, undefined));
|
|
48
|
-
}
|
|
49
|
-
for (const usageRecord of usageRecords) {
|
|
50
|
-
emit(events.usageFinal({
|
|
51
|
-
...usageRecord,
|
|
52
|
-
costUsd: usageRecords.length === 1 ? (message.total_cost_usd ?? null) : null,
|
|
53
|
-
}, { providerSessionId: state.providerSessionId, raw }));
|
|
54
|
-
}
|
|
55
|
-
if (message.is_error) {
|
|
56
|
-
const errors = Array.isArray(message.errors) ? message.errors.join("\n") : null;
|
|
57
|
-
emit(events.errorEvent(errors || message.stop_reason || "Claude turn failed", {
|
|
58
|
-
providerSessionId: state.providerSessionId,
|
|
59
|
-
raw,
|
|
60
|
-
}));
|
|
61
|
-
}
|
|
62
|
-
emit(events.done({
|
|
63
|
-
providerSessionId: state.providerSessionId,
|
|
64
|
-
stopReason: message.stop_reason || "end_turn",
|
|
65
|
-
raw,
|
|
66
|
-
}));
|
|
67
|
-
}
|
|
68
|
-
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,MAAM,CAAC,UAAU,CACf;4BACE,GAAG,WAAW;4BACd,OAAO,EAAE,YAAY,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI;yBAC7E,EACD,EAAE,iBAAiB,EAAE,KAAK,CAAC,iBAAiB,EAAE,GAAG,EAAE,CACpD,CACF,CAAC;oBACJ,CAAC;oBACD,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;wBACrB,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;wBAChF,IAAI,CACF,MAAM,CAAC,UAAU,CAAC,MAAM,IAAI,OAAO,CAAC,WAAW,IAAI,oBAAoB,EAAE;4BACvE,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;4BAC1C,GAAG;yBACJ,CAAC,CACH,CAAC;oBACJ,CAAC;oBACD,IAAI,CACF,MAAM,CAAC,IAAI,CAAC;wBACV,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;wBAC1C,UAAU,EAAG,OAAO,CAAC,WAAsB,IAAI,UAAU;wBACzD,GAAG;qBACJ,CAAC,CACH,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { WireClient } from "./wire-client.js";
|
|
2
|
-
/** Per-message law mirrored from the gateway's MAX_OPERATION_BYTES: an
|
|
3
|
-
* operation at or under this bound travels inline in the submit frame. */
|
|
4
|
-
export declare const MAX_INLINE_OPERATION_BYTES: number;
|
|
5
|
-
/** Byte slice size for staged pages, comfortably under the per-message law. */
|
|
6
|
-
export declare const MUTATION_PAGE_BYTES: number;
|
|
7
|
-
type Frame = Record<string, unknown> & {
|
|
8
|
-
type: string;
|
|
9
|
-
};
|
|
10
|
-
/** Publishes one mutation operation of any size as ONE atomic commit.
|
|
11
|
-
*
|
|
12
|
-
* The operation arrives as its canonical UTF-8 bytes, serialized exactly
|
|
13
|
-
* once by the caller — this function never re-serializes a graph. A small
|
|
14
|
-
* operation travels inline in the submit frame, byte-identical to the
|
|
15
|
-
* pre-paging wire. A larger one stages as byte pages of its canonical
|
|
16
|
-
* JSON, then submits a reference the gateway assembles into the same commit
|
|
17
|
-
* path — transport pages, the operation never does. Every attempt stages
|
|
18
|
-
* afresh, so a replay after a lost acknowledgement or dropped connection is
|
|
19
|
-
* self-sufficient: the authority answers a known mutation id with its
|
|
20
|
-
* original acknowledgement.
|
|
21
|
-
*
|
|
22
|
-
* Requires wire protocol >= 8: an older gateway drops the stage frame at its
|
|
23
|
-
* admission list and a paged publish could never complete. Paging is a
|
|
24
|
-
* bridge — the gateway reassembles the whole graph and the database journals
|
|
25
|
-
* it as one large operation; the eventual endpoint is immutable graph pages
|
|
26
|
-
* with a small atomically-committed graph-head pointer. */
|
|
27
|
-
export declare function submitMutationOperation(wire: Pick<WireClient, "request" | "requestBinary">, envelope: Record<string, unknown>, operation: Buffer, onLeg?: (leg: "stage" | "submit", durationMs: number) => void): Promise<Frame>;
|
|
28
|
-
export {};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
/** Per-message law mirrored from the gateway's MAX_OPERATION_BYTES: an
|
|
3
|
-
* operation at or under this bound travels inline in the submit frame. */
|
|
4
|
-
export const MAX_INLINE_OPERATION_BYTES = 8 * 1024 * 1024;
|
|
5
|
-
/** Byte slice size for staged pages, comfortably under the per-message law. */
|
|
6
|
-
export const MUTATION_PAGE_BYTES = 4 * 1024 * 1024;
|
|
7
|
-
/** Publishes one mutation operation of any size as ONE atomic commit.
|
|
8
|
-
*
|
|
9
|
-
* The operation arrives as its canonical UTF-8 bytes, serialized exactly
|
|
10
|
-
* once by the caller — this function never re-serializes a graph. A small
|
|
11
|
-
* operation travels inline in the submit frame, byte-identical to the
|
|
12
|
-
* pre-paging wire. A larger one stages as byte pages of its canonical
|
|
13
|
-
* JSON, then submits a reference the gateway assembles into the same commit
|
|
14
|
-
* path — transport pages, the operation never does. Every attempt stages
|
|
15
|
-
* afresh, so a replay after a lost acknowledgement or dropped connection is
|
|
16
|
-
* self-sufficient: the authority answers a known mutation id with its
|
|
17
|
-
* original acknowledgement.
|
|
18
|
-
*
|
|
19
|
-
* Requires wire protocol >= 8: an older gateway drops the stage frame at its
|
|
20
|
-
* admission list and a paged publish could never complete. Paging is a
|
|
21
|
-
* bridge — the gateway reassembles the whole graph and the database journals
|
|
22
|
-
* it as one large operation; the eventual endpoint is immutable graph pages
|
|
23
|
-
* with a small atomically-committed graph-head pointer. */
|
|
24
|
-
export async function submitMutationOperation(wire, envelope, operation, onLeg) {
|
|
25
|
-
const canonical = operation;
|
|
26
|
-
const started = performance.now();
|
|
27
|
-
if (canonical.byteLength <= MAX_INLINE_OPERATION_BYTES) {
|
|
28
|
-
const frame = await wire.request({
|
|
29
|
-
type: "shared.mutation.submit",
|
|
30
|
-
envelope: { ...envelope, operation: JSON.parse(canonical.toString("utf8")) },
|
|
31
|
-
}, ["shared.mutation.ack"]);
|
|
32
|
-
onLeg?.("submit", performance.now() - started);
|
|
33
|
-
return frame;
|
|
34
|
-
}
|
|
35
|
-
const staged = {
|
|
36
|
-
page_count: Math.ceil(canonical.byteLength / MUTATION_PAGE_BYTES),
|
|
37
|
-
operation_bytes: canonical.byteLength,
|
|
38
|
-
operation_sha256: createHash("sha256").update(canonical).digest("hex"),
|
|
39
|
-
};
|
|
40
|
-
for (let index = 0; index < staged.page_count; index += 1) {
|
|
41
|
-
const page = canonical.subarray(index * MUTATION_PAGE_BYTES, Math.min((index + 1) * MUTATION_PAGE_BYTES, canonical.byteLength));
|
|
42
|
-
await wire.requestBinary({
|
|
43
|
-
type: "shared.mutation.stage",
|
|
44
|
-
resource_id: envelope.resourceId,
|
|
45
|
-
mutation_id: envelope.mutationId,
|
|
46
|
-
page_index: index,
|
|
47
|
-
...staged,
|
|
48
|
-
bytes: page.byteLength,
|
|
49
|
-
}, page, ["shared.mutation.staged"]);
|
|
50
|
-
}
|
|
51
|
-
const submitStarted = performance.now();
|
|
52
|
-
onLeg?.("stage", submitStarted - started);
|
|
53
|
-
const frame = await wire.request({
|
|
54
|
-
type: "shared.mutation.submit",
|
|
55
|
-
envelope,
|
|
56
|
-
staged,
|
|
57
|
-
}, ["shared.mutation.ack"]);
|
|
58
|
-
onLeg?.("submit", performance.now() - submitStarted);
|
|
59
|
-
return frame;
|
|
60
|
-
}
|
|
61
|
-
//# sourceMappingURL=paged-mutation-submit.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"paged-mutation-submit.js","sourceRoot":"","sources":["../src/paged-mutation-submit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIzC;0EAC0E;AAC1E,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAE1D,+EAA+E;AAC/E,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAInD;;;;;;;;;;;;;;;;2DAgB2D;AAC3D,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,IAAmD,EACnD,QAAiC,EACjC,SAAiB,EACjB,KAA6D;IAE7D,MAAM,SAAS,GAAG,SAAS,CAAC;IAC5B,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAClC,IAAI,SAAS,CAAC,UAAU,IAAI,0BAA0B,EAAE,CAAC;QACvD,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC;YAC/B,IAAI,EAAE,wBAAwB;YAC9B,QAAQ,EAAE,EAAE,GAAG,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,SAA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