@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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { isIP } from "node:net";
|
|
2
3
|
import { resolve } from "node:path";
|
|
3
4
|
import { parseDurationMs } from "@leitwerk-dev/watcher-utils";
|
|
4
5
|
import { createDefu } from "defu";
|
|
@@ -134,50 +135,10 @@ const modelTurnConfigSchema = v.looseObject({
|
|
|
134
135
|
model_profile: v.optional(v.string()),
|
|
135
136
|
});
|
|
136
137
|
|
|
137
|
-
const watcherLaunchConfigSchema = v.looseObject({
|
|
138
|
-
default_model_profile: v.optional(v.string()),
|
|
139
|
-
turn_configs: v.optional(v.record(v.string(), modelTurnConfigSchema)),
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
const jiraWatcherSchema = v.looseObject({
|
|
143
|
-
type: v.literal("jira"),
|
|
144
|
-
enabled: v.boolean(),
|
|
145
|
-
project: v.string(),
|
|
146
|
-
poll_interval: v.string(),
|
|
147
|
-
labels: v.looseObject({
|
|
148
|
-
trigger: v.string(),
|
|
149
|
-
done: v.string(),
|
|
150
|
-
required: v.optional(stringArraySchema),
|
|
151
|
-
forbidden: v.optional(stringArraySchema),
|
|
152
|
-
}),
|
|
153
|
-
target_branch_label_prefix: v.string(),
|
|
154
|
-
launch: v.optional(watcherLaunchConfigSchema),
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
const gitlabMrWatcherSchema = v.looseObject({
|
|
158
|
-
type: v.literal("gitlab_mr"),
|
|
159
|
-
enabled: v.boolean(),
|
|
160
|
-
group: v.string(),
|
|
161
|
-
poll_interval: v.string(),
|
|
162
|
-
labels: v.looseObject({
|
|
163
|
-
trigger: v.string(),
|
|
164
|
-
done: v.string(),
|
|
165
|
-
}),
|
|
166
|
-
launch: v.optional(watcherLaunchConfigSchema),
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
const filesystemWatcherSchema = v.looseObject({
|
|
170
|
-
type: v.literal("filesystem"),
|
|
171
|
-
enabled: v.boolean(),
|
|
172
|
-
poll_interval: v.string(),
|
|
173
|
-
file_path: v.string(),
|
|
174
|
-
launch: v.optional(watcherLaunchConfigSchema),
|
|
175
|
-
});
|
|
176
|
-
|
|
177
138
|
const authNonEmptyString = v.pipe(v.string(), v.nonEmpty());
|
|
178
139
|
|
|
179
140
|
const authOidcProviderSchema = v.looseObject({
|
|
180
|
-
id:
|
|
141
|
+
id: authNonEmptyString,
|
|
181
142
|
kind: v.literal("oidc"),
|
|
182
143
|
issuer: authNonEmptyString,
|
|
183
144
|
client_id: authNonEmptyString,
|
|
@@ -187,6 +148,15 @@ const authOidcProviderSchema = v.looseObject({
|
|
|
187
148
|
identity_claim: v.optional(authNonEmptyString),
|
|
188
149
|
});
|
|
189
150
|
|
|
151
|
+
const authGithubProviderSchema = v.looseObject({
|
|
152
|
+
id: v.literal("github"),
|
|
153
|
+
kind: v.literal("oauth2"),
|
|
154
|
+
client_id: authNonEmptyString,
|
|
155
|
+
client_secret: authNonEmptyString,
|
|
156
|
+
organization: authNonEmptyString,
|
|
157
|
+
redirect_uri: v.optional(authNonEmptyString),
|
|
158
|
+
});
|
|
159
|
+
|
|
190
160
|
const authConfigSchema = v.looseObject({
|
|
191
161
|
enabled: v.optional(v.boolean()),
|
|
192
162
|
session: v.optional(
|
|
@@ -195,17 +165,27 @@ const authConfigSchema = v.looseObject({
|
|
|
195
165
|
ttl: v.optional(authNonEmptyString),
|
|
196
166
|
}),
|
|
197
167
|
),
|
|
198
|
-
providers: v.optional(
|
|
168
|
+
providers: v.optional(
|
|
169
|
+
v.array(v.variant("kind", [authOidcProviderSchema, authGithubProviderSchema])),
|
|
170
|
+
),
|
|
199
171
|
allowlist: v.optional(stringArraySchema),
|
|
200
172
|
});
|
|
201
173
|
|
|
202
|
-
const processWatcherConfigSchema = v.variant("type", [
|
|
203
|
-
jiraWatcherSchema,
|
|
204
|
-
gitlabMrWatcherSchema,
|
|
205
|
-
filesystemWatcherSchema,
|
|
206
|
-
]);
|
|
207
|
-
|
|
208
174
|
const safeSkillIdSchema = v.pipe(v.string(), v.regex(SAFE_SKILL_ID_PATTERN));
|
|
175
|
+
const kubernetesHostAliasIpSchema = v.pipe(
|
|
176
|
+
v.string(),
|
|
177
|
+
v.nonEmpty(),
|
|
178
|
+
v.check((value) => isIP(value) !== 0, "Expected an IPv4 or IPv6 address"),
|
|
179
|
+
);
|
|
180
|
+
const kubernetesHostnameSchema = v.pipe(
|
|
181
|
+
v.string(),
|
|
182
|
+
v.nonEmpty(),
|
|
183
|
+
v.maxLength(253),
|
|
184
|
+
v.regex(
|
|
185
|
+
/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/u,
|
|
186
|
+
"Expected a lowercase DNS hostname",
|
|
187
|
+
),
|
|
188
|
+
);
|
|
209
189
|
const skillSchema = v.strictObject({
|
|
210
190
|
id: safeSkillIdSchema,
|
|
211
191
|
label: v.optional(v.pipe(v.string(), v.nonEmpty())),
|
|
@@ -333,7 +313,7 @@ const configSchema = v.looseObject({
|
|
|
333
313
|
}),
|
|
334
314
|
),
|
|
335
315
|
turn_configs: v.optional(v.record(v.string(), modelTurnConfigSchema)),
|
|
336
|
-
watchers: v.optional(v.record(v.string(),
|
|
316
|
+
watchers: v.optional(v.record(v.string(), v.unknown())),
|
|
337
317
|
}),
|
|
338
318
|
),
|
|
339
319
|
),
|
|
@@ -392,6 +372,14 @@ const configSchema = v.looseObject({
|
|
|
392
372
|
node_selector: v.optional(v.record(v.string(), v.string())),
|
|
393
373
|
tolerations: v.optional(v.array(v.unknown())),
|
|
394
374
|
annotations: v.optional(v.record(v.string(), v.string())),
|
|
375
|
+
host_aliases: v.optional(
|
|
376
|
+
v.array(
|
|
377
|
+
v.strictObject({
|
|
378
|
+
ip: kubernetesHostAliasIpSchema,
|
|
379
|
+
hostnames: v.pipe(v.array(kubernetesHostnameSchema), v.nonEmpty()),
|
|
380
|
+
}),
|
|
381
|
+
),
|
|
382
|
+
),
|
|
395
383
|
}),
|
|
396
384
|
),
|
|
397
385
|
image_pull_secrets: v.optional(stringArraySchema),
|
|
@@ -470,27 +458,6 @@ function collectConfigSchemaErrors(config: unknown): string[] {
|
|
|
470
458
|
return parsed.issues.map((issue) => formatConfigSchemaIssue(issue).message);
|
|
471
459
|
}
|
|
472
460
|
|
|
473
|
-
function validateModelProfileReference(args: {
|
|
474
|
-
value: unknown;
|
|
475
|
-
path: string;
|
|
476
|
-
errors: string[];
|
|
477
|
-
configuredModelProfileIds: Set<string>;
|
|
478
|
-
allowedModelProfileIds: Set<string> | null;
|
|
479
|
-
}) {
|
|
480
|
-
if (typeof args.value !== "string" || args.value.trim() === "") {
|
|
481
|
-
return;
|
|
482
|
-
}
|
|
483
|
-
if (!args.configuredModelProfileIds.has(args.value)) {
|
|
484
|
-
args.errors.push(`Unknown model profile '${args.value}' at ${args.path}`);
|
|
485
|
-
return;
|
|
486
|
-
}
|
|
487
|
-
if (args.allowedModelProfileIds !== null && !args.allowedModelProfileIds.has(args.value)) {
|
|
488
|
-
args.errors.push(
|
|
489
|
-
`Model profile '${args.value}' at ${args.path} is not in allowed_model_profiles`,
|
|
490
|
-
);
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
|
|
494
461
|
function collectModelProfileReferenceErrors(config: LeitwerkConfig): string[] {
|
|
495
462
|
const errors: string[] = [];
|
|
496
463
|
const configuredModelProfileIds = new Set(
|
|
@@ -512,9 +479,7 @@ function collectModelProfileReferenceErrors(config: LeitwerkConfig): string[] {
|
|
|
512
479
|
}
|
|
513
480
|
for (const [processId, processConfig] of Object.entries(config.process_configs ?? {})) {
|
|
514
481
|
const processConfigPath = `process_configs.${processId}`;
|
|
515
|
-
let processAllowedProfiles: Set<string> | null = null;
|
|
516
482
|
if (processConfig.allowed_model_profiles !== undefined) {
|
|
517
|
-
processAllowedProfiles = new Set<string>();
|
|
518
483
|
for (const [index, profileId] of processConfig.allowed_model_profiles.entries()) {
|
|
519
484
|
const allowedProfilePath = `${processConfigPath}.allowed_model_profiles[${index}]`;
|
|
520
485
|
if (typeof profileId !== "string" || profileId.trim() === "") {
|
|
@@ -522,32 +487,7 @@ function collectModelProfileReferenceErrors(config: LeitwerkConfig): string[] {
|
|
|
522
487
|
}
|
|
523
488
|
if (!configuredModelProfileIds.has(profileId)) {
|
|
524
489
|
errors.push(`Unknown model profile '${profileId}' at ${allowedProfilePath}`);
|
|
525
|
-
continue;
|
|
526
490
|
}
|
|
527
|
-
processAllowedProfiles.add(profileId);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
for (const [watcherId, watcherConfig] of Object.entries(processConfig.watchers ?? {})) {
|
|
531
|
-
const launch = watcherConfig.launch;
|
|
532
|
-
if (!launch) {
|
|
533
|
-
continue;
|
|
534
|
-
}
|
|
535
|
-
const watcherPath = `${processConfigPath}.watchers.${watcherId}`;
|
|
536
|
-
validateModelProfileReference({
|
|
537
|
-
value: launch.default_model_profile,
|
|
538
|
-
path: `${watcherPath}.launch.default_model_profile`,
|
|
539
|
-
errors,
|
|
540
|
-
configuredModelProfileIds,
|
|
541
|
-
allowedModelProfileIds: processAllowedProfiles,
|
|
542
|
-
});
|
|
543
|
-
for (const [turnId, turnConfig] of Object.entries(launch.turn_configs ?? {})) {
|
|
544
|
-
validateModelProfileReference({
|
|
545
|
-
value: turnConfig.model_profile,
|
|
546
|
-
path: `${watcherPath}.launch.turn_configs.${turnId}.model_profile`,
|
|
547
|
-
errors,
|
|
548
|
-
configuredModelProfileIds,
|
|
549
|
-
allowedModelProfileIds: processAllowedProfiles,
|
|
550
|
-
});
|
|
551
491
|
}
|
|
552
492
|
}
|
|
553
493
|
}
|
|
@@ -829,7 +769,9 @@ function collectAuthConfigErrors(config: LeitwerkConfig): string[] {
|
|
|
829
769
|
}
|
|
830
770
|
const providers = auth.providers ?? [];
|
|
831
771
|
if (providers.length === 0) {
|
|
832
|
-
errors.push(
|
|
772
|
+
errors.push(
|
|
773
|
+
"auth.providers must include one authentication provider when auth.enabled is true",
|
|
774
|
+
);
|
|
833
775
|
}
|
|
834
776
|
if (providers.length > 1) {
|
|
835
777
|
errors.push("auth.providers currently supports exactly one provider");
|
|
@@ -838,10 +780,7 @@ function collectAuthConfigErrors(config: LeitwerkConfig): string[] {
|
|
|
838
780
|
errors.push("server.base_url must use https when auth is enabled, except for localhost");
|
|
839
781
|
}
|
|
840
782
|
for (const [index, provider] of providers.entries()) {
|
|
841
|
-
if (provider.
|
|
842
|
-
errors.push(`auth.providers[${index}].id must be forgejo in Phase 1`);
|
|
843
|
-
}
|
|
844
|
-
if (!isHttpsOrLoopbackHttpUrl(provider.issuer)) {
|
|
783
|
+
if (provider.kind === "oidc" && !isHttpsOrLoopbackHttpUrl(provider.issuer)) {
|
|
845
784
|
errors.push(
|
|
846
785
|
`auth.providers[${index}].issuer must be an absolute https URL, except for localhost`,
|
|
847
786
|
);
|
|
@@ -1100,7 +1039,7 @@ export function getDefaultConfig(): LeitwerkConfig {
|
|
|
1100
1039
|
access_modes: ["ReadWriteOnce"],
|
|
1101
1040
|
mount_path: "/state",
|
|
1102
1041
|
},
|
|
1103
|
-
pod: { node_selector: {}, tolerations: [], annotations: {} },
|
|
1042
|
+
pod: { node_selector: {}, tolerations: [], annotations: {}, host_aliases: [] },
|
|
1104
1043
|
image_pull_secrets: [],
|
|
1105
1044
|
image_pull_secret_copies: [],
|
|
1106
1045
|
},
|
|
@@ -60,7 +60,7 @@ export interface AuthSessionConfig {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
export interface AuthOidcProviderConfig {
|
|
63
|
-
id:
|
|
63
|
+
id: string;
|
|
64
64
|
kind: "oidc";
|
|
65
65
|
issuer: string;
|
|
66
66
|
client_id: string;
|
|
@@ -70,12 +70,24 @@ export interface AuthOidcProviderConfig {
|
|
|
70
70
|
identity_claim?: string;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
export interface AuthGithubProviderConfig {
|
|
74
|
+
id: "github";
|
|
75
|
+
kind: "oauth2";
|
|
76
|
+
client_id: string;
|
|
77
|
+
client_secret: string;
|
|
78
|
+
/** GitHub organization whose active members may sign in. */
|
|
79
|
+
organization: string;
|
|
80
|
+
redirect_uri?: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export type AuthProviderConfig = AuthOidcProviderConfig | AuthGithubProviderConfig;
|
|
84
|
+
|
|
73
85
|
export interface AuthConfig {
|
|
74
86
|
/** Only true enables authentication; omit or set false to keep the leitwerk unauthenticated. */
|
|
75
87
|
enabled?: boolean;
|
|
76
88
|
session?: AuthSessionConfig;
|
|
77
|
-
providers?:
|
|
78
|
-
/** Raw identity claim values that may sign in.
|
|
89
|
+
providers?: AuthProviderConfig[];
|
|
90
|
+
/** Raw OIDC identity claim values that may sign in. GitHub uses organization membership. */
|
|
79
91
|
allowlist?: string[];
|
|
80
92
|
}
|
|
81
93
|
|
|
@@ -129,10 +141,16 @@ export interface KubernetesProcessVolumeConfig {
|
|
|
129
141
|
mount_path: string;
|
|
130
142
|
}
|
|
131
143
|
|
|
144
|
+
export interface KubernetesHostAliasConfig {
|
|
145
|
+
ip: string;
|
|
146
|
+
hostnames: string[];
|
|
147
|
+
}
|
|
148
|
+
|
|
132
149
|
export interface KubernetesPodConfig {
|
|
133
150
|
node_selector?: Record<string, string>;
|
|
134
151
|
tolerations?: unknown[];
|
|
135
152
|
annotations?: Record<string, string>;
|
|
153
|
+
host_aliases?: KubernetesHostAliasConfig[];
|
|
136
154
|
}
|
|
137
155
|
|
|
138
156
|
export interface KubernetesImagePullSecretCopyConfig {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { OutcomeToolParameterSpec, TurnDefinition } from "@leitwerk-dev/process-sdk";
|
|
1
|
+
import { normalizeStringArray, type TurnOutcomePayload, trimString } from "@leitwerk-dev/domain";
|
|
3
2
|
import {
|
|
4
3
|
isAutomaticTurnDefinition,
|
|
5
4
|
isLlmTurnDefinition,
|
|
6
5
|
isServerAutomaticTurnDefinition,
|
|
6
|
+
type OutcomeToolParameterSpec,
|
|
7
|
+
type TurnDefinition,
|
|
7
8
|
} from "@leitwerk-dev/process-sdk";
|
|
8
9
|
import * as v from "valibot";
|
|
9
10
|
import { isTurnAvailableForProcessGraph, type ProcessGraphRegistry } from "../process-graph.js";
|
|
10
|
-
import { normalizeStringArray, trimString } from "./string-normalize.js";
|
|
11
11
|
|
|
12
12
|
interface OutcomeToolValidationContract {
|
|
13
13
|
kind: "outcome_tool";
|
package/src/index.ts
CHANGED
|
@@ -116,10 +116,7 @@ export {
|
|
|
116
116
|
type ProcessTitleGenerator,
|
|
117
117
|
type ProcessTitleLogger,
|
|
118
118
|
} from "./process-title-generator.js";
|
|
119
|
-
export {
|
|
120
|
-
buildProcessWatcherRegistry,
|
|
121
|
-
validateConfiguredProcessWatchersAgainstCatalog,
|
|
122
|
-
} from "./process-watcher-registry.js";
|
|
119
|
+
export { buildProcessWatcherRegistry } from "./process-watcher-registry.js";
|
|
123
120
|
export {
|
|
124
121
|
buildProjectUpdatedEffect,
|
|
125
122
|
buildProjectUpdatedFrame,
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type IntegrationToolDefinition,
|
|
3
|
+
type IntegrationToolExecutionContext,
|
|
4
|
+
RESERVED_INTEGRATION_TOOL_NAMES,
|
|
5
|
+
} from "@leitwerk-dev/process-sdk";
|
|
6
|
+
import type {
|
|
7
|
+
IntegrationToolDeclaration,
|
|
8
|
+
WorkerIntegrationToolCancelPayload,
|
|
9
|
+
WorkerIntegrationToolRequestPayload,
|
|
10
|
+
WorkerIntegrationToolResultPayload,
|
|
11
|
+
} from "@leitwerk-dev/worker-protocol";
|
|
12
|
+
import type { RepositoryBundle } from "./db/repositories.js";
|
|
13
|
+
import type { ProcessActionRegistry } from "./process-action-registry.js";
|
|
14
|
+
|
|
15
|
+
type RegisteredIntegrationTool = IntegrationToolDefinition<unknown>;
|
|
16
|
+
type IntegrationToolExecutionInput = Omit<IntegrationToolExecutionContext, "signal">;
|
|
17
|
+
|
|
18
|
+
interface PendingIntegrationToolExecution {
|
|
19
|
+
readonly controller: AbortController;
|
|
20
|
+
readonly promise: Promise<unknown>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const TOOL_NAME = /^[a-z][a-z0-9_]{0,63}$/;
|
|
24
|
+
const RESERVED_TOOL_NAMES = new Set<string>(RESERVED_INTEGRATION_TOOL_NAMES);
|
|
25
|
+
|
|
26
|
+
function parseToolArgs(value: unknown): Record<string, unknown> {
|
|
27
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
28
|
+
throw new Error("Integration tool arguments must be an object");
|
|
29
|
+
}
|
|
30
|
+
return value as Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class IntegrationToolRegistry {
|
|
34
|
+
private readonly tools = new Map<string, RegisteredIntegrationTool>();
|
|
35
|
+
private readonly executions = new Map<string, PendingIntegrationToolExecution>();
|
|
36
|
+
|
|
37
|
+
register<TArgs>(definition: IntegrationToolDefinition<TArgs>): void {
|
|
38
|
+
const name = definition.name;
|
|
39
|
+
if (!TOOL_NAME.test(name)) {
|
|
40
|
+
throw new Error(`Integration tool '${definition.name}' must match ${TOOL_NAME}`);
|
|
41
|
+
}
|
|
42
|
+
if (RESERVED_TOOL_NAMES.has(name)) {
|
|
43
|
+
throw new Error(`Integration tool '${name}' uses a reserved tool name`);
|
|
44
|
+
}
|
|
45
|
+
if (definition.description.trim() === "") {
|
|
46
|
+
throw new Error(`Integration tool '${name}' requires a description`);
|
|
47
|
+
}
|
|
48
|
+
if (this.tools.has(name)) throw new Error(`Duplicate integration tool '${name}'`);
|
|
49
|
+
this.tools.set(name, definition as RegisteredIntegrationTool);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declarations(names: readonly string[]): IntegrationToolDeclaration[] {
|
|
53
|
+
return names.map((name) => {
|
|
54
|
+
const definition = this.tools.get(name);
|
|
55
|
+
if (!definition) throw new Error(`Unknown integration tool '${name}'`);
|
|
56
|
+
return {
|
|
57
|
+
name: definition.name,
|
|
58
|
+
description: definition.description,
|
|
59
|
+
parameters: definition.parameters,
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
execute(name: string, args: unknown, ctx: IntegrationToolExecutionInput): Promise<unknown> {
|
|
65
|
+
const definition = this.tools.get(name);
|
|
66
|
+
if (!definition) return Promise.reject(new Error(`Unknown integration tool '${name}'`));
|
|
67
|
+
const existing = this.executions.get(ctx.idempotencyKey);
|
|
68
|
+
if (existing) return existing.promise;
|
|
69
|
+
const controller = new AbortController();
|
|
70
|
+
const promise = Promise.resolve()
|
|
71
|
+
.then(() => {
|
|
72
|
+
if (controller.signal.aborted) {
|
|
73
|
+
throw new Error("Integration tool execution cancelled");
|
|
74
|
+
}
|
|
75
|
+
return definition.execute(
|
|
76
|
+
{ ...ctx, signal: controller.signal },
|
|
77
|
+
definition.parse?.(args) ?? parseToolArgs(args),
|
|
78
|
+
);
|
|
79
|
+
})
|
|
80
|
+
.finally(() => this.executions.delete(ctx.idempotencyKey));
|
|
81
|
+
this.executions.set(ctx.idempotencyKey, { controller, promise });
|
|
82
|
+
return promise;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
cancel(idempotencyKey: string): boolean {
|
|
86
|
+
const execution = this.executions.get(idempotencyKey);
|
|
87
|
+
if (!execution) return false;
|
|
88
|
+
execution.controller.abort();
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function integrationToolIdempotencyKey(input: {
|
|
94
|
+
instanceId: string;
|
|
95
|
+
turnRecordId: string;
|
|
96
|
+
toolCallId: string;
|
|
97
|
+
toolName: string;
|
|
98
|
+
}): string {
|
|
99
|
+
return `${input.instanceId}:${input.turnRecordId}:${input.toolCallId}:${input.toolName}`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function createIntegrationToolRequestService(input: {
|
|
103
|
+
registry: IntegrationToolRegistry;
|
|
104
|
+
repos: Pick<RepositoryBundle, "processes" | "projects" | "turnRecords" | "turnStarts">;
|
|
105
|
+
processActionRegistry: Pick<ProcessActionRegistry, "getTurnDefinition">;
|
|
106
|
+
}) {
|
|
107
|
+
return {
|
|
108
|
+
cancel(instanceId: string, payload: WorkerIntegrationToolCancelPayload): boolean {
|
|
109
|
+
return input.registry.cancel(
|
|
110
|
+
integrationToolIdempotencyKey({
|
|
111
|
+
instanceId,
|
|
112
|
+
turnRecordId: payload.turnRecordId,
|
|
113
|
+
toolCallId: payload.toolCallId,
|
|
114
|
+
toolName: payload.toolName,
|
|
115
|
+
}),
|
|
116
|
+
);
|
|
117
|
+
},
|
|
118
|
+
async handle(
|
|
119
|
+
instanceId: string,
|
|
120
|
+
payload: WorkerIntegrationToolRequestPayload,
|
|
121
|
+
): Promise<WorkerIntegrationToolResultPayload> {
|
|
122
|
+
const fail = (error: string): WorkerIntegrationToolResultPayload => ({
|
|
123
|
+
turnRecordId: payload.turnRecordId,
|
|
124
|
+
toolCallId: payload.toolCallId,
|
|
125
|
+
ok: false,
|
|
126
|
+
error,
|
|
127
|
+
});
|
|
128
|
+
const process = input.repos.processes.getById(instanceId);
|
|
129
|
+
const turn = input.repos.turnRecords.getById(payload.turnRecordId);
|
|
130
|
+
if (!process || !turn || turn.instanceId !== instanceId || turn.status !== "running") {
|
|
131
|
+
return fail("Integration tool call does not belong to the active running turn");
|
|
132
|
+
}
|
|
133
|
+
const currentStart =
|
|
134
|
+
process.currentExecution?.kind === "worker_start"
|
|
135
|
+
? input.repos.turnStarts.getById(process.currentExecution.id)
|
|
136
|
+
: null;
|
|
137
|
+
const expectedTurnRecordId =
|
|
138
|
+
currentStart?.state.kind === "accepted" ? currentStart.state.turnRecordId : null;
|
|
139
|
+
if (expectedTurnRecordId !== payload.turnRecordId) {
|
|
140
|
+
return fail("Integration tool call targets a stale turn record");
|
|
141
|
+
}
|
|
142
|
+
if (process.selectedTurnId !== turn.turnId) {
|
|
143
|
+
return fail("Integration tool call targets a stale turn");
|
|
144
|
+
}
|
|
145
|
+
const turnDefinition = input.processActionRegistry.getTurnDefinition(
|
|
146
|
+
process.processId,
|
|
147
|
+
turn.turnId,
|
|
148
|
+
);
|
|
149
|
+
if (
|
|
150
|
+
turnDefinition?.kind !== "llm" ||
|
|
151
|
+
!turnDefinition.integrationTools?.includes(payload.toolName)
|
|
152
|
+
) {
|
|
153
|
+
return fail(`Integration tool '${payload.toolName}' is not authorized for this turn`);
|
|
154
|
+
}
|
|
155
|
+
const projects = input.repos.projects.listByInstance(instanceId);
|
|
156
|
+
const projectKey =
|
|
157
|
+
typeof payload.args.projectKey === "string" ? payload.args.projectKey : null;
|
|
158
|
+
const project = projectKey
|
|
159
|
+
? (projects.find((candidate) => candidate.key === projectKey) ?? null)
|
|
160
|
+
: null;
|
|
161
|
+
if (projectKey && !project) return fail(`Unknown process project '${projectKey}'`);
|
|
162
|
+
try {
|
|
163
|
+
const result = await input.registry.execute(payload.toolName, payload.args, {
|
|
164
|
+
process,
|
|
165
|
+
projects,
|
|
166
|
+
turn,
|
|
167
|
+
project,
|
|
168
|
+
idempotencyKey: integrationToolIdempotencyKey({
|
|
169
|
+
instanceId,
|
|
170
|
+
turnRecordId: payload.turnRecordId,
|
|
171
|
+
toolCallId: payload.toolCallId,
|
|
172
|
+
toolName: payload.toolName,
|
|
173
|
+
}),
|
|
174
|
+
});
|
|
175
|
+
return {
|
|
176
|
+
turnRecordId: payload.turnRecordId,
|
|
177
|
+
toolCallId: payload.toolCallId,
|
|
178
|
+
ok: true,
|
|
179
|
+
result,
|
|
180
|
+
};
|
|
181
|
+
} catch (error) {
|
|
182
|
+
return fail(error instanceof Error ? error.message : "Integration tool execution failed");
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
@@ -22,6 +22,12 @@ function requireApiKey(secrets: Readonly<Record<string, string>>): string {
|
|
|
22
22
|
return value;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
function configuredBaseUrl(config: unknown): string | undefined {
|
|
26
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) return undefined;
|
|
27
|
+
const value = (config as { baseUrl?: unknown }).baseUrl;
|
|
28
|
+
return typeof value === "string" && value.trim() !== "" ? value.trim() : undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
25
31
|
/**
|
|
26
32
|
* Direct, server-only Pi AI adapter. It never reads PI_CODING_AGENT_DIR or an
|
|
27
33
|
* ambient auth file; the current credential revision is supplied per call.
|
|
@@ -34,10 +40,12 @@ export function createBuiltinPiServerAdapter(builtinProviderId: string): PiServe
|
|
|
34
40
|
`Built-in adapter '${builtinProviderId}' cannot serve provider '${input.providerId}'`,
|
|
35
41
|
);
|
|
36
42
|
}
|
|
37
|
-
const
|
|
38
|
-
if (!
|
|
43
|
+
const canonicalModel = getModel(builtinProviderId as never, input.modelId as never);
|
|
44
|
+
if (!canonicalModel) {
|
|
39
45
|
throw new Error(`Built-in Pi model '${builtinProviderId}/${input.modelId}' is unavailable`);
|
|
40
46
|
}
|
|
47
|
+
const baseUrl = configuredBaseUrl(input.config);
|
|
48
|
+
const model = baseUrl ? { ...canonicalModel, baseUrl } : canonicalModel;
|
|
41
49
|
const reasoning = resolveThinkingLevel(input.thinkingLevel);
|
|
42
50
|
const message = await completeSimple(
|
|
43
51
|
model,
|