@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,164 @@
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 client_exports = {};
20
+ __export(client_exports, {
21
+ runFlow: () => runFlow,
22
+ streamFlow: () => streamFlow
23
+ });
24
+ module.exports = __toCommonJS(client_exports);
25
+ var import_async = require("@genkit-ai/core/async");
26
+ const __flowStreamDelimiter = "\n\n";
27
+ function streamFlow({
28
+ url,
29
+ input,
30
+ init,
31
+ streamId,
32
+ headers,
33
+ abortSignal
34
+ }) {
35
+ const channel = new import_async.Channel();
36
+ const streamIdTask = (0, import_async.createTask)();
37
+ const operationPromise = __flowRunEnvelope({
38
+ url,
39
+ input,
40
+ init,
41
+ sendChunk: (c) => channel.send(c),
42
+ headers: streamId ? { ...headers, "x-genkit-stream-id": streamId } : headers,
43
+ abortSignal,
44
+ responseCallback: (response) => {
45
+ streamIdTask.resolve(response.headers.get("x-genkit-stream-id"));
46
+ }
47
+ });
48
+ operationPromise.then(
49
+ () => channel.close(),
50
+ (err) => channel.error(err)
51
+ );
52
+ return {
53
+ output: operationPromise,
54
+ stream: channel,
55
+ streamId: streamIdTask.promise
56
+ };
57
+ }
58
+ async function __flowRunEnvelope({
59
+ url,
60
+ input,
61
+ init,
62
+ sendChunk,
63
+ headers,
64
+ abortSignal,
65
+ responseCallback
66
+ }) {
67
+ const response = await fetch(url, {
68
+ method: "POST",
69
+ body: JSON.stringify({
70
+ data: input,
71
+ ...init !== void 0 && { init }
72
+ }),
73
+ headers: {
74
+ Accept: "text/event-stream",
75
+ "Content-Type": "application/json",
76
+ ...headers
77
+ },
78
+ signal: abortSignal
79
+ });
80
+ if (responseCallback) {
81
+ responseCallback(response);
82
+ }
83
+ if (response.status === 204) {
84
+ throw new Error("NOT_FOUND: Stream not found.");
85
+ }
86
+ if (response.status !== 200) {
87
+ throw new Error(
88
+ `Server returned: ${response.status}: ${await response.text()}`
89
+ );
90
+ }
91
+ if (!response.body) {
92
+ throw new Error("Response body is empty");
93
+ }
94
+ var reader = response.body.getReader();
95
+ var decoder = new TextDecoder();
96
+ let buffer = "";
97
+ while (true) {
98
+ const result = await reader.read();
99
+ const decodedValue = decoder.decode(result.value);
100
+ if (decodedValue) {
101
+ buffer += decodedValue;
102
+ }
103
+ while (buffer.includes(__flowStreamDelimiter)) {
104
+ const chunk = JSON.parse(
105
+ buffer.substring(0, buffer.indexOf(__flowStreamDelimiter)).substring("data: ".length)
106
+ );
107
+ if (chunk.hasOwnProperty("message")) {
108
+ sendChunk(chunk.message);
109
+ } else if (chunk.hasOwnProperty("result")) {
110
+ return chunk.result;
111
+ } else if (chunk.hasOwnProperty("error")) {
112
+ throw new Error(
113
+ `${chunk.error.status}: ${chunk.error.message}
114
+ ${chunk.error.details}`
115
+ );
116
+ } else {
117
+ throw new Error("unknown chunk format: " + JSON.stringify(chunk));
118
+ }
119
+ buffer = buffer.substring(
120
+ buffer.indexOf(__flowStreamDelimiter) + __flowStreamDelimiter.length
121
+ );
122
+ }
123
+ }
124
+ throw new Error("stream did not terminate correctly");
125
+ }
126
+ async function runFlow({
127
+ url,
128
+ input,
129
+ init,
130
+ headers,
131
+ abortSignal
132
+ }) {
133
+ const response = await fetch(url, {
134
+ method: "POST",
135
+ body: JSON.stringify({
136
+ data: input,
137
+ ...init !== void 0 && { init }
138
+ }),
139
+ headers: {
140
+ "Content-Type": "application/json",
141
+ ...headers
142
+ },
143
+ signal: abortSignal
144
+ });
145
+ if (response.status !== 200) {
146
+ throw new Error(
147
+ `Server returned: ${response.status}: ${await response.text()}`
148
+ );
149
+ }
150
+ const wrappedResult = await response.json();
151
+ if ("error" in wrappedResult) {
152
+ if (typeof wrappedResult.error === "string") {
153
+ throw new Error(wrappedResult.error);
154
+ }
155
+ throw new Error(JSON.stringify(wrappedResult.error));
156
+ }
157
+ return wrappedResult.result;
158
+ }
159
+ // Annotate the CommonJS export names for ESM import in node:
160
+ 0 && (module.exports = {
161
+ runFlow,
162
+ streamFlow
163
+ });
164
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/client/client.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 { Channel, createTask } from '@genkit-ai/core/async';\n\nconst __flowStreamDelimiter = '\\n\\n';\n\n/**\n * Invoke and stream response from a deployed flow.\n *\n * For example:\n *\n * ```js\n * import { streamFlow } from 'genkit/beta/client';\n *\n * const response = streamFlow({\n * url: 'https://my-flow-deployed-url',\n * input: 'foo',\n * });\n * for await (const chunk of response.stream) {\n * console.log(chunk);\n * }\n * console.log(await response.output);\n * ```\n */\nexport function streamFlow<O = any, S = any, Init = any>({\n url,\n input,\n init,\n streamId,\n headers,\n abortSignal,\n}: {\n /** URL of the deployed flow. */\n url: string;\n /** Flow input. */\n input?: any;\n /** Initialization data for the action. */\n init?: Init;\n /** Stream ID to connect to. */\n streamId?: string;\n /** A map of HTTP headers to be added to the HTTP call. */\n headers?: Record<string, string>;\n /** Abort signal to abort the request. */\n abortSignal?: AbortSignal;\n}): {\n readonly output: Promise<O>;\n readonly stream: AsyncIterable<S>;\n readonly streamId: Promise<string | null>;\n} {\n const channel = new Channel<S>();\n const streamIdTask = createTask<string | null>();\n\n const operationPromise = __flowRunEnvelope({\n url,\n input,\n init,\n sendChunk: (c) => channel.send(c),\n headers: streamId\n ? { ...headers, 'x-genkit-stream-id': streamId }\n : headers,\n abortSignal,\n responseCallback: (response) => {\n streamIdTask.resolve(response.headers.get('x-genkit-stream-id'));\n },\n });\n operationPromise.then(\n () => channel.close(),\n (err) => channel.error(err)\n );\n\n return {\n output: operationPromise,\n stream: channel,\n streamId: streamIdTask.promise,\n };\n}\n\nasync function __flowRunEnvelope({\n url,\n input,\n init,\n sendChunk,\n headers,\n abortSignal,\n responseCallback,\n}: {\n url: string;\n input: any;\n init?: any;\n sendChunk: (chunk: any) => void;\n headers?: Record<string, string>;\n abortSignal?: AbortSignal;\n responseCallback?: (response: Response) => void;\n}) {\n const response = await fetch(url, {\n method: 'POST',\n body: JSON.stringify({\n data: input,\n ...(init !== undefined && { init }),\n }),\n headers: {\n Accept: 'text/event-stream',\n 'Content-Type': 'application/json',\n ...headers,\n },\n signal: abortSignal,\n });\n if (responseCallback) {\n responseCallback(response);\n }\n if (response.status === 204) {\n throw new Error('NOT_FOUND: Stream not found.');\n }\n if (response.status !== 200) {\n throw new Error(\n `Server returned: ${response.status}: ${await response.text()}`\n );\n }\n if (!response.body) {\n throw new Error('Response body is empty');\n }\n var reader = response.body.getReader();\n var decoder = new TextDecoder();\n\n let buffer = '';\n while (true) {\n const result = await reader.read();\n const decodedValue = decoder.decode(result.value);\n if (decodedValue) {\n buffer += decodedValue;\n }\n // If buffer includes the delimiter that means we are still receiving chunks.\n while (buffer.includes(__flowStreamDelimiter)) {\n const chunk = JSON.parse(\n buffer\n .substring(0, buffer.indexOf(__flowStreamDelimiter))\n .substring('data: '.length)\n );\n if (chunk.hasOwnProperty('message')) {\n sendChunk(chunk.message);\n } else if (chunk.hasOwnProperty('result')) {\n return chunk.result;\n } else if (chunk.hasOwnProperty('error')) {\n throw new Error(\n `${chunk.error.status}: ${chunk.error.message}\\n${chunk.error.details}`\n );\n } else {\n throw new Error('unknown chunk format: ' + JSON.stringify(chunk));\n }\n buffer = buffer.substring(\n buffer.indexOf(__flowStreamDelimiter) + __flowStreamDelimiter.length\n );\n }\n }\n throw new Error('stream did not terminate correctly');\n}\n\n/**\n * Invoke a deployed flow over HTTP(s).\n *\n * For example:\n *\n * ```js\n * import { runFlow } from 'genkit/beta/client';\n *\n * const response = await runFlow({\n * url: 'https://my-flow-deployed-url',\n * input: 'foo',\n * });\n * console.log(await response);\n * ```\n */\nexport async function runFlow<O = any, Init = any>({\n url,\n input,\n init,\n headers,\n abortSignal,\n}: {\n /** URL of the deployed flow. */\n url: string;\n /** Flow input. */\n input?: any;\n /** Initialization data for the action. */\n init?: Init;\n /** A map of HTTP headers to be added to the HTTP call. */\n headers?: Record<string, string>;\n /** Abort signal to abort the request. */\n abortSignal?: AbortSignal;\n}): Promise<O> {\n const response = await fetch(url, {\n method: 'POST',\n body: JSON.stringify({\n data: input,\n ...(init !== undefined && { init }),\n }),\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n signal: abortSignal,\n });\n if (response.status !== 200) {\n throw new Error(\n `Server returned: ${response.status}: ${await response.text()}`\n );\n }\n const wrappedResult = (await response.json()) as\n | { result: O }\n | { error: unknown };\n if ('error' in wrappedResult) {\n if (typeof wrappedResult.error === 'string') {\n throw new Error(wrappedResult.error);\n }\n // TODO: The callable protocol defines an HttpError that has a JSON format of\n // details?: string\n // httpErrorCode: { canonicalName: string }\n // message: string\n // Should we create a new error class that parses this and exposes it as fields?\n throw new Error(JSON.stringify(wrappedResult.error));\n }\n return wrappedResult.result;\n}\n"],"mappings":"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","names":[]}
@@ -0,0 +1,139 @@
1
+ import { Channel, createTask } from "@genkit-ai/core/async";
2
+ const __flowStreamDelimiter = "\n\n";
3
+ function streamFlow({
4
+ url,
5
+ input,
6
+ init,
7
+ streamId,
8
+ headers,
9
+ abortSignal
10
+ }) {
11
+ const channel = new Channel();
12
+ const streamIdTask = createTask();
13
+ const operationPromise = __flowRunEnvelope({
14
+ url,
15
+ input,
16
+ init,
17
+ sendChunk: (c) => channel.send(c),
18
+ headers: streamId ? { ...headers, "x-genkit-stream-id": streamId } : headers,
19
+ abortSignal,
20
+ responseCallback: (response) => {
21
+ streamIdTask.resolve(response.headers.get("x-genkit-stream-id"));
22
+ }
23
+ });
24
+ operationPromise.then(
25
+ () => channel.close(),
26
+ (err) => channel.error(err)
27
+ );
28
+ return {
29
+ output: operationPromise,
30
+ stream: channel,
31
+ streamId: streamIdTask.promise
32
+ };
33
+ }
34
+ async function __flowRunEnvelope({
35
+ url,
36
+ input,
37
+ init,
38
+ sendChunk,
39
+ headers,
40
+ abortSignal,
41
+ responseCallback
42
+ }) {
43
+ const response = await fetch(url, {
44
+ method: "POST",
45
+ body: JSON.stringify({
46
+ data: input,
47
+ ...init !== void 0 && { init }
48
+ }),
49
+ headers: {
50
+ Accept: "text/event-stream",
51
+ "Content-Type": "application/json",
52
+ ...headers
53
+ },
54
+ signal: abortSignal
55
+ });
56
+ if (responseCallback) {
57
+ responseCallback(response);
58
+ }
59
+ if (response.status === 204) {
60
+ throw new Error("NOT_FOUND: Stream not found.");
61
+ }
62
+ if (response.status !== 200) {
63
+ throw new Error(
64
+ `Server returned: ${response.status}: ${await response.text()}`
65
+ );
66
+ }
67
+ if (!response.body) {
68
+ throw new Error("Response body is empty");
69
+ }
70
+ var reader = response.body.getReader();
71
+ var decoder = new TextDecoder();
72
+ let buffer = "";
73
+ while (true) {
74
+ const result = await reader.read();
75
+ const decodedValue = decoder.decode(result.value);
76
+ if (decodedValue) {
77
+ buffer += decodedValue;
78
+ }
79
+ while (buffer.includes(__flowStreamDelimiter)) {
80
+ const chunk = JSON.parse(
81
+ buffer.substring(0, buffer.indexOf(__flowStreamDelimiter)).substring("data: ".length)
82
+ );
83
+ if (chunk.hasOwnProperty("message")) {
84
+ sendChunk(chunk.message);
85
+ } else if (chunk.hasOwnProperty("result")) {
86
+ return chunk.result;
87
+ } else if (chunk.hasOwnProperty("error")) {
88
+ throw new Error(
89
+ `${chunk.error.status}: ${chunk.error.message}
90
+ ${chunk.error.details}`
91
+ );
92
+ } else {
93
+ throw new Error("unknown chunk format: " + JSON.stringify(chunk));
94
+ }
95
+ buffer = buffer.substring(
96
+ buffer.indexOf(__flowStreamDelimiter) + __flowStreamDelimiter.length
97
+ );
98
+ }
99
+ }
100
+ throw new Error("stream did not terminate correctly");
101
+ }
102
+ async function runFlow({
103
+ url,
104
+ input,
105
+ init,
106
+ headers,
107
+ abortSignal
108
+ }) {
109
+ const response = await fetch(url, {
110
+ method: "POST",
111
+ body: JSON.stringify({
112
+ data: input,
113
+ ...init !== void 0 && { init }
114
+ }),
115
+ headers: {
116
+ "Content-Type": "application/json",
117
+ ...headers
118
+ },
119
+ signal: abortSignal
120
+ });
121
+ if (response.status !== 200) {
122
+ throw new Error(
123
+ `Server returned: ${response.status}: ${await response.text()}`
124
+ );
125
+ }
126
+ const wrappedResult = await response.json();
127
+ if ("error" in wrappedResult) {
128
+ if (typeof wrappedResult.error === "string") {
129
+ throw new Error(wrappedResult.error);
130
+ }
131
+ throw new Error(JSON.stringify(wrappedResult.error));
132
+ }
133
+ return wrappedResult.result;
134
+ }
135
+ export {
136
+ runFlow,
137
+ streamFlow
138
+ };
139
+ //# sourceMappingURL=client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/client/client.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 { Channel, createTask } from '@genkit-ai/core/async';\n\nconst __flowStreamDelimiter = '\\n\\n';\n\n/**\n * Invoke and stream response from a deployed flow.\n *\n * For example:\n *\n * ```js\n * import { streamFlow } from 'genkit/beta/client';\n *\n * const response = streamFlow({\n * url: 'https://my-flow-deployed-url',\n * input: 'foo',\n * });\n * for await (const chunk of response.stream) {\n * console.log(chunk);\n * }\n * console.log(await response.output);\n * ```\n */\nexport function streamFlow<O = any, S = any, Init = any>({\n url,\n input,\n init,\n streamId,\n headers,\n abortSignal,\n}: {\n /** URL of the deployed flow. */\n url: string;\n /** Flow input. */\n input?: any;\n /** Initialization data for the action. */\n init?: Init;\n /** Stream ID to connect to. */\n streamId?: string;\n /** A map of HTTP headers to be added to the HTTP call. */\n headers?: Record<string, string>;\n /** Abort signal to abort the request. */\n abortSignal?: AbortSignal;\n}): {\n readonly output: Promise<O>;\n readonly stream: AsyncIterable<S>;\n readonly streamId: Promise<string | null>;\n} {\n const channel = new Channel<S>();\n const streamIdTask = createTask<string | null>();\n\n const operationPromise = __flowRunEnvelope({\n url,\n input,\n init,\n sendChunk: (c) => channel.send(c),\n headers: streamId\n ? { ...headers, 'x-genkit-stream-id': streamId }\n : headers,\n abortSignal,\n responseCallback: (response) => {\n streamIdTask.resolve(response.headers.get('x-genkit-stream-id'));\n },\n });\n operationPromise.then(\n () => channel.close(),\n (err) => channel.error(err)\n );\n\n return {\n output: operationPromise,\n stream: channel,\n streamId: streamIdTask.promise,\n };\n}\n\nasync function __flowRunEnvelope({\n url,\n input,\n init,\n sendChunk,\n headers,\n abortSignal,\n responseCallback,\n}: {\n url: string;\n input: any;\n init?: any;\n sendChunk: (chunk: any) => void;\n headers?: Record<string, string>;\n abortSignal?: AbortSignal;\n responseCallback?: (response: Response) => void;\n}) {\n const response = await fetch(url, {\n method: 'POST',\n body: JSON.stringify({\n data: input,\n ...(init !== undefined && { init }),\n }),\n headers: {\n Accept: 'text/event-stream',\n 'Content-Type': 'application/json',\n ...headers,\n },\n signal: abortSignal,\n });\n if (responseCallback) {\n responseCallback(response);\n }\n if (response.status === 204) {\n throw new Error('NOT_FOUND: Stream not found.');\n }\n if (response.status !== 200) {\n throw new Error(\n `Server returned: ${response.status}: ${await response.text()}`\n );\n }\n if (!response.body) {\n throw new Error('Response body is empty');\n }\n var reader = response.body.getReader();\n var decoder = new TextDecoder();\n\n let buffer = '';\n while (true) {\n const result = await reader.read();\n const decodedValue = decoder.decode(result.value);\n if (decodedValue) {\n buffer += decodedValue;\n }\n // If buffer includes the delimiter that means we are still receiving chunks.\n while (buffer.includes(__flowStreamDelimiter)) {\n const chunk = JSON.parse(\n buffer\n .substring(0, buffer.indexOf(__flowStreamDelimiter))\n .substring('data: '.length)\n );\n if (chunk.hasOwnProperty('message')) {\n sendChunk(chunk.message);\n } else if (chunk.hasOwnProperty('result')) {\n return chunk.result;\n } else if (chunk.hasOwnProperty('error')) {\n throw new Error(\n `${chunk.error.status}: ${chunk.error.message}\\n${chunk.error.details}`\n );\n } else {\n throw new Error('unknown chunk format: ' + JSON.stringify(chunk));\n }\n buffer = buffer.substring(\n buffer.indexOf(__flowStreamDelimiter) + __flowStreamDelimiter.length\n );\n }\n }\n throw new Error('stream did not terminate correctly');\n}\n\n/**\n * Invoke a deployed flow over HTTP(s).\n *\n * For example:\n *\n * ```js\n * import { runFlow } from 'genkit/beta/client';\n *\n * const response = await runFlow({\n * url: 'https://my-flow-deployed-url',\n * input: 'foo',\n * });\n * console.log(await response);\n * ```\n */\nexport async function runFlow<O = any, Init = any>({\n url,\n input,\n init,\n headers,\n abortSignal,\n}: {\n /** URL of the deployed flow. */\n url: string;\n /** Flow input. */\n input?: any;\n /** Initialization data for the action. */\n init?: Init;\n /** A map of HTTP headers to be added to the HTTP call. */\n headers?: Record<string, string>;\n /** Abort signal to abort the request. */\n abortSignal?: AbortSignal;\n}): Promise<O> {\n const response = await fetch(url, {\n method: 'POST',\n body: JSON.stringify({\n data: input,\n ...(init !== undefined && { init }),\n }),\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n signal: abortSignal,\n });\n if (response.status !== 200) {\n throw new Error(\n `Server returned: ${response.status}: ${await response.text()}`\n );\n }\n const wrappedResult = (await response.json()) as\n | { result: O }\n | { error: unknown };\n if ('error' in wrappedResult) {\n if (typeof wrappedResult.error === 'string') {\n throw new Error(wrappedResult.error);\n }\n // TODO: The callable protocol defines an HttpError that has a JSON format of\n // details?: string\n // httpErrorCode: { canonicalName: string }\n // message: string\n // Should we create a new error class that parses this and exposes it as fields?\n throw new Error(JSON.stringify(wrappedResult.error));\n }\n return wrappedResult.result;\n}\n"],"mappings":"AAgBA,SAAS,SAAS,kBAAkB;AAEpC,MAAM,wBAAwB;AAoBvB,SAAS,WAAyC;AAAA,EACvD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAiBE;AACA,QAAM,UAAU,IAAI,QAAW;AAC/B,QAAM,eAAe,WAA0B;AAE/C,QAAM,mBAAmB,kBAAkB;AAAA,IACzC;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW,CAAC,MAAM,QAAQ,KAAK,CAAC;AAAA,IAChC,SAAS,WACL,EAAE,GAAG,SAAS,sBAAsB,SAAS,IAC7C;AAAA,IACJ;AAAA,IACA,kBAAkB,CAAC,aAAa;AAC9B,mBAAa,QAAQ,SAAS,QAAQ,IAAI,oBAAoB,CAAC;AAAA,IACjE;AAAA,EACF,CAAC;AACD,mBAAiB;AAAA,IACf,MAAM,QAAQ,MAAM;AAAA,IACpB,CAAC,QAAQ,QAAQ,MAAM,GAAG;AAAA,EAC5B;AAEA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,UAAU,aAAa;AAAA,EACzB;AACF;AAEA,eAAe,kBAAkB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAQG;AACD,QAAM,WAAW,MAAM,MAAM,KAAK;AAAA,IAChC,QAAQ;AAAA,IACR,MAAM,KAAK,UAAU;AAAA,MACnB,MAAM;AAAA,MACN,GAAI,SAAS,UAAa,EAAE,KAAK;AAAA,IACnC,CAAC;AAAA,IACD,SAAS;AAAA,MACP,QAAQ;AAAA,MACR,gBAAgB;AAAA,MAChB,GAAG;AAAA,IACL;AAAA,IACA,QAAQ;AAAA,EACV,CAAC;AACD,MAAI,kBAAkB;AACpB,qBAAiB,QAAQ;AAAA,EAC3B;AACA,MAAI,SAAS,WAAW,KAAK;AAC3B,UAAM,IAAI,MAAM,8BAA8B;AAAA,EAChD;AACA,MAAI,SAAS,WAAW,KAAK;AAC3B,UAAM,IAAI;AAAA,MACR,oBAAoB,SAAS,MAAM,KAAK,MAAM,SAAS,KAAK,CAAC;AAAA,IAC/D;AAAA,EACF;AACA,MAAI,CAAC,SAAS,MAAM;AAClB,UAAM,IAAI,MAAM,wBAAwB;AAAA,EAC1C;AACA,MAAI,SAAS,SAAS,KAAK,UAAU;AACrC,MAAI,UAAU,IAAI,YAAY;AAE9B,MAAI,SAAS;AACb,SAAO,MAAM;AACX,UAAM,SAAS,MAAM,OAAO,KAAK;AACjC,UAAM,eAAe,QAAQ,OAAO,OAAO,KAAK;AAChD,QAAI,cAAc;AAChB,gBAAU;AAAA,IACZ;AAEA,WAAO,OAAO,SAAS,qBAAqB,GAAG;AAC7C,YAAM,QAAQ,KAAK;AAAA,QACjB,OACG,UAAU,GAAG,OAAO,QAAQ,qBAAqB,CAAC,EAClD,UAAU,SAAS,MAAM;AAAA,MAC9B;AACA,UAAI,MAAM,eAAe,SAAS,GAAG;AACnC,kBAAU,MAAM,OAAO;AAAA,MACzB,WAAW,MAAM,eAAe,QAAQ,GAAG;AACzC,eAAO,MAAM;AAAA,MACf,WAAW,MAAM,eAAe,OAAO,GAAG;AACxC,cAAM,IAAI;AAAA,UACR,GAAG,MAAM,MAAM,MAAM,KAAK,MAAM,MAAM,OAAO;AAAA,EAAK,MAAM,MAAM,OAAO;AAAA,QACvE;AAAA,MACF,OAAO;AACL,cAAM,IAAI,MAAM,2BAA2B,KAAK,UAAU,KAAK,CAAC;AAAA,MAClE;AACA,eAAS,OAAO;AAAA,QACd,OAAO,QAAQ,qBAAqB,IAAI,sBAAsB;AAAA,MAChE;AAAA,IACF;AAAA,EACF;AACA,QAAM,IAAI,MAAM,oCAAoC;AACtD;AAiBA,eAAsB,QAA6B;AAAA,EACjD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAWe;AACb,QAAM,WAAW,MAAM,MAAM,KAAK;AAAA,IAChC,QAAQ;AAAA,IACR,MAAM,KAAK,UAAU;AAAA,MACnB,MAAM;AAAA,MACN,GAAI,SAAS,UAAa,EAAE,KAAK;AAAA,IACnC,CAAC;AAAA,IACD,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,GAAG;AAAA,IACL;AAAA,IACA,QAAQ;AAAA,EACV,CAAC;AACD,MAAI,SAAS,WAAW,KAAK;AAC3B,UAAM,IAAI;AAAA,MACR,oBAAoB,SAAS,MAAM,KAAK,MAAM,SAAS,KAAK,CAAC;AAAA,IAC/D;AAAA,EACF;AACA,QAAM,gBAAiB,MAAM,SAAS,KAAK;AAG3C,MAAI,WAAW,eAAe;AAC5B,QAAI,OAAO,cAAc,UAAU,UAAU;AAC3C,YAAM,IAAI,MAAM,cAAc,KAAK;AAAA,IACrC;AAMA,UAAM,IAAI,MAAM,KAAK,UAAU,cAAc,KAAK,CAAC;AAAA,EACrD;AACA,SAAO,cAAc;AACvB;","names":[]}
@@ -0,0 +1,6 @@
1
+ export { RemoteAgentOptions, remoteAgent } from './agent.mjs';
2
+ export { runFlow, streamFlow } from './client.mjs';
3
+ export { AgentInit, AgentInput, AgentOutput, AgentStreamChunk, GenerationUsage, MessageData, Part, ToolRequestPart, ToolResponsePart } from '@genkit-ai/ai';
4
+ export { AgentFinishReason, Artifact, SessionSnapshot, SessionState } from '@genkit-ai/ai/session';
5
+ export { AgentAPI, AgentChat, AgentChunk, AgentError, AgentInterrupt, AgentResponse, AgentTurn, DetachedTask } from '@genkit-ai/ai/agent-core';
6
+ export { JsonPatch, applyPatch } from '@genkit-ai/ai/json-patch';
@@ -0,0 +1,6 @@
1
+ export { RemoteAgentOptions, remoteAgent } from './agent.js';
2
+ export { runFlow, streamFlow } from './client.js';
3
+ export { AgentInit, AgentInput, AgentOutput, AgentStreamChunk, GenerationUsage, MessageData, Part, ToolRequestPart, ToolResponsePart } from '@genkit-ai/ai';
4
+ export { AgentFinishReason, Artifact, SessionSnapshot, SessionState } from '@genkit-ai/ai/session';
5
+ export { AgentAPI, AgentChat, AgentChunk, AgentError, AgentInterrupt, AgentResponse, AgentTurn, DetachedTask } from '@genkit-ai/ai/agent-core';
6
+ export { JsonPatch, applyPatch } from '@genkit-ai/ai/json-patch';
@@ -0,0 +1,55 @@
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 client_exports = {};
20
+ __export(client_exports, {
21
+ AgentError: () => import_agent.AgentError,
22
+ applyPatch: () => import_agent.applyPatch,
23
+ remoteAgent: () => import_agent.remoteAgent,
24
+ runFlow: () => import_client.runFlow,
25
+ streamFlow: () => import_client.streamFlow
26
+ });
27
+ module.exports = __toCommonJS(client_exports);
28
+ var import_agent = require("./agent.js");
29
+ var import_client = require("./client.js");
30
+ /**
31
+ * @license
32
+ *
33
+ * Copyright 2024 Google LLC
34
+ *
35
+ * Licensed under the Apache License, Version 2.0 (the "License");
36
+ * you may not use this file except in compliance with the License.
37
+ * You may obtain a copy of the License at
38
+ *
39
+ * http://www.apache.org/licenses/LICENSE-2.0
40
+ *
41
+ * Unless required by applicable law or agreed to in writing, software
42
+ * distributed under the License is distributed on an "AS IS" BASIS,
43
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
44
+ * See the License for the specific language governing permissions and
45
+ * limitations under the License.
46
+ */
47
+ // Annotate the CommonJS export names for ESM import in node:
48
+ 0 && (module.exports = {
49
+ AgentError,
50
+ applyPatch,
51
+ remoteAgent,
52
+ runFlow,
53
+ streamFlow
54
+ });
55
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/client/index.ts"],"sourcesContent":["/**\n * @license\n *\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\n/**\n * A simple, browser-safe client library for remotely running/streaming deployed Genkit flows.\n *\n * ```ts\n * import { runFlow, streamFlow } from 'genkit/beta/client';\n *\n * const response = await runFlow({\n * url: 'https://my-flow-deployed-url',\n * input: 'foo',\n * });\n *\n * const response = streamFlow({\n * url: 'https://my-flow-deployed-url',\n * input: 'foo',\n * });\n * for await (const chunk of response.stream) {\n * console.log(chunk);\n * }\n * console.log(await response.output);\n * ```\n *\n * @module beta/client\n */\nexport {\n AgentError,\n applyPatch,\n remoteAgent,\n type AgentAPI,\n type AgentChat,\n type AgentChunk,\n type AgentInterrupt,\n type AgentResponse,\n type AgentTurn,\n type DetachedTask,\n type JsonPatch,\n type RemoteAgentOptions,\n} from './agent.js';\n\nexport { runFlow, streamFlow } from './client.js';\nexport type {\n AgentFinishReason,\n AgentInit,\n AgentInput,\n AgentOutput,\n AgentStreamChunk,\n Artifact,\n GenerationUsage,\n MessageData,\n Part,\n SessionSnapshot,\n SessionState,\n ToolRequestPart,\n ToolResponsePart,\n} from './types.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyCA,mBAaO;AAEP,oBAAoC;AAxDpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;","names":[]}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @license
3
+ *
4
+ * Copyright 2024 Google LLC
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ import {
19
+ AgentError,
20
+ applyPatch,
21
+ remoteAgent
22
+ } from "./agent.mjs";
23
+ import { runFlow, streamFlow } from "./client.mjs";
24
+ export {
25
+ AgentError,
26
+ applyPatch,
27
+ remoteAgent,
28
+ runFlow,
29
+ streamFlow
30
+ };
31
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/client/index.ts"],"sourcesContent":["/**\n * @license\n *\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\n/**\n * A simple, browser-safe client library for remotely running/streaming deployed Genkit flows.\n *\n * ```ts\n * import { runFlow, streamFlow } from 'genkit/beta/client';\n *\n * const response = await runFlow({\n * url: 'https://my-flow-deployed-url',\n * input: 'foo',\n * });\n *\n * const response = streamFlow({\n * url: 'https://my-flow-deployed-url',\n * input: 'foo',\n * });\n * for await (const chunk of response.stream) {\n * console.log(chunk);\n * }\n * console.log(await response.output);\n * ```\n *\n * @module beta/client\n */\nexport {\n AgentError,\n applyPatch,\n remoteAgent,\n type AgentAPI,\n type AgentChat,\n type AgentChunk,\n type AgentInterrupt,\n type AgentResponse,\n type AgentTurn,\n type DetachedTask,\n type JsonPatch,\n type RemoteAgentOptions,\n} from './agent.mjs';\n\nexport { runFlow, streamFlow } from './client.mjs';\nexport type {\n AgentFinishReason,\n AgentInit,\n AgentInput,\n AgentOutput,\n AgentStreamChunk,\n Artifact,\n GenerationUsage,\n MessageData,\n Part,\n SessionSnapshot,\n SessionState,\n ToolRequestPart,\n ToolResponsePart,\n} from './types.mjs';\n"],"mappings":"AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyCA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAUK;AAEP,SAAS,SAAS,kBAAkB;","names":[]}
@@ -0,0 +1,17 @@
1
+ export { AgentInit, AgentInput, AgentOutput, AgentStreamChunk, GenerationUsage, MessageData, Part, ToolRequestPart, ToolResponsePart } from '@genkit-ai/ai';
2
+ export { AgentFinishReason, Artifact, SessionSnapshot, SessionState } from '@genkit-ai/ai/session';
3
+ import '@genkit-ai/ai/tool';
4
+ import '@genkit-ai/core';
5
+ import '@genkit-ai/ai/formats';
6
+ import '@genkit-ai/ai/evaluator';
7
+ import '@genkit-ai/core/registry';
8
+ import '@genkit-ai/ai/embedder';
9
+ import '@genkit-ai/ai/extract';
10
+ import '@genkit-ai/core/logging';
11
+ import '@genkit-ai/ai/model/middleware';
12
+ import '@genkit-ai/ai/model';
13
+ import '@genkit-ai/ai/reranker';
14
+ import '@genkit-ai/ai/retriever';
15
+ import '@genkit-ai/core/schema';
16
+ import '@genkit-ai/ai/testing';
17
+ import '@genkit-ai/core/tracing';
@@ -0,0 +1,17 @@
1
+ export { AgentInit, AgentInput, AgentOutput, AgentStreamChunk, GenerationUsage, MessageData, Part, ToolRequestPart, ToolResponsePart } from '@genkit-ai/ai';
2
+ export { AgentFinishReason, Artifact, SessionSnapshot, SessionState } from '@genkit-ai/ai/session';
3
+ import '@genkit-ai/ai/tool';
4
+ import '@genkit-ai/core';
5
+ import '@genkit-ai/ai/formats';
6
+ import '@genkit-ai/ai/evaluator';
7
+ import '@genkit-ai/core/registry';
8
+ import '@genkit-ai/ai/embedder';
9
+ import '@genkit-ai/ai/extract';
10
+ import '@genkit-ai/core/logging';
11
+ import '@genkit-ai/ai/model/middleware';
12
+ import '@genkit-ai/ai/model';
13
+ import '@genkit-ai/ai/reranker';
14
+ import '@genkit-ai/ai/retriever';
15
+ import '@genkit-ai/core/schema';
16
+ import '@genkit-ai/ai/testing';
17
+ import '@genkit-ai/core/tracing';
@@ -0,0 +1,17 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);
17
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/client/types.ts"],"sourcesContent":["/**\n * Copyright 2026 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\n/**\n * Type-only re-exports of the agent/generate contract types used by the agent\n * client. Kept type-only so the browser-safe client pulls in no runtime code\n * from `@genkit-ai/ai`.\n *\n * @module beta/client/types\n */\n\nexport type {\n AgentInit,\n AgentInput,\n AgentOutput,\n AgentStreamChunk,\n GenerationUsage,\n MessageData,\n Part,\n ToolRequestPart,\n ToolResponsePart,\n} from '@genkit-ai/ai';\nexport type {\n AgentFinishReason,\n Artifact,\n SessionSnapshot,\n SessionState,\n} from '@genkit-ai/ai/session';\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,3 @@
1
+ export { BaseDataPointSchema, Document, DocumentData, DocumentDataSchema, DynamicResourceAction, EmbedderAction, EmbedderArgument, EmbedderInfo, EmbedderParams, EmbedderReference, Embedding, EvalResponses, EvaluatorAction, EvaluatorInfo, EvaluatorParams, EvaluatorReference, ExecutablePrompt, GENKIT_UI_METADATA, GENKIT_UI_WIDGETS, GenerateMiddleware, GenerateMiddlewareDef, GenerateOptions, GenerateRequest, GenerateRequestData, GenerateResponse, GenerateResponseChunk, GenerateResponseChunkData, GenerateResponseData, GenerateStreamOptions, GenerateStreamResponse, GenerationBlockedError, GenerationCommonConfigSchema, GenerationResponseError, GenerationUsage, IndexerAction, IndexerArgument, IndexerInfo, IndexerParams, IndexerReference, InterruptConfig, LlmResponse, LlmResponseSchema, LlmStats, LlmStatsSchema, MediaPart, Message, MessageData, MessageSchema, MiddlewareDesc, MiddlewareDescSchema, MiddlewareRef, MiddlewareRefSchema, ModelArgument, ModelReference, ModelReferenceSchema, ModelRequest, ModelRequestSchema, ModelResponseData, ModelResponseSchema, MultipartToolAction, OperationOptions, OutputOptions, Part, PartSchema, PromptAction, PromptConfig, PromptGenerateOptions, RankedDocument, RerankerAction, RerankerArgument, RerankerInfo, RerankerParams, RerankerReference, ResourceAction, ResumeOptions, RetrieverAction, RetrieverArgument, RetrieverInfo, RetrieverParams, RetrieverReference, Role, RoleSchema, Tool, ToolAction, ToolArgument, ToolCall, ToolCallSchema, ToolChoice, ToolConfig, ToolInterruptError, ToolRequest, ToolRequestPart, ToolResponse, ToolResponsePart, ToolSchema, dynamicResource, embedderActionMetadata, embedderRef, evaluatorRef, generateMiddleware, indexerRef, modelActionMetadata, modelRef, rerankerRef, resource, respondTool, restartTool, retrieverRef } from '@genkit-ai/ai';
2
+ export { dynamicTool, tool } from '@genkit-ai/ai/tool';
3
+ export { Action, ActionContext, ActionMetadata, DynamicActionProviderAction, ErrorResponseMetadata, Flow, FlowConfig, FlowFn, FlowSideChannel, GENKIT_CLIENT_HEADER, GENKIT_VERSION, GenkitError, GenkitRuntimeConfig, JSONSchema, JSONSchema7, Middleware, Operation, OperationSchema, ReflectionServer, ReflectionServerOptions, RunActionResponse, Status, StatusCodes, StatusName, StatusNameSchema, StatusSchema, StreamingCallback, StreamingResponse, TelemetryConfig, UserFacingError, annotateSchema, defineJsonSchema, defineSchema, getClientHeader, getCurrentEnv, getGenkitRuntimeConfig, getStreamingCallback, isDevEnv, resetGenkitRuntimeConfig, runWithStreamingCallback, setGenkitRuntimeConfig, z } from '@genkit-ai/core';
@@ -0,0 +1,3 @@
1
+ export { BaseDataPointSchema, Document, DocumentData, DocumentDataSchema, DynamicResourceAction, EmbedderAction, EmbedderArgument, EmbedderInfo, EmbedderParams, EmbedderReference, Embedding, EvalResponses, EvaluatorAction, EvaluatorInfo, EvaluatorParams, EvaluatorReference, ExecutablePrompt, GENKIT_UI_METADATA, GENKIT_UI_WIDGETS, GenerateMiddleware, GenerateMiddlewareDef, GenerateOptions, GenerateRequest, GenerateRequestData, GenerateResponse, GenerateResponseChunk, GenerateResponseChunkData, GenerateResponseData, GenerateStreamOptions, GenerateStreamResponse, GenerationBlockedError, GenerationCommonConfigSchema, GenerationResponseError, GenerationUsage, IndexerAction, IndexerArgument, IndexerInfo, IndexerParams, IndexerReference, InterruptConfig, LlmResponse, LlmResponseSchema, LlmStats, LlmStatsSchema, MediaPart, Message, MessageData, MessageSchema, MiddlewareDesc, MiddlewareDescSchema, MiddlewareRef, MiddlewareRefSchema, ModelArgument, ModelReference, ModelReferenceSchema, ModelRequest, ModelRequestSchema, ModelResponseData, ModelResponseSchema, MultipartToolAction, OperationOptions, OutputOptions, Part, PartSchema, PromptAction, PromptConfig, PromptGenerateOptions, RankedDocument, RerankerAction, RerankerArgument, RerankerInfo, RerankerParams, RerankerReference, ResourceAction, ResumeOptions, RetrieverAction, RetrieverArgument, RetrieverInfo, RetrieverParams, RetrieverReference, Role, RoleSchema, Tool, ToolAction, ToolArgument, ToolCall, ToolCallSchema, ToolChoice, ToolConfig, ToolInterruptError, ToolRequest, ToolRequestPart, ToolResponse, ToolResponsePart, ToolSchema, dynamicResource, embedderActionMetadata, embedderRef, evaluatorRef, generateMiddleware, indexerRef, modelActionMetadata, modelRef, rerankerRef, resource, respondTool, restartTool, retrieverRef } from '@genkit-ai/ai';
2
+ export { dynamicTool, tool } from '@genkit-ai/ai/tool';
3
+ export { Action, ActionContext, ActionMetadata, DynamicActionProviderAction, ErrorResponseMetadata, Flow, FlowConfig, FlowFn, FlowSideChannel, GENKIT_CLIENT_HEADER, GENKIT_VERSION, GenkitError, GenkitRuntimeConfig, JSONSchema, JSONSchema7, Middleware, Operation, OperationSchema, ReflectionServer, ReflectionServerOptions, RunActionResponse, Status, StatusCodes, StatusName, StatusNameSchema, StatusSchema, StreamingCallback, StreamingResponse, TelemetryConfig, UserFacingError, annotateSchema, defineJsonSchema, defineSchema, getClientHeader, getCurrentEnv, getGenkitRuntimeConfig, getStreamingCallback, isDevEnv, resetGenkitRuntimeConfig, runWithStreamingCallback, setGenkitRuntimeConfig, z } from '@genkit-ai/core';