Commit 3bed78b
committed
refactor(openai-base, ai-utils, ai-openai, ai-grok): address PR #409 review feedback
- Eliminate `toCompatibleConfig` casts: `OpenAIClientConfig`/`GrokClientConfig`
extend `OpenAICompatibleClientConfig` directly; ai-grok keeps a
`withGrokDefaults()` helper for its xAI baseURL default.
- Fix tool-call streaming bugs:
- chat-completions-text: track `emittedAnyToolCallEnd` at outer scope so a
`tool_calls` finish_reason without a started/ended pair downgrades to `stop`.
- responses-text: guard `function_call_arguments.delta` with
`metadata?.started` to match the `.done` handler.
- Schema converter: `originalRequired` is optional and falls back to
`schema.required`; adapters now pass the unmodified array (not `|| []`)
so root-level required fields are no longer silently widened to `null`.
- Forward request options: shared `extractRequestOptions` helper threads
`headers`/`signal` from `Request | RequestInit` into both Chat Completions
and Responses SDK calls without per-call casts.
- Restore logger calls dropped during the refactor: `logger.request` before
every SDK call (image/summarize/transcription/tts/video/responses-text/
chat-completions-text), `logger.provider` per-chunk in both streaming
adapters, and try/catch + `logger.errors` around `summarize`,
`summarizeStream`, and `createVideoJob`.
- Move base64 helpers into `@tanstack/ai-utils` (`arrayBufferToBase64`,
`base64ToArrayBuffer`) with `Uint8Array.toBase64`/`fromBase64` fast paths
and `Buffer`/`atob`/`btoa` fallbacks; remove the per-adapter copies.
- Add `warnIfLargeMediaBuffer` in video.ts to surface base64-encoding-an-
unbounded-blob OOM risks on Workers/Lambda.
- Replace `client as any` in video.ts with a typed `getVideosClient()`
accessor; drop the arbitrary 1-10 cap in base `validateNumberOfImages`.
- Delete dead code: `openai-base/src/types/message-metadata.ts`,
`provider-options.ts`, and the unused `defineModelMeta` in ai-utils.
- Brand-via-base: every ai-openai tool factory now delegates to its
`@tanstack/openai-base` counterpart and brands the result, removing ten
duplicate function bodies.
- `satisfies` instead of `as` for the structured-output response narrow.
- Add `@types/node` dev dep on ai-utils so `process` typechecks.
- Tests: new `media-adapters.test.ts` (image / summarize / transcription /
tts / video) in openai-base, new `base64.test.ts` (incl. 1.5 MiB
roundtrip) in ai-utils.
All test suites green: ai-utils 18, openai-base 71, ai-groq 17,
ai-openai 131, ai-grok 53. `test:types`, `test:eslint`, and `build`
clean for every affected package.1 parent d0b318d commit 3bed78b
41 files changed
Lines changed: 831 additions & 565 deletions
File tree
- packages/typescript
- ai-grok/src
- adapters
- utils
- ai-openai/src
- adapters
- tools
- utils
- ai-utils
- src
- model-meta
- tests
- openai-base
- src
- adapters
- types
- utils
- tests
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
5 | | - | |
6 | | - | |
7 | | - | |
| 4 | + | |
8 | 5 | | |
9 | 6 | | |
10 | 7 | | |
| |||
21 | 18 | | |
22 | 19 | | |
23 | 20 | | |
24 | | - | |
25 | | - | |
| 21 | + | |
| 22 | + | |
26 | 23 | | |
27 | | - | |
| 24 | + | |
28 | 25 | | |
29 | 26 | | |
30 | 27 | | |
31 | 28 | | |
32 | 29 | | |
33 | | - | |
| 30 | + | |
34 | 31 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
| |||
36 | 35 | | |
37 | 36 | | |
38 | 37 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
| 38 | + | |
49 | 39 | | |
50 | 40 | | |
51 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
| 92 | + | |
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
| 102 | + | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
104 | 107 | | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
| 108 | + | |
114 | 109 | | |
115 | 110 | | |
116 | 111 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
0 commit comments