@claude-code-kit/agent 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Minnzen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # @claude-code-kit/agent
2
+
3
+ Headless agent framework for building LLM-powered tools and applications. Provides an AsyncGenerator-based query loop with tool execution, multi-provider support, context management, and tiered permissions.
4
+
5
+ ## Features
6
+
7
+ - **Multi-provider**: Anthropic (Claude) and OpenAI-compatible APIs (GPT, Ollama, vLLM, Groq, Together)
8
+ - **Tool execution**: Zod-based tool definitions with automatic JSON Schema generation
9
+ - **Context management**: Token counting with configurable compaction strategies
10
+ - **Tiered permissions**: Allow/deny lists, session approvals, read-only auto-approve, custom callbacks
11
+ - **Streaming**: AsyncGenerator-based event stream for real-time UI updates
12
+ - **Stateful sessions**: Maintains conversation history across calls
13
+ - **Headless**: No UI dependencies -- works in Node.js scripts, CLI apps, web servers, anywhere
14
+
15
+ ## Quick start
16
+
17
+ ```typescript
18
+ import { Agent, AnthropicProvider } from '@claude-code-kit/agent'
19
+ import { z } from 'zod'
20
+
21
+ const agent = new Agent({
22
+ provider: new AnthropicProvider({ apiKey: process.env.ANTHROPIC_API_KEY }),
23
+ model: 'claude-sonnet-4-20250514',
24
+ systemPrompt: 'You are a helpful assistant.',
25
+ tools: [{
26
+ name: 'get_weather',
27
+ description: 'Get weather for a city',
28
+ inputSchema: z.object({ city: z.string() }),
29
+ async execute({ city }) {
30
+ return { content: `Weather in ${city}: 72F, sunny` }
31
+ },
32
+ }],
33
+ })
34
+
35
+ // Simple API
36
+ const response = await agent.chat('What is the weather in Tokyo?')
37
+
38
+ // Streaming API
39
+ for await (const event of agent.run('What is the weather in Tokyo?')) {
40
+ switch (event.type) {
41
+ case 'text': process.stdout.write(event.text); break
42
+ case 'tool_call': console.log('Calling:', event.toolCall.name); break
43
+ case 'tool_result': console.log('Result:', event.result.content); break
44
+ case 'done': console.log('\nDone'); break
45
+ }
46
+ }
47
+ ```
48
+
49
+ ## Providers
50
+
51
+ ### Anthropic
52
+
53
+ ```typescript
54
+ import { AnthropicProvider } from '@claude-code-kit/agent'
55
+ const provider = new AnthropicProvider({ apiKey: '...' })
56
+ ```
57
+
58
+ ### OpenAI (and compatible)
59
+
60
+ ```typescript
61
+ import { OpenAIProvider } from '@claude-code-kit/agent'
62
+
63
+ // OpenAI
64
+ const openai = new OpenAIProvider({ apiKey: '...' })
65
+
66
+ // Ollama
67
+ const ollama = new OpenAIProvider({ baseURL: 'http://localhost:11434/v1' })
68
+
69
+ // Groq
70
+ const groq = new OpenAIProvider({ apiKey: '...', baseURL: 'https://api.groq.com/openai/v1' })
71
+ ```
72
+
73
+ ### Mock (for testing)
74
+
75
+ ```typescript
76
+ import { MockProvider } from '@claude-code-kit/agent'
77
+
78
+ const provider = new MockProvider([
79
+ [{ type: 'text', text: 'Hello!' }, { type: 'done' }],
80
+ ])
81
+ ```
82
+
83
+ ## Permissions
84
+
85
+ ```typescript
86
+ import { Agent, createPermissionHandler } from '@claude-code-kit/agent'
87
+
88
+ const agent = new Agent({
89
+ // ...
90
+ permissionHandler: createPermissionHandler({
91
+ alwaysAllow: ['get_weather', 'search'],
92
+ alwaysDeny: ['delete_file'],
93
+ autoApproveReadOnly: true,
94
+ onPermission: async (req) => {
95
+ const ok = await promptUser(`Allow ${req.tool}?`)
96
+ return { decision: ok ? 'allow' : 'deny' }
97
+ },
98
+ }),
99
+ })
100
+ ```
101
+
102
+ ## License
103
+
104
+ MIT