@namzu/openai 1.1.0 → 1.1.1
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 +29 -0
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +7 -5
- package/dist/client.js.map +1 -1
- package/package.json +12 -2
- package/src/client.ts +9 -7
- package/dist/__tests__/document-input.test.d.ts +0 -2
- package/dist/__tests__/document-input.test.d.ts.map +0 -1
- package/dist/__tests__/document-input.test.js +0 -92
- package/dist/__tests__/document-input.test.js.map +0 -1
- package/dist/__tests__/error-taxonomy.test.d.ts +0 -14
- package/dist/__tests__/error-taxonomy.test.d.ts.map +0 -1
- package/dist/__tests__/error-taxonomy.test.js +0 -203
- package/dist/__tests__/error-taxonomy.test.js.map +0 -1
- package/dist/__tests__/openai.test.d.ts +0 -2
- package/dist/__tests__/openai.test.d.ts.map +0 -1
- package/dist/__tests__/openai.test.js +0 -182
- package/dist/__tests__/openai.test.js.map +0 -1
- package/dist/__tests__/reasoning-params.test.d.ts +0 -2
- package/dist/__tests__/reasoning-params.test.d.ts.map +0 -1
- package/dist/__tests__/reasoning-params.test.js +0 -61
- package/dist/__tests__/reasoning-params.test.js.map +0 -1
- package/dist/__tests__/strict-schema.test.d.ts +0 -2
- package/dist/__tests__/strict-schema.test.d.ts.map +0 -1
- package/dist/__tests__/strict-schema.test.js +0 -85
- package/dist/__tests__/strict-schema.test.js.map +0 -1
- package/src/__tests__/document-input.test.ts +0 -125
- package/src/__tests__/error-taxonomy.test.ts +0 -234
- package/src/__tests__/openai.test.ts +0 -201
- package/src/__tests__/reasoning-params.test.ts +0 -76
- package/src/__tests__/strict-schema.test.ts +0 -110
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { DuplicateProviderError, ProviderRegistry } from '@namzu/sdk';
|
|
2
|
-
import { beforeEach, describe, expect, it } from 'vitest';
|
|
3
|
-
import { toOpenAIMessages } from '../client.js';
|
|
4
|
-
import { OPENAI_CAPABILITIES, OpenAIProvider, registerOpenAI } from '../index.js';
|
|
5
|
-
// Ensure a clean slate between tests. The sdk pre-registers 'mock' on import
|
|
6
|
-
// via its sideEffects whitelist; we only need to clear 'openai' to make
|
|
7
|
-
// re-registration deterministic across tests.
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
if (ProviderRegistry.isSupported('openai')) {
|
|
10
|
-
ProviderRegistry.unregister('openai');
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
describe('@namzu/openai', () => {
|
|
14
|
-
describe('registerOpenAI()', () => {
|
|
15
|
-
it("adds 'openai' to the ProviderRegistry", () => {
|
|
16
|
-
expect(ProviderRegistry.isSupported('openai')).toBe(false);
|
|
17
|
-
registerOpenAI();
|
|
18
|
-
expect(ProviderRegistry.isSupported('openai')).toBe(true);
|
|
19
|
-
expect(ProviderRegistry.listTypes()).toContain('openai');
|
|
20
|
-
});
|
|
21
|
-
it('throws DuplicateProviderError when called twice without options', () => {
|
|
22
|
-
registerOpenAI();
|
|
23
|
-
expect(() => registerOpenAI()).toThrowError(DuplicateProviderError);
|
|
24
|
-
});
|
|
25
|
-
it('allows re-registration when { replace: true } is passed', () => {
|
|
26
|
-
registerOpenAI();
|
|
27
|
-
expect(() => registerOpenAI({ replace: true })).not.toThrow();
|
|
28
|
-
expect(ProviderRegistry.isSupported('openai')).toBe(true);
|
|
29
|
-
});
|
|
30
|
-
it('exposes capabilities through the registry after registration', () => {
|
|
31
|
-
registerOpenAI();
|
|
32
|
-
const caps = ProviderRegistry.getCapabilities('openai');
|
|
33
|
-
expect(caps).toEqual(OPENAI_CAPABILITIES);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
describe('OPENAI_CAPABILITIES', () => {
|
|
37
|
-
it('declares the expected capability flags', () => {
|
|
38
|
-
expect(OPENAI_CAPABILITIES).toEqual({
|
|
39
|
-
supportsTools: true,
|
|
40
|
-
supportsStreaming: true,
|
|
41
|
-
supportsFunctionCalling: true,
|
|
42
|
-
supportsVision: true,
|
|
43
|
-
supportsDocuments: true,
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
it('is exposed on the provider instance for runtime negotiation', () => {
|
|
47
|
-
const provider = new OpenAIProvider({ apiKey: 'test-key' });
|
|
48
|
-
expect(provider.capabilities).toEqual(OPENAI_CAPABILITIES);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
describe('ProviderRegistry.create({ type: "openai", ... })', () => {
|
|
52
|
-
it('narrows the config type via module augmentation and instantiates OpenAIProvider', () => {
|
|
53
|
-
registerOpenAI();
|
|
54
|
-
const { provider, capabilities } = ProviderRegistry.create({
|
|
55
|
-
type: 'openai',
|
|
56
|
-
apiKey: 'test-key',
|
|
57
|
-
model: 'gpt-4o-mini',
|
|
58
|
-
});
|
|
59
|
-
expect(provider).toBeInstanceOf(OpenAIProvider);
|
|
60
|
-
expect(capabilities).toEqual(OPENAI_CAPABILITIES);
|
|
61
|
-
});
|
|
62
|
-
it('throws when apiKey is missing', () => {
|
|
63
|
-
registerOpenAI();
|
|
64
|
-
expect(() => ProviderRegistry.create({
|
|
65
|
-
type: 'openai',
|
|
66
|
-
apiKey: '',
|
|
67
|
-
})).toThrowError(/API key is required/);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
describe('toOpenAIMessages image attachments', () => {
|
|
71
|
-
it('maps user-message attachments to image_url content parts with base64 data URIs', () => {
|
|
72
|
-
const messages = [
|
|
73
|
-
{
|
|
74
|
-
role: 'user',
|
|
75
|
-
content: 'what is in this image?',
|
|
76
|
-
attachments: [
|
|
77
|
-
{ data: 'aGVsbG8=', mediaType: 'image/png' },
|
|
78
|
-
{ data: 'd29ybGQ=', mediaType: 'image/jpeg' },
|
|
79
|
-
],
|
|
80
|
-
},
|
|
81
|
-
];
|
|
82
|
-
const [mapped] = toOpenAIMessages(messages);
|
|
83
|
-
expect(mapped).toEqual({
|
|
84
|
-
role: 'user',
|
|
85
|
-
content: [
|
|
86
|
-
{ type: 'text', text: 'what is in this image?' },
|
|
87
|
-
{
|
|
88
|
-
type: 'image_url',
|
|
89
|
-
image_url: { url: 'data:image/png;base64,aGVsbG8=' },
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
type: 'image_url',
|
|
93
|
-
image_url: { url: 'data:image/jpeg;base64,d29ybGQ=' },
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
it('omits the text part when the user message is empty but keeps the images', () => {
|
|
99
|
-
const messages = [
|
|
100
|
-
{
|
|
101
|
-
role: 'user',
|
|
102
|
-
content: '',
|
|
103
|
-
attachments: [{ data: 'aGVsbG8=', mediaType: 'image/webp' }],
|
|
104
|
-
},
|
|
105
|
-
];
|
|
106
|
-
const [mapped] = toOpenAIMessages(messages);
|
|
107
|
-
expect(mapped).toEqual({
|
|
108
|
-
role: 'user',
|
|
109
|
-
content: [
|
|
110
|
-
{
|
|
111
|
-
type: 'image_url',
|
|
112
|
-
image_url: { url: 'data:image/webp;base64,aGVsbG8=' },
|
|
113
|
-
},
|
|
114
|
-
],
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
it('keeps plain text-only user messages in string form (no content parts)', () => {
|
|
118
|
-
const messages = [{ role: 'user', content: 'hello' }];
|
|
119
|
-
expect(toOpenAIMessages(messages)).toEqual([{ role: 'user', content: 'hello' }]);
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
it('keeps the Namzu enforcement hint out of the OpenAI SDK request', async () => {
|
|
123
|
-
const provider = new OpenAIProvider({ apiKey: 'test-key' });
|
|
124
|
-
let requestBody;
|
|
125
|
-
provider.client = {
|
|
126
|
-
chat: {
|
|
127
|
-
completions: {
|
|
128
|
-
create: async (body) => {
|
|
129
|
-
requestBody = body;
|
|
130
|
-
return (async function* () {
|
|
131
|
-
yield {
|
|
132
|
-
id: 'msg_done',
|
|
133
|
-
choices: [{ index: 0, delta: {}, finish_reason: 'stop' }],
|
|
134
|
-
usage: {
|
|
135
|
-
prompt_tokens: 1,
|
|
136
|
-
completion_tokens: 0,
|
|
137
|
-
total_tokens: 1,
|
|
138
|
-
},
|
|
139
|
-
};
|
|
140
|
-
})();
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
};
|
|
145
|
-
const tools = [
|
|
146
|
-
{
|
|
147
|
-
type: 'function',
|
|
148
|
-
function: {
|
|
149
|
-
name: 'edit',
|
|
150
|
-
description: 'Edit',
|
|
151
|
-
parameters: { type: 'object' },
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
|
-
];
|
|
155
|
-
for await (const _chunk of provider.chatStream({
|
|
156
|
-
model: 'gpt-5',
|
|
157
|
-
messages: [{ role: 'user', content: 'edit' }],
|
|
158
|
-
tools,
|
|
159
|
-
enforceToolInputSchema: ['edit'],
|
|
160
|
-
})) {
|
|
161
|
-
// Drain the test stream.
|
|
162
|
-
}
|
|
163
|
-
// The hint is not a wire field, so it must never appear verbatim —
|
|
164
|
-
// that is what "keeps it out of the request" means.
|
|
165
|
-
expect(requestBody).not.toHaveProperty('enforceToolInputSchema');
|
|
166
|
-
// It is consumed, not ignored. This used to assert the tools went
|
|
167
|
-
// through untouched, which read as "the hint is kept out" and
|
|
168
|
-
// actually pinned "the hint does nothing".
|
|
169
|
-
expect(requestBody?.tools).toEqual([
|
|
170
|
-
{
|
|
171
|
-
type: 'function',
|
|
172
|
-
function: {
|
|
173
|
-
name: 'edit',
|
|
174
|
-
description: 'Edit',
|
|
175
|
-
parameters: { type: 'object' },
|
|
176
|
-
strict: true,
|
|
177
|
-
},
|
|
178
|
-
},
|
|
179
|
-
]);
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
//# sourceMappingURL=openai.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openai.test.js","sourceRoot":"","sources":["../../src/__tests__/openai.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,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E,IAAI,EAAE,QAAQ,EAAE;oBAC9B,MAAM,EAAE,IAAI;iBACZ;aACD;SACD,CAAC,CAAA;IACH,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reasoning-params.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/reasoning-params.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,61 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,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
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,QAAQ,CAAA;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAE5C;;;;;;;;;GASG;AAEH,MAAM,KAAK,GAAG;IACb;QACC,IAAI,EAAE,UAAmB;QACzB,QAAQ,EAAE;YACT,IAAI,EAAE,MAAM;YACZ,WAAW,EAAE,aAAa;YAC1B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE;SACxE;KACD;IACD;QACC,IAAI,EAAE,UAAmB;QACzB,QAAQ,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;KACxF;CACD,CAAA;AAMD,SAAS,QAAQ,CAAC,sBAA0C;IAC3D,OAAO,aAAa,CAAC;QACpB,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,EAAE;QACZ,KAAK,EAAE,KAAK;QACZ,GAAG,CAAC,sBAAsB,CAAC,CAAC,CAAC,EAAE,sBAAsB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACrC,CAA0C,CAAA;AACpE,CAAC;AAED,QAAQ,CAAC,uDAAuD,EAAE,GAAG,EAAE;IACtE,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;QAC1C,MAAM,KAAK,GAAG,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;QAEhC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAA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ACtB,CAA8B,CAAA;QAElE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IACpD,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACpD,MAAM,CAAC,aAAa,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"}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import type { ChatCompletionParams } from '@namzu/sdk'
|
|
2
|
-
import { describe, expect, it } from 'vitest'
|
|
3
|
-
|
|
4
|
-
import { OPENAI_CAPABILITIES, toOpenAIMessages } from '../client.js'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* This driver declared `supportsDocuments: true` and had no document
|
|
8
|
-
* branch: every attachment became an `image_url` part, so a PDF went up as
|
|
9
|
-
* `data:application/pdf;base64,...` inside an image. The capability was a
|
|
10
|
-
* claim nothing in the mapper could honour.
|
|
11
|
-
*
|
|
12
|
-
* Citations are the other half, and this wire has no way to return them.
|
|
13
|
-
* Sending the document anyway would answer the question and drop the
|
|
14
|
-
* checkability the caller asked for — silently, since an empty citation
|
|
15
|
-
* list reads as "the model cited nothing" rather than "nobody asked". So a
|
|
16
|
-
* document requesting citations is refused here rather than degraded.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
const PDF = 'JVBERi0xLjQKJSVFT0Y='
|
|
20
|
-
|
|
21
|
-
function partsFor(attachments: unknown[], content = 'summarize this') {
|
|
22
|
-
const [message] = toOpenAIMessages([
|
|
23
|
-
{ role: 'user', content, attachments },
|
|
24
|
-
] as unknown as ChatCompletionParams['messages'])
|
|
25
|
-
return message?.content as unknown as Record<string, unknown>[]
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
describe('a document attachment reaches the wire as a file', () => {
|
|
29
|
-
it('sends a file part, not an image part', async () => {
|
|
30
|
-
const parts = partsFor([{ type: 'document', data: PDF, mediaType: 'application/pdf' }])
|
|
31
|
-
|
|
32
|
-
const file = parts.find((p) => p.type === 'file')
|
|
33
|
-
expect(file?.file).toMatchObject({ file_data: `data:application/pdf;base64,${PDF}` })
|
|
34
|
-
// The bug in one assertion: it used to be an image part.
|
|
35
|
-
expect(parts.some((p) => p.type === 'image_url')).toBe(false)
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
it('keeps the prose ahead of the file', () => {
|
|
39
|
-
const parts = partsFor([{ type: 'document', data: PDF, mediaType: 'application/pdf' }])
|
|
40
|
-
|
|
41
|
-
expect(parts[0]).toEqual({ type: 'text', text: 'summarize this' })
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
it('carries the filename when one was given', () => {
|
|
45
|
-
const parts = partsFor([
|
|
46
|
-
{ type: 'document', data: PDF, mediaType: 'application/pdf', name: 'lease.pdf' },
|
|
47
|
-
])
|
|
48
|
-
|
|
49
|
-
expect((parts.find((p) => p.type === 'file')?.file as { filename?: string }).filename).toBe(
|
|
50
|
-
'lease.pdf',
|
|
51
|
-
)
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
it('omits the filename when none was given', () => {
|
|
55
|
-
const parts = partsFor([{ type: 'document', data: PDF, mediaType: 'application/pdf' }])
|
|
56
|
-
|
|
57
|
-
expect(parts.find((p) => p.type === 'file')?.file).not.toHaveProperty('filename')
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
it('still maps an image attachment as an image', () => {
|
|
61
|
-
const parts = partsFor([{ type: 'image', data: 'AAAA', mediaType: 'image/png' }])
|
|
62
|
-
|
|
63
|
-
expect(parts.find((p) => p.type === 'image_url')?.image_url).toEqual({
|
|
64
|
-
url: 'data:image/png;base64,AAAA',
|
|
65
|
-
})
|
|
66
|
-
expect(parts.some((p) => p.type === 'file')).toBe(false)
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
it('carries both kinds in one message, in the order given', () => {
|
|
70
|
-
const parts = partsFor([
|
|
71
|
-
{ type: 'document', data: PDF, mediaType: 'application/pdf' },
|
|
72
|
-
{ type: 'image', data: 'AAAA', mediaType: 'image/png' },
|
|
73
|
-
])
|
|
74
|
-
|
|
75
|
-
expect(parts.map((p) => p.type)).toEqual(['text', 'file', 'image_url'])
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
it('leaves a plain text message as a string', () => {
|
|
79
|
-
const [message] = toOpenAIMessages([
|
|
80
|
-
{ role: 'user', content: 'no attachments here' },
|
|
81
|
-
] as ChatCompletionParams['messages'])
|
|
82
|
-
|
|
83
|
-
expect(message?.content).toBe('no attachments here')
|
|
84
|
-
})
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
describe('a document asking for citations is refused, not answered without them', () => {
|
|
88
|
-
it('throws rather than sending it', () => {
|
|
89
|
-
expect(() =>
|
|
90
|
-
partsFor([{ type: 'document', data: PDF, mediaType: 'application/pdf', citations: true }]),
|
|
91
|
-
).toThrow(/citations/i)
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
it('names the document, so the caller knows which one to change', () => {
|
|
95
|
-
expect(() =>
|
|
96
|
-
partsFor([
|
|
97
|
-
{
|
|
98
|
-
type: 'document',
|
|
99
|
-
data: PDF,
|
|
100
|
-
mediaType: 'application/pdf',
|
|
101
|
-
name: 'lease.pdf',
|
|
102
|
-
citations: true,
|
|
103
|
-
},
|
|
104
|
-
]),
|
|
105
|
-
).toThrow(/lease\.pdf/)
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
it('says what to do instead', () => {
|
|
109
|
-
expect(() =>
|
|
110
|
-
partsFor([{ type: 'document', data: PDF, mediaType: 'application/pdf', citations: true }]),
|
|
111
|
-
).toThrow(/Drop `citations`/)
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
it('accepts the same document without the request', () => {
|
|
115
|
-
expect(() =>
|
|
116
|
-
partsFor([{ type: 'document', data: PDF, mediaType: 'application/pdf', citations: false }]),
|
|
117
|
-
).not.toThrow()
|
|
118
|
-
})
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
describe('the capability claim matches the mapper', () => {
|
|
122
|
-
it('declares document support, which is now true', () => {
|
|
123
|
-
expect(OPENAI_CAPABILITIES.supportsDocuments).toBe(true)
|
|
124
|
-
})
|
|
125
|
-
})
|