@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,259 @@
1
+ /**
2
+ * Copyright 2025 Google LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import * as assert from 'assert';
18
+ import { beforeEach, describe, it } from 'node:test';
19
+ import { genkit, type GenkitBeta } from '../src/beta';
20
+ import {
21
+ backgroundModel,
22
+ embedderActionMetadata,
23
+ genkitPlugin,
24
+ genkitPluginV2,
25
+ model,
26
+ modelActionMetadata,
27
+ } from '../src/plugin';
28
+
29
+ const v1Plugin = genkitPlugin(
30
+ 'myV1Plugin',
31
+ (ai) => {
32
+ ai.defineModel({ name: 'myV1Plugin/model_eager' }, async () => {
33
+ return {};
34
+ });
35
+ },
36
+ async (ai, actionType, name) => {
37
+ switch (actionType) {
38
+ case 'model':
39
+ ai.defineModel({ name: 'myV1Plugin/' + name }, async () => {
40
+ return {};
41
+ });
42
+ case 'background-model':
43
+ ai.defineBackgroundModel({
44
+ name: 'myV1Plugin/' + name,
45
+ async start() {
46
+ return { id: 'abc' };
47
+ },
48
+ async check(operation) {
49
+ return operation;
50
+ },
51
+ async cancel(operation) {
52
+ return operation;
53
+ },
54
+ });
55
+ }
56
+ },
57
+ async () => {
58
+ return [
59
+ modelActionMetadata({
60
+ name: 'myV1Plugin/potential_model',
61
+ }),
62
+ embedderActionMetadata({
63
+ name: 'myV1Plugin/potential_embedder',
64
+ }),
65
+ ];
66
+ }
67
+ );
68
+
69
+ const v2Plugin = genkitPluginV2({
70
+ name: 'myV2Plugin',
71
+ init() {
72
+ return [
73
+ model({ name: 'model_eager' }, async () => {
74
+ return {};
75
+ }),
76
+ ];
77
+ },
78
+ resolve(actionType, name) {
79
+ switch (actionType) {
80
+ case 'model':
81
+ if (name === 'not-found') {
82
+ return undefined;
83
+ }
84
+ return model({ name }, async () => {
85
+ return {};
86
+ });
87
+ case 'background-model':
88
+ return backgroundModel({
89
+ name,
90
+ async start() {
91
+ return { id: 'abc' };
92
+ },
93
+ async check(operation) {
94
+ return operation;
95
+ },
96
+ async cancel(operation) {
97
+ return operation;
98
+ },
99
+ });
100
+ }
101
+ return undefined;
102
+ },
103
+ list() {
104
+ return [
105
+ modelActionMetadata({
106
+ name: 'potential_model',
107
+ }),
108
+ embedderActionMetadata({
109
+ name: 'potential_embedder',
110
+ }),
111
+ ];
112
+ },
113
+ });
114
+
115
+ describe('session', () => {
116
+ let ai: GenkitBeta;
117
+
118
+ beforeEach(() => {
119
+ ai = genkit({
120
+ model: 'echoModel',
121
+ plugins: [v1Plugin, v2Plugin],
122
+ });
123
+ });
124
+
125
+ it('lists actions', async () => {
126
+ assert.deepStrictEqual(
127
+ new Set(
128
+ Object.keys(await ai.registry.listResolvableActions()).filter(
129
+ (a) => a.startsWith('/model') || a.startsWith('/embedder')
130
+ )
131
+ ),
132
+ new Set([
133
+ '/embedder/myV1Plugin/potential_embedder',
134
+ '/embedder/myV2Plugin/potential_embedder',
135
+ '/model/myV1Plugin/potential_model',
136
+ '/model/myV1Plugin/model_eager',
137
+ '/model/myV2Plugin/model_eager',
138
+ '/model/myV2Plugin/potential_model',
139
+ ])
140
+ );
141
+ assert.deepStrictEqual(
142
+ new Set(
143
+ Object.keys(await ai.registry.listActions()).filter(
144
+ (a) => a.startsWith('/model') || a.startsWith('/embedder')
145
+ )
146
+ ),
147
+ new Set([
148
+ '/model/myV1Plugin/model_eager',
149
+ '/model/myV2Plugin/model_eager',
150
+ ])
151
+ );
152
+ });
153
+
154
+ it('resolves from v1 plugin', async () => {
155
+ const act = await ai.registry.lookupAction(
156
+ '/model/myV1Plugin/potential_model'
157
+ );
158
+ assert.ok(act);
159
+ assert.strictEqual(act.__action.name, 'myV1Plugin/potential_model');
160
+ assert.strictEqual(act.__action.actionType, 'model');
161
+
162
+ assert.deepStrictEqual(
163
+ new Set(
164
+ Object.keys(await ai.registry.listActions()).filter(
165
+ (a) => a.startsWith('/model') || a.startsWith('/embedder')
166
+ )
167
+ ),
168
+ new Set([
169
+ '/model/myV1Plugin/model_eager',
170
+ '/model/myV2Plugin/model_eager',
171
+ '/model/myV1Plugin/potential_model',
172
+ ])
173
+ );
174
+ });
175
+
176
+ it('resolves background model from v1 plugin', async () => {
177
+ const act = await ai.registry.lookupAction(
178
+ '/background-model/myV1Plugin/bg-model'
179
+ );
180
+ assert.ok(act);
181
+ assert.strictEqual(act.__action.name, 'myV1Plugin/bg-model');
182
+ assert.strictEqual(act.__action.actionType, 'background-model');
183
+
184
+ assert.deepStrictEqual(
185
+ new Set(
186
+ Object.keys(await ai.registry.listActions()).filter(
187
+ (a) =>
188
+ a.startsWith('/background-model') ||
189
+ a.startsWith('/check-operation') ||
190
+ a.startsWith('/cancel-operation')
191
+ )
192
+ ),
193
+ new Set([
194
+ '/background-model/myV1Plugin/bg-model',
195
+ '/check-operation/myV1Plugin/bg-model/check',
196
+ '/cancel-operation/myV1Plugin/bg-model/cancel',
197
+ ])
198
+ );
199
+ });
200
+
201
+ it('resolves from v2 plugin', async () => {
202
+ const act = await ai.registry.lookupAction(
203
+ '/model/myV2Plugin/potential_model'
204
+ );
205
+ assert.ok(act);
206
+ assert.strictEqual(act.__action.name, 'myV2Plugin/potential_model');
207
+ assert.strictEqual(act.__action.actionType, 'model');
208
+
209
+ assert.deepStrictEqual(
210
+ new Set(
211
+ Object.keys(await ai.registry.listActions()).filter(
212
+ (a) => a.startsWith('/model') || a.startsWith('/embedder')
213
+ )
214
+ ),
215
+ new Set([
216
+ '/model/myV1Plugin/model_eager',
217
+ '/model/myV2Plugin/model_eager',
218
+ '/model/myV2Plugin/potential_model',
219
+ ])
220
+ );
221
+ });
222
+
223
+ it('resolves background model from v2 plugin', async () => {
224
+ const act = await ai.registry.lookupAction(
225
+ '/background-model/myV2Plugin/bg-model'
226
+ );
227
+ assert.ok(act);
228
+ assert.strictEqual(act.__action.name, 'myV2Plugin/bg-model');
229
+ assert.strictEqual(act.__action.actionType, 'background-model');
230
+
231
+ assert.deepStrictEqual(
232
+ new Set(
233
+ Object.keys(await ai.registry.listActions()).filter(
234
+ (a) =>
235
+ a.startsWith('/background-model') ||
236
+ a.startsWith('/check-operation') ||
237
+ a.startsWith('/cancel-operation')
238
+ )
239
+ ),
240
+ new Set([
241
+ '/background-model/myV2Plugin/bg-model',
242
+ '/check-operation/myV2Plugin/bg-model/check',
243
+ '/cancel-operation/myV2Plugin/bg-model/cancel',
244
+ ])
245
+ );
246
+ });
247
+
248
+ it('resolves model using model resolve helper', async () => {
249
+ const act = await v2Plugin.model('foo-model');
250
+ assert.ok(act);
251
+ assert.strictEqual(act.__action.name, 'foo-model');
252
+ assert.strictEqual(act.__action.actionType, 'model');
253
+
254
+ await assert.rejects(v2Plugin.model('not-found'), {
255
+ name: 'GenkitError',
256
+ status: 'NOT_FOUND',
257
+ });
258
+ });
259
+ });
@@ -0,0 +1,9 @@
1
+ ---
2
+ model: googleai/gemini-2.5-flash
3
+ input:
4
+ schema: badSchemaRef1
5
+ output:
6
+ schema: badSchemaRef2
7
+ ---
8
+
9
+ doesn't matter
@@ -0,0 +1,5 @@
1
+ ---
2
+ config:
3
+ version: 'abc'
4
+ ---
5
+ hi {{ name }} from template
@@ -0,0 +1,25 @@
1
+ ---
2
+ model: googleai/gemini-5.0-ultimate-pro-plus
3
+ description: a description
4
+ config:
5
+ temperature: 11
6
+ tools:
7
+ - toolA
8
+ - toolB
9
+ returnToolRequests: true
10
+ input:
11
+ schema:
12
+ subject: string
13
+ output:
14
+ format: csv
15
+ schema:
16
+ obj?(object, a nested object):
17
+ nest1?: string
18
+ arr(array, array of objects):
19
+ nest2?: boolean
20
+ maxTurns: 77
21
+ toolChoice: required
22
+ metadata:
23
+ foo: bar
24
+ ---
25
+ {{role "system"}} Hello {{history}} from the prompt file {{ subject }}
@@ -0,0 +1,11 @@
1
+ ---
2
+ model: staticResponseModel
3
+ input:
4
+ schema:
5
+ name: string
6
+ output:
7
+ schema:
8
+ bar: string
9
+ ---
10
+
11
+ Hi {{ name }}
@@ -0,0 +1,9 @@
1
+ ---
2
+ model: googleai/gemini-2.5-flash
3
+ input:
4
+ schema: myInputSchema
5
+ output:
6
+ schema: myOutputSchema
7
+ ---
8
+
9
+ Write a poem about {{foo}}.
@@ -0,0 +1,5 @@
1
+ ---
2
+ config:
3
+ temperature: 12
4
+ ---
5
+ Hello from the sub folder prompt file
@@ -0,0 +1,5 @@
1
+ ---
2
+ config:
3
+ temperature: 11
4
+ ---
5
+ Hello from the prompt file
@@ -0,0 +1,8 @@
1
+ ---
2
+ description: a prompt variant in a file
3
+ config:
4
+ temperature: 13
5
+ tools: [toolA]
6
+ use: [myMiddleware]
7
+ ---
8
+ Hello from a variant of the hello prompt
@@ -0,0 +1,6 @@
1
+ ---
2
+ description: prompt in a file
3
+ tools:
4
+ - agentA
5
+ ---
6
+ {{ role "system" }} {{ @state.name }} toolPrompt prompt