@averyyy/pi-coding-agent 1.4.0-piclient.14 → 1.4.0-piclient.16
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/CHANGELOG.md +1 -0
- package/dist/bundle/chunks/{anthropic-messages-3TZAX2CL.js → anthropic-messages-RTMTRCJD.js} +1 -1
- package/dist/bundle/chunks/{azure-openai-responses-5OV6AS44.js → azure-openai-responses-32IFXADQ.js} +1 -1
- package/dist/bundle/chunks/{chunk-TLSZ4DWU.js → chunk-3W4ECU36.js} +1 -1
- package/dist/bundle/chunks/{chunk-D3OXAPLU.js → chunk-7TZ46DX3.js} +2 -2
- package/dist/bundle/chunks/{chunk-AFR3MIYD.js → chunk-NIXXKXME.js} +1 -1
- package/dist/bundle/chunks/{chunk-WVXVPMMO.js → chunk-PQ65VYIJ.js} +1 -1
- package/dist/bundle/chunks/{chunk-HZG4C6GI.js → chunk-QTBWPXJ6.js} +1 -1
- package/dist/bundle/chunks/{chunk-MKWEYCNF.js → chunk-RA32KT4S.js} +1 -1
- package/dist/bundle/chunks/{chunk-J2L5V6ES.js → chunk-RSPBBB2E.js} +42 -39
- package/dist/bundle/chunks/{chunk-VHUVVKJM.js → chunk-ULEDFAAS.js} +1 -1
- package/dist/bundle/chunks/{chunk-H76KZMOI.js → chunk-ZADMB3XG.js} +1 -1
- package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-QIIM6OB4.js → cloudflare-workers-ai-system-one-SHFSUL5R.js} +1 -1
- package/dist/bundle/chunks/devin.js +1 -1
- package/dist/bundle/chunks/google-antigravity.js +1 -1
- package/dist/bundle/chunks/{google-generative-ai-PNRT4EAN.js → google-generative-ai-4X76WNE7.js} +1 -1
- package/dist/bundle/chunks/{google-vertex-ZLSXUSEM.js → google-vertex-EXVYF56Z.js} +1 -1
- package/dist/bundle/chunks/{llama-cpp-classify-U4EH6TAM.js → llama-cpp-classify-K2UE4X5S.js} +1 -1
- package/dist/bundle/chunks/{mistral-conversations-OJFHLO4F.js → mistral-conversations-WQWSUHPM.js} +1 -1
- package/dist/bundle/chunks/{openai-codex-responses-UIB63WGM.js → openai-codex-responses-HUGPPMN4.js} +1 -1
- package/dist/bundle/chunks/{openai-completions-T5JB7LUM.js → openai-completions-VKJKJ3X3.js} +1 -1
- package/dist/bundle/chunks/{openai-decisions-Q46R33J3.js → openai-decisions-D4KWSP7Z.js} +1 -1
- package/dist/bundle/chunks/{openai-responses-FGTD6NDJ.js → openai-responses-SYCUDQZV.js} +1 -1
- package/dist/bundle/chunks/{openrouter-images-WBAVKHHY.js → openrouter-images-IIEU7ZDJ.js} +1 -1
- package/dist/bundle/chunks/{pi-messages-S7RKCD5K.js → pi-messages-SPC4GJC7.js} +1 -1
- package/dist/bundle/chunks/{typesafe-system-one-DFEHTLK5.js → typesafe-system-one-J55G2O6T.js} +1 -1
- package/dist/bundle/chunks/{virtual-modules-N6G7JXII.js → virtual-modules-S2BCYRZG.js} +1 -1
- package/dist/bundle/cli-runtime.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/cli/auth-check.d.ts.map +1 -1
- package/dist/cli/auth-check.js +12 -1
- package/dist/cli/auth-check.js.map +1 -1
- package/dist/cli/credential-print.d.ts.map +1 -1
- package/dist/cli/credential-print.js +6 -0
- package/dist/cli/credential-print.js.map +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +9 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +5 -0
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-runtime.d.ts +11 -4
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +153 -12
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/pi-server-accounts.d.ts +22 -0
- package/dist/core/pi-server-accounts.d.ts.map +1 -0
- package/dist/core/pi-server-accounts.js +137 -0
- package/dist/core/pi-server-accounts.js.map +1 -0
- package/dist/core/pi-server-client.d.ts +10 -7
- package/dist/core/pi-server-client.d.ts.map +1 -1
- package/dist/core/pi-server-client.js +11 -4
- package/dist/core/pi-server-client.js.map +1 -1
- package/dist/core/provider-composer.d.ts +1 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +1 -0
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +2 -1
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +37 -17
- package/dist/core/sdk.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +13 -4
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { raceWithAbortSignal } from "../utils/abort.js";
|
|
3
|
+
import { ChunkRequest } from "./pi-server-request.js";
|
|
4
|
+
export function isPiServerAccountProvider(providerId) {
|
|
5
|
+
return providerId === "devin" || providerId === "google-antigravity";
|
|
6
|
+
}
|
|
7
|
+
function request(signal) {
|
|
8
|
+
return new ChunkRequest({
|
|
9
|
+
serverUrl: process.env.PI_SERVER_URL ?? "http://127.0.0.1:4217",
|
|
10
|
+
authToken: process.env.PI_SERVER_AUTH_TOKEN ?? "",
|
|
11
|
+
signal,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
async function requireSuccess(response) {
|
|
15
|
+
if (response.ok)
|
|
16
|
+
return;
|
|
17
|
+
throw new Error(`pi-server account request failed (${response.status}): ${(await response.text()).slice(0, 500)}`);
|
|
18
|
+
}
|
|
19
|
+
export async function readPiServerAccounts(signal) {
|
|
20
|
+
const response = await request(signal).getJson("/api/accounts");
|
|
21
|
+
await requireSuccess(response);
|
|
22
|
+
return response.json();
|
|
23
|
+
}
|
|
24
|
+
export async function refreshPiServerAccounts(providerId, signal) {
|
|
25
|
+
const response = await request(signal).postJson("/api/accounts/refresh", { providerId });
|
|
26
|
+
await requireSuccess(response);
|
|
27
|
+
return response.json();
|
|
28
|
+
}
|
|
29
|
+
export async function logoutPiServerAccount(providerId, signal) {
|
|
30
|
+
const response = await request(signal).postJson("/api/accounts/logout", { providerId });
|
|
31
|
+
await requireSuccess(response);
|
|
32
|
+
return response.json();
|
|
33
|
+
}
|
|
34
|
+
export async function loginPiServerAccount(providerId, interaction) {
|
|
35
|
+
const loginId = randomUUID();
|
|
36
|
+
const controller = new AbortController();
|
|
37
|
+
const signal = interaction.signal ? AbortSignal.any([interaction.signal, controller.signal]) : controller.signal;
|
|
38
|
+
const prompts = new Map();
|
|
39
|
+
const replies = new Set();
|
|
40
|
+
let snapshot;
|
|
41
|
+
try {
|
|
42
|
+
const response = await request(signal).postJson("/api/accounts/login", { providerId, loginId });
|
|
43
|
+
await requireSuccess(response);
|
|
44
|
+
if (!response.headers.get("content-type")?.includes("text/event-stream") || !response.body) {
|
|
45
|
+
throw new Error("pi-server account login requires an event stream");
|
|
46
|
+
}
|
|
47
|
+
const reader = response.body.getReader();
|
|
48
|
+
const decoder = new TextDecoder();
|
|
49
|
+
let pending = "";
|
|
50
|
+
let eventName = "";
|
|
51
|
+
let data = [];
|
|
52
|
+
const dispatch = () => {
|
|
53
|
+
if (data.length === 0)
|
|
54
|
+
return;
|
|
55
|
+
const value = JSON.parse(data.join("\n"));
|
|
56
|
+
if (eventName === "notify")
|
|
57
|
+
interaction.notify(value);
|
|
58
|
+
else if (eventName === "prompt") {
|
|
59
|
+
const { promptId, prompt } = value;
|
|
60
|
+
const promptController = new AbortController();
|
|
61
|
+
prompts.set(promptId, promptController);
|
|
62
|
+
const reply = (async () => {
|
|
63
|
+
try {
|
|
64
|
+
const promptSignal = AbortSignal.any([signal, promptController.signal]);
|
|
65
|
+
const value = await raceWithAbortSignal(interaction.prompt({ ...prompt, signal: promptSignal }), promptSignal);
|
|
66
|
+
if (promptController.signal.aborted)
|
|
67
|
+
return;
|
|
68
|
+
const response = await request(signal).postJson("/api/accounts/login/reply", {
|
|
69
|
+
loginId,
|
|
70
|
+
promptId,
|
|
71
|
+
value,
|
|
72
|
+
});
|
|
73
|
+
await requireSuccess(response);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
if (!promptController.signal.aborted)
|
|
77
|
+
controller.abort(error);
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
prompts.delete(promptId);
|
|
81
|
+
}
|
|
82
|
+
})();
|
|
83
|
+
replies.add(reply);
|
|
84
|
+
void reply.finally(() => replies.delete(reply));
|
|
85
|
+
}
|
|
86
|
+
else if (eventName === "prompt_cancel") {
|
|
87
|
+
prompts.get(value.promptId)?.abort();
|
|
88
|
+
}
|
|
89
|
+
else if (eventName === "done")
|
|
90
|
+
snapshot = value;
|
|
91
|
+
else if (eventName === "error")
|
|
92
|
+
throw new Error(value.error);
|
|
93
|
+
};
|
|
94
|
+
try {
|
|
95
|
+
while (snapshot === undefined) {
|
|
96
|
+
const { value, done } = await reader.read();
|
|
97
|
+
pending += decoder.decode(value, { stream: !done });
|
|
98
|
+
let end = pending.indexOf("\n");
|
|
99
|
+
while (end >= 0) {
|
|
100
|
+
const line = pending.slice(0, end).replace(/\r$/u, "");
|
|
101
|
+
pending = pending.slice(end + 1);
|
|
102
|
+
if (line === "") {
|
|
103
|
+
dispatch();
|
|
104
|
+
eventName = "";
|
|
105
|
+
data = [];
|
|
106
|
+
}
|
|
107
|
+
else if (line.startsWith("event:"))
|
|
108
|
+
eventName = line.slice(6).trim();
|
|
109
|
+
else if (line.startsWith("data:"))
|
|
110
|
+
data.push(line.slice(5).trimStart());
|
|
111
|
+
end = pending.indexOf("\n");
|
|
112
|
+
}
|
|
113
|
+
if (done)
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
if (!snapshot)
|
|
117
|
+
throw new Error("pi-server account login ended without a result");
|
|
118
|
+
return snapshot;
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
await reader.cancel();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
const cancellation = await request(AbortSignal.timeout(15_000)).postJson("/api/accounts/login/cancel", {
|
|
126
|
+
loginId,
|
|
127
|
+
});
|
|
128
|
+
await requireSuccess(cancellation);
|
|
129
|
+
throw controller.signal.aborted ? controller.signal.reason : error;
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
for (const prompt of prompts.values())
|
|
133
|
+
prompt.abort();
|
|
134
|
+
await Promise.all(replies);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=pi-server-accounts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-server-accounts.js","sourceRoot":"","sources":["../../src/core/pi-server-accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAiBtD,MAAM,UAAU,yBAAyB,CAAC,UAAkB;IAC3D,OAAO,UAAU,KAAK,OAAO,IAAI,UAAU,KAAK,oBAAoB,CAAC;AACtE,CAAC;AAED,SAAS,OAAO,CAAC,MAAoB;IACpC,OAAO,IAAI,YAAY,CAAC;QACvB,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,uBAAuB;QAC/D,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,EAAE;QACjD,MAAM;KACN,CAAC,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,cAAc,CAAC,QAAkB;IAC/C,IAAI,QAAQ,CAAC,EAAE;QAAE,OAAO;IACxB,MAAM,IAAI,KAAK,CAAC,qCAAqC,QAAQ,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I,IAAI;oBAAE,MAAM;YACjB,CAAC;YACD,IAAI,CAAC,QAAQ;gBAAE,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;YACjF,OAAO,QAAQ,CAAC;QACjB,CAAC;gBAAS,CAAC;YACV,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC;QACvB,CAAC;IACF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,4BAA4B,EAAE;YACtG,OAAO;SACP,CAAC,CAAC;QACH,MAAM,cAAc,CAAC,YAAY,CAAC,CAAC;QACnC,MAAM,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;IACpE,CAAC;YAAS,CAAC;QACV,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE;YAAE,MAAM,CAAC,KAAK,EAAE,CAAC;QACtD,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;AACF,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { Api, AuthEvent, AuthInteraction, AuthPrompt, Model } from \"@earendil-works/pi-ai\";\nimport { raceWithAbortSignal } from \"../utils/abort.ts\";\nimport { ChunkRequest } from \"./pi-server-request.ts\";\n\nexport type PiServerAccountProviderId = \"devin\" | \"google-antigravity\";\n\nexport interface PiServerAccount {\n\tproviderId: PiServerAccountProviderId;\n\tloggedIn: boolean;\n\tmodels: Model<Api>[];\n\tupdatedAt?: number;\n\terror?: string;\n\taccount?: { email?: string; projectId?: string };\n}\n\nexport interface PiServerAccountsSnapshot {\n\taccounts: PiServerAccount[];\n}\n\nexport function isPiServerAccountProvider(providerId: string): providerId is PiServerAccountProviderId {\n\treturn providerId === \"devin\" || providerId === \"google-antigravity\";\n}\n\nfunction request(signal?: AbortSignal): ChunkRequest {\n\treturn new ChunkRequest({\n\t\tserverUrl: process.env.PI_SERVER_URL ?? \"http://127.0.0.1:4217\",\n\t\tauthToken: process.env.PI_SERVER_AUTH_TOKEN ?? \"\",\n\t\tsignal,\n\t});\n}\n\nasync function requireSuccess(response: Response): Promise<void> {\n\tif (response.ok) return;\n\tthrow new Error(`pi-server account request failed (${response.status}): ${(await response.text()).slice(0, 500)}`);\n}\n\nexport async function readPiServerAccounts(signal?: AbortSignal): Promise<PiServerAccountsSnapshot> {\n\tconst response = await request(signal).getJson(\"/api/accounts\");\n\tawait requireSuccess(response);\n\treturn response.json() as Promise<PiServerAccountsSnapshot>;\n}\n\nexport async function refreshPiServerAccounts(\n\tproviderId: PiServerAccountProviderId | undefined,\n\tsignal?: AbortSignal,\n): Promise<PiServerAccountsSnapshot> {\n\tconst response = await request(signal).postJson(\"/api/accounts/refresh\", { providerId });\n\tawait requireSuccess(response);\n\treturn response.json() as Promise<PiServerAccountsSnapshot>;\n}\n\nexport async function logoutPiServerAccount(\n\tproviderId: PiServerAccountProviderId,\n\tsignal?: AbortSignal,\n): Promise<PiServerAccountsSnapshot> {\n\tconst response = await request(signal).postJson(\"/api/accounts/logout\", { providerId });\n\tawait requireSuccess(response);\n\treturn response.json() as Promise<PiServerAccountsSnapshot>;\n}\n\nexport async function loginPiServerAccount(\n\tproviderId: PiServerAccountProviderId,\n\tinteraction: AuthInteraction,\n): Promise<PiServerAccountsSnapshot> {\n\tconst loginId = randomUUID();\n\tconst controller = new AbortController();\n\tconst signal = interaction.signal ? AbortSignal.any([interaction.signal, controller.signal]) : controller.signal;\n\tconst prompts = new Map<string, AbortController>();\n\tconst replies = new Set<Promise<void>>();\n\tlet snapshot: PiServerAccountsSnapshot | undefined;\n\ttry {\n\t\tconst response = await request(signal).postJson(\"/api/accounts/login\", { providerId, loginId });\n\t\tawait requireSuccess(response);\n\t\tif (!response.headers.get(\"content-type\")?.includes(\"text/event-stream\") || !response.body) {\n\t\t\tthrow new Error(\"pi-server account login requires an event stream\");\n\t\t}\n\t\tconst reader = response.body.getReader();\n\t\tconst decoder = new TextDecoder();\n\t\tlet pending = \"\";\n\t\tlet eventName = \"\";\n\t\tlet data: string[] = [];\n\t\tconst dispatch = (): void => {\n\t\t\tif (data.length === 0) return;\n\t\t\tconst value = JSON.parse(data.join(\"\\n\")) as unknown;\n\t\t\tif (eventName === \"notify\") interaction.notify(value as AuthEvent);\n\t\t\telse if (eventName === \"prompt\") {\n\t\t\t\tconst { promptId, prompt } = value as { promptId: string; prompt: Omit<AuthPrompt, \"signal\"> };\n\t\t\t\tconst promptController = new AbortController();\n\t\t\t\tprompts.set(promptId, promptController);\n\t\t\t\tconst reply = (async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst promptSignal = AbortSignal.any([signal, promptController.signal]);\n\t\t\t\t\t\tconst value = await raceWithAbortSignal(\n\t\t\t\t\t\t\tinteraction.prompt({ ...prompt, signal: promptSignal } as AuthPrompt),\n\t\t\t\t\t\t\tpromptSignal,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (promptController.signal.aborted) return;\n\t\t\t\t\t\tconst response = await request(signal).postJson(\"/api/accounts/login/reply\", {\n\t\t\t\t\t\t\tloginId,\n\t\t\t\t\t\t\tpromptId,\n\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tawait requireSuccess(response);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tif (!promptController.signal.aborted) controller.abort(error);\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tprompts.delete(promptId);\n\t\t\t\t\t}\n\t\t\t\t})();\n\t\t\t\treplies.add(reply);\n\t\t\t\tvoid reply.finally(() => replies.delete(reply));\n\t\t\t} else if (eventName === \"prompt_cancel\") {\n\t\t\t\tprompts.get((value as { promptId: string }).promptId)?.abort();\n\t\t\t} else if (eventName === \"done\") snapshot = value as PiServerAccountsSnapshot;\n\t\t\telse if (eventName === \"error\") throw new Error((value as { error: string }).error);\n\t\t};\n\t\ttry {\n\t\t\twhile (snapshot === undefined) {\n\t\t\t\tconst { value, done } = await reader.read();\n\t\t\t\tpending += decoder.decode(value, { stream: !done });\n\t\t\t\tlet end = pending.indexOf(\"\\n\");\n\t\t\t\twhile (end >= 0) {\n\t\t\t\t\tconst line = pending.slice(0, end).replace(/\\r$/u, \"\");\n\t\t\t\t\tpending = pending.slice(end + 1);\n\t\t\t\t\tif (line === \"\") {\n\t\t\t\t\t\tdispatch();\n\t\t\t\t\t\teventName = \"\";\n\t\t\t\t\t\tdata = [];\n\t\t\t\t\t} else if (line.startsWith(\"event:\")) eventName = line.slice(6).trim();\n\t\t\t\t\telse if (line.startsWith(\"data:\")) data.push(line.slice(5).trimStart());\n\t\t\t\t\tend = pending.indexOf(\"\\n\");\n\t\t\t\t}\n\t\t\t\tif (done) break;\n\t\t\t}\n\t\t\tif (!snapshot) throw new Error(\"pi-server account login ended without a result\");\n\t\t\treturn snapshot;\n\t\t} finally {\n\t\t\tawait reader.cancel();\n\t\t}\n\t} catch (error) {\n\t\tconst cancellation = await request(AbortSignal.timeout(15_000)).postJson(\"/api/accounts/login/cancel\", {\n\t\t\tloginId,\n\t\t});\n\t\tawait requireSuccess(cancellation);\n\t\tthrow controller.signal.aborted ? controller.signal.reason : error;\n\t} finally {\n\t\tfor (const prompt of prompts.values()) prompt.abort();\n\t\tawait Promise.all(replies);\n\t}\n}\n"]}
|
|
@@ -25,7 +25,10 @@ export interface PiServerHistorySnapshot {
|
|
|
25
25
|
leafId: string | null;
|
|
26
26
|
messages: Message[];
|
|
27
27
|
}
|
|
28
|
-
export interface
|
|
28
|
+
export interface PiServerAccountOptions {
|
|
29
|
+
authSource?: "server-account";
|
|
30
|
+
}
|
|
31
|
+
export interface PiServerStreamOptions extends SimpleStreamOptions, PiServerAccountOptions {
|
|
29
32
|
/** Monotonic start of run preparation or the last top-level tool completion; kept client-local. */
|
|
30
33
|
clientTiming?: {
|
|
31
34
|
startedAt: number;
|
|
@@ -47,10 +50,10 @@ interface PiServerSyncOptions {
|
|
|
47
50
|
onHistoryReconciled?: (snapshot: PiServerHistorySnapshot) => void | Promise<void>;
|
|
48
51
|
}
|
|
49
52
|
export declare function syncPiServerTree(sessionId: string, context: Context, tree: PiServerTreeSnapshot, options?: PiServerSyncOptions): Promise<void>;
|
|
50
|
-
export declare function streamRawPiServer<TApi extends string>(model: Model<TApi>, context: Context, options?: ModelsApiStreamOptions<TApi>): Promise<PiServerEventStream>;
|
|
51
|
-
export declare function fetchDeferredPiServer(model: Model<string>, handle: DeferredHandle, options?: DeferredFetchOptions): Promise<PiServerEventStream>;
|
|
52
|
-
export declare function cancelDeferredPiServer(model: Model<string>, handle: DeferredHandle, options?: DeferredCancelOptions): Promise<void>;
|
|
53
|
-
export interface PiServerCompactOptions extends SimpleStreamOptions {
|
|
53
|
+
export declare function streamRawPiServer<TApi extends string>(model: Model<TApi>, context: Context, options?: ModelsApiStreamOptions<TApi> & PiServerAccountOptions): Promise<PiServerEventStream>;
|
|
54
|
+
export declare function fetchDeferredPiServer(model: Model<string>, handle: DeferredHandle, options?: DeferredFetchOptions & PiServerAccountOptions): Promise<PiServerEventStream>;
|
|
55
|
+
export declare function cancelDeferredPiServer(model: Model<string>, handle: DeferredHandle, options?: DeferredCancelOptions & PiServerAccountOptions): Promise<void>;
|
|
56
|
+
export interface PiServerCompactOptions extends SimpleStreamOptions, PiServerAccountOptions {
|
|
54
57
|
ownerSessionId?: string;
|
|
55
58
|
customInstructions?: string;
|
|
56
59
|
settings?: unknown;
|
|
@@ -76,6 +79,6 @@ export interface PiServerModelCatalog {
|
|
|
76
79
|
}[];
|
|
77
80
|
}
|
|
78
81
|
export declare function fetchPiServerModels(options?: AuthOperationOptions): Promise<PiServerModelCatalog>;
|
|
79
|
-
export declare function generateImagesPiServer(model: ImageModel<ImageApi>, context: ImagesContext, options?: ImagesOptions): Promise<AssistantImages>;
|
|
80
|
-
export declare function classifyPiServer(model: ClassifierModel<ClassifierApi>, context: ClassifierContext, options?: ClassifierOptions): Promise<ClassifierResult>;
|
|
82
|
+
export declare function generateImagesPiServer(model: ImageModel<ImageApi>, context: ImagesContext, options?: ImagesOptions & PiServerAccountOptions): Promise<AssistantImages>;
|
|
83
|
+
export declare function classifyPiServer(model: ClassifierModel<ClassifierApi>, context: ClassifierContext, options?: ClassifierOptions & PiServerAccountOptions): Promise<ClassifierResult>;
|
|
81
84
|
//# sourceMappingURL=pi-server-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi-server-client.d.ts","sourceRoot":"","sources":["../../src/core/pi-server-client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,4BAA4B,EAC5B,mBAAmB,EAEnB,gBAAgB,EAChB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACN,KAAK,QAAQ,EACb,KAAK,eAAe,EAGpB,KAAK,2BAA2B,EAChC,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,OAAO,EAEZ,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,cAAc,EAEnB,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,sBAAsB,
|
|
1
|
+
{"version":3,"file":"pi-server-client.d.ts","sourceRoot":"","sources":["../../src/core/pi-server-client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,4BAA4B,EAC5B,mBAAmB,EAEnB,gBAAgB,EAChB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACN,KAAK,QAAQ,EACb,KAAK,eAAe,EAGpB,KAAK,2BAA2B,EAChC,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,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,KAAK,CAAC,GAAG,CAAC,EACjB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,qBAAqB,GAC7B,OAAO,CAAC,mBAAmB,CAAC,CAgX9B;AAiGD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC;AAetC,MAAM,WAAW,oBAAoB;IACpC,MAAM,EAAE,QAAQ,EAAE,CAAC;IACnB,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,SAAS,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,OAAO,CAAC;QAAC,cAAc,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;CAC7E;AAED,wBAAsB,mBAAmB,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAGvG;AAED,wBAAsB,sBAAsB,CAC3C,KAAK,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC3B,OAAO,EAAE,aAAa,EACtB,OAAO,CAAC,EAAE,aAAa,GAAG,sBAAsB,GAC9C,OAAO,CAAC,eAAe,CAAC,CAsB1B;AAED,wBAAsB,gBAAgB,CACrC,KAAK,EAAE,eAAe,CAAC,aAAa,CAAC,EACrC,OAAO,EAAE,iBAAiB,EAC1B,OAAO,CAAC,EAAE,iBAAiB,GAAG,sBAAsB,GAClD,OAAO,CAAC,gBAAgB,CAAC,CAsB3B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
3
|
-
import { createAssistantMessageEventStream, getModelType, parseStreamingJson, } from "@earendil-works/pi-ai";
|
|
3
|
+
import { createAssistantMessageEventStream, getModelType, parseStreamingJson, registerSessionResourceCleanup, } from "@earendil-works/pi-ai";
|
|
4
4
|
import { raceWithAbortSignal } from "../utils/abort.js";
|
|
5
5
|
import { buildPiServerTreePrefixHashes, hashPiServerSessionEntries, hashPiServerStaticContext, } from "./pi-server-protocol.js";
|
|
6
6
|
import { ChunkRequest } from "./pi-server-request.js";
|
|
@@ -63,6 +63,10 @@ export function resetSessionTracking(sessionId) {
|
|
|
63
63
|
sessionTreeLeafIds.delete(sessionId);
|
|
64
64
|
sessionHasTemporaryTree.delete(sessionId);
|
|
65
65
|
}
|
|
66
|
+
registerSessionResourceCleanup((sessionId) => {
|
|
67
|
+
if (sessionId !== undefined)
|
|
68
|
+
resetSessionTracking(sessionId);
|
|
69
|
+
});
|
|
66
70
|
export function resetAllSessionTracking() {
|
|
67
71
|
sessionStaticContextHashes.clear();
|
|
68
72
|
sessionTreeHashes.clear();
|
|
@@ -618,6 +622,7 @@ async function syncPiServerTreeWithRequest(sessionId, context, tree, request, on
|
|
|
618
622
|
}
|
|
619
623
|
function serializeOptions(options) {
|
|
620
624
|
return {
|
|
625
|
+
authSource: options?.authSource,
|
|
621
626
|
temperature: options?.temperature,
|
|
622
627
|
maxTokens: options?.maxTokens,
|
|
623
628
|
samplingParams: options?.samplingParams,
|
|
@@ -644,6 +649,7 @@ export function streamRawPiServer(model, context, options) {
|
|
|
644
649
|
throw new Error("Prepared stream option transforms cannot execute on pi-server");
|
|
645
650
|
}
|
|
646
651
|
return streamPiServer(model, context, {
|
|
652
|
+
authSource: options?.authSource,
|
|
647
653
|
signal: options?.signal,
|
|
648
654
|
sessionId: options?.sessionId,
|
|
649
655
|
onProviderStreamEvent: options?.onProviderStreamEvent,
|
|
@@ -988,9 +994,6 @@ export async function streamPiServer(model, context, options) {
|
|
|
988
994
|
if (!terminalReceived) {
|
|
989
995
|
throw new Error("pi-server stream ended before a terminal response event");
|
|
990
996
|
}
|
|
991
|
-
if (isEphemeralSession) {
|
|
992
|
-
resetSessionTracking(sessionId);
|
|
993
|
-
}
|
|
994
997
|
stream.end();
|
|
995
998
|
}
|
|
996
999
|
catch (error) {
|
|
@@ -1086,6 +1089,8 @@ export async function streamPiServer(model, context, options) {
|
|
|
1086
1089
|
stream.end();
|
|
1087
1090
|
}
|
|
1088
1091
|
finally {
|
|
1092
|
+
if (isEphemeralSession)
|
|
1093
|
+
resetSessionTracking(sessionId);
|
|
1089
1094
|
try {
|
|
1090
1095
|
await finishPiServerOperation(operation, options?.signal?.aborted === true || callbackFailed || observerFailed);
|
|
1091
1096
|
}
|
|
@@ -1205,6 +1210,7 @@ export async function generateImagesPiServer(model, context, options) {
|
|
|
1205
1210
|
model,
|
|
1206
1211
|
context,
|
|
1207
1212
|
options: {
|
|
1213
|
+
authSource: options?.authSource,
|
|
1208
1214
|
apiKey: options?.apiKey,
|
|
1209
1215
|
env: options?.env,
|
|
1210
1216
|
headers: options?.headers,
|
|
@@ -1222,6 +1228,7 @@ export async function classifyPiServer(model, context, options) {
|
|
|
1222
1228
|
model,
|
|
1223
1229
|
context,
|
|
1224
1230
|
options: {
|
|
1231
|
+
authSource: options?.authSource,
|
|
1225
1232
|
apiKey: options?.apiKey,
|
|
1226
1233
|
env: options?.env,
|
|
1227
1234
|
headers: options?.headers,
|