@sensigo/realm-mcp 0.1.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 +67 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/json-trace-buffer-store.d.ts +17 -0
- package/dist/json-trace-buffer-store.d.ts.map +1 -0
- package/dist/json-trace-buffer-store.js +128 -0
- package/dist/json-trace-buffer-store.js.map +1 -0
- package/dist/protocol/generator.d.ts +37 -0
- package/dist/protocol/generator.d.ts.map +1 -0
- package/dist/protocol/generator.js +99 -0
- package/dist/protocol/generator.js.map +1 -0
- package/dist/server.d.ts +39 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +72 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/append-trace.d.ts +30 -0
- package/dist/tools/append-trace.d.ts.map +1 -0
- package/dist/tools/append-trace.js +125 -0
- package/dist/tools/append-trace.js.map +1 -0
- package/dist/tools/create-workflow.d.ts +30 -0
- package/dist/tools/create-workflow.d.ts.map +1 -0
- package/dist/tools/create-workflow.js +228 -0
- package/dist/tools/create-workflow.js.map +1 -0
- package/dist/tools/execute-step.d.ts +51 -0
- package/dist/tools/execute-step.d.ts.map +1 -0
- package/dist/tools/execute-step.js +91 -0
- package/dist/tools/execute-step.js.map +1 -0
- package/dist/tools/get-run-state.d.ts +31 -0
- package/dist/tools/get-run-state.d.ts.map +1 -0
- package/dist/tools/get-run-state.js +63 -0
- package/dist/tools/get-run-state.js.map +1 -0
- package/dist/tools/get-workflow-protocol.d.ts +13 -0
- package/dist/tools/get-workflow-protocol.d.ts.map +1 -0
- package/dist/tools/get-workflow-protocol.js +30 -0
- package/dist/tools/get-workflow-protocol.js.map +1 -0
- package/dist/tools/list-workflows.d.ts +20 -0
- package/dist/tools/list-workflows.d.ts.map +1 -0
- package/dist/tools/list-workflows.js +21 -0
- package/dist/tools/list-workflows.js.map +1 -0
- package/dist/tools/start-run.d.ts +26 -0
- package/dist/tools/start-run.d.ts.map +1 -0
- package/dist/tools/start-run.js +90 -0
- package/dist/tools/start-run.js.map +1 -0
- package/dist/tools/submit-human-response.d.ts +15 -0
- package/dist/tools/submit-human-response.d.ts.map +1 -0
- package/dist/tools/submit-human-response.js +63 -0
- package/dist/tools/submit-human-response.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// append-trace.ts — append_trace MCP tool for incremental mid-step trace ingestion.
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { JsonWorkflowStore, JsonFileStore, WorkflowError, buildPreExecutionErrorEnvelope, } from '@sensigo/realm';
|
|
4
|
+
import { traceEntrySchema } from './execute-step.js';
|
|
5
|
+
/**
|
|
6
|
+
* Business logic for the append_trace tool.
|
|
7
|
+
* Buffers trace entries to the WAL for (runId, stepId). Entries are merged with
|
|
8
|
+
* any entries submitted at execute_step finalization.
|
|
9
|
+
*
|
|
10
|
+
* Throws WorkflowError for all error conditions. Callers (typically
|
|
11
|
+
* registerAppendTrace) catch and convert to ResponseEnvelope.
|
|
12
|
+
*/
|
|
13
|
+
export async function handleAppendTrace(args, stores) {
|
|
14
|
+
const workflowStore = stores?.workflowStore ?? new JsonWorkflowStore();
|
|
15
|
+
const runStore = stores?.runStore ?? new JsonFileStore();
|
|
16
|
+
const traceBufferStore = stores?.traceBufferStore;
|
|
17
|
+
// 1. Load the run. Throws STATE_RUN_NOT_FOUND if missing.
|
|
18
|
+
const run = await runStore.get(args.run_id);
|
|
19
|
+
// 2. Load the workflow definition.
|
|
20
|
+
const definition = await workflowStore.get(run.workflow_id);
|
|
21
|
+
// 3. Find the step in the definition.
|
|
22
|
+
const stepDef = definition.steps[args.step_id];
|
|
23
|
+
if (stepDef === undefined) {
|
|
24
|
+
throw new WorkflowError(`Step '${args.step_id}' not found in workflow '${run.workflow_id}'.`, {
|
|
25
|
+
code: 'STEP_NOT_FOUND',
|
|
26
|
+
category: 'STATE',
|
|
27
|
+
agentAction: 'report_to_user',
|
|
28
|
+
retryable: false,
|
|
29
|
+
details: { step_id: args.step_id, workflow_id: run.workflow_id, run_version: run.version },
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
// 4. Check step type — only agent steps support append_trace.
|
|
33
|
+
if (stepDef.execution !== 'agent') {
|
|
34
|
+
throw new WorkflowError(`Step '${args.step_id}' is not an agent step (execution: '${stepDef.execution}').`, {
|
|
35
|
+
code: 'STATE_STEP_NOT_ELIGIBLE',
|
|
36
|
+
category: 'STATE',
|
|
37
|
+
agentAction: 'report_to_user',
|
|
38
|
+
retryable: false,
|
|
39
|
+
details: { step_id: args.step_id, step_type: stepDef.execution, run_version: run.version },
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
// 5. Check step eligibility — must not be completed, failed, or in-progress.
|
|
43
|
+
if (run.completed_steps.includes(args.step_id) || run.failed_steps.includes(args.step_id)) {
|
|
44
|
+
throw new WorkflowError(`Step '${args.step_id}' has already been claimed (completed or failed).`, {
|
|
45
|
+
code: 'STATE_STEP_NOT_ELIGIBLE',
|
|
46
|
+
category: 'STATE',
|
|
47
|
+
agentAction: 'report_to_user',
|
|
48
|
+
retryable: false,
|
|
49
|
+
details: { step_id: args.step_id, step_state: 'already_claimed', run_version: run.version },
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (run.in_progress_steps.includes(args.step_id)) {
|
|
53
|
+
throw new WorkflowError(`Step '${args.step_id}' is currently being executed by execute_step.`, {
|
|
54
|
+
code: 'STATE_STEP_NOT_ELIGIBLE',
|
|
55
|
+
category: 'STATE',
|
|
56
|
+
agentAction: 'report_to_user',
|
|
57
|
+
retryable: false,
|
|
58
|
+
details: { step_id: args.step_id, step_state: 'in_progress', run_version: run.version },
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
// Steps 6 + 7: Require buffer store for any append_trace operation.
|
|
62
|
+
if (traceBufferStore === undefined) {
|
|
63
|
+
throw new WorkflowError('No trace buffer store configured', {
|
|
64
|
+
code: 'ENGINE_INTERNAL',
|
|
65
|
+
category: 'ENGINE',
|
|
66
|
+
agentAction: 'stop',
|
|
67
|
+
retryable: false,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
// 6. Empty entries — return current buffer state without writing.
|
|
71
|
+
if (args.entries.length === 0) {
|
|
72
|
+
const result = await traceBufferStore.append(args.run_id, args.step_id, []);
|
|
73
|
+
return { status: 'ok', ...result };
|
|
74
|
+
}
|
|
75
|
+
// 7. Append entries to the buffer.
|
|
76
|
+
const result = await traceBufferStore.append(args.run_id, args.step_id, args.entries);
|
|
77
|
+
return { status: 'ok', ...result };
|
|
78
|
+
}
|
|
79
|
+
/** Registers the append_trace MCP tool on the server. */
|
|
80
|
+
export function registerAppendTrace(server, opts) {
|
|
81
|
+
server.tool('append_trace', [
|
|
82
|
+
'Submit trace entries incrementally during an agent step, before calling execute_step.',
|
|
83
|
+
'Entries are buffered and merged with any entries submitted at execute_step finalization.',
|
|
84
|
+
'Delivery is best-effort: entries are durable after this call returns but are not canonical until execute_step completes.',
|
|
85
|
+
'Only valid for agent steps that have not yet been claimed (before execute_step is called).',
|
|
86
|
+
].join(' '), {
|
|
87
|
+
run_id: z.string(),
|
|
88
|
+
step_id: z.string(),
|
|
89
|
+
entries: z.array(traceEntrySchema),
|
|
90
|
+
}, async (args) => {
|
|
91
|
+
try {
|
|
92
|
+
const result = await handleAppendTrace(args, opts);
|
|
93
|
+
return {
|
|
94
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
const workflowErr = err instanceof WorkflowError
|
|
99
|
+
? err
|
|
100
|
+
: new WorkflowError(err instanceof Error ? err.message : String(err), {
|
|
101
|
+
code: 'ENGINE_INTERNAL',
|
|
102
|
+
category: 'ENGINE',
|
|
103
|
+
agentAction: 'stop',
|
|
104
|
+
retryable: false,
|
|
105
|
+
});
|
|
106
|
+
const runVersion = typeof workflowErr.details['run_version'] === 'number'
|
|
107
|
+
? workflowErr.details['run_version']
|
|
108
|
+
: 0;
|
|
109
|
+
const contextHint = workflowErr.code === 'STATE_RUN_NOT_FOUND'
|
|
110
|
+
? `Run '${args.run_id}' not found.`
|
|
111
|
+
: workflowErr.code === 'STEP_NOT_FOUND'
|
|
112
|
+
? `Step '${args.step_id}' not found in the workflow.`
|
|
113
|
+
: workflowErr.code === 'STATE_STEP_NOT_ELIGIBLE'
|
|
114
|
+
? `Step '${args.step_id}' is not eligible for trace buffering.`
|
|
115
|
+
: workflowErr.code === 'BUFFER_FULL'
|
|
116
|
+
? `Trace buffer is full for step '${args.step_id}'.`
|
|
117
|
+
: `An error occurred during append_trace for run '${args.run_id}'.`;
|
|
118
|
+
const envelope = buildPreExecutionErrorEnvelope('append_trace', args.run_id, runVersion, workflowErr, contextHint);
|
|
119
|
+
return {
|
|
120
|
+
content: [{ type: 'text', text: JSON.stringify(envelope, null, 2) }],
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=append-trace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"append-trace.js","sourceRoot":"","sources":["../../src/tools/append-trace.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,8BAA8B,GAK/B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAUrD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,IAIC,EACD,MAAgC;IAEhC,MAAM,aAAa,GAAG,MAAM,EAAE,aAAa,IAAI,IAAI,iBAAiB,EAAE,CAAC;IACvE,MAAM,QAAQ,GAAG,MAAM,EAAE,QAA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JsonWorkflowStore, JsonFileStore, type ResponseEnvelope } from '@sensigo/realm';
|
|
3
|
+
import { type HandleRunStores } from './start-run.js';
|
|
4
|
+
export interface CreateWorkflowStep {
|
|
5
|
+
id: string;
|
|
6
|
+
description: string;
|
|
7
|
+
depends_on?: string[];
|
|
8
|
+
input_schema?: Record<string, unknown>;
|
|
9
|
+
timeout_seconds?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface CreateWorkflowArgs {
|
|
12
|
+
steps: CreateWorkflowStep[];
|
|
13
|
+
metadata?: {
|
|
14
|
+
name?: string;
|
|
15
|
+
task_description?: string;
|
|
16
|
+
model?: string;
|
|
17
|
+
agent?: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Business logic for the create_workflow tool.
|
|
22
|
+
* Validates steps, derives a workflow ID, registers the definition, and starts a run.
|
|
23
|
+
*/
|
|
24
|
+
export declare function handleCreateWorkflow(args: CreateWorkflowArgs, stores?: {
|
|
25
|
+
workflowStore?: JsonWorkflowStore;
|
|
26
|
+
runStore?: JsonFileStore;
|
|
27
|
+
}): Promise<ResponseEnvelope>;
|
|
28
|
+
/** Registers the create_workflow MCP tool on the server. */
|
|
29
|
+
export declare function registerCreateWorkflow(server: McpServer, opts?: HandleRunStores): void;
|
|
30
|
+
//# sourceMappingURL=create-workflow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-workflow.d.ts","sourceRoot":"","sources":["../../src/tools/create-workflow.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EACL,iBAAiB,EACjB,aAAa,EAIb,KAAK,gBAAgB,EAGtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAkB,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtE,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,kBAAkB,EAAE,CAAC;IAC5B,QAAQ,CAAC,EAAE;QACT,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAyKD;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,kBAAkB,EACxB,MAAM,CAAC,EAAE;IAAE,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAAC,QAAQ,CAAC,EAAE,aAAa,CAAA;CAAE,GACvE,OAAO,CAAC,gBAAgB,CAAC,CAyB3B;AAED,4DAA4D;AAC5D,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,eAAe,GAAG,IAAI,CAmEtF"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
// create-workflow.ts — Mode 2: agent creates and registers a workflow at runtime, then starts a run.
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { JsonWorkflowStore, WorkflowError, resolvePreExecutionAgentAction, CURRENT_WORKFLOW_SCHEMA_VERSION, } from '@sensigo/realm';
|
|
5
|
+
import { handleStartRun } from './start-run.js';
|
|
6
|
+
function makeErrorEnvelope(errors) {
|
|
7
|
+
return {
|
|
8
|
+
command: 'create_workflow',
|
|
9
|
+
run_id: '',
|
|
10
|
+
run_version: 0,
|
|
11
|
+
status: 'error',
|
|
12
|
+
data: {},
|
|
13
|
+
evidence: [],
|
|
14
|
+
warnings: [],
|
|
15
|
+
errors,
|
|
16
|
+
agent_action: 'provide_input',
|
|
17
|
+
context_hint: 'Invalid create_workflow input. Fix the errors and retry.',
|
|
18
|
+
next_actions: [],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** Validates all submitted steps. Returns collected error strings (empty = valid). */
|
|
22
|
+
function validateArgs(args) {
|
|
23
|
+
const errors = [];
|
|
24
|
+
if (args.steps.length === 0) {
|
|
25
|
+
errors.push('steps must contain at least one step');
|
|
26
|
+
return errors;
|
|
27
|
+
}
|
|
28
|
+
// Rule 7: agent_profile is not supported on dynamic workflows.
|
|
29
|
+
for (const step of args.steps) {
|
|
30
|
+
if ('agent_profile' in step) {
|
|
31
|
+
errors.push(`Step '${step.id}': agent_profile is not supported on dynamically-created workflows. Use realm register with a YAML workflow file for profile-based execution.`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// Rule 2: step IDs must be unique.
|
|
35
|
+
const seenIds = new Set();
|
|
36
|
+
for (const step of args.steps) {
|
|
37
|
+
if (seenIds.has(step.id)) {
|
|
38
|
+
errors.push(`Duplicate step id: '${step.id}'`);
|
|
39
|
+
}
|
|
40
|
+
seenIds.add(step.id);
|
|
41
|
+
}
|
|
42
|
+
// Rule 3: step IDs must be non-empty with no spaces.
|
|
43
|
+
for (const step of args.steps) {
|
|
44
|
+
if (step.id.trim() === '' || step.id.includes(' ')) {
|
|
45
|
+
errors.push(`Step id '${step.id}' is invalid: must be a non-empty string with no spaces`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Rule 4: descriptions must be non-empty.
|
|
49
|
+
for (const step of args.steps) {
|
|
50
|
+
if (step.description.trim() === '') {
|
|
51
|
+
errors.push(`Step '${step.id}': description must be non-empty`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Rule 5: timeout_seconds must be a positive integer if present.
|
|
55
|
+
for (const step of args.steps) {
|
|
56
|
+
if (step.timeout_seconds !== undefined) {
|
|
57
|
+
if (!Number.isInteger(step.timeout_seconds) || step.timeout_seconds <= 0) {
|
|
58
|
+
errors.push(`Step '${step.id}': timeout_seconds must be a positive integer`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Rule 6: depends_on validation.
|
|
63
|
+
const allIds = new Set(args.steps.map((s) => s.id));
|
|
64
|
+
const stepPositions = new Map();
|
|
65
|
+
args.steps.forEach((s, i) => stepPositions.set(s.id, i));
|
|
66
|
+
for (const step of args.steps) {
|
|
67
|
+
if (step.depends_on !== undefined) {
|
|
68
|
+
if (step.depends_on.length > 1) {
|
|
69
|
+
errors.push(`Step '${step.id}': depends_on supports at most one predecessor (this engine is linear)`);
|
|
70
|
+
}
|
|
71
|
+
for (const ref of step.depends_on) {
|
|
72
|
+
if (!allIds.has(ref)) {
|
|
73
|
+
errors.push(`Step '${step.id}': depends_on references unknown step '${ref}'`);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const refPos = stepPositions.get(ref);
|
|
77
|
+
const myPos = stepPositions.get(step.id);
|
|
78
|
+
if (refPos >= myPos) {
|
|
79
|
+
errors.push(`Step '${step.id}': depends_on must reference a step that appears earlier in the list`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return errors;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Derives a deterministic workflow ID from a slug of the optional name and a
|
|
89
|
+
* 16-hex-char SHA-256 prefix of the definition content (excluding the `id`
|
|
90
|
+
* field to avoid circular dependency). Identical definition content always
|
|
91
|
+
* produces the same ID, making `create_workflow` retries idempotent with the
|
|
92
|
+
* existing file-overwrite semantics of `JsonWorkflowStore.register`.
|
|
93
|
+
*/
|
|
94
|
+
function deriveWorkflowId(name, definitionWithoutId) {
|
|
95
|
+
const hash = createHash('sha256')
|
|
96
|
+
.update(JSON.stringify(definitionWithoutId))
|
|
97
|
+
.digest('hex')
|
|
98
|
+
.slice(0, 16);
|
|
99
|
+
if (name !== undefined && name.trim() !== '') {
|
|
100
|
+
const slug = name
|
|
101
|
+
.toLowerCase()
|
|
102
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
103
|
+
.replace(/^-+|-+$/g, '');
|
|
104
|
+
return `${slug}-${hash}`;
|
|
105
|
+
}
|
|
106
|
+
return `dynamic-${hash}`;
|
|
107
|
+
}
|
|
108
|
+
/** Builds a linear WorkflowDefinition from the submitted steps. */
|
|
109
|
+
function buildWorkflowDefinition(workflowId, args) {
|
|
110
|
+
const { steps, metadata } = args;
|
|
111
|
+
const stepsRecord = {};
|
|
112
|
+
for (let i = 0; i < steps.length; i++) {
|
|
113
|
+
const step = steps[i];
|
|
114
|
+
const prevStepId = i === 0 ? undefined : steps[i - 1].id;
|
|
115
|
+
const stepDef = {
|
|
116
|
+
description: step.description,
|
|
117
|
+
execution: 'agent',
|
|
118
|
+
depends_on: prevStepId !== undefined ? [prevStepId] : [],
|
|
119
|
+
};
|
|
120
|
+
if (step.input_schema !== undefined) {
|
|
121
|
+
stepDef.input_schema = step.input_schema;
|
|
122
|
+
}
|
|
123
|
+
if (step.timeout_seconds !== undefined) {
|
|
124
|
+
stepDef.timeout_seconds = step.timeout_seconds;
|
|
125
|
+
}
|
|
126
|
+
stepsRecord[step.id] = stepDef;
|
|
127
|
+
}
|
|
128
|
+
const definition = {
|
|
129
|
+
id: workflowId,
|
|
130
|
+
name: metadata?.name ?? 'Dynamic Workflow',
|
|
131
|
+
version: 1,
|
|
132
|
+
schema_version: CURRENT_WORKFLOW_SCHEMA_VERSION,
|
|
133
|
+
steps: stepsRecord,
|
|
134
|
+
};
|
|
135
|
+
if (metadata?.task_description !== undefined) {
|
|
136
|
+
definition.protocol = { quick_start: metadata.task_description };
|
|
137
|
+
}
|
|
138
|
+
definition.origin = 'agent';
|
|
139
|
+
if (metadata?.model !== undefined) {
|
|
140
|
+
definition.model = metadata.model;
|
|
141
|
+
}
|
|
142
|
+
if (metadata?.agent !== undefined) {
|
|
143
|
+
definition.agent = metadata.agent;
|
|
144
|
+
}
|
|
145
|
+
return definition;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Business logic for the create_workflow tool.
|
|
149
|
+
* Validates steps, derives a workflow ID, registers the definition, and starts a run.
|
|
150
|
+
*/
|
|
151
|
+
export async function handleCreateWorkflow(args, stores) {
|
|
152
|
+
const errors = validateArgs(args);
|
|
153
|
+
if (errors.length > 0) {
|
|
154
|
+
return makeErrorEnvelope(errors);
|
|
155
|
+
}
|
|
156
|
+
const workflowStore = stores?.workflowStore ?? new JsonWorkflowStore();
|
|
157
|
+
// Build the definition body first (with a placeholder id that is excluded from the hash).
|
|
158
|
+
const definitionBody = buildWorkflowDefinition('__placeholder__', args);
|
|
159
|
+
// Hash all content except the id to derive a stable, deterministic id.
|
|
160
|
+
const { id: _placeholderId, ...definitionWithoutId } = definitionBody;
|
|
161
|
+
const workflowId = deriveWorkflowId(args.metadata?.name, definitionWithoutId);
|
|
162
|
+
const definition = { ...definitionBody, id: workflowId };
|
|
163
|
+
await workflowStore.register(definition);
|
|
164
|
+
const result = await handleStartRun({ workflow_id: workflowId, params: {} }, {
|
|
165
|
+
workflowStore,
|
|
166
|
+
...(stores?.runStore !== undefined ? { runStore: stores.runStore } : {}),
|
|
167
|
+
});
|
|
168
|
+
return { ...result, command: 'create_workflow', data: { workflow_id: workflowId } };
|
|
169
|
+
}
|
|
170
|
+
/** Registers the create_workflow MCP tool on the server. */
|
|
171
|
+
export function registerCreateWorkflow(server, opts) {
|
|
172
|
+
const stepSchema = z
|
|
173
|
+
.object({
|
|
174
|
+
id: z.string(),
|
|
175
|
+
description: z.string(),
|
|
176
|
+
depends_on: z.array(z.string()).optional(),
|
|
177
|
+
input_schema: z.record(z.unknown()).optional(),
|
|
178
|
+
timeout_seconds: z.number().optional(),
|
|
179
|
+
})
|
|
180
|
+
.passthrough();
|
|
181
|
+
server.tool('create_workflow', 'Create a dynamic Realm workflow at runtime and immediately start a run. Use this when you have a multi-step task and want to track your own execution plan. Returns next_action pointing at your first step — proceed with execute_step as normal.', {
|
|
182
|
+
steps: z.array(stepSchema).min(1),
|
|
183
|
+
metadata: z
|
|
184
|
+
.object({
|
|
185
|
+
name: z.string().optional(),
|
|
186
|
+
task_description: z.string().optional(),
|
|
187
|
+
model: z.string().optional(),
|
|
188
|
+
agent: z.string().optional(),
|
|
189
|
+
})
|
|
190
|
+
.optional(),
|
|
191
|
+
}, async (args) => {
|
|
192
|
+
try {
|
|
193
|
+
const result = await handleCreateWorkflow(args, opts);
|
|
194
|
+
return {
|
|
195
|
+
content: [
|
|
196
|
+
{
|
|
197
|
+
type: 'text',
|
|
198
|
+
text: JSON.stringify({ ...result, command: 'create_workflow' }, null, 2),
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
catch (err) {
|
|
204
|
+
const agentAction = err instanceof WorkflowError ? resolvePreExecutionAgentAction(err) : 'report_to_user';
|
|
205
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
206
|
+
return {
|
|
207
|
+
content: [
|
|
208
|
+
{
|
|
209
|
+
type: 'text',
|
|
210
|
+
text: JSON.stringify({
|
|
211
|
+
command: 'create_workflow',
|
|
212
|
+
run_id: '',
|
|
213
|
+
status: 'error',
|
|
214
|
+
data: {},
|
|
215
|
+
evidence: [],
|
|
216
|
+
warnings: [],
|
|
217
|
+
errors: [message],
|
|
218
|
+
agent_action: agentAction,
|
|
219
|
+
context_hint: 'An error occurred before the workflow could be registered or the run could be started.',
|
|
220
|
+
next_actions: [],
|
|
221
|
+
}, null, 2),
|
|
222
|
+
},
|
|
223
|
+
],
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=create-workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-workflow.js","sourceRoot":"","sources":["../../src/tools/create-workflow.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,OAAO,E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Q,EAAE,EAAE;4BACZ,QAAQ,EAAE,EAAE;4BACZ,MAAM,EAAE,CAAC,OAAO,CAAC;4BACjB,YAAY,EAAE,WAAW;4BACzB,YAAY,EACV,wFAAwF;4BAC1F,YAAY,EAAE,EAAE;yBACjB,EACD,IAAI,EACJ,CAAC,CACF;qBACF;iBACF;aACF,CAAC;QACJ,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
+
import { type ResponseEnvelope, type AgentTraceEntry } from '@sensigo/realm';
|
|
4
|
+
import type { HandleRunStores } from './start-run.js';
|
|
5
|
+
/** Zod schema for a single agent trace entry submitted to execute_step or append_trace. */
|
|
6
|
+
export declare const traceEntrySchema: z.ZodObject<{
|
|
7
|
+
event: z.ZodString;
|
|
8
|
+
timestamp: z.ZodOptional<z.ZodString>;
|
|
9
|
+
data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
event: string;
|
|
12
|
+
timestamp?: string | undefined;
|
|
13
|
+
data?: Record<string, string | number | boolean | null> | undefined;
|
|
14
|
+
}, {
|
|
15
|
+
event: string;
|
|
16
|
+
timestamp?: string | undefined;
|
|
17
|
+
data?: Record<string, string | number | boolean | null> | undefined;
|
|
18
|
+
}>;
|
|
19
|
+
/**
|
|
20
|
+
* Business logic for the execute_step tool.
|
|
21
|
+
* Validates eligibility, claims the step, and records the agent's params as step output.
|
|
22
|
+
*/
|
|
23
|
+
export declare function handleExecuteStep(args: {
|
|
24
|
+
run_id: string;
|
|
25
|
+
command: string;
|
|
26
|
+
params?: Record<string, unknown>;
|
|
27
|
+
trace?: AgentTraceEntry[] | undefined;
|
|
28
|
+
}, stores?: HandleRunStores): Promise<ResponseEnvelope>;
|
|
29
|
+
/**
|
|
30
|
+
* MCP-layer wrapper around handleExecuteStep.
|
|
31
|
+
* Returns the tool content format used by the MCP server (content array with text JSON).
|
|
32
|
+
* Exported for direct testing of the MCP response shape.
|
|
33
|
+
*/
|
|
34
|
+
export declare function handleExecuteStepTool(args: {
|
|
35
|
+
run_id: string;
|
|
36
|
+
command: string;
|
|
37
|
+
params?: Record<string, unknown>;
|
|
38
|
+
trace?: AgentTraceEntry[] | undefined;
|
|
39
|
+
}, stores?: HandleRunStores): Promise<{
|
|
40
|
+
content: Array<{
|
|
41
|
+
type: 'text';
|
|
42
|
+
text: string;
|
|
43
|
+
}>;
|
|
44
|
+
}>;
|
|
45
|
+
/** Registers the execute_step MCP tool on the server. */
|
|
46
|
+
export declare function registerExecuteStep(server: McpServer, opts?: {
|
|
47
|
+
registry?: import('@sensigo/realm').ExtensionRegistry;
|
|
48
|
+
secrets?: Record<string, string>;
|
|
49
|
+
traceBufferStore?: import('@sensigo/realm').TraceBufferStore;
|
|
50
|
+
}): void;
|
|
51
|
+
//# sourceMappingURL=execute-step.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute-step.d.ts","sourceRoot":"","sources":["../../src/tools/execute-step.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAOL,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,2FAA2F;AAC3F,eAAO,MAAM,gBAAgB;;;;;;;;;;;;EAI3B,CAAC;AASH;;;GAGG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE;IACJ,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,eAAe,EAAE,GAAG,SAAS,CAAC;CACvC,EACD,MAAM,CAAC,EAAE,eAAe,GACvB,OAAO,CAAC,gBAAgB,CAAC,CAqB3B;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE;IACJ,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,eAAe,EAAE,GAAG,SAAS,CAAC;CACvC,EACD,MAAM,CAAC,EAAE,eAAe,GACvB,OAAO,CAAC;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC,CA2C7D;AAED,yDAAyD;AACzD,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,SAAS,EACjB,IAAI,CAAC,EAAE;IACL,QAAQ,CAAC,EAAE,OAAO,gBAAgB,EAAE,iBAAiB,CAAC;IACtD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,gBAAgB,CAAC,EAAE,OAAO,gBAAgB,EAAE,gBAAgB,CAAC;CAC9D,GACA,IAAI,CAcN"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// execute-step tool — executes a named step in a workflow run.
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { JsonWorkflowStore, JsonFileStore, executeChain, WorkflowError, buildPreExecutionErrorEnvelope, } from '@sensigo/realm';
|
|
4
|
+
/** Zod schema for a single agent trace entry submitted to execute_step or append_trace. */
|
|
5
|
+
export const traceEntrySchema = z.object({
|
|
6
|
+
event: z.string(),
|
|
7
|
+
timestamp: z.string().optional(),
|
|
8
|
+
data: z.record(z.union([z.string(), z.number(), z.boolean(), z.null()])).optional(),
|
|
9
|
+
});
|
|
10
|
+
// For agent steps, the agent's params represent their work output. The dispatcher
|
|
11
|
+
// passes them through as the step output recorded in evidence.
|
|
12
|
+
const makeParamsDispatcher = (params) => async () => params;
|
|
13
|
+
/**
|
|
14
|
+
* Business logic for the execute_step tool.
|
|
15
|
+
* Validates eligibility, claims the step, and records the agent's params as step output.
|
|
16
|
+
*/
|
|
17
|
+
export async function handleExecuteStep(args, stores) {
|
|
18
|
+
const workflowStore = stores?.workflowStore ?? new JsonWorkflowStore();
|
|
19
|
+
const runStore = stores?.runStore ?? new JsonFileStore();
|
|
20
|
+
const run = await runStore.get(args.run_id);
|
|
21
|
+
const definition = await workflowStore.get(run.workflow_id);
|
|
22
|
+
const params = args.params ?? {};
|
|
23
|
+
return executeChain(runStore, definition, {
|
|
24
|
+
runId: args.run_id,
|
|
25
|
+
command: args.command,
|
|
26
|
+
input: params,
|
|
27
|
+
dispatcher: makeParamsDispatcher(params),
|
|
28
|
+
...(stores?.registry !== undefined ? { registry: stores.registry } : {}),
|
|
29
|
+
...(stores?.secrets !== undefined ? { secrets: stores.secrets } : {}),
|
|
30
|
+
// trace is a top-level execute_step field — never embedded in params.
|
|
31
|
+
...(args.trace !== undefined ? { trace: args.trace } : {}),
|
|
32
|
+
// Pass WAL buffer store so execution loop can merge and clean up the WAL.
|
|
33
|
+
...(stores?.traceBufferStore !== undefined
|
|
34
|
+
? { traceBufferStore: stores.traceBufferStore }
|
|
35
|
+
: {}),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* MCP-layer wrapper around handleExecuteStep.
|
|
40
|
+
* Returns the tool content format used by the MCP server (content array with text JSON).
|
|
41
|
+
* Exported for direct testing of the MCP response shape.
|
|
42
|
+
*/
|
|
43
|
+
export async function handleExecuteStepTool(args, stores) {
|
|
44
|
+
try {
|
|
45
|
+
const result = await handleExecuteStep(args, stores);
|
|
46
|
+
return {
|
|
47
|
+
content: [
|
|
48
|
+
{
|
|
49
|
+
type: 'text',
|
|
50
|
+
text: JSON.stringify({ ...result, data: {}, evidence: [] }, null, 2),
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
const workflowErr = err instanceof WorkflowError
|
|
57
|
+
? err
|
|
58
|
+
: new WorkflowError(err instanceof Error ? err.message : String(err), {
|
|
59
|
+
code: 'ENGINE_INTERNAL',
|
|
60
|
+
category: 'ENGINE',
|
|
61
|
+
agentAction: 'stop',
|
|
62
|
+
retryable: false,
|
|
63
|
+
});
|
|
64
|
+
const contextHint = workflowErr.code === 'STATE_WORKFLOW_NOT_FOUND'
|
|
65
|
+
? `Workflow definition for run '${args.run_id}' not found.`
|
|
66
|
+
: workflowErr.code === 'STATE_RUN_NOT_FOUND'
|
|
67
|
+
? `Run '${args.run_id}' not found.`
|
|
68
|
+
: `An error occurred before step '${args.command}' could begin.`;
|
|
69
|
+
const envelope = buildPreExecutionErrorEnvelope(args.command, args.run_id, 0, workflowErr, contextHint);
|
|
70
|
+
return {
|
|
71
|
+
content: [
|
|
72
|
+
{
|
|
73
|
+
type: 'text',
|
|
74
|
+
text: JSON.stringify(envelope, null, 2),
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** Registers the execute_step MCP tool on the server. */
|
|
81
|
+
export function registerExecuteStep(server, opts) {
|
|
82
|
+
server.tool('execute_step', 'Execute a workflow step. For agent steps, pass your output in params.', {
|
|
83
|
+
run_id: z.string(),
|
|
84
|
+
command: z.string(),
|
|
85
|
+
params: z.record(z.unknown()).optional().default({}),
|
|
86
|
+
trace: z.array(traceEntrySchema).optional(),
|
|
87
|
+
}, async (args) => {
|
|
88
|
+
return handleExecuteStepTool(args, opts);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=execute-step.js.map
|
|
@@ -0,0 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AAC,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;QACpD,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,QAAQ,EAAE;KAC5C,EACD,KAAK,EAAE,IAAI,EAAE,EAAE;QACb,OAAO,qBAAqB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { JsonFileStore, type RunPhase } from '@sensigo/realm';
|
|
3
|
+
export interface HandleRunStateStores {
|
|
4
|
+
runStore?: JsonFileStore;
|
|
5
|
+
}
|
|
6
|
+
export interface RunStateSummary {
|
|
7
|
+
run_id: string;
|
|
8
|
+
workflow_id: string;
|
|
9
|
+
run_phase: RunPhase;
|
|
10
|
+
terminal_state: boolean;
|
|
11
|
+
completed_steps: string[];
|
|
12
|
+
in_progress_steps: string[];
|
|
13
|
+
failed_steps: string[];
|
|
14
|
+
skipped_steps: string[];
|
|
15
|
+
pending_gate: import('@sensigo/realm').PendingGate | undefined;
|
|
16
|
+
evidence_count: number;
|
|
17
|
+
last_step: string | null;
|
|
18
|
+
created_at: string;
|
|
19
|
+
updated_at: string;
|
|
20
|
+
params: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Business logic for the get_run_state tool.
|
|
24
|
+
* Returns a structured summary of the run without the full evidence array.
|
|
25
|
+
*/
|
|
26
|
+
export declare function handleGetRunState(args: {
|
|
27
|
+
run_id: string;
|
|
28
|
+
}, stores?: HandleRunStateStores): Promise<RunStateSummary>;
|
|
29
|
+
/** Registers the get_run_state MCP tool on the server. */
|
|
30
|
+
export declare function registerGetRunState(server: McpServer, opts?: HandleRunStateStores): void;
|
|
31
|
+
//# sourceMappingURL=get-run-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-run-state.d.ts","sourceRoot":"","sources":["../../src/tools/get-run-state.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EACL,aAAa,EAGb,KAAK,QAAQ,EACd,MAAM,gBAAgB,CAAC;AAExB,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,QAAQ,CAAC;IACpB,cAAc,EAAE,OAAO,CAAC;IACxB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,EAAE,OAAO,gBAAgB,EAAE,WAAW,GAAG,SAAS,CAAC;IAC/D,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,EACxB,MAAM,CAAC,EAAE,oBAAoB,GAC5B,OAAO,CAAC,eAAe,CAAC,CAoB1B;AAED,0DAA0D;AAC1D,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,oBAAoB,GAAG,IAAI,CA2CxF"}
|