@distri/core 0.3.0 → 0.3.1

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.ts CHANGED
@@ -143,14 +143,6 @@ 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
- }
154
146
  interface InlineHookRequestedEvent {
155
147
  type: 'inline_hook_requested';
156
148
  data: {
@@ -169,7 +161,7 @@ interface InlineHookRequestedEvent {
169
161
  result?: any;
170
162
  };
171
163
  }
172
- type DistriEvent = RunStartedEvent | RunFinishedEvent | RunErrorEvent | PlanStartedEvent | PlanFinishedEvent | PlanPrunedEvent | TextMessageStartEvent | TextMessageContentEvent | TextMessageEndEvent | ToolExecutionStartEvent | ToolExecutionEndEvent | ToolRejectedEvent | StepStartedEvent | StepCompletedEvent | AgentHandoverEvent | FeedbackReceivedEvent | ToolCallsEvent | ToolResultsEvent | BrowserScreenshotEvent | BrowserSessionStartedEvent | InlineHookRequestedEvent;
164
+ type DistriEvent = RunStartedEvent | RunFinishedEvent | RunErrorEvent | PlanStartedEvent | PlanFinishedEvent | PlanPrunedEvent | TextMessageStartEvent | TextMessageContentEvent | TextMessageEndEvent | ToolExecutionStartEvent | ToolExecutionEndEvent | ToolRejectedEvent | StepStartedEvent | StepCompletedEvent | AgentHandoverEvent | FeedbackReceivedEvent | ToolCallsEvent | ToolResultsEvent | BrowserScreenshotEvent | InlineHookRequestedEvent;
173
165
 
174
166
  type ChatCompletionRole = 'system' | 'user' | 'assistant' | 'tool';
175
167
  interface ChatCompletionMessage {
@@ -231,14 +223,6 @@ declare class DistriClient {
231
223
  private refreshPromise?;
232
224
  private agentClients;
233
225
  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
226
  /**
243
227
  * Create a client with default cloud configuration.
244
228
  *
@@ -273,6 +257,25 @@ declare class DistriClient {
273
257
  * Session store: clear all keys in a session
274
258
  */
275
259
  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>;
276
279
  /**
277
280
  * Response from the token endpoint
278
281
  */
@@ -312,10 +315,6 @@ declare class DistriClient {
312
315
  accessToken?: string;
313
316
  refreshToken?: string;
314
317
  }): void;
315
- /**
316
- * Reset all authentication tokens.
317
- */
318
- resetTokens(): void;
319
318
  /**
320
319
  * Start streaming speech-to-text transcription via WebSocket
321
320
  */
@@ -342,13 +341,7 @@ declare class DistriClient {
342
341
  /**
343
342
  * Get specific agent by ID
344
343
  */
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>;
344
+ getAgent(agentId: string): Promise<AgentDefinition>;
352
345
  /**
353
346
  * Get or create A2AClient for an agent
354
347
  */
@@ -370,18 +363,9 @@ declare class DistriClient {
370
363
  */
371
364
  cancelTask(agentId: string, taskId: string): Promise<void>;
372
365
  /**
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
366
+ * Get threads from Distri server
383
367
  */
384
- createBrowserSession(): Promise<BrowserSession>;
368
+ getThreads(): Promise<DistriThread[]>;
385
369
  getThread(threadId: string): Promise<DistriThread>;
386
370
  /**
387
371
  * Get thread messages
@@ -408,9 +392,6 @@ declare class DistriClient {
408
392
  */
409
393
  get baseUrl(): string;
410
394
  private applyTokens;
411
- /**
412
- * Ensure access token is valid, refreshing if necessary
413
- */
414
395
  private ensureAccessToken;
415
396
  private refreshTokens;
416
397
  private performTokenRefresh;
@@ -424,10 +405,9 @@ declare class DistriClient {
424
405
  */
425
406
  private fetchAbsolute;
426
407
  /**
427
- * Enhanced fetch with retry logic and auth headers.
428
- * Exposed publicly for extensions like DistriHomeClient.
408
+ * Enhanced fetch with retry logic
429
409
  */
430
- fetch(input: RequestInfo | URL, initialInit?: RequestInit): Promise<Response>;
410
+ private fetch;
431
411
  /**
432
412
  * Delay utility
433
413
  */
@@ -477,20 +457,6 @@ interface InvokeResult {
477
457
  /** Whether the response was streamed */
478
458
  streamed: boolean;
479
459
  }
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
- }
494
460
  /**
495
461
  * Enhanced Agent class with simple tool system following AG-UI pattern
496
462
  */
@@ -499,7 +465,7 @@ declare class Agent {
499
465
  private agentDefinition;
500
466
  private hookHandlers;
501
467
  private defaultHookHandler;
502
- constructor(agentDefinition: AgentConfigWithTools, client: DistriClient);
468
+ constructor(agentDefinition: AgentDefinition, client: DistriClient);
503
469
  /**
504
470
  * Get agent information
505
471
  */
@@ -511,7 +477,7 @@ declare class Agent {
511
477
  /**
512
478
  * Get the full agent definition (including backend tools)
513
479
  */
514
- getDefinition(): AgentConfigWithTools;
480
+ getDefinition(): AgentDefinition;
515
481
  /**
516
482
  * Fetch messages for a thread (public method for useChat)
517
483
  */
@@ -524,19 +490,10 @@ declare class Agent {
524
490
  * Streaming invoke
525
491
  */
526
492
  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;
531
493
  /**
532
494
  * Enhance message params with tool definitions
533
495
  */
534
496
  private enhanceParamsWithTools;
535
- private assertExternalTools;
536
- private getRequiredExternalTools;
537
- private resolveToolConfig;
538
- private extractToolConfig;
539
- private formatExternalToolValidationMessage;
540
497
  /**
541
498
  * Register multiple hooks at once.
542
499
  */
@@ -544,7 +501,7 @@ declare class Agent {
544
501
  /**
545
502
  * Create an agent instance from an agent ID
546
503
  */
547
- static create(agentIdOrDef: string | AgentConfigWithTools, client: DistriClient): Promise<Agent>;
504
+ static create(agentIdOrDef: string | AgentDefinition, client: DistriClient): Promise<Agent>;
548
505
  /**
549
506
  * Complete an external tool call by sending the result back to the server
550
507
  */
@@ -733,18 +690,14 @@ interface FileUrl {
733
690
  name?: string;
734
691
  }
735
692
  type FileType = FileBytes | FileUrl;
736
- interface ToolDefinition {
737
- name: string;
738
- description: string;
739
- parameters: object;
740
- examples?: string;
741
- output_schema?: object;
742
- }
743
693
  /**
744
694
  * Tool definition interface following AG-UI pattern
745
695
  */
746
- interface DistriBaseTool extends ToolDefinition {
696
+ interface DistriBaseTool {
697
+ name: string;
747
698
  type: 'function' | 'ui';
699
+ description: string;
700
+ parameters: object;
748
701
  is_final?: boolean;
749
702
  autoExecute?: boolean;
750
703
  isExternal?: boolean;
@@ -800,10 +753,6 @@ declare function createFailedToolResult(toolCallId: string, toolName: string, er
800
753
  * Handles both frontend DistriPart format and backend BackendPart format
801
754
  */
802
755
  declare function extractToolResultData(toolResult: ToolResult): ToolResultData | null;
803
- interface AgentConfigWithTools extends AgentDefinition {
804
- markdown?: string;
805
- resolved_tools?: ToolDefinition[];
806
- }
807
756
  /**
808
757
  * Distri-specific Agent type that wraps A2A AgentCard
809
758
  */
@@ -823,8 +772,6 @@ interface AgentDefinition {
823
772
  mcp_servers?: McpDefinition[];
824
773
  /** Settings related to the model used by the agent. */
825
774
  model_settings?: ModelSettings;
826
- /** Secondary Model Settings used for analysis */
827
- analysis_model_settings?: ModelSettings;
828
775
  /** The size of the history to maintain for the agent. */
829
776
  history_size?: number;
830
777
  /** The planning configuration for the agent, if any. */
@@ -835,20 +782,10 @@ interface AgentDefinition {
835
782
  skills?: AgentSkill[];
836
783
  /** List of sub-agents that this agent can transfer control to */
837
784
  sub_agents?: string[];
785
+ agentType?: string;
838
786
  agent_type?: string;
839
- context_size?: number;
840
787
  tools?: DistriBaseTool[];
841
788
  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;
852
789
  }
853
790
  interface BrowserAgentConfig {
854
791
  enabled?: boolean;
@@ -909,9 +846,6 @@ interface DistriThread {
909
846
  updated_at: string;
910
847
  message_count: number;
911
848
  last_message?: string;
912
- user_id?: string;
913
- external_id?: string;
914
- tags?: string[];
915
849
  }
916
850
  interface Thread {
917
851
  id: string;
@@ -921,49 +855,6 @@ interface Thread {
921
855
  updated_at: string;
922
856
  message_count: number;
923
857
  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
- /** SSE stream URL (backend API) for event streaming */
964
- sse_url?: string;
965
- /** Frame URL for embedding (frontend app with token) */
966
- frame_url?: string;
967
858
  }
968
859
  interface ChatProps {
969
860
  thread: Thread;
@@ -1026,11 +917,6 @@ interface DistriClientConfig {
1026
917
  * Request interceptor for modifying requests before sending
1027
918
  */
1028
919
  interceptor?: (init?: RequestInit) => Promise<RequestInit | undefined>;
1029
- /**
1030
- * Hook to refresh the access token when it expires.
1031
- * Useful for public clients where only an access token is available.
1032
- */
1033
- onTokenRefresh?: () => Promise<string | null>;
1034
920
  /**
1035
921
  * Access token for bearer auth (optional)
1036
922
  */
@@ -1044,9 +930,12 @@ interface DistriClientConfig {
1044
930
  */
1045
931
  tokenRefreshSkewMs?: number;
1046
932
  /**
1047
- * Client ID from Distri Cloud.
933
+ * Callback invoked when tokens are refreshed
1048
934
  */
1049
- clientId?: string;
935
+ onTokenRefresh?: (tokens: {
936
+ accessToken: string;
937
+ refreshToken: string;
938
+ }) => void;
1050
939
  }
1051
940
  interface LLMResponse {
1052
941
  finish_reason: string;
@@ -1157,4 +1046,4 @@ declare function extractToolCallsFromDistriMessage(message: DistriMessage): any[
1157
1046
  */
1158
1047
  declare function extractToolResultsFromDistriMessage(message: DistriMessage): any[];
1159
1048
 
1160
- 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 };
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 };