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