@amalgm/chat 0.1.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/PURPOSE.md +107 -0
- package/README.md +41 -0
- package/dist/contract/chat-input.d.ts +144 -0
- package/dist/contract/chat-input.d.ts.map +1 -0
- package/dist/contract/chat-input.js +261 -0
- package/dist/contract/chat-input.js.map +1 -0
- package/dist/contract/create.d.ts +191 -0
- package/dist/contract/create.d.ts.map +1 -0
- package/dist/contract/create.js +249 -0
- package/dist/contract/create.js.map +1 -0
- package/dist/contract/freeze.d.ts +85 -0
- package/dist/contract/freeze.d.ts.map +1 -0
- package/dist/contract/freeze.js +151 -0
- package/dist/contract/freeze.js.map +1 -0
- package/dist/contract/harnesses.d.ts +21 -0
- package/dist/contract/harnesses.d.ts.map +1 -0
- package/dist/contract/harnesses.js +39 -0
- package/dist/contract/harnesses.js.map +1 -0
- package/dist/contract/index.d.ts +17 -0
- package/dist/contract/index.d.ts.map +1 -0
- package/dist/contract/index.js +17 -0
- package/dist/contract/index.js.map +1 -0
- package/dist/contract/input.d.ts +45 -0
- package/dist/contract/input.d.ts.map +1 -0
- package/dist/contract/input.js +78 -0
- package/dist/contract/input.js.map +1 -0
- package/dist/contract/models.d.ts +57 -0
- package/dist/contract/models.d.ts.map +1 -0
- package/dist/contract/models.js +380 -0
- package/dist/contract/models.js.map +1 -0
- package/dist/contract/payload-merge.d.ts +76 -0
- package/dist/contract/payload-merge.d.ts.map +1 -0
- package/dist/contract/payload-merge.js +215 -0
- package/dist/contract/payload-merge.js.map +1 -0
- package/dist/events/constructors.d.ts +53 -0
- package/dist/events/constructors.d.ts.map +1 -0
- package/dist/events/constructors.js +217 -0
- package/dist/events/constructors.js.map +1 -0
- package/dist/events/index.d.ts +12 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +12 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/schema.d.ts +455 -0
- package/dist/events/schema.d.ts.map +1 -0
- package/dist/events/schema.js +228 -0
- package/dist/events/schema.js.map +1 -0
- package/dist/events/tool-display.d.ts +22 -0
- package/dist/events/tool-display.d.ts.map +1 -0
- package/dist/events/tool-display.js +60 -0
- package/dist/events/tool-display.js.map +1 -0
- package/dist/events/tool-shape.d.ts +48 -0
- package/dist/events/tool-shape.d.ts.map +1 -0
- package/dist/events/tool-shape.js +225 -0
- package/dist/events/tool-shape.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/normalizers/claude.d.ts +628 -0
- package/dist/normalizers/claude.d.ts.map +1 -0
- package/dist/normalizers/claude.js +603 -0
- package/dist/normalizers/claude.js.map +1 -0
- package/dist/normalizers/codex.d.ts +352 -0
- package/dist/normalizers/codex.d.ts.map +1 -0
- package/dist/normalizers/codex.js +485 -0
- package/dist/normalizers/codex.js.map +1 -0
- package/dist/normalizers/cursor.d.ts +34 -0
- package/dist/normalizers/cursor.d.ts.map +1 -0
- package/dist/normalizers/cursor.js +197 -0
- package/dist/normalizers/cursor.js.map +1 -0
- package/dist/normalizers/index.d.ts +13 -0
- package/dist/normalizers/index.d.ts.map +1 -0
- package/dist/normalizers/index.js +13 -0
- package/dist/normalizers/index.js.map +1 -0
- package/dist/normalizers/opencode.d.ts +81 -0
- package/dist/normalizers/opencode.d.ts.map +1 -0
- package/dist/normalizers/opencode.js +640 -0
- package/dist/normalizers/opencode.js.map +1 -0
- package/dist/normalizers/pi.d.ts +28 -0
- package/dist/normalizers/pi.d.ts.map +1 -0
- package/dist/normalizers/pi.js +160 -0
- package/dist/normalizers/pi.js.map +1 -0
- package/dist/ports.d.ts +14 -0
- package/dist/ports.d.ts.map +1 -0
- package/dist/ports.js +7 -0
- package/dist/ports.js.map +1 -0
- package/dist/transcript/index.d.ts +14 -0
- package/dist/transcript/index.d.ts.map +1 -0
- package/dist/transcript/index.js +12 -0
- package/dist/transcript/index.js.map +1 -0
- package/dist/transcript/message-reducer.d.ts +167 -0
- package/dist/transcript/message-reducer.d.ts.map +1 -0
- package/dist/transcript/message-reducer.js +400 -0
- package/dist/transcript/message-reducer.js.map +1 -0
- package/dist/transcript/part-accumulator.d.ts +24 -0
- package/dist/transcript/part-accumulator.d.ts.map +1 -0
- package/dist/transcript/part-accumulator.js +30 -0
- package/dist/transcript/part-accumulator.js.map +1 -0
- package/dist/transcript/tool-display.d.ts +14 -0
- package/dist/transcript/tool-display.d.ts.map +1 -0
- package/dist/transcript/tool-display.js +125 -0
- package/dist/transcript/tool-display.js.map +1 -0
- package/dist/transcript/tool-shape.d.ts +34 -0
- package/dist/transcript/tool-shape.d.ts.map +1 -0
- package/dist/transcript/tool-shape.js +216 -0
- package/dist/transcript/tool-shape.js.map +1 -0
- package/dist/turns/index.d.ts +11 -0
- package/dist/turns/index.d.ts.map +1 -0
- package/dist/turns/index.js +11 -0
- package/dist/turns/index.js.map +1 -0
- package/dist/turns/queries.d.ts +36 -0
- package/dist/turns/queries.d.ts.map +1 -0
- package/dist/turns/queries.js +37 -0
- package/dist/turns/queries.js.map +1 -0
- package/dist/turns/replay.d.ts +105 -0
- package/dist/turns/replay.d.ts.map +1 -0
- package/dist/turns/replay.js +163 -0
- package/dist/turns/replay.js.map +1 -0
- package/dist/turns/status.d.ts +49 -0
- package/dist/turns/status.d.ts.map +1 -0
- package/dist/turns/status.js +56 -0
- package/dist/turns/status.js.map +1 -0
- package/dist/turns/turn-store.d.ts +109 -0
- package/dist/turns/turn-store.d.ts.map +1 -0
- package/dist/turns/turn-store.js +169 -0
- package/dist/turns/turn-store.js.map +1 -0
- package/dist/usage/finalize.d.ts +57 -0
- package/dist/usage/finalize.d.ts.map +1 -0
- package/dist/usage/finalize.js +139 -0
- package/dist/usage/finalize.js.map +1 -0
- package/dist/usage/index.d.ts +11 -0
- package/dist/usage/index.d.ts.map +1 -0
- package/dist/usage/index.js +11 -0
- package/dist/usage/index.js.map +1 -0
- package/dist/usage/model-catalog.d.ts +50 -0
- package/dist/usage/model-catalog.d.ts.map +1 -0
- package/dist/usage/model-catalog.js +344 -0
- package/dist/usage/model-catalog.js.map +1 -0
- package/dist/usage/normalize.d.ts +103 -0
- package/dist/usage/normalize.d.ts.map +1 -0
- package/dist/usage/normalize.js +71 -0
- package/dist/usage/normalize.js.map +1 -0
- package/dist/usage/ports.d.ts +141 -0
- package/dist/usage/ports.d.ts.map +1 -0
- package/dist/usage/ports.js +113 -0
- package/dist/usage/ports.js.map +1 -0
- package/dist/usage/tokens.d.ts +79 -0
- package/dist/usage/tokens.d.ts.map +1 -0
- package/dist/usage/tokens.js +98 -0
- package/dist/usage/tokens.js.map +1 -0
- package/dist/warm/client-cache.d.ts +47 -0
- package/dist/warm/client-cache.d.ts.map +1 -0
- package/dist/warm/client-cache.js +48 -0
- package/dist/warm/client-cache.js.map +1 -0
- package/dist/warm/envelope-cache.d.ts +79 -0
- package/dist/warm/envelope-cache.d.ts.map +1 -0
- package/dist/warm/envelope-cache.js +85 -0
- package/dist/warm/envelope-cache.js.map +1 -0
- package/dist/warm/index.d.ts +16 -0
- package/dist/warm/index.d.ts.map +1 -0
- package/dist/warm/index.js +11 -0
- package/dist/warm/index.js.map +1 -0
- package/dist/warm/payload.d.ts +137 -0
- package/dist/warm/payload.d.ts.map +1 -0
- package/dist/warm/payload.js +112 -0
- package/dist/warm/payload.js.map +1 -0
- package/dist/warm/revision.d.ts +70 -0
- package/dist/warm/revision.d.ts.map +1 -0
- package/dist/warm/revision.js +63 -0
- package/dist/warm/revision.js.map +1 -0
- package/dist/warm/store-policy.d.ts +57 -0
- package/dist/warm/store-policy.d.ts.map +1 -0
- package/dist/warm/store-policy.js +89 -0
- package/dist/warm/store-policy.js.map +1 -0
- package/dist/wire/frames.d.ts +208 -0
- package/dist/wire/frames.d.ts.map +1 -0
- package/dist/wire/frames.js +245 -0
- package/dist/wire/frames.js.map +1 -0
- package/dist/wire/index.d.ts +7 -0
- package/dist/wire/index.d.ts.map +1 -0
- package/dist/wire/index.js +7 -0
- package/dist/wire/index.js.map +1 -0
- package/package.json +72 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The freeze algebra — engine `chat-core/contract.js:347-458` plus
|
|
3
|
+
* `chat-core/auth.js:66-68` (`fingerprint`), ported byte-exact.
|
|
4
|
+
*
|
|
5
|
+
* A session's runtime identity is the sha256 fingerprint of
|
|
6
|
+
* `frozenRuntimeFields`; the field ORDER inside that object is load-bearing
|
|
7
|
+
* (it is JSON.stringify'd) and must never change. Hashing is injected via
|
|
8
|
+
* `Sha256HexPort` (engine default: `node:crypto` sha256 hex digest).
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Engine `auth.js fingerprint()`: first 16 hex chars of sha256, or null for
|
|
12
|
+
* falsy input. Non-strings are coerced with `String()` exactly as the engine.
|
|
13
|
+
*/
|
|
14
|
+
export function fingerprint(value, sha256Hex) {
|
|
15
|
+
return value ? sha256Hex(String(value)).slice(0, 16) : null;
|
|
16
|
+
}
|
|
17
|
+
function normalizeMcpHeader(header, sha256Hex) {
|
|
18
|
+
return {
|
|
19
|
+
name: String(header?.name || '').toLowerCase(),
|
|
20
|
+
valueFingerprint: fingerprint(header?.value || '', sha256Hex),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function normalizeMcpServer(server, sha256Hex) {
|
|
24
|
+
return {
|
|
25
|
+
name: String(server?.name || ''),
|
|
26
|
+
type: String(server?.type || 'http'),
|
|
27
|
+
url: String(server?.url || ''),
|
|
28
|
+
headers: Array.isArray(server?.headers)
|
|
29
|
+
? server.headers
|
|
30
|
+
.map((header) => normalizeMcpHeader(header, sha256Hex))
|
|
31
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
32
|
+
: [],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Engine `frozenRuntimeFields` (`contract.js:365-394`). Field order in the
|
|
37
|
+
* returned object is byte-exact — `runtimeKey` stringifies it.
|
|
38
|
+
*/
|
|
39
|
+
export function frozenRuntimeFields(input, ports) {
|
|
40
|
+
const { sha256Hex } = ports;
|
|
41
|
+
const authIdentity = input.authMethod === 'amalgm'
|
|
42
|
+
? 'platform_proxy'
|
|
43
|
+
: input.auth?.tokenFingerprint || null;
|
|
44
|
+
const mcpServers = (Array.isArray(input.mcpServers) ? input.mcpServers : [])
|
|
45
|
+
.map((server) => normalizeMcpServer(server, sha256Hex))
|
|
46
|
+
.sort((a, b) => `${a.name}\0${a.type}\0${a.url}`.localeCompare(`${b.name}\0${b.type}\0${b.url}`));
|
|
47
|
+
return {
|
|
48
|
+
sessionId: input.sessionId,
|
|
49
|
+
userId: input.userId,
|
|
50
|
+
computerId: input.computerId,
|
|
51
|
+
harness: input.harness,
|
|
52
|
+
authMethod: input.authMethod,
|
|
53
|
+
auth: authIdentity,
|
|
54
|
+
modelId: input.modelId,
|
|
55
|
+
usageModelId: input.usageModelId,
|
|
56
|
+
cliModel: input.cliModel,
|
|
57
|
+
reasoningEffort: input.reasoningEffort || null,
|
|
58
|
+
fastMode: input.fastMode === true,
|
|
59
|
+
contextWindow: input.contextWindow ?? null,
|
|
60
|
+
maxTokens: input.maxTokens ?? null,
|
|
61
|
+
cwd: input.cwd,
|
|
62
|
+
runtimeHomeLayout: input.runtimeHomeLayout,
|
|
63
|
+
systemPrompt: fingerprint(input.systemPrompt || '', sha256Hex),
|
|
64
|
+
compiledAgentInstructions: fingerprint(input.compiledAgentInstructions || '', sha256Hex),
|
|
65
|
+
agentConfig: fingerprint(JSON.stringify(input.agentConfig || null), sha256Hex),
|
|
66
|
+
origin: fingerprint(JSON.stringify(input.origin || null), sha256Hex),
|
|
67
|
+
mcpServers: fingerprint(JSON.stringify(mcpServers), sha256Hex),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** Engine `runtimeKey` (`contract.js:396-398`): fingerprint of the frozen fields. */
|
|
71
|
+
export function runtimeKey(input, ports) {
|
|
72
|
+
return fingerprint(JSON.stringify(frozenRuntimeFields(input, ports)), ports.sha256Hex);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Engine `changedRuntimeFields` (`contract.js:405-410`): the frozen-field keys
|
|
76
|
+
* whose values differ between two contracts. Prefers precomputed
|
|
77
|
+
* `runtimeFields`; falls back to recomputing (hence the ports).
|
|
78
|
+
*/
|
|
79
|
+
export function changedRuntimeFields(current, next, ports) {
|
|
80
|
+
const currentFields = current?.runtimeFields || frozenRuntimeFields(current || {}, ports);
|
|
81
|
+
const nextFields = next?.runtimeFields || frozenRuntimeFields(next || {}, ports);
|
|
82
|
+
const keys = [...new Set([...Object.keys(currentFields), ...Object.keys(nextFields)])];
|
|
83
|
+
return keys.filter((key) => currentFields[key] !== nextFields[key]);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Engine `frozenContractChangedError` (`contract.js:412-421`). Message and
|
|
87
|
+
* `code` are byte-exact.
|
|
88
|
+
*/
|
|
89
|
+
export function frozenContractChangedError(current, next, ports) {
|
|
90
|
+
const changed = changedRuntimeFields(current, next, ports);
|
|
91
|
+
const label = changed.length ? ` (${changed.join(', ')})` : '';
|
|
92
|
+
const err = new Error(`Frozen session contract changed${label}; start a new session for auth/harness/computer/instruction/MCP changes`);
|
|
93
|
+
err.code = 'FROZEN_SESSION_CONTRACT_CHANGED';
|
|
94
|
+
err.changedFields = changed;
|
|
95
|
+
return err;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Engine `continueFrozenRuntimeContract` (`contract.js:423-458`): when the
|
|
99
|
+
* next turn's contract drifts, keep the frozen identity from the current
|
|
100
|
+
* contract, carry over per-turn fields from `next`, and record the drifted
|
|
101
|
+
* keys in `continuedFromChangedContract` (warn semantics — the turn proceeds).
|
|
102
|
+
*/
|
|
103
|
+
export function continueFrozenRuntimeContract(current, next, ports) {
|
|
104
|
+
if (!current)
|
|
105
|
+
return next;
|
|
106
|
+
const changed = changedRuntimeFields(current, next, ports);
|
|
107
|
+
if (changed.length === 0)
|
|
108
|
+
return next;
|
|
109
|
+
return {
|
|
110
|
+
...next,
|
|
111
|
+
userId: current.userId,
|
|
112
|
+
computerId: current.computerId,
|
|
113
|
+
agentId: current.agentId,
|
|
114
|
+
agentConfigId: current.agentConfigId,
|
|
115
|
+
agentConfig: current.agentConfig,
|
|
116
|
+
runtimeHomeLayout: current.runtimeHomeLayout,
|
|
117
|
+
harness: current.harness,
|
|
118
|
+
authMethod: current.authMethod,
|
|
119
|
+
modelId: current.modelId,
|
|
120
|
+
usageModelId: current.usageModelId,
|
|
121
|
+
cliModel: current.cliModel,
|
|
122
|
+
reasoningEffort: current.reasoningEffort,
|
|
123
|
+
fastMode: current.fastMode,
|
|
124
|
+
contextWindow: current.contextWindow,
|
|
125
|
+
maxTokens: current.maxTokens,
|
|
126
|
+
cwd: current.cwd,
|
|
127
|
+
origin: current.origin,
|
|
128
|
+
constructs: current.constructs,
|
|
129
|
+
localBaseUrl: current.localBaseUrl,
|
|
130
|
+
mcpServers: current.mcpServers,
|
|
131
|
+
systemPrompt: current.systemPrompt,
|
|
132
|
+
compiledAgentInstructions: current.compiledAgentInstructions,
|
|
133
|
+
usageOwner: current.usageOwner,
|
|
134
|
+
auth: current.auth,
|
|
135
|
+
runtimeFields: current.runtimeFields,
|
|
136
|
+
runtimeKey: current.runtimeKey,
|
|
137
|
+
continuedFromChangedContract: changed,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Engine `assertSameContract` (`contract.js:650-655`): hard rejection when
|
|
142
|
+
* the runtime key moved. Throws `frozenContractChangedError`.
|
|
143
|
+
*/
|
|
144
|
+
export function assertSameContract(current, next, ports) {
|
|
145
|
+
if (!current)
|
|
146
|
+
return;
|
|
147
|
+
if (current.runtimeKey !== next.runtimeKey) {
|
|
148
|
+
throw frozenContractChangedError(current, next, ports);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=freeze.js.map
|
|
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,OAAO,CAAC,OAAO;QACxB,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,eAAe,EAAE,OAAO,CAAC,eAAe;QACxC,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,yBAAyB,EAAE,OAAO,CAAC,yBAAyB;QAC5D,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,4BAA4B,EAAE,OAAO;KACtC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAY,EAAE,IAAS,EAAE,KAAkB;IAC5E,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,IAAI,OAAO,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU,EAAE,CAAC;QAC3C,MAAM,0BAA0B,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IACzD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Harness identity — engine `chat-core/contract.js:12-22` (agentToHarness)
|
|
3
|
+
* and the hard allowlist enforced by `createContract` (`contract.js:575-577`),
|
|
4
|
+
* ported byte-exact.
|
|
5
|
+
*/
|
|
6
|
+
/** The only harnesses the clean chat core accepts. Order as in the engine. */
|
|
7
|
+
export declare const SUPPORTED_HARNESSES: readonly ["claude_code", "codex", "opencode", "cursor", "pi"];
|
|
8
|
+
export type Harness = (typeof SUPPORTED_HARNESSES)[number];
|
|
9
|
+
/**
|
|
10
|
+
* Engine `agentToHarness`: map a UI agent id onto a harness id. Unknown
|
|
11
|
+
* non-empty values pass through unchanged (the allowlist check happens in
|
|
12
|
+
* `assertSupportedHarness` / `createContract`); empty input defaults to
|
|
13
|
+
* `'claude_code'`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function agentToHarness(agent: unknown): string;
|
|
16
|
+
/**
|
|
17
|
+
* The allowlist gate from `createContract` (`contract.js:575-577`).
|
|
18
|
+
* Throw message is byte-exact with the engine.
|
|
19
|
+
*/
|
|
20
|
+
export declare function assertSupportedHarness(harness: string): asserts harness is Harness;
|
|
21
|
+
//# sourceMappingURL=harnesses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"harnesses.d.ts","sourceRoot":"","sources":["../../src/contract/harnesses.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,8EAA8E;AAC9E,eAAO,MAAM,mBAAmB,+DAAgE,CAAC;AAEjG,MAAM,MAAM,OAAO,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE3D;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CASrD;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAIlF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Harness identity — engine `chat-core/contract.js:12-22` (agentToHarness)
|
|
3
|
+
* and the hard allowlist enforced by `createContract` (`contract.js:575-577`),
|
|
4
|
+
* ported byte-exact.
|
|
5
|
+
*/
|
|
6
|
+
/** The only harnesses the clean chat core accepts. Order as in the engine. */
|
|
7
|
+
export const SUPPORTED_HARNESSES = ['claude_code', 'codex', 'opencode', 'cursor', 'pi'];
|
|
8
|
+
/**
|
|
9
|
+
* Engine `agentToHarness`: map a UI agent id onto a harness id. Unknown
|
|
10
|
+
* non-empty values pass through unchanged (the allowlist check happens in
|
|
11
|
+
* `assertSupportedHarness` / `createContract`); empty input defaults to
|
|
12
|
+
* `'claude_code'`.
|
|
13
|
+
*/
|
|
14
|
+
export function agentToHarness(agent) {
|
|
15
|
+
const clean = String(agent || '').trim();
|
|
16
|
+
if (clean === 'claude')
|
|
17
|
+
return 'claude_code';
|
|
18
|
+
if (clean === 'codex')
|
|
19
|
+
return 'codex';
|
|
20
|
+
if (clean === 'opencode')
|
|
21
|
+
return 'opencode';
|
|
22
|
+
if (clean === 'cursor')
|
|
23
|
+
return 'cursor';
|
|
24
|
+
if (clean === 'pi')
|
|
25
|
+
return 'pi';
|
|
26
|
+
if (clean === 'claude_code')
|
|
27
|
+
return 'claude_code';
|
|
28
|
+
return clean || 'claude_code';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The allowlist gate from `createContract` (`contract.js:575-577`).
|
|
32
|
+
* Throw message is byte-exact with the engine.
|
|
33
|
+
*/
|
|
34
|
+
export function assertSupportedHarness(harness) {
|
|
35
|
+
if (!SUPPORTED_HARNESSES.includes(harness)) {
|
|
36
|
+
throw new Error(`Unsupported harness for clean chat core: ${harness}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=harnesses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"harnesses.js","sourceRoot":"","sources":["../../src/contract/harnesses.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,8EAA8E;AAC9E,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,aAAa,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,CAAU,CAAC;AAIjG;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACzC,IAAI,KAAK,KAAK,QAAQ;QAAE,OAAO,aAAa,CAAC;IAC7C,IAAI,KAAK,KAAK,OAAO;QAAE,OAAO,OAAO,CAAC;IACtC,IAAI,KAAK,KAAK,UAAU;QAAE,OAAO,UAAU,CAAC;IAC5C,IAAI,KAAK,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC;IACxC,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,IAAI,KAAK,KAAK,aAAa;QAAE,OAAO,aAAa,CAAC;IAClD,OAAO,KAAK,IAAI,aAAa,CAAC;AAChC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAe;IACpD,IAAI,CAAE,mBAAyC,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QAClE,MAAM,IAAI,KAAK,CAAC,4CAA4C,OAAO,EAAE,CAAC,CAAC;IACzE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @amalgm/chat contract — the frozen session contract.
|
|
3
|
+
*
|
|
4
|
+
* Sources of truth (engine working tree, ported byte-exact):
|
|
5
|
+
* - `runtime/scripts/chat-core/contract.js` → harnesses / models / freeze / create
|
|
6
|
+
* - `runtime/lib/chatInput.js` → chat-input
|
|
7
|
+
* - `runtime/scripts/chat-core/chat-payload.js:33-185` → payload-merge
|
|
8
|
+
* - `runtime/scripts/chat-core/input.js` → input
|
|
9
|
+
*/
|
|
10
|
+
export * from './harnesses.js';
|
|
11
|
+
export * from './models.js';
|
|
12
|
+
export * from './freeze.js';
|
|
13
|
+
export * from './create.js';
|
|
14
|
+
export * from './chat-input.js';
|
|
15
|
+
export * from './payload-merge.js';
|
|
16
|
+
export * from './input.js';
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contract/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @amalgm/chat contract — the frozen session contract.
|
|
3
|
+
*
|
|
4
|
+
* Sources of truth (engine working tree, ported byte-exact):
|
|
5
|
+
* - `runtime/scripts/chat-core/contract.js` → harnesses / models / freeze / create
|
|
6
|
+
* - `runtime/lib/chatInput.js` → chat-input
|
|
7
|
+
* - `runtime/scripts/chat-core/chat-payload.js:33-185` → payload-merge
|
|
8
|
+
* - `runtime/scripts/chat-core/input.js` → input
|
|
9
|
+
*/
|
|
10
|
+
export * from './harnesses.js';
|
|
11
|
+
export * from './models.js';
|
|
12
|
+
export * from './freeze.js';
|
|
13
|
+
export * from './create.js';
|
|
14
|
+
export * from './chat-input.js';
|
|
15
|
+
export * from './payload-merge.js';
|
|
16
|
+
export * from './input.js';
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/contract/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn input normalization — engine `chat-core/input.js`, ported byte-exact.
|
|
3
|
+
*
|
|
4
|
+
* Two effects are severed into injected ports:
|
|
5
|
+
* - `env` on the normalized input (engine: `process.env`)
|
|
6
|
+
* - the lazy `require('../amalgm-mcp/project-context/prompt')` in
|
|
7
|
+
* `promptText`/`openCodeParts` becomes an optional injected provider.
|
|
8
|
+
*/
|
|
9
|
+
export interface NormalizedInput {
|
|
10
|
+
text: string;
|
|
11
|
+
parts: unknown[];
|
|
12
|
+
files: unknown[];
|
|
13
|
+
systemPrompt: string;
|
|
14
|
+
env: Record<string, string | undefined>;
|
|
15
|
+
}
|
|
16
|
+
export interface NormalizeInputPorts {
|
|
17
|
+
/** Engine default: `process.env`. SDK default: `{}`. */
|
|
18
|
+
env?: Record<string, string | undefined> | undefined;
|
|
19
|
+
}
|
|
20
|
+
/** Engine `normalizeInput(payload)` (`input.js:10-25`). */
|
|
21
|
+
export declare function normalizeInput(payload: Record<string, any>, ports?: NormalizeInputPorts): NormalizedInput;
|
|
22
|
+
export interface PromptTextPorts {
|
|
23
|
+
/**
|
|
24
|
+
* Engine: `amalgm-mcp/project-context/prompt.js projectContextTurnUpdateBlock`
|
|
25
|
+
* — the per-turn project-context update block (empty in the common case).
|
|
26
|
+
* Omitted ⇒ no context update, exactly like an engine host without the
|
|
27
|
+
* module.
|
|
28
|
+
*/
|
|
29
|
+
projectContextTurnUpdate?(contract: unknown): string | null | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Called with the first line of the provider's error message when it
|
|
32
|
+
* throws. Engine default:
|
|
33
|
+
* `console.warn('[chat-core] project context turn update failed:', message)`.
|
|
34
|
+
*/
|
|
35
|
+
onProjectContextError?(message: string): void;
|
|
36
|
+
}
|
|
37
|
+
/** Engine `promptText(input, contract)` (`input.js:41-50`). */
|
|
38
|
+
export declare function promptText(input: NormalizedInput, contract: unknown, ports?: PromptTextPorts): string;
|
|
39
|
+
/** Engine `openCodeParts(input, contract)` (`input.js:52-62`). */
|
|
40
|
+
export declare function openCodeParts(input: NormalizedInput, contract: unknown, ports?: PromptTextPorts): Array<{
|
|
41
|
+
type: string;
|
|
42
|
+
text?: string;
|
|
43
|
+
path?: string;
|
|
44
|
+
}>;
|
|
45
|
+
//# sourceMappingURL=input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/contract/input.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,mBAAmB;IAClC,wDAAwD;IACxD,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,SAAS,CAAC;CACtD;AAED,2DAA2D;AAC3D,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,GAAE,mBAAwB,GAAG,eAAe,CAe7G;AAED,MAAM,WAAW,eAAe;IAC9B;;;;;OAKG;IACH,wBAAwB,CAAC,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACxE;;;;OAIG;IACH,qBAAqB,CAAC,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/C;AAiBD,+DAA+D;AAC/D,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,GAAE,eAAoB,GAAG,MAAM,CASzG;AAED,kEAAkE;AAClE,wBAAgB,aAAa,CAC3B,KAAK,EAAE,eAAe,EACtB,QAAQ,EAAE,OAAO,EACjB,KAAK,GAAE,eAAoB,GAC1B,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAUvD"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn input normalization — engine `chat-core/input.js`, ported byte-exact.
|
|
3
|
+
*
|
|
4
|
+
* Two effects are severed into injected ports:
|
|
5
|
+
* - `env` on the normalized input (engine: `process.env`)
|
|
6
|
+
* - the lazy `require('../amalgm-mcp/project-context/prompt')` in
|
|
7
|
+
* `promptText`/`openCodeParts` becomes an optional injected provider.
|
|
8
|
+
*/
|
|
9
|
+
function textFromPart(part) {
|
|
10
|
+
if (!part || typeof part !== 'object')
|
|
11
|
+
return '';
|
|
12
|
+
if (part.type === 'text' && typeof part.text === 'string')
|
|
13
|
+
return part.text;
|
|
14
|
+
if (typeof part.content === 'string')
|
|
15
|
+
return part.content;
|
|
16
|
+
return '';
|
|
17
|
+
}
|
|
18
|
+
/** Engine `normalizeInput(payload)` (`input.js:10-25`). */
|
|
19
|
+
export function normalizeInput(payload, ports = {}) {
|
|
20
|
+
const chatInput = payload.chatInput && typeof payload.chatInput === 'object' ? payload.chatInput : null;
|
|
21
|
+
const parts = Array.isArray(payload.userParts) && payload.userParts.length > 0
|
|
22
|
+
? payload.userParts
|
|
23
|
+
: Array.isArray(chatInput?.parts) && chatInput.parts.length > 0
|
|
24
|
+
? chatInput.parts
|
|
25
|
+
: [{ type: 'text', text: payload.prompt || '' }];
|
|
26
|
+
const text = String(payload.prompt || parts.map(textFromPart).filter(Boolean).join('\n') || '').trim();
|
|
27
|
+
return {
|
|
28
|
+
text,
|
|
29
|
+
parts,
|
|
30
|
+
files: Array.isArray(chatInput?.files) ? chatInput.files : [],
|
|
31
|
+
systemPrompt: payload.systemPrompt || chatInput?.agent?.systemPrompt || '',
|
|
32
|
+
env: ports.env ?? {},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
// Resumed provider threads cannot change their system prompt without busting
|
|
36
|
+
// the provider's prompt cache, so context freshness rides on the turn instead:
|
|
37
|
+
// when the project context revision moved since this session last saw it, the
|
|
38
|
+
// turn gets a compact update block prepended. Empty in the common case.
|
|
39
|
+
function projectContextTurnUpdate(contract, ports) {
|
|
40
|
+
if (!ports.projectContextTurnUpdate)
|
|
41
|
+
return '';
|
|
42
|
+
try {
|
|
43
|
+
return ports.projectContextTurnUpdate(contract) || '';
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
const message = error instanceof Error ? error.message.split('\n')[0] : String(error);
|
|
47
|
+
ports.onProjectContextError?.(message);
|
|
48
|
+
return '';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** Engine `promptText(input, contract)` (`input.js:41-50`). */
|
|
52
|
+
export function promptText(input, contract, ports = {}) {
|
|
53
|
+
const chunks = [];
|
|
54
|
+
const contextUpdate = projectContextTurnUpdate(contract, ports);
|
|
55
|
+
if (contextUpdate)
|
|
56
|
+
chunks.push(contextUpdate);
|
|
57
|
+
if (input.files?.length) {
|
|
58
|
+
chunks.push(`<files>\n${input.files.map((file) => JSON.stringify(file)).join('\n')}\n</files>`);
|
|
59
|
+
}
|
|
60
|
+
chunks.push(input.text || '');
|
|
61
|
+
return chunks.filter(Boolean).join('\n\n');
|
|
62
|
+
}
|
|
63
|
+
/** Engine `openCodeParts(input, contract)` (`input.js:52-62`). */
|
|
64
|
+
export function openCodeParts(input, contract, ports = {}) {
|
|
65
|
+
const text = input.text || input.parts.map(textFromPart).filter(Boolean).join('\n');
|
|
66
|
+
const out = [];
|
|
67
|
+
const contextUpdate = projectContextTurnUpdate(contract, ports);
|
|
68
|
+
if (contextUpdate)
|
|
69
|
+
out.push({ type: 'text', text: contextUpdate });
|
|
70
|
+
if (text)
|
|
71
|
+
out.push({ type: 'text', text });
|
|
72
|
+
for (const file of (input.files || [])) {
|
|
73
|
+
if (file?.path)
|
|
74
|
+
out.push({ type: 'file', path: file.path });
|
|
75
|
+
}
|
|
76
|
+
return out.length ? out : [{ type: 'text', text: '' }];
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../src/contract/input.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,SAAS,YAAY,CAAC,IAAS;IAC7B,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IACjD,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,IAAI,CAAC;IAC5E,IAAI,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,OAAO,CAAC;IAC1D,OAAO,EAAE,CAAC;AACZ,CAAC;AAeD,2DAA2D;AAC3D,MAAM,UAAU,cAAc,CAAC,OAA4B,EAAE,QAA6B,EAAE;IAC1F,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,OAAO,OAAO,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;IACxG,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC;QAC5E,CAAC,CAAC,OAAO,CAAC,SAAS;QACnB,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,SAAS,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;YAC7D,CAAC,CAAC,SAAS,CAAC,KAAK;YACjB,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,M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,EAAE,CAAC;QACtF,IAAI,IAAI,EAAE,IAAI;YAAE,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model identity tables — engine `chat-core/contract.js:23-345`, ported
|
|
3
|
+
* byte-exact. A model has four identities:
|
|
4
|
+
*
|
|
5
|
+
* - display id — what the UI sent (`payload.modelId`)
|
|
6
|
+
* - canonical id — `canonicalModel()`: the billing identity
|
|
7
|
+
* (`contract.modelId` / `usageModelId`)
|
|
8
|
+
* - runtime-CLI id — `cliModelFor()`: what the harness CLI is launched with
|
|
9
|
+
* (`contract.cliModel`)
|
|
10
|
+
* - context profile — derived downstream from the canonical id
|
|
11
|
+
*
|
|
12
|
+
* The alias tables below are the frozen law: every row's spelling, order, and
|
|
13
|
+
* precedence must match the engine exactly, because `runtimeKey` fingerprints
|
|
14
|
+
* their outputs.
|
|
15
|
+
*/
|
|
16
|
+
export declare const GATEWAY_PROVIDERS: readonly ["prime-intellect", "arcee-ai", "alibaba", "amazon", "anthropic", "bytedance", "cohere", "cursor", "deepseek", "google", "inception", "kwaipilot", "meituan", "meta", "minimax", "mistral", "moonshotai", "morph", "nvidia", "openai", "perplexity", "xiaomi", "xai", "zai"];
|
|
17
|
+
export declare function gatewayModelId(raw: unknown): string;
|
|
18
|
+
export declare const CURSOR_CLI_ALIASES: Readonly<Record<string, string>>;
|
|
19
|
+
export declare const CURSOR_CANONICAL_MODEL_ALIASES: Readonly<Record<string, string>>;
|
|
20
|
+
export declare function cursorCliAlias(cliModel: string): string;
|
|
21
|
+
export declare function cursorAnthropicCliModel(model: string): string;
|
|
22
|
+
export declare function cursorCliModelFor(raw: unknown): string;
|
|
23
|
+
/**
|
|
24
|
+
* Claude Code display-id -> canonical billing-id alias table
|
|
25
|
+
* (`contract.js:171-240`). Keys are matched after `vercel/` strip +
|
|
26
|
+
* lowercase.
|
|
27
|
+
*/
|
|
28
|
+
export declare const CLAUDE_CODE_MODEL_ALIASES: Readonly<Record<string, string>>;
|
|
29
|
+
/**
|
|
30
|
+
* `canonicalModel(modelId, harness)` — engine `contract.js:164-258`.
|
|
31
|
+
* Throw message ("modelId is required for <harness>") is byte-exact.
|
|
32
|
+
*/
|
|
33
|
+
export declare function canonicalModel(modelId: unknown, harness: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Claude Code canonical/display -> CLI launch alias table
|
|
36
|
+
* (`contract.js:264-284`). Looked up first by canonical id, then by the
|
|
37
|
+
* lowercased raw input, else the raw input passes through.
|
|
38
|
+
*/
|
|
39
|
+
export declare const CLAUDE_CODE_CLI_ALIASES: Readonly<Record<string, string>>;
|
|
40
|
+
/**
|
|
41
|
+
* OpenCode gateway providers (`contract.js:312-334`). NOTE: intentionally a
|
|
42
|
+
* different list from `GATEWAY_PROVIDERS` — the engine's opencode branch omits
|
|
43
|
+
* 'moonshotai', 'morph', and 'nvidia'. Byte-parity requires keeping both.
|
|
44
|
+
*/
|
|
45
|
+
export declare const OPENCODE_GATEWAY_PROVIDERS: readonly ["prime-intellect", "arcee-ai", "alibaba", "amazon", "anthropic", "bytedance", "cohere", "cursor", "deepseek", "google", "inception", "kwaipilot", "meituan", "meta", "minimax", "mistral", "openai", "perplexity", "xiaomi", "xai", "zai"];
|
|
46
|
+
export interface CliModelForArgs {
|
|
47
|
+
harness: string;
|
|
48
|
+
modelId?: unknown;
|
|
49
|
+
cliModel?: unknown;
|
|
50
|
+
reasoningEffort?: unknown;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* `cliModelFor({ harness, modelId, cliModel, reasoningEffort })` — engine
|
|
54
|
+
* `contract.js:260-345`: the runtime-CLI identity for a model.
|
|
55
|
+
*/
|
|
56
|
+
export declare function cliModelFor({ harness, modelId, cliModel, reasoningEffort }: CliModelForArgs): string;
|
|
57
|
+
//# sourceMappingURL=models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/contract/models.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,eAAO,MAAM,iBAAiB,uRAyBpB,CAAC;AAGX,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAQnD;AAED,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAuB/D,CAAC;AAEF,eAAO,MAAM,8BAA8B,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAwB3E,CAAC;AAEF,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CA0B7D;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAgBtD;AAED;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAqEtE,CAAC;AAEF;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAyBxE;AAED;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAoBpE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,sPAsB7B,CAAC;AAEX,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,OA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