amalgm 0.1.51 → 0.1.53
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/lib/tunnel-events.js +48 -23
- package/package.json +2 -2
- package/runtime/lib/harnesses.js +12 -4
- package/runtime/scripts/amalgm-mcp/agents/store.js +5 -5
- package/runtime/scripts/amalgm-mcp/{artifacts → apps}/advertise.js +39 -24
- package/runtime/scripts/amalgm-mcp/apps/rest.js +144 -0
- package/runtime/scripts/amalgm-mcp/apps/store.js +171 -0
- package/runtime/scripts/amalgm-mcp/apps/supervisor.js +439 -0
- package/runtime/scripts/amalgm-mcp/apps/tools.js +176 -0
- package/runtime/scripts/amalgm-mcp/automations/cell-references.js +237 -0
- package/runtime/scripts/amalgm-mcp/automations/context.js +41 -0
- package/runtime/scripts/amalgm-mcp/automations/rest.js +148 -0
- package/runtime/scripts/amalgm-mcp/automations/runner.js +613 -0
- package/runtime/scripts/amalgm-mcp/automations/scheduler.js +90 -0
- package/runtime/scripts/amalgm-mcp/automations/store.js +1125 -0
- package/runtime/scripts/amalgm-mcp/automations/tool-actions.js +177 -0
- package/runtime/scripts/amalgm-mcp/automations/tools.js +418 -0
- package/runtime/scripts/amalgm-mcp/automations/validator.js +225 -0
- package/runtime/scripts/amalgm-mcp/browser/agent-browser.js +547 -0
- package/runtime/scripts/amalgm-mcp/browser/electron-bridge.js +222 -0
- package/runtime/scripts/amalgm-mcp/browser/page.js +13 -631
- package/runtime/scripts/amalgm-mcp/browser/tools.js +9 -7
- package/runtime/scripts/amalgm-mcp/config.js +33 -48
- package/runtime/scripts/amalgm-mcp/deps.js +1 -31
- package/runtime/scripts/amalgm-mcp/events/ingress.js +50 -42
- package/runtime/scripts/amalgm-mcp/events/internal-workflows.js +169 -0
- package/runtime/scripts/amalgm-mcp/events/matcher.js +45 -14
- package/runtime/scripts/amalgm-mcp/events/store.js +106 -57
- package/runtime/scripts/amalgm-mcp/index.js +12 -14
- package/runtime/scripts/amalgm-mcp/lib/prefs.js +229 -65
- package/runtime/scripts/amalgm-mcp/lib/tool-result.js +13 -27
- package/runtime/scripts/amalgm-mcp/server/core-tools.js +2 -3
- package/runtime/scripts/amalgm-mcp/server/http.js +106 -56
- package/runtime/scripts/amalgm-mcp/slack/inbound.js +1 -1
- package/runtime/scripts/amalgm-mcp/state/db.js +119 -0
- package/runtime/scripts/amalgm-mcp/state/snapshot.js +16 -3
- package/runtime/scripts/amalgm-mcp/tasks/executor.js +1 -1
- package/runtime/scripts/amalgm-mcp/tests/automations-store-runner.test.js +348 -0
- package/runtime/scripts/amalgm-mcp/tests/events-matcher.test.js +23 -0
- package/runtime/scripts/amalgm-mcp/tests/workflows-store-runner.test.js +67 -0
- package/runtime/scripts/amalgm-mcp/toolbox/tools.js +16 -3
- package/runtime/scripts/amalgm-mcp/workflows/compiler.js +222 -0
- package/runtime/scripts/amalgm-mcp/workflows/runner.js +593 -0
- package/runtime/scripts/amalgm-mcp/workflows/store.js +237 -0
- package/runtime/scripts/chat-core/adapters/claude.js +2 -1
- package/runtime/scripts/chat-core/auth.js +82 -12
- package/runtime/scripts/chat-core/contract.js +5 -1
- package/runtime/scripts/chat-core/engine.js +103 -62
- package/runtime/scripts/chat-core/event-schema.js +8 -0
- package/runtime/scripts/chat-core/events.js +5 -0
- package/runtime/scripts/chat-core/normalizers/codex.js +13 -1
- package/runtime/scripts/chat-core/parts.js +21 -6
- package/runtime/scripts/chat-core/sse.js +3 -0
- package/runtime/scripts/chat-core/tests/auth.test.js +84 -6
- package/runtime/scripts/chat-core/tests/engine.test.js +312 -0
- package/runtime/scripts/chat-core/tests/native-config.test.js +23 -0
- package/runtime/scripts/chat-core/tool-shape.js +4 -4
- package/runtime/scripts/chat-core/tooling/active-memory.js +5 -4
- package/runtime/scripts/chat-core/tooling/native-binaries.js +34 -9
- package/runtime/scripts/chat-core/tooling/native-config.js +34 -3
- package/runtime/scripts/local-gateway.js +34 -27
- package/runtime/scripts/platform-context.txt +76 -94
- package/runtime/scripts/amalgm-mcp/artifacts/rest.js +0 -103
- package/runtime/scripts/amalgm-mcp/artifacts/store.js +0 -157
- package/runtime/scripts/amalgm-mcp/artifacts/supervisor.js +0 -439
- package/runtime/scripts/amalgm-mcp/artifacts/tools.js +0 -176
- package/runtime/scripts/amalgm-mcp/events/executor.js +0 -258
- package/runtime/scripts/amalgm-mcp/events/rest.js +0 -214
- package/runtime/scripts/amalgm-mcp/events/tools.js +0 -323
- package/runtime/scripts/amalgm-mcp/tasks/rest.js +0 -110
- package/runtime/scripts/amalgm-mcp/tasks/tools.js +0 -416
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { compileWorkflowText } = require('../workflows/compiler');
|
|
4
|
+
const { buildWorkflowInput } = require('./context');
|
|
5
|
+
const { runFunctionSource } = require('./runner');
|
|
6
|
+
const { validateCellReferences } = require('./cell-references');
|
|
7
|
+
const { validateWorkflowToolActions } = require('./tool-actions');
|
|
8
|
+
|
|
9
|
+
const DEFAULT_VALIDATE_CODE_TIMEOUT_MS = 5_000;
|
|
10
|
+
|
|
11
|
+
class ValidationStop extends Error {
|
|
12
|
+
constructor() {
|
|
13
|
+
super('Workflow stopped');
|
|
14
|
+
this.name = 'ValidationStop';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function isObject(value) {
|
|
19
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function isFunctionRef(value) {
|
|
23
|
+
return isObject(value) && typeof value.$fn === 'string';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function resolveDynamic(value, input, options = {}) {
|
|
27
|
+
if (isFunctionRef(value)) return runFunctionSource(value.$fn, input, options);
|
|
28
|
+
if (Array.isArray(value)) {
|
|
29
|
+
const next = [];
|
|
30
|
+
for (const item of value) next.push(await resolveDynamic(item, input, options));
|
|
31
|
+
return next;
|
|
32
|
+
}
|
|
33
|
+
if (isObject(value)) {
|
|
34
|
+
const next = {};
|
|
35
|
+
for (const [key, child] of Object.entries(value)) {
|
|
36
|
+
next[key] = await resolveDynamic(child, input, options);
|
|
37
|
+
}
|
|
38
|
+
return next;
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function defaultEventFor(ir, input = {}) {
|
|
44
|
+
return {
|
|
45
|
+
id: input.id || 'validate:event',
|
|
46
|
+
source: input.source || ir.trigger?.source || 'amalgm.validate',
|
|
47
|
+
event: input.event || ir.trigger?.event || 'dry_run',
|
|
48
|
+
payload: isObject(input.payload) ? input.payload : {},
|
|
49
|
+
headers: isObject(input.headers) ? input.headers : {},
|
|
50
|
+
receivedAt: new Date().toISOString(),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function defaultDryOutput(cell, resolved) {
|
|
55
|
+
if (cell.kind === 'cli') {
|
|
56
|
+
return {
|
|
57
|
+
dryRun: true,
|
|
58
|
+
kind: 'cli',
|
|
59
|
+
command: resolved.command || resolved.run || '',
|
|
60
|
+
cwd: resolved.cwd || null,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
dryRun: true,
|
|
65
|
+
kind: 'tool',
|
|
66
|
+
toolId: cell.toolId,
|
|
67
|
+
actionName: cell.actionName,
|
|
68
|
+
args: resolved,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function validateDryRun(ir, options = {}) {
|
|
73
|
+
const event = defaultEventFor(ir, options.event);
|
|
74
|
+
const codeTimeoutMs = Number(options.codeTimeoutMs || options.code_timeout_ms) || DEFAULT_VALIDATE_CODE_TIMEOUT_MS;
|
|
75
|
+
const mockOutputs = isObject(options.mockOutputs || options.mock_outputs)
|
|
76
|
+
? (options.mockOutputs || options.mock_outputs)
|
|
77
|
+
: {};
|
|
78
|
+
const executeCode = options.executeCode !== false && options.execute_code !== false;
|
|
79
|
+
const ctx = {
|
|
80
|
+
automation: { id: 'validate:automation', name: options.name || 'Validation automation' },
|
|
81
|
+
event,
|
|
82
|
+
trigger: {
|
|
83
|
+
id: 'validate:trigger',
|
|
84
|
+
name: 'Validation trigger',
|
|
85
|
+
kind: 'event',
|
|
86
|
+
source: event.source,
|
|
87
|
+
event: event.event,
|
|
88
|
+
},
|
|
89
|
+
workflow: { id: 'validate:workflow', name: 'Validation workflow' },
|
|
90
|
+
previous: null,
|
|
91
|
+
outputs: {},
|
|
92
|
+
secrets: {},
|
|
93
|
+
};
|
|
94
|
+
const cells = [];
|
|
95
|
+
|
|
96
|
+
for (const cell of ir.cells) {
|
|
97
|
+
const input = buildWorkflowInput(ctx, () => {
|
|
98
|
+
throw new ValidationStop();
|
|
99
|
+
});
|
|
100
|
+
const record = {
|
|
101
|
+
name: cell.name,
|
|
102
|
+
kind: cell.kind,
|
|
103
|
+
status: 'completed',
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
if (cell.if !== undefined) {
|
|
108
|
+
const condition = await resolveDynamic(cell.if, input, { timeoutMs: codeTimeoutMs });
|
|
109
|
+
if (!condition) {
|
|
110
|
+
record.status = 'skipped';
|
|
111
|
+
record.output = null;
|
|
112
|
+
cells.push(record);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
let output;
|
|
118
|
+
if (Object.prototype.hasOwnProperty.call(mockOutputs, cell.name)) {
|
|
119
|
+
output = mockOutputs[cell.name];
|
|
120
|
+
} else if (cell.kind === 'code') {
|
|
121
|
+
output = executeCode
|
|
122
|
+
? await runFunctionSource(cell.code, input, { timeoutMs: codeTimeoutMs })
|
|
123
|
+
: { dryRun: true, kind: 'code' };
|
|
124
|
+
} else if (cell.kind === 'cli') {
|
|
125
|
+
const config = await resolveDynamic(cell.config || {}, input, { timeoutMs: codeTimeoutMs });
|
|
126
|
+
output = defaultDryOutput(cell, config);
|
|
127
|
+
} else if (cell.kind === 'tool') {
|
|
128
|
+
const args = await resolveDynamic(cell.args || {}, input, { timeoutMs: codeTimeoutMs });
|
|
129
|
+
output = defaultDryOutput(cell, args);
|
|
130
|
+
} else {
|
|
131
|
+
throw new Error(`Unsupported workflow cell kind "${cell.kind}".`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
ctx.previous = output;
|
|
135
|
+
ctx.outputs[cell.name] = output;
|
|
136
|
+
record.output = output;
|
|
137
|
+
cells.push(record);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
const stopped = error instanceof ValidationStop || error?.name === 'ValidationStop';
|
|
140
|
+
record.status = stopped ? 'stopped' : 'failed';
|
|
141
|
+
record.error = stopped ? null : (error.message || String(error));
|
|
142
|
+
cells.push(record);
|
|
143
|
+
return {
|
|
144
|
+
ok: false,
|
|
145
|
+
errors: stopped ? [] : [{
|
|
146
|
+
cell: cell.name,
|
|
147
|
+
message: record.error,
|
|
148
|
+
}],
|
|
149
|
+
dryRun: {
|
|
150
|
+
status: record.status,
|
|
151
|
+
cells,
|
|
152
|
+
output: ctx.outputs,
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
ok: true,
|
|
160
|
+
errors: [],
|
|
161
|
+
dryRun: {
|
|
162
|
+
status: 'completed',
|
|
163
|
+
cells,
|
|
164
|
+
output: ctx.outputs,
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function validateWorkflowText(workflowText, options = {}) {
|
|
170
|
+
let ir;
|
|
171
|
+
try {
|
|
172
|
+
ir = compileWorkflowText(workflowText);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
return {
|
|
175
|
+
ok: false,
|
|
176
|
+
errors: [{ phase: 'compile', message: error.message || String(error) }],
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const result = {
|
|
181
|
+
ok: true,
|
|
182
|
+
errors: [],
|
|
183
|
+
workflowIr: ir,
|
|
184
|
+
summary: {
|
|
185
|
+
trigger: ir.trigger,
|
|
186
|
+
cells: ir.cells.map((cell) => ({
|
|
187
|
+
name: cell.name,
|
|
188
|
+
kind: cell.kind,
|
|
189
|
+
...(cell.kind === 'tool' ? { toolId: cell.toolId, actionName: cell.actionName } : {}),
|
|
190
|
+
})),
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const staticErrors = validateCellReferences(ir);
|
|
195
|
+
if (staticErrors.length > 0) {
|
|
196
|
+
return {
|
|
197
|
+
...result,
|
|
198
|
+
ok: false,
|
|
199
|
+
errors: staticErrors,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const toolActionErrors = validateWorkflowToolActions(ir);
|
|
204
|
+
if (toolActionErrors.length > 0) {
|
|
205
|
+
return {
|
|
206
|
+
...result,
|
|
207
|
+
ok: false,
|
|
208
|
+
errors: toolActionErrors,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (options.dryRun === false || options.dry_run === false) return result;
|
|
213
|
+
|
|
214
|
+
const dryRun = await validateDryRun(ir, options);
|
|
215
|
+
return {
|
|
216
|
+
...result,
|
|
217
|
+
...dryRun,
|
|
218
|
+
workflowIr: ir,
|
|
219
|
+
summary: result.summary,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
module.exports = {
|
|
224
|
+
validateWorkflowText,
|
|
225
|
+
};
|