@inkdropapp/ai 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,7 +4,7 @@ Headless TypeScript library for multi-provider AI integration. Designed to run
4
4
  in the Inkdrop Electron main process.
5
5
 
6
6
  - **Two-interface design** — `AIProvider` (auth + model catalogue) is separate from `AIModel` (capabilities + streaming).
7
- - **Registry with task-slot routing** — slot binding plus fallback to per-provider defaults, so a single AI feature gets a sensible model without any user setup.
7
+ - **AIRegistry with task-slot routing** — slot binding plus fallback to per-provider defaults, so a single AI feature gets a sensible model without any user setup.
8
8
  - **Two providers ship out of the box**:
9
9
  - `AnthropicProvider` (Claude 4.x) — built-in model catalogue, prompt-cache configuration.
10
10
  - `OpenAICompatibleProvider` — instantiated per user-named entry; covers OpenRouter, Together, Fireworks, Groq, vLLM, Ollama (`/v1`), LiteLLM, etc. with a single class.
@@ -31,7 +31,7 @@ The package is **ESM-only**. Use `import`, not `require`.
31
31
  ## Quickstart
32
32
 
33
33
  ```ts
34
- import { Registry, type AISettings } from '@inkdropapp/ai'
34
+ import { AIRegistry, type AISettings } from '@inkdropapp/ai'
35
35
 
36
36
  const settings: AISettings = {
37
37
  providers: {
@@ -48,7 +48,7 @@ const settings: AISettings = {
48
48
  providerId: 'anthropic'
49
49
  }
50
50
 
51
- const registry = new Registry({ settings })
51
+ const registry = new AIRegistry({ settings })
52
52
 
53
53
  // Configure once — keys go to the system keyring (or env var).
54
54
  const anthropic = registry.getProvider('anthropic')!
@@ -142,7 +142,7 @@ An `AIModelCatalog` is a per-provider override of that list, designed to be
142
142
  distributed by a server endpoint and swapped in at runtime:
143
143
 
144
144
  ```ts
145
- import { Registry, type AIModelCatalog } from '@inkdropapp/ai'
145
+ import { AIRegistry, type AIModelCatalog } from '@inkdropapp/ai'
146
146
 
147
147
  const catalog: AIModelCatalog = {
148
148
  anthropic: {
@@ -170,14 +170,14 @@ const catalog: AIModelCatalog = {
170
170
  }
171
171
  }
172
172
 
173
- const registry = new Registry({ settings, catalog })
173
+ const registry = new AIRegistry({ settings, catalog })
174
174
  ```
175
175
 
176
176
  Resolution order, from highest to lowest priority:
177
177
 
178
178
  1. **User-declared `config.models`** (`settings.providers.<name>.models`) — the
179
179
  user's local overrides always win, regardless of where the catalogue came from.
180
- 2. **The catalogue passed to `Registry`** — overrides the provider's built-in list.
180
+ 2. **The catalogue passed to `AIRegistry`** — overrides the provider's built-in list.
181
181
  3. **The provider's compiled-in catalogue** (`ANTHROPIC_MODELS`, …) — fallback.
182
182
 
183
183
  `defaultModelId` / `defaultFastModelId` override the provider's hard-coded
@@ -194,7 +194,7 @@ Typical flow: app starts with no catalogue (built-in defaults apply), fetches
194
194
  one from the server in the background, then swaps it in:
195
195
 
196
196
  ```ts
197
- const registry = new Registry({ settings })
197
+ const registry = new AIRegistry({ settings })
198
198
 
199
199
  fetch('https://config.inkdrop.app/ai-catalog.json')
200
200
  .then(r => r.json() as Promise<AIModelCatalog>)
@@ -269,10 +269,10 @@ hosts that want to predict the name (e.g. for an onboarding hint).
269
269
 
270
270
  ## API reference
271
271
 
272
- ### `Registry`
272
+ ### `AIRegistry`
273
273
 
274
274
  ```ts
275
- new Registry({
275
+ new AIRegistry({
276
276
  settings: AISettings,
277
277
  catalog?: AIModelCatalog, // server-distributed model lists; see "Model catalogues"
278
278
  keyStore?: KeyStore
@@ -302,8 +302,8 @@ store.deleteKey(baseURL: string): Promise<void> // no-op if absent
302
302
  store.invalidate(baseURL?: string): void // omit url to clear all
303
303
  ```
304
304
 
305
- You generally don't construct a `KeyStore` yourself — `Registry` creates one.
306
- Pass an existing instance via `RegistryOptions.keyStore` if you want to share
305
+ You generally don't construct a `KeyStore` yourself — `AIRegistry` creates one.
306
+ Pass an existing instance via `AIRegistryOptions.keyStore` if you want to share
307
307
  its cache across registries.
308
308
 
309
309
  ### `AIProvider`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkdropapp/ai",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "AI integration common module",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -8,9 +8,9 @@
8
8
  "scripts": {
9
9
  "lint": "eslint src __tests__",
10
10
  "test": "node --experimental-vm-modules --no-warnings=ExperimentalWarning node_modules/jest/bin/jest.js --config jest.config.cjs --runInBand",
11
- "gen": "tsc --declaration --emitDeclarationOnly",
11
+ "build": "tsc --declaration --emitDeclarationOnly",
12
12
  "format": "prettier --write .",
13
- "prepublishOnly": "npm-run-all lint test gen"
13
+ "prepublishOnly": "npm-run-all lint test build"
14
14
  },
15
15
  "keywords": [
16
16
  "ai",
@@ -18,12 +18,15 @@
18
18
  ],
19
19
  "author": "Takuya Matsuyama <t@inkdrop.app>",
20
20
  "license": "UNLICENSED",
21
+ "packageManager": "pnpm@11.1.1",
21
22
  "dependencies": {
22
23
  "@ai-sdk/anthropic": "4.0.0-beta.42",
23
24
  "@ai-sdk/openai-compatible": "3.0.0-beta.36",
25
+ "@ai-sdk/provider": "4.0.0-beta.14",
24
26
  "@inkdropapp/ai-catalog": "^0.1.0",
25
27
  "@napi-rs/keyring": "^1.2.0",
26
- "ai": "7.0.0-beta.116"
28
+ "ai": "7.0.0-beta.116",
29
+ "npm-run-all2": "^8.0.4"
27
30
  },
28
31
  "devDependencies": {
29
32
  "@types/jest": "^30.0.0",
@@ -31,7 +34,6 @@
31
34
  "eslint": "^10.3.0",
32
35
  "eslint-config-prettier": "^10.1.8",
33
36
  "jest": "^30.4.2",
34
- "npm-run-all": "^4.1.5",
35
37
  "prettier": "^3.8.3",
36
38
  "ts-jest": "^29.4.9",
37
39
  "typescript": "^6.0.3",
package/src/index.ts CHANGED
@@ -42,7 +42,7 @@ export {
42
42
  deriveEnvVarName
43
43
  } from './providers/openai-compatible.js'
44
44
  export {
45
- Registry,
46
- type RegistryOptions,
45
+ AIRegistry,
46
+ type AIRegistryOptions,
47
47
  type ResolvedSlot
48
48
  } from './registry.js'
package/src/registry.ts CHANGED
@@ -13,13 +13,13 @@ export type ResolvedSlot = {
13
13
  model: AIModel
14
14
  }
15
15
 
16
- export type RegistryOptions = {
16
+ export type AIRegistryOptions = {
17
17
  settings: AISettings
18
18
  /**
19
19
  * Optional server-distributed catalogue of supported models per provider.
20
20
  * When omitted, each provider uses its compiled-in defaults (e.g. `ANTHROPIC_MODELS`).
21
21
  * The host typically fetches this from an API and either passes it at
22
- * construction time or swaps it in later via {@link Registry.updateCatalog}.
22
+ * construction time or swaps it in later via {@link AIRegistry.updateCatalog}.
23
23
  */
24
24
  catalog?: AIModelCatalog
25
25
  /** Pass an existing `KeyStore` to share its in-memory cache across registries. */
@@ -32,26 +32,26 @@ export type RegistryOptions = {
32
32
  * Owns one instance of every configured provider, resolves task slots with
33
33
  * fallback, and is the only place feature code calls to start a completion.
34
34
  *
35
- * The `Registry` is stateless beyond its provider list — it doesn't observe
36
- * settings on its own. Call {@link Registry.updateSettings} when settings
35
+ * The `AIRegistry` is stateless beyond its provider list — it doesn't observe
36
+ * settings on its own. Call {@link AIRegistry.updateSettings} when settings
37
37
  * change to rebuild providers.
38
38
  *
39
39
  * @example
40
40
  * ```ts
41
- * const registry = new Registry({ settings })
41
+ * const registry = new AIRegistry({ settings })
42
42
  * const events = await registry.streamCompletion('default', { messages })
43
43
  * for await (const event of events) {
44
44
  * if (event.kind === 'text-delta') process.stdout.write(event.delta)
45
45
  * }
46
46
  * ```
47
47
  */
48
- export class Registry {
48
+ export class AIRegistry {
49
49
  readonly keyStore: KeyStore
50
50
  private providers: Map<string, AIProvider> = new Map()
51
51
  private settings: AISettings
52
52
  private catalog: AIModelCatalog | undefined
53
53
 
54
- constructor(options: RegistryOptions) {
54
+ constructor(options: AIRegistryOptions) {
55
55
  this.keyStore = options.keyStore ?? new KeyStore()
56
56
  this.settings = options.settings
57
57
  this.catalog = options.catalog
@@ -140,7 +140,7 @@ export class Registry {
140
140
  /**
141
141
  * Streams a completion for a task slot.
142
142
  *
143
- * Resolves the slot via {@link Registry.resolveSlot}; throws {@link NoApiKey}
143
+ * Resolves the slot via {@link AIRegistry.resolveSlot}; throws {@link NoApiKey}
144
144
  * if no provider can satisfy it (no slot binding, and no authenticated
145
145
  * provider available for the implicit fallback). Otherwise returns the
146
146
  * model's stream — note that *upstream* errors (auth, rate limit, etc.)
package/src/settings.ts CHANGED
@@ -88,7 +88,7 @@ export type AnthropicProviderConfig = CommonProviderConfig & {
88
88
 
89
89
  /**
90
90
  * Top-level AI configuration. The host (Inkdrop main process) constructs this
91
- * from whichever persistence layer it uses and passes it to `Registry`.
91
+ * from whichever persistence layer it uses and passes it to `AIRegistry`.
92
92
  *
93
93
  * The library never reads or writes settings to disk itself.
94
94
  */
package/types/index.d.ts CHANGED
@@ -7,4 +7,4 @@ export { KeyStore, type KeyStoreOptions } from './key-store.js';
7
7
  export { normalizeBaseURL } from './url.js';
8
8
  export { AnthropicProvider } from './providers/anthropic.js';
9
9
  export { OpenAICompatibleProvider, deriveEnvVarName } from './providers/openai-compatible.js';
10
- export { Registry, type RegistryOptions, type ResolvedSlot } from './registry.js';
10
+ export { AIRegistry, type AIRegistryOptions, type ResolvedSlot } from './registry.js';
@@ -45,7 +45,10 @@ export interface AIModel {
45
45
  * OpenAI-compatible providers (OpenRouter, Together, Ollama, …) are modelled.
46
46
  */
47
47
  export interface AIProvider {
48
- /** Stable provider id; appears in `AISettings.slots[*].providerId`. */
48
+ /**
49
+ * Stable provider id; appears in both `AISettings.providerId` and
50
+ * `AISettings.slots[*].providerId`.
51
+ */
49
52
  readonly id: string;
50
53
  /** Human-readable label. */
51
54
  readonly name: string;
@@ -8,13 +8,13 @@ export type ResolvedSlot = {
8
8
  provider: AIProvider;
9
9
  model: AIModel;
10
10
  };
11
- export type RegistryOptions = {
11
+ export type AIRegistryOptions = {
12
12
  settings: AISettings;
13
13
  /**
14
14
  * Optional server-distributed catalogue of supported models per provider.
15
15
  * When omitted, each provider uses its compiled-in defaults (e.g. `ANTHROPIC_MODELS`).
16
16
  * The host typically fetches this from an API and either passes it at
17
- * construction time or swaps it in later via {@link Registry.updateCatalog}.
17
+ * construction time or swaps it in later via {@link AIRegistry.updateCatalog}.
18
18
  */
19
19
  catalog?: AIModelCatalog;
20
20
  /** Pass an existing `KeyStore` to share its in-memory cache across registries. */
@@ -26,25 +26,25 @@ export type RegistryOptions = {
26
26
  * Owns one instance of every configured provider, resolves task slots with
27
27
  * fallback, and is the only place feature code calls to start a completion.
28
28
  *
29
- * The `Registry` is stateless beyond its provider list — it doesn't observe
30
- * settings on its own. Call {@link Registry.updateSettings} when settings
29
+ * The `AIRegistry` is stateless beyond its provider list — it doesn't observe
30
+ * settings on its own. Call {@link AIRegistry.updateSettings} when settings
31
31
  * change to rebuild providers.
32
32
  *
33
33
  * @example
34
34
  * ```ts
35
- * const registry = new Registry({ settings })
35
+ * const registry = new AIRegistry({ settings })
36
36
  * const events = await registry.streamCompletion('default', { messages })
37
37
  * for await (const event of events) {
38
38
  * if (event.kind === 'text-delta') process.stdout.write(event.delta)
39
39
  * }
40
40
  * ```
41
41
  */
42
- export declare class Registry {
42
+ export declare class AIRegistry {
43
43
  readonly keyStore: KeyStore;
44
44
  private providers;
45
45
  private settings;
46
46
  private catalog;
47
- constructor(options: RegistryOptions);
47
+ constructor(options: AIRegistryOptions);
48
48
  /** All configured providers, sorted alphabetically by id. */
49
49
  listProviders(): AIProvider[];
50
50
  getProvider(id: string): AIProvider | undefined;
@@ -59,12 +59,17 @@ export declare class Registry {
59
59
  * Order:
60
60
  * 1. Explicit binding `settings.slots[slot]`, if both provider and model resolve.
61
61
  * 2. For `'fast'` only: fall back to `settings.slots.default`.
62
- * 3. First authenticated provider in alphabetical id order, taking that
62
+ * 3. Preferred provider `settings.providerId`, if that provider is configured,
63
+ * taking its `defaultModel()` (or `defaultFastModel()` for the fast slot).
64
+ * Authentication is not gated here — the user explicitly picked this
65
+ * provider; auth errors surface at stream time rather than silently
66
+ * swapping providers.
67
+ * 4. First authenticated provider in alphabetical id order, taking that
63
68
  * provider's `defaultModel()` (or `defaultFastModel()` for the fast slot).
64
69
  * Mirrors Zed's `available_fallback_model` without the Zed-Cloud preference.
65
- * 4. `undefined` if no provider can satisfy the slot.
70
+ * 5. `undefined` if no provider can satisfy the slot.
66
71
  *
67
- * Async because the third step calls `provider.isAuthenticated()`, which may
72
+ * Async because the fourth step calls `provider.isAuthenticated()`, which may
68
73
  * touch the keyring.
69
74
  */
70
75
  resolveSlot(slot: SlotName): Promise<ResolvedSlot | undefined>;
@@ -72,7 +77,7 @@ export declare class Registry {
72
77
  /**
73
78
  * Streams a completion for a task slot.
74
79
  *
75
- * Resolves the slot via {@link Registry.resolveSlot}; throws {@link NoApiKey}
80
+ * Resolves the slot via {@link AIRegistry.resolveSlot}; throws {@link NoApiKey}
76
81
  * if no provider can satisfy it (no slot binding, and no authenticated
77
82
  * provider available for the implicit fallback). Otherwise returns the
78
83
  * model's stream — note that *upstream* errors (auth, rate limit, etc.)
@@ -77,7 +77,7 @@ export type AnthropicProviderConfig = CommonProviderConfig & {
77
77
  };
78
78
  /**
79
79
  * Top-level AI configuration. The host (Inkdrop main process) constructs this
80
- * from whichever persistence layer it uses and passes it to `Registry`.
80
+ * from whichever persistence layer it uses and passes it to `AIRegistry`.
81
81
  *
82
82
  * The library never reads or writes settings to disk itself.
83
83
  */
@@ -87,8 +87,17 @@ export type AISettings = {
87
87
  openaiCompatible?: OpenAICompatibleProviderConfig[];
88
88
  };
89
89
  /**
90
- * Per-slot model overrides. Unset slots fall back to the first registered
91
- * provider's `defaultModel` / `defaultFastModel`.
90
+ * Preferred provider for every task slot. When set (and the per-slot
91
+ * `slots[slot]` override isn't), each slot resolves to this provider's
92
+ * `defaultModel` / `defaultFastModel`. This is the simple UI knob — bind it
93
+ * to a single "AI provider" dropdown.
94
+ */
95
+ providerId?: string;
96
+ /**
97
+ * Per-slot `(provider, model)` overrides. Wins over `providerId` when set.
98
+ * Useful for advanced configurations that pin a specific model per slot or
99
+ * mix providers across slots (e.g. Claude for `default`, a local model for
100
+ * `fast`).
92
101
  */
93
102
  slots?: Partial<Record<SlotName, SlotConfig>>;
94
103
  };