@workglow/ai 0.0.116 → 0.0.118

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.
@@ -0,0 +1,181 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { DataPorts } from "@workglow/task-graph";
7
+ import type { ToolCall, ToolCalls, ToolDefinition } from "./ToolCallingTask";
8
+ /**
9
+ * A text content block within a chat message.
10
+ */
11
+ export interface TextContentBlock {
12
+ readonly type: "text";
13
+ readonly text: string;
14
+ }
15
+ /**
16
+ * An image content block within a chat message.
17
+ */
18
+ export interface ImageContentBlock {
19
+ readonly type: "image";
20
+ readonly mimeType: string;
21
+ readonly data: string;
22
+ }
23
+ /**
24
+ * An audio content block within a chat message.
25
+ */
26
+ export interface AudioContentBlock {
27
+ readonly type: "audio";
28
+ readonly mimeType: string;
29
+ readonly data: string;
30
+ }
31
+ /**
32
+ * A tool-use content block within an assistant message.
33
+ * Represents the LLM requesting a tool invocation.
34
+ */
35
+ export interface ToolUseContentBlock {
36
+ readonly type: "tool_use";
37
+ readonly id: string;
38
+ readonly name: string;
39
+ readonly input: Record<string, unknown>;
40
+ }
41
+ /**
42
+ * A tool-result content block within a tool message.
43
+ * Represents the result of executing a tool call.
44
+ */
45
+ export interface ToolResultContentBlock {
46
+ readonly type: "tool_result";
47
+ readonly tool_use_id: string;
48
+ readonly content: string | ReadonlyArray<ToolResultInnerBlock>;
49
+ readonly is_error?: boolean;
50
+ }
51
+ /** Content blocks allowed in user messages */
52
+ export type UserContentBlock = TextContentBlock | ImageContentBlock | AudioContentBlock;
53
+ /** Content blocks allowed inside tool result content */
54
+ export type ToolResultInnerBlock = TextContentBlock | ImageContentBlock | AudioContentBlock;
55
+ export type ContentBlock = TextContentBlock | ImageContentBlock | AudioContentBlock | ToolUseContentBlock | ToolResultContentBlock;
56
+ /**
57
+ * Provider-agnostic chat message for multi-turn conversations.
58
+ * Uses a discriminated union on `role` to enforce correct content types.
59
+ */
60
+ export type ChatMessage = {
61
+ readonly role: "user";
62
+ readonly content: string | ReadonlyArray<UserContentBlock>;
63
+ } | {
64
+ readonly role: "assistant";
65
+ readonly content: ReadonlyArray<TextContentBlock | ToolUseContentBlock>;
66
+ } | {
67
+ readonly role: "tool";
68
+ readonly content: ReadonlyArray<ToolResultContentBlock>;
69
+ };
70
+ /**
71
+ * A tool backed by a Task in the TaskRegistry. Instantiated and run via
72
+ * `TaskRegistry.all.get(taskType)`. Optional `config` is passed to the
73
+ * task constructor for configurable tasks (e.g. `McpToolCallTask`,
74
+ * `JavaScriptTask`).
75
+ */
76
+ export interface RegistryToolSource {
77
+ readonly type: "registry";
78
+ readonly definition: ToolDefinition;
79
+ readonly taskType: string;
80
+ /** Configuration values passed to the task constructor. */
81
+ readonly config?: DataPorts;
82
+ }
83
+ /**
84
+ * A user-provided tool with a custom executor function.
85
+ */
86
+ export interface FunctionToolSource {
87
+ readonly type: "function";
88
+ readonly definition: ToolDefinition;
89
+ readonly run: (input: DataPorts) => Promise<DataPorts>;
90
+ }
91
+ export type ToolSource = RegistryToolSource | FunctionToolSource;
92
+ export interface ToolResult {
93
+ readonly toolCallId: string;
94
+ readonly toolName: string;
95
+ readonly output: DataPorts;
96
+ readonly isError: boolean;
97
+ /** Optional media content blocks to include alongside the JSON output. */
98
+ readonly mediaContent?: ReadonlyArray<ToolResultInnerBlock>;
99
+ }
100
+ /**
101
+ * Decision returned by the beforeToolCall hook.
102
+ * - `"allow"`: proceed with the tool call as-is
103
+ * - `"deny"`: skip the tool call and return an error to the LLM
104
+ * - `"modify"`: proceed with modified input
105
+ */
106
+ export type ToolCallDecision = {
107
+ readonly action: "allow";
108
+ } | {
109
+ readonly action: "deny";
110
+ readonly reason?: string;
111
+ } | {
112
+ readonly action: "modify";
113
+ readonly input: Record<string, unknown>;
114
+ };
115
+ /**
116
+ * Action returned by the onToolError hook.
117
+ * - `"throw"`: report the error to the LLM (default when no hook)
118
+ * - `"result"`: use a fallback result instead of reporting the error
119
+ */
120
+ export type ToolErrorAction = {
121
+ readonly action: "throw";
122
+ } | {
123
+ readonly action: "result";
124
+ readonly output: Record<string, unknown>;
125
+ };
126
+ /**
127
+ * Action returned by the onIteration hook.
128
+ * - `"continue"`: proceed with the next LLM call
129
+ * - `"stop"`: end the agent loop and return current results
130
+ */
131
+ export type IterationAction = {
132
+ readonly action: "continue";
133
+ } | {
134
+ readonly action: "stop";
135
+ };
136
+ /**
137
+ * Lifecycle hooks for the AgentTask loop.
138
+ * All hooks are optional; the agent runs without intervention by default.
139
+ */
140
+ export interface AgentHooks {
141
+ /** Called before each tool call. Can approve, deny, or modify the call. */
142
+ readonly beforeToolCall?: (call: ToolCall, source: ToolSource) => Promise<ToolCallDecision>;
143
+ /** Called after each successful tool call. Can transform the result. */
144
+ readonly afterToolCall?: (call: ToolCall, result: ToolResult) => Promise<ToolResult>;
145
+ /** Called when a tool call throws. Can provide a fallback result or re-throw. */
146
+ readonly onToolError?: (call: ToolCall, error: Error) => Promise<ToolErrorAction>;
147
+ /**
148
+ * Called at the start of each iteration, before calling the LLM.
149
+ * Can stop the loop or inspect state (e.g. for context trimming).
150
+ */
151
+ readonly onIteration?: (iteration: number, messages: ReadonlyArray<ChatMessage>, stats: {
152
+ readonly totalToolCalls: number;
153
+ }) => Promise<IterationAction>;
154
+ }
155
+ export declare function imageBlock(mimeType: string, data: string): ImageContentBlock;
156
+ export declare function audioBlock(mimeType: string, data: string): AudioContentBlock;
157
+ export declare function imageBlockFromDataUri(dataUri: string): ImageContentBlock;
158
+ export declare function audioBlockFromDataUri(dataUri: string): AudioContentBlock;
159
+ /**
160
+ * Creates a user message from a prompt string or array of content blocks.
161
+ */
162
+ export declare function userMessage(prompt: string | ReadonlyArray<UserContentBlock>): ChatMessage;
163
+ /**
164
+ * Creates an assistant message from text and optional tool calls.
165
+ */
166
+ export declare function assistantMessage(text: string, toolCalls?: ToolCalls): ChatMessage;
167
+ /**
168
+ * Creates a tool message from an array of tool results.
169
+ * When a result has `mediaContent`, emits content as an array of blocks
170
+ * instead of a plain JSON string.
171
+ */
172
+ export declare function toolMessage(results: ReadonlyArray<ToolResult>): ChatMessage;
173
+ /**
174
+ * Extracts all ToolDefinitions from an array of ToolSources.
175
+ */
176
+ export declare function toolSourceDefinitions(sources: ReadonlyArray<ToolSource>): ToolDefinition[];
177
+ /**
178
+ * Finds the ToolSource matching a tool call name.
179
+ */
180
+ export declare function findToolSource(sources: ReadonlyArray<ToolSource>, name: string): ToolSource | undefined;
181
+ //# sourceMappingURL=AgentTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentTypes.d.ts","sourceRoot":"","sources":["../../src/task/AgentTypes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAM7E;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC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AAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC,gBAAgB,CAAC,GAAG,WAAW,CAEzF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,SAAS,GAAG,WAAW,CAgBjF;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG,WAAW,CAiB3E;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG,cAAc,EAAE,CAE1F;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,aAAa,CAAC,UAAU,CAAC,EAClC,IAAI,EAAE,MAAM,GACX,UAAU,GAAG,SAAS,CAExB"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { IExecuteContext } from "@workglow/task-graph";
7
+ import type { ServiceRegistry } from "@workglow/util";
8
+ import type { AgentHooks, ToolResult, ToolSource } from "./AgentTypes";
9
+ import type { ToolCall, ToolCalls, ToolDefinition } from "./ToolCallingTask";
10
+ /**
11
+ * Builds an array of {@link ToolSource} entries from a unified tools list.
12
+ *
13
+ * Each entry is either:
14
+ * - A **string** — resolved from the TaskRegistry via {@link taskTypesToTools}.
15
+ * - A **{@link ToolDefinition}** object — dispatched based on its shape:
16
+ * - Has `execute` function → {@link FunctionToolSource}
17
+ * - Has a backing task in the task constructors (looked up by `name`) →
18
+ * {@link RegistryToolSource} with optional `config` passed through
19
+ * - Otherwise → {@link FunctionToolSource} that throws on invocation
20
+ *
21
+ * This mirrors the model resolution pattern: strings are convenient
22
+ * shorthand, objects give full control (including `config` for
23
+ * configurable tasks like `McpToolCallTask` or `JavaScriptTask`).
24
+ *
25
+ * The original order of entries in `tools` is preserved in the returned
26
+ * sources array. An optional `registry` can be provided to use a
27
+ * DI-scoped constructor map instead of the global TaskRegistry.
28
+ */
29
+ export declare function buildToolSources(tools?: ReadonlyArray<string | ToolDefinition>, registry?: ServiceRegistry): ToolSource[];
30
+ /**
31
+ * Executes a single tool call by dispatching to the appropriate handler
32
+ * based on the tool source type. Applies beforeToolCall, afterToolCall,
33
+ * and onToolError hooks when provided.
34
+ */
35
+ export declare function executeToolCall(toolCall: ToolCall, sources: ReadonlyArray<ToolSource>, context: IExecuteContext, hooks?: AgentHooks): Promise<ToolResult>;
36
+ /**
37
+ * Executes multiple tool calls with concurrency control.
38
+ *
39
+ * Uses the same shared-cursor worker pool pattern as IteratorTaskRunner:
40
+ * spawns N workers that pull from a shared cursor until all items are
41
+ * processed. Results are returned in the original order.
42
+ *
43
+ * @param maxConcurrency - Max parallel tool executions (default: 5)
44
+ */
45
+ export declare function executeToolCalls(toolCalls: ToolCalls, sources: ReadonlyArray<ToolSource>, context: IExecuteContext, hooks?: AgentHooks, maxConcurrency?: number): Promise<ToolResult[]>;
46
+ /**
47
+ * Checks whether a ToolCallingTask output contains any tool calls.
48
+ */
49
+ export declare function hasToolCalls(toolCalls: unknown[] | undefined): boolean;
50
+ //# sourceMappingURL=AgentUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentUtils.d.ts","sourceRoot":"","sources":["../../src/task/AgentUtils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,KAAK,EACV,UAAU,EAGV,UAAU,EACV,UAAU,EACX,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EACV,QAAQ,EACR,SAAS,EACT,cAAc,EAEf,MAAM,mBAAmB,CAAC;AAM3B;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,CAAC,EAAE,aAAa,CAAC,MAAM,GAAG,cAAc,CAAC,EAC9C,QAAQ,CAAC,EAAE,eAAe,GACzB,UAAU,EAAE,CA+Dd;AAMD;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,aAAa,CAAC,UAAU,CAAC,EAClC,OAAO,EAAE,eAAe,EACxB,KAAK,CAAC,EAAE,UAAU,GACjB,OAAO,CAAC,UAAU,CAAC,CAsFrB;AAED;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CACpC,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,aAAa,CAAC,UAAU,CAAC,EAClC,OAAO,EAAE,eAAe,EACxB,KAAK,CAAC,EAAE,UAAU,EAClB,cAAc,GAAE,MAAU,GACzB,OAAO,CAAC,UAAU,EAAE,CAAC,CA4BvB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,OAAO,EAAE,GAAG,SAAS,GAAG,OAAO,CAEtE"}
@@ -265,10 +265,10 @@ export declare const chunkRetrieval: (input: ChunkRetrievalTaskInput, config?: J
265
265
  metadata: {
266
266
  [x: string]: unknown;
267
267
  }[];
268
+ query: string | TypedArray | (string | TypedArray)[];
268
269
  chunks: string[];
269
- count: number;
270
270
  scores: number[];
271
- query: string | TypedArray | (string | TypedArray)[];
271
+ count: number;
272
272
  chunk_ids: string[];
273
273
  }>;
274
274
  declare module "@workglow/task-graph" {
@@ -123,10 +123,10 @@ export declare const vectorStoreSearch: (input: VectorStoreSearchTaskInput, conf
123
123
  metadata: {
124
124
  [x: string]: unknown;
125
125
  }[];
126
+ scores: number[];
127
+ count: number;
126
128
  ids: string[];
127
129
  vectors: import("@workglow/util").TypedArray[];
128
- count: number;
129
- scores: number[];
130
130
  }>;
131
131
  declare module "@workglow/task-graph" {
132
132
  interface Workflow {
@@ -107,8 +107,8 @@ export declare class ChunkVectorUpsertTask extends Task<VectorStoreUpsertTaskInp
107
107
  execute(input: VectorStoreUpsertTaskInput, context: IExecuteContext): Promise<VectorStoreUpsertTaskOutput>;
108
108
  }
109
109
  export declare const chunkVectorUpsert: (input: VectorStoreUpsertTaskInput, config?: JobQueueTaskConfig) => Promise<{
110
- doc_id: string;
111
110
  count: number;
111
+ doc_id: string;
112
112
  chunk_ids: string[];
113
113
  }>;
114
114
  declare module "@workglow/task-graph" {
@@ -275,7 +275,6 @@ export declare class HierarchicalChunkerTask extends Task<HierarchicalChunkerTas
275
275
  private collectAllText;
276
276
  }
277
277
  export declare const hierarchicalChunker: (input: HierarchicalChunkerTaskInput, config?: JobQueueTaskConfig) => Promise<{
278
- doc_id: string;
279
278
  chunks: {
280
279
  [x: string]: unknown;
281
280
  doc_title?: string | undefined;
@@ -294,8 +293,9 @@ export declare const hierarchicalChunker: (input: HierarchicalChunkerTaskInput,
294
293
  nodePath: string[];
295
294
  depth: number;
296
295
  }[];
297
- text: string[];
298
296
  count: number;
297
+ doc_id: string;
298
+ text: string[];
299
299
  }>;
300
300
  declare module "@workglow/task-graph" {
301
301
  interface Workflow {
@@ -332,8 +332,8 @@ export declare const hierarchyJoin: (input: HierarchyJoinTaskInput, config?: Job
332
332
  depth: number;
333
333
  }[];
334
334
  chunks: string[];
335
- count: number;
336
335
  scores: number[];
336
+ count: number;
337
337
  chunk_ids: string[];
338
338
  }>;
339
339
  declare module "@workglow/task-graph" {
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Shared message conversion utilities for converting provider-agnostic
8
+ * ChatMessage arrays to provider-specific formats.
9
+ *
10
+ * These are pure functions safe for both main-thread and worker contexts.
11
+ * Providers with unique requirements (Anthropic, Gemini, LlamaCpp)
12
+ * maintain their own conversion logic.
13
+ */
14
+ import type { ToolCallingTaskInput } from "./ToolCallingTask";
15
+ export interface OpenAICompatMessage {
16
+ role: string;
17
+ content: string | null | Array<{
18
+ type: string;
19
+ [key: string]: unknown;
20
+ }>;
21
+ tool_calls?: Array<{
22
+ id: string;
23
+ type: "function";
24
+ function: {
25
+ name: string;
26
+ arguments: string;
27
+ };
28
+ }>;
29
+ tool_call_id?: string;
30
+ }
31
+ /**
32
+ * Converts ToolCallingTaskInput to OpenAI-compatible message format.
33
+ * Used by OpenAI and HuggingFace Inference providers.
34
+ *
35
+ * Multi-turn capable: preserves full tool call metadata across turns.
36
+ */
37
+ export declare function toOpenAIMessages(input: ToolCallingTaskInput): OpenAICompatMessage[];
38
+ export interface TextFlatMessage {
39
+ role: string;
40
+ content: string;
41
+ }
42
+ /**
43
+ * Converts ToolCallingTaskInput to a simplified text-only message format.
44
+ * Used by providers that don't natively support structured multi-turn
45
+ * tool calling (Ollama, HuggingFace Transformers).
46
+ *
47
+ * NOTE: This format discards tool_use blocks from assistant messages.
48
+ * The LLM will not see what tools it previously called. Multi-turn tool
49
+ * calling will have degraded quality on these providers.
50
+ */
51
+ export declare function toTextFlatMessages(input: ToolCallingTaskInput): TextFlatMessage[];
52
+ //# sourceMappingURL=MessageConversion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MessageConversion.d.ts","sourceRoot":"","sources":["../../src/task/MessageConversion.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAsB9D,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC,CAAC;IACzE,UAAU,CAAC,EAAE,KAAK,CAAC;QACjB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,UAAU,CAAC;QACjB,QAAQ,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAA;SAAE,CAAC;KAC/C,CAAC,CAAC;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,oBAAoB,GAAG,mBAAmB,EAAE,CAuInF;AAMD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,oBAAoB,GAAG,eAAe,EAAE,CAqFjF"}
@@ -115,9 +115,9 @@ export declare class QueryExpanderTask extends Task<QueryExpanderTaskInput, Quer
115
115
  private preserveCapitalization;
116
116
  }
117
117
  export declare const queryExpander: (input: QueryExpanderTaskInput, config?: JobQueueTaskConfig) => Promise<{
118
- count: number;
119
118
  query: string[];
120
119
  method: string;
120
+ count: number;
121
121
  originalQuery: string;
122
122
  }>;
123
123
  declare module "@workglow/task-graph" {
@@ -204,9 +204,9 @@ export declare const reranker: (input: RerankerTaskInput, config?: JobQueueTaskC
204
204
  [x: string]: unknown;
205
205
  }[] | undefined;
206
206
  chunks: string[];
207
- count: number;
208
207
  scores: number[];
209
208
  originalIndices: number[];
209
+ count: number;
210
210
  }>;
211
211
  declare module "@workglow/task-graph" {
212
212
  interface Workflow {