arco-workbench 0.1.8 → 0.1.9
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/CONTRIBUTING.md +11 -0
- package/README.md +7 -5
- package/client/dist/assets/{PhosphorBackdrop-D7jdAV_G.js → PhosphorBackdrop-DRu16-Is.js} +1 -1
- package/client/dist/assets/{ThemedBackgroundShaderImpl-DrDm60h8.js → ThemedBackgroundShaderImpl-BLdwwQ4D.js} +1 -1
- package/client/dist/assets/{XtermView-BGFujb1e.js → XtermView-Xk7_9JaH.js} +1 -1
- package/client/dist/assets/{galleryEditor-D951A2sE.js → galleryEditor-CI8ClzBa.js} +1 -1
- package/client/dist/assets/{index-DD9kFGsF.css → index-BEFgrUJJ.css} +1 -1
- package/client/dist/assets/{index-CsVy3eZm.js → index-C7WzZfsr.js} +246 -244
- package/client/dist/index.html +2 -2
- package/client/src/App.tsx +2 -0
- package/client/src/components/ChatMessage.tsx +33 -8
- package/client/src/components/ChatModeView.tsx +2 -0
- package/client/src/components/ClusterRightPanel/SkillsControl.tsx +25 -8
- package/client/src/components/CodexLateCommand.tsx +34 -0
- package/client/src/components/DialogShell.tsx +2 -0
- package/client/src/components/MemberCard.tsx +4 -1
- package/client/src/components/MemberPane.tsx +3 -1
- package/client/src/components/PhoneUpload.tsx +288 -0
- package/client/src/components/PrimaryStatus.tsx +14 -6
- package/client/src/components/RuntimeStateBanner.tsx +5 -0
- package/client/src/components/SkillEditorDialog.tsx +2 -2
- package/client/src/components/SkillsSettings.tsx +17 -5
- package/client/src/components/TerminalInput.tsx +3 -1
- package/client/src/components/WorkflowView.tsx +2 -0
- package/client/src/explorer/ArtifactsLens.tsx +37 -28
- package/client/src/explorer/ExplorerApp.tsx +5 -4
- package/client/src/explorer/types.ts +8 -3
- package/client/src/help/content/cluster.tsx +11 -1
- package/client/src/help/content/composer.tsx +18 -1
- package/client/src/help/content/header.tsx +2 -1
- package/client/src/help/content/misc.tsx +1 -1
- package/client/src/help/content/settings.tsx +1 -1
- package/client/src/help/manualSections/clusters.tsx +3 -0
- package/client/src/help/manualSections/configuration.tsx +3 -1
- package/client/src/help/manualSections/gettingStarted.tsx +4 -4
- package/client/src/help/manualSections/maintenance.tsx +7 -6
- package/client/src/help/manualSections/powerFeatures.tsx +3 -2
- package/client/src/help/manualSections/workspace.tsx +30 -0
- package/client/src/stores/appStore.ts +7 -0
- package/client/src/stores/appStore.types.ts +4 -0
- package/client/src/styles/global.css +109 -0
- package/client/src/utils/phoneTheme.ts +38 -0
- package/client/src/utils/phoneUploadApi.ts +10 -0
- package/client/src/ws/handleServerMessage.ts +23 -6
- package/docs/CLIENT.md +7 -1
- package/docs/FEATURES.md +6 -3
- package/docs/GETTING_STARTED.md +8 -3
- package/docs/INDEX.md +1 -1
- package/docs/OPERATIONS.md +199 -48
- package/docs/PROTOCOL_CLUSTER.md +9 -1
- package/docs/PROVIDERS.md +34 -0
- package/docs/SETTINGS.md +5 -3
- package/native/darwin-arm64/manifest.json +1 -1
- package/native/linux-x64/manifest.json +1 -1
- package/native/win32-x64/manifest.json +1 -1
- package/node_modules/@arco/shared/dist/protocol/chat.d.ts +1 -0
- package/node_modules/@arco/shared/dist/protocol/clusters.d.ts +2 -0
- package/node_modules/@arco/shared/dist/protocol/serverMessages.d.ts +11 -0
- package/node_modules/@arco/shared/dist/protocol/workflows.d.ts +1 -0
- package/node_modules/@arco/shared/package.json +1 -1
- package/package.json +2 -2
- package/server/dist/clusterDirector.js +1 -0
- package/server/dist/clusterPeerOps.js +4 -1
- package/server/dist/clusterRehydrate.js +2 -0
- package/server/dist/explorerDocs.d.ts +10 -6
- package/server/dist/explorerDocs.js +75 -34
- package/server/dist/http/attachmentUpload.d.ts +13 -0
- package/server/dist/http/attachmentUpload.js +38 -0
- package/server/dist/http/browserWorktrees.d.ts +23 -0
- package/server/dist/http/browserWorktrees.js +120 -0
- package/server/dist/http/phoneUploadDrafts.d.ts +13 -0
- package/server/dist/http/phoneUploadDrafts.js +125 -0
- package/server/dist/http/phoneUploadListener.d.ts +17 -0
- package/server/dist/http/phoneUploadListener.js +81 -0
- package/server/dist/http/phoneUploadNetwork.d.ts +9 -0
- package/server/dist/http/phoneUploadNetwork.js +106 -0
- package/server/dist/http/phoneUploadPage.d.ts +2 -0
- package/server/dist/http/phoneUploadPage.js +136 -0
- package/server/dist/http/phoneUploadRouteHistory.d.ts +4 -0
- package/server/dist/http/phoneUploadRouteHistory.js +72 -0
- package/server/dist/http/phoneUploadRoutes.d.ts +4 -0
- package/server/dist/http/phoneUploadRoutes.js +419 -0
- package/server/dist/http/phoneUploadTheme.d.ts +17 -0
- package/server/dist/http/phoneUploadTheme.js +96 -0
- package/server/dist/http/projectBinding.d.ts +1 -0
- package/server/dist/http/projectBinding.js +3 -2
- package/server/dist/http/readConfinement.js +5 -1
- package/server/dist/http/router.js +13 -24
- package/server/dist/http/writeConfinement.js +19 -2
- package/server/dist/primitives/seedWorker.d.ts +1 -0
- package/server/dist/primitives/seedWorker.js +2 -1
- package/server/dist/providers/codex-appserver/heldCommands.d.ts +14 -0
- package/server/dist/providers/codex-appserver/heldCommands.js +54 -0
- package/server/dist/providers/codex-appserver/index.d.ts +52 -2
- package/server/dist/providers/codex-appserver/index.js +239 -21
- package/server/dist/providers/codex-appserver/lateCommands.d.ts +62 -0
- package/server/dist/providers/codex-appserver/lateCommands.js +195 -0
- package/server/dist/providers/codex-appserver/worker.d.ts +23 -1
- package/server/dist/providers/codex-appserver/worker.js +89 -20
- package/server/dist/providers/codex.js +2 -2
- package/server/dist/providers/codexCodeMode.d.ts +2 -1
- package/server/dist/providers/codexCodeMode.js +7 -3
- package/server/dist/workers/WorkerManager.d.ts +1 -0
- package/server/dist/workers/WorkerManager.js +1 -0
- package/server/dist/workers/processKill.d.ts +9 -1
- package/server/dist/workers/processKill.js +26 -10
- package/server/dist/ws/handoffHandlers.js +2 -0
- package/server/dist/ws/turnEngine.js +17 -0
- package/server/package.json +1 -1
- package/server/src/clusterDirector.ts +1 -0
- package/server/src/clusterPeerOps.ts +4 -1
- package/server/src/clusterRehydrate.ts +2 -0
- package/server/src/explorerDocs.ts +75 -34
- package/server/src/http/attachmentUpload.ts +49 -0
- package/server/src/http/browserWorktrees.ts +124 -0
- package/server/src/http/phoneUploadDrafts.ts +118 -0
- package/server/src/http/phoneUploadListener.ts +96 -0
- package/server/src/http/phoneUploadNetwork.ts +117 -0
- package/server/src/http/phoneUploadPage.ts +137 -0
- package/server/src/http/phoneUploadRouteHistory.ts +73 -0
- package/server/src/http/phoneUploadRoutes.ts +398 -0
- package/server/src/http/phoneUploadTheme.ts +97 -0
- package/server/src/http/projectBinding.ts +3 -2
- package/server/src/http/readConfinement.ts +5 -1
- package/server/src/http/router.ts +11 -25
- package/server/src/http/writeConfinement.ts +13 -2
- package/server/src/primitives/seedWorker.ts +3 -1
- package/server/src/providers/codex-appserver/heldCommands.ts +58 -0
- package/server/src/providers/codex-appserver/index.ts +222 -20
- package/server/src/providers/codex-appserver/lateCommands.ts +225 -0
- package/server/src/providers/codex-appserver/worker.ts +85 -21
- package/server/src/providers/codex.ts +2 -2
- package/server/src/providers/codexCodeMode.ts +8 -3
- package/server/src/workers/WorkerManager.ts +2 -0
- package/server/src/workers/processKill.ts +35 -7
- package/server/src/ws/handoffHandlers.ts +2 -0
- package/server/src/ws/turnEngine.ts +15 -0
- package/shared/dist/protocol/chat.d.ts +1 -0
- package/shared/dist/protocol/clusters.d.ts +2 -0
- package/shared/dist/protocol/serverMessages.d.ts +11 -0
- package/shared/dist/protocol/workflows.d.ts +1 -0
- package/shared/src/protocol/chat.ts +1 -0
- package/shared/src/protocol/clusters.ts +4 -5
- package/shared/src/protocol/serverMessages.ts +11 -0
- package/shared/src/protocol/workflows.ts +4 -0
package/client/dist/index.html
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
10
10
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
11
11
|
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;700&family=Share+Tech+Mono&display=swap" rel="stylesheet" />
|
|
12
|
-
<script type="module" crossorigin src="/assets/index-
|
|
13
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
12
|
+
<script type="module" crossorigin src="/assets/index-C7WzZfsr.js"></script>
|
|
13
|
+
<link rel="stylesheet" crossorigin href="/assets/index-BEFgrUJJ.css">
|
|
14
14
|
</head>
|
|
15
15
|
<body>
|
|
16
16
|
<div id="root"></div>
|
package/client/src/App.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PhoneUploadWindow } from './components/PhoneUpload';
|
|
1
2
|
import { memberReviewScopeSupported, MEMBER_REVIEW_SCOPE_REASON } from './utils/memberReviewScope';
|
|
2
3
|
import { requestVoicePanel } from './voice/panels';
|
|
3
4
|
import { CatchMeUp } from './components/CatchMeUp';
|
|
@@ -637,6 +638,7 @@ ${scopeBody}
|
|
|
637
638
|
}}
|
|
638
639
|
>
|
|
639
640
|
<ThemedBackgroundShader />
|
|
641
|
+
<PhoneUploadWindow />
|
|
640
642
|
|
|
641
643
|
<div
|
|
642
644
|
style={{
|
|
@@ -4,7 +4,7 @@ import { OperatorQuestionNotice } from './OperatorQuestionNotice';
|
|
|
4
4
|
import { useMessageSelectionStore } from '../stores/messageSelectionStore';
|
|
5
5
|
import { memo, useMemo, useRef, useState } from 'react';
|
|
6
6
|
import { useAppStore, type ClusterMemberLabel } from '../stores/appStore';
|
|
7
|
-
import ReactMarkdown, { type Components } from 'react-markdown';
|
|
7
|
+
import ReactMarkdown, { defaultUrlTransform, type Components } from 'react-markdown';
|
|
8
8
|
import remarkGfm from 'remark-gfm';
|
|
9
9
|
import rehypeHighlight from 'rehype-highlight';
|
|
10
10
|
import type { ChatMessage as ChatMessageType } from '@arco/shared';
|
|
@@ -26,6 +26,7 @@ export type { WrittenFilesIndex };
|
|
|
26
26
|
import { useOperatorLabel } from '../utils/operatorLabel';
|
|
27
27
|
import { useTerminalStore } from '../stores/terminalStore';
|
|
28
28
|
import { detectCommand } from './Terminal/detectCommand';
|
|
29
|
+
import { DialogShell } from './DialogShell';
|
|
29
30
|
|
|
30
31
|
// Thresholds above which an operator message auto-collapses into a pill.
|
|
31
32
|
// Either dimension triggers — a single 2000-char paragraph is as intrusive
|
|
@@ -89,6 +90,11 @@ function hasMarkdownFileRef(text: string): boolean {
|
|
|
89
90
|
return MARKDOWN_FILE_REF_RE.test(text);
|
|
90
91
|
}
|
|
91
92
|
|
|
93
|
+
// A Windows drive path in a Markdown link is a local viewer target.
|
|
94
|
+
function chatMarkdownUrl(url: string, key: string): string {
|
|
95
|
+
return key === 'href' && /^[A-Za-z]:[\\/]/.test(url) ? url : defaultUrlTransform(url);
|
|
96
|
+
}
|
|
97
|
+
|
|
92
98
|
// Extract pure text from a ReactMarkdown children prop. Markdown headings /
|
|
93
99
|
// inline-code may pass children as a string, an array of strings, or wrapped
|
|
94
100
|
// elements (when the heading itself contains nested formatting). We only
|
|
@@ -404,7 +410,7 @@ function ChatMessageInner({ message, jobId, jobCwd, writtenFiles, onCancelQueued
|
|
|
404
410
|
const renderSystemMarkdown = isSystem && hasMarkdownFileRef(displayContent);
|
|
405
411
|
|
|
406
412
|
// Filename auto-link: any markdown heading / inline `code` / `[link]` / image
|
|
407
|
-
// whose text resolves to a file
|
|
413
|
+
// whose text resolves to a project file opens FileViewerModal.
|
|
408
414
|
// State + modal live at message scope so each bubble owns its own viewer.
|
|
409
415
|
const [viewerPath, setViewerPath] = useState<string | null>(null);
|
|
410
416
|
// Shared mousedown coords for all FileLink spans in this bubble. A useRef
|
|
@@ -479,7 +485,10 @@ function ChatMessageInner({ message, jobId, jobCwd, writtenFiles, onCancelQueued
|
|
|
479
485
|
<CopyablePre {...props} workflowId={jobId}>{children}</CopyablePre>
|
|
480
486
|
),
|
|
481
487
|
a: ({ node: _node, href, children, ...props }) => {
|
|
482
|
-
|
|
488
|
+
let target = href;
|
|
489
|
+
// Markdown encodes local URL characters, including spaces in a checkout name.
|
|
490
|
+
try { if (href) target = decodeURIComponent(href); } catch { /* keep the original spelling */ }
|
|
491
|
+
const resolved = target ? resolveChatFilePath(target, jobCwd, writtenFiles) : null;
|
|
483
492
|
if (resolved) return <FileLink filePath={resolved}>{children}</FileLink>;
|
|
484
493
|
return <a {...props} href={href} target="_blank" rel="noopener noreferrer">{children}</a>;
|
|
485
494
|
},
|
|
@@ -678,6 +687,7 @@ function ChatMessageInner({ message, jobId, jobCwd, writtenFiles, onCancelQueued
|
|
|
678
687
|
remarkPlugins={[remarkGfm]}
|
|
679
688
|
rehypePlugins={[rehypeHighlight]}
|
|
680
689
|
components={markdownComponents}
|
|
690
|
+
urlTransform={chatMarkdownUrl}
|
|
681
691
|
>
|
|
682
692
|
{part.value}
|
|
683
693
|
</ReactMarkdown>
|
|
@@ -714,6 +724,7 @@ function ChatMessageInner({ message, jobId, jobCwd, writtenFiles, onCancelQueued
|
|
|
714
724
|
remarkPlugins={[remarkGfm]}
|
|
715
725
|
rehypePlugins={[rehypeHighlight]}
|
|
716
726
|
components={markdownComponents}
|
|
727
|
+
urlTransform={chatMarkdownUrl}
|
|
717
728
|
>
|
|
718
729
|
{displayContent}
|
|
719
730
|
</ReactMarkdown>
|
|
@@ -866,6 +877,8 @@ function hashSenderColor(senderWorkflowId: string | undefined): string {
|
|
|
866
877
|
function PeerMessageBlock({ message, jobId, onMakeTask }: { message: ChatMessageType; jobId?: string; onMakeTask?: (content: string, fromWorkflowId: string) => void }) {
|
|
867
878
|
const selected = useMessageSelectionStore((s) => !!jobId && (s.selected[jobId]?.includes(message.id) ?? false));
|
|
868
879
|
const isSent = message.role === 'peer-sent';
|
|
880
|
+
const [open, setOpen] = useState(false);
|
|
881
|
+
const openButton = useRef<HTMLButtonElement>(null);
|
|
869
882
|
const senderColor = hashSenderColor(message.senderWorkflowId);
|
|
870
883
|
const arrow = isSent ? '→' : '←';
|
|
871
884
|
const verb = isSent ? 'sent to' : 'from';
|
|
@@ -879,9 +892,14 @@ function PeerMessageBlock({ message, jobId, onMakeTask }: { message: ChatMessage
|
|
|
879
892
|
const senderLabel = peerInfo
|
|
880
893
|
? (peerInfo.role ? `${peerInfo.displayName} (${peerInfo.role})` : peerInfo.displayName)
|
|
881
894
|
: fallbackLabel;
|
|
882
|
-
|
|
895
|
+
const self = useAppStore((s) => jobId ? s.clusterMemberLabels[jobId] : undefined);
|
|
896
|
+
const selfLabel = self?.displayName ?? jobId?.slice(0, 8) ?? 'This member';
|
|
897
|
+
return (<>
|
|
883
898
|
<div
|
|
899
|
+
data-help="cluster.peer-message"
|
|
900
|
+
onClick={(event) => { if (!(event.target as HTMLElement).closest('button, input, a')) { openButton.current?.focus(); setOpen(true); } }}
|
|
884
901
|
style={{
|
|
902
|
+
cursor: 'pointer',
|
|
885
903
|
margin: '8px 16px',
|
|
886
904
|
padding: '8px 12px',
|
|
887
905
|
borderLeft: `3px solid ${senderColor}`,
|
|
@@ -944,11 +962,18 @@ function PeerMessageBlock({ message, jobId, onMakeTask }: { message: ChatMessage
|
|
|
944
962
|
</button>
|
|
945
963
|
) : null}
|
|
946
964
|
</div>
|
|
947
|
-
<
|
|
948
|
-
{message.content}
|
|
949
|
-
</
|
|
965
|
+
<button ref={openButton} type="button" aria-label={`Open peer message ${verb} ${senderLabel}`} aria-haspopup="dialog" data-help="cluster.peer-message" onClick={() => setOpen(true)} style={{ padding: 0, border: 0, background: 'transparent', color: 'var(--color-fg)', textAlign: 'left', font: 'inherit', cursor: 'pointer', whiteSpace: 'pre-wrap', wordBreak: 'break-word' }}>
|
|
966
|
+
{message.content.length > 200 ? `${message.content.slice(0, 200)}…` : message.content}
|
|
967
|
+
</button>
|
|
950
968
|
</div>
|
|
951
|
-
|
|
969
|
+
{open && <DialogShell title="Peer message" dataHelp="cluster.peer-message" onClose={() => setOpen(false)} width={720}
|
|
970
|
+
actions={<button type="button" onClick={() => setOpen(false)}>CLOSE</button>}>
|
|
971
|
+
<p>From: {isSent ? selfLabel : senderLabel}<br />To: {isSent ? senderLabel : selfLabel}<br />
|
|
972
|
+
{message.timestamp ? `Sent: ${new Date(message.timestamp).toLocaleString()}` : 'Time unavailable'}</p>
|
|
973
|
+
{isSent && message.peerFullContent === undefined && <p>Only the saved preview is available for this older sent message.</p>}
|
|
974
|
+
<div style={{ whiteSpace: 'pre-wrap', overflowWrap: 'anywhere' }}>{isSent ? (message.peerFullContent ?? message.content) : message.content}</div>
|
|
975
|
+
</DialogShell>}
|
|
976
|
+
</>);
|
|
952
977
|
}
|
|
953
978
|
|
|
954
979
|
// Memoised. ChatPanel virtualises with `overscan: 16`, so ~30 rows
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PhoneUploadButton } from './PhoneUpload';
|
|
1
2
|
import { TidyComposer } from './TidyComposer';
|
|
2
3
|
import { useMessageBoxSize, messageBoxMinHeight, messageBoxMaxHeight } from '../utils/messageBoxSize';
|
|
3
4
|
import { PendingQuestionsButton } from './PendingQuestionsButton';
|
|
@@ -340,6 +341,7 @@ export function ChatModeView({ job, onRenameWorkflow, onSend, onCancel, onLoadEa
|
|
|
340
341
|
{uploading ? '…' : '+'}
|
|
341
342
|
</button>
|
|
342
343
|
)}
|
|
344
|
+
{canAttach && <PhoneUploadButton workflowId={job.id} style={{ height: '30px', padding: '0 10px', borderRadius: '15px' }} />}
|
|
343
345
|
<textarea
|
|
344
346
|
data-help="chat.input"
|
|
345
347
|
ref={areaRef}
|
|
@@ -2,7 +2,7 @@ import { useEffect, useState, type CSSProperties } from 'react';
|
|
|
2
2
|
import { ROLE_PRESETS, presetForText, type ArcoSkillRef, type ClusterStatePayload, type ClusterSkillPin } from '@arco/shared';
|
|
3
3
|
import { useAppStore } from '../../stores/appStore';
|
|
4
4
|
import { useStartupStore } from '../../stores/startupStore';
|
|
5
|
-
import { DialogShell } from '../DialogShell';
|
|
5
|
+
import { DialogShell, SETTINGS_CHILD_DIALOG_Z_INDEX } from '../DialogShell';
|
|
6
6
|
|
|
7
7
|
interface Skill { scope: 'project' | 'global'; slug: string; name: string; off?: boolean }
|
|
8
8
|
const button: CSSProperties = { padding: '3px 8px', background: 'transparent', border: '1px solid var(--color-border-hairline)', borderRadius: '3px', color: 'var(--color-fg)', cursor: 'pointer', fontSize: '10px', letterSpacing: '1px' };
|
|
@@ -13,6 +13,9 @@ export function SkillsControl({ cluster, memberId }: { cluster: ClusterStatePayl
|
|
|
13
13
|
const send = useAppStore(s => s.wsSendRaw);
|
|
14
14
|
const connected = useAppStore(s => s.connected);
|
|
15
15
|
const [open, setOpen] = useState(false);
|
|
16
|
+
const [adding, setAdding] = useState(false);
|
|
17
|
+
const [selected, setSelected] = useState('');
|
|
18
|
+
const [pinning, setPinning] = useState<Skill | null>(null);
|
|
16
19
|
const [catalog, setCatalog] = useState<Skill[] | null>(null);
|
|
17
20
|
const [error, setError] = useState('');
|
|
18
21
|
const pins = cluster.skillPins ?? [];
|
|
@@ -36,13 +39,14 @@ export function SkillsControl({ cluster, memberId }: { cluster: ClusterStatePayl
|
|
|
36
39
|
<button type="button" className="display-font" data-help="cluster.skills" style={button}
|
|
37
40
|
aria-label={`${memberId ? 'Skills inherited from cluster' : 'Cluster skills'}, ${count} ${count === 1 ? 'pin' : 'pins'}`} aria-haspopup="dialog" aria-expanded={open}
|
|
38
41
|
onClick={() => setOpen(true)}>{memberId ? 'FROM CLUSTER' : 'SKILLS'} [{count}]</button>
|
|
39
|
-
{open && <DialogShell title="Cluster skills" dataHelp="cluster.skills" onClose={() => setOpen(false)} closeOnBackdrop width={620}
|
|
40
|
-
actions={
|
|
42
|
+
{open && !adding && !pinning && <DialogShell title="Cluster skills" dataHelp="cluster.skills" onClose={() => setOpen(false)} closeOnBackdrop width={620}
|
|
43
|
+
actions={<><button type="button" style={button} data-help="cluster.skills.add" disabled={catalog === null || !catalog.some(skill => !skill.off)} onClick={() => { setSelected(''); setAdding(true); }}>ADD SKILL</button><button type="button" style={button} data-help="cluster.skills" onClick={() => {
|
|
41
44
|
setOpen(false); useStartupStore.getState().setSettingsSection('skills'); useAppStore.getState().setShowSettings(true);
|
|
42
|
-
}}>SETTINGS > SKILLS</button
|
|
45
|
+
}}>SETTINGS > SKILLS</button></>}>
|
|
43
46
|
<p>Full skill text is added to every turn for matching members, including new and replaced members. Only the operator changes these pins.</p>
|
|
44
|
-
{!pins.length && <p>No skills are pinned to this cluster.
|
|
47
|
+
{!pins.length && <p>No skills are pinned to this cluster. Select ADD SKILL to pin one.</p>}
|
|
45
48
|
{error && <p role="alert">{error}</p>}
|
|
49
|
+
{catalog && !catalog.some(skill => !skill.off) && <p>No available skills. Create or turn on a skill in Settings > SKILLS.</p>}
|
|
46
50
|
{pins.map((pin, index) => {
|
|
47
51
|
const skill = catalog?.find(item => sameRef(item, pin));
|
|
48
52
|
const status = catalog === null ? 'Loading' : !skill ? 'Missing or unreadable' : skill.off ? 'Off' : 'Available';
|
|
@@ -59,18 +63,28 @@ export function SkillsControl({ cluster, memberId }: { cluster: ClusterStatePayl
|
|
|
59
63
|
})}
|
|
60
64
|
<p>Tab pins, cluster pins and matching role pins share one limit: 12 unique skills and 64 KiB of text. Missing or off skills are skipped. A skill that grows beyond the limit is reported in the conversation.</p>
|
|
61
65
|
</DialogShell>}
|
|
66
|
+
{open && adding && <DialogShell zIndex={9700} title="Add cluster skill" dataHelp="cluster.skills.add" onClose={() => setAdding(false)} width={620}
|
|
67
|
+
actions={<><button type="button" style={button} onClick={() => setAdding(false)}>CANCEL</button><button type="button" style={button} disabled={!selected} onClick={() => { const skill = catalog?.find(item => JSON.stringify([item.scope, item.slug]) === selected); if (skill) { setAdding(false); setPinning(skill); } }}>NEXT</button></>}>
|
|
68
|
+
<label>Skill<select className="arco-field" aria-label="Skill to add" data-help="cluster.skills.add" value={selected} onChange={event => setSelected(event.target.value)} style={{ display: 'block', width: '100%', minWidth: 0 }}>
|
|
69
|
+
<option value="">Select a skill</option>{catalog?.filter(skill => !skill.off).map(skill => <option key={JSON.stringify([skill.scope, skill.slug])} value={JSON.stringify([skill.scope, skill.slug])}>{skill.name} ({skill.scope})</option>)}
|
|
70
|
+
</select></label>
|
|
71
|
+
</DialogShell>}
|
|
72
|
+
{open && pinning && <PinSkillDialog skill={pinning} cwd={cluster.cwd} kind="cluster" initialTargetId={cluster.clusterId} onClose={() => setPinning(null)} />}
|
|
62
73
|
</>;
|
|
63
74
|
}
|
|
64
75
|
|
|
65
|
-
export function PinSkillDialog({ skill, cwd, kind, onClose }: { skill: Skill; cwd: string; kind: 'tab' | 'cluster'; onClose: () => void }) {
|
|
76
|
+
export function PinSkillDialog({ skill, cwd, kind, onClose, onPinned, initialTargetId }: { skill: Skill; cwd: string; kind: 'tab' | 'cluster'; onClose: () => void; initialTargetId?: string; onPinned?: (result: { kind: 'tab' | 'cluster'; id: string; role?: string; scope: 'project' | 'global'; slug: string; message: string }) => void }) {
|
|
66
77
|
const clusters = useAppStore(s => s.clusters);
|
|
67
78
|
const jobs = useAppStore(s => s.jobs);
|
|
79
|
+
const activeClusterId = useAppStore(s => s.activeClusterId);
|
|
80
|
+
const activeJobId = useAppStore(s => s.activeJobId);
|
|
68
81
|
const send = useAppStore(s => s.wsSendRaw);
|
|
69
82
|
const connected = useAppStore(s => s.connected);
|
|
70
83
|
const targets = kind === 'cluster'
|
|
71
84
|
? Object.values(clusters).filter(cluster => skill.scope === 'global' || cluster.cwd === cwd).map(cluster => ({ id: cluster.clusterId, name: cluster.name ?? `Cluster ${cluster.clusterId.slice(0, 8)}` }))
|
|
72
85
|
: Object.values(jobs).filter(job => job.config.kind !== 'chat' && (skill.scope === 'global' || job.config.workingDirectory === cwd)).map(job => ({ id: job.id, name: job.config.name || job.id.slice(0, 8) }));
|
|
73
|
-
const
|
|
86
|
+
const activeTarget = initialTargetId ?? (kind === 'cluster' ? activeClusterId ?? Object.values(clusters).find(item => item.members.some(member => member.workflowId === activeJobId))?.clusterId : activeJobId);
|
|
87
|
+
const [target, setTarget] = useState(targets.find(item => item.id === activeTarget)?.id ?? targets[0]?.id ?? '');
|
|
74
88
|
const [scope, setScope] = useState('all');
|
|
75
89
|
const [customRole, setCustomRole] = useState('');
|
|
76
90
|
const cluster = kind === 'cluster' ? clusters[target] : undefined;
|
|
@@ -88,9 +102,12 @@ export function PinSkillDialog({ skill, cwd, kind, onClose }: { skill: Skill; cw
|
|
|
88
102
|
const existing = jobs[target]?.config.pinnedSkills ?? [];
|
|
89
103
|
if (!existing.some(ref => sameRef(ref, skill))) send?.({ type: 'update_primary_config', workflowId: target, pinnedSkills: [...existing, { scope: skill.scope, slug: skill.slug }] });
|
|
90
104
|
}
|
|
105
|
+
const name = targets.find(item => item.id === target)?.name ?? target;
|
|
106
|
+
const destination = cluster ? `${name} (${role === undefined ? 'All members' : roleLabel(role)})` : name;
|
|
107
|
+
onPinned?.({ kind, id: target, role, scope: skill.scope, slug: skill.slug, message: `Pinned ${skill.name} to ${destination}.` });
|
|
91
108
|
onClose();
|
|
92
109
|
};
|
|
93
|
-
return <DialogShell title={`Pin ${skill.name} to ${kind}`} dataHelp="settings.skills.pin" onClose={onClose} width={620}
|
|
110
|
+
return <DialogShell zIndex={SETTINGS_CHILD_DIALOG_Z_INDEX} title={`Pin ${skill.name} to ${kind}`} dataHelp="settings.skills.pin" onClose={onClose} width={620}
|
|
94
111
|
actions={<><button type="button" data-help="settings.skills.pin" style={button} onClick={onClose}>CANCEL</button><button type="button" data-help="settings.skills.pin" style={button} disabled={!valid} onClick={pin}>PIN</button></>}>
|
|
95
112
|
{!targets.length ? <p>Open {kind === 'cluster' ? 'a cluster' : 'an Agent tab'}{skill.scope === 'project' ? ' for this project' : ''} to pin this skill.</p> : <>
|
|
96
113
|
<label>{kind === 'cluster' ? 'Cluster' : 'Tab'}<select className="arco-field" aria-label={`Pin destination ${kind}`} data-help="settings.skills.pin" value={target} style={{ display: 'block', width: '100%', minWidth: 0 }} onChange={event => { setTarget(event.target.value); setScope('all'); }}>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { JobState } from '../stores/appStore';
|
|
2
|
+
|
|
3
|
+
export function runningCodexCommand(job: JobState | undefined) {
|
|
4
|
+
return job?.codexLateCommands?.findLast(command => command.waitingUntil > Date.now());
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// The tab's turn is open only because the agent waits on this command. A
|
|
8
|
+
// server or a command from an earlier turn is running, not waited on.
|
|
9
|
+
export function waitedCodexCommand(job: JobState | undefined) {
|
|
10
|
+
return job?.busy ? job.codexLateCommands?.findLast(command => command.waiting && command.waitingUntil > Date.now()) : undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function CodexLateCommandLine({ job, header }: { job: JobState | undefined; header?: boolean }) {
|
|
14
|
+
const waited = waitedCodexCommand(job);
|
|
15
|
+
const command = waited ?? runningCodexCommand(job);
|
|
16
|
+
if (!command) return null;
|
|
17
|
+
let label = 'Shell command';
|
|
18
|
+
try { label = JSON.parse(command.input).command?.replace(/\s+/g, ' ').trim() || label; }
|
|
19
|
+
catch { /* keep the fallback */ }
|
|
20
|
+
const started = new Date(command.startedAt).toLocaleTimeString([], { hour: 'numeric', minute: '2-digit', second: '2-digit' });
|
|
21
|
+
// While the turn is held open for it, the agent is waiting on this command.
|
|
22
|
+
const text = waited ? `Waiting for a command started at ${started}: ${label}` : `Command still running since ${started}: ${label}`;
|
|
23
|
+
return <div
|
|
24
|
+
role="status"
|
|
25
|
+
data-help="worker.header.late-command"
|
|
26
|
+
data-testid="codex-command-running"
|
|
27
|
+
title={text}
|
|
28
|
+
style={{
|
|
29
|
+
color: 'var(--color-accent-secondary)', overflow: 'hidden', textOverflow: 'ellipsis',
|
|
30
|
+
whiteSpace: 'nowrap', minWidth: 0, fontSize: '10px', flexShrink: 0,
|
|
31
|
+
...(header ? { padding: '4px 12px', borderBottom: '1px solid var(--color-border-hairline)' } : {}),
|
|
32
|
+
}}
|
|
33
|
+
>{text}</div>;
|
|
34
|
+
}
|
|
@@ -9,6 +9,8 @@ import { confirmationSurfaceSize, contentSurfaceSize, formSurfaceSize, pickerSur
|
|
|
9
9
|
// The header and footer never scroll away, so the result line and the actions
|
|
10
10
|
// stay visible at small window heights.
|
|
11
11
|
|
|
12
|
+
export const SETTINGS_CHILD_DIALOG_Z_INDEX = 9701;
|
|
13
|
+
|
|
12
14
|
export const dialogTitleStyle: CSSProperties = {
|
|
13
15
|
fontSize: '12px', letterSpacing: '3px', color: 'var(--color-accent-primary)', margin: 0, fontWeight: 'normal',
|
|
14
16
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CodexLateCommandLine, runningCodexCommand } from './CodexLateCommand';
|
|
1
2
|
// docs/CLIENT.md - compact ~120px card per cluster member.
|
|
2
3
|
//
|
|
3
4
|
// Read-only-with-click; no composer, no primitive bar (those live in the
|
|
@@ -65,6 +66,7 @@ export function MemberCard({ job, displayName, status, role, pendingMail = 0, on
|
|
|
65
66
|
const wfid = job?.id ?? '';
|
|
66
67
|
const wfidShort = wfid.slice(0, 8);
|
|
67
68
|
const busy = status === 'busy';
|
|
69
|
+
const lateCommand = runningCodexCommand(job);
|
|
68
70
|
const waitingQuestion = hasWaitingQuestion(job);
|
|
69
71
|
const bodyText = useSettledPreview(job);
|
|
70
72
|
const bodyDim = bodyText === '[no turns]';
|
|
@@ -172,10 +174,11 @@ export function MemberCard({ job, displayName, status, role, pendingMail = 0, on
|
|
|
172
174
|
})()}
|
|
173
175
|
{density === 'compact' && roleChipLabel && <span data-help="cluster.member-card.role-chip" title={trimmedRole} style={{ padding: '0 4px', border: '1px solid var(--color-accent-secondary-a40, var(--color-accent-secondary-dim))', color: 'var(--color-accent-secondary)', fontSize: '9px', letterSpacing: '1px', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', minWidth: 0, flex: '0 1 auto' }}>{roleChipLabel}</span>}
|
|
174
176
|
<span style={{ marginLeft: 'auto', color: busy ? 'var(--color-accent-primary)' : 'var(--color-fg-muted)', fontSize: '10px', flexShrink: 0 }}>
|
|
175
|
-
{
|
|
177
|
+
{busy ? 'WORKING' : lateCommand ? 'COMMAND RUNNING' : 'IDLE'}
|
|
176
178
|
</span>
|
|
177
179
|
{wfid && <BriefControl scope="worker" targetId={wfid} label="BRIEF" data-help="cluster.member-brief" testId="member-brief" title="A short synopsis of this member from facts Arco can see. Read-only; sends nothing." style={{ padding: '1px 5px', fontSize: '9px', flexShrink: 0 }} />}
|
|
178
180
|
</div>
|
|
181
|
+
<CodexLateCommandLine job={job} />
|
|
179
182
|
{/* Line 2 — wfid prefix · role chip (when set). Folded into the
|
|
180
183
|
tooltip and line 1 in the compact density. */}
|
|
181
184
|
{density !== 'compact' && <div style={{ display: 'flex', alignItems: 'center', gap: '8px', fontSize: '10px', letterSpacing: '1px' }}>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CodexLateCommandLine, runningCodexCommand } from './CodexLateCommand';
|
|
1
2
|
import { ContextMeter } from './ContextMeter';
|
|
2
3
|
import { PrimaryStatus } from './PrimaryStatus';
|
|
3
4
|
// docs/PROTOCOL_CLUSTER.md - one cluster member's chat + composer.
|
|
@@ -166,11 +167,12 @@ export function MemberPane({
|
|
|
166
167
|
</span>
|
|
167
168
|
{accountBadge && <AccountBadge label={accountBadge} />}
|
|
168
169
|
<span style={{ color: status === 'busy' ? 'var(--color-warning)' : 'var(--color-fg-muted)', fontSize: '10px' }}>
|
|
169
|
-
{status === 'busy' ? 'WORKING' : 'IDLE'}
|
|
170
|
+
{status === 'busy' ? 'WORKING' : runningCodexCommand(job) ? 'COMMAND RUNNING' : 'IDLE'}
|
|
170
171
|
</span>
|
|
171
172
|
{status === 'busy' && <PrimaryStatus job={job} />}
|
|
172
173
|
<span data-help="worker.header.ctx" style={{ marginLeft: 'auto', flexShrink: 0, fontSize: '10px' }}><ContextMeter job={job} onRecalibrate={onRecalibrate} /></span>
|
|
173
174
|
</div>
|
|
175
|
+
<CodexLateCommandLine job={job} header />
|
|
174
176
|
|
|
175
177
|
<div style={{ flex: 1, minHeight: 0, display: 'flex', flexDirection: 'column' }}>
|
|
176
178
|
<ChatPanel
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState, type CSSProperties } from 'react';
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
3
|
+
import qrcode from 'qrcode-generator';
|
|
4
|
+
import { useAppStore } from '../stores/appStore';
|
|
5
|
+
import { phoneUploadRequest } from '../utils/phoneUploadApi';
|
|
6
|
+
import { phoneThemeSnapshot } from '../utils/phoneTheme';
|
|
7
|
+
const OPEN_EVENT = 'arco:open-phone-upload';
|
|
8
|
+
const IMAGE = /\.(?:png|jpe?g|gif|webp|avif|heic|heif|tiff?|bmp|ico)$/i;
|
|
9
|
+
|
|
10
|
+
interface Opening {
|
|
11
|
+
workflowId: string;
|
|
12
|
+
trigger: HTMLButtonElement;
|
|
13
|
+
}
|
|
14
|
+
interface Link {
|
|
15
|
+
id: string;
|
|
16
|
+
url: string;
|
|
17
|
+
expiresAt: number;
|
|
18
|
+
verifiedAt?: number;
|
|
19
|
+
}
|
|
20
|
+
interface PhoneFile {
|
|
21
|
+
fileId: string;
|
|
22
|
+
filename: string;
|
|
23
|
+
path: string;
|
|
24
|
+
expiresAt: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function qrUrl(value: string): string {
|
|
28
|
+
const qr = qrcode(0, 'M');
|
|
29
|
+
qr.addData(value);
|
|
30
|
+
qr.make();
|
|
31
|
+
return qr.createDataURL(4, 16);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// The composer that holds the button passes its own sizing, so the button
|
|
35
|
+
// matches the attach control beside it instead of standing taller.
|
|
36
|
+
export function PhoneUploadButton({ workflowId, style }: { workflowId: string; style?: CSSProperties }) {
|
|
37
|
+
return <button
|
|
38
|
+
type="button"
|
|
39
|
+
className="display-font phone-upload-button"
|
|
40
|
+
data-help="composer.upload-from-phone"
|
|
41
|
+
aria-label="Upload from phone"
|
|
42
|
+
title="Upload from phone"
|
|
43
|
+
onClick={e => { window.dispatchEvent(new CustomEvent<Opening>(OPEN_EVENT, {
|
|
44
|
+
detail: { workflowId, trigger: e.currentTarget },
|
|
45
|
+
})); }}
|
|
46
|
+
style={{
|
|
47
|
+
flexShrink: 0, padding: '3px 8px', whiteSpace: 'nowrap',
|
|
48
|
+
background: 'transparent', border: '1px solid var(--color-border-hairline)',
|
|
49
|
+
borderRadius: '3px', color: 'var(--color-accent-secondary-dim)', cursor: 'pointer',
|
|
50
|
+
fontSize: '10px', letterSpacing: '1px', ...style,
|
|
51
|
+
}}
|
|
52
|
+
>UPLOAD FROM PHONE</button>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Arco cannot tell from this computer whether a phone can reach an address:
|
|
56
|
+
// the firewall or the network may block it, and Arco never inspects either.
|
|
57
|
+
// A route is marked Verified by upload only after a file has arrived through
|
|
58
|
+
// it (the server remembers when); every other offered route is Unverified.
|
|
59
|
+
// The address, its status and when it last worked each take their own line,
|
|
60
|
+
// in the chooser and under the code alike, so a narrow window wraps cleanly.
|
|
61
|
+
export function PhoneRouteLabel({ origin, verifiedAt }: { origin: string; verifiedAt?: number }) {
|
|
62
|
+
return <span className="phone-upload-route-label">
|
|
63
|
+
<span className="phone-upload-address">{origin}</span>{' '}
|
|
64
|
+
{verifiedAt
|
|
65
|
+
? <><span className="phone-upload-verified">VERIFIED BY UPLOAD</span>{' '}
|
|
66
|
+
<span className="phone-upload-last-worked">Last worked {new Date(verifiedAt).toLocaleString()}</span></>
|
|
67
|
+
: <span className="phone-upload-unverified">UNVERIFIED</span>}
|
|
68
|
+
</span>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// The one place for troubleshooting, shown once whether the window is
|
|
72
|
+
// offering addresses or showing a code.
|
|
73
|
+
export function PhoneRouteInfo() {
|
|
74
|
+
return <details className="phone-upload-info">
|
|
75
|
+
<summary>More info</summary>
|
|
76
|
+
<p>
|
|
77
|
+
Verified by upload means a file has arrived through this address. Unverified means none has yet. Network and
|
|
78
|
+
firewall settings can change, so an address that worked before can stop working.
|
|
79
|
+
</p>
|
|
80
|
+
<p>
|
|
81
|
+
If the page won't open on the phone, check that the phone is on the same private network as this computer
|
|
82
|
+
and that this computer's firewall allows incoming connections on the address's port. Some networks,
|
|
83
|
+
such as guest Wi-Fi, keep devices apart. If this computer asks whether to allow incoming connections, allow
|
|
84
|
+
them on private networks. Arco does not inspect or change the firewall.
|
|
85
|
+
</p>
|
|
86
|
+
</details>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function PhoneCode({ opening, dismiss }: { opening: Opening; dismiss: () => void }) {
|
|
90
|
+
const { workflowId } = opening;
|
|
91
|
+
const workflowAvailable = useAppStore(s => !!s.jobs[workflowId]);
|
|
92
|
+
const [link, setLink] = useState<Link | null>(null);
|
|
93
|
+
const [origins, setOrigins] = useState<string[]>([]);
|
|
94
|
+
const [verified, setVerified] = useState<Record<string, number>>({});
|
|
95
|
+
const [verifiedAt, setVerifiedAt] = useState<number | undefined>();
|
|
96
|
+
const [chosen, setChosen] = useState('');
|
|
97
|
+
const [creating, setCreating] = useState(true);
|
|
98
|
+
const [error, setError] = useState('');
|
|
99
|
+
const [time, setTime] = useState(Date.now);
|
|
100
|
+
const [closed, setClosed] = useState(false);
|
|
101
|
+
const [count, setCount] = useState(0);
|
|
102
|
+
const published = useRef(new Set<string>());
|
|
103
|
+
const dismissButton = useRef<HTMLButtonElement>(null);
|
|
104
|
+
const closing = useRef(false);
|
|
105
|
+
const dismissRef = useRef(dismiss);
|
|
106
|
+
dismissRef.current = dismiss;
|
|
107
|
+
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
dismissButton.current?.focus();
|
|
110
|
+
const escape = (e: KeyboardEvent) => {
|
|
111
|
+
if (e.key === 'Escape' && !e.defaultPrevented) { e.preventDefault(); dismissRef.current(); }
|
|
112
|
+
};
|
|
113
|
+
window.addEventListener('keydown', escape);
|
|
114
|
+
return () => {
|
|
115
|
+
window.removeEventListener('keydown', escape);
|
|
116
|
+
if (opening.trigger.isConnected) opening.trigger.focus();
|
|
117
|
+
};
|
|
118
|
+
}, [opening]);
|
|
119
|
+
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
if (!workflowAvailable) dismissRef.current();
|
|
122
|
+
}, [workflowAvailable]);
|
|
123
|
+
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
let cancelled = false;
|
|
126
|
+
setCreating(true);
|
|
127
|
+
void phoneUploadRequest('', {
|
|
128
|
+
method: 'POST',
|
|
129
|
+
headers: { 'Content-Type': 'application/json' },
|
|
130
|
+
body: JSON.stringify({ workflowId, ...(chosen ? { origin: chosen } : {}), theme: phoneThemeSnapshot() }),
|
|
131
|
+
}).then(async response => {
|
|
132
|
+
const result = await response.json();
|
|
133
|
+
if (cancelled) {
|
|
134
|
+
if (result.id) void phoneUploadRequest('/' + result.id, { method: 'DELETE' }).catch(() => {});
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (!response.ok) setError(result.error || 'Phone upload is unavailable.');
|
|
138
|
+
else if (result.origins) {
|
|
139
|
+
setOrigins(result.origins);
|
|
140
|
+
setVerified(result.verified ?? {});
|
|
141
|
+
} else {
|
|
142
|
+
setLink(result);
|
|
143
|
+
setVerifiedAt(result.verifiedAt);
|
|
144
|
+
}
|
|
145
|
+
}).catch(() => {
|
|
146
|
+
if (!cancelled) setError('Phone upload is unavailable.');
|
|
147
|
+
}).finally(() => {
|
|
148
|
+
if (!cancelled) setCreating(false);
|
|
149
|
+
});
|
|
150
|
+
return () => { cancelled = true; };
|
|
151
|
+
}, [workflowId, chosen]);
|
|
152
|
+
|
|
153
|
+
useEffect(() => {
|
|
154
|
+
if (!link) return;
|
|
155
|
+
let inFlight = false;
|
|
156
|
+
let stopped = false;
|
|
157
|
+
|
|
158
|
+
const addFiles = (files: PhoneFile[]) => {
|
|
159
|
+
for (const file of files) {
|
|
160
|
+
if (published.current.has(file.fileId) || file.expiresAt <= Date.now()) continue;
|
|
161
|
+
published.current.add(file.fileId);
|
|
162
|
+
const isImage = IMAGE.test(file.filename);
|
|
163
|
+
useAppStore.getState().addAttachment(workflowId, {
|
|
164
|
+
filename: file.filename, path: file.path, isImage, phoneUpload: { id: file.fileId, expiresAt: file.expiresAt },
|
|
165
|
+
});
|
|
166
|
+
if (isImage) {
|
|
167
|
+
void phoneUploadRequest('/draft/' + file.fileId).then(async r => {
|
|
168
|
+
if (!r.ok) return;
|
|
169
|
+
const { preview } = await r.json();
|
|
170
|
+
if (!preview) return;
|
|
171
|
+
useAppStore.setState(state => {
|
|
172
|
+
const existing = state.attachments[workflowId];
|
|
173
|
+
if (!existing?.some(attachment => attachment.path === file.path)) return state;
|
|
174
|
+
return { attachments: { ...state.attachments, [workflowId]: existing.map(
|
|
175
|
+
attachment => attachment.path === file.path ? { ...attachment, previewUrl: preview } : attachment,
|
|
176
|
+
) } };
|
|
177
|
+
});
|
|
178
|
+
}).catch(() => {});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (!stopped) setCount(published.current.size);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const poll = async () => {
|
|
185
|
+
if (inFlight || closing.current) return;
|
|
186
|
+
const now = Date.now();
|
|
187
|
+
setTime(now);
|
|
188
|
+
inFlight = true;
|
|
189
|
+
try {
|
|
190
|
+
const response = await phoneUploadRequest('/' + link.id);
|
|
191
|
+
const data = await response.json();
|
|
192
|
+
if (stopped) return;
|
|
193
|
+
if (!response.ok) {
|
|
194
|
+
setClosed(true);
|
|
195
|
+
setError(data.error ?? 'Open a new code in Arco.');
|
|
196
|
+
clearInterval(timer);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
addFiles(data.files);
|
|
200
|
+
if (data.verifiedAt) setVerifiedAt(data.verifiedAt);
|
|
201
|
+
if (data.closed) {
|
|
202
|
+
setClosed(true);
|
|
203
|
+
clearInterval(timer);
|
|
204
|
+
}
|
|
205
|
+
} catch {
|
|
206
|
+
if (!stopped && now >= link.expiresAt) setClosed(true);
|
|
207
|
+
} finally {
|
|
208
|
+
inFlight = false;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const timer = window.setInterval(() => { void poll(); }, 1_000);
|
|
213
|
+
void poll();
|
|
214
|
+
return () => {
|
|
215
|
+
stopped = true;
|
|
216
|
+
closing.current = true;
|
|
217
|
+
clearInterval(timer);
|
|
218
|
+
// DELETE revokes the link before returning any attachments that arrived
|
|
219
|
+
// since the last poll. The files still go to the opening conversation.
|
|
220
|
+
void phoneUploadRequest('/' + link.id, { method: 'DELETE', keepalive: true }).then(async response => {
|
|
221
|
+
if (response.ok) addFiles((await response.json()).files);
|
|
222
|
+
}).catch(() => {});
|
|
223
|
+
};
|
|
224
|
+
}, [workflowId, link]);
|
|
225
|
+
|
|
226
|
+
const seconds = link ? Math.max(0, Math.ceil((link.expiresAt - time) / 1000)) : 0;
|
|
227
|
+
const image = useMemo(() => link ? qrUrl(link.url) : null, [link]);
|
|
228
|
+
const qr = !closed && seconds > 0 && !error ? image : null;
|
|
229
|
+
|
|
230
|
+
return createPortal(
|
|
231
|
+
<section
|
|
232
|
+
className="phone-upload-window"
|
|
233
|
+
role="dialog"
|
|
234
|
+
aria-labelledby="phone-upload-title"
|
|
235
|
+
data-testid="phone-upload-window"
|
|
236
|
+
>
|
|
237
|
+
<h2 id="phone-upload-title">UPLOAD FROM PHONE</h2>
|
|
238
|
+
<div role="status">
|
|
239
|
+
{error || (creating ? 'Opening phone upload…'
|
|
240
|
+
: closed || (link && seconds === 0) ? 'This code has expired. Open a new one to upload more files.'
|
|
241
|
+
: qr ? 'Scan on your phone while it is on the same private network.'
|
|
242
|
+
: 'Choose the private address your phone can reach.')}
|
|
243
|
+
</div>
|
|
244
|
+
{!creating && !link && !error && origins.map(origin =>
|
|
245
|
+
<button type="button" className="phone-upload-route" key={origin} onClick={() => setChosen(origin)}>
|
|
246
|
+
<PhoneRouteLabel origin={origin} verifiedAt={verified[origin]} />
|
|
247
|
+
</button>,
|
|
248
|
+
)}
|
|
249
|
+
{qr && <>
|
|
250
|
+
<img src={qr} alt="Scan to upload from your phone" />
|
|
251
|
+
<div className="phone-upload-route"><PhoneRouteLabel origin={new URL(link!.url).origin} verifiedAt={verifiedAt} /></div>
|
|
252
|
+
<div>Expires in {Math.floor(seconds / 60)}:{String(seconds % 60).padStart(2, '0')}</div>
|
|
253
|
+
</>}
|
|
254
|
+
{(qr || (!creating && !link && !error && origins.length > 0)) && <PhoneRouteInfo />}
|
|
255
|
+
{count > 0 && <div role="status">{count} added to the message box.</div>}
|
|
256
|
+
<button type="button" ref={dismissButton} onClick={dismiss}>Close</button>
|
|
257
|
+
</section>,
|
|
258
|
+
document.body,
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export function PhoneUploadWindow() {
|
|
263
|
+
const [opening, setOpening] = useState<(Opening & { key: number }) | null>(null);
|
|
264
|
+
const nextKey = useRef(0);
|
|
265
|
+
|
|
266
|
+
useEffect(() => {
|
|
267
|
+
const open = (event: Event) => {
|
|
268
|
+
setOpening({ ...(event as CustomEvent<Opening>).detail, key: ++nextKey.current });
|
|
269
|
+
};
|
|
270
|
+
window.addEventListener(OPEN_EVENT, open);
|
|
271
|
+
const expiry = window.setInterval(() => {
|
|
272
|
+
const store = useAppStore.getState();
|
|
273
|
+
const now = Date.now();
|
|
274
|
+
for (const [workflowId, files] of Object.entries(store.attachments)) {
|
|
275
|
+
for (let i = files.length - 1; i >= 0; i--) {
|
|
276
|
+
const upload = files[i].phoneUpload;
|
|
277
|
+
if (upload && upload.expiresAt <= now) store.removeAttachment(workflowId, i);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}, 10_000);
|
|
281
|
+
return () => {
|
|
282
|
+
window.removeEventListener(OPEN_EVENT, open);
|
|
283
|
+
clearInterval(expiry);
|
|
284
|
+
};
|
|
285
|
+
}, []);
|
|
286
|
+
|
|
287
|
+
return opening ? <PhoneCode key={opening.key} opening={opening} dismiss={() => setOpening(null)} /> : null;
|
|
288
|
+
}
|