UNPKG

@genkit-ai/core

Version:

Genkit AI framework core libraries.

1 lines 5.48 kB
{"version":3,"sources":["../src/flowTypes.ts"],"sourcesContent":["/**\n * Copyright 2024 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 { z } from 'zod';\n\n// NOTE: Keep this file in sync with genkit-tools/src/types/flow.ts!\n// Eventually tools will be source of truth for these types (by generating a\n// JSON schema) but until then this file must be manually kept in sync\n\nexport interface FlowStateQuery {\n limit?: number;\n continuationToken?: string;\n}\nexport interface FlowStateQueryResponse {\n flowStates: FlowState[];\n continuationToken?: string;\n}\n\n/**\n * Flow state store persistence interface.\n */\nexport interface FlowStateStore {\n save(id: string, state: FlowState): Promise<void>;\n load(id: string): Promise<FlowState | undefined>;\n list(query?: FlowStateQuery): Promise<FlowStateQueryResponse>;\n}\n\nexport const FlowStateExecutionSchema = z.object({\n startTime: z\n .number()\n .optional()\n .describe('start time in milliseconds since the epoch'),\n endTime: z\n .number()\n .optional()\n .describe('end time in milliseconds since the epoch'),\n traceIds: z.array(z.string()),\n});\n\nexport type FlowStateExecution = z.infer<typeof FlowStateExecutionSchema>;\n\nexport const FlowResponseSchema = z.object({\n response: z.unknown().nullable(),\n});\n\nexport const FlowErrorSchema = z.object({\n error: z.string().optional(),\n stacktrace: z.string().optional(),\n});\n\nexport type FlowError = z.infer<typeof FlowErrorSchema>;\n\nexport const FlowResultSchema = FlowResponseSchema.and(FlowErrorSchema);\n\n/**\n * Flow Operation, modelled after:\n * https://cloud.google.com/service-infrastructure/docs/service-management/reference/rpc/google.longrunning#google.longrunning.Operation\n */\nexport const OperationSchema = z.object({\n name: z\n .string()\n .describe(\n 'server-assigned name, which is only unique within the same service that originally ' +\n 'returns it.'\n ),\n metadata: z\n .any()\n .optional()\n .describe(\n 'Service-specific metadata associated with the operation. It typically contains progress ' +\n 'information and common metadata such as create time.'\n ),\n done: z\n .boolean()\n .optional()\n .default(false)\n .describe(\n 'If the value is false, it means the operation is still in progress. If true, the ' +\n 'operation is completed, and either error or response is available.'\n ),\n result: FlowResultSchema.optional(),\n blockedOnStep: z\n .object({\n name: z.string(),\n schema: z.string().optional(),\n })\n .optional(),\n});\n\nexport type Operation = z.infer<typeof OperationSchema>;\n\n/**\n * Defines the format for flow state. This is the format used for persisting the state in\n * the {@link FlowStateStore}.\n */\nexport const FlowStateSchema = z.object({\n name: z.string().optional(),\n flowId: z.string(),\n input: z.unknown(),\n startTime: z.number().describe('start time in milliseconds since the epoch'),\n cache: z.record(\n z.string(),\n z.object({\n value: z.any().optional(),\n empty: z.literal(true).optional(),\n })\n ),\n eventsTriggered: z.record(z.string(), z.any()),\n blockedOnStep: z\n .object({\n name: z.string(),\n schema: z.string().optional(),\n })\n .nullable(),\n operation: OperationSchema,\n traceContext: z.string().optional(),\n executions: z.array(FlowStateExecutionSchema),\n});\n\nexport type FlowState = z.infer<typeof FlowStateSchema>;\n"],"mappings":";AAgBA,SAAS,SAAS;AAwBX,MAAM,2BAA2B,EAAE,OAAO;AAAA,EAC/C,WAAW,EACR,OAAO,EACP,SAAS,EACT,SAAS,4CAA4C;AAAA,EACxD,SAAS,EACN,OAAO,EACP,SAAS,EACT,SAAS,0CAA0C;AAAA,EACtD,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC;AAC9B,CAAC;AAIM,MAAM,qBAAqB,EAAE,OAAO;AAAA,EACzC,UAAU,EAAE,QAAQ,EAAE,SAAS;AACjC,CAAC;AAEM,MAAM,kBAAkB,EAAE,OAAO;AAAA,EACtC,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,YAAY,EAAE,OAAO,EAAE,SAAS;AAClC,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