@vybestack/llxprt-code-core 0.6.2 → 0.7.0-nightly.251207.a6190e71e

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.
Files changed (92) hide show
  1. package/dist/src/auth/precedence.js +9 -10
  2. package/dist/src/auth/precedence.js.map +1 -1
  3. package/dist/src/auth/types.d.ts +6 -6
  4. package/dist/src/core/geminiChat.d.ts +8 -0
  5. package/dist/src/core/geminiChat.js +63 -5
  6. package/dist/src/core/geminiChat.js.map +1 -1
  7. package/dist/src/core/turn.js +12 -8
  8. package/dist/src/core/turn.js.map +1 -1
  9. package/dist/src/ide/ide-client.js +4 -2
  10. package/dist/src/ide/ide-client.js.map +1 -1
  11. package/dist/src/index.d.ts +1 -0
  12. package/dist/src/index.js +1 -0
  13. package/dist/src/index.js.map +1 -1
  14. package/dist/src/parsers/TextToolCallParser.d.ts +0 -15
  15. package/dist/src/parsers/TextToolCallParser.js +21 -5
  16. package/dist/src/parsers/TextToolCallParser.js.map +1 -1
  17. package/dist/src/providers/BaseProvider.d.ts +3 -0
  18. package/dist/src/providers/BaseProvider.js +11 -0
  19. package/dist/src/providers/BaseProvider.js.map +1 -1
  20. package/dist/src/providers/IProvider.d.ts +3 -0
  21. package/dist/src/providers/ProviderManager.js +6 -0
  22. package/dist/src/providers/ProviderManager.js.map +1 -1
  23. package/dist/src/providers/anthropic/AnthropicProvider.d.ts +0 -1
  24. package/dist/src/providers/anthropic/AnthropicProvider.js +233 -22
  25. package/dist/src/providers/anthropic/AnthropicProvider.js.map +1 -1
  26. package/dist/src/providers/anthropic/schemaConverter.d.ts +63 -0
  27. package/dist/src/providers/anthropic/schemaConverter.js +189 -0
  28. package/dist/src/providers/anthropic/schemaConverter.js.map +1 -0
  29. package/dist/src/providers/gemini/GeminiProvider.js +108 -11
  30. package/dist/src/providers/gemini/GeminiProvider.js.map +1 -1
  31. package/dist/src/providers/gemini/thoughtSignatures.d.ts +51 -0
  32. package/dist/src/providers/gemini/thoughtSignatures.js +189 -0
  33. package/dist/src/providers/gemini/thoughtSignatures.js.map +1 -0
  34. package/dist/src/providers/openai/OpenAIProvider.d.ts +78 -1
  35. package/dist/src/providers/openai/OpenAIProvider.js +1159 -190
  36. package/dist/src/providers/openai/OpenAIProvider.js.map +1 -1
  37. package/dist/src/providers/openai/ToolCallNormalizer.d.ts +6 -0
  38. package/dist/src/providers/openai/ToolCallNormalizer.js +16 -2
  39. package/dist/src/providers/openai/ToolCallNormalizer.js.map +1 -1
  40. package/dist/src/providers/openai/schemaConverter.d.ts +67 -0
  41. package/dist/src/providers/openai/schemaConverter.js +191 -0
  42. package/dist/src/providers/openai/schemaConverter.js.map +1 -0
  43. package/dist/src/providers/openai-responses/OpenAIResponsesProvider.d.ts +0 -4
  44. package/dist/src/providers/openai-responses/OpenAIResponsesProvider.js +3 -75
  45. package/dist/src/providers/openai-responses/OpenAIResponsesProvider.js.map +1 -1
  46. package/dist/src/providers/openai-responses/schemaConverter.d.ts +65 -0
  47. package/dist/src/providers/openai-responses/schemaConverter.js +195 -0
  48. package/dist/src/providers/openai-responses/schemaConverter.js.map +1 -0
  49. package/dist/src/providers/openai-vercel/OpenAIVercelProvider.d.ts +146 -0
  50. package/dist/src/providers/openai-vercel/OpenAIVercelProvider.js +1177 -0
  51. package/dist/src/providers/openai-vercel/OpenAIVercelProvider.js.map +1 -0
  52. package/dist/src/providers/openai-vercel/errors.d.ts +46 -0
  53. package/dist/src/providers/openai-vercel/errors.js +137 -0
  54. package/dist/src/providers/openai-vercel/errors.js.map +1 -0
  55. package/dist/src/providers/openai-vercel/index.d.ts +22 -0
  56. package/dist/src/providers/openai-vercel/index.js +23 -0
  57. package/dist/src/providers/openai-vercel/index.js.map +1 -0
  58. package/dist/src/providers/openai-vercel/messageConversion.d.ts +36 -0
  59. package/dist/src/providers/openai-vercel/messageConversion.js +410 -0
  60. package/dist/src/providers/openai-vercel/messageConversion.js.map +1 -0
  61. package/dist/src/providers/openai-vercel/schemaConverter.d.ts +66 -0
  62. package/dist/src/providers/openai-vercel/schemaConverter.js +191 -0
  63. package/dist/src/providers/openai-vercel/schemaConverter.js.map +1 -0
  64. package/dist/src/providers/openai-vercel/toolIdUtils.d.ts +33 -0
  65. package/dist/src/providers/openai-vercel/toolIdUtils.js +117 -0
  66. package/dist/src/providers/openai-vercel/toolIdUtils.js.map +1 -0
  67. package/dist/src/providers/reasoning/reasoningUtils.d.ts +43 -0
  68. package/dist/src/providers/reasoning/reasoningUtils.js +92 -0
  69. package/dist/src/providers/reasoning/reasoningUtils.js.map +1 -0
  70. package/dist/src/providers/utils/localEndpoint.js +6 -2
  71. package/dist/src/providers/utils/localEndpoint.js.map +1 -1
  72. package/dist/src/runtime/AgentRuntimeContext.d.ts +27 -0
  73. package/dist/src/runtime/AgentRuntimeContext.js.map +1 -1
  74. package/dist/src/runtime/createAgentRuntimeContext.js +27 -1
  75. package/dist/src/runtime/createAgentRuntimeContext.js.map +1 -1
  76. package/dist/src/services/history/IContent.d.ts +6 -0
  77. package/dist/src/services/history/IContent.js.map +1 -1
  78. package/dist/src/settings/types.d.ts +1 -1
  79. package/dist/src/tools/IToolFormatter.d.ts +1 -1
  80. package/dist/src/tools/ToolFormatter.js +14 -2
  81. package/dist/src/tools/ToolFormatter.js.map +1 -1
  82. package/dist/src/tools/ToolIdStrategy.d.ts +72 -0
  83. package/dist/src/tools/ToolIdStrategy.js +107 -0
  84. package/dist/src/tools/ToolIdStrategy.js.map +1 -0
  85. package/dist/src/tools/todo-schemas.d.ts +4 -4
  86. package/dist/src/utils/filesearch/ignore.js +3 -2
  87. package/dist/src/utils/filesearch/ignore.js.map +1 -1
  88. package/dist/src/utils/gitIgnoreParser.js +2 -1
  89. package/dist/src/utils/gitIgnoreParser.js.map +1 -1
  90. package/dist/src/utils/schemaValidator.js +41 -6
  91. package/dist/src/utils/schemaValidator.js.map +1 -1
  92. package/package.json +3 -1
@@ -0,0 +1,410 @@
1
+ /**
2
+ * Copyright 2025 Vybestack LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { normalizeToHistoryToolId, normalizeToOpenAIToolId, } from './toolIdUtils.js';
17
+ import { buildToolResponsePayload, EMPTY_TOOL_RESULT_PLACEHOLDER, } from '../utils/toolResponsePayload.js';
18
+ function inferMediaEncoding(imageData) {
19
+ const defaultResult = { encoding: 'url', mimeType: 'image/*' };
20
+ if (imageData.startsWith('data:image/') && imageData.includes(';base64,')) {
21
+ const mimeMatch = imageData.slice('data:'.length).match(/^([^;]+);base64,/);
22
+ const mimeType = mimeMatch?.[1] ?? 'image/*';
23
+ return { encoding: 'base64', mimeType };
24
+ }
25
+ if (imageData.startsWith('data:')) {
26
+ return defaultResult;
27
+ }
28
+ if (imageData.startsWith('http://') || imageData.startsWith('https://')) {
29
+ return defaultResult;
30
+ }
31
+ // Fallback: treat as base64 when it is not a recognizable URL
32
+ return { encoding: 'base64', mimeType: 'image/*' };
33
+ }
34
+ /**
35
+ * Convert IContent array to Vercel AI SDK CoreMessage array
36
+ * @param contents - The contents to convert
37
+ * @param toolIdMapper - Optional mapper for tool IDs (for Kimi K2 format)
38
+ */
39
+ export function convertToVercelMessages(contents, toolIdMapper) {
40
+ const messages = [];
41
+ // Helper to resolve tool call IDs based on format
42
+ const resolveToolCallId = (block) => {
43
+ if (toolIdMapper) {
44
+ return toolIdMapper.resolveToolCallId(block);
45
+ }
46
+ return normalizeToOpenAIToolId(block.id);
47
+ };
48
+ // Helper to resolve tool response IDs based on format
49
+ const resolveToolResponseId = (block) => {
50
+ if (toolIdMapper) {
51
+ return toolIdMapper.resolveToolResponseId(block);
52
+ }
53
+ return normalizeToOpenAIToolId(block.callId || '');
54
+ };
55
+ for (const content of contents) {
56
+ const metadata = content.metadata;
57
+ const metadataRole = metadata?.role;
58
+ if (metadataRole === 'system' ||
59
+ content.speaker === 'system') {
60
+ // Convert system messages
61
+ const textBlocks = content.blocks.filter((b) => b.type === 'text');
62
+ const text = textBlocks
63
+ .map((b) => b.text)
64
+ .filter((t) => t.length > 0)
65
+ .join('\n');
66
+ if (text) {
67
+ messages.push({
68
+ role: 'system',
69
+ content: text,
70
+ });
71
+ }
72
+ }
73
+ else if (content.speaker === 'human') {
74
+ // Convert human messages to user messages
75
+ const textBlocks = content.blocks.filter((b) => b.type === 'text');
76
+ const mediaBlocks = content.blocks.filter((b) => b.type === 'media');
77
+ const hasImages = mediaBlocks.length > 0;
78
+ const text = textBlocks
79
+ .map((b) => b.text)
80
+ .filter((t) => t.length > 0)
81
+ .join('\n');
82
+ if (hasImages) {
83
+ const parts = [];
84
+ if (text) {
85
+ parts.push({ type: 'text', text });
86
+ }
87
+ for (const media of mediaBlocks) {
88
+ parts.push({
89
+ type: 'image',
90
+ image: normalizeImageData(media),
91
+ });
92
+ }
93
+ if (parts.length > 0) {
94
+ messages.push({
95
+ role: 'user',
96
+ content: parts,
97
+ });
98
+ }
99
+ }
100
+ else if (text) {
101
+ messages.push({
102
+ role: 'user',
103
+ content: text,
104
+ });
105
+ }
106
+ }
107
+ else if (content.speaker === 'ai') {
108
+ // Convert AI messages to assistant messages
109
+ const textBlocks = content.blocks.filter((b) => b.type === 'text');
110
+ const toolCallBlocks = content.blocks.filter((b) => b.type === 'tool_call');
111
+ const text = textBlocks
112
+ .map((b) => b.text)
113
+ .filter((t) => t.length > 0)
114
+ .join('\n');
115
+ if (toolCallBlocks.length > 0) {
116
+ const contentParts = [];
117
+ if (text) {
118
+ contentParts.push({ type: 'text', text });
119
+ }
120
+ for (const block of toolCallBlocks) {
121
+ const toolCall = block;
122
+ const input = toolCall.input !== undefined ? toolCall.input : block.parameters;
123
+ contentParts.push({
124
+ type: 'tool-call',
125
+ toolCallId: resolveToolCallId(block),
126
+ toolName: block.name,
127
+ input,
128
+ });
129
+ }
130
+ messages.push({
131
+ role: 'assistant',
132
+ content: contentParts,
133
+ });
134
+ }
135
+ else if (text) {
136
+ messages.push({
137
+ role: 'assistant',
138
+ content: text,
139
+ });
140
+ }
141
+ }
142
+ else if (content.speaker === 'tool') {
143
+ // Convert tool messages to tool result messages
144
+ const toolResponseBlocks = content.blocks.filter((b) => b.type === 'tool_response');
145
+ if (toolResponseBlocks.length > 0) {
146
+ const toolContent = toolResponseBlocks.map((block) => {
147
+ const payload = buildToolResponsePayload(block);
148
+ const extBlock = block;
149
+ return {
150
+ type: 'tool-result',
151
+ toolCallId: resolveToolResponseId(block),
152
+ toolName: extBlock.name || extBlock.toolName || '',
153
+ output: {
154
+ type: 'text',
155
+ value: payload.result,
156
+ },
157
+ };
158
+ });
159
+ const toolMessage = {
160
+ role: 'tool',
161
+ content: toolContent,
162
+ };
163
+ messages.push(toolMessage);
164
+ }
165
+ }
166
+ }
167
+ return messages;
168
+ }
169
+ /**
170
+ * Convert Vercel AI SDK CoreMessage array back to IContent array
171
+ */
172
+ export function convertFromVercelMessages(messages) {
173
+ const contents = [];
174
+ for (const message of messages) {
175
+ if (message.role === 'user') {
176
+ // Convert user messages to human messages
177
+ if (Array.isArray(message.content)) {
178
+ const blocks = [];
179
+ for (const part of message.content) {
180
+ const partType = part.type;
181
+ if (typeof part === 'string') {
182
+ if (part) {
183
+ blocks.push({ type: 'text', text: part });
184
+ }
185
+ continue;
186
+ }
187
+ if (partType === 'text') {
188
+ const text = part.text;
189
+ if (text) {
190
+ blocks.push({ type: 'text', text });
191
+ }
192
+ }
193
+ else if (partType === 'image') {
194
+ const imageData = part.image ??
195
+ part.url;
196
+ if (imageData) {
197
+ const { encoding, mimeType } = inferMediaEncoding(imageData);
198
+ blocks.push({
199
+ type: 'media',
200
+ data: imageData,
201
+ encoding,
202
+ mimeType,
203
+ });
204
+ }
205
+ }
206
+ }
207
+ if (blocks.length > 0) {
208
+ contents.push({
209
+ speaker: 'human',
210
+ blocks,
211
+ });
212
+ }
213
+ }
214
+ else {
215
+ const text = typeof message.content === 'string' ? message.content : '';
216
+ if (text) {
217
+ contents.push({
218
+ speaker: 'human',
219
+ blocks: [
220
+ {
221
+ type: 'text',
222
+ text,
223
+ },
224
+ ],
225
+ });
226
+ }
227
+ }
228
+ }
229
+ else if (message.role === 'assistant') {
230
+ // Convert assistant messages to AI messages
231
+ const blocks = [];
232
+ if (typeof message.content === 'string') {
233
+ if (message.content) {
234
+ blocks.push({
235
+ type: 'text',
236
+ text: message.content,
237
+ });
238
+ }
239
+ }
240
+ else if (Array.isArray(message.content)) {
241
+ for (const part of message.content) {
242
+ const partType = part.type;
243
+ if (typeof part === 'string') {
244
+ if (part) {
245
+ blocks.push({
246
+ type: 'text',
247
+ text: part,
248
+ });
249
+ }
250
+ }
251
+ else if (partType === 'text') {
252
+ const text = part.text;
253
+ if (text) {
254
+ blocks.push({
255
+ type: 'text',
256
+ text,
257
+ });
258
+ }
259
+ }
260
+ else if (partType === 'image') {
261
+ const imageData = part.image ??
262
+ part.url;
263
+ if (imageData) {
264
+ const { encoding, mimeType } = inferMediaEncoding(imageData);
265
+ blocks.push({
266
+ type: 'media',
267
+ data: imageData,
268
+ encoding,
269
+ mimeType,
270
+ });
271
+ }
272
+ }
273
+ else if (partType === 'tool-call') {
274
+ const toolPart = part;
275
+ const parameters = toolPart.input !== undefined ? toolPart.input : toolPart.args;
276
+ const toolCallBlock = {
277
+ type: 'tool_call',
278
+ id: normalizeToHistoryToolId(toolPart.toolCallId),
279
+ name: toolPart.toolName,
280
+ parameters,
281
+ };
282
+ if (toolPart.input !== undefined) {
283
+ toolCallBlock.input = toolPart.input;
284
+ }
285
+ blocks.push(toolCallBlock);
286
+ }
287
+ }
288
+ }
289
+ // Handle toolInvocations if present (extended message format)
290
+ const extendedMessage = message;
291
+ if (extendedMessage.toolInvocations &&
292
+ extendedMessage.toolInvocations.length > 0) {
293
+ for (const invocation of extendedMessage.toolInvocations) {
294
+ if (invocation.state === 'call') {
295
+ blocks.push({
296
+ type: 'tool_call',
297
+ id: normalizeToHistoryToolId(invocation.toolCallId),
298
+ name: invocation.toolName,
299
+ parameters: invocation.args,
300
+ });
301
+ }
302
+ }
303
+ }
304
+ if (blocks.length > 0) {
305
+ contents.push({
306
+ speaker: 'ai',
307
+ blocks,
308
+ });
309
+ }
310
+ }
311
+ else if (message.role === 'tool') {
312
+ // Convert tool messages to tool response messages
313
+ const blocks = [];
314
+ for (const part of message.content) {
315
+ if (part.type === 'tool-result') {
316
+ const output = part.output;
317
+ const isErrorOutput = output &&
318
+ typeof output === 'object' &&
319
+ 'type' in output &&
320
+ typeof output.type === 'string' &&
321
+ output.type?.startsWith('error');
322
+ const resultValue = output &&
323
+ typeof output === 'object' &&
324
+ 'value' in output
325
+ ? output.value
326
+ : output;
327
+ let parsedResult = resultValue;
328
+ if (typeof resultValue === 'string') {
329
+ if (resultValue === EMPTY_TOOL_RESULT_PLACEHOLDER) {
330
+ parsedResult = undefined;
331
+ }
332
+ else {
333
+ try {
334
+ parsedResult = JSON.parse(resultValue);
335
+ }
336
+ catch {
337
+ parsedResult = resultValue;
338
+ }
339
+ }
340
+ }
341
+ const toolResponseBlock = {
342
+ type: 'tool_response',
343
+ callId: normalizeToHistoryToolId(part.toolCallId),
344
+ toolName: part.toolName,
345
+ result: parsedResult,
346
+ };
347
+ if (isErrorOutput) {
348
+ toolResponseBlock.isError = true;
349
+ if (typeof resultValue === 'string') {
350
+ toolResponseBlock.error = resultValue;
351
+ }
352
+ }
353
+ blocks.push(toolResponseBlock);
354
+ }
355
+ }
356
+ if (blocks.length > 0) {
357
+ contents.push({
358
+ speaker: 'tool',
359
+ blocks,
360
+ });
361
+ }
362
+ }
363
+ else if (message.role === 'system') {
364
+ // Convert system messages
365
+ const systemContent = message.content;
366
+ const text = typeof systemContent === 'string'
367
+ ? systemContent
368
+ : Array.isArray(systemContent)
369
+ ? systemContent
370
+ .map((part) => {
371
+ if (typeof part === 'string')
372
+ return part;
373
+ if (part.type === 'text')
374
+ return part.text || '';
375
+ return '';
376
+ })
377
+ .join('\n')
378
+ : '';
379
+ if (text) {
380
+ const systemContentObj = {
381
+ speaker: 'ai',
382
+ blocks: [
383
+ {
384
+ type: 'text',
385
+ text,
386
+ },
387
+ ],
388
+ metadata: {
389
+ role: 'system',
390
+ },
391
+ };
392
+ contents.push(systemContentObj);
393
+ }
394
+ }
395
+ }
396
+ return contents;
397
+ }
398
+ function normalizeImageData(media) {
399
+ if (media.data.startsWith('data:')) {
400
+ return media.data;
401
+ }
402
+ if (media.encoding === 'url') {
403
+ return media.data;
404
+ }
405
+ const prefix = media.mimeType
406
+ ? `data:${media.mimeType};base64,`
407
+ : 'data:image/*;base64,';
408
+ return `${prefix}${media.data}`;
409
+ }
410
+ //# sourceMappingURL=messageConversion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messageConversion.js","sourceRoot":"","sources":["../../../../src/providers/openai-vercel/messageConversion.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAyBH,OAAO,EACL,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,wBAAwB,EACxB,6BAA6B,GAC9B,MAAM,iCAAiC,CAAC;AAGzC,SAAS,kBAAkB,CAAC,SAAiB;IAI3C,MAAM,aAAa,GAAG,EAAE,QAAQ,EAAE,KAAc,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;IAExE,IAAI,SAAS,CAAC,UAAU,CAAC,aAAa,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QAC1E,MAAM,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;QAC5E,MAAM,QAA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EAAE,MAAM;4BACZ,IAAI;yBACL;qBACF;oBACD,QAAQ,EAAE;wBACR,IAAI,EAAE,QAAQ;qBACf;iBACF,CAAC;gBACF,QAAQ,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;YAClC,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAiB;IAC3C,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACnC,OAAO,KAAK,CAAC,IAAI,CAAC;IACpB,CAAC;IAED,IAAI,KAAK,CAAC,QAAQ,KAAK,KAAK,EAAE,CAAC;QAC7B,OAAO,KAAK,CAAC,IAAI,CAAC;IACpB,CAAC;IAED,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ;QAC3B,CAAC,CAAC,QAAQ,KAAK,CAAC,QAAQ,UAAU;QAClC,CAAC,CAAC,sBAAsB,CAAC;IAC3B,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;AAClC,CAAC"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Vybestack LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * OpenAI function parameter schema format
8
+ */
9
+ export interface OpenAIFunctionParameters {
10
+ type: 'object';
11
+ properties: Record<string, OpenAIPropertySchema>;
12
+ required: string[];
13
+ additionalProperties?: boolean;
14
+ [key: string]: unknown;
15
+ }
16
+ /**
17
+ * OpenAI property schema (recursive for nested objects/arrays)
18
+ */
19
+ export interface OpenAIPropertySchema {
20
+ type: string;
21
+ description?: string;
22
+ enum?: string[];
23
+ items?: OpenAIPropertySchema;
24
+ properties?: Record<string, OpenAIPropertySchema>;
25
+ required?: string[];
26
+ minimum?: number;
27
+ maximum?: number;
28
+ minLength?: number;
29
+ maxLength?: number;
30
+ default?: unknown;
31
+ }
32
+ /**
33
+ * OpenAI tool format for function calling (Vercel AI SDK compatible)
34
+ */
35
+ export interface OpenAIVercelTool {
36
+ type: 'function';
37
+ function: {
38
+ name: string;
39
+ description?: string;
40
+ parameters?: OpenAIFunctionParameters;
41
+ };
42
+ }
43
+ /**
44
+ * Input format from Gemini-style tool declarations
45
+ */
46
+ interface GeminiToolDeclaration {
47
+ name: string;
48
+ description?: string;
49
+ parametersJsonSchema?: unknown;
50
+ }
51
+ /**
52
+ * Convert a Gemini-style schema to OpenAI JSON Schema format.
53
+ * Handles:
54
+ * - Uppercase type enums → lowercase strings
55
+ * - Missing required fields → adds empty array
56
+ * - String numeric values → proper numbers
57
+ * - Recursive property/items conversion
58
+ */
59
+ export declare function convertSchemaToOpenAI(schema: unknown): OpenAIFunctionParameters;
60
+ /**
61
+ * Convert an array of Gemini-style tool declarations to OpenAI Vercel format
62
+ */
63
+ export declare function convertToolsToOpenAIVercel(geminiTools?: Array<{
64
+ functionDeclarations?: GeminiToolDeclaration[];
65
+ }>): OpenAIVercelTool[] | undefined;
66
+ export {};
@@ -0,0 +1,191 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Vybestack LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Schema converter for OpenAI Vercel provider.
8
+ * Converts tool schemas to OpenAI-compatible JSON Schema format for use with Vercel AI SDK.
9
+ *
10
+ * Key requirements for OpenAI function calling:
11
+ * - type: must be lowercase string ("object", "string", etc.)
12
+ * - required: must always be present as an array (even if empty)
13
+ * - properties: object describing each parameter
14
+ */
15
+ import { DebugLogger } from '../../debug/DebugLogger.js';
16
+ const logger = new DebugLogger('llxprt:provider:openai-vercel:schema');
17
+ /**
18
+ * Convert a Gemini-style schema to OpenAI JSON Schema format.
19
+ * Handles:
20
+ * - Uppercase type enums → lowercase strings
21
+ * - Missing required fields → adds empty array
22
+ * - String numeric values → proper numbers
23
+ * - Recursive property/items conversion
24
+ */
25
+ export function convertSchemaToOpenAI(schema) {
26
+ if (!schema || typeof schema !== 'object') {
27
+ return {
28
+ type: 'object',
29
+ properties: {},
30
+ required: [],
31
+ };
32
+ }
33
+ const input = schema;
34
+ const result = {
35
+ type: 'object',
36
+ properties: {},
37
+ required: [],
38
+ };
39
+ // Convert properties recursively
40
+ if (input.properties && typeof input.properties === 'object') {
41
+ result.properties = convertProperties(input.properties);
42
+ }
43
+ // Ensure required is always an array - CRITICAL for K2 and other models
44
+ if (Array.isArray(input.required)) {
45
+ result.required = input.required.map((r) => String(r));
46
+ }
47
+ else {
48
+ // OpenAI requires the 'required' field to be present, even if empty
49
+ result.required = [];
50
+ }
51
+ // Handle additionalProperties if present
52
+ if (typeof input.additionalProperties === 'boolean') {
53
+ result.additionalProperties = input.additionalProperties;
54
+ }
55
+ return result;
56
+ }
57
+ /**
58
+ * Convert properties object recursively
59
+ */
60
+ function convertProperties(properties) {
61
+ const result = {};
62
+ for (const [key, value] of Object.entries(properties)) {
63
+ if (value && typeof value === 'object') {
64
+ result[key] = convertPropertySchema(value);
65
+ }
66
+ }
67
+ return result;
68
+ }
69
+ /**
70
+ * Convert a single property schema
71
+ */
72
+ function convertPropertySchema(prop) {
73
+ const result = {
74
+ type: normalizeType(prop.type),
75
+ };
76
+ // Copy description
77
+ if (typeof prop.description === 'string') {
78
+ result.description = prop.description;
79
+ }
80
+ // Handle enum values
81
+ if (Array.isArray(prop.enum)) {
82
+ result.enum = prop.enum.map((v) => String(v));
83
+ }
84
+ // Handle array items
85
+ if (prop.items) {
86
+ if (Array.isArray(prop.items)) {
87
+ // Tuple type - use first item as representative
88
+ result.items = convertPropertySchema(prop.items[0]);
89
+ }
90
+ else {
91
+ result.items = convertPropertySchema(prop.items);
92
+ }
93
+ }
94
+ // Handle nested object properties
95
+ if (prop.properties && typeof prop.properties === 'object') {
96
+ result.properties = convertProperties(prop.properties);
97
+ // Nested objects should also have required array
98
+ if (Array.isArray(prop.required)) {
99
+ result.required = prop.required.map((r) => String(r));
100
+ }
101
+ else if (result.type === 'object') {
102
+ result.required = [];
103
+ }
104
+ }
105
+ // Handle numeric constraints (convert strings to numbers if needed)
106
+ if (prop.minimum !== undefined) {
107
+ result.minimum = toNumber(prop.minimum);
108
+ }
109
+ if (prop.maximum !== undefined) {
110
+ result.maximum = toNumber(prop.maximum);
111
+ }
112
+ if (prop.minLength !== undefined) {
113
+ result.minLength = toNumber(prop.minLength);
114
+ }
115
+ if (prop.maxLength !== undefined) {
116
+ result.maxLength = toNumber(prop.maxLength);
117
+ }
118
+ // Handle default value
119
+ if (prop.default !== undefined) {
120
+ result.default = prop.default;
121
+ }
122
+ return result;
123
+ }
124
+ /**
125
+ * Normalize type value to lowercase string.
126
+ * Handles Gemini's uppercase Type enum (e.g., "OBJECT" → "object")
127
+ */
128
+ function normalizeType(type) {
129
+ if (typeof type === 'string') {
130
+ return type.toLowerCase();
131
+ }
132
+ if (typeof type === 'number') {
133
+ // Gemini Type enum values
134
+ const typeMap = {
135
+ 1: 'string',
136
+ 2: 'number',
137
+ 3: 'integer',
138
+ 4: 'boolean',
139
+ 5: 'array',
140
+ 6: 'object',
141
+ };
142
+ return typeMap[type] || 'string';
143
+ }
144
+ return 'string';
145
+ }
146
+ /**
147
+ * Convert value to number, handling strings
148
+ */
149
+ function toNumber(value) {
150
+ if (typeof value === 'number') {
151
+ return value;
152
+ }
153
+ if (typeof value === 'string') {
154
+ const num = parseFloat(value);
155
+ return isNaN(num) ? undefined : num;
156
+ }
157
+ return undefined;
158
+ }
159
+ /**
160
+ * Convert an array of Gemini-style tool declarations to OpenAI Vercel format
161
+ */
162
+ export function convertToolsToOpenAIVercel(geminiTools) {
163
+ if (!geminiTools || geminiTools.length === 0) {
164
+ return undefined;
165
+ }
166
+ const openAITools = [];
167
+ for (const toolGroup of geminiTools) {
168
+ if (!toolGroup.functionDeclarations) {
169
+ continue;
170
+ }
171
+ for (const decl of toolGroup.functionDeclarations) {
172
+ const parameters = convertSchemaToOpenAI(decl.parametersJsonSchema);
173
+ openAITools.push({
174
+ type: 'function',
175
+ function: {
176
+ name: decl.name,
177
+ description: decl.description,
178
+ parameters,
179
+ },
180
+ });
181
+ }
182
+ }
183
+ if (logger.enabled && openAITools.length > 0) {
184
+ logger.debug(() => `Converted ${openAITools.length} tools to OpenAI Vercel format`, {
185
+ toolNames: openAITools.map((t) => t.function.name),
186
+ firstToolHasRequired: openAITools[0]?.function.parameters?.required !== undefined,
187
+ });
188
+ }
189
+ return openAITools.length > 0 ? openAITools : undefined;
190
+ }
191
+ //# sourceMappingURL=schemaConverter.js.map