@to11ai/sdk 2.0.0-rc.4 → 2.0.0-rc.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/dist/gateway.cjs +14 -9
- package/dist/gateway.d.ts +25 -5
- package/dist/gateway.js +14 -9
- package/package.json +3 -1
- package/src/gateway.ts +48 -23
package/dist/gateway.cjs
CHANGED
|
@@ -183,24 +183,29 @@ function toOpenAIMessages(messages, options = {}) {
|
|
|
183
183
|
return;
|
|
184
184
|
}
|
|
185
185
|
if (message.role === "assistant") {
|
|
186
|
-
const
|
|
186
|
+
const content2 = message.content ?? null;
|
|
187
|
+
out.push(message.toolCalls != null && message.toolCalls.length > 0 ? {
|
|
187
188
|
role: "assistant",
|
|
188
|
-
content:
|
|
189
|
-
|
|
190
|
-
if (message.toolCalls != null && message.toolCalls.length > 0) {
|
|
191
|
-
msg.tool_calls = message.toolCalls.map((call) => ({
|
|
189
|
+
content: content2,
|
|
190
|
+
tool_calls: message.toolCalls.map((call) => ({
|
|
192
191
|
id: requireToolCallId(call.id),
|
|
193
192
|
type: "function",
|
|
194
193
|
function: {
|
|
195
194
|
name: call.name,
|
|
196
195
|
arguments: JSON.stringify(call.arguments)
|
|
197
196
|
}
|
|
198
|
-
}))
|
|
199
|
-
}
|
|
200
|
-
out.push(msg);
|
|
197
|
+
}))
|
|
198
|
+
} : { role: "assistant", content: content2 });
|
|
201
199
|
return;
|
|
202
200
|
}
|
|
203
|
-
|
|
201
|
+
const content = message.content ?? "";
|
|
202
|
+
if (message.role === "user") {
|
|
203
|
+
out.push({ role: "user", content });
|
|
204
|
+
} else if (message.role === "developer") {
|
|
205
|
+
out.push({ role: "developer", content });
|
|
206
|
+
} else {
|
|
207
|
+
out.push({ role: "system", content });
|
|
208
|
+
}
|
|
204
209
|
});
|
|
205
210
|
return out;
|
|
206
211
|
}
|
package/dist/gateway.d.ts
CHANGED
|
@@ -95,13 +95,33 @@ export interface OpenAIToolCall {
|
|
|
95
95
|
arguments: string;
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
|
-
/**
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
/**
|
|
99
|
+
* OpenAI Chat Completions `messages[]` entry — a per-role discriminated union
|
|
100
|
+
* matching what Chat Completions requires for each role, so an
|
|
101
|
+
* `OpenAIChatMessage[]` is structurally assignable to the `openai` package's
|
|
102
|
+
* `ChatCompletionMessageParam[]` (a `render({ format: "openai" })` result spreads
|
|
103
|
+
* straight into `openai.chat.completions.create({ messages })` with no cast).
|
|
104
|
+
* The SDK carries no dependency on the `openai` package — this only mirrors its
|
|
105
|
+
* shape. (Assignability is regression-guarded in `gateway.provider-types.test.ts`.)
|
|
106
|
+
*/
|
|
107
|
+
export type OpenAIChatMessage = {
|
|
108
|
+
role: "system";
|
|
109
|
+
content: string;
|
|
110
|
+
} | {
|
|
111
|
+
role: "developer";
|
|
112
|
+
content: string;
|
|
113
|
+
} | {
|
|
114
|
+
role: "user";
|
|
115
|
+
content: string;
|
|
116
|
+
} | {
|
|
117
|
+
role: "assistant";
|
|
101
118
|
content?: string | null;
|
|
102
119
|
tool_calls?: OpenAIToolCall[];
|
|
103
|
-
|
|
104
|
-
|
|
120
|
+
} | {
|
|
121
|
+
role: "tool";
|
|
122
|
+
tool_call_id: string;
|
|
123
|
+
content: string;
|
|
124
|
+
};
|
|
105
125
|
/** Anthropic Messages `tools[]` entry. */
|
|
106
126
|
export interface AnthropicTool {
|
|
107
127
|
name: string;
|
package/dist/gateway.js
CHANGED
|
@@ -134,24 +134,29 @@ function toOpenAIMessages(messages, options = {}) {
|
|
|
134
134
|
return;
|
|
135
135
|
}
|
|
136
136
|
if (message.role === "assistant") {
|
|
137
|
-
const
|
|
137
|
+
const content2 = message.content ?? null;
|
|
138
|
+
out.push(message.toolCalls != null && message.toolCalls.length > 0 ? {
|
|
138
139
|
role: "assistant",
|
|
139
|
-
content:
|
|
140
|
-
|
|
141
|
-
if (message.toolCalls != null && message.toolCalls.length > 0) {
|
|
142
|
-
msg.tool_calls = message.toolCalls.map((call) => ({
|
|
140
|
+
content: content2,
|
|
141
|
+
tool_calls: message.toolCalls.map((call) => ({
|
|
143
142
|
id: requireToolCallId(call.id),
|
|
144
143
|
type: "function",
|
|
145
144
|
function: {
|
|
146
145
|
name: call.name,
|
|
147
146
|
arguments: JSON.stringify(call.arguments)
|
|
148
147
|
}
|
|
149
|
-
}))
|
|
150
|
-
}
|
|
151
|
-
out.push(msg);
|
|
148
|
+
}))
|
|
149
|
+
} : { role: "assistant", content: content2 });
|
|
152
150
|
return;
|
|
153
151
|
}
|
|
154
|
-
|
|
152
|
+
const content = message.content ?? "";
|
|
153
|
+
if (message.role === "user") {
|
|
154
|
+
out.push({ role: "user", content });
|
|
155
|
+
} else if (message.role === "developer") {
|
|
156
|
+
out.push({ role: "developer", content });
|
|
157
|
+
} else {
|
|
158
|
+
out.push({ role: "system", content });
|
|
159
|
+
}
|
|
155
160
|
});
|
|
156
161
|
return out;
|
|
157
162
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@to11ai/sdk",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.5",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -82,10 +82,12 @@
|
|
|
82
82
|
"format": "biome format --write ."
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
|
+
"@anthropic-ai/sdk": "^0.39.0",
|
|
85
86
|
"@biomejs/biome": "2.4.16",
|
|
86
87
|
"@hey-api/openapi-ts": "0.98.2",
|
|
87
88
|
"@opentelemetry/api": "^1.9.1",
|
|
88
89
|
"@types/bun": "^1.3.14",
|
|
90
|
+
"openai": "^4.67.0",
|
|
89
91
|
"typescript": "^6.0.3"
|
|
90
92
|
},
|
|
91
93
|
"dependencies": {
|
package/src/gateway.ts
CHANGED
|
@@ -180,13 +180,25 @@ export interface OpenAIToolCall {
|
|
|
180
180
|
function: { name: string; arguments: string };
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
/**
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
183
|
+
/**
|
|
184
|
+
* OpenAI Chat Completions `messages[]` entry — a per-role discriminated union
|
|
185
|
+
* matching what Chat Completions requires for each role, so an
|
|
186
|
+
* `OpenAIChatMessage[]` is structurally assignable to the `openai` package's
|
|
187
|
+
* `ChatCompletionMessageParam[]` (a `render({ format: "openai" })` result spreads
|
|
188
|
+
* straight into `openai.chat.completions.create({ messages })` with no cast).
|
|
189
|
+
* The SDK carries no dependency on the `openai` package — this only mirrors its
|
|
190
|
+
* shape. (Assignability is regression-guarded in `gateway.provider-types.test.ts`.)
|
|
191
|
+
*/
|
|
192
|
+
export type OpenAIChatMessage =
|
|
193
|
+
| { role: "system"; content: string }
|
|
194
|
+
| { role: "developer"; content: string }
|
|
195
|
+
| { role: "user"; content: string }
|
|
196
|
+
| {
|
|
197
|
+
role: "assistant";
|
|
198
|
+
content?: string | null;
|
|
199
|
+
tool_calls?: OpenAIToolCall[];
|
|
200
|
+
}
|
|
201
|
+
| { role: "tool"; tool_call_id: string; content: string };
|
|
190
202
|
|
|
191
203
|
/** Anthropic Messages `tools[]` entry. */
|
|
192
204
|
export interface AnthropicTool {
|
|
@@ -410,24 +422,37 @@ export function toOpenAIMessages(
|
|
|
410
422
|
return;
|
|
411
423
|
}
|
|
412
424
|
if (message.role === "assistant") {
|
|
413
|
-
const
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
425
|
+
const content = message.content ?? null;
|
|
426
|
+
out.push(
|
|
427
|
+
message.toolCalls != null && message.toolCalls.length > 0
|
|
428
|
+
? {
|
|
429
|
+
role: "assistant",
|
|
430
|
+
content,
|
|
431
|
+
tool_calls: message.toolCalls.map((call) => ({
|
|
432
|
+
id: requireToolCallId(call.id),
|
|
433
|
+
type: "function",
|
|
434
|
+
function: {
|
|
435
|
+
name: call.name,
|
|
436
|
+
arguments: JSON.stringify(call.arguments),
|
|
437
|
+
},
|
|
438
|
+
})),
|
|
439
|
+
}
|
|
440
|
+
: { role: "assistant", content },
|
|
441
|
+
);
|
|
428
442
|
return;
|
|
429
443
|
}
|
|
430
|
-
|
|
444
|
+
// Remaining plain-text roles: `system` | `developer` | `user`. Push a
|
|
445
|
+
// literal-role object per branch so each element lands on a single union
|
|
446
|
+
// member (a union-typed `role` wouldn't be assignable to the discriminated
|
|
447
|
+
// ChatCompletionMessageParam).
|
|
448
|
+
const content = message.content ?? "";
|
|
449
|
+
if (message.role === "user") {
|
|
450
|
+
out.push({ role: "user", content });
|
|
451
|
+
} else if (message.role === "developer") {
|
|
452
|
+
out.push({ role: "developer", content });
|
|
453
|
+
} else {
|
|
454
|
+
out.push({ role: "system", content });
|
|
455
|
+
}
|
|
431
456
|
});
|
|
432
457
|
return out;
|
|
433
458
|
}
|