MCPcopy Create free account
hub / github.com/tiann/hapi / parseToolResult

Function parseToolResult

cli/src/opencode/opencodeLocalLauncher.ts:191–231  ·  view source on GitHub ↗
(part: unknown)

Source from the content-addressed store, hash-verified

189}
190
191function parseToolResult(part: unknown): ParsedToolResult | null {
192 if (!isObject(part)) {
193 return null;
194 }
195 const record = part as Record<string, unknown>;
196 const callId = getString(record.callID)
197 || getString(record.callId)
198 || getString(record.tool_call_id)
199 || getString(record.toolCallId)
200 || getString(record.id);
201 if (!callId) {
202 return null;
203 }
204 if (getString(record.type) === 'tool' && isObject(record.state)) {
205 const state = record.state as Record<string, unknown>;
206 const status = getString(state.status);
207 if (status === 'completed') {
208 const output = {
209 content: state.output ?? state.title,
210 metadata: state.metadata,
211 title: state.title,
212 attachments: state.attachments
213 };
214 return { callId, output };
215 }
216 if (status === 'error') {
217 const output = {
218 content: state.error,
219 isError: true
220 };
221 return { callId, output };
222 }
223 return null;
224 }
225 const output = {
226 content: record.content,
227 metadata: record.metadata,
228 isError: record.is_error
229 };
230 return { callId, output };
231}
232
233function normalizeDecision(response: string | null, approved: boolean): PermissionDecision {
234 if (response === 'always' || response === 'approved_for_session') {

Callers 1

handleHookEventFunction · 0.85

Calls 2

isObjectFunction · 0.85
getStringFunction · 0.70

Tested by

no test coverage detected