@relayhistory/capture 0.0.0 → 0.18.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # Optional RelayHistory plugin
2
+
3
+ Install alongside the local SDK: `npm install ai-hist @relayhistory/capture`.
4
+ This package owns RelayHistory authentication, legacy sharing/replay, a durable
5
+ destination, and explicit readback/source adapters. It depends on the public
6
+ local SDK; installing or configuring it does not log in, read credentials, or
7
+ start uploads. `ai-hist` itself has no cloud package dependency.
8
+
9
+ The matching optional platform package supplies the Rust `relayhistory-plugin`
10
+ helper. Development builds may set `RELAYHISTORY_PLUGIN_BIN` or `binaryPath`.
11
+ No second native addon is needed. The helper preserves existing stage auth files,
12
+ refresh locks, error codes, and legacy cursors. Public error classes come from
13
+ `ai-hist`, so `instanceof` retains one identity.
14
+
15
+ ```sh
16
+ relayhistory-plugin login --base-url https://history.agentrelay.com
17
+ relayhistory-plugin token --base-url https://history.agentrelay.com
18
+ ```
19
+
20
+ Agent Relay Cloud sign-in runs in that Rust helper, not in JavaScript: no Cloud
21
+ SDK is bundled and no JavaScript code reads a Cloud credential. Without
22
+ `--token`, the helper takes `CLOUD_API_ACCESS_TOKEN`, then an unexpired Agent
23
+ Relay CLI session at `~/.agentworkforce/relay/cloud-auth.json` matching
24
+ `CLOUD_API_URL`, and only with a terminal attached the browser/device flow,
25
+ whose approval URL it writes to that terminal. A run with no terminal and no
26
+ credential fails immediately rather than waiting for an approval nobody sees.
27
+
28
+ These commands intentionally remain in the optional package. Replace imports
29
+ from `ai-hist/cloud` with `@relayhistory/capture`; local Git hook/commit-link
30
+ functions stay in `ai-hist`.
31
+
32
+ Create an explicit plugin config, located beside the application's node_modules:
33
+
34
+ ```json
35
+ {"plugins":[{"module":"@relayhistory/capture","options":{"baseUrl":"https://history.agentrelay.com","instanceId":"personal"}}]}
36
+ ```
37
+
38
+ Create a selection file before enabling delivery:
39
+
40
+ ```json
41
+ {"all_sources":false,"sources":["claude","codex"],"sessions":[],"kinds":["history","session_event","tool_call","file_edit","session","presence","relationship","commit_link","trajectory","source_observation","observation_evidence"],"excluded_sessions":[]}
42
+ ```
43
+
44
+ ```sh
45
+ ai-hist plugin relayhistory-migration-status --config history.json
46
+ ai-hist plugin relayhistory-enable --config history.json -- --selection selection.json
47
+ ai-hist delivery run --config history.json
48
+ ai-hist delivery status
49
+ ```
50
+
51
+ Enable creates a new explicit delivery generation. It never interprets a legacy
52
+ positional push cursor as an acknowledgment. Stop/remove old managed launchd or
53
+ cron push schedules first: active schedules block delivery and cannot be
54
+ acknowledged away. If the inspection is unavailable, explicitly set
55
+ `acknowledgeUninspectedLegacySchedules: true` after checking your own schedules;
56
+ this acknowledges an uninspected state, not a verified clear state. Arbitrary
57
+ user-created supervisors remain their owner's responsibility. Migration checks
58
+ are read-only and repeat before prepare/send. Background operation uses the same
59
+ `ai-hist delivery run` coordinator under your existing supervisor.
60
+
61
+ Jobs bind both the canonical service endpoint and the auth-derived organization/
62
+ workspace account. Changing endpoint requires a new instance/job; changing
63
+ account requires a new job. A swapped token cannot send an old account's batch.
64
+ The Rust queue persists the exact prepared bytes before sending. Uncertain
65
+ outcomes retry those bytes; the server accepts exact revision IDs durably in one
66
+ transaction and fences older revisions. No legacy `/ingest` fallback exists.
67
+ Durable acceptance does not promise search indexing. Inspect status for blocked
68
+ jobs, pending bytes and last acknowledgment; fix auth/config then retry explicitly.
69
+
70
+ `deliveryAccount({baseUrl})` resolves the account label. Pin that result as
71
+ `expectedAccount` in plugin options before cloud source acquisition. Remote
72
+ acquisition is selected with `--source-connector cloud --config history.json`.
73
+ The source adapter uses a fresh complete live readback traversal per acquisition;
74
+ cursors are not incremental checkpoints. Normalized evidence enters the local
75
+ engine through revision-fenced public source APIs, with independent connector
76
+ provenance and per-kind snapshots.
77
+
78
+ ```ts
79
+ import { getDeliveredSession, getSessionThreadWithHistory } from '@relayhistory/capture';
80
+ const evidence = await getDeliveredSession({source:'claude',sessionId:'session-id'}, options);
81
+ const thread = await getSessionThreadWithHistory({source:'claude',sessionId:'session-id'}, options);
82
+ ```
83
+
84
+ `getDeliveredSession` retains returned evidence records and projects a chronological
85
+ transcript, preferring session events over prompt fallback. The explicitly
86
+ registered MCP `get_session_thread` includes those records plus legacy lifecycle
87
+ links using one pinned account; `legacyStatus` exposes unavailable legacy data.
88
+ `read_delivered_history` exposes the live listing. Neither tool is present in the
89
+ ordinary local MCP server. Set `AI_HIST_PLUGIN_CONFIG` to register configured tools.
90
+
91
+ The service applies its documented recursive credential scrubbing and omits opaque
92
+ whole-provider blobs. Tool args, patches and normalized evidence remain readable
93
+ within that policy; delivered data is not a byte-exact backup of raw secrets.
94
+ See the repository's `plans/009-delivery-protocol.md` for the wire contract.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env node
2
+ /** Optional compatibility CLI. Local history commands remain in ai-hist. */
3
+ import { accessToken, enableCloud, login, replay } from './cloud-client.js';
4
+ import { createHistoryPlugin } from './plugin.js';
5
+ async function main() {
6
+ const [command, ...args] = process.argv.slice(2).filter(arg => arg !== '--no-warning');
7
+ const flags = new Map();
8
+ const positionals = [];
9
+ const booleans = new Set(['json', 'once', 'help']);
10
+ for (let index = 0; index < args.length; index++) {
11
+ const value = args[index];
12
+ if (value === '-h') {
13
+ flags.set('help', true);
14
+ continue;
15
+ }
16
+ if (!value.startsWith('--')) {
17
+ positionals.push(value);
18
+ continue;
19
+ }
20
+ const [name, inline] = value.slice(2).split(/=(.*)/s);
21
+ if (!['json', 'once', 'help', 'base-url', 'token', 'label', 'db', 'interval', 'limit', 'max-content', 'out'].includes(name))
22
+ throw new Error(`Unknown option --${name}`);
23
+ if (booleans.has(name)) {
24
+ flags.set(name, true);
25
+ continue;
26
+ }
27
+ const text = inline ?? args[++index];
28
+ if (text === undefined)
29
+ throw new Error(`--${name} requires a value`);
30
+ flags.set(name, text);
31
+ }
32
+ const text = (name) => typeof flags.get(name) === 'string' ? flags.get(name) : undefined;
33
+ const number = (name) => { const value = text(name); if (value === undefined)
34
+ return undefined; const n = Number(value); if (!Number.isSafeInteger(n) || n < 0)
35
+ throw new Error(`--${name} must be a non-negative integer`); return n; };
36
+ if (flags.has('help') || !command) {
37
+ process.stdout.write('relayhistory-plugin login|token|replay|enable-cloud [options]\nNew reliable jobs: ai-hist plugin relayhistory-enable --config FILE -- --selection FILE\n');
38
+ return;
39
+ }
40
+ const baseUrl = text('base-url');
41
+ if (command === 'token') {
42
+ if ([...flags.keys()].some(key => key !== 'base-url'))
43
+ throw new Error('token accepts only --base-url');
44
+ if (positionals.length)
45
+ throw new Error('token takes no positional arguments');
46
+ process.stdout.write(`${await accessToken({ baseUrl })}\n`);
47
+ return;
48
+ }
49
+ if (command === 'replay') {
50
+ if (positionals.length !== 1)
51
+ throw new Error('replay requires SESSION_ID');
52
+ const result = await replay(positionals[0], { baseUrl, limit: number('limit'), maxContent: number('max-content'), json: flags.has('json'), out: text('out') });
53
+ if (result.transcript !== null)
54
+ process.stdout.write(result.transcript);
55
+ return;
56
+ }
57
+ if (command === 'login' || command === 'enable-cloud') {
58
+ if (positionals.length)
59
+ throw new Error(`${command} takes no positional arguments`);
60
+ if (command === 'login' && text('token') && !baseUrl)
61
+ throw new Error('login requires --base-url with --token');
62
+ // Agent Relay Cloud sign-in, its credential precedence and its destination
63
+ // gate all run in the Rust helper; this only reports whether a terminal is
64
+ // attached, so a browser approval is never started where nobody sees it.
65
+ const token = text('token');
66
+ if (command === 'login') {
67
+ const auth = await login({ baseUrl, relayAccessToken: token, label: text('label'), ...(token ? {} : { interactive: process.stdin.isTTY === true }) });
68
+ process.stdout.write(flags.has('json') ? JSON.stringify({ ok: true, base_url: auth.baseUrl }) + '\n' : `Logged in to ${auth.baseUrl} (session stored).\n`);
69
+ return;
70
+ }
71
+ const handle = await enableCloud({ baseUrl, dbPath: text('db'), relayAccessToken: token, ...(token ? {} : { interactive: process.stdin.isTTY === true }), intervalMs: (number('interval') ?? 60) * 1000, watch: !flags.has('once'), onPush: result => process.stdout.write(JSON.stringify({ base_url: result.baseUrl, sent: result.sent, accepted: result.accepted, sync_skipped: result.syncSkipped }) + '\n') });
72
+ const { stop, ...result } = handle;
73
+ process.stdout.write(JSON.stringify({ base_url: result.baseUrl, sent: result.sent, accepted: result.accepted, sync_skipped: result.syncSkipped }) + '\n');
74
+ process.once('SIGINT', () => void stop());
75
+ process.once('SIGTERM', () => void stop());
76
+ return;
77
+ }
78
+ const operation = createHistoryPlugin({ baseUrl }).commands?.find(item => item.name === command);
79
+ if (!operation)
80
+ throw new Error('Unknown RelayHistory plugin command');
81
+ process.stdout.write(JSON.stringify(await operation.run(args)) + '\n');
82
+ }
83
+ main().catch(error => { process.stderr.write((error instanceof Error ? error.message : 'RelayHistory operation failed') + '\n'); process.exitCode = 2; });
84
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,4EAA4E;AAC5E,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,KAAK,UAAU,IAAI;IACjB,MAAM,CAAC,OAAO,EAAC,GAAG,IAAI,CAAC,GAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAA,EAAE,CAAA,GAAG,KAAG,cAAc,CAAC,CAAC;IAChF,MAAM,KAAK,GAAC,IAAI,GAAG,EAAsB,CAAC;IAAC,MAAM,WAAW,GAAU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AAQ,EAAC,MAAM,CAAC,OAAO,EAAC,IAAI,EAAC,MAAM,CAAC,IAAI,EAAC,QAAQ,EAAC,MAAM,CAAC,QAAQ,EAAC,YAAY,EAAC,MAAM,CAAC,WAAW,EAAC,CAAC,GAAC,IAAI,CAAC,CAAC;QAAA,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAC,GAAE,EAAE,CAAA,KAAK,IAAI,EAAE,CAAC,CAAC;QAAA,OAAO,CAAC,IAAI,CAAC,SAAS,EAAC,GAAE,EAAE,CAAA,KAAK,IAAI,EAAE,CAAC,CAAC;QAAA,OAAO;IACrQ,CAAC;IACD,MAAM,SAAS,GAAC,mBAAmB,CAAC,EAAC,OAAO,EAAC,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAA,EAAE,CAAA,IAAI,CAAC,IAAI,KAAG,OAAO,CAAC,CAAC;IACzF,IAAG,CAAC,SAAS;QAAC,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACrE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAC,IAAI,CAAC,CAAC;AACvE,CAAC;AACD,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAA,EAAE,GAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,YAAY,KAAK,CAAA,CAAC,CAAA,KAAK,CAAC,OAAO,CAAA,CAAC,CAAA,+BAA+B,CAAC,GAAC,IAAI,CAAC,CAAC,CAAA,OAAO,CAAC,QAAQ,GAAC,CAAC,CAAC,CAAA,CAAC,CAAC,CAAC"}
@@ -0,0 +1,225 @@
1
+ export interface RelayhistoryAuth {
2
+ baseUrl: string;
3
+ accessToken: string;
4
+ refreshToken?: string;
5
+ accessTokenExpiresAt?: string;
6
+ /** Cached provenance; never an authorization selector. */
7
+ orgId?: string;
8
+ workspaceId?: string;
9
+ }
10
+ export type LoginCloudResult = {
11
+ ok: true;
12
+ auth: RelayhistoryAuth;
13
+ } | {
14
+ ok: false;
15
+ error: string;
16
+ };
17
+ export interface CloudPushResult {
18
+ baseUrl: string;
19
+ sent: number;
20
+ accepted: number;
21
+ syncSkipped: boolean;
22
+ }
23
+ /** Return a secret service token with at least 60 seconds of validity. Rust
24
+ * selects the stage, refreshes if needed and atomically saves rotated tokens. */
25
+ export declare function accessToken(options?: {
26
+ baseUrl?: string;
27
+ }): Promise<string>;
28
+ export interface ReplayOptions {
29
+ baseUrl?: string;
30
+ /** Page size, not a total cap; Rust fetches every page in server order. */
31
+ limit?: number;
32
+ maxContent?: number;
33
+ /** Return the raw event array serialized as JSON instead of readable text. */
34
+ json?: boolean;
35
+ /** Atomically save in Rust after all pages succeed; transcript is then null. */
36
+ out?: string;
37
+ }
38
+ export interface ReplayResult {
39
+ eventCount: number;
40
+ transcript: string | null;
41
+ outputPath: string | null;
42
+ }
43
+ /** Fetch a cloud transcript without opening or importing into the local DB. */
44
+ export declare function replay(sessionId: string, options?: ReplayOptions): Promise<ReplayResult>;
45
+ export interface CloudOptions {
46
+ dbPath?: string;
47
+ baseUrl?: string;
48
+ relayAccessToken?: string;
49
+ label?: string;
50
+ /** Without a token, Rust may start the browser device flow only when this is true. */
51
+ interactive?: boolean;
52
+ /** Optional workspace selector for the Cloud sign-in Rust performs. */
53
+ workspace?: string;
54
+ }
55
+ export interface EnableCloudOptions extends CloudOptions {
56
+ /** Keep syncing until stop() is called. Defaults to true. */
57
+ watch?: boolean;
58
+ intervalMs?: number;
59
+ onPush?: (result: CloudPushResult) => void;
60
+ onError?: (error: unknown) => void;
61
+ }
62
+ export interface CloudHandle extends CloudPushResult {
63
+ stop(): Promise<void>;
64
+ }
65
+ /** Both SDK consumers and the engine use the same stage-scoped Rust auth store. */
66
+ export declare function loadStoredRelayhistoryAuth(baseUrl?: string): Promise<RelayhistoryAuth | null>;
67
+ export type CloudSessionResolution = {
68
+ auth: RelayhistoryAuth;
69
+ /** Marks a stored session eligible for native refresh after a 401. Omit for caller-managed auth. */
70
+ session?: true;
71
+ } | {
72
+ auth: null;
73
+ detail: string;
74
+ };
75
+ /** Read-only connector probe; stage selection and eligibility belong to Rust. */
76
+ export declare function resolveCloudSession(baseUrl?: string, now?: number): Promise<CloudSessionResolution>;
77
+ /** Rotate a rejected stored bearer under the native stage lock. */
78
+ export declare function refreshCloudSession(baseUrl: string, rejectedToken: string): Promise<RelayhistoryAuth | null>;
79
+ export interface LoginOptions {
80
+ baseUrl?: string;
81
+ /**
82
+ * An Agent Relay Cloud bearer to exchange. Omit it to let Rust resolve
83
+ * identity itself: `CLOUD_API_ACCESS_TOKEN`, then the Agent Relay CLI session
84
+ * file, then — only with {@link interactive} — the OAuth device flow.
85
+ */
86
+ relayAccessToken?: string;
87
+ label?: string;
88
+ /**
89
+ * Whether Rust may run the browser/device flow and write its approval URL to
90
+ * the controlling terminal. Without it a login that has no usable credential
91
+ * fails fast instead of waiting for an approval nobody can see.
92
+ */
93
+ interactive?: boolean;
94
+ /** Optional workspace selector for the Cloud sign-in Rust performs. */
95
+ workspace?: string;
96
+ }
97
+ /**
98
+ * Exchange an Agent Relay Cloud bearer for a RelayHistory session.
99
+ *
100
+ * Sign-in itself lives in the Rust helper: this passes the request through and
101
+ * never obtains, stores or inspects a Cloud credential in JavaScript.
102
+ */
103
+ export declare function login(options?: LoginOptions): Promise<RelayhistoryAuth>;
104
+ export declare function loginCloud(relayAccessToken: string, options?: {
105
+ baseUrl?: string;
106
+ label?: string;
107
+ }): Promise<LoginCloudResult>;
108
+ export declare function pushCloud(options?: CloudOptions): Promise<CloudPushResult>;
109
+ /** Device login, service-token exchange and first push run in Rust. The optional
110
+ * loop is host orchestration only: no token, refresh, stage or cursor logic in JS.
111
+ * The loop remains in this process; await stop() before shutdown. */
112
+ export declare function enableCloud(options?: EnableCloudOptions): Promise<CloudHandle>;
113
+ export type TraceVisibility = 'public' | 'private' | 'direct-link';
114
+ export interface ShareableTrace {
115
+ url: string;
116
+ visibility: TraceVisibility;
117
+ eventCount: number;
118
+ }
119
+ /** Share the already-pushed, frozen server snapshot of a session. */
120
+ export declare function createShareableTrace(sessionId: string, options: {
121
+ visibility: TraceVisibility;
122
+ source?: string;
123
+ baseUrl?: string;
124
+ }): Promise<ShareableTrace>;
125
+ /**
126
+ * The unsupported-operation message, in the shape the sibling remote
127
+ * connectors use.
128
+ *
129
+ * The leading phrase `no remote provider connectors are configured` is an
130
+ * explicit compatibility contract that callers and tests match on — see
131
+ * `crates/ai-hist/src/remote.rs::unconfigured_message`, whose format this
132
+ * reproduces for the one connector a thread can be served by (`cloud`).
133
+ */
134
+ export declare function cloudUnconfiguredMessage(operation: string, detail: string): string;
135
+ /** One lifecycle link, as the recall API returns it. */
136
+ export interface SessionThreadLink {
137
+ linkKind: string;
138
+ linkRef: string;
139
+ linkUrl: string | null;
140
+ /** ISO 8601, up to six fractional digits. Null for undated links. */
141
+ linkTs: string | null;
142
+ metadata: unknown;
143
+ /** 0..1, converted server-side from stored basis points. */
144
+ confidence: number | null;
145
+ }
146
+ /** One shipped-commit outcome, as the recall API returns it. */
147
+ export interface SessionThreadOutcome {
148
+ commitSha: string;
149
+ shippedAt: string | null;
150
+ reverted: boolean;
151
+ revertedBySha: string | null;
152
+ revertedAt: string | null;
153
+ }
154
+ /**
155
+ * The `GET /v1/sessions/:sessionId/thread` envelope. This is a description of
156
+ * what the recall API returns, not a normalization target: the envelope
157
+ * reaches the caller exactly as the service sent it, so a field this SDK build
158
+ * does not know about is passed through rather than dropped.
159
+ */
160
+ export interface SessionThread {
161
+ session: {
162
+ source: string;
163
+ sessionId: string;
164
+ orgId: string;
165
+ workspaceId: string;
166
+ firstEventAt: string | null;
167
+ lastEventAt: string | null;
168
+ } | null;
169
+ outcomes: SessionThreadOutcome[];
170
+ links: SessionThreadLink[];
171
+ nextCursor: string | null;
172
+ }
173
+ export interface SessionThreadQuery {
174
+ /** Upstream source. Validated against this build's source list. */
175
+ source: string;
176
+ /** The session id. Carried in the path, never as a query parameter. */
177
+ sessionId: string;
178
+ /**
179
+ * Optional `link_kind` filter, at most {@link MAX_THREAD_KINDS} values. Sent
180
+ * comma-separated, as the route expects. Not validated against a fixed list:
181
+ * new lenses add kinds, and the route filters on whatever it is given.
182
+ */
183
+ kinds?: readonly string[];
184
+ /** Optional ISO 8601 lower bound. */
185
+ since?: string;
186
+ /** Opaque page cursor from a previous `nextCursor`. */
187
+ cursor?: string;
188
+ /**
189
+ * Links per page. The route clamps to {@link MIN_THREAD_LIMIT}..{@link
190
+ * MAX_THREAD_LIMIT} and defaults to 100. Only links are paged; outcomes come
191
+ * back whole on every page.
192
+ */
193
+ limit?: number;
194
+ }
195
+ export interface SessionThreadOptions {
196
+ /** Overrides the stored session's base URL. */
197
+ baseUrl?: string;
198
+ /**
199
+ * The connector-status resolver: a usable stored RelayHistory session means
200
+ * the `cloud` connector is configured, and anything else carries the reason
201
+ * it is not. Defaults to {@link resolveCloudSession}.
202
+ * Return `{ auth }` without `session: true` for caller-managed credentials or
203
+ * isolated mocks: a 401 then throws AuthenticationExpiredError without refresh.
204
+ */
205
+ resolveSession?: (requestedBaseUrl?: string) => Promise<CloudSessionResolution>;
206
+ /**
207
+ * Transport for thread GET requests and their retries. Defaults to global fetch.
208
+ * Does not handle authentication requests: stored-session refresh uses Rust's
209
+ * native HTTP client and can make a real network request after a 401, even when
210
+ * this function is a mock. Proxy and TLS settings here do not configure refresh.
211
+ * For isolated mocks, also provide resolveSession returning `{ auth }` without
212
+ * `session: true`, which disables automatic refresh.
213
+ */
214
+ fetchImpl?: typeof fetch;
215
+ }
216
+ /**
217
+ * Fetch one page of a session's lifecycle thread from the recall API.
218
+ *
219
+ * Cloud-only. When no RelayHistory session is stored the `cloud` connector is
220
+ * unconfigured and this throws {@link UnsupportedOperationError} *without
221
+ * performing a network call* — the same classification the native engine gives
222
+ * a remote-only request no connector can serve.
223
+ */
224
+ export declare function getSessionThread(query: SessionThreadQuery, opts?: SessionThreadOptions): Promise<SessionThread>;
225
+ //# sourceMappingURL=cloud-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloud-client.d.ts","sourceRoot":"","sources":["../src/cloud-client.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,0DAA0D;IAC1D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AACD,MAAM,MAAM,gBAAgB,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AACnG,MAAM,WAAW,eAAe;IAAG,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,OAAO,CAAA;CAAE;AAC1G;iFACiF;AACjF,wBAAsB,WAAW,CAAC,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAErF;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8EAA8E;IAC9E,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,gFAAgF;IAChF,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AACD,MAAM,WAAW,YAAY;IAAG,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,UAAU,EAAE,MAAM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