@codeworksh/aikit 0.14.1-canary.158.1.gdff28d0d → 0.14.1-canary.160.1.g8b6596ff

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 (3) hide show
  1. package/README.md +42 -133
  2. package/cli.mjs +1 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,177 +1,86 @@
1
1
  # @codeworksh/aikit
2
2
 
3
- AiKit is a **TypeScript SDK** that provides a unified API for working with multiple LLM providers, automatic model discovery, provider configurations, token and cost tracking, and mid-session hand-off to other models.
4
- It gives you the basic primitives for streaming LLM responses without the extra bloat, letting you handle the orchestration yourself.
5
-
6
- ## Table of Contents
7
-
8
- - [Installation](#installation)
9
- - [Supported Providers](#supported-providers)
10
- - [Quick Start](#quick-start)
11
- - [Tools](#tools)
12
- - [Providers and Models](#providers-and-models)
13
- - [CLI Tools](#cli-tools)
14
- - [Model Generation](#model-generation)
15
- - [OAuth Providers](#oauth-providers)
16
- - [Contribute](#contribute)
17
-
18
- ## Installation
3
+ aikit is the model layer of [CodeWork](https://www.codework.sh): one message and event shape over many LLM providers, a model catalog with pricing, and cost tracking per message. The CodeWork harness makes every model call through it, and you can use it on its own when you want streaming primitives and to run the loop yourself.
19
4
 
20
5
  ```bash
21
- npm install @codeworksh/aikit
6
+ pnpm add @codeworksh/aikit
22
7
  ```
23
8
 
24
- Node `>=22.0.0` is required.
25
-
26
- ## Supported Providers
27
-
28
- Built on top of the Vercel AI SDK, `@codeworksh/aikit` supports a wide array of providers natively:
29
-
30
- - **Anthropic** (`@ai-sdk/anthropic`)
31
- - **OpenAI** (`@ai-sdk/openai`)
32
- - **Google** (`@ai-sdk/google`)
33
- - **Google Vertex AI** (`@ai-sdk/google-vertex`)
34
- - **xAI** (`@ai-sdk/xai`)
35
- - **OpenRouter** (`@openrouter/ai-sdk-provider`)
36
- - **OpenAI Compatible APIs** (`@ai-sdk/openai-compatible`)
9
+ Node 22 or later is required.
37
10
 
38
11
  ## Quick Start
39
12
 
40
13
  ```ts
41
- import { llm, stream, Message } from "@codeworksh/aikit";
14
+ import { llm, Message, stream } from "@codeworksh/aikit";
42
15
 
43
- // Resolve a model from the built-in registry
44
- const model = await llm("anthropic", "claude-haiku-4-5-20251001");
45
- if (!model) throw new Error("Model not found");
16
+ const model = await llm("anthropic", "claude-haiku-4-5");
17
+ if (!model) throw new Error("Model not in the catalog");
46
18
 
47
- // Setup conversation context
48
19
  const context: Message.Context = {
49
20
  systemPrompt: "You are a helpful coding assistant.",
50
21
  messages: [
51
22
  Message.createUserMessage({
52
23
  role: "user",
53
24
  time: { created: Date.now() },
54
- parts: [{ type: "text", text: "Write a simple loop in TypeScript." }],
25
+ parts: [{ type: "text", text: "Write a loop in TypeScript." }],
55
26
  }),
56
27
  ],
57
28
  };
58
29
 
59
- // Option 1: Stream events
60
- const s = stream(model, context, { apiKey: process.env.ANTHROPIC_API_KEY });
61
-
30
+ // The key is read from ANTHROPIC_API_KEY unless you pass { apiKey }.
31
+ const s = stream(model, context);
62
32
  for await (const event of s) {
63
- if (event.type === "text.delta") {
64
- process.stdout.write(event.delta);
65
- }
33
+ if (event.type === "text.delta") process.stdout.write(event.delta);
66
34
  }
67
35
 
68
- const finalMessage = await s.result();
69
- console.log(`\nMessage ID: ${finalMessage.messageId}`);
70
-
71
- // Option 2: Get complete response without streaming
72
- const message = await stream.complete(model, context, { apiKey: process.env.ANTHROPIC_API_KEY });
73
- console.log(message.parts);
74
- ```
75
-
76
- ## Tools
77
-
78
- Tools enable LLMs to interact with external systems. `@codeworksh/aikit` provides native support for function calling and schema validation using TypeBox.
79
-
80
- ```ts
81
- import { Type, llm, stream, Message, validateToolArguments } from "@codeworksh/aikit";
82
-
83
- const calculatorTool = {
84
- name: "calculator",
85
- description: "Evaluate arithmetic expressions",
86
- parameters: Type.Object({
87
- expression: Type.String(),
88
- }),
89
- };
90
-
91
- const context: Message.Context = {
92
- messages: [
93
- Message.createUserMessage({
94
- role: "user",
95
- time: { created: Date.now() },
96
- parts: [{ type: "text", text: "What is 25 * 18?" }],
97
- }),
98
- ],
99
- tools: [calculatorTool],
100
- };
101
-
102
- const response = await stream.complete(model, context, { apiKey: process.env.ANTHROPIC_API_KEY });
103
-
104
- // Check for tool calls in the response
105
- for (const part of response.parts) {
106
- if (part.type === "toolCall") {
107
- console.log(`Executing tool: ${part.name}`);
108
-
109
- // Validates arguments against TypeBox schema automatically
110
- const args = validateToolArguments(calculatorTool.parameters, part.arguments);
111
- // Execute your tool logic here...
112
- }
113
- }
36
+ const message = await s.result();
37
+ console.log(message.stopReason, message.usage.cost.total);
114
38
  ```
115
39
 
116
- ## Providers and Models
40
+ A failed request does not throw. The stream ends with an `error` event, and the final message has `stopReason: "error"` and an `errorMessage`. `stream.complete(model, context)` skips the events and resolves the final message.
117
41
 
118
- `@codeworksh/aikit` uses a registry to fetch model specifications and metadata.
42
+ ## What It Owns
119
43
 
120
- ```ts
121
- import { llm } from "@codeworksh/aikit";
44
+ aikit owns the wire shape (`Message`, `Event`), the provider adapters, the catalog format, error normalization and cost. Protocols: `anthropic`, `openai`, `openai-codex`, `github-copilot`, `openrouter`, `google`, `google-vertex`, `google-vertex-anthropic`, `xai` and `openai-compatible`. The transport underneath is the AI SDK.
122
45
 
123
- // Get all available providers
124
- const providers = await llm.providers();
125
- console.log(providers);
46
+ It depends on no other CodeWork package and does not use Effect. The harness depends on it, never the reverse, so aikit stays a plain library anyone can embed. Where credentials live, how fresh the catalog is, and retries belong to the embedder.
126
47
 
127
- // Get all models for a specific provider
128
- const anthropicModels = await llm.models("anthropic");
48
+ A session can switch models between turns. aikit replays signatures and reasoning only to the provider that produced them, so one vendor's opaque state never reaches another.
129
49
 
130
- // Get a specific model directly
131
- const gpt4 = await llm.model("openai", "gpt-4o");
132
- ```
50
+ ## The Model Catalog
133
51
 
134
- ## CLI Tools
52
+ `llm(provider, model)` looks a model up in `./models.gen.json`, or the file `CODEWORK_MODELS_FILE` names. A bundled baseline covers `anthropic`, `openai` and `openrouter`, so a first run works with no file at all. `llm.providers()` and `llm.models(provider)` list what the catalog has.
135
53
 
136
- `@codeworksh/aikit` ships with a CLI tool for managing local metadata and authentication.
137
-
138
- You can invoke it using `npx aikit` or `pnpm aikit`.
139
-
140
- ### Model Generation
141
-
142
- Generate a `models.gen.json` file fetching the latest metadata about providers and their available models from `models.dev`.
54
+ The package ships an `aikit` binary:
143
55
 
144
56
  ```bash
145
- pnpm aikit modelgen [path]
57
+ aikit modelgen [path] # build the catalog from models.dev and OpenRouter's listing
58
+ aikit auth --openai-codex # OAuth login; --device for a device code, --status, --refresh, --logout
59
+ aikit auth --github-copilot # device flow; --enterprise <domain> for GitHub Enterprise
146
60
  ```
147
61
 
148
- ### OAuth Providers
62
+ ## Code Map
149
63
 
150
- Manage OAuth credentials for providers that require it, such as OpenAI Codex and GitHub Copilot.
151
-
152
- ```bash
153
- # Start an OAuth login flow in your browser
154
- pnpm aikit auth --openai-codex
64
+ - [`src/index.ts`](https://github.com/codeworksh/codework/blob/main/packages/aikit/src/index.ts): the public exports.
65
+ - [`src/stream.ts`](https://github.com/codeworksh/codework/blob/main/packages/aikit/src/stream.ts): `stream` and `stream.complete`.
66
+ - [`src/llm.ts`](https://github.com/codeworksh/codework/blob/main/packages/aikit/src/llm.ts): model lookup over the catalog.
67
+ - [`src/message/message.ts`](https://github.com/codeworksh/codework/blob/main/packages/aikit/src/message/message.ts): `Context`, messages, tools and usage.
68
+ - [`src/event/event.ts`](https://github.com/codeworksh/codework/blob/main/packages/aikit/src/event/event.ts): the stream's events.
69
+ - [`src/llm/`](https://github.com/codeworksh/codework/tree/main/packages/aikit/src/llm): protocol registry, provider options, cross-model replay ([`transform.ts`](https://github.com/codeworksh/codework/blob/main/packages/aikit/src/llm/transform.ts)) and failures.
70
+ - [`src/model/`](https://github.com/codeworksh/codework/tree/main/packages/aikit/src/model): catalog loading and the bundled baseline.
71
+ - [`src/providers/`](https://github.com/codeworksh/codework/tree/main/packages/aikit/src/providers): the `openai-codex` and `github-copilot` providers.
72
+ - [`src/oauth/`](https://github.com/codeworksh/codework/tree/main/packages/aikit/src/oauth) and [`src/cli/`](https://github.com/codeworksh/codework/tree/main/packages/aikit/src/cli): logins and the `aikit` binary.
155
73
 
156
- # Codex with a device code instead: no localhost callback port, so it works
157
- # over SSH, in containers, and when something else holds port 1455
158
- pnpm aikit auth --openai-codex --device
74
+ ## Working Locally
159
75
 
160
- # GitHub Copilot uses the device flow; add --enterprise <domain> for GitHub Enterprise
161
- pnpm aikit auth --github-copilot
76
+ From `packages/aikit`:
162
77
 
163
- # Check the status of your stored credentials
164
- pnpm aikit auth --openai-codex --status
165
- pnpm aikit auth --github-copilot --status
166
-
167
- # Refresh your current credentials
168
- pnpm aikit auth --openai-codex --refresh
169
-
170
- # Clear stored credentials
171
- pnpm aikit auth --openai-codex --logout
172
- pnpm aikit auth --github-copilot --logout
78
+ ```bash
79
+ pnpm test # unit tests
80
+ pnpm test:e2e # also runs test/e2e, which calls live providers
81
+ pnpm typecheck
82
+ pnpm build # vp pack
83
+ pnpm cli modelgen
173
84
  ```
174
85
 
175
- ## Contribute
176
-
177
- `@codeworksh/aikit` is open to community contribution. Please ensure you submit an issue before submitting a pull request. The project prefers open community discussion before accepting new features.
86
+ For the rules on credentials, catalog publishing and adding a protocol, see [docs/internals/03_models.md](https://github.com/codeworksh/codework/blob/main/docs/internals/03_models.md).
package/cli.mjs CHANGED
@@ -7,7 +7,7 @@ import { a as oauthNotice, c as summarizeGitHubCopilot, i as oauthLoginIssue, l
7
7
  import yargs from "yargs";
8
8
  import { hideBin } from "yargs/helpers";
9
9
  //#region package.json
10
- var version = "0.14.1-canary.158.1.gdff28d0d";
10
+ var version = "0.14.1-canary.160.1.g8b6596ff";
11
11
  //#endregion
12
12
  //#region src/cli/oauth.ts
13
13
  async function runOpenAICodexAuth(args) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeworksh/aikit",
3
- "version": "0.14.1-canary.158.1.gdff28d0d",
3
+ "version": "0.14.1-canary.160.1.g8b6596ff",
4
4
  "description": "TypeScript SDK that provides a unified API for working with multiple LLM providers, automatic model discovery, and more.",
5
5
  "keywords": [
6
6
  "agent",