@bastani/pi-ai 0.9.74 → 0.9.75-alpha.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.
Files changed (82) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +3 -1
  3. package/dist/api/anthropic-messages.d.ts.map +1 -1
  4. package/dist/api/anthropic-messages.js +21 -7
  5. package/dist/api/anthropic-messages.js.map +1 -1
  6. package/dist/api/bedrock-converse-stream.d.ts.map +1 -1
  7. package/dist/api/bedrock-converse-stream.js +4 -2
  8. package/dist/api/bedrock-converse-stream.js.map +1 -1
  9. package/dist/api/constrained-sampling.d.ts +0 -2
  10. package/dist/api/constrained-sampling.d.ts.map +1 -1
  11. package/dist/api/constrained-sampling.js +0 -13
  12. package/dist/api/constrained-sampling.js.map +1 -1
  13. package/dist/api/openai-completions.d.ts.map +1 -1
  14. package/dist/api/openai-completions.js +9 -5
  15. package/dist/api/openai-completions.js.map +1 -1
  16. package/dist/api/openai-images-options.d.ts +18 -5
  17. package/dist/api/openai-images-options.d.ts.map +1 -1
  18. package/dist/api/openai-images-options.js +9 -3
  19. package/dist/api/openai-images-options.js.map +1 -1
  20. package/dist/api/openai-images.d.ts.map +1 -1
  21. package/dist/api/openai-images.js +121 -19
  22. package/dist/api/openai-images.js.map +1 -1
  23. package/dist/api/openai-responses.d.ts.map +1 -1
  24. package/dist/api/openai-responses.js +10 -3
  25. package/dist/api/openai-responses.js.map +1 -1
  26. package/dist/api/strict-tool-limits.d.ts +13 -0
  27. package/dist/api/strict-tool-limits.d.ts.map +1 -0
  28. package/dist/api/strict-tool-limits.js +50 -0
  29. package/dist/api/strict-tool-limits.js.map +1 -0
  30. package/dist/auth/types.d.ts +7 -0
  31. package/dist/auth/types.d.ts.map +1 -1
  32. package/dist/auth/types.js.map +1 -1
  33. package/dist/cache-warming.d.ts +53 -0
  34. package/dist/cache-warming.d.ts.map +1 -0
  35. package/dist/cache-warming.js +82 -0
  36. package/dist/cache-warming.js.map +1 -0
  37. package/dist/image-generation-error.d.ts +10 -3
  38. package/dist/image-generation-error.d.ts.map +1 -1
  39. package/dist/image-generation-error.js +3 -2
  40. package/dist/image-generation-error.js.map +1 -1
  41. package/dist/index.d.ts +3 -1
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +3 -1
  44. package/dist/index.js.map +1 -1
  45. package/dist/models.d.ts +15 -6
  46. package/dist/models.d.ts.map +1 -1
  47. package/dist/models.js +22 -7
  48. package/dist/models.js.map +1 -1
  49. package/dist/providers/data/.manifest.json +1 -1
  50. package/dist/providers/data/amazon-bedrock.json +1 -1
  51. package/dist/providers/data/anthropic.json +1 -1
  52. package/dist/providers/data/azure.json +1 -1
  53. package/dist/providers/data/google.json +1 -1
  54. package/dist/providers/data/meta.json +1 -1
  55. package/dist/providers/data/opencode-go.json +1 -1
  56. package/dist/providers/data/opencode.json +1 -1
  57. package/dist/providers/data/openrouter.json +1 -1
  58. package/dist/providers/data/vercel-ai-gateway.json +1 -1
  59. package/dist/providers/github-copilot-errors.d.ts +17 -5
  60. package/dist/providers/github-copilot-errors.d.ts.map +1 -1
  61. package/dist/providers/github-copilot-errors.js +55 -11
  62. package/dist/providers/github-copilot-errors.js.map +1 -1
  63. package/dist/providers/github-copilot-stream-attempt.d.ts +27 -0
  64. package/dist/providers/github-copilot-stream-attempt.d.ts.map +1 -0
  65. package/dist/providers/github-copilot-stream-attempt.js +45 -0
  66. package/dist/providers/github-copilot-stream-attempt.js.map +1 -0
  67. package/dist/providers/github-copilot.d.ts +10 -2
  68. package/dist/providers/github-copilot.d.ts.map +1 -1
  69. package/dist/providers/github-copilot.js +62 -36
  70. package/dist/providers/github-copilot.js.map +1 -1
  71. package/dist/types.d.ts +2 -0
  72. package/dist/types.d.ts.map +1 -1
  73. package/dist/types.js.map +1 -1
  74. package/dist/utils/stream-deadline.d.ts +6 -2
  75. package/dist/utils/stream-deadline.d.ts.map +1 -1
  76. package/dist/utils/stream-deadline.js +12 -3
  77. package/dist/utils/stream-deadline.js.map +1 -1
  78. package/dist/utils/version.d.ts +1 -1
  79. package/dist/utils/version.d.ts.map +1 -1
  80. package/dist/utils/version.js +1 -1
  81. package/dist/utils/version.js.map +1 -1
  82. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -4,6 +4,24 @@ This package is a Bastani fork of `@earendil-works/pi-ai`. Upstream history at t
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.9.75-alpha.1] - 2026-11-10
8
+
9
+ ### Added
10
+
11
+ - Added the prompt cache warming policy as shared helpers, so every host that warms a prompt cache decides the same way: `getPromptCacheTtlMs()` (the lifetime of the entry a request writes, from the model's `promptCache` tier for the request's `cacheRetention`, then `PI_CACHE_RETENTION`, defaulting to `short`), `getCacheWarmingDelayMs()`, `isCacheWarmingReplayable()`, `getCacheWarmingRequestOptions()`, `evaluateCacheWarming()`, the `CACHE_WARMING_*` constants and the `CacheWarmingAction`, `CacheWarmingPhase` and `CacheWarmingDecision` types. They moved from the coding agent's cache warmer, which keeps resolving the model-specific default retention before it asks for the lifetime (upstream [#11857](https://github.com/earendil-works/pi/pull/11857))
12
+ - Added Claude Fable 5.2 (`claude-fable-5-2`) to the `anthropic` provider ($8/$40 per million input/output tokens, 1M context, 128K output). Like Fable 5.1 it uses per-message effort and mid-conversation system messages; requests its safety classifiers refuse before any output are answered by Claude Opus 5 through server-side fallback and billed at Opus 5's price. Claude Fable 5.2 and Mythos 5.2 on other providers, such as OpenRouter's `anthropic/claude-fable-5.2`, get the same per-message effort support
13
+ - Added `GitHubCopilotStreamAttempt`, which records the request ID, duration and progress of one Copilot streaming request, and its `GitHubCopilotStreamSnapshot` result type, which `classifyGitHubCopilotFailure()` takes as `stream` ([#4626](https://github.com/bastani-inc/atomic/issues/4626))
14
+
15
+ ### Fixed
16
+
17
+ - GitHub Copilot now filters a stored API key by its account's model list as it does an OAuth login. `ApiKeyCredential` gains the optional `availableModelIds` and `fastModelIds` that a model refresh saves from the account's list, `RefreshModelsContext.updateCredential` is offered for a stored API key too and now takes and returns a `Credential` (it writes only while the store still holds the key or token the refresh used), and `refreshGitHubCopilotAccountModelLists()` renews just those lists for a provider alias. Nothing is hidden for a key whose list was not read or names no usable model ([#4627](https://github.com/bastani-inc/atomic/issues/4627))
18
+ - Catalog providers can set `Provider.refreshModelsAuth: "configured"` to refresh without renewing OAuth or receiving a provider credential, while still skipping unconfigured providers. Stale logins no longer block credential-free catalogs ([#4610](https://github.com/bastani-inc/atomic/issues/4610))
19
+ - Azure OpenAI models now keep OpenAI's long-context price tier, so requests above 272K input tokens are costed at Azure's long-context rates instead of the standard rates (upstream [#11948](https://github.com/earendil-works/pi/issues/11948))
20
+ - Fixed Anthropic and Bedrock sending `strict: "prefer"` tools strict again on every request after Claude rejected them for exceeding its strict tool limits, which cost a rejected request (400) per turn. Later requests with the same `sessionId` now send those tools non-strict right away, until `cleanupSessionResources(sessionId)` (upstream [#11626](https://github.com/earendil-works/pi/issues/11626))
21
+ - Fixed `outputFormat: "svg"` on GPT Image 2.6 failing with a generic `api-error` (HTTP 400, `missing_required_parameter` for `svg.model`) on accounts where the API requires the SVG authoring model. A request without `svg` now retries once with a default authoring model, `DEFAULT_SVG_AUTHOR_MODEL` (`gpt-6.1-sol`, a value that worked in testing: OpenAI documents no default), and retries once more without `svg` if the API rejects it as unsupported, so a call sends at most three requests. An `svg` you pass is always sent as given and never retried or replaced. `AssistantImages.svgModel` reports the model that wrote the SVG. A rejected `svg` or `svg.model` now fails with `ImageGenerationConfigError` (`code: "invalid-option"`, `field` `svg.model` or `svg`, and the new `reason` values `required-by-api`, `rejected-by-api` and `unsupported-by-api`) instead of `api-error`. Image requests pass their 10-minute default timeout to the SDK explicitly, so SVG authoring that takes tens of seconds never times out early ([#4615](https://github.com/bastani-inc/atomic/issues/4615))
22
+ - Fixed GitHub Copilot `stream-ended-early` failures giving almost nothing to diagnose them with. `GitHubCopilotStreamEndedEarlyError` now carries `durationMs` (how long the attempt ran) and `startedContent` (whether any stream event had arrived), and takes its `requestId` from the response's `x-request-id`, on Anthropic Messages, Chat Completions and Responses streams. The fields appear in `fields()`, survive serialization, and show in the message (`Attempt ran 312.4 s, response started, request ID …`). The hint no longer says Atomic retries "when retries are enabled", which was wrong once the retries were used up; it now suggests splitting the work, lowering the thinking effort or adding a fallback model. `GitHubCopilotFailureContext.streamStarted` is replaced by `stream`, and `recordGitHubCopilotFailure()` takes a `GitHubCopilotStreamSnapshot` (or `undefined` when no response arrived) instead of a boolean. `GitHubCopilotErrorFieldValue` now includes `boolean` ([#4626](https://github.com/bastani-inc/atomic/issues/4626))
23
+ - Fixed Anthropic `ping` events not counting as activity for the stream idle deadline (`streamDeadlineMs`), so a model thinking silently while the server kept the connection alive was cut at the deadline as if the stream had stalled. `withStreamDeadline()` takes an optional keep-alive predicate: a match restarts the idle timer and is not yielded, so pings never reach `onProviderStreamEvent` ([#4626](https://github.com/bastani-inc/atomic/issues/4626))
24
+
7
25
  ## [0.9.72] - 2026-11-08
8
26
 
9
27
  GPT Image 2.6, typed Copilot failures, and thinking `off` that every provider honors.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @bastani/pi-ai
2
2
 
3
- Bastani-branded fork of [`@earendil-works/pi-ai`](https://www.npmjs.com/package/@earendil-works/pi-ai) from [earendil-works/pi](https://github.com/earendil-works/pi). Originally forked at **v0.84.2** (`914cf1472e715297caa30db4b9535d534a9eb718`); applicable upstream Pi AI fixes and the unified model catalog are synced through [`085c84e98e7f4c950f2be606466fff4f75d8fe7c`](https://github.com/earendil-works/pi/commit/085c84e98e7f4c950f2be606466fff4f75d8fe7c). `@bastani/pi-ai` publishes at the same version as Atomic. `npm run build` refreshes the models.dev catalog, same as upstream.
3
+ Bastani-branded fork of [`@earendil-works/pi-ai`](https://www.npmjs.com/package/@earendil-works/pi-ai) from [earendil-works/pi](https://github.com/earendil-works/pi). Originally forked at **v0.84.2** (`914cf1472e715297caa30db4b9535d534a9eb718`); applicable upstream Pi AI fixes and the unified model catalog are synced through [`4ea8837927564c592b1d184c956ab7d28c88119b`](https://github.com/earendil-works/pi/commit/4ea8837927564c592b1d184c956ab7d28c88119b). `@bastani/pi-ai` publishes at the same version as Atomic. `npm run build` refreshes the models.dev catalog, same as upstream.
4
4
 
5
5
  The public API is a drop-in replacement: install `@bastani/pi-ai` and import from `@bastani/pi-ai` instead of `@earendil-works/pi-ai`. See [NOTICE.md](NOTICE.md). This package lives in the Atomic monorepo and publishes from `.github/workflows/publish.yml`. The first npm version must be published by hand so trusted publishing can be attached.
6
6
 
@@ -1432,6 +1432,8 @@ for (const [provider, error] of result.errors) console.error(provider, error);
1432
1432
 
1433
1433
  Use `models.refresh({ providers: ['openrouter'] })` to restrict work to selected providers, `models.refresh({ allowNetwork: false })` to restore persisted catalogs without network access, or `models.refresh({ force: true })` to bypass provider freshness checks. Model reads stay synchronous and return the last restored or refreshed list.
1434
1434
 
1435
+ Handwritten providers whose catalog source needs no provider credential can set `Provider.refreshModelsAuth` to `"configured"`. The network refresh still skips unconfigured providers, but does not refresh OAuth and receives `context.credential === undefined`. The default, `"credential"`, resolves the effective credential and refreshes expired OAuth before fetching models. Keep that default for account-specific catalogs and hooks that read `context.credential`.
1436
+
1435
1437
  `createProvider()` handles dynamic publication and persistence automatically. Handwritten `Provider.refreshModels()` implementations receive the read-only `context.stored` snapshot and publish through `context.publish({ persist?, update? })`. Omit `persist` to leave storage unchanged, pass a `ModelsStoreEntry` to write it, or pass `persist: null` to delete it. `ModelsStoreEntry.models` contains models of every type. Publication is generation-checked; put synchronous in-memory catalog changes in `update` rather than mutating state before publication.
1436
1438
 
1437
1439
  Custom models can carry `headers` (e.g. proxies behind bot detection) and `compat` flags. `Models.getAuth(model)` includes those model headers, and stream methods merge them before explicit request headers and `transformHeaders`. See [OpenAI Compatibility Settings](#openai-compatibility-settings).
@@ -1 +1 @@
1
- {"version":3,"file":"anthropic-messages.d.ts","sourceRoot":"","sources":["../../src/api/anthropic-messages.ts"],"names":[],"mappings":"AAAA,OAAO,SAAkD,MAAM,mBAAmB,CAAC;AAoBnF,OAAO,KAAK,EASX,mBAAmB,EAEnB,cAAc,EACd,aAAa,EAMb,MAAM,aAAa,CAAC;AAsLrB,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;AAE1E,MAAM,MAAM,wBAAwB,GAAG,YAAY,GAAG,SAAS,CAAC;AAkfhE,MAAM,WAAW,gBAAiB,SAAQ,aAAa;IACtD;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB;;;;;;;;;;;OAWG;IACH,eAAe,CAAC,EAAE,wBAAwB,CAAC;IAC3C;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACtE;;;;OAIG;IACH,MAAM,CAAC,EAAE,SAAS,CAAC;CACnB;AAqUD,eAAO,MAAM,MAAM,EAAE,cAAc,CAAC,oBAAoB,EAAE,gBAAgB,CA6azE,CAAC;AA+CF,eAAO,MAAM,YAAY,EAAE,cAAc,CAAC,oBAAoB,EAAE,mBAAmB,CAgDlF,CAAC"}
1
+ {"version":3,"file":"anthropic-messages.d.ts","sourceRoot":"","sources":["../../src/api/anthropic-messages.ts"],"names":[],"mappings":"AAAA,OAAO,SAAkD,MAAM,mBAAmB,CAAC;AAqBnF,OAAO,KAAK,EASX,mBAAmB,EAEnB,cAAc,EACd,aAAa,EAMb,MAAM,aAAa,CAAC;AA0LrB,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;AAE1E,MAAM,MAAM,wBAAwB,GAAG,YAAY,GAAG,SAAS,CAAC;AAkfhE,MAAM,WAAW,gBAAiB,SAAQ,aAAa;IACtD;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB;;;;;;;;;;;OAWG;IACH,eAAe,CAAC,EAAE,wBAAwB,CAAC;IAC3C;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACtE;;;;OAIG;IACH,MAAM,CAAC,EAAE,SAAS,CAAC;CACnB;AAqVD,eAAO,MAAM,MAAM,EAAE,cAAc,CAAC,oBAAoB,EAAE,gBAAgB,CAobzE,CAAC;AA+CF,eAAO,MAAM,YAAY,EAAE,cAAc,CAAC,oBAAoB,EAAE,mBAAmB,CAgDlF,CAAC"}
@@ -2,6 +2,7 @@ import Anthropic, {} from "@anthropic-ai/sdk";
2
2
  import { ANTHROPIC_FEDERATION_RULE_ID_ENV, ANTHROPIC_IDENTITY_TOKEN_FILE_ENV, ANTHROPIC_ORGANIZATION_ID_ENV, ANTHROPIC_SERVICE_ACCOUNT_ID_ENV, ANTHROPIC_WORKSPACE_ID_ENV, } from "../env-api-keys.js";
3
3
  import { calculateCost } from "../models.js";
4
4
  import { recordGitHubCopilotFailure } from "../providers/github-copilot-errors.js";
5
+ import { GitHubCopilotStreamAttempt } from "../providers/github-copilot-stream-attempt.js";
5
6
  import { registerSessionResourceCleanup } from "../session-resources.js";
6
7
  import { raceWithAbortSignal } from "../utils/abort.js";
7
8
  import { appendAssistantMessageDiagnostic } from "../utils/diagnostics.js";
@@ -24,9 +25,10 @@ import { getSystemMessageText, renderSystemMessageUpdate } from "../utils/text.j
24
25
  import { appendThinkingOffFallbackDiagnostic, getThinkingOffFallbackLevel } from "../utils/thinking-off.js";
25
26
  import { getCurrentTools, getInitialSystemMessage, resolveTranscript, } from "../utils/transcript.js";
26
27
  import { convertAnthropicAssistantContent } from "./anthropic-assistant-content.js";
27
- import { ANTHROPIC_STRICT_JSON_SCHEMA_PROFILE, getJsonSchemaToolParameters, isStrictToolLimitErrorMessage, prefersJsonSchemaStrictSampling, resolveJsonSchemaStrictSampling, } from "./constrained-sampling.js";
28
+ import { ANTHROPIC_STRICT_JSON_SCHEMA_PROFILE, getJsonSchemaToolParameters, prefersJsonSchemaStrictSampling, resolveJsonSchemaStrictSampling, } from "./constrained-sampling.js";
28
29
  import { buildCopilotDynamicHeaders, hasCopilotVisionInput, preserveCopilotIntegrationHeader, } from "./github-copilot-headers.js";
29
30
  import { adjustMaxTokensForThinking, buildBaseOptions, clampMaxTokensToContext } from "./simple-options.js";
31
+ import { hasExceededStrictToolLimits, isStrictToolLimitErrorMessage, markStrictToolLimitsExceeded, } from "./strict-tool-limits.js";
30
32
  import { splitErrorToolResultImages, transformMessages } from "./transform-messages.js";
31
33
  /**
32
34
  * Resolve cache retention preference.
@@ -636,6 +638,10 @@ const ANTHROPIC_MESSAGE_EVENTS = new Set([
636
638
  "content_block_delta",
637
639
  "content_block_stop",
638
640
  ]);
641
+ const ANTHROPIC_PING = { type: "ping" };
642
+ function isAnthropicPing(event) {
643
+ return event.type === "ping";
644
+ }
639
645
  function flushSseEvent(state) {
640
646
  if (!state.event && state.data.length === 0) {
641
647
  return null;
@@ -780,6 +786,10 @@ async function* iterateAnthropicEvents(response, signal) {
780
786
  const body = parseStreamedErrorBody(sse.data);
781
787
  throw new Anthropic.APIError(undefined, body, sse.data, response.headers, streamedErrorType(body));
782
788
  }
789
+ if (sse.event === "ping") {
790
+ yield ANTHROPIC_PING;
791
+ continue;
792
+ }
783
793
  if (!ANTHROPIC_MESSAGE_EVENTS.has(sse.event ?? "")) {
784
794
  continue;
785
795
  }
@@ -826,7 +836,7 @@ export const stream = (model, context, options) => {
826
836
  timestamp: Date.now(),
827
837
  };
828
838
  const streamDeadline = createStreamDeadline(options?.streamDeadlineMs, options?.signal);
829
- let streamStarted = false;
839
+ const streamAttempt = new GitHubCopilotStreamAttempt();
830
840
  let inputTransformations;
831
841
  try {
832
842
  const thinkingOffFallback = getAnthropicThinkingOffFallback(model, options);
@@ -874,12 +884,15 @@ export const stream = (model, context, options) => {
874
884
  ...(options?.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {}),
875
885
  maxRetries: 0,
876
886
  };
877
- const send = (body) => retryProviderRequest(() => client.beta.messages.create({ ...body, stream: true }, requestOptions).asResponse(), {
887
+ const send = (body) => retryProviderRequest(() => {
888
+ streamAttempt.begin();
889
+ return client.beta.messages.create({ ...body, stream: true }, requestOptions).asResponse();
890
+ }, {
878
891
  maxRetries: options?.maxRetries,
879
892
  maxRetryDelayMs: options?.maxRetryDelayMs,
880
893
  signal: streamDeadline.signal,
881
894
  });
882
- let disablePreferredStrictTools = false;
895
+ let disablePreferredStrictTools = hasExceededStrictToolLimits(options?.sessionId);
883
896
  let response;
884
897
  let params;
885
898
  // The thread request that produced the response; undefined when no `thread` was sent.
@@ -918,6 +931,7 @@ export const stream = (model, context, options) => {
918
931
  !isStrictToolLimitErrorMessage(error.message))
919
932
  throw error;
920
933
  disablePreferredStrictTools = true;
934
+ markStrictToolLimitsExceeded(options?.sessionId);
921
935
  appendAssistantMessageDiagnostic(output, {
922
936
  type: "anthropic_strict_tools_fallback",
923
937
  timestamp: Date.now(),
@@ -928,14 +942,14 @@ export const stream = (model, context, options) => {
928
942
  }
929
943
  await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);
930
944
  stream.push({ type: "start", partial: output });
931
- streamStarted = true;
945
+ streamAttempt.respond(response.headers);
932
946
  // Stream state per Anthropic block index, kept off the content blocks so it never reaches partials.
933
947
  const openBlocks = new Map();
934
948
  const openBlock = (anthropicIndex) => {
935
949
  const open = openBlocks.get(anthropicIndex);
936
950
  return open === undefined ? undefined : { ...open, block: output.content[open.contentIndex] };
937
951
  };
938
- for await (const event of withStreamDeadline(iterateAnthropicEvents(response, streamDeadline.signal), streamDeadline.deadlineMs, streamDeadline.abort)) {
952
+ for await (const event of streamAttempt.observe(withStreamDeadline(iterateAnthropicEvents(response, streamDeadline.signal), streamDeadline.deadlineMs, streamDeadline.abort, isAnthropicPing))) {
939
953
  await options?.onProviderStreamEvent?.(event, model);
940
954
  if (event.type === "message_start") {
941
955
  output.responseId = event.message.id;
@@ -1187,7 +1201,7 @@ export const stream = (model, context, options) => {
1187
1201
  output.errorMessage = error instanceof Error ? withCauseDetail(error) : JSON.stringify(error);
1188
1202
  output.retryAfterMs = error instanceof Error ? getProviderRetryAfterMs(error) : undefined;
1189
1203
  if (model.provider === "github-copilot")
1190
- recordGitHubCopilotFailure(output, error, streamStarted);
1204
+ recordGitHubCopilotFailure(output, error, streamAttempt.snapshot());
1191
1205
  stream.push({ type: "error", reason: output.stopReason, error: output });
1192
1206
  stream.end();
1193
1207
  }