@retainer/sdk 0.0.0-stage → 0.1.1

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/dist/index.js ADDED
@@ -0,0 +1,810 @@
1
+ import { isMaintenance, maintenanceFetch } from './maintenance.js';
2
+ export { isMaintenance, isMaintenanceRead, retryAfterMs, waitForRetry } from './maintenance.js';
3
+ export class RetainerApiError extends Error {
4
+ status;
5
+ code;
6
+ details;
7
+ constructor(status, code, message, details) {
8
+ super(message);
9
+ this.status = status;
10
+ this.code = code;
11
+ this.details = details;
12
+ this.name = 'RetainerApiError';
13
+ }
14
+ }
15
+ const isFailedChange = (body) => typeof body === 'object' && body !== null && body.status === 'failed';
16
+ export class RetainerClient {
17
+ options;
18
+ baseUrl;
19
+ fetchImpl;
20
+ constructor(options) {
21
+ this.options = options;
22
+ this.baseUrl = options.baseUrl.replace(/\/+$/, '');
23
+ const fetcher = options.fetch ?? globalThis.fetch.bind(globalThis);
24
+ this.fetchImpl = (input, init) => maintenanceFetch(fetcher, input, init);
25
+ }
26
+ headers() {
27
+ if (this.options.accessToken) {
28
+ return {
29
+ authorization: `Bearer ${this.options.accessToken}`,
30
+ ...(this.options.workspace ? { 'X-Retainer-Workspace': this.options.workspace } : {}),
31
+ ...(this.options.approval ? { 'X-Retainer-Approval': this.options.approval } : {}),
32
+ };
33
+ }
34
+ if (this.options.apiKey)
35
+ return { authorization: `Bearer ${this.options.apiKey}` };
36
+ return this.options.workspace
37
+ ? { 'X-Retainer-Client': 'web', 'X-Retainer-Workspace': this.options.workspace }
38
+ : { 'X-Retainer-Client': 'web' };
39
+ }
40
+ /** `isResult` lets an error status whose body is a result come back as one. */
41
+ async request(path, init = {}, isResult) {
42
+ const response = await this.fetchImpl(`${this.baseUrl}${path}`, {
43
+ ...init,
44
+ credentials: this.options.credentials ?? 'same-origin',
45
+ headers: {
46
+ ...this.headers(),
47
+ ...(init.body ? { 'content-type': 'application/json' } : {}),
48
+ ...init.headers,
49
+ },
50
+ });
51
+ if (response.status === 204)
52
+ return undefined;
53
+ const body = (await response.json());
54
+ if (!response.ok && !isResult?.(body)) {
55
+ if (response.status === 401 && path !== '/auth/session')
56
+ this.options.onUnauthorized?.();
57
+ throw new RetainerApiError(response.status, body.error?.code ?? 'request_failed', body.error?.message ?? response.statusText, body.error?.details);
58
+ }
59
+ return body;
60
+ }
61
+ query(path, params, signal) {
62
+ const qs = new URLSearchParams();
63
+ for (const [k, v] of Object.entries(params))
64
+ if (v !== undefined)
65
+ qs.set(k, String(v));
66
+ return { path: `${path}${qs.size ? `?${qs}` : ''}`, signal };
67
+ }
68
+ get(path, params = {}, signal) {
69
+ const q = this.query(path, params, signal);
70
+ return this.request(q.path, { signal });
71
+ }
72
+ send(method, path, body, signal, idempotencyKey) {
73
+ return this.request(path, {
74
+ method,
75
+ body: body === undefined ? undefined : JSON.stringify(body),
76
+ signal,
77
+ headers: idempotencyKey ? { 'idempotency-key': idempotencyKey } : {},
78
+ });
79
+ }
80
+ post(path, body, signal, idempotencyKey) {
81
+ return this.send('POST', path, body, signal, idempotencyKey);
82
+ }
83
+ /** Health reports database outages in its response body, including HTTP 503. */
84
+ async health() {
85
+ const response = await this.fetchImpl(`${this.baseUrl}/health`);
86
+ if (await isMaintenance(response)) {
87
+ throw new RetainerApiError(503, 'maintenance', 'Retainer is updating. Please retry shortly.');
88
+ }
89
+ return (await response.json());
90
+ }
91
+ signIn(key) {
92
+ return this.post('/auth/session', { key });
93
+ }
94
+ signOut() {
95
+ return this.request('/auth/session', { method: 'DELETE' });
96
+ }
97
+ me(signal) {
98
+ return this.get('/v1/me', {}, signal);
99
+ }
100
+ schema(signal) {
101
+ return this.get('/v1/schema', {}, signal);
102
+ }
103
+ templates(signal) {
104
+ return this.get('/v1/templates', {}, signal);
105
+ }
106
+ applyTemplate(name) {
107
+ return this.post(`/v1/templates/${encodeURIComponent(name)}/apply`);
108
+ }
109
+ queryRecords(object, input = {}, signal) {
110
+ return this.post(`/v1/objects/${encodeURIComponent(object)}/query`, input, signal);
111
+ }
112
+ record(id, include = ['provenance', 'relationReferences'], signal) {
113
+ return this.get(`/v1/records/${encodeURIComponent(id)}`, { include: include.join(',') }, signal);
114
+ }
115
+ linkedRecords(id, options = {}) {
116
+ const { signal, ...query } = options;
117
+ return this.get(`/v1/records/${encodeURIComponent(id)}/linked`, query, signal);
118
+ }
119
+ createRecord(object, input, idempotencyKey) {
120
+ return this.post(`/v1/objects/${encodeURIComponent(object)}/records`, input, undefined, idempotencyKey);
121
+ }
122
+ upsertRecord(object, input) {
123
+ return this.post(`/v1/objects/${encodeURIComponent(object)}/upsert`, input);
124
+ }
125
+ /** Saves several records. The result at each index is its write response or error. */
126
+ upsertRecords(items) {
127
+ return this.post('/v1/records/upsert', { items });
128
+ }
129
+ patchRecord(id, input) {
130
+ return this.request(`/v1/records/${encodeURIComponent(id)}`, {
131
+ method: 'PATCH',
132
+ body: JSON.stringify(input),
133
+ });
134
+ }
135
+ /** What deleting the record would delete with it; changes nothing. */
136
+ deleteImpact(id, signal) {
137
+ return this.get(`/v1/records/${encodeURIComponent(id)}/delete-impact`, {}, signal);
138
+ }
139
+ /** What deleting several records together would delete with them. */
140
+ bulkDeleteImpact(ids, signal) {
141
+ return this.post('/v1/records/delete-impact', { ids }, signal);
142
+ }
143
+ /** The total and requested aggregates over the records a filter matches. */
144
+ aggregate(object, input = {}, signal) {
145
+ return this.post(`/v1/objects/${encodeURIComponent(object)}/aggregate`, input, signal);
146
+ }
147
+ deleteRecord(id, bindings) {
148
+ return this.request(`/v1/records/${encodeURIComponent(id)}`, {
149
+ method: 'DELETE',
150
+ ...(bindings ? { body: JSON.stringify({ bindings }) } : {}),
151
+ });
152
+ }
153
+ /** The object's saved views the caller can see, in their saved order. */
154
+ views(object, signal) {
155
+ return this.get(`/v1/objects/${encodeURIComponent(object)}/views`, {}, signal);
156
+ }
157
+ view(id, signal) {
158
+ return this.get(`/v1/views/${encodeURIComponent(id)}`, {}, signal);
159
+ }
160
+ createView(object, input) {
161
+ return this.post(`/v1/objects/${encodeURIComponent(object)}/views`, input);
162
+ }
163
+ /** Changes only the keys given; `null` clears a setting. */
164
+ updateView(id, input) {
165
+ return this.request(`/v1/views/${encodeURIComponent(id)}`, {
166
+ method: 'PATCH',
167
+ body: JSON.stringify(input),
168
+ });
169
+ }
170
+ deleteView(id) {
171
+ return this.request(`/v1/views/${encodeURIComponent(id)}`, {
172
+ method: 'DELETE',
173
+ });
174
+ }
175
+ /** Merges `input.recordId` into `id`, which survives. Retrying with the same key is safe. */
176
+ mergeRecords(id, input, idempotencyKey) {
177
+ return this.post(`/v1/records/${encodeURIComponent(id)}/merge`, input, undefined, idempotencyKey);
178
+ }
179
+ /**
180
+ * Deletes the signed-in person's personal memory in this workspace (4.6):
181
+ * web sessions only; agents cannot clear it.
182
+ */
183
+ clearMyMemory() {
184
+ return this.post('/v1/records/me/forget');
185
+ }
186
+ /** Erases a person and what was logged about them (needs the `admin` scope). Not reversible. */
187
+ forget(id) {
188
+ return this.post(`/v1/records/${encodeURIComponent(id)}/forget`);
189
+ }
190
+ search(input, signal) {
191
+ return this.post('/v1/search', input, signal);
192
+ }
193
+ context(id, input = {}, signal) {
194
+ return this.get(`/v1/records/${encodeURIComponent(id)}/context`, input, signal);
195
+ }
196
+ mergeSuggestion(id, keep) {
197
+ return this.post(`/v1/review/merges/${encodeURIComponent(id)}/merge`, { keep });
198
+ }
199
+ dismissMergeSuggestion(id) {
200
+ return this.post(`/v1/review/merges/${encodeURIComponent(id)}/dismiss`);
201
+ }
202
+ review(options = {}) {
203
+ const { signal, ...params } = options;
204
+ return this.get('/v1/review', params, signal);
205
+ }
206
+ assertion(id, signal) {
207
+ return this.get(`/v1/assertions/${encodeURIComponent(id)}`, {}, signal);
208
+ }
209
+ decideAssertion(id, decision) {
210
+ return this.post(`/v1/assertions/${encodeURIComponent(id)}/${decision}`);
211
+ }
212
+ assertions(id, options = {}) {
213
+ const { signal, ...params } = options;
214
+ return this.get(`/v1/records/${encodeURIComponent(id)}/assertions`, params, signal);
215
+ }
216
+ /**
217
+ * Events attached directly to a record, newest first, each with how it is
218
+ * attached (`via`). `link` narrows to participant, about or field.
219
+ */
220
+ recordEvents(id, options = {}) {
221
+ const { signal, ...params } = options;
222
+ return this.get(`/v1/records/${encodeURIComponent(id)}/events`, params, signal);
223
+ }
224
+ /**
225
+ * A record's timeline (8): events (direct and rolled up, with `via`),
226
+ * values asserted for its fields and its facts, newest first. Filters for
227
+ * one kind (`fields`, `eventTypes`) leave the others out unless `types`
228
+ * names them.
229
+ */
230
+ timeline(id, options = {}) {
231
+ const { signal, types, fields, eventTypes, ...params } = options;
232
+ return this.get(`/v1/records/${encodeURIComponent(id)}/timeline`, {
233
+ ...params,
234
+ types: types?.join(','),
235
+ fields: fields?.join(','),
236
+ eventTypes: eventTypes?.join(','),
237
+ }, signal);
238
+ }
239
+ /**
240
+ * A record's current facts, or a profile's: `workspace` for workspace
241
+ * memory, `me` for the caller's personal memory (personal memory spec 4.4).
242
+ */
243
+ facts(id, options = {}) {
244
+ const { signal, ...params } = options;
245
+ return this.get(`/v1/records/${encodeURIComponent(id)}/facts`, params, signal);
246
+ }
247
+ /**
248
+ * Adds a fact to a record or a profile (`workspace`, `me`). `supersedes`
249
+ * replaces a current fact: on the same record it corrects it, elsewhere it
250
+ * moves it (4.9).
251
+ */
252
+ remember(id, input, idempotencyKey) {
253
+ return this.post(`/v1/records/${encodeURIComponent(id)}/facts`, input, undefined, idempotencyKey);
254
+ }
255
+ retractFact(id) {
256
+ return this.request(`/v1/facts/${encodeURIComponent(id)}`, {
257
+ method: 'DELETE',
258
+ });
259
+ }
260
+ /** A record's comments, newest first, with their total. A merged ID follows the merge. */
261
+ listComments(id, options = {}) {
262
+ const { signal, ...params } = options;
263
+ return this.get(`/v1/records/${encodeURIComponent(id)}/comments`, params, signal);
264
+ }
265
+ /** Adds a comment (a `user` key only). Retrying with the same key adds it once. */
266
+ addComment(id, input, idempotencyKey) {
267
+ return this.post(`/v1/records/${encodeURIComponent(id)}/comments`, input, undefined, idempotencyKey);
268
+ }
269
+ /** Edits a comment's body; its author only. */
270
+ editComment(id, input, idempotencyKey) {
271
+ return this.send('PATCH', `/v1/comments/${encodeURIComponent(id)}`, input, undefined, idempotencyKey);
272
+ }
273
+ /** Deletes a comment; its author, or a `user` key with `admin`. */
274
+ deleteComment(id, idempotencyKey) {
275
+ return this.send('DELETE', `/v1/comments/${encodeURIComponent(id)}`, undefined, undefined, idempotencyKey);
276
+ }
277
+ /** One live event: the record with its built-in columns and links. */
278
+ event(id, signal) {
279
+ return this.get(`/v1/events/${encodeURIComponent(id)}`, {}, signal);
280
+ }
281
+ /** Events, new records and grouped record writes, newest added first. */
282
+ workspaceFeed(input = {}, signal) {
283
+ return this.post('/v1/feed/query', input, signal);
284
+ }
285
+ /** Withdraws the field assertions on a Home update card and recomputes affected fields. */
286
+ revertFeedUpdate(id, input) {
287
+ return this.post(`/v1/feed/${encodeURIComponent(id)}/revert`, input);
288
+ }
289
+ /**
290
+ * Events of every event type in one page, newest first (`POST /v1/events/query`).
291
+ * Filters take `type`, `occurredAt`, `channel` and `externalId`; `linked` finds
292
+ * the events attached to one record.
293
+ */
294
+ queryEvents(input = {}, signal) {
295
+ return this.post('/v1/events/query', input, signal);
296
+ }
297
+ /**
298
+ * Logs an event; idempotent by channel and externalId. After creating an
299
+ * unmatched person, re-log with the same handle/role and their recordId.
300
+ * `added.participants.matched` includes participants resolved in place.
301
+ */
302
+ logEvent(input) {
303
+ return this.post('/v1/events', input);
304
+ }
305
+ /**
306
+ * Moves events to another event type, keeping their IDs, identities, links
307
+ * and the claims that cite them (`POST /v1/events/move`). Moving needs a
308
+ * `user` key with the `admin` scope; `dryRun: true` reports the plan with
309
+ * `schema:write` and changes nothing.
310
+ */
311
+ moveEvents(input) {
312
+ return this.post('/v1/events/move', input);
313
+ }
314
+ /**
315
+ * Adds links and retries eligible unmatched participants in place; idempotent.
316
+ * Successful resolutions are included in `added.participants.matched`.
317
+ */
318
+ addEventLinks(id, input) {
319
+ return this.post(`/v1/events/${encodeURIComponent(id)}/links`, input);
320
+ }
321
+ /** Removes one participant (a person's key only). */
322
+ removeParticipant(id, participantId) {
323
+ return this.request(`/v1/events/${encodeURIComponent(id)}/participants/${encodeURIComponent(participantId)}`, { method: 'DELETE' });
324
+ }
325
+ /** Removes a record from an event's `about` list (a person's key only). */
326
+ removeAbout(id, recordId) {
327
+ return this.request(`/v1/events/${encodeURIComponent(id)}/about/${encodeURIComponent(recordId)}`, { method: 'DELETE' });
328
+ }
329
+ /** Deletes an event and retracts the claims that cite it. */
330
+ deleteEvent(id, bindings) {
331
+ return this.request(`/v1/events/${encodeURIComponent(id)}`, {
332
+ method: 'DELETE',
333
+ ...(bindings ? { body: JSON.stringify({ bindings }) } : {}),
334
+ });
335
+ }
336
+ claims(id, options = {}) {
337
+ const { signal, ...params } = options;
338
+ return this.get(`/v1/events/${encodeURIComponent(id)}/claims`, params, signal);
339
+ }
340
+ fileErasureStatus(ids) {
341
+ return this.post('/v1/files/erasure-status', { ids });
342
+ }
343
+ createFileIntent(input, idempotencyKey) {
344
+ return this.post('/v1/files/intents', input, undefined, idempotencyKey);
345
+ }
346
+ finalizeFile(id) {
347
+ return this.post(`/v1/files/${encodeURIComponent(id)}/finalize`);
348
+ }
349
+ file(id, signal) {
350
+ return this.get(`/v1/files/${encodeURIComponent(id)}`, {}, signal);
351
+ }
352
+ downloadFile(id) {
353
+ return this.post(`/v1/files/${encodeURIComponent(id)}/download`);
354
+ }
355
+ extensionCatalog(signal) {
356
+ return this.get('/v1/extensions/catalog', {}, signal);
357
+ }
358
+ verifySource(installationId, input) {
359
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/source/verify`, input);
360
+ }
361
+ reserveSourceItem(installationId, input) {
362
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/source-items`, input);
363
+ }
364
+ sourceConnection(installationId) {
365
+ return this.get(`/v1/extensions/${encodeURIComponent(installationId)}/source`);
366
+ }
367
+ sourceSyncStatus(installationId, signal) {
368
+ return this.get(`/v1/extensions/${encodeURIComponent(installationId)}/source-sync`, {}, signal);
369
+ }
370
+ beginSourceScan(installationId, input) {
371
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/source-sync`, input);
372
+ }
373
+ reserveSourceItems(installationId, input) {
374
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/source-items/batch`, input);
375
+ }
376
+ sourceItem(installationId, itemId) {
377
+ return this.get(`/v1/extensions/${encodeURIComponent(installationId)}/source-items/${encodeURIComponent(itemId)}`);
378
+ }
379
+ changes(input = {}) {
380
+ const { signal, ...params } = input;
381
+ return this.get('/v1/changes', params, signal);
382
+ }
383
+ change(position, signal) {
384
+ return this.get(`/v1/changes/${encodeURIComponent(position)}`, {}, signal);
385
+ }
386
+ gmailImportWindow(installationId) {
387
+ return this.get(`/v1/extensions/${encodeURIComponent(installationId)}/runtime/gmail/window`);
388
+ }
389
+ gmailTarget(installationId, additionId, complete = false) {
390
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/runtime/gmail/target`, {
391
+ additionId,
392
+ complete,
393
+ });
394
+ }
395
+ releaseGmailConnection(installationId) {
396
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/runtime/gmail/release`, {});
397
+ }
398
+ prepareGmailMessage(installationId, input) {
399
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/runtime/gmail/prepare`, input);
400
+ }
401
+ appendGmailMessage(installationId, input) {
402
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/runtime/gmail/messages`, input);
403
+ }
404
+ /** The full text behind an event (an email's body, a transcript), or its thread's, oldest first. */
405
+ eventContent(eventId, after, signal) {
406
+ return this.get(`/v1/events/${encodeURIComponent(eventId)}/content`, { after }, signal);
407
+ }
408
+ prepareSourceItem(installationId, itemId, participants) {
409
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/source-items/${encodeURIComponent(itemId)}/prepare`, { participants });
410
+ }
411
+ markSourceUnavailable(installationId, itemId, input) {
412
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/source-items/${encodeURIComponent(itemId)}/unavailable`, input);
413
+ }
414
+ sourceRecoveryItems(installationId, options = {}) {
415
+ const { signal, ...params } = options;
416
+ return this.get(`/v1/extensions/${encodeURIComponent(installationId)}/source-items`, params, signal);
417
+ }
418
+ syncSourceEvent(installationId, input) {
419
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/source-events`, input);
420
+ }
421
+ sourceTaskSchema(installationId) {
422
+ return this.get(`/v1/extensions/${encodeURIComponent(installationId)}/source-tasks/schema`);
423
+ }
424
+ syncSourceTasks(installationId, itemId, input) {
425
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/source-items/${encodeURIComponent(itemId)}/tasks`, input);
426
+ }
427
+ disconnectSource(installationId) {
428
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/source/disconnect`);
429
+ }
430
+ extensions(signal) {
431
+ return this.get('/v1/extensions', {}, signal);
432
+ }
433
+ /** Standalone apps' sidebar links for the workspace's members (extensions spec 8). */
434
+ extensionLinks(signal) {
435
+ return this.get('/v1/extensions/links', {}, signal);
436
+ }
437
+ /**
438
+ * A standalone app's own credential writes its installation's generated
439
+ * secret, with revision CAS (extensions spec 8). A `409 revision_conflict`
440
+ * carries the current revision in its details, never the value.
441
+ */
442
+ writeGeneratedSecret(installationId, name, input) {
443
+ return this.send('PUT', `/v1/extensions/${encodeURIComponent(installationId)}/generated-secrets/${encodeURIComponent(name)}`, input);
444
+ }
445
+ extension(id, signal) {
446
+ return this.get(`/v1/extensions/${encodeURIComponent(id)}`, {}, signal);
447
+ }
448
+ extensionBindings(id, signal) {
449
+ return this.get(`/v1/extensions/${encodeURIComponent(id)}/bindings`, {}, signal);
450
+ }
451
+ previewExtension(input) {
452
+ return this.post('/v1/extensions/preview', input);
453
+ }
454
+ installExtension(input, idempotencyKey) {
455
+ return this.post('/v1/extensions', input, undefined, idempotencyKey);
456
+ }
457
+ extensionConnections(id, signal) {
458
+ return this.get(`/v1/extensions/${encodeURIComponent(id)}/connections`, {}, signal);
459
+ }
460
+ authorizeGmail(id, historyDays) {
461
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/connections/gmail/authorize`, {
462
+ shareGmail: true,
463
+ historyDays,
464
+ });
465
+ }
466
+ finishGmailAuthorization(id, attemptId) {
467
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/connections/gmail/complete`, { attemptId });
468
+ }
469
+ stageExtensionConnectionSecret(id, input) {
470
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/connections/secrets`, input);
471
+ }
472
+ connectExtension(id, input) {
473
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/connections`, input);
474
+ }
475
+ /** Start an OAuth connection; navigate the browser to `authorizationUrl`. */
476
+ authorizeExtensionConnection(id, input) {
477
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/connections/authorize`, input);
478
+ }
479
+ /** Finish the OAuth round trip from the callback page, with the provider's code or error. */
480
+ completeExtensionAuthorization(id, input) {
481
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/connections/authorize/complete`, input);
482
+ }
483
+ /** Hide the release notice the member saw; `at` is `releaseNotice.at`, unchanged. */
484
+ dismissReleaseNotice(id, connection, at) {
485
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/connections/${encodeURIComponent(connection)}/release-notice/dismiss`, { at });
486
+ }
487
+ /** The operator's OAuth client, for a live run whose function holds the token secret. */
488
+ extensionOAuthClient(id) {
489
+ return this.get(`/v1/extensions/${encodeURIComponent(id)}/runtime/oauth-client`);
490
+ }
491
+ disconnectExtension(id, connection) {
492
+ return this.send('DELETE', `/v1/extensions/${encodeURIComponent(id)}/connections/${encodeURIComponent(connection)}`);
493
+ }
494
+ extensionRuns(id, options = {}) {
495
+ const { signal, ...params } = options;
496
+ return this.get(`/v1/extensions/${encodeURIComponent(id)}/runs`, params, signal);
497
+ }
498
+ inspectExtensionRun(id, runId, signal) {
499
+ return this.get(`/v1/extensions/${encodeURIComponent(id)}/runs/${encodeURIComponent(runId)}`, {}, signal);
500
+ }
501
+ extensionRecordButtons(object, signal) {
502
+ return this.get('/v1/extensions/record-buttons', { object }, signal);
503
+ }
504
+ runExtensionRecordButton(button, recordId) {
505
+ return this.post(`/v1/extensions/${encodeURIComponent(button.installationId)}/record-buttons/${encodeURIComponent(button.functionId)}`, { recordId });
506
+ }
507
+ extensionRecordButtonRun(installationId, runId, signal) {
508
+ return this.get(`/v1/extensions/${encodeURIComponent(installationId)}/record-button-runs/${encodeURIComponent(runId)}`, {}, signal);
509
+ }
510
+ retryExtensionRun(id, runId, idempotencyKey) {
511
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/runs/${encodeURIComponent(runId)}/retry`, undefined, undefined, idempotencyKey);
512
+ }
513
+ upgradeExtension(id, input, idempotencyKey) {
514
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/upgrade`, { ...input, installationId: id }, undefined, idempotencyKey);
515
+ }
516
+ reconnectExtension(id, connectionOrInput, inputOrKey) {
517
+ if (typeof connectionOrInput === 'string' && typeof inputOrKey !== 'string')
518
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/connections/${encodeURIComponent(connectionOrInput)}/reconnect`, inputOrKey);
519
+ if (typeof connectionOrInput !== 'string' && typeof inputOrKey === 'string')
520
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/reconnect`, connectionOrInput, undefined, inputOrKey);
521
+ throw new TypeError('invalid reconnect arguments');
522
+ }
523
+ updateExtensionSettings(id, input) {
524
+ return this.send('PATCH', `/v1/extensions/${encodeURIComponent(id)}/settings`, input);
525
+ }
526
+ enableExtension(id) {
527
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/enable`);
528
+ }
529
+ stageExtensionSecret(input) {
530
+ return this.post('/v1/extensions/secrets', input);
531
+ }
532
+ /**
533
+ * The fill-only mapped write of a run whose function declares `mappedWrite`:
534
+ * fills only mapped fields that have no value and were not cleared. A
535
+ * `confidence` below the workspace's threshold holds the values for review
536
+ * (agent actors only).
537
+ */
538
+ extensionMappedWrite(installationId, input) {
539
+ return this.post(`/v1/extensions/${encodeURIComponent(installationId)}/runtime/mapped-writes`, input);
540
+ }
541
+ /**
542
+ * Queue child jobs and compare-and-set one KV value, all or nothing. A KV
543
+ * value can't be JSON `null` (422 `invalid_input`): a missing key reads as
544
+ * null, and KV has no delete.
545
+ */
546
+ extensionCheckpoint(id, input) {
547
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/runtime/checkpoint`, input);
548
+ }
549
+ extensionKv(id, key) {
550
+ return this.get(`/v1/extensions/${encodeURIComponent(id)}/runtime/kv/${encodeURIComponent(key)}`);
551
+ }
552
+ extensionSecret(id, name) {
553
+ return this.get(`/v1/extensions/${encodeURIComponent(id)}/runtime/secrets/${encodeURIComponent(name)}`);
554
+ }
555
+ /** Store provider-generated signing/refresh material with revision CAS; live runs only. */
556
+ setExtensionSecret(id, name, input) {
557
+ return this.request(`/v1/extensions/${encodeURIComponent(id)}/runtime/secrets/${encodeURIComponent(name)}`, { method: 'PUT', body: JSON.stringify(input) });
558
+ }
559
+ /** Recompute only the release-pinned last-contact fields. Values, provenance and actor are server-derived. */
560
+ reconcileLastContact(id, input) {
561
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/runtime/last-contact`, input);
562
+ }
563
+ /** Reserve a durable callback before provider registration returns its signing material. Setup only. */
564
+ prepareExtensionWebhook(id, input) {
565
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/runtime/webhooks/prepare`, input);
566
+ }
567
+ retireExtensionWebhook(id, input) {
568
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/runtime/webhooks/retire`, input);
569
+ }
570
+ /** Registered setup verifier only, after attesting its provider source account. */
571
+ bindExtensionWebhook(id, input) {
572
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/runtime/webhooks`, input);
573
+ }
574
+ extensionWebhooks(id) {
575
+ return this.get(`/v1/extensions/${encodeURIComponent(id)}/runtime/webhooks`);
576
+ }
577
+ extensionCredentials(id, signal) {
578
+ return this.get(`/v1/extensions/${encodeURIComponent(id)}/credentials`, {}, signal);
579
+ }
580
+ createExtensionKey(id, input) {
581
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/keys`, input);
582
+ }
583
+ revokeExtensionCredential(id, credentialId) {
584
+ return this.request(`/v1/extensions/${encodeURIComponent(id)}/credentials/${encodeURIComponent(credentialId)}`, { method: 'DELETE' });
585
+ }
586
+ disableExtension(id) {
587
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/disable`);
588
+ }
589
+ cancelExtensionSuggestions(id, version) {
590
+ const query = version ? `?version=${encodeURIComponent(version)}` : '';
591
+ return this.send('DELETE', `/v1/extensions/${encodeURIComponent(id)}/suggestions${query}`);
592
+ }
593
+ configureExtension(id, version) {
594
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/configure`, {
595
+ version,
596
+ });
597
+ }
598
+ /** An installation's model use this calendar month (UTC). */
599
+ extensionUsage(id, signal) {
600
+ return this.get(`/v1/extensions/${encodeURIComponent(id)}/usage`, undefined, signal);
601
+ }
602
+ extensionSuggestions(id, version, signal) {
603
+ return this.get(`/v1/extensions/${encodeURIComponent(id)}/suggestions`, { version }, signal);
604
+ }
605
+ saveExtensionSuggestions(id, input) {
606
+ return this.send('PUT', `/v1/extensions/${encodeURIComponent(id)}/runtime/suggestions`, input);
607
+ }
608
+ turnOnExtension(id, input, key) {
609
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/turn-on`, input, undefined, key);
610
+ }
611
+ approveExtensionAccess(id, input, key) {
612
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/access`, input, undefined, key);
613
+ }
614
+ uninstallExtension(id) {
615
+ return this.post(`/v1/extensions/${encodeURIComponent(id)}/uninstall`);
616
+ }
617
+ schemaChanges(options = {}) {
618
+ const { signal, ...params } = options;
619
+ return this.get('/v1/schema/changes', params, signal);
620
+ }
621
+ schemaChange(id, signal) {
622
+ return this.get(`/v1/schema/changes/${encodeURIComponent(id)}`, {}, signal);
623
+ }
624
+ /**
625
+ * A change that existing records block comes back as 409 with the change
626
+ * itself (`status: "failed"`, its `error` and the blocking `recordIds`),
627
+ * so it is returned like any other outcome rather than thrown.
628
+ */
629
+ proposeSchemaChange(operations, reason) {
630
+ return this.request('/v1/schema/changes', { method: 'POST', body: JSON.stringify({ operations, reason }) }, isFailedChange);
631
+ }
632
+ decideSchemaChange(id, decision) {
633
+ return this.request(`/v1/schema/changes/${encodeURIComponent(id)}/${decision}`, { method: 'POST' }, isFailedChange);
634
+ }
635
+ // Routines (routines spec §5, §6).
636
+ routineCapabilities(signal) {
637
+ return this.get('/v1/routines/capabilities', {}, signal);
638
+ }
639
+ /** Checks a routine; `wait` seconds for the sandbox's type-check before answering with a job. */
640
+ validateRoutine(input, wait = 15) {
641
+ return this.post(`/v1/routines/validate?wait=${wait}`, input);
642
+ }
643
+ previewRoutine(input) {
644
+ return this.post('/v1/routines/preview', input);
645
+ }
646
+ routinePreview(previewId, signal) {
647
+ return this.get(`/v1/routines/previews/${encodeURIComponent(previewId)}`, {}, signal);
648
+ }
649
+ routineJob(jobId, signal) {
650
+ return this.get(`/v1/routines/jobs/${encodeURIComponent(jobId)}`, {}, signal);
651
+ }
652
+ /** Asks the built-in builder for a routine from a description; poll the job. */
653
+ buildRoutine(description, routineId) {
654
+ return this.post('/v1/routines/build', {
655
+ description,
656
+ ...(routineId ? { routineId } : {}),
657
+ });
658
+ }
659
+ proposeRoutine(input) {
660
+ return this.post('/v1/routines', input);
661
+ }
662
+ routines(signal) {
663
+ return this.get('/v1/routines', {}, signal);
664
+ }
665
+ /** Opens a chat with the workspace agent (docs/specs/agent.md §6.1). */
666
+ dashboards(chatId, signal) {
667
+ return this.get('/v1/dashboards', { chatId }, signal);
668
+ }
669
+ dashboard(id, signal) {
670
+ return this.get(`/v1/dashboards/${encodeURIComponent(id)}`, {}, signal);
671
+ }
672
+ createDashboard(input) {
673
+ return this.post('/v1/dashboards', input);
674
+ }
675
+ updateDashboard(id, input) {
676
+ return this.send('PATCH', `/v1/dashboards/${encodeURIComponent(id)}`, input);
677
+ }
678
+ deleteDashboard(id) {
679
+ return this.send('DELETE', `/v1/dashboards/${encodeURIComponent(id)}`);
680
+ }
681
+ createAgentChat(signal, client) {
682
+ return this.post('/v1/agent/chats', { client }, signal);
683
+ }
684
+ /** The person's chats with the workspace agent. */
685
+ agentChats(signal) {
686
+ return this.get('/v1/agent/chats', {}, signal);
687
+ }
688
+ /** A chat and its messages, as AI SDK UI messages. */
689
+ agentChat(id, signal) {
690
+ return this.get(`/v1/agent/chats/${encodeURIComponent(id)}`, {}, signal);
691
+ }
692
+ /** A short stream token and the URL to send the chat's next message to. */
693
+ agentChatToken(id, signal) {
694
+ return this.post(`/v1/agent/chats/${encodeURIComponent(id)}/token`, {}, signal);
695
+ }
696
+ /** Stops the chat's running turn. */
697
+ cancelAgentChat(id, signal) {
698
+ return this.post(`/v1/agent/chats/${encodeURIComponent(id)}/cancel`, {}, signal);
699
+ }
700
+ deleteAgentChat(id, signal) {
701
+ return this.send('DELETE', `/v1/agent/chats/${encodeURIComponent(id)}`, undefined, signal);
702
+ }
703
+ routine(id, signal) {
704
+ return this.get(`/v1/routines/${encodeURIComponent(id)}`, {}, signal);
705
+ }
706
+ routineRun(id, runId, signal) {
707
+ return this.get(`/v1/routines/${encodeURIComponent(id)}/runs/${encodeURIComponent(runId)}`, {}, signal);
708
+ }
709
+ /** The agent tasks a run started, with their saved messages (agent spec §5.3). */
710
+ routineRunAgentTasks(id, runId, signal) {
711
+ return this.get(`/v1/routines/${encodeURIComponent(id)}/runs/${encodeURIComponent(runId)}/agent-tasks`, {}, signal);
712
+ }
713
+ decideRoutineVersion(id, versionId, decision) {
714
+ return this.post(`/v1/routines/${encodeURIComponent(id)}/versions/${encodeURIComponent(versionId)}/${decision}`, {});
715
+ }
716
+ /** Runs a version once for real, on one record, as the admin who asks. */
717
+ testRoutine(id, versionId, recordId) {
718
+ return this.post(`/v1/routines/${encodeURIComponent(id)}/versions/${encodeURIComponent(versionId)}/test`, { recordId });
719
+ }
720
+ setRoutineState(id, action) {
721
+ return this.post(`/v1/routines/${encodeURIComponent(id)}/${action}`, {});
722
+ }
723
+ releaseHeldRuns(id, action) {
724
+ return this.post(`/v1/routines/${encodeURIComponent(id)}/held`, {
725
+ action,
726
+ });
727
+ }
728
+ /** Runs an active schedule routine's tick now; its regular schedule is unchanged. */
729
+ runRoutineNow(id) {
730
+ return this.post(`/v1/routines/${encodeURIComponent(id)}/run-now`, {});
731
+ }
732
+ runRoutine(id, recordIds) {
733
+ return this.post(`/v1/routines/${encodeURIComponent(id)}/run`, {
734
+ recordIds,
735
+ });
736
+ }
737
+ routineButtons(object, signal) {
738
+ return this.get('/v1/routines/buttons', { object }, signal);
739
+ }
740
+ setTimeZone(timeZone) {
741
+ return this.send('PUT', '/v1/workspace/time-zone', { timeZone });
742
+ }
743
+ }
744
+ const ws = (id) => `/account/workspaces/${encodeURIComponent(id)}`;
745
+ const org = (id) => `/account/organizations/${encodeURIComponent(id)}`;
746
+ const approval = (id) => `/account/cli/approvals/${encodeURIComponent(id)}`;
747
+ export class RetainerAccountClient extends RetainerClient {
748
+ account() {
749
+ return this.get('/account');
750
+ }
751
+ organization(id) {
752
+ return this.get(org(id));
753
+ }
754
+ invitations(id) {
755
+ return this.get(`${org(id)}/invitations`);
756
+ }
757
+ invite(id, input) {
758
+ return this.send('POST', `${org(id)}/invitations`, input);
759
+ }
760
+ revokeInvitation(id, invitationId) {
761
+ return this.send('DELETE', `${org(id)}/invitations/${encodeURIComponent(invitationId)}`);
762
+ }
763
+ members(id) {
764
+ return this.get(`${ws(id)}/members`);
765
+ }
766
+ setMemberRole(target, userId, role) {
767
+ const workspace = 'workspaceId' in target;
768
+ return this.send(workspace ? 'PUT' : 'PATCH', `${workspace ? ws(target.workspaceId) : org(target.organizationId)}/members/${encodeURIComponent(userId)}`, { role });
769
+ }
770
+ removeMember(target, userId) {
771
+ return this.send('DELETE', `${'workspaceId' in target ? ws(target.workspaceId) : org(target.organizationId)}/members/${encodeURIComponent(userId)}`);
772
+ }
773
+ createWorkspace(input) {
774
+ return this.send('POST', '/account/workspaces', input);
775
+ }
776
+ renameWorkspace(id, name) {
777
+ return this.send('PATCH', ws(id), { name });
778
+ }
779
+ deleteWorkspace(id, name) {
780
+ return this.send('DELETE', ws(id), { name });
781
+ }
782
+ keys(id) {
783
+ return this.get(`${ws(id)}/keys`);
784
+ }
785
+ createKey(id, name, access) {
786
+ return this.send('POST', `${ws(id)}/keys`, { name, access });
787
+ }
788
+ revokeKey(id, keyId) {
789
+ return this.send('DELETE', `${ws(id)}/keys/${encodeURIComponent(keyId)}`);
790
+ }
791
+ connections(id) {
792
+ return this.get(id ? `${ws(id)}/connections` : '/account/connections');
793
+ }
794
+ disconnect(id, workspaceId) {
795
+ return this.send('DELETE', `${workspaceId ? ws(workspaceId) : '/account'}/connections/${encodeURIComponent(id)}`);
796
+ }
797
+ startElevation(input) {
798
+ return this.send('POST', '/account/cli/approvals', input);
799
+ }
800
+ approval(id) {
801
+ return this.get(approval(id));
802
+ }
803
+ endElevation(id) {
804
+ return this.send('POST', `${approval(id)}/end`);
805
+ }
806
+ logout() {
807
+ return this.send('DELETE', '/account/cli/login');
808
+ }
809
+ }
810
+ //# sourceMappingURL=index.js.map