@distri/core 0.3.1 → 0.3.2

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/dist/index.d.mts CHANGED
@@ -143,6 +143,14 @@ interface BrowserScreenshotEvent {
143
143
  timestamp_ms?: number;
144
144
  };
145
145
  }
146
+ interface BrowserSessionStartedEvent {
147
+ type: 'browser_session_started';
148
+ data: {
149
+ session_id: string;
150
+ viewer_url?: string;
151
+ stream_url?: string;
152
+ };
153
+ }
146
154
  interface InlineHookRequestedEvent {
147
155
  type: 'inline_hook_requested';
148
156
  data: {
@@ -161,7 +169,7 @@ interface InlineHookRequestedEvent {
161
169
  result?: any;
162
170
  };
163
171
  }
164
- type DistriEvent = RunStartedEvent | RunFinishedEvent | RunErrorEvent | PlanStartedEvent | PlanFinishedEvent | PlanPrunedEvent | TextMessageStartEvent | TextMessageContentEvent | TextMessageEndEvent | ToolExecutionStartEvent | ToolExecutionEndEvent | ToolRejectedEvent | StepStartedEvent | StepCompletedEvent | AgentHandoverEvent | FeedbackReceivedEvent | ToolCallsEvent | ToolResultsEvent | BrowserScreenshotEvent | InlineHookRequestedEvent;
172
+ type DistriEvent = RunStartedEvent | RunFinishedEvent | RunErrorEvent | PlanStartedEvent | PlanFinishedEvent | PlanPrunedEvent | TextMessageStartEvent | TextMessageContentEvent | TextMessageEndEvent | ToolExecutionStartEvent | ToolExecutionEndEvent | ToolRejectedEvent | StepStartedEvent | StepCompletedEvent | AgentHandoverEvent | FeedbackReceivedEvent | ToolCallsEvent | ToolResultsEvent | BrowserScreenshotEvent | BrowserSessionStartedEvent | InlineHookRequestedEvent;
165
173
 
166
174
  type ChatCompletionRole = 'system' | 'user' | 'assistant' | 'tool';
167
175
  interface ChatCompletionMessage {
@@ -223,6 +231,14 @@ declare class DistriClient {
223
231
  private refreshPromise?;
224
232
  private agentClients;
225
233
  constructor(config: DistriClientConfig);
234
+ /**
235
+ * Get the configured client ID.
236
+ */
237
+ get clientId(): string | undefined;
238
+ /**
239
+ * Set the client ID for embed token issuance.
240
+ */
241
+ set clientId(value: string | undefined);
226
242
  /**
227
243
  * Create a client with default cloud configuration.
228
244
  *
@@ -257,25 +273,6 @@ declare class DistriClient {
257
273
  * Session store: clear all keys in a session
258
274
  */
259
275
  clearSession(sessionId: string): Promise<void>;
260
- private static readonly ADDITIONAL_PARTS_KEY;
261
- /**
262
- * Set additional user message parts for the next agent iteration.
263
- * These parts will be appended to the user message in the prompt.
264
- * @param sessionId - The thread/session ID
265
- * @param parts - Array of DistriPart objects to append to user message
266
- */
267
- setAdditionalUserParts(sessionId: string, parts: DistriPart[]): Promise<void>;
268
- /**
269
- * Get the current additional user message parts.
270
- * @param sessionId - The thread/session ID
271
- * @returns Array of DistriPart objects or null if not set
272
- */
273
- getAdditionalUserParts(sessionId: string): Promise<DistriPart[] | null>;
274
- /**
275
- * Clear/delete the additional user message parts.
276
- * @param sessionId - The thread/session ID
277
- */
278
- clearAdditionalUserParts(sessionId: string): Promise<void>;
279
276
  /**
280
277
  * Response from the token endpoint
281
278
  */
@@ -315,6 +312,10 @@ declare class DistriClient {
315
312
  accessToken?: string;
316
313
  refreshToken?: string;
317
314
  }): void;
315
+ /**
316
+ * Reset all authentication tokens.
317
+ */
318
+ resetTokens(): void;
318
319
  /**
319
320
  * Start streaming speech-to-text transcription via WebSocket
320
321
  */
@@ -341,7 +342,13 @@ declare class DistriClient {
341
342
  /**
342
343
  * Get specific agent by ID
343
344
  */
344
- getAgent(agentId: string): Promise<AgentDefinition>;
345
+ getAgent(agentId: string): Promise<AgentConfigWithTools>;
346
+ /**
347
+ * Update an agent's definition (markdown only)
348
+ */
349
+ updateAgent(agentId: string, update: {
350
+ markdown: string;
351
+ }): Promise<AgentConfigWithTools>;
345
352
  /**
346
353
  * Get or create A2AClient for an agent
347
354
  */
@@ -363,9 +370,18 @@ declare class DistriClient {
363
370
  */
364
371
  cancelTask(agentId: string, taskId: string): Promise<void>;
365
372
  /**
366
- * Get threads from Distri server
373
+ * Get threads from Distri server with filtering and pagination
374
+ */
375
+ getThreads(params?: ThreadListParams): Promise<ThreadListResponse>;
376
+ /**
377
+ * Get agents sorted by thread count (most active first)
378
+ */
379
+ getAgentsByUsage(): Promise<AgentUsageInfo[]>;
380
+ /**
381
+ * Create a new browser session
382
+ * Returns session info including viewer_url and stream_url from browsr
367
383
  */
368
- getThreads(): Promise<DistriThread[]>;
384
+ createBrowserSession(): Promise<BrowserSession>;
369
385
  getThread(threadId: string): Promise<DistriThread>;
370
386
  /**
371
387
  * Get thread messages
@@ -392,6 +408,9 @@ declare class DistriClient {
392
408
  */
393
409
  get baseUrl(): string;
394
410
  private applyTokens;
411
+ /**
412
+ * Ensure access token is valid, refreshing if necessary
413
+ */
395
414
  private ensureAccessToken;
396
415
  private refreshTokens;
397
416
  private performTokenRefresh;
@@ -405,9 +424,10 @@ declare class DistriClient {
405
424
  */
406
425
  private fetchAbsolute;
407
426
  /**
408
- * Enhanced fetch with retry logic
427
+ * Enhanced fetch with retry logic and auth headers.
428
+ * Exposed publicly for extensions like DistriHomeClient.
409
429
  */
410
- private fetch;
430
+ fetch(input: RequestInfo | URL, initialInit?: RequestInit): Promise<Response>;
411
431
  /**
412
432
  * Delay utility
413
433
  */
@@ -457,6 +477,20 @@ interface InvokeResult {
457
477
  /** Whether the response was streamed */
458
478
  streamed: boolean;
459
479
  }
480
+ interface ExternalToolValidationResult {
481
+ isValid: boolean;
482
+ requiredTools: string[];
483
+ providedTools: string[];
484
+ missingTools: string[];
485
+ message?: string;
486
+ }
487
+ declare class ExternalToolValidationError extends DistriError {
488
+ missingTools: string[];
489
+ requiredTools: string[];
490
+ providedTools: string[];
491
+ agentName: string;
492
+ constructor(agentName: string, result: ExternalToolValidationResult);
493
+ }
460
494
  /**
461
495
  * Enhanced Agent class with simple tool system following AG-UI pattern
462
496
  */
@@ -465,7 +499,7 @@ declare class Agent {
465
499
  private agentDefinition;
466
500
  private hookHandlers;
467
501
  private defaultHookHandler;
468
- constructor(agentDefinition: AgentDefinition, client: DistriClient);
502
+ constructor(agentDefinition: AgentConfigWithTools, client: DistriClient);
469
503
  /**
470
504
  * Get agent information
471
505
  */
@@ -477,7 +511,7 @@ declare class Agent {
477
511
  /**
478
512
  * Get the full agent definition (including backend tools)
479
513
  */
480
- getDefinition(): AgentDefinition;
514
+ getDefinition(): AgentConfigWithTools;
481
515
  /**
482
516
  * Fetch messages for a thread (public method for useChat)
483
517
  */
@@ -490,10 +524,19 @@ declare class Agent {
490
524
  * Streaming invoke
491
525
  */
492
526
  invokeStream(params: MessageSendParams, tools?: DistriBaseTool[], hooks?: Record<string, HookHandler>): Promise<AsyncGenerator<DistriChatMessage>>;
527
+ /**
528
+ * Validate that required external tools are registered before invoking.
529
+ */
530
+ validateExternalTools(tools?: DistriBaseTool[]): ExternalToolValidationResult;
493
531
  /**
494
532
  * Enhance message params with tool definitions
495
533
  */
496
534
  private enhanceParamsWithTools;
535
+ private assertExternalTools;
536
+ private getRequiredExternalTools;
537
+ private resolveToolConfig;
538
+ private extractToolConfig;
539
+ private formatExternalToolValidationMessage;
497
540
  /**
498
541
  * Register multiple hooks at once.
499
542
  */
@@ -501,7 +544,7 @@ declare class Agent {
501
544
  /**
502
545
  * Create an agent instance from an agent ID
503
546
  */
504
- static create(agentIdOrDef: string | AgentDefinition, client: DistriClient): Promise<Agent>;
547
+ static create(agentIdOrDef: string | AgentConfigWithTools, client: DistriClient): Promise<Agent>;
505
548
  /**
506
549
  * Complete an external tool call by sending the result back to the server
507
550
  */
@@ -690,14 +733,18 @@ interface FileUrl {
690
733
  name?: string;
691
734
  }
692
735
  type FileType = FileBytes | FileUrl;
736
+ interface ToolDefinition {
737
+ name: string;
738
+ description: string;
739
+ parameters: object;
740
+ examples?: string;
741
+ output_schema?: object;
742
+ }
693
743
  /**
694
744
  * Tool definition interface following AG-UI pattern
695
745
  */
696
- interface DistriBaseTool {
697
- name: string;
746
+ interface DistriBaseTool extends ToolDefinition {
698
747
  type: 'function' | 'ui';
699
- description: string;
700
- parameters: object;
701
748
  is_final?: boolean;
702
749
  autoExecute?: boolean;
703
750
  isExternal?: boolean;
@@ -753,6 +800,10 @@ declare function createFailedToolResult(toolCallId: string, toolName: string, er
753
800
  * Handles both frontend DistriPart format and backend BackendPart format
754
801
  */
755
802
  declare function extractToolResultData(toolResult: ToolResult): ToolResultData | null;
803
+ interface AgentConfigWithTools extends AgentDefinition {
804
+ markdown?: string;
805
+ resolved_tools?: ToolDefinition[];
806
+ }
756
807
  /**
757
808
  * Distri-specific Agent type that wraps A2A AgentCard
758
809
  */
@@ -772,6 +823,8 @@ interface AgentDefinition {
772
823
  mcp_servers?: McpDefinition[];
773
824
  /** Settings related to the model used by the agent. */
774
825
  model_settings?: ModelSettings;
826
+ /** Secondary Model Settings used for analysis */
827
+ analysis_model_settings?: ModelSettings;
775
828
  /** The size of the history to maintain for the agent. */
776
829
  history_size?: number;
777
830
  /** The planning configuration for the agent, if any. */
@@ -782,10 +835,20 @@ interface AgentDefinition {
782
835
  skills?: AgentSkill[];
783
836
  /** List of sub-agents that this agent can transfer control to */
784
837
  sub_agents?: string[];
785
- agentType?: string;
786
838
  agent_type?: string;
839
+ context_size?: number;
787
840
  tools?: DistriBaseTool[];
788
841
  browser_config?: BrowserAgentConfig;
842
+ /** Agent usage statistics */
843
+ stats?: AgentStats;
844
+ }
845
+ /**
846
+ * Agent usage statistics
847
+ */
848
+ interface AgentStats {
849
+ thread_count: number;
850
+ sub_agent_usage_count: number;
851
+ last_used_at?: string | null;
789
852
  }
790
853
  interface BrowserAgentConfig {
791
854
  enabled?: boolean;
@@ -846,6 +909,9 @@ interface DistriThread {
846
909
  updated_at: string;
847
910
  message_count: number;
848
911
  last_message?: string;
912
+ user_id?: string;
913
+ external_id?: string;
914
+ tags?: string[];
849
915
  }
850
916
  interface Thread {
851
917
  id: string;
@@ -855,6 +921,48 @@ interface Thread {
855
921
  updated_at: string;
856
922
  message_count: number;
857
923
  last_message?: string;
924
+ user_id?: string;
925
+ external_id?: string;
926
+ tags?: string[];
927
+ }
928
+ /**
929
+ * Parameters for listing threads with filtering and pagination
930
+ */
931
+ interface ThreadListParams {
932
+ agent_id?: string;
933
+ external_id?: string;
934
+ search?: string;
935
+ from_date?: string;
936
+ to_date?: string;
937
+ tags?: string[];
938
+ limit?: number;
939
+ offset?: number;
940
+ }
941
+ /**
942
+ * Paginated response for thread listing
943
+ */
944
+ interface ThreadListResponse {
945
+ threads: DistriThread[];
946
+ total: number;
947
+ page: number;
948
+ page_size: number;
949
+ }
950
+ /**
951
+ * Agent usage information for sorting agents by thread count
952
+ */
953
+ interface AgentUsageInfo {
954
+ agent_id: string;
955
+ agent_name: string;
956
+ thread_count: number;
957
+ }
958
+ /**
959
+ * Browser session info returned when creating a session
960
+ */
961
+ interface BrowserSession {
962
+ session_id: string;
963
+ viewer_url?: string;
964
+ stream_url?: string;
965
+ frame_token?: string;
858
966
  }
859
967
  interface ChatProps {
860
968
  thread: Thread;
@@ -917,6 +1025,11 @@ interface DistriClientConfig {
917
1025
  * Request interceptor for modifying requests before sending
918
1026
  */
919
1027
  interceptor?: (init?: RequestInit) => Promise<RequestInit | undefined>;
1028
+ /**
1029
+ * Hook to refresh the access token when it expires.
1030
+ * Useful for public clients where only an access token is available.
1031
+ */
1032
+ onTokenRefresh?: () => Promise<string | null>;
920
1033
  /**
921
1034
  * Access token for bearer auth (optional)
922
1035
  */
@@ -930,12 +1043,9 @@ interface DistriClientConfig {
930
1043
  */
931
1044
  tokenRefreshSkewMs?: number;
932
1045
  /**
933
- * Callback invoked when tokens are refreshed
1046
+ * Client ID from Distri Cloud.
934
1047
  */
935
- onTokenRefresh?: (tokens: {
936
- accessToken: string;
937
- refreshToken: string;
938
- }) => void;
1048
+ clientId?: string;
939
1049
  }
940
1050
  interface LLMResponse {
941
1051
  finish_reason: string;
@@ -1046,4 +1156,4 @@ declare function extractToolCallsFromDistriMessage(message: DistriMessage): any[
1046
1156
  */
1047
1157
  declare function extractToolResultsFromDistriMessage(message: DistriMessage): any[];
1048
1158
 
1049
- export { A2AProtocolError, type A2AStreamEventData, type ActionPlanStep, Agent, type AgentDefinition, type AgentHandoverEvent, ApiError, type AssistantWithToolCalls, type BasePlanStep, type BatchToolCallsStep, type BrowserAgentConfig, type BrowserScreenshotEvent, type ChatCompletionChoice, type ChatCompletionMessage, type ChatCompletionRequest, type ChatCompletionResponse, type ChatCompletionResponseFormat, type ChatCompletionRole, type ChatProps, type CodePlanStep, type ConfigurationMeta, type ConfigurationResponse, ConnectionError, type ConnectionStatus, DEFAULT_BASE_URL, type DataPart, type DistriBaseTool, type DistriBrowserRuntimeConfig, type DistriChatMessage, DistriClient, type DistriClientConfig, type DistriConfiguration, DistriError, type DistriEvent, type DistriFnTool, type DistriMessage, type DistriPart, type DistriPlan, type DistriStreamEvent, type DistriThread, type ExternalMcpServer, type FeedbackReceivedEvent, type FileBytes, type FileType, type FileUrl, type FinalResultPlanStep, type HookContext, type HookHandler, type HookMutation, type ImagePart, type InlineHookEventData, type InlineHookRequest, type InlineHookRequestedEvent, type InvokeConfig, type InvokeContext, type InvokeResult, type LLMResponse, type LlmExecuteOptions, type LlmPlanStep, type McpDefinition, type McpServerType, type MessageRole, type ModelProviderConfig, type ModelProviderName, type ModelSettings, type PlanAction, type PlanFinishedEvent, type PlanPrunedEvent, type PlanStartedEvent, type PlanStep, type ReactStep, type Role, type RunErrorEvent, type RunFinishedEvent, type RunStartedEvent, type ServerConfig, type SpeechToTextConfig, type StepCompletedEvent, type StepStartedEvent, type StreamingTranscriptionOptions, type TextMessageContentEvent, type TextMessageEndEvent, type TextMessageStartEvent, type TextPart, type ThoughtPlanStep, type ThoughtStep, type Thread, type ToolCall, type ToolCallPart, type ToolCallsEvent, type ToolExecutionEndEvent, type ToolExecutionOptions, type ToolExecutionStartEvent, type ToolHandler, type ToolRejectedEvent, type ToolResult, type ToolResultData, type ToolResultRefPart, type ToolResults, type ToolResultsEvent, type UseToolsOptions, convertA2AMessageToDistri, convertA2APartToDistri, convertA2AStatusUpdateToDistri, convertDistriMessageToA2A, convertDistriPartToA2A, createFailedToolResult, createSuccessfulToolResult, decodeA2AStreamEvent, extractTextFromDistriMessage, extractToolCallsFromDistriMessage, extractToolResultData, extractToolResultsFromDistriMessage, isArrayParts, isDistriEvent, isDistriMessage, processA2AMessagesData, processA2AStreamData, uuidv4 };
1159
+ export { A2AProtocolError, type A2AStreamEventData, type ActionPlanStep, Agent, type AgentConfigWithTools, type AgentDefinition, type AgentHandoverEvent, type AgentStats, type AgentUsageInfo, ApiError, type AssistantWithToolCalls, type BasePlanStep, type BatchToolCallsStep, type BrowserAgentConfig, type BrowserScreenshotEvent, type BrowserSession, type BrowserSessionStartedEvent, type ChatCompletionChoice, type ChatCompletionMessage, type ChatCompletionRequest, type ChatCompletionResponse, type ChatCompletionResponseFormat, type ChatCompletionRole, type ChatProps, type CodePlanStep, type ConfigurationMeta, type ConfigurationResponse, ConnectionError, type ConnectionStatus, DEFAULT_BASE_URL, type DataPart, type DistriBaseTool, type DistriBrowserRuntimeConfig, type DistriChatMessage, DistriClient, type DistriClientConfig, type DistriConfiguration, DistriError, type DistriEvent, type DistriFnTool, type DistriMessage, type DistriPart, type DistriPlan, type DistriStreamEvent, type DistriThread, type ExternalMcpServer, ExternalToolValidationError, type ExternalToolValidationResult, type FeedbackReceivedEvent, type FileBytes, type FileType, type FileUrl, type FinalResultPlanStep, type HookContext, type HookHandler, type HookMutation, type ImagePart, type InlineHookEventData, type InlineHookRequest, type InlineHookRequestedEvent, type InvokeConfig, type InvokeContext, type InvokeResult, type LLMResponse, type LlmExecuteOptions, type LlmPlanStep, type McpDefinition, type McpServerType, type MessageRole, type ModelProviderConfig, type ModelProviderName, type ModelSettings, type PlanAction, type PlanFinishedEvent, type PlanPrunedEvent, type PlanStartedEvent, type PlanStep, type ReactStep, type Role, type RunErrorEvent, type RunFinishedEvent, type RunStartedEvent, type ServerConfig, type SpeechToTextConfig, type StepCompletedEvent, type StepStartedEvent, type StreamingTranscriptionOptions, type TextMessageContentEvent, type TextMessageEndEvent, type TextMessageStartEvent, type TextPart, type ThoughtPlanStep, type ThoughtStep, type Thread, type ThreadListParams, type ThreadListResponse, type ToolCall, type ToolCallPart, type ToolCallsEvent, type ToolDefinition, type ToolExecutionEndEvent, type ToolExecutionOptions, type ToolExecutionStartEvent, type ToolHandler, type ToolRejectedEvent, type ToolResult, type ToolResultData, type ToolResultRefPart, type ToolResults, type ToolResultsEvent, type UseToolsOptions, convertA2AMessageToDistri, convertA2APartToDistri, convertA2AStatusUpdateToDistri, convertDistriMessageToA2A, convertDistriPartToA2A, createFailedToolResult, createSuccessfulToolResult, decodeA2AStreamEvent, extractTextFromDistriMessage, extractToolCallsFromDistriMessage, extractToolResultData, extractToolResultsFromDistriMessage, isArrayParts, isDistriEvent, isDistriMessage, processA2AMessagesData, processA2AStreamData, uuidv4 };