@leitwerk-dev/server 0.5.3 → 0.5.5
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-DWWNqFtH.d.ts} +83 -77
- package/dist/app-VLQCV5WS.js +8 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/{chunk-6EEU4QOU.js → chunk-65CBLH7U.js} +350 -144
- package/dist/chunk-65CBLH7U.js.map +1 -0
- package/dist/chunk-C2K2AM5X.js +82 -0
- package/dist/chunk-C2K2AM5X.js.map +1 -0
- package/dist/{chunk-AJ2DQWI3.js → chunk-I3CCVPXY.js} +133 -83
- package/dist/chunk-I3CCVPXY.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/deployment-preflight.d.ts +2 -1
- package/dist/deployment-preflight.d.ts.map +1 -1
- package/dist/extension-boot-check.d.ts +5 -0
- package/dist/extension-boot-check.d.ts.map +1 -0
- 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.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +41 -3
- package/dist/index.js.map +1 -1
- package/dist/main.js +6 -71
- package/dist/main.js.map +1 -1
- 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/deployment-preflight.ts +15 -7
- package/src/extension-boot-check.ts +36 -0
- 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/index.ts +1 -0
- 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-VLQCV5WS.js.map} +0 -0
|
@@ -1,7 +1,54 @@
|
|
|
1
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
|
|
2
|
+
var __typeError = (msg) => {
|
|
3
|
+
throw TypeError(msg);
|
|
4
|
+
};
|
|
5
|
+
var __using = (stack, value, async) => {
|
|
6
|
+
if (value != null) {
|
|
7
|
+
if (typeof value !== "object" && typeof value !== "function") __typeError("Object expected");
|
|
8
|
+
var dispose, inner;
|
|
9
|
+
if (async) dispose = value[__knownSymbol("asyncDispose")];
|
|
10
|
+
if (dispose === void 0) {
|
|
11
|
+
dispose = value[__knownSymbol("dispose")];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") __typeError("Object not disposable");
|
|
15
|
+
if (inner) dispose = function() {
|
|
16
|
+
try {
|
|
17
|
+
inner.call(this);
|
|
18
|
+
} catch (e) {
|
|
19
|
+
return Promise.reject(e);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
stack.push([async, dispose, value]);
|
|
23
|
+
} else if (async) {
|
|
24
|
+
stack.push([async]);
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
};
|
|
28
|
+
var __callDispose = (stack, error, hasError) => {
|
|
29
|
+
var E = typeof SuppressedError === "function" ? SuppressedError : function(e, s, m, _) {
|
|
30
|
+
return _ = Error(m), _.name = "SuppressedError", _.error = e, _.suppressed = s, _;
|
|
31
|
+
};
|
|
32
|
+
var fail = (e) => error = hasError ? new E(e, error, "An error was suppressed during disposal") : (hasError = true, e);
|
|
33
|
+
var next = (it) => {
|
|
34
|
+
while (it = stack.pop()) {
|
|
35
|
+
try {
|
|
36
|
+
var result = it[1] && it[1].call(it[2]);
|
|
37
|
+
if (it[0]) return Promise.resolve(result).then(next, (e) => (fail(e), next()));
|
|
38
|
+
} catch (e) {
|
|
39
|
+
fail(e);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (hasError) throw error;
|
|
43
|
+
};
|
|
44
|
+
return next();
|
|
45
|
+
};
|
|
46
|
+
|
|
1
47
|
// src/config/config-loader.ts
|
|
2
48
|
import { existsSync, readFileSync } from "node:fs";
|
|
3
49
|
import { resolve } from "node:path";
|
|
4
50
|
import { copiedUnknownRecordSchema as unknownRecordSchema } from "@leitwerk-dev/domain";
|
|
51
|
+
import { modelPolicyIdentifiersSchema, modelRequirementsSchema } from "@leitwerk-dev/protocol";
|
|
5
52
|
import { DEFAULT_SESSION_TRANSFER_LIMITS } from "@leitwerk-dev/session-transfer";
|
|
6
53
|
import { parseDurationMs as parseDurationMs2 } from "@leitwerk-dev/watcher-utils";
|
|
7
54
|
import {
|
|
@@ -372,7 +419,8 @@ var skillIdsSchema = v.array(
|
|
|
372
419
|
v.pipe(v.string(), v.regex(SAFE_SKILL_ID_PATTERN, "Invalid skill ID"))
|
|
373
420
|
);
|
|
374
421
|
var modelTurnConfigSchema = v.looseObject({
|
|
375
|
-
model_profile: v.optional(v.string())
|
|
422
|
+
model_profile: v.optional(v.string()),
|
|
423
|
+
model_requirements: v.optional(modelRequirementsSchema)
|
|
376
424
|
});
|
|
377
425
|
var authNonEmptyString = v.pipe(v.string(), v.nonEmpty());
|
|
378
426
|
var authOidcProviderSchema = v.looseObject({
|
|
@@ -530,6 +578,8 @@ var configSchema = v.looseObject({
|
|
|
530
578
|
provider: v.string(),
|
|
531
579
|
model_id: v.string(),
|
|
532
580
|
thinking_level: v.optional(v.string()),
|
|
581
|
+
labels: v.optional(modelPolicyIdentifiersSchema),
|
|
582
|
+
default: v.optional(v.boolean()),
|
|
533
583
|
provider_options: v.optional(v.record(v.string(), v.string()))
|
|
534
584
|
})
|
|
535
585
|
),
|
|
@@ -559,6 +609,7 @@ var configSchema = v.looseObject({
|
|
|
559
609
|
v.looseObject({
|
|
560
610
|
default_skills: v.optional(skillIdsSchema),
|
|
561
611
|
default_model_profile: v.optional(v.string()),
|
|
612
|
+
model_requirements: v.optional(modelRequirementsSchema),
|
|
562
613
|
allowed_model_profiles: v.optional(v.pipe(stringArraySchema, v.nonEmpty())),
|
|
563
614
|
worker_runtime_profile: v.optional(v.string()),
|
|
564
615
|
storage_size: v.optional(storageSizeSchema),
|
|
@@ -7047,6 +7098,7 @@ function recordTurnProgress(deps, input) {
|
|
|
7047
7098
|
// src/process-model-policy/construct.ts
|
|
7048
7099
|
import { trimToNull } from "@leitwerk-dev/domain";
|
|
7049
7100
|
import { isLlmTurnDefinition } from "@leitwerk-dev/process-sdk";
|
|
7101
|
+
import { assertValidModelRequirements, compareModelProfileIds } from "@leitwerk-dev/protocol";
|
|
7050
7102
|
|
|
7051
7103
|
// src/process-graph.ts
|
|
7052
7104
|
import {
|
|
@@ -7085,7 +7137,10 @@ function constructPolicySnapshot(input) {
|
|
|
7085
7137
|
provider: profile.provider,
|
|
7086
7138
|
modelId: profile.model_id,
|
|
7087
7139
|
thinkingLevel: profile.thinking_level ?? "off",
|
|
7088
|
-
providerOptions: profile.provider_options ?? {}
|
|
7140
|
+
providerOptions: profile.provider_options ?? {},
|
|
7141
|
+
labels: [...new Set(profile.labels ?? [])].sort(compareModelProfileIds),
|
|
7142
|
+
default: profile.default ?? false,
|
|
7143
|
+
capabilities: structuredClone(input.capabilities?.(profile.provider, profile.model_id) ?? {})
|
|
7089
7144
|
}));
|
|
7090
7145
|
const processIds = /* @__PURE__ */ new Set([
|
|
7091
7146
|
...input.processGraphs.keys(),
|
|
@@ -7095,12 +7150,46 @@ function constructPolicySnapshot(input) {
|
|
|
7095
7150
|
for (const processId of processIds) {
|
|
7096
7151
|
const graph = input.processGraphs.has(processId) ? getProcessGraph2(input.processGraphs, processId) : null;
|
|
7097
7152
|
const config = configSnapshot.process_configs?.[processId];
|
|
7153
|
+
const requirements = [];
|
|
7154
|
+
const turnRequirements = {};
|
|
7155
|
+
const add = (layers, origin, value) => {
|
|
7156
|
+
if (value === void 0) return;
|
|
7157
|
+
assertValidModelRequirements(value);
|
|
7158
|
+
layers.push({ origin, requirements: structuredClone(value) });
|
|
7159
|
+
};
|
|
7160
|
+
add(
|
|
7161
|
+
requirements,
|
|
7162
|
+
`process:${processId}`,
|
|
7163
|
+
input.processGraphs.get(processId)?.modelRequirements
|
|
7164
|
+
);
|
|
7165
|
+
add(
|
|
7166
|
+
requirements,
|
|
7167
|
+
`process_configs.${processId}.model_requirements`,
|
|
7168
|
+
config?.model_requirements
|
|
7169
|
+
);
|
|
7098
7170
|
const llmTurnIds = /* @__PURE__ */ new Set();
|
|
7099
7171
|
const purposeProfileIdsByTurn = {};
|
|
7100
7172
|
const descriptions = {};
|
|
7101
7173
|
const pathTypes = {};
|
|
7102
7174
|
for (const [turnId, turn] of graph?.turns ?? []) {
|
|
7103
|
-
|
|
7175
|
+
const declared = input.processGraphs.get(processId)?.turns.get(turnId)?.definition;
|
|
7176
|
+
if (turn.turnType !== "llm") {
|
|
7177
|
+
if (declared && "modelRequirements" in declared)
|
|
7178
|
+
throw new Error(`Model requirements require an LLM turn: ${processId}/${turnId}`);
|
|
7179
|
+
continue;
|
|
7180
|
+
}
|
|
7181
|
+
const layers = [];
|
|
7182
|
+
add(
|
|
7183
|
+
layers,
|
|
7184
|
+
`turn:${processId}/${turnId}`,
|
|
7185
|
+
declared?.kind === "llm" ? declared.modelRequirements : void 0
|
|
7186
|
+
);
|
|
7187
|
+
add(
|
|
7188
|
+
layers,
|
|
7189
|
+
`process_configs.${processId}.turn_configs.${turnId}.model_requirements`,
|
|
7190
|
+
config?.turn_configs?.[turnId]?.model_requirements
|
|
7191
|
+
);
|
|
7192
|
+
turnRequirements[turnId] = layers;
|
|
7104
7193
|
llmTurnIds.add(turnId);
|
|
7105
7194
|
const definition = input.processActionRegistry.getTurnDefinition(processId, turnId);
|
|
7106
7195
|
pathTypes[turnId] = definition && isLlmTurnDefinition(definition) ? definition.branchType : "primary";
|
|
@@ -7115,6 +7204,8 @@ function constructPolicySnapshot(input) {
|
|
|
7115
7204
|
const allowed = config?.allowed_model_profiles ? new Set(config.allowed_model_profiles.map((id) => id.trim()).filter(Boolean)) : null;
|
|
7116
7205
|
processesById.set(processId, {
|
|
7117
7206
|
id: processId,
|
|
7207
|
+
requirements,
|
|
7208
|
+
turnRequirements,
|
|
7118
7209
|
allowedProfileIds: allowed,
|
|
7119
7210
|
defaultProfileId: trimToNull(config?.default_model_profile),
|
|
7120
7211
|
turnProfileIds: Object.fromEntries(
|
|
@@ -7146,7 +7237,10 @@ function constructPolicySnapshot(input) {
|
|
|
7146
7237
|
profilesById: new Map(profiles.map((profile) => [profile.id, profile])),
|
|
7147
7238
|
processesById,
|
|
7148
7239
|
workerStaticConfig: {
|
|
7149
|
-
pi:
|
|
7240
|
+
pi: {
|
|
7241
|
+
...configSnapshot.pi,
|
|
7242
|
+
model_profiles: configSnapshot.pi.model_profiles.map(({ labels: _labels, default: _default, ...profile }) => profile).sort((a, b) => compareModelProfileIds(a.id, b.id))
|
|
7243
|
+
},
|
|
7150
7244
|
workers: configSnapshot.workers,
|
|
7151
7245
|
processPi: Object.fromEntries(
|
|
7152
7246
|
Object.entries(configSnapshot.process_configs ?? {}).map(([id, value]) => [
|
|
@@ -7161,6 +7255,61 @@ function constructPolicySnapshot(input) {
|
|
|
7161
7255
|
// src/process-model-policy/evaluate.ts
|
|
7162
7256
|
import { trimToNull as trimToNull2 } from "@leitwerk-dev/domain";
|
|
7163
7257
|
|
|
7258
|
+
// src/process-model-policy/requirements.ts
|
|
7259
|
+
import { compareModelProfileIds as compareModelProfileIds2, modelCostRank } from "@leitwerk-dev/protocol";
|
|
7260
|
+
function requirementLayers(policy, turnId) {
|
|
7261
|
+
return policy.requirements.concat(turnId ? policy.turnRequirements[turnId] ?? [] : []);
|
|
7262
|
+
}
|
|
7263
|
+
function profileRejections(policy, profile, turnId) {
|
|
7264
|
+
const rejections = [];
|
|
7265
|
+
if (policy.allowedProfileIds && !policy.allowedProfileIds.has(profile.id))
|
|
7266
|
+
rejections.push({
|
|
7267
|
+
origin: `process_configs.${policy.id}.allowed_model_profiles`,
|
|
7268
|
+
code: "profile_not_allowed",
|
|
7269
|
+
values: [profile.id]
|
|
7270
|
+
});
|
|
7271
|
+
const labels = new Set(profile.labels);
|
|
7272
|
+
for (const { origin, requirements: r } of requirementLayers(policy, turnId)) {
|
|
7273
|
+
if (r.profiles && !r.profiles.includes(profile.id))
|
|
7274
|
+
rejections.push({ origin, code: "profile_not_allowed", values: r.profiles });
|
|
7275
|
+
const missing = r.labels?.all_of?.filter((label) => !labels.has(label)) ?? [];
|
|
7276
|
+
if (missing.length) rejections.push({ origin, code: "missing_labels", values: missing });
|
|
7277
|
+
if (r.labels?.any_of && !r.labels.any_of.some((label) => labels.has(label)))
|
|
7278
|
+
rejections.push({ origin, code: "no_matching_labels", values: r.labels.any_of });
|
|
7279
|
+
const forbidden = r.labels?.none_of?.filter((label) => labels.has(label)) ?? [];
|
|
7280
|
+
if (forbidden.length) rejections.push({ origin, code: "forbidden_labels", values: forbidden });
|
|
7281
|
+
for (const capability of r.capabilities ?? []) {
|
|
7282
|
+
if (profile.capabilities[capability] !== true)
|
|
7283
|
+
rejections.push({
|
|
7284
|
+
origin,
|
|
7285
|
+
code: profile.capabilities[capability] === false ? "unsupported_capability" : "unknown_capability",
|
|
7286
|
+
values: [capability]
|
|
7287
|
+
});
|
|
7288
|
+
}
|
|
7289
|
+
}
|
|
7290
|
+
return rejections;
|
|
7291
|
+
}
|
|
7292
|
+
function rankedProfiles(policy, profiles, turnId) {
|
|
7293
|
+
const eligible = profiles.filter((profile) => !profileRejections(policy, profile, turnId).length);
|
|
7294
|
+
const marked = eligible.filter((profile) => profile.default);
|
|
7295
|
+
const relevant = new Set(
|
|
7296
|
+
requirementLayers(policy, turnId).flatMap(({ requirements: r }) => [
|
|
7297
|
+
...r.labels?.all_of ?? [],
|
|
7298
|
+
...r.labels?.any_of ?? []
|
|
7299
|
+
])
|
|
7300
|
+
);
|
|
7301
|
+
const unrelated = (profile) => new Set(profile.labels.filter((label) => !relevant.has(label))).size;
|
|
7302
|
+
const ranked = (marked.length ? marked : eligible).sort(
|
|
7303
|
+
(a, b) => (marked.length ? unrelated(a) - unrelated(b) : 0) || modelCostRank(a.labels) - modelCostRank(b.labels) || compareModelProfileIds2(a.id, b.id)
|
|
7304
|
+
);
|
|
7305
|
+
const minUnrelated = Math.min(...marked.map(unrelated));
|
|
7306
|
+
return {
|
|
7307
|
+
tiedProfileIds: marked.filter((profile) => unrelated(profile) === minUnrelated).map((profile) => profile.id),
|
|
7308
|
+
marked: marked.length > 0,
|
|
7309
|
+
profiles: ranked
|
|
7310
|
+
};
|
|
7311
|
+
}
|
|
7312
|
+
|
|
7164
7313
|
// src/process-model-policy/types.ts
|
|
7165
7314
|
function provenanceKindForSource(source) {
|
|
7166
7315
|
return source === "action_override" || source === "launch_override" || source === "instance_turn_config" || source === "instance_default" ? "explicit" : "inherited";
|
|
@@ -7173,6 +7322,8 @@ function isPinnedModelSelection(selection) {
|
|
|
7173
7322
|
function processPolicy(snapshot, processId) {
|
|
7174
7323
|
return snapshot.processesById.get(processId) ?? {
|
|
7175
7324
|
id: processId,
|
|
7325
|
+
requirements: [],
|
|
7326
|
+
turnRequirements: {},
|
|
7176
7327
|
allowedProfileIds: null,
|
|
7177
7328
|
defaultProfileId: null,
|
|
7178
7329
|
turnProfileIds: {},
|
|
@@ -7182,7 +7333,7 @@ function processPolicy(snapshot, processId) {
|
|
|
7182
7333
|
turnPathTypes: {}
|
|
7183
7334
|
};
|
|
7184
7335
|
}
|
|
7185
|
-
function validateSelection(snapshot, processId, selection, availability) {
|
|
7336
|
+
function validateSelection(snapshot, processId, selection, availability, turnId) {
|
|
7186
7337
|
if (!selection)
|
|
7187
7338
|
return {
|
|
7188
7339
|
ok: false,
|
|
@@ -7200,12 +7351,14 @@ function validateSelection(snapshot, processId, selection, availability) {
|
|
|
7200
7351
|
...availability ? { availabilityRevision: availability.revision } : {}
|
|
7201
7352
|
};
|
|
7202
7353
|
const policy = processPolicy(snapshot, processId);
|
|
7203
|
-
|
|
7354
|
+
const rejections = profileRejections(policy, profile, turnId);
|
|
7355
|
+
if (rejections.length)
|
|
7204
7356
|
return {
|
|
7205
7357
|
ok: false,
|
|
7206
7358
|
code: "model_profile_not_allowed",
|
|
7207
7359
|
modelProfileId: profile.id,
|
|
7208
7360
|
processId,
|
|
7361
|
+
rejections,
|
|
7209
7362
|
selection,
|
|
7210
7363
|
...availability ? { availabilityRevision: availability.revision } : {}
|
|
7211
7364
|
};
|
|
@@ -7248,21 +7401,6 @@ function resolveDefault(snapshot, configuration, availability) {
|
|
|
7248
7401
|
availability
|
|
7249
7402
|
);
|
|
7250
7403
|
}
|
|
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
7404
|
function invalidConfiguration(configuration) {
|
|
7267
7405
|
return {
|
|
7268
7406
|
ok: false,
|
|
@@ -7272,18 +7410,13 @@ function invalidConfiguration(configuration) {
|
|
|
7272
7410
|
issues: configuration.issues
|
|
7273
7411
|
};
|
|
7274
7412
|
}
|
|
7275
|
-
function resolveTurn(snapshot, configuration, turnId,
|
|
7413
|
+
function resolveTurn(snapshot, configuration, turnId, preservePinnedSelection, existingSelection, override2, availability) {
|
|
7276
7414
|
const policy = processPolicy(snapshot, configuration.processId);
|
|
7277
7415
|
if (!policy.llmTurnIds.has(turnId)) return { ok: true, selection: null };
|
|
7278
7416
|
if (configuration.kind === "invalid") return invalidConfiguration(configuration);
|
|
7417
|
+
const validate = (selection) => validateSelection(snapshot, configuration.processId, selection, availability, turnId);
|
|
7279
7418
|
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
|
-
);
|
|
7419
|
+
if (purposeProfileId) return validate(candidate(purposeProfileId, "fixed_purpose"));
|
|
7287
7420
|
if (existingSelection.kind === "invalid" && existingSelection.turnId === turnId)
|
|
7288
7421
|
return {
|
|
7289
7422
|
ok: false,
|
|
@@ -7297,29 +7430,59 @@ function resolveTurn(snapshot, configuration, turnId, mode, existingSelection, o
|
|
|
7297
7430
|
existingSelection = { kind: "none" };
|
|
7298
7431
|
}
|
|
7299
7432
|
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
|
-
);
|
|
7433
|
+
return validate({
|
|
7434
|
+
modelProfileId: override2.profileId,
|
|
7435
|
+
provenance: { kind: "explicit", source: override2.source }
|
|
7436
|
+
});
|
|
7437
|
+
if (existingSelection.kind === "selected" && preservePinnedSelection && existingSelection.turnId === turnId && isPinnedModelSelection(existingSelection.selection))
|
|
7438
|
+
return validate(existingSelection.selection);
|
|
7316
7439
|
try {
|
|
7317
|
-
|
|
7318
|
-
|
|
7319
|
-
|
|
7320
|
-
|
|
7321
|
-
|
|
7322
|
-
|
|
7440
|
+
const skippedPreferences = [];
|
|
7441
|
+
const explain = (result) => ({
|
|
7442
|
+
...result,
|
|
7443
|
+
skippedPreferences
|
|
7444
|
+
});
|
|
7445
|
+
const preferences = [
|
|
7446
|
+
() => candidate(configuration.turnProfileIds.get(turnId), "instance_turn_config"),
|
|
7447
|
+
() => candidate(configuration.defaultProfileId, "instance_default"),
|
|
7448
|
+
() => candidate(policy.scopedProfileIdForTurn?.(turnId), "scoped_purpose_default"),
|
|
7449
|
+
() => candidate(policy.turnProfileIds[turnId], "process_config_turn"),
|
|
7450
|
+
() => candidate(policy.defaultProfileId, "process_config_default"),
|
|
7451
|
+
() => candidate(snapshot.defaultProfileId, "catalog_default")
|
|
7452
|
+
];
|
|
7453
|
+
for (const getPreference of preferences) {
|
|
7454
|
+
const preference = getPreference();
|
|
7455
|
+
if (!preference) continue;
|
|
7456
|
+
const result = validate(preference);
|
|
7457
|
+
if (!result.ok && result.code === "model_profile_not_allowed" && preference.provenance.source !== "instance_turn_config") {
|
|
7458
|
+
skippedPreferences.push({
|
|
7459
|
+
profileId: preference.modelProfileId,
|
|
7460
|
+
source: preference.provenance.source,
|
|
7461
|
+
rejections: result.rejections ?? []
|
|
7462
|
+
});
|
|
7463
|
+
continue;
|
|
7464
|
+
}
|
|
7465
|
+
return explain(result);
|
|
7466
|
+
}
|
|
7467
|
+
const ranked = rankedProfiles(policy, snapshot.profiles, turnId);
|
|
7468
|
+
if (!ranked.profiles.length)
|
|
7469
|
+
return {
|
|
7470
|
+
ok: false,
|
|
7471
|
+
code: "model_required",
|
|
7472
|
+
selection: null,
|
|
7473
|
+
skippedPreferences,
|
|
7474
|
+
...availability ? { availabilityRevision: availability.revision } : {},
|
|
7475
|
+
requirements: requirementLayers(policy, turnId)
|
|
7476
|
+
};
|
|
7477
|
+
return {
|
|
7478
|
+
...explain(
|
|
7479
|
+
validate(candidate(ranked.profiles[0]?.id, ranked.marked ? "marked_default" : "automatic"))
|
|
7480
|
+
),
|
|
7481
|
+
ranking: {
|
|
7482
|
+
kind: ranked.marked ? "marked_defaults" : "cost_id",
|
|
7483
|
+
tiedProfileIds: ranked.tiedProfileIds
|
|
7484
|
+
}
|
|
7485
|
+
};
|
|
7323
7486
|
} catch (error) {
|
|
7324
7487
|
return {
|
|
7325
7488
|
ok: false,
|
|
@@ -7331,7 +7494,7 @@ function resolveTurn(snapshot, configuration, turnId, mode, existingSelection, o
|
|
|
7331
7494
|
};
|
|
7332
7495
|
}
|
|
7333
7496
|
}
|
|
7334
|
-
function recoverPreparation(snapshot, cause, configuration,
|
|
7497
|
+
function recoverPreparation(snapshot, cause, configuration, currentStart, availability) {
|
|
7335
7498
|
const state = currentStart.state;
|
|
7336
7499
|
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
7500
|
return {
|
|
@@ -7343,22 +7506,12 @@ function recoverPreparation(snapshot, cause, configuration, existingSelection, c
|
|
|
7343
7506
|
};
|
|
7344
7507
|
const profileId = trimToNull2(state.requestedModelProfileId);
|
|
7345
7508
|
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
7509
|
return validateSelection(
|
|
7358
7510
|
snapshot,
|
|
7359
7511
|
configuration.processId,
|
|
7360
7512
|
profileId && provenance ? { modelProfileId: profileId, provenance } : null,
|
|
7361
|
-
availability
|
|
7513
|
+
availability,
|
|
7514
|
+
currentStart.turnId
|
|
7362
7515
|
);
|
|
7363
7516
|
}
|
|
7364
7517
|
|
|
@@ -7579,6 +7732,7 @@ function prepareLaunchPlan(snapshot, launchPlan, opts = {}) {
|
|
|
7579
7732
|
const warnings = [];
|
|
7580
7733
|
const errors = [];
|
|
7581
7734
|
const report = (issue2) => {
|
|
7735
|
+
if (!issue2) return;
|
|
7582
7736
|
if (invalidMode === "reject") errors.push(issue2);
|
|
7583
7737
|
else warnings.push(issue2);
|
|
7584
7738
|
};
|
|
@@ -7588,7 +7742,7 @@ function prepareLaunchPlan(snapshot, launchPlan, opts = {}) {
|
|
|
7588
7742
|
);
|
|
7589
7743
|
if (!parsed.ok) {
|
|
7590
7744
|
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
|
-
|
|
7745
|
+
errors.push(issue(parsed.error.code, message));
|
|
7592
7746
|
}
|
|
7593
7747
|
const baseConfig = {
|
|
7594
7748
|
defaultModelProfileId: launchPlan.processInput.defaultModelProfileId ?? null,
|
|
@@ -7603,26 +7757,26 @@ function prepareLaunchPlan(snapshot, launchPlan, opts = {}) {
|
|
|
7603
7757
|
const policy = snapshot.processesById.get(launchPlan.processId);
|
|
7604
7758
|
const llmTurns = policy?.llmTurnIds ?? /* @__PURE__ */ new Set();
|
|
7605
7759
|
const validTurns = {};
|
|
7606
|
-
|
|
7760
|
+
const defaultModelProfileId = normalized.defaultModelProfileId ?? null;
|
|
7607
7761
|
const modelIssue = (profileId, modelTarget) => {
|
|
7608
7762
|
if (!profileId) return null;
|
|
7609
|
-
const result = validateSelection(
|
|
7610
|
-
|
|
7611
|
-
|
|
7612
|
-
|
|
7763
|
+
const result = validateSelection(
|
|
7764
|
+
snapshot,
|
|
7765
|
+
launchPlan.processId,
|
|
7766
|
+
{
|
|
7767
|
+
modelProfileId: profileId,
|
|
7768
|
+
provenance: { kind: "explicit", source: "instance_default" }
|
|
7769
|
+
},
|
|
7770
|
+
void 0,
|
|
7771
|
+
modelTarget.kind === "default_model" ? void 0 : modelTarget.turnId ?? void 0
|
|
7772
|
+
);
|
|
7613
7773
|
return result.ok ? null : issueForPolicy(result, launchPlan.processId, modelTarget);
|
|
7614
7774
|
};
|
|
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;
|
|
7775
|
+
report(modelIssue(defaultModelProfileId, target("default_model")));
|
|
7622
7776
|
for (const [turnId, config] of Object.entries(normalized.turnConfigs ?? {})) {
|
|
7623
7777
|
const profileId = config.modelProfileId?.trim() || null;
|
|
7624
7778
|
if (!llmTurns.has(turnId)) {
|
|
7625
|
-
|
|
7779
|
+
errors.push(
|
|
7626
7780
|
issue(
|
|
7627
7781
|
"unknown_llm_turn",
|
|
7628
7782
|
`Turn '${turnId}' is not a known LLM turn for process '${launchPlan.processId}'`
|
|
@@ -7630,40 +7784,37 @@ function prepareLaunchPlan(snapshot, launchPlan, opts = {}) {
|
|
|
7630
7784
|
);
|
|
7631
7785
|
continue;
|
|
7632
7786
|
}
|
|
7633
|
-
if (profileId
|
|
7787
|
+
if (profileId) {
|
|
7788
|
+
report(modelIssue(profileId, target("turn_model", turnId)));
|
|
7634
7789
|
validTurns[turnId] = { modelProfileId: profileId };
|
|
7635
7790
|
}
|
|
7636
7791
|
}
|
|
7637
7792
|
const selectedTurnId = launchPlan.startTurnId ?? launchPlan.processInput.selectedTurnId;
|
|
7638
|
-
const
|
|
7639
|
-
|
|
7640
|
-
const selectedTurnIssue = !selectedProfileId ? null : !selectedTurnId ? issue(
|
|
7793
|
+
const selectedModelProfileId = launchPlan.processInput.selectedTurnModelProfileId?.trim() || null;
|
|
7794
|
+
const selectedTurnIssue = !selectedModelProfileId ? null : !selectedTurnId ? issue(
|
|
7641
7795
|
"selected_turn_model_requires_selected_turn",
|
|
7642
|
-
`Selected turn model profile '${
|
|
7796
|
+
`Selected turn model profile '${selectedModelProfileId}' requires a selected turn`
|
|
7643
7797
|
) : !llmTurns.has(selectedTurnId) ? issue(
|
|
7644
7798
|
"selected_turn_model_requires_llm_turn",
|
|
7645
|
-
`Selected turn model profile '${
|
|
7646
|
-
) : modelIssue(
|
|
7647
|
-
|
|
7648
|
-
report(selectedTurnIssue);
|
|
7649
|
-
if (invalidMode !== "reject") selectedModelProfileId = null;
|
|
7650
|
-
}
|
|
7799
|
+
`Selected turn model profile '${selectedModelProfileId}' requires selected turn '${selectedTurnId}' to be an LLM turn`
|
|
7800
|
+
) : modelIssue(selectedModelProfileId, target("selected_turn_model", selectedTurnId));
|
|
7801
|
+
report(selectedTurnIssue);
|
|
7651
7802
|
const modelConfig = { defaultModelProfileId, turnConfigs: validTurns };
|
|
7652
7803
|
let initialDefaultModelProfileId = null;
|
|
7653
7804
|
const configuration = modelConfigurationFromLaunchInput(launchPlan.processId, modelConfig);
|
|
7654
7805
|
const defaultResult = resolveDefault(snapshot, configuration);
|
|
7655
7806
|
if (defaultResult.ok)
|
|
7656
7807
|
initialDefaultModelProfileId = defaultResult.selection?.modelProfileId ?? null;
|
|
7657
|
-
if (selectedTurnId && !selectedModelProfileId) {
|
|
7808
|
+
if (selectedTurnId && !selectedModelProfileId && errors.length === 0 && warnings.length === 0) {
|
|
7658
7809
|
const turnResult = resolveTurn(
|
|
7659
7810
|
snapshot,
|
|
7660
7811
|
configuration,
|
|
7661
7812
|
selectedTurnId,
|
|
7662
|
-
|
|
7813
|
+
false,
|
|
7663
7814
|
{ kind: "none" },
|
|
7664
7815
|
{ kind: "inherit" }
|
|
7665
7816
|
);
|
|
7666
|
-
if (!turnResult.ok
|
|
7817
|
+
if (!turnResult.ok) {
|
|
7667
7818
|
report(
|
|
7668
7819
|
issueForPolicy(
|
|
7669
7820
|
turnResult,
|
|
@@ -7705,6 +7856,7 @@ function prepareLaunchPlan(snapshot, launchPlan, opts = {}) {
|
|
|
7705
7856
|
|
|
7706
7857
|
// src/process-model-policy/project.ts
|
|
7707
7858
|
import { trimToNull as trimToNull5 } from "@leitwerk-dev/domain";
|
|
7859
|
+
import { compareModelProfileIds as compareModelProfileIds3, modelCostRank as modelCostRank2 } from "@leitwerk-dev/protocol";
|
|
7708
7860
|
|
|
7709
7861
|
// src/process-model-policy-presenter.ts
|
|
7710
7862
|
function presentLaunchPlanPreparationIssues(issues) {
|
|
@@ -7716,11 +7868,11 @@ function presentLaunchPlanPreparationIssues(issues) {
|
|
|
7716
7868
|
function presentProcessModelPolicyFailure(failure) {
|
|
7717
7869
|
switch (failure.code) {
|
|
7718
7870
|
case "model_required":
|
|
7719
|
-
return
|
|
7871
|
+
return `No model satisfies this turn's requirements${failure.requirements?.length ? `: ${failure.requirements.map((layer) => `${layer.origin} ${JSON.stringify(layer.requirements)}`).join("; ")}` : ""}`;
|
|
7720
7872
|
case "unknown_model_profile":
|
|
7721
7873
|
return `Unknown model profile '${failure.modelProfileId}'`;
|
|
7722
7874
|
case "model_profile_not_allowed":
|
|
7723
|
-
return `Model profile '${failure.modelProfileId}' is not allowed for process '${failure.processId}'`;
|
|
7875
|
+
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
7876
|
case "model_stale":
|
|
7725
7877
|
return failure.reason ?? "Model status has not been refreshed";
|
|
7726
7878
|
case "model_unavailable":
|
|
@@ -7735,6 +7887,9 @@ function presentModelProfileOption(profile) {
|
|
|
7735
7887
|
const thinkingLevel = profile.thinkingLevel.trim();
|
|
7736
7888
|
return {
|
|
7737
7889
|
id: profile.id,
|
|
7890
|
+
...profile.policyReason ? { policyReason: profile.policyReason } : {},
|
|
7891
|
+
labels: profile.labels ?? [],
|
|
7892
|
+
default: profile.default ?? false,
|
|
7738
7893
|
label: `${profile.id} \u2014 ${profile.providerId}/${profile.modelId}`,
|
|
7739
7894
|
description: thinkingLevel && thinkingLevel.toLowerCase() !== "off" ? `Thinking level: ${thinkingLevel}` : "Thinking disabled",
|
|
7740
7895
|
availability: profile.availability,
|
|
@@ -7742,9 +7897,16 @@ function presentModelProfileOption(profile) {
|
|
|
7742
7897
|
checkedAt: profile.checkedAt
|
|
7743
7898
|
};
|
|
7744
7899
|
}
|
|
7900
|
+
function presentProfileMap(profiles = {}) {
|
|
7901
|
+
return Object.fromEntries(
|
|
7902
|
+
Object.entries(profiles).map(([id, options]) => [id, options.map(presentModelProfileOption)])
|
|
7903
|
+
);
|
|
7904
|
+
}
|
|
7745
7905
|
function presentLauncherModelConfigSchema(projection) {
|
|
7746
7906
|
return {
|
|
7747
7907
|
availableProfiles: projection.profiles.map(presentModelProfileOption),
|
|
7908
|
+
profilesByTurn: presentProfileMap(projection.profilesByTurn),
|
|
7909
|
+
excludedProfiles: presentProfileMap(projection.excludedProfiles),
|
|
7748
7910
|
llmTurns: projection.turns.map((turn) => ({ ...turn }))
|
|
7749
7911
|
};
|
|
7750
7912
|
}
|
|
@@ -7758,6 +7920,7 @@ function presentLauncherModelConfigPreview(projection) {
|
|
|
7758
7920
|
turnId: turn.turnId,
|
|
7759
7921
|
description: turn.description,
|
|
7760
7922
|
effective: {
|
|
7923
|
+
...turn.effective.explanation ? { explanation: turn.effective.explanation } : {},
|
|
7761
7924
|
...turn.effective.error ? { error: turn.effective.error } : {},
|
|
7762
7925
|
source: turn.effective.source,
|
|
7763
7926
|
profile: turn.effective.profile ? presentModelProfileOption(turn.effective.profile) : null
|
|
@@ -7768,6 +7931,8 @@ function presentLauncherModelConfigPreview(projection) {
|
|
|
7768
7931
|
function presentProcessModelConfiguration(projection) {
|
|
7769
7932
|
return {
|
|
7770
7933
|
state: projection.state,
|
|
7934
|
+
excludedProfiles: presentProfileMap(projection.excludedProfiles),
|
|
7935
|
+
profilesByTurn: presentProfileMap(projection.profilesByTurn),
|
|
7771
7936
|
availableProfiles: projection.profiles.map(presentModelProfileOption),
|
|
7772
7937
|
effectiveSelectedTurn: projection.effectiveSelectedTurn,
|
|
7773
7938
|
defaultModel: projection.defaultModel,
|
|
@@ -7776,24 +7941,6 @@ function presentProcessModelConfiguration(projection) {
|
|
|
7776
7941
|
}
|
|
7777
7942
|
|
|
7778
7943
|
// 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
7944
|
function defaultProjection(snapshot, configuration) {
|
|
7798
7945
|
const policy = snapshot.processesById.get(configuration.processId);
|
|
7799
7946
|
const { selection } = resolveDefault(snapshot, configuration);
|
|
@@ -7806,21 +7953,63 @@ function defaultProjection(snapshot, configuration) {
|
|
|
7806
7953
|
}
|
|
7807
7954
|
function projectPolicy(snapshot, request) {
|
|
7808
7955
|
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;
|
|
7956
|
+
const policy = snapshot.processesById.get(processId);
|
|
7957
|
+
const targetTurnId = "target" in request && request.target.kind === "turn" ? request.target.turnId : void 0;
|
|
7815
7958
|
if (request.kind === "compatible_profiles") {
|
|
7816
|
-
const allowedProfileIds = new Set(profiles.map((profile) => profile.id));
|
|
7817
7959
|
return snapshot.profiles.filter(
|
|
7818
|
-
(profile) => profile.provider === request.providerId && profile.modelId === request.modelId &&
|
|
7960
|
+
(profile) => profile.provider === request.providerId && profile.modelId === request.modelId && (!policy || !profileRejections(policy, profile, targetTurnId).length)
|
|
7819
7961
|
).map((profile) => profile.id);
|
|
7820
7962
|
}
|
|
7821
|
-
const
|
|
7963
|
+
const catalog = [...snapshot.profiles].sort(
|
|
7964
|
+
(a, b) => modelCostRank2(a.labels) - modelCostRank2(b.labels) || compareModelProfileIds3(a.id, b.id)
|
|
7965
|
+
).map((profile) => {
|
|
7966
|
+
const status = request.availability?.profiles.find(
|
|
7967
|
+
(candidate2) => candidate2.profileId === profile.id
|
|
7968
|
+
);
|
|
7969
|
+
return {
|
|
7970
|
+
source: profile,
|
|
7971
|
+
id: profile.id,
|
|
7972
|
+
providerId: profile.provider,
|
|
7973
|
+
modelId: profile.modelId,
|
|
7974
|
+
thinkingLevel: profile.thinkingLevel,
|
|
7975
|
+
labels: profile.labels,
|
|
7976
|
+
default: profile.default,
|
|
7977
|
+
availability: status?.availability ?? "stale",
|
|
7978
|
+
safeReason: status?.safeReason ?? null,
|
|
7979
|
+
checkedAt: status?.checkedAt ?? null
|
|
7980
|
+
};
|
|
7981
|
+
});
|
|
7982
|
+
const projectProfiles = (turnId) => {
|
|
7983
|
+
const projected = catalog.map(({ source, ...option }) => {
|
|
7984
|
+
const rejections = policy ? profileRejections(policy, source, turnId) : [];
|
|
7985
|
+
return {
|
|
7986
|
+
...option,
|
|
7987
|
+
policyReason: rejections.map((r) => `${r.code} (${r.values.join(", ")}) from ${r.origin}`).join("; ") || void 0
|
|
7988
|
+
};
|
|
7989
|
+
});
|
|
7990
|
+
return {
|
|
7991
|
+
profiles: projected.filter((profile) => !profile.policyReason),
|
|
7992
|
+
excludedProfiles: projected.filter((profile) => profile.policyReason)
|
|
7993
|
+
};
|
|
7994
|
+
};
|
|
7995
|
+
const processProfiles = projectProfiles(targetTurnId);
|
|
7996
|
+
const { profiles } = processProfiles;
|
|
7997
|
+
if (request.kind === "profile_options") return profiles;
|
|
7998
|
+
const profileMaps = () => {
|
|
7999
|
+
const turns2 = [...policy?.llmTurnIds ?? []].map(
|
|
8000
|
+
(turnId) => [turnId, projectProfiles(turnId)]
|
|
8001
|
+
);
|
|
8002
|
+
return {
|
|
8003
|
+
profilesByTurn: Object.fromEntries(turns2.map(([id, value]) => [id, value.profiles])),
|
|
8004
|
+
excludedProfiles: Object.fromEntries([
|
|
8005
|
+
["", processProfiles.excludedProfiles],
|
|
8006
|
+
...turns2.map(([id, value]) => [id, value.excludedProfiles])
|
|
8007
|
+
])
|
|
8008
|
+
};
|
|
8009
|
+
};
|
|
7822
8010
|
if (request.kind === "launcher_schema") {
|
|
7823
8011
|
return {
|
|
8012
|
+
...profileMaps(),
|
|
7824
8013
|
profiles,
|
|
7825
8014
|
turns: [...policy?.llmTurnIds ?? []].map((turnId) => ({
|
|
7826
8015
|
turnId,
|
|
@@ -7851,13 +8040,15 @@ function projectPolicy(snapshot, request) {
|
|
|
7851
8040
|
snapshot,
|
|
7852
8041
|
configuration,
|
|
7853
8042
|
turnId,
|
|
7854
|
-
|
|
8043
|
+
false,
|
|
7855
8044
|
{ kind: "none" },
|
|
7856
8045
|
{ kind: "inherit" },
|
|
7857
8046
|
request.availability
|
|
7858
8047
|
);
|
|
7859
8048
|
return {
|
|
7860
8049
|
turnId,
|
|
8050
|
+
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,
|
|
8051
|
+
ranking: resolved2.ranking,
|
|
7861
8052
|
effectiveModelProfileId: resolved2.selection?.modelProfileId ?? null,
|
|
7862
8053
|
effectiveSource: resolved2.selection?.provenance.source ?? "none",
|
|
7863
8054
|
...!resolved2.ok ? { effectiveError: presentProcessModelPolicyFailure(resolved2) } : {},
|
|
@@ -7871,7 +8062,9 @@ function projectPolicy(snapshot, request) {
|
|
|
7871
8062
|
};
|
|
7872
8063
|
});
|
|
7873
8064
|
if (request.kind === "launcher_preview") {
|
|
7874
|
-
const profilesById = new Map(
|
|
8065
|
+
const profilesById = new Map(
|
|
8066
|
+
catalog.map(({ source: _source, ...profile }) => [profile.id, profile])
|
|
8067
|
+
);
|
|
7875
8068
|
return {
|
|
7876
8069
|
defaultModel: {
|
|
7877
8070
|
source: defaultModel.source,
|
|
@@ -7881,7 +8074,9 @@ function projectPolicy(snapshot, request) {
|
|
|
7881
8074
|
turnId: turn.turnId,
|
|
7882
8075
|
description: turn.description,
|
|
7883
8076
|
effective: {
|
|
7884
|
-
|
|
8077
|
+
explanation: turn.explanation,
|
|
8078
|
+
ranking: turn.ranking,
|
|
8079
|
+
source: turn.effectiveSource,
|
|
7885
8080
|
...turn.effectiveError ? { error: turn.effectiveError } : {},
|
|
7886
8081
|
profile: profilesById.get(turn.effectiveModelProfileId ?? "") ?? null
|
|
7887
8082
|
}
|
|
@@ -7891,6 +8086,7 @@ function projectPolicy(snapshot, request) {
|
|
|
7891
8086
|
const selectedTurn = existingTurnSelectionFromProcess(request.process);
|
|
7892
8087
|
return {
|
|
7893
8088
|
state: { kind: "ready" },
|
|
8089
|
+
...profileMaps(),
|
|
7894
8090
|
profiles,
|
|
7895
8091
|
defaultModel,
|
|
7896
8092
|
turns,
|
|
@@ -7919,19 +8115,13 @@ async function evaluateAtStableAvailabilityRevision(input) {
|
|
|
7919
8115
|
}
|
|
7920
8116
|
|
|
7921
8117
|
// 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
8118
|
function evaluateSubject(snapshot, request) {
|
|
7929
8119
|
if (request.kind === "process_turn") {
|
|
7930
8120
|
return resolveTurn(
|
|
7931
8121
|
snapshot,
|
|
7932
8122
|
modelConfigurationFromProcess(request.process),
|
|
7933
8123
|
request.turnId,
|
|
7934
|
-
|
|
8124
|
+
request.initialSelection === true || request.startKind === "retry" || request.startKind === "startup_retry" || request.startKind === "continue",
|
|
7935
8125
|
existingTurnSelectionFromProcess(request.process),
|
|
7936
8126
|
modelOverride(
|
|
7937
8127
|
request.modelOverride,
|
|
@@ -7951,20 +8141,25 @@ function evaluateSubject(snapshot, request) {
|
|
|
7951
8141
|
turnConfigsJson: request.plan.processInput.turnConfigsJson
|
|
7952
8142
|
}),
|
|
7953
8143
|
request.turnId,
|
|
7954
|
-
|
|
8144
|
+
false,
|
|
7955
8145
|
{ kind: "none" },
|
|
7956
8146
|
modelOverride(selected, selected !== null, "launch_override"),
|
|
7957
8147
|
request.availability
|
|
7958
8148
|
);
|
|
7959
8149
|
}
|
|
7960
8150
|
if (request.kind === "runtime_selection") {
|
|
7961
|
-
return validateSelection(
|
|
8151
|
+
return validateSelection(
|
|
8152
|
+
snapshot,
|
|
8153
|
+
request.processId,
|
|
8154
|
+
request.selection,
|
|
8155
|
+
request.availability,
|
|
8156
|
+
request.target.kind === "turn" ? request.target.turnId : void 0
|
|
8157
|
+
);
|
|
7962
8158
|
}
|
|
7963
8159
|
return recoverPreparation(
|
|
7964
8160
|
snapshot,
|
|
7965
8161
|
request.cause,
|
|
7966
8162
|
modelConfigurationFromProcess(request.process),
|
|
7967
|
-
existingTurnSelectionFromProcess(request.process),
|
|
7968
8163
|
request.currentStart,
|
|
7969
8164
|
request.availability
|
|
7970
8165
|
);
|
|
@@ -8902,10 +9097,7 @@ function buildRuntimeProfileSelectionInput(args) {
|
|
|
8902
9097
|
|
|
8903
9098
|
// src/process-engine/turn-start-preflight.ts
|
|
8904
9099
|
import { VERSION as PI_RUNTIME_VERSION } from "@earendil-works/pi-coding-agent";
|
|
8905
|
-
import {
|
|
8906
|
-
filterProviderOptionsForDefinition,
|
|
8907
|
-
resolveOutcomeContract
|
|
8908
|
-
} from "@leitwerk-dev/process-sdk";
|
|
9100
|
+
import { resolveOutcomeContract } from "@leitwerk-dev/process-sdk";
|
|
8909
9101
|
import { IPC_PROTOCOL_VERSION, WORKER_API_VERSION } from "@leitwerk-dev/worker-protocol";
|
|
8910
9102
|
|
|
8911
9103
|
// src/model-providers/provider-options.ts
|
|
@@ -9092,7 +9284,21 @@ async function prepareCreatedTurnStarts(deps, process2, writes, explicitProvider
|
|
|
9092
9284
|
};
|
|
9093
9285
|
}
|
|
9094
9286
|
}
|
|
9095
|
-
const
|
|
9287
|
+
const priorState = write.input.state;
|
|
9288
|
+
const captured = priorState.automaticRetry ? priorState.kind === "preparation_failed" ? priorState.requestedModelProfileId && priorState.modelSelectionProvenance ? {
|
|
9289
|
+
modelProfileId: priorState.requestedModelProfileId,
|
|
9290
|
+
provenance: priorState.modelSelectionProvenance
|
|
9291
|
+
} : null : priorState.kind === "starting" && priorState.start.kind === "llm" && priorState.start.modelSelectionProvenance ? {
|
|
9292
|
+
modelProfileId: priorState.start.model.profileId,
|
|
9293
|
+
provenance: priorState.start.modelSelectionProvenance
|
|
9294
|
+
} : null : null;
|
|
9295
|
+
const evaluated = captured ? deps.processModelPolicy.evaluate({
|
|
9296
|
+
kind: "runtime_selection",
|
|
9297
|
+
target: { kind: "turn", turnId: write.input.turnId },
|
|
9298
|
+
processId: nextProcess.processId,
|
|
9299
|
+
selection: captured,
|
|
9300
|
+
availability
|
|
9301
|
+
}) : deps.processModelPolicy.evaluate({
|
|
9096
9302
|
kind: "process_turn",
|
|
9097
9303
|
process: nextProcess,
|
|
9098
9304
|
turnId: write.input.turnId,
|
|
@@ -9121,6 +9327,7 @@ async function prepareCreatedTurnStarts(deps, process2, writes, explicitProvider
|
|
|
9121
9327
|
Object.assign(nextProcess, patch);
|
|
9122
9328
|
Object.assign(writes.processPatch, patch);
|
|
9123
9329
|
}
|
|
9330
|
+
if (captured && priorState.kind === "starting") continue;
|
|
9124
9331
|
const provenance = nextProcess.selectedTurnModelKind && nextProcess.selectedTurnModelSource ? {
|
|
9125
9332
|
kind: nextProcess.selectedTurnModelKind,
|
|
9126
9333
|
source: nextProcess.selectedTurnModelSource
|
|
@@ -9168,9 +9375,7 @@ async function prepareCreatedTurnStarts(deps, process2, writes, explicitProvider
|
|
|
9168
9375
|
}
|
|
9169
9376
|
const provider = deps.registry.require(profile.provider);
|
|
9170
9377
|
const retainedProviderId = previousProviderId(deps, retainedState);
|
|
9171
|
-
const recoveryOptions = explicitProviderOptions ? { ...explicitProviderOptions } : retainedProviderId !== null && retainedProviderId !== provider.id ? {
|
|
9172
|
-
...filterProviderOptionsForDefinition(provider.definition.options, retainedOptions)
|
|
9173
|
-
} : retainedOptions;
|
|
9378
|
+
const recoveryOptions = explicitProviderOptions ? { ...explicitProviderOptions } : retainedProviderId !== null && retainedProviderId !== provider.id ? {} : retainedOptions;
|
|
9174
9379
|
const optionResult = resolveRegisteredProviderOptions({
|
|
9175
9380
|
provider,
|
|
9176
9381
|
explicit: recoveryOptions,
|
|
@@ -13179,6 +13384,8 @@ function createBroadcaster() {
|
|
|
13179
13384
|
}
|
|
13180
13385
|
|
|
13181
13386
|
export {
|
|
13387
|
+
__using,
|
|
13388
|
+
__callDispose,
|
|
13182
13389
|
resolveApiTokenPolicy,
|
|
13183
13390
|
ApiTokenValidationError,
|
|
13184
13391
|
tokenExpiry,
|
|
@@ -13250,7 +13457,6 @@ export {
|
|
|
13250
13457
|
presentLauncherModelConfigSchema,
|
|
13251
13458
|
presentLauncherModelConfigPreview,
|
|
13252
13459
|
presentProcessModelConfiguration,
|
|
13253
|
-
isPinnedModelSelection,
|
|
13254
13460
|
evaluateAtStableAvailabilityRevision,
|
|
13255
13461
|
createServerProcessModelPolicy,
|
|
13256
13462
|
resolveCurrentExecutionTurnRecordId,
|
|
@@ -13319,4 +13525,4 @@ export {
|
|
|
13319
13525
|
createProjectedSessionSnapshotStore,
|
|
13320
13526
|
createBroadcaster
|
|
13321
13527
|
};
|
|
13322
|
-
//# sourceMappingURL=chunk-
|
|
13528
|
+
//# sourceMappingURL=chunk-65CBLH7U.js.map
|