@bastani/pi-ai 0.9.37 → 0.9.38-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 (95) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +1 -1
  3. package/dist/api/anthropic-messages.js +8 -3
  4. package/dist/api/anthropic-messages.js.map +1 -1
  5. package/dist/api/bedrock-converse-stream.js +2 -2
  6. package/dist/api/bedrock-converse-stream.js.map +1 -1
  7. package/dist/api/google-shared.d.ts.map +1 -1
  8. package/dist/api/google-shared.js +1 -0
  9. package/dist/api/google-shared.js.map +1 -1
  10. package/dist/api/mistral-conversations.js +2 -2
  11. package/dist/api/mistral-conversations.js.map +1 -1
  12. package/dist/api/openai-codex-responses.d.ts.map +1 -1
  13. package/dist/api/openai-codex-responses.js +5 -1
  14. package/dist/api/openai-codex-responses.js.map +1 -1
  15. package/dist/api/openai-completions.d.ts +1 -1
  16. package/dist/api/openai-completions.d.ts.map +1 -1
  17. package/dist/api/openai-completions.js +31 -29
  18. package/dist/api/openai-completions.js.map +1 -1
  19. package/dist/api/openai-responses-shared.d.ts +10 -0
  20. package/dist/api/openai-responses-shared.d.ts.map +1 -1
  21. package/dist/api/openai-responses-shared.js +15 -2
  22. package/dist/api/openai-responses-shared.js.map +1 -1
  23. package/dist/api/openai-responses.d.ts.map +1 -1
  24. package/dist/api/openai-responses.js +25 -6
  25. package/dist/api/openai-responses.js.map +1 -1
  26. package/dist/api/openai-retry-hint-client.d.ts +10 -0
  27. package/dist/api/openai-retry-hint-client.d.ts.map +1 -0
  28. package/dist/api/openai-retry-hint-client.js +17 -0
  29. package/dist/api/openai-retry-hint-client.js.map +1 -0
  30. package/dist/auth/oauth/kimi-coding.d.ts +1 -1
  31. package/dist/auth/oauth/kimi-coding.js +1 -1
  32. package/dist/auth/oauth/kimi-coding.js.map +1 -1
  33. package/dist/index.d.ts +0 -1
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +0 -1
  36. package/dist/index.js.map +1 -1
  37. package/dist/model-catalog.d.ts +1 -1
  38. package/dist/model-catalog.d.ts.map +1 -1
  39. package/dist/model-catalog.js +32 -2
  40. package/dist/model-catalog.js.map +1 -1
  41. package/dist/providers/compat-schema.d.ts +3 -0
  42. package/dist/providers/compat-schema.d.ts.map +1 -1
  43. package/dist/providers/compat-schema.js +8 -0
  44. package/dist/providers/compat-schema.js.map +1 -1
  45. package/dist/providers/data/.manifest.json +1 -1
  46. package/dist/providers/data/kimi-coding.json +1 -1
  47. package/dist/providers/data/nvidia.json +1 -1
  48. package/dist/providers/data/openai.json +1 -1
  49. package/dist/providers/data/opencode-go.json +1 -1
  50. package/dist/providers/data/opencode.json +1 -1
  51. package/dist/providers/data/openrouter.json +1 -1
  52. package/dist/providers/data/radius.json +1 -1
  53. package/dist/providers/data/vercel-ai-gateway.json +1 -1
  54. package/dist/providers/data/xiaomi-token-plan-ams.json +1 -1
  55. package/dist/providers/data/xiaomi-token-plan-cn.json +1 -1
  56. package/dist/providers/data/xiaomi-token-plan-sgp.json +1 -1
  57. package/dist/providers/data/xiaomi.json +1 -1
  58. package/dist/providers/kimi-coding.d.ts +1 -1
  59. package/dist/providers/kimi-coding.js +3 -3
  60. package/dist/providers/kimi-coding.js.map +1 -1
  61. package/dist/providers/openai-codex.js.map +1 -1
  62. package/dist/providers/openai-mid-convo-effort.d.ts +2 -0
  63. package/dist/providers/openai-mid-convo-effort.d.ts.map +1 -0
  64. package/dist/providers/openai-mid-convo-effort.js +7 -0
  65. package/dist/providers/openai-mid-convo-effort.js.map +1 -0
  66. package/dist/providers/openai.d.ts.map +1 -1
  67. package/dist/providers/openai.js +11 -2
  68. package/dist/providers/openai.js.map +1 -1
  69. package/dist/providers/opencode-go.d.ts +3 -1
  70. package/dist/providers/opencode-go.d.ts.map +1 -1
  71. package/dist/providers/opencode-go.js +2 -0
  72. package/dist/providers/opencode-go.js.map +1 -1
  73. package/dist/types.d.ts +3 -0
  74. package/dist/types.d.ts.map +1 -1
  75. package/dist/types.js.map +1 -1
  76. package/dist/utils/json-parse.d.ts +2 -0
  77. package/dist/utils/json-parse.d.ts.map +1 -1
  78. package/dist/utils/json-parse.js +18 -1
  79. package/dist/utils/json-parse.js.map +1 -1
  80. package/dist/utils/retry-hints.d.ts +12 -0
  81. package/dist/utils/retry-hints.d.ts.map +1 -0
  82. package/dist/utils/retry-hints.js +50 -0
  83. package/dist/utils/retry-hints.js.map +1 -0
  84. package/dist/utils/retry.d.ts +20 -2
  85. package/dist/utils/retry.d.ts.map +1 -1
  86. package/dist/utils/retry.js +28 -3
  87. package/dist/utils/retry.js.map +1 -1
  88. package/dist/utils/validation.d.ts.map +1 -1
  89. package/dist/utils/validation.js +3 -0
  90. package/dist/utils/validation.js.map +1 -1
  91. package/package.json +1 -1
  92. package/dist/utils/assistant-message-frame.d.ts +0 -77
  93. package/dist/utils/assistant-message-frame.d.ts.map +0 -1
  94. package/dist/utils/assistant-message-frame.js +0 -439
  95. package/dist/utils/assistant-message-frame.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -4,6 +4,33 @@ 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.38-alpha.1] - 2026-10-15
8
+
9
+ ### Breaking Changes
10
+
11
+ - Removed `AssistantMessageFrame`, `AssistantMessageFrameEncoder`, and `reduceAssistantMessageFrames()`. Use `AssistantMessageEventStream` events for streaming progress and `result()` for the final message instead.
12
+
13
+ ### Added
14
+
15
+ - Added cache-preserving thinking-level changes for GPT-6 models on `openai` and `openai-api` with API-key authentication, controlled by `compat.supportsMidConvoEffort` ([#10853](https://github.com/earendil-works/pi/issues/10853)).
16
+
17
+ ### Changed
18
+
19
+ - Changed `kimi-coding` to OpenAI Chat Completions at `https://api.kimi.com/coding/v1`, matching the official Kimi Code client. K3, K3-256K, and Kimi For Coding support tools added mid-conversation without invalidating the prompt cache. Custom `models.json` base URLs for this provider must include `/v1` ([#10720](https://github.com/earendil-works/pi/issues/10720)).
20
+
21
+ ### Fixed
22
+
23
+ - Fixed OpenCode Go Gemini models failing with a 404, and builds failing when the OpenCode Go catalog lists Gemini models, by moving OpenCode Zen and OpenCode Go to the `opencode.ai/inference` endpoints and registering the Google Generative AI API on the `opencode-go` provider, matching OpenCode Zen.
24
+ - Fixed OpenCode Go MiniMax M2.7 failing with "Model does not support this protocol" by using the Anthropic Messages API.
25
+ - Fixed tool-call argument parsing dropping fields when a string contains an invalid `\u` escape such as `\usepackage` ([#10868](https://github.com/earendil-works/pi/issues/10868)).
26
+ - Fixed Anthropic requests failing with a 400 when an error tool result contains images; images are now replaced with a text note ([#10794](https://github.com/earendil-works/pi/issues/10794)).
27
+ - Fixed automatic retry not triggering for gateway `Unable to forward upstream stream` errors ([#10920](https://github.com/earendil-works/pi/issues/10920)).
28
+ - Fixed OpenAI-compatible responses showing thinking after the answer when a proxy such as LiteLLM sends reasoning and content in the same stream chunk ([#10926](https://github.com/earendil-works/pi/issues/10926)).
29
+ - Fixed Gemini 4 Argon requests on Google Vertex failing with "Thinking budget is not supported", and its thinking level being ignored on the Gemini API, by sending `thinkingLevel` for Gemini 4 and later models ([#10890](https://github.com/earendil-works/pi/issues/10890)).
30
+ - Fixed Xiaomi MiMo models failing with a 400 at the `minimal` thinking level by sending only the documented thinking on/off toggle and exposing only the `off` and `high` levels ([#10818](https://github.com/earendil-works/pi/issues/10818)).
31
+ - Fixed tool calls with malformed final JSON arguments silently running with only a parsed prefix. These calls now fail validation with the original arguments so the model can correct them ([#10897](https://github.com/earendil-works/pi/issues/10897)).
32
+ - Fixed `retryAssistantCall()` ignoring server retry hints. A failed response's `Retry-After-Ms`, `Retry-After` (seconds or HTTP date) or Cloudflare body `retry_after` is reported as `AssistantMessage.retryAfterMs` by the OpenAI Responses, OpenAI Completions and ChatGPT (Codex) providers, and replaces the exponential backoff for that retry, capped by the new `RetryPolicy.maxRetryDelayMs` (60 seconds by default). Cloudflare 521-523 responses and connection resets are now retryable ([#3623](https://github.com/bastani-inc/atomic/issues/3623))
33
+
7
34
  ## [0.9.36] - 2026-10-13
8
35
 
9
36
  ### Fixed
package/README.md CHANGED
@@ -93,7 +93,7 @@ Unified LLM API with provider collections, automatic auth resolution, token and
93
93
  - **OpenCode Zen**
94
94
  - **OpenCode Go**
95
95
  - **Fireworks** (uses OpenAI- and Anthropic-compatible APIs)
96
- - **Kimi For Coding** (Moonshot AI subscription endpoint, uses Anthropic-compatible API)
96
+ - **Kimi For Coding** (Moonshot AI subscription endpoint, uses OpenAI Chat Completions)
97
97
  - **Meta** (Model API, uses OpenAI Responses-compatible API)
98
98
  - **Qwen Token Plan** (separate Individual and existing catalogs, with a separate China provider)
99
99
  - **Xiaomi MiMo** (defaults to API billing endpoint, with separate Token Plan providers for `cn`/`ams`/`sgp` regions)
@@ -5,7 +5,7 @@ import { appendAssistantMessageDiagnostic } from "../utils/diagnostics.js";
5
5
  import { assertSupportedDocumentMimeType } from "../utils/document-input.js";
6
6
  import { AssistantMessageEventStream } from "../utils/event-stream.js";
7
7
  import { headersToRecord } from "../utils/headers.js";
8
- import { parseJsonWithRepair, parseStreamingJson } from "../utils/json-parse.js";
8
+ import { parseJsonWithRepair, parseStreamingJson, parseToolCallArguments } from "../utils/json-parse.js";
9
9
  import { getPiUserAgent } from "../utils/pi-user-agent.js";
10
10
  import { getProviderEnvValue } from "../utils/provider-env.js";
11
11
  import { retryProviderRequest } from "../utils/provider-retry.js";
@@ -827,7 +827,7 @@ export const stream = (model, context, options) => {
827
827
  });
828
828
  }
829
829
  else if (block.type === "toolCall") {
830
- block.arguments = parseStreamingJson(block.partialJson);
830
+ Object.assign(block, parseToolCallArguments(block.partialJson));
831
831
  // Finalize in-place and strip the scratch buffer so replay only
832
832
  // carries parsed arguments.
833
833
  delete block.partialJson;
@@ -1308,10 +1308,15 @@ function normalizeToolCallId(id) {
1308
1308
  return id.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 64);
1309
1309
  }
1310
1310
  function convertToolResult(msg) {
1311
+ const content = msg.isError
1312
+ ? msg.content.map((block) => block.type === "image"
1313
+ ? { type: "text", text: "[image omitted: error tool results cannot contain images]" }
1314
+ : block)
1315
+ : msg.content;
1311
1316
  return {
1312
1317
  type: "tool_result",
1313
1318
  tool_use_id: msg.toolCallId,
1314
- content: convertContentBlocks(msg.content),
1319
+ content: convertContentBlocks(content),
1315
1320
  is_error: msg.isError,
1316
1321
  };
1317
1322
  }