@ohos-ports/genkit 1.42.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. package/LICENSE +203 -0
  2. package/README.md +434 -0
  3. package/lib/beta.d.mts +18 -0
  4. package/lib/beta.d.ts +18 -0
  5. package/lib/beta.js +88 -0
  6. package/lib/beta.js.map +1 -0
  7. package/lib/beta.mjs +64 -0
  8. package/lib/beta.mjs.map +1 -0
  9. package/lib/client/agent.d.mts +52 -0
  10. package/lib/client/agent.d.ts +52 -0
  11. package/lib/client/agent.js +90 -0
  12. package/lib/client/agent.js.map +1 -0
  13. package/lib/client/agent.mjs +68 -0
  14. package/lib/client/agent.mjs.map +1 -0
  15. package/lib/client/client.d.mts +80 -0
  16. package/lib/client/client.d.ts +80 -0
  17. package/lib/client/client.js +164 -0
  18. package/lib/client/client.js.map +1 -0
  19. package/lib/client/client.mjs +139 -0
  20. package/lib/client/client.mjs.map +1 -0
  21. package/lib/client/index.d.mts +6 -0
  22. package/lib/client/index.d.ts +6 -0
  23. package/lib/client/index.js +55 -0
  24. package/lib/client/index.js.map +1 -0
  25. package/lib/client/index.mjs +31 -0
  26. package/lib/client/index.mjs.map +1 -0
  27. package/lib/client/types.d.mts +17 -0
  28. package/lib/client/types.d.ts +17 -0
  29. package/lib/client/types.js +17 -0
  30. package/lib/client/types.js.map +1 -0
  31. package/lib/client/types.mjs +1 -0
  32. package/lib/client/types.mjs.map +1 -0
  33. package/lib/common.d.mts +3 -0
  34. package/lib/common.d.ts +3 -0
  35. package/lib/common.js +151 -0
  36. package/lib/common.js.map +1 -0
  37. package/lib/common.mjs +128 -0
  38. package/lib/common.mjs.map +1 -0
  39. package/lib/context.d.mts +1 -0
  40. package/lib/context.d.ts +1 -0
  41. package/lib/context.js +50 -0
  42. package/lib/context.js.map +1 -0
  43. package/lib/context.mjs +28 -0
  44. package/lib/context.mjs.map +1 -0
  45. package/lib/embedder.d.mts +1 -0
  46. package/lib/embedder.d.ts +1 -0
  47. package/lib/embedder.js +48 -0
  48. package/lib/embedder.js.map +1 -0
  49. package/lib/embedder.mjs +26 -0
  50. package/lib/embedder.mjs.map +1 -0
  51. package/lib/evaluator.d.mts +1 -0
  52. package/lib/evaluator.d.ts +1 -0
  53. package/lib/evaluator.js +60 -0
  54. package/lib/evaluator.js.map +1 -0
  55. package/lib/evaluator.mjs +38 -0
  56. package/lib/evaluator.mjs.map +1 -0
  57. package/lib/extract.d.mts +1 -0
  58. package/lib/extract.d.ts +1 -0
  59. package/lib/extract.js +48 -0
  60. package/lib/extract.js.map +1 -0
  61. package/lib/extract.mjs +23 -0
  62. package/lib/extract.mjs.map +1 -0
  63. package/lib/formats.d.mts +1 -0
  64. package/lib/formats.d.ts +1 -0
  65. package/lib/formats.js +34 -0
  66. package/lib/formats.js.map +1 -0
  67. package/lib/formats.mjs +18 -0
  68. package/lib/formats.mjs.map +1 -0
  69. package/lib/genkit-beta.d.mts +183 -0
  70. package/lib/genkit-beta.d.ts +183 -0
  71. package/lib/genkit-beta.js +178 -0
  72. package/lib/genkit-beta.js.map +1 -0
  73. package/lib/genkit-beta.mjs +159 -0
  74. package/lib/genkit-beta.mjs.map +1 -0
  75. package/lib/genkit.d.mts +10 -0
  76. package/lib/genkit.d.ts +10 -0
  77. package/lib/genkit.js +471 -0
  78. package/lib/genkit.js.map +1 -0
  79. package/lib/genkit.mjs +489 -0
  80. package/lib/genkit.mjs.map +1 -0
  81. package/lib/index-BSkuxdwl.d.mts +311 -0
  82. package/lib/index-BSkuxdwl.d.ts +311 -0
  83. package/lib/index.d.mts +10 -0
  84. package/lib/index.d.ts +10 -0
  85. package/lib/index.js +51 -0
  86. package/lib/index.js.map +1 -0
  87. package/lib/index.mjs +24 -0
  88. package/lib/index.mjs.map +1 -0
  89. package/lib/logging.d.mts +1 -0
  90. package/lib/logging.d.ts +1 -0
  91. package/lib/logging.js +46 -0
  92. package/lib/logging.js.map +1 -0
  93. package/lib/logging.mjs +22 -0
  94. package/lib/logging.mjs.map +1 -0
  95. package/lib/middleware.d.mts +1 -0
  96. package/lib/middleware.d.ts +1 -0
  97. package/lib/middleware.js +56 -0
  98. package/lib/middleware.js.map +1 -0
  99. package/lib/middleware.mjs +34 -0
  100. package/lib/middleware.mjs.map +1 -0
  101. package/lib/model.d.mts +1 -0
  102. package/lib/model.d.ts +1 -0
  103. package/lib/model.js +92 -0
  104. package/lib/model.js.map +1 -0
  105. package/lib/model.mjs +70 -0
  106. package/lib/model.mjs.map +1 -0
  107. package/lib/plugin.d.mts +10 -0
  108. package/lib/plugin.d.ts +10 -0
  109. package/lib/plugin.js +143 -0
  110. package/lib/plugin.js.map +1 -0
  111. package/lib/plugin.mjs +113 -0
  112. package/lib/plugin.mjs.map +1 -0
  113. package/lib/registry.d.mts +1 -0
  114. package/lib/registry.d.ts +1 -0
  115. package/lib/registry.js +46 -0
  116. package/lib/registry.js.map +1 -0
  117. package/lib/registry.mjs +24 -0
  118. package/lib/registry.mjs.map +1 -0
  119. package/lib/reranker.d.mts +1 -0
  120. package/lib/reranker.d.ts +1 -0
  121. package/lib/reranker.js +54 -0
  122. package/lib/reranker.js.map +1 -0
  123. package/lib/reranker.mjs +32 -0
  124. package/lib/reranker.mjs.map +1 -0
  125. package/lib/retriever.d.mts +1 -0
  126. package/lib/retriever.d.ts +1 -0
  127. package/lib/retriever.js +58 -0
  128. package/lib/retriever.js.map +1 -0
  129. package/lib/retriever.mjs +36 -0
  130. package/lib/retriever.mjs.map +1 -0
  131. package/lib/schema.d.mts +1 -0
  132. package/lib/schema.d.ts +1 -0
  133. package/lib/schema.js +54 -0
  134. package/lib/schema.js.map +1 -0
  135. package/lib/schema.mjs +32 -0
  136. package/lib/schema.mjs.map +1 -0
  137. package/lib/testing.d.mts +1 -0
  138. package/lib/testing.d.ts +1 -0
  139. package/lib/testing.js +50 -0
  140. package/lib/testing.js.map +1 -0
  141. package/lib/testing.mjs +28 -0
  142. package/lib/testing.mjs.map +1 -0
  143. package/lib/tool.d.mts +1 -0
  144. package/lib/tool.d.ts +1 -0
  145. package/lib/tool.js +54 -0
  146. package/lib/tool.js.map +1 -0
  147. package/lib/tool.mjs +32 -0
  148. package/lib/tool.mjs.map +1 -0
  149. package/lib/tracing.d.mts +1 -0
  150. package/lib/tracing.d.ts +1 -0
  151. package/lib/tracing.js +82 -0
  152. package/lib/tracing.js.map +1 -0
  153. package/lib/tracing.mjs +60 -0
  154. package/lib/tracing.mjs.map +1 -0
  155. package/package.json +233 -0
  156. package/src/beta.ts +85 -0
  157. package/src/client/agent.ts +160 -0
  158. package/src/client/client.ts +237 -0
  159. package/src/client/index.ts +72 -0
  160. package/src/client/types.ts +41 -0
  161. package/src/common.ts +175 -0
  162. package/src/context.ts +37 -0
  163. package/src/embedder.ts +41 -0
  164. package/src/evaluator.ts +50 -0
  165. package/src/extract.ts +30 -0
  166. package/src/formats.ts +30 -0
  167. package/src/genkit-beta.ts +275 -0
  168. package/src/genkit.ts +818 -0
  169. package/src/index.ts +29 -0
  170. package/src/logging.ts +30 -0
  171. package/src/middleware.ts +38 -0
  172. package/src/model.ts +87 -0
  173. package/src/plugin.ts +172 -0
  174. package/src/registry.ts +36 -0
  175. package/src/reranker.ts +42 -0
  176. package/src/retriever.ts +55 -0
  177. package/src/schema.ts +40 -0
  178. package/src/testing.ts +47 -0
  179. package/src/tool.ts +40 -0
  180. package/src/tracing.ts +55 -0
  181. package/tests/agent_client_test.ts +497 -0
  182. package/tests/embed_test.ts +142 -0
  183. package/tests/evaluate_test.ts +52 -0
  184. package/tests/flow_test.ts +94 -0
  185. package/tests/formats_test.ts +168 -0
  186. package/tests/generate_test.ts +1631 -0
  187. package/tests/genkit_test.ts +33 -0
  188. package/tests/helpers.ts +176 -0
  189. package/tests/mock-model_test.ts +490 -0
  190. package/tests/plugins_test.ts +259 -0
  191. package/tests/prompts/badSchemaRef.prompt +9 -0
  192. package/tests/prompts/chat_preamble.prompt +5 -0
  193. package/tests/prompts/kitchensink.prompt +25 -0
  194. package/tests/prompts/output.prompt +11 -0
  195. package/tests/prompts/schemaRef.prompt +9 -0
  196. package/tests/prompts/sub/test.prompt +5 -0
  197. package/tests/prompts/test.prompt +5 -0
  198. package/tests/prompts/test.variant.prompt +8 -0
  199. package/tests/prompts/toolPrompt.prompt +6 -0
  200. package/tests/prompts_test.ts +1442 -0
  201. package/tests/session_test.ts +17 -0
  202. package/typedoc.json +22 -0
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var genkit_beta_exports = {};
20
+ __export(genkit_beta_exports, {
21
+ FileSessionStore: () => import_session_stores.FileSessionStore,
22
+ GenkitBeta: () => GenkitBeta,
23
+ InMemorySessionStore: () => import_session_stores.InMemorySessionStore,
24
+ SessionRunner: () => import_ai.SessionRunner,
25
+ applyPatch: () => import_json_patch.applyPatch,
26
+ diff: () => import_json_patch.diff,
27
+ genkit: () => genkit
28
+ });
29
+ module.exports = __toCommonJS(genkit_beta_exports);
30
+ var import_ai = require("@genkit-ai/ai");
31
+ var import_formats = require("@genkit-ai/ai/formats");
32
+ var import_session_stores = require("@genkit-ai/ai/session-stores");
33
+ var import_json_patch = require("@genkit-ai/ai/json-patch");
34
+ var import_genkit = require("./genkit.js");
35
+ function genkit(options) {
36
+ return new GenkitBeta(options);
37
+ }
38
+ class GenkitBeta extends import_genkit.Genkit {
39
+ constructor(options) {
40
+ super(options);
41
+ this.registry.apiStability = "beta";
42
+ }
43
+ /**
44
+ * Defines and registers a custom agent with a custom handler function.
45
+ *
46
+ * @beta
47
+ */
48
+ defineCustomAgent(config, fn) {
49
+ return (0, import_ai.defineCustomAgent)(this.registry, config, fn);
50
+ }
51
+ /**
52
+ * Defines and registers an agent from an existing Prompt template.
53
+ *
54
+ * @beta
55
+ */
56
+ definePromptAgent(config) {
57
+ return (0, import_ai.definePromptAgent)(this.registry, config);
58
+ }
59
+ /**
60
+ * Defines and registers an agent by creating a prompt and wiring it into a
61
+ * multi-turn agent in one step.
62
+ *
63
+ * This is a convenience shortcut that combines `definePrompt` and
64
+ * `definePromptAgent` into a single call.
65
+ *
66
+ * ```ts
67
+ * const myAgent = ai.defineAgent({
68
+ * name: 'myAgent',
69
+ * model: 'googleai/gemini-2.5-flash',
70
+ * system: 'Talk like a pirate.',
71
+ * tools: [weatherTool],
72
+ * store: new FileSessionStore('./.snapshots'),
73
+ * });
74
+ * ```
75
+ *
76
+ * @beta
77
+ */
78
+ defineAgent(config) {
79
+ return (0, import_ai.defineAgent)(this.registry, config);
80
+ }
81
+ /**
82
+ * Defines and registers a custom model output formatter.
83
+ *
84
+ * Here's an example of a custom JSON output formatter:
85
+ *
86
+ * ```ts
87
+ * import { extractJson } from 'genkit/extract';
88
+ *
89
+ * ai.defineFormat(
90
+ * { name: 'customJson' },
91
+ * (schema) => {
92
+ * let instructions: string | undefined;
93
+ * if (schema) {
94
+ * instructions = `Output should be in JSON format and conform to the following schema:
95
+ * \`\`\`
96
+ * ${JSON.stringify(schema)}
97
+ * \`\`\`
98
+ * `;
99
+ * }
100
+ * return {
101
+ * parseChunk: (chunk) => extractJson(chunk.accumulatedText),
102
+ * parseMessage: (message) => extractJson(message.text),
103
+ * instructions,
104
+ * };
105
+ * }
106
+ * );
107
+ *
108
+ * const { output } = await ai.generate({
109
+ * prompt: 'Invent a menu item for a pirate themed restaurant.',
110
+ * output: { format: 'customJson', schema: MenuItemSchema },
111
+ * });
112
+ * ```
113
+ *
114
+ * @beta
115
+ */
116
+ defineFormat(options, handler) {
117
+ return (0, import_formats.defineFormat)(this.registry, options, handler);
118
+ }
119
+ /**
120
+ * Defines and registers an interrupt.
121
+ *
122
+ * Interrupts are special tools that halt model processing and return control back to the caller. Interrupts make it simpler to implement
123
+ * "human-in-the-loop" and out-of-band processing patterns that require waiting on external actions to complete.
124
+ *
125
+ * @beta
126
+ */
127
+ defineInterrupt(config) {
128
+ return (0, import_ai.defineInterrupt)(this.registry, config);
129
+ }
130
+ /**
131
+ * Starts a generate operation for long running generation models, typically for
132
+ * video and complex audio generation.
133
+ *
134
+ * See {@link GenerateOptions} for detailed information about available options.
135
+ *
136
+ * ```ts
137
+ * const operation = await ai.generateOperation({
138
+ * model: googleAI.model('veo-3.1-generate-preview'),
139
+ * prompt: 'A banana riding a bicycle.',
140
+ * });
141
+ * ```
142
+ *
143
+ * The status of the operation and final result can be obtained using {@link Genkit.checkOperation}.
144
+ */
145
+ generateOperation(opts) {
146
+ return (0, import_ai.generateOperation)(this.registry, opts);
147
+ }
148
+ /**
149
+ * Defines a resource. Resources can then be accessed from a generate call.
150
+ *
151
+ * ```ts
152
+ * ai.defineResource({
153
+ * uri: 'my://resource/{param}',
154
+ * description: 'provides my resource',
155
+ * }, async ({param}) => {
156
+ * return [{ text: `resource ${param}` }]
157
+ * });
158
+ *
159
+ * await ai.generate({
160
+ * prompt: [{ resource: 'my://resource/value' }]
161
+ * })
162
+ * ```
163
+ */
164
+ defineResource(opts, fn) {
165
+ return (0, import_ai.defineResource)(this.registry, opts, fn);
166
+ }
167
+ }
168
+ // Annotate the CommonJS export names for ESM import in node:
169
+ 0 && (module.exports = {
170
+ FileSessionStore,
171
+ GenkitBeta,
172
+ InMemorySessionStore,
173
+ SessionRunner,
174
+ applyPatch,
175
+ diff,
176
+ genkit
177
+ });
178
+ //# sourceMappingURL=genkit-beta.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/genkit-beta.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 {\n GenerateOptions,\n GenerateResponseData,\n GenerationCommonConfigSchema,\n SessionRunner,\n defineAgent,\n defineCustomAgent,\n defineInterrupt,\n definePromptAgent,\n defineResource,\n generateOperation,\n type Agent,\n type AgentConfig,\n type AgentFn,\n type AgentStreamChunk,\n type ClientTransform,\n type InterruptConfig,\n type PromptConfig,\n type ResourceAction,\n type ResourceFn,\n type ResourceOptions,\n type ToolAction,\n} from '@genkit-ai/ai';\n\nimport { defineFormat } from '@genkit-ai/ai/formats';\n\nimport {\n type SessionSnapshot,\n type SessionSnapshotInput,\n type SessionState,\n type SessionStore,\n type SessionStoreOptions,\n type SnapshotMutator,\n} from '@genkit-ai/ai/session';\nimport {\n FileSessionStore,\n InMemorySessionStore,\n} from '@genkit-ai/ai/session-stores';\n\nimport { applyPatch, diff } from '@genkit-ai/ai/json-patch';\nimport { type Operation, type z } from '@genkit-ai/core';\nimport type { Formatter } from './formats.js';\nimport { Genkit, type GenkitOptions } from './genkit.js';\n\nexport type { JsonPatch, JsonPatchOperation } from '@genkit-ai/ai/json-patch';\nexport {\n FileSessionStore,\n InMemorySessionStore,\n SessionRunner,\n applyPatch,\n diff,\n};\nexport type {\n Agent,\n AgentFn,\n AgentStreamChunk,\n ClientTransform,\n GenkitOptions as GenkitBetaOptions,\n PromptConfig,\n SessionSnapshot,\n SessionSnapshotInput,\n SessionState,\n SessionStore,\n SessionStoreOptions,\n SnapshotMutator,\n};\n\n/**\n * WARNING: these APIs are considered unstable and subject to frequent breaking changes that may not honor semver.\n *\n * Initializes Genkit BETA APIs with a set of options.\n *\n * This will create a new Genkit registry, register the provided plugins, stores, and other configuration. This\n * should be called before any flows are registered.\n *\n * @beta\n */\nexport function genkit(options: GenkitOptions): GenkitBeta {\n return new GenkitBeta(options);\n}\n\n/**\n * Genkit BETA APIs.\n *\n * @beta\n */\nexport class GenkitBeta extends Genkit {\n constructor(options?: GenkitOptions) {\n super(options);\n this.registry.apiStability = 'beta';\n }\n\n /**\n * Defines and registers a custom agent with a custom handler function.\n *\n * @beta\n */\n defineCustomAgent<State = unknown>(\n config: {\n name: string;\n description?: string;\n stateSchema?: z.ZodType<State>;\n store?: SessionStore<State>;\n },\n fn: AgentFn<State>\n ) {\n return defineCustomAgent<State>(this.registry, config, fn);\n }\n\n /**\n * Defines and registers an agent from an existing Prompt template.\n *\n * @beta\n */\n definePromptAgent<\n State = unknown,\n I extends z.ZodTypeAny = z.ZodTypeAny,\n >(config: {\n promptName: string;\n /**\n * Input values for the referenced prompt's input variables. Lets a single\n * prompt be reused/customized across multiple agents.\n */\n promptInput?: z.infer<I>;\n stateSchema?: z.ZodType<State>;\n store?: SessionStore<State>;\n }) {\n return definePromptAgent<State, I>(this.registry, config);\n }\n\n /**\n * Defines and registers an agent by creating a prompt and wiring it into a\n * multi-turn agent in one step.\n *\n * This is a convenience shortcut that combines `definePrompt` and\n * `definePromptAgent` into a single call.\n *\n * ```ts\n * const myAgent = ai.defineAgent({\n * name: 'myAgent',\n * model: 'googleai/gemini-2.5-flash',\n * system: 'Talk like a pirate.',\n * tools: [weatherTool],\n * store: new FileSessionStore('./.snapshots'),\n * });\n * ```\n *\n * @beta\n */\n defineAgent<State = unknown, I extends z.ZodTypeAny = z.ZodTypeAny>(\n config: AgentConfig<State, I>\n ) {\n return defineAgent<State, I>(this.registry, config);\n }\n\n /**\n * Defines and registers a custom model output formatter.\n *\n * Here's an example of a custom JSON output formatter:\n *\n * ```ts\n * import { extractJson } from 'genkit/extract';\n *\n * ai.defineFormat(\n * { name: 'customJson' },\n * (schema) => {\n * let instructions: string | undefined;\n * if (schema) {\n * instructions = `Output should be in JSON format and conform to the following schema:\n * \\`\\`\\`\n * ${JSON.stringify(schema)}\n * \\`\\`\\`\n * `;\n * }\n * return {\n * parseChunk: (chunk) => extractJson(chunk.accumulatedText),\n * parseMessage: (message) => extractJson(message.text),\n * instructions,\n * };\n * }\n * );\n *\n * const { output } = await ai.generate({\n * prompt: 'Invent a menu item for a pirate themed restaurant.',\n * output: { format: 'customJson', schema: MenuItemSchema },\n * });\n * ```\n *\n * @beta\n */\n defineFormat(\n options: {\n name: string;\n } & Formatter['config'],\n handler: Formatter['handler']\n ): { config: Formatter['config']; handler: Formatter['handler'] } {\n return defineFormat(this.registry, options, handler);\n }\n\n /**\n * Defines and registers an interrupt.\n *\n * Interrupts are special tools that halt model processing and return control back to the caller. Interrupts make it simpler to implement\n * \"human-in-the-loop\" and out-of-band processing patterns that require waiting on external actions to complete.\n *\n * @beta\n */\n defineInterrupt<I extends z.ZodTypeAny, O extends z.ZodTypeAny>(\n config: InterruptConfig<I, O>\n ): ToolAction<I, O> {\n return defineInterrupt(this.registry, config);\n }\n\n /**\n * Starts a generate operation for long running generation models, typically for\n * video and complex audio generation.\n *\n * See {@link GenerateOptions} for detailed information about available options.\n *\n * ```ts\n * const operation = await ai.generateOperation({\n * model: googleAI.model('veo-3.1-generate-preview'),\n * prompt: 'A banana riding a bicycle.',\n * });\n * ```\n *\n * The status of the operation and final result can be obtained using {@link Genkit.checkOperation}.\n */\n generateOperation<\n O extends z.ZodTypeAny = z.ZodTypeAny,\n CustomOptions extends z.ZodTypeAny = typeof GenerationCommonConfigSchema,\n >(\n opts:\n | GenerateOptions<O, CustomOptions>\n | PromiseLike<GenerateOptions<O, CustomOptions>>\n ): Promise<Operation<GenerateResponseData>> {\n return generateOperation(this.registry, opts);\n }\n\n /**\n * Defines a resource. Resources can then be accessed from a generate call.\n *\n * ```ts\n * ai.defineResource({\n * uri: 'my://resource/{param}',\n * description: 'provides my resource',\n * }, async ({param}) => {\n * return [{ text: `resource ${param}` }]\n * });\n *\n * await ai.generate({\n * prompt: [{ resource: 'my://resource/value' }]\n * })\n * ```\n */\n defineResource(opts: ResourceOptions, fn: ResourceFn): ResourceAction {\n return defineResource(this.registry, opts, fn);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,gBAsBO;AAEP,qBAA6B;AAU7B,4BAGO;AAEP,wBAAiC;AAGjC,oBAA2C;AAmCpC,SAAS,OAAO,SAAoC;AACzD,SAAO,IAAI,WAAW,OAAO;AAC/B;AAOO,MAAM,mBAAmB,qBAAO;AAAA,EACrC,YAAY,SAAyB;AACnC,UAAM,OAAO;AACb,SAAK,SAAS,eAAe;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,kBACE,QAMA,IACA;AACA,eAAO,6BAAyB,KAAK,UAAU,QAAQ,EAAE;AAAA,EAC3D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,kBAGE,QASC;AACD,eAAO,6BAA4B,KAAK,UAAU,MAAM;AAAA,EAC1D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqBA,YACE,QACA;AACA,eAAO,uBAAsB,KAAK,UAAU,MAAM;AAAA,EACpD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqCA,aACE,SAGA,SACgE;AAChE,eAAO,6BAAa,KAAK,UAAU,SAAS,OAAO;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,gBACE,QACkB;AAClB,eAAO,2BAAgB,KAAK,UAAU,MAAM;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,kBAIE,MAG0C;AAC1C,eAAO,6BAAkB,KAAK,UAAU,IAAI;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBA,eAAe,MAAuB,IAAgC;AACpE,eAAO,0BAAe,KAAK,UAAU,MAAM,EAAE;AAAA,EAC/C;AACF;","names":[]}
@@ -0,0 +1,159 @@
1
+ import {
2
+ SessionRunner,
3
+ defineAgent,
4
+ defineCustomAgent,
5
+ defineInterrupt,
6
+ definePromptAgent,
7
+ defineResource,
8
+ generateOperation
9
+ } from "@genkit-ai/ai";
10
+ import { defineFormat } from "@genkit-ai/ai/formats";
11
+ import {
12
+ FileSessionStore,
13
+ InMemorySessionStore
14
+ } from "@genkit-ai/ai/session-stores";
15
+ import { applyPatch, diff } from "@genkit-ai/ai/json-patch";
16
+ import { Genkit } from "./genkit.mjs";
17
+ function genkit(options) {
18
+ return new GenkitBeta(options);
19
+ }
20
+ class GenkitBeta extends Genkit {
21
+ constructor(options) {
22
+ super(options);
23
+ this.registry.apiStability = "beta";
24
+ }
25
+ /**
26
+ * Defines and registers a custom agent with a custom handler function.
27
+ *
28
+ * @beta
29
+ */
30
+ defineCustomAgent(config, fn) {
31
+ return defineCustomAgent(this.registry, config, fn);
32
+ }
33
+ /**
34
+ * Defines and registers an agent from an existing Prompt template.
35
+ *
36
+ * @beta
37
+ */
38
+ definePromptAgent(config) {
39
+ return definePromptAgent(this.registry, config);
40
+ }
41
+ /**
42
+ * Defines and registers an agent by creating a prompt and wiring it into a
43
+ * multi-turn agent in one step.
44
+ *
45
+ * This is a convenience shortcut that combines `definePrompt` and
46
+ * `definePromptAgent` into a single call.
47
+ *
48
+ * ```ts
49
+ * const myAgent = ai.defineAgent({
50
+ * name: 'myAgent',
51
+ * model: 'googleai/gemini-2.5-flash',
52
+ * system: 'Talk like a pirate.',
53
+ * tools: [weatherTool],
54
+ * store: new FileSessionStore('./.snapshots'),
55
+ * });
56
+ * ```
57
+ *
58
+ * @beta
59
+ */
60
+ defineAgent(config) {
61
+ return defineAgent(this.registry, config);
62
+ }
63
+ /**
64
+ * Defines and registers a custom model output formatter.
65
+ *
66
+ * Here's an example of a custom JSON output formatter:
67
+ *
68
+ * ```ts
69
+ * import { extractJson } from 'genkit/extract';
70
+ *
71
+ * ai.defineFormat(
72
+ * { name: 'customJson' },
73
+ * (schema) => {
74
+ * let instructions: string | undefined;
75
+ * if (schema) {
76
+ * instructions = `Output should be in JSON format and conform to the following schema:
77
+ * \`\`\`
78
+ * ${JSON.stringify(schema)}
79
+ * \`\`\`
80
+ * `;
81
+ * }
82
+ * return {
83
+ * parseChunk: (chunk) => extractJson(chunk.accumulatedText),
84
+ * parseMessage: (message) => extractJson(message.text),
85
+ * instructions,
86
+ * };
87
+ * }
88
+ * );
89
+ *
90
+ * const { output } = await ai.generate({
91
+ * prompt: 'Invent a menu item for a pirate themed restaurant.',
92
+ * output: { format: 'customJson', schema: MenuItemSchema },
93
+ * });
94
+ * ```
95
+ *
96
+ * @beta
97
+ */
98
+ defineFormat(options, handler) {
99
+ return defineFormat(this.registry, options, handler);
100
+ }
101
+ /**
102
+ * Defines and registers an interrupt.
103
+ *
104
+ * Interrupts are special tools that halt model processing and return control back to the caller. Interrupts make it simpler to implement
105
+ * "human-in-the-loop" and out-of-band processing patterns that require waiting on external actions to complete.
106
+ *
107
+ * @beta
108
+ */
109
+ defineInterrupt(config) {
110
+ return defineInterrupt(this.registry, config);
111
+ }
112
+ /**
113
+ * Starts a generate operation for long running generation models, typically for
114
+ * video and complex audio generation.
115
+ *
116
+ * See {@link GenerateOptions} for detailed information about available options.
117
+ *
118
+ * ```ts
119
+ * const operation = await ai.generateOperation({
120
+ * model: googleAI.model('veo-3.1-generate-preview'),
121
+ * prompt: 'A banana riding a bicycle.',
122
+ * });
123
+ * ```
124
+ *
125
+ * The status of the operation and final result can be obtained using {@link Genkit.checkOperation}.
126
+ */
127
+ generateOperation(opts) {
128
+ return generateOperation(this.registry, opts);
129
+ }
130
+ /**
131
+ * Defines a resource. Resources can then be accessed from a generate call.
132
+ *
133
+ * ```ts
134
+ * ai.defineResource({
135
+ * uri: 'my://resource/{param}',
136
+ * description: 'provides my resource',
137
+ * }, async ({param}) => {
138
+ * return [{ text: `resource ${param}` }]
139
+ * });
140
+ *
141
+ * await ai.generate({
142
+ * prompt: [{ resource: 'my://resource/value' }]
143
+ * })
144
+ * ```
145
+ */
146
+ defineResource(opts, fn) {
147
+ return defineResource(this.registry, opts, fn);
148
+ }
149
+ }
150
+ export {
151
+ FileSessionStore,
152
+ GenkitBeta,
153
+ InMemorySessionStore,
154
+ SessionRunner,
155
+ applyPatch,
156
+ diff,
157
+ genkit
158
+ };
159
+ //# sourceMappingURL=genkit-beta.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/genkit-beta.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 {\n GenerateOptions,\n GenerateResponseData,\n GenerationCommonConfigSchema,\n SessionRunner,\n defineAgent,\n defineCustomAgent,\n defineInterrupt,\n definePromptAgent,\n defineResource,\n generateOperation,\n type Agent,\n type AgentConfig,\n type AgentFn,\n type AgentStreamChunk,\n type ClientTransform,\n type InterruptConfig,\n type PromptConfig,\n type ResourceAction,\n type ResourceFn,\n type ResourceOptions,\n type ToolAction,\n} from '@genkit-ai/ai';\n\nimport { defineFormat } from '@genkit-ai/ai/formats';\n\nimport {\n type SessionSnapshot,\n type SessionSnapshotInput,\n type SessionState,\n type SessionStore,\n type SessionStoreOptions,\n type SnapshotMutator,\n} from '@genkit-ai/ai/session';\nimport {\n FileSessionStore,\n InMemorySessionStore,\n} from '@genkit-ai/ai/session-stores';\n\nimport { applyPatch, diff } from '@genkit-ai/ai/json-patch';\nimport { type Operation, type z } from '@genkit-ai/core';\nimport type { Formatter } from './formats.mjs';\nimport { Genkit, type GenkitOptions } from './genkit.mjs';\n\nexport type { JsonPatch, JsonPatchOperation } from '@genkit-ai/ai/json-patch';\nexport {\n FileSessionStore,\n InMemorySessionStore,\n SessionRunner,\n applyPatch,\n diff,\n};\nexport type {\n Agent,\n AgentFn,\n AgentStreamChunk,\n ClientTransform,\n GenkitOptions as GenkitBetaOptions,\n PromptConfig,\n SessionSnapshot,\n SessionSnapshotInput,\n SessionState,\n SessionStore,\n SessionStoreOptions,\n SnapshotMutator,\n};\n\n/**\n * WARNING: these APIs are considered unstable and subject to frequent breaking changes that may not honor semver.\n *\n * Initializes Genkit BETA APIs with a set of options.\n *\n * This will create a new Genkit registry, register the provided plugins, stores, and other configuration. This\n * should be called before any flows are registered.\n *\n * @beta\n */\nexport function genkit(options: GenkitOptions): GenkitBeta {\n return new GenkitBeta(options);\n}\n\n/**\n * Genkit BETA APIs.\n *\n * @beta\n */\nexport class GenkitBeta extends Genkit {\n constructor(options?: GenkitOptions) {\n super(options);\n this.registry.apiStability = 'beta';\n }\n\n /**\n * Defines and registers a custom agent with a custom handler function.\n *\n * @beta\n */\n defineCustomAgent<State = unknown>(\n config: {\n name: string;\n description?: string;\n stateSchema?: z.ZodType<State>;\n store?: SessionStore<State>;\n },\n fn: AgentFn<State>\n ) {\n return defineCustomAgent<State>(this.registry, config, fn);\n }\n\n /**\n * Defines and registers an agent from an existing Prompt template.\n *\n * @beta\n */\n definePromptAgent<\n State = unknown,\n I extends z.ZodTypeAny = z.ZodTypeAny,\n >(config: {\n promptName: string;\n /**\n * Input values for the referenced prompt's input variables. Lets a single\n * prompt be reused/customized across multiple agents.\n */\n promptInput?: z.infer<I>;\n stateSchema?: z.ZodType<State>;\n store?: SessionStore<State>;\n }) {\n return definePromptAgent<State, I>(this.registry, config);\n }\n\n /**\n * Defines and registers an agent by creating a prompt and wiring it into a\n * multi-turn agent in one step.\n *\n * This is a convenience shortcut that combines `definePrompt` and\n * `definePromptAgent` into a single call.\n *\n * ```ts\n * const myAgent = ai.defineAgent({\n * name: 'myAgent',\n * model: 'googleai/gemini-2.5-flash',\n * system: 'Talk like a pirate.',\n * tools: [weatherTool],\n * store: new FileSessionStore('./.snapshots'),\n * });\n * ```\n *\n * @beta\n */\n defineAgent<State = unknown, I extends z.ZodTypeAny = z.ZodTypeAny>(\n config: AgentConfig<State, I>\n ) {\n return defineAgent<State, I>(this.registry, config);\n }\n\n /**\n * Defines and registers a custom model output formatter.\n *\n * Here's an example of a custom JSON output formatter:\n *\n * ```ts\n * import { extractJson } from 'genkit/extract';\n *\n * ai.defineFormat(\n * { name: 'customJson' },\n * (schema) => {\n * let instructions: string | undefined;\n * if (schema) {\n * instructions = `Output should be in JSON format and conform to the following schema:\n * \\`\\`\\`\n * ${JSON.stringify(schema)}\n * \\`\\`\\`\n * `;\n * }\n * return {\n * parseChunk: (chunk) => extractJson(chunk.accumulatedText),\n * parseMessage: (message) => extractJson(message.text),\n * instructions,\n * };\n * }\n * );\n *\n * const { output } = await ai.generate({\n * prompt: 'Invent a menu item for a pirate themed restaurant.',\n * output: { format: 'customJson', schema: MenuItemSchema },\n * });\n * ```\n *\n * @beta\n */\n defineFormat(\n options: {\n name: string;\n } & Formatter['config'],\n handler: Formatter['handler']\n ): { config: Formatter['config']; handler: Formatter['handler'] } {\n return defineFormat(this.registry, options, handler);\n }\n\n /**\n * Defines and registers an interrupt.\n *\n * Interrupts are special tools that halt model processing and return control back to the caller. Interrupts make it simpler to implement\n * \"human-in-the-loop\" and out-of-band processing patterns that require waiting on external actions to complete.\n *\n * @beta\n */\n defineInterrupt<I extends z.ZodTypeAny, O extends z.ZodTypeAny>(\n config: InterruptConfig<I, O>\n ): ToolAction<I, O> {\n return defineInterrupt(this.registry, config);\n }\n\n /**\n * Starts a generate operation for long running generation models, typically for\n * video and complex audio generation.\n *\n * See {@link GenerateOptions} for detailed information about available options.\n *\n * ```ts\n * const operation = await ai.generateOperation({\n * model: googleAI.model('veo-3.1-generate-preview'),\n * prompt: 'A banana riding a bicycle.',\n * });\n * ```\n *\n * The status of the operation and final result can be obtained using {@link Genkit.checkOperation}.\n */\n generateOperation<\n O extends z.ZodTypeAny = z.ZodTypeAny,\n CustomOptions extends z.ZodTypeAny = typeof GenerationCommonConfigSchema,\n >(\n opts:\n | GenerateOptions<O, CustomOptions>\n | PromiseLike<GenerateOptions<O, CustomOptions>>\n ): Promise<Operation<GenerateResponseData>> {\n return generateOperation(this.registry, opts);\n }\n\n /**\n * Defines a resource. Resources can then be accessed from a generate call.\n *\n * ```ts\n * ai.defineResource({\n * uri: 'my://resource/{param}',\n * description: 'provides my resource',\n * }, async ({param}) => {\n * return [{ text: `resource ${param}` }]\n * });\n *\n * await ai.generate({\n * prompt: [{ resource: 'my://resource/value' }]\n * })\n * ```\n */\n defineResource(opts: ResourceOptions, fn: ResourceFn): ResourceAction {\n return defineResource(this.registry, opts, fn);\n }\n}\n"],"mappings":"AAgBA;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAYK;AAEP,SAAS,oBAAoB;AAU7B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,SAAS,YAAY,YAAY;AAGjC,SAAS,cAAkC;AAmCpC,SAAS,OAAO,SAAoC;AACzD,SAAO,IAAI,WAAW,OAAO;AAC/B;AAOO,MAAM,mBAAmB,OAAO;AAAA,EACrC,YAAY,SAAyB;AACnC,UAAM,OAAO;AACb,SAAK,SAAS,eAAe;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,kBACE,QAMA,IACA;AACA,WAAO,kBAAyB,KAAK,UAAU,QAAQ,EAAE;AAAA,EAC3D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,kBAGE,QASC;AACD,WAAO,kBAA4B,KAAK,UAAU,MAAM;AAAA,EAC1D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqBA,YACE,QACA;AACA,WAAO,YAAsB,KAAK,UAAU,MAAM;AAAA,EACpD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqCA,aACE,SAGA,SACgE;AAChE,WAAO,aAAa,KAAK,UAAU,SAAS,OAAO;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,gBACE,QACkB;AAClB,WAAO,gBAAgB,KAAK,UAAU,MAAM;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,kBAIE,MAG0C;AAC1C,WAAO,kBAAkB,KAAK,UAAU,IAAI;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBA,eAAe,MAAuB,IAAgC;AACpE,WAAO,eAAe,KAAK,UAAU,MAAM,EAAE;AAAA,EAC/C;AACF;","names":[]}
@@ -0,0 +1,10 @@
1
+ import '@genkit-ai/ai';
2
+ import '@genkit-ai/ai/embedder';
3
+ import '@genkit-ai/ai/evaluator';
4
+ import '@genkit-ai/ai/model';
5
+ import '@genkit-ai/ai/reranker';
6
+ import '@genkit-ai/ai/retriever';
7
+ import '@genkit-ai/ai/tool';
8
+ import '@genkit-ai/core';
9
+ import '@genkit-ai/core/registry';
10
+ export { a as Genkit, G as GenkitOptions, h as PromptFn, _ as __disableReflectionApi, j as genkit } from './index-BSkuxdwl.mjs';
@@ -0,0 +1,10 @@
1
+ import '@genkit-ai/ai';
2
+ import '@genkit-ai/ai/embedder';
3
+ import '@genkit-ai/ai/evaluator';
4
+ import '@genkit-ai/ai/model';
5
+ import '@genkit-ai/ai/reranker';
6
+ import '@genkit-ai/ai/retriever';
7
+ import '@genkit-ai/ai/tool';
8
+ import '@genkit-ai/core';
9
+ import '@genkit-ai/core/registry';
10
+ export { a as Genkit, G as GenkitOptions, h as PromptFn, _ as __disableReflectionApi, j as genkit } from './index-BSkuxdwl.js';