MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / toProtocolTask

Function toProtocolTask

packages/agent-core/src/services/task/task.ts:103–132  ·  view source on GitHub ↗
(
  sessionId: string,
  info: BackgroundTaskInfo,
  output?: TaskOutputSnapshot,
)

Source from the content-addressed store, hash-verified

101}
102
103export function toProtocolTask(
104 sessionId: string,
105 info: BackgroundTaskInfo,
106 output?: TaskOutputSnapshot,
107): BackgroundTask {
108 const status = mapStatus(info.status);
109 const createdIso = new Date(info.startedAt).toISOString();
110 const base: BackgroundTask = {
111 id: info.taskId,
112 session_id: sessionId,
113 kind: mapKind(info.kind),
114 description: info.description,
115 status,
116 // Agent-core has no separate creation stamp; we synthesize from
117 // startedAt — running tasks usually start immediately after creation.
118 created_at: createdIso,
119 started_at: createdIso,
120 };
121 if (info.endedAt !== null && info.endedAt !== undefined) {
122 base.completed_at = new Date(info.endedAt).toISOString();
123 }
124 if (info.kind === 'process' && 'command' in info && typeof info.command === 'string') {
125 base.command = info.command;
126 }
127 if (output !== undefined) {
128 base.output_preview = output.preview;
129 base.output_bytes = output.bytes;
130 }
131 return base;
132}
133
134// ---------------------------------------------------------------------------
135// Interface + implementation

Callers 4

listMethod · 0.90
getMethod · 0.90
cancelMethod · 0.90

Calls 2

mapStatusFunction · 0.85
mapKindFunction · 0.85

Tested by

no test coverage detected