Skip to content
Source
Sign inSign up
Open History to see the last commit

devinAcp.ts

63 lines2.6 KB

1import type * as AcpSchema from "effect-acp/compat";
2import type { AcpToolCallState } from "@t3tools/provider-acp/server/runtimeModel";
3import type { AcpAdapterV2SubagentUpdate } from "@t3tools/provider-acp/server/adapter";
4​
5function 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​
11export 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;
31​
32export 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;
38​
39export 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 };
57​
58// Devin's plan exit offers several allow_once options in no promised order; T3 never answers with bypass.
59export function devinAnswerablePermissionOptions(
60 request: AcpSchema.RequestPermissionRequest,
61): ReadonlyArray<AcpSchema.PermissionOption> {
62 return request.options.filter((option) => option.optionId.trim() !== "plan_bypass");