@letta-ai/letta-agent-sdk 0.3.2 → 0.3.3
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/AGENTS.md +47 -0
- package/README.md +17 -0
- package/dist/client-entry.js +800 -732
- package/dist/client-entry.js.map +8 -5
- package/dist/cloud-sandbox.d.ts +33 -0
- package/dist/cloud-sandbox.d.ts.map +1 -0
- package/dist/cloud-session.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +799 -732
- package/dist/index.js.map +9 -6
- package/dist/remote-client-session-core.d.ts +6 -93
- package/dist/remote-client-session-core.d.ts.map +1 -1
- package/dist/remote-session-protocol.d.ts +130 -0
- package/dist/remote-session-protocol.d.ts.map +1 -0
- package/dist/remote-turn-coordinator.d.ts +49 -0
- package/dist/remote-turn-coordinator.d.ts.map +1 -0
- package/dist/types.d.ts +2 -20
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -2
- package/src/app-server-management.ts +641 -0
- package/src/app-server-session.ts +948 -0
- package/src/cli-resolver.ts +46 -0
- package/src/client-base.ts +482 -0
- package/src/client-entry.ts +31 -0
- package/src/client.ts +138 -0
- package/src/cloud-management.ts +360 -0
- package/src/cloud-sandbox.ts +117 -0
- package/src/cloud-session.ts +1313 -0
- package/src/index.ts +440 -0
- package/src/interactiveToolPolicy.ts +62 -0
- package/src/local-app-server-session.ts +39 -0
- package/src/local-app-server.ts +137 -0
- package/src/management-types.ts +133 -0
- package/src/management.ts +206 -0
- package/src/protocol.ts +249 -0
- package/src/remote-client-session-core.ts +786 -0
- package/src/remote-session-protocol.ts +660 -0
- package/src/remote-turn-coordinator.ts +505 -0
- package/src/remote.ts +177 -0
- package/src/repositories.ts +340 -0
- package/src/request-ids.ts +33 -0
- package/src/session.ts +1638 -0
- package/src/stream-events.ts +88 -0
- package/src/tool-helpers.ts +147 -0
- package/src/transport.ts +484 -0
- package/src/types.ts +1328 -0
- package/src/validation.ts +223 -0
- package/src/websocket.ts +22 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { ListMessagesResult, ListModelsResult } from "./types.js";
|
|
2
|
+
|
|
3
|
+
/** Agent state returned by either the Cloud API or Letta Code app-server. */
|
|
4
|
+
export type LettaAgent = Record<string, unknown> & {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
description?: string | null;
|
|
8
|
+
model?: string | null;
|
|
9
|
+
model_settings?: Record<string, unknown> | null;
|
|
10
|
+
tags?: string[];
|
|
11
|
+
created_at?: string | null;
|
|
12
|
+
updated_at?: string | null;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/** Conversation state returned by either the Cloud API or Letta Code app-server. */
|
|
16
|
+
export type LettaConversation = Record<string, unknown> & {
|
|
17
|
+
id: string;
|
|
18
|
+
agent_id: string;
|
|
19
|
+
summary?: string | null;
|
|
20
|
+
description?: string | null;
|
|
21
|
+
model?: string | null;
|
|
22
|
+
model_settings?: Record<string, unknown> | null;
|
|
23
|
+
archived?: boolean;
|
|
24
|
+
created_at?: string | null;
|
|
25
|
+
updated_at?: string | null;
|
|
26
|
+
last_message_at?: string | null;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** Raw Letta API message returned from conversation history. */
|
|
30
|
+
export type LettaConversationMessage = Record<string, unknown>;
|
|
31
|
+
|
|
32
|
+
export interface ListAgentsOptions {
|
|
33
|
+
before?: string;
|
|
34
|
+
after?: string;
|
|
35
|
+
limit?: number;
|
|
36
|
+
order?: "asc" | "desc";
|
|
37
|
+
orderBy?: "createdAt" | "lastRunCompletion";
|
|
38
|
+
/** Search agent names. */
|
|
39
|
+
query?: string;
|
|
40
|
+
/** Match one exact agent name. */
|
|
41
|
+
name?: string;
|
|
42
|
+
tags?: string[];
|
|
43
|
+
matchAllTags?: boolean;
|
|
44
|
+
/** Relationships to hydrate in each returned agent. */
|
|
45
|
+
include?: string[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface UpdateAgentOptions {
|
|
49
|
+
name?: string | null;
|
|
50
|
+
description?: string | null;
|
|
51
|
+
model?: string | null;
|
|
52
|
+
modelSettings?: Record<string, unknown> | null;
|
|
53
|
+
system?: string | null;
|
|
54
|
+
tags?: string[] | null;
|
|
55
|
+
hidden?: boolean | null;
|
|
56
|
+
contextWindowLimit?: number | null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface ListConversationsOptions {
|
|
60
|
+
agentId?: string;
|
|
61
|
+
after?: string;
|
|
62
|
+
limit?: number;
|
|
63
|
+
order?: "asc" | "desc";
|
|
64
|
+
orderBy?: "createdAt" | "lastRunCompletion" | "lastMessageAt";
|
|
65
|
+
archiveStatus?: "unarchived" | "archived" | "all";
|
|
66
|
+
summarySearch?: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface CreateConversationOptions {
|
|
70
|
+
agentId: string;
|
|
71
|
+
summary?: string | null;
|
|
72
|
+
description?: string | null;
|
|
73
|
+
model?: string | null;
|
|
74
|
+
modelSettings?: Record<string, unknown> | null;
|
|
75
|
+
contextWindowLimit?: number | null;
|
|
76
|
+
hidden?: boolean;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface UpdateConversationOptions {
|
|
80
|
+
summary?: string | null;
|
|
81
|
+
description?: string | null;
|
|
82
|
+
model?: string | null;
|
|
83
|
+
modelSettings?: Record<string, unknown> | null;
|
|
84
|
+
contextWindowLimit?: number | null;
|
|
85
|
+
archived?: boolean | null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface ConversationMessagesOptions {
|
|
89
|
+
before?: string;
|
|
90
|
+
after?: string;
|
|
91
|
+
order?: "asc" | "desc";
|
|
92
|
+
limit?: number;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type ConversationMessagesResult = ListMessagesResult & {
|
|
96
|
+
messages: LettaConversationMessage[];
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export interface AgentsClient {
|
|
100
|
+
list(options?: ListAgentsOptions): Promise<LettaAgent[]>;
|
|
101
|
+
retrieve(agentId: string): Promise<LettaAgent>;
|
|
102
|
+
update(
|
|
103
|
+
agentId: string,
|
|
104
|
+
options: UpdateAgentOptions,
|
|
105
|
+
): Promise<LettaAgent>;
|
|
106
|
+
delete(agentId: string): Promise<void>;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface ModelsClient {
|
|
110
|
+
/**
|
|
111
|
+
* List the model catalog without opening a session.
|
|
112
|
+
*
|
|
113
|
+
* Uses the same normalized result shape as `session.listModels()`, including
|
|
114
|
+
* availability and BYOK-alias metadata when the backend provides it.
|
|
115
|
+
*/
|
|
116
|
+
list(): Promise<ListModelsResult>;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface ConversationsClient {
|
|
120
|
+
list(
|
|
121
|
+
options?: ListConversationsOptions,
|
|
122
|
+
): Promise<LettaConversation[]>;
|
|
123
|
+
retrieve(conversationId: string): Promise<LettaConversation>;
|
|
124
|
+
create(options: CreateConversationOptions): Promise<LettaConversation>;
|
|
125
|
+
update(
|
|
126
|
+
conversationId: string,
|
|
127
|
+
options: UpdateConversationOptions,
|
|
128
|
+
): Promise<LettaConversation>;
|
|
129
|
+
listMessages(
|
|
130
|
+
conversationId: string,
|
|
131
|
+
options?: ConversationMessagesOptions,
|
|
132
|
+
): Promise<ConversationMessagesResult>;
|
|
133
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AgentsClient,
|
|
3
|
+
ConversationsClient,
|
|
4
|
+
ConversationMessagesResult,
|
|
5
|
+
CreateConversationOptions,
|
|
6
|
+
LettaAgent,
|
|
7
|
+
LettaConversation,
|
|
8
|
+
ListAgentsOptions,
|
|
9
|
+
ListConversationsOptions,
|
|
10
|
+
ModelsClient,
|
|
11
|
+
UpdateAgentOptions,
|
|
12
|
+
UpdateConversationOptions,
|
|
13
|
+
ConversationMessagesOptions,
|
|
14
|
+
} from "./management-types.js";
|
|
15
|
+
import type { ListModelsResult } from "./types.js";
|
|
16
|
+
|
|
17
|
+
export type ManagementQuery = Record<
|
|
18
|
+
string,
|
|
19
|
+
string | number | boolean | string[] | null | undefined
|
|
20
|
+
>;
|
|
21
|
+
|
|
22
|
+
export interface ManagementTransport {
|
|
23
|
+
listAgents(query: ManagementQuery): Promise<LettaAgent[]>;
|
|
24
|
+
retrieveAgent(agentId: string): Promise<LettaAgent>;
|
|
25
|
+
updateAgent(
|
|
26
|
+
agentId: string,
|
|
27
|
+
body: Record<string, unknown>,
|
|
28
|
+
): Promise<LettaAgent>;
|
|
29
|
+
deleteAgent(agentId: string): Promise<void>;
|
|
30
|
+
listModels(): Promise<ListModelsResult>;
|
|
31
|
+
listConversations(
|
|
32
|
+
query: ManagementQuery,
|
|
33
|
+
): Promise<LettaConversation[]>;
|
|
34
|
+
retrieveConversation(
|
|
35
|
+
conversationId: string,
|
|
36
|
+
): Promise<LettaConversation>;
|
|
37
|
+
createConversation(
|
|
38
|
+
body: Record<string, unknown>,
|
|
39
|
+
): Promise<LettaConversation>;
|
|
40
|
+
updateConversation(
|
|
41
|
+
conversationId: string,
|
|
42
|
+
body: Record<string, unknown>,
|
|
43
|
+
): Promise<LettaConversation>;
|
|
44
|
+
listConversationMessages(
|
|
45
|
+
conversationId: string,
|
|
46
|
+
query: ManagementQuery,
|
|
47
|
+
): Promise<ConversationMessagesResult>;
|
|
48
|
+
/**
|
|
49
|
+
* Release the pooled connection, waiting for in-flight work when necessary,
|
|
50
|
+
* so other clients of the same backend (for example sessions, which compete
|
|
51
|
+
* for the app-server's single control-client slot) can connect. Optional;
|
|
52
|
+
* transports whose backend has no such contention (Cloud REST) omit it.
|
|
53
|
+
*/
|
|
54
|
+
releaseIdleConnection?(): Promise<void> | void;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
type TransportProvider = () => ManagementTransport;
|
|
58
|
+
|
|
59
|
+
function definedEntries(
|
|
60
|
+
values: Record<string, unknown>,
|
|
61
|
+
): Record<string, unknown> {
|
|
62
|
+
return Object.fromEntries(
|
|
63
|
+
Object.entries(values).filter(([, value]) => value !== undefined),
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function assertNonEmptyId(value: string, name: string): void {
|
|
68
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
69
|
+
throw new Error(`Invalid ${name}. Expected a non-empty string.`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function agentListQuery(options: ListAgentsOptions): ManagementQuery {
|
|
74
|
+
const orderBy = options.orderBy?.replace(
|
|
75
|
+
/[A-Z]/g,
|
|
76
|
+
(character) => `_${character.toLowerCase()}`,
|
|
77
|
+
);
|
|
78
|
+
return {
|
|
79
|
+
before: options.before,
|
|
80
|
+
after: options.after,
|
|
81
|
+
limit: options.limit,
|
|
82
|
+
order: options.order,
|
|
83
|
+
order_by: orderBy,
|
|
84
|
+
query_text: options.query,
|
|
85
|
+
name: options.name,
|
|
86
|
+
tags: options.tags,
|
|
87
|
+
match_all_tags: options.matchAllTags,
|
|
88
|
+
include: options.include,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function agentUpdateBody(options: UpdateAgentOptions): Record<string, unknown> {
|
|
93
|
+
return definedEntries({
|
|
94
|
+
name: options.name,
|
|
95
|
+
description: options.description,
|
|
96
|
+
model: options.model,
|
|
97
|
+
model_settings: options.modelSettings,
|
|
98
|
+
system: options.system,
|
|
99
|
+
tags: options.tags,
|
|
100
|
+
hidden: options.hidden,
|
|
101
|
+
context_window_limit: options.contextWindowLimit,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function conversationListQuery(
|
|
106
|
+
options: ListConversationsOptions,
|
|
107
|
+
): ManagementQuery {
|
|
108
|
+
const orderBy = options.orderBy?.replace(
|
|
109
|
+
/[A-Z]/g,
|
|
110
|
+
(character) => `_${character.toLowerCase()}`,
|
|
111
|
+
);
|
|
112
|
+
return {
|
|
113
|
+
agent_id: options.agentId,
|
|
114
|
+
after: options.after,
|
|
115
|
+
limit: options.limit,
|
|
116
|
+
order: options.order,
|
|
117
|
+
order_by: orderBy,
|
|
118
|
+
archive_status: options.archiveStatus,
|
|
119
|
+
summary_search: options.summarySearch,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function conversationCreateBody(
|
|
124
|
+
options: CreateConversationOptions,
|
|
125
|
+
): Record<string, unknown> {
|
|
126
|
+
return definedEntries({
|
|
127
|
+
agent_id: options.agentId,
|
|
128
|
+
summary: options.summary,
|
|
129
|
+
description: options.description,
|
|
130
|
+
model: options.model,
|
|
131
|
+
model_settings: options.modelSettings,
|
|
132
|
+
context_window_limit: options.contextWindowLimit,
|
|
133
|
+
hidden: options.hidden,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function conversationUpdateBody(
|
|
138
|
+
options: UpdateConversationOptions,
|
|
139
|
+
): Record<string, unknown> {
|
|
140
|
+
return definedEntries({
|
|
141
|
+
summary: options.summary,
|
|
142
|
+
description: options.description,
|
|
143
|
+
model: options.model,
|
|
144
|
+
model_settings: options.modelSettings,
|
|
145
|
+
context_window_limit: options.contextWindowLimit,
|
|
146
|
+
archived: options.archived,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function conversationMessagesQuery(
|
|
151
|
+
options: ConversationMessagesOptions,
|
|
152
|
+
): ManagementQuery {
|
|
153
|
+
return {
|
|
154
|
+
before: options.before,
|
|
155
|
+
after: options.after,
|
|
156
|
+
order: options.order,
|
|
157
|
+
limit: options.limit,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function createAgentsClient(
|
|
162
|
+
transport: TransportProvider,
|
|
163
|
+
): AgentsClient {
|
|
164
|
+
return {
|
|
165
|
+
list: (options = {}) =>
|
|
166
|
+
transport().listAgents(agentListQuery(options)),
|
|
167
|
+
retrieve: (agentId) => transport().retrieveAgent(agentId),
|
|
168
|
+
update: (agentId, options) =>
|
|
169
|
+
transport().updateAgent(agentId, agentUpdateBody(options)),
|
|
170
|
+
delete: async (agentId) => {
|
|
171
|
+
assertNonEmptyId(agentId, "agent id");
|
|
172
|
+
await transport().deleteAgent(agentId);
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export function createModelsClient(
|
|
178
|
+
transport: TransportProvider,
|
|
179
|
+
): ModelsClient {
|
|
180
|
+
return {
|
|
181
|
+
list: () => transport().listModels(),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function createConversationsClient(
|
|
186
|
+
transport: TransportProvider,
|
|
187
|
+
): ConversationsClient {
|
|
188
|
+
return {
|
|
189
|
+
list: (options = {}) =>
|
|
190
|
+
transport().listConversations(conversationListQuery(options)),
|
|
191
|
+
retrieve: (conversationId) =>
|
|
192
|
+
transport().retrieveConversation(conversationId),
|
|
193
|
+
create: (options) =>
|
|
194
|
+
transport().createConversation(conversationCreateBody(options)),
|
|
195
|
+
update: (conversationId, options) =>
|
|
196
|
+
transport().updateConversation(
|
|
197
|
+
conversationId,
|
|
198
|
+
conversationUpdateBody(options),
|
|
199
|
+
),
|
|
200
|
+
listMessages: (conversationId, options = {}) =>
|
|
201
|
+
transport().listConversationMessages(
|
|
202
|
+
conversationId,
|
|
203
|
+
conversationMessagesQuery(options),
|
|
204
|
+
),
|
|
205
|
+
};
|
|
206
|
+
}
|
package/src/protocol.ts
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local protocol type surface consumed by the SDK.
|
|
3
|
+
*
|
|
4
|
+
* @letta-ai/letta-code@0.27.11 publishes these declarations under an internal
|
|
5
|
+
* dist path while its package.json points the public `./protocol` export at a
|
|
6
|
+
* missing file. Keep the SDK's public types self-contained so CI and consumers
|
|
7
|
+
* do not depend on that broken subpath export.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export interface MessageEnvelope {
|
|
11
|
+
type: string;
|
|
12
|
+
session_id?: string;
|
|
13
|
+
uuid?: string;
|
|
14
|
+
timestamp?: string;
|
|
15
|
+
event_seq?: number;
|
|
16
|
+
agent_id?: string;
|
|
17
|
+
conversation_id?: string;
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* System prompt preset configuration used by the CLI protocol.
|
|
23
|
+
*/
|
|
24
|
+
export interface SystemPromptPresetConfig {
|
|
25
|
+
type: "preset";
|
|
26
|
+
preset: string;
|
|
27
|
+
append?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Custom memory block definition accepted when creating agents.
|
|
32
|
+
*/
|
|
33
|
+
export interface CreateBlock {
|
|
34
|
+
label: string;
|
|
35
|
+
value: string;
|
|
36
|
+
base_template_id?: string | null;
|
|
37
|
+
deployment_id?: string | null;
|
|
38
|
+
description?: string | null;
|
|
39
|
+
entity_id?: string | null;
|
|
40
|
+
hidden?: boolean | null;
|
|
41
|
+
is_template?: boolean;
|
|
42
|
+
limit?: number;
|
|
43
|
+
metadata?: Record<string, unknown> | null;
|
|
44
|
+
preserve_on_migration?: boolean | null;
|
|
45
|
+
project_id?: string | null;
|
|
46
|
+
read_only?: boolean;
|
|
47
|
+
tags?: string[] | null;
|
|
48
|
+
template_id?: string | null;
|
|
49
|
+
template_name?: string | null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface SystemInitMessage extends MessageEnvelope {
|
|
53
|
+
type: "system";
|
|
54
|
+
subtype: "init";
|
|
55
|
+
agent_id: string;
|
|
56
|
+
conversation_id: string;
|
|
57
|
+
model: string;
|
|
58
|
+
tools: string[];
|
|
59
|
+
cwd: string;
|
|
60
|
+
mcp_servers: Array<{
|
|
61
|
+
name: string;
|
|
62
|
+
status: string;
|
|
63
|
+
}>;
|
|
64
|
+
permission_mode: string;
|
|
65
|
+
slash_commands: string[];
|
|
66
|
+
memfs_enabled?: boolean;
|
|
67
|
+
skill_sources?: Array<"bundled" | "global" | "agent" | "project">;
|
|
68
|
+
system_info_reminder_enabled?: boolean;
|
|
69
|
+
reflection_trigger?: "off" | "step-count" | "compaction-event";
|
|
70
|
+
reflection_behavior?: "reminder" | "auto-launch";
|
|
71
|
+
reflection_step_count?: number;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface MessageWire extends MessageEnvelope {
|
|
75
|
+
type: "message";
|
|
76
|
+
message_type?: string;
|
|
77
|
+
run_id?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface StreamEvent extends MessageEnvelope {
|
|
81
|
+
type: "stream_event";
|
|
82
|
+
event: unknown;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type ResultSubtype = "success" | "interrupted" | "error" | string;
|
|
86
|
+
|
|
87
|
+
export interface ResultMessage extends MessageEnvelope {
|
|
88
|
+
type: "result";
|
|
89
|
+
subtype: ResultSubtype;
|
|
90
|
+
agent_id?: string;
|
|
91
|
+
conversation_id: string;
|
|
92
|
+
duration_ms: number;
|
|
93
|
+
duration_api_ms?: number;
|
|
94
|
+
num_turns?: number;
|
|
95
|
+
result?: string | null;
|
|
96
|
+
run_ids?: string[];
|
|
97
|
+
usage?: unknown;
|
|
98
|
+
stop_reason?: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface ErrorMessage extends MessageEnvelope {
|
|
102
|
+
type: "error";
|
|
103
|
+
message: string;
|
|
104
|
+
stop_reason: string;
|
|
105
|
+
run_id?: string;
|
|
106
|
+
api_error?: Record<string, unknown>;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface CanUseToolControlRequest {
|
|
110
|
+
subtype: "can_use_tool";
|
|
111
|
+
tool_name: string;
|
|
112
|
+
input: Record<string, unknown>;
|
|
113
|
+
tool_call_id: string;
|
|
114
|
+
permission_suggestions?: unknown[];
|
|
115
|
+
blocked_path?: string | null;
|
|
116
|
+
diffs?: unknown[];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface RegisterExternalToolsRequest {
|
|
120
|
+
subtype: "register_external_tools";
|
|
121
|
+
tools: Array<{
|
|
122
|
+
name: string;
|
|
123
|
+
label?: string;
|
|
124
|
+
description: string;
|
|
125
|
+
parameters: Record<string, unknown>;
|
|
126
|
+
}>;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface BootstrapSessionStateRequest {
|
|
130
|
+
subtype: "bootstrap_session_state";
|
|
131
|
+
limit?: number;
|
|
132
|
+
order?: "asc" | "desc";
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface RecoverPendingApprovalsControlRequest {
|
|
136
|
+
subtype: "recover_pending_approvals";
|
|
137
|
+
agent_id?: string;
|
|
138
|
+
conversation_id?: string;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface ListMessagesControlRequest {
|
|
142
|
+
subtype: "list_messages";
|
|
143
|
+
conversation_id?: string;
|
|
144
|
+
agent_id?: string;
|
|
145
|
+
before?: string;
|
|
146
|
+
after?: string;
|
|
147
|
+
order?: "asc" | "desc";
|
|
148
|
+
limit?: number;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface InterruptControlRequest {
|
|
152
|
+
subtype: "interrupt";
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export interface InitializeControlRequest {
|
|
156
|
+
subtype: "initialize";
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface ExecuteExternalToolControlRequest {
|
|
160
|
+
subtype: "execute_external_tool";
|
|
161
|
+
tool_call_id: string;
|
|
162
|
+
tool_name: string;
|
|
163
|
+
input: Record<string, unknown>;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export type ControlRequestBody =
|
|
167
|
+
| InitializeControlRequest
|
|
168
|
+
| InterruptControlRequest
|
|
169
|
+
| RegisterExternalToolsRequest
|
|
170
|
+
| BootstrapSessionStateRequest
|
|
171
|
+
| RecoverPendingApprovalsControlRequest
|
|
172
|
+
| ListMessagesControlRequest
|
|
173
|
+
| CanUseToolControlRequest
|
|
174
|
+
| ExecuteExternalToolControlRequest
|
|
175
|
+
| (Record<string, unknown> & { subtype: string });
|
|
176
|
+
|
|
177
|
+
export interface ControlRequest extends MessageEnvelope {
|
|
178
|
+
type: "control_request";
|
|
179
|
+
request_id: string;
|
|
180
|
+
request: ControlRequestBody;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export interface CanUseToolResponseAllow {
|
|
184
|
+
behavior: "allow";
|
|
185
|
+
message?: string;
|
|
186
|
+
updatedInput?: Record<string, unknown> | null;
|
|
187
|
+
updatedPermissions?: unknown[];
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export interface CanUseToolResponseDeny {
|
|
191
|
+
behavior: "deny";
|
|
192
|
+
message: string;
|
|
193
|
+
interrupt?: boolean;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export type CanUseToolResponse = CanUseToolResponseAllow | CanUseToolResponseDeny;
|
|
197
|
+
|
|
198
|
+
export interface ExternalToolResultContent {
|
|
199
|
+
type: "text" | "image";
|
|
200
|
+
text?: string;
|
|
201
|
+
data?: string;
|
|
202
|
+
mimeType?: string;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface ExternalToolResultResponse {
|
|
206
|
+
subtype: "external_tool_result";
|
|
207
|
+
request_id: string;
|
|
208
|
+
tool_call_id: string;
|
|
209
|
+
content: ExternalToolResultContent[];
|
|
210
|
+
is_error: boolean;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export type ControlResponseBody =
|
|
214
|
+
| {
|
|
215
|
+
subtype: "success";
|
|
216
|
+
request_id: string;
|
|
217
|
+
response?: CanUseToolResponse | Record<string, unknown>;
|
|
218
|
+
}
|
|
219
|
+
| {
|
|
220
|
+
subtype: "error";
|
|
221
|
+
request_id: string;
|
|
222
|
+
error: string;
|
|
223
|
+
}
|
|
224
|
+
| ExternalToolResultResponse;
|
|
225
|
+
|
|
226
|
+
export interface ControlResponse extends MessageEnvelope {
|
|
227
|
+
type: "control_response";
|
|
228
|
+
response: ControlResponseBody;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export interface RetryMessage extends MessageEnvelope {
|
|
232
|
+
type: "retry";
|
|
233
|
+
reason: string;
|
|
234
|
+
attempt: number;
|
|
235
|
+
max_attempts: number;
|
|
236
|
+
delay_ms: number;
|
|
237
|
+
run_id?: string;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export type WireMessage =
|
|
241
|
+
| SystemInitMessage
|
|
242
|
+
| MessageWire
|
|
243
|
+
| StreamEvent
|
|
244
|
+
| ResultMessage
|
|
245
|
+
| ErrorMessage
|
|
246
|
+
| RetryMessage
|
|
247
|
+
| ControlRequest
|
|
248
|
+
| ControlResponse
|
|
249
|
+
| (MessageEnvelope & { type: string });
|