@distri/core 0.3.2 → 0.3.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/dist/index.d.mts CHANGED
@@ -169,7 +169,23 @@ interface InlineHookRequestedEvent {
169
169
  result?: any;
170
170
  };
171
171
  }
172
- type DistriEvent = RunStartedEvent | RunFinishedEvent | RunErrorEvent | PlanStartedEvent | PlanFinishedEvent | PlanPrunedEvent | TextMessageStartEvent | TextMessageContentEvent | TextMessageEndEvent | ToolExecutionStartEvent | ToolExecutionEndEvent | ToolRejectedEvent | StepStartedEvent | StepCompletedEvent | AgentHandoverEvent | FeedbackReceivedEvent | ToolCallsEvent | ToolResultsEvent | BrowserScreenshotEvent | BrowserSessionStartedEvent | InlineHookRequestedEvent;
172
+ type TodoStatus = 'open' | 'in_progress' | 'done';
173
+ interface TodoItem {
174
+ id: string;
175
+ content: string;
176
+ status: TodoStatus;
177
+ }
178
+ interface TodosUpdatedEvent {
179
+ type: 'todos_updated';
180
+ data: {
181
+ formatted_todos: string;
182
+ action: string;
183
+ todo_count: number;
184
+ /** Parsed todo items for rendering */
185
+ todos?: TodoItem[];
186
+ };
187
+ }
188
+ type DistriEvent = RunStartedEvent | RunFinishedEvent | RunErrorEvent | PlanStartedEvent | PlanFinishedEvent | PlanPrunedEvent | TextMessageStartEvent | TextMessageContentEvent | TextMessageEndEvent | ToolExecutionStartEvent | ToolExecutionEndEvent | ToolRejectedEvent | StepStartedEvent | StepCompletedEvent | AgentHandoverEvent | FeedbackReceivedEvent | ToolCallsEvent | ToolResultsEvent | BrowserScreenshotEvent | BrowserSessionStartedEvent | InlineHookRequestedEvent | TodosUpdatedEvent;
173
189
 
174
190
  type ChatCompletionRole = 'system' | 'user' | 'assistant' | 'tool';
175
191
  interface ChatCompletionMessage {
@@ -239,6 +255,15 @@ declare class DistriClient {
239
255
  * Set the client ID for embed token issuance.
240
256
  */
241
257
  set clientId(value: string | undefined);
258
+ /**
259
+ * Get the configured workspace ID.
260
+ */
261
+ get workspaceId(): string | undefined;
262
+ /**
263
+ * Set the workspace ID for multi-tenant support.
264
+ * Updates the X-Workspace-Id header for all subsequent requests.
265
+ */
266
+ set workspaceId(value: string | undefined);
242
267
  /**
243
268
  * Create a client with default cloud configuration.
244
269
  *
@@ -334,7 +359,7 @@ declare class DistriClient {
334
359
  /**
335
360
  * Minimal LLM helper that proxies to the Distri server using Distri messages.
336
361
  */
337
- llm(messages: DistriMessage[], tools?: unknown[], options?: LlmExecuteOptions): Promise<LLMResponse>;
362
+ llm(messages: DistriMessage[], tools?: ToolDefinition[], options?: LlmExecuteOptions): Promise<LLMResponse>;
338
363
  /**
339
364
  * Get all available agents from the Distri server
340
365
  */
@@ -361,6 +386,10 @@ declare class DistriClient {
361
386
  * Send a streaming message to an agent
362
387
  */
363
388
  sendMessageStream(agentId: string, params: MessageSendParams): AsyncGenerator<A2AStreamEventData>;
389
+ /**
390
+ * Extract a user-friendly error message from potentially nested errors
391
+ */
392
+ private extractErrorMessage;
364
393
  /**
365
394
  * Get task details
366
395
  */
@@ -374,9 +403,13 @@ declare class DistriClient {
374
403
  */
375
404
  getThreads(params?: ThreadListParams): Promise<ThreadListResponse>;
376
405
  /**
377
- * Get agents sorted by thread count (most active first)
406
+ * Get agents sorted by thread count (most active first).
407
+ * Includes all registered agents, even those with 0 threads.
408
+ * Optionally filter by name with search parameter.
378
409
  */
379
- getAgentsByUsage(): Promise<AgentUsageInfo[]>;
410
+ getAgentsByUsage(options?: {
411
+ search?: string;
412
+ }): Promise<AgentUsageInfo[]>;
380
413
  /**
381
414
  * Create a new browser session
382
415
  * Returns session info including viewer_url and stream_url from browsr
@@ -391,6 +424,35 @@ declare class DistriClient {
391
424
  * Get messages from a thread as DistriMessage format
392
425
  */
393
426
  getThreadMessagesAsDistri(threadId: string): Promise<DistriMessage[]>;
427
+ /**
428
+ * Mark a message as read
429
+ */
430
+ markMessageRead(threadId: string, messageId: string): Promise<MessageReadStatus>;
431
+ /**
432
+ * Get read status for a specific message
433
+ */
434
+ getMessageReadStatus(threadId: string, messageId: string): Promise<MessageReadStatus | null>;
435
+ /**
436
+ * Get read status for all messages in a thread
437
+ */
438
+ getThreadReadStatus(threadId: string): Promise<MessageReadStatus[]>;
439
+ /**
440
+ * Vote on a message (upvote or downvote)
441
+ * Downvotes require a comment explaining the issue
442
+ */
443
+ voteMessage(threadId: string, messageId: string, request: VoteMessageRequest): Promise<MessageVote>;
444
+ /**
445
+ * Remove vote from a message
446
+ */
447
+ removeVote(threadId: string, messageId: string): Promise<void>;
448
+ /**
449
+ * Get vote summary for a message (counts + current user's vote)
450
+ */
451
+ getMessageVoteSummary(threadId: string, messageId: string): Promise<MessageVoteSummary>;
452
+ /**
453
+ * Get all votes for a message (admin/analytics use)
454
+ */
455
+ getMessageVotes(threadId: string, messageId: string): Promise<MessageVote[]>;
394
456
  /**
395
457
  * Send a DistriMessage to a thread
396
458
  */
@@ -445,13 +507,19 @@ declare class DistriClient {
445
507
  */
446
508
  static initDistriMessage(role: DistriMessage['role'], parts: DistriPart[], id?: string, created_at?: number): DistriMessage;
447
509
  /**
448
- * Helper method to create message send parameters
510
+ * Helper method to create message send parameters.
511
+ *
512
+ * Pass `dynamicMetadata` to inject `dynamic_sections` and/or `dynamic_values`
513
+ * into the metadata so the server can apply them to prompt templates.
449
514
  */
450
- static initMessageParams(message: Message, configuration?: MessageSendParams['configuration'], metadata?: any): MessageSendParams;
515
+ static initMessageParams(message: Message, configuration?: MessageSendParams['configuration'], metadata?: any, dynamicMetadata?: DynamicMetadata): MessageSendParams;
451
516
  /**
452
- * Create MessageSendParams from a DistriMessage using InvokeContext
517
+ * Create MessageSendParams from a DistriMessage using InvokeContext.
518
+ *
519
+ * Pass `dynamicMetadata` to inject `dynamic_sections` and/or `dynamic_values`
520
+ * into the metadata so the server can apply them to prompt templates.
453
521
  */
454
- static initDistriMessageParams(message: DistriMessage, context: InvokeContext): MessageSendParams;
522
+ static initDistriMessageParams(message: DistriMessage, context: InvokeContext, dynamicMetadata?: DynamicMetadata): MessageSendParams;
455
523
  }
456
524
  declare function uuidv4(): string;
457
525
 
@@ -465,6 +533,14 @@ interface InvokeConfig {
465
533
  contextId?: string;
466
534
  /** Metadata for the requests */
467
535
  metadata?: any;
536
+ /** Dynamic prompt sections injected into the template per-call */
537
+ dynamic_sections?: DynamicMetadata['dynamic_sections'];
538
+ /** Dynamic key-value pairs available in templates per-call */
539
+ dynamic_values?: DynamicMetadata['dynamic_values'];
540
+ /** Per-part metadata indexed by part position (0-based).
541
+ * Use to control which parts are saved to the database.
542
+ * Parts with `save: false` will be filtered out before saving. */
543
+ parts?: DynamicMetadata['parts'];
468
544
  }
469
545
  /**
470
546
  * Result from agent invoke
@@ -529,7 +605,10 @@ declare class Agent {
529
605
  */
530
606
  validateExternalTools(tools?: DistriBaseTool[]): ExternalToolValidationResult;
531
607
  /**
532
- * Enhance message params with tool definitions
608
+ * Enhance message params with tool definitions and dynamic metadata.
609
+ *
610
+ * When `dynamic_sections` or `dynamic_values` are present in `params.metadata`,
611
+ * they are forwarded so the server injects them into the prompt template.
533
612
  */
534
613
  private enhanceParamsWithTools;
535
614
  private assertExternalTools;
@@ -558,7 +637,27 @@ declare class Agent {
558
637
  /**
559
638
  * Message roles supported by Distri
560
639
  */
561
- type MessageRole = 'system' | 'assistant' | 'user' | 'tool';
640
+ type MessageRole = 'system' | 'assistant' | 'user' | 'tool' | 'developer';
641
+ /**
642
+ * Message metadata structure that matches the backend.
643
+ * The 'parts' field maps part indices to PartMetadata for save filtering.
644
+ */
645
+ interface DistriMessageMetadata {
646
+ /** Per-part metadata indexed by part position (0-based). Parts with save: false are filtered before DB save. */
647
+ parts?: Record<number, {
648
+ save?: boolean;
649
+ }>;
650
+ /** Session ID for browser sessions */
651
+ session_id?: string;
652
+ /** Browser session ID */
653
+ browser_session_id?: string;
654
+ /** Model/definition overrides */
655
+ definition_overrides?: {
656
+ model?: string;
657
+ };
658
+ /** Additional arbitrary metadata */
659
+ [key: string]: unknown;
660
+ }
562
661
  /**
563
662
  * Distri-specific message structure with parts
564
663
  */
@@ -569,6 +668,12 @@ interface DistriMessage {
569
668
  created_at: number;
570
669
  step_id?: string;
571
670
  is_final?: boolean;
671
+ /** The ID of the agent that generated this message (for assistant messages) */
672
+ agent_id?: string;
673
+ /** The name of the agent that generated this message (for assistant messages) */
674
+ agent_name?: string;
675
+ /** Message metadata including parts metadata for save filtering */
676
+ metadata?: DistriMessageMetadata;
572
677
  }
573
678
  interface LlmExecuteOptions {
574
679
  thread_id?: string;
@@ -576,6 +681,11 @@ interface LlmExecuteOptions {
576
681
  run_id?: string;
577
682
  model_settings?: any;
578
683
  is_sub_task?: boolean;
684
+ headers?: Record<string, string>;
685
+ agent_id?: string;
686
+ external_id?: string;
687
+ load_history?: boolean;
688
+ title?: string;
579
689
  }
580
690
  interface AssistantWithToolCalls {
581
691
  id: string;
@@ -684,6 +794,36 @@ interface ReactStep extends BasePlanStep {
684
794
  action: string;
685
795
  }
686
796
  type DistriStreamEvent = DistriMessage | DistriEvent;
797
+ /**
798
+ * A named prompt section that can be dynamically injected into templates per-call.
799
+ */
800
+ interface PromptSection {
801
+ key: string;
802
+ content: string;
803
+ }
804
+ /**
805
+ * Metadata for individual message parts.
806
+ * Used to control part behavior such as persistence.
807
+ */
808
+ interface PartMetadata {
809
+ /** If false, this part will be filtered out before saving to the database.
810
+ * Useful for ephemeral/dynamic content that should only be sent in the current turn.
811
+ * Defaults to true. */
812
+ save?: boolean;
813
+ }
814
+ /**
815
+ * Dynamic metadata that can be provided per invoke call to customise
816
+ * prompt template rendering on the server.
817
+ */
818
+ interface DynamicMetadata {
819
+ /** Dynamic prompt sections injected into the template per-call */
820
+ dynamic_sections?: PromptSection[];
821
+ /** Dynamic key-value pairs available in templates per-call */
822
+ dynamic_values?: Record<string, unknown>;
823
+ /** Per-part metadata indexed by part position (0-based).
824
+ * Parts not listed will use default metadata (save: true). */
825
+ parts?: Record<number, PartMetadata>;
826
+ }
687
827
  /**
688
828
  * Context required for constructing A2A messages from DistriMessage
689
829
  */
@@ -718,12 +858,12 @@ type DataPart = {
718
858
  };
719
859
  type DistriPart = TextPart | ToolCallPart | ToolResultRefPart | ImagePart | DataPart;
720
860
  /**
721
- * File type for images
861
+ * File type for images - matches Rust FileType::Bytes
722
862
  */
723
863
  interface FileBytes {
724
864
  type: 'bytes';
725
865
  mime_type: string;
726
- data: string;
866
+ bytes: string;
727
867
  name?: string;
728
868
  }
729
869
  interface FileUrl {
@@ -775,6 +915,8 @@ interface ToolResult {
775
915
  readonly tool_call_id: string;
776
916
  readonly tool_name: string;
777
917
  readonly parts: readonly DistriPart[];
918
+ /** Per-part metadata indexed by part position (0-based). Parts with save: false will be filtered out when storing. */
919
+ readonly parts_metadata?: Record<number, PartMetadata>;
778
920
  }
779
921
  /**
780
922
  * Tool result data that goes inside the parts array
@@ -785,11 +927,20 @@ interface ToolResultData {
785
927
  error?: string;
786
928
  }
787
929
  declare function isArrayParts(result: any): boolean;
930
+ /**
931
+ * Part with optional inline metadata - used by tool handlers to mark parts as non-saveable
932
+ */
933
+ type DistriPartWithMetadata = DistriPart & {
934
+ __metadata?: PartMetadata;
935
+ };
788
936
  /**
789
937
  * Type-safe helper to create a successful ToolResult
790
938
  * Uses proper DistriPart structure - conversion to backend format happens in encoder
939
+ *
940
+ * Parts can include __metadata property to specify part-level metadata (e.g., save: false).
941
+ * Image parts are automatically marked as save: false.
791
942
  */
792
- declare function createSuccessfulToolResult(toolCallId: string, toolName: string, result: string | number | boolean | null | object | DistriPart[]): ToolResult;
943
+ declare function createSuccessfulToolResult(toolCallId: string, toolName: string, result: string | number | boolean | null | object | DistriPartWithMetadata[], explicitPartsMetadata?: Record<number, PartMetadata>): ToolResult;
793
944
  /**
794
945
  * Type-safe helper to create a failed ToolResult
795
946
  * Uses proper DistriPart structure - conversion to backend format happens in encoder
@@ -1046,6 +1197,11 @@ interface DistriClientConfig {
1046
1197
  * Client ID from Distri Cloud.
1047
1198
  */
1048
1199
  clientId?: string;
1200
+ /**
1201
+ * Workspace ID for multi-tenant support (Distri Cloud).
1202
+ * When provided, all requests will include X-Workspace-Id header.
1203
+ */
1204
+ workspaceId?: string;
1049
1205
  }
1050
1206
  interface LLMResponse {
1051
1207
  finish_reason: string;
@@ -1110,6 +1266,51 @@ type A2AStreamEventData = Message | TaskStatusUpdateEvent | TaskArtifactUpdateEv
1110
1266
  declare function isDistriMessage(event: DistriStreamEvent): event is DistriMessage;
1111
1267
  declare function isDistriEvent(event: DistriStreamEvent): event is DistriEvent;
1112
1268
  type DistriChatMessage = DistriEvent | DistriMessage;
1269
+ /**
1270
+ * Vote type for message feedback
1271
+ */
1272
+ type VoteType = 'upvote' | 'downvote';
1273
+ /**
1274
+ * Record of a message being read
1275
+ */
1276
+ interface MessageReadStatus {
1277
+ thread_id: string;
1278
+ message_id: string;
1279
+ user_id: string;
1280
+ read_at: string;
1281
+ }
1282
+ /**
1283
+ * Request to vote on a message
1284
+ */
1285
+ interface VoteMessageRequest {
1286
+ vote_type: VoteType;
1287
+ /** Required for downvotes */
1288
+ comment?: string;
1289
+ }
1290
+ /**
1291
+ * A vote on a message with optional feedback comment
1292
+ */
1293
+ interface MessageVote {
1294
+ id: string;
1295
+ thread_id: string;
1296
+ message_id: string;
1297
+ user_id: string;
1298
+ vote_type: VoteType;
1299
+ /** Comment is required for downvotes, optional for upvotes */
1300
+ comment?: string;
1301
+ created_at: string;
1302
+ updated_at: string;
1303
+ }
1304
+ /**
1305
+ * Summary of votes for a message
1306
+ */
1307
+ interface MessageVoteSummary {
1308
+ message_id: string;
1309
+ upvotes: number;
1310
+ downvotes: number;
1311
+ /** Current user's vote on this message, if any */
1312
+ user_vote?: VoteType;
1313
+ }
1113
1314
 
1114
1315
  /**
1115
1316
  * Converts an A2A Message to a DistriMessage
@@ -1156,4 +1357,4 @@ declare function extractToolCallsFromDistriMessage(message: DistriMessage): any[
1156
1357
  */
1157
1358
  declare function extractToolResultsFromDistriMessage(message: DistriMessage): any[];
1158
1359
 
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 };
1360
+ 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 DistriMessageMetadata, type DistriPart, type DistriPartWithMetadata, type DistriPlan, type DistriStreamEvent, type DistriThread, type DynamicMetadata, 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 MessageReadStatus, type MessageRole, type MessageVote, type MessageVoteSummary, type ModelProviderConfig, type ModelProviderName, type ModelSettings, type PartMetadata, type PlanAction, type PlanFinishedEvent, type PlanPrunedEvent, type PlanStartedEvent, type PlanStep, type PromptSection, 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 TodoItem, type TodoStatus, type TodosUpdatedEvent, 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, type VoteMessageRequest, type VoteType, convertA2AMessageToDistri, convertA2APartToDistri, convertA2AStatusUpdateToDistri, convertDistriMessageToA2A, convertDistriPartToA2A, createFailedToolResult, createSuccessfulToolResult, decodeA2AStreamEvent, extractTextFromDistriMessage, extractToolCallsFromDistriMessage, extractToolResultData, extractToolResultsFromDistriMessage, isArrayParts, isDistriEvent, isDistriMessage, processA2AMessagesData, processA2AStreamData, uuidv4 };