@workbench-kit/runtime 0.0.1-prototype.0 → 0.0.2-prototype.0.1.1
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/package.json +5 -2
- package/src/index.ts +16 -16
- package/src/mockRuntime.ts +218 -218
- package/src/types.ts +34 -47
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workbench-kit/runtime",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2-prototype.0.1.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
"!src/**/*.stories.ts",
|
|
14
14
|
"!src/**/*.stories.tsx"
|
|
15
15
|
],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@workbench-kit/contracts": "0.0.2-prototype.0.1.1"
|
|
18
|
+
},
|
|
16
19
|
"description": "Framework-neutral Workbench Kit runtime events and mock runtime utilities.",
|
|
17
20
|
"publishConfig": {
|
|
18
21
|
"access": "public",
|
|
@@ -21,7 +24,7 @@
|
|
|
21
24
|
},
|
|
22
25
|
"repository": {
|
|
23
26
|
"type": "git",
|
|
24
|
-
"url": "git+https://github.com/NewChoBo/
|
|
27
|
+
"url": "git+https://github.com/NewChoBo/workbench-kit.git",
|
|
25
28
|
"directory": "packages/runtime"
|
|
26
29
|
},
|
|
27
30
|
"scripts": {
|
package/src/index.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export { createMockWorkbenchRuntime } from './mockRuntime';
|
|
2
|
-
export type {
|
|
3
|
-
MockRuntimeResponsePlan,
|
|
4
|
-
MockWorkbenchRuntime,
|
|
5
|
-
MockWorkbenchRuntimeOptions,
|
|
6
|
-
SendRuntimeMessageOptions,
|
|
7
|
-
} from './mockRuntime';
|
|
8
|
-
export type {
|
|
9
|
-
RuntimeChatMessage,
|
|
10
|
-
RuntimeChatMessageSource,
|
|
11
|
-
RuntimeStatus,
|
|
12
|
-
RuntimeWorkspacePatch,
|
|
13
|
-
RuntimeWorkspacePatchSource,
|
|
14
|
-
WorkbenchRuntimeEvent,
|
|
15
|
-
WorkbenchRuntimeListener,
|
|
16
|
-
} from './types';
|
|
1
|
+
export { createMockWorkbenchRuntime } from './mockRuntime';
|
|
2
|
+
export type {
|
|
3
|
+
MockRuntimeResponsePlan,
|
|
4
|
+
MockWorkbenchRuntime,
|
|
5
|
+
MockWorkbenchRuntimeOptions,
|
|
6
|
+
SendRuntimeMessageOptions,
|
|
7
|
+
} from './mockRuntime';
|
|
8
|
+
export type {
|
|
9
|
+
RuntimeChatMessage,
|
|
10
|
+
RuntimeChatMessageSource,
|
|
11
|
+
RuntimeStatus,
|
|
12
|
+
RuntimeWorkspacePatch,
|
|
13
|
+
RuntimeWorkspacePatchSource,
|
|
14
|
+
WorkbenchRuntimeEvent,
|
|
15
|
+
WorkbenchRuntimeListener,
|
|
16
|
+
} from './types';
|
package/src/mockRuntime.ts
CHANGED
|
@@ -1,218 +1,218 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
RuntimeChatMessage,
|
|
3
|
-
RuntimeStatus,
|
|
4
|
-
RuntimeWorkspacePatch,
|
|
5
|
-
WorkbenchRuntimeEvent,
|
|
6
|
-
WorkbenchRuntimeListener,
|
|
7
|
-
} from './types';
|
|
8
|
-
|
|
9
|
-
export interface MockRuntimeResponsePlan {
|
|
10
|
-
chunks: string[];
|
|
11
|
-
intervalMs?: number;
|
|
12
|
-
label?: string;
|
|
13
|
-
workspacePatches?: RuntimeWorkspacePatch[];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface SendRuntimeMessageOptions {
|
|
17
|
-
response?: false | MockRuntimeResponsePlan;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface MockWorkbenchRuntimeOptions {
|
|
21
|
-
idPrefix?: string;
|
|
22
|
-
initialMessages?: RuntimeChatMessage[];
|
|
23
|
-
initialStatus?: RuntimeStatus;
|
|
24
|
-
now?: () => string;
|
|
25
|
-
response?:
|
|
26
|
-
| false
|
|
27
|
-
| MockRuntimeResponsePlan
|
|
28
|
-
| ((message: RuntimeChatMessage) => MockRuntimeResponsePlan);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface MockWorkbenchRuntime {
|
|
32
|
-
cancel: () => void;
|
|
33
|
-
dispose: () => void;
|
|
34
|
-
emitWorkspacePatch: (patch: RuntimeWorkspacePatch) => void;
|
|
35
|
-
getMessages: () => RuntimeChatMessage[];
|
|
36
|
-
getStatus: () => RuntimeStatus;
|
|
37
|
-
sendMessage: (
|
|
38
|
-
content: string,
|
|
39
|
-
options?: SendRuntimeMessageOptions,
|
|
40
|
-
) => RuntimeChatMessage | undefined;
|
|
41
|
-
streamAssistantResponse: (plan: MockRuntimeResponsePlan) => RuntimeChatMessage;
|
|
42
|
-
subscribe: (listener: WorkbenchRuntimeListener) => () => void;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function cloneMessage(message: RuntimeChatMessage): RuntimeChatMessage {
|
|
46
|
-
return { ...message };
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function cloneMessages(messages: RuntimeChatMessage[]) {
|
|
50
|
-
return messages.map(cloneMessage);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function defaultNow() {
|
|
54
|
-
return new Date().toISOString();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function createMockWorkbenchRuntime({
|
|
58
|
-
idPrefix = 'runtime-message',
|
|
59
|
-
initialMessages = [],
|
|
60
|
-
initialStatus = 'idle',
|
|
61
|
-
now = defaultNow,
|
|
62
|
-
response = {
|
|
63
|
-
chunks: ['Mock runtime received the message.'],
|
|
64
|
-
intervalMs: 80,
|
|
65
|
-
},
|
|
66
|
-
}: MockWorkbenchRuntimeOptions = {}): MockWorkbenchRuntime {
|
|
67
|
-
let counter = initialMessages.length;
|
|
68
|
-
let status = initialStatus;
|
|
69
|
-
let messages = cloneMessages(initialMessages);
|
|
70
|
-
const listeners = new Set<WorkbenchRuntimeListener>();
|
|
71
|
-
const activeTimers = new Set<ReturnType<typeof globalThis.setTimeout>>();
|
|
72
|
-
|
|
73
|
-
const nextId = () => {
|
|
74
|
-
counter += 1;
|
|
75
|
-
return `${idPrefix}-${counter}`;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const emit = (event: WorkbenchRuntimeEvent) => {
|
|
79
|
-
listeners.forEach((listener) => listener(event));
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const setStatus = (nextStatus: RuntimeStatus) => {
|
|
83
|
-
if (status === nextStatus) return;
|
|
84
|
-
|
|
85
|
-
const previousStatus = status;
|
|
86
|
-
status = nextStatus;
|
|
87
|
-
emit({ previousStatus, status, type: 'status' });
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const clearTimers = () => {
|
|
91
|
-
activeTimers.forEach((timer) => globalThis.clearTimeout(timer));
|
|
92
|
-
activeTimers.clear();
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const pushMessage = (message: RuntimeChatMessage) => {
|
|
96
|
-
messages = [...messages, message];
|
|
97
|
-
emit({ message: cloneMessage(message), type: 'message' });
|
|
98
|
-
return message;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const appendMessageDelta = (messageId: string, delta: string) => {
|
|
102
|
-
let updatedMessage: RuntimeChatMessage | undefined;
|
|
103
|
-
messages = messages.map((message) => {
|
|
104
|
-
if (message.id !== messageId) return message;
|
|
105
|
-
|
|
106
|
-
updatedMessage = {
|
|
107
|
-
...message,
|
|
108
|
-
content: `${message.content}${delta}`,
|
|
109
|
-
};
|
|
110
|
-
return updatedMessage;
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
if (updatedMessage) {
|
|
114
|
-
emit({ delta, message: cloneMessage(updatedMessage), type: 'message-delta' });
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
const emitWorkspacePatch = (patch: RuntimeWorkspacePatch) => {
|
|
119
|
-
emit({ patch, type: 'workspace-patch' });
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const finishStreaming = (workspacePatches: RuntimeWorkspacePatch[]) => {
|
|
123
|
-
workspacePatches.forEach(emitWorkspacePatch);
|
|
124
|
-
setStatus('idle');
|
|
125
|
-
activeTimers.clear();
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const streamAssistantResponse = ({
|
|
129
|
-
chunks,
|
|
130
|
-
intervalMs = 80,
|
|
131
|
-
label,
|
|
132
|
-
workspacePatches = [],
|
|
133
|
-
}: MockRuntimeResponsePlan) => {
|
|
134
|
-
clearTimers();
|
|
135
|
-
setStatus('running');
|
|
136
|
-
|
|
137
|
-
const assistantMessage = pushMessage({
|
|
138
|
-
content: '',
|
|
139
|
-
createdAt: now(),
|
|
140
|
-
id: nextId(),
|
|
141
|
-
label,
|
|
142
|
-
source: 'assistant',
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
if (chunks.length === 0) {
|
|
146
|
-
finishStreaming(workspacePatches);
|
|
147
|
-
return assistantMessage;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
chunks.forEach((chunk, index) => {
|
|
151
|
-
const timer = globalThis.setTimeout(
|
|
152
|
-
() => {
|
|
153
|
-
activeTimers.delete(timer);
|
|
154
|
-
if (status !== 'running') return;
|
|
155
|
-
|
|
156
|
-
appendMessageDelta(assistantMessage.id, chunk);
|
|
157
|
-
|
|
158
|
-
if (index === chunks.length - 1) {
|
|
159
|
-
finishStreaming(workspacePatches);
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
Math.max(0, intervalMs) * (index + 1),
|
|
163
|
-
);
|
|
164
|
-
activeTimers.add(timer);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
return assistantMessage;
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
const sendMessage = (content: string, options: SendRuntimeMessageOptions = {}) => {
|
|
171
|
-
const trimmedContent = content.trim();
|
|
172
|
-
if (!trimmedContent) return undefined;
|
|
173
|
-
|
|
174
|
-
clearTimers();
|
|
175
|
-
|
|
176
|
-
const userMessage = pushMessage({
|
|
177
|
-
content: trimmedContent,
|
|
178
|
-
createdAt: now(),
|
|
179
|
-
id: nextId(),
|
|
180
|
-
source: 'user',
|
|
181
|
-
});
|
|
182
|
-
setStatus('running');
|
|
183
|
-
|
|
184
|
-
const responsePlan = options.response ?? response;
|
|
185
|
-
if (responsePlan === false) {
|
|
186
|
-
return userMessage;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
streamAssistantResponse(
|
|
190
|
-
typeof responsePlan === 'function' ? responsePlan(userMessage) : responsePlan,
|
|
191
|
-
);
|
|
192
|
-
return userMessage;
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
return {
|
|
196
|
-
cancel: () => {
|
|
197
|
-
if (status !== 'running') return;
|
|
198
|
-
|
|
199
|
-
clearTimers();
|
|
200
|
-
setStatus('cancelled');
|
|
201
|
-
},
|
|
202
|
-
dispose: () => {
|
|
203
|
-
clearTimers();
|
|
204
|
-
listeners.clear();
|
|
205
|
-
},
|
|
206
|
-
emitWorkspacePatch,
|
|
207
|
-
getMessages: () => cloneMessages(messages),
|
|
208
|
-
getStatus: () => status,
|
|
209
|
-
sendMessage,
|
|
210
|
-
streamAssistantResponse,
|
|
211
|
-
subscribe: (listener) => {
|
|
212
|
-
listeners.add(listener);
|
|
213
|
-
return () => {
|
|
214
|
-
listeners.delete(listener);
|
|
215
|
-
};
|
|
216
|
-
},
|
|
217
|
-
};
|
|
218
|
-
}
|
|
1
|
+
import type {
|
|
2
|
+
RuntimeChatMessage,
|
|
3
|
+
RuntimeStatus,
|
|
4
|
+
RuntimeWorkspacePatch,
|
|
5
|
+
WorkbenchRuntimeEvent,
|
|
6
|
+
WorkbenchRuntimeListener,
|
|
7
|
+
} from './types';
|
|
8
|
+
|
|
9
|
+
export interface MockRuntimeResponsePlan {
|
|
10
|
+
chunks: string[];
|
|
11
|
+
intervalMs?: number;
|
|
12
|
+
label?: string;
|
|
13
|
+
workspacePatches?: RuntimeWorkspacePatch[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface SendRuntimeMessageOptions {
|
|
17
|
+
response?: false | MockRuntimeResponsePlan;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface MockWorkbenchRuntimeOptions {
|
|
21
|
+
idPrefix?: string;
|
|
22
|
+
initialMessages?: RuntimeChatMessage[];
|
|
23
|
+
initialStatus?: RuntimeStatus;
|
|
24
|
+
now?: () => string;
|
|
25
|
+
response?:
|
|
26
|
+
| false
|
|
27
|
+
| MockRuntimeResponsePlan
|
|
28
|
+
| ((message: RuntimeChatMessage) => MockRuntimeResponsePlan);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface MockWorkbenchRuntime {
|
|
32
|
+
cancel: () => void;
|
|
33
|
+
dispose: () => void;
|
|
34
|
+
emitWorkspacePatch: (patch: RuntimeWorkspacePatch) => void;
|
|
35
|
+
getMessages: () => RuntimeChatMessage[];
|
|
36
|
+
getStatus: () => RuntimeStatus;
|
|
37
|
+
sendMessage: (
|
|
38
|
+
content: string,
|
|
39
|
+
options?: SendRuntimeMessageOptions,
|
|
40
|
+
) => RuntimeChatMessage | undefined;
|
|
41
|
+
streamAssistantResponse: (plan: MockRuntimeResponsePlan) => RuntimeChatMessage;
|
|
42
|
+
subscribe: (listener: WorkbenchRuntimeListener) => () => void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function cloneMessage(message: RuntimeChatMessage): RuntimeChatMessage {
|
|
46
|
+
return { ...message };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function cloneMessages(messages: RuntimeChatMessage[]) {
|
|
50
|
+
return messages.map(cloneMessage);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function defaultNow() {
|
|
54
|
+
return new Date().toISOString();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function createMockWorkbenchRuntime({
|
|
58
|
+
idPrefix = 'runtime-message',
|
|
59
|
+
initialMessages = [],
|
|
60
|
+
initialStatus = 'idle',
|
|
61
|
+
now = defaultNow,
|
|
62
|
+
response = {
|
|
63
|
+
chunks: ['Mock runtime received the message.'],
|
|
64
|
+
intervalMs: 80,
|
|
65
|
+
},
|
|
66
|
+
}: MockWorkbenchRuntimeOptions = {}): MockWorkbenchRuntime {
|
|
67
|
+
let counter = initialMessages.length;
|
|
68
|
+
let status = initialStatus;
|
|
69
|
+
let messages = cloneMessages(initialMessages);
|
|
70
|
+
const listeners = new Set<WorkbenchRuntimeListener>();
|
|
71
|
+
const activeTimers = new Set<ReturnType<typeof globalThis.setTimeout>>();
|
|
72
|
+
|
|
73
|
+
const nextId = () => {
|
|
74
|
+
counter += 1;
|
|
75
|
+
return `${idPrefix}-${counter}`;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const emit = (event: WorkbenchRuntimeEvent) => {
|
|
79
|
+
listeners.forEach((listener) => listener(event));
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const setStatus = (nextStatus: RuntimeStatus) => {
|
|
83
|
+
if (status === nextStatus) return;
|
|
84
|
+
|
|
85
|
+
const previousStatus = status;
|
|
86
|
+
status = nextStatus;
|
|
87
|
+
emit({ previousStatus, status, type: 'status' });
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const clearTimers = () => {
|
|
91
|
+
activeTimers.forEach((timer) => globalThis.clearTimeout(timer));
|
|
92
|
+
activeTimers.clear();
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const pushMessage = (message: RuntimeChatMessage) => {
|
|
96
|
+
messages = [...messages, message];
|
|
97
|
+
emit({ message: cloneMessage(message), type: 'message' });
|
|
98
|
+
return message;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const appendMessageDelta = (messageId: string, delta: string) => {
|
|
102
|
+
let updatedMessage: RuntimeChatMessage | undefined;
|
|
103
|
+
messages = messages.map((message) => {
|
|
104
|
+
if (message.id !== messageId) return message;
|
|
105
|
+
|
|
106
|
+
updatedMessage = {
|
|
107
|
+
...message,
|
|
108
|
+
content: `${message.content}${delta}`,
|
|
109
|
+
};
|
|
110
|
+
return updatedMessage;
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
if (updatedMessage) {
|
|
114
|
+
emit({ delta, message: cloneMessage(updatedMessage), type: 'message-delta' });
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const emitWorkspacePatch = (patch: RuntimeWorkspacePatch) => {
|
|
119
|
+
emit({ patch, type: 'workspace-patch' });
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const finishStreaming = (workspacePatches: RuntimeWorkspacePatch[]) => {
|
|
123
|
+
workspacePatches.forEach(emitWorkspacePatch);
|
|
124
|
+
setStatus('idle');
|
|
125
|
+
activeTimers.clear();
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const streamAssistantResponse = ({
|
|
129
|
+
chunks,
|
|
130
|
+
intervalMs = 80,
|
|
131
|
+
label,
|
|
132
|
+
workspacePatches = [],
|
|
133
|
+
}: MockRuntimeResponsePlan) => {
|
|
134
|
+
clearTimers();
|
|
135
|
+
setStatus('running');
|
|
136
|
+
|
|
137
|
+
const assistantMessage = pushMessage({
|
|
138
|
+
content: '',
|
|
139
|
+
createdAt: now(),
|
|
140
|
+
id: nextId(),
|
|
141
|
+
label,
|
|
142
|
+
source: 'assistant',
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
if (chunks.length === 0) {
|
|
146
|
+
finishStreaming(workspacePatches);
|
|
147
|
+
return assistantMessage;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
chunks.forEach((chunk, index) => {
|
|
151
|
+
const timer = globalThis.setTimeout(
|
|
152
|
+
() => {
|
|
153
|
+
activeTimers.delete(timer);
|
|
154
|
+
if (status !== 'running') return;
|
|
155
|
+
|
|
156
|
+
appendMessageDelta(assistantMessage.id, chunk);
|
|
157
|
+
|
|
158
|
+
if (index === chunks.length - 1) {
|
|
159
|
+
finishStreaming(workspacePatches);
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
Math.max(0, intervalMs) * (index + 1),
|
|
163
|
+
);
|
|
164
|
+
activeTimers.add(timer);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
return assistantMessage;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const sendMessage = (content: string, options: SendRuntimeMessageOptions = {}) => {
|
|
171
|
+
const trimmedContent = content.trim();
|
|
172
|
+
if (!trimmedContent) return undefined;
|
|
173
|
+
|
|
174
|
+
clearTimers();
|
|
175
|
+
|
|
176
|
+
const userMessage = pushMessage({
|
|
177
|
+
content: trimmedContent,
|
|
178
|
+
createdAt: now(),
|
|
179
|
+
id: nextId(),
|
|
180
|
+
source: 'user',
|
|
181
|
+
});
|
|
182
|
+
setStatus('running');
|
|
183
|
+
|
|
184
|
+
const responsePlan = options.response ?? response;
|
|
185
|
+
if (responsePlan === false) {
|
|
186
|
+
return userMessage;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
streamAssistantResponse(
|
|
190
|
+
typeof responsePlan === 'function' ? responsePlan(userMessage) : responsePlan,
|
|
191
|
+
);
|
|
192
|
+
return userMessage;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
cancel: () => {
|
|
197
|
+
if (status !== 'running') return;
|
|
198
|
+
|
|
199
|
+
clearTimers();
|
|
200
|
+
setStatus('cancelled');
|
|
201
|
+
},
|
|
202
|
+
dispose: () => {
|
|
203
|
+
clearTimers();
|
|
204
|
+
listeners.clear();
|
|
205
|
+
},
|
|
206
|
+
emitWorkspacePatch,
|
|
207
|
+
getMessages: () => cloneMessages(messages),
|
|
208
|
+
getStatus: () => status,
|
|
209
|
+
sendMessage,
|
|
210
|
+
streamAssistantResponse,
|
|
211
|
+
subscribe: (listener) => {
|
|
212
|
+
listeners.add(listener);
|
|
213
|
+
return () => {
|
|
214
|
+
listeners.delete(listener);
|
|
215
|
+
};
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,47 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
| {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
type: 'message-delta';
|
|
36
|
-
}
|
|
37
|
-
| {
|
|
38
|
-
patch: RuntimeWorkspacePatch;
|
|
39
|
-
type: 'workspace-patch';
|
|
40
|
-
}
|
|
41
|
-
| {
|
|
42
|
-
previousStatus: RuntimeStatus;
|
|
43
|
-
status: RuntimeStatus;
|
|
44
|
-
type: 'status';
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export type WorkbenchRuntimeListener = (event: WorkbenchRuntimeEvent) => void;
|
|
1
|
+
import type {
|
|
2
|
+
ChatMessage,
|
|
3
|
+
ChatMessageSource,
|
|
4
|
+
WorkspacePatchEvent,
|
|
5
|
+
WorkspacePatchSource,
|
|
6
|
+
} from '@workbench-kit/contracts';
|
|
7
|
+
|
|
8
|
+
export type RuntimeChatMessageSource = ChatMessageSource;
|
|
9
|
+
export type RuntimeStatus = 'cancelled' | 'error' | 'idle' | 'running';
|
|
10
|
+
export type RuntimeWorkspacePatchSource = WorkspacePatchSource;
|
|
11
|
+
export type RuntimeWorkspacePatch = WorkspacePatchEvent;
|
|
12
|
+
export type RuntimeChatMessage = ChatMessage;
|
|
13
|
+
|
|
14
|
+
export type WorkbenchRuntimeEvent =
|
|
15
|
+
| {
|
|
16
|
+
message: RuntimeChatMessage;
|
|
17
|
+
type: 'message';
|
|
18
|
+
}
|
|
19
|
+
| {
|
|
20
|
+
delta: string;
|
|
21
|
+
message: RuntimeChatMessage;
|
|
22
|
+
type: 'message-delta';
|
|
23
|
+
}
|
|
24
|
+
| {
|
|
25
|
+
patch: RuntimeWorkspacePatch;
|
|
26
|
+
type: 'workspace-patch';
|
|
27
|
+
}
|
|
28
|
+
| {
|
|
29
|
+
previousStatus: RuntimeStatus;
|
|
30
|
+
status: RuntimeStatus;
|
|
31
|
+
type: 'status';
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type WorkbenchRuntimeListener = (event: WorkbenchRuntimeEvent) => void;
|