@ai-sdk/harness 1.0.100 → 1.0.102

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  DelayedPromise,
3
- generateId,
3
+ type InferToolSetContext,
4
4
  type AssistantModelMessage,
5
5
  type Context,
6
6
  type ToolModelMessage,
@@ -154,9 +154,10 @@ export class HarnessStreamTextResult<
154
154
 
155
155
  private readonly tools: TOOLS;
156
156
  private readonly runtimeContext: RUNTIME_CONTEXT;
157
- private readonly toolsContext: never;
157
+ private readonly toolsContext: InferToolSetContext<TOOLS>;
158
158
  private readonly providerName: string;
159
- private readonly modelId: string;
159
+ private readonly callId: string;
160
+ private modelId: string;
160
161
  private readonly outputSpecification: OUTPUT | undefined;
161
162
 
162
163
  // Accumulators that span the whole turn.
@@ -170,16 +171,18 @@ export class HarnessStreamTextResult<
170
171
  constructor(options: {
171
172
  tools: TOOLS;
172
173
  runtimeContext: RUNTIME_CONTEXT;
173
- toolsContext: never;
174
+ toolsContext: InferToolSetContext<TOOLS>;
174
175
  harnessId: string;
175
- sessionId: string;
176
+ callId: string;
177
+ modelId: string;
176
178
  output: OUTPUT | undefined;
177
179
  }) {
178
180
  this.tools = options.tools;
179
181
  this.runtimeContext = options.runtimeContext;
180
182
  this.toolsContext = options.toolsContext;
181
183
  this.providerName = `harness:${options.harnessId}`;
182
- this.modelId = options.sessionId;
184
+ this.callId = options.callId;
185
+ this.modelId = options.modelId;
183
186
  this.outputSpecification = options.output;
184
187
 
185
188
  let controllerRef!: ReadableStreamDefaultController<TextStreamPart<TOOLS>>;
@@ -224,6 +227,12 @@ export class HarnessStreamTextResult<
224
227
  this.appendToCurrentStepContent(part);
225
228
  }
226
229
 
230
+ setModelId(modelId: string): void {
231
+ if (this.stepsBuffer.length === 0) {
232
+ this.modelId = modelId;
233
+ }
234
+ }
235
+
227
236
  /**
228
237
  * Push a continuation input into the consumer stream without attributing it
229
238
  * to the next model step. Approval responses and client tool results arrive
@@ -262,7 +271,7 @@ export class HarnessStreamTextResult<
262
271
  const rawFinishReason = input.finishReason.raw;
263
272
 
264
273
  const step = new DefaultStepResult<TOOLS, RUNTIME_CONTEXT>({
265
- callId: generateId(),
274
+ callId: this.callId,
266
275
  stepNumber: this.stepNumber,
267
276
  provider: this.providerName,
268
277
  modelId: this.modelId,
@@ -276,7 +285,7 @@ export class HarnessStreamTextResult<
276
285
  warnings: input.warnings.length > 0 ? input.warnings : undefined,
277
286
  request: {},
278
287
  response: {
279
- id: generateId(),
288
+ id: `${this.callId}-${this.stepNumber}`,
280
289
  timestamp: new Date(),
281
290
  modelId: this.modelId,
282
291
  messages: [],
@@ -363,7 +372,7 @@ export class HarnessStreamTextResult<
363
372
  this.stepsBuffer.length > 0
364
373
  ? this.stepsBuffer[this.stepsBuffer.length - 1]!
365
374
  : new DefaultStepResult<TOOLS, RUNTIME_CONTEXT>({
366
- callId: generateId(),
375
+ callId: this.callId,
367
376
  stepNumber: 0,
368
377
  provider: this.providerName,
369
378
  modelId: this.modelId,
@@ -377,7 +386,7 @@ export class HarnessStreamTextResult<
377
386
  warnings: undefined,
378
387
  request: {},
379
388
  response: {
380
- id: generateId(),
389
+ id: `${this.callId}-0`,
381
390
  timestamp: new Date(),
382
391
  modelId: this.modelId,
383
392
  messages: [],
@@ -823,6 +832,19 @@ export class HarnessStreamTextResult<
823
832
  }
824
833
  return;
825
834
  }
835
+ case 'reasoning-delta': {
836
+ const last =
837
+ this.currentStepContent[this.currentStepContent.length - 1];
838
+ if (last && last.type === 'reasoning') {
839
+ (last as { text: string }).text += part.text;
840
+ } else {
841
+ this.currentStepContent.push({
842
+ type: 'reasoning',
843
+ text: part.text,
844
+ } as ContentPart<TOOLS>);
845
+ }
846
+ return;
847
+ }
826
848
  case 'tool-call':
827
849
  case 'tool-approval-request':
828
850
  case 'tool-approval-response':
@@ -833,9 +855,7 @@ export class HarnessStreamTextResult<
833
855
  } as ContentPart<TOOLS>);
834
856
  return;
835
857
  default:
836
- // text-start/end, reasoning-*, raw, error, finish-step, finish are
837
- // not directly stored as ContentParts. (Reasoning content parts
838
- // would belong here; we omit them for v0.)
858
+ // Boundary, raw, error, and finish parts are not ContentParts.
839
859
  return;
840
860
  }
841
861
  }