@leitwerk-dev/server 0.5.2 → 0.5.4
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/{app-DZUsf76a.d.ts → app-B8gyS_Id.d.ts} +82 -76
- package/dist/app-XAQTAQ5Y.js +8 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/{chunk-AJ2DQWI3.js → chunk-6STQ3LAP.js} +133 -83
- package/dist/chunk-6STQ3LAP.js.map +1 -0
- package/dist/{chunk-6EEU4QOU.js → chunk-ZA5TDEM5.js} +302 -144
- package/dist/chunk-ZA5TDEM5.js.map +1 -0
- package/dist/config/config-loader.d.ts.map +1 -1
- package/dist/dashboard-model-issues.d.ts.map +1 -1
- package/dist/future-execution/execution.d.ts.map +1 -1
- package/dist/future-execution/launch-lifecycle.d.ts.map +1 -1
- package/dist/future-execution/lifecycle.d.ts.map +1 -1
- package/dist/future-execution/reconciliation.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/main.js +3 -3
- package/dist/process-engine/ops/execute-action.d.ts.map +1 -1
- package/dist/process-engine/ops/retry-startup.d.ts.map +1 -1
- package/dist/process-engine/turn-start-preflight.d.ts.map +1 -1
- package/dist/process-model-config.d.ts.map +1 -1
- package/dist/process-model-policy/construct.d.ts +1 -0
- package/dist/process-model-policy/construct.d.ts.map +1 -1
- package/dist/process-model-policy/evaluate.d.ts +3 -3
- package/dist/process-model-policy/evaluate.d.ts.map +1 -1
- package/dist/process-model-policy/index.d.ts +1 -0
- package/dist/process-model-policy/index.d.ts.map +1 -1
- package/dist/process-model-policy/launch.d.ts.map +1 -1
- package/dist/process-model-policy/project.d.ts.map +1 -1
- package/dist/process-model-policy/requirements.d.ts +16 -0
- package/dist/process-model-policy/requirements.d.ts.map +1 -0
- package/dist/process-model-policy/types.d.ts +87 -75
- package/dist/process-model-policy/types.d.ts.map +1 -1
- package/dist/process-model-policy-presenter.d.ts.map +1 -1
- package/dist/process-model-selection.d.ts.map +1 -1
- package/dist/process-title-generator.d.ts +2 -0
- package/dist/process-title-generator.d.ts.map +1 -1
- package/dist/routes/process-actions.d.ts.map +1 -1
- package/dist/supervisor/worker-start-payload-builder.d.ts.map +1 -1
- package/dist/test-helpers/process-model-fixtures.d.ts +6 -0
- package/dist/test-helpers/process-model-fixtures.d.ts.map +1 -1
- package/dist/testing.js +1 -1
- package/package.json +12 -12
- package/src/app.ts +21 -0
- package/src/config/config-loader.ts +5 -0
- package/src/dashboard-model-issues.ts +66 -5
- package/src/future-execution/execution.ts +3 -8
- package/src/future-execution/launch-lifecycle.ts +15 -10
- package/src/future-execution/lifecycle.ts +1 -0
- package/src/future-execution/reconciliation.ts +2 -34
- package/src/launch-coordinator.ts +2 -2
- package/src/process-engine/ops/execute-action.ts +1 -0
- package/src/process-engine/ops/retry-startup.ts +10 -12
- package/src/process-engine/turn-start-preflight.ts +38 -15
- package/src/process-model-config.ts +7 -3
- package/src/process-model-policy/construct.ts +61 -3
- package/src/process-model-policy/evaluate.ts +73 -64
- package/src/process-model-policy/index.ts +16 -14
- package/src/process-model-policy/launch.ts +27 -29
- package/src/process-model-policy/project.ts +72 -43
- package/src/process-model-policy/requirements.ts +73 -0
- package/src/process-model-policy/types.ts +108 -78
- package/src/process-model-policy-presenter.ts +18 -2
- package/src/process-model-selection.ts +2 -0
- package/src/process-title-generator.ts +12 -16
- package/src/routes/launchers.ts +1 -1
- package/src/routes/process-actions.ts +1 -0
- package/src/supervisor/worker-start-payload-builder.ts +6 -1
- package/src/test-helpers/process-model-fixtures.ts +25 -4
- package/dist/app-2TCRADVA.js +0 -8
- package/dist/chunk-6EEU4QOU.js.map +0 -1
- package/dist/chunk-AJ2DQWI3.js.map +0 -1
- /package/dist/{app-2TCRADVA.js.map → app-XAQTAQ5Y.js.map} +0 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { copiedUnknownRecordSchema as unknownRecordSchema } from "@leitwerk-dev/domain";
|
|
5
|
+
import { modelPolicyIdentifiersSchema, modelRequirementsSchema } from "@leitwerk-dev/protocol";
|
|
5
6
|
import { DEFAULT_SESSION_TRANSFER_LIMITS } from "@leitwerk-dev/session-transfer";
|
|
6
7
|
import { parseDurationMs as parseDurationMs2 } from "@leitwerk-dev/watcher-utils";
|
|
7
8
|
import {
|
|
@@ -372,7 +373,8 @@ var skillIdsSchema = v.array(
|
|
|
372
373
|
v.pipe(v.string(), v.regex(SAFE_SKILL_ID_PATTERN, "Invalid skill ID"))
|
|
373
374
|
);
|
|
374
375
|
var modelTurnConfigSchema = v.looseObject({
|
|
375
|
-
model_profile: v.optional(v.string())
|
|
376
|
+
model_profile: v.optional(v.string()),
|
|
377
|
+
model_requirements: v.optional(modelRequirementsSchema)
|
|
376
378
|
});
|
|
377
379
|
var authNonEmptyString = v.pipe(v.string(), v.nonEmpty());
|
|
378
380
|
var authOidcProviderSchema = v.looseObject({
|
|
@@ -530,6 +532,8 @@ var configSchema = v.looseObject({
|
|
|
530
532
|
provider: v.string(),
|
|
531
533
|
model_id: v.string(),
|
|
532
534
|
thinking_level: v.optional(v.string()),
|
|
535
|
+
labels: v.optional(modelPolicyIdentifiersSchema),
|
|
536
|
+
default: v.optional(v.boolean()),
|
|
533
537
|
provider_options: v.optional(v.record(v.string(), v.string()))
|
|
534
538
|
})
|
|
535
539
|
),
|
|
@@ -559,6 +563,7 @@ var configSchema = v.looseObject({
|
|
|
559
563
|
v.looseObject({
|
|
560
564
|
default_skills: v.optional(skillIdsSchema),
|
|
561
565
|
default_model_profile: v.optional(v.string()),
|
|
566
|
+
model_requirements: v.optional(modelRequirementsSchema),
|
|
562
567
|
allowed_model_profiles: v.optional(v.pipe(stringArraySchema, v.nonEmpty())),
|
|
563
568
|
worker_runtime_profile: v.optional(v.string()),
|
|
564
569
|
storage_size: v.optional(storageSizeSchema),
|
|
@@ -7047,6 +7052,7 @@ function recordTurnProgress(deps, input) {
|
|
|
7047
7052
|
// src/process-model-policy/construct.ts
|
|
7048
7053
|
import { trimToNull } from "@leitwerk-dev/domain";
|
|
7049
7054
|
import { isLlmTurnDefinition } from "@leitwerk-dev/process-sdk";
|
|
7055
|
+
import { assertValidModelRequirements, compareModelProfileIds } from "@leitwerk-dev/protocol";
|
|
7050
7056
|
|
|
7051
7057
|
// src/process-graph.ts
|
|
7052
7058
|
import {
|
|
@@ -7085,7 +7091,10 @@ function constructPolicySnapshot(input) {
|
|
|
7085
7091
|
provider: profile.provider,
|
|
7086
7092
|
modelId: profile.model_id,
|
|
7087
7093
|
thinkingLevel: profile.thinking_level ?? "off",
|
|
7088
|
-
providerOptions: profile.provider_options ?? {}
|
|
7094
|
+
providerOptions: profile.provider_options ?? {},
|
|
7095
|
+
labels: [...new Set(profile.labels ?? [])].sort(compareModelProfileIds),
|
|
7096
|
+
default: profile.default ?? false,
|
|
7097
|
+
capabilities: structuredClone(input.capabilities?.(profile.provider, profile.model_id) ?? {})
|
|
7089
7098
|
}));
|
|
7090
7099
|
const processIds = /* @__PURE__ */ new Set([
|
|
7091
7100
|
...input.processGraphs.keys(),
|
|
@@ -7095,12 +7104,46 @@ function constructPolicySnapshot(input) {
|
|
|
7095
7104
|
for (const processId of processIds) {
|
|
7096
7105
|
const graph = input.processGraphs.has(processId) ? getProcessGraph2(input.processGraphs, processId) : null;
|
|
7097
7106
|
const config = configSnapshot.process_configs?.[processId];
|
|
7107
|
+
const requirements = [];
|
|
7108
|
+
const turnRequirements = {};
|
|
7109
|
+
const add = (layers, origin, value) => {
|
|
7110
|
+
if (value === void 0) return;
|
|
7111
|
+
assertValidModelRequirements(value);
|
|
7112
|
+
layers.push({ origin, requirements: structuredClone(value) });
|
|
7113
|
+
};
|
|
7114
|
+
add(
|
|
7115
|
+
requirements,
|
|
7116
|
+
`process:${processId}`,
|
|
7117
|
+
input.processGraphs.get(processId)?.modelRequirements
|
|
7118
|
+
);
|
|
7119
|
+
add(
|
|
7120
|
+
requirements,
|
|
7121
|
+
`process_configs.${processId}.model_requirements`,
|
|
7122
|
+
config?.model_requirements
|
|
7123
|
+
);
|
|
7098
7124
|
const llmTurnIds = /* @__PURE__ */ new Set();
|
|
7099
7125
|
const purposeProfileIdsByTurn = {};
|
|
7100
7126
|
const descriptions = {};
|
|
7101
7127
|
const pathTypes = {};
|
|
7102
7128
|
for (const [turnId, turn] of graph?.turns ?? []) {
|
|
7103
|
-
|
|
7129
|
+
const declared = input.processGraphs.get(processId)?.turns.get(turnId)?.definition;
|
|
7130
|
+
if (turn.turnType !== "llm") {
|
|
7131
|
+
if (declared && "modelRequirements" in declared)
|
|
7132
|
+
throw new Error(`Model requirements require an LLM turn: ${processId}/${turnId}`);
|
|
7133
|
+
continue;
|
|
7134
|
+
}
|
|
7135
|
+
const layers = [];
|
|
7136
|
+
add(
|
|
7137
|
+
layers,
|
|
7138
|
+
`turn:${processId}/${turnId}`,
|
|
7139
|
+
declared?.kind === "llm" ? declared.modelRequirements : void 0
|
|
7140
|
+
);
|
|
7141
|
+
add(
|
|
7142
|
+
layers,
|
|
7143
|
+
`process_configs.${processId}.turn_configs.${turnId}.model_requirements`,
|
|
7144
|
+
config?.turn_configs?.[turnId]?.model_requirements
|
|
7145
|
+
);
|
|
7146
|
+
turnRequirements[turnId] = layers;
|
|
7104
7147
|
llmTurnIds.add(turnId);
|
|
7105
7148
|
const definition = input.processActionRegistry.getTurnDefinition(processId, turnId);
|
|
7106
7149
|
pathTypes[turnId] = definition && isLlmTurnDefinition(definition) ? definition.branchType : "primary";
|
|
@@ -7115,6 +7158,8 @@ function constructPolicySnapshot(input) {
|
|
|
7115
7158
|
const allowed = config?.allowed_model_profiles ? new Set(config.allowed_model_profiles.map((id) => id.trim()).filter(Boolean)) : null;
|
|
7116
7159
|
processesById.set(processId, {
|
|
7117
7160
|
id: processId,
|
|
7161
|
+
requirements,
|
|
7162
|
+
turnRequirements,
|
|
7118
7163
|
allowedProfileIds: allowed,
|
|
7119
7164
|
defaultProfileId: trimToNull(config?.default_model_profile),
|
|
7120
7165
|
turnProfileIds: Object.fromEntries(
|
|
@@ -7146,7 +7191,10 @@ function constructPolicySnapshot(input) {
|
|
|
7146
7191
|
profilesById: new Map(profiles.map((profile) => [profile.id, profile])),
|
|
7147
7192
|
processesById,
|
|
7148
7193
|
workerStaticConfig: {
|
|
7149
|
-
pi:
|
|
7194
|
+
pi: {
|
|
7195
|
+
...configSnapshot.pi,
|
|
7196
|
+
model_profiles: configSnapshot.pi.model_profiles.map(({ labels: _labels, default: _default, ...profile }) => profile).sort((a, b) => compareModelProfileIds(a.id, b.id))
|
|
7197
|
+
},
|
|
7150
7198
|
workers: configSnapshot.workers,
|
|
7151
7199
|
processPi: Object.fromEntries(
|
|
7152
7200
|
Object.entries(configSnapshot.process_configs ?? {}).map(([id, value]) => [
|
|
@@ -7161,6 +7209,61 @@ function constructPolicySnapshot(input) {
|
|
|
7161
7209
|
// src/process-model-policy/evaluate.ts
|
|
7162
7210
|
import { trimToNull as trimToNull2 } from "@leitwerk-dev/domain";
|
|
7163
7211
|
|
|
7212
|
+
// src/process-model-policy/requirements.ts
|
|
7213
|
+
import { compareModelProfileIds as compareModelProfileIds2, modelCostRank } from "@leitwerk-dev/protocol";
|
|
7214
|
+
function requirementLayers(policy, turnId) {
|
|
7215
|
+
return policy.requirements.concat(turnId ? policy.turnRequirements[turnId] ?? [] : []);
|
|
7216
|
+
}
|
|
7217
|
+
function profileRejections(policy, profile, turnId) {
|
|
7218
|
+
const rejections = [];
|
|
7219
|
+
if (policy.allowedProfileIds && !policy.allowedProfileIds.has(profile.id))
|
|
7220
|
+
rejections.push({
|
|
7221
|
+
origin: `process_configs.${policy.id}.allowed_model_profiles`,
|
|
7222
|
+
code: "profile_not_allowed",
|
|
7223
|
+
values: [profile.id]
|
|
7224
|
+
});
|
|
7225
|
+
const labels = new Set(profile.labels);
|
|
7226
|
+
for (const { origin, requirements: r } of requirementLayers(policy, turnId)) {
|
|
7227
|
+
if (r.profiles && !r.profiles.includes(profile.id))
|
|
7228
|
+
rejections.push({ origin, code: "profile_not_allowed", values: r.profiles });
|
|
7229
|
+
const missing = r.labels?.all_of?.filter((label) => !labels.has(label)) ?? [];
|
|
7230
|
+
if (missing.length) rejections.push({ origin, code: "missing_labels", values: missing });
|
|
7231
|
+
if (r.labels?.any_of && !r.labels.any_of.some((label) => labels.has(label)))
|
|
7232
|
+
rejections.push({ origin, code: "no_matching_labels", values: r.labels.any_of });
|
|
7233
|
+
const forbidden = r.labels?.none_of?.filter((label) => labels.has(label)) ?? [];
|
|
7234
|
+
if (forbidden.length) rejections.push({ origin, code: "forbidden_labels", values: forbidden });
|
|
7235
|
+
for (const capability of r.capabilities ?? []) {
|
|
7236
|
+
if (profile.capabilities[capability] !== true)
|
|
7237
|
+
rejections.push({
|
|
7238
|
+
origin,
|
|
7239
|
+
code: profile.capabilities[capability] === false ? "unsupported_capability" : "unknown_capability",
|
|
7240
|
+
values: [capability]
|
|
7241
|
+
});
|
|
7242
|
+
}
|
|
7243
|
+
}
|
|
7244
|
+
return rejections;
|
|
7245
|
+
}
|
|
7246
|
+
function rankedProfiles(policy, profiles, turnId) {
|
|
7247
|
+
const eligible = profiles.filter((profile) => !profileRejections(policy, profile, turnId).length);
|
|
7248
|
+
const marked = eligible.filter((profile) => profile.default);
|
|
7249
|
+
const relevant = new Set(
|
|
7250
|
+
requirementLayers(policy, turnId).flatMap(({ requirements: r }) => [
|
|
7251
|
+
...r.labels?.all_of ?? [],
|
|
7252
|
+
...r.labels?.any_of ?? []
|
|
7253
|
+
])
|
|
7254
|
+
);
|
|
7255
|
+
const unrelated = (profile) => new Set(profile.labels.filter((label) => !relevant.has(label))).size;
|
|
7256
|
+
const ranked = (marked.length ? marked : eligible).sort(
|
|
7257
|
+
(a, b) => (marked.length ? unrelated(a) - unrelated(b) : 0) || modelCostRank(a.labels) - modelCostRank(b.labels) || compareModelProfileIds2(a.id, b.id)
|
|
7258
|
+
);
|
|
7259
|
+
const minUnrelated = Math.min(...marked.map(unrelated));
|
|
7260
|
+
return {
|
|
7261
|
+
tiedProfileIds: marked.filter((profile) => unrelated(profile) === minUnrelated).map((profile) => profile.id),
|
|
7262
|
+
marked: marked.length > 0,
|
|
7263
|
+
profiles: ranked
|
|
7264
|
+
};
|
|
7265
|
+
}
|
|
7266
|
+
|
|
7164
7267
|
// src/process-model-policy/types.ts
|
|
7165
7268
|
function provenanceKindForSource(source) {
|
|
7166
7269
|
return source === "action_override" || source === "launch_override" || source === "instance_turn_config" || source === "instance_default" ? "explicit" : "inherited";
|
|
@@ -7173,6 +7276,8 @@ function isPinnedModelSelection(selection) {
|
|
|
7173
7276
|
function processPolicy(snapshot, processId) {
|
|
7174
7277
|
return snapshot.processesById.get(processId) ?? {
|
|
7175
7278
|
id: processId,
|
|
7279
|
+
requirements: [],
|
|
7280
|
+
turnRequirements: {},
|
|
7176
7281
|
allowedProfileIds: null,
|
|
7177
7282
|
defaultProfileId: null,
|
|
7178
7283
|
turnProfileIds: {},
|
|
@@ -7182,7 +7287,7 @@ function processPolicy(snapshot, processId) {
|
|
|
7182
7287
|
turnPathTypes: {}
|
|
7183
7288
|
};
|
|
7184
7289
|
}
|
|
7185
|
-
function validateSelection(snapshot, processId, selection, availability) {
|
|
7290
|
+
function validateSelection(snapshot, processId, selection, availability, turnId) {
|
|
7186
7291
|
if (!selection)
|
|
7187
7292
|
return {
|
|
7188
7293
|
ok: false,
|
|
@@ -7200,12 +7305,14 @@ function validateSelection(snapshot, processId, selection, availability) {
|
|
|
7200
7305
|
...availability ? { availabilityRevision: availability.revision } : {}
|
|
7201
7306
|
};
|
|
7202
7307
|
const policy = processPolicy(snapshot, processId);
|
|
7203
|
-
|
|
7308
|
+
const rejections = profileRejections(policy, profile, turnId);
|
|
7309
|
+
if (rejections.length)
|
|
7204
7310
|
return {
|
|
7205
7311
|
ok: false,
|
|
7206
7312
|
code: "model_profile_not_allowed",
|
|
7207
7313
|
modelProfileId: profile.id,
|
|
7208
7314
|
processId,
|
|
7315
|
+
rejections,
|
|
7209
7316
|
selection,
|
|
7210
7317
|
...availability ? { availabilityRevision: availability.revision } : {}
|
|
7211
7318
|
};
|
|
@@ -7248,21 +7355,6 @@ function resolveDefault(snapshot, configuration, availability) {
|
|
|
7248
7355
|
availability
|
|
7249
7356
|
);
|
|
7250
7357
|
}
|
|
7251
|
-
function resolveInherited(snapshot, configuration, turnId) {
|
|
7252
|
-
const policy = processPolicy(snapshot, configuration.processId);
|
|
7253
|
-
const instanceTurn = candidate(configuration.turnProfileIds.get(turnId), "instance_turn_config");
|
|
7254
|
-
if (instanceTurn) return instanceTurn;
|
|
7255
|
-
const instanceDefault = candidate(configuration.defaultProfileId, "instance_default");
|
|
7256
|
-
if (instanceDefault) return instanceDefault;
|
|
7257
|
-
const scopedDefault = candidate(
|
|
7258
|
-
policy.scopedProfileIdForTurn?.(turnId),
|
|
7259
|
-
"scoped_purpose_default"
|
|
7260
|
-
);
|
|
7261
|
-
if (scopedDefault) return scopedDefault;
|
|
7262
|
-
const processTurn = candidate(policy.turnProfileIds[turnId], "process_config_turn");
|
|
7263
|
-
if (processTurn) return processTurn;
|
|
7264
|
-
return resolvedDefault(snapshot, configuration);
|
|
7265
|
-
}
|
|
7266
7358
|
function invalidConfiguration(configuration) {
|
|
7267
7359
|
return {
|
|
7268
7360
|
ok: false,
|
|
@@ -7272,18 +7364,13 @@ function invalidConfiguration(configuration) {
|
|
|
7272
7364
|
issues: configuration.issues
|
|
7273
7365
|
};
|
|
7274
7366
|
}
|
|
7275
|
-
function resolveTurn(snapshot, configuration, turnId,
|
|
7367
|
+
function resolveTurn(snapshot, configuration, turnId, preservePinnedSelection, existingSelection, override2, availability) {
|
|
7276
7368
|
const policy = processPolicy(snapshot, configuration.processId);
|
|
7277
7369
|
if (!policy.llmTurnIds.has(turnId)) return { ok: true, selection: null };
|
|
7278
7370
|
if (configuration.kind === "invalid") return invalidConfiguration(configuration);
|
|
7371
|
+
const validate = (selection) => validateSelection(snapshot, configuration.processId, selection, availability, turnId);
|
|
7279
7372
|
const purposeProfileId = policy.purposeProfileIdsByTurn[turnId];
|
|
7280
|
-
if (purposeProfileId)
|
|
7281
|
-
return validateSelection(
|
|
7282
|
-
snapshot,
|
|
7283
|
-
configuration.processId,
|
|
7284
|
-
candidate(purposeProfileId, "process_config_default"),
|
|
7285
|
-
availability
|
|
7286
|
-
);
|
|
7373
|
+
if (purposeProfileId) return validate(candidate(purposeProfileId, "fixed_purpose"));
|
|
7287
7374
|
if (existingSelection.kind === "invalid" && existingSelection.turnId === turnId)
|
|
7288
7375
|
return {
|
|
7289
7376
|
ok: false,
|
|
@@ -7297,29 +7384,59 @@ function resolveTurn(snapshot, configuration, turnId, mode, existingSelection, o
|
|
|
7297
7384
|
existingSelection = { kind: "none" };
|
|
7298
7385
|
}
|
|
7299
7386
|
if (override2.kind === "profile")
|
|
7300
|
-
return
|
|
7301
|
-
|
|
7302
|
-
|
|
7303
|
-
|
|
7304
|
-
|
|
7305
|
-
|
|
7306
|
-
},
|
|
7307
|
-
availability
|
|
7308
|
-
);
|
|
7309
|
-
if (existingSelection.kind === "selected" && (mode === "initial" || mode === "retry" || mode === "continue") && existingSelection.turnId === turnId && isPinnedModelSelection(existingSelection.selection))
|
|
7310
|
-
return validateSelection(
|
|
7311
|
-
snapshot,
|
|
7312
|
-
configuration.processId,
|
|
7313
|
-
existingSelection.selection,
|
|
7314
|
-
availability
|
|
7315
|
-
);
|
|
7387
|
+
return validate({
|
|
7388
|
+
modelProfileId: override2.profileId,
|
|
7389
|
+
provenance: { kind: "explicit", source: override2.source }
|
|
7390
|
+
});
|
|
7391
|
+
if (existingSelection.kind === "selected" && preservePinnedSelection && existingSelection.turnId === turnId && isPinnedModelSelection(existingSelection.selection))
|
|
7392
|
+
return validate(existingSelection.selection);
|
|
7316
7393
|
try {
|
|
7317
|
-
|
|
7318
|
-
|
|
7319
|
-
|
|
7320
|
-
|
|
7321
|
-
|
|
7322
|
-
|
|
7394
|
+
const skippedPreferences = [];
|
|
7395
|
+
const explain = (result) => ({
|
|
7396
|
+
...result,
|
|
7397
|
+
skippedPreferences
|
|
7398
|
+
});
|
|
7399
|
+
const preferences = [
|
|
7400
|
+
() => candidate(configuration.turnProfileIds.get(turnId), "instance_turn_config"),
|
|
7401
|
+
() => candidate(configuration.defaultProfileId, "instance_default"),
|
|
7402
|
+
() => candidate(policy.scopedProfileIdForTurn?.(turnId), "scoped_purpose_default"),
|
|
7403
|
+
() => candidate(policy.turnProfileIds[turnId], "process_config_turn"),
|
|
7404
|
+
() => candidate(policy.defaultProfileId, "process_config_default"),
|
|
7405
|
+
() => candidate(snapshot.defaultProfileId, "catalog_default")
|
|
7406
|
+
];
|
|
7407
|
+
for (const getPreference of preferences) {
|
|
7408
|
+
const preference = getPreference();
|
|
7409
|
+
if (!preference) continue;
|
|
7410
|
+
const result = validate(preference);
|
|
7411
|
+
if (!result.ok && result.code === "model_profile_not_allowed" && preference.provenance.source !== "instance_turn_config") {
|
|
7412
|
+
skippedPreferences.push({
|
|
7413
|
+
profileId: preference.modelProfileId,
|
|
7414
|
+
source: preference.provenance.source,
|
|
7415
|
+
rejections: result.rejections ?? []
|
|
7416
|
+
});
|
|
7417
|
+
continue;
|
|
7418
|
+
}
|
|
7419
|
+
return explain(result);
|
|
7420
|
+
}
|
|
7421
|
+
const ranked = rankedProfiles(policy, snapshot.profiles, turnId);
|
|
7422
|
+
if (!ranked.profiles.length)
|
|
7423
|
+
return {
|
|
7424
|
+
ok: false,
|
|
7425
|
+
code: "model_required",
|
|
7426
|
+
selection: null,
|
|
7427
|
+
skippedPreferences,
|
|
7428
|
+
...availability ? { availabilityRevision: availability.revision } : {},
|
|
7429
|
+
requirements: requirementLayers(policy, turnId)
|
|
7430
|
+
};
|
|
7431
|
+
return {
|
|
7432
|
+
...explain(
|
|
7433
|
+
validate(candidate(ranked.profiles[0]?.id, ranked.marked ? "marked_default" : "automatic"))
|
|
7434
|
+
),
|
|
7435
|
+
ranking: {
|
|
7436
|
+
kind: ranked.marked ? "marked_defaults" : "cost_id",
|
|
7437
|
+
tiedProfileIds: ranked.tiedProfileIds
|
|
7438
|
+
}
|
|
7439
|
+
};
|
|
7323
7440
|
} catch (error) {
|
|
7324
7441
|
return {
|
|
7325
7442
|
ok: false,
|
|
@@ -7331,7 +7448,7 @@ function resolveTurn(snapshot, configuration, turnId, mode, existingSelection, o
|
|
|
7331
7448
|
};
|
|
7332
7449
|
}
|
|
7333
7450
|
}
|
|
7334
|
-
function recoverPreparation(snapshot, cause, configuration,
|
|
7451
|
+
function recoverPreparation(snapshot, cause, configuration, currentStart, availability) {
|
|
7335
7452
|
const state = currentStart.state;
|
|
7336
7453
|
if (state.kind !== "preparation_failed" || state.code !== "model_unavailable" && state.code !== "model_stale" || state.availabilityRevision === void 0 || cause === "availability_transition" && state.availabilityRevision >= availability.revision)
|
|
7337
7454
|
return {
|
|
@@ -7343,22 +7460,12 @@ function recoverPreparation(snapshot, cause, configuration, existingSelection, c
|
|
|
7343
7460
|
};
|
|
7344
7461
|
const profileId = trimToNull2(state.requestedModelProfileId);
|
|
7345
7462
|
const provenance = state.modelSelectionProvenance;
|
|
7346
|
-
if (provenance?.kind === "inherited") {
|
|
7347
|
-
return resolveTurn(
|
|
7348
|
-
snapshot,
|
|
7349
|
-
configuration,
|
|
7350
|
-
currentStart.turnId,
|
|
7351
|
-
"retry",
|
|
7352
|
-
existingSelection,
|
|
7353
|
-
{ kind: "inherit" },
|
|
7354
|
-
availability
|
|
7355
|
-
);
|
|
7356
|
-
}
|
|
7357
7463
|
return validateSelection(
|
|
7358
7464
|
snapshot,
|
|
7359
7465
|
configuration.processId,
|
|
7360
7466
|
profileId && provenance ? { modelProfileId: profileId, provenance } : null,
|
|
7361
|
-
availability
|
|
7467
|
+
availability,
|
|
7468
|
+
currentStart.turnId
|
|
7362
7469
|
);
|
|
7363
7470
|
}
|
|
7364
7471
|
|
|
@@ -7579,6 +7686,7 @@ function prepareLaunchPlan(snapshot, launchPlan, opts = {}) {
|
|
|
7579
7686
|
const warnings = [];
|
|
7580
7687
|
const errors = [];
|
|
7581
7688
|
const report = (issue2) => {
|
|
7689
|
+
if (!issue2) return;
|
|
7582
7690
|
if (invalidMode === "reject") errors.push(issue2);
|
|
7583
7691
|
else warnings.push(issue2);
|
|
7584
7692
|
};
|
|
@@ -7588,7 +7696,7 @@ function prepareLaunchPlan(snapshot, launchPlan, opts = {}) {
|
|
|
7588
7696
|
);
|
|
7589
7697
|
if (!parsed.ok) {
|
|
7590
7698
|
const message = parsed.error.reason === "invalid_json" ? "turnConfigsJson must be valid JSON" : parsed.error.reason === "not_object" ? "turnConfigsJson must be an object" : `turnConfigsJson.${parsed.error.turnId ?? "<unknown>"} must be an object`;
|
|
7591
|
-
|
|
7699
|
+
errors.push(issue(parsed.error.code, message));
|
|
7592
7700
|
}
|
|
7593
7701
|
const baseConfig = {
|
|
7594
7702
|
defaultModelProfileId: launchPlan.processInput.defaultModelProfileId ?? null,
|
|
@@ -7603,26 +7711,26 @@ function prepareLaunchPlan(snapshot, launchPlan, opts = {}) {
|
|
|
7603
7711
|
const policy = snapshot.processesById.get(launchPlan.processId);
|
|
7604
7712
|
const llmTurns = policy?.llmTurnIds ?? /* @__PURE__ */ new Set();
|
|
7605
7713
|
const validTurns = {};
|
|
7606
|
-
|
|
7714
|
+
const defaultModelProfileId = normalized.defaultModelProfileId ?? null;
|
|
7607
7715
|
const modelIssue = (profileId, modelTarget) => {
|
|
7608
7716
|
if (!profileId) return null;
|
|
7609
|
-
const result = validateSelection(
|
|
7610
|
-
|
|
7611
|
-
|
|
7612
|
-
|
|
7717
|
+
const result = validateSelection(
|
|
7718
|
+
snapshot,
|
|
7719
|
+
launchPlan.processId,
|
|
7720
|
+
{
|
|
7721
|
+
modelProfileId: profileId,
|
|
7722
|
+
provenance: { kind: "explicit", source: "instance_default" }
|
|
7723
|
+
},
|
|
7724
|
+
void 0,
|
|
7725
|
+
modelTarget.kind === "default_model" ? void 0 : modelTarget.turnId ?? void 0
|
|
7726
|
+
);
|
|
7613
7727
|
return result.ok ? null : issueForPolicy(result, launchPlan.processId, modelTarget);
|
|
7614
7728
|
};
|
|
7615
|
-
|
|
7616
|
-
const issue2 = modelIssue(profileId, modelTarget);
|
|
7617
|
-
if (!issue2) return true;
|
|
7618
|
-
report(issue2);
|
|
7619
|
-
return false;
|
|
7620
|
-
};
|
|
7621
|
-
if (!validate(defaultModelProfileId, target("default_model"))) defaultModelProfileId = null;
|
|
7729
|
+
report(modelIssue(defaultModelProfileId, target("default_model")));
|
|
7622
7730
|
for (const [turnId, config] of Object.entries(normalized.turnConfigs ?? {})) {
|
|
7623
7731
|
const profileId = config.modelProfileId?.trim() || null;
|
|
7624
7732
|
if (!llmTurns.has(turnId)) {
|
|
7625
|
-
|
|
7733
|
+
errors.push(
|
|
7626
7734
|
issue(
|
|
7627
7735
|
"unknown_llm_turn",
|
|
7628
7736
|
`Turn '${turnId}' is not a known LLM turn for process '${launchPlan.processId}'`
|
|
@@ -7630,40 +7738,37 @@ function prepareLaunchPlan(snapshot, launchPlan, opts = {}) {
|
|
|
7630
7738
|
);
|
|
7631
7739
|
continue;
|
|
7632
7740
|
}
|
|
7633
|
-
if (profileId
|
|
7741
|
+
if (profileId) {
|
|
7742
|
+
report(modelIssue(profileId, target("turn_model", turnId)));
|
|
7634
7743
|
validTurns[turnId] = { modelProfileId: profileId };
|
|
7635
7744
|
}
|
|
7636
7745
|
}
|
|
7637
7746
|
const selectedTurnId = launchPlan.startTurnId ?? launchPlan.processInput.selectedTurnId;
|
|
7638
|
-
const
|
|
7639
|
-
|
|
7640
|
-
const selectedTurnIssue = !selectedProfileId ? null : !selectedTurnId ? issue(
|
|
7747
|
+
const selectedModelProfileId = launchPlan.processInput.selectedTurnModelProfileId?.trim() || null;
|
|
7748
|
+
const selectedTurnIssue = !selectedModelProfileId ? null : !selectedTurnId ? issue(
|
|
7641
7749
|
"selected_turn_model_requires_selected_turn",
|
|
7642
|
-
`Selected turn model profile '${
|
|
7750
|
+
`Selected turn model profile '${selectedModelProfileId}' requires a selected turn`
|
|
7643
7751
|
) : !llmTurns.has(selectedTurnId) ? issue(
|
|
7644
7752
|
"selected_turn_model_requires_llm_turn",
|
|
7645
|
-
`Selected turn model profile '${
|
|
7646
|
-
) : modelIssue(
|
|
7647
|
-
|
|
7648
|
-
report(selectedTurnIssue);
|
|
7649
|
-
if (invalidMode !== "reject") selectedModelProfileId = null;
|
|
7650
|
-
}
|
|
7753
|
+
`Selected turn model profile '${selectedModelProfileId}' requires selected turn '${selectedTurnId}' to be an LLM turn`
|
|
7754
|
+
) : modelIssue(selectedModelProfileId, target("selected_turn_model", selectedTurnId));
|
|
7755
|
+
report(selectedTurnIssue);
|
|
7651
7756
|
const modelConfig = { defaultModelProfileId, turnConfigs: validTurns };
|
|
7652
7757
|
let initialDefaultModelProfileId = null;
|
|
7653
7758
|
const configuration = modelConfigurationFromLaunchInput(launchPlan.processId, modelConfig);
|
|
7654
7759
|
const defaultResult = resolveDefault(snapshot, configuration);
|
|
7655
7760
|
if (defaultResult.ok)
|
|
7656
7761
|
initialDefaultModelProfileId = defaultResult.selection?.modelProfileId ?? null;
|
|
7657
|
-
if (selectedTurnId && !selectedModelProfileId) {
|
|
7762
|
+
if (selectedTurnId && !selectedModelProfileId && errors.length === 0 && warnings.length === 0) {
|
|
7658
7763
|
const turnResult = resolveTurn(
|
|
7659
7764
|
snapshot,
|
|
7660
7765
|
configuration,
|
|
7661
7766
|
selectedTurnId,
|
|
7662
|
-
|
|
7767
|
+
false,
|
|
7663
7768
|
{ kind: "none" },
|
|
7664
7769
|
{ kind: "inherit" }
|
|
7665
7770
|
);
|
|
7666
|
-
if (!turnResult.ok
|
|
7771
|
+
if (!turnResult.ok) {
|
|
7667
7772
|
report(
|
|
7668
7773
|
issueForPolicy(
|
|
7669
7774
|
turnResult,
|
|
@@ -7705,6 +7810,7 @@ function prepareLaunchPlan(snapshot, launchPlan, opts = {}) {
|
|
|
7705
7810
|
|
|
7706
7811
|
// src/process-model-policy/project.ts
|
|
7707
7812
|
import { trimToNull as trimToNull5 } from "@leitwerk-dev/domain";
|
|
7813
|
+
import { compareModelProfileIds as compareModelProfileIds3, modelCostRank as modelCostRank2 } from "@leitwerk-dev/protocol";
|
|
7708
7814
|
|
|
7709
7815
|
// src/process-model-policy-presenter.ts
|
|
7710
7816
|
function presentLaunchPlanPreparationIssues(issues) {
|
|
@@ -7716,11 +7822,11 @@ function presentLaunchPlanPreparationIssues(issues) {
|
|
|
7716
7822
|
function presentProcessModelPolicyFailure(failure) {
|
|
7717
7823
|
switch (failure.code) {
|
|
7718
7824
|
case "model_required":
|
|
7719
|
-
return
|
|
7825
|
+
return `No model satisfies this turn's requirements${failure.requirements?.length ? `: ${failure.requirements.map((layer) => `${layer.origin} ${JSON.stringify(layer.requirements)}`).join("; ")}` : ""}`;
|
|
7720
7826
|
case "unknown_model_profile":
|
|
7721
7827
|
return `Unknown model profile '${failure.modelProfileId}'`;
|
|
7722
7828
|
case "model_profile_not_allowed":
|
|
7723
|
-
return `Model profile '${failure.modelProfileId}' is not allowed for process '${failure.processId}'`;
|
|
7829
|
+
return `Model profile '${failure.modelProfileId}' is not allowed for process '${failure.processId}'${failure.rejections?.length ? `: ${failure.rejections.map((r) => `${r.code} (${r.values.join(", ")}) from ${r.origin}`).join("; ")}` : ""}`;
|
|
7724
7830
|
case "model_stale":
|
|
7725
7831
|
return failure.reason ?? "Model status has not been refreshed";
|
|
7726
7832
|
case "model_unavailable":
|
|
@@ -7735,6 +7841,9 @@ function presentModelProfileOption(profile) {
|
|
|
7735
7841
|
const thinkingLevel = profile.thinkingLevel.trim();
|
|
7736
7842
|
return {
|
|
7737
7843
|
id: profile.id,
|
|
7844
|
+
...profile.policyReason ? { policyReason: profile.policyReason } : {},
|
|
7845
|
+
labels: profile.labels ?? [],
|
|
7846
|
+
default: profile.default ?? false,
|
|
7738
7847
|
label: `${profile.id} \u2014 ${profile.providerId}/${profile.modelId}`,
|
|
7739
7848
|
description: thinkingLevel && thinkingLevel.toLowerCase() !== "off" ? `Thinking level: ${thinkingLevel}` : "Thinking disabled",
|
|
7740
7849
|
availability: profile.availability,
|
|
@@ -7742,9 +7851,16 @@ function presentModelProfileOption(profile) {
|
|
|
7742
7851
|
checkedAt: profile.checkedAt
|
|
7743
7852
|
};
|
|
7744
7853
|
}
|
|
7854
|
+
function presentProfileMap(profiles = {}) {
|
|
7855
|
+
return Object.fromEntries(
|
|
7856
|
+
Object.entries(profiles).map(([id, options]) => [id, options.map(presentModelProfileOption)])
|
|
7857
|
+
);
|
|
7858
|
+
}
|
|
7745
7859
|
function presentLauncherModelConfigSchema(projection) {
|
|
7746
7860
|
return {
|
|
7747
7861
|
availableProfiles: projection.profiles.map(presentModelProfileOption),
|
|
7862
|
+
profilesByTurn: presentProfileMap(projection.profilesByTurn),
|
|
7863
|
+
excludedProfiles: presentProfileMap(projection.excludedProfiles),
|
|
7748
7864
|
llmTurns: projection.turns.map((turn) => ({ ...turn }))
|
|
7749
7865
|
};
|
|
7750
7866
|
}
|
|
@@ -7758,6 +7874,7 @@ function presentLauncherModelConfigPreview(projection) {
|
|
|
7758
7874
|
turnId: turn.turnId,
|
|
7759
7875
|
description: turn.description,
|
|
7760
7876
|
effective: {
|
|
7877
|
+
...turn.effective.explanation ? { explanation: turn.effective.explanation } : {},
|
|
7761
7878
|
...turn.effective.error ? { error: turn.effective.error } : {},
|
|
7762
7879
|
source: turn.effective.source,
|
|
7763
7880
|
profile: turn.effective.profile ? presentModelProfileOption(turn.effective.profile) : null
|
|
@@ -7768,6 +7885,8 @@ function presentLauncherModelConfigPreview(projection) {
|
|
|
7768
7885
|
function presentProcessModelConfiguration(projection) {
|
|
7769
7886
|
return {
|
|
7770
7887
|
state: projection.state,
|
|
7888
|
+
excludedProfiles: presentProfileMap(projection.excludedProfiles),
|
|
7889
|
+
profilesByTurn: presentProfileMap(projection.profilesByTurn),
|
|
7771
7890
|
availableProfiles: projection.profiles.map(presentModelProfileOption),
|
|
7772
7891
|
effectiveSelectedTurn: projection.effectiveSelectedTurn,
|
|
7773
7892
|
defaultModel: projection.defaultModel,
|
|
@@ -7776,24 +7895,6 @@ function presentProcessModelConfiguration(projection) {
|
|
|
7776
7895
|
}
|
|
7777
7896
|
|
|
7778
7897
|
// src/process-model-policy/project.ts
|
|
7779
|
-
function projectProfiles(snapshot, processId, availability) {
|
|
7780
|
-
const process2 = snapshot.processesById.get(processId);
|
|
7781
|
-
return snapshot.profiles.filter((profile) => !process2?.allowedProfileIds || process2.allowedProfileIds.has(profile.id)).map((profile) => {
|
|
7782
|
-
const status = availability?.profiles.find((candidate2) => candidate2.profileId === profile.id);
|
|
7783
|
-
return {
|
|
7784
|
-
id: profile.id,
|
|
7785
|
-
providerId: profile.provider,
|
|
7786
|
-
modelId: profile.modelId,
|
|
7787
|
-
thinkingLevel: profile.thinkingLevel,
|
|
7788
|
-
availability: status?.availability ?? "stale",
|
|
7789
|
-
safeReason: status?.safeReason ?? null,
|
|
7790
|
-
checkedAt: status?.checkedAt ?? null
|
|
7791
|
-
};
|
|
7792
|
-
});
|
|
7793
|
-
}
|
|
7794
|
-
function sourceForPreview(source) {
|
|
7795
|
-
return source === "action_override" ? "instance_turn_config" : source;
|
|
7796
|
-
}
|
|
7797
7898
|
function defaultProjection(snapshot, configuration) {
|
|
7798
7899
|
const policy = snapshot.processesById.get(configuration.processId);
|
|
7799
7900
|
const { selection } = resolveDefault(snapshot, configuration);
|
|
@@ -7806,21 +7907,63 @@ function defaultProjection(snapshot, configuration) {
|
|
|
7806
7907
|
}
|
|
7807
7908
|
function projectPolicy(snapshot, request) {
|
|
7808
7909
|
const processId = request.kind === "process_configuration" ? request.process.processId : request.processId;
|
|
7809
|
-
const
|
|
7810
|
-
|
|
7811
|
-
processId,
|
|
7812
|
-
"availability" in request ? request.availability : void 0
|
|
7813
|
-
);
|
|
7814
|
-
if (request.kind === "profile_options") return profiles;
|
|
7910
|
+
const policy = snapshot.processesById.get(processId);
|
|
7911
|
+
const targetTurnId = "target" in request && request.target.kind === "turn" ? request.target.turnId : void 0;
|
|
7815
7912
|
if (request.kind === "compatible_profiles") {
|
|
7816
|
-
const allowedProfileIds = new Set(profiles.map((profile) => profile.id));
|
|
7817
7913
|
return snapshot.profiles.filter(
|
|
7818
|
-
(profile) => profile.provider === request.providerId && profile.modelId === request.modelId &&
|
|
7914
|
+
(profile) => profile.provider === request.providerId && profile.modelId === request.modelId && (!policy || !profileRejections(policy, profile, targetTurnId).length)
|
|
7819
7915
|
).map((profile) => profile.id);
|
|
7820
7916
|
}
|
|
7821
|
-
const
|
|
7917
|
+
const catalog = [...snapshot.profiles].sort(
|
|
7918
|
+
(a, b) => modelCostRank2(a.labels) - modelCostRank2(b.labels) || compareModelProfileIds3(a.id, b.id)
|
|
7919
|
+
).map((profile) => {
|
|
7920
|
+
const status = request.availability?.profiles.find(
|
|
7921
|
+
(candidate2) => candidate2.profileId === profile.id
|
|
7922
|
+
);
|
|
7923
|
+
return {
|
|
7924
|
+
source: profile,
|
|
7925
|
+
id: profile.id,
|
|
7926
|
+
providerId: profile.provider,
|
|
7927
|
+
modelId: profile.modelId,
|
|
7928
|
+
thinkingLevel: profile.thinkingLevel,
|
|
7929
|
+
labels: profile.labels,
|
|
7930
|
+
default: profile.default,
|
|
7931
|
+
availability: status?.availability ?? "stale",
|
|
7932
|
+
safeReason: status?.safeReason ?? null,
|
|
7933
|
+
checkedAt: status?.checkedAt ?? null
|
|
7934
|
+
};
|
|
7935
|
+
});
|
|
7936
|
+
const projectProfiles = (turnId) => {
|
|
7937
|
+
const projected = catalog.map(({ source, ...option }) => {
|
|
7938
|
+
const rejections = policy ? profileRejections(policy, source, turnId) : [];
|
|
7939
|
+
return {
|
|
7940
|
+
...option,
|
|
7941
|
+
policyReason: rejections.map((r) => `${r.code} (${r.values.join(", ")}) from ${r.origin}`).join("; ") || void 0
|
|
7942
|
+
};
|
|
7943
|
+
});
|
|
7944
|
+
return {
|
|
7945
|
+
profiles: projected.filter((profile) => !profile.policyReason),
|
|
7946
|
+
excludedProfiles: projected.filter((profile) => profile.policyReason)
|
|
7947
|
+
};
|
|
7948
|
+
};
|
|
7949
|
+
const processProfiles = projectProfiles(targetTurnId);
|
|
7950
|
+
const { profiles } = processProfiles;
|
|
7951
|
+
if (request.kind === "profile_options") return profiles;
|
|
7952
|
+
const profileMaps = () => {
|
|
7953
|
+
const turns2 = [...policy?.llmTurnIds ?? []].map(
|
|
7954
|
+
(turnId) => [turnId, projectProfiles(turnId)]
|
|
7955
|
+
);
|
|
7956
|
+
return {
|
|
7957
|
+
profilesByTurn: Object.fromEntries(turns2.map(([id, value]) => [id, value.profiles])),
|
|
7958
|
+
excludedProfiles: Object.fromEntries([
|
|
7959
|
+
["", processProfiles.excludedProfiles],
|
|
7960
|
+
...turns2.map(([id, value]) => [id, value.excludedProfiles])
|
|
7961
|
+
])
|
|
7962
|
+
};
|
|
7963
|
+
};
|
|
7822
7964
|
if (request.kind === "launcher_schema") {
|
|
7823
7965
|
return {
|
|
7966
|
+
...profileMaps(),
|
|
7824
7967
|
profiles,
|
|
7825
7968
|
turns: [...policy?.llmTurnIds ?? []].map((turnId) => ({
|
|
7826
7969
|
turnId,
|
|
@@ -7851,13 +7994,15 @@ function projectPolicy(snapshot, request) {
|
|
|
7851
7994
|
snapshot,
|
|
7852
7995
|
configuration,
|
|
7853
7996
|
turnId,
|
|
7854
|
-
|
|
7997
|
+
false,
|
|
7855
7998
|
{ kind: "none" },
|
|
7856
7999
|
{ kind: "inherit" },
|
|
7857
8000
|
request.availability
|
|
7858
8001
|
);
|
|
7859
8002
|
return {
|
|
7860
8003
|
turnId,
|
|
8004
|
+
explanation: resolved2.skippedPreferences?.length ? `Automatic \u2014 skipped ${resolved2.skippedPreferences.map((preference) => `${preference.profileId}: ${preference.rejections.map((r) => `${r.code} (${r.values.join(", ")}) from ${r.origin}`).join("; ")}`).join("; ")}` : void 0,
|
|
8005
|
+
ranking: resolved2.ranking,
|
|
7861
8006
|
effectiveModelProfileId: resolved2.selection?.modelProfileId ?? null,
|
|
7862
8007
|
effectiveSource: resolved2.selection?.provenance.source ?? "none",
|
|
7863
8008
|
...!resolved2.ok ? { effectiveError: presentProcessModelPolicyFailure(resolved2) } : {},
|
|
@@ -7871,7 +8016,9 @@ function projectPolicy(snapshot, request) {
|
|
|
7871
8016
|
};
|
|
7872
8017
|
});
|
|
7873
8018
|
if (request.kind === "launcher_preview") {
|
|
7874
|
-
const profilesById = new Map(
|
|
8019
|
+
const profilesById = new Map(
|
|
8020
|
+
catalog.map(({ source: _source, ...profile }) => [profile.id, profile])
|
|
8021
|
+
);
|
|
7875
8022
|
return {
|
|
7876
8023
|
defaultModel: {
|
|
7877
8024
|
source: defaultModel.source,
|
|
@@ -7881,7 +8028,9 @@ function projectPolicy(snapshot, request) {
|
|
|
7881
8028
|
turnId: turn.turnId,
|
|
7882
8029
|
description: turn.description,
|
|
7883
8030
|
effective: {
|
|
7884
|
-
|
|
8031
|
+
explanation: turn.explanation,
|
|
8032
|
+
ranking: turn.ranking,
|
|
8033
|
+
source: turn.effectiveSource,
|
|
7885
8034
|
...turn.effectiveError ? { error: turn.effectiveError } : {},
|
|
7886
8035
|
profile: profilesById.get(turn.effectiveModelProfileId ?? "") ?? null
|
|
7887
8036
|
}
|
|
@@ -7891,6 +8040,7 @@ function projectPolicy(snapshot, request) {
|
|
|
7891
8040
|
const selectedTurn = existingTurnSelectionFromProcess(request.process);
|
|
7892
8041
|
return {
|
|
7893
8042
|
state: { kind: "ready" },
|
|
8043
|
+
...profileMaps(),
|
|
7894
8044
|
profiles,
|
|
7895
8045
|
defaultModel,
|
|
7896
8046
|
turns,
|
|
@@ -7919,19 +8069,13 @@ async function evaluateAtStableAvailabilityRevision(input) {
|
|
|
7919
8069
|
}
|
|
7920
8070
|
|
|
7921
8071
|
// src/process-model-policy/index.ts
|
|
7922
|
-
function resolutionMode(startKind, initialSelection) {
|
|
7923
|
-
if (startKind === "retry" || startKind === "startup_retry") return "retry";
|
|
7924
|
-
if (startKind === "continue") return "continue";
|
|
7925
|
-
if (initialSelection) return "initial";
|
|
7926
|
-
return "resolve";
|
|
7927
|
-
}
|
|
7928
8072
|
function evaluateSubject(snapshot, request) {
|
|
7929
8073
|
if (request.kind === "process_turn") {
|
|
7930
8074
|
return resolveTurn(
|
|
7931
8075
|
snapshot,
|
|
7932
8076
|
modelConfigurationFromProcess(request.process),
|
|
7933
8077
|
request.turnId,
|
|
7934
|
-
|
|
8078
|
+
request.initialSelection === true || request.startKind === "retry" || request.startKind === "startup_retry" || request.startKind === "continue",
|
|
7935
8079
|
existingTurnSelectionFromProcess(request.process),
|
|
7936
8080
|
modelOverride(
|
|
7937
8081
|
request.modelOverride,
|
|
@@ -7951,20 +8095,25 @@ function evaluateSubject(snapshot, request) {
|
|
|
7951
8095
|
turnConfigsJson: request.plan.processInput.turnConfigsJson
|
|
7952
8096
|
}),
|
|
7953
8097
|
request.turnId,
|
|
7954
|
-
|
|
8098
|
+
false,
|
|
7955
8099
|
{ kind: "none" },
|
|
7956
8100
|
modelOverride(selected, selected !== null, "launch_override"),
|
|
7957
8101
|
request.availability
|
|
7958
8102
|
);
|
|
7959
8103
|
}
|
|
7960
8104
|
if (request.kind === "runtime_selection") {
|
|
7961
|
-
return validateSelection(
|
|
8105
|
+
return validateSelection(
|
|
8106
|
+
snapshot,
|
|
8107
|
+
request.processId,
|
|
8108
|
+
request.selection,
|
|
8109
|
+
request.availability,
|
|
8110
|
+
request.target.kind === "turn" ? request.target.turnId : void 0
|
|
8111
|
+
);
|
|
7962
8112
|
}
|
|
7963
8113
|
return recoverPreparation(
|
|
7964
8114
|
snapshot,
|
|
7965
8115
|
request.cause,
|
|
7966
8116
|
modelConfigurationFromProcess(request.process),
|
|
7967
|
-
existingTurnSelectionFromProcess(request.process),
|
|
7968
8117
|
request.currentStart,
|
|
7969
8118
|
request.availability
|
|
7970
8119
|
);
|
|
@@ -8902,10 +9051,7 @@ function buildRuntimeProfileSelectionInput(args) {
|
|
|
8902
9051
|
|
|
8903
9052
|
// src/process-engine/turn-start-preflight.ts
|
|
8904
9053
|
import { VERSION as PI_RUNTIME_VERSION } from "@earendil-works/pi-coding-agent";
|
|
8905
|
-
import {
|
|
8906
|
-
filterProviderOptionsForDefinition,
|
|
8907
|
-
resolveOutcomeContract
|
|
8908
|
-
} from "@leitwerk-dev/process-sdk";
|
|
9054
|
+
import { resolveOutcomeContract } from "@leitwerk-dev/process-sdk";
|
|
8909
9055
|
import { IPC_PROTOCOL_VERSION, WORKER_API_VERSION } from "@leitwerk-dev/worker-protocol";
|
|
8910
9056
|
|
|
8911
9057
|
// src/model-providers/provider-options.ts
|
|
@@ -9092,7 +9238,21 @@ async function prepareCreatedTurnStarts(deps, process2, writes, explicitProvider
|
|
|
9092
9238
|
};
|
|
9093
9239
|
}
|
|
9094
9240
|
}
|
|
9095
|
-
const
|
|
9241
|
+
const priorState = write.input.state;
|
|
9242
|
+
const captured = priorState.automaticRetry ? priorState.kind === "preparation_failed" ? priorState.requestedModelProfileId && priorState.modelSelectionProvenance ? {
|
|
9243
|
+
modelProfileId: priorState.requestedModelProfileId,
|
|
9244
|
+
provenance: priorState.modelSelectionProvenance
|
|
9245
|
+
} : null : priorState.kind === "starting" && priorState.start.kind === "llm" && priorState.start.modelSelectionProvenance ? {
|
|
9246
|
+
modelProfileId: priorState.start.model.profileId,
|
|
9247
|
+
provenance: priorState.start.modelSelectionProvenance
|
|
9248
|
+
} : null : null;
|
|
9249
|
+
const evaluated = captured ? deps.processModelPolicy.evaluate({
|
|
9250
|
+
kind: "runtime_selection",
|
|
9251
|
+
target: { kind: "turn", turnId: write.input.turnId },
|
|
9252
|
+
processId: nextProcess.processId,
|
|
9253
|
+
selection: captured,
|
|
9254
|
+
availability
|
|
9255
|
+
}) : deps.processModelPolicy.evaluate({
|
|
9096
9256
|
kind: "process_turn",
|
|
9097
9257
|
process: nextProcess,
|
|
9098
9258
|
turnId: write.input.turnId,
|
|
@@ -9121,6 +9281,7 @@ async function prepareCreatedTurnStarts(deps, process2, writes, explicitProvider
|
|
|
9121
9281
|
Object.assign(nextProcess, patch);
|
|
9122
9282
|
Object.assign(writes.processPatch, patch);
|
|
9123
9283
|
}
|
|
9284
|
+
if (captured && priorState.kind === "starting") continue;
|
|
9124
9285
|
const provenance = nextProcess.selectedTurnModelKind && nextProcess.selectedTurnModelSource ? {
|
|
9125
9286
|
kind: nextProcess.selectedTurnModelKind,
|
|
9126
9287
|
source: nextProcess.selectedTurnModelSource
|
|
@@ -9168,9 +9329,7 @@ async function prepareCreatedTurnStarts(deps, process2, writes, explicitProvider
|
|
|
9168
9329
|
}
|
|
9169
9330
|
const provider = deps.registry.require(profile.provider);
|
|
9170
9331
|
const retainedProviderId = previousProviderId(deps, retainedState);
|
|
9171
|
-
const recoveryOptions = explicitProviderOptions ? { ...explicitProviderOptions } : retainedProviderId !== null && retainedProviderId !== provider.id ? {
|
|
9172
|
-
...filterProviderOptionsForDefinition(provider.definition.options, retainedOptions)
|
|
9173
|
-
} : retainedOptions;
|
|
9332
|
+
const recoveryOptions = explicitProviderOptions ? { ...explicitProviderOptions } : retainedProviderId !== null && retainedProviderId !== provider.id ? {} : retainedOptions;
|
|
9174
9333
|
const optionResult = resolveRegisteredProviderOptions({
|
|
9175
9334
|
provider,
|
|
9176
9335
|
explicit: recoveryOptions,
|
|
@@ -13250,7 +13409,6 @@ export {
|
|
|
13250
13409
|
presentLauncherModelConfigSchema,
|
|
13251
13410
|
presentLauncherModelConfigPreview,
|
|
13252
13411
|
presentProcessModelConfiguration,
|
|
13253
|
-
isPinnedModelSelection,
|
|
13254
13412
|
evaluateAtStableAvailabilityRevision,
|
|
13255
13413
|
createServerProcessModelPolicy,
|
|
13256
13414
|
resolveCurrentExecutionTurnRecordId,
|
|
@@ -13319,4 +13477,4 @@ export {
|
|
|
13319
13477
|
createProjectedSessionSnapshotStore,
|
|
13320
13478
|
createBroadcaster
|
|
13321
13479
|
};
|
|
13322
|
-
//# sourceMappingURL=chunk-
|
|
13480
|
+
//# sourceMappingURL=chunk-ZA5TDEM5.js.map
|