odant-work 1.0.91 → 1.0.92
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/#system/certs/russian_trusted_root_ca.pem +32 -32
- package/#system/mail.json.example +9 -9
- package/#system/package-manifest.json +332 -373
- package/#system/settings.json.example +3 -3
- package/$server/$folder/$class/$data/handlers/pages/form/objects/$handler/class.js +2158 -0
- package/$server/$folder/$class/$data/handlers/pages/form/objects/object/$handler/class.js +1377 -0
- package/$server/$folder/$class/$domain/class.js +4 -4
- package/$server/$folder/$class/$handler/$trigger/class.js +3 -3
- package/$server/$folder/$class/$handler/class.js +9 -9
- package/$server/$folder/$class/$handler/handlers/pages/editor/$handler/class.js +5 -5
- package/$server/$folder/$class/$handler/readme.md +23 -23
- package/$server/$folder/$class/$module/handlers/pages/form/system/{$handler/tabs/mcp/$handler/mcp.js → mcp/$handler/class.js} +251 -210
- package/$server/$folder/$class/$module/handlers/pages/form/system/{$handler/tabs/modules → modules}/$handler/class.js +1 -0
- package/$server/$folder/$class/$structure/$organization/handlers/pages/site/$handler/{site.js → class.js} +351 -364
- package/$server/$folder/$class/$structure/$server/handlers/pages/form/system/{$handler/tabs/license/$handler/license.js → license/$handler/class.js} +104 -103
- package/$server/$folder/$class/$structure/$server/handlers/pages/site/$handler/{site.js → class.js} +45 -30
- package/$server/$folder/$class/$structure/$user/class.js +2 -2
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/agent/$handler/class.js +3 -0
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/messengers/$handler/class.js +3 -0
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/modules/$handler/class.js +3 -0
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/{$handler/tabs/profile/$handler/profile.js → profile/$handler/class.js} +6 -2
- package/$server/$folder/$class/$structure/handlers/pages/data/$handler/class.js +308 -5
- package/$server/$folder/$class/$structure/handlers/pages/explorer/$handler/class.js +14 -3
- package/$server/$folder/$class/$structure/handlers/pages/form/calendar/$handler/class.js +1281 -7
- package/$server/$folder/$class/$structure/handlers/pages/form/calendar/$handler/readme.md +40 -40
- package/$server/$folder/$class/$structure/handlers/pages/form/chat/$handler/class.js +2216 -6
- package/$server/$folder/$class/$structure/handlers/pages/form/email/$handler/class.js +1304 -6
- package/$server/$folder/$class/$structure/handlers/pages/form/search/$handler/class.js +305 -5
- package/$server/$folder/$class/$structure/handlers/pages/form/system/{$handler/tabs/agent/$handler/agent.js → agent/$handler/class.js} +329 -320
- package/$server/$folder/$class/$structure/handlers/pages/form/system/{$handler/tabs/database/$handler/database.js → database/$handler/class.js} +510 -577
- package/$server/$folder/$class/$structure/handlers/pages/form/system/{$handler/tabs/messengers/$handler/messengers.js → messengers/$handler/class.js} +142 -143
- package/$server/$folder/$class/$structure/handlers/pages/form/system/modules/$handler/class.js +270 -0
- package/$server/$folder/$class/$structure/handlers/pages/form/system/staff/$handler/class.js +2114 -0
- package/$server/$folder/$class/$structure/handlers/pages/site/$handler/class.js +229 -4
- package/$server/$folder/$class/ai/config.js +19 -19
- package/$server/$folder/$class/ai/prompt/$method/class.js +41 -41
- package/$server/$folder/$class/ai/skills/approval-flow.md +14 -14
- package/$server/$folder/$class/ai/skills/backup-check.md +13 -13
- package/$server/$folder/$class/ai/skills/computer.md +27 -27
- package/$server/$folder/$class/ai/skills/delegate-task.md +15 -15
- package/$server/$folder/$class/ai/skills/external-signup.md +14 -14
- package/$server/$folder/$class/ai/skills/onboarding.md +15 -15
- package/$server/$folder/$class/ai/skills/orchestration.md +41 -41
- package/$server/$folder/$class/ai/system.md +1 -1
- package/$server/$folder/$class/class.js +0 -3
- package/$server/$folder/$class/handlers/pages/form/folder/$handler/class.js +3 -0
- package/$server/$folder/$class/handlers/pages/form/system/$handler/class.js +2 -4
- package/$server/$folder/$class/handlers/pages/form/system/{$handler/tabs/files → files}/$handler/class.js +2 -0
- package/$server/$folder/$class/handlers/pages/form/system/{$handler/tabs/requisites/$handler/requisites.js → requisites/$handler/class.js} +43 -36
- package/$server/$folder/$class/handlers/pages/storage/$handler/class.js +25 -6
- package/$server/$folder/$file/$audio/handlers/preview/$handler/class.js +3 -3
- package/$server/$folder/$file/$audio/handlers/preview/$handler/preview.js +88 -88
- package/$server/$folder/$file/$call/class.js +10 -10
- package/$server/$folder/$file/$call/handlers/preview/$handler/class.js +4 -4
- package/$server/$folder/$file/$call/triggers/on_save/$trigger/class.js +48 -48
- package/$server/$folder/$file/$data/class.js +16 -16
- package/$server/$folder/$file/$data/handlers/pages/form/editor/$handler/class.js +31 -4
- package/$server/$folder/$file/$devs/$js/class.js +2 -2
- package/$server/$folder/$file/$devs/$json/class.js +2 -2
- package/$server/$folder/$file/$devs/$ts/class.js +2 -2
- package/$server/$folder/$file/$devs/handlers/pages/form/file/$handler/class.js +30 -2
- package/$server/$folder/$file/$eml/class.js +17 -17
- package/$server/$folder/$file/$ics/class.js +44 -44
- package/$server/$folder/$file/$ics/handlers/pages/form/file/$handler/class.js +10 -2
- package/$server/$folder/$file/$ics/handlers/preview/$handler/class.js +3 -3
- package/$server/$folder/$file/$ics/handlers/preview/$handler/preview.js +67 -67
- package/$server/$folder/$file/$ics/readme.md +21 -21
- package/$server/$folder/$file/$image/$svg/class.js +11 -11
- package/$server/$folder/$file/$image/handlers/preview/$handler/class.js +3 -3
- package/$server/$folder/$file/$image/handlers/preview/$handler/preview.js +33 -33
- package/$server/$folder/$file/$ipynb/handlers/pages/form/file/$handler/class.js +82 -2
- package/$server/$folder/$file/$logs/class.js +39 -39
- package/$server/$folder/$file/$logs/handlers/methods/txt-test/$handler/class.js +4 -4
- package/$server/$folder/$file/$md/handlers/pages/form/file/$handler/class.js +60 -2
- package/$server/$folder/$file/$office/$outlook/$ics/class.js +227 -227
- package/$server/$folder/$file/$office/$word/$rtf/template.rtf +159 -159
- package/$server/$folder/$file/$office/handlers/pages/form/file/$handler/class.js +1699 -2
- package/$server/$folder/$file/$task/handlers/pages/form/file/$handler/class.js +827 -2
- package/$server/$folder/$file/$task/handlers/pages/form/file/$handler/readme.md +1 -1
- package/$server/$folder/$file/$task/handlers/pages/form/file/$handler/ui/feed.js +17 -0
- package/$server/$folder/$file/$task/handlers/pages/form/file/$handler/ui/panel.js +7 -1
- package/$server/$folder/$file/$task/handlers/pages/form/file/$handler/ui/util.js +1 -0
- package/$server/$folder/$file/$task/handlers/pages/form/file/$handler/ui/voice-policy.js +6 -2
- package/$server/$folder/$file/$task/handlers/preview/$handler/class.js +3 -3
- package/$server/$folder/$file/$task/readme.md +32 -32
- package/$server/$folder/$file/$txt/handlers/preview/$handler/class.js +3 -3
- package/$server/$folder/$file/$txt/handlers/preview/$handler/preview.js +41 -41
- package/$server/$folder/$file/$video/handlers/preview/$handler/class.js +4 -4
- package/$server/$folder/$file/$video/handlers/preview/$handler/preview.js +13 -13
- package/$server/$folder/$file/class.js +2 -2
- package/$server/$folder/$file/handlers/methods/download/$handler/class.js +2 -2
- package/$server/$folder/$file/handlers/methods/download/$handler/download.js +4 -4
- package/$server/$folder/$file/handlers/pages/form/$handler/class.js +2 -2
- package/$server/$folder/$file/handlers/pages/form/file/$handler/class.js +32 -2
- package/$server/$folder/$file/handlers/pages/form/folder/$handler/class.js +3 -0
- package/$server/$folder/$file/readme.md +31 -31
- package/$server/$folder/class.js +11 -11
- package/$server/$folder/handlers/pages/form/$handler/class.js +2469 -5
- package/$server/$folder/handlers/pages/form/folder/$handler/class.js +22 -0
- package/$server/$folder/lib/chat-item/chat-item.js +2 -2
- package/$server/$folder/lib/email/settings.js +82 -82
- package/$server/$folder/lib/file-viewer/file-viewer.js +8 -8
- package/$server/$folder/lib/icon/user/user.js +6 -6
- package/$server/$folder/lib/item-data-grid/item-data-grid.js +48 -48
- package/$server/$folder/lib/item-form/item-form.js +84 -84
- package/$server/$folder/lib/menu/menu.js +3 -2
- package/$server/$folder/lib/menu/readme.md +29 -29
- package/$server/$folder/lib/node/readme.md +29 -29
- package/$server/$folder/lib/pack/pack.js +4 -4
- package/$server/$folder/lib/site-loc/readme.md +16 -16
- package/.github/workflows/ci.yml +39 -39
- package/AGENTS.md +1 -1
- package/{models/$ai/$folder/$class/$ai/handlers/pages/form/system/$handler/tabs/ai/$handler/ai.js → MODELS/$ai/$folder/$class/$ai/handlers/pages/form/system/ai/$handler/class.js} +383 -430
- package/{models/$ai/$folder/$class/$provider/handlers/pages/form/system/$handler/tabs/ai/$handler/ai.js → MODELS/$ai/$folder/$class/$provider/handlers/pages/form/system/ai/$handler/class.js} +155 -166
- package/{models → MODELS}/$ai/$folder/$class/$provider/readme.md +16 -16
- package/{models/$ai/handlers/pages/form/system/$handler/tabs/ai/$handler/ai.js → MODELS/$ai/handlers/pages/form/system/ai/$handler/class.js} +34 -33
- package/{models → MODELS}/GigaChat/$provider/readme.md +24 -24
- package/{models/Local/$provider/handlers/pages/form/system/$handler/tabs/ai/$handler/ai.js → MODELS/Local/$provider/handlers/pages/form/system/ai/$handler/class.js} +569 -626
- package/MODULES/$domain/handlers/pages/form/system/{$handler/tabs/mcp → mcp}/$handler/class.js +1 -0
- package/MODULES/Geo//320/232/320/260/321/200/321/202/320/260/$catalog/handlers/pages/form/map/$handler/class.js +648 -20
- package/MODULES/KLADR/$module/handlers/pages/form/kladr/$handler/class.js +140 -6
- package/MODULES/Process//320/227/320/260/320/264/320/260/321/207/320/270 /320/270 /321/215/321/202/320/260/320/277/321/213/$catalog/handlers/pages/form/gantt/$handler/class.js" +305 -5
- package/MODULES/Process//320/227/320/260/320/264/320/260/321/207/320/270 /320/270 /321/215/321/202/320/260/320/277/321/213/$catalog/handlers/pages/form/scheduler/$handler/class.js" +241 -5
- package/MODULES/Process//320/241/321/205/320/265/320/274/321/213 /320/277/321/200/320/276/321/206/320/265/321/201/321/201/320/276/320/262/$catalog/handlers/pages/form/bpmn/$handler/class.js" +515 -15
- package/MODULES/Register/CATALOGS/$catalog/$folder/$class/$data/$catalog/$virtual/handlers/pages/form/objects/$handler/class.js +3 -0
- package/MODULES/Register/CATALOGS/$catalog/$folder/$class/$data/$catalog/$virtual/handlers/pages/form/virtual/$handler/class.js +422 -5
- package/MODULES/Register/OPERATIONS//320/240/320/265/320/260/320/273/320/270/320/267/320/260/321/206/320/270/321/217//320/237/320/276/320/272/321/203/320/277/320/260/321/202/320/265/320/273/321/216/$operation/print//320/241/321/207/321/221/321/202 /320/275/320/260 /320/276/320/277/320/273/320/260/321/202/321/203.html" +40 -40
- package/MODULES/Register/OPERATIONS//320/240/320/265/320/260/320/273/320/270/320/267/320/260/321/206/320/270/321/217//320/237/320/276/320/272/321/203/320/277/320/260/321/202/320/265/320/273/321/216/$operation/print//320/242/320/276/320/262/320/260/321/200/320/275/320/260/321/217 /320/275/320/260/320/272/320/273/320/260/320/264/320/275/320/260/321/217.html" +56 -56
- package/MODULES/Register/REGISTER/$register/$folder/$class/$data/$register/$account/handlers/pages/form/analysis/$handler/class.js +13 -7
- package/MODULES/Register/REGISTER/$register/$folder/$class/$data/$register/$account/handlers/pages/form/postings/$handler/class.js +1791 -7
- package/MODULES/Register/REGISTER/$register/$folder/$class/$data/$register/$account/handlers/pages/form/turnovers/$handler/class.js +13 -7
- package/MODULES/Register/REGISTER/$register/handlers/pages/form/journal/$handler/class.js +776 -5
- package/MODULES/Register/REGISTER/$register/handlers/pages/form/sheet/$handler/class.js +807 -5
- package/MODULES/Register/REGISTER/68/01/$account/class.js +1 -1
- package/MODULES/Register/REGISTER/68/02/$account/class.js +1 -1
- package/MODULES/Register/REGISTER//320/232/320/260/320/264/321/200/320/276/320/262/321/213/320/271 /321/200/320/265/320/267/320/265/321/200/320/262/$account/class.js" +1 -1
- package/MODULES/Register/REGISTER//320/232/320/260/320/264/321/200/321/213//320/222 /320/276/321/202/320/277/321/203/321/201/320/272/320/265/$account/class.js" +1 -1
- package/MODULES/Register/REGISTER//320/232/320/260/320/264/321/200/321/213//320/240/320/260/320/261/320/276/321/202/320/260/321/216/321/202/$account/class.js +1 -1
- package/MODULES/Register/REGISTER//320/242/320/265/321/205/320/275/320/270/321/207/320/265/321/201/320/272/320/270/320/271/$account/class.js +1 -1
- package/MODULES/Register/STRUCTS/$struct/class.js +4 -4
- package/NODES/$node/$folder/$class/$node/class.js +35 -35
- package/NODES/$node/class.js +5 -5
- package/NODES/$node/handlers/pages/form/network/$handler/class.js +121 -4
- package/oda/benchmarks/dbmon/lib/ENV.js +213 -213
- package/oda/benchmarks/dbmon/lib/ga.js +11 -11
- package/oda/benchmarks/dbmon/lib/memory-stats.js +105 -105
- package/oda/benchmarks/dbmon/lib/monitor.js +69 -69
- package/oda/benchmarks/sierpinski/sierpinski.js +149 -149
- package/oda/components/editors/code-editor/code-editor.js +387 -387
- package/oda/components/editors/code-editor/src/ace.js +16 -16
- package/oda/components/editors/code-editor/src/beautify-css.js +1625 -1625
- package/oda/components/editors/code-editor/src/beautify-html.js +3122 -3122
- package/oda/components/editors/code-editor/src/beautify.js +4005 -4005
- package/oda/components/editors/code-editor/src/ext-beautify.js +7 -7
- package/oda/components/editors/code-editor/src/ext-code_lens.js +7 -7
- package/oda/components/editors/code-editor/src/ext-elastic_tabstops_lite.js +7 -7
- package/oda/components/editors/code-editor/src/ext-emmet.js +7 -7
- package/oda/components/editors/code-editor/src/ext-error_marker.js +7 -7
- package/oda/components/editors/code-editor/src/ext-hardwrap.js +7 -7
- package/oda/components/editors/code-editor/src/ext-keybinding_menu.js +7 -7
- package/oda/components/editors/code-editor/src/ext-language_tools.js +7 -7
- package/oda/components/editors/code-editor/src/ext-linking.js +7 -7
- package/oda/components/editors/code-editor/src/ext-modelist.js +7 -7
- package/oda/components/editors/code-editor/src/ext-options.js +7 -7
- package/oda/components/editors/code-editor/src/ext-prompt.js +7 -7
- package/oda/components/editors/code-editor/src/ext-rtl.js +7 -7
- package/oda/components/editors/code-editor/src/ext-searchbox.js +7 -7
- package/oda/components/editors/code-editor/src/ext-settings_menu.js +7 -7
- package/oda/components/editors/code-editor/src/ext-spellcheck.js +7 -7
- package/oda/components/editors/code-editor/src/ext-split.js +7 -7
- package/oda/components/editors/code-editor/src/ext-static_highlight.js +7 -7
- package/oda/components/editors/code-editor/src/ext-statusbar.js +7 -7
- package/oda/components/editors/code-editor/src/ext-textarea.js +7 -7
- package/oda/components/editors/code-editor/src/ext-themelist.js +7 -7
- package/oda/components/editors/code-editor/src/ext-whitespace.js +7 -7
- package/oda/components/editors/code-editor/src/keybinding-emacs.js +7 -7
- package/oda/components/editors/code-editor/src/keybinding-sublime.js +7 -7
- package/oda/components/editors/code-editor/src/keybinding-vim.js +7 -7
- package/oda/components/editors/code-editor/src/keybinding-vscode.js +7 -7
- package/oda/components/editors/code-editor/src/mode-css.js +7 -7
- package/oda/components/editors/code-editor/src/mode-html.js +7 -7
- package/oda/components/editors/code-editor/src/mode-javascript.js +7 -7
- package/oda/components/editors/code-editor/src/mode-json.js +7 -7
- package/oda/components/editors/code-editor/src/mode-markdown.js +7 -7
- package/oda/components/editors/code-editor/src/mode-svg.js +7 -7
- package/oda/components/editors/code-editor/src/mode-text.js +7 -7
- package/oda/components/editors/code-editor/src/mode-xml.js +7 -7
- package/oda/components/editors/code-editor/src/mode-xquery.js +7 -7
- package/oda/components/editors/code-editor/src/snippets/css.js +7 -7
- package/oda/components/editors/code-editor/src/snippets/html.js +7 -7
- package/oda/components/editors/code-editor/src/snippets/javascript.js +7 -7
- package/oda/components/editors/code-editor/src/snippets/json.js +7 -7
- package/oda/components/editors/code-editor/src/snippets/markdown.js +7 -7
- package/oda/components/editors/code-editor/src/snippets/svg.js +7 -7
- package/oda/components/editors/code-editor/src/snippets/text.js +7 -7
- package/oda/components/editors/code-editor/src/snippets/xml.js +7 -7
- package/oda/components/editors/code-editor/src/snippets/xquery.js +7 -7
- package/oda/components/editors/code-editor/src/theme-solarized_dark.js +7 -7
- package/oda/components/editors/code-editor/src/theme-solarized_light.js +7 -7
- package/oda/components/editors/markdown/markdown-editor/lib/font-awesome.min.css +3 -3
- package/oda/components/editors/markdown/markdown-editor/lib/readme.md +332 -332
- package/oda/components/editors/markdown/markdown-editor/markdown-editor.js +78 -78
- package/oda/components/editors/markdown/markdown-viewer/test.md +239 -239
- package/oda/components/editors/markdown/markdown.js +76 -76
- package/oda/components/inputs/block/readme.md +39 -39
- package/oda/components/inputs/checkbox/checkbox.js +92 -92
- package/oda/components/inputs/color/color.js +83 -83
- package/oda/components/inputs/date/date.js +40 -40
- package/oda/components/inputs/input/input.js +219 -219
- package/oda/components/inputs/link/link.js +1 -1
- package/oda/components/inputs/link/readme.md +42 -42
- package/oda/components/inputs/markdown-input/markdown-input.js +77 -77
- package/oda/components/inputs/numeric/numeric.js +141 -141
- package/oda/components/inputs/table-input/readme.md +39 -39
- package/oda/components/inputs/text/text.js +88 -88
- package/oda/components/inputs/toggle/toggle.js +101 -101
- package/oda/components/layouts/hexagon-layout/hexagon-layout.js +218 -218
- package/oda/components/menus/menu/index_old.html +140 -140
- package/oda/components/structure/controls-map.js +56 -56
- package/oda/components/structure/controls.js +29 -29
- package/oda/components/structure/readme.md +31 -31
- package/oda/components/structure/structure.js +64 -64
- package/oda/components/table/index.html +210 -210
- package/oda/components/table/lib/coerce.js +68 -68
- package/oda/components/table/lib/column.js +568 -568
- package/oda/components/table/readme.md +120 -120
- package/oda/components/table/router.js +86 -86
- package/oda/components/table/settings.js +89 -89
- package/oda/index.html +159 -159
- package/oda/tools/icons/icons-set/icons-set.js +60 -60
- package/oda/tools/icons/lib/svg/_makeSVG.html +41 -41
- package/oda/tools/icons/lib/svg/aws.svg +2679 -2679
- package/oda/tools/icons/lib/svg/info.json +46 -46
- package/oda/tools/jupyter/demo.ipynb +160 -160
- package/oda/tools/jupyter/lib/print_elements.js +73 -73
- package/oda/tools/jupyter/test-2.ipynb +305 -305
- package/oda/tools/jupyter/test.ipynb +603 -603
- package/oda/tools/styles/adoptedStyleSheets.js +333 -333
- package/oda/tools/tester/device-preview/devices.json +9 -9
- package/package.json +1 -1
- package/rules/rules.md +445 -445
- package/scripts/SYNC-README.md +107 -107
- package/scripts/agent-eval.mjs +223 -223
- package/scripts/dump-svn-chat.mjs +9 -9
- package/scripts/extract-chat-day.mjs +21 -21
- package/scripts/rag-bench.mjs +166 -166
- package/scripts/restore-chat.mjs +166 -166
- package/scripts/sync-svn-git.bat +129 -129
- package/scripts/test-merge.mjs +75 -75
- package/scripts/work-desktop-bridge.mjs +101 -101
- package/sources/client/class.js +3 -0
- package/sources/client/field.js +168 -168
- package/sources/client/handler.js +68 -32
- package/sources/client/index.js +32 -32
- package/sources/client/readme.md +16 -16
- package/sources/client.js +12 -0
- package/sources/core.js +91 -91
- package/sources/data/choices.js +125 -125
- package/sources/host/babel-merge.js +398 -353
- package/sources/host/config.js +48 -48
- package/sources/host/index-db.js +94 -94
- package/sources/host/net-guard.js +228 -228
- package/sources/host/package-install.js +63 -63
- package/sources/host/push.js +86 -86
- package/sources/host/readme.md +41 -41
- package/sources/host/secret-box.js +93 -93
- package/sources/host/server-id.js +26 -26
- package/sources/host/stun.js +33 -33
- package/sources/host/tls-ca.js +60 -60
- package/sources/host/vapid.js +14 -14
- package/sources/index.html +1 -1
- package/sources/modules/a2a/server.js +608 -608
- package/sources/modules/agent/connections.js +442 -442
- package/sources/modules/agent/diff.js +69 -69
- package/sources/modules/agent/eval.js +222 -222
- package/sources/modules/agent/hooks.js +131 -131
- package/sources/modules/agent/index.js +6 -3
- package/sources/modules/agent/log.js +43 -43
- package/sources/modules/agent/loop.js +65 -0
- package/sources/modules/agent/mcp-pool.js +253 -253
- package/sources/modules/agent/recovery.js +89 -89
- package/sources/modules/agent/scope.js +387 -0
- package/sources/modules/agent/session.js +350 -15
- package/sources/modules/agent/taint.js +100 -100
- package/sources/modules/agent/tools/branch.js +311 -311
- package/sources/modules/agent/tools/browser.js +254 -254
- package/sources/modules/agent/tools/computer.js +120 -120
- package/sources/modules/agent/tools/connect.js +316 -316
- package/sources/modules/agent/tools/dev/lsp.js +334 -334
- package/sources/modules/agent/tools/dev/patch.js +564 -564
- package/sources/modules/agent/tools/memory.js +153 -153
- package/sources/modules/agent/tools/meta.js +60 -0
- package/sources/modules/agent/tools/os-files.js +358 -358
- package/sources/modules/agent/tools/plugins.js +80 -80
- package/sources/modules/agent/tools/sandbox.js +268 -268
- package/sources/modules/agent/types.d.ts +183 -183
- package/sources/modules/agent/undo.js +254 -254
- package/sources/modules/agent/util.js +179 -179
- package/sources/modules/contacts/contacts.js +200 -200
- package/sources/modules/contacts/index.html +546 -546
- package/sources/modules/lan/discovery.js +192 -192
- package/sources/modules/lan/store.js +62 -62
- package/sources/modules/mcp/readme.md +70 -70
- package/sources/modules/mcp/server.js +525 -525
- package/sources/modules/mcp/tokens.js +140 -140
- package/sources/modules/nodes/identity.js +123 -123
- package/sources/modules/nodes/outbound.js +105 -105
- package/sources/modules/nodes/signing.js +71 -71
- package/sources/modules/rag/embed-worker.js +36 -36
- package/sources/modules/rag/readme.md +70 -70
- package/sources/modules/readme.md +21 -21
- package/sources/modules/sandbox/config.js +74 -74
- package/sources/modules/sandbox/driver.js +100 -100
- package/sources/modules/sandbox/images/work-computer/Dockerfile +34 -34
- package/sources/modules/sandbox/images/work-computer/entrypoint.sh +24 -24
- package/sources/modules/sandbox/manager.js +1089 -1089
- package/sources/modules/sandbox/readme.md +63 -63
- package/sources/modules/sandbox/vnc-proxy.js +296 -296
- package/sources/server/access/audit.js +138 -138
- package/sources/server/access/refs.js +106 -106
- package/sources/server/assert-class-id.js +23 -23
- package/sources/server/chat-threads.js +16 -5
- package/sources/server/class.js +4 -1
- package/sources/server/external-source.js +90 -90
- package/sources/server/file.js +1 -1
- package/sources/server/folder.js +75 -33
- package/sources/server/handler.js +25 -12
- package/sources/server/index.js +12 -12
- package/sources/server/memory-mark.js +34 -34
- package/sources/server/readme.md +110 -110
- package/sources/server/safe-node-name.js +67 -67
- package/sources/server/server.js +6 -6
- package/sources/server/upload-mark.js +24 -24
- package/sources/server/zip-guard.js +81 -81
- package/whitepaper.md +568 -568
- package/$server/$folder/$class/$module/handlers/pages/form/system/$handler/tabs/mcp/$handler/class.js +0 -9
- package/$server/$folder/$class/$module/handlers/pages/form/system/$handler/tabs/modules/$handler/modules.js +0 -1
- package/$server/$folder/$class/$structure/$server/handlers/pages/form/system/$handler/tabs/license/$handler/class.js +0 -6
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/$handler/tabs/agent/$handler/class.js +0 -3
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/$handler/tabs/messengers/$handler/class.js +0 -3
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/$handler/tabs/modules/$handler/class.js +0 -3
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/$handler/tabs/profile/$handler/class.js +0 -5
- package/$server/$folder/$class/$structure/handlers/pages/data/$handler/data.js +0 -313
- package/$server/$folder/$class/$structure/handlers/pages/explorer/$handler/explorer.js +0 -16
- package/$server/$folder/$class/$structure/handlers/pages/form/calendar/$handler/calendar.js +0 -1226
- package/$server/$folder/$class/$structure/handlers/pages/form/chat/$handler/chat.js +0 -2095
- package/$server/$folder/$class/$structure/handlers/pages/form/email/$handler/email.js +0 -1188
- package/$server/$folder/$class/$structure/handlers/pages/form/search/$handler/search.js +0 -289
- package/$server/$folder/$class/$structure/handlers/pages/form/system/$handler/tabs/agent/$handler/class.js +0 -6
- package/$server/$folder/$class/$structure/handlers/pages/form/system/$handler/tabs/database/$handler/class.js +0 -9
- package/$server/$folder/$class/$structure/handlers/pages/form/system/$handler/tabs/messengers/$handler/class.js +0 -6
- package/$server/$folder/$class/$structure/handlers/pages/form/system/$handler/tabs/modules/$handler/class.js +0 -5
- package/$server/$folder/$class/$structure/handlers/pages/form/system/$handler/tabs/modules/$handler/modules.js +0 -281
- package/$server/$folder/$class/$structure/handlers/pages/form/system/$handler/tabs/staff/$handler/class.js +0 -5
- package/$server/$folder/$class/$structure/handlers/pages/form/system/$handler/tabs/staff/$handler/staff.js +0 -2126
- package/$server/$folder/$class/$structure/handlers/pages/site/$handler/site.js +0 -240
- package/$server/$folder/$class/handlers/pages/form/object/$handler/class.js +0 -32
- package/$server/$folder/$class/handlers/pages/form/object/$handler/object.js +0 -1371
- package/$server/$folder/$class/handlers/pages/form/objects/$handler/class.js +0 -32
- package/$server/$folder/$class/handlers/pages/form/objects/$handler/objects.js +0 -2130
- package/$server/$folder/$class/handlers/pages/form/system/$handler/system.js +0 -309
- package/$server/$folder/$class/handlers/pages/form/system/$handler/tabs/files/$handler/files.js +0 -17
- package/$server/$folder/$class/handlers/pages/form/system/$handler/tabs/requisites/$handler/class.js +0 -16
- package/$server/$folder/$class/handlers/pages/storage/$handler/storage.js +0 -21
- package/$server/$folder/$file/$data/handlers/pages/form/editor/$handler/editor.js +0 -27
- package/$server/$folder/$file/$devs/handlers/pages/form/file/$handler/file.js +0 -31
- package/$server/$folder/$file/$ics/handlers/pages/form/file/$handler/file.js +0 -10
- package/$server/$folder/$file/$ipynb/handlers/pages/form/file/$handler/file.js +0 -72
- package/$server/$folder/$file/$md/handlers/pages/form/file/$handler/file.js +0 -63
- package/$server/$folder/$file/$office/handlers/pages/form/file/$handler/file.js +0 -1845
- package/$server/$folder/$file/$task/handlers/pages/form/file/$handler/file.js +0 -760
- package/$server/$folder/$file/handlers/pages/form/file/$handler/file.js +0 -29
- package/$server/$folder/handlers/pages/form/$handler/form.js +0 -2122
- package/MODULES/$domain/handlers/pages/form/system/$handler/tabs/mcp/$handler/mcp.js +0 -1
- package/MODULES/Geo//320/232/320/260/321/200/321/202/320/260/$catalog/handlers/pages/form/map/$handler/map.js +0 -623
- package/MODULES/KLADR/$module/handlers/pages/form/kladr/$handler/kladr.js +0 -134
- package/MODULES/Process//320/227/320/260/320/264/320/260/321/207/320/270 /320/270 /321/215/321/202/320/260/320/277/321/213/$catalog/handlers/pages/form/gantt/$handler/gantt.js" +0 -293
- package/MODULES/Process//320/227/320/260/320/264/320/260/321/207/320/270 /320/270 /321/215/321/202/320/260/320/277/321/213/$catalog/handlers/pages/form/scheduler/$handler/scheduler.js" +0 -234
- package/MODULES/Process//320/241/321/205/320/265/320/274/321/213 /320/277/321/200/320/276/321/206/320/265/321/201/321/201/320/276/320/262/$catalog/handlers/pages/form/bpmn/$handler/bpmn.js" +0 -406
- package/MODULES/Register/CATALOGS/$catalog/$folder/$class/$data/$catalog/$virtual/handlers/pages/form/virtual/$handler/virtual.js +0 -399
- package/MODULES/Register/REGISTER/$register/$folder/$class/$data/$register/$account/handlers/pages/form/analysis/$handler/analysis.js +0 -9
- package/MODULES/Register/REGISTER/$register/$folder/$class/$data/$register/$account/handlers/pages/form/postings/$handler/postings.js +0 -1700
- package/MODULES/Register/REGISTER/$register/$folder/$class/$data/$register/$account/handlers/pages/form/turnovers/$handler/turnovers.js +0 -9
- package/MODULES/Register/REGISTER/$register/handlers/pages/form/journal/$handler/journal.js +0 -723
- package/MODULES/Register/REGISTER/$register/handlers/pages/form/sheet/$handler/sheet.js +0 -808
- package/NODES/$node/handlers/pages/form/network/$handler/network.js +0 -110
- package/models/$ai/$folder/$class/$ai/handlers/pages/form/system/$handler/tabs/ai/$handler/class.js +0 -6
- package/models/$ai/$folder/$class/$provider/handlers/pages/form/system/$handler/tabs/ai/$handler/class.js +0 -6
- package/models/$ai/handlers/pages/form/system/$handler/tabs/ai/$handler/class.js +0 -6
- package/models/Local/$provider/handlers/pages/form/system/$handler/tabs/ai/$handler/class.js +0 -6
- /package/$server/$folder/$class/$structure/$organization/handlers/pages/form/system/{$handler/tabs/requisites → requisites}/$handler/class.js +0 -0
- /package/$server/$folder/$class/$structure/$server/handlers/pages/form/system/{$handler/tabs/database → database}/$handler/class.js +0 -0
- /package/{models → MODELS}/$ai/$folder/$class/$ai/class.js +0 -0
- /package/{models → MODELS}/$ai/$folder/$class/$ai/methods/chat/$method/class.js +0 -0
- /package/{models → MODELS}/$ai/$folder/$class/$provider/class.js +0 -0
- /package/{models → MODELS}/$ai/class.js +0 -0
- /package/{models → MODELS}/$ai/readme.md +0 -0
- /package/{models → MODELS}/GigaChat/$provider/$folder/$class/$ai/class.js +0 -0
- /package/{models → MODELS}/GigaChat/$provider/class.js +0 -0
- /package/{models → MODELS}/GigaChat/GigaChat 2 Lite/$ai/class.js +0 -0
- /package/{models → MODELS}/GigaChat/GigaChat 2 Max/$ai/class.js +0 -0
- /package/{models → MODELS}/GigaChat/GigaChat 2 Pro/$ai/class.js +0 -0
- /package/{models → MODELS}/GigaChat/GigaChat Embeddings/$ai/class.js +0 -0
- /package/{models → MODELS}/Local/$provider/$folder/$class/$ai/class.js +0 -0
- /package/{models → MODELS}/Local/$provider/class.js +0 -0
- /package/{models → MODELS}/Local/$provider/handlers/methods/transfer/$handler/class.js +0 -0
- /package/{models → MODELS}/MTS-AI/$provider/$folder/$class/$ai/class.js +0 -0
- /package/{models → MODELS}/MTS-AI/$provider/class.js +0 -0
- /package/{models → MODELS}/MTS-AI/Cotype Lite/$ai/class.js +0 -0
- /package/{models → MODELS}/MTS-AI/Cotype Pro 2/$ai/class.js +0 -0
- /package/{models → MODELS}/MTS-AI/Cotype Vision/$ai/class.js +0 -0
- /package/{models → MODELS}/T-Bank/$provider/$folder/$class/$ai/class.js +0 -0
- /package/{models → MODELS}/T-Bank/$provider/class.js +0 -0
- /package/{models → MODELS}/T-Bank/T-Lite 2.0/$ai/class.js +0 -0
- /package/{models → MODELS}/T-Bank/T-Pro 2.0/$ai/class.js +0 -0
- /package/{models → MODELS}/T-Bank/T-VoiceKit ASR/$ai/class.js +0 -0
- /package/{models → MODELS}/T-Bank/T-VoiceKit TTS/$ai/class.js +0 -0
- /package/{models → MODELS}/Yandex/$provider/$folder/$class/$ai/class.js +0 -0
- /package/{models → MODELS}/Yandex/$provider/class.js +0 -0
- /package/{models → MODELS}/Yandex/Alice AI (YandexGPT 5 Pro)/$ai/class.js +0 -0
- /package/{models → MODELS}/Yandex/Yandex Embeddings/$ai/class.js +0 -0
- /package/{models → MODELS}/Yandex/Yandex SpeechKit ASR/$ai/class.js +0 -0
- /package/{models → MODELS}/Yandex/Yandex SpeechKit TTS/$ai/class.js +0 -0
- /package/{models → MODELS}/Yandex/YandexART/$ai/class.js +0 -0
- /package/{models → MODELS}/Yandex/YandexGPT 5 Lite/$ai/class.js +0 -0
- /package/{models → MODELS}/Yandex/YandexGPT Reasoning/$ai/class.js +0 -0
- /package/{users → USERS}/$users/class.js +0 -0
|
@@ -1,2095 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
taskKeyOf,
|
|
3
|
-
taskDayOf,
|
|
4
|
-
isCreatedTask,
|
|
5
|
-
pathOfLog,
|
|
6
|
-
isChatModel,
|
|
7
|
-
getUserPreferredModel,
|
|
8
|
-
setUserPreferredModel,
|
|
9
|
-
} from './chat-task.js';
|
|
10
|
-
|
|
11
|
-
const sleep = ms => new Promise(r => setTimeout(r, ms));
|
|
12
|
-
const SORT_TIMES = new WeakMap();
|
|
13
|
-
/** localStorage.workChatDebug = 1 — журнал времён создания задачи в консоли. */
|
|
14
|
-
function chatDebug(...a) {
|
|
15
|
-
try {
|
|
16
|
-
if (globalThis.localStorage?.workChatDebug)
|
|
17
|
-
console.log('[chat]', Math.round(performance.now()) + 'мс', ...a);
|
|
18
|
-
}
|
|
19
|
-
catch { /* нет localStorage */ }
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Первый лист $ai с chat. Неязыковые модели (image/audio/embedding/asr/tts) отсекаются. */
|
|
23
|
-
async function firstChatLeaf(node) {
|
|
24
|
-
if (!node)
|
|
25
|
-
return null;
|
|
26
|
-
if (!node.items?.length) {
|
|
27
|
-
if (!isChatModel(node))
|
|
28
|
-
return null;
|
|
29
|
-
try {
|
|
30
|
-
const item = node.path ? await WORK.get_item(node.path) : null;
|
|
31
|
-
if (item && !isChatModel(item))
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
catch { /* лист без доп. данных — проверен по node */ }
|
|
35
|
-
return node;
|
|
36
|
-
}
|
|
37
|
-
for (const child of node.items) {
|
|
38
|
-
const found = await firstChatLeaf(child);
|
|
39
|
-
if (found)
|
|
40
|
-
return found;
|
|
41
|
-
}
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export default{
|
|
46
|
-
icon: 'icons:question-answer',
|
|
47
|
-
imports: '/oda//toggle.js, ~/lib//tree.js, ~/lib//chat-item',
|
|
48
|
-
template: /* html */`
|
|
49
|
-
<style>
|
|
50
|
-
:host{
|
|
51
|
-
@apply --vertical;
|
|
52
|
-
overflow: hidden;
|
|
53
|
-
position: relative;
|
|
54
|
-
}
|
|
55
|
-
</style>
|
|
56
|
-
<form-chat flex :$item></form-chat>
|
|
57
|
-
`
|
|
58
|
-
}
|
|
59
|
-
ODA({is: 'form-chat',
|
|
60
|
-
imports: '/oda//toggle.js, ~/lib//tree.js',
|
|
61
|
-
template: /* html */`
|
|
62
|
-
<style>
|
|
63
|
-
:host {
|
|
64
|
-
@apply --vertical;
|
|
65
|
-
overflow: hidden;
|
|
66
|
-
position: relative;
|
|
67
|
-
}
|
|
68
|
-
</style>
|
|
69
|
-
<oda-chat id="chat" :$item ::model></oda-chat>
|
|
70
|
-
`,
|
|
71
|
-
async attached(){
|
|
72
|
-
if (typeof BroadcastChannel !== 'undefined' && !this._modelBc) {
|
|
73
|
-
try {
|
|
74
|
-
this._modelBc = new BroadcastChannel('work-user-ai-model');
|
|
75
|
-
this._modelBc.onmessage = (ev) => {
|
|
76
|
-
const m = ev?.data?.model;
|
|
77
|
-
if (m && m !== this.model)
|
|
78
|
-
this.model = m;
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
catch { /* ignore */ }
|
|
82
|
-
}
|
|
83
|
-
await this._hydrateModel();
|
|
84
|
-
},
|
|
85
|
-
detached(){
|
|
86
|
-
try {
|
|
87
|
-
this._modelBc?.close?.();
|
|
88
|
-
this._modelBc = null;
|
|
89
|
-
}
|
|
90
|
-
catch { /* ignore */ }
|
|
91
|
-
},
|
|
92
|
-
last:{
|
|
93
|
-
$def: 0,
|
|
94
|
-
$save: true
|
|
95
|
-
},
|
|
96
|
-
model: {
|
|
97
|
-
$def: '',
|
|
98
|
-
set(n) {
|
|
99
|
-
if (n)
|
|
100
|
-
setUserPreferredModel(n);
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
get $saveKey(){
|
|
104
|
-
return this.$item?.short;
|
|
105
|
-
},
|
|
106
|
-
async _hydrateModel(){
|
|
107
|
-
const userModel = getUserPreferredModel();
|
|
108
|
-
if (userModel && this.model !== userModel)
|
|
109
|
-
this.model = userModel;
|
|
110
|
-
if (!this.model) {
|
|
111
|
-
try {
|
|
112
|
-
const children = await WORK.children;
|
|
113
|
-
const aiRoot = children?.find(el => el.type === '$ai');
|
|
114
|
-
if (!aiRoot) return;
|
|
115
|
-
const tree = await aiRoot.info({ deep: -1 });
|
|
116
|
-
const leaf = await firstChatLeaf(tree);
|
|
117
|
-
const path = leaf?.path;
|
|
118
|
-
if (path) {
|
|
119
|
-
this.model = path;
|
|
120
|
-
setUserPreferredModel(path);
|
|
121
|
-
}
|
|
122
|
-
} catch {}
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
get formChat(){
|
|
126
|
-
return this;
|
|
127
|
-
},
|
|
128
|
-
get chat(){
|
|
129
|
-
return this.$('oda-chat');
|
|
130
|
-
},
|
|
131
|
-
get isPrivate(){
|
|
132
|
-
return this.$item?.type === '$user'
|
|
133
|
-
},
|
|
134
|
-
focusInput(){
|
|
135
|
-
this.async(()=>{
|
|
136
|
-
this.chat?.focusInput?.();
|
|
137
|
-
})
|
|
138
|
-
},
|
|
139
|
-
receivers: [],
|
|
140
|
-
deptUsers: [],
|
|
141
|
-
operationClasses: [],
|
|
142
|
-
async _loadDepartmentContext($item = this.$item) {
|
|
143
|
-
if (!$item || this.isPrivate) {
|
|
144
|
-
this.deptUsers = [];
|
|
145
|
-
this.operationClasses = [];
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
try {
|
|
149
|
-
const d = await $item.fetch('places').catch(() => null);
|
|
150
|
-
const placeLabels = new Map();
|
|
151
|
-
const uidSet = new Set();
|
|
152
|
-
const opMap = new Map();
|
|
153
|
-
|
|
154
|
-
const collectTreeOps = (nodes, parentOpPath = '') => {
|
|
155
|
-
for (const n of nodes || []) {
|
|
156
|
-
if (!n) continue;
|
|
157
|
-
const isOp = n.type === '$operation';
|
|
158
|
-
const hasKids = Array.isArray(n.children) && n.children.length > 0;
|
|
159
|
-
const isOpsRoot = isOp && /(?:^|\/)OPERATIONS$/i.test(n.path || '');
|
|
160
|
-
if (isOp && n.path && !isOpsRoot) {
|
|
161
|
-
const leaf = !hasKids;
|
|
162
|
-
if (!leaf || n.access !== 'read') {
|
|
163
|
-
const prev = opMap.get(n.path);
|
|
164
|
-
const count = Number(n.objectCount ?? n.count) || prev?.count || 0;
|
|
165
|
-
opMap.set(n.path, {
|
|
166
|
-
id: n.path,
|
|
167
|
-
cid: n.path,
|
|
168
|
-
path: n.path,
|
|
169
|
-
parent: parentOpPath || prev?.parent || '',
|
|
170
|
-
label: n.label || n.id || n.path.split('/').pop(),
|
|
171
|
-
type: '$operation',
|
|
172
|
-
icon: n.icon || prev?.icon || 'carbon:task-complete',
|
|
173
|
-
leaf: prev ? (prev.leaf && leaf) : leaf,
|
|
174
|
-
count,
|
|
175
|
-
hint: n.path,
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
if (hasKids) {
|
|
180
|
-
const nextParent = (isOp && n.path && !isOpsRoot) ? n.path : parentOpPath;
|
|
181
|
-
collectTreeOps(n.children, nextParent);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
const walkPlaces = (places) => {
|
|
187
|
-
for (const p of places || []) {
|
|
188
|
-
if (!p) continue;
|
|
189
|
-
const pLabel = p.label || p.id || '';
|
|
190
|
-
for (const u of p.users || []) {
|
|
191
|
-
if (u && u !== 'GUEST' && u !== 'GUESTS' && u !== 'USERS') {
|
|
192
|
-
uidSet.add(u);
|
|
193
|
-
if (pLabel && !placeLabels.has(u))
|
|
194
|
-
placeLabels.set(u, pLabel);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
if (Array.isArray(p.tree))
|
|
198
|
-
collectTreeOps(p.tree);
|
|
199
|
-
if (Array.isArray(p.roles))
|
|
200
|
-
walkPlaces(p.roles);
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
if (d) {
|
|
205
|
-
if (Array.isArray(d.commonTree))
|
|
206
|
-
collectTreeOps(d.commonTree);
|
|
207
|
-
walkPlaces(d.places);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const roleIds = $item.DATA?.roleIds || {};
|
|
211
|
-
for (const [roleKey, list] of Object.entries(roleIds)) {
|
|
212
|
-
for (const u of list || []) {
|
|
213
|
-
if (u && u !== 'GUEST' && u !== 'GUESTS' && u !== 'USERS') {
|
|
214
|
-
uidSet.add(u);
|
|
215
|
-
if (!placeLabels.has(u))
|
|
216
|
-
placeLabels.set(u, roleKey === 'BOSS' ? 'Руководитель (BOSS)' : 'Сотрудник');
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Если в подразделении ещё не распределены места — подгружаем список пользователей из /USERS
|
|
222
|
-
if (!uidSet.size && WORK.DEV_MODE) {
|
|
223
|
-
const uRoot = await WORK.get_item('/USERS').catch(() => null);
|
|
224
|
-
const all = (await uRoot?.items) || [];
|
|
225
|
-
for (const u of all) {
|
|
226
|
-
if (u?.id && u.id[0] !== '$')
|
|
227
|
-
uidSet.add(u.id);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// Если по дереву ссылок не нашлось листовых $operation, добираем из db_workspace
|
|
232
|
-
if (![...opMap.values()].some(x => x.leaf)) {
|
|
233
|
-
const ws = await $item.fetch('db_workspace').catch(() => null);
|
|
234
|
-
for (const [cid, cls] of Object.entries(ws?.classes || {})) {
|
|
235
|
-
const p = cls?.path || cid;
|
|
236
|
-
if (cls?.type === '$operation' && p && !/(?:^|\/)OPERATIONS$/i.test(p)) {
|
|
237
|
-
const parentPath = /(?:^|\/)OPERATIONS$/i.test(cls.parent || '') ? '' : (cls.parent || '');
|
|
238
|
-
opMap.set(p, {
|
|
239
|
-
id: p,
|
|
240
|
-
cid: p,
|
|
241
|
-
path: p,
|
|
242
|
-
parent: parentPath,
|
|
243
|
-
label: cls.label || p.split('/').pop(),
|
|
244
|
-
type: '$operation',
|
|
245
|
-
icon: cls.icon || 'carbon:task-complete',
|
|
246
|
-
leaf: !!cls.leaf,
|
|
247
|
-
count: Number(cls.count ?? cls.objectCount) || 0,
|
|
248
|
-
hint: p,
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const users = uidSet.size && typeof WORK.usersByIds === 'function'
|
|
255
|
-
? ((await WORK.usersByIds([...uidSet])) || []).filter(Boolean)
|
|
256
|
-
: [];
|
|
257
|
-
for (const u of users) {
|
|
258
|
-
if (u?.id && placeLabels.has(u.id))
|
|
259
|
-
u._placeLabel = placeLabels.get(u.id);
|
|
260
|
-
}
|
|
261
|
-
this.deptUsers = users;
|
|
262
|
-
this.operationClasses = [...opMap.values()];
|
|
263
|
-
}
|
|
264
|
-
catch (err) {
|
|
265
|
-
console.warn('[chat] _loadDepartmentContext:', err);
|
|
266
|
-
}
|
|
267
|
-
},
|
|
268
|
-
// $item: null
|
|
269
|
-
$item: {
|
|
270
|
-
$def: null,
|
|
271
|
-
set($item) {
|
|
272
|
-
if($item && this.isPrivate && this.$item.id !== WORK.uid) this.receivers = [$item];
|
|
273
|
-
else this.receivers = [];
|
|
274
|
-
if ($item) {
|
|
275
|
-
this._hydrateModel();
|
|
276
|
-
this._loadDepartmentContext($item);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
})
|
|
281
|
-
ODA({is: 'oda-chat',
|
|
282
|
-
imports: 'oda//button, oda//icon, ~/lib//pack, ~/lib//tree, ~/lib//user, ~/lib//prompt-bar',
|
|
283
|
-
template:/* html */`
|
|
284
|
-
<style>
|
|
285
|
-
:host{
|
|
286
|
-
@apply --flex;
|
|
287
|
-
@apply --vertical;
|
|
288
|
-
overflow: hidden;
|
|
289
|
-
position: relative;
|
|
290
|
-
background: {{background}};
|
|
291
|
-
}
|
|
292
|
-
.back{
|
|
293
|
-
position: absolute;
|
|
294
|
-
top: 0px;
|
|
295
|
-
left: 0px;
|
|
296
|
-
width: 100%;
|
|
297
|
-
height: 100%;
|
|
298
|
-
background-repeat: round;
|
|
299
|
-
background: url({{url}});
|
|
300
|
-
pointer-events: none;
|
|
301
|
-
opacity: .1;
|
|
302
|
-
}
|
|
303
|
-
.mover{
|
|
304
|
-
gap: 4px;
|
|
305
|
-
position: absolute;
|
|
306
|
-
align-self: anchor-center;
|
|
307
|
-
right: 8px;
|
|
308
|
-
opacity: .5;
|
|
309
|
-
}
|
|
310
|
-
.mover>oda-button{
|
|
311
|
-
border-radius: 50%;
|
|
312
|
-
}
|
|
313
|
-
.feed-top-bar {
|
|
314
|
-
position: relative;
|
|
315
|
-
z-index: 8;
|
|
316
|
-
display: flex;
|
|
317
|
-
align-items: center;
|
|
318
|
-
justify-content: flex-end;
|
|
319
|
-
gap: 6px;
|
|
320
|
-
flex-wrap: wrap;
|
|
321
|
-
padding: 6px 12px 4px;
|
|
322
|
-
flex-shrink: 0;
|
|
323
|
-
}
|
|
324
|
-
.feed-mode-bar {
|
|
325
|
-
display: inline-flex;
|
|
326
|
-
align-items: center;
|
|
327
|
-
gap: 2px;
|
|
328
|
-
padding: 2px;
|
|
329
|
-
border-radius: 999px;
|
|
330
|
-
background: var(--content-background, #ffffff);
|
|
331
|
-
border: 1px solid var(--border-color, #cbd5e1);
|
|
332
|
-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
|
|
333
|
-
opacity: 0.94;
|
|
334
|
-
}
|
|
335
|
-
.feed-mode-bar:hover {
|
|
336
|
-
opacity: 1;
|
|
337
|
-
}
|
|
338
|
-
.feed-mode-btn {
|
|
339
|
-
border: none;
|
|
340
|
-
background: transparent;
|
|
341
|
-
color: var(--content-color, inherit);
|
|
342
|
-
font: inherit;
|
|
343
|
-
font-size: 11px;
|
|
344
|
-
font-weight: 600;
|
|
345
|
-
padding: 4px 10px;
|
|
346
|
-
border-radius: 999px;
|
|
347
|
-
cursor: pointer;
|
|
348
|
-
white-space: nowrap;
|
|
349
|
-
transition: background 0.15s ease, color 0.15s ease;
|
|
350
|
-
}
|
|
351
|
-
.feed-mode-btn:hover:not(.active) {
|
|
352
|
-
background: var(--subtle-background, rgba(0, 0, 0, 0.05));
|
|
353
|
-
}
|
|
354
|
-
.feed-mode-btn.active {
|
|
355
|
-
background: var(--accent-color, #2563eb);
|
|
356
|
-
color: var(--accent-back, #ffffff);
|
|
357
|
-
}
|
|
358
|
-
.audit-overlay {
|
|
359
|
-
position: absolute;
|
|
360
|
-
inset: 44px 12px 68px 12px;
|
|
361
|
-
z-index: 11;
|
|
362
|
-
background: var(--content-background, #fff);
|
|
363
|
-
border: 1px solid var(--border-color, #cbd5e1);
|
|
364
|
-
border-radius: 10px;
|
|
365
|
-
box-shadow: 0 6px 24px rgba(0,0,0,0.14);
|
|
366
|
-
display: flex;
|
|
367
|
-
overflow: hidden;
|
|
368
|
-
}
|
|
369
|
-
.audit-sidebar {
|
|
370
|
-
width: 260px;
|
|
371
|
-
flex-shrink: 0;
|
|
372
|
-
border-right: 1px solid var(--subtle-border, #e2e8f0);
|
|
373
|
-
overflow-y: auto;
|
|
374
|
-
padding: 8px;
|
|
375
|
-
display: flex;
|
|
376
|
-
flex-direction: column;
|
|
377
|
-
gap: 4px;
|
|
378
|
-
background: var(--subtle-background, #f8fafc);
|
|
379
|
-
box-sizing: border-box;
|
|
380
|
-
}
|
|
381
|
-
.audit-messages {
|
|
382
|
-
flex: 1 1 auto;
|
|
383
|
-
min-width: 0;
|
|
384
|
-
min-height: 0;
|
|
385
|
-
display: flex;
|
|
386
|
-
flex-direction: column;
|
|
387
|
-
overflow-y: auto;
|
|
388
|
-
padding: 12px 16px;
|
|
389
|
-
gap: 8px;
|
|
390
|
-
}
|
|
391
|
-
.participants-popover {
|
|
392
|
-
position: absolute;
|
|
393
|
-
top: 44px;
|
|
394
|
-
right: 12px;
|
|
395
|
-
z-index: 12;
|
|
396
|
-
width: min(280px, calc(100vw - 24px));
|
|
397
|
-
max-height: min(360px, 60dvh);
|
|
398
|
-
overflow-y: auto;
|
|
399
|
-
background: var(--content-background, #fff);
|
|
400
|
-
border: 1px solid var(--border-color, #cbd5e1);
|
|
401
|
-
border-radius: 10px;
|
|
402
|
-
box-shadow: 0 6px 20px rgba(0,0,0,0.16);
|
|
403
|
-
padding: 10px 12px;
|
|
404
|
-
display: flex;
|
|
405
|
-
flex-direction: column;
|
|
406
|
-
gap: 8px;
|
|
407
|
-
font-size: 12.5px;
|
|
408
|
-
box-sizing: border-box;
|
|
409
|
-
}
|
|
410
|
-
.chat-composer {
|
|
411
|
-
z-index: 10;
|
|
412
|
-
max-height: 50%;
|
|
413
|
-
overflow: visible;
|
|
414
|
-
padding-bottom: var(--safe-bottom, 0px);
|
|
415
|
-
}
|
|
416
|
-
@media (max-width: 768px) {
|
|
417
|
-
.feed-top-bar {
|
|
418
|
-
padding: 4px 8px;
|
|
419
|
-
}
|
|
420
|
-
.feed-mode-bar {
|
|
421
|
-
max-width: 100%;
|
|
422
|
-
overflow-x: auto;
|
|
423
|
-
}
|
|
424
|
-
.audit-overlay {
|
|
425
|
-
inset: 42px 6px 64px 6px;
|
|
426
|
-
flex-direction: column;
|
|
427
|
-
}
|
|
428
|
-
.audit-sidebar {
|
|
429
|
-
width: 100%;
|
|
430
|
-
max-height: 36%;
|
|
431
|
-
border-right: none;
|
|
432
|
-
border-bottom: 1px solid var(--subtle-border, #e2e8f0);
|
|
433
|
-
}
|
|
434
|
-
.participants-popover {
|
|
435
|
-
left: 8px;
|
|
436
|
-
right: 8px;
|
|
437
|
-
width: auto;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
</style>
|
|
441
|
-
|
|
442
|
-
<style>
|
|
443
|
-
::-webkit-scrollbar {
|
|
444
|
-
width: 4px;
|
|
445
|
-
height: 4px;
|
|
446
|
-
}
|
|
447
|
-
::-webkit-scrollbar-thumb {
|
|
448
|
-
background-color: transparent;
|
|
449
|
-
}
|
|
450
|
-
::-webkit-scrollbar-thumb:hover {
|
|
451
|
-
background-color: transparent;
|
|
452
|
-
}
|
|
453
|
-
::-webkit-scrollbar-track {
|
|
454
|
-
background-color: transparent;
|
|
455
|
-
}
|
|
456
|
-
</style>
|
|
457
|
-
<div class="back"></div>
|
|
458
|
-
<div class="feed-top-bar" ~if="showFeedModeToggle || ($item && $item.type !== '$user')">
|
|
459
|
-
<div class="feed-mode-bar" ~if="showFeedModeToggle">
|
|
460
|
-
<button type="button" class="feed-mode-btn" ~class="{ active: feedMode === 'dialog' }" @tap="setFeedMode('dialog')" title="Мой диалог и задачи с Агентом этого узла">Диалог</button>
|
|
461
|
-
<button type="button" class="feed-mode-btn" ~class="{ active: feedMode === 'local' }" @tap="setFeedMode('local')" title="Местный лог открытой точки (доступно только BOSS)">Местный лог</button>
|
|
462
|
-
<button type="button" class="feed-mode-btn" ~class="{ active: feedMode === 'audit' }" @tap="setFeedMode('audit')" title="Взаимодействия пользователей и клиентов с Агентом (доступно только BOSS)">Взаимодействия</button>
|
|
463
|
-
</div>
|
|
464
|
-
<div class="feed-mode-bar" ~if="$item && $item.type !== '$user'">
|
|
465
|
-
<button type="button" class="feed-mode-btn" ~class="{ active: showParticipants }" @tap="toggleParticipants()" title="Участники и рабочие места подразделения">Участники ({{participantsCount}})</button>
|
|
466
|
-
</div>
|
|
467
|
-
</div>
|
|
468
|
-
<div ~if="feedMode === 'audit' && showFeedModeToggle" class="audit-overlay">
|
|
469
|
-
<div class="audit-sidebar">
|
|
470
|
-
<div style="font-size:12px;font-weight:700;padding:4px 6px;color:var(--muted-color);">Диалоги с Агентом ({{auditThreads.length}})</div>
|
|
471
|
-
<div ~if="!auditThreads.length" style="font-size:12.5px;color:var(--muted-color);padding:8px 6px;">Взаимодействий пока нет</div>
|
|
472
|
-
<div ~for="auditThreads" @tap="openAuditThread($for.item)" ~class="{ active: auditSelectedId === $for.item.id }" style="padding:7px 9px;border-radius:7px;cursor:pointer;border:1px solid var(--subtle-border,transparent);background:var(--content-background,#fff);font-size:12.5px;">
|
|
473
|
-
<div style="font-weight:600;display:flex;justify-content:space-between;gap:6px;">
|
|
474
|
-
<span>{{$for.item.peerLabel}}</span>
|
|
475
|
-
<span style="font-size:11px;opacity:0.7;">{{$for.item.messageCount}}</span>
|
|
476
|
-
</div>
|
|
477
|
-
<div ~if="$for.item.lastMessage" style="font-size:11.5px;color:var(--muted-color);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;margin-top:2px;">{{$for.item.lastMessage.content || ($for.item.lastMessage.taskPath ? 'Задача' : 'Вложение')}}</div>
|
|
478
|
-
</div>
|
|
479
|
-
</div>
|
|
480
|
-
<div class="audit-messages">
|
|
481
|
-
<div ~if="!auditSelectedId" style="color:var(--muted-color);font-size:13px;margin:auto;">Выберите пользователя для просмотра истории взаимодействия с Агентом</div>
|
|
482
|
-
<div ~for="auditMessages" style="padding:8px 11px;border-radius:8px;border:1px solid var(--subtle-border,#e2e8f0);background:var(--subtle-background,#f8fafc);font-size:13px;">
|
|
483
|
-
<div style="font-size:11px;color:var(--muted-color);display:flex;justify-content:space-between;gap:8px;flex-wrap:wrap;margin-bottom:3px;">
|
|
484
|
-
<b>{{$for.item.sender === '$twin' ? 'Агент узла' : $for.item.sender}}</b>
|
|
485
|
-
<span>{{new Date($for.item.created).toLocaleString()}}</span>
|
|
486
|
-
</div>
|
|
487
|
-
<div style="white-space:pre-wrap;word-break:break-word;">{{$for.item.content || ($for.item.taskPath ? 'Задача: ' + $for.item.taskPath : '')}}</div>
|
|
488
|
-
<div ~if="$for.item.kind === 'approval'" style="display:flex;align-items:center;flex-wrap:wrap;gap:8px;margin-top:6px;">
|
|
489
|
-
<span ~if="$for.item.meta?.status === 'approved'" style="font-size:11.5px;font-weight:700;color:#059669;">✓ Утверждено</span>
|
|
490
|
-
<span ~if="$for.item.meta?.status === 'rejected'" style="font-size:11.5px;font-weight:700;color:#dc2626;">✕ Отклонено</span>
|
|
491
|
-
<oda-button ~if="$for.item.meta?.status === 'pending'" icon="icons:check" info-invert @tap="resolveApprovalMsg($for.item, 'approve')">Утвердить</oda-button>
|
|
492
|
-
<oda-button ~if="$for.item.meta?.status === 'pending'" icon="icons:close" @tap="resolveApprovalMsg($for.item, 'reject')">Отклонить</oda-button>
|
|
493
|
-
</div>
|
|
494
|
-
</div>
|
|
495
|
-
</div>
|
|
496
|
-
</div>
|
|
497
|
-
<div ~if="showParticipants && $item && $item.type !== '$user'" class="participants-popover">
|
|
498
|
-
<div style="display:flex;align-items:center;justify-content:space-between;font-weight:700;">
|
|
499
|
-
<span>Участники ({{participantsCount}})</span>
|
|
500
|
-
<oda-button icon="icons:close" :icon-size="14" @tap="showParticipants = false"></oda-button>
|
|
501
|
-
</div>
|
|
502
|
-
<div ~if="!participantsList.length" style="color:var(--muted-color);">Назначенных участников нет</div>
|
|
503
|
-
<div ~for="participantsList" @tap="openParticipant($for.item)" style="display:flex;align-items:center;gap:8px;padding:5px 7px;border-radius:7px;cursor:pointer;border:1px solid var(--subtle-border,transparent);">
|
|
504
|
-
<item-icon :$item="$for.item" icon-size="22" default="icons:person"></item-icon>
|
|
505
|
-
<div style="flex:1;min-width:0;">
|
|
506
|
-
<div style="font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">{{$for.item.label || $for.item.id}}</div>
|
|
507
|
-
<div ~if="$for.item._placeLabel" style="font-size:11px;color:var(--muted-color);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">{{$for.item._placeLabel}}</div>
|
|
508
|
-
</div>
|
|
509
|
-
</div>
|
|
510
|
-
</div>
|
|
511
|
-
<chat-ribbon id="ribbon" :$item @chat-item-expanded="onCardExpanded($event)"></chat-ribbon>
|
|
512
|
-
<div class="mover" vertical hidden>
|
|
513
|
-
<oda-button :hidden="$('#ribbon').scrollTop < 0" content shadow icon="icons:chevron-right:270" @tap="$('#ribbon').scrollTop = -($('#ribbon').scrollHeight)"></oda-button>
|
|
514
|
-
<oda-button :hidden="$('#ribbon').scrollTop > 0" content shadow icon="icons:chevron-right:90" @tap="$('#ribbon').scrollTop = 0"></oda-button>
|
|
515
|
-
</div>
|
|
516
|
-
<div vertical shadow content :hidden="hasExpandedCard" class="chat-composer">
|
|
517
|
-
<div ~if="replyTarget" horizontal accent-invert style="padding: 4px;">
|
|
518
|
-
<div horizontal flex style="overflow: auto; align-self: center;"></div>
|
|
519
|
-
<oda-button icon="icons:close" @tap="clear" style="padding: 0"></oda-button>
|
|
520
|
-
</div>
|
|
521
|
-
<div ~if="replyTarget" light vertical style="overflow-y: auto;" disabled>
|
|
522
|
-
<chat-item reply :$file="replyTarget"></chat-item>
|
|
523
|
-
</div>
|
|
524
|
-
<microchat-voice ~if="voiceOn"></microchat-voice>
|
|
525
|
-
<work-prompt-bar style="margin: 8px;" @tap="focusedItem = null"
|
|
526
|
-
::value ::files :ai="isAIMode" :placeholder :pending="awaitTask"
|
|
527
|
-
::model ::tts-mode ::receivers :dept-users="deptUsers" :operation-classes="operationClasses" :show-tts="true"
|
|
528
|
-
@receivers-changed="onReceiversChanged($event)" @create-operation="onCreateOperation($event)"
|
|
529
|
-
@send="onBarSend" @stop="onBarStop" @clear="clear" @prompt-key="_onPromptKey"></work-prompt-bar>
|
|
530
|
-
</div>
|
|
531
|
-
`,
|
|
532
|
-
get background(){
|
|
533
|
-
return `linear-gradient(145deg, var(--info-background), var(--info-color))`
|
|
534
|
-
},
|
|
535
|
-
get url(){
|
|
536
|
-
if(this.$pdp.$handler)
|
|
537
|
-
return this.$pdp.$handler.short + '/~/background.jpg';
|
|
538
|
-
},
|
|
539
|
-
files: [],
|
|
540
|
-
hasExpandedCard: false,
|
|
541
|
-
onCardExpanded(e) {
|
|
542
|
-
const detail = e?.detail || {};
|
|
543
|
-
this._expandedCards ??= new Set();
|
|
544
|
-
if (detail.card) {
|
|
545
|
-
if (detail.expanded)
|
|
546
|
-
this._expandedCards.add(detail.card);
|
|
547
|
-
else
|
|
548
|
-
this._expandedCards.delete(detail.card);
|
|
549
|
-
for (const c of [...this._expandedCards]) {
|
|
550
|
-
if (!c.isConnected || !c.expanded)
|
|
551
|
-
this._expandedCards.delete(c);
|
|
552
|
-
}
|
|
553
|
-
this.hasExpandedCard = this._expandedCards.size > 0;
|
|
554
|
-
}
|
|
555
|
-
else {
|
|
556
|
-
this.hasExpandedCard = Boolean(detail.expanded);
|
|
557
|
-
}
|
|
558
|
-
},
|
|
559
|
-
get placeholder(){
|
|
560
|
-
if(this.$pdp.receivers.length)
|
|
561
|
-
return 'Сообщение для ' + this.$pdp.receivers.map(user => user.label).join(', ') + ' ...';
|
|
562
|
-
return 'Новая задача для ИИ ...'
|
|
563
|
-
},
|
|
564
|
-
get isAIMode(){
|
|
565
|
-
const isForeign = this.$pdp?.isPrivate && this.$pdp?.$item?.id !== WORK.uid;
|
|
566
|
-
const hasReceivers = !!(this.$pdp?.receivers?.length);
|
|
567
|
-
return !isForeign && !hasReceivers;
|
|
568
|
-
},
|
|
569
|
-
get receivers(){
|
|
570
|
-
return this.$pdp.receivers;
|
|
571
|
-
},
|
|
572
|
-
set receivers(v) {
|
|
573
|
-
if (this.$pdp)
|
|
574
|
-
this.$pdp.receivers = Array.isArray(v) ? v : [];
|
|
575
|
-
},
|
|
576
|
-
get deptUsers() {
|
|
577
|
-
return this.$pdp?.deptUsers || [];
|
|
578
|
-
},
|
|
579
|
-
get operationClasses() {
|
|
580
|
-
return this.$pdp?.operationClasses || [];
|
|
581
|
-
},
|
|
582
|
-
onReceiversChanged(e) {
|
|
583
|
-
const list = e?.detail?.value ?? e?.detail ?? [];
|
|
584
|
-
if (this.$pdp)
|
|
585
|
-
this.$pdp.receivers = Array.isArray(list) ? list : [];
|
|
586
|
-
},
|
|
587
|
-
async onCreateOperation(e) {
|
|
588
|
-
const d = e?.detail?.value ?? e?.detail ?? {};
|
|
589
|
-
const path = d.path || d;
|
|
590
|
-
if (!path || typeof path !== 'string') return;
|
|
591
|
-
const clsItem = await WORK.get_item(path).catch(() => null);
|
|
592
|
-
if (!clsItem) return;
|
|
593
|
-
const unit = this.$pdp?.$item?.short || this.$pdp?.$item?.path || '';
|
|
594
|
-
const title = clsItem.DATA?.label || clsItem.label || clsItem.id || path.split('/').pop() || 'Операция';
|
|
595
|
-
const fmtNew = globalThis.__workClassPicker?.formatNewObjectLabel || globalThis.WORK?.formatNewObjectLabel;
|
|
596
|
-
const newLabel = typeof fmtNew === 'function' ? fmtNew(title) : `Новое ${title.toLowerCase()}`;
|
|
597
|
-
const nav = {
|
|
598
|
-
view: 'object',
|
|
599
|
-
create: true,
|
|
600
|
-
unit,
|
|
601
|
-
label: newLabel,
|
|
602
|
-
};
|
|
603
|
-
if (window.top && window.top !== window && typeof window.top.execute === 'function') {
|
|
604
|
-
await window.top.execute(clsItem, nav);
|
|
605
|
-
return;
|
|
606
|
-
}
|
|
607
|
-
let formHost = null;
|
|
608
|
-
for (let p = this; p; p = p.parentElement || p.domHost || p.getRootNode?.()?.host) {
|
|
609
|
-
if (typeof p.openInForm === 'function') {
|
|
610
|
-
formHost = p;
|
|
611
|
-
break;
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
if (!formHost) {
|
|
615
|
-
const pf = document.querySelector?.('pages-form');
|
|
616
|
-
formHost = pf?.$?.('work-form') || pf || document.querySelector?.('work-form');
|
|
617
|
-
}
|
|
618
|
-
if (formHost && typeof formHost.openInForm === 'function') {
|
|
619
|
-
await formHost.openInForm(clsItem, nav);
|
|
620
|
-
}
|
|
621
|
-
else if (typeof window.top?.execute === 'function') {
|
|
622
|
-
window.top.execute(clsItem, nav);
|
|
623
|
-
}
|
|
624
|
-
},
|
|
625
|
-
model: {
|
|
626
|
-
$def: '',
|
|
627
|
-
set(n) {
|
|
628
|
-
if (!n) return;
|
|
629
|
-
setUserPreferredModel(n);
|
|
630
|
-
},
|
|
631
|
-
},
|
|
632
|
-
get $saveKey(){
|
|
633
|
-
return this.$item?.short;
|
|
634
|
-
},
|
|
635
|
-
get modelItem(){
|
|
636
|
-
return this.model ? WORK.get_item(this.model) : null;
|
|
637
|
-
},
|
|
638
|
-
clear(e){
|
|
639
|
-
this.value = '';
|
|
640
|
-
this.files = [];
|
|
641
|
-
this.$pdp.replyTarget = null;
|
|
642
|
-
this.$pdp.files = [];
|
|
643
|
-
this.$('#ribbon').lastIdxHistory = -1;
|
|
644
|
-
this.focusInput();
|
|
645
|
-
},
|
|
646
|
-
$public:{
|
|
647
|
-
showDatePanel: {
|
|
648
|
-
$def: false,
|
|
649
|
-
$save: true
|
|
650
|
-
}
|
|
651
|
-
},
|
|
652
|
-
onBarSend(e){
|
|
653
|
-
if (this.skillSelectMode) {
|
|
654
|
-
this.value = '@' + this.$('skill-tree').focusedItem.name;
|
|
655
|
-
this.$('skill-tree').executed = true;
|
|
656
|
-
return;
|
|
657
|
-
}
|
|
658
|
-
this.send();
|
|
659
|
-
},
|
|
660
|
-
onBarStop() {
|
|
661
|
-
// Пока send в полёте — стоп не снимает ожидание карточки: это может быть
|
|
662
|
-
// второй клик по send, а не осознанный отказ от ожидания.
|
|
663
|
-
if (this._sending)
|
|
664
|
-
return;
|
|
665
|
-
this.awaitTask = false;
|
|
666
|
-
this._awaitingLogExpand = false;
|
|
667
|
-
},
|
|
668
|
-
async _onPromptKey(e){
|
|
669
|
-
e = e?.detail instanceof Event ? e.detail : e;
|
|
670
|
-
if (e.keyCode === 38 || e.code === 'ArrowUp') {
|
|
671
|
-
this.value = await this.$('chat-ribbon').getFromHistory(this.value, -1);
|
|
672
|
-
this.$('work-prompt-bar')?.selectInput();
|
|
673
|
-
}
|
|
674
|
-
else if (e.keyCode === 40 || e.code === 'ArrowDown') {
|
|
675
|
-
this.value = await this.$('chat-ribbon').getFromHistory(this.value, 1);
|
|
676
|
-
this.$('work-prompt-bar')?.selectInput();
|
|
677
|
-
}
|
|
678
|
-
},
|
|
679
|
-
value: {
|
|
680
|
-
$def: ''
|
|
681
|
-
},
|
|
682
|
-
replyTarget: {
|
|
683
|
-
$der: null,
|
|
684
|
-
set(n){
|
|
685
|
-
this.focusInput();
|
|
686
|
-
}
|
|
687
|
-
},
|
|
688
|
-
attached(){
|
|
689
|
-
this.async(()=>{
|
|
690
|
-
this.focusInput();
|
|
691
|
-
}, 100);
|
|
692
|
-
this.$pdp?._hydrateModel?.();
|
|
693
|
-
this._geo();
|
|
694
|
-
this._bindChatSocket();
|
|
695
|
-
},
|
|
696
|
-
detached() {
|
|
697
|
-
if (this._onWsChatMsg && globalThis.WORK?.chatEvents) {
|
|
698
|
-
globalThis.WORK.chatEvents.removeEventListener('chat:message', this._onWsChatMsg);
|
|
699
|
-
globalThis.WORK.chatEvents.removeEventListener('chat:action', this._onWsChatMsg);
|
|
700
|
-
this._onWsChatMsg = null;
|
|
701
|
-
}
|
|
702
|
-
},
|
|
703
|
-
_bindChatSocket() {
|
|
704
|
-
if (this._onWsChatMsg)
|
|
705
|
-
return;
|
|
706
|
-
globalThis.WORK.chatEvents ??= new EventTarget();
|
|
707
|
-
this._onWsChatMsg = (ev) => {
|
|
708
|
-
const d = ev?.detail;
|
|
709
|
-
const cur = this.$item;
|
|
710
|
-
if (!d || !cur)
|
|
711
|
-
return;
|
|
712
|
-
const curPath = String(cur.path || '/').replace(/\/+$/, '') || '/';
|
|
713
|
-
const hitTwin = d.kind === 'twin' && d.nodePath === curPath;
|
|
714
|
-
const hitDm = d.kind === 'dm' && cur.type === '$user' && (d.message?.sender === cur.id || d.message?.sender === WORK.uid);
|
|
715
|
-
const hitThread = d.threadId && this.$('#ribbon')?._threadId === d.threadId;
|
|
716
|
-
if (hitTwin || hitDm || hitThread) {
|
|
717
|
-
this.$('#ribbon')?.refreshFeed?.();
|
|
718
|
-
if (d.threadId && ev.type === 'chat:message') {
|
|
719
|
-
cur.fetch?.('chat_mark_read', { threadId: d.threadId })
|
|
720
|
-
?.then?.(res => WORK.applyChatReadLocal?.(res || { threadId: d.threadId, kind: d.kind, nodePath: curPath, peerId: cur.type === '$user' ? cur.id : '' }))
|
|
721
|
-
?.catch?.(() => {});
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
};
|
|
725
|
-
globalThis.WORK.chatEvents.addEventListener('chat:message', this._onWsChatMsg);
|
|
726
|
-
globalThis.WORK.chatEvents.addEventListener('chat:action', this._onWsChatMsg);
|
|
727
|
-
},
|
|
728
|
-
focusInput(){
|
|
729
|
-
this.$('work-prompt-bar')?.focusInput();
|
|
730
|
-
},
|
|
731
|
-
focusedItem: null,
|
|
732
|
-
feedMode: 'dialog',
|
|
733
|
-
showParticipants: false,
|
|
734
|
-
_canLocalFeed: false,
|
|
735
|
-
get participantsList() {
|
|
736
|
-
return Array.isArray(this.$pdp?.deptUsers) ? this.$pdp.deptUsers : [];
|
|
737
|
-
},
|
|
738
|
-
get participantsCount() {
|
|
739
|
-
return this.participantsList.length;
|
|
740
|
-
},
|
|
741
|
-
toggleParticipants() {
|
|
742
|
-
this.showParticipants = !this.showParticipants;
|
|
743
|
-
},
|
|
744
|
-
openParticipant(u) {
|
|
745
|
-
if (!u?.id || typeof window?.execute !== 'function')
|
|
746
|
-
return;
|
|
747
|
-
this.showParticipants = false;
|
|
748
|
-
window.execute(u);
|
|
749
|
-
},
|
|
750
|
-
get showFeedModeToggle() {
|
|
751
|
-
return Boolean(this.$item && this.$item.type !== '$user' && this._canLocalFeed);
|
|
752
|
-
},
|
|
753
|
-
async _refreshCanLocalFeed(item = this.$item) {
|
|
754
|
-
if (!item || item.type === '$user') {
|
|
755
|
-
this._canLocalFeed = false;
|
|
756
|
-
return;
|
|
757
|
-
}
|
|
758
|
-
if (globalThis.WORK?.DEV_MODE) {
|
|
759
|
-
this._canLocalFeed = true;
|
|
760
|
-
return;
|
|
761
|
-
}
|
|
762
|
-
const key = (item.path || '') + '|' + (item.id || '');
|
|
763
|
-
try {
|
|
764
|
-
const cached = item.myRoles;
|
|
765
|
-
const roles = await Promise.resolve(cached !== undefined ? cached : item.fetch?.('roles')).catch(() => []);
|
|
766
|
-
const curKey = (this.$item?.path || '') + '|' + (this.$item?.id || '');
|
|
767
|
-
if (curKey !== key)
|
|
768
|
-
return;
|
|
769
|
-
this._canLocalFeed = Array.isArray(roles) && roles.includes('BOSS');
|
|
770
|
-
}
|
|
771
|
-
catch {
|
|
772
|
-
const curKey = (this.$item?.path || '') + '|' + (this.$item?.id || '');
|
|
773
|
-
if (curKey === key)
|
|
774
|
-
this._canLocalFeed = false;
|
|
775
|
-
}
|
|
776
|
-
},
|
|
777
|
-
auditThreads: [],
|
|
778
|
-
auditSelectedId: '',
|
|
779
|
-
auditMessages: [],
|
|
780
|
-
setFeedMode(mode) {
|
|
781
|
-
const next = (mode === 'local' || mode === 'audit') && this.showFeedModeToggle ? mode : 'dialog';
|
|
782
|
-
if (this.feedMode === next)
|
|
783
|
-
return;
|
|
784
|
-
this.feedMode = next;
|
|
785
|
-
if (next === 'audit') {
|
|
786
|
-
this.loadAuditThreads();
|
|
787
|
-
return;
|
|
788
|
-
}
|
|
789
|
-
this.$('#ribbon')?.refreshFeed?.();
|
|
790
|
-
},
|
|
791
|
-
async loadAuditThreads() {
|
|
792
|
-
if (!this.$item?.fetch)
|
|
793
|
-
return;
|
|
794
|
-
try {
|
|
795
|
-
const list = await this.$item.fetch('chat_threads_list', { mode: 'audit' });
|
|
796
|
-
const raw = Array.isArray(list) ? list : [];
|
|
797
|
-
const uids = [...new Set(raw.flatMap(t => (t.participants || []).map(p => p.uid)).filter(Boolean))];
|
|
798
|
-
const users = uids.length && typeof WORK.usersByIds === 'function' ? await WORK.usersByIds(uids).catch(() => []) : [];
|
|
799
|
-
const nameMap = Object.fromEntries((users || []).filter(Boolean).map(u => [u.id, u.label || u.DATA?.label || u.id]));
|
|
800
|
-
this.auditThreads = raw.map(t => {
|
|
801
|
-
const peer = (t.participants || []).find(p => p.uid !== '$twin') || t.participants?.[0];
|
|
802
|
-
const roleHint = peer?.role === 'client' ? ' (Клиент)' : '';
|
|
803
|
-
return {
|
|
804
|
-
...t,
|
|
805
|
-
peerLabel: (nameMap[peer?.uid] || peer?.uid || t.title || t.id) + roleHint,
|
|
806
|
-
};
|
|
807
|
-
});
|
|
808
|
-
if (this.auditThreads.length && !this.auditSelectedId)
|
|
809
|
-
await this.openAuditThread(this.auditThreads[0]);
|
|
810
|
-
}
|
|
811
|
-
catch {
|
|
812
|
-
this.auditThreads = [];
|
|
813
|
-
}
|
|
814
|
-
},
|
|
815
|
-
async openAuditThread(thread) {
|
|
816
|
-
if (!thread?.id || !this.$item?.fetch)
|
|
817
|
-
return;
|
|
818
|
-
this.auditSelectedId = thread.id;
|
|
819
|
-
try {
|
|
820
|
-
const res = await this.$item.fetch('chat_messages_list', { threadId: thread.id, limit: 100 });
|
|
821
|
-
this.auditMessages = Array.isArray(res?.messages) ? res.messages : [];
|
|
822
|
-
}
|
|
823
|
-
catch {
|
|
824
|
-
this.auditMessages = [];
|
|
825
|
-
}
|
|
826
|
-
},
|
|
827
|
-
async resolveApprovalMsg(msg, action) {
|
|
828
|
-
if (!msg?.id || !this.auditSelectedId || !this.$item?.fetch)
|
|
829
|
-
return;
|
|
830
|
-
try {
|
|
831
|
-
await this.$item.fetch('chat_action', { threadId: this.auditSelectedId, messageId: msg.id, action });
|
|
832
|
-
await this.openAuditThread({ id: this.auditSelectedId });
|
|
833
|
-
}
|
|
834
|
-
catch { /* ignore */ }
|
|
835
|
-
},
|
|
836
|
-
async _ownCabinet() {
|
|
837
|
-
const uid = globalThis.WORK?.uid;
|
|
838
|
-
if (!uid || typeof globalThis.WORK?.get_item !== 'function')
|
|
839
|
-
return null;
|
|
840
|
-
return globalThis.WORK.get_item('/USERS//' + uid).catch(() => null);
|
|
841
|
-
},
|
|
842
|
-
_isAccessError(err) {
|
|
843
|
-
return /доступ запрещ|forbidden|\b403\b/i.test(String(err?.message || err || ''));
|
|
844
|
-
},
|
|
845
|
-
async _runWithCabinetFallback(fn) {
|
|
846
|
-
const primary = this.$pdp?.$item || this.$item;
|
|
847
|
-
return { target: primary, result: await fn(primary) };
|
|
848
|
-
},
|
|
849
|
-
$item: {
|
|
850
|
-
$def: null,
|
|
851
|
-
set(n) {
|
|
852
|
-
const changed = Boolean(this._prevItem && this._prevItem !== n);
|
|
853
|
-
this._prevItem = n;
|
|
854
|
-
this.feedMode = 'dialog';
|
|
855
|
-
this._canLocalFeed = false;
|
|
856
|
-
this._refreshCanLocalFeed(n);
|
|
857
|
-
if (changed)
|
|
858
|
-
this.$('#ribbon')?.refreshFeed?.();
|
|
859
|
-
}
|
|
860
|
-
},
|
|
861
|
-
taskItem: null,
|
|
862
|
-
data: null,
|
|
863
|
-
streams: {},
|
|
864
|
-
status: 'idle',
|
|
865
|
-
__microchatShell: true,
|
|
866
|
-
voiceOn: {
|
|
867
|
-
$def: false,
|
|
868
|
-
set(v) {
|
|
869
|
-
this.async(() => {
|
|
870
|
-
const bar = this.$('work-prompt-bar');
|
|
871
|
-
if (!v || !this._voice) {
|
|
872
|
-
bar?.setDialogLevel?.(0);
|
|
873
|
-
return;
|
|
874
|
-
}
|
|
875
|
-
this._voice.addEventListener('level', e => { if (this._voice?.state !== 'speaking') bar?.setDialogLevel?.(e.detail); });
|
|
876
|
-
this._voice.addEventListener('speechlevel', e => { if (this._voice?.state === 'speaking') bar?.setDialogLevel?.(e.detail); });
|
|
877
|
-
});
|
|
878
|
-
},
|
|
879
|
-
},
|
|
880
|
-
get canVoice() {
|
|
881
|
-
return !!(navigator.mediaDevices?.getUserMedia || window.SpeechRecognition || window.webkitSpeechRecognition);
|
|
882
|
-
},
|
|
883
|
-
toast(msg) {
|
|
884
|
-
ODA.showMessage?.(String(msg || ''));
|
|
885
|
-
},
|
|
886
|
-
async toggleVoice(on) {
|
|
887
|
-
const want = typeof on === 'boolean' ? on : !this.voiceOn;
|
|
888
|
-
if (!want) {
|
|
889
|
-
this._voice?.disable();
|
|
890
|
-
this.voiceOn = false;
|
|
891
|
-
return;
|
|
892
|
-
}
|
|
893
|
-
await Promise.all([
|
|
894
|
-
import('/$server/$folder/$file/$task/handlers/pages/form/file/$handler/ui/voice-ui.js'),
|
|
895
|
-
import('/$server/$folder/$file/$task/handlers/pages/form/file/$handler/ui/voice.js').then(m => { this._VoiceController = m.VoiceController; }),
|
|
896
|
-
]);
|
|
897
|
-
if (!this._VoiceController)
|
|
898
|
-
return;
|
|
899
|
-
this._voice ??= new this._VoiceController(this);
|
|
900
|
-
this.voiceOn = await this._voice.enable();
|
|
901
|
-
},
|
|
902
|
-
async sendVoiceText(text, { voice = true, interrupt = true, spokenText } = {}) {
|
|
903
|
-
text = String(text ?? '').trim();
|
|
904
|
-
if (!text)
|
|
905
|
-
return;
|
|
906
|
-
if (this.taskItem) {
|
|
907
|
-
let tz = '';
|
|
908
|
-
try { tz = Intl.DateTimeFormat().resolvedOptions().timeZone || ''; } catch { /* ignore */ }
|
|
909
|
-
const geo = await Promise.race([
|
|
910
|
-
Promise.resolve(this._geo?.()).catch(() => null),
|
|
911
|
-
new Promise(r => setTimeout(() => r(this._geoFix || null), 150)),
|
|
912
|
-
]);
|
|
913
|
-
const location = (geo && geo.lat != null && geo.lon != null)
|
|
914
|
-
? { lat: geo.lat, lon: geo.lon, ...(tz ? { tz } : {}) }
|
|
915
|
-
: (tz ? { tz } : null);
|
|
916
|
-
const payload = JSON.stringify({
|
|
917
|
-
prompt: text,
|
|
918
|
-
attachments: [],
|
|
919
|
-
...(location ? { location, ...(tz ? { tz } : {}) } : {}),
|
|
920
|
-
...(voice ? { voice: true } : {}),
|
|
921
|
-
...(interrupt ? { interrupt: true } : {}),
|
|
922
|
-
...(spokenText !== undefined ? { spokenText } : {}),
|
|
923
|
-
});
|
|
924
|
-
await this.taskItem.fetch('prompt', {}, payload);
|
|
925
|
-
return;
|
|
926
|
-
}
|
|
927
|
-
await this._createTask({ text, files: [], draft: { value: '', files: [], reply: null }, voice: true });
|
|
928
|
-
},
|
|
929
|
-
awaitTask: false,
|
|
930
|
-
ttsMode: {
|
|
931
|
-
$def: 'off',
|
|
932
|
-
$save: true,
|
|
933
|
-
},
|
|
934
|
-
async send(){
|
|
935
|
-
// Один send за раз: повторные Enter/клики игнорируются, иначе каждый клик создаст свою задачу-дубликат.
|
|
936
|
-
if (this._sending)
|
|
937
|
-
return;
|
|
938
|
-
const files = this.$('work-prompt-bar')?.files ?? this.files;
|
|
939
|
-
if (!(this.value || files.length)) return;
|
|
940
|
-
chatDebug('send: клик');
|
|
941
|
-
this.$('#ribbon').scrollDown = true;
|
|
942
|
-
|
|
943
|
-
const text = String(this.value ?? '').trim();
|
|
944
|
-
const list = [...files];
|
|
945
|
-
// Черновик на случай сбоя: поле очищается до сохранения — при ошибке вернуть текст и вложения.
|
|
946
|
-
const draft = { value: this.value, files: list, reply: this.$pdp.replyTarget };
|
|
947
|
-
this._sending = true;
|
|
948
|
-
|
|
949
|
-
try {
|
|
950
|
-
if (this.isAIMode) {
|
|
951
|
-
// экран «создаю задачу» — сразу, до любых запросов: человек видит, что процесс пошёл
|
|
952
|
-
this.clear();
|
|
953
|
-
await this._createTask({ text, files: list, draft });
|
|
954
|
-
} else {
|
|
955
|
-
const params = { encoding: 'utf-8' };
|
|
956
|
-
if (WORK.uid)
|
|
957
|
-
params.sender = WORK.uid;
|
|
958
|
-
if (this.$pdp.isPrivate && this.$pdp.$item.id !== WORK.uid)
|
|
959
|
-
params.receivers = [this.$pdp.$item.id];
|
|
960
|
-
else if (this.$pdp.receivers.length)
|
|
961
|
-
params.receivers = this.$pdp.receivers.map(u => u.id);
|
|
962
|
-
const uploadedPaths = [];
|
|
963
|
-
const isForeignDm = Boolean(this.$pdp.isPrivate && this.$pdp.$item?.id && this.$pdp.$item.id !== WORK.uid);
|
|
964
|
-
const runWrite = typeof this._runWithCabinetFallback === 'function'
|
|
965
|
-
? fn => this._runWithCabinetFallback(fn)
|
|
966
|
-
: async fn => ({ target: this.$pdp.$item, result: await fn(this.$pdp.$item) });
|
|
967
|
-
await runWrite(async target => {
|
|
968
|
-
uploadedPaths.length = 0;
|
|
969
|
-
const uploadTarget = isForeignDm ? ((await this._ownCabinet()) || target) : target;
|
|
970
|
-
if (list.length) {
|
|
971
|
-
const formData = new FormData();
|
|
972
|
-
for (const file of list)
|
|
973
|
-
formData.append('file', file, file.name);
|
|
974
|
-
const fileParams = (text || isForeignDm) ? { ...params, ignore_save_logs: true } : params;
|
|
975
|
-
const savedLogs = await uploadTarget.save_files(formData, fileParams);
|
|
976
|
-
const arr = Array.isArray(savedLogs) ? savedLogs : (savedLogs ? [savedLogs] : []);
|
|
977
|
-
for (const l of arr) {
|
|
978
|
-
const p = await pathOfLog(l);
|
|
979
|
-
if (p)
|
|
980
|
-
uploadedPaths.push(p.startsWith('/') ? p : '/' + p);
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
if (text && !isForeignDm) {
|
|
984
|
-
const msgParams = { ...params, message: text };
|
|
985
|
-
if (uploadedPaths.length)
|
|
986
|
-
msgParams.includes = JSON.stringify(uploadedPaths);
|
|
987
|
-
await target.fetch('save_message', msgParams);
|
|
988
|
-
}
|
|
989
|
-
const chatTarget = this.$pdp.$item || target;
|
|
990
|
-
if (chatTarget?.fetch && (text || uploadedPaths.length)) {
|
|
991
|
-
const chatPayload = {
|
|
992
|
-
kind: this.$pdp.isPrivate ? 'dm' : 'twin',
|
|
993
|
-
...(this.$pdp.isPrivate ? { peerId: this.$pdp.$item?.id || WORK.uid } : {}),
|
|
994
|
-
message: text,
|
|
995
|
-
attachments: uploadedPaths.map(p => ({ path: p, name: p.split('/').pop() || 'file' })),
|
|
996
|
-
};
|
|
997
|
-
await chatTarget.fetch('chat_send', {}, JSON.stringify(chatPayload))?.catch?.(() => {});
|
|
998
|
-
}
|
|
999
|
-
});
|
|
1000
|
-
this.clear();
|
|
1001
|
-
this.$('#ribbon')?.refreshFeed?.();
|
|
1002
|
-
}
|
|
1003
|
-
} catch (err) {
|
|
1004
|
-
console.warn('[chat] send', err);
|
|
1005
|
-
// Сбой — черновик не теряем: текст и вложения обратно в поле.
|
|
1006
|
-
this.value = draft.value;
|
|
1007
|
-
this.files = draft.files;
|
|
1008
|
-
this.$pdp.replyTarget = draft.reply;
|
|
1009
|
-
ODA.showMessage?.('Не удалось отправить: ' + (err?.message || err));
|
|
1010
|
-
this.focusInput();
|
|
1011
|
-
}
|
|
1012
|
-
finally {
|
|
1013
|
-
this._sending = false;
|
|
1014
|
-
}
|
|
1015
|
-
this.$('#ribbon').scrollDown = true;
|
|
1016
|
-
},
|
|
1017
|
-
_collectKnownLogKeys() {
|
|
1018
|
-
const ribbon = this.$('#ribbon');
|
|
1019
|
-
const known = new Set();
|
|
1020
|
-
for (const d of ribbon?.$$?.('chat-day') || []) {
|
|
1021
|
-
for (const it of d.logItems || []) {
|
|
1022
|
-
if (it?.id)
|
|
1023
|
-
known.add(String(it.id));
|
|
1024
|
-
const tk = taskKeyOf(it?.logRow?.path || it?.path || it?.id);
|
|
1025
|
-
if (tk)
|
|
1026
|
-
known.add(tk);
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
return known;
|
|
1030
|
-
},
|
|
1031
|
-
/**
|
|
1032
|
-
* Создание задачи: экран «создаю» → вложения → сохранение → явный запуск агента → карточка открыта по пути из ответа.
|
|
1033
|
-
* resume — задача уже создана (повтор запуска после сбоя), второй не создаётся.
|
|
1034
|
-
*/
|
|
1035
|
-
async _createTask({ text, files, draft, voice = false }) {
|
|
1036
|
-
this.awaitTask = true;
|
|
1037
|
-
this._awaitingLogExpand = false;
|
|
1038
|
-
this._awaitTaskPath = '';
|
|
1039
|
-
this._awaitTaskKey = '';
|
|
1040
|
-
this._awaitKnown = this._collectKnownLogKeys?.() || new Set();
|
|
1041
|
-
clearTimeout(this._awaitTimer);
|
|
1042
|
-
const item = this.$pdp.$item;
|
|
1043
|
-
try {
|
|
1044
|
-
const rawName = String(text || '').trim() || (files || []).map(f => f?.name).filter(Boolean).join(', ');
|
|
1045
|
-
const name = String(rawName).replace(/[<>:"/\\|?*\n\r]/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 90) || 'task';
|
|
1046
|
-
const useVoice = voice || !!this.voiceOn;
|
|
1047
|
-
let tz = '';
|
|
1048
|
-
try { tz = Intl.DateTimeFormat().resolvedOptions().timeZone || ''; } catch { /* ignore */ }
|
|
1049
|
-
this._geo?.();
|
|
1050
|
-
const root = globalThis.top || globalThis;
|
|
1051
|
-
let geo = this._geoFix || root.__workGeoFix || null;
|
|
1052
|
-
if (!geo) {
|
|
1053
|
-
try {
|
|
1054
|
-
const raw = globalThis.localStorage?.getItem?.('WORK.geo-fix');
|
|
1055
|
-
if (raw)
|
|
1056
|
-
geo = JSON.parse(raw);
|
|
1057
|
-
} catch { /* ignore */ }
|
|
1058
|
-
}
|
|
1059
|
-
const location = (geo && geo.lat != null && geo.lon != null)
|
|
1060
|
-
? { lat: geo.lat, lon: geo.lon, ...(tz ? { tz } : {}) }
|
|
1061
|
-
: (tz ? { tz } : null);
|
|
1062
|
-
const body = {
|
|
1063
|
-
name,
|
|
1064
|
-
...(text ? {} : { prompt: '' }),
|
|
1065
|
-
created: Date.now(),
|
|
1066
|
-
items: [],
|
|
1067
|
-
...(location ? { location, ...(tz ? { tz } : {}) } : {}),
|
|
1068
|
-
...(useVoice ? { voice: true } : {}),
|
|
1069
|
-
};
|
|
1070
|
-
if (this.model)
|
|
1071
|
-
body.model = this.model;
|
|
1072
|
-
const params = {
|
|
1073
|
-
encoding: 'utf-8',
|
|
1074
|
-
...(text ? {} : { prompt: '' }),
|
|
1075
|
-
...(location ? { location: JSON.stringify(location), ...(tz ? { tz } : {}) } : {}),
|
|
1076
|
-
...(useVoice ? { voice: true } : {}),
|
|
1077
|
-
};
|
|
1078
|
-
if (globalThis.WORK?.uid)
|
|
1079
|
-
params.sender = globalThis.WORK.uid;
|
|
1080
|
-
const canLookupTask = typeof globalThis.WORK?.get_item === 'function';
|
|
1081
|
-
const runWrite = typeof this._runWithCabinetFallback === 'function'
|
|
1082
|
-
? fn => this._runWithCabinetFallback(fn)
|
|
1083
|
-
: async fn => ({ target: item, result: await fn(item) });
|
|
1084
|
-
const { target: writeTarget, result: log } = await runWrite(async targetItem => {
|
|
1085
|
-
const saveParams = { ...params };
|
|
1086
|
-
if (files.length && !canLookupTask) {
|
|
1087
|
-
const preAttachments = [];
|
|
1088
|
-
await Promise.all(files.map(async file => {
|
|
1089
|
-
const fLog = await targetItem.save_file(file, { encoding: 'utf-8', ignore_save_logs: true });
|
|
1090
|
-
const fPath = await pathOfLog(fLog);
|
|
1091
|
-
if (fPath)
|
|
1092
|
-
preAttachments.push({ path: fPath.startsWith('/') ? fPath : '/' + fPath, name: file.name });
|
|
1093
|
-
}));
|
|
1094
|
-
if (preAttachments.length) {
|
|
1095
|
-
saveParams.includes = JSON.stringify(preAttachments.map(a => a.path));
|
|
1096
|
-
saveParams.attachments = JSON.stringify(preAttachments);
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
// Сначала создаём саму задачу, чтобы прикреплённые и создаваемые файлы размещались в папке этого таска
|
|
1100
|
-
if (files.length && canLookupTask)
|
|
1101
|
-
saveParams.skip_file_handler = true;
|
|
1102
|
-
return targetItem.save_file(new File([JSON.stringify(body, null, 2)], name + '.task', { type: 'application/json' }), saveParams);
|
|
1103
|
-
});
|
|
1104
|
-
const path = await pathOfLog(log);
|
|
1105
|
-
if (path && files.length && canLookupTask) {
|
|
1106
|
-
const createdTask = await globalThis.WORK.get_item(path).catch(() => null);
|
|
1107
|
-
const targetHolder = createdTask || writeTarget || item;
|
|
1108
|
-
const attachments = [];
|
|
1109
|
-
await Promise.all(files.map(async file => {
|
|
1110
|
-
const fLog = await targetHolder.save_file(file, { encoding: 'utf-8', ignore_save_logs: true, mainContext: path });
|
|
1111
|
-
const fPath = await pathOfLog(fLog);
|
|
1112
|
-
if (fPath)
|
|
1113
|
-
attachments.push({ path: fPath.startsWith('/') ? fPath : '/' + fPath, name: file.name });
|
|
1114
|
-
}));
|
|
1115
|
-
if (attachments.length && createdTask) {
|
|
1116
|
-
const includePaths = attachments.map(a => a.path);
|
|
1117
|
-
await (writeTarget || item).fetch?.('append_log_includes', { entryPath: path, includePaths })?.catch?.(() => {});
|
|
1118
|
-
await createdTask.fetch?.('prompt', {}, JSON.stringify({ prompt: text, attachments }))?.catch?.(() => {});
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
if (path) {
|
|
1122
|
-
const threadItem = this.$pdp?.$item || item;
|
|
1123
|
-
threadItem?.fetch?.('chat_send', {}, JSON.stringify({
|
|
1124
|
-
kind: threadItem.type === '$user' ? 'dm' : 'twin',
|
|
1125
|
-
...(threadItem.type === '$user' ? { peerId: threadItem.id } : {}),
|
|
1126
|
-
message: text,
|
|
1127
|
-
taskPath: path,
|
|
1128
|
-
}))?.catch?.(() => {});
|
|
1129
|
-
this._awaitTaskPath = String(path);
|
|
1130
|
-
this._awaitTaskKey = taskKeyOf(path);
|
|
1131
|
-
await this._openCreated(path);
|
|
1132
|
-
if (useVoice && canLookupTask) {
|
|
1133
|
-
const createdTask = await globalThis.WORK.get_item(path).catch(() => null);
|
|
1134
|
-
if (createdTask)
|
|
1135
|
-
this._bindChatVoiceTask(createdTask);
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
else {
|
|
1139
|
-
this.awaitTask = true;
|
|
1140
|
-
this._awaitNewTask('');
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
catch (err) {
|
|
1144
|
-
console.warn('[chat] создание задачи', err);
|
|
1145
|
-
this.awaitTask = false;
|
|
1146
|
-
this._awaitingLogExpand = false;
|
|
1147
|
-
ODA.showMessage?.('Не удалось отправить: ' + (err?.message || err));
|
|
1148
|
-
this.value = draft.value;
|
|
1149
|
-
this.files = draft.files;
|
|
1150
|
-
this.$pdp.replyTarget = draft.reply;
|
|
1151
|
-
this.focusInput();
|
|
1152
|
-
}
|
|
1153
|
-
},
|
|
1154
|
-
/**
|
|
1155
|
-
* Карточка созданной задачи — раскрыта сразу по пути из ответа сервера: .task-файл кладётся в ленту дня
|
|
1156
|
-
* (chat-day.adoptTask), события ленты не ждём. Не вышло — прежний путь: ждать запись ленты (_awaitNewTask).
|
|
1157
|
-
*/
|
|
1158
|
-
async _openCreated(path) {
|
|
1159
|
-
const ribbon = this.$('#ribbon');
|
|
1160
|
-
const day = taskDayOf(path) || new Date().toLocalDay();
|
|
1161
|
-
try {
|
|
1162
|
-
if (!ribbon.dateList.includes(day)) {
|
|
1163
|
-
ribbon.dateList = [...ribbon.dateList, day].sort();
|
|
1164
|
-
ribbon.render();
|
|
1165
|
-
}
|
|
1166
|
-
let dayEl = null;
|
|
1167
|
-
for (let i = 0; i < 40 && !dayEl; i++) {
|
|
1168
|
-
dayEl = [...(ribbon.$$('chat-day') || [])].find(d => d.day === day);
|
|
1169
|
-
if (!dayEl)
|
|
1170
|
-
await sleep(50);
|
|
1171
|
-
}
|
|
1172
|
-
if (!dayEl)
|
|
1173
|
-
throw new Error('нет дня в ленте: ' + day);
|
|
1174
|
-
const file = await WORK.get_item(path);
|
|
1175
|
-
if (!file || Array.isArray(file))
|
|
1176
|
-
throw new Error('нет файла задачи: ' + path);
|
|
1177
|
-
await dayEl.adoptTask(file);
|
|
1178
|
-
this.awaitTask = false;
|
|
1179
|
-
this._awaitingLogExpand = false;
|
|
1180
|
-
this._awaitTaskPath = '';
|
|
1181
|
-
this._awaitTaskKey = '';
|
|
1182
|
-
this._awaitKnown = null;
|
|
1183
|
-
clearTimeout(this._awaitTimer);
|
|
1184
|
-
}
|
|
1185
|
-
catch (err) {
|
|
1186
|
-
console.warn('[chat] открыть созданную задачу напрямую не вышло — ждём запись ленты:', err?.message || err);
|
|
1187
|
-
if (!this._awaitKnown?.size)
|
|
1188
|
-
this._awaitKnown = this._collectKnownLogKeys();
|
|
1189
|
-
this.awaitTask = true;
|
|
1190
|
-
this._awaitNewTask(path);
|
|
1191
|
-
}
|
|
1192
|
-
},
|
|
1193
|
-
_bindChatVoiceTask(task) {
|
|
1194
|
-
if (this.taskItem && this._chatTaskH) {
|
|
1195
|
-
for (const [k, fn] of Object.entries(this._chatTaskH))
|
|
1196
|
-
this.taskItem.unlisten?.(k, fn);
|
|
1197
|
-
}
|
|
1198
|
-
this.taskItem = task;
|
|
1199
|
-
this.streams = {};
|
|
1200
|
-
if (!task)
|
|
1201
|
-
return;
|
|
1202
|
-
const reload = async () => {
|
|
1203
|
-
try {
|
|
1204
|
-
const raw = await task.load();
|
|
1205
|
-
const data = typeof raw === 'string' ? JSON.parse(raw || '{}') : (raw || {});
|
|
1206
|
-
this.data = data;
|
|
1207
|
-
this.status = data.status || 'idle';
|
|
1208
|
-
this._voice?.onData(data);
|
|
1209
|
-
}
|
|
1210
|
-
catch { /* ignore */ }
|
|
1211
|
-
};
|
|
1212
|
-
this._chatTaskH = {
|
|
1213
|
-
'changed': () => reload(),
|
|
1214
|
-
'chat.done': () => reload(),
|
|
1215
|
-
'task.state': e => {
|
|
1216
|
-
const s = e.detail?.value?.status;
|
|
1217
|
-
if (s)
|
|
1218
|
-
this.status = s;
|
|
1219
|
-
},
|
|
1220
|
-
'task.delta': e => {
|
|
1221
|
-
const d = e.detail?.value;
|
|
1222
|
-
if (!d?.item || !d.token)
|
|
1223
|
-
return;
|
|
1224
|
-
const cur = this.streams[d.item] || {};
|
|
1225
|
-
const field = d.field === 'reasoning' ? 'reasoning' : 'content';
|
|
1226
|
-
this.streams = { ...this.streams, [d.item]: { ...cur, [field]: (cur[field] || '') + d.token } };
|
|
1227
|
-
this.status = 'running';
|
|
1228
|
-
this._voice?.onDelta({ item: d.item, field });
|
|
1229
|
-
},
|
|
1230
|
-
};
|
|
1231
|
-
for (const [k, fn] of Object.entries(this._chatTaskH))
|
|
1232
|
-
task.listen?.(k, fn);
|
|
1233
|
-
reload();
|
|
1234
|
-
},
|
|
1235
|
-
/**
|
|
1236
|
-
* Новая задача сохранена: день — из пути файла (…/YYYY-MM-DD/….task), а не из часов браузера.
|
|
1237
|
-
* Нет дня в ленте — добавить (chat-day раскроет карточку, пока awaitTask). Страховка: 15 с — снять ожидание.
|
|
1238
|
-
* _awaitTaskKey — имя файла задачи: точный ключ карточки (chat-task.js), не зависит от времени и префикса пути.
|
|
1239
|
-
*/
|
|
1240
|
-
_awaitNewTask(path) {
|
|
1241
|
-
const day = taskDayOf(path);
|
|
1242
|
-
const ribbon = this.$('#ribbon');
|
|
1243
|
-
if (day && ribbon && !ribbon.dateList.includes(day)) {
|
|
1244
|
-
ribbon.dateList = [...ribbon.dateList, day].sort();
|
|
1245
|
-
ribbon.render();
|
|
1246
|
-
}
|
|
1247
|
-
this._awaitTaskPath = String(path || '');
|
|
1248
|
-
this._awaitTaskKey = taskKeyOf(path);
|
|
1249
|
-
this._awaitingLogExpand = true;
|
|
1250
|
-
// Ретрай: вызываем _expandCreatedTask на всех видимых днях (найдёт по времени).
|
|
1251
|
-
for (const el of ribbon?.$$?.('chat-day') || [])
|
|
1252
|
-
el?._expandCreatedTask?.();
|
|
1253
|
-
clearTimeout(this._awaitTimer);
|
|
1254
|
-
this._awaitTimer = setTimeout(() => {
|
|
1255
|
-
if (!this.awaitTask)
|
|
1256
|
-
return;
|
|
1257
|
-
this.awaitTask = false;
|
|
1258
|
-
this._awaitingLogExpand = false;
|
|
1259
|
-
this._awaitTaskPath = '';
|
|
1260
|
-
this._awaitTaskKey = '';
|
|
1261
|
-
this._awaitKnown = null;
|
|
1262
|
-
ODA.showMessage?.('Задача создана' + (path ? ': ' + path : '') + ' — карточка не появилась в ленте, откройте из журнала');
|
|
1263
|
-
}, 15000);
|
|
1264
|
-
},
|
|
1265
|
-
/**
|
|
1266
|
-
* Геопозиция для запроса: уже известная (30 минут) или запрашивается при открытии чата. Отправку она не держит:
|
|
1267
|
-
* getCurrentPosition не имеет тайм-аута, пока человек не ответил на запрос разрешения, — свои 6 с; отказ помним 30 минут.
|
|
1268
|
-
*/
|
|
1269
|
-
_geo() {
|
|
1270
|
-
const now = Date.now();
|
|
1271
|
-
const TTL = 30 * 60 * 1000;
|
|
1272
|
-
if (this._geoFix && now - (this._geoFix.at || 0) < TTL)
|
|
1273
|
-
return this._geoFix;
|
|
1274
|
-
this._geoFix = null;
|
|
1275
|
-
if (!navigator.geolocation || (this._geoDeniedAt && now - this._geoDeniedAt < TTL))
|
|
1276
|
-
return null;
|
|
1277
|
-
if (this._geoWait)
|
|
1278
|
-
return this._geoWait;
|
|
1279
|
-
let finished = false;
|
|
1280
|
-
const promise = new Promise(resolve => {
|
|
1281
|
-
const finish = (pos, denied = false) => {
|
|
1282
|
-
if (finished)
|
|
1283
|
-
return;
|
|
1284
|
-
finished = true;
|
|
1285
|
-
clearTimeout(timer);
|
|
1286
|
-
this._geoWait = null;
|
|
1287
|
-
if (pos) {
|
|
1288
|
-
this._geoFix = pos;
|
|
1289
|
-
try {
|
|
1290
|
-
const root = globalThis.top || globalThis;
|
|
1291
|
-
root.__workGeoFix = pos;
|
|
1292
|
-
globalThis.__workGeoFix = pos;
|
|
1293
|
-
globalThis.localStorage?.setItem?.('WORK.geo-fix', JSON.stringify(pos));
|
|
1294
|
-
} catch { /* ignore */ }
|
|
1295
|
-
}
|
|
1296
|
-
if (denied)
|
|
1297
|
-
this._geoDeniedAt = Date.now();
|
|
1298
|
-
resolve(pos);
|
|
1299
|
-
};
|
|
1300
|
-
const timer = setTimeout(() => {
|
|
1301
|
-
chatDebug('геопозиция: ответа нет');
|
|
1302
|
-
finish(null);
|
|
1303
|
-
}, 6000);
|
|
1304
|
-
navigator.geolocation.getCurrentPosition(
|
|
1305
|
-
p => finish({ lat: p.coords.latitude, lon: p.coords.longitude, at: Date.now() }),
|
|
1306
|
-
err => {
|
|
1307
|
-
chatDebug('геопозиция недоступна:', err?.message || err);
|
|
1308
|
-
finish(null, err?.code === 1);
|
|
1309
|
-
},
|
|
1310
|
-
{ enableHighAccuracy: false, maximumAge: 300000, timeout: 4000 }
|
|
1311
|
-
);
|
|
1312
|
-
});
|
|
1313
|
-
// колбэк мог сработать синхронно (finished) — тогда запоминать ожидание нельзя: оно залипло бы навсегда
|
|
1314
|
-
if (!finished)
|
|
1315
|
-
this._geoWait = promise;
|
|
1316
|
-
return promise;
|
|
1317
|
-
},
|
|
1318
|
-
});
|
|
1319
|
-
ODA({is: 'chat-ribbon',
|
|
1320
|
-
template:/* html */`
|
|
1321
|
-
<style>
|
|
1322
|
-
:host{
|
|
1323
|
-
position: relative;
|
|
1324
|
-
@apply --light;
|
|
1325
|
-
@apply --vertical;
|
|
1326
|
-
@apply --flex;
|
|
1327
|
-
overflow-x: hidden;
|
|
1328
|
-
overflow-y: auto;
|
|
1329
|
-
scroll-behavior: smooth;
|
|
1330
|
-
flex-direction: column-reverse;
|
|
1331
|
-
background: transparent;
|
|
1332
|
-
--chat-card-max: {{ribbonHeight > 0 ? Math.round(ribbonHeight * 0.9) + 'px' : '90vh'}};
|
|
1333
|
-
}
|
|
1334
|
-
#ribbon{
|
|
1335
|
-
overflow: visible;
|
|
1336
|
-
height: max-content;
|
|
1337
|
-
@apply --vertical;
|
|
1338
|
-
position: relative;
|
|
1339
|
-
gap: 2px;
|
|
1340
|
-
}
|
|
1341
|
-
</style>
|
|
1342
|
-
<div id="ribbon" vertical flex>
|
|
1343
|
-
<div flex></div>
|
|
1344
|
-
<chat-day ~for="dates" :day="$for.item"></chat-day>
|
|
1345
|
-
</div>
|
|
1346
|
-
|
|
1347
|
-
`,
|
|
1348
|
-
$item: {
|
|
1349
|
-
$def: null,
|
|
1350
|
-
set(n) {
|
|
1351
|
-
if (this._prevRibbonItem && this._prevRibbonItem !== n) {
|
|
1352
|
-
this._prevRibbonItem = n;
|
|
1353
|
-
this.refreshFeed();
|
|
1354
|
-
}
|
|
1355
|
-
else {
|
|
1356
|
-
this._prevRibbonItem = n;
|
|
1357
|
-
}
|
|
1358
|
-
}
|
|
1359
|
-
},
|
|
1360
|
-
ribbonHeight: 0,
|
|
1361
|
-
attached() {
|
|
1362
|
-
this.async(() => {
|
|
1363
|
-
this.ribbonHeight = this.clientHeight - 8;
|
|
1364
|
-
});
|
|
1365
|
-
},
|
|
1366
|
-
get lastDay(){
|
|
1367
|
-
return this.$$('chat-day').last;
|
|
1368
|
-
},
|
|
1369
|
-
lastIdxHistory: -1,
|
|
1370
|
-
async getFromHistory(value, direction = -1){
|
|
1371
|
-
let history = await this.history;
|
|
1372
|
-
let lastInHistory = history[this.lastIdxHistory];
|
|
1373
|
-
if(value && value != lastInHistory)
|
|
1374
|
-
return value;
|
|
1375
|
-
let idx = this.lastIdxHistory + direction;
|
|
1376
|
-
if(idx < 0)
|
|
1377
|
-
idx = history.length - 1;
|
|
1378
|
-
else if(idx > history.length - 1)
|
|
1379
|
-
idx = 0;
|
|
1380
|
-
this.lastIdxHistory = idx;
|
|
1381
|
-
return history[idx];
|
|
1382
|
-
},
|
|
1383
|
-
get history(){
|
|
1384
|
-
return Promise.resolve(this.lastDay?.logs).then(async items=>{
|
|
1385
|
-
if (!Array.isArray(items))
|
|
1386
|
-
return [];
|
|
1387
|
-
const result = [];
|
|
1388
|
-
for (const file of items) {
|
|
1389
|
-
if (typeof file?.load !== 'function')
|
|
1390
|
-
continue;
|
|
1391
|
-
let raw;
|
|
1392
|
-
try {
|
|
1393
|
-
raw = await file.load();
|
|
1394
|
-
}
|
|
1395
|
-
catch {
|
|
1396
|
-
continue;
|
|
1397
|
-
}
|
|
1398
|
-
const body = typeof raw === 'string' ? JSON.parse(raw) : raw;
|
|
1399
|
-
const ext = body?.ext || body?.path?.split('/').pop()?.split('.').pop();
|
|
1400
|
-
if (ext !== 'txt' && ext !== 'prompt' && ext !== 'msg')
|
|
1401
|
-
continue;
|
|
1402
|
-
const text = body.content != null ? String(body.content) : '';
|
|
1403
|
-
if (text && !result.has(text))
|
|
1404
|
-
result.push(text);
|
|
1405
|
-
}
|
|
1406
|
-
return result;
|
|
1407
|
-
})
|
|
1408
|
-
},
|
|
1409
|
-
$listeners:{
|
|
1410
|
-
scroll(e){
|
|
1411
|
-
if (this.clientHeight <= 0 || this._restoringScroll || this._wasHidden)
|
|
1412
|
-
return;
|
|
1413
|
-
this._savedScrollTop = this.scrollTop;
|
|
1414
|
-
const down = this.scrollTop > -10;
|
|
1415
|
-
if (this.scrollDown === down)
|
|
1416
|
-
return;
|
|
1417
|
-
this.scrollDown = down;
|
|
1418
|
-
this.render();
|
|
1419
|
-
},
|
|
1420
|
-
resize(){
|
|
1421
|
-
if (this.clientHeight <= 0) {
|
|
1422
|
-
this._wasHidden = true;
|
|
1423
|
-
return;
|
|
1424
|
-
}
|
|
1425
|
-
const nextHeight = this.clientHeight - 8;
|
|
1426
|
-
if (nextHeight > 0 && this.ribbonHeight !== nextHeight)
|
|
1427
|
-
this.ribbonHeight = nextHeight;
|
|
1428
|
-
if (this._wasHidden) {
|
|
1429
|
-
this._wasHidden = false;
|
|
1430
|
-
this.restoreScrollPosition();
|
|
1431
|
-
}
|
|
1432
|
-
}
|
|
1433
|
-
},
|
|
1434
|
-
scrollDown: true,
|
|
1435
|
-
_savedScrollTop: 0,
|
|
1436
|
-
_wasHidden: false,
|
|
1437
|
-
_restoringScroll: false,
|
|
1438
|
-
restoreScrollPosition(targetTop = this._savedScrollTop) {
|
|
1439
|
-
if (typeof targetTop !== 'number' || this.clientHeight <= 0)
|
|
1440
|
-
return;
|
|
1441
|
-
this._wasHidden = false;
|
|
1442
|
-
this._restoringScroll = true;
|
|
1443
|
-
const apply = () => {
|
|
1444
|
-
if (this.clientHeight <= 0)
|
|
1445
|
-
return;
|
|
1446
|
-
const prevBehavior = this.style.scrollBehavior;
|
|
1447
|
-
this.style.scrollBehavior = 'auto';
|
|
1448
|
-
this.scrollTop = targetTop;
|
|
1449
|
-
this.style.scrollBehavior = prevBehavior;
|
|
1450
|
-
};
|
|
1451
|
-
apply();
|
|
1452
|
-
requestAnimationFrame(() => {
|
|
1453
|
-
apply();
|
|
1454
|
-
this._restoringScroll = false;
|
|
1455
|
-
});
|
|
1456
|
-
},
|
|
1457
|
-
get ribbon(){
|
|
1458
|
-
return this;
|
|
1459
|
-
},
|
|
1460
|
-
dateList: [],
|
|
1461
|
-
_datesWatch: null,
|
|
1462
|
-
_lastRole: '',
|
|
1463
|
-
_listenedSource: null,
|
|
1464
|
-
get activeRole() {
|
|
1465
|
-
return this.$item?.role || 'USER';
|
|
1466
|
-
},
|
|
1467
|
-
get isLocalFeed() {
|
|
1468
|
-
return this.$pdp?.feedMode === 'local';
|
|
1469
|
-
},
|
|
1470
|
-
get isDialogFeed() {
|
|
1471
|
-
return !this.isLocalFeed && this.$pdp?.feedMode !== 'audit';
|
|
1472
|
-
},
|
|
1473
|
-
_threadId: '',
|
|
1474
|
-
_threadMessages: [],
|
|
1475
|
-
_threadMessagesByDay: null,
|
|
1476
|
-
_localDayOf(ms) {
|
|
1477
|
-
const dt = new Date(Number(ms) || Date.now());
|
|
1478
|
-
if (typeof dt.toLocalDay === 'function')
|
|
1479
|
-
return dt.toLocalDay();
|
|
1480
|
-
const y = dt.getFullYear();
|
|
1481
|
-
const m = String(dt.getMonth() + 1).padStart(2, '0');
|
|
1482
|
-
const d = String(dt.getDate()).padStart(2, '0');
|
|
1483
|
-
return `${y}-${m}-${d}`;
|
|
1484
|
-
},
|
|
1485
|
-
threadMessagesForDay(day) {
|
|
1486
|
-
if (!day || !(this._threadMessagesByDay instanceof Map))
|
|
1487
|
-
return [];
|
|
1488
|
-
return this._threadMessagesByDay.get(day) || [];
|
|
1489
|
-
},
|
|
1490
|
-
async _resolveLogsSource() {
|
|
1491
|
-
return this.$item || null;
|
|
1492
|
-
},
|
|
1493
|
-
_syncSourceListeners(source) {
|
|
1494
|
-
if (this._listenedSource === source)
|
|
1495
|
-
return;
|
|
1496
|
-
if (this._listenedSource && this._listenedSource !== this.$item)
|
|
1497
|
-
this._listenedSource.unlisten?.('changed', this.onChanged);
|
|
1498
|
-
this._listenedSource = source || null;
|
|
1499
|
-
if (source && source !== this.$item)
|
|
1500
|
-
source.listen?.('changed', this.onChanged);
|
|
1501
|
-
},
|
|
1502
|
-
async refreshFeed() {
|
|
1503
|
-
this.dateList = [];
|
|
1504
|
-
await this.refreshDates(true);
|
|
1505
|
-
for (const dayEl of this.$$('chat-day') || []) {
|
|
1506
|
-
dayEl._logsInit = false;
|
|
1507
|
-
dayEl._ensureLogsInit?.();
|
|
1508
|
-
}
|
|
1509
|
-
},
|
|
1510
|
-
async refreshDates(force = false){
|
|
1511
|
-
if (!this.$item)
|
|
1512
|
-
return false;
|
|
1513
|
-
const curRole = this.activeRole;
|
|
1514
|
-
if (this._lastRole && this._lastRole !== curRole) {
|
|
1515
|
-
this.dateList = [];
|
|
1516
|
-
}
|
|
1517
|
-
this._lastRole = curRole;
|
|
1518
|
-
const source = (await this._resolveLogsSource()) || this.$item;
|
|
1519
|
-
this._syncSourceListeners(source);
|
|
1520
|
-
source.invalidate?.('logs_dates');
|
|
1521
|
-
const logsPromise = source.fetch('logs', {
|
|
1522
|
-
mode: 'dates',
|
|
1523
|
-
nonEmpty: 1,
|
|
1524
|
-
...(this.isLocalFeed ? { local: 1, feedMode: 'local' } : { feedMode: 'dialog' }),
|
|
1525
|
-
role: curRole,
|
|
1526
|
-
uid: WORK.uid || '',
|
|
1527
|
-
}).catch(() => []);
|
|
1528
|
-
const threadPromise = this.isDialogFeed && typeof this.$item.fetch === 'function'
|
|
1529
|
-
? this.$item.fetch('chat_messages_list', {
|
|
1530
|
-
kind: this.$item.type === '$user' ? 'dm' : 'twin',
|
|
1531
|
-
...(this.$item.type === '$user' ? { peerId: this.$item.id } : {}),
|
|
1532
|
-
limit: 200,
|
|
1533
|
-
}).catch(() => null)
|
|
1534
|
-
: Promise.resolve(null);
|
|
1535
|
-
|
|
1536
|
-
const [rawDates, threadRes] = await Promise.all([logsPromise, threadPromise]);
|
|
1537
|
-
// dates на сервере — по убыванию; в ленте дни — от старых к новым.
|
|
1538
|
-
const dateSet = new Set((Array.isArray(rawDates) ? rawDates : []).slice().reverse());
|
|
1539
|
-
const byDay = new Map();
|
|
1540
|
-
const msgs = Array.isArray(threadRes?.messages) ? threadRes.messages : [];
|
|
1541
|
-
this._threadId = threadRes?.thread?.id || '';
|
|
1542
|
-
this._threadMessages = msgs;
|
|
1543
|
-
for (const msg of msgs) {
|
|
1544
|
-
const d = this._localDayOf(msg.created);
|
|
1545
|
-
if (!d) continue;
|
|
1546
|
-
dateSet.add(d);
|
|
1547
|
-
let arr = byDay.get(d);
|
|
1548
|
-
if (!arr) {
|
|
1549
|
-
arr = [];
|
|
1550
|
-
byDay.set(d, arr);
|
|
1551
|
-
}
|
|
1552
|
-
arr.push(msg);
|
|
1553
|
-
}
|
|
1554
|
-
this._threadMessagesByDay = byDay;
|
|
1555
|
-
const curPath = String(this.$item.path || '/').replace(/\/+$/, '') || '/';
|
|
1556
|
-
const localUnread = this.$item.type === '$user'
|
|
1557
|
-
? (Number(WORK.chatUnread?.byPeer?.[this.$item.id]) || 0)
|
|
1558
|
-
: (Number(WORK.chatUnread?.byNode?.[curPath]) || 0);
|
|
1559
|
-
if ((threadRes?.thread?.unreadCount > 0 || localUnread > 0) && threadRes?.thread?.id) {
|
|
1560
|
-
const fallbackInfo = {
|
|
1561
|
-
threadId: threadRes.thread.id,
|
|
1562
|
-
kind: this.$item.type === '$user' ? 'dm' : 'twin',
|
|
1563
|
-
nodePath: curPath,
|
|
1564
|
-
peerId: this.$item.type === '$user' ? this.$item.id : '',
|
|
1565
|
-
};
|
|
1566
|
-
this.$item.fetch?.('chat_mark_read', { threadId: threadRes.thread.id })
|
|
1567
|
-
?.then?.(res => WORK.applyChatReadLocal?.(res?.threadId ? res : fallbackInfo))
|
|
1568
|
-
?.catch?.(() => {});
|
|
1569
|
-
WORK.applyChatReadLocal?.(fallbackInfo);
|
|
1570
|
-
}
|
|
1571
|
-
let dates = [...dateSet].sort();
|
|
1572
|
-
// Пока создаётся новая задача (awaitTask), не сбрасываем локально добавленный _openCreated день
|
|
1573
|
-
if (!force && this.$pdp?.awaitTask && Array.isArray(this.dateList)) {
|
|
1574
|
-
for (const d of this.dateList) {
|
|
1575
|
-
if (d && !dates.includes(d))
|
|
1576
|
-
dates.push(d);
|
|
1577
|
-
}
|
|
1578
|
-
dates.sort();
|
|
1579
|
-
}
|
|
1580
|
-
const prevDates = Array.isArray(this.dateList) ? this.dateList : [];
|
|
1581
|
-
if (prevDates.length !== dates.length || prevDates.some((d, i) => d !== dates[i])) {
|
|
1582
|
-
this.dateList = dates;
|
|
1583
|
-
this.render();
|
|
1584
|
-
return true;
|
|
1585
|
-
}
|
|
1586
|
-
return false;
|
|
1587
|
-
},
|
|
1588
|
-
get onChanged() {
|
|
1589
|
-
return () => this.refreshDates();
|
|
1590
|
-
},
|
|
1591
|
-
_ensureDatesWatch(){
|
|
1592
|
-
if (this._datesWatch) return this._datesWatch;
|
|
1593
|
-
this._datesWatch = this.refreshDates().then(()=>{
|
|
1594
|
-
this.$item?.listen?.('changed', this.onChanged);
|
|
1595
|
-
});
|
|
1596
|
-
if (!this._rolePollTimer) {
|
|
1597
|
-
this._rolePollTimer = setInterval(() => {
|
|
1598
|
-
if (this.$item && this._lastRole && this.activeRole !== this._lastRole) {
|
|
1599
|
-
this.$pdp?._refreshCanLocalFeed?.();
|
|
1600
|
-
this.refreshFeed();
|
|
1601
|
-
}
|
|
1602
|
-
}, 400);
|
|
1603
|
-
}
|
|
1604
|
-
return this._datesWatch;
|
|
1605
|
-
},
|
|
1606
|
-
get dates(){
|
|
1607
|
-
this._ensureDatesWatch();
|
|
1608
|
-
return this.dateList;
|
|
1609
|
-
},
|
|
1610
|
-
detached() {
|
|
1611
|
-
this.$item?.unlisten?.('changed', this.onChanged);
|
|
1612
|
-
if (this._listenedSource && this._listenedSource !== this.$item)
|
|
1613
|
-
this._listenedSource.unlisten?.('changed', this.onChanged);
|
|
1614
|
-
this._listenedSource = null;
|
|
1615
|
-
if (this._rolePollTimer) {
|
|
1616
|
-
clearInterval(this._rolePollTimer);
|
|
1617
|
-
this._rolePollTimer = 0;
|
|
1618
|
-
}
|
|
1619
|
-
this._datesWatch = null;
|
|
1620
|
-
}
|
|
1621
|
-
})
|
|
1622
|
-
ODA({is: 'chat-day',
|
|
1623
|
-
template:/* html */`
|
|
1624
|
-
<style>
|
|
1625
|
-
:host{
|
|
1626
|
-
@apply --vertical;
|
|
1627
|
-
@apply --no-flex;
|
|
1628
|
-
|
|
1629
|
-
}
|
|
1630
|
-
:host([expanded]) .day-ribbon{
|
|
1631
|
-
transition: opacity 1s ease-in-out;
|
|
1632
|
-
opacity: 1;
|
|
1633
|
-
}
|
|
1634
|
-
.label{
|
|
1635
|
-
cursor: pointer;
|
|
1636
|
-
font-size: x-small;
|
|
1637
|
-
align-self: center;
|
|
1638
|
-
align-items: center;
|
|
1639
|
-
text-align: center;
|
|
1640
|
-
width: 150px;
|
|
1641
|
-
border-radius: 16px;
|
|
1642
|
-
padding: 0px 8px;
|
|
1643
|
-
z-index: 1;
|
|
1644
|
-
}
|
|
1645
|
-
.date-line{
|
|
1646
|
-
top: 4px;
|
|
1647
|
-
position: sticky;
|
|
1648
|
-
align-items: center;
|
|
1649
|
-
width: -webkit-fill-available;
|
|
1650
|
-
}
|
|
1651
|
-
.day-ribbon{
|
|
1652
|
-
gap: 8px;
|
|
1653
|
-
padding: 8px;
|
|
1654
|
-
opacity: 0;
|
|
1655
|
-
}
|
|
1656
|
-
</style>
|
|
1657
|
-
<div flex vertical class="date-line" center>
|
|
1658
|
-
<div class="label" raised dark horizontal :accent-invert="expanded" @tap="expanded = !expanded">
|
|
1659
|
-
<label flex style="padding: 0px 4px;">{{label}}</label>
|
|
1660
|
-
<oda-button icon-size="16" :icon="expanderIcon"></oda-button>
|
|
1661
|
-
</div>
|
|
1662
|
-
</div>
|
|
1663
|
-
|
|
1664
|
-
<div class="day-ribbon" flex vertical ~if="expanded">
|
|
1665
|
-
<chat-item @tap="setFocus" ~for="logs" :$item="$for.item"></chat-item>
|
|
1666
|
-
</div>
|
|
1667
|
-
`,
|
|
1668
|
-
get expanderIcon(){
|
|
1669
|
-
return this.expanded?'icons:chevron-right:90':'icons:chevron-right';
|
|
1670
|
-
},
|
|
1671
|
-
get last(){
|
|
1672
|
-
let dates = this.$pdp.dates;
|
|
1673
|
-
if (dates?.then)
|
|
1674
|
-
return dates.then(days => days.last === this.day);
|
|
1675
|
-
return dates?.last === this.day;
|
|
1676
|
-
},
|
|
1677
|
-
day: '',
|
|
1678
|
-
setFocus(e) {
|
|
1679
|
-
this.$pdp.focusedItem = e.target.$item;
|
|
1680
|
-
},
|
|
1681
|
-
expanded:{
|
|
1682
|
-
$def: false,
|
|
1683
|
-
$attr: true,
|
|
1684
|
-
get(){
|
|
1685
|
-
return this.last;
|
|
1686
|
-
}
|
|
1687
|
-
},
|
|
1688
|
-
logItems: [],
|
|
1689
|
-
_logsFolder: null,
|
|
1690
|
-
_logsInit: false,
|
|
1691
|
-
_logsInitPromise: null,
|
|
1692
|
-
_logsListenersHooked: false,
|
|
1693
|
-
_dayFolderHooked: false,
|
|
1694
|
-
_expandedTaskKey: '',
|
|
1695
|
-
_logItemTime(f) {
|
|
1696
|
-
if (!f)
|
|
1697
|
-
return 0;
|
|
1698
|
-
const st = SORT_TIMES.get(f);
|
|
1699
|
-
if (Number.isFinite(st) && st > 0)
|
|
1700
|
-
return st;
|
|
1701
|
-
const isProxyItem = Boolean(typeof f.fetch === 'function' || f.short);
|
|
1702
|
-
const rowTime = !isProxyItem ? Number(f.logRow?.time || f.DATA?.logRow?.time || 0) : 0;
|
|
1703
|
-
if (rowTime > 0)
|
|
1704
|
-
return rowTime;
|
|
1705
|
-
const idPrefix = parseInt(String(f.id || '').split('.')[0], 10);
|
|
1706
|
-
if (idPrefix > 0)
|
|
1707
|
-
return idPrefix;
|
|
1708
|
-
const pathMatch = String(f.path || '').match(/\/(\d{10,16})\.[^/]+$/);
|
|
1709
|
-
if (pathMatch)
|
|
1710
|
-
return parseInt(pathMatch[1], 10) || 0;
|
|
1711
|
-
return 0;
|
|
1712
|
-
},
|
|
1713
|
-
_sortLogFiles(files){
|
|
1714
|
-
return files.slice().sort((a, b) => {
|
|
1715
|
-
const ta = this._logItemTime(a);
|
|
1716
|
-
const tb = this._logItemTime(b);
|
|
1717
|
-
if (ta && tb && ta !== tb)
|
|
1718
|
-
return ta - tb;
|
|
1719
|
-
return String(a?.id || '') < String(b?.id || '') ? -1 : 1;
|
|
1720
|
-
});
|
|
1721
|
-
},
|
|
1722
|
-
_isMatchingTaskItem(it, key, fileId = '') {
|
|
1723
|
-
if (!it)
|
|
1724
|
-
return false;
|
|
1725
|
-
if (fileId && it.id === fileId)
|
|
1726
|
-
return true;
|
|
1727
|
-
if (!key)
|
|
1728
|
-
return false;
|
|
1729
|
-
return taskKeyOf(it.logRow?.path || it.path || it.id) === key
|
|
1730
|
-
|| String(it.id || '').replace(/\.logs$/i, '.task') === key;
|
|
1731
|
-
},
|
|
1732
|
-
_syncExpandedTaskCard() {
|
|
1733
|
-
const key = this._expandedTaskKey;
|
|
1734
|
-
const cards = [...(this.$$('chat-item') || [])];
|
|
1735
|
-
if (!key)
|
|
1736
|
-
return;
|
|
1737
|
-
for (const c of cards) {
|
|
1738
|
-
const match = this._isMatchingTaskItem(c.$item, key);
|
|
1739
|
-
if (match && !c.expanded)
|
|
1740
|
-
c.expanded = true;
|
|
1741
|
-
else if (!match && c.expanded)
|
|
1742
|
-
c.expanded = false;
|
|
1743
|
-
}
|
|
1744
|
-
},
|
|
1745
|
-
async _dedupeLogFiles(files){
|
|
1746
|
-
const seen = new Set();
|
|
1747
|
-
const result = [];
|
|
1748
|
-
for (const f of files) {
|
|
1749
|
-
let key = f?.id;
|
|
1750
|
-
if (typeof f?.load === 'function') {
|
|
1751
|
-
try {
|
|
1752
|
-
const raw = await f.load();
|
|
1753
|
-
const row = typeof raw === 'string' ? JSON.parse(raw) : raw;
|
|
1754
|
-
// Записи файлов из контекста задачи — только внутри её карточки, не отдельными карточками.
|
|
1755
|
-
if (row?.mainContext)
|
|
1756
|
-
continue;
|
|
1757
|
-
// задача, принятая в ленту напрямую (adoptTask), — карточка уже есть; запись журнала о ней не дублируем
|
|
1758
|
-
if (row?.ext === 'task' && this._adopted?.has(taskKeyOf(row.path)))
|
|
1759
|
-
continue;
|
|
1760
|
-
if (row?.path)
|
|
1761
|
-
key = row.path;
|
|
1762
|
-
}
|
|
1763
|
-
catch { /* skip */ }
|
|
1764
|
-
}
|
|
1765
|
-
if (!key || seen.has(key))
|
|
1766
|
-
continue;
|
|
1767
|
-
seen.add(key);
|
|
1768
|
-
result.push(f);
|
|
1769
|
-
}
|
|
1770
|
-
// принятые напрямую задачи в журнале дня могут ещё не появиться — не теряем их при перечитывании ленты
|
|
1771
|
-
for (const f of this._adopted?.values() || [])
|
|
1772
|
-
if (!result.some(r => r?.id === f.id))
|
|
1773
|
-
result.push(f);
|
|
1774
|
-
return this._sortLogFiles(result);
|
|
1775
|
-
},
|
|
1776
|
-
/**
|
|
1777
|
-
* Принять только что созданную задачу в ленту дня сразу по её файлу: карточка раскрывается, не дожидаясь записи
|
|
1778
|
-
* журнала. Резолвится, когда форма задачи нарисована (до этого чат держит экран «создаю задачу»).
|
|
1779
|
-
*/
|
|
1780
|
-
async adoptTask(file) {
|
|
1781
|
-
if (!this._logsInit)
|
|
1782
|
-
this._ensureLogsInit();
|
|
1783
|
-
if (this._logsInitPromise)
|
|
1784
|
-
await Promise.race([this._logsInitPromise, sleep(400)]).catch(() => {});
|
|
1785
|
-
const key = taskKeyOf(file.path) || String(file.id);
|
|
1786
|
-
if (!SORT_TIMES.has(file))
|
|
1787
|
-
SORT_TIMES.set(file, this._logItemTime(file) || Date.now());
|
|
1788
|
-
this._expandedTaskKey = key;
|
|
1789
|
-
(this._adopted ??= new Map()).set(key, file);
|
|
1790
|
-
const isSameTask = it => this._isMatchingTaskItem(it, key, file.id);
|
|
1791
|
-
const filtered = (this.logItems || []).filter(it => !isSameTask(it));
|
|
1792
|
-
this.logItems = this._sortLogFiles([...filtered, file]);
|
|
1793
|
-
this.expanded = true;
|
|
1794
|
-
this.render();
|
|
1795
|
-
this._scrollRibbonDown();
|
|
1796
|
-
for (let i = 0; i < 60; i++) {
|
|
1797
|
-
const allCards = [...(this.$$('chat-item') || [])];
|
|
1798
|
-
const card = allCards.find(el => isSameTask(el.$item));
|
|
1799
|
-
if (card) {
|
|
1800
|
-
for (const other of allCards) {
|
|
1801
|
-
if (other !== card && other.expanded)
|
|
1802
|
-
other.expanded = false;
|
|
1803
|
-
}
|
|
1804
|
-
card.expanded = true;
|
|
1805
|
-
for (let j = 0; j < 30; j++) {
|
|
1806
|
-
if (card.$('.body > *')?.data)
|
|
1807
|
-
break;
|
|
1808
|
-
await new Promise(r => setTimeout(r, 50));
|
|
1809
|
-
}
|
|
1810
|
-
return true;
|
|
1811
|
-
}
|
|
1812
|
-
await new Promise(r => setTimeout(r, 50));
|
|
1813
|
-
}
|
|
1814
|
-
throw new Error('карточка задачи не появилась в ленте');
|
|
1815
|
-
},
|
|
1816
|
-
_scrollRibbonDown(){
|
|
1817
|
-
if (this.$pdp.ribbon?.scrollDown) {
|
|
1818
|
-
this.async(() => {
|
|
1819
|
-
if (this.$pdp.ribbon) {
|
|
1820
|
-
this.$pdp.ribbon._savedScrollTop = 0;
|
|
1821
|
-
this.$pdp.ribbon.scrollTop = 0;
|
|
1822
|
-
}
|
|
1823
|
-
}, 0);
|
|
1824
|
-
}
|
|
1825
|
-
},
|
|
1826
|
-
_wrapLogRow(row) {
|
|
1827
|
-
if (!row)
|
|
1828
|
-
return row;
|
|
1829
|
-
if (typeof row.load === 'function' && !row.logsFilePath && !row.DATA?.logsFilePath)
|
|
1830
|
-
return row;
|
|
1831
|
-
const rawRow = row.DATA?.logsFilePath ? { ...row.DATA } : row;
|
|
1832
|
-
const uid = rawRow.sender || 'system';
|
|
1833
|
-
const id = `${rawRow.time || 0}.${uid}.logs`;
|
|
1834
|
-
this._wrappedById ??= new Map();
|
|
1835
|
-
const existing = this._wrappedById.get(id);
|
|
1836
|
-
if (existing) {
|
|
1837
|
-
existing.logRow = rawRow;
|
|
1838
|
-
return existing;
|
|
1839
|
-
}
|
|
1840
|
-
const wrapped = {
|
|
1841
|
-
id,
|
|
1842
|
-
name: id,
|
|
1843
|
-
ext: 'logs',
|
|
1844
|
-
path: rawRow.logsFilePath || `/${id}`,
|
|
1845
|
-
logRow: rawRow,
|
|
1846
|
-
load: async () => ({ ...(wrapped.logRow || rawRow) }),
|
|
1847
|
-
};
|
|
1848
|
-
this._wrappedById.set(id, wrapped);
|
|
1849
|
-
return wrapped;
|
|
1850
|
-
},
|
|
1851
|
-
_wrapThreadMessage(msg) {
|
|
1852
|
-
if (!msg || !msg.id)
|
|
1853
|
-
return null;
|
|
1854
|
-
const id = `chatmsg.${msg.id}.msg`;
|
|
1855
|
-
this._wrappedById ??= new Map();
|
|
1856
|
-
const nodeLabel = this.$pdp?.$item?.DATA?.label || this.$pdp?.$item?.label || this.$pdp?.$item?.id || '';
|
|
1857
|
-
const enriched = { ...msg, nodeLabel };
|
|
1858
|
-
const rawRow = {
|
|
1859
|
-
time: msg.created || Date.now(),
|
|
1860
|
-
sender: msg.sender,
|
|
1861
|
-
content: msg.content || '',
|
|
1862
|
-
kind: msg.kind || 'text',
|
|
1863
|
-
includes: (msg.attachments || []).map(a => a.path).filter(Boolean),
|
|
1864
|
-
chatMessage: enriched,
|
|
1865
|
-
};
|
|
1866
|
-
const existing = this._wrappedById.get(id);
|
|
1867
|
-
if (existing) {
|
|
1868
|
-
SORT_TIMES.set(existing, rawRow.time);
|
|
1869
|
-
existing.logRow = rawRow;
|
|
1870
|
-
return existing;
|
|
1871
|
-
}
|
|
1872
|
-
const wrapped = {
|
|
1873
|
-
id,
|
|
1874
|
-
name: id,
|
|
1875
|
-
ext: 'msg',
|
|
1876
|
-
path: '',
|
|
1877
|
-
logRow: rawRow,
|
|
1878
|
-
load: async () => ({ ...(wrapped.logRow || rawRow) }),
|
|
1879
|
-
};
|
|
1880
|
-
SORT_TIMES.set(wrapped, rawRow.time);
|
|
1881
|
-
this._wrappedById.set(id, wrapped);
|
|
1882
|
-
return wrapped;
|
|
1883
|
-
},
|
|
1884
|
-
async _bindLogsFolder(){
|
|
1885
|
-
const source = await Promise.resolve(this.logsSource);
|
|
1886
|
-
return !!source;
|
|
1887
|
-
},
|
|
1888
|
-
async _fetchLogFiles(){
|
|
1889
|
-
const source = await Promise.resolve(this.logsSource);
|
|
1890
|
-
if (!source)
|
|
1891
|
-
return [];
|
|
1892
|
-
const role = this.$pdp?.$item?.role || 'USER';
|
|
1893
|
-
const uid = WORK.uid || '';
|
|
1894
|
-
const local = this.$pdp?.isLocalFeed ? { local: 1, feedMode: 'local' } : { feedMode: 'dialog' };
|
|
1895
|
-
let rows = [];
|
|
1896
|
-
try {
|
|
1897
|
-
if (typeof source.fetch === 'function')
|
|
1898
|
-
rows = await source.fetch('logs', { mode: 'bodies', day: this.day, role, uid, ...local });
|
|
1899
|
-
else if (typeof source.logs === 'function')
|
|
1900
|
-
rows = await source.logs({ mode: 'bodies', day: this.day, role, uid, ...local });
|
|
1901
|
-
}
|
|
1902
|
-
catch {
|
|
1903
|
-
rows = [];
|
|
1904
|
-
}
|
|
1905
|
-
if (!Array.isArray(rows))
|
|
1906
|
-
rows = [];
|
|
1907
|
-
const files = rows.map(r => this._wrapLogRow(r)).filter(f => f?.id?.endsWith?.('.logs') || f?.id?.endsWith?.('.task'));
|
|
1908
|
-
|
|
1909
|
-
if (!this.$pdp?.isLocalFeed && typeof this.$pdp?.threadMessagesForDay === 'function') {
|
|
1910
|
-
const taskKeys = new Set(rows.map(r => taskKeyOf(r?.path)).filter(Boolean));
|
|
1911
|
-
for (const f of this._adopted?.values() || []) {
|
|
1912
|
-
const tk = taskKeyOf(f?.path || f?.id);
|
|
1913
|
-
if (tk) taskKeys.add(tk);
|
|
1914
|
-
}
|
|
1915
|
-
const msgs = this.$pdp.threadMessagesForDay(this.day);
|
|
1916
|
-
for (const m of msgs) {
|
|
1917
|
-
if (m.taskPath && taskKeys.has(taskKeyOf(m.taskPath)))
|
|
1918
|
-
continue;
|
|
1919
|
-
if (m.sender !== '$twin' && m.kind === 'text' && rows.some(r => r?.sender === m.sender && String(r?.content || '').trim() === String(m.content || '').trim() && Math.abs((Number(r?.time) || 0) - (Number(m.created) || 0)) < 5000))
|
|
1920
|
-
continue;
|
|
1921
|
-
const w = this._wrapThreadMessage(m);
|
|
1922
|
-
if (w)
|
|
1923
|
-
files.push(w);
|
|
1924
|
-
}
|
|
1925
|
-
}
|
|
1926
|
-
return this._dedupeLogFiles(this._sortLogFiles(files));
|
|
1927
|
-
},
|
|
1928
|
-
/**
|
|
1929
|
-
* Раскрыть карточку только что созданной задачи. Строго та, что создана: по имени файла .task;
|
|
1930
|
-
* пока путь неизвестен — только новая запись моего авторства, которой не было в ленте до отправки.
|
|
1931
|
-
* «Ближайшая по времени» не подходит: раскрывалась последняя прежняя задача (см. chat-task.js).
|
|
1932
|
-
*/
|
|
1933
|
-
async _expandCreatedTask(file) {
|
|
1934
|
-
const chat = this.$pdp.$pdp;
|
|
1935
|
-
if (!chat?.awaitTask || !chat?._awaitingLogExpand)
|
|
1936
|
-
return;
|
|
1937
|
-
const day = taskDayOf(chat._awaitTaskPath);
|
|
1938
|
-
if (day && this.day !== day)
|
|
1939
|
-
return;
|
|
1940
|
-
const want = { key: chat._awaitTaskKey || '', known: chat._awaitKnown || new Set(), uid: WORK.uid };
|
|
1941
|
-
const loadRow = async f => {
|
|
1942
|
-
try {
|
|
1943
|
-
const raw = await f.load();
|
|
1944
|
-
return typeof raw === 'string' ? JSON.parse(raw) : raw;
|
|
1945
|
-
}
|
|
1946
|
-
catch {
|
|
1947
|
-
return null;
|
|
1948
|
-
}
|
|
1949
|
-
};
|
|
1950
|
-
let hit = null;
|
|
1951
|
-
let hitRow = null;
|
|
1952
|
-
for (const f of file ? [file] : this.logItems) {
|
|
1953
|
-
if (want.known.has(String(f?.id || '')))
|
|
1954
|
-
continue;
|
|
1955
|
-
const row = await loadRow(f);
|
|
1956
|
-
const rowKey = taskKeyOf(row?.path || f?.path || f?.id);
|
|
1957
|
-
if (rowKey && want.known.has(rowKey))
|
|
1958
|
-
continue;
|
|
1959
|
-
if (isCreatedTask(f, row, want)) {
|
|
1960
|
-
hit = f;
|
|
1961
|
-
hitRow = row;
|
|
1962
|
-
break;
|
|
1963
|
-
}
|
|
1964
|
-
}
|
|
1965
|
-
if (!hit)
|
|
1966
|
-
return;
|
|
1967
|
-
const hitKey = taskKeyOf(hitRow?.path || hit?.path || hit?.id) || String(hit.id || '').replace(/\.logs$/i, '.task');
|
|
1968
|
-
if (hitKey)
|
|
1969
|
-
this._expandedTaskKey = hitKey;
|
|
1970
|
-
// день мог быть свёрнут, карточка рисуется после render — ждём её появления
|
|
1971
|
-
if (!this.expanded)
|
|
1972
|
-
this.expanded = true;
|
|
1973
|
-
this.render();
|
|
1974
|
-
for (let i = 0; i < 30; i++) {
|
|
1975
|
-
const allCards = [...this.$$('chat-item')];
|
|
1976
|
-
const card = allCards.find(el => el.$item?.id === hit.id || (hitKey && this._isMatchingTaskItem(el.$item, hitKey)));
|
|
1977
|
-
if (card) {
|
|
1978
|
-
for (const other of allCards) {
|
|
1979
|
-
if (other !== card && other.expanded)
|
|
1980
|
-
other.expanded = false;
|
|
1981
|
-
}
|
|
1982
|
-
card.expanded = true;
|
|
1983
|
-
chat.awaitTask = false;
|
|
1984
|
-
chat._awaitingLogExpand = false;
|
|
1985
|
-
chat._awaitTaskPath = '';
|
|
1986
|
-
chat._awaitTaskKey = '';
|
|
1987
|
-
chat._awaitKnown = null;
|
|
1988
|
-
clearTimeout(chat._awaitTimer);
|
|
1989
|
-
return;
|
|
1990
|
-
}
|
|
1991
|
-
await new Promise(r => setTimeout(r, 50));
|
|
1992
|
-
}
|
|
1993
|
-
},
|
|
1994
|
-
async _onLogsChangedRun(){
|
|
1995
|
-
if (!this._logsInit)
|
|
1996
|
-
return;
|
|
1997
|
-
try {
|
|
1998
|
-
const items = await this._fetchLogFiles();
|
|
1999
|
-
const prev = Array.isArray(this.logItems) ? this.logItems : [];
|
|
2000
|
-
const prevLen = prev.length;
|
|
2001
|
-
const sameList = prev.length === items.length && items.every((it, idx) => it === prev[idx] || (it?.id && it.id === prev[idx]?.id));
|
|
2002
|
-
if (!sameList) {
|
|
2003
|
-
this.logItems = items;
|
|
2004
|
-
this.render();
|
|
2005
|
-
this._syncExpandedTaskCard();
|
|
2006
|
-
if (items.length > prevLen)
|
|
2007
|
-
this._scrollRibbonDown();
|
|
2008
|
-
}
|
|
2009
|
-
await this._expandCreatedTask();
|
|
2010
|
-
}
|
|
2011
|
-
catch (err) {
|
|
2012
|
-
console.warn('[chat-day] log changed', err);
|
|
2013
|
-
}
|
|
2014
|
-
},
|
|
2015
|
-
_onLogsChanged(e){
|
|
2016
|
-
this._lastChangedEvent = e;
|
|
2017
|
-
this.debounce('chat-day-logs', () => this._onLogsChangedRun(this._lastChangedEvent), 30);
|
|
2018
|
-
},
|
|
2019
|
-
_ensureLogsInit() {
|
|
2020
|
-
if (this._logsInit)
|
|
2021
|
-
return this._logsInitPromise;
|
|
2022
|
-
this._logsInit = true;
|
|
2023
|
-
this._wasInit = true;
|
|
2024
|
-
this._logsInitPromise = Promise.resolve(this.logsSource).then(async source => {
|
|
2025
|
-
if (!source)
|
|
2026
|
-
return;
|
|
2027
|
-
if (!this._logsListenersHooked) {
|
|
2028
|
-
this._logsListenersHooked = true;
|
|
2029
|
-
const onChanged = this._onChangedFn = e => this._onLogsChanged(e);
|
|
2030
|
-
this._listened = [source, this.$pdp.$item].filter(Boolean);
|
|
2031
|
-
source?.listen?.('changed', onChanged);
|
|
2032
|
-
if (this.$pdp.$item && this.$pdp.$item !== source)
|
|
2033
|
-
this.$pdp.$item?.listen?.('changed', onChanged);
|
|
2034
|
-
}
|
|
2035
|
-
this.logItems = await this._fetchLogFiles();
|
|
2036
|
-
this.render();
|
|
2037
|
-
this._syncExpandedTaskCard();
|
|
2038
|
-
this._scrollRibbonDown();
|
|
2039
|
-
await this._expandCreatedTask();
|
|
2040
|
-
}).catch(e => {
|
|
2041
|
-
console.warn('[chat-day] logs', e.message);
|
|
2042
|
-
this._logsInit = false;
|
|
2043
|
-
});
|
|
2044
|
-
return this._logsInitPromise;
|
|
2045
|
-
},
|
|
2046
|
-
get logs() {
|
|
2047
|
-
this._ensureLogsInit();
|
|
2048
|
-
return this.logItems;
|
|
2049
|
-
},
|
|
2050
|
-
/** День вернули в DOM после снятия подписок — подписаться заново (день, который не открывали, ленту не грузит). */
|
|
2051
|
-
attached() {
|
|
2052
|
-
if (this._wasInit && !this._logsInit)
|
|
2053
|
-
this._ensureLogsInit();
|
|
2054
|
-
},
|
|
2055
|
-
/** Снять подписки на ленту: день убрали из DOM — события больше не нужны (иначе копятся по числу дней). */
|
|
2056
|
-
detached() {
|
|
2057
|
-
for (const target of this._listened || [])
|
|
2058
|
-
target?.unlisten?.('changed', this._onChangedFn);
|
|
2059
|
-
this._listened = null;
|
|
2060
|
-
this._logsListenersHooked = false;
|
|
2061
|
-
this._logsInit = false;
|
|
2062
|
-
if (this._logsFolder && this._dayFolderHooked) {
|
|
2063
|
-
this._logsFolder.unlisten?.('changed', this._dayHandler);
|
|
2064
|
-
this._dayFolderHooked = false;
|
|
2065
|
-
}
|
|
2066
|
-
},
|
|
2067
|
-
get logsSource(){
|
|
2068
|
-
// По умолчанию всегда показывается личный кабинет (/USERS/<uid>);
|
|
2069
|
-
// местный лог точки (this.$pdp.$item) — только при явном включении режима local для BOSS.
|
|
2070
|
-
const role = this.$pdp?.$item?.role || 'USER';
|
|
2071
|
-
const uid = WORK.uid || '';
|
|
2072
|
-
const local = this.$pdp?.isLocalFeed ? { local: 1 } : {};
|
|
2073
|
-
return Promise.resolve(this.$pdp.$item?.fetch?.('chatSource', { role, uid, ...local })).then(path => {
|
|
2074
|
-
if (path && typeof path === 'string')
|
|
2075
|
-
return WORK.get_item(path);
|
|
2076
|
-
return this.$pdp.$item;
|
|
2077
|
-
});
|
|
2078
|
-
},
|
|
2079
|
-
get label(){
|
|
2080
|
-
let date = new Date(this.day);
|
|
2081
|
-
return date.toLocaleDateString(undefined, {
|
|
2082
|
-
weekday: "short",
|
|
2083
|
-
year: "numeric",
|
|
2084
|
-
month: "long",
|
|
2085
|
-
day: "numeric",
|
|
2086
|
-
});
|
|
2087
|
-
}
|
|
2088
|
-
})
|
|
2089
|
-
ODA({is: 'skill-tree', imports: '~/lib//tree.js', extends: 'item-tree',
|
|
2090
|
-
execute($item) {
|
|
2091
|
-
this.$pdp.chat.value = '@' + $item.name;
|
|
2092
|
-
this.focusedItem = $item;
|
|
2093
|
-
this.executed = true;
|
|
2094
|
-
},
|
|
2095
|
-
})
|