evolcore 0.0.8 → 0.0.9

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 (213) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +37 -3
  3. package/dist/agents/baseagent.js +111 -19
  4. package/dist/agents/claude-runner.js +30 -2
  5. package/dist/agents/codex-app-server-client.js +31 -0
  6. package/dist/agents/codex-runner.js +3 -0
  7. package/dist/aun/msg/group.js +9 -9
  8. package/dist/aun/msg/p2p.js +11 -6
  9. package/dist/aun/msg/upload.js +43 -29
  10. package/dist/aun/outbox.js +48 -5
  11. package/dist/channels/aun.js +199 -50
  12. package/dist/cli/aun-commands.js +10 -7
  13. package/dist/cli/daemon-commands.js +19 -4
  14. package/dist/cli/index.js +11 -1
  15. package/dist/cli/init.js +103 -4
  16. package/dist/cli/model.js +5 -5
  17. package/dist/config/builtin-role-templates.js +4 -3
  18. package/dist/config/config-field-policy.js +6 -2
  19. package/dist/config/config-manager.js +48 -11
  20. package/dist/config/role-schema.js +18 -3
  21. package/dist/config/role-service.js +3 -3
  22. package/dist/config/role-store.js +4 -3
  23. package/dist/config-store.js +4 -0
  24. package/dist/core/auth/operation-authorizer.js +3 -1
  25. package/dist/core/bootstrap-service.js +0 -12
  26. package/dist/core/channel-loader.js +5 -1
  27. package/dist/core/command/command-handler.js +1 -1
  28. package/dist/core/command/evol-menu-version-gate.js +3 -2
  29. package/dist/core/command/menu-handler.js +33 -22
  30. package/dist/core/command/menu-protocol.js +7 -4
  31. package/dist/core/command/slash-handler.js +4 -4
  32. package/dist/core/inference/text-inference.js +18 -5
  33. package/dist/core/message/message-bridge.js +17 -6
  34. package/dist/core/message/response-engine.js +22 -3
  35. package/dist/core/model/config-scope.js +3 -3
  36. package/dist/core/permission/tool-policy.js +18 -0
  37. package/dist/index.js +43 -26
  38. package/dist/ipc.js +1 -1
  39. package/dist/product.js +1 -0
  40. package/dist/utils/autostart.js +27 -0
  41. package/dist/utils/ecweb-utils.js +15 -2
  42. package/dist/utils/macos-autostart.js +179 -0
  43. package/dist/utils/windows-autostart.js +130 -0
  44. package/ecagent/dist/agent-loop.d.ts +1 -1
  45. package/ecagent/dist/agent-loop.js +1 -1
  46. package/ecagent/dist/agent.d.ts +1 -1
  47. package/ecagent/dist/agent.js +1 -1
  48. package/ecagent/dist/harness/agent-harness.d.ts +1 -1
  49. package/ecagent/dist/harness/compaction/branch-summarization.d.ts +1 -1
  50. package/ecagent/dist/harness/compaction/compaction.d.ts +1 -1
  51. package/ecagent/dist/harness/compaction/utils.d.ts +1 -1
  52. package/ecagent/dist/harness/messages.d.ts +1 -1
  53. package/ecagent/dist/harness/session/session.d.ts +1 -1
  54. package/ecagent/dist/harness/types.d.ts +1 -1
  55. package/ecagent/dist/proxy.d.ts +1 -1
  56. package/ecagent/dist/proxy.js +1 -1
  57. package/ecagent/dist/types.d.ts +1 -1
  58. package/kits/migrations/migrate-role-config-v5.mjs +27 -2
  59. package/kits/schemas/agent-config.schema.10.json +19 -1
  60. package/kits/schemas/daemon.schema.4.json +4 -0
  61. package/kits/schemas/defaults.schema.4.json +15 -1
  62. package/kits/schemas/relation-config.schema.8.json +22 -1
  63. package/kits/schemas/role-config.schema.1.json +2 -2
  64. package/package.json +2 -4
  65. package/ecagent/dist/agent-loop.d.ts.map +0 -1
  66. package/ecagent/dist/agent-loop.js.map +0 -1
  67. package/ecagent/dist/agent.d.ts.map +0 -1
  68. package/ecagent/dist/agent.js.map +0 -1
  69. package/ecagent/dist/harness/agent-harness.d.ts.map +0 -1
  70. package/ecagent/dist/harness/agent-harness.js.map +0 -1
  71. package/ecagent/dist/harness/compaction/branch-summarization.d.ts.map +0 -1
  72. package/ecagent/dist/harness/compaction/branch-summarization.js.map +0 -1
  73. package/ecagent/dist/harness/compaction/compaction.d.ts.map +0 -1
  74. package/ecagent/dist/harness/compaction/compaction.js.map +0 -1
  75. package/ecagent/dist/harness/compaction/utils.d.ts.map +0 -1
  76. package/ecagent/dist/harness/compaction/utils.js.map +0 -1
  77. package/ecagent/dist/harness/env/nodejs.d.ts.map +0 -1
  78. package/ecagent/dist/harness/env/nodejs.js.map +0 -1
  79. package/ecagent/dist/harness/messages.d.ts.map +0 -1
  80. package/ecagent/dist/harness/messages.js.map +0 -1
  81. package/ecagent/dist/harness/prompt-templates.d.ts.map +0 -1
  82. package/ecagent/dist/harness/prompt-templates.js.map +0 -1
  83. package/ecagent/dist/harness/session/jsonl-repo.d.ts.map +0 -1
  84. package/ecagent/dist/harness/session/jsonl-repo.js.map +0 -1
  85. package/ecagent/dist/harness/session/jsonl-storage.d.ts.map +0 -1
  86. package/ecagent/dist/harness/session/jsonl-storage.js.map +0 -1
  87. package/ecagent/dist/harness/session/memory-repo.d.ts.map +0 -1
  88. package/ecagent/dist/harness/session/memory-repo.js.map +0 -1
  89. package/ecagent/dist/harness/session/memory-storage.d.ts.map +0 -1
  90. package/ecagent/dist/harness/session/memory-storage.js.map +0 -1
  91. package/ecagent/dist/harness/session/repo-utils.d.ts.map +0 -1
  92. package/ecagent/dist/harness/session/repo-utils.js.map +0 -1
  93. package/ecagent/dist/harness/session/session.d.ts.map +0 -1
  94. package/ecagent/dist/harness/session/session.js.map +0 -1
  95. package/ecagent/dist/harness/session/uuid.d.ts.map +0 -1
  96. package/ecagent/dist/harness/session/uuid.js.map +0 -1
  97. package/ecagent/dist/harness/skills.d.ts.map +0 -1
  98. package/ecagent/dist/harness/skills.js.map +0 -1
  99. package/ecagent/dist/harness/system-prompt.d.ts.map +0 -1
  100. package/ecagent/dist/harness/system-prompt.js.map +0 -1
  101. package/ecagent/dist/harness/types.d.ts.map +0 -1
  102. package/ecagent/dist/harness/types.js.map +0 -1
  103. package/ecagent/dist/harness/utils/shell-output.d.ts.map +0 -1
  104. package/ecagent/dist/harness/utils/shell-output.js.map +0 -1
  105. package/ecagent/dist/harness/utils/truncate.d.ts.map +0 -1
  106. package/ecagent/dist/harness/utils/truncate.js.map +0 -1
  107. package/ecagent/dist/index.d.ts.map +0 -1
  108. package/ecagent/dist/index.js.map +0 -1
  109. package/ecagent/dist/node.d.ts.map +0 -1
  110. package/ecagent/dist/node.js.map +0 -1
  111. package/ecagent/dist/proxy.d.ts.map +0 -1
  112. package/ecagent/dist/proxy.js.map +0 -1
  113. package/ecagent/dist/runtime/api/lazy.d.ts.map +0 -1
  114. package/ecagent/dist/runtime/api/lazy.js.map +0 -1
  115. package/ecagent/dist/runtime/api/pi-messages.d.ts.map +0 -1
  116. package/ecagent/dist/runtime/api/pi-messages.js.map +0 -1
  117. package/ecagent/dist/runtime/api/pi-messages.lazy.d.ts.map +0 -1
  118. package/ecagent/dist/runtime/api/pi-messages.lazy.js.map +0 -1
  119. package/ecagent/dist/runtime/auth/context.d.ts.map +0 -1
  120. package/ecagent/dist/runtime/auth/context.js.map +0 -1
  121. package/ecagent/dist/runtime/auth/credential-store.d.ts.map +0 -1
  122. package/ecagent/dist/runtime/auth/credential-store.js.map +0 -1
  123. package/ecagent/dist/runtime/auth/helpers.d.ts.map +0 -1
  124. package/ecagent/dist/runtime/auth/helpers.js.map +0 -1
  125. package/ecagent/dist/runtime/auth/resolve.d.ts.map +0 -1
  126. package/ecagent/dist/runtime/auth/resolve.js.map +0 -1
  127. package/ecagent/dist/runtime/auth/types.d.ts.map +0 -1
  128. package/ecagent/dist/runtime/auth/types.js.map +0 -1
  129. package/ecagent/dist/runtime/compat.d.ts.map +0 -1
  130. package/ecagent/dist/runtime/compat.js.map +0 -1
  131. package/ecagent/dist/runtime/index.d.ts.map +0 -1
  132. package/ecagent/dist/runtime/index.js.map +0 -1
  133. package/ecagent/dist/runtime/models.d.ts.map +0 -1
  134. package/ecagent/dist/runtime/models.js.map +0 -1
  135. package/ecagent/dist/runtime/oauth.d.ts.map +0 -1
  136. package/ecagent/dist/runtime/oauth.js.map +0 -1
  137. package/ecagent/dist/runtime/providers/faux.d.ts.map +0 -1
  138. package/ecagent/dist/runtime/providers/faux.js.map +0 -1
  139. package/ecagent/dist/runtime/types.d.ts.map +0 -1
  140. package/ecagent/dist/runtime/types.js.map +0 -1
  141. package/ecagent/dist/runtime/utils/diagnostics.d.ts.map +0 -1
  142. package/ecagent/dist/runtime/utils/diagnostics.js.map +0 -1
  143. package/ecagent/dist/runtime/utils/event-stream.d.ts.map +0 -1
  144. package/ecagent/dist/runtime/utils/event-stream.js.map +0 -1
  145. package/ecagent/dist/runtime/utils/headers.d.ts.map +0 -1
  146. package/ecagent/dist/runtime/utils/headers.js.map +0 -1
  147. package/ecagent/dist/runtime/utils/json-parse.d.ts.map +0 -1
  148. package/ecagent/dist/runtime/utils/json-parse.js.map +0 -1
  149. package/ecagent/dist/runtime/utils/oauth/types.d.ts.map +0 -1
  150. package/ecagent/dist/runtime/utils/oauth/types.js.map +0 -1
  151. package/ecagent/dist/runtime/utils/overflow.d.ts.map +0 -1
  152. package/ecagent/dist/runtime/utils/overflow.js.map +0 -1
  153. package/ecagent/dist/runtime/utils/provider-env.d.ts.map +0 -1
  154. package/ecagent/dist/runtime/utils/provider-env.js.map +0 -1
  155. package/ecagent/dist/runtime/utils/retry.d.ts.map +0 -1
  156. package/ecagent/dist/runtime/utils/retry.js.map +0 -1
  157. package/ecagent/dist/runtime/utils/typebox-helpers.d.ts.map +0 -1
  158. package/ecagent/dist/runtime/utils/typebox-helpers.js.map +0 -1
  159. package/ecagent/dist/runtime/utils/validation.d.ts.map +0 -1
  160. package/ecagent/dist/runtime/utils/validation.js.map +0 -1
  161. package/ecagent/dist/types.d.ts.map +0 -1
  162. package/ecagent/dist/types.js.map +0 -1
  163. package/ecagent/package.json +0 -93
  164. package/ecagent/src/agent-loop.ts +0 -792
  165. package/ecagent/src/agent.ts +0 -575
  166. package/ecagent/src/harness/agent-harness.ts +0 -1029
  167. package/ecagent/src/harness/compaction/branch-summarization.ts +0 -261
  168. package/ecagent/src/harness/compaction/compaction.ts +0 -753
  169. package/ecagent/src/harness/compaction/utils.ts +0 -144
  170. package/ecagent/src/harness/env/nodejs.ts +0 -569
  171. package/ecagent/src/harness/messages.ts +0 -164
  172. package/ecagent/src/harness/prompt-templates.ts +0 -267
  173. package/ecagent/src/harness/session/jsonl-repo.ts +0 -179
  174. package/ecagent/src/harness/session/jsonl-storage.ts +0 -314
  175. package/ecagent/src/harness/session/memory-repo.ts +0 -50
  176. package/ecagent/src/harness/session/memory-storage.ts +0 -133
  177. package/ecagent/src/harness/session/repo-utils.ts +0 -51
  178. package/ecagent/src/harness/session/session.ts +0 -338
  179. package/ecagent/src/harness/session/uuid.ts +0 -54
  180. package/ecagent/src/harness/skills.ts +0 -375
  181. package/ecagent/src/harness/system-prompt.ts +0 -34
  182. package/ecagent/src/harness/types.ts +0 -838
  183. package/ecagent/src/harness/utils/shell-output.ts +0 -135
  184. package/ecagent/src/harness/utils/truncate.ts +0 -344
  185. package/ecagent/src/index.ts +0 -46
  186. package/ecagent/src/node.ts +0 -2
  187. package/ecagent/src/proxy.ts +0 -367
  188. package/ecagent/src/runtime/api/lazy.ts +0 -70
  189. package/ecagent/src/runtime/api/pi-messages.lazy.ts +0 -4
  190. package/ecagent/src/runtime/api/pi-messages.ts +0 -436
  191. package/ecagent/src/runtime/auth/context.ts +0 -45
  192. package/ecagent/src/runtime/auth/credential-store.ts +0 -47
  193. package/ecagent/src/runtime/auth/helpers.ts +0 -46
  194. package/ecagent/src/runtime/auth/resolve.ts +0 -141
  195. package/ecagent/src/runtime/auth/types.ts +0 -182
  196. package/ecagent/src/runtime/compat.ts +0 -158
  197. package/ecagent/src/runtime/index.ts +0 -31
  198. package/ecagent/src/runtime/models.ts +0 -452
  199. package/ecagent/src/runtime/oauth.ts +0 -1
  200. package/ecagent/src/runtime/providers/faux.ts +0 -538
  201. package/ecagent/src/runtime/types.ts +0 -718
  202. package/ecagent/src/runtime/utils/diagnostics.ts +0 -45
  203. package/ecagent/src/runtime/utils/event-stream.ts +0 -88
  204. package/ecagent/src/runtime/utils/headers.ts +0 -18
  205. package/ecagent/src/runtime/utils/json-parse.ts +0 -124
  206. package/ecagent/src/runtime/utils/oauth/types.ts +0 -79
  207. package/ecagent/src/runtime/utils/overflow.ts +0 -165
  208. package/ecagent/src/runtime/utils/provider-env.ts +0 -52
  209. package/ecagent/src/runtime/utils/retry.ts +0 -101
  210. package/ecagent/src/runtime/utils/typebox-helpers.ts +0 -24
  211. package/ecagent/src/runtime/utils/validation.ts +0 -310
  212. package/ecagent/src/types.ts +0 -430
  213. package/ecagent/tsconfig.build.json +0 -32
@@ -1,718 +0,0 @@
1
- import type { PiMessagesOptions } from "./api/pi-messages.ts";
2
- import type { AssistantMessageDiagnostic } from "./utils/diagnostics.ts";
3
- import type { AssistantMessageEventStream } from "./utils/event-stream.ts";
4
-
5
- export type { AssistantMessageEventStream } from "./utils/event-stream.ts";
6
-
7
- export type KnownApi =
8
- | "openai-completions"
9
- | "mistral-conversations"
10
- | "openai-responses"
11
- | "azure-openai-responses"
12
- | "openai-codex-responses"
13
- | "anthropic-messages"
14
- | "bedrock-converse-stream"
15
- | "google-generative-ai"
16
- | "google-vertex"
17
- | "pi-messages";
18
-
19
- export type Api = KnownApi | (string & {});
20
-
21
- export type KnownImagesApi = "openrouter-images";
22
-
23
- export type ImagesApi = KnownImagesApi | (string & {});
24
-
25
- export type KnownProvider =
26
- | "amazon-bedrock"
27
- | "ant-ling"
28
- | "anthropic"
29
- | "google"
30
- | "google-vertex"
31
- | "openai"
32
- | "azure-openai-responses"
33
- | "openai-codex"
34
- | "radius"
35
- | "nvidia"
36
- | "deepseek"
37
- | "github-copilot"
38
- | "xai"
39
- | "groq"
40
- | "cerebras"
41
- | "openrouter"
42
- | "vercel-ai-gateway"
43
- | "zai"
44
- | "zai-coding-cn"
45
- | "mistral"
46
- | "minimax"
47
- | "minimax-cn"
48
- | "moonshotai"
49
- | "moonshotai-cn"
50
- | "huggingface"
51
- | "fireworks"
52
- | "together"
53
- | "opencode"
54
- | "opencode-go"
55
- | "kimi-coding"
56
- | "cloudflare-workers-ai"
57
- | "cloudflare-ai-gateway"
58
- | "xiaomi"
59
- | "xiaomi-token-plan-cn"
60
- | "xiaomi-token-plan-ams"
61
- | "xiaomi-token-plan-sgp";
62
- export type ProviderId = KnownProvider | string;
63
-
64
- export type KnownImagesProvider = "openrouter";
65
-
66
- export type ImagesProviderId = KnownImagesProvider | string;
67
-
68
- export type ThinkingLevel = "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
69
- export type ModelThinkingLevel = "off" | ThinkingLevel;
70
- export type ThinkingLevelMap = Partial<Record<ModelThinkingLevel, string | null>>;
71
- export type ChatTemplateKwargValue =
72
- | string
73
- | number
74
- | boolean
75
- | null
76
- | {
77
- $var: "thinking.enabled" | "thinking.effort";
78
- omitWhenOff?: boolean;
79
- };
80
-
81
- /** Token budgets for each thinking level (token-based providers only) */
82
- export interface ThinkingBudgets {
83
- minimal?: number;
84
- low?: number;
85
- medium?: number;
86
- high?: number;
87
- }
88
-
89
- // Base options all providers share
90
- export type CacheRetention = "none" | "short" | "long";
91
-
92
- export type Transport = "sse" | "websocket" | "websocket-cached" | "auto";
93
-
94
- /** Provider-scoped environment overrides. Values take precedence over process.env. */
95
- export type ProviderEnv = Record<string, string>;
96
- export type ProviderHeaders = Record<string, string | null>;
97
- export type SessionAffinityFormat = "openai" | "openai-nosession" | "openrouter";
98
-
99
- export interface ProviderResponse {
100
- status: number;
101
- headers: Record<string, string>;
102
- }
103
-
104
- export interface StreamOptions {
105
- temperature?: number;
106
- maxTokens?: number;
107
- signal?: AbortSignal;
108
- apiKey?: string;
109
- /**
110
- * Preferred transport for providers that support multiple transports.
111
- * Providers that do not support this option ignore it.
112
- */
113
- transport?: Transport;
114
- /**
115
- * Prompt cache retention preference. Providers map this to their supported values.
116
- * Default: "short".
117
- */
118
- cacheRetention?: CacheRetention;
119
- /**
120
- * Optional session identifier for providers that support session-based caching.
121
- * Providers can use this to enable prompt caching, request routing, or other
122
- * session-aware features. Ignored by providers that don't support it.
123
- */
124
- sessionId?: string;
125
- /**
126
- * Optional callback for inspecting or replacing provider payloads before sending.
127
- * Return undefined to keep the payload unchanged.
128
- */
129
- onPayload?: (payload: unknown, model: Model<Api>) => unknown | undefined | Promise<unknown | undefined>;
130
- /**
131
- * Optional callback invoked after an HTTP response is received and before
132
- * its body stream is consumed.
133
- */
134
- onResponse?: (response: ProviderResponse, model: Model<Api>) => void | Promise<void>;
135
- /**
136
- * Optional custom HTTP headers to include in API requests.
137
- * Merged with provider defaults; caller values override default headers.
138
- * On AWS Bedrock these are injected via a Smithy `build`-step middleware so
139
- * they are covered by SigV4 signing; reserved headers (`x-amz-*`,
140
- * `authorization`, `host`) are silently ignored to preserve SigV4 / bearer auth.
141
- * A null value suppresses a provider/API default header with the same name.
142
- */
143
- headers?: ProviderHeaders;
144
- /**
145
- * HTTP request timeout in milliseconds for providers/SDKs that support it.
146
- * For example, OpenAI and Anthropic SDK clients default to 10 minutes.
147
- */
148
- timeoutMs?: number;
149
- /**
150
- * WebSocket connect timeout in milliseconds for providers that support
151
- * WebSocket transports. This covers the connection/open handshake only;
152
- * stream idleness after connection uses timeoutMs.
153
- */
154
- websocketConnectTimeoutMs?: number;
155
- /**
156
- * Maximum retry attempts for providers/SDKs that support client-side retries.
157
- * For example, OpenAI and Anthropic SDK clients default to 2.
158
- */
159
- maxRetries?: number;
160
- /**
161
- * Maximum delay in milliseconds to wait for a retry when the server requests a long wait.
162
- * If the server's requested delay exceeds this value, the request fails immediately
163
- * with an error containing the requested delay, allowing higher-level retry logic
164
- * to handle it with user visibility.
165
- * Default: 60000 (60 seconds). Set to 0 to disable the cap.
166
- */
167
- maxRetryDelayMs?: number;
168
- /**
169
- * Optional metadata to include in API requests.
170
- * Providers extract the fields they understand and ignore the rest.
171
- * For example, Anthropic uses `user_id` for abuse tracking and rate limiting.
172
- */
173
- metadata?: Record<string, unknown>;
174
- /**
175
- * Provider-scoped environment values. These take precedence over process.env for
176
- * provider configuration such as regional settings, endpoint placeholders, and
177
- * proxy variables.
178
- */
179
- env?: ProviderEnv;
180
- }
181
-
182
- export type ProviderStreamOptions = StreamOptions & Record<string, unknown>;
183
-
184
- /**
185
- * Maps known APIs to their full provider-specific stream option types.
186
- * Type-only imports from API implementation modules are erased at emit, so
187
- * this is tree-shake safe.
188
- */
189
- export interface ApiOptionsMap {
190
- "pi-messages": PiMessagesOptions;
191
- }
192
-
193
- /**
194
- * Full stream options for an API. Known APIs resolve to their concrete option
195
- * type; custom API strings fall back to the generic shape.
196
- */
197
- export type ApiStreamOptions<TApi extends Api> = TApi extends keyof ApiOptionsMap
198
- ? ApiOptionsMap[TApi]
199
- : StreamOptions & Record<string, unknown>;
200
-
201
- /**
202
- * The uniform stream contract of an API implementation module: every module
203
- * under `src/api/` exports exactly `stream` and `streamSimple`, so the module
204
- * itself satisfies this interface. Lazy wrappers (`lazyApi()`) and provider
205
- * factories pass these around as values. This is the untyped dispatch shape;
206
- * per-API option typing lives on the implementation modules themselves and on
207
- * `Provider.stream()` via `ApiStreamOptions`.
208
- */
209
- export interface ProviderStreams {
210
- stream(model: Model<Api>, context: Context, options?: StreamOptions): AssistantMessageEventStream;
211
- streamSimple(model: Model<Api>, context: Context, options?: SimpleStreamOptions): AssistantMessageEventStream;
212
- }
213
-
214
- /**
215
- * The uniform contract of an image-generation API implementation module:
216
- * every image API module under `src/api/` exports exactly `generateImages`,
217
- * so the module itself satisfies this interface. Lazy wrappers and image
218
- * provider factories pass these around as values.
219
- */
220
- export interface ProviderImages {
221
- generateImages(
222
- model: ImagesModel<ImagesApi>,
223
- context: ImagesContext,
224
- options?: ImagesOptions,
225
- ): Promise<AssistantImages>;
226
- }
227
-
228
- export interface ImagesOptions {
229
- signal?: AbortSignal;
230
- apiKey?: string;
231
- /**
232
- * Provider-scoped environment values. These take precedence over process.env for
233
- * provider configuration such as endpoint placeholders and proxy variables.
234
- */
235
- env?: ProviderEnv;
236
- /**
237
- * Optional callback for inspecting or replacing provider payloads before sending.
238
- * Return undefined to keep the payload unchanged.
239
- */
240
- onPayload?: (payload: unknown, model: ImagesModel<ImagesApi>) => unknown | undefined | Promise<unknown | undefined>;
241
- /**
242
- * Optional callback invoked after an HTTP response is received.
243
- */
244
- onResponse?: (response: ProviderResponse, model: ImagesModel<ImagesApi>) => void | Promise<void>;
245
- /**
246
- * Optional custom HTTP headers to include in API requests.
247
- * Merged with provider defaults; can override default headers.
248
- * A null value suppresses a provider/API default header with the same name.
249
- */
250
- headers?: ProviderHeaders;
251
- /**
252
- * HTTP request timeout in milliseconds for providers/SDKs that support it.
253
- */
254
- timeoutMs?: number;
255
- /**
256
- * Maximum retry attempts for providers/SDKs that support client-side retries.
257
- */
258
- maxRetries?: number;
259
- /**
260
- * Maximum delay in milliseconds to wait for a retry when the server requests a long wait.
261
- * If the server's requested delay exceeds this value, the request fails immediately
262
- * with an error containing the requested delay, allowing higher-level retry logic
263
- * to handle it with user visibility.
264
- * Default: 60000 (60 seconds). Set to 0 to disable the cap.
265
- */
266
- maxRetryDelayMs?: number;
267
- /**
268
- * Optional metadata to include in API requests.
269
- * Providers extract the fields they understand and ignore the rest.
270
- */
271
- metadata?: Record<string, unknown>;
272
- }
273
-
274
- export type ProviderImagesOptions = ImagesOptions & Record<string, unknown>;
275
-
276
- // Unified options with reasoning passed to streamSimple() and completeSimple()
277
- export interface SimpleStreamOptions extends StreamOptions {
278
- reasoning?: ThinkingLevel;
279
- /** Custom token budgets for thinking levels (token-based providers only) */
280
- thinkingBudgets?: ThinkingBudgets;
281
- }
282
-
283
- // Generic StreamFunction with typed options.
284
- //
285
- // Contract:
286
- // - Must return an AssistantMessageEventStream.
287
- // - Once invoked, request/model/runtime failures should be encoded in the
288
- // returned stream, not thrown.
289
- // - Error termination must produce an AssistantMessage with stopReason
290
- // "error" or "aborted" and errorMessage, emitted via the stream protocol.
291
- export type StreamFunction<TApi extends Api = Api, TOptions extends StreamOptions = StreamOptions> = (
292
- model: Model<TApi>,
293
- context: Context,
294
- options?: TOptions,
295
- ) => AssistantMessageEventStream;
296
-
297
- export type ImagesFunction<TApi extends ImagesApi = ImagesApi, TOptions extends ImagesOptions = ImagesOptions> = (
298
- model: ImagesModel<TApi>,
299
- context: ImagesContext,
300
- options?: TOptions,
301
- ) => Promise<AssistantImages>;
302
-
303
- export interface TextSignatureV1 {
304
- v: 1;
305
- id: string;
306
- phase?: "commentary" | "final_answer";
307
- }
308
-
309
- export interface TextContent {
310
- type: "text";
311
- text: string;
312
- textSignature?: string; // e.g., for OpenAI responses, message metadata (legacy id string or TextSignatureV1 JSON)
313
- }
314
-
315
- export interface ThinkingContent {
316
- type: "thinking";
317
- thinking: string;
318
- thinkingSignature?: string; // e.g., for OpenAI responses, the reasoning item ID
319
- /** When true, the thinking content was redacted by safety filters. The opaque
320
- * encrypted payload is stored in `thinkingSignature` so it can be passed back
321
- * to the API for multi-turn continuity. */
322
- redacted?: boolean;
323
- }
324
-
325
- export interface ImageContent {
326
- type: "image";
327
- data: string; // base64 encoded image data
328
- mimeType: string; // e.g., "image/jpeg", "image/png"
329
- }
330
-
331
- export interface ToolCall {
332
- type: "toolCall";
333
- id: string;
334
- name: string;
335
- arguments: Record<string, any>;
336
- thoughtSignature?: string; // Google-specific: opaque signature for reusing thought context
337
- }
338
-
339
- export interface Usage {
340
- input: number;
341
- output: number;
342
- cacheRead: number;
343
- cacheWrite: number;
344
- /** Subset of `cacheWrite` written with 1h retention. Only Anthropic reports this split. */
345
- cacheWrite1h?: number;
346
- /**
347
- * Reasoning/thinking tokens, when the provider reports them. This is a subset of
348
- * `output`: `output` already includes these tokens. Set to a number (possibly 0) by
349
- * providers that expose a reasoning breakdown; left undefined by providers that don't.
350
- */
351
- reasoning?: number;
352
- totalTokens: number;
353
- cost: {
354
- input: number;
355
- output: number;
356
- cacheRead: number;
357
- cacheWrite: number;
358
- total: number;
359
- };
360
- }
361
-
362
- export type StopReason = "stop" | "length" | "toolUse" | "error" | "aborted";
363
-
364
- export interface UserMessage {
365
- role: "user";
366
- content: string | (TextContent | ImageContent)[];
367
- timestamp: number; // Unix timestamp in milliseconds
368
- }
369
-
370
- export interface AssistantMessage {
371
- role: "assistant";
372
- content: (TextContent | ThinkingContent | ToolCall)[];
373
- api: Api;
374
- provider: ProviderId;
375
- model: string;
376
- responseModel?: string; // Concrete `chunk.model` when different from the requested `model` (e.g. OpenRouter `auto` -> `anthropic/...`)
377
- responseId?: string; // Provider-specific response/message identifier when the upstream API exposes one
378
- diagnostics?: AssistantMessageDiagnostic[]; // Redacted provider/runtime diagnostics for failures and recoveries.
379
- usage: Usage;
380
- stopReason: StopReason;
381
- errorMessage?: string;
382
- timestamp: number; // Unix timestamp in milliseconds
383
- }
384
-
385
- export interface ToolResultMessage<TDetails = any> {
386
- role: "toolResult";
387
- toolCallId: string;
388
- toolName: string;
389
- content: (TextContent | ImageContent)[]; // Supports text and images
390
- details?: TDetails;
391
- /**
392
- * Names from `Context.tools` that became available after this result.
393
- * Providers with native deferred tool loading use this as the load point;
394
- * other providers ignore it and use `Context.tools` normally.
395
- */
396
- addedToolNames?: string[];
397
- isError: boolean;
398
- timestamp: number; // Unix timestamp in milliseconds
399
- }
400
-
401
- export type Message = UserMessage | AssistantMessage | ToolResultMessage;
402
-
403
- export type ImagesInputContent = TextContent | ImageContent;
404
- export type ImagesOutputContent = TextContent | ImageContent;
405
-
406
- export interface ImagesContext {
407
- input: ImagesInputContent[];
408
- }
409
-
410
- export type ImagesStopReason = "stop" | "error" | "aborted";
411
-
412
- export interface AssistantImages {
413
- api: ImagesApi;
414
- provider: ImagesProviderId;
415
- model: string;
416
- output: ImagesOutputContent[];
417
- responseId?: string;
418
- usage?: Usage;
419
- stopReason: ImagesStopReason;
420
- errorMessage?: string;
421
- timestamp: number; // Unix timestamp in milliseconds
422
- }
423
-
424
- import type { TSchema } from "typebox";
425
-
426
- export interface Tool<TParameters extends TSchema = TSchema> {
427
- name: string;
428
- description: string;
429
- parameters: TParameters;
430
- }
431
-
432
- export interface Context {
433
- systemPrompt?: string;
434
- messages: Message[];
435
- tools?: Tool[];
436
- }
437
-
438
- /**
439
- * Event protocol for AssistantMessageEventStream.
440
- *
441
- * Streams should emit `start` before partial updates, then terminate with either:
442
- * - `done` carrying the final successful AssistantMessage, or
443
- * - `error` carrying the final AssistantMessage with stopReason "error" or "aborted"
444
- * and errorMessage.
445
- */
446
- export type AssistantMessageEvent =
447
- | { type: "start"; partial: AssistantMessage }
448
- | { type: "text_start"; contentIndex: number; partial: AssistantMessage }
449
- | { type: "text_delta"; contentIndex: number; delta: string; partial: AssistantMessage }
450
- | { type: "text_end"; contentIndex: number; content: string; partial: AssistantMessage }
451
- | { type: "thinking_start"; contentIndex: number; partial: AssistantMessage }
452
- | { type: "thinking_delta"; contentIndex: number; delta: string; partial: AssistantMessage }
453
- | { type: "thinking_end"; contentIndex: number; content: string; partial: AssistantMessage }
454
- | { type: "toolcall_start"; contentIndex: number; partial: AssistantMessage }
455
- | { type: "toolcall_delta"; contentIndex: number; delta: string; partial: AssistantMessage }
456
- | { type: "toolcall_end"; contentIndex: number; toolCall: ToolCall; partial: AssistantMessage }
457
- | { type: "done"; reason: Extract<StopReason, "stop" | "length" | "toolUse">; message: AssistantMessage }
458
- | { type: "error"; reason: Extract<StopReason, "aborted" | "error">; error: AssistantMessage };
459
-
460
- /**
461
- * Compatibility settings for OpenAI-compatible completions APIs.
462
- * Use this to override URL-based auto-detection for custom providers.
463
- */
464
- export interface OpenAICompletionsCompat {
465
- /** Whether the provider supports the `store` field. Default: auto-detected from URL. */
466
- supportsStore?: boolean;
467
- /** Whether the provider supports the `developer` role (vs `system`). Default: auto-detected from URL. */
468
- supportsDeveloperRole?: boolean;
469
- /** Whether the provider supports `reasoning_effort`. Default: auto-detected from URL. */
470
- supportsReasoningEffort?: boolean;
471
- /** Whether the provider supports `stream_options: { include_usage: true }` for token usage in streaming responses. Default: true. */
472
- supportsUsageInStreaming?: boolean;
473
- /** Which field to use for max tokens. Default: auto-detected from URL. */
474
- maxTokensField?: "max_completion_tokens" | "max_tokens";
475
- /** Whether tool results require the `name` field. Default: auto-detected from URL. */
476
- requiresToolResultName?: boolean;
477
- /** Whether a user message after tool results requires an assistant message in between. Default: auto-detected from URL. */
478
- requiresAssistantAfterToolResult?: boolean;
479
- /** Whether thinking blocks must be converted to text blocks with <thinking> delimiters. Default: auto-detected from URL. */
480
- requiresThinkingAsText?: boolean;
481
- /** Whether all replayed assistant messages must include an empty reasoning_content field when reasoning is enabled. Default: auto-detected from URL. */
482
- requiresReasoningContentOnAssistantMessages?: boolean;
483
- /** Format for reasoning/thinking parameter. "openai" uses reasoning_effort, "openrouter" uses reasoning: { effort }, "deepseek" uses thinking: { type } plus reasoning_effort when supported, "together" uses reasoning: { enabled } plus reasoning_effort when supported, "zai" uses thinking: { type }, "qwen" uses top-level enable_thinking: boolean, "qwen-chat-template" uses chat_template_kwargs.enable_thinking and preserve_thinking, "chat-template" uses configurable chat_template_kwargs, "string-thinking" uses top-level thinking: string, and "ant-ling" uses reasoning: { effort } only when the mapped effort is non-null. Default: "openai". */
484
- thinkingFormat?:
485
- | "openai"
486
- | "openrouter"
487
- | "deepseek"
488
- | "together"
489
- | "zai"
490
- | "qwen"
491
- | "chat-template"
492
- | "qwen-chat-template"
493
- | "string-thinking"
494
- | "ant-ling";
495
- /** Kwargs to send as `chat_template_kwargs` when `thinkingFormat` is `chat-template`. Use `{ "$var": "thinking.enabled" }` or `{ "$var": "thinking.effort" }` for pi-controlled thinking values. */
496
- chatTemplateKwargs?: Record<string, ChatTemplateKwargValue>;
497
- /** OpenRouter-compatible routing preferences sent as the `provider` request field. */
498
- openRouterRouting?: OpenRouterRouting;
499
- /** Vercel AI Gateway routing preferences. Only used when baseUrl points to Vercel AI Gateway. */
500
- vercelGatewayRouting?: VercelGatewayRouting;
501
- /** Whether z.ai supports top-level `tool_stream: true` for streaming tool call deltas. Default: false. */
502
- zaiToolStream?: boolean;
503
- /** Whether the provider supports the `strict` field in tool definitions. Default: true. */
504
- supportsStrictMode?: boolean;
505
- /** Cache control convention for prompt caching. "anthropic" applies Anthropic-style `cache_control` markers to the system prompt, last tool definition, and last user/assistant text content. */
506
- cacheControlFormat?: "anthropic";
507
- /** Whether to send session-affinity data from `options.sessionId`. Default: false. */
508
- sendSessionAffinityHeaders?: boolean;
509
- /** Session-affinity header format: `openai` sends `session_id`, `x-client-request-id`, and `x-session-affinity`; `openai-nosession` sends `x-client-request-id` and `x-session-affinity`; `openrouter` sends `x-session-id`. Does not affect the `prompt_cache_key` body param, which is governed by cache retention. Default: auto-detected. */
510
- sessionAffinityFormat?: SessionAffinityFormat;
511
- /** Whether the provider supports long prompt cache retention (`prompt_cache_retention: "24h"` or Anthropic-style `cache_control.ttl: "1h"`, depending on format). Default: true. */
512
- supportsLongCacheRetention?: boolean;
513
- }
514
-
515
- /** Compatibility settings for OpenAI Responses APIs. */
516
- export interface OpenAIResponsesCompat {
517
- /** Whether the provider supports the `developer` role (vs `system`). Default: true. */
518
- supportsDeveloperRole?: boolean;
519
- /** Session-affinity header format: `openai` sends `session_id` and `x-client-request-id`; `openai-nosession` sends `x-client-request-id`; `openrouter` sends `x-session-id`. Does not affect the `prompt_cache_key` body param, which is governed by cache retention. Default: auto-detected. */
520
- sessionAffinityFormat?: SessionAffinityFormat;
521
- /** Whether the provider supports `prompt_cache_retention: "24h"`. Default: true. */
522
- supportsLongCacheRetention?: boolean;
523
- /** Whether the model supports client-executed tool search for deferred tools. Default: false. */
524
- supportsToolSearch?: boolean;
525
- }
526
-
527
- /** Compatibility settings for Anthropic Messages-compatible APIs. */
528
- export interface AnthropicMessagesCompat {
529
- /**
530
- * Whether the provider accepts per-tool `eager_input_streaming`.
531
- * When false, the Anthropic provider omits `tools[].eager_input_streaming`
532
- * and sends the legacy `fine-grained-tool-streaming-2025-05-14` beta header
533
- * for tool-enabled requests.
534
- * Default: true.
535
- */
536
- supportsEagerToolInputStreaming?: boolean;
537
- /** Whether the provider supports Anthropic long cache retention (`cache_control.ttl: "1h"`). Default: true. */
538
- supportsLongCacheRetention?: boolean;
539
- /**
540
- * Whether to send the `x-session-affinity` header from `options.sessionId`
541
- * when caching is enabled. Required for providers like Fireworks that use
542
- * session affinity for prompt cache routing (requests to the same replica
543
- * maximize cache hits).
544
- * Default: false.
545
- */
546
- sendSessionAffinityHeaders?: boolean;
547
- /**
548
- * Whether the provider supports Anthropic-style `cache_control` markers on
549
- * tool definitions. When false, `cache_control` is omitted from tool params.
550
- * Some Anthropic-compatible providers (e.g., Fireworks) do not support this
551
- * field on tools and may reject or ignore it.
552
- * Default: true.
553
- */
554
- supportsCacheControlOnTools?: boolean;
555
- /**
556
- * Whether the model accepts the Anthropic `temperature` request field.
557
- * Claude Opus 4.7+ rejects non-default temperature values.
558
- * Default: true.
559
- */
560
- supportsTemperature?: boolean;
561
- /**
562
- * Whether to force adaptive thinking (`thinking.type: "adaptive"` plus
563
- * `output_config.effort`) regardless of the model id. Built-in models that
564
- * require adaptive thinking set this in generated metadata. Custom
565
- * Anthropic-compatible providers can set this to `true` for any model whose
566
- * upstream requires the adaptive format. Set to `false` to
567
- * opt out on overridden built-in models.
568
- * Default: false.
569
- */
570
- forceAdaptiveThinking?: boolean;
571
- /** Whether to replay empty thinking signatures as `signature: ""` instead of converting thinking to text. Default: false. */
572
- allowEmptySignature?: boolean;
573
- /**
574
- * Whether the provider supports deferred tools loaded by `tool_reference`
575
- * blocks in tool results. Default: true for first-party Anthropic models
576
- * except Haiku and models older than Claude 4.5; false for other providers.
577
- */
578
- supportsToolReferences?: boolean;
579
- }
580
-
581
- /**
582
- * OpenRouter provider routing preferences.
583
- * Controls which upstream providers OpenRouter routes requests to.
584
- * Sent as the `provider` field in the OpenRouter API request body.
585
- * @see https://openrouter.ai/docs/guides/routing/provider-selection
586
- */
587
- export interface OpenRouterRouting {
588
- /** Whether to allow backup providers to serve requests. Default: true. */
589
- allow_fallbacks?: boolean;
590
- /** Whether to filter providers to only those that support all parameters in the request. Default: false. */
591
- require_parameters?: boolean;
592
- /** Data collection setting. "allow" (default): allow providers that may store/train on data. "deny": only use providers that don't collect user data. */
593
- data_collection?: "deny" | "allow";
594
- /** Whether to restrict routing to only ZDR (Zero Data Retention) endpoints. */
595
- zdr?: boolean;
596
- /** Whether to restrict routing to only models that allow text distillation. */
597
- enforce_distillable_text?: boolean;
598
- /** An ordered list of provider names/slugs to try in sequence, falling back to the next if unavailable. */
599
- order?: string[];
600
- /** List of provider names/slugs to exclusively allow for this request. */
601
- only?: string[];
602
- /** List of provider names/slugs to skip for this request. */
603
- ignore?: string[];
604
- /** A list of quantization levels to filter providers by (e.g., ["fp16", "bf16", "fp8", "fp6", "int8", "int4", "fp4", "fp32"]). */
605
- quantizations?: string[];
606
- /** Sorting strategy. Can be a string (e.g., "price", "throughput", "latency") or an object with `by` and `partition`. */
607
- sort?:
608
- | string
609
- | {
610
- /** The sorting metric: "price", "throughput", "latency". */
611
- by?: string;
612
- /** Partitioning strategy: "model" (default) or "none". */
613
- partition?: string | null;
614
- };
615
- /** Maximum price per million tokens (USD). */
616
- max_price?: {
617
- /** Price per million prompt tokens. */
618
- prompt?: number | string;
619
- /** Price per million completion tokens. */
620
- completion?: number | string;
621
- /** Price per image. */
622
- image?: number | string;
623
- /** Price per audio unit. */
624
- audio?: number | string;
625
- /** Price per request. */
626
- request?: number | string;
627
- };
628
- /** Preferred minimum throughput (tokens/second). Can be a number (applies to p50) or an object with percentile-specific cutoffs. */
629
- preferred_min_throughput?:
630
- | number
631
- | {
632
- /** Minimum tokens/second at the 50th percentile. */
633
- p50?: number;
634
- /** Minimum tokens/second at the 75th percentile. */
635
- p75?: number;
636
- /** Minimum tokens/second at the 90th percentile. */
637
- p90?: number;
638
- /** Minimum tokens/second at the 99th percentile. */
639
- p99?: number;
640
- };
641
- /** Preferred maximum latency (seconds). Can be a number (applies to p50) or an object with percentile-specific cutoffs. */
642
- preferred_max_latency?:
643
- | number
644
- | {
645
- /** Maximum latency in seconds at the 50th percentile. */
646
- p50?: number;
647
- /** Maximum latency in seconds at the 75th percentile. */
648
- p75?: number;
649
- /** Maximum latency in seconds at the 90th percentile. */
650
- p90?: number;
651
- /** Maximum latency in seconds at the 99th percentile. */
652
- p99?: number;
653
- };
654
- }
655
-
656
- /**
657
- * Vercel AI Gateway routing preferences.
658
- * Controls which upstream providers the gateway routes requests to.
659
- * @see https://vercel.com/docs/ai-gateway/models-and-providers/provider-options
660
- */
661
- export interface VercelGatewayRouting {
662
- /** List of provider slugs to exclusively use for this request (e.g., ["bedrock", "anthropic"]). */
663
- only?: string[];
664
- /** List of provider slugs to try in order (e.g., ["anthropic", "openai"]). */
665
- order?: string[];
666
- }
667
-
668
- export interface ModelCostRates {
669
- input: number; // $/million tokens
670
- output: number; // $/million tokens
671
- cacheRead: number; // $/million tokens
672
- cacheWrite: number; // $/million tokens
673
- }
674
-
675
- export interface ModelCostTier extends ModelCostRates {
676
- /** Use this tier for requests whose total input usage exceeds this token count. */
677
- inputTokensAbove: number;
678
- }
679
-
680
- export interface ModelCost extends ModelCostRates {
681
- /** Request-wide pricing tiers. The highest matching input threshold applies to the full request. */
682
- tiers?: ModelCostTier[];
683
- }
684
-
685
- // Model interface for the unified model system
686
- export interface Model<TApi extends Api> {
687
- id: string;
688
- name: string;
689
- api: TApi;
690
- provider: ProviderId;
691
- baseUrl: string;
692
- reasoning: boolean;
693
- /**
694
- * Maps pi thinking levels to provider/model-specific values.
695
- * Missing keys use provider defaults. null marks a level as unsupported.
696
- */
697
- thinkingLevelMap?: ThinkingLevelMap;
698
- input: ("text" | "image")[];
699
- cost: ModelCost;
700
- contextWindow: number;
701
- maxTokens: number;
702
- headers?: Record<string, string>;
703
- /** Compatibility overrides for OpenAI-compatible APIs. If not set, auto-detected from baseUrl. */
704
- compat?: TApi extends "openai-completions"
705
- ? OpenAICompletionsCompat
706
- : TApi extends "openai-responses" | "openai-codex-responses"
707
- ? OpenAIResponsesCompat
708
- : TApi extends "anthropic-messages"
709
- ? AnthropicMessagesCompat
710
- : never;
711
- }
712
-
713
- export interface ImagesModel<TApi extends ImagesApi>
714
- extends Omit<Model<Api>, "api" | "provider" | "reasoning" | "contextWindow" | "maxTokens" | "compat"> {
715
- api: TApi;
716
- provider: ImagesProviderId;
717
- output: ("text" | "image")[];
718
- }