@atgs/tapeworm 0.0.1 → 0.0.2
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/agent/agent.d.ts +17 -0
- package/dist/conversation/conversation.d.ts +41 -0
- package/dist/index.d.ts +7 -0
- package/dist/model/OllamaModel.d.ts +27 -0
- package/dist/model/model.d.ts +84 -0
- package/dist/tool/tool.d.ts +15 -0
- package/dist/tool/toolCall.d.ts +26 -0
- package/dist/tool/toolschema.d.ts +91 -0
- package/package.json +3 -2
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Conversation, { ConversationManager } from "../conversation/conversation";
|
|
2
|
+
import { ModelResponse, type Model } from "../model/model";
|
|
3
|
+
import type Tool from "../tool/tool";
|
|
4
|
+
import type ToolCall from "../tool/toolCall";
|
|
5
|
+
export default class Agent {
|
|
6
|
+
name: string;
|
|
7
|
+
system_prompt?: string;
|
|
8
|
+
tools: Tool[];
|
|
9
|
+
model: Model;
|
|
10
|
+
conversation: Conversation;
|
|
11
|
+
conversationManager?: ConversationManager;
|
|
12
|
+
toolNameToIndexMap: any | undefined;
|
|
13
|
+
invoke(query: string): Promise<void>;
|
|
14
|
+
_runQuery(): Promise<ModelResponse>;
|
|
15
|
+
_runTool(toolCall: ToolCall): Promise<any>;
|
|
16
|
+
generateToolNameToIndexMap(): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Model } from "../model/model";
|
|
2
|
+
import type ToolCall from "../tool/toolCall";
|
|
3
|
+
export default class Conversation {
|
|
4
|
+
messages: Message[];
|
|
5
|
+
manager: ConversationManager;
|
|
6
|
+
constructor();
|
|
7
|
+
append(message: Message): void;
|
|
8
|
+
}
|
|
9
|
+
export declare class Message {
|
|
10
|
+
role: string;
|
|
11
|
+
content?: any;
|
|
12
|
+
toolCalls?: ToolCall[];
|
|
13
|
+
toolName?: string;
|
|
14
|
+
thinking?: string;
|
|
15
|
+
constructor(role: string, content: any, toolCalls: any[] | undefined, toolName: string | undefined, thinking: string | undefined);
|
|
16
|
+
setRole(role: string): void;
|
|
17
|
+
setContent(content: any): void;
|
|
18
|
+
setToolCalls(toolCalls: any): void;
|
|
19
|
+
static builder(): MessageBuilder;
|
|
20
|
+
}
|
|
21
|
+
export declare class MessageBuilder {
|
|
22
|
+
private _role;
|
|
23
|
+
private _content?;
|
|
24
|
+
private _toolCalls?;
|
|
25
|
+
private _toolName?;
|
|
26
|
+
private _thinking?;
|
|
27
|
+
role(role: string): MessageBuilder;
|
|
28
|
+
content(content: any): MessageBuilder;
|
|
29
|
+
toolCalls(toolCalls: ToolCall[]): MessageBuilder;
|
|
30
|
+
toolName(toolName: any): MessageBuilder;
|
|
31
|
+
thinking(thinking: string | undefined): MessageBuilder;
|
|
32
|
+
build(): Message;
|
|
33
|
+
}
|
|
34
|
+
export declare class ConversationManager {
|
|
35
|
+
compact(conversation: Message[]): Message[];
|
|
36
|
+
configure(model: Model): void;
|
|
37
|
+
}
|
|
38
|
+
export declare class DefaultConversationManager extends ConversationManager {
|
|
39
|
+
compact(conversation: Message[]): Message[];
|
|
40
|
+
configure(_model: Model): void;
|
|
41
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as Agent } from './agent/agent';
|
|
2
|
+
export { default as Conversation, Message, MessageBuilder, ConversationManager, DefaultConversationManager } from './conversation/conversation';
|
|
3
|
+
export { Model, ModelRequest, ModelRequestBuilder, ModelResponse, ModelResponseBuilder } from './model/model';
|
|
4
|
+
export { default as Tool } from './tool/tool';
|
|
5
|
+
export { default as ToolCall, ToolCallBuilder } from './tool/toolCall';
|
|
6
|
+
export { default as ToolSchema, ToolSchemaBuilder, Parameter, ParameterBuilder } from './tool/toolschema';
|
|
7
|
+
export { default as OllamaModel } from './model/OllamaModel';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Model, ModelRequest, ModelResponse } from "./model";
|
|
2
|
+
export default class OllamaModel extends Model {
|
|
3
|
+
endpoint: string;
|
|
4
|
+
model: string;
|
|
5
|
+
options?: any;
|
|
6
|
+
/**
|
|
7
|
+
* Create a model wrapper for an Ollama chat endpoint.
|
|
8
|
+
* @param endpoint Base URL of the Ollama server (e.g., http://localhost:11434).
|
|
9
|
+
* @param model Model name/tag to use for inference.
|
|
10
|
+
* @param options Additional Ollama options passed through to the API.
|
|
11
|
+
*/
|
|
12
|
+
constructor(endpoint: string, model: string, options: any);
|
|
13
|
+
/**
|
|
14
|
+
* Call the Ollama chat API with the provided conversation and tools.
|
|
15
|
+
* Formats the request, performs the HTTP POST, and translates the response into a ModelResponse.
|
|
16
|
+
*/
|
|
17
|
+
invoke(request: ModelRequest): Promise<ModelResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* Convert internal tool definitions into the JSON schema format expected by Ollama.
|
|
20
|
+
*/
|
|
21
|
+
_formatTools(request: ModelRequest): any;
|
|
22
|
+
/**
|
|
23
|
+
* Convert internal message objects into Ollama's chat message shape.
|
|
24
|
+
* Passes through assistant/system/user roles and maps tool role into the expected structure.
|
|
25
|
+
*/
|
|
26
|
+
_formatMessages(request: ModelRequest): any;
|
|
27
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { Message } from "../conversation/conversation";
|
|
2
|
+
import type Tool from "../tool/tool";
|
|
3
|
+
import type ToolCall from "../tool/toolCall";
|
|
4
|
+
/**
|
|
5
|
+
* A Model represents the LLM backend for the agent.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Model {
|
|
8
|
+
/**
|
|
9
|
+
* Execute the model against the provided request.
|
|
10
|
+
* @param request Aggregated messages and tools to send to the model.
|
|
11
|
+
*/
|
|
12
|
+
invoke(request: ModelRequest): Promise<ModelResponse>;
|
|
13
|
+
/**
|
|
14
|
+
* Return the maximum token budget supported by this model.
|
|
15
|
+
*/
|
|
16
|
+
tokenLimit(): void;
|
|
17
|
+
}
|
|
18
|
+
export declare class ModelRequest {
|
|
19
|
+
messages: Message[];
|
|
20
|
+
tools: Tool[];
|
|
21
|
+
/**
|
|
22
|
+
* Create a new model request envelope.
|
|
23
|
+
* @param messages Conversation history to send to the model.
|
|
24
|
+
* @param tools Tool definitions available for function calling.
|
|
25
|
+
*/
|
|
26
|
+
constructor(messages: Message[], tools: Tool[]);
|
|
27
|
+
static builder(): ModelRequestBuilder;
|
|
28
|
+
}
|
|
29
|
+
export declare class ModelRequestBuilder {
|
|
30
|
+
private _messages;
|
|
31
|
+
private _tools;
|
|
32
|
+
/**
|
|
33
|
+
* Supply the conversation messages to include.
|
|
34
|
+
*/
|
|
35
|
+
messages(messages: Message[]): ModelRequestBuilder;
|
|
36
|
+
/**
|
|
37
|
+
* Supply the tool list for this request.
|
|
38
|
+
*/
|
|
39
|
+
tools(tools: Tool[]): ModelRequestBuilder;
|
|
40
|
+
/**
|
|
41
|
+
* Build the ModelRequest, defaulting tools to an empty array.
|
|
42
|
+
*/
|
|
43
|
+
build(): ModelRequest;
|
|
44
|
+
}
|
|
45
|
+
export declare class ModelResponse {
|
|
46
|
+
toolCalls?: ToolCall[];
|
|
47
|
+
role?: string;
|
|
48
|
+
content?: string;
|
|
49
|
+
thinking?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Wrap a model response.
|
|
52
|
+
* @param toolCalls Optional tool calls returned by the model.
|
|
53
|
+
* @param role Role of the message (e.g., assistant, tool).
|
|
54
|
+
* @param content Text content returned by the model.
|
|
55
|
+
*/
|
|
56
|
+
constructor(toolCalls: ToolCall[], role: string | undefined, content: string | undefined, thinking: string | undefined);
|
|
57
|
+
static builder(): ModelResponseBuilder;
|
|
58
|
+
}
|
|
59
|
+
export declare class ModelResponseBuilder {
|
|
60
|
+
private _toolCalls;
|
|
61
|
+
private _role?;
|
|
62
|
+
private _content?;
|
|
63
|
+
private _thinking?;
|
|
64
|
+
/**
|
|
65
|
+
* Attach tool calls to the response.
|
|
66
|
+
*/
|
|
67
|
+
toolCalls(toolCalls: ToolCall[]): ModelResponseBuilder;
|
|
68
|
+
/**
|
|
69
|
+
* Set the role for the response message.
|
|
70
|
+
*/
|
|
71
|
+
role(role: string): ModelResponseBuilder;
|
|
72
|
+
/**
|
|
73
|
+
* Set the textual content for the response message.
|
|
74
|
+
*/
|
|
75
|
+
content(content: string): ModelResponseBuilder;
|
|
76
|
+
/**
|
|
77
|
+
* Set the thinking content for the response message.
|
|
78
|
+
*/
|
|
79
|
+
thinking(thinking: string): ModelResponseBuilder;
|
|
80
|
+
/**
|
|
81
|
+
* Build the ModelResponse from the collected fields.
|
|
82
|
+
*/
|
|
83
|
+
build(): ModelResponse;
|
|
84
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type ToolSchema from "./toolschema";
|
|
2
|
+
/**
|
|
3
|
+
* The Tool class represents a tool that a Tapeworm agent can use.
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
export default class Tool {
|
|
7
|
+
private name;
|
|
8
|
+
private description;
|
|
9
|
+
private tool_schema;
|
|
10
|
+
constructor();
|
|
11
|
+
getName(): string;
|
|
12
|
+
getDescription(): string;
|
|
13
|
+
getToolSchema(): ToolSchema;
|
|
14
|
+
execute(input: any): any;
|
|
15
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a single tool invocation returned by a model, including the target
|
|
3
|
+
* tool name, argument map, type (function/spec), and optional sequence number.
|
|
4
|
+
*/
|
|
5
|
+
export default class ToolCall {
|
|
6
|
+
sequence: number | undefined;
|
|
7
|
+
name: string;
|
|
8
|
+
parameters: any;
|
|
9
|
+
type: string;
|
|
10
|
+
constructor(sequence: number | undefined, name: string, parameters: any, type: string);
|
|
11
|
+
static builder(): ToolCallBuilder;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Fluent builder for constructing ToolCall instances from model output.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ToolCallBuilder {
|
|
17
|
+
private _sequence;
|
|
18
|
+
private _name;
|
|
19
|
+
private _parameters;
|
|
20
|
+
private _type;
|
|
21
|
+
sequence(sequence: number | undefined): ToolCallBuilder;
|
|
22
|
+
name(name: string): this;
|
|
23
|
+
parameters(parameters: any): ToolCallBuilder;
|
|
24
|
+
type(type: string): ToolCallBuilder;
|
|
25
|
+
build(): ToolCall;
|
|
26
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool schemas specify the input and output of a tool.
|
|
3
|
+
*/
|
|
4
|
+
export default class ToolSchema {
|
|
5
|
+
parameters: Parameter[];
|
|
6
|
+
output: string;
|
|
7
|
+
/**
|
|
8
|
+
* Create a new tool schema.
|
|
9
|
+
* @param parameters Ordered list of input parameters the tool accepts.
|
|
10
|
+
* @param output Human-readable description of the tool output.
|
|
11
|
+
*/
|
|
12
|
+
constructor(parameters: Parameter[], output: string);
|
|
13
|
+
/**
|
|
14
|
+
* Return a tool schema builder, so you can properly construct tools instead of dealing with the constructor
|
|
15
|
+
* @returns a tool schema builder.
|
|
16
|
+
*/
|
|
17
|
+
static builder(): ToolSchemaBuilder;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A builder for tool schemas
|
|
21
|
+
*/
|
|
22
|
+
export declare class ToolSchemaBuilder {
|
|
23
|
+
private _parameters;
|
|
24
|
+
private _output;
|
|
25
|
+
/**
|
|
26
|
+
* Add a parameter definition to the schema.
|
|
27
|
+
* @param parameter Fully constructed parameter to append.
|
|
28
|
+
*/
|
|
29
|
+
addParameter(parameter: Parameter): ToolSchemaBuilder;
|
|
30
|
+
/**
|
|
31
|
+
* Describe the output of the tool.
|
|
32
|
+
* @param output Text description of what the tool returns.
|
|
33
|
+
*/
|
|
34
|
+
output(output: string): ToolSchemaBuilder;
|
|
35
|
+
/**
|
|
36
|
+
* Build the ToolSchema instance from the collected fields.
|
|
37
|
+
*/
|
|
38
|
+
build(): ToolSchema;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A Parameter for a tool.
|
|
42
|
+
* Includes:
|
|
43
|
+
* - The name of the parameter
|
|
44
|
+
* - What the parameter is used for
|
|
45
|
+
* - The type of the parameter
|
|
46
|
+
*/
|
|
47
|
+
export declare class Parameter {
|
|
48
|
+
name: string;
|
|
49
|
+
description: string;
|
|
50
|
+
type: string;
|
|
51
|
+
required: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Create a new parameter definition.
|
|
54
|
+
* @param name Identifier for the parameter.
|
|
55
|
+
* @param description Explanation of how the parameter is used.
|
|
56
|
+
* @param type JSON-serializable type name (e.g., string, number).
|
|
57
|
+
* @param required Whether the parameter must be provided.
|
|
58
|
+
*/
|
|
59
|
+
constructor(name: string, description: string, type: string, required: boolean);
|
|
60
|
+
/**
|
|
61
|
+
* Placeholder for validating supported parameter types.
|
|
62
|
+
*/
|
|
63
|
+
assertValidType(): void;
|
|
64
|
+
static builder(): ParameterBuilder;
|
|
65
|
+
}
|
|
66
|
+
export declare class ParameterBuilder {
|
|
67
|
+
private _name;
|
|
68
|
+
private _description;
|
|
69
|
+
private _type;
|
|
70
|
+
private _required?;
|
|
71
|
+
/**
|
|
72
|
+
* Set the parameter name.
|
|
73
|
+
*/
|
|
74
|
+
name(name: string): ParameterBuilder;
|
|
75
|
+
/**
|
|
76
|
+
* Set the parameter description.
|
|
77
|
+
*/
|
|
78
|
+
description(description: string): ParameterBuilder;
|
|
79
|
+
/**
|
|
80
|
+
* Set the parameter type.
|
|
81
|
+
*/
|
|
82
|
+
type(type: string): ParameterBuilder;
|
|
83
|
+
/**
|
|
84
|
+
* Mark the parameter as required or optional.
|
|
85
|
+
*/
|
|
86
|
+
required(required: boolean): ParameterBuilder;
|
|
87
|
+
/**
|
|
88
|
+
* Build a Parameter instance using the accumulated fields.
|
|
89
|
+
*/
|
|
90
|
+
build(): Parameter;
|
|
91
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atgs/tapeworm",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/tapeworm.cjs.js",
|
|
6
6
|
"module": "dist/tapeworm.es.js",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"dist"
|
|
11
11
|
],
|
|
12
12
|
"scripts": {
|
|
13
|
-
"build": "vite build",
|
|
13
|
+
"build": "vite build && npm run build:types",
|
|
14
|
+
"build:types": "tsc -p tsconfig.types.json",
|
|
14
15
|
"test": "jest"
|
|
15
16
|
},
|
|
16
17
|
"devDependencies": {
|