@wraith-ai/core 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/README.md +1 -1
  2. package/dist/{attempt-BeB7EltG.d.mts → attempt-HgararU3.d.mts} +2 -1
  3. package/dist/attempt-HgararU3.d.mts.map +1 -0
  4. package/dist/{capabilities-BPb5HSH6.d.mts → capabilities-CNsPrkB7.d.mts} +2 -1
  5. package/dist/capabilities-CNsPrkB7.d.mts.map +1 -0
  6. package/dist/index.d.mts +6 -5
  7. package/dist/index.d.mts.map +1 -0
  8. package/dist/index.mjs +11 -9
  9. package/dist/index.mjs.map +1 -0
  10. package/dist/{methods-CZp6XGn8.mjs → methods-7Ryz6zbd.mjs} +4 -2
  11. package/dist/methods-7Ryz6zbd.mjs.map +1 -0
  12. package/dist/{model-B6tJ9kX_.mjs → model-C16NUwXW.mjs} +2 -0
  13. package/dist/model-C16NUwXW.mjs.map +1 -0
  14. package/dist/{model-D6LQSveS.d.mts → model-_wqePNTL.d.mts} +4 -3
  15. package/dist/model-_wqePNTL.d.mts.map +1 -0
  16. package/dist/{models-dev-Y0ZikMBQ.d.mts → models-dev-DNgymZy3.d.mts} +3 -2
  17. package/dist/models-dev-DNgymZy3.d.mts.map +1 -0
  18. package/dist/{openai-codex-BhtZvNpm.mjs → openai-codex-Bz1EFPEi.mjs} +3 -1
  19. package/dist/openai-codex-Bz1EFPEi.mjs.map +1 -0
  20. package/dist/{openai-codex-Bk-iG7MZ.mjs → openai-codex-uvjhVoVy.mjs} +6 -4
  21. package/dist/openai-codex-uvjhVoVy.mjs.map +1 -0
  22. package/dist/{openai-compatible-hkXv-P74.mjs → openai-compatible-DBppnQ_N.mjs} +4 -2
  23. package/dist/openai-compatible-DBppnQ_N.mjs.map +1 -0
  24. package/dist/{openrouter-BflQBug2.mjs → openrouter-D8nTOAQo.mjs} +5 -3
  25. package/dist/openrouter-D8nTOAQo.mjs.map +1 -0
  26. package/dist/providers/openai-codex.d.mts +4 -3
  27. package/dist/providers/openai-codex.d.mts.map +1 -0
  28. package/dist/providers/openai-codex.mjs +1 -1
  29. package/dist/providers/openai-compatible.d.mts +3 -2
  30. package/dist/providers/openai-compatible.d.mts.map +1 -0
  31. package/dist/providers/openai-compatible.mjs +1 -1
  32. package/dist/providers/openrouter.d.mts +3 -2
  33. package/dist/providers/openrouter.d.mts.map +1 -0
  34. package/dist/providers/openrouter.mjs +1 -1
  35. package/dist/{shared-8d7RsyPH.mjs → shared-BIJaPhMm.mjs} +3 -1
  36. package/dist/shared-BIJaPhMm.mjs.map +1 -0
  37. package/dist/snapshot.d.mts +3 -2
  38. package/dist/snapshot.d.mts.map +1 -0
  39. package/dist/snapshot.mjs +4999 -4977
  40. package/dist/snapshot.mjs.map +1 -0
  41. package/dist/{turn-effort-DquDDwdE.mjs → turn-effort-C61L4JIt.mjs} +2 -0
  42. package/dist/turn-effort-C61L4JIt.mjs.map +1 -0
  43. package/package.json +3 -2
  44. package/src/agent/agent.ts +90 -0
  45. package/src/agent/attachments.ts +195 -0
  46. package/src/agent/classifier.ts +525 -0
  47. package/src/agent/compact.ts +384 -0
  48. package/src/agent/conversation.ts +300 -0
  49. package/src/agent/cost.ts +164 -0
  50. package/src/agent/inbox.ts +80 -0
  51. package/src/agent/instructions.ts +62 -0
  52. package/src/agent/loop.ts +675 -0
  53. package/src/agent/messages.ts +252 -0
  54. package/src/agent/on-demand.ts +58 -0
  55. package/src/agent/prompts.ts +35 -0
  56. package/src/agent/request-images.ts +94 -0
  57. package/src/agent/stop.ts +37 -0
  58. package/src/agent/title.ts +122 -0
  59. package/src/agent/tool-groups.ts +186 -0
  60. package/src/agent/tools.ts +106 -0
  61. package/src/app.ts +67 -0
  62. package/src/config/credential-file-store.ts +66 -0
  63. package/src/config/environment.ts +105 -0
  64. package/src/config/instructions.ts +157 -0
  65. package/src/config/load.ts +667 -0
  66. package/src/config/locked-file.ts +85 -0
  67. package/src/config/paths.ts +368 -0
  68. package/src/config/schema.ts +363 -0
  69. package/src/config/subagents.ts +156 -0
  70. package/src/config/trust.ts +53 -0
  71. package/src/config/write.ts +241 -0
  72. package/src/errors.ts +85 -0
  73. package/src/events/types.ts +258 -0
  74. package/src/glob.ts +161 -0
  75. package/src/index.ts +681 -0
  76. package/src/logger.ts +47 -0
  77. package/src/paths.ts +143 -0
  78. package/src/permissions/chain.ts +42 -0
  79. package/src/permissions/command.ts +233 -0
  80. package/src/permissions/layered.ts +77 -0
  81. package/src/permissions/match.ts +80 -0
  82. package/src/permissions/modes.ts +48 -0
  83. package/src/permissions/policy.ts +160 -0
  84. package/src/permissions/types.ts +159 -0
  85. package/src/providers/cache.ts +107 -0
  86. package/src/providers/capabilities.ts +77 -0
  87. package/src/providers/catalog-view.ts +91 -0
  88. package/src/providers/catalog.ts +65 -0
  89. package/src/providers/errors.ts +108 -0
  90. package/src/providers/factories/index.ts +15 -0
  91. package/src/providers/factories/openai-codex.ts +382 -0
  92. package/src/providers/factories/openai-compatible.ts +81 -0
  93. package/src/providers/factories/openrouter.ts +165 -0
  94. package/src/providers/factories/shared.ts +22 -0
  95. package/src/providers/model.ts +197 -0
  96. package/src/providers/models-dev.ts +355 -0
  97. package/src/providers/oauth/methods.ts +10 -0
  98. package/src/providers/oauth/openai-codex.ts +228 -0
  99. package/src/providers/oauth.ts +177 -0
  100. package/src/providers/openai-codex.ts +7 -0
  101. package/src/providers/openai-compatible.ts +2 -0
  102. package/src/providers/openrouter.ts +2 -0
  103. package/src/providers/registry.ts +464 -0
  104. package/src/providers/turn-effort.ts +156 -0
  105. package/src/providers/types.ts +83 -0
  106. package/src/session/backend.ts +44 -0
  107. package/src/session/file-store.ts +278 -0
  108. package/src/session/format.ts +1037 -0
  109. package/src/session/memory-store.ts +73 -0
  110. package/src/session/session.ts +153 -0
  111. package/src/session/store.ts +219 -0
  112. package/src/sign-in/attempt.ts +166 -0
  113. package/src/sign-in/loopback.ts +74 -0
  114. package/src/snapshot/data.json +8936 -0
  115. package/src/snapshot/index.ts +37 -0
  116. package/src/tools/bin.ts +364 -0
  117. package/src/tools/builtin.ts +48 -0
  118. package/src/tools/change.ts +88 -0
  119. package/src/tools/define.ts +267 -0
  120. package/src/tools/describe.ts +96 -0
  121. package/src/tools/fs/edit-file.ts +129 -0
  122. package/src/tools/fs/glob.ts +75 -0
  123. package/src/tools/fs/grep.ts +212 -0
  124. package/src/tools/fs/line-endings.ts +17 -0
  125. package/src/tools/fs/list-dir.ts +85 -0
  126. package/src/tools/fs/read-file.ts +230 -0
  127. package/src/tools/fs/ripgrep.ts +211 -0
  128. package/src/tools/fs/write-file.ts +97 -0
  129. package/src/tools/job.ts +252 -0
  130. package/src/tools/mcp/auth-store.ts +127 -0
  131. package/src/tools/mcp/command.ts +151 -0
  132. package/src/tools/mcp/config.ts +168 -0
  133. package/src/tools/mcp/servers.ts +463 -0
  134. package/src/tools/mcp/sign-in.ts +226 -0
  135. package/src/tools/mcp/stdio.ts +204 -0
  136. package/src/tools/mcp/tools.ts +173 -0
  137. package/src/tools/on-demand.ts +184 -0
  138. package/src/tools/registry.ts +935 -0
  139. package/src/tools/shell/bash.ts +217 -0
  140. package/src/tools/shell/find-bash.ts +162 -0
  141. package/src/tools/source.ts +35 -0
  142. package/src/tools/spill.ts +127 -0
  143. package/src/tools/subagents.ts +597 -0
  144. package/src/tools/tasks.ts +603 -0
  145. package/src/tools/to-model.ts +33 -0
  146. package/src/tools/web/address.ts +95 -0
  147. package/src/tools/web/exa.ts +163 -0
  148. package/src/tools/web/fetch.ts +373 -0
  149. package/src/tools/web/html.ts +173 -0
  150. package/src/tools/web/search.ts +111 -0
  151. package/src/tools/web/source.ts +51 -0
  152. package/src/units.ts +18 -0
  153. package/src/version.ts +23 -0
@@ -0,0 +1,165 @@
1
+ import { createOpenRouter } from "@openrouter/ai-sdk-provider";
2
+ import { type LanguageModelMiddleware, wrapLanguageModel } from "ai";
3
+ import { WRAITH } from "../../app";
4
+ import type { CacheOptions, RequestFields } from "../cache";
5
+ import { type Provider, type ProviderOptions, providerFromFactory } from "../model";
6
+ import {
7
+ type ExplicitEffort,
8
+ explicitEffort,
9
+ planTurnEfforts,
10
+ type PromptMessage,
11
+ TURN_EFFORT_MODELS,
12
+ } from "../turn-effort";
13
+ import type { ProviderFactory, ProviderInstance } from "../types";
14
+ import { modelsEndpointFor, requireApiKey } from "./shared";
15
+
16
+ const DEFAULT_BASE_URL = "https://openrouter.ai/api/v1";
17
+
18
+ /** OpenRouter's own limit for the sticky-routing key. */
19
+ const MAX_SESSION_ID_LENGTH = 256;
20
+
21
+ /**
22
+ * Marks where an effort change goes. The SDK keeps nothing of a system message
23
+ * but its text, so the change travels as text and `fetch` turns it into the
24
+ * field OpenRouter reads. The NUL keeps it from ever matching a real prompt.
25
+ */
26
+ const TURN_SENTINEL = "\u0000turn-effort:";
27
+
28
+ /**
29
+ * Caching, in this vendor's dialect, for one request. Exported so tests can
30
+ * read the fields without an HTTP call. The SDK copies `providerOptions.openrouter`
31
+ * into the body as it is.
32
+ *
33
+ * A top-level `cache_control` is Anthropic's automatic mode: the breakpoint
34
+ * moves onto the last cacheable block as the conversation grows. Through
35
+ * OpenRouter it also covers Bedrock, Vertex and Azure, so provider fallback
36
+ * does not silently kill it.
37
+ */
38
+ export function openrouterRequestFields(cache: CacheOptions): RequestFields {
39
+ if (!cache.enabled) return {};
40
+
41
+ // OpenRouter knows two TTLs; a 24h intent (an OpenAI notion) lands on the
42
+ // longer one.
43
+ const fields: Record<string, unknown> = {
44
+ cache_control: { type: "ephemeral", ttl: cache.ttl === "5m" ? "5m" : "1h" },
45
+ };
46
+ // Sticky routing: keeps the follow-up request with the provider holding the
47
+ // warm cache.
48
+ if (cache.key !== undefined && cache.key.length <= MAX_SESSION_ID_LENGTH) {
49
+ fields["session_id"] = cache.key;
50
+ }
51
+ return { providerOptions: { openrouter: fields } };
52
+ }
53
+
54
+ type CallParams = Parameters<NonNullable<LanguageModelMiddleware["transformParams"]>>[0]["params"];
55
+
56
+ function withRequestEffort(params: CallParams, effort: ExplicitEffort | undefined): CallParams {
57
+ if (effort === undefined) return params;
58
+ const own = params.providerOptions?.["openrouter"];
59
+ return {
60
+ ...params,
61
+ providerOptions: { ...params.providerOptions, openrouter: { ...own, reasoning: { effort } } },
62
+ };
63
+ }
64
+
65
+ const sentinelFor = (level: ExplicitEffort): PromptMessage => ({
66
+ role: "system",
67
+ content: `${TURN_SENTINEL}${level}`,
68
+ });
69
+
70
+ /**
71
+ * `@openrouter/ai-sdk-provider` (3.0.0 and 3.1.0) never reads the portable
72
+ * `reasoning`, so this middleware writes the effort into the request: from a
73
+ * profile, or `"none"` from the classifier. It runs per call, not in
74
+ * `resolve()`, because the classifier sets the effort on the call itself.
75
+ *
76
+ * A profile's own `providerOptions.openrouter.reasoning` wins whole, never
77
+ * merged: OpenRouter takes `effort` or `max_tokens`, not both.
78
+ */
79
+ export function openrouterEffort(perTurn: boolean): LanguageModelMiddleware {
80
+ return {
81
+ specificationVersion: "v4",
82
+ async transformParams({ params }) {
83
+ if (params.providerOptions?.["openrouter"]?.["reasoning"] !== undefined) return params;
84
+ const current = explicitEffort(params.reasoning);
85
+
86
+ if (perTurn) {
87
+ const plan = planTurnEfforts(params.prompt, current, sentinelFor);
88
+ if (plan !== undefined) return withRequestEffort({ ...params, prompt: plan.prompt }, plan.base);
89
+ }
90
+ return withRequestEffort(params, current);
91
+ },
92
+ };
93
+ }
94
+
95
+ function sentinelLevel(message: unknown): string | undefined {
96
+ const { role, content } = (message ?? {}) as { role?: unknown; content?: unknown };
97
+ if (role !== "system") return undefined;
98
+ const text =
99
+ typeof content === "string"
100
+ ? content
101
+ : Array.isArray(content) && content.length === 1
102
+ ? (content[0] as { text?: unknown }).text
103
+ : undefined;
104
+ return typeof text === "string" && text.startsWith(TURN_SENTINEL)
105
+ ? text.slice(TURN_SENTINEL.length)
106
+ : undefined;
107
+ }
108
+
109
+ /** The sentinel, in the form OpenRouter documents for Chat Completions. */
110
+ export function withTurnUpdates(body: string): string {
111
+ if (!body.includes("turn-effort:")) return body;
112
+ const parsed = JSON.parse(body) as { messages?: unknown[] };
113
+ if (!Array.isArray(parsed.messages)) return body;
114
+
115
+ parsed.messages = parsed.messages.map((message) => {
116
+ const level = sentinelLevel(message);
117
+ return level === undefined
118
+ ? message
119
+ : { role: "system", content: "", configuration_update: { reasoning: { effort: level } } };
120
+ });
121
+ return JSON.stringify(parsed);
122
+ }
123
+
124
+ const turnUpdatesFetch: typeof globalThis.fetch = Object.assign(
125
+ async (input: Parameters<typeof globalThis.fetch>[0], init?: RequestInit) =>
126
+ globalThis.fetch(
127
+ input,
128
+ typeof init?.body === "string" ? { ...init, body: withTurnUpdates(init.body) } : init,
129
+ ),
130
+ { preconnect: globalThis.fetch.preconnect },
131
+ );
132
+
133
+ export const factory: ProviderFactory = (context): ProviderInstance => {
134
+ const baseURL = context.config.baseURL ?? DEFAULT_BASE_URL;
135
+ let client: ReturnType<typeof createOpenRouter> | null = null;
136
+
137
+ return {
138
+ languageModel(modelId) {
139
+ client ??= createOpenRouter({
140
+ apiKey: requireApiKey(context),
141
+ baseURL,
142
+ headers: { "X-Title": (context.app ?? WRAITH).name, ...context.config.headers },
143
+ ...context.config.options,
144
+ fetch: turnUpdatesFetch,
145
+ });
146
+ return wrapLanguageModel({
147
+ // Unconditional: without it OpenRouter returns no cost and no cache counters.
148
+ model: client.chat(modelId, { usage: { include: true } }),
149
+ middleware: openrouterEffort(TURN_EFFORT_MODELS.has(modelId)),
150
+ });
151
+ },
152
+ requestFields: openrouterRequestFields,
153
+ cacheSupport: "automatic",
154
+ modelsEndpoint: modelsEndpointFor(baseURL),
155
+ };
156
+ };
157
+
158
+ export interface OpenRouterOptions extends ProviderOptions {
159
+ apiKey: string;
160
+ }
161
+
162
+ /** OpenRouter from code: `openrouter({ apiKey }).model("anthropic/claude-sonnet-5.5")`. */
163
+ export function openrouter(options: OpenRouterOptions): Provider {
164
+ return providerFromFactory(factory, "openrouter", options);
165
+ }
@@ -0,0 +1,22 @@
1
+ import { AgentError } from "../../errors";
2
+ import type { ProviderFactoryContext } from "../types";
3
+
4
+ /**
5
+ * The key is demanded when a model is built, not when the provider is. Model
6
+ * catalogues are public, and needing a key to discover models before a
7
+ * provider can be configured would be circular.
8
+ */
9
+ export function requireApiKey(context: ProviderFactoryContext): string {
10
+ if (context.apiKey.trim() !== "") return context.apiKey;
11
+
12
+ throw new AgentError(
13
+ "config/missing-api-key",
14
+ `Provider "${context.name}" has no API key. Set ${context.config.apiKeyEnv ?? "its key environment variable"} or providers.${context.name}.apiKey.`,
15
+ { details: { provider: context.name, envVar: context.config.apiKeyEnv } },
16
+ );
17
+ }
18
+
19
+ /** Model catalogues live at `<baseURL>/models` for every provider we support. */
20
+ export function modelsEndpointFor(baseURL: string): string {
21
+ return `${baseURL.replace(/\/$/, "")}/models`;
22
+ }
@@ -0,0 +1,197 @@
1
+ import type { AppIdentity } from "../app";
2
+ import { type ModelPrices, resolvePrices } from "../agent/cost";
3
+ import type { ModelPricingConfig, ProviderConfig } from "../config/schema";
4
+ import {
5
+ type CacheDialect,
6
+ type CacheOptions,
7
+ type CacheTtl,
8
+ DEFAULT_CACHE_OPTIONS,
9
+ type RequestFields,
10
+ withCacheKey,
11
+ } from "./cache";
12
+ import type { ModelCapabilities, ModelInfo } from "./capabilities";
13
+ import { type CatalogView, catalogView, lookupInView } from "./catalog-view";
14
+ import type { OAuthCredential } from "./oauth";
15
+ import type {
16
+ AgentLanguageModel,
17
+ ModelCallSettings,
18
+ ProviderFactory,
19
+ ProviderInstance,
20
+ } from "./types";
21
+
22
+ /**
23
+ * A model as a value: what to call, what it costs, how large its window is,
24
+ * and what each request sends to stay on its cache. It knows no session, so
25
+ * one model serves any number of them.
26
+ */
27
+ export interface Model {
28
+ /**
29
+ * What it was asked for by — a profile, or "provider:model" — and what a
30
+ * resumed session asks for again. Absent for a bare SDK model.
31
+ */
32
+ readonly ref: string | undefined;
33
+ readonly providerName: string;
34
+ readonly modelId: string;
35
+ readonly languageModel: AgentLanguageModel;
36
+ /** A profile's settings: effort, temperature, the vendor's own options. */
37
+ readonly settings: ModelCallSettings;
38
+ /** What the catalog knows, through the provider's view; null when nothing. */
39
+ readonly info: ModelInfo | null;
40
+ /** The prices given for this model, else the catalog's. Absent is unknown, never free. */
41
+ readonly pricing: ModelPrices | undefined;
42
+ /** The window given for this model, else the catalog's. */
43
+ readonly contextLimit: number | undefined;
44
+ /** What a request keyed by `key` — a session's id, or a side mechanism's own — sends. */
45
+ requestFields(key: string | undefined): RequestFields;
46
+ /**
47
+ * False when the vendor's API takes images in a user message but not in a
48
+ * tool result; the loop then moves them. Absent: it takes them there.
49
+ */
50
+ readonly imagesInToolResults?: boolean;
51
+ }
52
+
53
+ export interface ModelOverrides {
54
+ /** Defaults to "provider:model". */
55
+ ref?: string;
56
+ settings?: ModelCallSettings;
57
+ /** Wins over the catalog's, whole: a price written by hand states this user's bill. */
58
+ pricing?: ModelPricingConfig;
59
+ contextLimit?: number;
60
+ }
61
+
62
+ /** Something that hands out models. Any object of this shape is a provider. */
63
+ export interface Provider {
64
+ /** What it is called in "name:model" references and in sessions. */
65
+ readonly name: string;
66
+ model(modelId: string, overrides?: ModelOverrides): Model;
67
+ }
68
+
69
+ export function isModel(value: Model | AgentLanguageModel): value is Model {
70
+ return "languageModel" in value;
71
+ }
72
+
73
+ /** A bare SDK model as a `Model`: its own ids, no catalog, no cache fields. */
74
+ export function toModel(value: Model | AgentLanguageModel): Model {
75
+ if (isModel(value)) return value;
76
+ return {
77
+ ref: undefined,
78
+ providerName: value.provider,
79
+ modelId: value.modelId,
80
+ languageModel: value,
81
+ settings: {},
82
+ info: null,
83
+ pricing: undefined,
84
+ contextLimit: undefined,
85
+ requestFields: () => ({}),
86
+ };
87
+ }
88
+
89
+ export interface ProviderSetup {
90
+ name: string;
91
+ /** Which catalog table this provider reads, and what its backend serves differently. */
92
+ view: CatalogView;
93
+ capabilities?: ModelCapabilities | undefined;
94
+ /** Without a key: each request adds its own. */
95
+ cache: CacheOptions;
96
+ }
97
+
98
+ /** A factory's instance as a `Provider`: the one place a `Model` is put together. */
99
+ export function providerFrom(instance: ProviderInstance, setup: ProviderSetup): Provider {
100
+ return {
101
+ name: setup.name,
102
+ model(modelId, overrides = {}) {
103
+ const languageModel = instance.languageModel(modelId);
104
+ const info =
105
+ setup.capabilities === undefined ? null : lookupInView(setup.capabilities, setup.view, modelId);
106
+ return {
107
+ ref: overrides.ref ?? `${setup.name}:${modelId}`,
108
+ providerName: setup.name,
109
+ modelId,
110
+ languageModel,
111
+ settings: overrides.settings ?? {},
112
+ info,
113
+ pricing: resolvePrices(info, overrides.pricing),
114
+ contextLimit: overrides.contextLimit ?? info?.contextLimit,
115
+ requestFields: (key) => instance.requestFields?.(withCacheKey(setup.cache, key)) ?? {},
116
+ ...(instance.imagesInToolResults === undefined ? {} : { imagesInToolResults: instance.imagesInToolResults }),
117
+ };
118
+ },
119
+ };
120
+ }
121
+
122
+ /** What every built-in provider takes besides its credentials. */
123
+ export interface ProviderOptions {
124
+ /** What it is called in "name:model" references and in sessions. Defaults to its type. */
125
+ name?: string;
126
+ baseURL?: string;
127
+ headers?: Record<string, string>;
128
+ /** Passed to the vendor's SDK as it is. */
129
+ options?: Record<string, unknown>;
130
+ /** Where windows and prices come from; without it they are unknown. */
131
+ capabilities?: ModelCapabilities;
132
+ /** On, for an hour, unless said otherwise. */
133
+ cache?: { enabled?: boolean; ttl?: CacheTtl; dialect?: CacheDialect };
134
+ /** Whose name a vendor is told is calling. */
135
+ app?: AppIdentity;
136
+ }
137
+
138
+ /** A built-in factory turned into a provider from code, with no config file. */
139
+ export function providerFromFactory(
140
+ factory: ProviderFactory,
141
+ type: string,
142
+ options: ProviderOptions & {
143
+ apiKey?: string;
144
+ credential?: () => Promise<OAuthCredential>;
145
+ },
146
+ ): Provider {
147
+ const name = options.name ?? type;
148
+ const config: ProviderConfig = {
149
+ type,
150
+ headers: options.headers ?? {},
151
+ options: options.options ?? {},
152
+ ...(options.baseURL === undefined ? {} : { baseURL: options.baseURL }),
153
+ ...(options.cache === undefined ? {} : { cache: options.cache }),
154
+ };
155
+ const instance = factory({
156
+ name,
157
+ apiKey: options.apiKey ?? "",
158
+ config,
159
+ ...(options.app === undefined ? {} : { app: options.app }),
160
+ ...(options.credential === undefined ? {} : { credential: options.credential }),
161
+ });
162
+ return providerFrom(instance, {
163
+ name,
164
+ view: catalogView(name, type),
165
+ capabilities: options.capabilities,
166
+ cache: {
167
+ enabled: options.cache?.enabled ?? DEFAULT_CACHE_OPTIONS.enabled,
168
+ ttl: options.cache?.ttl ?? DEFAULT_CACHE_OPTIONS.ttl,
169
+ ...(options.cache?.dialect === undefined ? {} : { dialect: options.cache.dialect }),
170
+ },
171
+ });
172
+ }
173
+
174
+ /** An AI SDK provider (`createMistral(...)`, `createAnthropic(...)`) as a `Provider`. */
175
+ export function fromAiSdk(
176
+ name: string,
177
+ sdk: { languageModel(modelId: string): AgentLanguageModel },
178
+ options: {
179
+ capabilities?: ModelCapabilities;
180
+ table?: string;
181
+ /** False for an SDK that sends a tool result as text only, such as one built on Chat Completions. */
182
+ imagesInToolResults?: boolean;
183
+ } = {},
184
+ ): Provider {
185
+ return providerFrom(
186
+ {
187
+ languageModel: (modelId) => sdk.languageModel(modelId),
188
+ ...(options.imagesInToolResults === undefined ? {} : { imagesInToolResults: options.imagesInToolResults }),
189
+ },
190
+ {
191
+ name,
192
+ view: { table: options.table ?? name },
193
+ capabilities: options.capabilities,
194
+ cache: DEFAULT_CACHE_OPTIONS,
195
+ },
196
+ );
197
+ }