@gitpagedocs/tools 1.1.61 → 1.1.63

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 (58) hide show
  1. package/README.md +33 -33
  2. package/package.json +1 -1
  3. package/src/ai/bootstrap.ts +50 -50
  4. package/src/ai/catalog.ts +188 -188
  5. package/src/ai/factory.ts +14 -14
  6. package/src/ai/http/streaming.ts +60 -60
  7. package/src/ai/index.ts +27 -27
  8. package/src/ai/legacy-adapter.ts +33 -33
  9. package/src/ai/model-registry.ts +13 -13
  10. package/src/ai/providers/anthropic-provider.ts +83 -83
  11. package/src/ai/providers/cohere-provider.ts +66 -66
  12. package/src/ai/providers/gemini-provider.ts +84 -84
  13. package/src/ai/providers/ollama-provider.ts +69 -69
  14. package/src/ai/providers/openai-compatible-provider.ts +75 -75
  15. package/src/ai/providers/shared.ts +72 -72
  16. package/src/ai/registry.ts +29 -29
  17. package/src/cache/file-cache.ts +86 -86
  18. package/src/cache/index.ts +9 -9
  19. package/src/cache/memory-cache.ts +47 -47
  20. package/src/cache/web-storage-cache.ts +91 -91
  21. package/src/config/config-loader.ts +59 -59
  22. package/src/config/index.ts +1 -1
  23. package/src/constants/config.ts +8 -8
  24. package/src/constants/index.ts +1 -1
  25. package/src/crypto/doc-access.ts +62 -62
  26. package/src/crypto/index.ts +4 -4
  27. package/src/crypto/node-crypto-service.ts +87 -87
  28. package/src/crypto/web-crypto-service.ts +102 -102
  29. package/src/crypto/web.ts +4 -4
  30. package/src/documentation/doc-generator.ts +74 -74
  31. package/src/documentation/doc-updater.ts +47 -47
  32. package/src/documentation/index.ts +18 -18
  33. package/src/documentation/marker-patcher.ts +33 -33
  34. package/src/documentation/sections.ts +84 -84
  35. package/src/errors/app-error.ts +84 -84
  36. package/src/errors/index.ts +1 -1
  37. package/src/filesystem/file-service.ts +121 -121
  38. package/src/filesystem/index.ts +2 -2
  39. package/src/index.ts +25 -25
  40. package/src/logger/index.ts +2 -2
  41. package/src/logger/logger.ts +73 -73
  42. package/src/logger/redaction.ts +43 -43
  43. package/src/platform/index.ts +1 -1
  44. package/src/platform/user-config-dir.ts +48 -48
  45. package/src/ports/ai.ts +109 -109
  46. package/src/ports/cache.ts +16 -16
  47. package/src/ports/config.ts +21 -21
  48. package/src/ports/crypto.ts +33 -33
  49. package/src/ports/index.ts +15 -15
  50. package/src/ports/logger.ts +23 -23
  51. package/src/ports/security.ts +42 -42
  52. package/src/security/credential-vault.ts +117 -117
  53. package/src/security/file-vault-storage.ts +25 -25
  54. package/src/security/index.ts +8 -8
  55. package/src/security/migrate-plaintext-key.ts +38 -38
  56. package/src/security/password-gate.ts +62 -62
  57. package/src/security/web-storage-vault-storage.ts +23 -23
  58. package/src/security/web.ts +9 -9
package/README.md CHANGED
@@ -1,33 +1,33 @@
1
- # @gitpagedocs/tools
2
-
3
- The **shared business-logic core** of the [Git Page Docs](../README.md) monorepo — the single home for domain logic consumed by the frontend, the CLI, and the MCP server. It ships **TypeScript source** and is consumed via `tsx` (CLI/MCP) or a TS-aware bundler (Next `transpilePackages`).
4
-
5
- ## Modules (`src/`)
6
-
7
- | Module | Responsibility |
8
- |---|---|
9
- | `ai/` | 14-provider AI system — data-driven `PROVIDER_CATALOG`, registry + factory (no switch chains), 5 family adapters (OpenAI-compatible, Anthropic, Gemini, Ollama, Cohere), SSE/NDJSON streaming, legacy↔catalog id mapping |
10
- | `security/` | `EncryptedCredentialVault` (AES-256-GCM), `SessionPasswordGate`, plaintext migration; web + file storage adapters |
11
- | `crypto/` | `NodeCryptoService` + `WebCryptoService` (SHA-256, PBKDF2, AES-256-GCM, masking, secure wipe); `deriveDocAccessKeys` / `verifyDocAccess` (double-hash documentation password gate shared by the CLI `password` command and the frontend gate) |
12
- | `cache/` | `MemoryCache`, `FileCache`, `WebStorageCache` (Strategy over one `Cache` port) |
13
- | `config/` | `GitPageDocsConfigLoader` (`.json` / `.js` / `.ts`) |
14
- | `logger/` | Level-filtered logger with **secret redaction** |
15
- | `errors/` | `AppError` + typed subclasses |
16
- | `filesystem/` | `FileService` (root-bounded list/read/write/search) |
17
- | `documentation/` | `DocumentationService`, `patchManagedRegion`, `DocUpdater` |
18
- | `ports/` | Type-only contracts (logger, cache, crypto, security, config, ai) |
19
-
20
- ## Entry points (`exports`)
21
-
22
- `.` (full barrel) · `./ai` · `./errors` · `./ports` · `./crypto/web` · `./security/web` · `./cache/web` — the `web` subpaths are browser-safe (no `node:` imports) for the Next.js bundle.
23
-
24
- ## Usage
25
-
26
- ```ts
27
- import { createDefaultFactory, PROVIDER_CATALOG } from "@gitpagedocs/tools/ai";
28
- import { EncryptedCredentialVault } from "@gitpagedocs/tools/security/web";
29
- ```
30
-
31
- ## Tests
32
-
33
- Unit + integration + E2E live in `tools/tests/**` (Vitest); self-tests in `tools/smoke/**`. Run from the repo root: `npx vitest run` and `npm run smoke:all`.
1
+ # @gitpagedocs/tools
2
+
3
+ The **shared business-logic core** of the [Git Page Docs](../README.md) monorepo — the single home for domain logic consumed by the frontend, the CLI, and the MCP server. It ships **TypeScript source** and is consumed via `tsx` (CLI/MCP) or a TS-aware bundler (Next `transpilePackages`).
4
+
5
+ ## Modules (`src/`)
6
+
7
+ | Module | Responsibility |
8
+ |---|---|
9
+ | `ai/` | 14-provider AI system — data-driven `PROVIDER_CATALOG`, registry + factory (no switch chains), 5 family adapters (OpenAI-compatible, Anthropic, Gemini, Ollama, Cohere), SSE/NDJSON streaming, legacy↔catalog id mapping |
10
+ | `security/` | `EncryptedCredentialVault` (AES-256-GCM), `SessionPasswordGate`, plaintext migration; web + file storage adapters |
11
+ | `crypto/` | `NodeCryptoService` + `WebCryptoService` (SHA-256, PBKDF2, AES-256-GCM, masking, secure wipe); `deriveDocAccessKeys` / `verifyDocAccess` (double-hash documentation password gate shared by the CLI `password` command and the frontend gate) |
12
+ | `cache/` | `MemoryCache`, `FileCache`, `WebStorageCache` (Strategy over one `Cache` port) |
13
+ | `config/` | `GitPageDocsConfigLoader` (`.json` / `.js` / `.ts`) |
14
+ | `logger/` | Level-filtered logger with **secret redaction** |
15
+ | `errors/` | `AppError` + typed subclasses |
16
+ | `filesystem/` | `FileService` (root-bounded list/read/write/search) |
17
+ | `documentation/` | `DocumentationService`, `patchManagedRegion`, `DocUpdater` |
18
+ | `ports/` | Type-only contracts (logger, cache, crypto, security, config, ai) |
19
+
20
+ ## Entry points (`exports`)
21
+
22
+ `.` (full barrel) · `./ai` · `./errors` · `./ports` · `./crypto/web` · `./security/web` · `./cache/web` — the `web` subpaths are browser-safe (no `node:` imports) for the Next.js bundle.
23
+
24
+ ## Usage
25
+
26
+ ```ts
27
+ import { createDefaultFactory, PROVIDER_CATALOG } from "@gitpagedocs/tools/ai";
28
+ import { EncryptedCredentialVault } from "@gitpagedocs/tools/security/web";
29
+ ```
30
+
31
+ ## Tests
32
+
33
+ Unit + integration + E2E live in `tools/tests/**` (Vitest); self-tests in `tools/smoke/**`. Run from the repo root: `npx vitest run` and `npm run smoke:all`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitpagedocs/tools",
3
- "version": "1.1.61",
3
+ "version": "1.1.63",
4
4
  "type": "module",
5
5
  "description": "Shared business-logic core for Git Page Docs (consumed by frontend, cli and mcp). Ships TypeScript source; consume via tsx or a TS-aware bundler.",
6
6
  "main": "./src/index.ts",
@@ -1,50 +1,50 @@
1
- import type { AIProvider, ProviderRegistration } from "../ports/ai";
2
- import { PROVIDER_CATALOG, type ProviderFamily, type ProviderSpec } from "./catalog";
3
- import { InMemoryProviderRegistry } from "./registry";
4
- import { RegistryProviderFactory } from "./factory";
5
- import { CatalogModelRegistry } from "./model-registry";
6
- import type { FetchLike } from "./http/streaming";
7
- import { OpenAiCompatibleProvider } from "./providers/openai-compatible-provider";
8
- import { AnthropicProvider } from "./providers/anthropic-provider";
9
- import { GeminiProvider } from "./providers/gemini-provider";
10
- import { OllamaProvider } from "./providers/ollama-provider";
11
- import { CohereProvider } from "./providers/cohere-provider";
12
-
13
- /** Maps a provider family to its adapter constructor (small Factory table). */
14
- type AdapterCtor = new (spec: ProviderSpec, fetchImpl?: FetchLike) => AIProvider;
15
-
16
- const FAMILY_ADAPTERS: Record<ProviderFamily, AdapterCtor> = {
17
- "openai-compatible": OpenAiCompatibleProvider,
18
- anthropic: AnthropicProvider,
19
- gemini: GeminiProvider,
20
- ollama: OllamaProvider,
21
- cohere: CohereProvider,
22
- };
23
-
24
- function toRegistration(spec: ProviderSpec, fetchImpl?: FetchLike): ProviderRegistration {
25
- const Adapter = FAMILY_ADAPTERS[spec.family];
26
- return {
27
- id: spec.id,
28
- label: spec.label,
29
- defaultModel: spec.defaultModel,
30
- capabilities: spec.capabilities,
31
- create: () => new Adapter(spec, fetchImpl),
32
- };
33
- }
34
-
35
- /** Registry pre-populated with every catalog provider. */
36
- export function createDefaultRegistry(fetchImpl?: FetchLike): InMemoryProviderRegistry {
37
- const registry = new InMemoryProviderRegistry();
38
- for (const spec of Object.values(PROVIDER_CATALOG)) {
39
- registry.register(toRegistration(spec, fetchImpl));
40
- }
41
- return registry;
42
- }
43
-
44
- export function createDefaultFactory(fetchImpl?: FetchLike): RegistryProviderFactory {
45
- return new RegistryProviderFactory(createDefaultRegistry(fetchImpl));
46
- }
47
-
48
- export function createModelRegistry(): CatalogModelRegistry {
49
- return new CatalogModelRegistry();
50
- }
1
+ import type { AIProvider, ProviderRegistration } from "../ports/ai";
2
+ import { PROVIDER_CATALOG, type ProviderFamily, type ProviderSpec } from "./catalog";
3
+ import { InMemoryProviderRegistry } from "./registry";
4
+ import { RegistryProviderFactory } from "./factory";
5
+ import { CatalogModelRegistry } from "./model-registry";
6
+ import type { FetchLike } from "./http/streaming";
7
+ import { OpenAiCompatibleProvider } from "./providers/openai-compatible-provider";
8
+ import { AnthropicProvider } from "./providers/anthropic-provider";
9
+ import { GeminiProvider } from "./providers/gemini-provider";
10
+ import { OllamaProvider } from "./providers/ollama-provider";
11
+ import { CohereProvider } from "./providers/cohere-provider";
12
+
13
+ /** Maps a provider family to its adapter constructor (small Factory table). */
14
+ type AdapterCtor = new (spec: ProviderSpec, fetchImpl?: FetchLike) => AIProvider;
15
+
16
+ const FAMILY_ADAPTERS: Record<ProviderFamily, AdapterCtor> = {
17
+ "openai-compatible": OpenAiCompatibleProvider,
18
+ anthropic: AnthropicProvider,
19
+ gemini: GeminiProvider,
20
+ ollama: OllamaProvider,
21
+ cohere: CohereProvider,
22
+ };
23
+
24
+ function toRegistration(spec: ProviderSpec, fetchImpl?: FetchLike): ProviderRegistration {
25
+ const Adapter = FAMILY_ADAPTERS[spec.family];
26
+ return {
27
+ id: spec.id,
28
+ label: spec.label,
29
+ defaultModel: spec.defaultModel,
30
+ capabilities: spec.capabilities,
31
+ create: () => new Adapter(spec, fetchImpl),
32
+ };
33
+ }
34
+
35
+ /** Registry pre-populated with every catalog provider. */
36
+ export function createDefaultRegistry(fetchImpl?: FetchLike): InMemoryProviderRegistry {
37
+ const registry = new InMemoryProviderRegistry();
38
+ for (const spec of Object.values(PROVIDER_CATALOG)) {
39
+ registry.register(toRegistration(spec, fetchImpl));
40
+ }
41
+ return registry;
42
+ }
43
+
44
+ export function createDefaultFactory(fetchImpl?: FetchLike): RegistryProviderFactory {
45
+ return new RegistryProviderFactory(createDefaultRegistry(fetchImpl));
46
+ }
47
+
48
+ export function createModelRegistry(): CatalogModelRegistry {
49
+ return new CatalogModelRegistry();
50
+ }
package/src/ai/catalog.ts CHANGED
@@ -1,188 +1,188 @@
1
- import type { AiProviderId, ModelDescriptor, ProviderCapabilities } from "../ports/ai";
2
-
3
- /**
4
- * Single source of truth for AI providers. Adding a provider = adding a catalog
5
- * entry; the registry/factory are data-driven, so there is no switch to grow.
6
- */
7
- export type ProviderFamily =
8
- | "openai-compatible"
9
- | "anthropic"
10
- | "gemini"
11
- | "ollama"
12
- | "cohere";
13
-
14
- export type AuthStyle = "bearer" | "x-api-key" | "query-key" | "api-key-header" | "none";
15
-
16
- export interface ProviderSpec {
17
- readonly id: AiProviderId;
18
- readonly label: string;
19
- readonly family: ProviderFamily;
20
- readonly defaultModel: string;
21
- /** Default API base URL (without the chat path). */
22
- readonly baseUrl: string;
23
- /** Provider needs a user-supplied baseUrl (Azure deployment, local Ollama). */
24
- readonly requiresBaseUrl?: boolean;
25
- readonly auth: AuthStyle;
26
- readonly capabilities: ProviderCapabilities;
27
- readonly models: readonly ModelDescriptor[];
28
- }
29
-
30
- const TEXT: ProviderCapabilities = { streaming: true, vision: false, audio: false };
31
- const VISION: ProviderCapabilities = { streaming: true, vision: true, audio: false };
32
- const VISION_AUDIO: ProviderCapabilities = { streaming: true, vision: true, audio: true };
33
-
34
- function models(...ids: string[]): ModelDescriptor[] {
35
- return ids.map((id) => ({ id }));
36
- }
37
-
38
- export const PROVIDER_CATALOG: Readonly<Record<AiProviderId, ProviderSpec>> = {
39
- openai: {
40
- id: "openai",
41
- label: "OpenAI",
42
- family: "openai-compatible",
43
- defaultModel: "gpt-4o-mini",
44
- baseUrl: "https://api.openai.com/v1",
45
- auth: "bearer",
46
- capabilities: VISION,
47
- models: models("gpt-4o", "gpt-4o-mini", "o3-mini", "o1"),
48
- },
49
- anthropic: {
50
- id: "anthropic",
51
- label: "Anthropic",
52
- family: "anthropic",
53
- // Latest Claude API model IDs.
54
- defaultModel: "claude-sonnet-4-6",
55
- baseUrl: "https://api.anthropic.com/v1",
56
- auth: "x-api-key",
57
- capabilities: VISION,
58
- models: models("claude-opus-4-8", "claude-sonnet-4-6", "claude-haiku-4-5-20251001"),
59
- },
60
- gemini: {
61
- id: "gemini",
62
- label: "Google Gemini",
63
- family: "gemini",
64
- defaultModel: "gemini-2.0-flash",
65
- baseUrl: "https://generativelanguage.googleapis.com/v1beta/models",
66
- auth: "query-key",
67
- capabilities: VISION_AUDIO,
68
- models: models("gemini-2.0-flash", "gemini-1.5-pro", "gemini-1.5-flash"),
69
- },
70
- openrouter: {
71
- id: "openrouter",
72
- label: "OpenRouter",
73
- family: "openai-compatible",
74
- defaultModel: "openai/gpt-4o-mini",
75
- baseUrl: "https://openrouter.ai/api/v1",
76
- auth: "bearer",
77
- capabilities: VISION,
78
- models: models("openai/gpt-4o-mini", "anthropic/claude-sonnet-4-6", "google/gemini-2.0-flash-exp"),
79
- },
80
- ollama: {
81
- id: "ollama",
82
- label: "Ollama (local)",
83
- family: "ollama",
84
- defaultModel: "llama3",
85
- baseUrl: "http://localhost:11434",
86
- requiresBaseUrl: false,
87
- auth: "none",
88
- capabilities: VISION,
89
- models: models("llama3", "llama3.1", "mistral", "qwen2.5"),
90
- },
91
- "azure-openai": {
92
- id: "azure-openai",
93
- label: "Azure OpenAI",
94
- family: "openai-compatible",
95
- defaultModel: "gpt-4o-mini",
96
- baseUrl: "",
97
- requiresBaseUrl: true,
98
- auth: "api-key-header",
99
- capabilities: VISION,
100
- models: models("gpt-4o", "gpt-4o-mini"),
101
- },
102
- mistral: {
103
- id: "mistral",
104
- label: "Mistral",
105
- family: "openai-compatible",
106
- defaultModel: "mistral-large-latest",
107
- baseUrl: "https://api.mistral.ai/v1",
108
- auth: "bearer",
109
- capabilities: TEXT,
110
- models: models("mistral-large-latest", "mistral-small-latest", "open-mistral-nemo"),
111
- },
112
- deepseek: {
113
- id: "deepseek",
114
- label: "DeepSeek",
115
- family: "openai-compatible",
116
- defaultModel: "deepseek-chat",
117
- baseUrl: "https://api.deepseek.com/v1",
118
- auth: "bearer",
119
- capabilities: TEXT,
120
- models: models("deepseek-chat", "deepseek-reasoner"),
121
- },
122
- cohere: {
123
- id: "cohere",
124
- label: "Cohere",
125
- family: "cohere",
126
- defaultModel: "command-r-plus",
127
- baseUrl: "https://api.cohere.com/v2",
128
- auth: "bearer",
129
- capabilities: TEXT,
130
- models: models("command-r-plus", "command-r"),
131
- },
132
- groq: {
133
- id: "groq",
134
- label: "Groq",
135
- family: "openai-compatible",
136
- defaultModel: "llama-3.3-70b-versatile",
137
- baseUrl: "https://api.groq.com/openai/v1",
138
- auth: "bearer",
139
- capabilities: TEXT,
140
- models: models("llama-3.3-70b-versatile", "llama-3.1-8b-instant", "mixtral-8x7b-32768"),
141
- },
142
- xai: {
143
- id: "xai",
144
- label: "xAI Grok",
145
- family: "openai-compatible",
146
- defaultModel: "grok-2-latest",
147
- baseUrl: "https://api.x.ai/v1",
148
- auth: "bearer",
149
- capabilities: VISION,
150
- models: models("grok-2-latest", "grok-2-vision-latest"),
151
- },
152
- together: {
153
- id: "together",
154
- label: "Together AI",
155
- family: "openai-compatible",
156
- defaultModel: "meta-llama/Llama-3.3-70B-Instruct-Turbo",
157
- baseUrl: "https://api.together.xyz/v1",
158
- auth: "bearer",
159
- capabilities: TEXT,
160
- models: models("meta-llama/Llama-3.3-70B-Instruct-Turbo", "mistralai/Mixtral-8x7B-Instruct-v0.1"),
161
- },
162
- fireworks: {
163
- id: "fireworks",
164
- label: "Fireworks AI",
165
- family: "openai-compatible",
166
- defaultModel: "accounts/fireworks/models/llama-v3p3-70b-instruct",
167
- baseUrl: "https://api.fireworks.ai/inference/v1",
168
- auth: "bearer",
169
- capabilities: TEXT,
170
- models: models("accounts/fireworks/models/llama-v3p3-70b-instruct"),
171
- },
172
- perplexity: {
173
- id: "perplexity",
174
- label: "Perplexity",
175
- family: "openai-compatible",
176
- defaultModel: "sonar",
177
- baseUrl: "https://api.perplexity.ai",
178
- auth: "bearer",
179
- capabilities: TEXT,
180
- models: models("sonar", "sonar-pro", "sonar-reasoning"),
181
- },
182
- };
183
-
184
- export const ALL_PROVIDER_IDS = Object.keys(PROVIDER_CATALOG) as AiProviderId[];
185
-
186
- export function getProviderSpec(id: AiProviderId): ProviderSpec {
187
- return PROVIDER_CATALOG[id];
188
- }
1
+ import type { AiProviderId, ModelDescriptor, ProviderCapabilities } from "../ports/ai";
2
+
3
+ /**
4
+ * Single source of truth for AI providers. Adding a provider = adding a catalog
5
+ * entry; the registry/factory are data-driven, so there is no switch to grow.
6
+ */
7
+ export type ProviderFamily =
8
+ | "openai-compatible"
9
+ | "anthropic"
10
+ | "gemini"
11
+ | "ollama"
12
+ | "cohere";
13
+
14
+ export type AuthStyle = "bearer" | "x-api-key" | "query-key" | "api-key-header" | "none";
15
+
16
+ export interface ProviderSpec {
17
+ readonly id: AiProviderId;
18
+ readonly label: string;
19
+ readonly family: ProviderFamily;
20
+ readonly defaultModel: string;
21
+ /** Default API base URL (without the chat path). */
22
+ readonly baseUrl: string;
23
+ /** Provider needs a user-supplied baseUrl (Azure deployment, local Ollama). */
24
+ readonly requiresBaseUrl?: boolean;
25
+ readonly auth: AuthStyle;
26
+ readonly capabilities: ProviderCapabilities;
27
+ readonly models: readonly ModelDescriptor[];
28
+ }
29
+
30
+ const TEXT: ProviderCapabilities = { streaming: true, vision: false, audio: false };
31
+ const VISION: ProviderCapabilities = { streaming: true, vision: true, audio: false };
32
+ const VISION_AUDIO: ProviderCapabilities = { streaming: true, vision: true, audio: true };
33
+
34
+ function models(...ids: string[]): ModelDescriptor[] {
35
+ return ids.map((id) => ({ id }));
36
+ }
37
+
38
+ export const PROVIDER_CATALOG: Readonly<Record<AiProviderId, ProviderSpec>> = {
39
+ openai: {
40
+ id: "openai",
41
+ label: "OpenAI",
42
+ family: "openai-compatible",
43
+ defaultModel: "gpt-4o-mini",
44
+ baseUrl: "https://api.openai.com/v1",
45
+ auth: "bearer",
46
+ capabilities: VISION,
47
+ models: models("gpt-4o", "gpt-4o-mini", "o3-mini", "o1"),
48
+ },
49
+ anthropic: {
50
+ id: "anthropic",
51
+ label: "Anthropic",
52
+ family: "anthropic",
53
+ // Latest Claude API model IDs.
54
+ defaultModel: "claude-sonnet-4-6",
55
+ baseUrl: "https://api.anthropic.com/v1",
56
+ auth: "x-api-key",
57
+ capabilities: VISION,
58
+ models: models("claude-opus-4-8", "claude-sonnet-4-6", "claude-haiku-4-5-20251001"),
59
+ },
60
+ gemini: {
61
+ id: "gemini",
62
+ label: "Google Gemini",
63
+ family: "gemini",
64
+ defaultModel: "gemini-2.0-flash",
65
+ baseUrl: "https://generativelanguage.googleapis.com/v1beta/models",
66
+ auth: "query-key",
67
+ capabilities: VISION_AUDIO,
68
+ models: models("gemini-2.0-flash", "gemini-1.5-pro", "gemini-1.5-flash"),
69
+ },
70
+ openrouter: {
71
+ id: "openrouter",
72
+ label: "OpenRouter",
73
+ family: "openai-compatible",
74
+ defaultModel: "openai/gpt-4o-mini",
75
+ baseUrl: "https://openrouter.ai/api/v1",
76
+ auth: "bearer",
77
+ capabilities: VISION,
78
+ models: models("openai/gpt-4o-mini", "anthropic/claude-sonnet-4-6", "google/gemini-2.0-flash-exp"),
79
+ },
80
+ ollama: {
81
+ id: "ollama",
82
+ label: "Ollama (local)",
83
+ family: "ollama",
84
+ defaultModel: "llama3",
85
+ baseUrl: "http://localhost:11434",
86
+ requiresBaseUrl: false,
87
+ auth: "none",
88
+ capabilities: VISION,
89
+ models: models("llama3", "llama3.1", "mistral", "qwen2.5"),
90
+ },
91
+ "azure-openai": {
92
+ id: "azure-openai",
93
+ label: "Azure OpenAI",
94
+ family: "openai-compatible",
95
+ defaultModel: "gpt-4o-mini",
96
+ baseUrl: "",
97
+ requiresBaseUrl: true,
98
+ auth: "api-key-header",
99
+ capabilities: VISION,
100
+ models: models("gpt-4o", "gpt-4o-mini"),
101
+ },
102
+ mistral: {
103
+ id: "mistral",
104
+ label: "Mistral",
105
+ family: "openai-compatible",
106
+ defaultModel: "mistral-large-latest",
107
+ baseUrl: "https://api.mistral.ai/v1",
108
+ auth: "bearer",
109
+ capabilities: TEXT,
110
+ models: models("mistral-large-latest", "mistral-small-latest", "open-mistral-nemo"),
111
+ },
112
+ deepseek: {
113
+ id: "deepseek",
114
+ label: "DeepSeek",
115
+ family: "openai-compatible",
116
+ defaultModel: "deepseek-chat",
117
+ baseUrl: "https://api.deepseek.com/v1",
118
+ auth: "bearer",
119
+ capabilities: TEXT,
120
+ models: models("deepseek-chat", "deepseek-reasoner"),
121
+ },
122
+ cohere: {
123
+ id: "cohere",
124
+ label: "Cohere",
125
+ family: "cohere",
126
+ defaultModel: "command-r-plus",
127
+ baseUrl: "https://api.cohere.com/v2",
128
+ auth: "bearer",
129
+ capabilities: TEXT,
130
+ models: models("command-r-plus", "command-r"),
131
+ },
132
+ groq: {
133
+ id: "groq",
134
+ label: "Groq",
135
+ family: "openai-compatible",
136
+ defaultModel: "llama-3.3-70b-versatile",
137
+ baseUrl: "https://api.groq.com/openai/v1",
138
+ auth: "bearer",
139
+ capabilities: TEXT,
140
+ models: models("llama-3.3-70b-versatile", "llama-3.1-8b-instant", "mixtral-8x7b-32768"),
141
+ },
142
+ xai: {
143
+ id: "xai",
144
+ label: "xAI Grok",
145
+ family: "openai-compatible",
146
+ defaultModel: "grok-2-latest",
147
+ baseUrl: "https://api.x.ai/v1",
148
+ auth: "bearer",
149
+ capabilities: VISION,
150
+ models: models("grok-2-latest", "grok-2-vision-latest"),
151
+ },
152
+ together: {
153
+ id: "together",
154
+ label: "Together AI",
155
+ family: "openai-compatible",
156
+ defaultModel: "meta-llama/Llama-3.3-70B-Instruct-Turbo",
157
+ baseUrl: "https://api.together.xyz/v1",
158
+ auth: "bearer",
159
+ capabilities: TEXT,
160
+ models: models("meta-llama/Llama-3.3-70B-Instruct-Turbo", "mistralai/Mixtral-8x7B-Instruct-v0.1"),
161
+ },
162
+ fireworks: {
163
+ id: "fireworks",
164
+ label: "Fireworks AI",
165
+ family: "openai-compatible",
166
+ defaultModel: "accounts/fireworks/models/llama-v3p3-70b-instruct",
167
+ baseUrl: "https://api.fireworks.ai/inference/v1",
168
+ auth: "bearer",
169
+ capabilities: TEXT,
170
+ models: models("accounts/fireworks/models/llama-v3p3-70b-instruct"),
171
+ },
172
+ perplexity: {
173
+ id: "perplexity",
174
+ label: "Perplexity",
175
+ family: "openai-compatible",
176
+ defaultModel: "sonar",
177
+ baseUrl: "https://api.perplexity.ai",
178
+ auth: "bearer",
179
+ capabilities: TEXT,
180
+ models: models("sonar", "sonar-pro", "sonar-reasoning"),
181
+ },
182
+ };
183
+
184
+ export const ALL_PROVIDER_IDS = Object.keys(PROVIDER_CATALOG) as AiProviderId[];
185
+
186
+ export function getProviderSpec(id: AiProviderId): ProviderSpec {
187
+ return PROVIDER_CATALOG[id];
188
+ }
package/src/ai/factory.ts CHANGED
@@ -1,14 +1,14 @@
1
- import type { AIProvider, AiProviderId, ProviderFactory } from "../ports/ai";
2
- import type { InMemoryProviderRegistry } from "./registry";
3
- import { ProviderError } from "../errors/app-error";
4
-
5
- /** Creates provider strategies from the registry (Factory pattern). */
6
- export class RegistryProviderFactory implements ProviderFactory {
7
- constructor(private readonly registry: InMemoryProviderRegistry) {}
8
-
9
- create(id: AiProviderId): AIProvider {
10
- const registration = this.registry.get(id);
11
- if (!registration) throw new ProviderError(`Unknown AI provider: ${id}`, { details: { provider: id } });
12
- return registration.create();
13
- }
14
- }
1
+ import type { AIProvider, AiProviderId, ProviderFactory } from "../ports/ai";
2
+ import type { InMemoryProviderRegistry } from "./registry";
3
+ import { ProviderError } from "../errors/app-error";
4
+
5
+ /** Creates provider strategies from the registry (Factory pattern). */
6
+ export class RegistryProviderFactory implements ProviderFactory {
7
+ constructor(private readonly registry: InMemoryProviderRegistry) {}
8
+
9
+ create(id: AiProviderId): AIProvider {
10
+ const registration = this.registry.get(id);
11
+ if (!registration) throw new ProviderError(`Unknown AI provider: ${id}`, { details: { provider: id } });
12
+ return registration.create();
13
+ }
14
+ }