mirror of
https://github.com/Heretek-AI/opencode.git
synced 2026-10-12 02:04:25 +00:00
297 lines
13 KiB
Diff
297 lines
13 KiB
Diff
diff --git a/dist/index.d.mts b/dist/index.d.mts
|
|
index e9c9916..b2cefd4 100644
|
|
--- a/dist/index.d.mts
|
|
+++ b/dist/index.d.mts
|
|
@@ -5,13 +5,7 @@ import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
|
|
type XaiChatModelId = 'grok-4.7' | 'grok-4.6' | 'grok-4.5' | 'grok-4.3' | 'grok-4.20-0309-reasoning' | 'grok-4.20-0309-non-reasoning' | 'grok-4.20-multi-agent-0309' | 'grok-build-0.1' | (string & {});
|
|
declare const xaiLanguageModelChatOptions: z.ZodObject<{
|
|
- reasoningEffort: z.ZodOptional<z.ZodEnum<{
|
|
- none: "none";
|
|
- low: "low";
|
|
- medium: "medium";
|
|
- high: "high";
|
|
- xhigh: "xhigh";
|
|
- }>>;
|
|
+ reasoningEffort: z.ZodOptional<z.ZodString>;
|
|
logprobs: z.ZodOptional<z.ZodBoolean>;
|
|
topLogprobs: z.ZodOptional<z.ZodNumber>;
|
|
serviceTier: z.ZodOptional<z.ZodEnum<{
|
|
@@ -82,13 +76,7 @@ type XaiResponsesModelId = 'grok-4.7' | 'grok-4.6' | 'grok-4.5' | 'grok-4.3' | '
|
|
* @see https://docs.x.ai/docs/api-reference#create-new-response
|
|
*/
|
|
declare const xaiLanguageModelResponsesOptions: z.ZodObject<{
|
|
- reasoningEffort: z.ZodOptional<z.ZodEnum<{
|
|
- none: "none";
|
|
- low: "low";
|
|
- medium: "medium";
|
|
- high: "high";
|
|
- xhigh: "xhigh";
|
|
- }>>;
|
|
+ reasoningEffort: z.ZodOptional<z.ZodString>;
|
|
logprobs: z.ZodOptional<z.ZodBoolean>;
|
|
topLogprobs: z.ZodOptional<z.ZodNumber>;
|
|
serviceTier: z.ZodOptional<z.ZodEnum<{
|
|
@@ -97,6 +85,7 @@ declare const xaiLanguageModelResponsesOptions: z.ZodObject<{
|
|
}>>;
|
|
store: z.ZodOptional<z.ZodBoolean>;
|
|
previousResponseId: z.ZodOptional<z.ZodString>;
|
|
+ promptCacheKey: z.ZodOptional<z.ZodString>;
|
|
include: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<{
|
|
"file_search_call.results": "file_search_call.results";
|
|
}>>>>;
|
|
diff --git a/dist/index.d.ts b/dist/index.d.ts
|
|
index e9c9916..b2cefd4 100644
|
|
--- a/dist/index.d.ts
|
|
+++ b/dist/index.d.ts
|
|
@@ -5,13 +5,7 @@ import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
|
|
type XaiChatModelId = 'grok-4.7' | 'grok-4.6' | 'grok-4.5' | 'grok-4.3' | 'grok-4.20-0309-reasoning' | 'grok-4.20-0309-non-reasoning' | 'grok-4.20-multi-agent-0309' | 'grok-build-0.1' | (string & {});
|
|
declare const xaiLanguageModelChatOptions: z.ZodObject<{
|
|
- reasoningEffort: z.ZodOptional<z.ZodEnum<{
|
|
- none: "none";
|
|
- low: "low";
|
|
- medium: "medium";
|
|
- high: "high";
|
|
- xhigh: "xhigh";
|
|
- }>>;
|
|
+ reasoningEffort: z.ZodOptional<z.ZodString>;
|
|
logprobs: z.ZodOptional<z.ZodBoolean>;
|
|
topLogprobs: z.ZodOptional<z.ZodNumber>;
|
|
serviceTier: z.ZodOptional<z.ZodEnum<{
|
|
@@ -82,13 +76,7 @@ type XaiResponsesModelId = 'grok-4.7' | 'grok-4.6' | 'grok-4.5' | 'grok-4.3' | '
|
|
* @see https://docs.x.ai/docs/api-reference#create-new-response
|
|
*/
|
|
declare const xaiLanguageModelResponsesOptions: z.ZodObject<{
|
|
- reasoningEffort: z.ZodOptional<z.ZodEnum<{
|
|
- none: "none";
|
|
- low: "low";
|
|
- medium: "medium";
|
|
- high: "high";
|
|
- xhigh: "xhigh";
|
|
- }>>;
|
|
+ reasoningEffort: z.ZodOptional<z.ZodString>;
|
|
logprobs: z.ZodOptional<z.ZodBoolean>;
|
|
topLogprobs: z.ZodOptional<z.ZodNumber>;
|
|
serviceTier: z.ZodOptional<z.ZodEnum<{
|
|
@@ -97,6 +85,7 @@ declare const xaiLanguageModelResponsesOptions: z.ZodObject<{
|
|
}>>;
|
|
store: z.ZodOptional<z.ZodBoolean>;
|
|
previousResponseId: z.ZodOptional<z.ZodString>;
|
|
+ promptCacheKey: z.ZodOptional<z.ZodString>;
|
|
include: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<{
|
|
"file_search_call.results": "file_search_call.results";
|
|
}>>>>;
|
|
diff --git a/dist/index.js b/dist/index.js
|
|
index d5eb865..13ad9ca 100644
|
|
--- a/dist/index.js
|
|
+++ b/dist/index.js
|
|
@@ -274,7 +274,7 @@ var searchSourceSchema = import_v42.z.discriminatedUnion("type", [
|
|
rssSourceSchema
|
|
]);
|
|
var xaiLanguageModelChatOptions = import_v42.z.object({
|
|
- reasoningEffort: import_v42.z.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
|
|
+ reasoningEffort: import_v42.z.string().optional(),
|
|
logprobs: import_v42.z.boolean().optional(),
|
|
topLogprobs: import_v42.z.number().int().min(0).max(8).optional(),
|
|
serviceTier: import_v42.z.enum(["default", "priority"]).optional(),
|
|
@@ -1162,6 +1162,14 @@ async function convertToXaiResponsesInput({
|
|
type: "input_file",
|
|
file_url: block.data.toString()
|
|
});
|
|
+ } else if (block.mediaType === "application/pdf") {
|
|
+ contentParts.push({
|
|
+ type: "input_file",
|
|
+ ...typeof block.data === "string" && block.data.startsWith("file-") ? { file_id: block.data } : {
|
|
+ filename: block.filename ?? "file",
|
|
+ file_data: `data:application/pdf;base64,${(0, import_provider_utils5.convertToBase64)(block.data)}`
|
|
+ }
|
|
+ });
|
|
} else {
|
|
throw new import_provider4.UnsupportedFunctionalityError({
|
|
functionality: `file part media type ${block.mediaType} as inline data (xAI Responses requires a URL or a Files API reference for non-image files)`
|
|
@@ -1846,7 +1854,7 @@ var xaiLanguageModelResponsesOptions = import_v48.z.object({
|
|
* models support reasoning effort; see xAI's docs for the values each model
|
|
* accepts. `xhigh` is currently only supported by `grok-4.6`.
|
|
*/
|
|
- reasoningEffort: import_v48.z.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
|
|
+ reasoningEffort: import_v48.z.string().optional(),
|
|
logprobs: import_v48.z.boolean().optional(),
|
|
topLogprobs: import_v48.z.number().int().min(0).max(8).optional(),
|
|
serviceTier: import_v48.z.enum(["default", "priority"]).optional(),
|
|
@@ -1861,6 +1869,10 @@ var xaiLanguageModelResponsesOptions = import_v48.z.object({
|
|
* The ID of the previous response from the model.
|
|
*/
|
|
previousResponseId: import_v48.z.string().optional(),
|
|
+ /**
|
|
+ * A stable key used by xAI to improve prompt cache routing.
|
|
+ */
|
|
+ promptCacheKey: import_v48.z.string().optional(),
|
|
/**
|
|
* Specify additional output data to include in the model response.
|
|
* Example values: 'file_search_call.results'.
|
|
@@ -2288,6 +2300,9 @@ var XaiResponsesLanguageModel = class {
|
|
...options.previousResponseId != null && {
|
|
previous_response_id: options.previousResponseId
|
|
},
|
|
+ ...options.promptCacheKey != null && {
|
|
+ prompt_cache_key: options.promptCacheKey
|
|
+ },
|
|
...options.serviceTier != null && {
|
|
service_tier: options.serviceTier
|
|
}
|
|
diff --git a/dist/index.mjs b/dist/index.mjs
|
|
index 1b24818..afb67cc 100644
|
|
--- a/dist/index.mjs
|
|
+++ b/dist/index.mjs
|
|
@@ -258,7 +258,7 @@ var searchSourceSchema = z2.discriminatedUnion("type", [
|
|
rssSourceSchema
|
|
]);
|
|
var xaiLanguageModelChatOptions = z2.object({
|
|
- reasoningEffort: z2.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
|
|
+ reasoningEffort: z2.string().optional(),
|
|
logprobs: z2.boolean().optional(),
|
|
topLogprobs: z2.number().int().min(0).max(8).optional(),
|
|
serviceTier: z2.enum(["default", "priority"]).optional(),
|
|
@@ -1165,6 +1165,14 @@ async function convertToXaiResponsesInput({
|
|
type: "input_file",
|
|
file_url: block.data.toString()
|
|
});
|
|
+ } else if (block.mediaType === "application/pdf") {
|
|
+ contentParts.push({
|
|
+ type: "input_file",
|
|
+ ...typeof block.data === "string" && block.data.startsWith("file-") ? { file_id: block.data } : {
|
|
+ filename: block.filename ?? "file",
|
|
+ file_data: `data:application/pdf;base64,${convertToBase642(block.data)}`
|
|
+ }
|
|
+ });
|
|
} else {
|
|
throw new UnsupportedFunctionalityError3({
|
|
functionality: `file part media type ${block.mediaType} as inline data (xAI Responses requires a URL or a Files API reference for non-image files)`
|
|
@@ -1849,7 +1857,7 @@ var xaiLanguageModelResponsesOptions = z8.object({
|
|
* models support reasoning effort; see xAI's docs for the values each model
|
|
* accepts. `xhigh` is currently only supported by `grok-4.6`.
|
|
*/
|
|
- reasoningEffort: z8.enum(["none", "low", "medium", "high", "xhigh"]).optional(),
|
|
+ reasoningEffort: z8.string().optional(),
|
|
logprobs: z8.boolean().optional(),
|
|
topLogprobs: z8.number().int().min(0).max(8).optional(),
|
|
serviceTier: z8.enum(["default", "priority"]).optional(),
|
|
@@ -1864,6 +1872,10 @@ var xaiLanguageModelResponsesOptions = z8.object({
|
|
* The ID of the previous response from the model.
|
|
*/
|
|
previousResponseId: z8.string().optional(),
|
|
+ /**
|
|
+ * A stable key used by xAI to improve prompt cache routing.
|
|
+ */
|
|
+ promptCacheKey: z8.string().optional(),
|
|
/**
|
|
* Specify additional output data to include in the model response.
|
|
* Example values: 'file_search_call.results'.
|
|
@@ -2309,6 +2321,9 @@ var XaiResponsesLanguageModel = class {
|
|
...options.previousResponseId != null && {
|
|
previous_response_id: options.previousResponseId
|
|
},
|
|
+ ...options.promptCacheKey != null && {
|
|
+ prompt_cache_key: options.promptCacheKey
|
|
+ },
|
|
...options.serviceTier != null && {
|
|
service_tier: options.serviceTier
|
|
}
|
|
diff --git a/src/responses/convert-to-xai-responses-input.ts b/src/responses/convert-to-xai-responses-input.ts
|
|
index 21af0cd..9b477ef 100644
|
|
--- a/src/responses/convert-to-xai-responses-input.ts
|
|
+++ b/src/responses/convert-to-xai-responses-input.ts
|
|
@@ -78,6 +78,17 @@ export async function convertToXaiResponsesInput({
|
|
type: 'input_file',
|
|
file_url: block.data.toString(),
|
|
});
|
|
+ } else if (block.mediaType === 'application/pdf') {
|
|
+ contentParts.push({
|
|
+ type: 'input_file',
|
|
+ ...(typeof block.data === 'string' &&
|
|
+ block.data.startsWith('file-')
|
|
+ ? { file_id: block.data }
|
|
+ : {
|
|
+ filename: block.filename ?? 'file',
|
|
+ file_data: `data:application/pdf;base64,${convertToBase64(block.data)}`,
|
|
+ }),
|
|
+ });
|
|
} else {
|
|
throw new UnsupportedFunctionalityError({
|
|
functionality: `file part media type ${block.mediaType} as inline data (xAI Responses requires a URL or a Files API reference for non-image files)`,
|
|
diff --git a/src/responses/xai-responses-api.ts b/src/responses/xai-responses-api.ts
|
|
index 0bc0f91..aa3857a 100644
|
|
--- a/src/responses/xai-responses-api.ts
|
|
+++ b/src/responses/xai-responses-api.ts
|
|
@@ -31,7 +31,13 @@ export type XaiResponsesUserMessageContentPart =
|
|
image_url: string;
|
|
detail?: 'low' | 'high' | 'auto';
|
|
}
|
|
- | { type: 'input_file'; file_url: string };
|
|
+ | {
|
|
+ type: 'input_file';
|
|
+ file_url?: string;
|
|
+ file_id?: string;
|
|
+ file_data?: string;
|
|
+ filename?: string;
|
|
+ };
|
|
|
|
export type XaiResponsesUserMessage = {
|
|
role: 'user';
|
|
diff --git a/src/responses/xai-responses-language-model.ts b/src/responses/xai-responses-language-model.ts
|
|
index 06d6e5a..98a2d39 100644
|
|
--- a/src/responses/xai-responses-language-model.ts
|
|
+++ b/src/responses/xai-responses-language-model.ts
|
|
@@ -201,6 +201,9 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
|
|
...(options.previousResponseId != null && {
|
|
previous_response_id: options.previousResponseId,
|
|
}),
|
|
+ ...(options.promptCacheKey != null && {
|
|
+ prompt_cache_key: options.promptCacheKey,
|
|
+ }),
|
|
...(options.serviceTier != null && {
|
|
service_tier: options.serviceTier,
|
|
}),
|
|
diff --git a/src/responses/xai-responses-options.ts b/src/responses/xai-responses-options.ts
|
|
index 6d52f46..9577200 100644
|
|
--- a/src/responses/xai-responses-options.ts
|
|
+++ b/src/responses/xai-responses-options.ts
|
|
@@ -22,9 +22,7 @@ export const xaiLanguageModelResponsesOptions = z.object({
|
|
* models support reasoning effort; see xAI's docs for the values each model
|
|
* accepts. `xhigh` is currently only supported by `grok-4.6`.
|
|
*/
|
|
- reasoningEffort: z
|
|
- .enum(['none', 'low', 'medium', 'high', 'xhigh'])
|
|
- .optional(),
|
|
+ reasoningEffort: z.string().optional(),
|
|
logprobs: z.boolean().optional(),
|
|
topLogprobs: z.number().int().min(0).max(8).optional(),
|
|
serviceTier: z.enum(['default', 'priority']).optional(),
|
|
@@ -39,6 +37,10 @@ export const xaiLanguageModelResponsesOptions = z.object({
|
|
* The ID of the previous response from the model.
|
|
*/
|
|
previousResponseId: z.string().optional(),
|
|
+ /**
|
|
+ * A stable key used by xAI to improve prompt cache routing.
|
|
+ */
|
|
+ promptCacheKey: z.string().optional(),
|
|
/**
|
|
* Specify additional output data to include in the model response.
|
|
* Example values: 'file_search_call.results'.
|
|
diff --git a/src/xai-chat-options.ts b/src/xai-chat-options.ts
|
|
index f3f1237..adb6ada 100644
|
|
--- a/src/xai-chat-options.ts
|
|
+++ b/src/xai-chat-options.ts
|
|
@@ -54,9 +54,7 @@ const searchSourceSchema = z.discriminatedUnion('type', [
|
|
|
|
// xai-specific provider options
|
|
export const xaiLanguageModelChatOptions = z.object({
|
|
- reasoningEffort: z
|
|
- .enum(['none', 'low', 'medium', 'high', 'xhigh'])
|
|
- .optional(),
|
|
+ reasoningEffort: z.string().optional(),
|
|
logprobs: z.boolean().optional(),
|
|
topLogprobs: z.number().int().min(0).max(8).optional(),
|
|
|