@robota-sdk/agent-transport 3.0.0-beta.74 → 3.0.0-beta.76
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 +10 -10
- package/dist/node/headless/index.cjs +1 -1
- package/dist/node/headless/index.d.ts +1 -1
- package/dist/node/headless/index.js +1 -1
- package/dist/node/headless-OnpVk4-k.cjs +15 -0
- package/dist/node/{headless-D02zUEGh.js → headless-mRYilLfC.js} +2 -2
- package/dist/node/{headless-D02zUEGh.js.map → headless-mRYilLfC.js.map} +1 -1
- package/dist/node/{index-DE3-dHqw.d.ts → index-CYl7ksS6.d.ts} +12 -2
- package/dist/node/{index-DE3-dHqw.d.ts.map → index-CYl7ksS6.d.ts.map} +1 -1
- package/dist/node/{index-WKTgvhlg.d.ts → index-E8Gx4-lc.d.ts} +12 -2
- package/dist/node/{index-WKTgvhlg.d.ts.map → index-E8Gx4-lc.d.ts.map} +1 -1
- package/dist/node/index.cjs +1 -1
- package/dist/node/index.d.ts +2 -7
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +1 -1
- package/dist/node/index.js.map +1 -1
- package/package.json +7 -75
- package/src/headless/HeadlessInteractionChannel.ts +21 -1
- package/src/index.ts +1 -5
- package/src/transport-registry.ts +0 -9
- package/dist/node/headless-BeHAOlIM.cjs +0 -15
- package/dist/node/http/index.cjs +0 -1
- package/dist/node/http/index.d.ts +0 -2
- package/dist/node/http/index.js +0 -1
- package/dist/node/http-2Jiuflc1.js +0 -2
- package/dist/node/http-2Jiuflc1.js.map +0 -1
- package/dist/node/http-CBAvefLw.cjs +0 -1
- package/dist/node/index-BQLN_Lc9.d.ts +0 -78
- package/dist/node/index-BQLN_Lc9.d.ts.map +0 -1
- package/dist/node/index-BnAGE-u9.d.ts +0 -33
- package/dist/node/index-BnAGE-u9.d.ts.map +0 -1
- package/dist/node/index-BrQ4gGw0.d.ts +0 -213
- package/dist/node/index-BrQ4gGw0.d.ts.map +0 -1
- package/dist/node/index-CoeBF21y.d.ts +0 -213
- package/dist/node/index-CoeBF21y.d.ts.map +0 -1
- package/dist/node/index-DHt-2VQ-.d.ts +0 -46
- package/dist/node/index-DHt-2VQ-.d.ts.map +0 -1
- package/dist/node/index-DMwKN5Le.d.ts +0 -33
- package/dist/node/index-DMwKN5Le.d.ts.map +0 -1
- package/dist/node/index-IvYaYY6v.d.ts +0 -78
- package/dist/node/index-IvYaYY6v.d.ts.map +0 -1
- package/dist/node/index-c0M42fsA.d.ts +0 -46
- package/dist/node/index-c0M42fsA.d.ts.map +0 -1
- package/dist/node/mcp/index.cjs +0 -1
- package/dist/node/mcp/index.d.ts +0 -2
- package/dist/node/mcp/index.js +0 -1
- package/dist/node/mcp-BOglBJNy.cjs +0 -1
- package/dist/node/mcp-D3BBVK7C.js +0 -2
- package/dist/node/mcp-D3BBVK7C.js.map +0 -1
- package/dist/node/rolldown-runtime-CMqjfN_6.cjs +0 -1
- package/dist/node/tui/index.cjs +0 -1
- package/dist/node/tui/index.d.ts +0 -2
- package/dist/node/tui/index.js +0 -1
- package/dist/node/tui-Btb1q88j.js +0 -25
- package/dist/node/tui-Btb1q88j.js.map +0 -1
- package/dist/node/tui-SbUT7Zlt.cjs +0 -24
- package/dist/node/ws/index.cjs +0 -1
- package/dist/node/ws/index.d.ts +0 -2
- package/dist/node/ws/index.js +0 -1
- package/dist/node/ws-Dc2RUwVs.js +0 -2
- package/dist/node/ws-Dc2RUwVs.js.map +0 -1
- package/dist/node/ws-QNMQn5kg.cjs +0 -1
- package/src/http/__tests__/http-transport.test.ts +0 -55
- package/src/http/__tests__/routes.test.ts +0 -168
- package/src/http/http-transport.ts +0 -41
- package/src/http/index.ts +0 -4
- package/src/http/routes.ts +0 -152
- package/src/mcp/__tests__/mcp-server.test.ts +0 -66
- package/src/mcp/__tests__/mcp-transport.test.ts +0 -46
- package/src/mcp/index.ts +0 -4
- package/src/mcp/mcp-server.ts +0 -163
- package/src/mcp/mcp-transport.ts +0 -48
- package/src/tui/App.tsx +0 -488
- package/src/tui/BackgroundTaskPanel.tsx +0 -36
- package/src/tui/CjkTextInput.tsx +0 -199
- package/src/tui/ConfirmPrompt.tsx +0 -70
- package/src/tui/ContextWarningBanner.tsx +0 -34
- package/src/tui/ExecutionWorkspaceDetailPane.tsx +0 -64
- package/src/tui/ExecutionWorkspaceSwitcher.tsx +0 -187
- package/src/tui/InputArea.tsx +0 -310
- package/src/tui/InteractivePrompt.tsx +0 -59
- package/src/tui/ListPicker.tsx +0 -95
- package/src/tui/MenuSelect.tsx +0 -104
- package/src/tui/MessageList.tsx +0 -284
- package/src/tui/PermissionPrompt.tsx +0 -86
- package/src/tui/PluginTUI.tsx +0 -258
- package/src/tui/SessionPicker.tsx +0 -68
- package/src/tui/SessionStatusBar.tsx +0 -70
- package/src/tui/SlashAutocomplete.tsx +0 -110
- package/src/tui/StatusBar.tsx +0 -209
- package/src/tui/StreamingIndicator.tsx +0 -93
- package/src/tui/TextPrompt.tsx +0 -81
- package/src/tui/ToolCommandOutput.tsx +0 -39
- package/src/tui/ToolDiffBlock.tsx +0 -32
- package/src/tui/TransportTUI.tsx +0 -117
- package/src/tui/TuiInteractionChannel.ts +0 -483
- package/src/tui/UpdateNotice.tsx +0 -14
- package/src/tui/UsageSummaryEntry.tsx +0 -39
- package/src/tui/WaveText.tsx +0 -44
- package/src/tui/__tests__/InteractivePrompt.test.tsx +0 -82
- package/src/tui/__tests__/ListPicker.test.tsx +0 -159
- package/src/tui/__tests__/MenuSelect.test.tsx +0 -103
- package/src/tui/__tests__/PluginTUI.test.tsx +0 -167
- package/src/tui/__tests__/SlashAutocomplete.test.tsx +0 -140
- package/src/tui/__tests__/TextPrompt.test.tsx +0 -98
- package/src/tui/__tests__/TuiInteractionChannel.display-contract.test.ts +0 -239
- package/src/tui/__tests__/TuiInteractionChannel.lifecycle.test.ts +0 -297
- package/src/tui/__tests__/TuiInteractionChannel.requestAction.test.ts +0 -124
- package/src/tui/__tests__/UpdateNotice.test.tsx +0 -15
- package/src/tui/__tests__/abort-after-permission.test.tsx +0 -169
- package/src/tui/__tests__/abort-streaming-e2e.test.tsx +0 -183
- package/src/tui/__tests__/background-task-panel.test.tsx +0 -53
- package/src/tui/__tests__/background-task-row-format.test.ts +0 -59
- package/src/tui/__tests__/channel-factory-integration.test.ts +0 -138
- package/src/tui/__tests__/cjk-text-input-flow.test.ts +0 -109
- package/src/tui/__tests__/cjk-text-input.test.ts +0 -191
- package/src/tui/__tests__/command-effect-handler.test.ts +0 -127
- package/src/tui/__tests__/command-output-summary.test.ts +0 -95
- package/src/tui/__tests__/compact-event-bridge.test.ts +0 -20
- package/src/tui/__tests__/confirm-permission-flow.test.ts +0 -130
- package/src/tui/__tests__/confirm-prompt.test.tsx +0 -87
- package/src/tui/__tests__/execution-workspace-switcher.test.tsx +0 -110
- package/src/tui/__tests__/execution-workspace-view-model.test.ts +0 -93
- package/src/tui/__tests__/fixtures/provider-setup-prompt-driver.tsx +0 -125
- package/src/tui/__tests__/input-area-flow.test.ts +0 -164
- package/src/tui/__tests__/message-list-rendering.test.tsx +0 -353
- package/src/tui/__tests__/prompt-queue.test.tsx +0 -255
- package/src/tui/__tests__/provider-setup-pty-e2e.test.ts +0 -233
- package/src/tui/__tests__/pty/pty-driver.ts +0 -135
- package/src/tui/__tests__/pty/tui-pty.ptytest.ts +0 -61
- package/src/tui/__tests__/render-channel-options.test.ts +0 -32
- package/src/tui/__tests__/render-markdown.test.ts +0 -72
- package/src/tui/__tests__/selection-flow.test.ts +0 -61
- package/src/tui/__tests__/session-init-poller.test.ts +0 -102
- package/src/tui/__tests__/session-naming.test.ts +0 -64
- package/src/tui/__tests__/session-switch-channel.test.tsx +0 -307
- package/src/tui/__tests__/slash-routing-effects.test.ts +0 -228
- package/src/tui/__tests__/status-activity.test.ts +0 -71
- package/src/tui/__tests__/status-bar.test.tsx +0 -158
- package/src/tui/__tests__/streaming-indicator.test.tsx +0 -137
- package/src/tui/__tests__/text-prompt-flow.test.ts +0 -77
- package/src/tui/__tests__/tui-channel-init-failure.test.ts +0 -57
- package/src/tui/__tests__/tui-state-manager.test.ts +0 -401
- package/src/tui/background-task-row-format.ts +0 -53
- package/src/tui/command-interaction.ts +0 -9
- package/src/tui/command-output-summary.ts +0 -122
- package/src/tui/create-default-tui-cli-adapter.ts +0 -41
- package/src/tui/execution-workspace-view-model.ts +0 -123
- package/src/tui/flows/cjk-text-input-flow.ts +0 -285
- package/src/tui/flows/confirm-prompt-flow.ts +0 -45
- package/src/tui/flows/input-area-flow.ts +0 -189
- package/src/tui/flows/permission-prompt-flow.ts +0 -85
- package/src/tui/flows/selection-flow.ts +0 -126
- package/src/tui/flows/session-init-poller.ts +0 -77
- package/src/tui/flows/text-prompt-flow.ts +0 -98
- package/src/tui/hooks/command-effect-handler.ts +0 -97
- package/src/tui/hooks/command-effect-queue.ts +0 -39
- package/src/tui/hooks/side-effects-types.ts +0 -35
- package/src/tui/hooks/useAutocomplete.ts +0 -87
- package/src/tui/hooks/usePluginCallbacks.ts +0 -31
- package/src/tui/hooks/usePluginScreenData.ts +0 -85
- package/src/tui/hooks/useSideEffects.ts +0 -175
- package/src/tui/hooks/useSlashRouting.ts +0 -118
- package/src/tui/hooks/useStatusLineSettings.ts +0 -37
- package/src/tui/hooks/useTuiChannel.ts +0 -95
- package/src/tui/index.ts +0 -14
- package/src/tui/interactions/CommandConfirm.tsx +0 -36
- package/src/tui/interactions/CommandPicker.tsx +0 -77
- package/src/tui/interactions/__tests__/CommandConfirm.test.tsx +0 -124
- package/src/tui/interactions/__tests__/CommandPicker.test.tsx +0 -138
- package/src/tui/plugin-tui-handlers.ts +0 -163
- package/src/tui/render-markdown.ts +0 -130
- package/src/tui/render.tsx +0 -117
- package/src/tui/session-naming.ts +0 -33
- package/src/tui/status-activity.ts +0 -63
- package/src/tui/tui-cli-adapter-context.tsx +0 -13
- package/src/tui/tui-cli-adapter.ts +0 -25
- package/src/tui/tui-state-manager.ts +0 -226
- package/src/tui/tui-transport.ts +0 -35
- package/src/tui/types.ts +0 -15
- package/src/tui/utils/__tests__/edit-diff.test.ts +0 -426
- package/src/tui/utils/__tests__/paste-detection.test.ts +0 -116
- package/src/tui/utils/__tests__/paste-labels.test.ts +0 -46
- package/src/tui/utils/__tests__/tool-call-extractor.test.ts +0 -227
- package/src/tui/utils/__tests__/tool-diff-summary.test.ts +0 -104
- package/src/tui/utils/edit-diff.ts +0 -153
- package/src/tui/utils/paste-labels.ts +0 -9
- package/src/tui/utils/tool-call-extractor.ts +0 -92
- package/src/tui/utils/tool-diff-summary.ts +0 -75
- package/src/ws/__tests__/ws-handler.test.ts +0 -409
- package/src/ws/__tests__/ws-transport.test.ts +0 -53
- package/src/ws/index.ts +0 -13
- package/src/ws/ws-background-messages.ts +0 -170
- package/src/ws/ws-handler.ts +0 -280
- package/src/ws/ws-protocol.ts +0 -78
- package/src/ws/ws-transport-configurable.ts +0 -128
- package/src/ws/ws-transport.ts +0 -42
|
@@ -1,409 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for WebSocket transport handler.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
6
|
-
import { createWsHandler } from '../ws-handler.js';
|
|
7
|
-
import type { TServerMessage } from '../ws-protocol.js';
|
|
8
|
-
import type {
|
|
9
|
-
IBackgroundJobGroupState,
|
|
10
|
-
IExecutionWorkspaceEvent,
|
|
11
|
-
IExecutionWorkspaceSnapshot,
|
|
12
|
-
IInteractiveSession,
|
|
13
|
-
TBackgroundJobGroupEvent,
|
|
14
|
-
TExecutionWorkspaceUpdateCause,
|
|
15
|
-
} from '@robota-sdk/agent-interface-transport';
|
|
16
|
-
import type {
|
|
17
|
-
IBackgroundTaskLogPage,
|
|
18
|
-
IBackgroundTaskState,
|
|
19
|
-
TBackgroundTaskEvent,
|
|
20
|
-
} from '@robota-sdk/agent-framework';
|
|
21
|
-
|
|
22
|
-
const backgroundTask: IBackgroundTaskState = {
|
|
23
|
-
id: 'task_1',
|
|
24
|
-
kind: 'agent',
|
|
25
|
-
label: 'Explore',
|
|
26
|
-
agentType: 'Explore',
|
|
27
|
-
status: 'running',
|
|
28
|
-
mode: 'background',
|
|
29
|
-
parentSessionId: 'session_1',
|
|
30
|
-
depth: 0,
|
|
31
|
-
cwd: '/repo',
|
|
32
|
-
updatedAt: '2026-05-01T00:00:00.000Z',
|
|
33
|
-
unread: false,
|
|
34
|
-
promptPreview: 'inspect code',
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const backgroundTaskLogPage: IBackgroundTaskLogPage = {
|
|
38
|
-
taskId: 'task_1',
|
|
39
|
-
cursor: { offset: 0 },
|
|
40
|
-
lines: ['line one'],
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const executionWorkspaceSnapshot: IExecutionWorkspaceSnapshot = {
|
|
44
|
-
sessionId: 'session_1',
|
|
45
|
-
entries: [],
|
|
46
|
-
updatedAt: '2026-05-01T00:00:00.000Z',
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const backgroundJobGroup: IBackgroundJobGroupState = {
|
|
50
|
-
id: 'group_1',
|
|
51
|
-
parentSessionId: 'session_1',
|
|
52
|
-
waitPolicy: 'wait_all',
|
|
53
|
-
taskIds: ['task_1'],
|
|
54
|
-
status: 'running',
|
|
55
|
-
createdAt: '2026-05-01T00:00:00.000Z',
|
|
56
|
-
updatedAt: '2026-05-01T00:00:00.000Z',
|
|
57
|
-
results: [],
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
function createMockSession() {
|
|
61
|
-
const listeners = new Map<string, Set<(...args: unknown[]) => void>>();
|
|
62
|
-
return {
|
|
63
|
-
submit: vi.fn(),
|
|
64
|
-
abort: vi.fn(),
|
|
65
|
-
cancelQueue: vi.fn(),
|
|
66
|
-
getMessages: vi.fn().mockReturnValue([{ role: 'user', content: 'hi' }]),
|
|
67
|
-
getContextState: vi
|
|
68
|
-
.fn()
|
|
69
|
-
.mockReturnValue({ usedTokens: 500, maxTokens: 100000, usedPercentage: 0.5 }),
|
|
70
|
-
isExecuting: vi.fn().mockReturnValue(false),
|
|
71
|
-
getPendingPrompt: vi.fn().mockReturnValue(null),
|
|
72
|
-
listBackgroundTasks: vi.fn().mockReturnValue([backgroundTask]),
|
|
73
|
-
getBackgroundTask: vi.fn().mockReturnValue(backgroundTask),
|
|
74
|
-
listBackgroundJobGroups: vi.fn().mockReturnValue([backgroundJobGroup]),
|
|
75
|
-
getBackgroundJobGroup: vi.fn().mockReturnValue(backgroundJobGroup),
|
|
76
|
-
waitBackgroundJobGroup: vi.fn().mockResolvedValue({
|
|
77
|
-
...backgroundJobGroup,
|
|
78
|
-
status: 'completed',
|
|
79
|
-
completedAt: '2026-05-01T00:00:01.000Z',
|
|
80
|
-
results: [{ taskId: 'task_1', label: 'Explore', status: 'completed', summary: 'done' }],
|
|
81
|
-
}),
|
|
82
|
-
cancelBackgroundTask: vi.fn().mockResolvedValue(undefined),
|
|
83
|
-
closeBackgroundTask: vi.fn().mockResolvedValue(undefined),
|
|
84
|
-
sendBackgroundTask: vi.fn().mockResolvedValue(undefined),
|
|
85
|
-
readBackgroundTaskLog: vi.fn().mockResolvedValue(backgroundTaskLogPage),
|
|
86
|
-
getExecutionWorkspaceSnapshot: vi.fn().mockReturnValue(executionWorkspaceSnapshot),
|
|
87
|
-
executeCommand: vi.fn().mockResolvedValue({ message: 'done', success: true, data: {} }),
|
|
88
|
-
listCommands: vi.fn().mockReturnValue([]),
|
|
89
|
-
on: vi.fn((event: string, handler: (...args: unknown[]) => void) => {
|
|
90
|
-
if (!listeners.has(event)) listeners.set(event, new Set());
|
|
91
|
-
listeners.get(event)!.add(handler);
|
|
92
|
-
}),
|
|
93
|
-
off: vi.fn((event: string, handler: (...args: unknown[]) => void) => {
|
|
94
|
-
listeners.get(event)?.delete(handler);
|
|
95
|
-
}),
|
|
96
|
-
_emit: (event: string, ...args: unknown[]) => {
|
|
97
|
-
listeners.get(event)?.forEach((h) => h(...args));
|
|
98
|
-
},
|
|
99
|
-
} as unknown as IInteractiveSession & { _emit: (event: string, ...args: unknown[]) => void };
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
describe('WebSocket Transport Handler', () => {
|
|
103
|
-
function setup() {
|
|
104
|
-
const session = createMockSession();
|
|
105
|
-
const sent: TServerMessage[] = [];
|
|
106
|
-
const { onMessage, cleanup } = createWsHandler({
|
|
107
|
-
session: session as unknown as IInteractiveSession,
|
|
108
|
-
send: (msg) => sent.push(msg),
|
|
109
|
-
});
|
|
110
|
-
return { session, sent, onMessage, cleanup };
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
it('submit calls session.submit()', () => {
|
|
114
|
-
const { onMessage, session } = setup();
|
|
115
|
-
onMessage(JSON.stringify({ type: 'submit', prompt: 'hello' }));
|
|
116
|
-
expect(
|
|
117
|
-
(session as unknown as { submit: ReturnType<typeof vi.fn> }).submit,
|
|
118
|
-
).toHaveBeenCalledWith('hello');
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('abort calls session.abort()', () => {
|
|
122
|
-
const { onMessage, session } = setup();
|
|
123
|
-
onMessage(JSON.stringify({ type: 'abort' }));
|
|
124
|
-
expect((session as unknown as { abort: ReturnType<typeof vi.fn> }).abort).toHaveBeenCalled();
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('cancel-queue calls session.cancelQueue()', () => {
|
|
128
|
-
const { onMessage, session } = setup();
|
|
129
|
-
onMessage(JSON.stringify({ type: 'cancel-queue' }));
|
|
130
|
-
expect(
|
|
131
|
-
(session as unknown as { cancelQueue: ReturnType<typeof vi.fn> }).cancelQueue,
|
|
132
|
-
).toHaveBeenCalled();
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('get-messages sends messages back', () => {
|
|
136
|
-
const { onMessage, sent } = setup();
|
|
137
|
-
onMessage(JSON.stringify({ type: 'get-messages' }));
|
|
138
|
-
expect(sent).toHaveLength(1);
|
|
139
|
-
expect(sent[0]!.type).toBe('messages');
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('get-context sends context state back', () => {
|
|
143
|
-
const { onMessage, sent } = setup();
|
|
144
|
-
onMessage(JSON.stringify({ type: 'get-context' }));
|
|
145
|
-
expect(sent).toHaveLength(1);
|
|
146
|
-
expect(sent[0]!.type).toBe('context');
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('get-executing sends executing status', () => {
|
|
150
|
-
const { onMessage, sent } = setup();
|
|
151
|
-
onMessage(JSON.stringify({ type: 'get-executing' }));
|
|
152
|
-
expect(sent[0]).toEqual({ type: 'executing', executing: false });
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('get-pending sends pending prompt', () => {
|
|
156
|
-
const { onMessage, sent } = setup();
|
|
157
|
-
onMessage(JSON.stringify({ type: 'get-pending' }));
|
|
158
|
-
expect(sent[0]).toEqual({ type: 'pending', pending: null });
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('get-background-tasks sends current background task list', () => {
|
|
162
|
-
const { onMessage, sent, session } = setup();
|
|
163
|
-
onMessage(JSON.stringify({ type: 'get-background-tasks', filter: { kind: 'agent' } }));
|
|
164
|
-
|
|
165
|
-
expect(sent[0]).toEqual({ type: 'background_tasks', tasks: [backgroundTask] });
|
|
166
|
-
expect(
|
|
167
|
-
(session as unknown as { listBackgroundTasks: ReturnType<typeof vi.fn> }).listBackgroundTasks,
|
|
168
|
-
).toHaveBeenCalledWith({ kind: 'agent' });
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it('get-background-task sends one background task snapshot', () => {
|
|
172
|
-
const { onMessage, sent, session } = setup();
|
|
173
|
-
onMessage(JSON.stringify({ type: 'get-background-task', taskId: 'task_1' }));
|
|
174
|
-
|
|
175
|
-
expect(sent[0]).toEqual({
|
|
176
|
-
type: 'background_task',
|
|
177
|
-
taskId: 'task_1',
|
|
178
|
-
task: backgroundTask,
|
|
179
|
-
});
|
|
180
|
-
expect(
|
|
181
|
-
(session as unknown as { getBackgroundTask: ReturnType<typeof vi.fn> }).getBackgroundTask,
|
|
182
|
-
).toHaveBeenCalledWith('task_1');
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it('get-background-job-groups sends group snapshots', () => {
|
|
186
|
-
const { onMessage, sent, session } = setup();
|
|
187
|
-
onMessage(JSON.stringify({ type: 'get-background-job-groups' }));
|
|
188
|
-
|
|
189
|
-
expect(sent[0]).toEqual({ type: 'background_job_groups', groups: [backgroundJobGroup] });
|
|
190
|
-
expect(
|
|
191
|
-
(session as unknown as { listBackgroundJobGroups: ReturnType<typeof vi.fn> })
|
|
192
|
-
.listBackgroundJobGroups,
|
|
193
|
-
).toHaveBeenCalled();
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it('get-background-job-group sends one group snapshot', () => {
|
|
197
|
-
const { onMessage, sent, session } = setup();
|
|
198
|
-
onMessage(JSON.stringify({ type: 'get-background-job-group', groupId: 'group_1' }));
|
|
199
|
-
|
|
200
|
-
expect(sent[0]).toEqual({
|
|
201
|
-
type: 'background_job_group',
|
|
202
|
-
groupId: 'group_1',
|
|
203
|
-
group: backgroundJobGroup,
|
|
204
|
-
});
|
|
205
|
-
expect(
|
|
206
|
-
(session as unknown as { getBackgroundJobGroup: ReturnType<typeof vi.fn> })
|
|
207
|
-
.getBackgroundJobGroup,
|
|
208
|
-
).toHaveBeenCalledWith('group_1');
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it('wait-background-job-group waits and sends the completed group', async () => {
|
|
212
|
-
const { onMessage, sent, session } = setup();
|
|
213
|
-
onMessage(JSON.stringify({ type: 'wait-background-job-group', groupId: 'group_1' }));
|
|
214
|
-
|
|
215
|
-
await new Promise((r) => setTimeout(r, 10));
|
|
216
|
-
|
|
217
|
-
expect(
|
|
218
|
-
(session as unknown as { waitBackgroundJobGroup: ReturnType<typeof vi.fn> })
|
|
219
|
-
.waitBackgroundJobGroup,
|
|
220
|
-
).toHaveBeenCalledWith('group_1');
|
|
221
|
-
expect(sent[0]).toMatchObject({
|
|
222
|
-
type: 'background_job_group',
|
|
223
|
-
groupId: 'group_1',
|
|
224
|
-
group: { id: 'group_1', status: 'completed' },
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
it('cancel-background-task maps to session control and emits control result', async () => {
|
|
229
|
-
const { onMessage, sent, session } = setup();
|
|
230
|
-
onMessage(JSON.stringify({ type: 'cancel-background-task', taskId: 'task_1', reason: 'stop' }));
|
|
231
|
-
|
|
232
|
-
await new Promise((r) => setTimeout(r, 10));
|
|
233
|
-
|
|
234
|
-
expect(
|
|
235
|
-
(session as unknown as { cancelBackgroundTask: ReturnType<typeof vi.fn> })
|
|
236
|
-
.cancelBackgroundTask,
|
|
237
|
-
).toHaveBeenCalledWith('task_1', 'stop');
|
|
238
|
-
expect(sent[0]).toEqual({
|
|
239
|
-
type: 'background_task_control_result',
|
|
240
|
-
action: 'cancel',
|
|
241
|
-
taskId: 'task_1',
|
|
242
|
-
success: true,
|
|
243
|
-
});
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
it('send-background-task maps prompt input to session control', async () => {
|
|
247
|
-
const { onMessage, sent, session } = setup();
|
|
248
|
-
onMessage(
|
|
249
|
-
JSON.stringify({
|
|
250
|
-
type: 'send-background-task',
|
|
251
|
-
taskId: 'task_1',
|
|
252
|
-
input: { prompt: 'continue' },
|
|
253
|
-
}),
|
|
254
|
-
);
|
|
255
|
-
|
|
256
|
-
await new Promise((r) => setTimeout(r, 10));
|
|
257
|
-
|
|
258
|
-
expect(
|
|
259
|
-
(session as unknown as { sendBackgroundTask: ReturnType<typeof vi.fn> }).sendBackgroundTask,
|
|
260
|
-
).toHaveBeenCalledWith('task_1', { prompt: 'continue' });
|
|
261
|
-
expect(sent[0]).toEqual({
|
|
262
|
-
type: 'background_task_control_result',
|
|
263
|
-
action: 'send',
|
|
264
|
-
taskId: 'task_1',
|
|
265
|
-
success: true,
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
it('read-background-task-log sends log page', async () => {
|
|
270
|
-
const { onMessage, sent, session } = setup();
|
|
271
|
-
onMessage(
|
|
272
|
-
JSON.stringify({
|
|
273
|
-
type: 'read-background-task-log',
|
|
274
|
-
taskId: 'task_1',
|
|
275
|
-
cursor: { offset: 0 },
|
|
276
|
-
}),
|
|
277
|
-
);
|
|
278
|
-
|
|
279
|
-
await new Promise((r) => setTimeout(r, 10));
|
|
280
|
-
|
|
281
|
-
expect(
|
|
282
|
-
(session as unknown as { readBackgroundTaskLog: ReturnType<typeof vi.fn> })
|
|
283
|
-
.readBackgroundTaskLog,
|
|
284
|
-
).toHaveBeenCalledWith('task_1', { offset: 0 });
|
|
285
|
-
expect(sent[0]).toEqual({
|
|
286
|
-
type: 'background_task_log',
|
|
287
|
-
taskId: 'task_1',
|
|
288
|
-
page: backgroundTaskLogPage,
|
|
289
|
-
});
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
it('command executes via session.executeCommand()', async () => {
|
|
293
|
-
const { onMessage, sent, session } = setup();
|
|
294
|
-
onMessage(JSON.stringify({ type: 'command', name: 'clear' }));
|
|
295
|
-
await new Promise((r) => setTimeout(r, 10));
|
|
296
|
-
expect(sent).toHaveLength(1);
|
|
297
|
-
expect(sent[0]!.type).toBe('command_result');
|
|
298
|
-
expect(
|
|
299
|
-
(session as unknown as { executeCommand: ReturnType<typeof vi.fn> }).executeCommand,
|
|
300
|
-
).toHaveBeenCalledWith('clear', '');
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
it('invalid JSON sends protocol_error', () => {
|
|
304
|
-
const { onMessage, sent } = setup();
|
|
305
|
-
onMessage('not json');
|
|
306
|
-
expect(sent[0]).toEqual({ type: 'protocol_error', message: 'Invalid JSON' });
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
it('unknown type sends protocol_error', () => {
|
|
310
|
-
const { onMessage, sent } = setup();
|
|
311
|
-
onMessage(JSON.stringify({ type: 'unknown_type' }));
|
|
312
|
-
expect(sent[0]!.type).toBe('protocol_error');
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it('submit without prompt sends protocol_error', () => {
|
|
316
|
-
const { onMessage, sent } = setup();
|
|
317
|
-
onMessage(JSON.stringify({ type: 'submit' }));
|
|
318
|
-
expect(sent[0]).toEqual({ type: 'protocol_error', message: 'prompt is required' });
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
it('forwards InteractiveSession events to client', () => {
|
|
322
|
-
const { session, sent } = setup();
|
|
323
|
-
(session as unknown as { _emit: (e: string, ...args: unknown[]) => void })._emit(
|
|
324
|
-
'text_delta',
|
|
325
|
-
'hello',
|
|
326
|
-
);
|
|
327
|
-
expect(sent).toHaveLength(1);
|
|
328
|
-
expect(sent[0]).toEqual({ type: 'text_delta', delta: 'hello' });
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
it('forwards thinking event', () => {
|
|
332
|
-
const { session, sent } = setup();
|
|
333
|
-
(session as unknown as { _emit: (e: string, ...args: unknown[]) => void })._emit(
|
|
334
|
-
'thinking',
|
|
335
|
-
true,
|
|
336
|
-
);
|
|
337
|
-
expect(sent[0]).toEqual({ type: 'thinking', isThinking: true });
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
it('forwards background task events to the client', () => {
|
|
341
|
-
const { session, sent } = setup();
|
|
342
|
-
const event: TBackgroundTaskEvent = {
|
|
343
|
-
type: 'background_task_text_delta',
|
|
344
|
-
taskId: 'task_1',
|
|
345
|
-
delta: 'partial',
|
|
346
|
-
};
|
|
347
|
-
(session as unknown as { _emit: (e: string, ...args: unknown[]) => void })._emit(
|
|
348
|
-
'background_task_event',
|
|
349
|
-
event,
|
|
350
|
-
);
|
|
351
|
-
|
|
352
|
-
expect(sent[0]).toEqual({ type: 'background_task_event', event });
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
it('forwards background job group events to the client', () => {
|
|
356
|
-
const { session, sent } = setup();
|
|
357
|
-
const event: TBackgroundJobGroupEvent = {
|
|
358
|
-
type: 'background_job_group_completed',
|
|
359
|
-
group: { ...backgroundJobGroup, status: 'completed' },
|
|
360
|
-
};
|
|
361
|
-
(session as unknown as { _emit: (e: string, ...args: unknown[]) => void })._emit(
|
|
362
|
-
'background_job_group_event',
|
|
363
|
-
event,
|
|
364
|
-
);
|
|
365
|
-
|
|
366
|
-
expect(sent[0]).toEqual({ type: 'background_job_group_event', event });
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
it('forwards execution_workspace_event to the client', () => {
|
|
370
|
-
const { session, sent } = setup();
|
|
371
|
-
const event: IExecutionWorkspaceEvent = {
|
|
372
|
-
type: 'execution_workspace_updated',
|
|
373
|
-
cause: 'main_thread',
|
|
374
|
-
snapshot: executionWorkspaceSnapshot,
|
|
375
|
-
};
|
|
376
|
-
(session as unknown as { _emit: (e: string, ...args: unknown[]) => void })._emit(
|
|
377
|
-
'execution_workspace_event',
|
|
378
|
-
event,
|
|
379
|
-
);
|
|
380
|
-
|
|
381
|
-
expect(sent[0]).toEqual({
|
|
382
|
-
type: 'execution_workspace_event',
|
|
383
|
-
snapshot: executionWorkspaceSnapshot,
|
|
384
|
-
});
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
it('get-execution-workspace sends current snapshot', () => {
|
|
388
|
-
const { onMessage, sent, session } = setup();
|
|
389
|
-
onMessage(JSON.stringify({ type: 'get-execution-workspace' }));
|
|
390
|
-
|
|
391
|
-
expect(sent[0]).toEqual({
|
|
392
|
-
type: 'execution_workspace_event',
|
|
393
|
-
snapshot: executionWorkspaceSnapshot,
|
|
394
|
-
});
|
|
395
|
-
expect(
|
|
396
|
-
(
|
|
397
|
-
session as unknown as {
|
|
398
|
-
getExecutionWorkspaceSnapshot: ReturnType<typeof vi.fn>;
|
|
399
|
-
}
|
|
400
|
-
).getExecutionWorkspaceSnapshot,
|
|
401
|
-
).toHaveBeenCalled();
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
it('cleanup unsubscribes from all events', () => {
|
|
405
|
-
const { session, cleanup } = setup();
|
|
406
|
-
cleanup();
|
|
407
|
-
expect((session as unknown as { off: ReturnType<typeof vi.fn> }).off).toHaveBeenCalledTimes(11);
|
|
408
|
-
});
|
|
409
|
-
});
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
-
import { createWsTransport } from '../ws-transport.js';
|
|
3
|
-
import type { IInteractiveSession } from '@robota-sdk/agent-interface-transport';
|
|
4
|
-
|
|
5
|
-
function createMockSession(): IInteractiveSession {
|
|
6
|
-
return {
|
|
7
|
-
submit: vi.fn(),
|
|
8
|
-
abort: vi.fn(),
|
|
9
|
-
cancelQueue: vi.fn(),
|
|
10
|
-
getMessages: vi.fn().mockReturnValue([]),
|
|
11
|
-
getContextState: vi
|
|
12
|
-
.fn()
|
|
13
|
-
.mockReturnValue({ usedPercentage: 0, usedTokens: 0, maxTokens: 200000 }),
|
|
14
|
-
isExecuting: vi.fn().mockReturnValue(false),
|
|
15
|
-
getPendingPrompt: vi.fn().mockReturnValue(null),
|
|
16
|
-
executeCommand: vi.fn().mockResolvedValue({ message: 'ok', success: true }),
|
|
17
|
-
listCommands: vi.fn().mockReturnValue([]),
|
|
18
|
-
on: vi.fn(),
|
|
19
|
-
off: vi.fn(),
|
|
20
|
-
} as unknown as IInteractiveSession;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
describe('createWsTransport', () => {
|
|
24
|
-
it('returns an adapter with name "ws"', () => {
|
|
25
|
-
const transport = createWsTransport({ send: vi.fn() });
|
|
26
|
-
expect(transport.name).toBe('ws');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('throws if start() is called without attach()', async () => {
|
|
30
|
-
const transport = createWsTransport({ send: vi.fn() });
|
|
31
|
-
await expect(transport.start()).rejects.toThrow('No session attached');
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('onMessage is null before start()', () => {
|
|
35
|
-
const transport = createWsTransport({ send: vi.fn() });
|
|
36
|
-
expect(transport.onMessage).toBeNull();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('provides onMessage after attach + start', async () => {
|
|
40
|
-
const transport = createWsTransport({ send: vi.fn() });
|
|
41
|
-
transport.attach(createMockSession() as never);
|
|
42
|
-
await transport.start();
|
|
43
|
-
expect(typeof transport.onMessage).toBe('function');
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('clears onMessage after stop()', async () => {
|
|
47
|
-
const transport = createWsTransport({ send: vi.fn() });
|
|
48
|
-
transport.attach(createMockSession() as never);
|
|
49
|
-
await transport.start();
|
|
50
|
-
await transport.stop();
|
|
51
|
-
expect(transport.onMessage).toBeNull();
|
|
52
|
-
});
|
|
53
|
-
});
|
package/src/ws/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export { createWsHandler } from './ws-handler.js';
|
|
2
|
-
export type { IWsHandlerOptions } from './ws-handler.js';
|
|
3
|
-
export type { TClientMessage, TServerMessage } from './ws-protocol.js';
|
|
4
|
-
export { createWsTransport } from './ws-transport.js';
|
|
5
|
-
export type { IWsTransportOptions } from './ws-transport.js';
|
|
6
|
-
export { WsTransport } from './ws-transport-configurable.js';
|
|
7
|
-
export type { IWsTransportConfig } from './ws-transport-configurable.js';
|
|
8
|
-
export type {
|
|
9
|
-
IExecutionWorkspaceSnapshot,
|
|
10
|
-
IExecutionWorkspaceEntry,
|
|
11
|
-
TExecutionWorkspaceStatus,
|
|
12
|
-
TExecutionAttention,
|
|
13
|
-
} from '@robota-sdk/agent-framework';
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import type { TBackgroundControlAction, TClientMessage, TServerMessage } from './ws-protocol.js';
|
|
2
|
-
import type { IInteractiveSession } from '@robota-sdk/agent-interface-transport';
|
|
3
|
-
|
|
4
|
-
export function handleBackgroundQueryMessage(
|
|
5
|
-
session: IInteractiveSession,
|
|
6
|
-
send: (message: TServerMessage) => void,
|
|
7
|
-
msg: Extract<
|
|
8
|
-
TClientMessage,
|
|
9
|
-
| { type: 'get-background-tasks' | 'get-background-task' | 'read-background-task-log' }
|
|
10
|
-
| {
|
|
11
|
-
type:
|
|
12
|
-
| 'get-background-job-groups'
|
|
13
|
-
| 'get-background-job-group'
|
|
14
|
-
| 'wait-background-job-group';
|
|
15
|
-
}
|
|
16
|
-
>,
|
|
17
|
-
): void {
|
|
18
|
-
if (msg.type === 'get-background-tasks') {
|
|
19
|
-
send({ type: 'background_tasks', tasks: session.listBackgroundTasks(msg.filter) });
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (msg.type === 'get-background-task') {
|
|
23
|
-
sendBackgroundTaskSnapshot(session, send, msg);
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
if (msg.type === 'get-background-job-groups') {
|
|
27
|
-
send({ type: 'background_job_groups', groups: session.listBackgroundJobGroups() });
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (msg.type === 'get-background-job-group') {
|
|
31
|
-
sendBackgroundJobGroupSnapshot(session, send, msg);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if (msg.type === 'wait-background-job-group') {
|
|
35
|
-
sendBackgroundJobGroupWaitResult(session, send, msg);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
sendBackgroundTaskLogPage(session, send, msg);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function handleBackgroundControlMessage(
|
|
42
|
-
session: IInteractiveSession,
|
|
43
|
-
send: (message: TServerMessage) => void,
|
|
44
|
-
msg: Extract<
|
|
45
|
-
TClientMessage,
|
|
46
|
-
{ type: 'cancel-background-task' | 'close-background-task' | 'send-background-task' }
|
|
47
|
-
>,
|
|
48
|
-
): void {
|
|
49
|
-
if (!msg.taskId) {
|
|
50
|
-
send({ type: 'protocol_error', message: 'taskId is required' });
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (msg.type === 'cancel-background-task') {
|
|
54
|
-
sendBackgroundTaskControlResult(
|
|
55
|
-
send,
|
|
56
|
-
'cancel',
|
|
57
|
-
msg.taskId,
|
|
58
|
-
session.cancelBackgroundTask(msg.taskId, msg.reason),
|
|
59
|
-
);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
if (msg.type === 'close-background-task') {
|
|
63
|
-
sendBackgroundTaskControlResult(
|
|
64
|
-
send,
|
|
65
|
-
'close',
|
|
66
|
-
msg.taskId,
|
|
67
|
-
session.closeBackgroundTask(msg.taskId),
|
|
68
|
-
);
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
sendBackgroundTaskInput(session, send, msg);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function sendBackgroundTaskSnapshot(
|
|
75
|
-
session: IInteractiveSession,
|
|
76
|
-
send: (message: TServerMessage) => void,
|
|
77
|
-
msg: Extract<TClientMessage, { type: 'get-background-task' }>,
|
|
78
|
-
): void {
|
|
79
|
-
if (!msg.taskId) {
|
|
80
|
-
send({ type: 'protocol_error', message: 'taskId is required' });
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
send({
|
|
84
|
-
type: 'background_task',
|
|
85
|
-
taskId: msg.taskId,
|
|
86
|
-
task: session.getBackgroundTask(msg.taskId) ?? null,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function sendBackgroundTaskLogPage(
|
|
91
|
-
session: IInteractiveSession,
|
|
92
|
-
send: (message: TServerMessage) => void,
|
|
93
|
-
msg: Extract<TClientMessage, { type: 'read-background-task-log' }>,
|
|
94
|
-
): void {
|
|
95
|
-
if (!msg.taskId) {
|
|
96
|
-
send({ type: 'protocol_error', message: 'taskId is required' });
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
session.readBackgroundTaskLog(msg.taskId, msg.cursor).then(
|
|
100
|
-
(page) => send({ type: 'background_task_log', taskId: msg.taskId, page }),
|
|
101
|
-
(error: Error) => send({ type: 'protocol_error', message: error.message }),
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function sendBackgroundJobGroupSnapshot(
|
|
106
|
-
session: IInteractiveSession,
|
|
107
|
-
send: (message: TServerMessage) => void,
|
|
108
|
-
msg: Extract<TClientMessage, { type: 'get-background-job-group' }>,
|
|
109
|
-
): void {
|
|
110
|
-
if (!msg.groupId) {
|
|
111
|
-
send({ type: 'protocol_error', message: 'groupId is required' });
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
send({
|
|
115
|
-
type: 'background_job_group',
|
|
116
|
-
groupId: msg.groupId,
|
|
117
|
-
group: session.getBackgroundJobGroup(msg.groupId) ?? null,
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function sendBackgroundJobGroupWaitResult(
|
|
122
|
-
session: IInteractiveSession,
|
|
123
|
-
send: (message: TServerMessage) => void,
|
|
124
|
-
msg: Extract<TClientMessage, { type: 'wait-background-job-group' }>,
|
|
125
|
-
): void {
|
|
126
|
-
if (!msg.groupId) {
|
|
127
|
-
send({ type: 'protocol_error', message: 'groupId is required' });
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
session.waitBackgroundJobGroup(msg.groupId).then(
|
|
131
|
-
(group) => send({ type: 'background_job_group', groupId: msg.groupId, group }),
|
|
132
|
-
(error: Error) => send({ type: 'protocol_error', message: error.message }),
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function sendBackgroundTaskInput(
|
|
137
|
-
session: IInteractiveSession,
|
|
138
|
-
send: (message: TServerMessage) => void,
|
|
139
|
-
msg: Extract<TClientMessage, { type: 'send-background-task' }>,
|
|
140
|
-
): void {
|
|
141
|
-
if (!msg.input) {
|
|
142
|
-
send({ type: 'protocol_error', message: 'input is required' });
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
sendBackgroundTaskControlResult(
|
|
146
|
-
send,
|
|
147
|
-
'send',
|
|
148
|
-
msg.taskId,
|
|
149
|
-
session.sendBackgroundTask(msg.taskId, msg.input),
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function sendBackgroundTaskControlResult(
|
|
154
|
-
send: (message: TServerMessage) => void,
|
|
155
|
-
action: TBackgroundControlAction,
|
|
156
|
-
taskId: string,
|
|
157
|
-
operation: Promise<void>,
|
|
158
|
-
): void {
|
|
159
|
-
operation.then(
|
|
160
|
-
() => send({ type: 'background_task_control_result', action, taskId, success: true }),
|
|
161
|
-
(error: Error) =>
|
|
162
|
-
send({
|
|
163
|
-
type: 'background_task_control_result',
|
|
164
|
-
action,
|
|
165
|
-
taskId,
|
|
166
|
-
success: false,
|
|
167
|
-
message: error.message,
|
|
168
|
-
}),
|
|
169
|
-
);
|
|
170
|
-
}
|