unsys-canvas 0.2.0 → 0.2.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/README.md +1 -1
- package/dist/core.d.ts +2 -2
- package/dist/core.js +81 -12
- package/dist/core.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +365 -370
- package/dist/index.js.map +1 -1
- package/dist/styles.css +0 -45
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# unsys-canvas
|
|
2
2
|
|
|
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.
|
|
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.2).
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
npm install unsys-canvas
|
package/dist/core.d.ts
CHANGED
|
@@ -377,7 +377,7 @@ declare function unsysCanvasHasLiveElements(scene: UnsysCanvasScene | null | und
|
|
|
377
377
|
* prompt construction, parse/validation, and board placement policy.
|
|
378
378
|
*
|
|
379
379
|
* Host extras use the same definition shape. A Pretty command, extra laser
|
|
380
|
-
* gestures, or
|
|
380
|
+
* gestures, or the right-click menu should add a row here (or via `commands`) rather than
|
|
381
381
|
* forking prompt files in the host.
|
|
382
382
|
*/
|
|
383
383
|
|
|
@@ -434,7 +434,7 @@ type UnsysCanvasParsedCommandReply = {
|
|
|
434
434
|
type UnsysCanvasCommandDefinition = UnsysCanvasCommandDef & {
|
|
435
435
|
gesture?: string | null;
|
|
436
436
|
gestureHint?: string | null;
|
|
437
|
-
/** Sidebar /
|
|
437
|
+
/** Sidebar / right-click menu. Hidden model kinds (ask, check, …) are false. */
|
|
438
438
|
catalog?: boolean;
|
|
439
439
|
needsModel?: boolean;
|
|
440
440
|
placement?: UnsysCanvasPlacementMode;
|
package/dist/core.js
CHANGED
|
@@ -2936,6 +2936,48 @@ function runUnsysCanvasCommand(input) {
|
|
|
2936
2936
|
return idle(null);
|
|
2937
2937
|
}
|
|
2938
2938
|
|
|
2939
|
+
// src/lib/work-canvas/command-errors.ts
|
|
2940
|
+
var MODEL_KIND_LABEL = {
|
|
2941
|
+
ask: "Ask",
|
|
2942
|
+
check: "Check",
|
|
2943
|
+
"selective-compress": "Compress",
|
|
2944
|
+
"suggest-insight": "Suggest insight",
|
|
2945
|
+
"clear-overlaps": "Clear overlaps",
|
|
2946
|
+
declutter: "Declutter"
|
|
2947
|
+
};
|
|
2948
|
+
function unsysCanvasCommandDisplayName(commandId) {
|
|
2949
|
+
const id = String(commandId || "").trim();
|
|
2950
|
+
if (!id || id === "ask") return "Ask";
|
|
2951
|
+
const catalog = UNSYS_CANVAS_COMMANDS.find((command) => command.id === id);
|
|
2952
|
+
if (catalog) return catalog.label;
|
|
2953
|
+
return MODEL_KIND_LABEL[id] ?? id;
|
|
2954
|
+
}
|
|
2955
|
+
function inferApiName(text, explicit) {
|
|
2956
|
+
const given = String(explicit || "").trim();
|
|
2957
|
+
if (given) return given;
|
|
2958
|
+
const lower = text.toLowerCase();
|
|
2959
|
+
if (lower.includes("openai")) return "OpenAI";
|
|
2960
|
+
if (lower.includes("anthropic") || lower.includes("claude")) return "Anthropic";
|
|
2961
|
+
return "xAI";
|
|
2962
|
+
}
|
|
2963
|
+
function formatUnsysCanvasApiError(input) {
|
|
2964
|
+
const api = inferApiName(`${input.apiName || ""} ${input.baseUrl || ""}`, input.apiName);
|
|
2965
|
+
const status = input.status != null && Number.isFinite(Number(input.status)) ? Number(input.status) : null;
|
|
2966
|
+
if (status === 401 || status === 403) {
|
|
2967
|
+
return `the ${api} API returned ${status}. Check the API key.`;
|
|
2968
|
+
}
|
|
2969
|
+
if (status) {
|
|
2970
|
+
const reason2 = String(input.reason || "").trim();
|
|
2971
|
+
return reason2 ? `the ${api} API returned ${status} (${reason2}).` : `the ${api} API returned ${status}.`;
|
|
2972
|
+
}
|
|
2973
|
+
const reason = String(input.reason || "").trim();
|
|
2974
|
+
return reason ? `the ${api} API failed (${reason}).` : `the ${api} API failed.`;
|
|
2975
|
+
}
|
|
2976
|
+
function formatUnsysCanvasUnparseableReply(commandId) {
|
|
2977
|
+
const name = unsysCanvasCommandDisplayName(commandId);
|
|
2978
|
+
return `${name} couldn't use the model reply because it wasn't valid.`;
|
|
2979
|
+
}
|
|
2980
|
+
|
|
2939
2981
|
// src/lib/work-canvas/work-canvas-xai.ts
|
|
2940
2982
|
var UNSYS_CANVAS_CONTEXT_TEXT_MAX = 220;
|
|
2941
2983
|
var UNSYS_CANVAS_CONTEXT_MAX_MARKS = 24;
|
|
@@ -2945,7 +2987,7 @@ function unsysCanvasXaiNeedsBoardContext(kind) {
|
|
|
2945
2987
|
function unsysCanvasXaiMaxTokens(kind) {
|
|
2946
2988
|
if (kind === "concepts") return 220;
|
|
2947
2989
|
if (kind === "simplify") return 280;
|
|
2948
|
-
if (kind === "pretty") return
|
|
2990
|
+
if (kind === "pretty") return 1600;
|
|
2949
2991
|
if (kind === "refactor" || kind === "check" || kind === "suggest-insight") return 400;
|
|
2950
2992
|
if (kind === "selective-compress" || kind === "clear-overlaps" || kind === "declutter") return 360;
|
|
2951
2993
|
return 800;
|
|
@@ -3133,9 +3175,16 @@ function unsysCanvasSceneVisiblyChanged(before, after) {
|
|
|
3133
3175
|
}
|
|
3134
3176
|
return false;
|
|
3135
3177
|
}
|
|
3136
|
-
function
|
|
3137
|
-
|
|
3138
|
-
return
|
|
3178
|
+
function applyUnsysCanvasCommandErrorNotice(input) {
|
|
3179
|
+
const text = String(input.message || "").trim();
|
|
3180
|
+
if (!text) return serializeUnsysCanvasScene(input.live);
|
|
3181
|
+
return withUnsysCanvasAutoLayout(
|
|
3182
|
+
mergeUnsysCanvasTurnOntoLiveWorkCanvas(
|
|
3183
|
+
input.live,
|
|
3184
|
+
{ text },
|
|
3185
|
+
{ fallbackOrigin: input.fallbackOrigin, reserved: input.reserved }
|
|
3186
|
+
)
|
|
3187
|
+
);
|
|
3139
3188
|
}
|
|
3140
3189
|
function applyUnsysCanvasAskReply(input) {
|
|
3141
3190
|
const live = serializeUnsysCanvasScene(input.live);
|
|
@@ -3180,6 +3229,9 @@ function applyUnsysCanvasAskReply(input) {
|
|
|
3180
3229
|
elements: input.payload.elements
|
|
3181
3230
|
});
|
|
3182
3231
|
if (placed.placed) next = placed.scene;
|
|
3232
|
+
else if (text || normalizeExtraSkeletons(input.payload.elements).length) {
|
|
3233
|
+
next = merge(text);
|
|
3234
|
+
}
|
|
3183
3235
|
} else if (kind === "concepts") {
|
|
3184
3236
|
const labels = unsysCanvasConceptLabels(source, {
|
|
3185
3237
|
text: input.payload.text,
|
|
@@ -3194,8 +3246,17 @@ function applyUnsysCanvasAskReply(input) {
|
|
|
3194
3246
|
next = merge(stripLearnerFacingWrappers(String(input.payload.text || "").trim()));
|
|
3195
3247
|
}
|
|
3196
3248
|
if (unsysCanvasSceneVisiblyChanged(live, next)) return withUnsysCanvasAutoLayout(next);
|
|
3197
|
-
const
|
|
3198
|
-
|
|
3249
|
+
const recoverable = stripLearnerFacingWrappers(String(input.payload.text || "").trim());
|
|
3250
|
+
if (recoverable || normalizeExtraSkeletons(input.payload.elements).length) {
|
|
3251
|
+
const recovered = merge(recoverable);
|
|
3252
|
+
if (unsysCanvasSceneVisiblyChanged(live, recovered)) return withUnsysCanvasAutoLayout(recovered);
|
|
3253
|
+
}
|
|
3254
|
+
return applyUnsysCanvasCommandErrorNotice({
|
|
3255
|
+
live,
|
|
3256
|
+
message: formatUnsysCanvasUnparseableReply(kind),
|
|
3257
|
+
fallbackOrigin: input.fallbackOrigin,
|
|
3258
|
+
reserved: input.reserved
|
|
3259
|
+
});
|
|
3199
3260
|
}
|
|
3200
3261
|
function applyUnsysCanvasPositionEdits(scene, selectedElements, reply) {
|
|
3201
3262
|
const current = serializeUnsysCanvasScene(scene);
|
|
@@ -3361,7 +3422,7 @@ function defaultBuildPrompt(commandId, context) {
|
|
|
3361
3422
|
timeoutMs: unsysCanvasXaiFetchTimeout(kind)
|
|
3362
3423
|
};
|
|
3363
3424
|
}
|
|
3364
|
-
var
|
|
3425
|
+
var MODEL_KIND_LABEL2 = {
|
|
3365
3426
|
ask: "Ask",
|
|
3366
3427
|
check: "Check",
|
|
3367
3428
|
"selective-compress": "Compress",
|
|
@@ -3372,8 +3433,8 @@ var MODEL_KIND_LABEL = {
|
|
|
3372
3433
|
function hiddenModelDef(id) {
|
|
3373
3434
|
return {
|
|
3374
3435
|
id,
|
|
3375
|
-
label:
|
|
3376
|
-
tooltip:
|
|
3436
|
+
label: MODEL_KIND_LABEL2[id] ?? id,
|
|
3437
|
+
tooltip: MODEL_KIND_LABEL2[id] ?? id,
|
|
3377
3438
|
shortcut: "",
|
|
3378
3439
|
needsSelection: id !== "ask",
|
|
3379
3440
|
boardOnly: false,
|
|
@@ -3645,7 +3706,7 @@ function createUnsysCanvasXaiBrowserRunner(options) {
|
|
|
3645
3706
|
return async (request) => {
|
|
3646
3707
|
const apiKey = String(await options.getApiKey() || "").trim();
|
|
3647
3708
|
if (!apiKey) {
|
|
3648
|
-
throw new Error("No API key.");
|
|
3709
|
+
throw new Error("No xAI API key.");
|
|
3649
3710
|
}
|
|
3650
3711
|
const baseURL = String(await options.getBaseUrl?.() || "").replace(/\/+$/, "") || "https://api.x.ai/v1";
|
|
3651
3712
|
const model = typeof options.model === "function" ? options.model(request.commandId) : options.model || "grok-4.7";
|
|
@@ -3678,7 +3739,15 @@ function createUnsysCanvasXaiBrowserRunner(options) {
|
|
|
3678
3739
|
if (!response.ok) {
|
|
3679
3740
|
const err = data.error;
|
|
3680
3741
|
const message = typeof err === "string" ? err : err && typeof err === "object" && "message" in err ? String(err.message || "") : "";
|
|
3681
|
-
|
|
3742
|
+
const apiName = /x\.ai/i.test(baseURL) ? "xAI" : "model";
|
|
3743
|
+
throw new Error(
|
|
3744
|
+
formatUnsysCanvasApiError({
|
|
3745
|
+
apiName,
|
|
3746
|
+
status: response.status,
|
|
3747
|
+
reason: message.trim(),
|
|
3748
|
+
baseUrl: baseURL
|
|
3749
|
+
})
|
|
3750
|
+
);
|
|
3682
3751
|
}
|
|
3683
3752
|
const text = choiceContent(data).trim();
|
|
3684
3753
|
if (!text) throw new Error("Canvas chat returned an empty reply.");
|
|
@@ -3704,7 +3773,7 @@ function createUnsysCanvasModelProxyRunner(options) {
|
|
|
3704
3773
|
const data = await response.json().catch(() => ({}));
|
|
3705
3774
|
if (!response.ok) {
|
|
3706
3775
|
const err = asRecord2(data.error);
|
|
3707
|
-
const message = err && typeof err.message === "string" && err.message || (typeof data.error === "string" ? data.error : "") || `
|
|
3776
|
+
const message = err && typeof err.message === "string" && err.message || (typeof data.error === "string" ? data.error : "") || `the model API returned ${response.status}`;
|
|
3708
3777
|
throw new Error(message);
|
|
3709
3778
|
}
|
|
3710
3779
|
const raw = typeof data.raw === "string" && data.raw.trim() ? data.raw : typeof data.message === "string" ? data.message : "";
|