amalgm 0.0.0 → 0.0.32

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 (116) hide show
  1. package/README.md +41 -1
  2. package/bin/amalgm.js +8 -2
  3. package/lib/auth-store.js +223 -0
  4. package/lib/cli.js +1132 -0
  5. package/lib/paths.js +30 -0
  6. package/lib/supervisor.js +476 -0
  7. package/lib/tunnel-chat.js +328 -0
  8. package/lib/tunnel-events.js +499 -0
  9. package/package.json +30 -3
  10. package/runtime/README.md +4 -0
  11. package/runtime/lib/chatInput.js +315 -0
  12. package/runtime/lib/harnesses.js +988 -0
  13. package/runtime/lib/local/amalgmStore.js +136 -0
  14. package/runtime/lib/local/credentialResolver.js +425 -0
  15. package/runtime/lib/mcpApps/registry.js +619 -0
  16. package/runtime/package.json +5 -0
  17. package/runtime/scripts/amalgm-mcp/agents/rest.js +144 -0
  18. package/runtime/scripts/amalgm-mcp/agents/store.js +684 -0
  19. package/runtime/scripts/amalgm-mcp/agents/talk.js +1162 -0
  20. package/runtime/scripts/amalgm-mcp/agents/tools.js +221 -0
  21. package/runtime/scripts/amalgm-mcp/artifacts/advertise.js +132 -0
  22. package/runtime/scripts/amalgm-mcp/artifacts/rest.js +103 -0
  23. package/runtime/scripts/amalgm-mcp/artifacts/store.js +157 -0
  24. package/runtime/scripts/amalgm-mcp/artifacts/supervisor.js +402 -0
  25. package/runtime/scripts/amalgm-mcp/artifacts/tools.js +176 -0
  26. package/runtime/scripts/amalgm-mcp/browser/page.js +637 -0
  27. package/runtime/scripts/amalgm-mcp/browser/tools.js +688 -0
  28. package/runtime/scripts/amalgm-mcp/config.js +140 -0
  29. package/runtime/scripts/amalgm-mcp/credentials/rest.js +45 -0
  30. package/runtime/scripts/amalgm-mcp/deps.js +40 -0
  31. package/runtime/scripts/amalgm-mcp/email/inbound.js +215 -0
  32. package/runtime/scripts/amalgm-mcp/events/executor.js +179 -0
  33. package/runtime/scripts/amalgm-mcp/events/ingress.js +113 -0
  34. package/runtime/scripts/amalgm-mcp/events/matcher.js +125 -0
  35. package/runtime/scripts/amalgm-mcp/events/rest.js +200 -0
  36. package/runtime/scripts/amalgm-mcp/events/ring-buffer.js +19 -0
  37. package/runtime/scripts/amalgm-mcp/events/store.js +113 -0
  38. package/runtime/scripts/amalgm-mcp/events/tools.js +306 -0
  39. package/runtime/scripts/amalgm-mcp/events/webhook-url.js +28 -0
  40. package/runtime/scripts/amalgm-mcp/fs/rest.js +293 -0
  41. package/runtime/scripts/amalgm-mcp/index.js +100 -0
  42. package/runtime/scripts/amalgm-mcp/lib/chat-runner.js +167 -0
  43. package/runtime/scripts/amalgm-mcp/lib/email-md.js +288 -0
  44. package/runtime/scripts/amalgm-mcp/lib/mcp-resolver.js +63 -0
  45. package/runtime/scripts/amalgm-mcp/lib/prefs.js +441 -0
  46. package/runtime/scripts/amalgm-mcp/lib/storage.js +92 -0
  47. package/runtime/scripts/amalgm-mcp/lib/supabase.js +118 -0
  48. package/runtime/scripts/amalgm-mcp/lib/tool-result.js +177 -0
  49. package/runtime/scripts/amalgm-mcp/local/rest.js +87 -0
  50. package/runtime/scripts/amalgm-mcp/mcp-connections/rest.js +234 -0
  51. package/runtime/scripts/amalgm-mcp/notify/index.js +107 -0
  52. package/runtime/scripts/amalgm-mcp/server/core-tools.js +20 -0
  53. package/runtime/scripts/amalgm-mcp/server/http.js +377 -0
  54. package/runtime/scripts/amalgm-mcp/server/mcp.js +127 -0
  55. package/runtime/scripts/amalgm-mcp/slack/inbound.js +200 -0
  56. package/runtime/scripts/amalgm-mcp/state/db.js +194 -0
  57. package/runtime/scripts/amalgm-mcp/state/events.js +113 -0
  58. package/runtime/scripts/amalgm-mcp/state/rest.js +64 -0
  59. package/runtime/scripts/amalgm-mcp/state/snapshot.js +76 -0
  60. package/runtime/scripts/amalgm-mcp/tasks/executor.js +225 -0
  61. package/runtime/scripts/amalgm-mcp/tasks/rest.js +110 -0
  62. package/runtime/scripts/amalgm-mcp/tasks/schedule-normalization.js +85 -0
  63. package/runtime/scripts/amalgm-mcp/tasks/scheduler.js +105 -0
  64. package/runtime/scripts/amalgm-mcp/tasks/store.js +154 -0
  65. package/runtime/scripts/amalgm-mcp/tasks/tools.js +391 -0
  66. package/runtime/scripts/amalgm-mcp/toolbox/rest.js +75 -0
  67. package/runtime/scripts/amalgm-mcp/toolbox/runner.js +257 -0
  68. package/runtime/scripts/amalgm-mcp/toolbox/store.js +933 -0
  69. package/runtime/scripts/amalgm-mcp/toolbox/tools.js +269 -0
  70. package/runtime/scripts/amalgm-mcp/user-api-keys/rest.js +105 -0
  71. package/runtime/scripts/amalgm-mcp/workspace/rest.js +497 -0
  72. package/runtime/scripts/chat-core/adapters/claude.js +165 -0
  73. package/runtime/scripts/chat-core/adapters/codex.js +313 -0
  74. package/runtime/scripts/chat-core/adapters/opencode.js +412 -0
  75. package/runtime/scripts/chat-core/auth.js +177 -0
  76. package/runtime/scripts/chat-core/contract.js +328 -0
  77. package/runtime/scripts/chat-core/credentials/store.js +212 -0
  78. package/runtime/scripts/chat-core/egress.js +87 -0
  79. package/runtime/scripts/chat-core/engine.js +253 -0
  80. package/runtime/scripts/chat-core/event-schema.js +231 -0
  81. package/runtime/scripts/chat-core/events.js +190 -0
  82. package/runtime/scripts/chat-core/index.js +11 -0
  83. package/runtime/scripts/chat-core/input.js +50 -0
  84. package/runtime/scripts/chat-core/normalizers/claude.js +450 -0
  85. package/runtime/scripts/chat-core/normalizers/codex.js +380 -0
  86. package/runtime/scripts/chat-core/normalizers/normalizer_spec.md +259 -0
  87. package/runtime/scripts/chat-core/normalizers/opencode.js +552 -0
  88. package/runtime/scripts/chat-core/normalizers/tool_contract.md +123 -0
  89. package/runtime/scripts/chat-core/normalizers/usage_contract.md +304 -0
  90. package/runtime/scripts/chat-core/parts.js +253 -0
  91. package/runtime/scripts/chat-core/recorder.js +65 -0
  92. package/runtime/scripts/chat-core/runtime.js +86 -0
  93. package/runtime/scripts/chat-core/server.js +163 -0
  94. package/runtime/scripts/chat-core/sse.js +196 -0
  95. package/runtime/scripts/chat-core/stores.js +100 -0
  96. package/runtime/scripts/chat-core/tool-display.js +149 -0
  97. package/runtime/scripts/chat-core/tool-shape.js +143 -0
  98. package/runtime/scripts/chat-core/tooling/mcp-bundle.js +161 -0
  99. package/runtime/scripts/chat-core/tooling/mcp-relay.js +97 -0
  100. package/runtime/scripts/chat-core/tooling/native-binaries.js +608 -0
  101. package/runtime/scripts/chat-core/tooling/system-prompt.js +20 -0
  102. package/runtime/scripts/chat-core/usage.js +343 -0
  103. package/runtime/scripts/chat-server/config.js +110 -0
  104. package/runtime/scripts/chat-server/db.js +529 -0
  105. package/runtime/scripts/chat-server/index.js +33 -0
  106. package/runtime/scripts/chat-server/model-catalog.js +327 -0
  107. package/runtime/scripts/chat-server.js +75 -0
  108. package/runtime/scripts/credential-adapter.js +131 -0
  109. package/runtime/scripts/fs-watcher.js +888 -0
  110. package/runtime/scripts/local-gateway.js +854 -0
  111. package/runtime/scripts/platform-context.txt +246 -0
  112. package/runtime/scripts/port-monitor.js +175 -0
  113. package/runtime/scripts/proxy-token-store.js +162 -0
  114. package/runtime/scripts/runtime-auth.js +163 -0
  115. package/runtime/scripts/test-claude-code-models.js +87 -0
  116. package/runtime/tsconfig.json +15 -0
@@ -0,0 +1,144 @@
1
+ /**
2
+ * /agents/* REST routes (UI-only, not MCP tools).
3
+ */
4
+
5
+ const {
6
+ createAgent,
7
+ deleteAgent,
8
+ getAllAgentsWithBuiltins,
9
+ resolveAgent,
10
+ updateAgent,
11
+ } = require('./store');
12
+ const credentialAdapter = require('../../credential-adapter');
13
+
14
+ function coerceAuthMethodForHarness(harnessId, authMethod) {
15
+ const supported = credentialAdapter.SUPPORTED_AUTH_BY_HARNESS?.[harnessId] || ['amalgm'];
16
+ return supported.includes(authMethod) ? authMethod : supported[0] || 'amalgm';
17
+ }
18
+
19
+ function normalizeStringList(values) {
20
+ if (!Array.isArray(values)) return [];
21
+ return [...new Set(values
22
+ .filter((value) => typeof value === 'string')
23
+ .map((value) => value.trim())
24
+ .filter(Boolean))];
25
+ }
26
+
27
+ function normalizeMcpConfig(mcp, mcpAppIds, nativeMcps) {
28
+ return {
29
+ inheritAll: mcp?.inheritAll !== false,
30
+ customServers: Array.isArray(mcp?.customServers) ? mcp.customServers : [],
31
+ appIds: normalizeStringList(mcp?.appIds ?? mcpAppIds),
32
+ nativeMcps: normalizeStringList(mcp?.nativeMcps ?? nativeMcps),
33
+ };
34
+ }
35
+
36
+ function normalizeToolConfig(tools, legacyMcp) {
37
+ const raw = tools && typeof tools === 'object' && !Array.isArray(tools) ? tools : null;
38
+ const selectedToolIds = normalizeStringList(
39
+ raw?.selectedToolIds
40
+ ?? raw?.selected
41
+ ?? [
42
+ ...normalizeStringList(legacyMcp?.appIds),
43
+ ...normalizeStringList(legacyMcp?.nativeMcps),
44
+ ],
45
+ );
46
+ return {
47
+ mode: raw?.mode === 'selected' || (!raw && legacyMcp?.inheritAll === false) ? 'selected' : 'all',
48
+ selectedToolIds,
49
+ };
50
+ }
51
+
52
+ async function handleList(sendJson) {
53
+ sendJson(200, { agents: getAllAgentsWithBuiltins() });
54
+ }
55
+
56
+ async function handleGet(body, sendJson) {
57
+ const { agent_id } = body;
58
+ const agent = resolveAgent(agent_id);
59
+ if (!agent) return sendJson(404, { error: `Agent not found: ${agent_id}` });
60
+ sendJson(200, { agent });
61
+ }
62
+
63
+ async function handleCreate(body, sendJson) {
64
+ const {
65
+ name,
66
+ description,
67
+ baseHarnessId,
68
+ baseModelId,
69
+ systemPrompt,
70
+ files,
71
+ skills,
72
+ mcpAppIds,
73
+ nativeMcps,
74
+ mcp,
75
+ tools,
76
+ authMethod,
77
+ } = body;
78
+ if (!name || !name.trim()) return sendJson(400, { error: 'name is required' });
79
+ if (!baseHarnessId) return sendJson(400, { error: 'baseHarnessId is required' });
80
+
81
+ const mcpConfig = normalizeMcpConfig(mcp, mcpAppIds, nativeMcps);
82
+ const toolConfig = normalizeToolConfig(tools, mcpConfig);
83
+ let agent;
84
+ try {
85
+ agent = createAgent({
86
+ name: name.trim(),
87
+ description: description || '',
88
+ baseHarnessId,
89
+ baseModelId: baseModelId || '',
90
+ systemPrompt: systemPrompt || '',
91
+ files: normalizeStringList(files),
92
+ skills: normalizeStringList(skills),
93
+ mcpAppIds: normalizeStringList(mcpConfig.appIds),
94
+ nativeMcps: normalizeStringList(mcpConfig.nativeMcps),
95
+ tools: toolConfig,
96
+ mcp: {
97
+ ...mcpConfig,
98
+ inheritAll: toolConfig.mode !== 'selected',
99
+ },
100
+ authMethod: coerceAuthMethodForHarness(baseHarnessId, authMethod),
101
+ });
102
+ } catch (error) {
103
+ return sendJson(400, { error: error.message || 'Failed to create agent' });
104
+ }
105
+ console.log(`[AmalgmMCP] Created agent: ${agent.id} (${agent.name})`);
106
+ sendJson(200, { ok: true, agent });
107
+ }
108
+
109
+ async function handleUpdate(body, sendJson) {
110
+ const { agent_id, ...updates } = body;
111
+ if (!agent_id) return sendJson(400, { error: 'agent_id is required' });
112
+ const existing = resolveAgent(agent_id);
113
+ if (!existing) return sendJson(404, { error: `Agent not found: ${agent_id}` });
114
+
115
+ if (updates.authMethod !== undefined) {
116
+ updates.authMethod = coerceAuthMethodForHarness(existing.baseHarnessId, updates.authMethod);
117
+ }
118
+
119
+ let agent;
120
+ try {
121
+ agent = updateAgent(agent_id, updates);
122
+ } catch (error) {
123
+ const message = error.message || 'Failed to update agent';
124
+ return sendJson(message.includes('not found') ? 404 : 400, { error: message });
125
+ }
126
+ console.log(`[AmalgmMCP] Updated agent: ${agent.id} (${agent.name})`);
127
+ sendJson(200, { ok: true, agent });
128
+ }
129
+
130
+ async function handleDelete(body, sendJson) {
131
+ const { agent_id } = body;
132
+ if (!agent_id) return sendJson(400, { error: 'agent_id is required' });
133
+ let deleted;
134
+ try {
135
+ deleted = deleteAgent(agent_id);
136
+ } catch (error) {
137
+ const message = error.message || 'Failed to delete agent';
138
+ return sendJson(message.includes('not found') ? 404 : 400, { error: message });
139
+ }
140
+ console.log(`[AmalgmMCP] Deleted agent: ${agent_id} (${deleted.name})`);
141
+ sendJson(200, { ok: true, deleted });
142
+ }
143
+
144
+ module.exports = { handleList, handleGet, handleCreate, handleUpdate, handleDelete };