@yourgpt/llm-sdk 2.1.7 → 2.1.8

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.
@@ -667,6 +667,11 @@ var OpenAIAdapter = class _OpenAIAdapter {
667
667
  id: currentToolCall.id,
668
668
  args: currentToolCall.arguments
669
669
  };
670
+ yield {
671
+ type: "action:end",
672
+ id: currentToolCall.id,
673
+ name: currentToolCall.name
674
+ };
670
675
  }
671
676
  const tcExtraContent = toolCall.extra_content;
672
677
  currentToolCall = {
@@ -700,6 +705,12 @@ var OpenAIAdapter = class _OpenAIAdapter {
700
705
  id: currentToolCall.id,
701
706
  args: currentToolCall.arguments
702
707
  };
708
+ yield {
709
+ type: "action:end",
710
+ id: currentToolCall.id,
711
+ name: currentToolCall.name
712
+ };
713
+ currentToolCall = null;
703
714
  }
704
715
  }
705
716
  }
@@ -1537,6 +1548,11 @@ var OllamaAdapter = class {
1537
1548
  id: toolCallId,
1538
1549
  args: JSON.stringify(toolCall.function?.arguments || {})
1539
1550
  };
1551
+ yield {
1552
+ type: "action:end",
1553
+ id: toolCallId,
1554
+ name: toolCall.function?.name || ""
1555
+ };
1540
1556
  }
1541
1557
  hasEmittedToolCalls = true;
1542
1558
  }
@@ -1818,6 +1834,11 @@ var GoogleAdapter = class {
1818
1834
  id: currentToolCall.id,
1819
1835
  args: JSON.stringify(currentToolCall.args)
1820
1836
  };
1837
+ yield {
1838
+ type: "action:end",
1839
+ id: currentToolCall.id,
1840
+ name: currentToolCall.name
1841
+ };
1821
1842
  }
1822
1843
  currentToolCall = {
1823
1844
  id: toolId,
@@ -1838,6 +1859,12 @@ var GoogleAdapter = class {
1838
1859
  id: currentToolCall.id,
1839
1860
  args: JSON.stringify(currentToolCall.args)
1840
1861
  };
1862
+ yield {
1863
+ type: "action:end",
1864
+ id: currentToolCall.id,
1865
+ name: currentToolCall.name
1866
+ };
1867
+ currentToolCall = null;
1841
1868
  }
1842
1869
  }
1843
1870
  const groundingMetadata = candidate?.groundingMetadata;
@@ -2127,6 +2154,11 @@ var AzureAdapter = class {
2127
2154
  id: currentToolCall.id,
2128
2155
  args: currentToolCall.arguments
2129
2156
  };
2157
+ yield {
2158
+ type: "action:end",
2159
+ id: currentToolCall.id,
2160
+ name: currentToolCall.name
2161
+ };
2130
2162
  }
2131
2163
  currentToolCall = {
2132
2164
  id: toolCall.id,
@@ -2150,6 +2182,12 @@ var AzureAdapter = class {
2150
2182
  id: currentToolCall.id,
2151
2183
  args: currentToolCall.arguments
2152
2184
  };
2185
+ yield {
2186
+ type: "action:end",
2187
+ id: currentToolCall.id,
2188
+ name: currentToolCall.name
2189
+ };
2190
+ currentToolCall = null;
2153
2191
  }
2154
2192
  }
2155
2193
  }
@@ -665,6 +665,11 @@ var OpenAIAdapter = class _OpenAIAdapter {
665
665
  id: currentToolCall.id,
666
666
  args: currentToolCall.arguments
667
667
  };
668
+ yield {
669
+ type: "action:end",
670
+ id: currentToolCall.id,
671
+ name: currentToolCall.name
672
+ };
668
673
  }
669
674
  const tcExtraContent = toolCall.extra_content;
670
675
  currentToolCall = {
@@ -698,6 +703,12 @@ var OpenAIAdapter = class _OpenAIAdapter {
698
703
  id: currentToolCall.id,
699
704
  args: currentToolCall.arguments
700
705
  };
706
+ yield {
707
+ type: "action:end",
708
+ id: currentToolCall.id,
709
+ name: currentToolCall.name
710
+ };
711
+ currentToolCall = null;
701
712
  }
702
713
  }
703
714
  }
@@ -1535,6 +1546,11 @@ var OllamaAdapter = class {
1535
1546
  id: toolCallId,
1536
1547
  args: JSON.stringify(toolCall.function?.arguments || {})
1537
1548
  };
1549
+ yield {
1550
+ type: "action:end",
1551
+ id: toolCallId,
1552
+ name: toolCall.function?.name || ""
1553
+ };
1538
1554
  }
1539
1555
  hasEmittedToolCalls = true;
1540
1556
  }
@@ -1816,6 +1832,11 @@ var GoogleAdapter = class {
1816
1832
  id: currentToolCall.id,
1817
1833
  args: JSON.stringify(currentToolCall.args)
1818
1834
  };
1835
+ yield {
1836
+ type: "action:end",
1837
+ id: currentToolCall.id,
1838
+ name: currentToolCall.name
1839
+ };
1819
1840
  }
1820
1841
  currentToolCall = {
1821
1842
  id: toolId,
@@ -1836,6 +1857,12 @@ var GoogleAdapter = class {
1836
1857
  id: currentToolCall.id,
1837
1858
  args: JSON.stringify(currentToolCall.args)
1838
1859
  };
1860
+ yield {
1861
+ type: "action:end",
1862
+ id: currentToolCall.id,
1863
+ name: currentToolCall.name
1864
+ };
1865
+ currentToolCall = null;
1839
1866
  }
1840
1867
  }
1841
1868
  const groundingMetadata = candidate?.groundingMetadata;
@@ -2125,6 +2152,11 @@ var AzureAdapter = class {
2125
2152
  id: currentToolCall.id,
2126
2153
  args: currentToolCall.arguments
2127
2154
  };
2155
+ yield {
2156
+ type: "action:end",
2157
+ id: currentToolCall.id,
2158
+ name: currentToolCall.name
2159
+ };
2128
2160
  }
2129
2161
  currentToolCall = {
2130
2162
  id: toolCall.id,
@@ -2148,6 +2180,12 @@ var AzureAdapter = class {
2148
2180
  id: currentToolCall.id,
2149
2181
  args: currentToolCall.arguments
2150
2182
  };
2183
+ yield {
2184
+ type: "action:end",
2185
+ id: currentToolCall.id,
2186
+ name: currentToolCall.name
2187
+ };
2188
+ currentToolCall = null;
2151
2189
  }
2152
2190
  }
2153
2191
  }
@@ -279,6 +279,11 @@ var AzureAdapter = class {
279
279
  id: currentToolCall.id,
280
280
  args: currentToolCall.arguments
281
281
  };
282
+ yield {
283
+ type: "action:end",
284
+ id: currentToolCall.id,
285
+ name: currentToolCall.name
286
+ };
282
287
  }
283
288
  currentToolCall = {
284
289
  id: toolCall.id,
@@ -302,6 +307,12 @@ var AzureAdapter = class {
302
307
  id: currentToolCall.id,
303
308
  args: currentToolCall.arguments
304
309
  };
310
+ yield {
311
+ type: "action:end",
312
+ id: currentToolCall.id,
313
+ name: currentToolCall.name
314
+ };
315
+ currentToolCall = null;
305
316
  }
306
317
  }
307
318
  }
@@ -277,6 +277,11 @@ var AzureAdapter = class {
277
277
  id: currentToolCall.id,
278
278
  args: currentToolCall.arguments
279
279
  };
280
+ yield {
281
+ type: "action:end",
282
+ id: currentToolCall.id,
283
+ name: currentToolCall.name
284
+ };
280
285
  }
281
286
  currentToolCall = {
282
287
  id: toolCall.id,
@@ -300,6 +305,12 @@ var AzureAdapter = class {
300
305
  id: currentToolCall.id,
301
306
  args: currentToolCall.arguments
302
307
  };
308
+ yield {
309
+ type: "action:end",
310
+ id: currentToolCall.id,
311
+ name: currentToolCall.name
312
+ };
313
+ currentToolCall = null;
303
314
  }
304
315
  }
305
316
  }
@@ -791,6 +791,11 @@ var OpenAIAdapter = class _OpenAIAdapter {
791
791
  id: currentToolCall.id,
792
792
  args: currentToolCall.arguments
793
793
  };
794
+ yield {
795
+ type: "action:end",
796
+ id: currentToolCall.id,
797
+ name: currentToolCall.name
798
+ };
794
799
  }
795
800
  const tcExtraContent = toolCall.extra_content;
796
801
  currentToolCall = {
@@ -824,6 +829,12 @@ var OpenAIAdapter = class _OpenAIAdapter {
824
829
  id: currentToolCall.id,
825
830
  args: currentToolCall.arguments
826
831
  };
832
+ yield {
833
+ type: "action:end",
834
+ id: currentToolCall.id,
835
+ name: currentToolCall.name
836
+ };
837
+ currentToolCall = null;
827
838
  }
828
839
  }
829
840
  }
@@ -789,6 +789,11 @@ var OpenAIAdapter = class _OpenAIAdapter {
789
789
  id: currentToolCall.id,
790
790
  args: currentToolCall.arguments
791
791
  };
792
+ yield {
793
+ type: "action:end",
794
+ id: currentToolCall.id,
795
+ name: currentToolCall.name
796
+ };
792
797
  }
793
798
  const tcExtraContent = toolCall.extra_content;
794
799
  currentToolCall = {
@@ -822,6 +827,12 @@ var OpenAIAdapter = class _OpenAIAdapter {
822
827
  id: currentToolCall.id,
823
828
  args: currentToolCall.arguments
824
829
  };
830
+ yield {
831
+ type: "action:end",
832
+ id: currentToolCall.id,
833
+ name: currentToolCall.name
834
+ };
835
+ currentToolCall = null;
825
836
  }
826
837
  }
827
838
  }
@@ -301,6 +301,11 @@ var OllamaAdapter = class {
301
301
  id: toolCallId,
302
302
  args: JSON.stringify(toolCall.function?.arguments || {})
303
303
  };
304
+ yield {
305
+ type: "action:end",
306
+ id: toolCallId,
307
+ name: toolCall.function?.name || ""
308
+ };
304
309
  }
305
310
  hasEmittedToolCalls = true;
306
311
  }
@@ -299,6 +299,11 @@ var OllamaAdapter = class {
299
299
  id: toolCallId,
300
300
  args: JSON.stringify(toolCall.function?.arguments || {})
301
301
  };
302
+ yield {
303
+ type: "action:end",
304
+ id: toolCallId,
305
+ name: toolCall.function?.name || ""
306
+ };
302
307
  }
303
308
  hasEmittedToolCalls = true;
304
309
  }
@@ -772,6 +772,11 @@ var OpenAIAdapter = class _OpenAIAdapter {
772
772
  id: currentToolCall.id,
773
773
  args: currentToolCall.arguments
774
774
  };
775
+ yield {
776
+ type: "action:end",
777
+ id: currentToolCall.id,
778
+ name: currentToolCall.name
779
+ };
775
780
  }
776
781
  const tcExtraContent = toolCall.extra_content;
777
782
  currentToolCall = {
@@ -805,6 +810,12 @@ var OpenAIAdapter = class _OpenAIAdapter {
805
810
  id: currentToolCall.id,
806
811
  args: currentToolCall.arguments
807
812
  };
813
+ yield {
814
+ type: "action:end",
815
+ id: currentToolCall.id,
816
+ name: currentToolCall.name
817
+ };
818
+ currentToolCall = null;
808
819
  }
809
820
  }
810
821
  }
@@ -770,6 +770,11 @@ var OpenAIAdapter = class _OpenAIAdapter {
770
770
  id: currentToolCall.id,
771
771
  args: currentToolCall.arguments
772
772
  };
773
+ yield {
774
+ type: "action:end",
775
+ id: currentToolCall.id,
776
+ name: currentToolCall.name
777
+ };
773
778
  }
774
779
  const tcExtraContent = toolCall.extra_content;
775
780
  currentToolCall = {
@@ -803,6 +808,12 @@ var OpenAIAdapter = class _OpenAIAdapter {
803
808
  id: currentToolCall.id,
804
809
  args: currentToolCall.arguments
805
810
  };
811
+ yield {
812
+ type: "action:end",
813
+ id: currentToolCall.id,
814
+ name: currentToolCall.name
815
+ };
816
+ currentToolCall = null;
806
817
  }
807
818
  }
808
819
  }
@@ -758,6 +758,11 @@ var OpenAIAdapter = class _OpenAIAdapter {
758
758
  id: currentToolCall.id,
759
759
  args: currentToolCall.arguments
760
760
  };
761
+ yield {
762
+ type: "action:end",
763
+ id: currentToolCall.id,
764
+ name: currentToolCall.name
765
+ };
761
766
  }
762
767
  const tcExtraContent = toolCall.extra_content;
763
768
  currentToolCall = {
@@ -791,6 +796,12 @@ var OpenAIAdapter = class _OpenAIAdapter {
791
796
  id: currentToolCall.id,
792
797
  args: currentToolCall.arguments
793
798
  };
799
+ yield {
800
+ type: "action:end",
801
+ id: currentToolCall.id,
802
+ name: currentToolCall.name
803
+ };
804
+ currentToolCall = null;
794
805
  }
795
806
  }
796
807
  }
@@ -756,6 +756,11 @@ var OpenAIAdapter = class _OpenAIAdapter {
756
756
  id: currentToolCall.id,
757
757
  args: currentToolCall.arguments
758
758
  };
759
+ yield {
760
+ type: "action:end",
761
+ id: currentToolCall.id,
762
+ name: currentToolCall.name
763
+ };
759
764
  }
760
765
  const tcExtraContent = toolCall.extra_content;
761
766
  currentToolCall = {
@@ -789,6 +794,12 @@ var OpenAIAdapter = class _OpenAIAdapter {
789
794
  id: currentToolCall.id,
790
795
  args: currentToolCall.arguments
791
796
  };
797
+ yield {
798
+ type: "action:end",
799
+ id: currentToolCall.id,
800
+ name: currentToolCall.name
801
+ };
802
+ currentToolCall = null;
792
803
  }
793
804
  }
794
805
  }
@@ -0,0 +1,53 @@
1
+ import { L as LanguageModel } from '../../types-CR8mi9I0.mjs';
2
+ import 'zod';
3
+
4
+ /**
5
+ * Together AI Provider
6
+ *
7
+ * Together AI is a high-performance inference platform for open-source models
8
+ * (Llama, DeepSeek, Qwen, Mistral, Gemma, and more).
9
+ *
10
+ * It uses an OpenAI-compatible REST API.
11
+ *
12
+ * @see https://docs.together.ai/reference
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { togetherai } from '@yourgpt/llm-sdk/togetherai';
17
+ * import { generateText } from '@yourgpt/llm-sdk';
18
+ *
19
+ * const result = await generateText({
20
+ * model: togetherai('meta-llama/Llama-3.3-70B-Instruct-Turbo'),
21
+ * prompt: 'Hello!',
22
+ * });
23
+ * ```
24
+ */
25
+
26
+ interface TogetherAIProviderOptions {
27
+ /** API key (defaults to TOGETHER_API_KEY env var) */
28
+ apiKey?: string;
29
+ /** Base URL for API (defaults to https://api.together.xyz/v1) */
30
+ baseURL?: string;
31
+ }
32
+ /**
33
+ * Create a Together AI language model.
34
+ *
35
+ * Model IDs follow the format `org/model-name` (e.g. 'meta-llama/Llama-3.3-70B-Instruct-Turbo').
36
+ *
37
+ * @param modelId - Full model ID (e.g. 'meta-llama/Llama-3.3-70B-Instruct-Turbo')
38
+ * @param options - Provider options
39
+ * @returns LanguageModel instance
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * const model = togetherai('meta-llama/Llama-3.3-70B-Instruct-Turbo');
44
+ *
45
+ * // With explicit API key
46
+ * const model = togetherai('deepseek-ai/DeepSeek-V3', {
47
+ * apiKey: 'your-key',
48
+ * });
49
+ * ```
50
+ */
51
+ declare function togetherai(modelId: string, options?: TogetherAIProviderOptions): LanguageModel;
52
+
53
+ export { type TogetherAIProviderOptions, togetherai as createTogetherAI, togetherai };
@@ -0,0 +1,53 @@
1
+ import { L as LanguageModel } from '../../types-CR8mi9I0.js';
2
+ import 'zod';
3
+
4
+ /**
5
+ * Together AI Provider
6
+ *
7
+ * Together AI is a high-performance inference platform for open-source models
8
+ * (Llama, DeepSeek, Qwen, Mistral, Gemma, and more).
9
+ *
10
+ * It uses an OpenAI-compatible REST API.
11
+ *
12
+ * @see https://docs.together.ai/reference
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { togetherai } from '@yourgpt/llm-sdk/togetherai';
17
+ * import { generateText } from '@yourgpt/llm-sdk';
18
+ *
19
+ * const result = await generateText({
20
+ * model: togetherai('meta-llama/Llama-3.3-70B-Instruct-Turbo'),
21
+ * prompt: 'Hello!',
22
+ * });
23
+ * ```
24
+ */
25
+
26
+ interface TogetherAIProviderOptions {
27
+ /** API key (defaults to TOGETHER_API_KEY env var) */
28
+ apiKey?: string;
29
+ /** Base URL for API (defaults to https://api.together.xyz/v1) */
30
+ baseURL?: string;
31
+ }
32
+ /**
33
+ * Create a Together AI language model.
34
+ *
35
+ * Model IDs follow the format `org/model-name` (e.g. 'meta-llama/Llama-3.3-70B-Instruct-Turbo').
36
+ *
37
+ * @param modelId - Full model ID (e.g. 'meta-llama/Llama-3.3-70B-Instruct-Turbo')
38
+ * @param options - Provider options
39
+ * @returns LanguageModel instance
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * const model = togetherai('meta-llama/Llama-3.3-70B-Instruct-Turbo');
44
+ *
45
+ * // With explicit API key
46
+ * const model = togetherai('deepseek-ai/DeepSeek-V3', {
47
+ * apiKey: 'your-key',
48
+ * });
49
+ * ```
50
+ */
51
+ declare function togetherai(modelId: string, options?: TogetherAIProviderOptions): LanguageModel;
52
+
53
+ export { type TogetherAIProviderOptions, togetherai as createTogetherAI, togetherai };
@@ -0,0 +1,205 @@
1
+ 'use strict';
2
+
3
+ // src/providers/togetherai/provider.ts
4
+ function togetherai(modelId, options = {}) {
5
+ const apiKey = options.apiKey ?? process.env.TOGETHER_API_KEY;
6
+ const baseURL = options.baseURL ?? "https://api.together.xyz/v1";
7
+ let client = null;
8
+ async function getClient() {
9
+ if (!client) {
10
+ const { default: OpenAI } = await import('openai');
11
+ client = new OpenAI({ apiKey, baseURL });
12
+ }
13
+ return client;
14
+ }
15
+ return {
16
+ provider: "togetherai",
17
+ modelId,
18
+ capabilities: {
19
+ supportsVision: true,
20
+ supportsTools: true,
21
+ supportsStreaming: true,
22
+ supportsJsonMode: true,
23
+ supportsThinking: false,
24
+ supportsPDF: false,
25
+ maxTokens: 131072,
26
+ supportedImageTypes: ["image/png", "image/jpeg", "image/gif", "image/webp"]
27
+ },
28
+ async doGenerate(params) {
29
+ const client2 = await getClient();
30
+ const messages = formatMessages(params.messages);
31
+ const requestBody = {
32
+ model: modelId,
33
+ messages,
34
+ temperature: params.temperature,
35
+ max_tokens: params.maxTokens
36
+ };
37
+ if (params.tools) {
38
+ requestBody.tools = params.tools;
39
+ }
40
+ const response = await client2.chat.completions.create(requestBody);
41
+ const choice = response.choices[0];
42
+ const message = choice.message;
43
+ const toolCalls = (message.tool_calls ?? []).map(
44
+ (tc) => ({
45
+ id: tc.id,
46
+ name: tc.function.name,
47
+ args: JSON.parse(tc.function.arguments || "{}")
48
+ })
49
+ );
50
+ return {
51
+ text: message.content ?? "",
52
+ toolCalls,
53
+ finishReason: mapFinishReason(choice.finish_reason),
54
+ usage: {
55
+ promptTokens: response.usage?.prompt_tokens ?? 0,
56
+ completionTokens: response.usage?.completion_tokens ?? 0,
57
+ totalTokens: response.usage?.total_tokens ?? 0
58
+ },
59
+ rawResponse: response
60
+ };
61
+ },
62
+ async *doStream(params) {
63
+ const client2 = await getClient();
64
+ const messages = formatMessages(params.messages);
65
+ const requestBody = {
66
+ model: modelId,
67
+ messages,
68
+ temperature: params.temperature,
69
+ max_tokens: params.maxTokens,
70
+ stream: true
71
+ };
72
+ if (params.tools) {
73
+ requestBody.tools = params.tools;
74
+ }
75
+ const stream = await client2.chat.completions.create(requestBody);
76
+ const toolCallMap = /* @__PURE__ */ new Map();
77
+ let totalPromptTokens = 0;
78
+ let totalCompletionTokens = 0;
79
+ for await (const chunk of stream) {
80
+ if (params.signal?.aborted) {
81
+ yield { type: "error", error: new Error("Aborted") };
82
+ return;
83
+ }
84
+ const choice = chunk.choices[0];
85
+ const delta = choice?.delta;
86
+ if (delta?.content) {
87
+ yield { type: "text-delta", text: delta.content };
88
+ }
89
+ if (delta?.tool_calls) {
90
+ for (const tc of delta.tool_calls) {
91
+ const idx = tc.index ?? 0;
92
+ if (!toolCallMap.has(idx)) {
93
+ toolCallMap.set(idx, {
94
+ id: tc.id ?? "",
95
+ name: tc.function?.name ?? "",
96
+ arguments: tc.function?.arguments ?? ""
97
+ });
98
+ } else {
99
+ const existing = toolCallMap.get(idx);
100
+ if (tc.id && !existing.id) existing.id = tc.id;
101
+ if (tc.function?.name && !existing.name)
102
+ existing.name = tc.function.name;
103
+ if (tc.function?.arguments)
104
+ existing.arguments += tc.function.arguments;
105
+ }
106
+ }
107
+ }
108
+ if (choice?.finish_reason) {
109
+ for (const [, tc] of toolCallMap) {
110
+ yield {
111
+ type: "tool-call",
112
+ toolCall: {
113
+ id: tc.id,
114
+ name: tc.name,
115
+ args: JSON.parse(tc.arguments || "{}")
116
+ }
117
+ };
118
+ }
119
+ toolCallMap.clear();
120
+ if (chunk.usage) {
121
+ totalPromptTokens = chunk.usage.prompt_tokens;
122
+ totalCompletionTokens = chunk.usage.completion_tokens;
123
+ }
124
+ yield {
125
+ type: "finish",
126
+ finishReason: mapFinishReason(choice.finish_reason),
127
+ usage: {
128
+ promptTokens: totalPromptTokens,
129
+ completionTokens: totalCompletionTokens,
130
+ totalTokens: totalPromptTokens + totalCompletionTokens
131
+ }
132
+ };
133
+ }
134
+ }
135
+ }
136
+ };
137
+ }
138
+ function mapFinishReason(reason) {
139
+ switch (reason) {
140
+ case "stop":
141
+ return "stop";
142
+ case "length":
143
+ return "length";
144
+ case "tool_calls":
145
+ case "function_call":
146
+ return "tool-calls";
147
+ case "content_filter":
148
+ return "content-filter";
149
+ default:
150
+ return "unknown";
151
+ }
152
+ }
153
+ function formatMessages(messages) {
154
+ return messages.map((msg) => {
155
+ switch (msg.role) {
156
+ case "system":
157
+ return { role: "system", content: msg.content };
158
+ case "user":
159
+ if (typeof msg.content === "string") {
160
+ return { role: "user", content: msg.content };
161
+ }
162
+ return {
163
+ role: "user",
164
+ content: msg.content.map((part) => {
165
+ if (part.type === "text") {
166
+ return { type: "text", text: part.text };
167
+ }
168
+ if (part.type === "image") {
169
+ const imageData = typeof part.image === "string" ? part.image : Buffer.from(part.image).toString("base64");
170
+ const url = imageData.startsWith("data:") ? imageData : `data:${part.mimeType ?? "image/png"};base64,${imageData}`;
171
+ return { type: "image_url", image_url: { url, detail: "auto" } };
172
+ }
173
+ return { type: "text", text: "" };
174
+ })
175
+ };
176
+ case "assistant": {
177
+ const assistantMsg = { role: "assistant", content: msg.content };
178
+ if (msg.toolCalls && msg.toolCalls.length > 0) {
179
+ assistantMsg.tool_calls = msg.toolCalls.map((tc) => ({
180
+ id: tc.id,
181
+ type: "function",
182
+ function: {
183
+ name: tc.name,
184
+ arguments: JSON.stringify(tc.args)
185
+ }
186
+ }));
187
+ }
188
+ return assistantMsg;
189
+ }
190
+ case "tool":
191
+ return {
192
+ role: "tool",
193
+ tool_call_id: msg.toolCallId,
194
+ content: msg.content
195
+ };
196
+ default:
197
+ return msg;
198
+ }
199
+ });
200
+ }
201
+
202
+ exports.createTogetherAI = togetherai;
203
+ exports.togetherai = togetherai;
204
+ //# sourceMappingURL=index.js.map
205
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,202 @@
1
+ // src/providers/togetherai/provider.ts
2
+ function togetherai(modelId, options = {}) {
3
+ const apiKey = options.apiKey ?? process.env.TOGETHER_API_KEY;
4
+ const baseURL = options.baseURL ?? "https://api.together.xyz/v1";
5
+ let client = null;
6
+ async function getClient() {
7
+ if (!client) {
8
+ const { default: OpenAI } = await import('openai');
9
+ client = new OpenAI({ apiKey, baseURL });
10
+ }
11
+ return client;
12
+ }
13
+ return {
14
+ provider: "togetherai",
15
+ modelId,
16
+ capabilities: {
17
+ supportsVision: true,
18
+ supportsTools: true,
19
+ supportsStreaming: true,
20
+ supportsJsonMode: true,
21
+ supportsThinking: false,
22
+ supportsPDF: false,
23
+ maxTokens: 131072,
24
+ supportedImageTypes: ["image/png", "image/jpeg", "image/gif", "image/webp"]
25
+ },
26
+ async doGenerate(params) {
27
+ const client2 = await getClient();
28
+ const messages = formatMessages(params.messages);
29
+ const requestBody = {
30
+ model: modelId,
31
+ messages,
32
+ temperature: params.temperature,
33
+ max_tokens: params.maxTokens
34
+ };
35
+ if (params.tools) {
36
+ requestBody.tools = params.tools;
37
+ }
38
+ const response = await client2.chat.completions.create(requestBody);
39
+ const choice = response.choices[0];
40
+ const message = choice.message;
41
+ const toolCalls = (message.tool_calls ?? []).map(
42
+ (tc) => ({
43
+ id: tc.id,
44
+ name: tc.function.name,
45
+ args: JSON.parse(tc.function.arguments || "{}")
46
+ })
47
+ );
48
+ return {
49
+ text: message.content ?? "",
50
+ toolCalls,
51
+ finishReason: mapFinishReason(choice.finish_reason),
52
+ usage: {
53
+ promptTokens: response.usage?.prompt_tokens ?? 0,
54
+ completionTokens: response.usage?.completion_tokens ?? 0,
55
+ totalTokens: response.usage?.total_tokens ?? 0
56
+ },
57
+ rawResponse: response
58
+ };
59
+ },
60
+ async *doStream(params) {
61
+ const client2 = await getClient();
62
+ const messages = formatMessages(params.messages);
63
+ const requestBody = {
64
+ model: modelId,
65
+ messages,
66
+ temperature: params.temperature,
67
+ max_tokens: params.maxTokens,
68
+ stream: true
69
+ };
70
+ if (params.tools) {
71
+ requestBody.tools = params.tools;
72
+ }
73
+ const stream = await client2.chat.completions.create(requestBody);
74
+ const toolCallMap = /* @__PURE__ */ new Map();
75
+ let totalPromptTokens = 0;
76
+ let totalCompletionTokens = 0;
77
+ for await (const chunk of stream) {
78
+ if (params.signal?.aborted) {
79
+ yield { type: "error", error: new Error("Aborted") };
80
+ return;
81
+ }
82
+ const choice = chunk.choices[0];
83
+ const delta = choice?.delta;
84
+ if (delta?.content) {
85
+ yield { type: "text-delta", text: delta.content };
86
+ }
87
+ if (delta?.tool_calls) {
88
+ for (const tc of delta.tool_calls) {
89
+ const idx = tc.index ?? 0;
90
+ if (!toolCallMap.has(idx)) {
91
+ toolCallMap.set(idx, {
92
+ id: tc.id ?? "",
93
+ name: tc.function?.name ?? "",
94
+ arguments: tc.function?.arguments ?? ""
95
+ });
96
+ } else {
97
+ const existing = toolCallMap.get(idx);
98
+ if (tc.id && !existing.id) existing.id = tc.id;
99
+ if (tc.function?.name && !existing.name)
100
+ existing.name = tc.function.name;
101
+ if (tc.function?.arguments)
102
+ existing.arguments += tc.function.arguments;
103
+ }
104
+ }
105
+ }
106
+ if (choice?.finish_reason) {
107
+ for (const [, tc] of toolCallMap) {
108
+ yield {
109
+ type: "tool-call",
110
+ toolCall: {
111
+ id: tc.id,
112
+ name: tc.name,
113
+ args: JSON.parse(tc.arguments || "{}")
114
+ }
115
+ };
116
+ }
117
+ toolCallMap.clear();
118
+ if (chunk.usage) {
119
+ totalPromptTokens = chunk.usage.prompt_tokens;
120
+ totalCompletionTokens = chunk.usage.completion_tokens;
121
+ }
122
+ yield {
123
+ type: "finish",
124
+ finishReason: mapFinishReason(choice.finish_reason),
125
+ usage: {
126
+ promptTokens: totalPromptTokens,
127
+ completionTokens: totalCompletionTokens,
128
+ totalTokens: totalPromptTokens + totalCompletionTokens
129
+ }
130
+ };
131
+ }
132
+ }
133
+ }
134
+ };
135
+ }
136
+ function mapFinishReason(reason) {
137
+ switch (reason) {
138
+ case "stop":
139
+ return "stop";
140
+ case "length":
141
+ return "length";
142
+ case "tool_calls":
143
+ case "function_call":
144
+ return "tool-calls";
145
+ case "content_filter":
146
+ return "content-filter";
147
+ default:
148
+ return "unknown";
149
+ }
150
+ }
151
+ function formatMessages(messages) {
152
+ return messages.map((msg) => {
153
+ switch (msg.role) {
154
+ case "system":
155
+ return { role: "system", content: msg.content };
156
+ case "user":
157
+ if (typeof msg.content === "string") {
158
+ return { role: "user", content: msg.content };
159
+ }
160
+ return {
161
+ role: "user",
162
+ content: msg.content.map((part) => {
163
+ if (part.type === "text") {
164
+ return { type: "text", text: part.text };
165
+ }
166
+ if (part.type === "image") {
167
+ const imageData = typeof part.image === "string" ? part.image : Buffer.from(part.image).toString("base64");
168
+ const url = imageData.startsWith("data:") ? imageData : `data:${part.mimeType ?? "image/png"};base64,${imageData}`;
169
+ return { type: "image_url", image_url: { url, detail: "auto" } };
170
+ }
171
+ return { type: "text", text: "" };
172
+ })
173
+ };
174
+ case "assistant": {
175
+ const assistantMsg = { role: "assistant", content: msg.content };
176
+ if (msg.toolCalls && msg.toolCalls.length > 0) {
177
+ assistantMsg.tool_calls = msg.toolCalls.map((tc) => ({
178
+ id: tc.id,
179
+ type: "function",
180
+ function: {
181
+ name: tc.name,
182
+ arguments: JSON.stringify(tc.args)
183
+ }
184
+ }));
185
+ }
186
+ return assistantMsg;
187
+ }
188
+ case "tool":
189
+ return {
190
+ role: "tool",
191
+ tool_call_id: msg.toolCallId,
192
+ content: msg.content
193
+ };
194
+ default:
195
+ return msg;
196
+ }
197
+ });
198
+ }
199
+
200
+ export { togetherai as createTogetherAI, togetherai };
201
+ //# sourceMappingURL=index.mjs.map
202
+ //# sourceMappingURL=index.mjs.map
@@ -740,6 +740,11 @@ var OpenAIAdapter = class _OpenAIAdapter {
740
740
  id: currentToolCall.id,
741
741
  args: currentToolCall.arguments
742
742
  };
743
+ yield {
744
+ type: "action:end",
745
+ id: currentToolCall.id,
746
+ name: currentToolCall.name
747
+ };
743
748
  }
744
749
  const tcExtraContent = toolCall.extra_content;
745
750
  currentToolCall = {
@@ -773,6 +778,12 @@ var OpenAIAdapter = class _OpenAIAdapter {
773
778
  id: currentToolCall.id,
774
779
  args: currentToolCall.arguments
775
780
  };
781
+ yield {
782
+ type: "action:end",
783
+ id: currentToolCall.id,
784
+ name: currentToolCall.name
785
+ };
786
+ currentToolCall = null;
776
787
  }
777
788
  }
778
789
  }
@@ -738,6 +738,11 @@ var OpenAIAdapter = class _OpenAIAdapter {
738
738
  id: currentToolCall.id,
739
739
  args: currentToolCall.arguments
740
740
  };
741
+ yield {
742
+ type: "action:end",
743
+ id: currentToolCall.id,
744
+ name: currentToolCall.name
745
+ };
741
746
  }
742
747
  const tcExtraContent = toolCall.extra_content;
743
748
  currentToolCall = {
@@ -771,6 +776,12 @@ var OpenAIAdapter = class _OpenAIAdapter {
771
776
  id: currentToolCall.id,
772
777
  args: currentToolCall.arguments
773
778
  };
779
+ yield {
780
+ type: "action:end",
781
+ id: currentToolCall.id,
782
+ name: currentToolCall.name
783
+ };
784
+ currentToolCall = null;
774
785
  }
775
786
  }
776
787
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yourgpt/llm-sdk",
3
- "version": "2.1.7",
3
+ "version": "2.1.8",
4
4
  "description": "AI SDK for building AI Agents with any LLM",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -51,6 +51,11 @@
51
51
  "import": "./dist/providers/fireworks/index.mjs",
52
52
  "require": "./dist/providers/fireworks/index.js"
53
53
  },
54
+ "./togetherai": {
55
+ "types": "./dist/providers/togetherai/index.d.mts",
56
+ "import": "./dist/providers/togetherai/index.mjs",
57
+ "require": "./dist/providers/togetherai/index.js"
58
+ },
54
59
  "./adapters": {
55
60
  "types": "./dist/adapters/index.d.ts",
56
61
  "import": "./dist/adapters/index.mjs",
@@ -119,6 +124,8 @@
119
124
  "ollama",
120
125
  "openrouter",
121
126
  "fireworks",
127
+ "togetherai",
128
+ "together-ai",
122
129
  "multi-provider",
123
130
  "streaming"
124
131
  ],