@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.
- package/LICENSE +203 -0
- package/README.md +434 -0
- package/lib/beta.d.mts +18 -0
- package/lib/beta.d.ts +18 -0
- package/lib/beta.js +88 -0
- package/lib/beta.js.map +1 -0
- package/lib/beta.mjs +64 -0
- package/lib/beta.mjs.map +1 -0
- package/lib/client/agent.d.mts +52 -0
- package/lib/client/agent.d.ts +52 -0
- package/lib/client/agent.js +90 -0
- package/lib/client/agent.js.map +1 -0
- package/lib/client/agent.mjs +68 -0
- package/lib/client/agent.mjs.map +1 -0
- package/lib/client/client.d.mts +80 -0
- package/lib/client/client.d.ts +80 -0
- package/lib/client/client.js +164 -0
- package/lib/client/client.js.map +1 -0
- package/lib/client/client.mjs +139 -0
- package/lib/client/client.mjs.map +1 -0
- package/lib/client/index.d.mts +6 -0
- package/lib/client/index.d.ts +6 -0
- package/lib/client/index.js +55 -0
- package/lib/client/index.js.map +1 -0
- package/lib/client/index.mjs +31 -0
- package/lib/client/index.mjs.map +1 -0
- package/lib/client/types.d.mts +17 -0
- package/lib/client/types.d.ts +17 -0
- package/lib/client/types.js +17 -0
- package/lib/client/types.js.map +1 -0
- package/lib/client/types.mjs +1 -0
- package/lib/client/types.mjs.map +1 -0
- package/lib/common.d.mts +3 -0
- package/lib/common.d.ts +3 -0
- package/lib/common.js +151 -0
- package/lib/common.js.map +1 -0
- package/lib/common.mjs +128 -0
- package/lib/common.mjs.map +1 -0
- package/lib/context.d.mts +1 -0
- package/lib/context.d.ts +1 -0
- package/lib/context.js +50 -0
- package/lib/context.js.map +1 -0
- package/lib/context.mjs +28 -0
- package/lib/context.mjs.map +1 -0
- package/lib/embedder.d.mts +1 -0
- package/lib/embedder.d.ts +1 -0
- package/lib/embedder.js +48 -0
- package/lib/embedder.js.map +1 -0
- package/lib/embedder.mjs +26 -0
- package/lib/embedder.mjs.map +1 -0
- package/lib/evaluator.d.mts +1 -0
- package/lib/evaluator.d.ts +1 -0
- package/lib/evaluator.js +60 -0
- package/lib/evaluator.js.map +1 -0
- package/lib/evaluator.mjs +38 -0
- package/lib/evaluator.mjs.map +1 -0
- package/lib/extract.d.mts +1 -0
- package/lib/extract.d.ts +1 -0
- package/lib/extract.js +48 -0
- package/lib/extract.js.map +1 -0
- package/lib/extract.mjs +23 -0
- package/lib/extract.mjs.map +1 -0
- package/lib/formats.d.mts +1 -0
- package/lib/formats.d.ts +1 -0
- package/lib/formats.js +34 -0
- package/lib/formats.js.map +1 -0
- package/lib/formats.mjs +18 -0
- package/lib/formats.mjs.map +1 -0
- package/lib/genkit-beta.d.mts +183 -0
- package/lib/genkit-beta.d.ts +183 -0
- package/lib/genkit-beta.js +178 -0
- package/lib/genkit-beta.js.map +1 -0
- package/lib/genkit-beta.mjs +159 -0
- package/lib/genkit-beta.mjs.map +1 -0
- package/lib/genkit.d.mts +10 -0
- package/lib/genkit.d.ts +10 -0
- package/lib/genkit.js +471 -0
- package/lib/genkit.js.map +1 -0
- package/lib/genkit.mjs +489 -0
- package/lib/genkit.mjs.map +1 -0
- package/lib/index-BSkuxdwl.d.mts +311 -0
- package/lib/index-BSkuxdwl.d.ts +311 -0
- package/lib/index.d.mts +10 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +51 -0
- package/lib/index.js.map +1 -0
- package/lib/index.mjs +24 -0
- package/lib/index.mjs.map +1 -0
- package/lib/logging.d.mts +1 -0
- package/lib/logging.d.ts +1 -0
- package/lib/logging.js +46 -0
- package/lib/logging.js.map +1 -0
- package/lib/logging.mjs +22 -0
- package/lib/logging.mjs.map +1 -0
- package/lib/middleware.d.mts +1 -0
- package/lib/middleware.d.ts +1 -0
- package/lib/middleware.js +56 -0
- package/lib/middleware.js.map +1 -0
- package/lib/middleware.mjs +34 -0
- package/lib/middleware.mjs.map +1 -0
- package/lib/model.d.mts +1 -0
- package/lib/model.d.ts +1 -0
- package/lib/model.js +92 -0
- package/lib/model.js.map +1 -0
- package/lib/model.mjs +70 -0
- package/lib/model.mjs.map +1 -0
- package/lib/plugin.d.mts +10 -0
- package/lib/plugin.d.ts +10 -0
- package/lib/plugin.js +143 -0
- package/lib/plugin.js.map +1 -0
- package/lib/plugin.mjs +113 -0
- package/lib/plugin.mjs.map +1 -0
- package/lib/registry.d.mts +1 -0
- package/lib/registry.d.ts +1 -0
- package/lib/registry.js +46 -0
- package/lib/registry.js.map +1 -0
- package/lib/registry.mjs +24 -0
- package/lib/registry.mjs.map +1 -0
- package/lib/reranker.d.mts +1 -0
- package/lib/reranker.d.ts +1 -0
- package/lib/reranker.js +54 -0
- package/lib/reranker.js.map +1 -0
- package/lib/reranker.mjs +32 -0
- package/lib/reranker.mjs.map +1 -0
- package/lib/retriever.d.mts +1 -0
- package/lib/retriever.d.ts +1 -0
- package/lib/retriever.js +58 -0
- package/lib/retriever.js.map +1 -0
- package/lib/retriever.mjs +36 -0
- package/lib/retriever.mjs.map +1 -0
- package/lib/schema.d.mts +1 -0
- package/lib/schema.d.ts +1 -0
- package/lib/schema.js +54 -0
- package/lib/schema.js.map +1 -0
- package/lib/schema.mjs +32 -0
- package/lib/schema.mjs.map +1 -0
- package/lib/testing.d.mts +1 -0
- package/lib/testing.d.ts +1 -0
- package/lib/testing.js +50 -0
- package/lib/testing.js.map +1 -0
- package/lib/testing.mjs +28 -0
- package/lib/testing.mjs.map +1 -0
- package/lib/tool.d.mts +1 -0
- package/lib/tool.d.ts +1 -0
- package/lib/tool.js +54 -0
- package/lib/tool.js.map +1 -0
- package/lib/tool.mjs +32 -0
- package/lib/tool.mjs.map +1 -0
- package/lib/tracing.d.mts +1 -0
- package/lib/tracing.d.ts +1 -0
- package/lib/tracing.js +82 -0
- package/lib/tracing.js.map +1 -0
- package/lib/tracing.mjs +60 -0
- package/lib/tracing.mjs.map +1 -0
- package/package.json +233 -0
- package/src/beta.ts +85 -0
- package/src/client/agent.ts +160 -0
- package/src/client/client.ts +237 -0
- package/src/client/index.ts +72 -0
- package/src/client/types.ts +41 -0
- package/src/common.ts +175 -0
- package/src/context.ts +37 -0
- package/src/embedder.ts +41 -0
- package/src/evaluator.ts +50 -0
- package/src/extract.ts +30 -0
- package/src/formats.ts +30 -0
- package/src/genkit-beta.ts +275 -0
- package/src/genkit.ts +818 -0
- package/src/index.ts +29 -0
- package/src/logging.ts +30 -0
- package/src/middleware.ts +38 -0
- package/src/model.ts +87 -0
- package/src/plugin.ts +172 -0
- package/src/registry.ts +36 -0
- package/src/reranker.ts +42 -0
- package/src/retriever.ts +55 -0
- package/src/schema.ts +40 -0
- package/src/testing.ts +47 -0
- package/src/tool.ts +40 -0
- package/src/tracing.ts +55 -0
- package/tests/agent_client_test.ts +497 -0
- package/tests/embed_test.ts +142 -0
- package/tests/evaluate_test.ts +52 -0
- package/tests/flow_test.ts +94 -0
- package/tests/formats_test.ts +168 -0
- package/tests/generate_test.ts +1631 -0
- package/tests/genkit_test.ts +33 -0
- package/tests/helpers.ts +176 -0
- package/tests/mock-model_test.ts +490 -0
- package/tests/plugins_test.ts +259 -0
- package/tests/prompts/badSchemaRef.prompt +9 -0
- package/tests/prompts/chat_preamble.prompt +5 -0
- package/tests/prompts/kitchensink.prompt +25 -0
- package/tests/prompts/output.prompt +11 -0
- package/tests/prompts/schemaRef.prompt +9 -0
- package/tests/prompts/sub/test.prompt +5 -0
- package/tests/prompts/test.prompt +5 -0
- package/tests/prompts/test.variant.prompt +8 -0
- package/tests/prompts/toolPrompt.prompt +6 -0
- package/tests/prompts_test.ts +1442 -0
- package/tests/session_test.ts +17 -0
- package/typedoc.json +22 -0
package/src/context.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Request context utilities — API key helpers, context providers, and
|
|
21
|
+
* request data types for authenticated and context-aware flows.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { apiKey, type ContextProvider } from 'genkit/context';
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @module context
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
apiKey,
|
|
32
|
+
getCallableJSON,
|
|
33
|
+
getHttpStatus,
|
|
34
|
+
type ApiKeyContext,
|
|
35
|
+
type ContextProvider,
|
|
36
|
+
type RequestData,
|
|
37
|
+
} from '@genkit-ai/core';
|
package/src/embedder.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Embedder types — reference helpers, schemas, and action types for building
|
|
21
|
+
* embedding model plugins.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { embedderRef, type EmbedderAction } from 'genkit/embedder';
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @module embedder
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
EmbedderInfoSchema,
|
|
32
|
+
embedderRef,
|
|
33
|
+
type EmbedRequest,
|
|
34
|
+
type EmbedderAction,
|
|
35
|
+
type EmbedderArgument,
|
|
36
|
+
type EmbedderInfo,
|
|
37
|
+
type EmbedderParams,
|
|
38
|
+
type EmbedderReference,
|
|
39
|
+
type Embedding,
|
|
40
|
+
type EmbeddingBatch,
|
|
41
|
+
} from '@genkit-ai/ai/embedder';
|
package/src/evaluator.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Evaluator types — schemas, reference helpers, and action types for building
|
|
21
|
+
* AI output quality evaluators.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { evaluatorRef, type EvalResponse } from 'genkit/evaluator';
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @module evaluator
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
BaseDataPointSchema,
|
|
32
|
+
BaseEvalDataPointSchema,
|
|
33
|
+
EvalResponseSchema,
|
|
34
|
+
EvalResponsesSchema,
|
|
35
|
+
EvalStatusEnum,
|
|
36
|
+
EvaluatorInfoSchema,
|
|
37
|
+
ScoreSchema,
|
|
38
|
+
evaluatorRef,
|
|
39
|
+
type BaseDataPoint,
|
|
40
|
+
type BaseEvalDataPoint,
|
|
41
|
+
type Dataset,
|
|
42
|
+
type EvalResponse,
|
|
43
|
+
type EvalResponses,
|
|
44
|
+
type EvaluatorAction,
|
|
45
|
+
type EvaluatorArgument,
|
|
46
|
+
type EvaluatorInfo,
|
|
47
|
+
type EvaluatorParams,
|
|
48
|
+
type EvaluatorReference,
|
|
49
|
+
type Score,
|
|
50
|
+
} from '@genkit-ai/ai/evaluator';
|
package/src/extract.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Extraction utilities — helpers for extracting structured JSON from model
|
|
21
|
+
* output, including partial JSON parsing for streaming.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { extractJson, parsePartialJson } from 'genkit/extract';
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @module extract
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export { extractJson, parsePartialJson } from '@genkit-ai/ai/extract';
|
package/src/formats.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Output format types — `Formatter` and `FormatArgument` interfaces used when
|
|
21
|
+
* defining custom output formats for model generation.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* import type { Formatter, FormatArgument } from 'genkit/formats';
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @module formats
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export type { FormatArgument, Formatter } from '@genkit-ai/ai/formats';
|
|
@@ -0,0 +1,275 @@
|
|
|
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 {
|
|
18
|
+
GenerateOptions,
|
|
19
|
+
GenerateResponseData,
|
|
20
|
+
GenerationCommonConfigSchema,
|
|
21
|
+
SessionRunner,
|
|
22
|
+
defineAgent,
|
|
23
|
+
defineCustomAgent,
|
|
24
|
+
defineInterrupt,
|
|
25
|
+
definePromptAgent,
|
|
26
|
+
defineResource,
|
|
27
|
+
generateOperation,
|
|
28
|
+
type Agent,
|
|
29
|
+
type AgentConfig,
|
|
30
|
+
type AgentFn,
|
|
31
|
+
type AgentStreamChunk,
|
|
32
|
+
type ClientTransform,
|
|
33
|
+
type InterruptConfig,
|
|
34
|
+
type PromptConfig,
|
|
35
|
+
type ResourceAction,
|
|
36
|
+
type ResourceFn,
|
|
37
|
+
type ResourceOptions,
|
|
38
|
+
type ToolAction,
|
|
39
|
+
} from '@genkit-ai/ai';
|
|
40
|
+
|
|
41
|
+
import { defineFormat } from '@genkit-ai/ai/formats';
|
|
42
|
+
|
|
43
|
+
import {
|
|
44
|
+
type SessionSnapshot,
|
|
45
|
+
type SessionSnapshotInput,
|
|
46
|
+
type SessionState,
|
|
47
|
+
type SessionStore,
|
|
48
|
+
type SessionStoreOptions,
|
|
49
|
+
type SnapshotMutator,
|
|
50
|
+
} from '@genkit-ai/ai/session';
|
|
51
|
+
import {
|
|
52
|
+
FileSessionStore,
|
|
53
|
+
InMemorySessionStore,
|
|
54
|
+
} from '@genkit-ai/ai/session-stores';
|
|
55
|
+
|
|
56
|
+
import { applyPatch, diff } from '@genkit-ai/ai/json-patch';
|
|
57
|
+
import { type Operation, type z } from '@genkit-ai/core';
|
|
58
|
+
import type { Formatter } from './formats.js';
|
|
59
|
+
import { Genkit, type GenkitOptions } from './genkit.js';
|
|
60
|
+
|
|
61
|
+
export type { JsonPatch, JsonPatchOperation } from '@genkit-ai/ai/json-patch';
|
|
62
|
+
export {
|
|
63
|
+
FileSessionStore,
|
|
64
|
+
InMemorySessionStore,
|
|
65
|
+
SessionRunner,
|
|
66
|
+
applyPatch,
|
|
67
|
+
diff,
|
|
68
|
+
};
|
|
69
|
+
export type {
|
|
70
|
+
Agent,
|
|
71
|
+
AgentFn,
|
|
72
|
+
AgentStreamChunk,
|
|
73
|
+
ClientTransform,
|
|
74
|
+
GenkitOptions as GenkitBetaOptions,
|
|
75
|
+
PromptConfig,
|
|
76
|
+
SessionSnapshot,
|
|
77
|
+
SessionSnapshotInput,
|
|
78
|
+
SessionState,
|
|
79
|
+
SessionStore,
|
|
80
|
+
SessionStoreOptions,
|
|
81
|
+
SnapshotMutator,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* WARNING: these APIs are considered unstable and subject to frequent breaking changes that may not honor semver.
|
|
86
|
+
*
|
|
87
|
+
* Initializes Genkit BETA APIs with a set of options.
|
|
88
|
+
*
|
|
89
|
+
* This will create a new Genkit registry, register the provided plugins, stores, and other configuration. This
|
|
90
|
+
* should be called before any flows are registered.
|
|
91
|
+
*
|
|
92
|
+
* @beta
|
|
93
|
+
*/
|
|
94
|
+
export function genkit(options: GenkitOptions): GenkitBeta {
|
|
95
|
+
return new GenkitBeta(options);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Genkit BETA APIs.
|
|
100
|
+
*
|
|
101
|
+
* @beta
|
|
102
|
+
*/
|
|
103
|
+
export class GenkitBeta extends Genkit {
|
|
104
|
+
constructor(options?: GenkitOptions) {
|
|
105
|
+
super(options);
|
|
106
|
+
this.registry.apiStability = 'beta';
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Defines and registers a custom agent with a custom handler function.
|
|
111
|
+
*
|
|
112
|
+
* @beta
|
|
113
|
+
*/
|
|
114
|
+
defineCustomAgent<State = unknown>(
|
|
115
|
+
config: {
|
|
116
|
+
name: string;
|
|
117
|
+
description?: string;
|
|
118
|
+
stateSchema?: z.ZodType<State>;
|
|
119
|
+
store?: SessionStore<State>;
|
|
120
|
+
},
|
|
121
|
+
fn: AgentFn<State>
|
|
122
|
+
) {
|
|
123
|
+
return defineCustomAgent<State>(this.registry, config, fn);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Defines and registers an agent from an existing Prompt template.
|
|
128
|
+
*
|
|
129
|
+
* @beta
|
|
130
|
+
*/
|
|
131
|
+
definePromptAgent<
|
|
132
|
+
State = unknown,
|
|
133
|
+
I extends z.ZodTypeAny = z.ZodTypeAny,
|
|
134
|
+
>(config: {
|
|
135
|
+
promptName: string;
|
|
136
|
+
/**
|
|
137
|
+
* Input values for the referenced prompt's input variables. Lets a single
|
|
138
|
+
* prompt be reused/customized across multiple agents.
|
|
139
|
+
*/
|
|
140
|
+
promptInput?: z.infer<I>;
|
|
141
|
+
stateSchema?: z.ZodType<State>;
|
|
142
|
+
store?: SessionStore<State>;
|
|
143
|
+
}) {
|
|
144
|
+
return definePromptAgent<State, I>(this.registry, config);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Defines and registers an agent by creating a prompt and wiring it into a
|
|
149
|
+
* multi-turn agent in one step.
|
|
150
|
+
*
|
|
151
|
+
* This is a convenience shortcut that combines `definePrompt` and
|
|
152
|
+
* `definePromptAgent` into a single call.
|
|
153
|
+
*
|
|
154
|
+
* ```ts
|
|
155
|
+
* const myAgent = ai.defineAgent({
|
|
156
|
+
* name: 'myAgent',
|
|
157
|
+
* model: 'googleai/gemini-2.5-flash',
|
|
158
|
+
* system: 'Talk like a pirate.',
|
|
159
|
+
* tools: [weatherTool],
|
|
160
|
+
* store: new FileSessionStore('./.snapshots'),
|
|
161
|
+
* });
|
|
162
|
+
* ```
|
|
163
|
+
*
|
|
164
|
+
* @beta
|
|
165
|
+
*/
|
|
166
|
+
defineAgent<State = unknown, I extends z.ZodTypeAny = z.ZodTypeAny>(
|
|
167
|
+
config: AgentConfig<State, I>
|
|
168
|
+
) {
|
|
169
|
+
return defineAgent<State, I>(this.registry, config);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Defines and registers a custom model output formatter.
|
|
174
|
+
*
|
|
175
|
+
* Here's an example of a custom JSON output formatter:
|
|
176
|
+
*
|
|
177
|
+
* ```ts
|
|
178
|
+
* import { extractJson } from 'genkit/extract';
|
|
179
|
+
*
|
|
180
|
+
* ai.defineFormat(
|
|
181
|
+
* { name: 'customJson' },
|
|
182
|
+
* (schema) => {
|
|
183
|
+
* let instructions: string | undefined;
|
|
184
|
+
* if (schema) {
|
|
185
|
+
* instructions = `Output should be in JSON format and conform to the following schema:
|
|
186
|
+
* \`\`\`
|
|
187
|
+
* ${JSON.stringify(schema)}
|
|
188
|
+
* \`\`\`
|
|
189
|
+
* `;
|
|
190
|
+
* }
|
|
191
|
+
* return {
|
|
192
|
+
* parseChunk: (chunk) => extractJson(chunk.accumulatedText),
|
|
193
|
+
* parseMessage: (message) => extractJson(message.text),
|
|
194
|
+
* instructions,
|
|
195
|
+
* };
|
|
196
|
+
* }
|
|
197
|
+
* );
|
|
198
|
+
*
|
|
199
|
+
* const { output } = await ai.generate({
|
|
200
|
+
* prompt: 'Invent a menu item for a pirate themed restaurant.',
|
|
201
|
+
* output: { format: 'customJson', schema: MenuItemSchema },
|
|
202
|
+
* });
|
|
203
|
+
* ```
|
|
204
|
+
*
|
|
205
|
+
* @beta
|
|
206
|
+
*/
|
|
207
|
+
defineFormat(
|
|
208
|
+
options: {
|
|
209
|
+
name: string;
|
|
210
|
+
} & Formatter['config'],
|
|
211
|
+
handler: Formatter['handler']
|
|
212
|
+
): { config: Formatter['config']; handler: Formatter['handler'] } {
|
|
213
|
+
return defineFormat(this.registry, options, handler);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Defines and registers an interrupt.
|
|
218
|
+
*
|
|
219
|
+
* Interrupts are special tools that halt model processing and return control back to the caller. Interrupts make it simpler to implement
|
|
220
|
+
* "human-in-the-loop" and out-of-band processing patterns that require waiting on external actions to complete.
|
|
221
|
+
*
|
|
222
|
+
* @beta
|
|
223
|
+
*/
|
|
224
|
+
defineInterrupt<I extends z.ZodTypeAny, O extends z.ZodTypeAny>(
|
|
225
|
+
config: InterruptConfig<I, O>
|
|
226
|
+
): ToolAction<I, O> {
|
|
227
|
+
return defineInterrupt(this.registry, config);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Starts a generate operation for long running generation models, typically for
|
|
232
|
+
* video and complex audio generation.
|
|
233
|
+
*
|
|
234
|
+
* See {@link GenerateOptions} for detailed information about available options.
|
|
235
|
+
*
|
|
236
|
+
* ```ts
|
|
237
|
+
* const operation = await ai.generateOperation({
|
|
238
|
+
* model: googleAI.model('veo-3.1-generate-preview'),
|
|
239
|
+
* prompt: 'A banana riding a bicycle.',
|
|
240
|
+
* });
|
|
241
|
+
* ```
|
|
242
|
+
*
|
|
243
|
+
* The status of the operation and final result can be obtained using {@link Genkit.checkOperation}.
|
|
244
|
+
*/
|
|
245
|
+
generateOperation<
|
|
246
|
+
O extends z.ZodTypeAny = z.ZodTypeAny,
|
|
247
|
+
CustomOptions extends z.ZodTypeAny = typeof GenerationCommonConfigSchema,
|
|
248
|
+
>(
|
|
249
|
+
opts:
|
|
250
|
+
| GenerateOptions<O, CustomOptions>
|
|
251
|
+
| PromiseLike<GenerateOptions<O, CustomOptions>>
|
|
252
|
+
): Promise<Operation<GenerateResponseData>> {
|
|
253
|
+
return generateOperation(this.registry, opts);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Defines a resource. Resources can then be accessed from a generate call.
|
|
258
|
+
*
|
|
259
|
+
* ```ts
|
|
260
|
+
* ai.defineResource({
|
|
261
|
+
* uri: 'my://resource/{param}',
|
|
262
|
+
* description: 'provides my resource',
|
|
263
|
+
* }, async ({param}) => {
|
|
264
|
+
* return [{ text: `resource ${param}` }]
|
|
265
|
+
* });
|
|
266
|
+
*
|
|
267
|
+
* await ai.generate({
|
|
268
|
+
* prompt: [{ resource: 'my://resource/value' }]
|
|
269
|
+
* })
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
defineResource(opts: ResourceOptions, fn: ResourceFn): ResourceAction {
|
|
273
|
+
return defineResource(this.registry, opts, fn);
|
|
274
|
+
}
|
|
275
|
+
}
|