@intentface/latch-core 0.9.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.
- package/LICENSE +21 -0
- package/README.md +45 -0
- package/dist/agent.d.ts +200 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +9 -0
- package/dist/agent.js.map +1 -0
- package/dist/compaction.d.ts +33 -0
- package/dist/compaction.d.ts.map +1 -0
- package/dist/compaction.js +104 -0
- package/dist/compaction.js.map +1 -0
- package/dist/connections.d.ts +16 -0
- package/dist/connections.d.ts.map +1 -0
- package/dist/connections.js +41 -0
- package/dist/connections.js.map +1 -0
- package/dist/context.d.ts +41 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +25 -0
- package/dist/context.js.map +1 -0
- package/dist/current-date.d.ts +12 -0
- package/dist/current-date.d.ts.map +1 -0
- package/dist/current-date.js +25 -0
- package/dist/current-date.js.map +1 -0
- package/dist/extensions.d.ts +333 -0
- package/dist/extensions.d.ts.map +1 -0
- package/dist/extensions.js +569 -0
- package/dist/extensions.js.map +1 -0
- package/dist/harness/index.d.ts +17 -0
- package/dist/harness/index.d.ts.map +1 -0
- package/dist/harness/index.js +15 -0
- package/dist/harness/index.js.map +1 -0
- package/dist/harness/tools.d.ts +88 -0
- package/dist/harness/tools.d.ts.map +1 -0
- package/dist/harness/tools.js +296 -0
- package/dist/harness/tools.js.map +1 -0
- package/dist/harness/web-fetch.d.ts +47 -0
- package/dist/harness/web-fetch.d.ts.map +1 -0
- package/dist/harness/web-fetch.js +247 -0
- package/dist/harness/web-fetch.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/limits.d.ts +152 -0
- package/dist/limits.d.ts.map +1 -0
- package/dist/limits.js +97 -0
- package/dist/limits.js.map +1 -0
- package/dist/memory.d.ts +93 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +13 -0
- package/dist/memory.js.map +1 -0
- package/dist/message.d.ts +46 -0
- package/dist/message.d.ts.map +1 -0
- package/dist/message.js +2 -0
- package/dist/message.js.map +1 -0
- package/dist/models/catalog.d.ts +56 -0
- package/dist/models/catalog.d.ts.map +1 -0
- package/dist/models/catalog.js +211 -0
- package/dist/models/catalog.js.map +1 -0
- package/dist/models/defaults.d.ts +23 -0
- package/dist/models/defaults.d.ts.map +1 -0
- package/dist/models/defaults.js +19 -0
- package/dist/models/defaults.js.map +1 -0
- package/dist/models/index.d.ts +23 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +19 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/prompt-caching.d.ts +19 -0
- package/dist/models/prompt-caching.d.ts.map +1 -0
- package/dist/models/prompt-caching.js +18 -0
- package/dist/models/prompt-caching.js.map +1 -0
- package/dist/models/provider.d.ts +19 -0
- package/dist/models/provider.d.ts.map +1 -0
- package/dist/models/provider.js +22 -0
- package/dist/models/provider.js.map +1 -0
- package/dist/models/reasoning.d.ts +21 -0
- package/dist/models/reasoning.d.ts.map +1 -0
- package/dist/models/reasoning.js +59 -0
- package/dist/models/reasoning.js.map +1 -0
- package/dist/pricing.d.ts +52 -0
- package/dist/pricing.d.ts.map +1 -0
- package/dist/pricing.js +37 -0
- package/dist/pricing.js.map +1 -0
- package/dist/principal.d.ts +37 -0
- package/dist/principal.d.ts.map +1 -0
- package/dist/principal.js +30 -0
- package/dist/principal.js.map +1 -0
- package/dist/projections.d.ts +37 -0
- package/dist/projections.d.ts.map +1 -0
- package/dist/projections.js +128 -0
- package/dist/projections.js.map +1 -0
- package/dist/prompt-caching.d.ts +106 -0
- package/dist/prompt-caching.d.ts.map +1 -0
- package/dist/prompt-caching.js +165 -0
- package/dist/prompt-caching.js.map +1 -0
- package/dist/runtime.d.ts +670 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +2425 -0
- package/dist/runtime.js.map +1 -0
- package/dist/scheduler.d.ts +31 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +43 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/storage.d.ts +389 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +38 -0
- package/dist/storage.js.map +1 -0
- package/dist/telemetry.d.ts +155 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +2 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/vault-node.d.ts +20 -0
- package/dist/vault-node.d.ts.map +1 -0
- package/dist/vault-node.js +30 -0
- package/dist/vault-node.js.map +1 -0
- package/dist/vault.d.ts +62 -0
- package/dist/vault.d.ts.map +1 -0
- package/dist/vault.js +88 -0
- package/dist/vault.js.map +1 -0
- package/package.json +95 -0
package/dist/memory.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory seam.
|
|
3
|
+
*
|
|
4
|
+
* An agent that declares `memory` (see `AgentConfig.memory`) gets persistent
|
|
5
|
+
* cross-session memory when the runtime is composed with a `MemoryProvider`
|
|
6
|
+
* (`RuntimeConfig.memory`). Core knows nothing about where memories live — the
|
|
7
|
+
* provider (e.g. `@intentface/latch-memory`) owns storage, retrieval, and the
|
|
8
|
+
* background extraction/consolidation jobs. Core's only job is the per-turn
|
|
9
|
+
* wiring: append the provider's compiled-index block to the agent's
|
|
10
|
+
* instructions and merge its scope-bound tools into the toolset.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Who one memory store is about — and who can see it.
|
|
14
|
+
*
|
|
15
|
+
* - `agent-user`: one store per (agent, user). The default fit for personal
|
|
16
|
+
* agents (a coach's memory of *you*).
|
|
17
|
+
* - `agent-org`: one store per (agent, org) — all org users share it.
|
|
18
|
+
* - `user`: one store per user, shared across every agent that declares the
|
|
19
|
+
* same scope AND the same `connection` (a different connection silently
|
|
20
|
+
* splits the store — validate at the surface, not here).
|
|
21
|
+
*
|
|
22
|
+
* Search and consolidation never cross a scope boundary.
|
|
23
|
+
*/
|
|
24
|
+
export type MemoryScope = "agent-user" | "agent-org" | "user";
|
|
25
|
+
/** An agent's memory declaration (`AgentConfig.memory`). */
|
|
26
|
+
export interface MemoryConfig {
|
|
27
|
+
scope: MemoryScope;
|
|
28
|
+
/**
|
|
29
|
+
* The connection (runtime connection-registry name, e.g. `"loredex"`) whose
|
|
30
|
+
* workspace holds this agent's memory files. The provider opens it itself,
|
|
31
|
+
* per operation — memory does not require the agent to also list it in
|
|
32
|
+
* `connections` (though agents typically do).
|
|
33
|
+
*/
|
|
34
|
+
connection: string;
|
|
35
|
+
/**
|
|
36
|
+
* Additional memory levels the background sweep extracts each idle chat
|
|
37
|
+
* into, beyond (and always implicitly including) `scope`. All levels share
|
|
38
|
+
* `connection`. The in-chat `memory_save` tool still writes only to `scope`;
|
|
39
|
+
* extra levels are populated by background extraction and injected/searched
|
|
40
|
+
* read-side. Readers must treat this as a set that contains `scope` (see the
|
|
41
|
+
* provider's normalization) — surfaces normalize on save.
|
|
42
|
+
*/
|
|
43
|
+
extractTo?: MemoryScope[];
|
|
44
|
+
/**
|
|
45
|
+
* Markdown index-schema outlines per agent-held level: top-level `##`
|
|
46
|
+
* section headings (with optional description bullets) that steer what the
|
|
47
|
+
* background extractor captures and how the consolidator organizes that
|
|
48
|
+
* level's MEMORY.md. Advisory — the index format itself is unchanged.
|
|
49
|
+
* The cross-agent `user` level's schema is NOT configured here: it lives as
|
|
50
|
+
* a shared workspace file (see `USER_SCHEMA_PATH` in the memory package).
|
|
51
|
+
*/
|
|
52
|
+
schemas?: Partial<Record<"agent-user" | "agent-org", string>>;
|
|
53
|
+
/** Background extraction tuning (used by the provider's job sweep, not core). */
|
|
54
|
+
extraction?: {
|
|
55
|
+
/** Chat idle time before a transcript is eligible for extraction (default 60). */
|
|
56
|
+
idleMinutes?: number;
|
|
57
|
+
};
|
|
58
|
+
/** Background consolidation tuning (used by the provider's job sweep, not core). */
|
|
59
|
+
consolidation?: {
|
|
60
|
+
/** Minimum time between consolidations of one scope (default 6). */
|
|
61
|
+
cooldownHours?: number;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The runtime's memory seam (`RuntimeConfig.memory`). Both methods are called
|
|
66
|
+
* once per turn, only for agents that declare `memory`.
|
|
67
|
+
*/
|
|
68
|
+
export interface MemoryProvider<P> {
|
|
69
|
+
/**
|
|
70
|
+
* The always-loaded system block for this scope: the compiled memory index
|
|
71
|
+
* plus standing usage instructions, or `undefined` when the store is empty
|
|
72
|
+
* or unreachable. MUST resolve fast (provider-side cache) and MUST NOT
|
|
73
|
+
* throw — a memory failure degrades to a turn without memory, never a dead
|
|
74
|
+
* turn (the runtime also guards with a `.catch`).
|
|
75
|
+
*/
|
|
76
|
+
instructionsFor(args: {
|
|
77
|
+
principal: P;
|
|
78
|
+
agent: string;
|
|
79
|
+
memory: MemoryConfig;
|
|
80
|
+
}): Promise<string | undefined>;
|
|
81
|
+
/**
|
|
82
|
+
* The scope-bound memory tools for this turn (e.g. `memory_search`,
|
|
83
|
+
* `memory_save`). Returned synchronously — tool `execute` opens connections
|
|
84
|
+
* lazily. Merged as capability tools, so an agent's `enabledTools`
|
|
85
|
+
* restriction never hides them.
|
|
86
|
+
*/
|
|
87
|
+
toolsFor(args: {
|
|
88
|
+
principal: P;
|
|
89
|
+
agent: string;
|
|
90
|
+
memory: MemoryConfig;
|
|
91
|
+
}): Record<string, unknown>;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,WAAW,GAAG,MAAM,CAAC;AAE9D,4DAA4D;AAC5D,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,WAAW,CAAC;IACnB;;;;;OAKG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,WAAW,EAAE,CAAC;IAC1B;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,GAAG,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IAC9D,iFAAiF;IACjF,UAAU,CAAC,EAAE;QACX,kFAAkF;QAClF,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,oFAAoF;IACpF,aAAa,CAAC,EAAE;QACd,oEAAoE;QACpE,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC;CACH;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B;;;;;;OAMG;IACH,eAAe,CAAC,IAAI,EAAE;QACpB,SAAS,EAAE,CAAC,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,YAAY,CAAC;KACtB,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAChC;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE;QACb,SAAS,EAAE,CAAC,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,YAAY,CAAC;KACtB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7B"}
|
package/dist/memory.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory seam.
|
|
3
|
+
*
|
|
4
|
+
* An agent that declares `memory` (see `AgentConfig.memory`) gets persistent
|
|
5
|
+
* cross-session memory when the runtime is composed with a `MemoryProvider`
|
|
6
|
+
* (`RuntimeConfig.memory`). Core knows nothing about where memories live — the
|
|
7
|
+
* provider (e.g. `@intentface/latch-memory`) owns storage, retrieval, and the
|
|
8
|
+
* background extraction/consolidation jobs. Core's only job is the per-turn
|
|
9
|
+
* wiring: append the provider's compiled-index block to the agent's
|
|
10
|
+
* instructions and merge its scope-bound tools into the toolset.
|
|
11
|
+
*/
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { UIMessage, UITools, UIDataTypes } from "ai";
|
|
2
|
+
/**
|
|
3
|
+
* The message model.
|
|
4
|
+
*
|
|
5
|
+
* `AppMessage` is the canonical stored unit and the source of truth for a
|
|
6
|
+
* conversation. It is just a *typed* AI SDK `UIMessage` — so all the stock
|
|
7
|
+
* stream/persistence helpers (`toUIMessageStream`, `convertToModelMessages`,
|
|
8
|
+
* `useChat`) work unchanged.
|
|
9
|
+
*
|
|
10
|
+
* Two ideas ride on the message instead of in extra tables:
|
|
11
|
+
* - the two axes (`visibility`, `sendToModel`) decide who sees a message —
|
|
12
|
+
* the model, the end user, both, or neither;
|
|
13
|
+
* - the execution facts (usage/cost/model/finishReason) live in `metadata`,
|
|
14
|
+
* so there is no separate "steps" table and no duplication.
|
|
15
|
+
*/
|
|
16
|
+
/** Who sees a message on the client projection. */
|
|
17
|
+
export type Visibility = "user" | "internal" | "redacted";
|
|
18
|
+
/** Per-message metadata stamped onto an `AppMessage`. */
|
|
19
|
+
export interface AppMetadata {
|
|
20
|
+
/** Client-projection axis: shown to the user, internal-only, or redacted. */
|
|
21
|
+
visibility?: Visibility;
|
|
22
|
+
/** Model-projection axis: whether `toModelMessages` includes it. */
|
|
23
|
+
sendToModel?: boolean;
|
|
24
|
+
/** Resolved model id for this message (e.g. "anthropic/claude-sonnet-4-6"). */
|
|
25
|
+
model?: string;
|
|
26
|
+
/** Token usage attributed to producing this message (incl. cached-prompt split). */
|
|
27
|
+
usage?: {
|
|
28
|
+
inputTokens?: number;
|
|
29
|
+
outputTokens?: number;
|
|
30
|
+
cacheReadTokens?: number;
|
|
31
|
+
cacheWriteTokens?: number;
|
|
32
|
+
};
|
|
33
|
+
/** Computed cost in the account's currency unit. */
|
|
34
|
+
cost?: number;
|
|
35
|
+
/** Finish reason from the producing step. */
|
|
36
|
+
finishReason?: string;
|
|
37
|
+
/** Server-side creation timestamp (unix ms). */
|
|
38
|
+
createdAt?: number;
|
|
39
|
+
/** Set when the message text is a transcription of a recorded voice message. */
|
|
40
|
+
voice?: {
|
|
41
|
+
durationMs: number;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** The stored conversation unit — a `UIMessage` typed with our metadata. */
|
|
45
|
+
export type AppMessage<TOOLS extends UITools = UITools> = UIMessage<AppMetadata, UIDataTypes, TOOLS>;
|
|
46
|
+
//# sourceMappingURL=message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../src/message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAE1D;;;;;;;;;;;;;GAaG;AAEH,mDAAmD;AACnD,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,UAAU,CAAC;AAE1D,yDAAyD;AACzD,MAAM,WAAW,WAAW;IAC1B,6EAA6E;IAC7E,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,oEAAoE;IACpE,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,+EAA+E;IAC/E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oFAAoF;IACpF,KAAK,CAAC,EAAE;QACN,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;KAC3B,CAAC;IACF,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gFAAgF;IAChF,KAAK,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;CAChC;AAED,4EAA4E;AAC5E,MAAM,MAAM,UAAU,CAAC,KAAK,SAAS,OAAO,GAAG,OAAO,IAAI,SAAS,CACjE,WAAW,EACX,WAAW,EACX,KAAK,CACN,CAAC"}
|
package/dist/message.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../src/message.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { LanguageModel } from "ai";
|
|
2
|
+
import type { Pricing } from "../pricing.js";
|
|
3
|
+
import { type ProviderId } from "./provider.js";
|
|
4
|
+
/**
|
|
5
|
+
* The model catalog, sourced from models.dev (the public model registry). A
|
|
6
|
+
* provider's models are included when its SDK is installed AND its API key is
|
|
7
|
+
* set (models.dev tells us the key env var) — so a picker shows exactly what
|
|
8
|
+
* this deployment can run, across providers, auto-updating as models ship.
|
|
9
|
+
* Each model's `cost` (USD/1M) feeds the pricing seam. Fetched once per process
|
|
10
|
+
* per option set; static fallback if offline.
|
|
11
|
+
*
|
|
12
|
+
* Provider SDKs are OPTIONAL peers of core and loaded lazily, per provider,
|
|
13
|
+
* only when that provider is usable here — a host with one API key never
|
|
14
|
+
* loads the other two SDKs, and core itself stays free of static provider
|
|
15
|
+
* imports.
|
|
16
|
+
*/
|
|
17
|
+
export interface ModelInfo {
|
|
18
|
+
id: string;
|
|
19
|
+
label: string;
|
|
20
|
+
provider: string;
|
|
21
|
+
/** Whether the model supports reasoning/thinking (gates the effort knob). */
|
|
22
|
+
reasoning?: boolean;
|
|
23
|
+
/** Max output tokens (models.dev `limit.output`) — bounds the thinking budget. */
|
|
24
|
+
maxOutput?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface ModelCatalog {
|
|
27
|
+
models: ModelInfo[];
|
|
28
|
+
pricing: Pricing;
|
|
29
|
+
/** Resolve a model id → provider model (unknown id → the default model). */
|
|
30
|
+
modelFor: (id: string) => LanguageModel;
|
|
31
|
+
/**
|
|
32
|
+
* The provider's NATIVE web tools for a model id (server-side search/fetch),
|
|
33
|
+
* keyed consistently (`web_search` / `web_fetch`) so prompts stay
|
|
34
|
+
* provider-agnostic. `{}` when the provider has none or isn't loaded.
|
|
35
|
+
*/
|
|
36
|
+
providerTools: (id: string) => Record<string, unknown>;
|
|
37
|
+
/** The id `modelFor` falls back to. */
|
|
38
|
+
defaultModel: string;
|
|
39
|
+
}
|
|
40
|
+
export interface ModelCatalogOptions {
|
|
41
|
+
/** Providers to consider (default: all three). Inclusion still requires the SDK + key env. */
|
|
42
|
+
providers?: readonly ProviderId[];
|
|
43
|
+
/** The model unknown ids resolve to (default: claude-sonnet-4-6). */
|
|
44
|
+
defaultModel?: string;
|
|
45
|
+
/** models.dev endpoint override (tests / mirrors). */
|
|
46
|
+
url?: string;
|
|
47
|
+
/** Fetch override (tests). */
|
|
48
|
+
fetch?: typeof fetch;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Load (and memoize per option set) the model catalog from models.dev, across
|
|
52
|
+
* runnable providers. Rejects — never returns a half-usable catalog — when an
|
|
53
|
+
* explicit `defaultModel` names a provider that isn't runnable here.
|
|
54
|
+
*/
|
|
55
|
+
export declare function loadModelCatalog(options?: ModelCatalogOptions): Promise<ModelCatalog>;
|
|
56
|
+
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/models/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAExC,OAAO,KAAK,EAAc,OAAO,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAgC,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAE9E;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,6EAA6E;IAC7E,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,kFAAkF;IAClF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,4EAA4E;IAC5E,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,aAAa,CAAC;IACxC;;;;OAIG;IACH,aAAa,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvD,uCAAuC;IACvC,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,mBAAmB;IAClC,8FAA8F;IAC9F,SAAS,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;IAClC,qEAAqE;IACrE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sDAAsD;IACtD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,8BAA8B;IAC9B,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAyKD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,YAAY,CAAC,CAsFzF"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { staticPricing } from "../pricing.js";
|
|
2
|
+
import { PROVIDER_IDS, providerFromId } from "./provider.js";
|
|
3
|
+
/**
|
|
4
|
+
* Lazy SDK loaders — the ONLY place a provider package is named. Each import
|
|
5
|
+
* resolves against the host's node_modules (optional peer), so a missing SDK
|
|
6
|
+
* is a per-provider "not available here", never a load-time failure of core.
|
|
7
|
+
*/
|
|
8
|
+
const LOADERS = {
|
|
9
|
+
anthropic: async () => {
|
|
10
|
+
const { anthropic } = await import("@ai-sdk/anthropic");
|
|
11
|
+
return {
|
|
12
|
+
model: (id) => anthropic(id),
|
|
13
|
+
webTools: () => ({
|
|
14
|
+
web_search: anthropic.tools.webSearch_20260209(),
|
|
15
|
+
web_fetch: anthropic.tools.webFetch_20260209(),
|
|
16
|
+
}),
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
openai: async () => {
|
|
20
|
+
const { openai } = await import("@ai-sdk/openai");
|
|
21
|
+
return { model: (id) => openai(id), webTools: () => ({ web_search: openai.tools.webSearch() }) };
|
|
22
|
+
},
|
|
23
|
+
google: async () => {
|
|
24
|
+
const { google } = await import("@ai-sdk/google");
|
|
25
|
+
return {
|
|
26
|
+
model: (id) => google(id),
|
|
27
|
+
webTools: () => ({
|
|
28
|
+
web_search: google.tools.googleSearch({}),
|
|
29
|
+
web_fetch: google.tools.urlContext({}),
|
|
30
|
+
}),
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
const DEFAULT_MODEL = "claude-sonnet-4-6";
|
|
35
|
+
const MODELS_DEV_URL = "https://models.dev/api.json";
|
|
36
|
+
/** Each provider's well-known key env var — models.dev tells us online; this is the offline copy. */
|
|
37
|
+
const KEY_ENV = {
|
|
38
|
+
anthropic: "ANTHROPIC_API_KEY",
|
|
39
|
+
openai: "OPENAI_API_KEY",
|
|
40
|
+
google: "GOOGLE_GENERATIVE_AI_API_KEY",
|
|
41
|
+
};
|
|
42
|
+
/** Load the SDKs for `providers` that are installed; missing ones are skipped (warned once). */
|
|
43
|
+
async function loadFactories(providers) {
|
|
44
|
+
const loaded = new Map();
|
|
45
|
+
await Promise.all(providers.map(async (p) => {
|
|
46
|
+
try {
|
|
47
|
+
loaded.set(p, await LOADERS[p]());
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
console.warn(`[latch-core/models] provider "${p}" unavailable (install @ai-sdk/${p} to use it):`, e instanceof Error ? e.message : e);
|
|
51
|
+
}
|
|
52
|
+
}));
|
|
53
|
+
return loaded;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The implicit default: the canonical Sonnet when Anthropic is runnable here,
|
|
57
|
+
* else the first listed model of a provider that is — so an OpenAI- or
|
|
58
|
+
* Google-only host never gets a default its SDK can't build.
|
|
59
|
+
*/
|
|
60
|
+
function pickDefaultModel(factories, models) {
|
|
61
|
+
if (factories.has("anthropic"))
|
|
62
|
+
return DEFAULT_MODEL;
|
|
63
|
+
return models.find((m) => factories.has(m.provider))?.id ?? DEFAULT_MODEL;
|
|
64
|
+
}
|
|
65
|
+
function buildResolvers(factories, idToProvider, defaultModel) {
|
|
66
|
+
const defaultProvider = providerFromId(defaultModel) ?? "anthropic";
|
|
67
|
+
const providerOfId = (id) => idToProvider.get(id) ?? providerFromId(id);
|
|
68
|
+
return {
|
|
69
|
+
modelFor: (id) => {
|
|
70
|
+
const provider = providerOfId(id);
|
|
71
|
+
const f = (provider && factories.get(provider)) || factories.get(defaultProvider);
|
|
72
|
+
if (!f) {
|
|
73
|
+
throw new Error(`[latch-core/models] no provider SDK loaded for "${id}" (or the default "${defaultModel}") — install @ai-sdk/${provider ?? defaultProvider} and set its API key`);
|
|
74
|
+
}
|
|
75
|
+
// A known provider resolves the requested id; an unknown id falls back to the default model.
|
|
76
|
+
return provider && factories.has(provider) ? f.model(id) : f.model(defaultModel);
|
|
77
|
+
},
|
|
78
|
+
providerTools: (id) => {
|
|
79
|
+
// Unknown ids default to the default model's provider (historically Anthropic's tools).
|
|
80
|
+
const provider = providerOfId(id) ?? defaultProvider;
|
|
81
|
+
return factories.get(provider)?.webTools() ?? {};
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Offline fallback: one known-good model per provider, restricted (like the
|
|
87
|
+
* online path) to providers that are keyed AND installed. Same eligibility
|
|
88
|
+
* rule, so an unconfigured SDK never yields a model that can't run.
|
|
89
|
+
*/
|
|
90
|
+
function fallbackCatalog(factories, defaultModel) {
|
|
91
|
+
const all = [
|
|
92
|
+
{ id: "claude-sonnet-4-6", label: "Claude Sonnet 4.6", provider: "anthropic", reasoning: true, maxOutput: 64000 },
|
|
93
|
+
{ id: "gpt-4o", label: "GPT-4o", provider: "openai", reasoning: false, maxOutput: 16384 },
|
|
94
|
+
{ id: "gemini-2.5-pro", label: "Gemini 2.5 Pro", provider: "google", reasoning: true, maxOutput: 65536 },
|
|
95
|
+
];
|
|
96
|
+
const models = all.filter((m) => factories.has(m.provider));
|
|
97
|
+
const chosenDefault = defaultModel ?? pickDefaultModel(factories, models);
|
|
98
|
+
return {
|
|
99
|
+
models,
|
|
100
|
+
pricing: staticPricing({
|
|
101
|
+
"claude-sonnet-4-6": { inputPer1M: 3, outputPer1M: 15 },
|
|
102
|
+
"gpt-4o": { inputPer1M: 2.5, outputPer1M: 10 },
|
|
103
|
+
"gemini-2.5-pro": { inputPer1M: 1.25, outputPer1M: 10 },
|
|
104
|
+
}),
|
|
105
|
+
...buildResolvers(factories, new Map(models.map((m) => [m.id, m.provider])), chosenDefault),
|
|
106
|
+
defaultModel: chosenDefault,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/** Providers whose key env is set (offline eligibility rule). */
|
|
110
|
+
const keyedProviders = (providers) => providers.filter((p) => !!process.env[KEY_ENV[p]]);
|
|
111
|
+
// Memo per (fetch implementation, option set): an injected fetch (tests,
|
|
112
|
+
// mirrors) gets its own cache, so it can never serve a catalog to callers
|
|
113
|
+
// using a different one.
|
|
114
|
+
const caches = new WeakMap();
|
|
115
|
+
const cacheFor = (fetchImpl) => {
|
|
116
|
+
let m = caches.get(fetchImpl);
|
|
117
|
+
if (!m)
|
|
118
|
+
caches.set(fetchImpl, (m = new Map()));
|
|
119
|
+
return m;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Load (and memoize per option set) the model catalog from models.dev, across
|
|
123
|
+
* runnable providers. Rejects — never returns a half-usable catalog — when an
|
|
124
|
+
* explicit `defaultModel` names a provider that isn't runnable here.
|
|
125
|
+
*/
|
|
126
|
+
export function loadModelCatalog(options = {}) {
|
|
127
|
+
const providers = options.providers ?? PROVIDER_IDS;
|
|
128
|
+
const url = options.url ?? MODELS_DEV_URL;
|
|
129
|
+
const doFetch = options.fetch ?? fetch;
|
|
130
|
+
const cache = cacheFor(doFetch);
|
|
131
|
+
const key = JSON.stringify([providers, options.defaultModel ?? null, url]);
|
|
132
|
+
const hit = cache.get(key);
|
|
133
|
+
if (hit)
|
|
134
|
+
return hit;
|
|
135
|
+
const loading = (async () => {
|
|
136
|
+
let factories;
|
|
137
|
+
let catalog;
|
|
138
|
+
try {
|
|
139
|
+
const res = await doFetch(url, { redirect: "error" });
|
|
140
|
+
if (!res.ok)
|
|
141
|
+
throw new Error(`HTTP ${res.status}`);
|
|
142
|
+
const all = (await res.json());
|
|
143
|
+
// Usable = listed by models.dev AND keyed. Then load those SDKs (only).
|
|
144
|
+
const keyed = providers.filter((p) => {
|
|
145
|
+
const md = all[p];
|
|
146
|
+
return !!md?.models && (md.env ?? []).some((e) => !!process.env[e]);
|
|
147
|
+
});
|
|
148
|
+
factories = await loadFactories(keyed);
|
|
149
|
+
const list = [];
|
|
150
|
+
const rates = {};
|
|
151
|
+
const idToProvider = new Map();
|
|
152
|
+
for (const provider of keyed) {
|
|
153
|
+
if (!factories.has(provider))
|
|
154
|
+
continue; // keyed but SDK not installed
|
|
155
|
+
for (const [id, m] of Object.entries(all[provider].models)) {
|
|
156
|
+
list.push({ id, label: m.name ?? id, provider, reasoning: m.reasoning, maxOutput: m.limit?.output });
|
|
157
|
+
idToProvider.set(id, provider);
|
|
158
|
+
if (m.cost?.input != null && m.cost?.output != null) {
|
|
159
|
+
rates[id] = {
|
|
160
|
+
inputPer1M: m.cost.input,
|
|
161
|
+
outputPer1M: m.cost.output,
|
|
162
|
+
...(m.cost.cache_read != null ? { cacheReadPer1M: m.cost.cache_read } : {}),
|
|
163
|
+
...(m.cost.cache_write != null ? { cacheWritePer1M: m.cost.cache_write } : {}),
|
|
164
|
+
};
|
|
165
|
+
// Long-context tier (higher rates above a context size).
|
|
166
|
+
const ct = (m.cost.tiers ?? []).find((t) => t.tier?.type === "context" && t.tier?.size && t.input != null && t.output != null);
|
|
167
|
+
if (ct?.tier?.size) {
|
|
168
|
+
rates[id].tier = {
|
|
169
|
+
thresholdTokens: ct.tier.size,
|
|
170
|
+
inputPer1M: ct.input,
|
|
171
|
+
outputPer1M: ct.output,
|
|
172
|
+
...(ct.cache_read != null ? { cacheReadPer1M: ct.cache_read } : {}),
|
|
173
|
+
...(ct.cache_write != null ? { cacheWritePer1M: ct.cache_write } : {}),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (list.length === 0)
|
|
180
|
+
throw new Error("no runnable providers (no API keys, or SDKs not installed?)");
|
|
181
|
+
list.sort((a, b) => a.label.localeCompare(b.label));
|
|
182
|
+
const defaultModel = options.defaultModel ?? pickDefaultModel(factories, list);
|
|
183
|
+
catalog = {
|
|
184
|
+
models: list,
|
|
185
|
+
pricing: staticPricing(rates),
|
|
186
|
+
...buildResolvers(factories, idToProvider, defaultModel),
|
|
187
|
+
defaultModel,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
catch (e) {
|
|
191
|
+
console.warn("models.dev unavailable, using fallback list:", e instanceof Error ? e.message : e);
|
|
192
|
+
// Offline: the same eligibility rule (keyed + installed) over the
|
|
193
|
+
// fallback list's providers, from the well-known key env names.
|
|
194
|
+
factories ??= await loadFactories(keyedProviders(providers));
|
|
195
|
+
catalog = fallbackCatalog(factories, options.defaultModel);
|
|
196
|
+
}
|
|
197
|
+
// An explicit default that this deployment can't build is a configuration
|
|
198
|
+
// error — say so now, not on the first turn that falls back to it.
|
|
199
|
+
const dp = providerFromId(catalog.defaultModel) ?? providerOfListed(catalog.models, catalog.defaultModel);
|
|
200
|
+
if (!dp || !factories.has(dp)) {
|
|
201
|
+
cache.delete(key);
|
|
202
|
+
throw new Error(`[latch-core/models] default model "${catalog.defaultModel}" is not runnable here — ` +
|
|
203
|
+
`its provider${dp ? ` (@ai-sdk/${dp})` : ""} is not installed or has no API key set`);
|
|
204
|
+
}
|
|
205
|
+
return catalog;
|
|
206
|
+
})();
|
|
207
|
+
cache.set(key, loading);
|
|
208
|
+
return loading;
|
|
209
|
+
}
|
|
210
|
+
const providerOfListed = (models, id) => models.find((m) => m.id === id)?.provider;
|
|
211
|
+
//# sourceMappingURL=catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../src/models/catalog.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAmB,MAAM,eAAe,CAAC;AAyD9E;;;;GAIG;AACH,MAAM,OAAO,GAAuD;IAClE,SAAS,EAAE,KAAK,IAAI,EAAE;QACpB,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC;QACxD,OAAO;YACL,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC;YAC5B,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC;gBACf,UAAU,EAAE,SAAS,CAAC,KAAK,CAAC,kBAAkB,EAAE;gBAChD,SAAS,EAAE,SAAS,CAAC,KAAK,CAAC,iBAAiB,EAAE;aAC/C,CAAC;SACH,CAAC;IACJ,CAAC;IACD,MAAM,EAAE,KAAK,IAAI,EAAE;QACjB,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAClD,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE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|
|
4
|
+
/**
|
|
5
|
+
* Per-principal cache-key suffix for memory-enabled agents (their system
|
|
6
|
+
* prompt is per-principal, so an OpenAI cache key shared across principals
|
|
7
|
+
* would route badly). Typically the storage owner key.
|
|
8
|
+
*/
|
|
9
|
+
principalKey?: (principal: P) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Prompt caching on (default true). `false` turns caching off
|
|
12
|
+
* (`resolvePromptCaching: () => undefined`) — the control arm of an A/B.
|
|
13
|
+
*/
|
|
14
|
+
promptCaching?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The provider-specific `RuntimeConfig` hooks, derived from one catalog:
|
|
18
|
+
* `pricing`, `resolveProviderTools`, `resolveReasoningOptions`,
|
|
19
|
+
* `resolvePromptCaching`. Spread into `createRuntime({...})`; override any one
|
|
20
|
+
* by listing it after the spread. This is what every host used to hand-write.
|
|
21
|
+
*/
|
|
22
|
+
export declare function providerDefaults<P, RC = unknown>(catalog: ModelCatalog, options?: ProviderDefaultsOptions<P>): Pick<RuntimeConfig<P, RC>, "pricing" | "resolveProviderTools" | "resolveReasoningOptions" | "resolvePromptCaching">;
|
|
23
|
+
//# sourceMappingURL=defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/models/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAIjD,MAAM,WAAW,uBAAuB,CAAC,CAAC;IACxC;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,KAAK,MAAM,CAAC;IACxC;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,EAC9C,OAAO,EAAE,YAAY,EACrB,OAAO,GAAE,uBAAuB,CAAC,CAAC,CAAM,GACvC,IAAI,CACL,aAAa,CAAC,CAAC,EAAE,EAAE,CAAC,EACpB,SAAS,GAAG,sBAAsB,GAAG,yBAAyB,GAAG,sBAAsB,CACxF,CAUA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { makeResolveReasoningOptions } from "./reasoning.js";
|
|
2
|
+
import { makeResolvePromptCaching } from "./prompt-caching.js";
|
|
3
|
+
/**
|
|
4
|
+
* The provider-specific `RuntimeConfig` hooks, derived from one catalog:
|
|
5
|
+
* `pricing`, `resolveProviderTools`, `resolveReasoningOptions`,
|
|
6
|
+
* `resolvePromptCaching`. Spread into `createRuntime({...})`; override any one
|
|
7
|
+
* by listing it after the spread. This is what every host used to hand-write.
|
|
8
|
+
*/
|
|
9
|
+
export function providerDefaults(catalog, options = {}) {
|
|
10
|
+
return {
|
|
11
|
+
pricing: catalog.pricing,
|
|
12
|
+
resolveProviderTools: catalog.providerTools,
|
|
13
|
+
resolveReasoningOptions: makeResolveReasoningOptions(catalog.models),
|
|
14
|
+
resolvePromptCaching: options.promptCaching === false
|
|
15
|
+
? () => undefined
|
|
16
|
+
: makeResolvePromptCaching(catalog.models, options.principalKey),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/models/defaults.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAgB/D;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAAqB,EACrB,UAAsC,EAAE;IAKxC,OAAO;QACL,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,oBAAoB,EAAE,OAAO,CAAC,aAAa;QAC3C,uBAAuB,EAAE,2BAA2B,CAAC,OAAO,CAAC,MAAM,CAAC;QACpE,oBAAoB,EAClB,OAAO,CAAC,aAAa,KAAK,KAAK;YAC7B,CAAC,CAAC,GAAG,EAAE,CAAC,SAAS;YACjB,CAAC,CAAC,wBAAwB,CAAI,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC;KACxE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @intentface/latch-core/models
|
|
3
|
+
*
|
|
4
|
+
* The model side of a Latch host, so no host hand-writes it: a models.dev-backed
|
|
5
|
+
* catalog (ids, labels, pricing, reasoning capability, max output), provider
|
|
6
|
+
* inference from a model id, and the `RuntimeConfig` hooks that depend on the
|
|
7
|
+
* provider — reasoning effort, native web tools, prompt caching.
|
|
8
|
+
*
|
|
9
|
+
* A separate subpath because it is the one part of core that touches provider
|
|
10
|
+
* SDKs — `@ai-sdk/anthropic|openai|google` are OPTIONAL peers, imported lazily
|
|
11
|
+
* per provider only when that provider is usable (SDK installed + key set).
|
|
12
|
+
* Importing the core root pulls in none of them.
|
|
13
|
+
*/
|
|
14
|
+
export { loadModelCatalog } from "./catalog.js";
|
|
15
|
+
export type { ModelCatalog, ModelCatalogOptions, ModelInfo } from "./catalog.js";
|
|
16
|
+
export { providerOf, providerFromId, PROVIDER_IDS } from "./provider.js";
|
|
17
|
+
export type { ProviderId } from "./provider.js";
|
|
18
|
+
export { makeResolveReasoningOptions } from "./reasoning.js";
|
|
19
|
+
export type { ReasoningEffort, ReasoningResolution } from "./reasoning.js";
|
|
20
|
+
export { makeResolvePromptCaching } from "./prompt-caching.js";
|
|
21
|
+
export { providerDefaults } from "./defaults.js";
|
|
22
|
+
export type { ProviderDefaultsOptions } from "./defaults.js";
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,YAAY,EAAE,YAAY,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACzE,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC7D,YAAY,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,YAAY,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @intentface/latch-core/models
|
|
3
|
+
*
|
|
4
|
+
* The model side of a Latch host, so no host hand-writes it: a models.dev-backed
|
|
5
|
+
* catalog (ids, labels, pricing, reasoning capability, max output), provider
|
|
6
|
+
* inference from a model id, and the `RuntimeConfig` hooks that depend on the
|
|
7
|
+
* provider — reasoning effort, native web tools, prompt caching.
|
|
8
|
+
*
|
|
9
|
+
* A separate subpath because it is the one part of core that touches provider
|
|
10
|
+
* SDKs — `@ai-sdk/anthropic|openai|google` are OPTIONAL peers, imported lazily
|
|
11
|
+
* per provider only when that provider is usable (SDK installed + key set).
|
|
12
|
+
* Importing the core root pulls in none of them.
|
|
13
|
+
*/
|
|
14
|
+
export { loadModelCatalog } from "./catalog.js";
|
|
15
|
+
export { providerOf, providerFromId, PROVIDER_IDS } from "./provider.js";
|
|
16
|
+
export { makeResolveReasoningOptions } from "./reasoning.js";
|
|
17
|
+
export { makeResolvePromptCaching } from "./prompt-caching.js";
|
|
18
|
+
export { providerDefaults } from "./defaults.js";
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAEzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAE7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type PromptCachingPlan } from "../prompt-caching.js";
|
|
2
|
+
/**
|
|
3
|
+
* Build the `RuntimeConfig.resolvePromptCaching` hook over the model catalog —
|
|
4
|
+
* core applies the plan; this side knows which provider a model id belongs to.
|
|
5
|
+
* Anthropic models get explicit cache breakpoints; OpenAI models get a cache
|
|
6
|
+
* routing key (`prompt_cache_key` — OpenAI caches automatically, the key only
|
|
7
|
+
* improves shard routing); other providers get nothing. `principalKey` scopes
|
|
8
|
+
* the OpenAI key per principal for memory-enabled agents, whose system prompt
|
|
9
|
+
* is per-principal (omit it and memory-scoped turns share the agent key).
|
|
10
|
+
*/
|
|
11
|
+
export declare function makeResolvePromptCaching<P>(models: ReadonlyArray<{
|
|
12
|
+
id: string;
|
|
13
|
+
provider: string;
|
|
14
|
+
}>, principalKey?: (principal: P) => string): (modelId: string, args: {
|
|
15
|
+
agent: string;
|
|
16
|
+
memoryScoped: boolean;
|
|
17
|
+
principal: P;
|
|
18
|
+
}) => PromptCachingPlan | undefined;
|
|
19
|
+
//# sourceMappingURL=prompt-caching.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-caching.d.ts","sourceRoot":"","sources":["../../src/models/prompt-caching.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAGpF;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EACxC,MAAM,EAAE,aAAa,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,EACvD,YAAY,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,KAAK,MAAM,IAGrC,SAAS,MAAM,EACf,MAAM;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,CAAC,CAAA;CAAE,KAC3D,iBAAiB,GAAG,SAAS,CAKjC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { promptCachingPlanFor } from "../prompt-caching.js";
|
|
2
|
+
import { providerOf } from "./provider.js";
|
|
3
|
+
/**
|
|
4
|
+
* Build the `RuntimeConfig.resolvePromptCaching` hook over the model catalog —
|
|
5
|
+
* core applies the plan; this side knows which provider a model id belongs to.
|
|
6
|
+
* Anthropic models get explicit cache breakpoints; OpenAI models get a cache
|
|
7
|
+
* routing key (`prompt_cache_key` — OpenAI caches automatically, the key only
|
|
8
|
+
* improves shard routing); other providers get nothing. `principalKey` scopes
|
|
9
|
+
* the OpenAI key per principal for memory-enabled agents, whose system prompt
|
|
10
|
+
* is per-principal (omit it and memory-scoped turns share the agent key).
|
|
11
|
+
*/
|
|
12
|
+
export function makeResolvePromptCaching(models, principalKey) {
|
|
13
|
+
return (modelId, args) => promptCachingPlanFor(providerOf(modelId, models), {
|
|
14
|
+
agent: args.agent,
|
|
15
|
+
...(args.memoryScoped && principalKey ? { cacheKeySuffix: principalKey(args.principal) } : {}),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=prompt-caching.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-caching.js","sourceRoot":"","sources":["../../src/models/prompt-caching.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAA0B,MAAM,sBAAsB,CAAC;AACpF,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C;;;;;;;;GAQG;AACH,MAAM,UAAU,wBAAwB,CACtC,MAAuD,EACvD,YAAuC;IAEvC,OAAO,CACL,OAAe,EACf,IAA4D,EAC7B,EAAE,CACjC,oBAAoB,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE;QAChD,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,GAAG,CAAC,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC/F,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which first-party provider a model id belongs to. ONE place for the id-prefix
|
|
3
|
+
* heuristic that used to live in three files (catalog fallback, provider tools,
|
|
4
|
+
* prompt caching) — a catalog entry wins when one is available; the prefixes
|
|
5
|
+
* cover models not in the catalog (offline fallback list, custom ids).
|
|
6
|
+
*/
|
|
7
|
+
export type ProviderId = "anthropic" | "openai" | "google";
|
|
8
|
+
export declare const PROVIDER_IDS: readonly ProviderId[];
|
|
9
|
+
/** Provider by id prefix alone: claude → anthropic; gpt/o-series → openai; gemini/gemma → google. */
|
|
10
|
+
export declare function providerFromId(modelId: string): ProviderId | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Provider for a model id: the catalog's answer when the id is listed, else the
|
|
13
|
+
* id-prefix heuristic. `catalog` is any list of `{ id, provider }`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function providerOf(modelId: string, catalog?: ReadonlyArray<{
|
|
16
|
+
id: string;
|
|
17
|
+
provider: string;
|
|
18
|
+
}>): ProviderId | undefined;
|
|
19
|
+
//# sourceMappingURL=provider.d.ts.map
|