import type { ProcessInstance, ProcessSemanticEntryRefKey, ProcessTurnStartSelection, ProcessTurnTerminalLifecycleStatus, TurnId, TurnProgressReport } from "@leitwerk-dev/domain"; import type { ExtensionProcessDefinition, ExternalActionSource, ExternalSourceEffect, ExternalSourceResolveContext, FormDefinition, ProcessTurnOutcomeEvent, ServerProcessContext, WorkerCompleteInput, WorkerProcessContext } from "./extension-api.js"; import { type MappedLlmTurnSpec } from "./mapped-turn.js"; import type { ServerExtensionEventMap } from "./server-events.js"; import type { TurnWaitPredicate } from "./turn-wait.js"; import type { HumanTurnActionView, HumanTurnExternalTrigger, HumanTurnNotesField, OutcomeToolParameterSpec, PiBuiltInToolName, ProcessActionPreviewDefinition, TurnAcceptanceState, TurnBranchType, TurnCompletionMode, TurnContextMode, TurnResultMarkdownBehavior } from "./types.js"; /** @internal */ type ProcessEventName = keyof ServerExtensionEventMap & string; /** @internal */ type ProcessEmittedEvent = { /** @internal */ type: ProcessEventName; /** @internal */ data: unknown; }; /** @public */ type ProcessQueuedInput = Parameters[0]; /** @public */ type MaybePromise = T | Promise; /** @public */ type StaticRouteTarget = { /** @public */ to?: TurnId; /** @internal */ complete?: boolean; /** @public */ lifecycleStatus?: ProcessTurnTerminalLifecycleStatus; }; /** @public */ export interface ProcessRuntimeTurnContext extends WorkerProcessContext { } /** An outcome-tool submission awaiting acceptance. @public */ export interface LlmOutcomeSubmission { /** @public */ outcome: string; /** @public */ params: Record; } /** @internal */ export interface LlmTurnPreparationContext extends ProcessRuntimeTurnContext { /** @internal */ callIntegrationTool(name: string, args: Record): Promise; /** @internal */ reportProgress(report: TurnProgressReport): void; } /** @public */ export interface ProcessServerRuntimeContext { /** @internal */ readonly process: ServerProcessContext["process"]; /** @internal */ readonly projects: ServerProcessContext["projects"]; /** @internal */ readonly params: TParams; /** @public */ readonly state: TState; /** @internal */ readSemanticTurnResultMarkdown(ref: ProcessSemanticEntryRefKey): string | null; /** @internal */ readProductTurnResultMarkdown(productName: string): string | null; /** @internal */ reportProgress?(report: TurnProgressReport): void; } /** @internal */ export interface ProcessBroadcastEffect { /** @internal */ type: string; /** @internal */ payload: Record; } /** @public */ export type ProcessPatchEffect = Partial>; /** @public */ export interface ProcessLifecycleEffects { /** @public */ processPatch?: ProcessPatchEffect; /** @internal */ broadcasts?: readonly ProcessBroadcastEffect[]; } /** @public */ export interface ProcessEffectPlan extends ProcessLifecycleEffects { /** @public */ state?: TState; /** @internal */ emit?: readonly ProcessEmittedEvent[]; /** @public */ queueInput?: readonly ProcessQueuedInput[]; } /** @public */ export interface ProcessActionExecution { /** @public */ readonly ctx: ProcessServerRuntimeContext; /** @public */ readonly input: Record; /** @internal */ readonly turnId: TurnId; /** @internal */ readonly actionId: string; /** @internal */ readonly selectedBranchId?: string; } /** @public */ export interface ProcessOutcomeExecution { /** @internal */ readonly ctx: ProcessServerRuntimeContext; /** @internal */ readonly event: ProcessTurnOutcomeEvent; /** @internal */ readonly turnId: TurnId; /** @internal */ readonly outcome: string; } /** @public */ export type ProcessActionEffect = (input: ProcessActionExecution) => MaybePromise | undefined>; /** @public */ export type ProcessActionBranchSelector = (input: Omit, "selectedBranchId">) => MaybePromise; /** @public */ export type ProcessOutcomeEffect = (input: ProcessOutcomeExecution) => MaybePromise | undefined>; /** @internal */ export type ProcessOutcomeBranchSelector = (input: ProcessOutcomeExecution) => MaybePromise; /** Branch route and display metadata for state-routed outcomes. @public */ export interface ProcessOutcomeBranchSpec extends StaticRouteTarget { /** @internal */ trigger?: string; /** Display name for the branch condition in the workflow graph. @public */ label?: string; /** Explains the condition without evaluating runtime state. @public */ description?: string; } /** @internal */ export interface ProcessActionExternalTrigger { /** @internal */ id: string; /** @internal */ label: string; /** @internal */ description: string; } /** @internal */ export interface ExternalActionInputPublication { /** @internal */ productName: string; /** @internal */ inputField: string; } /** @public */ export interface ProcessHumanTurnExternalActionSpec = Record> extends StaticRouteTarget { /** @internal */ id: string; /** @internal */ source: ExternalActionSource; /** Arms and exposes this action only when the current process snapshot matches. @public */ when?: (ctx: ExternalSourceResolveContext) => boolean; /** @internal */ label?: string; /** @internal */ description?: string; /** @internal */ publishInput?: ExternalActionInputPublication; /** @public */ effect?: ExternalSourceEffect; } /** @public */ export interface ProcessActionBranchSpec extends StaticRouteTarget { /** @internal */ trigger?: string; } /** @public */ type StaticActionRouting = StaticRouteTarget & { /** @internal */ trigger?: string; }; /** @public */ type BranchingActionRouting = { /** @public */ branches: Record; /** @public */ choose: ProcessActionBranchSelector; }; /** @public */ interface BaseActionSpec { /** @public */ label: string; /** @public */ description?: string; /** @internal */ form?: FormDefinition; /** @public */ preview?: ProcessActionPreviewDefinition; /** @public */ schedulable?: boolean; /** @public */ effect?: ProcessActionEffect; } /** @public */ export type ProcessHumanTurnActionSpec = BaseActionSpec & { /** @public */ acceptanceState: TurnAcceptanceState; /** @internal */ externalTriggers?: readonly ProcessActionExternalTrigger[]; } & (StaticActionRouting | BranchingActionRouting); /** Pure inputs for resolving a tool contract before worker preparation. @public */ export interface OutcomeParameterContext { /** @public */ readonly params: TParams; /** @public */ readonly state: TState; } /** @public */ interface ProcessToolOutcomeBaseSpec { /** Resolve parameters synchronously from captured process data. @public */ resolveParameters?: (ctx: OutcomeParameterContext) => Record; /** Opt in to provider schema enforcement. @public */ strictSchema?: boolean; /** @internal */ description: string; /** @internal */ parameters: Record; /** Product published from this outcome's turn-result markdown, when this outcome is selected. @internal */ publishedProduct?: string; /** Outcome parameter whose markdown value is captured as the turn result. @internal */ turnResultMarkdownParameter?: string; /** Outcome parameter containing a concise operator-facing summary. @internal */ resultSummaryParameter?: string; /** @internal */ effect?: ProcessOutcomeEffect; } /** @public */ export type ProcessToolOutcomeSpec = ProcessToolOutcomeBaseSpec & (StaticRouteTarget | { /** @internal */ branches: Record; /** @internal */ choose: ProcessOutcomeBranchSelector; }); /** @public */ export type HumanTurnOperatorAttention = "required" | "passive"; /** @public */ export interface HumanTurnDefinition { /** @public */ kind: "human"; /** @public */ description: string; /** Named product rendered as the subject of this human review turn. @internal */ reviewProduct?: string; /** @internal */ reviewSemanticRef?: ProcessSemanticEntryRefKey; /** Controls whether entering this turn should raise an action-required toast. @public */ operatorAttention?: HumanTurnOperatorAttention; /** @internal */ notesFields?: readonly HumanTurnNotesField[]; /** @internal */ commentary?: string; /** @public */ actions: Record>; /** @internal */ externalActions?: Record>; } /** @public */ export interface ProcessTurnEndSpec extends StaticRouteTarget { /** @public */ outcome: TOutcome; /** @public */ params?: Record; /** @public */ effect?: ProcessOutcomeEffect; } /** @internal */ export type OutcomeRouteSpec = StaticRouteTarget & Partial, "description" | "parameters" | "effect">>; /** @internal */ export interface OutcomeRouteOptions { /** @internal */ strict?: boolean; } /** @internal */ export type LlmModelPurpose = "process_title_generation"; /** @public */ export interface LlmTurnDefinition { /** @public */ kind: "llm"; /** @public */ description: string; /** Server-side entry condition, evaluated before worker allocation. @public */ waitFor?: TurnWaitPredicate; /** External events armed while this LLM turn is selected and waiting. @public */ externalActions?: Record>; /** Code-defined model policy purpose. Purpose selections cannot be overridden per launch/action. @internal */ modelPurpose?: LlmModelPurpose; /** Extension-defined scoped settings consumed by this turn. @public */ executionPurpose?: string; /** Built-in Pi tools active while this turn runs. @public */ availableTools: readonly PiBuiltInToolName[]; /** Server-owned integration tools proxied over authenticated worker IPC. @internal */ integrationTools?: readonly string[]; /** Resolve a constrained tool set from validated durable process data at turn start. @public */ resolveIntegrationTools?: (params: TParams, state: TState) => readonly string[]; /** Opt in to the durable, operator-facing ask_questions custom tool. @internal */ askQuestions?: boolean; /** Constrain questions using captured process data and completed preparation before prompting. @public */ resolveAskQuestions?: (ctx: ProcessRuntimeTurnContext) => boolean; /** Deterministic worker preparation that must complete before Pi is prompted. @internal */ prepare?(ctx: LlmTurnPreparationContext): MaybePromise; /** Return actionable errors before an outcome is accepted; no durable effects. @internal */ validateOutcome?(ctx: LlmTurnPreparationContext, outcome: LlmOutcomeSubmission): MaybePromise; /** @public */ completionMode?: TurnCompletionMode; /** @public */ branchType: TurnBranchType; /** @public */ context: TurnContextMode; /** @internal */ startFrom?: ProcessTurnStartSelection; /** @internal */ restorePrimaryLeafAfterTurn?: boolean; /** @public */ prompt(ctx: ProcessRuntimeTurnContext): string | Promise; /** @public */ outcomes?: Partial>>; /** @public */ turnEnd?: ProcessTurnEndSpec; /** @public */ turnResultMarkdown?: TurnResultMarkdownBehavior; /** @internal */ reviewSemanticRef?: ProcessSemanticEntryRefKey; /** @internal */ resultSemanticRef?: ProcessSemanticEntryRefKey; /** @internal */ publishedProduct?: string; /** @internal */ consumedProducts?: readonly string[]; /** @internal */ optionalConsumedProducts?: readonly string[]; /** @internal */ requiredSemanticMarkdownRefs?: readonly ProcessSemanticEntryRefKey[]; /** @internal */ optionalSemanticMarkdownRefs?: readonly ProcessSemanticEntryRefKey[]; /** Runs this turn once per frozen item, then collects and routes once. @public */ forEach?: MappedLlmTurnSpec; } /** @public */ export interface AutomaticTurnDefinition { /** @public */ kind: "automatic"; /** @public */ description: string; /** Server-side entry condition, evaluated before worker allocation. @public */ waitFor?: TurnWaitPredicate; /** Server-owned integration tools callable by this deterministic worker turn. @internal */ integrationTools?: readonly string[]; /** External events armed while this automatic turn is selected and waiting. @public */ externalActions?: Record>; /** @internal */ outcomes?: Partial>>; /** @internal */ turnEnd?: ProcessTurnEndSpec; /** @internal */ reviewSemanticRef?: ProcessSemanticEntryRefKey; /** @public */ run(ctx: ProcessRuntimeTurnContext): Promise> | WorkerCompleteInput; } /** @internal */ export interface ExternalSourceTransition = Record> extends StaticRouteTarget { /** @internal */ source: ExternalActionSource; /** @internal */ effect?: ExternalSourceEffect; } /** @public */ export interface ExternalTurnDefinition { /** @public */ kind: "external"; /** @public */ description: string; /** @internal */ transitions: readonly ExternalSourceTransition[]; /** @internal */ reviewSemanticRef?: ProcessSemanticEntryRefKey; } /** @public */ export type TurnDefinition = LlmTurnDefinition | AutomaticTurnDefinition | HumanTurnDefinition | ExternalTurnDefinition; /** @public */ export type TurnDefinitionRecord = Record>; /** @public */ export interface DefinedProcessInput extends Omit, "entryTurnId" | "alternateEntryTurnIds" | "turns"> { /** Primary entry used when a launch does not select a start turn explicitly. @public */ entry: TurnId; /** Additional entry turns that launchers may select explicitly. @public */ alternateEntries?: readonly TurnId[]; /** @public */ turns: TurnDefinitionRecord; } /** @internal */ export declare function getExternalSourceTransitionId(input: { /** @internal */ turnId: TurnId; /** @internal */ source: ExternalActionSource; /** @internal */ index: number; }): string; /** @internal */ export declare function getExternalActionArmingId(input: { /** @internal */ turnId: TurnId; /** @internal */ externalActionId: string; }): string; /** @internal */ export declare function getExternalActionTransitionTrigger(input: { /** @internal */ externalActionId: string; }): string; /** @internal */ export declare function resolveHumanTurnView(input: { /** @internal */ turnId: TurnId; /** @internal */ turn: HumanTurnDefinition; }): { /** @internal */ actions: readonly HumanTurnActionView[]; /** @internal */ externalTriggers: readonly HumanTurnExternalTrigger[]; }; /** Recheck declaration metadata and retained graph facts without executing author callbacks. @internal */ export declare function validateProcessDefinition(process: ExtensionProcessDefinition): readonly string[]; /** @public */ export declare function defineProcess(input: DefinedProcessInput): ExtensionProcessDefinition; /** @internal */ type RoutableTurnDefinition = LlmTurnDefinition | AutomaticTurnDefinition; /** @internal */ type RoutableOutcome = TTurn extends RoutableTurnDefinition ? TOutcome : never; /** @internal */ type RoutableParams = TTurn extends RoutableTurnDefinition ? TParams : never; /** @internal */ type RoutableState = TTurn extends RoutableTurnDefinition ? TState : never; /** @internal */ export declare function routeTurnOutcomes>(baseTurn: TTurn, routes: Partial, OutcomeRouteSpec, RoutableState>>>, options?: OutcomeRouteOptions): TTurn; /** @public */ export declare function llmTurn(input: Omit, "kind">): LlmTurnDefinition; /** @internal */ export declare function automaticTurn(input: Omit, "kind">): AutomaticTurnDefinition; /** @public */ export declare function humanTurn(input: Omit, "kind">): HumanTurnDefinition; /** @internal */ export declare function externalTurn(input: Omit, "kind">): ExternalTurnDefinition; export {}; //# sourceMappingURL=define-process.d.ts.map