@henryqw/pi-task-models 0.5.1 → 0.7.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 +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.js +23 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -67,7 +67,7 @@ Each configured profile needs one primary model and thinking level. Fallback is
|
|
|
67
67
|
|
|
68
68
|
Reads are strict. Malformed or unknown values fail visibly and never rewrite the file. Only explicit `/task-models` actions write config.
|
|
69
69
|
|
|
70
|
-
Consumers can call `resolveConfiguredTaskRoute(ctx, taskId)`
|
|
70
|
+
Consumers can call `resolveConfiguredTaskRoute(ctx, taskId)` for the first usable route or `resolveConfiguredTaskRoutes(ctx, taskId)` for primary and fallback routes. Both read strict shared config and fail with `/task-models` guidance when assignment, profile, or route is unavailable.
|
|
71
71
|
|
|
72
72
|
## Remove
|
|
73
73
|
|
package/dist/index.d.ts
CHANGED
|
@@ -52,8 +52,14 @@ export declare function rememberedThinkingLevel(model: {
|
|
|
52
52
|
provider: string;
|
|
53
53
|
id: string;
|
|
54
54
|
} | string, agentDir?: string): ThinkingLevel | undefined;
|
|
55
|
-
export declare function resolveTaskModelRoute(ctx: ExtensionContext, route: TaskModelRoute, agentDir?: string): ResolvedTaskRoute | undefined;
|
|
56
|
-
export declare function
|
|
55
|
+
export declare function resolveTaskModelRoute(ctx: ExtensionContext, route: TaskModelRoute, agentDir?: string, thinking?: ThinkingLevel): ResolvedTaskRoute | undefined;
|
|
56
|
+
export declare function resolveConfiguredTaskRoutes(ctx: ExtensionContext, task: string, agentDir?: string, thinking?: ThinkingLevel): ResolvedTaskRoute[];
|
|
57
|
+
export type TaskRouteErrorCode = "config-read" | "task-unassigned" | "profile-missing" | "no-route";
|
|
58
|
+
export type TaskRouteError = Error & {
|
|
59
|
+
taskRouteCode: TaskRouteErrorCode;
|
|
60
|
+
profileName?: ProfileName;
|
|
61
|
+
};
|
|
62
|
+
export declare function resolveConfiguredTaskRoute(ctx: ExtensionContext, task: string, agentDir?: string, thinking?: ThinkingLevel): ResolvedTaskRoute;
|
|
57
63
|
export declare function orderedProfileRoutes(profile: TaskModelProfile): TaskModelRoute[];
|
|
58
64
|
export declare function activeTaskPackages(pi: Pick<ExtensionAPI, "getCommands" | "getAllTools">, tasks?: Readonly<Record<string, ProfileName>>): ActiveTaskPackage[];
|
|
59
65
|
export declare function createTaskModelsExtension(pi: ExtensionAPI, options?: {
|
package/dist/index.js
CHANGED
|
@@ -206,11 +206,16 @@ export function rememberedThinkingLevel(model, agentDir = getAgentDir()) {
|
|
|
206
206
|
return undefined;
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
|
-
export function resolveTaskModelRoute(ctx, route, agentDir = getAgentDir()) {
|
|
209
|
+
export function resolveTaskModelRoute(ctx, route, agentDir = getAgentDir(), thinking) {
|
|
210
210
|
const model = resolveAvailableModel(availableTaskModels(ctx), route.model, ctx.model?.provider);
|
|
211
211
|
if (!model)
|
|
212
212
|
return undefined;
|
|
213
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
|
+
}
|
|
214
219
|
// Remembered per-model thinking (pi-model-thinking) wins over the profile level when supported.
|
|
215
220
|
const remembered = rememberedThinkingLevel(model, agentDir);
|
|
216
221
|
const thinkingLevel = remembered && levels.includes(remembered) ? remembered : route.thinkingLevel;
|
|
@@ -218,26 +223,36 @@ export function resolveTaskModelRoute(ctx, route, agentDir = getAgentDir()) {
|
|
|
218
223
|
return undefined;
|
|
219
224
|
return { model, thinkingLevel };
|
|
220
225
|
}
|
|
221
|
-
export function
|
|
226
|
+
export function resolveConfiguredTaskRoutes(ctx, task, agentDir = getAgentDir(), thinking) {
|
|
222
227
|
let config;
|
|
223
228
|
try {
|
|
224
229
|
config = readTaskModelsConfig(agentDir);
|
|
225
230
|
}
|
|
226
231
|
catch {
|
|
227
|
-
throw
|
|
232
|
+
throw taskRouteError("config-read", "Couldn't read task model config. Run /task-models.");
|
|
228
233
|
}
|
|
229
234
|
const profileName = config.tasks[task];
|
|
230
235
|
if (!profileName)
|
|
231
|
-
throw
|
|
236
|
+
throw taskRouteError("task-unassigned", `Task ${task} is not assigned to a profile. Run /task-models.`);
|
|
232
237
|
const profile = config.profiles[profileName];
|
|
233
238
|
if (!profile)
|
|
234
|
-
throw
|
|
239
|
+
throw taskRouteError("profile-missing", `Task ${task} profile ${profileName} is not configured. Run /task-models.`, profileName);
|
|
240
|
+
const routes = [];
|
|
235
241
|
for (const route of orderedProfileRoutes(profile)) {
|
|
236
|
-
const resolved = resolveTaskModelRoute(ctx, route, agentDir);
|
|
242
|
+
const resolved = resolveTaskModelRoute(ctx, route, agentDir, thinking);
|
|
237
243
|
if (resolved)
|
|
238
|
-
|
|
244
|
+
routes.push(resolved);
|
|
245
|
+
}
|
|
246
|
+
if (!routes.length) {
|
|
247
|
+
throw taskRouteError("no-route", `Task ${task} profile ${profileName} has no available route${thinking ? ` supporting thinking ${thinking}` : ""}. Run /task-models.`, profileName);
|
|
239
248
|
}
|
|
240
|
-
|
|
249
|
+
return routes;
|
|
250
|
+
}
|
|
251
|
+
function taskRouteError(taskRouteCode, message, profileName) {
|
|
252
|
+
return Object.assign(new Error(message), { taskRouteCode, ...(profileName ? { profileName } : {}) });
|
|
253
|
+
}
|
|
254
|
+
export function resolveConfiguredTaskRoute(ctx, task, agentDir = getAgentDir(), thinking) {
|
|
255
|
+
return resolveConfiguredTaskRoutes(ctx, task, agentDir, thinking)[0];
|
|
241
256
|
}
|
|
242
257
|
export function orderedProfileRoutes(profile) {
|
|
243
258
|
return profile.fallback ? [profile.primary, profile.fallback] : [profile.primary];
|