@a3s-lab/code 0.5.0 → 0.7.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/index.d.ts +87 -0
- package/index.darwin-arm64.node +0 -0
- package/index.darwin-x64.node +0 -0
- package/index.js +128 -0
- package/index.linux-arm64-gnu.node +0 -0
- package/index.linux-arm64-musl.node +0 -0
- package/index.linux-x64-gnu.node +0 -0
- package/index.linux-x64-musl.node +0 -0
- package/package.json +27 -34
- package/LICENSE +0 -21
- package/README.md +0 -764
- package/dist/chat.d.ts +0 -97
- package/dist/chat.d.ts.map +0 -1
- package/dist/chat.js +0 -179
- package/dist/chat.js.map +0 -1
- package/dist/client.d.ts +0 -1356
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -1014
- package/dist/client.js.map +0 -1
- package/dist/config.d.ts +0 -106
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -142
- package/dist/config.js.map +0 -1
- package/dist/generate.d.ts +0 -130
- package/dist/generate.d.ts.map +0 -1
- package/dist/generate.js +0 -283
- package/dist/generate.js.map +0 -1
- package/dist/index.d.ts +0 -54
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -60
- package/dist/index.js.map +0 -1
- package/dist/message.d.ts +0 -157
- package/dist/message.d.ts.map +0 -1
- package/dist/message.js +0 -279
- package/dist/message.js.map +0 -1
- package/dist/openai-compat.d.ts +0 -186
- package/dist/openai-compat.d.ts.map +0 -1
- package/dist/openai-compat.js +0 -263
- package/dist/openai-compat.js.map +0 -1
- package/dist/provider.d.ts +0 -64
- package/dist/provider.d.ts.map +0 -1
- package/dist/provider.js +0 -60
- package/dist/provider.js.map +0 -1
- package/dist/session.d.ts +0 -573
- package/dist/session.d.ts.map +0 -1
- package/dist/session.js +0 -1153
- package/dist/session.js.map +0 -1
- package/dist/tool.d.ts +0 -106
- package/dist/tool.d.ts.map +0 -1
- package/dist/tool.js +0 -71
- package/dist/tool.js.map +0 -1
- package/proto/code_agent.proto +0 -1754
package/index.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/* auto-generated by napi-rs */
|
|
3
|
+
|
|
4
|
+
export interface AgentOptions {
|
|
5
|
+
/** LLM model identifier (e.g., "claude-sonnet-4-20250514", "gpt-4o") */
|
|
6
|
+
model: string
|
|
7
|
+
/** API key for the LLM provider */
|
|
8
|
+
apiKey: string
|
|
9
|
+
/** Path to the workspace directory (sandbox root) */
|
|
10
|
+
workspace?: string
|
|
11
|
+
/** System prompt for the agent */
|
|
12
|
+
systemPrompt?: string
|
|
13
|
+
/** Base URL override for the LLM API */
|
|
14
|
+
baseUrl?: string
|
|
15
|
+
/** Maximum tool execution rounds per turn */
|
|
16
|
+
maxToolRounds?: number
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface AgentResult {
|
|
20
|
+
/** The final text response from the agent */
|
|
21
|
+
text: string
|
|
22
|
+
/** Number of tool calls made during execution */
|
|
23
|
+
toolCallsCount: number
|
|
24
|
+
/** Total prompt tokens used */
|
|
25
|
+
promptTokens: number
|
|
26
|
+
/** Total completion tokens used */
|
|
27
|
+
completionTokens: number
|
|
28
|
+
/** Total tokens used */
|
|
29
|
+
totalTokens: number
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface AgentEvent {
|
|
33
|
+
/** Event type: "start", "text_delta", "tool_start", "tool_end", "turn_start", "turn_end", "end", "error" */
|
|
34
|
+
type: string
|
|
35
|
+
/** Text content (for text_delta and end events) */
|
|
36
|
+
text?: string
|
|
37
|
+
/** Tool name (for tool_start and tool_end events) */
|
|
38
|
+
toolName?: string
|
|
39
|
+
/** Tool ID (for tool_start and tool_end events) */
|
|
40
|
+
toolId?: string
|
|
41
|
+
/** Tool output (for tool_end events) */
|
|
42
|
+
toolOutput?: string
|
|
43
|
+
/** Exit code (for tool_end events) */
|
|
44
|
+
exitCode?: number
|
|
45
|
+
/** Turn number (for turn_start and turn_end events) */
|
|
46
|
+
turn?: number
|
|
47
|
+
/** Prompt text (for start events) */
|
|
48
|
+
prompt?: string
|
|
49
|
+
/** Error message (for error events) */
|
|
50
|
+
error?: string
|
|
51
|
+
/** Token usage (for turn_end and end events) */
|
|
52
|
+
totalTokens?: number
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface ToolResult {
|
|
56
|
+
/** Tool name */
|
|
57
|
+
name: string
|
|
58
|
+
/** Tool output text */
|
|
59
|
+
output: string
|
|
60
|
+
/** Exit code (0 = success) */
|
|
61
|
+
exitCode: number
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* AI coding agent with tool execution capabilities.
|
|
66
|
+
*
|
|
67
|
+
* Create an Agent by providing a model name, API key, and workspace path.
|
|
68
|
+
* The agent auto-detects whether to use the Anthropic or OpenAI API based
|
|
69
|
+
* on the model name.
|
|
70
|
+
*/
|
|
71
|
+
export class Agent {
|
|
72
|
+
constructor(options: AgentOptions)
|
|
73
|
+
/** Send a prompt and wait for the complete response */
|
|
74
|
+
send(prompt: string): Promise<AgentResult>
|
|
75
|
+
/** Send a prompt and get all streaming events as an array */
|
|
76
|
+
stream(prompt: string): Promise<AgentEvent[]>
|
|
77
|
+
/** Execute a tool by name, bypassing the LLM */
|
|
78
|
+
tool(name: string, args: Record<string, unknown>): Promise<ToolResult>
|
|
79
|
+
/** Read a file from the workspace */
|
|
80
|
+
readFile(path: string): Promise<string>
|
|
81
|
+
/** Execute a bash command in the workspace */
|
|
82
|
+
bash(command: string): Promise<string>
|
|
83
|
+
/** Search for files matching a glob pattern */
|
|
84
|
+
glob(pattern: string): Promise<string[]>
|
|
85
|
+
/** Search file contents with a regex pattern */
|
|
86
|
+
grep(pattern: string): Promise<string>
|
|
87
|
+
}
|
|
Binary file
|
|
Binary file
|
package/index.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/* auto-generated by napi-rs */
|
|
3
|
+
|
|
4
|
+
const { existsSync, readFileSync } = require('fs')
|
|
5
|
+
const { join } = require('path')
|
|
6
|
+
|
|
7
|
+
const { platform, arch } = process
|
|
8
|
+
|
|
9
|
+
let nativeBinding = null
|
|
10
|
+
let localFileExisted = false
|
|
11
|
+
let loadError = null
|
|
12
|
+
|
|
13
|
+
function isMusl() {
|
|
14
|
+
// For Node 12, use os.release() to detect musl
|
|
15
|
+
if (!process.report || typeof process.report.getReport !== 'function') {
|
|
16
|
+
try {
|
|
17
|
+
const lddPath = require('child_process').execSync('which ldd').toString().trim()
|
|
18
|
+
return readFileSync(lddPath, 'utf8').includes('musl')
|
|
19
|
+
} catch {
|
|
20
|
+
return true
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
const { glibcVersionRuntime } = process.report.getReport().header
|
|
24
|
+
return !glibcVersionRuntime
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
switch (platform) {
|
|
29
|
+
case 'darwin':
|
|
30
|
+
switch (arch) {
|
|
31
|
+
case 'x64':
|
|
32
|
+
localFileExisted = existsSync(join(__dirname, 'a3s-code.darwin-x64.node'))
|
|
33
|
+
try {
|
|
34
|
+
if (localFileExisted) {
|
|
35
|
+
nativeBinding = require('./a3s-code.darwin-x64.node')
|
|
36
|
+
} else {
|
|
37
|
+
nativeBinding = require('@a3s-lab/code-darwin-x64')
|
|
38
|
+
}
|
|
39
|
+
} catch (e) {
|
|
40
|
+
loadError = e
|
|
41
|
+
}
|
|
42
|
+
break
|
|
43
|
+
case 'arm64':
|
|
44
|
+
localFileExisted = existsSync(join(__dirname, 'a3s-code.darwin-arm64.node'))
|
|
45
|
+
try {
|
|
46
|
+
if (localFileExisted) {
|
|
47
|
+
nativeBinding = require('./a3s-code.darwin-arm64.node')
|
|
48
|
+
} else {
|
|
49
|
+
nativeBinding = require('@a3s-lab/code-darwin-arm64')
|
|
50
|
+
}
|
|
51
|
+
} catch (e) {
|
|
52
|
+
loadError = e
|
|
53
|
+
}
|
|
54
|
+
break
|
|
55
|
+
default:
|
|
56
|
+
throw new Error(`Unsupported architecture on macOS: ${arch}`)
|
|
57
|
+
}
|
|
58
|
+
break
|
|
59
|
+
case 'linux':
|
|
60
|
+
switch (arch) {
|
|
61
|
+
case 'x64':
|
|
62
|
+
if (isMusl()) {
|
|
63
|
+
localFileExisted = existsSync(join(__dirname, 'a3s-code.linux-x64-musl.node'))
|
|
64
|
+
try {
|
|
65
|
+
if (localFileExisted) {
|
|
66
|
+
nativeBinding = require('./a3s-code.linux-x64-musl.node')
|
|
67
|
+
} else {
|
|
68
|
+
nativeBinding = require('@a3s-lab/code-linux-x64-musl')
|
|
69
|
+
}
|
|
70
|
+
} catch (e) {
|
|
71
|
+
loadError = e
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
localFileExisted = existsSync(join(__dirname, 'a3s-code.linux-x64-gnu.node'))
|
|
75
|
+
try {
|
|
76
|
+
if (localFileExisted) {
|
|
77
|
+
nativeBinding = require('./a3s-code.linux-x64-gnu.node')
|
|
78
|
+
} else {
|
|
79
|
+
nativeBinding = require('@a3s-lab/code-linux-x64-gnu')
|
|
80
|
+
}
|
|
81
|
+
} catch (e) {
|
|
82
|
+
loadError = e
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
break
|
|
86
|
+
case 'arm64':
|
|
87
|
+
if (isMusl()) {
|
|
88
|
+
localFileExisted = existsSync(join(__dirname, 'a3s-code.linux-arm64-musl.node'))
|
|
89
|
+
try {
|
|
90
|
+
if (localFileExisted) {
|
|
91
|
+
nativeBinding = require('./a3s-code.linux-arm64-musl.node')
|
|
92
|
+
} else {
|
|
93
|
+
nativeBinding = require('@a3s-lab/code-linux-arm64-musl')
|
|
94
|
+
}
|
|
95
|
+
} catch (e) {
|
|
96
|
+
loadError = e
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
localFileExisted = existsSync(join(__dirname, 'a3s-code.linux-arm64-gnu.node'))
|
|
100
|
+
try {
|
|
101
|
+
if (localFileExisted) {
|
|
102
|
+
nativeBinding = require('./a3s-code.linux-arm64-gnu.node')
|
|
103
|
+
} else {
|
|
104
|
+
nativeBinding = require('@a3s-lab/code-linux-arm64-gnu')
|
|
105
|
+
}
|
|
106
|
+
} catch (e) {
|
|
107
|
+
loadError = e
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
break
|
|
111
|
+
default:
|
|
112
|
+
throw new Error(`Unsupported architecture on Linux: ${arch}`)
|
|
113
|
+
}
|
|
114
|
+
break
|
|
115
|
+
default:
|
|
116
|
+
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (!nativeBinding) {
|
|
120
|
+
if (loadError) {
|
|
121
|
+
throw loadError
|
|
122
|
+
}
|
|
123
|
+
throw new Error(`Failed to load native binding`)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const { Agent } = nativeBinding
|
|
127
|
+
|
|
128
|
+
module.exports.Agent = Agent
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,43 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@a3s-lab/code",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"test:watch": "vitest",
|
|
16
|
-
"clean": "rm -rf dist",
|
|
17
|
-
"prepublishOnly": "npm run build"
|
|
18
|
-
},
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"@grpc/grpc-js": "^1.9.0",
|
|
21
|
-
"@grpc/proto-loader": "^0.7.0"
|
|
22
|
-
},
|
|
23
|
-
"devDependencies": {
|
|
24
|
-
"@vitest/coverage-v8": "^1.6.1",
|
|
25
|
-
"prettier": "^3.0.0",
|
|
26
|
-
"typescript": "^5.3.0",
|
|
27
|
-
"vitest": "^1.0.0"
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "A3S Code - Native AI coding agent library for Node.js",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"napi": {
|
|
8
|
+
"binaryName": "a3s-code",
|
|
9
|
+
"targets": [
|
|
10
|
+
"aarch64-apple-darwin",
|
|
11
|
+
"x86_64-apple-darwin",
|
|
12
|
+
"x86_64-unknown-linux-gnu",
|
|
13
|
+
"aarch64-unknown-linux-gnu"
|
|
14
|
+
]
|
|
28
15
|
},
|
|
29
|
-
"keywords": [
|
|
30
|
-
"a3s",
|
|
31
|
-
"code-agent",
|
|
32
|
-
"grpc",
|
|
33
|
-
"sdk"
|
|
34
|
-
],
|
|
35
16
|
"license": "MIT",
|
|
36
17
|
"repository": {
|
|
37
18
|
"type": "git",
|
|
38
|
-
"url": "https://github.com/
|
|
19
|
+
"url": "https://github.com/A3S-Lab/Code"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"index.js",
|
|
23
|
+
"index.d.ts",
|
|
24
|
+
"*.node"
|
|
25
|
+
],
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@napi-rs/cli": "^2"
|
|
39
28
|
},
|
|
40
|
-
"
|
|
41
|
-
"
|
|
29
|
+
"scripts": {
|
|
30
|
+
"artifacts": "napi artifacts",
|
|
31
|
+
"build": "napi build --platform --release --js index.js --dts index.d.ts",
|
|
32
|
+
"build:debug": "napi build --platform --js index.js --dts index.d.ts",
|
|
33
|
+
"prepublishOnly": "napi prepublish -t npm",
|
|
34
|
+
"test": "node test.mjs"
|
|
42
35
|
}
|
|
43
36
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 A3S Lab
|
|
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.
|