@mastra/server 0.0.0-revert-schema-20250416221206 → 0.0.0-safe-stringify-telemetry-20251205024938
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/CHANGELOG.md +4368 -0
- package/LICENSE.md +11 -42
- package/README.md +45 -137
- package/dist/chunk-2PLXW4ZX.cjs +2777 -0
- package/dist/chunk-2PLXW4ZX.cjs.map +1 -0
- package/dist/chunk-2S4IMB6E.cjs +130 -0
- package/dist/chunk-2S4IMB6E.cjs.map +1 -0
- package/dist/chunk-3SNGNFUJ.cjs +128 -0
- package/dist/chunk-3SNGNFUJ.cjs.map +1 -0
- package/dist/{chunk-L7XE5QTW.js → chunk-4QCXUEAT.js} +11 -2
- package/dist/chunk-4QCXUEAT.js.map +1 -0
- package/dist/{chunk-WTHDCRMY.js → chunk-67GYDFSB.js} +33 -8
- package/dist/chunk-67GYDFSB.js.map +1 -0
- package/dist/chunk-6N3HC6O4.js +705 -0
- package/dist/chunk-6N3HC6O4.js.map +1 -0
- package/dist/{chunk-7IWQE76Z.cjs → chunk-6ZR275MD.cjs} +37 -11
- package/dist/chunk-6ZR275MD.cjs.map +1 -0
- package/dist/{chunk-FV45V6WC.cjs → chunk-7NADHFD2.cjs} +3 -7
- package/dist/chunk-7NADHFD2.cjs.map +1 -0
- package/dist/chunk-7RGKOGE4.cjs +485 -0
- package/dist/chunk-7RGKOGE4.cjs.map +1 -0
- package/dist/chunk-ABRFV4XP.js +83 -0
- package/dist/chunk-ABRFV4XP.js.map +1 -0
- package/dist/{chunk-UV4WTEH4.js → chunk-AHB4JCIQ.js} +55 -15
- package/dist/chunk-AHB4JCIQ.js.map +1 -0
- package/dist/chunk-AW5BU3RQ.js +192 -0
- package/dist/chunk-AW5BU3RQ.js.map +1 -0
- package/dist/chunk-BATEJLED.js +124 -0
- package/dist/chunk-BATEJLED.js.map +1 -0
- package/dist/chunk-CY4TP3FK.js +16 -0
- package/dist/chunk-CY4TP3FK.js.map +1 -0
- package/dist/chunk-CY6R3HLM.cjs +727 -0
- package/dist/chunk-CY6R3HLM.cjs.map +1 -0
- package/dist/{chunk-M56ECCHK.cjs → chunk-EP3JQDPD.cjs} +22 -19
- package/dist/chunk-EP3JQDPD.cjs.map +1 -0
- package/dist/chunk-G4PUALCE.cjs +28 -0
- package/dist/chunk-G4PUALCE.cjs.map +1 -0
- package/dist/chunk-G5O5SC7R.cjs +19565 -0
- package/dist/chunk-G5O5SC7R.cjs.map +1 -0
- package/dist/chunk-GU4EWMZB.cjs +769 -0
- package/dist/chunk-GU4EWMZB.cjs.map +1 -0
- package/dist/chunk-I3C4ODGV.cjs +335 -0
- package/dist/chunk-I3C4ODGV.cjs.map +1 -0
- package/dist/chunk-IAE7SFBS.js +477 -0
- package/dist/chunk-IAE7SFBS.js.map +1 -0
- package/dist/chunk-LF2ZLOFP.js +767 -0
- package/dist/chunk-LF2ZLOFP.js.map +1 -0
- package/dist/{chunk-OPP7H5TW.js → chunk-LLUOPR3J.js} +92 -74
- package/dist/chunk-LLUOPR3J.js.map +1 -0
- package/dist/chunk-LPM6BBAX.cjs +1043 -0
- package/dist/chunk-LPM6BBAX.cjs.map +1 -0
- package/dist/{chunk-TRDNDNGQ.js → chunk-MMROOK5J.js} +4 -7
- package/dist/chunk-MMROOK5J.js.map +1 -0
- package/dist/{chunk-4JINXASC.js → chunk-MYR4PVGN.js} +7 -4
- package/dist/chunk-MYR4PVGN.js.map +1 -0
- package/dist/chunk-NT5XW5PI.cjs +596 -0
- package/dist/chunk-NT5XW5PI.cjs.map +1 -0
- package/dist/chunk-O7I5CWRX.cjs +44 -0
- package/dist/chunk-O7I5CWRX.cjs.map +1 -0
- package/dist/chunk-PBXWFGEH.js +579 -0
- package/dist/chunk-PBXWFGEH.js.map +1 -0
- package/dist/chunk-PR4QN5HX.js +39 -0
- package/dist/chunk-PR4QN5HX.js.map +1 -0
- package/dist/chunk-QGNHNNJR.js +909 -0
- package/dist/chunk-QGNHNNJR.js.map +1 -0
- package/dist/{chunk-3RVHWGWO.js → chunk-QQXMIP6C.js} +49 -22
- package/dist/chunk-QQXMIP6C.js.map +1 -0
- package/dist/chunk-QU6N55W6.cjs +256 -0
- package/dist/chunk-QU6N55W6.cjs.map +1 -0
- package/dist/chunk-RE4RPXT2.cjs +18 -0
- package/dist/chunk-RE4RPXT2.cjs.map +1 -0
- package/dist/chunk-RQK4FQUD.js +1012 -0
- package/dist/chunk-RQK4FQUD.js.map +1 -0
- package/dist/chunk-S6YZQY4V.cjs +938 -0
- package/dist/chunk-S6YZQY4V.cjs.map +1 -0
- package/dist/chunk-SHWNNZBL.js +254 -0
- package/dist/chunk-SHWNNZBL.js.map +1 -0
- package/dist/chunk-SPRRK3P7.cjs +200 -0
- package/dist/chunk-SPRRK3P7.cjs.map +1 -0
- package/dist/chunk-TOCYBDP2.js +46 -0
- package/dist/chunk-TOCYBDP2.js.map +1 -0
- package/dist/chunk-TRGAMKHX.cjs +167 -0
- package/dist/chunk-TRGAMKHX.cjs.map +1 -0
- package/dist/chunk-TRHCWKZ2.js +19529 -0
- package/dist/chunk-TRHCWKZ2.js.map +1 -0
- package/dist/chunk-VY4ENABS.cjs +135 -0
- package/dist/chunk-VY4ENABS.cjs.map +1 -0
- package/dist/chunk-X6C7BUWN.cjs +48 -0
- package/dist/chunk-X6C7BUWN.cjs.map +1 -0
- package/dist/chunk-XN74I6VW.cjs +88 -0
- package/dist/chunk-XN74I6VW.cjs.map +1 -0
- package/dist/chunk-YWOK4F5A.js +131 -0
- package/dist/chunk-YWOK4F5A.js.map +1 -0
- package/dist/chunk-ZULZ2752.js +2774 -0
- package/dist/chunk-ZULZ2752.js.map +1 -0
- package/dist/dist-4MVGNSRL.cjs +1150 -0
- package/dist/dist-4MVGNSRL.cjs.map +1 -0
- package/dist/dist-FZYCV3VB.cjs +940 -0
- package/dist/dist-FZYCV3VB.cjs.map +1 -0
- package/dist/dist-G2BYZJOC.cjs +928 -0
- package/dist/dist-G2BYZJOC.cjs.map +1 -0
- package/dist/dist-P4MXBQ3U.cjs +16 -0
- package/dist/dist-P4MXBQ3U.cjs.map +1 -0
- package/dist/dist-PQZUVLPC.js +937 -0
- package/dist/dist-PQZUVLPC.js.map +1 -0
- package/dist/dist-R7WYX6LC.js +925 -0
- package/dist/dist-R7WYX6LC.js.map +1 -0
- package/dist/dist-RFMYFILX.cjs +764 -0
- package/dist/dist-RFMYFILX.cjs.map +1 -0
- package/dist/dist-X7XR3M3Z.js +1147 -0
- package/dist/dist-X7XR3M3Z.js.map +1 -0
- package/dist/dist-XVBSOGFK.js +761 -0
- package/dist/dist-XVBSOGFK.js.map +1 -0
- package/dist/dist-YREX2TJT.js +3 -0
- package/dist/dist-YREX2TJT.js.map +1 -0
- package/dist/index.cjs +6 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/server/a2a/protocol.d.ts +8 -0
- package/dist/server/a2a/protocol.d.ts.map +1 -0
- package/dist/server/a2a/store.cjs +25 -0
- package/dist/server/a2a/store.cjs.map +1 -0
- package/dist/server/a2a/store.d.ts +14 -0
- package/dist/server/a2a/store.d.ts.map +1 -0
- package/dist/server/a2a/store.js +23 -0
- package/dist/server/a2a/store.js.map +1 -0
- package/dist/server/a2a/tasks.d.ts +20 -0
- package/dist/server/a2a/tasks.d.ts.map +1 -0
- package/dist/server/handlers/a2a.cjs +32 -0
- package/dist/server/handlers/a2a.cjs.map +1 -0
- package/dist/server/handlers/a2a.d.ts +68 -0
- package/dist/server/handlers/a2a.d.ts.map +1 -0
- package/dist/server/handlers/a2a.js +3 -0
- package/dist/server/handlers/a2a.js.map +1 -0
- package/dist/server/handlers/agent-builder.cjs +68 -0
- package/dist/server/handlers/agent-builder.cjs.map +1 -0
- package/dist/server/handlers/agent-builder.d.ts +94 -0
- package/dist/server/handlers/agent-builder.d.ts.map +1 -0
- package/dist/server/handlers/agent-builder.js +3 -0
- package/dist/server/handlers/agent-builder.js.map +1 -0
- package/dist/server/handlers/agents.cjs +65 -7
- package/dist/server/handlers/agents.cjs.map +1 -0
- package/dist/server/handlers/agents.d.ts +210 -6
- package/dist/server/handlers/agents.d.ts.map +1 -0
- package/dist/server/handlers/agents.js +3 -1
- package/dist/server/handlers/agents.js.map +1 -0
- package/dist/server/handlers/error.cjs +4 -2
- package/dist/server/handlers/error.cjs.map +1 -0
- package/dist/server/handlers/error.d.ts +2 -1
- package/dist/server/handlers/error.d.ts.map +1 -0
- package/dist/server/handlers/error.js +3 -1
- package/dist/server/handlers/error.js.map +1 -0
- package/dist/server/handlers/legacyWorkflows.cjs +48 -0
- package/dist/server/handlers/legacyWorkflows.cjs.map +1 -0
- package/dist/server/handlers/legacyWorkflows.d.ts +59 -0
- package/dist/server/handlers/legacyWorkflows.d.ts.map +1 -0
- package/dist/server/handlers/legacyWorkflows.js +3 -0
- package/dist/server/handlers/legacyWorkflows.js.map +1 -0
- package/dist/server/handlers/logs.cjs +6 -4
- package/dist/server/handlers/logs.cjs.map +1 -0
- package/dist/server/handlers/logs.d.ts +34 -3
- package/dist/server/handlers/logs.d.ts.map +1 -0
- package/dist/server/handlers/logs.js +3 -1
- package/dist/server/handlers/logs.js.map +1 -0
- package/dist/server/handlers/memory.cjs +39 -9
- package/dist/server/handlers/memory.cjs.map +1 -0
- package/dist/server/handlers/memory.d.ts +118 -8
- package/dist/server/handlers/memory.d.ts.map +1 -0
- package/dist/server/handlers/memory.js +3 -1
- package/dist/server/handlers/memory.js.map +1 -0
- package/dist/server/handlers/observability.cjs +24 -0
- package/dist/server/handlers/observability.cjs.map +1 -0
- package/dist/server/handlers/observability.d.ts +49 -0
- package/dist/server/handlers/observability.d.ts.map +1 -0
- package/dist/server/handlers/observability.js +3 -0
- package/dist/server/handlers/observability.js.map +1 -0
- package/dist/server/handlers/scores.cjs +32 -0
- package/dist/server/handlers/scores.cjs.map +1 -0
- package/dist/server/handlers/scores.d.ts +152 -0
- package/dist/server/handlers/scores.d.ts.map +1 -0
- package/dist/server/handlers/scores.js +3 -0
- package/dist/server/handlers/scores.js.map +1 -0
- package/dist/server/handlers/telemetry.cjs +9 -3
- package/dist/server/handlers/telemetry.cjs.map +1 -0
- package/dist/server/handlers/telemetry.d.ts +33 -2
- package/dist/server/handlers/telemetry.d.ts.map +1 -0
- package/dist/server/handlers/telemetry.js +3 -1
- package/dist/server/handlers/telemetry.js.map +1 -0
- package/dist/server/handlers/tools.cjs +11 -5
- package/dist/server/handlers/tools.cjs.map +1 -0
- package/dist/server/handlers/tools.d.ts +25 -4
- package/dist/server/handlers/tools.d.ts.map +1 -0
- package/dist/server/handlers/tools.js +3 -1
- package/dist/server/handlers/tools.js.map +1 -0
- package/dist/server/handlers/utils.cjs +8 -2
- package/dist/server/handlers/utils.cjs.map +1 -0
- package/dist/server/handlers/utils.d.ts +8 -1
- package/dist/server/handlers/utils.d.ts.map +1 -0
- package/dist/server/handlers/utils.js +3 -1
- package/dist/server/handlers/utils.js.map +1 -0
- package/dist/server/handlers/vector.cjs +9 -7
- package/dist/server/handlers/vector.cjs.map +1 -0
- package/dist/server/handlers/vector.d.ts +51 -6
- package/dist/server/handlers/vector.d.ts.map +1 -0
- package/dist/server/handlers/vector.js +3 -1
- package/dist/server/handlers/vector.js.map +1 -0
- package/dist/server/handlers/voice.cjs +10 -4
- package/dist/server/handlers/voice.cjs.map +1 -0
- package/dist/server/handlers/voice.d.ts +41 -3
- package/dist/server/handlers/voice.d.ts.map +1 -0
- package/dist/server/handlers/voice.js +3 -1
- package/dist/server/handlers/voice.js.map +1 -0
- package/dist/server/handlers/workflows.cjs +83 -13
- package/dist/server/handlers/workflows.cjs.map +1 -0
- package/dist/server/handlers/workflows.d.ts +151 -10
- package/dist/server/handlers/workflows.d.ts.map +1 -0
- package/dist/server/handlers/workflows.js +3 -1
- package/dist/server/handlers/workflows.js.map +1 -0
- package/dist/server/handlers.cjs +49 -27
- package/dist/server/handlers.cjs.map +1 -0
- package/dist/server/handlers.d.ts +14 -9
- package/dist/server/handlers.d.ts.map +1 -0
- package/dist/server/handlers.js +15 -9
- package/dist/server/handlers.js.map +1 -0
- package/dist/server/http-exception.d.ts +87 -0
- package/dist/server/http-exception.d.ts.map +1 -0
- package/dist/server/types.d.ts +10 -0
- package/dist/server/types.d.ts.map +1 -0
- package/dist/server/utils.d.ts +44 -0
- package/dist/server/utils.d.ts.map +1 -0
- package/dist/token-375W3LEI.cjs +64 -0
- package/dist/token-375W3LEI.cjs.map +1 -0
- package/dist/token-C3IMNCC4.js +62 -0
- package/dist/token-C3IMNCC4.js.map +1 -0
- package/dist/token-util-CV3RRG6K.cjs +9 -0
- package/dist/token-util-CV3RRG6K.cjs.map +1 -0
- package/dist/token-util-E5QO2RCL.js +7 -0
- package/dist/token-util-E5QO2RCL.js.map +1 -0
- package/package.json +50 -19
- package/dist/_tsup-dts-rollup.d.cts +0 -573
- package/dist/_tsup-dts-rollup.d.ts +0 -573
- package/dist/chunk-2FJURXCL.cjs +0 -213
- package/dist/chunk-3AHQ5RGN.js +0 -11
- package/dist/chunk-3EJZQ6TQ.js +0 -49
- package/dist/chunk-A7DF4ETD.cjs +0 -100
- package/dist/chunk-B64YROKU.cjs +0 -317
- package/dist/chunk-I6MBOQTH.js +0 -156
- package/dist/chunk-JLDXUWK7.cjs +0 -126
- package/dist/chunk-PDC4ZBQW.cjs +0 -126
- package/dist/chunk-QH6XWSXP.cjs +0 -5579
- package/dist/chunk-QN4KF3BH.cjs +0 -18
- package/dist/chunk-RBQASTUP.js +0 -203
- package/dist/chunk-SKBVVI24.cjs +0 -54
- package/dist/chunk-UE27Q3XD.cjs +0 -164
- package/dist/chunk-VK6FX47H.js +0 -5576
- package/dist/chunk-YANVFOYA.js +0 -120
- package/dist/chunk-ZLBRQFDD.cjs +0 -13
- package/dist/index.d.cts +0 -1
- package/dist/server/handlers/agents.d.cts +0 -6
- package/dist/server/handlers/error.d.cts +0 -1
- package/dist/server/handlers/logs.d.cts +0 -3
- package/dist/server/handlers/memory.d.cts +0 -8
- package/dist/server/handlers/network.cjs +0 -22
- package/dist/server/handlers/network.d.cts +0 -4
- package/dist/server/handlers/network.d.ts +0 -4
- package/dist/server/handlers/network.js +0 -1
- package/dist/server/handlers/telemetry.d.cts +0 -2
- package/dist/server/handlers/tools.d.cts +0 -4
- package/dist/server/handlers/utils.d.cts +0 -1
- package/dist/server/handlers/vector.d.cts +0 -6
- package/dist/server/handlers/voice.d.cts +0 -3
- package/dist/server/handlers/workflows.d.cts +0 -10
- package/dist/server/handlers.d.cts +0 -9
|
@@ -0,0 +1,764 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkLPM6BBAX_cjs = require('./chunk-LPM6BBAX.cjs');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
function convertToGroqChatMessages(prompt) {
|
|
7
|
+
const messages = [];
|
|
8
|
+
for (const { role, content } of prompt) {
|
|
9
|
+
switch (role) {
|
|
10
|
+
case "system": {
|
|
11
|
+
messages.push({ role: "system", content });
|
|
12
|
+
break;
|
|
13
|
+
}
|
|
14
|
+
case "user": {
|
|
15
|
+
if (content.length === 1 && content[0].type === "text") {
|
|
16
|
+
messages.push({ role: "user", content: content[0].text });
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
messages.push({
|
|
20
|
+
role: "user",
|
|
21
|
+
content: content.map((part) => {
|
|
22
|
+
var _a;
|
|
23
|
+
switch (part.type) {
|
|
24
|
+
case "text": {
|
|
25
|
+
return { type: "text", text: part.text };
|
|
26
|
+
}
|
|
27
|
+
case "image": {
|
|
28
|
+
return {
|
|
29
|
+
type: "image_url",
|
|
30
|
+
image_url: {
|
|
31
|
+
url: part.image instanceof URL ? part.image.toString() : `data:${(_a = part.mimeType) != null ? _a : "image/jpeg"};base64,${chunkLPM6BBAX_cjs.convertUint8ArrayToBase64(part.image)}`
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
case "file": {
|
|
36
|
+
throw new chunkLPM6BBAX_cjs.UnsupportedFunctionalityError({
|
|
37
|
+
functionality: "File content parts in user messages"
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
case "assistant": {
|
|
46
|
+
let text = "";
|
|
47
|
+
const toolCalls = [];
|
|
48
|
+
for (const part of content) {
|
|
49
|
+
switch (part.type) {
|
|
50
|
+
case "text": {
|
|
51
|
+
text += part.text;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case "tool-call": {
|
|
55
|
+
toolCalls.push({
|
|
56
|
+
id: part.toolCallId,
|
|
57
|
+
type: "function",
|
|
58
|
+
function: {
|
|
59
|
+
name: part.toolName,
|
|
60
|
+
arguments: JSON.stringify(part.args)
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
messages.push({
|
|
68
|
+
role: "assistant",
|
|
69
|
+
content: text,
|
|
70
|
+
tool_calls: toolCalls.length > 0 ? toolCalls : void 0
|
|
71
|
+
});
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
case "tool": {
|
|
75
|
+
for (const toolResponse of content) {
|
|
76
|
+
messages.push({
|
|
77
|
+
role: "tool",
|
|
78
|
+
tool_call_id: toolResponse.toolCallId,
|
|
79
|
+
content: JSON.stringify(toolResponse.result)
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
default: {
|
|
85
|
+
const _exhaustiveCheck = role;
|
|
86
|
+
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return messages;
|
|
91
|
+
}
|
|
92
|
+
function getResponseMetadata({
|
|
93
|
+
id,
|
|
94
|
+
model,
|
|
95
|
+
created
|
|
96
|
+
}) {
|
|
97
|
+
return {
|
|
98
|
+
id: id != null ? id : void 0,
|
|
99
|
+
modelId: model != null ? model : void 0,
|
|
100
|
+
timestamp: created != null ? new Date(created * 1e3) : void 0
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
var groqErrorDataSchema = zod.z.object({
|
|
104
|
+
error: zod.z.object({
|
|
105
|
+
message: zod.z.string(),
|
|
106
|
+
type: zod.z.string()
|
|
107
|
+
})
|
|
108
|
+
});
|
|
109
|
+
var groqFailedResponseHandler = chunkLPM6BBAX_cjs.createJsonErrorResponseHandler({
|
|
110
|
+
errorSchema: groqErrorDataSchema,
|
|
111
|
+
errorToMessage: (data) => data.error.message
|
|
112
|
+
});
|
|
113
|
+
function prepareTools({
|
|
114
|
+
mode
|
|
115
|
+
}) {
|
|
116
|
+
var _a;
|
|
117
|
+
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
|
|
118
|
+
const toolWarnings = [];
|
|
119
|
+
if (tools == null) {
|
|
120
|
+
return { tools: void 0, tool_choice: void 0, toolWarnings };
|
|
121
|
+
}
|
|
122
|
+
const toolChoice = mode.toolChoice;
|
|
123
|
+
const groqTools = [];
|
|
124
|
+
for (const tool of tools) {
|
|
125
|
+
if (tool.type === "provider-defined") {
|
|
126
|
+
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
127
|
+
} else {
|
|
128
|
+
groqTools.push({
|
|
129
|
+
type: "function",
|
|
130
|
+
function: {
|
|
131
|
+
name: tool.name,
|
|
132
|
+
description: tool.description,
|
|
133
|
+
parameters: tool.parameters
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (toolChoice == null) {
|
|
139
|
+
return { tools: groqTools, tool_choice: void 0, toolWarnings };
|
|
140
|
+
}
|
|
141
|
+
const type = toolChoice.type;
|
|
142
|
+
switch (type) {
|
|
143
|
+
case "auto":
|
|
144
|
+
case "none":
|
|
145
|
+
case "required":
|
|
146
|
+
return { tools: groqTools, tool_choice: type, toolWarnings };
|
|
147
|
+
case "tool":
|
|
148
|
+
return {
|
|
149
|
+
tools: groqTools,
|
|
150
|
+
tool_choice: {
|
|
151
|
+
type: "function",
|
|
152
|
+
function: {
|
|
153
|
+
name: toolChoice.toolName
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
toolWarnings
|
|
157
|
+
};
|
|
158
|
+
default: {
|
|
159
|
+
const _exhaustiveCheck = type;
|
|
160
|
+
throw new chunkLPM6BBAX_cjs.UnsupportedFunctionalityError({
|
|
161
|
+
functionality: `Unsupported tool choice type: ${_exhaustiveCheck}`
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function mapGroqFinishReason(finishReason) {
|
|
167
|
+
switch (finishReason) {
|
|
168
|
+
case "stop":
|
|
169
|
+
return "stop";
|
|
170
|
+
case "length":
|
|
171
|
+
return "length";
|
|
172
|
+
case "content_filter":
|
|
173
|
+
return "content-filter";
|
|
174
|
+
case "function_call":
|
|
175
|
+
case "tool_calls":
|
|
176
|
+
return "tool-calls";
|
|
177
|
+
default:
|
|
178
|
+
return "unknown";
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
var GroqChatLanguageModel = class {
|
|
182
|
+
constructor(modelId, settings, config) {
|
|
183
|
+
this.specificationVersion = "v1";
|
|
184
|
+
this.supportsStructuredOutputs = false;
|
|
185
|
+
this.defaultObjectGenerationMode = "json";
|
|
186
|
+
this.modelId = modelId;
|
|
187
|
+
this.settings = settings;
|
|
188
|
+
this.config = config;
|
|
189
|
+
}
|
|
190
|
+
get provider() {
|
|
191
|
+
return this.config.provider;
|
|
192
|
+
}
|
|
193
|
+
get supportsImageUrls() {
|
|
194
|
+
return !this.settings.downloadImages;
|
|
195
|
+
}
|
|
196
|
+
getArgs({
|
|
197
|
+
mode,
|
|
198
|
+
prompt,
|
|
199
|
+
maxTokens,
|
|
200
|
+
temperature,
|
|
201
|
+
topP,
|
|
202
|
+
topK,
|
|
203
|
+
frequencyPenalty,
|
|
204
|
+
presencePenalty,
|
|
205
|
+
stopSequences,
|
|
206
|
+
responseFormat,
|
|
207
|
+
seed,
|
|
208
|
+
stream,
|
|
209
|
+
providerMetadata
|
|
210
|
+
}) {
|
|
211
|
+
const type = mode.type;
|
|
212
|
+
const warnings = [];
|
|
213
|
+
if (topK != null) {
|
|
214
|
+
warnings.push({
|
|
215
|
+
type: "unsupported-setting",
|
|
216
|
+
setting: "topK"
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
if (responseFormat != null && responseFormat.type === "json" && responseFormat.schema != null) {
|
|
220
|
+
warnings.push({
|
|
221
|
+
type: "unsupported-setting",
|
|
222
|
+
setting: "responseFormat",
|
|
223
|
+
details: "JSON response format schema is not supported"
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
const groqOptions = chunkLPM6BBAX_cjs.parseProviderOptions({
|
|
227
|
+
provider: "groq",
|
|
228
|
+
providerOptions: providerMetadata,
|
|
229
|
+
schema: zod.z.object({
|
|
230
|
+
reasoningFormat: zod.z.enum(["parsed", "raw", "hidden"]).nullish()
|
|
231
|
+
})
|
|
232
|
+
});
|
|
233
|
+
const baseArgs = {
|
|
234
|
+
// model id:
|
|
235
|
+
model: this.modelId,
|
|
236
|
+
// model specific settings:
|
|
237
|
+
user: this.settings.user,
|
|
238
|
+
parallel_tool_calls: this.settings.parallelToolCalls,
|
|
239
|
+
// standardized settings:
|
|
240
|
+
max_tokens: maxTokens,
|
|
241
|
+
temperature,
|
|
242
|
+
top_p: topP,
|
|
243
|
+
frequency_penalty: frequencyPenalty,
|
|
244
|
+
presence_penalty: presencePenalty,
|
|
245
|
+
stop: stopSequences,
|
|
246
|
+
seed,
|
|
247
|
+
// response format:
|
|
248
|
+
response_format: (
|
|
249
|
+
// json object response format is not supported for streaming:
|
|
250
|
+
stream === false && (responseFormat == null ? void 0 : responseFormat.type) === "json" ? { type: "json_object" } : void 0
|
|
251
|
+
),
|
|
252
|
+
// provider options:
|
|
253
|
+
reasoning_format: groqOptions == null ? void 0 : groqOptions.reasoningFormat,
|
|
254
|
+
// messages:
|
|
255
|
+
messages: convertToGroqChatMessages(prompt)
|
|
256
|
+
};
|
|
257
|
+
switch (type) {
|
|
258
|
+
case "regular": {
|
|
259
|
+
const { tools, tool_choice, toolWarnings } = prepareTools({ mode });
|
|
260
|
+
return {
|
|
261
|
+
args: {
|
|
262
|
+
...baseArgs,
|
|
263
|
+
tools,
|
|
264
|
+
tool_choice
|
|
265
|
+
},
|
|
266
|
+
warnings: [...warnings, ...toolWarnings]
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
case "object-json": {
|
|
270
|
+
return {
|
|
271
|
+
args: {
|
|
272
|
+
...baseArgs,
|
|
273
|
+
response_format: (
|
|
274
|
+
// json object response format is not supported for streaming:
|
|
275
|
+
stream === false ? { type: "json_object" } : void 0
|
|
276
|
+
)
|
|
277
|
+
},
|
|
278
|
+
warnings
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
case "object-tool": {
|
|
282
|
+
return {
|
|
283
|
+
args: {
|
|
284
|
+
...baseArgs,
|
|
285
|
+
tool_choice: {
|
|
286
|
+
type: "function",
|
|
287
|
+
function: { name: mode.tool.name }
|
|
288
|
+
},
|
|
289
|
+
tools: [
|
|
290
|
+
{
|
|
291
|
+
type: "function",
|
|
292
|
+
function: {
|
|
293
|
+
name: mode.tool.name,
|
|
294
|
+
description: mode.tool.description,
|
|
295
|
+
parameters: mode.tool.parameters
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
]
|
|
299
|
+
},
|
|
300
|
+
warnings
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
default: {
|
|
304
|
+
const _exhaustiveCheck = type;
|
|
305
|
+
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
async doGenerate(options) {
|
|
310
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
311
|
+
const { args, warnings } = this.getArgs({ ...options, stream: false });
|
|
312
|
+
const body = JSON.stringify(args);
|
|
313
|
+
const {
|
|
314
|
+
responseHeaders,
|
|
315
|
+
value: response,
|
|
316
|
+
rawValue: rawResponse
|
|
317
|
+
} = await chunkLPM6BBAX_cjs.postJsonToApi({
|
|
318
|
+
url: this.config.url({
|
|
319
|
+
path: "/chat/completions",
|
|
320
|
+
modelId: this.modelId
|
|
321
|
+
}),
|
|
322
|
+
headers: chunkLPM6BBAX_cjs.combineHeaders(this.config.headers(), options.headers),
|
|
323
|
+
body: args,
|
|
324
|
+
failedResponseHandler: groqFailedResponseHandler,
|
|
325
|
+
successfulResponseHandler: chunkLPM6BBAX_cjs.createJsonResponseHandler(
|
|
326
|
+
groqChatResponseSchema
|
|
327
|
+
),
|
|
328
|
+
abortSignal: options.abortSignal,
|
|
329
|
+
fetch: this.config.fetch
|
|
330
|
+
});
|
|
331
|
+
const { messages: rawPrompt, ...rawSettings } = args;
|
|
332
|
+
const choice = response.choices[0];
|
|
333
|
+
return {
|
|
334
|
+
text: (_a = choice.message.content) != null ? _a : void 0,
|
|
335
|
+
reasoning: (_b = choice.message.reasoning) != null ? _b : void 0,
|
|
336
|
+
toolCalls: (_c = choice.message.tool_calls) == null ? void 0 : _c.map((toolCall) => {
|
|
337
|
+
var _a2;
|
|
338
|
+
return {
|
|
339
|
+
toolCallType: "function",
|
|
340
|
+
toolCallId: (_a2 = toolCall.id) != null ? _a2 : chunkLPM6BBAX_cjs.generateId(),
|
|
341
|
+
toolName: toolCall.function.name,
|
|
342
|
+
args: toolCall.function.arguments
|
|
343
|
+
};
|
|
344
|
+
}),
|
|
345
|
+
finishReason: mapGroqFinishReason(choice.finish_reason),
|
|
346
|
+
usage: {
|
|
347
|
+
promptTokens: (_e = (_d = response.usage) == null ? void 0 : _d.prompt_tokens) != null ? _e : NaN,
|
|
348
|
+
completionTokens: (_g = (_f = response.usage) == null ? void 0 : _f.completion_tokens) != null ? _g : NaN
|
|
349
|
+
},
|
|
350
|
+
rawCall: { rawPrompt, rawSettings },
|
|
351
|
+
rawResponse: { headers: responseHeaders, body: rawResponse },
|
|
352
|
+
response: getResponseMetadata(response),
|
|
353
|
+
warnings,
|
|
354
|
+
request: { body }
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
async doStream(options) {
|
|
358
|
+
const { args, warnings } = this.getArgs({ ...options, stream: true });
|
|
359
|
+
const body = JSON.stringify({ ...args, stream: true });
|
|
360
|
+
const { responseHeaders, value: response } = await chunkLPM6BBAX_cjs.postJsonToApi({
|
|
361
|
+
url: this.config.url({
|
|
362
|
+
path: "/chat/completions",
|
|
363
|
+
modelId: this.modelId
|
|
364
|
+
}),
|
|
365
|
+
headers: chunkLPM6BBAX_cjs.combineHeaders(this.config.headers(), options.headers),
|
|
366
|
+
body: {
|
|
367
|
+
...args,
|
|
368
|
+
stream: true
|
|
369
|
+
},
|
|
370
|
+
failedResponseHandler: groqFailedResponseHandler,
|
|
371
|
+
successfulResponseHandler: chunkLPM6BBAX_cjs.createEventSourceResponseHandler(groqChatChunkSchema),
|
|
372
|
+
abortSignal: options.abortSignal,
|
|
373
|
+
fetch: this.config.fetch
|
|
374
|
+
});
|
|
375
|
+
const { messages: rawPrompt, ...rawSettings } = args;
|
|
376
|
+
const toolCalls = [];
|
|
377
|
+
let finishReason = "unknown";
|
|
378
|
+
let usage = {
|
|
379
|
+
promptTokens: void 0,
|
|
380
|
+
completionTokens: void 0
|
|
381
|
+
};
|
|
382
|
+
let isFirstChunk = true;
|
|
383
|
+
return {
|
|
384
|
+
stream: response.pipeThrough(
|
|
385
|
+
new TransformStream({
|
|
386
|
+
transform(chunk, controller) {
|
|
387
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
388
|
+
if (!chunk.success) {
|
|
389
|
+
finishReason = "error";
|
|
390
|
+
controller.enqueue({ type: "error", error: chunk.error });
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
const value = chunk.value;
|
|
394
|
+
if ("error" in value) {
|
|
395
|
+
finishReason = "error";
|
|
396
|
+
controller.enqueue({ type: "error", error: value.error });
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
if (isFirstChunk) {
|
|
400
|
+
isFirstChunk = false;
|
|
401
|
+
controller.enqueue({
|
|
402
|
+
type: "response-metadata",
|
|
403
|
+
...getResponseMetadata(value)
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
if (((_a = value.x_groq) == null ? void 0 : _a.usage) != null) {
|
|
407
|
+
usage = {
|
|
408
|
+
promptTokens: (_b = value.x_groq.usage.prompt_tokens) != null ? _b : void 0,
|
|
409
|
+
completionTokens: (_c = value.x_groq.usage.completion_tokens) != null ? _c : void 0
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
const choice = value.choices[0];
|
|
413
|
+
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
414
|
+
finishReason = mapGroqFinishReason(choice.finish_reason);
|
|
415
|
+
}
|
|
416
|
+
if ((choice == null ? void 0 : choice.delta) == null) {
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
const delta = choice.delta;
|
|
420
|
+
if (delta.reasoning != null && delta.reasoning.length > 0) {
|
|
421
|
+
controller.enqueue({
|
|
422
|
+
type: "reasoning",
|
|
423
|
+
textDelta: delta.reasoning
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
if (delta.content != null && delta.content.length > 0) {
|
|
427
|
+
controller.enqueue({
|
|
428
|
+
type: "text-delta",
|
|
429
|
+
textDelta: delta.content
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
if (delta.tool_calls != null) {
|
|
433
|
+
for (const toolCallDelta of delta.tool_calls) {
|
|
434
|
+
const index = toolCallDelta.index;
|
|
435
|
+
if (toolCalls[index] == null) {
|
|
436
|
+
if (toolCallDelta.type !== "function") {
|
|
437
|
+
throw new chunkLPM6BBAX_cjs.InvalidResponseDataError({
|
|
438
|
+
data: toolCallDelta,
|
|
439
|
+
message: `Expected 'function' type.`
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
if (toolCallDelta.id == null) {
|
|
443
|
+
throw new chunkLPM6BBAX_cjs.InvalidResponseDataError({
|
|
444
|
+
data: toolCallDelta,
|
|
445
|
+
message: `Expected 'id' to be a string.`
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
if (((_d = toolCallDelta.function) == null ? void 0 : _d.name) == null) {
|
|
449
|
+
throw new chunkLPM6BBAX_cjs.InvalidResponseDataError({
|
|
450
|
+
data: toolCallDelta,
|
|
451
|
+
message: `Expected 'function.name' to be a string.`
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
toolCalls[index] = {
|
|
455
|
+
id: toolCallDelta.id,
|
|
456
|
+
type: "function",
|
|
457
|
+
function: {
|
|
458
|
+
name: toolCallDelta.function.name,
|
|
459
|
+
arguments: (_e = toolCallDelta.function.arguments) != null ? _e : ""
|
|
460
|
+
},
|
|
461
|
+
hasFinished: false
|
|
462
|
+
};
|
|
463
|
+
const toolCall2 = toolCalls[index];
|
|
464
|
+
if (((_f = toolCall2.function) == null ? void 0 : _f.name) != null && ((_g = toolCall2.function) == null ? void 0 : _g.arguments) != null) {
|
|
465
|
+
if (toolCall2.function.arguments.length > 0) {
|
|
466
|
+
controller.enqueue({
|
|
467
|
+
type: "tool-call-delta",
|
|
468
|
+
toolCallType: "function",
|
|
469
|
+
toolCallId: toolCall2.id,
|
|
470
|
+
toolName: toolCall2.function.name,
|
|
471
|
+
argsTextDelta: toolCall2.function.arguments
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
if (chunkLPM6BBAX_cjs.isParsableJson(toolCall2.function.arguments)) {
|
|
475
|
+
controller.enqueue({
|
|
476
|
+
type: "tool-call",
|
|
477
|
+
toolCallType: "function",
|
|
478
|
+
toolCallId: (_h = toolCall2.id) != null ? _h : chunkLPM6BBAX_cjs.generateId(),
|
|
479
|
+
toolName: toolCall2.function.name,
|
|
480
|
+
args: toolCall2.function.arguments
|
|
481
|
+
});
|
|
482
|
+
toolCall2.hasFinished = true;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
continue;
|
|
486
|
+
}
|
|
487
|
+
const toolCall = toolCalls[index];
|
|
488
|
+
if (toolCall.hasFinished) {
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
if (((_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null) {
|
|
492
|
+
toolCall.function.arguments += (_k = (_j = toolCallDelta.function) == null ? void 0 : _j.arguments) != null ? _k : "";
|
|
493
|
+
}
|
|
494
|
+
controller.enqueue({
|
|
495
|
+
type: "tool-call-delta",
|
|
496
|
+
toolCallType: "function",
|
|
497
|
+
toolCallId: toolCall.id,
|
|
498
|
+
toolName: toolCall.function.name,
|
|
499
|
+
argsTextDelta: (_l = toolCallDelta.function.arguments) != null ? _l : ""
|
|
500
|
+
});
|
|
501
|
+
if (((_m = toolCall.function) == null ? void 0 : _m.name) != null && ((_n = toolCall.function) == null ? void 0 : _n.arguments) != null && chunkLPM6BBAX_cjs.isParsableJson(toolCall.function.arguments)) {
|
|
502
|
+
controller.enqueue({
|
|
503
|
+
type: "tool-call",
|
|
504
|
+
toolCallType: "function",
|
|
505
|
+
toolCallId: (_o = toolCall.id) != null ? _o : chunkLPM6BBAX_cjs.generateId(),
|
|
506
|
+
toolName: toolCall.function.name,
|
|
507
|
+
args: toolCall.function.arguments
|
|
508
|
+
});
|
|
509
|
+
toolCall.hasFinished = true;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
},
|
|
514
|
+
flush(controller) {
|
|
515
|
+
var _a, _b;
|
|
516
|
+
controller.enqueue({
|
|
517
|
+
type: "finish",
|
|
518
|
+
finishReason,
|
|
519
|
+
usage: {
|
|
520
|
+
promptTokens: (_a = usage.promptTokens) != null ? _a : NaN,
|
|
521
|
+
completionTokens: (_b = usage.completionTokens) != null ? _b : NaN
|
|
522
|
+
},
|
|
523
|
+
...{}
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
})
|
|
527
|
+
),
|
|
528
|
+
rawCall: { rawPrompt, rawSettings },
|
|
529
|
+
rawResponse: { headers: responseHeaders },
|
|
530
|
+
warnings,
|
|
531
|
+
request: { body }
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
var groqChatResponseSchema = zod.z.object({
|
|
536
|
+
id: zod.z.string().nullish(),
|
|
537
|
+
created: zod.z.number().nullish(),
|
|
538
|
+
model: zod.z.string().nullish(),
|
|
539
|
+
choices: zod.z.array(
|
|
540
|
+
zod.z.object({
|
|
541
|
+
message: zod.z.object({
|
|
542
|
+
content: zod.z.string().nullish(),
|
|
543
|
+
reasoning: zod.z.string().nullish(),
|
|
544
|
+
tool_calls: zod.z.array(
|
|
545
|
+
zod.z.object({
|
|
546
|
+
id: zod.z.string().nullish(),
|
|
547
|
+
type: zod.z.literal("function"),
|
|
548
|
+
function: zod.z.object({
|
|
549
|
+
name: zod.z.string(),
|
|
550
|
+
arguments: zod.z.string()
|
|
551
|
+
})
|
|
552
|
+
})
|
|
553
|
+
).nullish()
|
|
554
|
+
}),
|
|
555
|
+
index: zod.z.number(),
|
|
556
|
+
finish_reason: zod.z.string().nullish()
|
|
557
|
+
})
|
|
558
|
+
),
|
|
559
|
+
usage: zod.z.object({
|
|
560
|
+
prompt_tokens: zod.z.number().nullish(),
|
|
561
|
+
completion_tokens: zod.z.number().nullish()
|
|
562
|
+
}).nullish()
|
|
563
|
+
});
|
|
564
|
+
var groqChatChunkSchema = zod.z.union([
|
|
565
|
+
zod.z.object({
|
|
566
|
+
id: zod.z.string().nullish(),
|
|
567
|
+
created: zod.z.number().nullish(),
|
|
568
|
+
model: zod.z.string().nullish(),
|
|
569
|
+
choices: zod.z.array(
|
|
570
|
+
zod.z.object({
|
|
571
|
+
delta: zod.z.object({
|
|
572
|
+
content: zod.z.string().nullish(),
|
|
573
|
+
reasoning: zod.z.string().nullish(),
|
|
574
|
+
tool_calls: zod.z.array(
|
|
575
|
+
zod.z.object({
|
|
576
|
+
index: zod.z.number(),
|
|
577
|
+
id: zod.z.string().nullish(),
|
|
578
|
+
type: zod.z.literal("function").optional(),
|
|
579
|
+
function: zod.z.object({
|
|
580
|
+
name: zod.z.string().nullish(),
|
|
581
|
+
arguments: zod.z.string().nullish()
|
|
582
|
+
})
|
|
583
|
+
})
|
|
584
|
+
).nullish()
|
|
585
|
+
}).nullish(),
|
|
586
|
+
finish_reason: zod.z.string().nullable().optional(),
|
|
587
|
+
index: zod.z.number()
|
|
588
|
+
})
|
|
589
|
+
),
|
|
590
|
+
x_groq: zod.z.object({
|
|
591
|
+
usage: zod.z.object({
|
|
592
|
+
prompt_tokens: zod.z.number().nullish(),
|
|
593
|
+
completion_tokens: zod.z.number().nullish()
|
|
594
|
+
}).nullish()
|
|
595
|
+
}).nullish()
|
|
596
|
+
}),
|
|
597
|
+
groqErrorDataSchema
|
|
598
|
+
]);
|
|
599
|
+
var groqProviderOptionsSchema = zod.z.object({
|
|
600
|
+
language: zod.z.string().nullish(),
|
|
601
|
+
prompt: zod.z.string().nullish(),
|
|
602
|
+
responseFormat: zod.z.string().nullish(),
|
|
603
|
+
temperature: zod.z.number().min(0).max(1).nullish(),
|
|
604
|
+
timestampGranularities: zod.z.array(zod.z.string()).nullish()
|
|
605
|
+
});
|
|
606
|
+
var GroqTranscriptionModel = class {
|
|
607
|
+
constructor(modelId, config) {
|
|
608
|
+
this.modelId = modelId;
|
|
609
|
+
this.config = config;
|
|
610
|
+
this.specificationVersion = "v1";
|
|
611
|
+
}
|
|
612
|
+
get provider() {
|
|
613
|
+
return this.config.provider;
|
|
614
|
+
}
|
|
615
|
+
getArgs({
|
|
616
|
+
audio,
|
|
617
|
+
mediaType,
|
|
618
|
+
providerOptions
|
|
619
|
+
}) {
|
|
620
|
+
var _a, _b, _c, _d, _e;
|
|
621
|
+
const warnings = [];
|
|
622
|
+
const groqOptions = chunkLPM6BBAX_cjs.parseProviderOptions({
|
|
623
|
+
provider: "groq",
|
|
624
|
+
providerOptions,
|
|
625
|
+
schema: groqProviderOptionsSchema
|
|
626
|
+
});
|
|
627
|
+
const formData = new FormData();
|
|
628
|
+
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([chunkLPM6BBAX_cjs.convertBase64ToUint8Array(audio)]);
|
|
629
|
+
formData.append("model", this.modelId);
|
|
630
|
+
formData.append("file", new File([blob], "audio", { type: mediaType }));
|
|
631
|
+
if (groqOptions) {
|
|
632
|
+
const transcriptionModelOptions = {
|
|
633
|
+
language: (_a = groqOptions.language) != null ? _a : void 0,
|
|
634
|
+
prompt: (_b = groqOptions.prompt) != null ? _b : void 0,
|
|
635
|
+
response_format: (_c = groqOptions.responseFormat) != null ? _c : void 0,
|
|
636
|
+
temperature: (_d = groqOptions.temperature) != null ? _d : void 0,
|
|
637
|
+
timestamp_granularities: (_e = groqOptions.timestampGranularities) != null ? _e : void 0
|
|
638
|
+
};
|
|
639
|
+
for (const key in transcriptionModelOptions) {
|
|
640
|
+
const value = transcriptionModelOptions[key];
|
|
641
|
+
if (value !== void 0) {
|
|
642
|
+
formData.append(key, String(value));
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
return {
|
|
647
|
+
formData,
|
|
648
|
+
warnings
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
async doGenerate(options) {
|
|
652
|
+
var _a, _b, _c, _d, _e;
|
|
653
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
654
|
+
const { formData, warnings } = this.getArgs(options);
|
|
655
|
+
const {
|
|
656
|
+
value: response,
|
|
657
|
+
responseHeaders,
|
|
658
|
+
rawValue: rawResponse
|
|
659
|
+
} = await chunkLPM6BBAX_cjs.postFormDataToApi({
|
|
660
|
+
url: this.config.url({
|
|
661
|
+
path: "/audio/transcriptions",
|
|
662
|
+
modelId: this.modelId
|
|
663
|
+
}),
|
|
664
|
+
headers: chunkLPM6BBAX_cjs.combineHeaders(this.config.headers(), options.headers),
|
|
665
|
+
formData,
|
|
666
|
+
failedResponseHandler: groqFailedResponseHandler,
|
|
667
|
+
successfulResponseHandler: chunkLPM6BBAX_cjs.createJsonResponseHandler(
|
|
668
|
+
groqTranscriptionResponseSchema
|
|
669
|
+
),
|
|
670
|
+
abortSignal: options.abortSignal,
|
|
671
|
+
fetch: this.config.fetch
|
|
672
|
+
});
|
|
673
|
+
return {
|
|
674
|
+
text: response.text,
|
|
675
|
+
segments: (_e = (_d = response.segments) == null ? void 0 : _d.map((segment) => ({
|
|
676
|
+
text: segment.text,
|
|
677
|
+
startSecond: segment.start,
|
|
678
|
+
endSecond: segment.end
|
|
679
|
+
}))) != null ? _e : [],
|
|
680
|
+
language: response.language,
|
|
681
|
+
durationInSeconds: response.duration,
|
|
682
|
+
warnings,
|
|
683
|
+
response: {
|
|
684
|
+
timestamp: currentDate,
|
|
685
|
+
modelId: this.modelId,
|
|
686
|
+
headers: responseHeaders,
|
|
687
|
+
body: rawResponse
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
var groqTranscriptionResponseSchema = zod.z.object({
|
|
693
|
+
task: zod.z.string(),
|
|
694
|
+
language: zod.z.string(),
|
|
695
|
+
duration: zod.z.number(),
|
|
696
|
+
text: zod.z.string(),
|
|
697
|
+
segments: zod.z.array(
|
|
698
|
+
zod.z.object({
|
|
699
|
+
id: zod.z.number(),
|
|
700
|
+
seek: zod.z.number(),
|
|
701
|
+
start: zod.z.number(),
|
|
702
|
+
end: zod.z.number(),
|
|
703
|
+
text: zod.z.string(),
|
|
704
|
+
tokens: zod.z.array(zod.z.number()),
|
|
705
|
+
temperature: zod.z.number(),
|
|
706
|
+
avg_logprob: zod.z.number(),
|
|
707
|
+
compression_ratio: zod.z.number(),
|
|
708
|
+
no_speech_prob: zod.z.number()
|
|
709
|
+
})
|
|
710
|
+
),
|
|
711
|
+
x_groq: zod.z.object({
|
|
712
|
+
id: zod.z.string()
|
|
713
|
+
})
|
|
714
|
+
});
|
|
715
|
+
function createGroq(options = {}) {
|
|
716
|
+
var _a;
|
|
717
|
+
const baseURL = (_a = chunkLPM6BBAX_cjs.withoutTrailingSlash(options.baseURL)) != null ? _a : "https://api.groq.com/openai/v1";
|
|
718
|
+
const getHeaders = () => ({
|
|
719
|
+
Authorization: `Bearer ${chunkLPM6BBAX_cjs.loadApiKey({
|
|
720
|
+
apiKey: options.apiKey,
|
|
721
|
+
environmentVariableName: "GROQ_API_KEY",
|
|
722
|
+
description: "Groq"
|
|
723
|
+
})}`,
|
|
724
|
+
...options.headers
|
|
725
|
+
});
|
|
726
|
+
const createChatModel = (modelId, settings = {}) => new GroqChatLanguageModel(modelId, settings, {
|
|
727
|
+
provider: "groq.chat",
|
|
728
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
729
|
+
headers: getHeaders,
|
|
730
|
+
fetch: options.fetch
|
|
731
|
+
});
|
|
732
|
+
const createLanguageModel = (modelId, settings) => {
|
|
733
|
+
if (new.target) {
|
|
734
|
+
throw new Error(
|
|
735
|
+
"The Groq model function cannot be called with the new keyword."
|
|
736
|
+
);
|
|
737
|
+
}
|
|
738
|
+
return createChatModel(modelId, settings);
|
|
739
|
+
};
|
|
740
|
+
const createTranscriptionModel = (modelId) => {
|
|
741
|
+
return new GroqTranscriptionModel(modelId, {
|
|
742
|
+
provider: "groq.transcription",
|
|
743
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
744
|
+
headers: getHeaders,
|
|
745
|
+
fetch: options.fetch
|
|
746
|
+
});
|
|
747
|
+
};
|
|
748
|
+
const provider = function(modelId, settings) {
|
|
749
|
+
return createLanguageModel(modelId, settings);
|
|
750
|
+
};
|
|
751
|
+
provider.languageModel = createLanguageModel;
|
|
752
|
+
provider.chat = createChatModel;
|
|
753
|
+
provider.textEmbeddingModel = (modelId) => {
|
|
754
|
+
throw new chunkLPM6BBAX_cjs.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
|
|
755
|
+
};
|
|
756
|
+
provider.transcription = createTranscriptionModel;
|
|
757
|
+
return provider;
|
|
758
|
+
}
|
|
759
|
+
var groq = createGroq();
|
|
760
|
+
|
|
761
|
+
exports.createGroq = createGroq;
|
|
762
|
+
exports.groq = groq;
|
|
763
|
+
//# sourceMappingURL=dist-RFMYFILX.cjs.map
|
|
764
|
+
//# sourceMappingURL=dist-RFMYFILX.cjs.map
|