@ai-matrx/kit 0.12.1 → 0.13.2
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/CHANGELOG.md +31 -0
- package/README.md +3 -0
- package/dist/content-transfer.cjs +1356 -0
- package/dist/content-transfer.cjs.map +1 -0
- package/dist/content-transfer.d.cts +356 -0
- package/dist/content-transfer.d.ts +356 -0
- package/dist/content-transfer.js +1323 -0
- package/dist/content-transfer.js.map +1 -0
- package/dist/index.cjs +1207 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +356 -1
- package/dist/index.d.ts +356 -1
- package/dist/index.js +1207 -3
- package/dist/index.js.map +1 -1
- package/package.json +14 -2
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
/** Framework-neutral transfer contracts. All data crossing this boundary is JSON. */
|
|
2
|
+
type Json = null | boolean | number | string | Json[] | {
|
|
3
|
+
[key: string]: Json;
|
|
4
|
+
};
|
|
5
|
+
type Payload = {
|
|
6
|
+
kind: "text";
|
|
7
|
+
text: string;
|
|
8
|
+
} | {
|
|
9
|
+
kind: "markdown";
|
|
10
|
+
text: string;
|
|
11
|
+
} | {
|
|
12
|
+
kind: "json";
|
|
13
|
+
value: Json;
|
|
14
|
+
} | {
|
|
15
|
+
kind: "rows";
|
|
16
|
+
rows: Record<string, Json>[];
|
|
17
|
+
columns: Column[];
|
|
18
|
+
} | {
|
|
19
|
+
kind: "registered";
|
|
20
|
+
format: string;
|
|
21
|
+
value: Json;
|
|
22
|
+
};
|
|
23
|
+
type Column = {
|
|
24
|
+
id: string;
|
|
25
|
+
label: string;
|
|
26
|
+
path: string;
|
|
27
|
+
visible: boolean;
|
|
28
|
+
exportable?: boolean;
|
|
29
|
+
classification?: "ordinary" | "secret" | "credential";
|
|
30
|
+
};
|
|
31
|
+
type ExportProjection = {
|
|
32
|
+
rules: {
|
|
33
|
+
target: "payload" | "row";
|
|
34
|
+
path: string;
|
|
35
|
+
exportable: boolean;
|
|
36
|
+
classification: "ordinary" | "secret" | "credential";
|
|
37
|
+
}[];
|
|
38
|
+
};
|
|
39
|
+
type TransferScope = "target" | "row" | "selected" | "view" | "loaded" | "all-matching";
|
|
40
|
+
type Section = {
|
|
41
|
+
id: string;
|
|
42
|
+
label: string;
|
|
43
|
+
path: string;
|
|
44
|
+
includedByDefault: boolean;
|
|
45
|
+
};
|
|
46
|
+
type Coverage = {
|
|
47
|
+
status: "complete" | "loaded" | "partial" | "unknown";
|
|
48
|
+
included: number;
|
|
49
|
+
total: number | null;
|
|
50
|
+
reason?: string;
|
|
51
|
+
};
|
|
52
|
+
type Omission = {
|
|
53
|
+
path: string;
|
|
54
|
+
reason: "excluded" | "filtered" | "truncated" | "unsupported" | "escaped" | "duplicate";
|
|
55
|
+
count?: number;
|
|
56
|
+
};
|
|
57
|
+
type RawSnapshot = {
|
|
58
|
+
id: string;
|
|
59
|
+
sourceId: string;
|
|
60
|
+
revision: string;
|
|
61
|
+
capturedAt: string;
|
|
62
|
+
label: string;
|
|
63
|
+
payload: Payload;
|
|
64
|
+
coverage: Coverage;
|
|
65
|
+
unsavedChanges: boolean;
|
|
66
|
+
omissions: Omission[];
|
|
67
|
+
sections: Section[];
|
|
68
|
+
limits?: TransferLimits;
|
|
69
|
+
};
|
|
70
|
+
declare const projected: unique symbol;
|
|
71
|
+
type Snapshot = RawSnapshot & {
|
|
72
|
+
readonly [projected]: true;
|
|
73
|
+
};
|
|
74
|
+
type QuerySnapshot = {
|
|
75
|
+
sourceId: string;
|
|
76
|
+
revision: string;
|
|
77
|
+
query: Json;
|
|
78
|
+
order: {
|
|
79
|
+
field: string;
|
|
80
|
+
direction: "asc" | "desc";
|
|
81
|
+
}[];
|
|
82
|
+
};
|
|
83
|
+
type ExportPage = {
|
|
84
|
+
rows: Record<string, Json>[];
|
|
85
|
+
nextCursor: string | null;
|
|
86
|
+
coverage: Coverage;
|
|
87
|
+
consistencyToken: string | null;
|
|
88
|
+
};
|
|
89
|
+
type CapturedAllMatching = {
|
|
90
|
+
query: QuerySnapshot;
|
|
91
|
+
getRowId(row: Record<string, Json>): string;
|
|
92
|
+
page(request: {
|
|
93
|
+
query: QuerySnapshot;
|
|
94
|
+
cursor: string | null;
|
|
95
|
+
consistencyToken: string | null;
|
|
96
|
+
signal: AbortSignal;
|
|
97
|
+
}): Promise<ExportPage>;
|
|
98
|
+
stableSnapshot?: boolean;
|
|
99
|
+
};
|
|
100
|
+
type CapturedSource = {
|
|
101
|
+
snapshot: RawSnapshot;
|
|
102
|
+
projection: ExportProjection;
|
|
103
|
+
allMatching?: CapturedAllMatching;
|
|
104
|
+
};
|
|
105
|
+
type Source = {
|
|
106
|
+
id: string;
|
|
107
|
+
label: string;
|
|
108
|
+
capture(request: {
|
|
109
|
+
scope: TransferScope;
|
|
110
|
+
signal: AbortSignal;
|
|
111
|
+
}): Promise<CapturedSource>;
|
|
112
|
+
};
|
|
113
|
+
type Draft = {
|
|
114
|
+
snapshotId: string;
|
|
115
|
+
sourceId: string;
|
|
116
|
+
sourceRevision: string;
|
|
117
|
+
revision: number;
|
|
118
|
+
payload: Payload;
|
|
119
|
+
omissions: Omission[];
|
|
120
|
+
manuallyEdited: boolean;
|
|
121
|
+
provenance: {
|
|
122
|
+
kind: "original" | "deterministic" | "manual" | "ai";
|
|
123
|
+
operationId?: string;
|
|
124
|
+
description: string;
|
|
125
|
+
}[];
|
|
126
|
+
/** Frozen prior states, with history omitted to avoid recursive duplication. */
|
|
127
|
+
history?: readonly Omit<Draft, "history">[];
|
|
128
|
+
};
|
|
129
|
+
type Transform = {
|
|
130
|
+
id: string;
|
|
131
|
+
apply(draft: Draft, options: Json, signal: AbortSignal): Promise<Draft>;
|
|
132
|
+
};
|
|
133
|
+
type Artifact = {
|
|
134
|
+
snapshotId: string;
|
|
135
|
+
draftRevision: number;
|
|
136
|
+
format: string;
|
|
137
|
+
plainText: string;
|
|
138
|
+
html?: string;
|
|
139
|
+
file?: {
|
|
140
|
+
filename: string;
|
|
141
|
+
mime: string;
|
|
142
|
+
bytes: Uint8Array;
|
|
143
|
+
};
|
|
144
|
+
omissions: Omission[];
|
|
145
|
+
};
|
|
146
|
+
type FormatAdapter = {
|
|
147
|
+
id: string;
|
|
148
|
+
label: string;
|
|
149
|
+
supports(payload: Payload): boolean;
|
|
150
|
+
build(draft: Draft, signal: AbortSignal): Promise<Artifact>;
|
|
151
|
+
};
|
|
152
|
+
type TransferOutcome = {
|
|
153
|
+
status: "success";
|
|
154
|
+
delivered: "clipboard" | "download-started" | "action";
|
|
155
|
+
mimeTypes: string[];
|
|
156
|
+
/** Host-provided completion text for an explicit page action. */
|
|
157
|
+
message?: string;
|
|
158
|
+
} | {
|
|
159
|
+
status: "degraded";
|
|
160
|
+
delivered: "plain-text";
|
|
161
|
+
reason: string;
|
|
162
|
+
} | {
|
|
163
|
+
status: "cancelled";
|
|
164
|
+
} | {
|
|
165
|
+
status: "error";
|
|
166
|
+
code: string;
|
|
167
|
+
message: string;
|
|
168
|
+
retryable: boolean;
|
|
169
|
+
};
|
|
170
|
+
type Transport = {
|
|
171
|
+
copy(artifact: Artifact, signal: AbortSignal): Promise<TransferOutcome>;
|
|
172
|
+
download(artifact: Artifact, signal: AbortSignal): Promise<TransferOutcome>;
|
|
173
|
+
};
|
|
174
|
+
type SurfaceHandle = {
|
|
175
|
+
instanceId: string;
|
|
176
|
+
surfaceName: string;
|
|
177
|
+
isMounted(): boolean;
|
|
178
|
+
capture(signal: AbortSignal): Promise<CapturedSource>;
|
|
179
|
+
};
|
|
180
|
+
type AiPreparation = {
|
|
181
|
+
supports(snapshot: Snapshot): boolean;
|
|
182
|
+
run(request: {
|
|
183
|
+
snapshot: Snapshot;
|
|
184
|
+
draft: Draft;
|
|
185
|
+
instruction: string;
|
|
186
|
+
signal: AbortSignal;
|
|
187
|
+
}): Promise<Draft>;
|
|
188
|
+
/** Create an isolated adapter session for one preparation workspace. */
|
|
189
|
+
fork?(): AiPreparation;
|
|
190
|
+
/** Cancel the retained provider request; closing a host UI does not imply this. */
|
|
191
|
+
cancel?(): Promise<void>;
|
|
192
|
+
/** Revalidate the frozen source and recover a previously saved provider result. */
|
|
193
|
+
recover?(input: {
|
|
194
|
+
snapshot: Snapshot;
|
|
195
|
+
draft: Draft;
|
|
196
|
+
signal: AbortSignal;
|
|
197
|
+
}): Promise<Draft>;
|
|
198
|
+
};
|
|
199
|
+
type TransferLimits = {
|
|
200
|
+
maxRows: number | null;
|
|
201
|
+
maxStringChars: number | null;
|
|
202
|
+
maxDepth: number | null;
|
|
203
|
+
maxArrayItems?: number | null;
|
|
204
|
+
targetTokens: number | null;
|
|
205
|
+
};
|
|
206
|
+
type TransferPreferences = {
|
|
207
|
+
initialFormat: string;
|
|
208
|
+
initialPreset: "full" | "compact" | "brief";
|
|
209
|
+
limits: TransferLimits;
|
|
210
|
+
};
|
|
211
|
+
type PageAction = {
|
|
212
|
+
/** Alternate click-time source, captured through the same projection and limits before run. */
|
|
213
|
+
source?: Source;
|
|
214
|
+
id: string;
|
|
215
|
+
label: string;
|
|
216
|
+
supports(snapshot: Snapshot): boolean;
|
|
217
|
+
run(request: {
|
|
218
|
+
snapshot: Snapshot;
|
|
219
|
+
draft: Draft;
|
|
220
|
+
signal: AbortSignal;
|
|
221
|
+
}): Promise<TransferOutcome>;
|
|
222
|
+
};
|
|
223
|
+
type TransferCapabilities = {
|
|
224
|
+
formats?: FormatAdapter[];
|
|
225
|
+
ai?: AiPreparation;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
/** Matrx's portable, source-labelled envelope for external AI tools. */
|
|
229
|
+
interface AgentPayloadInput {
|
|
230
|
+
kind: string;
|
|
231
|
+
location: string;
|
|
232
|
+
description: string;
|
|
233
|
+
data: unknown;
|
|
234
|
+
summary?: string;
|
|
235
|
+
attributes?: Record<string, string | number | boolean | null | undefined>;
|
|
236
|
+
context?: Record<string, string | number | boolean | null | undefined>;
|
|
237
|
+
}
|
|
238
|
+
interface AgentPayloadEnvironment {
|
|
239
|
+
url?: string;
|
|
240
|
+
route?: string;
|
|
241
|
+
capturedAt?: string;
|
|
242
|
+
}
|
|
243
|
+
/** A fence longer than any content fence prevents accidental Markdown closure. */
|
|
244
|
+
declare function fenceJsonBlock(json: string): string;
|
|
245
|
+
/** Capture location at invocation; environment injection makes non-browser use explicit. */
|
|
246
|
+
declare function buildAgentPayload(input: AgentPayloadInput, environment?: AgentPayloadEnvironment): string;
|
|
247
|
+
|
|
248
|
+
declare class ContentTransferError extends Error {
|
|
249
|
+
readonly code: string;
|
|
250
|
+
readonly path: string | undefined;
|
|
251
|
+
constructor(code: string, message: string, path?: string);
|
|
252
|
+
}
|
|
253
|
+
declare const bound: unique symbol;
|
|
254
|
+
type BoundAllMatching = {
|
|
255
|
+
readonly [bound]: true;
|
|
256
|
+
readonly source: CapturedAllMatching;
|
|
257
|
+
readonly projection: ExportProjection;
|
|
258
|
+
readonly columns: readonly Column[];
|
|
259
|
+
readonly limits?: TransferLimits;
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
* Validates arbitrary host data at the transfer boundary and returns a detached
|
|
263
|
+
* JSON value. This deliberately shares the capture validator: undefined,
|
|
264
|
+
* functions, dates, non-finite numbers, and cycles are rejected rather than
|
|
265
|
+
* silently coerced by a JSON stringify round trip.
|
|
266
|
+
*/
|
|
267
|
+
declare function normalizeTransferJson(value: unknown): Json;
|
|
268
|
+
/** Column ids are identities, never an alternative data address. */
|
|
269
|
+
declare function readTransferCell(row: Record<string, Json>, column: Column): Json | undefined;
|
|
270
|
+
declare function projectSnapshot(raw: RawSnapshot, projection: ExportProjection): Snapshot;
|
|
271
|
+
declare function directSource(payload: Payload, options?: Partial<Pick<RawSnapshot, "id" | "sourceId" | "revision" | "label" | "coverage" | "unsavedChanges" | "sections" | "limits"> & {
|
|
272
|
+
projection: ExportProjection;
|
|
273
|
+
}>): CapturedSource;
|
|
274
|
+
declare function capture(source: Source | Payload, signal: AbortSignal, scope?: TransferScope): Promise<{
|
|
275
|
+
snapshot: Snapshot;
|
|
276
|
+
allMatching?: BoundAllMatching;
|
|
277
|
+
}>;
|
|
278
|
+
declare function createDraft(s: Snapshot): Draft;
|
|
279
|
+
declare const editDraft: (d: Draft, p: Payload) => Draft;
|
|
280
|
+
declare const resetDraft: (s: Snapshot) => Draft;
|
|
281
|
+
declare const sourceChanged: (d: Draft, s: Snapshot) => boolean;
|
|
282
|
+
declare function undoDraft(d: Draft): Draft;
|
|
283
|
+
/** Keep and regenerate are explicit choices; observing fresh data never overwrites edits. */
|
|
284
|
+
declare function refreshDraft(draft: Draft, snapshot: Snapshot, choice: "keep" | "regenerate"): Draft;
|
|
285
|
+
declare function applySectionSelection(d: Draft, s: Snapshot, ids: readonly string[]): Draft;
|
|
286
|
+
declare function transformRows(d: Draft, o: {
|
|
287
|
+
search?: string;
|
|
288
|
+
sort?: {
|
|
289
|
+
column: string;
|
|
290
|
+
direction: "asc" | "desc";
|
|
291
|
+
};
|
|
292
|
+
filters?: Readonly<Record<string, string>>;
|
|
293
|
+
/** Positions in this call's input draft rows; unlike ids, no guessed key is used. */
|
|
294
|
+
selectedIndices?: readonly number[];
|
|
295
|
+
selectedIds?: readonly string[];
|
|
296
|
+
idColumn?: string;
|
|
297
|
+
visibleColumns?: readonly string[];
|
|
298
|
+
structuredProjection?: "full" | "visible";
|
|
299
|
+
top?: number | null;
|
|
300
|
+
}): Draft;
|
|
301
|
+
declare function reduceJson(draft: Draft, options: {
|
|
302
|
+
exclude?: readonly string[];
|
|
303
|
+
maxDepth?: number | null;
|
|
304
|
+
maxStringChars?: number | null;
|
|
305
|
+
maxArrayItems?: number | null;
|
|
306
|
+
}): Draft;
|
|
307
|
+
declare function collectAllMatching(c: BoundAllMatching, signal: AbortSignal): Promise<{
|
|
308
|
+
rows: Record<string, Json>[];
|
|
309
|
+
coverage: RawSnapshot["coverage"];
|
|
310
|
+
omissions: Omission[];
|
|
311
|
+
error?: ContentTransferError;
|
|
312
|
+
}>;
|
|
313
|
+
/** Preserve artifact-byte identity even if a consumer mutates a returned view. */
|
|
314
|
+
declare function sealTransferArtifact(artifact: Artifact): Artifact;
|
|
315
|
+
declare function serialize(draft: Draft, format: "plain" | "markdown" | "json" | "compact-json" | "csv" | "tsv" | "html", options?: {
|
|
316
|
+
spreadsheetSafe?: boolean;
|
|
317
|
+
filename?: string;
|
|
318
|
+
}): Artifact;
|
|
319
|
+
declare function renderMarkdownHtml(markdown: string): Promise<string>;
|
|
320
|
+
declare function serializeMarkdownRich(d: Draft, filename?: string): Promise<Artifact>;
|
|
321
|
+
declare function createBrowserTransport(): Transport;
|
|
322
|
+
type TransferPreferenceOverrides = Partial<Omit<TransferPreferences, "limits">> & {
|
|
323
|
+
limits?: Partial<TransferLimits>;
|
|
324
|
+
};
|
|
325
|
+
/** Restrictions intersect: neither a menu nor a provider can relax a source limit. */
|
|
326
|
+
declare function resolveTransferPreferences(provider?: TransferPreferenceOverrides, menu?: TransferPreferenceOverrides, sourceLimits?: Partial<TransferLimits>): TransferPreferences;
|
|
327
|
+
/** One stable id per registered format or action; ambiguous overrides fail loudly. */
|
|
328
|
+
declare function resolveTransferRegistry<T extends {
|
|
329
|
+
id: string;
|
|
330
|
+
}>(...groups: readonly (readonly T[])[]): readonly T[];
|
|
331
|
+
type TransferSurfaceDeclaration = {
|
|
332
|
+
surfaceName: string;
|
|
333
|
+
label?: string;
|
|
334
|
+
values: readonly {
|
|
335
|
+
name: string;
|
|
336
|
+
label: string;
|
|
337
|
+
exportable?: boolean;
|
|
338
|
+
classification?: "ordinary" | "secret" | "credential";
|
|
339
|
+
includedByDefault?: boolean;
|
|
340
|
+
}[];
|
|
341
|
+
};
|
|
342
|
+
/** A structural adapter to the actual mounted surface, never a global name lookup. */
|
|
343
|
+
declare function createSurfaceTransferHandle(options: {
|
|
344
|
+
instanceId: string;
|
|
345
|
+
manifest: TransferSurfaceDeclaration;
|
|
346
|
+
isMounted(): boolean;
|
|
347
|
+
getScope(): Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
348
|
+
getRevision?(): string;
|
|
349
|
+
unsavedChanges?(): boolean;
|
|
350
|
+
projection?: ExportProjection;
|
|
351
|
+
limits?: TransferLimits;
|
|
352
|
+
}): SurfaceHandle;
|
|
353
|
+
/** Applies explicit preparation/source limits with exact omissions; token target is advisory. */
|
|
354
|
+
declare function applyTransferLimits(draft: Draft, limits: Partial<TransferLimits>): Draft;
|
|
355
|
+
|
|
356
|
+
export { type AgentPayloadEnvironment, type AgentPayloadInput, type AiPreparation, type Artifact, type BoundAllMatching, type CapturedAllMatching, type CapturedSource, type Column, ContentTransferError, type Coverage, type Draft, type ExportPage, type ExportProjection, type FormatAdapter, type Json, type Omission, type PageAction, type Payload, type QuerySnapshot, type RawSnapshot, type Section, type Snapshot, type Source, type SurfaceHandle, type TransferCapabilities, type TransferLimits, type TransferOutcome, type TransferPreferenceOverrides, type TransferPreferences, type TransferScope, type TransferSurfaceDeclaration, type Transform, type Transport, applySectionSelection, applyTransferLimits, buildAgentPayload, capture, collectAllMatching, createBrowserTransport, createDraft, createSurfaceTransferHandle, directSource, editDraft, fenceJsonBlock, normalizeTransferJson, projectSnapshot, readTransferCell, reduceJson, refreshDraft, renderMarkdownHtml, resetDraft, resolveTransferPreferences, resolveTransferRegistry, sealTransferArtifact, serialize, serializeMarkdownRich, sourceChanged, transformRows, undoDraft };
|