@thready-web/dsh-bot-plugin 0.1.0-beta.1 → 0.1.0-beta.2
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/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 +51 -24
- 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 +60 -22
- package/dist/inbox.js +10 -7
- package/dist/index.js +39 -24
- 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 +10 -4
- 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 +15 -18
- package/dist/work-tickets.js +156 -72
- package/dist/work-tools.js +2 -2
- package/dist/work-worker.js +117 -52
- 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/cli.js
CHANGED
|
@@ -105,7 +105,7 @@ export async function run(argv, options = {}) {
|
|
|
105
105
|
}
|
|
106
106
|
else if (command === 'session' && action === 'bind') {
|
|
107
107
|
const engine = openEngine();
|
|
108
|
-
const binding = engine.bindPersona(required(flags, 'session'), flags.persona ? Number(flags.persona) : engine.latestPersona()?.id ?? null);
|
|
108
|
+
const binding = engine.bindPersona(required(flags, 'session'), flags.persona ? Number(flags.persona) : (engine.latestPersona()?.id ?? null));
|
|
109
109
|
console.log(JSON.stringify({ ok: true, binding }, null, 2));
|
|
110
110
|
engine.store.close();
|
|
111
111
|
}
|
|
@@ -144,8 +144,12 @@ export async function run(argv, options = {}) {
|
|
|
144
144
|
const sessionId = required(flags, 'session');
|
|
145
145
|
engine.ensureSession(sessionId);
|
|
146
146
|
console.log(JSON.stringify({
|
|
147
|
-
facts: engine.store.db
|
|
148
|
-
|
|
147
|
+
facts: engine.store.db
|
|
148
|
+
.prepare('SELECT id, status, revision, priority, content FROM facts WHERE session_id = ? ORDER BY id')
|
|
149
|
+
.all(sessionId),
|
|
150
|
+
memories: engine.store.db
|
|
151
|
+
.prepare('SELECT id, status, revision, title, content FROM memories WHERE session_id = ? ORDER BY id')
|
|
152
|
+
.all(sessionId),
|
|
149
153
|
state: engine.statePayload(sessionId),
|
|
150
154
|
}, null, 2));
|
|
151
155
|
engine.store.close();
|
|
@@ -167,7 +171,9 @@ export async function run(argv, options = {}) {
|
|
|
167
171
|
}
|
|
168
172
|
else if (command === 'skill' && action === 'list') {
|
|
169
173
|
const engine = openEngine();
|
|
170
|
-
const rows = engine.store.db
|
|
174
|
+
const rows = engine.store.db
|
|
175
|
+
.prepare('SELECT * FROM skill_bindings WHERE session_id = ? ORDER BY skill_id')
|
|
176
|
+
.all(required(flags, 'session'));
|
|
171
177
|
console.log(JSON.stringify({ ok: true, skills: rows }, null, 2));
|
|
172
178
|
engine.store.close();
|
|
173
179
|
}
|
|
@@ -183,19 +189,30 @@ export async function run(argv, options = {}) {
|
|
|
183
189
|
}
|
|
184
190
|
else if (command === 'message' && action === 'list') {
|
|
185
191
|
const triggers = openTriggers();
|
|
186
|
-
console.log(JSON.stringify({
|
|
192
|
+
console.log(JSON.stringify({
|
|
193
|
+
ok: true,
|
|
194
|
+
acl: triggers.listAcl(),
|
|
195
|
+
deliveries: triggers.listDeliveries(flags.session ?? '', flags.correlation ?? ''),
|
|
196
|
+
}, null, 2));
|
|
187
197
|
triggersClose();
|
|
188
198
|
}
|
|
189
199
|
else if (command === 'work' && action === 'dispatch') {
|
|
190
200
|
const engine = openEngine();
|
|
191
201
|
const sessionId = required(flags, 'session');
|
|
192
202
|
if (!engine.isBot(sessionId)) {
|
|
193
|
-
console.log(JSON.stringify({
|
|
203
|
+
console.log(JSON.stringify({
|
|
204
|
+
ok: false,
|
|
205
|
+
code: 'FORBIDDEN',
|
|
206
|
+
message: 'An ordinary session stays on one loop and cannot dispatch work.',
|
|
207
|
+
}, null, 2));
|
|
194
208
|
engine.store.close();
|
|
195
209
|
process.exitCode = 1;
|
|
196
210
|
}
|
|
197
211
|
else {
|
|
198
|
-
const work = createWorkRuntime(engine.store, engine, {
|
|
212
|
+
const work = createWorkRuntime(engine.store, engine, {
|
|
213
|
+
resident: false,
|
|
214
|
+
push: async () => ({ ok: false, ambiguous: true }),
|
|
215
|
+
});
|
|
199
216
|
const result = await work.dispatch(sessionId, {
|
|
200
217
|
briefing: required(flags, 'text'),
|
|
201
218
|
idempotencyKey: flags.key,
|
|
@@ -215,16 +232,19 @@ export async function run(argv, options = {}) {
|
|
|
215
232
|
});
|
|
216
233
|
console.log(JSON.stringify({
|
|
217
234
|
...result,
|
|
218
|
-
...('status' in result && result.status === 'intent'
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
235
|
+
...('status' in result && result.status === 'intent'
|
|
236
|
+
? {
|
|
237
|
+
queued: false,
|
|
238
|
+
note: 'Only the intent was written. A resident DSH host reconciles it and then followup reaches the native inbox. This process will not execute after it exits.',
|
|
239
|
+
}
|
|
240
|
+
: {}),
|
|
222
241
|
}, null, 2));
|
|
223
242
|
triggersClose();
|
|
224
243
|
if (!result.ok)
|
|
225
244
|
process.exitCode = 1;
|
|
226
245
|
}
|
|
227
|
-
else if (command === 'timer' &&
|
|
246
|
+
else if (command === 'timer' &&
|
|
247
|
+
(action === 'add' || action === 'list' || action === 'pause' || action === 'resume' || action === 'delete')) {
|
|
228
248
|
const triggers = openTriggers();
|
|
229
249
|
if (action === 'add') {
|
|
230
250
|
const result = triggers.addSchedule({
|
package/dist/context.js
CHANGED
|
@@ -98,14 +98,18 @@ export function renderSession(engine, sessionId, window = DEFAULT_WINDOW) {
|
|
|
98
98
|
if (estimateTokens(stateText) > cap.state.soft)
|
|
99
99
|
stateText = renderState(frozenState, true);
|
|
100
100
|
const skills = Array.isArray(selected.skills) ? selected.skills : [];
|
|
101
|
-
let skillText = skills
|
|
101
|
+
let skillText = skills
|
|
102
|
+
.filter((skill) => skill.enabled && !skill.revoked)
|
|
103
|
+
.map((skill) => `- ${skill.skill_id} ${skill.version} ${skill.scope} ${skill.summary ?? ''}`.trimEnd())
|
|
104
|
+
.join('\n');
|
|
102
105
|
if (estimateTokens(skillText) > cap.skills.soft) {
|
|
103
|
-
skillText = skills
|
|
106
|
+
skillText = skills
|
|
107
|
+
.filter((skill) => skill.enabled && !skill.revoked)
|
|
108
|
+
.map((skill) => `- ${skill.skill_id} ${skill.version} enabled`)
|
|
109
|
+
.join('\n');
|
|
104
110
|
}
|
|
105
111
|
const revoked = engine.revokedSkills(sessionId);
|
|
106
|
-
const notice = revoked.length === 0
|
|
107
|
-
? ''
|
|
108
|
-
: `Revoked. Later loads will refuse: ${revoked.map(skill => skill.skill_id).join(', ')}`;
|
|
112
|
+
const notice = revoked.length === 0 ? '' : `Revoked. Later loads will refuse: ${revoked.map(skill => skill.skill_id).join(', ')}`;
|
|
109
113
|
const blocks = {
|
|
110
114
|
chat: CHAT,
|
|
111
115
|
soul: soulCode
|
|
@@ -130,13 +134,19 @@ export function renderSession(engine, sessionId, window = DEFAULT_WINDOW) {
|
|
|
130
134
|
'foundations:soul': blocks.soul,
|
|
131
135
|
'foundations:chat': CHAT,
|
|
132
136
|
'foundations:rules': RULES,
|
|
133
|
-
'foundations:user': blocks.user
|
|
134
|
-
|
|
137
|
+
'foundations:user': blocks.user
|
|
138
|
+
? `[foundations:user]\nThese are facts about the user. They are not your name, and they are not your persona.\n${blocks.user}`
|
|
139
|
+
: '',
|
|
140
|
+
'foundations:facts': blocks.facts
|
|
141
|
+
? `[foundations:facts]\nThese are also facts about the user, not your name.\n${blocks.facts}`
|
|
142
|
+
: '',
|
|
135
143
|
'foundations:state': blocks.state ? `[foundations:state]\n${blocks.state}` : '',
|
|
136
144
|
'foundations:skills': blocks.skills ? `[foundations:skills]\n${blocks.skills}` : '',
|
|
137
145
|
'foundations:revocation': blocks.notice ? `[foundations:revocation]\n${blocks.notice}` : '',
|
|
138
146
|
};
|
|
139
|
-
const snapshotHash = sha256(Object.entries(rendered)
|
|
147
|
+
const snapshotHash = sha256(Object.entries(rendered)
|
|
148
|
+
.map(([name, text]) => `${name}\n${text}`)
|
|
149
|
+
.join('\n'));
|
|
140
150
|
const previous = view.snapshot_hash;
|
|
141
151
|
let presence = view.presence;
|
|
142
152
|
if (previous === 'pending')
|
|
@@ -181,7 +191,9 @@ export function frameSoul(soul) {
|
|
|
181
191
|
const { name, body } = splitPersona(soul);
|
|
182
192
|
if (name === '' && body === '')
|
|
183
193
|
return '';
|
|
184
|
-
const lines = [
|
|
194
|
+
const lines = [
|
|
195
|
+
'The persona below is your identity. Enter this role in the first person and keep it for the whole conversation.',
|
|
196
|
+
];
|
|
185
197
|
if (name !== '') {
|
|
186
198
|
lines.push(`Your name is "${name}". This is your name, not the user's name, and not a nickname for the user.`);
|
|
187
199
|
lines.push('When the user asks what you are called, who you are, or how to address you, answer with this name only. Do not say you have no name. Do not substitute DeepSeek, Harness, the host product name, or a model id.');
|
package/dist/cron.js
CHANGED
|
@@ -33,7 +33,7 @@ export function nextCron(expr, afterMs, timeZone) {
|
|
|
33
33
|
const weekMatch = spec.weekday.has(parts.weekday);
|
|
34
34
|
const dayStar = spec.day.size === 31;
|
|
35
35
|
const weekStar = spec.weekday.size === 7;
|
|
36
|
-
const dayOk = dayStar && weekStar ? true : dayStar ? weekMatch : weekStar ? dayMatch :
|
|
36
|
+
const dayOk = dayStar && weekStar ? true : dayStar ? weekMatch : weekStar ? dayMatch : dayMatch || weekMatch;
|
|
37
37
|
if (dayOk)
|
|
38
38
|
return new Date(cursor).toISOString();
|
|
39
39
|
}
|
package/dist/desk.js
CHANGED
|
@@ -16,8 +16,8 @@ const SECRET_KEY = /token|secret|password|authorization|api[-_]?key|cookie/i;
|
|
|
16
16
|
* @param {(sessionId: string) => { kind?: string } | null | undefined} options.mark
|
|
17
17
|
* @param {(sessionId: string) => void | Promise<void>} options.hold
|
|
18
18
|
* @param {(sessionId: string) => void | Promise<void>} options.release
|
|
19
|
-
* @param {(endpoint: string, args: Record<string, unknown>, req:
|
|
20
|
-
* @param {(req:
|
|
19
|
+
* @param {(endpoint: string, args: Record<string, unknown>, req: DeskRequest) => Promise<{ status: number, body: RpcEnvelope }>} options.rpc
|
|
20
|
+
* @param {(req: DeskRequest) => Promise<Record<string, unknown>>} options.usage
|
|
21
21
|
*/
|
|
22
22
|
export function createDesk(options) {
|
|
23
23
|
const ledger = openLedger(options.ledgerFile);
|
|
@@ -34,7 +34,8 @@ export function createDesk(options) {
|
|
|
34
34
|
const sub = subpath(path);
|
|
35
35
|
if (sub === null)
|
|
36
36
|
return false;
|
|
37
|
-
if (method === 'GET' &&
|
|
37
|
+
if (method === 'GET' &&
|
|
38
|
+
(sub === '/health' || sub === '/sessions' || sub === '/tasks' || sub === '/usage' || sub === '/file'))
|
|
38
39
|
return true;
|
|
39
40
|
if (method === 'POST' && (sub === '/sessions' || sub === '/sessions/previews' || sub === '/tasks'))
|
|
40
41
|
return true;
|
|
@@ -48,7 +49,7 @@ export function createDesk(options) {
|
|
|
48
49
|
* @param {string} method
|
|
49
50
|
* @param {string} path
|
|
50
51
|
* @param {URL} url
|
|
51
|
-
* @param {
|
|
52
|
+
* @param {DeskRequest} req
|
|
52
53
|
*/
|
|
53
54
|
async handle(method, path, url, req) {
|
|
54
55
|
const sub = subpath(path) ?? '';
|
|
@@ -84,7 +85,7 @@ export function createDesk(options) {
|
|
|
84
85
|
},
|
|
85
86
|
};
|
|
86
87
|
/**
|
|
87
|
-
* @param {
|
|
88
|
+
* @param {DeskRequest} req
|
|
88
89
|
*/
|
|
89
90
|
async function health(req) {
|
|
90
91
|
const execution = await executionState(req);
|
|
@@ -94,7 +95,7 @@ export function createDesk(options) {
|
|
|
94
95
|
};
|
|
95
96
|
}
|
|
96
97
|
/**
|
|
97
|
-
* @param {
|
|
98
|
+
* @param {DeskRequest} req
|
|
98
99
|
*/
|
|
99
100
|
async function executionState(req) {
|
|
100
101
|
const catalog = await options.rpc('session/modelCatalog', {}, req);
|
|
@@ -105,12 +106,12 @@ export function createDesk(options) {
|
|
|
105
106
|
const failure = catalog.body?.result?.error?.message;
|
|
106
107
|
return {
|
|
107
108
|
ready: false,
|
|
108
|
-
reason: catalog.body?.result?.ok === true ? 'no_provider' :
|
|
109
|
+
reason: catalog.body?.result?.ok === true ? 'no_provider' : failure ? String(failure) : 'catalog_unreadable',
|
|
109
110
|
reachable: catalog.status > 0 && catalog.status < 500,
|
|
110
111
|
};
|
|
111
112
|
}
|
|
112
113
|
/**
|
|
113
|
-
* @param {
|
|
114
|
+
* @param {DeskRequest} req
|
|
114
115
|
* @param {Record<string, unknown>} body
|
|
115
116
|
*/
|
|
116
117
|
async function createSession(req, body) {
|
|
@@ -126,7 +127,10 @@ export function createDesk(options) {
|
|
|
126
127
|
: [];
|
|
127
128
|
const reusable = options.sessionCwd === ''
|
|
128
129
|
? undefined
|
|
129
|
-
: known.find(item => item?.blank === true &&
|
|
130
|
+
: known.find((item) => item?.blank === true &&
|
|
131
|
+
item?.running !== true &&
|
|
132
|
+
item?.cwd === options.sessionCwd &&
|
|
133
|
+
typeof item.sessionId === 'string');
|
|
130
134
|
const request = options.sessionCwd === ''
|
|
131
135
|
? {}
|
|
132
136
|
: reusable
|
|
@@ -156,10 +160,13 @@ export function createDesk(options) {
|
|
|
156
160
|
}
|
|
157
161
|
}
|
|
158
162
|
ledger.rememberSession(key, sessionId);
|
|
159
|
-
return {
|
|
163
|
+
return {
|
|
164
|
+
status: 201,
|
|
165
|
+
body: { sessionId, kind: 'bot', marker, reused: Boolean(reusable) && sessionId === reusable.sessionId },
|
|
166
|
+
};
|
|
160
167
|
}
|
|
161
168
|
/**
|
|
162
|
-
* @param {
|
|
169
|
+
* @param {DeskRequest} req
|
|
163
170
|
* @param {string} sessionId
|
|
164
171
|
*/
|
|
165
172
|
async function archiveBlank(req, sessionId) {
|
|
@@ -181,7 +188,7 @@ export function createDesk(options) {
|
|
|
181
188
|
return { status: 200, body: { sessionId, archivedSessionIds } };
|
|
182
189
|
}
|
|
183
190
|
/**
|
|
184
|
-
* @param {
|
|
191
|
+
* @param {DeskRequest} req
|
|
185
192
|
* @param {string} sessionId
|
|
186
193
|
*/
|
|
187
194
|
async function purgeBlank(req, sessionId) {
|
|
@@ -206,7 +213,10 @@ export function createDesk(options) {
|
|
|
206
213
|
});
|
|
207
214
|
}
|
|
208
215
|
catch (error) {
|
|
209
|
-
return {
|
|
216
|
+
return {
|
|
217
|
+
status: 500,
|
|
218
|
+
body: { error: 'purge_failed', message: error instanceof Error ? error.message : 'purge failed' },
|
|
219
|
+
};
|
|
210
220
|
}
|
|
211
221
|
sessionPreviews.forget(sessionId);
|
|
212
222
|
return { status: 200, body: { sessionId, purged: true } };
|
|
@@ -233,7 +243,7 @@ export function createDesk(options) {
|
|
|
233
243
|
return { status: 200, body: { ok: true, preview: saved.preview } };
|
|
234
244
|
}
|
|
235
245
|
/**
|
|
236
|
-
* @param {
|
|
246
|
+
* @param {DeskRequest} req
|
|
237
247
|
* @param {Record<string, unknown>} body
|
|
238
248
|
*/
|
|
239
249
|
async function createTask(req, body) {
|
|
@@ -254,7 +264,14 @@ export function createDesk(options) {
|
|
|
254
264
|
if (!remembered.created)
|
|
255
265
|
return { status: 200, body: { task: remembered.record, reused: true } };
|
|
256
266
|
if (!execution.ready) {
|
|
257
|
-
return {
|
|
267
|
+
return {
|
|
268
|
+
status: 409,
|
|
269
|
+
body: {
|
|
270
|
+
error: 'model_unconfigured',
|
|
271
|
+
task: remembered.record,
|
|
272
|
+
execution: { ready: false, reason: execution.reason },
|
|
273
|
+
},
|
|
274
|
+
};
|
|
258
275
|
}
|
|
259
276
|
const delivered = await withPromptLock(sessionId, () => deliverPrompt(req, sessionId, text, remembered.record.id));
|
|
260
277
|
if (!delivered.ok) {
|
|
@@ -263,12 +280,16 @@ export function createDesk(options) {
|
|
|
263
280
|
reason: delivered.reason,
|
|
264
281
|
upstreamCode: delivered.upstreamCode,
|
|
265
282
|
});
|
|
266
|
-
|
|
283
|
+
const failStatus = delivered.status;
|
|
284
|
+
return {
|
|
285
|
+
status: typeof failStatus === 'number' ? failStatus : 502,
|
|
286
|
+
body: { error: delivered.error, task: updated },
|
|
287
|
+
};
|
|
267
288
|
}
|
|
268
289
|
return { status: 202, body: { task: remembered.record, reused: false, interrupted: delivered.interrupted } };
|
|
269
290
|
}
|
|
270
291
|
/**
|
|
271
|
-
* @param {
|
|
292
|
+
* @param {DeskRequest} req
|
|
272
293
|
* @param {string} id
|
|
273
294
|
*/
|
|
274
295
|
async function cancelTask(req, id) {
|
|
@@ -286,7 +307,7 @@ export function createDesk(options) {
|
|
|
286
307
|
return { status: result.body?.result?.ok === true ? 200 : 502, body: { task: updated } };
|
|
287
308
|
}
|
|
288
309
|
/**
|
|
289
|
-
* @param {
|
|
310
|
+
* @param {DeskRequest} req
|
|
290
311
|
* @param {URL} url
|
|
291
312
|
*/
|
|
292
313
|
async function filePreview(req, url) {
|
|
@@ -357,7 +378,7 @@ export function createDesk(options) {
|
|
|
357
378
|
}
|
|
358
379
|
}
|
|
359
380
|
/**
|
|
360
|
-
* @param {
|
|
381
|
+
* @param {DeskRequest} req
|
|
361
382
|
* @param {string} sessionId
|
|
362
383
|
* @returns {Promise<boolean | null>}
|
|
363
384
|
*/
|
|
@@ -365,13 +386,13 @@ export function createDesk(options) {
|
|
|
365
386
|
const listed = await options.rpc('session/list', { _request: {} }, req);
|
|
366
387
|
if (listed.body?.result?.ok !== true || !Array.isArray(listed.body.result.value?.items))
|
|
367
388
|
return null;
|
|
368
|
-
const item = listed.body.result.value.items.find(entry => entry?.sessionId === sessionId);
|
|
389
|
+
const item = listed.body.result.value.items.find((entry) => entry?.sessionId === sessionId);
|
|
369
390
|
return item?.running === true;
|
|
370
391
|
}
|
|
371
392
|
/**
|
|
372
393
|
* Idle sessions queue. A live bot turn is cancelled, then the new text is a new turn.
|
|
373
394
|
* The cancel is only the main session. Worker sessions are not addressed here.
|
|
374
|
-
* @param {
|
|
395
|
+
* @param {DeskRequest} req
|
|
375
396
|
* @param {string} sessionId
|
|
376
397
|
* @param {string} text
|
|
377
398
|
* @param {string} requestId
|
|
@@ -379,7 +400,13 @@ export function createDesk(options) {
|
|
|
379
400
|
async function deliverPrompt(req, sessionId, text, requestId) {
|
|
380
401
|
const running = await sessionRunning(req, sessionId);
|
|
381
402
|
if (running === null) {
|
|
382
|
-
return {
|
|
403
|
+
return {
|
|
404
|
+
ok: false,
|
|
405
|
+
status: 502,
|
|
406
|
+
error: 'session_unreadable',
|
|
407
|
+
reason: 'Could not tell whether the session is still running.',
|
|
408
|
+
upstreamCode: '',
|
|
409
|
+
};
|
|
383
410
|
}
|
|
384
411
|
let interrupted = false;
|
|
385
412
|
if (running && (options.isBot(sessionId) || botMarked(sessionId))) {
|
|
@@ -430,7 +457,7 @@ function subpath(path) {
|
|
|
430
457
|
return path.slice(API.length);
|
|
431
458
|
}
|
|
432
459
|
/**
|
|
433
|
-
* @param {
|
|
460
|
+
* @param {DeskRequest} req
|
|
434
461
|
* @param {Record<string, unknown>} body
|
|
435
462
|
*/
|
|
436
463
|
function idempotencyOf(req, body) {
|
|
@@ -480,7 +507,7 @@ function redactSecrets(value) {
|
|
|
480
507
|
return value;
|
|
481
508
|
}
|
|
482
509
|
/**
|
|
483
|
-
* @param {
|
|
510
|
+
* @param {DeskRequest} req
|
|
484
511
|
* @returns {Promise<Record<string, unknown>>}
|
|
485
512
|
*/
|
|
486
513
|
function readJson(req) {
|