@leitwerk-dev/showcase-processes 0.3.1 → 0.4.0
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/README.md +6 -25
- package/dist/file-external.d.ts +2 -22
- package/dist/file-external.d.ts.map +1 -1
- package/dist/filesystem-watcher.d.ts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +63 -721
- package/dist/index.js.map +1 -1
- package/dist/process-definition.d.ts +2 -14
- package/dist/process-definition.d.ts.map +1 -1
- package/dist/testing/harness.d.ts +2 -38
- package/dist/testing/harness.d.ts.map +1 -1
- package/dist/ui/manifest.json +0 -12
- package/package.json +4 -4
- package/src/file-external.ts +6 -253
- package/src/filesystem-watcher.ts +4 -3
- package/src/index.ts +15 -36
- package/src/process-definition.ts +54 -606
- package/src/testing/harness.ts +7 -68
- package/src/ui/manifest.json +0 -12
- package/dist/trigger-files.d.ts +0 -15
- package/dist/trigger-files.d.ts.map +0 -1
- package/dist/turns/external-complete.d.ts +0 -11
- package/dist/turns/external-complete.d.ts.map +0 -1
- package/dist/turns/run-single-prompt.d.ts +0 -14
- package/dist/turns/run-single-prompt.d.ts.map +0 -1
- package/dist/ui/assets/leaf-outcome-element.js +0 -245
- package/dist/ui/assets/leaf-outcome-element.js.map +0 -1
- package/dist/ui/leaf-outcome-element.d.ts +0 -2
- package/dist/ui/leaf-outcome-element.d.ts.map +0 -1
- package/src/trigger-files.ts +0 -47
- package/src/turns/external-complete.ts +0 -12
- package/src/turns/run-single-prompt.ts +0 -76
- package/src/ui/leaf-outcome-element.ts +0 -95
package/src/file-external.ts
CHANGED
|
@@ -1,264 +1,17 @@
|
|
|
1
|
-
import type
|
|
2
|
-
CoreServerSetupDeps,
|
|
3
|
-
ExternalActionSource,
|
|
4
|
-
ExternalSourceArmingLike,
|
|
5
|
-
} from "@leitwerk-dev/process-sdk";
|
|
6
|
-
import { emptyPollResult, type PollResult, parseDurationMs } from "@leitwerk-dev/watcher-utils";
|
|
7
|
-
import { consumeTriggerFile, readTriggerFile } from "./trigger-files.js";
|
|
1
|
+
import { defineFileExternalSource, type FileExternalInput } from "@leitwerk-dev/process-sdk";
|
|
8
2
|
|
|
9
|
-
/** @internal */
|
|
10
|
-
export type FileExternalConsumeMode = "delete" | "keep";
|
|
11
|
-
|
|
12
|
-
/** @internal */
|
|
13
|
-
export interface FileExternalInput {
|
|
14
|
-
/** @internal */
|
|
15
|
-
path: string;
|
|
16
|
-
/** @internal */
|
|
17
|
-
pollInterval: string;
|
|
18
|
-
/** @internal */
|
|
19
|
-
consume: FileExternalConsumeMode;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** @internal */
|
|
23
|
-
export const FILE_EXTERNAL_PRESENCE_KIND = "@leitwerk-dev/showcase-processes.file.presence";
|
|
24
3
|
/** @internal */
|
|
25
4
|
export const FILE_EXTERNAL_INSTRUCTION_KIND = "@leitwerk-dev/showcase-processes.file.instruction";
|
|
26
5
|
|
|
27
|
-
function normalizeConfig(input: FileExternalInput): FileExternalInput {
|
|
28
|
-
return {
|
|
29
|
-
path: input.path,
|
|
30
|
-
pollInterval: input.pollInterval,
|
|
31
|
-
consume: input.consume,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function interpolateTemplate(template: string, values: Record<string, string>): string {
|
|
36
|
-
return template.replace(/\{([a-zA-Z0-9_]+)\}/g, (match, key: string) => values[key] ?? match);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function resolveFileConfig(
|
|
40
|
-
input: FileExternalInput,
|
|
41
|
-
ctx: { process: { id: string } },
|
|
42
|
-
): FileExternalInput {
|
|
43
|
-
return {
|
|
44
|
-
...input,
|
|
45
|
-
path: interpolateTemplate(input.path, { instanceId: ctx.process.id }),
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function fileLabel(kind: "presence" | "instruction", path: string): string {
|
|
50
|
-
return kind === "presence" ? `File present: ${path}` : `File instruction: ${path}`;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
6
|
/** @internal */
|
|
54
7
|
export const fileExternal = {
|
|
55
8
|
/** @internal */
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
kind: FILE_EXTERNAL_PRESENCE_KIND,
|
|
60
|
-
label: fileLabel("presence", config.path),
|
|
61
|
-
description: `Fires when ${config.path} exists`,
|
|
62
|
-
config,
|
|
63
|
-
inputMode: "none",
|
|
64
|
-
resolve(ctx) {
|
|
65
|
-
return resolveFileConfig(config, ctx);
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
},
|
|
69
|
-
/** @internal */
|
|
70
|
-
instruction(input: FileExternalInput): ExternalActionSource {
|
|
71
|
-
const config = normalizeConfig(input);
|
|
72
|
-
return {
|
|
9
|
+
instruction(input: FileExternalInput) {
|
|
10
|
+
return defineFileExternalSource(input, {
|
|
73
11
|
kind: FILE_EXTERNAL_INSTRUCTION_KIND,
|
|
74
|
-
label:
|
|
75
|
-
description: `Reads ${
|
|
76
|
-
config,
|
|
12
|
+
label: `File instruction: ${input.path}`,
|
|
13
|
+
description: `Reads ${input.path} as instruction text`,
|
|
77
14
|
inputMode: "instruction",
|
|
78
|
-
|
|
79
|
-
return resolveFileConfig(config, ctx);
|
|
80
|
-
},
|
|
81
|
-
};
|
|
15
|
+
});
|
|
82
16
|
},
|
|
83
17
|
};
|
|
84
|
-
|
|
85
|
-
function parseFileConfig(value: unknown): FileExternalInput | null {
|
|
86
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
const record = value as Record<string, unknown>;
|
|
90
|
-
if (typeof record.path !== "string" || record.path.trim() === "") {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
path: record.path,
|
|
95
|
-
pollInterval: typeof record.pollInterval === "string" ? record.pollInterval : "1s",
|
|
96
|
-
consume: record.consume === "keep" ? "keep" : "delete",
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async function maybeConsume(config: FileExternalInput): Promise<void> {
|
|
101
|
-
if (config.consume === "delete") {
|
|
102
|
-
await consumeTriggerFile(config.path);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function createDueTracker() {
|
|
107
|
-
const nextDueAtByKey = new Map<string, number>();
|
|
108
|
-
return {
|
|
109
|
-
isDue(key: string, pollInterval: string, nowMs = Date.now()): boolean {
|
|
110
|
-
const nextDueAt = nextDueAtByKey.get(key) ?? 0;
|
|
111
|
-
if (nextDueAt > nowMs) {
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
const intervalMs = parseDurationMs(pollInterval, 1_000);
|
|
115
|
-
nextDueAtByKey.set(key, nowMs + intervalMs);
|
|
116
|
-
return true;
|
|
117
|
-
},
|
|
118
|
-
prune(activeKeys: ReadonlySet<string>): void {
|
|
119
|
-
for (const key of [...nextDueAtByKey.keys()]) {
|
|
120
|
-
if (!activeKeys.has(key)) {
|
|
121
|
-
nextDueAtByKey.delete(key);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function resolveArmedFileConfig(
|
|
129
|
-
armed: ReturnType<CoreServerSetupDeps["externalSources"]["listArmed"]>[number],
|
|
130
|
-
resolveAlias: (config: FileExternalInput) => FileExternalInput,
|
|
131
|
-
): FileExternalInput | null {
|
|
132
|
-
const parsed = parseFileConfig(armed.resolved) ?? parseFileConfig(armed.source.config);
|
|
133
|
-
return parsed ? resolveAlias(parsed) : null;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
async function pollArmedFileSource(
|
|
137
|
-
armed: ExternalSourceArmingLike,
|
|
138
|
-
resolveConfig: (config: FileExternalInput) => FileExternalInput,
|
|
139
|
-
isDue: (key: string, pollInterval: string) => boolean,
|
|
140
|
-
activeKeys: Set<string>,
|
|
141
|
-
result: PollResult,
|
|
142
|
-
) {
|
|
143
|
-
const config = resolveArmedFileConfig(armed, resolveConfig);
|
|
144
|
-
if (!config) {
|
|
145
|
-
result.errors.push(`${armed.id}:invalid_config`);
|
|
146
|
-
return null;
|
|
147
|
-
}
|
|
148
|
-
const key = `${armed.instanceId}:${armed.id}`;
|
|
149
|
-
activeKeys.add(key);
|
|
150
|
-
if (!isDue(key, config.pollInterval)) {
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
153
|
-
const file = await readTriggerFile(config.path);
|
|
154
|
-
if (!file.exists) {
|
|
155
|
-
return null;
|
|
156
|
-
}
|
|
157
|
-
return { config, file };
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
async function firePresenceSources(
|
|
161
|
-
deps: CoreServerSetupDeps,
|
|
162
|
-
result: PollResult,
|
|
163
|
-
resolveConfig: (config: FileExternalInput) => FileExternalInput,
|
|
164
|
-
isDue: (key: string, pollInterval: string) => boolean,
|
|
165
|
-
activeKeys: Set<string>,
|
|
166
|
-
): Promise<void> {
|
|
167
|
-
for (const armed of deps.externalSources.listArmed(FILE_EXTERNAL_PRESENCE_KIND)) {
|
|
168
|
-
const target = await pollArmedFileSource(armed, resolveConfig, isDue, activeKeys, result);
|
|
169
|
-
if (!target) {
|
|
170
|
-
continue;
|
|
171
|
-
}
|
|
172
|
-
const { config } = target;
|
|
173
|
-
const fired = await deps.externalSources.fire({
|
|
174
|
-
instanceId: armed.instanceId,
|
|
175
|
-
armingId: armed.id,
|
|
176
|
-
event: { path: config.path, pollInterval: config.pollInterval },
|
|
177
|
-
mergeKey: config.path,
|
|
178
|
-
});
|
|
179
|
-
if (!fired.ok) {
|
|
180
|
-
result.errors.push(`${armed.id}:${fired.code ?? fired.error ?? "fire_failed"}`);
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
await maybeConsume(config);
|
|
184
|
-
result.created.push(armed.id);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
async function fireInstructionSources(
|
|
189
|
-
deps: CoreServerSetupDeps,
|
|
190
|
-
result: PollResult,
|
|
191
|
-
resolveConfig: (config: FileExternalInput) => FileExternalInput,
|
|
192
|
-
isDue: (key: string, pollInterval: string) => boolean,
|
|
193
|
-
activeKeys: Set<string>,
|
|
194
|
-
): Promise<void> {
|
|
195
|
-
for (const armed of deps.externalSources.listArmed(FILE_EXTERNAL_INSTRUCTION_KIND)) {
|
|
196
|
-
const target = await pollArmedFileSource(armed, resolveConfig, isDue, activeKeys, result);
|
|
197
|
-
if (!target) {
|
|
198
|
-
continue;
|
|
199
|
-
}
|
|
200
|
-
const { config, file } = target;
|
|
201
|
-
const instruction = file.content.trim();
|
|
202
|
-
if (!instruction) {
|
|
203
|
-
continue;
|
|
204
|
-
}
|
|
205
|
-
const fired = await deps.externalSources.fire({
|
|
206
|
-
instanceId: armed.instanceId,
|
|
207
|
-
armingId: armed.id,
|
|
208
|
-
input: { instruction },
|
|
209
|
-
event: { path: config.path, pollInterval: config.pollInterval },
|
|
210
|
-
mergeKey: config.path,
|
|
211
|
-
});
|
|
212
|
-
if (!fired.ok) {
|
|
213
|
-
result.errors.push(`${armed.id}:${fired.code ?? fired.error ?? "fire_failed"}`);
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
216
|
-
await maybeConsume(config);
|
|
217
|
-
result.created.push(armed.id);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/** @internal */
|
|
222
|
-
export function createFileExternalSourceProvider(
|
|
223
|
-
deps: CoreServerSetupDeps,
|
|
224
|
-
aliases: Partial<Record<string, string>> = {},
|
|
225
|
-
) {
|
|
226
|
-
function applyAlias(config: FileExternalInput): FileExternalInput {
|
|
227
|
-
const exact = aliases[config.path];
|
|
228
|
-
if (exact) {
|
|
229
|
-
return { ...config, path: exact };
|
|
230
|
-
}
|
|
231
|
-
for (const [template, replacement] of Object.entries(aliases)) {
|
|
232
|
-
if (!replacement || !template.includes("{instanceId}")) {
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
235
|
-
const [prefix, suffix = ""] = template.split("{instanceId}");
|
|
236
|
-
if (!prefix || !config.path.startsWith(prefix) || !config.path.endsWith(suffix)) {
|
|
237
|
-
continue;
|
|
238
|
-
}
|
|
239
|
-
const instanceId = config.path.slice(prefix.length, config.path.length - suffix.length);
|
|
240
|
-
return {
|
|
241
|
-
...config,
|
|
242
|
-
path: replacement.includes("{instanceId}")
|
|
243
|
-
? interpolateTemplate(replacement, { instanceId })
|
|
244
|
-
: replacement,
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
return config;
|
|
248
|
-
}
|
|
249
|
-
const due = createDueTracker();
|
|
250
|
-
return deps.polling.create({
|
|
251
|
-
id: "showcase-file-external",
|
|
252
|
-
pollInterval: () => "50ms",
|
|
253
|
-
isEnabled: () => true,
|
|
254
|
-
defaultIntervalMs: 50,
|
|
255
|
-
async pollOnce() {
|
|
256
|
-
const result = emptyPollResult();
|
|
257
|
-
const activeKeys = new Set<string>();
|
|
258
|
-
await firePresenceSources(deps, result, applyAlias, due.isDue, activeKeys);
|
|
259
|
-
await fireInstructionSources(deps, result, applyAlias, due.isDue, activeKeys);
|
|
260
|
-
due.prune(activeKeys);
|
|
261
|
-
return result;
|
|
262
|
-
},
|
|
263
|
-
});
|
|
264
|
-
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import type { CoreServerSetupDeps } from "@leitwerk-dev/process-sdk";
|
|
3
3
|
import {
|
|
4
|
+
consumeTriggerFile,
|
|
4
5
|
defineProcessWatcherSource,
|
|
5
6
|
parseProcessWatcherLaunchModelConfig,
|
|
7
|
+
readTriggerFile,
|
|
6
8
|
} from "@leitwerk-dev/process-sdk";
|
|
7
9
|
import { emptyPollResult, parseDurationMs } from "@leitwerk-dev/watcher-utils";
|
|
8
|
-
import { consumeTriggerFile, readTriggerFile } from "./trigger-files.js";
|
|
9
10
|
|
|
10
11
|
/** @internal */
|
|
11
12
|
export interface FilesystemWatcherEvent {
|
|
@@ -88,8 +89,8 @@ export function createFilesystemWatcherProvider(deps: CoreServerSetupDeps) {
|
|
|
88
89
|
async pollOnce() {
|
|
89
90
|
const result = emptyPollResult();
|
|
90
91
|
const file = await readTriggerFile(watcher.config.filePath);
|
|
91
|
-
if (
|
|
92
|
-
const content = file.
|
|
92
|
+
if (file === null || file.trim() === "") return result;
|
|
93
|
+
const content = file.trim();
|
|
93
94
|
const sourceEventKey = createHash("sha256")
|
|
94
95
|
.update(`${watcher.config.filePath}\0${content}`)
|
|
95
96
|
.digest("hex");
|
package/src/index.ts
CHANGED
|
@@ -1,28 +1,21 @@
|
|
|
1
|
-
import type { LeitwerkExtensionModule } from "@leitwerk-dev/process-sdk";
|
|
2
|
-
import { coreHostCapabilities } from "@leitwerk-dev/process-sdk";
|
|
3
|
-
import { createFileExternalSourceProvider } from "./file-external.js";
|
|
4
|
-
import { createFilesystemWatcherProvider } from "./filesystem-watcher.js";
|
|
5
1
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from "./process-definition.js";
|
|
2
|
+
coreHostCapabilities,
|
|
3
|
+
createFileExternalSourceProvider,
|
|
4
|
+
type LeitwerkExtensionModule,
|
|
5
|
+
} from "@leitwerk-dev/process-sdk";
|
|
6
|
+
import { FILE_EXTERNAL_INSTRUCTION_KIND } from "./file-external.js";
|
|
7
|
+
import { createFilesystemWatcherProvider } from "./filesystem-watcher.js";
|
|
8
|
+
import { poemCreatorProcess } from "./process-definition.js";
|
|
14
9
|
import { leaveFeedbackToolRenderer } from "./turns/poem-creator.js";
|
|
15
10
|
|
|
16
11
|
/** @internal */
|
|
17
|
-
interface
|
|
12
|
+
interface ShowcaseProcessesConfig {
|
|
18
13
|
/** @internal */
|
|
19
14
|
file_triggers?: {
|
|
20
15
|
/** @internal */
|
|
21
16
|
poll_interval?: string;
|
|
22
17
|
/** @internal */
|
|
23
18
|
poem_review_path?: string;
|
|
24
|
-
/** @internal */
|
|
25
|
-
complete_prompt_path?: string;
|
|
26
19
|
};
|
|
27
20
|
}
|
|
28
21
|
|
|
@@ -34,23 +27,11 @@ const manifest = {
|
|
|
34
27
|
version: "0.1.0",
|
|
35
28
|
} as const;
|
|
36
29
|
|
|
37
|
-
const fileTriggerDefaults = {
|
|
38
|
-
poll_interval: "1s",
|
|
39
|
-
poem_review_path: "/tmp/poem-review-{instanceId}",
|
|
40
|
-
complete_prompt_path: "/tmp/complete-prompt",
|
|
41
|
-
};
|
|
42
|
-
|
|
43
30
|
/** @public */
|
|
44
|
-
const
|
|
31
|
+
const showcaseProcessesExtension: LeitwerkExtensionModule = {
|
|
45
32
|
manifest,
|
|
46
33
|
setupCatalog(api) {
|
|
47
34
|
api.registerToolRenderer(leaveFeedbackToolRenderer);
|
|
48
|
-
api.registerProcess(singlePromptProcess);
|
|
49
|
-
api.registerProcess(singlePromptWithToolProcess);
|
|
50
|
-
api.registerProcess(singlePromptExternalCompleteProcess);
|
|
51
|
-
api.registerProcess(k8sSmokeProcess);
|
|
52
|
-
api.registerProcess(k8sSmokeSpecializedProcess);
|
|
53
|
-
api.registerProcess(k8sSmokeLongProcess);
|
|
54
35
|
api.registerProcess(poemCreatorProcess);
|
|
55
36
|
},
|
|
56
37
|
setupServer(api, rawConfig) {
|
|
@@ -58,20 +39,18 @@ const singlePromptExtension: LeitwerkExtensionModule = {
|
|
|
58
39
|
if (!deps || Array.isArray(deps)) {
|
|
59
40
|
return;
|
|
60
41
|
}
|
|
61
|
-
const config = (rawConfig ?? {}) as
|
|
62
|
-
const resolvedFileTriggerConfig = {
|
|
63
|
-
...fileTriggerDefaults,
|
|
64
|
-
...config.file_triggers,
|
|
65
|
-
};
|
|
42
|
+
const config = (rawConfig ?? {}) as ShowcaseProcessesConfig;
|
|
66
43
|
createFileExternalSourceProvider(deps, {
|
|
67
|
-
"
|
|
68
|
-
|
|
44
|
+
id: "showcase-file-external",
|
|
45
|
+
kind: FILE_EXTERNAL_INSTRUCTION_KIND,
|
|
46
|
+
inputMode: "instruction",
|
|
47
|
+
aliases: { "/tmp/poem-review-{instanceId}": config.file_triggers?.poem_review_path },
|
|
69
48
|
});
|
|
70
49
|
createFilesystemWatcherProvider(deps);
|
|
71
50
|
},
|
|
72
51
|
};
|
|
73
52
|
|
|
74
|
-
export default
|
|
53
|
+
export default showcaseProcessesExtension;
|
|
75
54
|
export {
|
|
76
55
|
buildPoemLeafOutcomeFallbackMarkdown,
|
|
77
56
|
buildPoemLeafOutcomePayload,
|