File size: 1,686 Bytes
cc11e77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
 * actionPlannerTypes.ts — S553: tipi puri estratti da actionPlanner.ts
 *
 * Contiene solo TypeScript types/interfaces senza dipendenze runtime.
 * Permette import type-only senza pull-in di actionPlanner.ts
 * (eventRuntime, checkPolicy, Dexie taskStore, ecc.).
 *
 * Consumato da actionPlanner.ts (re-esporta per backward compat) e
 * da agentLoop.ts / agentSSE.ts che tipano ActionStep / ActionPlan.
 */

import type { RiskLevel } from "@/lib/capabilityPolicy";

export type StepStatus = "pending" | "running" | "done" | "error" | "skipped" | "waiting_confirm";

export interface ActionStep {
  id:        string;
  tool:      string;
  args:      Record<string, unknown>;
  label:     string;
  risk:      RiskLevel;
  preview:   string;
  status:    StepStatus;
  result?:   unknown;
  error?:    string;
  startedAt?: number;
  doneAt?:   number;
}

export interface ActionPlan {
  id:     string;
  goal:   string;
  steps:  ActionStep[];
  taskId: string;
}

export interface PlannerCallbacks {
  /** Chiamato prima di ogni step — permette di aggiornare UI */
  onStepStart?:   (step: ActionStep) => void;
  /** Chiamato al completamento di uno step */
  onStepDone?:    (step: ActionStep, result: unknown) => void;
  /** Chiamato su errore step non-fatal */
  onStepError?:   (step: ActionStep, error: string) => void;
  /** Richiesta conferma per step risky/dangerous — ritorna true=procedi, false=salta */
  onNeedConfirm?: (step: ActionStep) => Promise<boolean>;
  /** Chiamato al termine del piano */
  onPlanDone?:    (plan: ActionPlan, success: boolean) => void;
}

export type ToolExecutor = (tool: string, args: Record<string, unknown>) => Promise<unknown>;