@codeworksh/aikit 0.3.0 → 0.4.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 +73 -81
- package/{agent → dist/pack/agent}/codemode/drivers/drivers.d.mts +1 -1
- package/dist/pack/codemode-BEDXG7WN.d.mts +8736 -0
- package/{index.d.mts → dist/pack/index.d.mts} +3 -3
- package/dist/pack/index.mjs +8226 -0
- package/dist/pack/index.mjs.map +1 -0
- package/package.json +32 -22
- package/src/agent/agent.ts +790 -0
- package/src/agent/codemode/codemode.ts +561 -0
- package/src/agent/codemode/drivers/drivers.ts +1 -0
- package/src/agent/codemode/drivers/quickjs-wasi-driver.ts +149 -0
- package/src/agent/codemode/index.ts +1 -0
- package/src/agent/loop.ts +903 -0
- package/src/agent.ts +11 -0
- package/src/event/event.ts +277 -0
- package/src/index.ts +6 -0
- package/src/llm.ts +31 -0
- package/src/message/message.ts +311 -0
- package/src/model/catalog.ts +94 -0
- package/src/model/model.ts +250 -0
- package/src/model/transform.ts +59 -0
- package/src/provider/provider.ts +60 -0
- package/src/provider/providers/anthropic/index.ts +792 -0
- package/src/provider/providers/github/github.ts +34 -0
- package/src/provider/providers/openai/completions.ts +953 -0
- package/src/provider/providers/utils.ts +7 -0
- package/src/provider/register.ts +6 -0
- package/src/provider/stream.ts +278 -0
- package/src/stream.ts +72 -0
- package/src/utils/eventstream.ts +95 -0
- package/src/utils/helpers.ts +24 -0
- package/src/utils/jsonparse.ts +32 -0
- package/src/utils/overflow.ts +121 -0
- package/src/utils/sanitize.ts +25 -0
- package/src/utils/validation.ts +87 -0
- package/LICENSE +0 -21
- package/codemode-z3ZIw-5q.d.mts +0 -8234
- package/index.mjs +0 -2694
- package/index.mjs.map +0 -1
- /package/{agent → dist/pack/agent}/codemode/drivers/drivers.mjs +0 -0
- /package/{agent → dist/pack/agent}/codemode/drivers/drivers.mjs.map +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @codeworksh/aikit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
@codeworksh/aikit is **TypeScript SDK** for building AI agents and agentic harness. Provides a unified API for working with multiple LLM providers and support for tool calling(function calling) required for agentic workflows.
|
|
4
|
+
|
|
5
|
+
@codeworksh/aikit isn't just another SDK. It gives you the basic primitives for streaming LLM responses without the extra bloat, letting you handle the agentic orchestration yourself.
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
@@ -10,7 +12,7 @@ npm install @codeworksh/aikit
|
|
|
10
12
|
|
|
11
13
|
Node `>=24.14.1` is required.
|
|
12
14
|
|
|
13
|
-
##
|
|
15
|
+
## API Overview
|
|
14
16
|
|
|
15
17
|
- `llm(...)` to resolve a model from the built-in registry
|
|
16
18
|
- `stream(...)` and `stream.complete(...)` for provider-normalized LLM streaming
|
|
@@ -18,21 +20,15 @@ Node `>=24.14.1` is required.
|
|
|
18
20
|
- `agent.loop(...)` and `agent.loopContinue(...)` for lower-level turn orchestration
|
|
19
21
|
- `Message` helpers for typed messages and generated `messageId` values
|
|
20
22
|
|
|
21
|
-
## Root API
|
|
22
|
-
|
|
23
|
-
```ts
|
|
24
|
-
import { Agent, Message, agent, llm, stream } from "@codeworksh/aikit";
|
|
25
|
-
```
|
|
26
|
-
|
|
27
23
|
## Quick Start
|
|
28
24
|
|
|
29
25
|
```ts
|
|
30
26
|
import { Agent } from "@codeworksh/aikit";
|
|
31
27
|
|
|
32
28
|
const agent = await Agent.create({
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
provider: "anthropic",
|
|
30
|
+
model: "claude-haiku-4-5-20251001",
|
|
31
|
+
getApiKey: async () => process.env.ANTHROPIC_API_KEY,
|
|
36
32
|
});
|
|
37
33
|
|
|
38
34
|
agent.setSystemPrompt("Be concise.");
|
|
@@ -55,23 +51,23 @@ const model = await llm("anthropic", "claude-haiku-4-5-20251001");
|
|
|
55
51
|
if (!model) throw new Error("Model not found");
|
|
56
52
|
|
|
57
53
|
const s = stream(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
54
|
+
model,
|
|
55
|
+
{
|
|
56
|
+
messages: [
|
|
57
|
+
Message.createUserMessage({
|
|
58
|
+
role: "user",
|
|
59
|
+
time: { created: Date.now() },
|
|
60
|
+
parts: [{ type: "text", text: "Count from 1 to 3" }],
|
|
61
|
+
}),
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
{ apiKey: process.env.ANTHROPIC_API_KEY },
|
|
69
65
|
);
|
|
70
66
|
|
|
71
67
|
for await (const event of s) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
if (event.type === "text.delta") {
|
|
69
|
+
process.stdout.write(event.delta);
|
|
70
|
+
}
|
|
75
71
|
}
|
|
76
72
|
|
|
77
73
|
const finalMessage = await s.result();
|
|
@@ -86,17 +82,17 @@ console.log(finalMessage.messageId);
|
|
|
86
82
|
import { Agent } from "@codeworksh/aikit";
|
|
87
83
|
|
|
88
84
|
const agent = await Agent.create({
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
85
|
+
provider: "anthropic",
|
|
86
|
+
model: "claude-haiku-4-5-20251001",
|
|
87
|
+
getApiKey: async () => process.env.ANTHROPIC_API_KEY,
|
|
92
88
|
});
|
|
93
89
|
|
|
94
90
|
agent.setSystemPrompt("Be concise.");
|
|
95
91
|
|
|
96
92
|
agent.subscribe((event) => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
if (event.type === "message.end") {
|
|
94
|
+
console.log(event.message.role, event.message.messageId);
|
|
95
|
+
}
|
|
100
96
|
});
|
|
101
97
|
|
|
102
98
|
await agent.prompt([{ type: "text", text: "Say hello in one line." }]);
|
|
@@ -111,33 +107,35 @@ import { Type } from "@sinclair/typebox";
|
|
|
111
107
|
import { Agent } from "@codeworksh/aikit";
|
|
112
108
|
|
|
113
109
|
const calculatorTool = Agent.defineTool({
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
110
|
+
name: "calculator",
|
|
111
|
+
label: "Calculator",
|
|
112
|
+
description: "Evaluate arithmetic expressions",
|
|
113
|
+
parameters: Type.Object({
|
|
114
|
+
expression: Type.String(),
|
|
115
|
+
}),
|
|
116
|
+
async execute(_callID, params) {
|
|
117
|
+
return {
|
|
118
|
+
status: "completed",
|
|
119
|
+
result: {
|
|
120
|
+
content: [{ type: "text", text: `result for ${params.expression}` }],
|
|
121
|
+
isError: false,
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
},
|
|
129
125
|
});
|
|
130
126
|
|
|
131
127
|
const instance = await Agent.create({
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
128
|
+
provider: "anthropic",
|
|
129
|
+
model: "claude-haiku-4-5-20251001",
|
|
130
|
+
getApiKey: async () => process.env.ANTHROPIC_API_KEY,
|
|
131
|
+
initialState: {
|
|
132
|
+
tools: [calculatorTool],
|
|
133
|
+
},
|
|
138
134
|
});
|
|
139
135
|
|
|
140
|
-
await instance.prompt([
|
|
136
|
+
await instance.prompt([
|
|
137
|
+
{ type: "text", text: "Use the calculator tool for 25 * 18." },
|
|
138
|
+
]);
|
|
141
139
|
```
|
|
142
140
|
|
|
143
141
|
## Lower-Level Loop
|
|
@@ -151,23 +149,23 @@ const model = await llm("anthropic", "claude-haiku-4-5-20251001");
|
|
|
151
149
|
if (!model) throw new Error("Model not found");
|
|
152
150
|
|
|
153
151
|
const run = agent.loop(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
152
|
+
{
|
|
153
|
+
model,
|
|
154
|
+
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
155
|
+
convertToLlm: async (messages) => messages,
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
systemPrompt: "Be concise.",
|
|
159
|
+
messages: [],
|
|
160
|
+
tools: [],
|
|
161
|
+
},
|
|
162
|
+
[
|
|
163
|
+
Message.createUserMessage({
|
|
164
|
+
role: "user",
|
|
165
|
+
time: { created: Date.now() },
|
|
166
|
+
parts: [{ type: "text", text: "Reply with exactly: ok" }],
|
|
167
|
+
}),
|
|
168
|
+
],
|
|
171
169
|
);
|
|
172
170
|
|
|
173
171
|
const messages = await run.result();
|
|
@@ -184,9 +182,9 @@ Use the helpers when constructing messages yourself:
|
|
|
184
182
|
import { Message } from "@codeworksh/aikit";
|
|
185
183
|
|
|
186
184
|
const userMessage = Message.createUserMessage({
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
185
|
+
role: "user",
|
|
186
|
+
time: { created: Date.now() },
|
|
187
|
+
parts: [{ type: "text", text: "hello" }],
|
|
190
188
|
});
|
|
191
189
|
|
|
192
190
|
console.log(userMessage.messageId);
|
|
@@ -194,12 +192,6 @@ console.log(userMessage.messageId);
|
|
|
194
192
|
|
|
195
193
|
This is useful for persistence layers like SQLite, event reconciliation, and updating stored messages by identity instead of array position.
|
|
196
194
|
|
|
197
|
-
##
|
|
198
|
-
|
|
199
|
-
- `stream(...)`: raw provider-normalized stream
|
|
200
|
-
- `stream.complete(...)`: final assistant message without manual iteration
|
|
201
|
-
- `Agent.create(...)`: stateful agent instance
|
|
202
|
-
- `agent.loop(...)`: lower-level agent loop
|
|
203
|
-
- `agent.loopContinue(...)`: continue from an existing context
|
|
195
|
+
## Contribute
|
|
204
196
|
|
|
205
|
-
|
|
197
|
+
@codeworksh/aikit is open to community contribution. Please ensure you submit an issue before submitting a pull request. The @codeworksh/aikit project prefers open community discussion before accepting new features.
|