@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.
@@ -0,0 +1,988 @@
1
+ import type { BindingWriteStamp, ExtensionAuthorization, ExtensionAuthorizationCompletion, ExtensionAuthorizeInput, ExtensionBindingChoices, ExtensionConnection, ExtensionConnectionInput, ExtensionInstallation, ExtensionInstallInput, ExtensionManifest, ExtensionOAuthClient, ExtensionPreview, ExtensionRecordButton, ExtensionRecordButtonRun } from '@retainer/extension';
2
+ import type { CreateDashboard, DashboardSummary, OrganizationRole, SavedDashboard, UpdateDashboard, WorkspaceRole } from '@retainer/shared';
3
+ export { isMaintenance, isMaintenanceRead, retryAfterMs, waitForRetry } from './maintenance.js';
4
+ import type { Actor, AddedLinks, AggregateInput, AggregateResult, AssertionView, AttachedEventPage, BulkDeleteImpact, CommentPage, ContextInput, ContextPack, CreateViewInput, DecisionResult, DeleteImpact, DeleteRecordResult, EventAttachment, LogEventInput as EventInput, EventPage, EventQueryInput, ExtensionRunInspection, FactPlace, ForgetResult, LinkedRecordPage, LogEventResult, MergeInput, MergeResult, MergeSuggestionDecision, MoveEventsInput, MoveEventsResult, Page, PresentedComment, PresentedFact, PresentedRecord, ProfileAlias, ProfileContextPack, QueryInput, RecordPage, RetractEventResult, ReviewCollection, ReviewQueue, RoutineButton, RoutineCapabilities, RoutineCheckResult, RoutineDetail, RoutinePreview, RoutineProblem, RoutineReport, RoutineRunAgentTask, RoutineRunView, RoutineView, SavedView, SchemaChange, SchemaChangeResult, SchemaDescription, SchemaOperation, SearchInput, SearchResult, Session, TemplateView, TimelineItemKind, TimelinePage, UpdateViewInput, UpsertRecordsResponse, WorkspaceFeedInput, WorkspaceFeedPage, WriteResponse } from '@retainer/shared';
5
+ export type RetainerClientOptions = {
6
+ /** The Retainer server origin, such as https://retainer.tamloot.cc. */
7
+ baseUrl: string;
8
+ /** Bearer credential: workspace/installation key or a REST installation OAuth access token. */
9
+ apiKey?: string;
10
+ /** A CLI access token issued after browser consent. */
11
+ accessToken?: string;
12
+ /** The browser approval ID for a CLI action that requires individual confirmation. */
13
+ approval?: string;
14
+ /** Fetch credential mode. Defaults to same-origin, which works for Retainer session cookies. */
15
+ credentials?: 'omit' | 'same-origin' | 'include';
16
+ /**
17
+ * The workspace ID for session-cookie or CLI requests. A person
18
+ * can reach several workspaces with one session; an API key belongs to
19
+ * one, so key requests ignore this.
20
+ */
21
+ workspace?: string;
22
+ /** Override fetch, for example to route requests through a proxy. */
23
+ fetch?: typeof fetch;
24
+ /** Called on HTTP 401, except for requests to /auth/session. */
25
+ onUnauthorized?: () => void;
26
+ };
27
+ export type HealthResponse = {
28
+ status: 'ok' | 'error';
29
+ version: string;
30
+ database: 'ok' | 'unreachable';
31
+ };
32
+ export declare class RetainerApiError extends Error {
33
+ readonly status: number;
34
+ readonly code: string;
35
+ readonly details?: Record<string, unknown> | undefined;
36
+ constructor(status: number, code: string, message: string, details?: Record<string, unknown> | undefined);
37
+ }
38
+ export type PageOptions = {
39
+ limit?: number;
40
+ cursor?: string;
41
+ signal?: AbortSignal;
42
+ };
43
+ export type PatchInput = {
44
+ values: Record<string, unknown>;
45
+ expectedUpdatedAt?: string;
46
+ source?: string;
47
+ };
48
+ export type UpsertInput = PatchInput & {
49
+ id?: string;
50
+ match?: Record<string, unknown>;
51
+ ifMissing?: 'fail' | 'create';
52
+ };
53
+ export type UpsertRecordsItem = Omit<UpsertInput, 'values'> & {
54
+ object: string;
55
+ values?: UpsertInput['values'];
56
+ bindings?: BindingWriteStamp;
57
+ /** For creates without id or match. Reuse the same key when retrying this item. */
58
+ idempotencyKey?: string;
59
+ };
60
+ export type { MoveEventsInput, MoveEventsResult };
61
+ export type LogEventInput = EventInput & {
62
+ bindings?: BindingWriteStamp;
63
+ };
64
+ type Participant = {
65
+ handle?: string;
66
+ recordId?: string;
67
+ role?: string;
68
+ };
69
+ export declare class RetainerClient {
70
+ private readonly options;
71
+ private readonly baseUrl;
72
+ private readonly fetchImpl;
73
+ constructor(options: RetainerClientOptions);
74
+ protected headers(): Record<string, string>;
75
+ /** `isResult` lets an error status whose body is a result come back as one. */
76
+ protected request<T>(path: string, init?: RequestInit, isResult?: (body: unknown) => boolean): Promise<T>;
77
+ private query;
78
+ protected get<T>(path: string, params?: Record<string, unknown>, signal?: AbortSignal): Promise<T>;
79
+ protected send<T>(method: string, path: string, body?: unknown, signal?: AbortSignal, idempotencyKey?: string): Promise<T>;
80
+ private post;
81
+ /** Health reports database outages in its response body, including HTTP 503. */
82
+ health(): Promise<HealthResponse>;
83
+ signIn(key: string): Promise<Session>;
84
+ signOut(): Promise<{
85
+ signedOut: true;
86
+ }>;
87
+ me(signal?: AbortSignal): Promise<Session>;
88
+ schema(signal?: AbortSignal): Promise<SchemaDescription>;
89
+ templates(signal?: AbortSignal): Promise<{
90
+ templates: TemplateView[];
91
+ }>;
92
+ applyTemplate(name: string): Promise<SchemaChangeResult>;
93
+ queryRecords(object: string, input?: QueryInput, signal?: AbortSignal): Promise<RecordPage>;
94
+ record(id: string, include?: string[], signal?: AbortSignal): Promise<PresentedRecord>;
95
+ linkedRecords(id: string, options?: PageOptions & {
96
+ object?: string;
97
+ }): Promise<LinkedRecordPage>;
98
+ createRecord(object: string, input: {
99
+ values: Record<string, unknown>;
100
+ source?: string;
101
+ bindings?: BindingWriteStamp;
102
+ }, idempotencyKey?: string): Promise<WriteResponse>;
103
+ upsertRecord(object: string, input: UpsertInput & {
104
+ bindings?: BindingWriteStamp;
105
+ }): Promise<WriteResponse>;
106
+ /** Saves several records. The result at each index is its write response or error. */
107
+ upsertRecords(items: UpsertRecordsItem[]): Promise<UpsertRecordsResponse>;
108
+ patchRecord(id: string, input: PatchInput & {
109
+ bindings?: BindingWriteStamp;
110
+ }): Promise<WriteResponse>;
111
+ /** What deleting the record would delete with it; changes nothing. */
112
+ deleteImpact(id: string, signal?: AbortSignal): Promise<DeleteImpact>;
113
+ /** What deleting several records together would delete with them. */
114
+ bulkDeleteImpact(ids: string[], signal?: AbortSignal): Promise<BulkDeleteImpact>;
115
+ /** The total and requested aggregates over the records a filter matches. */
116
+ aggregate(object: string, input?: AggregateInput, signal?: AbortSignal): Promise<AggregateResult>;
117
+ deleteRecord(id: string, bindings?: BindingWriteStamp): Promise<DeleteRecordResult>;
118
+ /** The object's saved views the caller can see, in their saved order. */
119
+ views(object: string, signal?: AbortSignal): Promise<{
120
+ views: SavedView[];
121
+ }>;
122
+ view(id: string, signal?: AbortSignal): Promise<SavedView>;
123
+ createView(object: string, input: CreateViewInput): Promise<SavedView>;
124
+ /** Changes only the keys given; `null` clears a setting. */
125
+ updateView(id: string, input: UpdateViewInput): Promise<SavedView>;
126
+ deleteView(id: string): Promise<{
127
+ id: string;
128
+ deleted: true;
129
+ }>;
130
+ /** Merges `input.recordId` into `id`, which survives. Retrying with the same key is safe. */
131
+ mergeRecords(id: string, input: MergeInput, idempotencyKey?: string): Promise<MergeResult>;
132
+ /**
133
+ * Deletes the signed-in person's personal memory in this workspace (4.6):
134
+ * web sessions only; agents cannot clear it.
135
+ */
136
+ clearMyMemory(): Promise<{
137
+ cleared: true;
138
+ counts: Record<string, number>;
139
+ }>;
140
+ /** Erases a person and what was logged about them (needs the `admin` scope). Not reversible. */
141
+ forget(id: string): Promise<ForgetResult>;
142
+ search(input: SearchInput, signal?: AbortSignal): Promise<SearchResult>;
143
+ context(id: ProfileAlias, input?: ContextInput, signal?: AbortSignal): Promise<ProfileContextPack>;
144
+ context(id: string, input?: ContextInput, signal?: AbortSignal): Promise<ContextPack>;
145
+ mergeSuggestion(id: string, keep: string): Promise<MergeResult>;
146
+ dismissMergeSuggestion(id: string): Promise<MergeSuggestionDecision>;
147
+ review(options?: Omit<PageOptions, 'cursor'> & Partial<Record<`${ReviewCollection}Cursor`, string>>): Promise<ReviewQueue>;
148
+ assertion(id: string, signal?: AbortSignal): Promise<AssertionView>;
149
+ decideAssertion(id: string, decision: 'accept' | 'reject'): Promise<DecisionResult>;
150
+ assertions(id: string, options?: PageOptions & {
151
+ field?: string;
152
+ }): Promise<Page<AssertionView>>;
153
+ /**
154
+ * Events attached directly to a record, newest first, each with how it is
155
+ * attached (`via`). `link` narrows to participant, about or field.
156
+ */
157
+ recordEvents(id: string, options?: PageOptions & {
158
+ link?: EventAttachment;
159
+ }): Promise<AttachedEventPage>;
160
+ /**
161
+ * A record's timeline (8): events (direct and rolled up, with `via`),
162
+ * values asserted for its fields and its facts, newest first. Filters for
163
+ * one kind (`fields`, `eventTypes`) leave the others out unless `types`
164
+ * names them.
165
+ */
166
+ timeline(id: string, options?: PageOptions & {
167
+ types?: TimelineItemKind[];
168
+ fields?: string[];
169
+ eventTypes?: string[];
170
+ from?: string;
171
+ to?: string;
172
+ }): Promise<TimelinePage>;
173
+ /**
174
+ * A record's current facts, or a profile's: `workspace` for workspace
175
+ * memory, `me` for the caller's personal memory (personal memory spec 4.4).
176
+ */
177
+ facts(id: string, options?: PageOptions): Promise<FactPlace & {
178
+ facts: PresentedFact[];
179
+ nextCursor: string | null;
180
+ }>;
181
+ /**
182
+ * Adds a fact to a record or a profile (`workspace`, `me`). `supersedes`
183
+ * replaces a current fact: on the same record it corrects it, elsewhere it
184
+ * moves it (4.9).
185
+ */
186
+ remember(id: string, input: {
187
+ text: string;
188
+ source?: string;
189
+ quote?: string;
190
+ supersedes?: string;
191
+ }, idempotencyKey?: string): Promise<{
192
+ fact: PresentedFact;
193
+ }>;
194
+ retractFact(id: string): Promise<{
195
+ id: string;
196
+ deleted: true;
197
+ }>;
198
+ /** A record's comments, newest first, with their total. A merged ID follows the merge. */
199
+ listComments(id: string, options?: PageOptions): Promise<CommentPage>;
200
+ /** Adds a comment (a `user` key only). Retrying with the same key adds it once. */
201
+ addComment(id: string, input: {
202
+ body: string;
203
+ }, idempotencyKey?: string): Promise<PresentedComment>;
204
+ /** Edits a comment's body; its author only. */
205
+ editComment(id: string, input: {
206
+ body: string;
207
+ }, idempotencyKey?: string): Promise<PresentedComment>;
208
+ /** Deletes a comment; its author, or a `user` key with `admin`. */
209
+ deleteComment(id: string, idempotencyKey?: string): Promise<{
210
+ id: string;
211
+ deleted: true;
212
+ }>;
213
+ /** One live event: the record with its built-in columns and links. */
214
+ event(id: string, signal?: AbortSignal): Promise<PresentedRecord>;
215
+ /** Events, new records and grouped record writes, newest added first. */
216
+ workspaceFeed(input?: WorkspaceFeedInput, signal?: AbortSignal): Promise<WorkspaceFeedPage>;
217
+ /** Withdraws the field assertions on a Home update card and recomputes affected fields. */
218
+ revertFeedUpdate(id: string, input: {
219
+ recordId: string;
220
+ assertionIds: string[];
221
+ }): Promise<{
222
+ id: string;
223
+ retractedAssertions: number;
224
+ }>;
225
+ /**
226
+ * Events of every event type in one page, newest first (`POST /v1/events/query`).
227
+ * Filters take `type`, `occurredAt`, `channel` and `externalId`; `linked` finds
228
+ * the events attached to one record.
229
+ */
230
+ queryEvents(input?: EventQueryInput, signal?: AbortSignal): Promise<EventPage>;
231
+ /**
232
+ * Logs an event; idempotent by channel and externalId. After creating an
233
+ * unmatched person, re-log with the same handle/role and their recordId.
234
+ * `added.participants.matched` includes participants resolved in place.
235
+ */
236
+ logEvent(input: LogEventInput): Promise<LogEventResult>;
237
+ /**
238
+ * Moves events to another event type, keeping their IDs, identities, links
239
+ * and the claims that cite them (`POST /v1/events/move`). Moving needs a
240
+ * `user` key with the `admin` scope; `dryRun: true` reports the plan with
241
+ * `schema:write` and changes nothing.
242
+ */
243
+ moveEvents(input: MoveEventsInput): Promise<MoveEventsResult>;
244
+ /**
245
+ * Adds links and retries eligible unmatched participants in place; idempotent.
246
+ * Successful resolutions are included in `added.participants.matched`.
247
+ */
248
+ addEventLinks(id: string, input: {
249
+ participants?: Participant[];
250
+ about?: string[];
251
+ bindings?: BindingWriteStamp;
252
+ }): Promise<PresentedRecord & {
253
+ added: AddedLinks;
254
+ }>;
255
+ /** Removes one participant (a person's key only). */
256
+ removeParticipant(id: string, participantId: string): Promise<PresentedRecord>;
257
+ /** Removes a record from an event's `about` list (a person's key only). */
258
+ removeAbout(id: string, recordId: string): Promise<PresentedRecord>;
259
+ /** Deletes an event and retracts the claims that cite it. */
260
+ deleteEvent(id: string, bindings?: BindingWriteStamp): Promise<RetractEventResult>;
261
+ claims(id: string, options?: Omit<PageOptions, 'cursor'> & {
262
+ assertionsCursor?: string;
263
+ factsCursor?: string;
264
+ /** `false` leaves out the event's own logged values, which cite it too. */
265
+ own?: boolean;
266
+ }): Promise<{
267
+ assertions: AssertionView[];
268
+ facts: PresentedFact[];
269
+ nextCursors: {
270
+ assertions: string | null;
271
+ facts: string | null;
272
+ };
273
+ }>;
274
+ fileErasureStatus(ids: string[]): Promise<{
275
+ pending: number;
276
+ succeeded: number;
277
+ jobs: {
278
+ id: string;
279
+ status: string;
280
+ code: string | null;
281
+ }[];
282
+ }>;
283
+ createFileIntent(input: import('@retainer/shared').FileUploadInput, idempotencyKey: string): Promise<{
284
+ id: string;
285
+ upload: import('@retainer/shared').FileTransfer;
286
+ }>;
287
+ finalizeFile(id: string): Promise<Omit<import("@retainer/shared").FileUploadInput, "sourceItemId"> & {
288
+ id: string;
289
+ } & {
290
+ state: 'ready';
291
+ }>;
292
+ file(id: string, signal?: AbortSignal): Promise<import("@retainer/shared").FileView>;
293
+ downloadFile(id: string): Promise<import("@retainer/shared").FileTransfer>;
294
+ extensionCatalog(signal?: AbortSignal): Promise<{
295
+ releases: {
296
+ manifest: ExtensionManifest;
297
+ digest: string;
298
+ actorCeiling: string;
299
+ bindingProposal?: {
300
+ choices: ExtensionBindingChoices;
301
+ proposedBy: Actor;
302
+ };
303
+ }[];
304
+ }>;
305
+ verifySource(installationId: string, input: {
306
+ sharing: 'workspace';
307
+ accountId?: string;
308
+ }): Promise<{
309
+ sourceAccountId: string;
310
+ provider: string;
311
+ identity: string;
312
+ sharing: 'workspace';
313
+ }>;
314
+ reserveSourceItem(installationId: string, input: {
315
+ sourceAccountId: string;
316
+ externalId: string;
317
+ }): Promise<{
318
+ sourceItemId: string;
319
+ }>;
320
+ sourceConnection(installationId: string): Promise<{
321
+ sourceAccountId: string;
322
+ provider: string;
323
+ identity: 'account' | 'global-resource';
324
+ }>;
325
+ sourceSyncStatus(installationId: string, signal?: AbortSignal): Promise<import("@retainer/shared").SourceSyncStatus>;
326
+ beginSourceScan(installationId: string, input: import('@retainer/shared').SourceScan): Promise<{
327
+ scanId: string;
328
+ }>;
329
+ reserveSourceItems(installationId: string, input: {
330
+ sourceAccountId: string;
331
+ externalIds: string[];
332
+ }): Promise<{
333
+ items: ({
334
+ externalId: string;
335
+ sourceItemId: string;
336
+ state: string;
337
+ providerRevision: string | null;
338
+ } | {
339
+ externalId: string;
340
+ code: 'source_erased' | 'source_deleted';
341
+ })[];
342
+ }>;
343
+ sourceItem(installationId: string, itemId: string): Promise<import("@retainer/shared").SourceItemView>;
344
+ changes(input?: {
345
+ after?: string;
346
+ limit?: number;
347
+ signal?: AbortSignal;
348
+ }): Promise<import("@retainer/shared").ChangePage>;
349
+ change(position: string, signal?: AbortSignal): Promise<import("@retainer/shared").RecordChange>;
350
+ gmailImportWindow(installationId: string): Promise<{
351
+ from: number;
352
+ through?: number;
353
+ }>;
354
+ gmailTarget(installationId: string, additionId: string | null, complete?: boolean): Promise<{
355
+ target: {
356
+ id: string;
357
+ email: string;
358
+ from: number;
359
+ through: number;
360
+ } | null;
361
+ }>;
362
+ releaseGmailConnection(installationId: string): Promise<{
363
+ released: true;
364
+ }>;
365
+ prepareGmailMessage(installationId: string, input: {
366
+ from: string[];
367
+ to: string[];
368
+ occurredAt: string;
369
+ messageId: string;
370
+ sourceItemId: string;
371
+ }): Promise<{
372
+ prepared: boolean;
373
+ }>;
374
+ appendGmailMessage(installationId: string, input: {
375
+ sourceItemId: string;
376
+ from: string[];
377
+ to: string[];
378
+ messageId: string;
379
+ threadId: string;
380
+ rfcMessageId?: string;
381
+ occurredAt: string;
382
+ originalDate?: string;
383
+ subject: string;
384
+ body: string;
385
+ targetEmail?: string;
386
+ targetPersonId?: string;
387
+ }): Promise<{
388
+ kind: 'imported';
389
+ messageId: string;
390
+ eventId: string;
391
+ created: boolean;
392
+ } | {
393
+ kind: 'no_match' | 'removed';
394
+ }>;
395
+ /** The full text behind an event (an email's body, a transcript), or its thread's, oldest first. */
396
+ eventContent(eventId: string, after?: string, signal?: AbortSignal): Promise<import("@retainer/shared").EventContentPage>;
397
+ prepareSourceItem(installationId: string, itemId: string, participants: string[]): Promise<{
398
+ prepared: true;
399
+ }>;
400
+ markSourceUnavailable(installationId: string, itemId: string, input: {
401
+ status: 'unavailable' | 'deleted';
402
+ evidence?: 'provider_event' | 'definitive_lookup';
403
+ }): Promise<{
404
+ state: string;
405
+ invalidated: import('@retainer/shared').SourceEventResult['invalidated'];
406
+ }>;
407
+ sourceRecoveryItems(installationId: string, options?: PageOptions): Promise<{
408
+ items: {
409
+ sourceItemId: string;
410
+ }[];
411
+ nextCursor: string | null;
412
+ }>;
413
+ syncSourceEvent(installationId: string, input: import('@retainer/shared').SourceEventImport): Promise<import("@retainer/shared").SourceEventResult>;
414
+ sourceTaskSchema(installationId: string): Promise<import("@retainer/extension").SourceTaskSchema>;
415
+ syncSourceTasks(installationId: string, itemId: string, input: import('@retainer/extension').SourceTaskBatchInput): Promise<import("@retainer/extension").SourceTaskBatchResult>;
416
+ disconnectSource(installationId: string): Promise<{
417
+ disconnected: true;
418
+ }>;
419
+ extensions(signal?: AbortSignal): Promise<{
420
+ installations: ExtensionInstallation[];
421
+ }>;
422
+ /** Standalone apps' sidebar links for the workspace's members (extensions spec 8). */
423
+ extensionLinks(signal?: AbortSignal): Promise<{
424
+ links: import('@retainer/extension').ExtensionAppLink[];
425
+ }>;
426
+ /**
427
+ * A standalone app's own credential writes its installation's generated
428
+ * secret, with revision CAS (extensions spec 8). A `409 revision_conflict`
429
+ * carries the current revision in its details, never the value.
430
+ */
431
+ writeGeneratedSecret(installationId: string, name: string, input: {
432
+ expectedRevision: number | null;
433
+ value: string;
434
+ }): Promise<{
435
+ revision: number;
436
+ }>;
437
+ extension(id: string, signal?: AbortSignal): Promise<ExtensionInstallation & {
438
+ contributions: {
439
+ kind: string;
440
+ universalId: string;
441
+ elementId: string;
442
+ }[];
443
+ }>;
444
+ extensionBindings(id: string, signal?: AbortSignal): Promise<{
445
+ bindings_revision: number;
446
+ createPeople: "contacted_first" | "everyone" | "never";
447
+ bindings: Record<string, {
448
+ status: "incompatible" | "missing" | "ok";
449
+ objects: {
450
+ id: string;
451
+ name: string;
452
+ label: string;
453
+ }[];
454
+ fields: Record<string, {
455
+ id: string;
456
+ name: string;
457
+ label: string;
458
+ values: Record<string, string>;
459
+ }>;
460
+ } | null>;
461
+ }>;
462
+ previewExtension(input: ExtensionInstallInput): Promise<ExtensionPreview>;
463
+ installExtension(input: ExtensionInstallInput & {
464
+ planDigest: string;
465
+ }, idempotencyKey: string): Promise<ExtensionInstallation>;
466
+ extensionConnections(id: string, signal?: AbortSignal): Promise<{
467
+ connections: ExtensionConnection[];
468
+ }>;
469
+ authorizeGmail(id: string, historyDays: number): Promise<{
470
+ attemptId: string;
471
+ connectLink: string;
472
+ sessionToken: string;
473
+ integrationId: string;
474
+ expiresAt: string;
475
+ }>;
476
+ finishGmailAuthorization(id: string, attemptId: string): Promise<{
477
+ pending: true;
478
+ } | {
479
+ id: string;
480
+ state: 'connecting';
481
+ }>;
482
+ stageExtensionConnectionSecret(id: string, input: {
483
+ connectionId?: string;
484
+ name: string;
485
+ value: string;
486
+ }): Promise<{
487
+ pendingSecretId: string;
488
+ installationId: string;
489
+ connectionId: string;
490
+ expiresAt: string;
491
+ }>;
492
+ connectExtension(id: string, input: ExtensionConnectionInput): Promise<{
493
+ id: string;
494
+ state: 'connecting';
495
+ }>;
496
+ /** Start an OAuth connection; navigate the browser to `authorizationUrl`. */
497
+ authorizeExtensionConnection(id: string, input: ExtensionAuthorizeInput): Promise<ExtensionAuthorization>;
498
+ /** Finish the OAuth round trip from the callback page, with the provider's code or error. */
499
+ completeExtensionAuthorization(id: string, input: ExtensionAuthorizationCompletion): Promise<{
500
+ id: string;
501
+ state: 'connecting';
502
+ } | {
503
+ cancelled: true;
504
+ }>;
505
+ /** Hide the release notice the member saw; `at` is `releaseNotice.at`, unchanged. */
506
+ dismissReleaseNotice(id: string, connection: string, at: string): Promise<{
507
+ dismissed: true;
508
+ }>;
509
+ /** The operator's OAuth client, for a live run whose function holds the token secret. */
510
+ extensionOAuthClient(id: string): Promise<ExtensionOAuthClient>;
511
+ disconnectExtension(id: string, connection: string): Promise<{
512
+ disconnected: true;
513
+ }>;
514
+ extensionRuns(id: string, options?: PageOptions & {
515
+ connection?: string;
516
+ status?: 'active' | 'succeeded' | 'failed' | 'cancelled';
517
+ }): Promise<{
518
+ runs: {
519
+ id: string;
520
+ functionId: string;
521
+ functionName?: string | null;
522
+ triggerKind?: string;
523
+ connectionId: string | null;
524
+ status: string;
525
+ attempt: number;
526
+ generation: number;
527
+ releaseDigest: string;
528
+ code: string | null;
529
+ createdAt: string;
530
+ updatedAt: string;
531
+ }[];
532
+ nextCursor: string | null;
533
+ }>;
534
+ inspectExtensionRun(id: string, runId: string, signal?: AbortSignal): Promise<ExtensionRunInspection>;
535
+ extensionRecordButtons(object: string, signal?: AbortSignal): Promise<{
536
+ buttons: ExtensionRecordButton[];
537
+ }>;
538
+ runExtensionRecordButton(button: ExtensionRecordButton, recordId: string): Promise<{
539
+ id: string;
540
+ }>;
541
+ extensionRecordButtonRun(installationId: string, runId: string, signal?: AbortSignal): Promise<ExtensionRecordButtonRun>;
542
+ retryExtensionRun(id: string, runId: string, idempotencyKey: string): Promise<{
543
+ id: string;
544
+ status: string;
545
+ }>;
546
+ upgradeExtension(id: string, input: ExtensionInstallInput & {
547
+ planDigest: string;
548
+ }, idempotencyKey: string): Promise<ExtensionInstallation>;
549
+ reconnectExtension(id: string, connection: string, input: ExtensionConnectionInput & {
550
+ expectedGeneration: number;
551
+ }): Promise<{
552
+ id: string;
553
+ state: 'connecting';
554
+ }>;
555
+ reconnectExtension(id: string, input: ExtensionInstallInput & {
556
+ planDigest: string;
557
+ }, idempotencyKey: string): Promise<ExtensionInstallation>;
558
+ updateExtensionSettings(id: string, input: {
559
+ expectedRevision: number;
560
+ settings: ExtensionInstallInput['settings'];
561
+ }): Promise<ExtensionInstallation>;
562
+ enableExtension(id: string): Promise<ExtensionInstallation>;
563
+ stageExtensionSecret(input: {
564
+ registrationId: string;
565
+ version: string;
566
+ installationId?: string;
567
+ name: string;
568
+ value: string;
569
+ }): Promise<{
570
+ pendingSecretId: string;
571
+ installationId: string;
572
+ expiresAt: string;
573
+ }>;
574
+ /**
575
+ * The fill-only mapped write of a run whose function declares `mappedWrite`:
576
+ * fills only mapped fields that have no value and were not cleared. A
577
+ * `confidence` below the workspace's threshold holds the values for review
578
+ * (agent actors only).
579
+ */
580
+ extensionMappedWrite(installationId: string, input: {
581
+ recordId: string;
582
+ binding: string;
583
+ lookup?: string;
584
+ expectedUpdatedAt?: string;
585
+ values: Record<string, unknown>;
586
+ observedAt?: string;
587
+ confidence?: number;
588
+ }): Promise<{
589
+ outcome: 'applied' | 'skipped';
590
+ reason?: 'record_deleted' | 'record_merged' | 'lookup_changed' | 'nothing_to_fill';
591
+ fields: Record<string, 'applied' | 'populated' | 'cleared' | 'pending_review'>;
592
+ }>;
593
+ /**
594
+ * Queue child jobs and compare-and-set one KV value, all or nothing. A KV
595
+ * value can't be JSON `null` (422 `invalid_input`): a missing key reads as
596
+ * null, and KV has no delete.
597
+ */
598
+ extensionCheckpoint(id: string, input: {
599
+ children: {
600
+ functionId: string;
601
+ input: unknown;
602
+ dedupeKey: string;
603
+ }[];
604
+ scanComplete?: {
605
+ scanId: string;
606
+ through: string;
607
+ };
608
+ kv?: {
609
+ key: string;
610
+ expectedRevision: number | null;
611
+ value: NonNullable<unknown>;
612
+ };
613
+ }): Promise<{
614
+ ids: string[];
615
+ revision?: number;
616
+ }>;
617
+ extensionKv(id: string, key: string): Promise<{
618
+ value: unknown;
619
+ revision: number;
620
+ } | null>;
621
+ extensionSecret(id: string, name: string): Promise<{
622
+ value: string;
623
+ revision: number;
624
+ }>;
625
+ /** Store provider-generated signing/refresh material with revision CAS; live runs only. */
626
+ setExtensionSecret(id: string, name: string, input: {
627
+ expectedRevision: number | null;
628
+ value: string;
629
+ }): Promise<{
630
+ revision: number;
631
+ }>;
632
+ /** Recompute only the release-pinned last-contact fields. Values, provenance and actor are server-derived. */
633
+ reconcileLastContact(id: string, input: {
634
+ kind: 'scan';
635
+ after?: string | null;
636
+ through?: string;
637
+ } | {
638
+ kind: 'records';
639
+ recordIds: string[];
640
+ }): Promise<{
641
+ processed: number;
642
+ changed: number;
643
+ nextAfter: string | null;
644
+ through: string | null;
645
+ }>;
646
+ /** Reserve a durable callback before provider registration returns its signing material. Setup only. */
647
+ prepareExtensionWebhook(id: string, input: {
648
+ route: string;
649
+ }): Promise<{
650
+ bindingId: string;
651
+ url: string;
652
+ }>;
653
+ retireExtensionWebhook(id: string, input: {
654
+ route: string;
655
+ }): Promise<{
656
+ retired: number;
657
+ }>;
658
+ /** Registered setup verifier only, after attesting its provider source account. */
659
+ bindExtensionWebhook(id: string, input: {
660
+ route: string;
661
+ accountHint?: string;
662
+ subscriptionId?: string;
663
+ }): Promise<{
664
+ bindingId: string;
665
+ url: string;
666
+ }>;
667
+ extensionWebhooks(id: string): Promise<{
668
+ bindings: {
669
+ bindingId: string;
670
+ route: string;
671
+ subscriptionId: string | null;
672
+ active: boolean;
673
+ state: 'pending' | 'active' | 'retired';
674
+ url: string;
675
+ }[];
676
+ }>;
677
+ extensionCredentials(id: string, signal?: AbortSignal): Promise<{
678
+ credentials: import('@retainer/extension').ExtensionCredential[];
679
+ }>;
680
+ createExtensionKey(id: string, input: {
681
+ expectedGeneration: number;
682
+ scopes: ('read' | 'write')[];
683
+ }): Promise<{
684
+ id: string;
685
+ key: string;
686
+ prefix: string;
687
+ scopes: ('read' | 'write')[];
688
+ generation: number;
689
+ createdAt: string;
690
+ }>;
691
+ revokeExtensionCredential(id: string, credentialId: string): Promise<{
692
+ revoked: boolean;
693
+ }>;
694
+ disableExtension(id: string): Promise<ExtensionInstallation>;
695
+ cancelExtensionSuggestions(id: string, version?: string): Promise<{
696
+ cancelled: boolean;
697
+ }>;
698
+ configureExtension(id: string, version?: string): Promise<{
699
+ id: string;
700
+ }>;
701
+ /** An installation's model use this calendar month (UTC). */
702
+ extensionUsage(id: string, signal?: AbortSignal): Promise<{
703
+ model: {
704
+ month: string;
705
+ requests: number;
706
+ inputTokens: number;
707
+ outputTokens: number;
708
+ cacheReadTokens: number;
709
+ cacheWriteTokens: number;
710
+ };
711
+ }>;
712
+ extensionSuggestions(id: string, version?: string, signal?: AbortSignal): Promise<import("@retainer/extension").ExtensionSuggestions>;
713
+ saveExtensionSuggestions(id: string, input: {
714
+ bindings?: import('@retainer/extension').ExtensionBindingChoices;
715
+ bindingReasons?: Record<string, string>;
716
+ settings?: Record<string, string | number | boolean>;
717
+ }): Promise<{
718
+ saved: boolean;
719
+ }>;
720
+ turnOnExtension(id: string, input: ExtensionInstallInput & {
721
+ planDigest: string;
722
+ }, key: string): Promise<ExtensionInstallation>;
723
+ approveExtensionAccess(id: string, input: ExtensionInstallInput & {
724
+ planDigest: string;
725
+ }, key: string): Promise<ExtensionInstallation>;
726
+ uninstallExtension(id: string): Promise<ExtensionInstallation>;
727
+ schemaChanges(options?: PageOptions & {
728
+ status?: string;
729
+ }): Promise<{
730
+ changes: SchemaChange[];
731
+ total: number;
732
+ nextCursor: string | null;
733
+ }>;
734
+ schemaChange(id: string, signal?: AbortSignal): Promise<SchemaChange>;
735
+ /**
736
+ * A change that existing records block comes back as 409 with the change
737
+ * itself (`status: "failed"`, its `error` and the blocking `recordIds`),
738
+ * so it is returned like any other outcome rather than thrown.
739
+ */
740
+ proposeSchemaChange(operations: SchemaOperation[], reason?: string): Promise<SchemaChangeResult>;
741
+ decideSchemaChange(id: string, decision: 'approve' | 'reject'): Promise<SchemaChangeResult>;
742
+ routineCapabilities(signal?: AbortSignal): Promise<RoutineCapabilities>;
743
+ /** Checks a routine; `wait` seconds for the sandbox's type-check before answering with a job. */
744
+ validateRoutine(input: {
745
+ manifest: unknown;
746
+ code: string;
747
+ }, wait?: number): Promise<RoutineCheckResult>;
748
+ previewRoutine(input: {
749
+ manifest: unknown;
750
+ code: string;
751
+ }): Promise<{
752
+ valid: boolean;
753
+ problems: RoutineProblem[];
754
+ /** Null when nothing matched recently: there is nothing to dry-run or poll. */
755
+ previewId?: string | null;
756
+ matched?: number;
757
+ done?: boolean;
758
+ }>;
759
+ routinePreview(previewId: string, signal?: AbortSignal): Promise<RoutinePreview>;
760
+ routineJob(jobId: string, signal?: AbortSignal): Promise<RoutineRunView & Partial<RoutineCheckResult>>;
761
+ /** Asks the built-in builder for a routine from a description; poll the job. */
762
+ buildRoutine(description: string, routineId?: string): Promise<{
763
+ jobId: string;
764
+ }>;
765
+ proposeRoutine(input: {
766
+ manifest: unknown;
767
+ code: string;
768
+ name: string;
769
+ description: string;
770
+ summary: string;
771
+ report: RoutineReport;
772
+ routineId?: string;
773
+ }): Promise<{
774
+ routineId: string;
775
+ versionId: string;
776
+ number: number;
777
+ }>;
778
+ routines(signal?: AbortSignal): Promise<{
779
+ timeZone: string;
780
+ routines: RoutineView[];
781
+ }>;
782
+ /** Opens a chat with the workspace agent (docs/specs/agent.md §6.1). */
783
+ dashboards(chatId?: string, signal?: AbortSignal): Promise<{
784
+ dashboards: DashboardSummary[];
785
+ }>;
786
+ dashboard(id: string, signal?: AbortSignal): Promise<SavedDashboard>;
787
+ createDashboard(input: CreateDashboard): Promise<SavedDashboard>;
788
+ updateDashboard(id: string, input: UpdateDashboard): Promise<SavedDashboard>;
789
+ deleteDashboard(id: string): Promise<void>;
790
+ createAgentChat(signal?: AbortSignal, client?: 'web' | 'cli'): Promise<AgentChat>;
791
+ /** The person's chats with the workspace agent. */
792
+ agentChats(signal?: AbortSignal): Promise<{
793
+ chats: AgentChat[];
794
+ }>;
795
+ /** A chat and its messages, as AI SDK UI messages. */
796
+ agentChat(id: string, signal?: AbortSignal): Promise<AgentChatDetail>;
797
+ /** A short stream token and the URL to send the chat's next message to. */
798
+ agentChatToken(id: string, signal?: AbortSignal): Promise<AgentStreamToken>;
799
+ /** Stops the chat's running turn. */
800
+ cancelAgentChat(id: string, signal?: AbortSignal): Promise<{
801
+ cancelled: boolean;
802
+ }>;
803
+ deleteAgentChat(id: string, signal?: AbortSignal): Promise<void>;
804
+ routine(id: string, signal?: AbortSignal): Promise<RoutineDetail>;
805
+ routineRun(id: string, runId: string, signal?: AbortSignal): Promise<RoutineRunView>;
806
+ /** The agent tasks a run started, with their saved messages (agent spec §5.3). */
807
+ routineRunAgentTasks(id: string, runId: string, signal?: AbortSignal): Promise<{
808
+ tasks: RoutineRunAgentTask[];
809
+ }>;
810
+ decideRoutineVersion(id: string, versionId: string, decision: 'approve' | 'reject'): Promise<{
811
+ routineId: string;
812
+ versionId: string;
813
+ state?: string;
814
+ status?: string;
815
+ discardedRuns?: number;
816
+ }>;
817
+ /** Runs a version once for real, on one record, as the admin who asks. */
818
+ testRoutine(id: string, versionId: string, recordId: string | null): Promise<{
819
+ runId: string;
820
+ }>;
821
+ setRoutineState(id: string, action: 'pause' | 'resume' | 'archive'): Promise<{
822
+ routineId: string;
823
+ status: RoutineView['status'];
824
+ }>;
825
+ releaseHeldRuns(id: string, action: 'run' | 'discard'): Promise<{
826
+ routineId: string;
827
+ queued?: number;
828
+ discarded?: number;
829
+ }>;
830
+ /** Runs an active schedule routine's tick now; its regular schedule is unchanged. */
831
+ runRoutineNow(id: string): Promise<{
832
+ routineId: string;
833
+ queued: number;
834
+ held?: number;
835
+ matched?: number;
836
+ }>;
837
+ runRoutine(id: string, recordIds: string[]): Promise<{
838
+ runs: string[];
839
+ }>;
840
+ routineButtons(object: string, signal?: AbortSignal): Promise<{
841
+ buttons: RoutineButton[];
842
+ }>;
843
+ setTimeZone(timeZone: string): Promise<{
844
+ timeZone: string;
845
+ }>;
846
+ }
847
+ export type AgentChat = {
848
+ id: string;
849
+ title: string | null;
850
+ createdAt: string;
851
+ lastActiveAt?: string;
852
+ status?: string;
853
+ };
854
+ export type AgentChatDetail = {
855
+ id: string;
856
+ title: string | null;
857
+ running: boolean;
858
+ /**
859
+ * The last turn was stopped and the runtime hasn't finished stopping: a step it
860
+ * was on may still be saved, so read the chat again shortly.
861
+ */
862
+ stopping?: boolean;
863
+ /** Oldest first; each turn that didn't complete ends with a `data-turn-end` part. */
864
+ messages: Array<{
865
+ id: string;
866
+ role: string;
867
+ parts: Array<Record<string, unknown>>;
868
+ }>;
869
+ };
870
+ export type AgentStreamToken = {
871
+ token: string;
872
+ expiresAt: string;
873
+ streamUrl: string;
874
+ };
875
+ export type CliApprovalRequest = {
876
+ id: string;
877
+ url: string;
878
+ expiresAt: string;
879
+ };
880
+ export type CliApproval = {
881
+ id: string;
882
+ kind: 'elevation' | 'action';
883
+ status: 'pending' | 'approved' | 'denied' | 'used' | 'ended' | 'expired';
884
+ expiresAt: string;
885
+ resultId: string | null;
886
+ workspaceId?: string;
887
+ organizationId?: string;
888
+ targetName: string;
889
+ };
890
+ export type CliWorkspace = {
891
+ id: string;
892
+ slug: string;
893
+ name: string;
894
+ role: WorkspaceRole;
895
+ };
896
+ export type CliOrganization = {
897
+ id: string;
898
+ name: string;
899
+ role: OrganizationRole;
900
+ workspaces: CliWorkspace[];
901
+ };
902
+ export type CliAccount = {
903
+ user: {
904
+ id: string;
905
+ email: string;
906
+ name: string;
907
+ };
908
+ organizations: CliOrganization[];
909
+ elevations: CliApproval[];
910
+ };
911
+ type Member = {
912
+ userId: string;
913
+ email: string;
914
+ name: string;
915
+ role: OrganizationRole | WorkspaceRole;
916
+ };
917
+ type Connection = {
918
+ id: string;
919
+ workspace: Pick<CliWorkspace, 'id' | 'slug' | 'name'> | null;
920
+ };
921
+ export declare class RetainerAccountClient extends RetainerClient {
922
+ account(): Promise<CliAccount>;
923
+ organization(id: string): Promise<CliOrganization & {
924
+ members: Member[];
925
+ }>;
926
+ invitations(id: string): Promise<{
927
+ invitations: unknown[];
928
+ }>;
929
+ invite(id: string, input: {
930
+ email: string;
931
+ role: string;
932
+ workspaces: {
933
+ workspaceId: string;
934
+ role: string;
935
+ }[];
936
+ }): Promise<{
937
+ id: string;
938
+ link: string;
939
+ expiresAt: string;
940
+ }>;
941
+ revokeInvitation(id: string, invitationId: string): Promise<void>;
942
+ members(id: string): Promise<{
943
+ members: Member[];
944
+ }>;
945
+ setMemberRole(target: {
946
+ workspaceId: string;
947
+ } | {
948
+ organizationId: string;
949
+ }, userId: string, role: string): Promise<void>;
950
+ removeMember(target: {
951
+ workspaceId: string;
952
+ } | {
953
+ organizationId: string;
954
+ }, userId: string): Promise<void>;
955
+ createWorkspace(input: {
956
+ name: string;
957
+ organizationId: string;
958
+ template?: string;
959
+ }): Promise<{
960
+ workspace: CliWorkspace;
961
+ }>;
962
+ renameWorkspace(id: string, name: string): Promise<CliWorkspace>;
963
+ deleteWorkspace(id: string, name: string): Promise<{
964
+ id: string;
965
+ purgeAfter: string;
966
+ }>;
967
+ keys(id: string): Promise<{
968
+ keys: unknown[];
969
+ }>;
970
+ createKey(id: string, name: string, access: string): Promise<{
971
+ id: string;
972
+ key: string;
973
+ }>;
974
+ revokeKey(id: string, keyId: string): Promise<void>;
975
+ connections(id?: string): Promise<{
976
+ connections: Connection[];
977
+ }>;
978
+ disconnect(id: string, workspaceId?: string): Promise<void>;
979
+ startElevation(input: {
980
+ workspaceId?: string;
981
+ organizationId?: string;
982
+ minutes?: number;
983
+ reason?: string;
984
+ }): Promise<CliApprovalRequest>;
985
+ approval(id: string): Promise<CliApproval>;
986
+ endElevation(id: string): Promise<void>;
987
+ logout(): Promise<void>;
988
+ }