@mastra/rag 0.1.19-alpha.4 → 0.1.19-alpha.5
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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +7 -0
- package/dist/index.cjs +160 -22
- package/dist/index.js +160 -22
- package/package.json +2 -2
- package/vitest.config.ts +0 -3
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/rag@0.1.19-alpha.
|
|
2
|
+
> @mastra/rag@0.1.19-alpha.5 build /home/runner/work/mastra/mastra/packages/rag
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.4.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 14392ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.2
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/packages/rag/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.8.2
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/packages/rag/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 16255ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
20
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m224.12 KB[39m
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 4278ms
|
|
22
|
+
[32mESM[39m [1mdist/index.js [22m[32m222.34 KB[39m
|
|
23
|
+
[32mESM[39m ⚡️ Build success in 4286ms
|
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -137,7 +137,7 @@ var require_secure_json_parse = __commonJS({
|
|
|
137
137
|
}
|
|
138
138
|
});
|
|
139
139
|
|
|
140
|
-
// ../../node_modules/.pnpm/@ai-sdk+provider@1.1.
|
|
140
|
+
// ../../node_modules/.pnpm/@ai-sdk+provider@1.1.3/node_modules/@ai-sdk/provider/dist/index.mjs
|
|
141
141
|
var marker = "vercel.ai.error";
|
|
142
142
|
var symbol = Symbol.for(marker);
|
|
143
143
|
var _a;
|
|
@@ -417,7 +417,7 @@ var customAlphabet = (alphabet, defaultSize = 21) => {
|
|
|
417
417
|
};
|
|
418
418
|
};
|
|
419
419
|
|
|
420
|
-
// ../../node_modules/.pnpm/@ai-sdk+provider-utils@2.2.
|
|
420
|
+
// ../../node_modules/.pnpm/@ai-sdk+provider-utils@2.2.7_zod@3.24.3/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
421
421
|
var import_secure_json_parse = __toESM(require_secure_json_parse());
|
|
422
422
|
function combineHeaders(...headers) {
|
|
423
423
|
return headers.reduce(
|
|
@@ -925,6 +925,36 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
|
|
|
925
925
|
rawValue: parsedResult.rawValue
|
|
926
926
|
};
|
|
927
927
|
};
|
|
928
|
+
var createBinaryResponseHandler = () => async ({ response, url, requestBodyValues }) => {
|
|
929
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
930
|
+
if (!response.body) {
|
|
931
|
+
throw new APICallError({
|
|
932
|
+
message: "Response body is empty",
|
|
933
|
+
url,
|
|
934
|
+
requestBodyValues,
|
|
935
|
+
statusCode: response.status,
|
|
936
|
+
responseHeaders,
|
|
937
|
+
responseBody: void 0
|
|
938
|
+
});
|
|
939
|
+
}
|
|
940
|
+
try {
|
|
941
|
+
const buffer = await response.arrayBuffer();
|
|
942
|
+
return {
|
|
943
|
+
responseHeaders,
|
|
944
|
+
value: new Uint8Array(buffer)
|
|
945
|
+
};
|
|
946
|
+
} catch (error) {
|
|
947
|
+
throw new APICallError({
|
|
948
|
+
message: "Failed to read response as array buffer",
|
|
949
|
+
url,
|
|
950
|
+
requestBodyValues,
|
|
951
|
+
statusCode: response.status,
|
|
952
|
+
responseHeaders,
|
|
953
|
+
responseBody: void 0,
|
|
954
|
+
cause: error
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
};
|
|
928
958
|
var { btoa, atob } = globalThis;
|
|
929
959
|
function convertBase64ToUint8Array(base64String) {
|
|
930
960
|
const base64Url = base64String.replace(/-/g, "+").replace(/_/g, "/");
|
|
@@ -1426,6 +1456,15 @@ var OpenAIChatLanguageModel = class {
|
|
|
1426
1456
|
}
|
|
1427
1457
|
baseArgs.max_tokens = void 0;
|
|
1428
1458
|
}
|
|
1459
|
+
} else if (this.modelId.startsWith("gpt-4o-search-preview") || this.modelId.startsWith("gpt-4o-mini-search-preview")) {
|
|
1460
|
+
if (baseArgs.temperature != null) {
|
|
1461
|
+
baseArgs.temperature = void 0;
|
|
1462
|
+
warnings.push({
|
|
1463
|
+
type: "unsupported-setting",
|
|
1464
|
+
setting: "temperature",
|
|
1465
|
+
details: "temperature is not supported for the search preview models and has been removed."
|
|
1466
|
+
});
|
|
1467
|
+
}
|
|
1429
1468
|
}
|
|
1430
1469
|
switch (type) {
|
|
1431
1470
|
case "regular": {
|
|
@@ -1934,7 +1973,7 @@ var openaiChatChunkSchema = zod.z.union([
|
|
|
1934
1973
|
openaiErrorDataSchema
|
|
1935
1974
|
]);
|
|
1936
1975
|
function isReasoningModel(modelId) {
|
|
1937
|
-
return modelId
|
|
1976
|
+
return modelId.startsWith("o");
|
|
1938
1977
|
}
|
|
1939
1978
|
function isAudioModel(modelId) {
|
|
1940
1979
|
return modelId.startsWith("gpt-4o-audio-preview");
|
|
@@ -2465,18 +2504,12 @@ var OpenAIImageModel = class {
|
|
|
2465
2504
|
var openaiImageResponseSchema = zod.z.object({
|
|
2466
2505
|
data: zod.z.array(zod.z.object({ b64_json: zod.z.string() }))
|
|
2467
2506
|
});
|
|
2468
|
-
var
|
|
2469
|
-
include: zod.z.array(zod.z.string()).
|
|
2470
|
-
|
|
2471
|
-
),
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
"An optional text to guide the model's style or continue a previous audio segment."
|
|
2475
|
-
),
|
|
2476
|
-
temperature: zod.z.number().min(0).max(1).optional().default(0).describe("The sampling temperature, between 0 and 1."),
|
|
2477
|
-
timestampGranularities: zod.z.array(zod.z.enum(["word", "segment"])).optional().default(["segment"]).describe(
|
|
2478
|
-
"The timestamp granularities to populate for this transcription."
|
|
2479
|
-
)
|
|
2507
|
+
var openAIProviderOptionsSchema = zod.z.object({
|
|
2508
|
+
include: zod.z.array(zod.z.string()).nullish(),
|
|
2509
|
+
language: zod.z.string().nullish(),
|
|
2510
|
+
prompt: zod.z.string().nullish(),
|
|
2511
|
+
temperature: zod.z.number().min(0).max(1).nullish().default(0),
|
|
2512
|
+
timestampGranularities: zod.z.array(zod.z.enum(["word", "segment"])).nullish().default(["segment"])
|
|
2480
2513
|
});
|
|
2481
2514
|
var languageMap = {
|
|
2482
2515
|
afrikaans: "af",
|
|
@@ -2551,11 +2584,12 @@ var OpenAITranscriptionModel = class {
|
|
|
2551
2584
|
mediaType,
|
|
2552
2585
|
providerOptions
|
|
2553
2586
|
}) {
|
|
2587
|
+
var _a15, _b, _c, _d, _e;
|
|
2554
2588
|
const warnings = [];
|
|
2555
2589
|
const openAIOptions = parseProviderOptions({
|
|
2556
2590
|
provider: "openai",
|
|
2557
2591
|
providerOptions,
|
|
2558
|
-
schema:
|
|
2592
|
+
schema: openAIProviderOptionsSchema
|
|
2559
2593
|
});
|
|
2560
2594
|
const formData = new FormData();
|
|
2561
2595
|
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
|
|
@@ -2563,16 +2597,16 @@ var OpenAITranscriptionModel = class {
|
|
|
2563
2597
|
formData.append("file", new File([blob], "audio", { type: mediaType }));
|
|
2564
2598
|
if (openAIOptions) {
|
|
2565
2599
|
const transcriptionModelOptions = {
|
|
2566
|
-
include: openAIOptions.include,
|
|
2567
|
-
language: openAIOptions.language,
|
|
2568
|
-
prompt: openAIOptions.prompt,
|
|
2569
|
-
temperature: openAIOptions.temperature,
|
|
2570
|
-
timestamp_granularities: openAIOptions.timestampGranularities
|
|
2600
|
+
include: (_a15 = openAIOptions.include) != null ? _a15 : void 0,
|
|
2601
|
+
language: (_b = openAIOptions.language) != null ? _b : void 0,
|
|
2602
|
+
prompt: (_c = openAIOptions.prompt) != null ? _c : void 0,
|
|
2603
|
+
temperature: (_d = openAIOptions.temperature) != null ? _d : void 0,
|
|
2604
|
+
timestamp_granularities: (_e = openAIOptions.timestampGranularities) != null ? _e : void 0
|
|
2571
2605
|
};
|
|
2572
2606
|
for (const key in transcriptionModelOptions) {
|
|
2573
2607
|
const value = transcriptionModelOptions[key];
|
|
2574
2608
|
if (value !== void 0) {
|
|
2575
|
-
formData.append(key, value);
|
|
2609
|
+
formData.append(key, String(value));
|
|
2576
2610
|
}
|
|
2577
2611
|
}
|
|
2578
2612
|
}
|
|
@@ -2851,6 +2885,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2851
2885
|
constructor(modelId, config) {
|
|
2852
2886
|
this.specificationVersion = "v1";
|
|
2853
2887
|
this.defaultObjectGenerationMode = "json";
|
|
2888
|
+
this.supportsStructuredOutputs = true;
|
|
2854
2889
|
this.modelId = modelId;
|
|
2855
2890
|
this.config = config;
|
|
2856
2891
|
}
|
|
@@ -3432,6 +3467,101 @@ function webSearchPreviewTool({
|
|
|
3432
3467
|
var openaiTools = {
|
|
3433
3468
|
webSearchPreview: webSearchPreviewTool
|
|
3434
3469
|
};
|
|
3470
|
+
var OpenAIProviderOptionsSchema = zod.z.object({
|
|
3471
|
+
instructions: zod.z.string().nullish(),
|
|
3472
|
+
speed: zod.z.number().min(0.25).max(4).default(1).nullish()
|
|
3473
|
+
});
|
|
3474
|
+
var OpenAISpeechModel = class {
|
|
3475
|
+
constructor(modelId, config) {
|
|
3476
|
+
this.modelId = modelId;
|
|
3477
|
+
this.config = config;
|
|
3478
|
+
this.specificationVersion = "v1";
|
|
3479
|
+
}
|
|
3480
|
+
get provider() {
|
|
3481
|
+
return this.config.provider;
|
|
3482
|
+
}
|
|
3483
|
+
getArgs({
|
|
3484
|
+
text,
|
|
3485
|
+
voice = "alloy",
|
|
3486
|
+
outputFormat = "mp3",
|
|
3487
|
+
speed,
|
|
3488
|
+
instructions,
|
|
3489
|
+
providerOptions
|
|
3490
|
+
}) {
|
|
3491
|
+
const warnings = [];
|
|
3492
|
+
const openAIOptions = parseProviderOptions({
|
|
3493
|
+
provider: "openai",
|
|
3494
|
+
providerOptions,
|
|
3495
|
+
schema: OpenAIProviderOptionsSchema
|
|
3496
|
+
});
|
|
3497
|
+
const requestBody = {
|
|
3498
|
+
model: this.modelId,
|
|
3499
|
+
input: text,
|
|
3500
|
+
voice,
|
|
3501
|
+
response_format: "mp3",
|
|
3502
|
+
speed,
|
|
3503
|
+
instructions
|
|
3504
|
+
};
|
|
3505
|
+
if (outputFormat) {
|
|
3506
|
+
if (["mp3", "opus", "aac", "flac", "wav", "pcm"].includes(outputFormat)) {
|
|
3507
|
+
requestBody.response_format = outputFormat;
|
|
3508
|
+
} else {
|
|
3509
|
+
warnings.push({
|
|
3510
|
+
type: "unsupported-setting",
|
|
3511
|
+
setting: "outputFormat",
|
|
3512
|
+
details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`
|
|
3513
|
+
});
|
|
3514
|
+
}
|
|
3515
|
+
}
|
|
3516
|
+
if (openAIOptions) {
|
|
3517
|
+
const speechModelOptions = {};
|
|
3518
|
+
for (const key in speechModelOptions) {
|
|
3519
|
+
const value = speechModelOptions[key];
|
|
3520
|
+
if (value !== void 0) {
|
|
3521
|
+
requestBody[key] = value;
|
|
3522
|
+
}
|
|
3523
|
+
}
|
|
3524
|
+
}
|
|
3525
|
+
return {
|
|
3526
|
+
requestBody,
|
|
3527
|
+
warnings
|
|
3528
|
+
};
|
|
3529
|
+
}
|
|
3530
|
+
async doGenerate(options) {
|
|
3531
|
+
var _a15, _b, _c;
|
|
3532
|
+
const currentDate = (_c = (_b = (_a15 = this.config._internal) == null ? void 0 : _a15.currentDate) == null ? void 0 : _b.call(_a15)) != null ? _c : /* @__PURE__ */ new Date();
|
|
3533
|
+
const { requestBody, warnings } = this.getArgs(options);
|
|
3534
|
+
const {
|
|
3535
|
+
value: audio,
|
|
3536
|
+
responseHeaders,
|
|
3537
|
+
rawValue: rawResponse
|
|
3538
|
+
} = await postJsonToApi({
|
|
3539
|
+
url: this.config.url({
|
|
3540
|
+
path: "/audio/speech",
|
|
3541
|
+
modelId: this.modelId
|
|
3542
|
+
}),
|
|
3543
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
3544
|
+
body: requestBody,
|
|
3545
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
3546
|
+
successfulResponseHandler: createBinaryResponseHandler(),
|
|
3547
|
+
abortSignal: options.abortSignal,
|
|
3548
|
+
fetch: this.config.fetch
|
|
3549
|
+
});
|
|
3550
|
+
return {
|
|
3551
|
+
audio,
|
|
3552
|
+
warnings,
|
|
3553
|
+
request: {
|
|
3554
|
+
body: JSON.stringify(requestBody)
|
|
3555
|
+
},
|
|
3556
|
+
response: {
|
|
3557
|
+
timestamp: currentDate,
|
|
3558
|
+
modelId: this.modelId,
|
|
3559
|
+
headers: responseHeaders,
|
|
3560
|
+
body: rawResponse
|
|
3561
|
+
}
|
|
3562
|
+
};
|
|
3563
|
+
}
|
|
3564
|
+
};
|
|
3435
3565
|
function createOpenAI(options = {}) {
|
|
3436
3566
|
var _a15, _b, _c;
|
|
3437
3567
|
const baseURL = (_a15 = withoutTrailingSlash(options.baseURL)) != null ? _a15 : "https://api.openai.com/v1";
|
|
@@ -3479,6 +3609,12 @@ function createOpenAI(options = {}) {
|
|
|
3479
3609
|
headers: getHeaders,
|
|
3480
3610
|
fetch: options.fetch
|
|
3481
3611
|
});
|
|
3612
|
+
const createSpeechModel = (modelId) => new OpenAISpeechModel(modelId, {
|
|
3613
|
+
provider: `${providerName}.speech`,
|
|
3614
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
3615
|
+
headers: getHeaders,
|
|
3616
|
+
fetch: options.fetch
|
|
3617
|
+
});
|
|
3482
3618
|
const createLanguageModel = (modelId, settings) => {
|
|
3483
3619
|
if (new.target) {
|
|
3484
3620
|
throw new Error(
|
|
@@ -3515,6 +3651,8 @@ function createOpenAI(options = {}) {
|
|
|
3515
3651
|
provider.imageModel = createImageModel;
|
|
3516
3652
|
provider.transcription = createTranscriptionModel;
|
|
3517
3653
|
provider.transcriptionModel = createTranscriptionModel;
|
|
3654
|
+
provider.speech = createSpeechModel;
|
|
3655
|
+
provider.speechModel = createSpeechModel;
|
|
3518
3656
|
provider.tools = openaiTools;
|
|
3519
3657
|
return provider;
|
|
3520
3658
|
}
|
package/dist/index.js
CHANGED
|
@@ -135,7 +135,7 @@ var require_secure_json_parse = __commonJS({
|
|
|
135
135
|
}
|
|
136
136
|
});
|
|
137
137
|
|
|
138
|
-
// ../../node_modules/.pnpm/@ai-sdk+provider@1.1.
|
|
138
|
+
// ../../node_modules/.pnpm/@ai-sdk+provider@1.1.3/node_modules/@ai-sdk/provider/dist/index.mjs
|
|
139
139
|
var marker = "vercel.ai.error";
|
|
140
140
|
var symbol = Symbol.for(marker);
|
|
141
141
|
var _a;
|
|
@@ -415,7 +415,7 @@ var customAlphabet = (alphabet, defaultSize = 21) => {
|
|
|
415
415
|
};
|
|
416
416
|
};
|
|
417
417
|
|
|
418
|
-
// ../../node_modules/.pnpm/@ai-sdk+provider-utils@2.2.
|
|
418
|
+
// ../../node_modules/.pnpm/@ai-sdk+provider-utils@2.2.7_zod@3.24.3/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
419
419
|
var import_secure_json_parse = __toESM(require_secure_json_parse());
|
|
420
420
|
function combineHeaders(...headers) {
|
|
421
421
|
return headers.reduce(
|
|
@@ -923,6 +923,36 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
|
|
|
923
923
|
rawValue: parsedResult.rawValue
|
|
924
924
|
};
|
|
925
925
|
};
|
|
926
|
+
var createBinaryResponseHandler = () => async ({ response, url, requestBodyValues }) => {
|
|
927
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
928
|
+
if (!response.body) {
|
|
929
|
+
throw new APICallError({
|
|
930
|
+
message: "Response body is empty",
|
|
931
|
+
url,
|
|
932
|
+
requestBodyValues,
|
|
933
|
+
statusCode: response.status,
|
|
934
|
+
responseHeaders,
|
|
935
|
+
responseBody: void 0
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
try {
|
|
939
|
+
const buffer = await response.arrayBuffer();
|
|
940
|
+
return {
|
|
941
|
+
responseHeaders,
|
|
942
|
+
value: new Uint8Array(buffer)
|
|
943
|
+
};
|
|
944
|
+
} catch (error) {
|
|
945
|
+
throw new APICallError({
|
|
946
|
+
message: "Failed to read response as array buffer",
|
|
947
|
+
url,
|
|
948
|
+
requestBodyValues,
|
|
949
|
+
statusCode: response.status,
|
|
950
|
+
responseHeaders,
|
|
951
|
+
responseBody: void 0,
|
|
952
|
+
cause: error
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
};
|
|
926
956
|
var { btoa, atob } = globalThis;
|
|
927
957
|
function convertBase64ToUint8Array(base64String) {
|
|
928
958
|
const base64Url = base64String.replace(/-/g, "+").replace(/_/g, "/");
|
|
@@ -1424,6 +1454,15 @@ var OpenAIChatLanguageModel = class {
|
|
|
1424
1454
|
}
|
|
1425
1455
|
baseArgs.max_tokens = void 0;
|
|
1426
1456
|
}
|
|
1457
|
+
} else if (this.modelId.startsWith("gpt-4o-search-preview") || this.modelId.startsWith("gpt-4o-mini-search-preview")) {
|
|
1458
|
+
if (baseArgs.temperature != null) {
|
|
1459
|
+
baseArgs.temperature = void 0;
|
|
1460
|
+
warnings.push({
|
|
1461
|
+
type: "unsupported-setting",
|
|
1462
|
+
setting: "temperature",
|
|
1463
|
+
details: "temperature is not supported for the search preview models and has been removed."
|
|
1464
|
+
});
|
|
1465
|
+
}
|
|
1427
1466
|
}
|
|
1428
1467
|
switch (type) {
|
|
1429
1468
|
case "regular": {
|
|
@@ -1932,7 +1971,7 @@ var openaiChatChunkSchema = z.union([
|
|
|
1932
1971
|
openaiErrorDataSchema
|
|
1933
1972
|
]);
|
|
1934
1973
|
function isReasoningModel(modelId) {
|
|
1935
|
-
return modelId
|
|
1974
|
+
return modelId.startsWith("o");
|
|
1936
1975
|
}
|
|
1937
1976
|
function isAudioModel(modelId) {
|
|
1938
1977
|
return modelId.startsWith("gpt-4o-audio-preview");
|
|
@@ -2463,18 +2502,12 @@ var OpenAIImageModel = class {
|
|
|
2463
2502
|
var openaiImageResponseSchema = z.object({
|
|
2464
2503
|
data: z.array(z.object({ b64_json: z.string() }))
|
|
2465
2504
|
});
|
|
2466
|
-
var
|
|
2467
|
-
include: z.array(z.string()).
|
|
2468
|
-
|
|
2469
|
-
),
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
"An optional text to guide the model's style or continue a previous audio segment."
|
|
2473
|
-
),
|
|
2474
|
-
temperature: z.number().min(0).max(1).optional().default(0).describe("The sampling temperature, between 0 and 1."),
|
|
2475
|
-
timestampGranularities: z.array(z.enum(["word", "segment"])).optional().default(["segment"]).describe(
|
|
2476
|
-
"The timestamp granularities to populate for this transcription."
|
|
2477
|
-
)
|
|
2505
|
+
var openAIProviderOptionsSchema = z.object({
|
|
2506
|
+
include: z.array(z.string()).nullish(),
|
|
2507
|
+
language: z.string().nullish(),
|
|
2508
|
+
prompt: z.string().nullish(),
|
|
2509
|
+
temperature: z.number().min(0).max(1).nullish().default(0),
|
|
2510
|
+
timestampGranularities: z.array(z.enum(["word", "segment"])).nullish().default(["segment"])
|
|
2478
2511
|
});
|
|
2479
2512
|
var languageMap = {
|
|
2480
2513
|
afrikaans: "af",
|
|
@@ -2549,11 +2582,12 @@ var OpenAITranscriptionModel = class {
|
|
|
2549
2582
|
mediaType,
|
|
2550
2583
|
providerOptions
|
|
2551
2584
|
}) {
|
|
2585
|
+
var _a15, _b, _c, _d, _e;
|
|
2552
2586
|
const warnings = [];
|
|
2553
2587
|
const openAIOptions = parseProviderOptions({
|
|
2554
2588
|
provider: "openai",
|
|
2555
2589
|
providerOptions,
|
|
2556
|
-
schema:
|
|
2590
|
+
schema: openAIProviderOptionsSchema
|
|
2557
2591
|
});
|
|
2558
2592
|
const formData = new FormData();
|
|
2559
2593
|
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
|
|
@@ -2561,16 +2595,16 @@ var OpenAITranscriptionModel = class {
|
|
|
2561
2595
|
formData.append("file", new File([blob], "audio", { type: mediaType }));
|
|
2562
2596
|
if (openAIOptions) {
|
|
2563
2597
|
const transcriptionModelOptions = {
|
|
2564
|
-
include: openAIOptions.include,
|
|
2565
|
-
language: openAIOptions.language,
|
|
2566
|
-
prompt: openAIOptions.prompt,
|
|
2567
|
-
temperature: openAIOptions.temperature,
|
|
2568
|
-
timestamp_granularities: openAIOptions.timestampGranularities
|
|
2598
|
+
include: (_a15 = openAIOptions.include) != null ? _a15 : void 0,
|
|
2599
|
+
language: (_b = openAIOptions.language) != null ? _b : void 0,
|
|
2600
|
+
prompt: (_c = openAIOptions.prompt) != null ? _c : void 0,
|
|
2601
|
+
temperature: (_d = openAIOptions.temperature) != null ? _d : void 0,
|
|
2602
|
+
timestamp_granularities: (_e = openAIOptions.timestampGranularities) != null ? _e : void 0
|
|
2569
2603
|
};
|
|
2570
2604
|
for (const key in transcriptionModelOptions) {
|
|
2571
2605
|
const value = transcriptionModelOptions[key];
|
|
2572
2606
|
if (value !== void 0) {
|
|
2573
|
-
formData.append(key, value);
|
|
2607
|
+
formData.append(key, String(value));
|
|
2574
2608
|
}
|
|
2575
2609
|
}
|
|
2576
2610
|
}
|
|
@@ -2849,6 +2883,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2849
2883
|
constructor(modelId, config) {
|
|
2850
2884
|
this.specificationVersion = "v1";
|
|
2851
2885
|
this.defaultObjectGenerationMode = "json";
|
|
2886
|
+
this.supportsStructuredOutputs = true;
|
|
2852
2887
|
this.modelId = modelId;
|
|
2853
2888
|
this.config = config;
|
|
2854
2889
|
}
|
|
@@ -3430,6 +3465,101 @@ function webSearchPreviewTool({
|
|
|
3430
3465
|
var openaiTools = {
|
|
3431
3466
|
webSearchPreview: webSearchPreviewTool
|
|
3432
3467
|
};
|
|
3468
|
+
var OpenAIProviderOptionsSchema = z.object({
|
|
3469
|
+
instructions: z.string().nullish(),
|
|
3470
|
+
speed: z.number().min(0.25).max(4).default(1).nullish()
|
|
3471
|
+
});
|
|
3472
|
+
var OpenAISpeechModel = class {
|
|
3473
|
+
constructor(modelId, config) {
|
|
3474
|
+
this.modelId = modelId;
|
|
3475
|
+
this.config = config;
|
|
3476
|
+
this.specificationVersion = "v1";
|
|
3477
|
+
}
|
|
3478
|
+
get provider() {
|
|
3479
|
+
return this.config.provider;
|
|
3480
|
+
}
|
|
3481
|
+
getArgs({
|
|
3482
|
+
text,
|
|
3483
|
+
voice = "alloy",
|
|
3484
|
+
outputFormat = "mp3",
|
|
3485
|
+
speed,
|
|
3486
|
+
instructions,
|
|
3487
|
+
providerOptions
|
|
3488
|
+
}) {
|
|
3489
|
+
const warnings = [];
|
|
3490
|
+
const openAIOptions = parseProviderOptions({
|
|
3491
|
+
provider: "openai",
|
|
3492
|
+
providerOptions,
|
|
3493
|
+
schema: OpenAIProviderOptionsSchema
|
|
3494
|
+
});
|
|
3495
|
+
const requestBody = {
|
|
3496
|
+
model: this.modelId,
|
|
3497
|
+
input: text,
|
|
3498
|
+
voice,
|
|
3499
|
+
response_format: "mp3",
|
|
3500
|
+
speed,
|
|
3501
|
+
instructions
|
|
3502
|
+
};
|
|
3503
|
+
if (outputFormat) {
|
|
3504
|
+
if (["mp3", "opus", "aac", "flac", "wav", "pcm"].includes(outputFormat)) {
|
|
3505
|
+
requestBody.response_format = outputFormat;
|
|
3506
|
+
} else {
|
|
3507
|
+
warnings.push({
|
|
3508
|
+
type: "unsupported-setting",
|
|
3509
|
+
setting: "outputFormat",
|
|
3510
|
+
details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`
|
|
3511
|
+
});
|
|
3512
|
+
}
|
|
3513
|
+
}
|
|
3514
|
+
if (openAIOptions) {
|
|
3515
|
+
const speechModelOptions = {};
|
|
3516
|
+
for (const key in speechModelOptions) {
|
|
3517
|
+
const value = speechModelOptions[key];
|
|
3518
|
+
if (value !== void 0) {
|
|
3519
|
+
requestBody[key] = value;
|
|
3520
|
+
}
|
|
3521
|
+
}
|
|
3522
|
+
}
|
|
3523
|
+
return {
|
|
3524
|
+
requestBody,
|
|
3525
|
+
warnings
|
|
3526
|
+
};
|
|
3527
|
+
}
|
|
3528
|
+
async doGenerate(options) {
|
|
3529
|
+
var _a15, _b, _c;
|
|
3530
|
+
const currentDate = (_c = (_b = (_a15 = this.config._internal) == null ? void 0 : _a15.currentDate) == null ? void 0 : _b.call(_a15)) != null ? _c : /* @__PURE__ */ new Date();
|
|
3531
|
+
const { requestBody, warnings } = this.getArgs(options);
|
|
3532
|
+
const {
|
|
3533
|
+
value: audio,
|
|
3534
|
+
responseHeaders,
|
|
3535
|
+
rawValue: rawResponse
|
|
3536
|
+
} = await postJsonToApi({
|
|
3537
|
+
url: this.config.url({
|
|
3538
|
+
path: "/audio/speech",
|
|
3539
|
+
modelId: this.modelId
|
|
3540
|
+
}),
|
|
3541
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
3542
|
+
body: requestBody,
|
|
3543
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
3544
|
+
successfulResponseHandler: createBinaryResponseHandler(),
|
|
3545
|
+
abortSignal: options.abortSignal,
|
|
3546
|
+
fetch: this.config.fetch
|
|
3547
|
+
});
|
|
3548
|
+
return {
|
|
3549
|
+
audio,
|
|
3550
|
+
warnings,
|
|
3551
|
+
request: {
|
|
3552
|
+
body: JSON.stringify(requestBody)
|
|
3553
|
+
},
|
|
3554
|
+
response: {
|
|
3555
|
+
timestamp: currentDate,
|
|
3556
|
+
modelId: this.modelId,
|
|
3557
|
+
headers: responseHeaders,
|
|
3558
|
+
body: rawResponse
|
|
3559
|
+
}
|
|
3560
|
+
};
|
|
3561
|
+
}
|
|
3562
|
+
};
|
|
3433
3563
|
function createOpenAI(options = {}) {
|
|
3434
3564
|
var _a15, _b, _c;
|
|
3435
3565
|
const baseURL = (_a15 = withoutTrailingSlash(options.baseURL)) != null ? _a15 : "https://api.openai.com/v1";
|
|
@@ -3477,6 +3607,12 @@ function createOpenAI(options = {}) {
|
|
|
3477
3607
|
headers: getHeaders,
|
|
3478
3608
|
fetch: options.fetch
|
|
3479
3609
|
});
|
|
3610
|
+
const createSpeechModel = (modelId) => new OpenAISpeechModel(modelId, {
|
|
3611
|
+
provider: `${providerName}.speech`,
|
|
3612
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
3613
|
+
headers: getHeaders,
|
|
3614
|
+
fetch: options.fetch
|
|
3615
|
+
});
|
|
3480
3616
|
const createLanguageModel = (modelId, settings) => {
|
|
3481
3617
|
if (new.target) {
|
|
3482
3618
|
throw new Error(
|
|
@@ -3513,6 +3649,8 @@ function createOpenAI(options = {}) {
|
|
|
3513
3649
|
provider.imageModel = createImageModel;
|
|
3514
3650
|
provider.transcription = createTranscriptionModel;
|
|
3515
3651
|
provider.transcriptionModel = createTranscriptionModel;
|
|
3652
|
+
provider.speech = createSpeechModel;
|
|
3653
|
+
provider.speechModel = createSpeechModel;
|
|
3516
3654
|
provider.tools = openaiTools;
|
|
3517
3655
|
return provider;
|
|
3518
3656
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/rag",
|
|
3
|
-
"version": "0.1.19-alpha.
|
|
3
|
+
"version": "0.1.19-alpha.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"node-html-better-parser": "^1.4.7",
|
|
28
28
|
"pathe": "^2.0.3",
|
|
29
29
|
"zod": "^3.24.2",
|
|
30
|
-
"@mastra/core": "^0.9.0-alpha.
|
|
30
|
+
"@mastra/core": "^0.9.0-alpha.5"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"ai": "^4.0.0"
|