@relayhistory/capture 0.0.0 → 0.18.8
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 +94 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +84 -0
- package/dist/cli.js.map +1 -0
- package/dist/cloud-client.d.ts +225 -0
- package/dist/cloud-client.d.ts.map +1 -0
- package/dist/cloud-client.js +276 -0
- package/dist/cloud-client.js.map +1 -0
- package/dist/helper.d.ts +29 -0
- package/dist/helper.d.ts.map +1 -0
- package/dist/helper.js +159 -0
- package/dist/helper.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.d.ts +100 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +452 -0
- package/dist/plugin.js.map +1 -0
- package/dist/plugin.test.d.ts +2 -0
- package/dist/plugin.test.d.ts.map +1 -0
- package/dist/plugin.test.js +295 -0
- package/dist/plugin.test.js.map +1 -0
- package/package.json +55 -3
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/** Cloud API wrappers over the shared Rust engine. */
|
|
2
|
+
import { AuthenticationExpiredError, ConnectorFailureError, InvalidArgumentError, SOURCES, UnsupportedOperationError, isSource, } from 'ai-hist';
|
|
3
|
+
import { helperCall } from './helper.js';
|
|
4
|
+
/** Return a secret service token with at least 60 seconds of validity. Rust
|
|
5
|
+
* selects the stage, refreshes if needed and atomically saves rotated tokens. */
|
|
6
|
+
export async function accessToken(options = {}) {
|
|
7
|
+
return helperCall((native) => native.accessToken(options.baseUrl));
|
|
8
|
+
}
|
|
9
|
+
/** Fetch a cloud transcript without opening or importing into the local DB. */
|
|
10
|
+
export async function replay(sessionId, options = {}) {
|
|
11
|
+
for (const key of ['limit', 'maxContent']) {
|
|
12
|
+
const value = options[key];
|
|
13
|
+
if (value !== undefined && (!Number.isSafeInteger(value) || value < 0 || value > 0xffff_ffff)) {
|
|
14
|
+
throw new InvalidArgumentError(`${key} must be an integer between 0 and 4294967295`, 'INVALID_ARGUMENT');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const result = await helperCall((native) => native.replay(sessionId, options));
|
|
18
|
+
return { eventCount: result.eventCount, transcript: result.transcript ?? null, outputPath: result.outputPath ?? null };
|
|
19
|
+
}
|
|
20
|
+
/** Both SDK consumers and the engine use the same stage-scoped Rust auth store. */
|
|
21
|
+
export async function loadStoredRelayhistoryAuth(baseUrl) {
|
|
22
|
+
return helperCall((native) => native.cloudLoadAuth(baseUrl));
|
|
23
|
+
}
|
|
24
|
+
/** Read-only connector probe; stage selection and eligibility belong to Rust. */
|
|
25
|
+
export async function resolveCloudSession(baseUrl, now = Date.now()) {
|
|
26
|
+
const result = await helperCall((native) => native.cloudResolveSession(baseUrl, now));
|
|
27
|
+
return result.auth
|
|
28
|
+
? { auth: result.auth, session: true }
|
|
29
|
+
: { auth: null, detail: result.detail ?? 'no stored relayhistory session (run `ai-hist login`)' };
|
|
30
|
+
}
|
|
31
|
+
/** Rotate a rejected stored bearer under the native stage lock. */
|
|
32
|
+
export async function refreshCloudSession(baseUrl, rejectedToken) {
|
|
33
|
+
return helperCall((native) => native.cloudRefreshSession(baseUrl, rejectedToken));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Exchange an Agent Relay Cloud bearer for a RelayHistory session.
|
|
37
|
+
*
|
|
38
|
+
* Sign-in itself lives in the Rust helper: this passes the request through and
|
|
39
|
+
* never obtains, stores or inspects a Cloud credential in JavaScript.
|
|
40
|
+
*/
|
|
41
|
+
export async function login(options = {}) {
|
|
42
|
+
return helperCall((native) => native.cloudLogin({
|
|
43
|
+
baseUrl: options.baseUrl,
|
|
44
|
+
relayAccessToken: options.relayAccessToken,
|
|
45
|
+
label: options.label,
|
|
46
|
+
interactive: options.interactive,
|
|
47
|
+
workspace: options.workspace,
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
export async function loginCloud(relayAccessToken, options = {}) {
|
|
51
|
+
try {
|
|
52
|
+
const auth = await login({ ...options, relayAccessToken });
|
|
53
|
+
return { ok: true, auth };
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export async function pushCloud(options = {}) {
|
|
60
|
+
return helperCall((native) => native.pushCloud(options));
|
|
61
|
+
}
|
|
62
|
+
/** Device login, service-token exchange and first push run in Rust. The optional
|
|
63
|
+
* loop is host orchestration only: no token, refresh, stage or cursor logic in JS.
|
|
64
|
+
* The loop remains in this process; await stop() before shutdown. */
|
|
65
|
+
export async function enableCloud(options = {}) {
|
|
66
|
+
const intervalMs = options.intervalMs ?? 60_000;
|
|
67
|
+
if (!Number.isSafeInteger(intervalMs) || intervalMs < 1_000 || intervalMs > 2_147_483_647) {
|
|
68
|
+
throw new InvalidArgumentError('intervalMs must be an integer between 1000 and 2147483647', 'INVALID_ARGUMENT');
|
|
69
|
+
}
|
|
70
|
+
const first = await helperCall((native) => native.enableCloud(options));
|
|
71
|
+
let stopped = false;
|
|
72
|
+
let timer;
|
|
73
|
+
let pending = Promise.resolve();
|
|
74
|
+
const schedule = () => {
|
|
75
|
+
if (stopped || options.watch === false)
|
|
76
|
+
return;
|
|
77
|
+
timer = setTimeout(() => {
|
|
78
|
+
pending = (async () => {
|
|
79
|
+
try {
|
|
80
|
+
const result = await pushCloud({ dbPath: options.dbPath, baseUrl: first.baseUrl });
|
|
81
|
+
options.onPush?.(result);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
if (options.onError)
|
|
85
|
+
options.onError(error);
|
|
86
|
+
else
|
|
87
|
+
process.stderr.write(`ai-hist cloud push failed: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
schedule();
|
|
91
|
+
}
|
|
92
|
+
})();
|
|
93
|
+
}, intervalMs);
|
|
94
|
+
};
|
|
95
|
+
schedule();
|
|
96
|
+
return { ...first, async stop() { stopped = true; clearTimeout(timer); await pending; } };
|
|
97
|
+
}
|
|
98
|
+
/** Share the already-pushed, frozen server snapshot of a session. */
|
|
99
|
+
export async function createShareableTrace(sessionId, options) {
|
|
100
|
+
return helperCall(async (native) => JSON.parse(await native.createShareableTrace(sessionId, options.visibility, options.source, options.baseUrl)));
|
|
101
|
+
}
|
|
102
|
+
// ---------------------------------------------------------------------------
|
|
103
|
+
// Session thread (SPEC §3.4 / §3.5)
|
|
104
|
+
//
|
|
105
|
+
// `get_session_thread` is the *lifecycle* fan-out for one session — the PRs,
|
|
106
|
+
// reviews, commits, incidents, tickets, Slack threads, hotfixes and follow-up
|
|
107
|
+
// sessions the cloud has stitched to it. It is cloud-only on purpose: a thread
|
|
108
|
+
// exists only once the cloud has ingested lens events, so there is no local
|
|
109
|
+
// fallback and no local cache. Threads change as PRs and incidents land, so
|
|
110
|
+
// every call fetches.
|
|
111
|
+
// ---------------------------------------------------------------------------
|
|
112
|
+
/** The operation name the unsupported-operation message is phrased around. */
|
|
113
|
+
const THREAD_OPERATION = 'thread';
|
|
114
|
+
/**
|
|
115
|
+
* Query parameters that select tenancy. Tenancy is derived from the bearer
|
|
116
|
+
* token server-side; sending one of these would be a client asserting its own
|
|
117
|
+
* scope. Mirrors the guard in the Rust transport (`cloud::recall_page`).
|
|
118
|
+
*/
|
|
119
|
+
const TENANCY_PARAMS = new Set([
|
|
120
|
+
'org_id', 'orgId', 'workspace_id', 'workspaceId',
|
|
121
|
+
]);
|
|
122
|
+
const DEFAULT_CLOUD_BASE_URL = 'https://history.agentrelay.com';
|
|
123
|
+
/**
|
|
124
|
+
* A base URL reduced to the identity of its stage, so two spellings of one
|
|
125
|
+
* stage compare equal. Mirrors `cloud::normalized_stage`.
|
|
126
|
+
*
|
|
127
|
+
* Scheme and host are case-insensitive per RFC 3986 and are lowercased; the
|
|
128
|
+
* path is not, and is preserved exactly. A stage mounted under a case-sensitive
|
|
129
|
+
* prefix (`https://host/Recall`) must keep it or the request goes elsewhere.
|
|
130
|
+
*/
|
|
131
|
+
function normalizeStage(baseUrl) {
|
|
132
|
+
const trimmed = baseUrl.trim().replace(/\/+$/, '');
|
|
133
|
+
let parsed;
|
|
134
|
+
try {
|
|
135
|
+
parsed = new URL(trimmed);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
// Not a URL this build can parse: compare it verbatim rather than
|
|
139
|
+
// inventing an origin for it.
|
|
140
|
+
return trimmed;
|
|
141
|
+
}
|
|
142
|
+
return `${parsed.protocol.toLowerCase()}//${parsed.host.toLowerCase()}${parsed.pathname}`
|
|
143
|
+
.replace(/\/+$/, '');
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The unsupported-operation message, in the shape the sibling remote
|
|
147
|
+
* connectors use.
|
|
148
|
+
*
|
|
149
|
+
* The leading phrase `no remote provider connectors are configured` is an
|
|
150
|
+
* explicit compatibility contract that callers and tests match on — see
|
|
151
|
+
* `crates/ai-hist/src/remote.rs::unconfigured_message`, whose format this
|
|
152
|
+
* reproduces for the one connector a thread can be served by (`cloud`).
|
|
153
|
+
*/
|
|
154
|
+
export function cloudUnconfiguredMessage(operation, detail) {
|
|
155
|
+
return `no remote provider connectors are configured: remote session ${operation} is not available (cloud: ${detail})`;
|
|
156
|
+
}
|
|
157
|
+
/** Most `link_kind` values the recall route accepts in one `kinds` filter. */
|
|
158
|
+
const MAX_THREAD_KINDS = 50;
|
|
159
|
+
/** The `limit` range the recall route accepts before clamping. */
|
|
160
|
+
const MIN_THREAD_LIMIT = 1;
|
|
161
|
+
const MAX_THREAD_LIMIT = 500;
|
|
162
|
+
function requireSecureTransport(baseUrl) {
|
|
163
|
+
if (baseUrl.startsWith('https://'))
|
|
164
|
+
return;
|
|
165
|
+
const authority = baseUrl.startsWith('http://') ? baseUrl.slice('http://'.length) : null;
|
|
166
|
+
const hostPort = authority?.split('/')[0];
|
|
167
|
+
// An IPv6 literal is bracketed and full of colons, so the port cannot be
|
|
168
|
+
// split off before the brackets are removed.
|
|
169
|
+
const host = hostPort?.startsWith('[')
|
|
170
|
+
? hostPort.slice(1, hostPort.indexOf(']')).toLowerCase()
|
|
171
|
+
: hostPort?.split(':')[0]?.toLowerCase();
|
|
172
|
+
if (host === 'localhost' || host === '127.0.0.1' || host === '::1')
|
|
173
|
+
return;
|
|
174
|
+
throw new ConnectorFailureError(`refusing to send the relayhistory bearer token in cleartext to \`${baseUrl}\` — use an `
|
|
175
|
+
+ 'https:// endpoint. Plain http:// is accepted only for loopback.', 'CONNECTOR_FAILURE');
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Fetch one page of a session's lifecycle thread from the recall API.
|
|
179
|
+
*
|
|
180
|
+
* Cloud-only. When no RelayHistory session is stored the `cloud` connector is
|
|
181
|
+
* unconfigured and this throws {@link UnsupportedOperationError} *without
|
|
182
|
+
* performing a network call* — the same classification the native engine gives
|
|
183
|
+
* a remote-only request no connector can serve.
|
|
184
|
+
*/
|
|
185
|
+
export async function getSessionThread(query, opts = {}) {
|
|
186
|
+
// A misspelled source is an invalid argument, not an unsupported remote
|
|
187
|
+
// request — reject it with the engine's own message before classifying
|
|
188
|
+
// anything, exactly as `ensure_remote_connectors_configured_for_at` does.
|
|
189
|
+
if (!isSource(query.source)) {
|
|
190
|
+
throw new InvalidArgumentError(`invalid source '${query.source}' (choose from ${SOURCES.join(', ')})`, 'INVALID_ARGUMENT');
|
|
191
|
+
}
|
|
192
|
+
if (typeof query.sessionId !== 'string' || query.sessionId.length === 0) {
|
|
193
|
+
throw new InvalidArgumentError('session_id must be a non-empty string', 'INVALID_ARGUMENT');
|
|
194
|
+
}
|
|
195
|
+
if (query.kinds && query.kinds.length > MAX_THREAD_KINDS) {
|
|
196
|
+
throw new InvalidArgumentError(`kinds accepts at most ${MAX_THREAD_KINDS} values (got ${query.kinds.length})`, 'INVALID_ARGUMENT');
|
|
197
|
+
}
|
|
198
|
+
if (query.limit !== undefined
|
|
199
|
+
&& (!Number.isInteger(query.limit)
|
|
200
|
+
|| query.limit < MIN_THREAD_LIMIT || query.limit > MAX_THREAD_LIMIT)) {
|
|
201
|
+
// Rejected here rather than sent to be clamped, so a caller asking for 5000
|
|
202
|
+
// learns it is getting 500 instead of silently believing it got 5000.
|
|
203
|
+
throw new InvalidArgumentError(`limit must be an integer in ${MIN_THREAD_LIMIT}..${MAX_THREAD_LIMIT} (got ${query.limit})`, 'INVALID_ARGUMENT');
|
|
204
|
+
}
|
|
205
|
+
// A stored session belongs to one stage, so naming a stage selects it rather
|
|
206
|
+
// than redirecting it: sending this stage's bearer token to another host is
|
|
207
|
+
// what `cloud::load_auth`'s `same_stage` check refuses. A stage no stored
|
|
208
|
+
// session can serve is an unconfigured connector, not a request to attempt.
|
|
209
|
+
const resolve = opts.resolveSession ?? resolveCloudSession;
|
|
210
|
+
const resolved = await resolve(opts.baseUrl);
|
|
211
|
+
if (!resolved.auth) {
|
|
212
|
+
throw new UnsupportedOperationError(cloudUnconfiguredMessage(THREAD_OPERATION, resolved.detail), 'UNSUPPORTED_OPERATION');
|
|
213
|
+
}
|
|
214
|
+
const auth = resolved.auth;
|
|
215
|
+
const baseUrl = normalizeStage(auth.baseUrl || DEFAULT_CLOUD_BASE_URL);
|
|
216
|
+
requireSecureTransport(baseUrl);
|
|
217
|
+
const params = new URLSearchParams();
|
|
218
|
+
params.set('source', query.source);
|
|
219
|
+
if (query.kinds?.length)
|
|
220
|
+
params.set('kinds', query.kinds.join(','));
|
|
221
|
+
if (query.since)
|
|
222
|
+
params.set('since', query.since);
|
|
223
|
+
if (query.cursor)
|
|
224
|
+
params.set('cursor', query.cursor);
|
|
225
|
+
if (query.limit !== undefined)
|
|
226
|
+
params.set('limit', String(query.limit));
|
|
227
|
+
for (const key of params.keys()) {
|
|
228
|
+
// Defence in depth: tenancy comes from the token, never a query parameter.
|
|
229
|
+
if (TENANCY_PARAMS.has(key)) {
|
|
230
|
+
throw new InvalidArgumentError('recall tenancy comes from the token, not query parameters', 'INVALID_ARGUMENT');
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const url = `${baseUrl}/v1/sessions/${encodeURIComponent(query.sessionId)}/thread?${params}`;
|
|
234
|
+
const doFetch = opts.fetchImpl ?? fetch;
|
|
235
|
+
const send = async (bearer) => {
|
|
236
|
+
try {
|
|
237
|
+
return await doFetch(url, {
|
|
238
|
+
headers: { Authorization: `Bearer ${bearer}`, Accept: 'application/json' },
|
|
239
|
+
// A redirect would carry the bearer token to whatever the hop names.
|
|
240
|
+
redirect: 'error',
|
|
241
|
+
signal: AbortSignal.timeout(30_000),
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
catch (cause) {
|
|
245
|
+
throw new ConnectorFailureError(`cloud thread request failed: ${cause instanceof Error ? cause.message : String(cause)}`, 'CONNECTOR_FAILURE', { cause });
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
let resp = await send(auth.accessToken);
|
|
249
|
+
// Only sessions resolved from the canonical store can spend a refresh token.
|
|
250
|
+
// Rust serializes rotation with the same stage lock used by native requests.
|
|
251
|
+
if (resp.status === 401 && resolved.session) {
|
|
252
|
+
const refreshed = await refreshCloudSession(auth.baseUrl, auth.accessToken);
|
|
253
|
+
if (refreshed)
|
|
254
|
+
resp = await send(refreshed.accessToken);
|
|
255
|
+
}
|
|
256
|
+
if (resp.status === 401) {
|
|
257
|
+
throw new AuthenticationExpiredError('the stored relayhistory session was rejected (HTTP 401); run `ai-hist login`', 'AUTHENTICATION_EXPIRED');
|
|
258
|
+
}
|
|
259
|
+
if (resp.status === 403) {
|
|
260
|
+
// Authenticated but not permitted: a different session, and a different fix.
|
|
261
|
+
throw new ConnectorFailureError('the stored relayhistory session is not permitted to read this thread (HTTP 403); '
|
|
262
|
+
+ 'it needs the `rth:read` scope', 'CONNECTOR_FAILURE');
|
|
263
|
+
}
|
|
264
|
+
if (!resp.ok) {
|
|
265
|
+
const text = await resp.text().catch(() => '');
|
|
266
|
+
throw new ConnectorFailureError(`cloud thread request failed (HTTP ${resp.status}): ${text.slice(0, 200)}`, 'CONNECTOR_FAILURE');
|
|
267
|
+
}
|
|
268
|
+
try {
|
|
269
|
+
// Passed through unchanged: the recall API owns this shape.
|
|
270
|
+
return (await resp.json());
|
|
271
|
+
}
|
|
272
|
+
catch (cause) {
|
|
273
|
+
throw new ConnectorFailureError('cloud thread response was not valid JSON', 'CONNECTOR_FAILURE', { cause });
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
//# sourceMappingURL=cloud-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloud-client.js","sourceRoot":"","sources":["../src/cloud-client.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,OAAO,EACL,0BAA0B,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,OAAO,EAChF,yBAAyB,EAAE,QAAQ,GACpC,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAazC;iFACiF;AACjF,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,UAAgC,EAAE;IAClE,OAAO,UAAU,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;AACrE,CAAC;AAcD,+EAA+E;AAC/E,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,SAAiB,EAAE,UAAyB,EAAE;IACzE,KAAK,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,YAAY,CAAU,EAAE,CAAC;QACnD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;QAC3B,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,WAAW,CAAC,EAA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;IAC1D,CAAC;IAED,IAAI,IAAI,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;QACxB,MAAM,IAAI,0BAA0B,CAClC,8EAA8E,EAC9E,wBAAwB,CACzB,CAAC;IACJ,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;QACxB,6EAA6E;QAC7E,MAAM,IAAI,qBAAqB,CAC7B,mFAAmF;cAC/E,+BAA+B,EACnC,mBAAmB,CACpB,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;QACb,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;QAC/C,MAAM,IAAI,qBAAqB,CAC7B,qCAAqC,IAAI,CAAC,MAAM,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAC1E,mBAAmB,CACpB,CAAC;IACJ,CAAC;IAED,IAAI,CAAC;QACH,4DAA4D;QAC5D,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAkB,CAAC;IAC9C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,qBAAqB,CAC7B,0CAA0C,EAC1C,mBAAmB,EACnB,EAAE,KAAK,EAAE,CACV,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/dist/helper.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type ChildProcess } from 'node:child_process';
|
|
2
|
+
import type { CloudPushResult, RelayhistoryAuth, ReplayOptions, ReplayResult } from './cloud-client.js';
|
|
3
|
+
export interface HelperOptions {
|
|
4
|
+
binaryPath?: string;
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
timeoutMs?: number;
|
|
7
|
+
}
|
|
8
|
+
/** Only terminate the process tree rooted at the helper we created. POSIX
|
|
9
|
+
* helpers lead a fresh process group; Windows uses taskkill's PID-scoped tree.
|
|
10
|
+
* Cancellation is not complete until the helper's stdio/process is reaped. */
|
|
11
|
+
export declare function terminateHelperTree(child: ChildProcess, closed: Promise<void>, isClosed: () => boolean): Promise<void>;
|
|
12
|
+
export declare function helperRequest<T>(operation: string, args?: Record<string, unknown>, options?: HelperOptions): Promise<T>;
|
|
13
|
+
interface HelperBinding {
|
|
14
|
+
accessToken(baseUrl?: string): Promise<string>;
|
|
15
|
+
replay(sessionId: string, options: ReplayOptions): Promise<ReplayResult>;
|
|
16
|
+
createShareableTrace(sessionId: string, visibility: string, source?: string, baseUrl?: string): Promise<string>;
|
|
17
|
+
cloudLoadAuth(baseUrl?: string): Promise<RelayhistoryAuth | null>;
|
|
18
|
+
cloudResolveSession(baseUrl: string | undefined, now: number): Promise<{
|
|
19
|
+
auth?: RelayhistoryAuth | null;
|
|
20
|
+
detail?: string;
|
|
21
|
+
}>;
|
|
22
|
+
cloudRefreshSession(baseUrl: string, rejectedToken: string): Promise<RelayhistoryAuth | null>;
|
|
23
|
+
cloudLogin(options: object): Promise<RelayhistoryAuth>;
|
|
24
|
+
enableCloud(options: object): Promise<CloudPushResult>;
|
|
25
|
+
pushCloud(options: object): Promise<CloudPushResult>;
|
|
26
|
+
}
|
|
27
|
+
export declare function helperCall<T>(call: (helper: HelperBinding) => Promise<T>): Promise<T>;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAEA,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAK9D,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACxG,MAAM,WAAW,aAAa;IAAG,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAC;I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,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IACvD,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CACtD;AAgBD,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAyB"}
|
package/dist/helper.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/** Bounded, cancellable bridge to the optional RelayHistory Rust executable. */
|
|
2
|
+
import { StringDecoder } from 'node:string_decoder';
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
6
|
+
import { dirname, join } from 'node:path';
|
|
7
|
+
import { RelayHistoryError, InvalidArgumentError, UnsupportedOperationError, AuthenticationExpiredError, ConnectorFailureError, runtimePlatform } from 'ai-hist';
|
|
8
|
+
function packagedBinary() {
|
|
9
|
+
const binary = 'relayhistory-plugin' + (process.platform === 'win32' ? '.exe' : '');
|
|
10
|
+
try {
|
|
11
|
+
return join(dirname(createRequire(import.meta.url).resolve('@relayhistory/capture-' + runtimePlatform() + '/package.json')), binary);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return fileURLToPath(new URL('../bin/' + runtimePlatform() + '/' + binary, import.meta.url));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Only terminate the process tree rooted at the helper we created. POSIX
|
|
18
|
+
* helpers lead a fresh process group; Windows uses taskkill's PID-scoped tree.
|
|
19
|
+
* Cancellation is not complete until the helper's stdio/process is reaped. */
|
|
20
|
+
export async function terminateHelperTree(child, closed, isClosed) {
|
|
21
|
+
if (isClosed())
|
|
22
|
+
return;
|
|
23
|
+
let deadline;
|
|
24
|
+
try {
|
|
25
|
+
await Promise.race([
|
|
26
|
+
(async () => {
|
|
27
|
+
if (child.pid !== undefined) {
|
|
28
|
+
if (process.platform === 'win32') {
|
|
29
|
+
// Do not target a potentially reused PID after observing its exit.
|
|
30
|
+
if (child.exitCode !== null || child.signalCode !== null)
|
|
31
|
+
throw new Error('Helper exited before tree cleanup');
|
|
32
|
+
await new Promise((resolve, reject) => {
|
|
33
|
+
const killer = spawn(join(process.env.SystemRoot ?? 'C:\\Windows', 'System32', 'taskkill.exe'), ['/PID', String(child.pid), '/T', '/F'], { windowsHide: true, stdio: 'ignore' });
|
|
34
|
+
const limit = setTimeout(() => { killer.kill(); reject(new Error('Tree cleanup timed out')); }, 2000);
|
|
35
|
+
killer.once('error', () => { clearTimeout(limit); reject(new Error('Tree cleanup unavailable')); });
|
|
36
|
+
killer.once('close', code => { clearTimeout(limit); if (code === 0)
|
|
37
|
+
resolve();
|
|
38
|
+
else
|
|
39
|
+
reject(new Error('Tree cleanup failed')); });
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
try {
|
|
44
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (error.code !== 'ESRCH')
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
await closed;
|
|
53
|
+
})(),
|
|
54
|
+
new Promise((_resolve, reject) => { deadline = setTimeout(() => reject(new Error('Helper cleanup timed out')), 3000); }),
|
|
55
|
+
]);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// Release our handles even if a broken/escaping subprocess does not close
|
|
59
|
+
// inherited pipes. Report failed cleanup instead of promising cancellation.
|
|
60
|
+
if (child.exitCode === null && child.signalCode === null)
|
|
61
|
+
child.kill('SIGKILL');
|
|
62
|
+
child.stdin?.destroy();
|
|
63
|
+
child.stdout?.destroy();
|
|
64
|
+
child.stderr?.destroy();
|
|
65
|
+
child.unref();
|
|
66
|
+
throw new RelayHistoryError('Helper process tree cleanup failed', 'HISTORY_PLUGIN_CLEANUP_FAILED');
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
if (deadline !== undefined)
|
|
70
|
+
clearTimeout(deadline);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export async function helperRequest(operation, args = {}, options = {}) {
|
|
74
|
+
options.signal?.throwIfAborted();
|
|
75
|
+
const body = JSON.stringify({ version: 1, operation, args });
|
|
76
|
+
if (Buffer.byteLength(body) > 16 * 1_048_576)
|
|
77
|
+
throw new InvalidArgumentError('RelayHistory helper request exceeds 16 MiB', 'INVALID_ARGUMENT');
|
|
78
|
+
const executable = options.binaryPath ?? process.env.RELAYHISTORY_PLUGIN_BIN
|
|
79
|
+
?? packagedBinary();
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
const child = spawn(executable, [], { stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true, detached: process.platform !== 'win32' });
|
|
82
|
+
const decoder = new StringDecoder('utf8');
|
|
83
|
+
let output = '';
|
|
84
|
+
let bytes = 0;
|
|
85
|
+
let settled = false;
|
|
86
|
+
let closed = false;
|
|
87
|
+
const childClosed = new Promise(resolve => child.once('close', () => { closed = true; resolve(); }));
|
|
88
|
+
const finish = (error, value) => {
|
|
89
|
+
if (settled)
|
|
90
|
+
return;
|
|
91
|
+
settled = true;
|
|
92
|
+
clearTimeout(timer);
|
|
93
|
+
options.signal?.removeEventListener('abort', abort);
|
|
94
|
+
if (error) {
|
|
95
|
+
void terminateHelperTree(child, childClosed, () => closed).then(() => reject(error), reject);
|
|
96
|
+
}
|
|
97
|
+
else
|
|
98
|
+
resolve(value);
|
|
99
|
+
};
|
|
100
|
+
const abort = () => finish(new RelayHistoryError('RelayHistory helper operation cancelled', 'HISTORY_PLUGIN_CANCELLED'));
|
|
101
|
+
const timer = setTimeout(() => finish(new RelayHistoryError('RelayHistory helper operation timed out', 'HISTORY_PLUGIN_TIMEOUT')), options.timeoutMs ?? 60_000);
|
|
102
|
+
options.signal?.addEventListener('abort', abort, { once: true });
|
|
103
|
+
child.on('error', () => finish(new RelayHistoryError('RelayHistory helper is unavailable; install its matching platform artifact', 'HISTORY_PLUGIN_BINARY_MISSING')));
|
|
104
|
+
child.stdin.on('error', () => finish(new RelayHistoryError('RelayHistory helper input failed', 'HISTORY_PLUGIN_PROTOCOL_FAILED')));
|
|
105
|
+
// Never forward arbitrary stderr, which could contain auth or history.
|
|
106
|
+
child.stderr.resume();
|
|
107
|
+
child.stdout.on('data', (chunk) => {
|
|
108
|
+
bytes += chunk.length;
|
|
109
|
+
if (bytes > 32 * 1_048_576)
|
|
110
|
+
return finish(new RelayHistoryError('RelayHistory helper response exceeds 32 MiB', 'HISTORY_PLUGIN_PROTOCOL_FAILED'));
|
|
111
|
+
output += decoder.write(chunk);
|
|
112
|
+
});
|
|
113
|
+
child.on('close', code => {
|
|
114
|
+
if (settled)
|
|
115
|
+
return;
|
|
116
|
+
try {
|
|
117
|
+
if (code !== 0)
|
|
118
|
+
throw new Error();
|
|
119
|
+
const envelope = JSON.parse(output + decoder.end());
|
|
120
|
+
if (envelope.version !== 1 || typeof envelope.ok !== 'boolean')
|
|
121
|
+
throw new Error();
|
|
122
|
+
if (!envelope.ok) {
|
|
123
|
+
const code = envelope.error?.code;
|
|
124
|
+
if (typeof code !== 'string' || !/^[A-Z_]{1,100}$/.test(code))
|
|
125
|
+
throw new Error();
|
|
126
|
+
// Stable public classes come from the installed local SDK instance.
|
|
127
|
+
const ErrorType = code === 'INVALID_ARGUMENT' ? InvalidArgumentError
|
|
128
|
+
: code === 'UNSUPPORTED_OPERATION' ? UnsupportedOperationError
|
|
129
|
+
: code === 'AUTHENTICATION_EXPIRED' ? AuthenticationExpiredError
|
|
130
|
+
: code === 'CONNECTOR_FAILURE' ? ConnectorFailureError : RelayHistoryError;
|
|
131
|
+
finish(new ErrorType(`RelayHistory operation failed (${code})`, code));
|
|
132
|
+
}
|
|
133
|
+
else
|
|
134
|
+
finish(undefined, envelope.value);
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
finish(new RelayHistoryError('RelayHistory helper returned an invalid response', 'HISTORY_PLUGIN_PROTOCOL_FAILED'));
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
child.stdin.end(body);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function cloudOptions(value) {
|
|
144
|
+
const options = value;
|
|
145
|
+
return Object.fromEntries(['baseUrl', 'dbPath', 'relayAccessToken', 'label', 'interactive', 'workspace'].map(key => [key, options[key]]));
|
|
146
|
+
}
|
|
147
|
+
const bridge = {
|
|
148
|
+
accessToken: baseUrl => helperRequest('accessToken', { baseUrl }),
|
|
149
|
+
replay: (sessionId, options) => helperRequest('replay', { sessionId, ...options }),
|
|
150
|
+
createShareableTrace: (sessionId, visibility, source, baseUrl) => helperRequest('createShareableTrace', { sessionId, visibility, source, baseUrl }),
|
|
151
|
+
cloudLoadAuth: baseUrl => helperRequest('cloudLoadAuth', { baseUrl }),
|
|
152
|
+
cloudResolveSession: (baseUrl, now) => helperRequest('cloudResolveSession', { baseUrl, now }),
|
|
153
|
+
cloudRefreshSession: (baseUrl, rejectedToken) => helperRequest('cloudRefreshSession', { baseUrl, rejectedToken }),
|
|
154
|
+
cloudLogin: options => helperRequest('cloudLogin', { ...options }, { timeoutMs: 300_000 }),
|
|
155
|
+
enableCloud: options => helperRequest('enableCloud', cloudOptions(options), { timeoutMs: 300_000 }),
|
|
156
|
+
pushCloud: options => helperRequest('pushCloud', cloudOptions(options), { timeoutMs: 300_000 }),
|
|
157
|
+
};
|
|
158
|
+
export function helperCall(call) { return call(bridge); }
|
|
159
|
+
//# sourceMappingURL=helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,KAA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Aa,EAAC,CAAC;IAC5G,UAAU,EAAE,OAAO,CAAC,EAAE,CAAC,aAAa,CAAC,YAAY,EAAC,EAAC,GAAG,OAAO,EAAC,EAAC,EAAC,SAAS,EAAC,OAAO,EAAC,CAAC;IACnF,WAAW,EAAE,OAAO,CAAC,EAAE,CAAC,aAAa,CAAC,aAAa,EAAC,YAAY,CAAC,OAAO,CAAC,EAAC,EAAC,SAAS,EAAC,OAAO,EAAC,CAAC;IAC9F,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC,aAAa,CAAC,WAAW,EAAC,YAAY,CAAC,OAAO,CAAC,EAAC,EAAC,SAAS,EAAC,OAAO,EAAC,CAAC;CAC3F,CAAC;AACF,MAAM,UAAU,UAAU,CAAI,IAA2C,IAAgB,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { type HistoryDestination, type HistoryExportRecord, type HistoryPlugin, type HistorySource } from 'ai-hist';
|
|
2
|
+
import { type HelperOptions } from './helper.js';
|
|
3
|
+
import { type SessionThreadQuery, type SessionThreadOptions } from './cloud-client.js';
|
|
4
|
+
export interface RelayHistoryPluginOptions extends HelperOptions {
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
instanceId?: string;
|
|
7
|
+
expectedAccount?: string;
|
|
8
|
+
acknowledgeUninspectedLegacySchedules?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface DeliveryReadOptions {
|
|
11
|
+
expectedAccount: string;
|
|
12
|
+
kind?: string;
|
|
13
|
+
source?: string;
|
|
14
|
+
sessionId?: string;
|
|
15
|
+
cursor?: string;
|
|
16
|
+
includeDeleted?: boolean;
|
|
17
|
+
limit?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface DeliveryReadPage {
|
|
20
|
+
protocolVersion: 1;
|
|
21
|
+
listing: 'live';
|
|
22
|
+
records: HistoryExportRecord[];
|
|
23
|
+
nextCursor: string | null;
|
|
24
|
+
}
|
|
25
|
+
export declare function deliveryAccount(options?: RelayHistoryPluginOptions): Promise<string>;
|
|
26
|
+
export declare function readDeliveredHistory(query: DeliveryReadOptions, options?: RelayHistoryPluginOptions): Promise<DeliveryReadPage>;
|
|
27
|
+
/** Restart each traversal from the beginning: the live listing is not a change feed. */
|
|
28
|
+
export declare function deliveredHistory(query: Omit<DeliveryReadOptions, 'cursor'>, options?: RelayHistoryPluginOptions): AsyncGenerator<HistoryExportRecord>;
|
|
29
|
+
export declare function projectDeliveredTranscript(records: readonly HistoryExportRecord[]): {
|
|
30
|
+
originId: string;
|
|
31
|
+
recordId: string;
|
|
32
|
+
revisionId: string;
|
|
33
|
+
eventId: string | null;
|
|
34
|
+
timestampMs: number | null;
|
|
35
|
+
role: string;
|
|
36
|
+
text: string;
|
|
37
|
+
representation: import("ai-hist").HistoryEvidenceKind;
|
|
38
|
+
}[];
|
|
39
|
+
export declare function getDeliveredSession(query: {
|
|
40
|
+
source: string;
|
|
41
|
+
sessionId: string;
|
|
42
|
+
}, options?: RelayHistoryPluginOptions): Promise<{
|
|
43
|
+
records: HistoryExportRecord[];
|
|
44
|
+
transcript: {
|
|
45
|
+
originId: string;
|
|
46
|
+
recordId: string;
|
|
47
|
+
revisionId: string;
|
|
48
|
+
eventId: string | null;
|
|
49
|
+
timestampMs: number | null;
|
|
50
|
+
role: string;
|
|
51
|
+
text: string;
|
|
52
|
+
representation: import("ai-hist").HistoryEvidenceKind;
|
|
53
|
+
}[];
|
|
54
|
+
listing: "live";
|
|
55
|
+
}>;
|
|
56
|
+
/** Both components use one pinned account. Legacy reads cannot rotate credentials. */
|
|
57
|
+
export declare function getSessionThreadWithHistory(query: SessionThreadQuery, options?: RelayHistoryPluginOptions & SessionThreadOptions): Promise<{
|
|
58
|
+
legacyStatus: {
|
|
59
|
+
available: boolean;
|
|
60
|
+
code?: string;
|
|
61
|
+
};
|
|
62
|
+
deliveredHistory: HistoryExportRecord[];
|
|
63
|
+
transcript: {
|
|
64
|
+
originId: string;
|
|
65
|
+
recordId: string;
|
|
66
|
+
revisionId: string;
|
|
67
|
+
eventId: string | null;
|
|
68
|
+
timestampMs: number | null;
|
|
69
|
+
role: string;
|
|
70
|
+
text: string;
|
|
71
|
+
representation: import("ai-hist").HistoryEvidenceKind;
|
|
72
|
+
}[];
|
|
73
|
+
historyListing: "live";
|
|
74
|
+
session: {
|
|
75
|
+
source: string;
|
|
76
|
+
sessionId: string;
|
|
77
|
+
orgId: string;
|
|
78
|
+
workspaceId: string;
|
|
79
|
+
firstEventAt: string | null;
|
|
80
|
+
lastEventAt: string | null;
|
|
81
|
+
} | null;
|
|
82
|
+
outcomes: import("./cloud-client.js").SessionThreadOutcome[];
|
|
83
|
+
links: import("./cloud-client.js").SessionThreadLink[];
|
|
84
|
+
nextCursor: string | null;
|
|
85
|
+
}>;
|
|
86
|
+
/** Read-only migration check. Loading the module never inspects or changes services. */
|
|
87
|
+
export interface LegacyScheduleStatus {
|
|
88
|
+
state: 'clear' | 'active' | 'unknown';
|
|
89
|
+
jobs: string[];
|
|
90
|
+
}
|
|
91
|
+
export declare function legacySchedules(options?: HelperOptions): Promise<LegacyScheduleStatus>;
|
|
92
|
+
export declare function relayHistoryInstance(options?: RelayHistoryPluginOptions): string;
|
|
93
|
+
export declare function relayHistoryDestination(options?: RelayHistoryPluginOptions): HistoryDestination;
|
|
94
|
+
/** Cross-origin revisions are incomparable. Pick a stable origin/record winner
|
|
95
|
+
* for each canonical identity; readback still exposes every original record. */
|
|
96
|
+
export declare function canonicalDeliveredEvidence(rows: readonly HistoryExportRecord[]): HistoryExportRecord[];
|
|
97
|
+
export declare function relayHistorySource(options?: RelayHistoryPluginOptions): HistorySource;
|
|
98
|
+
/** Inert registration. Network/auth/service checks occur only in invoked operations. */
|
|
99
|
+
export declare function createHistoryPlugin(options?: RelayHistoryPluginOptions): HistoryPlugin;
|
|
100
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAQL,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EAExB,KAAK,aAAa,EAElB,KAAK,aAAa,EAGnB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAML,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EAE1B,MAAM,mBAAmB,CAAC;AAG3B,MAAM,WAAW,yBAA0B,SAAQ,aAAa;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,qCAAqC,CAAC,EAAE,OAAO,CAAC;CACjD;AACD,MAAM,WAAW,mBAAmB;IAClC,eAAe,EAAE,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AACD,MAAM,WAAW,gBAAgB;IAC/B,eAAe,EAAE,CAAC,CAAC;IAC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