@distri/core 0.3.3 → 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 {
@@ -343,7 +359,7 @@ declare class DistriClient {
343
359
  /**
344
360
  * Minimal LLM helper that proxies to the Distri server using Distri messages.
345
361
  */
346
- llm(messages: DistriMessage[], tools?: unknown[], options?: LlmExecuteOptions): Promise<LLMResponse>;
362
+ llm(messages: DistriMessage[], tools?: ToolDefinition[], options?: LlmExecuteOptions): Promise<LLMResponse>;
347
363
  /**
348
364
  * Get all available agents from the Distri server
349
365
  */
@@ -387,9 +403,13 @@ declare class DistriClient {
387
403
  */
388
404
  getThreads(params?: ThreadListParams): Promise<ThreadListResponse>;
389
405
  /**
390
- * 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.
391
409
  */
392
- getAgentsByUsage(): Promise<AgentUsageInfo[]>;
410
+ getAgentsByUsage(options?: {
411
+ search?: string;
412
+ }): Promise<AgentUsageInfo[]>;
393
413
  /**
394
414
  * Create a new browser session
395
415
  * Returns session info including viewer_url and stream_url from browsr
@@ -404,6 +424,35 @@ declare class DistriClient {
404
424
  * Get messages from a thread as DistriMessage format
405
425
  */
406
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[]>;
407
456
  /**
408
457
  * Send a DistriMessage to a thread
409
458
  */
@@ -458,13 +507,19 @@ declare class DistriClient {
458
507
  */
459
508
  static initDistriMessage(role: DistriMessage['role'], parts: DistriPart[], id?: string, created_at?: number): DistriMessage;
460
509
  /**
461
- * 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.
462
514
  */
463
- static initMessageParams(message: Message, configuration?: MessageSendParams['configuration'], metadata?: any): MessageSendParams;
515
+ static initMessageParams(message: Message, configuration?: MessageSendParams['configuration'], metadata?: any, dynamicMetadata?: DynamicMetadata): MessageSendParams;
464
516
  /**
465
- * 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.
466
521
  */
467
- static initDistriMessageParams(message: DistriMessage, context: InvokeContext): MessageSendParams;
522
+ static initDistriMessageParams(message: DistriMessage, context: InvokeContext, dynamicMetadata?: DynamicMetadata): MessageSendParams;
468
523
  }
469
524
  declare function uuidv4(): string;
470
525
 
@@ -478,6 +533,14 @@ interface InvokeConfig {
478
533
  contextId?: string;
479
534
  /** Metadata for the requests */
480
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'];
481
544
  }
482
545
  /**
483
546
  * Result from agent invoke
@@ -542,7 +605,10 @@ declare class Agent {
542
605
  */
543
606
  validateExternalTools(tools?: DistriBaseTool[]): ExternalToolValidationResult;
544
607
  /**
545
- * 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.
546
612
  */
547
613
  private enhanceParamsWithTools;
548
614
  private assertExternalTools;
@@ -572,6 +638,26 @@ declare class Agent {
572
638
  * Message roles supported by Distri
573
639
  */
574
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
+ }
575
661
  /**
576
662
  * Distri-specific message structure with parts
577
663
  */
@@ -582,6 +668,12 @@ interface DistriMessage {
582
668
  created_at: number;
583
669
  step_id?: string;
584
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;
585
677
  }
586
678
  interface LlmExecuteOptions {
587
679
  thread_id?: string;
@@ -589,6 +681,11 @@ interface LlmExecuteOptions {
589
681
  run_id?: string;
590
682
  model_settings?: any;
591
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;
592
689
  }
593
690
  interface AssistantWithToolCalls {
594
691
  id: string;
@@ -697,6 +794,36 @@ interface ReactStep extends BasePlanStep {
697
794
  action: string;
698
795
  }
699
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
+ }
700
827
  /**
701
828
  * Context required for constructing A2A messages from DistriMessage
702
829
  */
@@ -731,12 +858,12 @@ type DataPart = {
731
858
  };
732
859
  type DistriPart = TextPart | ToolCallPart | ToolResultRefPart | ImagePart | DataPart;
733
860
  /**
734
- * File type for images
861
+ * File type for images - matches Rust FileType::Bytes
735
862
  */
736
863
  interface FileBytes {
737
864
  type: 'bytes';
738
865
  mime_type: string;
739
- data: string;
866
+ bytes: string;
740
867
  name?: string;
741
868
  }
742
869
  interface FileUrl {
@@ -788,6 +915,8 @@ interface ToolResult {
788
915
  readonly tool_call_id: string;
789
916
  readonly tool_name: string;
790
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>;
791
920
  }
792
921
  /**
793
922
  * Tool result data that goes inside the parts array
@@ -798,11 +927,20 @@ interface ToolResultData {
798
927
  error?: string;
799
928
  }
800
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
+ };
801
936
  /**
802
937
  * Type-safe helper to create a successful ToolResult
803
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.
804
942
  */
805
- 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;
806
944
  /**
807
945
  * Type-safe helper to create a failed ToolResult
808
946
  * Uses proper DistriPart structure - conversion to backend format happens in encoder
@@ -1128,6 +1266,51 @@ type A2AStreamEventData = Message | TaskStatusUpdateEvent | TaskArtifactUpdateEv
1128
1266
  declare function isDistriMessage(event: DistriStreamEvent): event is DistriMessage;
1129
1267
  declare function isDistriEvent(event: DistriStreamEvent): event is DistriEvent;
1130
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
+ }
1131
1314
 
1132
1315
  /**
1133
1316
  * Converts an A2A Message to a DistriMessage
@@ -1174,4 +1357,4 @@ declare function extractToolCallsFromDistriMessage(message: DistriMessage): any[
1174
1357
  */
1175
1358
  declare function extractToolResultsFromDistriMessage(message: DistriMessage): any[];
1176
1359
 
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 };
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 };
package/dist/index.d.ts 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 {
@@ -343,7 +359,7 @@ declare class DistriClient {
343
359
  /**
344
360
  * Minimal LLM helper that proxies to the Distri server using Distri messages.
345
361
  */
346
- llm(messages: DistriMessage[], tools?: unknown[], options?: LlmExecuteOptions): Promise<LLMResponse>;
362
+ llm(messages: DistriMessage[], tools?: ToolDefinition[], options?: LlmExecuteOptions): Promise<LLMResponse>;
347
363
  /**
348
364
  * Get all available agents from the Distri server
349
365
  */
@@ -387,9 +403,13 @@ declare class DistriClient {
387
403
  */
388
404
  getThreads(params?: ThreadListParams): Promise<ThreadListResponse>;
389
405
  /**
390
- * 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.
391
409
  */
392
- getAgentsByUsage(): Promise<AgentUsageInfo[]>;
410
+ getAgentsByUsage(options?: {
411
+ search?: string;
412
+ }): Promise<AgentUsageInfo[]>;
393
413
  /**
394
414
  * Create a new browser session
395
415
  * Returns session info including viewer_url and stream_url from browsr
@@ -404,6 +424,35 @@ declare class DistriClient {
404
424
  * Get messages from a thread as DistriMessage format
405
425
  */
406
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[]>;
407
456
  /**
408
457
  * Send a DistriMessage to a thread
409
458
  */
@@ -458,13 +507,19 @@ declare class DistriClient {
458
507
  */
459
508
  static initDistriMessage(role: DistriMessage['role'], parts: DistriPart[], id?: string, created_at?: number): DistriMessage;
460
509
  /**
461
- * 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.
462
514
  */
463
- static initMessageParams(message: Message, configuration?: MessageSendParams['configuration'], metadata?: any): MessageSendParams;
515
+ static initMessageParams(message: Message, configuration?: MessageSendParams['configuration'], metadata?: any, dynamicMetadata?: DynamicMetadata): MessageSendParams;
464
516
  /**
465
- * 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.
466
521
  */
467
- static initDistriMessageParams(message: DistriMessage, context: InvokeContext): MessageSendParams;
522
+ static initDistriMessageParams(message: DistriMessage, context: InvokeContext, dynamicMetadata?: DynamicMetadata): MessageSendParams;
468
523
  }
469
524
  declare function uuidv4(): string;
470
525
 
@@ -478,6 +533,14 @@ interface InvokeConfig {
478
533
  contextId?: string;
479
534
  /** Metadata for the requests */
480
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'];
481
544
  }
482
545
  /**
483
546
  * Result from agent invoke
@@ -542,7 +605,10 @@ declare class Agent {
542
605
  */
543
606
  validateExternalTools(tools?: DistriBaseTool[]): ExternalToolValidationResult;
544
607
  /**
545
- * 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.
546
612
  */
547
613
  private enhanceParamsWithTools;
548
614
  private assertExternalTools;
@@ -572,6 +638,26 @@ declare class Agent {
572
638
  * Message roles supported by Distri
573
639
  */
574
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
+ }
575
661
  /**
576
662
  * Distri-specific message structure with parts
577
663
  */
@@ -582,6 +668,12 @@ interface DistriMessage {
582
668
  created_at: number;
583
669
  step_id?: string;
584
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;
585
677
  }
586
678
  interface LlmExecuteOptions {
587
679
  thread_id?: string;
@@ -589,6 +681,11 @@ interface LlmExecuteOptions {
589
681
  run_id?: string;
590
682
  model_settings?: any;
591
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;
592
689
  }
593
690
  interface AssistantWithToolCalls {
594
691
  id: string;
@@ -697,6 +794,36 @@ interface ReactStep extends BasePlanStep {
697
794
  action: string;
698
795
  }
699
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
+ }
700
827
  /**
701
828
  * Context required for constructing A2A messages from DistriMessage
702
829
  */
@@ -731,12 +858,12 @@ type DataPart = {
731
858
  };
732
859
  type DistriPart = TextPart | ToolCallPart | ToolResultRefPart | ImagePart | DataPart;
733
860
  /**
734
- * File type for images
861
+ * File type for images - matches Rust FileType::Bytes
735
862
  */
736
863
  interface FileBytes {
737
864
  type: 'bytes';
738
865
  mime_type: string;
739
- data: string;
866
+ bytes: string;
740
867
  name?: string;
741
868
  }
742
869
  interface FileUrl {
@@ -788,6 +915,8 @@ interface ToolResult {
788
915
  readonly tool_call_id: string;
789
916
  readonly tool_name: string;
790
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>;
791
920
  }
792
921
  /**
793
922
  * Tool result data that goes inside the parts array
@@ -798,11 +927,20 @@ interface ToolResultData {
798
927
  error?: string;
799
928
  }
800
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
+ };
801
936
  /**
802
937
  * Type-safe helper to create a successful ToolResult
803
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.
804
942
  */
805
- 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;
806
944
  /**
807
945
  * Type-safe helper to create a failed ToolResult
808
946
  * Uses proper DistriPart structure - conversion to backend format happens in encoder
@@ -1128,6 +1266,51 @@ type A2AStreamEventData = Message | TaskStatusUpdateEvent | TaskArtifactUpdateEv
1128
1266
  declare function isDistriMessage(event: DistriStreamEvent): event is DistriMessage;
1129
1267
  declare function isDistriEvent(event: DistriStreamEvent): event is DistriEvent;
1130
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
+ }
1131
1314
 
1132
1315
  /**
1133
1316
  * Converts an A2A Message to a DistriMessage
@@ -1174,4 +1357,4 @@ declare function extractToolCallsFromDistriMessage(message: DistriMessage): any[
1174
1357
  */
1175
1358
  declare function extractToolResultsFromDistriMessage(message: DistriMessage): any[];
1176
1359
 
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 };
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 };