@clinebot/agents 0.0.0
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/README.md +145 -0
- package/dist/agent-input.d.ts +2 -0
- package/dist/agent.d.ts +56 -0
- package/dist/extensions.d.ts +21 -0
- package/dist/hooks/engine.d.ts +42 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/lifecycle.d.ts +5 -0
- package/dist/hooks/node.d.ts +2 -0
- package/dist/hooks/subprocess-runner.d.ts +16 -0
- package/dist/hooks/subprocess.d.ts +268 -0
- package/dist/index.browser.d.ts +1 -0
- package/dist/index.browser.js +49 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +49 -0
- package/dist/index.node.d.ts +5 -0
- package/dist/index.node.js +49 -0
- package/dist/mcp/index.d.ts +4 -0
- package/dist/mcp/policies.d.ts +14 -0
- package/dist/mcp/tools.d.ts +9 -0
- package/dist/mcp/types.d.ts +35 -0
- package/dist/message-builder.d.ts +31 -0
- package/dist/prompts/cline.d.ts +1 -0
- package/dist/prompts/index.d.ts +1 -0
- package/dist/runtime/agent-runtime-bus.d.ts +13 -0
- package/dist/runtime/conversation-store.d.ts +16 -0
- package/dist/runtime/lifecycle-orchestrator.d.ts +28 -0
- package/dist/runtime/tool-orchestrator.d.ts +39 -0
- package/dist/runtime/turn-processor.d.ts +21 -0
- package/dist/teams/index.d.ts +3 -0
- package/dist/teams/multi-agent.d.ts +566 -0
- package/dist/teams/spawn-agent-tool.d.ts +85 -0
- package/dist/teams/team-tools.d.ts +51 -0
- package/dist/tools/ask-question.d.ts +12 -0
- package/dist/tools/create.d.ts +59 -0
- package/dist/tools/execution.d.ts +61 -0
- package/dist/tools/formatting.d.ts +20 -0
- package/dist/tools/index.d.ts +11 -0
- package/dist/tools/registry.d.ts +26 -0
- package/dist/tools/validation.d.ts +27 -0
- package/dist/types.d.ts +826 -0
- package/package.json +54 -0
- package/src/agent-input.ts +116 -0
- package/src/agent.test.ts +931 -0
- package/src/agent.ts +1050 -0
- package/src/example.test.ts +564 -0
- package/src/extensions.ts +337 -0
- package/src/hooks/engine.test.ts +163 -0
- package/src/hooks/engine.ts +537 -0
- package/src/hooks/index.ts +6 -0
- package/src/hooks/lifecycle.ts +239 -0
- package/src/hooks/node.ts +18 -0
- package/src/hooks/subprocess-runner.ts +140 -0
- package/src/hooks/subprocess.test.ts +180 -0
- package/src/hooks/subprocess.ts +620 -0
- package/src/index.browser.ts +1 -0
- package/src/index.node.ts +21 -0
- package/src/index.ts +133 -0
- package/src/mcp/index.ts +17 -0
- package/src/mcp/policies.test.ts +51 -0
- package/src/mcp/policies.ts +53 -0
- package/src/mcp/tools.test.ts +76 -0
- package/src/mcp/tools.ts +60 -0
- package/src/mcp/types.ts +41 -0
- package/src/message-builder.test.ts +175 -0
- package/src/message-builder.ts +429 -0
- package/src/prompts/cline.ts +49 -0
- package/src/prompts/index.ts +1 -0
- package/src/runtime/agent-runtime-bus.ts +53 -0
- package/src/runtime/conversation-store.ts +61 -0
- package/src/runtime/lifecycle-orchestrator.ts +90 -0
- package/src/runtime/tool-orchestrator.ts +177 -0
- package/src/runtime/turn-processor.ts +250 -0
- package/src/streaming.test.ts +197 -0
- package/src/streaming.ts +307 -0
- package/src/teams/index.ts +63 -0
- package/src/teams/multi-agent.lifecycle.test.ts +48 -0
- package/src/teams/multi-agent.ts +1866 -0
- package/src/teams/spawn-agent-tool.test.ts +172 -0
- package/src/teams/spawn-agent-tool.ts +223 -0
- package/src/teams/team-tools.test.ts +448 -0
- package/src/teams/team-tools.ts +929 -0
- package/src/tools/ask-question.ts +78 -0
- package/src/tools/create.ts +104 -0
- package/src/tools/execution.ts +311 -0
- package/src/tools/formatting.ts +73 -0
- package/src/tools/index.ts +45 -0
- package/src/tools/registry.ts +52 -0
- package/src/tools/tools.test.ts +292 -0
- package/src/tools/validation.ts +73 -0
- package/src/types.ts +966 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Creation Utilities
|
|
3
|
+
*
|
|
4
|
+
* Functions for creating tools with proper typing.
|
|
5
|
+
*/
|
|
6
|
+
import type { providers as LlmsProviders } from "@clinebot/llms";
|
|
7
|
+
import { type Tool, type ToolContext } from "@clinebot/shared";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
/**
|
|
10
|
+
* Create a tool with proper typing
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const readFile = createTool({
|
|
15
|
+
* name: "read_file",
|
|
16
|
+
* description: "Read the contents of a file",
|
|
17
|
+
* inputSchema: {
|
|
18
|
+
* type: "object",
|
|
19
|
+
* properties: {
|
|
20
|
+
* path: { type: "string", description: "File path to read" }
|
|
21
|
+
* },
|
|
22
|
+
* required: ["path"]
|
|
23
|
+
* },
|
|
24
|
+
* execute: async ({ path }) => {
|
|
25
|
+
* const content = await fs.readFile(path, "utf-8")
|
|
26
|
+
* return { content }
|
|
27
|
+
* }
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function createTool<TInput, TOutput>(config: {
|
|
32
|
+
name: string;
|
|
33
|
+
description: string;
|
|
34
|
+
inputSchema: Record<string, unknown>;
|
|
35
|
+
execute: (input: TInput, context: ToolContext) => Promise<TOutput>;
|
|
36
|
+
timeoutMs?: number;
|
|
37
|
+
retryable?: boolean;
|
|
38
|
+
maxRetries?: number;
|
|
39
|
+
}): Tool<TInput, TOutput>;
|
|
40
|
+
export declare function createTool<TSchema extends z.ZodTypeAny, TOutput>(config: {
|
|
41
|
+
name: string;
|
|
42
|
+
description: string;
|
|
43
|
+
inputSchema: TSchema;
|
|
44
|
+
execute: (input: z.infer<TSchema>, context: ToolContext) => Promise<TOutput>;
|
|
45
|
+
timeoutMs?: number;
|
|
46
|
+
retryable?: boolean;
|
|
47
|
+
maxRetries?: number;
|
|
48
|
+
}): Tool<z.infer<TSchema>, TOutput>;
|
|
49
|
+
/**
|
|
50
|
+
* Convert a Tool to a ToolDefinition for the provider
|
|
51
|
+
*
|
|
52
|
+
* This transforms our internal Tool format into the format expected
|
|
53
|
+
* by the provider's API.
|
|
54
|
+
*/
|
|
55
|
+
export declare function toToolDefinition(tool: Tool): LlmsProviders.ToolDefinition;
|
|
56
|
+
/**
|
|
57
|
+
* Convert an array of Tools to ToolDefinitions
|
|
58
|
+
*/
|
|
59
|
+
export declare function toToolDefinitions(tools: Tool[]): LlmsProviders.ToolDefinition[];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Execution
|
|
3
|
+
*
|
|
4
|
+
* Functions for executing tools with error handling, timeouts, and retries.
|
|
5
|
+
*/
|
|
6
|
+
import type { Tool, ToolCallRecord, ToolContext } from "@clinebot/shared";
|
|
7
|
+
import type { PendingToolCall } from "../types.js";
|
|
8
|
+
export interface ToolExecutionObserver {
|
|
9
|
+
onToolCallStart?: (call: PendingToolCall) => Promise<void> | void;
|
|
10
|
+
onToolCallEnd?: (record: ToolCallRecord) => Promise<void> | void;
|
|
11
|
+
}
|
|
12
|
+
export interface ToolExecutionAuthorizer {
|
|
13
|
+
authorize?: (call: PendingToolCall, context: ToolContext) => Promise<{
|
|
14
|
+
allowed: true;
|
|
15
|
+
} | {
|
|
16
|
+
allowed: false;
|
|
17
|
+
reason: string;
|
|
18
|
+
}> | {
|
|
19
|
+
allowed: true;
|
|
20
|
+
} | {
|
|
21
|
+
allowed: false;
|
|
22
|
+
reason: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export interface ToolExecutionOptions {
|
|
26
|
+
maxConcurrency?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Execute a single tool with error handling and timeout
|
|
30
|
+
*
|
|
31
|
+
* @param tool - The tool to execute
|
|
32
|
+
* @param input - The input to pass to the tool
|
|
33
|
+
* @param context - The execution context
|
|
34
|
+
* @returns A record of the tool call execution
|
|
35
|
+
*/
|
|
36
|
+
export declare function executeTool(tool: Tool, input: unknown, context: ToolContext): Promise<{
|
|
37
|
+
output: unknown;
|
|
38
|
+
error?: string;
|
|
39
|
+
durationMs: number;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Execute a tool with retries
|
|
43
|
+
*/
|
|
44
|
+
export declare function executeToolWithRetry(tool: Tool, input: unknown, context: ToolContext): Promise<{
|
|
45
|
+
output: unknown;
|
|
46
|
+
error?: string;
|
|
47
|
+
durationMs: number;
|
|
48
|
+
}>;
|
|
49
|
+
/**
|
|
50
|
+
* Execute multiple tools in parallel
|
|
51
|
+
*
|
|
52
|
+
* @param toolRegistry - Map of tools by name
|
|
53
|
+
* @param calls - Array of tool calls to execute
|
|
54
|
+
* @param context - The execution context
|
|
55
|
+
* @returns Array of tool call records
|
|
56
|
+
*/
|
|
57
|
+
export declare function executeToolsInParallel(toolRegistry: Map<string, Tool>, calls: PendingToolCall[], context: ToolContext, observer?: ToolExecutionObserver, authorizer?: ToolExecutionAuthorizer, options?: ToolExecutionOptions): Promise<ToolCallRecord[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Execute tools sequentially (for cases where order matters)
|
|
60
|
+
*/
|
|
61
|
+
export declare function executeToolsSequentially(toolRegistry: Map<string, Tool>, calls: PendingToolCall[], context: ToolContext, observer?: ToolExecutionObserver, authorizer?: ToolExecutionAuthorizer): Promise<ToolCallRecord[]>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Result Formatting
|
|
3
|
+
*
|
|
4
|
+
* Functions for formatting tool results for various purposes.
|
|
5
|
+
*/
|
|
6
|
+
import type { ToolCallRecord } from "../types.js";
|
|
7
|
+
/**
|
|
8
|
+
* Format a tool result for sending back to the model
|
|
9
|
+
*
|
|
10
|
+
* The result is serialized to a string (JSON for objects, string for primitives)
|
|
11
|
+
*/
|
|
12
|
+
export declare function formatToolResult(output: unknown, error?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Format multiple tool results into a structured summary
|
|
15
|
+
*/
|
|
16
|
+
export declare function formatToolResultsSummary(records: ToolCallRecord[]): string;
|
|
17
|
+
/**
|
|
18
|
+
* Format a tool call record as a detailed string
|
|
19
|
+
*/
|
|
20
|
+
export declare function formatToolCallRecord(record: ToolCallRecord): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for creating, managing, and executing tools.
|
|
5
|
+
*/
|
|
6
|
+
export { type AskQuestionExecutor, type AskQuestionInput, AskQuestionInputSchema, type AskQuestionToolConfig, createAskQuestionTool, } from "./ask-question.js";
|
|
7
|
+
export { createTool, toToolDefinition, toToolDefinitions } from "./create.js";
|
|
8
|
+
export { executeTool, executeToolsInParallel, executeToolsSequentially, executeToolWithRetry, type ToolExecutionAuthorizer, type ToolExecutionObserver, } from "./execution.js";
|
|
9
|
+
export { formatToolCallRecord, formatToolResult, formatToolResultsSummary, } from "./formatting.js";
|
|
10
|
+
export { createToolRegistry, getAllTools, getTool, getToolNames, hasTool, } from "./registry.js";
|
|
11
|
+
export { validateToolDefinition, validateToolInput, validateTools, } from "./validation.js";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Registry
|
|
3
|
+
*
|
|
4
|
+
* Utilities for managing collections of tools.
|
|
5
|
+
*/
|
|
6
|
+
import type { Tool } from "../types.js";
|
|
7
|
+
/**
|
|
8
|
+
* Create a map of tools by name for quick lookup
|
|
9
|
+
*/
|
|
10
|
+
export declare function createToolRegistry(tools: Tool[]): Map<string, Tool>;
|
|
11
|
+
/**
|
|
12
|
+
* Get a tool by name from the registry
|
|
13
|
+
*/
|
|
14
|
+
export declare function getTool(registry: Map<string, Tool>, name: string): Tool | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Check if a tool exists in the registry
|
|
17
|
+
*/
|
|
18
|
+
export declare function hasTool(registry: Map<string, Tool>, name: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Get all tool names from the registry
|
|
21
|
+
*/
|
|
22
|
+
export declare function getToolNames(registry: Map<string, Tool>): string[];
|
|
23
|
+
/**
|
|
24
|
+
* Get all tools from the registry
|
|
25
|
+
*/
|
|
26
|
+
export declare function getAllTools(registry: Map<string, Tool>): Tool[];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Validation
|
|
3
|
+
*
|
|
4
|
+
* Functions for validating tools and tool inputs.
|
|
5
|
+
*/
|
|
6
|
+
import type { Tool } from "../types.js";
|
|
7
|
+
/**
|
|
8
|
+
* Validate that all tools have unique names
|
|
9
|
+
*/
|
|
10
|
+
export declare function validateTools(tools: Tool[]): void;
|
|
11
|
+
/**
|
|
12
|
+
* Validate tool input against its schema (basic validation)
|
|
13
|
+
*
|
|
14
|
+
* Note: This is a simplified validation. For full JSON Schema validation,
|
|
15
|
+
* consider using a library like ajv.
|
|
16
|
+
*/
|
|
17
|
+
export declare function validateToolInput(tool: Tool, input: unknown): {
|
|
18
|
+
valid: boolean;
|
|
19
|
+
error?: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Validate a tool definition
|
|
23
|
+
*/
|
|
24
|
+
export declare function validateToolDefinition(tool: Tool): {
|
|
25
|
+
valid: boolean;
|
|
26
|
+
errors: string[];
|
|
27
|
+
};
|