@oai404iao/pi-subagent 0.2.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/src/types.ts ADDED
@@ -0,0 +1,154 @@
1
+ import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
2
+ import type { Usage } from "@earendil-works/pi-ai";
3
+
4
+ export type AgentScope = "user" | "project" | "both";
5
+ export type AgentSource = "bundled" | "user" | "project";
6
+ export type ReportDelivery = "wakeup" | "quiet";
7
+ export type SubagentMode = "one-shot" | "continuable";
8
+ export type SubagentProviderName = "spawn" | "fork";
9
+ export type SubagentStopReason = "completed" | "aborted" | "error" | "max-tokens";
10
+
11
+ export interface SubagentSettings {
12
+ agentScope: AgentScope;
13
+ syncBundledAgents: boolean;
14
+ maxDepth: number;
15
+ enableRunInBackground: boolean;
16
+ defaultBackground: boolean;
17
+ reportDelivery: ReportDelivery;
18
+ inheritExtensions: boolean;
19
+ maxOutputBytes: number;
20
+ }
21
+
22
+ export interface AgentDefinition {
23
+ name: string;
24
+ description: string;
25
+ tools?: string[];
26
+ model?: string;
27
+ thinking?: ThinkingLevel;
28
+ systemPrompt: string;
29
+ source: AgentSource;
30
+ filePath: string;
31
+ }
32
+
33
+ export interface AgentSnapshot {
34
+ name: string;
35
+ description: string;
36
+ tools?: string[];
37
+ model?: string;
38
+ thinking?: ThinkingLevel;
39
+ systemPrompt: string;
40
+ source: AgentSource;
41
+ }
42
+
43
+ export interface ResolvedModel {
44
+ provider: string;
45
+ id: string;
46
+ }
47
+
48
+ export interface SubagentRuntimeSnapshot {
49
+ agentScope: AgentScope;
50
+ syncBundledAgents: boolean;
51
+ maxDepth: number;
52
+ enableRunInBackground: boolean;
53
+ defaultBackground: boolean;
54
+ reportDelivery: ReportDelivery;
55
+ inheritExtensions: boolean;
56
+ maxOutputBytes: number;
57
+ }
58
+
59
+ export interface SubagentDescriptor {
60
+ version: 1;
61
+ mode: SubagentMode;
62
+ provider: SubagentProviderName;
63
+ label: string;
64
+ parentSessionId: string;
65
+ parentSessionFile?: string;
66
+ depth: number;
67
+ cwd: string;
68
+ createdAt: string;
69
+ agent: AgentSnapshot;
70
+ model: ResolvedModel;
71
+ thinkingLevel: ThinkingLevel;
72
+ runtime: SubagentRuntimeSnapshot;
73
+ }
74
+
75
+ export interface SubagentUsage extends Usage {
76
+ turns: number;
77
+ }
78
+
79
+ export interface SubagentRunResult {
80
+ id: string;
81
+ sessionFile?: string;
82
+ output: string;
83
+ stopReason: SubagentStopReason;
84
+ usage: SubagentUsage;
85
+ }
86
+
87
+ export interface TraceItem {
88
+ type: "tool" | "text";
89
+ name?: string;
90
+ text: string;
91
+ }
92
+
93
+ export interface DelegationDetails {
94
+ kind: "delegation";
95
+ id: string;
96
+ provider: SubagentProviderName;
97
+ mode: SubagentMode;
98
+ agent: string;
99
+ label: string;
100
+ depth: number;
101
+ status: "starting" | "running" | "waiting" | "completed" | "failed" | "ready";
102
+ sessionFile?: string;
103
+ stopReason?: SubagentStopReason;
104
+ output?: string;
105
+ trace: TraceItem[];
106
+ usage?: SubagentUsage;
107
+ }
108
+
109
+ export interface ControlDetails {
110
+ kind: "control";
111
+ action: "send" | "interrupt" | "list" | "report";
112
+ id?: string;
113
+ }
114
+
115
+ export interface CatalogChild {
116
+ kind: "child";
117
+ id: string;
118
+ parentId: string;
119
+ depth: number;
120
+ descriptor: SubagentDescriptor;
121
+ sessionFile?: string;
122
+ status: "running" | "idle" | "ready";
123
+ }
124
+
125
+ export interface CatalogDiagnostic {
126
+ kind: "diagnostic";
127
+ id: string;
128
+ reason: "corrupt" | "unavailable";
129
+ sessionFile?: string;
130
+ parentSessionFile?: string;
131
+ message: string;
132
+ }
133
+
134
+ export type CatalogEntry = CatalogChild | CatalogDiagnostic;
135
+
136
+ export interface ParentMessageDetails {
137
+ kind: "report" | "settled";
138
+ childId: string;
139
+ label: string;
140
+ stopReason?: SubagentStopReason;
141
+ truncated?: boolean;
142
+ }
143
+
144
+ export function snapshotAgent(agent: AgentDefinition): AgentSnapshot {
145
+ return {
146
+ name: agent.name,
147
+ description: agent.description,
148
+ ...(agent.tools ? { tools: [...agent.tools] } : {}),
149
+ ...(agent.model ? { model: agent.model } : {}),
150
+ ...(agent.thinking ? { thinking: agent.thinking } : {}),
151
+ systemPrompt: agent.systemPrompt,
152
+ source: agent.source,
153
+ };
154
+ }