@thready-web/dsh-bot-plugin 0.1.0-beta.1 → 0.1.0-beta.3
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 +31 -0
- package/client.js +646 -621
- package/dist/cli.js +32 -12
- package/dist/context.js +21 -9
- package/dist/cron.js +1 -1
- package/dist/desk.js +75 -26
- package/dist/engine.js +160 -77
- package/dist/fs-safe.js +1 -1
- package/dist/host.js +1 -0
- package/dist/http-plugin.js +6 -2
- package/dist/http.js +61 -23
- package/dist/inbox.js +10 -7
- package/dist/index.js +115 -28
- package/dist/live-diff.js +3 -1
- package/dist/live-snapshot.js +3 -1
- package/dist/provision.js +2 -0
- package/dist/runtime-registry.js +4 -4
- package/dist/session-files.js +1 -1
- package/dist/session-previews.js +5 -1
- package/dist/store.js +20 -5
- package/dist/tools.js +62 -26
- package/dist/triggers.js +83 -39
- package/dist/work-admit.js +124 -8
- package/dist/work-child.js +9 -6
- package/dist/work-http.js +4 -2
- package/dist/work-ledger.js +16 -14
- package/dist/work-mock-host.js +8 -6
- package/dist/work-mock.js +20 -19
- package/dist/work-tickets.js +156 -72
- package/dist/work-tools.js +2 -2
- package/dist/work-worker.js +213 -71
- package/package.json +8 -4
- package/public/assets/{index-ByU9a3Lh.js → index-D0tTt7E4.js} +37 -37
- package/public/assets/{index-Be82iGwe.css → index-PyqSrdBb.css} +1 -1
- package/public/index.html +2 -2
package/dist/work-child.js
CHANGED
|
@@ -14,7 +14,9 @@ function presetsOf(ctx) {
|
|
|
14
14
|
if (typeof ctx.get === 'function')
|
|
15
15
|
return ctx.get('agentPresets') ?? null;
|
|
16
16
|
}
|
|
17
|
-
catch {
|
|
17
|
+
catch {
|
|
18
|
+
/* preset service is optional until a worker is created */
|
|
19
|
+
}
|
|
18
20
|
try {
|
|
19
21
|
return ctx.agentPresets ?? null;
|
|
20
22
|
}
|
|
@@ -31,7 +33,8 @@ export function ensureWorkerFilePreset(ctx) {
|
|
|
31
33
|
const presets = presetsOf(ctx);
|
|
32
34
|
if (!presets?.register || !presets?.mount)
|
|
33
35
|
return Promise.resolve(null);
|
|
34
|
-
return presets
|
|
36
|
+
return presets
|
|
37
|
+
.register({
|
|
35
38
|
id: WORKER_FILE_PRESET,
|
|
36
39
|
plugins: [
|
|
37
40
|
{
|
|
@@ -40,7 +43,9 @@ export function ensureWorkerFilePreset(ctx) {
|
|
|
40
43
|
config: { applyPatch: false, readImage: false },
|
|
41
44
|
},
|
|
42
45
|
],
|
|
43
|
-
})
|
|
46
|
+
})
|
|
47
|
+
.then(() => WORKER_FILE_PRESET)
|
|
48
|
+
.catch((error) => {
|
|
44
49
|
const message = error instanceof Error ? error.message : String(error);
|
|
45
50
|
if (message.includes('Duplicate'))
|
|
46
51
|
return WORKER_FILE_PRESET;
|
|
@@ -59,9 +64,7 @@ export function workerFileSetup(ctx, presetId) {
|
|
|
59
64
|
const presets = presetsOf(ctx);
|
|
60
65
|
if (!presets?.mount)
|
|
61
66
|
return;
|
|
62
|
-
const recorded = agent?.session && typeof presets.presetForSession === 'function'
|
|
63
|
-
? presets.presetForSession(agent.session)
|
|
64
|
-
: null;
|
|
67
|
+
const recorded = agent?.session && typeof presets.presetForSession === 'function' ? presets.presetForSession(agent.session) : null;
|
|
65
68
|
const id = presetId || recorded || presets.defaultId;
|
|
66
69
|
if (!id)
|
|
67
70
|
return;
|
package/dist/work-http.js
CHANGED
|
@@ -202,7 +202,9 @@ export function openPageLive(req, res, source) {
|
|
|
202
202
|
}
|
|
203
203
|
};
|
|
204
204
|
void pump();
|
|
205
|
-
timer = setInterval(() => {
|
|
205
|
+
timer = setInterval(() => {
|
|
206
|
+
void pump();
|
|
207
|
+
}, intervalMs);
|
|
206
208
|
timer.unref?.();
|
|
207
209
|
req.on('close', stop);
|
|
208
210
|
res.on('error', stop);
|
|
@@ -216,7 +218,7 @@ export function openPageLive(req, res, source) {
|
|
|
216
218
|
* @param {string} path
|
|
217
219
|
* @param {URL} url
|
|
218
220
|
* @param {Record<string, unknown>} body
|
|
219
|
-
* @param {ReturnType<import('./work-worker.js').createWorkRuntime> | null} work
|
|
221
|
+
* @param {ReturnType<typeof import('./work-worker.js').createWorkRuntime> | null} work
|
|
220
222
|
*/
|
|
221
223
|
export async function handleWorkApi(method, path, url, body, work) {
|
|
222
224
|
if (!path.startsWith('/session-foundations/api/work'))
|
package/dist/work-ledger.js
CHANGED
|
@@ -47,7 +47,7 @@ export function renderNotice(lines) {
|
|
|
47
47
|
].join('\n');
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
|
-
* @param {ReturnType<import('./work-tickets.js').createTicketBook>} book
|
|
50
|
+
* @param {ReturnType<typeof import('./work-tickets.js').createTicketBook>} book
|
|
51
51
|
* @param {{
|
|
52
52
|
* pid: number,
|
|
53
53
|
* inflight: Set<string>,
|
|
@@ -82,7 +82,7 @@ export async function reconcileInputs(book, deps) {
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
|
-
* @param {ReturnType<import('./work-tickets.js').createTicketBook>} book
|
|
85
|
+
* @param {ReturnType<typeof import('./work-tickets.js').createTicketBook>} book
|
|
86
86
|
* @param {{
|
|
87
87
|
* pid: number,
|
|
88
88
|
* inflight: Set<string>,
|
|
@@ -123,7 +123,7 @@ export async function reconcileNotices(book, deps) {
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
|
-
* @param {ReturnType<import('./work-tickets.js').createTicketBook>} book
|
|
126
|
+
* @param {ReturnType<typeof import('./work-tickets.js').createTicketBook>} book
|
|
127
127
|
* @param {Record<string, any>} input
|
|
128
128
|
* @param {{
|
|
129
129
|
* pid: number,
|
|
@@ -140,7 +140,9 @@ export async function pushInput(book, input, deps) {
|
|
|
140
140
|
try {
|
|
141
141
|
budget = { ...budget, ...JSON.parse(ticket.budget_json) };
|
|
142
142
|
}
|
|
143
|
-
catch {
|
|
143
|
+
catch {
|
|
144
|
+
/* host default */
|
|
145
|
+
}
|
|
144
146
|
const text = book.readBriefing(input.payload_hash);
|
|
145
147
|
const body = renderBriefing({ text, revision: input.briefing_revision, budget, kind: input.kind });
|
|
146
148
|
deps.inflight.add(input.native_message_id);
|
|
@@ -149,10 +151,10 @@ export async function pushInput(book, input, deps) {
|
|
|
149
151
|
attempts: input.flush_attempts,
|
|
150
152
|
markFlushing: () => book.markInputFlush(input.id, 'flushing', deps.pid, '', null, true),
|
|
151
153
|
push: () => deps.push(attempt.child_session_id, input.native_message_id, body),
|
|
152
|
-
markAccepted:
|
|
153
|
-
markAmbiguous:
|
|
154
|
-
markDead:
|
|
155
|
-
markRetry:
|
|
154
|
+
markAccepted: seq => book.noteInputAccepted(input, seq),
|
|
155
|
+
markAmbiguous: error => book.markInputFlush(input.id, 'ambiguous', deps.pid, error, null, false),
|
|
156
|
+
markDead: error => book.markInputFlush(input.id, 'dead', deps.pid, error, null, false),
|
|
157
|
+
markRetry: error => book.markInputFlush(input.id, 'intent', deps.pid, error, null, false),
|
|
156
158
|
});
|
|
157
159
|
}
|
|
158
160
|
finally {
|
|
@@ -160,7 +162,7 @@ export async function pushInput(book, input, deps) {
|
|
|
160
162
|
}
|
|
161
163
|
}
|
|
162
164
|
/**
|
|
163
|
-
* @param {ReturnType<import('./work-tickets.js').createTicketBook>} book
|
|
165
|
+
* @param {ReturnType<typeof import('./work-tickets.js').createTicketBook>} book
|
|
164
166
|
* @param {string} nativeId
|
|
165
167
|
* @param {string} owner
|
|
166
168
|
* @param {string} text
|
|
@@ -178,10 +180,10 @@ export async function pushNotice(book, nativeId, owner, text, attempts, deps) {
|
|
|
178
180
|
attempts,
|
|
179
181
|
markFlushing: () => book.markNoticeGroup(nativeId, 'flushing', deps.pid, '', null, true),
|
|
180
182
|
push: () => deps.push(owner, nativeId, text),
|
|
181
|
-
markAccepted:
|
|
182
|
-
markAmbiguous:
|
|
183
|
-
markDead:
|
|
184
|
-
markRetry:
|
|
183
|
+
markAccepted: seq => book.markNoticeGroup(nativeId, 'accepted', deps.pid, '', seq, false),
|
|
184
|
+
markAmbiguous: error => book.markNoticeGroup(nativeId, 'ambiguous', deps.pid, error, null, false),
|
|
185
|
+
markDead: error => book.markNoticeGroup(nativeId, 'dead', deps.pid, error, null, false),
|
|
186
|
+
markRetry: error => book.markNoticeGroup(nativeId, 'intent', deps.pid, error, null, false),
|
|
185
187
|
});
|
|
186
188
|
}
|
|
187
189
|
finally {
|
|
@@ -213,5 +215,5 @@ export function messageIdOf(event) {
|
|
|
213
215
|
*/
|
|
214
216
|
export function reasonKindOf(event) {
|
|
215
217
|
const reason = event?.data?.reason;
|
|
216
|
-
return reason && typeof reason === 'object' ? reason.kind ?? '' : '';
|
|
218
|
+
return reason && typeof reason === 'object' ? (reason.kind ?? '') : '';
|
|
217
219
|
}
|
package/dist/work-mock-host.js
CHANGED
|
@@ -16,13 +16,13 @@ export async function startWorkMock(options) {
|
|
|
16
16
|
const clock = { ms: Date.now() };
|
|
17
17
|
const now = options.now ?? (() => new Date(clock.ms));
|
|
18
18
|
const work = createWorkRuntime(store, engine, {
|
|
19
|
-
createChild:
|
|
19
|
+
createChild: spec => world.createChild(spec),
|
|
20
20
|
push: (sessionId, messageId, text) => world.push(sessionId, messageId, text),
|
|
21
21
|
logHas: (sessionId, messageId) => world.logHas(sessionId, messageId),
|
|
22
22
|
remove: (sessionId, messageId) => world.remove(sessionId, messageId),
|
|
23
|
-
pendingIds:
|
|
23
|
+
pendingIds: sessionId => world.pendingIds(sessionId),
|
|
24
24
|
cancel: (sessionId, cancelOptions) => world.cancel(sessionId, cancelOptions),
|
|
25
|
-
snapshot:
|
|
25
|
+
snapshot: sessionId => world.snapshot(sessionId),
|
|
26
26
|
now,
|
|
27
27
|
pid: process.pid,
|
|
28
28
|
});
|
|
@@ -119,14 +119,16 @@ export async function startWorkMock(options) {
|
|
|
119
119
|
try {
|
|
120
120
|
store.close();
|
|
121
121
|
}
|
|
122
|
-
catch {
|
|
122
|
+
catch {
|
|
123
|
+
/* closed */
|
|
124
|
+
}
|
|
123
125
|
resolve();
|
|
124
126
|
});
|
|
125
127
|
}),
|
|
126
128
|
};
|
|
127
129
|
}
|
|
128
130
|
/**
|
|
129
|
-
* @param {ReturnType<import('./work-worker.js').createWorkRuntime>} work
|
|
131
|
+
* @param {ReturnType<typeof import('./work-worker.js').createWorkRuntime>} work
|
|
130
132
|
* @param {unknown} ticketId
|
|
131
133
|
*/
|
|
132
134
|
function statusOf(work, ticketId) {
|
|
@@ -154,7 +156,7 @@ function send(res, status, body) {
|
|
|
154
156
|
function readJson(req) {
|
|
155
157
|
return new Promise((resolve, reject) => {
|
|
156
158
|
const chunks = [];
|
|
157
|
-
req.on('data', chunk => chunks.push(chunk));
|
|
159
|
+
req.on('data', (chunk) => chunks.push(chunk));
|
|
158
160
|
req.on('end', () => {
|
|
159
161
|
const raw = Buffer.concat(chunks).toString('utf8');
|
|
160
162
|
if (raw === '') {
|
package/dist/work-mock.js
CHANGED
|
@@ -43,29 +43,25 @@ export function createMockWorld() {
|
|
|
43
43
|
},
|
|
44
44
|
seeUser(sessionId, messageId, turn) {
|
|
45
45
|
const slot = session(sessionId);
|
|
46
|
-
append(slot, 'user/message', { id: messageId, turn, message: { id: messageId } });
|
|
47
|
-
return slot.events.at(-1);
|
|
46
|
+
return append(slot, 'user/message', { id: messageId, turn, message: { id: messageId } });
|
|
48
47
|
},
|
|
49
48
|
endTurn(sessionId, turn, reasonKind) {
|
|
50
49
|
const slot = session(sessionId);
|
|
51
|
-
append(slot, 'turn/end', { turn, reason: { kind: reasonKind } });
|
|
52
|
-
return slot.events.at(-1);
|
|
50
|
+
return append(slot, 'turn/end', { turn, reason: { kind: reasonKind } });
|
|
53
51
|
},
|
|
54
52
|
toolCall(sessionId, name, args) {
|
|
55
53
|
const slot = session(sessionId);
|
|
56
|
-
append(slot, 'tool/call', { name, arguments: args });
|
|
57
|
-
return slot.events.at(-1);
|
|
54
|
+
return append(slot, 'tool/call', { name, arguments: args });
|
|
58
55
|
},
|
|
59
56
|
assistant(sessionId, text) {
|
|
60
57
|
const slot = session(sessionId);
|
|
61
|
-
append(slot, 'assistant/message', { text, message: { content: [{ type: 'text', text }] } });
|
|
62
|
-
return slot.events.at(-1);
|
|
58
|
+
return append(slot, 'assistant/message', { text, message: { content: [{ type: 'text', text }] } });
|
|
63
59
|
},
|
|
64
60
|
forgetLog(sessionId, messageId) {
|
|
65
61
|
const slot = session(sessionId);
|
|
66
|
-
slot.events = slot.events.filter(event => !(event.type === 'agent/inbox/spliced'
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
slot.events = slot.events.filter(event => !(event.type === 'agent/inbox/spliced' &&
|
|
63
|
+
Array.isArray(event.data?.inserted) &&
|
|
64
|
+
event.data.inserted.some((item) => item?.id === messageId)));
|
|
69
65
|
slot.nextTurn = slot.nextTurn.filter(item => item.id !== messageId);
|
|
70
66
|
},
|
|
71
67
|
async createChild(spec) {
|
|
@@ -84,13 +80,13 @@ export function createMockWorld() {
|
|
|
84
80
|
const slot = session(sessionId);
|
|
85
81
|
if (!slot.nextTurn.some(item => item.id === messageId))
|
|
86
82
|
slot.nextTurn.push({ id: messageId, text });
|
|
87
|
-
const
|
|
88
|
-
return { ok: true, ambiguous: false, seq, target: 'next-turn' };
|
|
83
|
+
const event = append(slot, 'agent/inbox/spliced', { inserted: [{ id: messageId }], target: 'next-turn' });
|
|
84
|
+
return { ok: true, ambiguous: false, seq: event.seq, target: 'next-turn' };
|
|
89
85
|
},
|
|
90
86
|
async logHas(sessionId, messageId) {
|
|
91
|
-
return session(sessionId).events.some(event =>
|
|
92
|
-
|
|
93
|
-
|
|
87
|
+
return session(sessionId).events.some(event => event.type === 'agent/inbox/spliced' &&
|
|
88
|
+
Array.isArray(event.data?.inserted) &&
|
|
89
|
+
event.data.inserted.some((item) => item?.id === messageId));
|
|
94
90
|
},
|
|
95
91
|
async remove(sessionId, messageId) {
|
|
96
92
|
const slot = session(sessionId);
|
|
@@ -101,7 +97,11 @@ export function createMockWorld() {
|
|
|
101
97
|
return true;
|
|
102
98
|
},
|
|
103
99
|
async cancel(sessionId, options) {
|
|
104
|
-
cancels.push({
|
|
100
|
+
cancels.push({
|
|
101
|
+
sessionId,
|
|
102
|
+
keepInbox: options?.keepInbox === true,
|
|
103
|
+
...(typeof options?.reason === 'string' ? { reason: options.reason } : {}),
|
|
104
|
+
});
|
|
105
105
|
},
|
|
106
106
|
async snapshot(sessionId) {
|
|
107
107
|
return session(sessionId).events.map(event => ({ ...event, data: event.data }));
|
|
@@ -125,7 +125,8 @@ export function createMockWorld() {
|
|
|
125
125
|
*/
|
|
126
126
|
function append(slot, type, data) {
|
|
127
127
|
slot.seq += 1;
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
const event = { type, seq: slot.seq, data };
|
|
129
|
+
slot.events.push(event);
|
|
130
|
+
return event;
|
|
130
131
|
}
|
|
131
132
|
}
|