@genkit-ai/next
Version:
Next.js plugin for Genkit
1 lines • 2.17 kB
Source Map (JSON)
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["/**\n * Copyright 2025 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Action, z } from 'genkit';\nimport {\n runFlow as baseRunFlow,\n streamFlow as baseStreamFlow,\n} from 'genkit/beta/client';\n\ntype Input<A extends Action> =\n A extends Action<infer I extends z.ZodTypeAny, any, any> ? z.infer<I> : never;\ntype Output<A extends Action> =\n A extends Action<any, infer O extends z.ZodTypeAny, any> ? z.infer<O> : never;\ntype Stream<A extends Action> =\n A extends Action<any, any, infer S extends z.ZodTypeAny> ? z.infer<S> : never;\n\nexport interface RequestData<T> {\n url: string;\n headers?: Record<string, string>;\n input?: T;\n streamId?: string;\n abortSignal?: AbortSignal;\n}\n\nexport function runFlow<A extends Action = Action>(\n req: RequestData<Input<A>>\n): Promise<Output<A>> {\n return baseRunFlow<Output<A>>(req);\n}\n\nexport interface StreamResponse<A extends Action> {\n output: Promise<Output<A>>;\n stream: AsyncIterable<Stream<A>>;\n streamId: Promise<string | null>;\n}\n\nexport function streamFlow<A extends Action = Action>(\n req: RequestData<Input<A>>\n): StreamResponse<A> {\n const res = baseStreamFlow<Output<A>, Stream<A>>(req);\n return {\n output: res.output,\n stream: res.stream,\n streamId: res.streamId,\n };\n}\n"],"mappings":"AAiBA;AAAA,EACE,WAAW;AAAA,EACX,cAAc;AAAA,OACT;AAiBA,SAAS,QACd,KACoB;AACpB,SAAO,YAAuB,GAAG;AACnC;AAQO,SAAS,WACd,KACmB;AACnB,QAAM,MAAM,eAAqC,GAAG;AACpD,SAAO;AAAA,IACL,QAAQ,IAAI;AAAA,IACZ,QAAQ,IAAI;AAAA,IACZ,UAAU,IAAI;AAAA,EAChB;AACF;","names":[]}