@pxlabz/tasq-sdk 0.1.31 → 0.2.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 +6 -36
- package/index.d.ts +59 -0
- package/index.js +11 -0
- package/package.json +11 -26
- package/dist/index.d.ts +0 -5541
- package/dist/index.js +0 -639
- package/dist/index.js.map +0 -1
package/dist/index.js
DELETED
|
@@ -1,639 +0,0 @@
|
|
|
1
|
-
// src/prefixes.ts
|
|
2
|
-
var AGENT_KEY_PREFIX = "tq_ag_";
|
|
3
|
-
var USER_TOKEN_PREFIX = "tq_us_";
|
|
4
|
-
|
|
5
|
-
// src/errors.ts
|
|
6
|
-
var TasqApiError = class extends Error {
|
|
7
|
-
code;
|
|
8
|
-
status;
|
|
9
|
-
details;
|
|
10
|
-
constructor(status, body) {
|
|
11
|
-
super(body.message);
|
|
12
|
-
this.name = "TasqApiError";
|
|
13
|
-
this.code = body.code;
|
|
14
|
-
this.status = status;
|
|
15
|
-
this.details = body.details;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
var TasqRateLimitError = class extends TasqApiError {
|
|
19
|
-
retryAfterSeconds;
|
|
20
|
-
resetAt;
|
|
21
|
-
limit;
|
|
22
|
-
remaining;
|
|
23
|
-
constructor(status, body, retryAfterHeader) {
|
|
24
|
-
super(status, body);
|
|
25
|
-
this.name = "TasqRateLimitError";
|
|
26
|
-
const details = body.details ?? {};
|
|
27
|
-
this.limit = details.limit;
|
|
28
|
-
this.remaining = details.remaining;
|
|
29
|
-
this.resetAt = details.resetAt === void 0 ? void 0 : new Date(details.resetAt);
|
|
30
|
-
const fromHeader = Number(retryAfterHeader);
|
|
31
|
-
if (retryAfterHeader !== null && Number.isFinite(fromHeader)) {
|
|
32
|
-
this.retryAfterSeconds = Math.max(0, fromHeader);
|
|
33
|
-
} else if (this.resetAt !== void 0) {
|
|
34
|
-
const ms = this.resetAt.getTime() - Date.now();
|
|
35
|
-
this.retryAfterSeconds = Math.max(0, Math.ceil(ms / 1e3));
|
|
36
|
-
} else {
|
|
37
|
-
this.retryAfterSeconds = 0;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
var TasqValidationError = class extends TasqApiError {
|
|
42
|
-
issues;
|
|
43
|
-
constructor(status, body) {
|
|
44
|
-
super(status, body);
|
|
45
|
-
this.name = "TasqValidationError";
|
|
46
|
-
this.issues = Array.isArray(body.details) ? body.details : [];
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var TasqPolicyDeniedError = class extends TasqApiError {
|
|
50
|
-
/** The rejected action name, when the API reported one. */
|
|
51
|
-
action;
|
|
52
|
-
/** The policy version quoted in the message, when the API quoted one. */
|
|
53
|
-
policyVersion;
|
|
54
|
-
constructor(status, body) {
|
|
55
|
-
super(status, body);
|
|
56
|
-
this.name = "TasqPolicyDeniedError";
|
|
57
|
-
this.action = actionFromDetails(body.details);
|
|
58
|
-
this.policyVersion = policyVersionFromMessage(body.message);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
function actionFromDetails(details) {
|
|
62
|
-
if (!Array.isArray(details)) return void 0;
|
|
63
|
-
const issues = details;
|
|
64
|
-
for (const issue of issues) {
|
|
65
|
-
if (issue.path[0] === "action") return issue.message;
|
|
66
|
-
}
|
|
67
|
-
return void 0;
|
|
68
|
-
}
|
|
69
|
-
function policyVersionFromMessage(message) {
|
|
70
|
-
const match = /policy v(?:ersion )?(\d+)/i.exec(message);
|
|
71
|
-
if (!match?.[1]) return void 0;
|
|
72
|
-
return Number(match[1]);
|
|
73
|
-
}
|
|
74
|
-
function noCredentialError() {
|
|
75
|
-
return new TasqApiError(0, {
|
|
76
|
-
code: "NO_CREDENTIAL",
|
|
77
|
-
message: "No credential configured. Run `tasq auth login`, or set TASQ_API_KEY."
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
function toTasqError(status, body, retryAfterHeader) {
|
|
81
|
-
if (status === 429 || body.code === "RATE_LIMITED") {
|
|
82
|
-
return new TasqRateLimitError(status, body, retryAfterHeader);
|
|
83
|
-
}
|
|
84
|
-
if (body.code === "VALIDATION_ERROR") {
|
|
85
|
-
return new TasqValidationError(status, body);
|
|
86
|
-
}
|
|
87
|
-
if (body.code === "AGENT_ACTION_DENIED") {
|
|
88
|
-
return new TasqPolicyDeniedError(status, body);
|
|
89
|
-
}
|
|
90
|
-
return new TasqApiError(status, body);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// src/client.ts
|
|
94
|
-
var PROJECT_UPDATES_PAGE_MAX = 100;
|
|
95
|
-
function assertPrefix(token, prefix, label) {
|
|
96
|
-
if (!token.startsWith(prefix)) {
|
|
97
|
-
throw new Error(
|
|
98
|
-
`Invalid ${label}: expected a token starting with "${prefix}".`
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
function credential(auth) {
|
|
103
|
-
if (auth === void 0) return void 0;
|
|
104
|
-
if ("agentKey" in auth) {
|
|
105
|
-
assertPrefix(auth.agentKey, AGENT_KEY_PREFIX, "agent key");
|
|
106
|
-
return auth.agentKey;
|
|
107
|
-
}
|
|
108
|
-
assertPrefix(auth.userToken, USER_TOKEN_PREFIX, "user token");
|
|
109
|
-
return auth.userToken;
|
|
110
|
-
}
|
|
111
|
-
function normaliseBaseUrl(baseUrl) {
|
|
112
|
-
return `${baseUrl.replace(/\/+$/, "")}/api`;
|
|
113
|
-
}
|
|
114
|
-
function queryString(params) {
|
|
115
|
-
if (!params) return "";
|
|
116
|
-
const search = new URLSearchParams();
|
|
117
|
-
for (const [key, value] of Object.entries(params)) {
|
|
118
|
-
if (value === void 0) continue;
|
|
119
|
-
search.set(key, String(value));
|
|
120
|
-
}
|
|
121
|
-
const encoded = search.toString();
|
|
122
|
-
return encoded === "" ? "" : `?${encoded}`;
|
|
123
|
-
}
|
|
124
|
-
var TasqClient = class _TasqClient {
|
|
125
|
-
#baseUrl;
|
|
126
|
-
#token;
|
|
127
|
-
#fetch;
|
|
128
|
-
/** A client with no credential, for the two anonymous auth calls. */
|
|
129
|
-
static anonymous(baseUrl, fetchImpl) {
|
|
130
|
-
return new _TasqClient({ baseUrl, fetch: fetchImpl });
|
|
131
|
-
}
|
|
132
|
-
constructor(options) {
|
|
133
|
-
this.#baseUrl = normaliseBaseUrl(options.baseUrl);
|
|
134
|
-
this.#token = credential(options.auth);
|
|
135
|
-
this.#fetch = options.fetch ?? globalThis.fetch;
|
|
136
|
-
}
|
|
137
|
-
async #request(path, init = {}) {
|
|
138
|
-
const { anonymous = false, timeoutMs, ...requestInit } = init;
|
|
139
|
-
const headers = new Headers(requestInit.headers);
|
|
140
|
-
if (!anonymous) {
|
|
141
|
-
if (this.#token === void 0) throw noCredentialError();
|
|
142
|
-
headers.set("authorization", `Bearer ${this.#token}`);
|
|
143
|
-
}
|
|
144
|
-
if (requestInit.body !== void 0 && !headers.has("content-type")) {
|
|
145
|
-
headers.set("content-type", "application/json");
|
|
146
|
-
}
|
|
147
|
-
headers.set("accept", "application/json");
|
|
148
|
-
const timeout = timeoutMs === void 0 ? void 0 : AbortSignal.timeout(timeoutMs);
|
|
149
|
-
const signals = [requestInit.signal, timeout].filter(
|
|
150
|
-
(candidate) => candidate != null
|
|
151
|
-
);
|
|
152
|
-
const signal = signals.length === 0 ? void 0 : signals.length === 1 ? signals[0] : AbortSignal.any(signals);
|
|
153
|
-
const response = await this.#fetch(`${this.#baseUrl}${path}`, {
|
|
154
|
-
...requestInit,
|
|
155
|
-
headers,
|
|
156
|
-
signal
|
|
157
|
-
});
|
|
158
|
-
if (!response.ok) {
|
|
159
|
-
throw await this.#toError(response);
|
|
160
|
-
}
|
|
161
|
-
return await response.json();
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* A read whose body is Markdown rather than JSON.
|
|
165
|
-
*
|
|
166
|
-
* The export and the `format=markdown` context are documents, not
|
|
167
|
-
* envelopes, so they are read as text. Errors still arrive as the JSON
|
|
168
|
-
* envelope every other route uses, so the failure path is `#toError`'s,
|
|
169
|
-
* unchanged.
|
|
170
|
-
*/
|
|
171
|
-
async #text(path, params, options) {
|
|
172
|
-
const headers = new Headers({ accept: "text/markdown" });
|
|
173
|
-
if (this.#token === void 0) throw noCredentialError();
|
|
174
|
-
headers.set("authorization", `Bearer ${this.#token}`);
|
|
175
|
-
const timeout = options?.timeoutMs === void 0 ? void 0 : AbortSignal.timeout(options.timeoutMs);
|
|
176
|
-
const signals = [options?.signal, timeout].filter(
|
|
177
|
-
(candidate) => candidate != null
|
|
178
|
-
);
|
|
179
|
-
const signal = signals.length === 0 ? void 0 : signals.length === 1 ? signals[0] : AbortSignal.any(signals);
|
|
180
|
-
const response = await this.#fetch(
|
|
181
|
-
`${this.#baseUrl}${path}${queryString(params)}`,
|
|
182
|
-
{ headers, signal }
|
|
183
|
-
);
|
|
184
|
-
if (!response.ok) throw await this.#toError(response);
|
|
185
|
-
return await response.text();
|
|
186
|
-
}
|
|
187
|
-
async #toError(response) {
|
|
188
|
-
const retryAfter = response.headers.get("retry-after");
|
|
189
|
-
const fallback = {
|
|
190
|
-
code: `HTTP_${response.status}`,
|
|
191
|
-
message: `Request failed with status ${response.status}`
|
|
192
|
-
};
|
|
193
|
-
const envelope = await response.json().catch(() => null);
|
|
194
|
-
const error = envelope?.error;
|
|
195
|
-
const body = error?.code === void 0 ? fallback : {
|
|
196
|
-
code: error.code,
|
|
197
|
-
message: error.message ?? fallback.message,
|
|
198
|
-
details: error.details
|
|
199
|
-
};
|
|
200
|
-
return toTasqError(response.status, body, retryAfter);
|
|
201
|
-
}
|
|
202
|
-
#get(path, params, options) {
|
|
203
|
-
return this.#request(`${path}${queryString(params)}`, options);
|
|
204
|
-
}
|
|
205
|
-
workspaces = {
|
|
206
|
-
list: async () => (await this.#get("/workspaces")).workspaces,
|
|
207
|
-
get: async (slug) => (await this.#get(
|
|
208
|
-
`/workspaces/${encodeURIComponent(slug)}`
|
|
209
|
-
)).workspace
|
|
210
|
-
};
|
|
211
|
-
tasks = {
|
|
212
|
-
list: async (slug, filters) => (await this.#get(
|
|
213
|
-
`/workspaces/${encodeURIComponent(slug)}/tasks`,
|
|
214
|
-
filters
|
|
215
|
-
)).tasks,
|
|
216
|
-
get: async (slug, taskId) => (await this.#get(
|
|
217
|
-
`/workspaces/${encodeURIComponent(slug)}/tasks/${encodeURIComponent(taskId)}`
|
|
218
|
-
)).task,
|
|
219
|
-
/**
|
|
220
|
-
* Ask a person to sign off on a task (6.3). Asking again while a
|
|
221
|
-
* request stands replaces the approver. The approver cannot be an agent.
|
|
222
|
-
*/
|
|
223
|
-
requestApproval: (slug, taskId, approverId) => this.dispatch("task.requestApproval", slug, { taskId, approverId }),
|
|
224
|
-
/**
|
|
225
|
-
* The approver's answer (6.3). `approve` also moves the task to the next
|
|
226
|
-
* status in its team's category order. Person credentials only: no
|
|
227
|
-
* agent policy can include it.
|
|
228
|
-
*/
|
|
229
|
-
decide: (slug, taskId, decision) => this.dispatch("task.decide", slug, { taskId, decision })
|
|
230
|
-
};
|
|
231
|
-
/**
|
|
232
|
-
* Time tracking: whole minutes on a task for a day, no running timer.
|
|
233
|
-
* Everything here is member-level; a guest credential is refused. Turn a
|
|
234
|
-
* typed duration into minutes with `parseDuration`.
|
|
235
|
-
*/
|
|
236
|
-
time = {
|
|
237
|
-
/** A task's entries, newest day first, and its total with direct subtasks. */
|
|
238
|
-
forTask: (slug, taskId) => this.#get(
|
|
239
|
-
`/workspaces/${encodeURIComponent(slug)}/tasks/${encodeURIComponent(taskId)}/time`
|
|
240
|
-
),
|
|
241
|
-
/**
|
|
242
|
-
* Time on a project's tasks between two inclusive `YYYY-MM-DD` days, by
|
|
243
|
-
* person and day. The API reads at most 92 days at a time.
|
|
244
|
-
*/
|
|
245
|
-
forProject: (slug, projectId, range) => this.#get(
|
|
246
|
-
`/workspaces/${encodeURIComponent(slug)}/projects/${encodeURIComponent(projectId)}/time`,
|
|
247
|
-
{ from: range.from, to: range.to }
|
|
248
|
-
),
|
|
249
|
-
/**
|
|
250
|
-
* Log minutes on a task for a day. `memberId` defaults to the caller;
|
|
251
|
-
* logging for someone else is an admin's job.
|
|
252
|
-
*/
|
|
253
|
-
log: (slug, input) => this.dispatch("time.log", slug, input),
|
|
254
|
-
/** Change an entry; omitted fields are left alone, `note: null` clears it. */
|
|
255
|
-
update: (slug, input) => this.dispatch("time.update", slug, input),
|
|
256
|
-
delete: (slug, input) => this.dispatch("time.delete", slug, input)
|
|
257
|
-
};
|
|
258
|
-
/**
|
|
259
|
-
* Clients (initiatives) and their hours. Member-only; refused unless a team
|
|
260
|
-
* with a project for the client has Client hours on.
|
|
261
|
-
*/
|
|
262
|
-
clients = {
|
|
263
|
-
/**
|
|
264
|
-
* One month of a client's hours by billable flag, project and person.
|
|
265
|
-
* `month` is `YYYY-MM`; `billableOnly` counts billable entries only.
|
|
266
|
-
*/
|
|
267
|
-
hours: (slug, clientId, month, options = {}) => this.#get(
|
|
268
|
-
`/workspaces/${encodeURIComponent(slug)}/clients/${encodeURIComponent(clientId)}/hours`,
|
|
269
|
-
{ month, billable: options.billableOnly ? "billable" : "all" }
|
|
270
|
-
),
|
|
271
|
-
/** A client's billing months, newest first, with each one's hours and state. */
|
|
272
|
-
billing: (slug, clientId) => this.#get(
|
|
273
|
-
`/workspaces/${encodeURIComponent(slug)}/clients/${encodeURIComponent(clientId)}/billing`
|
|
274
|
-
)
|
|
275
|
-
};
|
|
276
|
-
/** The caller's own time (TM-2, My week). */
|
|
277
|
-
me = {
|
|
278
|
-
/**
|
|
279
|
-
* The caller's Monday-to-Sunday week around `day` (`YYYY-MM-DD`), that
|
|
280
|
-
* day's entries, and tasks they worked on that day with no time logged.
|
|
281
|
-
* `tz` is the IANA zone that decides which edits fall on the day.
|
|
282
|
-
*/
|
|
283
|
-
week: (slug, day, options = {}) => this.#get(
|
|
284
|
-
`/workspaces/${encodeURIComponent(slug)}/me/week`,
|
|
285
|
-
options.tz ? { day, tz: options.tz } : { day }
|
|
286
|
-
)
|
|
287
|
-
};
|
|
288
|
-
/**
|
|
289
|
-
* Agent timesheet drafts (TM-2). The drafting agent reads a draft and the
|
|
290
|
-
* member's day and saves lines; the member requests, logs, dismisses or
|
|
291
|
-
* replies. Agent keys are refused the member's side by policy.
|
|
292
|
-
*/
|
|
293
|
-
timeDrafts = {
|
|
294
|
-
get: async (slug, draftId) => (await this.#get(
|
|
295
|
-
`/workspaces/${encodeURIComponent(slug)}/time-drafts/${encodeURIComponent(draftId)}`
|
|
296
|
-
)).draft,
|
|
297
|
-
/** The member's week around `day`, read by the agent that drafts it. */
|
|
298
|
-
memberWeek: (slug, memberId, day) => this.#get(
|
|
299
|
-
`/workspaces/${encodeURIComponent(slug)}/members/${encodeURIComponent(memberId)}/week`,
|
|
300
|
-
{ day }
|
|
301
|
-
),
|
|
302
|
-
request: (slug, input) => this.dispatch("timeDraft.request", slug, input),
|
|
303
|
-
save: (slug, input) => this.dispatch("timeDraft.save", slug, input),
|
|
304
|
-
confirm: (slug, input) => this.dispatch("timeDraft.confirm", slug, input),
|
|
305
|
-
dismiss: (slug, input) => this.dispatch("timeDraft.dismiss", slug, input),
|
|
306
|
-
reply: (slug, input) => this.dispatch("timeDraft.reply", slug, input)
|
|
307
|
-
};
|
|
308
|
-
/** Close, invoice and reopen a client's month (admins only). */
|
|
309
|
-
billingPeriods = {
|
|
310
|
-
close: (slug, input) => this.dispatch("billingPeriod.close", slug, input),
|
|
311
|
-
markInvoiced: (slug, input) => this.dispatch("billingPeriod.markInvoiced", slug, input),
|
|
312
|
-
reopen: (slug, input) => this.dispatch("billingPeriod.reopen", slug, input)
|
|
313
|
-
};
|
|
314
|
-
projects = {
|
|
315
|
-
list: async (slug) => (await this.#get(
|
|
316
|
-
`/workspaces/${encodeURIComponent(slug)}/projects`
|
|
317
|
-
)).projects,
|
|
318
|
-
get: async (slug, projectId) => (await this.#get(
|
|
319
|
-
`/workspaces/${encodeURIComponent(slug)}/projects/${encodeURIComponent(projectId)}`
|
|
320
|
-
)).project,
|
|
321
|
-
/**
|
|
322
|
-
* Pin a project to the caller's own sidebar. People only: an agent
|
|
323
|
-
* key is refused by policy whatever its preset.
|
|
324
|
-
*/
|
|
325
|
-
star: (slug, input) => this.dispatch("project.star", slug, input),
|
|
326
|
-
unstar: (slug, input) => this.dispatch("project.unstar", slug, input),
|
|
327
|
-
/**
|
|
328
|
-
* Share a project with a guest already in the workspace (6.2). Admins
|
|
329
|
-
* and the project lead only; an agent key is always refused.
|
|
330
|
-
*/
|
|
331
|
-
grantGuest: (slug, input) => this.dispatch("project.grantGuest", slug, input),
|
|
332
|
-
setGuestAccess: (slug, input) => this.dispatch("project.setGuestAccess", slug, input),
|
|
333
|
-
revokeGuest: (slug, input) => this.dispatch("project.revokeGuest", slug, input)
|
|
334
|
-
};
|
|
335
|
-
/**
|
|
336
|
-
* Initiatives group projects across teams. Any member reads them; every
|
|
337
|
-
* write is admin-level, so an agent key (always a member) cannot make one.
|
|
338
|
-
*/
|
|
339
|
-
initiatives = {
|
|
340
|
-
list: async (slug) => (await this.#get(
|
|
341
|
-
`/workspaces/${encodeURIComponent(slug)}/initiatives`
|
|
342
|
-
)).initiatives,
|
|
343
|
-
create: (slug, input) => this.dispatch("initiative.create", slug, input),
|
|
344
|
-
update: (slug, input) => this.dispatch("initiative.update", slug, input),
|
|
345
|
-
delete: (slug, input) => this.dispatch("initiative.delete", slug, input),
|
|
346
|
-
linkProject: (slug, input) => this.dispatch("initiative.linkProject", slug, input),
|
|
347
|
-
unlinkProject: (slug, input) => this.dispatch("initiative.unlinkProject", slug, input)
|
|
348
|
-
};
|
|
349
|
-
/**
|
|
350
|
-
* Project updates: a health call and a body for the project's client (7.5).
|
|
351
|
-
*
|
|
352
|
-
* `draft` is what an agent calls; an agent's update is always a draft
|
|
353
|
-
* whatever it passes. `send` is people only: no agent policy can grant it,
|
|
354
|
-
* because nothing an agent drafts goes to a client without a person
|
|
355
|
-
* approving it.
|
|
356
|
-
*/
|
|
357
|
-
projectUpdates = {
|
|
358
|
-
/**
|
|
359
|
-
* Every update on the project, drafts included, newest first. Follows
|
|
360
|
-
* `nextCursor` until the last page; use `listPage` for one page.
|
|
361
|
-
*/
|
|
362
|
-
list: async (slug, projectId) => {
|
|
363
|
-
const updates = [];
|
|
364
|
-
let before;
|
|
365
|
-
do {
|
|
366
|
-
const page = await this.projectUpdates.listPage(slug, projectId, {
|
|
367
|
-
limit: PROJECT_UPDATES_PAGE_MAX,
|
|
368
|
-
before
|
|
369
|
-
});
|
|
370
|
-
updates.push(...page.updates);
|
|
371
|
-
before = page.nextCursor ?? void 0;
|
|
372
|
-
} while (before !== void 0);
|
|
373
|
-
return updates;
|
|
374
|
-
},
|
|
375
|
-
/**
|
|
376
|
-
* One page of the project's updates, drafts included, newest first; pass
|
|
377
|
-
* `nextCursor` as `before` for the next. The API returns 20 by default,
|
|
378
|
-
* at most 100.
|
|
379
|
-
*/
|
|
380
|
-
listPage: (slug, projectId, query = {}) => this.#get(
|
|
381
|
-
`/workspaces/${encodeURIComponent(slug)}/projects/${encodeURIComponent(projectId)}/updates`,
|
|
382
|
-
{ limit: query.limit, before: query.before }
|
|
383
|
-
),
|
|
384
|
-
draft: (slug, input) => this.dispatch("projectUpdate.create", slug, input),
|
|
385
|
-
create: (slug, input) => this.dispatch("projectUpdate.create", slug, input),
|
|
386
|
-
update: (slug, input) => this.dispatch("projectUpdate.update", slug, input),
|
|
387
|
-
send: (slug, input) => this.dispatch("projectUpdate.send", slug, input),
|
|
388
|
-
delete: (slug, input) => this.dispatch("projectUpdate.delete", slug, input)
|
|
389
|
-
};
|
|
390
|
-
threads = {
|
|
391
|
-
/**
|
|
392
|
-
* The context bundle for one thread: the entity it hangs off, the
|
|
393
|
-
* transcript, recent activity, and the participants (D-6).
|
|
394
|
-
*
|
|
395
|
-
* Authorized by the entity's own read rule, so a read-only agent may
|
|
396
|
-
* pull it. Lists are capped per D-8 with `truncated` flags.
|
|
397
|
-
*/
|
|
398
|
-
context: (slug, threadId, options) => this.#get(
|
|
399
|
-
`/workspaces/${encodeURIComponent(slug)}/threads/${encodeURIComponent(threadId)}/context`,
|
|
400
|
-
void 0,
|
|
401
|
-
options
|
|
402
|
-
)
|
|
403
|
-
};
|
|
404
|
-
cycles = {
|
|
405
|
-
list: async (slug, filters) => (await this.#get(
|
|
406
|
-
`/workspaces/${encodeURIComponent(slug)}/cycles`,
|
|
407
|
-
filters
|
|
408
|
-
)).cycles
|
|
409
|
-
};
|
|
410
|
-
teams = {
|
|
411
|
-
list: async (slug) => (await this.#get(
|
|
412
|
-
`/workspaces/${encodeURIComponent(slug)}/teams`
|
|
413
|
-
)).teams,
|
|
414
|
-
/** The only read that carries a team's statuses. */
|
|
415
|
-
get: async (slug, identifier) => (await this.#get(
|
|
416
|
-
`/workspaces/${encodeURIComponent(slug)}/teams/${encodeURIComponent(identifier)}`
|
|
417
|
-
)).team,
|
|
418
|
-
/**
|
|
419
|
-
* Whether agents on this team may wake each other, plus the loop and
|
|
420
|
-
* fan-out limits that stand behind the open setting (B-04c D-1).
|
|
421
|
-
*
|
|
422
|
-
* Read-only here on purpose: saving the setting is admin-only and web-only
|
|
423
|
-
* (D-8), so no agent key can reach it.
|
|
424
|
-
*/
|
|
425
|
-
agentSettings: (slug, identifier) => this.#get(
|
|
426
|
-
`/workspaces/${encodeURIComponent(slug)}/teams/${encodeURIComponent(identifier)}/agent-settings`
|
|
427
|
-
)
|
|
428
|
-
};
|
|
429
|
-
labels = {
|
|
430
|
-
list: async (slug) => (await this.#get(
|
|
431
|
-
`/workspaces/${encodeURIComponent(slug)}/labels`
|
|
432
|
-
)).labels
|
|
433
|
-
};
|
|
434
|
-
/**
|
|
435
|
-
* Custom fields (6.4): the workspace library, archived fields included.
|
|
436
|
-
* Values are set with `task.setField` and `project.setField`, by field key.
|
|
437
|
-
*/
|
|
438
|
-
fields = {
|
|
439
|
-
list: async (slug) => (await this.#get(
|
|
440
|
-
`/workspaces/${encodeURIComponent(slug)}/fields`
|
|
441
|
-
)).fields,
|
|
442
|
-
/** Set a task's value; null, `[]` or `false` clears it. */
|
|
443
|
-
setTaskValue: (slug, taskId, fieldKey, value) => this.dispatch("task.setField", slug, { taskId, fieldKey, value }),
|
|
444
|
-
/**
|
|
445
|
-
* Set one value on up to 100 tasks, all or nothing: a task whose team
|
|
446
|
-
* has the field off refuses the whole set.
|
|
447
|
-
*/
|
|
448
|
-
bulkSetTaskValue: (slug, taskIds, fieldKey, value) => this.dispatch("task.bulkSetField", slug, { taskIds, fieldKey, value }),
|
|
449
|
-
/** Set a project field's value; null clears it. */
|
|
450
|
-
setProjectValue: (slug, projectId, fieldKey, value) => this.dispatch("project.setField", slug, { projectId, fieldKey, value })
|
|
451
|
-
};
|
|
452
|
-
agents = {
|
|
453
|
-
policy: (slug, agentId) => this.#get(
|
|
454
|
-
`/workspaces/${encodeURIComponent(slug)}/agents/${encodeURIComponent(agentId)}/policy`
|
|
455
|
-
),
|
|
456
|
-
/**
|
|
457
|
-
* Long-poll for mentions addressed to the agent behind this key.
|
|
458
|
-
*
|
|
459
|
-
* The same call acks: ids passed as `ack` are marked before the select
|
|
460
|
-
* runs, so a runner's next poll is also its acknowledgement of the last
|
|
461
|
-
* batch (D-5). Agent keys only.
|
|
462
|
-
*/
|
|
463
|
-
events: (slug, query = {}, options) => this.#get(
|
|
464
|
-
`/workspaces/${encodeURIComponent(slug)}/agents/me/events`,
|
|
465
|
-
{
|
|
466
|
-
wait: query.wait,
|
|
467
|
-
limit: query.limit,
|
|
468
|
-
ack: query.ack === void 0 || query.ack.length === 0 ? void 0 : query.ack.join(",")
|
|
469
|
-
},
|
|
470
|
-
options
|
|
471
|
-
)
|
|
472
|
-
};
|
|
473
|
-
/**
|
|
474
|
-
* Releases: the structural record of a cycle close, and the narrative an
|
|
475
|
-
* agent or a person attaches to it (B-04d).
|
|
476
|
-
*
|
|
477
|
-
* Reads are authorized by the workspace role guard rather than a policy
|
|
478
|
-
* action, so a read-only agent may pull the context it needs; the write
|
|
479
|
-
* goes through `release.saveNarrative` like every other action.
|
|
480
|
-
*/
|
|
481
|
-
releases = {
|
|
482
|
-
list: async (slug, teamIdentifier) => (await this.#get(
|
|
483
|
-
`/workspaces/${encodeURIComponent(slug)}/releases`,
|
|
484
|
-
{ team: teamIdentifier }
|
|
485
|
-
)).releases,
|
|
486
|
-
get: async (slug, releaseId) => (await this.#get(
|
|
487
|
-
`/workspaces/${encodeURIComponent(slug)}/releases/${encodeURIComponent(releaseId)}`
|
|
488
|
-
)).release,
|
|
489
|
-
/**
|
|
490
|
-
* The context bundle a narrator writes from.
|
|
491
|
-
*
|
|
492
|
-
* `format: "markdown"` returns the server-rendered prompt as a string,
|
|
493
|
-
* which is what a harness pastes into a model; the default returns the
|
|
494
|
-
* bundle, for a runner that branches on the fields itself.
|
|
495
|
-
*/
|
|
496
|
-
context: ((slug, releaseId, options = {}) => {
|
|
497
|
-
const path = `/workspaces/${encodeURIComponent(slug)}/releases/${encodeURIComponent(releaseId)}/context`;
|
|
498
|
-
return options.format === "markdown" ? this.#text(path, { format: "markdown" }, options) : this.#get(path, void 0, options);
|
|
499
|
-
}),
|
|
500
|
-
diff: async (slug, releaseId) => (await this.#get(
|
|
501
|
-
`/workspaces/${encodeURIComponent(slug)}/releases/${encodeURIComponent(releaseId)}/diff`
|
|
502
|
-
)).diff,
|
|
503
|
-
/** The release as a Markdown document, the same body the web export serves. */
|
|
504
|
-
export: (slug, releaseId) => this.#text(
|
|
505
|
-
`/workspaces/${encodeURIComponent(slug)}/releases/${encodeURIComponent(releaseId)}/export`
|
|
506
|
-
),
|
|
507
|
-
/** Last write wins; the author and timestamp move with the body (D-3). */
|
|
508
|
-
saveNarrative: (slug, input) => this.dispatch("release.saveNarrative", slug, input)
|
|
509
|
-
};
|
|
510
|
-
members = {
|
|
511
|
-
list: async (slug) => (await this.#get(
|
|
512
|
-
`/workspaces/${encodeURIComponent(slug)}/members`
|
|
513
|
-
)).members
|
|
514
|
-
};
|
|
515
|
-
notifications = {
|
|
516
|
-
list: (slug, query = {}) => this.#get(
|
|
517
|
-
`/workspaces/${encodeURIComponent(slug)}/notifications`,
|
|
518
|
-
{ unread: query.unread === true ? 1 : void 0 }
|
|
519
|
-
)
|
|
520
|
-
};
|
|
521
|
-
activity = {
|
|
522
|
-
/** The workspace activity feed, newest first; page with `nextCursor`. */
|
|
523
|
-
list: (slug, query = {}) => this.#get(
|
|
524
|
-
`/workspaces/${encodeURIComponent(slug)}/activity`,
|
|
525
|
-
{ limit: query.limit, before: query.before }
|
|
526
|
-
)
|
|
527
|
-
};
|
|
528
|
-
waiting = {
|
|
529
|
-
/** Approvals and agent drafts waiting on the caller. People only. */
|
|
530
|
-
get: (slug) => this.#get(
|
|
531
|
-
`/workspaces/${encodeURIComponent(slug)}/waiting`
|
|
532
|
-
)
|
|
533
|
-
};
|
|
534
|
-
auth = {
|
|
535
|
-
/** The principal behind the current credential. */
|
|
536
|
-
me: async () => (await this.#get("/auth/me")).user,
|
|
537
|
-
/** Step one of CLI login: mail a sign-in code. Needs no credential. */
|
|
538
|
-
requestMagicLink: async (input) => {
|
|
539
|
-
await this.#request("/auth/magic-link", {
|
|
540
|
-
method: "POST",
|
|
541
|
-
body: JSON.stringify({ email: input.email }),
|
|
542
|
-
anonymous: true
|
|
543
|
-
});
|
|
544
|
-
},
|
|
545
|
-
/** Step two: exchange the code for a `tq_us_…` token. Needs no credential. */
|
|
546
|
-
verifyCliCode: (input) => this.#request("/auth/cli/verify-code", {
|
|
547
|
-
method: "POST",
|
|
548
|
-
body: JSON.stringify(input),
|
|
549
|
-
anonymous: true
|
|
550
|
-
}),
|
|
551
|
-
/** Revoke the user token this client authenticates with. */
|
|
552
|
-
revokeUserToken: async () => {
|
|
553
|
-
await this.#request("/auth/cli/token", { method: "DELETE" });
|
|
554
|
-
}
|
|
555
|
-
};
|
|
556
|
-
/** Run a write action. The API validates `input`; the SDK does not. */
|
|
557
|
-
dispatch(action, slug, input) {
|
|
558
|
-
return this.#request(
|
|
559
|
-
`/workspaces/${encodeURIComponent(slug)}/actions`,
|
|
560
|
-
{ method: "POST", body: JSON.stringify({ action, input }) }
|
|
561
|
-
);
|
|
562
|
-
}
|
|
563
|
-
};
|
|
564
|
-
|
|
565
|
-
// src/time.ts
|
|
566
|
-
var DURATION_FORMS = "1h 30m, 1h30m, 90m, 1.5h, 1:30 or a bare number of hours";
|
|
567
|
-
function parseDuration(raw) {
|
|
568
|
-
const value = raw.trim().toLowerCase().replace(/\s+/g, "");
|
|
569
|
-
if (!value) return null;
|
|
570
|
-
let match = value.match(/^(\d{1,2}):([0-5]\d)$/);
|
|
571
|
-
if (match) return Number(match[1]) * 60 + Number(match[2]);
|
|
572
|
-
match = value.match(/^(\d+(?:\.\d+)?)h$/);
|
|
573
|
-
if (match) return Math.round(Number(match[1]) * 60);
|
|
574
|
-
match = value.match(/^(\d+)m(?:in|ins)?$/);
|
|
575
|
-
if (match) return Number(match[1]);
|
|
576
|
-
match = value.match(/^(\d+)h(\d+)m?(?:in|ins)?$/);
|
|
577
|
-
if (match) return Number(match[1]) * 60 + Number(match[2]);
|
|
578
|
-
match = value.match(/^(\d+(?:\.\d+)?)$/);
|
|
579
|
-
if (match) return Math.round(Number(match[1]) * 60);
|
|
580
|
-
return null;
|
|
581
|
-
}
|
|
582
|
-
function formatMinutes(minutes) {
|
|
583
|
-
const hours = Math.floor(minutes / 60);
|
|
584
|
-
const rest = minutes % 60;
|
|
585
|
-
if (hours === 0) return `${rest}m`;
|
|
586
|
-
return rest === 0 ? `${hours}h` : `${hours}h ${rest}m`;
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
// src/types.ts
|
|
590
|
-
var PROJECT_HEALTH_VALUES = [
|
|
591
|
-
"on_track",
|
|
592
|
-
"at_risk",
|
|
593
|
-
"off_track"
|
|
594
|
-
];
|
|
595
|
-
var THREAD_CONTEXT_MESSAGE_LIMIT = 50;
|
|
596
|
-
var THREAD_CONTEXT_ACTIVITY_LIMIT = 20;
|
|
597
|
-
var THREAD_CONTEXT_DESCRIPTION_MAX = 8e3;
|
|
598
|
-
var AGENT_ISOLATION_VALUES = ["isolated", "open"];
|
|
599
|
-
var SUPPRESSED_REASONS = [
|
|
600
|
-
"isolation",
|
|
601
|
-
"fanout_cap",
|
|
602
|
-
"loop_cap",
|
|
603
|
-
"guest_actor"
|
|
604
|
-
];
|
|
605
|
-
var MAX_AGENT_WAKES_PER_MESSAGE = 10;
|
|
606
|
-
var MAX_CONSECUTIVE_AGENT_MESSAGES = 5;
|
|
607
|
-
var RELEASE_DISPOSITIONS = [
|
|
608
|
-
"shipped",
|
|
609
|
-
"carried_over",
|
|
610
|
-
"dropped"
|
|
611
|
-
];
|
|
612
|
-
var RELEASE_NARRATIVE_MAX = 5e4;
|
|
613
|
-
var RELEASE_NARRATIVE_EXCERPT_MAX = 500;
|
|
614
|
-
var RELEASE_CONTEXT_TASK_LIMIT = 100;
|
|
615
|
-
export {
|
|
616
|
-
AGENT_ISOLATION_VALUES,
|
|
617
|
-
AGENT_KEY_PREFIX,
|
|
618
|
-
DURATION_FORMS,
|
|
619
|
-
MAX_AGENT_WAKES_PER_MESSAGE,
|
|
620
|
-
MAX_CONSECUTIVE_AGENT_MESSAGES,
|
|
621
|
-
PROJECT_HEALTH_VALUES,
|
|
622
|
-
RELEASE_CONTEXT_TASK_LIMIT,
|
|
623
|
-
RELEASE_DISPOSITIONS,
|
|
624
|
-
RELEASE_NARRATIVE_EXCERPT_MAX,
|
|
625
|
-
RELEASE_NARRATIVE_MAX,
|
|
626
|
-
SUPPRESSED_REASONS,
|
|
627
|
-
THREAD_CONTEXT_ACTIVITY_LIMIT,
|
|
628
|
-
THREAD_CONTEXT_DESCRIPTION_MAX,
|
|
629
|
-
THREAD_CONTEXT_MESSAGE_LIMIT,
|
|
630
|
-
TasqApiError,
|
|
631
|
-
TasqClient,
|
|
632
|
-
TasqPolicyDeniedError,
|
|
633
|
-
TasqRateLimitError,
|
|
634
|
-
TasqValidationError,
|
|
635
|
-
USER_TOKEN_PREFIX,
|
|
636
|
-
formatMinutes,
|
|
637
|
-
parseDuration
|
|
638
|
-
};
|
|
639
|
-
//# sourceMappingURL=index.js.map
|