unsys-canvas 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -5
- package/dist/core.d.ts +367 -7
- package/dist/core.js +1587 -511
- package/dist/core.js.map +1 -1
- package/dist/index.d.ts +386 -14
- package/dist/index.js +2606 -618
- package/dist/index.js.map +1 -1
- package/dist/styles.css +106 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
# unsys-canvas
|
|
2
2
|
|
|
3
|
-
React package: think on an Excalidraw board with a **host-supplied** LLM (`onAsk`).
|
|
4
|
-
|
|
5
|
-
npm cannot install this folder via `github:…#ref:subdir` (that syntax is pnpm/yarn). From a clone:
|
|
3
|
+
MIT React package: think on an Excalidraw board with a **host-supplied** LLM (`runModel`, or deprecated `onAsk`). Published as [`unsys-canvas`](https://www.npmjs.com/package/unsys-canvas) (currently 0.2.0).
|
|
6
4
|
|
|
7
5
|
```bash
|
|
8
|
-
npm install
|
|
6
|
+
npm install unsys-canvas
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Peer dependencies: `react`, `react-dom`, and `@excalidraw/excalidraw@0.18.0-c0a0ca3`.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { UnsysCanvas } from "unsys-canvas";
|
|
13
|
+
import "unsys-canvas/styles.css";
|
|
9
14
|
```
|
|
10
15
|
|
|
11
|
-
|
|
16
|
+
The package owns the command registry (prompts, parse, placement) and emits raw board changes. Theming is a `style` prop. There is no default LLM. Live collaboration is an opt-in `collaboration` transport plus Invite. See the [repository README](https://github.com/dncolomer/unsys-canvas) and [docs/ARCHITECTURE.md](../../docs/ARCHITECTURE.md).
|
|
17
|
+
|
|
18
|
+
## License
|
|
19
|
+
|
|
20
|
+
MIT
|
package/dist/core.d.ts
CHANGED
|
@@ -139,16 +139,20 @@ interface PromptImpactLayer {
|
|
|
139
139
|
declare const UNSYS_CANVAS_COMMANDS: readonly [{
|
|
140
140
|
readonly id: "simplify";
|
|
141
141
|
readonly label: "Simplify";
|
|
142
|
-
readonly tooltip: "
|
|
142
|
+
readonly tooltip: "Keep the original marks and place a shorter, plainer rewrite next to them. If the selection is a term, make the meaning plain.";
|
|
143
143
|
readonly shortcut: "s";
|
|
144
|
+
readonly gesture: "question-mark";
|
|
145
|
+
readonly gestureHint: "Laser: question mark over a mark.";
|
|
144
146
|
readonly needsSelection: true;
|
|
145
147
|
readonly boardOnly: false;
|
|
146
|
-
readonly replacesSelection:
|
|
148
|
+
readonly replacesSelection: false;
|
|
147
149
|
}, {
|
|
148
150
|
readonly id: "breakdown";
|
|
149
151
|
readonly label: "Subdivide";
|
|
150
152
|
readonly tooltip: "Keep the original mark and fan its parts into smaller nodes, linked with arrows.";
|
|
151
153
|
readonly shortcut: "b";
|
|
154
|
+
readonly gesture: "double-line";
|
|
155
|
+
readonly gestureHint: "Laser: two quick lines from a mark into empty space.";
|
|
152
156
|
readonly needsSelection: true;
|
|
153
157
|
readonly boardOnly: false;
|
|
154
158
|
readonly replacesSelection: false;
|
|
@@ -157,6 +161,8 @@ declare const UNSYS_CANVAS_COMMANDS: readonly [{
|
|
|
157
161
|
readonly label: "Concepts";
|
|
158
162
|
readonly tooltip: "Keep the original and fan its named concepts into linked nodes.";
|
|
159
163
|
readonly shortcut: "c";
|
|
164
|
+
readonly gesture: "line";
|
|
165
|
+
readonly gestureHint: "Laser: line from a mark into empty space.";
|
|
160
166
|
readonly needsSelection: true;
|
|
161
167
|
readonly boardOnly: false;
|
|
162
168
|
readonly replacesSelection: false;
|
|
@@ -166,6 +172,8 @@ declare const UNSYS_CANVAS_COMMANDS: readonly [{
|
|
|
166
172
|
readonly slash: "run";
|
|
167
173
|
readonly tooltip: "Work the highlighted problem: carry it out, compute it, or show the result.";
|
|
168
174
|
readonly shortcut: "d";
|
|
175
|
+
readonly gesture: "loop";
|
|
176
|
+
readonly gestureHint: "Laser: circle or loop over a mark.";
|
|
169
177
|
readonly needsSelection: true;
|
|
170
178
|
readonly boardOnly: false;
|
|
171
179
|
readonly replacesSelection: false;
|
|
@@ -174,9 +182,21 @@ declare const UNSYS_CANVAS_COMMANDS: readonly [{
|
|
|
174
182
|
readonly label: "Refactor";
|
|
175
183
|
readonly tooltip: "Delete the selected marks and replace them with a clearer rewrite.";
|
|
176
184
|
readonly shortcut: "r";
|
|
185
|
+
readonly gesture: "zigzag";
|
|
186
|
+
readonly gestureHint: "Laser: zigzag over a mark.";
|
|
177
187
|
readonly needsSelection: true;
|
|
178
188
|
readonly boardOnly: false;
|
|
179
189
|
readonly replacesSelection: true;
|
|
190
|
+
}, {
|
|
191
|
+
readonly id: "pretty";
|
|
192
|
+
readonly label: "Pretty";
|
|
193
|
+
readonly tooltip: "Keep the original marks and place a tidied, well-formatted Excalidraw note next to them.";
|
|
194
|
+
readonly shortcut: "p";
|
|
195
|
+
readonly gesture: "check";
|
|
196
|
+
readonly gestureHint: "Laser: check mark over a mark.";
|
|
197
|
+
readonly needsSelection: true;
|
|
198
|
+
readonly boardOnly: false;
|
|
199
|
+
readonly replacesSelection: false;
|
|
180
200
|
}];
|
|
181
201
|
type UnsysCanvasCommandId = (typeof UNSYS_CANVAS_COMMANDS)[number]["id"] | (string & {});
|
|
182
202
|
type UnsysCanvasHostCommand = {
|
|
@@ -186,13 +206,19 @@ type UnsysCanvasHostCommand = {
|
|
|
186
206
|
shortcut?: string;
|
|
187
207
|
slash?: string;
|
|
188
208
|
needsSelection?: boolean;
|
|
209
|
+
/** Ignored. Only Refactor may replace the selection. */
|
|
189
210
|
replacesSelection?: boolean;
|
|
211
|
+
gesture?: string | null;
|
|
212
|
+
gestureHint?: string | null;
|
|
213
|
+
catalog?: boolean;
|
|
214
|
+
needsModel?: boolean;
|
|
215
|
+
placement?: "beside" | "replace";
|
|
190
216
|
run?: (ctx: {
|
|
191
217
|
selectedElements: UnsysCanvasElement[];
|
|
192
218
|
scene: UnsysCanvasScene;
|
|
193
219
|
}) => void | Promise<void>;
|
|
194
220
|
};
|
|
195
|
-
type UnsysCanvasAskKind = "ask" | "draw" | "simplify" | "concepts" | "check" | "selective-compress" | "refactor" | "suggest-insight" | "clear-overlaps" | "declutter";
|
|
221
|
+
type UnsysCanvasAskKind = "ask" | "draw" | "simplify" | "concepts" | "check" | "selective-compress" | "refactor" | "pretty" | "suggest-insight" | "clear-overlaps" | "declutter";
|
|
196
222
|
type UnsysCanvasCommandDef = {
|
|
197
223
|
id: string;
|
|
198
224
|
label: string;
|
|
@@ -202,6 +228,8 @@ type UnsysCanvasCommandDef = {
|
|
|
202
228
|
boardOnly: boolean;
|
|
203
229
|
replacesSelection: boolean;
|
|
204
230
|
slash?: string;
|
|
231
|
+
gesture?: string | null;
|
|
232
|
+
gestureHint?: string | null;
|
|
205
233
|
run?: UnsysCanvasHostCommand["run"];
|
|
206
234
|
};
|
|
207
235
|
/** Built-in catalog plus host-registered commands. */
|
|
@@ -221,8 +249,8 @@ type UnsysCanvasCommandRun = {
|
|
|
221
249
|
};
|
|
222
250
|
/**
|
|
223
251
|
* Local result of a sidebar/dock command click.
|
|
224
|
-
* Subdivide, Focus, and Next mutate now.
|
|
225
|
-
*
|
|
252
|
+
* Subdivide, Focus, and Next mutate now. Refactor drops the original marks
|
|
253
|
+
* immediately, then asks XAI. Simplify, Do/run, Concepts, and Pretty keep the
|
|
226
254
|
* original and ask. A click that cannot run returns a short board notice instead of going silent.
|
|
227
255
|
*/
|
|
228
256
|
declare function runUnsysCanvasCommand(input: {
|
|
@@ -240,6 +268,7 @@ declare function runUnsysCanvasCommand(input: {
|
|
|
240
268
|
* Leaf module. Types from the scene module are erased at runtime.
|
|
241
269
|
*/
|
|
242
270
|
|
|
271
|
+
type UnsysCanvasWorkspaceInput = PromptWorkspaceContextInput;
|
|
243
272
|
declare function buildUnsysCanvasCommandUserMessage(input: {
|
|
244
273
|
kind?: UnsysCanvasAskKind | "compress" | null;
|
|
245
274
|
prompt?: string | null;
|
|
@@ -343,12 +372,196 @@ declare function convertUnsysCanvasSkeletons(skeletons: UnsysCanvasSkeleton[] |
|
|
|
343
372
|
declare const convertToExcalidrawElements: typeof convertUnsysCanvasSkeletons;
|
|
344
373
|
declare function unsysCanvasHasLiveElements(scene: UnsysCanvasScene | null | undefined): boolean;
|
|
345
374
|
|
|
375
|
+
/**
|
|
376
|
+
* Command registry: source of truth for catalog chrome, context extraction,
|
|
377
|
+
* prompt construction, parse/validation, and board placement policy.
|
|
378
|
+
*
|
|
379
|
+
* Host extras use the same definition shape. A Pretty command, extra laser
|
|
380
|
+
* gestures, or a picker should add a row here (or via `commands`) rather than
|
|
381
|
+
* forking prompt files in the host.
|
|
382
|
+
*/
|
|
383
|
+
|
|
384
|
+
declare const UNSYS_CANVAS_COMMAND_SYSTEM_PROMPT: string;
|
|
385
|
+
type UnsysCanvasModelRole = "system" | "user" | "assistant";
|
|
386
|
+
type UnsysCanvasModelMessage = {
|
|
387
|
+
role: UnsysCanvasModelRole;
|
|
388
|
+
content: string;
|
|
389
|
+
};
|
|
390
|
+
type UnsysCanvasJsonSchema = {
|
|
391
|
+
name: string;
|
|
392
|
+
strict?: boolean;
|
|
393
|
+
schema: Record<string, unknown>;
|
|
394
|
+
};
|
|
395
|
+
type UnsysCanvasResponseFormat = "json" | "json_schema" | "text";
|
|
396
|
+
type UnsysCanvasPlacementMode = "beside" | "replace";
|
|
397
|
+
/** Compact, validated mark used to build prompts. Not an open prompt field. */
|
|
398
|
+
type UnsysCanvasContextElement = {
|
|
399
|
+
id: string;
|
|
400
|
+
type: string;
|
|
401
|
+
x: number;
|
|
402
|
+
y: number;
|
|
403
|
+
width?: number;
|
|
404
|
+
height?: number;
|
|
405
|
+
text?: string;
|
|
406
|
+
};
|
|
407
|
+
type UnsysCanvasCommandContextPayload = {
|
|
408
|
+
selectedElements: UnsysCanvasContextElement[];
|
|
409
|
+
liveElements?: UnsysCanvasContextElement[];
|
|
410
|
+
prompt?: string;
|
|
411
|
+
boardLabel?: string;
|
|
412
|
+
workspace?: UnsysCanvasWorkspaceInput | null;
|
|
413
|
+
};
|
|
414
|
+
type UnsysCanvasCommandPrompt = {
|
|
415
|
+
messages: UnsysCanvasModelMessage[];
|
|
416
|
+
responseFormat: UnsysCanvasResponseFormat;
|
|
417
|
+
jsonSchema?: UnsysCanvasJsonSchema;
|
|
418
|
+
maxTokens: number;
|
|
419
|
+
timeoutMs: number;
|
|
420
|
+
};
|
|
421
|
+
type UnsysCanvasParsedCommandReply = {
|
|
422
|
+
text: string;
|
|
423
|
+
elements: UnsysCanvasSkeleton[] | null;
|
|
424
|
+
origin: {
|
|
425
|
+
x?: number;
|
|
426
|
+
y?: number;
|
|
427
|
+
} | null;
|
|
428
|
+
raw: string;
|
|
429
|
+
};
|
|
430
|
+
/**
|
|
431
|
+
* One command. Built-ins and host extras share this shape.
|
|
432
|
+
* Optional fields keep today's thin host extras (`id` + `label` + `run`) working.
|
|
433
|
+
*/
|
|
434
|
+
type UnsysCanvasCommandDefinition = UnsysCanvasCommandDef & {
|
|
435
|
+
gesture?: string | null;
|
|
436
|
+
gestureHint?: string | null;
|
|
437
|
+
/** Sidebar / slash / picker. Hidden model kinds (ask, check, …) are false. */
|
|
438
|
+
catalog?: boolean;
|
|
439
|
+
needsModel?: boolean;
|
|
440
|
+
placement?: UnsysCanvasPlacementMode;
|
|
441
|
+
/** Laser / pointer classifier id. Pretty/new gestures add a new kind here. */
|
|
442
|
+
extractContext?: (input: {
|
|
443
|
+
scene: UnsysCanvasScene;
|
|
444
|
+
selectedElements: readonly UnsysCanvasElement[];
|
|
445
|
+
prompt?: string | null;
|
|
446
|
+
workspace?: UnsysCanvasWorkspaceInput | null;
|
|
447
|
+
}) => UnsysCanvasCommandContextPayload;
|
|
448
|
+
buildPrompt?: (context: UnsysCanvasCommandContextPayload) => UnsysCanvasCommandPrompt;
|
|
449
|
+
parseResponse?: (raw: string) => UnsysCanvasParsedCommandReply;
|
|
450
|
+
};
|
|
451
|
+
declare function extractUnsysCanvasCommandContext(input: {
|
|
452
|
+
commandId: string;
|
|
453
|
+
scene: UnsysCanvasScene | null | undefined;
|
|
454
|
+
selectedElements: readonly UnsysCanvasElement[] | null | undefined;
|
|
455
|
+
prompt?: string | null;
|
|
456
|
+
workspace?: UnsysCanvasWorkspaceInput | null;
|
|
457
|
+
}): UnsysCanvasCommandContextPayload;
|
|
458
|
+
type UnsysCanvasHostCommandSpec = UnsysCanvasHostCommand & Partial<Pick<UnsysCanvasCommandDefinition, "extractContext" | "buildPrompt" | "parseResponse">>;
|
|
459
|
+
declare function listUnsysCanvasCommandDefinitions(extras?: readonly UnsysCanvasHostCommandSpec[]): UnsysCanvasCommandDefinition[];
|
|
460
|
+
declare function getUnsysCanvasCommand(id: string | null | undefined, extras?: readonly UnsysCanvasHostCommandSpec[]): UnsysCanvasCommandDefinition | null;
|
|
461
|
+
declare function isUnsysCanvasKnownCommandId(id: string | null | undefined, extras?: readonly UnsysCanvasHostCommandSpec[]): boolean;
|
|
462
|
+
declare function buildUnsysCanvasCommandPrompt(commandId: string, context: UnsysCanvasCommandContextPayload, extras?: readonly UnsysCanvasHostCommandSpec[]): UnsysCanvasCommandPrompt;
|
|
463
|
+
declare function parseUnsysCanvasCommandResponse(commandId: string, raw: string, extras?: readonly UnsysCanvasHostCommandSpec[]): UnsysCanvasParsedCommandReply;
|
|
464
|
+
declare function unsysCanvasCommandPlacement(id: string | null | undefined): UnsysCanvasPlacementMode;
|
|
465
|
+
declare function unsysCanvasGestureCommandId(gesture: string | null | undefined): string | null;
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Host LLM contract. The package builds prompts from the registry; the host
|
|
469
|
+
* only executes a model. Server routes must accept commandId + context, never
|
|
470
|
+
* caller-supplied messages.
|
|
471
|
+
*/
|
|
472
|
+
|
|
473
|
+
type UnsysCanvasModelRequest = {
|
|
474
|
+
commandId: string;
|
|
475
|
+
messages: UnsysCanvasModelMessage[];
|
|
476
|
+
responseFormat: UnsysCanvasResponseFormat;
|
|
477
|
+
jsonSchema?: UnsysCanvasJsonSchema;
|
|
478
|
+
maxTokens: number;
|
|
479
|
+
timeoutMs: number;
|
|
480
|
+
signal?: AbortSignal;
|
|
481
|
+
context: UnsysCanvasCommandContextPayload;
|
|
482
|
+
};
|
|
483
|
+
type UnsysCanvasModelResult = {
|
|
484
|
+
text: string;
|
|
485
|
+
};
|
|
486
|
+
type UnsysCanvasRunModel = (request: UnsysCanvasModelRequest) => Promise<UnsysCanvasModelResult>;
|
|
487
|
+
type UnsysCanvasModelHandlerOk = UnsysCanvasParsedCommandReply & {
|
|
488
|
+
ok: true;
|
|
489
|
+
};
|
|
490
|
+
type UnsysCanvasModelHandlerErr = {
|
|
491
|
+
ok: false;
|
|
492
|
+
status: number;
|
|
493
|
+
error: string;
|
|
494
|
+
};
|
|
495
|
+
type UnsysCanvasModelHandlerResult = UnsysCanvasModelHandlerOk | UnsysCanvasModelHandlerErr;
|
|
496
|
+
/**
|
|
497
|
+
* Parse a client POST body. Rejects unknown command ids and any attempt to
|
|
498
|
+
* supply model messages or system/user prompts at the top level.
|
|
499
|
+
*/
|
|
500
|
+
declare function parseUnsysCanvasModelClientBody(body: unknown, extras?: readonly UnsysCanvasHostCommandSpec[]): {
|
|
501
|
+
ok: true;
|
|
502
|
+
commandId: string;
|
|
503
|
+
context: UnsysCanvasCommandContextPayload;
|
|
504
|
+
} | UnsysCanvasModelHandlerErr;
|
|
505
|
+
declare function buildUnsysCanvasModelRequest(input: {
|
|
506
|
+
commandId: string;
|
|
507
|
+
scene?: UnsysCanvasScene | null;
|
|
508
|
+
selectedElements?: readonly UnsysCanvasElement[] | null;
|
|
509
|
+
prompt?: string | null;
|
|
510
|
+
workspace?: UnsysCanvasWorkspaceInput | null;
|
|
511
|
+
context?: UnsysCanvasCommandContextPayload;
|
|
512
|
+
extras?: readonly UnsysCanvasHostCommandSpec[];
|
|
513
|
+
signal?: AbortSignal;
|
|
514
|
+
}): UnsysCanvasModelRequest;
|
|
515
|
+
/**
|
|
516
|
+
* Server helper: build the prompt from the package registry, then call the
|
|
517
|
+
* host-provided model. Mount this in an API route. The API key stays on the server.
|
|
518
|
+
*/
|
|
519
|
+
declare function handleCanvasModelRequest(body: unknown, options: {
|
|
520
|
+
runModel: UnsysCanvasRunModel;
|
|
521
|
+
extras?: readonly UnsysCanvasHostCommandSpec[];
|
|
522
|
+
signal?: AbortSignal;
|
|
523
|
+
}): Promise<UnsysCanvasModelHandlerResult>;
|
|
524
|
+
declare function handleCanvasModelHttpRequest(req: Request, options: {
|
|
525
|
+
runModel: UnsysCanvasRunModel;
|
|
526
|
+
extras?: readonly UnsysCanvasHostCommandSpec[];
|
|
527
|
+
}): Promise<Response>;
|
|
528
|
+
type UnsysCanvasXaiRunnerOptions = {
|
|
529
|
+
getApiKey: () => string | null | Promise<string | null>;
|
|
530
|
+
getBaseUrl?: () => string | null | Promise<string | null>;
|
|
531
|
+
model?: string | ((commandId: string) => string);
|
|
532
|
+
reasoningEffort?: "low" | "medium" | "high";
|
|
533
|
+
fetch?: typeof fetch;
|
|
534
|
+
};
|
|
535
|
+
/**
|
|
536
|
+
* Browser (or Node) OpenAI-compatible Chat Completions runner. Default base URL
|
|
537
|
+
* is xAI. The host supplies the API key; the package never reads env secrets.
|
|
538
|
+
*/
|
|
539
|
+
declare function createUnsysCanvasXaiBrowserRunner(options: UnsysCanvasXaiRunnerOptions): UnsysCanvasRunModel;
|
|
540
|
+
/**
|
|
541
|
+
* Client runner that posts commandId + extracted context to a host API route
|
|
542
|
+
* which must call `handleCanvasModelRequest`. Messages are not sent.
|
|
543
|
+
*/
|
|
544
|
+
declare function createUnsysCanvasModelProxyRunner(options: {
|
|
545
|
+
url: string;
|
|
546
|
+
headers?: () => Record<string, string> | Promise<Record<string, string>>;
|
|
547
|
+
fetch?: typeof fetch;
|
|
548
|
+
}): UnsysCanvasRunModel;
|
|
549
|
+
declare function runUnsysCanvasModelAsk(runModel: UnsysCanvasRunModel, input: {
|
|
550
|
+
commandId: string;
|
|
551
|
+
scene: UnsysCanvasScene;
|
|
552
|
+
selectedElements: readonly UnsysCanvasElement[];
|
|
553
|
+
prompt?: string | null;
|
|
554
|
+
workspace?: UnsysCanvasWorkspaceInput | null;
|
|
555
|
+
extras?: readonly UnsysCanvasHostCommandSpec[];
|
|
556
|
+
signal?: AbortSignal;
|
|
557
|
+
}): Promise<UnsysCanvasParsedCommandReply>;
|
|
558
|
+
|
|
346
559
|
/**
|
|
347
560
|
* Verbose raw board event feed. No classification or proof-of-work semantics.
|
|
348
561
|
* High-frequency updates are batched by merging consecutive same-key events
|
|
349
562
|
* (first `from`, last `to`) so information is not dropped.
|
|
350
563
|
*/
|
|
351
|
-
declare const UNSYS_CANVAS_EVENT_TYPES: readonly ["element:added", "element:updated", "element:deleted", "element:moved", "element:resized", "text:edited", "selection:changed", "tool:changed", "viewport:changed", "command:run", "prompt:submit", "dictate:start", "dictate:stop", "dictate:text", "laser:gesture", "latex:render", "undo", "redo"];
|
|
564
|
+
declare const UNSYS_CANVAS_EVENT_TYPES: readonly ["element:added", "element:updated", "element:deleted", "element:moved", "element:resized", "text:edited", "selection:changed", "tool:changed", "viewport:changed", "command:run", "command:complete", "prompt:submit", "dictate:start", "dictate:stop", "dictate:text", "laser:gesture", "latex:render", "undo", "redo"];
|
|
352
565
|
type UnsysCanvasEventType = (typeof UNSYS_CANVAS_EVENT_TYPES)[number];
|
|
353
566
|
type UnsysCanvasEvent = {
|
|
354
567
|
seq: number;
|
|
@@ -370,6 +583,7 @@ declare class UnsysCanvasEventCollector {
|
|
|
370
583
|
private push;
|
|
371
584
|
observeScene(scene?: unknown, _opts?: unknown): UnsysCanvasEvent[];
|
|
372
585
|
command(id?: string, meta?: unknown): UnsysCanvasEvent[];
|
|
586
|
+
commandComplete(id?: string, meta?: unknown): UnsysCanvasEvent[];
|
|
373
587
|
dictate(meta?: unknown): UnsysCanvasEvent[];
|
|
374
588
|
prompt(text?: string, meta?: unknown): UnsysCanvasEvent[];
|
|
375
589
|
laser(meta?: unknown): UnsysCanvasEvent[];
|
|
@@ -504,5 +718,151 @@ declare function parseUnsysCanvasStyle(value: unknown): UnsysCanvasStyle;
|
|
|
504
718
|
declare function unsysCanvasSidebarStyleCssVars(style: UnsysCanvasStyle | null | undefined): Record<string, string>;
|
|
505
719
|
|
|
506
720
|
declare function assertOnAsk(onAsk: unknown): void;
|
|
721
|
+
/** Prefer `runModel`. `onAsk` remains for hosts that have not migrated. */
|
|
722
|
+
declare function assertCanvasModel(input: {
|
|
723
|
+
onAsk?: unknown;
|
|
724
|
+
runModel?: unknown;
|
|
725
|
+
}): void;
|
|
726
|
+
|
|
727
|
+
type UnsysCanvasCollabPointerTool = "pointer" | "laser";
|
|
728
|
+
type UnsysCanvasCollabPointer = {
|
|
729
|
+
x: number;
|
|
730
|
+
y: number;
|
|
731
|
+
tool: UnsysCanvasCollabPointerTool;
|
|
732
|
+
};
|
|
733
|
+
type UnsysCanvasCollabUserColor = {
|
|
734
|
+
background: string;
|
|
735
|
+
stroke: string;
|
|
736
|
+
};
|
|
737
|
+
type UnsysCanvasCollabUser = {
|
|
738
|
+
id: string;
|
|
739
|
+
name: string;
|
|
740
|
+
color: UnsysCanvasCollabUserColor;
|
|
741
|
+
};
|
|
742
|
+
type UnsysCanvasCollabScenePayload = {
|
|
743
|
+
elements: UnsysCanvasElement[];
|
|
744
|
+
files: UnsysCanvasFiles;
|
|
745
|
+
};
|
|
746
|
+
type UnsysCanvasCollabPointerPayload = {
|
|
747
|
+
pointer: UnsysCanvasCollabPointer;
|
|
748
|
+
button: "up" | "down";
|
|
749
|
+
selectedElementIds?: Record<string, boolean>;
|
|
750
|
+
};
|
|
751
|
+
type UnsysCanvasCollaborationHandlers = {
|
|
752
|
+
onMessage: (bytes: Uint8Array) => void;
|
|
753
|
+
onOpen?: () => void;
|
|
754
|
+
onClose?: () => void;
|
|
755
|
+
onError?: (error: unknown) => void;
|
|
756
|
+
};
|
|
757
|
+
type UnsysCanvasCollaborationSocket = {
|
|
758
|
+
send: (bytes: Uint8Array) => void;
|
|
759
|
+
close: () => void;
|
|
760
|
+
};
|
|
761
|
+
/**
|
|
762
|
+
* Byte pipe for one room. Ciphertext only — the library encrypts with the
|
|
763
|
+
* key from the URL fragment so a relay cannot read the board.
|
|
764
|
+
*/
|
|
765
|
+
type UnsysCanvasCollaborationTransport = {
|
|
766
|
+
open: (roomId: string, handlers: UnsysCanvasCollaborationHandlers) => UnsysCanvasCollaborationSocket;
|
|
767
|
+
};
|
|
768
|
+
/** Host-supplied collaboration adapter. Today this is a transport; session + reconcile stay in the package. */
|
|
769
|
+
type UnsysCanvasCollaborationAdapter = UnsysCanvasCollaborationTransport;
|
|
770
|
+
type UnsysCanvasCollaborator = {
|
|
771
|
+
pointer?: UnsysCanvasCollabPointer;
|
|
772
|
+
button?: "up" | "down";
|
|
773
|
+
selectedElementIds?: Record<string, boolean>;
|
|
774
|
+
username?: string | null;
|
|
775
|
+
userState?: "active" | "pending" | "idle" | "away";
|
|
776
|
+
color?: UnsysCanvasCollabUserColor;
|
|
777
|
+
avatarUrl?: string | null;
|
|
778
|
+
id?: string;
|
|
779
|
+
};
|
|
780
|
+
type UnsysCanvasCollabReconcileOptions = {
|
|
781
|
+
/** Local element ids currently being edited, resized, or created. Remote updates for these are ignored. */
|
|
782
|
+
editingIds?: Iterable<string> | null;
|
|
783
|
+
};
|
|
784
|
+
type UnsysCanvasCollabRoom = {
|
|
785
|
+
roomId: string;
|
|
786
|
+
key: string;
|
|
787
|
+
};
|
|
788
|
+
|
|
789
|
+
/** Live-collaboration fragment. Distinct from `#tc1.` scene snapshots. */
|
|
790
|
+
declare const UNSYS_CANVAS_COLLAB_HASH_PREFIX: "uc1.";
|
|
791
|
+
declare function generateUnsysCanvasCollabRoom(): UnsysCanvasCollabRoom;
|
|
792
|
+
declare function buildUnsysCanvasCollabHash(room: UnsysCanvasCollabRoom): string;
|
|
793
|
+
declare function parseUnsysCanvasCollabHash(hash: string | null | undefined): UnsysCanvasCollabRoom | null;
|
|
794
|
+
declare function isUnsysCanvasCollabHash(hash: string | null | undefined): boolean;
|
|
795
|
+
declare function readUnsysCanvasCollabHashFromLocation(hash?: string | null | undefined): UnsysCanvasCollabRoom | null;
|
|
796
|
+
declare function replaceUnsysCanvasCollabLocationHash(room: UnsysCanvasCollabRoom): string;
|
|
797
|
+
/**
|
|
798
|
+
* Shareable board URL. The encryption key stays in the fragment so it is
|
|
799
|
+
* not sent to a relay or to HTTP access logs.
|
|
800
|
+
*/
|
|
801
|
+
declare function buildUnsysCanvasCollabShareUrl(room: UnsysCanvasCollabRoom, href?: string | null | undefined): string;
|
|
802
|
+
|
|
803
|
+
declare function reconcileUnsysCanvasElements(local: readonly UnsysCanvasElement[] | null | undefined, remote: readonly UnsysCanvasElement[] | null | undefined, options?: UnsysCanvasCollabReconcileOptions): UnsysCanvasElement[];
|
|
804
|
+
declare function reconcileUnsysCanvasFiles(local: UnsysCanvasFiles | null | undefined, remote: UnsysCanvasFiles | null | undefined): UnsysCanvasFiles;
|
|
805
|
+
declare function reconcileUnsysCanvasScene(local: Pick<UnsysCanvasScene, "elements" | "files"> | null | undefined, remote: UnsysCanvasCollabScenePayload | null | undefined, options?: UnsysCanvasCollabReconcileOptions): UnsysCanvasCollabScenePayload;
|
|
806
|
+
|
|
807
|
+
type UnsysCanvasCollabSessionHandlers = {
|
|
808
|
+
onRemoteScene?: (scene: UnsysCanvasCollabScenePayload, from: UnsysCanvasCollabUser) => void;
|
|
809
|
+
onCollaborators?: (collaborators: Map<string, UnsysCanvasCollaborator>) => void;
|
|
810
|
+
onOpen?: () => void;
|
|
811
|
+
onClose?: () => void;
|
|
812
|
+
onError?: (error: unknown) => void;
|
|
813
|
+
};
|
|
814
|
+
type UnsysCanvasCollabSessionOptions = {
|
|
815
|
+
roomId: string;
|
|
816
|
+
key: string;
|
|
817
|
+
user: UnsysCanvasCollabUser;
|
|
818
|
+
transport: UnsysCanvasCollaborationTransport;
|
|
819
|
+
handlers?: UnsysCanvasCollabSessionHandlers;
|
|
820
|
+
getLocalScene?: () => UnsysCanvasCollabScenePayload | null;
|
|
821
|
+
getEditingIds?: () => Iterable<string> | null;
|
|
822
|
+
};
|
|
823
|
+
declare class UnsysCanvasCollabSession {
|
|
824
|
+
readonly roomId: string;
|
|
825
|
+
readonly user: UnsysCanvasCollabUser;
|
|
826
|
+
private readonly key;
|
|
827
|
+
private readonly transport;
|
|
828
|
+
private readonly handlers;
|
|
829
|
+
private readonly getLocalScene?;
|
|
830
|
+
private readonly getEditingIds?;
|
|
831
|
+
private socket;
|
|
832
|
+
private collaborators;
|
|
833
|
+
private closed;
|
|
834
|
+
constructor(options: UnsysCanvasCollabSessionOptions);
|
|
835
|
+
start(): void;
|
|
836
|
+
close(): void;
|
|
837
|
+
broadcastScene(scene: UnsysCanvasCollabScenePayload): Promise<void>;
|
|
838
|
+
broadcastPointer(pointer: UnsysCanvasCollabPointerPayload): Promise<void>;
|
|
839
|
+
private sendHello;
|
|
840
|
+
private send;
|
|
841
|
+
private handleBytes;
|
|
842
|
+
private touchCollaborator;
|
|
843
|
+
private emitCollaborators;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* In-process relay for tests and same-runtime hosts. Ciphertext still
|
|
848
|
+
* flows through so encryption can be exercised without a network.
|
|
849
|
+
*/
|
|
850
|
+
declare function createUnsysCanvasMemoryTransportHub(): {
|
|
851
|
+
createTransport: () => UnsysCanvasCollaborationTransport;
|
|
852
|
+
};
|
|
853
|
+
|
|
854
|
+
type UnsysCanvasWebsocketTransportOptions = {
|
|
855
|
+
/** `ws://` or `wss://` URL of a Unsys Canvas collab relay. */
|
|
856
|
+
url: string;
|
|
857
|
+
};
|
|
858
|
+
/**
|
|
859
|
+
* Reference transport: opaque encrypted frames over a WebSocket relay.
|
|
860
|
+
* The relay only sees `roomId` plus ciphertext.
|
|
861
|
+
*/
|
|
862
|
+
declare function createUnsysCanvasWebsocketTransport(options: UnsysCanvasWebsocketTransportOptions): UnsysCanvasCollaborationTransport;
|
|
863
|
+
declare function isUnsysCanvasRelayUrl(value: string | null | undefined): boolean;
|
|
864
|
+
|
|
865
|
+
declare function encryptUnsysCanvasCollabJson(keyB64: string, value: unknown): Promise<Uint8Array>;
|
|
866
|
+
declare function decryptUnsysCanvasCollabJson(keyB64: string, packed: Uint8Array): Promise<unknown>;
|
|
507
867
|
|
|
508
|
-
export { DEFAULT_UNSYS_CANVAS_BOARD_STYLE, DEFAULT_UNSYS_CANVAS_STYLE_TOKENS, EMPTY_UNSYS_CANVAS_STYLE, UNSYS_CANVAS_COMMANDS, UNSYS_CANVAS_EVENT_TYPES, UNSYS_CANVAS_HASH_PREFIX, type UnsysCanvasAskKind, type UnsysCanvasBoardStyle, type UnsysCanvasCommandId, type UnsysCanvasElement, type UnsysCanvasEvent, UnsysCanvasEventCollector, type UnsysCanvasEventType, type UnsysCanvasHostCommand, type UnsysCanvasScene, type UnsysCanvasSidebarTokens, type UnsysCanvasStyle, applyUnsysCanvasAskReply, assertOnAsk, buildUnsysCanvasCommandUserMessage, convertToExcalidrawElements, decodeUnsysCanvasHash, emptyUnsysCanvasScene, encodeUnsysCanvasHash, normalizeUnsysCanvasLinearElement, parseUnsysCanvasAskReply, parseUnsysCanvasStyle, readUnsysCanvasHashFromLocation, replaceUnsysCanvasLocationHash, runUnsysCanvasCommand, serializeUnsysCanvasScene, unsysCanvasAskFromSessionChat, unsysCanvasCommandsFor, unsysCanvasHasLiveElements, unsysCanvasSidebarStyleCssVars, unsysCanvasTurnContextMessage, unsysCanvasXaiFetchTimeout, unsysCanvasXaiMaxTokens, unsysCanvasXaiNeedsBoardContext };
|
|
868
|
+
export { DEFAULT_UNSYS_CANVAS_BOARD_STYLE, DEFAULT_UNSYS_CANVAS_STYLE_TOKENS, EMPTY_UNSYS_CANVAS_STYLE, UNSYS_CANVAS_COLLAB_HASH_PREFIX, UNSYS_CANVAS_COMMANDS, UNSYS_CANVAS_COMMAND_SYSTEM_PROMPT, UNSYS_CANVAS_EVENT_TYPES, UNSYS_CANVAS_HASH_PREFIX, type UnsysCanvasAskKind, type UnsysCanvasBoardStyle, type UnsysCanvasCollabRoom, UnsysCanvasCollabSession, type UnsysCanvasCollaborationAdapter, type UnsysCanvasCollaborationTransport, type UnsysCanvasCommandContextPayload, type UnsysCanvasCommandDefinition, type UnsysCanvasCommandId, type UnsysCanvasElement, type UnsysCanvasEvent, UnsysCanvasEventCollector, type UnsysCanvasEventType, type UnsysCanvasHostCommand, type UnsysCanvasHostCommandSpec, type UnsysCanvasModelRequest, type UnsysCanvasModelResult, type UnsysCanvasParsedCommandReply, type UnsysCanvasRunModel, type UnsysCanvasScene, type UnsysCanvasSidebarTokens, type UnsysCanvasStyle, applyUnsysCanvasAskReply, assertCanvasModel, assertOnAsk, buildUnsysCanvasCollabHash, buildUnsysCanvasCollabShareUrl, buildUnsysCanvasCommandPrompt, buildUnsysCanvasCommandUserMessage, buildUnsysCanvasModelRequest, convertToExcalidrawElements, createUnsysCanvasMemoryTransportHub, createUnsysCanvasModelProxyRunner, createUnsysCanvasWebsocketTransport, createUnsysCanvasXaiBrowserRunner, decodeUnsysCanvasHash, decryptUnsysCanvasCollabJson, emptyUnsysCanvasScene, encodeUnsysCanvasHash, encryptUnsysCanvasCollabJson, extractUnsysCanvasCommandContext, generateUnsysCanvasCollabRoom, getUnsysCanvasCommand, handleCanvasModelHttpRequest, handleCanvasModelRequest, isUnsysCanvasCollabHash, isUnsysCanvasKnownCommandId, isUnsysCanvasRelayUrl, listUnsysCanvasCommandDefinitions, normalizeUnsysCanvasLinearElement, parseUnsysCanvasAskReply, parseUnsysCanvasCollabHash, parseUnsysCanvasCommandResponse, parseUnsysCanvasModelClientBody, parseUnsysCanvasStyle, readUnsysCanvasCollabHashFromLocation, readUnsysCanvasHashFromLocation, reconcileUnsysCanvasElements, reconcileUnsysCanvasFiles, reconcileUnsysCanvasScene, replaceUnsysCanvasCollabLocationHash, replaceUnsysCanvasLocationHash, runUnsysCanvasCommand, runUnsysCanvasModelAsk, serializeUnsysCanvasScene, unsysCanvasAskFromSessionChat, unsysCanvasCommandPlacement, unsysCanvasCommandsFor, unsysCanvasGestureCommandId, unsysCanvasHasLiveElements, unsysCanvasSidebarStyleCssVars, unsysCanvasTurnContextMessage, unsysCanvasXaiFetchTimeout, unsysCanvasXaiMaxTokens, unsysCanvasXaiNeedsBoardContext };
|