@codeworksh/aikit 0.3.1 → 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.
Files changed (41) hide show
  1. package/README.md +73 -81
  2. package/{agent → dist/pack/agent}/codemode/drivers/drivers.d.mts +1 -1
  3. package/dist/pack/codemode-BEDXG7WN.d.mts +8736 -0
  4. package/{index.d.mts → dist/pack/index.d.mts} +1 -1
  5. package/dist/pack/index.mjs +8226 -0
  6. package/dist/pack/index.mjs.map +1 -0
  7. package/package.json +31 -24
  8. package/src/agent/agent.ts +790 -0
  9. package/src/agent/codemode/codemode.ts +561 -0
  10. package/src/agent/codemode/drivers/drivers.ts +1 -0
  11. package/src/agent/codemode/drivers/quickjs-wasi-driver.ts +149 -0
  12. package/src/agent/codemode/index.ts +1 -0
  13. package/src/agent/loop.ts +903 -0
  14. package/src/agent.ts +11 -0
  15. package/src/event/event.ts +277 -0
  16. package/src/index.ts +6 -0
  17. package/src/llm.ts +31 -0
  18. package/src/message/message.ts +311 -0
  19. package/src/model/catalog.ts +94 -0
  20. package/src/model/model.ts +250 -0
  21. package/src/model/transform.ts +59 -0
  22. package/src/provider/provider.ts +60 -0
  23. package/src/provider/providers/anthropic/index.ts +792 -0
  24. package/src/provider/providers/github/github.ts +34 -0
  25. package/src/provider/providers/openai/completions.ts +953 -0
  26. package/src/provider/providers/utils.ts +7 -0
  27. package/src/provider/register.ts +6 -0
  28. package/src/provider/stream.ts +278 -0
  29. package/src/stream.ts +72 -0
  30. package/src/utils/eventstream.ts +95 -0
  31. package/src/utils/helpers.ts +24 -0
  32. package/src/utils/jsonparse.ts +32 -0
  33. package/src/utils/overflow.ts +121 -0
  34. package/src/utils/sanitize.ts +25 -0
  35. package/src/utils/validation.ts +87 -0
  36. package/LICENSE +0 -21
  37. package/codemode-SiETGR3z.d.mts +0 -8410
  38. package/index.mjs +0 -3381
  39. package/index.mjs.map +0 -1
  40. /package/{agent → dist/pack/agent}/codemode/drivers/drivers.mjs +0 -0
  41. /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
- Toolkit for building AI agents and streaming LLM workflows.
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
- ## What You Get
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
- provider: "anthropic",
34
- model: "claude-haiku-4-5-20251001",
35
- getApiKey: async () => process.env.ANTHROPIC_API_KEY,
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
- model,
59
- {
60
- messages: [
61
- Message.createUserMessage({
62
- role: "user",
63
- time: { created: Date.now() },
64
- parts: [{ type: "text", text: "Count from 1 to 3" }],
65
- }),
66
- ],
67
- },
68
- { apiKey: process.env.ANTHROPIC_API_KEY },
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
- if (event.type === "text.delta") {
73
- process.stdout.write(event.delta);
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
- provider: "anthropic",
90
- model: "claude-haiku-4-5-20251001",
91
- getApiKey: async () => process.env.ANTHROPIC_API_KEY,
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
- if (event.type === "message.end") {
98
- console.log(event.message.role, event.message.messageId);
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
- name: "calculator",
115
- label: "Calculator",
116
- description: "Evaluate arithmetic expressions",
117
- parameters: Type.Object({
118
- expression: Type.String(),
119
- }),
120
- async execute(_callID, params) {
121
- return {
122
- status: "completed",
123
- result: {
124
- content: [{ type: "text", text: `result for ${params.expression}` }],
125
- isError: false,
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
- provider: "anthropic",
133
- model: "claude-haiku-4-5-20251001",
134
- getApiKey: async () => process.env.ANTHROPIC_API_KEY,
135
- initialState: {
136
- tools: [calculatorTool],
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([{ type: "text", text: "Use the calculator tool for 25 * 18." }]);
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
- model,
156
- apiKey: process.env.ANTHROPIC_API_KEY,
157
- convertToLlm: async (messages) => messages,
158
- },
159
- {
160
- systemPrompt: "Be concise.",
161
- messages: [],
162
- tools: [],
163
- },
164
- [
165
- Message.createUserMessage({
166
- role: "user",
167
- time: { created: Date.now() },
168
- parts: [{ type: "text", text: "Reply with exactly: ok" }],
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
- role: "user",
188
- time: { created: Date.now() },
189
- parts: [{ type: "text", text: "hello" }],
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
- ## Lower-Level APIs
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
- API docs can be added later. For now, the tests under `packages/aikit/test/` are the best reference for concrete usage.
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.
@@ -1,4 +1,4 @@
1
- import { t as CodeMode } from "../../../codemode-SiETGR3z.mjs";
1
+ import { t as CodeMode } from "../../../codemode-BEDXG7WN.mjs";
2
2
 
3
3
  //#region src/agent/codemode/drivers/quickjs-wasi-driver.d.ts
4
4
  declare function createQuickJSWasiDriver(): CodeMode.Driver;