@veryfront/ext-llm-openai 0.1.1281 → 0.1.1283-rc.24946
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/esm/extensions/ext-llm-openai/src/openai-provider.d.ts.map +1 -1
- package/esm/extensions/ext-llm-openai/src/openai-provider.js +20 -9
- package/esm/extensions/ext-llm-openai/src/openai-responses-request-builder.d.ts.map +1 -1
- package/esm/extensions/ext-llm-openai/src/openai-responses-request-builder.js +107 -8
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-provider.d.ts","sourceRoot":"","sources":["../../../../src/extensions/ext-llm-openai/src/openai-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,2BAA2B,EAC5B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,kBAAkB,EAQlB,aAAa,EACb,UAAU,EAEV,iBAAiB,
|
|
1
|
+
{"version":3,"file":"openai-provider.d.ts","sourceRoot":"","sources":["../../../../src/extensions/ext-llm-openai/src/openai-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,2BAA2B,EAC5B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,kBAAkB,EAQlB,aAAa,EACb,UAAU,EAEV,iBAAiB,EAEjB,aAAa,EACb,uBAAuB,EACvB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EASpB,+BAA+B,EAEhC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEL,KAAK,6BAA6B,EAClC,KAAK,+BAA+B,EACrC,MAAM,kCAAkC,CAAC;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* @module extensions/ext-llm-openai/openai-provider
|
|
9
9
|
*/
|
|
10
|
-
import { buildProviderError, createOpenAIRequestInit, createWarningCollector, DEFAULT_PROVIDER_STREAM_HEADERS_TIMEOUT_MS, DEFAULT_PROVIDER_STREAM_TOTAL_HEADERS_BUDGET_MS, getOpenAIChatCompletionsUrl, getOpenAIEmbeddingUrl, getOpenAIResponsesUrl, isNumberArray, mergeUsage, notifyProviderRequestRetry, parseRetryAfterMs, ProviderError, ProviderOverloadedError, ProviderQuotaError, ProviderRateLimitError, ProviderRequestError, readGatewayBillingMode, readGatewayUsageCosts, readRecord, requestJson, requestStream, stringifyJsonValue, TOOL_INPUT_PENDING_THRESHOLD_MS, waitForProviderStreamRetry, } from "veryfront/provider/shared";
|
|
10
|
+
import { buildProviderError, createOpenAIRequestInit, createWarningCollector, DEFAULT_PROVIDER_STREAM_HEADERS_TIMEOUT_MS, DEFAULT_PROVIDER_STREAM_TOTAL_HEADERS_BUDGET_MS, getOpenAIChatCompletionsUrl, getOpenAIEmbeddingUrl, getOpenAIResponsesUrl, isNumberArray, mergeUsage, notifyProviderRequestRetry, parseRetryAfterMs, promptHasDocumentInput, ProviderError, ProviderOverloadedError, ProviderQuotaError, ProviderRateLimitError, ProviderRequestError, readGatewayBillingMode, readGatewayUsageCosts, readRecord, requestJson, requestStream, routesOpenAIDocumentInputToResponses, stringifyJsonValue, TOOL_INPUT_PENDING_THRESHOLD_MS, waitForProviderStreamRetry, } from "veryfront/provider/shared";
|
|
11
11
|
import { buildOpenAIChatRequest, } from "./openai-chat-request-builder.js";
|
|
12
12
|
import { MAX_OPENAI_STREAM_TOOL_CALLS, streamOpenAICompatibleParts } from "./openai-chat-stream.js";
|
|
13
13
|
import { buildOpenAIResponsesRequest } from "./openai-responses-request-builder.js";
|
|
@@ -900,6 +900,15 @@ function requestUsesOpenAIHostedTool(optionsForRuntime) {
|
|
|
900
900
|
}
|
|
901
901
|
return resolveOpenAIWebSearchDescriptor(options.tools) !== undefined;
|
|
902
902
|
}
|
|
903
|
+
/**
|
|
904
|
+
* Non-image files need Responses; Chat Completions only carries images. Only
|
|
905
|
+
* providers that serve Responses documents move there; the rest keep Chat
|
|
906
|
+
* Completions, which rejects the file before inference.
|
|
907
|
+
*/
|
|
908
|
+
function requiresOpenAIResponses(options, documentsOnResponses) {
|
|
909
|
+
return requestUsesOpenAIHostedTool(options) ||
|
|
910
|
+
(documentsOnResponses && promptHasDocumentInput(options.prompt));
|
|
911
|
+
}
|
|
903
912
|
function createOpenAIChatCompletionsOnlyRuntime(chatRuntime, hostedToolReason) {
|
|
904
913
|
function assertHostedToolsSupported(options) {
|
|
905
914
|
if (requestUsesOpenAIHostedTool(options)) {
|
|
@@ -919,19 +928,21 @@ function createOpenAIChatCompletionsOnlyRuntime(chatRuntime, hostedToolReason) {
|
|
|
919
928
|
},
|
|
920
929
|
};
|
|
921
930
|
}
|
|
922
|
-
function createOpenAIAdaptiveModelRuntime(chatRuntime, responsesRuntime) {
|
|
931
|
+
function createOpenAIAdaptiveModelRuntime(chatRuntime, responsesRuntime, documentsOnResponses) {
|
|
923
932
|
return {
|
|
924
933
|
...chatRuntime,
|
|
925
934
|
openAITransport: "auto",
|
|
926
|
-
|
|
927
|
-
|
|
935
|
+
openAIResponsesDocumentInput: documentsOnResponses,
|
|
936
|
+
// Async, so a request the selected runtime rejects up front still rejects.
|
|
937
|
+
async doGenerate(optionsForRuntime) {
|
|
938
|
+
return await (requiresOpenAIResponses(optionsForRuntime, documentsOnResponses)
|
|
928
939
|
? responsesRuntime.doGenerate(optionsForRuntime)
|
|
929
|
-
: chatRuntime.doGenerate(optionsForRuntime);
|
|
940
|
+
: chatRuntime.doGenerate(optionsForRuntime));
|
|
930
941
|
},
|
|
931
|
-
doStream(optionsForRuntime) {
|
|
932
|
-
return
|
|
942
|
+
async doStream(optionsForRuntime) {
|
|
943
|
+
return await (requiresOpenAIResponses(optionsForRuntime, documentsOnResponses)
|
|
933
944
|
? responsesRuntime.doStream(optionsForRuntime)
|
|
934
|
-
: chatRuntime.doStream(optionsForRuntime);
|
|
945
|
+
: chatRuntime.doStream(optionsForRuntime));
|
|
935
946
|
},
|
|
936
947
|
};
|
|
937
948
|
}
|
|
@@ -1007,7 +1018,7 @@ export class OpenAIProvider {
|
|
|
1007
1018
|
if (transport === "chat-completions") {
|
|
1008
1019
|
return createOpenAIChatCompletionsOnlyRuntime(chatRuntime, getOpenAIChatCompletionsOnlyReason(config));
|
|
1009
1020
|
}
|
|
1010
|
-
return createOpenAIAdaptiveModelRuntime(chatRuntime, responsesRuntime);
|
|
1021
|
+
return createOpenAIAdaptiveModelRuntime(chatRuntime, responsesRuntime, routesOpenAIDocumentInputToResponses(providerName, config.baseURL));
|
|
1011
1022
|
}
|
|
1012
1023
|
createEmbedding(modelId, config) {
|
|
1013
1024
|
return createOpenAIEmbeddingRuntime({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-responses-request-builder.d.ts","sourceRoot":"","sources":["../../../../src/extensions/ext-llm-openai/src/openai-responses-request-builder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"openai-responses-request-builder.d.ts","sourceRoot":"","sources":["../../../../src/extensions/ext-llm-openai/src/openai-responses-request-builder.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,kCAAkC,CAAC;AAyBxF,MAAM,MAAM,wBAAwB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE/D,MAAM,MAAM,sBAAsB,GAAG;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,wBAAwB,EAAE,CAAC;IAClC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CA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yToolArguments, stringifyToolResultValue, unwrapToolInputSchema, } from "veryfront/provider/shared";
|
|
1
|
+
import { fileInputBaseName, isImageFileInput, jsonValuesEqual, readInlineFileData, readRemoteFileUrl, stringifyToolArguments, stringifyToolResultValue, unsupportedFileInputError, unwrapToolInputSchema, } from "veryfront/provider/shared";
|
|
2
2
|
import { rejectsOpenAISamplingParams, resolveOpenAIReasoningConfig, shouldRequestOpenAIReasoningSummary, } from "./openai-reasoning-models.js";
|
|
3
3
|
import { defineOpenAIProviderOptions, readOpenAIProviderOptions, } from "./openai-provider-options.js";
|
|
4
4
|
import { isBoundedOpenAIStreamString, MAX_OPENAI_STREAM_TOOL_NAME_BYTES, } from "./openai-stream-metadata.js";
|
|
@@ -259,6 +259,93 @@ function toOpenAIResponsesInput(prompt) {
|
|
|
259
259
|
input,
|
|
260
260
|
};
|
|
261
261
|
}
|
|
262
|
+
const INLINE_FILE_EXTENSIONS = {
|
|
263
|
+
"application/json": "json",
|
|
264
|
+
"application/pdf": "pdf",
|
|
265
|
+
"text/csv": "csv",
|
|
266
|
+
"text/html": "html",
|
|
267
|
+
"text/markdown": "md",
|
|
268
|
+
"text/plain": "txt",
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* Inline document types Responses reads, besides `text/*` and `+json`/`+xml`
|
|
272
|
+
* types. From OpenAI's file input table, plus common aliases. Other types,
|
|
273
|
+
* such as archives, fail before inference.
|
|
274
|
+
*/
|
|
275
|
+
const RESPONSES_DOCUMENT_TYPES = new Set([
|
|
276
|
+
"application/pdf",
|
|
277
|
+
"application/msword",
|
|
278
|
+
"application/rtf",
|
|
279
|
+
"application/vnd.ms-excel",
|
|
280
|
+
"application/vnd.ms-powerpoint",
|
|
281
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
282
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
283
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
284
|
+
"application/vnd.oasis.opendocument.text",
|
|
285
|
+
"application/vnd.apple.pages",
|
|
286
|
+
"application/vnd.apple.keynote",
|
|
287
|
+
"application/vnd.apple.iwork",
|
|
288
|
+
"application/vnd.google-apps.document",
|
|
289
|
+
"application/vnd.google-apps.spreadsheet",
|
|
290
|
+
"application/vnd.google-apps.presentation",
|
|
291
|
+
"application/csv",
|
|
292
|
+
"application/x-iif",
|
|
293
|
+
"application/json",
|
|
294
|
+
"application/json5",
|
|
295
|
+
"application/x-json5",
|
|
296
|
+
"application/x-ndjson",
|
|
297
|
+
"application/xml",
|
|
298
|
+
"application/yaml",
|
|
299
|
+
"application/x-yaml",
|
|
300
|
+
"application/toml",
|
|
301
|
+
"application/x-toml",
|
|
302
|
+
"application/graphql",
|
|
303
|
+
"application/x-graphql",
|
|
304
|
+
"application/javascript",
|
|
305
|
+
"application/x-javascript",
|
|
306
|
+
"application/typescript",
|
|
307
|
+
"application/x-python",
|
|
308
|
+
"application/x-sh",
|
|
309
|
+
"application/x-bash",
|
|
310
|
+
"application/x-awk",
|
|
311
|
+
"application/x-sql",
|
|
312
|
+
"application/x-scala",
|
|
313
|
+
"application/x-rust",
|
|
314
|
+
"application/x-powershell",
|
|
315
|
+
"application/x-patch",
|
|
316
|
+
"application/x-php",
|
|
317
|
+
"application/x-httpd-php",
|
|
318
|
+
"application/x-httpd-php-source",
|
|
319
|
+
"application/x-protobuf",
|
|
320
|
+
"application/x-terraform",
|
|
321
|
+
"application/x-subrip",
|
|
322
|
+
"message/rfc822",
|
|
323
|
+
]);
|
|
324
|
+
function isResponsesDocumentType(mediaType) {
|
|
325
|
+
return mediaType.startsWith("text/") || /\+(json|xml)$/.test(mediaType) ||
|
|
326
|
+
RESPONSES_DOCUMENT_TYPES.has(mediaType);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Build an inline `input_file`. OpenAI infers the file type from the filename
|
|
330
|
+
* extension, so a filename without one needs a MIME type we can name.
|
|
331
|
+
*/
|
|
332
|
+
function toOpenAIResponsesInlineFile(part, data) {
|
|
333
|
+
const mediaType = part.mediaType.toLowerCase();
|
|
334
|
+
if (!isResponsesDocumentType(mediaType)) {
|
|
335
|
+
throw unsupportedFileInputError("OpenAI Responses", part, "Send a document such as PDF, text, code, a spreadsheet, or an office document.");
|
|
336
|
+
}
|
|
337
|
+
const extension = INLINE_FILE_EXTENSIONS[mediaType];
|
|
338
|
+
const name = fileInputBaseName(part.filename) ?? "file";
|
|
339
|
+
const hasExtension = /.\.[^.]+$/.test(name);
|
|
340
|
+
if (!hasExtension && !extension) {
|
|
341
|
+
throw unsupportedFileInputError("OpenAI Responses", part, "Set a filename with an extension, for example with fileFromBytes.");
|
|
342
|
+
}
|
|
343
|
+
return {
|
|
344
|
+
type: "input_file",
|
|
345
|
+
file_data: `data:${mediaType};base64,${data}`,
|
|
346
|
+
filename: hasExtension ? name : `${name}.${extension}`,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
262
349
|
function toOpenAIResponsesUserContent(parts) {
|
|
263
350
|
const content = [];
|
|
264
351
|
for (const part of parts) {
|
|
@@ -268,15 +355,27 @@ function toOpenAIResponsesUserContent(parts) {
|
|
|
268
355
|
}
|
|
269
356
|
continue;
|
|
270
357
|
}
|
|
271
|
-
if (part
|
|
272
|
-
|
|
358
|
+
if (isImageFileInput(part)) {
|
|
359
|
+
// Inline data is validated; any other image URL must be remote.
|
|
360
|
+
const imageUrl = readInlineFileData(part) === undefined
|
|
361
|
+
? readRemoteFileUrl("OpenAI Responses", part)
|
|
362
|
+
: part.url;
|
|
363
|
+
content.push({ type: "input_image", image_url: imageUrl, detail: "auto" });
|
|
273
364
|
continue;
|
|
274
365
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
366
|
+
// Responses file inputs are documents; audio and video use other input shapes.
|
|
367
|
+
if (/^(audio|video)\//i.test(part.mediaType)) {
|
|
368
|
+
throw unsupportedFileInputError("OpenAI Responses", part, "Send a document such as PDF, text, or a spreadsheet.");
|
|
369
|
+
}
|
|
370
|
+
const data = readInlineFileData(part);
|
|
371
|
+
const filename = fileInputBaseName(part.filename);
|
|
372
|
+
content.push(data === undefined
|
|
373
|
+
? {
|
|
374
|
+
type: "input_file",
|
|
375
|
+
file_url: readRemoteFileUrl("OpenAI Responses", part),
|
|
376
|
+
...(filename ? { filename } : {}),
|
|
377
|
+
}
|
|
378
|
+
: toOpenAIResponsesInlineFile(part, data));
|
|
280
379
|
}
|
|
281
380
|
return content;
|
|
282
381
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veryfront/ext-llm-openai",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1283-rc.24946",
|
|
4
4
|
"description": "Veryfront first-party extension package for ext-llm-openai",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"veryfront",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"capabilities": []
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"veryfront": "^0.1.
|
|
48
|
+
"veryfront": "^0.1.1283-rc.24946"
|
|
49
49
|
},
|
|
50
50
|
"type": "module",
|
|
51
51
|
"types": "./esm/extensions/ext-llm-openai/src/index.d.ts",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"NOTICE",
|
|
56
56
|
"README.md"
|
|
57
57
|
],
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "820ec8782f7b9e3d0c3543668013c2e252730ff6"
|
|
59
59
|
}
|