@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,4 +1,5 @@
|
|
|
1
1
|
import { trimToNull } from "@leitwerk-dev/domain";
|
|
2
|
+
import { compareModelProfileIds, modelCostRank } from "@leitwerk-dev/protocol";
|
|
2
3
|
import { presentProcessModelPolicyFailure } from "../process-model-policy-presenter.js";
|
|
3
4
|
import { resolveDefault, resolveTurn } from "./evaluate.js";
|
|
4
5
|
import {
|
|
@@ -6,45 +7,17 @@ import {
|
|
|
6
7
|
modelConfigurationFromLaunchInput,
|
|
7
8
|
modelConfigurationFromProcess,
|
|
8
9
|
} from "./input.js";
|
|
10
|
+
import { profileRejections } from "./requirements.js";
|
|
9
11
|
import type {
|
|
10
12
|
PolicySnapshot,
|
|
11
|
-
ProcessModelAvailabilitySnapshot,
|
|
12
13
|
ProcessModelPolicyProjectionByKind,
|
|
13
14
|
ProcessModelPolicyProjectionKind,
|
|
14
15
|
ProcessModelPolicyProjectionSubject,
|
|
15
16
|
ProcessModelPolicyProjectionSubjectFor,
|
|
16
17
|
ProjectedModelDefault,
|
|
17
|
-
ProjectedModelProfile,
|
|
18
|
-
ProjectedModelResolutionSource,
|
|
19
18
|
ValidModelConfiguration,
|
|
20
19
|
} from "./types.js";
|
|
21
20
|
|
|
22
|
-
function projectProfiles(
|
|
23
|
-
snapshot: PolicySnapshot,
|
|
24
|
-
processId: string,
|
|
25
|
-
availability?: ProcessModelAvailabilitySnapshot,
|
|
26
|
-
): readonly ProjectedModelProfile[] {
|
|
27
|
-
const process = snapshot.processesById.get(processId);
|
|
28
|
-
return snapshot.profiles
|
|
29
|
-
.filter((profile) => !process?.allowedProfileIds || process.allowedProfileIds.has(profile.id))
|
|
30
|
-
.map((profile) => {
|
|
31
|
-
const status = availability?.profiles.find((candidate) => candidate.profileId === profile.id);
|
|
32
|
-
return {
|
|
33
|
-
id: profile.id,
|
|
34
|
-
providerId: profile.provider,
|
|
35
|
-
modelId: profile.modelId,
|
|
36
|
-
thinkingLevel: profile.thinkingLevel,
|
|
37
|
-
availability: status?.availability ?? "stale",
|
|
38
|
-
safeReason: status?.safeReason ?? null,
|
|
39
|
-
checkedAt: status?.checkedAt ?? null,
|
|
40
|
-
};
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function sourceForPreview(source: ProjectedModelResolutionSource): ProjectedModelResolutionSource {
|
|
45
|
-
return source === "action_override" ? "instance_turn_config" : source;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
21
|
function defaultProjection(
|
|
49
22
|
snapshot: PolicySnapshot,
|
|
50
23
|
configuration: ValidModelConfiguration,
|
|
@@ -76,29 +49,76 @@ export function projectPolicy(
|
|
|
76
49
|
): ProcessModelPolicyProjectionByKind[ProcessModelPolicyProjectionKind] {
|
|
77
50
|
const processId =
|
|
78
51
|
request.kind === "process_configuration" ? request.process.processId : request.processId;
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
"availability" in request ? request.availability : undefined,
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
if (request.kind === "profile_options") return profiles;
|
|
86
|
-
|
|
52
|
+
const policy = snapshot.processesById.get(processId);
|
|
53
|
+
const targetTurnId =
|
|
54
|
+
"target" in request && request.target.kind === "turn" ? request.target.turnId : undefined;
|
|
87
55
|
if (request.kind === "compatible_profiles") {
|
|
88
|
-
const allowedProfileIds = new Set(profiles.map((profile) => profile.id));
|
|
89
56
|
return snapshot.profiles
|
|
90
57
|
.filter(
|
|
91
58
|
(profile) =>
|
|
92
59
|
profile.provider === request.providerId &&
|
|
93
60
|
profile.modelId === request.modelId &&
|
|
94
|
-
|
|
61
|
+
(!policy || !profileRejections(policy, profile, targetTurnId).length),
|
|
95
62
|
)
|
|
96
63
|
.map((profile) => profile.id);
|
|
97
64
|
}
|
|
65
|
+
const catalog = [...snapshot.profiles]
|
|
66
|
+
.sort(
|
|
67
|
+
(a, b) =>
|
|
68
|
+
modelCostRank(a.labels) - modelCostRank(b.labels) || compareModelProfileIds(a.id, b.id),
|
|
69
|
+
)
|
|
70
|
+
.map((profile) => {
|
|
71
|
+
const status = request.availability?.profiles.find(
|
|
72
|
+
(candidate) => candidate.profileId === profile.id,
|
|
73
|
+
);
|
|
74
|
+
return {
|
|
75
|
+
source: profile,
|
|
76
|
+
id: profile.id,
|
|
77
|
+
providerId: profile.provider,
|
|
78
|
+
modelId: profile.modelId,
|
|
79
|
+
thinkingLevel: profile.thinkingLevel,
|
|
80
|
+
labels: profile.labels,
|
|
81
|
+
default: profile.default,
|
|
82
|
+
availability: status?.availability ?? ("stale" as const),
|
|
83
|
+
safeReason: status?.safeReason ?? null,
|
|
84
|
+
checkedAt: status?.checkedAt ?? null,
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
const projectProfiles = (turnId?: string) => {
|
|
88
|
+
const projected = catalog.map(({ source, ...option }) => {
|
|
89
|
+
const rejections = policy ? profileRejections(policy, source, turnId) : [];
|
|
90
|
+
return {
|
|
91
|
+
...option,
|
|
92
|
+
policyReason:
|
|
93
|
+
rejections.map((r) => `${r.code} (${r.values.join(", ")}) from ${r.origin}`).join("; ") ||
|
|
94
|
+
undefined,
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
profiles: projected.filter((profile) => !profile.policyReason),
|
|
99
|
+
excludedProfiles: projected.filter((profile) => profile.policyReason),
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
const processProfiles = projectProfiles(targetTurnId);
|
|
103
|
+
const { profiles } = processProfiles;
|
|
98
104
|
|
|
99
|
-
|
|
105
|
+
if (request.kind === "profile_options") return profiles;
|
|
106
|
+
|
|
107
|
+
const profileMaps = () => {
|
|
108
|
+
const turns = [...(policy?.llmTurnIds ?? [])].map(
|
|
109
|
+
(turnId) => [turnId, projectProfiles(turnId)] as const,
|
|
110
|
+
);
|
|
111
|
+
return {
|
|
112
|
+
profilesByTurn: Object.fromEntries(turns.map(([id, value]) => [id, value.profiles])),
|
|
113
|
+
excludedProfiles: Object.fromEntries([
|
|
114
|
+
["", processProfiles.excludedProfiles],
|
|
115
|
+
...turns.map(([id, value]) => [id, value.excludedProfiles]),
|
|
116
|
+
]),
|
|
117
|
+
};
|
|
118
|
+
};
|
|
100
119
|
if (request.kind === "launcher_schema") {
|
|
101
120
|
return {
|
|
121
|
+
...profileMaps(),
|
|
102
122
|
profiles,
|
|
103
123
|
turns: [...(policy?.llmTurnIds ?? [])].map((turnId) => ({
|
|
104
124
|
turnId,
|
|
@@ -134,13 +154,17 @@ export function projectPolicy(
|
|
|
134
154
|
snapshot,
|
|
135
155
|
configuration,
|
|
136
156
|
turnId,
|
|
137
|
-
|
|
157
|
+
false,
|
|
138
158
|
{ kind: "none" },
|
|
139
159
|
{ kind: "inherit" },
|
|
140
160
|
request.availability,
|
|
141
161
|
);
|
|
142
162
|
return {
|
|
143
163
|
turnId,
|
|
164
|
+
explanation: resolved.skippedPreferences?.length
|
|
165
|
+
? `Automatic — skipped ${resolved.skippedPreferences.map((preference) => `${preference.profileId}: ${preference.rejections.map((r) => `${r.code} (${r.values.join(", ")}) from ${r.origin}`).join("; ")}`).join("; ")}`
|
|
166
|
+
: undefined,
|
|
167
|
+
ranking: resolved.ranking,
|
|
144
168
|
effectiveModelProfileId: resolved.selection?.modelProfileId ?? null,
|
|
145
169
|
effectiveSource: resolved.selection?.provenance.source ?? ("none" as const),
|
|
146
170
|
...(!resolved.ok ? { effectiveError: presentProcessModelPolicyFailure(resolved) } : {}),
|
|
@@ -162,7 +186,9 @@ export function projectPolicy(
|
|
|
162
186
|
});
|
|
163
187
|
|
|
164
188
|
if (request.kind === "launcher_preview") {
|
|
165
|
-
const profilesById = new Map(
|
|
189
|
+
const profilesById = new Map(
|
|
190
|
+
catalog.map(({ source: _source, ...profile }) => [profile.id, profile]),
|
|
191
|
+
);
|
|
166
192
|
return {
|
|
167
193
|
defaultModel: {
|
|
168
194
|
source: defaultModel.source,
|
|
@@ -172,7 +198,9 @@ export function projectPolicy(
|
|
|
172
198
|
turnId: turn.turnId,
|
|
173
199
|
description: turn.description,
|
|
174
200
|
effective: {
|
|
175
|
-
|
|
201
|
+
explanation: turn.explanation,
|
|
202
|
+
ranking: turn.ranking,
|
|
203
|
+
source: turn.effectiveSource,
|
|
176
204
|
...(turn.effectiveError ? { error: turn.effectiveError } : {}),
|
|
177
205
|
profile: profilesById.get(turn.effectiveModelProfileId ?? "") ?? null,
|
|
178
206
|
},
|
|
@@ -183,6 +211,7 @@ export function projectPolicy(
|
|
|
183
211
|
const selectedTurn = existingTurnSelectionFromProcess(request.process);
|
|
184
212
|
return {
|
|
185
213
|
state: { kind: "ready" },
|
|
214
|
+
...profileMaps(),
|
|
186
215
|
profiles,
|
|
187
216
|
defaultModel,
|
|
188
217
|
turns,
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { compareModelProfileIds, modelCostRank } from "@leitwerk-dev/protocol";
|
|
2
|
+
import type { PolicyProcess, PolicyProfile } from "./types.js";
|
|
3
|
+
|
|
4
|
+
/** @internal */
|
|
5
|
+
export function requirementLayers(policy: PolicyProcess, turnId?: string) {
|
|
6
|
+
return policy.requirements.concat(turnId ? (policy.turnRequirements[turnId] ?? []) : []);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Stable policy evidence; availability never participates. @internal */
|
|
10
|
+
export function profileRejections(policy: PolicyProcess, profile: PolicyProfile, turnId?: string) {
|
|
11
|
+
const rejections: { origin: string; code: string; values: readonly string[] }[] = [];
|
|
12
|
+
if (policy.allowedProfileIds && !policy.allowedProfileIds.has(profile.id))
|
|
13
|
+
rejections.push({
|
|
14
|
+
origin: `process_configs.${policy.id}.allowed_model_profiles`,
|
|
15
|
+
code: "profile_not_allowed",
|
|
16
|
+
values: [profile.id],
|
|
17
|
+
});
|
|
18
|
+
const labels = new Set(profile.labels);
|
|
19
|
+
for (const { origin, requirements: r } of requirementLayers(policy, turnId)) {
|
|
20
|
+
if (r.profiles && !r.profiles.includes(profile.id))
|
|
21
|
+
rejections.push({ origin, code: "profile_not_allowed", values: r.profiles });
|
|
22
|
+
const missing = r.labels?.all_of?.filter((label) => !labels.has(label)) ?? [];
|
|
23
|
+
if (missing.length) rejections.push({ origin, code: "missing_labels", values: missing });
|
|
24
|
+
if (r.labels?.any_of && !r.labels.any_of.some((label) => labels.has(label)))
|
|
25
|
+
rejections.push({ origin, code: "no_matching_labels", values: r.labels.any_of });
|
|
26
|
+
const forbidden = r.labels?.none_of?.filter((label) => labels.has(label)) ?? [];
|
|
27
|
+
if (forbidden.length) rejections.push({ origin, code: "forbidden_labels", values: forbidden });
|
|
28
|
+
for (const capability of r.capabilities ?? []) {
|
|
29
|
+
if (profile.capabilities[capability] !== true)
|
|
30
|
+
rejections.push({
|
|
31
|
+
origin,
|
|
32
|
+
code:
|
|
33
|
+
profile.capabilities[capability] === false
|
|
34
|
+
? "unsupported_capability"
|
|
35
|
+
: "unknown_capability",
|
|
36
|
+
values: [capability],
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return rejections;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** @internal */
|
|
44
|
+
export function rankedProfiles(
|
|
45
|
+
policy: PolicyProcess,
|
|
46
|
+
profiles: readonly PolicyProfile[],
|
|
47
|
+
turnId?: string,
|
|
48
|
+
) {
|
|
49
|
+
const eligible = profiles.filter((profile) => !profileRejections(policy, profile, turnId).length);
|
|
50
|
+
const marked = eligible.filter((profile) => profile.default);
|
|
51
|
+
const relevant = new Set(
|
|
52
|
+
requirementLayers(policy, turnId).flatMap(({ requirements: r }) => [
|
|
53
|
+
...(r.labels?.all_of ?? []),
|
|
54
|
+
...(r.labels?.any_of ?? []),
|
|
55
|
+
]),
|
|
56
|
+
);
|
|
57
|
+
const unrelated = (profile: PolicyProfile) =>
|
|
58
|
+
new Set(profile.labels.filter((label) => !relevant.has(label))).size;
|
|
59
|
+
const ranked = (marked.length ? marked : eligible).sort(
|
|
60
|
+
(a, b) =>
|
|
61
|
+
(marked.length ? unrelated(a) - unrelated(b) : 0) ||
|
|
62
|
+
modelCostRank(a.labels) - modelCostRank(b.labels) ||
|
|
63
|
+
compareModelProfileIds(a.id, b.id),
|
|
64
|
+
);
|
|
65
|
+
const minUnrelated = Math.min(...marked.map(unrelated));
|
|
66
|
+
return {
|
|
67
|
+
tiedProfileIds: marked
|
|
68
|
+
.filter((profile) => unrelated(profile) === minUnrelated)
|
|
69
|
+
.map((profile) => profile.id),
|
|
70
|
+
marked: marked.length > 0,
|
|
71
|
+
profiles: ranked,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -8,20 +8,19 @@ import type {
|
|
|
8
8
|
TurnStartRecord,
|
|
9
9
|
} from "@leitwerk-dev/domain";
|
|
10
10
|
import type { LaunchPlanPreparationResultLike, ProcessLaunchPlan } from "@leitwerk-dev/process-sdk";
|
|
11
|
+
import type {
|
|
12
|
+
LauncherModelConfigSchema,
|
|
13
|
+
ProcessModelConfigurationView,
|
|
14
|
+
} from "@leitwerk-dev/protocol/http-contracts";
|
|
11
15
|
import type { ModelStatusCacheSnapshot } from "../model-providers/model-status-cache.js";
|
|
12
16
|
|
|
13
17
|
/** @internal */
|
|
14
18
|
export type ProcessModelAvailabilitySnapshot = ModelStatusCacheSnapshot;
|
|
15
19
|
|
|
16
20
|
/** @internal */
|
|
17
|
-
export type PersistedModelConfigurationIssue =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/** @internal */
|
|
21
|
-
readonly reason: "invalid_json" | "not_object" | "turn_config_not_object";
|
|
22
|
-
/** @internal */
|
|
23
|
-
readonly turnId?: string;
|
|
24
|
-
};
|
|
21
|
+
export type PersistedModelConfigurationIssue = Readonly<
|
|
22
|
+
Extract<ProcessModelConfigurationView["state"], { kind: "blocked" }>["issues"][number]
|
|
23
|
+
>;
|
|
25
24
|
|
|
26
25
|
export interface ValidModelConfiguration {
|
|
27
26
|
readonly kind: "valid";
|
|
@@ -121,6 +120,10 @@ export type ModelOverride =
|
|
|
121
120
|
|
|
122
121
|
/** @internal */
|
|
123
122
|
type ProcessModelPolicyFailureBase = {
|
|
123
|
+
/** @internal */
|
|
124
|
+
readonly ranking?: ModelRankingEvidence;
|
|
125
|
+
/** @internal */
|
|
126
|
+
readonly skippedPreferences?: readonly SkippedModelPreference[];
|
|
124
127
|
/** @internal */
|
|
125
128
|
readonly ok: false;
|
|
126
129
|
/** @internal */
|
|
@@ -135,6 +138,8 @@ export type ProcessModelPolicyFailure = ProcessModelPolicyFailureBase &
|
|
|
135
138
|
| {
|
|
136
139
|
/** @internal */
|
|
137
140
|
readonly code: "model_required";
|
|
141
|
+
/** Effective hard constraints when no eligible model exists. @internal */
|
|
142
|
+
readonly requirements?: readonly PolicyRequirementLayer[];
|
|
138
143
|
}
|
|
139
144
|
| {
|
|
140
145
|
/** @internal */
|
|
@@ -149,6 +154,8 @@ export type ProcessModelPolicyFailure = ProcessModelPolicyFailureBase &
|
|
|
149
154
|
readonly modelProfileId: string;
|
|
150
155
|
/** @internal */
|
|
151
156
|
readonly processId: string;
|
|
157
|
+
/** @internal */
|
|
158
|
+
readonly rejections?: readonly ModelRequirementRejection[];
|
|
152
159
|
}
|
|
153
160
|
| {
|
|
154
161
|
/** @internal */
|
|
@@ -176,6 +183,10 @@ export type ProcessModelPolicyFailure = ProcessModelPolicyFailureBase &
|
|
|
176
183
|
);
|
|
177
184
|
/** @internal */
|
|
178
185
|
export interface ProcessModelPolicyResolution {
|
|
186
|
+
/** @internal */
|
|
187
|
+
readonly ranking?: ModelRankingEvidence;
|
|
188
|
+
/** @internal */
|
|
189
|
+
readonly skippedPreferences?: readonly SkippedModelPreference[];
|
|
179
190
|
/** @internal */
|
|
180
191
|
readonly ok: true;
|
|
181
192
|
/** @internal */
|
|
@@ -188,6 +199,8 @@ export type ProcessModelPolicyEvaluation = ProcessModelPolicyResolution | Proces
|
|
|
188
199
|
|
|
189
200
|
/** @internal */
|
|
190
201
|
export interface ProjectedModelProfile {
|
|
202
|
+
/** Independent of cached availability. @internal */
|
|
203
|
+
readonly policyReason?: string;
|
|
191
204
|
/** @internal */
|
|
192
205
|
readonly id: string;
|
|
193
206
|
/** @internal */
|
|
@@ -197,6 +210,10 @@ export interface ProjectedModelProfile {
|
|
|
197
210
|
/** @internal */
|
|
198
211
|
readonly thinkingLevel: string;
|
|
199
212
|
/** @internal */
|
|
213
|
+
readonly labels?: readonly string[];
|
|
214
|
+
/** @internal */
|
|
215
|
+
readonly default?: boolean;
|
|
216
|
+
/** @internal */
|
|
200
217
|
readonly availability: "available" | "unavailable" | "stale";
|
|
201
218
|
/** @internal */
|
|
202
219
|
readonly safeReason: string | null;
|
|
@@ -205,31 +222,21 @@ export interface ProjectedModelProfile {
|
|
|
205
222
|
}
|
|
206
223
|
|
|
207
224
|
/** @internal */
|
|
208
|
-
export
|
|
209
|
-
/** @internal */
|
|
210
|
-
readonly processConfigModelProfileId: string | null;
|
|
211
|
-
/** @internal */
|
|
212
|
-
readonly instanceModelProfileId: string | null;
|
|
213
|
-
/** @internal */
|
|
214
|
-
readonly effectiveModelProfileId: string | null;
|
|
215
|
-
/** @internal */
|
|
216
|
-
readonly source: "instance" | "process_config" | "catalog_default" | "none";
|
|
217
|
-
}
|
|
225
|
+
export type ProjectedModelDefault = Readonly<ProcessModelConfigurationView["defaultModel"]>;
|
|
218
226
|
|
|
219
227
|
/** @internal */
|
|
220
228
|
export type ProjectedModelResolutionSource = ProcessSelectedTurnModelSource | "none";
|
|
221
229
|
|
|
222
230
|
/** @internal */
|
|
223
231
|
export interface ProjectedLauncherModelSchema {
|
|
232
|
+
/** Excluded candidates with policy origins, keyed by turn; empty key denotes the process preference. @internal */
|
|
233
|
+
readonly excludedProfiles?: Readonly<Record<string, readonly ProjectedModelProfile[]>>;
|
|
234
|
+
/** @internal */
|
|
235
|
+
readonly profilesByTurn?: Readonly<Record<string, readonly ProjectedModelProfile[]>>;
|
|
224
236
|
/** @internal */
|
|
225
237
|
readonly profiles: readonly ProjectedModelProfile[];
|
|
226
238
|
/** @internal */
|
|
227
|
-
readonly turns:
|
|
228
|
-
/** @internal */
|
|
229
|
-
readonly turnId: string;
|
|
230
|
-
/** @internal */
|
|
231
|
-
readonly description: string;
|
|
232
|
-
}[];
|
|
239
|
+
readonly turns: LauncherModelConfigSchema["llmTurns"];
|
|
233
240
|
}
|
|
234
241
|
|
|
235
242
|
/** @internal */
|
|
@@ -249,6 +256,10 @@ export interface ProjectedLauncherModelPreview {
|
|
|
249
256
|
readonly description: string;
|
|
250
257
|
/** @internal */
|
|
251
258
|
readonly effective: {
|
|
259
|
+
/** @internal */
|
|
260
|
+
readonly explanation?: string;
|
|
261
|
+
/** @internal */
|
|
262
|
+
readonly ranking?: ModelRankingEvidence;
|
|
252
263
|
/** @internal */
|
|
253
264
|
readonly error?: string;
|
|
254
265
|
/** @internal */
|
|
@@ -260,60 +271,27 @@ export interface ProjectedLauncherModelPreview {
|
|
|
260
271
|
}
|
|
261
272
|
|
|
262
273
|
/** @internal */
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
/** @internal */
|
|
274
|
-
readonly issues: readonly PersistedModelConfigurationIssue[];
|
|
275
|
-
};
|
|
276
|
-
/** @internal */
|
|
277
|
-
readonly profiles: readonly ProjectedModelProfile[];
|
|
278
|
-
/** @internal */
|
|
279
|
-
readonly effectiveSelectedTurn: {
|
|
280
|
-
/** @internal */
|
|
281
|
-
readonly turnId: string;
|
|
282
|
-
/** @internal */
|
|
283
|
-
readonly description: string;
|
|
284
|
-
/** @internal */
|
|
285
|
-
readonly modelProfileId: string;
|
|
286
|
-
/** @internal */
|
|
287
|
-
readonly source: ProcessSelectedTurnModelSource;
|
|
288
|
-
} | null;
|
|
289
|
-
/** @internal */
|
|
290
|
-
readonly defaultModel: ProjectedModelDefault;
|
|
291
|
-
/** @internal */
|
|
292
|
-
readonly turns: readonly {
|
|
293
|
-
/** @internal */
|
|
294
|
-
readonly turnId: string;
|
|
295
|
-
/** @internal */
|
|
296
|
-
readonly description: string;
|
|
297
|
-
/** @internal */
|
|
298
|
-
readonly pathType: string;
|
|
299
|
-
/** @internal */
|
|
300
|
-
readonly processConfigModelProfileId: string | null;
|
|
301
|
-
/** @internal */
|
|
302
|
-
readonly instanceModelProfileId: string | null;
|
|
303
|
-
/** @internal */
|
|
304
|
-
readonly effectiveConfiguredModelProfileId: string | null;
|
|
305
|
-
/** @internal */
|
|
306
|
-
readonly fixedModelProfileId: string | null;
|
|
307
|
-
/** @internal */
|
|
308
|
-
readonly effectiveModelProfileId: string | null;
|
|
309
|
-
/** @internal */
|
|
310
|
-
readonly effectiveSource: ProcessSelectedTurnModelSource | "none";
|
|
311
|
-
/** @internal */
|
|
312
|
-
readonly effectiveError?: string;
|
|
274
|
+
type ProjectedTurnModelConfiguration = Readonly<ProcessModelConfigurationView["turns"][number]>;
|
|
275
|
+
|
|
276
|
+
/** @internal */
|
|
277
|
+
export type ProjectedProcessModelConfiguration = Readonly<
|
|
278
|
+
Omit<
|
|
279
|
+
ProcessModelConfigurationView,
|
|
280
|
+
"availableProfiles" | "profilesByTurn" | "excludedProfiles" | "turns"
|
|
281
|
+
>
|
|
282
|
+
> &
|
|
283
|
+
Pick<ProjectedLauncherModelSchema, "profiles" | "profilesByTurn" | "excludedProfiles"> & {
|
|
313
284
|
/** @internal */
|
|
314
|
-
readonly
|
|
315
|
-
|
|
316
|
-
|
|
285
|
+
readonly turns: readonly Readonly<
|
|
286
|
+
ProjectedTurnModelConfiguration &
|
|
287
|
+
Required<
|
|
288
|
+
Pick<
|
|
289
|
+
ProjectedTurnModelConfiguration,
|
|
290
|
+
"fixedModelProfileId" | "effectiveModelProfileId" | "effectiveSource"
|
|
291
|
+
>
|
|
292
|
+
>
|
|
293
|
+
>[];
|
|
294
|
+
};
|
|
317
295
|
|
|
318
296
|
/** @internal */
|
|
319
297
|
export interface ProcessModelPolicyProjectionByKind {
|
|
@@ -360,6 +338,8 @@ export type ProcessModelPolicyEvaluationSubject =
|
|
|
360
338
|
| {
|
|
361
339
|
/** @internal */
|
|
362
340
|
readonly kind: "runtime_selection";
|
|
341
|
+
/** Explicit validation scope. @internal */
|
|
342
|
+
readonly target: ModelPolicyTarget;
|
|
363
343
|
/** @internal */
|
|
364
344
|
readonly processId: string;
|
|
365
345
|
/** @internal */
|
|
@@ -386,6 +366,8 @@ export type ProcessModelPolicyProjectionSubject =
|
|
|
386
366
|
/** @internal */
|
|
387
367
|
readonly kind: "profile_options";
|
|
388
368
|
/** @internal */
|
|
369
|
+
readonly target: ModelPolicyTarget;
|
|
370
|
+
/** @internal */
|
|
389
371
|
readonly processId: string;
|
|
390
372
|
/** @internal */
|
|
391
373
|
readonly availability: ProcessModelAvailabilitySnapshot;
|
|
@@ -394,6 +376,8 @@ export type ProcessModelPolicyProjectionSubject =
|
|
|
394
376
|
/** @internal */
|
|
395
377
|
readonly kind: "compatible_profiles";
|
|
396
378
|
/** @internal */
|
|
379
|
+
readonly target: ModelPolicyTarget;
|
|
380
|
+
/** @internal */
|
|
397
381
|
readonly processId: string;
|
|
398
382
|
/** @internal */
|
|
399
383
|
readonly providerId: string;
|
|
@@ -458,7 +442,7 @@ export interface PrepareLaunchPlanOptions {
|
|
|
458
442
|
/** @internal */
|
|
459
443
|
readonly replaceModelConfig?: boolean;
|
|
460
444
|
/** @internal */
|
|
461
|
-
readonly invalidModelConfig?: "reject" | "
|
|
445
|
+
readonly invalidModelConfig?: "reject" | "retain";
|
|
462
446
|
}
|
|
463
447
|
|
|
464
448
|
/** @internal */
|
|
@@ -479,14 +463,60 @@ export interface ServerProcessModelPolicy {
|
|
|
479
463
|
/** @internal */
|
|
480
464
|
fingerprint(request: ProcessModelPolicyFingerprintSubject): string;
|
|
481
465
|
}
|
|
466
|
+
/** @internal */
|
|
467
|
+
export type ModelPolicyTarget =
|
|
468
|
+
| {
|
|
469
|
+
/** @internal */
|
|
470
|
+
readonly kind: "process_default";
|
|
471
|
+
}
|
|
472
|
+
| {
|
|
473
|
+
/** @internal */
|
|
474
|
+
readonly kind: "turn";
|
|
475
|
+
/** @internal */
|
|
476
|
+
readonly turnId: string;
|
|
477
|
+
};
|
|
478
|
+
/** @internal */
|
|
479
|
+
export interface ModelRankingEvidence {
|
|
480
|
+
/** @internal */
|
|
481
|
+
readonly kind: "marked_defaults" | "cost_id";
|
|
482
|
+
/** Equal-specificity marked defaults; ordered by the actual cost/ID tie-break. @internal */
|
|
483
|
+
readonly tiedProfileIds: readonly string[];
|
|
484
|
+
}
|
|
485
|
+
/** @internal */
|
|
486
|
+
export interface SkippedModelPreference {
|
|
487
|
+
/** @internal */
|
|
488
|
+
readonly profileId: string;
|
|
489
|
+
/** @internal */
|
|
490
|
+
readonly source: ProcessSelectedTurnModelSource;
|
|
491
|
+
/** @internal */
|
|
492
|
+
readonly rejections: readonly ModelRequirementRejection[];
|
|
493
|
+
}
|
|
494
|
+
/** @internal */
|
|
495
|
+
export interface ModelRequirementRejection {
|
|
496
|
+
/** @internal */ readonly origin: string;
|
|
497
|
+
/** @internal */ readonly code: string;
|
|
498
|
+
/** @internal */ readonly values: readonly string[];
|
|
499
|
+
}
|
|
482
500
|
export interface PolicyProfile {
|
|
501
|
+
readonly labels: readonly string[];
|
|
502
|
+
readonly default: boolean;
|
|
503
|
+
readonly capabilities: Readonly<Record<string, boolean | "unknown">>;
|
|
483
504
|
readonly id: string;
|
|
484
505
|
readonly provider: string;
|
|
485
506
|
readonly modelId: string;
|
|
486
507
|
readonly thinkingLevel: string;
|
|
487
508
|
readonly providerOptions: Readonly<Record<string, unknown>>;
|
|
488
509
|
}
|
|
510
|
+
/** @internal */
|
|
511
|
+
export interface PolicyRequirementLayer {
|
|
512
|
+
/** @internal */
|
|
513
|
+
readonly origin: string;
|
|
514
|
+
/** @internal */
|
|
515
|
+
readonly requirements: import("@leitwerk-dev/protocol").ModelRequirements;
|
|
516
|
+
}
|
|
489
517
|
export interface PolicyProcess {
|
|
518
|
+
readonly requirements: readonly PolicyRequirementLayer[];
|
|
519
|
+
readonly turnRequirements: Readonly<Record<string, readonly PolicyRequirementLayer[]>>;
|
|
490
520
|
readonly id: string;
|
|
491
521
|
readonly allowedProfileIds: ReadonlySet<string> | null;
|
|
492
522
|
readonly defaultProfileId: string | null;
|
|
@@ -27,11 +27,11 @@ export function presentLaunchPlanPreparationIssues(
|
|
|
27
27
|
export function presentProcessModelPolicyFailure(failure: ProcessModelPolicyFailure): string {
|
|
28
28
|
switch (failure.code) {
|
|
29
29
|
case "model_required":
|
|
30
|
-
return
|
|
30
|
+
return `No model satisfies this turn's requirements${failure.requirements?.length ? `: ${failure.requirements.map((layer) => `${layer.origin} ${JSON.stringify(layer.requirements)}`).join("; ")}` : ""}`;
|
|
31
31
|
case "unknown_model_profile":
|
|
32
32
|
return `Unknown model profile '${failure.modelProfileId}'`;
|
|
33
33
|
case "model_profile_not_allowed":
|
|
34
|
-
return `Model profile '${failure.modelProfileId}' is not allowed for process '${failure.processId}'`;
|
|
34
|
+
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("; ")}` : ""}`;
|
|
35
35
|
case "model_stale":
|
|
36
36
|
return failure.reason ?? "Model status has not been refreshed";
|
|
37
37
|
case "model_unavailable":
|
|
@@ -54,6 +54,9 @@ export function presentModelProfileOption(
|
|
|
54
54
|
const thinkingLevel = profile.thinkingLevel.trim();
|
|
55
55
|
return {
|
|
56
56
|
id: profile.id,
|
|
57
|
+
...(profile.policyReason ? { policyReason: profile.policyReason } : {}),
|
|
58
|
+
labels: profile.labels ?? [],
|
|
59
|
+
default: profile.default ?? false,
|
|
57
60
|
label: `${profile.id} — ${profile.providerId}/${profile.modelId}`,
|
|
58
61
|
description:
|
|
59
62
|
thinkingLevel && thinkingLevel.toLowerCase() !== "off"
|
|
@@ -65,11 +68,21 @@ export function presentModelProfileOption(
|
|
|
65
68
|
};
|
|
66
69
|
}
|
|
67
70
|
|
|
71
|
+
function presentProfileMap(
|
|
72
|
+
profiles: Readonly<Record<string, readonly ProjectedModelProfile[]>> = {},
|
|
73
|
+
) {
|
|
74
|
+
return Object.fromEntries(
|
|
75
|
+
Object.entries(profiles).map(([id, options]) => [id, options.map(presentModelProfileOption)]),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
68
79
|
export function presentLauncherModelConfigSchema(
|
|
69
80
|
projection: ProjectedLauncherModelSchema,
|
|
70
81
|
): LauncherModelConfigSchema {
|
|
71
82
|
return {
|
|
72
83
|
availableProfiles: projection.profiles.map(presentModelProfileOption),
|
|
84
|
+
profilesByTurn: presentProfileMap(projection.profilesByTurn),
|
|
85
|
+
excludedProfiles: presentProfileMap(projection.excludedProfiles),
|
|
73
86
|
llmTurns: projection.turns.map((turn) => ({ ...turn })),
|
|
74
87
|
};
|
|
75
88
|
}
|
|
@@ -93,6 +106,7 @@ export function presentLauncherModelConfigPreview(
|
|
|
93
106
|
turnId: turn.turnId,
|
|
94
107
|
description: turn.description,
|
|
95
108
|
effective: {
|
|
109
|
+
...(turn.effective.explanation ? { explanation: turn.effective.explanation } : {}),
|
|
96
110
|
...(turn.effective.error ? { error: turn.effective.error } : {}),
|
|
97
111
|
source: turn.effective.source,
|
|
98
112
|
profile: turn.effective.profile ? presentModelProfileOption(turn.effective.profile) : null,
|
|
@@ -106,6 +120,8 @@ export function presentProcessModelConfiguration(
|
|
|
106
120
|
): ProcessModelConfigurationView {
|
|
107
121
|
return {
|
|
108
122
|
state: projection.state,
|
|
123
|
+
excludedProfiles: presentProfileMap(projection.excludedProfiles),
|
|
124
|
+
profilesByTurn: presentProfileMap(projection.profilesByTurn),
|
|
109
125
|
availableProfiles: projection.profiles.map(presentModelProfileOption),
|
|
110
126
|
effectiveSelectedTurn: projection.effectiveSelectedTurn,
|
|
111
127
|
defaultModel: projection.defaultModel,
|
|
@@ -43,6 +43,7 @@ export function createProcessModelSelection(
|
|
|
43
43
|
return deps.processModelPolicy
|
|
44
44
|
.project({
|
|
45
45
|
kind: "profile_options",
|
|
46
|
+
target: { kind: "process_default" },
|
|
46
47
|
processId: process.processId,
|
|
47
48
|
availability: deps.modelStatusCache.snapshot(),
|
|
48
49
|
})
|
|
@@ -114,6 +115,7 @@ export function createProcessModelSelection(
|
|
|
114
115
|
resolveCompatibleModelProfileIds: (providerId, modelId) =>
|
|
115
116
|
deps.processModelPolicy.project({
|
|
116
117
|
kind: "compatible_profiles",
|
|
118
|
+
target: { kind: "turn", turnId },
|
|
117
119
|
availability,
|
|
118
120
|
processId: process.processId,
|
|
119
121
|
providerId,
|