| 1 | import { app } from "../lib/bridge"; |
| 2 | import { displayedComposerProfileCollaborationMode, type ComposerProfile } from "../lib/composerProfile"; |
| 3 | import type { TabMeta } from "../lib/types"; |
| 4 | import type { StructuredInvocationSubmit } from "../lib/invocationDisplay"; |
| 5 | import type { ControllerProfileResource } from "./controllerProfileOwner"; |
| 6 | import type { InitialGoal, SubmissionPorts, SubmissionResource } from "./sessionSubmissionOwner"; |
| 7 | |
| 8 | export function createSubmissionPorts(input: { |
| 9 | send(tab: string, display: string, submit?: string, original?: string, structured?: StructuredInvocationSubmit, initialGoal?: InitialGoal): Promise<void>; |
| 10 | setGoal(tab: string, goal: string): Promise<void>; clearGoal(tab: string): Promise<void>; |
| 11 | clearUndo: SubmissionPorts["clearUndo"]; patchGoal: SubmissionPorts["patchGoal"]; profile: SubmissionPorts["profile"]; |
| 12 | }): SubmissionPorts { |
| 13 | return { clearUndo: input.clearUndo, patchGoal: input.patchGoal, profile: input.profile, |
| 14 | send: (tab, display, submit, structured, goal) => input.send(tab, display, submit, undefined, structured, goal), |
| 15 | setGoal: (tab, goal, remote) => remote ? app.SetRemoteTabGoal(tab, goal) : goal ? input.setGoal(tab, goal) : input.clearGoal(tab), |
| 16 | }; |
| 17 | } |
| 18 | |
| 19 | export function projectSubmissionResources(resources: readonly ControllerProfileResource[], tabs: readonly TabMeta[], |
| 20 | profiles: Readonly<Record<string, ComposerProfile>>, active: { tabId: string; profile: ComposerProfile; ready: boolean }, |
| 21 | messages: { starting: string; readOnly: string }): SubmissionResource[] { |
| 22 | return resources.map(resource => { |
| 23 | const tab = tabs.find(value => value.id === resource.target.tabId); |
| 24 | const profile = resource.target.tabId === active.tabId ? active.profile : profiles[resource.target.tabId]; |
| 25 | const ready = Boolean(tab?.ready && (!tab.runtime || tab.runtime.phase === "ready") && !tab.startupErr) |
| 26 | && (resource.target.tabId !== active.tabId || active.ready); |
| 27 | return { target: resource.target, remote: resource.remote, |
| 28 | ready, |
| 29 | unavailable: tab?.readOnly ? messages.readOnly : ready ? "" : tab?.runtime?.issue?.message || tab?.startupErr || messages.starting, |
| 30 | goalDraft: Boolean(profile && displayedComposerProfileCollaborationMode(profile) === "goal" && !profile.goal.trim()), |
| 31 | collaboration: resource.profile.collaboration, approval: resource.profile.approval, |
| 32 | }; |
| 33 | }); |
| 34 | } |
| 35 |