@namzu/openai 1.0.2 → 1.1.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 +168 -0
- package/dist/__tests__/document-input.test.d.ts +2 -0
- package/dist/__tests__/document-input.test.d.ts.map +1 -0
- package/dist/__tests__/document-input.test.js +92 -0
- package/dist/__tests__/document-input.test.js.map +1 -0
- package/dist/__tests__/error-taxonomy.test.d.ts +14 -0
- package/dist/__tests__/error-taxonomy.test.d.ts.map +1 -0
- package/dist/__tests__/error-taxonomy.test.js +203 -0
- package/dist/__tests__/error-taxonomy.test.js.map +1 -0
- package/dist/__tests__/openai.test.js +74 -3
- package/dist/__tests__/openai.test.js.map +1 -1
- package/dist/__tests__/reasoning-params.test.d.ts +2 -0
- package/dist/__tests__/reasoning-params.test.d.ts.map +1 -0
- package/dist/__tests__/reasoning-params.test.js +61 -0
- package/dist/__tests__/reasoning-params.test.js.map +1 -0
- package/dist/__tests__/strict-schema.test.d.ts +2 -0
- package/dist/__tests__/strict-schema.test.d.ts.map +1 -0
- package/dist/__tests__/strict-schema.test.js +85 -0
- package/dist/__tests__/strict-schema.test.js.map +1 -0
- package/dist/client.d.ts +28 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +162 -67
- package/dist/client.js.map +1 -1
- package/dist/strict-schema.d.ts +2 -0
- package/dist/strict-schema.d.ts.map +1 -0
- package/dist/strict-schema.js +2 -0
- package/dist/strict-schema.js.map +1 -0
- package/package.json +4 -4
- package/src/__tests__/document-input.test.ts +125 -0
- package/src/__tests__/error-taxonomy.test.ts +234 -0
- package/src/__tests__/openai.test.ts +77 -3
- package/src/__tests__/reasoning-params.test.ts +76 -0
- package/src/__tests__/strict-schema.test.ts +110 -0
- package/src/client.ts +169 -67
- package/src/strict-schema.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reasoning-params.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/reasoning-params.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { OPENAI_CAPABILITIES, assertThinkingSupported } from '../client.js';
|
|
3
|
+
/**
|
|
4
|
+
* This driver does not implement extended thinking, and used to accept the
|
|
5
|
+
* request anyway.
|
|
6
|
+
*
|
|
7
|
+
* So a caller who asked for reasoning got an ordinary completion: no
|
|
8
|
+
* thinking, no reasoning blocks, and no error. The empty reasoning list
|
|
9
|
+
* that came back reads as "the model did not reason" rather than "nobody
|
|
10
|
+
* asked it to" — which is the failure mode, not the missing feature. Same
|
|
11
|
+
* call as the citations one in this driver: refuse what cannot be
|
|
12
|
+
* delivered rather than deliver something else quietly.
|
|
13
|
+
*/
|
|
14
|
+
describe('an extended-thinking request is refused, not dropped', () => {
|
|
15
|
+
it('throws when thinking is asked for', () => {
|
|
16
|
+
expect(() => assertThinkingSupported({ thinking: { type: 'enabled' } })).toThrow(/extended thinking/i);
|
|
17
|
+
});
|
|
18
|
+
it('says what to do instead', () => {
|
|
19
|
+
expect(() => assertThinkingSupported({ thinking: { type: 'enabled' } })).toThrow(/Drop `thinking`/);
|
|
20
|
+
});
|
|
21
|
+
it('explains why silence would be worse than an error', () => {
|
|
22
|
+
// The message has to name the symptom the caller would otherwise
|
|
23
|
+
// see, or they will read the empty list as an answer.
|
|
24
|
+
expect(() => assertThinkingSupported({ thinking: { type: 'enabled' } })).toThrow(/empty reasoning list/);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe('asking for it to be off is honoured as a no-op', () => {
|
|
28
|
+
it('accepts an explicit disable', () => {
|
|
29
|
+
// Off is the state this driver is already in, so refusing here would
|
|
30
|
+
// reject a request it is in fact satisfying.
|
|
31
|
+
expect(() => assertThinkingSupported({ thinking: { type: 'disabled' } })).not.toThrow();
|
|
32
|
+
});
|
|
33
|
+
it('accepts a call that says nothing about thinking', () => {
|
|
34
|
+
expect(() => assertThinkingSupported({})).not.toThrow();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe('the declared capabilities stay honest', () => {
|
|
38
|
+
it('claims the tools and streaming it does implement', () => {
|
|
39
|
+
expect(OPENAI_CAPABILITIES.supportsTools).toBe(true);
|
|
40
|
+
expect(OPENAI_CAPABILITIES.supportsStreaming).toBe(true);
|
|
41
|
+
expect(OPENAI_CAPABILITIES.supportsFunctionCalling).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
it('claims the vision and documents it now maps', () => {
|
|
44
|
+
expect(OPENAI_CAPABILITIES.supportsVision).toBe(true);
|
|
45
|
+
expect(OPENAI_CAPABILITIES.supportsDocuments).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
it('answers every flag the negotiation reads', () => {
|
|
48
|
+
// An absent flag defaults to permissive, so a missing one is not a
|
|
49
|
+
// neutral omission — it is a claim.
|
|
50
|
+
for (const flag of [
|
|
51
|
+
'supportsTools',
|
|
52
|
+
'supportsStreaming',
|
|
53
|
+
'supportsFunctionCalling',
|
|
54
|
+
'supportsVision',
|
|
55
|
+
'supportsDocuments',
|
|
56
|
+
]) {
|
|
57
|
+
expect(typeof OPENAI_CAPABILITIES[flag]).toBe('boolean');
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=reasoning-params.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reasoning-params.test.js","sourceRoot":"","sources":["../../src/__tests__/reasoning-params.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA;AAE3E;;;;;;;;;;GAUG;AAEH,QAAQ,CAAC,sDAAsD,EAAE,GAAG,EAAE;IACrE,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QAC5C,MAAM,CAAC,GAAG,E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,GAAG,EAAE;QAC3D,MAAM,CAAC,mBAAmB,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACpD,MAAM,CAAC,mBAAmB,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACxD,MAAM,CAAC,mBAAmB,CAAC,uBAAuB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC/D,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACtD,MAAM,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACrD,MAAM,CAAC,mBAAmB,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACzD,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;QACnD,mEAAmE;QACnE,oCAAoC;QACpC,KAAK,MAAM,IAAI,IAAI;YAClB,eAAe;YACf,mBAAmB;YACnB,yBAAyB;YACzB,gBAAgB;YAChB,mBAAmB;SACV,EAAE,CAAC;YACZ,MAAM,CAAC,OAAO,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QACzD,CAAC;IACF,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strict-schema.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/strict-schema.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { toOpenAITools } from '../client.js';
|
|
3
|
+
/**
|
|
4
|
+
* `enforceToolInputSchema` names the tools whose model-facing schema should
|
|
5
|
+
* be enforced by constrained generation rather than merely suggested.
|
|
6
|
+
*
|
|
7
|
+
* Both sibling drivers consumed it. This one dropped it on the floor, so a
|
|
8
|
+
* caller who had asked for a guaranteed-valid tool input silently got a
|
|
9
|
+
* best-effort one, and learned about it from a repair attempt rather than
|
|
10
|
+
* from an error. This is the wire the flag maps onto most directly — it
|
|
11
|
+
* takes the flag on the function itself.
|
|
12
|
+
*/
|
|
13
|
+
const TOOLS = [
|
|
14
|
+
{
|
|
15
|
+
type: 'function',
|
|
16
|
+
function: {
|
|
17
|
+
name: 'read',
|
|
18
|
+
description: 'read a file',
|
|
19
|
+
parameters: { type: 'object', properties: { path: { type: 'string' } } },
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
type: 'function',
|
|
24
|
+
function: { name: 'write', description: 'write a file', parameters: { type: 'object' } },
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
function toolsFor(enforceToolInputSchema) {
|
|
28
|
+
return toOpenAITools({
|
|
29
|
+
model: 'm',
|
|
30
|
+
messages: [],
|
|
31
|
+
tools: TOOLS,
|
|
32
|
+
...(enforceToolInputSchema ? { enforceToolInputSchema } : {}),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
describe('the schema of a named tool is enforced, not suggested', () => {
|
|
36
|
+
it('marks the tool the caller named', () => {
|
|
37
|
+
const tools = toolsFor(['read']);
|
|
38
|
+
expect(tools?.find((t) => t.function.name === 'read')?.function.strict).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
it('leaves every other tool alone', () => {
|
|
41
|
+
const tools = toolsFor(['read']);
|
|
42
|
+
// Enforcement is not free and not always possible; marking a tool
|
|
43
|
+
// nobody asked about changes behaviour the caller did not ask to
|
|
44
|
+
// change.
|
|
45
|
+
expect(tools?.find((t) => t.function.name === 'write')?.function).not.toHaveProperty('strict');
|
|
46
|
+
});
|
|
47
|
+
it('marks several when several were named', () => {
|
|
48
|
+
const tools = toolsFor(['read', 'write']);
|
|
49
|
+
expect(tools?.every((t) => t.function.strict === true)).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
it('marks nothing when the hint is absent', () => {
|
|
52
|
+
expect(toolsFor()?.some((t) => 'strict' in t.function)).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
it('marks nothing when the hint names no tool', () => {
|
|
55
|
+
expect(toolsFor([])?.some((t) => 'strict' in t.function)).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
it('ignores a name that matches no registered tool', () => {
|
|
58
|
+
const tools = toolsFor(['nonexistent']);
|
|
59
|
+
expect(tools).toHaveLength(2);
|
|
60
|
+
expect(tools?.some((t) => 'strict' in t.function)).toBe(false);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
describe('the rest of the tool schema is untouched', () => {
|
|
64
|
+
it('keeps the name, description and parameters', () => {
|
|
65
|
+
const read = toolsFor(['read'])?.find((t) => t.function.name === 'read');
|
|
66
|
+
expect(read?.function.description).toBe('read a file');
|
|
67
|
+
expect(read?.function.parameters).toMatchObject({
|
|
68
|
+
type: 'object',
|
|
69
|
+
properties: { path: { type: 'string' } },
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
it('substitutes an empty object for missing parameters', () => {
|
|
73
|
+
const tools = toOpenAITools({
|
|
74
|
+
model: 'm',
|
|
75
|
+
messages: [],
|
|
76
|
+
tools: [{ type: 'function', function: { name: 'ping' } }],
|
|
77
|
+
});
|
|
78
|
+
expect(tools?.[0]?.function.parameters).toEqual({});
|
|
79
|
+
});
|
|
80
|
+
it('sends no tools at all when there are none', () => {
|
|
81
|
+
expect(toOpenAITools({ model: 'm', messages: [] })).toBeUndefined();
|
|
82
|
+
expect(toOpenAITools({ model: 'm', messages: [], tools: [] })).toBeUndefined();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
//# sourceMappingURL=strict-schema.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strict-schema.test.js","sourceRoot":"","sources":["../../src/__tests__/strict-schema.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM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CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,EAA0B,CAAC,CAAC,CAAC,aAAa,EAAE,CAAA;QAC3F,MAAM,CACL,aAAa,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAA0B,CAAC,CAC9E,CAAC,aAAa,EAAE,CAAA;IAClB,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ChatCompletionParams, LLMProvider, ModelInfo, ProviderCapabilities, StreamChunk } from '@namzu/sdk';
|
|
2
|
-
import type { ChatCompletionMessageParam } from 'openai/resources/chat/completions';
|
|
2
|
+
import type { ChatCompletionMessageParam, ChatCompletionTool } from 'openai/resources/chat/completions';
|
|
3
3
|
import type { OpenAIConfig } from './types.js';
|
|
4
4
|
/**
|
|
5
5
|
* Full capability set — this driver maps tools (`toOpenAITools`), streams
|
|
@@ -7,7 +7,34 @@ import type { OpenAIConfig } from './types.js';
|
|
|
7
7
|
* content parts with base64 data URIs (`toOpenAIMessages`).
|
|
8
8
|
*/
|
|
9
9
|
export declare const OPENAI_CAPABILITIES: ProviderCapabilities;
|
|
10
|
+
/**
|
|
11
|
+
* Refuse an extended-thinking request this driver does not implement.
|
|
12
|
+
*
|
|
13
|
+
* The parameter was accepted and dropped, so a caller who had asked for
|
|
14
|
+
* reasoning got an ordinary completion: no thinking, no reasoning blocks,
|
|
15
|
+
* no error — and the empty reasoning array reads as "the model did not
|
|
16
|
+
* reason" rather than "nobody asked it to". Turning it OFF is honoured as
|
|
17
|
+
* a no-op, because that is the state the driver is already in.
|
|
18
|
+
*/
|
|
19
|
+
export declare function assertThinkingSupported(params: {
|
|
20
|
+
thinking?: {
|
|
21
|
+
type: 'enabled' | 'disabled';
|
|
22
|
+
};
|
|
23
|
+
}): void;
|
|
10
24
|
export declare function toOpenAIMessages(messages: ChatCompletionParams['messages']): ChatCompletionMessageParam[];
|
|
25
|
+
/**
|
|
26
|
+
* Tool schemas, with constrained generation where the caller asked for it.
|
|
27
|
+
*
|
|
28
|
+
* `enforceToolInputSchema` names the tools whose schema should be enforced
|
|
29
|
+
* rather than suggested. Both sibling drivers consumed it; this one dropped
|
|
30
|
+
* it on the floor, so a caller who had asked for a guaranteed-valid tool
|
|
31
|
+
* input got a best-effort one — and found out from a repair attempt rather
|
|
32
|
+
* than from an error.
|
|
33
|
+
*
|
|
34
|
+
* This wire is the one the flag maps onto most directly: it takes `strict`
|
|
35
|
+
* on the function itself.
|
|
36
|
+
*/
|
|
37
|
+
export declare function toOpenAITools(params: ChatCompletionParams): ChatCompletionTool[] | undefined;
|
|
11
38
|
export declare class OpenAIProvider implements LLMProvider {
|
|
12
39
|
readonly id = "openai";
|
|
13
40
|
readonly name = "OpenAI";
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,oBAAoB,EAEpB,WAAW,EACX,SAAS,EACT,oBAAoB,EACpB,WAAW,EAGX,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,oBAAoB,EAEpB,WAAW,EACX,SAAS,EACT,oBAAoB,EACpB,WAAW,EAGX,MAAM,YAAY,CAAA;AASnB,OAAO,KAAK,EAEX,0BAA0B,EAC1B,kBAAkB,EAElB,MAAM,mCAAmC,CAAA;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,oBAMjC,CAAA;AAyDD;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE;IAC/C,QAAQ,CAAC,EAAE;QAAE,IAAI,EAAE,SAAS,GAAG,UAAU,CAAA;KAAE,CAAA;CAC3C,GAAG,IAAI,CAOP;AAuBD,wBAAgB,gBAAgB,CAC/B,QAAQ,EAAE,oBAAoB,CAAC,UAAU,CAAC,GACxC,0BAA0B,EAAE,CAoE9B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,oBAAoB,GAAG,kBAAkB,EAAE,GAAG,SAAS,CAY5F;AAED,qBAAa,cAAe,YAAW,WAAW;IACjD,QAAQ,CAAC,EAAE,YAAW;IACtB,QAAQ,CAAC,IAAI,YAAW;IACxB,QAAQ,CAAC,YAAY,uBAAsB;IAE3C,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,YAAY,CAAC,CAAQ;gBAEjB,MAAM,EAAE,YAAY;IAkBhC,OAAO,CAAC,YAAY;IAUb,UAAU,CAAC,MAAM,EAAE,oBAAoB,GAAG,aAAa,CAAC,WAAW,CAAC;IA6FrE,UAAU,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAclC,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;CAQrC"}
|
package/dist/client.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { toolResultToText } from '@namzu/sdk';
|
|
2
|
+
import { ProviderRequestError, isCallerAbortError, isProviderRequestError, providerVendorError, } from '@namzu/sdk';
|
|
1
3
|
import OpenAI from 'openai';
|
|
2
4
|
/**
|
|
3
5
|
* Full capability set — this driver maps tools (`toOpenAITools`), streams
|
|
@@ -9,6 +11,7 @@ export const OPENAI_CAPABILITIES = {
|
|
|
9
11
|
supportsStreaming: true,
|
|
10
12
|
supportsFunctionCalling: true,
|
|
11
13
|
supportsVision: true,
|
|
14
|
+
supportsDocuments: true,
|
|
12
15
|
};
|
|
13
16
|
function mapFinishReason(reason) {
|
|
14
17
|
switch (reason) {
|
|
@@ -53,22 +56,70 @@ function formatToolChoice(tc) {
|
|
|
53
56
|
}
|
|
54
57
|
return undefined;
|
|
55
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Refuse an extended-thinking request this driver does not implement.
|
|
61
|
+
*
|
|
62
|
+
* The parameter was accepted and dropped, so a caller who had asked for
|
|
63
|
+
* reasoning got an ordinary completion: no thinking, no reasoning blocks,
|
|
64
|
+
* no error — and the empty reasoning array reads as "the model did not
|
|
65
|
+
* reason" rather than "nobody asked it to". Turning it OFF is honoured as
|
|
66
|
+
* a no-op, because that is the state the driver is already in.
|
|
67
|
+
*/
|
|
68
|
+
export function assertThinkingSupported(params) {
|
|
69
|
+
if (params.thinking?.type !== 'enabled')
|
|
70
|
+
return;
|
|
71
|
+
throw new Error('This provider driver does not implement extended thinking, and silently ' +
|
|
72
|
+
'ignoring the request would return an ordinary completion with an empty ' +
|
|
73
|
+
'reasoning list. Drop `thinking`, or use a driver that implements it.');
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Refuse a document whose citations this wire cannot return.
|
|
77
|
+
*
|
|
78
|
+
* Citations are the difference between an answer you trust and one you
|
|
79
|
+
* verify, and this request format has no mechanism to carry them back.
|
|
80
|
+
* Sending the document anyway would answer the question and quietly drop
|
|
81
|
+
* the checkability the caller specifically asked for — the caller would
|
|
82
|
+
* see prose, no error, and an empty `citations` array they might read as
|
|
83
|
+
* "the model cited nothing" rather than "nobody asked".
|
|
84
|
+
*/
|
|
85
|
+
function assertCitationsSupported(attachment, index) {
|
|
86
|
+
if (!attachment.citations)
|
|
87
|
+
return;
|
|
88
|
+
const which = attachment.name ?? `attachment ${index}`;
|
|
89
|
+
throw new Error(`This provider cannot return citations, and ${which} asked for them. Drop \`citations\` to send the document without them, or use a provider whose capabilities include citation support.`);
|
|
90
|
+
}
|
|
56
91
|
export function toOpenAIMessages(messages) {
|
|
57
92
|
return messages.map((msg) => {
|
|
58
93
|
if (msg.role === 'system') {
|
|
59
94
|
return { role: 'system', content: msg.content };
|
|
60
95
|
}
|
|
61
96
|
if (msg.role === 'user') {
|
|
62
|
-
// User message with
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
//
|
|
97
|
+
// User message with attachments → multimodal content parts, text
|
|
98
|
+
// first. Images become an `image_url` part carrying a base64 data
|
|
99
|
+
// URI; documents become a `file` part. Plain text-only user
|
|
100
|
+
// messages keep the string form.
|
|
66
101
|
if (msg.attachments && msg.attachments.length > 0) {
|
|
67
102
|
const parts = [];
|
|
68
103
|
if (msg.content.length > 0) {
|
|
69
104
|
parts.push({ type: 'text', text: msg.content });
|
|
70
105
|
}
|
|
71
|
-
for (const att of msg.attachments) {
|
|
106
|
+
for (const [index, att] of msg.attachments.entries()) {
|
|
107
|
+
if (att.type === 'document') {
|
|
108
|
+
// A document is not an image with a different media
|
|
109
|
+
// type. Every attachment used to become an `image_url`,
|
|
110
|
+
// so a PDF went up as `data:application/pdf;base64,...`
|
|
111
|
+
// inside an image part — while the capability set
|
|
112
|
+
// claimed documents were supported.
|
|
113
|
+
assertCitationsSupported(att, index);
|
|
114
|
+
parts.push({
|
|
115
|
+
type: 'file',
|
|
116
|
+
file: {
|
|
117
|
+
file_data: `data:${att.mediaType};base64,${att.data}`,
|
|
118
|
+
...(att.name ? { filename: att.name } : {}),
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
72
123
|
parts.push({
|
|
73
124
|
type: 'image_url',
|
|
74
125
|
image_url: { url: `data:${att.mediaType};base64,${att.data}` },
|
|
@@ -81,7 +132,10 @@ export function toOpenAIMessages(messages) {
|
|
|
81
132
|
if (msg.role === 'tool') {
|
|
82
133
|
return {
|
|
83
134
|
role: 'tool',
|
|
84
|
-
content
|
|
135
|
+
// Tool messages are text-only on this wire, so a content block
|
|
136
|
+
// degrades to an honest placeholder rather than having its
|
|
137
|
+
// base64 payload dumped as text.
|
|
138
|
+
content: toolResultToText(msg.content),
|
|
85
139
|
tool_call_id: msg.toolCallId,
|
|
86
140
|
};
|
|
87
141
|
}
|
|
@@ -104,15 +158,29 @@ export function toOpenAIMessages(messages) {
|
|
|
104
158
|
return assistant;
|
|
105
159
|
});
|
|
106
160
|
}
|
|
107
|
-
|
|
161
|
+
/**
|
|
162
|
+
* Tool schemas, with constrained generation where the caller asked for it.
|
|
163
|
+
*
|
|
164
|
+
* `enforceToolInputSchema` names the tools whose schema should be enforced
|
|
165
|
+
* rather than suggested. Both sibling drivers consumed it; this one dropped
|
|
166
|
+
* it on the floor, so a caller who had asked for a guaranteed-valid tool
|
|
167
|
+
* input got a best-effort one — and found out from a repair attempt rather
|
|
168
|
+
* than from an error.
|
|
169
|
+
*
|
|
170
|
+
* This wire is the one the flag maps onto most directly: it takes `strict`
|
|
171
|
+
* on the function itself.
|
|
172
|
+
*/
|
|
173
|
+
export function toOpenAITools(params) {
|
|
108
174
|
if (!params.tools || params.tools.length === 0)
|
|
109
175
|
return undefined;
|
|
176
|
+
const enforced = new Set(params.enforceToolInputSchema ?? []);
|
|
110
177
|
return params.tools.map((t) => ({
|
|
111
178
|
type: 'function',
|
|
112
179
|
function: {
|
|
113
180
|
name: t.function.name,
|
|
114
181
|
description: t.function.description ?? '',
|
|
115
182
|
parameters: (t.function.parameters ?? {}),
|
|
183
|
+
...(enforced.has(t.function.name) ? { strict: true } : {}),
|
|
116
184
|
},
|
|
117
185
|
}));
|
|
118
186
|
}
|
|
@@ -151,68 +219,95 @@ export class OpenAIProvider {
|
|
|
151
219
|
}
|
|
152
220
|
async *chatStream(params) {
|
|
153
221
|
const model = this.resolveModel(params);
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
stream
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
//
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
222
|
+
assertThinkingSupported(params);
|
|
223
|
+
let stream;
|
|
224
|
+
try {
|
|
225
|
+
stream = await this.client.chat.completions.create({
|
|
226
|
+
model,
|
|
227
|
+
messages: toOpenAIMessages(params.messages),
|
|
228
|
+
stream: true,
|
|
229
|
+
stream_options: { include_usage: true },
|
|
230
|
+
tools: toOpenAITools(params),
|
|
231
|
+
tool_choice: formatToolChoice(params.toolChoice),
|
|
232
|
+
parallel_tool_calls: params.parallelToolCalls,
|
|
233
|
+
temperature: params.temperature,
|
|
234
|
+
max_tokens: params.maxTokens,
|
|
235
|
+
top_p: params.topP,
|
|
236
|
+
frequency_penalty: params.frequencyPenalty,
|
|
237
|
+
presence_penalty: params.presencePenalty,
|
|
238
|
+
stop: params.stop,
|
|
239
|
+
response_format: params.responseFormat,
|
|
240
|
+
},
|
|
241
|
+
// Per-request abort: a Stop tears the in-flight SSE request down.
|
|
242
|
+
{ signal: params.signal });
|
|
243
|
+
}
|
|
244
|
+
catch (err) {
|
|
245
|
+
// The vendor SDK builds its error message FROM the response body, so a
|
|
246
|
+
// credential the upstream echoed back is already inside `err.message`
|
|
247
|
+
// before this code runs (proven with a planted fake token). Classify from
|
|
248
|
+
// the status and drop the vendor error entirely — no re-throw, no
|
|
249
|
+
// `cause`, because a `cause` is exactly what a structured logger walks.
|
|
250
|
+
if (isCallerAbortError(err, params.signal))
|
|
251
|
+
throw params.signal?.reason ?? err;
|
|
252
|
+
if (isProviderRequestError(err))
|
|
253
|
+
throw err;
|
|
254
|
+
throw providerVendorError({ providerId: 'openai', error: err });
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
for await (const chunk of stream) {
|
|
258
|
+
// Stop pulling promptly on abort; `for await` calls the stream's
|
|
259
|
+
// `.return()` on this throw, releasing the connection.
|
|
260
|
+
params.signal?.throwIfAborted();
|
|
261
|
+
try {
|
|
262
|
+
const choice = chunk.choices[0];
|
|
263
|
+
const delta = choice?.delta;
|
|
264
|
+
const toolCalls = delta?.tool_calls?.map((tc) => ({
|
|
265
|
+
index: tc.index,
|
|
266
|
+
id: tc.id,
|
|
267
|
+
type: tc.type,
|
|
268
|
+
function: tc.function
|
|
269
|
+
? {
|
|
270
|
+
name: tc.function.name,
|
|
271
|
+
arguments: tc.function.arguments,
|
|
272
|
+
}
|
|
273
|
+
: undefined,
|
|
274
|
+
}));
|
|
275
|
+
const hasDelta = (delta?.content !== undefined && delta.content !== null) ||
|
|
276
|
+
(toolCalls && toolCalls.length > 0);
|
|
277
|
+
const finishReason = choice?.finish_reason
|
|
278
|
+
? mapFinishReason(choice.finish_reason)
|
|
279
|
+
: undefined;
|
|
280
|
+
const usage = chunk.usage ? parseUsage(chunk.usage) : undefined;
|
|
281
|
+
if (!hasDelta && !finishReason && !usage)
|
|
282
|
+
continue;
|
|
283
|
+
yield {
|
|
284
|
+
id: chunk.id,
|
|
285
|
+
delta: {
|
|
286
|
+
content: delta?.content ?? undefined,
|
|
287
|
+
toolCalls,
|
|
288
|
+
},
|
|
289
|
+
finishReason,
|
|
290
|
+
usage,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
catch (parseErr) {
|
|
294
|
+
if (isProviderRequestError(parseErr))
|
|
295
|
+
throw parseErr;
|
|
296
|
+
throw new ProviderRequestError({
|
|
297
|
+
kind: 'server',
|
|
298
|
+
providerId: 'openai',
|
|
299
|
+
detail: 'the provider stream returned malformed data',
|
|
300
|
+
});
|
|
301
|
+
}
|
|
214
302
|
}
|
|
215
303
|
}
|
|
304
|
+
catch (err) {
|
|
305
|
+
if (isCallerAbortError(err, params.signal))
|
|
306
|
+
throw params.signal?.reason ?? err;
|
|
307
|
+
if (isProviderRequestError(err))
|
|
308
|
+
throw err;
|
|
309
|
+
throw providerVendorError({ providerId: 'openai', error: err });
|
|
310
|
+
}
|
|
216
311
|
}
|
|
217
312
|
async listModels() {
|
|
218
313
|
const page = await this.client.models.list();
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAUA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAS3B;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAyB;IACxD,aAAa,EAAE,IAAI;IACnB,iBAAiB,EAAE,IAAI;IACvB,uBAAuB,EAAE,IAAI;IAC7B,cAAc,EAAE,IAAI;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EACN,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,GACnB,MAAM,YAAY,CAAA;AACnB,OAAO,MAAM,MAAM,QAAQ,CAAA;AAS3B;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAyB;IACxD,aAAa,EAAE,IAAI;IACnB,iBAAiB,EAAE,IAAI;IACvB,uBAAuB,EAAE,IAAI;IAC7B,cAAc,EAAE,IAAI;IACpB,iBAAiB,EAAE,IAAI;CACvB,CAAA;AAMD,SAAS,eAAe,CAAC,MAA6C;IACrE,QAAQ,MAAM,EAAE,CAAC;QAChB,KAAK,QAAQ;YACZ,OAAO,QAAQ,CAAA;QAChB,KAAK,YAAY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;SACvB,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,WAAW;QAChB,IAAI,CAAC;YACJ,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA;YAC/B,OAAO,IAAI,CAAA;QACZ,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,KAAK,CAAA;QACb,CAAC;IACF,CAAC;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strict-schema.d.ts","sourceRoot":"","sources":["../src/strict-schema.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strict-schema.js","sourceRoot":"","sources":["../src/strict-schema.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@namzu/openai",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "OpenAI LLM provider for @namzu/sdk via the official `openai` npm SDK. Chat Completions API with streaming + tool-use.",
|
|
5
5
|
"license": "FSL-1.1-MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -37,14 +37,14 @@
|
|
|
37
37
|
"openai": "^6.0.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@namzu/sdk": ">=1.
|
|
40
|
+
"@namzu/sdk": ">=1.3.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@biomejs/biome": "^1.9.4",
|
|
44
44
|
"@types/node": "^22.19.17",
|
|
45
45
|
"typescript": "^5.5.0",
|
|
46
|
-
"vitest": "^2.
|
|
47
|
-
"@namzu/sdk": "^
|
|
46
|
+
"vitest": "^3.2.6",
|
|
47
|
+
"@namzu/sdk": "^3.0.0"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "tsc --build",
|