@clearideas/agent-runtime-model-ai-sdk 0.6.0 → 0.6.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 CHANGED
@@ -29,3 +29,14 @@ functions in `createProviderRegistryModelResolver`.
29
29
  The adapter supports generation, text and reasoning deltas, structured object
30
30
  output, tool-call conversion, usage, provider metadata, and abort signals.
31
31
  Agent Runtime executes tool calls sequentially.
32
+
33
+ Anthropic 4.0.72 and newer emit an `anthropic.message_start` custom part with
34
+ stream metadata. The adapter omits this metadata-only part from replayable
35
+ assistant content while preserving ordinary content, token usage, and provider
36
+ options. Older provider versions that do not emit this part remain supported.
37
+
38
+ Other custom parts remain unsupported and raise an error. In particular,
39
+ Anthropic server-side fallback blocks carry replay semantics and are not
40
+ silently discarded. Replaying those blocks requires an extension to the
41
+ runtime's content contracts; this compatibility fix does not enable that
42
+ feature.
@@ -27,7 +27,12 @@ const defaultGenerateText = async (options) => {
27
27
  return result;
28
28
  };
29
29
  const defaultStreamText = (options) => {
30
- const result = streamText(options);
30
+ const result = streamText({
31
+ ...options,
32
+ // The adapter propagates fullStream error parts to the runtime. Disable
33
+ // the SDK's default console.error handler to avoid duplicate stderr output.
34
+ onError: () => { },
35
+ });
31
36
  return result;
32
37
  };
33
38
  const combinedProviderOptions = (message) => {
@@ -126,7 +131,11 @@ export class AiSdkModelAdapter {
126
131
  break;
127
132
  }
128
133
  }
129
- const structuredOutput = request.outputSchema == null ? undefined : await result.output;
134
+ // A turn that calls tools is not the step's final answer, so there is no
135
+ // structured output to read yet; only the final turn is parsed.
136
+ const structuredOutput = request.outputSchema == null || toolCalls.length > 0
137
+ ? undefined
138
+ : await result.output;
130
139
  const responseMessages = result.responseMessages == null
131
140
  ? undefined
132
141
  : await result.responseMessages;
@@ -191,16 +200,20 @@ export class AiSdkModelAdapter {
191
200
  return options;
192
201
  }
193
202
  #toModelResult(request, result) {
203
+ const toolCalls = result.toolCalls.map(toToolCall);
194
204
  return this.#buildModelResult({
195
205
  request,
196
206
  text: result.text,
197
207
  reasoning: result.reasoningText ?? "",
198
- toolCalls: result.toolCalls.map(toToolCall),
208
+ toolCalls,
199
209
  finishReason: result.finishReason,
200
210
  usage: result.totalUsage,
201
211
  providerMetadata: result.providerMetadata,
202
212
  responseMessages: result.responseMessages,
203
- structuredOutput: request.outputSchema == null ? undefined : result.output,
213
+ // Reading `output` on a tool-call turn throws (there is no final answer).
214
+ structuredOutput: request.outputSchema == null || toolCalls.length > 0
215
+ ? undefined
216
+ : result.output,
204
217
  });
205
218
  }
206
219
  #buildModelResult(input) {
@@ -284,6 +297,17 @@ const mediaType = (part) => {
284
297
  }
285
298
  return value;
286
299
  };
300
+ /**
301
+ * Tool-result files accept only tagged file data in AI SDK 7. step-prompt
302
+ * resolves stored artifacts to base64 data: URLs, which are sent as inline
303
+ * bytes; any other URI is sent as a URL.
304
+ */
305
+ const toolResultFileData = (uri) => {
306
+ const inline = /^data:[^,]*;base64,(.*)$/su.exec(uri);
307
+ return inline
308
+ ? { type: "data", data: inline[1] }
309
+ : { type: "url", url: new URL(uri) };
310
+ };
287
311
  const toAiSdkToolResultPart = (part) => {
288
312
  const result = part.result;
289
313
  let output;
@@ -303,7 +327,7 @@ const toAiSdkToolResultPart = (part) => {
303
327
  }
304
328
  value.push({
305
329
  type: "file",
306
- data: new URL(artifact.uri),
330
+ data: toolResultFileData(artifact.uri),
307
331
  mediaType: artifact.mediaType,
308
332
  filename: artifact.name,
309
333
  });
@@ -551,7 +575,15 @@ function fromAiSdkResponseMessage(message, id, createdAt, model) {
551
575
  const rawContent = typeof message.content === "string"
552
576
  ? [{ type: "text", text: message.content }]
553
577
  : message.content;
554
- const content = rawContent.map((rawPart) => {
578
+ // Anthropic's message-start part carries bookkeeping, not replay content.
579
+ // Other custom parts can carry semantics such as fallback boundaries.
580
+ const replayContent = rawContent.filter((rawPart) => {
581
+ const part = rawPart;
582
+ return !(message.role === "assistant" &&
583
+ part.type === "custom" &&
584
+ part.kind === "anthropic.message_start");
585
+ });
586
+ const content = replayContent.map((rawPart) => {
555
587
  const part = rawPart;
556
588
  switch (part.type) {
557
589
  case "text":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clearideas/agent-runtime-model-ai-sdk",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "AI SDK model adapter for the vendor-neutral Clear Ideas Agent Runtime.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Clear Ideas Incorporated",
@@ -36,8 +36,8 @@
36
36
  "postpack": "node ../../scripts/cleanup-package-license.mjs"
37
37
  },
38
38
  "dependencies": {
39
- "@clearideas/agent-runtime-contracts": "0.6.0",
40
- "@clearideas/agent-runtime-core": "0.6.0",
39
+ "@clearideas/agent-runtime-contracts": "0.6.2",
40
+ "@clearideas/agent-runtime-core": "0.6.2",
41
41
  "ai": "^7.0.98"
42
42
  },
43
43
  "devDependencies": {