ai-sdk-provider-claude-code 2.2.0 → 2.2.2
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/README.md +5 -3
- package/dist/index.cjs +65 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +65 -11
- package/dist/index.js.map +1 -1
- package/docs/ai-sdk-v5/GUIDE.md +16 -16
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -192,9 +192,11 @@ Key changes:
|
|
|
192
192
|
|
|
193
193
|
## Models
|
|
194
194
|
|
|
195
|
-
- **`opus`** - Claude
|
|
196
|
-
- **`sonnet`** - Claude
|
|
197
|
-
- **`haiku`** - Claude
|
|
195
|
+
- **`opus`** - Claude Opus (most capable)
|
|
196
|
+
- **`sonnet`** - Claude Sonnet (balanced performance)
|
|
197
|
+
- **`haiku`** - Claude Haiku (fastest, most cost-effective)
|
|
198
|
+
|
|
199
|
+
You can also use full model identifiers directly (e.g., `claude-opus-4-5`, `claude-sonnet-4-5-20250514`).
|
|
198
200
|
|
|
199
201
|
## Documentation
|
|
200
202
|
|
package/dist/index.cjs
CHANGED
|
@@ -1189,6 +1189,9 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
|
|
|
1189
1189
|
options.abortSignal.addEventListener("abort", abortListener, { once: true });
|
|
1190
1190
|
}
|
|
1191
1191
|
const queryOptions = this.createQueryOptions(abortController, options.responseFormat);
|
|
1192
|
+
if (queryOptions.includePartialMessages === void 0) {
|
|
1193
|
+
queryOptions.includePartialMessages = true;
|
|
1194
|
+
}
|
|
1192
1195
|
const warnings = this.generateAllWarnings(
|
|
1193
1196
|
options,
|
|
1194
1197
|
messagesPrompt
|
|
@@ -1260,6 +1263,8 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
|
|
|
1260
1263
|
let usage = { inputTokens: 0, outputTokens: 0, totalTokens: 0 };
|
|
1261
1264
|
let accumulatedText = "";
|
|
1262
1265
|
let textPartId;
|
|
1266
|
+
let streamedTextLength = 0;
|
|
1267
|
+
let hasReceivedStreamEvents = false;
|
|
1263
1268
|
try {
|
|
1264
1269
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1265
1270
|
if (this.settings.canUseTool && this.settings.permissionPromptToolName) {
|
|
@@ -1282,6 +1287,34 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
|
|
|
1282
1287
|
});
|
|
1283
1288
|
for await (const message of response) {
|
|
1284
1289
|
this.logger.debug(`[claude-code] Stream received message type: ${message.type}`);
|
|
1290
|
+
if (message.type === "stream_event") {
|
|
1291
|
+
const streamEvent = message;
|
|
1292
|
+
const event = streamEvent.event;
|
|
1293
|
+
if (event.type === "content_block_delta" && event.delta.type === "text_delta" && "text" in event.delta && event.delta.text) {
|
|
1294
|
+
const deltaText = event.delta.text;
|
|
1295
|
+
hasReceivedStreamEvents = true;
|
|
1296
|
+
if (options.responseFormat?.type === "json") {
|
|
1297
|
+
accumulatedText += deltaText;
|
|
1298
|
+
streamedTextLength += deltaText.length;
|
|
1299
|
+
continue;
|
|
1300
|
+
}
|
|
1301
|
+
if (!textPartId) {
|
|
1302
|
+
textPartId = (0, import_provider_utils.generateId)();
|
|
1303
|
+
controller.enqueue({
|
|
1304
|
+
type: "text-start",
|
|
1305
|
+
id: textPartId
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
controller.enqueue({
|
|
1309
|
+
type: "text-delta",
|
|
1310
|
+
id: textPartId,
|
|
1311
|
+
delta: deltaText
|
|
1312
|
+
});
|
|
1313
|
+
accumulatedText += deltaText;
|
|
1314
|
+
streamedTextLength += deltaText.length;
|
|
1315
|
+
}
|
|
1316
|
+
continue;
|
|
1317
|
+
}
|
|
1285
1318
|
if (message.type === "assistant") {
|
|
1286
1319
|
if (!message.message?.content) {
|
|
1287
1320
|
this.logger.warn(
|
|
@@ -1344,20 +1377,41 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
|
|
|
1344
1377
|
}
|
|
1345
1378
|
const text = content.map((c) => c.type === "text" ? c.text : "").join("");
|
|
1346
1379
|
if (text) {
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1380
|
+
if (hasReceivedStreamEvents) {
|
|
1381
|
+
const newTextStart = streamedTextLength;
|
|
1382
|
+
const deltaText = text.length > newTextStart ? text.slice(newTextStart) : "";
|
|
1383
|
+
accumulatedText = text;
|
|
1384
|
+
if (options.responseFormat?.type !== "json" && deltaText) {
|
|
1385
|
+
if (!textPartId) {
|
|
1386
|
+
textPartId = (0, import_provider_utils.generateId)();
|
|
1387
|
+
controller.enqueue({
|
|
1388
|
+
type: "text-start",
|
|
1389
|
+
id: textPartId
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1351
1392
|
controller.enqueue({
|
|
1352
|
-
type: "text-
|
|
1353
|
-
id: textPartId
|
|
1393
|
+
type: "text-delta",
|
|
1394
|
+
id: textPartId,
|
|
1395
|
+
delta: deltaText
|
|
1396
|
+
});
|
|
1397
|
+
}
|
|
1398
|
+
streamedTextLength = text.length;
|
|
1399
|
+
} else {
|
|
1400
|
+
accumulatedText += text;
|
|
1401
|
+
if (options.responseFormat?.type !== "json") {
|
|
1402
|
+
if (!textPartId) {
|
|
1403
|
+
textPartId = (0, import_provider_utils.generateId)();
|
|
1404
|
+
controller.enqueue({
|
|
1405
|
+
type: "text-start",
|
|
1406
|
+
id: textPartId
|
|
1407
|
+
});
|
|
1408
|
+
}
|
|
1409
|
+
controller.enqueue({
|
|
1410
|
+
type: "text-delta",
|
|
1411
|
+
id: textPartId,
|
|
1412
|
+
delta: text
|
|
1354
1413
|
});
|
|
1355
1414
|
}
|
|
1356
|
-
controller.enqueue({
|
|
1357
|
-
type: "text-delta",
|
|
1358
|
-
id: textPartId,
|
|
1359
|
-
delta: text
|
|
1360
|
-
});
|
|
1361
1415
|
}
|
|
1362
1416
|
}
|
|
1363
1417
|
} else if (message.type === "user") {
|