@causyne/agent 1.20.121 → 1.20.124
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/bin/causyne.js +38 -15
- package/docs/SECURITY_REVIEW.md +42 -6
- package/package.json +5 -5
- package/src/acp/agentCatalog.js +141 -62
- package/src/acp/agentCatalog.ts +142 -65
- package/src/acp/client.js +489 -109
- package/src/acp/client.ts +465 -108
- package/src/acp/peerProfiles.js +55 -22
- package/src/acp/peerProfiles.ts +51 -22
- package/src/acp/protocol.js +181 -8
- package/src/acp/protocol.ts +189 -8
- package/src/acp/server.js +250 -53
- package/src/acp/server.ts +234 -53
- package/src/agent/errorClassifier.js +48 -8
- package/src/agent/errorClassifier.ts +50 -7
- package/src/agent/providerFailure.js +1 -1
- package/src/agent/providerFailure.ts +7 -1
- package/src/agent/toolArgValidator.js +38 -4
- package/src/agent/toolArgValidator.ts +39 -4
- package/src/agent/toolTurnIntegrity.js +28 -7
- package/src/agent/toolTurnIntegrity.ts +25 -6
- package/src/agent/workspaceBoundary.js +30 -4
- package/src/agent/workspaceBoundary.ts +32 -4
- package/src/agentLoop.js +609 -222
- package/src/agentLoop.ts +632 -220
- package/src/approvalGrants.js +19 -7
- package/src/approvalGrants.ts +20 -7
- package/src/approvalPolicy.js +76 -16
- package/src/approvalPolicy.ts +74 -16
- package/src/auditLog.js +641 -48
- package/src/auditLog.ts +661 -0
- package/src/autoUpdate.js +37 -7
- package/src/autoUpdate.ts +32 -7
- package/src/backgroundTasks.js +328 -0
- package/src/backgroundTasks.ts +339 -0
- package/src/benchmarks/codingEval.js +558 -0
- package/src/benchmarks/codingEval.ts +628 -0
- package/src/benchmarks/planCache.js +115 -134
- package/src/benchmarks/planCache.ts +163 -0
- package/src/browser/browserRuntime.js +52 -0
- package/src/browser/browserRuntime.ts +55 -0
- package/src/browser/causyneBrowser.js +887 -12
- package/src/browser/causyneBrowser.ts +1045 -34
- package/src/browser/searchProviders.js +95 -7
- package/src/browser/searchProviders.ts +90 -7
- package/src/browser/urlPolicy.js +8 -1
- package/src/browser/urlPolicy.ts +7 -1
- package/src/browser/workspacePathSafety.js +6 -4
- package/src/browser/workspacePathSafety.ts +7 -4
- package/src/capabilities.js +18 -17
- package/src/capabilities.ts +38 -0
- package/src/checkpoints.js +1241 -1127
- package/src/checkpoints.ts +1377 -0
- package/src/cliMode.js +707 -755
- package/src/cliMode.ts +780 -0
- package/src/codebase/repoMap.js +656 -0
- package/src/codebase/repoMap.ts +664 -0
- package/src/commands.js +3651 -2514
- package/src/commands.ts +3985 -0
- package/src/compiledSkills.js +8052 -8054
- package/src/compiledSkills.ts +8078 -0
- package/src/config.js +389 -250
- package/src/config.ts +451 -0
- package/src/configVault.js +113 -19
- package/src/configVault.ts +103 -19
- package/src/contextManager.js +473 -557
- package/src/contextManager.ts +599 -0
- package/src/continuum/adapters/antigravity.js +8 -3
- package/src/continuum/adapters/antigravity.ts +8 -3
- package/src/continuum/compactor.js +2 -1
- package/src/continuum/compactor.ts +2 -1
- package/src/continuum/sanitizer.js +33 -4
- package/src/continuum/sanitizer.ts +32 -4
- package/src/continuum/ui/continuumPicker.js +0 -2
- package/src/continuum/ui/continuumPicker.ts +0 -2
- package/src/continuum/ui/continuumPickerView.js +3 -4
- package/src/continuum/ui/continuumPickerView.ts +7 -22
- package/src/core/contextCompactor.js +88 -7
- package/src/core/contextCompactor.ts +87 -8
- package/src/cortex/vectorDb.js +26 -15
- package/src/cortex/vectorDb.ts +26 -16
- package/src/creative/liveBridge.js +10 -7
- package/src/creative/liveBridge.ts +11 -7
- package/src/creative/studioScripts.js +17 -6
- package/src/creative/studioScripts.ts +15 -6
- package/src/decideTools.js +7 -2
- package/src/decideTools.ts +7 -2
- package/src/decisionPolicy.js +26 -6
- package/src/decisionPolicy.ts +24 -6
- package/src/designPalettes.js +72 -84
- package/src/designPalettes.ts +111 -0
- package/src/devMode.js +2 -2
- package/src/devMode.ts +6 -0
- package/src/diffReview.js +370 -0
- package/src/diffReview.ts +407 -0
- package/src/documentEngine/antiSlopAuditor.js +10 -5
- package/src/documentEngine/antiSlopAuditor.ts +11 -5
- package/src/documentEngine/documentForge.js +47 -15
- package/src/documentEngine/documentForge.ts +43 -14
- package/src/dynamicCatalogue.js +311 -11
- package/src/dynamicCatalogue.ts +331 -11
- package/src/embodimentSession.js +143 -154
- package/src/embodimentSession.ts +173 -0
- package/src/engines/design.js +2 -1
- package/src/engines/design.ts +2 -1
- package/src/engines/film.js +4 -4
- package/src/engines/film.ts +2 -2
- package/src/engines/installer.js +60 -29
- package/src/engines/installer.ts +73 -22
- package/src/engines/light.js +2 -1
- package/src/engines/light.ts +2 -1
- package/src/engines/registry.js +1 -1
- package/src/engines/registry.ts +1 -1
- package/src/engines/reverseHarness.js +4 -3
- package/src/engines/reverseHarness.ts +4 -3
- package/src/enterprisePolicy.js +660 -0
- package/src/enterprisePolicy.ts +728 -0
- package/src/entrypoint.js +514 -268
- package/src/entrypoint.ts +607 -0
- package/src/gitSnapshot.js +417 -312
- package/src/gitSnapshot.ts +500 -0
- package/src/headlessCli.js +326 -14
- package/src/headlessCli.ts +323 -13
- package/src/historyPruner.js +3 -2
- package/src/historyPruner.ts +3 -2
- package/src/hooks.js +250 -26
- package/src/hooks.ts +239 -26
- package/src/ignoreRules.js +297 -0
- package/src/ignoreRules.ts +308 -0
- package/src/implementationPlan.js +28 -17
- package/src/implementationPlan.ts +29 -17
- package/src/infra/atomicWriter.js +96 -20
- package/src/infra/atomicWriter.ts +112 -20
- package/src/launchIntent.js +14 -3
- package/src/launchIntent.ts +14 -3
- package/src/licensing/entitlements.js +553 -237
- package/src/licensing/entitlements.ts +590 -0
- package/src/licensing/policy.js +17 -1
- package/src/licensing/policy.ts +31 -0
- package/src/lsp/lspCatalog.js +398 -0
- package/src/lsp/lspCatalog.ts +452 -0
- package/src/lsp/lspClient.js +699 -0
- package/src/lsp/lspClient.ts +799 -0
- package/src/lsp/lspProtocol.js +121 -0
- package/src/lsp/lspProtocol.ts +140 -0
- package/src/mcp/mcpClient.js +69 -8
- package/src/mcp/mcpClient.ts +66 -9
- package/src/mcp/mcpRegistry.js +180 -7
- package/src/mcp/mcpRegistry.ts +171 -7
- package/src/mcp/mcpSecurity.js +6 -7
- package/src/mcp/mcpSecurity.ts +7 -6
- package/src/memory/episodicStore.js +2 -5
- package/src/memory/episodicStore.ts +2 -5
- package/src/memory/scopedFacts.js +1 -1
- package/src/memory/scopedFacts.ts +1 -1
- package/src/memory/symbolFolder.js +1 -1
- package/src/memory/symbolFolder.ts +1 -1
- package/src/memory.js +80 -32
- package/src/memory.ts +111 -0
- package/src/memoryManager.js +151 -143
- package/src/memoryManager.ts +182 -0
- package/src/modelCatalogue.js +172 -195
- package/src/modelCatalogue.ts +201 -0
- package/src/modelIds.js +8 -27
- package/src/modelIds.ts +33 -0
- package/src/modelRouter.js +1 -1
- package/src/modelRouter.ts +1 -1
- package/src/modelVariants.js +600 -0
- package/src/modelVariants.ts +663 -0
- package/src/observer/evidence.js +15 -5
- package/src/observer/evidence.ts +15 -5
- package/src/osKeychain.js +79 -17
- package/src/osKeychain.ts +64 -17
- package/src/outputStore.js +210 -156
- package/src/outputStore.ts +321 -0
- package/src/perception.js +3 -2
- package/src/perception.ts +3 -2
- package/src/planCache.js +5 -8
- package/src/planCache.ts +5 -8
- package/src/plugins/pluginManager.js +689 -461
- package/src/plugins/pluginManager.ts +807 -0
- package/src/plugins/pluginRunner.js +82 -37
- package/src/plugins/pluginRunner.ts +98 -0
- package/src/plugins/pluginSkills.js +47 -9
- package/src/plugins/pluginSkills.ts +46 -8
- package/src/pluginsFactory/discovery.js +0 -1
- package/src/pluginsFactory/discovery.ts +0 -1
- package/src/pluginsFactory/pluginsFactory.js +19 -11
- package/src/pluginsFactory/pluginsFactory.ts +18 -11
- package/src/pluginsFactory/templates.js +17 -4
- package/src/pluginsFactory/templates.ts +17 -4
- package/src/prWorkflow.js +337 -0
- package/src/prWorkflow.ts +376 -0
- package/src/procSignal.js +1 -2
- package/src/procSignal.ts +1 -3
- package/src/projectInstructions.js +319 -0
- package/src/projectInstructions.ts +361 -0
- package/src/promptMentions.js +2 -2
- package/src/promptMentions.ts +2 -2
- package/src/providers/acp.js +235 -50
- package/src/providers/acp.ts +241 -51
- package/src/providers/anthropic.js +431 -400
- package/src/providers/anthropic.ts +493 -0
- package/src/providers/antigravity.js +575 -358
- package/src/providers/antigravity.ts +565 -359
- package/src/providers/base.js +229 -320
- package/src/providers/base.ts +348 -0
- package/src/providers/byokHttp.js +183 -30
- package/src/providers/byokHttp.ts +232 -32
- package/src/providers/byokStream.js +287 -70
- package/src/providers/byokStream.ts +282 -71
- package/src/providers/dashscope-byok.js +123 -89
- package/src/providers/dashscope-byok.ts +142 -0
- package/src/providers/deepseek.js +82 -72
- package/src/providers/deepseek.ts +108 -0
- package/src/providers/factory.js +76 -28
- package/src/providers/factory.ts +82 -0
- package/src/providers/gemini.js +279 -278
- package/src/providers/gemini.ts +313 -0
- package/src/providers/loopGuard.js +9 -5
- package/src/providers/loopGuard.ts +10 -5
- package/src/providers/moonshot.js +103 -72
- package/src/providers/moonshot.ts +122 -0
- package/src/providers/muse.js +82 -152
- package/src/providers/muse.ts +122 -0
- package/src/providers/ollama.js +360 -106
- package/src/providers/ollama.ts +408 -0
- package/src/providers/openai-compatible.js +168 -95
- package/src/providers/openai-compatible.ts +200 -0
- package/src/providers/openai.js +45 -15
- package/src/providers/openai.ts +52 -0
- package/src/providers/openrouter.js +342 -113
- package/src/providers/openrouter.ts +333 -116
- package/src/providers/pi.js +6 -0
- package/src/providers/pi.ts +6 -0
- package/src/providers/qwen-byok.js +122 -87
- package/src/providers/qwen-byok.ts +141 -0
- package/src/providers/toolContracts.js +40 -14
- package/src/providers/toolContracts.ts +35 -14
- package/src/providers/wireNormalizer.js +144 -11
- package/src/providers/wireNormalizer.ts +132 -12
- package/src/providers/xai.js +80 -72
- package/src/providers/xai.ts +103 -0
- package/src/provisioning/capabilityConsent.js +29 -11
- package/src/provisioning/capabilityConsent.ts +42 -0
- package/src/provisioning/capabilityProvisioner.js +309 -197
- package/src/provisioning/capabilityProvisioner.ts +413 -0
- package/src/provisioning/capabilityTools.js +31 -17
- package/src/provisioning/capabilityTools.ts +43 -0
- package/src/provisioning/npmInstall.js +33 -5
- package/src/provisioning/npmInstall.ts +33 -5
- package/src/reliability/assetEvidence.js +4 -2
- package/src/reliability/assetEvidence.ts +4 -2
- package/src/reporting.js +328 -326
- package/src/reporting.ts +482 -0
- package/src/sandbox.js +526 -554
- package/src/sandbox.ts +590 -0
- package/src/sandboxPolicy.js +95 -16
- package/src/sandboxPolicy.ts +97 -16
- package/src/sessionJournal.js +32 -6
- package/src/sessionJournal.ts +27 -6
- package/src/sessionStore.js +1 -2
- package/src/sessionStore.ts +2 -0
- package/src/skills/skillResourceSafety.js +19 -8
- package/src/skills/skillResourceSafety.ts +16 -7
- package/src/skillsManager.js +3 -3
- package/src/skillsManager.ts +3 -3
- package/src/slopDetector.js +202 -265
- package/src/slopDetector.ts +279 -0
- package/src/smartToolsUse.js +38 -8
- package/src/smartToolsUse.ts +39 -11
- package/src/stallGuard.js +53 -23
- package/src/stallGuard.ts +53 -23
- package/src/subagentJournal.js +6 -4
- package/src/subagentJournal.ts +6 -4
- package/src/taskBuffer.js +91 -40
- package/src/taskBuffer.ts +94 -0
- package/src/textDiff.js +6 -1
- package/src/textDiff.ts +6 -1
- package/src/timeMachine.js +7 -1
- package/src/timeMachine.ts +7 -1
- package/src/tokenTracker.js +120 -38
- package/src/tokenTracker.ts +110 -38
- package/src/toolPacks.js +8 -1
- package/src/toolPacks.ts +8 -1
- package/src/tools/applyPatch.js +610 -0
- package/src/tools/applyPatch.ts +661 -0
- package/src/tools/archive.js +372 -48
- package/src/tools/archive.ts +372 -48
- package/src/tools/astryxOracle.js +77 -72
- package/src/tools/astryxOracle.ts +95 -0
- package/src/tools/axSnapshot.js +127 -147
- package/src/tools/axSnapshot.ts +174 -0
- package/src/tools/backgroundTask.js +86 -0
- package/src/tools/backgroundTask.ts +121 -0
- package/src/tools/blenderAutomator.js +434 -390
- package/src/tools/blenderAutomator.ts +623 -0
- package/src/tools/checkSystemSpecs.js +54 -61
- package/src/tools/checkSystemSpecs.ts +73 -0
- package/src/tools/clipboard.js +42 -31
- package/src/tools/clipboard.ts +61 -0
- package/src/tools/codeSearchAst.js +359 -91
- package/src/tools/codeSearchAst.ts +399 -0
- package/src/tools/codeSearcher.js +179 -37
- package/src/tools/codeSearcher.ts +188 -33
- package/src/tools/codeTools.js +208 -245
- package/src/tools/codeTools.ts +271 -0
- package/src/tools/codebaseSearch.js +5 -0
- package/src/tools/codebaseSearch.ts +5 -0
- package/src/tools/computerUse.js +7 -3
- package/src/tools/computerUse.ts +7 -3
- package/src/tools/creativeApps.js +13 -8
- package/src/tools/creativeApps.ts +22 -9
- package/src/tools/deferredMcpSearch.js +26 -14
- package/src/tools/deferredMcpSearch.ts +26 -14
- package/src/tools/desktopAct.js +185 -197
- package/src/tools/desktopAct.ts +257 -0
- package/src/tools/desktopOpen.js +69 -10
- package/src/tools/desktopOpen.ts +70 -11
- package/src/tools/documentForge.js +167 -82
- package/src/tools/documentForge.ts +169 -84
- package/src/tools/dynamicLoader.js +4 -40
- package/src/tools/dynamicLoader.ts +13 -0
- package/src/tools/executeProceduralMedia.js +117 -86
- package/src/tools/executeProceduralMedia.ts +135 -0
- package/src/tools/fileTracker.js +74 -0
- package/src/tools/fileTracker.ts +94 -0
- package/src/tools/fsDelete.js +57 -47
- package/src/tools/fsDelete.ts +80 -0
- package/src/tools/fsEdit.js +250 -61
- package/src/tools/fsEdit.ts +265 -63
- package/src/tools/fsFind.js +8 -5
- package/src/tools/fsFind.ts +7 -4
- package/src/tools/fsMove.js +79 -52
- package/src/tools/fsMove.ts +108 -0
- package/src/tools/fsRead.js +163 -18
- package/src/tools/fsRead.ts +169 -18
- package/src/tools/fsSearch.js +5 -0
- package/src/tools/fsSearch.ts +5 -0
- package/src/tools/fsWrite.js +31 -11
- package/src/tools/fsWrite.ts +31 -13
- package/src/tools/gameAiBehaviorTree.js +74 -91
- package/src/tools/gameAiBehaviorTree.ts +219 -0
- package/src/tools/gameAnimationRig.js +128 -147
- package/src/tools/gameAnimationRig.ts +215 -0
- package/src/tools/gameAssetFetcher.js +403 -441
- package/src/tools/gameAssetFetcher.ts +477 -0
- package/src/tools/gameAssetHarvester.js +171 -200
- package/src/tools/gameAssetHarvester.ts +261 -0
- package/src/tools/gameAudioSynth.js +223 -259
- package/src/tools/gameAudioSynth.ts +255 -0
- package/src/tools/gameBuilder.js +100 -91
- package/src/tools/gameBuilder.ts +913 -0
- package/src/tools/gameCanvasAudit.js +138 -96
- package/src/tools/gameCanvasAudit.ts +157 -0
- package/src/tools/gameCinematicSequencer.js +93 -111
- package/src/tools/gameCinematicSequencer.ts +165 -0
- package/src/tools/gameDataForge.js +115 -118
- package/src/tools/gameDataForge.ts +151 -0
- package/src/tools/gameDialogueTreeGen.js +125 -156
- package/src/tools/gameDialogueTreeGen.ts +159 -0
- package/src/tools/gameEconomyBalancer.js +150 -153
- package/src/tools/gameEconomyBalancer.ts +186 -0
- package/src/tools/gameEntitySpawner.js +91 -108
- package/src/tools/gameEntitySpawner.ts +209 -0
- package/src/tools/gameLoreForge.js +125 -147
- package/src/tools/gameLoreForge.ts +162 -0
- package/src/tools/gameQuestArcBuilder.js +105 -144
- package/src/tools/gameQuestArcBuilder.ts +147 -0
- package/src/tools/gameSceneBuilder.js +143 -149
- package/src/tools/gameSceneBuilder.ts +196 -0
- package/src/tools/gameShaderForge.js +83 -101
- package/src/tools/gameShaderForge.ts +181 -0
- package/src/tools/gameTilemapGenerator.js +99 -129
- package/src/tools/gameTilemapGenerator.ts +158 -0
- package/src/tools/gameUiHudBuilder.js +109 -129
- package/src/tools/gameUiHudBuilder.ts +300 -0
- package/src/tools/gameVfxEmitterGen.js +86 -89
- package/src/tools/gameVfxEmitterGen.ts +133 -0
- package/src/tools/gameWebRuntimeInspector.js +153 -86
- package/src/tools/gameWebRuntimeInspector.ts +167 -0
- package/src/tools/generateMediaViaApi.js +126 -22
- package/src/tools/generateMediaViaApi.ts +123 -22
- package/src/tools/gitExec.js +133 -86
- package/src/tools/gitExec.ts +146 -0
- package/src/tools/gitWorktree.js +115 -0
- package/src/tools/gitWorktree.ts +150 -0
- package/src/tools/godotAutomator.js +417 -394
- package/src/tools/godotAutomator.ts +530 -0
- package/src/tools/lspCodeIntel.js +217 -0
- package/src/tools/lspCodeIntel.ts +260 -0
- package/src/tools/manageLocalAiDependencies.js +242 -206
- package/src/tools/manageLocalAiDependencies.ts +288 -0
- package/src/tools/memoryRecall.js +62 -11
- package/src/tools/memoryRecall.ts +70 -13
- package/src/tools/memoryWrite.js +27 -14
- package/src/tools/memoryWrite.ts +30 -14
- package/src/tools/multiEdit.js +73 -63
- package/src/tools/multiEdit.ts +80 -65
- package/src/tools/nativeEngine.js +33 -18
- package/src/tools/nativeEngine.ts +31 -18
- package/src/tools/openSourceToolProvisioner.js +49 -14
- package/src/tools/openSourceToolProvisioner.ts +54 -15
- package/src/tools/osSandbox.js +202 -25
- package/src/tools/osSandbox.ts +192 -25
- package/src/tools/palmierAutomator.js +147 -95
- package/src/tools/palmierAutomator.ts +171 -0
- package/src/tools/payloadSanitizer.js +40 -8
- package/src/tools/payloadSanitizer.ts +39 -8
- package/src/tools/pdfReader.js +95 -104
- package/src/tools/pdfReader.ts +125 -0
- package/src/tools/peerAgent.js +96 -34
- package/src/tools/peerAgent.ts +114 -37
- package/src/tools/persistentShell.js +267 -144
- package/src/tools/persistentShell.ts +314 -0
- package/src/tools/pluginManager.js +84 -72
- package/src/tools/pluginManager.ts +109 -0
- package/src/tools/pluginsFactory.js +38 -6
- package/src/tools/pluginsFactory.ts +42 -6
- package/src/tools/printer.js +278 -296
- package/src/tools/printer.ts +326 -0
- package/src/tools/procTerm.js +96 -83
- package/src/tools/procTerm.ts +127 -0
- package/src/tools/processList.js +45 -48
- package/src/tools/processList.ts +73 -0
- package/src/tools/readNativeSkill.js +10 -8
- package/src/tools/readNativeSkill.ts +10 -8
- package/src/tools/registry.js +298 -286
- package/src/tools/registry.ts +486 -0
- package/src/tools/repoMap.js +46 -0
- package/src/tools/repoMap.ts +66 -0
- package/src/tools/requestDecision.js +10 -3
- package/src/tools/requestDecision.ts +10 -3
- package/src/tools/resolveAutomator.js +91 -17
- package/src/tools/resolveAutomator.ts +102 -17
- package/src/tools/reverseEngineering.js +168 -41
- package/src/tools/reverseEngineering.ts +161 -41
- package/src/tools/subagentOrchestrator.js +404 -348
- package/src/tools/subagentOrchestrator.ts +457 -0
- package/src/tools/sysRun.js +148 -51
- package/src/tools/sysRun.ts +142 -46
- package/src/tools/toolDispatch.js +24 -1
- package/src/tools/toolDispatch.ts +21 -1
- package/src/tools/toolForge.js +84 -67
- package/src/tools/toolForge.ts +102 -0
- package/src/tools/toolOutputStore.js +62 -23
- package/src/tools/toolOutputStore.ts +56 -23
- package/src/tools/toolPathSafety.js +262 -0
- package/src/tools/toolPathSafety.ts +308 -0
- package/src/tools/toolScanner.js +41 -10
- package/src/tools/toolScanner.ts +42 -10
- package/src/tools/toolSelfRepair.js +115 -34
- package/src/tools/toolSelfRepair.ts +122 -34
- package/src/tools/uiForge.js +71 -6
- package/src/tools/uiForge.ts +74 -6
- package/src/tools/viewImage.js +62 -17
- package/src/tools/viewImage.ts +57 -12
- package/src/tools/visionInspector.js +15 -3
- package/src/tools/visionInspector.ts +15 -3
- package/src/tools/walkerSafety.js +2 -0
- package/src/tools/walkerSafety.ts +2 -0
- package/src/tools/webFetch.js +110 -12
- package/src/tools/webFetch.ts +110 -13
- package/src/toolsList.js +5 -0
- package/src/toolsList.ts +5 -0
- package/src/tui/ask.js +159 -168
- package/src/tui/ask.ts +259 -0
- package/src/tui/banner.js +3 -2
- package/src/tui/banner.ts +3 -2
- package/src/tui/block.js +0 -1
- package/src/tui/block.ts +0 -1
- package/src/tui/chatRenderer.js +1193 -1441
- package/src/tui/chatRenderer.ts +1336 -0
- package/src/tui/clipboardImage.js +36 -12
- package/src/tui/clipboardImage.ts +39 -13
- package/src/tui/clipboardSync.js +34 -9
- package/src/tui/clipboardSync.ts +38 -9
- package/src/tui/codeProgress.js +0 -1
- package/src/tui/codeProgress.ts +0 -1
- package/src/tui/completion.js +395 -371
- package/src/tui/completion.ts +574 -0
- package/src/tui/composerControls.js +113 -19
- package/src/tui/composerControls.ts +124 -19
- package/src/tui/consoleGuard.js +39 -11
- package/src/tui/consoleGuard.ts +38 -11
- package/src/tui/dialogs.js +864 -717
- package/src/tui/dialogs.ts +984 -0
- package/src/tui/diff.js +205 -195
- package/src/tui/diff.ts +336 -0
- package/src/tui/history.js +143 -108
- package/src/tui/history.ts +167 -0
- package/src/tui/home.js +165 -161
- package/src/tui/home.ts +251 -0
- package/src/tui/invocation.js +58 -65
- package/src/tui/invocation.ts +117 -0
- package/src/tui/keys.js +437 -420
- package/src/tui/keys.ts +597 -0
- package/src/tui/lineEditor.js +477 -432
- package/src/tui/lineEditor.ts +542 -0
- package/src/tui/messageActionPlacement.js +0 -1
- package/src/tui/messageActionPlacement.ts +0 -1
- package/src/tui/messageInteraction.js +2 -5
- package/src/tui/messageInteraction.ts +2 -5
- package/src/tui/modelPicker.js +1 -3
- package/src/tui/modelPicker.ts +4 -6
- package/src/tui/observerPicker.js +0 -2
- package/src/tui/observerPicker.ts +0 -2
- package/src/tui/overlay.js +3 -2
- package/src/tui/overlay.ts +3 -2
- package/src/tui/prompt.js +1816 -2151
- package/src/tui/prompt.ts +1870 -0
- package/src/tui/runningLight.js +0 -1
- package/src/tui/runningLight.ts +0 -1
- package/src/tui/selectList.js +365 -337
- package/src/tui/selectList.ts +441 -0
- package/src/tui/sessionPicker.js +3 -3
- package/src/tui/sessionPicker.ts +3 -3
- package/src/tui/sessionPickerView.js +7 -3
- package/src/tui/sessionPickerView.ts +10 -22
- package/src/tui/sessionSidebar.js +3 -1
- package/src/tui/sessionSidebar.ts +4 -1
- package/src/tui/setup.js +17 -5
- package/src/tui/setup.ts +19 -5
- package/src/tui/skillAuthoring.js +0 -2
- package/src/tui/skillAuthoring.ts +0 -3
- package/src/tui/stageSurface.js +829 -909
- package/src/tui/stageSurface.ts +1003 -0
- package/src/tui/statusLine.js +7 -4
- package/src/tui/statusLine.ts +7 -3
- package/src/tui/terminalInputFramer.js +82 -69
- package/src/tui/terminalInputFramer.ts +116 -0
- package/src/tui/text.js +25 -10
- package/src/tui/text.ts +24 -10
- package/src/tui/textLayout.js +0 -1
- package/src/tui/textLayout.ts +0 -1
- package/src/tui/theme.js +245 -250
- package/src/tui/theme.ts +441 -0
- package/src/tui/thinkingBox.js +0 -1
- package/src/tui/thinkingBox.ts +0 -1
- package/src/tui/toolOutputNormalizer.js +2 -3
- package/src/tui/toolOutputNormalizer.ts +4 -3
- package/src/tui/transcript.js +239 -216
- package/src/tui/transcript.ts +324 -0
- package/src/tui/turnRail.js +53 -54
- package/src/tui/turnRail.ts +51 -49
- package/src/tui/usageCard.js +0 -2
- package/src/tui/usageCard.ts +0 -2
- package/src/tui/viewport.js +4 -4
- package/src/tui/viewport.ts +5 -5
- package/src/tui/workspaceIdentity.js +2 -1
- package/src/tui/workspaceIdentity.ts +2 -1
- package/src/tui/workspaceSwitch.js +4 -2
- package/src/tui/workspaceSwitch.ts +5 -2
- package/src/types/contracts.ts +4 -1
- package/src/uncertainty.js +8 -3
- package/src/uncertainty.ts +8 -3
- package/src/utils/browserOpen.js +107 -0
- package/src/utils/browserOpen.ts +129 -0
- package/src/utils/cli_ui.js +0 -0
- package/src/utils/cli_ui.ts +158 -0
- package/src/utils/paths.js +8 -5
- package/src/utils/paths.ts +9 -7
- package/src/utils/winSpawn.js +248 -0
- package/src/utils/winSpawn.ts +275 -0
- package/src/verification/boundedExplorer.js +138 -107
- package/src/verification/boundedExplorer.ts +154 -0
- package/src/verification/byokSmokeProbe.js +193 -0
- package/src/verification/byokSmokeProbe.ts +234 -0
- package/src/verification/cliProbe.js +144 -110
- package/src/verification/cliProbe.ts +170 -0
- package/src/verification/featureMap.js +105 -75
- package/src/verification/featureMap.ts +124 -0
- package/src/verification/interactivePty.js +195 -100
- package/src/verification/interactivePty.ts +333 -0
- package/src/verification/propertyProbe.js +109 -101
- package/src/verification/propertyProbe.ts +159 -0
- package/src/verification/ptyProbe.js +168 -73
- package/src/verification/ptyProbe.ts +254 -0
- package/src/verification/skillCatalog.js +25 -25
- package/src/verification/skillCatalog.ts +66 -0
- package/src/verification/statechart.js +140 -127
- package/src/verification/statechart.ts +196 -0
- package/src/verification/uiRuntime.js +80 -49
- package/src/verification/uiRuntime.ts +88 -0
- package/src/version.js +37 -32
- package/src/version.ts +45 -0
- package/src/vfeTracker.js +9 -3
- package/src/vfeTracker.ts +9 -3
- package/src/web/guiLauncher.js +89 -0
- package/src/web/guiLauncher.ts +119 -0
- package/src/web/skybridgeBrowserBridge.js +256 -0
- package/src/web/skybridgeBrowserBridge.ts +285 -0
- package/src/web/skybridgeBrowserMcp.js +730 -0
- package/src/web/skybridgeBrowserMcp.ts +813 -0
- package/src/web/skybridgeClientScript.js +3951 -0
- package/src/web/skybridgeClientScript.ts +3952 -0
- package/src/web/skybridgeServer.js +2622 -0
- package/src/web/skybridgeServer.ts +2787 -0
- package/src/web/skybridgeStyles.js +827 -0
- package/src/web/skybridgeStyles.ts +828 -0
- package/src/web/skybridgeUi.js +472 -0
- package/src/web/skybridgeUi.ts +485 -0
- package/src/worktreeManager.js +511 -0
- package/src/worktreeManager.ts +546 -0
- package/src/zeroCostFailover.js +168 -0
- package/src/zeroCostFailover.ts +198 -0
- package/src/zeroCostRouting.js +391 -0
- package/src/zeroCostRouting.ts +437 -0
- package/src/agentLoop.d.ts +0 -65
- package/src/auditLog.d.ts +0 -3
- package/src/checkpoints.d.ts +0 -4
- package/src/compiledSkills.d.ts +0 -5
- package/src/config.d.ts +0 -2
- package/src/contextManager.d.ts +0 -14
- package/src/designPalettes.d.ts +0 -2
- package/src/devMode.d.ts +0 -1
- package/src/embodimentSession.d.ts +0 -2
- package/src/licensing/entitlements.d.ts +0 -14
- package/src/memory.d.ts +0 -13
- package/src/memoryManager.d.ts +0 -1
- package/src/modelCatalogue.d.ts +0 -6
- package/src/modelIds.d.ts +0 -2
- package/src/outputStore.d.ts +0 -4
- package/src/plugins/pluginManager.d.ts +0 -7
- package/src/providers/antigravity.d.ts +0 -19
- package/src/providers/base.d.ts +0 -94
- package/src/providers/factory.d.ts +0 -1
- package/src/provisioning/capabilityProvisioner.d.ts +0 -12
- package/src/sandbox.d.ts +0 -1
- package/src/slopDetector.d.ts +0 -3
- package/src/taskBuffer.d.ts +0 -1
- package/src/tools/desktopAct.d.ts +0 -10
- package/src/tools/registry.d.ts +0 -5
- package/src/tui/chatRenderer.d.ts +0 -27
- package/src/tui/diff.d.ts +0 -3
- package/src/utils/cli_ui.d.ts +0 -19
- package/src/utils/paths.d.ts +0 -3
- package/src/verification/skillCatalog.d.ts +0 -1
- package/src/version.d.ts +0 -1
|
@@ -0,0 +1,3952 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Causyne Web Interface Client Runtime
|
|
3
|
+
*
|
|
4
|
+
* Pure DOM-constructed browser client (zero untrusted HTML sinks, zero external
|
|
5
|
+
* CDN scripts) uniting:
|
|
6
|
+
* - ChatGPT-grade conversational ergonomics (persistent drafts, IME-safe
|
|
7
|
+
* composer, smart auto-scroll, grouped sessions, anchored popovers)
|
|
8
|
+
* - Claude-grade agent-loop & workspace presentation (live pulsing activity
|
|
9
|
+
* bar, grouped collapsible tool timeline, implementation plan checklist,
|
|
10
|
+
* live streaming code & document Artifact cards with version history,
|
|
11
|
+
* structured tool approvals with session-scoped "Always allow", resizable
|
|
12
|
+
* split Studio pane, @file mention autocomplete, and embedded loopback /
|
|
13
|
+
* sandboxed HTML & SVG Live Browser preview).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export function getSkybridgeClientScript(): string {
|
|
17
|
+
return [
|
|
18
|
+
'(function () {',
|
|
19
|
+
' "use strict";',
|
|
20
|
+
' const DRAFT_KEY = "causyne/web/composerDraft/v1";',
|
|
21
|
+
' const THEME_KEY = "causyne/web/theme/v1";',
|
|
22
|
+
' const MODE_KEY = "causyne/web/autonomyMode/v1";',
|
|
23
|
+
' const STUDIO_WIDTH_KEY = "causyne/web/studioWidth/v1";',
|
|
24
|
+
' const DEFAULT_STUDIO_W = 480;',
|
|
25
|
+
'',
|
|
26
|
+
' const hashParams = new URLSearchParams((window.location.hash || "").replace(/^#/, ""));',
|
|
27
|
+
' const TOKEN_STORE_KEY = "causyne/web/token:" + window.location.origin;',
|
|
28
|
+
' let sessionToken = hashParams.get("token") || "";',
|
|
29
|
+
' if (sessionToken) {',
|
|
30
|
+
' try { window.sessionStorage.setItem(TOKEN_STORE_KEY, sessionToken); } catch {}',
|
|
31
|
+
' try { window.history.replaceState(null, "", window.location.pathname + window.location.search); } catch {}',
|
|
32
|
+
' } else {',
|
|
33
|
+
' try { sessionToken = window.sessionStorage.getItem(TOKEN_STORE_KEY) || ""; } catch {}',
|
|
34
|
+
' }',
|
|
35
|
+
'',
|
|
36
|
+
' let apiBase = "";',
|
|
37
|
+
' try {',
|
|
38
|
+
' const qs = new URLSearchParams(window.location.search || "");',
|
|
39
|
+
' const bridge = (qs.get("bridge") || "").trim();',
|
|
40
|
+
' if (bridge) {',
|
|
41
|
+
' const parsed = new URL(bridge);',
|
|
42
|
+
' const host = parsed.hostname.toLowerCase();',
|
|
43
|
+
' if (parsed.protocol === "http:" && (host === "127.0.0.1" || host === "localhost")) {',
|
|
44
|
+
' apiBase = parsed.origin;',
|
|
45
|
+
' }',
|
|
46
|
+
' }',
|
|
47
|
+
' } catch {}',
|
|
48
|
+
'',
|
|
49
|
+
' const el = (id) => document.getElementById(id);',
|
|
50
|
+
' const appEl = el("app");',
|
|
51
|
+
' const stageEl = el("stage");',
|
|
52
|
+
' const threadWrapEl = el("thread-wrap");',
|
|
53
|
+
' const threadEl = el("thread");',
|
|
54
|
+
' const scrollBottomBtn = el("scroll-bottom-btn");',
|
|
55
|
+
' const ariaStatusEl = el("aria-status");',
|
|
56
|
+
' const ariaAlertEl = el("aria-alert");',
|
|
57
|
+
' const sidebarBackdrop = el("sidebar-backdrop");',
|
|
58
|
+
' const closeSidebarBtn = el("close-sidebar-btn");',
|
|
59
|
+
' const openSidebarBtn = el("open-sidebar-btn");',
|
|
60
|
+
' const newChatBtn = el("new-chat-btn");',
|
|
61
|
+
' const navFilesBtn = el("nav-files-btn");',
|
|
62
|
+
' const navCanvasBtn = el("nav-canvas-btn");',
|
|
63
|
+
' const navBrowserBtn = el("nav-browser-btn");',
|
|
64
|
+
' const navCliBtn = el("nav-cli-btn");',
|
|
65
|
+
' const navDiffBtn = el("nav-diff-btn");',
|
|
66
|
+
' const navSettingsBtn = el("nav-settings-btn");',
|
|
67
|
+
' const sessionSearchEl = el("session-search");',
|
|
68
|
+
' const sessionListEl = el("session-list");',
|
|
69
|
+
' const wsNameEl = el("ws-pill");',
|
|
70
|
+
' const wsMetaEl = el("ws-meta");',
|
|
71
|
+
' const modelTriggerBtn = el("model-trigger");',
|
|
72
|
+
' const modelTriggerName = el("model-trigger-name");',
|
|
73
|
+
' const modelPopover = el("model-popover");',
|
|
74
|
+
' const livenessPill = el("liveness-pill");',
|
|
75
|
+
' const livenessText = el("liveness-text");',
|
|
76
|
+
' const usagePill = el("usage-pill");',
|
|
77
|
+
' const modeSelect = el("mode-select");',
|
|
78
|
+
' const studioToggleBtn = el("studio-toggle-btn");',
|
|
79
|
+
' const studioExpandBtn = el("studio-expand-btn");',
|
|
80
|
+
' const studioCloseBtn = el("studio-close-btn");',
|
|
81
|
+
' const studioResizer = el("studio-resizer");',
|
|
82
|
+
' const studioRoot = el("studio-pane-root");',
|
|
83
|
+
' const chatForm = el("chat-form");',
|
|
84
|
+
' const composerPill = el("composer-pill");',
|
|
85
|
+
' const composerChipsEl = el("composer-chips");',
|
|
86
|
+
' const mentionPopover = el("mention-popover");',
|
|
87
|
+
' const plusBtn = el("plus-btn");',
|
|
88
|
+
' const plusPopover = el("plus-popover");',
|
|
89
|
+
' const promptInput = el("prompt-input");',
|
|
90
|
+
' const sendBtn = el("send-btn");',
|
|
91
|
+
' const heroHelpBtn = el("hero-help-btn");',
|
|
92
|
+
' const fileFilterEl = el("file-filter");',
|
|
93
|
+
' const fileUpBtn = el("file-up-btn");',
|
|
94
|
+
' const refreshFilesBtn = el("refresh-files");',
|
|
95
|
+
' const fileListEl = el("file-list");',
|
|
96
|
+
' const filePathInput = el("file-path-input");',
|
|
97
|
+
' const fileContentInput = el("file-content-input");',
|
|
98
|
+
' const canvasPreviewEl = el("canvas-preview");',
|
|
99
|
+
' const canvasHtmlFrame = el("canvas-html-frame");',
|
|
100
|
+
' const canvasCodeBtn = el("canvas-code-btn");',
|
|
101
|
+
' const canvasModeBtn = el("canvas-mode-btn");',
|
|
102
|
+
' const artifactVersionSelect = el("artifact-version-select");',
|
|
103
|
+
' const canvasDownloadBtn = el("canvas-download-btn");',
|
|
104
|
+
' const canvasRefineBtn = el("canvas-refine-btn");',
|
|
105
|
+
' const saveFileBtn = el("save-file-btn");',
|
|
106
|
+
' const fileStatusEl = el("file-status");',
|
|
107
|
+
' const browserUrlInput = el("browser-url-input");',
|
|
108
|
+
' const browserBackBtn = el("browser-back-btn");',
|
|
109
|
+
' const browserFwdBtn = el("browser-fwd-btn");',
|
|
110
|
+
' const browserReloadBtn = el("browser-reload-btn");',
|
|
111
|
+
' const browserFrame = el("browser-frame");',
|
|
112
|
+
' const liveViewportSurface = el("live-viewport-surface");',
|
|
113
|
+
' const liveBrowserImg = el("live-browser-img");',
|
|
114
|
+
' const browserAgentBanner = el("browser-agent-banner");',
|
|
115
|
+
' const browserAgentBannerText = el("browser-agent-banner-text");',
|
|
116
|
+
' const bannerTakeControlBtn = el("banner-take-control-btn");',
|
|
117
|
+
' const browserTabsRow = el("browser-tabs-row");',
|
|
118
|
+
' const browserTabsEl = el("browser-tabs");',
|
|
119
|
+
' const browserNewTabBtn = el("browser-new-tab-btn");',
|
|
120
|
+
' const browserMoreBtn = el("browser-more-btn");',
|
|
121
|
+
' const browserMorePopover = el("browser-more-popover");',
|
|
122
|
+
' const bmodeAgentBtn = el("bmode-agent-btn");',
|
|
123
|
+
' const bmodeFrameBtn = el("bmode-frame-btn");',
|
|
124
|
+
' const browserEngineSelect = el("browser-engine-select");',
|
|
125
|
+
' const browserNativeWinBtn = el("browser-native-win-btn");',
|
|
126
|
+
' const browserHandoffBtn = el("browser-handoff-btn");',
|
|
127
|
+
' const browserSyncToggleBtn = el("browser-sync-toggle-btn");',
|
|
128
|
+
' const browserSyncDrawer = el("browser-sync-drawer");',
|
|
129
|
+
' const cdpPortInput = el("cdp-port-input");',
|
|
130
|
+
' const cdpScanBtn = el("cdp-scan-btn");',
|
|
131
|
+
' const cdpTabsList = el("cdp-tabs-list");',
|
|
132
|
+
' const cdpSyncStatus = el("cdp-sync-status");',
|
|
133
|
+
' const browserImportInput = el("browser-import-input");',
|
|
134
|
+
' const browserImportBtn = el("browser-import-btn");',
|
|
135
|
+
' const browserStartBtn = el("browser-start-btn");',
|
|
136
|
+
' const browserStartNativeBtn = el("browser-start-native-btn");',
|
|
137
|
+
' const browserCloseEngineBtn = el("browser-close-engine-btn");',
|
|
138
|
+
' const browserSnapshotBtn = el("browser-snapshot-btn");',
|
|
139
|
+
' const browserEmpty = el("browser-empty");',
|
|
140
|
+
' const browserDemoBtn = el("browser-demo-btn");',
|
|
141
|
+
' const browserOpenExtBtn = el("browser-open-ext-btn");',
|
|
142
|
+
' const cliCmdInput = el("cli-cmd-input");',
|
|
143
|
+
' const cliRunBtn = el("cli-run-btn");',
|
|
144
|
+
' const cliStatsEl = el("cli-stats");',
|
|
145
|
+
' const cliQuickGrid = el("cli-quick-grid");',
|
|
146
|
+
' const cliConsoleEl = el("cli-console");',
|
|
147
|
+
' const cliStatusEl = el("cli-status");',
|
|
148
|
+
' const cliProbeBtn = el("cli-probe-btn");',
|
|
149
|
+
' const vaultProviderSelect = el("vault-provider-select");',
|
|
150
|
+
' const vaultKeyInput = el("vault-key-input");',
|
|
151
|
+
' const vaultSaveBtn = el("vault-save-btn");',
|
|
152
|
+
' const vaultStatusEl = el("vault-status");',
|
|
153
|
+
' const diffScopeSessionBtn = el("diff-scope-session");',
|
|
154
|
+
' const diffScopeWorkspaceBtn = el("diff-scope-workspace");',
|
|
155
|
+
' const diffStagedToggle = el("diff-staged-toggle");',
|
|
156
|
+
' const refreshDiffBtn = el("refresh-diff-btn");',
|
|
157
|
+
' const diffSummaryEl = el("diff-summary");',
|
|
158
|
+
' const diffListEl = el("diff-list");',
|
|
159
|
+
' const settingsModal = el("settings-modal");',
|
|
160
|
+
' const settingsCloseBtn = el("settings-close-btn");',
|
|
161
|
+
' const themeToggleBtn = el("theme-toggle-btn");',
|
|
162
|
+
' const doctorLoadBtn = el("doctor-load-btn");',
|
|
163
|
+
' const doctorPre = el("doctor-pre");',
|
|
164
|
+
' const settingsWsPath = el("settings-ws-path");',
|
|
165
|
+
' const licenseSummaryEl = el("license-summary");',
|
|
166
|
+
' const licenseBadgeEl = el("license-badge");',
|
|
167
|
+
' const licenseMeterWrap = el("license-meter-wrap");',
|
|
168
|
+
' const licenseMeterFill = el("license-meter-fill");',
|
|
169
|
+
' const licenseSupportNote = el("license-support-note");',
|
|
170
|
+
' const licensePlanSelect = el("license-plan-select");',
|
|
171
|
+
' const licenseUpgradeBtn = el("license-upgrade-btn");',
|
|
172
|
+
' const licensePortalBtn = el("license-portal-btn");',
|
|
173
|
+
' const licenseRefreshBtn = el("license-refresh-btn");',
|
|
174
|
+
' const licenseRecoveryInput = el("license-recovery-input");',
|
|
175
|
+
' const licenseRecoverBtn = el("license-recover-btn");',
|
|
176
|
+
' const licenseStatusMsg = el("license-status-msg");',
|
|
177
|
+
'',
|
|
178
|
+
' const state = {',
|
|
179
|
+
' sessionId: null,',
|
|
180
|
+
' sessions: [],',
|
|
181
|
+
' models: null,',
|
|
182
|
+
' modelTab: null,',
|
|
183
|
+
' modelQuery: "",',
|
|
184
|
+
' modelExpandedPeers: new Set(),',
|
|
185
|
+
' modelSelectedIndex: 0,',
|
|
186
|
+
' modelRefreshing: false,',
|
|
187
|
+
' modelLiveHydrated: false,',
|
|
188
|
+
' modelNotice: "",',
|
|
189
|
+
' activeProvider: "unconfigured",',
|
|
190
|
+
' activeModel: "default",',
|
|
191
|
+
' workspaceRoot: "",',
|
|
192
|
+
' lastScrollTop: 0,',
|
|
193
|
+
' attachments: [],',
|
|
194
|
+
' currentDir: "",',
|
|
195
|
+
' parentDir: "",',
|
|
196
|
+
' studioTab: "files",',
|
|
197
|
+
' studioExpanded: false,',
|
|
198
|
+
' studioWidth: DEFAULT_STUDIO_W,',
|
|
199
|
+
' canvasPreviewMode: false,',
|
|
200
|
+
' canvasDirty: false,',
|
|
201
|
+
' artifactVersions: new Map(),',
|
|
202
|
+
' sessionWorkspaces: new Map(),',
|
|
203
|
+
' sessionSwitchSeq: 0,',
|
|
204
|
+
' usageTokens: 0,',
|
|
205
|
+
' diffScope: "session",',
|
|
206
|
+
' browserEngine: "agent",',
|
|
207
|
+
' browserMode: "empty",',
|
|
208
|
+
' browserUrl: "",',
|
|
209
|
+
' browserSrcdoc: "",',
|
|
210
|
+
' browserViewport: "desktop",',
|
|
211
|
+
' liveBrowserActive: false,',
|
|
212
|
+
' liveBrowserVisible: false,',
|
|
213
|
+
' liveBrowserRuntime: null,',
|
|
214
|
+
' liveBrowserPref: "auto",',
|
|
215
|
+
' liveStreamMode: "idle",',
|
|
216
|
+
' liveStreamAbort: null,',
|
|
217
|
+
' liveStreamConnected: false,',
|
|
218
|
+
' liveFps: 0,',
|
|
219
|
+
' pointerDragging: false,',
|
|
220
|
+
' liveBrowserWidth: 1280,',
|
|
221
|
+
' liveBrowserHeight: 800,',
|
|
222
|
+
' controlOwner: "human",',
|
|
223
|
+
' cliCommands: [],',
|
|
224
|
+
' mentionMode: "file",',
|
|
225
|
+
' mentionItems: [],',
|
|
226
|
+
' mentionIndex: 0,',
|
|
227
|
+
' mentionStart: -1,',
|
|
228
|
+
' diffStaged: false,',
|
|
229
|
+
' isComposing: false,',
|
|
230
|
+
' stickToBottom: true,',
|
|
231
|
+
' activeController: null,',
|
|
232
|
+
' activeTurn: null,',
|
|
233
|
+
' activePrompt: ""',
|
|
234
|
+
' };',
|
|
235
|
+
'',
|
|
236
|
+
' function apiUrl(p) { return apiBase + p; }',
|
|
237
|
+
' function authHeaders(extra) {',
|
|
238
|
+
' return Object.assign({ "Authorization": "Bearer " + sessionToken }, extra || {});',
|
|
239
|
+
' }',
|
|
240
|
+
' function announceStatus(msg) { if (ariaStatusEl) ariaStatusEl.textContent = msg; }',
|
|
241
|
+
' function announceAlert(msg) { if (ariaAlertEl) ariaAlertEl.textContent = msg; }',
|
|
242
|
+
'',
|
|
243
|
+
' function setLiveness(active, label) {',
|
|
244
|
+
' const isActive = Boolean(active);',
|
|
245
|
+
' livenessPill.classList.toggle("active", isActive);',
|
|
246
|
+
' appEl.classList.toggle("is-processing", isActive);',
|
|
247
|
+
' if (label) livenessText.textContent = label;',
|
|
248
|
+
' if (state.activeTurn && typeof state.activeTurn.setActivity === "function") {',
|
|
249
|
+
' state.activeTurn.setActivity(isActive, label || "Thinking...");',
|
|
250
|
+
' }',
|
|
251
|
+
' }',
|
|
252
|
+
'',
|
|
253
|
+
' function applyTheme(theme) {',
|
|
254
|
+
' const next = theme === "light" ? "light" : "dark";',
|
|
255
|
+
' document.documentElement.setAttribute("data-theme", next);',
|
|
256
|
+
' if (themeToggleBtn) themeToggleBtn.textContent = next === "light" ? "Dark" : "Light";',
|
|
257
|
+
' try { window.localStorage.setItem(THEME_KEY, next); } catch {}',
|
|
258
|
+
' }',
|
|
259
|
+
' function clampStudioWidth(raw) {',
|
|
260
|
+
' const n = Number(raw);',
|
|
261
|
+
' const sidebarW = appEl.classList.contains("sidebar-collapsed") || window.innerWidth <= 960 ? 0 : 256;',
|
|
262
|
+
' const minW = 320;',
|
|
263
|
+
' const maxByChat = Math.max(minW, window.innerWidth - sidebarW - 360);',
|
|
264
|
+
' const maxW = Math.max(minW, Math.min(Math.floor(window.innerWidth * 0.72), maxByChat));',
|
|
265
|
+
' const base = Number.isFinite(n) && n > 0 ? Math.round(n) : DEFAULT_STUDIO_W;',
|
|
266
|
+
' return Math.max(minW, Math.min(maxW, base));',
|
|
267
|
+
' }',
|
|
268
|
+
' function syncExpandedStudioWidth() {',
|
|
269
|
+
' const sidebarW = appEl.classList.contains("sidebar-collapsed") || window.innerWidth <= 960 ? 0 : 256;',
|
|
270
|
+
' const available = Math.max(360, window.innerWidth - sidebarW - 380);',
|
|
271
|
+
' const expandedW = Math.min(1040, Math.max(360, available));',
|
|
272
|
+
' document.documentElement.style.setProperty("--studio-expanded-w", expandedW + "px");',
|
|
273
|
+
' }',
|
|
274
|
+
' function applyStudioWidth(px, persist) {',
|
|
275
|
+
' const clamped = clampStudioWidth(px);',
|
|
276
|
+
' state.studioWidth = clamped;',
|
|
277
|
+
' document.documentElement.style.setProperty("--studio-w", clamped + "px");',
|
|
278
|
+
' syncExpandedStudioWidth();',
|
|
279
|
+
' if (studioRoot) { studioRoot.style.flexBasis = ""; studioRoot.style.width = ""; }',
|
|
280
|
+
' if (persist) { try { window.localStorage.setItem(STUDIO_WIDTH_KEY, String(clamped)); } catch {} }',
|
|
281
|
+
' }',
|
|
282
|
+
' try {',
|
|
283
|
+
' const savedTheme = window.localStorage.getItem(THEME_KEY);',
|
|
284
|
+
' if (savedTheme === "light" || savedTheme === "dark") applyTheme(savedTheme);',
|
|
285
|
+
' const savedMode = window.localStorage.getItem(MODE_KEY);',
|
|
286
|
+
' if (savedMode === "A" || savedMode === "B" || savedMode === "C") modeSelect.value = savedMode;',
|
|
287
|
+
' const savedDraft = window.localStorage.getItem(DRAFT_KEY);',
|
|
288
|
+
' if (savedDraft) promptInput.value = savedDraft;',
|
|
289
|
+
' const savedW = window.localStorage.getItem(STUDIO_WIDTH_KEY);',
|
|
290
|
+
' if (savedW) applyStudioWidth(savedW, false);',
|
|
291
|
+
' } catch {}',
|
|
292
|
+
'',
|
|
293
|
+
' if (window.innerWidth <= 960) appEl.classList.add("sidebar-collapsed");',
|
|
294
|
+
'',
|
|
295
|
+
' function setStageMode(hasMessages) {',
|
|
296
|
+
' stageEl.classList.toggle("is-empty", !hasMessages);',
|
|
297
|
+
' stageEl.classList.toggle("has-messages", hasMessages);',
|
|
298
|
+
' }',
|
|
299
|
+
'',
|
|
300
|
+
' function updateComposerMetrics() {',
|
|
301
|
+
' promptInput.style.height = "auto";',
|
|
302
|
+
' const nextH = Math.min(200, Math.max(26, promptInput.scrollHeight));',
|
|
303
|
+
' promptInput.style.height = nextH + "px";',
|
|
304
|
+
' const hasText = Boolean((promptInput.value || "").trim());',
|
|
305
|
+
' const streaming = state.activeController !== null;',
|
|
306
|
+
' sendBtn.classList.toggle("ready", !streaming && hasText);',
|
|
307
|
+
' sendBtn.classList.toggle("stopping", streaming);',
|
|
308
|
+
' sendBtn.setAttribute("aria-label", streaming ? "Stop response" : "Send message");',
|
|
309
|
+
' const iconSend = el("icon-send");',
|
|
310
|
+
' const iconStop = el("icon-stop");',
|
|
311
|
+
' if (iconSend) iconSend.style.display = streaming ? "none" : "block";',
|
|
312
|
+
' if (iconStop) iconStop.style.display = streaming ? "block" : "none";',
|
|
313
|
+
' try {',
|
|
314
|
+
' if (promptInput.value) window.localStorage.setItem(DRAFT_KEY, promptInput.value);',
|
|
315
|
+
' else window.localStorage.removeItem(DRAFT_KEY);',
|
|
316
|
+
' } catch {}',
|
|
317
|
+
' }',
|
|
318
|
+
'',
|
|
319
|
+
' function scrollToBottom(force, smooth) {',
|
|
320
|
+
' if (!threadWrapEl) return;',
|
|
321
|
+
' if (force || state.stickToBottom) {',
|
|
322
|
+
' if (smooth && typeof threadWrapEl.scrollTo === "function") {',
|
|
323
|
+
' threadWrapEl.scrollTo({ top: threadWrapEl.scrollHeight, behavior: "smooth" });',
|
|
324
|
+
' } else {',
|
|
325
|
+
' threadWrapEl.scrollTop = threadWrapEl.scrollHeight;',
|
|
326
|
+
' }',
|
|
327
|
+
' state.lastScrollTop = threadWrapEl.scrollTop;',
|
|
328
|
+
' state.stickToBottom = true;',
|
|
329
|
+
' scrollBottomBtn.classList.remove("visible");',
|
|
330
|
+
' }',
|
|
331
|
+
' }',
|
|
332
|
+
'',
|
|
333
|
+
' threadWrapEl.addEventListener("scroll", () => {',
|
|
334
|
+
' const curTop = threadWrapEl.scrollTop;',
|
|
335
|
+
' const gap = threadWrapEl.scrollHeight - curTop - threadWrapEl.clientHeight;',
|
|
336
|
+
' const atBottom = gap <= 24;',
|
|
337
|
+
' const scrollingDown = curTop >= state.lastScrollTop;',
|
|
338
|
+
' if (atBottom && scrollingDown) state.stickToBottom = true;',
|
|
339
|
+
' else if (!atBottom && !scrollingDown) state.stickToBottom = false;',
|
|
340
|
+
' state.lastScrollTop = curTop;',
|
|
341
|
+
' scrollBottomBtn.classList.toggle("visible", gap > 72 && !state.stickToBottom);',
|
|
342
|
+
' }, { passive: true });',
|
|
343
|
+
' scrollBottomBtn.addEventListener("click", () => scrollToBottom(true, true));',
|
|
344
|
+
'',
|
|
345
|
+
' function closeAllPopovers() {',
|
|
346
|
+
' modelPopover.classList.remove("open");',
|
|
347
|
+
' plusPopover.classList.remove("open");',
|
|
348
|
+
' mentionPopover.classList.remove("open");',
|
|
349
|
+
' browserMorePopover.classList.remove("open");',
|
|
350
|
+
' modelTriggerBtn.setAttribute("aria-expanded", "false");',
|
|
351
|
+
' plusBtn.setAttribute("aria-expanded", "false");',
|
|
352
|
+
' browserMoreBtn.setAttribute("aria-expanded", "false");',
|
|
353
|
+
' }',
|
|
354
|
+
'',
|
|
355
|
+
' function positionPopover(pop, anchor, preferUp) {',
|
|
356
|
+
' const rect = anchor.getBoundingClientRect();',
|
|
357
|
+
' pop.classList.add("open");',
|
|
358
|
+
' const pw = pop.offsetWidth || 300;',
|
|
359
|
+
' const ph = pop.offsetHeight || 220;',
|
|
360
|
+
' let left = rect.left;',
|
|
361
|
+
' if (left + pw > window.innerWidth - 10) left = rect.right - pw;',
|
|
362
|
+
' left = Math.max(10, Math.min(window.innerWidth - pw - 10, left));',
|
|
363
|
+
' let top = preferUp ? (rect.top - ph - 8) : (rect.bottom + 8);',
|
|
364
|
+
' if (top < 10) top = rect.bottom + 8;',
|
|
365
|
+
' if (top + ph > window.innerHeight - 10) top = Math.max(10, window.innerHeight - ph - 10);',
|
|
366
|
+
' pop.style.left = left + "px";',
|
|
367
|
+
' pop.style.top = top + "px";',
|
|
368
|
+
' }',
|
|
369
|
+
'',
|
|
370
|
+
' /* Safe URL & Loopback Validators */',
|
|
371
|
+
' function isSafeHttpUrl(raw) {',
|
|
372
|
+
' try {',
|
|
373
|
+
' const u = new URL(raw);',
|
|
374
|
+
' return u.protocol === "https:" || u.protocol === "http:";',
|
|
375
|
+
' } catch {',
|
|
376
|
+
' return false;',
|
|
377
|
+
' }',
|
|
378
|
+
' }',
|
|
379
|
+
'',
|
|
380
|
+
' function parseLoopbackUrl(raw) {',
|
|
381
|
+
' try {',
|
|
382
|
+
' const trimmed = String(raw || "").trim();',
|
|
383
|
+
' if (!trimmed) return null;',
|
|
384
|
+
' const normalized = /^https?:\\/\\//i.test(trimmed) ? trimmed : ("http://" + trimmed);',
|
|
385
|
+
' const u = new URL(normalized);',
|
|
386
|
+
' const host = u.hostname.toLowerCase();',
|
|
387
|
+
' if (u.protocol !== "http:") return null;',
|
|
388
|
+
' if (host !== "127.0.0.1" && host !== "localhost") return null;',
|
|
389
|
+
' return u.href;',
|
|
390
|
+
' } catch {',
|
|
391
|
+
' return null;',
|
|
392
|
+
' }',
|
|
393
|
+
' }',
|
|
394
|
+
'',
|
|
395
|
+
' function extractLoopbackUrls(text) {',
|
|
396
|
+
' const found = [];',
|
|
397
|
+
' const matches = String(text || "").match(/http:\\/\\/(?:127\\.0\\.0\\.1|localhost):\\d{2,5}(?:\\/[^\\s)\\[\\]\'"`<>]*)?/gi) || [];',
|
|
398
|
+
' for (const m of matches) {',
|
|
399
|
+
' const cleaned = m.replace(/[.,;:!?\\])+]+$/g, "");',
|
|
400
|
+
' const valid = parseLoopbackUrl(cleaned);',
|
|
401
|
+
' if (valid && !found.includes(valid)) found.push(valid);',
|
|
402
|
+
' }',
|
|
403
|
+
' return found.slice(0, 3);',
|
|
404
|
+
' }',
|
|
405
|
+
'',
|
|
406
|
+
' function parseWorkspaceFileHref(rawHref) {',
|
|
407
|
+
' const trimmed = String(rawHref || "").trim();',
|
|
408
|
+
' if (!trimmed.toLowerCase().startsWith("file://")) return null;',
|
|
409
|
+
' let body = trimmed.slice(7);',
|
|
410
|
+
' let lineBadge = "";',
|
|
411
|
+
' const hashIdx = body.indexOf("#");',
|
|
412
|
+
' if (hashIdx >= 0) {',
|
|
413
|
+
' const frag = body.slice(hashIdx + 1);',
|
|
414
|
+
' body = body.slice(0, hashIdx);',
|
|
415
|
+
' const lm = frag.match(/^L(\\d+)(?:-L?(\\d+))?$/i);',
|
|
416
|
+
' if (lm) lineBadge = lm[2] ? (":" + lm[1] + "-" + lm[2]) : (":" + lm[1]);',
|
|
417
|
+
' }',
|
|
418
|
+
' const qIdx = body.indexOf("?");',
|
|
419
|
+
' if (qIdx >= 0) body = body.slice(0, qIdx);',
|
|
420
|
+
' try { body = decodeURIComponent(body); } catch {}',
|
|
421
|
+
' const wsRoot = String(state.workspaceRoot || "").replace(/\\/+$/, "");',
|
|
422
|
+
' const normPrivate = (p) => p.replace(/^\\/private(?=\\/(?:var|tmp)(?:\\/|$))/, "");',
|
|
423
|
+
' const bodyNorm = normPrivate(body);',
|
|
424
|
+
' const wsNorm = normPrivate(wsRoot);',
|
|
425
|
+
' let relPath = null;',
|
|
426
|
+
' if (wsNorm && bodyNorm.startsWith(wsNorm + "/")) {',
|
|
427
|
+
' relPath = bodyNorm.slice(wsNorm.length + 1);',
|
|
428
|
+
' }',
|
|
429
|
+
' const display = relPath || body.split("/").slice(-2).join("/") || body;',
|
|
430
|
+
' return { fullPath: body, relPath, display, lineBadge };',
|
|
431
|
+
' }',
|
|
432
|
+
'',
|
|
433
|
+
' function createInlineFileChip(label, fileInfo) {',
|
|
434
|
+
' const btn = document.createElement("button");',
|
|
435
|
+
' btn.type = "button";',
|
|
436
|
+
' btn.className = "md-file-chip" + (fileInfo.relPath ? "" : " is-static");',
|
|
437
|
+
' btn.title = fileInfo.fullPath + fileInfo.lineBadge;',
|
|
438
|
+
' const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");',
|
|
439
|
+
' svg.setAttribute("viewBox", "0 0 24 24");',
|
|
440
|
+
' const p1 = document.createElementNS("http://www.w3.org/2000/svg", "path");',
|
|
441
|
+
' p1.setAttribute("d", "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8Z");',
|
|
442
|
+
' const p2 = document.createElementNS("http://www.w3.org/2000/svg", "polyline");',
|
|
443
|
+
' p2.setAttribute("points", "14 2 14 8 20 8");',
|
|
444
|
+
' svg.appendChild(p1); svg.appendChild(p2);',
|
|
445
|
+
' btn.appendChild(svg);',
|
|
446
|
+
' const nameEl = document.createElement("span");',
|
|
447
|
+
' nameEl.className = "md-file-chip-name";',
|
|
448
|
+
' const cleanLabel = String(label || "").replace(/^`|`$/g, "").trim();',
|
|
449
|
+
' const showLabel = (cleanLabel && !cleanLabel.startsWith("/Users/") && !cleanLabel.startsWith("/home/"))',
|
|
450
|
+
' ? cleanLabel : fileInfo.display;',
|
|
451
|
+
' nameEl.textContent = showLabel;',
|
|
452
|
+
' btn.appendChild(nameEl);',
|
|
453
|
+
' if (fileInfo.lineBadge) {',
|
|
454
|
+
' const ln = document.createElement("span");',
|
|
455
|
+
' ln.className = "md-file-chip-line";',
|
|
456
|
+
' ln.textContent = fileInfo.lineBadge;',
|
|
457
|
+
' btn.appendChild(ln);',
|
|
458
|
+
' }',
|
|
459
|
+
' if (fileInfo.relPath) {',
|
|
460
|
+
' btn.addEventListener("click", () => { void openFile(fileInfo.relPath); });',
|
|
461
|
+
' }',
|
|
462
|
+
' return btn;',
|
|
463
|
+
' }',
|
|
464
|
+
'',
|
|
465
|
+
' function isHtmlOrSvgPath(relPath) {',
|
|
466
|
+
' const p = String(relPath || "").toLowerCase();',
|
|
467
|
+
' return p.endsWith(".html") || p.endsWith(".htm") || p.endsWith(".svg");',
|
|
468
|
+
' }',
|
|
469
|
+
'',
|
|
470
|
+
' function artifactBadgeFor(relPath, lang) {',
|
|
471
|
+
' const p = String(relPath || "").toLowerCase();',
|
|
472
|
+
' if (p.endsWith(".idoc.md")) return { tag: "IDOC", label: "idoc Document" };',
|
|
473
|
+
' if (p.endsWith(".html") || p.endsWith(".htm") || lang === "html") return { tag: "HTML", label: "Interactive HTML" };',
|
|
474
|
+
' if (p.endsWith(".svg") || lang === "svg") return { tag: "SVG", label: "SVG Graphic" };',
|
|
475
|
+
' if (p.endsWith(".md") || lang === "markdown" || lang === "md") return { tag: "DOC", label: "Markdown Document" };',
|
|
476
|
+
' const ext = p.includes(".") ? p.split(".").pop().toUpperCase().slice(0, 4) : (lang ? lang.toUpperCase().slice(0, 4) : "CODE");',
|
|
477
|
+
' return { tag: ext || "CODE", label: "Source File" };',
|
|
478
|
+
' }',
|
|
479
|
+
'',
|
|
480
|
+
' /* Safe-DOM Inline & Block Markdown Renderer */',
|
|
481
|
+
' function appendInlineNodes(parent, text) {',
|
|
482
|
+
' let i = 0;',
|
|
483
|
+
' const len = text.length;',
|
|
484
|
+
' let buf = "";',
|
|
485
|
+
' function flush() {',
|
|
486
|
+
' if (buf) { parent.appendChild(document.createTextNode(buf)); buf = ""; }',
|
|
487
|
+
' }',
|
|
488
|
+
' while (i < len) {',
|
|
489
|
+
' if (text[i] === "`") {',
|
|
490
|
+
' const end = text.indexOf("`", i + 1);',
|
|
491
|
+
' if (end > i + 1) {',
|
|
492
|
+
' flush();',
|
|
493
|
+
' const c = document.createElement("code");',
|
|
494
|
+
' c.className = "inline-code";',
|
|
495
|
+
' c.textContent = text.slice(i + 1, end);',
|
|
496
|
+
' parent.appendChild(c);',
|
|
497
|
+
' i = end + 1;',
|
|
498
|
+
' continue;',
|
|
499
|
+
' }',
|
|
500
|
+
' }',
|
|
501
|
+
' if (text[i] === "*" && text[i + 1] === "*") {',
|
|
502
|
+
' const end = text.indexOf("**", i + 2);',
|
|
503
|
+
' if (end > i + 2) {',
|
|
504
|
+
' flush();',
|
|
505
|
+
' const s = document.createElement("strong");',
|
|
506
|
+
' appendInlineNodes(s, text.slice(i + 2, end));',
|
|
507
|
+
' parent.appendChild(s);',
|
|
508
|
+
' i = end + 2;',
|
|
509
|
+
' continue;',
|
|
510
|
+
' }',
|
|
511
|
+
' }',
|
|
512
|
+
' if (text[i] === "*" && text[i + 1] !== " " && text[i + 1] !== "*") {',
|
|
513
|
+
' const end = text.indexOf("*", i + 1);',
|
|
514
|
+
' if (end > i + 1 && text[end - 1] !== " ") {',
|
|
515
|
+
' flush();',
|
|
516
|
+
' const em = document.createElement("em");',
|
|
517
|
+
' em.textContent = text.slice(i + 1, end);',
|
|
518
|
+
' parent.appendChild(em);',
|
|
519
|
+
' i = end + 1;',
|
|
520
|
+
' continue;',
|
|
521
|
+
' }',
|
|
522
|
+
' }',
|
|
523
|
+
' if (text[i] === "[") {',
|
|
524
|
+
' const mid = text.indexOf("](", i + 1);',
|
|
525
|
+
' const end = mid > -1 ? text.indexOf(")", mid + 2) : -1;',
|
|
526
|
+
' if (mid > i + 1 && end > mid + 2) {',
|
|
527
|
+
' const label = text.slice(i + 1, mid);',
|
|
528
|
+
' const href = text.slice(mid + 2, end).trim();',
|
|
529
|
+
' if (isSafeHttpUrl(href)) {',
|
|
530
|
+
' flush();',
|
|
531
|
+
' const a = document.createElement("a");',
|
|
532
|
+
' a.href = href; a.target = "_blank"; a.rel = "noopener noreferrer";',
|
|
533
|
+
' a.textContent = label.replace(/^`|`$/g, "");',
|
|
534
|
+
' parent.appendChild(a);',
|
|
535
|
+
' i = end + 1;',
|
|
536
|
+
' continue;',
|
|
537
|
+
' }',
|
|
538
|
+
' const fileInfo = parseWorkspaceFileHref(href);',
|
|
539
|
+
' if (fileInfo) {',
|
|
540
|
+
' flush();',
|
|
541
|
+
' parent.appendChild(createInlineFileChip(label, fileInfo));',
|
|
542
|
+
' i = end + 1;',
|
|
543
|
+
' continue;',
|
|
544
|
+
' }',
|
|
545
|
+
' }',
|
|
546
|
+
' }',
|
|
547
|
+
' if ((text[i] === "h" && (text.startsWith("http://", i) || text.startsWith("https://", i)))) {',
|
|
548
|
+
' let j = i;',
|
|
549
|
+
' while (j < len && !/[\\s<>"\'`\\[\\]]/.test(text[j])) j += 1;',
|
|
550
|
+
' let rawUrl = text.slice(i, j);',
|
|
551
|
+
' let trail = "";',
|
|
552
|
+
' while (rawUrl.length > 0 && /[.,;:!?)]/.test(rawUrl[rawUrl.length - 1])) {',
|
|
553
|
+
' trail = rawUrl[rawUrl.length - 1] + trail;',
|
|
554
|
+
' rawUrl = rawUrl.slice(0, -1);',
|
|
555
|
+
' }',
|
|
556
|
+
' if (isSafeHttpUrl(rawUrl)) {',
|
|
557
|
+
' flush();',
|
|
558
|
+
' const a = document.createElement("a");',
|
|
559
|
+
' a.href = rawUrl; a.target = "_blank"; a.rel = "noopener noreferrer";',
|
|
560
|
+
' a.textContent = rawUrl;',
|
|
561
|
+
' parent.appendChild(a);',
|
|
562
|
+
' if (trail) buf += trail;',
|
|
563
|
+
' i = j;',
|
|
564
|
+
' continue;',
|
|
565
|
+
' }',
|
|
566
|
+
' }',
|
|
567
|
+
' buf += text[i];',
|
|
568
|
+
' i += 1;',
|
|
569
|
+
' }',
|
|
570
|
+
' flush();',
|
|
571
|
+
' }',
|
|
572
|
+
'',
|
|
573
|
+
' function copyText(text, btn) {',
|
|
574
|
+
' const done = () => {',
|
|
575
|
+
' if (!btn) return;',
|
|
576
|
+
' const prev = btn.textContent;',
|
|
577
|
+
' btn.textContent = "Copied";',
|
|
578
|
+
' setTimeout(() => { btn.textContent = prev; }, 1400);',
|
|
579
|
+
' };',
|
|
580
|
+
' if (navigator.clipboard && navigator.clipboard.writeText) {',
|
|
581
|
+
' navigator.clipboard.writeText(text).then(done).catch(() => {});',
|
|
582
|
+
' }',
|
|
583
|
+
' }',
|
|
584
|
+
'',
|
|
585
|
+
' /* Artifact Versioning + Canvas / Live Browser Preview Integration */',
|
|
586
|
+
' function recordArtifactVersion(relPath, content) {',
|
|
587
|
+
' const key = relPath || "draft.idoc.md";',
|
|
588
|
+
' const list = state.artifactVersions.get(key) || [];',
|
|
589
|
+
' if (list.length === 0 || list[list.length - 1].content !== content) {',
|
|
590
|
+
' list.push({ version: list.length + 1, content, at: Date.now() });',
|
|
591
|
+
' state.artifactVersions.set(key, list);',
|
|
592
|
+
' }',
|
|
593
|
+
' syncArtifactVersionSelect(key);',
|
|
594
|
+
' return list.length;',
|
|
595
|
+
' }',
|
|
596
|
+
'',
|
|
597
|
+
' function syncArtifactVersionSelect(relPath) {',
|
|
598
|
+
' const list = state.artifactVersions.get(relPath || "") || [];',
|
|
599
|
+
' artifactVersionSelect.textContent = "";',
|
|
600
|
+
' if (list.length <= 1) {',
|
|
601
|
+
' artifactVersionSelect.style.display = "none";',
|
|
602
|
+
' return;',
|
|
603
|
+
' }',
|
|
604
|
+
' artifactVersionSelect.style.display = "inline-block";',
|
|
605
|
+
' for (const item of list) {',
|
|
606
|
+
' const opt = document.createElement("option");',
|
|
607
|
+
' opt.value = String(item.version);',
|
|
608
|
+
' opt.textContent = "v" + item.version;',
|
|
609
|
+
' artifactVersionSelect.appendChild(opt);',
|
|
610
|
+
' }',
|
|
611
|
+
' artifactVersionSelect.value = String(list[list.length - 1].version);',
|
|
612
|
+
' }',
|
|
613
|
+
'',
|
|
614
|
+
' function openInCanvas(suggestedPath, content, preferPreview) {',
|
|
615
|
+
' openStudio("canvas");',
|
|
616
|
+
' const targetPath = suggestedPath || filePathInput.value || "draft.idoc.md";',
|
|
617
|
+
' filePathInput.value = targetPath;',
|
|
618
|
+
' fileContentInput.value = content || "";',
|
|
619
|
+
' const ver = recordArtifactVersion(targetPath, content || "");',
|
|
620
|
+
' fileStatusEl.textContent = "Canvas · " + targetPath + " (v" + ver + ")";',
|
|
621
|
+
' setCanvasPreviewMode(Boolean(preferPreview));',
|
|
622
|
+
' }',
|
|
623
|
+
'',
|
|
624
|
+
' function openBrowserUrl(rawUrl) {',
|
|
625
|
+
' const valid = parseLoopbackUrl(rawUrl);',
|
|
626
|
+
' if (!valid) {',
|
|
627
|
+
' announceAlert("Only http://127.0.0.1 or http://localhost URLs are allowed in static preview.");',
|
|
628
|
+
' return;',
|
|
629
|
+
' }',
|
|
630
|
+
' openStudio("browser");',
|
|
631
|
+
' setBrowserEngine("frame");',
|
|
632
|
+
' state.browserMode = "url";',
|
|
633
|
+
' state.browserUrl = valid;',
|
|
634
|
+
' state.browserSrcdoc = "";',
|
|
635
|
+
' browserUrlInput.value = valid;',
|
|
636
|
+
' browserEmpty.style.display = "none";',
|
|
637
|
+
' browserFrame.style.display = "block";',
|
|
638
|
+
' browserFrame.removeAttribute("srcdoc");',
|
|
639
|
+
' browserFrame.setAttribute("sandbox", "allow-scripts allow-forms allow-same-origin");',
|
|
640
|
+
' browserFrame.src = valid;',
|
|
641
|
+
' browserOpenExtBtn.style.display = "flex";',
|
|
642
|
+
' }',
|
|
643
|
+
'',
|
|
644
|
+
' function openBrowserArtifact(title, htmlOrSvg) {',
|
|
645
|
+
' openStudio("browser");',
|
|
646
|
+
' setBrowserEngine("frame");',
|
|
647
|
+
' state.browserMode = "srcdoc";',
|
|
648
|
+
' state.browserUrl = "";',
|
|
649
|
+
' const trimmed = String(htmlOrSvg || "").trim();',
|
|
650
|
+
' const wrapped = trimmed.startsWith("<svg")',
|
|
651
|
+
' ? ("<!DOCTYPE html><html><body style=\\"margin:0;display:grid;place-items:center;min-height:100vh;background:#141714\\">" + trimmed + "</body></html>")',
|
|
652
|
+
' : trimmed;',
|
|
653
|
+
' state.browserSrcdoc = wrapped;',
|
|
654
|
+
' browserUrlInput.value = title || "preview.html";',
|
|
655
|
+
' browserEmpty.style.display = "none";',
|
|
656
|
+
' browserFrame.style.display = "block";',
|
|
657
|
+
' browserFrame.removeAttribute("src");',
|
|
658
|
+
' browserFrame.setAttribute("sandbox", "allow-scripts");',
|
|
659
|
+
' browserFrame.srcdoc = wrapped;',
|
|
660
|
+
' browserOpenExtBtn.style.display = "none";',
|
|
661
|
+
' }',
|
|
662
|
+
'',
|
|
663
|
+
' function createCodeCard(lang, codeText) {',
|
|
664
|
+
' const normLang = String(lang || "").toLowerCase();',
|
|
665
|
+
' const card = document.createElement("div");',
|
|
666
|
+
' card.className = "code-card";',
|
|
667
|
+
' const head = document.createElement("div");',
|
|
668
|
+
' head.className = "code-head";',
|
|
669
|
+
' const langSpan = document.createElement("span");',
|
|
670
|
+
' const lineCount = codeText ? codeText.split("\\n").length : 0;',
|
|
671
|
+
' langSpan.textContent = (lang || "code") + " · " + lineCount + " lines";',
|
|
672
|
+
' const actions = document.createElement("div");',
|
|
673
|
+
' actions.className = "code-head-actions";',
|
|
674
|
+
' if (normLang === "html" || normLang === "svg") {',
|
|
675
|
+
' const prevBtn = document.createElement("button");',
|
|
676
|
+
' prevBtn.type = "button"; prevBtn.className = "code-btn"; prevBtn.textContent = "Live Preview";',
|
|
677
|
+
' prevBtn.addEventListener("click", () => openBrowserArtifact("snippet." + normLang, codeText));',
|
|
678
|
+
' actions.appendChild(prevBtn);',
|
|
679
|
+
' }',
|
|
680
|
+
' const canvasBtn = document.createElement("button");',
|
|
681
|
+
' canvasBtn.type = "button"; canvasBtn.className = "code-btn"; canvasBtn.textContent = "Open in Canvas";',
|
|
682
|
+
' canvasBtn.addEventListener("click", () => {',
|
|
683
|
+
' const ext = normLang && /^[a-z0-9]{1,8}$/.test(normLang) ? normLang : "txt";',
|
|
684
|
+
' openInCanvas("snippet." + ext, codeText, normLang === "md" || normLang === "markdown" || normLang === "html" || normLang === "svg");',
|
|
685
|
+
' });',
|
|
686
|
+
' const copyBtn = document.createElement("button");',
|
|
687
|
+
' copyBtn.type = "button"; copyBtn.className = "code-btn"; copyBtn.textContent = "Copy";',
|
|
688
|
+
' copyBtn.addEventListener("click", () => copyText(codeText, copyBtn));',
|
|
689
|
+
' actions.appendChild(canvasBtn);',
|
|
690
|
+
' actions.appendChild(copyBtn);',
|
|
691
|
+
' head.appendChild(langSpan);',
|
|
692
|
+
' head.appendChild(actions);',
|
|
693
|
+
' const pre = document.createElement("pre");',
|
|
694
|
+
' pre.className = "code-pre";',
|
|
695
|
+
' const codeEl = document.createElement("code");',
|
|
696
|
+
' codeEl.textContent = codeText;',
|
|
697
|
+
' pre.appendChild(codeEl);',
|
|
698
|
+
' card.appendChild(head);',
|
|
699
|
+
' card.appendChild(pre);',
|
|
700
|
+
' return card;',
|
|
701
|
+
' }',
|
|
702
|
+
'',
|
|
703
|
+
' function parseTableRow(line) {',
|
|
704
|
+
' let trimmed = line.trim();',
|
|
705
|
+
' if (trimmed.startsWith("|")) trimmed = trimmed.slice(1);',
|
|
706
|
+
' if (trimmed.endsWith("|")) trimmed = trimmed.slice(0, -1);',
|
|
707
|
+
' return trimmed.split("|").map((c) => c.trim());',
|
|
708
|
+
' }',
|
|
709
|
+
'',
|
|
710
|
+
' function isTableDivider(line) {',
|
|
711
|
+
' const cells = parseTableRow(line);',
|
|
712
|
+
' if (cells.length === 0) return false;',
|
|
713
|
+
' for (const c of cells) { if (!/^:?-{2,}:?$/.test(c)) return false; }',
|
|
714
|
+
' return true;',
|
|
715
|
+
' }',
|
|
716
|
+
'',
|
|
717
|
+
' function renderMarkdownInto(container, source, streaming) {',
|
|
718
|
+
' container.textContent = "";',
|
|
719
|
+
' const lines = String(source || "").replace(/\\r\\n/g, "\\n").split("\\n");',
|
|
720
|
+
' let i = 0;',
|
|
721
|
+
' while (i < lines.length) {',
|
|
722
|
+
' const line = lines[i];',
|
|
723
|
+
' if (!line.trim()) { i += 1; continue; }',
|
|
724
|
+
' if (line.trimStart().startsWith("```")) {',
|
|
725
|
+
' const lang = line.trimStart().slice(3).trim().split(/\\s+/)[0] || "";',
|
|
726
|
+
' const codeLines = [];',
|
|
727
|
+
' i += 1;',
|
|
728
|
+
' while (i < lines.length && !lines[i].trimStart().startsWith("```")) {',
|
|
729
|
+
' codeLines.push(lines[i]);',
|
|
730
|
+
' i += 1;',
|
|
731
|
+
' }',
|
|
732
|
+
' if (i < lines.length) i += 1;',
|
|
733
|
+
' container.appendChild(createCodeCard(lang, codeLines.join("\\n")));',
|
|
734
|
+
' continue;',
|
|
735
|
+
' }',
|
|
736
|
+
' if (/^#{1,4}\\s+/.test(line)) {',
|
|
737
|
+
' const level = Math.min(4, line.match(/^#+/)[0].length);',
|
|
738
|
+
' const h = document.createElement("h" + level);',
|
|
739
|
+
' appendInlineNodes(h, line.slice(level).trim());',
|
|
740
|
+
' container.appendChild(h);',
|
|
741
|
+
' i += 1;',
|
|
742
|
+
' continue;',
|
|
743
|
+
' }',
|
|
744
|
+
' if (/^\\s*([-*_])\\1{2,}\\s*$/.test(line)) {',
|
|
745
|
+
' container.appendChild(document.createElement("hr"));',
|
|
746
|
+
' i += 1;',
|
|
747
|
+
' continue;',
|
|
748
|
+
' }',
|
|
749
|
+
' if (line.trimStart().startsWith("> ")) {',
|
|
750
|
+
' const bq = document.createElement("blockquote");',
|
|
751
|
+
' const parts = [];',
|
|
752
|
+
' while (i < lines.length && lines[i].trimStart().startsWith("> ")) {',
|
|
753
|
+
' parts.push(lines[i].trimStart().slice(2));',
|
|
754
|
+
' i += 1;',
|
|
755
|
+
' }',
|
|
756
|
+
' appendInlineNodes(bq, parts.join(" "));',
|
|
757
|
+
' container.appendChild(bq);',
|
|
758
|
+
' continue;',
|
|
759
|
+
' }',
|
|
760
|
+
' if (line.includes("|") && i + 1 < lines.length && isTableDivider(lines[i + 1])) {',
|
|
761
|
+
' const wrap = document.createElement("div");',
|
|
762
|
+
' wrap.className = "md-table-wrap";',
|
|
763
|
+
' const table = document.createElement("table");',
|
|
764
|
+
' table.className = "md-table";',
|
|
765
|
+
' const thead = document.createElement("thead");',
|
|
766
|
+
' const hr = document.createElement("tr");',
|
|
767
|
+
' for (const hCell of parseTableRow(line)) {',
|
|
768
|
+
' const th = document.createElement("th");',
|
|
769
|
+
' appendInlineNodes(th, hCell);',
|
|
770
|
+
' hr.appendChild(th);',
|
|
771
|
+
' }',
|
|
772
|
+
' thead.appendChild(hr);',
|
|
773
|
+
' table.appendChild(thead);',
|
|
774
|
+
' const tbody = document.createElement("tbody");',
|
|
775
|
+
' i += 2;',
|
|
776
|
+
' while (i < lines.length && lines[i].includes("|") && lines[i].trim()) {',
|
|
777
|
+
' const tr = document.createElement("tr");',
|
|
778
|
+
' for (const bCell of parseTableRow(lines[i])) {',
|
|
779
|
+
' const td = document.createElement("td");',
|
|
780
|
+
' appendInlineNodes(td, bCell);',
|
|
781
|
+
' tr.appendChild(td);',
|
|
782
|
+
' }',
|
|
783
|
+
' tbody.appendChild(tr);',
|
|
784
|
+
' i += 1;',
|
|
785
|
+
' }',
|
|
786
|
+
' table.appendChild(tbody);',
|
|
787
|
+
' wrap.appendChild(table);',
|
|
788
|
+
' container.appendChild(wrap);',
|
|
789
|
+
' continue;',
|
|
790
|
+
' }',
|
|
791
|
+
' if (/^\\s*[-*+]\\s+/.test(line)) {',
|
|
792
|
+
' const ul = document.createElement("ul");',
|
|
793
|
+
' while (i < lines.length && /^\\s*[-*+]\\s+/.test(lines[i])) {',
|
|
794
|
+
' const li = document.createElement("li");',
|
|
795
|
+
' appendInlineNodes(li, lines[i].replace(/^\\s*[-*+]\\s+/, ""));',
|
|
796
|
+
' ul.appendChild(li);',
|
|
797
|
+
' i += 1;',
|
|
798
|
+
' }',
|
|
799
|
+
' container.appendChild(ul);',
|
|
800
|
+
' continue;',
|
|
801
|
+
' }',
|
|
802
|
+
' if (/^\\s*\\d+\\.\\s+/.test(line)) {',
|
|
803
|
+
' const ol = document.createElement("ol");',
|
|
804
|
+
' while (i < lines.length && /^\\s*\\d+\\.\\s+/.test(lines[i])) {',
|
|
805
|
+
' const li = document.createElement("li");',
|
|
806
|
+
' appendInlineNodes(li, lines[i].replace(/^\\s*\\d+\\.\\s+/, ""));',
|
|
807
|
+
' ol.appendChild(li);',
|
|
808
|
+
' i += 1;',
|
|
809
|
+
' }',
|
|
810
|
+
' container.appendChild(ol);',
|
|
811
|
+
' continue;',
|
|
812
|
+
' }',
|
|
813
|
+
' const paraLines = [];',
|
|
814
|
+
' while (i < lines.length && lines[i].trim()',
|
|
815
|
+
' && !lines[i].trimStart().startsWith("```")',
|
|
816
|
+
' && !/^#{1,4}\\s+/.test(lines[i])',
|
|
817
|
+
' && !/^\\s*[-*+]\\s+/.test(lines[i])',
|
|
818
|
+
' && !/^\\s*\\d+\\.\\s+/.test(lines[i])',
|
|
819
|
+
' && !lines[i].trimStart().startsWith("> ")) {',
|
|
820
|
+
' paraLines.push(lines[i]);',
|
|
821
|
+
' i += 1;',
|
|
822
|
+
' }',
|
|
823
|
+
' const p = document.createElement("p");',
|
|
824
|
+
' appendInlineNodes(p, paraLines.join(" "));',
|
|
825
|
+
' container.appendChild(p);',
|
|
826
|
+
' }',
|
|
827
|
+
' if (streaming) {',
|
|
828
|
+
' const cursor = document.createElement("span");',
|
|
829
|
+
' cursor.className = "streaming-cursor";',
|
|
830
|
+
' container.appendChild(cursor);',
|
|
831
|
+
' }',
|
|
832
|
+
' }',
|
|
833
|
+
'',
|
|
834
|
+
' function cloneCausyneMark(extraClass) {',
|
|
835
|
+
' const tpl = el("causyne-mark-svg");',
|
|
836
|
+
' if (!tpl) return null;',
|
|
837
|
+
' const clone = tpl.cloneNode(true);',
|
|
838
|
+
' clone.removeAttribute("id");',
|
|
839
|
+
' if (extraClass) clone.classList.add(extraClass);',
|
|
840
|
+
' return clone;',
|
|
841
|
+
' }',
|
|
842
|
+
'',
|
|
843
|
+
' function createBrandAvatar() {',
|
|
844
|
+
' const wrap = document.createElement("div");',
|
|
845
|
+
' wrap.className = "assistant-avatar";',
|
|
846
|
+
' const mark = cloneCausyneMark("");',
|
|
847
|
+
' if (mark) wrap.appendChild(mark);',
|
|
848
|
+
' return wrap;',
|
|
849
|
+
' }',
|
|
850
|
+
'',
|
|
851
|
+
' function summarizeToolTarget(tool, args) {',
|
|
852
|
+
' if (!args || typeof args !== "object") return "";',
|
|
853
|
+
' const raw = args.path || args.filePath || args.file || args.command || args.query || args.url || "";',
|
|
854
|
+
' return typeof raw === "string" ? raw.slice(0, 90) : "";',
|
|
855
|
+
' }',
|
|
856
|
+
'',
|
|
857
|
+
' /* Adaptive Velocity Stream Smoother (barrier-paced rAF cadence) */',
|
|
858
|
+
' function solveBarrierBisect(fn, lo, hi) {',
|
|
859
|
+
' if (lo >= hi) return hi;',
|
|
860
|
+
' let a = lo; let b = hi; let fa = fn(a);',
|
|
861
|
+
' if (fa >= 0) return a;',
|
|
862
|
+
' if (fn(b) <= 0) return b;',
|
|
863
|
+
' for (let k = 0; k < 22 && (b - a) > 0.05; k += 1) {',
|
|
864
|
+
' const mid = (a + b) * 0.5;',
|
|
865
|
+
' const fm = fn(mid);',
|
|
866
|
+
' if (fm <= 0) { a = mid; fa = fm; } else { b = mid; }',
|
|
867
|
+
' }',
|
|
868
|
+
' return a;',
|
|
869
|
+
' }',
|
|
870
|
+
'',
|
|
871
|
+
' function createStreamSmoother(onRender) {',
|
|
872
|
+
' let fullText = "";',
|
|
873
|
+
' let shownLen = 0;',
|
|
874
|
+
' let vel = 120;',
|
|
875
|
+
' let lastT = 0;',
|
|
876
|
+
' let startMs = 0;',
|
|
877
|
+
' let arrivals = [[-9999, 0]];',
|
|
878
|
+
' let done = false;',
|
|
879
|
+
' let rafId = 0;',
|
|
880
|
+
' const alpha = 0.99;',
|
|
881
|
+
' const gamma = 1e-5;',
|
|
882
|
+
' const reducedMotion = Boolean(window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches);',
|
|
883
|
+
' function step() {',
|
|
884
|
+
' rafId = 0;',
|
|
885
|
+
' const total = fullText.length;',
|
|
886
|
+
' if (reducedMotion || total === 0) {',
|
|
887
|
+
' shownLen = total;',
|
|
888
|
+
' onRender(fullText, !done, shownLen);',
|
|
889
|
+
' return;',
|
|
890
|
+
' }',
|
|
891
|
+
' if (shownLen >= total) {',
|
|
892
|
+
' if (done) onRender(fullText, false, total);',
|
|
893
|
+
' return;',
|
|
894
|
+
' }',
|
|
895
|
+
' const nowSec = (performance.now() - startMs) / 1000;',
|
|
896
|
+
' const dt = Math.max(nowSec - lastT, 1e-4);',
|
|
897
|
+
' const upper = total + (done ? 120 : 0);',
|
|
898
|
+
' const lagTarget = 0.9 * nowSec - 0.25;',
|
|
899
|
+
' let minChars = 0;',
|
|
900
|
+
' for (let idx = arrivals.length - 1; idx >= 0; idx -= 1) {',
|
|
901
|
+
' if (arrivals[idx][0] < lagTarget) { minChars = arrivals[idx][1]; break; }',
|
|
902
|
+
' }',
|
|
903
|
+
' const lo = Math.max(shownLen, Math.min(total, done ? total : minChars));',
|
|
904
|
+
' const nextX = done && (total - shownLen) <= 18',
|
|
905
|
+
' ? total',
|
|
906
|
+
' : solveBarrierBisect((x) => {',
|
|
907
|
+
' const d = (x - shownLen) / dt;',
|
|
908
|
+
' return 2 * (done ? gamma * 0.01 : gamma) * (1 / dt) * (d - vel) - 1 / Math.max(1e-4, x - lo) + 1 / Math.max(1e-4, upper - x);',
|
|
909
|
+
' }, lo, upper);',
|
|
910
|
+
' const clamped = Math.min(total, Math.max(shownLen + 1, Math.round(nextX)));',
|
|
911
|
+
' const instV = (clamped - shownLen) / dt;',
|
|
912
|
+
' vel = Math.max(45, Math.min(2400, alpha * vel + (1 - alpha) * instV));',
|
|
913
|
+
' shownLen = clamped;',
|
|
914
|
+
' lastT = nowSec;',
|
|
915
|
+
' onRender(fullText.slice(0, shownLen), !done || shownLen < total, shownLen);',
|
|
916
|
+
' if (shownLen < total) rafId = window.requestAnimationFrame(step);',
|
|
917
|
+
' else if (done) onRender(fullText, false, total);',
|
|
918
|
+
' }',
|
|
919
|
+
' function schedule() {',
|
|
920
|
+
' if (!rafId) rafId = window.requestAnimationFrame(step);',
|
|
921
|
+
' }',
|
|
922
|
+
' return {',
|
|
923
|
+
' push(delta) {',
|
|
924
|
+
' if (!delta) return;',
|
|
925
|
+
' if (!startMs) { startMs = performance.now(); lastT = 0; }',
|
|
926
|
+
' fullText += delta;',
|
|
927
|
+
' const tSec = (performance.now() - startMs) / 1000;',
|
|
928
|
+
' arrivals.push([tSec, fullText.length]);',
|
|
929
|
+
' if (arrivals.length > 120) arrivals.shift();',
|
|
930
|
+
' schedule();',
|
|
931
|
+
' },',
|
|
932
|
+
' setFull(text, streaming) {',
|
|
933
|
+
' fullText = String(text || "");',
|
|
934
|
+
' if (!streaming) {',
|
|
935
|
+
' if (rafId) { window.cancelAnimationFrame(rafId); rafId = 0; }',
|
|
936
|
+
' done = true; shownLen = fullText.length;',
|
|
937
|
+
' onRender(fullText, false, shownLen);',
|
|
938
|
+
' return;',
|
|
939
|
+
' }',
|
|
940
|
+
' if (!startMs) { startMs = performance.now(); lastT = 0; }',
|
|
941
|
+
' arrivals.push([(performance.now() - startMs) / 1000, fullText.length]);',
|
|
942
|
+
' schedule();',
|
|
943
|
+
' },',
|
|
944
|
+
' flush() {',
|
|
945
|
+
' done = true;',
|
|
946
|
+
' if (rafId) { window.cancelAnimationFrame(rafId); rafId = 0; }',
|
|
947
|
+
' shownLen = fullText.length;',
|
|
948
|
+
' onRender(fullText, false, shownLen);',
|
|
949
|
+
' },',
|
|
950
|
+
' getText() { return fullText; }',
|
|
951
|
+
' };',
|
|
952
|
+
' }',
|
|
953
|
+
'',
|
|
954
|
+
' function formatThoughtDuration(ms) {',
|
|
955
|
+
' const secs = Math.round(ms / 1000);',
|
|
956
|
+
' if (secs < 1) return "Thought briefly";',
|
|
957
|
+
' if (secs < 60) return "Thought for " + secs + "s";',
|
|
958
|
+
' const mins = Math.floor(secs / 60);',
|
|
959
|
+
' const rem = secs % 60;',
|
|
960
|
+
' return rem > 0 ? ("Thought for " + mins + "m " + rem + "s") : ("Thought for " + mins + "m");',
|
|
961
|
+
' }',
|
|
962
|
+
'',
|
|
963
|
+
' function classifyStepKind(toolName) {',
|
|
964
|
+
' const t = String(toolName || "").toLowerCase();',
|
|
965
|
+
' if (t === "fs_read" || t === "read_file" || t === "view_file" || t === "view_image") return "read";',
|
|
966
|
+
' if (t === "fs_write" || t === "write_file" || t === "create_file" || t === "write_to_file") return "write";',
|
|
967
|
+
' if (t === "fs_edit" || t === "edit_file" || t === "multi_edit" || t === "apply_patch") return "edit";',
|
|
968
|
+
' if (t === "fs_list" || t === "fs_search" || t === "grep" || t === "glob") return "search";',
|
|
969
|
+
' if (t === "sysrun" || t === "bash" || t === "shell" || t === "run_command") return "cmd";',
|
|
970
|
+
' if (t.includes("browser") || t === "screenshot") return "browser";',
|
|
971
|
+
' if (t.includes("web_search") || t.includes("web_fetch")) return "web";',
|
|
972
|
+
' if (t === "tool_search") return "discover";',
|
|
973
|
+
' if (t === "update_plan") return "plan";',
|
|
974
|
+
' return "other";',
|
|
975
|
+
' }',
|
|
976
|
+
'',
|
|
977
|
+
' function summarizeTimelineSteps(stepKinds, totalCount, isRunning, elapsedMs, restored) {',
|
|
978
|
+
' if (totalCount === 0) return isRunning ? "Working..." : "Completed";',
|
|
979
|
+
' const counts = new Map();',
|
|
980
|
+
' for (const k of stepKinds) counts.set(k, (counts.get(k) || 0) + 1);',
|
|
981
|
+
' const parts = [];',
|
|
982
|
+
' const add = (key, sg, pl) => {',
|
|
983
|
+
' const n = counts.get(key) || 0;',
|
|
984
|
+
' if (n > 0) parts.push(n === 1 ? sg : pl.replace("{n}", String(n)));',
|
|
985
|
+
' };',
|
|
986
|
+
' add("read", "Read a file", "Read {n} files");',
|
|
987
|
+
' add("write", "Created a file", "Created {n} files");',
|
|
988
|
+
' add("edit", "Edited a file", "Edited {n} files");',
|
|
989
|
+
' add("search", "Searched files", "Searched files");',
|
|
990
|
+
' add("cmd", "Ran a command", "Ran {n} commands");',
|
|
991
|
+
' add("browser", "Used browser", "Used browser ({n})");',
|
|
992
|
+
' add("web", "Searched the web", "Searched the web");',
|
|
993
|
+
' const prefix = parts.length > 0',
|
|
994
|
+
' ? parts.slice(0, 3).join(", ")',
|
|
995
|
+
' : (isRunning ? ("Working · " + totalCount + (totalCount === 1 ? " step" : " steps")) : (totalCount + (totalCount === 1 ? " step" : " steps")));',
|
|
996
|
+
' if (isRunning) return prefix + "...";',
|
|
997
|
+
' if (!restored && typeof elapsedMs === "number" && elapsedMs >= 1000) {',
|
|
998
|
+
' return prefix + " · " + Math.round(elapsedMs / 1000) + "s";',
|
|
999
|
+
' }',
|
|
1000
|
+
' return prefix;',
|
|
1001
|
+
' }',
|
|
1002
|
+
'',
|
|
1003
|
+
' function createCollapsibleCard(initialLabel, openByDefault, dotKind) {',
|
|
1004
|
+
' const root = document.createElement("div");',
|
|
1005
|
+
' root.className = "collapsible-card" + (openByDefault ? " is-open" : "");',
|
|
1006
|
+
' const trigger = document.createElement("button");',
|
|
1007
|
+
' trigger.type = "button";',
|
|
1008
|
+
' trigger.className = "collapsible-trigger";',
|
|
1009
|
+
' trigger.setAttribute("aria-expanded", openByDefault ? "true" : "false");',
|
|
1010
|
+
' const left = document.createElement("span");',
|
|
1011
|
+
' left.className = "collapsible-trigger-left";',
|
|
1012
|
+
' const dot = document.createElement("span");',
|
|
1013
|
+
' dot.className = "status-dot" + (dotKind ? (" " + dotKind) : "");',
|
|
1014
|
+
' const labelEl = document.createElement("span");',
|
|
1015
|
+
' labelEl.className = "collapsible-label";',
|
|
1016
|
+
' labelEl.textContent = initialLabel;',
|
|
1017
|
+
' left.appendChild(dot);',
|
|
1018
|
+
' left.appendChild(labelEl);',
|
|
1019
|
+
' const chev = document.createElementNS("http://www.w3.org/2000/svg", "svg");',
|
|
1020
|
+
' chev.setAttribute("viewBox", "0 0 24 24");',
|
|
1021
|
+
' chev.setAttribute("class", "collapsible-chevron");',
|
|
1022
|
+
' const pl = document.createElementNS("http://www.w3.org/2000/svg", "polyline");',
|
|
1023
|
+
' pl.setAttribute("points", "9 6 15 12 9 18");',
|
|
1024
|
+
' chev.appendChild(pl);',
|
|
1025
|
+
' trigger.appendChild(left);',
|
|
1026
|
+
' trigger.appendChild(chev);',
|
|
1027
|
+
' const body = document.createElement("div");',
|
|
1028
|
+
' body.className = "collapsible-body";',
|
|
1029
|
+
' const inner = document.createElement("div");',
|
|
1030
|
+
' inner.className = "collapsible-inner";',
|
|
1031
|
+
' body.appendChild(inner);',
|
|
1032
|
+
' root.appendChild(trigger);',
|
|
1033
|
+
' root.appendChild(body);',
|
|
1034
|
+
' let userToggled = false;',
|
|
1035
|
+
' const setOpen = (next, byUser) => {',
|
|
1036
|
+
' if (byUser) userToggled = true;',
|
|
1037
|
+
' root.classList.toggle("is-open", Boolean(next));',
|
|
1038
|
+
' trigger.setAttribute("aria-expanded", next ? "true" : "false");',
|
|
1039
|
+
' };',
|
|
1040
|
+
' trigger.addEventListener("click", () => setOpen(!root.classList.contains("is-open"), true));',
|
|
1041
|
+
' return {',
|
|
1042
|
+
' root, inner, labelEl, dot, setOpen,',
|
|
1043
|
+
' wasUserToggled: () => userToggled,',
|
|
1044
|
+
' setActive(active) { root.classList.toggle("is-active", Boolean(active)); }',
|
|
1045
|
+
' };',
|
|
1046
|
+
' }',
|
|
1047
|
+
'',
|
|
1048
|
+
' let threadSpacerEl = null;',
|
|
1049
|
+
' let lastLiveUserTurnEl = null;',
|
|
1050
|
+
'',
|
|
1051
|
+
' function ensureThreadSpacer() {',
|
|
1052
|
+
' if (!threadSpacerEl || !threadSpacerEl.isConnected) {',
|
|
1053
|
+
' threadSpacerEl = document.createElement("div");',
|
|
1054
|
+
' threadSpacerEl.id = "thread-spacer";',
|
|
1055
|
+
' threadSpacerEl.className = "thread-spacer";',
|
|
1056
|
+
' threadSpacerEl.setAttribute("aria-hidden", "true");',
|
|
1057
|
+
' threadSpacerEl.style.height = "0px";',
|
|
1058
|
+
' threadEl.appendChild(threadSpacerEl);',
|
|
1059
|
+
' } else if (threadEl.lastElementChild !== threadSpacerEl) {',
|
|
1060
|
+
' threadEl.appendChild(threadSpacerEl);',
|
|
1061
|
+
' }',
|
|
1062
|
+
' return threadSpacerEl;',
|
|
1063
|
+
' }',
|
|
1064
|
+
'',
|
|
1065
|
+
' function resetThreadSpacer() {',
|
|
1066
|
+
' lastLiveUserTurnEl = null;',
|
|
1067
|
+
' if (threadSpacerEl) threadSpacerEl.style.height = "0px";',
|
|
1068
|
+
' }',
|
|
1069
|
+
'',
|
|
1070
|
+
' function updateThreadSpacer() {',
|
|
1071
|
+
' if (!threadSpacerEl || !lastLiveUserTurnEl || !lastLiveUserTurnEl.isConnected || !threadWrapEl) return;',
|
|
1072
|
+
' const userRect = lastLiveUserTurnEl.getBoundingClientRect();',
|
|
1073
|
+
' const spacerRect = threadSpacerEl.getBoundingClientRect();',
|
|
1074
|
+
' const contentBelowUser = Math.max(0, spacerRect.top - userRect.top);',
|
|
1075
|
+
' const targetExtra = Math.max(0, threadWrapEl.clientHeight - contentBelowUser - 36);',
|
|
1076
|
+
' threadSpacerEl.style.height = Math.round(targetExtra) + "px";',
|
|
1077
|
+
' }',
|
|
1078
|
+
'',
|
|
1079
|
+
' function appendUserTurn(prompt, attachments, animate) {',
|
|
1080
|
+
' setStageMode(true);',
|
|
1081
|
+
' const turn = document.createElement("div");',
|
|
1082
|
+
' turn.className = "turn user" + (animate ? " turn-enter" : "");',
|
|
1083
|
+
' if (attachments && attachments.length > 0) {',
|
|
1084
|
+
' const line = document.createElement("div");',
|
|
1085
|
+
' line.className = "attach-line";',
|
|
1086
|
+
' for (const p of attachments) {',
|
|
1087
|
+
' const tag = document.createElement("span");',
|
|
1088
|
+
' tag.className = "attach-tag";',
|
|
1089
|
+
' tag.textContent = "@" + p;',
|
|
1090
|
+
' line.appendChild(tag);',
|
|
1091
|
+
' }',
|
|
1092
|
+
' turn.appendChild(line);',
|
|
1093
|
+
' }',
|
|
1094
|
+
' const bubble = document.createElement("div");',
|
|
1095
|
+
' bubble.className = "user-bubble";',
|
|
1096
|
+
' bubble.textContent = prompt;',
|
|
1097
|
+
' turn.appendChild(bubble);',
|
|
1098
|
+
' const uActs = document.createElement("div");',
|
|
1099
|
+
' uActs.className = "user-actions";',
|
|
1100
|
+
' const cp = document.createElement("button");',
|
|
1101
|
+
' cp.type = "button"; cp.className = "msg-action-btn"; cp.textContent = "Copy";',
|
|
1102
|
+
' cp.addEventListener("click", () => copyText(prompt, cp));',
|
|
1103
|
+
' const ed = document.createElement("button");',
|
|
1104
|
+
' ed.type = "button"; ed.className = "msg-action-btn"; ed.textContent = "Edit";',
|
|
1105
|
+
' ed.addEventListener("click", () => {',
|
|
1106
|
+
' promptInput.value = prompt;',
|
|
1107
|
+
' updateComposerMetrics();',
|
|
1108
|
+
' promptInput.focus();',
|
|
1109
|
+
' });',
|
|
1110
|
+
' uActs.appendChild(cp); uActs.appendChild(ed);',
|
|
1111
|
+
' turn.appendChild(uActs);',
|
|
1112
|
+
' if (threadSpacerEl && threadSpacerEl.parentElement === threadEl) {',
|
|
1113
|
+
' threadEl.insertBefore(turn, threadSpacerEl);',
|
|
1114
|
+
' } else {',
|
|
1115
|
+
' threadEl.appendChild(turn);',
|
|
1116
|
+
' }',
|
|
1117
|
+
' if (animate) {',
|
|
1118
|
+
' lastLiveUserTurnEl = turn;',
|
|
1119
|
+
' ensureThreadSpacer();',
|
|
1120
|
+
' updateThreadSpacer();',
|
|
1121
|
+
' window.requestAnimationFrame(() => {',
|
|
1122
|
+
' updateThreadSpacer();',
|
|
1123
|
+
' scrollToBottom(true, true);',
|
|
1124
|
+
' });',
|
|
1125
|
+
' } else {',
|
|
1126
|
+
' scrollToBottom(true);',
|
|
1127
|
+
' }',
|
|
1128
|
+
' }',
|
|
1129
|
+
'',
|
|
1130
|
+
' function createAssistantTurn(promptForRetry, opts) {',
|
|
1131
|
+
' const isRestored = Boolean(opts && opts.restored);',
|
|
1132
|
+
' setStageMode(true);',
|
|
1133
|
+
' const turn = document.createElement("div");',
|
|
1134
|
+
' turn.className = "turn assistant" + (isRestored ? "" : " turn-enter");',
|
|
1135
|
+
' const row = document.createElement("div");',
|
|
1136
|
+
' row.className = "assistant-row" + (isRestored ? "" : " is-streaming");',
|
|
1137
|
+
' row.appendChild(createBrandAvatar());',
|
|
1138
|
+
' const col = document.createElement("div");',
|
|
1139
|
+
' col.className = "assistant-col";',
|
|
1140
|
+
' const eventsSlot = document.createElement("div");',
|
|
1141
|
+
' eventsSlot.style.display = "flex";',
|
|
1142
|
+
' eventsSlot.style.flexDirection = "column";',
|
|
1143
|
+
' eventsSlot.style.gap = "8px";',
|
|
1144
|
+
' const artifactsSlot = document.createElement("div");',
|
|
1145
|
+
' artifactsSlot.style.display = "flex";',
|
|
1146
|
+
' artifactsSlot.style.flexDirection = "column";',
|
|
1147
|
+
' artifactsSlot.style.gap = "8px";',
|
|
1148
|
+
' const prose = document.createElement("div");',
|
|
1149
|
+
' prose.className = "assistant-prose";',
|
|
1150
|
+
' const urlPreviewSlot = document.createElement("div");',
|
|
1151
|
+
' urlPreviewSlot.className = "preview-url-bar";',
|
|
1152
|
+
' const errorSlot = document.createElement("div");',
|
|
1153
|
+
' errorSlot.style.display = "flex";',
|
|
1154
|
+
' errorSlot.style.flexDirection = "column";',
|
|
1155
|
+
' errorSlot.style.gap = "8px";',
|
|
1156
|
+
' const liveRow = document.createElement("div");',
|
|
1157
|
+
' liveRow.className = "turn-live-row" + (isRestored ? "" : " is-active");',
|
|
1158
|
+
' const liveMark = document.createElement("span");',
|
|
1159
|
+
' liveMark.className = "turn-live-mark";',
|
|
1160
|
+
' const liveSvg = cloneCausyneMark("");',
|
|
1161
|
+
' if (liveSvg) liveMark.appendChild(liveSvg);',
|
|
1162
|
+
' const liveLabel = document.createElement("span");',
|
|
1163
|
+
' liveLabel.className = "turn-live-label";',
|
|
1164
|
+
' liveLabel.textContent = "Thinking...";',
|
|
1165
|
+
' liveRow.appendChild(liveMark);',
|
|
1166
|
+
' liveRow.appendChild(liveLabel);',
|
|
1167
|
+
' const actionsRow = document.createElement("div");',
|
|
1168
|
+
' actionsRow.className = "msg-actions";',
|
|
1169
|
+
' actionsRow.style.display = "none";',
|
|
1170
|
+
' col.appendChild(eventsSlot);',
|
|
1171
|
+
' col.appendChild(artifactsSlot);',
|
|
1172
|
+
' col.appendChild(prose);',
|
|
1173
|
+
' col.appendChild(urlPreviewSlot);',
|
|
1174
|
+
' col.appendChild(errorSlot);',
|
|
1175
|
+
' col.appendChild(liveRow);',
|
|
1176
|
+
' col.appendChild(actionsRow);',
|
|
1177
|
+
' row.appendChild(col);',
|
|
1178
|
+
' turn.appendChild(row);',
|
|
1179
|
+
' if (threadSpacerEl && threadSpacerEl.parentElement === threadEl) {',
|
|
1180
|
+
' threadEl.insertBefore(turn, threadSpacerEl);',
|
|
1181
|
+
' } else {',
|
|
1182
|
+
' threadEl.appendChild(turn);',
|
|
1183
|
+
' }',
|
|
1184
|
+
'',
|
|
1185
|
+
' let rawText = "";',
|
|
1186
|
+
' let reasoningText = "";',
|
|
1187
|
+
' let interruptedShown = false;',
|
|
1188
|
+
' let reasonCard = null;',
|
|
1189
|
+
' let reasonBody = null;',
|
|
1190
|
+
' let reasonStartedAt = 0;',
|
|
1191
|
+
' let reasonCollapsedOnProse = false;',
|
|
1192
|
+
' let planCard = null;',
|
|
1193
|
+
' let timelineCard = null;',
|
|
1194
|
+
' let timelineStepsEl = null;',
|
|
1195
|
+
' let timelineStartedAt = 0;',
|
|
1196
|
+
' let stepCount = 0;',
|
|
1197
|
+
' let runningSteps = 0;',
|
|
1198
|
+
' const stepKinds = [];',
|
|
1199
|
+
' const toolCards = new Map();',
|
|
1200
|
+
' const codeCards = new Map();',
|
|
1201
|
+
'',
|
|
1202
|
+
' function renderText(textToRender, isStreaming) {',
|
|
1203
|
+
' renderMarkdownInto(prose, textToRender, isStreaming);',
|
|
1204
|
+
' if (isStreaming && prose.lastElementChild) {',
|
|
1205
|
+
' prose.lastElementChild.classList.add("stream-fade");',
|
|
1206
|
+
' }',
|
|
1207
|
+
' updateThreadSpacer();',
|
|
1208
|
+
' scrollToBottom(false);',
|
|
1209
|
+
' }',
|
|
1210
|
+
'',
|
|
1211
|
+
' const proseSmoother = createStreamSmoother((visibleText, isStreaming) => {',
|
|
1212
|
+
' renderText(visibleText, isStreaming);',
|
|
1213
|
+
' });',
|
|
1214
|
+
'',
|
|
1215
|
+
' const reasonSmoother = createStreamSmoother((visibleReasoning, isStreaming) => {',
|
|
1216
|
+
' if (!reasonBody) return;',
|
|
1217
|
+
' reasonBody.textContent = visibleReasoning;',
|
|
1218
|
+
' reasonBody.scrollTop = reasonBody.scrollHeight;',
|
|
1219
|
+
' if (reasonCard) {',
|
|
1220
|
+
' if (isStreaming) {',
|
|
1221
|
+
' const sec = Math.max(1, Math.round((Date.now() - reasonStartedAt) / 1000));',
|
|
1222
|
+
' reasonCard.labelEl.textContent = "Thinking · " + sec + "s";',
|
|
1223
|
+
' }',
|
|
1224
|
+
' }',
|
|
1225
|
+
' scrollToBottom(false);',
|
|
1226
|
+
' });',
|
|
1227
|
+
'',
|
|
1228
|
+
' function ensureTimeline(containerSlot) {',
|
|
1229
|
+
' if (timelineCard && !containerSlot) return;',
|
|
1230
|
+
' timelineStartedAt = Date.now();',
|
|
1231
|
+
' const card = createCollapsibleCard("Working...", !isRestored, isRestored ? "done" : "running");',
|
|
1232
|
+
' if (!isRestored) card.setActive(true);',
|
|
1233
|
+
' const stepsWrap = document.createElement("div");',
|
|
1234
|
+
' stepsWrap.className = "timeline-steps";',
|
|
1235
|
+
' card.inner.appendChild(stepsWrap);',
|
|
1236
|
+
' (containerSlot || eventsSlot).appendChild(card.root);',
|
|
1237
|
+
' if (!containerSlot) { timelineCard = card; timelineStepsEl = stepsWrap; }',
|
|
1238
|
+
' return { card, stepsWrap };',
|
|
1239
|
+
' }',
|
|
1240
|
+
'',
|
|
1241
|
+
' function refreshTimelineHeader(done) {',
|
|
1242
|
+
' if (!timelineCard) return;',
|
|
1243
|
+
' const running = !done && runningSteps > 0;',
|
|
1244
|
+
' const elapsed = Date.now() - timelineStartedAt;',
|
|
1245
|
+
' timelineCard.labelEl.textContent = summarizeTimelineSteps(stepKinds, stepCount, running, elapsed, isRestored);',
|
|
1246
|
+
' timelineCard.setActive(running);',
|
|
1247
|
+
' timelineCard.dot.className = "status-dot " + (running ? "running" : "done");',
|
|
1248
|
+
' }',
|
|
1249
|
+
'',
|
|
1250
|
+
' function collapseThinkingOnProse() {',
|
|
1251
|
+
' if (!reasonCard || reasonCollapsedOnProse || isRestored) return;',
|
|
1252
|
+
' reasonCollapsedOnProse = true;',
|
|
1253
|
+
' reasonSmoother.flush();',
|
|
1254
|
+
' reasonCard.setActive(false);',
|
|
1255
|
+
' reasonCard.dot.className = "status-dot done";',
|
|
1256
|
+
' reasonCard.labelEl.textContent = formatThoughtDuration(Date.now() - reasonStartedAt);',
|
|
1257
|
+
' if (!reasonCard.wasUserToggled()) reasonCard.setOpen(false, false);',
|
|
1258
|
+
' }',
|
|
1259
|
+
'',
|
|
1260
|
+
' function syncLoopbackButtons() {',
|
|
1261
|
+
' urlPreviewSlot.textContent = "";',
|
|
1262
|
+
' for (const u of extractLoopbackUrls(rawText)) {',
|
|
1263
|
+
' const btn = document.createElement("button");',
|
|
1264
|
+
' btn.type = "button";',
|
|
1265
|
+
' btn.className = "preview-url-btn";',
|
|
1266
|
+
' btn.textContent = "Open " + u + " in Live Browser";',
|
|
1267
|
+
' btn.addEventListener("click", () => openBrowserUrl(u));',
|
|
1268
|
+
' urlPreviewSlot.appendChild(btn);',
|
|
1269
|
+
' }',
|
|
1270
|
+
' }',
|
|
1271
|
+
'',
|
|
1272
|
+
' function buildStepRow(toolName, targetText, statusText, failed, outputText) {',
|
|
1273
|
+
' const card = document.createElement("div");',
|
|
1274
|
+
' card.className = "tool-card";',
|
|
1275
|
+
' const head = document.createElement("div");',
|
|
1276
|
+
' head.className = "tool-card-head";',
|
|
1277
|
+
' const hLeft = document.createElement("span");',
|
|
1278
|
+
' hLeft.className = "tool-head-left";',
|
|
1279
|
+
' const sDot = document.createElement("span");',
|
|
1280
|
+
' sDot.className = "status-dot " + (statusText === "running..." ? "running" : failed ? "failed" : "done");',
|
|
1281
|
+
' const name = document.createElement("span");',
|
|
1282
|
+
' name.className = "tool-badge";',
|
|
1283
|
+
' name.textContent = toolName;',
|
|
1284
|
+
' const target = document.createElement("span");',
|
|
1285
|
+
' target.className = "tool-target";',
|
|
1286
|
+
' target.textContent = targetText;',
|
|
1287
|
+
' hLeft.appendChild(sDot); hLeft.appendChild(name); hLeft.appendChild(target);',
|
|
1288
|
+
' const st = document.createElement("span");',
|
|
1289
|
+
' st.className = "tool-state";',
|
|
1290
|
+
' st.textContent = statusText;',
|
|
1291
|
+
' if (failed) st.style.color = "var(--err)";',
|
|
1292
|
+
' head.appendChild(hLeft); head.appendChild(st);',
|
|
1293
|
+
' card.appendChild(head);',
|
|
1294
|
+
' if (outputText) {',
|
|
1295
|
+
' const out = document.createElement("div");',
|
|
1296
|
+
' out.className = "tool-out";',
|
|
1297
|
+
' out.textContent = String(outputText).slice(0, 480);',
|
|
1298
|
+
' card.appendChild(out);',
|
|
1299
|
+
' }',
|
|
1300
|
+
' return { card, statusEl: st, dotEl: sDot };',
|
|
1301
|
+
' }',
|
|
1302
|
+
'',
|
|
1303
|
+
' return {',
|
|
1304
|
+
' setActivity(active, label) {',
|
|
1305
|
+
' if (isRestored) return;',
|
|
1306
|
+
' liveRow.classList.toggle("is-active", Boolean(active));',
|
|
1307
|
+
' if (label) liveLabel.textContent = label;',
|
|
1308
|
+
' },',
|
|
1309
|
+
' appendText(delta) {',
|
|
1310
|
+
' collapseThinkingOnProse();',
|
|
1311
|
+
' rawText += delta;',
|
|
1312
|
+
' proseSmoother.push(delta);',
|
|
1313
|
+
' },',
|
|
1314
|
+
' setText(full, streaming) {',
|
|
1315
|
+
' if (full) collapseThinkingOnProse();',
|
|
1316
|
+
' rawText = full;',
|
|
1317
|
+
' proseSmoother.setFull(full, Boolean(streaming));',
|
|
1318
|
+
' },',
|
|
1319
|
+
' updateReasoning(ev) {',
|
|
1320
|
+
' if (!reasonCard) {',
|
|
1321
|
+
' reasonStartedAt = Date.now();',
|
|
1322
|
+
' const openInit = Boolean(ev.streaming && !isRestored);',
|
|
1323
|
+
' reasonCard = createCollapsibleCard(isRestored ? "Thought process" : "Thinking...", openInit, ev.streaming ? "thinking" : "done");',
|
|
1324
|
+
' reasonCard.setActive(Boolean(ev.streaming && !isRestored));',
|
|
1325
|
+
' reasonBody = document.createElement("div");',
|
|
1326
|
+
' reasonBody.className = "reason-body";',
|
|
1327
|
+
' reasonCard.inner.appendChild(reasonBody);',
|
|
1328
|
+
' eventsSlot.prepend(reasonCard.root);',
|
|
1329
|
+
' }',
|
|
1330
|
+
' if (typeof ev.content === "string" && ev.content.length >= reasoningText.length) {',
|
|
1331
|
+
' reasoningText = ev.content;',
|
|
1332
|
+
' reasonSmoother.setFull(reasoningText, Boolean(ev.streaming && !isRestored));',
|
|
1333
|
+
' } else if (typeof ev.delta === "string") {',
|
|
1334
|
+
' reasoningText += ev.delta;',
|
|
1335
|
+
' reasonSmoother.push(ev.delta);',
|
|
1336
|
+
' }',
|
|
1337
|
+
' if (isRestored) {',
|
|
1338
|
+
' reasonCard.labelEl.textContent = "Thought process";',
|
|
1339
|
+
' reasonCard.setActive(false);',
|
|
1340
|
+
' reasonCard.dot.className = "status-dot done";',
|
|
1341
|
+
' } else if (!ev.streaming) {',
|
|
1342
|
+
' const ms = typeof ev.elapsedMs === "number" ? ev.elapsedMs : (Date.now() - reasonStartedAt);',
|
|
1343
|
+
' reasonCard.labelEl.textContent = formatThoughtDuration(ms);',
|
|
1344
|
+
' reasonCard.setActive(false);',
|
|
1345
|
+
' reasonCard.dot.className = "status-dot done";',
|
|
1346
|
+
' }',
|
|
1347
|
+
' scrollToBottom(false);',
|
|
1348
|
+
' },',
|
|
1349
|
+
' renderRestoredBlocks(blocks) {',
|
|
1350
|
+
' const allTextParts = [];',
|
|
1351
|
+
' prose.style.display = "none";',
|
|
1352
|
+
' for (const blk of blocks) {',
|
|
1353
|
+
' if (blk.kind === "reasoning" && blk.content) {',
|
|
1354
|
+
' const rc = createCollapsibleCard("Thought process", false, "done");',
|
|
1355
|
+
' const rb = document.createElement("div");',
|
|
1356
|
+
' rb.className = "reason-body";',
|
|
1357
|
+
' rb.textContent = blk.content;',
|
|
1358
|
+
' rc.inner.appendChild(rb);',
|
|
1359
|
+
' eventsSlot.appendChild(rc.root);',
|
|
1360
|
+
' } else if (blk.kind === "steps" && Array.isArray(blk.steps) && blk.steps.length > 0) {',
|
|
1361
|
+
' const kinds = blk.steps.map((s) => classifyStepKind(s.tool));',
|
|
1362
|
+
' const label = summarizeTimelineSteps(kinds, blk.steps.length, false, 0, true);',
|
|
1363
|
+
' const tc = createCollapsibleCard(label, false, blk.steps.some((s) => s.status === "failed") ? "failed" : "done");',
|
|
1364
|
+
' const sw = document.createElement("div");',
|
|
1365
|
+
' sw.className = "timeline-steps";',
|
|
1366
|
+
' for (const st of blk.steps) {',
|
|
1367
|
+
' const rowObj = buildStepRow(st.tool || "step", st.target || "", st.status === "failed" ? "failed" : "done", st.status === "failed", st.output || "");',
|
|
1368
|
+
' sw.appendChild(rowObj.card);',
|
|
1369
|
+
' }',
|
|
1370
|
+
' tc.inner.appendChild(sw);',
|
|
1371
|
+
' eventsSlot.appendChild(tc.root);',
|
|
1372
|
+
' } else if (blk.kind === "text" && blk.content) {',
|
|
1373
|
+
' allTextParts.push(blk.content);',
|
|
1374
|
+
' const seg = document.createElement("div");',
|
|
1375
|
+
' seg.className = "assistant-prose";',
|
|
1376
|
+
' renderMarkdownInto(seg, blk.content, false);',
|
|
1377
|
+
' eventsSlot.appendChild(seg);',
|
|
1378
|
+
' }',
|
|
1379
|
+
' }',
|
|
1380
|
+
' rawText = allTextParts.join("\\n\\n");',
|
|
1381
|
+
' },',
|
|
1382
|
+
' updatePlan(ev) {',
|
|
1383
|
+
' const items = Array.isArray(ev.plan) ? ev.plan : [];',
|
|
1384
|
+
' if (items.length === 0) return;',
|
|
1385
|
+
' if (!planCard) {',
|
|
1386
|
+
' planCard = document.createElement("div");',
|
|
1387
|
+
' planCard.className = "plan-card";',
|
|
1388
|
+
' eventsSlot.appendChild(planCard);',
|
|
1389
|
+
' }',
|
|
1390
|
+
' planCard.textContent = "";',
|
|
1391
|
+
' const doneCount = items.filter((s) => s.status === "completed").length;',
|
|
1392
|
+
' const head = document.createElement("div");',
|
|
1393
|
+
' head.className = "plan-head";',
|
|
1394
|
+
' const left = document.createElement("span");',
|
|
1395
|
+
' left.textContent = ev.explanation || "Execution Plan";',
|
|
1396
|
+
' const right = document.createElement("span");',
|
|
1397
|
+
' right.textContent = doneCount + "/" + items.length;',
|
|
1398
|
+
' head.appendChild(left); head.appendChild(right);',
|
|
1399
|
+
' planCard.appendChild(head);',
|
|
1400
|
+
' for (const s of items) {',
|
|
1401
|
+
' const line = document.createElement("div");',
|
|
1402
|
+
' const st = String(s.status || "pending");',
|
|
1403
|
+
' line.className = "plan-step" + (st === "completed" ? " done" : st === "in_progress" ? " active" : "");',
|
|
1404
|
+
' const ic = document.createElement("span");',
|
|
1405
|
+
' ic.className = "step-icon";',
|
|
1406
|
+
' ic.textContent = st === "completed" ? "✓" : st === "in_progress" ? "●" : "○";',
|
|
1407
|
+
' const txt = document.createElement("span");',
|
|
1408
|
+
' txt.textContent = s.text || s.step || "";',
|
|
1409
|
+
' line.appendChild(ic); line.appendChild(txt);',
|
|
1410
|
+
' planCard.appendChild(line);',
|
|
1411
|
+
' }',
|
|
1412
|
+
' scrollToBottom(false);',
|
|
1413
|
+
' },',
|
|
1414
|
+
' addStepStart(ev) {',
|
|
1415
|
+
' ensureTimeline();',
|
|
1416
|
+
' stepCount += 1;',
|
|
1417
|
+
' runningSteps += 1;',
|
|
1418
|
+
' stepKinds.push(classifyStepKind(ev.tool));',
|
|
1419
|
+
' const targetStr = summarizeToolTarget(ev.tool, ev.args);',
|
|
1420
|
+
' const built = buildStepRow(ev.tool || "tool", targetStr, "running...", false, "");',
|
|
1421
|
+
' timelineStepsEl.appendChild(built.card);',
|
|
1422
|
+
' const key = ev.toolCallId || ((ev.tool || "tool") + ":" + stepCount);',
|
|
1423
|
+
' toolCards.set(key, { card: built.card, status: built.statusEl, dot: built.dotEl, startedAt: Date.now() });',
|
|
1424
|
+
' refreshTimelineHeader(false);',
|
|
1425
|
+
' setLiveness(true, (ev.tool || "Running") + (targetStr ? " · " + targetStr : ""));',
|
|
1426
|
+
' scrollToBottom(false);',
|
|
1427
|
+
' },',
|
|
1428
|
+
' addStepEnd(ev, failed) {',
|
|
1429
|
+
' ensureTimeline();',
|
|
1430
|
+
' if (runningSteps > 0) runningSteps -= 1;',
|
|
1431
|
+
' const key = ev.toolCallId || "";',
|
|
1432
|
+
' const entry = key ? toolCards.get(key) : null;',
|
|
1433
|
+
' const resObj = ev.result && typeof ev.result === "object" ? ev.result : null;',
|
|
1434
|
+
' const rawOut = ev.error || ev.summary || (typeof ev.output === "string" ? ev.output : "")',
|
|
1435
|
+
' || (resObj && typeof resObj.output === "string" ? resObj.output : "")',
|
|
1436
|
+
' || (resObj && typeof resObj.message === "string" ? resObj.message : "");',
|
|
1437
|
+
' let targetCard = entry ? entry.card : null;',
|
|
1438
|
+
' if (!entry) {',
|
|
1439
|
+
' stepCount += 1;',
|
|
1440
|
+
' stepKinds.push(classifyStepKind(ev.tool));',
|
|
1441
|
+
' const built = buildStepRow(ev.tool || "tool", "", failed ? "failed" : "done", failed, rawOut);',
|
|
1442
|
+
' timelineStepsEl.appendChild(built.card);',
|
|
1443
|
+
' targetCard = built.card;',
|
|
1444
|
+
' } else {',
|
|
1445
|
+
' const elapsed = Math.max(1, Date.now() - entry.startedAt);',
|
|
1446
|
+
' entry.status.textContent = (failed ? "failed · " : "done · ") + elapsed + "ms";',
|
|
1447
|
+
' entry.dot.className = "status-dot " + (failed ? "failed" : "done");',
|
|
1448
|
+
' if (failed) entry.status.style.color = "var(--err)";',
|
|
1449
|
+
' if (rawOut) {',
|
|
1450
|
+
' const out = document.createElement("div");',
|
|
1451
|
+
' out.className = "tool-out";',
|
|
1452
|
+
' out.textContent = String(rawOut).slice(0, 480);',
|
|
1453
|
+
' targetCard.appendChild(out);',
|
|
1454
|
+
' }',
|
|
1455
|
+
' }',
|
|
1456
|
+
' refreshTimelineHeader(false);',
|
|
1457
|
+
' scrollToBottom(false);',
|
|
1458
|
+
' },',
|
|
1459
|
+
' addNativeStep(ev, failed) {',
|
|
1460
|
+
' const actionName = String(ev.actionName || "").trim();',
|
|
1461
|
+
' const detail = String(ev.detail || "").trim();',
|
|
1462
|
+
' const msg = String(ev.message || "").trim();',
|
|
1463
|
+
' if (actionName === "true" || actionName === ":" || detail === "true" || detail === ":") return;',
|
|
1464
|
+
' if (!actionName && (!msg || /(?:^|\\s)(?:true|:)$/.test(msg))) return;',
|
|
1465
|
+
' ensureTimeline();',
|
|
1466
|
+
' stepCount += 1;',
|
|
1467
|
+
' const cleanAction = actionName.replace(/^causyne[-_]browser[_:]/i, "");',
|
|
1468
|
+
' stepKinds.push(classifyStepKind(cleanAction));',
|
|
1469
|
+
' const cleanMsg = msg.replace(/^acp\\/[a-z0-9._-]+\\s+/i, "").replace(/^causyne[-_]browser[_:]/i, "");',
|
|
1470
|
+
' const built = buildStepRow(cleanAction || "step", detail || (cleanMsg && cleanMsg !== cleanAction ? cleanMsg : ""), failed ? "failed" : "done", failed, "");',
|
|
1471
|
+
' timelineStepsEl.appendChild(built.card);',
|
|
1472
|
+
' refreshTimelineHeader(false);',
|
|
1473
|
+
' scrollToBottom(false);',
|
|
1474
|
+
' },',
|
|
1475
|
+
' upsertCodeProgress(ev) {',
|
|
1476
|
+
' const key = ev.id || ev.path || ("code-" + codeCards.size);',
|
|
1477
|
+
' let slot = codeCards.get(key);',
|
|
1478
|
+
' if (!slot) {',
|
|
1479
|
+
' const card = document.createElement("div");',
|
|
1480
|
+
' card.className = "artifact-card streaming";',
|
|
1481
|
+
' const top = document.createElement("div");',
|
|
1482
|
+
' top.className = "artifact-top";',
|
|
1483
|
+
' const meta = document.createElement("div");',
|
|
1484
|
+
' meta.className = "artifact-meta";',
|
|
1485
|
+
' const ic = document.createElement("div");',
|
|
1486
|
+
' ic.className = "artifact-icon";',
|
|
1487
|
+
' const textBox = document.createElement("div");',
|
|
1488
|
+
' textBox.style.minWidth = "0";',
|
|
1489
|
+
' const title = document.createElement("div");',
|
|
1490
|
+
' title.className = "artifact-title";',
|
|
1491
|
+
' const sub = document.createElement("div");',
|
|
1492
|
+
' sub.className = "artifact-sub";',
|
|
1493
|
+
' textBox.appendChild(title); textBox.appendChild(sub);',
|
|
1494
|
+
' meta.appendChild(ic); meta.appendChild(textBox);',
|
|
1495
|
+
' const btns = document.createElement("div");',
|
|
1496
|
+
' btns.className = "artifact-btns";',
|
|
1497
|
+
' top.appendChild(meta); top.appendChild(btns);',
|
|
1498
|
+
' const pre = document.createElement("pre");',
|
|
1499
|
+
' pre.className = "artifact-stream-pre";',
|
|
1500
|
+
' card.appendChild(top); card.appendChild(pre);',
|
|
1501
|
+
' artifactsSlot.appendChild(card);',
|
|
1502
|
+
' slot = { card, ic, title, sub, btns, pre, code: "", path: "" };',
|
|
1503
|
+
' codeCards.set(key, slot);',
|
|
1504
|
+
' }',
|
|
1505
|
+
' const relPath = ev.path || slot.path || "workspace-file";',
|
|
1506
|
+
' slot.path = relPath;',
|
|
1507
|
+
' if (typeof ev.code === "string") slot.code = ev.code;',
|
|
1508
|
+
' const badge = artifactBadgeFor(relPath, "");',
|
|
1509
|
+
' slot.ic.textContent = badge.tag;',
|
|
1510
|
+
' slot.title.textContent = relPath;',
|
|
1511
|
+
' const lines = slot.code ? slot.code.split("\\n").length : 0;',
|
|
1512
|
+
' const phase = ev.phase || "working";',
|
|
1513
|
+
' slot.card.classList.toggle("streaming", phase === "draft" || phase === "working");',
|
|
1514
|
+
' slot.sub.textContent = (ev.operation || "Updating") + " · " + badge.label',
|
|
1515
|
+
' + (lines > 0 ? (" · " + lines + " lines") : "") + " · " + phase;',
|
|
1516
|
+
' if (slot.code) {',
|
|
1517
|
+
' slot.pre.style.display = "block";',
|
|
1518
|
+
' slot.pre.textContent = slot.code.split("\\n").slice(-10).join("\\n");',
|
|
1519
|
+
' } else {',
|
|
1520
|
+
' slot.pre.style.display = "none";',
|
|
1521
|
+
' }',
|
|
1522
|
+
' slot.btns.textContent = "";',
|
|
1523
|
+
' if (phase === "done") {',
|
|
1524
|
+
' slot.pre.style.display = "none";',
|
|
1525
|
+
' const openBtn = document.createElement("button");',
|
|
1526
|
+
' openBtn.type = "button"; openBtn.className = "btn-ghost"; openBtn.textContent = "Open";',
|
|
1527
|
+
' openBtn.addEventListener("click", () => {',
|
|
1528
|
+
' if (slot.code) openInCanvas(relPath, slot.code, relPath.endsWith(".md") || isHtmlOrSvgPath(relPath));',
|
|
1529
|
+
' else void openFile(relPath);',
|
|
1530
|
+
' });',
|
|
1531
|
+
' slot.btns.appendChild(openBtn);',
|
|
1532
|
+
' if (isHtmlOrSvgPath(relPath) && slot.code) {',
|
|
1533
|
+
' const liveBtn = document.createElement("button");',
|
|
1534
|
+
' liveBtn.type = "button"; liveBtn.className = "btn-primary"; liveBtn.textContent = "Preview";',
|
|
1535
|
+
' liveBtn.addEventListener("click", () => openBrowserArtifact(relPath, slot.code));',
|
|
1536
|
+
' slot.btns.appendChild(liveBtn);',
|
|
1537
|
+
' }',
|
|
1538
|
+
' }',
|
|
1539
|
+
' scrollToBottom(false);',
|
|
1540
|
+
' },',
|
|
1541
|
+
' addApproval(ev) {',
|
|
1542
|
+
' const box = document.createElement("div");',
|
|
1543
|
+
' box.className = "approval-card";',
|
|
1544
|
+
' const top = document.createElement("div");',
|
|
1545
|
+
' top.className = "approval-top";',
|
|
1546
|
+
' const text = document.createElement("span");',
|
|
1547
|
+
' text.className = "approval-text";',
|
|
1548
|
+
' text.textContent = "Allow " + (ev.tool || "tool") + "?";',
|
|
1549
|
+
' const btns = document.createElement("div");',
|
|
1550
|
+
' btns.className = "approval-actions";',
|
|
1551
|
+
' const yes = document.createElement("button");',
|
|
1552
|
+
' yes.type = "button"; yes.className = "btn-primary"; yes.textContent = "Allow";',
|
|
1553
|
+
' const always = document.createElement("button");',
|
|
1554
|
+
' always.type = "button"; always.className = "btn-ghost"; always.textContent = "Always allow";',
|
|
1555
|
+
' const no = document.createElement("button");',
|
|
1556
|
+
' no.type = "button"; no.className = "btn-danger"; no.textContent = "Deny";',
|
|
1557
|
+
' async function decide(approved, remember) {',
|
|
1558
|
+
' yes.disabled = true; always.disabled = true; no.disabled = true;',
|
|
1559
|
+
' await fetch(apiUrl("/api/approve"), {',
|
|
1560
|
+
' method: "POST",',
|
|
1561
|
+
' headers: authHeaders({ "Content-Type": "application/json" }),',
|
|
1562
|
+
' body: JSON.stringify({ sessionId: state.sessionId || undefined, toolCallId: ev.toolCallId, approved, remember: Boolean(remember), tool: ev.tool || "" })',
|
|
1563
|
+
' });',
|
|
1564
|
+
' text.textContent = (approved ? (remember ? "Always allowed " : "Allowed ") : "Denied ") + (ev.tool || "tool");',
|
|
1565
|
+
' btns.textContent = "";',
|
|
1566
|
+
' const badge = document.createElement("span");',
|
|
1567
|
+
' badge.className = "pop-sub";',
|
|
1568
|
+
' badge.textContent = approved ? (remember ? "Always allowed" : "Allowed") : "Denied";',
|
|
1569
|
+
' if (!approved) badge.style.color = "var(--err)";',
|
|
1570
|
+
' btns.appendChild(badge);',
|
|
1571
|
+
' }',
|
|
1572
|
+
' yes.addEventListener("click", () => { void decide(true, false); });',
|
|
1573
|
+
' always.addEventListener("click", () => { void decide(true, true); });',
|
|
1574
|
+
' no.addEventListener("click", () => { void decide(false, false); });',
|
|
1575
|
+
' btns.appendChild(yes); btns.appendChild(always); btns.appendChild(no);',
|
|
1576
|
+
' top.appendChild(text); top.appendChild(btns);',
|
|
1577
|
+
' box.appendChild(top);',
|
|
1578
|
+
' if (ev.args && typeof ev.args === "object" && Object.keys(ev.args).length > 0) {',
|
|
1579
|
+
' const pre = document.createElement("pre");',
|
|
1580
|
+
' pre.className = "approval-args";',
|
|
1581
|
+
' try { pre.textContent = JSON.stringify(ev.args, null, 2).slice(0, 600); } catch {}',
|
|
1582
|
+
' box.appendChild(pre);',
|
|
1583
|
+
' }',
|
|
1584
|
+
' eventsSlot.appendChild(box);',
|
|
1585
|
+
' setLiveness(true, "Waiting for approval · " + (ev.tool || "tool"));',
|
|
1586
|
+
' scrollToBottom(true);',
|
|
1587
|
+
' },',
|
|
1588
|
+
' addDecision(reqObj) {',
|
|
1589
|
+
' if (!reqObj || typeof reqObj !== "object") return;',
|
|
1590
|
+
' const box = document.createElement("div");',
|
|
1591
|
+
' box.className = "decision-card";',
|
|
1592
|
+
' const q = document.createElement("div");',
|
|
1593
|
+
' q.className = "decision-q";',
|
|
1594
|
+
' q.textContent = reqObj.question || "Choose how to proceed:";',
|
|
1595
|
+
' box.appendChild(q);',
|
|
1596
|
+
' const optsWrap = document.createElement("div");',
|
|
1597
|
+
' optsWrap.className = "decision-options";',
|
|
1598
|
+
' const optButtons = [];',
|
|
1599
|
+
' let resolved = false;',
|
|
1600
|
+
' const customInput = document.createElement("input");',
|
|
1601
|
+
' const customBtn = document.createElement("button");',
|
|
1602
|
+
' async function submitChoice(optionId, label, custom) {',
|
|
1603
|
+
' if (resolved || !label) return;',
|
|
1604
|
+
' resolved = true;',
|
|
1605
|
+
' for (const b of optButtons) b.disabled = true;',
|
|
1606
|
+
' customInput.disabled = true; customBtn.disabled = true;',
|
|
1607
|
+
' await fetch(apiUrl("/api/decision"), {',
|
|
1608
|
+
' method: "POST",',
|
|
1609
|
+
' headers: authHeaders({ "Content-Type": "application/json" }),',
|
|
1610
|
+
' body: JSON.stringify({ sessionId: state.sessionId || undefined, requestId: reqObj.id || "", optionId: optionId || null, label, custom: Boolean(custom) })',
|
|
1611
|
+
' }).catch(() => {});',
|
|
1612
|
+
' optsWrap.textContent = "";',
|
|
1613
|
+
' const chosen = document.createElement("span");',
|
|
1614
|
+
' chosen.className = "pop-sub";',
|
|
1615
|
+
' chosen.textContent = "Selected: " + label;',
|
|
1616
|
+
' optsWrap.appendChild(chosen);',
|
|
1617
|
+
' }',
|
|
1618
|
+
' const options = Array.isArray(reqObj.options) ? reqObj.options : [];',
|
|
1619
|
+
' for (const opt of options) {',
|
|
1620
|
+
' const btn = document.createElement("button");',
|
|
1621
|
+
' btn.type = "button"; btn.className = "decision-opt-btn";',
|
|
1622
|
+
' const lbl = document.createElement("span");',
|
|
1623
|
+
' lbl.className = "decision-opt-label";',
|
|
1624
|
+
' lbl.textContent = opt.label || opt.id || "Option";',
|
|
1625
|
+
' btn.appendChild(lbl);',
|
|
1626
|
+
' if (opt.description) {',
|
|
1627
|
+
' const desc = document.createElement("span");',
|
|
1628
|
+
' desc.className = "decision-opt-desc";',
|
|
1629
|
+
' desc.textContent = opt.description;',
|
|
1630
|
+
' btn.appendChild(desc);',
|
|
1631
|
+
' }',
|
|
1632
|
+
' btn.addEventListener("click", () => { void submitChoice(opt.id || null, opt.label || opt.id || "", false); });',
|
|
1633
|
+
' optButtons.push(btn);',
|
|
1634
|
+
' optsWrap.appendChild(btn);',
|
|
1635
|
+
' }',
|
|
1636
|
+
' const customRow = document.createElement("div");',
|
|
1637
|
+
' customRow.className = "decision-custom-row";',
|
|
1638
|
+
' customInput.type = "text"; customInput.className = "decision-custom-input";',
|
|
1639
|
+
' customInput.placeholder = "Or type a custom answer...";',
|
|
1640
|
+
' customBtn.type = "button"; customBtn.className = "btn-ghost"; customBtn.textContent = "Send";',
|
|
1641
|
+
' customBtn.addEventListener("click", () => { void submitChoice(null, (customInput.value || "").trim(), true); });',
|
|
1642
|
+
' customInput.addEventListener("keydown", (e) => {',
|
|
1643
|
+
' if (e.key === "Enter") { e.preventDefault(); void submitChoice(null, (customInput.value || "").trim(), true); }',
|
|
1644
|
+
' });',
|
|
1645
|
+
' customRow.appendChild(customInput); customRow.appendChild(customBtn);',
|
|
1646
|
+
' box.appendChild(optsWrap);',
|
|
1647
|
+
' box.appendChild(customRow);',
|
|
1648
|
+
' eventsSlot.appendChild(box);',
|
|
1649
|
+
' setLiveness(true, "Waiting for your decision...");',
|
|
1650
|
+
' updateThreadSpacer();',
|
|
1651
|
+
' scrollToBottom(true);',
|
|
1652
|
+
' },',
|
|
1653
|
+
' addNotice(msg) {',
|
|
1654
|
+
' const card = document.createElement("div");',
|
|
1655
|
+
' card.className = "tool-card";',
|
|
1656
|
+
' card.textContent = msg;',
|
|
1657
|
+
' eventsSlot.appendChild(card);',
|
|
1658
|
+
' updateThreadSpacer();',
|
|
1659
|
+
' scrollToBottom(false);',
|
|
1660
|
+
' },',
|
|
1661
|
+
' addError(msg, retryText, code) {',
|
|
1662
|
+
' const err = document.createElement("div");',
|
|
1663
|
+
' err.className = code === "DAILY_LIMIT_REACHED" ? "msg-upgrade" : "msg-error";',
|
|
1664
|
+
' const txt = document.createElement("span");',
|
|
1665
|
+
' txt.textContent = msg;',
|
|
1666
|
+
' err.appendChild(txt);',
|
|
1667
|
+
' if (code === "DAILY_LIMIT_REACHED") {',
|
|
1668
|
+
' const acts = document.createElement("div");',
|
|
1669
|
+
' acts.className = "msg-upgrade-actions";',
|
|
1670
|
+
' const upgBtn = document.createElement("button");',
|
|
1671
|
+
' upgBtn.type = "button"; upgBtn.className = "btn-primary"; upgBtn.textContent = "Upgrade to Pro";',
|
|
1672
|
+
' upgBtn.addEventListener("click", () => { settingsModal.classList.add("open"); void loadLicenseStatus(false); });',
|
|
1673
|
+
' acts.appendChild(upgBtn);',
|
|
1674
|
+
' err.appendChild(acts);',
|
|
1675
|
+
' } else {',
|
|
1676
|
+
' const targetRetry = retryText || promptForRetry;',
|
|
1677
|
+
' if (targetRetry) {',
|
|
1678
|
+
' const btn = document.createElement("button");',
|
|
1679
|
+
' btn.type = "button"; btn.className = "btn-ghost"; btn.textContent = "Retry";',
|
|
1680
|
+
' btn.addEventListener("click", () => { err.remove(); void submitPrompt(targetRetry, []); });',
|
|
1681
|
+
' err.appendChild(btn);',
|
|
1682
|
+
' }',
|
|
1683
|
+
' }',
|
|
1684
|
+
' errorSlot.appendChild(err);',
|
|
1685
|
+
' announceAlert(msg);',
|
|
1686
|
+
' updateThreadSpacer();',
|
|
1687
|
+
' scrollToBottom(true);',
|
|
1688
|
+
' },',
|
|
1689
|
+
' addInterrupted(msg, retryText) {',
|
|
1690
|
+
' if (interruptedShown) return;',
|
|
1691
|
+
' interruptedShown = true;',
|
|
1692
|
+
' const box = document.createElement("div");',
|
|
1693
|
+
' box.className = "msg-interrupted";',
|
|
1694
|
+
' const txt = document.createElement("span");',
|
|
1695
|
+
' txt.textContent = msg || "Causyne\\u2019s response was interrupted.";',
|
|
1696
|
+
' box.appendChild(txt);',
|
|
1697
|
+
' const targetRetry = retryText || promptForRetry;',
|
|
1698
|
+
' if (targetRetry) {',
|
|
1699
|
+
' const acts = document.createElement("div");',
|
|
1700
|
+
' acts.className = "msg-interrupted-actions";',
|
|
1701
|
+
' const contBtn = document.createElement("button");',
|
|
1702
|
+
' contBtn.type = "button"; contBtn.className = "btn-primary"; contBtn.textContent = "Continue";',
|
|
1703
|
+
' contBtn.addEventListener("click", () => { box.remove(); void submitPrompt(targetRetry, []); });',
|
|
1704
|
+
' acts.appendChild(contBtn);',
|
|
1705
|
+
' box.appendChild(acts);',
|
|
1706
|
+
' }',
|
|
1707
|
+
' errorSlot.appendChild(box);',
|
|
1708
|
+
' updateThreadSpacer();',
|
|
1709
|
+
' scrollToBottom(false);',
|
|
1710
|
+
' },',
|
|
1711
|
+
' finish() {',
|
|
1712
|
+
' row.classList.remove("is-streaming");',
|
|
1713
|
+
' liveRow.classList.remove("is-active");',
|
|
1714
|
+
' reasonSmoother.flush();',
|
|
1715
|
+
' if (prose.style.display !== "none") proseSmoother.flush();',
|
|
1716
|
+
' if (reasonCard && !isRestored) {',
|
|
1717
|
+
' reasonCard.setActive(false);',
|
|
1718
|
+
' reasonCard.dot.className = "status-dot done";',
|
|
1719
|
+
' reasonCard.labelEl.textContent = formatThoughtDuration(Date.now() - reasonStartedAt);',
|
|
1720
|
+
' if (!reasonCard.wasUserToggled()) reasonCard.setOpen(false, false);',
|
|
1721
|
+
' }',
|
|
1722
|
+
' syncLoopbackButtons();',
|
|
1723
|
+
' refreshTimelineHeader(true);',
|
|
1724
|
+
' if (timelineCard && stepCount > 0 && !timelineCard.wasUserToggled()) timelineCard.setOpen(false, false);',
|
|
1725
|
+
' if (!rawText.trim()) return;',
|
|
1726
|
+
' actionsRow.textContent = "";',
|
|
1727
|
+
' actionsRow.style.display = "flex";',
|
|
1728
|
+
' const copyBtn = document.createElement("button");',
|
|
1729
|
+
' copyBtn.type = "button"; copyBtn.className = "msg-action-btn"; copyBtn.textContent = "Copy";',
|
|
1730
|
+
' copyBtn.addEventListener("click", () => copyText(rawText, copyBtn));',
|
|
1731
|
+
' const canvasBtn = document.createElement("button");',
|
|
1732
|
+
' canvasBtn.type = "button"; canvasBtn.className = "msg-action-btn"; canvasBtn.textContent = "Open in Canvas";',
|
|
1733
|
+
' canvasBtn.addEventListener("click", () => openInCanvas("response.idoc.md", rawText, true));',
|
|
1734
|
+
' actionsRow.appendChild(copyBtn);',
|
|
1735
|
+
' actionsRow.appendChild(canvasBtn);',
|
|
1736
|
+
' if (promptForRetry) {',
|
|
1737
|
+
' const retryBtn = document.createElement("button");',
|
|
1738
|
+
' retryBtn.type = "button"; retryBtn.className = "msg-action-btn"; retryBtn.textContent = "Regenerate";',
|
|
1739
|
+
' retryBtn.addEventListener("click", () => { void submitPrompt(promptForRetry, []); });',
|
|
1740
|
+
' actionsRow.appendChild(retryBtn);',
|
|
1741
|
+
' }',
|
|
1742
|
+
' }',
|
|
1743
|
+
' };',
|
|
1744
|
+
' }',
|
|
1745
|
+
'',
|
|
1746
|
+
' /* Attachment Chips + @file Mention Autocomplete */',
|
|
1747
|
+
' function renderAttachmentChips() {',
|
|
1748
|
+
' composerChipsEl.textContent = "";',
|
|
1749
|
+
' composerChipsEl.classList.toggle("has-items", state.attachments.length > 0);',
|
|
1750
|
+
' for (const rel of state.attachments) {',
|
|
1751
|
+
' const chip = document.createElement("span");',
|
|
1752
|
+
' chip.className = "chip";',
|
|
1753
|
+
' const label = document.createElement("span");',
|
|
1754
|
+
' label.textContent = "@" + rel;',
|
|
1755
|
+
' const rm = document.createElement("button");',
|
|
1756
|
+
' rm.type = "button"; rm.textContent = "x"; rm.setAttribute("aria-label", "Remove " + rel);',
|
|
1757
|
+
' rm.addEventListener("click", () => {',
|
|
1758
|
+
' state.attachments = state.attachments.filter((item) => item !== rel);',
|
|
1759
|
+
' renderAttachmentChips();',
|
|
1760
|
+
' });',
|
|
1761
|
+
' chip.appendChild(label); chip.appendChild(rm);',
|
|
1762
|
+
' composerChipsEl.appendChild(chip);',
|
|
1763
|
+
' }',
|
|
1764
|
+
' }',
|
|
1765
|
+
'',
|
|
1766
|
+
' function attachWorkspaceFile(relPath) {',
|
|
1767
|
+
' if (!relPath || state.attachments.includes(relPath) || state.attachments.length >= 6) return;',
|
|
1768
|
+
' state.attachments.push(relPath);',
|
|
1769
|
+
' renderAttachmentChips();',
|
|
1770
|
+
' promptInput.focus();',
|
|
1771
|
+
' }',
|
|
1772
|
+
'',
|
|
1773
|
+
' function renderMentionList() {',
|
|
1774
|
+
' mentionPopover.textContent = "";',
|
|
1775
|
+
' if (state.mentionItems.length === 0) { mentionPopover.classList.remove("open"); return; }',
|
|
1776
|
+
' mentionPopover.classList.add("open");',
|
|
1777
|
+
' state.mentionItems.forEach((item, idx) => {',
|
|
1778
|
+
' const btn = document.createElement("button");',
|
|
1779
|
+
' btn.type = "button";',
|
|
1780
|
+
' btn.className = "mention-item" + (idx === state.mentionIndex ? " selected" : "");',
|
|
1781
|
+
' if (state.mentionMode === "command") {',
|
|
1782
|
+
' btn.textContent = "/" + item.name + (item.description ? (" — " + item.description.slice(0, 62)) : "");',
|
|
1783
|
+
' btn.addEventListener("click", () => applySlashChoice(item.name));',
|
|
1784
|
+
' } else {',
|
|
1785
|
+
' btn.textContent = "@" + item.path;',
|
|
1786
|
+
' btn.addEventListener("click", () => applyMentionChoice(item.path));',
|
|
1787
|
+
' }',
|
|
1788
|
+
' mentionPopover.appendChild(btn);',
|
|
1789
|
+
' });',
|
|
1790
|
+
' }',
|
|
1791
|
+
'',
|
|
1792
|
+
' function applySlashChoice(cmdName) {',
|
|
1793
|
+
' promptInput.value = "/" + cmdName + " ";',
|
|
1794
|
+
' state.mentionItems = []; state.mentionStart = -1;',
|
|
1795
|
+
' mentionPopover.classList.remove("open");',
|
|
1796
|
+
' updateComposerMetrics();',
|
|
1797
|
+
' promptInput.focus();',
|
|
1798
|
+
' }',
|
|
1799
|
+
'',
|
|
1800
|
+
' function applyMentionChoice(relPath) {',
|
|
1801
|
+
' const pos = promptInput.selectionStart || promptInput.value.length;',
|
|
1802
|
+
' if (state.mentionStart >= 0 && pos >= state.mentionStart) {',
|
|
1803
|
+
' promptInput.value = promptInput.value.slice(0, state.mentionStart) + promptInput.value.slice(pos);',
|
|
1804
|
+
' }',
|
|
1805
|
+
' attachWorkspaceFile(relPath);',
|
|
1806
|
+
' state.mentionItems = []; state.mentionStart = -1;',
|
|
1807
|
+
' mentionPopover.classList.remove("open");',
|
|
1808
|
+
' updateComposerMetrics();',
|
|
1809
|
+
' }',
|
|
1810
|
+
'',
|
|
1811
|
+
' async function checkAtMention() {',
|
|
1812
|
+
' const val = promptInput.value || "";',
|
|
1813
|
+
' const trimmedLeft = val.trimStart();',
|
|
1814
|
+
' if (trimmedLeft.startsWith("/") && !trimmedLeft.includes(" ") && state.cliCommands.length > 0) {',
|
|
1815
|
+
' const q = trimmedLeft.slice(1).toLowerCase();',
|
|
1816
|
+
' state.mentionMode = "command";',
|
|
1817
|
+
' const prefixHits = state.cliCommands.filter((c) => c.name.toLowerCase().startsWith(q));',
|
|
1818
|
+
' const nameHits = state.cliCommands.filter((c) => {',
|
|
1819
|
+
' const n = c.name.toLowerCase();',
|
|
1820
|
+
' return !n.startsWith(q) && n.includes(q);',
|
|
1821
|
+
' });',
|
|
1822
|
+
' const descHits = state.cliCommands.filter((c) => {',
|
|
1823
|
+
' const n = c.name.toLowerCase();',
|
|
1824
|
+
' return !n.includes(q) && (c.description || "").toLowerCase().includes(q);',
|
|
1825
|
+
' });',
|
|
1826
|
+
' state.mentionItems = prefixHits.concat(nameHits, descHits).slice(0, 10);',
|
|
1827
|
+
' state.mentionIndex = 0;',
|
|
1828
|
+
' renderMentionList();',
|
|
1829
|
+
' return;',
|
|
1830
|
+
' }',
|
|
1831
|
+
' const pos = promptInput.selectionStart || val.length;',
|
|
1832
|
+
' const before = val.slice(0, pos);',
|
|
1833
|
+
' const atIdx = before.lastIndexOf("@");',
|
|
1834
|
+
' if (atIdx < 0 || (atIdx > 0 && !/\\s/.test(before[atIdx - 1]))) {',
|
|
1835
|
+
' state.mentionItems = []; state.mentionStart = -1;',
|
|
1836
|
+
' mentionPopover.classList.remove("open");',
|
|
1837
|
+
' return;',
|
|
1838
|
+
' }',
|
|
1839
|
+
' const query = before.slice(atIdx + 1);',
|
|
1840
|
+
' if (/\\s/.test(query)) { mentionPopover.classList.remove("open"); return; }',
|
|
1841
|
+
' state.mentionMode = "file";',
|
|
1842
|
+
' state.mentionStart = atIdx;',
|
|
1843
|
+
' const res = await fetch(apiUrl("/api/files?q=" + encodeURIComponent(query)), { headers: authHeaders() }).catch(() => null);',
|
|
1844
|
+
' if (!res || !res.ok) return;',
|
|
1845
|
+
' const data = await res.json();',
|
|
1846
|
+
' state.mentionItems = (data.entries || []).filter((x) => x.type === "file").slice(0, 8);',
|
|
1847
|
+
' state.mentionIndex = 0;',
|
|
1848
|
+
' renderMentionList();',
|
|
1849
|
+
' }',
|
|
1850
|
+
'',
|
|
1851
|
+
' /* Studio Drawer (Files · Canvas · Shared Agent/Human Browser · Diff · CLI) */',
|
|
1852
|
+
' function syncPanelChromeState() {',
|
|
1853
|
+
' const isOpen = appEl.classList.contains("studio-open");',
|
|
1854
|
+
' studioToggleBtn.classList.toggle("active", isOpen);',
|
|
1855
|
+
' studioToggleBtn.setAttribute("aria-expanded", isOpen ? "true" : "false");',
|
|
1856
|
+
' if (studioExpandBtn) {',
|
|
1857
|
+
' studioExpandBtn.classList.toggle("active", state.studioExpanded);',
|
|
1858
|
+
' studioExpandBtn.title = state.studioExpanded ? "Restore panel width" : "Expand panel";',
|
|
1859
|
+
' }',
|
|
1860
|
+
' const navMap = [',
|
|
1861
|
+
' [navFilesBtn, "files"],',
|
|
1862
|
+
' [navCanvasBtn, "canvas"],',
|
|
1863
|
+
' [navBrowserBtn, "browser"],',
|
|
1864
|
+
' [navCliBtn, "cli"],',
|
|
1865
|
+
' [navDiffBtn, "diff"]',
|
|
1866
|
+
' ];',
|
|
1867
|
+
' for (const pair of navMap) {',
|
|
1868
|
+
' if (pair[0]) pair[0].classList.toggle("active", isOpen && state.studioTab === pair[1]);',
|
|
1869
|
+
' }',
|
|
1870
|
+
' }',
|
|
1871
|
+
' function openStudio(tab) {',
|
|
1872
|
+
' closeAllPopovers();',
|
|
1873
|
+
' if (window.innerWidth <= 960) appEl.classList.add("sidebar-collapsed");',
|
|
1874
|
+
' if (studioRoot) { studioRoot.style.flexBasis = ""; studioRoot.style.width = ""; }',
|
|
1875
|
+
' applyStudioWidth(state.studioWidth || DEFAULT_STUDIO_W, false);',
|
|
1876
|
+
' appEl.classList.add("studio-open");',
|
|
1877
|
+
' appEl.classList.toggle("studio-expanded", Boolean(state.studioExpanded));',
|
|
1878
|
+
' if (tab) setStudioTab(tab);',
|
|
1879
|
+
' else {',
|
|
1880
|
+
' syncPanelChromeState();',
|
|
1881
|
+
' if (state.studioTab === "browser" && state.browserEngine === "agent") startLiveBrowserStream();',
|
|
1882
|
+
' }',
|
|
1883
|
+
' }',
|
|
1884
|
+
' function closeStudio() {',
|
|
1885
|
+
' state.studioExpanded = false;',
|
|
1886
|
+
' appEl.classList.remove("studio-open", "studio-expanded", "studio-resizing");',
|
|
1887
|
+
' studioResizer.classList.remove("dragging", "snap-close");',
|
|
1888
|
+
' if (studioRoot) { studioRoot.style.flexBasis = ""; studioRoot.style.width = ""; }',
|
|
1889
|
+
' stopLiveBrowserStream();',
|
|
1890
|
+
' syncPanelChromeState();',
|
|
1891
|
+
' }',
|
|
1892
|
+
' function toggleStudioNav(tab) {',
|
|
1893
|
+
' if (appEl.classList.contains("studio-open") && state.studioTab === tab) closeStudio();',
|
|
1894
|
+
' else openStudio(tab);',
|
|
1895
|
+
' }',
|
|
1896
|
+
' function toggleStudioMaximize() {',
|
|
1897
|
+
' if (!appEl.classList.contains("studio-open")) return;',
|
|
1898
|
+
' state.studioExpanded = !state.studioExpanded;',
|
|
1899
|
+
' if (state.studioExpanded && window.innerWidth > 960 && window.innerWidth < 1380) {',
|
|
1900
|
+
' appEl.classList.add("sidebar-collapsed");',
|
|
1901
|
+
' }',
|
|
1902
|
+
' syncExpandedStudioWidth();',
|
|
1903
|
+
' appEl.classList.toggle("studio-expanded", state.studioExpanded);',
|
|
1904
|
+
' syncPanelChromeState();',
|
|
1905
|
+
' }',
|
|
1906
|
+
' function setStudioTab(tab) {',
|
|
1907
|
+
' state.studioTab = tab;',
|
|
1908
|
+
' document.querySelectorAll(".studio-tab").forEach((b) => {',
|
|
1909
|
+
' b.classList.toggle("active", b.getAttribute("data-tab") === tab);',
|
|
1910
|
+
' });',
|
|
1911
|
+
' document.querySelectorAll(".studio-pane").forEach((p) => {',
|
|
1912
|
+
' p.classList.toggle("active", p.getAttribute("data-pane") === tab);',
|
|
1913
|
+
' });',
|
|
1914
|
+
' syncPanelChromeState();',
|
|
1915
|
+
' if (tab === "files") void loadFiles(state.currentDir, fileFilterEl.value || "");',
|
|
1916
|
+
' if (tab === "diff") void loadDiff();',
|
|
1917
|
+
' if (tab === "cli") void loadCliOverview();',
|
|
1918
|
+
' if (tab === "browser" && state.browserEngine === "agent") {',
|
|
1919
|
+
' void refreshLiveBrowserState(false);',
|
|
1920
|
+
' startLiveBrowserStream();',
|
|
1921
|
+
' } else {',
|
|
1922
|
+
' stopLiveBrowserStream();',
|
|
1923
|
+
' }',
|
|
1924
|
+
' }',
|
|
1925
|
+
'',
|
|
1926
|
+
' /* Shared Agent + Human Live Browser Runtime (CDP Screencast + Native Window) */',
|
|
1927
|
+
' function stopLiveBrowserStream() {',
|
|
1928
|
+
' if (state.liveStreamAbort) {',
|
|
1929
|
+
' try { state.liveStreamAbort.abort(); } catch {}',
|
|
1930
|
+
' state.liveStreamAbort = null;',
|
|
1931
|
+
' }',
|
|
1932
|
+
' state.liveStreamConnected = false;',
|
|
1933
|
+
' }',
|
|
1934
|
+
'',
|
|
1935
|
+
' function updateAgentBrowserBanner(activity) {',
|
|
1936
|
+
' const active = Boolean(activity && activity.active);',
|
|
1937
|
+
' browserAgentBanner.classList.toggle("visible", active && state.liveBrowserActive);',
|
|
1938
|
+
' liveViewportSurface.classList.toggle("agent-active", active || state.controlOwner === "agent");',
|
|
1939
|
+
' if (active) {',
|
|
1940
|
+
' browserAgentBannerText.textContent = "Causyne is browsing";',
|
|
1941
|
+
' }',
|
|
1942
|
+
' }',
|
|
1943
|
+
'',
|
|
1944
|
+
' function startLiveBrowserStream() {',
|
|
1945
|
+
' if (state.liveStreamAbort || !appEl.classList.contains("studio-open") || state.studioTab !== "browser" || state.browserEngine !== "agent") {',
|
|
1946
|
+
' return;',
|
|
1947
|
+
' }',
|
|
1948
|
+
' const ctrl = new AbortController();',
|
|
1949
|
+
' state.liveStreamAbort = ctrl;',
|
|
1950
|
+
' (async () => {',
|
|
1951
|
+
' try {',
|
|
1952
|
+
' const res = await fetch(apiUrl("/api/browser/stream"), {',
|
|
1953
|
+
' headers: authHeaders(),',
|
|
1954
|
+
' signal: ctrl.signal',
|
|
1955
|
+
' });',
|
|
1956
|
+
' if (!res.ok || !res.body) return;',
|
|
1957
|
+
' state.liveStreamConnected = true;',
|
|
1958
|
+
' const reader = res.body.getReader();',
|
|
1959
|
+
' const dec = new TextDecoder();',
|
|
1960
|
+
' let buf = "";',
|
|
1961
|
+
' while (true) {',
|
|
1962
|
+
' const step = await reader.read();',
|
|
1963
|
+
' if (step.done) break;',
|
|
1964
|
+
' buf += dec.decode(step.value, { stream: true });',
|
|
1965
|
+
' let nl = buf.indexOf("\\n");',
|
|
1966
|
+
' while (nl !== -1) {',
|
|
1967
|
+
' const line = buf.slice(0, nl).trim();',
|
|
1968
|
+
' buf = buf.slice(nl + 1);',
|
|
1969
|
+
' if (line) {',
|
|
1970
|
+
' try {',
|
|
1971
|
+
' const ev = JSON.parse(line);',
|
|
1972
|
+
' if (ev.type === "agent_activity") {',
|
|
1973
|
+
' if (ev.controlOwner) {',
|
|
1974
|
+
' state.controlOwner = ev.controlOwner === "agent" ? "agent" : "human";',
|
|
1975
|
+
' browserHandoffBtn.textContent = state.controlOwner === "agent" ? "Take control" : "Let Causyne browse";',
|
|
1976
|
+
' }',
|
|
1977
|
+
' updateAgentBrowserBanner(ev.agentActivity);',
|
|
1978
|
+
' } else if (ev.type === "frame" || ev.type === "meta" || ev.type === "closed") {',
|
|
1979
|
+
' applyLiveBrowserFrame(ev);',
|
|
1980
|
+
' }',
|
|
1981
|
+
' } catch {}',
|
|
1982
|
+
' }',
|
|
1983
|
+
' nl = buf.indexOf("\\n");',
|
|
1984
|
+
' }',
|
|
1985
|
+
' }',
|
|
1986
|
+
' } catch {',
|
|
1987
|
+
' // Stream aborted cleanly or server closed.',
|
|
1988
|
+
' } finally {',
|
|
1989
|
+
' if (state.liveStreamAbort === ctrl) {',
|
|
1990
|
+
' state.liveStreamAbort = null;',
|
|
1991
|
+
' state.liveStreamConnected = false;',
|
|
1992
|
+
' }',
|
|
1993
|
+
' }',
|
|
1994
|
+
' })();',
|
|
1995
|
+
' }',
|
|
1996
|
+
'',
|
|
1997
|
+
' function setBrowserEngine(engine) {',
|
|
1998
|
+
' state.browserEngine = engine === "frame" ? "frame" : "agent";',
|
|
1999
|
+
' bmodeAgentBtn.classList.toggle("active", state.browserEngine === "agent");',
|
|
2000
|
+
' bmodeFrameBtn.classList.toggle("active", state.browserEngine === "frame");',
|
|
2001
|
+
' const isAgent = state.browserEngine === "agent";',
|
|
2002
|
+
' if (browserNewTabBtn) browserNewTabBtn.style.display = isAgent ? "inline-flex" : "none";',
|
|
2003
|
+
' if (browserNativeWinBtn) browserNativeWinBtn.style.display = isAgent ? "inline-flex" : "none";',
|
|
2004
|
+
' if (browserSyncToggleBtn) browserSyncToggleBtn.style.display = isAgent ? "inline-flex" : "none";',
|
|
2005
|
+
' if (!isAgent && browserSyncDrawer) { browserSyncDrawer.classList.remove("open"); if (browserSyncToggleBtn) browserSyncToggleBtn.classList.remove("active"); }',
|
|
2006
|
+
' if (isAgent) {',
|
|
2007
|
+
' browserFrame.style.display = "none";',
|
|
2008
|
+
' if (liveViewportSurface) liveViewportSurface.style.display = "flex";',
|
|
2009
|
+
' void refreshLiveBrowserState(false);',
|
|
2010
|
+
' startLiveBrowserStream();',
|
|
2011
|
+
' } else {',
|
|
2012
|
+
' stopLiveBrowserStream();',
|
|
2013
|
+
' liveBrowserImg.style.display = "none";',
|
|
2014
|
+
' if (liveViewportSurface) liveViewportSurface.style.display = "none";',
|
|
2015
|
+
' browserAgentBanner.classList.remove("visible");',
|
|
2016
|
+
' const hasFrame = state.browserMode === "url" || state.browserMode === "srcdoc";',
|
|
2017
|
+
' browserEmpty.style.display = hasFrame ? "none" : "flex";',
|
|
2018
|
+
' browserFrame.style.display = hasFrame ? "block" : "none";',
|
|
2019
|
+
' }',
|
|
2020
|
+
' }',
|
|
2021
|
+
'',
|
|
2022
|
+
' function applyLiveBrowserFrame(data) {',
|
|
2023
|
+
' if (!data) return;',
|
|
2024
|
+
' state.liveBrowserActive = Boolean(data.active);',
|
|
2025
|
+
' if (typeof data.visible === "boolean") state.liveBrowserVisible = data.visible;',
|
|
2026
|
+
' if (data.engine !== undefined) state.liveBrowserRuntime = data.engine;',
|
|
2027
|
+
' if (typeof data.enginePreference === "string") {',
|
|
2028
|
+
' state.liveBrowserPref = data.enginePreference;',
|
|
2029
|
+
' if (browserEngineSelect && browserEngineSelect.value !== data.enginePreference) {',
|
|
2030
|
+
' browserEngineSelect.value = data.enginePreference;',
|
|
2031
|
+
' }',
|
|
2032
|
+
' }',
|
|
2033
|
+
' if (data.enginesAvailable && browserEngineSelect) {',
|
|
2034
|
+
' const optCf = browserEngineSelect.querySelector("option[value=camoufox]");',
|
|
2035
|
+
' const optCh = browserEngineSelect.querySelector("option[value=chromium]");',
|
|
2036
|
+
' if (optCf) optCf.textContent = data.enginesAvailable.camoufox ? "Camoufox" : "Camoufox (unavailable)";',
|
|
2037
|
+
' if (optCh) optCh.textContent = data.enginesAvailable.chromium ? "Chromium" : "Chromium (unavailable)";',
|
|
2038
|
+
' }',
|
|
2039
|
+
' if (typeof data.streamMode === "string") state.liveStreamMode = data.streamMode;',
|
|
2040
|
+
' if (typeof data.fps === "number") state.liveFps = data.fps;',
|
|
2041
|
+
' state.controlOwner = data.controlOwner === "agent" ? "agent" : "human";',
|
|
2042
|
+
' if (typeof data.width === "number" && data.width > 0) state.liveBrowserWidth = data.width;',
|
|
2043
|
+
' if (typeof data.height === "number" && data.height > 0) state.liveBrowserHeight = data.height;',
|
|
2044
|
+
' browserHandoffBtn.textContent = state.controlOwner === "agent" ? "Take control" : "Let Causyne browse";',
|
|
2045
|
+
' browserNativeWinBtn.classList.toggle("active", state.liveBrowserVisible);',
|
|
2046
|
+
' browserNativeWinBtn.title = state.liveBrowserVisible ? "Return browser to panel" : "Open in desktop window";',
|
|
2047
|
+
' if (data.agentActivity) updateAgentBrowserBanner(data.agentActivity);',
|
|
2048
|
+
'',
|
|
2049
|
+
' if (Array.isArray(data.tabs)) {',
|
|
2050
|
+
' browserTabsEl.textContent = "";',
|
|
2051
|
+
' for (const tab of data.tabs) {',
|
|
2052
|
+
' const pill = document.createElement("div");',
|
|
2053
|
+
' pill.className = "btab" + (tab.active ? " active" : "");',
|
|
2054
|
+
' const lbl = document.createElement("button");',
|
|
2055
|
+
' lbl.type = "button"; lbl.className = "btab-label";',
|
|
2056
|
+
' lbl.textContent = tab.title || tab.url || "New tab";',
|
|
2057
|
+
' lbl.addEventListener("click", () => { void runBrowserAction({ action: "switchTab", tabId: tab.tabId }); });',
|
|
2058
|
+
' const cls = document.createElement("button");',
|
|
2059
|
+
' cls.type = "button"; cls.className = "btab-close"; cls.textContent = "×";',
|
|
2060
|
+
' cls.addEventListener("click", () => { void runBrowserAction({ action: "closeTab", tabId: tab.tabId }); });',
|
|
2061
|
+
' pill.appendChild(lbl); pill.appendChild(cls);',
|
|
2062
|
+
' browserTabsEl.appendChild(pill);',
|
|
2063
|
+
' }',
|
|
2064
|
+
' browserTabsEl.appendChild(browserNewTabBtn);',
|
|
2065
|
+
' }',
|
|
2066
|
+
'',
|
|
2067
|
+
' if (state.browserEngine !== "agent") return;',
|
|
2068
|
+
' if (data.url && document.activeElement !== browserUrlInput) browserUrlInput.value = data.url;',
|
|
2069
|
+
' if (data.active && data.imageBase64) {',
|
|
2070
|
+
' browserEmpty.style.display = "none";',
|
|
2071
|
+
' browserFrame.style.display = "none";',
|
|
2072
|
+
' liveBrowserImg.src = "data:" + (data.mimeType || "image/jpeg") + ";base64," + data.imageBase64;',
|
|
2073
|
+
' liveBrowserImg.style.display = "block";',
|
|
2074
|
+
' } else if (!data.active) {',
|
|
2075
|
+
' liveBrowserImg.style.display = "none";',
|
|
2076
|
+
' browserAgentBanner.classList.remove("visible");',
|
|
2077
|
+
' browserEmpty.style.display = "flex";',
|
|
2078
|
+
' }',
|
|
2079
|
+
' }',
|
|
2080
|
+
'',
|
|
2081
|
+
' async function sendLiveInput(payload) {',
|
|
2082
|
+
' if (!state.liveBrowserActive) {',
|
|
2083
|
+
' await runBrowserAction(Object.assign({ action: payload.kind }, payload));',
|
|
2084
|
+
' return;',
|
|
2085
|
+
' }',
|
|
2086
|
+
' if (state.liveStreamConnected) {',
|
|
2087
|
+
' await fetch(apiUrl("/api/browser/input"), {',
|
|
2088
|
+
' method: "POST", headers: authHeaders({ "Content-Type": "application/json" }),',
|
|
2089
|
+
' body: JSON.stringify(payload)',
|
|
2090
|
+
' }).catch(() => null);',
|
|
2091
|
+
' } else {',
|
|
2092
|
+
' await runBrowserAction(Object.assign({ action: payload.kind }, payload));',
|
|
2093
|
+
' }',
|
|
2094
|
+
' }',
|
|
2095
|
+
'',
|
|
2096
|
+
' async function refreshLiveBrowserState(ensureStarted) {',
|
|
2097
|
+
' const qs = ensureStarted ? "?ensure=1" : "";',
|
|
2098
|
+
' const res = await fetch(apiUrl("/api/browser/state" + qs), { headers: authHeaders() }).catch(() => null);',
|
|
2099
|
+
' if (!res || !res.ok) return;',
|
|
2100
|
+
' applyLiveBrowserFrame(await res.json());',
|
|
2101
|
+
' }',
|
|
2102
|
+
'',
|
|
2103
|
+
' async function runBrowserAction(payload) {',
|
|
2104
|
+
' const res = await fetch(apiUrl("/api/browser/action"), {',
|
|
2105
|
+
' method: "POST", headers: authHeaders({ "Content-Type": "application/json" }),',
|
|
2106
|
+
' body: JSON.stringify(payload)',
|
|
2107
|
+
' }).catch(() => null);',
|
|
2108
|
+
' if (!res) { announceAlert("Browser action failed."); return null; }',
|
|
2109
|
+
' const data = await res.json().catch(() => ({ error: "HTTP " + res.status }));',
|
|
2110
|
+
' if (!res.ok) { announceAlert(data.error || "Browser action failed."); return null; }',
|
|
2111
|
+
' applyLiveBrowserFrame(data);',
|
|
2112
|
+
' return data;',
|
|
2113
|
+
' }',
|
|
2114
|
+
'',
|
|
2115
|
+
' async function scanLocalChromeTabs() {',
|
|
2116
|
+
' const port = Number(cdpPortInput.value || 9222);',
|
|
2117
|
+
' cdpSyncStatus.textContent = "Checking port " + port + "...";',
|
|
2118
|
+
' cdpTabsList.textContent = "";',
|
|
2119
|
+
' const res = await fetch(apiUrl("/api/browser/cdp/tabs?port=" + encodeURIComponent(String(port))), { headers: authHeaders() }).catch(() => null);',
|
|
2120
|
+
' if (!res || !res.ok) {',
|
|
2121
|
+
' cdpSyncStatus.textContent = "No Chrome debugging port found on " + port + ". Start Chrome with --remote-debugging-port=" + port;',
|
|
2122
|
+
' return;',
|
|
2123
|
+
' }',
|
|
2124
|
+
' const data = await res.json();',
|
|
2125
|
+
' const tabs = data.tabs || [];',
|
|
2126
|
+
' cdpSyncStatus.textContent = tabs.length + " open tab(s) on port " + data.port;',
|
|
2127
|
+
' for (const tab of tabs) {',
|
|
2128
|
+
' const row = document.createElement("div"); row.className = "sync-row";',
|
|
2129
|
+
' const title = document.createElement("span"); title.className = "sync-tab-title";',
|
|
2130
|
+
' title.textContent = tab.title || tab.url;',
|
|
2131
|
+
' const openOnly = document.createElement("button"); openOnly.type = "button"; openOnly.className = "btn-ghost"; openOnly.textContent = "Open";',
|
|
2132
|
+
' openOnly.addEventListener("click", () => { void syncChromeTab(data.port, tab.id, false); });',
|
|
2133
|
+
' const syncBtn = document.createElement("button"); syncBtn.type = "button"; syncBtn.className = "btn-primary"; syncBtn.textContent = "Import tab";',
|
|
2134
|
+
' syncBtn.addEventListener("click", () => { void syncChromeTab(data.port, tab.id, true); });',
|
|
2135
|
+
' row.appendChild(title); row.appendChild(openOnly); row.appendChild(syncBtn);',
|
|
2136
|
+
' cdpTabsList.appendChild(row);',
|
|
2137
|
+
' }',
|
|
2138
|
+
' }',
|
|
2139
|
+
'',
|
|
2140
|
+
' async function syncChromeTab(port, targetId, includeCookies) {',
|
|
2141
|
+
' cdpSyncStatus.textContent = includeCookies ? "Importing tab and session..." : "Opening tab...";',
|
|
2142
|
+
' const res = await fetch(apiUrl("/api/browser/cdp/sync"), {',
|
|
2143
|
+
' method: "POST", headers: authHeaders({ "Content-Type": "application/json" }),',
|
|
2144
|
+
' body: JSON.stringify({ port, targetId, includeCookies })',
|
|
2145
|
+
' }).catch(() => null);',
|
|
2146
|
+
' if (!res) { cdpSyncStatus.textContent = "Import failed."; return; }',
|
|
2147
|
+
' const data = await res.json().catch(() => ({ error: "HTTP " + res.status }));',
|
|
2148
|
+
' if (!res.ok) { cdpSyncStatus.textContent = data.error || "Import failed."; return; }',
|
|
2149
|
+
' setBrowserEngine("agent");',
|
|
2150
|
+
' applyLiveBrowserFrame(data);',
|
|
2151
|
+
' cdpSyncStatus.textContent = "Imported " + (data.syncedUrl || "tab");',
|
|
2152
|
+
' }',
|
|
2153
|
+
'',
|
|
2154
|
+
' async function importExplicitBrowserData() {',
|
|
2155
|
+
' const rawText = (browserImportInput.value || "").trim();',
|
|
2156
|
+
' if (!rawText) { cdpSyncStatus.textContent = "Paste URLs, Bookmarks HTML, or storageState JSON first."; return; }',
|
|
2157
|
+
' cdpSyncStatus.textContent = "Importing...";',
|
|
2158
|
+
' const res = await fetch(apiUrl("/api/browser/import"), {',
|
|
2159
|
+
' method: "POST", headers: authHeaders({ "Content-Type": "application/json" }),',
|
|
2160
|
+
' body: JSON.stringify({ rawText, openFirstUrl: true })',
|
|
2161
|
+
' }).catch(() => null);',
|
|
2162
|
+
' if (!res) { cdpSyncStatus.textContent = "Import failed."; return; }',
|
|
2163
|
+
' const data = await res.json().catch(() => ({ error: "HTTP " + res.status }));',
|
|
2164
|
+
' if (!res.ok) { cdpSyncStatus.textContent = data.error || "Import failed."; return; }',
|
|
2165
|
+
' setBrowserEngine("agent");',
|
|
2166
|
+
' applyLiveBrowserFrame(data);',
|
|
2167
|
+
' browserImportInput.value = "";',
|
|
2168
|
+
' cdpSyncStatus.textContent = "Imported " + ((data.importedUrls || []).length) + " URL(s), " + (data.importedCookies || 0) + " cookie(s).";',
|
|
2169
|
+
' }',
|
|
2170
|
+
'',
|
|
2171
|
+
' /* Full Causyne CLI Mirror (Commands + Overview + Vault) */',
|
|
2172
|
+
' const QUICK_CLI_COMMANDS = [',
|
|
2173
|
+
' "/status", "/doctor", "/map", "/rules", "/checkpoints", "/undo",',
|
|
2174
|
+
' "/worktree list", "/pr", "/tasks", "/mcp", "/skills", "/peers",',
|
|
2175
|
+
' "/plugins", "/slop", "/policy", "/audit", "/eval"',
|
|
2176
|
+
' ];',
|
|
2177
|
+
'',
|
|
2178
|
+
' function renderCliQuickGrid() {',
|
|
2179
|
+
' cliQuickGrid.textContent = "";',
|
|
2180
|
+
' for (const cmd of QUICK_CLI_COMMANDS) {',
|
|
2181
|
+
' const btn = document.createElement("button");',
|
|
2182
|
+
' btn.type = "button"; btn.className = "cli-chip"; btn.textContent = cmd;',
|
|
2183
|
+
' btn.addEventListener("click", () => { void runCliCommand(cmd, "studio"); });',
|
|
2184
|
+
' cliQuickGrid.appendChild(btn);',
|
|
2185
|
+
' }',
|
|
2186
|
+
' }',
|
|
2187
|
+
'',
|
|
2188
|
+
' async function loadCliCommands() {',
|
|
2189
|
+
' const res = await fetch(apiUrl("/api/commands"), { headers: authHeaders() }).catch(() => null);',
|
|
2190
|
+
' if (!res || !res.ok) return;',
|
|
2191
|
+
' const data = await res.json();',
|
|
2192
|
+
' state.cliCommands = data.commands || [];',
|
|
2193
|
+
' }',
|
|
2194
|
+
'',
|
|
2195
|
+
' async function loadCliOverview() {',
|
|
2196
|
+
' const res = await fetch(apiUrl("/api/cli/overview"), { headers: authHeaders() }).catch(() => null);',
|
|
2197
|
+
' if (!res || !res.ok) return;',
|
|
2198
|
+
' const d = await res.json();',
|
|
2199
|
+
' const parts = [',
|
|
2200
|
+
' (d.commandsCount || 0) + " commands",',
|
|
2201
|
+
' (d.skillsCount || 0) + " skills"',
|
|
2202
|
+
' ];',
|
|
2203
|
+
' const cps = (d.checkpoints || []).length;',
|
|
2204
|
+
' if (cps > 0) parts.push(cps + " checkpoints");',
|
|
2205
|
+
' const mcps = (d.mcpServers || []).length;',
|
|
2206
|
+
' if (mcps > 0) parts.push(mcps + " MCP");',
|
|
2207
|
+
' const tasks = (d.tasks || []).length;',
|
|
2208
|
+
' if (tasks > 0) parts.push(tasks + " running");',
|
|
2209
|
+
' cliStatsEl.textContent = parts.join(" · ");',
|
|
2210
|
+
' }',
|
|
2211
|
+
'',
|
|
2212
|
+
' function appendCliTurnCard(cmdLine, title, output, ok) {',
|
|
2213
|
+
' setStageMode(true);',
|
|
2214
|
+
' const turn = document.createElement("div");',
|
|
2215
|
+
' turn.className = "turn assistant";',
|
|
2216
|
+
' const card = document.createElement("div");',
|
|
2217
|
+
' card.className = "cli-turn-card";',
|
|
2218
|
+
' const head = document.createElement("div");',
|
|
2219
|
+
' head.className = "cli-turn-head";',
|
|
2220
|
+
' const left = document.createElement("span");',
|
|
2221
|
+
' left.textContent = (title || cmdLine) + (ok ? "" : " (failed)");',
|
|
2222
|
+
' if (!ok) left.style.color = "var(--err)";',
|
|
2223
|
+
' const right = document.createElement("div");',
|
|
2224
|
+
' right.style.display = "inline-flex"; right.style.gap = "6px";',
|
|
2225
|
+
' const copyBtn = document.createElement("button");',
|
|
2226
|
+
' copyBtn.type = "button"; copyBtn.className = "code-btn"; copyBtn.textContent = "Copy";',
|
|
2227
|
+
' copyBtn.addEventListener("click", () => copyText(output || "", copyBtn));',
|
|
2228
|
+
' const canvasBtn = document.createElement("button");',
|
|
2229
|
+
' canvasBtn.type = "button"; canvasBtn.className = "code-btn"; canvasBtn.textContent = "Canvas";',
|
|
2230
|
+
' canvasBtn.addEventListener("click", () => openInCanvas("cli-output.md", output || "", false));',
|
|
2231
|
+
' right.appendChild(copyBtn); right.appendChild(canvasBtn);',
|
|
2232
|
+
' head.appendChild(left); head.appendChild(right);',
|
|
2233
|
+
' const pre = document.createElement("pre");',
|
|
2234
|
+
' pre.className = "cli-turn-body";',
|
|
2235
|
+
' pre.textContent = output || "(no output)";',
|
|
2236
|
+
' card.appendChild(head); card.appendChild(pre);',
|
|
2237
|
+
' turn.appendChild(card);',
|
|
2238
|
+
' threadEl.appendChild(turn);',
|
|
2239
|
+
' scrollToBottom(true);',
|
|
2240
|
+
' }',
|
|
2241
|
+
'',
|
|
2242
|
+
' async function runCliCommand(rawInput, target) {',
|
|
2243
|
+
' const trimmed = String(rawInput || "").trim();',
|
|
2244
|
+
' if (!trimmed) return;',
|
|
2245
|
+
' if (trimmed === "/new" || trimmed === "/clear") { startFreshChat(); return; }',
|
|
2246
|
+
' if (trimmed === "/browser") { openStudio("browser"); return; }',
|
|
2247
|
+
' if (trimmed === "/diff") { openStudio("diff"); }',
|
|
2248
|
+
' if (target === "studio") {',
|
|
2249
|
+
' cliStatusEl.textContent = "Running " + trimmed + "...";',
|
|
2250
|
+
' cliConsoleEl.textContent = "Executing " + trimmed + "...";',
|
|
2251
|
+
' } else {',
|
|
2252
|
+
' appendUserTurn(trimmed, []);',
|
|
2253
|
+
' }',
|
|
2254
|
+
' const res = await fetch(apiUrl("/api/command"), {',
|
|
2255
|
+
' method: "POST", headers: authHeaders({ "Content-Type": "application/json" }),',
|
|
2256
|
+
' body: JSON.stringify({ input: trimmed })',
|
|
2257
|
+
' }).catch(() => null);',
|
|
2258
|
+
' if (!res) {',
|
|
2259
|
+
' if (target === "studio") cliConsoleEl.textContent = "Command request failed.";',
|
|
2260
|
+
' else appendCliTurnCard(trimmed, trimmed, "Command request failed.", false);',
|
|
2261
|
+
' return;',
|
|
2262
|
+
' }',
|
|
2263
|
+
' const data = await res.json().catch(() => ({ ok: false, output: "HTTP " + res.status }));',
|
|
2264
|
+
' const outText = data.output || data.error || "(done)";',
|
|
2265
|
+
' if (target === "studio") {',
|
|
2266
|
+
' cliConsoleEl.textContent = outText;',
|
|
2267
|
+
' cliStatusEl.textContent = (data.ok ? "OK · " : "Failed · ") + trimmed;',
|
|
2268
|
+
' void loadCliOverview();',
|
|
2269
|
+
' } else {',
|
|
2270
|
+
' appendCliTurnCard(trimmed, data.title || trimmed, outText, Boolean(data.ok));',
|
|
2271
|
+
' }',
|
|
2272
|
+
' void loadHealth();',
|
|
2273
|
+
' }',
|
|
2274
|
+
'',
|
|
2275
|
+
' async function runZeroSpendProbe() {',
|
|
2276
|
+
' cliStatusEl.textContent = "Testing connections...";',
|
|
2277
|
+
' cliConsoleEl.textContent = "Checking local Ollama and configured providers...";',
|
|
2278
|
+
' const res = await fetch(apiUrl("/api/doctor/probe"), { method: "POST", headers: authHeaders() }).catch(() => null);',
|
|
2279
|
+
' if (!res || !res.ok) { cliConsoleEl.textContent = "Connection test failed."; return; }',
|
|
2280
|
+
' const data = await res.json();',
|
|
2281
|
+
' cliConsoleEl.textContent = data.report || "Completed.";',
|
|
2282
|
+
' cliStatusEl.textContent = (data.summary?.passedCount || 0) + " connected";',
|
|
2283
|
+
' }',
|
|
2284
|
+
'',
|
|
2285
|
+
' async function saveVaultApiKey() {',
|
|
2286
|
+
' const provider = vaultProviderSelect.value;',
|
|
2287
|
+
' const apiKey = (vaultKeyInput.value || "").trim();',
|
|
2288
|
+
' if (!apiKey) { vaultStatusEl.textContent = "Enter an API key first."; return; }',
|
|
2289
|
+
' vaultStatusEl.textContent = "Saving...";',
|
|
2290
|
+
' const res = await fetch(apiUrl("/api/config/key"), {',
|
|
2291
|
+
' method: "POST", headers: authHeaders({ "Content-Type": "application/json" }),',
|
|
2292
|
+
' body: JSON.stringify({ provider, apiKey, activate: true })',
|
|
2293
|
+
' }).catch(() => null);',
|
|
2294
|
+
' vaultKeyInput.value = "";',
|
|
2295
|
+
' if (!res || !res.ok) { vaultStatusEl.textContent = "Could not save key."; return; }',
|
|
2296
|
+
' const data = await res.json();',
|
|
2297
|
+
' vaultStatusEl.textContent = "Saved for " + data.provider + ".";',
|
|
2298
|
+
' void loadHealth();',
|
|
2299
|
+
' void loadModels();',
|
|
2300
|
+
' }',
|
|
2301
|
+
'',
|
|
2302
|
+
' function renderCanvasPreview() {',
|
|
2303
|
+
' const pathVal = (filePathInput.value || "").trim();',
|
|
2304
|
+
' const content = fileContentInput.value || "";',
|
|
2305
|
+
' if (isHtmlOrSvgPath(pathVal)) {',
|
|
2306
|
+
' canvasPreviewEl.style.display = "none";',
|
|
2307
|
+
' canvasHtmlFrame.style.display = "block";',
|
|
2308
|
+
' canvasHtmlFrame.srcdoc = content.trim().startsWith("<svg")',
|
|
2309
|
+
' ? ("<!DOCTYPE html><html><body style=\\"margin:0;display:grid;place-items:center;min-height:100vh;background:#141714\\">" + content + "</body></html>")',
|
|
2310
|
+
' : content;',
|
|
2311
|
+
' } else {',
|
|
2312
|
+
' canvasHtmlFrame.style.display = "none";',
|
|
2313
|
+
' canvasPreviewEl.style.display = "block";',
|
|
2314
|
+
' renderMarkdownInto(canvasPreviewEl, content, false);',
|
|
2315
|
+
' }',
|
|
2316
|
+
' }',
|
|
2317
|
+
'',
|
|
2318
|
+
' function setCanvasPreviewMode(previewOn) {',
|
|
2319
|
+
' state.canvasPreviewMode = previewOn;',
|
|
2320
|
+
' canvasCodeBtn.classList.toggle("active", !previewOn);',
|
|
2321
|
+
' canvasModeBtn.classList.toggle("active", previewOn);',
|
|
2322
|
+
' fileContentInput.style.display = previewOn ? "none" : "block";',
|
|
2323
|
+
' if (previewOn) {',
|
|
2324
|
+
' renderCanvasPreview();',
|
|
2325
|
+
' } else {',
|
|
2326
|
+
' canvasPreviewEl.style.display = "none";',
|
|
2327
|
+
' canvasHtmlFrame.style.display = "none";',
|
|
2328
|
+
' }',
|
|
2329
|
+
' }',
|
|
2330
|
+
'',
|
|
2331
|
+
' /* Draggable Split-Pane Resize Handle (CSS-Variable Driven, Snap-to-Close, DblClick Reset) */',
|
|
2332
|
+
' let resizing = false;',
|
|
2333
|
+
' let snapClosePending = false;',
|
|
2334
|
+
' let resizePointerId = null;',
|
|
2335
|
+
' let resizeStartWidth = DEFAULT_STUDIO_W;',
|
|
2336
|
+
' studioResizer.addEventListener("pointerdown", (e) => {',
|
|
2337
|
+
' if (!appEl.classList.contains("studio-open") || state.studioExpanded) return;',
|
|
2338
|
+
' e.preventDefault();',
|
|
2339
|
+
' resizing = true;',
|
|
2340
|
+
' snapClosePending = false;',
|
|
2341
|
+
' resizeStartWidth = state.studioWidth || DEFAULT_STUDIO_W;',
|
|
2342
|
+
' resizePointerId = e.pointerId;',
|
|
2343
|
+
' appEl.classList.add("studio-resizing");',
|
|
2344
|
+
' studioResizer.classList.add("dragging");',
|
|
2345
|
+
' try { studioResizer.setPointerCapture(e.pointerId); } catch {}',
|
|
2346
|
+
' });',
|
|
2347
|
+
' studioResizer.addEventListener("pointermove", (e) => {',
|
|
2348
|
+
' if (!resizing) return;',
|
|
2349
|
+
' const rawW = window.innerWidth - e.clientX;',
|
|
2350
|
+
' if (rawW < 210) {',
|
|
2351
|
+
' snapClosePending = true;',
|
|
2352
|
+
' studioResizer.classList.add("snap-close");',
|
|
2353
|
+
' return;',
|
|
2354
|
+
' }',
|
|
2355
|
+
' snapClosePending = false;',
|
|
2356
|
+
' studioResizer.classList.remove("snap-close");',
|
|
2357
|
+
' applyStudioWidth(rawW, false);',
|
|
2358
|
+
' });',
|
|
2359
|
+
' const endResize = (cancelled) => {',
|
|
2360
|
+
' if (!resizing) return;',
|
|
2361
|
+
' resizing = false;',
|
|
2362
|
+
' const shouldSnapClose = !cancelled && snapClosePending;',
|
|
2363
|
+
' snapClosePending = false;',
|
|
2364
|
+
' appEl.classList.remove("studio-resizing");',
|
|
2365
|
+
' studioResizer.classList.remove("dragging", "snap-close");',
|
|
2366
|
+
' if (resizePointerId !== null) {',
|
|
2367
|
+
' try { studioResizer.releasePointerCapture(resizePointerId); } catch {}',
|
|
2368
|
+
' resizePointerId = null;',
|
|
2369
|
+
' }',
|
|
2370
|
+
' if (shouldSnapClose) {',
|
|
2371
|
+
' applyStudioWidth(resizeStartWidth, false);',
|
|
2372
|
+
' closeStudio();',
|
|
2373
|
+
' } else if (cancelled) {',
|
|
2374
|
+
' applyStudioWidth(resizeStartWidth, false);',
|
|
2375
|
+
' } else {',
|
|
2376
|
+
' applyStudioWidth(state.studioWidth, true);',
|
|
2377
|
+
' }',
|
|
2378
|
+
' };',
|
|
2379
|
+
' studioResizer.addEventListener("pointerup", () => endResize(false));',
|
|
2380
|
+
' studioResizer.addEventListener("pointercancel", () => endResize(true));',
|
|
2381
|
+
' studioResizer.addEventListener("dblclick", () => {',
|
|
2382
|
+
' if (!appEl.classList.contains("studio-open")) return;',
|
|
2383
|
+
' state.studioExpanded = false;',
|
|
2384
|
+
' appEl.classList.remove("studio-expanded");',
|
|
2385
|
+
' applyStudioWidth(DEFAULT_STUDIO_W, true);',
|
|
2386
|
+
' syncPanelChromeState();',
|
|
2387
|
+
' });',
|
|
2388
|
+
' window.addEventListener("resize", () => {',
|
|
2389
|
+
' closeAllPopovers();',
|
|
2390
|
+
' if (appEl.classList.contains("studio-open") && window.innerWidth > 960) {',
|
|
2391
|
+
' applyStudioWidth(state.studioWidth, false);',
|
|
2392
|
+
' }',
|
|
2393
|
+
' });',
|
|
2394
|
+
'',
|
|
2395
|
+
' /* Sessions Sidebar */',
|
|
2396
|
+
' function bucketLabel(ts) {',
|
|
2397
|
+
' const now = new Date();',
|
|
2398
|
+
' const startToday = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime();',
|
|
2399
|
+
' const dayMs = 86400000;',
|
|
2400
|
+
' if (ts >= startToday) return "Today";',
|
|
2401
|
+
' if (ts >= startToday - dayMs) return "Yesterday";',
|
|
2402
|
+
' if (ts >= startToday - 7 * dayMs) return "Previous 7 days";',
|
|
2403
|
+
' return "Older";',
|
|
2404
|
+
' }',
|
|
2405
|
+
'',
|
|
2406
|
+
' function updateActiveSessionRow(activeId) {',
|
|
2407
|
+
' sessionListEl.querySelectorAll(".session-item").forEach((elItem) => {',
|
|
2408
|
+
' elItem.classList.toggle("active", Boolean(activeId && elItem.dataset.sessionId === activeId));',
|
|
2409
|
+
' });',
|
|
2410
|
+
' }',
|
|
2411
|
+
'',
|
|
2412
|
+
' function startInlineSessionRename(item, titleBtn, s) {',
|
|
2413
|
+
' const input = document.createElement("input");',
|
|
2414
|
+
' input.type = "text"; input.className = "session-rename-input";',
|
|
2415
|
+
' input.value = s.title || ""; input.maxLength = 80;',
|
|
2416
|
+
' titleBtn.style.display = "none";',
|
|
2417
|
+
' item.insertBefore(input, titleBtn);',
|
|
2418
|
+
' input.focus(); input.select();',
|
|
2419
|
+
' let finished = false;',
|
|
2420
|
+
' const finish = async (save) => {',
|
|
2421
|
+
' if (finished) return; finished = true;',
|
|
2422
|
+
' const next = (input.value || "").trim();',
|
|
2423
|
+
' input.remove(); titleBtn.style.display = "";',
|
|
2424
|
+
' if (!save || !next || next === s.title) return;',
|
|
2425
|
+
' s.title = next; titleBtn.textContent = next;',
|
|
2426
|
+
' await fetch(apiUrl("/api/sessions/" + encodeURIComponent(s.id)), {',
|
|
2427
|
+
' method: "PATCH", headers: authHeaders({ "Content-Type": "application/json" }),',
|
|
2428
|
+
' body: JSON.stringify({ title: next })',
|
|
2429
|
+
' }).catch(() => {});',
|
|
2430
|
+
' };',
|
|
2431
|
+
' input.addEventListener("click", (ev) => ev.stopPropagation());',
|
|
2432
|
+
' input.addEventListener("keydown", (ev) => {',
|
|
2433
|
+
' if (ev.key === "Enter") { ev.preventDefault(); ev.stopPropagation(); void finish(true); }',
|
|
2434
|
+
' else if (ev.key === "Escape") { ev.preventDefault(); ev.stopPropagation(); void finish(false); }',
|
|
2435
|
+
' });',
|
|
2436
|
+
' input.addEventListener("blur", () => { void finish(true); });',
|
|
2437
|
+
' }',
|
|
2438
|
+
'',
|
|
2439
|
+
' function renderSessionList() {',
|
|
2440
|
+
' const prevScroll = sessionListEl.scrollTop;',
|
|
2441
|
+
' const q = (sessionSearchEl.value || "").trim().toLowerCase();',
|
|
2442
|
+
' const filtered = state.sessions.filter((s) => !q || String(s.title || "").toLowerCase().includes(q));',
|
|
2443
|
+
' sessionListEl.textContent = "";',
|
|
2444
|
+
' if (filtered.length === 0) {',
|
|
2445
|
+
' const empty = document.createElement("div");',
|
|
2446
|
+
' empty.className = "session-empty";',
|
|
2447
|
+
' empty.textContent = q ? "No matching chats." : "No saved workspace chats yet.";',
|
|
2448
|
+
' sessionListEl.appendChild(empty);',
|
|
2449
|
+
' return;',
|
|
2450
|
+
' }',
|
|
2451
|
+
' let currentGroup = "";',
|
|
2452
|
+
' for (const s of filtered) {',
|
|
2453
|
+
' const grp = bucketLabel(s.updatedAt || s.createdAt || 0);',
|
|
2454
|
+
' if (grp !== currentGroup) {',
|
|
2455
|
+
' currentGroup = grp;',
|
|
2456
|
+
' const gl = document.createElement("div");',
|
|
2457
|
+
' gl.className = "session-group-label";',
|
|
2458
|
+
' gl.textContent = grp;',
|
|
2459
|
+
' sessionListEl.appendChild(gl);',
|
|
2460
|
+
' }',
|
|
2461
|
+
' const item = document.createElement("div");',
|
|
2462
|
+
' item.dataset.sessionId = s.id;',
|
|
2463
|
+
' item.className = "session-item" + (s.id === state.sessionId ? " active" : "");',
|
|
2464
|
+
' item.addEventListener("click", () => { void loadSessionTranscript(s.id); });',
|
|
2465
|
+
' if (s.running) {',
|
|
2466
|
+
' const dot = document.createElement("span");',
|
|
2467
|
+
' dot.className = "session-run-dot" + (s.awaitingClient ? " awaiting" : "");',
|
|
2468
|
+
' dot.title = s.awaitingClient ? "Waiting for your input" : "Running in background";',
|
|
2469
|
+
' item.appendChild(dot);',
|
|
2470
|
+
' }',
|
|
2471
|
+
' const titleBtn = document.createElement("button");',
|
|
2472
|
+
' titleBtn.type = "button"; titleBtn.className = "session-title";',
|
|
2473
|
+
' titleBtn.textContent = s.title || "Untitled";',
|
|
2474
|
+
' titleBtn.title = s.title || "Untitled";',
|
|
2475
|
+
' const actions = document.createElement("div");',
|
|
2476
|
+
' actions.className = "session-actions";',
|
|
2477
|
+
' const renBtn = document.createElement("button");',
|
|
2478
|
+
' renBtn.type = "button"; renBtn.className = "mini-icon-btn"; renBtn.textContent = "R"; renBtn.title = "Rename";',
|
|
2479
|
+
' renBtn.addEventListener("click", (e) => {',
|
|
2480
|
+
' e.stopPropagation();',
|
|
2481
|
+
' startInlineSessionRename(item, titleBtn, s);',
|
|
2482
|
+
' });',
|
|
2483
|
+
' const delBtn = document.createElement("button");',
|
|
2484
|
+
' delBtn.type = "button"; delBtn.className = "mini-icon-btn"; delBtn.textContent = "x"; delBtn.title = "Delete";',
|
|
2485
|
+
' delBtn.addEventListener("click", async (e) => {',
|
|
2486
|
+
' e.stopPropagation();',
|
|
2487
|
+
' await fetch(apiUrl("/api/sessions/" + encodeURIComponent(s.id)), { method: "DELETE", headers: authHeaders() }).catch(() => {});',
|
|
2488
|
+
' state.sessionWorkspaces.delete(s.id);',
|
|
2489
|
+
' if (state.sessionId === s.id) void startFreshChat();',
|
|
2490
|
+
' void loadSessions();',
|
|
2491
|
+
' });',
|
|
2492
|
+
' actions.appendChild(renBtn); actions.appendChild(delBtn);',
|
|
2493
|
+
' item.appendChild(titleBtn); item.appendChild(actions);',
|
|
2494
|
+
' sessionListEl.appendChild(item);',
|
|
2495
|
+
' }',
|
|
2496
|
+
' sessionListEl.scrollTop = prevScroll;',
|
|
2497
|
+
' }',
|
|
2498
|
+
'',
|
|
2499
|
+
' async function loadSessions() {',
|
|
2500
|
+
' const res = await fetch(apiUrl("/api/sessions"), { headers: authHeaders() });',
|
|
2501
|
+
' if (!res.ok) return;',
|
|
2502
|
+
' const data = await res.json();',
|
|
2503
|
+
' state.sessions = data.sessions || [];',
|
|
2504
|
+
' renderSessionList();',
|
|
2505
|
+
' }',
|
|
2506
|
+
'',
|
|
2507
|
+
' function sessionKey(id) { return id || "__draft__"; }',
|
|
2508
|
+
'',
|
|
2509
|
+
' function syncUsagePill(tokens) {',
|
|
2510
|
+
' state.usageTokens = Number(tokens) > 0 ? Number(tokens) : 0;',
|
|
2511
|
+
' if (state.usageTokens > 0) {',
|
|
2512
|
+
' usagePill.textContent = state.usageTokens.toLocaleString() + " tok";',
|
|
2513
|
+
' usagePill.classList.add("visible");',
|
|
2514
|
+
' } else {',
|
|
2515
|
+
' usagePill.textContent = "";',
|
|
2516
|
+
' usagePill.classList.remove("visible");',
|
|
2517
|
+
' }',
|
|
2518
|
+
' }',
|
|
2519
|
+
'',
|
|
2520
|
+
' function syncDiffControlsUi() {',
|
|
2521
|
+
' const isSessionScope = state.diffScope === "session" && Boolean(state.sessionId);',
|
|
2522
|
+
' if (diffScopeSessionBtn) {',
|
|
2523
|
+
' diffScopeSessionBtn.classList.toggle("active", isSessionScope);',
|
|
2524
|
+
' diffScopeSessionBtn.disabled = !state.sessionId;',
|
|
2525
|
+
' }',
|
|
2526
|
+
' if (diffScopeWorkspaceBtn) diffScopeWorkspaceBtn.classList.toggle("active", !isSessionScope);',
|
|
2527
|
+
' if (diffStagedToggle) {',
|
|
2528
|
+
' diffStagedToggle.style.display = isSessionScope ? "none" : "inline-block";',
|
|
2529
|
+
' diffStagedToggle.textContent = state.diffStaged ? "Staged" : "Working";',
|
|
2530
|
+
' }',
|
|
2531
|
+
' }',
|
|
2532
|
+
'',
|
|
2533
|
+
' function saveCurrentSessionWorkspace() {',
|
|
2534
|
+
' const key = sessionKey(state.sessionId);',
|
|
2535
|
+
' state.sessionWorkspaces.set(key, {',
|
|
2536
|
+
' studioOpen: appEl.classList.contains("studio-open"),',
|
|
2537
|
+
' studioTab: state.studioTab,',
|
|
2538
|
+
' canvasPath: filePathInput.value || "",',
|
|
2539
|
+
' canvasContent: fileContentInput.value || "",',
|
|
2540
|
+
' canvasPreviewMode: Boolean(state.canvasPreviewMode),',
|
|
2541
|
+
' canvasStatus: fileStatusEl.textContent || "Ready",',
|
|
2542
|
+
' canvasDirty: Boolean(state.canvasDirty),',
|
|
2543
|
+
' diffScope: state.diffScope,',
|
|
2544
|
+
' diffStaged: Boolean(state.diffStaged),',
|
|
2545
|
+
' attachments: state.attachments.slice(),',
|
|
2546
|
+
' draftPrompt: promptInput.value || "",',
|
|
2547
|
+
' usageTokens: state.usageTokens,',
|
|
2548
|
+
' browserEngine: state.browserEngine,',
|
|
2549
|
+
' browserMode: state.browserMode,',
|
|
2550
|
+
' browserUrl: state.browserUrl,',
|
|
2551
|
+
' browserSrcdoc: state.browserSrcdoc,',
|
|
2552
|
+
' cliConsoleText: cliConsoleEl.textContent || "Select a command above or type /help.",',
|
|
2553
|
+
' cliStatusText: cliStatusEl.textContent || "Ready"',
|
|
2554
|
+
' });',
|
|
2555
|
+
' }',
|
|
2556
|
+
'',
|
|
2557
|
+
' function applySessionWorkspace(nextSessionId) {',
|
|
2558
|
+
' const key = sessionKey(nextSessionId);',
|
|
2559
|
+
' const saved = state.sessionWorkspaces.get(key) || null;',
|
|
2560
|
+
' state.attachments = saved ? saved.attachments.slice() : [];',
|
|
2561
|
+
' renderAttachmentChips();',
|
|
2562
|
+
' promptInput.value = saved ? saved.draftPrompt : "";',
|
|
2563
|
+
' updateComposerMetrics();',
|
|
2564
|
+
' syncUsagePill(saved ? saved.usageTokens : 0);',
|
|
2565
|
+
' filePathInput.value = saved ? saved.canvasPath : "";',
|
|
2566
|
+
' fileContentInput.value = saved ? saved.canvasContent : "";',
|
|
2567
|
+
' state.canvasDirty = saved ? Boolean(saved.canvasDirty) : false;',
|
|
2568
|
+
' fileStatusEl.textContent = saved ? saved.canvasStatus : "Ready";',
|
|
2569
|
+
' canvasHtmlFrame.removeAttribute("srcdoc");',
|
|
2570
|
+
' canvasPreviewEl.textContent = "";',
|
|
2571
|
+
' syncArtifactVersionSelect(filePathInput.value.trim());',
|
|
2572
|
+
' setCanvasPreviewMode(saved ? Boolean(saved.canvasPreviewMode) : false);',
|
|
2573
|
+
' state.diffScope = saved ? saved.diffScope : (nextSessionId ? "session" : "workspace");',
|
|
2574
|
+
' state.diffStaged = saved ? Boolean(saved.diffStaged) : false;',
|
|
2575
|
+
' syncDiffControlsUi();',
|
|
2576
|
+
' diffListEl.textContent = "";',
|
|
2577
|
+
' diffSummaryEl.textContent = "Loading...";',
|
|
2578
|
+
' cliConsoleEl.textContent = saved ? saved.cliConsoleText : "Select a command above or type /help.";',
|
|
2579
|
+
' cliStatusEl.textContent = saved ? saved.cliStatusText : "Ready";',
|
|
2580
|
+
' if (saved && saved.browserEngine === "frame") {',
|
|
2581
|
+
' state.browserMode = saved.browserMode || "empty";',
|
|
2582
|
+
' state.browserUrl = saved.browserUrl || "";',
|
|
2583
|
+
' state.browserSrcdoc = saved.browserSrcdoc || "";',
|
|
2584
|
+
' if (state.browserMode === "srcdoc" && state.browserSrcdoc) {',
|
|
2585
|
+
' browserFrame.removeAttribute("src");',
|
|
2586
|
+
' browserFrame.srcdoc = state.browserSrcdoc;',
|
|
2587
|
+
' } else if (state.browserMode === "url" && state.browserUrl) {',
|
|
2588
|
+
' browserFrame.removeAttribute("srcdoc");',
|
|
2589
|
+
' browserFrame.src = state.browserUrl;',
|
|
2590
|
+
' } else {',
|
|
2591
|
+
' browserFrame.removeAttribute("srcdoc");',
|
|
2592
|
+
' browserFrame.removeAttribute("src");',
|
|
2593
|
+
' }',
|
|
2594
|
+
' setBrowserEngine("frame");',
|
|
2595
|
+
' } else {',
|
|
2596
|
+
' state.browserMode = "empty"; state.browserUrl = ""; state.browserSrcdoc = "";',
|
|
2597
|
+
' browserFrame.removeAttribute("srcdoc"); browserFrame.removeAttribute("src");',
|
|
2598
|
+
' if (state.browserEngine === "frame") setBrowserEngine("agent");',
|
|
2599
|
+
' }',
|
|
2600
|
+
' if (appEl.classList.contains("studio-open")) {',
|
|
2601
|
+
' if (state.studioTab === "diff") void loadDiff();',
|
|
2602
|
+
' else if (state.studioTab === "files") void loadFiles(state.currentDir, fileFilterEl.value || "");',
|
|
2603
|
+
' else if (state.studioTab === "cli") void loadCliOverview();',
|
|
2604
|
+
' else if (state.studioTab === "browser" && state.browserEngine === "agent") { void refreshLiveBrowserState(false); startLiveBrowserStream(); }',
|
|
2605
|
+
' }',
|
|
2606
|
+
' }',
|
|
2607
|
+
'',
|
|
2608
|
+
' function detachLocalStreamReader() {',
|
|
2609
|
+
' if (state.activeController) {',
|
|
2610
|
+
' try { state.activeController.abort(); } catch {}',
|
|
2611
|
+
' state.activeController = null;',
|
|
2612
|
+
' }',
|
|
2613
|
+
' state.activeTurn = null;',
|
|
2614
|
+
' state.activePrompt = "";',
|
|
2615
|
+
' setLiveness(false, "");',
|
|
2616
|
+
' updateComposerMetrics();',
|
|
2617
|
+
' }',
|
|
2618
|
+
'',
|
|
2619
|
+
' async function loadSessionTranscript(id) {',
|
|
2620
|
+
' if (!id) return;',
|
|
2621
|
+
' // Switching chats detaches ONLY our local UI stream reader — the server keeps AgentLoop running in the background.',
|
|
2622
|
+
' detachLocalStreamReader();',
|
|
2623
|
+
' saveCurrentSessionWorkspace();',
|
|
2624
|
+
' const seq = ++state.sessionSwitchSeq;',
|
|
2625
|
+
' state.sessionId = id;',
|
|
2626
|
+
' updateActiveSessionRow(id);',
|
|
2627
|
+
' applySessionWorkspace(id);',
|
|
2628
|
+
' if (window.innerWidth <= 960) appEl.classList.add("sidebar-collapsed");',
|
|
2629
|
+
' const res = await fetch(apiUrl("/api/sessions/" + encodeURIComponent(id)), { headers: authHeaders() }).catch(() => null);',
|
|
2630
|
+
' if (seq !== state.sessionSwitchSeq) return;',
|
|
2631
|
+
' if (!res || !res.ok) {',
|
|
2632
|
+
' threadEl.textContent = "";',
|
|
2633
|
+
' resetThreadSpacer();',
|
|
2634
|
+
' setStageMode(true);',
|
|
2635
|
+
' const errTurn = createAssistantTurn("");',
|
|
2636
|
+
' errTurn.addError(res && res.status === 401',
|
|
2637
|
+
' ? "Session authentication expired. Reopen the URL printed by `causyne web`."',
|
|
2638
|
+
' : "Could not load conversation (HTTP " + (res ? res.status : "network error") + ").");',
|
|
2639
|
+
' return;',
|
|
2640
|
+
' }',
|
|
2641
|
+
' const data = await res.json().catch(() => null);',
|
|
2642
|
+
' const sess = data && data.session;',
|
|
2643
|
+
' if (!sess || seq !== state.sessionSwitchSeq) return;',
|
|
2644
|
+
' threadEl.textContent = "";',
|
|
2645
|
+
' resetThreadSpacer();',
|
|
2646
|
+
' threadEl.classList.remove("chat-fade-in");',
|
|
2647
|
+
' void threadEl.offsetWidth;',
|
|
2648
|
+
' threadEl.classList.add("chat-fade-in");',
|
|
2649
|
+
' const msgs = sess.messages || [];',
|
|
2650
|
+
' setStageMode(msgs.length > 0 || Boolean(sess.running));',
|
|
2651
|
+
' let lastUserPrompt = "";',
|
|
2652
|
+
' for (const m of msgs) {',
|
|
2653
|
+
' if (m.role === "user") {',
|
|
2654
|
+
' lastUserPrompt = m.content || "";',
|
|
2655
|
+
' appendUserTurn(lastUserPrompt, [], false);',
|
|
2656
|
+
' } else {',
|
|
2657
|
+
' const t = createAssistantTurn(lastUserPrompt, { restored: true });',
|
|
2658
|
+
' if (Array.isArray(m.blocks) && m.blocks.length > 0) {',
|
|
2659
|
+
' t.renderRestoredBlocks(m.blocks);',
|
|
2660
|
+
' } else {',
|
|
2661
|
+
' if (m.reasoning) t.updateReasoning({ content: m.reasoning, streaming: false });',
|
|
2662
|
+
' if (Array.isArray(m.steps)) {',
|
|
2663
|
+
' for (const st of m.steps) {',
|
|
2664
|
+
' t.addNativeStep({ actionName: st.tool, detail: st.target || st.output || "", message: st.tool }, st.status === "failed");',
|
|
2665
|
+
' }',
|
|
2666
|
+
' }',
|
|
2667
|
+
' if (m.content) t.setText(m.content, false);',
|
|
2668
|
+
' }',
|
|
2669
|
+
' t.finish();',
|
|
2670
|
+
' }',
|
|
2671
|
+
' }',
|
|
2672
|
+
' if (sess.running && sess.activeRun) {',
|
|
2673
|
+
' // Re-attach seamlessly to the live background run (Claude Desktop rejoin behavior).',
|
|
2674
|
+
' const runPrompt = sess.activeRun.prompt || lastUserPrompt;',
|
|
2675
|
+
' if (runPrompt && (msgs.length === 0 || msgs[msgs.length - 1].role !== "user" || msgs[msgs.length - 1].content !== runPrompt)) {',
|
|
2676
|
+
' appendUserTurn(runPrompt, [], false);',
|
|
2677
|
+
' }',
|
|
2678
|
+
' scrollToBottom(true);',
|
|
2679
|
+
' void attachToActiveSessionStream(id, runPrompt, seq);',
|
|
2680
|
+
' return;',
|
|
2681
|
+
' }',
|
|
2682
|
+
' if (msgs.length > 0 && msgs[msgs.length - 1].role === "user") {',
|
|
2683
|
+
' const interruptedTurn = createAssistantTurn(lastUserPrompt, { restored: true });',
|
|
2684
|
+
' interruptedTurn.addInterrupted("Causyne\\u2019s response was interrupted.", lastUserPrompt);',
|
|
2685
|
+
' interruptedTurn.finish();',
|
|
2686
|
+
' }',
|
|
2687
|
+
' scrollToBottom(true);',
|
|
2688
|
+
' }',
|
|
2689
|
+
'',
|
|
2690
|
+
' async function startFreshChat() {',
|
|
2691
|
+
' detachLocalStreamReader();',
|
|
2692
|
+
' saveCurrentSessionWorkspace();',
|
|
2693
|
+
' state.sessionSwitchSeq += 1;',
|
|
2694
|
+
' state.sessionWorkspaces.delete("__draft__");',
|
|
2695
|
+
' state.sessionId = null;',
|
|
2696
|
+
' threadEl.textContent = "";',
|
|
2697
|
+
' resetThreadSpacer();',
|
|
2698
|
+
' setStageMode(false);',
|
|
2699
|
+
' applySessionWorkspace(null);',
|
|
2700
|
+
' updateActiveSessionRow(null);',
|
|
2701
|
+
' promptInput.focus();',
|
|
2702
|
+
' if (window.innerWidth <= 960) appEl.classList.add("sidebar-collapsed");',
|
|
2703
|
+
' }',
|
|
2704
|
+
'',
|
|
2705
|
+
' /* Health & Model Switcher */',
|
|
2706
|
+
' async function loadHealth() {',
|
|
2707
|
+
' const res = await fetch(apiUrl("/api/health"), { headers: authHeaders() });',
|
|
2708
|
+
' if (!res.ok) {',
|
|
2709
|
+
' wsNameEl.textContent = "Auth required";',
|
|
2710
|
+
' wsMetaEl.textContent = "Open URL printed by causyne web";',
|
|
2711
|
+
' const turn = createAssistantTurn("");',
|
|
2712
|
+
' turn.addError("Missing or invalid Skybridge token. Open the URL printed by `causyne web`.");',
|
|
2713
|
+
' return;',
|
|
2714
|
+
' }',
|
|
2715
|
+
' const data = await res.json();',
|
|
2716
|
+
' state.activeProvider = data.provider || "unconfigured";',
|
|
2717
|
+
' state.activeModel = data.model || "default";',
|
|
2718
|
+
' state.workspaceRoot = data.workspaceRoot || "";',
|
|
2719
|
+
' wsNameEl.textContent = data.workspaceName || "Workspace";',
|
|
2720
|
+
' wsMetaEl.textContent = "v" + data.version;',
|
|
2721
|
+
' if (settingsWsPath) settingsWsPath.textContent = data.workspaceRoot || "";',
|
|
2722
|
+
' const cleanModel = String(state.activeModel || "").split("/").pop() || state.activeProvider;',
|
|
2723
|
+
' modelTriggerName.textContent = cleanModel === "default" ? state.activeProvider : cleanModel;',
|
|
2724
|
+
' }',
|
|
2725
|
+
'',
|
|
2726
|
+
' async function loadModels(mode) {',
|
|
2727
|
+
' const isRefresh = mode === "refresh";',
|
|
2728
|
+
' const isLive = mode === "live";',
|
|
2729
|
+
' if (isRefresh || isLive) {',
|
|
2730
|
+
' state.modelRefreshing = true;',
|
|
2731
|
+
' updateModelRefreshUi();',
|
|
2732
|
+
' }',
|
|
2733
|
+
' const qs = isRefresh ? "?refresh=1" : (isLive ? "?live=1" : "");',
|
|
2734
|
+
' try {',
|
|
2735
|
+
' const res = await fetch(apiUrl("/api/models" + qs), { headers: authHeaders() });',
|
|
2736
|
+
' if (!res.ok) return;',
|
|
2737
|
+
' const data = await res.json();',
|
|
2738
|
+
' state.models = data;',
|
|
2739
|
+
' if (!state.modelTab) state.modelTab = data.initialTab || "acp";',
|
|
2740
|
+
' if (data.activeProvider) state.activeProvider = data.activeProvider;',
|
|
2741
|
+
' if (data.activeModel) state.activeModel = data.activeModel;',
|
|
2742
|
+
' renderModelPopover();',
|
|
2743
|
+
' if (!isRefresh && !isLive && !state.modelLiveHydrated) {',
|
|
2744
|
+
' state.modelLiveHydrated = true;',
|
|
2745
|
+
' void loadModels("live");',
|
|
2746
|
+
' }',
|
|
2747
|
+
' } finally {',
|
|
2748
|
+
' if (isRefresh || isLive) {',
|
|
2749
|
+
' state.modelRefreshing = false;',
|
|
2750
|
+
' updateModelRefreshUi();',
|
|
2751
|
+
' }',
|
|
2752
|
+
' }',
|
|
2753
|
+
' }',
|
|
2754
|
+
'',
|
|
2755
|
+
' function updateModelRefreshUi() {',
|
|
2756
|
+
' const btn = modelPopover.querySelector(".mp-refresh-btn");',
|
|
2757
|
+
' if (!btn) return;',
|
|
2758
|
+
' btn.disabled = state.modelRefreshing;',
|
|
2759
|
+
' btn.textContent = state.modelRefreshing ? "Refreshing..." : "Refresh";',
|
|
2760
|
+
' }',
|
|
2761
|
+
'',
|
|
2762
|
+
' async function selectModel(provider, model) {',
|
|
2763
|
+
' closeAllPopovers();',
|
|
2764
|
+
' const res = await fetch(apiUrl("/api/model"), {',
|
|
2765
|
+
' method: "POST", headers: authHeaders({ "Content-Type": "application/json" }),',
|
|
2766
|
+
' body: JSON.stringify({ provider, model })',
|
|
2767
|
+
' });',
|
|
2768
|
+
' if (!res.ok) return;',
|
|
2769
|
+
' const data = await res.json();',
|
|
2770
|
+
' state.activeProvider = data.provider;',
|
|
2771
|
+
' state.activeModel = data.model;',
|
|
2772
|
+
' const cleanModel = String(data.model || "").split("/").pop() || data.provider;',
|
|
2773
|
+
' modelTriggerName.textContent = cleanModel === "default" ? data.provider : cleanModel;',
|
|
2774
|
+
' announceStatus("Switched model to " + cleanModel);',
|
|
2775
|
+
' void loadModels();',
|
|
2776
|
+
' }',
|
|
2777
|
+
'',
|
|
2778
|
+
' async function disconnectOpenRouterAccount() {',
|
|
2779
|
+
' const res = await fetch(apiUrl("/api/model"), {',
|
|
2780
|
+
' method: "POST", headers: authHeaders({ "Content-Type": "application/json" }),',
|
|
2781
|
+
' body: JSON.stringify({ action: "disconnect", provider: "openrouter" })',
|
|
2782
|
+
' });',
|
|
2783
|
+
' if (!res.ok) return;',
|
|
2784
|
+
' const data = await res.json();',
|
|
2785
|
+
' state.activeProvider = data.provider || state.activeProvider;',
|
|
2786
|
+
' state.activeModel = data.model || state.activeModel;',
|
|
2787
|
+
' state.modelNotice = "Disconnected OpenRouter account.";',
|
|
2788
|
+
' await loadModels();',
|
|
2789
|
+
' }',
|
|
2790
|
+
'',
|
|
2791
|
+
' function fuzzyMatchModelItem(item, query) {',
|
|
2792
|
+
' const q = String(query || "").trim().toLowerCase();',
|
|
2793
|
+
' if (!q) return true;',
|
|
2794
|
+
' const hay = [item.label || "", item.category || "", item.id || "", item.description || "", (item.value && item.value.providerLabel) || ""].join(" ").toLowerCase();',
|
|
2795
|
+
' const tokens = q.split(/\\s+/).filter(Boolean);',
|
|
2796
|
+
' for (const tok of tokens) {',
|
|
2797
|
+
' if (hay.includes(tok)) continue;',
|
|
2798
|
+
' let ti = 0;',
|
|
2799
|
+
' for (let hi = 0; hi < hay.length && ti < tok.length; hi += 1) {',
|
|
2800
|
+
' if (hay[hi] === tok[ti]) ti += 1;',
|
|
2801
|
+
' }',
|
|
2802
|
+
' if (ti < tok.length) return false;',
|
|
2803
|
+
' }',
|
|
2804
|
+
' return true;',
|
|
2805
|
+
' }',
|
|
2806
|
+
'',
|
|
2807
|
+
' function getVisibleModelItems() {',
|
|
2808
|
+
' if (!state.models || !state.models.tabs) return [];',
|
|
2809
|
+
' const tab = state.modelTab || state.models.initialTab || "acp";',
|
|
2810
|
+
' const rawItems = Array.isArray(state.models.tabs[tab]) ? state.models.tabs[tab] : [];',
|
|
2811
|
+
' const q = String(state.modelQuery || "").trim();',
|
|
2812
|
+
' if (q) {',
|
|
2813
|
+
' return rawItems.filter((item) => !(item.value && item.value.isToggle) && fuzzyMatchModelItem(item, q));',
|
|
2814
|
+
' }',
|
|
2815
|
+
' if (tab !== "acp") return rawItems;',
|
|
2816
|
+
' const MAX_ACP = 10;',
|
|
2817
|
+
' const byPeer = new Map();',
|
|
2818
|
+
' const orderedPeers = [];',
|
|
2819
|
+
' for (const item of rawItems) {',
|
|
2820
|
+
' const key = (item.value && item.value.providerId) || item.category || "peer";',
|
|
2821
|
+
' if (!byPeer.has(key)) { byPeer.set(key, []); orderedPeers.push(key); }',
|
|
2822
|
+
' byPeer.get(key).push(item);',
|
|
2823
|
+
' }',
|
|
2824
|
+
' const out = [];',
|
|
2825
|
+
' for (const key of orderedPeers) {',
|
|
2826
|
+
' const peerItems = byPeer.get(key) || [];',
|
|
2827
|
+
' const installedModels = peerItems.filter((it) => it.value && it.value.installed && !it.value.isToggle);',
|
|
2828
|
+
' if (installedModels.length <= MAX_ACP) {',
|
|
2829
|
+
' for (const it of peerItems) out.push(it);',
|
|
2830
|
+
' continue;',
|
|
2831
|
+
' }',
|
|
2832
|
+
' const expanded = state.modelExpandedPeers.has(key);',
|
|
2833
|
+
' const slice = expanded ? installedModels : installedModels.slice(0, MAX_ACP);',
|
|
2834
|
+
' for (const it of slice) out.push(it);',
|
|
2835
|
+
' const first = installedModels[0];',
|
|
2836
|
+
' out.push({',
|
|
2837
|
+
' id: key + (expanded ? ":__load_less__" : ":__load_more__"),',
|
|
2838
|
+
' label: expanded ? ("Show fewer (top " + MAX_ACP + ")") : ("Show " + (installedModels.length - MAX_ACP) + " more models..."),',
|
|
2839
|
+
' category: first ? first.category : "",',
|
|
2840
|
+
' description: expanded ? "collapse" : "expand",',
|
|
2841
|
+
' value: { type: "toggle", isToggle: true, action: expanded ? "collapse" : "expand", peerKey: key, providerId: key, modelId: "", providerLabel: first && first.value ? first.value.providerLabel : key, installed: true, isCurrent: false, isConfigured: true }',
|
|
2842
|
+
' });',
|
|
2843
|
+
' }',
|
|
2844
|
+
' return out;',
|
|
2845
|
+
' }',
|
|
2846
|
+
'',
|
|
2847
|
+
' function activateModelPickerItem(item) {',
|
|
2848
|
+
' if (!item || !item.value) return;',
|
|
2849
|
+
' const v = item.value;',
|
|
2850
|
+
' if (v.isToggle && v.peerKey) {',
|
|
2851
|
+
' if (state.modelExpandedPeers.has(v.peerKey)) state.modelExpandedPeers.delete(v.peerKey);',
|
|
2852
|
+
' else state.modelExpandedPeers.add(v.peerKey);',
|
|
2853
|
+
' renderModelListOnly();',
|
|
2854
|
+
' return;',
|
|
2855
|
+
' }',
|
|
2856
|
+
' if (v.type === "action" && v.action === "disconnect" && v.providerId === "openrouter") {',
|
|
2857
|
+
' void disconnectOpenRouterAccount();',
|
|
2858
|
+
' return;',
|
|
2859
|
+
' }',
|
|
2860
|
+
' if (v.type === "acp" && !v.installed) {',
|
|
2861
|
+
' state.modelNotice = v.setupInstruction || (v.providerLabel + " is not installed on PATH yet.");',
|
|
2862
|
+
' renderModelListOnly();',
|
|
2863
|
+
' return;',
|
|
2864
|
+
' }',
|
|
2865
|
+
' if ((v.type === "byok" || v.type === "free") && !v.isConfigured && v.providerId !== "ollama") {',
|
|
2866
|
+
' closeAllPopovers();',
|
|
2867
|
+
' settingsModal.classList.add("open");',
|
|
2868
|
+
' if (vaultProviderSelect) {',
|
|
2869
|
+
' const opt = Array.from(vaultProviderSelect.options).find((o) => o.value === v.providerId);',
|
|
2870
|
+
' if (opt) vaultProviderSelect.value = v.providerId;',
|
|
2871
|
+
' }',
|
|
2872
|
+
' if (vaultStatusEl) vaultStatusEl.textContent = "Add your " + (v.envVar || (v.providerLabel + " API key")) + " to use " + v.modelId + ".";',
|
|
2873
|
+
' if (vaultKeyInput) vaultKeyInput.focus();',
|
|
2874
|
+
' return;',
|
|
2875
|
+
' }',
|
|
2876
|
+
' state.modelNotice = "";',
|
|
2877
|
+
' void selectModel(v.providerId, v.modelId || "");',
|
|
2878
|
+
' }',
|
|
2879
|
+
'',
|
|
2880
|
+
' function switchModelTab(nextTab) {',
|
|
2881
|
+
' if (state.modelTab === nextTab) return;',
|
|
2882
|
+
' state.modelTab = nextTab;',
|
|
2883
|
+
' state.modelSelectedIndex = 0;',
|
|
2884
|
+
' state.modelNotice = "";',
|
|
2885
|
+
' renderModelPopover();',
|
|
2886
|
+
' }',
|
|
2887
|
+
'',
|
|
2888
|
+
' function ensureModelPickerShell() {',
|
|
2889
|
+
' if (modelPopover.querySelector(".mp-head")) return;',
|
|
2890
|
+
' modelPopover.textContent = "";',
|
|
2891
|
+
' const head = document.createElement("div"); head.className = "mp-head";',
|
|
2892
|
+
' const topRow = document.createElement("div"); topRow.className = "mp-top-row";',
|
|
2893
|
+
' const tabsEl = document.createElement("div"); tabsEl.className = "mp-tabs"; tabsEl.setAttribute("role", "tablist");',
|
|
2894
|
+
' for (const def of [{ id: "acp", label: "ACP" }, { id: "byok", label: "BYOK" }, { id: "free", label: "FREE" }]) {',
|
|
2895
|
+
' const tb = document.createElement("button"); tb.type = "button"; tb.className = "mp-tab"; tb.setAttribute("role", "tab"); tb.dataset.mptab = def.id;',
|
|
2896
|
+
' tb.textContent = def.label;',
|
|
2897
|
+
' tb.addEventListener("click", () => switchModelTab(def.id));',
|
|
2898
|
+
' tabsEl.appendChild(tb);',
|
|
2899
|
+
' }',
|
|
2900
|
+
' const refreshBtn = document.createElement("button"); refreshBtn.type = "button"; refreshBtn.className = "mp-refresh-btn";',
|
|
2901
|
+
' refreshBtn.textContent = "Refresh";',
|
|
2902
|
+
' refreshBtn.addEventListener("click", () => { void loadModels("refresh"); });',
|
|
2903
|
+
' topRow.appendChild(tabsEl); topRow.appendChild(refreshBtn);',
|
|
2904
|
+
' const searchInput = document.createElement("input"); searchInput.type = "search"; searchInput.className = "mp-search";',
|
|
2905
|
+
' searchInput.placeholder = "Filter models (e.g. gemini, sonnet, deepseek)...";',
|
|
2906
|
+
' searchInput.setAttribute("aria-label", "Filter models");',
|
|
2907
|
+
' searchInput.addEventListener("input", () => {',
|
|
2908
|
+
' state.modelQuery = searchInput.value || "";',
|
|
2909
|
+
' state.modelSelectedIndex = 0;',
|
|
2910
|
+
' renderModelListOnly();',
|
|
2911
|
+
' });',
|
|
2912
|
+
' searchInput.addEventListener("keydown", (e) => {',
|
|
2913
|
+
' const items = getVisibleModelItems();',
|
|
2914
|
+
' const tabOrder = ["acp", "byok", "free"];',
|
|
2915
|
+
' const curTabIdx = Math.max(0, tabOrder.indexOf(state.modelTab || "acp"));',
|
|
2916
|
+
' if (e.key === "Tab") {',
|
|
2917
|
+
' e.preventDefault();',
|
|
2918
|
+
' const nextIdx = (curTabIdx + (e.shiftKey ? 2 : 1)) % 3;',
|
|
2919
|
+
' switchModelTab(tabOrder[nextIdx]);',
|
|
2920
|
+
' return;',
|
|
2921
|
+
' }',
|
|
2922
|
+
' if ((e.key === "ArrowLeft" || e.key === "ArrowRight") && !searchInput.value) {',
|
|
2923
|
+
' e.preventDefault();',
|
|
2924
|
+
' const nextIdx = e.key === "ArrowRight" ? Math.min(2, curTabIdx + 1) : Math.max(0, curTabIdx - 1);',
|
|
2925
|
+
' switchModelTab(tabOrder[nextIdx]);',
|
|
2926
|
+
' return;',
|
|
2927
|
+
' }',
|
|
2928
|
+
' if (e.key === "ArrowDown") {',
|
|
2929
|
+
' e.preventDefault();',
|
|
2930
|
+
' if (items.length > 0) {',
|
|
2931
|
+
' state.modelSelectedIndex = (state.modelSelectedIndex + 1) % items.length;',
|
|
2932
|
+
' renderModelListOnly(true);',
|
|
2933
|
+
' }',
|
|
2934
|
+
' return;',
|
|
2935
|
+
' }',
|
|
2936
|
+
' if (e.key === "ArrowUp") {',
|
|
2937
|
+
' e.preventDefault();',
|
|
2938
|
+
' if (items.length > 0) {',
|
|
2939
|
+
' state.modelSelectedIndex = (state.modelSelectedIndex - 1 + items.length) % items.length;',
|
|
2940
|
+
' renderModelListOnly(true);',
|
|
2941
|
+
' }',
|
|
2942
|
+
' return;',
|
|
2943
|
+
' }',
|
|
2944
|
+
' if (e.key === "Enter") {',
|
|
2945
|
+
' e.preventDefault();',
|
|
2946
|
+
' if (items.length > 0) {',
|
|
2947
|
+
' const chosen = items[Math.min(state.modelSelectedIndex, items.length - 1)];',
|
|
2948
|
+
' activateModelPickerItem(chosen);',
|
|
2949
|
+
' }',
|
|
2950
|
+
' return;',
|
|
2951
|
+
' }',
|
|
2952
|
+
' if (e.key === "Escape") {',
|
|
2953
|
+
' e.preventDefault();',
|
|
2954
|
+
' closeAllPopovers();',
|
|
2955
|
+
' }',
|
|
2956
|
+
' });',
|
|
2957
|
+
' head.appendChild(topRow); head.appendChild(searchInput);',
|
|
2958
|
+
' const noteEl = document.createElement("div"); noteEl.className = "mp-note"; noteEl.style.display = "none";',
|
|
2959
|
+
' const listEl = document.createElement("div"); listEl.className = "mp-list";',
|
|
2960
|
+
' const footEl = document.createElement("div"); footEl.className = "mp-foot";',
|
|
2961
|
+
' const footLeft = document.createElement("span"); footLeft.textContent = "Tab switch · ↑↓ navigate · Enter select";',
|
|
2962
|
+
' const footCount = document.createElement("span"); footCount.className = "mp-foot-count";',
|
|
2963
|
+
' footEl.appendChild(footLeft); footEl.appendChild(footCount);',
|
|
2964
|
+
' modelPopover.appendChild(head); modelPopover.appendChild(noteEl); modelPopover.appendChild(listEl); modelPopover.appendChild(footEl);',
|
|
2965
|
+
' }',
|
|
2966
|
+
'',
|
|
2967
|
+
' function renderModelListOnly(scrollFocused) {',
|
|
2968
|
+
' const listEl = modelPopover.querySelector(".mp-list");',
|
|
2969
|
+
' const noteEl = modelPopover.querySelector(".mp-note");',
|
|
2970
|
+
' const footCount = modelPopover.querySelector(".mp-foot-count");',
|
|
2971
|
+
' if (!listEl) return;',
|
|
2972
|
+
' if (noteEl) {',
|
|
2973
|
+
' if (state.modelNotice) { noteEl.textContent = state.modelNotice; noteEl.style.display = "block"; }',
|
|
2974
|
+
' else { noteEl.textContent = ""; noteEl.style.display = "none"; }',
|
|
2975
|
+
' }',
|
|
2976
|
+
' listEl.textContent = "";',
|
|
2977
|
+
' const items = getVisibleModelItems();',
|
|
2978
|
+
' if (state.modelSelectedIndex >= items.length) state.modelSelectedIndex = Math.max(0, items.length - 1);',
|
|
2979
|
+
' const selectableCount = items.filter((it) => !(it.value && (it.value.isToggle || it.value.type === "action"))).length;',
|
|
2980
|
+
' if (footCount) footCount.textContent = selectableCount + (selectableCount === 1 ? " model" : " models");',
|
|
2981
|
+
' if (items.length === 0) {',
|
|
2982
|
+
' const empty = document.createElement("div"); empty.className = "mp-empty";',
|
|
2983
|
+
' empty.textContent = state.modelQuery ? "No models matched your search in this tab." : "Loading models...";',
|
|
2984
|
+
' listEl.appendChild(empty);',
|
|
2985
|
+
' return;',
|
|
2986
|
+
' }',
|
|
2987
|
+
' let currentCategory = "";',
|
|
2988
|
+
' let focusedBtn = null;',
|
|
2989
|
+
' items.forEach((item, idx) => {',
|
|
2990
|
+
' if (item.category && item.category !== currentCategory) {',
|
|
2991
|
+
' currentCategory = item.category;',
|
|
2992
|
+
' const cat = document.createElement("div"); cat.className = "mp-cat";',
|
|
2993
|
+
' cat.textContent = currentCategory;',
|
|
2994
|
+
' listEl.appendChild(cat);',
|
|
2995
|
+
' }',
|
|
2996
|
+
' const v = item.value || {};',
|
|
2997
|
+
' const btn = document.createElement("button"); btn.type = "button";',
|
|
2998
|
+
' const isFocused = idx === state.modelSelectedIndex;',
|
|
2999
|
+
' const isCurrent = Boolean(v.isCurrent);',
|
|
3000
|
+
' const isMuted = (v.type === "acp" && !v.installed) || ((v.type === "byok" || v.type === "free") && !v.isConfigured && v.providerId !== "ollama");',
|
|
3001
|
+
' const isDanger = v.type === "action" && v.action === "disconnect";',
|
|
3002
|
+
' btn.className = "mp-row"',
|
|
3003
|
+
' + (isFocused ? " focused" : "")',
|
|
3004
|
+
' + (isCurrent ? " current" : "")',
|
|
3005
|
+
' + (v.isToggle ? " toggle" : "")',
|
|
3006
|
+
' + (isMuted ? " muted" : "")',
|
|
3007
|
+
' + (isDanger ? " danger" : "");',
|
|
3008
|
+
' btn.title = item.id || item.label || "";',
|
|
3009
|
+
' const lbl = document.createElement("span"); lbl.className = "mp-row-label";',
|
|
3010
|
+
' lbl.textContent = item.label || "";',
|
|
3011
|
+
' const st = document.createElement("span");',
|
|
3012
|
+
' st.className = "mp-row-status" + (isCurrent ? " is-active" : (v.installed && v.isConfigured ? " is-ready" : ""));',
|
|
3013
|
+
' st.textContent = item.description || "";',
|
|
3014
|
+
' btn.appendChild(lbl); btn.appendChild(st);',
|
|
3015
|
+
' btn.addEventListener("mouseenter", () => { state.modelSelectedIndex = idx; });',
|
|
3016
|
+
' btn.addEventListener("click", () => activateModelPickerItem(item));',
|
|
3017
|
+
' listEl.appendChild(btn);',
|
|
3018
|
+
' if (isFocused) focusedBtn = btn;',
|
|
3019
|
+
' });',
|
|
3020
|
+
' if (scrollFocused && focusedBtn) focusedBtn.scrollIntoView({ block: "nearest" });',
|
|
3021
|
+
' }',
|
|
3022
|
+
'',
|
|
3023
|
+
' function renderModelPopover() {',
|
|
3024
|
+
' ensureModelPickerShell();',
|
|
3025
|
+
' const activeTab = state.modelTab || (state.models && state.models.initialTab) || "acp";',
|
|
3026
|
+
' state.modelTab = activeTab;',
|
|
3027
|
+
' const tabsData = (state.models && state.models.tabs) || {};',
|
|
3028
|
+
' modelPopover.querySelectorAll(".mp-tab").forEach((tb) => {',
|
|
3029
|
+
' const id = tb.dataset.mptab;',
|
|
3030
|
+
' const isSelected = id === activeTab;',
|
|
3031
|
+
' tb.classList.toggle("active", isSelected);',
|
|
3032
|
+
' tb.setAttribute("aria-selected", isSelected ? "true" : "false");',
|
|
3033
|
+
' const list = Array.isArray(tabsData[id]) ? tabsData[id] : [];',
|
|
3034
|
+
' const hasActive = list.some((it) => it && it.value && it.value.isCurrent);',
|
|
3035
|
+
' tb.textContent = "";',
|
|
3036
|
+
' if (hasActive) { const dot = document.createElement("span"); dot.className = "mp-tab-dot"; tb.appendChild(dot); }',
|
|
3037
|
+
' tb.appendChild(document.createTextNode(id === "acp" ? "ACP" : (id === "byok" ? "BYOK" : "FREE")));',
|
|
3038
|
+
' });',
|
|
3039
|
+
' const searchInput = modelPopover.querySelector(".mp-search");',
|
|
3040
|
+
' if (searchInput && searchInput.value !== state.modelQuery) searchInput.value = state.modelQuery;',
|
|
3041
|
+
' updateModelRefreshUi();',
|
|
3042
|
+
' renderModelListOnly(false);',
|
|
3043
|
+
' }',
|
|
3044
|
+
'',
|
|
3045
|
+
' /* Files, Canvas/idoc, Git Diff & Doctor */',
|
|
3046
|
+
' async function loadFiles(dir, query) {',
|
|
3047
|
+
' const params = new URLSearchParams();',
|
|
3048
|
+
' if (dir) params.set("dir", dir);',
|
|
3049
|
+
' if (query) params.set("q", query);',
|
|
3050
|
+
' const qs = params.toString() ? ("?" + params.toString()) : "";',
|
|
3051
|
+
' const res = await fetch(apiUrl("/api/files" + qs), { headers: authHeaders() });',
|
|
3052
|
+
' if (!res.ok) return;',
|
|
3053
|
+
' const data = await res.json();',
|
|
3054
|
+
' state.currentDir = data.dir || ""; state.parentDir = data.parentDir || "";',
|
|
3055
|
+
' fileUpBtn.disabled = !state.currentDir;',
|
|
3056
|
+
' fileListEl.textContent = "";',
|
|
3057
|
+
' const entries = data.entries || [];',
|
|
3058
|
+
' if (entries.length === 0) {',
|
|
3059
|
+
' const empty = document.createElement("div"); empty.className = "session-empty"; empty.textContent = "No files in this directory.";',
|
|
3060
|
+
' fileListEl.appendChild(empty); return;',
|
|
3061
|
+
' }',
|
|
3062
|
+
' for (const item of entries) {',
|
|
3063
|
+
' const row = document.createElement("div"); row.className = "file-row";',
|
|
3064
|
+
' const openBtn = document.createElement("button"); openBtn.type = "button"; openBtn.className = "file-open-btn";',
|
|
3065
|
+
' openBtn.textContent = (item.type === "dir" ? "[dir] " : "") + item.path;',
|
|
3066
|
+
' openBtn.addEventListener("click", () => {',
|
|
3067
|
+
' if (item.type === "dir") { void loadFiles(item.path, ""); }',
|
|
3068
|
+
' else { void openFile(item.path); }',
|
|
3069
|
+
' });',
|
|
3070
|
+
' row.appendChild(openBtn);',
|
|
3071
|
+
' if (item.type === "file") {',
|
|
3072
|
+
' const atBtn = document.createElement("button"); atBtn.type = "button"; atBtn.className = "file-attach-btn";',
|
|
3073
|
+
' atBtn.textContent = "+ @"; atBtn.title = "Attach to prompt";',
|
|
3074
|
+
' atBtn.addEventListener("click", () => attachWorkspaceFile(item.path));',
|
|
3075
|
+
' row.appendChild(atBtn);',
|
|
3076
|
+
' }',
|
|
3077
|
+
' fileListEl.appendChild(row);',
|
|
3078
|
+
' }',
|
|
3079
|
+
' }',
|
|
3080
|
+
'',
|
|
3081
|
+
' async function openFile(relPath) {',
|
|
3082
|
+
' const seq = state.sessionSwitchSeq;',
|
|
3083
|
+
' const res = await fetch(apiUrl("/api/file?path=" + encodeURIComponent(relPath)), { headers: authHeaders() });',
|
|
3084
|
+
' if (seq !== state.sessionSwitchSeq) return;',
|
|
3085
|
+
' const data = await res.json();',
|
|
3086
|
+
' if (!res.ok) { fileStatusEl.textContent = data.error || "Read failed"; return; }',
|
|
3087
|
+
' state.canvasDirty = false;',
|
|
3088
|
+
' openInCanvas(data.path || relPath, data.content || "", isHtmlOrSvgPath(data.path || relPath));',
|
|
3089
|
+
' fileStatusEl.textContent = "Loaded " + (data.path || relPath) + " (" + (data.size || 0) + " B)";',
|
|
3090
|
+
' saveCurrentSessionWorkspace();',
|
|
3091
|
+
' }',
|
|
3092
|
+
'',
|
|
3093
|
+
' async function saveFile() {',
|
|
3094
|
+
' const relPath = (filePathInput.value || "").trim();',
|
|
3095
|
+
' if (!relPath) { fileStatusEl.textContent = "Enter a workspace relative path first."; return; }',
|
|
3096
|
+
' const content = fileContentInput.value || "";',
|
|
3097
|
+
' const res = await fetch(apiUrl("/api/file"), {',
|
|
3098
|
+
' method: "POST", headers: authHeaders({ "Content-Type": "application/json" }),',
|
|
3099
|
+
' body: JSON.stringify({ path: relPath, content, sessionId: state.sessionId || undefined })',
|
|
3100
|
+
' });',
|
|
3101
|
+
' const data = await res.json();',
|
|
3102
|
+
' if (!res.ok) { fileStatusEl.textContent = data.error || "Write failed"; return; }',
|
|
3103
|
+
' state.canvasDirty = false;',
|
|
3104
|
+
' const ver = recordArtifactVersion(data.path, content);',
|
|
3105
|
+
' fileStatusEl.textContent = "Saved " + data.path + " v" + ver + " (" + data.bytes + " B)";',
|
|
3106
|
+
' saveCurrentSessionWorkspace();',
|
|
3107
|
+
' void loadFiles(state.currentDir, fileFilterEl.value || "");',
|
|
3108
|
+
' if (state.studioTab === "diff") void loadDiff();',
|
|
3109
|
+
' }',
|
|
3110
|
+
'',
|
|
3111
|
+
' async function loadDiff() {',
|
|
3112
|
+
' const seq = state.sessionSwitchSeq;',
|
|
3113
|
+
' const scope = state.diffScope === "session" && state.sessionId ? "session" : "workspace";',
|
|
3114
|
+
' syncDiffControlsUi();',
|
|
3115
|
+
' const params = new URLSearchParams();',
|
|
3116
|
+
' params.set("scope", scope);',
|
|
3117
|
+
' if (state.sessionId) params.set("sessionId", state.sessionId);',
|
|
3118
|
+
' if (scope === "workspace" && state.diffStaged) params.set("staged", "1");',
|
|
3119
|
+
' const res = await fetch(apiUrl("/api/diff?" + params.toString()), { headers: authHeaders() }).catch(() => null);',
|
|
3120
|
+
' if (!res || !res.ok || seq !== state.sessionSwitchSeq) return;',
|
|
3121
|
+
' const data = await res.json().catch(() => null);',
|
|
3122
|
+
' if (!data || seq !== state.sessionSwitchSeq) return;',
|
|
3123
|
+
' diffListEl.textContent = "";',
|
|
3124
|
+
' const wsCount = Number(data.workspaceFileCount || 0);',
|
|
3125
|
+
' const sessCount = Number(data.sessionFileCount || 0);',
|
|
3126
|
+
' if (diffScopeSessionBtn) diffScopeSessionBtn.textContent = state.sessionId ? ("This chat (" + sessCount + ")") : "This chat";',
|
|
3127
|
+
' if (diffScopeWorkspaceBtn) diffScopeWorkspaceBtn.textContent = "Workspace (" + wsCount + ")";',
|
|
3128
|
+
' if (!data.isGitRepo && scope === "workspace") { diffSummaryEl.textContent = "Not a Git repository."; return; }',
|
|
3129
|
+
' const files = data.files || [];',
|
|
3130
|
+
' const addTot = Number(data.totalAdditions || 0);',
|
|
3131
|
+
' const delTot = Number(data.totalDeletions || 0);',
|
|
3132
|
+
' diffSummaryEl.textContent = (addTot || delTot)',
|
|
3133
|
+
' ? ("+" + addTot + " / -" + delTot)',
|
|
3134
|
+
' : (files.length > 0 ? (files.length + (files.length === 1 ? " file" : " files")) : "");',
|
|
3135
|
+
' if (files.length === 0) {',
|
|
3136
|
+
' const empty = document.createElement("div"); empty.className = "diff-empty-box";',
|
|
3137
|
+
' const activeSessObj = state.sessions.find((x) => x.id === state.sessionId);',
|
|
3138
|
+
' const activeTitle = activeSessObj && activeSessObj.title ? ("\\"" + activeSessObj.title.slice(0, 48) + "\\"") : "this conversation";',
|
|
3139
|
+
' const msg = document.createElement("div");',
|
|
3140
|
+
' msg.textContent = scope === "session"',
|
|
3141
|
+
' ? ("No file changes in " + activeTitle + ".")',
|
|
3142
|
+
' : (state.diffStaged ? "No staged changes." : "Working tree clean.");',
|
|
3143
|
+
' empty.appendChild(msg);',
|
|
3144
|
+
' if (scope === "session" && wsCount > 0) {',
|
|
3145
|
+
' const switchBtn = document.createElement("button");',
|
|
3146
|
+
' switchBtn.type = "button"; switchBtn.className = "btn-ghost";',
|
|
3147
|
+
' switchBtn.textContent = "View workspace changes (" + wsCount + ")";',
|
|
3148
|
+
' switchBtn.addEventListener("click", () => { state.diffScope = "workspace"; saveCurrentSessionWorkspace(); syncDiffControlsUi(); void loadDiff(); });',
|
|
3149
|
+
' empty.appendChild(switchBtn);',
|
|
3150
|
+
' }',
|
|
3151
|
+
' diffListEl.appendChild(empty); return;',
|
|
3152
|
+
' }',
|
|
3153
|
+
' for (const f of files) {',
|
|
3154
|
+
' const card = document.createElement("details"); card.className = "diff-file"; card.open = files.length <= 6;',
|
|
3155
|
+
' const head = document.createElement("summary"); head.className = "diff-file-head";',
|
|
3156
|
+
' const p = document.createElement("span"); p.className = "diff-file-path";',
|
|
3157
|
+
' p.title = f.path;',
|
|
3158
|
+
' const badgeChar = f.status && f.status[0] ? f.status[0].toUpperCase() : "M";',
|
|
3159
|
+
' p.textContent = "[" + badgeChar + "] " + f.path;',
|
|
3160
|
+
' const right = document.createElement("span"); right.className = "diff-file-right";',
|
|
3161
|
+
' if (f.additions || f.deletions) {',
|
|
3162
|
+
' const add = document.createElement("span"); add.className = "diff-add"; add.textContent = "+" + f.additions;',
|
|
3163
|
+
' const del = document.createElement("span"); del.className = "diff-del"; del.textContent = "-" + f.deletions;',
|
|
3164
|
+
' right.appendChild(add); right.appendChild(del);',
|
|
3165
|
+
' }',
|
|
3166
|
+
' if (f.existsOnDisk !== false) {',
|
|
3167
|
+
' const openBtn = document.createElement("button"); openBtn.type = "button"; openBtn.className = "diff-open-btn";',
|
|
3168
|
+
' openBtn.textContent = "Open";',
|
|
3169
|
+
' openBtn.addEventListener("click", (e) => { e.preventDefault(); e.stopPropagation(); void openFile(f.path); });',
|
|
3170
|
+
' right.appendChild(openBtn);',
|
|
3171
|
+
' }',
|
|
3172
|
+
' head.appendChild(p); head.appendChild(right);',
|
|
3173
|
+
' card.appendChild(head);',
|
|
3174
|
+
' if (Array.isArray(f.hunks) && f.hunks.length > 0) {',
|
|
3175
|
+
' const pre = document.createElement("div"); pre.className = "diff-lines";',
|
|
3176
|
+
' for (const h of f.hunks) {',
|
|
3177
|
+
' const hh = document.createElement("div"); hh.className = "diff-line hunk"; hh.textContent = h.header;',
|
|
3178
|
+
' pre.appendChild(hh);',
|
|
3179
|
+
' for (const ln of h.lines || []) {',
|
|
3180
|
+
' const row = document.createElement("div");',
|
|
3181
|
+
' row.className = "diff-line" + (ln.startsWith("+") ? " plus" : ln.startsWith("-") ? " minus" : "");',
|
|
3182
|
+
' row.textContent = ln;',
|
|
3183
|
+
' pre.appendChild(row);',
|
|
3184
|
+
' }',
|
|
3185
|
+
' }',
|
|
3186
|
+
' card.appendChild(pre);',
|
|
3187
|
+
' } else if (f.note) {',
|
|
3188
|
+
' const note = document.createElement("div"); note.className = "diff-note"; note.textContent = f.note;',
|
|
3189
|
+
' card.appendChild(note);',
|
|
3190
|
+
' }',
|
|
3191
|
+
' diffListEl.appendChild(card);',
|
|
3192
|
+
' }',
|
|
3193
|
+
' }',
|
|
3194
|
+
'',
|
|
3195
|
+
' async function loadDoctorReport() {',
|
|
3196
|
+
' doctorPre.textContent = "Loading redacted diagnostics...";',
|
|
3197
|
+
' const res = await fetch(apiUrl("/api/doctor/report"), { headers: authHeaders() });',
|
|
3198
|
+
' if (!res.ok) { doctorPre.textContent = "Unable to load diagnostics."; return; }',
|
|
3199
|
+
' const data = await res.json();',
|
|
3200
|
+
' doctorPre.textContent = data.report || "No diagnostics available.";',
|
|
3201
|
+
' }',
|
|
3202
|
+
'',
|
|
3203
|
+
' function isSafeBillingUrl(raw) {',
|
|
3204
|
+
' try {',
|
|
3205
|
+
' const u = new URL(String(raw || ""));',
|
|
3206
|
+
' if (u.protocol !== "https:" || u.username || u.password || u.port) return false;',
|
|
3207
|
+
' const h = u.hostname.toLowerCase();',
|
|
3208
|
+
' return h === "paddle.com" || h.endsWith(".paddle.com") || h === "dodopayments.com" || h.endsWith(".dodopayments.com") || h === "causyne.com" || h.endsWith(".causyne.com");',
|
|
3209
|
+
' } catch {',
|
|
3210
|
+
' return false;',
|
|
3211
|
+
' }',
|
|
3212
|
+
' }',
|
|
3213
|
+
'',
|
|
3214
|
+
' async function loadLicenseStatus(forceLive) {',
|
|
3215
|
+
' if (!licenseSummaryEl) return;',
|
|
3216
|
+
' licenseSummaryEl.textContent = "Checking plan status...";',
|
|
3217
|
+
' const qs = forceLive ? "?live=1" : "";',
|
|
3218
|
+
' const res = await fetch(apiUrl("/api/license/status" + qs), { headers: authHeaders() }).catch(() => null);',
|
|
3219
|
+
' if (!res) { licenseSummaryEl.textContent = "Could not load plan status."; return; }',
|
|
3220
|
+
' const data = await res.json().catch(() => null);',
|
|
3221
|
+
' if (!res.ok || !data) {',
|
|
3222
|
+
' licenseSummaryEl.textContent = (data && data.error) || "Licensing service offline.";',
|
|
3223
|
+
' return;',
|
|
3224
|
+
' }',
|
|
3225
|
+
' const isPro = data.entitlement === "pro" && Boolean(data.paidUntil);',
|
|
3226
|
+
' if (licenseBadgeEl) {',
|
|
3227
|
+
' licenseBadgeEl.textContent = isPro ? ("Pro · " + (data.plan || "active")) : "Free · 6h/day";',
|
|
3228
|
+
' licenseBadgeEl.classList.toggle("is-pro", isPro);',
|
|
3229
|
+
' }',
|
|
3230
|
+
' if (licensePortalBtn) licensePortalBtn.style.display = isPro ? "inline-flex" : "none";',
|
|
3231
|
+
' if (isPro) {',
|
|
3232
|
+
' const untilStr = String(data.paidUntil).slice(0, 10);',
|
|
3233
|
+
' licenseSummaryEl.textContent = "Unlimited daily execution · Paid through " + untilStr;',
|
|
3234
|
+
' if (licenseMeterWrap) licenseMeterWrap.style.display = "none";',
|
|
3235
|
+
' if (licenseSupportNote) {',
|
|
3236
|
+
' licenseSupportNote.textContent = data.recoveryCode',
|
|
3237
|
+
' ? ("Thank you for supporting Causyne! Save your multi-device recovery code: " + data.recoveryCode)',
|
|
3238
|
+
' : "Thank you for supporting independent Causyne development and community maintenance.";',
|
|
3239
|
+
' }',
|
|
3240
|
+
' } else {',
|
|
3241
|
+
' const daySec = Number(data.dailySeconds || 21600);',
|
|
3242
|
+
' const remSec = typeof data.remainingSeconds === "number" ? Math.max(0, data.remainingSeconds) : daySec;',
|
|
3243
|
+
' const remMin = Math.floor(remSec / 60);',
|
|
3244
|
+
' const dayMin = Math.floor(daySec / 60);',
|
|
3245
|
+
' const pct = daySec > 0 ? Math.max(0, Math.min(100, Math.round((remSec / daySec) * 100))) : 100;',
|
|
3246
|
+
' licenseSummaryEl.textContent = remMin + " of " + dayMin + " free active minutes remaining today (resets 00:00 UTC)";',
|
|
3247
|
+
' if (licenseMeterWrap) licenseMeterWrap.style.display = "block";',
|
|
3248
|
+
' if (licenseMeterFill) licenseMeterFill.style.width = pct + "%";',
|
|
3249
|
+
' if (licenseSupportNote) {',
|
|
3250
|
+
' licenseSupportNote.textContent = remSec <= 0 && data.supportMessage',
|
|
3251
|
+
' ? data.supportMessage',
|
|
3252
|
+
' : "Free includes 6 hours/day of active execution. Upgrade to Causyne Pro for unlimited daily usage and to support independent development, ongoing maintenance, and making Causyne Agent better for the entire community. Thank you for your trust and support.";',
|
|
3253
|
+
' }',
|
|
3254
|
+
' }',
|
|
3255
|
+
' }',
|
|
3256
|
+
'',
|
|
3257
|
+
' async function startLicenseCheckout() {',
|
|
3258
|
+
' if (!licensePlanSelect || !licenseStatusMsg) return;',
|
|
3259
|
+
' const plan = licensePlanSelect.value || "monthly";',
|
|
3260
|
+
' licenseStatusMsg.textContent = "Opening secure Paddle checkout...";',
|
|
3261
|
+
' const res = await fetch(apiUrl("/api/license/checkout"), {',
|
|
3262
|
+
' method: "POST", headers: authHeaders({ "Content-Type": "application/json" }),',
|
|
3263
|
+
' body: JSON.stringify({ plan })',
|
|
3264
|
+
' }).catch(() => null);',
|
|
3265
|
+
' if (!res) { licenseStatusMsg.textContent = "Could not reach checkout service."; return; }',
|
|
3266
|
+
' const data = await res.json().catch(() => ({ error: "Checkout error" }));',
|
|
3267
|
+
' if (!res.ok || !data.url || !isSafeBillingUrl(data.url)) {',
|
|
3268
|
+
' licenseStatusMsg.textContent = data.error || "Checkout unavailable right now. Visit causyne.com/pricing.html.";',
|
|
3269
|
+
' return;',
|
|
3270
|
+
' }',
|
|
3271
|
+
' window.open(data.url, "_blank", "noopener,noreferrer");',
|
|
3272
|
+
' licenseStatusMsg.textContent = "Paddle checkout opened in a new tab. Click Refresh after payment completes.";',
|
|
3273
|
+
' }',
|
|
3274
|
+
'',
|
|
3275
|
+
' async function claimLicenseRecovery() {',
|
|
3276
|
+
' if (!licenseRecoveryInput || !licenseStatusMsg) return;',
|
|
3277
|
+
' const code = (licenseRecoveryInput.value || "").trim();',
|
|
3278
|
+
' if (!code) { licenseStatusMsg.textContent = "Enter your CSYN-XXXX-XXXX-XXXX-XXXX recovery code first."; return; }',
|
|
3279
|
+
' licenseStatusMsg.textContent = "Linking license...";',
|
|
3280
|
+
' const res = await fetch(apiUrl("/api/license/recover"), {',
|
|
3281
|
+
' method: "POST", headers: authHeaders({ "Content-Type": "application/json" }),',
|
|
3282
|
+
' body: JSON.stringify({ recoveryCode: code })',
|
|
3283
|
+
' }).catch(() => null);',
|
|
3284
|
+
' if (!res) { licenseStatusMsg.textContent = "Could not reach licensing service."; return; }',
|
|
3285
|
+
' const data = await res.json().catch(() => ({ error: "Recovery failed" }));',
|
|
3286
|
+
' if (!res.ok) { licenseStatusMsg.textContent = data.error || "Could not link recovery code."; return; }',
|
|
3287
|
+
' licenseRecoveryInput.value = "";',
|
|
3288
|
+
' licenseStatusMsg.textContent = "Causyne Pro linked to this device!";',
|
|
3289
|
+
' void loadLicenseStatus(true);',
|
|
3290
|
+
' }',
|
|
3291
|
+
'',
|
|
3292
|
+
' async function openBillingPortal() {',
|
|
3293
|
+
' if (!licenseStatusMsg) return;',
|
|
3294
|
+
' licenseStatusMsg.textContent = "Opening Paddle billing portal...";',
|
|
3295
|
+
' const res = await fetch(apiUrl("/api/license/portal"), {',
|
|
3296
|
+
' method: "POST", headers: authHeaders({ "Content-Type": "application/json" }),',
|
|
3297
|
+
' body: "{}"',
|
|
3298
|
+
' }).catch(() => null);',
|
|
3299
|
+
' if (!res) { licenseStatusMsg.textContent = "Could not open billing portal."; return; }',
|
|
3300
|
+
' const data = await res.json().catch(() => ({ error: "Portal unavailable" }));',
|
|
3301
|
+
' if (!res.ok || !data.url || !isSafeBillingUrl(data.url)) {',
|
|
3302
|
+
' licenseStatusMsg.textContent = data.error || "Billing portal unavailable.";',
|
|
3303
|
+
' return;',
|
|
3304
|
+
' }',
|
|
3305
|
+
' window.open(data.url, "_blank", "noopener,noreferrer");',
|
|
3306
|
+
' licenseStatusMsg.textContent = "Paddle billing portal opened in a new tab.";',
|
|
3307
|
+
' }',
|
|
3308
|
+
'',
|
|
3309
|
+
' /* Streaming Chat Submission & Detached Re-Attachment (100% Real AgentLoop Event Fidelity) */',
|
|
3310
|
+
' async function stopActiveRun() {',
|
|
3311
|
+
' const sid = state.sessionId || undefined;',
|
|
3312
|
+
' const ctrl = state.activeController;',
|
|
3313
|
+
' const turn = state.activeTurn;',
|
|
3314
|
+
' const promptCopy = state.activePrompt;',
|
|
3315
|
+
' await fetch(apiUrl("/api/stop"), {',
|
|
3316
|
+
' method: "POST",',
|
|
3317
|
+
' headers: authHeaders({ "Content-Type": "application/json" }),',
|
|
3318
|
+
' body: JSON.stringify({ sessionId: sid })',
|
|
3319
|
+
' }).catch(() => {});',
|
|
3320
|
+
' // Give the NDJSON stream a brief window to deliver the server stopped frame cleanly.',
|
|
3321
|
+
' const waitStart = Date.now();',
|
|
3322
|
+
' while (ctrl && state.activeController === ctrl && (Date.now() - waitStart) < 400) {',
|
|
3323
|
+
' await new Promise((r) => setTimeout(r, 40));',
|
|
3324
|
+
' }',
|
|
3325
|
+
' if (ctrl && state.activeController === ctrl) {',
|
|
3326
|
+
' try { ctrl.abort(); } catch {}',
|
|
3327
|
+
' state.activeController = null;',
|
|
3328
|
+
' state.activeTurn = null;',
|
|
3329
|
+
' state.activePrompt = "";',
|
|
3330
|
+
' if (turn) {',
|
|
3331
|
+
' turn.addInterrupted("You stopped Causyne\\u2019s response.", promptCopy);',
|
|
3332
|
+
' turn.finish();',
|
|
3333
|
+
' }',
|
|
3334
|
+
' }',
|
|
3335
|
+
' setLiveness(false, "");',
|
|
3336
|
+
' updateComposerMetrics();',
|
|
3337
|
+
' announceStatus("Response stopped.");',
|
|
3338
|
+
' void loadSessions();',
|
|
3339
|
+
' }',
|
|
3340
|
+
'',
|
|
3341
|
+
' async function consumeNdjsonStream(res, assistant, runSeq, promptForRetry) {',
|
|
3342
|
+
' const reader = res.body.getReader();',
|
|
3343
|
+
' const decoder = new TextDecoder();',
|
|
3344
|
+
' let buf = "";',
|
|
3345
|
+
' let receivedTerminal = false;',
|
|
3346
|
+
' let receivedIdle = false;',
|
|
3347
|
+
' while (true) {',
|
|
3348
|
+
' const step = await reader.read();',
|
|
3349
|
+
' if (step.done) break;',
|
|
3350
|
+
' if (runSeq !== state.sessionSwitchSeq) break;',
|
|
3351
|
+
' buf += decoder.decode(step.value, { stream: true });',
|
|
3352
|
+
' const lines = buf.split("\\n");',
|
|
3353
|
+
' buf = lines.pop() || "";',
|
|
3354
|
+
' for (const line of lines) {',
|
|
3355
|
+
' if (!line.trim()) continue;',
|
|
3356
|
+
' let ev = null; try { ev = JSON.parse(line); } catch { continue; }',
|
|
3357
|
+
' if (ev.type === "heartbeat") {',
|
|
3358
|
+
' continue;',
|
|
3359
|
+
' } else if (ev.type === "idle") {',
|
|
3360
|
+
' receivedIdle = true;',
|
|
3361
|
+
' receivedTerminal = true;',
|
|
3362
|
+
' continue;',
|
|
3363
|
+
' } else if (ev.type === "session_bound" && ev.sessionId) {',
|
|
3364
|
+
' const prevDraft = state.sessionWorkspaces.get("__draft__");',
|
|
3365
|
+
' if (prevDraft && !state.sessionId) {',
|
|
3366
|
+
' state.sessionWorkspaces.set(ev.sessionId, prevDraft);',
|
|
3367
|
+
' state.sessionWorkspaces.delete("__draft__");',
|
|
3368
|
+
' }',
|
|
3369
|
+
' state.sessionId = ev.sessionId;',
|
|
3370
|
+
' syncDiffControlsUi();',
|
|
3371
|
+
' void loadSessions();',
|
|
3372
|
+
' } else if (ev.type === "agent_reasoning" || ev.type === "reasoning_chunk") {',
|
|
3373
|
+
' assistant.updateReasoning(ev);',
|
|
3374
|
+
' setLiveness(true, "Reasoning...");',
|
|
3375
|
+
' } else if (ev.type === "agent_plan") {',
|
|
3376
|
+
' assistant.updatePlan(ev);',
|
|
3377
|
+
' } else if (ev.type === "status" && ev.message) {',
|
|
3378
|
+
' setLiveness(true, ev.message);',
|
|
3379
|
+
' } else if (ev.type === "agent_activity" && ev.activity) {',
|
|
3380
|
+
' setLiveness(true, ev.activity);',
|
|
3381
|
+
' } else if (ev.type === "step_start" || ev.type === "tool_start") {',
|
|
3382
|
+
' assistant.addStepStart(ev);',
|
|
3383
|
+
' if (String(ev.tool || "").toLowerCase().includes("browser")) {',
|
|
3384
|
+
' openStudio("browser");',
|
|
3385
|
+
' setBrowserEngine("agent");',
|
|
3386
|
+
' }',
|
|
3387
|
+
' } else if (ev.type === "step_complete" || ev.type === "tool_result") {',
|
|
3388
|
+
' assistant.addStepEnd(ev, ev.success === false);',
|
|
3389
|
+
' const tLow = String(ev.tool || "").toLowerCase();',
|
|
3390
|
+
' if (tLow.includes("browser")) {',
|
|
3391
|
+
' void refreshLiveBrowserState(false);',
|
|
3392
|
+
' } else if (appEl.classList.contains("studio-open") && state.studioTab === "diff" && /(write|edit|patch|delete|move|forge)/.test(tLow)) {',
|
|
3393
|
+
' void loadDiff();',
|
|
3394
|
+
' }',
|
|
3395
|
+
' } else if (ev.type === "step_error") {',
|
|
3396
|
+
' assistant.addStepEnd(ev, true);',
|
|
3397
|
+
' } else if (ev.type === "code_progress") {',
|
|
3398
|
+
' assistant.upsertCodeProgress(ev);',
|
|
3399
|
+
' if (ev.phase === "done" && appEl.classList.contains("studio-open") && state.studioTab === "diff") {',
|
|
3400
|
+
' void loadDiff();',
|
|
3401
|
+
' }',
|
|
3402
|
+
' } else if (ev.type === "approval_request") {',
|
|
3403
|
+
' assistant.addApproval(ev);',
|
|
3404
|
+
' } else if (ev.type === "decision_request" && ev.request) {',
|
|
3405
|
+
' assistant.addDecision(ev.request);',
|
|
3406
|
+
' } else if (ev.type === "usage_update") {',
|
|
3407
|
+
' const total = Number(ev.totalTokens || ev.sessionTokens || ev.promptTokens || 0);',
|
|
3408
|
+
' if (total > 0) syncUsagePill(total);',
|
|
3409
|
+
' } else if (ev.type === "agent_chunk" && ev.delta) {',
|
|
3410
|
+
' assistant.appendText(ev.delta);',
|
|
3411
|
+
' setLiveness(true, "Responding...");',
|
|
3412
|
+
' } else if (ev.type === "agent_message" && typeof ev.content === "string") {',
|
|
3413
|
+
' assistant.setText(ev.content, Boolean(ev.streaming));',
|
|
3414
|
+
' setLiveness(Boolean(ev.streaming), ev.streaming ? "Responding..." : "");',
|
|
3415
|
+
' } else if ((ev.type === "notice" || ev.type === "budget_warning" || ev.type === "warning") && ev.message) {',
|
|
3416
|
+
' if (ev.nativeStep === true) {',
|
|
3417
|
+
' assistant.addNativeStep(ev, ev.type === "warning" || ev.nativeFailed === true);',
|
|
3418
|
+
' const actLower = String(ev.actionName || ev.message || "").toLowerCase();',
|
|
3419
|
+
' if (actLower.includes("browser")) {',
|
|
3420
|
+
' openStudio("browser");',
|
|
3421
|
+
' void refreshLiveBrowserState(false);',
|
|
3422
|
+
' } else if (appEl.classList.contains("studio-open") && state.studioTab === "diff" && /(write|edit|patch|delete|move)/.test(actLower)) {',
|
|
3423
|
+
' void loadDiff();',
|
|
3424
|
+
' }',
|
|
3425
|
+
' } else {',
|
|
3426
|
+
' assistant.addNotice(ev.message);',
|
|
3427
|
+
' }',
|
|
3428
|
+
' } else if (ev.type === "stopped") {',
|
|
3429
|
+
' receivedTerminal = true;',
|
|
3430
|
+
' assistant.addInterrupted("You stopped Causyne\\u2019s response.", promptForRetry);',
|
|
3431
|
+
' } else if (ev.type === "done") {',
|
|
3432
|
+
' receivedTerminal = true;',
|
|
3433
|
+
' } else if (ev.type === "error") {',
|
|
3434
|
+
' receivedTerminal = true;',
|
|
3435
|
+
' assistant.addError(ev.message || "Task error.", promptForRetry, ev.code || "");',
|
|
3436
|
+
' }',
|
|
3437
|
+
' }',
|
|
3438
|
+
' }',
|
|
3439
|
+
' return { receivedTerminal, receivedIdle };',
|
|
3440
|
+
' }',
|
|
3441
|
+
'',
|
|
3442
|
+
' async function attachToActiveSessionStream(sessionId, promptForRetry, runSeq) {',
|
|
3443
|
+
' const assistant = createAssistantTurn(promptForRetry);',
|
|
3444
|
+
' const controller = new AbortController();',
|
|
3445
|
+
' state.activeController = controller;',
|
|
3446
|
+
' state.activeTurn = assistant;',
|
|
3447
|
+
' state.activePrompt = promptForRetry || "";',
|
|
3448
|
+
' updateComposerMetrics();',
|
|
3449
|
+
' setLiveness(true, "Continuing in background...");',
|
|
3450
|
+
' let shouldReloadFinished = false;',
|
|
3451
|
+
' try {',
|
|
3452
|
+
' const res = await fetch(apiUrl("/api/sessions/" + encodeURIComponent(sessionId) + "/stream"), {',
|
|
3453
|
+
' headers: authHeaders(),',
|
|
3454
|
+
' signal: controller.signal',
|
|
3455
|
+
' });',
|
|
3456
|
+
' if (runSeq !== state.sessionSwitchSeq) return;',
|
|
3457
|
+
' if (!res.ok || !res.body) {',
|
|
3458
|
+
' assistant.finish();',
|
|
3459
|
+
' return;',
|
|
3460
|
+
' }',
|
|
3461
|
+
' const streamResult = await consumeNdjsonStream(res, assistant, runSeq, promptForRetry);',
|
|
3462
|
+
' if (runSeq === state.sessionSwitchSeq) {',
|
|
3463
|
+
' if (streamResult.receivedIdle) {',
|
|
3464
|
+
' shouldReloadFinished = true;',
|
|
3465
|
+
' } else if (!streamResult.receivedTerminal) {',
|
|
3466
|
+
' assistant.addInterrupted("Causyne\\u2019s response was interrupted.", promptForRetry);',
|
|
3467
|
+
' }',
|
|
3468
|
+
' assistant.finish();',
|
|
3469
|
+
' if (appEl.classList.contains("studio-open")) {',
|
|
3470
|
+
' if (state.studioTab === "files") void loadFiles(state.currentDir, fileFilterEl.value || "");',
|
|
3471
|
+
' if (state.studioTab === "diff") void loadDiff();',
|
|
3472
|
+
' }',
|
|
3473
|
+
' }',
|
|
3474
|
+
' } catch (err) {',
|
|
3475
|
+
' if (runSeq === state.sessionSwitchSeq && err && err.name !== "AbortError") {',
|
|
3476
|
+
' assistant.addInterrupted("Causyne\\u2019s response was interrupted.", promptForRetry);',
|
|
3477
|
+
' }',
|
|
3478
|
+
' assistant.finish();',
|
|
3479
|
+
' } finally {',
|
|
3480
|
+
' if (state.activeController === controller) {',
|
|
3481
|
+
' state.activeController = null;',
|
|
3482
|
+
' state.activeTurn = null;',
|
|
3483
|
+
' state.activePrompt = "";',
|
|
3484
|
+
' setLiveness(false, "");',
|
|
3485
|
+
' updateComposerMetrics();',
|
|
3486
|
+
' }',
|
|
3487
|
+
' void loadSessions();',
|
|
3488
|
+
' if (shouldReloadFinished && runSeq === state.sessionSwitchSeq) {',
|
|
3489
|
+
' void loadSessionTranscript(sessionId);',
|
|
3490
|
+
' }',
|
|
3491
|
+
' }',
|
|
3492
|
+
' }',
|
|
3493
|
+
'',
|
|
3494
|
+
' async function submitPrompt(promptText, attachList) {',
|
|
3495
|
+
' const prompt = (promptText || "").trim();',
|
|
3496
|
+
' if (!prompt || state.activeController) return;',
|
|
3497
|
+
' const runSeq = state.sessionSwitchSeq;',
|
|
3498
|
+
' appendUserTurn(prompt, attachList, true);',
|
|
3499
|
+
' const assistant = createAssistantTurn(prompt);',
|
|
3500
|
+
' const controller = new AbortController();',
|
|
3501
|
+
' state.activeController = controller;',
|
|
3502
|
+
' state.activeTurn = assistant;',
|
|
3503
|
+
' state.activePrompt = prompt;',
|
|
3504
|
+
' updateComposerMetrics();',
|
|
3505
|
+
' setLiveness(true, "Thinking...");',
|
|
3506
|
+
' announceStatus("Causyne is working...");',
|
|
3507
|
+
'',
|
|
3508
|
+
' try {',
|
|
3509
|
+
' const res = await fetch(apiUrl("/api/chat"), {',
|
|
3510
|
+
' method: "POST",',
|
|
3511
|
+
' headers: authHeaders({ "Content-Type": "application/json" }),',
|
|
3512
|
+
' body: JSON.stringify({',
|
|
3513
|
+
' prompt,',
|
|
3514
|
+
' mode: modeSelect.value,',
|
|
3515
|
+
' sessionId: state.sessionId || undefined,',
|
|
3516
|
+
' attachments: attachList',
|
|
3517
|
+
' }),',
|
|
3518
|
+
' signal: controller.signal',
|
|
3519
|
+
' });',
|
|
3520
|
+
' if (runSeq !== state.sessionSwitchSeq) return;',
|
|
3521
|
+
' if (!res.ok || !res.body) {',
|
|
3522
|
+
' const errData = await res.json().catch(() => ({ error: "HTTP " + res.status }));',
|
|
3523
|
+
' assistant.addError(errData.error || "Request failed.", prompt);',
|
|
3524
|
+
' return;',
|
|
3525
|
+
' }',
|
|
3526
|
+
' const streamResult = await consumeNdjsonStream(res, assistant, runSeq, prompt);',
|
|
3527
|
+
' if (runSeq === state.sessionSwitchSeq) {',
|
|
3528
|
+
' if (!streamResult.receivedTerminal) {',
|
|
3529
|
+
' assistant.addInterrupted("Causyne\\u2019s response was interrupted.", prompt);',
|
|
3530
|
+
' }',
|
|
3531
|
+
' assistant.finish();',
|
|
3532
|
+
' announceStatus("Response complete.");',
|
|
3533
|
+
' if (appEl.classList.contains("studio-open")) {',
|
|
3534
|
+
' if (state.studioTab === "files") void loadFiles(state.currentDir, fileFilterEl.value || "");',
|
|
3535
|
+
' if (state.studioTab === "diff") void loadDiff();',
|
|
3536
|
+
' }',
|
|
3537
|
+
' }',
|
|
3538
|
+
' } catch (err) {',
|
|
3539
|
+
' if (runSeq === state.sessionSwitchSeq && err && err.name !== "AbortError") {',
|
|
3540
|
+
' assistant.addInterrupted("Causyne\\u2019s response was interrupted.", prompt);',
|
|
3541
|
+
' }',
|
|
3542
|
+
' assistant.finish();',
|
|
3543
|
+
' } finally {',
|
|
3544
|
+
' if (state.activeController === controller) {',
|
|
3545
|
+
' state.activeController = null;',
|
|
3546
|
+
' state.activeTurn = null;',
|
|
3547
|
+
' state.activePrompt = "";',
|
|
3548
|
+
' setLiveness(false, "");',
|
|
3549
|
+
' updateComposerMetrics();',
|
|
3550
|
+
' }',
|
|
3551
|
+
' void loadSessions();',
|
|
3552
|
+
' }',
|
|
3553
|
+
' }',
|
|
3554
|
+
'',
|
|
3555
|
+
' /* Event Listeners */',
|
|
3556
|
+
' composerPill.addEventListener("click", (e) => { if (e.target === composerPill) promptInput.focus(); });',
|
|
3557
|
+
' promptInput.addEventListener("compositionstart", () => { state.isComposing = true; });',
|
|
3558
|
+
' promptInput.addEventListener("compositionend", () => { state.isComposing = false; });',
|
|
3559
|
+
' promptInput.addEventListener("input", () => { updateComposerMetrics(); void checkAtMention(); });',
|
|
3560
|
+
' promptInput.addEventListener("keydown", (e) => {',
|
|
3561
|
+
' if (mentionPopover.classList.contains("open") && state.mentionItems.length > 0) {',
|
|
3562
|
+
' if (e.key === "ArrowDown") { e.preventDefault(); state.mentionIndex = (state.mentionIndex + 1) % state.mentionItems.length; renderMentionList(); return; }',
|
|
3563
|
+
' if (e.key === "ArrowUp") { e.preventDefault(); state.mentionIndex = (state.mentionIndex - 1 + state.mentionItems.length) % state.mentionItems.length; renderMentionList(); return; }',
|
|
3564
|
+
' if (e.key === "Enter" || e.key === "Tab") {',
|
|
3565
|
+
' e.preventDefault();',
|
|
3566
|
+
' const chosen = state.mentionItems[state.mentionIndex];',
|
|
3567
|
+
' if (state.mentionMode === "command") applySlashChoice(chosen.name);',
|
|
3568
|
+
' else applyMentionChoice(chosen.path);',
|
|
3569
|
+
' return;',
|
|
3570
|
+
' }',
|
|
3571
|
+
' if (e.key === "Escape") { e.preventDefault(); mentionPopover.classList.remove("open"); return; }',
|
|
3572
|
+
' }',
|
|
3573
|
+
' if (e.key === "Enter" && !e.shiftKey && !e.isComposing && !state.isComposing) {',
|
|
3574
|
+
' e.preventDefault();',
|
|
3575
|
+
' chatForm.requestSubmit();',
|
|
3576
|
+
' }',
|
|
3577
|
+
' });',
|
|
3578
|
+
'',
|
|
3579
|
+
' chatForm.addEventListener("submit", (e) => {',
|
|
3580
|
+
' e.preventDefault();',
|
|
3581
|
+
' if (state.activeController) { void stopActiveRun(); return; }',
|
|
3582
|
+
' const text = (promptInput.value || "").trim();',
|
|
3583
|
+
' if (!text) return;',
|
|
3584
|
+
' const toAttach = state.attachments.slice();',
|
|
3585
|
+
' promptInput.value = "";',
|
|
3586
|
+
' state.attachments = [];',
|
|
3587
|
+
' renderAttachmentChips();',
|
|
3588
|
+
' updateComposerMetrics();',
|
|
3589
|
+
' if (text.startsWith("/") && /^\\/[a-z?][a-z0-9_-]*/i.test(text)) {',
|
|
3590
|
+
' void runCliCommand(text, "chat");',
|
|
3591
|
+
' return;',
|
|
3592
|
+
' }',
|
|
3593
|
+
' void submitPrompt(text, toAttach);',
|
|
3594
|
+
' });',
|
|
3595
|
+
'',
|
|
3596
|
+
' sendBtn.addEventListener("click", (e) => { if (state.activeController) { e.preventDefault(); void stopActiveRun(); } });',
|
|
3597
|
+
' heroHelpBtn.addEventListener("click", () => {',
|
|
3598
|
+
' promptInput.value = "Inspect this local workspace and summarize its architecture and next steps.";',
|
|
3599
|
+
' updateComposerMetrics(); promptInput.focus();',
|
|
3600
|
+
' });',
|
|
3601
|
+
'',
|
|
3602
|
+
' closeSidebarBtn.addEventListener("click", () => { appEl.classList.add("sidebar-collapsed"); if (appEl.classList.contains("studio-open")) applyStudioWidth(state.studioWidth, false); });',
|
|
3603
|
+
' openSidebarBtn.addEventListener("click", () => { if (window.innerWidth <= 960 && appEl.classList.contains("studio-open")) closeStudio(); appEl.classList.remove("sidebar-collapsed"); if (appEl.classList.contains("studio-open")) applyStudioWidth(state.studioWidth, false); });',
|
|
3604
|
+
' sidebarBackdrop.addEventListener("click", () => { appEl.classList.add("sidebar-collapsed"); if (window.innerWidth <= 960 && appEl.classList.contains("studio-open")) closeStudio(); });',
|
|
3605
|
+
' newChatBtn.addEventListener("click", () => { void startFreshChat(); });',
|
|
3606
|
+
' navFilesBtn.addEventListener("click", () => toggleStudioNav("files"));',
|
|
3607
|
+
' navCanvasBtn.addEventListener("click", () => toggleStudioNav("canvas"));',
|
|
3608
|
+
' navBrowserBtn.addEventListener("click", () => toggleStudioNav("browser"));',
|
|
3609
|
+
' navCliBtn.addEventListener("click", () => toggleStudioNav("cli"));',
|
|
3610
|
+
' navDiffBtn.addEventListener("click", () => toggleStudioNav("diff"));',
|
|
3611
|
+
' navSettingsBtn.addEventListener("click", () => { settingsModal.classList.add("open"); void loadLicenseStatus(false); void loadDoctorReport(); });',
|
|
3612
|
+
' studioToggleBtn.addEventListener("click", () => {',
|
|
3613
|
+
' if (appEl.classList.contains("studio-open")) closeStudio();',
|
|
3614
|
+
' else openStudio(state.studioTab || "files");',
|
|
3615
|
+
' });',
|
|
3616
|
+
' if (studioExpandBtn) studioExpandBtn.addEventListener("click", toggleStudioMaximize);',
|
|
3617
|
+
' studioCloseBtn.addEventListener("click", closeStudio);',
|
|
3618
|
+
' fileContentInput.addEventListener("input", () => {',
|
|
3619
|
+
' state.canvasDirty = true;',
|
|
3620
|
+
' const p = (filePathInput.value || "").trim();',
|
|
3621
|
+
' fileStatusEl.textContent = (p ? (p + " · ") : "") + "Unsaved";',
|
|
3622
|
+
' });',
|
|
3623
|
+
' document.querySelectorAll(".studio-tab").forEach((btn) => {',
|
|
3624
|
+
' btn.addEventListener("click", () => setStudioTab(btn.getAttribute("data-tab") || "files"));',
|
|
3625
|
+
' });',
|
|
3626
|
+
'',
|
|
3627
|
+
' modelTriggerBtn.addEventListener("click", (e) => {',
|
|
3628
|
+
' e.stopPropagation();',
|
|
3629
|
+
' const wasOpen = modelPopover.classList.contains("open");',
|
|
3630
|
+
' closeAllPopovers();',
|
|
3631
|
+
' if (!wasOpen) {',
|
|
3632
|
+
' state.modelQuery = "";',
|
|
3633
|
+
' state.modelNotice = "";',
|
|
3634
|
+
' state.modelSelectedIndex = 0;',
|
|
3635
|
+
' modelTriggerBtn.setAttribute("aria-expanded", "true");',
|
|
3636
|
+
' renderModelPopover();',
|
|
3637
|
+
' positionPopover(modelPopover, modelTriggerBtn, false);',
|
|
3638
|
+
' const searchInput = modelPopover.querySelector(".mp-search");',
|
|
3639
|
+
' if (searchInput) searchInput.focus();',
|
|
3640
|
+
' void loadModels();',
|
|
3641
|
+
' }',
|
|
3642
|
+
' });',
|
|
3643
|
+
'',
|
|
3644
|
+
' plusBtn.addEventListener("click", (e) => {',
|
|
3645
|
+
' e.stopPropagation();',
|
|
3646
|
+
' const wasOpen = plusPopover.classList.contains("open");',
|
|
3647
|
+
' closeAllPopovers();',
|
|
3648
|
+
' if (!wasOpen) { plusBtn.setAttribute("aria-expanded", "true"); positionPopover(plusPopover, plusBtn, true); }',
|
|
3649
|
+
' });',
|
|
3650
|
+
'',
|
|
3651
|
+
' el("plus-attach-file").addEventListener("click", () => { closeAllPopovers(); openStudio("files"); fileFilterEl.focus(); });',
|
|
3652
|
+
' el("plus-new-idoc").addEventListener("click", () => {',
|
|
3653
|
+
' closeAllPopovers(); openInCanvas("docs/plan.idoc.md", "# Causyne idoc\\n\\n## Goal\\n\\n- \\n", false);',
|
|
3654
|
+
' });',
|
|
3655
|
+
' el("plus-open-browser").addEventListener("click", () => { closeAllPopovers(); openStudio("browser"); browserUrlInput.focus(); });',
|
|
3656
|
+
' el("plus-open-diff").addEventListener("click", () => { closeAllPopovers(); openStudio("diff"); });',
|
|
3657
|
+
' el("plus-open-doctor").addEventListener("click", () => { closeAllPopovers(); settingsModal.classList.add("open"); void loadDoctorReport(); });',
|
|
3658
|
+
'',
|
|
3659
|
+
' browserMoreBtn.addEventListener("click", (e) => {',
|
|
3660
|
+
' e.stopPropagation();',
|
|
3661
|
+
' const wasOpen = browserMorePopover.classList.contains("open");',
|
|
3662
|
+
' closeAllPopovers();',
|
|
3663
|
+
' if (!wasOpen) { browserMoreBtn.setAttribute("aria-expanded", "true"); positionPopover(browserMorePopover, browserMoreBtn, false); }',
|
|
3664
|
+
' });',
|
|
3665
|
+
'',
|
|
3666
|
+
' document.addEventListener("click", (e) => {',
|
|
3667
|
+
' if (!modelPopover.contains(e.target) && !modelTriggerBtn.contains(e.target)',
|
|
3668
|
+
' && !plusPopover.contains(e.target) && !plusBtn.contains(e.target)',
|
|
3669
|
+
' && !browserMorePopover.contains(e.target) && !browserMoreBtn.contains(e.target)',
|
|
3670
|
+
' && !mentionPopover.contains(e.target)) { closeAllPopovers(); }',
|
|
3671
|
+
' });',
|
|
3672
|
+
'',
|
|
3673
|
+
' modeSelect.addEventListener("change", () => { try { window.localStorage.setItem(MODE_KEY, modeSelect.value); } catch {} });',
|
|
3674
|
+
' sessionSearchEl.addEventListener("input", renderSessionList);',
|
|
3675
|
+
' fileFilterEl.addEventListener("input", () => { void loadFiles(state.currentDir, fileFilterEl.value || ""); });',
|
|
3676
|
+
' fileUpBtn.addEventListener("click", () => { void loadFiles(state.parentDir, ""); });',
|
|
3677
|
+
' refreshFilesBtn.addEventListener("click", () => { void loadFiles(state.currentDir, fileFilterEl.value || ""); });',
|
|
3678
|
+
' saveFileBtn.addEventListener("click", () => { void saveFile(); });',
|
|
3679
|
+
' canvasCodeBtn.addEventListener("click", () => setCanvasPreviewMode(false));',
|
|
3680
|
+
' canvasModeBtn.addEventListener("click", () => setCanvasPreviewMode(true));',
|
|
3681
|
+
' artifactVersionSelect.addEventListener("change", () => {',
|
|
3682
|
+
' const list = state.artifactVersions.get((filePathInput.value || "").trim()) || [];',
|
|
3683
|
+
' const chosen = list.find((item) => String(item.version) === artifactVersionSelect.value);',
|
|
3684
|
+
' if (chosen) { fileContentInput.value = chosen.content; if (state.canvasPreviewMode) renderCanvasPreview(); }',
|
|
3685
|
+
' });',
|
|
3686
|
+
' canvasDownloadBtn.addEventListener("click", () => {',
|
|
3687
|
+
' const name = ((filePathInput.value || "causyne-artifact.md").split("/").pop()) || "artifact.md";',
|
|
3688
|
+
' const blob = new Blob([fileContentInput.value || ""], { type: "text/plain;charset=utf-8" });',
|
|
3689
|
+
' const url = URL.createObjectURL(blob);',
|
|
3690
|
+
' const a = document.createElement("a"); a.href = url; a.download = name; a.click();',
|
|
3691
|
+
' setTimeout(() => URL.revokeObjectURL(url), 1000);',
|
|
3692
|
+
' });',
|
|
3693
|
+
' canvasRefineBtn.addEventListener("click", () => {',
|
|
3694
|
+
' const p = (filePathInput.value || "").trim();',
|
|
3695
|
+
' if (p) attachWorkspaceFile(p);',
|
|
3696
|
+
' promptInput.value = p ? ("Review and improve " + p + " in this workspace.") : "Improve the open Canvas draft.";',
|
|
3697
|
+
' updateComposerMetrics(); promptInput.focus();',
|
|
3698
|
+
' });',
|
|
3699
|
+
'',
|
|
3700
|
+
' /* Browser Controls */',
|
|
3701
|
+
' bmodeAgentBtn.addEventListener("click", () => { closeAllPopovers(); setBrowserEngine("agent"); });',
|
|
3702
|
+
' bmodeFrameBtn.addEventListener("click", () => { closeAllPopovers(); setBrowserEngine("frame"); });',
|
|
3703
|
+
' browserStartBtn.addEventListener("click", () => {',
|
|
3704
|
+
' setBrowserEngine("agent");',
|
|
3705
|
+
' void runBrowserAction({ action: "start" }).then(() => { startLiveBrowserStream(); liveViewportSurface.focus(); });',
|
|
3706
|
+
' });',
|
|
3707
|
+
' browserStartNativeBtn.addEventListener("click", () => {',
|
|
3708
|
+
' setBrowserEngine("agent");',
|
|
3709
|
+
' void runBrowserAction({ action: "setMode", visible: true, ensureStarted: true }).then(() => startLiveBrowserStream());',
|
|
3710
|
+
' });',
|
|
3711
|
+
' browserNativeWinBtn.addEventListener("click", () => {',
|
|
3712
|
+
' setBrowserEngine("agent");',
|
|
3713
|
+
' const nextVisible = !state.liveBrowserVisible;',
|
|
3714
|
+
' void runBrowserAction({ action: "setMode", visible: nextVisible, ensureStarted: true }).then(() => startLiveBrowserStream());',
|
|
3715
|
+
' });',
|
|
3716
|
+
' browserEngineSelect.addEventListener("change", () => {',
|
|
3717
|
+
' const pref = browserEngineSelect.value || "auto";',
|
|
3718
|
+
' void runBrowserAction({ action: "setMode", enginePreference: pref, ensureStarted: state.liveBrowserActive });',
|
|
3719
|
+
' });',
|
|
3720
|
+
' browserCloseEngineBtn.addEventListener("click", () => { closeAllPopovers(); void runBrowserAction({ action: "close" }); });',
|
|
3721
|
+
' browserHandoffBtn.addEventListener("click", () => {',
|
|
3722
|
+
' closeAllPopovers();',
|
|
3723
|
+
' const nextAction = state.controlOwner === "agent" ? "takeControl" : "handToAgent";',
|
|
3724
|
+
' void runBrowserAction({ action: nextAction });',
|
|
3725
|
+
' });',
|
|
3726
|
+
' bannerTakeControlBtn.addEventListener("click", () => {',
|
|
3727
|
+
' void runBrowserAction({ action: "takeControl" }).then(() => liveViewportSurface.focus());',
|
|
3728
|
+
' });',
|
|
3729
|
+
' browserSyncToggleBtn.addEventListener("click", () => {',
|
|
3730
|
+
' const open = browserSyncDrawer.classList.toggle("open");',
|
|
3731
|
+
' browserSyncToggleBtn.classList.toggle("active", open);',
|
|
3732
|
+
' if (open) void scanLocalChromeTabs();',
|
|
3733
|
+
' });',
|
|
3734
|
+
' cdpScanBtn.addEventListener("click", () => { void scanLocalChromeTabs(); });',
|
|
3735
|
+
' browserImportBtn.addEventListener("click", () => { void importExplicitBrowserData(); });',
|
|
3736
|
+
' browserNewTabBtn.addEventListener("click", () => { void runBrowserAction({ action: "newTab" }); });',
|
|
3737
|
+
' browserBackBtn.addEventListener("click", () => { void runBrowserAction({ action: "back" }); });',
|
|
3738
|
+
' browserFwdBtn.addEventListener("click", () => { void runBrowserAction({ action: "forward" }); });',
|
|
3739
|
+
' function triggerBrowserNavigate() {',
|
|
3740
|
+
' const val = (browserUrlInput.value || "").trim();',
|
|
3741
|
+
' if (state.browserEngine === "agent") {',
|
|
3742
|
+
' void runBrowserAction({ action: "goto", url: val }).then(() => startLiveBrowserStream());',
|
|
3743
|
+
' } else { openBrowserUrl(val); }',
|
|
3744
|
+
' }',
|
|
3745
|
+
' browserUrlInput.addEventListener("keydown", (e) => { if (e.key === "Enter") { e.preventDefault(); triggerBrowserNavigate(); } });',
|
|
3746
|
+
' browserReloadBtn.addEventListener("click", () => {',
|
|
3747
|
+
' if (state.browserEngine === "agent") { void runBrowserAction({ action: "reload" }); return; }',
|
|
3748
|
+
' if (state.browserMode === "url" && state.browserUrl) browserFrame.src = state.browserUrl;',
|
|
3749
|
+
' else if (state.browserMode === "srcdoc" && state.browserSrcdoc) browserFrame.srcdoc = state.browserSrcdoc;',
|
|
3750
|
+
' });',
|
|
3751
|
+
' function mapViewportCoords(e) {',
|
|
3752
|
+
' const rect = liveBrowserImg.getBoundingClientRect();',
|
|
3753
|
+
' if (!rect.width || !rect.height) return null;',
|
|
3754
|
+
' return {',
|
|
3755
|
+
' x: Math.round(((e.clientX - rect.left) / rect.width) * state.liveBrowserWidth),',
|
|
3756
|
+
' y: Math.round(((e.clientY - rect.top) / rect.height) * state.liveBrowserHeight)',
|
|
3757
|
+
' };',
|
|
3758
|
+
' }',
|
|
3759
|
+
' function mapMouseButton(btn) { return btn === 2 ? "right" : btn === 1 ? "middle" : "left"; }',
|
|
3760
|
+
' let lastMoveSent = 0;',
|
|
3761
|
+
' liveBrowserImg.addEventListener("pointerdown", (e) => {',
|
|
3762
|
+
' e.preventDefault();',
|
|
3763
|
+
' liveViewportSurface.focus();',
|
|
3764
|
+
' const pt = mapViewportCoords(e);',
|
|
3765
|
+
' if (!pt) return;',
|
|
3766
|
+
' state.pointerDragging = true;',
|
|
3767
|
+
' void sendLiveInput({ kind: "mousedown", x: pt.x, y: pt.y, button: mapMouseButton(e.button) });',
|
|
3768
|
+
' });',
|
|
3769
|
+
' liveBrowserImg.addEventListener("pointermove", (e) => {',
|
|
3770
|
+
' const now = Date.now();',
|
|
3771
|
+
' if (!state.pointerDragging && document.activeElement !== liveViewportSurface) return;',
|
|
3772
|
+
' if (now - lastMoveSent < (state.pointerDragging ? 35 : 90)) return;',
|
|
3773
|
+
' lastMoveSent = now;',
|
|
3774
|
+
' const pt = mapViewportCoords(e);',
|
|
3775
|
+
' if (pt) void sendLiveInput({ kind: "mousemove", x: pt.x, y: pt.y });',
|
|
3776
|
+
' });',
|
|
3777
|
+
' liveBrowserImg.addEventListener("pointerup", (e) => {',
|
|
3778
|
+
' if (!state.pointerDragging) return;',
|
|
3779
|
+
' state.pointerDragging = false;',
|
|
3780
|
+
' const pt = mapViewportCoords(e);',
|
|
3781
|
+
' if (pt) void sendLiveInput({ kind: "mouseup", x: pt.x, y: pt.y, button: mapMouseButton(e.button) });',
|
|
3782
|
+
' });',
|
|
3783
|
+
' liveBrowserImg.addEventListener("dblclick", (e) => {',
|
|
3784
|
+
' e.preventDefault();',
|
|
3785
|
+
' const pt = mapViewportCoords(e);',
|
|
3786
|
+
' if (pt) void sendLiveInput({ kind: "dblclick", x: pt.x, y: pt.y });',
|
|
3787
|
+
' });',
|
|
3788
|
+
' liveBrowserImg.addEventListener("contextmenu", (e) => {',
|
|
3789
|
+
' e.preventDefault();',
|
|
3790
|
+
' const pt = mapViewportCoords(e);',
|
|
3791
|
+
' if (pt) void sendLiveInput({ kind: "contextmenu", x: pt.x, y: pt.y, button: "right" });',
|
|
3792
|
+
' });',
|
|
3793
|
+
' let wheelTimer = null;',
|
|
3794
|
+
' let wheelDx = 0; let wheelDy = 0;',
|
|
3795
|
+
' liveBrowserImg.addEventListener("wheel", (e) => {',
|
|
3796
|
+
' e.preventDefault();',
|
|
3797
|
+
' wheelDx += e.deltaX; wheelDy += e.deltaY;',
|
|
3798
|
+
' if (wheelTimer) return;',
|
|
3799
|
+
' wheelTimer = setTimeout(() => {',
|
|
3800
|
+
' const dx = Math.round(wheelDx); const dy = Math.round(wheelDy);',
|
|
3801
|
+
' wheelDx = 0; wheelDy = 0; wheelTimer = null;',
|
|
3802
|
+
' void sendLiveInput({ kind: "wheel", deltaX: dx, deltaY: dy });',
|
|
3803
|
+
' }, 60);',
|
|
3804
|
+
' }, { passive: false });',
|
|
3805
|
+
' liveViewportSurface.addEventListener("keydown", (e) => {',
|
|
3806
|
+
' if (!state.liveBrowserActive || state.browserEngine !== "agent") return;',
|
|
3807
|
+
' const mod = e.metaKey || e.ctrlKey;',
|
|
3808
|
+
' if (mod && e.key.toLowerCase() === "v") return;',
|
|
3809
|
+
' e.preventDefault();',
|
|
3810
|
+
' e.stopPropagation();',
|
|
3811
|
+
' if (mod && e.key.length === 1) {',
|
|
3812
|
+
' const prefix = e.metaKey ? "Meta+" : "Control+";',
|
|
3813
|
+
' void sendLiveInput({ kind: "key", key: prefix + e.key.toLowerCase() });',
|
|
3814
|
+
' return;',
|
|
3815
|
+
' }',
|
|
3816
|
+
' if (e.key.length === 1 && !e.altKey) {',
|
|
3817
|
+
' void sendLiveInput({ kind: "type", text: e.key });',
|
|
3818
|
+
' return;',
|
|
3819
|
+
' }',
|
|
3820
|
+
' const keyMap = {',
|
|
3821
|
+
' Enter: "Enter", Backspace: "Backspace", Delete: "Delete", Tab: "Tab", Escape: "Escape",',
|
|
3822
|
+
' ArrowUp: "ArrowUp", ArrowDown: "ArrowDown", ArrowLeft: "ArrowLeft", ArrowRight: "ArrowRight",',
|
|
3823
|
+
' Home: "Home", End: "End", PageUp: "PageUp", PageDown: "PageDown"',
|
|
3824
|
+
' };',
|
|
3825
|
+
' const mapped = keyMap[e.key];',
|
|
3826
|
+
' if (mapped) void sendLiveInput({ kind: "key", key: mapped });',
|
|
3827
|
+
' });',
|
|
3828
|
+
' liveViewportSurface.addEventListener("paste", (e) => {',
|
|
3829
|
+
' if (!state.liveBrowserActive || state.browserEngine !== "agent") return;',
|
|
3830
|
+
' const txt = (e.clipboardData && e.clipboardData.getData("text/plain")) || "";',
|
|
3831
|
+
' if (!txt) return;',
|
|
3832
|
+
' e.preventDefault();',
|
|
3833
|
+
' void sendLiveInput({ kind: "paste", text: txt });',
|
|
3834
|
+
' });',
|
|
3835
|
+
' browserSnapshotBtn.addEventListener("click", async () => {',
|
|
3836
|
+
' closeAllPopovers();',
|
|
3837
|
+
' const data = await runBrowserAction({ action: "snapshot" });',
|
|
3838
|
+
' if (data && data.snapshot) {',
|
|
3839
|
+
' openStudio("cli");',
|
|
3840
|
+
' cliConsoleEl.textContent = data.snapshot;',
|
|
3841
|
+
' cliStatusEl.textContent = "Page structure (" + (data.refsCount || 0) + " interactive elements)";',
|
|
3842
|
+
' }',
|
|
3843
|
+
' });',
|
|
3844
|
+
' browserDemoBtn.addEventListener("click", () => {',
|
|
3845
|
+
' closeAllPopovers();',
|
|
3846
|
+
' setBrowserEngine("frame");',
|
|
3847
|
+
' const content = (fileContentInput.value || "").trim();',
|
|
3848
|
+
' if (content && (content.startsWith("<") || isHtmlOrSvgPath(filePathInput.value))) {',
|
|
3849
|
+
' openBrowserArtifact(filePathInput.value || "preview.html", content);',
|
|
3850
|
+
' } else {',
|
|
3851
|
+
' openBrowserArtifact("preview.html", "<!DOCTYPE html><html><body style=\\"margin:0;padding:32px;background:#141714;color:#ecefe9;font-family:system-ui\\"><h2 style=\\"margin:0 0 8px;font-weight:500\\">Document preview</h2><p style=\\"color:#a0a79c\\">Open an HTML or SVG file in the Editor to preview it here.</p></body></html>");',
|
|
3852
|
+
' }',
|
|
3853
|
+
' });',
|
|
3854
|
+
' browserOpenExtBtn.addEventListener("click", () => {',
|
|
3855
|
+
' closeAllPopovers();',
|
|
3856
|
+
' const valid = parseLoopbackUrl(state.browserUrl);',
|
|
3857
|
+
' if (valid) window.open(valid, "_blank", "noopener,noreferrer");',
|
|
3858
|
+
' });',
|
|
3859
|
+
' document.querySelectorAll("[data-vp]").forEach((btn) => {',
|
|
3860
|
+
' btn.addEventListener("click", () => {',
|
|
3861
|
+
' const vp = btn.getAttribute("data-vp") || "desktop";',
|
|
3862
|
+
' state.browserViewport = vp;',
|
|
3863
|
+
' document.querySelectorAll("[data-vp]").forEach((b) => b.classList.toggle("active", b === btn));',
|
|
3864
|
+
' browserFrame.classList.toggle("vp-tablet", vp === "tablet");',
|
|
3865
|
+
' browserFrame.classList.toggle("vp-mobile", vp === "mobile");',
|
|
3866
|
+
' if (state.browserEngine === "agent" && state.liveBrowserActive) {',
|
|
3867
|
+
' const dims = vp === "mobile" ? { width: 390, height: 844 } : vp === "tablet" ? { width: 768, height: 900 } : { width: 1280, height: 800 };',
|
|
3868
|
+
' void runBrowserAction({ action: "viewport", width: dims.width, height: dims.height });',
|
|
3869
|
+
' }',
|
|
3870
|
+
' });',
|
|
3871
|
+
' });',
|
|
3872
|
+
'',
|
|
3873
|
+
' cliRunBtn.addEventListener("click", () => { void runCliCommand(cliCmdInput.value, "studio"); cliCmdInput.value = ""; });',
|
|
3874
|
+
' cliCmdInput.addEventListener("keydown", (e) => {',
|
|
3875
|
+
' if (e.key === "Enter") { e.preventDefault(); void runCliCommand(cliCmdInput.value, "studio"); cliCmdInput.value = ""; }',
|
|
3876
|
+
' });',
|
|
3877
|
+
' cliProbeBtn.addEventListener("click", () => { void runZeroSpendProbe(); });',
|
|
3878
|
+
' vaultSaveBtn.addEventListener("click", () => { void saveVaultApiKey(); });',
|
|
3879
|
+
'',
|
|
3880
|
+
' setInterval(() => {',
|
|
3881
|
+
' if (state.activeController && appEl.classList.contains("studio-open")',
|
|
3882
|
+
' && state.studioTab === "browser" && state.browserEngine === "agent" && !state.liveStreamConnected) {',
|
|
3883
|
+
' void refreshLiveBrowserState(false);',
|
|
3884
|
+
' startLiveBrowserStream();',
|
|
3885
|
+
' }',
|
|
3886
|
+
' }, 2000);',
|
|
3887
|
+
'',
|
|
3888
|
+
' setInterval(() => {',
|
|
3889
|
+
' if (!state.activeController && state.sessions.some((s) => s.running)) {',
|
|
3890
|
+
' void loadSessions();',
|
|
3891
|
+
' }',
|
|
3892
|
+
' }, 4000);',
|
|
3893
|
+
'',
|
|
3894
|
+
' if (diffScopeSessionBtn) diffScopeSessionBtn.addEventListener("click", () => {',
|
|
3895
|
+
' if (!state.sessionId) return;',
|
|
3896
|
+
' state.diffScope = "session";',
|
|
3897
|
+
' saveCurrentSessionWorkspace();',
|
|
3898
|
+
' syncDiffControlsUi();',
|
|
3899
|
+
' void loadDiff();',
|
|
3900
|
+
' });',
|
|
3901
|
+
' if (diffScopeWorkspaceBtn) diffScopeWorkspaceBtn.addEventListener("click", () => {',
|
|
3902
|
+
' state.diffScope = "workspace";',
|
|
3903
|
+
' saveCurrentSessionWorkspace();',
|
|
3904
|
+
' syncDiffControlsUi();',
|
|
3905
|
+
' void loadDiff();',
|
|
3906
|
+
' });',
|
|
3907
|
+
' diffStagedToggle.addEventListener("click", () => {',
|
|
3908
|
+
' state.diffStaged = !state.diffStaged;',
|
|
3909
|
+
' syncDiffControlsUi();',
|
|
3910
|
+
' void loadDiff();',
|
|
3911
|
+
' });',
|
|
3912
|
+
' refreshDiffBtn.addEventListener("click", () => { void loadDiff(); });',
|
|
3913
|
+
' settingsCloseBtn.addEventListener("click", () => settingsModal.classList.remove("open"));',
|
|
3914
|
+
' settingsModal.addEventListener("click", (e) => { if (e.target === settingsModal) settingsModal.classList.remove("open"); });',
|
|
3915
|
+
' themeToggleBtn.addEventListener("click", () => {',
|
|
3916
|
+
' const cur = document.documentElement.getAttribute("data-theme") || "dark";',
|
|
3917
|
+
' applyTheme(cur === "light" ? "dark" : "light");',
|
|
3918
|
+
' });',
|
|
3919
|
+
' doctorLoadBtn.addEventListener("click", () => { void loadDoctorReport(); });',
|
|
3920
|
+
' if (licenseUpgradeBtn) licenseUpgradeBtn.addEventListener("click", () => { void startLicenseCheckout(); });',
|
|
3921
|
+
' if (licensePortalBtn) licensePortalBtn.addEventListener("click", () => { void openBillingPortal(); });',
|
|
3922
|
+
' if (licenseRefreshBtn) licenseRefreshBtn.addEventListener("click", () => { void loadLicenseStatus(true); });',
|
|
3923
|
+
' if (licenseRecoverBtn) licenseRecoverBtn.addEventListener("click", () => { void claimLicenseRecovery(); });',
|
|
3924
|
+
'',
|
|
3925
|
+
' document.addEventListener("keydown", (e) => {',
|
|
3926
|
+
' if (document.activeElement === liveViewportSurface && state.liveBrowserActive) return;',
|
|
3927
|
+
' const mod = e.metaKey || e.ctrlKey;',
|
|
3928
|
+
' if (mod && e.key.toLowerCase() === "b") { e.preventDefault(); appEl.classList.toggle("sidebar-collapsed"); if (appEl.classList.contains("studio-open")) applyStudioWidth(state.studioWidth, false); }',
|
|
3929
|
+
' else if (mod && e.key === "\\\\") { e.preventDefault(); if (appEl.classList.contains("studio-open")) closeStudio(); else openStudio(state.studioTab || "files"); }',
|
|
3930
|
+
' else if (mod && e.shiftKey && e.key.toLowerCase() === "o") { e.preventDefault(); void startFreshChat(); }',
|
|
3931
|
+
' else if (mod && e.key.toLowerCase() === "s" && appEl.classList.contains("studio-open") && state.studioTab === "canvas") {',
|
|
3932
|
+
' e.preventDefault(); void saveFile();',
|
|
3933
|
+
' } else if (e.key === "Escape") {',
|
|
3934
|
+
' if (resizing) { endResize(true); return; }',
|
|
3935
|
+
' if (settingsModal.classList.contains("open")) { settingsModal.classList.remove("open"); return; }',
|
|
3936
|
+
' if (modelPopover.classList.contains("open") || plusPopover.classList.contains("open") || browserMorePopover.classList.contains("open") || mentionPopover.classList.contains("open")) { closeAllPopovers(); return; }',
|
|
3937
|
+
' if (appEl.classList.contains("studio-open")) { closeStudio(); return; }',
|
|
3938
|
+
' if (state.activeController) { void stopActiveRun(); }',
|
|
3939
|
+
' }',
|
|
3940
|
+
' });',
|
|
3941
|
+
' window.addEventListener("beforeunload", stopLiveBrowserStream);',
|
|
3942
|
+
'',
|
|
3943
|
+
' updateComposerMetrics();',
|
|
3944
|
+
' renderCliQuickGrid();',
|
|
3945
|
+
' promptInput.focus();',
|
|
3946
|
+
' void loadHealth();',
|
|
3947
|
+
' void loadSessions();',
|
|
3948
|
+
' void loadFiles("", "");',
|
|
3949
|
+
' void loadCliCommands();',
|
|
3950
|
+
'})();'
|
|
3951
|
+
].join('\n');
|
|
3952
|
+
}
|