( client: HttpDaemonClient, runtime: AgentRuntimeRecord, task: QueuedTaskRecord, )
| 805 | } |
| 806 | |
| 807 | async function executeRemoteQueuedTask( |
| 808 | client: HttpDaemonClient, |
| 809 | runtime: AgentRuntimeRecord, |
| 810 | task: QueuedTaskRecord, |
| 811 | ): Promise<void> { |
| 812 | const payload = parseTaskPayload(task); |
| 813 | const channelThreadId = resolveConversationThreadId({ |
| 814 | triggerType: task.triggerType, |
| 815 | payload, |
| 816 | }); |
| 817 | const workDir = channelThreadId |
| 818 | ? getDaemonChannelWorkDirPath(ensureDaemonStateDir(), { |
| 819 | workspaceId: task.workspaceId, |
| 820 | threadId: channelThreadId, |
| 821 | agentId: task.agentId, |
| 822 | }) |
| 823 | : getWorkspaceRemoteTaskWorkDir(task.workspaceId, task.id); |
| 824 | const isPersistentConversationWorkspace = Boolean(channelThreadId); |
| 825 | if (!isPersistentConversationWorkspace) { |
| 826 | rmSync(workDir, { recursive: true, force: true }); |
| 827 | } |
| 828 | mkdirSync(workDir, { recursive: true }); |
| 829 | |
| 830 | try { |
| 831 | await client.startTask(task.id); |
| 832 | const bundle = await client.getInputBundle(task.id); |
| 833 | materializeInputBundle(workDir, bundle); |
| 834 | |
| 835 | const result = await runProviderTask( |
| 836 | runtime, |
| 837 | bundle.prompt, |
| 838 | workDir, |
| 839 | { |
| 840 | sessionId: (bundle.metadata.routerSession?.providerSessionId ?? payload.channelSessionId?.trim()) || undefined, |
| 841 | contextEnv: buildRuntimeContextEnv({ |
| 842 | AGENT_SPACE_CONTEXT_AGENT_NAME: payload.assignee ?? task.agentId, |
| 843 | AGENT_SPACE_CONTEXT_TASK_ID: task.id, |
| 844 | AGENT_SPACE_CONTEXT_TRIGGER_TYPE: task.triggerType, |
| 845 | }, bundle.metadata.googleWorkspace), |
| 846 | runtimeToolCapabilities: bundle.metadata.runtimeToolCapabilities?.capabilities ?? [], |
| 847 | onEvent: (event) => { |
| 848 | void client.reportMessages(task.id, { |
| 849 | messages: [ |
| 850 | { |
| 851 | type: event.type, |
| 852 | content: event.content, |
| 853 | tool: event.tool, |
| 854 | inputJson: event.inputJson, |
| 855 | output: event.output, |
| 856 | }, |
| 857 | ], |
| 858 | }).catch((error) => { |
| 859 | const message = error instanceof Error ? error.message : String(error); |
| 860 | console.error(`Failed to report remote task message for ${task.id}: ${message}`); |
| 861 | }); |
| 862 | }, |
| 863 | }, |
| 864 | ); |
no test coverage detected