@dinoxx/dinox-cli 2.18.5 → 2.20.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/LICENSE +15 -0
- package/README.md +17 -17
- package/dist/chunks/applePodcast-V4FSJOC5.js +169 -0
- package/dist/chunks/bbc-NTMRPYRF.js +570 -0
- package/dist/chunks/bilibili-UA3MBSPH.js +835 -0
- package/dist/chunks/bohaishibei-B7UVXH4Y.js +246 -0
- package/dist/chunks/chunk-224ML7QC.js +21 -0
- package/dist/chunks/chunk-2LW76QIL.js +32 -0
- package/dist/chunks/chunk-2M7RJATW.js +60 -0
- package/dist/chunks/chunk-3EKNTO6G.js +61 -0
- package/dist/chunks/chunk-3VZNZWDG.js +437 -0
- package/dist/chunks/chunk-5JF7J5MP.js +114 -0
- package/dist/chunks/chunk-5KU25TMX.js +26 -0
- package/dist/chunks/chunk-67RXND3H.js +65 -0
- package/dist/chunks/chunk-6AZT4ARG.js +1491 -0
- package/dist/chunks/chunk-6D3QLMRM.js +421 -0
- package/dist/chunks/chunk-6VMHHE5Y.js +235 -0
- package/dist/chunks/chunk-77UP745T.js +143 -0
- package/dist/chunks/chunk-7A5QISPG.js +19 -0
- package/dist/chunks/chunk-7ODU7LXP.js +31 -0
- package/dist/chunks/chunk-A6WF7CZL.js +904 -0
- package/dist/chunks/chunk-ABYPGMDC.js +100 -0
- package/dist/chunks/chunk-AHRCI2RW.js +141 -0
- package/dist/chunks/chunk-BDLS5EEP.js +49 -0
- package/dist/chunks/chunk-BKCNERPB.js +246 -0
- package/dist/chunks/chunk-BZQYECIH.js +54 -0
- package/dist/chunks/chunk-D5SBKLDX.js +71 -0
- package/dist/chunks/chunk-DR6BGSZM.js +865 -0
- package/dist/chunks/chunk-F7BDWXBG.js +57 -0
- package/dist/chunks/chunk-FGQRYB7F.js +34 -0
- package/dist/chunks/chunk-FIQYJ6KZ.js +19 -0
- package/dist/chunks/chunk-FKLZZGEX.js +116 -0
- package/dist/chunks/chunk-FZGEWY5L.js +37 -0
- package/dist/chunks/chunk-GTDX2LIJ.js +265 -0
- package/dist/chunks/chunk-HIJXC3RT.js +194 -0
- package/dist/chunks/chunk-HQJUJYUM.js +36 -0
- package/dist/chunks/chunk-IAEJG5NI.js +50 -0
- package/dist/chunks/chunk-KCHHY6QB.js +65 -0
- package/dist/chunks/chunk-KL75BFYJ.js +71 -0
- package/dist/chunks/chunk-KOAKG2QU.js +45 -0
- package/dist/chunks/chunk-MCFXD2LS.js +66 -0
- package/dist/chunks/chunk-MLOITAK6.js +29 -0
- package/dist/chunks/chunk-N44NRKDJ.js +101 -0
- package/dist/chunks/chunk-N6ALWINB.js +14115 -0
- package/dist/chunks/chunk-NGIIELO4.js +61 -0
- package/dist/chunks/chunk-OG6MBAGC.js +95 -0
- package/dist/chunks/chunk-P4LG4DIO.js +108 -0
- package/dist/chunks/chunk-PJDD4R46.js +77 -0
- package/dist/chunks/chunk-PK5AOVLU.js +107 -0
- package/dist/chunks/chunk-PTFGE4KS.js +66 -0
- package/dist/chunks/chunk-Q6G7VO5G.js +67 -0
- package/dist/chunks/chunk-QFUD3I7W.js +185 -0
- package/dist/chunks/chunk-QNIYFLJT.js +39 -0
- package/dist/chunks/chunk-QZQRG3JY.js +86 -0
- package/dist/chunks/chunk-RKJYKUQD.js +91 -0
- package/dist/chunks/chunk-TAENC45D.js +160 -0
- package/dist/chunks/chunk-TILRKKRN.js +20481 -0
- package/dist/chunks/chunk-TIXOORAP.js +60 -0
- package/dist/chunks/chunk-ULKGDBAJ.js +80 -0
- package/dist/chunks/chunk-URYABAYN.js +72 -0
- package/dist/chunks/chunk-VNB4ZFLN.js +86 -0
- package/dist/chunks/chunk-W7R5JTSA.js +42 -0
- package/dist/chunks/chunk-WC3GSQBC.js +25699 -0
- package/dist/chunks/chunk-WMJXAF3X.js +55 -0
- package/dist/chunks/chunk-X36EIV25.js +93 -0
- package/dist/chunks/chunk-X7IZXCSL.js +60 -0
- package/dist/chunks/chunk-XEPDFQYD.js +215 -0
- package/dist/chunks/chunk-XFVLNCOW.js +171 -0
- package/dist/chunks/chunk-XMMTGPZ6.js +1332 -0
- package/dist/chunks/chunk-XQZUX7OT.js +39 -0
- package/dist/chunks/chunk-XZLFMJOG.js +72 -0
- package/dist/chunks/chunk-ZGF3OEWR.js +84 -0
- package/dist/chunks/chunk-ZHKS4R4P.js +1215 -0
- package/dist/chunks/cookies-6QQHSM26.js +34 -0
- package/dist/chunks/dedaoNote-KJ32ZQLS.js +418 -0
- package/dist/chunks/doubanGroup-HR4K2KMY.js +429 -0
- package/dist/chunks/doubao-MXUHPLUB.js +462 -0
- package/dist/chunks/douyin-UU2FSQPS.js +566 -0
- package/dist/chunks/ensure-MLNCD2SD.js +18 -0
- package/dist/chunks/execute-57M65KKK.js +17 -0
- package/dist/chunks/facebook-SZFOVE7R.js +878 -0
- package/dist/chunks/feishu-ISWRJ7HI.js +877 -0
- package/dist/chunks/ima-D7CX5WR4.js +202 -0
- package/dist/chunks/instagram-HNDPO37H.js +939 -0
- package/dist/chunks/install-IIMVFNAT.js +303 -0
- package/dist/chunks/jike-H7L4LJTN.js +445 -0
- package/dist/chunks/mcp-PZBHAYXQ.js +297 -0
- package/dist/chunks/mcpServer-T4DNYR7R.js +436 -0
- package/dist/chunks/metaso-ZVZW5UBB.js +194 -0
- package/dist/chunks/run-GCMWLTIV.js +1464 -0
- package/dist/chunks/runCli-SBQE2VQJ.js +464 -0
- package/dist/chunks/setup-EEU6GSWX.js +378 -0
- package/dist/chunks/threads-ADW6IANQ.js +657 -0
- package/dist/chunks/twitter-NAGCB3NI.js +1148 -0
- package/dist/chunks/web-QFKZCM4F.js +31 -0
- package/dist/chunks/wechat-OXNNLT4J.js +1551 -0
- package/dist/chunks/weibo-PMVGDNQU.js +641 -0
- package/dist/chunks/workbuddy-NNAXIIIZ.js +426 -0
- package/dist/chunks/xiaoheihe-WFQJRBAD.js +316 -0
- package/dist/chunks/xiaohongshu-5CXBELGW.js +1833 -0
- package/dist/chunks/xiaoyuzhou-6L6IB46Y.js +322 -0
- package/dist/chunks/youtube-52NGBTQC.js +58 -0
- package/dist/chunks/zcool-HDSWK4KD.js +755 -0
- package/dist/chunks/zhihu-EX2VRJYY.js +1024 -0
- package/dist/dinox.js +137 -51
- package/dist/dsh-plugin/lib/client.js +754 -317
- package/dist/dsh-plugin/lib/index.js +7 -2
- package/dist/dsh-plugin/package.json +1 -1
- package/dist/dsh-plugin/runtime.json +3 -3
- package/dist/editor-ui/mcp-app.html +325 -303
- package/package.json +81 -63
- package/dist/ai/ragxClient.d.ts +0 -15
- package/dist/ai/ragxClient.js +0 -71
- package/dist/auth/devicePair.d.ts +0 -62
- package/dist/auth/devicePair.js +0 -377
- package/dist/auth/userInfo.d.ts +0 -26
- package/dist/auth/userInfo.js +0 -224
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -130
- package/dist/cliTypes.d.ts +0 -7
- package/dist/cliTypes.js +0 -1
- package/dist/commands/auth/index.d.ts +0 -34
- package/dist/commands/auth/index.js +0 -605
- package/dist/commands/batch.d.ts +0 -35
- package/dist/commands/batch.js +0 -202
- package/dist/commands/boxes/index.d.ts +0 -4
- package/dist/commands/boxes/index.js +0 -382
- package/dist/commands/boxes/model.d.ts +0 -37
- package/dist/commands/boxes/model.js +0 -93
- package/dist/commands/boxes/operations.d.ts +0 -86
- package/dist/commands/boxes/operations.js +0 -448
- package/dist/commands/boxes/repo.d.ts +0 -36
- package/dist/commands/boxes/repo.js +0 -320
- package/dist/commands/boxes/store.d.ts +0 -22
- package/dist/commands/boxes/store.js +0 -143
- package/dist/commands/config/index.d.ts +0 -5
- package/dist/commands/config/index.js +0 -105
- package/dist/commands/descriptor/register.d.ts +0 -8
- package/dist/commands/descriptor/register.js +0 -122
- package/dist/commands/descriptor/types.d.ts +0 -37
- package/dist/commands/descriptor/types.js +0 -17
- package/dist/commands/doctor.d.ts +0 -126
- package/dist/commands/doctor.js +0 -558
- package/dist/commands/domain/options.d.ts +0 -10
- package/dist/commands/domain/options.js +0 -75
- package/dist/commands/domain/run.d.ts +0 -24
- package/dist/commands/domain/run.js +0 -137
- package/dist/commands/editor/index.d.ts +0 -4
- package/dist/commands/editor/index.js +0 -155
- package/dist/commands/gateway/index.d.ts +0 -4
- package/dist/commands/gateway/index.js +0 -340
- package/dist/commands/graph/index.d.ts +0 -4
- package/dist/commands/graph/index.js +0 -173
- package/dist/commands/graph/repo.d.ts +0 -40
- package/dist/commands/graph/repo.js +0 -201
- package/dist/commands/info/index.d.ts +0 -4
- package/dist/commands/info/index.js +0 -75
- package/dist/commands/mcp.d.ts +0 -6
- package/dist/commands/mcp.js +0 -47
- package/dist/commands/meta/index.d.ts +0 -4
- package/dist/commands/meta/index.js +0 -60
- package/dist/commands/meta/repo.d.ts +0 -30
- package/dist/commands/meta/repo.js +0 -76
- package/dist/commands/notes/actions.d.ts +0 -12
- package/dist/commands/notes/actions.js +0 -591
- package/dist/commands/notes/bulk.d.ts +0 -35
- package/dist/commands/notes/bulk.js +0 -195
- package/dist/commands/notes/contentEngine.d.ts +0 -95
- package/dist/commands/notes/contentEngine.js +0 -710
- package/dist/commands/notes/contentPatch.d.ts +0 -114
- package/dist/commands/notes/contentPatch.js +0 -450
- package/dist/commands/notes/contentPatchCommand.d.ts +0 -6
- package/dist/commands/notes/contentPatchCommand.js +0 -164
- package/dist/commands/notes/createFromTemplate.d.ts +0 -35
- package/dist/commands/notes/createFromTemplate.js +0 -58
- package/dist/commands/notes/descriptors.d.ts +0 -4
- package/dist/commands/notes/descriptors.js +0 -548
- package/dist/commands/notes/detailContent.d.ts +0 -19
- package/dist/commands/notes/detailContent.js +0 -62
- package/dist/commands/notes/dryRun.d.ts +0 -33
- package/dist/commands/notes/dryRun.js +0 -133
- package/dist/commands/notes/export.d.ts +0 -27
- package/dist/commands/notes/export.js +0 -252
- package/dist/commands/notes/index.d.ts +0 -2
- package/dist/commands/notes/index.js +0 -2
- package/dist/commands/notes/metadataMutation.d.ts +0 -29
- package/dist/commands/notes/metadataMutation.js +0 -138
- package/dist/commands/notes/repo/read.d.ts +0 -8
- package/dist/commands/notes/repo/read.js +0 -302
- package/dist/commands/notes/repo/resolve.d.ts +0 -8
- package/dist/commands/notes/repo/resolve.js +0 -187
- package/dist/commands/notes/repo/search.d.ts +0 -43
- package/dist/commands/notes/repo/search.js +0 -513
- package/dist/commands/notes/repo/semantic.d.ts +0 -14
- package/dist/commands/notes/repo/semantic.js +0 -31
- package/dist/commands/notes/repo/shared.d.ts +0 -192
- package/dist/commands/notes/repo/shared.js +0 -102
- package/dist/commands/notes/repo/write.d.ts +0 -27
- package/dist/commands/notes/repo/write.js +0 -262
- package/dist/commands/notes/repo.d.ts +0 -7
- package/dist/commands/notes/repo.js +0 -7
- package/dist/commands/notes/runtime.d.ts +0 -20
- package/dist/commands/notes/runtime.js +0 -175
- package/dist/commands/notes/searchOutput.d.ts +0 -15
- package/dist/commands/notes/searchOutput.js +0 -54
- package/dist/commands/notes/searchResponse.d.ts +0 -54
- package/dist/commands/notes/searchResponse.js +0 -57
- package/dist/commands/notes/searchSql.d.ts +0 -11
- package/dist/commands/notes/searchSql.js +0 -614
- package/dist/commands/notes/searchTime.d.ts +0 -9
- package/dist/commands/notes/searchTime.js +0 -85
- package/dist/commands/notes/semantic.d.ts +0 -116
- package/dist/commands/notes/semantic.js +0 -332
- package/dist/commands/notes/writeReceipt.d.ts +0 -20
- package/dist/commands/notes/writeReceipt.js +0 -82
- package/dist/commands/prompt/index.d.ts +0 -5
- package/dist/commands/prompt/index.js +0 -132
- package/dist/commands/prompt/repo.d.ts +0 -28
- package/dist/commands/prompt/repo.js +0 -220
- package/dist/commands/properties/index.d.ts +0 -16
- package/dist/commands/properties/index.js +0 -640
- package/dist/commands/properties/repo.d.ts +0 -150
- package/dist/commands/properties/repo.js +0 -272
- package/dist/commands/runtime.d.ts +0 -54
- package/dist/commands/runtime.js +0 -228
- package/dist/commands/savedViews/fields.d.ts +0 -28
- package/dist/commands/savedViews/fields.js +0 -87
- package/dist/commands/savedViews/index.d.ts +0 -7
- package/dist/commands/savedViews/index.js +0 -506
- package/dist/commands/savedViews/model.d.ts +0 -45
- package/dist/commands/savedViews/model.js +0 -90
- package/dist/commands/savedViews/repo.d.ts +0 -125
- package/dist/commands/savedViews/repo.js +0 -393
- package/dist/commands/schema/commandMetadata.d.ts +0 -2
- package/dist/commands/schema/commandMetadata.js +0 -18
- package/dist/commands/schema/globalOptions.d.ts +0 -11
- package/dist/commands/schema/globalOptions.js +0 -11
- package/dist/commands/schema/index.d.ts +0 -5
- package/dist/commands/schema/index.js +0 -130
- package/dist/commands/schema/renderSkills.d.ts +0 -12
- package/dist/commands/schema/renderSkills.js +0 -364
- package/dist/commands/schema/spec.d.ts +0 -5
- package/dist/commands/schema/spec.js +0 -74
- package/dist/commands/schema/types.d.ts +0 -34
- package/dist/commands/schema/types.js +0 -1
- package/dist/commands/skills/index.d.ts +0 -80
- package/dist/commands/skills/index.js +0 -572
- package/dist/commands/storage/index.d.ts +0 -4
- package/dist/commands/storage/index.js +0 -270
- package/dist/commands/storage/repo/configs.d.ts +0 -30
- package/dist/commands/storage/repo/configs.js +0 -259
- package/dist/commands/storage/repo/operations.d.ts +0 -25
- package/dist/commands/storage/repo/operations.js +0 -339
- package/dist/commands/storage/repo/remote.d.ts +0 -32
- package/dist/commands/storage/repo/remote.js +0 -132
- package/dist/commands/storage/repo/resources.d.ts +0 -12
- package/dist/commands/storage/repo/resources.js +0 -134
- package/dist/commands/storage/repo/shared.d.ts +0 -181
- package/dist/commands/storage/repo/shared.js +0 -36
- package/dist/commands/storage/repo/targets.d.ts +0 -12
- package/dist/commands/storage/repo/targets.js +0 -178
- package/dist/commands/storage/repo.d.ts +0 -3
- package/dist/commands/storage/repo.js +0 -4
- package/dist/commands/sync.d.ts +0 -27
- package/dist/commands/sync.js +0 -153
- package/dist/commands/tags/content.d.ts +0 -32
- package/dist/commands/tags/content.js +0 -252
- package/dist/commands/tags/index.d.ts +0 -4
- package/dist/commands/tags/index.js +0 -404
- package/dist/commands/tags/model.d.ts +0 -38
- package/dist/commands/tags/model.js +0 -100
- package/dist/commands/tags/operations.d.ts +0 -105
- package/dist/commands/tags/operations.js +0 -468
- package/dist/commands/tags/repo.d.ts +0 -27
- package/dist/commands/tags/repo.js +0 -236
- package/dist/commands/tags/store.d.ts +0 -28
- package/dist/commands/tags/store.js +0 -166
- package/dist/commands/templates/index.d.ts +0 -4
- package/dist/commands/templates/index.js +0 -290
- package/dist/commands/templates/model.d.ts +0 -28
- package/dist/commands/templates/model.js +0 -195
- package/dist/commands/templates/repo.d.ts +0 -53
- package/dist/commands/templates/repo.js +0 -78
- package/dist/commands/todo/contentModel.d.ts +0 -31
- package/dist/commands/todo/contentModel.js +0 -375
- package/dist/commands/todo/dryRun.d.ts +0 -24
- package/dist/commands/todo/dryRun.js +0 -137
- package/dist/commands/todo/index.d.ts +0 -10
- package/dist/commands/todo/index.js +0 -445
- package/dist/commands/todo/repo.d.ts +0 -136
- package/dist/commands/todo/repo.js +0 -428
- package/dist/commands/todo/taskIdentity.d.ts +0 -2
- package/dist/commands/todo/taskIdentity.js +0 -64
- package/dist/commands/todo/taskModel.d.ts +0 -37
- package/dist/commands/todo/taskModel.js +0 -359
- package/dist/commands/update.d.ts +0 -46
- package/dist/commands/update.js +0 -326
- package/dist/commands/writeConfirmation.d.ts +0 -13
- package/dist/commands/writeConfirmation.js +0 -54
- package/dist/commands/writeDryRun.d.ts +0 -88
- package/dist/commands/writeDryRun.js +0 -162
- package/dist/commands/writeDurability.d.ts +0 -5
- package/dist/commands/writeDurability.js +0 -22
- package/dist/commands/writeReceipt.d.ts +0 -13
- package/dist/commands/writeReceipt.js +0 -12
- package/dist/config/keys.d.ts +0 -9
- package/dist/config/keys.js +0 -14
- package/dist/config/paths.d.ts +0 -6
- package/dist/config/paths.js +0 -55
- package/dist/config/resolve.d.ts +0 -4
- package/dist/config/resolve.js +0 -68
- package/dist/config/serviceEndpoints.d.ts +0 -5
- package/dist/config/serviceEndpoints.js +0 -5
- package/dist/config/store.d.ts +0 -8
- package/dist/config/store.js +0 -149
- package/dist/config/types.d.ts +0 -55
- package/dist/config/types.js +0 -1
- package/dist/constants/links.d.ts +0 -18
- package/dist/constants/links.js +0 -26
- package/dist/contract/snapshot.d.ts +0 -30
- package/dist/contract/snapshot.js +0 -114
- package/dist/daemon/autoInstall.d.ts +0 -32
- package/dist/daemon/autoInstall.js +0 -106
- package/dist/daemon/client.d.ts +0 -29
- package/dist/daemon/client.js +0 -418
- package/dist/daemon/connectivity.d.ts +0 -20
- package/dist/daemon/connectivity.js +0 -42
- package/dist/daemon/ensure.d.ts +0 -1
- package/dist/daemon/ensure.js +0 -120
- package/dist/daemon/env.d.ts +0 -8
- package/dist/daemon/env.js +0 -81
- package/dist/daemon/forward.d.ts +0 -37
- package/dist/daemon/forward.js +0 -155
- package/dist/daemon/fresh.d.ts +0 -4
- package/dist/daemon/fresh.js +0 -10
- package/dist/daemon/index.d.ts +0 -80
- package/dist/daemon/index.js +0 -727
- package/dist/daemon/launch.d.ts +0 -43
- package/dist/daemon/launch.js +0 -124
- package/dist/daemon/lifecycle.d.ts +0 -51
- package/dist/daemon/lifecycle.js +0 -182
- package/dist/daemon/log.d.ts +0 -14
- package/dist/daemon/log.js +0 -57
- package/dist/daemon/pid.d.ts +0 -31
- package/dist/daemon/pid.js +0 -212
- package/dist/daemon/route.d.ts +0 -14
- package/dist/daemon/route.js +0 -43
- package/dist/daemon/server.d.ts +0 -67
- package/dist/daemon/server.js +0 -563
- package/dist/daemon/supervise.d.ts +0 -29
- package/dist/daemon/supervise.js +0 -100
- package/dist/daemon/supervisor.d.ts +0 -91
- package/dist/daemon/supervisor.js +0 -612
- package/dist/daemon/types.d.ts +0 -71
- package/dist/daemon/types.js +0 -2
- package/dist/dinox.d.ts +0 -2
- package/dist/editor/anchor.d.ts +0 -46
- package/dist/editor/anchor.js +0 -129
- package/dist/editor/blockIds.d.ts +0 -21
- package/dist/editor/blockIds.js +0 -51
- package/dist/editor/blocks.d.ts +0 -47
- package/dist/editor/blocks.js +0 -236
- package/dist/editor/compat.d.ts +0 -32
- package/dist/editor/compat.js +0 -392
- package/dist/editor/daemon.d.ts +0 -10
- package/dist/editor/daemon.js +0 -56
- package/dist/editor/document.d.ts +0 -74
- package/dist/editor/document.js +0 -88
- package/dist/editor/i18n.d.ts +0 -23
- package/dist/editor/i18n.js +0 -61
- package/dist/editor/install.d.ts +0 -90
- package/dist/editor/install.js +0 -335
- package/dist/editor/mcp.d.ts +0 -22
- package/dist/editor/mcp.js +0 -222
- package/dist/editor/meta.d.ts +0 -70
- package/dist/editor/meta.js +0 -163
- package/dist/editor/paths.d.ts +0 -2
- package/dist/editor/paths.js +0 -13
- package/dist/editor/persistence.d.ts +0 -4
- package/dist/editor/persistence.js +0 -35
- package/dist/editor/saveGuard.d.ts +0 -9
- package/dist/editor/saveGuard.js +0 -38
- package/dist/editor/schema.d.ts +0 -14
- package/dist/editor/schema.js +0 -38
- package/dist/editor/service.d.ts +0 -326
- package/dist/editor/service.js +0 -1007
- package/dist/gateway/adapters/acp.d.ts +0 -75
- package/dist/gateway/adapters/acp.js +0 -431
- package/dist/gateway/adapters/codexImages.d.ts +0 -4
- package/dist/gateway/adapters/codexImages.js +0 -34
- package/dist/gateway/adapters/echo.d.ts +0 -12
- package/dist/gateway/adapters/echo.js +0 -54
- package/dist/gateway/adapters/index.d.ts +0 -13
- package/dist/gateway/adapters/index.js +0 -42
- package/dist/gateway/agentTaskHost.d.ts +0 -135
- package/dist/gateway/agentTaskHost.js +0 -410
- package/dist/gateway/assistantProjection.d.ts +0 -36
- package/dist/gateway/assistantProjection.js +0 -230
- package/dist/gateway/config.d.ts +0 -56
- package/dist/gateway/config.js +0 -312
- package/dist/gateway/conversationContext.d.ts +0 -44
- package/dist/gateway/conversationContext.js +0 -75
- package/dist/gateway/detect.d.ts +0 -63
- package/dist/gateway/detect.js +0 -281
- package/dist/gateway/deviceHost.d.ts +0 -100
- package/dist/gateway/deviceHost.js +0 -735
- package/dist/gateway/fileUpload.d.ts +0 -12
- package/dist/gateway/fileUpload.js +0 -154
- package/dist/gateway/keepAwake.d.ts +0 -24
- package/dist/gateway/keepAwake.js +0 -64
- package/dist/gateway/mcpCommandTools.d.ts +0 -62
- package/dist/gateway/mcpCommandTools.js +0 -220
- package/dist/gateway/mcpEnv.d.ts +0 -11
- package/dist/gateway/mcpEnv.js +0 -11
- package/dist/gateway/mcpGroups.d.ts +0 -3
- package/dist/gateway/mcpGroups.js +0 -4
- package/dist/gateway/mcpServer.d.ts +0 -25
- package/dist/gateway/mcpServer.js +0 -214
- package/dist/gateway/processTree.d.ts +0 -15
- package/dist/gateway/processTree.js +0 -60
- package/dist/gateway/protocol.d.ts +0 -145
- package/dist/gateway/protocol.js +0 -195
- package/dist/gateway/runExecutor.d.ts +0 -104
- package/dist/gateway/runExecutor.js +0 -480
- package/dist/gateway/service.d.ts +0 -35
- package/dist/gateway/service.js +0 -147
- package/dist/gateway/spawnAgent.d.ts +0 -12
- package/dist/gateway/spawnAgent.js +0 -32
- package/dist/gateway/streamPublisher.d.ts +0 -33
- package/dist/gateway/streamPublisher.js +0 -93
- package/dist/gateway/taskJournal.d.ts +0 -14
- package/dist/gateway/taskJournal.js +0 -47
- package/dist/gateway/threadStore.d.ts +0 -230
- package/dist/gateway/threadStore.js +0 -621
- package/dist/gateway/types.d.ts +0 -168
- package/dist/gateway/types.js +0 -12
- package/dist/gateway/workspace.d.ts +0 -5
- package/dist/gateway/workspace.js +0 -30
- package/dist/gateway/workspaceFolders.d.ts +0 -35
- package/dist/gateway/workspaceFolders.js +0 -142
- package/dist/gateway/workspaceListing.d.ts +0 -5
- package/dist/gateway/workspaceListing.js +0 -78
- package/dist/integrations/dsh/host.d.ts +0 -53
- package/dist/integrations/dsh/host.js +0 -237
- package/dist/integrations/dsh/mcpClient.d.ts +0 -66
- package/dist/integrations/dsh/mcpClient.js +0 -192
- package/dist/powersync/connector.d.ts +0 -22
- package/dist/powersync/connector.js +0 -91
- package/dist/powersync/exclusiveRuntime.d.ts +0 -21
- package/dist/powersync/exclusiveRuntime.js +0 -66
- package/dist/powersync/runtime.d.ts +0 -62
- package/dist/powersync/runtime.js +0 -358
- package/dist/powersync/schema/content.d.ts +0 -1
- package/dist/powersync/schema/content.js +0 -1
- package/dist/powersync/schema/electronCanonical.d.ts +0 -1561
- package/dist/powersync/schema/electronCanonical.js +0 -1154
- package/dist/powersync/schema/index.d.ts +0 -844
- package/dist/powersync/schema/index.js +0 -8
- package/dist/powersync/schema/local.d.ts +0 -13
- package/dist/powersync/schema/local.js +0 -24
- package/dist/powersync/schema/note.d.ts +0 -1
- package/dist/powersync/schema/note.js +0 -1
- package/dist/powersync/schema/notesExtras.d.ts +0 -1
- package/dist/powersync/schema/notesExtras.js +0 -1
- package/dist/powersync/schema/projects.d.ts +0 -1
- package/dist/powersync/schema/projects.js +0 -1
- package/dist/powersync/schema/savedViews.d.ts +0 -1
- package/dist/powersync/schema/savedViews.js +0 -1
- package/dist/powersync/schema/storage.d.ts +0 -1
- package/dist/powersync/schema/storage.js +0 -1
- package/dist/powersync/schema/tags.d.ts +0 -1
- package/dist/powersync/schema/tags.js +0 -1
- package/dist/powersync/syncGate.d.ts +0 -45
- package/dist/powersync/syncGate.js +0 -45
- package/dist/powersync/syncPass.d.ts +0 -9
- package/dist/powersync/syncPass.js +0 -33
- package/dist/powersync/tokenIndex.d.ts +0 -32
- package/dist/powersync/tokenIndex.js +0 -382
- package/dist/powersync/uploader.d.ts +0 -22
- package/dist/powersync/uploader.js +0 -231
- package/dist/requests/execute.d.ts +0 -11
- package/dist/requests/execute.js +0 -26
- package/dist/requests/store.d.ts +0 -10
- package/dist/requests/store.js +0 -190
- package/dist/runCli.d.ts +0 -2
- package/dist/runCli.js +0 -64
- package/dist/skills/check.d.ts +0 -7
- package/dist/skills/check.js +0 -747
- package/dist/skills/commandRefs.d.ts +0 -21
- package/dist/skills/commandRefs.js +0 -124
- package/dist/skills/generate.d.ts +0 -13
- package/dist/skills/generate.js +0 -80
- package/dist/skills/registry.d.ts +0 -13
- package/dist/skills/registry.js +0 -65
- package/dist/skills/retired.d.ts +0 -60
- package/dist/skills/retired.js +0 -58
- package/dist/utils/abort.d.ts +0 -6
- package/dist/utils/abort.js +0 -19
- package/dist/utils/argValue.d.ts +0 -1
- package/dist/utils/argValue.js +0 -18
- package/dist/utils/asyncRelease.d.ts +0 -2
- package/dist/utils/asyncRelease.js +0 -25
- package/dist/utils/authToken.d.ts +0 -4
- package/dist/utils/authToken.js +0 -28
- package/dist/utils/bidlinkCanonicalization.d.ts +0 -2
- package/dist/utils/bidlinkCanonicalization.js +0 -164
- package/dist/utils/consoleEncoding.d.ts +0 -5
- package/dist/utils/consoleEncoding.js +0 -27
- package/dist/utils/cursor.d.ts +0 -9
- package/dist/utils/cursor.js +0 -61
- package/dist/utils/deadline.d.ts +0 -8
- package/dist/utils/deadline.js +0 -31
- package/dist/utils/defaultFormat.d.ts +0 -8
- package/dist/utils/defaultFormat.js +0 -38
- package/dist/utils/dryRun.d.ts +0 -32
- package/dist/utils/dryRun.js +0 -88
- package/dist/utils/errorCodes.d.ts +0 -595
- package/dist/utils/errorCodes.js +0 -163
- package/dist/utils/errors.d.ts +0 -54
- package/dist/utils/errors.js +0 -277
- package/dist/utils/id.d.ts +0 -1
- package/dist/utils/id.js +0 -4
- package/dist/utils/nodeRuntime.d.ts +0 -4
- package/dist/utils/nodeRuntime.js +0 -12
- package/dist/utils/output.d.ts +0 -26
- package/dist/utils/output.js +0 -262
- package/dist/utils/processExit.d.ts +0 -1
- package/dist/utils/processExit.js +0 -33
- package/dist/utils/progress.d.ts +0 -25
- package/dist/utils/progress.js +0 -59
- package/dist/utils/redact.d.ts +0 -1
- package/dist/utils/redact.js +0 -10
- package/dist/utils/requestContext.d.ts +0 -32
- package/dist/utils/requestContext.js +0 -13
- package/dist/utils/select.d.ts +0 -20
- package/dist/utils/select.js +0 -92
- package/dist/utils/sqliteLease.d.ts +0 -8
- package/dist/utils/sqliteLease.js +0 -59
- package/dist/utils/syncTimeout.d.ts +0 -7
- package/dist/utils/syncTimeout.js +0 -20
- package/dist/utils/terminalSanitization.d.ts +0 -2
- package/dist/utils/terminalSanitization.js +0 -37
- package/dist/utils/text.d.ts +0 -1
- package/dist/utils/text.js +0 -35
- package/dist/utils/time.d.ts +0 -1
- package/dist/utils/time.js +0 -3
- package/dist/utils/tiptapMarkdown.d.ts +0 -9
- package/dist/utils/tiptapMarkdown.js +0 -367
- package/dist/utils/tiptapMarkdownSchema.d.ts +0 -37
- package/dist/utils/tiptapMarkdownSchema.js +0 -608
- package/dist/utils/tiptapMarkdownSchemaUtils.d.ts +0 -74
- package/dist/utils/tiptapMarkdownSchemaUtils.js +0 -394
- package/dist/utils/tiptapMarkdownSyntax.d.ts +0 -9
- package/dist/utils/tiptapMarkdownSyntax.js +0 -249
- package/dist/utils/tokenize.d.ts +0 -1
- package/dist/utils/tokenize.js +0 -67
- package/dist/utils/updateNotice.d.ts +0 -8
- package/dist/utils/updateNotice.js +0 -112
- package/dist/utils/usageError.d.ts +0 -37
- package/dist/utils/usageError.js +0 -127
- package/dist/utils/version.d.ts +0 -1
- package/dist/utils/version.js +0 -21
- package/dist/vendor/electron/domain/note-templates.d.ts +0 -3
- package/dist/vendor/electron/domain/note-templates.js +0 -232
- package/dist/vendor/electron/domain/properties.d.ts +0 -10
- package/dist/vendor/electron/domain/properties.js +0 -1549
- package/dist/vendor/electron/domain/saved-view-analytics.d.ts +0 -45
- package/dist/vendor/electron/domain/saved-view-analytics.js +0 -365
- package/dist/vendor/electron/domain/saved-view-relative-date.d.ts +0 -21
- package/dist/vendor/electron/domain/saved-view-relative-date.js +0 -153
- package/dist/vendor/electron/domain/saved-views.d.ts +0 -61
- package/dist/vendor/electron/domain/saved-views.js +0 -1120
- package/dist/vendor/electron/rpc.d.ts +0 -22
- package/dist/vendor/electron/rpc.js +0 -27
- package/dist/vendor/electron/shared/ai-errors.d.ts +0 -11
- package/dist/vendor/electron/shared/ai-errors.js +0 -107
- package/dist/vendor/electron/shared/external-types.d.ts +0 -20
- package/dist/vendor/electron/shared/external-types.js +0 -1
- package/dist/vendor/electron/shared/index.d.ts +0 -9
- package/dist/vendor/electron/shared/index.js +0 -7
- package/dist/vendor/electron/shared/note-properties.d.ts +0 -328
- package/dist/vendor/electron/shared/note-properties.js +0 -1027
- package/dist/vendor/electron/shared/note-templates.d.ts +0 -82
- package/dist/vendor/electron/shared/note-templates.js +0 -84
- package/dist/vendor/electron/shared/powersync-read-models.d.ts +0 -1716
- package/dist/vendor/electron/shared/powersync-read-models.js +0 -1
- package/dist/vendor/electron/shared/remote-device-agent.d.ts +0 -375
- package/dist/vendor/electron/shared/remote-device-agent.js +0 -191
- package/dist/vendor/electron/shared/saved-views.d.ts +0 -394
- package/dist/vendor/electron/shared/saved-views.js +0 -981
- package/dist/vendor/electron/sql-utils.d.ts +0 -5
- package/dist/vendor/electron/sql-utils.js +0 -32
package/dist/editor/service.js
DELETED
|
@@ -1,1007 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { DinoxError } from '../utils/errors.js';
|
|
3
|
-
import { locateAnchor } from './anchor.js';
|
|
4
|
-
import { isMessage, sourceText } from './i18n.js';
|
|
5
|
-
import { shortBlockId } from './blockIds.js';
|
|
6
|
-
import { reconcileBlocks, segmentDocument } from './blocks.js';
|
|
7
|
-
import { parseMetaPatch } from './meta.js';
|
|
8
|
-
const MAX_KEY_LENGTH = 200;
|
|
9
|
-
const MAX_ACTIVITY = 80;
|
|
10
|
-
const MAX_SUGGESTIONS = 50;
|
|
11
|
-
const MAX_WAIT_MS = 25_000;
|
|
12
|
-
/** A note up to this many characters of Markdown is read in full; longer ones as an outline. */
|
|
13
|
-
const FULL_READ_CHARS = 8_000;
|
|
14
|
-
const OUTLINE_CLIP = 80;
|
|
15
|
-
const OUTLINE_WINDOW = 10;
|
|
16
|
-
const MAX_READ_BLOCKS = 80;
|
|
17
|
-
/** A focus read: the blocks the user is on, and this many on each side. */
|
|
18
|
-
const FOCUS_AROUND = 2;
|
|
19
|
-
const MAX_EDITS = 20;
|
|
20
|
-
const MAX_LOG = 600;
|
|
21
|
-
const BLOCK_ID = /^b\d+$/;
|
|
22
|
-
const SESSION_TTL_MS = 7 * 24 * 60 * 60 * 1000;
|
|
23
|
-
const PERSIST_DEBOUNCE_MS = 500;
|
|
24
|
-
const REMOTE_DEBOUNCE_MS = 300;
|
|
25
|
-
const UPLOAD_TIMEOUT_MS = 30_000;
|
|
26
|
-
function usage(message, code = 'INVALID_ARGUMENT') {
|
|
27
|
-
return new DinoxError(message, { code, recoverable: true });
|
|
28
|
-
}
|
|
29
|
-
function str(value, name, { optional = false, max = 200_000 } = {}) {
|
|
30
|
-
if (value === undefined && optional)
|
|
31
|
-
return undefined;
|
|
32
|
-
if (typeof value !== 'string')
|
|
33
|
-
throw usage(`${name} must be a string`);
|
|
34
|
-
if (value.length > max)
|
|
35
|
-
throw usage(`${name} is too long`);
|
|
36
|
-
return value;
|
|
37
|
-
}
|
|
38
|
-
function isDoc(value) {
|
|
39
|
-
return Boolean(value) && typeof value === 'object' && value.type === 'doc' && Array.isArray(value.content);
|
|
40
|
-
}
|
|
41
|
-
function clip(value, max) {
|
|
42
|
-
const flat = value.replace(/\s*\n\s*/g, ' ⏎ ');
|
|
43
|
-
return flat.length > max ? `${flat.slice(0, max - 1)}…` : flat;
|
|
44
|
-
}
|
|
45
|
-
const LINE_PREFIX = /^\s{0,8}(?:>\s?)*\s{0,8}(?:#{1,6}\s+|[-*+]\s+(?:\[[ xX]\]\s+)?|\d+[.)]\s+(?:\[[ xX]\]\s+)?)?/;
|
|
46
|
-
/** A whole-block replacement keeps the block's type, so a repeated `## ` or `- [ ] ` is dropped. */
|
|
47
|
-
export function withoutLinePrefix(blockMd, replace) {
|
|
48
|
-
if (blockMd.startsWith('```')) {
|
|
49
|
-
const fenced = /^```[^\n]*\n([\s\S]*?)\n?```\s*$/.exec(replace);
|
|
50
|
-
return fenced ? fenced[1] : replace;
|
|
51
|
-
}
|
|
52
|
-
const own = LINE_PREFIX.exec(blockMd)?.[0] ?? '';
|
|
53
|
-
if (!own)
|
|
54
|
-
return replace;
|
|
55
|
-
const theirs = LINE_PREFIX.exec(replace)?.[0] ?? '';
|
|
56
|
-
return theirs ? replace.slice(theirs.length) : replace;
|
|
57
|
-
}
|
|
58
|
-
export class EditorService {
|
|
59
|
-
options;
|
|
60
|
-
sessions = new Map();
|
|
61
|
-
waiters = new Map();
|
|
62
|
-
openWaiters = new Set();
|
|
63
|
-
opensRev = 0;
|
|
64
|
-
remoteSeq = 0;
|
|
65
|
-
persistTimer = null;
|
|
66
|
-
remoteTimer = null;
|
|
67
|
-
unwatch = null;
|
|
68
|
-
closed = false;
|
|
69
|
-
now;
|
|
70
|
-
constructor(options) {
|
|
71
|
-
this.options = options;
|
|
72
|
-
this.now = options.now ?? Date.now;
|
|
73
|
-
}
|
|
74
|
-
async restore() {
|
|
75
|
-
const saved = await this.options.persistence?.load().catch(() => []) ?? [];
|
|
76
|
-
const cutoff = this.now() - SESSION_TTL_MS;
|
|
77
|
-
for (const entry of saved) {
|
|
78
|
-
if (!entry?.key || entry.updatedAt < cutoff)
|
|
79
|
-
continue;
|
|
80
|
-
this.sessions.set(entry.key, {
|
|
81
|
-
...this.blank(entry.key),
|
|
82
|
-
...entry,
|
|
83
|
-
suggestions: (entry.suggestions ?? []).filter(s => s.status === 'pending'),
|
|
84
|
-
activity: (entry.activity ?? []).slice(-MAX_ACTIVITY),
|
|
85
|
-
ackSeq: entry.openSeq,
|
|
86
|
-
version: entry.version ?? 0,
|
|
87
|
-
floor: entry.version ?? 0,
|
|
88
|
-
blockSeq: entry.blockSeq ?? 0,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
this.updateWatch();
|
|
92
|
-
}
|
|
93
|
-
// ---- model-facing --------------------------------------------------------
|
|
94
|
-
async open(key, input) {
|
|
95
|
-
const session = this.session(key);
|
|
96
|
-
if (session.dirty || session.saving) {
|
|
97
|
-
throw new DinoxError('The open note has unsaved changes; wait for them to save before opening another note.', {
|
|
98
|
-
code: 'EDITOR_UNSAVED_CHANGES',
|
|
99
|
-
recoverable: true,
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
const noteId = str(input.noteId, 'noteId', { optional: true, max: 200 })?.trim();
|
|
103
|
-
const query = str(input.query, 'query', { optional: true, max: 500 });
|
|
104
|
-
let otherHits = [];
|
|
105
|
-
let id = noteId;
|
|
106
|
-
if (!id) {
|
|
107
|
-
const hits = await this.options.store.search(query ?? '', 6);
|
|
108
|
-
if (!hits.length)
|
|
109
|
-
throw new DinoxError(`No note matches "${query ?? ''}"`, { code: 'NOTE_NOT_FOUND', recoverable: true });
|
|
110
|
-
id = hits[0].id;
|
|
111
|
-
otherHits = hits.slice(1);
|
|
112
|
-
}
|
|
113
|
-
const note = await this.options.store.load(id);
|
|
114
|
-
const meta = await this.loadMeta(id);
|
|
115
|
-
Object.assign(session, {
|
|
116
|
-
noteId: note.noteId,
|
|
117
|
-
title: note.title,
|
|
118
|
-
knownHash: note.hash,
|
|
119
|
-
knownVersion: note.version,
|
|
120
|
-
selection: { text: '', start: 0, end: 0 },
|
|
121
|
-
dirty: false,
|
|
122
|
-
suggestions: [],
|
|
123
|
-
upload: null,
|
|
124
|
-
remote: null,
|
|
125
|
-
openSeq: session.openSeq + 1,
|
|
126
|
-
});
|
|
127
|
-
this.setMeta(session, meta);
|
|
128
|
-
this.adopt(session, note.document, null);
|
|
129
|
-
this.record(session, 'ai', 'open', { key: '開啟了「{title}」', params: { title: note.title || '未命名筆記' } });
|
|
130
|
-
this.changed(session);
|
|
131
|
-
this.opensRev++;
|
|
132
|
-
this.wake(this.openWaiters);
|
|
133
|
-
this.updateWatch();
|
|
134
|
-
return { ...this.payload(session, note), otherHits };
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* What the model reads. Without arguments: the whole note as blocks (an
|
|
138
|
-
* outline around the user's cursor when it is long). With `since`: only
|
|
139
|
-
* what changed after that version, including the user's verdicts on
|
|
140
|
-
* suggestions. With `blocks`: exactly those blocks. With `focus`: the
|
|
141
|
-
* blocks under the user's cursor or selection and their neighbours, so an
|
|
142
|
-
* edit at the cursor costs a few blocks, not the whole note.
|
|
143
|
-
*/
|
|
144
|
-
async read(key, input = {}) {
|
|
145
|
-
const session = this.requireOpen(key);
|
|
146
|
-
await this.hydrate(session);
|
|
147
|
-
this.ensureBlocks(session, 'user');
|
|
148
|
-
const blocks = session.blocks;
|
|
149
|
-
const selection = this.selectionBlocks(session);
|
|
150
|
-
const base = {
|
|
151
|
-
noteId: session.noteId,
|
|
152
|
-
title: session.title,
|
|
153
|
-
version: session.version,
|
|
154
|
-
dirty: session.dirty,
|
|
155
|
-
blockCount: blocks.length,
|
|
156
|
-
selection,
|
|
157
|
-
pending: session.suggestions.filter(s => s.status === 'pending').map(s => ({
|
|
158
|
-
id: s.id,
|
|
159
|
-
kind: s.kind,
|
|
160
|
-
block: s.block ?? this.blockAt(session, s.at)?.id ?? null,
|
|
161
|
-
summary: clip(s.kind === 'replace' ? `${s.find ?? ''} → ${s.replace ?? ''}` : s.kind === 'comment' ? `「${s.find ?? ''}」${s.comment ?? ''}` : s.markdown ?? '', 60),
|
|
162
|
-
})),
|
|
163
|
-
};
|
|
164
|
-
let notice;
|
|
165
|
-
const wanted = Array.isArray(input.blocks) ? input.blocks.filter((id) => typeof id === 'string').slice(0, MAX_READ_BLOCKS) : [];
|
|
166
|
-
if (wanted.length) {
|
|
167
|
-
const found = wanted.map(id => findBlock(blocks, id)).filter((block) => Boolean(block));
|
|
168
|
-
const missing = wanted.filter(id => !findBlock(blocks, id));
|
|
169
|
-
if (missing.length)
|
|
170
|
-
notice = `No longer in the note: ${missing.join(', ')}.`;
|
|
171
|
-
this.recordRead(session, found);
|
|
172
|
-
return { ...base, mode: 'blocks', blocks: found.map(({ id, md }) => ({ id, md })), ...(notice ? { notice } : {}) };
|
|
173
|
-
}
|
|
174
|
-
if (input.focus === true && blocks.length) {
|
|
175
|
-
const hit = (selection?.blocks ?? []).map(id => blocks.findIndex(block => block.id === id)).filter(index => index >= 0);
|
|
176
|
-
const from = Math.max(0, (hit.length ? Math.min(...hit) : 0) - FOCUS_AROUND);
|
|
177
|
-
const to = Math.min(blocks.length, (hit.length ? Math.max(...hit) : 0) + FOCUS_AROUND + 1);
|
|
178
|
-
const found = blocks.slice(from, Math.min(to, from + MAX_READ_BLOCKS));
|
|
179
|
-
this.recordRead(session, found);
|
|
180
|
-
return {
|
|
181
|
-
...base, mode: 'blocks', blocks: found.map(({ id, md }) => ({ id, md })),
|
|
182
|
-
...(hit.length ? {} : { notice: 'The user has no cursor in the note; these are its first blocks.' }),
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
if (input.since !== undefined && input.since !== null) {
|
|
186
|
-
const since = Number(input.since);
|
|
187
|
-
if (Number.isInteger(since) && since >= session.floor && since <= session.version) {
|
|
188
|
-
const { changes, resolved } = this.changesSince(session, since);
|
|
189
|
-
const touched = changes.filter(change => change.op !== 'removed').length;
|
|
190
|
-
const chars = changes.reduce((sum, change) => sum + (change.md?.length ?? 0), 0);
|
|
191
|
-
if (touched <= Math.max(12, blocks.length * 0.6) && chars <= FULL_READ_CHARS) {
|
|
192
|
-
this.recordRead(session, changes.flatMap(change => blocks.filter(block => block.id === change.id)), { key: '正在看你剛才的修改' });
|
|
193
|
-
return { ...base, mode: 'changes', changes, resolved };
|
|
194
|
-
}
|
|
195
|
-
notice = `Most of the note changed since version ${since}; here it is again.`;
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
notice = `Version ${input.since} is not available (the note was reopened or the history is too old); here is the current note.`;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
const total = blocks.reduce((sum, block) => sum + block.md.length + 1, 0);
|
|
202
|
-
this.recordRead(session, null);
|
|
203
|
-
if (total <= FULL_READ_CHARS) {
|
|
204
|
-
return { ...base, mode: 'full', blocks: blocks.map(({ id, md }) => ({ id, md })), ...(notice ? { notice } : {}) };
|
|
205
|
-
}
|
|
206
|
-
const focus = Math.max(0, blocks.findIndex(block => block.id === selection?.blocks[0]));
|
|
207
|
-
const outline = blocks.map(({ id, md }, index) => (Math.abs(index - focus) <= OUTLINE_WINDOW || md.length <= OUTLINE_CLIP
|
|
208
|
-
? { id, md }
|
|
209
|
-
: { id, md: clip(md, OUTLINE_CLIP), clipped: true }));
|
|
210
|
-
notice = [notice, 'The note is long: blocks away from the cursor are clipped; read them with blocks: [...].'].filter(Boolean).join(' ');
|
|
211
|
-
return { ...base, mode: 'outline', blocks: outline, notice };
|
|
212
|
-
}
|
|
213
|
-
/** Legacy name of `read` without arguments. */
|
|
214
|
-
state(key) {
|
|
215
|
-
return this.read(key);
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* One or more suggestions, all or none: every edit is validated against the
|
|
219
|
-
* note first, and any failure rejects the whole batch with a reason per edit.
|
|
220
|
-
*/
|
|
221
|
-
async suggest(key, input) {
|
|
222
|
-
const session = this.requireOpen(key);
|
|
223
|
-
await this.hydrate(session);
|
|
224
|
-
this.ensureBlocks(session, 'user');
|
|
225
|
-
const edits = Array.isArray(input.edits) ? input.edits : [input];
|
|
226
|
-
if (!edits.length)
|
|
227
|
-
throw usage('edits must not be empty');
|
|
228
|
-
if (edits.length > MAX_EDITS)
|
|
229
|
-
throw usage(`At most ${MAX_EDITS} edits per call`);
|
|
230
|
-
const pendingCount = session.suggestions.filter(s => s.status === 'pending').length;
|
|
231
|
-
if (pendingCount + edits.length > MAX_SUGGESTIONS)
|
|
232
|
-
throw usage('Too many pending suggestions; wait for the user to review them');
|
|
233
|
-
const prepared = [];
|
|
234
|
-
const errors = [];
|
|
235
|
-
let code;
|
|
236
|
-
edits.forEach((edit, index) => {
|
|
237
|
-
try {
|
|
238
|
-
prepared.push(this.prepare(session, edit));
|
|
239
|
-
}
|
|
240
|
-
catch (error) {
|
|
241
|
-
errors.push(`Edit ${index + 1}: ${error instanceof Error ? error.message : String(error)}`);
|
|
242
|
-
if (!code && error instanceof DinoxError)
|
|
243
|
-
code = error.code;
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
if (errors.length) {
|
|
247
|
-
throw new DinoxError(`${edits.length > 1 ? 'No suggestion was made. ' : ''}${errors.join(' ')}`, {
|
|
248
|
-
code: code ?? 'INVALID_ARGUMENT',
|
|
249
|
-
recoverable: true,
|
|
250
|
-
details: { errors },
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
session.suggestions.push(...prepared);
|
|
254
|
-
const count = (kind) => prepared.filter(s => s.kind === kind).length;
|
|
255
|
-
const parts = [['replace', '{n} 處修改'], ['insert', '{n} 段新增'], ['comment', '{n} 則註解']]
|
|
256
|
-
.map(([kind, key]) => ({ key, params: { n: count(kind) } }))
|
|
257
|
-
.filter(part => part.params.n);
|
|
258
|
-
this.record(session, 'ai', 'suggest', { key: '提出了{list}', params: { list: parts } });
|
|
259
|
-
this.changed(session);
|
|
260
|
-
return { version: session.version, suggestions: prepared.map(s => ({ id: s.id, kind: s.kind, block: s.block ?? null })) };
|
|
261
|
-
}
|
|
262
|
-
prepare(session, raw) {
|
|
263
|
-
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
264
|
-
throw usage('each edit must be an object');
|
|
265
|
-
const edit = raw;
|
|
266
|
-
const reason = str(edit.reason, 'reason', { optional: true, max: 2000 }) ?? '';
|
|
267
|
-
const base = { id: `s${randomUUID().slice(0, 8)}`, reason, status: 'pending', createdAt: new Date(this.now()).toISOString() };
|
|
268
|
-
// A note id is accepted for a block id; suggestions always record the id the model reads.
|
|
269
|
-
const blockId = typeof edit.block === 'string' ? blockRef(session.blocks, edit.block.trim()) : undefined;
|
|
270
|
-
if (edit.comment !== undefined || edit.kind === 'comment') {
|
|
271
|
-
const comment = str(edit.comment, 'comment', { max: 4000 }).trim();
|
|
272
|
-
if (!comment)
|
|
273
|
-
throw usage('comment must not be empty');
|
|
274
|
-
const find = edit.find === undefined || edit.find === '' ? undefined : str(edit.find, 'find', { max: 20_000 });
|
|
275
|
-
if (blockId) {
|
|
276
|
-
const block = session.blocks[this.blockIndex(session, blockId)];
|
|
277
|
-
if (find === undefined) {
|
|
278
|
-
if (!block.text)
|
|
279
|
-
throw usage(`${blockId} is empty; there is nothing to comment on`);
|
|
280
|
-
return { ...base, kind: 'comment', block: blockId, find: block.text, comment, anchor: block.text, at: block.start };
|
|
281
|
-
}
|
|
282
|
-
const located = this.locate(block.text, find, 'find', blockId);
|
|
283
|
-
return { ...base, kind: 'comment', block: blockId, find, comment, anchor: located.anchor, at: block.start + located.start };
|
|
284
|
-
}
|
|
285
|
-
if (find === undefined)
|
|
286
|
-
throw usage('a comment needs block (and optionally find), or find');
|
|
287
|
-
const located = this.locate(session.plainText, find, 'find');
|
|
288
|
-
return { ...base, kind: 'comment', find, comment, anchor: located.anchor, at: located.start, block: this.blockAt(session, located.start)?.id };
|
|
289
|
-
}
|
|
290
|
-
if (edit.markdown !== undefined || edit.kind === 'insert') {
|
|
291
|
-
const markdown = str(edit.markdown, 'markdown', { max: 50_000 });
|
|
292
|
-
if (!markdown.trim())
|
|
293
|
-
throw usage('markdown must not be empty');
|
|
294
|
-
const after = blockRef(session.blocks, (str(edit.after ?? blockId, 'after', { max: 20_000 }) ?? '').trim());
|
|
295
|
-
if (!after)
|
|
296
|
-
throw usage('an insert needs after: a block id, "start" or "end"');
|
|
297
|
-
if (after === 'end' || after === '<end>')
|
|
298
|
-
return { ...base, kind: 'insert', after: '<end>', markdown, anchor: '<end>' };
|
|
299
|
-
if (after === 'start' || after === '<start>')
|
|
300
|
-
return { ...base, kind: 'insert', after: '<start>', markdown, anchor: '<start>' };
|
|
301
|
-
if (BLOCK_ID.test(after) || findBlock(session.blocks, after)) {
|
|
302
|
-
const index = this.blockIndex(session, after);
|
|
303
|
-
// An empty block has no text to anchor on: follow the nearest earlier block with text.
|
|
304
|
-
const holder = session.blocks.slice(0, index + 1).reverse().find(block => block.text);
|
|
305
|
-
if (!holder)
|
|
306
|
-
return { ...base, kind: 'insert', block: after, after: '<start>', markdown, anchor: '<start>' };
|
|
307
|
-
return { ...base, kind: 'insert', block: after, after, markdown, anchor: holder.text, at: holder.start };
|
|
308
|
-
}
|
|
309
|
-
const located = this.locate(session.plainText, after, 'after');
|
|
310
|
-
return { ...base, kind: 'insert', after, markdown, anchor: located.anchor, at: located.start, block: this.blockAt(session, located.start)?.id };
|
|
311
|
-
}
|
|
312
|
-
if (edit.replace === undefined)
|
|
313
|
-
throw usage('each edit needs {block, replace}, {block, find, replace}, {after, markdown} or {block, find?, comment}');
|
|
314
|
-
const replace = str(edit.replace, 'replace', { max: 50_000 });
|
|
315
|
-
const find = edit.find === undefined || edit.find === '' ? undefined : str(edit.find, 'find', { max: 20_000 });
|
|
316
|
-
if (blockId) {
|
|
317
|
-
const block = session.blocks[this.blockIndex(session, blockId)];
|
|
318
|
-
if (find !== undefined) {
|
|
319
|
-
const located = this.locate(block.text, find, 'find', blockId);
|
|
320
|
-
return { ...base, kind: 'replace', block: blockId, find, replace, anchor: located.anchor, at: block.start + located.start };
|
|
321
|
-
}
|
|
322
|
-
if (!block.text)
|
|
323
|
-
throw usage(`${blockId} is empty; add content with {after: "${blockId}", markdown} instead`);
|
|
324
|
-
return { ...base, kind: 'replace', block: blockId, find: block.text, replace: withoutLinePrefix(block.md, replace), anchor: block.text, at: block.start };
|
|
325
|
-
}
|
|
326
|
-
if (find === undefined)
|
|
327
|
-
throw usage('a replace needs block (and optionally find), or find');
|
|
328
|
-
const located = this.locate(session.plainText, find, 'find');
|
|
329
|
-
return { ...base, kind: 'replace', find, replace, anchor: located.anchor, at: located.start, block: this.blockAt(session, located.start)?.id };
|
|
330
|
-
}
|
|
331
|
-
locate(text, find, name, blockId) {
|
|
332
|
-
const located = locateAnchor(text, find);
|
|
333
|
-
const where = blockId ? ` in ${blockId}` : ' in the note';
|
|
334
|
-
if (located.status === 'missing') {
|
|
335
|
-
throw new DinoxError(`${name} "${clip(find, 60)}" does not occur${where}; read the note again and quote it exactly.`, {
|
|
336
|
-
code: 'EDITOR_ANCHOR_MISSING',
|
|
337
|
-
recoverable: true,
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
if (located.status === 'ambiguous') {
|
|
341
|
-
throw new DinoxError(`${name} "${clip(find, 60)}" occurs ${located.count} times${where}; ${blockId ? 'quote more of the block' : 'name the block, or quote more text'} so it is unique.`, {
|
|
342
|
-
code: 'EDITOR_ANCHOR_AMBIGUOUS',
|
|
343
|
-
recoverable: true,
|
|
344
|
-
details: { count: located.count },
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
return located;
|
|
348
|
-
}
|
|
349
|
-
blockIndex(session, id) {
|
|
350
|
-
const index = session.blocks.findIndex(block => block.id === id || block.nodeId === id);
|
|
351
|
-
if (index === -1) {
|
|
352
|
-
throw new DinoxError(`Block ${id} is not in the note (it was deleted, or the note changed); read the note again.`, {
|
|
353
|
-
code: 'EDITOR_UNKNOWN_BLOCK',
|
|
354
|
-
recoverable: true,
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
return index;
|
|
358
|
-
}
|
|
359
|
-
async search(input) {
|
|
360
|
-
const query = str(input.query ?? '', 'query', { max: 500 });
|
|
361
|
-
const limit = Math.max(1, Math.min(20, Number(input.limit) || 10));
|
|
362
|
-
return this.options.store.search(query, limit);
|
|
363
|
-
}
|
|
364
|
-
// ---- UI-facing -----------------------------------------------------------
|
|
365
|
-
/**
|
|
366
|
-
* Mirrors the UI and long-polls for changes. A call that carries no updates
|
|
367
|
-
* and names the current `rev` waits up to `waitMs` for anything to change.
|
|
368
|
-
*/
|
|
369
|
-
async sync(key, input, signal) {
|
|
370
|
-
const session = this.session(key);
|
|
371
|
-
const openSeq = Number(input.openSeq ?? 0);
|
|
372
|
-
let updated = false;
|
|
373
|
-
if (session.noteId && openSeq === session.openSeq) {
|
|
374
|
-
if (session.ackSeq < openSeq) {
|
|
375
|
-
session.ackSeq = openSeq;
|
|
376
|
-
this.opensRev++;
|
|
377
|
-
this.wake(this.openWaiters);
|
|
378
|
-
}
|
|
379
|
-
if (input.mirror !== undefined)
|
|
380
|
-
updated = this.applyMirror(session, input.mirror) || updated;
|
|
381
|
-
if (input.doc !== undefined) {
|
|
382
|
-
// A host without incremental mirroring sends the whole document.
|
|
383
|
-
if (!isDoc(input.doc))
|
|
384
|
-
throw usage('doc must be a Tiptap document');
|
|
385
|
-
session.doc = input.doc;
|
|
386
|
-
session.mirrorRev = null;
|
|
387
|
-
updated = true;
|
|
388
|
-
}
|
|
389
|
-
if (input.dirty !== undefined) {
|
|
390
|
-
session.dirty = Boolean(input.dirty);
|
|
391
|
-
updated = true;
|
|
392
|
-
}
|
|
393
|
-
if (input.selection !== undefined) {
|
|
394
|
-
const selection = input.selection;
|
|
395
|
-
const text = str(selection?.text, 'selection.text', { max: 100_000 }).slice(0, 4000);
|
|
396
|
-
session.selection = { text, start: Number(selection?.start) || 0, end: Number(selection?.end) || 0 };
|
|
397
|
-
updated = true;
|
|
398
|
-
}
|
|
399
|
-
if (updated) {
|
|
400
|
-
session.updatedAt = this.now();
|
|
401
|
-
// Mirror updates are the UI's own news: no rev bump, so its next poll can wait.
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
const rev = Number(input.rev);
|
|
405
|
-
const waitMs = Math.max(0, Math.min(MAX_WAIT_MS, Number(input.waitMs) || 0));
|
|
406
|
-
if (!updated && waitMs > 0 && rev === session.rev && openSeq >= session.openSeq) {
|
|
407
|
-
await this.waitFor(this.waitersOf(key), waitMs, signal);
|
|
408
|
-
}
|
|
409
|
-
return this.view(session, openSeq);
|
|
410
|
-
}
|
|
411
|
-
async save(key, input) {
|
|
412
|
-
const session = this.requireOpen(key);
|
|
413
|
-
if (Number(input.openSeq) !== session.openSeq) {
|
|
414
|
-
throw new DinoxError('The session has opened another note; this save was discarded.', { code: 'EDITOR_STALE_SEQUENCE', recoverable: true });
|
|
415
|
-
}
|
|
416
|
-
if (!isDoc(input.doc))
|
|
417
|
-
throw usage('doc must be a Tiptap document');
|
|
418
|
-
const doc = input.doc;
|
|
419
|
-
const force = input.force === true;
|
|
420
|
-
let baseHash = str(input.baseHash, 'baseHash', { max: 200 });
|
|
421
|
-
let baseVersion = input.baseVersion === null ? null : Number(input.baseVersion);
|
|
422
|
-
if (baseVersion !== null && !Number.isFinite(baseVersion))
|
|
423
|
-
throw usage('baseVersion must be a number or null');
|
|
424
|
-
const run = async () => {
|
|
425
|
-
if (force) {
|
|
426
|
-
const current = await this.options.store.load(session.noteId);
|
|
427
|
-
baseHash = current.hash;
|
|
428
|
-
baseVersion = current.version;
|
|
429
|
-
}
|
|
430
|
-
let result = await this.options.store.save({ noteId: session.noteId, baseHash, baseVersion, document: doc });
|
|
431
|
-
// Same content, newer version: only the title, tags or properties moved on; that is no conflict for the body.
|
|
432
|
-
if (result.status === 'conflict' && result.current.hash === baseHash && result.current.version !== baseVersion) {
|
|
433
|
-
result = await this.options.store.save({ noteId: session.noteId, baseHash, baseVersion: result.current.version, document: doc });
|
|
434
|
-
}
|
|
435
|
-
if (result.status === 'conflict') {
|
|
436
|
-
this.record(session, 'system', 'remote', { key: '這則筆記在別處被修改了' });
|
|
437
|
-
this.changed(session);
|
|
438
|
-
return result;
|
|
439
|
-
}
|
|
440
|
-
session.knownHash = result.hash;
|
|
441
|
-
session.knownVersion = result.version;
|
|
442
|
-
// The live mirror is at least as new as this save; only a host that never mirrors sets the document here.
|
|
443
|
-
if (session.mirrorRev === null)
|
|
444
|
-
session.doc = doc;
|
|
445
|
-
if (result.status === 'saved') {
|
|
446
|
-
session.upload = { hash: result.hash, state: 'pending' };
|
|
447
|
-
this.trackUpload(session, result.hash);
|
|
448
|
-
// Hashtags typed into the body become tags, and the edit time moved.
|
|
449
|
-
this.setMeta(session, await this.loadMeta(session.noteId));
|
|
450
|
-
}
|
|
451
|
-
this.changed(session);
|
|
452
|
-
return result;
|
|
453
|
-
};
|
|
454
|
-
// One write per session at a time; the UI never has two saves in flight, this only guards misuse.
|
|
455
|
-
const previous = session.saving ?? Promise.resolve();
|
|
456
|
-
const current = previous.catch(() => undefined).then(run);
|
|
457
|
-
session.saving = current;
|
|
458
|
-
try {
|
|
459
|
-
return await current;
|
|
460
|
-
}
|
|
461
|
-
catch (error) {
|
|
462
|
-
this.record(session, 'system', 'error', { key: '儲存失敗:{error}', params: { error: error instanceof Error ? error.message : String(error) } });
|
|
463
|
-
this.changed(session);
|
|
464
|
-
throw error;
|
|
465
|
-
}
|
|
466
|
-
finally {
|
|
467
|
-
if (session.saving === current)
|
|
468
|
-
session.saving = null;
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
resolve(key, input) {
|
|
472
|
-
const session = this.requireOpen(key);
|
|
473
|
-
const id = str(input.id, 'id', { max: 100 });
|
|
474
|
-
if (typeof input.accepted !== 'boolean')
|
|
475
|
-
throw usage('accepted must be a boolean');
|
|
476
|
-
const suggestion = session.suggestions.find(s => s.id === id);
|
|
477
|
-
if (!suggestion)
|
|
478
|
-
throw new DinoxError('Unknown suggestion', { code: 'NOT_FOUND', recoverable: true });
|
|
479
|
-
if (suggestion.status === 'pending') {
|
|
480
|
-
suggestion.status = input.accepted ? 'accepted' : 'rejected';
|
|
481
|
-
this.ensureBlocks(session, 'user');
|
|
482
|
-
session.version++;
|
|
483
|
-
this.log(session, { v: session.version, op: suggestion.status, id: suggestion.block ?? this.blockAt(session, suggestion.at)?.id ?? null, by: 'user', suggestion: suggestion.id });
|
|
484
|
-
const what = suggestion.kind === 'comment' ? ['採納了 AI 的註解', '略過了 AI 的註解'] : ['接受了 AI 的建議', '略過了 AI 的建議'];
|
|
485
|
-
this.record(session, 'user', input.accepted ? 'accept' : 'reject', { key: what[input.accepted ? 0 : 1] });
|
|
486
|
-
// Keep the list short: settled suggestions only matter to the UI that just settled them.
|
|
487
|
-
session.suggestions = session.suggestions.filter(s => s.status === 'pending' || s === suggestion);
|
|
488
|
-
this.changed(session);
|
|
489
|
-
}
|
|
490
|
-
return { ok: true };
|
|
491
|
-
}
|
|
492
|
-
/** Tags, card boxes and property definitions the header can pick from. */
|
|
493
|
-
async catalog() {
|
|
494
|
-
if (!this.options.store.catalog)
|
|
495
|
-
return { tags: [], boxes: [], properties: [] };
|
|
496
|
-
return this.options.store.catalog();
|
|
497
|
-
}
|
|
498
|
-
/** Writes the title, tags, boxes, starred or property values of the open note. */
|
|
499
|
-
async updateMeta(key, input) {
|
|
500
|
-
const session = this.requireOpen(key);
|
|
501
|
-
if (Number(input.openSeq) !== session.openSeq) {
|
|
502
|
-
throw new DinoxError('The session has opened another note; this change was discarded.', { code: 'EDITOR_STALE_SEQUENCE', recoverable: true });
|
|
503
|
-
}
|
|
504
|
-
if (!this.options.store.updateMeta)
|
|
505
|
-
throw new DinoxError('This editor cannot change note details.', { code: 'COMMAND_FAILED', recoverable: false });
|
|
506
|
-
const patch = parseMetaPatch(input.patch);
|
|
507
|
-
const before = session.meta;
|
|
508
|
-
const { changed, meta } = await this.options.store.updateMeta(session.noteId, patch);
|
|
509
|
-
if (changed.length) {
|
|
510
|
-
session.title = meta.title;
|
|
511
|
-
// The body is untouched, so its content hash stays; only the row version moved.
|
|
512
|
-
session.knownVersion = meta.version;
|
|
513
|
-
this.setMeta(session, meta);
|
|
514
|
-
const message = describeMetaChange(changed, before, meta);
|
|
515
|
-
if ((message.params?.clauses).length)
|
|
516
|
-
this.record(session, 'user', 'save', message);
|
|
517
|
-
void this.options.store.waitForUpload(UPLOAD_TIMEOUT_MS).catch(() => false);
|
|
518
|
-
this.changed(session);
|
|
519
|
-
}
|
|
520
|
-
return { changed, meta, metaSeq: session.metaSeq };
|
|
521
|
-
}
|
|
522
|
-
note(key, input) {
|
|
523
|
-
const session = this.session(key);
|
|
524
|
-
const text = str(input.text, 'text', { max: 2000 });
|
|
525
|
-
// A UI may word the entry as a message so other panels show it in their language.
|
|
526
|
-
const message = isMessage(input.message) ? input.message : null;
|
|
527
|
-
this.record(session, input.actor === 'user' ? 'user' : 'system', input.error ? 'error' : 'read', message && sourceText(message).length <= 2000 ? message : text);
|
|
528
|
-
this.changed(session);
|
|
529
|
-
return { ok: true };
|
|
530
|
-
}
|
|
531
|
-
/** Sessions whose latest open has not reached a UI; hosts use this to reveal the editor. */
|
|
532
|
-
async watchOpens(input, signal) {
|
|
533
|
-
const cursor = Number(input.cursor);
|
|
534
|
-
const waitMs = Math.max(0, Math.min(MAX_WAIT_MS, Number(input.waitMs) || 0));
|
|
535
|
-
if (waitMs > 0 && cursor === this.opensRev)
|
|
536
|
-
await this.waitFor(this.openWaiters, waitMs, signal);
|
|
537
|
-
const opens = [...this.sessions.values()]
|
|
538
|
-
.filter(s => s.noteId && s.ackSeq < s.openSeq)
|
|
539
|
-
.map(s => ({ session: s.key, openSeq: s.openSeq, noteId: s.noteId, title: s.title }));
|
|
540
|
-
return { cursor: this.opensRev, opens };
|
|
541
|
-
}
|
|
542
|
-
async close() {
|
|
543
|
-
this.closed = true;
|
|
544
|
-
this.unwatch?.();
|
|
545
|
-
this.unwatch = null;
|
|
546
|
-
if (this.remoteTimer)
|
|
547
|
-
clearTimeout(this.remoteTimer);
|
|
548
|
-
for (const set of this.waiters.values())
|
|
549
|
-
this.wake(set);
|
|
550
|
-
this.wake(this.openWaiters);
|
|
551
|
-
if (this.persistTimer) {
|
|
552
|
-
clearTimeout(this.persistTimer);
|
|
553
|
-
this.persistTimer = null;
|
|
554
|
-
}
|
|
555
|
-
await this.persistNow();
|
|
556
|
-
}
|
|
557
|
-
// ---- remote changes ------------------------------------------------------
|
|
558
|
-
/** Re-reads open notes and announces content changed outside this service. */
|
|
559
|
-
async checkRemote() {
|
|
560
|
-
const open = [...this.sessions.values()].filter(s => s.noteId && s.knownHash);
|
|
561
|
-
if (!open.length)
|
|
562
|
-
return;
|
|
563
|
-
const hashes = await this.options.store.hashes([...new Set(open.map(s => s.noteId))]);
|
|
564
|
-
for (const session of open) {
|
|
565
|
-
const current = hashes.get(session.noteId);
|
|
566
|
-
if (!current)
|
|
567
|
-
continue;
|
|
568
|
-
// A save of ours may still be committing; its result decides.
|
|
569
|
-
if (session.saving)
|
|
570
|
-
continue;
|
|
571
|
-
if (current.hash === session.knownHash) {
|
|
572
|
-
// Only the title, tags, boxes or properties changed (here or in another app).
|
|
573
|
-
if (current.version !== session.knownVersion) {
|
|
574
|
-
session.knownVersion = current.version;
|
|
575
|
-
const meta = await this.loadMeta(session.noteId);
|
|
576
|
-
if (meta)
|
|
577
|
-
session.title = meta.title;
|
|
578
|
-
this.setMeta(session, meta);
|
|
579
|
-
this.changed(session);
|
|
580
|
-
}
|
|
581
|
-
continue;
|
|
582
|
-
}
|
|
583
|
-
const note = await this.options.store.load(session.noteId).catch(() => null);
|
|
584
|
-
if (!note || note.hash === session.knownHash)
|
|
585
|
-
continue;
|
|
586
|
-
session.knownHash = note.hash;
|
|
587
|
-
session.knownVersion = note.version;
|
|
588
|
-
session.title = note.title;
|
|
589
|
-
this.setMeta(session, await this.loadMeta(session.noteId));
|
|
590
|
-
if (!session.dirty)
|
|
591
|
-
this.adopt(session, note.document, 'remote');
|
|
592
|
-
session.remote = { seq: ++this.remoteSeq, note };
|
|
593
|
-
this.record(session, 'system', 'remote', { key: session.dirty ? '別處有新的版本,與你的修改衝突' : '已同步別處的修改' });
|
|
594
|
-
this.changed(session);
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
// ---- internals -----------------------------------------------------------
|
|
598
|
-
blank(key) {
|
|
599
|
-
return {
|
|
600
|
-
key,
|
|
601
|
-
noteId: null,
|
|
602
|
-
title: '',
|
|
603
|
-
knownHash: null,
|
|
604
|
-
knownVersion: null,
|
|
605
|
-
doc: null,
|
|
606
|
-
plainText: '',
|
|
607
|
-
blocks: [],
|
|
608
|
-
blocksDoc: null,
|
|
609
|
-
blockSeq: 0,
|
|
610
|
-
aliases: new Map(),
|
|
611
|
-
version: 0,
|
|
612
|
-
floor: 0,
|
|
613
|
-
changeLog: [],
|
|
614
|
-
mirrorRev: null,
|
|
615
|
-
meta: null,
|
|
616
|
-
metaSeq: 0,
|
|
617
|
-
selection: { text: '', start: 0, end: 0 },
|
|
618
|
-
dirty: false,
|
|
619
|
-
suggestions: [],
|
|
620
|
-
activity: [],
|
|
621
|
-
openSeq: 0,
|
|
622
|
-
ackSeq: 0,
|
|
623
|
-
rev: 0,
|
|
624
|
-
upload: null,
|
|
625
|
-
remote: null,
|
|
626
|
-
updatedAt: this.now(),
|
|
627
|
-
saving: null,
|
|
628
|
-
};
|
|
629
|
-
}
|
|
630
|
-
session(key) {
|
|
631
|
-
if (typeof key !== 'string' || !key.trim() || key.length > MAX_KEY_LENGTH)
|
|
632
|
-
throw usage('Invalid editor session');
|
|
633
|
-
let session = this.sessions.get(key);
|
|
634
|
-
if (!session) {
|
|
635
|
-
session = this.blank(key);
|
|
636
|
-
this.sessions.set(key, session);
|
|
637
|
-
}
|
|
638
|
-
return session;
|
|
639
|
-
}
|
|
640
|
-
requireOpen(key) {
|
|
641
|
-
const session = this.session(key);
|
|
642
|
-
if (!session.noteId) {
|
|
643
|
-
throw new DinoxError('No note is open in this editor session; call dinox_editor_open first.', {
|
|
644
|
-
code: 'EDITOR_NOTE_NOT_OPEN',
|
|
645
|
-
recoverable: true,
|
|
646
|
-
});
|
|
647
|
-
}
|
|
648
|
-
return session;
|
|
649
|
-
}
|
|
650
|
-
payload(session, note) {
|
|
651
|
-
return { ...note, openSeq: session.openSeq, session: session.key, meta: session.meta };
|
|
652
|
-
}
|
|
653
|
-
async view(session, uiSeq) {
|
|
654
|
-
let openRequest;
|
|
655
|
-
if (session.noteId && uiSeq < session.openSeq) {
|
|
656
|
-
// A restored session (or a newly mounted UI) gets the note from the database.
|
|
657
|
-
const note = await this.options.store.load(session.noteId).catch(() => null);
|
|
658
|
-
if (note) {
|
|
659
|
-
if (!session.doc || session.knownHash !== note.hash) {
|
|
660
|
-
const fresh = !session.doc;
|
|
661
|
-
Object.assign(session, { knownHash: note.hash, knownVersion: note.version, title: note.title });
|
|
662
|
-
this.adopt(session, note.document, fresh ? null : 'remote');
|
|
663
|
-
}
|
|
664
|
-
if (!session.meta)
|
|
665
|
-
this.setMeta(session, await this.loadMeta(session.noteId));
|
|
666
|
-
openRequest = this.payload(session, note);
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
return {
|
|
670
|
-
rev: session.rev,
|
|
671
|
-
openSeq: session.openSeq,
|
|
672
|
-
noteId: session.noteId,
|
|
673
|
-
title: session.title,
|
|
674
|
-
suggestions: session.suggestions,
|
|
675
|
-
activity: session.activity.slice(-30),
|
|
676
|
-
upload: session.upload,
|
|
677
|
-
remote: session.remote,
|
|
678
|
-
mirrorRev: session.mirrorRev,
|
|
679
|
-
meta: session.meta,
|
|
680
|
-
metaSeq: session.metaSeq,
|
|
681
|
-
...(openRequest ? { openRequest } : {}),
|
|
682
|
-
};
|
|
683
|
-
}
|
|
684
|
-
// ---- blocks ----------------------------------------------------------------
|
|
685
|
-
/** A session restored after a daemon restart has no document until something needs it. */
|
|
686
|
-
async hydrate(session) {
|
|
687
|
-
if (session.doc || !session.noteId)
|
|
688
|
-
return;
|
|
689
|
-
const note = await this.options.store.load(session.noteId);
|
|
690
|
-
if (session.doc)
|
|
691
|
-
return;
|
|
692
|
-
Object.assign(session, { knownHash: note.hash, knownVersion: note.version, title: note.title });
|
|
693
|
-
this.adopt(session, note.document, null);
|
|
694
|
-
if (!session.meta)
|
|
695
|
-
this.setMeta(session, await this.loadMeta(session.noteId));
|
|
696
|
-
}
|
|
697
|
-
/**
|
|
698
|
-
* Takes a document from outside the mirror. `by: null` starts a fresh
|
|
699
|
-
* history (a newly opened or restored note); otherwise the difference is
|
|
700
|
-
* logged as that actor's change.
|
|
701
|
-
*/
|
|
702
|
-
adopt(session, doc, by) {
|
|
703
|
-
if (by)
|
|
704
|
-
this.ensureBlocks(session, 'user');
|
|
705
|
-
else {
|
|
706
|
-
session.blocks = [];
|
|
707
|
-
session.blocksDoc = null;
|
|
708
|
-
session.aliases = new Map();
|
|
709
|
-
}
|
|
710
|
-
session.doc = doc;
|
|
711
|
-
session.mirrorRev = null;
|
|
712
|
-
this.ensureBlocks(session, by ?? 'user');
|
|
713
|
-
if (!by) {
|
|
714
|
-
session.changeLog = [];
|
|
715
|
-
session.floor = session.version;
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
/** Brings the blocks up to date with the document, logging what changed. */
|
|
719
|
-
ensureBlocks(session, by) {
|
|
720
|
-
if (session.blocksDoc === session.doc)
|
|
721
|
-
return;
|
|
722
|
-
let segmented = { text: '', segments: [] };
|
|
723
|
-
if (session.doc) {
|
|
724
|
-
try {
|
|
725
|
-
segmented = segmentDocument(session.doc);
|
|
726
|
-
}
|
|
727
|
-
catch (error) {
|
|
728
|
-
this.options.log?.('segment failed', { error: String(error) });
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
const { ids, changes } = this.identify(session, segmented.segments);
|
|
732
|
-
session.blocks = segmented.segments.map((segment, index) => ({ id: ids[index], ...segment }));
|
|
733
|
-
session.plainText = segmented.text;
|
|
734
|
-
session.blocksDoc = session.doc;
|
|
735
|
-
if (!changes.length)
|
|
736
|
-
return;
|
|
737
|
-
session.version++;
|
|
738
|
-
for (const change of changes)
|
|
739
|
-
this.log(session, { v: session.version, op: change.op, id: change.id, by });
|
|
740
|
-
}
|
|
741
|
-
/**
|
|
742
|
-
* Which block is which. A block with a note id is that block, whatever
|
|
743
|
-
* happened to its text: it keeps the id the model knows it by. Only blocks
|
|
744
|
-
* without one (older notes, or a block that just got its id in this edit)
|
|
745
|
-
* are paired by position and similarity with the blocks that had none.
|
|
746
|
-
*/
|
|
747
|
-
identify(session, segments) {
|
|
748
|
-
const previous = new Map(session.blocks.map(block => [block.id, block]));
|
|
749
|
-
const ids = segments.map(() => undefined);
|
|
750
|
-
const used = new Set();
|
|
751
|
-
const changes = [];
|
|
752
|
-
segments.forEach((segment, index) => {
|
|
753
|
-
const alias = segment.nodeId ? session.aliases.get(segment.nodeId) : undefined;
|
|
754
|
-
if (!alias || used.has(alias))
|
|
755
|
-
return;
|
|
756
|
-
ids[index] = alias;
|
|
757
|
-
used.add(alias);
|
|
758
|
-
const before = previous.get(alias);
|
|
759
|
-
if (!before)
|
|
760
|
-
changes.push({ id: alias, op: 'added' });
|
|
761
|
-
else if (before.md !== segment.md)
|
|
762
|
-
changes.push({ id: alias, op: 'changed' });
|
|
763
|
-
});
|
|
764
|
-
for (const block of session.blocks) {
|
|
765
|
-
if (block.nodeId && !used.has(block.id))
|
|
766
|
-
changes.push({ id: block.id, op: 'removed' });
|
|
767
|
-
}
|
|
768
|
-
const reserved = new Set([...used, ...previous.keys(), ...session.aliases.values()]);
|
|
769
|
-
const taken = (alias) => reserved.has(alias);
|
|
770
|
-
const rest = segments.flatMap((segment, index) => (ids[index] ? [] : [index]));
|
|
771
|
-
const paired = reconcileBlocks(session.blocks.filter(block => !block.nodeId), rest.map(index => segments[index].md), k => {
|
|
772
|
-
const nodeId = segments[rest[k]].nodeId;
|
|
773
|
-
let alias = nodeId ? shortBlockId(nodeId, taken) : '';
|
|
774
|
-
while (!alias || taken(alias))
|
|
775
|
-
alias = `b${++session.blockSeq}`;
|
|
776
|
-
reserved.add(alias);
|
|
777
|
-
return alias;
|
|
778
|
-
});
|
|
779
|
-
rest.forEach((index, k) => { ids[index] = paired.ids[k]; });
|
|
780
|
-
changes.push(...paired.changes);
|
|
781
|
-
segments.forEach((segment, index) => {
|
|
782
|
-
if (segment.nodeId)
|
|
783
|
-
session.aliases.set(segment.nodeId, ids[index]);
|
|
784
|
-
});
|
|
785
|
-
return { ids: ids, changes };
|
|
786
|
-
}
|
|
787
|
-
log(session, entry) {
|
|
788
|
-
session.changeLog.push(entry);
|
|
789
|
-
while (session.changeLog.length > MAX_LOG)
|
|
790
|
-
session.floor = Math.max(session.floor, session.changeLog.shift().v);
|
|
791
|
-
}
|
|
792
|
-
changesSince(session, since) {
|
|
793
|
-
const ops = new Map();
|
|
794
|
-
const resolved = [];
|
|
795
|
-
for (const entry of session.changeLog) {
|
|
796
|
-
if (entry.v <= since)
|
|
797
|
-
continue;
|
|
798
|
-
if (entry.op === 'accepted' || entry.op === 'rejected') {
|
|
799
|
-
resolved.push({ suggestion: entry.suggestion, block: entry.id, accepted: entry.op === 'accepted' });
|
|
800
|
-
continue;
|
|
801
|
-
}
|
|
802
|
-
const id = entry.id;
|
|
803
|
-
const before = ops.get(id);
|
|
804
|
-
if (!before)
|
|
805
|
-
ops.set(id, { op: entry.op, by: entry.by });
|
|
806
|
-
else if (entry.op === 'removed') {
|
|
807
|
-
if (before.op === 'added')
|
|
808
|
-
ops.delete(id);
|
|
809
|
-
else
|
|
810
|
-
ops.set(id, { op: 'removed', by: entry.by });
|
|
811
|
-
}
|
|
812
|
-
else
|
|
813
|
-
ops.set(id, { op: before.op, by: entry.by === 'remote' ? 'remote' : before.by });
|
|
814
|
-
}
|
|
815
|
-
const order = new Map(session.blocks.map((block, index) => [block.id, index]));
|
|
816
|
-
const changes = [...ops].map(([id, { op, by }]) => {
|
|
817
|
-
const index = order.get(id);
|
|
818
|
-
if (op === 'removed' || index === undefined)
|
|
819
|
-
return { id, op: 'removed', by };
|
|
820
|
-
return { id, op, by, md: session.blocks[index].md, after: index > 0 ? session.blocks[index - 1].id : null };
|
|
821
|
-
});
|
|
822
|
-
changes.sort((a, b) => (order.get(a.id) ?? -1) - (order.get(b.id) ?? -1));
|
|
823
|
-
return { changes, resolved };
|
|
824
|
-
}
|
|
825
|
-
blockAt(session, at) {
|
|
826
|
-
if (at === undefined)
|
|
827
|
-
return undefined;
|
|
828
|
-
return session.blocks.find(block => at >= block.start && at <= block.end);
|
|
829
|
-
}
|
|
830
|
-
selectionBlocks(session) {
|
|
831
|
-
if (!session.blocks.length)
|
|
832
|
-
return null;
|
|
833
|
-
const { start, end, text } = session.selection;
|
|
834
|
-
const hit = session.blocks.filter(block => (text ? block.end > start && block.start < end : start >= block.start && start <= block.end));
|
|
835
|
-
if (!hit.length)
|
|
836
|
-
return null;
|
|
837
|
-
return { blocks: hit.slice(0, 20).map(block => block.id), text: clip(text, 300) };
|
|
838
|
-
}
|
|
839
|
-
recordRead(session, blocks, message = { key: '正在閱讀筆記' }) {
|
|
840
|
-
this.record(session, 'ai', 'read', message, blocks ? blocks.map(block => [block.start, block.end]) : undefined);
|
|
841
|
-
this.changed(session);
|
|
842
|
-
}
|
|
843
|
-
/**
|
|
844
|
-
* Mirror updates from the UI: a whole document, or a splice of top-level
|
|
845
|
-
* nodes on top of the revision the daemon has. A splice on any other base is
|
|
846
|
-
* ignored; the view's `mirrorRev` then tells the UI to resend in full.
|
|
847
|
-
*/
|
|
848
|
-
applyMirror(session, raw) {
|
|
849
|
-
if (!raw || typeof raw !== 'object')
|
|
850
|
-
throw usage('mirror must be an object');
|
|
851
|
-
const mirror = raw;
|
|
852
|
-
const rev = str(mirror.rev, 'mirror.rev', { max: 100 });
|
|
853
|
-
if (mirror.doc !== undefined) {
|
|
854
|
-
if (!isDoc(mirror.doc))
|
|
855
|
-
throw usage('mirror.doc must be a Tiptap document');
|
|
856
|
-
session.doc = mirror.doc;
|
|
857
|
-
session.mirrorRev = rev;
|
|
858
|
-
return true;
|
|
859
|
-
}
|
|
860
|
-
if (!session.doc || mirror.base !== session.mirrorRev || session.mirrorRev === null)
|
|
861
|
-
return false;
|
|
862
|
-
const content = session.doc.content ?? [];
|
|
863
|
-
const from = Number(mirror.from);
|
|
864
|
-
const remove = Number(mirror.remove);
|
|
865
|
-
const insert = mirror.insert;
|
|
866
|
-
const valid = Number.isInteger(from) && Number.isInteger(remove) && from >= 0 && remove >= 0 && from + remove <= content.length
|
|
867
|
-
&& Array.isArray(insert) && insert.every(node => node && typeof node === 'object' && typeof node.type === 'string');
|
|
868
|
-
if (!valid)
|
|
869
|
-
throw usage('mirror patch is out of range');
|
|
870
|
-
session.doc = { ...session.doc, content: [...content.slice(0, from), ...insert, ...content.slice(from + remove)] };
|
|
871
|
-
session.mirrorRev = rev;
|
|
872
|
-
return true;
|
|
873
|
-
}
|
|
874
|
-
trackUpload(session, hash) {
|
|
875
|
-
void this.options.store.waitForUpload(UPLOAD_TIMEOUT_MS).then(ok => ok, () => false).then(ok => {
|
|
876
|
-
if (session.upload?.hash !== hash)
|
|
877
|
-
return;
|
|
878
|
-
session.upload = { hash, state: ok ? 'uploaded' : 'failed' };
|
|
879
|
-
this.changed(session);
|
|
880
|
-
});
|
|
881
|
-
}
|
|
882
|
-
record(session, actor, kind, message, focus) {
|
|
883
|
-
const text = typeof message === 'string' ? message : sourceText(message);
|
|
884
|
-
session.activity.push({ at: new Date(this.now()).toISOString(), actor, kind, text, ...(typeof message === 'string' ? {} : { message }), ...(focus ? { focus } : {}) });
|
|
885
|
-
if (session.activity.length > MAX_ACTIVITY)
|
|
886
|
-
session.activity = session.activity.slice(-MAX_ACTIVITY);
|
|
887
|
-
}
|
|
888
|
-
async loadMeta(noteId) {
|
|
889
|
-
if (!this.options.store.meta)
|
|
890
|
-
return null;
|
|
891
|
-
try {
|
|
892
|
-
return await this.options.store.meta(noteId);
|
|
893
|
-
}
|
|
894
|
-
catch (error) {
|
|
895
|
-
this.options.log?.('editor meta load failed', { error: error instanceof Error ? error.message : String(error) });
|
|
896
|
-
return null;
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
setMeta(session, meta) {
|
|
900
|
-
if (!meta && session.meta)
|
|
901
|
-
return;
|
|
902
|
-
if (JSON.stringify(meta) === JSON.stringify(session.meta))
|
|
903
|
-
return;
|
|
904
|
-
session.meta = meta;
|
|
905
|
-
session.metaSeq++;
|
|
906
|
-
}
|
|
907
|
-
changed(session) {
|
|
908
|
-
session.rev++;
|
|
909
|
-
session.updatedAt = this.now();
|
|
910
|
-
this.wake(this.waitersOf(session.key));
|
|
911
|
-
this.schedulePersist();
|
|
912
|
-
}
|
|
913
|
-
waitersOf(key) {
|
|
914
|
-
let set = this.waiters.get(key);
|
|
915
|
-
if (!set) {
|
|
916
|
-
set = new Set();
|
|
917
|
-
this.waiters.set(key, set);
|
|
918
|
-
}
|
|
919
|
-
return set;
|
|
920
|
-
}
|
|
921
|
-
wake(set) {
|
|
922
|
-
for (const resolve of [...set])
|
|
923
|
-
resolve();
|
|
924
|
-
set.clear();
|
|
925
|
-
}
|
|
926
|
-
waitFor(set, ms, signal) {
|
|
927
|
-
if (this.closed || signal?.aborted)
|
|
928
|
-
return Promise.resolve();
|
|
929
|
-
return new Promise(resolve => {
|
|
930
|
-
const done = () => {
|
|
931
|
-
clearTimeout(timer);
|
|
932
|
-
set.delete(done);
|
|
933
|
-
signal?.removeEventListener('abort', done);
|
|
934
|
-
resolve();
|
|
935
|
-
};
|
|
936
|
-
const timer = setTimeout(done, ms);
|
|
937
|
-
set.add(done);
|
|
938
|
-
signal?.addEventListener('abort', done, { once: true });
|
|
939
|
-
});
|
|
940
|
-
}
|
|
941
|
-
updateWatch() {
|
|
942
|
-
const anyOpen = [...this.sessions.values()].some(s => s.noteId);
|
|
943
|
-
if (anyOpen && !this.unwatch && this.options.watchNotes && !this.closed) {
|
|
944
|
-
this.unwatch = this.options.watchNotes(() => {
|
|
945
|
-
if (this.remoteTimer)
|
|
946
|
-
clearTimeout(this.remoteTimer);
|
|
947
|
-
this.remoteTimer = setTimeout(() => {
|
|
948
|
-
this.remoteTimer = null;
|
|
949
|
-
this.checkRemote().catch(error => this.options.log?.('remote check failed', { error: String(error) }));
|
|
950
|
-
}, REMOTE_DEBOUNCE_MS);
|
|
951
|
-
});
|
|
952
|
-
}
|
|
953
|
-
else if (!anyOpen && this.unwatch) {
|
|
954
|
-
this.unwatch();
|
|
955
|
-
this.unwatch = null;
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
schedulePersist() {
|
|
959
|
-
if (!this.options.persistence || this.persistTimer || this.closed)
|
|
960
|
-
return;
|
|
961
|
-
this.persistTimer = setTimeout(() => {
|
|
962
|
-
this.persistTimer = null;
|
|
963
|
-
void this.persistNow();
|
|
964
|
-
}, PERSIST_DEBOUNCE_MS);
|
|
965
|
-
}
|
|
966
|
-
async persistNow() {
|
|
967
|
-
if (!this.options.persistence)
|
|
968
|
-
return;
|
|
969
|
-
const sessions = [...this.sessions.values()]
|
|
970
|
-
.filter(s => s.noteId)
|
|
971
|
-
.map(({ key, noteId, title, knownHash, knownVersion, openSeq, suggestions, activity, updatedAt, version, blockSeq }) => ({
|
|
972
|
-
key, noteId, title, knownHash, knownVersion, openSeq, version, blockSeq,
|
|
973
|
-
suggestions: suggestions.filter(s => s.status === 'pending'),
|
|
974
|
-
activity: activity.slice(-MAX_ACTIVITY),
|
|
975
|
-
updatedAt,
|
|
976
|
-
}));
|
|
977
|
-
await this.options.persistence.save(sessions).catch(error => this.options.log?.('persist failed', { error: String(error) }));
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
function describeMetaChange(changed, before, after) {
|
|
981
|
-
const parts = [];
|
|
982
|
-
if (changed.includes('title'))
|
|
983
|
-
parts.push({ key: '把標題改成「{title}」', params: { title: after.title || '未命名筆記' } });
|
|
984
|
-
if (changed.includes('tags')) {
|
|
985
|
-
const added = after.tags.filter(tag => !before?.tags.includes(tag));
|
|
986
|
-
const removed = (before?.tags ?? []).filter(tag => !after.tags.includes(tag));
|
|
987
|
-
if (added.length)
|
|
988
|
-
parts.push({ key: '加上標籤 {tags}', params: { tags: added.map(tag => `#${tag}`).join(' ') } });
|
|
989
|
-
if (removed.length)
|
|
990
|
-
parts.push({ key: '移除標籤 {tags}', params: { tags: removed.map(tag => `#${tag}`).join(' ') } });
|
|
991
|
-
}
|
|
992
|
-
if (changed.includes('boxes'))
|
|
993
|
-
parts.push(after.boxes.length ? { key: '移到卡片盒「{boxes}」', params: { boxes: after.boxes.map(box => box.name) } } : { key: '移出了卡片盒' });
|
|
994
|
-
if (changed.includes('is_starred'))
|
|
995
|
-
parts.push({ key: after.starred ? '加上星標' : '取消星標' });
|
|
996
|
-
if (changed.includes('properties'))
|
|
997
|
-
parts.push({ key: '更新了屬性' });
|
|
998
|
-
return { key: '{clauses}', params: { clauses: parts } };
|
|
999
|
-
}
|
|
1000
|
-
/** A block by the id the model knows it by, or by its note id. */
|
|
1001
|
-
function findBlock(blocks, id) {
|
|
1002
|
-
return blocks.find(block => block.id === id) ?? blocks.find(block => block.nodeId === id);
|
|
1003
|
-
}
|
|
1004
|
-
/** The id the model reads for a block named by either id; anything else as given. */
|
|
1005
|
-
function blockRef(blocks, value) {
|
|
1006
|
-
return findBlock(blocks, value)?.id ?? value;
|
|
1007
|
-
}
|