MCPcopy Index your code
hub / github.com/anomalyco/opencode / scriptedResponses

Function scriptedResponses

packages/llm/test/lib/http.ts:85–98  ·  view source on GitHub ↗
(bodies: ReadonlyArray<string>, init: ResponseInit = { headers: SSE_HEADERS })

Source from the content-addressed store, hash-verified

83 * array is reused if the test makes more requests than scripted.
84 */
85export const scriptedResponses = (bodies: ReadonlyArray<string>, init: ResponseInit = { headers: SSE_HEADERS }) => {
86 if (bodies.length === 0) throw new Error("scriptedResponses requires at least one body")
87 return Layer.unwrap(
88 Effect.gen(function* () {
89 const cursor = yield* Ref.make(0)
90 return dynamicResponse((input) =>
91 Effect.gen(function* () {
92 const index = yield* Ref.getAndUpdate(cursor, (n) => n + 1)
93 return input.respond(bodies[index] ?? bodies[bodies.length - 1], init)
94 }),
95 )
96 }),
97 )
98}

Callers 1

Calls 3

dynamicResponseFunction · 0.85
respondMethod · 0.80
makeMethod · 0.45

Tested by

no test coverage detected