@genkit-ai/ai
Version:
Genkit AI framework generative AI APIs.
226 lines • 8.81 kB
JavaScript
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var agent_types_exports = {};
__export(agent_types_exports, {
AgentAbortRequestSchema: () => AgentAbortRequestSchema,
AgentAbortResponseSchema: () => AgentAbortResponseSchema,
AgentFinishReasonSchema: () => AgentFinishReasonSchema,
AgentInitSchema: () => AgentInitSchema,
AgentInputSchema: () => AgentInputSchema,
AgentMetadataSchema: () => AgentMetadataSchema,
AgentOutputSchema: () => AgentOutputSchema,
AgentResultSchema: () => AgentResultSchema,
AgentStateManagementSchema: () => AgentStateManagementSchema,
AgentStreamChunkSchema: () => AgentStreamChunkSchema,
ArtifactSchema: () => ArtifactSchema,
GetSnapshotRequestSchema: () => GetSnapshotRequestSchema,
JsonPatchOpSchema: () => JsonPatchOpSchema,
JsonPatchOperationSchema: () => JsonPatchOperationSchema,
JsonPatchSchema: () => JsonPatchSchema,
RuntimeErrorSchema: () => RuntimeErrorSchema,
SessionSnapshotSchema: () => SessionSnapshotSchema,
SessionStateSchema: () => SessionStateSchema,
SnapshotStatusSchema: () => SnapshotStatusSchema,
TurnEndSchema: () => TurnEndSchema
});
module.exports = __toCommonJS(agent_types_exports);
var import_core = require("@genkit-ai/core");
var import_model_types = require("./model-types.js");
var import_parts = require("./parts.js");
const RuntimeErrorSchema = import_core.z.object({
/** Canonical status name (e.g. `INTERNAL`, `FAILED_PRECONDITION`). */
status: import_core.z.string().optional(),
/** Human-readable error message. */
message: import_core.z.string(),
/** Optional structured details describing the failure. */
details: import_core.z.any().optional()
});
const ArtifactSchema = import_core.z.object({
/** Name identifies the artifact (e.g., "generated_code.go", "diagram.png"). */
name: import_core.z.string().optional(),
/** Parts contains the artifact content (text, media, etc.). */
parts: import_core.z.array(import_model_types.PartSchema),
/** Metadata contains additional artifact-specific data. */
metadata: import_core.z.record(import_core.z.any()).optional()
});
const SnapshotStatusSchema = import_core.z.enum([
"pending",
"completed",
"aborted",
"failed",
"expired"
]);
const AgentFinishReasonSchema = import_core.z.enum([
// Mirror of generate's FinishReason:
"stop",
"length",
"blocked",
"interrupted",
"other",
"unknown",
// Agent-specific additions:
"aborted",
"detached",
"failed"
]);
const SessionStateSchema = import_core.z.object({
sessionId: import_core.z.string().optional(),
messages: import_core.z.array(import_model_types.MessageSchema).optional(),
custom: import_core.z.any().optional(),
artifacts: import_core.z.array(ArtifactSchema).optional()
});
const AgentInputSchema = import_core.z.object({
/** User's input message for this turn. */
message: import_model_types.MessageSchema.optional(),
/** Options for resuming an interrupted generation. */
resume: import_core.z.object({
respond: import_core.z.array(import_parts.ToolResponsePartSchema).optional(),
restart: import_core.z.array(import_parts.ToolRequestPartSchema).optional()
}).optional(),
detach: import_core.z.boolean().optional()
});
const AgentInitSchema = import_core.z.object({
snapshotId: import_core.z.string().optional(),
sessionId: import_core.z.string().optional(),
state: SessionStateSchema.optional()
});
const AgentResultSchema = import_core.z.object({
message: import_model_types.MessageSchema.optional(),
artifacts: import_core.z.array(ArtifactSchema).optional(),
/** The reason the whole invocation finished (e.g. `stop`, `interrupted`). */
finishReason: AgentFinishReasonSchema.optional()
});
const AgentOutputSchema = import_core.z.object({
/**
* ID of the session this invocation belongs to, assigned by the framework
* when the invocation starts.
*/
sessionId: import_core.z.string().optional(),
snapshotId: import_core.z.string().optional(),
state: SessionStateSchema.optional(),
message: import_model_types.MessageSchema.optional(),
artifacts: import_core.z.array(ArtifactSchema).optional(),
/** The reason the invocation finished (e.g. `stop`, `interrupted`). */
finishReason: AgentFinishReasonSchema.optional(),
/**
* Present when `finishReason` is `failed`. Carries the original error
* details (RuntimeError shape; the runtime resolves gracefully instead of
* throwing). The accompanying `state`/`snapshotId` hold the last-good state -
* the state the failed turn started with.
*/
error: RuntimeErrorSchema.optional()
});
const TurnEndSchema = import_core.z.object({
snapshotId: import_core.z.string().optional(),
/** The reason this turn finished (e.g. `stop`, `interrupted`). */
finishReason: AgentFinishReasonSchema.optional()
});
const JsonPatchOpSchema = import_core.z.enum([
"add",
"remove",
"replace",
"move",
"copy",
"test"
]);
const JsonPatchOperationSchema = import_core.z.object({
op: JsonPatchOpSchema,
/** A JSON Pointer (RFC 6901) to the target location, e.g. `"/agentStatus"`. */
path: import_core.z.string(),
/** Source pointer; required for `move` and `copy`. */
from: import_core.z.string().optional(),
/** New value; required for `add`, `replace`, and `test`. */
value: import_core.z.any().optional()
});
const JsonPatchSchema = import_core.z.array(JsonPatchOperationSchema);
const AgentStreamChunkSchema = import_core.z.object({
modelChunk: import_model_types.ModelResponseChunkSchema.optional(),
/**
* An RFC 6902 JSON Patch describing a delta applied to the session's
* `custom` state. The runtime auto-emits these whenever custom state is
* mutated during a turn; clients apply them to keep their tracked custom
* state live mid-stream.
*/
customPatch: JsonPatchSchema.optional(),
artifact: ArtifactSchema.optional(),
turnEnd: TurnEndSchema.optional()
});
const SessionSnapshotSchema = import_core.z.object({
snapshotId: import_core.z.string(),
sessionId: import_core.z.string().optional(),
parentId: import_core.z.string().optional(),
createdAt: import_core.z.string(),
updatedAt: import_core.z.string().optional(),
heartbeatAt: import_core.z.string().optional(),
status: SnapshotStatusSchema.optional(),
finishReason: AgentFinishReasonSchema.optional(),
error: RuntimeErrorSchema.optional(),
state: SessionStateSchema.optional()
});
const GetSnapshotRequestSchema = import_core.z.object({
snapshotId: import_core.z.string().optional(),
sessionId: import_core.z.string().optional()
});
const AgentAbortRequestSchema = import_core.z.object({
snapshotId: import_core.z.string()
});
const AgentAbortResponseSchema = import_core.z.object({
snapshotId: import_core.z.string(),
status: SnapshotStatusSchema.optional()
});
const AgentStateManagementSchema = import_core.z.enum(["server", "client"]);
const AgentMetadataSchema = import_core.z.object({
/** Who owns session state for this agent. */
stateManagement: AgentStateManagementSchema,
/**
* Whether the agent's invocations can be aborted. True only when the
* configured store implements the abort lifecycle.
*/
abortable: import_core.z.boolean(),
/**
* JSON schema for the agent's custom session state (the `custom` field of
* `SessionState`), inferred from the agent's state type. Omitted when the
* state type carries no schema to infer.
*/
stateSchema: import_core.z.record(import_core.z.any()).optional()
});
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
AgentAbortRequestSchema,
AgentAbortResponseSchema,
AgentFinishReasonSchema,
AgentInitSchema,
AgentInputSchema,
AgentMetadataSchema,
AgentOutputSchema,
AgentResultSchema,
AgentStateManagementSchema,
AgentStreamChunkSchema,
ArtifactSchema,
GetSnapshotRequestSchema,
JsonPatchOpSchema,
JsonPatchOperationSchema,
JsonPatchSchema,
RuntimeErrorSchema,
SessionSnapshotSchema,
SessionStateSchema,
SnapshotStatusSchema,
TurnEndSchema
});
//# sourceMappingURL=agent-types.js.map