MCPcopy Index your code
hub / github.com/Opencode-DCP/opencode-dynamic-context-pruning / extractToolContent

Function extractToolContent

lib/token-utils.ts:105–124  ·  view source on GitHub ↗
(part: any)

Source from the content-addressed store, hash-verified

103}
104
105export function extractToolContent(part: any): string[] {
106 const contents: string[] = []
107
108 if (part?.type !== "tool") {
109 return contents
110 }
111
112 if (part.state?.input !== undefined) {
113 contents.push(stringifyToolContent(part.state.input))
114 }
115
116 const completedOutput = extractCompletedToolOutput(part)
117 if (completedOutput !== undefined) {
118 contents.push(completedOutput)
119 } else if (part.state?.status === "error" && part.state?.error) {
120 contents.push(stringifyToolContent(part.state.error))
121 }
122
123 return contents
124}
125
126export function countToolTokens(part: any): number {
127 const contents = extractToolContent(part)

Callers 3

assertCountedFunction · 0.90
countToolTokensFunction · 0.85
countAllMessageTokensFunction · 0.85

Calls 2

stringifyToolContentFunction · 0.85

Tested by 1

assertCountedFunction · 0.72