@av-pi-studio/server 0.0.109 → 0.0.111
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/agent/provider-contract.d.ts +6 -0
- package/dist/agent/providers/pi/agent.d.ts +4 -6
- package/dist/agent/providers/pi/agent.js +31 -22
- package/dist/agent/slash-command-operations.d.ts +15 -2
- package/dist/agent/slash-command-operations.js +15 -0
- package/dist/daemon/bootstrap.js +0 -13
- package/dist/daemon/dev-bootstrap.js +0 -13
- package/package.json +4 -4
|
@@ -253,6 +253,9 @@ export interface AgentSession {
|
|
|
253
253
|
}>;
|
|
254
254
|
/** `/model` (set) — mirrors Pi RPC `set_model` (distinct from the legacy string-only `setModel?`). */
|
|
255
255
|
setProviderModel?(provider: string, modelId: string): Promise<unknown>;
|
|
256
|
+
/** The models THIS process can switch to — mirrors Pi RPC `get_available_models`. Pi loads
|
|
257
|
+
* `models.json` once at spawn, so after an edit a fresh process's list can differ from this one. */
|
|
258
|
+
listModels?(): Promise<AgentModelDefinition[]>;
|
|
256
259
|
/** `/model` (cycle) — mirrors Pi RPC `cycle_model`. */
|
|
257
260
|
cycleModel?(): Promise<AgentCycleModelResult>;
|
|
258
261
|
/** `/copy` — mirrors Pi RPC `get_last_assistant_text`. */
|
|
@@ -268,8 +271,11 @@ export interface AgentClient {
|
|
|
268
271
|
readonly capabilities: AgentCapabilityFlags;
|
|
269
272
|
createSession(config: AgentSessionConfig, launchContext?: LaunchContext, options?: CreateSessionOptions): Promise<AgentSession>;
|
|
270
273
|
resumeSession(handle: PersistenceHandle, overrides?: Partial<AgentSessionConfig>, launchContext?: LaunchContext): Promise<AgentSession>;
|
|
274
|
+
/** `session`: a live session of this provider whose own list should answer (see
|
|
275
|
+
* `AgentSession.listModels`) — otherwise a fresh, sessionless discovery. */
|
|
271
276
|
listModels(opts?: {
|
|
272
277
|
cwd?: string;
|
|
278
|
+
session?: AgentSession;
|
|
273
279
|
}): Promise<AgentModelDefinition[]>;
|
|
274
280
|
isAvailable(): Promise<boolean> | boolean;
|
|
275
281
|
listModes?(opts?: {
|
|
@@ -77,15 +77,13 @@ export declare class PiAgentClient implements AgentClient {
|
|
|
77
77
|
*/
|
|
78
78
|
resumeSession(handle: PersistenceHandle, overrides?: Partial<AgentSessionConfig>, launchContext?: LaunchContext): Promise<AgentSession>;
|
|
79
79
|
/**
|
|
80
|
-
* Discover models via the Pi RPC `get_available_models` command (no scratch session)
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* (sprint-043: dropping this field here caused every `agent_set_model_request` to fail with
|
|
84
|
-
* "Model not found: pi/<modelId>" — "pi" is the pi-studio `AgentClient` id, never a real LLM
|
|
85
|
-
* provider Pi recognizes).
|
|
80
|
+
* Discover models via the Pi RPC `get_available_models` command (no scratch session): from the
|
|
81
|
+
* given live `session`'s own process when there is one — the only list its `set_model` accepts —
|
|
82
|
+
* else from a fresh top-level process, which reads the current `models.json`.
|
|
86
83
|
*/
|
|
87
84
|
listModels(opts?: {
|
|
88
85
|
cwd?: string;
|
|
86
|
+
session?: AgentSession;
|
|
89
87
|
}): Promise<AgentModelDefinition[]>;
|
|
90
88
|
/** Pi RPC has no `list_modes`; modes come from the provider manifest, not the process. */
|
|
91
89
|
listModes(): Promise<AgentModeDefinition[]>;
|
|
@@ -43,6 +43,28 @@ function modelIdFrom(model) {
|
|
|
43
43
|
return rec.name;
|
|
44
44
|
return undefined;
|
|
45
45
|
}
|
|
46
|
+
/** Map a `get_available_models` response (raw Pi `Model` objects, docs/rpc.md § Model) to the
|
|
47
|
+
* contract's definitions. Each entry's own `provider` (the underlying LLM provider, e.g.
|
|
48
|
+
* `"anthropic"`) is REQUIRED to call `set_model` back (sprint-043: dropping it caused every
|
|
49
|
+
* `agent_set_model_request` to fail with "Model not found: pi/<modelId>" — "pi" is the pi-studio
|
|
50
|
+
* `AgentClient` id, never a real LLM provider Pi recognizes). */
|
|
51
|
+
function toModelDefinitions(data) {
|
|
52
|
+
const raw = data && typeof data === "object" && "models" in data ? data.models : undefined;
|
|
53
|
+
const models = Array.isArray(raw) ? raw : [];
|
|
54
|
+
return models.map((m) => {
|
|
55
|
+
const rec = m;
|
|
56
|
+
return {
|
|
57
|
+
id: String(rec.id ?? rec.name ?? ""),
|
|
58
|
+
label: typeof rec.name === "string" ? rec.name : String(rec.id ?? ""),
|
|
59
|
+
provider: typeof rec.provider === "string" ? rec.provider : undefined,
|
|
60
|
+
// Raw Pi `Model` objects carry `reasoning` + `thinkingLevelMap`; surface the derived
|
|
61
|
+
// per-model level list so clients can offer draft sessions the right levels with no
|
|
62
|
+
// live process (sprint-070/task-001).
|
|
63
|
+
reasoning: typeof rec.reasoning === "boolean" ? rec.reasoning : undefined,
|
|
64
|
+
thinkingLevels: deriveThinkingLevels(rec),
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
}
|
|
46
68
|
/** Dialog methods block for a client answer; every other extension UI method is fire-and-forget
|
|
47
69
|
* (docs/rpc.md § Extension UI Protocol). The single place the blocking set is encoded — a future Pi
|
|
48
70
|
* release that adds a method only ever touches this constant. */
|
|
@@ -384,6 +406,9 @@ class PiAgentSession {
|
|
|
384
406
|
const data = (await this.transport.request("export_html", params));
|
|
385
407
|
return { path: data?.path ?? "" };
|
|
386
408
|
}
|
|
409
|
+
async listModels() {
|
|
410
|
+
return toModelDefinitions(await this.transport.request("get_available_models"));
|
|
411
|
+
}
|
|
387
412
|
async setProviderModel(provider, modelId) {
|
|
388
413
|
const data = await this.transport.request("set_model", { provider, modelId });
|
|
389
414
|
const resolved = modelIdFrom(data);
|
|
@@ -544,30 +569,14 @@ export class PiAgentClient {
|
|
|
544
569
|
return session;
|
|
545
570
|
}
|
|
546
571
|
/**
|
|
547
|
-
* Discover models via the Pi RPC `get_available_models` command (no scratch session)
|
|
548
|
-
*
|
|
549
|
-
*
|
|
550
|
-
* (sprint-043: dropping this field here caused every `agent_set_model_request` to fail with
|
|
551
|
-
* "Model not found: pi/<modelId>" — "pi" is the pi-studio `AgentClient` id, never a real LLM
|
|
552
|
-
* provider Pi recognizes).
|
|
572
|
+
* Discover models via the Pi RPC `get_available_models` command (no scratch session): from the
|
|
573
|
+
* given live `session`'s own process when there is one — the only list its `set_model` accepts —
|
|
574
|
+
* else from a fresh top-level process, which reads the current `models.json`.
|
|
553
575
|
*/
|
|
554
576
|
async listModels(opts) {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
return models.map((m) => {
|
|
559
|
-
const rec = m;
|
|
560
|
-
return {
|
|
561
|
-
id: String(rec.id ?? rec.name ?? ""),
|
|
562
|
-
label: typeof rec.name === "string" ? rec.name : String(rec.id ?? ""),
|
|
563
|
-
provider: typeof rec.provider === "string" ? rec.provider : undefined,
|
|
564
|
-
// Raw Pi `Model` objects carry `reasoning` + `thinkingLevelMap`; surface the derived
|
|
565
|
-
// per-model level list so clients can offer draft sessions the right levels with no
|
|
566
|
-
// live process (sprint-070/task-001).
|
|
567
|
-
reasoning: typeof rec.reasoning === "boolean" ? rec.reasoning : undefined,
|
|
568
|
-
thinkingLevels: deriveThinkingLevels(rec),
|
|
569
|
-
};
|
|
570
|
-
});
|
|
577
|
+
if (opts?.session?.listModels)
|
|
578
|
+
return opts.session.listModels();
|
|
579
|
+
return toModelDefinitions(await this.topLevel("get_available_models", opts?.cwd));
|
|
571
580
|
}
|
|
572
581
|
/** Pi RPC has no `list_modes`; modes come from the provider manifest, not the process. */
|
|
573
582
|
listModes() {
|
|
@@ -2,7 +2,7 @@ import type { Session } from "../ws/session.js";
|
|
|
2
2
|
import type { HandlerRegistry } from "../ws/router.js";
|
|
3
3
|
import type { Logger } from "../logging/logger.js";
|
|
4
4
|
import type { AgentManager } from "./agent-manager.js";
|
|
5
|
-
import type { AgentClient } from "./provider-contract.js";
|
|
5
|
+
import type { AgentClient, AgentModelDefinition } from "./provider-contract.js";
|
|
6
6
|
/**
|
|
7
7
|
* Slash-command operations (sprint-037): Pi built-in commands that have a real Pi RPC equivalent
|
|
8
8
|
* — /session, /compact, /new, /resume, /fork, /clone, /name, /export, /model, /copy — surfaced as
|
|
@@ -12,7 +12,8 @@ import type { AgentClient } from "./provider-contract.js";
|
|
|
12
12
|
*
|
|
13
13
|
* Also hosts command *discovery* (sprint-040): `agent_list_commands_request` surfaces Pi's
|
|
14
14
|
* `get_commands` (extension commands, prompt templates, skills) for a live session — a disjoint
|
|
15
|
-
* set from the built-in slash commands above
|
|
15
|
+
* set from the built-in slash commands above — and the model picker's `list_provider_models`,
|
|
16
|
+
* next to the `set_model` it feeds.
|
|
16
17
|
*
|
|
17
18
|
* Pi's own RPC contract is explicit that TUI-only built-ins (/settings, /hotkeys, etc.) have no
|
|
18
19
|
* RPC equivalent and would not execute if sent via `prompt` — those are intentionally NOT
|
|
@@ -24,6 +25,12 @@ export interface SlashCommandOpsDeps {
|
|
|
24
25
|
broadcast: (sessions: Iterable<Session>, message: unknown) => void;
|
|
25
26
|
logger?: Logger;
|
|
26
27
|
}
|
|
28
|
+
export interface ListProviderModelsResult {
|
|
29
|
+
type: "list_provider_models_response";
|
|
30
|
+
requestId: string;
|
|
31
|
+
provider: string;
|
|
32
|
+
models: AgentModelDefinition[];
|
|
33
|
+
}
|
|
27
34
|
export declare class SlashCommandOperationsService {
|
|
28
35
|
private readonly deps;
|
|
29
36
|
constructor(deps: SlashCommandOpsDeps);
|
|
@@ -112,6 +119,12 @@ export declare class SlashCommandOperationsService {
|
|
|
112
119
|
* always the EFFECTIVE level (Pi clamps silently; the provider re-reads `get_state`), so the
|
|
113
120
|
* wire, the record, and the live process can never disagree. */
|
|
114
121
|
private persistThinking;
|
|
122
|
+
/** Model picker list (sprint-043). With an `agentId` whose live session belongs to `provider`,
|
|
123
|
+
* the agent's own process answers: Pi loads `models.json` once at spawn, so a fresh process can
|
|
124
|
+
* offer a model this agent's `set_model` then rejects ("Model not found") after the file was
|
|
125
|
+
* edited. With no agent, or no live process (it spawns fresh, reading the current file), a
|
|
126
|
+
* sessionless discovery answers as before. */
|
|
127
|
+
handleListProviderModels(msg: Record<string, unknown>, requestId: string | undefined): Promise<ListProviderModelsResult>;
|
|
115
128
|
/** `/model` (set) — broadcast the model change and persist it (see `persistModel`). A
|
|
116
129
|
* materialized draft with no live process yet (`managed.session === null` — deferred-draft
|
|
117
130
|
* creation, `agent-service.ts` `handleCreate`, defers the real spawn to first send) has no
|
|
@@ -30,6 +30,7 @@ export class SlashCommandOperationsService {
|
|
|
30
30
|
registry.register("agent_clone_request", (ctx) => this.handleClone(ctx.message, getActiveSessions));
|
|
31
31
|
registry.register("agent_set_session_name_request", (ctx) => this.handleSetSessionName(ctx.message, getActiveSessions));
|
|
32
32
|
registry.register("agent_export_html_request", (ctx) => this.handleExportHtml(ctx.message));
|
|
33
|
+
registry.register("list_provider_models", (ctx) => this.handleListProviderModels(ctx.message, ctx.requestId));
|
|
33
34
|
registry.register("agent_set_model_request", (ctx) => this.handleSetModel(ctx.message, getActiveSessions));
|
|
34
35
|
registry.register("agent_cycle_model_request", (ctx) => this.handleCycleModel(ctx.message, getActiveSessions));
|
|
35
36
|
registry.register("agent_last_assistant_text_request", (ctx) => this.handleLastAssistantText(ctx.message));
|
|
@@ -304,6 +305,20 @@ export class SlashCommandOperationsService {
|
|
|
304
305
|
};
|
|
305
306
|
await this.deps.manager.updateRecord(agentId, { config });
|
|
306
307
|
}
|
|
308
|
+
/** Model picker list (sprint-043). With an `agentId` whose live session belongs to `provider`,
|
|
309
|
+
* the agent's own process answers: Pi loads `models.json` once at spawn, so a fresh process can
|
|
310
|
+
* offer a model this agent's `set_model` then rejects ("Model not found") after the file was
|
|
311
|
+
* edited. With no agent, or no live process (it spawns fresh, reading the current file), a
|
|
312
|
+
* sessionless discovery answers as before. */
|
|
313
|
+
async handleListProviderModels(msg, requestId) {
|
|
314
|
+
const provider = String(msg.provider ?? "pi");
|
|
315
|
+
const cwd = msg.cwd ? String(msg.cwd) : undefined;
|
|
316
|
+
const agentId = typeof msg.agentId === "string" ? msg.agentId : undefined;
|
|
317
|
+
const live = agentId ? this.deps.manager.get(agentId)?.session : undefined;
|
|
318
|
+
const session = live?.provider === provider ? live : undefined;
|
|
319
|
+
const models = await this.deps.resolveClient(provider).listModels({ cwd, session });
|
|
320
|
+
return { type: "list_provider_models_response", requestId: requestId ?? "", provider, models };
|
|
321
|
+
}
|
|
307
322
|
/** `/model` (set) — broadcast the model change and persist it (see `persistModel`). A
|
|
308
323
|
* materialized draft with no live process yet (`managed.session === null` — deferred-draft
|
|
309
324
|
* creation, `agent-service.ts` `handleCreate`, defers the real spawn to first send) has no
|
package/dist/daemon/bootstrap.js
CHANGED
|
@@ -301,19 +301,6 @@ export function startDaemon(opts) {
|
|
|
301
301
|
requestId: ctx.requestId ?? "",
|
|
302
302
|
providers: providerRegistry.listMetadata(),
|
|
303
303
|
}));
|
|
304
|
-
// ── Provider model discovery (sprint-043: composer model selector) ──────────
|
|
305
|
-
registry.register("list_provider_models", async (ctx) => {
|
|
306
|
-
const provider = String(ctx.message.provider ?? "pi");
|
|
307
|
-
const cwd = ctx.message.cwd ? String(ctx.message.cwd) : undefined;
|
|
308
|
-
const client = resolveClient(provider);
|
|
309
|
-
const models = await client.listModels(cwd ? { cwd } : undefined);
|
|
310
|
-
return {
|
|
311
|
-
type: "list_provider_models_response",
|
|
312
|
-
requestId: ctx.requestId ?? "",
|
|
313
|
-
provider,
|
|
314
|
-
models,
|
|
315
|
-
};
|
|
316
|
-
});
|
|
317
304
|
const defaultModelCache = new Map();
|
|
318
305
|
// ── Default-model discovery (deferred-draft preselect: new chats show the model they'll
|
|
319
306
|
// actually run on before anything is spawned) ──────────────────────────────
|
|
@@ -198,19 +198,6 @@ export function startDevDaemon(opts) {
|
|
|
198
198
|
requestId: ctx.requestId ?? "",
|
|
199
199
|
providers: providerRegistry.listMetadata(),
|
|
200
200
|
}));
|
|
201
|
-
// ── Provider model discovery (sprint-043: composer model selector) ──────────
|
|
202
|
-
registry.register("list_provider_models", async (ctx) => {
|
|
203
|
-
const provider = String(ctx.message.provider ?? "pi");
|
|
204
|
-
const cwd = ctx.message.cwd ? String(ctx.message.cwd) : undefined;
|
|
205
|
-
const client = resolveClient(provider);
|
|
206
|
-
const models = await client.listModels(cwd ? { cwd } : undefined);
|
|
207
|
-
return {
|
|
208
|
-
type: "list_provider_models_response",
|
|
209
|
-
requestId: ctx.requestId ?? "",
|
|
210
|
-
provider,
|
|
211
|
-
models,
|
|
212
|
-
};
|
|
213
|
-
});
|
|
214
201
|
const defaultModelCache = new Map();
|
|
215
202
|
// ── Default-model discovery (deferred-draft preselect) ───────────────────
|
|
216
203
|
registry.register("resolve_default_model", async (ctx) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@av-pi-studio/server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.111",
|
|
4
4
|
"bin": {
|
|
5
5
|
"pi-studio-daemon": "dist/daemon/main.js"
|
|
6
6
|
},
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"clean": "rm -rf dist *.tsbuildinfo"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@av-pi-studio/protocol": "^0.0.
|
|
28
|
-
"@av-pi-studio/relay": "^0.0.
|
|
29
|
-
"@earendil-works/pi-coding-agent": "^1.
|
|
27
|
+
"@av-pi-studio/protocol": "^0.0.111",
|
|
28
|
+
"@av-pi-studio/relay": "^0.0.111",
|
|
29
|
+
"@earendil-works/pi-coding-agent": "^1.4.0",
|
|
30
30
|
"@xterm/addon-serialize": "^0.14.0",
|
|
31
31
|
"@xterm/headless": "^6.0.0",
|
|
32
32
|
"bcryptjs": "^3.0.3",
|