@merit-systems/echo-react-sdk 1.0.39-test.536e84b4.0 → 1.0.39-test.e7bb7c63.0
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/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1161 -224
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -13460,7 +13460,7 @@ var webSearch_20250305 = (args = {}) => {
|
|
|
13460
13460
|
function isWebSearchTool(tool2) {
|
|
13461
13461
|
return typeof tool2 === "object" && tool2 !== null && "type" in tool2 && tool2.type === "web_search_20250305";
|
|
13462
13462
|
}
|
|
13463
|
-
function prepareTools$
|
|
13463
|
+
function prepareTools$3({
|
|
13464
13464
|
tools,
|
|
13465
13465
|
toolChoice,
|
|
13466
13466
|
disableParallelToolUse
|
|
@@ -14318,7 +14318,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
14318
14318
|
toolChoice: anthropicToolChoice,
|
|
14319
14319
|
toolWarnings,
|
|
14320
14320
|
betas: toolsBetas
|
|
14321
|
-
} = prepareTools$
|
|
14321
|
+
} = prepareTools$3(
|
|
14322
14322
|
jsonResponseTool != null ? {
|
|
14323
14323
|
tools: [jsonResponseTool],
|
|
14324
14324
|
toolChoice: { type: "tool", toolName: jsonResponseTool.name },
|
|
@@ -15858,7 +15858,7 @@ var googleGenerativeAIProviderOptions = object({
|
|
|
15858
15858
|
*/
|
|
15859
15859
|
labels: record(string$1(), string$1()).optional()
|
|
15860
15860
|
});
|
|
15861
|
-
function prepareTools$
|
|
15861
|
+
function prepareTools$2({
|
|
15862
15862
|
tools,
|
|
15863
15863
|
toolChoice,
|
|
15864
15864
|
modelId
|
|
@@ -16124,7 +16124,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
16124
16124
|
tools: googleTools2,
|
|
16125
16125
|
toolConfig: googleToolConfig,
|
|
16126
16126
|
toolWarnings
|
|
16127
|
-
} = prepareTools$
|
|
16127
|
+
} = prepareTools$2({
|
|
16128
16128
|
tools,
|
|
16129
16129
|
toolChoice,
|
|
16130
16130
|
modelId: this.modelId
|
|
@@ -16602,7 +16602,7 @@ var safetyRatingSchema = object({
|
|
|
16602
16602
|
severityScore: number$1().nullish(),
|
|
16603
16603
|
blocked: boolean$1().nullish()
|
|
16604
16604
|
});
|
|
16605
|
-
var usageSchema$
|
|
16605
|
+
var usageSchema$2 = object({
|
|
16606
16606
|
cachedContentTokenCount: number$1().nullish(),
|
|
16607
16607
|
thoughtsTokenCount: number$1().nullish(),
|
|
16608
16608
|
promptTokenCount: number$1().nullish(),
|
|
@@ -16619,7 +16619,7 @@ var responseSchema = object({
|
|
|
16619
16619
|
urlContextMetadata: urlContextMetadataSchema.nullish()
|
|
16620
16620
|
})
|
|
16621
16621
|
),
|
|
16622
|
-
usageMetadata: usageSchema$
|
|
16622
|
+
usageMetadata: usageSchema$2.nullish()
|
|
16623
16623
|
});
|
|
16624
16624
|
var chunkSchema = object({
|
|
16625
16625
|
candidates: array(
|
|
@@ -16631,7 +16631,7 @@ var chunkSchema = object({
|
|
|
16631
16631
|
urlContextMetadata: urlContextMetadataSchema.nullish()
|
|
16632
16632
|
})
|
|
16633
16633
|
).nullish(),
|
|
16634
|
-
usageMetadata: usageSchema$
|
|
16634
|
+
usageMetadata: usageSchema$2.nullish()
|
|
16635
16635
|
});
|
|
16636
16636
|
var codeExecution = createProviderDefinedToolFactoryWithOutputSchema({
|
|
16637
16637
|
id: "google.code_execution",
|
|
@@ -17484,7 +17484,7 @@ function convertToGroqChatMessages(prompt) {
|
|
|
17484
17484
|
}
|
|
17485
17485
|
return messages;
|
|
17486
17486
|
}
|
|
17487
|
-
function getResponseMetadata$
|
|
17487
|
+
function getResponseMetadata$2({
|
|
17488
17488
|
id: id2,
|
|
17489
17489
|
model,
|
|
17490
17490
|
created
|
|
@@ -17543,7 +17543,7 @@ function isBrowserSearchSupportedModel(modelId) {
|
|
|
17543
17543
|
function getSupportedModelsString() {
|
|
17544
17544
|
return BROWSER_SEARCH_SUPPORTED_MODELS.join(", ");
|
|
17545
17545
|
}
|
|
17546
|
-
function prepareTools({
|
|
17546
|
+
function prepareTools$1({
|
|
17547
17547
|
tools,
|
|
17548
17548
|
toolChoice,
|
|
17549
17549
|
modelId
|
|
@@ -17678,7 +17678,7 @@ var GroqChatLanguageModel = class {
|
|
|
17678
17678
|
tools: groqTools2,
|
|
17679
17679
|
toolChoice: groqToolChoice,
|
|
17680
17680
|
toolWarnings
|
|
17681
|
-
} = prepareTools({ tools, toolChoice, modelId: this.modelId });
|
|
17681
|
+
} = prepareTools$1({ tools, toolChoice, modelId: this.modelId });
|
|
17682
17682
|
return {
|
|
17683
17683
|
args: {
|
|
17684
17684
|
// model id:
|
|
@@ -17773,7 +17773,7 @@ var GroqChatLanguageModel = class {
|
|
|
17773
17773
|
totalTokens: (_g = (_f = response.usage) == null ? void 0 : _f.total_tokens) != null ? _g : void 0
|
|
17774
17774
|
},
|
|
17775
17775
|
response: {
|
|
17776
|
-
...getResponseMetadata$
|
|
17776
|
+
...getResponseMetadata$2(response),
|
|
17777
17777
|
headers: responseHeaders,
|
|
17778
17778
|
body: rawResponse
|
|
17779
17779
|
},
|
|
@@ -17835,7 +17835,7 @@ var GroqChatLanguageModel = class {
|
|
|
17835
17835
|
isFirstChunk = false;
|
|
17836
17836
|
controller.enqueue({
|
|
17837
17837
|
type: "response-metadata",
|
|
17838
|
-
...getResponseMetadata$
|
|
17838
|
+
...getResponseMetadata$2(value)
|
|
17839
17839
|
});
|
|
17840
17840
|
}
|
|
17841
17841
|
if (((_a10 = value.x_groq) == null ? void 0 : _a10.usage) != null) {
|
|
@@ -17966,18 +17966,1077 @@ var GroqChatLanguageModel = class {
|
|
|
17966
17966
|
}
|
|
17967
17967
|
},
|
|
17968
17968
|
flush(controller) {
|
|
17969
|
-
if (isActiveReasoning) {
|
|
17970
|
-
controller.enqueue({ type: "reasoning-end", id: "reasoning-0" });
|
|
17971
|
-
}
|
|
17972
|
-
if (isActiveText) {
|
|
17973
|
-
controller.enqueue({ type: "text-end", id: "txt-0" });
|
|
17969
|
+
if (isActiveReasoning) {
|
|
17970
|
+
controller.enqueue({ type: "reasoning-end", id: "reasoning-0" });
|
|
17971
|
+
}
|
|
17972
|
+
if (isActiveText) {
|
|
17973
|
+
controller.enqueue({ type: "text-end", id: "txt-0" });
|
|
17974
|
+
}
|
|
17975
|
+
controller.enqueue({
|
|
17976
|
+
type: "finish",
|
|
17977
|
+
finishReason,
|
|
17978
|
+
usage,
|
|
17979
|
+
...{}
|
|
17980
|
+
});
|
|
17981
|
+
}
|
|
17982
|
+
})
|
|
17983
|
+
),
|
|
17984
|
+
request: { body },
|
|
17985
|
+
response: { headers: responseHeaders }
|
|
17986
|
+
};
|
|
17987
|
+
}
|
|
17988
|
+
};
|
|
17989
|
+
var groqChatResponseSchema = object({
|
|
17990
|
+
id: string$1().nullish(),
|
|
17991
|
+
created: number$1().nullish(),
|
|
17992
|
+
model: string$1().nullish(),
|
|
17993
|
+
choices: array(
|
|
17994
|
+
object({
|
|
17995
|
+
message: object({
|
|
17996
|
+
content: string$1().nullish(),
|
|
17997
|
+
reasoning: string$1().nullish(),
|
|
17998
|
+
tool_calls: array(
|
|
17999
|
+
object({
|
|
18000
|
+
id: string$1().nullish(),
|
|
18001
|
+
type: literal("function"),
|
|
18002
|
+
function: object({
|
|
18003
|
+
name: string$1(),
|
|
18004
|
+
arguments: string$1()
|
|
18005
|
+
})
|
|
18006
|
+
})
|
|
18007
|
+
).nullish()
|
|
18008
|
+
}),
|
|
18009
|
+
index: number$1(),
|
|
18010
|
+
finish_reason: string$1().nullish()
|
|
18011
|
+
})
|
|
18012
|
+
),
|
|
18013
|
+
usage: object({
|
|
18014
|
+
prompt_tokens: number$1().nullish(),
|
|
18015
|
+
completion_tokens: number$1().nullish(),
|
|
18016
|
+
total_tokens: number$1().nullish()
|
|
18017
|
+
}).nullish()
|
|
18018
|
+
});
|
|
18019
|
+
var groqChatChunkSchema = union([
|
|
18020
|
+
object({
|
|
18021
|
+
id: string$1().nullish(),
|
|
18022
|
+
created: number$1().nullish(),
|
|
18023
|
+
model: string$1().nullish(),
|
|
18024
|
+
choices: array(
|
|
18025
|
+
object({
|
|
18026
|
+
delta: object({
|
|
18027
|
+
content: string$1().nullish(),
|
|
18028
|
+
reasoning: string$1().nullish(),
|
|
18029
|
+
tool_calls: array(
|
|
18030
|
+
object({
|
|
18031
|
+
index: number$1(),
|
|
18032
|
+
id: string$1().nullish(),
|
|
18033
|
+
type: literal("function").optional(),
|
|
18034
|
+
function: object({
|
|
18035
|
+
name: string$1().nullish(),
|
|
18036
|
+
arguments: string$1().nullish()
|
|
18037
|
+
})
|
|
18038
|
+
})
|
|
18039
|
+
).nullish()
|
|
18040
|
+
}).nullish(),
|
|
18041
|
+
finish_reason: string$1().nullable().optional(),
|
|
18042
|
+
index: number$1()
|
|
18043
|
+
})
|
|
18044
|
+
),
|
|
18045
|
+
x_groq: object({
|
|
18046
|
+
usage: object({
|
|
18047
|
+
prompt_tokens: number$1().nullish(),
|
|
18048
|
+
completion_tokens: number$1().nullish(),
|
|
18049
|
+
total_tokens: number$1().nullish()
|
|
18050
|
+
}).nullish()
|
|
18051
|
+
}).nullish()
|
|
18052
|
+
}),
|
|
18053
|
+
groqErrorDataSchema
|
|
18054
|
+
]);
|
|
18055
|
+
var groqProviderOptionsSchema = object({
|
|
18056
|
+
language: string$1().nullish(),
|
|
18057
|
+
prompt: string$1().nullish(),
|
|
18058
|
+
responseFormat: string$1().nullish(),
|
|
18059
|
+
temperature: number$1().min(0).max(1).nullish(),
|
|
18060
|
+
timestampGranularities: array(string$1()).nullish()
|
|
18061
|
+
});
|
|
18062
|
+
var GroqTranscriptionModel = class {
|
|
18063
|
+
constructor(modelId, config2) {
|
|
18064
|
+
this.modelId = modelId;
|
|
18065
|
+
this.config = config2;
|
|
18066
|
+
this.specificationVersion = "v2";
|
|
18067
|
+
}
|
|
18068
|
+
get provider() {
|
|
18069
|
+
return this.config.provider;
|
|
18070
|
+
}
|
|
18071
|
+
async getArgs({
|
|
18072
|
+
audio,
|
|
18073
|
+
mediaType,
|
|
18074
|
+
providerOptions
|
|
18075
|
+
}) {
|
|
18076
|
+
var _a10, _b, _c, _d, _e;
|
|
18077
|
+
const warnings = [];
|
|
18078
|
+
const groqOptions = await parseProviderOptions({
|
|
18079
|
+
provider: "groq",
|
|
18080
|
+
providerOptions,
|
|
18081
|
+
schema: groqProviderOptionsSchema
|
|
18082
|
+
});
|
|
18083
|
+
const formData = new FormData();
|
|
18084
|
+
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
|
|
18085
|
+
formData.append("model", this.modelId);
|
|
18086
|
+
const fileExtension = mediaTypeToExtension(mediaType);
|
|
18087
|
+
formData.append(
|
|
18088
|
+
"file",
|
|
18089
|
+
new File([blob], "audio", { type: mediaType }),
|
|
18090
|
+
`audio.${fileExtension}`
|
|
18091
|
+
);
|
|
18092
|
+
if (groqOptions) {
|
|
18093
|
+
const transcriptionModelOptions = {
|
|
18094
|
+
language: (_a10 = groqOptions.language) != null ? _a10 : void 0,
|
|
18095
|
+
prompt: (_b = groqOptions.prompt) != null ? _b : void 0,
|
|
18096
|
+
response_format: (_c = groqOptions.responseFormat) != null ? _c : void 0,
|
|
18097
|
+
temperature: (_d = groqOptions.temperature) != null ? _d : void 0,
|
|
18098
|
+
timestamp_granularities: (_e = groqOptions.timestampGranularities) != null ? _e : void 0
|
|
18099
|
+
};
|
|
18100
|
+
for (const key in transcriptionModelOptions) {
|
|
18101
|
+
const value = transcriptionModelOptions[key];
|
|
18102
|
+
if (value !== void 0) {
|
|
18103
|
+
formData.append(key, String(value));
|
|
18104
|
+
}
|
|
18105
|
+
}
|
|
18106
|
+
}
|
|
18107
|
+
return {
|
|
18108
|
+
formData,
|
|
18109
|
+
warnings
|
|
18110
|
+
};
|
|
18111
|
+
}
|
|
18112
|
+
async doGenerate(options) {
|
|
18113
|
+
var _a10, _b, _c, _d, _e, _f, _g;
|
|
18114
|
+
const currentDate = (_c = (_b = (_a10 = this.config._internal) == null ? void 0 : _a10.currentDate) == null ? void 0 : _b.call(_a10)) != null ? _c : /* @__PURE__ */ new Date();
|
|
18115
|
+
const { formData, warnings } = await this.getArgs(options);
|
|
18116
|
+
const {
|
|
18117
|
+
value: response,
|
|
18118
|
+
responseHeaders,
|
|
18119
|
+
rawValue: rawResponse
|
|
18120
|
+
} = await postFormDataToApi({
|
|
18121
|
+
url: this.config.url({
|
|
18122
|
+
path: "/audio/transcriptions",
|
|
18123
|
+
modelId: this.modelId
|
|
18124
|
+
}),
|
|
18125
|
+
headers: combineHeaders$1(this.config.headers(), options.headers),
|
|
18126
|
+
formData,
|
|
18127
|
+
failedResponseHandler: groqFailedResponseHandler,
|
|
18128
|
+
successfulResponseHandler: createJsonResponseHandler$1(
|
|
18129
|
+
groqTranscriptionResponseSchema
|
|
18130
|
+
),
|
|
18131
|
+
abortSignal: options.abortSignal,
|
|
18132
|
+
fetch: this.config.fetch
|
|
18133
|
+
});
|
|
18134
|
+
return {
|
|
18135
|
+
text: response.text,
|
|
18136
|
+
segments: (_e = (_d = response.segments) == null ? void 0 : _d.map((segment) => ({
|
|
18137
|
+
text: segment.text,
|
|
18138
|
+
startSecond: segment.start,
|
|
18139
|
+
endSecond: segment.end
|
|
18140
|
+
}))) != null ? _e : [],
|
|
18141
|
+
language: (_f = response.language) != null ? _f : void 0,
|
|
18142
|
+
durationInSeconds: (_g = response.duration) != null ? _g : void 0,
|
|
18143
|
+
warnings,
|
|
18144
|
+
response: {
|
|
18145
|
+
timestamp: currentDate,
|
|
18146
|
+
modelId: this.modelId,
|
|
18147
|
+
headers: responseHeaders,
|
|
18148
|
+
body: rawResponse
|
|
18149
|
+
}
|
|
18150
|
+
};
|
|
18151
|
+
}
|
|
18152
|
+
};
|
|
18153
|
+
var groqTranscriptionResponseSchema = object({
|
|
18154
|
+
text: string$1(),
|
|
18155
|
+
x_groq: object({
|
|
18156
|
+
id: string$1()
|
|
18157
|
+
}),
|
|
18158
|
+
// additional properties are returned when `response_format: 'verbose_json'` is
|
|
18159
|
+
task: string$1().nullish(),
|
|
18160
|
+
language: string$1().nullish(),
|
|
18161
|
+
duration: number$1().nullish(),
|
|
18162
|
+
segments: array(
|
|
18163
|
+
object({
|
|
18164
|
+
id: number$1(),
|
|
18165
|
+
seek: number$1(),
|
|
18166
|
+
start: number$1(),
|
|
18167
|
+
end: number$1(),
|
|
18168
|
+
text: string$1(),
|
|
18169
|
+
tokens: array(number$1()),
|
|
18170
|
+
temperature: number$1(),
|
|
18171
|
+
avg_logprob: number$1(),
|
|
18172
|
+
compression_ratio: number$1(),
|
|
18173
|
+
no_speech_prob: number$1()
|
|
18174
|
+
})
|
|
18175
|
+
).nullish()
|
|
18176
|
+
});
|
|
18177
|
+
var browserSearch = createProviderDefinedToolFactory({
|
|
18178
|
+
id: "groq.browser_search",
|
|
18179
|
+
name: "browser_search",
|
|
18180
|
+
inputSchema: object({})
|
|
18181
|
+
});
|
|
18182
|
+
var groqTools = {
|
|
18183
|
+
browserSearch
|
|
18184
|
+
};
|
|
18185
|
+
function createGroq(options = {}) {
|
|
18186
|
+
var _a10;
|
|
18187
|
+
const baseURL = (_a10 = withoutTrailingSlash$1(options.baseURL)) != null ? _a10 : "https://api.groq.com/openai/v1";
|
|
18188
|
+
const getHeaders = () => ({
|
|
18189
|
+
Authorization: `Bearer ${loadApiKey$1({
|
|
18190
|
+
apiKey: options.apiKey,
|
|
18191
|
+
environmentVariableName: "GROQ_API_KEY",
|
|
18192
|
+
description: "Groq"
|
|
18193
|
+
})}`,
|
|
18194
|
+
...options.headers
|
|
18195
|
+
});
|
|
18196
|
+
const createChatModel = (modelId) => new GroqChatLanguageModel(modelId, {
|
|
18197
|
+
provider: "groq.chat",
|
|
18198
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
18199
|
+
headers: getHeaders,
|
|
18200
|
+
fetch: options.fetch
|
|
18201
|
+
});
|
|
18202
|
+
const createLanguageModel = (modelId) => {
|
|
18203
|
+
if (new.target) {
|
|
18204
|
+
throw new Error(
|
|
18205
|
+
"The Groq model function cannot be called with the new keyword."
|
|
18206
|
+
);
|
|
18207
|
+
}
|
|
18208
|
+
return createChatModel(modelId);
|
|
18209
|
+
};
|
|
18210
|
+
const createTranscriptionModel = (modelId) => {
|
|
18211
|
+
return new GroqTranscriptionModel(modelId, {
|
|
18212
|
+
provider: "groq.transcription",
|
|
18213
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
18214
|
+
headers: getHeaders,
|
|
18215
|
+
fetch: options.fetch
|
|
18216
|
+
});
|
|
18217
|
+
};
|
|
18218
|
+
const provider = function(modelId) {
|
|
18219
|
+
return createLanguageModel(modelId);
|
|
18220
|
+
};
|
|
18221
|
+
provider.languageModel = createLanguageModel;
|
|
18222
|
+
provider.chat = createChatModel;
|
|
18223
|
+
provider.textEmbeddingModel = (modelId) => {
|
|
18224
|
+
throw new NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
|
|
18225
|
+
};
|
|
18226
|
+
provider.imageModel = (modelId) => {
|
|
18227
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
18228
|
+
};
|
|
18229
|
+
provider.transcription = createTranscriptionModel;
|
|
18230
|
+
provider.transcriptionModel = createTranscriptionModel;
|
|
18231
|
+
provider.tools = groqTools;
|
|
18232
|
+
return provider;
|
|
18233
|
+
}
|
|
18234
|
+
createGroq();
|
|
18235
|
+
object({
|
|
18236
|
+
/**
|
|
18237
|
+
* A unique identifier representing your end-user, which can help the provider to
|
|
18238
|
+
* monitor and detect abuse.
|
|
18239
|
+
*/
|
|
18240
|
+
user: string$1().optional(),
|
|
18241
|
+
/**
|
|
18242
|
+
* Reasoning effort for reasoning models. Defaults to `medium`.
|
|
18243
|
+
*/
|
|
18244
|
+
reasoningEffort: string$1().optional()
|
|
18245
|
+
});
|
|
18246
|
+
var openaiCompatibleErrorDataSchema = object({
|
|
18247
|
+
error: object({
|
|
18248
|
+
message: string$1(),
|
|
18249
|
+
// The additional information below is handled loosely to support
|
|
18250
|
+
// OpenAI-compatible providers that have slightly different error
|
|
18251
|
+
// responses:
|
|
18252
|
+
type: string$1().nullish(),
|
|
18253
|
+
param: any().nullish(),
|
|
18254
|
+
code: union([string$1(), number$1()]).nullish()
|
|
18255
|
+
})
|
|
18256
|
+
});
|
|
18257
|
+
var defaultOpenAICompatibleErrorStructure = {
|
|
18258
|
+
errorSchema: openaiCompatibleErrorDataSchema,
|
|
18259
|
+
errorToMessage: (data) => data.error.message
|
|
18260
|
+
};
|
|
18261
|
+
var openaiCompatibleTokenUsageSchema = object({
|
|
18262
|
+
prompt_tokens: number$1().nullish(),
|
|
18263
|
+
completion_tokens: number$1().nullish(),
|
|
18264
|
+
total_tokens: number$1().nullish(),
|
|
18265
|
+
prompt_tokens_details: object({
|
|
18266
|
+
cached_tokens: number$1().nullish()
|
|
18267
|
+
}).nullish(),
|
|
18268
|
+
completion_tokens_details: object({
|
|
18269
|
+
reasoning_tokens: number$1().nullish(),
|
|
18270
|
+
accepted_prediction_tokens: number$1().nullish(),
|
|
18271
|
+
rejected_prediction_tokens: number$1().nullish()
|
|
18272
|
+
}).nullish()
|
|
18273
|
+
}).nullish();
|
|
18274
|
+
object({
|
|
18275
|
+
id: string$1().nullish(),
|
|
18276
|
+
created: number$1().nullish(),
|
|
18277
|
+
model: string$1().nullish(),
|
|
18278
|
+
choices: array(
|
|
18279
|
+
object({
|
|
18280
|
+
message: object({
|
|
18281
|
+
role: literal("assistant").nullish(),
|
|
18282
|
+
content: string$1().nullish(),
|
|
18283
|
+
reasoning_content: string$1().nullish(),
|
|
18284
|
+
reasoning: string$1().nullish(),
|
|
18285
|
+
tool_calls: array(
|
|
18286
|
+
object({
|
|
18287
|
+
id: string$1().nullish(),
|
|
18288
|
+
function: object({
|
|
18289
|
+
name: string$1(),
|
|
18290
|
+
arguments: string$1()
|
|
18291
|
+
})
|
|
18292
|
+
})
|
|
18293
|
+
).nullish()
|
|
18294
|
+
}),
|
|
18295
|
+
finish_reason: string$1().nullish()
|
|
18296
|
+
})
|
|
18297
|
+
),
|
|
18298
|
+
usage: openaiCompatibleTokenUsageSchema
|
|
18299
|
+
});
|
|
18300
|
+
object({
|
|
18301
|
+
/**
|
|
18302
|
+
* Echo back the prompt in addition to the completion.
|
|
18303
|
+
*/
|
|
18304
|
+
echo: boolean$1().optional(),
|
|
18305
|
+
/**
|
|
18306
|
+
* Modify the likelihood of specified tokens appearing in the completion.
|
|
18307
|
+
*
|
|
18308
|
+
* Accepts a JSON object that maps tokens (specified by their token ID in
|
|
18309
|
+
* the GPT tokenizer) to an associated bias value from -100 to 100.
|
|
18310
|
+
*/
|
|
18311
|
+
logitBias: record(string$1(), number$1()).optional(),
|
|
18312
|
+
/**
|
|
18313
|
+
* The suffix that comes after a completion of inserted text.
|
|
18314
|
+
*/
|
|
18315
|
+
suffix: string$1().optional(),
|
|
18316
|
+
/**
|
|
18317
|
+
* A unique identifier representing your end-user, which can help providers to
|
|
18318
|
+
* monitor and detect abuse.
|
|
18319
|
+
*/
|
|
18320
|
+
user: string$1().optional()
|
|
18321
|
+
});
|
|
18322
|
+
var usageSchema$1 = object({
|
|
18323
|
+
prompt_tokens: number$1(),
|
|
18324
|
+
completion_tokens: number$1(),
|
|
18325
|
+
total_tokens: number$1()
|
|
18326
|
+
});
|
|
18327
|
+
object({
|
|
18328
|
+
id: string$1().nullish(),
|
|
18329
|
+
created: number$1().nullish(),
|
|
18330
|
+
model: string$1().nullish(),
|
|
18331
|
+
choices: array(
|
|
18332
|
+
object({
|
|
18333
|
+
text: string$1(),
|
|
18334
|
+
finish_reason: string$1()
|
|
18335
|
+
})
|
|
18336
|
+
),
|
|
18337
|
+
usage: usageSchema$1.nullish()
|
|
18338
|
+
});
|
|
18339
|
+
object({
|
|
18340
|
+
/**
|
|
18341
|
+
* The number of dimensions the resulting output embeddings should have.
|
|
18342
|
+
* Only supported in text-embedding-3 and later models.
|
|
18343
|
+
*/
|
|
18344
|
+
dimensions: number$1().optional(),
|
|
18345
|
+
/**
|
|
18346
|
+
* A unique identifier representing your end-user, which can help providers to
|
|
18347
|
+
* monitor and detect abuse.
|
|
18348
|
+
*/
|
|
18349
|
+
user: string$1().optional()
|
|
18350
|
+
});
|
|
18351
|
+
object({
|
|
18352
|
+
data: array(object({ embedding: array(number$1()) })),
|
|
18353
|
+
usage: object({ prompt_tokens: number$1() }).nullish(),
|
|
18354
|
+
providerMetadata: record(string$1(), record(string$1(), any())).optional()
|
|
18355
|
+
});
|
|
18356
|
+
var OpenAICompatibleImageModel = class {
|
|
18357
|
+
constructor(modelId, config2) {
|
|
18358
|
+
this.modelId = modelId;
|
|
18359
|
+
this.config = config2;
|
|
18360
|
+
this.specificationVersion = "v2";
|
|
18361
|
+
this.maxImagesPerCall = 10;
|
|
18362
|
+
}
|
|
18363
|
+
get provider() {
|
|
18364
|
+
return this.config.provider;
|
|
18365
|
+
}
|
|
18366
|
+
async doGenerate({
|
|
18367
|
+
prompt,
|
|
18368
|
+
n,
|
|
18369
|
+
size,
|
|
18370
|
+
aspectRatio,
|
|
18371
|
+
seed,
|
|
18372
|
+
providerOptions,
|
|
18373
|
+
headers,
|
|
18374
|
+
abortSignal
|
|
18375
|
+
}) {
|
|
18376
|
+
var _a10, _b, _c, _d, _e;
|
|
18377
|
+
const warnings = [];
|
|
18378
|
+
if (aspectRatio != null) {
|
|
18379
|
+
warnings.push({
|
|
18380
|
+
type: "unsupported-setting",
|
|
18381
|
+
setting: "aspectRatio",
|
|
18382
|
+
details: "This model does not support aspect ratio. Use `size` instead."
|
|
18383
|
+
});
|
|
18384
|
+
}
|
|
18385
|
+
if (seed != null) {
|
|
18386
|
+
warnings.push({ type: "unsupported-setting", setting: "seed" });
|
|
18387
|
+
}
|
|
18388
|
+
const currentDate = (_c = (_b = (_a10 = this.config._internal) == null ? void 0 : _a10.currentDate) == null ? void 0 : _b.call(_a10)) != null ? _c : /* @__PURE__ */ new Date();
|
|
18389
|
+
const { value: response, responseHeaders } = await postJsonToApi$1({
|
|
18390
|
+
url: this.config.url({
|
|
18391
|
+
path: "/images/generations",
|
|
18392
|
+
modelId: this.modelId
|
|
18393
|
+
}),
|
|
18394
|
+
headers: combineHeaders$1(this.config.headers(), headers),
|
|
18395
|
+
body: {
|
|
18396
|
+
model: this.modelId,
|
|
18397
|
+
prompt,
|
|
18398
|
+
n,
|
|
18399
|
+
size,
|
|
18400
|
+
...(_d = providerOptions.openai) != null ? _d : {},
|
|
18401
|
+
response_format: "b64_json"
|
|
18402
|
+
},
|
|
18403
|
+
failedResponseHandler: createJsonErrorResponseHandler$1(
|
|
18404
|
+
(_e = this.config.errorStructure) != null ? _e : defaultOpenAICompatibleErrorStructure
|
|
18405
|
+
),
|
|
18406
|
+
successfulResponseHandler: createJsonResponseHandler$1(
|
|
18407
|
+
openaiCompatibleImageResponseSchema
|
|
18408
|
+
),
|
|
18409
|
+
abortSignal,
|
|
18410
|
+
fetch: this.config.fetch
|
|
18411
|
+
});
|
|
18412
|
+
return {
|
|
18413
|
+
images: response.data.map((item) => item.b64_json),
|
|
18414
|
+
warnings,
|
|
18415
|
+
response: {
|
|
18416
|
+
timestamp: currentDate,
|
|
18417
|
+
modelId: this.modelId,
|
|
18418
|
+
headers: responseHeaders
|
|
18419
|
+
}
|
|
18420
|
+
};
|
|
18421
|
+
}
|
|
18422
|
+
};
|
|
18423
|
+
var openaiCompatibleImageResponseSchema = object({
|
|
18424
|
+
data: array(object({ b64_json: string$1() }))
|
|
18425
|
+
});
|
|
18426
|
+
function convertToXaiChatMessages(prompt) {
|
|
18427
|
+
const messages = [];
|
|
18428
|
+
const warnings = [];
|
|
18429
|
+
for (const { role, content } of prompt) {
|
|
18430
|
+
switch (role) {
|
|
18431
|
+
case "system": {
|
|
18432
|
+
messages.push({ role: "system", content });
|
|
18433
|
+
break;
|
|
18434
|
+
}
|
|
18435
|
+
case "user": {
|
|
18436
|
+
if (content.length === 1 && content[0].type === "text") {
|
|
18437
|
+
messages.push({ role: "user", content: content[0].text });
|
|
18438
|
+
break;
|
|
18439
|
+
}
|
|
18440
|
+
messages.push({
|
|
18441
|
+
role: "user",
|
|
18442
|
+
content: content.map((part) => {
|
|
18443
|
+
switch (part.type) {
|
|
18444
|
+
case "text": {
|
|
18445
|
+
return { type: "text", text: part.text };
|
|
18446
|
+
}
|
|
18447
|
+
case "file": {
|
|
18448
|
+
if (part.mediaType.startsWith("image/")) {
|
|
18449
|
+
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
18450
|
+
return {
|
|
18451
|
+
type: "image_url",
|
|
18452
|
+
image_url: {
|
|
18453
|
+
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`
|
|
18454
|
+
}
|
|
18455
|
+
};
|
|
18456
|
+
} else {
|
|
18457
|
+
throw new UnsupportedFunctionalityError$1({
|
|
18458
|
+
functionality: `file part media type ${part.mediaType}`
|
|
18459
|
+
});
|
|
18460
|
+
}
|
|
18461
|
+
}
|
|
18462
|
+
}
|
|
18463
|
+
})
|
|
18464
|
+
});
|
|
18465
|
+
break;
|
|
18466
|
+
}
|
|
18467
|
+
case "assistant": {
|
|
18468
|
+
let text2 = "";
|
|
18469
|
+
const toolCalls = [];
|
|
18470
|
+
for (const part of content) {
|
|
18471
|
+
switch (part.type) {
|
|
18472
|
+
case "text": {
|
|
18473
|
+
text2 += part.text;
|
|
18474
|
+
break;
|
|
18475
|
+
}
|
|
18476
|
+
case "tool-call": {
|
|
18477
|
+
toolCalls.push({
|
|
18478
|
+
id: part.toolCallId,
|
|
18479
|
+
type: "function",
|
|
18480
|
+
function: {
|
|
18481
|
+
name: part.toolName,
|
|
18482
|
+
arguments: JSON.stringify(part.input)
|
|
18483
|
+
}
|
|
18484
|
+
});
|
|
18485
|
+
break;
|
|
18486
|
+
}
|
|
18487
|
+
}
|
|
18488
|
+
}
|
|
18489
|
+
messages.push({
|
|
18490
|
+
role: "assistant",
|
|
18491
|
+
content: text2,
|
|
18492
|
+
tool_calls: toolCalls.length > 0 ? toolCalls : void 0
|
|
18493
|
+
});
|
|
18494
|
+
break;
|
|
18495
|
+
}
|
|
18496
|
+
case "tool": {
|
|
18497
|
+
for (const toolResponse of content) {
|
|
18498
|
+
const output = toolResponse.output;
|
|
18499
|
+
let contentValue;
|
|
18500
|
+
switch (output.type) {
|
|
18501
|
+
case "text":
|
|
18502
|
+
case "error-text":
|
|
18503
|
+
contentValue = output.value;
|
|
18504
|
+
break;
|
|
18505
|
+
case "content":
|
|
18506
|
+
case "json":
|
|
18507
|
+
case "error-json":
|
|
18508
|
+
contentValue = JSON.stringify(output.value);
|
|
18509
|
+
break;
|
|
18510
|
+
}
|
|
18511
|
+
messages.push({
|
|
18512
|
+
role: "tool",
|
|
18513
|
+
tool_call_id: toolResponse.toolCallId,
|
|
18514
|
+
content: contentValue
|
|
18515
|
+
});
|
|
18516
|
+
}
|
|
18517
|
+
break;
|
|
18518
|
+
}
|
|
18519
|
+
default: {
|
|
18520
|
+
const _exhaustiveCheck = role;
|
|
18521
|
+
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
|
18522
|
+
}
|
|
18523
|
+
}
|
|
18524
|
+
}
|
|
18525
|
+
return { messages, warnings };
|
|
18526
|
+
}
|
|
18527
|
+
function getResponseMetadata$1({
|
|
18528
|
+
id: id2,
|
|
18529
|
+
model,
|
|
18530
|
+
created
|
|
18531
|
+
}) {
|
|
18532
|
+
return {
|
|
18533
|
+
id: id2 != null ? id2 : void 0,
|
|
18534
|
+
modelId: model != null ? model : void 0,
|
|
18535
|
+
timestamp: created != null ? new Date(created * 1e3) : void 0
|
|
18536
|
+
};
|
|
18537
|
+
}
|
|
18538
|
+
function mapXaiFinishReason(finishReason) {
|
|
18539
|
+
switch (finishReason) {
|
|
18540
|
+
case "stop":
|
|
18541
|
+
return "stop";
|
|
18542
|
+
case "length":
|
|
18543
|
+
return "length";
|
|
18544
|
+
case "tool_calls":
|
|
18545
|
+
case "function_call":
|
|
18546
|
+
return "tool-calls";
|
|
18547
|
+
case "content_filter":
|
|
18548
|
+
return "content-filter";
|
|
18549
|
+
default:
|
|
18550
|
+
return "unknown";
|
|
18551
|
+
}
|
|
18552
|
+
}
|
|
18553
|
+
var webSourceSchema = object({
|
|
18554
|
+
type: literal("web"),
|
|
18555
|
+
country: string$1().length(2).optional(),
|
|
18556
|
+
excludedWebsites: array(string$1()).max(5).optional(),
|
|
18557
|
+
allowedWebsites: array(string$1()).max(5).optional(),
|
|
18558
|
+
safeSearch: boolean$1().optional()
|
|
18559
|
+
});
|
|
18560
|
+
var xSourceSchema = object({
|
|
18561
|
+
type: literal("x"),
|
|
18562
|
+
xHandles: array(string$1()).optional()
|
|
18563
|
+
});
|
|
18564
|
+
var newsSourceSchema = object({
|
|
18565
|
+
type: literal("news"),
|
|
18566
|
+
country: string$1().length(2).optional(),
|
|
18567
|
+
excludedWebsites: array(string$1()).max(5).optional(),
|
|
18568
|
+
safeSearch: boolean$1().optional()
|
|
18569
|
+
});
|
|
18570
|
+
var rssSourceSchema = object({
|
|
18571
|
+
type: literal("rss"),
|
|
18572
|
+
links: array(string$1().url()).max(1)
|
|
18573
|
+
// currently only supports one RSS link
|
|
18574
|
+
});
|
|
18575
|
+
var searchSourceSchema = discriminatedUnion("type", [
|
|
18576
|
+
webSourceSchema,
|
|
18577
|
+
xSourceSchema,
|
|
18578
|
+
newsSourceSchema,
|
|
18579
|
+
rssSourceSchema
|
|
18580
|
+
]);
|
|
18581
|
+
var xaiProviderOptions = object({
|
|
18582
|
+
/**
|
|
18583
|
+
* reasoning effort for reasoning models
|
|
18584
|
+
* only supported by grok-3-mini and grok-3-mini-fast models
|
|
18585
|
+
*/
|
|
18586
|
+
reasoningEffort: _enum(["low", "high"]).optional(),
|
|
18587
|
+
searchParameters: object({
|
|
18588
|
+
/**
|
|
18589
|
+
* search mode preference
|
|
18590
|
+
* - "off": disables search completely
|
|
18591
|
+
* - "auto": model decides whether to search (default)
|
|
18592
|
+
* - "on": always enables search
|
|
18593
|
+
*/
|
|
18594
|
+
mode: _enum(["off", "auto", "on"]),
|
|
18595
|
+
/**
|
|
18596
|
+
* whether to return citations in the response
|
|
18597
|
+
* defaults to true
|
|
18598
|
+
*/
|
|
18599
|
+
returnCitations: boolean$1().optional(),
|
|
18600
|
+
/**
|
|
18601
|
+
* start date for search data (ISO8601 format: YYYY-MM-DD)
|
|
18602
|
+
*/
|
|
18603
|
+
fromDate: string$1().optional(),
|
|
18604
|
+
/**
|
|
18605
|
+
* end date for search data (ISO8601 format: YYYY-MM-DD)
|
|
18606
|
+
*/
|
|
18607
|
+
toDate: string$1().optional(),
|
|
18608
|
+
/**
|
|
18609
|
+
* maximum number of search results to consider
|
|
18610
|
+
* defaults to 20
|
|
18611
|
+
*/
|
|
18612
|
+
maxSearchResults: number$1().min(1).max(50).optional(),
|
|
18613
|
+
/**
|
|
18614
|
+
* data sources to search from
|
|
18615
|
+
* defaults to ["web", "x"] if not specified
|
|
18616
|
+
*/
|
|
18617
|
+
sources: array(searchSourceSchema).optional()
|
|
18618
|
+
}).optional()
|
|
18619
|
+
});
|
|
18620
|
+
var xaiErrorDataSchema = object({
|
|
18621
|
+
error: object({
|
|
18622
|
+
message: string$1(),
|
|
18623
|
+
type: string$1().nullish(),
|
|
18624
|
+
param: any().nullish(),
|
|
18625
|
+
code: union([string$1(), number$1()]).nullish()
|
|
18626
|
+
})
|
|
18627
|
+
});
|
|
18628
|
+
var xaiFailedResponseHandler = createJsonErrorResponseHandler$1({
|
|
18629
|
+
errorSchema: xaiErrorDataSchema,
|
|
18630
|
+
errorToMessage: (data) => data.error.message
|
|
18631
|
+
});
|
|
18632
|
+
function prepareTools({
|
|
18633
|
+
tools,
|
|
18634
|
+
toolChoice
|
|
18635
|
+
}) {
|
|
18636
|
+
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
18637
|
+
const toolWarnings = [];
|
|
18638
|
+
if (tools == null) {
|
|
18639
|
+
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
18640
|
+
}
|
|
18641
|
+
const xaiTools = [];
|
|
18642
|
+
for (const tool2 of tools) {
|
|
18643
|
+
if (tool2.type === "provider-defined") {
|
|
18644
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool2 });
|
|
18645
|
+
} else {
|
|
18646
|
+
xaiTools.push({
|
|
18647
|
+
type: "function",
|
|
18648
|
+
function: {
|
|
18649
|
+
name: tool2.name,
|
|
18650
|
+
description: tool2.description,
|
|
18651
|
+
parameters: tool2.inputSchema
|
|
18652
|
+
}
|
|
18653
|
+
});
|
|
18654
|
+
}
|
|
18655
|
+
}
|
|
18656
|
+
if (toolChoice == null) {
|
|
18657
|
+
return { tools: xaiTools, toolChoice: void 0, toolWarnings };
|
|
18658
|
+
}
|
|
18659
|
+
const type = toolChoice.type;
|
|
18660
|
+
switch (type) {
|
|
18661
|
+
case "auto":
|
|
18662
|
+
case "none":
|
|
18663
|
+
return { tools: xaiTools, toolChoice: type, toolWarnings };
|
|
18664
|
+
case "required":
|
|
18665
|
+
return { tools: xaiTools, toolChoice: "required", toolWarnings };
|
|
18666
|
+
case "tool":
|
|
18667
|
+
return {
|
|
18668
|
+
tools: xaiTools,
|
|
18669
|
+
toolChoice: {
|
|
18670
|
+
type: "function",
|
|
18671
|
+
function: { name: toolChoice.toolName }
|
|
18672
|
+
},
|
|
18673
|
+
toolWarnings
|
|
18674
|
+
};
|
|
18675
|
+
default: {
|
|
18676
|
+
const _exhaustiveCheck = type;
|
|
18677
|
+
throw new UnsupportedFunctionalityError$1({
|
|
18678
|
+
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
18679
|
+
});
|
|
18680
|
+
}
|
|
18681
|
+
}
|
|
18682
|
+
}
|
|
18683
|
+
var XaiChatLanguageModel = class {
|
|
18684
|
+
constructor(modelId, config2) {
|
|
18685
|
+
this.specificationVersion = "v2";
|
|
18686
|
+
this.supportedUrls = {
|
|
18687
|
+
"image/*": [/^https?:\/\/.*$/]
|
|
18688
|
+
};
|
|
18689
|
+
this.modelId = modelId;
|
|
18690
|
+
this.config = config2;
|
|
18691
|
+
}
|
|
18692
|
+
get provider() {
|
|
18693
|
+
return this.config.provider;
|
|
18694
|
+
}
|
|
18695
|
+
async getArgs({
|
|
18696
|
+
prompt,
|
|
18697
|
+
maxOutputTokens,
|
|
18698
|
+
temperature,
|
|
18699
|
+
topP,
|
|
18700
|
+
topK,
|
|
18701
|
+
frequencyPenalty,
|
|
18702
|
+
presencePenalty,
|
|
18703
|
+
stopSequences,
|
|
18704
|
+
seed,
|
|
18705
|
+
responseFormat,
|
|
18706
|
+
providerOptions,
|
|
18707
|
+
tools,
|
|
18708
|
+
toolChoice
|
|
18709
|
+
}) {
|
|
18710
|
+
var _a10, _b, _c;
|
|
18711
|
+
const warnings = [];
|
|
18712
|
+
const options = (_a10 = await parseProviderOptions({
|
|
18713
|
+
provider: "xai",
|
|
18714
|
+
providerOptions,
|
|
18715
|
+
schema: xaiProviderOptions
|
|
18716
|
+
})) != null ? _a10 : {};
|
|
18717
|
+
if (topK != null) {
|
|
18718
|
+
warnings.push({
|
|
18719
|
+
type: "unsupported-setting",
|
|
18720
|
+
setting: "topK"
|
|
18721
|
+
});
|
|
18722
|
+
}
|
|
18723
|
+
if (frequencyPenalty != null) {
|
|
18724
|
+
warnings.push({
|
|
18725
|
+
type: "unsupported-setting",
|
|
18726
|
+
setting: "frequencyPenalty"
|
|
18727
|
+
});
|
|
18728
|
+
}
|
|
18729
|
+
if (presencePenalty != null) {
|
|
18730
|
+
warnings.push({
|
|
18731
|
+
type: "unsupported-setting",
|
|
18732
|
+
setting: "presencePenalty"
|
|
18733
|
+
});
|
|
18734
|
+
}
|
|
18735
|
+
if (stopSequences != null) {
|
|
18736
|
+
warnings.push({
|
|
18737
|
+
type: "unsupported-setting",
|
|
18738
|
+
setting: "stopSequences"
|
|
18739
|
+
});
|
|
18740
|
+
}
|
|
18741
|
+
if (responseFormat != null && responseFormat.type === "json" && responseFormat.schema != null) {
|
|
18742
|
+
warnings.push({
|
|
18743
|
+
type: "unsupported-setting",
|
|
18744
|
+
setting: "responseFormat",
|
|
18745
|
+
details: "JSON response format schema is not supported"
|
|
18746
|
+
});
|
|
18747
|
+
}
|
|
18748
|
+
const { messages, warnings: messageWarnings } = convertToXaiChatMessages(prompt);
|
|
18749
|
+
warnings.push(...messageWarnings);
|
|
18750
|
+
const {
|
|
18751
|
+
tools: xaiTools,
|
|
18752
|
+
toolChoice: xaiToolChoice,
|
|
18753
|
+
toolWarnings
|
|
18754
|
+
} = prepareTools({
|
|
18755
|
+
tools,
|
|
18756
|
+
toolChoice
|
|
18757
|
+
});
|
|
18758
|
+
warnings.push(...toolWarnings);
|
|
18759
|
+
const baseArgs = {
|
|
18760
|
+
// model id
|
|
18761
|
+
model: this.modelId,
|
|
18762
|
+
// standard generation settings
|
|
18763
|
+
max_tokens: maxOutputTokens,
|
|
18764
|
+
temperature,
|
|
18765
|
+
top_p: topP,
|
|
18766
|
+
seed,
|
|
18767
|
+
reasoning_effort: options.reasoningEffort,
|
|
18768
|
+
// response format
|
|
18769
|
+
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? responseFormat.schema != null ? {
|
|
18770
|
+
type: "json_schema",
|
|
18771
|
+
json_schema: {
|
|
18772
|
+
name: (_b = responseFormat.name) != null ? _b : "response",
|
|
18773
|
+
schema: responseFormat.schema,
|
|
18774
|
+
strict: true
|
|
18775
|
+
}
|
|
18776
|
+
} : { type: "json_object" } : void 0,
|
|
18777
|
+
// search parameters
|
|
18778
|
+
search_parameters: options.searchParameters ? {
|
|
18779
|
+
mode: options.searchParameters.mode,
|
|
18780
|
+
return_citations: options.searchParameters.returnCitations,
|
|
18781
|
+
from_date: options.searchParameters.fromDate,
|
|
18782
|
+
to_date: options.searchParameters.toDate,
|
|
18783
|
+
max_search_results: options.searchParameters.maxSearchResults,
|
|
18784
|
+
sources: (_c = options.searchParameters.sources) == null ? void 0 : _c.map((source) => ({
|
|
18785
|
+
type: source.type,
|
|
18786
|
+
...source.type === "web" && {
|
|
18787
|
+
country: source.country,
|
|
18788
|
+
excluded_websites: source.excludedWebsites,
|
|
18789
|
+
allowed_websites: source.allowedWebsites,
|
|
18790
|
+
safe_search: source.safeSearch
|
|
18791
|
+
},
|
|
18792
|
+
...source.type === "x" && {
|
|
18793
|
+
x_handles: source.xHandles
|
|
18794
|
+
},
|
|
18795
|
+
...source.type === "news" && {
|
|
18796
|
+
country: source.country,
|
|
18797
|
+
excluded_websites: source.excludedWebsites,
|
|
18798
|
+
safe_search: source.safeSearch
|
|
18799
|
+
},
|
|
18800
|
+
...source.type === "rss" && {
|
|
18801
|
+
links: source.links
|
|
18802
|
+
}
|
|
18803
|
+
}))
|
|
18804
|
+
} : void 0,
|
|
18805
|
+
// messages in xai format
|
|
18806
|
+
messages,
|
|
18807
|
+
// tools in xai format
|
|
18808
|
+
tools: xaiTools,
|
|
18809
|
+
tool_choice: xaiToolChoice
|
|
18810
|
+
};
|
|
18811
|
+
return {
|
|
18812
|
+
args: baseArgs,
|
|
18813
|
+
warnings
|
|
18814
|
+
};
|
|
18815
|
+
}
|
|
18816
|
+
async doGenerate(options) {
|
|
18817
|
+
var _a10, _b, _c;
|
|
18818
|
+
const { args: body, warnings } = await this.getArgs(options);
|
|
18819
|
+
const {
|
|
18820
|
+
responseHeaders,
|
|
18821
|
+
value: response,
|
|
18822
|
+
rawValue: rawResponse
|
|
18823
|
+
} = await postJsonToApi$1({
|
|
18824
|
+
url: `${(_a10 = this.config.baseURL) != null ? _a10 : "https://api.x.ai/v1"}/chat/completions`,
|
|
18825
|
+
headers: combineHeaders$1(this.config.headers(), options.headers),
|
|
18826
|
+
body,
|
|
18827
|
+
failedResponseHandler: xaiFailedResponseHandler,
|
|
18828
|
+
successfulResponseHandler: createJsonResponseHandler$1(
|
|
18829
|
+
xaiChatResponseSchema
|
|
18830
|
+
),
|
|
18831
|
+
abortSignal: options.abortSignal,
|
|
18832
|
+
fetch: this.config.fetch
|
|
18833
|
+
});
|
|
18834
|
+
const choice = response.choices[0];
|
|
18835
|
+
const content = [];
|
|
18836
|
+
if (choice.message.content != null && choice.message.content.length > 0) {
|
|
18837
|
+
let text2 = choice.message.content;
|
|
18838
|
+
const lastMessage = body.messages[body.messages.length - 1];
|
|
18839
|
+
if ((lastMessage == null ? void 0 : lastMessage.role) === "assistant" && text2 === lastMessage.content) {
|
|
18840
|
+
text2 = "";
|
|
18841
|
+
}
|
|
18842
|
+
if (text2.length > 0) {
|
|
18843
|
+
content.push({ type: "text", text: text2 });
|
|
18844
|
+
}
|
|
18845
|
+
}
|
|
18846
|
+
if (choice.message.reasoning_content != null && choice.message.reasoning_content.length > 0) {
|
|
18847
|
+
content.push({
|
|
18848
|
+
type: "reasoning",
|
|
18849
|
+
text: choice.message.reasoning_content
|
|
18850
|
+
});
|
|
18851
|
+
}
|
|
18852
|
+
if (choice.message.tool_calls != null) {
|
|
18853
|
+
for (const toolCall of choice.message.tool_calls) {
|
|
18854
|
+
content.push({
|
|
18855
|
+
type: "tool-call",
|
|
18856
|
+
toolCallId: toolCall.id,
|
|
18857
|
+
toolName: toolCall.function.name,
|
|
18858
|
+
input: toolCall.function.arguments
|
|
18859
|
+
});
|
|
18860
|
+
}
|
|
18861
|
+
}
|
|
18862
|
+
if (response.citations != null) {
|
|
18863
|
+
for (const url2 of response.citations) {
|
|
18864
|
+
content.push({
|
|
18865
|
+
type: "source",
|
|
18866
|
+
sourceType: "url",
|
|
18867
|
+
id: this.config.generateId(),
|
|
18868
|
+
url: url2
|
|
18869
|
+
});
|
|
18870
|
+
}
|
|
18871
|
+
}
|
|
18872
|
+
return {
|
|
18873
|
+
content,
|
|
18874
|
+
finishReason: mapXaiFinishReason(choice.finish_reason),
|
|
18875
|
+
usage: {
|
|
18876
|
+
inputTokens: response.usage.prompt_tokens,
|
|
18877
|
+
outputTokens: response.usage.completion_tokens,
|
|
18878
|
+
totalTokens: response.usage.total_tokens,
|
|
18879
|
+
reasoningTokens: (_c = (_b = response.usage.completion_tokens_details) == null ? void 0 : _b.reasoning_tokens) != null ? _c : void 0
|
|
18880
|
+
},
|
|
18881
|
+
request: { body },
|
|
18882
|
+
response: {
|
|
18883
|
+
...getResponseMetadata$1(response),
|
|
18884
|
+
headers: responseHeaders,
|
|
18885
|
+
body: rawResponse
|
|
18886
|
+
},
|
|
18887
|
+
warnings
|
|
18888
|
+
};
|
|
18889
|
+
}
|
|
18890
|
+
async doStream(options) {
|
|
18891
|
+
var _a10;
|
|
18892
|
+
const { args, warnings } = await this.getArgs(options);
|
|
18893
|
+
const body = {
|
|
18894
|
+
...args,
|
|
18895
|
+
stream: true,
|
|
18896
|
+
stream_options: {
|
|
18897
|
+
include_usage: true
|
|
18898
|
+
}
|
|
18899
|
+
};
|
|
18900
|
+
const { responseHeaders, value: response } = await postJsonToApi$1({
|
|
18901
|
+
url: `${(_a10 = this.config.baseURL) != null ? _a10 : "https://api.x.ai/v1"}/chat/completions`,
|
|
18902
|
+
headers: combineHeaders$1(this.config.headers(), options.headers),
|
|
18903
|
+
body,
|
|
18904
|
+
failedResponseHandler: xaiFailedResponseHandler,
|
|
18905
|
+
successfulResponseHandler: createEventSourceResponseHandler$1(xaiChatChunkSchema),
|
|
18906
|
+
abortSignal: options.abortSignal,
|
|
18907
|
+
fetch: this.config.fetch
|
|
18908
|
+
});
|
|
18909
|
+
let finishReason = "unknown";
|
|
18910
|
+
const usage = {
|
|
18911
|
+
inputTokens: void 0,
|
|
18912
|
+
outputTokens: void 0,
|
|
18913
|
+
totalTokens: void 0
|
|
18914
|
+
};
|
|
18915
|
+
let isFirstChunk = true;
|
|
18916
|
+
const contentBlocks = {};
|
|
18917
|
+
const lastReasoningDeltas = {};
|
|
18918
|
+
const self = this;
|
|
18919
|
+
return {
|
|
18920
|
+
stream: response.pipeThrough(
|
|
18921
|
+
new TransformStream({
|
|
18922
|
+
start(controller) {
|
|
18923
|
+
controller.enqueue({ type: "stream-start", warnings });
|
|
18924
|
+
},
|
|
18925
|
+
transform(chunk, controller) {
|
|
18926
|
+
var _a22, _b;
|
|
18927
|
+
if (options.includeRawChunks) {
|
|
18928
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
18929
|
+
}
|
|
18930
|
+
if (!chunk.success) {
|
|
18931
|
+
controller.enqueue({ type: "error", error: chunk.error });
|
|
18932
|
+
return;
|
|
18933
|
+
}
|
|
18934
|
+
const value = chunk.value;
|
|
18935
|
+
if (isFirstChunk) {
|
|
18936
|
+
controller.enqueue({
|
|
18937
|
+
type: "response-metadata",
|
|
18938
|
+
...getResponseMetadata$1(value)
|
|
18939
|
+
});
|
|
18940
|
+
isFirstChunk = false;
|
|
18941
|
+
}
|
|
18942
|
+
if (value.citations != null) {
|
|
18943
|
+
for (const url2 of value.citations) {
|
|
18944
|
+
controller.enqueue({
|
|
18945
|
+
type: "source",
|
|
18946
|
+
sourceType: "url",
|
|
18947
|
+
id: self.config.generateId(),
|
|
18948
|
+
url: url2
|
|
18949
|
+
});
|
|
18950
|
+
}
|
|
18951
|
+
}
|
|
18952
|
+
if (value.usage != null) {
|
|
18953
|
+
usage.inputTokens = value.usage.prompt_tokens;
|
|
18954
|
+
usage.outputTokens = value.usage.completion_tokens;
|
|
18955
|
+
usage.totalTokens = value.usage.total_tokens;
|
|
18956
|
+
usage.reasoningTokens = (_b = (_a22 = value.usage.completion_tokens_details) == null ? void 0 : _a22.reasoning_tokens) != null ? _b : void 0;
|
|
18957
|
+
}
|
|
18958
|
+
const choice = value.choices[0];
|
|
18959
|
+
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
18960
|
+
finishReason = mapXaiFinishReason(choice.finish_reason);
|
|
18961
|
+
}
|
|
18962
|
+
if ((choice == null ? void 0 : choice.delta) == null) {
|
|
18963
|
+
return;
|
|
18964
|
+
}
|
|
18965
|
+
const delta = choice.delta;
|
|
18966
|
+
const choiceIndex = choice.index;
|
|
18967
|
+
if (delta.content != null && delta.content.length > 0) {
|
|
18968
|
+
const textContent = delta.content;
|
|
18969
|
+
const lastMessage = body.messages[body.messages.length - 1];
|
|
18970
|
+
if ((lastMessage == null ? void 0 : lastMessage.role) === "assistant" && textContent === lastMessage.content) {
|
|
18971
|
+
return;
|
|
18972
|
+
}
|
|
18973
|
+
const blockId = `text-${value.id || choiceIndex}`;
|
|
18974
|
+
if (contentBlocks[blockId] == null) {
|
|
18975
|
+
contentBlocks[blockId] = { type: "text" };
|
|
18976
|
+
controller.enqueue({
|
|
18977
|
+
type: "text-start",
|
|
18978
|
+
id: blockId
|
|
18979
|
+
});
|
|
18980
|
+
}
|
|
18981
|
+
controller.enqueue({
|
|
18982
|
+
type: "text-delta",
|
|
18983
|
+
id: blockId,
|
|
18984
|
+
delta: textContent
|
|
18985
|
+
});
|
|
18986
|
+
}
|
|
18987
|
+
if (delta.reasoning_content != null && delta.reasoning_content.length > 0) {
|
|
18988
|
+
const blockId = `reasoning-${value.id || choiceIndex}`;
|
|
18989
|
+
if (lastReasoningDeltas[blockId] === delta.reasoning_content) {
|
|
18990
|
+
return;
|
|
18991
|
+
}
|
|
18992
|
+
lastReasoningDeltas[blockId] = delta.reasoning_content;
|
|
18993
|
+
if (contentBlocks[blockId] == null) {
|
|
18994
|
+
contentBlocks[blockId] = { type: "reasoning" };
|
|
18995
|
+
controller.enqueue({
|
|
18996
|
+
type: "reasoning-start",
|
|
18997
|
+
id: blockId
|
|
18998
|
+
});
|
|
18999
|
+
}
|
|
19000
|
+
controller.enqueue({
|
|
19001
|
+
type: "reasoning-delta",
|
|
19002
|
+
id: blockId,
|
|
19003
|
+
delta: delta.reasoning_content
|
|
19004
|
+
});
|
|
19005
|
+
}
|
|
19006
|
+
if (delta.tool_calls != null) {
|
|
19007
|
+
for (const toolCall of delta.tool_calls) {
|
|
19008
|
+
const toolCallId = toolCall.id;
|
|
19009
|
+
controller.enqueue({
|
|
19010
|
+
type: "tool-input-start",
|
|
19011
|
+
id: toolCallId,
|
|
19012
|
+
toolName: toolCall.function.name
|
|
19013
|
+
});
|
|
19014
|
+
controller.enqueue({
|
|
19015
|
+
type: "tool-input-delta",
|
|
19016
|
+
id: toolCallId,
|
|
19017
|
+
delta: toolCall.function.arguments
|
|
19018
|
+
});
|
|
19019
|
+
controller.enqueue({
|
|
19020
|
+
type: "tool-input-end",
|
|
19021
|
+
id: toolCallId
|
|
19022
|
+
});
|
|
19023
|
+
controller.enqueue({
|
|
19024
|
+
type: "tool-call",
|
|
19025
|
+
toolCallId,
|
|
19026
|
+
toolName: toolCall.function.name,
|
|
19027
|
+
input: toolCall.function.arguments
|
|
19028
|
+
});
|
|
19029
|
+
}
|
|
19030
|
+
}
|
|
19031
|
+
},
|
|
19032
|
+
flush(controller) {
|
|
19033
|
+
for (const [blockId, block] of Object.entries(contentBlocks)) {
|
|
19034
|
+
controller.enqueue({
|
|
19035
|
+
type: block.type === "text" ? "text-end" : "reasoning-end",
|
|
19036
|
+
id: blockId
|
|
19037
|
+
});
|
|
17974
19038
|
}
|
|
17975
|
-
controller.enqueue({
|
|
17976
|
-
type: "finish",
|
|
17977
|
-
finishReason,
|
|
17978
|
-
usage,
|
|
17979
|
-
...{}
|
|
17980
|
-
});
|
|
19039
|
+
controller.enqueue({ type: "finish", finishReason, usage });
|
|
17981
19040
|
}
|
|
17982
19041
|
})
|
|
17983
19042
|
),
|
|
@@ -17986,18 +19045,27 @@ var GroqChatLanguageModel = class {
|
|
|
17986
19045
|
};
|
|
17987
19046
|
}
|
|
17988
19047
|
};
|
|
17989
|
-
var
|
|
19048
|
+
var xaiUsageSchema = object({
|
|
19049
|
+
prompt_tokens: number$1(),
|
|
19050
|
+
completion_tokens: number$1(),
|
|
19051
|
+
total_tokens: number$1(),
|
|
19052
|
+
completion_tokens_details: object({
|
|
19053
|
+
reasoning_tokens: number$1().nullish()
|
|
19054
|
+
}).nullish()
|
|
19055
|
+
});
|
|
19056
|
+
var xaiChatResponseSchema = object({
|
|
17990
19057
|
id: string$1().nullish(),
|
|
17991
19058
|
created: number$1().nullish(),
|
|
17992
19059
|
model: string$1().nullish(),
|
|
17993
19060
|
choices: array(
|
|
17994
19061
|
object({
|
|
17995
19062
|
message: object({
|
|
19063
|
+
role: literal("assistant"),
|
|
17996
19064
|
content: string$1().nullish(),
|
|
17997
|
-
|
|
19065
|
+
reasoning_content: string$1().nullish(),
|
|
17998
19066
|
tool_calls: array(
|
|
17999
19067
|
object({
|
|
18000
|
-
id: string$1()
|
|
19068
|
+
id: string$1(),
|
|
18001
19069
|
type: literal("function"),
|
|
18002
19070
|
function: object({
|
|
18003
19071
|
name: string$1(),
|
|
@@ -18010,228 +19078,84 @@ var groqChatResponseSchema = object({
|
|
|
18010
19078
|
finish_reason: string$1().nullish()
|
|
18011
19079
|
})
|
|
18012
19080
|
),
|
|
18013
|
-
|
|
18014
|
-
|
|
18015
|
-
|
|
18016
|
-
total_tokens: number$1().nullish()
|
|
18017
|
-
}).nullish()
|
|
19081
|
+
object: literal("chat.completion"),
|
|
19082
|
+
usage: xaiUsageSchema,
|
|
19083
|
+
citations: array(string$1().url()).nullish()
|
|
18018
19084
|
});
|
|
18019
|
-
var
|
|
18020
|
-
|
|
18021
|
-
|
|
18022
|
-
|
|
18023
|
-
|
|
18024
|
-
|
|
18025
|
-
object({
|
|
18026
|
-
|
|
18027
|
-
|
|
18028
|
-
|
|
18029
|
-
|
|
18030
|
-
|
|
18031
|
-
|
|
18032
|
-
|
|
18033
|
-
|
|
18034
|
-
|
|
18035
|
-
|
|
18036
|
-
arguments: string$1().nullish()
|
|
18037
|
-
})
|
|
19085
|
+
var xaiChatChunkSchema = object({
|
|
19086
|
+
id: string$1().nullish(),
|
|
19087
|
+
created: number$1().nullish(),
|
|
19088
|
+
model: string$1().nullish(),
|
|
19089
|
+
choices: array(
|
|
19090
|
+
object({
|
|
19091
|
+
delta: object({
|
|
19092
|
+
role: _enum(["assistant"]).optional(),
|
|
19093
|
+
content: string$1().nullish(),
|
|
19094
|
+
reasoning_content: string$1().nullish(),
|
|
19095
|
+
tool_calls: array(
|
|
19096
|
+
object({
|
|
19097
|
+
id: string$1(),
|
|
19098
|
+
type: literal("function"),
|
|
19099
|
+
function: object({
|
|
19100
|
+
name: string$1(),
|
|
19101
|
+
arguments: string$1()
|
|
18038
19102
|
})
|
|
18039
|
-
)
|
|
18040
|
-
|
|
18041
|
-
finish_reason: string$1().nullable().optional(),
|
|
18042
|
-
index: number$1()
|
|
18043
|
-
})
|
|
18044
|
-
),
|
|
18045
|
-
x_groq: object({
|
|
18046
|
-
usage: object({
|
|
18047
|
-
prompt_tokens: number$1().nullish(),
|
|
18048
|
-
completion_tokens: number$1().nullish(),
|
|
18049
|
-
total_tokens: number$1().nullish()
|
|
18050
|
-
}).nullish()
|
|
18051
|
-
}).nullish()
|
|
18052
|
-
}),
|
|
18053
|
-
groqErrorDataSchema
|
|
18054
|
-
]);
|
|
18055
|
-
var groqProviderOptionsSchema = object({
|
|
18056
|
-
language: string$1().nullish(),
|
|
18057
|
-
prompt: string$1().nullish(),
|
|
18058
|
-
responseFormat: string$1().nullish(),
|
|
18059
|
-
temperature: number$1().min(0).max(1).nullish(),
|
|
18060
|
-
timestampGranularities: array(string$1()).nullish()
|
|
18061
|
-
});
|
|
18062
|
-
var GroqTranscriptionModel = class {
|
|
18063
|
-
constructor(modelId, config2) {
|
|
18064
|
-
this.modelId = modelId;
|
|
18065
|
-
this.config = config2;
|
|
18066
|
-
this.specificationVersion = "v2";
|
|
18067
|
-
}
|
|
18068
|
-
get provider() {
|
|
18069
|
-
return this.config.provider;
|
|
18070
|
-
}
|
|
18071
|
-
async getArgs({
|
|
18072
|
-
audio,
|
|
18073
|
-
mediaType,
|
|
18074
|
-
providerOptions
|
|
18075
|
-
}) {
|
|
18076
|
-
var _a10, _b, _c, _d, _e;
|
|
18077
|
-
const warnings = [];
|
|
18078
|
-
const groqOptions = await parseProviderOptions({
|
|
18079
|
-
provider: "groq",
|
|
18080
|
-
providerOptions,
|
|
18081
|
-
schema: groqProviderOptionsSchema
|
|
18082
|
-
});
|
|
18083
|
-
const formData = new FormData();
|
|
18084
|
-
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
|
|
18085
|
-
formData.append("model", this.modelId);
|
|
18086
|
-
const fileExtension = mediaTypeToExtension(mediaType);
|
|
18087
|
-
formData.append(
|
|
18088
|
-
"file",
|
|
18089
|
-
new File([blob], "audio", { type: mediaType }),
|
|
18090
|
-
`audio.${fileExtension}`
|
|
18091
|
-
);
|
|
18092
|
-
if (groqOptions) {
|
|
18093
|
-
const transcriptionModelOptions = {
|
|
18094
|
-
language: (_a10 = groqOptions.language) != null ? _a10 : void 0,
|
|
18095
|
-
prompt: (_b = groqOptions.prompt) != null ? _b : void 0,
|
|
18096
|
-
response_format: (_c = groqOptions.responseFormat) != null ? _c : void 0,
|
|
18097
|
-
temperature: (_d = groqOptions.temperature) != null ? _d : void 0,
|
|
18098
|
-
timestamp_granularities: (_e = groqOptions.timestampGranularities) != null ? _e : void 0
|
|
18099
|
-
};
|
|
18100
|
-
for (const key in transcriptionModelOptions) {
|
|
18101
|
-
const value = transcriptionModelOptions[key];
|
|
18102
|
-
if (value !== void 0) {
|
|
18103
|
-
formData.append(key, String(value));
|
|
18104
|
-
}
|
|
18105
|
-
}
|
|
18106
|
-
}
|
|
18107
|
-
return {
|
|
18108
|
-
formData,
|
|
18109
|
-
warnings
|
|
18110
|
-
};
|
|
18111
|
-
}
|
|
18112
|
-
async doGenerate(options) {
|
|
18113
|
-
var _a10, _b, _c, _d, _e, _f, _g;
|
|
18114
|
-
const currentDate = (_c = (_b = (_a10 = this.config._internal) == null ? void 0 : _a10.currentDate) == null ? void 0 : _b.call(_a10)) != null ? _c : /* @__PURE__ */ new Date();
|
|
18115
|
-
const { formData, warnings } = await this.getArgs(options);
|
|
18116
|
-
const {
|
|
18117
|
-
value: response,
|
|
18118
|
-
responseHeaders,
|
|
18119
|
-
rawValue: rawResponse
|
|
18120
|
-
} = await postFormDataToApi({
|
|
18121
|
-
url: this.config.url({
|
|
18122
|
-
path: "/audio/transcriptions",
|
|
18123
|
-
modelId: this.modelId
|
|
19103
|
+
})
|
|
19104
|
+
).nullish()
|
|
18124
19105
|
}),
|
|
18125
|
-
|
|
18126
|
-
|
|
18127
|
-
failedResponseHandler: groqFailedResponseHandler,
|
|
18128
|
-
successfulResponseHandler: createJsonResponseHandler$1(
|
|
18129
|
-
groqTranscriptionResponseSchema
|
|
18130
|
-
),
|
|
18131
|
-
abortSignal: options.abortSignal,
|
|
18132
|
-
fetch: this.config.fetch
|
|
18133
|
-
});
|
|
18134
|
-
return {
|
|
18135
|
-
text: response.text,
|
|
18136
|
-
segments: (_e = (_d = response.segments) == null ? void 0 : _d.map((segment) => ({
|
|
18137
|
-
text: segment.text,
|
|
18138
|
-
startSecond: segment.start,
|
|
18139
|
-
endSecond: segment.end
|
|
18140
|
-
}))) != null ? _e : [],
|
|
18141
|
-
language: (_f = response.language) != null ? _f : void 0,
|
|
18142
|
-
durationInSeconds: (_g = response.duration) != null ? _g : void 0,
|
|
18143
|
-
warnings,
|
|
18144
|
-
response: {
|
|
18145
|
-
timestamp: currentDate,
|
|
18146
|
-
modelId: this.modelId,
|
|
18147
|
-
headers: responseHeaders,
|
|
18148
|
-
body: rawResponse
|
|
18149
|
-
}
|
|
18150
|
-
};
|
|
18151
|
-
}
|
|
18152
|
-
};
|
|
18153
|
-
var groqTranscriptionResponseSchema = object({
|
|
18154
|
-
text: string$1(),
|
|
18155
|
-
x_groq: object({
|
|
18156
|
-
id: string$1()
|
|
18157
|
-
}),
|
|
18158
|
-
// additional properties are returned when `response_format: 'verbose_json'` is
|
|
18159
|
-
task: string$1().nullish(),
|
|
18160
|
-
language: string$1().nullish(),
|
|
18161
|
-
duration: number$1().nullish(),
|
|
18162
|
-
segments: array(
|
|
18163
|
-
object({
|
|
18164
|
-
id: number$1(),
|
|
18165
|
-
seek: number$1(),
|
|
18166
|
-
start: number$1(),
|
|
18167
|
-
end: number$1(),
|
|
18168
|
-
text: string$1(),
|
|
18169
|
-
tokens: array(number$1()),
|
|
18170
|
-
temperature: number$1(),
|
|
18171
|
-
avg_logprob: number$1(),
|
|
18172
|
-
compression_ratio: number$1(),
|
|
18173
|
-
no_speech_prob: number$1()
|
|
19106
|
+
finish_reason: string$1().nullish(),
|
|
19107
|
+
index: number$1()
|
|
18174
19108
|
})
|
|
18175
|
-
)
|
|
18176
|
-
|
|
18177
|
-
|
|
18178
|
-
id: "groq.browser_search",
|
|
18179
|
-
name: "browser_search",
|
|
18180
|
-
inputSchema: object({})
|
|
19109
|
+
),
|
|
19110
|
+
usage: xaiUsageSchema.nullish(),
|
|
19111
|
+
citations: array(string$1().url()).nullish()
|
|
18181
19112
|
});
|
|
18182
|
-
var
|
|
18183
|
-
|
|
19113
|
+
var xaiErrorStructure = {
|
|
19114
|
+
errorSchema: xaiErrorDataSchema,
|
|
19115
|
+
errorToMessage: (data) => data.error.message
|
|
18184
19116
|
};
|
|
18185
|
-
function
|
|
19117
|
+
function createXai(options = {}) {
|
|
18186
19118
|
var _a10;
|
|
18187
|
-
const baseURL =
|
|
19119
|
+
const baseURL = withoutTrailingSlash$1(
|
|
19120
|
+
(_a10 = options.baseURL) != null ? _a10 : "https://api.x.ai/v1"
|
|
19121
|
+
);
|
|
18188
19122
|
const getHeaders = () => ({
|
|
18189
19123
|
Authorization: `Bearer ${loadApiKey$1({
|
|
18190
19124
|
apiKey: options.apiKey,
|
|
18191
|
-
environmentVariableName: "
|
|
18192
|
-
description: "
|
|
19125
|
+
environmentVariableName: "XAI_API_KEY",
|
|
19126
|
+
description: "xAI API key"
|
|
18193
19127
|
})}`,
|
|
18194
19128
|
...options.headers
|
|
18195
19129
|
});
|
|
18196
|
-
const createChatModel = (modelId) => new GroqChatLanguageModel(modelId, {
|
|
18197
|
-
provider: "groq.chat",
|
|
18198
|
-
url: ({ path }) => `${baseURL}${path}`,
|
|
18199
|
-
headers: getHeaders,
|
|
18200
|
-
fetch: options.fetch
|
|
18201
|
-
});
|
|
18202
19130
|
const createLanguageModel = (modelId) => {
|
|
18203
|
-
|
|
18204
|
-
|
|
18205
|
-
|
|
18206
|
-
);
|
|
18207
|
-
}
|
|
18208
|
-
return createChatModel(modelId);
|
|
18209
|
-
};
|
|
18210
|
-
const createTranscriptionModel = (modelId) => {
|
|
18211
|
-
return new GroqTranscriptionModel(modelId, {
|
|
18212
|
-
provider: "groq.transcription",
|
|
18213
|
-
url: ({ path }) => `${baseURL}${path}`,
|
|
19131
|
+
return new XaiChatLanguageModel(modelId, {
|
|
19132
|
+
provider: "xai.chat",
|
|
19133
|
+
baseURL,
|
|
18214
19134
|
headers: getHeaders,
|
|
19135
|
+
generateId: generateId$1,
|
|
18215
19136
|
fetch: options.fetch
|
|
18216
19137
|
});
|
|
18217
19138
|
};
|
|
18218
|
-
const
|
|
18219
|
-
return
|
|
19139
|
+
const createImageModel = (modelId) => {
|
|
19140
|
+
return new OpenAICompatibleImageModel(modelId, {
|
|
19141
|
+
provider: "xai.image",
|
|
19142
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
19143
|
+
headers: getHeaders,
|
|
19144
|
+
fetch: options.fetch,
|
|
19145
|
+
errorStructure: xaiErrorStructure
|
|
19146
|
+
});
|
|
18220
19147
|
};
|
|
19148
|
+
const provider = (modelId) => createLanguageModel(modelId);
|
|
18221
19149
|
provider.languageModel = createLanguageModel;
|
|
18222
|
-
provider.chat =
|
|
19150
|
+
provider.chat = createLanguageModel;
|
|
18223
19151
|
provider.textEmbeddingModel = (modelId) => {
|
|
18224
19152
|
throw new NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
|
|
18225
19153
|
};
|
|
18226
|
-
provider.imageModel =
|
|
18227
|
-
|
|
18228
|
-
};
|
|
18229
|
-
provider.transcription = createTranscriptionModel;
|
|
18230
|
-
provider.transcriptionModel = createTranscriptionModel;
|
|
18231
|
-
provider.tools = groqTools;
|
|
19154
|
+
provider.imageModel = createImageModel;
|
|
19155
|
+
provider.image = createImageModel;
|
|
18232
19156
|
return provider;
|
|
18233
19157
|
}
|
|
18234
|
-
|
|
19158
|
+
createXai();
|
|
18235
19159
|
var openaiErrorDataSchema = object({
|
|
18236
19160
|
error: object({
|
|
18237
19161
|
message: string$1(),
|
|
@@ -26957,6 +27881,18 @@ function createEchoGroq({ appId, baseRouterUrl = ROUTER_BASE_URL }, getTokenFn,
|
|
|
26957
27881
|
)
|
|
26958
27882
|
});
|
|
26959
27883
|
}
|
|
27884
|
+
function createEchoXAI({ appId, baseRouterUrl = ROUTER_BASE_URL }, getTokenFn, onInsufficientFunds) {
|
|
27885
|
+
validateAppId(appId, "createEchoXAI");
|
|
27886
|
+
return createXai({
|
|
27887
|
+
baseURL: baseRouterUrl,
|
|
27888
|
+
apiKey: "placeholder_replaced_by_echoFetch",
|
|
27889
|
+
fetch: echoFetch(
|
|
27890
|
+
fetch,
|
|
27891
|
+
async () => await getTokenFn(appId),
|
|
27892
|
+
onInsufficientFunds
|
|
27893
|
+
)
|
|
27894
|
+
});
|
|
27895
|
+
}
|
|
26960
27896
|
function createEchoOpenAI({ appId, baseRouterUrl = ROUTER_BASE_URL }, getTokenFn, onInsufficientFunds) {
|
|
26961
27897
|
validateAppId(appId, "createEchoOpenAI");
|
|
26962
27898
|
return createOpenAI({
|
|
@@ -30000,7 +30936,8 @@ const useEchoModelProviders = () => {
|
|
|
30000
30936
|
getToken,
|
|
30001
30937
|
onInsufficientFunds
|
|
30002
30938
|
),
|
|
30003
|
-
groq: createEchoGroq(baseConfig, getToken, onInsufficientFunds)
|
|
30939
|
+
groq: createEchoGroq(baseConfig, getToken, onInsufficientFunds),
|
|
30940
|
+
xai: createEchoXAI(baseConfig, getToken, onInsufficientFunds)
|
|
30004
30941
|
};
|
|
30005
30942
|
}, [getToken, config2.appId, config2.baseRouterUrl, setIsInsufficientFunds]);
|
|
30006
30943
|
};
|