@oh-my-pi/pi-agent-core 18.21.0 → 18.22.1

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/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [18.22.1] - 2026-11-17
6
+
7
+ ### Added
8
+
9
+ - A model on an extension's custom api can take the Anthropic on-demand compaction lane by declaring `remoteCompaction: { api: "anthropic-messages", enabled: true }`; the request goes through its own stream like any turn ([#19580](https://github.com/can1357/oh-my-pi/pull/19580) by [@ryanskidmore](https://github.com/ryanskidmore))
10
+
11
+ ### Fixed
12
+
13
+ - Fixed provider-error handling so failed tool calls are no longer fed back to the model as refusal explanations.
14
+ - Fixed one-shot retries and title generation for custom Zhipu Coding Plan providers so Beijing-time quota resets are honored.
15
+ - Fixed OpenAI remote compaction (V1 and V2) dropping configured headers of models.yml and extension-registered models, so header-authenticated gateways returned 401 ([#19579](https://github.com/can1357/oh-my-pi/pull/19579) by [@ryanskidmore](https://github.com/ryanskidmore))
16
+
5
17
  ## [18.20.1] - 2026-11-14
6
18
 
7
19
  ### Fixed
@@ -38,10 +38,10 @@ export interface AnthropicCompactionPreserveData {
38
38
  * provider routes requests, so a Foundry or `ANTHROPIC_BASE_URL` reroute of a
39
39
  * first-party model is excluded unless the route opted in with
40
40
  * `remoteCompaction.enabled`. Bedrock Converse models compact through a
41
- * Bedrock Runtime side request; their ordinary turns stay on Converse.
41
+ * Bedrock Runtime side request; their ordinary turns stay on Converse. A
42
+ * custom api qualifies through {@link declaresAnthropicCompaction}.
42
43
  */
43
- export declare function shouldUseAnthropicNativeCompaction(model: Model): model is Model<"anthropic-messages" | "bedrock-converse-stream">;
44
- type AnthropicNativeCompactionModel = Model<"anthropic-messages" | "bedrock-converse-stream">;
44
+ export declare function shouldUseAnthropicNativeCompaction(model: Model): boolean;
45
45
  export declare function getPreservedAnthropicCompactionData(preserveData: Record<string, unknown> | undefined): AnthropicCompactionPreserveData | undefined;
46
46
  /** Set or strip the Anthropic compaction slot; a new compaction never inherits a stale summary. */
47
47
  export declare function withAnthropicCompactionPreserveData(preserveData: Record<string, unknown> | undefined, compaction: AnthropicCompactionPreserveData | undefined): Record<string, unknown> | undefined;
@@ -86,5 +86,4 @@ export interface AnthropicNativeCompactionOptions extends Pick<SimpleStreamOptio
86
86
  * without a summary is a native failure, including tool use, refusals and
87
87
  * output limits; the configured method order can then choose a fallback.
88
88
  */
89
- export declare function requestAnthropicNativeCompaction(model: AnthropicNativeCompactionModel, apiKey: ApiKey, request: AnthropicNativeCompactionRequest, signal: AbortSignal | undefined, options: AnthropicNativeCompactionOptions): Promise<AnthropicNativeCompactionResponse>;
90
- export {};
89
+ export declare function requestAnthropicNativeCompaction(model: Model, apiKey: ApiKey, request: AnthropicNativeCompactionRequest, signal: AbortSignal | undefined, options: AnthropicNativeCompactionOptions): Promise<AnthropicNativeCompactionResponse>;
@@ -7,8 +7,9 @@ export interface BedrockCompactionRequest {
7
7
  /**
8
8
  * Shape a native compaction request for Amazon Bedrock's OpenAI routes
9
9
  * (`isBedrockOpenAIUrl`) the way stream dispatch shapes a normal Bedrock turn:
10
- * configured headers, transport fetch (proxy, CA, User-Agent, request
11
- * recording), then the provider's model and request hooks. The bundled
10
+ * transport fetch (proxy, CA, User-Agent, request recording), then the
11
+ * provider's model and request hooks, on a model whose configured headers
12
+ * the caller already resolved (`withResolvedHeaders`). The bundled
12
13
  * `bedrock-mantle` provider's hook fills in `{region}` and picks bearer or
13
14
  * SigV4 auth; without it compaction targets an unresolved host.
14
15
  *
@@ -1,5 +1,19 @@
1
1
  import type { AssistantMessage, Message } from "@oh-my-pi/pi-ai";
2
+ /**
3
+ * Model-facing text of a tool call the provider stream ended before it could run.
4
+ * The provider's error (`details.upstreamError`) stays in the session for the UI.
5
+ */
6
+ export declare const PROVIDER_ERROR_NOT_EXECUTED_TEXT = "Tool call was not executed because the provider stream ended with an error before the tool could run.";
2
7
  /** Detects API-level provider refusals that are terminal errors, not dialogue to replay. */
3
8
  export declare function isProviderRefusalMessage(message: AssistantMessage): boolean;
4
- /** Removes API-level provider refusals from live provider replay while preserving other messages. */
9
+ /**
10
+ * The provider replay form of one converted message, or `undefined` when it is
11
+ * not replayed. API-level refusals are dropped. A provider-error placeholder
12
+ * keeps its "not executed" fact but loses the provider's error text: replaying a
13
+ * refusal explanation ("…reverse engineering or duplicating model outputs…")
14
+ * feeds the classifier its own verdict and makes every later turn of the
15
+ * session likelier to be refused.
16
+ */
17
+ export declare function toProviderReplayMessage(message: Message): Message | undefined;
18
+ /** Applies {@link toProviderReplayMessage} to live provider replay. */
5
19
  export declare function filterProviderReplayMessages(messages: readonly Message[]): Message[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@oh-my-pi/pi-agent-core",
4
- "version": "18.21.0",
4
+ "version": "18.22.1",
5
5
  "description": "General-purpose agent with transport abstraction, state management, and attachment support",
6
6
  "homepage": "https://omp.sh",
7
7
  "author": {
@@ -38,16 +38,16 @@
38
38
  "fmt": "oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts'"
39
39
  },
40
40
  "dependencies": {
41
- "@oh-my-pi/pi-ai": "18.21.0",
42
- "@oh-my-pi/pi-catalog": "18.21.0",
43
- "@oh-my-pi/pi-natives": "18.21.0",
44
- "@oh-my-pi/pi-utils": "18.21.0",
45
- "@oh-my-pi/pi-wire": "18.21.0",
46
- "@oh-my-pi/snapcompact": "18.21.0",
41
+ "@oh-my-pi/pi-ai": "18.22.1",
42
+ "@oh-my-pi/pi-catalog": "18.22.1",
43
+ "@oh-my-pi/pi-natives": "18.22.1",
44
+ "@oh-my-pi/pi-utils": "18.22.1",
45
+ "@oh-my-pi/pi-wire": "18.22.1",
46
+ "@oh-my-pi/snapcompact": "18.22.1",
47
47
  "@opentelemetry/api": "^1.9.1"
48
48
  },
49
49
  "devDependencies": {
50
- "@oh-my-pi/omptype": "18.21.0",
50
+ "@oh-my-pi/omptype": "18.22.1",
51
51
  "@opentelemetry/context-async-hooks": "2.9.0",
52
52
  "@opentelemetry/sdk-trace-base": "2.9.0",
53
53
  "@types/bun": "^1.3.14"
package/src/agent.ts CHANGED
@@ -40,7 +40,7 @@ import {
40
40
  } from "./agent-loop";
41
41
  import type { AppendOnlyContextManager } from "./append-only-context";
42
42
  import { agentPauseGate } from "./pause";
43
- import { isProviderRefusalMessage } from "./replay-policy";
43
+ import { filterProviderReplayMessages } from "./replay-policy";
44
44
  import { SentToolDefinitions } from "./sent-tool-definitions";
45
45
  import { Tokenizer } from "./tokenizer";
46
46
  import {
@@ -75,10 +75,12 @@ import { isSoftToolRequirement } from "./types";
75
75
  * Default convertToLlm: Keep only LLM-compatible replay messages.
76
76
  */
77
77
  function defaultConvertToLlm(messages: AgentMessage[]): Message[] {
78
- return messages.filter((m): m is Message => {
79
- if (m.role === "assistant") return !isProviderRefusalMessage(m);
80
- return m.role === "user" || m.role === "developer" || m.role === "toolResult";
81
- });
78
+ return filterProviderReplayMessages(
79
+ messages.filter(
80
+ (m): m is Message =>
81
+ m.role === "assistant" || m.role === "user" || m.role === "developer" || m.role === "toolResult",
82
+ ),
83
+ );
82
84
  }
83
85
 
84
86
  function refreshToolChoiceForActiveTools(
@@ -17,8 +17,10 @@ import type {
17
17
  SimpleStreamOptions,
18
18
  Usage,
19
19
  } from "@oh-my-pi/pi-ai";
20
+ import { isBuiltinApi } from "@oh-my-pi/pi-ai/api-registry";
20
21
  import * as AIError from "@oh-my-pi/pi-ai/error";
21
22
  import {
23
+ declaresAnthropicCompactionEndpoint,
22
24
  supportsAnthropicCompaction,
23
25
  supportsBedrockConverseCompaction,
24
26
  } from "@oh-my-pi/pi-ai/providers/anthropic-compaction";
@@ -59,6 +61,22 @@ function isBedrockConverseModel(model: Model): model is Model<"bedrock-converse-
59
61
  return model.api === "bedrock-converse-stream";
60
62
  }
61
63
 
64
+ /**
65
+ * Whether a custom api (an extension's `registerProvider` stream, never a
66
+ * built-in adapter) declares that it dispatches its model to Anthropic
67
+ * Messages with an endpoint that serves on-demand compaction
68
+ * (`declaresAnthropicCompactionEndpoint`). The request goes through the
69
+ * model's own api like any turn, so the custom stream shapes and
70
+ * authenticates it, and the Anthropic provider it delegates to still applies
71
+ * its own model and endpoint policy. The stream receives the caller's
72
+ * `reasoning` as is: it resolves the effort earlier controls left in force
73
+ * (`resolveAnthropicCompactionEffort`) on the Anthropic model it delegates to,
74
+ * which the agent never sees.
75
+ */
76
+ function declaresAnthropicCompaction(model: Model): boolean {
77
+ return !isBuiltinApi(model.api) && declaresAnthropicCompactionEndpoint(model);
78
+ }
79
+
62
80
  /**
63
81
  * Whether a model compacts through the Anthropic compaction beta. Model
64
82
  * eligibility is catalog policy (`compat.supportsServerCompaction`, the
@@ -66,17 +84,15 @@ function isBedrockConverseModel(model: Model): model is Model<"bedrock-converse-
66
84
  * provider routes requests, so a Foundry or `ANTHROPIC_BASE_URL` reroute of a
67
85
  * first-party model is excluded unless the route opted in with
68
86
  * `remoteCompaction.enabled`. Bedrock Converse models compact through a
69
- * Bedrock Runtime side request; their ordinary turns stay on Converse.
87
+ * Bedrock Runtime side request; their ordinary turns stay on Converse. A
88
+ * custom api qualifies through {@link declaresAnthropicCompaction}.
70
89
  */
71
- export function shouldUseAnthropicNativeCompaction(
72
- model: Model,
73
- ): model is Model<"anthropic-messages" | "bedrock-converse-stream"> {
90
+ export function shouldUseAnthropicNativeCompaction(model: Model): boolean {
74
91
  if (isAnthropicMessagesModel(model)) return supportsAnthropicCompaction(model);
75
- return isBedrockConverseModel(model) && supportsBedrockConverseCompaction(model);
92
+ if (isBedrockConverseModel(model)) return supportsBedrockConverseCompaction(model);
93
+ return declaresAnthropicCompaction(model);
76
94
  }
77
95
 
78
- type AnthropicNativeCompactionModel = Model<"anthropic-messages" | "bedrock-converse-stream">;
79
-
80
96
  export function getPreservedAnthropicCompactionData(
81
97
  preserveData: Record<string, unknown> | undefined,
82
98
  ): AnthropicCompactionPreserveData | undefined {
@@ -244,7 +260,7 @@ export interface AnthropicNativeCompactionOptions
244
260
  * output limits; the configured method order can then choose a fallback.
245
261
  */
246
262
  export async function requestAnthropicNativeCompaction(
247
- model: AnthropicNativeCompactionModel,
263
+ model: Model,
248
264
  apiKey: ApiKey,
249
265
  request: AnthropicNativeCompactionRequest,
250
266
  signal: AbortSignal | undefined,
@@ -1,7 +1,6 @@
1
1
  import { getProviderDefinition } from "@oh-my-pi/pi-ai/registry";
2
2
  import type { FetchImpl, Model } from "@oh-my-pi/pi-ai/types";
3
3
  import { transportFetch } from "@oh-my-pi/pi-ai/utils/transport-fetch";
4
- import { untilAborted } from "@oh-my-pi/pi-utils";
5
4
 
6
5
  export interface BedrockCompactionRequest {
7
6
  model: Model;
@@ -12,8 +11,9 @@ export interface BedrockCompactionRequest {
12
11
  /**
13
12
  * Shape a native compaction request for Amazon Bedrock's OpenAI routes
14
13
  * (`isBedrockOpenAIUrl`) the way stream dispatch shapes a normal Bedrock turn:
15
- * configured headers, transport fetch (proxy, CA, User-Agent, request
16
- * recording), then the provider's model and request hooks. The bundled
14
+ * transport fetch (proxy, CA, User-Agent, request recording), then the
15
+ * provider's model and request hooks, on a model whose configured headers
16
+ * the caller already resolved (`withResolvedHeaders`). The bundled
17
17
  * `bedrock-mantle` provider's hook fills in `{region}` and picks bearer or
18
18
  * SigV4 auth; without it compaction targets an unresolved host.
19
19
  *
@@ -26,16 +26,9 @@ export async function prepareBedrockCompactionRequest(
26
26
  fetch: FetchImpl | undefined,
27
27
  signal: AbortSignal | undefined,
28
28
  ): Promise<BedrockCompactionRequest> {
29
- let resolvedModel = model;
30
- const resolveHeaders = model.resolveHeaders;
31
- if (resolveHeaders) {
32
- const headers = await untilAborted(signal, () => resolveHeaders(signal));
33
- signal?.throwIfAborted();
34
- resolvedModel = { ...model, resolveHeaders: undefined, headers: headers ? { ...headers } : undefined };
35
- }
36
- const baseFetch = transportFetch(resolvedModel, fetch);
37
- const provider = getProviderDefinition(resolvedModel.provider);
38
- const providerModel = provider?.prepareModel?.(resolvedModel) ?? resolvedModel;
29
+ const baseFetch = transportFetch(model, fetch);
30
+ const provider = getProviderDefinition(model.provider);
31
+ const providerModel = provider?.prepareModel?.(model) ?? model;
39
32
  const prepared = provider?.prepareRequest?.(providerModel, { apiKey, fetch: baseFetch, signal }) ?? {
40
33
  model: providerModel,
41
34
  options: { apiKey, fetch: baseFetch },
@@ -10,7 +10,11 @@
10
10
  import type { Api, CodexCompactionContext, FetchImpl, Model, ProviderSessionState } from "@oh-my-pi/pi-ai";
11
11
  import * as AIError from "@oh-my-pi/pi-ai/error";
12
12
  import { createOpenAICodexCompactionRequestContext } from "@oh-my-pi/pi-ai/providers/openai-codex-compaction";
13
- import { applyCodexResponsesLiteShape } from "@oh-my-pi/pi-ai/providers/openai-codex/request-transformer";
13
+ import {
14
+ applyCodexResponsesLiteShape,
15
+ moveCodexInstructionsToInput,
16
+ withCodexRoutingFieldsFirst,
17
+ } from "@oh-my-pi/pi-ai/providers/openai-codex/request-transformer";
14
18
  import type {
15
19
  OpenAICodexCompactionBody,
16
20
  OpenAICodexCompatibilityMetadata,
@@ -22,6 +26,7 @@ import {
22
26
  resolveOpenAIRequestSetup,
23
27
  } from "@oh-my-pi/pi-ai/providers/openai-shared";
24
28
  import { captureOpenAIHttpError } from "@oh-my-pi/pi-ai/utils/openai-http";
29
+ import { withResolvedHeaders } from "@oh-my-pi/pi-ai/utils/model-headers";
25
30
  import type { CatalogPolicyInputs } from "@oh-my-pi/pi-catalog/types";
26
31
  import { isBedrockOpenAIUrl } from "@oh-my-pi/pi-catalog/hosts";
27
32
  import {
@@ -231,6 +236,8 @@ export function buildCompactionV2Request(
231
236
  };
232
237
  if (model.useResponsesLite) {
233
238
  applyCodexResponsesLiteShape(body);
239
+ } else {
240
+ moveCodexInstructionsToInput(body);
234
241
  }
235
242
  return buildCompactionV2RequestFromBody(model, body, options);
236
243
  }
@@ -277,6 +284,7 @@ export async function requestCompactionV2Streaming(
277
284
  codexAccessPrograms?: boolean;
278
285
  },
279
286
  ): Promise<CompactionV2Response> {
287
+ model = await withResolvedHeaders(model, signal);
280
288
  let fetchImpl: FetchImpl = options?.fetch ?? globalThis.fetch;
281
289
  if (isBedrockOpenAIUrl(model.baseUrl)) {
282
290
  ({
@@ -393,7 +401,7 @@ async function attemptCompactionV2Streaming(
393
401
  const response = await fetchImpl(endpoint, {
394
402
  method: "POST",
395
403
  headers: buildCompactionV2Headers(model, apiKey, request, options.codexMetadata),
396
- body: stringifyJson(body),
404
+ body: stringifyJson(withCodexRoutingFieldsFirst(body)),
397
405
  signal,
398
406
  });
399
407
 
@@ -18,7 +18,11 @@
18
18
  import { attach, create, Flag, ProviderHttpError } from "@oh-my-pi/pi-ai/error";
19
19
  import { getCodexAttestationHeader } from "@oh-my-pi/pi-ai/providers/openai-codex-attestation";
20
20
  import { createOpenAICodexCompactionRequestContext } from "@oh-my-pi/pi-ai/providers/openai-codex-compaction";
21
- import { applyCodexResponsesLiteShape } from "@oh-my-pi/pi-ai/providers/openai-codex/request-transformer";
21
+ import {
22
+ applyCodexResponsesLiteShape,
23
+ moveCodexInstructionsToInput,
24
+ withCodexRoutingFieldsFirst,
25
+ } from "@oh-my-pi/pi-ai/providers/openai-codex/request-transformer";
22
26
  import {
23
27
  applyInferenceHeaders,
24
28
  applySessionHeader,
@@ -51,6 +55,7 @@ import {
51
55
  truncateResponseItemId,
52
56
  } from "@oh-my-pi/pi-ai/utils";
53
57
  import { captureOpenAIHttpError } from "@oh-my-pi/pi-ai/utils/openai-http";
58
+ import { withResolvedHeaders } from "@oh-my-pi/pi-ai/utils/model-headers";
54
59
  import { isBedrockOpenAIUrl } from "@oh-my-pi/pi-catalog/hosts";
55
60
  import {
56
61
  applyCodexResidencyHeader,
@@ -60,16 +65,7 @@ import {
60
65
  OPENAI_HEADER_VALUES,
61
66
  OPENAI_HEADERS,
62
67
  } from "@oh-my-pi/pi-catalog/wire/codex";
63
- import {
64
- $env,
65
- isRecord,
66
- logger,
67
- prompt,
68
- ptree,
69
- stringifyJson,
70
- structuredCloneJSON,
71
- untilAborted,
72
- } from "@oh-my-pi/pi-utils";
68
+ import { $env, isRecord, logger, prompt, ptree, stringifyJson, structuredCloneJSON } from "@oh-my-pi/pi-utils";
73
69
  import { dataUrlImageSize } from "../image-tokens";
74
70
  import { Tokenizer } from "../tokenizer";
75
71
  import { appendAzureApiVersion, resolveAzureOpenAiBaseUrl } from "./azure-openai-endpoint";
@@ -889,6 +885,7 @@ export async function requestOpenAiRemoteCompaction(
889
885
  rewriteOutputs?: boolean;
890
886
  },
891
887
  ): Promise<OpenAiRemoteCompactionResponse> {
888
+ model = await withResolvedHeaders(model, signal);
892
889
  let fetchImpl: FetchImpl = opts?.fetch ?? fetch;
893
890
  if (isBedrockOpenAIUrl(model.baseUrl)) {
894
891
  ({ model, apiKey, fetch: fetchImpl } = await prepareBedrockCompactionRequest(model, apiKey, opts?.fetch, signal));
@@ -991,9 +988,10 @@ export async function requestOpenAiRemoteCompaction(
991
988
  includeInstallationHeader: true,
992
989
  }).headers,
993
990
  );
994
- // Responses Lite models take the same rewrite on `/responses/compact`:
995
- // instructions ride as an input item and the lite marker header is set
996
- // (codex-rs routes compaction through `build_responses_request`).
991
+ // codex-rs routes `/responses/compact` through `build_responses_request`:
992
+ // instructions always ride as a leading input item, and Responses Lite
993
+ // models additionally take the Lite rewrite and marker header.
994
+ moveCodexInstructionsToInput(request);
997
995
  if (model.useResponsesLite) {
998
996
  applyCodexResponsesLiteShape(request);
999
997
  headers[OPENAI_HEADERS.RESPONSES_LITE] = "true";
@@ -1008,7 +1006,7 @@ export async function requestOpenAiRemoteCompaction(
1008
1006
  const response = await fetchImpl(endpoint, {
1009
1007
  method: "POST",
1010
1008
  headers,
1011
- body: stringifyJson(request),
1009
+ body: stringifyJson(isCodexResponses ? withCodexRoutingFieldsFirst(request) : request),
1012
1010
  signal: ptree.combineSignals(signal, opts?.timeoutMs ?? REMOTE_COMPACTION_TIMEOUT_MS),
1013
1011
  });
1014
1012
 
@@ -1098,11 +1096,7 @@ export async function requestRemoteCompaction(
1098
1096
  if (isChatCompletions) {
1099
1097
  if (opts?.apiKey) headers.set("Authorization", `Bearer ${opts.apiKey}`);
1100
1098
  const model = opts?.model;
1101
- const resolveHeaders = model?.resolveHeaders;
1102
- const configuredHeaders = resolveHeaders
1103
- ? await untilAborted(signal, () => resolveHeaders(signal))
1104
- : model?.headers;
1105
- signal?.throwIfAborted();
1099
+ const configuredHeaders = model ? (await withResolvedHeaders(model, signal)).headers : undefined;
1106
1100
  // `set` replaces case-insensitively, so a configured `authorization` overrides the default bearer.
1107
1101
  if (configuredHeaders) {
1108
1102
  for (const name in configuredHeaders) headers.set(name, configuredHeaders[name]!);
@@ -1,4 +1,11 @@
1
- import type { AssistantMessage, Message } from "@oh-my-pi/pi-ai";
1
+ import type { AssistantMessage, Message, ToolResultMessage } from "@oh-my-pi/pi-ai";
2
+
3
+ /**
4
+ * Model-facing text of a tool call the provider stream ended before it could run.
5
+ * The provider's error (`details.upstreamError`) stays in the session for the UI.
6
+ */
7
+ export const PROVIDER_ERROR_NOT_EXECUTED_TEXT =
8
+ "Tool call was not executed because the provider stream ended with an error before the tool could run.";
2
9
 
3
10
  /** Detects API-level provider refusals that are terminal errors, not dialogue to replay. */
4
11
  export function isProviderRefusalMessage(message: AssistantMessage): boolean {
@@ -7,7 +14,35 @@ export function isProviderRefusalMessage(message: AssistantMessage): boolean {
7
14
  return stopType === "refusal" || stopType === "sensitive";
8
15
  }
9
16
 
10
- /** Removes API-level provider refusals from live provider replay while preserving other messages. */
17
+ /**
18
+ * Detects the placeholder result agent-loop persists for a tool call whose
19
+ * assistant turn ended on a provider error (`source: "assistant_stop_error"`).
20
+ */
21
+ function isProviderErrorPlaceholder(message: ToolResultMessage): boolean {
22
+ const details = message.details as { __synthetic?: unknown; source?: unknown } | undefined;
23
+ return details?.__synthetic === true && details.source === "assistant_stop_error";
24
+ }
25
+
26
+ /**
27
+ * The provider replay form of one converted message, or `undefined` when it is
28
+ * not replayed. API-level refusals are dropped. A provider-error placeholder
29
+ * keeps its "not executed" fact but loses the provider's error text: replaying a
30
+ * refusal explanation ("…reverse engineering or duplicating model outputs…")
31
+ * feeds the classifier its own verdict and makes every later turn of the
32
+ * session likelier to be refused.
33
+ */
34
+ export function toProviderReplayMessage(message: Message): Message | undefined {
35
+ if (message.role === "assistant") return isProviderRefusalMessage(message) ? undefined : message;
36
+ if (message.role !== "toolResult" || !isProviderErrorPlaceholder(message)) return message;
37
+ return { ...message, content: [{ type: "text", text: PROVIDER_ERROR_NOT_EXECUTED_TEXT }] };
38
+ }
39
+
40
+ /** Applies {@link toProviderReplayMessage} to live provider replay. */
11
41
  export function filterProviderReplayMessages(messages: readonly Message[]): Message[] {
12
- return messages.filter(message => message.role !== "assistant" || !isProviderRefusalMessage(message));
42
+ const replayed: Message[] = [];
43
+ for (const message of messages) {
44
+ const replay = toProviderReplayMessage(message);
45
+ if (replay) replayed.push(replay);
46
+ }
47
+ return replayed;
13
48
  }
package/src/telemetry.ts CHANGED
@@ -1892,6 +1892,7 @@ export async function instrumentedCompleteSimple<TApi extends Api>(
1892
1892
  ? await retryTransientCompletion(runOnce, {
1893
1893
  ...span.retry,
1894
1894
  provider: model.provider,
1895
+ baseUrl: model.baseUrl,
1895
1896
  // Framework-owned: the caller must not be able to detach the
1896
1897
  // abort signal or the header source by passing them itself.
1897
1898
  signal: options.signal,