Skip to content

Commit c0e7cd4

Browse files
committed
ai-node-canvas 0.83.0: the review is answered, and the progress panel lets go
The review of 0.82.0 left thirteen things to fix. They are fixed here; the one that was approved as it is stays as it is. A download could be sent to a machine of its own: the address was judged once, and the connection could go somewhere else. The address that was judged is now the address that is used - the name is resolved once, and the connection is pinned to that address, on every hop of a redirect. The private addresses are judged by the rules of Node's own BlockList, and an IPv6 address that carries an IPv4 inside it is judged by that IPv4. A file could be written through a link that points at nothing. A name that is already taken is refused instead of written through, and the name of a template is the name of the file that holds it: a template of the user cannot be overwritten, and a template that could not be applied is not saved. A run the runtime refused left the node busy for ever. The refusal now names the run that is going, the chain waits for that run, and the node is free the moment the run is refused. The progress panel could not be put away, and a run that had failed stayed on the screen for ever. It is a progress panel, not a history: a run that is over is kept thirty seconds so its reason can still be read, and then it goes. It has a button that puts it away, and a run that starts brings it back. The READMEs and the MCP description now say what the tools do: that a template can be listed and put on a canvas, that putting one there does not run it, and that a download can only go to an address the runtime is willing to reach. 246 tests, 246 mutations, 0 errors.
1 parent a1f514e commit c0e7cd4

17 files changed

Lines changed: 1112 additions & 179 deletions

File tree

‎plugins/antianqi/ai-node-canvas/.minimax-plugin/plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"schemaVersion": 1,
33
"name": "ai-node-canvas",
44
"displayName": "节点画布",
5-
"version": "0.82.0",
5+
"version": "0.83.0",
66
"description": "无限画布节点编排:把 MiniMax 模型生成的文本、图片、视频串成工作流,连线即数据流,上游产物可直接被下游引用。",
77
"author": "antianqi",
88
"icon": "icon.png",

‎plugins/antianqi/ai-node-canvas/README.md‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ this package.
312312
- **A template of the user can be managed** — every template of the user
313313
carries a delete button next to it (the question is asked in the page, like
314314
every other question here). The ready-made ones are not the user's to take
315-
away.
315+
away. **Deleting a template of the user cannot be undone**: the file is
316+
gone, and there is no copy of it anywhere.
316317
- **The canvas is a workbench, and it saves itself** — a change is written
317318
down about a second later, and the state beside the canvas name says
318319
whether it happened, so the toolbar has no **保存** button: a button that
@@ -639,6 +640,14 @@ separate pictures.
639640
other request — image, video, audio, music, voice catalogue, video
640641
understanding — goes through the Host connector (`context.hostConnector`),
641642
and the Host owns the credentials and the egress.
643+
- **The addresses a download may go to** — a link that points at this machine
644+
or at the network it sits in is refused: the loopback, the private ranges,
645+
the link-local range, the shared space of a carrier and the reserved ranges,
646+
in IPv4 and in IPv6 alike — including the forms that carry an IPv4 address
647+
inside an IPv6 one (`::ffff:7f00:1`, `::7f00:1`, `64:ff9b::7f00:1`). The
648+
name is looked up **once**, and the address that was judged is the address
649+
that is connected to, so a name cannot answer one thing for the check and
650+
another for the connection. Every hop of a redirect is judged the same way.
642651
- **The two steps of an upload** — the provider's upload command does not take
643652
a local path, because the provider cannot read this machine's disk. It takes
644653
the file name and the media type and answers with a signed form; the runtime

‎plugins/antianqi/ai-node-canvas/README.zh-CN.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ MiniMax Code 里的无限画布节点图。每个节点是一次模型运行,
154154
文件里只有步骤,没有结果也没有素材,所以换台机器打开也是完整的;
155155
一条链从哪张图起步,那个**空输入位**也跟着走,放的人自己往里放图。
156156
- **自己的模板能管** — 「我的模板」里每一条旁边都有删除按钮(删除前也是在页面里问,
157-
跟这里别的问题一样)。内置的那些不是你的,删不了。
157+
跟这里别的问题一样)。内置的那些不是你的,删不了。**删掉自己的模板找不回来**:
158+
文件没有了,机器上也不会留下另一份。
158159
- **画布是工作台,它自己会存** — 改动后一秒左右自己落盘,页头画布名旁边那颗状态芯片说了算,
159160
所以工具栏上**没有「保存」按钮**:手动再存一次只是把页面已经在做的事做第二遍。
160161
窗口关掉时那份本地草稿也跟着走,所以「刚改完就关」也不会丢。
@@ -398,6 +399,11 @@ provider 有**几种不同的请求**把素材变成视频,不是同一个请
398399
产物下载一份存本地(这样画布里的链接不会过期),本地文件要作为生成参考时会先
399400
上传给 provider(provider 够不到回环地址)。其余请求(图片、视频、音频、音乐、
400401
音色清单、视频理解)全部走宿主连接器(`context.hostConnector`),凭据与出网由宿主掌握。
402+
- **下载能去的地址** — 指向本机、指向本机所在网络的链接一律拒绝:回环、私有网段、
403+
链路本地、运营商共享地址段和保留网段,IPv4 与 IPv6 都一样,也包括把 IPv4
404+
藏在 IPv6 里的那几种写法(`::ffff:7f00:1`、`::7f00:1`、`64:ff9b::7f00:1`)。
405+
主机名**只解析一次**,判定用的那个地址就是连接用的那个地址,所以同一个名字
406+
没法「查的时候是一回事、连的时候是另一回事」。重定向的每一跳都按同一条规则判。
401407
- **上传的两步** — provider 的上传命令不收本地路径(provider 读不到本机磁盘):
402408
它收文件名与媒体类型,回一份预签名表单;运行时再把字节以 `multipart/form-data`
403409
POST 到那份表单指向的主机(表单字段原样带上,文件放在 `file_field_name` 指定的那一项)。

‎plugins/antianqi/ai-node-canvas/miniapp/client/actions.mjs‎

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -528,26 +528,15 @@ function templateRef(value, ids) {
528528
export function applyTemplate(canvas, template, context = {}) {
529529
const doc = canvas ?? { nodes: [], connections: [] };
530530
const actions = Array.isArray(template?.actions) ? template.actions : [];
531-
if (!actions.length) return { canvas: doc, error: '这个模板是空的' };
532531
// A template is a skeleton: it may make nodes and draw the lines between
533532
// them. It may not take anything away — a template that could would tidy
534533
// up a canvas it was dropped on, and the steps of a chain are not a licence
535-
// to remove things.
536-
for (const action of actions) {
537-
const type = String(action?.type ?? '');
538-
if (!TEMPLATE_ACTION_TYPES.includes(type)) {
539-
return {
540-
canvas: doc,
541-
error: `模板里有一步做不了的事:${type || '(没有说是什么)'}(模板只能:${TEMPLATE_ACTION_TYPES.join('、')})`,
542-
};
543-
}
544-
if (type === 'connect') {
545-
const from = String(action?.args?.from ?? '');
546-
const to = String(action?.args?.to ?? '');
547-
if (!/^@\d+$/.test(from) || !/^@\d+$/.test(to)) {
548-
return { canvas: doc, error: '模板里的线要指向模板自己做的节点(@1 这样的名字)' };
549-
}
550-
}
534+
// to remove things. The steps are judged by the one rule that judges them
535+
// everywhere: the file that is read, the canvas the template is put on and
536+
// the place it is kept in.
537+
const problem = templateStepsError(actions);
538+
if (problem) {
539+
return { canvas: doc, error: problem };
551540
}
552541
const ctx = { idFor: fallbackId, ...context };
553542
const view = doc.viewport ?? { x: 80, y: 60 };
@@ -661,6 +650,36 @@ export const TEMPLATE_FILE_VERSION = 1;
661650
*/
662651
export const TEMPLATE_ACTION_TYPES = ['add_node', 'connect'];
663652

653+
/**
654+
* Whether the steps of a template are steps a template may carry.
655+
*
656+
* One rule, read by the three places that meet a template: the file that is
657+
* read, the canvas a template is put on, and the place a template is kept
658+
* in. The answer is empty when the steps are fine, and says what is wrong
659+
* when they are not.
660+
*/
661+
export function templateStepsError(actions) {
662+
const list = Array.isArray(actions) ? actions : [];
663+
if (!list.length) return '这个模板里没有步骤';
664+
for (const action of list) {
665+
if (!action || typeof action !== 'object' || !action.args || typeof action.args !== 'object') {
666+
return '这个模板里有一步写坏了';
667+
}
668+
const type = String(action.type ?? '');
669+
if (!TEMPLATE_ACTION_TYPES.includes(type)) {
670+
return `这个模板里有一步不是节点也不是连线:${type || '空'}(模板只能:${TEMPLATE_ACTION_TYPES.join('、')})`;
671+
}
672+
if (type === 'connect') {
673+
const from = String(action.args.from ?? '');
674+
const to = String(action.args.to ?? '');
675+
if (!/^@\d+$/.test(from) || !/^@\d+$/.test(to)) {
676+
return '模板里的线要指向模板自己做的节点(@1 这样的名字)';
677+
}
678+
}
679+
}
680+
return '';
681+
}
682+
664683
/**
665684
* The document a template is shared as.
666685
*
@@ -705,16 +724,10 @@ export function readTemplateFile(text) {
705724
return { ok: false, error: '这个模板的版本比这个画布新,请先更新画布' };
706725
}
707726
const actions = parsed.actions;
708-
if (!Array.isArray(actions) || !actions.length) {
709-
return { ok: false, error: '这个模板里没有步骤' };
710-
}
711-
for (const action of actions) {
712-
if (!action || typeof action !== 'object' || !action.args || typeof action.args !== 'object') {
713-
return { ok: false, error: '这个模板里有一步写坏了' };
714-
}
715-
if (action.type !== 'add_node' && action.type !== 'connect') {
716-
return { ok: false, error: `这个模板里有一步不是节点也不是连线:${action.type ?? '空'}` };
717-
}
727+
// The steps are judged by the one rule that judges them everywhere.
728+
const problem = templateStepsError(actions);
729+
if (problem) {
730+
return { ok: false, error: problem };
718731
}
719732
return {
720733
ok: true,
@@ -727,6 +740,18 @@ export function readTemplateFile(text) {
727740
};
728741
}
729742

743+
/**
744+
* The name a canvas takes from a template.
745+
*
746+
* The name is given to the canvas only when the steps are really on it: a
747+
* template that does not fit leaves the canvas as it was, so a canvas with a
748+
* name and no steps is never stored.
749+
*/
750+
export function canvasTitleAfterTemplate(template, applied) {
751+
if (!applied) return '';
752+
return String(template?.title ?? '').trim();
753+
}
754+
730755
/**
731756
* Apply one action to a canvas document.
732757
*

‎plugins/antianqi/ai-node-canvas/miniapp/client/app.js‎

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
import { detectMention, parseSegments, plainText, textIndexBefore } from './mention.mjs';
1313
import { bandSelection, BATCH_COUNTS, BATCH_MODES, cropRectAfterDrag, dragPositions, effectiveOption, fanOutParams, fitMediaBox, fitParamsToCaps, inputKindsFor, isControlTarget, kindOf, mentionCandidates as mentionCandidatesOf, modelSummary, NODE_GAP, placeOverlay, planBatchPlacement, planGridSplit, planPaste, portOfConnection, portState, pushAside, resolveEventTarget, roleOf, slotsOf as slotsOfForm, TILE_CARD, toolPrompt, upstreamNodes } from './tools.mjs';
1414
import { cardChrome, DATA_KINDS, hasTextBox, isTypingTarget, modeLabelOf, modesFor, NODE_FORMS, NODE_KINDS, modeOf, modeRecordOf, modesOf, portKinds, portKindsFor, portList, ratioLabel, ratioOptionsFor, redrawBlocker, runModeOf, stripInputs } from './forms.mjs';
15-
import { isBusyRefusal, runIsGone, waitForTheRun, withDeadline } from './run-watch.mjs';
16-
import { applyAction, applyModel, inheritedTextFor, lineKind, linesDroppedByMode, materializeResults, planIncoming, planPort, promptTemplateFor, readTemplateFile, runSpecFor, syncMentions, templateFile, templateFromCanvas } from './actions.mjs';
15+
import { isBusyRefusal, panelClosed, panelIsShown, panelTasks, runIsGone, taskIsExpired, theRunThatIsGoing, theRunToWaitFor, waitForTheRun, withDeadline } from './run-watch.mjs';
16+
import { panelTitleRow } from './task-panel.mjs';
17+
import { applyAction, applyModel, canvasTitleAfterTemplate, inheritedTextFor, lineKind, linesDroppedByMode, materializeResults, planIncoming, planPort, promptTemplateFor, readTemplateFile, runSpecFor, syncMentions, templateFile, templateFromCanvas } from './actions.mjs';
1718

1819
(() => {
1920
'use strict';
@@ -101,6 +102,8 @@ import { applyAction, applyModel, inheritedTextFor, lineKind, linesDroppedByMode
101102
nodeTasks: new Map(), // nodeId -> taskId
102103
polling: new Set(), // taskIds whose poll is still on its way
103104
pollTimer: null,
105+
// The user put the progress panel away: it comes back when a run starts.
106+
taskPanelClosed: false,
104107
actionTimer: null,
105108
saveTimer: null,
106109
historyTimer: null,
@@ -161,6 +164,9 @@ import { applyAction, applyModel, inheritedTextFor, lineKind, linesDroppedByMode
161164
const error = new Error(payload?.message || payload?.error || `HTTP ${response.status}`);
162165
error.code = payload?.error || 'http_error';
163166
error.status = response.status;
167+
// A refused run names the run that is going: the one that asked waits
168+
// for that run instead of standing still.
169+
if (payload?.runId) error.runId = payload.runId;
164170
if (response.status === 401) {
165171
// The Host rotates the loopback credential when the runtime restarts,
166172
// and that happens on every plugin update. The page still holds the
@@ -3230,14 +3236,18 @@ import { applyAction, applyModel, inheritedTextFor, lineKind, linesDroppedByMode
32303236
}
32313237
state.pendingPanel = false;
32323238
const now = Date.now();
3233-
const tasks = [...state.tasks.values()].filter(
3234-
(task) => task.status === 'running' || task.status === 'waiting-question' || task.status === 'error'
3235-
// A run that just finished stays a moment. Its log says how long it
3236-
// waited for the machine and how long it ran, and that is the answer
3237-
// to "why was this one slower?".
3238-
|| (task.status === 'done' && now - (task.finishedAt ?? 0) < 30_000),
3239-
);
3240-
if (tasks.length === 0) {
3239+
// The panel shows what is going on and what just finished. A run that is
3240+
// over stays a moment — a failed one too, so the reason can be read — and
3241+
// then it goes: the panel is not a history of everything that ever ran.
3242+
const tasks = panelTasks(state.tasks.values(), { now });
3243+
// A run that is over and out of the panel is let go: the table does not
3244+
// grow for ever.
3245+
for (const [id, task] of state.tasks) {
3246+
if (taskIsExpired(task, { now })) state.tasks.delete(id);
3247+
}
3248+
// The panel sits over the canvas, so the user can put it away. It comes
3249+
// back when a run starts, because that is what the panel is for.
3250+
if (!panelIsShown({ closed: state.taskPanelClosed, tasks })) {
32413251
// The panel is hidden, but its old content is cleared as well: a hidden
32423252
// panel that still holds buttons is a stale control in the page.
32433253
panel.hidden = true;
@@ -3246,7 +3256,13 @@ import { applyAction, applyModel, inheritedTextFor, lineKind, linesDroppedByMode
32463256
}
32473257
panel.hidden = false;
32483258
panel.textContent = '';
3249-
panel.appendChild(el('div', 'nxc-taskpanel__title', '运行进度'));
3259+
const title = panelTitleRow(document, {
3260+
onPutAway: () => {
3261+
state.taskPanelClosed = panelClosed({ closed: state.taskPanelClosed, event: 'put-away' });
3262+
panel.hidden = true;
3263+
},
3264+
});
3265+
panel.appendChild(title);
32503266
for (const task of tasks) {
32513267
const item = el('div', 'nxc-taskpanel__item');
32523268
const head = el('div', 'nxc-taskpanel__head');
@@ -3617,14 +3633,15 @@ import { applyAction, applyModel, inheritedTextFor, lineKind, linesDroppedByMode
36173633
);
36183634
if (applied.error) {
36193635
showBanner(`模板没有铺上:${applied.error}`, 'error');
3620-
return;
3636+
return false;
36213637
}
36223638
state.canvas.nodes = applied.canvas.nodes;
36233639
state.canvas.connections = applied.canvas.connections;
36243640
state.selection = [];
36253641
markDirty();
36263642
render();
36273643
showBanner(`已铺上「${template.title}」,点节点上的「生成」开始`);
3644+
return true;
36283645
}
36293646

36303647
/**
@@ -3662,7 +3679,8 @@ import { applyAction, applyModel, inheritedTextFor, lineKind, linesDroppedByMode
36623679
* The question is asked in the page: a native confirm() is a separate OS
36633680
* window that never reaches the screen inside the MiniApp host.
36643681
*/
3665-
async function deleteTemplate(template) { const yes = await confirmInPage(`确定删掉模板「${template.title}」?画布本身不受影响。`);
3682+
async function deleteTemplate(template) {
3683+
const yes = await confirmInPage(`确定删掉模板「${template.title}」?画布本身不受影响,删掉就找不回来了。`);
36663684
if (!yes) return;
36673685
try {
36683686
await api(`/api/templates/${encodeURIComponent(template.id)}`, { method: 'DELETE' });
@@ -3920,23 +3938,26 @@ import { applyAction, applyModel, inheritedTextFor, lineKind, linesDroppedByMode
39203938
}
39213939

39223940
/** Wait for the run that was started on this node to finish. */
3923-
function waitForRun(nodeId, timeoutMs = 2_700_000) {
3941+
function waitForRun(nodeId, taskId = '', timeoutMs = 2_700_000) {
39243942
// The run this wait is about is held on to. The page forgets which run
39253943
// belongs to a node as soon as that run is over — the node is free to run
39263944
// again — so a waiter that looked the run up again would never see it
39273945
// finish, and the chain would stand still until its own timeout.
3928-
const taskId = state.nodeTasks.get(nodeId);
3946+
const id = theRunToWaitFor({ taskId, nodeId, known: state.nodeTasks });
39293947
return waitForTheRun({
3930-
taskId,
3931-
readTask: (id) => state.tasks.get(id),
3948+
taskId: id,
3949+
readTask: (task) => state.tasks.get(task),
39323950
timeoutMs,
39333951
});
39343952
}
39353953

39363954
/** Run a node and wait for its result. */
39373955
async function runAndWait(node) {
3938-
await startRun(node, { chain: false });
3939-
const task = await waitForRun(node.id);
3956+
const started = await startRun(node, { chain: false });
3957+
// The run that was started is the run that is waited for: the id is
3958+
// handed over, so a run that is over before the waiter looks it up is
3959+
// still waited for.
3960+
const task = await waitForRun(node.id, started?.id ?? '');
39403961
return task?.status === 'done';
39413962
}
39423963

@@ -4009,6 +4030,9 @@ import { applyAction, applyModel, inheritedTextFor, lineKind, linesDroppedByMode
40094030
const task = payload.run;
40104031
state.tasks.set(task.id, task);
40114032
state.nodeTasks.set(node.id, task.id);
4033+
// A run is starting, so the progress panel is worth showing again: the
4034+
// user put it away, but this is what it is for.
4035+
state.taskPanelClosed = panelClosed({ closed: state.taskPanelClosed, event: 'run-started' });
40124036
if (task.sessionId) node.metadata.sessionId = task.sessionId;
40134037
ensurePolling();
40144038
render();
@@ -4024,6 +4048,14 @@ import { applyAction, applyModel, inheritedTextFor, lineKind, linesDroppedByMode
40244048
showBanner(String(error?.message ?? error));
40254049
markDirty();
40264050
render();
4051+
// The runtime names the run that is going, so the chain can wait for
4052+
// it even when this page is the one that did not start it.
4053+
const running = theRunThatIsGoing(error);
4054+
if (running) {
4055+
state.nodeTasks.set(node.id, running);
4056+
ensurePolling();
4057+
return { id: running, status: 'running', busy: true };
4058+
}
40274059
return null;
40284060
}
40294061
node.metadata.output.status = 'error';
@@ -4991,9 +5023,15 @@ import { applyAction, applyModel, inheritedTextFor, lineKind, linesDroppedByMode
49915023
const empty = Boolean(state.canvas?.id) && !(state.canvas?.nodes?.length);
49925024
if (empty) {
49935025
// The canvas that is open is empty: it becomes the canvas of this
4994-
// template, and it takes the name of it.
4995-
if (template.title) state.canvas.title = template.title;
4996-
applyTemplateOnCanvas(template);
5026+
// template. The name is given to it only when the steps are really on
5027+
// it, so a template that does not fit leaves no canvas with a name and
5028+
// no steps.
5029+
const applied = applyTemplateOnCanvas(template);
5030+
const title = canvasTitleAfterTemplate(template, applied);
5031+
if (!title) return;
5032+
state.canvas.title = title;
5033+
markDirty();
5034+
render();
49975035
return;
49985036
}
49995037
await createCanvas(`${template.title || '新画布'}`, { askName: false });

‎plugins/antianqi/ai-node-canvas/miniapp/client/forms.mjs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ export function modesOf(node) {
191191
* lands on the mode that is left.
192192
*/
193193
export function currentModeId(modeId) {
194-
return LEGACY_MODES[modeId] ?? modeId;
194+
// The lookup is exact: a name that is not in the table is not a mode of the
195+
// old names, and it stays the name it is.
196+
return Object.hasOwn(LEGACY_MODES, modeId) ? LEGACY_MODES[modeId] : modeId;
195197
}
196198

197199
/** The mode a node is in. */

0 commit comments

Comments
 (0)