@sayknow-cli/ai 0.4.2 → 0.4.3

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 (186) hide show
  1. package/dist/types/api-registry.d.ts +30 -0
  2. package/dist/types/auth-broker/client.d.ts +67 -0
  3. package/dist/types/auth-broker/index.d.ts +5 -0
  4. package/dist/types/auth-broker/refresher.d.ts +25 -0
  5. package/dist/types/auth-broker/remote-store.d.ts +99 -0
  6. package/dist/types/auth-broker/server.d.ts +32 -0
  7. package/dist/types/auth-broker/types.d.ts +110 -0
  8. package/dist/types/auth-broker/wire-schemas.d.ts +443 -0
  9. package/dist/types/auth-gateway/http.d.ts +40 -0
  10. package/dist/types/auth-gateway/index.d.ts +3 -0
  11. package/dist/types/auth-gateway/server.d.ts +36 -0
  12. package/dist/types/auth-gateway/types.d.ts +115 -0
  13. package/dist/types/auth-storage.d.ts +699 -0
  14. package/dist/types/cli.d.ts +2 -0
  15. package/dist/types/context-cap-policy.d.ts +10 -0
  16. package/dist/types/index.d.ts +53 -0
  17. package/dist/types/model-cache.d.ts +19 -0
  18. package/dist/types/model-manager.d.ts +64 -0
  19. package/dist/types/model-retirements.d.ts +6 -0
  20. package/dist/types/model-thinking.d.ts +74 -0
  21. package/dist/types/models.d.ts +21 -0
  22. package/dist/types/provider-details.d.ts +24 -0
  23. package/dist/types/provider-models/bundled-references.d.ts +4 -0
  24. package/dist/types/provider-models/descriptors.d.ts +48 -0
  25. package/dist/types/provider-models/google.d.ts +20 -0
  26. package/dist/types/provider-models/index.d.ts +5 -0
  27. package/dist/types/provider-models/ollama.d.ts +7 -0
  28. package/dist/types/provider-models/openai-compat.d.ts +256 -0
  29. package/dist/types/provider-models/special.d.ts +19 -0
  30. package/dist/types/providers/amazon-bedrock.d.ts +60 -0
  31. package/dist/types/providers/anthropic-messages-server-schema.d.ts +450 -0
  32. package/dist/types/providers/anthropic-messages-server.d.ts +17 -0
  33. package/dist/types/providers/anthropic.d.ts +209 -0
  34. package/dist/types/providers/aws-credential-config.d.ts +19 -0
  35. package/dist/types/providers/aws-credentials.d.ts +43 -0
  36. package/dist/types/providers/aws-eventstream.d.ts +38 -0
  37. package/dist/types/providers/aws-sigv4.d.ts +55 -0
  38. package/dist/types/providers/azure-openai-responses.d.ts +15 -0
  39. package/dist/types/providers/composer-discipline.d.ts +26 -0
  40. package/dist/types/providers/cursor/client-version.d.ts +10 -0
  41. package/dist/types/providers/cursor/gen/agent_pb.d.ts +13022 -0
  42. package/dist/types/providers/cursor.d.ts +45 -0
  43. package/dist/types/providers/error-message.d.ts +27 -0
  44. package/dist/types/providers/github-copilot-headers.d.ts +40 -0
  45. package/dist/types/providers/gitlab-duo.d.ts +27 -0
  46. package/dist/types/providers/google-auth.d.ts +24 -0
  47. package/dist/types/providers/google-gemini-cli.d.ts +75 -0
  48. package/dist/types/providers/google-gemini-headers.d.ts +43 -0
  49. package/dist/types/providers/google-shared.d.ts +179 -0
  50. package/dist/types/providers/google-types.d.ts +138 -0
  51. package/dist/types/providers/google-vertex.d.ts +7 -0
  52. package/dist/types/providers/google.d.ts +4 -0
  53. package/dist/types/providers/grammar.d.ts +1 -0
  54. package/dist/types/providers/kimi.d.ts +27 -0
  55. package/dist/types/providers/mock.d.ts +177 -0
  56. package/dist/types/providers/ollama.d.ts +41 -0
  57. package/dist/types/providers/openai-anthropic-shim.d.ts +31 -0
  58. package/dist/types/providers/openai-bounded-rate-limits.d.ts +3 -0
  59. package/dist/types/providers/openai-chat-server-schema.d.ts +815 -0
  60. package/dist/types/providers/openai-chat-server.d.ts +16 -0
  61. package/dist/types/providers/openai-codex/constants.d.ts +26 -0
  62. package/dist/types/providers/openai-codex/request-transformer.d.ts +50 -0
  63. package/dist/types/providers/openai-codex/response-handler.d.ts +18 -0
  64. package/dist/types/providers/openai-codex-responses.d.ts +68 -0
  65. package/dist/types/providers/openai-completions-compat.d.ts +27 -0
  66. package/dist/types/providers/openai-completions.d.ts +33 -0
  67. package/dist/types/providers/openai-request-transform.d.ts +4 -0
  68. package/dist/types/providers/openai-responses-server-schema.d.ts +392 -0
  69. package/dist/types/providers/openai-responses-server.d.ts +17 -0
  70. package/dist/types/providers/openai-responses-shared.d.ts +104 -0
  71. package/dist/types/providers/openai-responses.d.ts +32 -0
  72. package/dist/types/providers/pi-native-client.d.ts +13 -0
  73. package/dist/types/providers/pi-native-server.d.ts +60 -0
  74. package/dist/types/providers/register-builtins.d.ts +31 -0
  75. package/dist/types/providers/synthetic.d.ts +26 -0
  76. package/dist/types/providers/transform-messages.d.ts +14 -0
  77. package/dist/types/providers/vision-guard.d.ts +8 -0
  78. package/dist/types/rate-limit-utils.d.ts +19 -0
  79. package/dist/types/stream.d.ts +43 -0
  80. package/dist/types/types.d.ts +882 -0
  81. package/dist/types/usage/claude.d.ts +3 -0
  82. package/dist/types/usage/gemini.d.ts +2 -0
  83. package/dist/types/usage/github-copilot.d.ts +7 -0
  84. package/dist/types/usage/google-antigravity.d.ts +2 -0
  85. package/dist/types/usage/grok-cli.d.ts +10 -0
  86. package/dist/types/usage/kimi.d.ts +2 -0
  87. package/dist/types/usage/minimax-code.d.ts +2 -0
  88. package/dist/types/usage/openai-codex.d.ts +3 -0
  89. package/dist/types/usage/shared.d.ts +1 -0
  90. package/dist/types/usage/zai.d.ts +2 -0
  91. package/dist/types/usage.d.ts +258 -0
  92. package/dist/types/utils/abort.d.ts +19 -0
  93. package/dist/types/utils/anthropic-auth.d.ts +31 -0
  94. package/dist/types/utils/discovery/antigravity.d.ts +67 -0
  95. package/dist/types/utils/discovery/codex.d.ts +38 -0
  96. package/dist/types/utils/discovery/cursor.d.ts +23 -0
  97. package/dist/types/utils/discovery/gemini.d.ts +25 -0
  98. package/dist/types/utils/discovery/index.d.ts +4 -0
  99. package/dist/types/utils/discovery/openai-compatible.d.ts +74 -0
  100. package/dist/types/utils/event-stream.d.ts +39 -0
  101. package/dist/types/utils/fallback-transport.d.ts +66 -0
  102. package/dist/types/utils/fireworks-model-id.d.ts +10 -0
  103. package/dist/types/utils/foundry.d.ts +1 -0
  104. package/dist/types/utils/h2-fetch.d.ts +22 -0
  105. package/dist/types/utils/http-inspector.d.ts +35 -0
  106. package/dist/types/utils/idle-iterator.d.ts +67 -0
  107. package/dist/types/utils/json-parse.d.ts +18 -0
  108. package/dist/types/utils/oauth/alibaba-coding-plan.d.ts +18 -0
  109. package/dist/types/utils/oauth/anthropic.d.ts +22 -0
  110. package/dist/types/utils/oauth/api-key-login.d.ts +35 -0
  111. package/dist/types/utils/oauth/api-key-validation.d.ts +27 -0
  112. package/dist/types/utils/oauth/callback-server.d.ts +60 -0
  113. package/dist/types/utils/oauth/cerebras.d.ts +1 -0
  114. package/dist/types/utils/oauth/cloudflare-ai-gateway.d.ts +18 -0
  115. package/dist/types/utils/oauth/cursor.d.ts +15 -0
  116. package/dist/types/utils/oauth/deepinfra.d.ts +1 -0
  117. package/dist/types/utils/oauth/deepseek.d.ts +10 -0
  118. package/dist/types/utils/oauth/firepass.d.ts +1 -0
  119. package/dist/types/utils/oauth/fireworks.d.ts +1 -0
  120. package/dist/types/utils/oauth/fugu.d.ts +1 -0
  121. package/dist/types/utils/oauth/github-copilot.d.ts +38 -0
  122. package/dist/types/utils/oauth/gitlab-duo.d.ts +3 -0
  123. package/dist/types/utils/oauth/glm-zcode.d.ts +71 -0
  124. package/dist/types/utils/oauth/google-antigravity.d.ts +11 -0
  125. package/dist/types/utils/oauth/google-gemini-cli.d.ts +10 -0
  126. package/dist/types/utils/oauth/google-oauth-shared.d.ts +28 -0
  127. package/dist/types/utils/oauth/huggingface.d.ts +19 -0
  128. package/dist/types/utils/oauth/index.d.ts +39 -0
  129. package/dist/types/utils/oauth/kagi.d.ts +17 -0
  130. package/dist/types/utils/oauth/kilo.d.ts +5 -0
  131. package/dist/types/utils/oauth/kimi.d.ts +21 -0
  132. package/dist/types/utils/oauth/litellm.d.ts +18 -0
  133. package/dist/types/utils/oauth/lm-studio.d.ts +17 -0
  134. package/dist/types/utils/oauth/minimax-code.d.ts +28 -0
  135. package/dist/types/utils/oauth/moonshot.d.ts +1 -0
  136. package/dist/types/utils/oauth/nanogpt.d.ts +1 -0
  137. package/dist/types/utils/oauth/nvidia.d.ts +18 -0
  138. package/dist/types/utils/oauth/ollama-cloud.d.ts +2 -0
  139. package/dist/types/utils/oauth/ollama.d.ts +18 -0
  140. package/dist/types/utils/oauth/openai-codex.d.ts +21 -0
  141. package/dist/types/utils/oauth/opencode.d.ts +18 -0
  142. package/dist/types/utils/oauth/parallel.d.ts +17 -0
  143. package/dist/types/utils/oauth/perplexity.d.ts +9 -0
  144. package/dist/types/utils/oauth/pkce.d.ts +8 -0
  145. package/dist/types/utils/oauth/qianfan.d.ts +17 -0
  146. package/dist/types/utils/oauth/qwen-portal.d.ts +19 -0
  147. package/dist/types/utils/oauth/synthetic.d.ts +1 -0
  148. package/dist/types/utils/oauth/tavily.d.ts +17 -0
  149. package/dist/types/utils/oauth/together.d.ts +1 -0
  150. package/dist/types/utils/oauth/types.d.ts +45 -0
  151. package/dist/types/utils/oauth/venice.d.ts +18 -0
  152. package/dist/types/utils/oauth/vercel-ai-gateway.d.ts +18 -0
  153. package/dist/types/utils/oauth/vllm.d.ts +16 -0
  154. package/dist/types/utils/oauth/xai.d.ts +30 -0
  155. package/dist/types/utils/oauth/xiaomi.d.ts +25 -0
  156. package/dist/types/utils/oauth/zai.d.ts +18 -0
  157. package/dist/types/utils/oauth/zenmux.d.ts +1 -0
  158. package/dist/types/utils/overflow.d.ts +14 -0
  159. package/dist/types/utils/parse-bind.d.ts +23 -0
  160. package/dist/types/utils/provider-response.d.ts +3 -0
  161. package/dist/types/utils/retry-after.d.ts +3 -0
  162. package/dist/types/utils/retry-budget.d.ts +1 -0
  163. package/dist/types/utils/retry.d.ts +27 -0
  164. package/dist/types/utils/schema/adapt.d.ts +24 -0
  165. package/dist/types/utils/schema/compatibility.d.ts +30 -0
  166. package/dist/types/utils/schema/dereference.d.ts +11 -0
  167. package/dist/types/utils/schema/draft.d.ts +10 -0
  168. package/dist/types/utils/schema/equality.d.ts +4 -0
  169. package/dist/types/utils/schema/fields.d.ts +49 -0
  170. package/dist/types/utils/schema/index.d.ts +14 -0
  171. package/dist/types/utils/schema/json-schema-validator.d.ts +12 -0
  172. package/dist/types/utils/schema/meta-validator.d.ts +2 -0
  173. package/dist/types/utils/schema/normalize.d.ts +93 -0
  174. package/dist/types/utils/schema/root-combinator.d.ts +12 -0
  175. package/dist/types/utils/schema/spill.d.ts +8 -0
  176. package/dist/types/utils/schema/stamps.d.ts +25 -0
  177. package/dist/types/utils/schema/types.d.ts +4 -0
  178. package/dist/types/utils/schema/wire.d.ts +54 -0
  179. package/dist/types/utils/schema/zod-decontaminate.d.ts +31 -0
  180. package/dist/types/utils/sse-debug.d.ts +10 -0
  181. package/dist/types/utils/tool-call-healing.d.ts +71 -0
  182. package/dist/types/utils/tool-choice-capability.d.ts +41 -0
  183. package/dist/types/utils/tool-choice.d.ts +50 -0
  184. package/dist/types/utils/validation.d.ts +17 -0
  185. package/dist/types/utils.d.ts +89 -0
  186. package/package.json +25 -24
@@ -0,0 +1,209 @@
1
+ import Anthropic, { type ClientOptions as AnthropicSdkClientOptions } from "@anthropic-ai/sdk";
2
+ import type { MessageCreateParamsStreaming, MessageParam } from "@anthropic-ai/sdk/resources/messages";
3
+ import type { FetchImpl, Message, Model, ProviderSessionState, ServiceTier, SimpleStreamOptions, StreamFunction, StreamOptions, Usage } from "../types";
4
+ export type AnthropicHeaderOptions = {
5
+ apiKey: string;
6
+ baseUrl?: string;
7
+ isOAuth?: boolean;
8
+ extraBetas?: string[];
9
+ stream?: boolean;
10
+ modelHeaders?: Record<string, string>;
11
+ isCloudflareAiGateway?: boolean;
12
+ /**
13
+ * Attach ZCode client "source" headers (User-Agent: ZCode/<ver>, X-Title,
14
+ * X-ZCode-Agent: glm, X-Platform, etc.) so api.z.ai recognizes the caller as
15
+ * the ZCode client, exactly like ZCode's `buildZCodeSourceHeaders` does for
16
+ * GLM providers. glm-zcode only.
17
+ */
18
+ zcodeSourceHeaders?: boolean;
19
+ };
20
+ export declare function normalizeAnthropicBaseUrl(baseUrl?: string): string | undefined;
21
+ export declare function buildBetaHeader(baseBetas: string[], extraBetas: string[]): string;
22
+ /**
23
+ * Replicates ZCode's `buildZCodeSourceHeaders()` + GLM `X-ZCode-Agent` tag
24
+ * (host bundle `Bl` / `buildConnectivitySourceHeaders` for GLM providers), so
25
+ * api.z.ai sees skc's glm-zcode requests as the ZCode client. Dynamic values
26
+ * (platform/arch, locale, timezone, OS version) are resolved at runtime exactly
27
+ * as ZCode does; printable-ASCII-only and conditionally omitted when empty.
28
+ */
29
+ export declare function buildZCodeSourceHeaders(): Record<string, string>;
30
+ export declare function buildAnthropicHeaders(options: AnthropicHeaderOptions): Record<string, string>;
31
+ type AnthropicCacheControl = {
32
+ type: "ephemeral";
33
+ ttl?: "1h" | "5m";
34
+ };
35
+ /**
36
+ * Clears the in-session "server rejected fast mode" sticky flag. Call when the
37
+ * caller is explicitly re-arming `serviceTier: "priority"` (e.g. user toggled
38
+ * `/fast on` after a previous turn auto-disabled it) so the next request
39
+ * actually carries `speed: "fast"` again. No-op when the map or state entry
40
+ * hasn't been materialized yet.
41
+ */
42
+ export declare function clearAnthropicFastModeFallback(providerSessionState: Map<string, ProviderSessionState> | undefined): void;
43
+ export declare function isAnthropicFastModeUnsupportedError(error: unknown): boolean;
44
+ export declare function isAnthropicThinkingBlockMutationError(error: unknown): boolean;
45
+ export declare const claudeCodeVersion = "2.1.63";
46
+ export declare const claudeToolPrefix: string;
47
+ export declare const claudeCodeSystemInstruction = "You are a Claude agent, built on Anthropic's Claude Agent SDK.";
48
+ export declare function mapStainlessOs(platform: string): "MacOS" | "Windows" | "Linux" | "FreeBSD" | `Other::${string}`;
49
+ export declare function mapStainlessArch(arch: string): "x64" | "arm64" | "x86" | `other::${string}`;
50
+ export declare const claudeCodeHeaders: {
51
+ readonly "X-Stainless-Retry-Count": "0";
52
+ readonly "X-Stainless-Runtime-Version": "v24.3.0";
53
+ readonly "X-Stainless-Package-Version": "0.74.0";
54
+ readonly "X-Stainless-Runtime": "node";
55
+ readonly "X-Stainless-Lang": "js";
56
+ readonly "X-Stainless-Arch": "arm64" | "x64" | "x86" | `other::${string}`;
57
+ readonly "X-Stainless-Os": "MacOS" | "Windows" | "Linux" | "FreeBSD" | `Other::${string}`;
58
+ readonly "X-Stainless-Timeout": "600";
59
+ };
60
+ export declare function isClaudeCloakingUserId(userId: string): boolean;
61
+ export declare function generateClaudeCloakingUserId(): string;
62
+ export declare const applyClaudeToolPrefix: (name: string, prefixOverride?: string) => string;
63
+ export declare const stripClaudeToolPrefix: (name: string, prefixOverride?: string) => string;
64
+ export type AnthropicEffort = "low" | "medium" | "high" | "xhigh" | "max";
65
+ export type AnthropicThinkingDisplay = "summarized" | "omitted";
66
+ export interface AnthropicOptions extends StreamOptions {
67
+ /**
68
+ * Enable extended thinking.
69
+ * For Opus 4.6+: uses adaptive thinking (Anthropic model decides when/how much to think).
70
+ * For older models: uses budget-based thinking with thinkingBudgetTokens.
71
+ */
72
+ thinkingEnabled?: boolean;
73
+ /**
74
+ * Token budget for extended thinking (older models only).
75
+ * Ignored for Opus 4.6+ which uses adaptive thinking.
76
+ */
77
+ thinkingBudgetTokens?: number;
78
+ /**
79
+ * Effort level for adaptive thinking (Opus 4.6+ only).
80
+ * Controls how much thinking Anthropic model allocates:
81
+ * - "max": Always thinks with no constraints
82
+ * - "high": Always thinks, deep reasoning (default)
83
+ * - "medium": Moderate thinking, may skip for simple queries
84
+ * - "low": Minimal thinking, skips for simple tasks
85
+ * Ignored for older models.
86
+ */
87
+ effort?: AnthropicEffort;
88
+ /**
89
+ * Optional reasoning level fallback for direct Anthropic provider usage.
90
+ * Converted to adaptive effort when effort is not explicitly provided.
91
+ */
92
+ reasoning?: SimpleStreamOptions["reasoning"];
93
+ /**
94
+ * Controls how Anthropic returns thinking content when the selected thinking
95
+ * transport supports a display option. Defaults to "summarized" where the
96
+ * API accepts it.
97
+ */
98
+ thinkingDisplay?: AnthropicThinkingDisplay;
99
+ interleavedThinking?: boolean;
100
+ toolChoice?: "auto" | "any" | "none" | {
101
+ type: "tool";
102
+ name: string;
103
+ };
104
+ betas?: string[] | string;
105
+ /**
106
+ * Realization of `serviceTier: "priority"` on Anthropic models. When
107
+ * `"priority"`, sets `speed: "fast"` on the request and appends the
108
+ * `fast-mode-2026-02-01` beta header. Anthropic rejects unsupported models
109
+ * with `invalid_request_error`, which triggers an in-provider one-shot
110
+ * fallback (see `fastModeDisabled` provider state).
111
+ *
112
+ * Other `ServiceTier` values are currently ignored on this provider.
113
+ */
114
+ serviceTier?: ServiceTier;
115
+ /** Force OAuth bearer auth mode for proxy tokens that don't match Anthropic token prefixes. */
116
+ isOAuth?: boolean;
117
+ /**
118
+ * Pre-built Anthropic client instance. When provided, skips internal client
119
+ * construction entirely. Use this to inject alternative SDK clients such as
120
+ * `AnthropicVertex` that shares the same messaging API.
121
+ */
122
+ client?: Anthropic;
123
+ }
124
+ export type AnthropicClientOptionsArgs = {
125
+ model: Model<"anthropic-messages">;
126
+ apiKey: string;
127
+ extraBetas?: string[];
128
+ stream?: boolean;
129
+ interleavedThinking?: boolean;
130
+ headers?: Record<string, string>;
131
+ dynamicHeaders?: Record<string, string>;
132
+ isOAuth?: boolean;
133
+ hasTools?: boolean;
134
+ onSseEvent?: AnthropicOptions["onSseEvent"];
135
+ fetch?: FetchImpl;
136
+ requestMaxRetries?: number;
137
+ maxRetryDelayMs?: number;
138
+ };
139
+ export type AnthropicClientOptionsResult = {
140
+ isOAuthToken: boolean;
141
+ apiKey: string | null;
142
+ authToken?: string | null;
143
+ baseURL?: string;
144
+ maxRetries: number;
145
+ dangerouslyAllowBrowser: boolean;
146
+ defaultHeaders: Record<string, string>;
147
+ logLevel: AnthropicSdkClientOptions["logLevel"];
148
+ fetch?: AnthropicSdkClientOptions["fetch"];
149
+ fetchOptions?: AnthropicSdkClientOptions["fetchOptions"];
150
+ };
151
+ export declare function isProviderRetryableError(error: unknown, provider?: string): boolean;
152
+ export type AnthropicUsageLike = {
153
+ cache_creation?: {
154
+ ephemeral_5m_input_tokens?: number | null;
155
+ ephemeral_1h_input_tokens?: number | null;
156
+ } | null;
157
+ server_tool_use?: {
158
+ web_search_requests?: number | null;
159
+ web_fetch_requests?: number | null;
160
+ } | null;
161
+ };
162
+ /**
163
+ * Capture Anthropic's optional cache-creation TTL breakdown and server-tool-use
164
+ * counters into the harness Usage shape. Only sets fields that were reported, so
165
+ * a `message_delta` that omits `cache_creation` does not clobber the breakdown
166
+ * established at `message_start`.
167
+ */
168
+ export declare function applyAnthropicUsageExtras(usage: Usage, source: AnthropicUsageLike): void;
169
+ export declare const streamAnthropic: StreamFunction<"anthropic-messages">;
170
+ export type AnthropicSystemBlock = {
171
+ type: "text";
172
+ text: string;
173
+ cache_control?: AnthropicCacheControl;
174
+ };
175
+ type SystemBlockOptions = {
176
+ includeClaudeCodeInstruction?: boolean;
177
+ extraInstructions?: string[];
178
+ billingPayload?: unknown;
179
+ cacheControl?: AnthropicCacheControl;
180
+ };
181
+ export declare function buildAnthropicSystemBlocks(systemPrompt: readonly string[] | undefined, options?: SystemBlockOptions): AnthropicSystemBlock[] | undefined;
182
+ export declare function normalizeExtraBetas(betas?: string[] | string): string[];
183
+ export declare function buildAnthropicClientOptions(args: AnthropicClientOptionsArgs): AnthropicClientOptionsResult;
184
+ export declare function normalizeCacheControlTtlOrdering(params: MessageCreateParamsStreaming): void;
185
+ export declare function convertAnthropicMessages(messages: Message[], model: Model<"anthropic-messages">, isOAuthToken: boolean, options?: {
186
+ repairLatestAssistantThinking?: boolean;
187
+ }): MessageParam[];
188
+ /**
189
+ * Normalize a JSON Schema node for Anthropic tool `input_schema`.
190
+ *
191
+ * Applies the full whitelist semantics from the Anthropic Python SDK's
192
+ * `lib/_parse/_transform.py::transform_schema`:
193
+ *
194
+ * 1. Universal keys (`$ref`, `$defs`, `type`, `anyOf`/`oneOf`/`allOf`, `enum`, `const`,
195
+ * `description`, `title`, `default`, `nullable`) are preserved on every node.
196
+ * 2. Per-type keys are kept additively (object → `properties`/`required`/`additionalProperties`,
197
+ * array → `items`/`prefixItems` plus `minItems` only when 0 or 1, string → `format`
198
+ * only when in the supported value set).
199
+ * 3. Everything else is demoted into the node's `description` as `\n\n{key: value, ...}`
200
+ * so the model still sees the constraint as a natural-language hint.
201
+ *
202
+ * Object nodes default to `additionalProperties: false`, but explicit open-map
203
+ * declarations (`additionalProperties: true` or a schema literal — Zod's
204
+ * `z.record(z.string(), z.unknown())` produces `{}`) are preserved. The strict-mode
205
+ * pass downstream demotes those shapes to non-strict instead of fabricating a closed
206
+ * object, so callers like the resolve tool keep working open-map semantics.
207
+ */
208
+ export declare function normalizeAnthropicToolSchema(schema: unknown): unknown;
209
+ export {};
@@ -0,0 +1,19 @@
1
+ import type { AwsCredentials } from "./aws-sigv4";
2
+ export type AwsIniFile = Record<string, Record<string, string>>;
3
+ export interface AwsCredentialSourceOptions {
4
+ profile?: string;
5
+ }
6
+ export interface AwsCredentialSource {
7
+ profile: string;
8
+ credentialsPath: string;
9
+ configPath: string;
10
+ }
11
+ export type AwsProfileCapability = "static" | "process" | "sso" | undefined;
12
+ export declare function parseAwsIni(text: string): AwsIniFile;
13
+ export declare function resolveAwsCredentialSource(options?: AwsCredentialSourceOptions): AwsCredentialSource;
14
+ export declare function readAwsStaticEnvironmentCredentials(): AwsCredentials | undefined;
15
+ export declare function classifyAwsProfileCapability(profile: string, credentialsIni: AwsIniFile | undefined, configIni: AwsIniFile | undefined): AwsProfileCapability;
16
+ export declare function hasResolvableAwsProfileSource(options?: AwsCredentialSourceOptions & {
17
+ onScan?: () => void;
18
+ }, now?: number): boolean;
19
+ export declare function isValidBedrockBearerToken(token: string | undefined): token is string;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * AWS credential resolution for the Bedrock provider.
3
+ *
4
+ * Chain (first hit wins):
5
+ * 1. Static credentials from the environment
6
+ * (`AWS_ACCESS_KEY_ID` + `AWS_SECRET_ACCESS_KEY` [+ `AWS_SESSION_TOKEN`]).
7
+ * 2. Profile in `~/.aws/credentials` (and `~/.aws/config` for SSO):
8
+ * - static `aws_access_key_id` / `aws_secret_access_key` / `aws_session_token`
9
+ * - SSO profile referencing a cached token in `~/.aws/sso/cache/*.json`,
10
+ * which we exchange for short-lived role credentials via
11
+ * `https://portal.sso.{region}.amazonaws.com/federation/credentials`.
12
+ * - `credential_process` — an external command emitting the AWS SDK
13
+ * `Version: 1` JSON envelope on stdout. Used by `aws-vault`, `granted`,
14
+ * in-house brokers, etc.
15
+ * 3. EC2 IMDSv2 (only when `AWS_EC2_METADATA_DISABLED` is unset / falsey and
16
+ * `169.254.169.254` is reachable within a 1 s timeout).
17
+ *
18
+ * Resolved credentials are cached process-wide per profile and refreshed
19
+ * 60 s before `Expiration` to absorb clock skew.
20
+ */
21
+ import type { AwsCredentials } from "./aws-sigv4";
22
+ export interface ResolvedCredentials extends AwsCredentials {
23
+ /** Absolute expiration timestamp in ms. `undefined` for non-expiring static creds. */
24
+ expiresAt?: number;
25
+ }
26
+ export interface CredentialResolveOptions {
27
+ /** Named profile from `~/.aws/credentials` / `~/.aws/config`. */
28
+ profile?: string;
29
+ /** Falls back to env (`AWS_REGION` / `AWS_DEFAULT_REGION`) and finally `us-east-1`. */
30
+ region?: string;
31
+ signal?: AbortSignal;
32
+ }
33
+ export declare function resolveAwsCredentials(opts?: CredentialResolveOptions): Promise<ResolvedCredentials>;
34
+ /** POSIX-shell-style tokenizer used by the AWS CLI for `credential_process`.
35
+ *
36
+ * Outside quotes a backslash escapes the next character. Inside single quotes
37
+ * everything is literal (no escapes, cannot contain `'`). Inside double quotes
38
+ * a backslash only escapes `$`, `` ` ``, `"`, and `\` — every other backslash
39
+ * is preserved verbatim, which is what makes Windows paths like
40
+ * `"C:\Program Files\tool\auth.exe"` survive tokenization. */
41
+ export declare function tokenizeCredentialProcessCommand(cmd: string): string[];
42
+ /** Test/diagnostic helper — drops cached credentials. */
43
+ export declare function clearAwsCredentialCache(): void;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * `application/vnd.amazon.eventstream` decoder.
3
+ *
4
+ * Wire format (all integers big-endian):
5
+ *
6
+ * [total length u32]
7
+ * [headers length u32]
8
+ * [prelude CRC32 u32] <- CRC over the first 8 bytes
9
+ * [headers headers_length]
10
+ * [payload total_length - headers_length - 16]
11
+ * [message CRC32 u32] <- CRC over the entire message minus the trailing 4 bytes
12
+ *
13
+ * Headers: a sequence of `[name_len u8][name utf8][value_type u8][value …]`.
14
+ * We only need the typed values Bedrock emits (boolean true/false, byte, short,
15
+ * integer, long, byte-array, string, timestamp, uuid). All are surfaced as
16
+ * strings for ease of consumption — Bedrock only sets string-valued headers in
17
+ * practice (`:event-type`, `:message-type`, `:content-type`, `:exception-type`).
18
+ */
19
+ export interface EventStreamMessage {
20
+ /** Lower-cased copy is *not* applied — Bedrock uses casing like `:event-type` verbatim. */
21
+ headers: Record<string, string>;
22
+ payload: Uint8Array;
23
+ }
24
+ export declare function crc32(bytes: Uint8Array, seed?: number): number;
25
+ /**
26
+ * Decode a single, fully buffered eventstream message. Throws if the framing is
27
+ * malformed or either CRC mismatches. Used by both `decodeEventStream` (the
28
+ * streaming entry point) and the unit tests, which exercise it with hand-built
29
+ * frames.
30
+ */
31
+ export declare function decodeMessage(frame: Uint8Array): EventStreamMessage;
32
+ /**
33
+ * Async generator that consumes a `ReadableStream<Uint8Array>` (e.g. a fetch
34
+ * response body) and yields fully-framed messages. Handles arbitrary chunk
35
+ * boundaries: messages may span multiple chunks, and a single chunk may carry
36
+ * many messages.
37
+ */
38
+ export declare function decodeEventStream(source: ReadableStream<Uint8Array>): AsyncGenerator<EventStreamMessage>;
@@ -0,0 +1,55 @@
1
+ /**
2
+ * AWS Signature V4 signing for HTTP requests. WebCrypto-only — no node:crypto.
3
+ *
4
+ * Matches `@smithy/signature-v4` for our usage: header-based signing with a
5
+ * full SHA-256 payload hash (Bedrock requires `applyChecksum: true`).
6
+ *
7
+ * Returns the set of headers to attach to the request:
8
+ * - `host`
9
+ * - `x-amz-date`
10
+ * - `x-amz-content-sha256`
11
+ * - `x-amz-security-token` (only when credentials carry a sessionToken)
12
+ * - `authorization`
13
+ */
14
+ export interface AwsCredentials {
15
+ accessKeyId: string;
16
+ secretAccessKey: string;
17
+ sessionToken?: string;
18
+ }
19
+ export interface SignParams {
20
+ method: string;
21
+ /** Hostname only — used to build the `host` header and the canonical request. */
22
+ host: string;
23
+ /** URI path component, e.g. `/model/anthropic.Anthropic model/converse-stream`. */
24
+ path: string;
25
+ /** Optional pre-built query string (without leading `?`). */
26
+ query?: string;
27
+ /** Extra headers to sign in addition to `host`/`x-amz-*`. Names are case-insensitive. */
28
+ headers?: Record<string, string>;
29
+ body: Uint8Array;
30
+ region: string;
31
+ service: string;
32
+ credentials: AwsCredentials;
33
+ /** Override clock for deterministic tests. */
34
+ date?: Date;
35
+ }
36
+ export declare function toHex(bytes: Uint8Array): string;
37
+ export declare function sha256(data: Uint8Array | string): Promise<Uint8Array>;
38
+ export declare function sha256Hex(data: Uint8Array | string): Promise<string>;
39
+ /**
40
+ * Derive a signing key: HMAC chain `kSecret → kDate → kRegion → kService → kSigning`.
41
+ */
42
+ export declare function getSigningKey(secretAccessKey: string, shortDate: string, region: string, service: string): Promise<Uint8Array>;
43
+ /** `YYYYMMDDTHHMMSSZ` + 8-char `YYYYMMDD`. */
44
+ export declare function formatAmzDate(d: Date): {
45
+ longDate: string;
46
+ shortDate: string;
47
+ };
48
+ export interface SignedHeaders {
49
+ host: string;
50
+ "x-amz-date": string;
51
+ "x-amz-content-sha256": string;
52
+ authorization: string;
53
+ "x-amz-security-token"?: string;
54
+ }
55
+ export declare function signRequest(params: SignParams): Promise<SignedHeaders>;
@@ -0,0 +1,15 @@
1
+ import type { ServiceTier, StreamFunction, StreamOptions, ToolChoice } from "../types";
2
+ export interface AzureOpenAIResponsesOptions extends StreamOptions {
3
+ reasoning?: "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
4
+ reasoningSummary?: "auto" | "detailed" | "concise" | null;
5
+ azureApiVersion?: string;
6
+ azureResourceName?: string;
7
+ azureBaseUrl?: string;
8
+ azureDeploymentName?: string;
9
+ toolChoice?: ToolChoice;
10
+ serviceTier?: ServiceTier;
11
+ }
12
+ /**
13
+ * Generate function for Azure OpenAI Responses API
14
+ */
15
+ export declare const streamAzureOpenAIResponses: StreamFunction<"azure-openai-responses">;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Anchor/edit discipline for composer-harness models (xai grok-composer-*,
3
+ * cursor composer-*).
4
+ *
5
+ * Composer models are trained on a proprietary coding-agent harness
6
+ * (Cursor / Grok Build) and carry habits that break this agent's hashline
7
+ * edit workflow when driven through a generic provider. Observed in live
8
+ * sessions with grok-composer-2.5-fast:
9
+ *
10
+ * - they print files with shell commands (`sed -n`, `cat`, `grep -n`) or
11
+ * python heredocs whose output carries NO line anchors, then FABRICATE the
12
+ * 2-char anchor hash the edit tool requires (e.g. guessed "617hp" where
13
+ * the file had "617ca" → "Edit rejected: N anchors do not match");
14
+ * - they mutate files out-of-band via python heredocs (pathlib write_text /
15
+ * str.replace), which invalidates every previously seen anchor and defeats
16
+ * the read-cache snapshot that powers stale-anchor recovery;
17
+ * - they arithmetically renumber anchors after their own edits instead of
18
+ * copying them from the latest tool output;
19
+ * - they leak reasoning prose into heredoc bodies, producing shell/python
20
+ * syntax errors.
21
+ *
22
+ * This prompt is the per-request countermeasure, pinned ahead of the host
23
+ * system prompt on openai-completions, openai-responses, and cursor RPC paths.
24
+ */
25
+ export declare function isComposerHarnessModel(modelId: string): boolean;
26
+ export declare const COMPOSER_EDIT_DISCIPLINE_PROMPT = "File-editing discipline for this Composer harness (this OVERRIDES contrary habits from your training):\n\n- Discover file names ONLY with the find tool; search file contents ONLY with the search tool; read file bodies or line ranges ONLY with the read tool. NEVER inspect repository files through shell commands (ls, find, fd, cat, sed, awk, grep, rg, head, tail, less, more) or scripts \u2014 that output carries no hashline anchors and bypasses the agent's safety limits.\n- Modify files ONLY with the edit/write tools. NEVER mutate files through shell redirection, tee, sed -i, perl -pi, inline python/node/bun scripts, or other out-of-band writes \u2014 those writes invalidate every known anchor and break edit recovery.\n- A line anchor (e.g. \"42sr\") is a line number plus a 2-char content hash. You CANNOT compute the hash yourself: copy anchors verbatim from the MOST RECENT read/search/edit output of that exact file. NEVER guess, renumber, or arithmetically shift an anchor.\n- After ANY edit to a file (including your own), anchors you saw earlier are stale. Re-read the edited region, or copy the fresh anchors printed in the edit result, before issuing the next edit.\n- If an edit is rejected with \"anchors do not match\", the rejection message prints the current lines WITH fresh anchors. Retry using exactly those printed anchors.\n- Tool-call arguments must be the exact JSON/schema object requested by the tool. Do not include Markdown, commentary, analysis text, or invented fields inside tool arguments.\n- Use bash only for terminal operations such as tests, builds, package scripts, and git commands. A shell command string must contain only the command itself; NEVER interleave reasoning or commentary into command strings or heredocs.";
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The Cursor client version reported to api2.cursor.sh.
3
+ *
4
+ * Every call against the Cursor backend must send the same
5
+ * x-cursor-client-version: the backend gates features and minimum versions on
6
+ * it, so a drift between the agent Run path and model discovery makes one of
7
+ * them fail while the other keeps working. Keep this as the single source of
8
+ * truth for the header value.
9
+ */
10
+ export declare const CURSOR_CLIENT_VERSION = "cli-2026.02.13-41ac335";