@cadraos/sdk 0.1.2 → 0.1.4
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/README.md +1 -1
- package/dist/chat/index.cjs +2874 -102
- package/dist/chat/index.cjs.map +1 -1
- package/dist/chat/index.d.cts +2616 -478
- package/dist/chat/index.d.ts +2616 -478
- package/dist/chat/index.js +2874 -102
- package/dist/chat/index.js.map +1 -1
- package/dist/index.cjs +267 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +195 -3
- package/dist/index.d.ts +195 -3
- package/dist/index.js +267 -24
- package/dist/index.js.map +1 -1
- package/package.json +14 -9
package/dist/index.d.cts
CHANGED
|
@@ -176,13 +176,17 @@ interface ExecuteInput {
|
|
|
176
176
|
task: string;
|
|
177
177
|
/** Additional context for the execution */
|
|
178
178
|
context?: Record<string, unknown>;
|
|
179
|
+
/** Attachment UUIDs to include with the message (for images, documents, etc.) */
|
|
180
|
+
attachmentIds?: string[];
|
|
181
|
+
/** Team UUID for team-based execution (routes to team's lead orchestrator) */
|
|
182
|
+
teamUuid?: string;
|
|
179
183
|
/** Execution options */
|
|
180
184
|
options?: ExecuteOptions;
|
|
181
185
|
}
|
|
182
186
|
/**
|
|
183
187
|
* Execution status
|
|
184
188
|
*/
|
|
185
|
-
type ExecutionStatus = 'queued' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
189
|
+
type ExecutionStatus = 'queued' | 'running' | 'completed' | 'failed' | 'cancelled' | 'paused' | 'waiting_user_input';
|
|
186
190
|
/**
|
|
187
191
|
* Token usage information
|
|
188
192
|
*/
|
|
@@ -250,6 +254,11 @@ interface AgentListOptions extends ListOptions {
|
|
|
250
254
|
/** Filter by type */
|
|
251
255
|
type?: AgentType;
|
|
252
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Log types that can be generated during execution
|
|
259
|
+
* Matches the LogType from cadra-api's log-collector service
|
|
260
|
+
*/
|
|
261
|
+
type LogType = 'info' | 'llm_request' | 'llm_response' | 'tool_call' | 'tool_result' | 'error' | 'system' | 'think' | 'rag' | 'skill' | 'delegation' | 'plan' | 'message';
|
|
253
262
|
/**
|
|
254
263
|
* Execution log entry
|
|
255
264
|
*/
|
|
@@ -257,7 +266,7 @@ interface ExecutionLog {
|
|
|
257
266
|
/** Unique identifier */
|
|
258
267
|
uuid: string;
|
|
259
268
|
/** Log type */
|
|
260
|
-
type:
|
|
269
|
+
type: LogType;
|
|
261
270
|
/** Log title/summary */
|
|
262
271
|
title: string;
|
|
263
272
|
/** Log content/details */
|
|
@@ -277,6 +286,8 @@ interface AgentExecution {
|
|
|
277
286
|
uuid: string;
|
|
278
287
|
/** Agent ID */
|
|
279
288
|
agentUuid: string;
|
|
289
|
+
/** Session ID for conversation continuity */
|
|
290
|
+
sessionId?: string;
|
|
280
291
|
/** Execution status */
|
|
281
292
|
status: ExecutionStatus;
|
|
282
293
|
/** Input provided */
|
|
@@ -335,6 +346,8 @@ interface AgentConfigUpdateInput {
|
|
|
335
346
|
interface ExecuteResponse {
|
|
336
347
|
/** Execution ID */
|
|
337
348
|
executionId: string;
|
|
349
|
+
/** Session ID for conversation continuity */
|
|
350
|
+
sessionId?: string;
|
|
338
351
|
/** Initial status */
|
|
339
352
|
status: ExecutionStatus;
|
|
340
353
|
}
|
|
@@ -685,6 +698,8 @@ interface SendMessageInput {
|
|
|
685
698
|
message: string;
|
|
686
699
|
/** Additional context */
|
|
687
700
|
context?: Record<string, unknown>;
|
|
701
|
+
/** Attachment UUIDs to include with the message (for images, documents, etc.) */
|
|
702
|
+
attachmentIds?: string[];
|
|
688
703
|
}
|
|
689
704
|
/**
|
|
690
705
|
* Session artifact type
|
|
@@ -804,6 +819,126 @@ interface ConnectionChangeEvent {
|
|
|
804
819
|
/** Whether using fallback polling */
|
|
805
820
|
usingFallback?: boolean;
|
|
806
821
|
}
|
|
822
|
+
/**
|
|
823
|
+
* Paused event (ask_user waiting for user input)
|
|
824
|
+
*/
|
|
825
|
+
interface PausedEvent {
|
|
826
|
+
/** The question to ask the user */
|
|
827
|
+
question: string;
|
|
828
|
+
/** Optional predefined choices */
|
|
829
|
+
options?: string[];
|
|
830
|
+
/** Reason for pausing */
|
|
831
|
+
reason: 'waiting_user_input';
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Delegation started event (handoff_to_agent initiated)
|
|
835
|
+
*/
|
|
836
|
+
interface DelegationStartedEvent {
|
|
837
|
+
/** Event type */
|
|
838
|
+
type: 'delegation_started';
|
|
839
|
+
/** Unique handoff ID */
|
|
840
|
+
handoffId: string;
|
|
841
|
+
/** Target agent UUID */
|
|
842
|
+
targetAgentUuid: string;
|
|
843
|
+
/** Target agent name */
|
|
844
|
+
targetAgentName?: string;
|
|
845
|
+
/** Preview of the delegated task */
|
|
846
|
+
taskPreview: string;
|
|
847
|
+
/** Event timestamp */
|
|
848
|
+
timestamp: string;
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* Delegation completed event (handoff_to_agent finished)
|
|
852
|
+
*/
|
|
853
|
+
interface DelegationCompletedEvent {
|
|
854
|
+
/** Event type */
|
|
855
|
+
type: 'delegation_completed';
|
|
856
|
+
/** Unique handoff ID */
|
|
857
|
+
handoffId: string;
|
|
858
|
+
/** Completion status */
|
|
859
|
+
status: 'completed' | 'failed';
|
|
860
|
+
/** Preview of the result (if completed) */
|
|
861
|
+
resultPreview?: string;
|
|
862
|
+
/** Error message (if failed) */
|
|
863
|
+
error?: string;
|
|
864
|
+
/** Duration in milliseconds */
|
|
865
|
+
durationMs: number;
|
|
866
|
+
/** Event timestamp */
|
|
867
|
+
timestamp: string;
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Text delta event - token-by-token streaming text
|
|
871
|
+
*/
|
|
872
|
+
interface TextDeltaEvent {
|
|
873
|
+
/** Text delta chunk */
|
|
874
|
+
delta: string;
|
|
875
|
+
/** Execution ID */
|
|
876
|
+
executionId: string;
|
|
877
|
+
/** Event timestamp */
|
|
878
|
+
timestamp: string;
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Started event - execution has begun
|
|
882
|
+
*/
|
|
883
|
+
interface StartedEvent {
|
|
884
|
+
/** Execution ID */
|
|
885
|
+
executionId: string;
|
|
886
|
+
/** Agent UUID */
|
|
887
|
+
agentUuid: string;
|
|
888
|
+
/** Initial status */
|
|
889
|
+
status: 'initializing';
|
|
890
|
+
/** Current step description */
|
|
891
|
+
currentStep?: string;
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* Progress event - execution status update
|
|
895
|
+
*/
|
|
896
|
+
interface ProgressEvent {
|
|
897
|
+
/** Current status */
|
|
898
|
+
status: 'initializing' | 'thinking' | 'acting' | 'observing' | 'planning' | 'paused';
|
|
899
|
+
/** Current iteration number */
|
|
900
|
+
iteration: number;
|
|
901
|
+
/** Description of current step */
|
|
902
|
+
currentStep?: string;
|
|
903
|
+
/** Current token usage */
|
|
904
|
+
tokenUsage?: {
|
|
905
|
+
prompt: number;
|
|
906
|
+
completion: number;
|
|
907
|
+
total: number;
|
|
908
|
+
};
|
|
909
|
+
/** Current cost */
|
|
910
|
+
cost?: number;
|
|
911
|
+
/** Number of tool calls made */
|
|
912
|
+
toolCalls?: number;
|
|
913
|
+
}
|
|
914
|
+
/**
|
|
915
|
+
* Task status for task list updates
|
|
916
|
+
*/
|
|
917
|
+
type TaskStatus = 'pending' | 'in_progress' | 'completed';
|
|
918
|
+
/**
|
|
919
|
+
* Task item in task list
|
|
920
|
+
*/
|
|
921
|
+
interface TaskItem {
|
|
922
|
+
/** Unique task ID */
|
|
923
|
+
id: string;
|
|
924
|
+
/** Task content/description */
|
|
925
|
+
content: string;
|
|
926
|
+
/** Active form text shown during in_progress */
|
|
927
|
+
activeForm?: string | null;
|
|
928
|
+
/** Task status */
|
|
929
|
+
status: TaskStatus;
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Task list update event - agent creating/updating task list
|
|
933
|
+
*/
|
|
934
|
+
interface TaskListUpdateEvent {
|
|
935
|
+
/** Execution ID */
|
|
936
|
+
executionId: string;
|
|
937
|
+
/** Current task list */
|
|
938
|
+
tasks: TaskItem[];
|
|
939
|
+
/** Timestamp */
|
|
940
|
+
timestamp: string;
|
|
941
|
+
}
|
|
807
942
|
/**
|
|
808
943
|
* Stream event map for type-safe event handlers
|
|
809
944
|
*/
|
|
@@ -812,6 +947,13 @@ interface StreamEventMap {
|
|
|
812
947
|
toolCall: ToolCallEvent;
|
|
813
948
|
toolResult: ToolResultEvent;
|
|
814
949
|
plan: PlanEvent;
|
|
950
|
+
paused: PausedEvent;
|
|
951
|
+
started: StartedEvent;
|
|
952
|
+
progress: ProgressEvent;
|
|
953
|
+
taskListUpdate: TaskListUpdateEvent;
|
|
954
|
+
delegationStarted: DelegationStartedEvent;
|
|
955
|
+
delegationCompleted: DelegationCompletedEvent;
|
|
956
|
+
textDelta: TextDeltaEvent;
|
|
815
957
|
complete: CompleteEvent;
|
|
816
958
|
error: ErrorEvent;
|
|
817
959
|
connectionChange: ConnectionChangeEvent;
|
|
@@ -828,6 +970,20 @@ interface StreamController {
|
|
|
828
970
|
on(event: 'toolResult', callback: (data: ToolResultEvent) => void): void;
|
|
829
971
|
/** Listen for plan updates */
|
|
830
972
|
on(event: 'plan', callback: (data: PlanEvent) => void): void;
|
|
973
|
+
/** Listen for paused events (ask_user waiting for input) */
|
|
974
|
+
on(event: 'paused', callback: (data: PausedEvent) => void): void;
|
|
975
|
+
/** Listen for execution started (immediate feedback) */
|
|
976
|
+
on(event: 'started', callback: (data: StartedEvent) => void): void;
|
|
977
|
+
/** Listen for progress updates (status changes during execution) */
|
|
978
|
+
on(event: 'progress', callback: (data: ProgressEvent) => void): void;
|
|
979
|
+
/** Listen for task list updates */
|
|
980
|
+
on(event: 'taskListUpdate', callback: (data: TaskListUpdateEvent) => void): void;
|
|
981
|
+
/** Listen for delegation started events */
|
|
982
|
+
on(event: 'delegationStarted', callback: (data: DelegationStartedEvent) => void): void;
|
|
983
|
+
/** Listen for delegation completed events */
|
|
984
|
+
on(event: 'delegationCompleted', callback: (data: DelegationCompletedEvent) => void): void;
|
|
985
|
+
/** Listen for text delta events (token-by-token streaming) */
|
|
986
|
+
on(event: 'textDelta', callback: (data: TextDeltaEvent) => void): void;
|
|
831
987
|
/** Listen for completion */
|
|
832
988
|
on(event: 'complete', callback: (data: CompleteEvent) => void): void;
|
|
833
989
|
/** Listen for errors */
|
|
@@ -913,10 +1069,14 @@ declare abstract class BaseResourceAPI {
|
|
|
913
1069
|
interface ExecutionStreamControllerOptions {
|
|
914
1070
|
/** Execution ID to stream */
|
|
915
1071
|
executionId: string;
|
|
1072
|
+
/** Session ID for conversation continuity */
|
|
1073
|
+
sessionId?: string;
|
|
916
1074
|
/** Base URL for API */
|
|
917
1075
|
baseUrl: string;
|
|
918
1076
|
/** API key or token */
|
|
919
1077
|
apiKey?: string;
|
|
1078
|
+
/** Token provider callback for dynamic auth */
|
|
1079
|
+
tokenProvider?: () => Promise<string>;
|
|
920
1080
|
/** Organization ID */
|
|
921
1081
|
orgId: number;
|
|
922
1082
|
/** Function to get execution status (for polling fallback) */
|
|
@@ -936,6 +1096,10 @@ interface ExecutionStreamControllerOptions {
|
|
|
936
1096
|
interface ExecutionStreamController extends StreamController {
|
|
937
1097
|
/** Connect to the stream */
|
|
938
1098
|
connect(): Promise<void>;
|
|
1099
|
+
/** Get the execution ID */
|
|
1100
|
+
readonly executionId: string;
|
|
1101
|
+
/** Get the session ID (if available) */
|
|
1102
|
+
readonly sessionId: string | undefined;
|
|
939
1103
|
}
|
|
940
1104
|
|
|
941
1105
|
/**
|
|
@@ -1039,6 +1203,33 @@ declare class AgentsAPI extends BaseResourceAPI {
|
|
|
1039
1203
|
* ```
|
|
1040
1204
|
*/
|
|
1041
1205
|
stream(uuid: string, input: ExecuteInput): Promise<ExecutionStreamController>;
|
|
1206
|
+
/**
|
|
1207
|
+
* Connect to an existing execution's stream
|
|
1208
|
+
*
|
|
1209
|
+
* Use this when the execution was started externally (e.g., via tRPC for team executions)
|
|
1210
|
+
* and you need to connect to its SSE stream for real-time updates.
|
|
1211
|
+
*
|
|
1212
|
+
* @param executionId - Execution UUID (already running)
|
|
1213
|
+
* @param sessionId - Optional session ID for conversation continuity
|
|
1214
|
+
* @returns Stream controller for the execution
|
|
1215
|
+
*
|
|
1216
|
+
* @example
|
|
1217
|
+
* ```typescript
|
|
1218
|
+
* // Execution started via tRPC
|
|
1219
|
+
* const executionId = await trpc.executions.start.mutate({ teamUuid, task });
|
|
1220
|
+
*
|
|
1221
|
+
* // Connect to SSE stream for real-time updates
|
|
1222
|
+
* const stream = client.agents.streamExecution(executionId);
|
|
1223
|
+
*
|
|
1224
|
+
* stream.on('log', (log) => console.log(log.title));
|
|
1225
|
+
* stream.on('delegationStarted', (data) => console.log('Subagent:', data.targetAgentName));
|
|
1226
|
+
* stream.on('complete', ({ execution }) => console.log(execution.output));
|
|
1227
|
+
*
|
|
1228
|
+
* await stream.connect();
|
|
1229
|
+
* const result = await stream.wait();
|
|
1230
|
+
* ```
|
|
1231
|
+
*/
|
|
1232
|
+
streamExecution(executionId: string, sessionId?: string): ExecutionStreamController;
|
|
1042
1233
|
/**
|
|
1043
1234
|
* Get execution result by ID
|
|
1044
1235
|
*
|
|
@@ -1111,6 +1302,7 @@ interface StreamConfig {
|
|
|
1111
1302
|
baseUrl: string;
|
|
1112
1303
|
apiKey?: string;
|
|
1113
1304
|
token?: string;
|
|
1305
|
+
tokenProvider?: () => Promise<string>;
|
|
1114
1306
|
orgId: number;
|
|
1115
1307
|
}
|
|
1116
1308
|
|
|
@@ -1901,4 +2093,4 @@ declare class NetworkError extends AISaaSError {
|
|
|
1901
2093
|
constructor(message?: string, details?: Record<string, unknown>);
|
|
1902
2094
|
}
|
|
1903
2095
|
|
|
1904
|
-
export { AISaaSClient, type AISaaSClientOptions, AISaaSError, type Agent, type AgentConfig, type AgentConfigUpdateInput, type AgentExecution, type AgentListOptions, type AgentStatus, type AgentType, type AgentUpdateInput, type Artifact, type ArtifactDownloadOptions, type ArtifactListOptions, type ArtifactType, type ArtifactUploadInput, AuthenticationError, AuthorizationError, type CompleteEvent, ConflictError, type ConnectionChangeEvent, type ErrorEvent, type ExecuteInput, type ExecuteOptions, type ExecuteResponse, type ExecutionLog, type ExecutionStatus, type ExecutionStreamController, type ExecutionStreamControllerOptions, type JSONSchema, type ListOptions, NetworkError, NotFoundError, type PaginatedResponse, type PaginationInfo, type PlanEvent, RateLimitError, type SendMessageInput, ServerError, type Session, type SessionArtifact, type SessionArtifactListOptions, type SessionArtifactType, type SessionArtifactVariantType, type SessionCreateInput, type SessionHistory, type SessionListOptions, type SessionMessage, type SignedUrlResponse, type Skill, type SkillDetails, type SkillExecuteInput, type SkillExecution, type SkillListOptions, type SkillTool, type SkillUpdateInput, type SkillVariable, type StreamController, type StreamEventMap, TimeoutError, type TokenUsage, type Tool, type ToolCallEvent, type ToolConfigUpdateInput, type ToolExecution, type ToolListOptions, type ToolResultEvent, type ToolUpdateInput, type ToolValidationResult, ValidationError };
|
|
2096
|
+
export { AISaaSClient, type AISaaSClientOptions, AISaaSError, type Agent, type AgentConfig, type AgentConfigUpdateInput, type AgentExecution, type AgentListOptions, type AgentStatus, type AgentType, type AgentUpdateInput, type Artifact, type ArtifactDownloadOptions, type ArtifactListOptions, type ArtifactType, type ArtifactUploadInput, AuthenticationError, AuthorizationError, type CompleteEvent, ConflictError, type ConnectionChangeEvent, type DelegationCompletedEvent, type DelegationStartedEvent, type ErrorEvent, type ExecuteInput, type ExecuteOptions, type ExecuteResponse, type ExecutionLog, type ExecutionStatus, type ExecutionStreamController, type ExecutionStreamControllerOptions, type JSONSchema, type ListOptions, NetworkError, NotFoundError, type PaginatedResponse, type PaginationInfo, type PausedEvent, type PlanEvent, type ProgressEvent, RateLimitError, type SendMessageInput, ServerError, type Session, type SessionArtifact, type SessionArtifactListOptions, type SessionArtifactType, type SessionArtifactVariantType, type SessionCreateInput, type SessionHistory, type SessionListOptions, type SessionMessage, type SignedUrlResponse, type Skill, type SkillDetails, type SkillExecuteInput, type SkillExecution, type SkillListOptions, type SkillTool, type SkillUpdateInput, type SkillVariable, type StartedEvent, type StreamController, type StreamEventMap, type TextDeltaEvent, TimeoutError, type TokenUsage, type Tool, type ToolCallEvent, type ToolConfigUpdateInput, type ToolExecution, type ToolListOptions, type ToolResultEvent, type ToolUpdateInput, type ToolValidationResult, ValidationError };
|
package/dist/index.d.ts
CHANGED
|
@@ -176,13 +176,17 @@ interface ExecuteInput {
|
|
|
176
176
|
task: string;
|
|
177
177
|
/** Additional context for the execution */
|
|
178
178
|
context?: Record<string, unknown>;
|
|
179
|
+
/** Attachment UUIDs to include with the message (for images, documents, etc.) */
|
|
180
|
+
attachmentIds?: string[];
|
|
181
|
+
/** Team UUID for team-based execution (routes to team's lead orchestrator) */
|
|
182
|
+
teamUuid?: string;
|
|
179
183
|
/** Execution options */
|
|
180
184
|
options?: ExecuteOptions;
|
|
181
185
|
}
|
|
182
186
|
/**
|
|
183
187
|
* Execution status
|
|
184
188
|
*/
|
|
185
|
-
type ExecutionStatus = 'queued' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
189
|
+
type ExecutionStatus = 'queued' | 'running' | 'completed' | 'failed' | 'cancelled' | 'paused' | 'waiting_user_input';
|
|
186
190
|
/**
|
|
187
191
|
* Token usage information
|
|
188
192
|
*/
|
|
@@ -250,6 +254,11 @@ interface AgentListOptions extends ListOptions {
|
|
|
250
254
|
/** Filter by type */
|
|
251
255
|
type?: AgentType;
|
|
252
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Log types that can be generated during execution
|
|
259
|
+
* Matches the LogType from cadra-api's log-collector service
|
|
260
|
+
*/
|
|
261
|
+
type LogType = 'info' | 'llm_request' | 'llm_response' | 'tool_call' | 'tool_result' | 'error' | 'system' | 'think' | 'rag' | 'skill' | 'delegation' | 'plan' | 'message';
|
|
253
262
|
/**
|
|
254
263
|
* Execution log entry
|
|
255
264
|
*/
|
|
@@ -257,7 +266,7 @@ interface ExecutionLog {
|
|
|
257
266
|
/** Unique identifier */
|
|
258
267
|
uuid: string;
|
|
259
268
|
/** Log type */
|
|
260
|
-
type:
|
|
269
|
+
type: LogType;
|
|
261
270
|
/** Log title/summary */
|
|
262
271
|
title: string;
|
|
263
272
|
/** Log content/details */
|
|
@@ -277,6 +286,8 @@ interface AgentExecution {
|
|
|
277
286
|
uuid: string;
|
|
278
287
|
/** Agent ID */
|
|
279
288
|
agentUuid: string;
|
|
289
|
+
/** Session ID for conversation continuity */
|
|
290
|
+
sessionId?: string;
|
|
280
291
|
/** Execution status */
|
|
281
292
|
status: ExecutionStatus;
|
|
282
293
|
/** Input provided */
|
|
@@ -335,6 +346,8 @@ interface AgentConfigUpdateInput {
|
|
|
335
346
|
interface ExecuteResponse {
|
|
336
347
|
/** Execution ID */
|
|
337
348
|
executionId: string;
|
|
349
|
+
/** Session ID for conversation continuity */
|
|
350
|
+
sessionId?: string;
|
|
338
351
|
/** Initial status */
|
|
339
352
|
status: ExecutionStatus;
|
|
340
353
|
}
|
|
@@ -685,6 +698,8 @@ interface SendMessageInput {
|
|
|
685
698
|
message: string;
|
|
686
699
|
/** Additional context */
|
|
687
700
|
context?: Record<string, unknown>;
|
|
701
|
+
/** Attachment UUIDs to include with the message (for images, documents, etc.) */
|
|
702
|
+
attachmentIds?: string[];
|
|
688
703
|
}
|
|
689
704
|
/**
|
|
690
705
|
* Session artifact type
|
|
@@ -804,6 +819,126 @@ interface ConnectionChangeEvent {
|
|
|
804
819
|
/** Whether using fallback polling */
|
|
805
820
|
usingFallback?: boolean;
|
|
806
821
|
}
|
|
822
|
+
/**
|
|
823
|
+
* Paused event (ask_user waiting for user input)
|
|
824
|
+
*/
|
|
825
|
+
interface PausedEvent {
|
|
826
|
+
/** The question to ask the user */
|
|
827
|
+
question: string;
|
|
828
|
+
/** Optional predefined choices */
|
|
829
|
+
options?: string[];
|
|
830
|
+
/** Reason for pausing */
|
|
831
|
+
reason: 'waiting_user_input';
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Delegation started event (handoff_to_agent initiated)
|
|
835
|
+
*/
|
|
836
|
+
interface DelegationStartedEvent {
|
|
837
|
+
/** Event type */
|
|
838
|
+
type: 'delegation_started';
|
|
839
|
+
/** Unique handoff ID */
|
|
840
|
+
handoffId: string;
|
|
841
|
+
/** Target agent UUID */
|
|
842
|
+
targetAgentUuid: string;
|
|
843
|
+
/** Target agent name */
|
|
844
|
+
targetAgentName?: string;
|
|
845
|
+
/** Preview of the delegated task */
|
|
846
|
+
taskPreview: string;
|
|
847
|
+
/** Event timestamp */
|
|
848
|
+
timestamp: string;
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* Delegation completed event (handoff_to_agent finished)
|
|
852
|
+
*/
|
|
853
|
+
interface DelegationCompletedEvent {
|
|
854
|
+
/** Event type */
|
|
855
|
+
type: 'delegation_completed';
|
|
856
|
+
/** Unique handoff ID */
|
|
857
|
+
handoffId: string;
|
|
858
|
+
/** Completion status */
|
|
859
|
+
status: 'completed' | 'failed';
|
|
860
|
+
/** Preview of the result (if completed) */
|
|
861
|
+
resultPreview?: string;
|
|
862
|
+
/** Error message (if failed) */
|
|
863
|
+
error?: string;
|
|
864
|
+
/** Duration in milliseconds */
|
|
865
|
+
durationMs: number;
|
|
866
|
+
/** Event timestamp */
|
|
867
|
+
timestamp: string;
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Text delta event - token-by-token streaming text
|
|
871
|
+
*/
|
|
872
|
+
interface TextDeltaEvent {
|
|
873
|
+
/** Text delta chunk */
|
|
874
|
+
delta: string;
|
|
875
|
+
/** Execution ID */
|
|
876
|
+
executionId: string;
|
|
877
|
+
/** Event timestamp */
|
|
878
|
+
timestamp: string;
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Started event - execution has begun
|
|
882
|
+
*/
|
|
883
|
+
interface StartedEvent {
|
|
884
|
+
/** Execution ID */
|
|
885
|
+
executionId: string;
|
|
886
|
+
/** Agent UUID */
|
|
887
|
+
agentUuid: string;
|
|
888
|
+
/** Initial status */
|
|
889
|
+
status: 'initializing';
|
|
890
|
+
/** Current step description */
|
|
891
|
+
currentStep?: string;
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* Progress event - execution status update
|
|
895
|
+
*/
|
|
896
|
+
interface ProgressEvent {
|
|
897
|
+
/** Current status */
|
|
898
|
+
status: 'initializing' | 'thinking' | 'acting' | 'observing' | 'planning' | 'paused';
|
|
899
|
+
/** Current iteration number */
|
|
900
|
+
iteration: number;
|
|
901
|
+
/** Description of current step */
|
|
902
|
+
currentStep?: string;
|
|
903
|
+
/** Current token usage */
|
|
904
|
+
tokenUsage?: {
|
|
905
|
+
prompt: number;
|
|
906
|
+
completion: number;
|
|
907
|
+
total: number;
|
|
908
|
+
};
|
|
909
|
+
/** Current cost */
|
|
910
|
+
cost?: number;
|
|
911
|
+
/** Number of tool calls made */
|
|
912
|
+
toolCalls?: number;
|
|
913
|
+
}
|
|
914
|
+
/**
|
|
915
|
+
* Task status for task list updates
|
|
916
|
+
*/
|
|
917
|
+
type TaskStatus = 'pending' | 'in_progress' | 'completed';
|
|
918
|
+
/**
|
|
919
|
+
* Task item in task list
|
|
920
|
+
*/
|
|
921
|
+
interface TaskItem {
|
|
922
|
+
/** Unique task ID */
|
|
923
|
+
id: string;
|
|
924
|
+
/** Task content/description */
|
|
925
|
+
content: string;
|
|
926
|
+
/** Active form text shown during in_progress */
|
|
927
|
+
activeForm?: string | null;
|
|
928
|
+
/** Task status */
|
|
929
|
+
status: TaskStatus;
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Task list update event - agent creating/updating task list
|
|
933
|
+
*/
|
|
934
|
+
interface TaskListUpdateEvent {
|
|
935
|
+
/** Execution ID */
|
|
936
|
+
executionId: string;
|
|
937
|
+
/** Current task list */
|
|
938
|
+
tasks: TaskItem[];
|
|
939
|
+
/** Timestamp */
|
|
940
|
+
timestamp: string;
|
|
941
|
+
}
|
|
807
942
|
/**
|
|
808
943
|
* Stream event map for type-safe event handlers
|
|
809
944
|
*/
|
|
@@ -812,6 +947,13 @@ interface StreamEventMap {
|
|
|
812
947
|
toolCall: ToolCallEvent;
|
|
813
948
|
toolResult: ToolResultEvent;
|
|
814
949
|
plan: PlanEvent;
|
|
950
|
+
paused: PausedEvent;
|
|
951
|
+
started: StartedEvent;
|
|
952
|
+
progress: ProgressEvent;
|
|
953
|
+
taskListUpdate: TaskListUpdateEvent;
|
|
954
|
+
delegationStarted: DelegationStartedEvent;
|
|
955
|
+
delegationCompleted: DelegationCompletedEvent;
|
|
956
|
+
textDelta: TextDeltaEvent;
|
|
815
957
|
complete: CompleteEvent;
|
|
816
958
|
error: ErrorEvent;
|
|
817
959
|
connectionChange: ConnectionChangeEvent;
|
|
@@ -828,6 +970,20 @@ interface StreamController {
|
|
|
828
970
|
on(event: 'toolResult', callback: (data: ToolResultEvent) => void): void;
|
|
829
971
|
/** Listen for plan updates */
|
|
830
972
|
on(event: 'plan', callback: (data: PlanEvent) => void): void;
|
|
973
|
+
/** Listen for paused events (ask_user waiting for input) */
|
|
974
|
+
on(event: 'paused', callback: (data: PausedEvent) => void): void;
|
|
975
|
+
/** Listen for execution started (immediate feedback) */
|
|
976
|
+
on(event: 'started', callback: (data: StartedEvent) => void): void;
|
|
977
|
+
/** Listen for progress updates (status changes during execution) */
|
|
978
|
+
on(event: 'progress', callback: (data: ProgressEvent) => void): void;
|
|
979
|
+
/** Listen for task list updates */
|
|
980
|
+
on(event: 'taskListUpdate', callback: (data: TaskListUpdateEvent) => void): void;
|
|
981
|
+
/** Listen for delegation started events */
|
|
982
|
+
on(event: 'delegationStarted', callback: (data: DelegationStartedEvent) => void): void;
|
|
983
|
+
/** Listen for delegation completed events */
|
|
984
|
+
on(event: 'delegationCompleted', callback: (data: DelegationCompletedEvent) => void): void;
|
|
985
|
+
/** Listen for text delta events (token-by-token streaming) */
|
|
986
|
+
on(event: 'textDelta', callback: (data: TextDeltaEvent) => void): void;
|
|
831
987
|
/** Listen for completion */
|
|
832
988
|
on(event: 'complete', callback: (data: CompleteEvent) => void): void;
|
|
833
989
|
/** Listen for errors */
|
|
@@ -913,10 +1069,14 @@ declare abstract class BaseResourceAPI {
|
|
|
913
1069
|
interface ExecutionStreamControllerOptions {
|
|
914
1070
|
/** Execution ID to stream */
|
|
915
1071
|
executionId: string;
|
|
1072
|
+
/** Session ID for conversation continuity */
|
|
1073
|
+
sessionId?: string;
|
|
916
1074
|
/** Base URL for API */
|
|
917
1075
|
baseUrl: string;
|
|
918
1076
|
/** API key or token */
|
|
919
1077
|
apiKey?: string;
|
|
1078
|
+
/** Token provider callback for dynamic auth */
|
|
1079
|
+
tokenProvider?: () => Promise<string>;
|
|
920
1080
|
/** Organization ID */
|
|
921
1081
|
orgId: number;
|
|
922
1082
|
/** Function to get execution status (for polling fallback) */
|
|
@@ -936,6 +1096,10 @@ interface ExecutionStreamControllerOptions {
|
|
|
936
1096
|
interface ExecutionStreamController extends StreamController {
|
|
937
1097
|
/** Connect to the stream */
|
|
938
1098
|
connect(): Promise<void>;
|
|
1099
|
+
/** Get the execution ID */
|
|
1100
|
+
readonly executionId: string;
|
|
1101
|
+
/** Get the session ID (if available) */
|
|
1102
|
+
readonly sessionId: string | undefined;
|
|
939
1103
|
}
|
|
940
1104
|
|
|
941
1105
|
/**
|
|
@@ -1039,6 +1203,33 @@ declare class AgentsAPI extends BaseResourceAPI {
|
|
|
1039
1203
|
* ```
|
|
1040
1204
|
*/
|
|
1041
1205
|
stream(uuid: string, input: ExecuteInput): Promise<ExecutionStreamController>;
|
|
1206
|
+
/**
|
|
1207
|
+
* Connect to an existing execution's stream
|
|
1208
|
+
*
|
|
1209
|
+
* Use this when the execution was started externally (e.g., via tRPC for team executions)
|
|
1210
|
+
* and you need to connect to its SSE stream for real-time updates.
|
|
1211
|
+
*
|
|
1212
|
+
* @param executionId - Execution UUID (already running)
|
|
1213
|
+
* @param sessionId - Optional session ID for conversation continuity
|
|
1214
|
+
* @returns Stream controller for the execution
|
|
1215
|
+
*
|
|
1216
|
+
* @example
|
|
1217
|
+
* ```typescript
|
|
1218
|
+
* // Execution started via tRPC
|
|
1219
|
+
* const executionId = await trpc.executions.start.mutate({ teamUuid, task });
|
|
1220
|
+
*
|
|
1221
|
+
* // Connect to SSE stream for real-time updates
|
|
1222
|
+
* const stream = client.agents.streamExecution(executionId);
|
|
1223
|
+
*
|
|
1224
|
+
* stream.on('log', (log) => console.log(log.title));
|
|
1225
|
+
* stream.on('delegationStarted', (data) => console.log('Subagent:', data.targetAgentName));
|
|
1226
|
+
* stream.on('complete', ({ execution }) => console.log(execution.output));
|
|
1227
|
+
*
|
|
1228
|
+
* await stream.connect();
|
|
1229
|
+
* const result = await stream.wait();
|
|
1230
|
+
* ```
|
|
1231
|
+
*/
|
|
1232
|
+
streamExecution(executionId: string, sessionId?: string): ExecutionStreamController;
|
|
1042
1233
|
/**
|
|
1043
1234
|
* Get execution result by ID
|
|
1044
1235
|
*
|
|
@@ -1111,6 +1302,7 @@ interface StreamConfig {
|
|
|
1111
1302
|
baseUrl: string;
|
|
1112
1303
|
apiKey?: string;
|
|
1113
1304
|
token?: string;
|
|
1305
|
+
tokenProvider?: () => Promise<string>;
|
|
1114
1306
|
orgId: number;
|
|
1115
1307
|
}
|
|
1116
1308
|
|
|
@@ -1901,4 +2093,4 @@ declare class NetworkError extends AISaaSError {
|
|
|
1901
2093
|
constructor(message?: string, details?: Record<string, unknown>);
|
|
1902
2094
|
}
|
|
1903
2095
|
|
|
1904
|
-
export { AISaaSClient, type AISaaSClientOptions, AISaaSError, type Agent, type AgentConfig, type AgentConfigUpdateInput, type AgentExecution, type AgentListOptions, type AgentStatus, type AgentType, type AgentUpdateInput, type Artifact, type ArtifactDownloadOptions, type ArtifactListOptions, type ArtifactType, type ArtifactUploadInput, AuthenticationError, AuthorizationError, type CompleteEvent, ConflictError, type ConnectionChangeEvent, type ErrorEvent, type ExecuteInput, type ExecuteOptions, type ExecuteResponse, type ExecutionLog, type ExecutionStatus, type ExecutionStreamController, type ExecutionStreamControllerOptions, type JSONSchema, type ListOptions, NetworkError, NotFoundError, type PaginatedResponse, type PaginationInfo, type PlanEvent, RateLimitError, type SendMessageInput, ServerError, type Session, type SessionArtifact, type SessionArtifactListOptions, type SessionArtifactType, type SessionArtifactVariantType, type SessionCreateInput, type SessionHistory, type SessionListOptions, type SessionMessage, type SignedUrlResponse, type Skill, type SkillDetails, type SkillExecuteInput, type SkillExecution, type SkillListOptions, type SkillTool, type SkillUpdateInput, type SkillVariable, type StreamController, type StreamEventMap, TimeoutError, type TokenUsage, type Tool, type ToolCallEvent, type ToolConfigUpdateInput, type ToolExecution, type ToolListOptions, type ToolResultEvent, type ToolUpdateInput, type ToolValidationResult, ValidationError };
|
|
2096
|
+
export { AISaaSClient, type AISaaSClientOptions, AISaaSError, type Agent, type AgentConfig, type AgentConfigUpdateInput, type AgentExecution, type AgentListOptions, type AgentStatus, type AgentType, type AgentUpdateInput, type Artifact, type ArtifactDownloadOptions, type ArtifactListOptions, type ArtifactType, type ArtifactUploadInput, AuthenticationError, AuthorizationError, type CompleteEvent, ConflictError, type ConnectionChangeEvent, type DelegationCompletedEvent, type DelegationStartedEvent, type ErrorEvent, type ExecuteInput, type ExecuteOptions, type ExecuteResponse, type ExecutionLog, type ExecutionStatus, type ExecutionStreamController, type ExecutionStreamControllerOptions, type JSONSchema, type ListOptions, NetworkError, NotFoundError, type PaginatedResponse, type PaginationInfo, type PausedEvent, type PlanEvent, type ProgressEvent, RateLimitError, type SendMessageInput, ServerError, type Session, type SessionArtifact, type SessionArtifactListOptions, type SessionArtifactType, type SessionArtifactVariantType, type SessionCreateInput, type SessionHistory, type SessionListOptions, type SessionMessage, type SignedUrlResponse, type Skill, type SkillDetails, type SkillExecuteInput, type SkillExecution, type SkillListOptions, type SkillTool, type SkillUpdateInput, type SkillVariable, type StartedEvent, type StreamController, type StreamEventMap, type TextDeltaEvent, TimeoutError, type TokenUsage, type Tool, type ToolCallEvent, type ToolConfigUpdateInput, type ToolExecution, type ToolListOptions, type ToolResultEvent, type ToolUpdateInput, type ToolValidationResult, ValidationError };
|