@leitwerk-dev/server 0.1.6 → 0.1.8
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.d.ts.map +1 -1
- package/dist/app.js +31 -40
- package/dist/app.js.map +1 -1
- package/dist/auth/auth-client.d.ts +25 -0
- package/dist/auth/auth-client.d.ts.map +1 -0
- package/dist/auth/auth-client.js +19 -0
- package/dist/auth/auth-client.js.map +1 -0
- package/dist/auth/auth-config.d.ts +8 -2
- package/dist/auth/auth-config.d.ts.map +1 -1
- package/dist/auth/auth-config.js +17 -7
- package/dist/auth/auth-config.js.map +1 -1
- package/dist/auth/auth-service.d.ts +2 -0
- package/dist/auth/auth-service.d.ts.map +1 -1
- package/dist/auth/auth-service.js +9 -5
- package/dist/auth/auth-service.js.map +1 -1
- package/dist/auth/auth-test-helpers.js +2 -2
- package/dist/auth/auth-test-helpers.js.map +1 -1
- package/dist/auth/github-oauth-client.d.ts +20 -0
- package/dist/auth/github-oauth-client.d.ts.map +1 -0
- package/dist/auth/github-oauth-client.js +79 -0
- package/dist/auth/github-oauth-client.js.map +1 -0
- package/dist/auth/oidc-client.d.ts +4 -4
- package/dist/{chunk-G4PCN46L.js → chunk-ES5RBLAT.js} +47 -99
- package/dist/chunk-ES5RBLAT.js.map +1 -0
- package/dist/{chunk-KVHAK5UR.js → chunk-UC3OOEQ3.js} +527 -410
- package/dist/chunk-UC3OOEQ3.js.map +1 -0
- package/dist/config/config-loader.d.ts.map +1 -1
- package/dist/config/config-loader.js +21 -89
- package/dist/config/config-loader.js.map +1 -1
- package/dist/config/config-types.d.ts +18 -3
- package/dist/config/config-types.d.ts.map +1 -1
- package/dist/domain-logic/outcome-tools.d.ts +2 -2
- package/dist/domain-logic/outcome-tools.d.ts.map +1 -1
- package/dist/domain-logic/outcome-tools.js +1 -1
- package/dist/domain-logic/outcome-tools.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/integration-tool-registry.d.ts +23 -0
- package/dist/integration-tool-registry.d.ts.map +1 -0
- package/dist/integration-tool-registry.js +140 -0
- package/dist/integration-tool-registry.js.map +1 -0
- package/dist/model-providers/builtin-server-adapter.d.ts.map +1 -1
- package/dist/model-providers/builtin-server-adapter.js +10 -2
- package/dist/model-providers/builtin-server-adapter.js.map +1 -1
- package/dist/process-ui-snapshot-presenter.d.ts.map +1 -1
- package/dist/process-ui-snapshot-presenter.js +0 -2
- package/dist/process-ui-snapshot-presenter.js.map +1 -1
- package/dist/process-watcher-registry.d.ts +3 -31
- package/dist/process-watcher-registry.d.ts.map +1 -1
- package/dist/process-watcher-registry.js +96 -97
- package/dist/process-watcher-registry.js.map +1 -1
- package/dist/routes/watchers.d.ts.map +1 -1
- package/dist/routes/watchers.js +14 -50
- package/dist/routes/watchers.js.map +1 -1
- package/dist/semantic-state-json.d.ts +1 -2
- package/dist/semantic-state-json.d.ts.map +1 -1
- package/dist/semantic-state-json.js +1 -2
- package/dist/semantic-state-json.js.map +1 -1
- package/dist/supervisor/ipc-handler.d.ts +4 -1
- package/dist/supervisor/ipc-handler.d.ts.map +1 -1
- package/dist/supervisor/ipc-handler.js +18 -0
- package/dist/supervisor/ipc-handler.js.map +1 -1
- package/dist/supervisor/worker-start-payload-builder.d.ts +5 -4
- package/dist/supervisor/worker-start-payload-builder.d.ts.map +1 -1
- package/dist/supervisor/worker-start-payload-builder.js +9 -0
- package/dist/supervisor/worker-start-payload-builder.js.map +1 -1
- package/dist/supervisor/worker-supervisor.d.ts +4 -5
- package/dist/supervisor/worker-supervisor.d.ts.map +1 -1
- package/dist/supervisor/worker-supervisor.js +6 -0
- package/dist/supervisor/worker-supervisor.js.map +1 -1
- package/dist/test-helpers/fake-worker-supervisor.d.ts.map +1 -1
- package/dist/test-helpers/fake-worker-supervisor.js +1 -0
- package/dist/test-helpers/fake-worker-supervisor.js.map +1 -1
- package/dist/test-helpers/ipc-handler-harness.d.ts +1 -0
- package/dist/test-helpers/ipc-handler-harness.d.ts.map +1 -1
- package/dist/test-helpers/ipc-handler-harness.js +4 -3
- package/dist/test-helpers/ipc-handler-harness.js.map +1 -1
- package/dist/test-helpers/process-fixtures.js +3 -3
- package/dist/test-helpers/process-fixtures.js.map +1 -1
- package/dist/{writes-irEq9SlA.d.ts → writes-CVXLCYce.d.ts} +61 -13
- package/package.json +10 -10
- package/src/app.ts +37 -44
- package/src/auth/auth-client.ts +40 -0
- package/src/auth/auth-config.ts +34 -9
- package/src/auth/auth-service.ts +11 -5
- package/src/auth/auth-test-helpers.ts +2 -2
- package/src/auth/github-oauth-client.ts +111 -0
- package/src/auth/oidc-client.ts +5 -5
- package/src/config/config-loader.ts +42 -103
- package/src/config/config-types.ts +21 -3
- package/src/domain-logic/outcome-tools.ts +3 -3
- package/src/index.ts +1 -4
- package/src/integration-tool-registry.ts +186 -0
- package/src/model-providers/builtin-server-adapter.ts +10 -2
- package/src/process-ui-snapshot-presenter.ts +0 -2
- package/src/process-watcher-registry.ts +124 -167
- package/src/routes/watchers.ts +14 -50
- package/src/semantic-state-json.ts +0 -2
- package/src/supervisor/ipc-handler.ts +35 -0
- package/src/supervisor/worker-start-payload-builder.ts +21 -1
- package/src/supervisor/worker-supervisor.ts +14 -4
- package/src/test-helpers/fake-worker-supervisor.ts +1 -0
- package/src/test-helpers/ipc-handler-harness.ts +7 -3
- package/src/test-helpers/process-fixtures.ts +3 -3
- package/dist/chunk-G4PCN46L.js.map +0 -1
- package/dist/chunk-KVHAK5UR.js.map +0 -1
- package/dist/domain-logic/idempotency.d.ts +0 -3
- package/dist/domain-logic/idempotency.d.ts.map +0 -1
- package/dist/domain-logic/idempotency.js +0 -3
- package/dist/domain-logic/idempotency.js.map +0 -1
- package/dist/domain-logic/index.d.ts +0 -7
- package/dist/domain-logic/index.d.ts.map +0 -1
- package/dist/domain-logic/index.js +0 -6
- package/dist/domain-logic/index.js.map +0 -1
- package/dist/domain-logic/input-sequencer.d.ts +0 -16
- package/dist/domain-logic/input-sequencer.d.ts.map +0 -1
- package/dist/domain-logic/input-sequencer.js +0 -2
- package/dist/domain-logic/input-sequencer.js.map +0 -1
- package/dist/domain-logic/string-normalize.d.ts +0 -2
- package/dist/domain-logic/string-normalize.d.ts.map +0 -1
- package/dist/domain-logic/string-normalize.js +0 -2
- package/dist/domain-logic/string-normalize.js.map +0 -1
- package/dist/filesystem-process-watchers.d.ts +0 -22
- package/dist/filesystem-process-watchers.d.ts.map +0 -1
- package/dist/filesystem-process-watchers.js +0 -79
- package/dist/filesystem-process-watchers.js.map +0 -1
- package/dist/test-helpers/in-process-worker.d.ts +0 -2
- package/dist/test-helpers/in-process-worker.d.ts.map +0 -1
- package/dist/test-helpers/in-process-worker.js +0 -2
- package/dist/test-helpers/in-process-worker.js.map +0 -1
- package/dist/test-helpers/leaf-outcome-fixtures.d.ts +0 -37
- package/dist/test-helpers/leaf-outcome-fixtures.d.ts.map +0 -1
- package/dist/test-helpers/leaf-outcome-fixtures.js +0 -81
- package/dist/test-helpers/leaf-outcome-fixtures.js.map +0 -1
- package/src/domain-logic/idempotency.ts +0 -3
- package/src/domain-logic/index.ts +0 -31
- package/src/domain-logic/input-sequencer.ts +0 -18
- package/src/domain-logic/string-normalize.ts +0 -1
- package/src/filesystem-process-watchers.ts +0 -147
- package/src/test-helpers/in-process-worker.ts +0 -2
- package/src/test-helpers/leaf-outcome-fixtures.ts +0 -140
|
@@ -7,53 +7,26 @@ import type {
|
|
|
7
7
|
ProcessLaunchConfig,
|
|
8
8
|
ProcessLaunchPlan,
|
|
9
9
|
ProcessWatcherDefinition,
|
|
10
|
+
ProcessWatcherPresentation,
|
|
11
|
+
ProcessWatcherServiceLike,
|
|
12
|
+
ProcessWatcherSource,
|
|
13
|
+
RegisteredProcessWatcherLike,
|
|
10
14
|
} from "@leitwerk-dev/process-sdk";
|
|
11
15
|
import { buildProcessWatchers } from "@leitwerk-dev/process-sdk";
|
|
12
|
-
import type { ProcessWatcherType } from "@leitwerk-dev/protocol";
|
|
13
|
-
import type {
|
|
14
|
-
ProcessWatcherConfigSnapshot,
|
|
15
|
-
WatcherLaunchConfigSnapshot,
|
|
16
|
-
} from "@leitwerk-dev/protocol/config-snapshot";
|
|
17
16
|
import type { LeitwerkConfig } from "./config/config-types.js";
|
|
18
17
|
import { buildProcessLaunchPlan } from "./process-launch-plan.js";
|
|
19
18
|
import type { ServerProcessModelPolicy } from "./process-model-policy/index.js";
|
|
20
19
|
|
|
21
|
-
export
|
|
22
|
-
processId: string;
|
|
23
|
-
processDisplayName: string;
|
|
24
|
-
watcherId: string;
|
|
25
|
-
watcherLabel: string;
|
|
26
|
-
watcherDescription: string;
|
|
27
|
-
type: ProcessWatcherType;
|
|
28
|
-
enabled: boolean;
|
|
29
|
-
pollInterval: string;
|
|
30
|
-
configPath: string;
|
|
31
|
-
config: ProcessWatcherConfigSnapshot;
|
|
32
|
-
launchModelConfig: LaunchModelConfigInputLike;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface ResolvedProcessWatcherStartLike {
|
|
36
|
-
watcher: RegisteredProcessWatcherLike;
|
|
37
|
-
launchPlan: ProcessLaunchPlan;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface ProcessWatcherServiceLike {
|
|
41
|
-
listAll(): readonly RegisteredProcessWatcherLike[];
|
|
42
|
-
listByType(type: ProcessWatcherType): readonly RegisteredProcessWatcherLike[];
|
|
43
|
-
resolveLaunch(
|
|
44
|
-
processId: string,
|
|
45
|
-
watcherId: string,
|
|
46
|
-
payload: unknown,
|
|
47
|
-
ctx?: LauncherContext,
|
|
48
|
-
): Promise<ResolvedProcessWatcherStartLike | null>;
|
|
49
|
-
}
|
|
20
|
+
export type { ProcessWatcherServiceLike, RegisteredProcessWatcherLike };
|
|
50
21
|
|
|
51
22
|
interface RegisteredProcessWatcher {
|
|
52
23
|
processId: string;
|
|
53
24
|
processDisplayName: string;
|
|
54
25
|
processDef: ExtensionProcessDefinition;
|
|
55
26
|
definition: ProcessWatcherDefinition;
|
|
56
|
-
config:
|
|
27
|
+
config: unknown;
|
|
28
|
+
enabled: boolean;
|
|
29
|
+
presentation: ProcessWatcherPresentation;
|
|
57
30
|
configPath: string;
|
|
58
31
|
launchModelConfig: LaunchModelConfigInputLike;
|
|
59
32
|
}
|
|
@@ -61,6 +34,7 @@ interface RegisteredProcessWatcher {
|
|
|
61
34
|
interface ProcessWatcherRegistryOptions {
|
|
62
35
|
modelProfiles?: readonly LauncherModelProfileSummary[];
|
|
63
36
|
getModelProfilesForProcess?: (processId: string) => readonly LauncherModelProfileSummary[];
|
|
37
|
+
processModelPolicy?: ServerProcessModelPolicy;
|
|
64
38
|
}
|
|
65
39
|
|
|
66
40
|
function collectProcessWatchers(
|
|
@@ -80,7 +54,7 @@ function buildLaunchPlan(
|
|
|
80
54
|
launcherId: `${watcher.processId}.${watcher.definition.id}`,
|
|
81
55
|
metadataAdditions: {
|
|
82
56
|
processWatcherId: watcher.definition.id,
|
|
83
|
-
|
|
57
|
+
processWatcherSourceId: watcher.definition.source.id,
|
|
84
58
|
processWatcherConfigPath: watcher.configPath,
|
|
85
59
|
},
|
|
86
60
|
errorSubject: `Process watcher '${watcher.definition.id}'`,
|
|
@@ -88,39 +62,41 @@ function buildLaunchPlan(
|
|
|
88
62
|
});
|
|
89
63
|
}
|
|
90
64
|
|
|
91
|
-
function
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
65
|
+
function parseConfiguredWatcher(input: {
|
|
66
|
+
processId: string;
|
|
67
|
+
processDisplayName: string;
|
|
68
|
+
processDef: ExtensionProcessDefinition;
|
|
69
|
+
definition: ProcessWatcherDefinition;
|
|
70
|
+
rawConfig: unknown;
|
|
71
|
+
configPath: string;
|
|
72
|
+
}): RegisteredProcessWatcher {
|
|
73
|
+
try {
|
|
74
|
+
const parsed = input.definition.source.parseConfig(input.rawConfig);
|
|
75
|
+
if (typeof parsed.enabled !== "boolean") {
|
|
76
|
+
throw new Error("parseConfig() must return a boolean enabled value");
|
|
77
|
+
}
|
|
78
|
+
const presentation = input.definition.source.presentConfig(parsed.config);
|
|
79
|
+
if (presentation.targetSummary.trim() === "") {
|
|
80
|
+
throw new Error("presentConfig() must return a non-empty targetSummary");
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
processId: input.processId,
|
|
84
|
+
processDisplayName: input.processDisplayName,
|
|
85
|
+
processDef: input.processDef,
|
|
86
|
+
definition: input.definition,
|
|
87
|
+
config: parsed.config,
|
|
88
|
+
enabled: parsed.enabled,
|
|
89
|
+
presentation,
|
|
90
|
+
configPath: input.configPath,
|
|
91
|
+
launchModelConfig: parsed.launchModelConfig ?? {
|
|
92
|
+
defaultModelProfileId: null,
|
|
93
|
+
turnConfigs: {},
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
} catch (error) {
|
|
97
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
98
|
+
throw new Error(`${input.configPath}: ${message}`, { cause: error });
|
|
99
|
+
}
|
|
124
100
|
}
|
|
125
101
|
|
|
126
102
|
function validateWatcherLaunchModelConfig(
|
|
@@ -131,9 +107,6 @@ function validateWatcherLaunchModelConfig(
|
|
|
131
107
|
const errors: string[] = [];
|
|
132
108
|
const schema = policy.project({ kind: "launcher_schema", processId });
|
|
133
109
|
const llmTurnIds = new Set(schema.turns.map((turn) => turn.turnId));
|
|
134
|
-
// Watcher launch profiles are inherited server defaults. Unknown or newly
|
|
135
|
-
// disallowed profiles are skipped when the launch plan is prepared; only
|
|
136
|
-
// structural turn mistakes make watcher configuration invalid at startup.
|
|
137
110
|
for (const turnId of Object.keys(modelConfig.turnConfigs ?? {})) {
|
|
138
111
|
if (!llmTurnIds.has(turnId)) {
|
|
139
112
|
errors.push(`turn '${turnId}': is not a known LLM turn for process '${processId}'`);
|
|
@@ -142,48 +115,49 @@ function validateWatcherLaunchModelConfig(
|
|
|
142
115
|
return errors;
|
|
143
116
|
}
|
|
144
117
|
|
|
145
|
-
|
|
118
|
+
function collectConfiguredProcessWatchers(input: {
|
|
146
119
|
config: LeitwerkConfig;
|
|
147
120
|
catalog: Pick<ExtensionCatalog, "processes">;
|
|
148
121
|
processModelPolicy?: ServerProcessModelPolicy;
|
|
149
|
-
}): string[] {
|
|
122
|
+
}): { watchers: RegisteredProcessWatcher[]; errors: string[] } {
|
|
123
|
+
const watchers: RegisteredProcessWatcher[] = [];
|
|
150
124
|
const errors: string[] = [];
|
|
151
125
|
for (const [processId, processConfig] of Object.entries(input.config.process_configs ?? {})) {
|
|
152
|
-
if (!input.catalog.processes.has(processId)) {
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
126
|
const processDef = input.catalog.processes.get(processId);
|
|
156
|
-
if (!processDef)
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
(
|
|
162
|
-
|
|
163
|
-
const watcherDef = built.get(watcherId);
|
|
164
|
-
if (!watcherDef) {
|
|
165
|
-
errors.push(
|
|
166
|
-
`Unknown watcher '${watcherId}' at process_configs.${processId}.watchers.${watcherId}`,
|
|
167
|
-
);
|
|
127
|
+
if (!processDef) continue;
|
|
128
|
+
const definitions = collectProcessWatchers(processDef);
|
|
129
|
+
for (const [watcherId, rawConfig] of Object.entries(processConfig.watchers ?? {})) {
|
|
130
|
+
const configPath = `process_configs.${processId}.watchers.${watcherId}`;
|
|
131
|
+
const definition = definitions.get(watcherId);
|
|
132
|
+
if (!definition) {
|
|
133
|
+
errors.push(`Unknown watcher '${watcherId}' at ${configPath}`);
|
|
168
134
|
continue;
|
|
169
135
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
136
|
+
try {
|
|
137
|
+
const watcher = parseConfiguredWatcher({
|
|
138
|
+
processId,
|
|
139
|
+
processDisplayName: processDef.displayName,
|
|
140
|
+
processDef,
|
|
141
|
+
definition,
|
|
142
|
+
rawConfig,
|
|
143
|
+
configPath,
|
|
144
|
+
});
|
|
145
|
+
watchers.push(watcher);
|
|
146
|
+
if (input.processModelPolicy) {
|
|
147
|
+
errors.push(
|
|
148
|
+
...validateWatcherLaunchModelConfig(
|
|
149
|
+
processId,
|
|
150
|
+
watcher.launchModelConfig,
|
|
151
|
+
input.processModelPolicy,
|
|
152
|
+
),
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
} catch (error) {
|
|
156
|
+
errors.push(error instanceof Error ? error.message : String(error));
|
|
183
157
|
}
|
|
184
158
|
}
|
|
185
159
|
}
|
|
186
|
-
return errors;
|
|
160
|
+
return { watchers, errors };
|
|
187
161
|
}
|
|
188
162
|
|
|
189
163
|
export function buildProcessWatcherRegistry(
|
|
@@ -191,82 +165,65 @@ export function buildProcessWatcherRegistry(
|
|
|
191
165
|
config: LeitwerkConfig,
|
|
192
166
|
options: ProcessWatcherRegistryOptions = {},
|
|
193
167
|
): ProcessWatcherServiceLike {
|
|
194
|
-
const watchers
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
| { watchers?: Record<string, ProcessWatcherConfigSnapshot> }
|
|
202
|
-
| undefined
|
|
203
|
-
)?.watchers ?? {};
|
|
204
|
-
for (const [watcherId, watcherConfig] of Object.entries(processWatchers)) {
|
|
205
|
-
const watcherDef = built.get(watcherId);
|
|
206
|
-
if (!watcherDef || watcherDef.type !== watcherConfig.type) {
|
|
207
|
-
continue;
|
|
208
|
-
}
|
|
209
|
-
watchers.set(watcherKey(processId, watcherId), {
|
|
210
|
-
processId,
|
|
211
|
-
processDisplayName: processDef.displayName,
|
|
212
|
-
processDef,
|
|
213
|
-
definition: watcherDef,
|
|
214
|
-
config: watcherConfig,
|
|
215
|
-
configPath: `process_configs.${processId}.watchers.${watcherId}`,
|
|
216
|
-
launchModelConfig: buildWatcherLaunchModelConfig(watcherConfig.launch),
|
|
217
|
-
});
|
|
218
|
-
}
|
|
168
|
+
const { watchers, errors } = collectConfiguredProcessWatchers({
|
|
169
|
+
catalog,
|
|
170
|
+
config,
|
|
171
|
+
processModelPolicy: options.processModelPolicy,
|
|
172
|
+
});
|
|
173
|
+
if (errors.length > 0) {
|
|
174
|
+
throw new Error(`Invalid process watcher config:\n${errors.join("\n")}`);
|
|
219
175
|
}
|
|
220
176
|
|
|
221
177
|
const getDefaultModelProfilesForProcess = (
|
|
222
178
|
processId: string,
|
|
223
179
|
): readonly LauncherModelProfileSummary[] =>
|
|
224
180
|
options.getModelProfilesForProcess?.(processId) ?? options.modelProfiles ?? [];
|
|
225
|
-
|
|
226
181
|
const createWatcherContext = (processId: string, ctx: LauncherContext = {}): LauncherContext => ({
|
|
227
182
|
...ctx,
|
|
228
183
|
modelProfiles: ctx.modelProfiles ?? getDefaultModelProfilesForProcess(processId),
|
|
229
184
|
});
|
|
230
185
|
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
return processCompare
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
186
|
+
const registrations = watchers
|
|
187
|
+
.sort((a, b) => {
|
|
188
|
+
const processCompare = a.processDisplayName.localeCompare(b.processDisplayName);
|
|
189
|
+
return processCompare !== 0
|
|
190
|
+
? processCompare
|
|
191
|
+
: a.definition.label.localeCompare(b.definition.label);
|
|
192
|
+
})
|
|
193
|
+
.map((watcher) => ({
|
|
194
|
+
source: watcher.definition.source,
|
|
195
|
+
view: {
|
|
196
|
+
processId: watcher.processId,
|
|
197
|
+
processDisplayName: watcher.processDisplayName,
|
|
198
|
+
watcherId: watcher.definition.id,
|
|
199
|
+
watcherLabel: watcher.definition.label,
|
|
200
|
+
watcherDescription: watcher.definition.description,
|
|
201
|
+
sourceId: watcher.definition.source.id,
|
|
202
|
+
sourceLabel: watcher.definition.source.label,
|
|
203
|
+
enabled: watcher.enabled,
|
|
204
|
+
configPath: watcher.configPath,
|
|
205
|
+
config: structuredClone(watcher.config),
|
|
206
|
+
presentation: structuredClone(watcher.presentation),
|
|
207
|
+
launchModelConfig: structuredClone(watcher.launchModelConfig),
|
|
208
|
+
async resolveLaunch(event: unknown, ctx: LauncherContext = {}) {
|
|
209
|
+
const watcherContext = createWatcherContext(watcher.processId, ctx);
|
|
210
|
+
if (
|
|
211
|
+
watcher.definition.matches &&
|
|
212
|
+
!(await watcher.definition.matches(event, watcherContext))
|
|
213
|
+
) {
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
const launchConfig = await watcher.definition.resolveLaunchConfig(event, watcherContext);
|
|
217
|
+
return buildLaunchPlan(watcher, launchConfig, config.commit_messages);
|
|
218
|
+
},
|
|
219
|
+
} satisfies RegisteredProcessWatcherLike,
|
|
220
|
+
}));
|
|
238
221
|
|
|
239
222
|
return {
|
|
240
|
-
listAll() {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
.filter((watcher) => watcher.definition.type === type)
|
|
246
|
-
.map(buildRegistrationView);
|
|
247
|
-
},
|
|
248
|
-
async resolveLaunch(
|
|
249
|
-
processId: string,
|
|
250
|
-
watcherId: string,
|
|
251
|
-
payload: unknown,
|
|
252
|
-
ctx: LauncherContext = {},
|
|
253
|
-
) {
|
|
254
|
-
const watcher = watchers.get(watcherKey(processId, watcherId));
|
|
255
|
-
if (!watcher) {
|
|
256
|
-
return null;
|
|
257
|
-
}
|
|
258
|
-
const watcherContext = createWatcherContext(processId, ctx);
|
|
259
|
-
if (watcher.definition.matches) {
|
|
260
|
-
const matches = await watcher.definition.matches(payload, watcherContext);
|
|
261
|
-
if (!matches) {
|
|
262
|
-
return null;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
const launchConfig = await watcher.definition.resolveLaunchConfig(payload, watcherContext);
|
|
266
|
-
return {
|
|
267
|
-
watcher: buildRegistrationView(watcher),
|
|
268
|
-
launchPlan: buildLaunchPlan(watcher, launchConfig, config.commit_messages),
|
|
269
|
-
};
|
|
270
|
-
},
|
|
223
|
+
listAll: () => registrations.map(({ view }) => view),
|
|
224
|
+
listBySource: <TConfig, TEvent>(source: ProcessWatcherSource<TConfig, TEvent>) =>
|
|
225
|
+
registrations
|
|
226
|
+
.filter((watcher) => watcher.source === source)
|
|
227
|
+
.map(({ view }) => view) as RegisteredProcessWatcherLike<TConfig, TEvent>[],
|
|
271
228
|
};
|
|
272
229
|
}
|
package/src/routes/watchers.ts
CHANGED
|
@@ -42,56 +42,20 @@ function summarizeLaunchModelConfig(
|
|
|
42
42
|
|
|
43
43
|
function buildWatcherSummary(watcher: RegisteredProcessWatcherLike): WatcherSummary {
|
|
44
44
|
const launchModel = summarizeLaunchModelConfig(watcher.launchModelConfig);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
project: watcher.config.project,
|
|
60
|
-
labels: watcher.config.labels,
|
|
61
|
-
targetBranchLabelPrefix: watcher.config.target_branch_label_prefix,
|
|
62
|
-
};
|
|
63
|
-
case "gitlab_mr":
|
|
64
|
-
return {
|
|
65
|
-
processId: watcher.processId,
|
|
66
|
-
processDisplayName: watcher.processDisplayName,
|
|
67
|
-
watcherId: watcher.watcherId,
|
|
68
|
-
label: watcher.watcherLabel,
|
|
69
|
-
description: watcher.watcherDescription,
|
|
70
|
-
type: "gitlab_mr",
|
|
71
|
-
enabled: watcher.enabled,
|
|
72
|
-
pollInterval: watcher.pollInterval,
|
|
73
|
-
configPath: watcher.configPath,
|
|
74
|
-
launchModel,
|
|
75
|
-
targetSummary: `GitLab group ${watcher.config.group} · trigger ${watcher.config.labels.trigger}`,
|
|
76
|
-
group: watcher.config.group,
|
|
77
|
-
labels: watcher.config.labels,
|
|
78
|
-
};
|
|
79
|
-
case "filesystem":
|
|
80
|
-
return {
|
|
81
|
-
processId: watcher.processId,
|
|
82
|
-
processDisplayName: watcher.processDisplayName,
|
|
83
|
-
watcherId: watcher.watcherId,
|
|
84
|
-
label: watcher.watcherLabel,
|
|
85
|
-
description: watcher.watcherDescription,
|
|
86
|
-
type: "filesystem",
|
|
87
|
-
enabled: watcher.enabled,
|
|
88
|
-
pollInterval: watcher.pollInterval,
|
|
89
|
-
configPath: watcher.configPath,
|
|
90
|
-
launchModel,
|
|
91
|
-
targetSummary: `File ${watcher.config.file_path}`,
|
|
92
|
-
filePath: watcher.config.file_path,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
45
|
+
return {
|
|
46
|
+
processId: watcher.processId,
|
|
47
|
+
processDisplayName: watcher.processDisplayName,
|
|
48
|
+
watcherId: watcher.watcherId,
|
|
49
|
+
label: watcher.watcherLabel,
|
|
50
|
+
description: watcher.watcherDescription,
|
|
51
|
+
sourceId: watcher.sourceId,
|
|
52
|
+
sourceLabel: watcher.sourceLabel,
|
|
53
|
+
enabled: watcher.enabled,
|
|
54
|
+
configPath: watcher.configPath,
|
|
55
|
+
launchModel,
|
|
56
|
+
targetSummary: watcher.presentation.targetSummary,
|
|
57
|
+
details: [...(watcher.presentation.details ?? [])],
|
|
58
|
+
};
|
|
95
59
|
}
|
|
96
60
|
|
|
97
61
|
export function registerWatcherRoutes(app: FastifyInstance, deps: WatcherRouteDeps): void {
|
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
type ProcessSemanticEntryRefs,
|
|
3
3
|
type ProcessStateJsonParseContext,
|
|
4
4
|
parseProcessStateJsonStrict,
|
|
5
|
-
parseSemanticEntryRefsFromStateJsonStrict,
|
|
6
5
|
parseSemanticEntryRefsStrict,
|
|
7
6
|
} from "@leitwerk-dev/domain";
|
|
8
7
|
|
|
@@ -10,7 +9,6 @@ export type ParsedProcessSemanticEntryRefs = ProcessSemanticEntryRefs;
|
|
|
10
9
|
export type ProcessStateJsonContext = ProcessStateJsonParseContext;
|
|
11
10
|
|
|
12
11
|
export const parseProcessStateJsonRecord = parseProcessStateJsonStrict;
|
|
13
|
-
export const parseProcessSemanticRefsFromStateJson = parseSemanticEntryRefsFromStateJsonStrict;
|
|
14
12
|
|
|
15
13
|
export function parseSemanticEntryRefsFromStateRecord(
|
|
16
14
|
stateRecord: Record<string, unknown>,
|
|
@@ -4,6 +4,9 @@ import {
|
|
|
4
4
|
decodeWorkerToServerMessage,
|
|
5
5
|
type IpcEnvelope,
|
|
6
6
|
type WorkerCredentialUpdateResultPayload,
|
|
7
|
+
type WorkerIntegrationToolCancelPayload,
|
|
8
|
+
type WorkerIntegrationToolRequestPayload,
|
|
9
|
+
type WorkerIntegrationToolResultPayload,
|
|
7
10
|
type WorkerTurnStartAcceptedPayload,
|
|
8
11
|
} from "@leitwerk-dev/worker-protocol";
|
|
9
12
|
import type { RepositoryBundle } from "../db/repositories.js";
|
|
@@ -46,6 +49,14 @@ export interface IpcHandlerDeps
|
|
|
46
49
|
expectedRevision: number;
|
|
47
50
|
values: Record<string, string>;
|
|
48
51
|
}) => { accepted: boolean; currentRevision: number | null; safeReason?: string };
|
|
52
|
+
handleIntegrationToolRequest?: (
|
|
53
|
+
instanceId: string,
|
|
54
|
+
payload: WorkerIntegrationToolRequestPayload,
|
|
55
|
+
) => Promise<WorkerIntegrationToolResultPayload>;
|
|
56
|
+
handleIntegrationToolCancel?: (
|
|
57
|
+
instanceId: string,
|
|
58
|
+
payload: WorkerIntegrationToolCancelPayload,
|
|
59
|
+
) => void;
|
|
49
60
|
}
|
|
50
61
|
|
|
51
62
|
export interface IpcHandlerCallbacks {
|
|
@@ -69,6 +80,11 @@ export interface IpcHandlerCallbacks {
|
|
|
69
80
|
workerId: string,
|
|
70
81
|
payload: WorkerCredentialUpdateResultPayload,
|
|
71
82
|
) => void;
|
|
83
|
+
onIntegrationToolResult?: (
|
|
84
|
+
instanceId: string,
|
|
85
|
+
workerId: string,
|
|
86
|
+
payload: WorkerIntegrationToolResultPayload,
|
|
87
|
+
) => void;
|
|
72
88
|
}
|
|
73
89
|
|
|
74
90
|
export function createIpcHandler(deps: IpcHandlerDeps, callbacks: IpcHandlerCallbacks) {
|
|
@@ -103,6 +119,25 @@ export function createIpcHandler(deps: IpcHandlerDeps, callbacks: IpcHandlerCall
|
|
|
103
119
|
);
|
|
104
120
|
|
|
105
121
|
switch (msg.type) {
|
|
122
|
+
case "worker.integration_tool_cancel": {
|
|
123
|
+
deps.handleIntegrationToolCancel?.(instanceId, msg.payload);
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
case "worker.integration_tool_request": {
|
|
127
|
+
if (!deps.handleIntegrationToolRequest) break;
|
|
128
|
+
void deps
|
|
129
|
+
.handleIntegrationToolRequest(instanceId, msg.payload)
|
|
130
|
+
.then((payload) => callbacks.onIntegrationToolResult?.(instanceId, workerId, payload))
|
|
131
|
+
.catch(() =>
|
|
132
|
+
callbacks.onIntegrationToolResult?.(instanceId, workerId, {
|
|
133
|
+
turnRecordId: msg.payload.turnRecordId,
|
|
134
|
+
toolCallId: msg.payload.toolCallId,
|
|
135
|
+
ok: false,
|
|
136
|
+
error: "Integration tool execution failed",
|
|
137
|
+
}),
|
|
138
|
+
);
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
106
141
|
case "worker.credential_update": {
|
|
107
142
|
const result = deps.updateCredential?.(msg.payload) ?? {
|
|
108
143
|
accepted: false,
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
} from "@leitwerk-dev/worker-protocol";
|
|
18
18
|
import type { LeitwerkConfig } from "../config/config-types.js";
|
|
19
19
|
import type { RepositoryBundle } from "../db/repositories.js";
|
|
20
|
+
import type { ResolvedProviderCredential } from "../model-providers/credentials.js";
|
|
20
21
|
import type { ProcessActionRegistry } from "../process-action-registry.js";
|
|
21
22
|
import { getProcessTurnGraph, type ProcessGraphRegistry } from "../process-graph.js";
|
|
22
23
|
import { toInputDelivery } from "../process-input-dispatch.js";
|
|
@@ -46,7 +47,12 @@ export interface WorkerStartPayloadBuilderDeps
|
|
|
46
47
|
resolveCredential?(
|
|
47
48
|
providerId: string,
|
|
48
49
|
options: Readonly<Record<string, string>>,
|
|
49
|
-
):
|
|
50
|
+
): Pick<ResolvedProviderCredential, "revision" | "values"> | null;
|
|
51
|
+
integrationTools?: {
|
|
52
|
+
declarations(
|
|
53
|
+
names: readonly string[],
|
|
54
|
+
): import("@leitwerk-dev/worker-protocol").IntegrationToolDeclaration[];
|
|
55
|
+
};
|
|
50
56
|
}
|
|
51
57
|
|
|
52
58
|
export function buildWorkerRuntimeSettingsSnapshot(
|
|
@@ -296,6 +302,19 @@ export function createWorkerStartPayloadBuilder(deps: WorkerStartPayloadBuilderD
|
|
|
296
302
|
projects: deps.projects.listByInstance(process.id),
|
|
297
303
|
}) ?? [];
|
|
298
304
|
const bootstrap = resolveBootstrap(start, deps);
|
|
305
|
+
const selectedTurn = deps.processActionRegistry.getTurnDefinition(
|
|
306
|
+
process.processId,
|
|
307
|
+
start.turnId,
|
|
308
|
+
);
|
|
309
|
+
const integrationToolNames =
|
|
310
|
+
selectedTurn?.kind === "llm" ? (selectedTurn.integrationTools ?? []) : [];
|
|
311
|
+
const integrationTools =
|
|
312
|
+
integrationToolNames.length > 0
|
|
313
|
+
? deps.integrationTools?.declarations(integrationToolNames)
|
|
314
|
+
: undefined;
|
|
315
|
+
if (integrationToolNames.length > 0 && !integrationTools) {
|
|
316
|
+
throw new Error(`Integration tools are unavailable for turn '${start.turnId}'`);
|
|
317
|
+
}
|
|
299
318
|
const payloadBase = {
|
|
300
319
|
...contextSnapshot,
|
|
301
320
|
workerLeaseId: lease.id,
|
|
@@ -310,6 +329,7 @@ export function createWorkerStartPayloadBuilder(deps: WorkerStartPayloadBuilderD
|
|
|
310
329
|
workerRuntimeSettings: buildWorkerRuntimeSettingsSnapshot(deps.config),
|
|
311
330
|
...(treePaths.resume ? { resumeLeafEntryId } : {}),
|
|
312
331
|
...(repositoryCredentials.length > 0 ? { repositoryCredentials } : {}),
|
|
332
|
+
...(integrationTools && integrationTools.length > 0 ? { integrationTools } : {}),
|
|
313
333
|
};
|
|
314
334
|
const payload: WorkerStartPayload =
|
|
315
335
|
bootstrap.kind === "llm"
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
WORKER_SNAPSHOT_TOKEN_ENV,
|
|
21
21
|
type WorkerCredentialUpdateResultPayload,
|
|
22
22
|
type WorkerHelloPayload,
|
|
23
|
+
type WorkerIntegrationToolResultPayload,
|
|
23
24
|
type WorkerQuestionResponsePayload,
|
|
24
25
|
} from "@leitwerk-dev/worker-protocol";
|
|
25
26
|
import type {
|
|
@@ -79,10 +80,8 @@ export interface SupervisorDeps
|
|
|
79
80
|
serverEpoch?: string;
|
|
80
81
|
resolveResourceBundle?: (digest: string) => PiResourceBundle | null;
|
|
81
82
|
resolveRepositoryCredentials?: WorkerStartPayloadBuilderDeps["resolveRepositoryCredentials"];
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
options: Readonly<Record<string, string>>,
|
|
85
|
-
) => { revision: number; values: Record<string, string> } | null;
|
|
83
|
+
integrationTools?: WorkerStartPayloadBuilderDeps["integrationTools"];
|
|
84
|
+
resolveCredential?: WorkerStartPayloadBuilderDeps["resolveCredential"];
|
|
86
85
|
}
|
|
87
86
|
|
|
88
87
|
export interface WorkerHandle {
|
|
@@ -133,6 +132,11 @@ export interface WorkerSupervisor {
|
|
|
133
132
|
workerId: string,
|
|
134
133
|
payload: WorkerCredentialUpdateResultPayload,
|
|
135
134
|
): void;
|
|
135
|
+
integrationToolResult(
|
|
136
|
+
instanceId: string,
|
|
137
|
+
workerId: string,
|
|
138
|
+
payload: WorkerIntegrationToolResultPayload,
|
|
139
|
+
): void;
|
|
136
140
|
getWorker(instanceId: string): WorkerHandle | undefined;
|
|
137
141
|
isAdoptionPending(instanceId: string): boolean;
|
|
138
142
|
adoptRegisteredWorkers(): Promise<void>;
|
|
@@ -856,6 +860,12 @@ export function createWorkerSupervisor(deps: SupervisorDeps): WorkerSupervisor {
|
|
|
856
860
|
questionResponse(instanceId, workerId, payload) {
|
|
857
861
|
sendToCurrentWorker(instanceId, workerId, { type: "worker.question_response", payload });
|
|
858
862
|
},
|
|
863
|
+
integrationToolResult(instanceId, workerId, payload) {
|
|
864
|
+
sendToCurrentWorker(instanceId, workerId, {
|
|
865
|
+
type: "worker.integration_tool_result",
|
|
866
|
+
payload,
|
|
867
|
+
});
|
|
868
|
+
},
|
|
859
869
|
credentialUpdateResult(instanceId, workerId, payload) {
|
|
860
870
|
sendToCurrentWorker(instanceId, workerId, {
|
|
861
871
|
type: "worker.credential_update_accepted",
|
|
@@ -58,7 +58,7 @@ interface TestProcessState {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
const testProcessGraphRegistry = createDefaultTestProcessGraphRegistry();
|
|
61
|
-
const
|
|
61
|
+
const ticketTurnGraph = getProcessGraph(testProcessGraphRegistry, "ticket_issue_process");
|
|
62
62
|
const mrPolishGraph = getProcessGraph(testProcessGraphRegistry, "mr_polish_process");
|
|
63
63
|
|
|
64
64
|
function parseReviewSubject(value: unknown): ReviewSubject | null {
|
|
@@ -246,7 +246,7 @@ const testTurns = new Map<string, TurnDefinition<Record<string, never>, TestProc
|
|
|
246
246
|
],
|
|
247
247
|
]);
|
|
248
248
|
|
|
249
|
-
const
|
|
249
|
+
const ticketTurnProcess = createTestProcess("ticket_issue_process", ticketTurnGraph, (api) => {
|
|
250
250
|
api.onTurnOutcome("generate_plan", async (event, ctx) => {
|
|
251
251
|
if (event.outcome !== "plan_saved") {
|
|
252
252
|
return;
|
|
@@ -348,7 +348,7 @@ const mrPolishProcess = createTestProcess("mr_polish_process", mrPolishGraph, (a
|
|
|
348
348
|
});
|
|
349
349
|
|
|
350
350
|
const testProcessGraphs = new Map<string, ExtensionProcessDefinition>([
|
|
351
|
-
[
|
|
351
|
+
[ticketTurnProcess.id, ticketTurnProcess as ExtensionProcessDefinition],
|
|
352
352
|
[mrPolishProcess.id, mrPolishProcess as ExtensionProcessDefinition],
|
|
353
353
|
]);
|
|
354
354
|
|
|
@@ -368,6 +368,9 @@ export function createTestIpcHandler(
|
|
|
368
368
|
opts: {
|
|
369
369
|
toastTtlMs?: number;
|
|
370
370
|
workerEventLogger?: Parameters<typeof createIpcHandler>[0]["workerEventLogger"];
|
|
371
|
+
handleIntegrationToolCancel?: Parameters<
|
|
372
|
+
typeof createIpcHandler
|
|
373
|
+
>[0]["handleIntegrationToolCancel"];
|
|
371
374
|
} = {},
|
|
372
375
|
) {
|
|
373
376
|
const processOperations = createProcessOperationCoordinator();
|
|
@@ -431,6 +434,7 @@ export function createTestIpcHandler(
|
|
|
431
434
|
events: deps.events,
|
|
432
435
|
leases: deps.leases,
|
|
433
436
|
turnRecords: deps.turnRecords,
|
|
437
|
+
handleIntegrationToolCancel: opts.handleIntegrationToolCancel,
|
|
434
438
|
processQuestions,
|
|
435
439
|
broadcaster: deps.broadcaster,
|
|
436
440
|
commands,
|