pi2dsh 0.3.0 → 0.3.2
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/README.md +31 -11
- package/README.zh.md +31 -11
- package/dist/all-Rt4K68QA.mjs +28512 -0
- package/dist/all-Rt4K68QA.mjs.map +1 -0
- package/dist/anthropic-messages-Beym0_aC.mjs +6438 -0
- package/dist/anthropic-messages-Beym0_aC.mjs.map +1 -0
- package/dist/azure-openai-responses-cHqZTgLD.mjs +209 -0
- package/dist/azure-openai-responses-cHqZTgLD.mjs.map +1 -0
- package/dist/{build-DsGYAgiT.mjs → build-BG7p2Lbr.mjs} +2 -2
- package/dist/{build-DsGYAgiT.mjs.map → build-BG7p2Lbr.mjs.map} +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/compat/pi-ai.d.mts +25 -3
- package/dist/compat/pi-ai.d.mts.map +1 -1
- package/dist/compat/pi-ai.mjs +3 -2919
- package/dist/compat/pi-coding-agent.d.mts +12 -1
- package/dist/compat/pi-coding-agent.d.mts.map +1 -1
- package/dist/compat/pi-coding-agent.mjs +2 -2
- package/dist/credentials-oauth.d.mts +27 -0
- package/dist/credentials-oauth.d.mts.map +1 -0
- package/dist/credentials-oauth.mjs +91 -0
- package/dist/credentials-oauth.mjs.map +1 -0
- package/dist/deferred-tools-BD4g5QUx.mjs +32 -0
- package/dist/deferred-tools-BD4g5QUx.mjs.map +1 -0
- package/dist/diagnostics-CJye1UFh.mjs +99 -0
- package/dist/diagnostics-CJye1UFh.mjs.map +1 -0
- package/dist/dist-IQKOgQyt.mjs +10035 -0
- package/dist/dist-IQKOgQyt.mjs.map +1 -0
- package/dist/dist-QBBA-dL_.mjs +1246 -0
- package/dist/dist-QBBA-dL_.mjs.map +1 -0
- package/dist/error-body-DKA3lknR.mjs +104 -0
- package/dist/error-body-DKA3lknR.mjs.map +1 -0
- package/dist/github-copilot-headers-CZo2QHrt.mjs +25 -0
- package/dist/github-copilot-headers-CZo2QHrt.mjs.map +1 -0
- package/dist/google-generative-ai-B7OZs5lu.mjs +358 -0
- package/dist/google-generative-ai-B7OZs5lu.mjs.map +1 -0
- package/dist/google-shared-CRsAUItF.mjs +29042 -0
- package/dist/google-shared-CRsAUItF.mjs.map +1 -0
- package/dist/google-vertex-DmdaHQtB.mjs +402 -0
- package/dist/google-vertex-DmdaHQtB.mjs.map +1 -0
- package/dist/hash-Dbggamac.mjs +19 -0
- package/dist/hash-Dbggamac.mjs.map +1 -0
- package/dist/headers-CPzZhJQn.mjs +17 -0
- package/dist/headers-CPzZhJQn.mjs.map +1 -0
- package/dist/host.d.mts.map +1 -1
- package/dist/host.mjs +15 -3
- package/dist/host.mjs.map +1 -1
- package/dist/images-models-DJtHo9Rp.mjs +1068 -0
- package/dist/images-models-DJtHo9Rp.mjs.map +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/json-parse-CFyFZSLJ.mjs +384 -0
- package/dist/json-parse-CFyFZSLJ.mjs.map +1 -0
- package/dist/{mcp-config-gqg7GJEE.mjs → mcp-config-D2B3kv-Z.mjs} +34 -16
- package/dist/mcp-config-D2B3kv-Z.mjs.map +1 -0
- package/dist/mistral-conversations-HHZCcFv_.mjs +42007 -0
- package/dist/mistral-conversations-HHZCcFv_.mjs.map +1 -0
- package/dist/multipart-parser-CIa5BbwO.mjs +301 -0
- package/dist/multipart-parser-CIa5BbwO.mjs.map +1 -0
- package/dist/oauth-bridge-C6fL1qSv.mjs +375 -0
- package/dist/oauth-bridge-C6fL1qSv.mjs.map +1 -0
- package/dist/openai-DkzRh5_G.mjs +6732 -0
- package/dist/openai-DkzRh5_G.mjs.map +1 -0
- package/dist/openai-codex-responses-vmovNu-q.mjs +1169 -0
- package/dist/openai-codex-responses-vmovNu-q.mjs.map +1 -0
- package/dist/openai-completions-fXHhRolF.mjs +947 -0
- package/dist/openai-completions-fXHhRolF.mjs.map +1 -0
- package/dist/openai-prompt-cache-BDWtZRKh.mjs +11 -0
- package/dist/openai-prompt-cache-BDWtZRKh.mjs.map +1 -0
- package/dist/openai-responses-DKdCYf3h.mjs +247 -0
- package/dist/openai-responses-DKdCYf3h.mjs.map +1 -0
- package/dist/openai-responses-shared-D0Jq7yVP.mjs +572 -0
- package/dist/openai-responses-shared-D0Jq7yVP.mjs.map +1 -0
- package/dist/openrouter-images-fG3Aj6M4.mjs +127 -0
- package/dist/openrouter-images-fG3Aj6M4.mjs.map +1 -0
- package/dist/otel-BQSQRBLF.mjs +24935 -0
- package/dist/otel-BQSQRBLF.mjs.map +1 -0
- package/dist/pi-ai-DhYGgq4Y.mjs +2984 -0
- package/dist/pi-ai-DhYGgq4Y.mjs.map +1 -0
- package/dist/{pi-coding-agent-Z1hTs61i.mjs → pi-coding-agent-fPHwKP4d.mjs} +27 -3
- package/dist/{pi-coding-agent-Z1hTs61i.mjs.map → pi-coding-agent-fPHwKP4d.mjs.map} +1 -1
- package/dist/pi-messages-CV-Ts8An.mjs +306 -0
- package/dist/pi-messages-CV-Ts8An.mjs.map +1 -0
- package/dist/provider-env-C72pF4vP.mjs +40 -0
- package/dist/provider-env-C72pF4vP.mjs.map +1 -0
- package/dist/provider-retry-Cw6YJ4cr.mjs +80 -0
- package/dist/provider-retry-Cw6YJ4cr.mjs.map +1 -0
- package/dist/rolldown-runtime-CTfmNlz1.mjs +44 -0
- package/dist/{runtime-oLd2EInK.mjs → runtime-B9R7bDWT.mjs} +838 -345
- package/dist/runtime-B9R7bDWT.mjs.map +1 -0
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/sanitize-unicode-wLA11KvZ.mjs +29 -0
- package/dist/sanitize-unicode-wLA11KvZ.mjs.map +1 -0
- package/dist/src-C3WBfOks.mjs +5031 -0
- package/dist/src-C3WBfOks.mjs.map +1 -0
- package/dist/transform-messages-DGq9mvhA.mjs +379 -0
- package/dist/transform-messages-DGq9mvhA.mjs.map +1 -0
- package/dist/uuid-DtFT7tOE.mjs +65 -0
- package/dist/uuid-DtFT7tOE.mjs.map +1 -0
- package/package.json +11 -1
- package/dist/compat/pi-ai.mjs.map +0 -1
- package/dist/mcp-config-gqg7GJEE.mjs.map +0 -1
- package/dist/rolldown-runtime-D-uZhY3_.mjs +0 -16
- package/dist/runtime-oLd2EInK.mjs.map +0 -1
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
|
|
2
|
+
//#region node_modules/.pnpm/@earendil-works+pi-ai@0.84.1_ws@8.21.3_zod@4.4.3/node_modules/@earendil-works/pi-ai/dist/api/constrained-sampling.js
|
|
3
|
+
function getGrammarToolInput(toolName, arguments_, inputProperty) {
|
|
4
|
+
const input = arguments_[inputProperty];
|
|
5
|
+
if (typeof input !== "string") throw new Error(`Grammar tool call "${toolName}" requires argument "${inputProperty}" to be a string.`);
|
|
6
|
+
return input;
|
|
7
|
+
}
|
|
8
|
+
function appendGrammarToolInputJsonDelta(buffer, inputProperty, nextInput, close) {
|
|
9
|
+
if (buffer.closed) {
|
|
10
|
+
if (close && nextInput === buffer.input) return void 0;
|
|
11
|
+
throw new Error(`grammar tool input for property "${inputProperty}" changed after it was closed`);
|
|
12
|
+
}
|
|
13
|
+
if (!nextInput.startsWith(buffer.input)) throw new Error(`grammar tool input for property "${inputProperty}" changed non-monotonically`);
|
|
14
|
+
const inputDelta = nextInput.slice(buffer.input.length);
|
|
15
|
+
if (!close && inputDelta.length === 0) return void 0;
|
|
16
|
+
let delta = "";
|
|
17
|
+
if (!buffer.started) {
|
|
18
|
+
delta += `{${JSON.stringify(inputProperty)}:"`;
|
|
19
|
+
buffer.started = true;
|
|
20
|
+
}
|
|
21
|
+
delta += JSON.stringify(inputDelta).slice(1, -1);
|
|
22
|
+
buffer.input = nextInput;
|
|
23
|
+
if (close) {
|
|
24
|
+
delta += "\"}";
|
|
25
|
+
buffer.closed = true;
|
|
26
|
+
}
|
|
27
|
+
return delta;
|
|
28
|
+
}
|
|
29
|
+
function inferGrammarInputProperty(tool) {
|
|
30
|
+
const schema = tool.parameters;
|
|
31
|
+
if (schema.type !== "object") throw new Error("grammar constrained sampling requires an object parameter schema");
|
|
32
|
+
if (!Array.isArray(schema.required) || schema.required.length !== 1 || typeof schema.required[0] !== "string") throw new Error("grammar constrained sampling requires exactly one required string property");
|
|
33
|
+
const inputProperty = schema.required[0];
|
|
34
|
+
if (!schema.properties?.[inputProperty]) throw new Error(`grammar constrained sampling requires a properties entry for ${inputProperty}`);
|
|
35
|
+
if (schema.properties[inputProperty]?.type !== "string") throw new Error(`grammar constrained sampling property ${inputProperty} must have type string`);
|
|
36
|
+
return inputProperty;
|
|
37
|
+
}
|
|
38
|
+
function resolveJsonSchemaStrictSampling(tool, supportsStrictMode) {
|
|
39
|
+
const config = tool.constrainedSampling;
|
|
40
|
+
if (!config || config.type !== "json_schema") return;
|
|
41
|
+
if (supportsStrictMode) return true;
|
|
42
|
+
if (config.strict === "require") throw new Error(`Tool "${tool.name}" requires JSON-schema constrained sampling, but strict tools are unsupported.`);
|
|
43
|
+
}
|
|
44
|
+
function resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools) {
|
|
45
|
+
const config = tool.constrainedSampling;
|
|
46
|
+
if (!config || config.type !== "grammar") return;
|
|
47
|
+
if (!supportsOpenAIGrammarTools) return;
|
|
48
|
+
const larkDefinition = config.variants.openai_lark;
|
|
49
|
+
const regexDefinition = config.variants.openai_regex;
|
|
50
|
+
const hasLarkDefinition = typeof larkDefinition === "string" && larkDefinition.trim().length > 0;
|
|
51
|
+
const hasRegexDefinition = typeof regexDefinition === "string" && regexDefinition.trim().length > 0;
|
|
52
|
+
if (!hasLarkDefinition && !hasRegexDefinition) throw new Error(`Tool "${tool.name}" cannot use grammar constrained sampling: no supported grammar variant was provided.`);
|
|
53
|
+
try {
|
|
54
|
+
return {
|
|
55
|
+
format: hasLarkDefinition ? "lark" : "regex",
|
|
56
|
+
definition: hasLarkDefinition ? larkDefinition : regexDefinition,
|
|
57
|
+
inputProperty: inferGrammarInputProperty(tool)
|
|
58
|
+
};
|
|
59
|
+
} catch (error) {
|
|
60
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
61
|
+
throw new Error(`Tool "${tool.name}" cannot use grammar constrained sampling: ${message}.`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function createGrammarToolInputProperties(tools, supportsOpenAIGrammarTools) {
|
|
65
|
+
const properties = /* @__PURE__ */ new Map();
|
|
66
|
+
for (const tool of tools ?? []) {
|
|
67
|
+
const grammar = resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools);
|
|
68
|
+
if (grammar) properties.set(tool.name, grammar.inputProperty);
|
|
69
|
+
}
|
|
70
|
+
return properties;
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region node_modules/.pnpm/@earendil-works+pi-ai@0.84.1_ws@8.21.3_zod@4.4.3/node_modules/@earendil-works/pi-ai/dist/utils/estimate.js
|
|
74
|
+
const CHARS_PER_TOKEN = 4;
|
|
75
|
+
const ESTIMATED_IMAGE_CHARS = 4800;
|
|
76
|
+
function calculateContextTokens(usage) {
|
|
77
|
+
return usage.totalTokens || usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
|
|
78
|
+
}
|
|
79
|
+
function safeJsonStringify(value) {
|
|
80
|
+
try {
|
|
81
|
+
return JSON.stringify(value) ?? "undefined";
|
|
82
|
+
} catch {
|
|
83
|
+
return "[unserializable]";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function estimateTextAndImageContentChars(content) {
|
|
87
|
+
if (typeof content === "string") return content.length;
|
|
88
|
+
let chars = 0;
|
|
89
|
+
for (const block of content) chars += block.type === "text" ? block.text.length : ESTIMATED_IMAGE_CHARS;
|
|
90
|
+
return chars;
|
|
91
|
+
}
|
|
92
|
+
function estimateTextTokens(text) {
|
|
93
|
+
return Math.ceil(text.length / CHARS_PER_TOKEN);
|
|
94
|
+
}
|
|
95
|
+
function estimateTextAndImageContentTokens(content) {
|
|
96
|
+
return Math.ceil(estimateTextAndImageContentChars(content) / CHARS_PER_TOKEN);
|
|
97
|
+
}
|
|
98
|
+
function estimateMessageTokens(message) {
|
|
99
|
+
let chars = 0;
|
|
100
|
+
if (message.role === "user") return estimateTextAndImageContentTokens(message.content);
|
|
101
|
+
if (message.role === "toolResult") return estimateTextAndImageContentTokens(message.content);
|
|
102
|
+
for (const block of message.content) if (block.type === "text") chars += block.text.length;
|
|
103
|
+
else if (block.type === "thinking") chars += block.thinking.length;
|
|
104
|
+
else chars += block.name.length + safeJsonStringify(block.arguments).length;
|
|
105
|
+
return Math.ceil(chars / CHARS_PER_TOKEN);
|
|
106
|
+
}
|
|
107
|
+
function getLastAssistantUsageInfo(messages) {
|
|
108
|
+
let latestPrefixTimestamp = Number.NEGATIVE_INFINITY;
|
|
109
|
+
let usageInfo;
|
|
110
|
+
for (let i = 0; i < messages.length; i++) {
|
|
111
|
+
const message = messages[i];
|
|
112
|
+
if (message.role === "assistant") {
|
|
113
|
+
const assistant = message;
|
|
114
|
+
if (assistant.timestamp >= latestPrefixTimestamp && assistant.stopReason !== "aborted" && assistant.stopReason !== "error" && calculateContextTokens(assistant.usage) > 0) usageInfo = {
|
|
115
|
+
usage: assistant.usage,
|
|
116
|
+
index: i
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
latestPrefixTimestamp = Math.max(latestPrefixTimestamp, message.timestamp);
|
|
120
|
+
}
|
|
121
|
+
return usageInfo;
|
|
122
|
+
}
|
|
123
|
+
function estimateMessages(messages) {
|
|
124
|
+
const usageInfo = getLastAssistantUsageInfo(messages);
|
|
125
|
+
if (usageInfo) {
|
|
126
|
+
const usageTokens = calculateContextTokens(usageInfo.usage);
|
|
127
|
+
let trailingTokens = 0;
|
|
128
|
+
for (let i = usageInfo.index + 1; i < messages.length; i++) trailingTokens += estimateMessageTokens(messages[i]);
|
|
129
|
+
return {
|
|
130
|
+
tokens: usageTokens + trailingTokens,
|
|
131
|
+
usageTokens,
|
|
132
|
+
trailingTokens,
|
|
133
|
+
lastUsageIndex: usageInfo.index
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
let tokens = 0;
|
|
137
|
+
for (const message of messages) tokens += estimateMessageTokens(message);
|
|
138
|
+
return {
|
|
139
|
+
tokens,
|
|
140
|
+
usageTokens: 0,
|
|
141
|
+
trailingTokens: tokens,
|
|
142
|
+
lastUsageIndex: null
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function estimateToolsTokens(tools) {
|
|
146
|
+
if (!tools || tools.length === 0) return 0;
|
|
147
|
+
return estimateTextTokens(safeJsonStringify(tools));
|
|
148
|
+
}
|
|
149
|
+
function isMessageArray(value) {
|
|
150
|
+
return Array.isArray(value);
|
|
151
|
+
}
|
|
152
|
+
function estimateContextTokens(context) {
|
|
153
|
+
if (isMessageArray(context)) return estimateMessages(context);
|
|
154
|
+
const estimate = estimateMessages(context.messages);
|
|
155
|
+
if (estimate.lastUsageIndex !== null) {
|
|
156
|
+
const addedNames = new Set(context.messages.slice(estimate.lastUsageIndex + 1).filter((message) => message.role === "toolResult").flatMap((message) => message.addedToolNames ?? []));
|
|
157
|
+
const addedToolTokens = estimateToolsTokens(context.tools?.filter((tool) => addedNames.has(tool.name)));
|
|
158
|
+
return {
|
|
159
|
+
tokens: estimate.tokens + addedToolTokens,
|
|
160
|
+
usageTokens: estimate.usageTokens,
|
|
161
|
+
trailingTokens: estimate.trailingTokens + addedToolTokens,
|
|
162
|
+
lastUsageIndex: estimate.lastUsageIndex
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
const prefixTokens = (context.systemPrompt ? estimateTextTokens(context.systemPrompt) : 0) + estimateToolsTokens(context.tools);
|
|
166
|
+
return {
|
|
167
|
+
tokens: estimate.tokens + prefixTokens,
|
|
168
|
+
usageTokens: estimate.usageTokens,
|
|
169
|
+
trailingTokens: estimate.trailingTokens + prefixTokens,
|
|
170
|
+
lastUsageIndex: estimate.lastUsageIndex
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region node_modules/.pnpm/@earendil-works+pi-ai@0.84.1_ws@8.21.3_zod@4.4.3/node_modules/@earendil-works/pi-ai/dist/api/simple-options.js
|
|
175
|
+
const CONTEXT_SAFETY_TOKENS = 4096;
|
|
176
|
+
const MIN_MAX_TOKENS = 1;
|
|
177
|
+
function clampMaxTokensToContext(model, context, maxTokens) {
|
|
178
|
+
if (model.contextWindow <= 0) return Math.max(MIN_MAX_TOKENS, maxTokens);
|
|
179
|
+
const available = model.contextWindow - estimateContextTokens(context).tokens - CONTEXT_SAFETY_TOKENS;
|
|
180
|
+
return Math.min(maxTokens, Math.max(MIN_MAX_TOKENS, available));
|
|
181
|
+
}
|
|
182
|
+
function buildBaseOptions(model, context, options, apiKey) {
|
|
183
|
+
const samplingParams = model.samplingParams || options?.samplingParams ? {
|
|
184
|
+
...model.samplingParams,
|
|
185
|
+
...options?.samplingParams
|
|
186
|
+
} : void 0;
|
|
187
|
+
return {
|
|
188
|
+
temperature: options?.temperature,
|
|
189
|
+
samplingParams,
|
|
190
|
+
maxTokens: clampMaxTokensToContext(model, context, options?.maxTokens ?? model.maxTokens),
|
|
191
|
+
signal: options?.signal,
|
|
192
|
+
telemetryContext: options?.telemetryContext,
|
|
193
|
+
apiKey: apiKey || options?.apiKey,
|
|
194
|
+
fetch: options?.fetch,
|
|
195
|
+
transport: options?.transport,
|
|
196
|
+
cacheRetention: options?.cacheRetention,
|
|
197
|
+
sessionId: options?.sessionId,
|
|
198
|
+
headers: options?.headers,
|
|
199
|
+
onPayload: options?.onPayload,
|
|
200
|
+
onResponse: options?.onResponse,
|
|
201
|
+
timeoutMs: options?.timeoutMs,
|
|
202
|
+
websocketConnectTimeoutMs: options?.websocketConnectTimeoutMs,
|
|
203
|
+
maxRetries: options?.maxRetries,
|
|
204
|
+
maxRetryDelayMs: options?.maxRetryDelayMs,
|
|
205
|
+
metadata: options?.metadata,
|
|
206
|
+
env: options?.env
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/** Tokens always left for the answer when a thinking budget shares the response ceiling. */
|
|
210
|
+
const MIN_ANSWER_TOKENS = 1024;
|
|
211
|
+
function clampReasoning(effort) {
|
|
212
|
+
return effort === "xhigh" || effort === "max" ? "high" : effort;
|
|
213
|
+
}
|
|
214
|
+
function adjustMaxTokensForThinking(baseMaxTokens, modelMaxTokens, reasoningLevel, customBudgets) {
|
|
215
|
+
let thinkingBudget = {
|
|
216
|
+
minimal: 1024,
|
|
217
|
+
low: 2048,
|
|
218
|
+
medium: 8192,
|
|
219
|
+
high: 16384,
|
|
220
|
+
...customBudgets
|
|
221
|
+
}[clampReasoning(reasoningLevel)];
|
|
222
|
+
const maxTokens = baseMaxTokens === void 0 ? modelMaxTokens : Math.min(baseMaxTokens + thinkingBudget, modelMaxTokens);
|
|
223
|
+
if (maxTokens <= thinkingBudget) thinkingBudget = Math.max(0, maxTokens - MIN_ANSWER_TOKENS);
|
|
224
|
+
return {
|
|
225
|
+
maxTokens,
|
|
226
|
+
thinkingBudget
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
//#endregion
|
|
230
|
+
//#region node_modules/.pnpm/@earendil-works+pi-ai@0.84.1_ws@8.21.3_zod@4.4.3/node_modules/@earendil-works/pi-ai/dist/api/transform-messages.js
|
|
231
|
+
const NON_VISION_USER_IMAGE_PLACEHOLDER = "(image omitted: model does not support images)";
|
|
232
|
+
const NON_VISION_TOOL_IMAGE_PLACEHOLDER = "(tool image omitted: model does not support images)";
|
|
233
|
+
function replaceImagesWithPlaceholder(content, placeholder) {
|
|
234
|
+
const result = [];
|
|
235
|
+
let previousWasPlaceholder = false;
|
|
236
|
+
for (const block of content) {
|
|
237
|
+
if (block.type === "image") {
|
|
238
|
+
if (!previousWasPlaceholder) result.push({
|
|
239
|
+
type: "text",
|
|
240
|
+
text: placeholder
|
|
241
|
+
});
|
|
242
|
+
previousWasPlaceholder = true;
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
result.push(block);
|
|
246
|
+
previousWasPlaceholder = block.text === placeholder;
|
|
247
|
+
}
|
|
248
|
+
return result;
|
|
249
|
+
}
|
|
250
|
+
function downgradeUnsupportedImages(messages, model) {
|
|
251
|
+
if (model.input.includes("image")) return messages;
|
|
252
|
+
return messages.map((msg) => {
|
|
253
|
+
if (msg.role === "user" && Array.isArray(msg.content)) return {
|
|
254
|
+
...msg,
|
|
255
|
+
content: replaceImagesWithPlaceholder(msg.content, NON_VISION_USER_IMAGE_PLACEHOLDER)
|
|
256
|
+
};
|
|
257
|
+
if (msg.role === "toolResult") return {
|
|
258
|
+
...msg,
|
|
259
|
+
content: replaceImagesWithPlaceholder(msg.content, NON_VISION_TOOL_IMAGE_PLACEHOLDER)
|
|
260
|
+
};
|
|
261
|
+
return msg;
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Normalize tool call ID for cross-provider compatibility.
|
|
266
|
+
* OpenAI Responses API generates IDs that are 450+ chars with special characters like `|`.
|
|
267
|
+
* Anthropic APIs require IDs matching ^[a-zA-Z0-9_-]+$ (max 64 chars).
|
|
268
|
+
*/
|
|
269
|
+
function transformMessages(messages, model, normalizeToolCallId) {
|
|
270
|
+
const toolCallIdMap = /* @__PURE__ */ new Map();
|
|
271
|
+
const transformed = downgradeUnsupportedImages(messages.map((msg) => msg.content == null ? {
|
|
272
|
+
...msg,
|
|
273
|
+
content: []
|
|
274
|
+
} : msg), model).map((msg) => {
|
|
275
|
+
if (msg.role === "user") return msg;
|
|
276
|
+
if (msg.role === "toolResult") {
|
|
277
|
+
const normalizedId = toolCallIdMap.get(msg.toolCallId);
|
|
278
|
+
if (normalizedId && normalizedId !== msg.toolCallId) return {
|
|
279
|
+
...msg,
|
|
280
|
+
toolCallId: normalizedId
|
|
281
|
+
};
|
|
282
|
+
return msg;
|
|
283
|
+
}
|
|
284
|
+
if (msg.role === "assistant") {
|
|
285
|
+
const assistantMsg = msg;
|
|
286
|
+
const isSameModel = assistantMsg.provider === model.provider && assistantMsg.api === model.api && assistantMsg.model === model.id;
|
|
287
|
+
const transformedContent = assistantMsg.content.flatMap((block) => {
|
|
288
|
+
if (block.type === "thinking") {
|
|
289
|
+
if (block.redacted) return isSameModel ? block : [];
|
|
290
|
+
if (isSameModel && block.thinkingSignature) return block;
|
|
291
|
+
if (!block.thinking || block.thinking.trim() === "") return [];
|
|
292
|
+
if (isSameModel) return block;
|
|
293
|
+
return {
|
|
294
|
+
type: "text",
|
|
295
|
+
text: block.thinking
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
if (block.type === "text") {
|
|
299
|
+
if (isSameModel) return block;
|
|
300
|
+
return {
|
|
301
|
+
type: "text",
|
|
302
|
+
text: block.text
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
if (block.type === "toolCall") {
|
|
306
|
+
const toolCall = block;
|
|
307
|
+
let normalizedToolCall = toolCall;
|
|
308
|
+
if (!isSameModel && toolCall.thoughtSignature) {
|
|
309
|
+
normalizedToolCall = { ...toolCall };
|
|
310
|
+
delete normalizedToolCall.thoughtSignature;
|
|
311
|
+
}
|
|
312
|
+
if (!isSameModel && normalizeToolCallId) {
|
|
313
|
+
const normalizedId = normalizeToolCallId(toolCall.id, model, assistantMsg);
|
|
314
|
+
if (normalizedId !== toolCall.id) {
|
|
315
|
+
toolCallIdMap.set(toolCall.id, normalizedId);
|
|
316
|
+
normalizedToolCall = {
|
|
317
|
+
...normalizedToolCall,
|
|
318
|
+
id: normalizedId
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return normalizedToolCall;
|
|
323
|
+
}
|
|
324
|
+
return block;
|
|
325
|
+
});
|
|
326
|
+
return {
|
|
327
|
+
...assistantMsg,
|
|
328
|
+
content: transformedContent
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
return msg;
|
|
332
|
+
});
|
|
333
|
+
const result = [];
|
|
334
|
+
let pendingToolCalls = [];
|
|
335
|
+
let existingToolResultIds = /* @__PURE__ */ new Set();
|
|
336
|
+
const insertSyntheticToolResults = () => {
|
|
337
|
+
if (pendingToolCalls.length > 0) {
|
|
338
|
+
for (const tc of pendingToolCalls) if (!existingToolResultIds.has(tc.id)) result.push({
|
|
339
|
+
role: "toolResult",
|
|
340
|
+
toolCallId: tc.id,
|
|
341
|
+
toolName: tc.name,
|
|
342
|
+
content: [{
|
|
343
|
+
type: "text",
|
|
344
|
+
text: "No result provided"
|
|
345
|
+
}],
|
|
346
|
+
isError: true,
|
|
347
|
+
timestamp: Date.now()
|
|
348
|
+
});
|
|
349
|
+
pendingToolCalls = [];
|
|
350
|
+
existingToolResultIds = /* @__PURE__ */ new Set();
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
for (let i = 0; i < transformed.length; i++) {
|
|
354
|
+
const msg = transformed[i];
|
|
355
|
+
if (msg.role === "assistant") {
|
|
356
|
+
insertSyntheticToolResults();
|
|
357
|
+
const assistantMsg = msg;
|
|
358
|
+
if (assistantMsg.stopReason === "error" || assistantMsg.stopReason === "aborted") continue;
|
|
359
|
+
const toolCalls = assistantMsg.content.filter((b) => b.type === "toolCall");
|
|
360
|
+
if (toolCalls.length > 0) {
|
|
361
|
+
pendingToolCalls = toolCalls;
|
|
362
|
+
existingToolResultIds = /* @__PURE__ */ new Set();
|
|
363
|
+
}
|
|
364
|
+
result.push(msg);
|
|
365
|
+
} else if (msg.role === "toolResult") {
|
|
366
|
+
existingToolResultIds.add(msg.toolCallId);
|
|
367
|
+
result.push(msg);
|
|
368
|
+
} else if (msg.role === "user") {
|
|
369
|
+
insertSyntheticToolResults();
|
|
370
|
+
result.push(msg);
|
|
371
|
+
} else result.push(msg);
|
|
372
|
+
}
|
|
373
|
+
insertSyntheticToolResults();
|
|
374
|
+
return result;
|
|
375
|
+
}
|
|
376
|
+
//#endregion
|
|
377
|
+
export { clampMaxTokensToContext as a, createGrammarToolInputProperties as c, resolveJsonSchemaStrictSampling as d, buildBaseOptions as i, getGrammarToolInput as l, MIN_ANSWER_TOKENS as n, clampReasoning as o, adjustMaxTokensForThinking as r, appendGrammarToolInputJsonDelta as s, transformMessages as t, resolveGrammarConstrainedSampling as u };
|
|
378
|
+
|
|
379
|
+
//# sourceMappingURL=transform-messages-DGq9mvhA.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform-messages-DGq9mvhA.mjs","names":[],"sources":["../node_modules/.pnpm/@earendil-works+pi-ai@0.84.1_ws@8.21.3_zod@4.4.3/node_modules/@earendil-works/pi-ai/dist/api/constrained-sampling.js","../node_modules/.pnpm/@earendil-works+pi-ai@0.84.1_ws@8.21.3_zod@4.4.3/node_modules/@earendil-works/pi-ai/dist/utils/estimate.js","../node_modules/.pnpm/@earendil-works+pi-ai@0.84.1_ws@8.21.3_zod@4.4.3/node_modules/@earendil-works/pi-ai/dist/api/simple-options.js","../node_modules/.pnpm/@earendil-works+pi-ai@0.84.1_ws@8.21.3_zod@4.4.3/node_modules/@earendil-works/pi-ai/dist/api/transform-messages.js"],"sourcesContent":["export function getGrammarToolInput(toolName, arguments_, inputProperty) {\n const input = arguments_[inputProperty];\n if (typeof input !== \"string\") {\n throw new Error(`Grammar tool call \"${toolName}\" requires argument \"${inputProperty}\" to be a string.`);\n }\n return input;\n}\nexport function appendGrammarToolInputJsonDelta(buffer, inputProperty, nextInput, close) {\n if (buffer.closed) {\n if (close && nextInput === buffer.input)\n return undefined;\n throw new Error(`grammar tool input for property \"${inputProperty}\" changed after it was closed`);\n }\n if (!nextInput.startsWith(buffer.input)) {\n throw new Error(`grammar tool input for property \"${inputProperty}\" changed non-monotonically`);\n }\n const inputDelta = nextInput.slice(buffer.input.length);\n if (!close && inputDelta.length === 0)\n return undefined;\n let delta = \"\";\n if (!buffer.started) {\n delta += `{${JSON.stringify(inputProperty)}:\"`;\n buffer.started = true;\n }\n delta += JSON.stringify(inputDelta).slice(1, -1);\n buffer.input = nextInput;\n if (close) {\n delta += '\"}';\n buffer.closed = true;\n }\n return delta;\n}\nfunction inferGrammarInputProperty(tool) {\n const schema = tool.parameters;\n if (schema.type !== \"object\") {\n throw new Error(\"grammar constrained sampling requires an object parameter schema\");\n }\n if (!Array.isArray(schema.required) || schema.required.length !== 1 || typeof schema.required[0] !== \"string\") {\n throw new Error(\"grammar constrained sampling requires exactly one required string property\");\n }\n const inputProperty = schema.required[0];\n if (!schema.properties?.[inputProperty]) {\n throw new Error(`grammar constrained sampling requires a properties entry for ${inputProperty}`);\n }\n if (schema.properties[inputProperty]?.type !== \"string\") {\n throw new Error(`grammar constrained sampling property ${inputProperty} must have type string`);\n }\n return inputProperty;\n}\nexport function resolveJsonSchemaStrictSampling(tool, supportsStrictMode) {\n const config = tool.constrainedSampling;\n if (!config || config.type !== \"json_schema\") {\n return undefined;\n }\n if (supportsStrictMode) {\n return true;\n }\n if (config.strict === \"require\") {\n throw new Error(`Tool \"${tool.name}\" requires JSON-schema constrained sampling, but strict tools are unsupported.`);\n }\n return undefined;\n}\nexport function resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools) {\n const config = tool.constrainedSampling;\n if (!config || config.type !== \"grammar\") {\n return undefined;\n }\n if (!supportsOpenAIGrammarTools) {\n return undefined;\n }\n const larkDefinition = config.variants.openai_lark;\n const regexDefinition = config.variants.openai_regex;\n const hasLarkDefinition = typeof larkDefinition === \"string\" && larkDefinition.trim().length > 0;\n const hasRegexDefinition = typeof regexDefinition === \"string\" && regexDefinition.trim().length > 0;\n if (!hasLarkDefinition && !hasRegexDefinition) {\n throw new Error(`Tool \"${tool.name}\" cannot use grammar constrained sampling: no supported grammar variant was provided.`);\n }\n try {\n return {\n format: hasLarkDefinition ? \"lark\" : \"regex\",\n definition: hasLarkDefinition ? larkDefinition : regexDefinition,\n inputProperty: inferGrammarInputProperty(tool),\n };\n }\n catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n throw new Error(`Tool \"${tool.name}\" cannot use grammar constrained sampling: ${message}.`);\n }\n}\nexport function createGrammarToolInputProperties(tools, supportsOpenAIGrammarTools) {\n const properties = new Map();\n for (const tool of tools ?? []) {\n const grammar = resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools);\n if (grammar) {\n properties.set(tool.name, grammar.inputProperty);\n }\n }\n return properties;\n}\n//# sourceMappingURL=constrained-sampling.js.map","const CHARS_PER_TOKEN = 4;\nconst ESTIMATED_IMAGE_CHARS = 4800;\nexport function calculateContextTokens(usage) {\n return usage.totalTokens || usage.input + usage.output + usage.cacheRead + usage.cacheWrite;\n}\nfunction safeJsonStringify(value) {\n try {\n return JSON.stringify(value) ?? \"undefined\";\n }\n catch {\n return \"[unserializable]\";\n }\n}\nfunction estimateTextAndImageContentChars(content) {\n if (typeof content === \"string\")\n return content.length;\n let chars = 0;\n for (const block of content)\n chars += block.type === \"text\" ? block.text.length : ESTIMATED_IMAGE_CHARS;\n return chars;\n}\nexport function estimateTextTokens(text) {\n return Math.ceil(text.length / CHARS_PER_TOKEN);\n}\nexport function estimateTextAndImageContentTokens(content) {\n return Math.ceil(estimateTextAndImageContentChars(content) / CHARS_PER_TOKEN);\n}\nexport function estimateMessageTokens(message) {\n let chars = 0;\n if (message.role === \"user\")\n return estimateTextAndImageContentTokens(message.content);\n if (message.role === \"toolResult\")\n return estimateTextAndImageContentTokens(message.content);\n for (const block of message.content) {\n if (block.type === \"text\") {\n chars += block.text.length;\n }\n else if (block.type === \"thinking\") {\n chars += block.thinking.length;\n }\n else {\n chars += block.name.length + safeJsonStringify(block.arguments).length;\n }\n }\n return Math.ceil(chars / CHARS_PER_TOKEN);\n}\nfunction getLastAssistantUsageInfo(messages) {\n let latestPrefixTimestamp = Number.NEGATIVE_INFINITY;\n let usageInfo;\n for (let i = 0; i < messages.length; i++) {\n const message = messages[i];\n if (message.role === \"assistant\") {\n const assistant = message;\n // A newer prefix message was inserted after this response (for example, a\n // compaction summary), so its usage cannot describe the current prefix.\n const usageAppliesToPrefix = assistant.timestamp >= latestPrefixTimestamp;\n if (usageAppliesToPrefix &&\n assistant.stopReason !== \"aborted\" &&\n assistant.stopReason !== \"error\" &&\n calculateContextTokens(assistant.usage) > 0) {\n usageInfo = { usage: assistant.usage, index: i };\n }\n }\n latestPrefixTimestamp = Math.max(latestPrefixTimestamp, message.timestamp);\n }\n return usageInfo;\n}\nfunction estimateMessages(messages) {\n const usageInfo = getLastAssistantUsageInfo(messages);\n if (usageInfo) {\n const usageTokens = calculateContextTokens(usageInfo.usage);\n let trailingTokens = 0;\n for (let i = usageInfo.index + 1; i < messages.length; i++) {\n trailingTokens += estimateMessageTokens(messages[i]);\n }\n return { tokens: usageTokens + trailingTokens, usageTokens, trailingTokens, lastUsageIndex: usageInfo.index };\n }\n let tokens = 0;\n for (const message of messages)\n tokens += estimateMessageTokens(message);\n return { tokens, usageTokens: 0, trailingTokens: tokens, lastUsageIndex: null };\n}\nfunction estimateToolsTokens(tools) {\n if (!tools || tools.length === 0)\n return 0;\n return estimateTextTokens(safeJsonStringify(tools));\n}\nfunction isMessageArray(value) {\n return Array.isArray(value);\n}\nexport function estimateContextTokens(context) {\n if (isMessageArray(context))\n return estimateMessages(context);\n const estimate = estimateMessages(context.messages);\n if (estimate.lastUsageIndex !== null) {\n const addedNames = new Set(context.messages\n .slice(estimate.lastUsageIndex + 1)\n .filter((message) => message.role === \"toolResult\")\n .flatMap((message) => message.addedToolNames ?? []));\n const addedToolTokens = estimateToolsTokens(context.tools?.filter((tool) => addedNames.has(tool.name)));\n return {\n tokens: estimate.tokens + addedToolTokens,\n usageTokens: estimate.usageTokens,\n trailingTokens: estimate.trailingTokens + addedToolTokens,\n lastUsageIndex: estimate.lastUsageIndex,\n };\n }\n const prefixTokens = (context.systemPrompt ? estimateTextTokens(context.systemPrompt) : 0) + estimateToolsTokens(context.tools);\n return {\n tokens: estimate.tokens + prefixTokens,\n usageTokens: estimate.usageTokens,\n trailingTokens: estimate.trailingTokens + prefixTokens,\n lastUsageIndex: estimate.lastUsageIndex,\n };\n}\n//# sourceMappingURL=estimate.js.map","import { estimateContextTokens } from \"../utils/estimate.js\";\nconst CONTEXT_SAFETY_TOKENS = 4096;\nconst MIN_MAX_TOKENS = 1;\nexport function clampMaxTokensToContext(model, context, maxTokens) {\n if (model.contextWindow <= 0)\n return Math.max(MIN_MAX_TOKENS, maxTokens);\n const available = model.contextWindow - estimateContextTokens(context).tokens - CONTEXT_SAFETY_TOKENS;\n return Math.min(maxTokens, Math.max(MIN_MAX_TOKENS, available));\n}\nexport function buildBaseOptions(model, context, options, apiKey) {\n const samplingParams = model.samplingParams || options?.samplingParams\n ? { ...model.samplingParams, ...options?.samplingParams }\n : undefined;\n return {\n temperature: options?.temperature,\n samplingParams,\n maxTokens: clampMaxTokensToContext(model, context, options?.maxTokens ?? model.maxTokens),\n signal: options?.signal,\n telemetryContext: options?.telemetryContext,\n apiKey: apiKey || options?.apiKey,\n fetch: options?.fetch,\n transport: options?.transport,\n cacheRetention: options?.cacheRetention,\n sessionId: options?.sessionId,\n headers: options?.headers,\n onPayload: options?.onPayload,\n onResponse: options?.onResponse,\n timeoutMs: options?.timeoutMs,\n websocketConnectTimeoutMs: options?.websocketConnectTimeoutMs,\n maxRetries: options?.maxRetries,\n maxRetryDelayMs: options?.maxRetryDelayMs,\n metadata: options?.metadata,\n env: options?.env,\n };\n}\n/** Tokens always left for the answer when a thinking budget shares the response ceiling. */\nexport const MIN_ANSWER_TOKENS = 1024;\nexport function clampReasoning(effort) {\n return effort === \"xhigh\" || effort === \"max\" ? \"high\" : effort;\n}\nexport function adjustMaxTokensForThinking(\n// Undefined means no explicit caller cap. Use the model cap and fit thinking inside it.\nbaseMaxTokens, modelMaxTokens, reasoningLevel, customBudgets) {\n const defaultBudgets = {\n minimal: 1024,\n low: 2048,\n medium: 8192,\n high: 16384,\n };\n const budgets = { ...defaultBudgets, ...customBudgets };\n const level = clampReasoning(reasoningLevel);\n let thinkingBudget = budgets[level];\n const maxTokens = baseMaxTokens === undefined ? modelMaxTokens : Math.min(baseMaxTokens + thinkingBudget, modelMaxTokens);\n if (maxTokens <= thinkingBudget) {\n thinkingBudget = Math.max(0, maxTokens - MIN_ANSWER_TOKENS);\n }\n return { maxTokens, thinkingBudget };\n}\n//# sourceMappingURL=simple-options.js.map","const NON_VISION_USER_IMAGE_PLACEHOLDER = \"(image omitted: model does not support images)\";\nconst NON_VISION_TOOL_IMAGE_PLACEHOLDER = \"(tool image omitted: model does not support images)\";\nfunction replaceImagesWithPlaceholder(content, placeholder) {\n const result = [];\n let previousWasPlaceholder = false;\n for (const block of content) {\n if (block.type === \"image\") {\n if (!previousWasPlaceholder) {\n result.push({ type: \"text\", text: placeholder });\n }\n previousWasPlaceholder = true;\n continue;\n }\n result.push(block);\n previousWasPlaceholder = block.text === placeholder;\n }\n return result;\n}\nfunction downgradeUnsupportedImages(messages, model) {\n if (model.input.includes(\"image\")) {\n return messages;\n }\n return messages.map((msg) => {\n if (msg.role === \"user\" && Array.isArray(msg.content)) {\n return {\n ...msg,\n content: replaceImagesWithPlaceholder(msg.content, NON_VISION_USER_IMAGE_PLACEHOLDER),\n };\n }\n if (msg.role === \"toolResult\") {\n return {\n ...msg,\n content: replaceImagesWithPlaceholder(msg.content, NON_VISION_TOOL_IMAGE_PLACEHOLDER),\n };\n }\n return msg;\n });\n}\n/**\n * Normalize tool call ID for cross-provider compatibility.\n * OpenAI Responses API generates IDs that are 450+ chars with special characters like `|`.\n * Anthropic APIs require IDs matching ^[a-zA-Z0-9_-]+$ (max 64 chars).\n */\nexport function transformMessages(messages, model, normalizeToolCallId) {\n // Build a map of original tool call IDs to normalized IDs\n const toolCallIdMap = new Map();\n // Normalize null/undefined content from untyped callers (custom tools, hand-built\n // histories, old session files) so downstream code can rely on the type contract.\n const normalizedMessages = messages.map((msg) => (msg.content == null ? { ...msg, content: [] } : msg));\n const imageAwareMessages = downgradeUnsupportedImages(normalizedMessages, model);\n // First pass: transform messages (unsupported image downgrade, thinking blocks, tool call ID normalization)\n const transformed = imageAwareMessages.map((msg) => {\n // User messages pass through unchanged\n if (msg.role === \"user\") {\n return msg;\n }\n // Handle toolResult messages - normalize toolCallId if we have a mapping\n if (msg.role === \"toolResult\") {\n const normalizedId = toolCallIdMap.get(msg.toolCallId);\n if (normalizedId && normalizedId !== msg.toolCallId) {\n return { ...msg, toolCallId: normalizedId };\n }\n return msg;\n }\n // Assistant messages need transformation check\n if (msg.role === \"assistant\") {\n const assistantMsg = msg;\n const isSameModel = assistantMsg.provider === model.provider &&\n assistantMsg.api === model.api &&\n assistantMsg.model === model.id;\n const transformedContent = assistantMsg.content.flatMap((block) => {\n if (block.type === \"thinking\") {\n // Redacted thinking is opaque encrypted content, only valid for the same model.\n // Drop it for cross-model to avoid API errors.\n if (block.redacted) {\n return isSameModel ? block : [];\n }\n // For same model: keep thinking blocks with signatures (needed for replay)\n // even if the thinking text is empty (OpenAI encrypted reasoning)\n if (isSameModel && block.thinkingSignature)\n return block;\n // Skip empty thinking blocks, convert others to plain text\n if (!block.thinking || block.thinking.trim() === \"\")\n return [];\n if (isSameModel)\n return block;\n return {\n type: \"text\",\n text: block.thinking,\n };\n }\n if (block.type === \"text\") {\n if (isSameModel)\n return block;\n return {\n type: \"text\",\n text: block.text,\n };\n }\n if (block.type === \"toolCall\") {\n const toolCall = block;\n let normalizedToolCall = toolCall;\n if (!isSameModel && toolCall.thoughtSignature) {\n normalizedToolCall = { ...toolCall };\n delete normalizedToolCall.thoughtSignature;\n }\n if (!isSameModel && normalizeToolCallId) {\n const normalizedId = normalizeToolCallId(toolCall.id, model, assistantMsg);\n if (normalizedId !== toolCall.id) {\n toolCallIdMap.set(toolCall.id, normalizedId);\n normalizedToolCall = { ...normalizedToolCall, id: normalizedId };\n }\n }\n return normalizedToolCall;\n }\n return block;\n });\n return {\n ...assistantMsg,\n content: transformedContent,\n };\n }\n return msg;\n });\n // Second pass: insert synthetic empty tool results for orphaned tool calls\n // This preserves thinking signatures and satisfies API requirements\n const result = [];\n let pendingToolCalls = [];\n let existingToolResultIds = new Set();\n const insertSyntheticToolResults = () => {\n if (pendingToolCalls.length > 0) {\n for (const tc of pendingToolCalls) {\n if (!existingToolResultIds.has(tc.id)) {\n result.push({\n role: \"toolResult\",\n toolCallId: tc.id,\n toolName: tc.name,\n content: [{ type: \"text\", text: \"No result provided\" }],\n isError: true,\n timestamp: Date.now(),\n });\n }\n }\n pendingToolCalls = [];\n existingToolResultIds = new Set();\n }\n };\n for (let i = 0; i < transformed.length; i++) {\n const msg = transformed[i];\n if (msg.role === \"assistant\") {\n // If we have pending orphaned tool calls from a previous assistant, insert synthetic results now\n insertSyntheticToolResults();\n // Skip errored/aborted assistant messages entirely.\n // These are incomplete turns that shouldn't be replayed:\n // - May have partial content (reasoning without message, incomplete tool calls)\n // - Replaying them can cause API errors (e.g., OpenAI \"reasoning without following item\")\n // - The model should retry from the last valid state\n const assistantMsg = msg;\n if (assistantMsg.stopReason === \"error\" || assistantMsg.stopReason === \"aborted\") {\n continue;\n }\n // Track tool calls from this assistant message\n const toolCalls = assistantMsg.content.filter((b) => b.type === \"toolCall\");\n if (toolCalls.length > 0) {\n pendingToolCalls = toolCalls;\n existingToolResultIds = new Set();\n }\n result.push(msg);\n }\n else if (msg.role === \"toolResult\") {\n existingToolResultIds.add(msg.toolCallId);\n result.push(msg);\n }\n else if (msg.role === \"user\") {\n // User message interrupts tool flow - insert synthetic results for orphaned calls\n insertSyntheticToolResults();\n result.push(msg);\n }\n else {\n result.push(msg);\n }\n }\n // If the conversation ends with unresolved tool calls, synthesize results now.\n insertSyntheticToolResults();\n return result;\n}\n//# sourceMappingURL=transform-messages.js.map"],"x_google_ignoreList":[0,1,2,3],"mappings":";;AAAA,SAAgB,oBAAoB,UAAU,YAAY,eAAe;CACrE,MAAM,QAAQ,WAAW;CACzB,IAAI,OAAO,UAAU,UACjB,MAAM,IAAI,MAAM,sBAAsB,SAAS,uBAAuB,cAAc,kBAAkB;CAE1G,OAAO;AACX;AACA,SAAgB,gCAAgC,QAAQ,eAAe,WAAW,OAAO;CACrF,IAAI,OAAO,QAAQ;EACf,IAAI,SAAS,cAA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,GAAG;IACb,SAAS,CAAC;KAAE,MAAM;KAAQ,MAAM;IAAqB,CAAC;IACtD,SAAS;IACT,WAAW,KAAK,IAAI;GACxB,CAAC;GAGT,mBAAmB,CAAC;GACpB,wCAAwB,IAAI,IAAI;EACpC;CACJ;CACA,KAAK,IAAI,IAAI,GAAG,IAAI,YAAY,QAAQ,KAAK;EACzC,MAAM,MAAM,YAAY;EACxB,IAAI,IAAI,SAAS,aAAa;GAE1B,2BAA2B;GAM3B,MAAM,eAAe;GACrB,IAAI,aAAa,eAAe,WAAW,aAAa,eAAe,WACnE;GAGJ,MAAM,YAAY,aAAa,QAAQ,QAAQ,MAAM,EAAE,SAAS,UAAU;GAC1E,IAAI,UAAU,SAAS,GAAG;IACtB,mBAAmB;IACnB,wCAAwB,IAAI,IAAI;GACpC;GACA,OAAO,KAAK,GAAG;EACnB,OACK,IAAI,IAAI,SAAS,cAAc;GAChC,sBAAsB,IAAI,IAAI,UAAU;GACxC,OAAO,KAAK,GAAG;EACnB,OACK,IAAI,IAAI,SAAS,QAAQ;GAE1B,2BAA2B;GAC3B,OAAO,KAAK,GAAG;EACnB,OAEI,OAAO,KAAK,GAAG;CAEvB;CAEA,2BAA2B;CAC3B,OAAO;AACX"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
|
|
2
|
+
//#region node_modules/.pnpm/@earendil-works+pi-ai@0.84.1_ws@8.21.3_zod@4.4.3/node_modules/@earendil-works/pi-ai/dist/session-resources.js
|
|
3
|
+
const sessionResourceCleanups = /* @__PURE__ */ new Set();
|
|
4
|
+
function registerSessionResourceCleanup(cleanup) {
|
|
5
|
+
sessionResourceCleanups.add(cleanup);
|
|
6
|
+
return () => {
|
|
7
|
+
sessionResourceCleanups.delete(cleanup);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function cleanupSessionResources(sessionId) {
|
|
11
|
+
const errors = [];
|
|
12
|
+
for (const cleanup of sessionResourceCleanups) try {
|
|
13
|
+
cleanup(sessionId);
|
|
14
|
+
} catch (error) {
|
|
15
|
+
errors.push(error);
|
|
16
|
+
}
|
|
17
|
+
if (errors.length > 0) throw new AggregateError(errors, "Failed to cleanup session resources");
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region node_modules/.pnpm/@earendil-works+pi-ai@0.84.1_ws@8.21.3_zod@4.4.3/node_modules/@earendil-works/pi-ai/dist/utils/uuid.js
|
|
21
|
+
let lastTimestamp = -Infinity;
|
|
22
|
+
let sequence = 0;
|
|
23
|
+
function fillRandomBytes(bytes) {
|
|
24
|
+
if (globalThis.crypto?.getRandomValues) {
|
|
25
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
for (let i = 0; i < bytes.length; i++) bytes[i] = Math.floor(Math.random() * 256);
|
|
29
|
+
}
|
|
30
|
+
/** Generate a time-ordered UUIDv7. */
|
|
31
|
+
function uuidv7() {
|
|
32
|
+
const random = /* @__PURE__ */ new Uint8Array(16);
|
|
33
|
+
fillRandomBytes(random);
|
|
34
|
+
const timestamp = Date.now();
|
|
35
|
+
if (timestamp > lastTimestamp) {
|
|
36
|
+
sequence = random[6] * 16777216 + random[7] * 65536 + random[8] * 256 + random[9];
|
|
37
|
+
lastTimestamp = timestamp;
|
|
38
|
+
} else {
|
|
39
|
+
sequence = sequence + 1 >>> 0;
|
|
40
|
+
if (sequence === 0) lastTimestamp++;
|
|
41
|
+
}
|
|
42
|
+
const bytes = /* @__PURE__ */ new Uint8Array(16);
|
|
43
|
+
bytes[0] = lastTimestamp / 1099511627776 & 255;
|
|
44
|
+
bytes[1] = lastTimestamp / 4294967296 & 255;
|
|
45
|
+
bytes[2] = lastTimestamp / 16777216 & 255;
|
|
46
|
+
bytes[3] = lastTimestamp / 65536 & 255;
|
|
47
|
+
bytes[4] = lastTimestamp / 256 & 255;
|
|
48
|
+
bytes[5] = lastTimestamp & 255;
|
|
49
|
+
bytes[6] = 112 | sequence >>> 28 & 15;
|
|
50
|
+
bytes[7] = sequence >>> 20 & 255;
|
|
51
|
+
bytes[8] = 128 | sequence >>> 14 & 63;
|
|
52
|
+
bytes[9] = sequence >>> 6 & 255;
|
|
53
|
+
bytes[10] = (sequence & 63) << 2 | random[10] & 3;
|
|
54
|
+
bytes[11] = random[11];
|
|
55
|
+
bytes[12] = random[12];
|
|
56
|
+
bytes[13] = random[13];
|
|
57
|
+
bytes[14] = random[14];
|
|
58
|
+
bytes[15] = random[15];
|
|
59
|
+
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0"));
|
|
60
|
+
return `${hex.slice(0, 4).join("")}-${hex.slice(4, 6).join("")}-${hex.slice(6, 8).join("")}-${hex.slice(8, 10).join("")}-${hex.slice(10, 16).join("")}`;
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
export { cleanupSessionResources as n, registerSessionResourceCleanup as r, uuidv7 as t };
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=uuid-DtFT7tOE.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid-DtFT7tOE.mjs","names":[],"sources":["../node_modules/.pnpm/@earendil-works+pi-ai@0.84.1_ws@8.21.3_zod@4.4.3/node_modules/@earendil-works/pi-ai/dist/session-resources.js","../node_modules/.pnpm/@earendil-works+pi-ai@0.84.1_ws@8.21.3_zod@4.4.3/node_modules/@earendil-works/pi-ai/dist/utils/uuid.js"],"sourcesContent":["const sessionResourceCleanups = new Set();\nexport function registerSessionResourceCleanup(cleanup) {\n sessionResourceCleanups.add(cleanup);\n return () => {\n sessionResourceCleanups.delete(cleanup);\n };\n}\nexport function cleanupSessionResources(sessionId) {\n const errors = [];\n for (const cleanup of sessionResourceCleanups) {\n try {\n cleanup(sessionId);\n }\n catch (error) {\n errors.push(error);\n }\n }\n if (errors.length > 0) {\n throw new AggregateError(errors, \"Failed to cleanup session resources\");\n }\n}\n//# sourceMappingURL=session-resources.js.map","let lastTimestamp = -Infinity;\nlet sequence = 0;\nfunction fillRandomBytes(bytes) {\n if (globalThis.crypto?.getRandomValues) {\n globalThis.crypto.getRandomValues(bytes);\n return;\n }\n for (let i = 0; i < bytes.length; i++) {\n bytes[i] = Math.floor(Math.random() * 256);\n }\n}\n/** Generate a time-ordered UUIDv7. */\nexport function uuidv7() {\n const random = new Uint8Array(16);\n fillRandomBytes(random);\n const timestamp = Date.now();\n if (timestamp > lastTimestamp) {\n sequence = random[6] * 0x1000000 + random[7] * 0x10000 + random[8] * 0x100 + random[9];\n lastTimestamp = timestamp;\n }\n else {\n sequence = (sequence + 1) >>> 0;\n if (sequence === 0)\n lastTimestamp++;\n }\n const bytes = new Uint8Array(16);\n bytes[0] = (lastTimestamp / 0x10000000000) & 0xff;\n bytes[1] = (lastTimestamp / 0x100000000) & 0xff;\n bytes[2] = (lastTimestamp / 0x1000000) & 0xff;\n bytes[3] = (lastTimestamp / 0x10000) & 0xff;\n bytes[4] = (lastTimestamp / 0x100) & 0xff;\n bytes[5] = lastTimestamp & 0xff;\n bytes[6] = 0x70 | ((sequence >>> 28) & 0x0f);\n bytes[7] = (sequence >>> 20) & 0xff;\n bytes[8] = 0x80 | ((sequence >>> 14) & 0x3f);\n bytes[9] = (sequence >>> 6) & 0xff;\n bytes[10] = ((sequence & 0x3f) << 2) | (random[10] & 0x03);\n bytes[11] = random[11];\n bytes[12] = random[12];\n bytes[13] = random[13];\n bytes[14] = random[14];\n bytes[15] = random[15];\n const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, \"0\"));\n return `${hex.slice(0, 4).join(\"\")}-${hex.slice(4, 6).join(\"\")}-${hex.slice(6, 8).join(\"\")}-${hex.slice(8, 10).join(\"\")}-${hex.slice(10, 16).join(\"\")}`;\n}\n//# sourceMappingURL=uuid.js.map"],"x_google_ignoreList":[0,1],"mappings":";;AAAA,MAAM,0CAA0B,IAAI,IAAI;AACxC,SAAgB,+BAA+B,SAAS;CACpD,wBAAwB,IAAI,OAAO;CACnC,aAAa;EACT,wBA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,OAAO;CACnB,MAAM,MAAM,OAAO;CACnB,MAAM,MAAM,OAAO;CACnB,MAAM,MAAM,OAAO;CACnB,MAAM,MAAM,OAAO;CACnB,MAAM,MAAM,MAAM,KAAK,QAAQ,SAAS,KAAK,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC;CAC1E,OAAO,GAAG,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,GAAG,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,GAAG,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,GAAG,IAAI,MAAM,GAAG,EAAE,CAAC,CAAC,KAAK,EAAE,EAAE,GAAG,IAAI,MAAM,IAAI,EAAE,CAAC,CAAC,KAAK,EAAE;AACxJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi2dsh",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Bridge the Pi and DeepSeek Harness ecosystems: a general Pi Host ABI that runs unmodified Pi extensions as native DSH plugins, plus per-package conversion and MCP config translation.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -26,6 +26,10 @@
|
|
|
26
26
|
"./compat/pi-ai": {
|
|
27
27
|
"types": "./dist/compat/pi-ai.d.mts",
|
|
28
28
|
"default": "./dist/compat/pi-ai.mjs"
|
|
29
|
+
},
|
|
30
|
+
"./credentials-oauth": {
|
|
31
|
+
"types": "./dist/credentials-oauth.d.mts",
|
|
32
|
+
"default": "./dist/credentials-oauth.mjs"
|
|
29
33
|
}
|
|
30
34
|
},
|
|
31
35
|
"files": [
|
|
@@ -114,14 +118,20 @@
|
|
|
114
118
|
"@deepseek-ai/dsh-agent": "0.1.0-rc.6",
|
|
115
119
|
"@deepseek-ai/dsh-attachment-local": "0.1.0-rc.6",
|
|
116
120
|
"@deepseek-ai/dsh-commands": "0.1.0-rc.6",
|
|
121
|
+
"@deepseek-ai/dsh-credentials": "0.1.0-rc.6",
|
|
122
|
+
"@deepseek-ai/dsh-invariants": "0.1.0-rc.6",
|
|
123
|
+
"@deepseek-ai/dsh-launch-environment": "0.1.0-rc.6",
|
|
117
124
|
"@deepseek-ai/dsh-llm": "0.1.0-rc.6",
|
|
125
|
+
"@deepseek-ai/dsh-llm-pi-ai": "0.1.0-rc.6",
|
|
118
126
|
"@deepseek-ai/dsh-scope": "0.1.0-rc.6",
|
|
119
127
|
"@deepseek-ai/dsh-session": "0.1.0-rc.6",
|
|
128
|
+
"@deepseek-ai/dsh-settings": "0.1.0-rc.6",
|
|
120
129
|
"@deepseek-ai/dsh-skill": "0.1.0-rc.6",
|
|
121
130
|
"@deepseek-ai/dsh-skill-filesystem": "0.1.0-rc.6",
|
|
122
131
|
"@deepseek-ai/dsh-subprocess": "0.1.0-rc.6",
|
|
123
132
|
"@deepseek-ai/dsh-subprocess-local": "0.1.0-rc.6",
|
|
124
133
|
"@deepseek-ai/dsh-system-prompt": "0.1.0-rc.6",
|
|
134
|
+
"@deepseek-ai/dsh-timeout": "0.1.0-rc.6",
|
|
125
135
|
"@deepseek-ai/dsh-tools": "0.1.0-rc.6",
|
|
126
136
|
"@deepseek-ai/dsh-user-questions": "0.1.0-rc.6",
|
|
127
137
|
"@earendil-works/pi-ai": "0.84.1",
|