@leitwerk-dev/example-processes 0.0.0-stage → 0.4.1
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 +33 -2
- package/dist/LICENSE +13 -0
- package/dist/file-external.d.ts +9 -0
- package/dist/file-external.d.ts.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +337 -0
- package/dist/index.js.map +1 -0
- package/dist/process-definition.d.ts +20 -0
- package/dist/process-definition.d.ts.map +1 -0
- package/dist/testing/harness.d.ts +3 -0
- package/dist/testing/harness.d.ts.map +1 -0
- package/dist/ui/assets/leaf-outcome-element.js +245 -0
- package/dist/ui/assets/leaf-outcome-element.js.map +1 -0
- package/dist/ui/leaf-outcome-element.d.ts +2 -0
- package/dist/ui/leaf-outcome-element.d.ts.map +1 -0
- package/dist/ui/manifest.json +18 -0
- package/package.json +53 -5
- package/src/file-external.ts +18 -0
- package/src/index.ts +61 -0
- package/src/process-definition.ts +417 -0
- package/src/testing/harness.ts +45 -0
- package/src/ui/leaf-outcome-element.ts +95 -0
- package/src/ui/manifest.json +18 -0
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
3
|
+
import {
|
|
4
|
+
type AutomaticOutcomeBuilder,
|
|
5
|
+
type Codec,
|
|
6
|
+
createEmptyStructuralProcessState,
|
|
7
|
+
type ExtensionProcessDefinition,
|
|
8
|
+
flow,
|
|
9
|
+
type HumanFlowBuilder,
|
|
10
|
+
type ProcessLauncherDefinition,
|
|
11
|
+
type ProcessLeafOutcomeDefinition,
|
|
12
|
+
type StructuralProcessState,
|
|
13
|
+
structuralStateCodec,
|
|
14
|
+
} from "@leitwerk-dev/process-sdk";
|
|
15
|
+
import { fileExternal } from "./file-external.js";
|
|
16
|
+
|
|
17
|
+
/** @internal */
|
|
18
|
+
interface PromptProcessParams {
|
|
19
|
+
/** @internal */
|
|
20
|
+
prompt: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const promptProcessParamsCodec: Codec<PromptProcessParams> = {
|
|
24
|
+
parse(value) {
|
|
25
|
+
const record =
|
|
26
|
+
typeof value === "object" && value !== null ? (value as Record<string, unknown>) : {};
|
|
27
|
+
return { prompt: typeof record.prompt === "string" ? record.prompt : "" };
|
|
28
|
+
},
|
|
29
|
+
serialize(value) {
|
|
30
|
+
return value;
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function promptLaunchResolution(options: {
|
|
35
|
+
processId: string;
|
|
36
|
+
startTurnId: string;
|
|
37
|
+
defaultPrompt?: () => string;
|
|
38
|
+
titleLabel?: string;
|
|
39
|
+
}) {
|
|
40
|
+
return {
|
|
41
|
+
resolveDefaults: () => ({ prompt: options.defaultPrompt?.() ?? "" }),
|
|
42
|
+
resolveLaunchConfig(input: Record<string, unknown>) {
|
|
43
|
+
const inputPrompt = typeof input.prompt === "string" ? input.prompt.trim() : "";
|
|
44
|
+
const prompt = inputPrompt || options.defaultPrompt?.().trim() || "";
|
|
45
|
+
if (!prompt) {
|
|
46
|
+
return {
|
|
47
|
+
ok: false as const,
|
|
48
|
+
errors: [{ code: "required", fieldId: "prompt", message: "prompt is required" }],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
ok: true as const,
|
|
53
|
+
launchConfig: {
|
|
54
|
+
processId: options.processId,
|
|
55
|
+
params: { prompt },
|
|
56
|
+
titleSourceFields: [{ label: options.titleLabel ?? "Prompt", value: prompt }],
|
|
57
|
+
startTurnId: options.startTurnId,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function createMarkdownLeafOutcome(rendererId: string) {
|
|
65
|
+
return {
|
|
66
|
+
rendererId,
|
|
67
|
+
capture(ctx) {
|
|
68
|
+
const markdown = ctx.turnRecord?.turnResultMarkdown?.trim() ?? "";
|
|
69
|
+
return {
|
|
70
|
+
rendererId,
|
|
71
|
+
schemaVersion: 1,
|
|
72
|
+
props: {
|
|
73
|
+
prompt: ctx.params.prompt,
|
|
74
|
+
markdown: markdown.length > 0 ? markdown : null,
|
|
75
|
+
leafEntryId: ctx.leaf.entryId,
|
|
76
|
+
turnRecordId: ctx.leaf.turnRecordId,
|
|
77
|
+
},
|
|
78
|
+
fallbackMarkdown: markdown.length > 0 ? markdown : null,
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
} satisfies ProcessLeafOutcomeDefinition<PromptProcessParams, StructuralProcessState>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function promptProcess(processId: string, displayName: string, entry: string) {
|
|
85
|
+
return flow
|
|
86
|
+
.process<PromptProcessParams, StructuralProcessState>(processId)
|
|
87
|
+
.displayName(displayName)
|
|
88
|
+
.entry(entry)
|
|
89
|
+
.codecs({ params: promptProcessParamsCodec, state: structuralStateCodec })
|
|
90
|
+
.initialState(createEmptyStructuralProcessState)
|
|
91
|
+
.ui((api) =>
|
|
92
|
+
api.leafOutcome(
|
|
93
|
+
createMarkdownLeafOutcome(`@leitwerk-dev/showcase-processes:${processId}.leaf_outcome`),
|
|
94
|
+
),
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function buildSinglePromptInstruction(promptText: string): string {
|
|
99
|
+
return `Run the following one-shot operator prompt exactly once.
|
|
100
|
+
|
|
101
|
+
${promptText}`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function buildSinglePromptWithToolInstruction(promptText: string): string {
|
|
105
|
+
return `${buildSinglePromptInstruction(promptText)}
|
|
106
|
+
|
|
107
|
+
When you are done, call the done tool with a short summary of the result.`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function promptTurn(turnId: string, instruction = buildSinglePromptInstruction) {
|
|
111
|
+
return flow
|
|
112
|
+
.llm<PromptProcessParams, StructuralProcessState>(turnId)
|
|
113
|
+
.description("Run Prompt")
|
|
114
|
+
.tools("read", "bash", "edit", "write")
|
|
115
|
+
.prompt((ctx) => instruction(ctx.params.prompt));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function promptLauncher(options: {
|
|
119
|
+
processId: string;
|
|
120
|
+
startTurnId: string;
|
|
121
|
+
displayName: string;
|
|
122
|
+
launcherId: string;
|
|
123
|
+
formId: string;
|
|
124
|
+
description: string;
|
|
125
|
+
cardDescription: string;
|
|
126
|
+
placeholder: string;
|
|
127
|
+
promptDescription: string;
|
|
128
|
+
submitLabel?: string;
|
|
129
|
+
}): ProcessLauncherDefinition<PromptProcessParams> {
|
|
130
|
+
return {
|
|
131
|
+
id: options.launcherId,
|
|
132
|
+
label: options.displayName,
|
|
133
|
+
description: options.description,
|
|
134
|
+
visibility: "ui",
|
|
135
|
+
ui: {
|
|
136
|
+
card: { title: options.displayName, description: options.cardDescription },
|
|
137
|
+
launchConfigSchema: {
|
|
138
|
+
id: options.formId,
|
|
139
|
+
title: options.displayName,
|
|
140
|
+
fields: [
|
|
141
|
+
{
|
|
142
|
+
id: "prompt",
|
|
143
|
+
label: "Prompt",
|
|
144
|
+
kind: "textarea",
|
|
145
|
+
required: true,
|
|
146
|
+
placeholder: options.placeholder,
|
|
147
|
+
description: options.promptDescription,
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
submitLabel: options.submitLabel ?? "Run Prompt",
|
|
151
|
+
},
|
|
152
|
+
...promptLaunchResolution(options),
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** @internal */
|
|
158
|
+
export const singlePromptProcess = promptProcess(
|
|
159
|
+
"single_prompt_process",
|
|
160
|
+
"Single Prompt",
|
|
161
|
+
"run_single_prompt",
|
|
162
|
+
)
|
|
163
|
+
.turn(promptTurn("run_single_prompt").end("completed").complete())
|
|
164
|
+
.launcher(
|
|
165
|
+
promptLauncher({
|
|
166
|
+
processId: "single_prompt_process",
|
|
167
|
+
startTurnId: "run_single_prompt",
|
|
168
|
+
displayName: "Single Prompt",
|
|
169
|
+
launcherId: "single_prompt_process.single_prompt_ui",
|
|
170
|
+
formId: "single_prompt_form",
|
|
171
|
+
description: "Run one prompt and finish on turn end",
|
|
172
|
+
cardDescription:
|
|
173
|
+
"Run a one-shot prompt. The shared launcher shell chooses the model configuration.",
|
|
174
|
+
placeholder: "Say hello.",
|
|
175
|
+
promptDescription:
|
|
176
|
+
"The exact prompt sent to Pi for this one-shot run. This version finishes when the assistant turn ends normally.",
|
|
177
|
+
}),
|
|
178
|
+
)
|
|
179
|
+
.define();
|
|
180
|
+
|
|
181
|
+
/** @internal */
|
|
182
|
+
export const singlePromptWithToolProcess = promptProcess(
|
|
183
|
+
"single_prompt_with_tool_process",
|
|
184
|
+
"Single Prompt + Done Tool",
|
|
185
|
+
"run_single_prompt_with_tool",
|
|
186
|
+
)
|
|
187
|
+
.turn(
|
|
188
|
+
promptTurn("run_single_prompt_with_tool", buildSinglePromptWithToolInstruction).outcomeTool(
|
|
189
|
+
"done",
|
|
190
|
+
(tool) =>
|
|
191
|
+
tool
|
|
192
|
+
.description("Mark the prompt run as complete")
|
|
193
|
+
.requiredString("summary", "Short summary of the result")
|
|
194
|
+
.complete(),
|
|
195
|
+
),
|
|
196
|
+
)
|
|
197
|
+
.launcher(
|
|
198
|
+
promptLauncher({
|
|
199
|
+
processId: "single_prompt_with_tool_process",
|
|
200
|
+
startTurnId: "run_single_prompt_with_tool",
|
|
201
|
+
displayName: "Single Prompt + Done Tool",
|
|
202
|
+
launcherId: "single_prompt_with_tool_process.single_prompt_with_tool_ui",
|
|
203
|
+
formId: "single_prompt_with_tool_form",
|
|
204
|
+
description: "Run one prompt and require an explicit done tool",
|
|
205
|
+
cardDescription:
|
|
206
|
+
"Run a one-shot prompt and force an explicit done tool call. The shared launcher shell chooses the model configuration.",
|
|
207
|
+
placeholder: "Say hello, then call the done tool with a short summary.",
|
|
208
|
+
promptDescription:
|
|
209
|
+
"The exact prompt sent to Pi for this one-shot run. This version requires the explicit done outcome tool.",
|
|
210
|
+
submitLabel: "Run Prompt + Tool",
|
|
211
|
+
}),
|
|
212
|
+
)
|
|
213
|
+
.define();
|
|
214
|
+
|
|
215
|
+
type SmokeOutcomeBuilder = AutomaticOutcomeBuilder<PromptProcessParams, StructuralProcessState>;
|
|
216
|
+
type SmokeRunFn = (ctx: {
|
|
217
|
+
params: PromptProcessParams;
|
|
218
|
+
}) =>
|
|
219
|
+
| { params: Record<string, unknown>; markdown: string }
|
|
220
|
+
| Promise<{ params: Record<string, unknown>; markdown: string }>;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Builds one of the Kubernetes smoke fixtures: an automatic worker run turn that
|
|
224
|
+
* hands off to a wait turn with a `complete` action (and an optional `run_again`
|
|
225
|
+
* action), plus a UI launcher. The three fixtures share this skeleton and differ
|
|
226
|
+
* only in their ids, run body, and outcome parameter shape.
|
|
227
|
+
*/
|
|
228
|
+
function defineK8sSmokeProcess(args: {
|
|
229
|
+
baseId: string;
|
|
230
|
+
displayName: string;
|
|
231
|
+
runTurnDescription: string;
|
|
232
|
+
outcomeDescription: string;
|
|
233
|
+
describeOutcome?: (outcome: SmokeOutcomeBuilder) => void;
|
|
234
|
+
waitDescription: string;
|
|
235
|
+
waitCommentary?: string;
|
|
236
|
+
runAgain?: { label: string; description: string };
|
|
237
|
+
completeLabel: string;
|
|
238
|
+
launcherDescription: string;
|
|
239
|
+
cardDescription: string;
|
|
240
|
+
submitLabel: string;
|
|
241
|
+
promptField?: { label: string };
|
|
242
|
+
defaultPrompt: string;
|
|
243
|
+
run: SmokeRunFn;
|
|
244
|
+
}): ExtensionProcessDefinition<PromptProcessParams, StructuralProcessState> {
|
|
245
|
+
const processId = `${args.baseId}_process`;
|
|
246
|
+
const runTurnId = `${args.baseId}_run`;
|
|
247
|
+
const waitTurnId = `${args.baseId}_wait`;
|
|
248
|
+
const promptField = args.promptField;
|
|
249
|
+
const launchResolution = promptLaunchResolution({
|
|
250
|
+
processId,
|
|
251
|
+
startTurnId: runTurnId,
|
|
252
|
+
defaultPrompt: () => args.defaultPrompt,
|
|
253
|
+
titleLabel: "Smoke",
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
const runTurn = flow
|
|
257
|
+
.automatic<PromptProcessParams, StructuralProcessState>(runTurnId)
|
|
258
|
+
.description(args.runTurnDescription)
|
|
259
|
+
.run(async (ctx) => {
|
|
260
|
+
const result = await args.run(ctx);
|
|
261
|
+
return { outcome: "ready" as const, ...result };
|
|
262
|
+
})
|
|
263
|
+
.outcome("ready", (outcome) => {
|
|
264
|
+
outcome.description(args.outcomeDescription);
|
|
265
|
+
args.describeOutcome?.(outcome);
|
|
266
|
+
return outcome.to(waitTurnId);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
const waitTurn: HumanFlowBuilder<PromptProcessParams, StructuralProcessState> = flow
|
|
270
|
+
.human<PromptProcessParams, StructuralProcessState>(waitTurnId)
|
|
271
|
+
.description(args.waitDescription);
|
|
272
|
+
if (args.waitCommentary) {
|
|
273
|
+
waitTurn.commentary(args.waitCommentary);
|
|
274
|
+
}
|
|
275
|
+
if (args.runAgain) {
|
|
276
|
+
const runAgain = args.runAgain;
|
|
277
|
+
waitTurn.action("run_again", (action) =>
|
|
278
|
+
action
|
|
279
|
+
.label(runAgain.label)
|
|
280
|
+
.description(runAgain.description)
|
|
281
|
+
.acceptanceState("neutral")
|
|
282
|
+
.to(runTurnId),
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
waitTurn.action("complete", (action) =>
|
|
286
|
+
action.label(args.completeLabel).acceptanceState("accepted").complete(),
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
return flow
|
|
290
|
+
.process<PromptProcessParams, StructuralProcessState>(processId)
|
|
291
|
+
.displayName(args.displayName)
|
|
292
|
+
.entry(runTurnId)
|
|
293
|
+
.codecs({ params: promptProcessParamsCodec, state: structuralStateCodec })
|
|
294
|
+
.initialState(() => createEmptyStructuralProcessState())
|
|
295
|
+
.turn(runTurn)
|
|
296
|
+
.turn(waitTurn)
|
|
297
|
+
.launcher({
|
|
298
|
+
id: `${processId}.${args.baseId}_ui`,
|
|
299
|
+
label: args.displayName,
|
|
300
|
+
description: args.launcherDescription,
|
|
301
|
+
visibility: "ui",
|
|
302
|
+
ui: {
|
|
303
|
+
card: { title: args.displayName, description: args.cardDescription },
|
|
304
|
+
launchConfigSchema: {
|
|
305
|
+
id: `${args.baseId}_form`,
|
|
306
|
+
title: args.displayName,
|
|
307
|
+
fields: promptField
|
|
308
|
+
? [{ id: "prompt", label: promptField.label, kind: "text", required: true }]
|
|
309
|
+
: [],
|
|
310
|
+
submitLabel: args.submitLabel,
|
|
311
|
+
},
|
|
312
|
+
...(promptField ? { resolveDefaults: launchResolution.resolveDefaults } : {}),
|
|
313
|
+
resolveLaunchConfig: (input) =>
|
|
314
|
+
launchResolution.resolveLaunchConfig(promptField ? input : {}),
|
|
315
|
+
},
|
|
316
|
+
})
|
|
317
|
+
.define();
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** @internal */
|
|
321
|
+
export const k8sSmokeProcess = defineK8sSmokeProcess({
|
|
322
|
+
baseId: "k8s_smoke",
|
|
323
|
+
displayName: "Kubernetes Smoke",
|
|
324
|
+
runTurnDescription: "Run a deterministic worker-side Kubernetes smoke step",
|
|
325
|
+
outcomeDescription: "The worker-side smoke step completed",
|
|
326
|
+
describeOutcome: (outcome) => outcome.string("prompt", "The smoke prompt"),
|
|
327
|
+
waitDescription: "Wait after the Kubernetes smoke worker step",
|
|
328
|
+
waitCommentary: "The smoke worker is idle; actions can respawn it on the retained PVC.",
|
|
329
|
+
runAgain: { label: "Run smoke again", description: "Select the worker-side smoke turn again." },
|
|
330
|
+
completeLabel: "Complete smoke",
|
|
331
|
+
launcherDescription: "Run a deterministic worker-backed Kubernetes smoke process",
|
|
332
|
+
cardDescription: "Creates a worker pod/PVC and then waits for a follow-up action.",
|
|
333
|
+
submitLabel: "Run smoke",
|
|
334
|
+
promptField: { label: "Smoke prompt" },
|
|
335
|
+
defaultPrompt: "kind smoke",
|
|
336
|
+
run: (ctx) => ({
|
|
337
|
+
params: { prompt: ctx.params.prompt },
|
|
338
|
+
markdown: `Kubernetes smoke worker ran: ${ctx.params.prompt}`,
|
|
339
|
+
}),
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
/** @internal */
|
|
343
|
+
export const k8sSmokeSpecializedProcess = defineK8sSmokeProcess({
|
|
344
|
+
baseId: "k8s_smoke_specialized",
|
|
345
|
+
displayName: "Kubernetes Specialized Smoke",
|
|
346
|
+
runTurnDescription: "Verify the specialized Kubernetes worker image tool path",
|
|
347
|
+
outcomeDescription: "The specialized image tool ran",
|
|
348
|
+
describeOutcome: (outcome) => outcome.requiredString("output", "Tool output"),
|
|
349
|
+
waitDescription: "Wait after specialized image verification",
|
|
350
|
+
waitCommentary: "The specialized Kubernetes image was selected and executed its smoke tool.",
|
|
351
|
+
completeLabel: "Complete specialized smoke",
|
|
352
|
+
launcherDescription: "Run a deterministic worker-backed process on the specialized smoke image",
|
|
353
|
+
cardDescription: "Validates runtime-profile image selection with a deterministic tool.",
|
|
354
|
+
submitLabel: "Run specialized smoke",
|
|
355
|
+
defaultPrompt: "specialized",
|
|
356
|
+
run: () => {
|
|
357
|
+
const output = execFileSync("leitwerk-specialized-tool", { encoding: "utf8" }).trim();
|
|
358
|
+
return { params: { output }, markdown: output };
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
/** @internal */
|
|
363
|
+
export const k8sSmokeLongProcess = defineK8sSmokeProcess({
|
|
364
|
+
baseId: "k8s_smoke_long",
|
|
365
|
+
displayName: "Kubernetes Long Smoke",
|
|
366
|
+
runTurnDescription: "Stay busy long enough for server restart adoption tests",
|
|
367
|
+
outcomeDescription: "The long smoke step completed",
|
|
368
|
+
waitDescription: "Wait after long smoke",
|
|
369
|
+
completeLabel: "Complete long smoke",
|
|
370
|
+
launcherDescription: "Run a long worker-backed process for server restart adoption tests",
|
|
371
|
+
cardDescription: "Keeps a worker pod busy while the server restarts.",
|
|
372
|
+
submitLabel: "Run long smoke",
|
|
373
|
+
defaultPrompt: "long",
|
|
374
|
+
run: async () => {
|
|
375
|
+
await delay(90_000);
|
|
376
|
+
return { params: {}, markdown: "long smoke completed" };
|
|
377
|
+
},
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
const externalPromptCompletionTurnId = "await_external_prompt_completion";
|
|
381
|
+
|
|
382
|
+
/** @internal */
|
|
383
|
+
export const singlePromptExternalCompleteProcess = promptProcess(
|
|
384
|
+
"single_prompt_external_complete_process",
|
|
385
|
+
"Single Prompt + External Complete",
|
|
386
|
+
"run_single_prompt",
|
|
387
|
+
)
|
|
388
|
+
.turn(promptTurn("run_single_prompt").end("completed").to(externalPromptCompletionTurnId))
|
|
389
|
+
.turn(
|
|
390
|
+
flow
|
|
391
|
+
.external<PromptProcessParams, StructuralProcessState>(externalPromptCompletionTurnId)
|
|
392
|
+
.description("Wait for an external completion trigger after the single prompt finishes")
|
|
393
|
+
.from(
|
|
394
|
+
fileExternal.presence({
|
|
395
|
+
path: "/tmp/complete-prompt",
|
|
396
|
+
pollInterval: "1s",
|
|
397
|
+
consume: "delete",
|
|
398
|
+
}),
|
|
399
|
+
)
|
|
400
|
+
.complete(),
|
|
401
|
+
)
|
|
402
|
+
.launcher(
|
|
403
|
+
promptLauncher({
|
|
404
|
+
processId: "single_prompt_external_complete_process",
|
|
405
|
+
startTurnId: "run_single_prompt",
|
|
406
|
+
displayName: "Single Prompt + External Complete",
|
|
407
|
+
launcherId: "single_prompt_external_complete_process.single_prompt_external_complete_ui",
|
|
408
|
+
formId: "single_prompt_external_complete_form",
|
|
409
|
+
description: "Run one prompt, then wait for the external complete trigger file",
|
|
410
|
+
cardDescription:
|
|
411
|
+
"Run a one-shot prompt, preserve its result in the chronicle, and finish only when the external completion trigger fires.",
|
|
412
|
+
placeholder: "Say hello, then wait for the external completion file.",
|
|
413
|
+
promptDescription:
|
|
414
|
+
"The prompt runs once. After it finishes, the process waits for the configured prompt-complete trigger file (default: /tmp/complete-prompt).",
|
|
415
|
+
}),
|
|
416
|
+
)
|
|
417
|
+
.define();
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { fixtureModelProfiles, fixtureModelProviders } from "@leitwerk-dev/test-support";
|
|
2
|
+
import {
|
|
3
|
+
createExtensionIntegrationHarness,
|
|
4
|
+
type ExtensionIntegrationHarnessOptions,
|
|
5
|
+
} from "@leitwerk-dev/test-support/integration";
|
|
6
|
+
import exampleProcessesExtension from "../index.js";
|
|
7
|
+
|
|
8
|
+
export function createExampleHarness(options: Partial<ExtensionIntegrationHarnessOptions> = {}) {
|
|
9
|
+
return createExtensionIntegrationHarness({
|
|
10
|
+
extensions: [
|
|
11
|
+
exampleProcessesExtension,
|
|
12
|
+
{
|
|
13
|
+
manifest: { id: "example-fixture-providers", version: "1" },
|
|
14
|
+
modelProviders: fixtureModelProviders(
|
|
15
|
+
...fixtureModelProfiles.map((model) => ({ ...model, id: model.provider, server: true })),
|
|
16
|
+
),
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
models: fixtureModelProfiles,
|
|
20
|
+
defaultModel: fixtureModelProfiles[0].id,
|
|
21
|
+
script(_id, _prompt, observation) {
|
|
22
|
+
const names = new Set(observation.tools.map((tool) => tool.name));
|
|
23
|
+
if (names.has("done"))
|
|
24
|
+
return {
|
|
25
|
+
tools: [
|
|
26
|
+
{
|
|
27
|
+
name: "done",
|
|
28
|
+
arguments: { summary: "Completed", markdown: "# Result\n\nCompleted." },
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
tools: [
|
|
34
|
+
{
|
|
35
|
+
name: "markdown_result",
|
|
36
|
+
arguments: {
|
|
37
|
+
markdown: "# Result\n\nCompleted.",
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
...options,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {
|
|
2
|
+
escapeLeafOutcomeHtml,
|
|
3
|
+
LeafOutcomeCustomElement,
|
|
4
|
+
} from "@leitwerk-dev/process-sdk/leaf-outcome-renderer";
|
|
5
|
+
|
|
6
|
+
interface SinglePromptLeafOutcomePayload {
|
|
7
|
+
prompt?: unknown;
|
|
8
|
+
markdown?: unknown;
|
|
9
|
+
leafEntryId?: unknown;
|
|
10
|
+
turnRecordId?: unknown;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const TAG_NAME = "o2-showcase-processes-leaf-outcome";
|
|
14
|
+
|
|
15
|
+
class SinglePromptLeafOutcomeElement extends LeafOutcomeCustomElement<SinglePromptLeafOutcomePayload> {
|
|
16
|
+
protected renderContent(): void {
|
|
17
|
+
if (!this.canRender()) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const runtime = this.runtime;
|
|
21
|
+
if (!runtime) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const payload = this.payload;
|
|
25
|
+
const markdown = typeof payload?.markdown === "string" ? payload.markdown.trim() : "";
|
|
26
|
+
if (!markdown) {
|
|
27
|
+
this.emitError(
|
|
28
|
+
"missing_markdown_payload",
|
|
29
|
+
"The selected-leaf snapshot payload did not include markdown content.",
|
|
30
|
+
);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const prompt = typeof payload?.prompt === "string" ? payload.prompt.trim() : "";
|
|
34
|
+
const relativeTime =
|
|
35
|
+
this.meta && typeof this.meta.createdAt === "string"
|
|
36
|
+
? runtime.formatRelativeTime(this.meta.createdAt)
|
|
37
|
+
: null;
|
|
38
|
+
const promptMarkup = prompt ? `<p class="prompt">${escapeLeafOutcomeHtml(prompt)}</p>` : "";
|
|
39
|
+
const metaMarkup = relativeTime
|
|
40
|
+
? `<p class="meta">Captured ${escapeLeafOutcomeHtml(relativeTime)}</p>`
|
|
41
|
+
: "";
|
|
42
|
+
this.shadowRootRef.innerHTML = `
|
|
43
|
+
<style>
|
|
44
|
+
:host {
|
|
45
|
+
display: block;
|
|
46
|
+
color: var(--o2-text, #1f2933);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.wrap {
|
|
50
|
+
display: flex;
|
|
51
|
+
flex-direction: column;
|
|
52
|
+
gap: var(--o2-space-md, 12px);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.prompt,
|
|
56
|
+
.meta {
|
|
57
|
+
margin: 0;
|
|
58
|
+
font-size: 12px;
|
|
59
|
+
line-height: 1.5;
|
|
60
|
+
color: var(--o2-text-muted, #667085);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.prompt {
|
|
64
|
+
padding: var(--o2-space-sm, 8px) 0;
|
|
65
|
+
border-top: 1px solid color-mix(in srgb, var(--o2-border, #ddd4c8) 78%, white 22%);
|
|
66
|
+
border-bottom: 1px solid color-mix(in srgb, var(--o2-border, #ddd4c8) 54%, white 46%);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.markdown {
|
|
70
|
+
color: var(--o2-text, #1f2933);
|
|
71
|
+
font-size: 14px;
|
|
72
|
+
line-height: 1.65;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.markdown :where(*:first-child) {
|
|
76
|
+
margin-top: 0;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.markdown :where(*:last-child) {
|
|
80
|
+
margin-bottom: 0;
|
|
81
|
+
}
|
|
82
|
+
</style>
|
|
83
|
+
<article class="wrap" data-renderer="showcase-processes-leaf-outcome">
|
|
84
|
+
${promptMarkup}
|
|
85
|
+
<div class="markdown">${runtime.markdown.render(markdown)}</div>
|
|
86
|
+
${metaMarkup}
|
|
87
|
+
</article>
|
|
88
|
+
`;
|
|
89
|
+
this.emitReady();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!customElements.get(TAG_NAME)) {
|
|
94
|
+
customElements.define(TAG_NAME, SinglePromptLeafOutcomeElement);
|
|
95
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"apiVersion": 1,
|
|
3
|
+
"extensionManifestId": "example-processes",
|
|
4
|
+
"renderers": {
|
|
5
|
+
"@leitwerk-dev/showcase-processes:single_prompt_process.leaf_outcome": {
|
|
6
|
+
"kind": "custom_element",
|
|
7
|
+
"tagName": "o2-showcase-processes-leaf-outcome",
|
|
8
|
+
"module": "./leaf-outcome-element.ts",
|
|
9
|
+
"rendererApiVersion": 1
|
|
10
|
+
},
|
|
11
|
+
"@leitwerk-dev/showcase-processes:single_prompt_with_tool_process.leaf_outcome": {
|
|
12
|
+
"kind": "custom_element",
|
|
13
|
+
"tagName": "o2-showcase-processes-leaf-outcome",
|
|
14
|
+
"module": "./leaf-outcome-element.ts",
|
|
15
|
+
"rendererApiVersion": 1
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|