amalgm 0.1.51 → 0.1.52

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.
Files changed (70) hide show
  1. package/lib/tunnel-events.js +48 -23
  2. package/package.json +2 -2
  3. package/runtime/lib/harnesses.js +12 -4
  4. package/runtime/scripts/amalgm-mcp/agents/store.js +5 -5
  5. package/runtime/scripts/amalgm-mcp/{artifacts → apps}/advertise.js +39 -24
  6. package/runtime/scripts/amalgm-mcp/apps/rest.js +144 -0
  7. package/runtime/scripts/amalgm-mcp/apps/store.js +171 -0
  8. package/runtime/scripts/amalgm-mcp/apps/supervisor.js +439 -0
  9. package/runtime/scripts/amalgm-mcp/apps/tools.js +176 -0
  10. package/runtime/scripts/amalgm-mcp/automations/cell-references.js +237 -0
  11. package/runtime/scripts/amalgm-mcp/automations/context.js +41 -0
  12. package/runtime/scripts/amalgm-mcp/automations/rest.js +148 -0
  13. package/runtime/scripts/amalgm-mcp/automations/runner.js +613 -0
  14. package/runtime/scripts/amalgm-mcp/automations/scheduler.js +90 -0
  15. package/runtime/scripts/amalgm-mcp/automations/store.js +1125 -0
  16. package/runtime/scripts/amalgm-mcp/automations/tool-actions.js +177 -0
  17. package/runtime/scripts/amalgm-mcp/automations/tools.js +418 -0
  18. package/runtime/scripts/amalgm-mcp/automations/validator.js +225 -0
  19. package/runtime/scripts/amalgm-mcp/browser/agent-browser.js +505 -0
  20. package/runtime/scripts/amalgm-mcp/browser/electron-bridge.js +222 -0
  21. package/runtime/scripts/amalgm-mcp/browser/page.js +13 -631
  22. package/runtime/scripts/amalgm-mcp/browser/tools.js +9 -7
  23. package/runtime/scripts/amalgm-mcp/config.js +33 -48
  24. package/runtime/scripts/amalgm-mcp/deps.js +1 -31
  25. package/runtime/scripts/amalgm-mcp/events/ingress.js +50 -42
  26. package/runtime/scripts/amalgm-mcp/events/internal-workflows.js +169 -0
  27. package/runtime/scripts/amalgm-mcp/events/matcher.js +45 -14
  28. package/runtime/scripts/amalgm-mcp/events/store.js +106 -57
  29. package/runtime/scripts/amalgm-mcp/index.js +12 -14
  30. package/runtime/scripts/amalgm-mcp/lib/prefs.js +229 -65
  31. package/runtime/scripts/amalgm-mcp/lib/tool-result.js +13 -27
  32. package/runtime/scripts/amalgm-mcp/server/core-tools.js +2 -3
  33. package/runtime/scripts/amalgm-mcp/server/http.js +106 -56
  34. package/runtime/scripts/amalgm-mcp/slack/inbound.js +1 -1
  35. package/runtime/scripts/amalgm-mcp/state/db.js +119 -0
  36. package/runtime/scripts/amalgm-mcp/state/snapshot.js +16 -3
  37. package/runtime/scripts/amalgm-mcp/tasks/executor.js +1 -1
  38. package/runtime/scripts/amalgm-mcp/tests/automations-store-runner.test.js +348 -0
  39. package/runtime/scripts/amalgm-mcp/tests/events-matcher.test.js +23 -0
  40. package/runtime/scripts/amalgm-mcp/tests/workflows-store-runner.test.js +67 -0
  41. package/runtime/scripts/amalgm-mcp/toolbox/tools.js +16 -3
  42. package/runtime/scripts/amalgm-mcp/workflows/compiler.js +222 -0
  43. package/runtime/scripts/amalgm-mcp/workflows/runner.js +593 -0
  44. package/runtime/scripts/amalgm-mcp/workflows/store.js +237 -0
  45. package/runtime/scripts/chat-core/adapters/claude.js +2 -1
  46. package/runtime/scripts/chat-core/auth.js +82 -12
  47. package/runtime/scripts/chat-core/contract.js +5 -1
  48. package/runtime/scripts/chat-core/engine.js +103 -62
  49. package/runtime/scripts/chat-core/event-schema.js +8 -0
  50. package/runtime/scripts/chat-core/events.js +5 -0
  51. package/runtime/scripts/chat-core/normalizers/codex.js +13 -1
  52. package/runtime/scripts/chat-core/parts.js +21 -6
  53. package/runtime/scripts/chat-core/sse.js +3 -0
  54. package/runtime/scripts/chat-core/tests/auth.test.js +84 -6
  55. package/runtime/scripts/chat-core/tests/engine.test.js +312 -0
  56. package/runtime/scripts/chat-core/tests/native-config.test.js +23 -0
  57. package/runtime/scripts/chat-core/tool-shape.js +4 -4
  58. package/runtime/scripts/chat-core/tooling/active-memory.js +5 -4
  59. package/runtime/scripts/chat-core/tooling/native-config.js +34 -3
  60. package/runtime/scripts/local-gateway.js +34 -27
  61. package/runtime/scripts/platform-context.txt +76 -94
  62. package/runtime/scripts/amalgm-mcp/artifacts/rest.js +0 -103
  63. package/runtime/scripts/amalgm-mcp/artifacts/store.js +0 -157
  64. package/runtime/scripts/amalgm-mcp/artifacts/supervisor.js +0 -439
  65. package/runtime/scripts/amalgm-mcp/artifacts/tools.js +0 -176
  66. package/runtime/scripts/amalgm-mcp/events/executor.js +0 -258
  67. package/runtime/scripts/amalgm-mcp/events/rest.js +0 -214
  68. package/runtime/scripts/amalgm-mcp/events/tools.js +0 -323
  69. package/runtime/scripts/amalgm-mcp/tasks/rest.js +0 -110
  70. package/runtime/scripts/amalgm-mcp/tasks/tools.js +0 -416
@@ -0,0 +1,222 @@
1
+ const http = require('http');
2
+ const https = require('https');
3
+
4
+ const DEFAULT_SESSION = `mcp-${process.pid}-default`;
5
+
6
+ function config() {
7
+ const baseUrl = process.env.AMALGM_ELECTRON_BROWSER_URL;
8
+ const token = process.env.AMALGM_ELECTRON_BROWSER_TOKEN;
9
+ return baseUrl && token ? { baseUrl, token } : null;
10
+ }
11
+
12
+ function isConfigured() {
13
+ return Boolean(config());
14
+ }
15
+
16
+ function requestJson(url, { method = 'GET', headers = {}, body } = {}) {
17
+ return new Promise((resolve, reject) => {
18
+ const target = new URL(url);
19
+ const transport = target.protocol === 'https:' ? https : http;
20
+ const payload = body ? JSON.stringify(body) : null;
21
+ const req = transport.request(target, {
22
+ method,
23
+ headers: {
24
+ Accept: 'application/json',
25
+ ...(payload ? {
26
+ 'Content-Type': 'application/json',
27
+ 'Content-Length': String(Buffer.byteLength(payload)),
28
+ } : {}),
29
+ ...headers,
30
+ },
31
+ }, (res) => {
32
+ let raw = '';
33
+ res.on('data', (chunk) => { raw += chunk.toString(); });
34
+ res.on('end', () => {
35
+ let parsed = {};
36
+ if (raw.trim()) {
37
+ try {
38
+ parsed = JSON.parse(raw);
39
+ } catch (err) {
40
+ reject(new Error(`Browser bridge returned invalid JSON: ${err.message}`));
41
+ return;
42
+ }
43
+ }
44
+
45
+ if (res.statusCode && res.statusCode >= 400) {
46
+ const error = new Error(parsed?.error || `Browser bridge request failed with status ${res.statusCode}`);
47
+ error.statusCode = res.statusCode;
48
+ reject(error);
49
+ return;
50
+ }
51
+
52
+ resolve(parsed);
53
+ });
54
+ });
55
+
56
+ req.on('error', reject);
57
+ req.setTimeout(120_000, () => {
58
+ req.destroy(new Error('Browser bridge request timed out'));
59
+ });
60
+ if (payload) req.write(payload);
61
+ req.end();
62
+ });
63
+ }
64
+
65
+ function withContext(body = {}, context = {}) {
66
+ const next = {
67
+ ...body,
68
+ ...(context?.callerSessionId ? { callerSessionId: context.callerSessionId } : {}),
69
+ };
70
+ if (!next.tabId && !next.sessionId && !next.browserSessionId) {
71
+ next.browserSessionId = context?.callerSessionId || DEFAULT_SESSION;
72
+ }
73
+ return next;
74
+ }
75
+
76
+ async function call(action, body = {}, context) {
77
+ const bridge = config();
78
+ if (!bridge) throw new Error('Electron browser bridge is not configured');
79
+ return requestJson(`${bridge.baseUrl}/browser/${action}`, {
80
+ method: 'POST',
81
+ headers: { 'x-amalgm-browser-token': bridge.token },
82
+ body: withContext(body, context),
83
+ });
84
+ }
85
+
86
+ async function navigateBrowser(args = {}, context) {
87
+ return call('navigate', args, context);
88
+ }
89
+
90
+ async function screenshotBrowser(args = {}, context) {
91
+ return call('screenshot', args, context);
92
+ }
93
+
94
+ async function snapshotBrowser(args = {}, context) {
95
+ return call('snapshot', args, context);
96
+ }
97
+
98
+ async function clickBrowser(args = {}, context) {
99
+ return call('click', args, context);
100
+ }
101
+
102
+ async function typeBrowser(args = {}, context) {
103
+ return call('type', args, context);
104
+ }
105
+
106
+ async function pressBrowser(args = {}, context) {
107
+ return call('press', args, context);
108
+ }
109
+
110
+ async function getTextBrowser(args = {}, context) {
111
+ return call('get_text', args, context);
112
+ }
113
+
114
+ async function evaluateBrowser(args = {}, context) {
115
+ return call('evaluate', args, context);
116
+ }
117
+
118
+ async function stateBrowser(args = {}, context) {
119
+ return call('state', args, context);
120
+ }
121
+
122
+ async function locatorCountBrowser(args = {}, context) {
123
+ return call('locator_count', args, context);
124
+ }
125
+
126
+ async function locatorTextBrowser(args = {}, context) {
127
+ return call('locator_text', args, context);
128
+ }
129
+
130
+ async function waitForLoadStateBrowser(args = {}, context) {
131
+ return call('wait_for_load_state', args, context);
132
+ }
133
+
134
+ async function waitForURLBrowser(args = {}, context) {
135
+ return call('wait_for_url', args, context);
136
+ }
137
+
138
+ async function waitForSelectorBrowser(args = {}, context) {
139
+ return call('wait_for_selector', args, context);
140
+ }
141
+
142
+ async function tabNavigationBrowser(action, args = {}, context) {
143
+ return call(action, args, context);
144
+ }
145
+
146
+ async function tabsListBrowser(context) {
147
+ return call('tabs_list', {}, context);
148
+ }
149
+
150
+ async function tabsSelectedBrowser(context) {
151
+ return call('tabs_selected', {}, context);
152
+ }
153
+
154
+ async function tabsNewBrowser(args = {}, context) {
155
+ const sessionId = args.browserSessionId || args.sessionId || `browser-${Date.now().toString(36)}`;
156
+ return call('tabs_new', {
157
+ ...args,
158
+ browserSessionId: sessionId,
159
+ sessionId,
160
+ newTab: true,
161
+ }, context);
162
+ }
163
+
164
+ async function tabsGetBrowser(args = {}, context) {
165
+ return call('tabs_get', args, context);
166
+ }
167
+
168
+ async function tabsSelectBrowser(args = {}, context) {
169
+ return call('tabs_select', args, context);
170
+ }
171
+
172
+ async function cuaBrowser(action, args = {}, context) {
173
+ return call(action, args, context);
174
+ }
175
+
176
+ async function clipboardBrowser(action, args = {}, context) {
177
+ return call(action, args, context);
178
+ }
179
+
180
+ async function startVideoBrowser(args = {}, context) {
181
+ return call('start_video', {
182
+ ...args,
183
+ recordingSessionId: args.sessionId || args.recording_id || args.session_id,
184
+ }, context);
185
+ }
186
+
187
+ async function stopVideoBrowser(args = {}, context) {
188
+ return call('stop_video', args, context);
189
+ }
190
+
191
+ async function closeBrowser(args = {}, context) {
192
+ return call('close', args, context);
193
+ }
194
+
195
+ module.exports = {
196
+ clipboardBrowser,
197
+ closeBrowser,
198
+ clickBrowser,
199
+ cuaBrowser,
200
+ evaluateBrowser,
201
+ getTextBrowser,
202
+ isConfigured,
203
+ locatorCountBrowser,
204
+ locatorTextBrowser,
205
+ navigateBrowser,
206
+ pressBrowser,
207
+ screenshotBrowser,
208
+ snapshotBrowser,
209
+ startVideoBrowser,
210
+ stateBrowser,
211
+ stopVideoBrowser,
212
+ tabNavigationBrowser,
213
+ tabsGetBrowser,
214
+ tabsListBrowser,
215
+ tabsNewBrowser,
216
+ tabsSelectBrowser,
217
+ tabsSelectedBrowser,
218
+ typeBrowser,
219
+ waitForLoadStateBrowser,
220
+ waitForSelectorBrowser,
221
+ waitForURLBrowser,
222
+ };