@henryqw/pi-task-models 0.4.1 → 0.6.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/dist/index.d.ts +6 -2
- package/dist/index.js +33 -7
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -48,8 +48,12 @@ export declare function resolveAvailableModel(models: readonly AvailableModel[],
|
|
|
48
48
|
export declare function supportedThinkingLevels(model: AvailableModel): ThinkingLevel[];
|
|
49
49
|
export declare function availableTaskModels(ctx: ExtensionContext): AvailableModel[];
|
|
50
50
|
export declare function taskThinkingLevels(ctx: ExtensionContext, model: AvailableModel): ThinkingLevel[];
|
|
51
|
-
export declare function
|
|
52
|
-
|
|
51
|
+
export declare function rememberedThinkingLevel(model: {
|
|
52
|
+
provider: string;
|
|
53
|
+
id: string;
|
|
54
|
+
} | string, agentDir?: string): ThinkingLevel | undefined;
|
|
55
|
+
export declare function resolveTaskModelRoute(ctx: ExtensionContext, route: TaskModelRoute, agentDir?: string, thinking?: ThinkingLevel): ResolvedTaskRoute | undefined;
|
|
56
|
+
export declare function resolveConfiguredTaskRoute(ctx: ExtensionContext, task: string, agentDir?: string, thinking?: ThinkingLevel): ResolvedTaskRoute;
|
|
53
57
|
export declare function orderedProfileRoutes(profile: TaskModelProfile): TaskModelRoute[];
|
|
54
58
|
export declare function activeTaskPackages(pi: Pick<ExtensionAPI, "getCommands" | "getAllTools">, tasks?: Readonly<Record<string, ProfileName>>): ActiveTaskPackage[];
|
|
55
59
|
export declare function createTaskModelsExtension(pi: ExtensionAPI, options?: {
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,8 @@ export const DEFAULT_TASK_ASSIGNMENTS = {
|
|
|
14
14
|
};
|
|
15
15
|
const CODEX_ALIAS = /^openai-codex-(?:[2-9]|[1-9]\d+)$/;
|
|
16
16
|
const CONFIG_FILE = "pi-task-models.json";
|
|
17
|
+
// Owned by @henryqw/pi-model-thinking; keys use the same canonical provider/model form.
|
|
18
|
+
const MODEL_THINKING_CONFIG_FILE = "pi-model-thinking.json";
|
|
17
19
|
const defaultTaskAssignments = () => ({ ...DEFAULT_TASK_ASSIGNMENTS });
|
|
18
20
|
export const configPath = (agentDir = getAgentDir()) => join(agentDir, "config", CONFIG_FILE);
|
|
19
21
|
function isCodexProvider(provider) {
|
|
@@ -191,13 +193,37 @@ export function taskThinkingLevels(ctx, model) {
|
|
|
191
193
|
return supported;
|
|
192
194
|
return supported.includes(pinned) ? [pinned] : [];
|
|
193
195
|
}
|
|
194
|
-
|
|
196
|
+
// pi-model-thinking's config is untrusted user data; keep only recognized levels for this model.
|
|
197
|
+
export function rememberedThinkingLevel(model, agentDir = getAgentDir()) {
|
|
198
|
+
try {
|
|
199
|
+
const value = JSON.parse(readFileSync(join(agentDir, "config", MODEL_THINKING_CONFIG_FILE), "utf8"));
|
|
200
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
201
|
+
return undefined;
|
|
202
|
+
const level = value[canonicalModelReference(model)];
|
|
203
|
+
return isThinkingLevel(level) ? level : undefined;
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
export function resolveTaskModelRoute(ctx, route, agentDir = getAgentDir(), thinking) {
|
|
195
210
|
const model = resolveAvailableModel(availableTaskModels(ctx), route.model, ctx.model?.provider);
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
211
|
+
if (!model)
|
|
212
|
+
return undefined;
|
|
213
|
+
const levels = taskThinkingLevels(ctx, model);
|
|
214
|
+
// An explicit requested level wins over remembered and profile levels; a model
|
|
215
|
+
// that cannot honor it is skipped so later fallback routes get considered.
|
|
216
|
+
if (thinking !== undefined) {
|
|
217
|
+
return levels.includes(thinking) ? { model, thinkingLevel: thinking } : undefined;
|
|
218
|
+
}
|
|
219
|
+
// Remembered per-model thinking (pi-model-thinking) wins over the profile level when supported.
|
|
220
|
+
const remembered = rememberedThinkingLevel(model, agentDir);
|
|
221
|
+
const thinkingLevel = remembered && levels.includes(remembered) ? remembered : route.thinkingLevel;
|
|
222
|
+
if (!levels.includes(thinkingLevel))
|
|
223
|
+
return undefined;
|
|
224
|
+
return { model, thinkingLevel };
|
|
199
225
|
}
|
|
200
|
-
export function resolveConfiguredTaskRoute(ctx, task, agentDir = getAgentDir()) {
|
|
226
|
+
export function resolveConfiguredTaskRoute(ctx, task, agentDir = getAgentDir(), thinking) {
|
|
201
227
|
let config;
|
|
202
228
|
try {
|
|
203
229
|
config = readTaskModelsConfig(agentDir);
|
|
@@ -212,11 +238,11 @@ export function resolveConfiguredTaskRoute(ctx, task, agentDir = getAgentDir())
|
|
|
212
238
|
if (!profile)
|
|
213
239
|
throw new Error(`Task ${task} profile ${profileName} is not configured. Run /task-models.`);
|
|
214
240
|
for (const route of orderedProfileRoutes(profile)) {
|
|
215
|
-
const resolved = resolveTaskModelRoute(ctx, route);
|
|
241
|
+
const resolved = resolveTaskModelRoute(ctx, route, agentDir, thinking);
|
|
216
242
|
if (resolved)
|
|
217
243
|
return resolved;
|
|
218
244
|
}
|
|
219
|
-
throw new Error(`Task ${task} profile ${profileName} has no available route. Run /task-models.`);
|
|
245
|
+
throw new Error(`Task ${task} profile ${profileName} has no available route${thinking ? ` supporting thinking ${thinking}` : ""}. Run /task-models.`);
|
|
220
246
|
}
|
|
221
247
|
export function orderedProfileRoutes(profile) {
|
|
222
248
|
return profile.fallback ? [profile.primary, profile.fallback] : [profile.primary];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@henryqw/pi-task-models",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Shared task model profiles and routing for HenryQW Pi extensions.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "tsc --project tsconfig.build.json",
|
|
32
32
|
"test": "npm run build && node --test test/*.test.ts",
|
|
33
|
-
"typecheck": "tsc --noEmit --allowImportingTsExtensions --target ES2022 --module NodeNext --moduleResolution NodeNext --types node --skipLibCheck src/*.ts extensions/*.ts",
|
|
33
|
+
"typecheck": "tsc --noEmit --allowImportingTsExtensions --target ES2022 --module NodeNext --moduleResolution NodeNext --types node --skipLibCheck src/*.ts extensions/*.ts test/*.ts",
|
|
34
34
|
"prepack": "npm run build",
|
|
35
35
|
"pack:check": "npm pack --dry-run"
|
|
36
36
|
},
|