@a3s-lab/code 1.7.2 → 1.8.3
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 +3 -66
- package/index.d.ts +37 -47
- package/index.js +16 -7
- package/package.json +8 -9
package/README.md
CHANGED
|
@@ -28,35 +28,18 @@ main().catch(console.error)
|
|
|
28
28
|
|
|
29
29
|
`session.tool(...)` returns a `ToolResult` enriched with parsed metadata helpers.
|
|
30
30
|
|
|
31
|
-
### Document Runtime
|
|
32
|
-
|
|
33
|
-
```js
|
|
34
|
-
const { parseDocumentRuntime } = require('@a3s-lab/code')
|
|
35
|
-
|
|
36
|
-
const tool = await session.tool('agentic_parse', { path: 'docs/scanned.pdf' })
|
|
37
|
-
console.log(tool.metadata)
|
|
38
|
-
console.log(tool.documentRuntime)
|
|
39
|
-
|
|
40
|
-
const runtime = parseDocumentRuntime(tool)
|
|
41
|
-
if (runtime?.ocr) {
|
|
42
|
-
console.log(runtime.ocr.provider, runtime.ocr.model, runtime.ocr.dpi)
|
|
43
|
-
}
|
|
44
|
-
```
|
|
45
|
-
|
|
46
31
|
### Agentic Parse LLM Blocks
|
|
47
32
|
|
|
48
33
|
When `agentic_parse` runs with a query, the SDK exposes the exact structured
|
|
49
34
|
document blocks selected for the LLM input.
|
|
50
35
|
|
|
51
36
|
```js
|
|
52
|
-
const { parseAgenticParseLlmBlocks } = require('@a3s-lab/code')
|
|
53
|
-
|
|
54
37
|
const tool = await session.tool('agentic_parse', {
|
|
55
38
|
path: 'docs/scanned.pdf',
|
|
56
39
|
query: 'overview',
|
|
57
40
|
})
|
|
58
41
|
|
|
59
|
-
for (const block of tool.agenticParseLlmBlocks ??
|
|
42
|
+
for (const block of tool.agenticParseLlmBlocks ?? []) {
|
|
60
43
|
console.log(block.index, block.kind, block.label, block.location?.display)
|
|
61
44
|
}
|
|
62
45
|
```
|
|
@@ -67,14 +50,12 @@ for (const block of tool.agenticParseLlmBlocks ?? parseAgenticParseLlmBlocks(too
|
|
|
67
50
|
locators derived from `CompositeDocumentParser` blocks.
|
|
68
51
|
|
|
69
52
|
```js
|
|
70
|
-
const { parseAgenticSearchResults } = require('@a3s-lab/code')
|
|
71
|
-
|
|
72
53
|
const search = await session.tool('agentic_search', {
|
|
73
54
|
query: 'overview',
|
|
74
55
|
mode: 'fast',
|
|
75
56
|
})
|
|
76
57
|
|
|
77
|
-
for (const result of search.agenticSearchResults ??
|
|
58
|
+
for (const result of search.agenticSearchResults ?? []) {
|
|
78
59
|
for (const match of result.matches ?? []) {
|
|
79
60
|
console.log(match.lineNumber, match.locator, match.content)
|
|
80
61
|
}
|
|
@@ -89,59 +70,15 @@ const deep = await session.tool('agentic_search', {
|
|
|
89
70
|
mode: 'deep',
|
|
90
71
|
})
|
|
91
72
|
|
|
92
|
-
for (const result of deep.agenticSearchResults ??
|
|
73
|
+
for (const result of deep.agenticSearchResults ?? []) {
|
|
93
74
|
for (const sampled of result.sampledLines ?? []) {
|
|
94
75
|
console.log(sampled.lineNumber, sampled.locator, sampled.distance, sampled.weight)
|
|
95
76
|
}
|
|
96
77
|
}
|
|
97
78
|
```
|
|
98
79
|
|
|
99
|
-
## OCR Backend For Better Context Extraction
|
|
100
|
-
|
|
101
|
-
Use `documentOcrProvider` when you want `agentic_search` and `agentic_parse`
|
|
102
|
-
to recover context from scanned PDFs or images via a JavaScript OCR callback.
|
|
103
|
-
|
|
104
|
-
```js
|
|
105
|
-
const {
|
|
106
|
-
Agent,
|
|
107
|
-
DocumentParserRegistry,
|
|
108
|
-
} = require('@a3s-lab/code')
|
|
109
|
-
|
|
110
|
-
async function main() {
|
|
111
|
-
const agent = await Agent.create('agent.hcl')
|
|
112
|
-
|
|
113
|
-
const session = agent.session('.', {
|
|
114
|
-
documentParserRegistry: new DocumentParserRegistry({
|
|
115
|
-
ocr: {
|
|
116
|
-
enabled: true,
|
|
117
|
-
model: 'openai/gpt-4.1-mini',
|
|
118
|
-
maxImages: 2,
|
|
119
|
-
dpi: 144,
|
|
120
|
-
},
|
|
121
|
-
}),
|
|
122
|
-
documentOcrProvider: {
|
|
123
|
-
name: 'node-mock-ocr',
|
|
124
|
-
formats: ['pdf', 'image'],
|
|
125
|
-
handler(request) {
|
|
126
|
-
console.log(request.path, request.format, request.config)
|
|
127
|
-
return 'Recovered OCR text from Node backend.'
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
const tool = await session.tool('agentic_parse', { path: 'docs/scanned.pdf' })
|
|
133
|
-
console.log(tool.documentRuntime)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
main().catch(console.error)
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
If you do not inject a backend, the Rust core can also auto-detect local
|
|
140
|
-
`tesseract` and `pdftoppm` installations for the same context-extraction fallback.
|
|
141
|
-
|
|
142
80
|
## Examples
|
|
143
81
|
|
|
144
|
-
- `examples/test-document-ocr-provider.js`
|
|
145
82
|
- `examples/test-agentic-parse-llm-blocks.js`
|
|
146
83
|
- `examples/test-agentic-search-locators.js`
|
|
147
84
|
- `examples/test-agentic-search-sampled-lines.js`
|
package/index.d.ts
CHANGED
|
@@ -142,36 +142,6 @@ export interface AhpEventContext {
|
|
|
142
142
|
currentTask?: string
|
|
143
143
|
capabilities?: Record<string, string>
|
|
144
144
|
}
|
|
145
|
-
/** A single match within an agentic search result. */
|
|
146
|
-
export interface AgenticSearchMatch {
|
|
147
|
-
lineNumber?: number
|
|
148
|
-
content?: string
|
|
149
|
-
locator?: string
|
|
150
|
-
contextBefore: Array<string>
|
|
151
|
-
contextAfter: Array<string>
|
|
152
|
-
}
|
|
153
|
-
/** A sampled line from an agentic search result. */
|
|
154
|
-
export interface AgenticSearchSampledLine {
|
|
155
|
-
lineNumber?: number
|
|
156
|
-
content?: string
|
|
157
|
-
locator?: string
|
|
158
|
-
distance?: number
|
|
159
|
-
weight?: number
|
|
160
|
-
}
|
|
161
|
-
/** An agentic search result with scoring and matches. */
|
|
162
|
-
export interface AgenticSearchResult {
|
|
163
|
-
path?: string
|
|
164
|
-
fileType?: string
|
|
165
|
-
relevance?: number
|
|
166
|
-
evidenceScore?: number
|
|
167
|
-
matchCount?: number
|
|
168
|
-
sampledLineCount?: number
|
|
169
|
-
score?: number
|
|
170
|
-
matches: Array<AgenticSearchMatch>
|
|
171
|
-
sampledLines: Array<AgenticSearchSampledLine>
|
|
172
|
-
}
|
|
173
|
-
/** Parse a JSON string or object into AgenticSearchResult objects. */
|
|
174
|
-
export declare function parseAgenticSearchResults(json: any): Array<AgenticSearchResult>
|
|
175
145
|
export interface AgentResult {
|
|
176
146
|
text: string
|
|
177
147
|
toolCallsCount: number
|
|
@@ -216,6 +186,8 @@ export interface ToolResult {
|
|
|
216
186
|
exitCode: number
|
|
217
187
|
/** Raw JSON-encoded tool metadata returned by the Rust core API. */
|
|
218
188
|
metadataJson?: string
|
|
189
|
+
/** Convenience JSON view of `metadata.document_runtime` when present. */
|
|
190
|
+
documentRuntimeJson?: string
|
|
219
191
|
}
|
|
220
192
|
/** Result of a single `EventStream.next()` call. */
|
|
221
193
|
export interface NextResult {
|
|
@@ -580,16 +552,38 @@ export interface SkillInfo {
|
|
|
580
552
|
* Each entry has `name`, `description`, and `kind` (instruction, tool, or agent).
|
|
581
553
|
*/
|
|
582
554
|
export declare function builtinSkills(): Array<SkillInfo>
|
|
555
|
+
/** Role of a team member. */
|
|
556
|
+
export const enum TeamRole {
|
|
557
|
+
/** Decomposes goals into tasks, assigns work. */
|
|
558
|
+
Lead = 0,
|
|
559
|
+
/** Executes assigned tasks. */
|
|
560
|
+
Worker = 1,
|
|
561
|
+
/** Reviews completed work, provides feedback. */
|
|
562
|
+
Reviewer = 2
|
|
563
|
+
}
|
|
564
|
+
/** Task status on the team task board. */
|
|
565
|
+
export const enum TeamTaskStatus {
|
|
566
|
+
/** Waiting to be claimed. */
|
|
567
|
+
Open = 0,
|
|
568
|
+
/** Claimed by a worker. */
|
|
569
|
+
InProgress = 1,
|
|
570
|
+
/** Work done, awaiting review. */
|
|
571
|
+
InReview = 2,
|
|
572
|
+
/** Approved by reviewer. */
|
|
573
|
+
Done = 3,
|
|
574
|
+
/** Rejected, needs rework. */
|
|
575
|
+
Rejected = 4
|
|
576
|
+
}
|
|
583
577
|
/** Team configuration. */
|
|
584
578
|
export interface TeamConfig {
|
|
585
579
|
/** Maximum concurrent tasks on the board (default: 50). */
|
|
586
|
-
maxTasks
|
|
580
|
+
maxTasks?: number
|
|
587
581
|
/** Message channel buffer size (default: 128). */
|
|
588
|
-
channelBuffer
|
|
582
|
+
channelBuffer?: number
|
|
589
583
|
/** Maximum coordinator rounds before `runUntilDone` exits (default: 10). */
|
|
590
|
-
maxRounds
|
|
584
|
+
maxRounds?: number
|
|
591
585
|
/** Worker/Reviewer polling interval in milliseconds (default: 200). */
|
|
592
|
-
pollIntervalMs
|
|
586
|
+
pollIntervalMs?: number
|
|
593
587
|
}
|
|
594
588
|
/** A task snapshot from the team board (read-only). */
|
|
595
589
|
export interface TeamTask {
|
|
@@ -597,7 +591,7 @@ export interface TeamTask {
|
|
|
597
591
|
description: string
|
|
598
592
|
postedBy: string
|
|
599
593
|
assignedTo?: string
|
|
600
|
-
/** Task status
|
|
594
|
+
/** Task status. */
|
|
601
595
|
status: string
|
|
602
596
|
result?: string
|
|
603
597
|
createdAt: number
|
|
@@ -1089,7 +1083,7 @@ export declare class Session {
|
|
|
1089
1083
|
/** Search file contents with a regex pattern. */
|
|
1090
1084
|
grep(pattern: string): Promise<string>
|
|
1091
1085
|
/** Execute a git command (status, log, branch, checkout, diff, stash, remote, worktree). */
|
|
1092
|
-
git(command: string, subcommand?: string, name?: string, path?: string, newBranch?: boolean, base?: string, force?: boolean, maxCount?: number, message?: string, includeUntracked?: boolean, target?: string, reference?: string): Promise<ToolResult>
|
|
1086
|
+
git(command: string, subcommand?: string | undefined | null, name?: string | undefined | null, path?: string | undefined | null, newBranch?: boolean | undefined | null, base?: string | undefined | null, force?: boolean | undefined | null, maxCount?: number | undefined | null, message?: string | undefined | null, includeUntracked?: boolean | undefined | null, target?: string | undefined | null, reference?: string | undefined | null): Promise<ToolResult>
|
|
1093
1087
|
/** Check if this session has a lane queue configured. */
|
|
1094
1088
|
hasQueue(): boolean
|
|
1095
1089
|
/**
|
|
@@ -1396,12 +1390,8 @@ export declare class TeamTaskBoard {
|
|
|
1396
1390
|
reject(taskId: string): boolean
|
|
1397
1391
|
/** Get a task by ID. */
|
|
1398
1392
|
get(taskId: string): TeamTask | null
|
|
1399
|
-
/**
|
|
1400
|
-
|
|
1401
|
-
*
|
|
1402
|
-
* @param status - "open", "in_progress", "in_review", "done", or "rejected"
|
|
1403
|
-
*/
|
|
1404
|
-
byStatus(status: string): Array<TeamTask>
|
|
1393
|
+
/** Get all tasks with the given status. */
|
|
1394
|
+
byStatus(status: TeamTaskStatus): Array<TeamTask>
|
|
1405
1395
|
/** Get all tasks assigned to a member. */
|
|
1406
1396
|
byAssignee(memberId: string): Array<TeamTask>
|
|
1407
1397
|
/** Summary stats as `{ open, inProgress, inReview, done, rejected }`. */
|
|
@@ -1419,9 +1409,9 @@ export declare class TeamTaskBoard {
|
|
|
1419
1409
|
* @example
|
|
1420
1410
|
* ```js
|
|
1421
1411
|
* const team = new Team("refactor-auth");
|
|
1422
|
-
* team.addMember("lead",
|
|
1423
|
-
* team.addMember("worker-1",
|
|
1424
|
-
* team.addMember("reviewer",
|
|
1412
|
+
* team.addMember("lead", TeamRole.Lead);
|
|
1413
|
+
* team.addMember("worker-1", TeamRole.Worker);
|
|
1414
|
+
* team.addMember("reviewer", TeamRole.Reviewer);
|
|
1425
1415
|
* const runner = new TeamRunner(team);
|
|
1426
1416
|
* runner.bindSession("lead", leadSession);
|
|
1427
1417
|
* const result = await runner.runUntilDone("Refactor the auth module");
|
|
@@ -1439,9 +1429,9 @@ export declare class Team {
|
|
|
1439
1429
|
* Add a member to the team.
|
|
1440
1430
|
*
|
|
1441
1431
|
* @param memberId - Unique member identifier
|
|
1442
|
-
* @param role -
|
|
1432
|
+
* @param role - TeamRole: Lead, Worker, or Reviewer
|
|
1443
1433
|
*/
|
|
1444
|
-
addMember(memberId: string, role:
|
|
1434
|
+
addMember(memberId: string, role: TeamRole): void
|
|
1445
1435
|
/** Remove a member. Returns true if the member was found. */
|
|
1446
1436
|
removeMember(memberId: string): boolean
|
|
1447
1437
|
/** Number of registered members. */
|
package/index.js
CHANGED
|
@@ -118,6 +118,18 @@ switch (platform) {
|
|
|
118
118
|
break
|
|
119
119
|
} catch {}
|
|
120
120
|
switch (arch) {
|
|
121
|
+
case 'x64':
|
|
122
|
+
localFileExisted = existsSync(join(__dirname, 'index.darwin-x64.node'))
|
|
123
|
+
try {
|
|
124
|
+
if (localFileExisted) {
|
|
125
|
+
nativeBinding = require('./index.darwin-x64.node')
|
|
126
|
+
} else {
|
|
127
|
+
nativeBinding = require('@a3s-lab/code-darwin-x64')
|
|
128
|
+
}
|
|
129
|
+
} catch (e) {
|
|
130
|
+
loadError = e
|
|
131
|
+
}
|
|
132
|
+
break
|
|
121
133
|
case 'arm64':
|
|
122
134
|
localFileExisted = existsSync(
|
|
123
135
|
join(__dirname, 'index.darwin-arm64.node')
|
|
@@ -133,7 +145,7 @@ switch (platform) {
|
|
|
133
145
|
}
|
|
134
146
|
break
|
|
135
147
|
default:
|
|
136
|
-
throw new Error(`Unsupported architecture on macOS: ${arch}
|
|
148
|
+
throw new Error(`Unsupported architecture on macOS: ${arch}`)
|
|
137
149
|
}
|
|
138
150
|
break
|
|
139
151
|
case 'freebsd':
|
|
@@ -298,18 +310,13 @@ if (!nativeBinding) {
|
|
|
298
310
|
throw new Error(`Failed to load native binding`)
|
|
299
311
|
}
|
|
300
312
|
|
|
301
|
-
const {
|
|
313
|
+
const { EventStream, FileMemoryStore, FileSessionStore, MemorySessionStore, DefaultSecurityProvider, SkillPlugin, StdioTransport, HttpTransport, WebSocketTransport, UnixSocketTransport, Agent, Session, builtinSkills, TeamRole, TeamTaskStatus, TeamTaskBoard, Team, TeamRunner, SubAgentHandle, SubAgentEventStream, Orchestrator } = nativeBinding
|
|
302
314
|
|
|
303
|
-
module.exports.parseDocumentRuntime = parseDocumentRuntime
|
|
304
|
-
module.exports.parseAgenticSearchResults = parseAgenticSearchResults
|
|
305
|
-
module.exports.parseAgenticParseLlmBlocks = parseAgenticParseLlmBlocks
|
|
306
|
-
module.exports.enrichToolResult = enrichToolResult
|
|
307
315
|
module.exports.EventStream = EventStream
|
|
308
316
|
module.exports.FileMemoryStore = FileMemoryStore
|
|
309
317
|
module.exports.FileSessionStore = FileSessionStore
|
|
310
318
|
module.exports.MemorySessionStore = MemorySessionStore
|
|
311
319
|
module.exports.DefaultSecurityProvider = DefaultSecurityProvider
|
|
312
|
-
module.exports.DocumentParserRegistry = DocumentParserRegistry
|
|
313
320
|
module.exports.SkillPlugin = SkillPlugin
|
|
314
321
|
module.exports.StdioTransport = StdioTransport
|
|
315
322
|
module.exports.HttpTransport = HttpTransport
|
|
@@ -318,6 +325,8 @@ module.exports.UnixSocketTransport = UnixSocketTransport
|
|
|
318
325
|
module.exports.Agent = Agent
|
|
319
326
|
module.exports.Session = Session
|
|
320
327
|
module.exports.builtinSkills = builtinSkills
|
|
328
|
+
module.exports.TeamRole = TeamRole
|
|
329
|
+
module.exports.TeamTaskStatus = TeamTaskStatus
|
|
321
330
|
module.exports.TeamTaskBoard = TeamTaskBoard
|
|
322
331
|
module.exports.Team = Team
|
|
323
332
|
module.exports.TeamRunner = TeamRunner
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@a3s-lab/code",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.3",
|
|
4
4
|
"description": "A3S Code - Native AI coding agent library for Node.js",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -41,15 +41,14 @@
|
|
|
41
41
|
"test:agentic-search-locators": "node examples/test-agentic-search-locators.js",
|
|
42
42
|
"test:agentic-search-sampled-lines": "node examples/test-agentic-search-sampled-lines.js",
|
|
43
43
|
"test:agentic-parse-llm-blocks": "node examples/test-agentic-parse-llm-blocks.js",
|
|
44
|
-
"test:loop": "tsx --tsconfig examples/tsconfig.json examples/test_loop_commands.ts"
|
|
45
|
-
"test:ocr-provider-example": "node examples/test-document-ocr-provider.js"
|
|
44
|
+
"test:loop": "tsx --tsconfig examples/tsconfig.json examples/test_loop_commands.ts"
|
|
46
45
|
},
|
|
47
46
|
"optionalDependencies": {
|
|
48
|
-
"@a3s-lab/code-darwin-arm64": "1.
|
|
49
|
-
"@a3s-lab/code-linux-x64-gnu": "1.
|
|
50
|
-
"@a3s-lab/code-linux-x64-musl": "1.
|
|
51
|
-
"@a3s-lab/code-linux-arm64-gnu": "1.
|
|
52
|
-
"@a3s-lab/code-linux-arm64-musl": "1.
|
|
53
|
-
"@a3s-lab/code-win32-x64-msvc": "1.
|
|
47
|
+
"@a3s-lab/code-darwin-arm64": "1.8.3",
|
|
48
|
+
"@a3s-lab/code-linux-x64-gnu": "1.8.3",
|
|
49
|
+
"@a3s-lab/code-linux-x64-musl": "1.8.3",
|
|
50
|
+
"@a3s-lab/code-linux-arm64-gnu": "1.8.3",
|
|
51
|
+
"@a3s-lab/code-linux-arm64-musl": "1.8.3",
|
|
52
|
+
"@a3s-lab/code-win32-x64-msvc": "1.8.3"
|
|
54
53
|
}
|
|
55
54
|
}
|