@opengeni/react 7.6.1 → 7.7.0-canary.37111190284001

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 (145) hide show
  1. package/README.md +47 -2
  2. package/dist/{browser-viewer-5X47I6T2.js → browser-viewer-63TXMINB.js} +6 -5
  3. package/dist/{chunk-5EXGU7UF.js → chunk-55DDDVKU.js} +3 -3
  4. package/dist/{chunk-UINDK6C3.js → chunk-7CYYXWHU.js} +5 -8
  5. package/dist/chunk-7CYYXWHU.js.map +1 -0
  6. package/dist/{chunk-LZ3KHA55.js → chunk-A2L5N3EI.js} +332 -339
  7. package/dist/chunk-A2L5N3EI.js.map +1 -0
  8. package/dist/{chunk-KGENSZKS.js → chunk-AAG4R3QN.js} +4 -3
  9. package/dist/chunk-AAG4R3QN.js.map +1 -0
  10. package/dist/{chunk-Z3DISEQN.js → chunk-CWWKTNKK.js} +35 -18
  11. package/dist/chunk-CWWKTNKK.js.map +1 -0
  12. package/dist/{chunk-WZ55DVGK.js → chunk-ELCE5SXV.js} +8 -4
  13. package/dist/chunk-ELCE5SXV.js.map +1 -0
  14. package/dist/{chunk-YSMMDOOE.js → chunk-GISEVGS6.js} +10 -2
  15. package/dist/chunk-GISEVGS6.js.map +1 -0
  16. package/dist/{chunk-BI57CQUV.js → chunk-I7IWRQLN.js} +2 -2
  17. package/dist/{chunk-XA6R7DJQ.js → chunk-IQUCRAT7.js} +3 -3
  18. package/dist/{chunk-CHPKSLPN.js → chunk-NBZ64YY7.js} +4 -2
  19. package/dist/chunk-NBZ64YY7.js.map +1 -0
  20. package/dist/{chunk-DV2DBNPQ.js → chunk-Q5QBEZIQ.js} +48 -29
  21. package/dist/chunk-Q5QBEZIQ.js.map +1 -0
  22. package/dist/{chunk-FGBCYQOT.js → chunk-RDKBXMWX.js} +120 -74
  23. package/dist/chunk-RDKBXMWX.js.map +1 -0
  24. package/dist/{chunk-45GE35O7.js → chunk-TKB4SB44.js} +10 -2
  25. package/dist/chunk-TKB4SB44.js.map +1 -0
  26. package/dist/{chunk-YCGBREUV.js → chunk-TOAH2BKA.js} +6 -2
  27. package/dist/{chunk-YCGBREUV.js.map → chunk-TOAH2BKA.js.map} +1 -1
  28. package/dist/chunk-UGLEYEMP.js +33 -0
  29. package/dist/chunk-UGLEYEMP.js.map +1 -0
  30. package/dist/{chunk-UJRYEWZI.js → chunk-UTRTG6LH.js} +48 -8
  31. package/dist/chunk-UTRTG6LH.js.map +1 -0
  32. package/dist/{chunk-YRYF2GLG.js → chunk-WYVLAAJA.js} +39 -31
  33. package/dist/chunk-WYVLAAJA.js.map +1 -0
  34. package/dist/{chunk-VGIKFIO2.js → chunk-XOAMRDDK.js} +6 -3
  35. package/dist/chunk-XOAMRDDK.js.map +1 -0
  36. package/dist/{chunk-6NEZPF53.js → chunk-YN7I3STW.js} +153 -32
  37. package/dist/chunk-YN7I3STW.js.map +1 -0
  38. package/dist/{chunk-KZ73RL76.js → chunk-YQEAA6LT.js} +7 -3
  39. package/dist/chunk-YQEAA6LT.js.map +1 -0
  40. package/dist/client.d.ts +4 -1
  41. package/dist/commands/types.d.ts +2 -0
  42. package/dist/components/approval-surface.d.ts +15 -0
  43. package/dist/components/session-conversation.d.ts +3 -0
  44. package/dist/composer.js +8 -7
  45. package/dist/{computer-viewer-7GF35SNY.js → computer-viewer-X2MBRZY4.js} +5 -4
  46. package/dist/connect.js +3 -3
  47. package/dist/hooks/use-browser-session.d.ts +4 -0
  48. package/dist/hooks/use-composer.d.ts +2 -0
  49. package/dist/hooks/use-computer-session.d.ts +2 -0
  50. package/dist/hooks/use-file-attachments.d.ts +2 -0
  51. package/dist/hooks/use-session-events.d.ts +1 -1
  52. package/dist/hooks/use-workspace-sessions.d.ts +15 -5
  53. package/dist/index.d.ts +2 -2
  54. package/dist/index.js +28 -21
  55. package/dist/index.js.map +1 -1
  56. package/dist/interaction.d.ts +1 -1
  57. package/dist/interaction.js +6 -5
  58. package/dist/interaction.js.map +1 -1
  59. package/dist/{latest-question-3BJGKQQ6.js → latest-question-CNEZ5KAN.js} +3 -3
  60. package/dist/lib/error-message.d.ts +7 -0
  61. package/dist/lib/format.d.ts +27 -3
  62. package/dist/lib/interaction-errors.d.ts +3 -0
  63. package/dist/machines.js +5 -4
  64. package/dist/{model-policy-picker-menu-PUTA5JOB.js → model-policy-picker-menu-GN2LTB7Z.js} +4 -4
  65. package/dist/model-policy.js +1 -1
  66. package/dist/provider.d.ts +5 -1
  67. package/dist/{queue-surface-implementation-2CAQAIHM.js → queue-surface-implementation-HENWYFWA.js} +3 -2
  68. package/dist/{queue-surface-implementation-2CAQAIHM.js.map → queue-surface-implementation-HENWYFWA.js.map} +1 -1
  69. package/dist/realtime.js +2 -2
  70. package/dist/{sandbox-files-AEJTWGT4.js → sandbox-files-BBC47SLD.js} +4 -3
  71. package/dist/session-ui.d.ts +1 -1
  72. package/dist/session-ui.js +13 -12
  73. package/dist/session-ui.js.map +1 -1
  74. package/dist/session.js +7 -6
  75. package/dist/usage.js +2 -1
  76. package/dist/usage.js.map +1 -1
  77. package/package.json +3 -3
  78. package/src/client.ts +5 -1
  79. package/src/commands/registry.ts +18 -15
  80. package/src/commands/types.ts +2 -0
  81. package/src/components/approval-surface.tsx +166 -42
  82. package/src/components/browser-viewer.tsx +38 -9
  83. package/src/components/composer.tsx +9 -2
  84. package/src/components/computer-viewer.tsx +160 -30
  85. package/src/components/generated-video-player.tsx +4 -2
  86. package/src/components/human-input-form.tsx +18 -5
  87. package/src/components/message-timeline.tsx +120 -168
  88. package/src/components/model-policy-picker.tsx +2 -15
  89. package/src/components/open-geni-chat.tsx +11 -4
  90. package/src/components/queue-surface-state.tsx +3 -1
  91. package/src/components/session-chrome.tsx +5 -2
  92. package/src/components/session-commands-panel.tsx +3 -1
  93. package/src/components/session-conversation.tsx +10 -3
  94. package/src/components/session-list.tsx +7 -5
  95. package/src/components/session-mcp-capability-card.tsx +11 -1
  96. package/src/hooks/internal.ts +3 -2
  97. package/src/hooks/use-browser-session.ts +115 -79
  98. package/src/hooks/use-composer.ts +70 -31
  99. package/src/hooks/use-computer-session.ts +57 -6
  100. package/src/hooks/use-file-attachments.ts +16 -3
  101. package/src/hooks/use-goal.ts +2 -1
  102. package/src/hooks/use-session-capabilities.ts +3 -2
  103. package/src/hooks/use-session-events.ts +15 -8
  104. package/src/hooks/use-slash-commands.ts +6 -11
  105. package/src/hooks/use-turn-queue.ts +2 -1
  106. package/src/hooks/use-workspace-sessions.ts +40 -7
  107. package/src/index.ts +7 -2
  108. package/src/interaction.ts +1 -0
  109. package/src/lib/error-message.ts +37 -0
  110. package/src/lib/format.ts +73 -9
  111. package/src/lib/interaction-errors.ts +15 -0
  112. package/src/model-policy.ts +6 -1
  113. package/src/provider.tsx +12 -4
  114. package/src/session-ui.ts +1 -1
  115. package/src/timeline/projection.ts +12 -1
  116. package/styles/compiled.css +14 -30
  117. package/dist/chunk-45GE35O7.js.map +0 -1
  118. package/dist/chunk-6NEZPF53.js.map +0 -1
  119. package/dist/chunk-CHPKSLPN.js.map +0 -1
  120. package/dist/chunk-DV2DBNPQ.js.map +0 -1
  121. package/dist/chunk-FGBCYQOT.js.map +0 -1
  122. package/dist/chunk-KGENSZKS.js.map +0 -1
  123. package/dist/chunk-KZ73RL76.js.map +0 -1
  124. package/dist/chunk-LZ3KHA55.js.map +0 -1
  125. package/dist/chunk-UINDK6C3.js.map +0 -1
  126. package/dist/chunk-UJRYEWZI.js.map +0 -1
  127. package/dist/chunk-VGIKFIO2.js.map +0 -1
  128. package/dist/chunk-WZ55DVGK.js.map +0 -1
  129. package/dist/chunk-YRYF2GLG.js.map +0 -1
  130. package/dist/chunk-YSMMDOOE.js.map +0 -1
  131. package/dist/chunk-Z3DISEQN.js.map +0 -1
  132. package/dist/components/timeline-pill-geometry.d.ts +0 -8
  133. package/dist/components/timeline-pill-placement.d.ts +0 -24
  134. package/dist/timeline-pill-geometry-Z23V243M.js +0 -110
  135. package/dist/timeline-pill-geometry-Z23V243M.js.map +0 -1
  136. package/src/components/timeline-pill-geometry.ts +0 -169
  137. package/src/components/timeline-pill-placement.ts +0 -99
  138. /package/dist/{browser-viewer-5X47I6T2.js.map → browser-viewer-63TXMINB.js.map} +0 -0
  139. /package/dist/{chunk-5EXGU7UF.js.map → chunk-55DDDVKU.js.map} +0 -0
  140. /package/dist/{chunk-BI57CQUV.js.map → chunk-I7IWRQLN.js.map} +0 -0
  141. /package/dist/{chunk-XA6R7DJQ.js.map → chunk-IQUCRAT7.js.map} +0 -0
  142. /package/dist/{computer-viewer-7GF35SNY.js.map → computer-viewer-X2MBRZY4.js.map} +0 -0
  143. /package/dist/{latest-question-3BJGKQQ6.js.map → latest-question-CNEZ5KAN.js.map} +0 -0
  144. /package/dist/{model-policy-picker-menu-PUTA5JOB.js.map → model-policy-picker-menu-GN2LTB7Z.js.map} +0 -0
  145. /package/dist/{sandbox-files-AEJTWGT4.js.map → sandbox-files-BBC47SLD.js.map} +0 -0
@@ -4,7 +4,10 @@ import {
4
4
  usePageLiveActivity,
5
5
  usePolledValue,
6
6
  useSessionEventTrigger
7
- } from "./chunk-KZ73RL76.js";
7
+ } from "./chunk-YQEAA6LT.js";
8
+ import {
9
+ normalizeError
10
+ } from "./chunk-UGLEYEMP.js";
8
11
  import {
9
12
  useEmbeddedGoal,
10
13
  useEmbeddedSessionLineage,
@@ -131,7 +134,7 @@ function useGoal(sessionId, options = {}) {
131
134
  setGoal(null);
132
135
  setError(null);
133
136
  } else {
134
- setError(cause instanceof Error ? cause : new Error(String(cause)));
137
+ setError(normalizeError(cause));
135
138
  }
136
139
  setLoading(false);
137
140
  } finally {
@@ -475,4 +478,4 @@ export {
475
478
  isLineageRefreshEvent,
476
479
  useSessionLineage
477
480
  };
478
- //# sourceMappingURL=chunk-VGIKFIO2.js.map
481
+ //# sourceMappingURL=chunk-XOAMRDDK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/embedded-session-client.ts","../src/hooks/use-goal.ts","../src/hooks/use-session-mcp-approval-policy.ts","../src/hooks/use-session-lineage.ts"],"sourcesContent":["import type { ComposerDraft } from \"@opengeni/sdk\";\nimport type { EmbeddedSessionClientLike } from \"./client\";\n\nexport type ComposerDraftMapContext = {\n operation: \"read\" | \"save\" | \"submit\";\n workspaceId: string;\n sessionId: string;\n};\n\nexport type CreateEmbeddedSessionClientOptions = {\n /**\n * Explicit host-owned method replacements. Methods inherited from `base`\n * retain `base` as their receiver; overrides retain this object as theirs.\n */\n overrides?: Partial<EmbeddedSessionClientLike> | undefined;\n /** Presentation/policy projection for every draft entering the React layer. */\n mapComposerDraft?:\n | ((draft: ComposerDraft, context: ComposerDraftMapContext) => ComposerDraft)\n | undefined;\n};\n\nconst requiredMethods = [\n \"getSession\",\n \"listEvents\",\n \"streamEvents\",\n \"getComposerDraft\",\n \"saveComposerDraft\",\n \"submitComposerDraft\",\n \"sendMessage\",\n \"steerMessage\",\n \"getQueue\",\n \"moveQueueItem\",\n \"editQueueItem\",\n \"steerQueueItem\",\n \"deleteQueueItem\",\n \"pauseSession\",\n \"resumeSession\",\n \"sendApprovalDecision\",\n] as const satisfies readonly (keyof EmbeddedSessionClientLike)[];\n\n/**\n * Build the exact client required by `@opengeni/react/session` from a full SDK\n * client or host proxy. The constructor binds every delegated method once,\n * supports a host-owned atomic composer-submit override, and fails at creation\n * time instead of waiting for a missing method to be exercised by a hook.\n */\nexport function createEmbeddedSessionClient(\n base: EmbeddedSessionClientLike,\n options: CreateEmbeddedSessionClientOptions = {},\n): EmbeddedSessionClientLike {\n const overrides = options.overrides ?? {};\n const client = {} as EmbeddedSessionClientLike;\n for (const key of requiredMethods) {\n const override = overrides[key];\n const method = override ?? base[key];\n if (typeof method !== \"function\") {\n throw new TypeError(`Embedded session client method is required: ${key}`);\n }\n client[key] = method.bind(override === undefined ? base : overrides) as never;\n }\n\n const inferenceOverride = overrides.setWorkspaceInferenceState;\n const inferenceBase = base.setWorkspaceInferenceState;\n const inferenceMethod = inferenceOverride ?? inferenceBase;\n if (typeof inferenceMethod === \"function\") {\n client.setWorkspaceInferenceState = inferenceMethod.bind(\n inferenceOverride === undefined ? base : overrides,\n );\n }\n\n const mapDraft = options.mapComposerDraft;\n if (!mapDraft) return client;\n\n const getComposerDraft = client.getComposerDraft;\n client.getComposerDraft = async (workspaceId, sessionId) =>\n mapDraft(await getComposerDraft(workspaceId, sessionId), {\n operation: \"read\",\n workspaceId,\n sessionId,\n });\n\n const saveComposerDraft = client.saveComposerDraft;\n client.saveComposerDraft = async (workspaceId, sessionId, request) =>\n mapDraft(await saveComposerDraft(workspaceId, sessionId, request), {\n operation: \"save\",\n workspaceId,\n sessionId,\n });\n\n const submitComposerDraft = client.submitComposerDraft;\n client.submitComposerDraft = async (workspaceId, sessionId, request) => {\n const response = await submitComposerDraft(workspaceId, sessionId, request);\n return {\n ...response,\n draft: mapDraft(response.draft, {\n operation: \"submit\",\n workspaceId,\n sessionId,\n }),\n };\n };\n\n return client;\n}\n","import { OpenGeniApiError, type SessionEvent, type SessionGoal } from \"@opengeni/sdk\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { useEmbeddedGoal, type EmbeddedGoalClientOverride } from \"../session-context\";\nimport { normalizeError } from \"../lib/error-message\";\nimport {\n useDebouncedCallback,\n useMutationRunner,\n usePageLiveActivity,\n useSessionEventTrigger,\n type SessionEventFeedOptions,\n} from \"./internal\";\n\n/** Event types that change the session goal (set/updated/completed/paused/...). */\nexport function isGoalEvent(event: Pick<SessionEvent, \"type\">): boolean {\n return event.type.startsWith(\"goal.\");\n}\n\n/**\n * Events that can change the server-authoritative continuation projection.\n * The projection is derived from durable turn, session, control, and system\n * update state, so those events refresh the goal without model polling.\n */\nexport function isGoalRefreshEvent(event: Pick<SessionEvent, \"type\">): boolean {\n const type = event.type;\n return (\n isGoalEvent(event) ||\n type.startsWith(\"turn.\") ||\n type.startsWith(\"session.\") ||\n type.startsWith(\"system.update.\") ||\n type.startsWith(\"workspace.inference.\") ||\n type.startsWith(\"user.\")\n );\n}\n\nexport type UseGoalOptions = EmbeddedGoalClientOverride &\n SessionEventFeedOptions & {\n /** Optional safety-net polling (ms). Off by default — event refreshes drive updates. */\n pollIntervalMs?: number | undefined;\n };\n\nexport type UseGoalResult = {\n /** The session goal, or null when the session has none. */\n goal: SessionGoal | null;\n /** Convenience flags over `goal.status`. */\n isActive: boolean;\n isPaused: boolean;\n isCompleted: boolean;\n loading: boolean;\n error: Error | null;\n refresh: () => Promise<void>;\n /** Pause the goal loop (PATCH status=paused). */\n pause: (rationale?: string) => Promise<SessionGoal | null>;\n /** Resume a paused goal: resets counters and re-arms continuations. */\n resume: () => Promise<SessionGoal | null>;\n /** Clear the session goal; goal-less sessions remain a successful no-op. */\n clearGoal: () => Promise<void>;\n /** Alias for `clearGoal`. */\n deleteGoal: () => Promise<void>;\n /** True while a pause/resume/clear is in flight. */\n updating: boolean;\n mutationError: Error | null;\n clearMutationError: () => void;\n};\n\n/**\n * The session's goal: state, the autonomy counters (`autoContinuations`,\n * `noProgressStreak`), and pause/resume control. A goal-less session yields\n * `goal: null` (the 404 is absorbed). Live-updates on goal, turn, session,\n * control, and system-update events — pass `options.events` from\n * `useSessionEvents` to reuse its stream.\n */\nexport function useGoal(\n sessionId: string | null | undefined,\n options: UseGoalOptions = {},\n): UseGoalResult {\n const { client, workspaceId } = useEmbeddedGoal(options);\n const enabled = (options.enabled ?? true) && Boolean(sessionId);\n const sharedEvents = options.events;\n const sharedFeed = sharedEvents !== undefined;\n const pageLive = usePageLiveActivity();\n const [goal, setGoal] = useState<SessionGoal | null>(null);\n const [loading, setLoading] = useState(enabled);\n const [error, setError] = useState<Error | null>(null);\n const { run, mutating, mutationError, clearMutationError } = useMutationRunner();\n const generation = useRef(0);\n const targetKeyRef = useRef<string | null>(null);\n const loadAbort = useRef<AbortController | null>(null);\n\n const retireLoads = useCallback(() => {\n generation.current += 1;\n loadAbort.current?.abort();\n loadAbort.current = null;\n }, []);\n\n const load = useCallback(async (): Promise<void> => {\n if (!sessionId) {\n return;\n }\n const ticket = ++generation.current;\n loadAbort.current?.abort();\n const controller = new AbortController();\n loadAbort.current = controller;\n try {\n const fetched = await client.getGoal(workspaceId, sessionId, {\n signal: controller.signal,\n });\n if (ticket === generation.current) {\n setGoal(fetched);\n setError(null);\n setLoading(false);\n }\n } catch (cause) {\n if (ticket !== generation.current) {\n return;\n }\n if (cause instanceof OpenGeniApiError && cause.status === 404) {\n // No goal is a normal state, not an error.\n setGoal(null);\n setError(null);\n } else {\n setError(normalizeError(cause));\n }\n setLoading(false);\n } finally {\n if (loadAbort.current === controller) loadAbort.current = null;\n }\n }, [client, workspaceId, sessionId]);\n\n useEffect(() => {\n const targetKey = `${workspaceId} ${sessionId ?? \"\"}`;\n if (targetKeyRef.current !== targetKey) {\n targetKeyRef.current = targetKey;\n setGoal(null);\n setError(null);\n }\n if (!enabled || !pageLive) {\n retireLoads();\n setLoading(false);\n return;\n }\n if (sharedFeed) {\n // A shared log supplies invalidations, not the authoritative goal snapshot.\n setLoading(true);\n void load();\n return () => {\n retireLoads();\n };\n }\n setLoading(true);\n const pollIntervalMs = options.pollIntervalMs;\n if (pollIntervalMs === undefined || pollIntervalMs <= 0) {\n void load();\n return () => {\n retireLoads();\n };\n }\n let cancelled = false;\n let timer: ReturnType<typeof setTimeout> | null = null;\n const schedule = () => {\n if (cancelled) return;\n timer = setTimeout(() => {\n timer = null;\n void load().finally(schedule);\n }, pollIntervalMs);\n };\n void load().finally(schedule);\n return () => {\n cancelled = true;\n if (timer !== null) clearTimeout(timer);\n retireLoads();\n };\n }, [\n load,\n enabled,\n pageLive,\n workspaceId,\n sessionId,\n options.pollIntervalMs,\n retireLoads,\n sharedFeed,\n ]);\n\n const scheduleRefresh = useDebouncedCallback(() => void load());\n useSessionEventTrigger(client, workspaceId, sessionId, isGoalRefreshEvent, scheduleRefresh, {\n enabled,\n ...(sharedEvents !== undefined ? { events: sharedEvents } : {}),\n });\n\n const pause = useCallback(\n async (rationale?: string): Promise<SessionGoal | null> => {\n if (!sessionId) {\n return null;\n }\n const result = await run(() =>\n client.updateGoal(workspaceId, sessionId, {\n status: \"paused\",\n ...(rationale !== undefined ? { rationale } : {}),\n }),\n );\n if (result) {\n setGoal(result);\n }\n return result;\n },\n [client, workspaceId, sessionId, run],\n );\n\n const resume = useCallback(async (): Promise<SessionGoal | null> => {\n if (!sessionId) {\n return null;\n }\n const result = await run(() => client.updateGoal(workspaceId, sessionId, { status: \"active\" }));\n if (result) {\n setGoal(result);\n }\n return result;\n }, [client, workspaceId, sessionId, run]);\n\n const clearGoal = useCallback(async (): Promise<void> => {\n if (!sessionId) {\n return;\n }\n // deleteGoal resolves void, so distinguish success (a truthy sentinel) from\n // mutation.run's null-on-failure. Only a SUCCESSFUL delete hides the goal:\n // a failed one leaves the pill up so its mutationError renders. And invalidate\n // any in-flight load first so a slower getGoal started before the delete can't\n // commit and repopulate the just-cleared goal.\n const ok = await run(async () => {\n await client.deleteGoal(workspaceId, sessionId);\n return true as const;\n });\n if (ok) {\n retireLoads();\n setGoal(null);\n setError(null);\n }\n }, [client, workspaceId, sessionId, run, retireLoads]);\n\n return {\n goal,\n isActive: goal?.status === \"active\",\n isPaused: goal?.status === \"paused\",\n isCompleted: goal?.status === \"completed\",\n loading,\n error,\n refresh: load,\n pause,\n resume,\n clearGoal,\n deleteGoal: clearGoal,\n updating: mutating,\n mutationError,\n clearMutationError,\n };\n}\n","import type {\n SessionEvent,\n SessionMcpApprovalPolicy,\n SessionMcpApprovalPolicyTarget,\n UpdateSessionMcpApprovalPolicyResponse,\n} from \"@opengeni/sdk\";\nimport { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport {\n useEmbeddedSessionMcpApprovalPolicy,\n type EmbeddedSessionMcpApprovalPolicyClientOverride,\n} from \"../session-context\";\nimport {\n useDebouncedCallback,\n useMutationRunner,\n usePolledValue,\n useSessionEventTrigger,\n type SessionEventFeedOptions,\n} from \"./internal\";\n\nexport function isSessionMcpApprovalPolicyEvent(\n event: Pick<SessionEvent, \"type\" | \"payload\">,\n serverId?: string,\n): boolean {\n if (event.type !== \"session.mcp.approval_policy.updated\") {\n return false;\n }\n if (serverId === undefined) {\n return true;\n }\n const payload = event.payload as { serverId?: unknown } | null;\n return payload?.serverId === serverId;\n}\n\nexport type UseSessionMcpApprovalPolicyOptions = EmbeddedSessionMcpApprovalPolicyClientOverride &\n SessionEventFeedOptions & {\n /** Optional safety-net polling (ms). Off by default; policy events drive refreshes. */\n pollIntervalMs?: number | undefined;\n };\n\nexport type UseSessionMcpApprovalPolicyResult = {\n server: SessionMcpApprovalPolicyTarget | null;\n policy: SessionMcpApprovalPolicy | null;\n loading: boolean;\n error: Error | null;\n refresh: () => Promise<void>;\n update: (\n policy: SessionMcpApprovalPolicy,\n ) => Promise<UpdateSessionMcpApprovalPolicyResponse | null>;\n updating: boolean;\n clearError: () => void;\n};\n\n/**\n * Read and update one existing session MCP server's approval policy. Updates\n * become effective for the next claimed attempt; current work is unchanged.\n */\nexport function useSessionMcpApprovalPolicy(\n sessionId: string | null | undefined,\n serverId: string | null | undefined,\n options: UseSessionMcpApprovalPolicyOptions = {},\n): UseSessionMcpApprovalPolicyResult {\n const { client, workspaceId } = useEmbeddedSessionMcpApprovalPolicy(options);\n const enabled = (options.enabled ?? true) && Boolean(sessionId && serverId);\n const [override, setOverride] = useState<SessionMcpApprovalPolicyTarget | null>(null);\n const targetKey = `${workspaceId}\\u0000${sessionId ?? \"\"}\\u0000${serverId ?? \"\"}`;\n const authoritativeGeneration = useRef(0);\n const mutationIdentity = useMemo(() => ({ client, targetKey }), [client, targetKey]);\n const { run, mutating, mutationError, clearMutationError } = useMutationRunner(mutationIdentity);\n\n useLayoutEffect(() => {\n authoritativeGeneration.current += 1;\n setOverride(null);\n }, [client, targetKey]);\n\n type PolicyRead = {\n targetKey: string;\n generation: number;\n server: SessionMcpApprovalPolicyTarget | null;\n };\n const load = useCallback(async (): Promise<PolicyRead> => {\n const generation = authoritativeGeneration.current;\n if (!sessionId || !serverId) {\n return { targetKey, generation, server: null };\n }\n const session = await client.getSession(workspaceId, sessionId);\n return {\n targetKey,\n generation,\n server:\n session.mcpServers.find((server) => server.id === serverId) ??\n (session.mcpApprovalPolicies && Object.hasOwn(session.mcpApprovalPolicies, serverId)\n ? {\n id: serverId,\n source: \"workspace\",\n requireApproval: session.mcpApprovalPolicies[serverId]!,\n }\n : null),\n };\n }, [client, serverId, sessionId, targetKey, workspaceId]);\n const {\n data,\n loading,\n error: loadError,\n refresh,\n } = usePolledValue(load, {\n enabled,\n pollIntervalMs: options.pollIntervalMs,\n });\n useEffect(() => {\n if (data?.targetKey === targetKey && data.generation === authoritativeGeneration.current) {\n setOverride(null);\n }\n }, [data, targetKey]);\n\n const scheduleRefresh = useDebouncedCallback(() => void refresh());\n const matchesPolicyEvent = useCallback(\n (event: Pick<SessionEvent, \"type\" | \"payload\">) =>\n isSessionMcpApprovalPolicyEvent(event, serverId ?? undefined),\n [serverId],\n );\n useSessionEventTrigger(\n client,\n workspaceId,\n sessionId,\n matchesPolicyEvent,\n scheduleRefresh,\n {\n enabled,\n ...(options.events !== undefined ? { events: options.events } : {}),\n },\n async () => await refresh(),\n );\n\n const update = useCallback(\n async (\n policy: SessionMcpApprovalPolicy,\n ): Promise<UpdateSessionMcpApprovalPolicyResponse | null> => {\n if (!sessionId || !serverId) {\n return null;\n }\n const response = await run(() =>\n client.updateSessionMcpApprovalPolicy(workspaceId, sessionId, serverId, {\n requireApproval: policy,\n }),\n );\n if (response) {\n authoritativeGeneration.current += 1;\n setOverride(response.server);\n void refresh();\n }\n return response;\n },\n [client, refresh, run, serverId, sessionId, workspaceId],\n );\n\n const server = override ?? data?.server ?? null;\n return {\n server,\n policy: server?.requireApproval ?? null,\n loading,\n error: mutationError ?? loadError,\n refresh: async () => {\n await refresh();\n },\n update,\n updating: mutating,\n clearError: clearMutationError,\n };\n}\n","import type { SessionEvent, SessionLineageResponse } from \"@opengeni/sdk\";\nimport { useCallback, useEffect, useRef } from \"react\";\nimport {\n useEmbeddedSessionLineage,\n type EmbeddedSessionLineageClientOverride,\n} from \"../session-context\";\nimport { useDebouncedCallback, usePolledValue, useSessionEventTrigger } from \"./internal\";\n\nexport type UseSessionLineageOptions = EmbeddedSessionLineageClientOverride & {\n events?: SessionEvent[] | undefined;\n /** Refresh interval (ms). Off by default. */\n pollIntervalMs?: number | undefined;\n enabled?: boolean | undefined;\n /** Optional shared causal clock invoked when each network read starts. */\n beginRead?: (() => number) | undefined;\n};\n\nexport type UseSessionLineageResult = {\n lineage: SessionLineageResponse | null;\n loading: boolean;\n error: Error | null;\n /** Causal generation captured when the accepted lineage read started. */\n readGeneration: number;\n refresh: () => Promise<void>;\n};\n\nexport function isLineageRefreshEvent(event: SessionEvent): boolean {\n if (event.type === \"session.status.changed\" || event.type === \"session.created\") {\n return true;\n }\n // A child's creation never appears on the PARENT's stream as session.created —\n // the parent sees its own spawn as an agent.toolCall.* for session_create.\n // Created events are handled separately so they can refresh immediately and\n // once after the child row has had time to commit.\n if (event.type === \"agent.toolCall.output\") {\n const payload = event.payload as { name?: unknown; toolName?: unknown } | null | undefined;\n const name =\n typeof payload?.name === \"string\"\n ? payload.name\n : typeof payload?.toolName === \"string\"\n ? payload.toolName\n : \"\";\n return name === \"session_create\" || name.endsWith(\"__session_create\");\n }\n return false;\n}\n\nfunction isSessionCreateToolCallCreated(event: SessionEvent): boolean {\n if (event.type !== \"agent.toolCall.created\") {\n return false;\n }\n const payload = event.payload as { name?: unknown; toolName?: unknown } | null | undefined;\n const name =\n typeof payload?.name === \"string\"\n ? payload.name\n : typeof payload?.toolName === \"string\"\n ? payload.toolName\n : \"\";\n return name === \"session_create\" || name.endsWith(\"__session_create\");\n}\n\n/** Read the ancestors + descendant tree for one session. Data-only; no UI state. */\nexport function useSessionLineage(\n sessionId: string | null | undefined,\n options: UseSessionLineageOptions = {},\n): UseSessionLineageResult {\n const { client, workspaceId, workspaceControlEvent, registerSessionReconciler } =\n useEmbeddedSessionLineage(options);\n const enabled = (options.enabled ?? true) && Boolean(sessionId);\n const nextReadGeneration = useRef(0);\n const beginRead = options.beginRead;\n const load = useCallback(\n async (signal?: AbortSignal) => {\n if (!sessionId) {\n return {\n lineage: { ancestors: [], children: [], truncated: false },\n readGeneration: 0,\n };\n }\n let readGeneration = 0;\n const lineage = await client.getSessionLineage(workspaceId, sessionId, {\n signal,\n onRequestStart: (sharedReadGeneration) => {\n readGeneration = sharedReadGeneration ?? beginRead?.() ?? ++nextReadGeneration.current;\n },\n });\n return {\n lineage,\n readGeneration,\n };\n },\n [beginRead, client, workspaceId, sessionId],\n );\n const state = usePolledValue(load, { pollIntervalMs: options.pollIntervalMs, enabled });\n const refresh = state.refresh;\n useEffect(() => {\n if (enabled && workspaceControlEvent) void refresh();\n }, [enabled, refresh, workspaceControlEvent]);\n useEffect(() => {\n if (!sessionId || !enabled) return;\n return registerSessionReconciler(sessionId, \"lineage\", refresh);\n }, [enabled, refresh, registerSessionReconciler, sessionId]);\n const refreshSoon = useDebouncedCallback(() => void refresh(), 150);\n const delayedChildRefreshRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n // Clear a pending delayed refresh on session/workspace SWITCH (not just\n // unmount): otherwise a timer scheduled for the previous session can fire\n // ~2.5s later and commit that session's lineage onto the new one.\n useEffect(() => {\n return () => {\n if (delayedChildRefreshRef.current !== null) {\n clearTimeout(delayedChildRefreshRef.current);\n delayedChildRefreshRef.current = null;\n }\n };\n }, [sessionId, workspaceId]);\n const refreshAfterChildCreate = useCallback(() => {\n void refresh();\n if (delayedChildRefreshRef.current !== null) {\n clearTimeout(delayedChildRefreshRef.current);\n }\n delayedChildRefreshRef.current = setTimeout(() => {\n delayedChildRefreshRef.current = null;\n void refresh();\n }, 2500);\n }, [refresh]);\n useSessionEventTrigger(\n client,\n workspaceId,\n sessionId,\n isLineageRefreshEvent,\n refreshSoon,\n // SHARED-FEED ONLY: without a caller-provided events log the trigger would\n // open its OWN streamEvents tail — a second live SSE connection next to the\n // session route's useSessionEvents. A caller with no feed opts into polling\n // (pollIntervalMs), never a duplicate stream.\n { events: options.events, enabled: enabled && options.events !== undefined },\n );\n useSessionEventTrigger(\n client,\n workspaceId,\n sessionId,\n isSessionCreateToolCallCreated,\n refreshAfterChildCreate,\n { events: options.events, enabled: enabled && options.events !== undefined },\n );\n return {\n lineage: state.data?.lineage ?? null,\n loading: state.loading,\n error: state.error,\n readGeneration: state.data?.readGeneration ?? 0,\n refresh,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAqBA,IAAM,kBAAkB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAQO,SAAS,4BACd,MACA,UAA8C,CAAC,GACpB;AAC3B,QAAM,YAAY,QAAQ,aAAa,CAAC;AACxC,QAAM,SAAS,CAAC;AAChB,aAAW,OAAO,iBAAiB;AACjC,UAAM,WAAW,UAAU,GAAG;AAC9B,UAAM,SAAS,YAAY,KAAK,GAAG;AACnC,QAAI,OAAO,WAAW,YAAY;AAChC,YAAM,IAAI,UAAU,+CAA+C,GAAG,EAAE;AAAA,IAC1E;AACA,WAAO,GAAG,IAAI,OAAO,KAAK,aAAa,SAAY,OAAO,SAAS;AAAA,EACrE;AAEA,QAAM,oBAAoB,UAAU;AACpC,QAAM,gBAAgB,KAAK;AAC3B,QAAM,kBAAkB,qBAAqB;AAC7C,MAAI,OAAO,oBAAoB,YAAY;AACzC,WAAO,6BAA6B,gBAAgB;AAAA,MAClD,sBAAsB,SAAY,OAAO;AAAA,IAC3C;AAAA,EACF;AAEA,QAAM,WAAW,QAAQ;AACzB,MAAI,CAAC,SAAU,QAAO;AAEtB,QAAM,mBAAmB,OAAO;AAChC,SAAO,mBAAmB,OAAO,aAAa,cAC5C,SAAS,MAAM,iBAAiB,aAAa,SAAS,GAAG;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AAW,QAAQ,WAAW,OAAU;AAAA,EAC7E;AACA,SAAO;AAAA,IACL,SAAS,MAAM,MAAM,WAAW;AAAA,IAChC,SAAS,MAAM;AAAA,IACf,OAAO,MAAM;AAAA,IACb,gBAAgB,MAAM,MAAM,kBAAkB;AAAA,IAC9C;AAAA,EACF;AACF;","names":["useCallback","useEffect","useRef","useState","useState","useRef","useCallback","server","useEffect","useCallback","useEffect","useRef","useRef","useCallback","useEffect"]}
@@ -1,10 +1,11 @@
1
1
  import {
2
2
  InteractionInterventionBanner,
3
+ isInteractionControlUnavailable,
3
4
  isNonRetryableInteractionError,
4
5
  isSourcePlacementChangedError,
5
6
  useInteractionInterventions,
6
7
  useInteractionInvalidation
7
- } from "./chunk-YSMMDOOE.js";
8
+ } from "./chunk-GISEVGS6.js";
8
9
  import {
9
10
  copyTextToClipboard
10
11
  } from "./chunk-JVYQRRC4.js";
@@ -22,7 +23,7 @@ import {
22
23
  } from "./chunk-5J4FOW6Q.js";
23
24
  import {
24
25
  usePageLiveActivity
25
- } from "./chunk-KZ73RL76.js";
26
+ } from "./chunk-YQEAA6LT.js";
26
27
  import {
27
28
  useEmbeddedComputerInteraction
28
29
  } from "./chunk-NEXLLTP4.js";
@@ -452,6 +453,7 @@ function useComputerSession(options) {
452
453
  requestRef.current.controller?.abort();
453
454
  const controller = new AbortController();
454
455
  requestRef.current = { id, controller };
456
+ let discoveryCompleted = false;
455
457
  try {
456
458
  const [session, targetResponse] = await Promise.all([
457
459
  client.getComputerSession(workspaceId, computerSessionId, {
@@ -461,6 +463,7 @@ function useComputerSession(options) {
461
463
  signal: controller.signal
462
464
  })
463
465
  ]);
466
+ discoveryCompleted = true;
464
467
  if (!mountedRef.current || requestRef.current.id !== id) return;
465
468
  const targets = sortComputerTargets(targetResponse.targets);
466
469
  const selected = chooseTarget(targets, selectedTargetIdRef.current, session.platform);
@@ -477,7 +480,8 @@ function useComputerSession(options) {
477
480
  selectedTargetId: selected?.id ?? null,
478
481
  observation: retainedObservation,
479
482
  loading: false,
480
- error: null
483
+ error: null,
484
+ controlError: null
481
485
  } : current
482
486
  );
483
487
  const observation = selected ? await client.observeComputerTarget(workspaceId, computerSessionId, selected.id, {
@@ -500,11 +504,16 @@ function useComputerSession(options) {
500
504
  );
501
505
  } catch (cause) {
502
506
  if (controller.signal.aborted || !mountedRef.current || requestRef.current.id !== id) return;
507
+ const error = cause instanceof Error ? cause : new Error(String(cause));
503
508
  setState(
504
509
  (current) => current.computerSessionId === computerSessionId ? {
505
510
  ...current,
506
511
  loading: false,
507
- error: cause instanceof Error ? cause : new Error(String(cause))
512
+ error,
513
+ controlError: isInteractionControlUnavailable(
514
+ error,
515
+ discoveryCompleted ? "observation" : "control"
516
+ ) ? error : current.controlError
508
517
  } : current
509
518
  );
510
519
  } finally {
@@ -561,11 +570,19 @@ function useComputerSession(options) {
561
570
  (current) => current.computerSessionId === scopeComputerSessionId ? { ...current, mutating: true, error: null } : current
562
571
  );
563
572
  try {
564
- return await operation();
573
+ const result = await operation();
574
+ setState(
575
+ (current) => current.computerSessionId === scopeComputerSessionId ? { ...current, controlError: null } : current
576
+ );
577
+ return result;
565
578
  } catch (cause) {
566
579
  const error = cause instanceof Error ? cause : new Error(String(cause));
567
580
  setState(
568
- (current) => current.computerSessionId === scopeComputerSessionId ? { ...current, error } : current
581
+ (current) => current.computerSessionId === scopeComputerSessionId ? {
582
+ ...current,
583
+ error,
584
+ controlError: isInteractionControlUnavailable(error) ? error : current.controlError
585
+ } : current
569
586
  );
570
587
  throw error;
571
588
  } finally {
@@ -612,7 +629,12 @@ function useComputerSession(options) {
612
629
  } catch (cause) {
613
630
  const error = cause instanceof Error ? cause : new Error(String(cause));
614
631
  setState(
615
- (current) => current.computerSessionId === computerSessionId && current.selectedTargetId === target.id ? { ...current, loading: false, error } : current
632
+ (current) => current.computerSessionId === computerSessionId && current.selectedTargetId === target.id ? {
633
+ ...current,
634
+ loading: false,
635
+ error,
636
+ controlError: isInteractionControlUnavailable(error, "observation") ? error : current.controlError
637
+ } : current
616
638
  );
617
639
  throw error;
618
640
  }
@@ -684,7 +706,19 @@ function useComputerSession(options) {
684
706
  );
685
707
  const readClipboard = useCallback2(async () => {
686
708
  if (!computerSessionId) throw new Error("No desktop is selected.");
687
- return await client.readComputerClipboard(workspaceId, computerSessionId);
709
+ try {
710
+ return await client.readComputerClipboard(workspaceId, computerSessionId);
711
+ } catch (cause) {
712
+ const error = cause instanceof Error ? cause : new Error(String(cause));
713
+ setState(
714
+ (current) => current.computerSessionId === computerSessionId ? {
715
+ ...current,
716
+ error,
717
+ controlError: isInteractionControlUnavailable(error) ? error : current.controlError
718
+ } : current
719
+ );
720
+ throw error;
721
+ }
688
722
  }, [client, computerSessionId, workspaceId]);
689
723
  return {
690
724
  session: visible.session,
@@ -694,6 +728,7 @@ function useComputerSession(options) {
694
728
  loading: visible.loading,
695
729
  mutating: visible.mutating,
696
730
  error: visible.error,
731
+ controlError: visible.controlError,
697
732
  refresh,
698
733
  readClipboard,
699
734
  selectTarget,
@@ -710,7 +745,8 @@ function emptyState(computerSessionId, loading) {
710
745
  observation: null,
711
746
  loading,
712
747
  mutating: false,
713
- error: null
748
+ error: null,
749
+ controlError: null
714
750
  };
715
751
  }
716
752
  function chooseTarget(targets, preferredId, platform) {
@@ -1084,7 +1120,9 @@ function ComputerViewer({
1084
1120
  const displayedFrame = frames.frame && frames.frame.computerSessionId === selection?.sessionId && frames.frame.targetId === computer.selectedTarget?.id && frames.frame.targetGeneration === computer.selectedTarget?.targetGeneration ? frames.frame : null;
1085
1121
  const rfbStream = frames.attachment?.stream.kind === "direct_rfb" ? frames.attachment.stream : null;
1086
1122
  const machineLocked = selectedRegistrySession?.failureCode === "machine_locked";
1087
- const rfbInputEnabled = !machineLocked && computer.session?.capabilities?.pointerInput === true && computer.session?.capabilities?.keyboardInput === true;
1123
+ const controlUnavailable = computer.controlError !== null;
1124
+ const connectionState = controlUnavailable ? "error" : frames.state;
1125
+ const rfbInputEnabled = !machineLocked && !controlUnavailable && computer.session?.capabilities?.pointerInput === true && computer.session?.capabilities?.keyboardInput === true;
1088
1126
  const rfbCapability = useMemo2(() => {
1089
1127
  if (!rfbStream || !frames.attachment) return null;
1090
1128
  const bounds = computer.selectedTarget?.bounds;
@@ -1192,6 +1230,7 @@ function ComputerViewer({
1192
1230
  ]);
1193
1231
  const perform = useCallback4(
1194
1232
  async (action, frame) => {
1233
+ if (computer.controlError) throw computer.controlError;
1195
1234
  let receipt;
1196
1235
  if (action.type === "pointer") {
1197
1236
  if (!frame) throw new Error("Desktop view is not ready for pointer input.");
@@ -1203,8 +1242,12 @@ function ComputerViewer({
1203
1242
  throw new Error(receipt.error?.message ?? "Desktop input did not complete.");
1204
1243
  }
1205
1244
  },
1206
- [act, actFromFrame]
1245
+ [act, actFromFrame, computer.controlError]
1207
1246
  );
1247
+ const reconnect = () => {
1248
+ void refreshComputer();
1249
+ frames.reconnect();
1250
+ };
1208
1251
  const copyFromRfb = useCallback4(
1209
1252
  (event) => {
1210
1253
  if (!rfbInputEnabled || !rfbStream || computer.session?.capabilities?.clipboard !== true)
@@ -1298,7 +1341,7 @@ function ComputerViewer({
1298
1341
  },
1299
1342
  onCreate: hideGenericCreate ? void 0 : createComputer,
1300
1343
  onRefresh: () => {
1301
- if (frames.state === "error" && !generationLossSelected && !generationLossFrames) {
1344
+ if (connectionState === "error" && !generationLossSelected && !generationLossFrames) {
1302
1345
  frames.reconnect();
1303
1346
  }
1304
1347
  void Promise.all([refreshRegistry(), refreshComputer()]);
@@ -1356,7 +1399,19 @@ function ComputerViewer({
1356
1399
  className: "h-full"
1357
1400
  }
1358
1401
  ),
1359
- !rfbInputEnabled ? /* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute bottom-3 left-1/2 -translate-x-1/2 rounded-full border border-white/10 bg-black/70 px-3 py-1 text-[11px] text-white/80 backdrop-blur", children: "View only \xB7 direct input unavailable" }) : null
1402
+ !rfbInputEnabled ? /* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute bottom-3 left-1/2 -translate-x-1/2 rounded-full border border-white/10 bg-black/70 px-3 py-1 text-[11px] text-white/80 backdrop-blur", children: controlUnavailable ? /* @__PURE__ */ jsxs(Fragment, { children: [
1403
+ "Desktop controls unavailable",
1404
+ " ",
1405
+ /* @__PURE__ */ jsx(
1406
+ "button",
1407
+ {
1408
+ type: "button",
1409
+ onClick: reconnect,
1410
+ className: "pointer-events-auto ml-2 font-medium underline",
1411
+ children: "Reconnect"
1412
+ }
1413
+ )
1414
+ ] }) : "View only \xB7 direct input unavailable" }) : null
1360
1415
  ] }) : /* @__PURE__ */ jsx(
1361
1416
  ComputerViewport,
1362
1417
  {
@@ -1364,16 +1419,18 @@ function ComputerViewer({
1364
1419
  observation: computer.observation,
1365
1420
  target: computer.selectedTarget,
1366
1421
  machineLocked,
1367
- connectionState: frames.state,
1368
- connectionError: frames.error ?? computer.error,
1422
+ controlUnavailable,
1423
+ connectionState,
1424
+ connectionError: computer.controlError ?? frames.error ?? computer.error,
1369
1425
  mutating: computer.mutating,
1370
1426
  backgroundActions: computer.session?.capabilities?.backgroundActions === true,
1427
+ backgroundInput: computer.session?.capabilities?.backgroundInput === true,
1371
1428
  clipboardEnabled: computer.session?.capabilities?.clipboard === true,
1372
1429
  pointerInput: computer.session?.capabilities?.pointerInput === true,
1373
1430
  keyboardInput: computer.session?.capabilities?.keyboardInput === true,
1374
1431
  onAction: perform,
1375
1432
  onReadClipboard: computer.readClipboard,
1376
- onReconnect: generationLossSelected || generationLossFrames ? () => void 0 : frames.reconnect,
1433
+ onReconnect: generationLossSelected || generationLossFrames ? () => void 0 : reconnect,
1377
1434
  onError: (cause) => notifyError(cause, "Desktop input failed.")
1378
1435
  },
1379
1436
  JSON.stringify([
@@ -1387,7 +1444,8 @@ function ComputerViewer({
1387
1444
  ComputerSemanticPanel,
1388
1445
  {
1389
1446
  observation: computer.observation,
1390
- mutating: computer.mutating,
1447
+ mutating: computer.mutating || controlUnavailable,
1448
+ controlUnavailable,
1391
1449
  onAction: (action) => void perform(action, null).catch(
1392
1450
  (cause) => notifyError(cause, "Desktop action failed.")
1393
1451
  )
@@ -1399,10 +1457,11 @@ function ComputerViewer({
1399
1457
  {
1400
1458
  session: computer.session,
1401
1459
  target: computer.selectedTarget,
1402
- connectionState: frames.state,
1460
+ connectionState,
1461
+ controlUnavailable,
1403
1462
  refreshing: registry.refreshing,
1404
1463
  showControls,
1405
- controlCount: semanticNodes(computer.observation).length,
1464
+ controlCount: semanticControls(computer.observation).length,
1406
1465
  onToggleControls: () => setShowControls((current) => !current)
1407
1466
  }
1408
1467
  )
@@ -1627,6 +1686,7 @@ function ComputerLifecyclePanel(props) {
1627
1686
  function ComputerViewport(props) {
1628
1687
  const canvasRef = useRef4(null);
1629
1688
  const inputRef = useRef4(null);
1689
+ const composingRef = useRef4(false);
1630
1690
  const pointerStartRef = useRef4(null);
1631
1691
  const clickTimerRef = useRef4(null);
1632
1692
  const lastClickRef = useRef4(null);
@@ -1647,7 +1707,7 @@ function ComputerViewport(props) {
1647
1707
  readClipboardRef.current = props.onReadClipboard;
1648
1708
  errorRef.current = props.onError;
1649
1709
  const streamFailed = props.connectionState === "error";
1650
- const rawInputEnabled = !streamFailed && !props.machineLocked && (!props.backgroundActions || props.target?.kind === "screen" || props.target?.focused === true);
1710
+ const rawInputEnabled = !streamFailed && !props.controlUnavailable && !props.machineLocked && (props.backgroundInput || !props.backgroundActions || props.target?.kind === "screen" || props.target?.focused === true);
1651
1711
  const clearBufferedInput = useCallback4(() => {
1652
1712
  if (clickTimerRef.current) clearTimeout(clickTimerRef.current);
1653
1713
  if (wheelRef.current?.timer) clearTimeout(wheelRef.current.timer);
@@ -1657,10 +1717,25 @@ function ComputerViewport(props) {
1657
1717
  pendingTextRef.current = null;
1658
1718
  pointerStartRef.current = null;
1659
1719
  lastClickRef.current = null;
1720
+ composingRef.current = false;
1660
1721
  if (inputRef.current) inputRef.current.value = "";
1661
1722
  }, []);
1662
1723
  const pointerInputEnabled = rawInputEnabled && props.pointerInput;
1663
1724
  const keyboardInputEnabled = rawInputEnabled && props.keyboardInput;
1725
+ useLayoutEffect(() => {
1726
+ const canvas = canvasRef.current;
1727
+ const viewport = canvas?.parentElement;
1728
+ if (!canvas || !viewport) return;
1729
+ const fit = () => fitComputerCanvas(canvas);
1730
+ fit();
1731
+ if (typeof ResizeObserver === "undefined") {
1732
+ window.addEventListener("resize", fit);
1733
+ return () => window.removeEventListener("resize", fit);
1734
+ }
1735
+ const observer = new ResizeObserver(fit);
1736
+ observer.observe(viewport);
1737
+ return () => observer.disconnect();
1738
+ }, []);
1664
1739
  const paintQueuedFrames = useCallback4(() => {
1665
1740
  if (decodingFrameRef.current) return;
1666
1741
  decodingFrameRef.current = true;
@@ -1925,6 +2000,9 @@ function ComputerViewport(props) {
1925
2000
  };
1926
2001
  const keyDown = (event) => {
1927
2002
  if (!keyboardInputEnabled) return;
2003
+ if (composingRef.current || event.nativeEvent.isComposing || event.nativeEvent.keyCode === 229) {
2004
+ return;
2005
+ }
1928
2006
  flushPendingWheel();
1929
2007
  const command = event.metaKey || event.ctrlKey;
1930
2008
  if (props.clipboardEnabled && command && !event.altKey && ["c", "v"].includes(event.key.toLowerCase())) {
@@ -1970,7 +2048,8 @@ function ComputerViewport(props) {
1970
2048
  await dispatch({ type: "clipboard", operation: "paste" }, null);
1971
2049
  });
1972
2050
  };
1973
- const input = (value) => {
2051
+ const input = (value, nativeComposing = false) => {
2052
+ if (composingRef.current || nativeComposing) return;
1974
2053
  if (!value || !keyboardInputEnabled) return;
1975
2054
  flushPendingWheel();
1976
2055
  flushPendingClick();
@@ -1987,6 +2066,10 @@ function ComputerViewport(props) {
1987
2066
  }
1988
2067
  if (inputRef.current) inputRef.current.value = "";
1989
2068
  };
2069
+ const compositionEnd = (event) => {
2070
+ composingRef.current = false;
2071
+ input(event.currentTarget.value || event.data);
2072
+ };
1990
2073
  const showCanvas = props.frame !== null && paintedFrame !== null && sameComputerTarget(props.frame, paintedFrame) && !props.machineLocked && !streamFailed;
1991
2074
  return /* @__PURE__ */ jsxs("div", { className: "relative min-h-0 flex-1 overflow-hidden bg-black", children: [
1992
2075
  /* @__PURE__ */ jsx(
@@ -2013,7 +2096,11 @@ function ComputerViewport(props) {
2013
2096
  {
2014
2097
  ref: inputRef,
2015
2098
  defaultValue: "",
2016
- onInput: (event) => input(event.currentTarget.value),
2099
+ onInput: (event) => input(event.currentTarget.value, event.nativeEvent.isComposing),
2100
+ onCompositionStart: () => {
2101
+ composingRef.current = true;
2102
+ },
2103
+ onCompositionEnd: compositionEnd,
2017
2104
  onKeyDown: keyDown,
2018
2105
  onCopy: copy,
2019
2106
  onPaste: paste,
@@ -2030,6 +2117,7 @@ function ComputerViewport(props) {
2030
2117
  {
2031
2118
  observation: props.observation,
2032
2119
  machineLocked: props.machineLocked,
2120
+ controlUnavailable: props.controlUnavailable,
2033
2121
  connectionState: props.connectionState,
2034
2122
  error: props.connectionError,
2035
2123
  onAction: (action) => enqueue(action, null),
@@ -2069,14 +2157,14 @@ function ComputerViewportFallback(props) {
2069
2157
  ] }) });
2070
2158
  }
2071
2159
  const controlFailure = interactionControlFailureFromError(props.error);
2072
- const interactive = semanticNodes(props.observation).filter((node) => semanticAction(node) !== null).slice(0, 10);
2160
+ const interactive = semanticControls(props.observation).filter((node) => semanticAction(node) !== null).slice(0, 10);
2073
2161
  return /* @__PURE__ */ jsx("div", { className: "absolute inset-0 grid place-items-center bg-og-bg p-6", children: /* @__PURE__ */ jsxs("div", { className: "w-full max-w-md rounded-og-lg border border-og-border bg-og-surface-1 p-4 shadow-lg", children: [
2074
2162
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
2075
2163
  props.error ? /* @__PURE__ */ jsx(CircleAlertIcon, { className: "size-4 text-og-danger" }) : /* @__PURE__ */ jsx(LoaderCircleIcon, { className: "size-4 animate-spin text-og-fg-muted" }),
2076
- /* @__PURE__ */ jsx("p", { className: "text-og-menu font-medium text-og-fg", children: isAttachedChromeGenerationLossError(props.error) ? "Chrome reconnected\u2014open a fresh browser/desktop." : props.error ? "Live view disconnected" : computerConnectionLabel(props.connectionState) })
2164
+ /* @__PURE__ */ jsx("p", { className: "text-og-menu font-medium text-og-fg", children: isAttachedChromeGenerationLossError(props.error) ? "Chrome reconnected\u2014open a fresh browser/desktop." : props.controlUnavailable ? "Desktop controls unavailable" : props.error ? "Live view disconnected" : computerConnectionLabel(props.connectionState) })
2077
2165
  ] }),
2078
2166
  props.error ? /* @__PURE__ */ jsx("p", { className: "mt-2 text-og-control leading-5 text-og-fg-muted", children: isAttachedChromeGenerationLossError(props.error) ? "Chrome reconnected\u2014open a fresh browser/desktop. Use Browser \u2192 New browser \u2192 Connected Chrome." : controlFailure?.message ?? props.error.message }) : null,
2079
- interactive.length > 0 ? /* @__PURE__ */ jsxs("div", { className: "mt-3 border-t border-og-border pt-3", children: [
2167
+ interactive.length > 0 && !props.controlUnavailable ? /* @__PURE__ */ jsxs("div", { className: "mt-3 border-t border-og-border pt-3", children: [
2080
2168
  /* @__PURE__ */ jsx("p", { className: "mb-2 text-og-xs text-og-fg-subtle", children: "App controls remain available" }),
2081
2169
  /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1.5", children: interactive.map((node) => /* @__PURE__ */ jsx(
2082
2170
  "button",
@@ -2104,13 +2192,14 @@ function ComputerViewportFallback(props) {
2104
2192
  ] }) });
2105
2193
  }
2106
2194
  function ComputerSemanticPanel(props) {
2107
- const nodes = semanticNodes(props.observation).slice(0, 100);
2195
+ const nodes = semanticControls(props.observation).slice(0, 100);
2108
2196
  return /* @__PURE__ */ jsxs("aside", { className: "box-border max-h-[40%] w-full shrink-0 overflow-y-auto border-t border-og-border bg-og-surface-1 p-2 @xl/computer-viewer:max-h-none @xl/computer-viewer:w-64 @xl/computer-viewer:border-t-0 @xl/computer-viewer:border-l", children: [
2109
2197
  /* @__PURE__ */ jsxs("div", { className: "mb-2 flex items-center gap-1.5 px-1 text-og-xs font-medium uppercase tracking-[0.1em] text-og-fg-subtle", children: [
2110
2198
  /* @__PURE__ */ jsx(KeyboardIcon, { className: "size-3" }),
2111
2199
  " App controls"
2112
2200
  ] }),
2113
- nodes.length === 0 ? /* @__PURE__ */ jsx("p", { className: "px-1 py-2 text-og-control leading-5 text-og-fg-muted", children: "This view has no accessibility controls. Use the live image instead." }) : /* @__PURE__ */ jsx("div", { className: "space-y-0.5", children: nodes.map((node) => /* @__PURE__ */ jsx(
2201
+ props.controlUnavailable ? /* @__PURE__ */ jsx("p", { className: "px-1 py-2 text-og-control leading-5 text-og-fg-muted", children: "Reconnect to use app controls." }) : null,
2202
+ nodes.length === 0 ? props.controlUnavailable ? null : /* @__PURE__ */ jsx("p", { className: "px-1 py-2 text-og-control leading-5 text-og-fg-muted", children: "This view has no accessibility controls. Use the live image instead." }) : /* @__PURE__ */ jsx("div", { className: "space-y-0.5", children: nodes.map((node) => /* @__PURE__ */ jsx(
2114
2203
  ComputerSemanticControl,
2115
2204
  {
2116
2205
  node,
@@ -2199,8 +2288,8 @@ function ComputerStatusBar(props) {
2199
2288
  )
2200
2289
  }
2201
2290
  ),
2202
- /* @__PURE__ */ jsx("span", { children: props.connectionState === "live" ? "Live" : computerConnectionLabel(props.connectionState) }),
2203
- /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate", children: screen ? "Full screen \xB7 input may move pointer and focus" : props.session?.capabilities?.backgroundActions ? "Window \xB7 app controls work in the background" : props.target?.kind ?? "Desktop" }),
2291
+ /* @__PURE__ */ jsx("span", { children: props.controlUnavailable ? "Controls unavailable" : props.connectionState === "live" ? "Live" : computerConnectionLabel(props.connectionState) }),
2292
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate", children: props.controlUnavailable ? "Reconnect to use desktop input" : screen ? "Full screen \xB7 input may move pointer and focus" : props.session?.capabilities?.backgroundInput ? "Window \xB7 clicks and typing stay in the background" : props.session?.capabilities?.backgroundActions ? "Window \xB7 app controls work in the background" : props.target?.kind ?? "Desktop" }),
2204
2293
  screen ? /* @__PURE__ */ jsx(MousePointer2Icon, { className: "size-3", "aria-hidden": true }) : null,
2205
2294
  props.refreshing ? /* @__PURE__ */ jsx(LoaderCircleIcon, { className: "size-3 animate-spin" }) : null,
2206
2295
  /* @__PURE__ */ jsxs(
@@ -2236,11 +2325,30 @@ function ComputerNotice(props) {
2236
2325
  }
2237
2326
  );
2238
2327
  }
2239
- function semanticNodes(observation) {
2328
+ var structuralRoles = /* @__PURE__ */ new Set([
2329
+ "frame",
2330
+ "panel",
2331
+ "section",
2332
+ "document",
2333
+ "document web",
2334
+ "static",
2335
+ "static text",
2336
+ "heading",
2337
+ "paragraph",
2338
+ "notification",
2339
+ "separator",
2340
+ "tool bar",
2341
+ "page tab list"
2342
+ ]);
2343
+ function semanticControls(observation) {
2240
2344
  if (observation?.semantic?.kind !== "snapshot") return [];
2241
2345
  const result = [];
2242
2346
  const visit = (node) => {
2243
- result.push(node);
2347
+ const role = node.role.trim().toLowerCase();
2348
+ const label = node.name?.trim() || node.identifier?.trim();
2349
+ if (node.actions.includes("set_value") || label && label.toLowerCase() !== role && !structuralRoles.has(role) && semanticAction(node) !== null) {
2350
+ result.push(node);
2351
+ }
2244
2352
  node.children?.forEach(visit);
2245
2353
  };
2246
2354
  observation.semantic.roots.forEach(visit);
@@ -2261,11 +2369,24 @@ function semanticValue(node) {
2261
2369
  return typeof node.value === "string" ? node.value : null;
2262
2370
  }
2263
2371
  function paintCanvas(canvas, image, width, height) {
2372
+ const dimensionsChanged = canvas.width !== width || canvas.height !== height;
2264
2373
  canvas.width = width;
2265
2374
  canvas.height = height;
2266
2375
  const context = canvas.getContext("2d", { alpha: false });
2267
2376
  if (!context) throw new Error("Desktop canvas is unavailable.");
2268
2377
  context.drawImage(image, 0, 0, width, height);
2378
+ if (dimensionsChanged) fitComputerCanvas(canvas);
2379
+ }
2380
+ function fitComputerCanvas(canvas) {
2381
+ const viewport = canvas.parentElement;
2382
+ if (!viewport || canvas.width <= 0 || canvas.height <= 0) return;
2383
+ const scale = Math.min(
2384
+ viewport.clientWidth / canvas.width,
2385
+ viewport.clientHeight / canvas.height
2386
+ );
2387
+ if (!Number.isFinite(scale) || scale <= 0) return;
2388
+ canvas.style.width = `${canvas.width * scale}px`;
2389
+ canvas.style.height = `${canvas.height * scale}px`;
2269
2390
  }
2270
2391
  function loadImage(url) {
2271
2392
  return new Promise((resolve, reject) => {
@@ -2423,4 +2544,4 @@ export {
2423
2544
  ComputerViewer,
2424
2545
  computerKey
2425
2546
  };
2426
- //# sourceMappingURL=chunk-6NEZPF53.js.map
2547
+ //# sourceMappingURL=chunk-YN7I3STW.js.map