@distri/core 0.3.5 → 0.3.6
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 +275 -4
- package/dist/index.d.ts +275 -4
- package/dist/index.js +351 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +344 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ interface RunStartedEvent {
|
|
|
7
7
|
data: {
|
|
8
8
|
runId?: string;
|
|
9
9
|
taskId?: string;
|
|
10
|
+
agentId?: string;
|
|
10
11
|
};
|
|
11
12
|
}
|
|
12
13
|
interface RunFinishedEvent {
|
|
@@ -368,6 +369,12 @@ declare class DistriClient {
|
|
|
368
369
|
* Get specific agent by ID
|
|
369
370
|
*/
|
|
370
371
|
getAgent(agentId: string): Promise<AgentConfigWithTools>;
|
|
372
|
+
/**
|
|
373
|
+
* Fetch all available models grouped by provider, with configuration status.
|
|
374
|
+
* Each provider includes `configured: boolean` indicating whether the
|
|
375
|
+
* provider's required API key(s) are set on the server.
|
|
376
|
+
*/
|
|
377
|
+
fetchAvailableModels(): Promise<ProviderModelsStatus[]>;
|
|
371
378
|
/**
|
|
372
379
|
* Update an agent's definition (markdown only)
|
|
373
380
|
*/
|
|
@@ -489,6 +496,8 @@ declare class DistriClient {
|
|
|
489
496
|
* Enhanced fetch with retry logic and auth headers.
|
|
490
497
|
* Exposed publicly for extensions like DistriHomeClient.
|
|
491
498
|
*/
|
|
499
|
+
/** Call a registered tool via the server's /tools/call endpoint. */
|
|
500
|
+
callTool(toolName: string, input: Record<string, unknown>): Promise<unknown>;
|
|
492
501
|
fetch(input: RequestInfo | URL, initialInit?: RequestInit): Promise<Response>;
|
|
493
502
|
/**
|
|
494
503
|
* Delay utility
|
|
@@ -824,6 +833,45 @@ interface DynamicMetadata {
|
|
|
824
833
|
* Parts not listed will use default metadata (save: true). */
|
|
825
834
|
parts?: Record<number, PartMetadata>;
|
|
826
835
|
}
|
|
836
|
+
/**
|
|
837
|
+
* Tier of context compaction applied by the server.
|
|
838
|
+
*/
|
|
839
|
+
type CompactionTier = 'trim' | 'summarize' | 'reset';
|
|
840
|
+
/**
|
|
841
|
+
* Emitted when the agent performs context compaction to stay within
|
|
842
|
+
* token budget limits. Mirrors the server-side ContextCompaction event.
|
|
843
|
+
*/
|
|
844
|
+
interface ContextCompactionEvent {
|
|
845
|
+
type: 'context_compaction';
|
|
846
|
+
/** Which tier of compaction was applied */
|
|
847
|
+
tier: CompactionTier;
|
|
848
|
+
/** Token count before compaction */
|
|
849
|
+
tokens_before: number;
|
|
850
|
+
/** Token count after compaction */
|
|
851
|
+
tokens_after: number;
|
|
852
|
+
/** Number of entries removed or summarized */
|
|
853
|
+
entries_affected: number;
|
|
854
|
+
/** Context budget limit that triggered compaction */
|
|
855
|
+
context_limit: number;
|
|
856
|
+
/** Usage ratio that triggered compaction (0.0 - 1.0) */
|
|
857
|
+
usage_ratio: number;
|
|
858
|
+
/** Optional summary text (for Tier 2 summarization) */
|
|
859
|
+
summary?: string;
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* Current context health information derived from compaction events
|
|
863
|
+
* and usage tracking.
|
|
864
|
+
*/
|
|
865
|
+
interface ContextHealth {
|
|
866
|
+
/** Current usage ratio (0.0 - 1.0) */
|
|
867
|
+
usage_ratio: number;
|
|
868
|
+
/** Estimated tokens currently used */
|
|
869
|
+
tokens_used: number;
|
|
870
|
+
/** Token budget limit */
|
|
871
|
+
tokens_limit: number;
|
|
872
|
+
/** Last compaction event, if any */
|
|
873
|
+
last_compaction?: ContextCompactionEvent;
|
|
874
|
+
}
|
|
827
875
|
/**
|
|
828
876
|
* Context required for constructing A2A messages from DistriMessage
|
|
829
877
|
*/
|
|
@@ -1021,9 +1069,9 @@ interface McpDefinition {
|
|
|
1021
1069
|
type?: McpServerType;
|
|
1022
1070
|
}
|
|
1023
1071
|
interface ModelSettings {
|
|
1024
|
-
model
|
|
1072
|
+
model?: string;
|
|
1025
1073
|
temperature: number;
|
|
1026
|
-
max_tokens
|
|
1074
|
+
max_tokens?: number;
|
|
1027
1075
|
context_size: number;
|
|
1028
1076
|
top_p: number;
|
|
1029
1077
|
frequency_penalty: number;
|
|
@@ -1063,6 +1111,9 @@ interface DistriThread {
|
|
|
1063
1111
|
user_id?: string;
|
|
1064
1112
|
external_id?: string;
|
|
1065
1113
|
tags?: string[];
|
|
1114
|
+
input_tokens?: number;
|
|
1115
|
+
output_tokens?: number;
|
|
1116
|
+
total_tokens?: number;
|
|
1066
1117
|
}
|
|
1067
1118
|
interface Thread {
|
|
1068
1119
|
id: string;
|
|
@@ -1074,7 +1125,11 @@ interface Thread {
|
|
|
1074
1125
|
last_message?: string;
|
|
1075
1126
|
user_id?: string;
|
|
1076
1127
|
external_id?: string;
|
|
1128
|
+
channel_id?: string;
|
|
1077
1129
|
tags?: string[];
|
|
1130
|
+
input_tokens?: number;
|
|
1131
|
+
output_tokens?: number;
|
|
1132
|
+
total_tokens?: number;
|
|
1078
1133
|
}
|
|
1079
1134
|
/**
|
|
1080
1135
|
* Parameters for listing threads with filtering and pagination
|
|
@@ -1203,11 +1258,16 @@ interface DistriClientConfig {
|
|
|
1203
1258
|
*/
|
|
1204
1259
|
workspaceId?: string;
|
|
1205
1260
|
}
|
|
1261
|
+
interface TokenUsage {
|
|
1262
|
+
input_tokens: number;
|
|
1263
|
+
output_tokens: number;
|
|
1264
|
+
total_tokens: number;
|
|
1265
|
+
}
|
|
1206
1266
|
interface LLMResponse {
|
|
1207
1267
|
finish_reason: string;
|
|
1208
1268
|
content: string;
|
|
1209
1269
|
tool_calls: ToolCall[];
|
|
1210
|
-
|
|
1270
|
+
usage?: TokenUsage;
|
|
1211
1271
|
tools?: any[];
|
|
1212
1272
|
}
|
|
1213
1273
|
interface ExternalMcpServer {
|
|
@@ -1311,6 +1371,40 @@ interface MessageVoteSummary {
|
|
|
1311
1371
|
/** Current user's vote on this message, if any */
|
|
1312
1372
|
user_vote?: VoteType;
|
|
1313
1373
|
}
|
|
1374
|
+
/**
|
|
1375
|
+
* Information about a single model
|
|
1376
|
+
*/
|
|
1377
|
+
interface ModelInfo {
|
|
1378
|
+
id: string;
|
|
1379
|
+
name: string;
|
|
1380
|
+
}
|
|
1381
|
+
/**
|
|
1382
|
+
* Models grouped by provider with configuration status
|
|
1383
|
+
*/
|
|
1384
|
+
interface ProviderModelsStatus {
|
|
1385
|
+
provider_id: string;
|
|
1386
|
+
provider_label: string;
|
|
1387
|
+
configured: boolean;
|
|
1388
|
+
models: ModelInfo[];
|
|
1389
|
+
}
|
|
1390
|
+
interface UsageHistoryEntry {
|
|
1391
|
+
date: string;
|
|
1392
|
+
tokens: number;
|
|
1393
|
+
identifier_id?: string | null;
|
|
1394
|
+
channel_id?: string | null;
|
|
1395
|
+
channel_name?: string | null;
|
|
1396
|
+
agent_id?: string | null;
|
|
1397
|
+
}
|
|
1398
|
+
interface ChannelUsageSummary {
|
|
1399
|
+
id: string;
|
|
1400
|
+
name: string | null;
|
|
1401
|
+
provider: string;
|
|
1402
|
+
}
|
|
1403
|
+
interface UsageHistoryFilters {
|
|
1404
|
+
identifier_id?: string;
|
|
1405
|
+
channel_id?: string;
|
|
1406
|
+
agent_id?: string;
|
|
1407
|
+
}
|
|
1314
1408
|
|
|
1315
1409
|
/**
|
|
1316
1410
|
* Converts an A2A Message to a DistriMessage
|
|
@@ -1357,4 +1451,181 @@ declare function extractToolCallsFromDistriMessage(message: DistriMessage): any[
|
|
|
1357
1451
|
*/
|
|
1358
1452
|
declare function extractToolResultsFromDistriMessage(message: DistriMessage): any[];
|
|
1359
1453
|
|
|
1360
|
-
|
|
1454
|
+
/**
|
|
1455
|
+
* Workflow engine types — mirrors distri-workflow Rust crate.
|
|
1456
|
+
*/
|
|
1457
|
+
type WorkflowStatus = 'pending' | 'running' | 'paused' | 'completed' | 'failed' | 'blocked';
|
|
1458
|
+
type StepStatus = 'pending' | 'blocked' | 'running' | 'done' | 'failed' | 'skipped';
|
|
1459
|
+
type StepExecution = 'sequential' | 'parallel';
|
|
1460
|
+
interface WorkflowDefinition {
|
|
1461
|
+
id: string;
|
|
1462
|
+
workflow_type: string;
|
|
1463
|
+
/** JSON Schema for required inputs. */
|
|
1464
|
+
input_schema?: Record<string, unknown>;
|
|
1465
|
+
steps: WorkflowStep[];
|
|
1466
|
+
status?: WorkflowStatus;
|
|
1467
|
+
current_step?: number;
|
|
1468
|
+
context?: Record<string, unknown>;
|
|
1469
|
+
notes?: WorkflowNote[];
|
|
1470
|
+
created_at?: string;
|
|
1471
|
+
updated_at?: string;
|
|
1472
|
+
}
|
|
1473
|
+
interface WorkflowStep {
|
|
1474
|
+
id: string;
|
|
1475
|
+
label: string;
|
|
1476
|
+
kind: StepKind;
|
|
1477
|
+
depends_on?: string[];
|
|
1478
|
+
execution?: StepExecution;
|
|
1479
|
+
requires?: StepRequirement[];
|
|
1480
|
+
/** Explicit input mapping with {input.X}, {steps.X.Y}, {env.X} references. */
|
|
1481
|
+
input?: Record<string, unknown>;
|
|
1482
|
+
status?: StepStatus;
|
|
1483
|
+
result?: unknown;
|
|
1484
|
+
error?: string | null;
|
|
1485
|
+
started_at?: string | null;
|
|
1486
|
+
completed_at?: string | null;
|
|
1487
|
+
}
|
|
1488
|
+
interface StepRequirement {
|
|
1489
|
+
skill: string;
|
|
1490
|
+
permissions?: string[];
|
|
1491
|
+
config?: unknown;
|
|
1492
|
+
}
|
|
1493
|
+
type StepKind = {
|
|
1494
|
+
type: 'tool_call';
|
|
1495
|
+
tool_name: string;
|
|
1496
|
+
input?: unknown;
|
|
1497
|
+
agent_id?: string;
|
|
1498
|
+
} | {
|
|
1499
|
+
type: 'api_call';
|
|
1500
|
+
method: string;
|
|
1501
|
+
url: string;
|
|
1502
|
+
body?: unknown;
|
|
1503
|
+
headers?: Record<string, string>;
|
|
1504
|
+
} | {
|
|
1505
|
+
type: 'script';
|
|
1506
|
+
command: string;
|
|
1507
|
+
args?: string[];
|
|
1508
|
+
cwd?: string;
|
|
1509
|
+
timeout_secs?: number;
|
|
1510
|
+
} | {
|
|
1511
|
+
type: 'agent_run';
|
|
1512
|
+
agent_id: string;
|
|
1513
|
+
prompt: string;
|
|
1514
|
+
tools?: string[];
|
|
1515
|
+
skills?: string[];
|
|
1516
|
+
model?: string;
|
|
1517
|
+
} | {
|
|
1518
|
+
type: 'condition';
|
|
1519
|
+
expression: string;
|
|
1520
|
+
if_true: StepKind;
|
|
1521
|
+
if_false?: StepKind;
|
|
1522
|
+
} | {
|
|
1523
|
+
type: 'checkpoint';
|
|
1524
|
+
message: string;
|
|
1525
|
+
};
|
|
1526
|
+
interface StepResult {
|
|
1527
|
+
status: StepStatus;
|
|
1528
|
+
result?: unknown;
|
|
1529
|
+
error?: string | null;
|
|
1530
|
+
context_updates?: Record<string, unknown>;
|
|
1531
|
+
}
|
|
1532
|
+
interface WorkflowNote {
|
|
1533
|
+
step_id: string;
|
|
1534
|
+
message: string;
|
|
1535
|
+
at: string;
|
|
1536
|
+
}
|
|
1537
|
+
/** Helper: count steps by status */
|
|
1538
|
+
declare function countSteps(workflow: WorkflowDefinition): {
|
|
1539
|
+
pending: number;
|
|
1540
|
+
blocked: number;
|
|
1541
|
+
running: number;
|
|
1542
|
+
done: number;
|
|
1543
|
+
failed: number;
|
|
1544
|
+
skipped: number;
|
|
1545
|
+
};
|
|
1546
|
+
/** Helper: get progress percentage */
|
|
1547
|
+
declare function workflowProgress(workflow: WorkflowDefinition): number;
|
|
1548
|
+
/** Helper: get the step icon for display */
|
|
1549
|
+
declare function stepIcon(status: StepStatus): string;
|
|
1550
|
+
|
|
1551
|
+
/**
|
|
1552
|
+
* WorkflowRunner — client-side workflow execution engine.
|
|
1553
|
+
*
|
|
1554
|
+
* Mirrors the Rust DistriStepExecutor + WorkflowRunner.
|
|
1555
|
+
* Runs workflow steps in dependency order, resolves namespace references,
|
|
1556
|
+
* emits WorkflowEvent callbacks, and executes steps via DistriClient or custom handlers.
|
|
1557
|
+
*
|
|
1558
|
+
* Usage:
|
|
1559
|
+
* const runner = new WorkflowRunner(client, {
|
|
1560
|
+
* buildRequest: (step, init) => ({ ...init, headers: { ...init.headers, 'X-Custom': 'value' } })
|
|
1561
|
+
* })
|
|
1562
|
+
* const events = runner.run(workflowDef, { doc_id: 'abc' })
|
|
1563
|
+
* for await (const event of events) { console.log(event) }
|
|
1564
|
+
*/
|
|
1565
|
+
|
|
1566
|
+
type WorkflowEvent = {
|
|
1567
|
+
event: 'workflow_started';
|
|
1568
|
+
workflow_id: string;
|
|
1569
|
+
workflow_type: string;
|
|
1570
|
+
total_steps: number;
|
|
1571
|
+
} | {
|
|
1572
|
+
event: 'step_started';
|
|
1573
|
+
workflow_id: string;
|
|
1574
|
+
step_id: string;
|
|
1575
|
+
step_label: string;
|
|
1576
|
+
} | {
|
|
1577
|
+
event: 'step_completed';
|
|
1578
|
+
workflow_id: string;
|
|
1579
|
+
step_id: string;
|
|
1580
|
+
step_label: string;
|
|
1581
|
+
result?: unknown;
|
|
1582
|
+
} | {
|
|
1583
|
+
event: 'step_failed';
|
|
1584
|
+
workflow_id: string;
|
|
1585
|
+
step_id: string;
|
|
1586
|
+
step_label: string;
|
|
1587
|
+
error: string;
|
|
1588
|
+
} | {
|
|
1589
|
+
event: 'workflow_completed';
|
|
1590
|
+
workflow_id: string;
|
|
1591
|
+
status: WorkflowStatus;
|
|
1592
|
+
steps_done: number;
|
|
1593
|
+
steps_failed: number;
|
|
1594
|
+
};
|
|
1595
|
+
type WorkflowEventCallback = (event: WorkflowEvent) => void;
|
|
1596
|
+
interface WorkflowRunnerOptions {
|
|
1597
|
+
/** Hook to customize fetch RequestInit before HTTP calls (add auth, base URL, etc.) */
|
|
1598
|
+
buildRequest?: (step: WorkflowStep, init: RequestInit, url: string) => {
|
|
1599
|
+
url: string;
|
|
1600
|
+
init: RequestInit;
|
|
1601
|
+
};
|
|
1602
|
+
/** Environment variables injected into {env.X} namespace */
|
|
1603
|
+
env?: Record<string, unknown>;
|
|
1604
|
+
/** Custom step executor — override default behavior for any step kind */
|
|
1605
|
+
executeStep?: (step: WorkflowStep, resolvedInput: unknown, context: ExecutionContext) => Promise<StepResult>;
|
|
1606
|
+
}
|
|
1607
|
+
interface ExecutionContext {
|
|
1608
|
+
input: Record<string, unknown>;
|
|
1609
|
+
steps: Record<string, unknown>;
|
|
1610
|
+
env: Record<string, unknown>;
|
|
1611
|
+
}
|
|
1612
|
+
/** Resolve {namespace.path} in a string template. */
|
|
1613
|
+
declare function resolveTemplate(template: string, ctx: ExecutionContext): string;
|
|
1614
|
+
/** Recursively resolve namespace references in a JSON value.
|
|
1615
|
+
* Full-value references like "{steps.fetch.items}" preserve the original type. */
|
|
1616
|
+
declare function resolveValue(value: unknown, ctx: ExecutionContext): unknown;
|
|
1617
|
+
declare class WorkflowRunner {
|
|
1618
|
+
private client;
|
|
1619
|
+
private options;
|
|
1620
|
+
constructor(client: DistriClient, options?: WorkflowRunnerOptions);
|
|
1621
|
+
/** Run a workflow to completion. Returns an async generator of WorkflowEvents. */
|
|
1622
|
+
run(definition: WorkflowDefinition, input?: Record<string, unknown>): AsyncGenerator<WorkflowEvent>;
|
|
1623
|
+
/** Find indices of steps that are pending with all dependencies met. */
|
|
1624
|
+
private findRunnable;
|
|
1625
|
+
/** Default step executor — handles tool_call, api_call, checkpoint, etc. */
|
|
1626
|
+
private executeStep;
|
|
1627
|
+
private executeToolCall;
|
|
1628
|
+
private executeApiCall;
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
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 ChannelUsageSummary, type ChatCompletionChoice, type ChatCompletionMessage, type ChatCompletionRequest, type ChatCompletionResponse, type ChatCompletionResponseFormat, type ChatCompletionRole, type ChatProps, type CodePlanStep, type CompactionTier, type ConfigurationMeta, type ConfigurationResponse, ConnectionError, type ConnectionStatus, type ContextCompactionEvent, type ContextHealth, 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 ExecutionContext, 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 ModelInfo, type ModelProviderConfig, type ModelProviderName, type ModelSettings, type PartMetadata, type PlanAction, type PlanFinishedEvent, type PlanPrunedEvent, type PlanStartedEvent, type PlanStep, type PromptSection, type ProviderModelsStatus, type ReactStep, type Role, type RunErrorEvent, type RunFinishedEvent, type RunStartedEvent, type ServerConfig, type SpeechToTextConfig, type StepCompletedEvent, type StepExecution, type StepKind, type StepRequirement, type StepResult, type StepStartedEvent, type StepStatus, 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 TokenUsage, 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 UsageHistoryEntry, type UsageHistoryFilters, type UseToolsOptions, type VoteMessageRequest, type VoteType, type WorkflowDefinition, type WorkflowEvent, type WorkflowEventCallback, type WorkflowNote, WorkflowRunner, type WorkflowRunnerOptions, type WorkflowStatus, type WorkflowStep, convertA2AMessageToDistri, convertA2APartToDistri, convertA2AStatusUpdateToDistri, convertDistriMessageToA2A, convertDistriPartToA2A, countSteps, createFailedToolResult, createSuccessfulToolResult, decodeA2AStreamEvent, extractTextFromDistriMessage, extractToolCallsFromDistriMessage, extractToolResultData, extractToolResultsFromDistriMessage, isArrayParts, isDistriEvent, isDistriMessage, processA2AMessagesData, processA2AStreamData, resolveTemplate, resolveValue, stepIcon, uuidv4, workflowProgress };
|