@duetso/agent 0.1.29 → 0.1.31

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.
@@ -1,129 +0,0 @@
1
- import { findEnvKeys, getModel } from "@earendil-works/pi-ai";
2
- import { DUET_GATEWAY_API_KEY_ENV, isDuetGatewayModelName, resolveDuetGatewayModel, } from "./duet-gateway.js";
3
- /**
4
- * Provider inference order. Entries are tried top-to-bottom; the first one
5
- * with a present env var wins. `customEnvVar` covers providers pi-ai's
6
- * `findEnvKeys` doesn't know about (currently only `duet-gateway`).
7
- *
8
- * `duet-gateway` sits before `vercel-ai-gateway` because the CLI startup shim
9
- * copies `DUET_API_KEY` into `AI_GATEWAY_API_KEY`, which would otherwise route
10
- * through Vercel's gateway directly when the user only set `DUET_API_KEY`.
11
- */
12
- const MODEL_PROVIDER_INFERENCE = [
13
- {
14
- provider: "duet-gateway",
15
- model: "duet-gateway:anthropic/claude-opus-4.7",
16
- customEnvVar: () => (process.env[DUET_GATEWAY_API_KEY_ENV] ? DUET_GATEWAY_API_KEY_ENV : null),
17
- },
18
- {
19
- provider: "vercel-ai-gateway",
20
- model: "vercel-ai-gateway:anthropic/claude-opus-4.7",
21
- },
22
- {
23
- provider: "openrouter",
24
- model: "openrouter:anthropic/claude-opus-4.7",
25
- },
26
- {
27
- provider: "anthropic",
28
- model: "anthropic:claude-opus-4-7",
29
- },
30
- {
31
- provider: "openai",
32
- model: "openai:gpt-5.5",
33
- },
34
- ];
35
- const MEMORY_MODEL_PROVIDER_INFERENCE = [
36
- {
37
- provider: "duet-gateway",
38
- model: "duet-gateway:anthropic/claude-haiku-4.5",
39
- customEnvVar: () => (process.env[DUET_GATEWAY_API_KEY_ENV] ? DUET_GATEWAY_API_KEY_ENV : null),
40
- },
41
- {
42
- provider: "vercel-ai-gateway",
43
- model: "vercel-ai-gateway:anthropic/claude-haiku-4.5",
44
- },
45
- {
46
- provider: "openrouter",
47
- model: "openrouter:anthropic/claude-haiku-4.5",
48
- },
49
- {
50
- provider: "anthropic",
51
- model: "anthropic:claude-haiku-4-5",
52
- },
53
- {
54
- provider: "openai",
55
- model: "openai:gpt-5.4-mini",
56
- },
57
- ];
58
- export const DEFAULT_CLI_MODEL = "anthropic:claude-opus-4-7";
59
- export const DEFAULT_CLI_MEMORY_MODEL = "anthropic:claude-haiku-4-5";
60
- export function resolveModelName(model) {
61
- const separator = model.indexOf(":");
62
- if (separator === -1) {
63
- throw new Error("Models must use provider:modelId syntax");
64
- }
65
- if (isDuetGatewayModelName(model)) {
66
- const modelId = model.slice(separator + 1);
67
- const resolved = resolveDuetGatewayModel(modelId);
68
- if (!resolved) {
69
- throw new Error(`Unknown duet-gateway model: ${modelId}`);
70
- }
71
- return resolved;
72
- }
73
- const provider = model.slice(0, separator);
74
- const modelId = model.slice(separator + 1);
75
- return getModel(provider, modelId);
76
- }
77
- function lookupProviderEnvVar(entry) {
78
- if (entry.customEnvVar) {
79
- return entry.customEnvVar() ?? undefined;
80
- }
81
- const envVars = findEnvKeys(entry.provider);
82
- return envVars && envVars.length > 0 ? envVars[0] : undefined;
83
- }
84
- /**
85
- * Same selection logic as resolveCliModel, but picks each provider's cheaper
86
- * observational-memory model.
87
- */
88
- export function resolveCliMemoryModel(memoryModelName, dotenvKeys) {
89
- return resolveCliModelWith(memoryModelName, MEMORY_MODEL_PROVIDER_INFERENCE, dotenvKeys, DEFAULT_CLI_MEMORY_MODEL);
90
- }
91
- /**
92
- * Resolve the user-visible model and report provenance so callers can show
93
- * "inferred from ANTHROPIC_API_KEY in an env file" etc.
94
- */
95
- export function resolveCliModel(modelName, dotenvKeys) {
96
- return resolveCliModelWith(modelName, MODEL_PROVIDER_INFERENCE, dotenvKeys, DEFAULT_CLI_MODEL);
97
- }
98
- function resolveCliModelWith(modelName, providerInference, dotenvKeys, defaultModel) {
99
- if (modelName)
100
- return { modelName, source: "explicit" };
101
- const inferred = findInferredProviderEntry(providerInference);
102
- if (inferred) {
103
- return {
104
- modelName: inferred.entry.model,
105
- source: "inferred",
106
- envVar: inferred.envVar,
107
- fromDotenv: dotenvKeys.has(inferred.envVar),
108
- };
109
- }
110
- return { modelName: defaultModel, source: "default" };
111
- }
112
- function findInferredProviderEntry(providerInference) {
113
- for (const entry of providerInference) {
114
- const envVar = lookupProviderEnvVar(entry);
115
- if (envVar)
116
- return { entry, envVar };
117
- }
118
- return undefined;
119
- }
120
- export function describeModelResolution(resolution) {
121
- if (resolution.source === "explicit")
122
- return "explicit CLI flag";
123
- if (resolution.source === "inferred") {
124
- const where = resolution.fromDotenv ? "an env file" : "shell environment";
125
- return `inferred from ${resolution.envVar} in ${where}`;
126
- }
127
- return "built-in default (no provider env vars set)";
128
- }
129
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/model-resolution/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAc,MAAM,uBAAuB,CAAC;AAE1E,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAyB3B;;;;;;;;GAQG;AACH,MAAM,wBAAwB,GAA6B;IACzD;QACE,QAAQ,EAAE,cAAc;QACxB,KAAK,EAAE,wCAAwC;QAC/C,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,IAAI,CAAC;KAC9F;IACD;QACE,QAAQ,EAAE,mBAAmB;QAC7B,KAAK,EAAE,6CAA6C;KACrD;IACD;QACE,QAAQ,EAAE,YAAY;QACtB,KAAK,EAAE,sCAAsC;KAC9C;IACD;QACE,QAAQ,EAAE,WAAW;QACrB,KAAK,EAAE,2BAA2B;KACnC;IACD;QACE,QAAQ,EAAE,QAAQ;QAClB,KAAK,EAAE,gBAAgB;KACxB;CACF,CAAC;AAEF,MAAM,+BAA+B,G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