@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
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { trimToNull } from "@leitwerk-dev/domain";
|
|
2
2
|
import { isLlmTurnDefinition } from "@leitwerk-dev/process-sdk";
|
|
3
|
+
import { assertValidModelRequirements, compareModelProfileIds } from "@leitwerk-dev/protocol";
|
|
3
4
|
import type { LeitwerkConfig } from "../config/config-types.js";
|
|
4
5
|
import type { ProcessActionRegistry } from "../process-action-registry.js";
|
|
5
6
|
import { getProcessGraph, type ProcessGraphRegistry } from "../process-graph.js";
|
|
6
|
-
import type {
|
|
7
|
+
import type {
|
|
8
|
+
PolicyProcess,
|
|
9
|
+
PolicyProfile,
|
|
10
|
+
PolicyRequirementLayer,
|
|
11
|
+
PolicySnapshot,
|
|
12
|
+
} from "./types.js";
|
|
7
13
|
|
|
8
14
|
export interface ProcessModelPolicyConfigurationIssue {
|
|
9
15
|
readonly code: "unknown_llm_turn";
|
|
@@ -25,6 +31,10 @@ export function constructPolicySnapshot(input: {
|
|
|
25
31
|
config: LeitwerkConfig;
|
|
26
32
|
processGraphs: ProcessGraphRegistry;
|
|
27
33
|
processActionRegistry: Pick<ProcessActionRegistry, "getTurnDefinition">;
|
|
34
|
+
capabilities?: (
|
|
35
|
+
providerId: string,
|
|
36
|
+
modelId: string,
|
|
37
|
+
) => Readonly<Record<string, boolean | "unknown">>;
|
|
28
38
|
}): PolicySnapshot {
|
|
29
39
|
const configSnapshot = structuredClone(input.config);
|
|
30
40
|
const profiles: PolicyProfile[] = configSnapshot.pi.model_profiles.map((profile) => ({
|
|
@@ -33,6 +43,9 @@ export function constructPolicySnapshot(input: {
|
|
|
33
43
|
modelId: profile.model_id,
|
|
34
44
|
thinkingLevel: profile.thinking_level ?? "off",
|
|
35
45
|
providerOptions: profile.provider_options ?? {},
|
|
46
|
+
labels: [...new Set(profile.labels ?? [])].sort(compareModelProfileIds),
|
|
47
|
+
default: profile.default ?? false,
|
|
48
|
+
capabilities: structuredClone(input.capabilities?.(profile.provider, profile.model_id) ?? {}),
|
|
36
49
|
}));
|
|
37
50
|
const processIds = new Set([
|
|
38
51
|
...input.processGraphs.keys(),
|
|
@@ -44,12 +57,50 @@ export function constructPolicySnapshot(input: {
|
|
|
44
57
|
? getProcessGraph(input.processGraphs, processId)
|
|
45
58
|
: null;
|
|
46
59
|
const config = configSnapshot.process_configs?.[processId];
|
|
60
|
+
const requirements: PolicyRequirementLayer[] = [];
|
|
61
|
+
const turnRequirements: Record<string, PolicyRequirementLayer[]> = {};
|
|
62
|
+
const add = (
|
|
63
|
+
layers: PolicyRequirementLayer[],
|
|
64
|
+
origin: string,
|
|
65
|
+
value: import("@leitwerk-dev/protocol").ModelRequirements | undefined,
|
|
66
|
+
) => {
|
|
67
|
+
if (value === undefined) return;
|
|
68
|
+
assertValidModelRequirements(value);
|
|
69
|
+
layers.push({ origin, requirements: structuredClone(value) });
|
|
70
|
+
};
|
|
71
|
+
add(
|
|
72
|
+
requirements,
|
|
73
|
+
`process:${processId}`,
|
|
74
|
+
input.processGraphs.get(processId)?.modelRequirements,
|
|
75
|
+
);
|
|
76
|
+
add(
|
|
77
|
+
requirements,
|
|
78
|
+
`process_configs.${processId}.model_requirements`,
|
|
79
|
+
config?.model_requirements,
|
|
80
|
+
);
|
|
47
81
|
const llmTurnIds = new Set<string>();
|
|
48
82
|
const purposeProfileIdsByTurn: Record<string, string> = {};
|
|
49
83
|
const descriptions: Record<string, string> = {};
|
|
50
84
|
const pathTypes: Record<string, string> = {};
|
|
51
85
|
for (const [turnId, turn] of graph?.turns ?? []) {
|
|
52
|
-
|
|
86
|
+
const declared = input.processGraphs.get(processId)?.turns.get(turnId)?.definition;
|
|
87
|
+
if (turn.turnType !== "llm") {
|
|
88
|
+
if (declared && "modelRequirements" in declared)
|
|
89
|
+
throw new Error(`Model requirements require an LLM turn: ${processId}/${turnId}`);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const layers: PolicyRequirementLayer[] = [];
|
|
93
|
+
add(
|
|
94
|
+
layers,
|
|
95
|
+
`turn:${processId}/${turnId}`,
|
|
96
|
+
declared?.kind === "llm" ? declared.modelRequirements : undefined,
|
|
97
|
+
);
|
|
98
|
+
add(
|
|
99
|
+
layers,
|
|
100
|
+
`process_configs.${processId}.turn_configs.${turnId}.model_requirements`,
|
|
101
|
+
config?.turn_configs?.[turnId]?.model_requirements,
|
|
102
|
+
);
|
|
103
|
+
turnRequirements[turnId] = layers;
|
|
53
104
|
llmTurnIds.add(turnId);
|
|
54
105
|
const definition = input.processActionRegistry.getTurnDefinition(processId, turnId);
|
|
55
106
|
pathTypes[turnId] =
|
|
@@ -70,6 +121,8 @@ export function constructPolicySnapshot(input: {
|
|
|
70
121
|
: null;
|
|
71
122
|
processesById.set(processId, {
|
|
72
123
|
id: processId,
|
|
124
|
+
requirements,
|
|
125
|
+
turnRequirements,
|
|
73
126
|
allowedProfileIds: allowed,
|
|
74
127
|
defaultProfileId: trimToNull(config?.default_model_profile),
|
|
75
128
|
turnProfileIds: Object.fromEntries(
|
|
@@ -101,7 +154,12 @@ export function constructPolicySnapshot(input: {
|
|
|
101
154
|
profilesById: new Map(profiles.map((profile) => [profile.id, profile])),
|
|
102
155
|
processesById,
|
|
103
156
|
workerStaticConfig: {
|
|
104
|
-
pi:
|
|
157
|
+
pi: {
|
|
158
|
+
...configSnapshot.pi,
|
|
159
|
+
model_profiles: configSnapshot.pi.model_profiles
|
|
160
|
+
.map(({ labels: _labels, default: _default, ...profile }) => profile)
|
|
161
|
+
.sort((a, b) => compareModelProfileIds(a.id, b.id)),
|
|
162
|
+
},
|
|
105
163
|
workers: configSnapshot.workers,
|
|
106
164
|
processPi: Object.fromEntries(
|
|
107
165
|
Object.entries(configSnapshot.process_configs ?? {}).map(([id, value]) => [
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DurableModelSelection, TurnStartRecord } from "@leitwerk-dev/domain";
|
|
2
2
|
import { trimToNull } from "@leitwerk-dev/domain";
|
|
3
|
+
import { profileRejections, rankedProfiles, requirementLayers } from "./requirements.js";
|
|
3
4
|
import type {
|
|
4
5
|
ExistingTurnSelection,
|
|
5
6
|
ModelConfiguration,
|
|
@@ -8,6 +9,7 @@ import type {
|
|
|
8
9
|
PolicySnapshot,
|
|
9
10
|
ProcessModelAvailabilitySnapshot,
|
|
10
11
|
ProcessModelPolicyEvaluation,
|
|
12
|
+
SkippedModelPreference,
|
|
11
13
|
ValidModelConfiguration,
|
|
12
14
|
} from "./types.js";
|
|
13
15
|
import { isPinnedModelSelection, provenanceKindForSource } from "./types.js";
|
|
@@ -16,6 +18,8 @@ function processPolicy(snapshot: PolicySnapshot, processId: string): PolicyProce
|
|
|
16
18
|
return (
|
|
17
19
|
snapshot.processesById.get(processId) ?? {
|
|
18
20
|
id: processId,
|
|
21
|
+
requirements: [],
|
|
22
|
+
turnRequirements: {},
|
|
19
23
|
allowedProfileIds: null,
|
|
20
24
|
defaultProfileId: null,
|
|
21
25
|
turnProfileIds: {},
|
|
@@ -32,6 +36,7 @@ export function validateSelection(
|
|
|
32
36
|
processId: string,
|
|
33
37
|
selection: DurableModelSelection | null,
|
|
34
38
|
availability?: ProcessModelAvailabilitySnapshot,
|
|
39
|
+
turnId?: string,
|
|
35
40
|
): ProcessModelPolicyEvaluation {
|
|
36
41
|
if (!selection)
|
|
37
42
|
return {
|
|
@@ -50,12 +55,14 @@ export function validateSelection(
|
|
|
50
55
|
...(availability ? { availabilityRevision: availability.revision } : {}),
|
|
51
56
|
};
|
|
52
57
|
const policy = processPolicy(snapshot, processId);
|
|
53
|
-
|
|
58
|
+
const rejections = profileRejections(policy, profile, turnId);
|
|
59
|
+
if (rejections.length)
|
|
54
60
|
return {
|
|
55
61
|
ok: false,
|
|
56
62
|
code: "model_profile_not_allowed",
|
|
57
63
|
modelProfileId: profile.id,
|
|
58
64
|
processId,
|
|
65
|
+
rejections,
|
|
59
66
|
selection,
|
|
60
67
|
...(availability ? { availabilityRevision: availability.revision } : {}),
|
|
61
68
|
};
|
|
@@ -87,7 +94,10 @@ function candidate(
|
|
|
87
94
|
| "instance_default"
|
|
88
95
|
| "process_config_default"
|
|
89
96
|
| "catalog_default"
|
|
90
|
-
| "scoped_purpose_default"
|
|
97
|
+
| "scoped_purpose_default"
|
|
98
|
+
| "marked_default"
|
|
99
|
+
| "automatic"
|
|
100
|
+
| "fixed_purpose",
|
|
91
101
|
): DurableModelSelection | null {
|
|
92
102
|
const id = trimToNull(modelProfileId);
|
|
93
103
|
return id
|
|
@@ -120,26 +130,6 @@ export function resolveDefault(
|
|
|
120
130
|
);
|
|
121
131
|
}
|
|
122
132
|
|
|
123
|
-
function resolveInherited(
|
|
124
|
-
snapshot: PolicySnapshot,
|
|
125
|
-
configuration: ValidModelConfiguration,
|
|
126
|
-
turnId: string,
|
|
127
|
-
): DurableModelSelection | null {
|
|
128
|
-
const policy = processPolicy(snapshot, configuration.processId);
|
|
129
|
-
const instanceTurn = candidate(configuration.turnProfileIds.get(turnId), "instance_turn_config");
|
|
130
|
-
if (instanceTurn) return instanceTurn;
|
|
131
|
-
const instanceDefault = candidate(configuration.defaultProfileId, "instance_default");
|
|
132
|
-
if (instanceDefault) return instanceDefault;
|
|
133
|
-
const scopedDefault = candidate(
|
|
134
|
-
policy.scopedProfileIdForTurn?.(turnId),
|
|
135
|
-
"scoped_purpose_default",
|
|
136
|
-
);
|
|
137
|
-
if (scopedDefault) return scopedDefault;
|
|
138
|
-
const processTurn = candidate(policy.turnProfileIds[turnId], "process_config_turn");
|
|
139
|
-
if (processTurn) return processTurn;
|
|
140
|
-
return resolvedDefault(snapshot, configuration);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
133
|
function invalidConfiguration(
|
|
144
134
|
configuration: Extract<ModelConfiguration, { kind: "invalid" }>,
|
|
145
135
|
): ProcessModelPolicyEvaluation {
|
|
@@ -156,7 +146,7 @@ export function resolveTurn(
|
|
|
156
146
|
snapshot: PolicySnapshot,
|
|
157
147
|
configuration: ModelConfiguration,
|
|
158
148
|
turnId: string,
|
|
159
|
-
|
|
149
|
+
preservePinnedSelection: boolean,
|
|
160
150
|
existingSelection: ExistingTurnSelection,
|
|
161
151
|
override: ModelOverride,
|
|
162
152
|
availability?: ProcessModelAvailabilitySnapshot,
|
|
@@ -164,15 +154,11 @@ export function resolveTurn(
|
|
|
164
154
|
const policy = processPolicy(snapshot, configuration.processId);
|
|
165
155
|
if (!policy.llmTurnIds.has(turnId)) return { ok: true, selection: null };
|
|
166
156
|
if (configuration.kind === "invalid") return invalidConfiguration(configuration);
|
|
157
|
+
const validate = (selection: DurableModelSelection | null) =>
|
|
158
|
+
validateSelection(snapshot, configuration.processId, selection, availability, turnId);
|
|
167
159
|
// A configured code-defined purpose is authoritative over launch/action overrides.
|
|
168
160
|
const purposeProfileId = policy.purposeProfileIdsByTurn[turnId];
|
|
169
|
-
if (purposeProfileId)
|
|
170
|
-
return validateSelection(
|
|
171
|
-
snapshot,
|
|
172
|
-
configuration.processId,
|
|
173
|
-
candidate(purposeProfileId, "process_config_default"),
|
|
174
|
-
availability,
|
|
175
|
-
);
|
|
161
|
+
if (purposeProfileId) return validate(candidate(purposeProfileId, "fixed_purpose"));
|
|
176
162
|
if (existingSelection.kind === "invalid" && existingSelection.turnId === turnId)
|
|
177
163
|
return {
|
|
178
164
|
ok: false,
|
|
@@ -186,34 +172,68 @@ export function resolveTurn(
|
|
|
186
172
|
existingSelection = { kind: "none" };
|
|
187
173
|
}
|
|
188
174
|
if (override.kind === "profile")
|
|
189
|
-
return
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
modelProfileId: override.profileId,
|
|
194
|
-
provenance: { kind: "explicit", source: override.source },
|
|
195
|
-
},
|
|
196
|
-
availability,
|
|
197
|
-
);
|
|
175
|
+
return validate({
|
|
176
|
+
modelProfileId: override.profileId,
|
|
177
|
+
provenance: { kind: "explicit", source: override.source },
|
|
178
|
+
});
|
|
198
179
|
if (
|
|
199
180
|
existingSelection.kind === "selected" &&
|
|
200
|
-
|
|
181
|
+
preservePinnedSelection &&
|
|
201
182
|
existingSelection.turnId === turnId &&
|
|
202
183
|
isPinnedModelSelection(existingSelection.selection)
|
|
203
184
|
)
|
|
204
|
-
return
|
|
205
|
-
snapshot,
|
|
206
|
-
configuration.processId,
|
|
207
|
-
existingSelection.selection,
|
|
208
|
-
availability,
|
|
209
|
-
);
|
|
185
|
+
return validate(existingSelection.selection);
|
|
210
186
|
try {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
187
|
+
const skippedPreferences: SkippedModelPreference[] = [];
|
|
188
|
+
const explain = (result: ProcessModelPolicyEvaluation): ProcessModelPolicyEvaluation => ({
|
|
189
|
+
...result,
|
|
190
|
+
skippedPreferences,
|
|
191
|
+
});
|
|
192
|
+
const preferences = [
|
|
193
|
+
() => candidate(configuration.turnProfileIds.get(turnId), "instance_turn_config"),
|
|
194
|
+
() => candidate(configuration.defaultProfileId, "instance_default"),
|
|
195
|
+
() => candidate(policy.scopedProfileIdForTurn?.(turnId), "scoped_purpose_default"),
|
|
196
|
+
() => candidate(policy.turnProfileIds[turnId], "process_config_turn"),
|
|
197
|
+
() => candidate(policy.defaultProfileId, "process_config_default"),
|
|
198
|
+
() => candidate(snapshot.defaultProfileId, "catalog_default"),
|
|
199
|
+
];
|
|
200
|
+
for (const getPreference of preferences) {
|
|
201
|
+
const preference = getPreference();
|
|
202
|
+
if (!preference) continue;
|
|
203
|
+
const result = validate(preference);
|
|
204
|
+
if (
|
|
205
|
+
!result.ok &&
|
|
206
|
+
result.code === "model_profile_not_allowed" &&
|
|
207
|
+
preference.provenance.source !== "instance_turn_config"
|
|
208
|
+
) {
|
|
209
|
+
skippedPreferences.push({
|
|
210
|
+
profileId: preference.modelProfileId,
|
|
211
|
+
source: preference.provenance.source,
|
|
212
|
+
rejections: result.rejections ?? [],
|
|
213
|
+
});
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
return explain(result);
|
|
217
|
+
}
|
|
218
|
+
const ranked = rankedProfiles(policy, snapshot.profiles, turnId);
|
|
219
|
+
if (!ranked.profiles.length)
|
|
220
|
+
return {
|
|
221
|
+
ok: false,
|
|
222
|
+
code: "model_required",
|
|
223
|
+
selection: null,
|
|
224
|
+
skippedPreferences,
|
|
225
|
+
...(availability ? { availabilityRevision: availability.revision } : {}),
|
|
226
|
+
requirements: requirementLayers(policy, turnId),
|
|
227
|
+
};
|
|
228
|
+
return {
|
|
229
|
+
...explain(
|
|
230
|
+
validate(candidate(ranked.profiles[0]?.id, ranked.marked ? "marked_default" : "automatic")),
|
|
231
|
+
),
|
|
232
|
+
ranking: {
|
|
233
|
+
kind: ranked.marked ? "marked_defaults" : "cost_id",
|
|
234
|
+
tiedProfileIds: ranked.tiedProfileIds,
|
|
235
|
+
},
|
|
236
|
+
};
|
|
217
237
|
} catch (error) {
|
|
218
238
|
return {
|
|
219
239
|
ok: false,
|
|
@@ -230,7 +250,6 @@ export function recoverPreparation(
|
|
|
230
250
|
snapshot: PolicySnapshot,
|
|
231
251
|
cause: "availability_transition" | "startup_reconciliation",
|
|
232
252
|
configuration: ModelConfiguration,
|
|
233
|
-
existingSelection: ExistingTurnSelection,
|
|
234
253
|
currentStart: TurnStartRecord,
|
|
235
254
|
availability: ProcessModelAvailabilitySnapshot,
|
|
236
255
|
): ProcessModelPolicyEvaluation {
|
|
@@ -250,21 +269,11 @@ export function recoverPreparation(
|
|
|
250
269
|
};
|
|
251
270
|
const profileId = trimToNull(state.requestedModelProfileId);
|
|
252
271
|
const provenance = state.modelSelectionProvenance;
|
|
253
|
-
if (provenance?.kind === "inherited") {
|
|
254
|
-
return resolveTurn(
|
|
255
|
-
snapshot,
|
|
256
|
-
configuration,
|
|
257
|
-
currentStart.turnId,
|
|
258
|
-
"retry",
|
|
259
|
-
existingSelection,
|
|
260
|
-
{ kind: "inherit" },
|
|
261
|
-
availability,
|
|
262
|
-
);
|
|
263
|
-
}
|
|
264
272
|
return validateSelection(
|
|
265
273
|
snapshot,
|
|
266
274
|
configuration.processId,
|
|
267
275
|
profileId && provenance ? { modelProfileId: profileId, provenance } : null,
|
|
268
276
|
availability,
|
|
277
|
+
currentStart.turnId,
|
|
269
278
|
);
|
|
270
279
|
}
|
|
@@ -53,16 +53,6 @@ export type {
|
|
|
53
53
|
export { isPinnedModelSelection } from "./types.js";
|
|
54
54
|
export { ProcessModelPolicyConfigurationError };
|
|
55
55
|
|
|
56
|
-
function resolutionMode(
|
|
57
|
-
startKind: Extract<ProcessModelPolicyEvaluationSubject, { kind: "process_turn" }>["startKind"],
|
|
58
|
-
initialSelection: boolean | undefined,
|
|
59
|
-
): "resolve" | "initial" | "retry" | "continue" {
|
|
60
|
-
if (startKind === "retry" || startKind === "startup_retry") return "retry";
|
|
61
|
-
if (startKind === "continue") return "continue";
|
|
62
|
-
if (initialSelection) return "initial";
|
|
63
|
-
return "resolve";
|
|
64
|
-
}
|
|
65
|
-
|
|
66
56
|
function evaluateSubject(
|
|
67
57
|
snapshot: PolicySnapshot,
|
|
68
58
|
request: ProcessModelPolicyEvaluationSubject,
|
|
@@ -72,7 +62,10 @@ function evaluateSubject(
|
|
|
72
62
|
snapshot,
|
|
73
63
|
modelConfigurationFromProcess(request.process),
|
|
74
64
|
request.turnId,
|
|
75
|
-
|
|
65
|
+
request.initialSelection === true ||
|
|
66
|
+
request.startKind === "retry" ||
|
|
67
|
+
request.startKind === "startup_retry" ||
|
|
68
|
+
request.startKind === "continue",
|
|
76
69
|
existingTurnSelectionFromProcess(request.process),
|
|
77
70
|
modelOverride(
|
|
78
71
|
request.modelOverride,
|
|
@@ -92,20 +85,25 @@ function evaluateSubject(
|
|
|
92
85
|
turnConfigsJson: request.plan.processInput.turnConfigsJson,
|
|
93
86
|
}),
|
|
94
87
|
request.turnId,
|
|
95
|
-
|
|
88
|
+
false,
|
|
96
89
|
{ kind: "none" },
|
|
97
90
|
modelOverride(selected, selected !== null, "launch_override"),
|
|
98
91
|
request.availability,
|
|
99
92
|
);
|
|
100
93
|
}
|
|
101
94
|
if (request.kind === "runtime_selection") {
|
|
102
|
-
return validateSelection(
|
|
95
|
+
return validateSelection(
|
|
96
|
+
snapshot,
|
|
97
|
+
request.processId,
|
|
98
|
+
request.selection,
|
|
99
|
+
request.availability,
|
|
100
|
+
request.target.kind === "turn" ? request.target.turnId : undefined,
|
|
101
|
+
);
|
|
103
102
|
}
|
|
104
103
|
return recoverPreparation(
|
|
105
104
|
snapshot,
|
|
106
105
|
request.cause,
|
|
107
106
|
modelConfigurationFromProcess(request.process),
|
|
108
|
-
existingTurnSelectionFromProcess(request.process),
|
|
109
107
|
request.currentStart,
|
|
110
108
|
request.availability,
|
|
111
109
|
);
|
|
@@ -116,6 +114,10 @@ export function createServerProcessModelPolicy(input: {
|
|
|
116
114
|
config: LeitwerkConfig;
|
|
117
115
|
processGraphs: ProcessGraphRegistry;
|
|
118
116
|
processActionRegistry: Pick<ProcessActionRegistry, "getTurnDefinition">;
|
|
117
|
+
capabilities?: (
|
|
118
|
+
providerId: string,
|
|
119
|
+
modelId: string,
|
|
120
|
+
) => Readonly<Record<string, boolean | "unknown">>;
|
|
119
121
|
scopedSettings?: Pick<ScopedSettingsService, "modelDefault">;
|
|
120
122
|
}): ServerProcessModelPolicy {
|
|
121
123
|
const snapshot = constructPolicySnapshot(input);
|
|
@@ -106,7 +106,8 @@ export function prepareLaunchPlan(
|
|
|
106
106
|
const invalidMode = opts.invalidModelConfig ?? "reject";
|
|
107
107
|
const warnings: LaunchPlanPreparationIssue[] = [];
|
|
108
108
|
const errors: LaunchPlanPreparationIssue[] = [];
|
|
109
|
-
const report = (issue: LaunchPlanPreparationIssue): void => {
|
|
109
|
+
const report = (issue: LaunchPlanPreparationIssue | null): void => {
|
|
110
|
+
if (!issue) return;
|
|
110
111
|
if (invalidMode === "reject") errors.push(issue);
|
|
111
112
|
else warnings.push(issue);
|
|
112
113
|
};
|
|
@@ -121,7 +122,7 @@ export function prepareLaunchPlan(
|
|
|
121
122
|
: parsed.error.reason === "not_object"
|
|
122
123
|
? "turnConfigsJson must be an object"
|
|
123
124
|
: `turnConfigsJson.${parsed.error.turnId ?? "<unknown>"} must be an object`;
|
|
124
|
-
|
|
125
|
+
errors.push(issue(parsed.error.code, message));
|
|
125
126
|
}
|
|
126
127
|
const baseConfig: LaunchModelConfigInput = {
|
|
127
128
|
defaultModelProfileId: launchPlan.processInput.defaultModelProfileId ?? null,
|
|
@@ -136,29 +137,29 @@ export function prepareLaunchPlan(
|
|
|
136
137
|
const policy = snapshot.processesById.get(launchPlan.processId);
|
|
137
138
|
const llmTurns = policy?.llmTurnIds ?? new Set<string>();
|
|
138
139
|
const validTurns: Record<string, { modelProfileId: string }> = {};
|
|
139
|
-
|
|
140
|
+
const defaultModelProfileId = normalized.defaultModelProfileId ?? null;
|
|
140
141
|
const modelIssue = (
|
|
141
142
|
profileId: string | null,
|
|
142
143
|
modelTarget: ModelTarget,
|
|
143
144
|
): LaunchPlanPreparationIssue | null => {
|
|
144
145
|
if (!profileId) return null;
|
|
145
|
-
const result = validateSelection(
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
const result = validateSelection(
|
|
147
|
+
snapshot,
|
|
148
|
+
launchPlan.processId,
|
|
149
|
+
{
|
|
150
|
+
modelProfileId: profileId,
|
|
151
|
+
provenance: { kind: "explicit", source: "instance_default" },
|
|
152
|
+
},
|
|
153
|
+
undefined,
|
|
154
|
+
modelTarget.kind === "default_model" ? undefined : (modelTarget.turnId ?? undefined),
|
|
155
|
+
);
|
|
149
156
|
return result.ok ? null : issueForPolicy(result, launchPlan.processId, modelTarget);
|
|
150
157
|
};
|
|
151
|
-
|
|
152
|
-
const issue = modelIssue(profileId, modelTarget);
|
|
153
|
-
if (!issue) return true;
|
|
154
|
-
report(issue);
|
|
155
|
-
return false;
|
|
156
|
-
};
|
|
157
|
-
if (!validate(defaultModelProfileId, target("default_model"))) defaultModelProfileId = null;
|
|
158
|
+
report(modelIssue(defaultModelProfileId, target("default_model")));
|
|
158
159
|
for (const [turnId, config] of Object.entries(normalized.turnConfigs ?? {})) {
|
|
159
160
|
const profileId = config.modelProfileId?.trim() || null;
|
|
160
161
|
if (!llmTurns.has(turnId)) {
|
|
161
|
-
|
|
162
|
+
errors.push(
|
|
162
163
|
issue(
|
|
163
164
|
"unknown_llm_turn",
|
|
164
165
|
`Turn '${turnId}' is not a known LLM turn for process '${launchPlan.processId}'`,
|
|
@@ -166,31 +167,28 @@ export function prepareLaunchPlan(
|
|
|
166
167
|
);
|
|
167
168
|
continue;
|
|
168
169
|
}
|
|
169
|
-
if (profileId
|
|
170
|
+
if (profileId) {
|
|
171
|
+
report(modelIssue(profileId, target("turn_model", turnId)));
|
|
170
172
|
validTurns[turnId] = { modelProfileId: profileId };
|
|
171
173
|
}
|
|
172
174
|
}
|
|
173
175
|
|
|
174
176
|
const selectedTurnId = launchPlan.startTurnId ?? launchPlan.processInput.selectedTurnId;
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
const selectedTurnIssue: LaunchPlanPreparationIssue | null = !selectedProfileId
|
|
177
|
+
const selectedModelProfileId = launchPlan.processInput.selectedTurnModelProfileId?.trim() || null;
|
|
178
|
+
const selectedTurnIssue: LaunchPlanPreparationIssue | null = !selectedModelProfileId
|
|
178
179
|
? null
|
|
179
180
|
: !selectedTurnId
|
|
180
181
|
? issue(
|
|
181
182
|
"selected_turn_model_requires_selected_turn",
|
|
182
|
-
`Selected turn model profile '${
|
|
183
|
+
`Selected turn model profile '${selectedModelProfileId}' requires a selected turn`,
|
|
183
184
|
)
|
|
184
185
|
: !llmTurns.has(selectedTurnId)
|
|
185
186
|
? issue(
|
|
186
187
|
"selected_turn_model_requires_llm_turn",
|
|
187
|
-
`Selected turn model profile '${
|
|
188
|
+
`Selected turn model profile '${selectedModelProfileId}' requires selected turn '${selectedTurnId}' to be an LLM turn`,
|
|
188
189
|
)
|
|
189
|
-
: modelIssue(
|
|
190
|
-
|
|
191
|
-
report(selectedTurnIssue);
|
|
192
|
-
if (invalidMode !== "reject") selectedModelProfileId = null;
|
|
193
|
-
}
|
|
190
|
+
: modelIssue(selectedModelProfileId, target("selected_turn_model", selectedTurnId));
|
|
191
|
+
report(selectedTurnIssue);
|
|
194
192
|
|
|
195
193
|
const modelConfig = { defaultModelProfileId, turnConfigs: validTurns };
|
|
196
194
|
let initialDefaultModelProfileId = null;
|
|
@@ -198,16 +196,16 @@ export function prepareLaunchPlan(
|
|
|
198
196
|
const defaultResult = resolveDefault(snapshot, configuration);
|
|
199
197
|
if (defaultResult.ok)
|
|
200
198
|
initialDefaultModelProfileId = defaultResult.selection?.modelProfileId ?? null;
|
|
201
|
-
if (selectedTurnId && !selectedModelProfileId) {
|
|
199
|
+
if (selectedTurnId && !selectedModelProfileId && errors.length === 0 && warnings.length === 0) {
|
|
202
200
|
const turnResult = resolveTurn(
|
|
203
201
|
snapshot,
|
|
204
202
|
configuration,
|
|
205
203
|
selectedTurnId,
|
|
206
|
-
|
|
204
|
+
false,
|
|
207
205
|
{ kind: "none" },
|
|
208
206
|
{ kind: "inherit" },
|
|
209
207
|
);
|
|
210
|
-
if (!turnResult.ok
|
|
208
|
+
if (!turnResult.ok) {
|
|
211
209
|
report(
|
|
212
210
|
issueForPolicy(
|
|
213
211
|
turnResult,
|