@deliverd/sdk 0.11.0 → 0.12.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/README.md +39 -0
- package/dist/dev.d.ts.map +1 -1
- package/dist/dev.js +398 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +13 -0
- package/dist/released.d.ts +1 -1
- package/dist/released.d.ts.map +1 -1
- package/dist/released.js +1262 -0
- package/dist/tasks.d.ts +95 -0
- package/dist/tasks.d.ts.map +1 -0
- package/dist/tasks.js +254 -0
- package/dist/types.d.ts +341 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/dev.ts +407 -1
- package/src/index.ts +4 -0
- package/src/messages.ts +13 -0
- package/src/released.ts +1262 -0
- package/src/tasks.ts +312 -0
- package/src/types.ts +398 -1
package/src/tasks.ts
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { listOrCollect, type PageOf } from "./paging.js";
|
|
2
|
+
import type { HttpClient } from "./http.js";
|
|
3
|
+
import type {
|
|
4
|
+
AddFindingInput,
|
|
5
|
+
AppliedSideTask,
|
|
6
|
+
ApplySideTaskInput,
|
|
7
|
+
CancelTaskInput,
|
|
8
|
+
CompleteTaskInput,
|
|
9
|
+
CreateSideTaskInput,
|
|
10
|
+
CreateTaskInput,
|
|
11
|
+
DecisionApproval,
|
|
12
|
+
LinkTasksInput,
|
|
13
|
+
ListTasksInput,
|
|
14
|
+
RequestDecisionApprovalInput,
|
|
15
|
+
TaskContext,
|
|
16
|
+
TaskData,
|
|
17
|
+
TaskFinding,
|
|
18
|
+
TaskGraph,
|
|
19
|
+
TaskLinkResult,
|
|
20
|
+
UpdateTaskInput,
|
|
21
|
+
} from "./types.js";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Task Graph: what the work is for, kept apart from the conversation doing it.
|
|
25
|
+
*
|
|
26
|
+
* An agent deep in a debugging session forgets the objective it started
|
|
27
|
+
* from, because the objective is a paragraph thousands of tokens back. A task
|
|
28
|
+
* keeps it somewhere the agent can ask for: `task.context()` returns the
|
|
29
|
+
* objective first, always, then where this task stands, what is settled, and
|
|
30
|
+
* one paragraph to say back to itself.
|
|
31
|
+
*
|
|
32
|
+
* A problem that would take over the thread is branched into a side task with
|
|
33
|
+
* the facts it needs (not the transcript), completed with a structured
|
|
34
|
+
* result, and applied back to the parent — which is how the main thread gets
|
|
35
|
+
* the answer without the hour it took.
|
|
36
|
+
*
|
|
37
|
+
* Nothing here asks a person anything by itself. A decision is recorded as a
|
|
38
|
+
* suggestion, and `requestDecisionApproval()` is how one is put to somebody.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
const enc = encodeURIComponent;
|
|
42
|
+
|
|
43
|
+
export class Task {
|
|
44
|
+
constructor(
|
|
45
|
+
private readonly http: HttpClient,
|
|
46
|
+
private data: TaskData
|
|
47
|
+
) {}
|
|
48
|
+
|
|
49
|
+
get id(): string { return this.data.id; }
|
|
50
|
+
get kind(): TaskData["kind"] { return this.data.kind; }
|
|
51
|
+
get status(): TaskData["status"] { return this.data.status; }
|
|
52
|
+
/** The page a person can open. */
|
|
53
|
+
get url(): string { return this.data.url; }
|
|
54
|
+
get title(): string { return this.data.title; }
|
|
55
|
+
/** What the work is for: the objective's purpose, or a side task's goal. */
|
|
56
|
+
get objective(): string { return this.data.objective; }
|
|
57
|
+
get state(): TaskData["state"] { return this.data.state; }
|
|
58
|
+
get version(): number { return this.data.version; }
|
|
59
|
+
get rootTaskId(): string { return this.data.rootTaskId; }
|
|
60
|
+
get parentTaskId(): string | null { return this.data.parentTaskId; }
|
|
61
|
+
get result(): TaskData["result"] { return this.data.result; }
|
|
62
|
+
get outcome(): TaskData["outcome"] { return this.data.outcome; }
|
|
63
|
+
/** Present on a single read; empty otherwise. */
|
|
64
|
+
get findings(): NonNullable<TaskData["findings"]> { return this.data.findings ?? []; }
|
|
65
|
+
/** Present on a single read; empty otherwise. */
|
|
66
|
+
get children(): NonNullable<TaskData["children"]> { return this.data.children ?? []; }
|
|
67
|
+
/** True when `create()` returned an open objective you had already started under the same `externalId`. */
|
|
68
|
+
get resumed(): boolean { return this.data.resumed === true; }
|
|
69
|
+
|
|
70
|
+
get isSideTask(): boolean { return this.data.kind !== "objective"; }
|
|
71
|
+
/** Neither completed nor cancelled. */
|
|
72
|
+
get active(): boolean { return this.data.status !== "completed" && this.data.status !== "cancelled"; }
|
|
73
|
+
get completed(): boolean { return this.data.status === "completed"; }
|
|
74
|
+
get cancelled(): boolean { return this.data.status === "cancelled"; }
|
|
75
|
+
|
|
76
|
+
toJSON(): TaskData { return this.data; }
|
|
77
|
+
|
|
78
|
+
async refresh(signal?: AbortSignal): Promise<this> {
|
|
79
|
+
this.data = await this.http.request<TaskData>({ method: "GET", path: `/tasks/${enc(this.data.id)}`, signal });
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** What to read instead of the history. Call it whenever you have lost the thread. */
|
|
84
|
+
context(signal?: AbortSignal): Promise<TaskContext> {
|
|
85
|
+
return this.http.request<TaskContext>({ method: "GET", path: `/tasks/${enc(this.data.id)}/context`, signal });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The whole tree this task belongs to, from its objective down. */
|
|
89
|
+
graph(signal?: AbortSignal): Promise<TaskGraph> {
|
|
90
|
+
return this.http.request<TaskGraph>({ method: "GET", path: `/tasks/${enc(this.data.id)}/graph`, signal });
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Change the title, status or working state. */
|
|
94
|
+
async update(input: UpdateTaskInput, signal?: AbortSignal): Promise<this> {
|
|
95
|
+
this.data = await this.http.request<TaskData>({
|
|
96
|
+
method: "PATCH",
|
|
97
|
+
path: `/tasks/${enc(this.data.id)}`,
|
|
98
|
+
body: input,
|
|
99
|
+
signal,
|
|
100
|
+
});
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Branch a problem out of this task so it does not take over the thread. */
|
|
105
|
+
async createSideTask(input: CreateSideTaskInput, signal?: AbortSignal): Promise<Task> {
|
|
106
|
+
const data = await this.http.request<TaskData>({
|
|
107
|
+
method: "POST",
|
|
108
|
+
path: `/tasks/${enc(this.data.id)}/side-tasks`,
|
|
109
|
+
body: input,
|
|
110
|
+
signal,
|
|
111
|
+
});
|
|
112
|
+
return new Task(this.http, data);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Record what was tested, seen or concluded. A decision is recorded as a suggestion. */
|
|
116
|
+
addFinding(input: AddFindingInput, signal?: AbortSignal): Promise<TaskFinding> {
|
|
117
|
+
return this.http.request<TaskFinding>({
|
|
118
|
+
method: "POST",
|
|
119
|
+
path: `/tasks/${enc(this.data.id)}/findings`,
|
|
120
|
+
body: input,
|
|
121
|
+
signal,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Put a suggested decision on this task to a person. */
|
|
126
|
+
requestDecisionApproval(
|
|
127
|
+
findingId: string,
|
|
128
|
+
input: RequestDecisionApprovalInput = {},
|
|
129
|
+
signal?: AbortSignal
|
|
130
|
+
): Promise<DecisionApproval> {
|
|
131
|
+
return this.http.request<DecisionApproval>({
|
|
132
|
+
method: "POST",
|
|
133
|
+
path: `/tasks/${enc(this.data.id)}/findings/${enc(findingId)}/approval`,
|
|
134
|
+
body: input,
|
|
135
|
+
signal,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Finish it with a structured result. A side task's result then waits to be applied. */
|
|
140
|
+
async complete(input: CompleteTaskInput, signal?: AbortSignal): Promise<this> {
|
|
141
|
+
this.data = await this.http.request<TaskData>({
|
|
142
|
+
method: "POST",
|
|
143
|
+
path: `/tasks/${enc(this.data.id)}/complete`,
|
|
144
|
+
body: input,
|
|
145
|
+
signal,
|
|
146
|
+
});
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Carry this finished side task's result into its parent — or record that it
|
|
152
|
+
* was kept for reference, or discarded. Returns the parent's fresh context,
|
|
153
|
+
* which is what to read next.
|
|
154
|
+
*/
|
|
155
|
+
async apply(input: ApplySideTaskInput = {}, signal?: AbortSignal): Promise<AppliedSideTask> {
|
|
156
|
+
const out = await this.http.request<AppliedSideTask>({
|
|
157
|
+
method: "POST",
|
|
158
|
+
path: `/tasks/${enc(this.data.id)}/apply`,
|
|
159
|
+
body: input,
|
|
160
|
+
signal,
|
|
161
|
+
});
|
|
162
|
+
this.data = out.sideTask;
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Open a completed task again. Its result is kept in `previousResults`. */
|
|
167
|
+
async reopen(signal?: AbortSignal): Promise<this> {
|
|
168
|
+
this.data = await this.http.request<TaskData>({
|
|
169
|
+
method: "POST",
|
|
170
|
+
path: `/tasks/${enc(this.data.id)}/reopen`,
|
|
171
|
+
body: {},
|
|
172
|
+
signal,
|
|
173
|
+
});
|
|
174
|
+
return this;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Call it off. It stays in the tree as a record of what was tried. */
|
|
178
|
+
async cancel(input: CancelTaskInput = {}, signal?: AbortSignal): Promise<this> {
|
|
179
|
+
this.data = await this.http.request<TaskData>({
|
|
180
|
+
method: "POST",
|
|
181
|
+
path: `/tasks/${enc(this.data.id)}/cancel`,
|
|
182
|
+
body: input,
|
|
183
|
+
signal,
|
|
184
|
+
});
|
|
185
|
+
return this;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Relate this task to another: it depends on, blocks, supersedes… */
|
|
189
|
+
link(input: LinkTasksInput, signal?: AbortSignal): Promise<TaskLinkResult> {
|
|
190
|
+
return this.http.request<TaskLinkResult>({
|
|
191
|
+
method: "POST",
|
|
192
|
+
path: `/tasks/${enc(this.data.id)}/links`,
|
|
193
|
+
body: input,
|
|
194
|
+
signal,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export class Tasks {
|
|
200
|
+
constructor(private readonly http: HttpClient) {}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Start an objective. With an `externalId`, an open objective you already
|
|
204
|
+
* started under it comes back instead (`task.resumed`), so a restarted
|
|
205
|
+
* agent picks its goal up rather than starting a second.
|
|
206
|
+
*/
|
|
207
|
+
async create(input: CreateTaskInput, signal?: AbortSignal): Promise<Task> {
|
|
208
|
+
const data = await this.http.request<TaskData>({ method: "POST", path: "/tasks", body: input, signal });
|
|
209
|
+
return new Task(this.http, data);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** A task with its path, children, findings and links. */
|
|
213
|
+
async get(id: string, signal?: AbortSignal): Promise<Task> {
|
|
214
|
+
const data = await this.http.request<TaskData>({ method: "GET", path: `/tasks/${enc(id)}`, signal });
|
|
215
|
+
return new Task(this.http, data);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Objectives, most recently active first. Side tasks are reached through
|
|
220
|
+
* the objective they belong to.
|
|
221
|
+
*
|
|
222
|
+
* With no `limit` this is every one of them; with a `limit` it is one page,
|
|
223
|
+
* and `listPage` hands back the cursor to continue from.
|
|
224
|
+
*/
|
|
225
|
+
async list(input: ListTasksInput = {}, signal?: AbortSignal): Promise<Task[]> {
|
|
226
|
+
return listOrCollect(input, async (q: { limit?: number; cursor?: string }) => {
|
|
227
|
+
const page = await this.listPage({ ...input, ...q }, signal);
|
|
228
|
+
return { items: page.items, nextCursor: page.nextCursor };
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** One page, and the cursor to continue from — null when it is the end. */
|
|
233
|
+
async listPage(input: ListTasksInput = {}, signal?: AbortSignal): Promise<PageOf<Task>> {
|
|
234
|
+
const { tasks, nextCursor } = await this.http.request<{ tasks: TaskData[]; nextCursor: string | null }>({
|
|
235
|
+
method: "GET",
|
|
236
|
+
path: "/tasks",
|
|
237
|
+
query: {
|
|
238
|
+
status: input.status,
|
|
239
|
+
externalId: input.externalId,
|
|
240
|
+
q: input.q,
|
|
241
|
+
limit: input.limit,
|
|
242
|
+
cursor: input.cursor,
|
|
243
|
+
},
|
|
244
|
+
signal,
|
|
245
|
+
});
|
|
246
|
+
return { items: tasks.map((t) => new Task(this.http, t)), nextCursor };
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
context(id: string, signal?: AbortSignal): Promise<TaskContext> {
|
|
250
|
+
return this.http.request<TaskContext>({ method: "GET", path: `/tasks/${enc(id)}/context`, signal });
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
graph(id: string, signal?: AbortSignal): Promise<TaskGraph> {
|
|
254
|
+
return this.http.request<TaskGraph>({ method: "GET", path: `/tasks/${enc(id)}/graph`, signal });
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async update(id: string, input: UpdateTaskInput, signal?: AbortSignal): Promise<Task> {
|
|
258
|
+
const data = await this.http.request<TaskData>({ method: "PATCH", path: `/tasks/${enc(id)}`, body: input, signal });
|
|
259
|
+
return new Task(this.http, data);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
async createSideTask(parentId: string, input: CreateSideTaskInput, signal?: AbortSignal): Promise<Task> {
|
|
263
|
+
const data = await this.http.request<TaskData>({
|
|
264
|
+
method: "POST",
|
|
265
|
+
path: `/tasks/${enc(parentId)}/side-tasks`,
|
|
266
|
+
body: input,
|
|
267
|
+
signal,
|
|
268
|
+
});
|
|
269
|
+
return new Task(this.http, data);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
addFinding(id: string, input: AddFindingInput, signal?: AbortSignal): Promise<TaskFinding> {
|
|
273
|
+
return this.http.request<TaskFinding>({ method: "POST", path: `/tasks/${enc(id)}/findings`, body: input, signal });
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
requestDecisionApproval(
|
|
277
|
+
id: string,
|
|
278
|
+
findingId: string,
|
|
279
|
+
input: RequestDecisionApprovalInput = {},
|
|
280
|
+
signal?: AbortSignal
|
|
281
|
+
): Promise<DecisionApproval> {
|
|
282
|
+
return this.http.request<DecisionApproval>({
|
|
283
|
+
method: "POST",
|
|
284
|
+
path: `/tasks/${enc(id)}/findings/${enc(findingId)}/approval`,
|
|
285
|
+
body: input,
|
|
286
|
+
signal,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async complete(id: string, input: CompleteTaskInput, signal?: AbortSignal): Promise<Task> {
|
|
291
|
+
const data = await this.http.request<TaskData>({ method: "POST", path: `/tasks/${enc(id)}/complete`, body: input, signal });
|
|
292
|
+
return new Task(this.http, data);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
apply(id: string, input: ApplySideTaskInput = {}, signal?: AbortSignal): Promise<AppliedSideTask> {
|
|
296
|
+
return this.http.request<AppliedSideTask>({ method: "POST", path: `/tasks/${enc(id)}/apply`, body: input, signal });
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
async reopen(id: string, signal?: AbortSignal): Promise<Task> {
|
|
300
|
+
const data = await this.http.request<TaskData>({ method: "POST", path: `/tasks/${enc(id)}/reopen`, body: {}, signal });
|
|
301
|
+
return new Task(this.http, data);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
async cancel(id: string, input: CancelTaskInput = {}, signal?: AbortSignal): Promise<Task> {
|
|
305
|
+
const data = await this.http.request<TaskData>({ method: "POST", path: `/tasks/${enc(id)}/cancel`, body: input, signal });
|
|
306
|
+
return new Task(this.http, data);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
link(id: string, input: LinkTasksInput, signal?: AbortSignal): Promise<TaskLinkResult> {
|
|
310
|
+
return this.http.request<TaskLinkResult>({ method: "POST", path: `/tasks/${enc(id)}/links`, body: input, signal });
|
|
311
|
+
}
|
|
312
|
+
}
|