amalgm 0.1.246 → 0.1.247
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 +5 -3
- package/lib/cli.js +92 -4
- package/lib/shared-realtime-tunnel.js +82 -19
- package/package.json +1 -1
- package/runtime/scripts/amalgm-mcp/automations/deliveries.js +276 -0
- package/runtime/scripts/amalgm-mcp/automations/rest.js +51 -0
- package/runtime/scripts/amalgm-mcp/automations/scheduler.js +11 -67
- package/runtime/scripts/amalgm-mcp/automations/store.js +67 -20
- package/runtime/scripts/amalgm-mcp/events/ingress.js +69 -215
- package/runtime/scripts/amalgm-mcp/events/processor.js +189 -0
- package/runtime/scripts/amalgm-mcp/lib/email-embeds.js +41 -0
- package/runtime/scripts/amalgm-mcp/lib/email-md.js +107 -1
- package/runtime/scripts/amalgm-mcp/lib/generated/email-render.json +10 -2
- package/runtime/scripts/amalgm-mcp/observer/README.md +8 -6
- package/runtime/scripts/amalgm-mcp/registration/entity-cloud.js +262 -22
- package/runtime/scripts/amalgm-mcp/registration/entity-content.js +86 -0
- package/runtime/scripts/amalgm-mcp/registration/index.js +4 -1
- package/runtime/scripts/amalgm-mcp/registration/service.js +102 -0
- package/runtime/scripts/amalgm-mcp/registration/tree.js +19 -5
- package/runtime/scripts/amalgm-mcp/registry/index.js +16 -1
- package/runtime/scripts/amalgm-mcp/registry/store.js +58 -7
- package/runtime/scripts/amalgm-mcp/server/routes/automations.js +8 -0
- package/runtime/scripts/amalgm-mcp/server/routes/entities.js +56 -0
- package/runtime/scripts/amalgm-mcp/server/routes/workspace.js +14 -0
- package/runtime/scripts/amalgm-mcp/tests/adapters.test.js +1 -1
- package/runtime/scripts/amalgm-mcp/tests/doorbell.matrix.watch.test.js +2 -2
- package/runtime/scripts/amalgm-mcp/tests/email-render-goldens/citations.html +5 -5
- package/runtime/scripts/amalgm-mcp/tests/email-render-goldens/links.html +3 -3
- package/runtime/scripts/amalgm-mcp/tests/email-render-goldens/notification-shell.html +1 -1
- package/runtime/scripts/amalgm-mcp/tests/email-render-goldens/share-invite.html +13 -0
- package/runtime/scripts/amalgm-mcp/tests/email-render-goldens/text.html +1 -1
- package/runtime/scripts/amalgm-mcp/tests/email-render.test.js +17 -1
- package/runtime/scripts/amalgm-mcp/tests/entity-cloud.test.js +189 -0
- package/runtime/scripts/amalgm-mcp/tests/entity-content.test.js +126 -0
- package/runtime/scripts/amalgm-mcp/tests/entity-materialization.test.js +118 -0
- package/runtime/scripts/amalgm-mcp/tests/entity.registry.test.js +126 -11
- package/runtime/scripts/amalgm-mcp/tests/entity.rig.js +20 -6
- package/runtime/scripts/amalgm-mcp/tests/fake-watch.js +8 -0
- package/runtime/scripts/amalgm-mcp/tests/observer.rig.js +8 -1
- package/runtime/scripts/amalgm-mcp/tests/registration.service.test.js +630 -102
- package/runtime/scripts/amalgm-mcp/tests/registration.test.js +45 -10
- package/runtime/scripts/amalgm-mcp/tests/workspace-materialize.test.js +54 -0
- package/runtime/scripts/amalgm-mcp/workspace/materialize.js +292 -0
- package/runtime/scripts/chat-core/contract.js +21 -3
- package/runtime/scripts/chat-core/engine.js +8 -0
- package/runtime/scripts/chat-core/server.js +11 -1
- package/runtime/scripts/chat-core/tests/workspace-preflight.test.js +116 -0
- package/runtime/scripts/chat-core/workspace-preflight.js +89 -0
- package/runtime/scripts/local-gateway.js +0 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const http = require('http');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { runtimePort } = require('../../lib/runtime-manifest');
|
|
6
|
+
const { runtimeAuthHeaders } = require('../runtime-auth');
|
|
7
|
+
|
|
8
|
+
function postJson(url, body) {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
const target = new URL(url);
|
|
11
|
+
const encoded = Buffer.from(JSON.stringify(body));
|
|
12
|
+
const request = http.request({
|
|
13
|
+
protocol: target.protocol,
|
|
14
|
+
hostname: target.hostname,
|
|
15
|
+
port: target.port,
|
|
16
|
+
path: `${target.pathname}${target.search}`,
|
|
17
|
+
method: 'POST',
|
|
18
|
+
headers: runtimeAuthHeaders({
|
|
19
|
+
'content-type': 'application/json',
|
|
20
|
+
'content-length': String(encoded.length),
|
|
21
|
+
}),
|
|
22
|
+
}, (response) => {
|
|
23
|
+
const chunks = [];
|
|
24
|
+
response.on('data', (chunk) => chunks.push(Buffer.from(chunk)));
|
|
25
|
+
response.on('end', () => {
|
|
26
|
+
let payload = {};
|
|
27
|
+
try {
|
|
28
|
+
payload = JSON.parse(Buffer.concat(chunks).toString('utf8') || '{}');
|
|
29
|
+
} catch {
|
|
30
|
+
// The status and generic message below still describe the failure.
|
|
31
|
+
}
|
|
32
|
+
if ((response.statusCode || 500) >= 400) {
|
|
33
|
+
reject(Object.assign(
|
|
34
|
+
new Error(payload?.error || 'Workspace materialization failed.'),
|
|
35
|
+
{
|
|
36
|
+
status: response.statusCode || 500,
|
|
37
|
+
code: payload?.code || 'workspace_materialization_failed',
|
|
38
|
+
},
|
|
39
|
+
));
|
|
40
|
+
} else {
|
|
41
|
+
resolve(payload);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
request.setTimeout(65_000, () => {
|
|
46
|
+
request.destroy(Object.assign(
|
|
47
|
+
new Error('Workspace materialization timed out.'),
|
|
48
|
+
{ status: 504, code: 'workspace_materialization_timeout' },
|
|
49
|
+
));
|
|
50
|
+
});
|
|
51
|
+
request.on('error', reject);
|
|
52
|
+
request.end(encoded);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function materializePayloadWorkspace(payload, options = {}) {
|
|
57
|
+
const ref = payload?.cloudWorkspaceRef;
|
|
58
|
+
if (!ref?.materializer) return payload;
|
|
59
|
+
const onStatus = typeof options.onStatus === 'function' ? options.onStatus : () => {};
|
|
60
|
+
onStatus({
|
|
61
|
+
phase: 'hydrating',
|
|
62
|
+
resourceId: ref.resourceId || null,
|
|
63
|
+
label: ref.kind === 'code-project' ? 'Preparing code project…' : 'Preparing cloud workspace…',
|
|
64
|
+
});
|
|
65
|
+
const request = options.request || postJson;
|
|
66
|
+
const result = await request(
|
|
67
|
+
process.env.AMALGM_WORKSPACE_MATERIALIZE_URL
|
|
68
|
+
|| `http://127.0.0.1:${runtimePort('amalgm-mcp')}/workspace/materialize`,
|
|
69
|
+
ref,
|
|
70
|
+
);
|
|
71
|
+
if (!result?.cwd || !path.isAbsolute(result.cwd)) {
|
|
72
|
+
throw Object.assign(
|
|
73
|
+
new Error('Workspace materializer did not return an absolute folder.'),
|
|
74
|
+
{ status: 500, code: 'workspace_materialization_invalid_result' },
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
onStatus({
|
|
78
|
+
phase: 'ready',
|
|
79
|
+
resourceId: ref.resourceId || null,
|
|
80
|
+
label: 'Cloud workspace ready',
|
|
81
|
+
cwd: result.cwd,
|
|
82
|
+
});
|
|
83
|
+
return { ...payload, cwd: result.cwd };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
module.exports = {
|
|
87
|
+
materializePayloadWorkspace,
|
|
88
|
+
postJson,
|
|
89
|
+
};
|