mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-20 16:07:47 +08:00
Merge pull request #116 from CJackHwang/codex/align-vercel-deployment-with-go-version-semantics
Align Vercel JS toolcall detection/format behavior with Go semantics
This commit is contained in:
@@ -60,6 +60,9 @@ function formatIncrementalToolCallDeltas(deltas, idStore) {
|
|||||||
if (typeof d.arguments === 'string' && d.arguments !== '') {
|
if (typeof d.arguments === 'string' && d.arguments !== '') {
|
||||||
fn.arguments = d.arguments;
|
fn.arguments = d.arguments;
|
||||||
}
|
}
|
||||||
|
if (Object.keys(fn).length === 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (Object.keys(fn).length > 0) {
|
if (Object.keys(fn).length > 0) {
|
||||||
item.function = fn;
|
item.function = fn;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,15 +17,18 @@ function extractToolNames(tools) {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
const out = [];
|
const out = [];
|
||||||
|
const seen = new Set();
|
||||||
for (const t of tools) {
|
for (const t of tools) {
|
||||||
if (!t || typeof t !== 'object') {
|
if (!t || typeof t !== 'object') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const fn = t.function && typeof t.function === 'object' ? t.function : t;
|
const fn = t.function && typeof t.function === 'object' ? t.function : t;
|
||||||
const name = toStringSafe(fn.name);
|
const name = toStringSafe(fn.name);
|
||||||
// Keep parity with Go injectToolPrompt: object tools without name still
|
if (!name || seen.has(name)) {
|
||||||
// enter tool mode via fallback name "unknown".
|
continue;
|
||||||
out.push(name || 'unknown');
|
}
|
||||||
|
seen.add(name);
|
||||||
|
out.push(name);
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,6 +98,12 @@ test('incremental and final tool formatting share stable id via idStore', () =>
|
|||||||
assert.equal(incremental[0].id, finalCalls[0].id);
|
assert.equal(incremental[0].id, finalCalls[0].id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('formatIncrementalToolCallDeltas drops empty deltas (Go parity)', () => {
|
||||||
|
const idStore = new Map();
|
||||||
|
const formatted = formatIncrementalToolCallDeltas([{ index: 0 }], idStore);
|
||||||
|
assert.deepEqual(formatted, []);
|
||||||
|
});
|
||||||
|
|
||||||
test('parseChunkForContent keeps split response/content fragments inside response array', () => {
|
test('parseChunkForContent keeps split response/content fragments inside response array', () => {
|
||||||
const chunk = {
|
const chunk = {
|
||||||
p: 'response',
|
p: 'response',
|
||||||
|
|||||||
@@ -31,13 +31,14 @@ function collectText(events) {
|
|||||||
.join('');
|
.join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
test('extractToolNames keeps tool mode enabled with unknown fallback', () => {
|
test('extractToolNames keeps only declared tool names (Go parity)', () => {
|
||||||
const names = extractToolNames([
|
const names = extractToolNames([
|
||||||
{ function: { description: 'no name tool' } },
|
{ function: { description: 'no name tool' } },
|
||||||
{ function: { name: ' read_file ' } },
|
{ function: { name: ' read_file ' } },
|
||||||
|
{ function: { name: 'read_file' } },
|
||||||
{},
|
{},
|
||||||
]);
|
]);
|
||||||
assert.deepEqual(names, ['unknown', 'read_file', 'unknown']);
|
assert.deepEqual(names, ['read_file']);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('parseToolCalls keeps non-object argument strings as _raw (Go parity)', () => {
|
test('parseToolCalls keeps non-object argument strings as _raw (Go parity)', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user