@amodalai/runtime 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/LICENSE +21 -0
- package/dist/.last_build +0 -0
- package/dist/src/agent/agent-runner.d.ts +13 -0
- package/dist/src/agent/agent-runner.js +827 -0
- package/dist/src/agent/agent-runner.js.map +1 -0
- package/dist/src/agent/agent-runner.test.d.ts +6 -0
- package/dist/src/agent/agent-runner.test.js +552 -0
- package/dist/src/agent/agent-runner.test.js.map +1 -0
- package/dist/src/agent/agent-types.d.ts +57 -0
- package/dist/src/agent/agent-types.js +17 -0
- package/dist/src/agent/agent-types.js.map +1 -0
- package/dist/src/agent/agent-types.test.d.ts +6 -0
- package/dist/src/agent/agent-types.test.js +44 -0
- package/dist/src/agent/agent-types.test.js.map +1 -0
- package/dist/src/agent/automation-bridge.d.ts +24 -0
- package/dist/src/agent/automation-bridge.js +24 -0
- package/dist/src/agent/automation-bridge.js.map +1 -0
- package/dist/src/agent/automation-bridge.test.d.ts +6 -0
- package/dist/src/agent/automation-bridge.test.js +67 -0
- package/dist/src/agent/automation-bridge.test.js.map +1 -0
- package/dist/src/agent/config-watcher.d.ts +20 -0
- package/dist/src/agent/config-watcher.js +68 -0
- package/dist/src/agent/config-watcher.js.map +1 -0
- package/dist/src/agent/config-watcher.test.d.ts +6 -0
- package/dist/src/agent/config-watcher.test.js +83 -0
- package/dist/src/agent/config-watcher.test.js.map +1 -0
- package/dist/src/agent/custom-tools-e2e.test.d.ts +6 -0
- package/dist/src/agent/custom-tools-e2e.test.js +566 -0
- package/dist/src/agent/custom-tools-e2e.test.js.map +1 -0
- package/dist/src/agent/local-server.d.ts +15 -0
- package/dist/src/agent/local-server.js +158 -0
- package/dist/src/agent/local-server.js.map +1 -0
- package/dist/src/agent/local-server.test.d.ts +6 -0
- package/dist/src/agent/local-server.test.js +126 -0
- package/dist/src/agent/local-server.test.js.map +1 -0
- package/dist/src/agent/proactive/delivery.d.ts +21 -0
- package/dist/src/agent/proactive/delivery.js +68 -0
- package/dist/src/agent/proactive/delivery.js.map +1 -0
- package/dist/src/agent/proactive/delivery.test.d.ts +6 -0
- package/dist/src/agent/proactive/delivery.test.js +65 -0
- package/dist/src/agent/proactive/delivery.test.js.map +1 -0
- package/dist/src/agent/proactive/proactive-runner.d.ts +76 -0
- package/dist/src/agent/proactive/proactive-runner.js +201 -0
- package/dist/src/agent/proactive/proactive-runner.js.map +1 -0
- package/dist/src/agent/proactive/proactive-runner.test.d.ts +6 -0
- package/dist/src/agent/proactive/proactive-runner.test.js +265 -0
- package/dist/src/agent/proactive/proactive-runner.test.js.map +1 -0
- package/dist/src/agent/request-helper.d.ts +16 -0
- package/dist/src/agent/request-helper.js +87 -0
- package/dist/src/agent/request-helper.js.map +1 -0
- package/dist/src/agent/routes/automations.d.ts +19 -0
- package/dist/src/agent/routes/automations.js +58 -0
- package/dist/src/agent/routes/automations.js.map +1 -0
- package/dist/src/agent/routes/automations.test.d.ts +6 -0
- package/dist/src/agent/routes/automations.test.js +117 -0
- package/dist/src/agent/routes/automations.test.js.map +1 -0
- package/dist/src/agent/routes/chat.d.ts +35 -0
- package/dist/src/agent/routes/chat.js +88 -0
- package/dist/src/agent/routes/chat.js.map +1 -0
- package/dist/src/agent/routes/chat.test.d.ts +6 -0
- package/dist/src/agent/routes/chat.test.js +115 -0
- package/dist/src/agent/routes/chat.test.js.map +1 -0
- package/dist/src/agent/routes/inspect.d.ts +12 -0
- package/dist/src/agent/routes/inspect.js +40 -0
- package/dist/src/agent/routes/inspect.js.map +1 -0
- package/dist/src/agent/routes/inspect.test.d.ts +6 -0
- package/dist/src/agent/routes/inspect.test.js +80 -0
- package/dist/src/agent/routes/inspect.test.js.map +1 -0
- package/dist/src/agent/routes/stores.d.ts +20 -0
- package/dist/src/agent/routes/stores.js +137 -0
- package/dist/src/agent/routes/stores.js.map +1 -0
- package/dist/src/agent/routes/stores.test.d.ts +6 -0
- package/dist/src/agent/routes/stores.test.js +191 -0
- package/dist/src/agent/routes/stores.test.js.map +1 -0
- package/dist/src/agent/routes/task.d.ts +11 -0
- package/dist/src/agent/routes/task.js +116 -0
- package/dist/src/agent/routes/task.js.map +1 -0
- package/dist/src/agent/routes/task.test.d.ts +6 -0
- package/dist/src/agent/routes/task.test.js +91 -0
- package/dist/src/agent/routes/task.test.js.map +1 -0
- package/dist/src/agent/routes/webhooks.d.ts +17 -0
- package/dist/src/agent/routes/webhooks.js +53 -0
- package/dist/src/agent/routes/webhooks.js.map +1 -0
- package/dist/src/agent/routes/webhooks.test.d.ts +6 -0
- package/dist/src/agent/routes/webhooks.test.js +100 -0
- package/dist/src/agent/routes/webhooks.test.js.map +1 -0
- package/dist/src/agent/session-manager.d.ts +72 -0
- package/dist/src/agent/session-manager.js +214 -0
- package/dist/src/agent/session-manager.js.map +1 -0
- package/dist/src/agent/session-manager.test.d.ts +6 -0
- package/dist/src/agent/session-manager.test.js +145 -0
- package/dist/src/agent/session-manager.test.js.map +1 -0
- package/dist/src/agent/shell-executor-local.d.ts +16 -0
- package/dist/src/agent/shell-executor-local.js +51 -0
- package/dist/src/agent/shell-executor-local.js.map +1 -0
- package/dist/src/agent/shell-executor-local.test.d.ts +6 -0
- package/dist/src/agent/shell-executor-local.test.js +46 -0
- package/dist/src/agent/shell-executor-local.test.js.map +1 -0
- package/dist/src/agent/snapshot-server.d.ts +38 -0
- package/dist/src/agent/snapshot-server.js +114 -0
- package/dist/src/agent/snapshot-server.js.map +1 -0
- package/dist/src/agent/stores-e2e.test.d.ts +6 -0
- package/dist/src/agent/stores-e2e.test.js +433 -0
- package/dist/src/agent/stores-e2e.test.js.map +1 -0
- package/dist/src/agent/tool-context-builder.d.ts +11 -0
- package/dist/src/agent/tool-context-builder.js +84 -0
- package/dist/src/agent/tool-context-builder.js.map +1 -0
- package/dist/src/agent/tool-context-builder.test.d.ts +6 -0
- package/dist/src/agent/tool-context-builder.test.js +152 -0
- package/dist/src/agent/tool-context-builder.test.js.map +1 -0
- package/dist/src/agent/tool-executor-local.d.ts +15 -0
- package/dist/src/agent/tool-executor-local.js +74 -0
- package/dist/src/agent/tool-executor-local.js.map +1 -0
- package/dist/src/agent/tool-executor-local.test.d.ts +6 -0
- package/dist/src/agent/tool-executor-local.test.js +116 -0
- package/dist/src/agent/tool-executor-local.test.js.map +1 -0
- package/dist/src/agent/tool-harness-template.d.ts +23 -0
- package/dist/src/agent/tool-harness-template.js +94 -0
- package/dist/src/agent/tool-harness-template.js.map +1 -0
- package/dist/src/agent/user-context-fetcher.d.ts +25 -0
- package/dist/src/agent/user-context-fetcher.js +79 -0
- package/dist/src/agent/user-context-fetcher.js.map +1 -0
- package/dist/src/agent/user-context-fetcher.test.d.ts +6 -0
- package/dist/src/agent/user-context-fetcher.test.js +121 -0
- package/dist/src/agent/user-context-fetcher.test.js.map +1 -0
- package/dist/src/audit/audit-client.d.ts +46 -0
- package/dist/src/audit/audit-client.js +83 -0
- package/dist/src/audit/audit-client.js.map +1 -0
- package/dist/src/cron/heartbeat-runner.d.ts +24 -0
- package/dist/src/cron/heartbeat-runner.js +87 -0
- package/dist/src/cron/heartbeat-runner.js.map +1 -0
- package/dist/src/cron/heartbeat-runner.test.d.ts +6 -0
- package/dist/src/cron/heartbeat-runner.test.js +120 -0
- package/dist/src/cron/heartbeat-runner.test.js.map +1 -0
- package/dist/src/cron/heartbeat-scheduler.d.ts +26 -0
- package/dist/src/cron/heartbeat-scheduler.js +54 -0
- package/dist/src/cron/heartbeat-scheduler.js.map +1 -0
- package/dist/src/cron/heartbeat-scheduler.test.d.ts +6 -0
- package/dist/src/cron/heartbeat-scheduler.test.js +61 -0
- package/dist/src/cron/heartbeat-scheduler.test.js.map +1 -0
- package/dist/src/index.d.ts +24 -0
- package/dist/src/index.js +118 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/middleware/auth.d.ts +40 -0
- package/dist/src/middleware/auth.js +135 -0
- package/dist/src/middleware/auth.js.map +1 -0
- package/dist/src/middleware/auth.test.d.ts +6 -0
- package/dist/src/middleware/auth.test.js +268 -0
- package/dist/src/middleware/auth.test.js.map +1 -0
- package/dist/src/middleware/error-handler.d.ts +20 -0
- package/dist/src/middleware/error-handler.js +48 -0
- package/dist/src/middleware/error-handler.js.map +1 -0
- package/dist/src/middleware/error-handler.test.d.ts +6 -0
- package/dist/src/middleware/error-handler.test.js +68 -0
- package/dist/src/middleware/error-handler.test.js.map +1 -0
- package/dist/src/middleware/request-validation.d.ts +13 -0
- package/dist/src/middleware/request-validation.js +26 -0
- package/dist/src/middleware/request-validation.js.map +1 -0
- package/dist/src/middleware/request-validation.test.d.ts +6 -0
- package/dist/src/middleware/request-validation.test.js +57 -0
- package/dist/src/middleware/request-validation.test.js.map +1 -0
- package/dist/src/output/email-output.d.ts +10 -0
- package/dist/src/output/email-output.js +12 -0
- package/dist/src/output/email-output.js.map +1 -0
- package/dist/src/output/output-router.d.ts +12 -0
- package/dist/src/output/output-router.js +36 -0
- package/dist/src/output/output-router.js.map +1 -0
- package/dist/src/output/output-router.test.d.ts +6 -0
- package/dist/src/output/output-router.test.js +132 -0
- package/dist/src/output/output-router.test.js.map +1 -0
- package/dist/src/output/slack-output.d.ts +10 -0
- package/dist/src/output/slack-output.js +54 -0
- package/dist/src/output/slack-output.js.map +1 -0
- package/dist/src/output/webhook-output.d.ts +10 -0
- package/dist/src/output/webhook-output.js +25 -0
- package/dist/src/output/webhook-output.js.map +1 -0
- package/dist/src/routes/ai-stream.d.ts +159 -0
- package/dist/src/routes/ai-stream.js +309 -0
- package/dist/src/routes/ai-stream.js.map +1 -0
- package/dist/src/routes/ai-stream.test.d.ts +6 -0
- package/dist/src/routes/ai-stream.test.js +586 -0
- package/dist/src/routes/ai-stream.test.js.map +1 -0
- package/dist/src/routes/ask-user-response.d.ts +30 -0
- package/dist/src/routes/ask-user-response.js +61 -0
- package/dist/src/routes/ask-user-response.js.map +1 -0
- package/dist/src/routes/ask-user-response.test.d.ts +6 -0
- package/dist/src/routes/ask-user-response.test.js +88 -0
- package/dist/src/routes/ask-user-response.test.js.map +1 -0
- package/dist/src/routes/chat-stream.d.ts +14 -0
- package/dist/src/routes/chat-stream.js +84 -0
- package/dist/src/routes/chat-stream.js.map +1 -0
- package/dist/src/routes/chat-stream.test.d.ts +6 -0
- package/dist/src/routes/chat-stream.test.js +155 -0
- package/dist/src/routes/chat-stream.test.js.map +1 -0
- package/dist/src/routes/chat.d.ts +13 -0
- package/dist/src/routes/chat.js +55 -0
- package/dist/src/routes/chat.js.map +1 -0
- package/dist/src/routes/chat.test.d.ts +6 -0
- package/dist/src/routes/chat.test.js +99 -0
- package/dist/src/routes/chat.test.js.map +1 -0
- package/dist/src/routes/health.d.ts +13 -0
- package/dist/src/routes/health.js +23 -0
- package/dist/src/routes/health.js.map +1 -0
- package/dist/src/routes/health.test.d.ts +6 -0
- package/dist/src/routes/health.test.js +45 -0
- package/dist/src/routes/health.test.js.map +1 -0
- package/dist/src/routes/sessions.d.ts +14 -0
- package/dist/src/routes/sessions.js +82 -0
- package/dist/src/routes/sessions.js.map +1 -0
- package/dist/src/routes/webhooks.d.ts +13 -0
- package/dist/src/routes/webhooks.js +43 -0
- package/dist/src/routes/webhooks.js.map +1 -0
- package/dist/src/routes/webhooks.test.d.ts +6 -0
- package/dist/src/routes/webhooks.test.js +80 -0
- package/dist/src/routes/webhooks.test.js.map +1 -0
- package/dist/src/routes/widget-actions.d.ts +49 -0
- package/dist/src/routes/widget-actions.js +78 -0
- package/dist/src/routes/widget-actions.js.map +1 -0
- package/dist/src/server.d.ts +31 -0
- package/dist/src/server.js +129 -0
- package/dist/src/server.js.map +1 -0
- package/dist/src/server.test.d.ts +6 -0
- package/dist/src/server.test.js +153 -0
- package/dist/src/server.test.js.map +1 -0
- package/dist/src/session/history-converter.d.ts +21 -0
- package/dist/src/session/history-converter.js +59 -0
- package/dist/src/session/history-converter.js.map +1 -0
- package/dist/src/session/history-converter.test.d.ts +6 -0
- package/dist/src/session/history-converter.test.js +130 -0
- package/dist/src/session/history-converter.test.js.map +1 -0
- package/dist/src/session/session-manager.d.ts +117 -0
- package/dist/src/session/session-manager.js +480 -0
- package/dist/src/session/session-manager.js.map +1 -0
- package/dist/src/session/session-manager.test.d.ts +6 -0
- package/dist/src/session/session-manager.test.js +586 -0
- package/dist/src/session/session-manager.test.js.map +1 -0
- package/dist/src/session/session-runner.d.ts +30 -0
- package/dist/src/session/session-runner.js +771 -0
- package/dist/src/session/session-runner.js.map +1 -0
- package/dist/src/session/session-runner.test.d.ts +6 -0
- package/dist/src/session/session-runner.test.js +842 -0
- package/dist/src/session/session-runner.test.js.map +1 -0
- package/dist/src/stores/index.d.ts +8 -0
- package/dist/src/stores/index.js +9 -0
- package/dist/src/stores/index.js.map +1 -0
- package/dist/src/stores/key-resolver.d.ts +21 -0
- package/dist/src/stores/key-resolver.js +30 -0
- package/dist/src/stores/key-resolver.js.map +1 -0
- package/dist/src/stores/key-resolver.test.d.ts +6 -0
- package/dist/src/stores/key-resolver.test.js +31 -0
- package/dist/src/stores/key-resolver.test.js.map +1 -0
- package/dist/src/stores/pglite-store-backend.d.ts +36 -0
- package/dist/src/stores/pglite-store-backend.js +227 -0
- package/dist/src/stores/pglite-store-backend.js.map +1 -0
- package/dist/src/stores/pglite-store-backend.test.d.ts +6 -0
- package/dist/src/stores/pglite-store-backend.test.js +150 -0
- package/dist/src/stores/pglite-store-backend.test.js.map +1 -0
- package/dist/src/stores/ttl-resolver.d.ts +24 -0
- package/dist/src/stores/ttl-resolver.js +64 -0
- package/dist/src/stores/ttl-resolver.js.map +1 -0
- package/dist/src/stores/ttl-resolver.test.d.ts +6 -0
- package/dist/src/stores/ttl-resolver.test.js +68 -0
- package/dist/src/stores/ttl-resolver.test.js.map +1 -0
- package/dist/src/types.d.ts +227 -0
- package/dist/src/types.js +50 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/types.test.d.ts +6 -0
- package/dist/src/types.test.js +68 -0
- package/dist/src/types.test.js.map +1 -0
- package/dist/src/utils/jwt-verify.d.ts +20 -0
- package/dist/src/utils/jwt-verify.js +34 -0
- package/dist/src/utils/jwt-verify.js.map +1 -0
- package/dist/src/utils/jwt-verify.test.d.ts +6 -0
- package/dist/src/utils/jwt-verify.test.js +156 -0
- package/dist/src/utils/jwt-verify.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Amodal Labs, Inc.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
7
|
+
// Mock fetch globally
|
|
8
|
+
const mockFetch = vi.fn();
|
|
9
|
+
vi.stubGlobal('fetch', mockFetch);
|
|
10
|
+
// Dynamic imports after mocking
|
|
11
|
+
const { sendSlackOutput } = await import('./slack-output.js');
|
|
12
|
+
const { sendWebhookOutput } = await import('./webhook-output.js');
|
|
13
|
+
const { sendEmailOutput } = await import('./email-output.js');
|
|
14
|
+
const { routeOutput } = await import('./output-router.js');
|
|
15
|
+
function makeResult(overrides = {}) {
|
|
16
|
+
return {
|
|
17
|
+
automation: 'zone-monitor',
|
|
18
|
+
response: 'All zones clear.',
|
|
19
|
+
tool_calls: [
|
|
20
|
+
{
|
|
21
|
+
tool_name: 'get_zone_overview',
|
|
22
|
+
tool_id: 'call-1',
|
|
23
|
+
status: 'success',
|
|
24
|
+
duration_ms: 120,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
output_sent: false,
|
|
28
|
+
duration_ms: 500,
|
|
29
|
+
...overrides,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
describe('sendSlackOutput', () => {
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
mockFetch.mockReset();
|
|
35
|
+
});
|
|
36
|
+
it('posts formatted blocks to Slack webhook URL', async () => {
|
|
37
|
+
mockFetch.mockResolvedValueOnce({ ok: true });
|
|
38
|
+
await sendSlackOutput('https://hooks.slack.com/abc', makeResult());
|
|
39
|
+
expect(mockFetch).toHaveBeenCalledOnce();
|
|
40
|
+
const [url, opts] = mockFetch.mock.calls[0];
|
|
41
|
+
expect(url).toBe('https://hooks.slack.com/abc');
|
|
42
|
+
expect(opts.method).toBe('POST');
|
|
43
|
+
const body = JSON.parse(opts.body);
|
|
44
|
+
expect(body.blocks).toBeDefined();
|
|
45
|
+
expect(body.blocks.length).toBeGreaterThanOrEqual(3);
|
|
46
|
+
});
|
|
47
|
+
it('throws on non-ok response', async () => {
|
|
48
|
+
mockFetch.mockResolvedValueOnce({
|
|
49
|
+
ok: false,
|
|
50
|
+
status: 500,
|
|
51
|
+
statusText: 'Internal Server Error',
|
|
52
|
+
});
|
|
53
|
+
await expect(sendSlackOutput('https://hooks.slack.com/abc', makeResult())).rejects.toThrow('Slack webhook failed');
|
|
54
|
+
});
|
|
55
|
+
it('includes tool call summary in blocks', async () => {
|
|
56
|
+
mockFetch.mockResolvedValueOnce({ ok: true });
|
|
57
|
+
await sendSlackOutput('https://hooks.slack.com/abc', makeResult());
|
|
58
|
+
const body = JSON.parse(mockFetch.mock.calls[0][1].body);
|
|
59
|
+
const toolBlock = body.blocks.find((b) => typeof b['text'] === 'object' &&
|
|
60
|
+
(b['text']['text'] ?? '').includes('Tool calls'));
|
|
61
|
+
expect(toolBlock).toBeDefined();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
describe('sendWebhookOutput', () => {
|
|
65
|
+
beforeEach(() => {
|
|
66
|
+
mockFetch.mockReset();
|
|
67
|
+
});
|
|
68
|
+
it('posts JSON to generic webhook URL', async () => {
|
|
69
|
+
mockFetch.mockResolvedValueOnce({ ok: true });
|
|
70
|
+
await sendWebhookOutput('https://example.com/hook', makeResult());
|
|
71
|
+
expect(mockFetch).toHaveBeenCalledOnce();
|
|
72
|
+
const [url, opts] = mockFetch.mock.calls[0];
|
|
73
|
+
expect(url).toBe('https://example.com/hook');
|
|
74
|
+
const body = JSON.parse(opts.body);
|
|
75
|
+
expect(body.automation).toBe('zone-monitor');
|
|
76
|
+
expect(body.response).toBe('All zones clear.');
|
|
77
|
+
expect(body.tool_calls).toHaveLength(1);
|
|
78
|
+
expect(body.timestamp).toBeDefined();
|
|
79
|
+
});
|
|
80
|
+
it('throws on non-ok response', async () => {
|
|
81
|
+
mockFetch.mockResolvedValueOnce({
|
|
82
|
+
ok: false,
|
|
83
|
+
status: 404,
|
|
84
|
+
statusText: 'Not Found',
|
|
85
|
+
});
|
|
86
|
+
await expect(sendWebhookOutput('https://example.com/hook', makeResult())).rejects.toThrow('Webhook failed');
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
describe('sendEmailOutput', () => {
|
|
90
|
+
it('logs warning to stderr', async () => {
|
|
91
|
+
const writeSpy = vi.spyOn(process.stderr, 'write').mockReturnValue(true);
|
|
92
|
+
await sendEmailOutput('admin@example.com', makeResult());
|
|
93
|
+
expect(writeSpy).toHaveBeenCalledOnce();
|
|
94
|
+
const msg = writeSpy.mock.calls[0]?.[0];
|
|
95
|
+
expect(msg).toContain('Email output not implemented');
|
|
96
|
+
expect(msg).toContain('admin@example.com');
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
describe('routeOutput', () => {
|
|
100
|
+
beforeEach(() => {
|
|
101
|
+
mockFetch.mockReset();
|
|
102
|
+
});
|
|
103
|
+
it('routes to slack channel', async () => {
|
|
104
|
+
mockFetch.mockResolvedValueOnce({ ok: true });
|
|
105
|
+
const sent = await routeOutput({ channel: 'slack', target: 'https://hooks.slack.com/abc' }, makeResult());
|
|
106
|
+
expect(sent).toBe(true);
|
|
107
|
+
expect(mockFetch).toHaveBeenCalledOnce();
|
|
108
|
+
});
|
|
109
|
+
it('routes to webhook channel', async () => {
|
|
110
|
+
mockFetch.mockResolvedValueOnce({ ok: true });
|
|
111
|
+
const sent = await routeOutput({ channel: 'webhook', target: 'https://example.com/hook' }, makeResult());
|
|
112
|
+
expect(sent).toBe(true);
|
|
113
|
+
});
|
|
114
|
+
it('routes to email channel (stub)', async () => {
|
|
115
|
+
vi.spyOn(process.stderr, 'write').mockReturnValue(true);
|
|
116
|
+
const sent = await routeOutput({ channel: 'email', target: 'admin@example.com' }, makeResult());
|
|
117
|
+
expect(sent).toBe(true);
|
|
118
|
+
});
|
|
119
|
+
it('returns false and logs for unknown channel', async () => {
|
|
120
|
+
const writeSpy = vi.spyOn(process.stderr, 'write').mockReturnValue(true);
|
|
121
|
+
const sent = await routeOutput({ channel: 'sms', target: '+1234567890' }, makeResult());
|
|
122
|
+
expect(sent).toBe(false);
|
|
123
|
+
expect(writeSpy).toHaveBeenCalled();
|
|
124
|
+
});
|
|
125
|
+
it('catches errors and returns false', async () => {
|
|
126
|
+
mockFetch.mockRejectedValueOnce(new Error('network error'));
|
|
127
|
+
vi.spyOn(process.stderr, 'write').mockReturnValue(true);
|
|
128
|
+
const sent = await routeOutput({ channel: 'slack', target: 'https://hooks.slack.com/abc' }, makeResult());
|
|
129
|
+
expect(sent).toBe(false);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
//# sourceMappingURL=output-router.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-router.test.js","sourceRoot":"","sources":["../../../src/output/output-router.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAG9D,sBAAsB;AACtB,MAAM,SAAS,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;AAC1B,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AAElC,gCAAgC;AAChC,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAC9D,MAAM,EAAE,iBAAiB,EAAE,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,CAAC;AACl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D,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAExD,MAAM,IAAI,GAAG,MAAM,WAAW,CAC5B,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,6BAA6B,EAAE,EAC3D,UAAU,EAAE,CACb,CAAC;QACF,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Amodal Labs, Inc.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
import type { AutomationResult } from '../types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Format automation result for Slack and POST to webhook URL.
|
|
9
|
+
*/
|
|
10
|
+
export declare function sendSlackOutput(target: string, result: AutomationResult): Promise<void>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Amodal Labs, Inc.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Format automation result for Slack and POST to webhook URL.
|
|
8
|
+
*/
|
|
9
|
+
export async function sendSlackOutput(target, result) {
|
|
10
|
+
const blocks = [
|
|
11
|
+
{
|
|
12
|
+
type: 'header',
|
|
13
|
+
text: {
|
|
14
|
+
type: 'plain_text',
|
|
15
|
+
text: `Automation: ${result.automation}`,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
type: 'section',
|
|
20
|
+
text: {
|
|
21
|
+
type: 'mrkdwn',
|
|
22
|
+
text: result.response || '_No response_',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
if (result.tool_calls.length > 0) {
|
|
27
|
+
const toolSummary = result.tool_calls
|
|
28
|
+
.map((tc) => `• ${tc.tool_name}: ${tc.status}${tc.error ? ` (${tc.error})` : ''}`)
|
|
29
|
+
.join('\n');
|
|
30
|
+
blocks.push({
|
|
31
|
+
type: 'section',
|
|
32
|
+
text: {
|
|
33
|
+
type: 'mrkdwn',
|
|
34
|
+
text: `*Tool calls:*\n${toolSummary}`,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
blocks.push({
|
|
39
|
+
type: 'context',
|
|
40
|
+
text: {
|
|
41
|
+
type: 'mrkdwn',
|
|
42
|
+
text: `Duration: ${result.duration_ms}ms`,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
const response = await fetch(target, {
|
|
46
|
+
method: 'POST',
|
|
47
|
+
headers: { 'Content-Type': 'application/json' },
|
|
48
|
+
body: JSON.stringify({ blocks }),
|
|
49
|
+
});
|
|
50
|
+
if (!response.ok) {
|
|
51
|
+
throw new Error(`Slack webhook failed: ${response.status} ${response.statusText}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=slack-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slack-output.js","sourceRoot":"","sources":["../../../src/output/slack-output.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,MAAc,EACd,MAAwB;IAExB,MAAM,MAAM,GAAG;QACb;YACE,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE;gBACJ,IAAI,EAAE,YAAY;gBAClB,IAAI,EAAE,eAAe,MAAM,CAAC,UAAU,EAAE;aACzC;SACF;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE;gBACJ,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,MAAM,CAAC,QAAQ,IAAI,eAAe;aACzC;SACF;KACF,CAAC;IAEF,IAAI,MAAM,CAAC,UAA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**
|
|
8
|
+
* POST automation result as JSON to a generic webhook URL.
|
|
9
|
+
*/
|
|
10
|
+
export declare function sendWebhookOutput(target: string, result: AutomationResult): Promise<void>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Amodal Labs, Inc.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* POST automation result as JSON to a generic webhook URL.
|
|
8
|
+
*/
|
|
9
|
+
export async function sendWebhookOutput(target, result) {
|
|
10
|
+
const response = await fetch(target, {
|
|
11
|
+
method: 'POST',
|
|
12
|
+
headers: { 'Content-Type': 'application/json' },
|
|
13
|
+
body: JSON.stringify({
|
|
14
|
+
automation: result.automation,
|
|
15
|
+
response: result.response,
|
|
16
|
+
tool_calls: result.tool_calls,
|
|
17
|
+
duration_ms: result.duration_ms,
|
|
18
|
+
timestamp: new Date().toISOString(),
|
|
19
|
+
}),
|
|
20
|
+
});
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
throw new Error(`Webhook failed: ${response.status} ${response.statusText}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=webhook-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook-output.js","sourceRoot":"","sources":["../../../src/output/webhook-output.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAAc,EACd,MAAwB;IAExB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,MAAM,EAAE;QACnC,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC,CAAC;KACH,CAAC,CAAC;IAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CACb,mBAAmB,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAC5D,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Amodal Labs, Inc.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Vercel AI SDK UI Message Stream Protocol adapter.
|
|
8
|
+
*
|
|
9
|
+
* Accepts requests in the Vercel AI SDK format, feeds the user message into
|
|
10
|
+
* the existing `streamMessage()` async generator, and translates every
|
|
11
|
+
* `SSEEvent` into the UI Message Stream Protocol that `@ai-sdk/react`'s
|
|
12
|
+
* `useChat` hook expects.
|
|
13
|
+
*
|
|
14
|
+
* Protocol spec: events are newline-delimited JSON objects prefixed with
|
|
15
|
+
* `data: `, terminated by `data: [DONE]\n\n`. The response MUST include the
|
|
16
|
+
* `x-vercel-ai-ui-message-stream: v1` header.
|
|
17
|
+
*/
|
|
18
|
+
import { Router } from 'express';
|
|
19
|
+
import { z } from 'zod';
|
|
20
|
+
import type { SessionManager } from '../session/session-manager.js';
|
|
21
|
+
import type { AuditClient } from '../audit/audit-client.js';
|
|
22
|
+
import { type SSEEvent } from '../types.js';
|
|
23
|
+
export declare const AIStreamRequestSchema: z.ZodObject<{
|
|
24
|
+
messages: z.ZodArray<z.ZodObject<{
|
|
25
|
+
role: z.ZodEnum<["user", "assistant", "system"]>;
|
|
26
|
+
parts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
27
|
+
type: z.ZodString;
|
|
28
|
+
text: z.ZodOptional<z.ZodString>;
|
|
29
|
+
}, "strip", z.ZodTypeAny, {
|
|
30
|
+
type: string;
|
|
31
|
+
text?: string | undefined;
|
|
32
|
+
}, {
|
|
33
|
+
type: string;
|
|
34
|
+
text?: string | undefined;
|
|
35
|
+
}>, "many">>;
|
|
36
|
+
content: z.ZodOptional<z.ZodString>;
|
|
37
|
+
}, "strip", z.ZodTypeAny, {
|
|
38
|
+
role: "user" | "assistant" | "system";
|
|
39
|
+
parts?: {
|
|
40
|
+
type: string;
|
|
41
|
+
text?: string | undefined;
|
|
42
|
+
}[] | undefined;
|
|
43
|
+
content?: string | undefined;
|
|
44
|
+
}, {
|
|
45
|
+
role: "user" | "assistant" | "system";
|
|
46
|
+
parts?: {
|
|
47
|
+
type: string;
|
|
48
|
+
text?: string | undefined;
|
|
49
|
+
}[] | undefined;
|
|
50
|
+
content?: string | undefined;
|
|
51
|
+
}>, "many">;
|
|
52
|
+
session_id: z.ZodOptional<z.ZodString>;
|
|
53
|
+
role: z.ZodOptional<z.ZodString>;
|
|
54
|
+
deploy_id: z.ZodOptional<z.ZodString>;
|
|
55
|
+
}, "strip", z.ZodTypeAny, {
|
|
56
|
+
messages: {
|
|
57
|
+
role: "user" | "assistant" | "system";
|
|
58
|
+
parts?: {
|
|
59
|
+
type: string;
|
|
60
|
+
text?: string | undefined;
|
|
61
|
+
}[] | undefined;
|
|
62
|
+
content?: string | undefined;
|
|
63
|
+
}[];
|
|
64
|
+
session_id?: string | undefined;
|
|
65
|
+
role?: string | undefined;
|
|
66
|
+
deploy_id?: string | undefined;
|
|
67
|
+
}, {
|
|
68
|
+
messages: {
|
|
69
|
+
role: "user" | "assistant" | "system";
|
|
70
|
+
parts?: {
|
|
71
|
+
type: string;
|
|
72
|
+
text?: string | undefined;
|
|
73
|
+
}[] | undefined;
|
|
74
|
+
content?: string | undefined;
|
|
75
|
+
}[];
|
|
76
|
+
session_id?: string | undefined;
|
|
77
|
+
role?: string | undefined;
|
|
78
|
+
deploy_id?: string | undefined;
|
|
79
|
+
}>;
|
|
80
|
+
export type AIStreamRequest = z.infer<typeof AIStreamRequestSchema>;
|
|
81
|
+
interface UIMessageStart {
|
|
82
|
+
type: 'message-start';
|
|
83
|
+
messageId: string;
|
|
84
|
+
}
|
|
85
|
+
interface UIStartStep {
|
|
86
|
+
type: 'start-step';
|
|
87
|
+
}
|
|
88
|
+
interface UIFinishStep {
|
|
89
|
+
type: 'finish-step';
|
|
90
|
+
}
|
|
91
|
+
interface UIFinish {
|
|
92
|
+
type: 'finish';
|
|
93
|
+
finishReason: 'stop' | 'error' | 'other';
|
|
94
|
+
}
|
|
95
|
+
interface UITextStart {
|
|
96
|
+
type: 'text-start';
|
|
97
|
+
id: string;
|
|
98
|
+
}
|
|
99
|
+
interface UITextDelta {
|
|
100
|
+
type: 'text-delta';
|
|
101
|
+
id: string;
|
|
102
|
+
delta: string;
|
|
103
|
+
}
|
|
104
|
+
interface UITextEnd {
|
|
105
|
+
type: 'text-end';
|
|
106
|
+
id: string;
|
|
107
|
+
}
|
|
108
|
+
interface UIToolInputStart {
|
|
109
|
+
type: 'tool-input-start';
|
|
110
|
+
toolCallId: string;
|
|
111
|
+
toolName: string;
|
|
112
|
+
}
|
|
113
|
+
interface UIToolInputAvailable {
|
|
114
|
+
type: 'tool-input-available';
|
|
115
|
+
toolCallId: string;
|
|
116
|
+
toolName: string;
|
|
117
|
+
input: Record<string, unknown>;
|
|
118
|
+
}
|
|
119
|
+
interface UIToolOutputAvailable {
|
|
120
|
+
type: 'tool-output-available';
|
|
121
|
+
toolCallId: string;
|
|
122
|
+
output: Record<string, unknown>;
|
|
123
|
+
}
|
|
124
|
+
interface UIToolOutputError {
|
|
125
|
+
type: 'tool-output-error';
|
|
126
|
+
toolCallId: string;
|
|
127
|
+
errorText: string;
|
|
128
|
+
}
|
|
129
|
+
interface UIDataPart {
|
|
130
|
+
type: string;
|
|
131
|
+
id?: string;
|
|
132
|
+
data: Record<string, unknown>;
|
|
133
|
+
}
|
|
134
|
+
interface UIError {
|
|
135
|
+
type: 'error';
|
|
136
|
+
errorText: string;
|
|
137
|
+
}
|
|
138
|
+
type UIStreamEvent = UIMessageStart | UIStartStep | UIFinishStep | UIFinish | UITextStart | UITextDelta | UITextEnd | UIToolInputStart | UIToolInputAvailable | UIToolOutputAvailable | UIToolOutputError | UIDataPart | UIError;
|
|
139
|
+
interface AdapterState {
|
|
140
|
+
messageId: string;
|
|
141
|
+
textBlockOpen: boolean;
|
|
142
|
+
textBlockId: string;
|
|
143
|
+
textBlockCounter: number;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Translate a single `SSEEvent` into one or more `UIStreamEvent`s.
|
|
147
|
+
*
|
|
148
|
+
* The `state` parameter is mutated across calls to track whether a text
|
|
149
|
+
* block is currently open.
|
|
150
|
+
*/
|
|
151
|
+
export declare function translateEvent(event: SSEEvent, state: AdapterState): UIStreamEvent[];
|
|
152
|
+
export declare function extractUserMessage(messages: AIStreamRequest['messages']): string;
|
|
153
|
+
export interface AIStreamRouterOptions {
|
|
154
|
+
sessionManager: SessionManager;
|
|
155
|
+
auditClient?: AuditClient;
|
|
156
|
+
platformApiUrl?: string;
|
|
157
|
+
}
|
|
158
|
+
export declare function createAIStreamRouter(options: AIStreamRouterOptions): Router;
|
|
159
|
+
export {};
|