MCPcopy Create free account
hub / github.com/Noumena-Network/code / createToolWrapper

Function createToolWrapper

src/tools/REPLTool/toolWrappers.ts:151–254  ·  view source on GitHub ↗
(
  toolName: string,
  runtime: ReplWrapperRuntime,
)

Source from the content-addressed store, hash-verified

149}
150
151export function createToolWrapper(
152 toolName: string,
153 runtime: ReplWrapperRuntime,
154): (args: Record<string, unknown>) => Promise<unknown> {
155 return async (rawArgs: Record<string, unknown>) => {
156 const toolInput = ensureRecord(rawArgs)
157 const innerToolUseID = randomUUID()
158
159 const toolUse: ToolUseBlock = {
160 type: 'tool_use',
161 id: innerToolUseID,
162 name: toolName,
163 input: toolInput,
164 }
165
166 const assistantMessage = createAssistantMessage({
167 content: [toolUse],
168 isVirtual: true,
169 }) as AssistantMessage
170
171 runtime.pushMessage(assistantMessage)
172 runtime.onProgress?.({
173 toolUseID: runtime.outerToolUseID,
174 data: {
175 type: 'repl_tool_call',
176 phase: 'start',
177 toolName,
178 toolInput,
179 },
180 })
181
182 const innerContext: ToolUseContext = {
183 ...runtime.toolUseContext,
184 getAppState: createNestedGetAppState(
185 runtime.toolUseContext.getAppState,
186 runtime.availableTools,
187 ),
188 options: {
189 ...runtime.toolUseContext.options,
190 tools: runtime.availableTools,
191 },
192 }
193
194 let sawToolResult = false
195 let toolResult: unknown
196 let toolError: string | undefined
197
198 for await (const update of runToolUse(
199 toolUse,
200 assistantMessage,
201 runtime.canUseTool,
202 innerContext,
203 )) {
204 if (update.contextModifier) {
205 runtime.pushContextModifier(update.contextModifier.modifyContext)
206 }
207 if (update.message.type === 'progress') {
208 continue

Callers 2

callFunction · 0.85
handleKernelRunToolMethod · 0.85

Calls 7

randomUUIDFunction · 0.90
createNestedGetAppStateFunction · 0.85
runToolUseFunction · 0.85
makeVirtualMessageFunction · 0.85
extractToolResultBlockFunction · 0.85
ensureRecordFunction · 0.70
createAssistantMessageFunction · 0.50

Tested by

no test coverage detected