my-pi 0.3.5 → 0.4.0
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 +32 -252
- package/dist/extensions.d.ts +11 -0
- package/dist/extensions.js +148 -0
- package/dist/extensions.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +40 -523
- package/dist/index.js.map +1 -1
- package/dist/manager.d.ts +3 -0
- package/dist/manager.js +71 -0
- package/dist/manager.js.map +1 -0
- package/dist/settings.d.ts +3 -0
- package/dist/settings.js +16 -0
- package/dist/settings.js.map +1 -0
- package/package.json +33 -78
- package/dist/api.d.ts +0 -494
- package/dist/api.js +0 -532
- package/dist/api.js.map +0 -1
- package/dist/builtin-registry-wSfsQBi4.js +0 -563
- package/dist/builtin-registry-wSfsQBi4.js.map +0 -1
- package/dist/footer-BAZIMVSb.js +0 -1
- package/dist/handoff-C6wR2mSG.js +0 -28
- package/dist/handoff-C6wR2mSG.js.map +0 -1
- package/dist/hooks-resolution-qlhPfMFJ.js +0 -485
- package/dist/hooks-resolution-qlhPfMFJ.js.map +0 -1
- package/dist/openrouter-fusion-config-BWsHBPQv.js +0 -65
- package/dist/openrouter-fusion-config-BWsHBPQv.js.map +0 -1
- package/dist/prompt-presets-XraV03Ed.js +0 -1402
- package/dist/prompt-presets-XraV03Ed.js.map +0 -1
- package/dist/session-name-CD6TVRnh.js +0 -158
- package/dist/session-name-CD6TVRnh.js.map +0 -1
- package/dist/settings-BCn3P9qH.js +0 -177
- package/dist/settings-BCn3P9qH.js.map +0 -1
- package/dist/startup-screen-DUeBWuAc.js +0 -218
- package/dist/startup-screen-DUeBWuAc.js.map +0 -1
- package/dist/turn-timer-CoyDI4gQ.js +0 -64
- package/dist/turn-timer-CoyDI4gQ.js.map +0 -1
- package/dist/umans-provider-C2UJ4qkO.js +0 -307
- package/dist/umans-provider-C2UJ4qkO.js.map +0 -1
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
import { createProvider } from "@earendil-works/pi-ai";
|
|
2
|
-
import { anthropicMessagesApi } from "@earendil-works/pi-ai/api/anthropic-messages.lazy";
|
|
3
|
-
//#region src/extensions/umans-provider/index.ts
|
|
4
|
-
const DEFAULT_BASE_URL = "https://api.code.umans.ai";
|
|
5
|
-
const API_KEY_ENV = "UMANS_API_KEY";
|
|
6
|
-
const USER_AGENT = "my-pi-umans-provider/0.1.0";
|
|
7
|
-
const STATIC_UMANS_CATALOG = {
|
|
8
|
-
"umans-kimi-k2.6": {
|
|
9
|
-
name: "umans-kimi-k2.6",
|
|
10
|
-
display_name: "Umans Kimi K2.6",
|
|
11
|
-
capabilities: {
|
|
12
|
-
max_completion_tokens: 262144,
|
|
13
|
-
recommended_max_tokens: 32768,
|
|
14
|
-
context_window: 262144,
|
|
15
|
-
supports_vision: true,
|
|
16
|
-
supports_tools: true,
|
|
17
|
-
reasoning: {
|
|
18
|
-
supported: true,
|
|
19
|
-
can_disable: true,
|
|
20
|
-
levels: [
|
|
21
|
-
"none",
|
|
22
|
-
"minimal",
|
|
23
|
-
"low",
|
|
24
|
-
"medium",
|
|
25
|
-
"high",
|
|
26
|
-
"xhigh",
|
|
27
|
-
"max"
|
|
28
|
-
],
|
|
29
|
-
default_level: "medium"
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
"umans-kimi-k2.7": {
|
|
34
|
-
name: "umans-kimi-k2.7",
|
|
35
|
-
display_name: "Umans Kimi K2.7 Code",
|
|
36
|
-
capabilities: {
|
|
37
|
-
max_completion_tokens: 262144,
|
|
38
|
-
recommended_max_tokens: 32768,
|
|
39
|
-
context_window: 262144,
|
|
40
|
-
supports_vision: true,
|
|
41
|
-
supports_tools: true,
|
|
42
|
-
reasoning: {
|
|
43
|
-
supported: true,
|
|
44
|
-
can_disable: false,
|
|
45
|
-
levels: [
|
|
46
|
-
"minimal",
|
|
47
|
-
"low",
|
|
48
|
-
"medium",
|
|
49
|
-
"high",
|
|
50
|
-
"xhigh",
|
|
51
|
-
"max"
|
|
52
|
-
],
|
|
53
|
-
default_level: "medium"
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
"umans-glm-5.2": {
|
|
58
|
-
name: "umans-glm-5.2",
|
|
59
|
-
display_name: "Umans GLM 5.2",
|
|
60
|
-
capabilities: {
|
|
61
|
-
max_completion_tokens: 131072,
|
|
62
|
-
recommended_max_tokens: 131071,
|
|
63
|
-
context_window: 405504,
|
|
64
|
-
supports_vision: "via-handoff",
|
|
65
|
-
supports_tools: true,
|
|
66
|
-
reasoning: {
|
|
67
|
-
supported: true,
|
|
68
|
-
can_disable: true,
|
|
69
|
-
levels: [
|
|
70
|
-
"none",
|
|
71
|
-
"minimal",
|
|
72
|
-
"low",
|
|
73
|
-
"medium",
|
|
74
|
-
"high",
|
|
75
|
-
"xhigh",
|
|
76
|
-
"max"
|
|
77
|
-
],
|
|
78
|
-
default_level: "medium"
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
"umans-coder": {
|
|
83
|
-
name: "umans-coder",
|
|
84
|
-
display_name: "Umans Coder",
|
|
85
|
-
capabilities: {
|
|
86
|
-
max_completion_tokens: 262144,
|
|
87
|
-
recommended_max_tokens: 32768,
|
|
88
|
-
context_window: 262144,
|
|
89
|
-
supports_vision: true,
|
|
90
|
-
supports_tools: true,
|
|
91
|
-
reasoning: {
|
|
92
|
-
supported: true,
|
|
93
|
-
can_disable: false,
|
|
94
|
-
levels: [
|
|
95
|
-
"minimal",
|
|
96
|
-
"low",
|
|
97
|
-
"medium",
|
|
98
|
-
"high",
|
|
99
|
-
"xhigh",
|
|
100
|
-
"max"
|
|
101
|
-
],
|
|
102
|
-
default_level: "medium"
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
"umans-flash": {
|
|
107
|
-
name: "umans-flash",
|
|
108
|
-
display_name: "Umans Flash",
|
|
109
|
-
capabilities: {
|
|
110
|
-
max_completion_tokens: 262144,
|
|
111
|
-
recommended_max_tokens: 32768,
|
|
112
|
-
context_window: 262144,
|
|
113
|
-
supports_vision: true,
|
|
114
|
-
supports_tools: true,
|
|
115
|
-
reasoning: {
|
|
116
|
-
supported: true,
|
|
117
|
-
can_disable: true,
|
|
118
|
-
levels: [
|
|
119
|
-
"none",
|
|
120
|
-
"minimal",
|
|
121
|
-
"low",
|
|
122
|
-
"medium",
|
|
123
|
-
"high",
|
|
124
|
-
"xhigh",
|
|
125
|
-
"max"
|
|
126
|
-
],
|
|
127
|
-
default_level: "medium"
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
"umans-qwen3.6-35b-a3b": {
|
|
132
|
-
name: "umans-qwen3.6-35b-a3b",
|
|
133
|
-
display_name: "Umans Qwen3.6 35B A3B",
|
|
134
|
-
capabilities: {
|
|
135
|
-
max_completion_tokens: 262144,
|
|
136
|
-
recommended_max_tokens: 32768,
|
|
137
|
-
context_window: 262144,
|
|
138
|
-
supports_vision: true,
|
|
139
|
-
supports_tools: true,
|
|
140
|
-
reasoning: {
|
|
141
|
-
supported: true,
|
|
142
|
-
can_disable: true,
|
|
143
|
-
levels: [
|
|
144
|
-
"none",
|
|
145
|
-
"minimal",
|
|
146
|
-
"low",
|
|
147
|
-
"medium",
|
|
148
|
-
"high",
|
|
149
|
-
"xhigh",
|
|
150
|
-
"max"
|
|
151
|
-
],
|
|
152
|
-
default_level: "medium"
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
function safe_max_tokens(recommended, cap) {
|
|
158
|
-
let value = typeof recommended === "number" && recommended > 0 ? recommended : 32768;
|
|
159
|
-
if (typeof cap === "number" && cap > 0) value = Math.min(value, cap - 1);
|
|
160
|
-
return Math.max(value, 1);
|
|
161
|
-
}
|
|
162
|
-
function is_record(value) {
|
|
163
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
164
|
-
}
|
|
165
|
-
function normalize_umans_catalog(value) {
|
|
166
|
-
const source = is_record(value) && is_record(value.data) ? value.data : value;
|
|
167
|
-
if (!is_record(source)) return {};
|
|
168
|
-
const catalog = {};
|
|
169
|
-
for (const [id, info] of Object.entries(source)) {
|
|
170
|
-
if (!is_record(info)) continue;
|
|
171
|
-
const capabilities = is_record(info.capabilities) ? info.capabilities : {};
|
|
172
|
-
catalog[id] = {
|
|
173
|
-
name: typeof info.name === "string" ? info.name : id,
|
|
174
|
-
display_name: typeof info.display_name === "string" ? info.display_name : id,
|
|
175
|
-
deprecation: info.deprecation,
|
|
176
|
-
capabilities
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
return catalog;
|
|
180
|
-
}
|
|
181
|
-
async function fetch_umans_catalog(base_url, api_key, signal) {
|
|
182
|
-
const headers = { "user-agent": USER_AGENT };
|
|
183
|
-
if (api_key) headers.authorization = `Bearer ${api_key}`;
|
|
184
|
-
const response = await fetch(`${base_url.replace(/\/$/, "")}/v1/models/info`, {
|
|
185
|
-
headers,
|
|
186
|
-
signal
|
|
187
|
-
});
|
|
188
|
-
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
189
|
-
return normalize_umans_catalog(await response.json());
|
|
190
|
-
}
|
|
191
|
-
function to_pi_models(catalog, base_url = DEFAULT_BASE_URL) {
|
|
192
|
-
return Object.entries(catalog).filter(([, info]) => !info.deprecation).map(([id, info]) => {
|
|
193
|
-
const capabilities = info.capabilities ?? {};
|
|
194
|
-
const input = capabilities.supports_vision ? ["text", "image"] : ["text"];
|
|
195
|
-
return {
|
|
196
|
-
id,
|
|
197
|
-
name: info.display_name ?? id,
|
|
198
|
-
api: "anthropic-messages",
|
|
199
|
-
provider: "umans",
|
|
200
|
-
baseUrl: base_url,
|
|
201
|
-
maxTokens: safe_max_tokens(capabilities.recommended_max_tokens, capabilities.max_completion_tokens),
|
|
202
|
-
contextWindow: capabilities.context_window ?? 262144,
|
|
203
|
-
reasoning: capabilities.reasoning?.supported === true,
|
|
204
|
-
input,
|
|
205
|
-
cost: {
|
|
206
|
-
input: 0,
|
|
207
|
-
output: 0,
|
|
208
|
-
cacheRead: 0,
|
|
209
|
-
cacheWrite: 0
|
|
210
|
-
},
|
|
211
|
-
supportsTools: capabilities.supports_tools !== false
|
|
212
|
-
};
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
async function prompt_for_api_key(interaction) {
|
|
216
|
-
const key = (await interaction.prompt({
|
|
217
|
-
type: "secret",
|
|
218
|
-
message: "Enter your Umans API key:"
|
|
219
|
-
})).trim();
|
|
220
|
-
if (!key) throw new Error("Umans API key is required");
|
|
221
|
-
return key;
|
|
222
|
-
}
|
|
223
|
-
function bearer_auth(key) {
|
|
224
|
-
return { auth: { headers: { authorization: `Bearer ${key}` } } };
|
|
225
|
-
}
|
|
226
|
-
function create_umans_api_key_auth(env = process.env) {
|
|
227
|
-
return {
|
|
228
|
-
name: "Umans API key",
|
|
229
|
-
async login(interaction) {
|
|
230
|
-
return {
|
|
231
|
-
type: "api_key",
|
|
232
|
-
key: await prompt_for_api_key(interaction)
|
|
233
|
-
};
|
|
234
|
-
},
|
|
235
|
-
async check({ credential }) {
|
|
236
|
-
if (credential?.key) return {
|
|
237
|
-
type: "api_key",
|
|
238
|
-
source: "stored API key"
|
|
239
|
-
};
|
|
240
|
-
if (env[API_KEY_ENV]?.trim()) return {
|
|
241
|
-
type: "api_key",
|
|
242
|
-
source: API_KEY_ENV
|
|
243
|
-
};
|
|
244
|
-
},
|
|
245
|
-
async resolve({ credential }) {
|
|
246
|
-
const stored_key = credential?.key?.trim();
|
|
247
|
-
if (stored_key) return {
|
|
248
|
-
...bearer_auth(stored_key),
|
|
249
|
-
source: "stored API key"
|
|
250
|
-
};
|
|
251
|
-
const env_key = env[API_KEY_ENV]?.trim();
|
|
252
|
-
return env_key ? {
|
|
253
|
-
...bearer_auth(env_key),
|
|
254
|
-
source: API_KEY_ENV
|
|
255
|
-
} : void 0;
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
function create_legacy_umans_oauth() {
|
|
260
|
-
return {
|
|
261
|
-
name: "Legacy Umans credential",
|
|
262
|
-
loginLabel: "Enter Umans API key (legacy credential)",
|
|
263
|
-
async login(interaction) {
|
|
264
|
-
const key = await prompt_for_api_key(interaction);
|
|
265
|
-
return {
|
|
266
|
-
type: "oauth",
|
|
267
|
-
refresh: key,
|
|
268
|
-
access: key,
|
|
269
|
-
expires: Date.now() + 31536e8
|
|
270
|
-
};
|
|
271
|
-
},
|
|
272
|
-
refresh: (credential) => Promise.resolve(credential),
|
|
273
|
-
toAuth: async (credential) => bearer_auth(credential.access).auth
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
function credential_key(credential, env) {
|
|
277
|
-
if (credential?.type === "api_key") return credential.key?.trim();
|
|
278
|
-
if (credential?.type === "oauth") return credential.access.trim();
|
|
279
|
-
return env[API_KEY_ENV]?.trim() || void 0;
|
|
280
|
-
}
|
|
281
|
-
function create_umans_provider(options = {}) {
|
|
282
|
-
const env = options.env ?? process.env;
|
|
283
|
-
const base_url = options.base_url?.trim() || env.UMANS_BASE_URL?.trim() || DEFAULT_BASE_URL;
|
|
284
|
-
const fetch_catalog = options.fetch_catalog ?? fetch_umans_catalog;
|
|
285
|
-
return createProvider({
|
|
286
|
-
id: "umans",
|
|
287
|
-
name: "Umans",
|
|
288
|
-
baseUrl: base_url,
|
|
289
|
-
auth: {
|
|
290
|
-
apiKey: create_umans_api_key_auth(env),
|
|
291
|
-
oauth: create_legacy_umans_oauth()
|
|
292
|
-
},
|
|
293
|
-
models: to_pi_models(STATIC_UMANS_CATALOG, base_url),
|
|
294
|
-
async fetchModels(context) {
|
|
295
|
-
return to_pi_models(await fetch_catalog(base_url, credential_key(context.credential, env), context.signal), base_url);
|
|
296
|
-
},
|
|
297
|
-
api: anthropicMessagesApi()
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
const extension = (pi) => {
|
|
301
|
-
if (process.env.UMANS_DISABLE === "1") return;
|
|
302
|
-
pi.registerProvider(create_umans_provider());
|
|
303
|
-
};
|
|
304
|
-
//#endregion
|
|
305
|
-
export { extension as default };
|
|
306
|
-
|
|
307
|
-
//# sourceMappingURL=umans-provider-C2UJ4qkO.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"umans-provider-C2UJ4qkO.js","names":[],"sources":["../src/extensions/umans-provider/index.ts"],"sourcesContent":["import {\n\tcreateProvider,\n\ttype ApiKeyAuth,\n\ttype AuthInteraction,\n\ttype Credential,\n\ttype OAuthAuth,\n\ttype OAuthCredential,\n\ttype Provider,\n} from '@earendil-works/pi-ai';\nimport { anthropicMessagesApi } from '@earendil-works/pi-ai/api/anthropic-messages.lazy';\nimport type { ExtensionFactory } from '@earendil-works/pi-coding-agent';\n\nconst DEFAULT_BASE_URL = 'https://api.code.umans.ai';\nconst API_KEY_ENV = 'UMANS_API_KEY';\nconst USER_AGENT = 'my-pi-umans-provider/0.1.0';\n\ninterface ReasoningInfo {\n\tsupported: boolean;\n\tcan_disable: boolean;\n\tlevels: string[];\n\tdefault_level: string;\n}\n\ninterface ModelCapabilities {\n\tmax_completion_tokens?: number;\n\trecommended_max_tokens?: number;\n\tcontext_window?: number;\n\tsupports_vision?: boolean | 'via-handoff';\n\tsupports_tools?: boolean;\n\treasoning?: ReasoningInfo;\n}\n\ninterface UmansModelInfo {\n\tname: string;\n\tdisplay_name?: string;\n\tdeprecation?: unknown;\n\tcapabilities: ModelCapabilities;\n}\n\nexport const STATIC_UMANS_CATALOG: Record<string, UmansModelInfo> = {\n\t'umans-kimi-k2.6': {\n\t\tname: 'umans-kimi-k2.6',\n\t\tdisplay_name: 'Umans Kimi K2.6',\n\t\tcapabilities: {\n\t\t\tmax_completion_tokens: 262144,\n\t\t\trecommended_max_tokens: 32768,\n\t\t\tcontext_window: 262144,\n\t\t\tsupports_vision: true,\n\t\t\tsupports_tools: true,\n\t\t\treasoning: {\n\t\t\t\tsupported: true,\n\t\t\t\tcan_disable: true,\n\t\t\t\tlevels: [\n\t\t\t\t\t'none',\n\t\t\t\t\t'minimal',\n\t\t\t\t\t'low',\n\t\t\t\t\t'medium',\n\t\t\t\t\t'high',\n\t\t\t\t\t'xhigh',\n\t\t\t\t\t'max',\n\t\t\t\t],\n\t\t\t\tdefault_level: 'medium',\n\t\t\t},\n\t\t},\n\t},\n\t'umans-kimi-k2.7': {\n\t\tname: 'umans-kimi-k2.7',\n\t\tdisplay_name: 'Umans Kimi K2.7 Code',\n\t\tcapabilities: {\n\t\t\tmax_completion_tokens: 262144,\n\t\t\trecommended_max_tokens: 32768,\n\t\t\tcontext_window: 262144,\n\t\t\tsupports_vision: true,\n\t\t\tsupports_tools: true,\n\t\t\treasoning: {\n\t\t\t\tsupported: true,\n\t\t\t\tcan_disable: false,\n\t\t\t\tlevels: ['minimal', 'low', 'medium', 'high', 'xhigh', 'max'],\n\t\t\t\tdefault_level: 'medium',\n\t\t\t},\n\t\t},\n\t},\n\t'umans-glm-5.2': {\n\t\tname: 'umans-glm-5.2',\n\t\tdisplay_name: 'Umans GLM 5.2',\n\t\tcapabilities: {\n\t\t\tmax_completion_tokens: 131072,\n\t\t\trecommended_max_tokens: 131071,\n\t\t\tcontext_window: 405504,\n\t\t\tsupports_vision: 'via-handoff',\n\t\t\tsupports_tools: true,\n\t\t\treasoning: {\n\t\t\t\tsupported: true,\n\t\t\t\tcan_disable: true,\n\t\t\t\tlevels: [\n\t\t\t\t\t'none',\n\t\t\t\t\t'minimal',\n\t\t\t\t\t'low',\n\t\t\t\t\t'medium',\n\t\t\t\t\t'high',\n\t\t\t\t\t'xhigh',\n\t\t\t\t\t'max',\n\t\t\t\t],\n\t\t\t\tdefault_level: 'medium',\n\t\t\t},\n\t\t},\n\t},\n\t'umans-coder': {\n\t\tname: 'umans-coder',\n\t\tdisplay_name: 'Umans Coder',\n\t\tcapabilities: {\n\t\t\tmax_completion_tokens: 262144,\n\t\t\trecommended_max_tokens: 32768,\n\t\t\tcontext_window: 262144,\n\t\t\tsupports_vision: true,\n\t\t\tsupports_tools: true,\n\t\t\treasoning: {\n\t\t\t\tsupported: true,\n\t\t\t\tcan_disable: false,\n\t\t\t\tlevels: ['minimal', 'low', 'medium', 'high', 'xhigh', 'max'],\n\t\t\t\tdefault_level: 'medium',\n\t\t\t},\n\t\t},\n\t},\n\t'umans-flash': {\n\t\tname: 'umans-flash',\n\t\tdisplay_name: 'Umans Flash',\n\t\tcapabilities: {\n\t\t\tmax_completion_tokens: 262144,\n\t\t\trecommended_max_tokens: 32768,\n\t\t\tcontext_window: 262144,\n\t\t\tsupports_vision: true,\n\t\t\tsupports_tools: true,\n\t\t\treasoning: {\n\t\t\t\tsupported: true,\n\t\t\t\tcan_disable: true,\n\t\t\t\tlevels: [\n\t\t\t\t\t'none',\n\t\t\t\t\t'minimal',\n\t\t\t\t\t'low',\n\t\t\t\t\t'medium',\n\t\t\t\t\t'high',\n\t\t\t\t\t'xhigh',\n\t\t\t\t\t'max',\n\t\t\t\t],\n\t\t\t\tdefault_level: 'medium',\n\t\t\t},\n\t\t},\n\t},\n\t'umans-qwen3.6-35b-a3b': {\n\t\tname: 'umans-qwen3.6-35b-a3b',\n\t\tdisplay_name: 'Umans Qwen3.6 35B A3B',\n\t\tcapabilities: {\n\t\t\tmax_completion_tokens: 262144,\n\t\t\trecommended_max_tokens: 32768,\n\t\t\tcontext_window: 262144,\n\t\t\tsupports_vision: true,\n\t\t\tsupports_tools: true,\n\t\t\treasoning: {\n\t\t\t\tsupported: true,\n\t\t\t\tcan_disable: true,\n\t\t\t\tlevels: [\n\t\t\t\t\t'none',\n\t\t\t\t\t'minimal',\n\t\t\t\t\t'low',\n\t\t\t\t\t'medium',\n\t\t\t\t\t'high',\n\t\t\t\t\t'xhigh',\n\t\t\t\t\t'max',\n\t\t\t\t],\n\t\t\t\tdefault_level: 'medium',\n\t\t\t},\n\t\t},\n\t},\n};\n\nfunction safe_max_tokens(recommended?: number, cap?: number): number {\n\tlet value =\n\t\ttypeof recommended === 'number' && recommended > 0\n\t\t\t? recommended\n\t\t\t: 32768;\n\tif (typeof cap === 'number' && cap > 0)\n\t\tvalue = Math.min(value, cap - 1);\n\treturn Math.max(value, 1);\n}\n\nfunction is_record(value: unknown): value is Record<string, unknown> {\n\treturn (\n\t\t!!value && typeof value === 'object' && !Array.isArray(value)\n\t);\n}\n\nexport function normalize_umans_catalog(\n\tvalue: unknown,\n): Record<string, UmansModelInfo> {\n\tconst source =\n\t\tis_record(value) && is_record(value.data) ? value.data : value;\n\tif (!is_record(source)) return {};\n\n\tconst catalog: Record<string, UmansModelInfo> = {};\n\tfor (const [id, info] of Object.entries(source)) {\n\t\tif (!is_record(info)) continue;\n\t\tconst capabilities = is_record(info.capabilities)\n\t\t\t? info.capabilities\n\t\t\t: {};\n\t\tcatalog[id] = {\n\t\t\tname: typeof info.name === 'string' ? info.name : id,\n\t\t\tdisplay_name:\n\t\t\t\ttypeof info.display_name === 'string'\n\t\t\t\t\t? info.display_name\n\t\t\t\t\t: id,\n\t\t\tdeprecation: info.deprecation,\n\t\t\tcapabilities: capabilities as ModelCapabilities,\n\t\t};\n\t}\n\treturn catalog;\n}\n\nexport async function fetch_umans_catalog(\n\tbase_url: string,\n\tapi_key?: string,\n\tsignal?: AbortSignal,\n): Promise<Record<string, UmansModelInfo>> {\n\tconst headers: Record<string, string> = {\n\t\t'user-agent': USER_AGENT,\n\t};\n\tif (api_key) headers.authorization = `Bearer ${api_key}`;\n\n\tconst response = await fetch(\n\t\t`${base_url.replace(/\\/$/, '')}/v1/models/info`,\n\t\t{ headers, signal },\n\t);\n\tif (!response.ok) throw new Error(`HTTP ${response.status}`);\n\treturn normalize_umans_catalog(await response.json());\n}\n\nexport function to_pi_models(\n\tcatalog: Record<string, UmansModelInfo>,\n\tbase_url = DEFAULT_BASE_URL,\n) {\n\treturn Object.entries(catalog)\n\t\t.filter(([, info]) => !info.deprecation)\n\t\t.map(([id, info]) => {\n\t\t\tconst capabilities = info.capabilities ?? {};\n\t\t\tconst input: ('text' | 'image')[] = capabilities.supports_vision\n\t\t\t\t? ['text', 'image']\n\t\t\t\t: ['text'];\n\t\t\treturn {\n\t\t\t\tid,\n\t\t\t\tname: info.display_name ?? id,\n\t\t\t\tapi: 'anthropic-messages' as const,\n\t\t\t\tprovider: 'umans',\n\t\t\t\tbaseUrl: base_url,\n\t\t\t\tmaxTokens: safe_max_tokens(\n\t\t\t\t\tcapabilities.recommended_max_tokens,\n\t\t\t\t\tcapabilities.max_completion_tokens,\n\t\t\t\t),\n\t\t\t\tcontextWindow: capabilities.context_window ?? 262144,\n\t\t\t\treasoning: capabilities.reasoning?.supported === true,\n\t\t\t\tinput,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\t\t\tsupportsTools: capabilities.supports_tools !== false,\n\t\t\t};\n\t\t});\n}\n\nasync function prompt_for_api_key(\n\tinteraction: AuthInteraction,\n): Promise<string> {\n\tconst api_key = await interaction.prompt({\n\t\ttype: 'secret',\n\t\tmessage: 'Enter your Umans API key:',\n\t});\n\tconst key = api_key.trim();\n\tif (!key) throw new Error('Umans API key is required');\n\treturn key;\n}\n\nfunction bearer_auth(key: string) {\n\treturn {\n\t\tauth: { headers: { authorization: `Bearer ${key}` } },\n\t};\n}\n\nexport function create_umans_api_key_auth(\n\tenv: NodeJS.ProcessEnv = process.env,\n): ApiKeyAuth {\n\treturn {\n\t\tname: 'Umans API key',\n\t\tasync login(interaction) {\n\t\t\treturn {\n\t\t\t\ttype: 'api_key',\n\t\t\t\tkey: await prompt_for_api_key(interaction),\n\t\t\t};\n\t\t},\n\t\tasync check({ credential }) {\n\t\t\tif (credential?.key)\n\t\t\t\treturn { type: 'api_key', source: 'stored API key' };\n\t\t\tif (env[API_KEY_ENV]?.trim())\n\t\t\t\treturn { type: 'api_key', source: API_KEY_ENV };\n\t\t\treturn undefined;\n\t\t},\n\t\tasync resolve({ credential }) {\n\t\t\tconst stored_key = credential?.key?.trim();\n\t\t\tif (stored_key)\n\t\t\t\treturn {\n\t\t\t\t\t...bearer_auth(stored_key),\n\t\t\t\t\tsource: 'stored API key',\n\t\t\t\t};\n\t\t\tconst env_key = env[API_KEY_ENV]?.trim();\n\t\t\treturn env_key\n\t\t\t\t? { ...bearer_auth(env_key), source: API_KEY_ENV }\n\t\t\t\t: undefined;\n\t\t},\n\t};\n}\n\nfunction create_legacy_umans_oauth(): OAuthAuth {\n\treturn {\n\t\tname: 'Legacy Umans credential',\n\t\tloginLabel: 'Enter Umans API key (legacy credential)',\n\t\tasync login(interaction): Promise<OAuthCredential> {\n\t\t\tconst key = await prompt_for_api_key(interaction);\n\t\t\treturn {\n\t\t\t\ttype: 'oauth',\n\t\t\t\trefresh: key,\n\t\t\t\taccess: key,\n\t\t\t\texpires: Date.now() + 100 * 365 * 24 * 60 * 60 * 1000,\n\t\t\t};\n\t\t},\n\t\trefresh: (credential) => Promise.resolve(credential),\n\t\ttoAuth: async (credential) => bearer_auth(credential.access).auth,\n\t};\n}\n\nfunction credential_key(\n\tcredential: Credential | undefined,\n\tenv: NodeJS.ProcessEnv,\n): string | undefined {\n\tif (credential?.type === 'api_key') return credential.key?.trim();\n\tif (credential?.type === 'oauth') return credential.access.trim();\n\treturn env[API_KEY_ENV]?.trim() || undefined;\n}\n\nexport interface CreateUmansProviderOptions {\n\tbase_url?: string;\n\tenv?: NodeJS.ProcessEnv;\n\tfetch_catalog?: typeof fetch_umans_catalog;\n}\n\nexport function create_umans_provider(\n\toptions: CreateUmansProviderOptions = {},\n): Provider<'anthropic-messages'> {\n\tconst env = options.env ?? process.env;\n\tconst base_url =\n\t\toptions.base_url?.trim() ||\n\t\tenv.UMANS_BASE_URL?.trim() ||\n\t\tDEFAULT_BASE_URL;\n\tconst fetch_catalog = options.fetch_catalog ?? fetch_umans_catalog;\n\treturn createProvider({\n\t\tid: 'umans',\n\t\tname: 'Umans',\n\t\tbaseUrl: base_url,\n\t\tauth: {\n\t\t\tapiKey: create_umans_api_key_auth(env),\n\t\t\toauth: create_legacy_umans_oauth(),\n\t\t},\n\t\tmodels: to_pi_models(STATIC_UMANS_CATALOG, base_url),\n\t\tasync fetchModels(context) {\n\t\t\tconst catalog = await fetch_catalog(\n\t\t\t\tbase_url,\n\t\t\t\tcredential_key(context.credential, env),\n\t\t\t\tcontext.signal,\n\t\t\t);\n\t\t\treturn to_pi_models(catalog, base_url);\n\t\t},\n\t\tapi: anthropicMessagesApi(),\n\t});\n}\n\nconst extension: ExtensionFactory = (pi) => {\n\tif (process.env.UMANS_DISABLE === '1') return;\n\tpi.registerProvider(create_umans_provider());\n};\n\nexport default extension;\n"],"mappings":";;;AAYA,MAAM,mBAAmB;AACzB,MAAM,cAAc;AACpB,MAAM,aAAa;AAyBnB,MAAa,uBAAuD;CACnE,mBAAmB;EAClB,MAAM;EACN,cAAc;EACd,cAAc;GACb,uBAAuB;GACvB,wBAAwB;GACxB,gBAAgB;GAChB,iBAAiB;GACjB,gBAAgB;GAChB,WAAW;IACV,WAAW;IACX,aAAa;IACb,QAAQ;KACP;KACA;KACA;KACA;KACA;KACA;KACA;IACD;IACA,eAAe;GAChB;EACD;CACD;CACA,mBAAmB;EAClB,MAAM;EACN,cAAc;EACd,cAAc;GACb,uBAAuB;GACvB,wBAAwB;GACxB,gBAAgB;GAChB,iBAAiB;GACjB,gBAAgB;GAChB,WAAW;IACV,WAAW;IACX,aAAa;IACb,QAAQ;KAAC;KAAW;KAAO;KAAU;KAAQ;KAAS;IAAK;IAC3D,eAAe;GAChB;EACD;CACD;CACA,iBAAiB;EAChB,MAAM;EACN,cAAc;EACd,cAAc;GACb,uBAAuB;GACvB,wBAAwB;GACxB,gBAAgB;GAChB,iBAAiB;GACjB,gBAAgB;GAChB,WAAW;IACV,WAAW;IACX,aAAa;IACb,QAAQ;KACP;KACA;KACA;KACA;KACA;KACA;KACA;IACD;IACA,eAAe;GAChB;EACD;CACD;CACA,eAAe;EACd,MAAM;EACN,cAAc;EACd,cAAc;GACb,uBAAuB;GACvB,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