( raw: string | undefined, )
| 124 | }; |
| 125 | |
| 126 | export 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 | |
| 149 | export const resolveToolInvocation = (input: { |
| 150 | rawPathParts: ReadonlyArray<string>; |
no test coverage detected