pycodex-ws 0.6.2__tar.gz → 0.6.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/PKG-INFO +2 -2
  2. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/pyproject.toml +2 -2
  3. pycodex_ws-0.6.3/workspace_server/content_views.mjs +37 -0
  4. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/frontend/transcript.mjs +10 -7
  5. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/README.md +1 -0
  6. pycodex_ws-0.6.3/workspace_server/optional_features/file-attachments/README.md +137 -0
  7. pycodex_ws-0.6.3/workspace_server/optional_features/file-attachments/source/custom.css +189 -0
  8. pycodex_ws-0.6.3/workspace_server/optional_features/file-attachments/source/custom.js +5 -0
  9. pycodex_ws-0.6.3/workspace_server/optional_features/file-attachments/source/upload_browser.py +314 -0
  10. pycodex_ws-0.6.3/workspace_server/optional_features/file-attachments/source/upload_core.mjs +271 -0
  11. pycodex_ws-0.6.3/workspace_server/optional_features/file-attachments/source/upload_core.test.mjs +161 -0
  12. pycodex_ws-0.6.3/workspace_server/optional_features/file-attachments/source/uploads.mjs +385 -0
  13. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/session_api.py +18 -44
  14. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/sessions.py +1 -1
  15. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/workspace.html +15 -8
  16. pycodex_ws-0.6.2/workspace_server/content_views.mjs +0 -37
  17. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/.gitignore +0 -0
  18. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/LICENSE +0 -0
  19. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/README.md +0 -0
  20. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/pycodex_router/__init__.py +0 -0
  21. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/pycodex_router/__main__.py +0 -0
  22. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/pycodex_router/browser.py +0 -0
  23. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/pycodex_router/client.py +0 -0
  24. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/pycodex_router/index.html +0 -0
  25. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/pycodex_router/protocol.py +0 -0
  26. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/pycodex_router/server.py +0 -0
  27. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/pycodex_ws/__init__.py +0 -0
  28. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/pycodex_ws/feishu_auth.py +0 -0
  29. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/pycodex_ws/feishu_card.py +0 -0
  30. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/pycodex_ws/feishu_connection.py +0 -0
  31. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/pycodex_ws/feishu_link.py +0 -0
  32. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/pycodex_ws/feishu_oauth.py +0 -0
  33. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/pycodex_ws/feishu_render.py +0 -0
  34. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/pycodex_ws/server_support.py +0 -0
  35. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/pycodex_ws/workspace_config.py +0 -0
  36. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/WORKSPACE_API.md +0 -0
  37. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/__init__.py +0 -0
  38. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/__main__.py +0 -0
  39. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/agent_access.py +0 -0
  40. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/app.py +0 -0
  41. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/content_views.LICENSE.txt +0 -0
  42. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/content_views.css +0 -0
  43. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/customization.py +0 -0
  44. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/editor.css +0 -0
  45. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/editor.mjs +0 -0
  46. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/frontend/.gitignore +0 -0
  47. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/frontend/build.mjs +0 -0
  48. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/frontend/composer.mjs +0 -0
  49. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/frontend/content_views.css +0 -0
  50. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/frontend/content_views.mjs +0 -0
  51. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/frontend/editor.css +0 -0
  52. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/frontend/editor.mjs +0 -0
  53. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/frontend/editor_context.mjs +0 -0
  54. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/frontend/package-lock.json +0 -0
  55. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/frontend/package.json +0 -0
  56. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/frontend/prompt_history.mjs +0 -0
  57. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/frontend/touch_selection.mjs +0 -0
  58. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/frontend/view_labels.mjs +0 -0
  59. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/one_line_agent.py +0 -0
  60. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/CONTRIBUTING.md +0 -0
  61. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/clock-ticks/README.md +0 -0
  62. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/clock-ticks/preview-mobile.png +0 -0
  63. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/clock-ticks/preview.html +0 -0
  64. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/clock-ticks/preview.png +0 -0
  65. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/clock-ticks/source/custom.css +0 -0
  66. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/clock-ticks/source/custom.js +0 -0
  67. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/clock-ticks/source/fixture.mjs +0 -0
  68. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/clock-ticks/source/verify.mjs +0 -0
  69. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/consecutive-tool-groups/README.md +0 -0
  70. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/consecutive-tool-groups/preview-mobile.png +0 -0
  71. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/consecutive-tool-groups/preview.html +0 -0
  72. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/consecutive-tool-groups/preview.png +0 -0
  73. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/consecutive-tool-groups/source/fixture.mjs +0 -0
  74. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/consecutive-tool-groups/source/tool-groups.css +0 -0
  75. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/consecutive-tool-groups/source/tool-groups.js +0 -0
  76. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/consecutive-tool-groups/source/verify.mjs +0 -0
  77. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/exec-status/README.md +0 -0
  78. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/exec-status/preview-mobile.png +0 -0
  79. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/exec-status/preview.html +0 -0
  80. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/exec-status/preview.png +0 -0
  81. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/exec-status/source/custom.css +0 -0
  82. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/exec-status/source/custom.js +0 -0
  83. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/exec-status/source/fixture.mjs +0 -0
  84. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/exec-status/source/verify.mjs +0 -0
  85. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/reasoning-display/README.md +0 -0
  86. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/reasoning-display/preview-mobile.png +0 -0
  87. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/reasoning-display/preview.html +0 -0
  88. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/reasoning-display/preview.png +0 -0
  89. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/reasoning-display/source/custom.css +0 -0
  90. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/reasoning-display/source/custom.js +0 -0
  91. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/reasoning-display/source/fixture.mjs +0 -0
  92. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/reasoning-display/source/verify.mjs +0 -0
  93. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/session-tips/README.md +0 -0
  94. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/session-tips/preview-mobile.png +0 -0
  95. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/session-tips/preview.html +0 -0
  96. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/session-tips/preview.png +0 -0
  97. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/session-tips/source/custom.css +0 -0
  98. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/session-tips/source/custom.js +0 -0
  99. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/session-tips/source/fixture.mjs +0 -0
  100. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/session-tips/source/session-tips.js +0 -0
  101. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/session-tips/source/verify.mjs +0 -0
  102. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/skill-completion/README.md +0 -0
  103. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/skill-completion/preview.png +0 -0
  104. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/skill-completion/source/custom.css +0 -0
  105. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/skill-completion/source/custom.js +0 -0
  106. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/skill-completion/source/skill-completion.css +0 -0
  107. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/skill-completion/source/skill-completion.mjs +0 -0
  108. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/skill-completion/source/verify.mjs +0 -0
  109. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/tool-calls/README.md +0 -0
  110. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/tool-calls/preview-mobile.png +0 -0
  111. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/tool-calls/preview.html +0 -0
  112. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/tool-calls/preview.png +0 -0
  113. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/tool-calls/source/custom.css +0 -0
  114. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/tool-calls/source/custom.js +0 -0
  115. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/tool-calls/source/fixture.mjs +0 -0
  116. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/tool-calls/source/verify.mjs +0 -0
  117. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/voice-input/README.md +0 -0
  118. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/voice-input/preview-mobile.png +0 -0
  119. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/voice-input/preview.png +0 -0
  120. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/voice-input/source/custom.css +0 -0
  121. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/voice-input/source/custom.js +0 -0
  122. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/voice-input/source/verify.cjs +0 -0
  123. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/voice-input/source/voice-input.css +0 -0
  124. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/optional_features/voice-input/source/voice-input.js +0 -0
  125. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/owned_process.py +0 -0
  126. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/reloader.py +0 -0
  127. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/routes.py +0 -0
  128. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/runtime_info.py +0 -0
  129. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/session_view.py +0 -0
  130. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/sharing.py +0 -0
  131. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/view_sources.py +0 -0
  132. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/workspace_views.py +0 -0
  133. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/workspaces.html +0 -0
  134. {pycodex_ws-0.6.2 → pycodex_ws-0.6.3}/workspace_server/workspaces.py +0 -0
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycodex-ws
3
- Version: 0.6.2
3
+ Version: 0.6.3
4
4
  Summary: Browser workspace and optional Feishu integration for python-codex
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.7
7
7
  Requires-Dist: pillow>=9.0.0
8
- Requires-Dist: python-codex==0.6.2
8
+ Requires-Dist: python-codex==0.6.3
9
9
  Requires-Dist: websockets<16,>=11
10
10
  Description-Content-Type: text/markdown
11
11
 
@@ -4,12 +4,12 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "pycodex-ws"
7
- version = "0.6.2"
7
+ version = "0.6.3"
8
8
  description = "Browser workspace and optional Feishu integration for python-codex"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.7"
11
11
  dependencies = [
12
- "python-codex==0.6.2",
12
+ "python-codex==0.6.3",
13
13
  "pillow>=9.0.0",
14
14
  "websockets>=11,<16",
15
15
  ]
@@ -0,0 +1,37 @@
1
+ // Generated by workspace_server/frontend/build.mjs. See content_views.LICENSE.txt.
2
+ function j(l){function t(n){let r=n.lastIndexOf("/");return r<0?".":n.slice(0,r)||"/"}let e=new Map,s=l.map(n=>{let o=(n.kind==="diff"?n.title.split(" <-> "):[n.title]).map(h=>{let a=/^(?:([0-9a-f]{40}|[0-9a-f]{64})|.+ \(([0-9a-f]{40}|[0-9a-f]{64})\)):(.+)$/i.exec(h),u=a?a[3]:h,d=u.slice(u.lastIndexOf("/")+1);return e.has(d)||e.set(d,new Set),e.get(d).add(u),{path:u,name:d,revision:a?(a[1]||a[2]).slice(0,7):null}});return{view:n,sources:o}}),i=new Map;for(let n of e.values()){if(n.size<2)continue;let r=Array.from(n),o=r.map(h=>t(h).split("/"));r.forEach((h,a)=>{let u=1;for(;u<o[a].length&&o.some((d,b)=>b!==a&&d.slice(-u).join("/")===o[a].slice(-u).join("/"));)u+=1;i.set(h,o[a].slice(-u).join("/")||"/")})}return new Map(s.map(({view:n,sources:r})=>{let o=r.every(d=>d.path===r[0].path),h=o?r[0].name:r.map(d=>d.name).join(" \u2194 "),a="";o?a=i.get(r[0].path)||"":r.some(d=>i.has(d.path))&&(a=r.map(d=>i.get(d.path)||t(d.path)).join(" \u2194 "));let u=r.some(d=>d.revision)?r.map(d=>d.revision||"working tree").join(" \u2194 "):n.kind==="diff"&&o?"diff":"";return[n.id,{name:h,description:[a,u].filter(Boolean).join(" \xB7 ")}]}))}function A(l){return typeof l=="string"?l:Array.isArray(l)?l.map(t=>t.text||t.refusal||`[${t.type}]`).join(`
3
+ `):JSON.stringify(l,null,2)}function H(l){let t=[],e=new Map;for(let s of l){let i=s.payload,n=`record:${s.index}`;if(i.type==="function_call"||i.type==="custom_tool_call"){let r={key:`call:${i.call_id}`,kind:"tool",callId:i.call_id,toolName:i.name,label:[i.namespace,i.name].filter(Boolean).join("."),input:A(i.type==="custom_tool_call"?i.input:i.arguments)};e.set(i.call_id,r),t.push(r)}else if(i.type==="function_call_output"||i.type==="custom_tool_call_output"){let r=e.get(i.call_id);r||(r={key:`call:${i.call_id}`,kind:"tool",callId:i.call_id,toolName:i.name,label:i.name||"Tool"},e.set(i.call_id,r),t.push(r)),r.output=A(i.output)}else if(i.type==="message"||i.type==="agent_message")t.push({key:n,kind:i.role||"agent_message",label:i.type==="agent_message"?`${i.author} \u2192 ${i.recipient}`:i.role,phase:i.phase,body:A(i.content)});else if(i.type==="reasoning"){let r=[...i.summary||[],...i.content||[]].map(o=>o.text||"").filter(Boolean).join(`
4
+
5
+ `)||"No readable reasoning was recorded.";t.push({key:n,kind:"reasoning",label:"Reasoning",body:r})}else t.push({key:n,kind:"raw",label:i.type||s.type,body:A(i)})}return t}function W(l){let t={state:l.output===void 0?"pending":"completed"};if(l.toolName!=="exec"&&l.toolName!=="wait")return t;if(l.toolName==="wait"&&l.input!==void 0){let s;try{s=JSON.parse(l.input)}catch(i){if(!(i instanceof SyntaxError))throw i}typeof(s==null?void 0:s.cell_id)=="string"&&(t.cellId=s.cell_id)}let e=/^Script (running with cell ID (\S+)|completed|failed|terminated)\nWall time [\d.]+ seconds\nOutput:\n/.exec(l.output);return e&&(t.state=e[2]?"running":e[1],e[2]&&(t.cellId=e[2])),t}var T=class{constructor({viewport:t,request:e,renderMarkdown:s,sessionId:i,agentId:n,agentPath:r}){this.viewport=t,this.document=t.ownerDocument,this.window=this.document.defaultView,this.request=e,this.renderMarkdown=s,this.position=[0,0],this.sessionId=i,this.agentId=n,this.records=new Map,this.source=null,this.revision=null,this.nextCursor=null,this.agentSessionId=null,this.active=!1,this.socket=null,this.requestController=null,this.reloadTimer=null,this.retryTimer=null,this.pendingRefresh=!1,this.pendingReset=!1,this.lastLoad=0,this.root=this.element("section","transcript"),this.root.dataset.sessionId=i;let o=this.element("div","snapshot-heading transcript-heading"),h=this.element("span","snapshot-label",r);h.title=`Agent: ${n}
6
+ Session: ${i}`,this.status=this.element("span","snapshot-stamp","Loading\u2026"),this.refresh=this.element("button","content-mode-toggle","Refresh"),this.refresh.type="button",this.refresh.addEventListener("click",()=>this.load()),this.error=this.element("div","transcript-error"),this.error.setAttribute("role","alert"),this.error.hidden=!0,this.older=this.element("button","content-mode-toggle","Load earlier"),this.older.type="button",this.older.hidden=!0,this.older.addEventListener("click",()=>this.load(!0)),o.append(h,this.status,this.older,this.refresh),this.scroll=this.element("div","transcript-scroll"),this.scroll.tabIndex=0,this.scroll.setAttribute("aria-label",r+" transcript"),this.list=this.element("div","transcript-list","Loading transcript\u2026"),this.scroll.appendChild(this.list),this.root.append(o,this.error,this.scroll),this.visibilityChanged=()=>{this.document.hidden?this.disconnect():(this.load(),this.connect())}}element(t,e,s){let i=this.document.createElement(t);return i.className=e,s!==void 0&&(i.textContent=s),i}start(){this.active||(this.active=!0,[this.scroll.scrollLeft,this.scroll.scrollTop]=this.position,this.document.addEventListener("visibilitychange",this.visibilityChanged),this.document.hidden||(this.load(),this.connect()))}disconnect(){var e;clearTimeout(this.reloadTimer),clearTimeout(this.retryTimer),this.reloadTimer=this.retryTimer=null,(e=this.requestController)==null||e.abort(),this.requestController=null;let t=this.socket;this.socket=null,t&&t.close()}stop(){this.active=!1,this.document.removeEventListener("visibilitychange",this.visibilityChanged),this.disconnect(),this.position=[this.scroll.scrollLeft,this.scroll.scrollTop]}schedule(t=!1){this.pendingReset||(this.pendingReset=t),!(this.reloadTimer!==null||!this.active||this.document.hidden)&&(this.reloadTimer=setTimeout(()=>{this.reloadTimer=null,this.load()},Math.max(150,1e3-(Date.now()-this.lastLoad))))}connect(){if(this.socket||!this.active||this.document.hidden)return;let t=new URL("ws/session",this.window.location.href);t.protocol=t.protocol==="https:"?"wss:":"ws:",t.searchParams.set("session_id",this.sessionId),t.searchParams.set("agent_id",this.agentId);let e=new this.window.WebSocket(t);this.socket=e,e.onmessage=s=>{if(this.socket!==e)return;let i=JSON.parse(s.data);if(i.type==="error"){this.showError(i.error);return}let n=i.state;n&&(this.agentSessionId!==null&&this.agentSessionId!==n.agent_session_id&&(this.pendingReset=!0),this.agentSessionId=n.agent_session_id,this.status.textContent=n.running?"Running":"Live"),(i.type==="hello"||["model_called","model_completed","tool_started","tool_completed","turn_completed","turn_failed","turn_interrupted","session_state","compact_completed","auto_compact_completed"].includes(i.kind))&&this.schedule(i.kind==="compact_completed"||i.kind==="auto_compact_completed")},e.onclose=s=>{this.socket===e&&(this.socket=null,this.status.textContent="Disconnected",s.code!==1e3&&s.code!==1008&&(this.retryTimer=setTimeout(()=>{this.retryTimer=null,this.connect()},2e3)))}}showError(t){this.error.textContent=t,this.error.hidden=!t}async load(t=!1){if(!this.active||this.document.hidden||t&&!this.nextCursor)return;if(this.requestController){t||(this.pendingRefresh=!0);return}this.pendingReset&&(t=!1);let e=new AbortController;this.requestController=e;let s=this.pendingReset;this.pendingReset=!1,this.pendingRefresh=!1,this.older.disabled=!0;let i=n=>{let r=new URLSearchParams({agent_id:this.agentId,limit:"100"});return n!==null&&r.set("before",n),this.request(`api/sessions/${encodeURIComponent(this.sessionId)}/history?${r}`,{signal:e.signal})};try{let n=await i(t?this.nextCursor:null),r=n.items,o=Array.from(this.records.values()),h=o.length?o[o.length-1].index:-1,a=n.next_cursor,u=this.source!==n.source||this.revision!==n.revision;if(!t&&!s&&!u&&o.length)for(;r.length&&r[0].index>h&&a!==null;){let y=await i(a);if(y.source!==n.source||y.revision!==n.revision)throw Object.assign(new Error("History changed"),{status:409});r=y.items.concat(r),a=y.next_cursor}if(this.requestController!==e)return;let d=r.filter(y=>this.records.has(y.index)),b=s||u||!t&&o.length&&(!d.length||d.some(y=>JSON.stringify(y)!==JSON.stringify(this.records.get(y.index))));b&&(this.records.clear(),r=n.items);for(let y of r)this.records.set(y.index,y);this.records=new Map(Array.from(this.records).sort((y,I)=>y[0]-I[0])),(t||b||!o.length)&&(this.nextCursor=n.next_cursor),this.source=n.source,this.revision=n.revision,this.showError(""),this.render()}catch(n){if(this.requestController!==e||n.name==="AbortError")return;n.status===409?(this.pendingReset=!0,this.pendingRefresh=!0):(this.showError("Unable to load transcript: "+n.message),[401,403,404].includes(n.status)&&this.disconnect())}finally{this.requestController===e&&(this.requestController=null,this.lastLoad=Date.now(),this.older.disabled=!1,(this.pendingRefresh||this.pendingReset)&&this.schedule())}}renderBlock(t){let e=t.kind==="tool",s=this.element("details","transcript-record");s.dataset.key=t.key,s.dataset.kind=t.kind,t.toolName&&(s.dataset.tool=t.toolName),s.open=t.kind!=="reasoning";let i=this.element("summary","transcript-marker"),n=this.element("span","transcript-marker-line"),r=this.element("span","transcript-label");if(r.appendChild(this.element("span","transcript-role",t.label)),n.appendChild(r),i.appendChild(n),e){i.title="Call: "+t.callId;let o=W(t);if(o.cellId){let a=this.element("span","transcript-cell",o.cellId);a.title="Cell: "+o.cellId;let u=0;for(let d of o.cellId)u=(u*31+d.charCodeAt(0))%80;a.style.setProperty("--transcript-cell-hue",200+u),r.appendChild(a)}let h=this.element("span","transcript-phase",{pending:"Awaiting result",running:"Running",completed:"Completed",failed:"Failed",terminated:"Terminated"}[o.state]);if(h.dataset.state=o.state,n.appendChild(h),s.append(i,t.input===void 0?this.element("p","transcript-note","Load earlier records to see this call's input."):this.element("pre","transcript-code",t.input)),t.output!==void 0){let a=this.element("details","transcript-output");a.append(this.element("summary","","Output"),this.element("pre","transcript-code",t.output)),s.appendChild(a)}}else{t.phase&&n.appendChild(this.element("span","transcript-phase",t.phase));let o=this.element("div","transcript-body markdown");t.kind!=="raw"&&this.renderMarkdown?this.renderMarkdown(o,t.body||""):o.appendChild(this.element("pre","transcript-code",t.body)),s.append(i,o)}return s.signature=JSON.stringify(t),s}render(){let t=this.scroll.scrollHeight-this.scroll.scrollTop-this.scroll.clientHeight<40,e=this.scroll.getBoundingClientRect().top,s=Array.from(this.list.children).find(a=>a.getBoundingClientRect().bottom>e),i=s==null?void 0:s.getBoundingClientRect().top,n=new Map(Array.from(this.list.children,a=>[a.dataset.key,a])),r=H(Array.from(this.records.values())),o=r.map(a=>{let u=JSON.stringify(a),d=n.get(a.key);if((d==null?void 0:d.signature)===u)return d;let b=this.renderBlock(a);if(d){b.open=d.open;let y=d.querySelector(".transcript-output"),I=b.querySelector(".transcript-output");y&&I&&(I.open=y.open)}return b});this.list.children.length||(this.list.textContent="");let h=new Set(o);for(let a of Array.from(this.list.children))h.has(a)||a.remove();if(o.forEach((a,u)=>{this.list.children[u]!==a&&this.list.insertBefore(a,this.list.children[u]||null)}),r.length||(this.list.textContent="No messages yet."),this.older.hidden=this.nextCursor===null,t)this.scroll.scrollTop=this.scroll.scrollHeight;else if(s){let a=o.find(u=>u.dataset.key===s.dataset.key);a&&(this.scroll.scrollTop+=a.getBoundingClientRect().top-i)}}};var E=class l{constructor(t,e,s,i,n,r=null){this.element=t,this.changed=e,this.submit=s,this.editContext=i,this.error=n,this.recallInput=r,this.recalledParts=null,this.composing=!1,this.selection={start:0,end:0},this.undo=[],this.redo=[],this.previous=this.read(),t.addEventListener("input",o=>{o.isComposing||this.record(),this.changed()}),t.addEventListener("compositionstart",()=>{this.composing=!0}),t.addEventListener("compositionend",()=>{this.composing=!1,this.record(),this.changed()}),document.addEventListener("selectionchange",()=>{this.captureSelection()&&this.changed()}),t.addEventListener("keydown",o=>this.keydown(o)),t.addEventListener("beforeinput",o=>{o.inputType==="historyUndo"||o.inputType==="historyRedo"?(o.preventDefault(),this.history(o.inputType==="historyUndo")):o.inputType.startsWith("format")&&o.preventDefault()}),t.addEventListener("click",o=>{let h=o.target.closest(".context-token");h&&this.editContext(JSON.parse(h.dataset.context))}),t.addEventListener("mousedown",o=>{o.target.closest(".context-token")&&o.preventDefault()}),t.addEventListener("copy",o=>this.copy(o,!1)),t.addEventListener("cut",o=>this.copy(o,!0)),t.addEventListener("paste",o=>{o.preventDefault(),this.paste(o.clipboardData)}),t.addEventListener("dragover",o=>o.preventDefault()),t.addEventListener("drop",o=>{o.preventDefault();let h=document.caretRangeFromPoint(o.clientX,o.clientY);if(h&&t.contains(h.startContainer)){let a=window.getSelection();a.removeAllRanges(),a.addRange(h),this.captureSelection()}this.paste(o.dataTransfer)})}static size(t){return t.reduce((e,s)=>e+(s.type==="context"?1:s.text.length),0)}static text(t){return t.map(e=>e.text).join("")}static slice(t,e,s){let i=[],n=0;for(let r of t){let o=l.size([r]);e<n+o&&s>n&&i.push(r.type==="context"?{...r}:{type:"text",text:r.text.slice(Math.max(0,e-n),s-n)}),n+=o}return i}parts(t=this.element){let e=[],s=n=>{if(!n)return;let r=e.at(-1);(r==null?void 0:r.type)==="text"?r.text+=n:e.push({type:"text",text:n})},i=n=>{var r;for(let o of n.childNodes)o.nodeType===Node.TEXT_NODE?s(o.data):(r=o.dataset)!=null&&r.context?e.push(JSON.parse(o.dataset.context)):o.nodeName==="BR"?!o.hasAttribute("data-tail")&&n.childNodes.length>1&&s(`
7
+ `):(["DIV","P"].includes(o.nodeName)&&e.length&&!e.at(-1).text.endsWith(`
8
+ `)&&s(`
9
+ `),i(o))};return i(t),e}captureSelection(){if(document.activeElement!==this.element)return!1;let t=window.getSelection();if(!t.rangeCount)return!1;let e=t.getRangeAt(0);if(!this.element.contains(e.startContainer)||!this.element.contains(e.endContainer))return!1;let s=document.createRange();s.selectNodeContents(this.element),s.setEnd(e.startContainer,e.startOffset);let i=l.size(this.parts(s.cloneContents()));return this.selection={start:i,end:i+l.size(this.parts(e.cloneContents()))},!0}read(){return this.captureSelection(),{parts:this.parts(),selection:{...this.selection}}}set(t){this.recalledParts=null,this.undo=[],this.redo=[],this.render(t),document.activeElement===this.element&&this.focus(),this.previous=this.read()}render(t){let e=t.parts||[];this.element.replaceChildren();for(let i of e)if(i.type==="text")this.element.append(document.createTextNode(i.text));else{let n=document.createElement("span");n.className="context-token",n.contentEditable="false",n.dataset.context=JSON.stringify(i),n.textContent=i.label,n.title=i.label+`
10
+ Click to edit context; Backspace / Delete to remove`,this.element.append(n,document.createTextNode(""))}if(!e.length||e.at(-1).type==="text"&&e.at(-1).text.endsWith(`
11
+ `)){let i=document.createElement("br");i.dataset.tail="",this.element.append(i)}let s=l.size(e);this.selection=t.selection||{start:s,end:s},this.selection={start:Math.min(this.selection.start,s),end:Math.min(this.selection.end,s)},this.element.classList.toggle("empty",!e.length)}focus(){this.element.focus({preventScroll:!0});let t=i=>{let n=r=>{var o;for(let h=0;h<r.childNodes.length;h++){let a=r.childNodes[h];if(a.nodeType===Node.TEXT_NODE){if(i<=a.length)return[a,i];i-=a.length}else if((o=a.dataset)!=null&&o.context){if(i===0)return[r,h];if(i-=1,i===0)return[r,h+1]}else if(a.nodeName==="BR"){if(i===0)return[r,h];a.hasAttribute("data-tail")||(i-=1)}else{let u=n(a);if(u)return u}}};return n(this.element)||[this.element,this.element.childNodes.length]},e=document.createRange();e.setStart(...t(this.selection.start)),e.setEnd(...t(this.selection.end));let s=window.getSelection();s.removeAllRanges(),s.addRange(e)}record(){let t=this.read();JSON.stringify(t.parts)!==JSON.stringify(this.previous.parts)&&(this.undo.push(this.previous),this.undo.length>40&&this.undo.shift(),this.redo=[],this.previous=t),this.element.classList.toggle("empty",!t.parts.length)}replace(t,e,s){let i=this.read(),n=[...l.slice(i.parts,0,t),...s,...l.slice(i.parts,e,l.size(i.parts))],r=t+l.size(s);this.render({parts:n,selection:{start:r,end:r}}),this.focus(),this.record(),this.changed()}insert(t){this.captureSelection(),this.replace(this.selection.start,this.selection.end,t.map(e=>({...e,type:"context",id:crypto.getRandomValues(new Uint32Array(4)).join("-")})))}updateContext(t,e){for(let s of this.element.querySelectorAll(".context-token")){let i=JSON.parse(s.dataset.context);i.id===t&&(s.dataset.context=JSON.stringify({...i,text:e}))}this.record(),this.changed()}removeContext(t){let e=0;for(let s of this.parts()){if(s.type==="context"&&s.id===t){this.replace(e,e+1,[]);return}e+=l.size([s])}}history(t){let e=t?this.undo:this.redo;e.length&&((t?this.redo:this.undo).push(this.read()),this.render(e.pop()),this.focus(),this.previous=this.read(),this.changed())}keydown(t){var s;if(t.isComposing||this.composing||t.keyCode===229)return;let e=t.ctrlKey||t.metaKey;if(this.recallInput&&["ArrowUp","ArrowDown"].includes(t.key)&&!e&&!t.altKey&&!t.shiftKey){let i=this.read();if(i.selection.start===i.selection.end){let n=i.selection.start,r=l.text(i.parts),o=t.key==="ArrowUp",h=l.text(l.slice(i.parts,0,n)),a=l.text(l.slice(i.parts,n,l.size(i.parts)));if(this.recalledParts===JSON.stringify(i.parts)||!r||!(o?h:a).includes(`
12
+ `)){let d=this.recallInput(o,i);d&&(t.preventDefault(),this.render(d),this.recalledParts=JSON.stringify(d.parts),this.focus(),this.record(),this.changed())}}}else if(e&&(t.key.toLowerCase()==="z"||t.key.toLowerCase()==="y"))t.preventDefault(),this.history(t.key.toLowerCase()==="z"&&!t.shiftKey);else if(t.key==="Enter")t.preventDefault(),t.shiftKey?(this.captureSelection(),this.replace(this.selection.start,this.selection.end,[{type:"text",text:`
13
+ `}])):this.submit();else if(["Backspace","Delete"].includes(t.key)&&!e&&!t.altKey){this.captureSelection();let{start:i,end:n}=this.selection,r=t.key==="Backspace"?i-1:i;i===n&&((s=l.slice(this.parts(),r,r+1)[0])==null?void 0:s.type)==="context"&&(t.preventDefault(),this.replace(r,r+1,[]))}}copy(t,e){if(!this.captureSelection()||this.selection.start===this.selection.end)return;let s=l.slice(this.parts(),this.selection.start,this.selection.end);t.clipboardData.setData("text/plain",l.text(s)),t.clipboardData.setData("application/x-pycodex-parts",JSON.stringify(s)),t.preventDefault(),e&&this.replace(this.selection.start,this.selection.end,[])}paste(t){try{let e=t.getData("application/x-pycodex-parts"),s=e?JSON.parse(e):[{type:"text",text:t.getData("text/plain")}];if(!Array.isArray(s)||s.some(i=>!i||typeof i.text!="string"||!["text","context"].includes(i.type)||i.type==="context"&&typeof i.label!="string"))throw new Error("Invalid context format in clipboard.");this.captureSelection(),this.replace(this.selection.start,this.selection.end,s.map(i=>i.type==="context"?{...i,id:crypto.getRandomValues(new Uint32Array(4)).join("-")}:i))}catch(e){this.error(e.message)}}};function K(l){let t=l.trim().match(/^<(clock_tick|exec_command_completed)>\s*([\s\S]*?)\s*<\/\1>$/);if(!t)return!1;try{let e=JSON.parse(t[2]);return e!==null&&typeof e=="object"&&!Array.isArray(e)}catch(e){return!1}}var D=class{constructor(){this.entries=[],this.seen=new Set,this.pending=[],this.index=null,this.draft=null}remember(t){let e=t.parts.map(s=>({...s}));E.text(e).trim()&&(this.append({parts:e}),this.pending.push(E.text(e).trim()),this.pending.length>100&&this.pending.shift(),this.reset())}append(t){this.entries.push(t),this.entries.length>100&&(this.entries.shift(),this.index!==null&&(this.index=Math.max(0,this.index-1)))}update(t){for(let e of t||[]){let s=e.submission_id||e.turn_id;if(!s||this.seen.has(s))continue;this.seen.add(s);let i=e.prompt;if(!i||!i.trim())continue;let n=this.pending.indexOf(i.trim());if(n!==-1){this.pending.splice(n,1);continue}e.kind==="compaction"||K(i)||!["web","cli","feishu","resume","user"].includes(e.sender)||this.append({parts:[{type:"text",text:i}]})}}reset(){this.index=null,this.draft=null}recall(t,e){if(this.index!==null&&JSON.stringify(e.parts)!==JSON.stringify(this.entries[this.index].parts)&&this.reset(),t){if(!this.entries.length||this.index===0)return null;this.index===null&&(this.draft=e,this.index=this.entries.length),this.index-=1}else{if(this.index===null)return null;if(this.index+=1,this.index>=this.entries.length){let s=this.draft;return this.reset(),s}}return{parts:this.entries[this.index].parts.map(s=>({...s}))}}};function st(l,t=!0){if(typeof l!="string"||!l||l!==l.trim()||/[\x00-\x1f\x7f]/.test(l))return!1;if(/^(?:diff:|git:|workspace:\/\/canvas\/?$)/i.test(l))return!0;if(!t||/^(?:https?|ftps?|mailto|tel|sms|javascript|vbscript|data|blob|about|file):/i.test(l))return!1;let e=l.split("#");if(e.length>2||e.length===2&&!/^L-?\d+$/i.test(e[1]))return!1;let s=e[0].replace(/:-?\d+$/,"");return!!s&&!s.startsWith("//")&&!s.includes("?")&&(!/^[a-z][a-z\d+.-]*:/i.test(s)||/^[a-z]:(?:[/\\]|%2f|%5c)/i.test(s))}var P=class{constructor({request:t,onChange:e,onSelect:s,selected:i=null,enableBoard:n=!0}){this.request=t,this.onChange=e,this.onSelect=s,this.enableBoard=n,this.views=[],this.transcripts=new Map,this.activeId=n?"board":null,this.snapshot=null,this.selection=null,this.displayMode=null,this.loading=!1,this.error="",this.closing=new Set,this.cache=new Map,this.initialSelection=i,this.initialized=!1,this.mutation=0,this.pollRequest=null,this.contentRequest=null,this.openRequest=null,this.timer=null}start(){this.timer===null&&(this.poll(),this.timer=setInterval(()=>this.poll(),2e3))}stop(){clearInterval(this.timer),this.timer=null,this.cancelOpen(),this.pollRequest&&this.pollRequest.abort(),this.contentRequest&&this.contentRequest.abort(),this.pollRequest=null,this.contentRequest=null,this.loading=!1}async poll(){if(this.pollRequest||this.openRequest)return;let t=new AbortController,e=this.mutation;this.pollRequest=t;try{let s=await this.request("api/views",{signal:t.signal});if(this.pollRequest!==t||e!==this.mutation)return;this.updateViews(s.views);let i=new Set(this.views.map(r=>r.id));this.error="";let n=this.activeId;this.initialized||(n=this.initialSelection||this.defaultId(),this.initialized=!0),(n==="board"&&!this.enableBoard||n!==null&&n!=="board"&&!i.has(n))&&(n=this.defaultId()),n!==this.activeId||n!==null&&n!=="board"&&!this.snapshot&&!this.loading?this.select(n,null,null,!1):(n!==null&&n!=="board"&&!this.cache.has(n)&&!this.contentRequest&&this.load(n),this.onChange(this))}catch(s){this.pollRequest===t&&e===this.mutation&&s.name!=="AbortError"&&(this.error="Unable to load tabs: "+s.message,this.onChange(this))}finally{this.pollRequest===t&&(this.pollRequest=null)}}defaultId(){return this.enableBoard?"board":this.views.length?this.views[0].id:null}updateViews(t){this.views=t.concat(Array.from(this.transcripts.values()));let e=new Map(this.views.map(s=>[s.id,s.revision]));for(let[s,i]of this.cache)(!e.has(s)||i.revision<e.get(s))&&this.cache.delete(s)}cancelOpen(){this.openRequest&&this.openRequest.abort(),this.openRequest=null}openTranscript(t,e,s){let i=`transcript:${t}:${e}`;if(!this.transcripts.has(i)){let n={id:i,kind:"transcript",title:s,sessionId:t,agentId:e,revision:1,documents:[]};this.transcripts.set(i,n),this.views.push(n),this.cache.set(i,n)}return this.initialized=!0,this.select(i)}async open(t,e,s){if(this.cancelOpen(),/^workspace:\/\/canvas\/?$/i.test(t)){if(!this.enableBoard)throw new Error("Canvas is disabled for this workspace.");await this.select("board");return}let i=new AbortController;this.openRequest=i,this.mutation+=1,this.error="",this.onChange(this);try{let n=await this.request("api/views/open",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({href:t,src_path:e,session_id:s}),signal:i.signal});if(this.openRequest!==i)return;this.mutation+=1,this.updateViews(n.views);let r=n.view;return this.cache.set(r.id,r),this.initialized=!0,this.openRequest=null,this.select(r.id,r.selection?{...r.selection,revision:r.reveal_revision,contentRevision:r.revision}:null,r.selection?"source":"preview")}catch(n){if(this.openRequest!==i||n.name==="AbortError")return;throw this.error="Unable to open view: "+n.message,n}finally{this.openRequest===i&&(this.openRequest=null,this.onChange(this))}}async select(t,e=null,s=null,i=!0){if(t==="board"&&!this.enableBoard||t!==null&&t!=="board"&&!this.views.some(r=>r.id===t))return;this.cancelOpen();let n=t===this.activeId?this.snapshot:null;this.contentRequest&&this.contentRequest.abort(),this.contentRequest=null,this.activeId=t,this.selection=e,this.displayMode=s,this.initialized||(this.initialSelection=t),this.snapshot=this.cache.get(t)||n,this.loading=t!==null&&t!=="board"&&!this.snapshot,this.error="",this.onChange(this),i&&this.onSelect(t),!(t===null||t==="board"||this.cache.has(t))&&await this.load(t)}setDisplayMode(t){!this.snapshot||this.activeId===null||this.activeId==="board"||!["source","preview"].includes(t)||(this.cancelOpen(),this.selection=null,this.displayMode=t,this.onChange(this))}async load(t){let e=new AbortController;this.contentRequest=e;try{let s=await this.request("api/views/"+encodeURIComponent(t),{signal:e.signal});if(this.contentRequest!==e||this.activeId!==t)return;let i=this.views.find(n=>n.id===t);if(!i||s.revision<i.revision)return;this.cache.set(t,s),this.snapshot=s,this.error=""}catch(s){if(this.contentRequest!==e||this.activeId!==t||s.name==="AbortError")return;this.error="Unable to load view: "+s.message}finally{this.contentRequest===e&&(this.contentRequest=null,this.loading=!1,this.onChange(this))}}async close(t){if(!(t===null||t==="board"||this.closing.has(t))){this.cancelOpen(),this.closing.add(t),this.mutation+=1,this.onChange(this);try{this.transcripts.has(t)?this.transcripts.delete(t):await this.request("api/views/"+encodeURIComponent(t),{method:"DELETE"}),this.mutation+=1;let e=this.views.findIndex(s=>s.id===t);this.views=this.views.filter(s=>s.id!==t),this.cache.delete(t),this.activeId===t&&await this.select(e>0?this.views[e-1].id:this.defaultId())}catch(e){this.error="Unable to close tab: "+e.message}finally{this.closing.delete(t),this.onChange(this)}}}};function m(l,t,e,s){let i=l.createElement(t);return i.className=e,s!==void 0&&(i.textContent=s),i}var B=class{constructor(t,e=[0,0]){this.document=t.ownerDocument,this.window=this.document.defaultView,this.position=e,this.generation=0,this.frame=m(this.document,"iframe","snapshot-html"),this.frame.title="HTML preview",this.receive=s=>{if(s.source!==this.frame.contentWindow)return;let i=s.data;!i||i.generation!==this.generation||(i.type==="workspace-preview-ready"?this.frame.contentWindow.postMessage({type:"workspace-preview-restore",generation:this.generation,position:this.position},"*"):i.type==="workspace-preview-scroll"&&Array.isArray(i.position)&&i.position.length===2&&i.position.every(Number.isFinite)&&(this.position=i.position))},this.window.addEventListener("message",this.receive),t.appendChild(this.frame)}update(t){if(t===this.source)return;let e=new this.window.DOMParser().parseFromString(t,"text/html"),s=this.generation+1,i=e.createElement("script");i.textContent=`(() => {
14
+ const generation = ${s};
15
+ let restored = false;
16
+ function report() {
17
+ if (restored) parent.postMessage({
18
+ type: "workspace-preview-scroll", generation, position: [scrollX, scrollY],
19
+ }, "*");
20
+ }
21
+ addEventListener("message", event => {
22
+ const message = event.data;
23
+ if (event.source !== parent || !message ||
24
+ message.type !== "workspace-preview-restore" || message.generation !== generation) return;
25
+ scrollTo(message.position[0], message.position[1]);
26
+ restored = true;
27
+ report();
28
+ });
29
+ addEventListener("scroll", report, {passive: true});
30
+ addEventListener("load", () => parent.postMessage({
31
+ type: "workspace-preview-ready", generation,
32
+ }, "*"));
33
+ })();`,e.head.prepend(i);let n=e.doctype?new this.window.XMLSerializer().serializeToString(e.doctype)+`
34
+ `:"";this.frame.srcdoc=n+e.documentElement.outerHTML,this.generation=s,this.source=t}capture(){return this.position}destroy(){this.window.removeEventListener("message",this.receive)}},z=class{constructor({content:t,renderMarkdown:e,loadEditor:s=null,onInsertContext:i=null,onChangeMode:n=null,request:r=null,createHtmlPreview:o=(h,a)=>new B(h,a)}){this.content=t,this.document=t.ownerDocument,this.renderMarkdown=e,this.request=r,this.transcripts=new Map,this.transcript=null,this.onInsertContext=i,this.onChangeMode=n,this.loadEditor=s||(()=>this.loadEditorAssets()),this.editorAssets=null,this.createHtmlPreview=o,this.activeId=null,this.editor=null,this.htmlPreview=null,this.pdfFrame=null,this.generation=0,this.remaining=new Set,this.editorStates=new Map,this.previews=new Map,this.scrollPositions=new Map,this.sourceViews=new Set,this.pendingSelection=null,this.selectionRevision=0}loadEditorAssets(){if(!this.editorAssets){let t=this.document.createElement("link");t.rel="stylesheet",t.href=new URL("./editor.css",import.meta.url).href;let e=new Promise((s,i)=>{t.addEventListener("load",s,{once:!0}),t.addEventListener("error",()=>i(new Error("Editor stylesheet request failed.")),{once:!0})});this.document.head.insertBefore(t,this.document.head.querySelector("[data-pycodex-custom-style]")),this.editorAssets=Promise.all([import("./editor.mjs"),e]).then(([s])=>s).catch(s=>{throw t.remove(),this.editorAssets=null,s})}return this.editorAssets}retain(t){this.remaining=new Set(t);for(let[e,s]of this.transcripts)this.remaining.has(e)||(s.stop(),this.transcripts.delete(e));for(let e of[this.editorStates,this.previews,this.scrollPositions,this.sourceViews])for(let s of e.keys())this.remaining.has(s)||e.delete(s)}clear(t=""){this.generation+=1,this.transcript&&(this.remaining.has(this.activeId)&&this.scrollPositions.set(this.activeId,[this.content.scrollLeft,this.content.scrollTop]),this.transcript.stop(),this.transcript=null),this.editor?(this.remaining.has(this.activeId)&&this.editorStates.set(this.activeId,this.editor.capture()),this.editor.destroy(),this.editor=null):this.htmlPreview?(this.remaining.has(this.activeId)&&this.scrollPositions.set(this.activeId,this.htmlPreview.capture()),this.htmlPreview.destroy(),this.htmlPreview=null):this.remaining.has(this.activeId)&&this.previews.has(this.activeId)&&this.scrollPositions.set(this.activeId,[this.content.scrollLeft,this.content.scrollTop]),this.activeId=null,this.pdfFrame=null,this.content.classList.remove("code-view"),this.content.classList.remove("html-view"),this.content.classList.remove("pdf-view","transcript-view"),this.content.textContent="",t&&this.content.appendChild(m(this.document,"div","content-placeholder",t))}addModeToggle(t,e,s=null){if(!this.onChangeMode)return;let i=m(this.document,"button","content-mode-toggle",e?"Show preview":"Show source");i.type="button",i.title=e?"Show rendered Markdown":"Show Markdown source",i.setAttribute("aria-label",i.textContent),i.addEventListener("click",()=>this.onChangeMode(e?"preview":"source")),t.insertBefore(i,s)}async show(t,e,s=null,i=null){if(e.kind==="transcript"){if(this.activeId===t&&this.transcript)return;this.clear(),this.activeId=t,this.content.classList.add("transcript-view"),this.transcripts.has(t)||this.transcripts.set(t,new T({viewport:this.content,request:this.request,renderMarkdown:this.renderMarkdown,sessionId:e.sessionId,agentId:e.agentId,agentPath:e.title})),this.transcript=this.transcripts.get(t),this.content.appendChild(this.transcript.root);let[f,w]=this.scrollPositions.get(t)||[0,0];this.content.scrollLeft=f,this.content.scrollTop=w,this.transcript.start();return}s&&e.revision<s.contentRevision&&(s=null),this.pendingSelection=s,i==="preview"?this.sourceViews.delete(t):(s||i==="source")&&this.sourceViews.add(t);let n=e.documents[0],r=e.kind==="file"&&!this.sourceViews.has(t),o=r&&/\.(md|markdown)$/i.test(n.label)&&this.renderMarkdown,h=r&&/\.html?$/i.test(n.label),a=e.kind==="file"&&n.media_type==="application/pdf",u=a?new URL(`../api/views/${encodeURIComponent(t)}/pdf?revision=${e.revision}`,import.meta.url).href:null;if(a&&n.error){this.clear(n.error);return}if(this.activeId===t&&this.pdfFrame&&a){this.pdfFrame.src!==u&&(this.pdfFrame.src=u);return}if(this.activeId===t&&this.htmlPreview&&h)return this.htmlPreview.update(n.text);if(this.activeId===t&&this.editor&&!o&&!h&&!a){let f=this.generation;try{await this.editor.update(e),f===this.generation&&await this.applySelection(t,s)}catch(w){if(f===this.generation)throw w}return}this.clear(),this.activeId=t;let d=this.generation;if(a){this.content.classList.add("pdf-view");let f=m(this.document,"div","snapshot-heading");f.appendChild(m(this.document,"span","snapshot-label",n.label));let w=m(this.document,"div","pdf-actions"),C=m(this.document,"a","content-mode-toggle","Open in new tab");C.href=u,C.target="_blank",C.rel="noopener";let c=m(this.document,"a","content-mode-toggle","Download");c.href=u+"&download=true",w.append(C,c),f.appendChild(w),this.pdfFrame=m(this.document,"iframe","snapshot-pdf"),this.pdfFrame.title="PDF preview: "+n.label,this.pdfFrame.src=u,this.content.append(f,this.pdfFrame);return}if(e.kind==="diff"||!n.image_url&&!o&&!h){this.content.classList.add("code-view"),this.content.appendChild(m(this.document,"div","content-placeholder","Loading code viewer\u2026"));try{let f=await this.loadEditor();if(d!==this.generation)return;this.content.textContent="";let w=m(this.document,"div","workspace-editor");this.content.appendChild(w);let C=this.onInsertContext&&(x=>{d===this.generation&&this.activeId===t&&this.onInsertContext(x)}),c=await f.createSnapshotEditor(w,e,this.editorStates.get(t),C);if(d!==this.generation){c.destroy();return}if(this.editor=c,this.onChangeMode&&this.renderMarkdown&&e.kind==="file"&&/\.(md|markdown)$/i.test(n.label)){let x=w.querySelector(".editor-toolbar"),S=x.querySelector(".editor-actions");x.insertBefore(m(this.document,"span","snapshot-stamp","Read only"),S),this.addModeToggle(x,!0,S)}}catch(f){if(d!==this.generation)return;this.content.textContent="",this.content.appendChild(m(this.document,"div","content-placeholder","Unable to load code viewer: "+f.message));return}await this.applySelection(t,s);return}if(h)return this.content.classList.add("html-view"),this.htmlPreview=this.createHtmlPreview(this.content,this.scrollPositions.get(t)),this.htmlPreview.update(n.text);if(!this.previews.has(t)){let f=m(this.document,"div","snapshot"),w=m(this.document,"div","snapshot-heading");if(w.appendChild(m(this.document,"span","snapshot-label",n.label)),w.appendChild(m(this.document,"span","snapshot-stamp","Read only")),o&&this.onChangeMode&&(w.classList.add("markdown-heading"),this.addModeToggle(w,!1)),f.appendChild(w),n.image_url){let C=m(this.document,"img","snapshot-image");C.alt=n.label,f.appendChild(C)}else f.appendChild(m(this.document,"div","snapshot-markdown markdown"));this.previews.set(t,f)}this.content.appendChild(this.previews.get(t));let b=this.content.querySelector(".snapshot-image");if(b&&b.src!==n.image_url&&(b.src=n.image_url),o){let f=this.content.querySelector(".snapshot-markdown");n.source&&f.setAttribute("data-src-path",n.source.path),this.renderMarkdown(f,n.text)}let[y,I]=this.scrollPositions.get(t)||[0,0];this.content.scrollLeft=y,this.content.scrollTop=I}async applySelection(t,e){if(!e||e.revision<=this.selectionRevision)return;let s=this.editor,i=()=>this.activeId===t&&this.editor===s&&this.pendingSelection===e&&e.revision>this.selectionRevision;i()&&await s.revealLine(e.document,e.line,i)&&(this.selectionRevision=e.revision)}};function nt({tabs:l,frame:t,content:e,status:s,request:i,renderMarkdown:n,onInsertContext:r,enableBoard:o=!0}){let h=l.ownerDocument,a=new z({content:e,renderMarkdown:n,onInsertContext:r,request:i,onChangeMode:c=>f.setDisplayMode(c)}),u,d=null,b=!1,y=null,I=null,f;function w(c){let x=h.getElementById("content-tab-"+c);x&&(x.focus({preventScroll:!0}),x.scrollIntoView({block:"nearest",inline:"nearest"}))}function C(c){let x=c.snapshot?c.snapshot.documents.map(p=>p.error):[];s.textContent=[c.error,...x].filter(Boolean).join("; ")||(c.openRequest?"Opening view\u2026":""),s.title=s.textContent,s.hidden=!s.textContent;let S=new Map(Array.from(l.children,p=>[p.dataset.viewId,p])),V=(o?[{id:"board",title:"Canvas",kind:"board"}]:[]).concat(c.views),M=j(c.views.filter(p=>p.kind!=="transcript"));for(let p of c.views)p.kind==="transcript"&&M.set(p.id,{name:p.title.split("/").pop(),description:"Transcript"});M.set("board",{name:"Canvas",description:""}),V.forEach((p,L)=>{let g=S.get(p.id);if(!g){g=m(h,"div","tab content-tab"),g.dataset.viewId=p.id,g.id="content-tab-"+p.id,g.setAttribute("role","tab"),g.setAttribute("aria-controls",p.id==="board"?t.id:e.id);let O=m(h,"span","tab-label content-tab-label");if(O.appendChild(m(h,"span","content-tab-name")),O.appendChild(m(h,"span","content-tab-description")),g.appendChild(O),g.addEventListener("click",()=>f.select(p.id)),g.addEventListener("keydown",v=>{if(v.target!==g)return;let k=(o?["board"]:[]).concat(f.views.map(F=>F.id)),U=k.indexOf(p.id),R=null;v.key==="ArrowRight"&&(R=k[(U+1)%k.length]),v.key==="ArrowLeft"&&(R=k[(U+k.length-1)%k.length]),v.key==="Home"&&(R=k[0]),v.key==="End"&&(R=k[k.length-1]),(v.key==="Enter"||v.key===" ")&&(R=p.id),v.key==="Delete"&&p.id!=="board"&&(v.preventDefault(),f.close(p.id)),R!==null&&(v.preventDefault(),f.select(R),h.getElementById("content-tab-"+R).focus())}),p.id!=="board"){let v=m(h,"button","tab-close content-tab-close");v.type="button",v.title="Close tab",v.setAttribute("aria-label","Close "+p.title),v.innerHTML='<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" aria-hidden="true"><path d="M4 4l8 8M12 4l-8 8"/></svg>',v.addEventListener("click",k=>{k.stopPropagation(),f.close(p.id)}),g.appendChild(v)}}S.delete(p.id);let N=M.get(p.id);g.querySelector(".content-tab-name").textContent=N.name;let J=g.querySelector(".content-tab-description");J.textContent=N.description,J.hidden=!N.description,g.className="tab content-tab"+(p.id===c.activeId?" active":""),g.tabIndex=p.id===c.activeId?0:-1,g.title=p.id==="board"?l.dataset.boardTitle:p.kind==="transcript"?`${p.title}
35
+ Agent transcript`:p.title+(p.live?`
36
+ Read only \xB7 follows file changes \xB7 `:`
37
+ Read-only snapshot \xB7 `)+new Date(p.created_at).toLocaleString(),g.setAttribute("aria-selected",String(p.id===c.activeId)),g.setAttribute("aria-label",p.title);let _=g.querySelector(".content-tab-close");_&&(_.disabled=c.closing.has(p.id),_.setAttribute("aria-label","Close "+p.title)),l.children[L]!==g&&l.insertBefore(g,l.children[L]||null)}),S.forEach(p=>p.remove()),a.retain(c.views.map(p=>p.id));let q=c.activeId==="board",$=u!==c.activeId||d!==c.snapshot||b!==c.loading||y!==c.selection||I!==c.displayMode;if(q&&$&&a.clear(),t.hidden=!q,e.hidden=q,!!$&&(u=c.activeId,d=c.snapshot,b=c.loading,y=c.selection,I=c.displayMode,c.activeId?e.setAttribute("aria-labelledby","content-tab-"+c.activeId):e.removeAttribute("aria-labelledby"),e.setAttribute("aria-busy",String(c.loading)),!q))if(c.snapshot){let p=c.activeId,L=c.snapshot;a.show(p,L,c.selection,c.displayMode).catch(g=>{u!==p||d!==L||(d=null,c.error="Unable to update view: "+g.message,s.textContent=s.title=c.error,s.hidden=!1)})}else a.clear(c.loading?"Loading view\u2026":c.activeId?"View unavailable.":"Open a file link to view it here.")}return f=new P({request:i,enableBoard:o,onChange:C,onSelect:c=>{e.closest(".workspace").dataset.mobilePane="board",w(c)}}),C(f),{start(){f.start(),C(f)},stop(){f.stop(),a.clear(),u=null},poll(){return f.poll()},open(c,x,S){return f.open(c,x,S)},openTranscript(c,x,S){return f.openTranscript(c,x,S)}}}export{E as Composer,P as ContentTabs,D as PromptHistory,z as SnapshotDisplay,st as isWorkspaceLink,nt as mountContentViews};
@@ -12,9 +12,7 @@ function transcriptBlocks(records) {
12
12
  for (const record of records) {
13
13
  const item = record.payload;
14
14
  const key = `record:${record.index}`;
15
- if (record.type === "compacted") {
16
- blocks.push({key, kind: "compaction", label: "Compaction", body: item.message});
17
- } else if (item.type === "function_call" || item.type === "custom_tool_call") {
15
+ if (item.type === "function_call" || item.type === "custom_tool_call") {
18
16
  const block = {
19
17
  key: `call:${item.call_id}`, kind: "tool", callId: item.call_id,
20
18
  toolName: item.name,
@@ -83,6 +81,7 @@ export class TranscriptView {
83
81
  this.agentId = agentId;
84
82
  this.records = new Map();
85
83
  this.source = null;
84
+ this.revision = null;
86
85
  this.nextCursor = null;
87
86
  this.agentSessionId = null;
88
87
  this.active = false;
@@ -247,17 +246,20 @@ export class TranscriptView {
247
246
  const lastIndex = previous.length ? previous[previous.length - 1].index : -1;
248
247
  let cursor = newest.next_cursor;
249
248
  // A burst can exceed one page; fill the gap before merging with loaded history.
250
- if (!older && !reset && this.source === newest.source && previous.length) {
249
+ const replaced = this.source !== newest.source || this.revision !== newest.revision;
250
+ if (!older && !reset && !replaced && previous.length) {
251
251
  while (records.length && records[0].index > lastIndex && cursor !== null) {
252
252
  const earlier = await page(cursor);
253
- if (earlier.source !== newest.source) throw Object.assign(new Error("History changed"), {status: 409});
253
+ if (earlier.source !== newest.source || earlier.revision !== newest.revision) {
254
+ throw Object.assign(new Error("History changed"), {status: 409});
255
+ }
254
256
  records = earlier.items.concat(records);
255
257
  cursor = earlier.next_cursor;
256
258
  }
257
259
  }
258
260
  if (this.requestController !== controller) return;
259
261
  const overlap = records.filter(item => this.records.has(item.index));
260
- const changed = reset || this.source !== newest.source || (!older && previous.length && (
262
+ const changed = reset || replaced || (!older && previous.length && (
261
263
  !overlap.length || overlap.some(item =>
262
264
  JSON.stringify(item) !== JSON.stringify(this.records.get(item.index)))
263
265
  ));
@@ -269,6 +271,7 @@ export class TranscriptView {
269
271
  this.records = new Map(Array.from(this.records).sort((left, right) => left[0] - right[0]));
270
272
  if (older || changed || !previous.length) this.nextCursor = newest.next_cursor;
271
273
  this.source = newest.source;
274
+ this.revision = newest.revision;
272
275
  this.showError("");
273
276
  this.render();
274
277
  } catch (error) {
@@ -296,7 +299,7 @@ export class TranscriptView {
296
299
  node.dataset.key = block.key;
297
300
  node.dataset.kind = block.kind;
298
301
  if (block.toolName) node.dataset.tool = block.toolName;
299
- node.open = block.kind !== "reasoning" && block.kind !== "compaction";
302
+ node.open = block.kind !== "reasoning";
300
303
  const heading = this.element("summary", "transcript-marker");
301
304
  const line = this.element("span", "transcript-marker-line");
302
305
  const label = this.element("span", "transcript-label");
@@ -17,6 +17,7 @@ space. Request failures remain visible; reasoning records need readable text.
17
17
  | clock-ticks | [Clock tick dividers](clock-ticks/README.md) | Quiet timestamped dividers for periodic wake-ups, with expandable trigger details. | Chromium history/live updates, preserved source, session switching, keyboard/mobile and cleanup; synthetic preview |
18
18
  | consecutive-tool-groups | [Consecutive tool groups](consecutive-tool-groups/README.md) | One expandable conversation row for a run of tool calls, with running/failure counts. | Chromium fixtures, live updates, refresh, keyboard/mobile and cleanup; adapter supplied by the frontend |
19
19
  | exec-status | [Exec status](exec-status/README.md) | Running and exited command sessions above the composer. | Chromium fixtures, lifecycle, desktop/mobile; live processes not tested |
20
+ | file-attachments | [File attachments](file-attachments/README.md) | Select, paste or drop local files with previews, per-file retry and a send guard during reads. | Node queue/encoding/capacity/session checks; Chromium Composer fixtures, preview cleanup and mobile layout; no live model calls |
20
21
  | reasoning-display | [Recorded reasoning](reasoning-display/README.md) | Readable recorded reasoning summaries and text. | Chromium fixtures, opaque filtering, desktop/mobile; live model not tested |
21
22
  | session-tips | [Session tips](session-tips/README.md) | Browser-local per-conversation notes in a compact corner card. | Chromium fixtures, session/rollout isolation, refresh, storage failures and desktop/mobile; synthetic sessions |
22
23
  | skill-completion | [Skill completion](skill-completion/README.md) | Optional @/$ skill dropdown with prefix filtering, keyboard selection and customizable catalogs. | Chromium default-off, keyboard/click/touch, undo/chips, stale results, custom catalogs and cleanup; Node prefix checks |
@@ -0,0 +1,137 @@
1
+ ---
2
+ title: "File attachments"
3
+ summary: "Preview, remove and retry local files in the composer before sending their contents with a message."
4
+ tags: [attachments, composer, files]
5
+ ---
6
+
7
+ # File attachments
8
+
9
+ ## Behavior
10
+
11
+ Select several files, paste a file, or drop files onto the composer. Each file
12
+ gets a card showing its path, size and state. Text opens in a plain-text dialog;
13
+ PNG, JPEG, GIF and WebP files have local thumbnails and an image preview.
14
+ Folder selection preserves relative paths and skips `.git`, `node_modules`,
15
+ `.venv` and `__pycache__`. Dropped directories use the folder-picker entry.
16
+
17
+ For example, selecting a readable source file, an oversized file and a file
18
+ that cannot be read produces a ready card and two independent error cards.
19
+ The readable file stays in the draft. Read/capacity errors can be retried or
20
+ removed, and cancelling leaves previously completed files in place.
21
+ Both the send action and Enter wait for unfinished reads; completion does not
22
+ send automatically. Failed files are clearly marked as excluded from sending.
23
+
24
+ This supplies a client attachment flow where the built-in page has no local
25
+ file picker. Text or base64 content enters ordinary context tokens in the
26
+ current draft and travels with the user's next message.
27
+
28
+ ## Source
29
+
30
+ - [custom.js](source/custom.js) mounts the feature through the built-in host.
31
+ - [uploads.mjs](source/uploads.mjs) owns the picker, cards, preview dialog,
32
+ input events, send guard, draft observation and resource cleanup.
33
+ - [upload_core.mjs](source/upload_core.mjs) owns encoding, queueing,
34
+ deduplication, capacity checks, retries and session isolation.
35
+ - [custom.css](source/custom.css) contains scoped styles using the workspace
36
+ palette, including a narrow-screen layout.
37
+ - [upload_core.test.mjs](source/upload_core.test.mjs) checks queue and draft
38
+ behavior with controlled FileReader completion.
39
+ - [upload_browser.py](source/upload_browser.py) checks the real Composer and
40
+ supplied sources in Chromium with local fixtures.
41
+
42
+ The UI takes inspiration from [Atrium](https://github.com/yuangpeng/atrium)'s
43
+ `web/src/chat/Composer.tsx`. The implementation uses the existing draft host
44
+ and does not require React, Atrium, an SDK or generated dependency bundles.
45
+
46
+ ## Integration
47
+
48
+ Requires built-in page host API version 1: `getActiveSessionId`,
49
+ `onSessionChanged`, `getDraft` and `setDraft`. The DOM assumptions are
50
+ `#composer`, `.composer-surface`, `#prompt` and `#contextBlockDetail`.
51
+ Browser prerequisites are ES modules, FileReader, TextDecoder, Web Crypto,
52
+ MutationObserver and a native HTML dialog. Folder selection is exposed only
53
+ when the browser supports `webkitdirectory`.
54
+
55
+ 1. Copy the two `.mjs` runtime modules into your configured frontend directory.
56
+ 2. With no existing JavaScript customization, use the supplied `custom.js`.
57
+ With an existing `mount(host)`, import `mountUploads` and call it there;
58
+ retain other initialization and call its returned disposer on teardown.
59
+ 3. Append the scoped rules from `custom.css` to your existing customization CSS.
60
+ 4. Refresh, select two small files, inspect a card and remove one, then send
61
+ the remaining file through the ordinary composer.
62
+
63
+ Undo by removing the mount call and scoped CSS rules, then refreshing. Preserve
64
+ other customizations and any draft you want to keep. Supporting modules do not
65
+ run without being imported. Removing this UI does not remove context tokens
66
+ already stored in the draft; those can still be removed using the composer.
67
+
68
+ The queue re-reads the latest draft before each commit, preserving typing,
69
+ other context and selection. Cards derive from the draft, so native token
70
+ deletion or draft replacement updates the shelf. An epoch rejects a picker
71
+ opened before switching A → B → A. Session changes, pagehide and disposal abort
72
+ pending reads, discard temporary File references and revoke preview URLs.
73
+
74
+ ## Validation
75
+
76
+ Using Node 22, run from the repository root:
77
+
78
+ ```bash
79
+ node packages/pycodex-ws/workspace_server/optional_features/file-attachments/source/upload_core.test.mjs
80
+ ```
81
+
82
+ Ten behavior groups pass: UTF-8/BOM UTF-16/binary encoding, legacy tokens,
83
+ typing and selection during reads, isolated failure and retry, deduplication,
84
+ folder exclusions, cancelled/removed reads, session epochs, encoded message
85
+ and serialized draft limits, file count, draft roundtrips and raster filtering.
86
+
87
+ The manual DOM check needs Python's `httpx` and `websockets` (use the repository's
88
+ dev environment) and an existing Chromium executable. It downloads nothing.
89
+ Output must be a new canonical directory on a writable JuiceFS mount; the
90
+ writer verifies mount identity, capacity, inodes and permissions before creating
91
+ the profile, cache, log, HTML fixture and result JSON.
92
+
93
+ ```bash
94
+ python packages/pycodex-ws/workspace_server/optional_features/file-attachments/source/upload_browser.py \
95
+ --output "$ATTACHMENT_CHECK_OUTPUT" \
96
+ --mount-source "$ATTACHMENT_CHECK_MOUNT_SOURCE" \
97
+ --chrome "$ATTACHMENT_CHECK_CHROME"
98
+ ```
99
+
100
+ Twenty-seven Chromium DOM checks pass. The fixture exercises initial mounting, Enter/button send guards, completed
101
+ and failed cards, editing during reads, plain-text escaping, mixed paste,
102
+ drop, retry, cancellation, draft restoration, session switches, stale pickers,
103
+ image decoding, URL release, native token deletion, one ordinary send,
104
+ narrow-screen overflow and teardown. It uses the real Composer and feature
105
+ sources. Its draft store and sender are in-memory fixtures; it makes no model
106
+ or production API requests. The result JSON lists each observed check.
107
+
108
+ Source syntax and whitespace checks accompany these behavior checks.
109
+ Actual cross-browser behavior, production model interpretation and server
110
+ reconnection were not checked: the feature has no server request or WS stream,
111
+ and these checks intentionally use local fixtures.
112
+
113
+ ## Preview
114
+
115
+ No screenshot is included. Expect a compact paperclip/folder toolbar beneath
116
+ the editor and a scrollable shelf of file cards. Ready cards show a file icon
117
+ or image thumbnail and a remove button; failures show an explanation and a
118
+ retry button when recovery is possible. A modal displays text or a raster image.
119
+
120
+ ## Limitations
121
+
122
+ - This is readable reference source for customization, with Chinese UI labels.
123
+ Adapt labels, DOM selectors and styling when integrating a different page.
124
+ - Each file is at most 256 KiB; one message has at most 32 attachments and
125
+ 512 KiB of original file bytes. Encoded message text is at most 160,000
126
+ characters, the serialized UTF-8 draft at most 512 KiB, and the draft at most
127
+ 500 parts. All limits include existing draft content. The pending/error queue
128
+ holds at most 64 entries. Larger files need splitting or another workflow.
129
+ - Binary attachments travel as base64 text. Raster previews stay in the browser;
130
+ they do not create native model image inputs. There is no server upload API,
131
+ server file staging or executable HTML/SVG preview.
132
+ - Completed attachments use the host's draft lifecycle. Persistence after a
133
+ page reload depends on the integrating frontend's draft storage; unfinished
134
+ reads and retry File objects are never persisted.
135
+ - Files are appended through `setDraft`, so the host determines undo behavior.
136
+ The context editor can alter an attachment's serialized content; malformed
137
+ tokens remain removable but have no parsed preview.
@@ -0,0 +1,189 @@
1
+ /* Local attachment shelf, using the workspace palette and composer layout. */
2
+ .pycodex-file-upload {
3
+ position: relative;
4
+ min-width: 0;
5
+ border-top: 1px solid var(--line, #dce4e8);
6
+ color: var(--ink, #18303e);
7
+ }
8
+ .pycodex-file-upload [hidden] { display: none !important; }
9
+ .pycodex-upload-toolbar {
10
+ display: flex;
11
+ align-items: center;
12
+ flex-wrap: wrap;
13
+ gap: 4px 8px;
14
+ padding: 5px 9px;
15
+ min-width: 0;
16
+ }
17
+ .pycodex-file-upload .pycodex-upload-button {
18
+ display: inline-flex;
19
+ align-items: center;
20
+ justify-content: center;
21
+ gap: 5px;
22
+ flex: 0 0 auto;
23
+ min-height: 32px;
24
+ padding: 4px 7px;
25
+ border: 0;
26
+ border-radius: 7px;
27
+ background: transparent;
28
+ color: var(--muted, #60727e);
29
+ font: inherit;
30
+ font-size: 12px;
31
+ cursor: pointer;
32
+ }
33
+ .pycodex-file-upload .pycodex-upload-button:hover {
34
+ background: var(--panel-hover, #edf3f5);
35
+ color: var(--ink, #18303e);
36
+ }
37
+ .pycodex-file-upload button:focus-visible,
38
+ .pycodex-upload-help summary:focus-visible {
39
+ outline: 2px solid var(--accent, #087f9a);
40
+ outline-offset: 2px;
41
+ }
42
+ .pycodex-file-upload button:disabled { cursor: default; }
43
+ .pycodex-upload-toolbar button:disabled { opacity: .5; }
44
+ .pycodex-file-upload svg { width: 17px; height: 17px; flex: 0 0 auto; }
45
+ .pycodex-upload-status {
46
+ flex: 1 1 160px;
47
+ min-width: 0;
48
+ color: var(--muted, #60727e);
49
+ font-size: 11px;
50
+ line-height: 1.5;
51
+ overflow-wrap: anywhere;
52
+ }
53
+ .pycodex-upload-status[data-state="error"] { color: var(--danger, #b42318); }
54
+ .pycodex-attachment-tray {
55
+ display: grid;
56
+ grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
57
+ gap: 6px;
58
+ max-height: 168px;
59
+ overflow: auto;
60
+ overscroll-behavior: contain;
61
+ padding: 8px 10px 3px;
62
+ margin: 0;
63
+ list-style: none;
64
+ }
65
+ .pycodex-attachment {
66
+ position: relative;
67
+ display: flex;
68
+ align-items: center;
69
+ gap: 2px;
70
+ min-width: 0;
71
+ min-height: 54px;
72
+ padding: 3px 5px;
73
+ border: 1px solid var(--line, #dce4e8);
74
+ border-radius: 9px;
75
+ background: var(--panel, #f7fafb);
76
+ }
77
+ .pycodex-attachment[data-state="error"] { border-color: var(--danger, #b42318); }
78
+ .pycodex-file-upload .pycodex-attachment-open {
79
+ display: flex;
80
+ align-items: center;
81
+ gap: 8px;
82
+ flex: 1 1 auto;
83
+ min-width: 0;
84
+ padding: 4px;
85
+ border: 0;
86
+ border-radius: 6px;
87
+ background: transparent;
88
+ color: inherit;
89
+ text-align: left;
90
+ font: inherit;
91
+ cursor: pointer;
92
+ }
93
+ .pycodex-attachment-open:enabled:hover { background: var(--panel-hover, #edf3f5); }
94
+ .pycodex-attachment-visual {
95
+ display: grid;
96
+ place-items: center;
97
+ flex: 0 0 34px;
98
+ width: 34px;
99
+ height: 34px;
100
+ overflow: hidden;
101
+ border-radius: 5px;
102
+ color: var(--muted, #60727e);
103
+ background: var(--bg, #fff);
104
+ }
105
+ .pycodex-attachment-visual img { display: block; width: 100%; height: 100%; object-fit: cover; }
106
+ .pycodex-attachment-info { display: block; min-width: 0; }
107
+ .pycodex-attachment-name {
108
+ display: block;
109
+ overflow: hidden;
110
+ text-overflow: ellipsis;
111
+ white-space: nowrap;
112
+ font-size: 12px;
113
+ font-weight: 500;
114
+ }
115
+ .pycodex-attachment-detail {
116
+ display: block;
117
+ color: var(--muted, #60727e);
118
+ font-size: 10px;
119
+ line-height: 1.5;
120
+ overflow-wrap: anywhere;
121
+ }
122
+ .pycodex-attachment[data-state="error"] .pycodex-attachment-detail { color: var(--danger, #b42318); }
123
+ .pycodex-file-upload .pycodex-attachment-remove { padding: 4px; }
124
+ .pycodex-attachment-progress {
125
+ position: absolute;
126
+ left: 7px;
127
+ bottom: 0;
128
+ width: calc(100% - 14px);
129
+ height: 3px;
130
+ border: 0;
131
+ accent-color: var(--accent, #087f9a);
132
+ }
133
+ .pycodex-upload-help { position: relative; flex: 0 0 auto; font-size: 11px; color: var(--muted, #60727e); }
134
+ .pycodex-upload-help summary { cursor: pointer; padding: 7px 2px; }
135
+ .pycodex-upload-help > div {
136
+ position: absolute;
137
+ bottom: calc(100% + 8px);
138
+ right: 0;
139
+ z-index: 20;
140
+ width: min(290px, calc(100vw - 40px));
141
+ padding: 12px;
142
+ border: 1px solid var(--line, #dce4e8);
143
+ border-radius: 9px;
144
+ background: var(--bg, #fff);
145
+ box-shadow: 0 4px 20px #0002;
146
+ font-size: 12px;
147
+ line-height: 1.7;
148
+ }
149
+ .pycodex-upload-drop-hint { display: none; }
150
+ .pycodex-upload-drag .composer-surface { outline: 2px dashed var(--accent, #087f9a); outline-offset: 3px; }
151
+ .pycodex-upload-drag .pycodex-upload-drop-hint {
152
+ display: grid;
153
+ position: absolute;
154
+ inset: 0;
155
+ z-index: 15;
156
+ place-items: center;
157
+ border-radius: 8px;
158
+ background: var(--bg, #fff);
159
+ opacity: .95;
160
+ color: var(--accent, #087f9a);
161
+ font-size: 13px;
162
+ pointer-events: none;
163
+ }
164
+ .pycodex-upload-preview {
165
+ width: min(800px, calc(100vw - 32px));
166
+ max-height: min(80vh, 800px);
167
+ padding: 0;
168
+ border: 1px solid var(--line, #dce4e8);
169
+ border-radius: 12px;
170
+ background: var(--bg, #fff);
171
+ color: var(--ink, #18303e);
172
+ box-shadow: 0 12px 60px #0004;
173
+ }
174
+ .pycodex-upload-preview::backdrop { background: #0006; }
175
+ .pycodex-upload-preview-heading { display: flex; align-items: center; gap: 12px; padding: 12px 16px 4px; }
176
+ .pycodex-upload-preview-heading h2 { flex: 1; min-width: 0; margin: 0; font-size: 15px; overflow-wrap: anywhere; }
177
+ .pycodex-upload-preview-meta { margin: 0; padding: 0 16px 12px; font-size: 12px; color: var(--muted, #60727e); }
178
+ .pycodex-upload-preview-body { padding: 16px; border-top: 1px solid var(--line, #dce4e8); }
179
+ .pycodex-upload-preview-body img { display: block; max-width: 100%; max-height: 60vh; object-fit: contain; margin: auto; }
180
+ .pycodex-upload-preview-body pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/1.65 ui-monospace, monospace; }
181
+ .pycodex-upload-preview-body p { margin: 0; font-size: 13px; line-height: 1.6; }
182
+ @media (max-width: 640px) {
183
+ .pycodex-upload-toolbar { gap: 3px 5px; }
184
+ .pycodex-file-upload .pycodex-upload-button { min-width: 40px; min-height: 40px; }
185
+ .pycodex-file-upload .pycodex-attachment-remove { min-width: 40px; }
186
+ .pycodex-upload-status { flex-basis: 100%; order: 2; padding: 0 4px 2px; }
187
+ .pycodex-upload-help { margin-left: auto; }
188
+ .pycodex-attachment-tray { grid-template-columns: 1fr; max-height: 150px; }
189
+ }
@@ -0,0 +1,5 @@
1
+ import {mountUploads} from "./uploads.mjs";
2
+
3
+ export function mount(host) {
4
+ return mountUploads(host);
5
+ }