@distri/core 0.3.1 → 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/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,23 @@ 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);
242
+ /**
243
+ * Get the configured workspace ID.
244
+ */
245
+ get workspaceId(): string | undefined;
246
+ /**
247
+ * Set the workspace ID for multi-tenant support.
248
+ * Updates the X-Workspace-Id header for all subsequent requests.
249
+ */
250
+ set workspaceId(value: string | undefined);
226
251
  /**
227
252
  * Create a client with default cloud configuration.
228
253
  *
@@ -257,25 +282,6 @@ declare class DistriClient {
257
282
  * Session store: clear all keys in a session
258
283
  */
259
284
  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
285
  /**
280
286
  * Response from the token endpoint
281
287
  */
@@ -315,6 +321,10 @@ declare class DistriClient {
315
321
  accessToken?: string;
316
322
  refreshToken?: string;
317
323
  }): void;
324
+ /**
325
+ * Reset all authentication tokens.
326
+ */
327
+ resetTokens(): void;
318
328
  /**
319
329
  * Start streaming speech-to-text transcription via WebSocket
320
330
  */
@@ -341,7 +351,13 @@ declare class DistriClient {
341
351
  /**
342
352
  * Get specific agent by ID
343
353
  */
344
- getAgent(agentId: string): Promise<AgentDefinition>;
354
+ getAgent(agentId: string): Promise<AgentConfigWithTools>;
355
+ /**
356
+ * Update an agent's definition (markdown only)
357
+ */
358
+ updateAgent(agentId: string, update: {
359
+ markdown: string;
360
+ }): Promise<AgentConfigWithTools>;
345
361
  /**
346
362
  * Get or create A2AClient for an agent
347
363
  */
@@ -354,6 +370,10 @@ declare class DistriClient {
354
370
  * Send a streaming message to an agent
355
371
  */
356
372
  sendMessageStream(agentId: string, params: MessageSendParams): AsyncGenerator<A2AStreamEventData>;
373
+ /**
374
+ * Extract a user-friendly error message from potentially nested errors
375
+ */
376
+ private extractErrorMessage;
357
377
  /**
358
378
  * Get task details
359
379
  */
@@ -363,9 +383,18 @@ declare class DistriClient {
363
383
  */
364
384
  cancelTask(agentId: string, taskId: string): Promise<void>;
365
385
  /**
366
- * Get threads from Distri server
386
+ * Get threads from Distri server with filtering and pagination
387
+ */
388
+ getThreads(params?: ThreadListParams): Promise<ThreadListResponse>;
389
+ /**
390
+ * Get agents sorted by thread count (most active first)
391
+ */
392
+ getAgentsByUsage(): Promise<AgentUsageInfo[]>;
393
+ /**
394
+ * Create a new browser session
395
+ * Returns session info including viewer_url and stream_url from browsr
367
396
  */
368
- getThreads(): Promise<DistriThread[]>;
397
+ createBrowserSession(): Promise<BrowserSession>;
369
398
  getThread(threadId: string): Promise<DistriThread>;
370
399
  /**
371
400
  * Get thread messages
@@ -392,6 +421,9 @@ declare class DistriClient {
392
421
  */
393
422
  get baseUrl(): string;
394
423
  private applyTokens;
424
+ /**
425
+ * Ensure access token is valid, refreshing if necessary
426
+ */
395
427
  private ensureAccessToken;
396
428
  private refreshTokens;
397
429
  private performTokenRefresh;
@@ -405,9 +437,10 @@ declare class DistriClient {
405
437
  */
406
438
  private fetchAbsolute;
407
439
  /**
408
- * Enhanced fetch with retry logic
440
+ * Enhanced fetch with retry logic and auth headers.
441
+ * Exposed publicly for extensions like DistriHomeClient.
409
442
  */
410
- private fetch;
443
+ fetch(input: RequestInfo | URL, initialInit?: RequestInit): Promise<Response>;
411
444
  /**
412
445
  * Delay utility
413
446
  */
@@ -457,6 +490,20 @@ interface InvokeResult {
457
490
  /** Whether the response was streamed */
458
491
  streamed: boolean;
459
492
  }
493
+ interface ExternalToolValidationResult {
494
+ isValid: boolean;
495
+ requiredTools: string[];
496
+ providedTools: string[];
497
+ missingTools: string[];
498
+ message?: string;
499
+ }
500
+ declare class ExternalToolValidationError extends DistriError {
501
+ missingTools: string[];
502
+ requiredTools: string[];
503
+ providedTools: string[];
504
+ agentName: string;
505
+ constructor(agentName: string, result: ExternalToolValidationResult);
506
+ }
460
507
  /**
461
508
  * Enhanced Agent class with simple tool system following AG-UI pattern
462
509
  */
@@ -465,7 +512,7 @@ declare class Agent {
465
512
  private agentDefinition;
466
513
  private hookHandlers;
467
514
  private defaultHookHandler;
468
- constructor(agentDefinition: AgentDefinition, client: DistriClient);
515
+ constructor(agentDefinition: AgentConfigWithTools, client: DistriClient);
469
516
  /**
470
517
  * Get agent information
471
518
  */
@@ -477,7 +524,7 @@ declare class Agent {
477
524
  /**
478
525
  * Get the full agent definition (including backend tools)
479
526
  */
480
- getDefinition(): AgentDefinition;
527
+ getDefinition(): AgentConfigWithTools;
481
528
  /**
482
529
  * Fetch messages for a thread (public method for useChat)
483
530
  */
@@ -490,10 +537,19 @@ declare class Agent {
490
537
  * Streaming invoke
491
538
  */
492
539
  invokeStream(params: MessageSendParams, tools?: DistriBaseTool[], hooks?: Record<string, HookHandler>): Promise<AsyncGenerator<DistriChatMessage>>;
540
+ /**
541
+ * Validate that required external tools are registered before invoking.
542
+ */
543
+ validateExternalTools(tools?: DistriBaseTool[]): ExternalToolValidationResult;
493
544
  /**
494
545
  * Enhance message params with tool definitions
495
546
  */
496
547
  private enhanceParamsWithTools;
548
+ private assertExternalTools;
549
+ private getRequiredExternalTools;
550
+ private resolveToolConfig;
551
+ private extractToolConfig;
552
+ private formatExternalToolValidationMessage;
497
553
  /**
498
554
  * Register multiple hooks at once.
499
555
  */
@@ -501,7 +557,7 @@ declare class Agent {
501
557
  /**
502
558
  * Create an agent instance from an agent ID
503
559
  */
504
- static create(agentIdOrDef: string | AgentDefinition, client: DistriClient): Promise<Agent>;
560
+ static create(agentIdOrDef: string | AgentConfigWithTools, client: DistriClient): Promise<Agent>;
505
561
  /**
506
562
  * Complete an external tool call by sending the result back to the server
507
563
  */
@@ -515,7 +571,7 @@ declare class Agent {
515
571
  /**
516
572
  * Message roles supported by Distri
517
573
  */
518
- type MessageRole = 'system' | 'assistant' | 'user' | 'tool';
574
+ type MessageRole = 'system' | 'assistant' | 'user' | 'tool' | 'developer';
519
575
  /**
520
576
  * Distri-specific message structure with parts
521
577
  */
@@ -690,14 +746,18 @@ interface FileUrl {
690
746
  name?: string;
691
747
  }
692
748
  type FileType = FileBytes | FileUrl;
749
+ interface ToolDefinition {
750
+ name: string;
751
+ description: string;
752
+ parameters: object;
753
+ examples?: string;
754
+ output_schema?: object;
755
+ }
693
756
  /**
694
757
  * Tool definition interface following AG-UI pattern
695
758
  */
696
- interface DistriBaseTool {
697
- name: string;
759
+ interface DistriBaseTool extends ToolDefinition {
698
760
  type: 'function' | 'ui';
699
- description: string;
700
- parameters: object;
701
761
  is_final?: boolean;
702
762
  autoExecute?: boolean;
703
763
  isExternal?: boolean;
@@ -753,6 +813,10 @@ declare function createFailedToolResult(toolCallId: string, toolName: string, er
753
813
  * Handles both frontend DistriPart format and backend BackendPart format
754
814
  */
755
815
  declare function extractToolResultData(toolResult: ToolResult): ToolResultData | null;
816
+ interface AgentConfigWithTools extends AgentDefinition {
817
+ markdown?: string;
818
+ resolved_tools?: ToolDefinition[];
819
+ }
756
820
  /**
757
821
  * Distri-specific Agent type that wraps A2A AgentCard
758
822
  */
@@ -772,6 +836,8 @@ interface AgentDefinition {
772
836
  mcp_servers?: McpDefinition[];
773
837
  /** Settings related to the model used by the agent. */
774
838
  model_settings?: ModelSettings;
839
+ /** Secondary Model Settings used for analysis */
840
+ analysis_model_settings?: ModelSettings;
775
841
  /** The size of the history to maintain for the agent. */
776
842
  history_size?: number;
777
843
  /** The planning configuration for the agent, if any. */
@@ -782,10 +848,20 @@ interface AgentDefinition {
782
848
  skills?: AgentSkill[];
783
849
  /** List of sub-agents that this agent can transfer control to */
784
850
  sub_agents?: string[];
785
- agentType?: string;
786
851
  agent_type?: string;
852
+ context_size?: number;
787
853
  tools?: DistriBaseTool[];
788
854
  browser_config?: BrowserAgentConfig;
855
+ /** Agent usage statistics */
856
+ stats?: AgentStats;
857
+ }
858
+ /**
859
+ * Agent usage statistics
860
+ */
861
+ interface AgentStats {
862
+ thread_count: number;
863
+ sub_agent_usage_count: number;
864
+ last_used_at?: string | null;
789
865
  }
790
866
  interface BrowserAgentConfig {
791
867
  enabled?: boolean;
@@ -846,6 +922,9 @@ interface DistriThread {
846
922
  updated_at: string;
847
923
  message_count: number;
848
924
  last_message?: string;
925
+ user_id?: string;
926
+ external_id?: string;
927
+ tags?: string[];
849
928
  }
850
929
  interface Thread {
851
930
  id: string;
@@ -855,6 +934,48 @@ interface Thread {
855
934
  updated_at: string;
856
935
  message_count: number;
857
936
  last_message?: string;
937
+ user_id?: string;
938
+ external_id?: string;
939
+ tags?: string[];
940
+ }
941
+ /**
942
+ * Parameters for listing threads with filtering and pagination
943
+ */
944
+ interface ThreadListParams {
945
+ agent_id?: string;
946
+ external_id?: string;
947
+ search?: string;
948
+ from_date?: string;
949
+ to_date?: string;
950
+ tags?: string[];
951
+ limit?: number;
952
+ offset?: number;
953
+ }
954
+ /**
955
+ * Paginated response for thread listing
956
+ */
957
+ interface ThreadListResponse {
958
+ threads: DistriThread[];
959
+ total: number;
960
+ page: number;
961
+ page_size: number;
962
+ }
963
+ /**
964
+ * Agent usage information for sorting agents by thread count
965
+ */
966
+ interface AgentUsageInfo {
967
+ agent_id: string;
968
+ agent_name: string;
969
+ thread_count: number;
970
+ }
971
+ /**
972
+ * Browser session info returned when creating a session
973
+ */
974
+ interface BrowserSession {
975
+ session_id: string;
976
+ viewer_url?: string;
977
+ stream_url?: string;
978
+ frame_token?: string;
858
979
  }
859
980
  interface ChatProps {
860
981
  thread: Thread;
@@ -917,6 +1038,11 @@ interface DistriClientConfig {
917
1038
  * Request interceptor for modifying requests before sending
918
1039
  */
919
1040
  interceptor?: (init?: RequestInit) => Promise<RequestInit | undefined>;
1041
+ /**
1042
+ * Hook to refresh the access token when it expires.
1043
+ * Useful for public clients where only an access token is available.
1044
+ */
1045
+ onTokenRefresh?: () => Promise<string | null>;
920
1046
  /**
921
1047
  * Access token for bearer auth (optional)
922
1048
  */
@@ -930,12 +1056,14 @@ interface DistriClientConfig {
930
1056
  */
931
1057
  tokenRefreshSkewMs?: number;
932
1058
  /**
933
- * Callback invoked when tokens are refreshed
1059
+ * Client ID from Distri Cloud.
1060
+ */
1061
+ clientId?: string;
1062
+ /**
1063
+ * Workspace ID for multi-tenant support (Distri Cloud).
1064
+ * When provided, all requests will include X-Workspace-Id header.
934
1065
  */
935
- onTokenRefresh?: (tokens: {
936
- accessToken: string;
937
- refreshToken: string;
938
- }) => void;
1066
+ workspaceId?: string;
939
1067
  }
940
1068
  interface LLMResponse {
941
1069
  finish_reason: string;
@@ -1046,4 +1174,4 @@ declare function extractToolCallsFromDistriMessage(message: DistriMessage): any[
1046
1174
  */
1047
1175
  declare function extractToolResultsFromDistriMessage(message: DistriMessage): any[];
1048
1176
 
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 };
1177
+ 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 };