MCPcopy Create free account
hub / github.com/agentforce314/clawcodex / asCommandDispatch

Function asCommandDispatch

ui-tui/src/lib/rpc.ts:8–46  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

6 !value || typeof value !== 'object' || Array.isArray(value) ? null : (value as T)
7
8export const asCommandDispatch = (value: unknown): CommandDispatchResponse | null => {
9 const o = asRpcResult(value)
10
11 if (!o || typeof o.type !== 'string') {
12 return null
13 }
14
15 const t = o.type
16
17 if (t === 'exec' || t === 'plugin') {
18 return { type: t, output: typeof o.output === 'string' ? o.output : undefined }
19 }
20
21 if (t === 'alias' && typeof o.target === 'string') {
22 return { type: 'alias', target: o.target }
23 }
24
25 if (t === 'skill' && typeof o.name === 'string') {
26 return { type: 'skill', name: o.name, message: typeof o.message === 'string' ? o.message : undefined }
27 }
28
29 if (t === 'send' && typeof o.message === 'string') {
30 return {
31 type: 'send',
32 message: o.message,
33 notice: typeof o.notice === 'string' ? o.notice : undefined
34 }
35 }
36
37 if (t === 'prefill' && typeof o.message === 'string') {
38 return {
39 type: 'prefill',
40 message: o.message,
41 notice: typeof o.notice === 'string' ? o.notice : undefined
42 }
43 }
44
45 return null
46}
47
48export const rpcErrorMessage = (err: unknown) =>
49 err instanceof Error && err.message ? err.message : typeof err === 'string' && err.trim() ? err : 'request failed'

Callers 3

handleDispatchFunction · 0.85
handlerFunction · 0.85

Calls 1

asRpcResultFunction · 0.85

Tested by

no test coverage detected