@codeworksh/aikit 0.4.1-dev.20260530133305 → 0.4.1-dev.20260530165410
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 +34 -34
- package/index.d.mts +12 -12
- package/package.json +1 -4
package/README.md
CHANGED
|
@@ -12,8 +12,8 @@ It gives you the basic primitives for streaming LLM responses without the extra
|
|
|
12
12
|
- [Tools](#tools)
|
|
13
13
|
- [Providers and Models](#providers-and-models)
|
|
14
14
|
- [CLI Tools](#cli-tools)
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
- [Model Generation](#model-generation)
|
|
16
|
+
- [OAuth Providers](#oauth-providers)
|
|
17
17
|
- [Contribute](#contribute)
|
|
18
18
|
|
|
19
19
|
## Installation
|
|
@@ -47,23 +47,23 @@ if (!model) throw new Error("Model not found");
|
|
|
47
47
|
|
|
48
48
|
// Setup conversation context
|
|
49
49
|
const context: Message.Context = {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
systemPrompt: "You are a helpful coding assistant.",
|
|
51
|
+
messages: [
|
|
52
|
+
Message.createUserMessage({
|
|
53
|
+
role: "user",
|
|
54
|
+
time: { created: Date.now() },
|
|
55
|
+
parts: [{ type: "text", text: "Write a simple loop in TypeScript." }],
|
|
56
|
+
}),
|
|
57
|
+
],
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
// Option 1: Stream events
|
|
61
61
|
const s = stream(model, context, { apiKey: process.env.ANTHROPIC_API_KEY });
|
|
62
62
|
|
|
63
63
|
for await (const event of s) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
if (event.type === "text.delta") {
|
|
65
|
+
process.stdout.write(event.delta);
|
|
66
|
+
}
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
const finalMessage = await s.result();
|
|
@@ -82,41 +82,41 @@ Tools enable LLMs to interact with external systems. `@codeworksh/aikit` provide
|
|
|
82
82
|
import { Type, llm, stream, Message, validateToolArguments } from "@codeworksh/aikit";
|
|
83
83
|
|
|
84
84
|
const calculatorTool = {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
85
|
+
name: "calculator",
|
|
86
|
+
description: "Evaluate arithmetic expressions",
|
|
87
|
+
parameters: Type.Object({
|
|
88
|
+
expression: Type.String(),
|
|
89
|
+
}),
|
|
90
90
|
};
|
|
91
91
|
|
|
92
92
|
const context: Message.Context = {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
93
|
+
messages: [
|
|
94
|
+
Message.createUserMessage({
|
|
95
|
+
role: "user",
|
|
96
|
+
time: { created: Date.now() },
|
|
97
|
+
parts: [{ type: "text", text: "What is 25 * 18?" }],
|
|
98
|
+
}),
|
|
99
|
+
],
|
|
100
|
+
tools: [calculatorTool],
|
|
101
101
|
};
|
|
102
102
|
|
|
103
103
|
const response = await stream.complete(model, context, { apiKey: process.env.ANTHROPIC_API_KEY });
|
|
104
104
|
|
|
105
105
|
// Check for tool calls in the response
|
|
106
106
|
for (const part of response.parts) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
107
|
+
if (part.type === "toolCall") {
|
|
108
|
+
console.log(`Executing tool: ${part.name}`);
|
|
109
|
+
|
|
110
|
+
// Validates arguments against TypeBox schema automatically
|
|
111
|
+
const args = validateToolArguments(calculatorTool.parameters, part.arguments);
|
|
112
|
+
// Execute your tool logic here...
|
|
113
|
+
}
|
|
114
114
|
}
|
|
115
115
|
```
|
|
116
116
|
|
|
117
117
|
## Providers and Models
|
|
118
118
|
|
|
119
|
-
`@codeworksh/aikit` uses a registry to fetch model specifications and metadata.
|
|
119
|
+
`@codeworksh/aikit` uses a registry to fetch model specifications and metadata.
|
|
120
120
|
|
|
121
121
|
```ts
|
|
122
122
|
import { llm } from "@codeworksh/aikit";
|
package/index.d.mts
CHANGED
|
@@ -5424,10 +5424,11 @@ declare namespace Model {
|
|
|
5424
5424
|
function getBuiltInModels(): Promise<BuiltInModels>;
|
|
5425
5425
|
const registry: {
|
|
5426
5426
|
(): Promise<Map<string, Map<string, {
|
|
5427
|
+
headers?: Record<string, string> | undefined;
|
|
5427
5428
|
api?: {
|
|
5428
5429
|
id?: string | undefined;
|
|
5429
5430
|
url?: string | undefined;
|
|
5430
|
-
method?: "
|
|
5431
|
+
method?: "languageModel" | "chat" | "completion" | "completionModel" | "messages" | "responses" | undefined;
|
|
5431
5432
|
} | undefined;
|
|
5432
5433
|
options?: Record<string, unknown> | undefined;
|
|
5433
5434
|
thinkingLevelMap?: {
|
|
@@ -5438,7 +5439,6 @@ declare namespace Model {
|
|
|
5438
5439
|
high?: string | null | undefined;
|
|
5439
5440
|
xhigh?: string | null | undefined;
|
|
5440
5441
|
} | undefined;
|
|
5441
|
-
headers?: Record<string, string> | undefined;
|
|
5442
5442
|
npm?: string | undefined;
|
|
5443
5443
|
providerOptionsKey?: string | undefined;
|
|
5444
5444
|
providerOptions?: Record<string, unknown> | undefined;
|
|
@@ -5452,7 +5452,7 @@ declare namespace Model {
|
|
|
5452
5452
|
googleVertexAnthropic?: "anthropic" | "google" | "google-vertex" | "google-vertex-anthropic" | "openai" | "openai-compatible" | "openrouter" | "xai" | undefined;
|
|
5453
5453
|
openaiCompatible?: "anthropic" | "google" | "google-vertex" | "google-vertex-anthropic" | "openai" | "openai-compatible" | "openrouter" | "xai" | undefined;
|
|
5454
5454
|
} | undefined;
|
|
5455
|
-
|
|
5455
|
+
maxTokens: number;
|
|
5456
5456
|
id: string;
|
|
5457
5457
|
name: string;
|
|
5458
5458
|
provider: {
|
|
@@ -5463,6 +5463,8 @@ declare namespace Model {
|
|
|
5463
5463
|
source: "env" | "config" | "custom" | "api" | "unknown";
|
|
5464
5464
|
env: string[];
|
|
5465
5465
|
};
|
|
5466
|
+
baseUrl: string;
|
|
5467
|
+
reasoning: boolean;
|
|
5466
5468
|
input: ("text" | "image")[];
|
|
5467
5469
|
cost: {
|
|
5468
5470
|
input: number;
|
|
@@ -5470,19 +5472,18 @@ declare namespace Model {
|
|
|
5470
5472
|
cacheRead: number;
|
|
5471
5473
|
cacheWrite: number;
|
|
5472
5474
|
};
|
|
5473
|
-
baseUrl: string;
|
|
5474
|
-
reasoning: boolean;
|
|
5475
5475
|
contextWindow: number;
|
|
5476
|
-
|
|
5476
|
+
protocol: "anthropic" | "google" | "google-vertex" | "google-vertex-anthropic" | "openai" | "openai-compatible" | "openrouter" | "xai";
|
|
5477
5477
|
}>>>;
|
|
5478
5478
|
reset(): void;
|
|
5479
5479
|
};
|
|
5480
5480
|
function supportsProtocol(model: Info, protocol: KnownProviderEnum): boolean;
|
|
5481
5481
|
function getModel<TProvider extends string, TModel extends Info["id"]>(provider: TProvider, model: TModel, overrides?: Partial<Info>): Promise<{
|
|
5482
|
+
headers?: Record<string, string> | undefined;
|
|
5482
5483
|
api?: {
|
|
5483
5484
|
id?: string | undefined;
|
|
5484
5485
|
url?: string | undefined;
|
|
5485
|
-
method?: "
|
|
5486
|
+
method?: "languageModel" | "chat" | "completion" | "completionModel" | "messages" | "responses" | undefined;
|
|
5486
5487
|
} | undefined;
|
|
5487
5488
|
options?: Record<string, unknown> | undefined;
|
|
5488
5489
|
thinkingLevelMap?: {
|
|
@@ -5493,7 +5494,6 @@ declare namespace Model {
|
|
|
5493
5494
|
high?: string | null | undefined;
|
|
5494
5495
|
xhigh?: string | null | undefined;
|
|
5495
5496
|
} | undefined;
|
|
5496
|
-
headers?: Record<string, string> | undefined;
|
|
5497
5497
|
npm?: string | undefined;
|
|
5498
5498
|
providerOptionsKey?: string | undefined;
|
|
5499
5499
|
providerOptions?: Record<string, unknown> | undefined;
|
|
@@ -5507,7 +5507,7 @@ declare namespace Model {
|
|
|
5507
5507
|
googleVertexAnthropic?: "anthropic" | "google" | "google-vertex" | "google-vertex-anthropic" | "openai" | "openai-compatible" | "openrouter" | "xai" | undefined;
|
|
5508
5508
|
openaiCompatible?: "anthropic" | "google" | "google-vertex" | "google-vertex-anthropic" | "openai" | "openai-compatible" | "openrouter" | "xai" | undefined;
|
|
5509
5509
|
} | undefined;
|
|
5510
|
-
|
|
5510
|
+
maxTokens: number;
|
|
5511
5511
|
id: string;
|
|
5512
5512
|
name: string;
|
|
5513
5513
|
provider: {
|
|
@@ -5518,6 +5518,8 @@ declare namespace Model {
|
|
|
5518
5518
|
source: "env" | "config" | "custom" | "api" | "unknown";
|
|
5519
5519
|
env: string[];
|
|
5520
5520
|
};
|
|
5521
|
+
baseUrl: string;
|
|
5522
|
+
reasoning: boolean;
|
|
5521
5523
|
input: ("text" | "image")[];
|
|
5522
5524
|
cost: {
|
|
5523
5525
|
input: number;
|
|
@@ -5525,10 +5527,8 @@ declare namespace Model {
|
|
|
5525
5527
|
cacheRead: number;
|
|
5526
5528
|
cacheWrite: number;
|
|
5527
5529
|
};
|
|
5528
|
-
baseUrl: string;
|
|
5529
|
-
reasoning: boolean;
|
|
5530
5530
|
contextWindow: number;
|
|
5531
|
-
|
|
5531
|
+
protocol: "anthropic" | "google" | "google-vertex" | "google-vertex-anthropic" | "openai" | "openai-compatible" | "openrouter" | "xai";
|
|
5532
5532
|
} | undefined>;
|
|
5533
5533
|
function getProviders(): Promise<string[]>;
|
|
5534
5534
|
function getModels<TProvider extends string>(provider: TProvider): Promise<Info[]>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeworksh/aikit",
|
|
3
|
-
"version": "0.4.1-dev.
|
|
3
|
+
"version": "0.4.1-dev.20260530165410",
|
|
4
4
|
"description": "Toolkit for building AI agents and agent harness.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|
|
@@ -55,14 +55,11 @@
|
|
|
55
55
|
"@ai-sdk/google-vertex": "^4.0.137",
|
|
56
56
|
"@ai-sdk/openai": "^3.0.65",
|
|
57
57
|
"@ai-sdk/openai-compatible": "^2.0.48",
|
|
58
|
-
"@ai-sdk/provider": "^3.0.10",
|
|
59
58
|
"@ai-sdk/xai": "^3.0.92",
|
|
60
59
|
"@openrouter/ai-sdk-provider": "^2.9.0",
|
|
61
60
|
"ai": "^6.0.191",
|
|
62
61
|
"dedent": "^1.7.2",
|
|
63
|
-
"esbuild": "^0.27.3",
|
|
64
62
|
"partial-json": "^0.1.7",
|
|
65
|
-
"quickjs-wasi": "^2.2.0",
|
|
66
63
|
"remeda": "^2.33.6",
|
|
67
64
|
"typebox": "^1.1.37",
|
|
68
65
|
"uuidv7": "^1.2.1",
|