ai-sdk-provider-claude-code 2.2.2 → 2.2.3

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/index.cjs CHANGED
@@ -1313,6 +1313,26 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
1313
1313
  accumulatedText += deltaText;
1314
1314
  streamedTextLength += deltaText.length;
1315
1315
  }
1316
+ if (event.type === "content_block_delta" && event.delta.type === "input_json_delta" && "partial_json" in event.delta && event.delta.partial_json) {
1317
+ const jsonDelta = event.delta.partial_json;
1318
+ hasReceivedStreamEvents = true;
1319
+ if (options.responseFormat?.type === "json") {
1320
+ if (!textPartId) {
1321
+ textPartId = (0, import_provider_utils.generateId)();
1322
+ controller.enqueue({
1323
+ type: "text-start",
1324
+ id: textPartId
1325
+ });
1326
+ }
1327
+ controller.enqueue({
1328
+ type: "text-delta",
1329
+ id: textPartId,
1330
+ delta: jsonDelta
1331
+ });
1332
+ accumulatedText += jsonDelta;
1333
+ streamedTextLength += jsonDelta.length;
1334
+ }
1335
+ }
1316
1336
  continue;
1317
1337
  }
1318
1338
  if (message.type === "assistant") {
@@ -1556,7 +1576,13 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
1556
1576
  this.logger.debug(`[claude-code] Stream finish reason: ${finishReason}`);
1557
1577
  this.setSessionId(message.session_id);
1558
1578
  const structuredOutput = "structured_output" in message ? message.structured_output : void 0;
1559
- if (structuredOutput !== void 0) {
1579
+ const alreadyStreamedJson = textPartId && options.responseFormat?.type === "json" && hasReceivedStreamEvents;
1580
+ if (alreadyStreamedJson && textPartId) {
1581
+ controller.enqueue({
1582
+ type: "text-end",
1583
+ id: textPartId
1584
+ });
1585
+ } else if (structuredOutput !== void 0) {
1560
1586
  const jsonTextId = (0, import_provider_utils.generateId)();
1561
1587
  const jsonText = JSON.stringify(structuredOutput);
1562
1588
  controller.enqueue({