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