The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import type * as AcpSchema from "effect-acp/compat"; |
| 2 | import type { AcpToolCallState } from "@t3tools/provider-acp/server/runtimeModel"; |
| 3 | import type { AcpAdapterV2SubagentUpdate } from "@t3tools/provider-acp/server/adapter"; |
| 4 | |
| 5 | function record(value: unknown): Record<string, unknown> | undefined { |
| 6 | return typeof value === "object" && value !== null && !Array.isArray(value) |
| 7 | ? (value as Record<string, unknown>) |
| 8 | : undefined; |
| 9 | } |
| 10 | |
| 11 | export function normalizeDevinSessionUpdate( |
| 12 | notification: AcpSchema.SessionNotification, |
| 13 | ): AcpSchema.SessionNotification { |
| 14 | const update = notification.update; |
| 15 | const meta = record("_meta" in update ? update._meta : undefined); |
| 16 | const parentAgentId = record(meta?.["cognition.ai/subagent_context"])?.parentAgentId; |
| 17 | const routed = |
| 18 | typeof parentAgentId === "string" && parentAgentId !== "root" |
| 19 | ? { ...notification, sessionId: parentAgentId } |
| 20 | : notification; |
| 21 | const messageId = meta?.["cognition.ai/streamingMessageId"]; |
| 22 | if ( |
| 23 | (update.sessionUpdate === "agent_message_chunk" || |
| 24 | update.sessionUpdate === "agent_thought_chunk") && |
| 25 | typeof messageId === "string" |
| 26 | ) { |
| 27 | return { ...routed, update: { ...update, messageId } }; |
| 28 | } |
| 29 | return routed; |
| 30 | } |
| 31 | |
| 32 | export function normalizeDevinToolCall(tool: AcpToolCallState): AcpToolCallState { |
| 33 | const name = record(tool.data.meta)?.["cognition.ai/inferenceToolName"]; |
| 34 | return typeof name === "string" && (!tool.title || tool.title === "Tool") |
| 35 | ? { ...tool, title: name } |
| 36 | : tool; |
| 37 | } |
| 38 | |
| 39 | export function extractDevinSubagentUpdate( |
| 40 | tool: AcpToolCallState, |
| 41 | ): AcpAdapterV2SubagentUpdate | undefined { |
| 42 | const meta = record(tool.data.meta); |
| 43 | const completed = record(meta?.["cognition.ai/subagent_completed"]); |
| 44 | const started = record(meta?.["cognition.ai/subagent_started"]); |
| 45 | const data = completed ?? started; |
| 46 | if (typeof data?.agentId !== "string") return undefined; |
| 47 | return { |
| 48 | nativeTaskId: data.agentId, |
| 49 | childSessionId: data.agentId, |
| 50 | prompt: typeof started?.task === "string" ? started.task : "", |
| 51 | title: typeof started?.title === "string" ? started.title : null, |
| 52 | model: typeof started?.model === "string" ? started.model : null, |
| 53 | status: completed ? (completed.success === false ? "failed" : "completed") : "running", |
| 54 | result: typeof completed?.summary === "string" ? completed.summary : null, |
| 55 | }; |
| 56 | } |
| 57 | |
| 58 | // Devin's plan exit offers several allow_once options in no promised order; T3 never answers with bypass. |
| 59 | export function devinAnswerablePermissionOptions( |
| 60 | request: AcpSchema.RequestPermissionRequest, |
| 61 | ): ReadonlyArray<AcpSchema.PermissionOption> { |
| 62 | return request.options.filter((option) => option.optionId.trim() !== "plan_bypass"); |
| 63 | } |