@a3s-lab/code 0.3.1 → 0.4.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 +371 -509
- package/dist/chat.d.ts +97 -0
- package/dist/chat.d.ts.map +1 -0
- package/dist/chat.js +179 -0
- package/dist/chat.js.map +1 -0
- package/dist/client.d.ts +199 -25
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +149 -18
- package/dist/client.js.map +1 -1
- package/dist/generate.d.ts +130 -0
- package/dist/generate.d.ts.map +1 -0
- package/dist/generate.js +283 -0
- package/dist/generate.js.map +1 -0
- package/dist/index.d.ts +44 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -2
- package/dist/index.js.map +1 -1
- package/dist/message.d.ts +157 -0
- package/dist/message.d.ts.map +1 -0
- package/dist/message.js +279 -0
- package/dist/message.js.map +1 -0
- package/dist/provider.d.ts +64 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +60 -0
- package/dist/provider.js.map +1 -0
- package/dist/session.d.ts +540 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +1092 -0
- package/dist/session.js.map +1 -0
- package/dist/tool.d.ts +106 -0
- package/dist/tool.d.ts.map +1 -0
- package/dist/tool.js +71 -0
- package/dist/tool.js.map +1 -0
- package/package.json +1 -1
- package/proto/code_agent.proto +256 -14
package/dist/generate.js
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-Level AI Functions (Convenience Wrappers)
|
|
3
|
+
*
|
|
4
|
+
* Vercel AI SDK-style standalone functions that auto-manage session lifecycle.
|
|
5
|
+
* These create a temporary session, run the operation, and clean up.
|
|
6
|
+
*
|
|
7
|
+
* For multi-turn or long-lived usage, prefer creating a Session directly:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const session = await client.createSession({ model: openai('gpt-4o') });
|
|
10
|
+
* const { text } = await session.generateText({ prompt: 'Hello' });
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { generateText, streamText, createProvider } from '@a3s-lab/code';
|
|
16
|
+
*
|
|
17
|
+
* const openai = createProvider({ name: 'openai', apiKey: 'sk-xxx' });
|
|
18
|
+
*
|
|
19
|
+
* // One-shot generation (auto session)
|
|
20
|
+
* const { text } = await generateText({
|
|
21
|
+
* model: openai('gpt-4o'),
|
|
22
|
+
* prompt: 'Explain this codebase',
|
|
23
|
+
* workspace: '/project',
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
import { A3sClient } from './client.js';
|
|
28
|
+
// ============================================================================
|
|
29
|
+
// Standalone Functions (auto session lifecycle)
|
|
30
|
+
// ============================================================================
|
|
31
|
+
/**
|
|
32
|
+
* Generate text from a language model (auto session).
|
|
33
|
+
*
|
|
34
|
+
* Creates a temporary session, generates text, and cleans up.
|
|
35
|
+
* For multi-turn usage, create a Session directly instead.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const { text } = await generateText({
|
|
40
|
+
* model: openai('gpt-4o'),
|
|
41
|
+
* prompt: 'Summarize this file',
|
|
42
|
+
* workspace: '/project',
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export async function generateText(options) {
|
|
47
|
+
const client = new A3sClient(options.server);
|
|
48
|
+
const session = await client.createSession({
|
|
49
|
+
model: options.model,
|
|
50
|
+
workspace: options.workspace,
|
|
51
|
+
system: options.system,
|
|
52
|
+
});
|
|
53
|
+
try {
|
|
54
|
+
return await session.generateText({
|
|
55
|
+
prompt: options.prompt,
|
|
56
|
+
messages: options.messages,
|
|
57
|
+
tools: options.tools,
|
|
58
|
+
maxSteps: options.maxSteps,
|
|
59
|
+
onStepFinish: options.onStepFinish,
|
|
60
|
+
onToolCall: options.onToolCall,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
await session.close();
|
|
65
|
+
client.close();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Stream text from a language model (auto session).
|
|
70
|
+
*
|
|
71
|
+
* Returns immediately with stream handles. Session is cleaned up when stream ends.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const { textStream } = streamText({
|
|
76
|
+
* model: openai('gpt-4o'),
|
|
77
|
+
* prompt: 'Explain this codebase',
|
|
78
|
+
* });
|
|
79
|
+
* for await (const chunk of textStream) {
|
|
80
|
+
* process.stdout.write(chunk);
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export function streamText(options) {
|
|
85
|
+
const client = new A3sClient(options.server);
|
|
86
|
+
let session = null;
|
|
87
|
+
// We need to create the session first, then delegate to session.streamText()
|
|
88
|
+
// Since streamText returns synchronously, we wrap with a deferred pattern
|
|
89
|
+
let resolveText;
|
|
90
|
+
let resolveUsage;
|
|
91
|
+
let resolveFinishReason;
|
|
92
|
+
let resolveSteps;
|
|
93
|
+
let rejectAll;
|
|
94
|
+
const textPromise = new Promise((res, rej) => {
|
|
95
|
+
resolveText = res;
|
|
96
|
+
rejectAll = rej;
|
|
97
|
+
});
|
|
98
|
+
const usagePromise = new Promise((res) => { resolveUsage = res; });
|
|
99
|
+
const finishReasonPromise = new Promise((res) => { resolveFinishReason = res; });
|
|
100
|
+
const stepsPromise = new Promise((res) => { resolveSteps = res; });
|
|
101
|
+
const chunks = [];
|
|
102
|
+
let streamDone = false;
|
|
103
|
+
const waiters = [];
|
|
104
|
+
function notify() {
|
|
105
|
+
for (const w of waiters.splice(0))
|
|
106
|
+
w();
|
|
107
|
+
}
|
|
108
|
+
const produce = (async () => {
|
|
109
|
+
try {
|
|
110
|
+
session = await client.createSession({
|
|
111
|
+
model: options.model,
|
|
112
|
+
workspace: options.workspace,
|
|
113
|
+
system: options.system,
|
|
114
|
+
});
|
|
115
|
+
const result = session.streamText({
|
|
116
|
+
prompt: options.prompt,
|
|
117
|
+
messages: options.messages,
|
|
118
|
+
tools: options.tools,
|
|
119
|
+
maxSteps: options.maxSteps,
|
|
120
|
+
onStepFinish: options.onStepFinish,
|
|
121
|
+
onToolCall: options.onToolCall,
|
|
122
|
+
});
|
|
123
|
+
// Pipe fullStream into our chunks buffer
|
|
124
|
+
for await (const chunk of result.fullStream) {
|
|
125
|
+
chunks.push(chunk);
|
|
126
|
+
notify();
|
|
127
|
+
}
|
|
128
|
+
resolveText(await result.text);
|
|
129
|
+
resolveUsage(await result.usage);
|
|
130
|
+
resolveFinishReason(await result.finishReason);
|
|
131
|
+
resolveSteps(await result.steps);
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
rejectAll(err);
|
|
135
|
+
}
|
|
136
|
+
finally {
|
|
137
|
+
streamDone = true;
|
|
138
|
+
notify();
|
|
139
|
+
if (session)
|
|
140
|
+
await session.close();
|
|
141
|
+
client.close();
|
|
142
|
+
}
|
|
143
|
+
})();
|
|
144
|
+
produce.catch(() => { });
|
|
145
|
+
function createIterator(transform) {
|
|
146
|
+
return {
|
|
147
|
+
[Symbol.asyncIterator]() {
|
|
148
|
+
let index = 0;
|
|
149
|
+
return {
|
|
150
|
+
async next() {
|
|
151
|
+
while (true) {
|
|
152
|
+
if (index < chunks.length) {
|
|
153
|
+
const val = transform(chunks[index++]);
|
|
154
|
+
if (val !== null)
|
|
155
|
+
return { value: val, done: false };
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (streamDone) {
|
|
159
|
+
return { value: undefined, done: true };
|
|
160
|
+
}
|
|
161
|
+
await new Promise((r) => waiters.push(r));
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
textStream: createIterator((c) => (c.content ? c.content : null)),
|
|
170
|
+
fullStream: createIterator((c) => c),
|
|
171
|
+
toolStream: createIterator((c) => (c.toolCall ? c.toolCall : null)),
|
|
172
|
+
text: textPromise,
|
|
173
|
+
usage: usagePromise,
|
|
174
|
+
finishReason: finishReasonPromise,
|
|
175
|
+
steps: stepsPromise,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Generate a structured object from a language model (auto session).
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* const { object } = await generateObject({
|
|
184
|
+
* model: openai('gpt-4o'),
|
|
185
|
+
* schema: JSON.stringify({ type: 'object', properties: { summary: { type: 'string' } } }),
|
|
186
|
+
* prompt: 'Summarize this project',
|
|
187
|
+
* });
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
export async function generateObject(options) {
|
|
191
|
+
const client = new A3sClient(options.server);
|
|
192
|
+
const session = await client.createSession({
|
|
193
|
+
model: options.model,
|
|
194
|
+
workspace: options.workspace,
|
|
195
|
+
system: options.system,
|
|
196
|
+
});
|
|
197
|
+
try {
|
|
198
|
+
return await session.generateObject({
|
|
199
|
+
prompt: options.prompt,
|
|
200
|
+
messages: options.messages,
|
|
201
|
+
schema: options.schema,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
finally {
|
|
205
|
+
await session.close();
|
|
206
|
+
client.close();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Stream a structured object from a language model (auto session).
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```typescript
|
|
214
|
+
* const { partialStream, object } = streamObject({
|
|
215
|
+
* model: openai('gpt-4o'),
|
|
216
|
+
* schema: '{"type":"object","properties":{"items":{"type":"array"}}}',
|
|
217
|
+
* prompt: 'List project files',
|
|
218
|
+
* });
|
|
219
|
+
* for await (const partial of partialStream) {
|
|
220
|
+
* console.log('partial:', partial);
|
|
221
|
+
* }
|
|
222
|
+
* const result = await object;
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
export function streamObject(options) {
|
|
226
|
+
const client = new A3sClient(options.server);
|
|
227
|
+
let session = null;
|
|
228
|
+
let resolveObject;
|
|
229
|
+
let resolveData;
|
|
230
|
+
let rejectAll;
|
|
231
|
+
const objectPromise = new Promise((res, rej) => {
|
|
232
|
+
resolveObject = res;
|
|
233
|
+
rejectAll = rej;
|
|
234
|
+
});
|
|
235
|
+
const dataPromise = new Promise((res) => {
|
|
236
|
+
resolveData = res;
|
|
237
|
+
});
|
|
238
|
+
const partialStream = {
|
|
239
|
+
[Symbol.asyncIterator]() {
|
|
240
|
+
let started = false;
|
|
241
|
+
let innerIter;
|
|
242
|
+
return {
|
|
243
|
+
async next() {
|
|
244
|
+
if (!started) {
|
|
245
|
+
started = true;
|
|
246
|
+
session = await client.createSession({
|
|
247
|
+
model: options.model,
|
|
248
|
+
workspace: options.workspace,
|
|
249
|
+
system: options.system,
|
|
250
|
+
});
|
|
251
|
+
const result = session.streamObject({
|
|
252
|
+
prompt: options.prompt,
|
|
253
|
+
messages: options.messages,
|
|
254
|
+
schema: options.schema,
|
|
255
|
+
});
|
|
256
|
+
innerIter = result.partialStream[Symbol.asyncIterator]();
|
|
257
|
+
// Wire up the promises
|
|
258
|
+
result.object.then((v) => resolveObject(v), (e) => rejectAll(e));
|
|
259
|
+
result.data.then((v) => resolveData(v));
|
|
260
|
+
}
|
|
261
|
+
try {
|
|
262
|
+
const r = await innerIter.next();
|
|
263
|
+
if (r.done) {
|
|
264
|
+
if (session)
|
|
265
|
+
await session.close();
|
|
266
|
+
client.close();
|
|
267
|
+
return { value: undefined, done: true };
|
|
268
|
+
}
|
|
269
|
+
return r;
|
|
270
|
+
}
|
|
271
|
+
catch (err) {
|
|
272
|
+
if (session)
|
|
273
|
+
await session.close();
|
|
274
|
+
client.close();
|
|
275
|
+
throw err;
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
},
|
|
280
|
+
};
|
|
281
|
+
return { partialStream, object: objectPromise, data: dataPromise };
|
|
282
|
+
}
|
|
283
|
+
//# sourceMappingURL=generate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../ts/generate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAoExC,+EAA+E;AAC/E,gDAAgD;AAChD,+EAA+E;AAE/E;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,OAA4B;IAE5B,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7C,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC;QACzC,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,YAAY,CAAC;YAChC,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,UAAU,EAAE,OAAO,CAAC,UAAU;SAC/B,CAAC,CAAC;IACL,CAAC;YAAS,CAAC;QACT,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;QACtB,MAAM,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,UAAU,CAAC,OAA4B;IACrD,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7C,IAAI,OAAO,GAAmB,IA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C;aACF,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;AACrE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,52 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A3S Code Agent TypeScript SDK
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Session-based AI coding agent SDK with AgenticLoop, Skills, HITL, and Lane Queue.
|
|
5
|
+
*
|
|
6
|
+
* @example Quick Start
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { A3sClient, createProvider } from '@a3s-lab/code';
|
|
9
|
+
*
|
|
10
|
+
* const client = new A3sClient();
|
|
11
|
+
* const openai = createProvider({ name: 'openai', apiKey: 'sk-xxx' });
|
|
12
|
+
*
|
|
13
|
+
* await using session = await client.createSession({
|
|
14
|
+
* model: openai('gpt-4o'),
|
|
15
|
+
* workspace: '/project',
|
|
16
|
+
* system: 'You are a senior software engineer.',
|
|
17
|
+
* confirmation: { requireConfirmation: ['Bash', 'Write'] },
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* // Simple question
|
|
21
|
+
* const { text } = await session.send('What is TypeScript?');
|
|
22
|
+
*
|
|
23
|
+
* // Complex task — auto-enters AgenticLoop
|
|
24
|
+
* const { text, steps, toolCalls } = await session.send(
|
|
25
|
+
* 'Refactor the auth module to use JWT',
|
|
26
|
+
* );
|
|
27
|
+
*
|
|
28
|
+
* // Streaming with real-time events
|
|
29
|
+
* const { eventStream } = session.sendStream('Fix all TODOs in src/');
|
|
30
|
+
* for await (const event of eventStream) {
|
|
31
|
+
* if (event.type === 'text') process.stdout.write(event.content);
|
|
32
|
+
* if (event.type === 'tool_call') console.log(`🔧 ${event.toolName}`);
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
6
35
|
*/
|
|
36
|
+
export { Session } from './session.js';
|
|
37
|
+
export type { SessionCreateOptions, MessageInput, StepResult, ToolCallEvent, SessionGenerateTextOptions, SessionGenerateObjectOptions, GenerateTextResult, StreamTextResult, GenerateObjectResult, StreamObjectResult, SendOptions, SendResult, SendStreamResult, AgentLoopEvent, ConfirmationRequest, ConfirmationConfig, PermissionConfig, SkillDefinition, SkillInfo, AgentDefinition, AgentInfo, LaneName, LaneConfig, LaneStats, QueueStats, ExternalTaskResult, SessionStats, } from './session.js';
|
|
38
|
+
export { generateText, streamText, generateObject, streamObject } from './generate.js';
|
|
39
|
+
export type { BaseGenerateOptions, GenerateTextOptions, GenerateObjectOptions, } from './generate.js';
|
|
40
|
+
export { createChat } from './chat.js';
|
|
41
|
+
export type { ChatOptions, ChatSendResult, ChatStreamResult, Chat, } from './chat.js';
|
|
42
|
+
export { createProvider, model } from './provider.js';
|
|
43
|
+
export type { ProviderOptions, ModelRef, ModelSelector, } from './provider.js';
|
|
44
|
+
export { tool } from './tool.js';
|
|
45
|
+
export type { JsonSchema, ToolExecutionOptions, ToolDefinition, ToolSet, } from './tool.js';
|
|
46
|
+
export { convertToModelMessages, convertToUIMessages, a3sMessageToModel, modelMessageToA3s, a3sMessagesToModel, modelMessagesToA3s, a3sMessagesToUI, uiMessagesToA3s, } from './message.js';
|
|
47
|
+
export type { UIMessage, UIMessagePart, UIMessageTextPart, UIMessageToolInvocationPart, UIMessageStepBoundaryPart, UIMessageReasoningPart, ModelMessage, SystemModelMessage, UserModelMessage, AssistantModelMessage, ToolModelMessage, } from './message.js';
|
|
7
48
|
export { A3sClient, StorageType, SessionLane, TimeoutAction, TaskHandlerMode, CronJobStatusEnum, CronExecutionStatusEnum } from './client.js';
|
|
8
|
-
export type { A3sClientOptions, HealthStatus, HealthCheckResponse,
|
|
49
|
+
export type { A3sClientOptions, HealthStatus, HealthCheckResponse, ToolCapability, ModelCapability, ResourceLimits, GetCapabilitiesResponse, InitializeResponse, ShutdownResponse, StorageTypeString, LLMConfig, SessionConfig, ContextUsage, SessionState, SessionInfo, CreateSessionResponse, DestroySessionResponse, ListSessionsResponse, GetSessionResponse, ConfigureSessionResponse, MessageRole, Message, TextContent, ToolUseContent, ToolResultContent, ContentBlock, ConversationMessage, GetMessagesResponse, ToolResult, ToolCall, Usage, FinishReason, GenerateResponse, ChunkType, GenerateChunk, GenerateStructuredResponse, GenerateStructuredChunk, Skill, GetSkillResponse, LoadSkillResponse, UnloadSkillResponse, ListSkillsResponse, GetContextUsageResponse, CompactContextResponse, ClearContextResponse, EventType, AgentEvent, CancelResponse, PauseResponse, ResumeResponse, SessionLaneType, TimeoutActionType, ConfirmationPolicy, ConfirmToolExecutionResponse, SetConfirmationPolicyResponse, GetConfirmationPolicyResponse, TaskHandlerModeType, LaneHandlerConfig, ExternalTask, SetLaneHandlerResponse, GetLaneHandlerResponse, CompleteExternalTaskResponse, ListPendingExternalTasksResponse, PermissionDecision, PermissionRule, PermissionPolicy, SetPermissionPolicyResponse, GetPermissionPolicyResponse, CheckPermissionResponse, AddPermissionRuleResponse, Todo, GetTodosResponse, SetTodosResponse, ModelCostInfo, ModelLimitInfo, ModelModalitiesInfo, ModelInfo, ProviderInfo, ListProvidersResponse, GetProviderResponse, AddProviderResponse, UpdateProviderResponse, RemoveProviderResponse, SetDefaultModelResponse, GetDefaultModelResponse, Complexity, StepStatus, PlanStep, ExecutionPlan, AgentGoal, CreatePlanResponse, GetPlanResponse, ExtractGoalResponse, CheckGoalAchievementResponse, MemoryType, MemoryItem, MemoryStats, StoreMemoryResponse, RetrieveMemoryResponse, SearchMemoriesResponse, GetMemoryStatsResponse, ClearMemoriesResponse, McpStdioTransport, McpHttpTransport, McpTransport, McpServerConfig, McpServerInfo, McpToolInfo, RegisterMcpServerResponse, ConnectMcpServerResponse, DisconnectMcpServerResponse, ListMcpServersResponse, GetMcpToolsResponse, LspServerInfo, LspPosition, LspRange, LspLocation, LspSymbol, LspDiagnostic, StartLspServerResponse, StopLspServerResponse, ListLspServersResponse, LspHoverResponse, LspDefinitionResponse, LspReferencesResponse, LspSymbolsResponse, LspDiagnosticsResponse, CronJobStatus, CronExecutionStatus, CronJob, CronExecution, ListCronJobsResponse, CreateCronJobResponse, GetCronJobResponse, UpdateCronJobResponse, PauseCronJobResponse, ResumeCronJobResponse, DeleteCronJobResponse, GetCronHistoryResponse, RunCronJobResponse, ParseCronScheduleResponse, ToolStats, GetToolMetricsResponse, ModelCostBreakdown, DayCostBreakdown, GetCostSummaryResponse, } from './client.js';
|
|
9
50
|
export { getConfig, getModelConfig, getDefaultModel, printConfig, loadConfigFromFile, loadConfigFromDir, loadDefaultConfig, } from './config.js';
|
|
10
51
|
export type { A3sConfig, ProviderConfig, ModelConfigEntry, ModelConfig, } from './config.js';
|
|
11
52
|
export { openAIRoleToA3S, a3sRoleToOpenAI, openAIMessageToA3S, a3sMessageToOpenAI, openAIMessagesToA3S, normalizeMessage, normalizeMessages, a3sResponseToOpenAI, a3sChunkToOpenAI, isOpenAIFormat, isTextContent, isImageContent, } from './openai-compat.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAMH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,YAAY,EACV,oBAAoB,EACpB,YAAY,EACZ,UAAU,EACV,aAAa,EACb,0BAA0B,EAC1B,4BAA4B,EAC5B,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAElB,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,SAAS,EACT,eAAe,EACf,SAAS,EACT,QAAQ,EACR,UAAU,EACV,SAAS,EACT,UAAU,E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
|
|
2
2
|
* A3S Code Agent TypeScript SDK
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Session-based AI coding agent SDK with AgenticLoop, Skills, HITL, and Lane Queue.
|
|
5
|
+
*
|
|
6
|
+
* @example Quick Start
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { A3sClient, createProvider } from '@a3s-lab/code';
|
|
9
|
+
*
|
|
10
|
+
* const client = new A3sClient();
|
|
11
|
+
* const openai = createProvider({ name: 'openai', apiKey: 'sk-xxx' });
|
|
12
|
+
*
|
|
13
|
+
* await using session = await client.createSession({
|
|
14
|
+
* model: openai('gpt-4o'),
|
|
15
|
+
* workspace: '/project',
|
|
16
|
+
* system: 'You are a senior software engineer.',
|
|
17
|
+
* confirmation: { requireConfirmation: ['Bash', 'Write'] },
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* // Simple question
|
|
21
|
+
* const { text } = await session.send('What is TypeScript?');
|
|
22
|
+
*
|
|
23
|
+
* // Complex task — auto-enters AgenticLoop
|
|
24
|
+
* const { text, steps, toolCalls } = await session.send(
|
|
25
|
+
* 'Refactor the auth module to use JWT',
|
|
26
|
+
* );
|
|
27
|
+
*
|
|
28
|
+
* // Streaming with real-time events
|
|
29
|
+
* const { eventStream } = session.sendStream('Fix all TODOs in src/');
|
|
30
|
+
* for await (const event of eventStream) {
|
|
31
|
+
* if (event.type === 'text') process.stdout.write(event.content);
|
|
32
|
+
* if (event.type === 'tool_call') console.log(`🔧 ${event.toolName}`);
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
6
35
|
*/
|
|
36
|
+
// ============================================================================
|
|
37
|
+
// Session (Core API)
|
|
38
|
+
// ============================================================================
|
|
39
|
+
export { Session } from './session.js';
|
|
40
|
+
// ============================================================================
|
|
41
|
+
// High-Level API (Vercel AI SDK-style convenience wrappers)
|
|
42
|
+
// ============================================================================
|
|
43
|
+
export { generateText, streamText, generateObject, streamObject } from './generate.js';
|
|
44
|
+
export { createChat } from './chat.js';
|
|
45
|
+
export { createProvider, model } from './provider.js';
|
|
46
|
+
export { tool } from './tool.js';
|
|
47
|
+
// UIMessage / ModelMessage Conversion
|
|
48
|
+
export { convertToModelMessages, convertToUIMessages, a3sMessageToModel, modelMessageToA3s, a3sMessagesToModel, modelMessagesToA3s, a3sMessagesToUI, uiMessagesToA3s, } from './message.js';
|
|
49
|
+
// ============================================================================
|
|
50
|
+
// Low-Level Client (for advanced usage)
|
|
51
|
+
// ============================================================================
|
|
7
52
|
export { A3sClient, StorageType, SessionLane, TimeoutAction, TaskHandlerMode, CronJobStatusEnum, CronExecutionStatusEnum } from './client.js';
|
|
8
53
|
export { getConfig, getModelConfig, getDefaultModel, printConfig, loadConfigFromFile, loadConfigFromDir, loadDefaultConfig, } from './config.js';
|
|
9
54
|
// OpenAI-Compatible Types and Utilities
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAE/E,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAgCvC,+EAA+E;AAC/E,4DAA4D;AAC5D,+EAA+E;AAE/E,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAOvF,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAQvC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAOtD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAQjC,sCAAsC;AACtC,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,eAAe,GAChB,MAAM,cAAc,CAAC;AAetB,+EAA+E;AAC/E,wCAAwC;AACxC,+EAA+E;AAE/E,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,eAAe,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAyK9I,OAAO,EACL,SAAS,EACT,cAAc,EACd,eAAe,EACf,WAAW,EACX,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AASrB,wCAAwC;AACxC,OAAO;AACL,uBAAuB;AACvB,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB;AAChB,cAAc;AACd,cAAc,EACd,aAAa,EACb,cAAc,GACf,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UIMessage / ModelMessage Conversion Layer
|
|
3
|
+
*
|
|
4
|
+
* Vercel AI SDK-style message types for frontend ↔ backend conversion.
|
|
5
|
+
*
|
|
6
|
+
* - UIMessage: Frontend format with id, createdAt, parts (for rendering)
|
|
7
|
+
* - ModelMessage: Backend format with role, content (for LLM)
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { convertToModelMessages, convertToUIMessages } from '@a3s-lab/code';
|
|
12
|
+
*
|
|
13
|
+
* // Frontend → Backend (before calling generateText/streamText)
|
|
14
|
+
* const modelMessages = convertToModelMessages(uiMessages);
|
|
15
|
+
* const { text } = await generateText({ model, messages: modelMessages });
|
|
16
|
+
*
|
|
17
|
+
* // Backend → Frontend (after receiving response)
|
|
18
|
+
* const uiMessages = convertToUIMessages(modelMessages);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
import type { Message, ToolCall } from './client.js';
|
|
22
|
+
/** Text part in a UIMessage */
|
|
23
|
+
export interface UIMessageTextPart {
|
|
24
|
+
type: 'text';
|
|
25
|
+
text: string;
|
|
26
|
+
}
|
|
27
|
+
/** Tool invocation part in a UIMessage */
|
|
28
|
+
export interface UIMessageToolInvocationPart {
|
|
29
|
+
type: 'tool-invocation';
|
|
30
|
+
toolInvocation: {
|
|
31
|
+
toolCallId: string;
|
|
32
|
+
toolName: string;
|
|
33
|
+
args: Record<string, unknown>;
|
|
34
|
+
state: 'call' | 'result' | 'partial-call';
|
|
35
|
+
result?: unknown;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** Step boundary part in a UIMessage */
|
|
39
|
+
export interface UIMessageStepBoundaryPart {
|
|
40
|
+
type: 'step-boundary';
|
|
41
|
+
stepIndex: number;
|
|
42
|
+
}
|
|
43
|
+
/** Reasoning part in a UIMessage */
|
|
44
|
+
export interface UIMessageReasoningPart {
|
|
45
|
+
type: 'reasoning';
|
|
46
|
+
reasoning: string;
|
|
47
|
+
}
|
|
48
|
+
/** Union of all UIMessage part types */
|
|
49
|
+
export type UIMessagePart = UIMessageTextPart | UIMessageToolInvocationPart | UIMessageStepBoundaryPart | UIMessageReasoningPart;
|
|
50
|
+
/**
|
|
51
|
+
* UIMessage — Frontend-friendly message format.
|
|
52
|
+
*
|
|
53
|
+
* Contains id, timestamps, and structured parts for rendering in chat UIs.
|
|
54
|
+
* This is the format used by frontend hooks (like useChat in Vercel AI SDK).
|
|
55
|
+
*/
|
|
56
|
+
export interface UIMessage<TMetadata = Record<string, unknown>> {
|
|
57
|
+
/** Unique message identifier */
|
|
58
|
+
id: string;
|
|
59
|
+
/** Message role */
|
|
60
|
+
role: 'user' | 'assistant' | 'system';
|
|
61
|
+
/** Message content (plain text, for backward compatibility) */
|
|
62
|
+
content: string;
|
|
63
|
+
/** Structured parts for rich rendering */
|
|
64
|
+
parts: UIMessagePart[];
|
|
65
|
+
/** Creation timestamp */
|
|
66
|
+
createdAt?: Date;
|
|
67
|
+
/** Custom metadata */
|
|
68
|
+
metadata?: TMetadata;
|
|
69
|
+
}
|
|
70
|
+
/** System message for LLM */
|
|
71
|
+
export interface SystemModelMessage {
|
|
72
|
+
role: 'system';
|
|
73
|
+
content: string;
|
|
74
|
+
}
|
|
75
|
+
/** User message for LLM */
|
|
76
|
+
export interface UserModelMessage {
|
|
77
|
+
role: 'user';
|
|
78
|
+
content: string;
|
|
79
|
+
}
|
|
80
|
+
/** Assistant message for LLM (may include tool calls) */
|
|
81
|
+
export interface AssistantModelMessage {
|
|
82
|
+
role: 'assistant';
|
|
83
|
+
content: string;
|
|
84
|
+
toolCalls?: ToolCall[];
|
|
85
|
+
}
|
|
86
|
+
/** Tool result message for LLM */
|
|
87
|
+
export interface ToolModelMessage {
|
|
88
|
+
role: 'tool';
|
|
89
|
+
content: string;
|
|
90
|
+
toolCallId?: string;
|
|
91
|
+
toolName?: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* ModelMessage — Backend message format for LLM.
|
|
95
|
+
*
|
|
96
|
+
* This is the format passed to generateText(), streamText(), and the
|
|
97
|
+
* underlying A3S client. It maps directly to the A3S proto Message type.
|
|
98
|
+
*/
|
|
99
|
+
export type ModelMessage = SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage;
|
|
100
|
+
/**
|
|
101
|
+
* Convert UIMessage[] to ModelMessage[] for use with generateText/streamText.
|
|
102
|
+
*
|
|
103
|
+
* This is the primary conversion function for frontend → backend message flow.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* import { convertToModelMessages, generateText } from '@a3s-lab/code';
|
|
108
|
+
*
|
|
109
|
+
* // In your API route handler:
|
|
110
|
+
* const modelMessages = convertToModelMessages(uiMessages);
|
|
111
|
+
* const { text } = await generateText({
|
|
112
|
+
* model: openai('gpt-4o'),
|
|
113
|
+
* messages: modelMessages,
|
|
114
|
+
* });
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare function convertToModelMessages(uiMessages: UIMessage[]): ModelMessage[];
|
|
118
|
+
/**
|
|
119
|
+
* Convert ModelMessage[] to UIMessage[] for frontend rendering.
|
|
120
|
+
*
|
|
121
|
+
* Groups assistant messages with their tool results into single UIMessages
|
|
122
|
+
* with structured parts.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* import { convertToUIMessages } from '@a3s-lab/code';
|
|
127
|
+
*
|
|
128
|
+
* const uiMessages = convertToUIMessages(response.messages);
|
|
129
|
+
* // Render uiMessages in your chat UI
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export declare function convertToUIMessages(modelMessages: ModelMessage[]): UIMessage[];
|
|
133
|
+
/**
|
|
134
|
+
* Convert A3S Message to ModelMessage.
|
|
135
|
+
*/
|
|
136
|
+
export declare function a3sMessageToModel(msg: Message): ModelMessage;
|
|
137
|
+
/**
|
|
138
|
+
* Convert ModelMessage to A3S Message.
|
|
139
|
+
*/
|
|
140
|
+
export declare function modelMessageToA3s(msg: ModelMessage): Message;
|
|
141
|
+
/**
|
|
142
|
+
* Convert A3S Message[] to ModelMessage[].
|
|
143
|
+
*/
|
|
144
|
+
export declare function a3sMessagesToModel(messages: Message[]): ModelMessage[];
|
|
145
|
+
/**
|
|
146
|
+
* Convert ModelMessage[] to A3S Message[].
|
|
147
|
+
*/
|
|
148
|
+
export declare function modelMessagesToA3s(messages: ModelMessage[]): Message[];
|
|
149
|
+
/**
|
|
150
|
+
* Convert A3S Message[] to UIMessage[] (shorthand for a3sMessagesToModel + convertToUIMessages).
|
|
151
|
+
*/
|
|
152
|
+
export declare function a3sMessagesToUI(messages: Message[]): UIMessage[];
|
|
153
|
+
/**
|
|
154
|
+
* Convert UIMessage[] to A3S Message[] (shorthand for convertToModelMessages + modelMessagesToA3s).
|
|
155
|
+
*/
|
|
156
|
+
export declare function uiMessagesToA3s(uiMessages: UIMessage[]): Message[];
|
|
157
|
+
//# sourceMappingURL=message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../ts/message.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAMrD,+BAA+B;AAC/B,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,0CAA0C;AAC1C,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,iBAAiB,CAAC;IACxB,cAAc,EAAE;QACd,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC9B,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,cAAc,CAAC;QAC1C,MAAM,CAAC,EAAE,OAAO,CAAC;KAClB,CAAC;CACH;AAED,wCAAwC;AACxC,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,eAAe,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,oCAAoC;AACpC,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,WAAW,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wCAAwC;AACxC,MAAM,MAAM,aAAa,GACrB,iBAAiB,GACjB,2BAA2B,GAC3B,yBAAyB,GACzB,sBAAsB,CAAC;AAE3B;;;;;GAKG;AACH,MAAM,WAAW,SAAS,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC5D,gCAAgC;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,mBAAmB;IACnB,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;IACtC,+DAA+D;IAC/D,OAAO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