MCPcopy
hub / github.com/anomalyco/opencode / toolPart

Function toolPart

packages/app/e2e/smoke/session-timeline.fixture.ts:115–148  ·  view source on GitHub ↗
(
  index: number,
  partIndex: number,
  tool: string,
  input: Record<string, unknown>,
  outputLength = 160,
)

Source from the content-addressed store, hash-verified

113}
114
115function toolPart(
116 index: number,
117 partIndex: number,
118 tool: string,
119 input: Record<string, unknown>,
120 outputLength = 160,
121): MessagePart {
122 const metadata =
123 tool === "apply_patch"
124 ? { files: [patchFile(index, "update"), patchFile(index + 1, index % 2 === 0 ? "add" : "delete")] }
125 : tool === "edit" || tool === "write"
126 ? {
127 filediff: fileDiff(String(input.filePath ?? `src/generated/file-${index}.ts`), index),
128 diff: patch(index, outputLength),
129 preview: patch(index + 1, 420),
130 }
131 : tool === "question"
132 ? { answers: [["Proceed"], ["Keep sample output"]] }
133 : {}
134 return {
135 id: id(`prt_tool_${tool}_${partIndex}`, index),
136 type: "tool",
137 callID: id("call", index * 10 + partIndex),
138 tool,
139 state: {
140 status: "completed",
141 input,
142 output: lorem(index * 23 + partIndex, outputLength),
143 title: tool === "bash" ? input.command : input.filePath || input.path || input.pattern || "completed",
144 metadata,
145 time: { start: 1700000000000 + index * 10_000, end: 1700000000000 + index * 10_000 + 400 },
146 },
147 }
148}
149
150function patchFile(seed: number, type: "add" | "update" | "delete") {
151 return {

Callers 1

turnFunction · 0.70

Calls 5

patchFileFunction · 0.70
fileDiffFunction · 0.70
patchFunction · 0.70
idFunction · 0.70
loremFunction · 0.70

Tested by

no test coverage detected