dsh-drawai 0.2.1 → 0.2.3

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 (2) hide show
  1. package/lib/index.js +15 -5
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -809,6 +809,9 @@ async function applyOps(doc, ops, out, opctx) {
809
809
  if (typeof op.label === 'string') synthetic.label = op.label
810
810
  if (has(op, 'x')) synthetic.x = op.x
811
811
  if (has(op, 'y')) synthetic.y = op.y
812
+ // 就地插一条 addNode 紧随其后(读像素是 async 的,所以这条 op 不能在解析参数时先展开)。
813
+ // 注意:这里改的必须是**我们自己那份** ops —— 调用方(execute)已经 slice 过,
814
+ // 因为宿主给的 arguments 是深冻结的,直接 splice 会抛 "object is not extensible"。
812
815
  ops.splice(i + 1, 0, synthetic)
813
816
  notes.push(
814
817
  '🖼 ' + rawImage + ' → 逐像素矢量化:' + metrics.palette.length + ' 色 / ' + metrics.paths + ' 条 path / ' +
@@ -2900,7 +2903,13 @@ export function apply(ctx) {
2900
2903
  const focused = focusedPathFor(sessionIdOf(exec))
2901
2904
  const path =
2902
2905
  typeof args.path === 'string' && args.path.length > 0 ? args.path : focused !== undefined && focused.length > 0 ? focused : DEFAULT_PATH
2903
- const ops = Array.isArray(args.ops) ? args.ops : []
2906
+ // **入参是宿主深冻结的**:dsh-tools 在 execute 之前把整份 arguments 深冻结
2907
+ // (`arguments: deepFreeze(snapshotJsonValue(exec.arguments))`,见 dsh-tools 的 tool 执行器),
2908
+ // 数组和里面的 op 对象都是 non-extensible。所以这里必须**复制成一份可扩展的数组**再用:
2909
+ // traceImage 会往 ops 里插一条合成的 addNode(见下面 applyOps 里的 `ops.splice`),
2910
+ // 就地改冻结数组会抛 `Cannot add property N, object is not extensible`。
2911
+ // op 落盘语义不受影响 —— 复制出来的数组里元素仍是原来那些(本文件只读它们,从不写回)。
2912
+ const ops = Array.isArray(args.ops) ? args.ops.slice() : []
2904
2913
  if (ops.length === 0) throw new Error('ops must contain at least one operation')
2905
2914
 
2906
2915
  const sessionId = sessionIdOf(exec)
@@ -3336,10 +3345,11 @@ function sanitizeNewName(raw) {
3336
3345
  ? 'DrawAI 画布:用户现在打开的是 ' + path + '。diagram_read / diagram_apply 不传 path 时默认就操作这一张。'
3337
3346
  : 'DrawAI 画布:用户关掉了画布(此刻没有打开任何一张)。不传 path 时工具会退回 ' + DEFAULT_PATH + '。'
3338
3347
  try {
3339
- // 形状照 @deepseek-ai/dsh-llm 的 UserMessage:role + content + source。
3340
- // source 用 `{ kind: 'plugin', plugin: <本插件名> }`(与第一方 dsh-agent-instructions 同款);
3341
- // 不带 form —— 它只是个"环境事实",不是 instructions/catalog 那几类。
3342
- agent.inject({ role: 'user', content: [{ type: 'text', text: text }], source: { kind: 'plugin', plugin: name } })
3348
+ // Session V4 要求 producer-owned source kind:字面量 `'plugin'` 会被拒
3349
+ // (format v4 message requires a producer-owned source kind)。
3350
+ // 目标形是 `{ kind: 'plugin:<名>' }`(V3→V4 迁移对旧 wrapper 也写成这样),
3351
+ // 对 user/message 注入在 V3/V4 都可过;不带 form —— 它只是"环境事实"。
3352
+ agent.inject({ role: 'user', content: [{ type: 'text', text: text }], source: { kind: 'plugin:' + name } })
3343
3353
  } catch (error) {
3344
3354
  // 注入失败不该影响画布本身:工具那条回退链还在。
3345
3355
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-drawai",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "type": "module",
5
5
  "description": "DSH 右侧栏的可编辑画布 + AI 语义绘图工具(diagram_apply / diagram_read),直接读写原生 .drawio 文件",
6
6
  "license": "MIT",