@ai-matrx/alchemy 0.6.2 → 0.8.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.
Files changed (113) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/dist/actions.cjs +374 -0
  3. package/dist/actions.cjs.map +1 -0
  4. package/dist/actions.d.cts +773 -0
  5. package/dist/actions.d.ts +773 -0
  6. package/dist/actions.js +351 -0
  7. package/dist/actions.js.map +1 -0
  8. package/dist/checks.cjs +31 -2
  9. package/dist/checks.cjs.map +1 -1
  10. package/dist/checks.d.cts +24 -1
  11. package/dist/checks.d.ts +24 -1
  12. package/dist/checks.js +31 -2
  13. package/dist/checks.js.map +1 -1
  14. package/dist/core.cjs +1757 -2
  15. package/dist/core.cjs.map +1 -1
  16. package/dist/core.d.cts +595 -1
  17. package/dist/core.d.ts +595 -1
  18. package/dist/core.js +1749 -2
  19. package/dist/core.js.map +1 -1
  20. package/dist/declare.cjs +12 -10
  21. package/dist/declare.cjs.map +1 -1
  22. package/dist/declare.d.cts +18 -2
  23. package/dist/declare.d.ts +18 -2
  24. package/dist/declare.js +12 -10
  25. package/dist/declare.js.map +1 -1
  26. package/dist/index.cjs +1757 -2
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +595 -1
  29. package/dist/index.d.ts +595 -1
  30. package/dist/index.js +1749 -2
  31. package/dist/index.js.map +1 -1
  32. package/dist/menu.cjs +436 -0
  33. package/dist/menu.cjs.map +1 -0
  34. package/dist/menu.d.cts +834 -0
  35. package/dist/menu.d.ts +834 -0
  36. package/dist/menu.js +413 -0
  37. package/dist/menu.js.map +1 -0
  38. package/dist/operate-document.cjs +163 -0
  39. package/dist/operate-document.cjs.map +1 -0
  40. package/dist/operate-document.d.cts +132 -0
  41. package/dist/operate-document.d.ts +132 -0
  42. package/dist/operate-document.js +130 -0
  43. package/dist/operate-document.js.map +1 -0
  44. package/dist/operate-rich-html.cjs +129 -0
  45. package/dist/operate-rich-html.cjs.map +1 -0
  46. package/dist/operate-rich-html.d.cts +136 -0
  47. package/dist/operate-rich-html.d.ts +136 -0
  48. package/dist/operate-rich-html.js +96 -0
  49. package/dist/operate-rich-html.js.map +1 -0
  50. package/dist/operate-server.cjs +157 -0
  51. package/dist/operate-server.cjs.map +1 -0
  52. package/dist/operate-server.d.cts +183 -0
  53. package/dist/operate-server.d.ts +183 -0
  54. package/dist/operate-server.js +134 -0
  55. package/dist/operate-server.js.map +1 -0
  56. package/dist/operate-xlsx.cjs +248 -0
  57. package/dist/operate-xlsx.cjs.map +1 -0
  58. package/dist/operate-xlsx.d.cts +129 -0
  59. package/dist/operate-xlsx.d.ts +129 -0
  60. package/dist/operate-xlsx.js +215 -0
  61. package/dist/operate-xlsx.js.map +1 -0
  62. package/dist/operate.cjs +1774 -0
  63. package/dist/operate.cjs.map +1 -0
  64. package/dist/operate.d.cts +595 -0
  65. package/dist/operate.d.ts +595 -0
  66. package/dist/operate.js +1750 -0
  67. package/dist/operate.js.map +1 -0
  68. package/dist/ports.cjs.map +1 -1
  69. package/dist/ports.d.cts +361 -3
  70. package/dist/ports.d.ts +361 -3
  71. package/dist/react-bar.cjs +686 -0
  72. package/dist/react-bar.cjs.map +1 -0
  73. package/dist/react-bar.d.cts +379 -0
  74. package/dist/react-bar.d.ts +379 -0
  75. package/dist/react-bar.js +665 -0
  76. package/dist/react-bar.js.map +1 -0
  77. package/dist/react-host.cjs +301 -0
  78. package/dist/react-host.cjs.map +1 -0
  79. package/dist/react-host.d.cts +820 -0
  80. package/dist/react-host.d.ts +820 -0
  81. package/dist/react-host.js +269 -0
  82. package/dist/react-host.js.map +1 -0
  83. package/dist/react-menu.cjs +735 -0
  84. package/dist/react-menu.cjs.map +1 -0
  85. package/dist/react-menu.d.cts +370 -0
  86. package/dist/react-menu.d.ts +370 -0
  87. package/dist/react-menu.js +722 -0
  88. package/dist/react-menu.js.map +1 -0
  89. package/dist/react-overflow.cjs +592 -0
  90. package/dist/react-overflow.cjs.map +1 -0
  91. package/dist/react-overflow.d.cts +817 -0
  92. package/dist/react-overflow.d.ts +817 -0
  93. package/dist/react-overflow.js +571 -0
  94. package/dist/react-overflow.js.map +1 -0
  95. package/dist/react-palette.cjs +489 -0
  96. package/dist/react-palette.cjs.map +1 -0
  97. package/dist/react-palette.d.cts +359 -0
  98. package/dist/react-palette.d.ts +359 -0
  99. package/dist/react-palette.js +457 -0
  100. package/dist/react-palette.js.map +1 -0
  101. package/dist/react-selection.cjs +617 -0
  102. package/dist/react-selection.cjs.map +1 -0
  103. package/dist/react-selection.d.cts +357 -0
  104. package/dist/react-selection.d.ts +357 -0
  105. package/dist/react-selection.js +596 -0
  106. package/dist/react-selection.js.map +1 -0
  107. package/dist/react-sheet.cjs +616 -0
  108. package/dist/react-sheet.cjs.map +1 -0
  109. package/dist/react-sheet.d.cts +361 -0
  110. package/dist/react-sheet.d.ts +361 -0
  111. package/dist/react-sheet.js +595 -0
  112. package/dist/react-sheet.js.map +1 -0
  113. package/package.json +148 -5
@@ -0,0 +1,379 @@
1
+ import { TransferOutcome } from '@ai-matrx/kit/content-transfer';
2
+ import * as React from 'react';
3
+
4
+ /**
5
+ * Matrx Alchemy — Declare types (CONTRACT §2.1).
6
+ *
7
+ * A declaration is plain JSON data (chair ruling N2): no functions, no classes,
8
+ * no React. Runtime behaviour lives in `MountedSurface` (`/declare/host`) and in
9
+ * handler registrations, never here. Zero React, zero `@ai-matrx/agents`.
10
+ */
11
+ type Json = null | boolean | number | string | Json[] | {
12
+ [key: string]: Json;
13
+ };
14
+ /** Unchanged from `ui_surface_value_type_chk`. */
15
+ type ValueType = "string" | "number" | "boolean" | "object" | "array" | "document";
16
+ type Classification = "ordinary" | "secret" | "credential";
17
+ /** Persisted (CONTRACT §2.7). Projection enforces it before any value leaves. */
18
+ interface Sensitivity {
19
+ /** false = never leaves through Operate. Default true. */
20
+ exportable: boolean;
21
+ /** secret/credential are always excluded; no caller can relax this. Default "ordinary". */
22
+ classification: Classification;
23
+ /** Pre-checked in the preparation workspace. Default true. */
24
+ includedByDefault: boolean;
25
+ }
26
+ interface ValueGroup {
27
+ key: string;
28
+ label: string;
29
+ sortOrder: number;
30
+ description?: string;
31
+ }
32
+ /** The four runtime slots a capture fills (absorbs page-capture). */
33
+ type LiveSlot = "selection" | "on-demand" | "errors" | "requests";
34
+ interface DeclaredValue {
35
+ name: string;
36
+ label: string;
37
+ description: string;
38
+ valueType: ValueType;
39
+ /** Registered content-ir kind key (DB: kind_key). */
40
+ valueKind?: string;
41
+ alwaysAvailable: boolean;
42
+ typicalCharCount: number;
43
+ autoContext?: boolean;
44
+ group?: string;
45
+ sortOrder?: number;
46
+ sensitivity?: Partial<Sensitivity>;
47
+ /** Filled at capture time from a live slot instead of the scope. */
48
+ liveSlot?: LiveSlot;
49
+ /** "request" values drop out of "Only the data". Default "data". */
50
+ role?: "data" | "request";
51
+ }
52
+ /** Where a write lands. "stream" = applied live, op by op, into an editable text. */
53
+ type WriteMode = "draft" | "entity" | "ui" | "stream";
54
+ /** Who may apply WITHOUT a click. "queued" = filed for an organization's review. */
55
+ type ApplyPolicy = "manual" | "ask" | "auto" | "queued";
56
+ /** The WidgetHandle text op set, unchanged in meaning. */
57
+ type StreamOp = "replace" | "insert_before" | "insert_after" | "prepend" | "append" | "patch";
58
+ interface WriteTarget {
59
+ name: string;
60
+ label: string;
61
+ description: string;
62
+ valueType: ValueType;
63
+ valueKind?: string;
64
+ /** Read twin (evidence loop). Required when patchable or mode === "stream". */
65
+ updatesValue?: string;
66
+ patchable?: boolean;
67
+ approvalComparison?: "text-replacement";
68
+ mode: WriteMode;
69
+ /** Required iff mode === "stream". */
70
+ streamOps?: readonly StreamOp[];
71
+ /** Default "manual". Binding overrides may only tighten. */
72
+ applyPolicy?: ApplyPolicy;
73
+ destination?: boolean;
74
+ /** Present when the target writes into an item rather than the screen. */
75
+ itemType?: string;
76
+ group?: string;
77
+ sortOrder?: number;
78
+ }
79
+ /** One kind of thing inside a screen (a row, a message, a code block, a card). */
80
+ interface ItemType {
81
+ name: string;
82
+ label: string;
83
+ description: string;
84
+ /** Value names that together identify one item. */
85
+ identity: readonly string[];
86
+ levels?: readonly string[];
87
+ entityType?: string;
88
+ values: readonly DeclaredValue[];
89
+ writeTargets?: readonly WriteTarget[];
90
+ }
91
+ type Readiness = "verified" | "partial" | "stub";
92
+ /** `ui_surface_execution_mode_check`, unchanged. */
93
+ type ExecutionMode = "python-stream" | "nextjs-stream" | "browser-realtime" | "local-runtime";
94
+ interface ConfigNamespaceDeclaration {
95
+ namespace: string;
96
+ label: string;
97
+ description: string;
98
+ }
99
+ interface EvidenceSourceDeclaration {
100
+ kind: "processed_document";
101
+ idValue: string;
102
+ fileIdValue?: string;
103
+ labelValue?: string;
104
+ representation?: "clean" | "raw";
105
+ }
106
+ /**
107
+ * One screen's declaration. Owning packages add fields (agent roles, client
108
+ * tools) as EXTENSION SLOTS — by interface extension or declaration merging —
109
+ * and register a `DeclarationExtension` so validation and the sync cover them.
110
+ */
111
+ interface SurfaceDeclaration {
112
+ surfaceName: string;
113
+ /** REQUIRED. `ui_surface.client_name`; must equal the surfaceName prefix. */
114
+ client: string;
115
+ /** REQUIRED. `ui_surface.execution_mode`. */
116
+ executionMode: ExecutionMode;
117
+ /** REQUIRED. `ui_surface.description` ("" only where the live row is empty). */
118
+ description: string;
119
+ label: string;
120
+ readiness: Readiness;
121
+ readinessNote?: string;
122
+ urlPattern?: string;
123
+ inheritsFrom?: string;
124
+ intro?: string;
125
+ overlayId?: string;
126
+ values: readonly DeclaredValue[];
127
+ groups?: readonly ValueGroup[];
128
+ writeTargets?: readonly WriteTarget[];
129
+ itemTypes?: readonly ItemType[];
130
+ liveSlots?: readonly LiveSlot[];
131
+ configNamespaces?: readonly ConfigNamespaceDeclaration[];
132
+ evidenceSources?: readonly EvidenceSourceDeclaration[];
133
+ skipBaselineValues?: boolean;
134
+ }
135
+ type ValueProvenance = {
136
+ kind: "own";
137
+ } | {
138
+ kind: "inherited";
139
+ from: string;
140
+ } | {
141
+ kind: "baseline";
142
+ };
143
+ type ResolvedValue = DeclaredValue & {
144
+ provenance: ValueProvenance;
145
+ groupKey: string;
146
+ /** Defaults filled. */
147
+ resolvedSensitivity: Sensitivity;
148
+ };
149
+ interface ResolvedSurfaceDeclaration extends SurfaceDeclaration {
150
+ contentHash: string;
151
+ values: readonly ResolvedValue[];
152
+ groups: readonly ValueGroup[];
153
+ }
154
+ /**
155
+ * ITEM KEYS. A value or write target is identified by (surfaceName, itemType ?? "", name).
156
+ * The qualified key "<itemType>.<name>" names an item value; a bare name is a screen value.
157
+ */
158
+ type QualifiedValueKey = string;
159
+ /** Live slot payloads (page-capture's shapes, kept). */
160
+ interface LiveValues {
161
+ selection?: {
162
+ choices: Record<string, Json>;
163
+ text: string | null;
164
+ };
165
+ "on-demand"?: readonly OnDemandSection[];
166
+ errors?: readonly string[];
167
+ requests?: readonly RecentRequest[];
168
+ }
169
+ interface OnDemandSection {
170
+ id: string;
171
+ title: string;
172
+ description?: string;
173
+ role: "data" | "request";
174
+ brief?: Json;
175
+ load(signal: AbortSignal): Promise<Json>;
176
+ }
177
+ interface RecentRequest {
178
+ method: string;
179
+ path: string;
180
+ status: string;
181
+ httpStatus?: number;
182
+ durationMs?: number;
183
+ requestId?: string;
184
+ client?: string;
185
+ requestBody?: Json;
186
+ requestBodyNote?: string;
187
+ errorSentence?: string;
188
+ timestamp: number;
189
+ }
190
+ /** RAW-FREE. What leaves the package about a clicked item. */
191
+ interface ResolvedItem {
192
+ itemType: string;
193
+ identity: Record<string, string>;
194
+ level?: string;
195
+ readOnly: boolean;
196
+ }
197
+
198
+ /**
199
+ * The click target (CONTRACT §2.4) in its own module: `/ports` references it,
200
+ * and `/ports` must stay free of every other package (types only).
201
+ */
202
+
203
+ /** The transfer Payload's kinds (`actions/types.ts` asserts equality at compile time). */
204
+ type PayloadKind = "text" | "markdown" | "json" | "rows" | "registered";
205
+ /** What eligibility is computed from: everything declared at the click target. */
206
+ interface ClickTarget {
207
+ surface: {
208
+ instanceId: string;
209
+ surfaceName: string;
210
+ } | null;
211
+ /** The resolved declaration (inheritance applied). Eligibility decides by KEY existence over it. */
212
+ declaration: ResolvedSurfaceDeclaration | null;
213
+ /** Declared value keys with a read path here (screen names + qualified item keys). Key existence, not population. */
214
+ valueKeys: ReadonlySet<QualifiedValueKey>;
215
+ /** Scope chain, most general first: ["global", "<domain>", "<surfaceName>"]. */
216
+ scopeChain: readonly string[];
217
+ /** The surface's explicit exclusions (the one override). */
218
+ excludedActionIds: ReadonlySet<string>;
219
+ item: ResolvedItem | null;
220
+ level: string | null;
221
+ /** Offsets + the live range handle, editable or not. */
222
+ selection: {
223
+ text: string;
224
+ type: "editable" | "non-editable";
225
+ start: number;
226
+ end: number;
227
+ /** Opaque host handle (DOM Range / element) used to restore or stream into the selection. */
228
+ handle?: unknown;
229
+ } | null;
230
+ /** Payload kinds a capture of this target would produce (from declared value types/kinds). */
231
+ payloadKinds: readonly PayloadKind[];
232
+ /** Declared targets writable on this target right now. */
233
+ writable: readonly WriteTarget[];
234
+ readOnly: boolean;
235
+ /** True when any declared value here is secret/credential or non-exportable. */
236
+ restricted: boolean;
237
+ organizationId: string | null;
238
+ auth: {
239
+ authenticated: boolean;
240
+ admin: boolean;
241
+ creator: boolean;
242
+ };
243
+ /**
244
+ * Host-owned context a provider reads to act (the rich-document source, the
245
+ * editable field's callbacks). Opaque to the package; never crosses into the
246
+ * model. Providers that need it narrow it themselves.
247
+ */
248
+ host?: unknown;
249
+ }
250
+
251
+ /**
252
+ * Matrx Alchemy — Actions types (CONTRACT §2.4).
253
+ *
254
+ * One registry of everything a person can do to a thing. Providers plug in;
255
+ * eligibility is computed from what is declared at the click target; duplicate
256
+ * ids are refused; an action that does not apply is ABSENT (chair ruling R1).
257
+ *
258
+ * Framework-neutral: zero React, zero `@ai-matrx/agents`. Icons are string KEYS
259
+ * resolved by the host's `IconResolverPort`; labels go through `I18nPort`.
260
+ */
261
+
262
+ /** rich-document's ActionCategory, unchanged, plus the three the context menu groups by. */
263
+ type ActionCategory = "feedback" | "copy" | "export" | "save" | "edit" | "share" | "creator" | "app" | "listen" | "study" | "ask" | "ai" | "admin" | "clipboard" | "history" | "surface-info";
264
+ interface ResolveRestriction {
265
+ exclude?: readonly string[];
266
+ categories?: readonly ActionCategory[];
267
+ }
268
+
269
+ /**
270
+ * `@ai-matrx/alchemy/declare/host` — HOST-BINDING types only (CONTRACT §2.1, §2.6).
271
+ * Never imported by providers (`/declare`, `/actions`, `/menu`, `/operate` see only
272
+ * the raw-free `ResolvedItem`). Types only: no runtime code.
273
+ */
274
+
275
+ interface ItemAnchor {
276
+ /** The host element the person clicked. */
277
+ element: unknown;
278
+ level?: string;
279
+ }
280
+ /** Raw item reads: consumed only by projection and the write handler that owns the target. */
281
+ interface InternalResolvedItem extends ResolvedItem {
282
+ readValues(signal: AbortSignal): Promise<Record<string, unknown>>;
283
+ }
284
+ /** A mounted instance of a declared surface. Structural handle, never a global name lookup. */
285
+ interface MountedSurface {
286
+ instanceId: string;
287
+ surfaceName: string;
288
+ isMounted(): boolean;
289
+ /** Same revision before and after a read, or capture refuses with "surface-changed". */
290
+ getRevision?(): string;
291
+ unsavedChanges?(): boolean;
292
+ readValues(signal: AbortSignal): Promise<Record<string, unknown>>;
293
+ readLive?(signal: AbortSignal): Promise<LiveValues>;
294
+ resolveItem?(anchor: ItemAnchor): InternalResolvedItem | null;
295
+ }
296
+
297
+ interface ProjectionSource {
298
+ surface: MountedSurface | null;
299
+ declaration: ResolvedSurfaceDeclaration | null;
300
+ item: InternalResolvedItem | null;
301
+ }
302
+
303
+ /**
304
+ * The one run path (T1e). Every layout runs an action through here, so the
305
+ * sign-in-then-resume rule, projection and failure capture live once.
306
+ */
307
+
308
+ type RunResult = {
309
+ status: "ran";
310
+ outcome: TransferOutcome | void;
311
+ } | {
312
+ status: "auth-pending";
313
+ } | {
314
+ status: "failed";
315
+ error: unknown;
316
+ };
317
+
318
+ /**
319
+ * The React half of T1e: one hook every renderer uses to resolve the registry
320
+ * at a target, build the model and run a node. Handlers never live in a
321
+ * renderer — they live in providers and run through `runAction`.
322
+ *
323
+ * The context object is shared through globalThis so every per-layout entry
324
+ * (each bundled separately) reads the same provider (module state is banned
325
+ * across dual-loader graphs).
326
+ */
327
+
328
+ interface MenuEngineOptions {
329
+ restrict?: ResolveRestriction;
330
+ /** Raw sources for projection (the host's mounted surface / clicked item). */
331
+ source?: ProjectionSource;
332
+ /** Content the menu acts on when nothing is selected (header text). */
333
+ content?: string | null;
334
+ contentFingerprint?: string;
335
+ /** Called after a node ran (close the menu, announce). */
336
+ onRan?: (nodeId: string, result: RunResult) => void;
337
+ /** Resolve only while true (renderers resolve on open). Default true. */
338
+ active?: boolean;
339
+ /**
340
+ * Re-resolve when this changes even if the target object is the same (a
341
+ * host that keeps one target per mount and reads live state through it).
342
+ */
343
+ revision?: string | number;
344
+ }
345
+
346
+ /**
347
+ * `@ai-matrx/alchemy/react/sheet` — the mobile bottom-sheet layout, T1m.
348
+ * T1's twin over the SAME model (`sheet(model)`), so mobile can never drift
349
+ * from desktop. Path-based drill-down: a list of submenu ids re-resolved
350
+ * against the live model every render, so loading agents update in place.
351
+ */
352
+
353
+ interface ActionSheetProps extends MenuEngineOptions {
354
+ target: ClickTarget;
355
+ open: boolean;
356
+ onOpenChange(open: boolean): void;
357
+ title?: string;
358
+ }
359
+
360
+ interface ActionBarProps extends MenuEngineOptions {
361
+ target: ClickTarget;
362
+ /** Compact presentation (smaller gaps); membership is identical. */
363
+ mini?: boolean;
364
+ className?: string;
365
+ /** Hide the ⋯ (the host turned the options off); the primaries still render. */
366
+ hideOverflow?: boolean;
367
+ /**
368
+ * Below this viewport width the ⋯ opens the mobile bottom sheet
369
+ * (`/react/sheet`, loaded on first tap) instead of a dropdown. Default 768.
370
+ */
371
+ sheetBelow?: number;
372
+ /** Override the sheet loader (tests, custom bundlers). */
373
+ loadSheet?: () => Promise<{
374
+ ActionSheet: React.ComponentType<ActionSheetProps>;
375
+ }>;
376
+ }
377
+ declare function ActionBar({ target, mini, className, hideOverflow, sheetBelow, loadSheet, ...options }: ActionBarProps): React.ReactElement | null;
378
+
379
+ export { ActionBar, type ActionBarProps };