@inferencesh/sdk 0.6.49 → 0.6.50

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.
@@ -139,8 +139,18 @@ export function createActions(ctx) {
139
139
  checkTurnEnd(chatData);
140
140
  }
141
141
  });
142
+ // Token-by-token streaming state, reset at every assistant-message boundary.
143
+ const deltaAccum = createLLMDeltaAccumulator();
142
144
  // Listen for ChatMessage updates
143
145
  manager.addEventListener('chat_messages', (message, fields) => {
146
+ // A new assistant message starts a new accumulation. The accumulator is
147
+ // cumulative and shared across the whole connection, so without this the
148
+ // next message's deltas merge into the previous message's state — and
149
+ // because concat with "" is a no-op, a turn that is only tool calls
150
+ // would render the previous message's text as its own.
151
+ if (message.role === 'assistant' && !getState().messages.some(m => m.id === message.id)) {
152
+ deltaAccum.reset();
153
+ }
144
154
  updateMessage(message, fields);
145
155
  });
146
156
  // Listen for AgentRun updates (state transitions, output)
@@ -152,8 +162,6 @@ export function createActions(ctx) {
152
162
  if (currentChat)
153
163
  checkTurnEnd({ ...currentChat, active_run: run });
154
164
  });
155
- // Listen for LLM delta events (token-by-token streaming)
156
- const deltaAccum = createLLMDeltaAccumulator();
157
165
  manager.addEventListener('delta', (evt) => {
158
166
  if (evt && evt.delta) {
159
167
  deltaAccum.apply(evt.delta);
package/dist/delta.d.ts CHANGED
@@ -8,6 +8,14 @@ export declare class DeltaAccumulator {
8
8
  private tags;
9
9
  private registry;
10
10
  constructor(tags: FieldTags, registry?: FieldTagsRegistry);
11
+ /**
12
+ * Discard everything accumulated so far. Required at a message boundary: the
13
+ * accumulator is cumulative, so without a reset the next message's deltas
14
+ * merge into the previous message's state. Concat makes that invisible for
15
+ * text — appending "" leaves the old text in place, so a tool-call-only turn
16
+ * serves the previous message's answer as its own.
17
+ */
18
+ reset(): void;
11
19
  seed(output: Record<string, any>): void;
12
20
  apply(delta: Record<string, any>): void;
13
21
  toOutput(): Record<string, any>;
package/dist/delta.js CHANGED
@@ -57,6 +57,16 @@ export class DeltaAccumulator {
57
57
  this.tags = tags;
58
58
  this.registry = registry;
59
59
  }
60
+ /**
61
+ * Discard everything accumulated so far. Required at a message boundary: the
62
+ * accumulator is cumulative, so without a reset the next message's deltas
63
+ * merge into the previous message's state. Concat makes that invisible for
64
+ * text — appending "" leaves the old text in place, so a tool-call-only turn
65
+ * serves the previous message's answer as its own.
66
+ */
67
+ reset() {
68
+ this.state = {};
69
+ }
60
70
  seed(output) {
61
71
  for (const [key, value] of Object.entries(output)) {
62
72
  if (value != null)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inferencesh/sdk",
3
- "version": "0.6.49",
3
+ "version": "0.6.50",
4
4
  "description": "Official JavaScript/TypeScript SDK for inference.sh - Run AI models with a simple API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",