@thready-web/dsh-bot-plugin 0.0.0-stage → 0.1.0-beta.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/README.md +45 -2
- package/client.js +646 -0
- package/dist/cdc.js +73 -0
- package/dist/cli.js +352 -0
- package/dist/context.js +262 -0
- package/dist/cron.js +98 -0
- package/dist/desk-ledger.js +91 -0
- package/dist/desk.js +518 -0
- package/dist/engine.js +733 -0
- package/dist/errors.js +46 -0
- package/dist/fs-safe.js +100 -0
- package/dist/http-plugin.js +33 -0
- package/dist/http.js +593 -0
- package/dist/inbox.js +194 -0
- package/dist/index.js +411 -0
- package/dist/live-diff.js +188 -0
- package/dist/live-snapshot.js +152 -0
- package/dist/provision.js +44 -0
- package/dist/router-plugin.js +14 -0
- package/dist/runtime-registry.js +36 -0
- package/dist/session-files.js +111 -0
- package/dist/session-previews.js +111 -0
- package/dist/store.js +598 -0
- package/dist/tools.js +357 -0
- package/dist/triggers.js +874 -0
- package/dist/work-admit.js +128 -0
- package/dist/work-child.js +73 -0
- package/dist/work-durable.js +53 -0
- package/dist/work-http.js +287 -0
- package/dist/work-ledger.js +217 -0
- package/dist/work-mock-host.js +187 -0
- package/dist/work-mock.js +131 -0
- package/dist/work-tickets.js +1042 -0
- package/dist/work-tools.js +150 -0
- package/dist/work-worker.js +1108 -0
- package/fixtures/mock-llm.mjs +267 -0
- package/package.json +54 -4
- package/public/assets/index-Be82iGwe.css +1 -0
- package/public/assets/index-ByU9a3Lh.js +61 -0
- package/public/index.html +14 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { toolError } from "./errors.js";
|
|
2
|
+
const OUTPUT = {
|
|
3
|
+
schema: {
|
|
4
|
+
type: 'object',
|
|
5
|
+
properties: { ok: { type: 'boolean' } },
|
|
6
|
+
required: ['ok'],
|
|
7
|
+
},
|
|
8
|
+
render(_args, value) {
|
|
9
|
+
return [{ type: 'text', text: JSON.stringify(value) }];
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Bot tools plus the worker report. Execute checks the host session.
|
|
14
|
+
* Model arguments never supply owner, attempt, or fence.
|
|
15
|
+
* @param {ReturnType<import('./work-worker.js').createWorkRuntime>} work
|
|
16
|
+
* @param {import('./engine.js').Engine} engine
|
|
17
|
+
*/
|
|
18
|
+
export function workToolDefinitions(work, engine) {
|
|
19
|
+
return [
|
|
20
|
+
tool('foundations_dispatch', 'Hand a long job to a worker session. Available only on a bot. status=accepted means received, not yet dispatched. status=enqueued means it entered the execution queue, not that it has started. The return value is never started. ownerSessionId is ignored.', {
|
|
21
|
+
type: 'object',
|
|
22
|
+
properties: {
|
|
23
|
+
briefing: { type: 'string' },
|
|
24
|
+
idempotencyKey: { type: 'string' },
|
|
25
|
+
budget: {
|
|
26
|
+
type: 'object',
|
|
27
|
+
description: 'Time and token estimate for this ticket. When omitted, the host estimates from the task text. It cannot exceed the host ceiling.',
|
|
28
|
+
properties: {
|
|
29
|
+
wallMs: { type: 'integer', description: 'Expected maximum runtime in milliseconds.' },
|
|
30
|
+
maxTokens: { type: 'integer', description: 'Expected maximum tokens.' },
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
correlationId: { type: 'string' },
|
|
34
|
+
ownerSessionId: { type: 'string', description: 'Ignored. The host uses the current session.' },
|
|
35
|
+
parentTicketId: { type: 'string', description: 'The MVP rejects a non-empty value.' },
|
|
36
|
+
},
|
|
37
|
+
required: ['briefing'],
|
|
38
|
+
}, (args, hostId) => work.dispatch(hostId, args), 'bot'),
|
|
39
|
+
tool('foundations_supply', 'Write the user supplement into the next briefing generation. The host binds the ticket and ignores owner, attempt, and fence.', {
|
|
40
|
+
type: 'object',
|
|
41
|
+
properties: {
|
|
42
|
+
text: { type: 'string' },
|
|
43
|
+
ticketId: { type: 'string' },
|
|
44
|
+
expectedRevision: { type: 'integer' },
|
|
45
|
+
ownerSessionId: { type: 'string', description: 'Ignored.' },
|
|
46
|
+
},
|
|
47
|
+
required: ['text'],
|
|
48
|
+
}, (args, hostId) => work.supply(hostId, args), 'bot'),
|
|
49
|
+
tool('foundations_redirect', 'Redirect with a new briefing generation. In-flight old reports become stale. Running tools are not stopped automatically.', {
|
|
50
|
+
type: 'object',
|
|
51
|
+
properties: {
|
|
52
|
+
text: { type: 'string' },
|
|
53
|
+
ticketId: { type: 'string' },
|
|
54
|
+
expectedRevision: { type: 'integer' },
|
|
55
|
+
ownerSessionId: { type: 'string', description: 'Ignored.' },
|
|
56
|
+
},
|
|
57
|
+
required: ['text'],
|
|
58
|
+
}, (args, hostId) => work.redirect(hostId, args), 'bot'),
|
|
59
|
+
tool('foundations_cancel', 'Cancel the ticket. Ticket notices that have not been claimed are removed from the inbox. It does not start again on its own.', {
|
|
60
|
+
type: 'object',
|
|
61
|
+
properties: {
|
|
62
|
+
ticketId: { type: 'string' },
|
|
63
|
+
note: { type: 'string' },
|
|
64
|
+
expectedRevision: { type: 'integer' },
|
|
65
|
+
ownerSessionId: { type: 'string', description: 'Ignored.' },
|
|
66
|
+
},
|
|
67
|
+
}, (args, hostId) => work.cancelTicket(hostId, args), 'bot'),
|
|
68
|
+
tool('foundations_grant', 'Grant more time or tokens to an unfinished ticket. wallMs and maxTokens are amounts to add, not a new total. A budget-exhausted notice is not a failure. deny=true refuses the grant and stops this round.', {
|
|
69
|
+
type: 'object',
|
|
70
|
+
properties: {
|
|
71
|
+
ticketId: { type: 'string' },
|
|
72
|
+
wallMs: { type: 'integer', description: 'Milliseconds to add.' },
|
|
73
|
+
maxTokens: { type: 'integer', description: 'Tokens to add.' },
|
|
74
|
+
deny: { type: 'boolean', description: 'Refuse the grant and stop.' },
|
|
75
|
+
ownerSessionId: { type: 'string', description: 'Ignored.' },
|
|
76
|
+
},
|
|
77
|
+
required: ['ticketId'],
|
|
78
|
+
}, (args, hostId) => work.grant(hostId, args), 'bot'),
|
|
79
|
+
tool('foundations_retry', 'When the user explicitly asks, open a new attempt for a failed or cancelled ticket. Do not call this automatically.', {
|
|
80
|
+
type: 'object',
|
|
81
|
+
properties: {
|
|
82
|
+
ticketId: { type: 'string' },
|
|
83
|
+
expectedRevision: { type: 'integer' },
|
|
84
|
+
ownerSessionId: { type: 'string', description: 'Ignored.' },
|
|
85
|
+
},
|
|
86
|
+
}, (args, hostId) => work.retry(hostId, args), 'bot'),
|
|
87
|
+
tool('foundations_publish', 'Record one intent to publish to the user. Each result has one row. The user has not seen it yet. Then write the reply in your own words.', {
|
|
88
|
+
type: 'object',
|
|
89
|
+
properties: {
|
|
90
|
+
resultEventId: { type: 'string' },
|
|
91
|
+
text: { type: 'string' },
|
|
92
|
+
ownerSessionId: { type: 'string', description: 'Ignored.' },
|
|
93
|
+
},
|
|
94
|
+
required: ['resultEventId', 'text'],
|
|
95
|
+
}, (args, hostId, exec) => work.publish(hostId, { ...args, turn: exec?.turn ?? null }), 'bot'),
|
|
96
|
+
tool('foundations_reject', 'Reject the current candidate. That result cannot be published afterward.', {
|
|
97
|
+
type: 'object',
|
|
98
|
+
properties: {
|
|
99
|
+
resultEventId: { type: 'string' },
|
|
100
|
+
ownerSessionId: { type: 'string', description: 'Ignored.' },
|
|
101
|
+
},
|
|
102
|
+
required: ['resultEventId'],
|
|
103
|
+
}, (args, hostId) => work.reject(hostId, args), 'bot'),
|
|
104
|
+
tool('foundations_report', 'The worker reports progress, a question, an artifact, a result, or a failure. This only writes the ledger. ticket, attempt, fence, and owner are discarded.', {
|
|
105
|
+
type: 'object',
|
|
106
|
+
properties: {
|
|
107
|
+
kind: { type: 'string', enum: ['progress', 'question', 'artifact', 'result', 'failure'] },
|
|
108
|
+
text: { type: 'string' },
|
|
109
|
+
ticketId: { type: 'string', description: 'Ignored.' },
|
|
110
|
+
attemptId: { type: 'string', description: 'Ignored.' },
|
|
111
|
+
fencingToken: { type: 'integer', description: 'Ignored.' },
|
|
112
|
+
briefingRevision: { type: 'integer', description: 'Ignored.' },
|
|
113
|
+
ownerSessionId: { type: 'string', description: 'Ignored.' },
|
|
114
|
+
},
|
|
115
|
+
required: ['kind', 'text'],
|
|
116
|
+
}, (args, hostId) => {
|
|
117
|
+
if (engine.isBot(hostId))
|
|
118
|
+
return toolError('FORBIDDEN', 'The main session cannot report in place of the worker.');
|
|
119
|
+
return work.report(hostId, args);
|
|
120
|
+
}, 'worker'),
|
|
121
|
+
];
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* @param {string} name
|
|
125
|
+
* @param {string} description
|
|
126
|
+
* @param {Record<string, unknown>} parameters
|
|
127
|
+
* @param {(args: Record<string, unknown>, hostId: string, exec: { turn?: number }) => Promise<unknown>} run
|
|
128
|
+
* @param {'bot' | 'worker'} who
|
|
129
|
+
*/
|
|
130
|
+
function tool(name, description, parameters, run, who) {
|
|
131
|
+
return {
|
|
132
|
+
name,
|
|
133
|
+
description,
|
|
134
|
+
parameters,
|
|
135
|
+
output: OUTPUT,
|
|
136
|
+
audience: who,
|
|
137
|
+
async execute(args, exec) {
|
|
138
|
+
const hostId = exec?.agent?.id;
|
|
139
|
+
if (typeof hostId !== 'string' || hostId === '')
|
|
140
|
+
return toolError('UNAVAILABLE', 'The host did not bind a sessionId.');
|
|
141
|
+
try {
|
|
142
|
+
return await run(args ?? {}, hostId, exec ?? {});
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
const code = error && typeof error === 'object' && 'code' in error ? String(error.code) : 'STORE_FAILURE';
|
|
146
|
+
return toolError(code === 'CAS_CONFLICT' ? 'CAS_CONFLICT' : 'STORE_FAILURE', error instanceof Error ? error.message : String(error));
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|