@agi-cli/sdk 0.1.120 → 0.1.122
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/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -41,6 +41,7 @@ export {
|
|
|
41
41
|
defaultModelFor,
|
|
42
42
|
hasModel,
|
|
43
43
|
getFastModel,
|
|
44
|
+
getFastModelForAuth,
|
|
44
45
|
} from './providers/src/index.ts';
|
|
45
46
|
export {
|
|
46
47
|
isProviderAuthorized,
|
|
@@ -66,6 +67,11 @@ export {
|
|
|
66
67
|
createOpenAIOAuthModel,
|
|
67
68
|
} from './providers/src/index.ts';
|
|
68
69
|
export type { OpenAIOAuthConfig } from './providers/src/index.ts';
|
|
70
|
+
export {
|
|
71
|
+
isModelAllowedForOAuth,
|
|
72
|
+
filterModelsForAuthType,
|
|
73
|
+
getOAuthModelPrefixes,
|
|
74
|
+
} from './providers/src/index.ts';
|
|
69
75
|
|
|
70
76
|
// =======================
|
|
71
77
|
// Authentication (from internal auth module)
|
|
@@ -12,6 +12,7 @@ export {
|
|
|
12
12
|
defaultModelFor,
|
|
13
13
|
hasModel,
|
|
14
14
|
getFastModel,
|
|
15
|
+
getFastModelForAuth,
|
|
15
16
|
} from './utils.ts';
|
|
16
17
|
export { validateProviderModel } from './validate.ts';
|
|
17
18
|
export { estimateModelCostUsd } from './pricing.ts';
|
|
@@ -29,3 +30,8 @@ export {
|
|
|
29
30
|
createOpenAIOAuthModel,
|
|
30
31
|
} from './openai-oauth-client.ts';
|
|
31
32
|
export type { OpenAIOAuthConfig } from './openai-oauth-client.ts';
|
|
33
|
+
export {
|
|
34
|
+
isModelAllowedForOAuth,
|
|
35
|
+
filterModelsForAuthType,
|
|
36
|
+
getOAuthModelPrefixes,
|
|
37
|
+
} from './oauth-models.ts';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ProviderId, ModelInfo } from '../../types/src/index.ts';
|
|
2
|
+
|
|
3
|
+
const OAUTH_MODEL_PREFIXES: Partial<Record<ProviderId, string[]>> = {
|
|
4
|
+
anthropic: ['claude-haiku-4-5', 'claude-opus-4-5', 'claude-sonnet-4-5'],
|
|
5
|
+
openai: [
|
|
6
|
+
'gpt-5.2-codex',
|
|
7
|
+
'gpt-5.1-codex-max',
|
|
8
|
+
'gpt-5.1-codex-mini',
|
|
9
|
+
'gpt-5.2',
|
|
10
|
+
],
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function isModelAllowedForOAuth(
|
|
14
|
+
provider: ProviderId,
|
|
15
|
+
modelId: string,
|
|
16
|
+
): boolean {
|
|
17
|
+
const prefixes = OAUTH_MODEL_PREFIXES[provider];
|
|
18
|
+
if (!prefixes) return true;
|
|
19
|
+
return prefixes.some((prefix) => modelId.startsWith(prefix));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function filterModelsForAuthType(
|
|
23
|
+
provider: ProviderId,
|
|
24
|
+
models: ModelInfo[],
|
|
25
|
+
authType: 'api' | 'oauth' | 'wallet' | undefined,
|
|
26
|
+
): ModelInfo[] {
|
|
27
|
+
if (authType !== 'oauth') return models;
|
|
28
|
+
const prefixes = OAUTH_MODEL_PREFIXES[provider];
|
|
29
|
+
if (!prefixes) return models;
|
|
30
|
+
return models.filter((m) =>
|
|
31
|
+
prefixes.some((prefix) => m.id.startsWith(prefix)),
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function getOAuthModelPrefixes(
|
|
36
|
+
provider: ProviderId,
|
|
37
|
+
): string[] | undefined {
|
|
38
|
+
return OAUTH_MODEL_PREFIXES[provider];
|
|
39
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { catalog } from './catalog-merged.ts';
|
|
2
|
-
import type { ProviderId } from '../../types/src/index.ts';
|
|
2
|
+
import type { ProviderId, ModelInfo } from '../../types/src/index.ts';
|
|
3
|
+
import { filterModelsForAuthType } from './oauth-models.ts';
|
|
3
4
|
|
|
4
5
|
export const providerIds = Object.keys(catalog) as ProviderId[];
|
|
5
6
|
|
|
@@ -61,3 +62,39 @@ export function getFastModel(provider: ProviderId): string | undefined {
|
|
|
61
62
|
|
|
62
63
|
return sorted[0]?.id ?? providerModels[0]?.id;
|
|
63
64
|
}
|
|
65
|
+
|
|
66
|
+
export function getFastModelForAuth(
|
|
67
|
+
provider: ProviderId,
|
|
68
|
+
authType: 'api' | 'oauth' | 'wallet' | undefined,
|
|
69
|
+
): string | undefined {
|
|
70
|
+
const providerModels = catalog[provider]?.models ?? [];
|
|
71
|
+
if (!providerModels.length) return undefined;
|
|
72
|
+
|
|
73
|
+
const filteredModels = filterModelsForAuthType(
|
|
74
|
+
provider,
|
|
75
|
+
providerModels,
|
|
76
|
+
authType,
|
|
77
|
+
);
|
|
78
|
+
if (!filteredModels.length) return getFastModel(provider);
|
|
79
|
+
|
|
80
|
+
if (authType !== 'oauth') {
|
|
81
|
+
const preferred = PREFERRED_FAST_MODELS[provider] ?? [];
|
|
82
|
+
for (const modelId of preferred) {
|
|
83
|
+
if (filteredModels.some((m) => m.id === modelId)) {
|
|
84
|
+
return modelId;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// For OAuth or when no preferred model found, use cost-based selection
|
|
90
|
+
const sorted = [...filteredModels]
|
|
91
|
+
.filter(
|
|
92
|
+
(m: ModelInfo) => m.cost?.input !== undefined && m.toolCall !== false,
|
|
93
|
+
)
|
|
94
|
+
.sort(
|
|
95
|
+
(a: ModelInfo, b: ModelInfo) =>
|
|
96
|
+
(a.cost?.input ?? Infinity) - (b.cost?.input ?? Infinity),
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
return sorted[0]?.id ?? filteredModels[0]?.id;
|
|
100
|
+
}
|