@zergai/ztc 0.12.1-dev.202611080256 → 0.13.0-beta.1
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/bin/zmux-darwin-arm64 +0 -0
- package/bin/ztc-audio-darwin-arm64 +0 -0
- package/bin/ztc-capture-darwin-arm64 +0 -0
- package/bin/ztc-computer-darwin-arm64 +0 -0
- package/bin/ztc-llm-darwin-arm64 +0 -0
- package/bin/ztc-tts-darwin-arm64 +0 -0
- package/bin/ztc-tui-darwin-arm64 +0 -0
- package/bin/zterm-darwin-arm64 +0 -0
- package/dist/agent/tools/sim.js +7 -0
- package/dist/cli_ratatui.d.ts +6 -1
- package/dist/cli_ratatui.js +26 -16
- package/dist/config.d.ts +10 -0
- package/dist/config.js +14 -6
- package/dist/simulation/inference.d.ts +11 -1
- package/dist/simulation/inference.js +102 -51
- package/dist/simulation/llm.js +6 -1
- package/dist/simulation/memory/embedding.d.ts +15 -9
- package/dist/simulation/memory/embedding.js +57 -54
- package/dist/simulation/world/memory_manager.d.ts +7 -2
- package/dist/simulation/world/memory_manager.js +6 -4
- package/dist/simulation/world/state.d.ts +6 -0
- package/dist/simulation/world/state.js +17 -1
- package/dist/zlm-embed.mjs +15 -5
- package/package.json +13 -7
package/bin/zmux-darwin-arm64
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/bin/ztc-llm-darwin-arm64
CHANGED
|
Binary file
|
package/bin/ztc-tts-darwin-arm64
CHANGED
|
Binary file
|
package/bin/ztc-tui-darwin-arm64
CHANGED
|
Binary file
|
package/bin/zterm-darwin-arm64
CHANGED
|
Binary file
|
package/dist/agent/tools/sim.js
CHANGED
|
@@ -39,6 +39,11 @@ function ensureSimLoaded() {
|
|
|
39
39
|
})();
|
|
40
40
|
return _simLoaded;
|
|
41
41
|
}
|
|
42
|
+
/** What the world just started or loaded tells the person, such as that its memory runs without embeddings. */
|
|
43
|
+
function worldNotices(state) {
|
|
44
|
+
const notices = state.getNotices();
|
|
45
|
+
return notices.length > 0 ? { notices } : {};
|
|
46
|
+
}
|
|
42
47
|
// ── sim_init ──
|
|
43
48
|
export const simInitTool = {
|
|
44
49
|
definition: {
|
|
@@ -103,6 +108,7 @@ When target_counts is set, use sim_next_target() in a loop after setup to genera
|
|
|
103
108
|
retrievalWeights: config.retrievalWeights,
|
|
104
109
|
reflectionThreshold: config.reflectionThreshold,
|
|
105
110
|
},
|
|
111
|
+
...worldNotices(state),
|
|
106
112
|
});
|
|
107
113
|
},
|
|
108
114
|
};
|
|
@@ -587,6 +593,7 @@ export const simCheckpointLoadTool = {
|
|
|
587
593
|
checkpointPath,
|
|
588
594
|
agentCount: state.getAllAgents().length,
|
|
589
595
|
artifactCount: state.getArtifacts().length,
|
|
596
|
+
...worldNotices(state),
|
|
590
597
|
});
|
|
591
598
|
},
|
|
592
599
|
};
|
package/dist/cli_ratatui.d.ts
CHANGED
|
@@ -261,6 +261,7 @@ export declare class RatatuiApp {
|
|
|
261
261
|
private workspacePausedSnapshot;
|
|
262
262
|
private workspacePausedEffectCwd;
|
|
263
263
|
private workspacePausedQueueId;
|
|
264
|
+
/** Input held over a workspace pause, and whether the person entered it (see handleSubmit's `person`). */
|
|
264
265
|
private workspacePendingInputs;
|
|
265
266
|
private workspaceDeferredRun;
|
|
266
267
|
private workspaceAdmissionTail;
|
|
@@ -992,10 +993,14 @@ export declare class RatatuiApp {
|
|
|
992
993
|
private askForSendCredential;
|
|
993
994
|
private localWorkspace;
|
|
994
995
|
private retireWorkspaceChoice;
|
|
995
|
-
/**
|
|
996
|
+
/**
|
|
997
|
+
* Only accepted-but-unadmitted sources belong to this local pause. `person`: the person entered it, so /sessions
|
|
998
|
+
* continue sends it as theirs, with its one real attempt past a Zerg Router refusal.
|
|
999
|
+
*/
|
|
996
1000
|
private retainWorkspaceInput;
|
|
997
1001
|
private chooseWorkspaceAction;
|
|
998
1002
|
private pauseWorkspace;
|
|
1003
|
+
/** `person`: the person entered `input` themselves, which a pause keeps with it (see retainWorkspaceInput). */
|
|
999
1004
|
private guardWorkspaceAdmission;
|
|
1000
1005
|
private waitForWorkspaceContinuation;
|
|
1001
1006
|
private admitWorkspaceTool;
|
package/dist/cli_ratatui.js
CHANGED
|
@@ -569,6 +569,7 @@ export class RatatuiApp {
|
|
|
569
569
|
workspacePausedSnapshot = null;
|
|
570
570
|
workspacePausedEffectCwd = null;
|
|
571
571
|
workspacePausedQueueId = null;
|
|
572
|
+
/** Input held over a workspace pause, and whether the person entered it (see handleSubmit's `person`). */
|
|
572
573
|
workspacePendingInputs = [];
|
|
573
574
|
workspaceDeferredRun = false;
|
|
574
575
|
workspaceAdmissionTail = Promise.resolve();
|
|
@@ -8729,7 +8730,7 @@ export class RatatuiApp {
|
|
|
8729
8730
|
}
|
|
8730
8731
|
// Resolve local overlap while the full input is still unadmitted, before
|
|
8731
8732
|
// a busy classifier or any provider can receive the candidate source.
|
|
8732
|
-
if (!queuedEntryId && !await this.guardWorkspaceAdmission(input))
|
|
8733
|
+
if (!queuedEntryId && !await this.guardWorkspaceAdmission(input, undefined, undefined, undefined, person))
|
|
8733
8734
|
return;
|
|
8734
8735
|
// Enter during a run steers the current turn at its next tool boundary.
|
|
8735
8736
|
// Tab remains the explicit after-turn queue.
|
|
@@ -8992,9 +8993,15 @@ export class RatatuiApp {
|
|
|
8992
8993
|
this.workspaceChoice?.finish(null);
|
|
8993
8994
|
return pending;
|
|
8994
8995
|
}
|
|
8995
|
-
/**
|
|
8996
|
-
|
|
8997
|
-
|
|
8996
|
+
/**
|
|
8997
|
+
* Only accepted-but-unadmitted sources belong to this local pause. `person`: the person entered it, so /sessions
|
|
8998
|
+
* continue sends it as theirs, with its one real attempt past a Zerg Router refusal.
|
|
8999
|
+
*/
|
|
9000
|
+
retainWorkspaceInput(input, person) {
|
|
9001
|
+
this.workspacePendingInputs.push({
|
|
9002
|
+
input: { ...input, attachments: input.attachments.map(attachment => ({ ...attachment })) },
|
|
9003
|
+
person,
|
|
9004
|
+
});
|
|
8998
9005
|
this.restoreBusyDraft(input);
|
|
8999
9006
|
}
|
|
9000
9007
|
chooseWorkspaceAction(snapshot, signal) {
|
|
@@ -9044,20 +9051,21 @@ export class RatatuiApp {
|
|
|
9044
9051
|
ownedIds.push(id);
|
|
9045
9052
|
});
|
|
9046
9053
|
}
|
|
9047
|
-
async pauseWorkspace(snapshot, input, cancelled = false, queuedEntryId, effectCwd) {
|
|
9054
|
+
async pauseWorkspace(snapshot, input, cancelled = false, queuedEntryId, effectCwd, person = false) {
|
|
9048
9055
|
this.workspacePaused = true;
|
|
9049
9056
|
this.workspacePausedSnapshot = snapshot;
|
|
9050
9057
|
this.workspacePausedEffectCwd = effectCwd ?? null;
|
|
9051
9058
|
this.workspacePausedQueueId = queuedEntryId ?? null;
|
|
9052
9059
|
await this.localWorkspace().setActivity('paused');
|
|
9053
9060
|
if (input && !queuedEntryId && !this.exiting)
|
|
9054
|
-
this.retainWorkspaceInput(input);
|
|
9061
|
+
this.retainWorkspaceInput(input, person);
|
|
9055
9062
|
if (!this.exiting)
|
|
9056
9063
|
this.addSystemMessage(cancelled
|
|
9057
9064
|
? 'Workspace decision cancelled. Input retained. Use /sessions continue when ready.'
|
|
9058
9065
|
: 'This session is paused. Prompt, attachments and queued work are retained. Use /sessions continue when ready.');
|
|
9059
9066
|
}
|
|
9060
|
-
|
|
9067
|
+
/** `person`: the person entered `input` themselves, which a pause keeps with it (see retainWorkspaceInput). */
|
|
9068
|
+
async guardWorkspaceAdmission(input, signal, cwd, queuedEntryId, person = false) {
|
|
9061
9069
|
if (this.isHostedRuntime())
|
|
9062
9070
|
return !this.exiting && !signal?.aborted;
|
|
9063
9071
|
const epoch = this.workspaceEpoch;
|
|
@@ -9074,7 +9082,7 @@ export class RatatuiApp {
|
|
|
9074
9082
|
}
|
|
9075
9083
|
if (this.workspacePaused) {
|
|
9076
9084
|
if (input && !queuedEntryId) {
|
|
9077
|
-
this.retainWorkspaceInput(input);
|
|
9085
|
+
this.retainWorkspaceInput(input, person);
|
|
9078
9086
|
// Enter once did nothing visible here: the prompt went back into the composer silently (2026-10-27).
|
|
9079
9087
|
if (!this.exiting)
|
|
9080
9088
|
this.addSystemMessage('This session is paused for a workspace overlap. Your message is kept; run /sessions continue to send it.');
|
|
@@ -9119,7 +9127,7 @@ export class RatatuiApp {
|
|
|
9119
9127
|
coordinator.acknowledge(latest);
|
|
9120
9128
|
return true;
|
|
9121
9129
|
}
|
|
9122
|
-
await this.pauseWorkspace(snapshot, input, choice === null, queuedEntryId, cwd);
|
|
9130
|
+
await this.pauseWorkspace(snapshot, input, choice === null, queuedEntryId, cwd, person);
|
|
9123
9131
|
if (choice === 'isolate')
|
|
9124
9132
|
await this.isolateWorkspace();
|
|
9125
9133
|
return false;
|
|
@@ -9131,7 +9139,7 @@ export class RatatuiApp {
|
|
|
9131
9139
|
if (queuedEntryId)
|
|
9132
9140
|
this.workspacePausedQueueId = queuedEntryId;
|
|
9133
9141
|
if (input && !queuedEntryId)
|
|
9134
|
-
this.retainWorkspaceInput(input);
|
|
9142
|
+
this.retainWorkspaceInput(input, person);
|
|
9135
9143
|
this.addErrorMessage(`Workspace admission failed. Input retained: ${String(error)}`);
|
|
9136
9144
|
}
|
|
9137
9145
|
return false;
|
|
@@ -9213,14 +9221,15 @@ export class RatatuiApp {
|
|
|
9213
9221
|
const retained = this.workspacePendingInputs.splice(0);
|
|
9214
9222
|
const deferred = this.workspaceDeferredRun;
|
|
9215
9223
|
this.workspaceDeferredRun = false;
|
|
9216
|
-
for (const
|
|
9224
|
+
for (const entry of retained) {
|
|
9217
9225
|
if (this.exiting || this.workspacePaused) {
|
|
9218
|
-
this.workspacePendingInputs.push(
|
|
9226
|
+
this.workspacePendingInputs.push(entry);
|
|
9219
9227
|
continue;
|
|
9220
9228
|
}
|
|
9221
|
-
if (getPlainText(this.inputState.segments) === input.text)
|
|
9229
|
+
if (getPlainText(this.inputState.segments) === entry.input.text)
|
|
9222
9230
|
this.setInputToText('', 0);
|
|
9223
|
-
|
|
9231
|
+
// What the person typed is still theirs: it keeps its one real attempt past a Zerg Router refusal.
|
|
9232
|
+
await this.handleSubmit(entry.input, undefined, undefined, false, false, entry.person);
|
|
9224
9233
|
}
|
|
9225
9234
|
if (deferred && retained.length === 0 && !this.exiting) {
|
|
9226
9235
|
this.pendingAgentTurn = true;
|
|
@@ -9239,9 +9248,10 @@ export class RatatuiApp {
|
|
|
9239
9248
|
const queuedInput = this.workspacePausedQueueId
|
|
9240
9249
|
? this.controller.getQueue().find(entry => entry.id === this.workspacePausedQueueId)
|
|
9241
9250
|
: undefined;
|
|
9251
|
+
const pending = this.workspacePendingInputs[0];
|
|
9242
9252
|
const input = queuedInput
|
|
9243
9253
|
? { text: queuedInput.text, attachments: queuedInput.attachments || [] }
|
|
9244
|
-
:
|
|
9254
|
+
: pending?.input;
|
|
9245
9255
|
if (input?.attachments.length) {
|
|
9246
9256
|
this.addSystemMessage('Attached tasks cannot yet be transferred to an isolated pane. Your text and images are retained.');
|
|
9247
9257
|
return;
|
|
@@ -9273,7 +9283,7 @@ export class RatatuiApp {
|
|
|
9273
9283
|
this.workspacePausedQueueId = null;
|
|
9274
9284
|
}
|
|
9275
9285
|
else {
|
|
9276
|
-
if (this.workspacePendingInputs[0] ===
|
|
9286
|
+
if (pending && this.workspacePendingInputs[0] === pending)
|
|
9277
9287
|
this.workspacePendingInputs.shift();
|
|
9278
9288
|
if (input && getPlainText(this.inputState.segments) === input.text)
|
|
9279
9289
|
this.setInputToText('', 0);
|
package/dist/config.d.ts
CHANGED
|
@@ -262,6 +262,16 @@ export declare class ConfigStore {
|
|
|
262
262
|
origin: string;
|
|
263
263
|
token: string;
|
|
264
264
|
} | undefined;
|
|
265
|
+
/**
|
|
266
|
+
* The ZergAI platform login, for `destination` only when that is the platform's own Router proxy
|
|
267
|
+
* (`<API base>/api/zrouter`), the one place the platform issued it for. Any other Router, Zerg Router's own origin
|
|
268
|
+
* or one a profile or ZERG_PROXY_URL names, gets nothing. ZTC's chat route, its Router catalog and simulation memory
|
|
269
|
+
* all take the platform token from here.
|
|
270
|
+
*/
|
|
271
|
+
getPlatformProxyLogin(destination: string | undefined): {
|
|
272
|
+
origin: string;
|
|
273
|
+
token: string;
|
|
274
|
+
} | undefined;
|
|
265
275
|
getRouterCatalogConnection(destination?: string | undefined): RouterCatalogConnection | undefined;
|
|
266
276
|
/** New children use configured routing, not a parent's restored inference route. */
|
|
267
277
|
getChildAuthMode(): ZTCAuthMode;
|
package/dist/config.js
CHANGED
|
@@ -1557,6 +1557,17 @@ export class ConfigStore {
|
|
|
1557
1557
|
return undefined;
|
|
1558
1558
|
return { origin: credentials.origin, token: credentials.token };
|
|
1559
1559
|
}
|
|
1560
|
+
/**
|
|
1561
|
+
* The ZergAI platform login, for `destination` only when that is the platform's own Router proxy
|
|
1562
|
+
* (`<API base>/api/zrouter`), the one place the platform issued it for. Any other Router, Zerg Router's own origin
|
|
1563
|
+
* or one a profile or ZERG_PROXY_URL names, gets nothing. ZTC's chat route, its Router catalog and simulation memory
|
|
1564
|
+
* all take the platform token from here.
|
|
1565
|
+
*/
|
|
1566
|
+
getPlatformProxyLogin(destination) {
|
|
1567
|
+
const origin = normalizedOrigin(destination);
|
|
1568
|
+
const token = this.getAuthToken();
|
|
1569
|
+
return origin && token && origin === this.deriveZRouterUrl(this.getApiBaseUrl()) ? { origin, token } : undefined;
|
|
1570
|
+
}
|
|
1560
1571
|
getRouterCatalogConnection(destination = this.get().zergProxyUrl) {
|
|
1561
1572
|
const origin = normalizedOrigin(destination);
|
|
1562
1573
|
if (!origin)
|
|
@@ -1565,9 +1576,8 @@ export class ConfigStore {
|
|
|
1565
1576
|
if (credentials && !this.routerCredentialsError && credentials.origin === origin) {
|
|
1566
1577
|
return { origin, token: credentials.token, workspaceId: credentials.workspaceId };
|
|
1567
1578
|
}
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
return token ? { origin, token, workspaceId: this.getActiveWorkspace()?.id.toString() } : undefined;
|
|
1579
|
+
const platform = this.getPlatformProxyLogin(origin);
|
|
1580
|
+
return platform ? { origin, token: platform.token, workspaceId: this.getActiveWorkspace()?.id.toString() } : undefined;
|
|
1571
1581
|
}
|
|
1572
1582
|
/** New children use configured routing, not a parent's restored inference route. */
|
|
1573
1583
|
getChildAuthMode() {
|
|
@@ -1682,9 +1692,7 @@ export class ConfigStore {
|
|
|
1682
1692
|
// Legacy platform tokens belong only to its /api/zrouter endpoint. A
|
|
1683
1693
|
// standalone Router requires its own device login, including after logout.
|
|
1684
1694
|
// Modal shared endpoints are unavailable through the legacy platform proxy.
|
|
1685
|
-
|
|
1686
|
-
let authToken = provider !== 'modal' && proxyUrl?.replace(/\/+$/, '') === platformProxyUrl
|
|
1687
|
-
? this.getAuthToken() : undefined;
|
|
1695
|
+
let authToken = provider !== 'modal' ? this.getPlatformProxyLogin(proxyUrl)?.token : undefined;
|
|
1688
1696
|
let routerError = this.routerCredentialsError;
|
|
1689
1697
|
if (authMode !== 'direct' && this.routerCredentials && !routerError) {
|
|
1690
1698
|
if (proxyUrl?.replace(/\/+$/, '') !== this.routerCredentials.origin) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CodexReasoningEffort } from '../config/types.js';
|
|
2
|
+
import type { SimConfig } from './types/config.js';
|
|
2
3
|
export interface ResolvedSimulationInference {
|
|
3
4
|
provider: string;
|
|
4
5
|
model: string;
|
|
@@ -6,9 +7,18 @@ export interface ResolvedSimulationInference {
|
|
|
6
7
|
codexFastMode?: boolean;
|
|
7
8
|
apiKey?: string;
|
|
8
9
|
baseUrl?: string;
|
|
10
|
+
/** Where memory gets embeddings on this route, when it has a place for them (see embeddingEndpoint). */
|
|
9
11
|
embeddingApiKey?: string;
|
|
10
12
|
embeddingBaseUrl?: string;
|
|
11
13
|
embeddingModel?: string;
|
|
12
14
|
codexAuthFilePath?: string;
|
|
13
15
|
}
|
|
14
|
-
|
|
16
|
+
/** What a world says about its own route: its provider and model, and its inference settings. */
|
|
17
|
+
export type SimulationWorldRoute = Pick<SimConfig, 'provider' | 'model' | 'inference'>;
|
|
18
|
+
/**
|
|
19
|
+
* The route a simulation runs on: one given for the call, ZTC_SIM_PROVIDER and ZTC_SIM_MODEL, its world's own (the
|
|
20
|
+
* attached world unless `world` names one, as a world being built or restored does), else the profile's. Its provider
|
|
21
|
+
* is the one ZTC knows, however it is written ('Anthropic' is anthropic, as for ZTC's own chat): an id ZTC did not
|
|
22
|
+
* recognize got whichever vendor's key ZTC found first, and its backend was then built for the vendor it named.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveSimulationInference(explicitRoute?: Pick<ResolvedSimulationInference, 'provider' | 'model' | 'codexEffort' | 'codexFastMode'>, world?: SimulationWorldRoute | undefined): ResolvedSimulationInference;
|
|
@@ -1,83 +1,134 @@
|
|
|
1
|
+
import { normalizeProviderId } from '../agent/backends/provider_ids.js';
|
|
1
2
|
import { configStore } from '../config.js';
|
|
3
|
+
import { readApiKeyEnvReference } from '../config/provider_api_key_env.js';
|
|
2
4
|
import { getDefaultModel } from '../utils/models.js';
|
|
3
5
|
import { getSimState } from './world/state.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
/** What a custom endpoint gets when nothing gives it a key of its own (a local server needs none). No credential. */
|
|
7
|
+
const NO_ENDPOINT_KEY = 'local-inference';
|
|
8
|
+
/**
|
|
9
|
+
* The providers besides the custom endpoint whose chat backend sends to a base URL it is given, and the origin of
|
|
10
|
+
* their own API, which it uses without one (createBackendForProvider). The others always reach their own API.
|
|
11
|
+
*/
|
|
12
|
+
const OWN_ORIGINS = {
|
|
13
|
+
deepseek: 'https://api.deepseek.com',
|
|
14
|
+
fireworks: 'https://api.fireworks.ai',
|
|
15
|
+
};
|
|
16
|
+
const OPENAI_ORIGIN = 'https://api.openai.com';
|
|
17
|
+
function origin(url) {
|
|
18
|
+
if (!url)
|
|
19
|
+
return undefined;
|
|
20
|
+
try {
|
|
21
|
+
return new URL(url).origin;
|
|
13
22
|
}
|
|
14
|
-
|
|
23
|
+
catch {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** The world's own key: the one it gives, or the variable it names unless that holds another vendor's key or ZTC's. */
|
|
28
|
+
function ownKey(vendor, key, variable) {
|
|
29
|
+
return key || (variable ? readApiKeyEnvReference(variable, vendor) : undefined);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Where a simulation's chat goes and the key it carries. The world's own key goes to the world's endpoint. Otherwise
|
|
33
|
+
* the key ZTC keeps for the provider (configStore.getApiKey: the variable named for it, the saved key, its standard
|
|
34
|
+
* variable) goes only where ZTC itself would send it: the provider's own API, or for openai_compatible the custom
|
|
35
|
+
* endpoint ZTC is set up with. So OPENAI_API_KEY reaches OpenAI alone, and no provider's key reaches another vendor or
|
|
36
|
+
* an endpoint a world names.
|
|
37
|
+
*/
|
|
38
|
+
function chatEndpoint(provider, world) {
|
|
39
|
+
const compat = provider === 'openai_compatible';
|
|
40
|
+
const configured = compat ? configStore.getOpenAICompatibleBaseUrl() || undefined : undefined;
|
|
41
|
+
const baseUrl = world?.baseUrl || configured;
|
|
42
|
+
const own = ownKey(provider, world?.apiKey, world?.apiKeyEnvVar);
|
|
43
|
+
if (own)
|
|
44
|
+
return { apiKey: own, baseUrl };
|
|
45
|
+
const named = origin(world?.baseUrl);
|
|
46
|
+
const elsewhere = Boolean(world?.baseUrl) && (compat
|
|
47
|
+
? named !== origin(configured)
|
|
48
|
+
: Object.hasOwn(OWN_ORIGINS, provider) && named !== OWN_ORIGINS[provider]);
|
|
49
|
+
if (elsewhere)
|
|
50
|
+
return { apiKey: NO_ENDPOINT_KEY, baseUrl };
|
|
51
|
+
const apiKey = configStore.getApiKey(provider);
|
|
52
|
+
return { apiKey: apiKey ?? (compat && baseUrl ? NO_ENDPOINT_KEY : undefined), baseUrl };
|
|
15
53
|
}
|
|
16
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Where a simulation's memory gets embeddings on its route: an embedding key or endpoint its world configures, else
|
|
56
|
+
* the route itself when it serves embeddings (OpenAI with its key, a custom endpoint with its key and base URL), else
|
|
57
|
+
* none here (createEmbeddingProvider then tries the session's platform proxy, and otherwise stays lexical). A key goes
|
|
58
|
+
* to an embedding endpoint only when it is meant for it: the world's own embedding key, or the route's key at the
|
|
59
|
+
* route's own endpoint. Another provider's key never does, and OPENAI_API_KEY is never picked for a route that is not
|
|
60
|
+
* OpenAI's.
|
|
61
|
+
*/
|
|
62
|
+
function embeddingEndpoint(provider, chat, world) {
|
|
63
|
+
const embeddingModel = world?.embeddingModel;
|
|
64
|
+
const embeddingBaseUrl = world?.embeddingBaseUrl || undefined;
|
|
65
|
+
const target = origin(embeddingBaseUrl) ?? OPENAI_ORIGIN;
|
|
66
|
+
const vendor = target === OPENAI_ORIGIN ? 'openai' : 'openai_compatible';
|
|
67
|
+
const own = ownKey(vendor, world?.embeddingApiKey, world?.embeddingApiKeyEnvVar);
|
|
68
|
+
const routeOrigin = provider === 'openai' ? OPENAI_ORIGIN
|
|
69
|
+
: provider === 'openai_compatible' ? origin(chat.baseUrl) : undefined;
|
|
70
|
+
if (own || embeddingBaseUrl) {
|
|
71
|
+
const routeKey = routeOrigin === target ? chat.apiKey : undefined;
|
|
72
|
+
return { embeddingApiKey: own || routeKey || NO_ENDPOINT_KEY, embeddingBaseUrl, embeddingModel };
|
|
73
|
+
}
|
|
74
|
+
if (provider === 'openai' && chat.apiKey)
|
|
75
|
+
return { embeddingApiKey: chat.apiKey, embeddingModel };
|
|
76
|
+
if (provider === 'openai_compatible' && chat.baseUrl) {
|
|
77
|
+
return { embeddingApiKey: chat.apiKey || NO_ENDPOINT_KEY, embeddingBaseUrl: chat.baseUrl, embeddingModel };
|
|
78
|
+
}
|
|
79
|
+
return { embeddingModel };
|
|
80
|
+
}
|
|
81
|
+
/** A route's keys and endpoints, for its chat and its memory. */
|
|
82
|
+
function keyedRoute(provider, world) {
|
|
83
|
+
const chat = chatEndpoint(provider, world);
|
|
84
|
+
return { ...chat, ...embeddingEndpoint(provider, chat, world) };
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The route a simulation runs on: one given for the call, ZTC_SIM_PROVIDER and ZTC_SIM_MODEL, its world's own (the
|
|
88
|
+
* attached world unless `world` names one, as a world being built or restored does), else the profile's. Its provider
|
|
89
|
+
* is the one ZTC knows, however it is written ('Anthropic' is anthropic, as for ZTC's own chat): an id ZTC did not
|
|
90
|
+
* recognize got whichever vendor's key ZTC found first, and its backend was then built for the vendor it named.
|
|
91
|
+
*/
|
|
92
|
+
export function resolveSimulationInference(explicitRoute, world = getSimState()?.config) {
|
|
17
93
|
if (explicitRoute) {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
model: explicitRoute.model,
|
|
21
|
-
});
|
|
22
|
-
const apiKey = resolveApiKeyFromConfig(explicitRoute.provider);
|
|
23
|
-
const baseUrl = explicitRoute.provider === 'openai_compatible'
|
|
24
|
-
? configStore.getOpenAICompatibleBaseUrl() || undefined
|
|
25
|
-
: undefined;
|
|
94
|
+
const provider = normalizeProviderId(explicitRoute.provider);
|
|
95
|
+
const backendConfig = configStore.resolveLLMBackendConfig({ provider, model: explicitRoute.model });
|
|
26
96
|
return {
|
|
27
97
|
...explicitRoute,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
embeddingApiKey: apiKey,
|
|
31
|
-
embeddingBaseUrl: baseUrl,
|
|
98
|
+
provider,
|
|
99
|
+
...keyedRoute(provider),
|
|
32
100
|
codexAuthFilePath: backendConfig.codexAuthFilePath,
|
|
33
101
|
};
|
|
34
102
|
}
|
|
35
103
|
const envProvider = process.env.ZTC_SIM_PROVIDER;
|
|
36
104
|
const envModel = process.env.ZTC_SIM_MODEL;
|
|
37
105
|
if (envProvider && envModel) {
|
|
38
|
-
const
|
|
39
|
-
const baseUrl = envProvider === 'openai_compatible'
|
|
40
|
-
? configStore.getOpenAICompatibleBaseUrl() || undefined
|
|
41
|
-
: undefined;
|
|
106
|
+
const provider = normalizeProviderId(envProvider);
|
|
42
107
|
return {
|
|
43
|
-
provider
|
|
108
|
+
provider,
|
|
44
109
|
model: envModel,
|
|
45
|
-
codexEffort: configStore.getCodexEffort(
|
|
46
|
-
|
|
47
|
-
baseUrl,
|
|
48
|
-
embeddingApiKey: apiKey,
|
|
49
|
-
embeddingBaseUrl: baseUrl,
|
|
110
|
+
codexEffort: configStore.getCodexEffort(provider, envModel),
|
|
111
|
+
...keyedRoute(provider),
|
|
50
112
|
};
|
|
51
113
|
}
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const provider = inference?.provider ?? simConfig.provider;
|
|
57
|
-
const model = inference?.model ?? simConfig.model;
|
|
114
|
+
const inference = world?.inference;
|
|
115
|
+
if (world?.provider && world?.model) {
|
|
116
|
+
const provider = normalizeProviderId(inference?.provider ?? world.provider);
|
|
117
|
+
const model = inference?.model ?? world.model;
|
|
58
118
|
return {
|
|
59
119
|
provider,
|
|
60
120
|
model,
|
|
61
121
|
codexEffort: inference?.codexEffort
|
|
62
122
|
?? configStore.getCodexEffort(provider, model),
|
|
63
|
-
|
|
64
|
-
baseUrl: inference?.baseUrl,
|
|
65
|
-
embeddingApiKey: inference?.embeddingApiKey
|
|
66
|
-
?? (inference?.embeddingApiKeyEnvVar ? process.env[inference.embeddingApiKeyEnvVar] : undefined)
|
|
67
|
-
?? resolveApiKeyFromConfig(provider, inference?.apiKey, inference?.apiKeyEnvVar),
|
|
68
|
-
embeddingBaseUrl: inference?.embeddingBaseUrl ?? inference?.baseUrl,
|
|
69
|
-
embeddingModel: inference?.embeddingModel,
|
|
123
|
+
...keyedRoute(provider, inference),
|
|
70
124
|
};
|
|
71
125
|
}
|
|
72
|
-
const provider = configStore.getProvider();
|
|
126
|
+
const provider = normalizeProviderId(configStore.getProvider());
|
|
73
127
|
const model = configStore.get().model || getDefaultModel(provider, 'full');
|
|
74
128
|
return {
|
|
75
129
|
provider,
|
|
76
130
|
model,
|
|
77
131
|
codexEffort: configStore.getCodexEffort(provider, model),
|
|
78
|
-
|
|
79
|
-
baseUrl: configStore.getOpenAICompatibleBaseUrl() || undefined,
|
|
80
|
-
embeddingApiKey: configStore.getApiKey(provider) || process.env.OPENAI_API_KEY,
|
|
81
|
-
embeddingBaseUrl: configStore.getOpenAICompatibleBaseUrl() || undefined,
|
|
132
|
+
...keyedRoute(provider),
|
|
82
133
|
};
|
|
83
134
|
}
|
package/dist/simulation/llm.js
CHANGED
|
@@ -113,6 +113,10 @@ function getBackend(resolved) {
|
|
|
113
113
|
const apiKey = resolved.apiKey ?? configStore.getApiKey(provider);
|
|
114
114
|
if (!apiKey)
|
|
115
115
|
throw new Error('No API key configured for LLM fill');
|
|
116
|
+
// Without an endpoint, the custom-endpoint backend would send its key to OpenAI.
|
|
117
|
+
if (provider === 'openai_compatible' && !resolved.baseUrl) {
|
|
118
|
+
throw new Error('No custom endpoint is set up for the simulation: set one with /config openai-compat, or give its config inference.baseUrl.');
|
|
119
|
+
}
|
|
116
120
|
const cacheKey = [
|
|
117
121
|
provider,
|
|
118
122
|
apiKey,
|
|
@@ -124,7 +128,8 @@ function getBackend(resolved) {
|
|
|
124
128
|
return cachedBackend;
|
|
125
129
|
cachedBackend = createBackendForProvider(provider, {
|
|
126
130
|
apiKey,
|
|
127
|
-
|
|
131
|
+
// The route's own endpoint: the custom endpoint ZTC is set up with belongs to openai_compatible alone.
|
|
132
|
+
baseUrl: resolved.baseUrl,
|
|
128
133
|
codexAuthFilePath: resolved.codexAuthFilePath,
|
|
129
134
|
});
|
|
130
135
|
cachedBackendKey = cacheKey;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Embedding Provider — Real LM Embeddings
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Semantic embeddings through an OpenAI-compatible embeddings API, where the
|
|
5
|
+
* simulation has one (see createEmbeddingProvider); otherwise memory is lexical.
|
|
6
|
+
* text-embedding-3-small (1536 dims) costs little next to a period's completions.
|
|
7
7
|
*
|
|
8
8
|
* Research basis: Park et al. §4.1 — relevance scored by cosine similarity
|
|
9
9
|
* between memory embeddings and query embedding. TF-IDF was a placeholder;
|
|
10
10
|
* real embeddings enable semantic matching across paraphrases.
|
|
11
11
|
*/
|
|
12
|
+
import { type SimulationWorldRoute } from '../inference.js';
|
|
12
13
|
export interface EmbeddingProvider {
|
|
13
14
|
embed(text: string): Promise<number[]>;
|
|
14
15
|
embedBatch(texts: string[]): Promise<number[][]>;
|
|
@@ -46,10 +47,15 @@ export declare class ZeroEmbeddingProvider implements EmbeddingProvider {
|
|
|
46
47
|
embedBatch(texts: string[]): Promise<number[][]>;
|
|
47
48
|
}
|
|
48
49
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
50
|
+
* A simulation's embeddings, from the first of: an embedding key or endpoint its world configures; its own route when
|
|
51
|
+
* that serves embeddings, OpenAI with its key or a custom endpoint with its key and base URL (see
|
|
52
|
+
* resolveSimulationInference); the ZergAI platform's own proxy, with the platform login, as ZTC's own completions use it
|
|
53
|
+
* (configStore.getPlatformProxyLogin: no other Router, Zerg Router's own origin included, ever gets that login).
|
|
54
|
+
* Without any, memory stays lexical, no request is made, and `onNotice` hears why and how to give it embeddings (the
|
|
55
|
+
* simulation says it once). Another provider's key never reaches an embeddings endpoint, and OPENAI_API_KEY is not
|
|
56
|
+
* picked on its own for a route that is not OpenAI's: it never worked while a provider key was set (that key went
|
|
57
|
+
* instead, and OpenAI refused it), and picking it would start OpenAI charges nobody chose. `world` is the simulation's
|
|
58
|
+
* own config, for a world being built or restored, which is attached only after; without it, the route is the
|
|
59
|
+
* attached world's or the profile's.
|
|
54
60
|
*/
|
|
55
|
-
export declare function createEmbeddingProvider(cache: Map<string, number[]>,
|
|
61
|
+
export declare function createEmbeddingProvider(cache: Map<string, number[]>, world?: SimulationWorldRoute, onNotice?: (notice: string) => void): EmbeddingProvider;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Embedding Provider — Real LM Embeddings
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Semantic embeddings through an OpenAI-compatible embeddings API, where the
|
|
5
|
+
* simulation has one (see createEmbeddingProvider); otherwise memory is lexical.
|
|
6
|
+
* text-embedding-3-small (1536 dims) costs little next to a period's completions.
|
|
7
7
|
*
|
|
8
8
|
* Research basis: Park et al. §4.1 — relevance scored by cosine similarity
|
|
9
9
|
* between memory embeddings and query embedding. TF-IDF was a placeholder;
|
|
10
10
|
* real embeddings enable semantic matching across paraphrases.
|
|
11
11
|
*/
|
|
12
12
|
import { configStore } from '../../config.js';
|
|
13
|
+
import { normalizeProviderId } from '../../agent/backends/provider_ids.js';
|
|
13
14
|
import { resolveSimulationInference } from '../inference.js';
|
|
14
15
|
import { routerAccount, routerRefusalGate } from '../../agent/backends/router_gate.js';
|
|
15
16
|
import { endingRouterRefusal, readRouterRefusal } from '../../agent/backends/router_refusal.js';
|
|
@@ -169,57 +170,59 @@ export class ZeroEmbeddingProvider {
|
|
|
169
170
|
return texts.map(() => ZERO_VEC);
|
|
170
171
|
}
|
|
171
172
|
}
|
|
173
|
+
/** What a simulation without embeddings says once: that its memory matches words, and how to give it embeddings. */
|
|
174
|
+
function withoutEmbeddingsNotice(provider, model) {
|
|
175
|
+
return `Simulation memory runs without embeddings on ${provider}/${model}, so recall matches words, not meaning. `
|
|
176
|
+
+ 'For embeddings, run the simulation on openai or openai_compatible, or give its config inference.embeddingApiKey '
|
|
177
|
+
+ '(or embeddingApiKeyEnvVar) and, for an endpoint other than OpenAI\'s, inference.embeddingBaseUrl.';
|
|
178
|
+
}
|
|
179
|
+
/** What a ZergRouter simulation says once: why its memory matches words. No setting changes that, so it gives no remedy. */
|
|
180
|
+
function routerWithoutEmbeddingsNotice(model) {
|
|
181
|
+
return `Simulation memory runs without embeddings on zergrouter/${model}: a ZergRouter simulation calls only its chat `
|
|
182
|
+
+ 'model, so recall matches words, not meaning.';
|
|
183
|
+
}
|
|
184
|
+
/** Memory that matches words: zero vectors, and no request. */
|
|
185
|
+
function lexicalMemory(cache) {
|
|
186
|
+
return new CachedEmbeddingProvider(new ZeroEmbeddingProvider(), cache);
|
|
187
|
+
}
|
|
172
188
|
/**
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
189
|
+
* A simulation's embeddings, from the first of: an embedding key or endpoint its world configures; its own route when
|
|
190
|
+
* that serves embeddings, OpenAI with its key or a custom endpoint with its key and base URL (see
|
|
191
|
+
* resolveSimulationInference); the ZergAI platform's own proxy, with the platform login, as ZTC's own completions use it
|
|
192
|
+
* (configStore.getPlatformProxyLogin: no other Router, Zerg Router's own origin included, ever gets that login).
|
|
193
|
+
* Without any, memory stays lexical, no request is made, and `onNotice` hears why and how to give it embeddings (the
|
|
194
|
+
* simulation says it once). Another provider's key never reaches an embeddings endpoint, and OPENAI_API_KEY is not
|
|
195
|
+
* picked on its own for a route that is not OpenAI's: it never worked while a provider key was set (that key went
|
|
196
|
+
* instead, and OpenAI refused it), and picking it would start OpenAI charges nobody chose. `world` is the simulation's
|
|
197
|
+
* own config, for a world being built or restored, which is attached only after; without it, the route is the
|
|
198
|
+
* attached world's or the profile's.
|
|
178
199
|
*/
|
|
179
|
-
export function createEmbeddingProvider(cache,
|
|
180
|
-
//
|
|
181
|
-
if (
|
|
182
|
-
return
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
routerRoute = proxyUrl;
|
|
208
|
-
}
|
|
209
|
-
else if (provider === 'openai') {
|
|
210
|
-
apiKey = configStore.getApiKey('openai');
|
|
211
|
-
}
|
|
212
|
-
else if (provider === 'openai_compatible') {
|
|
213
|
-
apiKey = configStore.getApiKey('openai_compatible');
|
|
214
|
-
baseUrl = configStore.getOpenAICompatibleBaseUrl() || undefined;
|
|
215
|
-
}
|
|
216
|
-
// For non-OpenAI providers, require OPENAI_API_KEY for embeddings
|
|
217
|
-
if (!apiKey) {
|
|
218
|
-
apiKey = process.env.OPENAI_API_KEY;
|
|
219
|
-
}
|
|
220
|
-
if (!apiKey) {
|
|
221
|
-
throw new Error('OpenAI API key required for embeddings. ' +
|
|
222
|
-
'Set OPENAI_API_KEY environment variable, or use an OpenAI provider.');
|
|
223
|
-
}
|
|
224
|
-
return new CachedEmbeddingProvider(new OpenAIEmbeddingProvider(apiKey, baseUrl, model, routerRoute), cache);
|
|
200
|
+
export function createEmbeddingProvider(cache, world, onNotice) {
|
|
201
|
+
// Embeddings someone turned off need no route, and nothing said.
|
|
202
|
+
if (process.env.ZTC_SIM_DISABLE_EMBEDDINGS === '1')
|
|
203
|
+
return lexicalMemory(cache);
|
|
204
|
+
// A ZergRouter simulation calls only its one DeepSeek chat model, whatever route the environment names: its memory
|
|
205
|
+
// stays lexical and no embedding model is called, on Router or anywhere else.
|
|
206
|
+
if (world?.provider && normalizeProviderId(world.provider) === 'zergrouter') {
|
|
207
|
+
onNotice?.(routerWithoutEmbeddingsNotice(world.model));
|
|
208
|
+
return lexicalMemory(cache);
|
|
209
|
+
}
|
|
210
|
+
const inference = resolveSimulationInference(undefined, world);
|
|
211
|
+
if (inference.provider === 'zergrouter') {
|
|
212
|
+
onNotice?.(routerWithoutEmbeddingsNotice(inference.model));
|
|
213
|
+
return lexicalMemory(cache);
|
|
214
|
+
}
|
|
215
|
+
const model = inference.embeddingModel ?? EMBEDDING_MODEL;
|
|
216
|
+
if (inference.embeddingApiKey) {
|
|
217
|
+
const embeddings = new OpenAIEmbeddingProvider(inference.embeddingApiKey, inference.embeddingBaseUrl, model);
|
|
218
|
+
return new CachedEmbeddingProvider(embeddings, cache);
|
|
219
|
+
}
|
|
220
|
+
// A session signed in to the ZergAI platform embeds through the platform's own proxy, the one place its login goes.
|
|
221
|
+
const platform = configStore.getPlatformProxyLogin(configStore.get().zergProxyUrl);
|
|
222
|
+
if (platform) {
|
|
223
|
+
const embeddings = new OpenAIEmbeddingProvider(platform.token, `${platform.origin}/v1`, model, platform.origin);
|
|
224
|
+
return new CachedEmbeddingProvider(embeddings, cache);
|
|
225
|
+
}
|
|
226
|
+
onNotice?.(withoutEmbeddingsNotice(inference.provider, inference.model));
|
|
227
|
+
return lexicalMemory(cache);
|
|
225
228
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type AgentMemoryStore, type MemoryBackendKind, type MemoryStoreSnapshot } from '../memory/backend.js';
|
|
2
|
+
import type { SimulationWorldRoute } from '../inference.js';
|
|
2
3
|
import type { SimClock } from '../memory/sim_clock.js';
|
|
3
4
|
import type { InvariantMode } from '../memory/invariants.js';
|
|
4
5
|
import type { AgentScratch, ConceptNode, MemoryPrivacyLabel } from '../types.js';
|
|
@@ -12,7 +13,10 @@ export interface MemoryTelemetrySnapshot {
|
|
|
12
13
|
files: Array<[MemoryTelemetryFileName, number]>;
|
|
13
14
|
}
|
|
14
15
|
export interface MemoryManagerDeps {
|
|
15
|
-
|
|
16
|
+
/** The simulation's own route, which decides where its memory gets embeddings. */
|
|
17
|
+
route?: SimulationWorldRoute;
|
|
18
|
+
/** Hears what memory tells the person, such as that it runs without embeddings. */
|
|
19
|
+
onNotice?: (notice: string) => void;
|
|
16
20
|
invariantMode?: InvariantMode;
|
|
17
21
|
outputDir?: string;
|
|
18
22
|
backend?: MemoryBackendKind;
|
|
@@ -24,7 +28,8 @@ export declare class MemoryManager {
|
|
|
24
28
|
private memories;
|
|
25
29
|
private embeddings;
|
|
26
30
|
private embeddingProvider;
|
|
27
|
-
private readonly
|
|
31
|
+
private readonly route?;
|
|
32
|
+
private readonly onNotice?;
|
|
28
33
|
private clock;
|
|
29
34
|
private warnedOverflow;
|
|
30
35
|
private invariantMode?;
|
|
@@ -17,7 +17,8 @@ export class MemoryManager {
|
|
|
17
17
|
memories = new Map();
|
|
18
18
|
embeddings = new Map();
|
|
19
19
|
embeddingProvider;
|
|
20
|
-
|
|
20
|
+
route;
|
|
21
|
+
onNotice;
|
|
21
22
|
clock;
|
|
22
23
|
warnedOverflow = false;
|
|
23
24
|
invariantMode;
|
|
@@ -27,8 +28,9 @@ export class MemoryManager {
|
|
|
27
28
|
detachedTelemetry;
|
|
28
29
|
constructor(clock, deps) {
|
|
29
30
|
this.clock = clock;
|
|
30
|
-
this.
|
|
31
|
-
this.
|
|
31
|
+
this.route = deps?.route;
|
|
32
|
+
this.onNotice = deps?.onNotice;
|
|
33
|
+
this.embeddingProvider = createEmbeddingProvider(this.embeddings, this.route, this.onNotice);
|
|
32
34
|
this.invariantMode = deps?.invariantMode;
|
|
33
35
|
this.backend = deps?.backend ?? resolveMemoryBackendKind();
|
|
34
36
|
this.outputDir = deps?.outputDir;
|
|
@@ -160,7 +162,7 @@ export class MemoryManager {
|
|
|
160
162
|
m.setEmbeddingsAccessor(() => this.embeddings);
|
|
161
163
|
return [agentId, m];
|
|
162
164
|
}));
|
|
163
|
-
this.embeddingProvider = createEmbeddingProvider(this.embeddings, this.
|
|
165
|
+
this.embeddingProvider = createEmbeddingProvider(this.embeddings, this.route, this.onNotice);
|
|
164
166
|
this.warnedOverflow = false;
|
|
165
167
|
this.restoreTelemetry(normalized.telemetry);
|
|
166
168
|
}
|
|
@@ -109,6 +109,8 @@ export declare class SimState {
|
|
|
109
109
|
private _pendingMemoryWrites;
|
|
110
110
|
private _pendingMemoryWriteErrors;
|
|
111
111
|
private activeWorldTransition;
|
|
112
|
+
/** What this simulation tells the person, each once, such as that its memory runs without embeddings. */
|
|
113
|
+
private readonly notices;
|
|
112
114
|
constructor(goal: SimGoal, config: SimConfig, preset?: DomainPreset, restoredWorldId?: string, restoredWorldContext?: WorldContextSnapshot, detached?: boolean);
|
|
113
115
|
private get worldContext();
|
|
114
116
|
private get agentRegistry();
|
|
@@ -431,6 +433,10 @@ export declare class SimState {
|
|
|
431
433
|
saveCheckpoint(outputPath?: string, extensions?: CheckpointExtensions): string;
|
|
432
434
|
static loadCheckpoint(checkpointPath: string, outputDirectory?: string): Promise<SimState>;
|
|
433
435
|
static fromCheckpoint(raw: unknown, outputDirectory?: string, detached?: boolean): Promise<SimState>;
|
|
436
|
+
/** Says `notice` once: in this simulation's status and in what started or loaded it, and on stderr for a run nobody watches. */
|
|
437
|
+
private addNotice;
|
|
438
|
+
/** What this simulation tells the person, such as that its memory runs without embeddings. */
|
|
439
|
+
getNotices(): string[];
|
|
434
440
|
getStatus(): Record<string, unknown>;
|
|
435
441
|
getRuntimePeriodNumber(): number | null;
|
|
436
442
|
getCheckpointExtension(namespace: string): CheckpointExtension | null;
|
|
@@ -10,6 +10,7 @@ import { appendFileSync, closeSync, constants as fsConstants, existsSync, fstatS
|
|
|
10
10
|
import { basename, dirname, extname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
11
11
|
import { homedir } from 'node:os';
|
|
12
12
|
import { markSimulationSubsystemLoaded } from '../subsystem_loaded.js';
|
|
13
|
+
import { runtimeDiagOnce } from '../../utils/debug_log.js';
|
|
13
14
|
import { containsPrivateMemoryText } from '../memory/backend.js';
|
|
14
15
|
import { RelationshipGraph, } from './topology.js';
|
|
15
16
|
import { EventQueue } from './events.js';
|
|
@@ -373,6 +374,8 @@ export class SimState {
|
|
|
373
374
|
_pendingMemoryWrites = new Set();
|
|
374
375
|
_pendingMemoryWriteErrors = [];
|
|
375
376
|
activeWorldTransition = null;
|
|
377
|
+
/** What this simulation tells the person, each once, such as that its memory runs without embeddings. */
|
|
378
|
+
notices = [];
|
|
376
379
|
constructor(goal, config, preset, restoredWorldId, restoredWorldContext, detached = false) {
|
|
377
380
|
this.id = restoredWorldId
|
|
378
381
|
?? `sim-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
@@ -485,7 +488,8 @@ export class SimState {
|
|
|
485
488
|
this.world = createWorld(definition, restoredWorldContext);
|
|
486
489
|
const memCfg = this.preset.memoryConfig;
|
|
487
490
|
this.memoryManager = new MemoryManager({ nowMs: () => this.calendar.getCurrentTime().getTime() }, {
|
|
488
|
-
|
|
491
|
+
route: this.config,
|
|
492
|
+
onNotice: notice => this.addNotice(notice),
|
|
489
493
|
invariantMode: memCfg?.invariants?.mode,
|
|
490
494
|
outputDir: this.config.outputDir,
|
|
491
495
|
detached,
|
|
@@ -1870,6 +1874,17 @@ export class SimState {
|
|
|
1870
1874
|
return state;
|
|
1871
1875
|
}
|
|
1872
1876
|
// ── Status ──
|
|
1877
|
+
/** Says `notice` once: in this simulation's status and in what started or loaded it, and on stderr for a run nobody watches. */
|
|
1878
|
+
addNotice(notice) {
|
|
1879
|
+
if (this.notices.includes(notice))
|
|
1880
|
+
return;
|
|
1881
|
+
this.notices.push(notice);
|
|
1882
|
+
runtimeDiagOnce('warn', `[ztc] ${notice}`);
|
|
1883
|
+
}
|
|
1884
|
+
/** What this simulation tells the person, such as that its memory runs without embeddings. */
|
|
1885
|
+
getNotices() {
|
|
1886
|
+
return [...this.notices];
|
|
1887
|
+
}
|
|
1873
1888
|
getStatus() {
|
|
1874
1889
|
const agents = this.agentRegistry.getAllAgents();
|
|
1875
1890
|
return {
|
|
@@ -1904,6 +1919,7 @@ export class SimState {
|
|
|
1904
1919
|
pendingRecords: this.artifactStore.getPendingPersistenceRecordCount(),
|
|
1905
1920
|
}
|
|
1906
1921
|
: null,
|
|
1922
|
+
...(this.notices.length > 0 ? { notices: this.getNotices() } : {}),
|
|
1907
1923
|
};
|
|
1908
1924
|
}
|
|
1909
1925
|
getRuntimePeriodNumber() {
|
package/dist/zlm-embed.mjs
CHANGED
|
@@ -11581,6 +11581,17 @@ var init_config = __esm({
|
|
|
11581
11581
|
if (!credentials || this.routerCredentialsError || !(Date.parse(credentials.expiresAt) > Date.now())) return void 0;
|
|
11582
11582
|
return { origin: credentials.origin, token: credentials.token };
|
|
11583
11583
|
}
|
|
11584
|
+
/**
|
|
11585
|
+
* The ZergAI platform login, for `destination` only when that is the platform's own Router proxy
|
|
11586
|
+
* (`<API base>/api/zrouter`), the one place the platform issued it for. Any other Router, Zerg Router's own origin
|
|
11587
|
+
* or one a profile or ZERG_PROXY_URL names, gets nothing. ZTC's chat route, its Router catalog and simulation memory
|
|
11588
|
+
* all take the platform token from here.
|
|
11589
|
+
*/
|
|
11590
|
+
getPlatformProxyLogin(destination) {
|
|
11591
|
+
const origin = normalizedOrigin(destination);
|
|
11592
|
+
const token = this.getAuthToken();
|
|
11593
|
+
return origin && token && origin === this.deriveZRouterUrl(this.getApiBaseUrl()) ? { origin, token } : void 0;
|
|
11594
|
+
}
|
|
11584
11595
|
getRouterCatalogConnection(destination = this.get().zergProxyUrl) {
|
|
11585
11596
|
const origin = normalizedOrigin(destination);
|
|
11586
11597
|
if (!origin) return void 0;
|
|
@@ -11588,8 +11599,8 @@ var init_config = __esm({
|
|
|
11588
11599
|
if (credentials && !this.routerCredentialsError && credentials.origin === origin) {
|
|
11589
11600
|
return { origin, token: credentials.token, workspaceId: credentials.workspaceId };
|
|
11590
11601
|
}
|
|
11591
|
-
const
|
|
11592
|
-
return
|
|
11602
|
+
const platform2 = this.getPlatformProxyLogin(origin);
|
|
11603
|
+
return platform2 ? { origin, token: platform2.token, workspaceId: this.getActiveWorkspace()?.id.toString() } : void 0;
|
|
11593
11604
|
}
|
|
11594
11605
|
/** New children use configured routing, not a parent's restored inference route. */
|
|
11595
11606
|
getChildAuthMode() {
|
|
@@ -11685,8 +11696,7 @@ var init_config = __esm({
|
|
|
11685
11696
|
let model = repoOverride?.model ?? opts.model ?? (configProvider === provider ? cfg.model : void 0) ?? getDefaultModelForProvider(provider);
|
|
11686
11697
|
const authMode = isLocalSubscriptionProvider(provider) ? "direct" : resolveAuthMode(cfg);
|
|
11687
11698
|
const proxyUrl = normalizedOrigin(cfg.zergProxyUrl);
|
|
11688
|
-
|
|
11689
|
-
let authToken = provider !== "modal" && proxyUrl?.replace(/\/+$/, "") === platformProxyUrl ? this.getAuthToken() : void 0;
|
|
11699
|
+
let authToken = provider !== "modal" ? this.getPlatformProxyLogin(proxyUrl)?.token : void 0;
|
|
11690
11700
|
let routerError = this.routerCredentialsError;
|
|
11691
11701
|
if (authMode !== "direct" && this.routerCredentials && !routerError) {
|
|
11692
11702
|
if (proxyUrl?.replace(/\/+$/, "") !== this.routerCredentials.origin) {
|
|
@@ -44855,7 +44865,7 @@ var invokeSkillTool = makeInvokeSkillTool(resolveAmbientSkills);
|
|
|
44855
44865
|
// src/zlm.ts
|
|
44856
44866
|
var ZLM_EMBED_API_VERSION = "zerglang.ztc-embed/1";
|
|
44857
44867
|
var ZLM_STDIO_PROTOCOL = "zerglang.ztc-host/1";
|
|
44858
|
-
var ZLM_ZTC_VERSION = true ? "0.
|
|
44868
|
+
var ZLM_ZTC_VERSION = true ? "0.13.0-beta.1" : "development";
|
|
44859
44869
|
var ZLM_MAX_HOST_TOOLS = 64;
|
|
44860
44870
|
var ZLM_MAX_SYSTEM_PROMPT_BYTES = 128 * 1024;
|
|
44861
44871
|
var ZLM_HOST_APPROVAL_CAPABILITIES = Object.freeze([
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zergai/ztc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0-beta.1",
|
|
4
4
|
"description": "Zerg Terminal Client - CLI agent for continual AI systems",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"homepage": "https://zergai.com/docs/ztc",
|
|
@@ -275,17 +275,23 @@
|
|
|
275
275
|
"node": "^20.19.0 || >=22.12.0"
|
|
276
276
|
},
|
|
277
277
|
"zergRelease": {
|
|
278
|
-
"branch": "
|
|
279
|
-
"channel": "
|
|
280
|
-
"sourceCommit": "
|
|
278
|
+
"branch": "main",
|
|
279
|
+
"channel": "next",
|
|
280
|
+
"sourceCommit": "cc44ea623eb5f055d0772e635db9ed44093dcc96",
|
|
281
281
|
"sourceVersion": "0.2.0-canary.2",
|
|
282
282
|
"whatsNew": [
|
|
283
|
-
"
|
|
283
|
+
"Simulations send each API key or sign-in only to the service that issued it, and never use OPENAI_API_KEY for another provider.",
|
|
284
|
+
"Without an embedding route, a simulation's memory matches words instead of meaning, and the simulation says so once.",
|
|
285
|
+
"A message you kept over a workspace pause still gets its one try past a Zerg Router refusal."
|
|
284
286
|
],
|
|
285
|
-
"changes": [
|
|
287
|
+
"changes": [
|
|
288
|
+
"A message you kept over a workspace pause still gets its try past a Zerg Router refusal.",
|
|
289
|
+
"A simulation sends a provider's key only to that provider.",
|
|
290
|
+
"Simulation memory sends your ZergAI platform login only to the platform."
|
|
291
|
+
]
|
|
286
292
|
},
|
|
287
293
|
"publishConfig": {
|
|
288
|
-
"tag": "
|
|
294
|
+
"tag": "next",
|
|
289
295
|
"access": "public"
|
|
290
296
|
}
|
|
291
297
|
}
|