@codehz/ai 0.2.2 → 0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codehz/ai",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "type": "module",
5
5
  "module": "dist/index.mjs",
6
6
  "exports": {
@@ -116,12 +116,25 @@ function getActiveItem(state: AggregatorState, itemId: string, expectedType: Act
116
116
  return item;
117
117
  }
118
118
 
119
+ function coalesceContentBlocks(blocks: readonly ContentBlock[]): ContentBlock[] {
120
+ const result: ContentBlock[] = [];
121
+ for (const block of blocks) {
122
+ const previous = result[result.length - 1];
123
+ if (block.type === "text" && previous?.type === "text") {
124
+ previous.text += block.text;
125
+ } else {
126
+ result.push({ ...block });
127
+ }
128
+ }
129
+ return result;
130
+ }
131
+
119
132
  function finalizeMessage(active: ActiveMessage): MessageItem {
120
133
  return {
121
134
  type: "message",
122
135
  id: active.id,
123
136
  role: active.role,
124
- content: active.content,
137
+ content: coalesceContentBlocks(active.content),
125
138
  };
126
139
  }
127
140
 
@@ -130,7 +143,7 @@ function finalizeReasoning(active: ActiveReasoning): import("../types/index.js")
130
143
  type: "reasoning",
131
144
  id: active.id,
132
145
  visibility: active.visibility,
133
- content: active.content,
146
+ content: coalesceContentBlocks(active.content),
134
147
  };
135
148
  }
136
149