MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / parseJsonObjectInput

Function parseJsonObjectInput

apps/cli/src/tooling.ts:126–147  ·  view source on GitHub ↗
(
  raw: string | undefined,
)

Source from the content-addressed store, hash-verified

124};
125
126export const parseJsonObjectInput = (
127 raw: string | undefined,
128): Effect.Effect<Record<string, unknown>, Error> =>
129 Effect.gen(function* () {
130 if (raw === undefined || raw.trim().length === 0) {
131 return {};
132 }
133
134 const parsed = yield* Effect.try({
135 try: () => JSON.parse(raw) as unknown,
136 catch: (cause) =>
137 cause instanceof Error
138 ? new Error(`Invalid JSON arguments: ${cause.message}`)
139 : new Error(`Invalid JSON arguments: ${String(cause)}`),
140 });
141
142 if (!isRecord(parsed)) {
143 return yield* Effect.fail(new Error("Tool arguments must decode to a JSON object"));
144 }
145
146 return parsed;
147 });
148
149export const resolveToolInvocation = (input: {
150 rawPathParts: ReadonlyArray<string>;

Callers 3

parseOptionalJsonObjectFunction · 0.90
tools-cli.test.tsFile · 0.90
resolveToolInvocationFunction · 0.85

Calls 1

isRecordFunction · 0.70

Tested by

no test coverage detected