| 1 | import type { AppBindings } from "./bridge"; |
| 2 | import type { StructuredInvocationSubmit } from "./invocationDisplay"; |
| 3 | import type { CollaborationMode, ToolApprovalMode } from "./types"; |
| 4 | import { submitAttachmentTurn } from "./attachmentSubmit"; |
| 5 | import { draftSubmit } from "./draftSubmit"; |
| 6 | |
| 7 | export async function submitTurn( |
| 8 | app: AppBindings, |
| 9 | tabId: string, |
| 10 | submissionId: string, |
| 11 | display: string, |
| 12 | submit: string, |
| 13 | original: string, |
| 14 | structured?: StructuredInvocationSubmit, |
| 15 | initialGoal?: { goal: string; collaborationMode: CollaborationMode; toolApprovalMode: ToolApprovalMode }, |
| 16 | ): Promise<[number, (string | string[])?]> { |
| 17 | let receipt: unknown; |
| 18 | if (structured?.attachments?.length) receipt = await submitAttachmentTurn(app, submissionId, structured, original, initialGoal); |
| 19 | else if (initialGoal) { |
| 20 | receipt = await app.SubmitInitialGoalToTabWithID( |
| 21 | tabId, |
| 22 | initialGoal.goal, |
| 23 | structured?.display.trim() || display, |
| 24 | structured?.input.trim() || submit, |
| 25 | structured?.invocations ?? [], |
| 26 | initialGoal.collaborationMode, |
| 27 | initialGoal.toolApprovalMode, |
| 28 | submissionId, |
| 29 | ); |
| 30 | } else if (structured) receipt = await app.SubmitInvocationsToTabWithID(tabId, structured.display.trim(), structured.input.trim(), structured.invocations, submissionId); |
| 31 | else if (original) receipt = await app.SubmitEditedDisplayToTabWithID(tabId, display, submit, original, submissionId); |
| 32 | else if (display !== submit) receipt = await app.SubmitDisplayToTabWithID(tabId, display, submit, submissionId); |
| 33 | else receipt = await draftSubmit(app, tabId, submit, submissionId); |
| 34 | if (initialGoal) return [1, Array.isArray(receipt) ? receipt : []]; |
| 35 | if (receipt && typeof receipt === "object" && "disposition" in receipt && receipt.disposition === "management_handled") return [2]; |
| 36 | if (receipt && typeof receipt === "object" && "turnId" in receipt && typeof receipt.turnId === "string") return [3, receipt.turnId]; |
| 37 | return [0]; |
| 38 | } |
| 39 |