@botiverse/oar 0.0.7 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/contracts/list-models.d.ts +45 -0
- package/dist/contracts/list-models.d.ts.map +1 -0
- package/dist/contracts/list-models.js +2 -0
- package/dist/contracts/list-models.js.map +1 -0
- package/dist/contracts/runtime.d.ts +2 -0
- package/dist/contracts/runtime.d.ts.map +1 -1
- package/dist/contracts/runtime.js.map +1 -1
- package/dist/contracts/session.d.ts +1 -0
- package/dist/contracts/session.d.ts.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/runtimes/claude/index.d.ts +2 -0
- package/dist/runtimes/claude/index.d.ts.map +1 -1
- package/dist/runtimes/claude/index.js +3 -0
- package/dist/runtimes/claude/index.js.map +1 -1
- package/dist/runtimes/claude/list-models.d.ts +11 -0
- package/dist/runtimes/claude/list-models.d.ts.map +1 -0
- package/dist/runtimes/claude/list-models.js +122 -0
- package/dist/runtimes/claude/list-models.js.map +1 -0
- package/dist/runtimes/claude/session.d.ts.map +1 -1
- package/dist/runtimes/claude/session.js +9 -0
- package/dist/runtimes/claude/session.js.map +1 -1
- package/dist/runtimes/codex/index.d.ts +2 -0
- package/dist/runtimes/codex/index.d.ts.map +1 -1
- package/dist/runtimes/codex/index.js +3 -0
- package/dist/runtimes/codex/index.js.map +1 -1
- package/dist/runtimes/codex/list-models.d.ts +11 -0
- package/dist/runtimes/codex/list-models.d.ts.map +1 -0
- package/dist/runtimes/codex/list-models.js +85 -0
- package/dist/runtimes/codex/list-models.js.map +1 -0
- package/dist/runtimes/codex/session.d.ts.map +1 -1
- package/dist/runtimes/codex/session.js +22 -0
- package/dist/runtimes/codex/session.js.map +1 -1
- package/dist/runtimes/grok/index.d.ts +2 -0
- package/dist/runtimes/grok/index.d.ts.map +1 -1
- package/dist/runtimes/grok/index.js +3 -0
- package/dist/runtimes/grok/index.js.map +1 -1
- package/dist/runtimes/grok/list-models.d.ts +17 -0
- package/dist/runtimes/grok/list-models.d.ts.map +1 -0
- package/dist/runtimes/grok/list-models.js +103 -0
- package/dist/runtimes/grok/list-models.js.map +1 -0
- package/dist/runtimes/kimi/index.d.ts +2 -0
- package/dist/runtimes/kimi/index.d.ts.map +1 -1
- package/dist/runtimes/kimi/index.js +3 -0
- package/dist/runtimes/kimi/index.js.map +1 -1
- package/dist/runtimes/kimi/list-models.d.ts +12 -0
- package/dist/runtimes/kimi/list-models.d.ts.map +1 -0
- package/dist/runtimes/kimi/list-models.js +113 -0
- package/dist/runtimes/kimi/list-models.js.map +1 -0
- package/dist/runtimes/kimi/session.d.ts.map +1 -1
- package/dist/runtimes/kimi/session.js +3 -0
- package/dist/runtimes/kimi/session.js.map +1 -1
- package/dist/runtimes/pi/index.d.ts +2 -0
- package/dist/runtimes/pi/index.d.ts.map +1 -1
- package/dist/runtimes/pi/index.js +3 -0
- package/dist/runtimes/pi/index.js.map +1 -1
- package/dist/runtimes/pi/list-models.d.ts +48 -0
- package/dist/runtimes/pi/list-models.d.ts.map +1 -0
- package/dist/runtimes/pi/list-models.js +66 -0
- package/dist/runtimes/pi/list-models.js.map +1 -0
- package/dist/runtimes/pi/resolve.d.ts +42 -0
- package/dist/runtimes/pi/resolve.d.ts.map +1 -0
- package/dist/runtimes/pi/resolve.js +52 -0
- package/dist/runtimes/pi/resolve.js.map +1 -0
- package/dist/runtimes/pi/session.d.ts +14 -0
- package/dist/runtimes/pi/session.d.ts.map +1 -1
- package/dist/runtimes/pi/session.js +72 -40
- package/dist/runtimes/pi/session.js.map +1 -1
- package/dist/shared/acp/model.d.ts +36 -0
- package/dist/shared/acp/model.d.ts.map +1 -0
- package/dist/shared/acp/model.js +48 -0
- package/dist/shared/acp/model.js.map +1 -0
- package/dist/shared/acp/profile.d.ts +16 -0
- package/dist/shared/acp/profile.d.ts.map +1 -1
- package/dist/shared/acp/profile.js +5 -2
- package/dist/shared/acp/profile.js.map +1 -1
- package/dist/shared/acp/session.d.ts.map +1 -1
- package/dist/shared/acp/session.js +16 -7
- package/dist/shared/acp/session.js.map +1 -1
- package/dist/shared/acp/usage-wait.d.ts +30 -0
- package/dist/shared/acp/usage-wait.d.ts.map +1 -0
- package/dist/shared/acp/usage-wait.js +34 -0
- package/dist/shared/acp/usage-wait.js.map +1 -0
- package/dist/shared/effort-levels.d.ts +10 -0
- package/dist/shared/effort-levels.d.ts.map +1 -0
- package/dist/shared/effort-levels.js +33 -0
- package/dist/shared/effort-levels.js.map +1 -0
- package/dist/shared/executable/process.d.ts +1 -0
- package/dist/shared/executable/process.d.ts.map +1 -1
- package/dist/shared/executable/process.js +5 -1
- package/dist/shared/executable/process.js.map +1 -1
- package/dist/shared/json.d.ts +2 -0
- package/dist/shared/json.d.ts.map +1 -1
- package/dist/shared/json.js +15 -0
- package/dist/shared/json.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { createAgentSessionServices } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
/**
|
|
3
|
+
* Pi model ids are only unique per provider, so the session-facing id is
|
|
4
|
+
* `provider/model`, the same spelling Pi's own `--model` flag accepts.
|
|
5
|
+
*/
|
|
6
|
+
export function projectPiModels(models) {
|
|
7
|
+
return models.map((model) => ({
|
|
8
|
+
id: `${model.provider}/${model.id}`,
|
|
9
|
+
displayName: model.name === undefined || model.name.trim().length === 0 ? model.id : model.name.trim(),
|
|
10
|
+
}));
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* In-process through the bundled SDK, built the way `pi --list-models` builds
|
|
14
|
+
* its own runtime: `createAgentSessionServices` loads the extensions under the
|
|
15
|
+
* agent dir and applies their provider registrations to the ModelRuntime
|
|
16
|
+
* before anything is listed. That matters because extensions can be the ONLY
|
|
17
|
+
* source of providers (on exe.dev every listed provider comes from the exe-dev
|
|
18
|
+
* extension; auth.json is empty). A bare `ModelRuntime.create()` sees none of
|
|
19
|
+
* them and prints "no models" while `pi --list-models` prints dozens.
|
|
20
|
+
*
|
|
21
|
+
* The list itself comes from `getAvailable()`, which computes availability on
|
|
22
|
+
* demand. Do NOT read `ModelRegistry.getAvailable()` / `getAvailableSnapshot()`
|
|
23
|
+
* here: that snapshot starts empty and is only filled by an availability
|
|
24
|
+
* refresh (the other half of the 2026-09-05 "no models" bug).
|
|
25
|
+
*
|
|
26
|
+
* Skills, prompt templates, themes, and context files are skipped: they cannot
|
|
27
|
+
* register providers, and listing must not read the project's prompt files.
|
|
28
|
+
* `OAR_PI_AGENT_DIR` pins the agent dir exactly as the session adapter does,
|
|
29
|
+
* so the list and the session see the same providers.
|
|
30
|
+
*
|
|
31
|
+
* Pi keys on provider API keys rather than one login, so "nothing configured"
|
|
32
|
+
* is an `ok` empty list, not `unauthenticated`.
|
|
33
|
+
*/
|
|
34
|
+
export function createPiListModels(createRuntime) {
|
|
35
|
+
return async (installation, options = {}) => {
|
|
36
|
+
if (installation.via !== "bundled") {
|
|
37
|
+
return { kind: "unsupported", reason: "pi model listing runs through the bundled Pi SDK" };
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const signal = AbortSignal.timeout(options.timeoutMs ?? 15_000);
|
|
41
|
+
const runtime = await createRuntime(signal);
|
|
42
|
+
const available = await runtime.getAvailable(undefined, { signal });
|
|
43
|
+
return { kind: "ok", models: projectPiModels(available) };
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
47
|
+
return { kind: "unsupported", reason: `pi SDK could not list available models: ${detail}` };
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export const piListModels = createPiListModels(async (signal) => {
|
|
52
|
+
const agentDir = process.env.OAR_PI_AGENT_DIR;
|
|
53
|
+
const services = await createAgentSessionServices({
|
|
54
|
+
cwd: process.cwd(),
|
|
55
|
+
...(agentDir === undefined ? {} : { agentDir }),
|
|
56
|
+
modelRuntimeSignal: signal,
|
|
57
|
+
resourceLoaderOptions: {
|
|
58
|
+
noSkills: true,
|
|
59
|
+
noPromptTemplates: true,
|
|
60
|
+
noThemes: true,
|
|
61
|
+
noContextFiles: true,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
return services.modelRuntime;
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=list-models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-models.js","sourceRoot":"","sources":["../../../src/runtimes/pi/list-models.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAsB7E;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,MAAgC;IAC9D,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC5B,EAAE,EAAE,GAAG,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,EAAE,EAAE;QACnC,WAAW,EAAE,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE;KACvG,CAAC,CAAC,CAAC;AACN,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,kBAAkB,CAChC,aAAqE;IAErE,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,GAAG,EAAE,EAAE,EAAE;QAC1C,IAAI,YAAY,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;YACnC,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,kDAAkD,EAAE,CAAC;QAC7F,CAAC;QACD,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,IAAI,MA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|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly path: string;
|
|
5
|
+
}
|
|
6
|
+
/** Structural slice of `SessionManager.list`; kept narrow for tests. */
|
|
7
|
+
export interface PiSessionLister {
|
|
8
|
+
list(cwd: string, sessionDir?: string): Promise<readonly PiSessionInfo[]>;
|
|
9
|
+
}
|
|
10
|
+
/** Structural slice of `ModelRuntime.getModel`; kept generic for tests. */
|
|
11
|
+
export interface PiModelLookup<TModel> {
|
|
12
|
+
getModel(provider: string, modelId: string): TModel | undefined;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Mirrors pi's unexported `getDefaultSessionDirPath` (session-manager.js
|
|
16
|
+
* 0.84.2): the cwd is resolved, its leading separator dropped, every `/ \ :`
|
|
17
|
+
* turned into `-`, and wrapped in `--…--` under `<agentDir>/sessions`. Kept
|
|
18
|
+
* in lock-step so the agent-dir pin (OAR_PI_AGENT_DIR) and pi's own CLI land
|
|
19
|
+
* sessions in the same directory.
|
|
20
|
+
*/
|
|
21
|
+
export declare function piSessionDir(cwd: string, agentDir: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Session id → session file. Listing is per cwd because pi's directory is
|
|
24
|
+
* per cwd: a session started elsewhere is not found here, and the error says
|
|
25
|
+
* where it looked so the caller can tell "wrong cwd" from "never persisted"
|
|
26
|
+
* (pi writes the file on the first message, so an unused session has none).
|
|
27
|
+
*/
|
|
28
|
+
export declare function piFindSessionFile(lister: PiSessionLister, id: string, cwd: string, sessionDir: string): Promise<string>;
|
|
29
|
+
/** Splits `provider/model` at the first slash; model ids may themselves contain slashes. */
|
|
30
|
+
export declare function splitPiModelId(model: string): {
|
|
31
|
+
provider: string;
|
|
32
|
+
modelId: string;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* `provider/model` → pi Model through the session's ModelRuntime (extension
|
|
36
|
+
* registrations included, since the runtime comes from
|
|
37
|
+
* createAgentSessionServices). Unknown is an error rather than a fallback:
|
|
38
|
+
* pi would otherwise pick its own default and the caller's choice would
|
|
39
|
+
* silently not apply.
|
|
40
|
+
*/
|
|
41
|
+
export declare function piResolveModel<TModel>(lookup: PiModelLookup<TModel>, model: string): TModel;
|
|
42
|
+
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../../src/runtimes/pi/resolve.ts"],"names":[],"mappings":"AAaA,6DAA6D;AAC7D,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,wEAAwE;AACxE,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,aAAa,EAAE,CAAC,CAAC;CAC3E;AAED,2EAA2E;AAC3E,MAAM,WAAW,aAAa,CAAC,MAAM;IACnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CACjE;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGlE;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,eAAe,EACvB,EAAE,EAAE,MAAM,EACV,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC,CAUjB;AAED,4FAA4F;AAC5F,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAQnF;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAU3F"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { join, resolve } from "node:path";
|
|
2
|
+
/**
|
|
3
|
+
* Mirrors pi's unexported `getDefaultSessionDirPath` (session-manager.js
|
|
4
|
+
* 0.84.2): the cwd is resolved, its leading separator dropped, every `/ \ :`
|
|
5
|
+
* turned into `-`, and wrapped in `--…--` under `<agentDir>/sessions`. Kept
|
|
6
|
+
* in lock-step so the agent-dir pin (OAR_PI_AGENT_DIR) and pi's own CLI land
|
|
7
|
+
* sessions in the same directory.
|
|
8
|
+
*/
|
|
9
|
+
export function piSessionDir(cwd, agentDir) {
|
|
10
|
+
const slug = resolve(cwd).replace(/^[/\\]/u, "").replaceAll(/[/\\:]/gu, "-");
|
|
11
|
+
return join(resolve(agentDir), "sessions", `--${slug}--`);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Session id → session file. Listing is per cwd because pi's directory is
|
|
15
|
+
* per cwd: a session started elsewhere is not found here, and the error says
|
|
16
|
+
* where it looked so the caller can tell "wrong cwd" from "never persisted"
|
|
17
|
+
* (pi writes the file on the first message, so an unused session has none).
|
|
18
|
+
*/
|
|
19
|
+
export async function piFindSessionFile(lister, id, cwd, sessionDir) {
|
|
20
|
+
const sessions = await lister.list(cwd, sessionDir);
|
|
21
|
+
const found = sessions.find((session) => session.id === id);
|
|
22
|
+
if (found === undefined) {
|
|
23
|
+
throw new Error(`pi session ${id} not found: no session file with that id under ${sessionDir} `
|
|
24
|
+
+ `(${sessions.length} session(s) there for cwd ${cwd}; pi persists a session on its first message)`);
|
|
25
|
+
}
|
|
26
|
+
return found.path;
|
|
27
|
+
}
|
|
28
|
+
/** Splits `provider/model` at the first slash; model ids may themselves contain slashes. */
|
|
29
|
+
export function splitPiModelId(model) {
|
|
30
|
+
const slash = model.indexOf("/");
|
|
31
|
+
if (slash <= 0 || slash === model.length - 1) {
|
|
32
|
+
throw new Error(`pi model must be spelled provider/model as listed by \`oar models pi\`; got ${JSON.stringify(model)}`);
|
|
33
|
+
}
|
|
34
|
+
return { provider: model.slice(0, slash), modelId: model.slice(slash + 1) };
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* `provider/model` → pi Model through the session's ModelRuntime (extension
|
|
38
|
+
* registrations included, since the runtime comes from
|
|
39
|
+
* createAgentSessionServices). Unknown is an error rather than a fallback:
|
|
40
|
+
* pi would otherwise pick its own default and the caller's choice would
|
|
41
|
+
* silently not apply.
|
|
42
|
+
*/
|
|
43
|
+
export function piResolveModel(lookup, model) {
|
|
44
|
+
const { provider, modelId } = splitPiModelId(model);
|
|
45
|
+
const found = lookup.getModel(provider, modelId);
|
|
46
|
+
if (found === undefined) {
|
|
47
|
+
throw new Error(`pi model ${model} is not registered: provider ${provider} has no model ${modelId} `
|
|
48
|
+
+ "(see `oar models pi` for the usable list)");
|
|
49
|
+
}
|
|
50
|
+
return found;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../../src/runtimes/pi/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA6B1C;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW,EAAE,QAAgB;IACxD,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;IAC7E,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,UAAU,EAAE,KAAK,IAAI,IAAI,CAAC,CAAC;AAC5D,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAAuB,EACvB,EAAU,EACV,GAAW,EACX,UAAkB;IAElB,MAAM,QAAQ,GAAG,MA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AAG;cAClF,2CAA2C,CAC9C,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -7,5 +7,19 @@ import type { StartSession } from "../../contracts/session.js";
|
|
|
7
7
|
* replaces the builtin by name. Exported for direct unit verification.
|
|
8
8
|
*/
|
|
9
9
|
export declare function piEnvBashTool(cwd: string, overlay: Readonly<Record<string, string>>): Promise<NonNullable<CreateAgentSessionOptions["customTools"]>[number]>;
|
|
10
|
+
/** The slice of pi's AgentSession the model read-back depends on; structural for tests. */
|
|
11
|
+
export interface PiModelSource {
|
|
12
|
+
readonly model: {
|
|
13
|
+
readonly provider: string;
|
|
14
|
+
readonly id: string;
|
|
15
|
+
} | undefined;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* pi's `AgentSession.model` (SDK 0.84.2 agent-session.d.ts: "Current model
|
|
19
|
+
* (may be undefined if not yet selected)") is the runtime-owned current
|
|
20
|
+
* model, updated by setModel/model switching; spelled `provider/id` like the
|
|
21
|
+
* list-models projection and pi's own `--model` flag.
|
|
22
|
+
*/
|
|
23
|
+
export declare function piEffectiveModel(session: PiModelSource): string | null;
|
|
10
24
|
export declare const piSession: StartSession;
|
|
11
25
|
//# sourceMappingURL=session.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/runtimes/pi/session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/runtimes/pi/session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkC,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AACjH,OAAO,KAAK,EAA2B,YAAY,EAAQ,MAAM,4BAA4B,CAAC;AAuB9F;;;;;GAKG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACxC,OAAO,CAAC,WAAW,CAAC,yBAAyB,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAKxE;AAED,2FAA2F;AAC3F,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;CAChF;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,GAAG,IAAI,CAGtE;AAoED,eAAO,MAAM,SAAS,EAAE,YAwIvB,CAAC"}
|
|
@@ -2,12 +2,14 @@ import { classifyFailure } from "../../shared/failure-class.js";
|
|
|
2
2
|
import { sealSession } from "../../shared/seal-session.js";
|
|
3
3
|
import { createSessionKernel } from "../../shared/session-kernel.js";
|
|
4
4
|
import { foldPiEvent, initialPiProjection, piAbortRequested, piPrompted, piSettledOutcome, } from "./projection.js";
|
|
5
|
+
import { piFindSessionFile, piResolveModel, piSessionDir } from "./resolve.js";
|
|
5
6
|
/*
|
|
6
7
|
* Bundled pi SDK mapping (in-process, no fork — settled 2026-08-21):
|
|
7
8
|
* prompt resolves on settlement; steer acceptance means entry into pi's
|
|
8
9
|
* queue; abort is cooperative. Turn deltas/tools map, session events drop.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
10
|
+
* Resume opens the cwd's session file by id and options.model resolves
|
|
11
|
+
* through the ModelRuntime (see resolve.ts). Process-global lazy env reads
|
|
12
|
+
* mean another embedded pi cannot safely share this process.
|
|
11
13
|
*/
|
|
12
14
|
/**
|
|
13
15
|
* The bash tool that carries SessionOptions.env into the agent's spawned
|
|
@@ -21,54 +23,83 @@ export async function piEnvBashTool(cwd, overlay) {
|
|
|
21
23
|
spawnHook: (context) => ({ ...context, env: { ...context.env, ...overlay } }),
|
|
22
24
|
}));
|
|
23
25
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
26
|
+
/**
|
|
27
|
+
* pi's `AgentSession.model` (SDK 0.84.2 agent-session.d.ts: "Current model
|
|
28
|
+
* (may be undefined if not yet selected)") is the runtime-owned current
|
|
29
|
+
* model, updated by setModel/model switching; spelled `provider/id` like the
|
|
30
|
+
* list-models projection and pi's own `--model` flag.
|
|
31
|
+
*/
|
|
32
|
+
export function piEffectiveModel(session) {
|
|
33
|
+
const { model } = session;
|
|
34
|
+
return model === undefined ? null : `${model.provider}/${model.id}`;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Opens (or resumes) the pi AgentSession the adapter wraps. Services first
|
|
38
|
+
* (createAgentSessionServices loads the agent dir's extensions and their
|
|
39
|
+
* provider registrations into the ModelRuntime, exactly as `pi` itself does),
|
|
40
|
+
* then the session against an explicit SessionManager so resume and creation
|
|
41
|
+
* share one session directory.
|
|
42
|
+
*/
|
|
43
|
+
async function openPiAgentSession(options) {
|
|
33
44
|
const sdk = await import("@earendil-works/pi-coding-agent");
|
|
34
|
-
// Per-session env on an in-process runtime: the runtime itself has no own
|
|
35
|
-
// process, but the processes the AGENT spawns do — a bash tool built with a
|
|
36
|
-
// spawnHook overlaying the env replaces the builtin by name (custom tools
|
|
37
|
-
// win the SDK's tool registry). Provider config (keys, base URLs) does NOT
|
|
38
|
-
// travel this way for pi; that needs its native modelRuntime/agentDir
|
|
39
|
-
// channel. Tool-level spawn verified in SDK source, not yet live (no
|
|
40
|
-
// configured pi on this machine).
|
|
41
|
-
const overlay = options.env;
|
|
42
45
|
// OAR_PI_AGENT_DIR pins pi's global config home (models.json/auth.json/
|
|
43
|
-
// settings) — same namespaced-env-pin pattern as OAR_CLAUDE_BIN.
|
|
44
|
-
// how a host (or the pi-aimock behavior backend) points the
|
|
45
|
-
// model plane somewhere else.
|
|
46
|
-
const agentDir = process.env.OAR_PI_AGENT_DIR;
|
|
46
|
+
// settings/sessions) — same namespaced-env-pin pattern as OAR_CLAUDE_BIN.
|
|
47
|
+
// This is how a host (or the pi-aimock behavior backend) points the
|
|
48
|
+
// in-process model plane somewhere else.
|
|
49
|
+
const agentDir = process.env.OAR_PI_AGENT_DIR ?? sdk.getAgentDir();
|
|
47
50
|
// YOLO by default (repo policy): pi gates tool execution on project trust,
|
|
48
51
|
// which is an approval prompt no embedded host can answer — pre-trust the
|
|
49
52
|
// session cwd the same way pi's own Trust button would (auditable in
|
|
50
53
|
// <agentDir>/trust.json).
|
|
51
|
-
new sdk.ProjectTrustStore(agentDir
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
agentDir: agentDir ?? sdk.getAgentDir(),
|
|
54
|
+
new sdk.ProjectTrustStore(agentDir).set(options.cwd, true);
|
|
55
|
+
const services = await sdk.createAgentSessionServices({
|
|
56
|
+
cwd: options.cwd,
|
|
57
|
+
agentDir,
|
|
58
|
+
// System prompt seams: pi's DefaultResourceLoader natively supports both
|
|
59
|
+
// replace (systemPrompt) and append (appendSystemPrompt).
|
|
60
|
+
resourceLoaderOptions: {
|
|
59
61
|
...(options.systemPrompt === undefined ? {} : { systemPrompt: options.systemPrompt }),
|
|
60
62
|
...(options.appendSystemPrompt === undefined ? {} : { appendSystemPrompt: [options.appendSystemPrompt] }),
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
// pi persists sessions per cwd under <agentDir>/sessions; the same
|
|
66
|
+
// directory is used to create (so a later resume finds the file) and to
|
|
67
|
+
// look a resumed id up.
|
|
68
|
+
const sessionDir = piSessionDir(options.cwd, agentDir);
|
|
69
|
+
const sessionManager = options.resume === undefined
|
|
70
|
+
? sdk.SessionManager.create(options.cwd, sessionDir)
|
|
71
|
+
: sdk.SessionManager.open(await piFindSessionFile(sdk.SessionManager, options.resume, options.cwd, sessionDir), sessionDir);
|
|
72
|
+
// An explicit model wins over the one recorded in a resumed session
|
|
73
|
+
// (sdk.js createAgentSession precedence, same in the services path); the
|
|
74
|
+
// recorded one is restored only when none is given.
|
|
75
|
+
const model = options.model === undefined ? undefined : piResolveModel(services.modelRuntime, options.model);
|
|
76
|
+
// Per-session env on an in-process runtime: the runtime itself has no own
|
|
77
|
+
// process, but the processes the AGENT spawns do — a bash tool built with a
|
|
78
|
+
// spawnHook overlaying the env replaces the builtin by name (custom tools
|
|
79
|
+
// win the SDK's tool registry). Provider config (keys, base URLs) does NOT
|
|
80
|
+
// travel this way for pi; that needs its native modelRuntime/agentDir
|
|
81
|
+
// channel.
|
|
82
|
+
const overlay = options.env;
|
|
83
|
+
const { session } = await sdk.createAgentSessionFromServices({
|
|
84
|
+
services,
|
|
85
|
+
sessionManager,
|
|
86
|
+
...(model === undefined ? {} : { model }),
|
|
70
87
|
...(overlay === undefined ? {} : { customTools: [await piEnvBashTool(options.cwd, overlay)] }),
|
|
71
88
|
});
|
|
89
|
+
// Read back rather than trust the request: Session.model() is the
|
|
90
|
+
// runtime's report, and a resume that kept the old model must not pass.
|
|
91
|
+
const effective = piEffectiveModel(session);
|
|
92
|
+
if (options.model !== undefined && effective !== options.model) {
|
|
93
|
+
session.dispose();
|
|
94
|
+
throw new Error(`pi did not apply model ${options.model}: the session reports ${effective ?? "no model"}`);
|
|
95
|
+
}
|
|
96
|
+
return session;
|
|
97
|
+
}
|
|
98
|
+
export const piSession = async (installation, options) => {
|
|
99
|
+
if (installation.via !== "bundled") {
|
|
100
|
+
throw new Error("The pi session adapter needs the bundled sdk installation");
|
|
101
|
+
}
|
|
102
|
+
const piAgentSession = await openPiAgentSession(options);
|
|
72
103
|
const kernel = createSessionKernel(piAgentSession.sessionId);
|
|
73
104
|
let currentTurn = null;
|
|
74
105
|
let projection = initialPiProjection;
|
|
@@ -167,6 +198,7 @@ export const piSession = async (installation, options) => {
|
|
|
167
198
|
return { kind: "turn", turn: makeTurn(turn) };
|
|
168
199
|
},
|
|
169
200
|
subscribe: (observer) => kernel.subscribe(observer),
|
|
201
|
+
model: () => piEffectiveModel(piAgentSession),
|
|
170
202
|
contextUsage: () => {
|
|
171
203
|
// pi is authoritative: getContextUsage() returns tokens (null right
|
|
172
204
|
// after compaction, before the next response), contextWindow, percent.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/runtimes/pi/session.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAmB,MAAM,gCAAgC,CAAC;AACtF,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,gBAAgB,EAChB,UAAU,EACV,gBAAgB,GAEjB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/runtimes/pi/session.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAmB,MAAM,gCAAgC,CAAC;AACtF,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,gBAAgB,EAChB,UAAU,EACV,gBAAgB,GAEjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE/E;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,GAAW,EACX,OAAyC;IAEzC,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,iCAAiC,CAAC,CAAC;IA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EAAE,CAAC;YACd,CAAC;SACF;QACD,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,IAAI,QAAQ,EAAE,CAAC;gBACb,OAAO;YACT,CAAC;YACD,QAAQ,GAAG,IAAI,CAAC;YAChB,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;YAC/B,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;gBACpB,MAAM,cAAc,CAAC,KAAK,EAAE,CAAC;gBAC7B,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;YACrC,CAAC;YACD,cAAc,CAAC,OAAO,EAAE,CAAC;QAC3B,CAAC;KACF,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type JsonRecord } from "../json.js";
|
|
2
|
+
import type { OpenedAcpSession } from "./profile.js";
|
|
3
|
+
/**
|
|
4
|
+
* The model an ACP agent reports as in effect, read from the agent's own
|
|
5
|
+
* frames rather than from what we asked for. Two spellings exist upstream:
|
|
6
|
+
*
|
|
7
|
+
* - kimi-code (packages/acp-server, f9ca33376): `session/new|load|resume`
|
|
8
|
+
* answer `configOptions` with a `{type: "select", id: "model", currentValue}`
|
|
9
|
+
* row whose `currentValue` is the bare model id, and every switch
|
|
10
|
+
* (`session/set_model`, `set_config_option`) pushes
|
|
11
|
+
* `session/update {sessionUpdate: "config_option_update", configOptions}`
|
|
12
|
+
* BEFORE the switch request is answered; the `set_model` response is `{}`.
|
|
13
|
+
* - xai-grok-shell 1.0.12 (bc7f02e): `session/new|load` answer
|
|
14
|
+
* `models.currentModelId` (a requested model the account cannot use falls
|
|
15
|
+
* back to the default silently) and `session/set_model` answers
|
|
16
|
+
* `{_meta: {model}}` with the applied id.
|
|
17
|
+
*
|
|
18
|
+
* Null when the frame carries neither: it is the caller's job to keep the
|
|
19
|
+
* last reported value, never to substitute the requested one.
|
|
20
|
+
*/
|
|
21
|
+
export declare function acpReportedModel(frame: JsonRecord | null): string | null;
|
|
22
|
+
/** Last model the agent reported; `null` until it says one. */
|
|
23
|
+
export interface AcpModelReadback {
|
|
24
|
+
readonly current: () => string | null;
|
|
25
|
+
/** Feed any update or response frame; frames without a model change nothing. */
|
|
26
|
+
readonly observe: (frame: JsonRecord | null) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Apply the open handshake in precedence order: the set_model answer
|
|
29
|
+
* (grok's `_meta.model`), then anything pushed while opening (kimi's
|
|
30
|
+
* config_option_update, which arrives before set_model is answered), then
|
|
31
|
+
* the session new/load response. The request parameter is never consulted.
|
|
32
|
+
*/
|
|
33
|
+
readonly opened: (opened: OpenedAcpSession) => void;
|
|
34
|
+
}
|
|
35
|
+
export declare function createAcpModelReadback(): AcpModelReadback;
|
|
36
|
+
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/shared/acp/model.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAexE;AAED,+DAA+D;AAC/D,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACtC,gFAAgF;IAChF,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,KAAK,IAAI,CAAC;IACrD;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAC;CACrD;AAED,wBAAgB,sBAAsB,IAAI,gBAAgB,CAWzD"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { asRecord, asRecordList } from "../json.js";
|
|
2
|
+
/**
|
|
3
|
+
* The model an ACP agent reports as in effect, read from the agent's own
|
|
4
|
+
* frames rather than from what we asked for. Two spellings exist upstream:
|
|
5
|
+
*
|
|
6
|
+
* - kimi-code (packages/acp-server, f9ca33376): `session/new|load|resume`
|
|
7
|
+
* answer `configOptions` with a `{type: "select", id: "model", currentValue}`
|
|
8
|
+
* row whose `currentValue` is the bare model id, and every switch
|
|
9
|
+
* (`session/set_model`, `set_config_option`) pushes
|
|
10
|
+
* `session/update {sessionUpdate: "config_option_update", configOptions}`
|
|
11
|
+
* BEFORE the switch request is answered; the `set_model` response is `{}`.
|
|
12
|
+
* - xai-grok-shell 1.0.12 (bc7f02e): `session/new|load` answer
|
|
13
|
+
* `models.currentModelId` (a requested model the account cannot use falls
|
|
14
|
+
* back to the default silently) and `session/set_model` answers
|
|
15
|
+
* `{_meta: {model}}` with the applied id.
|
|
16
|
+
*
|
|
17
|
+
* Null when the frame carries neither: it is the caller's job to keep the
|
|
18
|
+
* last reported value, never to substitute the requested one.
|
|
19
|
+
*/
|
|
20
|
+
export function acpReportedModel(frame) {
|
|
21
|
+
if (frame === null) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const option = asRecordList(frame.configOptions).find((entry) => entry.id === "model");
|
|
25
|
+
if (typeof option?.currentValue === "string") {
|
|
26
|
+
return option.currentValue;
|
|
27
|
+
}
|
|
28
|
+
const currentModelId = asRecord(frame.models)?.currentModelId;
|
|
29
|
+
if (typeof currentModelId === "string") {
|
|
30
|
+
return currentModelId;
|
|
31
|
+
}
|
|
32
|
+
// oxlint-disable-next-line eslint/no-underscore-dangle -- `_meta` is the ACP extension envelope.
|
|
33
|
+
const metaModel = asRecord(frame._meta)?.model;
|
|
34
|
+
return typeof metaModel === "string" ? metaModel : null;
|
|
35
|
+
}
|
|
36
|
+
export function createAcpModelReadback() {
|
|
37
|
+
let model = null;
|
|
38
|
+
return {
|
|
39
|
+
current: () => model,
|
|
40
|
+
observe: (frame) => {
|
|
41
|
+
model = acpReportedModel(frame) ?? model;
|
|
42
|
+
},
|
|
43
|
+
opened: (opened) => {
|
|
44
|
+
model = acpReportedModel(opened.setModelResponse ?? null) ?? model ?? acpReportedModel(opened.response);
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../../src/shared/acp/model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAmB,MAAM,YAAY,CAAC;AAGrE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAwB;IACvD,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,OAAO,CAAC,CAAC;IACvF,IAAI,OAAO,MAAM,EAAE,YAAY,KAAK,QAAQ,EAAE,CAAC;QAC7C,OAAO,MAAM,CAAC,YAAY,CAAC;IAC7B,CAAC;IACD,MAAM,cAAc,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,cAAc,CAAC;IAC9D,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE,CAAC;QACvC,OAAO,cAAc,CAAC;IACxB,CAAC;IACD,iGAAiG;IACjG,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IAC/C,OAAO,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;AAC1D,CAAC;AAgBD,MAAM,UAAU,sBAAsB;IACpC,IAAI,KAAK,GAAkB,IAAI,CAAC;IAChC,OAAO;QACL,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK;QACpB,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YACjB,KAAK,GAAG,gBAAgB,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC;QAC3C,CAAC;QACD,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;YACjB,KAAK,GAAG,gBAAgB,CAAC,MAAM,CAAC,gBAAgB,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,gBAAgB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC1G,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -2,6 +2,8 @@ import { type ClientConnection, type SendRequestOptions } from "@agentclientprot
|
|
|
2
2
|
import type { ContextUsage, SessionOptions, TurnOutcome } from "../../contracts/session.js";
|
|
3
3
|
import { type JsonRecord } from "../json.js";
|
|
4
4
|
import { type AcpProcess } from "./process.js";
|
|
5
|
+
export { createAcpModelReadback } from "./model.js";
|
|
6
|
+
export { createUsageUpdateGate } from "./usage-wait.js";
|
|
5
7
|
export interface AcpSessionProfile {
|
|
6
8
|
readonly args: readonly string[] | ((options: SessionOptions) => readonly string[]);
|
|
7
9
|
readonly requestTimeoutMs?: number;
|
|
@@ -23,11 +25,25 @@ export interface AcpSessionProfile {
|
|
|
23
25
|
readonly steerParams?: (input: string) => JsonRecord;
|
|
24
26
|
readonly promptContextUsage?: (response: JsonRecord) => ContextUsage | null;
|
|
25
27
|
readonly promptOutcome?: (response: JsonRecord) => TurnOutcome | null;
|
|
28
|
+
/**
|
|
29
|
+
* The agent answers `session/prompt` BEFORE it pushes the turn's
|
|
30
|
+
* `usage_update` (kimi-code f9ca33376 packages/acp-server/src/session.ts:
|
|
31
|
+
* `onTurnEnded` resolves the prompt driver, then `void emitUsageUpdate()`
|
|
32
|
+
* awaits `listModels` + `getContext` and only then notifies — or skips the
|
|
33
|
+
* push when the catalog has no size for the model). When true, the session
|
|
34
|
+
* holds the turn open after the response until that update lands, bounded
|
|
35
|
+
* by `usageUpdateTimeoutMs`; on timeout it settles with whatever it has.
|
|
36
|
+
*/
|
|
37
|
+
readonly usageUpdateAfterPrompt?: boolean;
|
|
38
|
+
/** Bound for `usageUpdateAfterPrompt`; default 500 ms. */
|
|
39
|
+
readonly usageUpdateTimeoutMs?: number;
|
|
26
40
|
}
|
|
27
41
|
export interface OpenedAcpSession {
|
|
28
42
|
readonly initialized: JsonRecord;
|
|
29
43
|
readonly response: JsonRecord;
|
|
30
44
|
readonly sessionId: string;
|
|
45
|
+
/** The `session/set_model` response, when a model was requested; grok reports the applied model in its `_meta`. */
|
|
46
|
+
readonly setModelResponse?: JsonRecord;
|
|
31
47
|
}
|
|
32
48
|
export declare function hasAcpCapability(value: unknown): boolean;
|
|
33
49
|
export declare function promptAcp(process: AcpProcess, sessionId: string, input: string, extraParams?: JsonRecord): Promise<JsonRecord>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../../src/shared/acp/profile.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC5F,OAAO,EAAY,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,KAAK,UAAU,EAAmB,MAAM,cAAc,CAAC;AAEhE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,CAAC,CAAC,OAAO,EAAE,cAAc,KAAK,SAAS,MAAM,EAAE,CAAC,CAAC;IACpF,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,gFAAg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protocol/sdk";
|
|
3
3
|
import { asRecord } from "../json.js";
|
|
4
4
|
import { withAcpDeadline } from "./process.js";
|
|
5
|
+
export { createAcpModelReadback } from "./model.js";
|
|
6
|
+
export { createUsageUpdateGate } from "./usage-wait.js";
|
|
5
7
|
export function hasAcpCapability(value) {
|
|
6
8
|
return value === true || asRecord(value) !== null;
|
|
7
9
|
}
|
|
@@ -86,8 +88,9 @@ async function createOrResume(process, profile, initialized, options, meta) {
|
|
|
86
88
|
export async function openAcpSession(process, profile, options) {
|
|
87
89
|
const initialized = await initialize(process, profile, options);
|
|
88
90
|
const opened = await createOrResume(process, profile, initialized, options, profile.sessionMeta?.(options));
|
|
91
|
+
let setModelResponse = undefined;
|
|
89
92
|
if (options.model !== undefined) {
|
|
90
|
-
await withAcpDeadline(process, "session/set_model", profile.requestTimeoutMs ?? 15_000, (requestOptions) => process.connection.agent.request("session/set_model", { sessionId: opened.sessionId, modelId: options.model }, requestOptions));
|
|
93
|
+
setModelResponse = asRecord(await withAcpDeadline(process, "session/set_model", profile.requestTimeoutMs ?? 15_000, (requestOptions) => process.connection.agent.request("session/set_model", { sessionId: opened.sessionId, modelId: options.model }, requestOptions))) ?? undefined;
|
|
91
94
|
}
|
|
92
95
|
const configure = profile.configureSession;
|
|
93
96
|
if (configure !== undefined) {
|
|
@@ -99,6 +102,6 @@ export async function openAcpSession(process, profile, options) {
|
|
|
99
102
|
...(requestOptions === undefined ? {} : { requestOptions }),
|
|
100
103
|
}));
|
|
101
104
|
}
|
|
102
|
-
return { initialized, ...opened };
|
|
105
|
+
return { initialized, ...opened, ...(setModelResponse === undefined ? {} : { setModelResponse }) };
|
|
103
106
|
}
|
|
104
107
|
//# sourceMappingURL=profile.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../../../src/shared/acp/profile.ts"],"names":[],"mappings":"AAAA,2HAA2H;AAC3H,OAAO,EACL,OAAO,EACP,gBAAgB,GAGjB,MAAM,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AC,UAAU;YAC9B,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,OAAO;YACP,GAAG,CAAC,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC;SAC5D,CAAC,CACH,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,WAAW,EAAE,GAAG,MAAM,EAAE,GAAG,CAAC,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAC,EAAE,CAAC;AACrG,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/shared/acp/session.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAyC,YAAY,EAAkC,MAAM,4BAA4B,CAAC;AAKtI,OAAO,
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/shared/acp/session.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAyC,YAAY,EAAkC,MAAM,4BAA4B,CAAC;AAKtI,OAAO,EAOL,KAAK,iBAAiB,EACvB,MAAM,cAAc,CAAC;AAStB,YAAY,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAWtD,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,YAAY,CAwQnE"}
|