pi-gemini-app 0.1.8 → 0.1.10
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 +3 -0
- package/extensions/pi/provider.js +19 -69
- package/extensions/pi/stream.js +6 -4
- package/native-wire/robin-current.mjs +2 -1
- package/package.json +1 -1
- package/src/gateway/automatic-recovery.mjs +9 -3
- package/src/gateway/image-download.mjs +2 -1
- package/src/gateway/image-upload.mjs +58 -14
- package/src/gateway/native-diagnostic.mjs +3 -2
- package/src/gateway/native-evidence.mjs +1 -0
- package/src/gateway/native-transport.mjs +66 -6
- package/src/gateway/quota-transport.mjs +2 -2
- package/src/gateway/terms.mjs +3 -3
- package/src/image-input.mjs +11 -4
- package/src/native-provider.mjs +166 -41
- package/src/openai-contract.mjs +61 -16
- package/src/openai-usage.mjs +39 -2
- package/src/tool-protocol.mjs +26 -8
package/src/tool-protocol.mjs
CHANGED
|
@@ -130,7 +130,7 @@ export function buildToolInstruction(tools = [], choice = 'auto') {
|
|
|
130
130
|
'```tool_call',
|
|
131
131
|
'{"name":"declared_name","arguments":{}}',
|
|
132
132
|
'```',
|
|
133
|
-
'Arguments must be a JSON object matching the declared schema. Never invent tools or results.',
|
|
133
|
+
'Arguments must be a JSON object matching the declared schema. Emit one strict UTF-8 JSON object per tool_call block with properly escaped strings (for multiple calls, use separate tool_call blocks; no trailing commas or raw newlines in strings). Never invent tools or results.',
|
|
134
134
|
'Only the caller executes tools. Wait for linked caller tool results before using results.',
|
|
135
135
|
'After emitting your tool_call block(s), STOP your response immediately. Never emit, simulate, or echo [Caller tool result], [User], [Assistant], or any transcript role markers.',
|
|
136
136
|
'A standalone top-level tool_call fence is reserved for actual requests; use json fences for literal examples. Inline references are text.',
|
|
@@ -183,7 +183,7 @@ function callerResultPreviewCut(str) {
|
|
|
183
183
|
* `[Caller tool result]` continuation and everything after it is suppressed so
|
|
184
184
|
* the caller receives only the real tool calls. */
|
|
185
185
|
export function createToolCallSplitter({ newId = () => 'call_' + crypto.randomBytes(12).toString('hex'), policy = compileToolPolicy([]) } = {}) {
|
|
186
|
-
let pending = '', scanned = 0, seen = 0, closed = false, suppressed = false, bytes = 0;
|
|
186
|
+
let pending = '', scanned = 0, seen = 0, closed = false, suppressed = false, bytes = 0, consumedChars = 0;
|
|
187
187
|
let mode = 'text', marker = '`', fenceLength = 3, toolBody = '', toolBytes = 0, headerBytes = 0, inlineTicks = 0;
|
|
188
188
|
const ids = new Set();
|
|
189
189
|
const malformed = reason => {
|
|
@@ -243,7 +243,7 @@ export function createToolCallSplitter({ newId = () => 'call_' + crypto.randomBy
|
|
|
243
243
|
}
|
|
244
244
|
events.push({ type: 'content', text: raw });
|
|
245
245
|
};
|
|
246
|
-
const line = (raw, final, events) => {
|
|
246
|
+
const line = (raw, final, events, lineStartOffset = consumedChars) => {
|
|
247
247
|
if (suppressed) return;
|
|
248
248
|
const eol = /\r?\n$/.exec(raw)?.[0] ?? '';
|
|
249
249
|
const text = eol ? raw.slice(0, -eol.length) : raw;
|
|
@@ -254,7 +254,13 @@ export function createToolCallSplitter({ newId = () => 'call_' + crypto.randomBy
|
|
|
254
254
|
if (run?.[0] === '`' && run.length >= fenceLength) {
|
|
255
255
|
// JSON/name/schema validation, not incidental Markdown suffix layout,
|
|
256
256
|
// authorizes the call. Never scan the suffix again as another request.
|
|
257
|
-
|
|
257
|
+
try {
|
|
258
|
+
emitCall(events);
|
|
259
|
+
} catch (err) {
|
|
260
|
+
if (err && typeof err === 'object') err.postFenceOffset = lineStartOffset + opening[0].length;
|
|
261
|
+
throw err;
|
|
262
|
+
}
|
|
263
|
+
mode = 'text'; toolBody = ''; toolBytes = 0; inlineTicks = 0;
|
|
258
264
|
if (info.trim()) {
|
|
259
265
|
const markerIdx = info.indexOf(CALLER_RESULT_MARKER);
|
|
260
266
|
if (markerIdx >= 0) {
|
|
@@ -292,17 +298,29 @@ export function createToolCallSplitter({ newId = () => 'call_' + crypto.randomBy
|
|
|
292
298
|
};
|
|
293
299
|
const drain = final => {
|
|
294
300
|
const events = []; let consumed = 0, from = scanned;
|
|
301
|
+
const runLine = (raw, isFinal, lineStartOffset) => {
|
|
302
|
+
try { line(raw, isFinal, events, lineStartOffset); }
|
|
303
|
+
catch (err) {
|
|
304
|
+
if (err && typeof err === 'object' && err.postFenceOffset === undefined) {
|
|
305
|
+
err.postFenceOffset = lineStartOffset + raw.length;
|
|
306
|
+
}
|
|
307
|
+
throw err;
|
|
308
|
+
}
|
|
309
|
+
};
|
|
295
310
|
for (;;) {
|
|
296
311
|
const end = pending.indexOf('\n', from);
|
|
297
312
|
if (end < 0) break;
|
|
298
|
-
|
|
313
|
+
const lineStartOffset = consumedChars + consumed;
|
|
314
|
+
runLine(pending.slice(consumed, end + 1), false, lineStartOffset);
|
|
299
315
|
consumed = end + 1; from = consumed;
|
|
300
|
-
if (suppressed) { pending = ''; scanned = 0; return events; }
|
|
316
|
+
if (suppressed) { consumedChars += consumed; pending = ''; scanned = 0; return events; }
|
|
301
317
|
}
|
|
302
|
-
if (consumed) pending = pending.slice(consumed);
|
|
318
|
+
if (consumed) { consumedChars += consumed; pending = pending.slice(consumed); }
|
|
303
319
|
scanned = pending.length;
|
|
304
320
|
if (final && pending) {
|
|
305
|
-
|
|
321
|
+
const lineStartOffset = consumedChars;
|
|
322
|
+
runLine(pending, true, lineStartOffset);
|
|
323
|
+
consumedChars += pending.length;
|
|
306
324
|
pending = ''; scanned = 0;
|
|
307
325
|
if (suppressed) return events;
|
|
308
326
|
}
|