@blade-ai/agent-sdk 0.1.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/CHANGELOG.md +14 -0
- package/README.md +110 -0
- package/dist/index.js +1858 -0
- package/package.json +93 -0
- package/vendor/ripgrep/.gitignore +12 -0
- package/vendor/ripgrep/README.md +59 -0
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Blade Agent SDK
|
|
2
|
+
|
|
3
|
+
面向 Node.js 与 TypeScript 的多轮会话 Agent SDK,提供标准的 send/stream 会话模式、工具调用、会话恢复与自动清理。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @blade-ai/agent-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 快速上手
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { createSession } from '@blade-ai/agent-sdk';
|
|
15
|
+
|
|
16
|
+
const session = await createSession({
|
|
17
|
+
provider: { type: 'openai-compatible', apiKey: process.env.BLADE_API_KEY },
|
|
18
|
+
model: 'gpt-4o-mini',
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
await session.send('你好');
|
|
22
|
+
for await (const msg of session.stream()) {
|
|
23
|
+
if (msg.type === 'content') {
|
|
24
|
+
process.stdout.write(msg.delta);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 会话 API
|
|
30
|
+
|
|
31
|
+
### send / stream
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
await session.send('请总结下面的文本...');
|
|
35
|
+
for await (const msg of session.stream({ includeThinking: false })) {
|
|
36
|
+
if (msg.type === 'content') {
|
|
37
|
+
process.stdout.write(msg.delta);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 一次性 prompt
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { prompt } from '@blade-ai/agent-sdk';
|
|
46
|
+
|
|
47
|
+
const result = await prompt('2+2 等于多少?', {
|
|
48
|
+
provider: { type: 'openai-compatible', apiKey: process.env.BLADE_API_KEY },
|
|
49
|
+
model: 'gpt-4o-mini',
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
console.log(result.result);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 恢复会话
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { resumeSession } from '@blade-ai/agent-sdk';
|
|
59
|
+
|
|
60
|
+
const session = await resumeSession({
|
|
61
|
+
sessionId: 'your-session-id',
|
|
62
|
+
provider: { type: 'openai-compatible', apiKey: process.env.BLADE_API_KEY },
|
|
63
|
+
model: 'gpt-4o-mini',
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
await session.send('继续上次的话题');
|
|
67
|
+
for await (const msg of session.stream()) {
|
|
68
|
+
if (msg.type === 'content') process.stdout.write(msg.delta);
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 自动清理
|
|
73
|
+
|
|
74
|
+
TypeScript 5.2+ 支持 `using` 自动清理:
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { createSession } from '@blade-ai/agent-sdk';
|
|
78
|
+
|
|
79
|
+
await using session = await createSession({
|
|
80
|
+
provider: { type: 'openai-compatible', apiKey: process.env.BLADE_API_KEY },
|
|
81
|
+
model: 'gpt-4o-mini',
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
await session.send('你好');
|
|
85
|
+
for await (const msg of session.stream()) {
|
|
86
|
+
if (msg.type === 'content') process.stdout.write(msg.delta);
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
旧版本 TypeScript 可手动调用:
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
const session = await createSession({ provider, model });
|
|
94
|
+
session.close();
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## 主要类型
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import type { ISession, StreamMessage, PromptResult } from '@blade-ai/agent-sdk';
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## 运行环境
|
|
104
|
+
|
|
105
|
+
- Node.js >= 20
|
|
106
|
+
- TypeScript >= 5.2(可选,用于 `using` 自动清理)
|
|
107
|
+
|
|
108
|
+
## 许可证
|
|
109
|
+
|
|
110
|
+
MIT
|