@omarestrella/ai-sdk-agent-sdk 1.0.0-beta.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/LICENSE +21 -0
- package/README.md +91 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +6 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/json.d.ts +6 -0
- package/dist/src/json.d.ts.map +1 -0
- package/dist/src/json.js +29 -0
- package/dist/src/json.js.map +1 -0
- package/dist/src/language-model.d.ts +23 -0
- package/dist/src/language-model.d.ts.map +1 -0
- package/dist/src/language-model.js +440 -0
- package/dist/src/language-model.js.map +1 -0
- package/dist/src/logger.d.ts +15 -0
- package/dist/src/logger.d.ts.map +1 -0
- package/dist/src/logger.js +142 -0
- package/dist/src/logger.js.map +1 -0
- package/dist/src/messages.d.ts +14 -0
- package/dist/src/messages.d.ts.map +1 -0
- package/dist/src/messages.js +92 -0
- package/dist/src/messages.js.map +1 -0
- package/dist/src/provider.d.ts +15 -0
- package/dist/src/provider.d.ts.map +1 -0
- package/dist/src/provider.js +19 -0
- package/dist/src/provider.js.map +1 -0
- package/dist/src/tools.d.ts +21 -0
- package/dist/src/tools.d.ts.map +1 -0
- package/dist/src/tools.js +82 -0
- package/dist/src/tools.js.map +1 -0
- package/dist/test/messages.test.d.ts +2 -0
- package/dist/test/messages.test.d.ts.map +1 -0
- package/dist/test/messages.test.js +173 -0
- package/dist/test/messages.test.js.map +1 -0
- package/dist/test/tools.test.d.ts +2 -0
- package/dist/test/tools.test.d.ts.map +1 -0
- package/dist/test/tools.test.js +175 -0
- package/dist/test/tools.test.js.map +1 -0
- package/package.json +70 -0
- package/src/index.ts +11 -0
- package/src/json.ts +38 -0
- package/src/language-model.ts +526 -0
- package/src/logger.ts +171 -0
- package/src/messages.ts +102 -0
- package/src/provider.ts +45 -0
- package/src/tools.ts +112 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { convertMessages } from "../src/messages";
|
|
3
|
+
describe("convertMessages", () => {
|
|
4
|
+
test("should convert system message", () => {
|
|
5
|
+
const messages = [
|
|
6
|
+
{ role: "system", content: "You are a helpful assistant." },
|
|
7
|
+
];
|
|
8
|
+
const result = convertMessages(messages);
|
|
9
|
+
expect(result.systemPrompt).toBe("You are a helpful assistant.");
|
|
10
|
+
expect(result.prompt).toBe("");
|
|
11
|
+
});
|
|
12
|
+
test("should convert user text message", () => {
|
|
13
|
+
const messages = [
|
|
14
|
+
{
|
|
15
|
+
role: "user",
|
|
16
|
+
content: [{ type: "text", text: "Hello, how are you?" }],
|
|
17
|
+
},
|
|
18
|
+
];
|
|
19
|
+
const result = convertMessages(messages);
|
|
20
|
+
expect(result.systemPrompt).toBe("");
|
|
21
|
+
expect(result.prompt).toBe("[user]\nHello, how are you?");
|
|
22
|
+
});
|
|
23
|
+
test("should convert user file message", () => {
|
|
24
|
+
const messages = [
|
|
25
|
+
{
|
|
26
|
+
role: "user",
|
|
27
|
+
content: [
|
|
28
|
+
{
|
|
29
|
+
type: "file",
|
|
30
|
+
data: Buffer.from("test content").toString("base64"),
|
|
31
|
+
mediaType: "application/pdf",
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
const result = convertMessages(messages);
|
|
37
|
+
expect(result.systemPrompt).toBe("");
|
|
38
|
+
expect(result.prompt).toBe("[user]\n[File: application/pdf]");
|
|
39
|
+
});
|
|
40
|
+
test("should convert assistant text message", () => {
|
|
41
|
+
const messages = [
|
|
42
|
+
{
|
|
43
|
+
role: "assistant",
|
|
44
|
+
content: [{ type: "text", text: "I'm doing well, thank you!" }],
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
const result = convertMessages(messages);
|
|
48
|
+
expect(result.systemPrompt).toBe("");
|
|
49
|
+
expect(result.prompt).toBe("[assistant]\nI'm doing well, thank you!");
|
|
50
|
+
});
|
|
51
|
+
test("should convert assistant tool call", () => {
|
|
52
|
+
const messages = [
|
|
53
|
+
{
|
|
54
|
+
role: "assistant",
|
|
55
|
+
content: [
|
|
56
|
+
{
|
|
57
|
+
type: "tool-call",
|
|
58
|
+
toolCallId: "call-123",
|
|
59
|
+
toolName: "getWeather",
|
|
60
|
+
input: { city: "San Francisco" },
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
];
|
|
65
|
+
const result = convertMessages(messages);
|
|
66
|
+
expect(result.systemPrompt).toBe("");
|
|
67
|
+
expect(result.prompt).toContain('[tool_call: getWeather({"city":"San Francisco"})]');
|
|
68
|
+
});
|
|
69
|
+
test("should convert assistant reasoning", () => {
|
|
70
|
+
const messages = [
|
|
71
|
+
{
|
|
72
|
+
role: "assistant",
|
|
73
|
+
content: [{ type: "reasoning", text: "Let me think about this..." }],
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
const result = convertMessages(messages);
|
|
77
|
+
expect(result.systemPrompt).toBe("");
|
|
78
|
+
expect(result.prompt).toBe("[assistant]\n[thinking]\nLet me think about this...\n[/thinking]");
|
|
79
|
+
});
|
|
80
|
+
test("should convert tool result with text output", () => {
|
|
81
|
+
const messages = [
|
|
82
|
+
{
|
|
83
|
+
role: "tool",
|
|
84
|
+
content: [
|
|
85
|
+
{
|
|
86
|
+
type: "tool-result",
|
|
87
|
+
toolCallId: "call-123",
|
|
88
|
+
toolName: "getWeather",
|
|
89
|
+
output: { type: "text", value: "Sunny, 72°F" },
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
];
|
|
94
|
+
const result = convertMessages(messages);
|
|
95
|
+
expect(result.systemPrompt).toBe("");
|
|
96
|
+
expect(result.prompt).toContain("[tool_result: getWeather (id: call-123)]");
|
|
97
|
+
expect(result.prompt).toContain('{"type":"text","value":"Sunny, 72°F"}');
|
|
98
|
+
});
|
|
99
|
+
test("should convert tool result with json output", () => {
|
|
100
|
+
const messages = [
|
|
101
|
+
{
|
|
102
|
+
role: "tool",
|
|
103
|
+
content: [
|
|
104
|
+
{
|
|
105
|
+
type: "tool-result",
|
|
106
|
+
toolCallId: "call-456",
|
|
107
|
+
toolName: "calculate",
|
|
108
|
+
output: { type: "json", value: 42 },
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
},
|
|
112
|
+
];
|
|
113
|
+
const result = convertMessages(messages);
|
|
114
|
+
expect(result.systemPrompt).toBe("");
|
|
115
|
+
expect(result.prompt).toContain("[tool_result: calculate (id: call-456)]");
|
|
116
|
+
expect(result.prompt).toContain("42");
|
|
117
|
+
});
|
|
118
|
+
test("should handle full conversation flow", () => {
|
|
119
|
+
const messages = [
|
|
120
|
+
{ role: "system", content: "You are a helpful assistant." },
|
|
121
|
+
{
|
|
122
|
+
role: "user",
|
|
123
|
+
content: [{ type: "text", text: "What's the weather?" }],
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
role: "assistant",
|
|
127
|
+
content: [
|
|
128
|
+
{
|
|
129
|
+
type: "tool-call",
|
|
130
|
+
toolCallId: "call-1",
|
|
131
|
+
toolName: "getWeather",
|
|
132
|
+
input: { city: "NYC" },
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
role: "tool",
|
|
138
|
+
content: [
|
|
139
|
+
{
|
|
140
|
+
type: "tool-result",
|
|
141
|
+
toolCallId: "call-1",
|
|
142
|
+
toolName: "getWeather",
|
|
143
|
+
output: { type: "text", value: "Rainy, 60°F" },
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
role: "assistant",
|
|
149
|
+
content: [{ type: "text", text: "It's rainy in NYC today." }],
|
|
150
|
+
},
|
|
151
|
+
];
|
|
152
|
+
const result = convertMessages(messages);
|
|
153
|
+
expect(result.systemPrompt).toBe("You are a helpful assistant.");
|
|
154
|
+
expect(result.prompt).toContain("[user]\nWhat's the weather?");
|
|
155
|
+
expect(result.prompt).toContain('[tool_call: getWeather({"city":"NYC"})]');
|
|
156
|
+
expect(result.prompt).toContain("It's rainy in NYC today.");
|
|
157
|
+
});
|
|
158
|
+
test("should handle empty messages", () => {
|
|
159
|
+
const messages = [];
|
|
160
|
+
const result = convertMessages(messages);
|
|
161
|
+
expect(result.systemPrompt).toBe("");
|
|
162
|
+
expect(result.prompt).toBe("");
|
|
163
|
+
});
|
|
164
|
+
test("should handle multiple system messages", () => {
|
|
165
|
+
const messages = [
|
|
166
|
+
{ role: "system", content: "You are an AI assistant." },
|
|
167
|
+
{ role: "system", content: "Be concise and helpful." },
|
|
168
|
+
];
|
|
169
|
+
const result = convertMessages(messages);
|
|
170
|
+
expect(result.systemPrompt).toBe("You are an AI assistant.\n\nBe concise and helpful.");
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
//# sourceMappingURL=messages.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.test.js","sourceRoot":"","sources":["../../test/messages.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,IAAI,CAAC,+BAA+B,EAAE,GAAG,EAAE;QACzC,MAAM,QAAQ,GAA0B;YACtC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,8BAA8B,EAAE;SAC5D,CAAC;QAEF,MAAM,MAAM,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;QAEzC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;QACjE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;IAE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Q,GAA0B,EAAE,CAAC;QAE3C,MAAM,MAAM,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;QAEzC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACrC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAClD,MAAM,QAAQ,GAA0B;YACtC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,0BAA0B,EAAE;YACvD,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,yBAAyB,EAAE;SACvD,CAAC;QAEF,MAAM,MAAM,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;QAEzC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,qDAAqD,CAAC,CAAC;IAC1F,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.test.d.ts","sourceRoot":"","sources":["../../test/tools.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { convertTools } from "../src/tools";
|
|
3
|
+
describe("convertTools", () => {
|
|
4
|
+
test("should return undefined for empty tools array", () => {
|
|
5
|
+
const result = convertTools([]);
|
|
6
|
+
expect(result).toBeUndefined();
|
|
7
|
+
});
|
|
8
|
+
test("should return undefined for undefined tools", () => {
|
|
9
|
+
const result = convertTools(undefined);
|
|
10
|
+
expect(result).toBeUndefined();
|
|
11
|
+
});
|
|
12
|
+
test("should convert tool with simple string parameter", () => {
|
|
13
|
+
const tools = [
|
|
14
|
+
{
|
|
15
|
+
type: "function",
|
|
16
|
+
name: "getWeather",
|
|
17
|
+
description: "Get the weather for a city",
|
|
18
|
+
inputSchema: {
|
|
19
|
+
type: "object",
|
|
20
|
+
properties: {
|
|
21
|
+
city: { type: "string" },
|
|
22
|
+
},
|
|
23
|
+
required: ["city"],
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
const result = convertTools(tools);
|
|
28
|
+
expect(result).toBeDefined();
|
|
29
|
+
// The MCP server should be created successfully
|
|
30
|
+
});
|
|
31
|
+
test("should convert tool with multiple parameter types", () => {
|
|
32
|
+
const tools = [
|
|
33
|
+
{
|
|
34
|
+
type: "function",
|
|
35
|
+
name: "createUser",
|
|
36
|
+
description: "Create a new user",
|
|
37
|
+
inputSchema: {
|
|
38
|
+
type: "object",
|
|
39
|
+
properties: {
|
|
40
|
+
name: { type: "string" },
|
|
41
|
+
age: { type: "integer" },
|
|
42
|
+
email: { type: "string", format: "email" },
|
|
43
|
+
isActive: { type: "boolean" },
|
|
44
|
+
},
|
|
45
|
+
required: ["name", "email"],
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
];
|
|
49
|
+
const result = convertTools(tools);
|
|
50
|
+
expect(result).toBeDefined();
|
|
51
|
+
});
|
|
52
|
+
test("should convert tool with nested object parameters", () => {
|
|
53
|
+
const tools = [
|
|
54
|
+
{
|
|
55
|
+
type: "function",
|
|
56
|
+
name: "updateConfig",
|
|
57
|
+
description: "Update configuration",
|
|
58
|
+
inputSchema: {
|
|
59
|
+
type: "object",
|
|
60
|
+
properties: {
|
|
61
|
+
settings: {
|
|
62
|
+
type: "object",
|
|
63
|
+
properties: {
|
|
64
|
+
theme: { type: "string" },
|
|
65
|
+
notifications: { type: "boolean" },
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
const result = convertTools(tools);
|
|
73
|
+
expect(result).toBeDefined();
|
|
74
|
+
});
|
|
75
|
+
test("should convert tool with array parameters", () => {
|
|
76
|
+
const tools = [
|
|
77
|
+
{
|
|
78
|
+
type: "function",
|
|
79
|
+
name: "addTags",
|
|
80
|
+
description: "Add tags to an item",
|
|
81
|
+
inputSchema: {
|
|
82
|
+
type: "object",
|
|
83
|
+
properties: {
|
|
84
|
+
tags: {
|
|
85
|
+
type: "array",
|
|
86
|
+
items: { type: "string" },
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
];
|
|
92
|
+
const result = convertTools(tools);
|
|
93
|
+
expect(result).toBeDefined();
|
|
94
|
+
});
|
|
95
|
+
test("should convert tool with enum parameters", () => {
|
|
96
|
+
const tools = [
|
|
97
|
+
{
|
|
98
|
+
type: "function",
|
|
99
|
+
name: "setPriority",
|
|
100
|
+
description: "Set task priority",
|
|
101
|
+
inputSchema: {
|
|
102
|
+
type: "object",
|
|
103
|
+
properties: {
|
|
104
|
+
priority: {
|
|
105
|
+
type: "string",
|
|
106
|
+
enum: ["low", "medium", "high"],
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
];
|
|
112
|
+
const result = convertTools(tools);
|
|
113
|
+
expect(result).toBeDefined();
|
|
114
|
+
});
|
|
115
|
+
test("should convert multiple tools", () => {
|
|
116
|
+
const tools = [
|
|
117
|
+
{
|
|
118
|
+
type: "function",
|
|
119
|
+
name: "getWeather",
|
|
120
|
+
description: "Get weather",
|
|
121
|
+
inputSchema: {
|
|
122
|
+
type: "object",
|
|
123
|
+
properties: { city: { type: "string" } },
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
type: "function",
|
|
128
|
+
name: "getTime",
|
|
129
|
+
description: "Get current time",
|
|
130
|
+
inputSchema: {
|
|
131
|
+
type: "object",
|
|
132
|
+
properties: {},
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
];
|
|
136
|
+
const result = convertTools(tools);
|
|
137
|
+
expect(result).toBeDefined();
|
|
138
|
+
});
|
|
139
|
+
test("should handle tool without parameters", () => {
|
|
140
|
+
const tools = [
|
|
141
|
+
{
|
|
142
|
+
type: "function",
|
|
143
|
+
name: "getStatus",
|
|
144
|
+
description: "Get system status",
|
|
145
|
+
inputSchema: {
|
|
146
|
+
type: "object",
|
|
147
|
+
properties: {},
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
];
|
|
151
|
+
const result = convertTools(tools);
|
|
152
|
+
expect(result).toBeDefined();
|
|
153
|
+
});
|
|
154
|
+
test("should convert tool with optional parameters", () => {
|
|
155
|
+
const tools = [
|
|
156
|
+
{
|
|
157
|
+
type: "function",
|
|
158
|
+
name: "search",
|
|
159
|
+
description: "Search items",
|
|
160
|
+
inputSchema: {
|
|
161
|
+
type: "object",
|
|
162
|
+
properties: {
|
|
163
|
+
query: { type: "string" },
|
|
164
|
+
limit: { type: "integer" },
|
|
165
|
+
offset: { type: "integer" },
|
|
166
|
+
},
|
|
167
|
+
required: ["query"],
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
];
|
|
171
|
+
const result = convertTools(tools);
|
|
172
|
+
expect(result).toBeDefined();
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
//# sourceMappingURL=tools.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.test.js","sourceRoot":"","sources":["../../test/tools.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,IAAI,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACzD,MAAM,MAAM,GAAG,YAAY,CAAC,EAAE,CAAC,CAAC;QAChC,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,6CAA6C,EAAE,GAAG,EAA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CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACxD,MAAM,KAAK,GAAkC;YAC3C;gBACE,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,cAAc;gBAC3B,WAAW,EAAE;oBACX,IAAI,EAAE,QAAQ;oBACd,UAAU,EAAE;wBACV,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;wBACzB,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;wBAC1B,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;qBAC5B;oBACD,QAAQ,EAAE,CAAC,OAAO,CAAC;iBACpB;aACF;SACF,CAAC;QAEF,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;QACnC,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@omarestrella/ai-sdk-agent-sdk",
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
|
+
"description": "AI SDK provider for the Agent SDK for OpenCode",
|
|
5
|
+
"homepage": "https://github.com/omarestrella/ai-sdk-agent-sdk",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"agent-sdk",
|
|
8
|
+
"ai-sdk",
|
|
9
|
+
"anthropic",
|
|
10
|
+
"claude",
|
|
11
|
+
"opencode"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/omarestrella/ai-sdk-agent-sdk.git"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"src",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
24
|
+
"main": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"import": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"default": "./dist/index.js"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsc",
|
|
36
|
+
"prepublishOnly": "rm -rf dist && tsc",
|
|
37
|
+
"lint": "oxlint",
|
|
38
|
+
"lint:fix": "oxlint --fix",
|
|
39
|
+
"fmt": "oxfmt",
|
|
40
|
+
"fmt:check": "oxfmt --check",
|
|
41
|
+
"test": "bun test"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@ai-sdk/provider": "^2.0.0",
|
|
45
|
+
"@ai-sdk/provider-utils": "^3.0.0",
|
|
46
|
+
"@anthropic-ai/claude-agent-sdk": ">=0.2.0",
|
|
47
|
+
"zod": "^4.3.6"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@anthropic-ai/sdk": "^0.72.1",
|
|
51
|
+
"@types/consola": "^2.2.8",
|
|
52
|
+
"@types/bun": "^1.3.8",
|
|
53
|
+
"@types/node": "^25.1.0",
|
|
54
|
+
"oxfmt": "^0.27.0",
|
|
55
|
+
"oxlint": "^1.42.0",
|
|
56
|
+
"typescript": "^5.0.0"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@anthropic-ai/claude-agent-sdk": ">=0.2.0",
|
|
60
|
+
"consola": ""
|
|
61
|
+
},
|
|
62
|
+
"peerDependenciesMeta": {
|
|
63
|
+
"consola": {
|
|
64
|
+
"optional": true
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"engines": {
|
|
68
|
+
"node": ">=18"
|
|
69
|
+
}
|
|
70
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export {
|
|
2
|
+
createClaudeAgent,
|
|
3
|
+
type ClaudeAgentProvider,
|
|
4
|
+
type ClaudeAgentProviderSettings,
|
|
5
|
+
} from "./provider";
|
|
6
|
+
|
|
7
|
+
export { ClaudeAgentLanguageModel } from "./language-model";
|
|
8
|
+
|
|
9
|
+
// `create` alias for compatibility with opencode's dynamic provider loader,
|
|
10
|
+
// which looks for a `create` function export from npm packages.
|
|
11
|
+
export { createClaudeAgent as create } from "./provider";
|
package/src/json.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { logger } from "./logger";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Safely serializes a value to JSON, handling circular references
|
|
5
|
+
* by replacing them with `[Circular]`.
|
|
6
|
+
*/
|
|
7
|
+
export function safeJsonStringify(
|
|
8
|
+
value: unknown,
|
|
9
|
+
space?: string | number,
|
|
10
|
+
): string {
|
|
11
|
+
const seen = new WeakSet();
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
return JSON.stringify(
|
|
15
|
+
value,
|
|
16
|
+
(key, val) => {
|
|
17
|
+
if (val === null || typeof val !== "object") {
|
|
18
|
+
return val;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (seen.has(val)) {
|
|
22
|
+
return "[Circular]";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
seen.add(val);
|
|
26
|
+
return val;
|
|
27
|
+
},
|
|
28
|
+
space,
|
|
29
|
+
);
|
|
30
|
+
} catch (e) {
|
|
31
|
+
const err = e as Error;
|
|
32
|
+
logger.error("Cannot stringify JSON", {
|
|
33
|
+
error: err.message,
|
|
34
|
+
stack: err.stack,
|
|
35
|
+
});
|
|
36
|
+
return "{}";
|
|
37
|
+
}
|
|
38
|
+
}
|