@gajae-code/ai 0.18.1 → 0.18.6

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 (38) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/dist/types/auth-storage.d.ts +8 -1
  3. package/dist/types/index.d.ts +0 -1
  4. package/dist/types/providers/cursor.d.ts +6 -3
  5. package/dist/types/providers/kiro-api-key.d.ts +1 -0
  6. package/dist/types/providers/openai-codex-responses.d.ts +2 -0
  7. package/dist/types/types.d.ts +1 -1
  8. package/dist/types/utils/fallback-transport.d.ts +6 -0
  9. package/dist/types/utils/oauth/glm-zcode.d.ts +5 -0
  10. package/dist/types/utils/oauth/index.d.ts +4 -0
  11. package/package.json +3 -3
  12. package/src/auth-storage.ts +115 -39
  13. package/src/index.ts +0 -1
  14. package/src/model-pricing.ts +10 -0
  15. package/src/model-thinking.ts +8 -0
  16. package/src/models.json +210 -0
  17. package/src/providers/anthropic.ts +25 -1
  18. package/src/providers/aws-eventstream.ts +2 -1
  19. package/src/providers/cursor.d.ts +6 -3
  20. package/src/providers/cursor.ts +73 -64
  21. package/src/providers/kiro-api-key.d.ts +1 -0
  22. package/src/providers/kiro-api-key.ts +1 -1
  23. package/src/providers/kiro-codewhisperer.ts +142 -34
  24. package/src/providers/openai-codex-responses.d.ts +2 -0
  25. package/src/providers/openai-codex-responses.ts +438 -40
  26. package/src/providers/openai-completions.ts +19 -1
  27. package/src/stream.ts +20 -0
  28. package/src/types.d.ts +1 -1
  29. package/src/types.ts +3 -0
  30. package/src/utils/fallback-transport.d.ts +6 -0
  31. package/src/utils/fallback-transport.ts +6 -0
  32. package/src/utils/idle-iterator.ts +10 -3
  33. package/src/utils/oauth/glm-zcode.d.ts +5 -0
  34. package/src/utils/oauth/glm-zcode.ts +8 -1
  35. package/src/utils/oauth/index.ts +11 -1
  36. package/src/utils/validation.ts +5 -0
  37. package/dist/types/utils/h2-fetch.d.ts +0 -35
  38. package/src/utils/h2-fetch.ts +0 -133
package/src/models.json CHANGED
@@ -964,6 +964,31 @@
964
964
  "maxLevel": "high"
965
965
  }
966
966
  },
967
+ "anthropic.claude-sonnet-5-5": {
968
+ "id": "anthropic.claude-sonnet-5-5",
969
+ "name": "Anthropic Sonnet 5.5",
970
+ "api": "bedrock-converse-stream",
971
+ "provider": "amazon-bedrock",
972
+ "baseUrl": "https://bedrock-runtime.us-east-1.amazonaws.com",
973
+ "reasoning": true,
974
+ "input": [
975
+ "text",
976
+ "image"
977
+ ],
978
+ "cost": {
979
+ "input": 2,
980
+ "output": 10,
981
+ "cacheRead": 0.2,
982
+ "cacheWrite": 2.5
983
+ },
984
+ "contextWindow": 1000000,
985
+ "maxTokens": 128000,
986
+ "thinking": {
987
+ "mode": "anthropic-budget-effort",
988
+ "minLevel": "minimal",
989
+ "maxLevel": "high"
990
+ }
991
+ },
967
992
  "apac.amazon.nova-lite-v1:0": {
968
993
  "id": "apac.amazon.nova-lite-v1:0",
969
994
  "name": "Nova Lite (APAC)",
@@ -1308,6 +1333,31 @@
1308
1333
  "maxLevel": "high"
1309
1334
  }
1310
1335
  },
1336
+ "au.anthropic.claude-sonnet-5-5": {
1337
+ "id": "au.anthropic.claude-sonnet-5-5",
1338
+ "name": "Anthropic Sonnet 5.5 (AU)",
1339
+ "api": "bedrock-converse-stream",
1340
+ "provider": "amazon-bedrock",
1341
+ "baseUrl": "https://bedrock-runtime.us-east-1.amazonaws.com",
1342
+ "reasoning": true,
1343
+ "input": [
1344
+ "text",
1345
+ "image"
1346
+ ],
1347
+ "cost": {
1348
+ "input": 2.2,
1349
+ "output": 11,
1350
+ "cacheRead": 0.22,
1351
+ "cacheWrite": 2.75
1352
+ },
1353
+ "contextWindow": 1000000,
1354
+ "maxTokens": 128000,
1355
+ "thinking": {
1356
+ "mode": "anthropic-budget-effort",
1357
+ "minLevel": "minimal",
1358
+ "maxLevel": "high"
1359
+ }
1360
+ },
1311
1361
  "ca.amazon.nova-lite-v1:0": {
1312
1362
  "id": "ca.amazon.nova-lite-v1:0",
1313
1363
  "name": "Nova Lite (CA)",
@@ -2072,6 +2122,31 @@
2072
2122
  "maxLevel": "high"
2073
2123
  }
2074
2124
  },
2125
+ "eu.anthropic.claude-sonnet-5-5": {
2126
+ "id": "eu.anthropic.claude-sonnet-5-5",
2127
+ "name": "Anthropic Sonnet 5.5 (EU)",
2128
+ "api": "bedrock-converse-stream",
2129
+ "provider": "amazon-bedrock",
2130
+ "baseUrl": "https://bedrock-runtime.us-east-1.amazonaws.com",
2131
+ "reasoning": true,
2132
+ "input": [
2133
+ "text",
2134
+ "image"
2135
+ ],
2136
+ "cost": {
2137
+ "input": 2.2,
2138
+ "output": 11,
2139
+ "cacheRead": 0.22,
2140
+ "cacheWrite": 2.75
2141
+ },
2142
+ "contextWindow": 1000000,
2143
+ "maxTokens": 128000,
2144
+ "thinking": {
2145
+ "mode": "anthropic-budget-effort",
2146
+ "minLevel": "minimal",
2147
+ "maxLevel": "high"
2148
+ }
2149
+ },
2075
2150
  "eu.mistral.pixtral-large-2502-v1:0": {
2076
2151
  "id": "eu.mistral.pixtral-large-2502-v1:0",
2077
2152
  "name": "Pixtral Large (25.02) (EU)",
@@ -2477,6 +2552,31 @@
2477
2552
  "maxLevel": "high"
2478
2553
  }
2479
2554
  },
2555
+ "global.anthropic.claude-sonnet-5-5": {
2556
+ "id": "global.anthropic.claude-sonnet-5-5",
2557
+ "name": "Anthropic Sonnet 5.5 (Global)",
2558
+ "api": "bedrock-converse-stream",
2559
+ "provider": "amazon-bedrock",
2560
+ "baseUrl": "https://bedrock-runtime.us-east-1.amazonaws.com",
2561
+ "reasoning": true,
2562
+ "input": [
2563
+ "text",
2564
+ "image"
2565
+ ],
2566
+ "cost": {
2567
+ "input": 2,
2568
+ "output": 10,
2569
+ "cacheRead": 0.2,
2570
+ "cacheWrite": 2.5
2571
+ },
2572
+ "contextWindow": 1000000,
2573
+ "maxTokens": 128000,
2574
+ "thinking": {
2575
+ "mode": "anthropic-budget-effort",
2576
+ "minLevel": "minimal",
2577
+ "maxLevel": "high"
2578
+ }
2579
+ },
2480
2580
  "global.openai.gpt-5.6-luna": {
2481
2581
  "id": "global.openai.gpt-5.6-luna",
2482
2582
  "name": "GPT-5.6 Luna (Global)",
@@ -3020,6 +3120,31 @@
3020
3120
  "maxLevel": "high"
3021
3121
  }
3022
3122
  },
3123
+ "jp.anthropic.claude-sonnet-5-5": {
3124
+ "id": "jp.anthropic.claude-sonnet-5-5",
3125
+ "name": "Anthropic Sonnet 5.5 (JP)",
3126
+ "api": "bedrock-converse-stream",
3127
+ "provider": "amazon-bedrock",
3128
+ "baseUrl": "https://bedrock-runtime.us-east-1.amazonaws.com",
3129
+ "reasoning": true,
3130
+ "input": [
3131
+ "text",
3132
+ "image"
3133
+ ],
3134
+ "cost": {
3135
+ "input": 2.2,
3136
+ "output": 11,
3137
+ "cacheRead": 0.22,
3138
+ "cacheWrite": 2.75
3139
+ },
3140
+ "contextWindow": 1000000,
3141
+ "maxTokens": 128000,
3142
+ "thinking": {
3143
+ "mode": "anthropic-budget-effort",
3144
+ "minLevel": "minimal",
3145
+ "maxLevel": "high"
3146
+ }
3147
+ },
3023
3148
  "meta.llama3-1-405b-instruct-v1:0": {
3024
3149
  "id": "meta.llama3-1-405b-instruct-v1:0",
3025
3150
  "name": "Llama 3.1 405B Instruct",
@@ -4501,6 +4626,31 @@
4501
4626
  "maxLevel": "high"
4502
4627
  }
4503
4628
  },
4629
+ "us.anthropic.claude-sonnet-5-5": {
4630
+ "id": "us.anthropic.claude-sonnet-5-5",
4631
+ "name": "Anthropic Sonnet 5.5 (US)",
4632
+ "api": "bedrock-converse-stream",
4633
+ "provider": "amazon-bedrock",
4634
+ "baseUrl": "https://bedrock-runtime.us-east-1.amazonaws.com",
4635
+ "reasoning": true,
4636
+ "input": [
4637
+ "text",
4638
+ "image"
4639
+ ],
4640
+ "cost": {
4641
+ "input": 2.2,
4642
+ "output": 11,
4643
+ "cacheRead": 0.22,
4644
+ "cacheWrite": 2.75
4645
+ },
4646
+ "contextWindow": 1000000,
4647
+ "maxTokens": 128000,
4648
+ "thinking": {
4649
+ "mode": "anthropic-budget-effort",
4650
+ "minLevel": "minimal",
4651
+ "maxLevel": "high"
4652
+ }
4653
+ },
4504
4654
  "us.deepseek.r1-v1:0": {
4505
4655
  "id": "us.deepseek.r1-v1:0",
4506
4656
  "name": "DeepSeek-R1 (US)",
@@ -5656,6 +5806,31 @@
5656
5806
  "minLevel": "minimal",
5657
5807
  "maxLevel": "max"
5658
5808
  }
5809
+ },
5810
+ "claude-sonnet-5-5": {
5811
+ "id": "claude-sonnet-5-5",
5812
+ "name": "Anthropic Sonnet 5.5",
5813
+ "api": "anthropic-messages",
5814
+ "provider": "anthropic",
5815
+ "baseUrl": "https://api.anthropic.com",
5816
+ "reasoning": true,
5817
+ "input": [
5818
+ "text",
5819
+ "image"
5820
+ ],
5821
+ "cost": {
5822
+ "input": 2,
5823
+ "output": 10,
5824
+ "cacheRead": 0.2,
5825
+ "cacheWrite": 2.5
5826
+ },
5827
+ "contextWindow": 1000000,
5828
+ "maxTokens": 128000,
5829
+ "thinking": {
5830
+ "mode": "anthropic-adaptive",
5831
+ "minLevel": "minimal",
5832
+ "maxLevel": "max"
5833
+ }
5659
5834
  }
5660
5835
  },
5661
5836
  "azure-openai": {
@@ -68026,6 +68201,41 @@
68026
68201
  }
68027
68202
  }
68028
68203
  },
68204
+ "gpt-6.1-sol": {
68205
+ "id": "gpt-6.1-sol",
68206
+ "name": "GPT-6.1-Sol",
68207
+ "api": "openai-codex-responses",
68208
+ "provider": "openai-codex",
68209
+ "baseUrl": "https://chatgpt.com/backend-api",
68210
+ "reasoning": true,
68211
+ "input": [
68212
+ "text",
68213
+ "image"
68214
+ ],
68215
+ "cost": {
68216
+ "input": 2,
68217
+ "output": 10,
68218
+ "cacheRead": 0.1,
68219
+ "cacheWrite": 2.5
68220
+ },
68221
+ "contextWindow": 272000,
68222
+ "maxTokens": 128000,
68223
+ "preferWebsockets": true,
68224
+ "thinking": {
68225
+ "mode": "effort",
68226
+ "minLevel": "low",
68227
+ "maxLevel": "max"
68228
+ },
68229
+ "longContextPricing": {
68230
+ "threshold": 272000,
68231
+ "cost": {
68232
+ "input": 4,
68233
+ "output": 15,
68234
+ "cacheRead": 0.2,
68235
+ "cacheWrite": 5
68236
+ }
68237
+ }
68238
+ },
68029
68239
  "gpt-daybreak-blue-latest": {
68030
68240
  "id": "gpt-daybreak-blue-latest",
68031
68241
  "name": "Daybreak Blue",
@@ -1764,6 +1764,23 @@ function isTransientStreamEnvelopeError(error: unknown): boolean {
1764
1764
  );
1765
1765
  }
1766
1766
 
1767
+ /**
1768
+ * A request whose connection failed before the server returned any response:
1769
+ * the SDK's connection error, or a reset/closed/refused socket with no HTTP status.
1770
+ */
1771
+ function isPreResponseConnectionFailure(error: unknown): boolean {
1772
+ if (!(error instanceof Error)) return false;
1773
+ if (extractHttpStatusFromError(error) !== undefined) return false;
1774
+ if (error instanceof Anthropic.APIConnectionTimeoutError) return false;
1775
+ if (error instanceof Anthropic.APIConnectionError) return true;
1776
+ const code = (error as { code?: unknown }).code;
1777
+ if (typeof code === "string" && /^(?:ECONNRESET|ECONNREFUSED|EPIPE|ENOTFOUND|EAI_AGAIN)$/.test(code)) return true;
1778
+ return (
1779
+ isUnexpectedSocketCloseMessage(error.message) ||
1780
+ /\b(?:ECONNRESET|ECONNREFUSED|EPIPE)\b|^connection error\.?$|other side closed/i.test(error.message)
1781
+ );
1782
+ }
1783
+
1767
1784
  function isProviderRetryableStreamEnvelopeError(error: unknown): boolean {
1768
1785
  if (!(error instanceof Error)) return false;
1769
1786
  return /stream event order|before message_start/i.test(error.message);
@@ -2672,7 +2689,14 @@ export const streamAnthropic: StreamFunction<"anthropic-messages"> = (
2672
2689
  // Otherwise the multi-megabyte body is re-uploaded up to the default
2673
2690
  // streamMaxRetries budget despite the ceiling. Once iteration has
2674
2691
  // begun, only the grace-clock path above decides.
2675
- if (requestUploadCeilingBound && firstEventWaitStartedAt === undefined) {
2692
+ // A connection that dropped before any response (reset, socket closed,
2693
+ // connect failure) is exempt: the server never answered, so a retry is
2694
+ // not a re-upload after a stall, and a network blip must not end the turn.
2695
+ if (
2696
+ requestUploadCeilingBound &&
2697
+ firstEventWaitStartedAt === undefined &&
2698
+ !isPreResponseConnectionFailure(streamFailure)
2699
+ ) {
2676
2700
  Object.assign(streamFailure as Error, {
2677
2701
  requestBytes,
2678
2702
  endpointClass,
@@ -178,7 +178,8 @@ export async function* decodeEventStream(source: ReadableStream<Uint8Array>): As
178
178
  if (offset > 0) buf = buf.slice(offset);
179
179
  if (done) break;
180
180
  }
181
- if (buf.length > 0) throw new Error("eventstream: truncated message at end of stream");
181
+ if (buf.length > 0)
182
+ throw new Error(`eventstream: truncated message at end of stream (${buf.length} trailing bytes)`);
182
183
  } finally {
183
184
  reader.releaseLock();
184
185
  }
@@ -2,8 +2,10 @@ import http2 from "node:http2";
2
2
  import { type JsonValue } from "@bufbuild/protobuf";
3
3
  import type { AssistantMessage, CursorExecHandlerResult, CursorExecHandlers, CursorToolResultHandler, Message, Model, StreamFunction, StreamOptions, Tool, ToolCall, ToolResultMessage, Usage } from "../types";
4
4
  import { kProviderResolvedToolCall } from "../utils/block-symbols";
5
+ import { AssistantMessageEventStream } from "../utils/event-stream";
5
6
  import { CURSOR_CLIENT_VERSION } from "./cursor/client-version";
6
7
  import type { CursorRule, RequestedModel_ModelParameterbytes } from "./cursor/gen/agent_pb";
8
+ import { type AgentServerMessage } from "./cursor/gen/agent_pb";
7
9
  export declare const CURSOR_API_URL = "https://api2.cursor.sh";
8
10
  export { CURSOR_CLIENT_VERSION };
9
11
  /** Drop all cached state + blob bytes for a conversation (F15 bound + session-teardown hook). */
@@ -46,9 +48,8 @@ export declare function mapH2TransportError(error: unknown, baseUrl: string): un
46
48
  export declare const streamCursor: StreamFunction<"cursor-agent">;
47
49
  type ToolCallState = ToolCall & {
48
50
  index: number;
49
- partialJson?: string;
50
- kind: "mcp" | "todo_write" | "native" | "cursor-exec";
51
- [kProviderResolvedToolCall]?: true;
51
+ kind: "todo_write" | "native" | "cursor-exec";
52
+ [kProviderResolvedToolCall]: true;
52
53
  };
53
54
  interface UsageState {
54
55
  sawTokenDelta: boolean;
@@ -56,6 +57,8 @@ interface UsageState {
56
57
  checkpointOutputTokens: number;
57
58
  hasConversationCheckpoint: boolean;
58
59
  }
60
+ /** Offline test seam for the same server-message boundary used by streamCursor. */
61
+ export declare function createCursorServerMessageHandlerForTest(output: AssistantMessage, stream: AssistantMessageEventStream, write: (frame: Uint8Array, done: () => void) => boolean, options?: CursorOptions): (message: AgentServerMessage) => Promise<void>;
59
62
  export declare function storeCursorBlobForTest(blobStore: Map<string, Uint8Array>, blobId: Uint8Array, blobData: Uint8Array, limits: {
60
63
  maxBytes: number;
61
64
  }): boolean;
@@ -32,7 +32,6 @@ import { kProviderResolvedToolCall } from "../utils/block-symbols";
32
32
  import { AssistantMessageEventStream } from "../utils/event-stream";
33
33
  import { transportFailureFacts } from "../utils/fallback-transport";
34
34
  import { FirstEventTimeoutError, getStreamFirstEventTimeoutMs, getStreamIdleTimeoutMs } from "../utils/idle-iterator";
35
- import { captureUnicodeEscapeEvidence, parseStreamingJson } from "../utils/json-parse";
36
35
  import { connectProxiedSocket, getProxyForUrl } from "../utils/proxy";
37
36
  import { formatErrorMessageWithRetryAfter } from "../utils/retry-after";
38
37
  import { flattenToolRootCombinators, toolWireSchema } from "../utils/schema";
@@ -2288,10 +2287,8 @@ export const streamCursor: StreamFunction<"cursor-agent"> = (
2288
2287
  }
2289
2288
  if (state.currentToolCall) {
2290
2289
  const idx = output.content.indexOf(state.currentToolCall);
2291
- state.currentToolCall.arguments = parseStreamingJson(state.currentToolCall.partialJson);
2292
- captureUnicodeEscapeEvidence(state.currentToolCall, state.currentToolCall.partialJson ?? "");
2293
- delete (state.currentToolCall as any).partialJson;
2294
- delete (state.currentToolCall as any).index;
2290
+ delete (state.currentToolCall as Partial<ToolCallState>).index;
2291
+ delete (state.currentToolCall as Partial<ToolCallState>).kind;
2295
2292
  stream.push({
2296
2293
  type: "toolcall_end",
2297
2294
  contentIndex: idx,
@@ -2428,9 +2425,8 @@ export const streamCursor: StreamFunction<"cursor-agent"> = (
2428
2425
 
2429
2426
  type ToolCallState = ToolCall & {
2430
2427
  index: number;
2431
- partialJson?: string;
2432
- kind: "mcp" | "todo_write" | "native" | "cursor-exec";
2433
- [kProviderResolvedToolCall]?: true;
2428
+ kind: "todo_write" | "native" | "cursor-exec";
2429
+ [kProviderResolvedToolCall]: true;
2434
2430
  };
2435
2431
 
2436
2432
  interface BlockState {
@@ -2493,6 +2489,57 @@ async function handleServerMessage(
2493
2489
  }
2494
2490
  }
2495
2491
 
2492
+ /** Offline test seam for the same server-message boundary used by streamCursor. */
2493
+ export function createCursorServerMessageHandlerForTest(
2494
+ output: AssistantMessage,
2495
+ stream: AssistantMessageEventStream,
2496
+ write: (frame: Uint8Array, done: () => void) => boolean,
2497
+ options: CursorOptions = {},
2498
+ ): (message: AgentServerMessage) => Promise<void> {
2499
+ const state: BlockState = {
2500
+ currentTextBlock: null,
2501
+ currentThinkingBlock: null,
2502
+ currentToolCall: null,
2503
+ firstTokenTime: undefined,
2504
+ setTextBlock(block) {
2505
+ this.currentTextBlock = block;
2506
+ },
2507
+ setThinkingBlock(block) {
2508
+ this.currentThinkingBlock = block;
2509
+ },
2510
+ setToolCall(block) {
2511
+ this.currentToolCall = block;
2512
+ },
2513
+ setFirstTokenTime() {
2514
+ this.firstTokenTime ??= Date.now();
2515
+ },
2516
+ };
2517
+ const usageState: UsageState = {
2518
+ sawTokenDelta: false,
2519
+ conversationUsedTokens: 0,
2520
+ checkpointOutputTokens: 0,
2521
+ hasConversationCheckpoint: false,
2522
+ };
2523
+ const writer = { write, isActive: () => true } as unknown as CursorRequestWriter;
2524
+ const blobs = new Map<string, Uint8Array>();
2525
+ return message =>
2526
+ handleServerMessage(
2527
+ message,
2528
+ output,
2529
+ stream,
2530
+ state,
2531
+ blobs,
2532
+ writer,
2533
+ options.execHandlers,
2534
+ options.onToolResult,
2535
+ usageState,
2536
+ [],
2537
+ undefined,
2538
+ [],
2539
+ options.signal,
2540
+ );
2541
+ }
2542
+
2496
2543
  function handleKvServerMessage(
2497
2544
  kvMsg: KvServerMessage,
2498
2545
  blobStore: Map<string, Uint8Array>,
@@ -3164,6 +3211,7 @@ async function handleExecServerMessage(
3164
3211
  case "mcpArgs": {
3165
3212
  const args = execMsg.message.value;
3166
3213
  const mcpCall = decodeMcpCall(args);
3214
+ synthesizeCursorExecToolCall(output, stream, mcpCall.toolCallId, mcpCall.toolName, mcpCall.args);
3167
3215
  const { execResult } = await resolveExecHandler(
3168
3216
  mcpCall,
3169
3217
  execHandlers?.mcp?.bind(execHandlers),
@@ -4063,17 +4111,6 @@ function decodeMcpArgValue(value: Uint8Array): unknown {
4063
4111
  return parseToolArgsJson(text);
4064
4112
  }
4065
4113
 
4066
- function decodeMcpArgsMap(args?: Record<string, Uint8Array>): Record<string, unknown> | undefined {
4067
- if (!args) {
4068
- return undefined;
4069
- }
4070
- const decoded: Record<string, unknown> = {};
4071
- for (const [key, value] of Object.entries(args)) {
4072
- decoded[key] = decodeMcpArgValue(value);
4073
- }
4074
- return decoded;
4075
- }
4076
-
4077
4114
  function decodeMcpCall(args: {
4078
4115
  name: string;
4079
4116
  args: Record<string, Uint8Array>;
@@ -4089,7 +4126,7 @@ function decodeMcpCall(args: {
4089
4126
  name: args.name,
4090
4127
  providerIdentifier: args.providerIdentifier,
4091
4128
  toolName: args.toolName || args.name,
4092
- toolCallId: args.toolCallId,
4129
+ toolCallId: args.toolCallId || crypto.randomUUID(),
4093
4130
  args: decodedArgs,
4094
4131
  rawArgs: args.args ?? {},
4095
4132
  };
@@ -4336,7 +4373,7 @@ const CURSOR_EXEC_OWNED_TOOL_CASES = new Set([
4336
4373
  ]);
4337
4374
 
4338
4375
  function isExecOwnedToolCall(toolCall: any): boolean {
4339
- return CURSOR_EXEC_OWNED_TOOL_CASES.has(toolCall?.tool?.case);
4376
+ return !!selectMcpToolCall(toolCall) || CURSOR_EXEC_OWNED_TOOL_CASES.has(toolCall?.tool?.case);
4340
4377
  }
4341
4378
 
4342
4379
  export function buildNativeToolCallBlock(
@@ -4358,6 +4395,7 @@ export function buildNativeToolCallBlock(
4358
4395
  : { raw: convertedArgs },
4359
4396
  index,
4360
4397
  kind: "native",
4398
+ [kProviderResolvedToolCall]: true,
4361
4399
  };
4362
4400
  }
4363
4401
  for (const [key, payload] of Object.entries(toolCall)) {
@@ -4380,6 +4418,7 @@ export function buildNativeToolCallBlock(
4380
4418
  arguments: safeArguments,
4381
4419
  index,
4382
4420
  kind: "native",
4421
+ [kProviderResolvedToolCall]: true,
4383
4422
  };
4384
4423
  }
4385
4424
  return null;
@@ -4445,6 +4484,7 @@ function synthesizeCursorExecToolCall(
4445
4484
  name: string,
4446
4485
  args: Record<string, unknown>,
4447
4486
  ): void {
4487
+ if (output.content.some(block => block.type === "toolCall" && block.id === toolCallId)) return;
4448
4488
  const block: ToolCallState = {
4449
4489
  type: "toolCall",
4450
4490
  id: toolCallId,
@@ -4518,33 +4558,19 @@ function processInteractionUpdate(
4518
4558
  state.setThinkingBlock(null);
4519
4559
  }
4520
4560
  } else if (updateCase === "toolCallStarted" && isExecOwnedToolCall(update.message.value.toolCall)) {
4521
- // Pi stream call IDs and exec IDs are distinct namespaces; without a shared
4522
- // correlation field, suppress the streamed variant and synthesize from exec.
4561
+ // Exec owns MCP and Pi tools. Suppress interaction announcements and
4562
+ // synthesize canonical, provider-resolved blocks before executing them.
4523
4563
  log("exec", "streamedToolCallOwnedByExec", { case: update.message.value.toolCall?.tool?.case });
4524
4564
  } else if (updateCase === "toolCallStarted") {
4525
4565
  const toolCall = update.message.value.toolCall;
4526
4566
  if (toolCall) {
4527
- const mcpCall = selectMcpToolCall(toolCall);
4528
- if (mcpCall) {
4529
- const args = mcpCall.args || {};
4530
- const block: ToolCallState = {
4531
- type: "toolCall",
4532
- id: args.toolCallId || crypto.randomUUID(),
4533
- name: args.name || args.toolName || "",
4534
- arguments: {},
4535
- index: output.content.length,
4536
- partialJson: "",
4537
- kind: "mcp",
4538
- };
4539
- output.content.push(block);
4540
- state.setToolCall(block);
4541
- stream.push({ type: "toolcall_start", contentIndex: output.content.length - 1, partial: output });
4542
- return;
4543
- }
4567
+ const callId = update.message.value.callId || crypto.randomUUID();
4568
+ // Repeated announcements describe the same provider-owned execution.
4569
+ if (output.content.some(block => block.type === "toolCall" && block.id === callId)) return;
4544
4570
 
4545
4571
  const todoArgs = buildTodoWriteArgs(toolCall);
4546
4572
  if (todoArgs) {
4547
- const callId = update.message.value.callId || crypto.randomUUID();
4573
+ // Cursor owns its todo state; this snapshot is for display, not local { ops } dispatch.
4548
4574
  const block: ToolCallState = {
4549
4575
  type: "toolCall",
4550
4576
  id: callId,
@@ -4552,6 +4578,7 @@ function processInteractionUpdate(
4552
4578
  arguments: todoArgs,
4553
4579
  index: output.content.length,
4554
4580
  kind: "todo_write",
4581
+ [kProviderResolvedToolCall]: true,
4555
4582
  };
4556
4583
  output.content.push(block);
4557
4584
  state.setToolCall(block);
@@ -4562,44 +4589,26 @@ function processInteractionUpdate(
4562
4589
  // Fallback: cursor-native tool variants (shell/glob/grep/…) we don't model
4563
4590
  // explicitly. Render them so the call and its result are visible instead of
4564
4591
  // vanishing.
4565
- const nativeBlock = buildNativeToolCallBlock(
4566
- toolCall,
4567
- update.message.value.callId || crypto.randomUUID(),
4568
- output.content.length,
4569
- );
4592
+ const nativeBlock = buildNativeToolCallBlock(toolCall, callId, output.content.length);
4570
4593
  if (nativeBlock) {
4571
4594
  output.content.push(nativeBlock);
4572
4595
  state.setToolCall(nativeBlock);
4573
4596
  stream.push({ type: "toolcall_start", contentIndex: output.content.length - 1, partial: output });
4574
4597
  }
4575
4598
  }
4576
- } else if (updateCase === "toolCallDelta" || updateCase === "partialToolCall") {
4577
- if (state.currentToolCall?.kind === "mcp") {
4578
- const delta = update.message.value.argsTextDelta || "";
4579
- state.currentToolCall.partialJson = `${state.currentToolCall.partialJson ?? ""}${delta}`;
4580
- state.currentToolCall.arguments = parseStreamingJson(state.currentToolCall.partialJson ?? "");
4581
- const idx = output.content.indexOf(state.currentToolCall);
4582
- stream.push({ type: "toolcall_delta", contentIndex: idx, delta, partial: output });
4583
- }
4584
4599
  } else if (updateCase === "toolCallCompleted") {
4600
+ if (isExecOwnedToolCall(update.message.value.toolCall)) return;
4585
4601
  if (state.currentToolCall) {
4586
4602
  const toolCall = update.message.value.toolCall;
4587
- if (state.currentToolCall.kind === "mcp") {
4588
- captureUnicodeEscapeEvidence(state.currentToolCall, state.currentToolCall.partialJson ?? "");
4589
- const decodedArgs = decodeMcpArgsMap(selectMcpToolCall(toolCall)?.args?.args);
4590
- if (decodedArgs) {
4591
- state.currentToolCall.arguments = decodedArgs;
4592
- }
4593
- } else if (state.currentToolCall.kind === "todo_write" && toolCall) {
4603
+ if (state.currentToolCall.kind === "todo_write" && toolCall) {
4594
4604
  const todoArgs = buildTodoWriteArgs(toolCall);
4595
4605
  if (todoArgs) {
4596
4606
  state.currentToolCall.arguments = todoArgs;
4597
4607
  }
4598
4608
  }
4599
4609
  const idx = output.content.indexOf(state.currentToolCall);
4600
- delete (state.currentToolCall as any).partialJson;
4601
- delete (state.currentToolCall as any).index;
4602
- delete (state.currentToolCall as any).kind;
4610
+ delete (state.currentToolCall as Partial<ToolCallState>).index;
4611
+ delete (state.currentToolCall as Partial<ToolCallState>).kind;
4603
4612
  stream.push({ type: "toolcall_end", contentIndex: idx, toolCall: state.currentToolCall, partial: output });
4604
4613
  state.setToolCall(null);
4605
4614
  }
@@ -5,6 +5,7 @@ export declare function kiroApiRegion(options?: {
5
5
  }): string;
6
6
  export declare function kiroApiBaseUrl(region: string): string;
7
7
  export declare function toKiroModelId(modelId: string): string;
8
+ export declare function sanitizeKiroError(value: unknown, secret?: string): string;
8
9
  export declare function kiroApiStaticModels(): Model<"kiro-codewhisperer-stream">[];
9
10
  /** Discover models this API key can use. Returns null when the key is missing. */
10
11
  export declare function fetchKiroApiModels(apiKey: string, region?: string): Promise<Model<"kiro-codewhisperer-stream">[]>;
@@ -118,7 +118,7 @@ function kiroApiHeaders(apiKey: string, target: string): Record<string, string>
118
118
  };
119
119
  }
120
120
 
121
- function sanitizeKiroError(value: unknown, secret?: string): string {
121
+ export function sanitizeKiroError(value: unknown, secret?: string): string {
122
122
  let message = value instanceof Error ? value.message : String(value);
123
123
  if (secret) message = message.split(secret).join("[redacted]");
124
124
  message = message.replace(/bearer\s+[^\s,;]+/gi, "Bearer [redacted]");