@strand-js/anthropic 0.1.0 → 0.1.1
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 +70 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# @strand-js/anthropic
|
|
2
|
+
|
|
3
|
+
Anthropic provider adapter for [Strand](https://github.com/strand-js/strand) — AI state management for React.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @strand-js/anthropic
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Express / Fastify / Hono
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { createStrandHandler } from '@strand-js/anthropic'
|
|
17
|
+
|
|
18
|
+
app.post('/api/strand', createStrandHandler({
|
|
19
|
+
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
20
|
+
model: 'claude-sonnet-4-6',
|
|
21
|
+
system: 'You are a helpful assistant.',
|
|
22
|
+
}))
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Next.js App Router
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
// app/api/strand/route.ts
|
|
29
|
+
import { createStrandRoute } from '@strand-js/anthropic'
|
|
30
|
+
|
|
31
|
+
export const POST = createStrandRoute({
|
|
32
|
+
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
33
|
+
model: 'claude-sonnet-4-6',
|
|
34
|
+
})
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### With tools
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { z } from 'zod'
|
|
41
|
+
import { tool } from '@strand-js/core'
|
|
42
|
+
|
|
43
|
+
const weatherTool = tool({
|
|
44
|
+
name: 'get_weather',
|
|
45
|
+
description: 'Get weather for a city',
|
|
46
|
+
parameters: z.object({ location: z.string() }),
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
createStrandHandler({
|
|
50
|
+
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
51
|
+
model: 'claude-sonnet-4-6',
|
|
52
|
+
tools: [weatherTool],
|
|
53
|
+
onToolCall: async (name, args) => fetchWeather(args.location),
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### With auth
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
createStrandHandler({
|
|
61
|
+
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
62
|
+
model: 'claude-sonnet-4-6',
|
|
63
|
+
authorize: async (request) => {
|
|
64
|
+
const user = await verifyToken(request.headers.get('authorization'))
|
|
65
|
+
if (!user) throw new Error('Unauthorized')
|
|
66
|
+
},
|
|
67
|
+
})
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
[Full documentation →](https://github.com/strand-js/strand)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strand-js/anthropic",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Anthropic provider adapter for Strand",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@anthropic-ai/sdk": "^0.40.0",
|
|
20
|
-
"@strand-js/core": "0.1.
|
|
20
|
+
"@strand-js/core": "0.1.1"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/express": "^5.0.0",
|