@ssweens/pi-vertex 1.1.13 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +125 -0
- package/README.md +86 -36
- package/TEST_COVERAGE.md +36 -2
- package/auth.ts +1 -1
- package/config.ts +1 -1
- package/index.ts +16 -7
- package/models/claude.ts +188 -22
- package/models/gemini.ts +200 -42
- package/models/maas.ts +241 -201
- package/package.json +15 -6
- package/streaming/gemini.ts +71 -35
- package/streaming/index.ts +30 -1
- package/streaming/maas.ts +90 -33
- package/streaming/sse-comment-filter.ts +169 -0
- package/tests/first-byte-timeout-check.mjs +56 -0
- package/tests/model-catalog-check.mjs +122 -0
- package/types.ts +22 -2
- package/utils.ts +5 -3
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/** Catalog additions and Vertex's GPT Responses request/replay contract. No network. */
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { existsSync, mkdtempSync, rmSync } from "node:fs";
|
|
4
|
+
import { registerHooks } from "node:module";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { GoogleAuth } from "google-auth-library";
|
|
9
|
+
import { getSupportedThinkingLevels } from "@earendil-works/pi-ai";
|
|
10
|
+
|
|
11
|
+
// Production uses Pi's TS loader. Resolve its .js source imports for Node's type stripper.
|
|
12
|
+
const root = new URL("../", import.meta.url).href;
|
|
13
|
+
registerHooks({
|
|
14
|
+
resolve(specifier, context, nextResolve) {
|
|
15
|
+
if (specifier.startsWith(".") && specifier.endsWith(".js") &&
|
|
16
|
+
context.parentURL?.startsWith(root) && !context.parentURL.includes("/node_modules/")) {
|
|
17
|
+
const source = new URL(specifier.slice(0, -3) + ".ts", context.parentURL);
|
|
18
|
+
if (existsSync(source)) return nextResolve(source.href, context);
|
|
19
|
+
}
|
|
20
|
+
return nextResolve(specifier, context);
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
const { ALL_MODELS, getModelById } = await import("../models/index.ts");
|
|
24
|
+
const { streamVertex } = await import("../streaming/index.ts");
|
|
25
|
+
assert.equal(new Set(ALL_MODELS.map(m => m.id)).size, ALL_MODELS.length, "unique model IDs");
|
|
26
|
+
|
|
27
|
+
const neon = getModelById("gemini-4-neon");
|
|
28
|
+
assert.equal(neon.apiId, "gemini-4-neon");
|
|
29
|
+
assert.equal(neon.endpointType, "gemini");
|
|
30
|
+
assert.equal(neon.contextWindow, 1048576);
|
|
31
|
+
assert.equal(neon.maxTokens, 65536);
|
|
32
|
+
assert.deepEqual(neon.cost, { input: 3, output: 15, cacheRead: 0.15, cacheWrite: 0 });
|
|
33
|
+
assert.deepEqual(getSupportedThinkingLevels(neon), ["off", "low", "medium", "high", "xhigh"]);
|
|
34
|
+
const deepseek = getModelById("deepseek-v4.1-flash-1017");
|
|
35
|
+
assert.equal(deepseek.apiId, "deepseek-ai/deepseek-v4.1-flash-1017-maas");
|
|
36
|
+
assert.equal(deepseek.cost.cacheRead, 0.006);
|
|
37
|
+
assert.deepEqual(getSupportedThinkingLevels(deepseek), ["off", "minimal", "low", "medium", "high", "max"]);
|
|
38
|
+
const grok = getModelById("grok-4.20-non-reasoning");
|
|
39
|
+
assert.equal(grok.apiId, "grok-4.20-non-reasoning");
|
|
40
|
+
assert.equal(grok.tools, true);
|
|
41
|
+
assert.deepEqual(getSupportedThinkingLevels(grok), ["off"]);
|
|
42
|
+
const gptIds = ["gpt-6.2-astra", "gpt-6.2-sol", "gpt-6-astra", "gpt-6.1-sol", "gpt-6.1-terra", "gpt-6-luna"];
|
|
43
|
+
for (const id of gptIds) {
|
|
44
|
+
const m = getModelById(id);
|
|
45
|
+
assert.equal(m.apiId, id);
|
|
46
|
+
assert.equal(m.publisher, "openai");
|
|
47
|
+
assert.equal(m.maasApi, "responses");
|
|
48
|
+
assert.equal(m.contextWindow, 1050000);
|
|
49
|
+
assert.equal(m.maxTokens, 128000);
|
|
50
|
+
assert.deepEqual(m.input, ["text", "image"]);
|
|
51
|
+
assert.equal(m.tools, true);
|
|
52
|
+
assert.deepEqual(getSupportedThinkingLevels(m), ["off", "low", "medium", "high", "xhigh", "max"]);
|
|
53
|
+
}
|
|
54
|
+
assert.equal(getModelById("gpt-oss-120b").maasApi, undefined, "GPT-OSS stays on Chat Completions");
|
|
55
|
+
|
|
56
|
+
const dir = mkdtempSync(join(tmpdir(), "pi-vertex-catalog-"));
|
|
57
|
+
const savedEnv = { ...process.env };
|
|
58
|
+
const getClient = GoogleAuth.prototype.getClient;
|
|
59
|
+
process.env.PI_CODING_AGENT_DIR = dir;
|
|
60
|
+
process.env.GOOGLE_CLOUD_PROJECT = "vertex-test-project";
|
|
61
|
+
process.env.GOOGLE_CLOUD_LOCATION = "global";
|
|
62
|
+
// Existence is checked by the extension; getClient is stubbed so no ADC file is parsed.
|
|
63
|
+
process.env.GOOGLE_APPLICATION_CREDENTIALS = fileURLToPath(import.meta.url);
|
|
64
|
+
GoogleAuth.prototype.getClient = async () => ({ getAccessToken: async () => ({ token: "test-token" }) });
|
|
65
|
+
const tool = { name: "probe", description: "Probe", parameters: { type: "object", properties: {} } };
|
|
66
|
+
const context = { messages: [
|
|
67
|
+
{ role: "system", content: "Use probe.", toolsAdded: [tool], timestamp: 0 },
|
|
68
|
+
{ role: "user", content: "Probe.", timestamp: 0 },
|
|
69
|
+
] };
|
|
70
|
+
const reasoningItem = { type: "reasoning", id: "rs_test", summary: [], encrypted_content: "test-ciphertext" };
|
|
71
|
+
const call = { type: "function_call", id: "fc_test", call_id: "call_test", name: "probe", arguments: "{}" };
|
|
72
|
+
let captured;
|
|
73
|
+
async function request(id, reasoning, ctx = context, onPayload) {
|
|
74
|
+
captured = undefined;
|
|
75
|
+
const result = await streamVertex(getModelById(id), ctx, {
|
|
76
|
+
reasoning, maxTokens: 1024, maxRetries: 0, onPayload,
|
|
77
|
+
fetch: async (url, init) => {
|
|
78
|
+
captured = { url: String(url), body: JSON.parse(init.body) };
|
|
79
|
+
const events = [reasoningItem, call].map((item, output_index) => ({ type: "response.output_item.done", output_index, item }));
|
|
80
|
+
events.push({ type: "response.completed", response: { id: "resp_test", status: "completed", output: [reasoningItem, call], usage: { input_tokens: 10, output_tokens: 5 } } });
|
|
81
|
+
return new Response(events.map(e => `data: ${JSON.stringify(e)}\n\n`).join(""), { headers: { "content-type": "text/event-stream" } });
|
|
82
|
+
},
|
|
83
|
+
}).result();
|
|
84
|
+
assert.equal(result.stopReason, "toolUse", result.errorMessage);
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
const first = await request("gpt-6.2-sol", "xhigh", context, payload => ({ ...payload, metadata: { hook: "preserved" } }));
|
|
89
|
+
assert.equal(first.stopReason, "toolUse", first.errorMessage);
|
|
90
|
+
assert.equal(captured.url, "https://aiplatform.googleapis.com/v1/projects/vertex-test-project/locations/global/publishers/openai/v1/responses");
|
|
91
|
+
assert.equal(captured.body.model, "gpt-6.2-sol");
|
|
92
|
+
assert.equal(captured.body.store, false);
|
|
93
|
+
assert.equal(captured.body.max_output_tokens, 1024);
|
|
94
|
+
assert.deepEqual(captured.body.reasoning, { effort: "xhigh" }, "no unsupported summary");
|
|
95
|
+
assert.deepEqual(captured.body.metadata, { hook: "preserved" });
|
|
96
|
+
assert(captured.body.include.includes("reasoning.encrypted_content"));
|
|
97
|
+
assert.equal(captured.body.tools[0].name, "probe");
|
|
98
|
+
assert.equal(captured.body.prompt_cache_retention, undefined);
|
|
99
|
+
const toolCall = first.content.find(b => b.type === "toolCall");
|
|
100
|
+
assert.equal(toolCall.name, "probe");
|
|
101
|
+
const replay = await request("gpt-6.2-sol", undefined, { messages: [...context.messages, first,
|
|
102
|
+
{ role: "toolResult", toolCallId: toolCall.id, toolName: "probe", content: [{ type: "text", text: "ok" }], timestamp: 0 },
|
|
103
|
+
] });
|
|
104
|
+
assert.equal(replay.stopReason, "toolUse", replay.errorMessage);
|
|
105
|
+
assert.equal(captured.body.reasoning, undefined, "Astra/Sol off uses model default, not rejected none");
|
|
106
|
+
assert(captured.body.include.includes("reasoning.encrypted_content"), "off still requests replay state");
|
|
107
|
+
assert(captured.body.input.some(i => i.type === "reasoning" && i.encrypted_content === "test-ciphertext"));
|
|
108
|
+
assert(captured.body.input.some(i => i.type === "function_call_output" && i.output === "ok"));
|
|
109
|
+
await request("gpt-6-luna", undefined);
|
|
110
|
+
assert.deepEqual(captured.body.reasoning, { effort: "none" }, "Luna off disables reasoning");
|
|
111
|
+
await request("gpt-6.1-terra", "max");
|
|
112
|
+
assert.deepEqual(captured.body.reasoning, { effort: "max" });
|
|
113
|
+
await request("muse-ember-1.0", "minimal");
|
|
114
|
+
assert(captured.url.endsWith("/publishers/meta/v1/responses"));
|
|
115
|
+
assert.deepEqual(captured.body.reasoning, { effort: "minimal", summary: "auto" }, "Muse is unchanged");
|
|
116
|
+
} finally {
|
|
117
|
+
GoogleAuth.prototype.getClient = getClient;
|
|
118
|
+
for (const key of Object.keys(process.env)) if (!(key in savedEnv)) delete process.env[key];
|
|
119
|
+
Object.assign(process.env, savedEnv);
|
|
120
|
+
rmSync(dir, { recursive: true, force: true });
|
|
121
|
+
}
|
|
122
|
+
console.log("PASS new model catalog and GPT Responses routing, effort, payload hook, and encrypted tool replay");
|
package/types.ts
CHANGED
|
@@ -22,13 +22,26 @@ export type {
|
|
|
22
22
|
ToolResultMessage,
|
|
23
23
|
Usage,
|
|
24
24
|
UserMessage,
|
|
25
|
-
} from "@
|
|
25
|
+
} from "@earendil-works/pi-ai";
|
|
26
|
+
|
|
27
|
+
import type { ThinkingLevel, ThinkingLevelMap } from "@earendil-works/pi-ai";
|
|
26
28
|
|
|
27
29
|
// Vertex-specific types
|
|
28
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Mirrors pi-ai's `Model["input"]`, which is `("text" | "image")[]`.
|
|
33
|
+
* Do not widen: pi-coding-agent rejects any other modality at registration.
|
|
34
|
+
*/
|
|
29
35
|
export type ModelInputType = "text" | "image";
|
|
30
36
|
export type EndpointType = "gemini" | "maas";
|
|
31
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Wire API for non-Anthropic MaaS models. Most use the OpenAI-compatible Chat
|
|
40
|
+
* Completions endpoint (`/endpoints/openapi`); Meta Muse and OpenAI GPT only
|
|
41
|
+
* serve the OpenAI-compatible Responses API (`/publishers/{publisher}/v1/responses`).
|
|
42
|
+
*/
|
|
43
|
+
export type MaasApi = "chat-completions" | "responses";
|
|
44
|
+
|
|
32
45
|
export interface ModelCost {
|
|
33
46
|
input: number;
|
|
34
47
|
output: number;
|
|
@@ -59,6 +72,13 @@ export interface VertexModelConfig {
|
|
|
59
72
|
*/
|
|
60
73
|
costRegional?: ModelCost;
|
|
61
74
|
region: string;
|
|
75
|
+
/**
|
|
76
|
+
* Pi thinking level → provider level. Passed to Pi so the selector offers only
|
|
77
|
+
* supported levels: `null` hides a level, and `xhigh`/`max` appear only when set.
|
|
78
|
+
*/
|
|
79
|
+
thinkingLevelMap?: ThinkingLevelMap;
|
|
80
|
+
/** Non-Anthropic MaaS wire API. Default: "chat-completions". */
|
|
81
|
+
maasApi?: MaasApi;
|
|
62
82
|
}
|
|
63
83
|
|
|
64
84
|
export interface AuthConfig {
|
|
@@ -70,6 +90,6 @@ export interface AuthConfig {
|
|
|
70
90
|
export interface StreamOptions {
|
|
71
91
|
maxTokens?: number;
|
|
72
92
|
temperature?: number;
|
|
73
|
-
reasoning?:
|
|
93
|
+
reasoning?: ThinkingLevel;
|
|
74
94
|
signal?: AbortSignal;
|
|
75
95
|
}
|
package/utils.ts
CHANGED
|
@@ -80,7 +80,9 @@ function supportsMultimodalFunctionResponse(modelId: string): boolean {
|
|
|
80
80
|
*/
|
|
81
81
|
export function convertToGeminiMessages(messages: Message[], modelId: string): GeminiContent[] {
|
|
82
82
|
const result: GeminiContent[] = [];
|
|
83
|
-
|
|
83
|
+
// Gemini 3 and 4 require thoughtSignature on all functionCall parts.
|
|
84
|
+
const requiresThoughtSignature =
|
|
85
|
+
modelId.startsWith("gemini-3") || modelId.startsWith("gemini-4");
|
|
84
86
|
let pendingToolCalls: ToolCall[] = [];
|
|
85
87
|
let existingToolResultIds = new Set<string>();
|
|
86
88
|
|
|
@@ -225,8 +227,8 @@ export function convertToGeminiMessages(messages: Message[], modelId: string): G
|
|
|
225
227
|
};
|
|
226
228
|
if (thoughtSig) {
|
|
227
229
|
part.thoughtSignature = thoughtSig;
|
|
228
|
-
} else if (
|
|
229
|
-
// Gemini 3
|
|
230
|
+
} else if (requiresThoughtSignature) {
|
|
231
|
+
// Gemini 3/4 require thoughtSignature on all functionCall parts.
|
|
230
232
|
// For cross-provider tool calls (or rare same-provider calls without signatures),
|
|
231
233
|
// use the documented escape hatch to bypass validation.
|
|
232
234
|
// See: https://docs.cloud.google.com/vertex-ai/generative-ai/docs/thought-signatures
|