Repository navigation
Expand file tree
/
Copy pathturnTypes.ts
More file actions
111 lines (99 loc) · 3.12 KB
/
Copy pathturnTypes.ts
File metadata and controls
111 lines (99 loc) · 3.12 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import type { AdminUser, AudioAdapter } from "adminforth";
import type { DetectedLanguage } from "./languageDetect.js";
import type { CurrentPageContext } from "../tools/getUserLocation.js";
import type { AgentEventEmitter } from "./agentEvents.js";
import type { ApprovalRequest } from "../tools/approvalFormatter.js";
/**
* Minimal sink the application layer uses to persist per-turn debug traces. The
* concrete implementation (the sequence-debug collector) lives in the llm layer;
* the domain/application layers depend only on this narrow interface, so the
* dependency direction stays llm -> application/domain.
*/
export type DebugSink = {
flush(): void;
getHistory(): unknown[];
};
/** A pending human-in-the-loop approval, normalized (provider-agnostic). */
export type PendingInterrupt = {
id: string;
/** Number of decisions the provider expects on resume (one per pending tool call). */
count: number;
/** The pending tool calls, normalized so they can be described to the user. */
requests: ApprovalRequest[];
};
export type BaseAgentTurnInput = {
prompt: string;
sessionId: string;
modeName?: string | null;
userTimeZone?: string;
currentPage?: CurrentPageContext;
chatSurface?: string;
adminPublicOrigin?: string;
abortSignal?: AbortSignal;
adminUser: AdminUser;
};
export type TextAgentTurnInput = BaseAgentTurnInput & {
emit: AgentEventEmitter;
approvalDecision?: "approve" | "reject";
failureLogMessage?: string;
abortLogMessage?: string;
};
export type SpeechAgentTurnInput = Omit<BaseAgentTurnInput, "prompt"> & {
emit: AgentEventEmitter;
audioAdapter: AudioAdapter;
audio: {
buffer: Buffer;
filename: string;
mimeType: string;
};
failureLogMessage?: string;
abortLogMessage?: string;
};
export type AgentTurnContext = {
adminUser: AdminUser;
userTimeZone: string;
sessionId: string;
turnId: string;
abortSignal?: AbortSignal;
currentPage?: CurrentPageContext;
chatSurface?: string;
adminPublicOrigin?: string;
userLanguage?: DetectedLanguage | null;
};
export type AgentTurnObservability = {
emit?: AgentEventEmitter;
sequenceDebugSink: DebugSink;
};
export type RunAndPersistAgentResponseInput = BaseAgentTurnInput & {
emit?: AgentEventEmitter;
approvalDecision?: "approve" | "reject";
failureLogMessage: string;
abortLogMessage: string;
editTurnId?: string;
};
export type RunAndPersistAgentResponseResult = {
text: string;
turnId: string;
aborted: boolean;
failed: boolean;
};
export type HandleTurnInput = TextAgentTurnInput;
export type HandleSpeechTurnInput = SpeechAgentTurnInput;
export type HandleEditTurnInput = TextAgentTurnInput & { turnId: string };
export type AgentMessage = {
role: "user";
content: string;
};
/**
* Normalized unit of a streamed agent turn. The LLM port converts the raw
* LangGraph stream into these typed chunks so the application layer never
* touches LangGraph's tuple/`any` stream shape.
*/
export type AgentStreamChunk =
| { kind: "text"; delta: string }
| { kind: "reasoning"; delta: string }
| {
kind: "interrupt";
interrupt: unknown;
descriptors: PendingInterrupt[];
};