donobu
Version:
Create browser automations with an LLM agent and replay them as Playwright scripts.
190 lines • 7.62 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isComplete = exports.FlowsQuerySchema = exports.FlowMetadataSchema = exports.StateSchema = void 0;
const v4_1 = require("zod/v4");
const Provenance_1 = require("./Provenance");
const RunConfig_1 = require("./RunConfig");
const RunMode_1 = require("./RunMode");
const SortOrder_1 = require("./SortOrder");
exports.StateSchema = v4_1.z
.enum([
'UNSTARTED',
'INITIALIZING',
'QUERYING_LLM_FOR_NEXT_ACTION',
'WAITING_ON_USER_FOR_NEXT_ACTION',
'PAUSED',
'RESUMING',
'RUNNING_ACTION',
'FAILED',
'SUCCESS',
])
.describe(`Represents the possible states of a flow:
- UNSTARTED: Flow created but not yet initialized.
- INITIALIZING: Setting up browser context and initial state.
- RUNNING_ACTION: Executing a tool call.
- QUERYING_LLM_FOR_NEXT_ACTION: AI determining next action (AUTONOMOUS mode).
- WAITING_ON_USER_FOR_NEXT_ACTION: Waiting for user input (INSTRUCT mode).
- PAUSED: Flow execution temporarily suspended.
- RESUMING: Transitioning from paused to active state.
- FAILED: Flow terminated unsuccessfully.
- SUCCESS: Flow completed successfully.`);
exports.FlowMetadataSchema = RunConfig_1.RunConfigSchema.extend({
id: v4_1.z.string().describe('The unique ID of this flow.'),
metadataVersion: v4_1.z
.number()
.optional()
.describe('Schema version of this metadata object. Absent in rows written by SDKs older than v5. ' +
'Used by read-time normalization to detect which format a row is in.'),
name: v4_1.z.string().nullable().describe('The name of this flow.'),
createdWithDonobuVersion: v4_1.z
.string()
.describe('The version of Donobu that created the flow.'),
testId: v4_1.z
.string()
.optional()
.nullable()
.describe('The ID of the test this flow was created from.'),
// Flow-runner-specific fields (not part of RunConfig).
gptConfigName: v4_1.z
.string()
.nullable()
.describe('The name of the specific GPT configuration used for the flow.'),
hasGptConfigNameOverride: v4_1.z
.boolean()
.describe('If true, means that the `gptConfigName` was explicitly overwritten when the flow was created.'),
defaultMessageDuration: v4_1.z
.number()
.nullable()
.describe("The default amount of time the Donobu flow agent's messaging for the user should show (in milliseconds)."),
runMode: RunMode_1.RunModeSchema,
isControlPanelEnabled: v4_1.z
.boolean()
.describe('Set to true if the control panel should be enabled.'),
result: v4_1.z
.union([
v4_1.z.record(v4_1.z.string(), v4_1.z.unknown()),
v4_1.z.array(v4_1.z.record(v4_1.z.string(), v4_1.z.unknown())),
])
.nullable()
.describe(`The final output of the flow, populated when the flow reaches a terminal state. The content
depends on how the flow completes:
(1) If the flow succeeds and resultJsonSchema is specified, contains an object conforming to that
schema extracted from the flow context;
(2) If resultJsonSchema extraction fails, contains error details about the extraction failure;
(3) Otherwise, contains the metadata from the final tool call, or null if no tools were executed.`),
inputTokensUsed: v4_1.z
.number()
.describe('The number of LLM input tokens used during this flow.'),
completionTokensUsed: v4_1.z
.number()
.describe('The number of LLM completion tokens used during this flow.'),
startedAt: v4_1.z
.number()
.nullable()
.describe('The Unix epoch millisecond timestamp of when the flow started.'),
completedAt: v4_1.z
.number()
.nullable()
.describe('The Unix epoch millisecond timestamp of when the flow completed.'),
state: exports.StateSchema.describe('The current state of the flow.'),
nextState: exports.StateSchema.nullable().describe('The planned next state of the flow.'),
provenance: Provenance_1.ProvenanceSchema.optional().describe('Records how this flow came into existence (Studio vs. code-first). ' +
'Absent on rows written before provenance tracking was introduced.'),
});
const FlowSortBySchema = v4_1.z.enum(['created_at', 'name', 'run_mode', 'state']);
/**
* Query parameters for filtering and paginating flow metadata results.
*/
exports.FlowsQuerySchema = v4_1.z.object({
/**
* Filter flows by exact name match.
*
* When specified, only flows with this exact name will be returned.
* This uses indexed lookups in most persistence implementations for efficient querying.
*
* @example "user-onboarding-flow"
*/
name: v4_1.z.string().optional(),
/**
* Filter flows by partial name (case-insensitive substring match).
* Mutually exclusive with `name`.
*/
partialName: v4_1.z.string().optional(),
/**
* Filter flows that started after this timestamp (inclusive).
*
* Unix epoch timestamp in milliseconds. Flows with `startedAt` greater than
* or equal to this value will be included in results.
*
* @example Date.now() - (24 * 60 * 60 * 1000) // Flows from last 24 hours
*/
startedAfter: v4_1.z.coerce.number().optional(),
/**
* Filter flows that started before this timestamp (inclusive).
*
* Unix epoch timestamp in milliseconds. Flows with `startedAt` less than
* or equal to this value will be included in results.
*
* @example new Date('2024-01-01').getTime() // Flows before 2024
*/
startedBefore: v4_1.z.coerce.number().optional(),
/**
* Filter flows by run mode.
*/
runMode: RunMode_1.RunModeSchema.optional(),
/**
* Filter flows by current state.
*/
state: exports.StateSchema.optional(),
/**
* Filter flows by the test they belong to.
*/
testId: v4_1.z.string().optional(),
/**
* Filter by whether the flow has an associated test.
*
* - `true` → only return flows with no test (orphaned flows)
* - `false` → only return flows that do belong to a test
* - omitted → no filter applied
*/
orphaned: v4_1.z.preprocess((v) => (v === 'true' ? true : v === 'false' ? false : v), v4_1.z.boolean().optional()),
/**
* Column to sort results by. Defaults to `created_at`.
*/
sortBy: FlowSortBySchema.optional(),
/**
* Sort direction. Defaults to `desc`.
*/
sortOrder: SortOrder_1.SortOrderSchema.optional(),
/**
* Maximum number of flows to return per page.
*
* Valid range is 1-100. Defaults to 100.
*
* @minimum 1
* @maximum 100
*/
limit: v4_1.z.coerce.number().min(1).max(100).optional(),
/**
* Pagination token for retrieving subsequent pages of results.
*
* This token is returned in the `nextPageToken` field of `PaginatedResult`
* and should be passed as-is to retrieve the next page. The format and
* content of this token is implementation-specific and should not be parsed
* or modified by client code.
*
* @example "eyJvZmZzZXQiOjIwfQ=="
*/
pageToken: v4_1.z.string().optional(),
});
/**
* Checks if a flow state represents completion (either success or failure).
*
* @param state - The state to check
* @returns True if the state represents completion
*/
const isComplete = (state) => {
return state === 'FAILED' || state === 'SUCCESS';
};
exports.isComplete = isComplete;
//# sourceMappingURL=FlowMetadata.js.map