@a3s-lab/code 0.3.1 → 0.4.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/dist/chat.d.ts ADDED
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Chat — Multi-turn Conversation (Convenience Wrapper)
3
+ *
4
+ * A thin wrapper around Session for backward compatibility.
5
+ * For new code, prefer using Session directly:
6
+ *
7
+ * ```typescript
8
+ * const session = await client.createSession({ model: openai('gpt-4o') });
9
+ * const { text } = await session.generateText({ prompt: 'Hello' });
10
+ * const { text: reply } = await session.generateText({ prompt: 'Follow up' });
11
+ * ```
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { createChat, createProvider, tool } from '@a3s-lab/code';
16
+ *
17
+ * const openai = createProvider({ name: 'openai', apiKey: 'sk-xxx' });
18
+ *
19
+ * const chat = createChat({
20
+ * model: openai('gpt-4o'),
21
+ * workspace: '/project',
22
+ * system: 'You are a helpful code assistant',
23
+ * });
24
+ *
25
+ * const { text } = await chat.send('Hello');
26
+ * const { textStream } = chat.stream('Follow up');
27
+ * for await (const chunk of textStream) {
28
+ * process.stdout.write(chunk);
29
+ * }
30
+ * await chat.close();
31
+ * ```
32
+ */
33
+ import type { A3sClientOptions, ContextUsage } from './client.js';
34
+ import type { ModelRef } from './provider.js';
35
+ import type { ToolSet } from './tool.js';
36
+ import type { MessageInput, StepResult, ToolCallEvent } from './session.js';
37
+ /** Options for creating a chat */
38
+ export interface ChatOptions {
39
+ /** Model reference from createProvider() */
40
+ model: ModelRef;
41
+ /** Working directory for tool sandboxing */
42
+ workspace?: string;
43
+ /** System prompt */
44
+ system?: string;
45
+ /** gRPC server connection options */
46
+ server?: A3sClientOptions;
47
+ /** Client-side tool definitions */
48
+ tools?: ToolSet;
49
+ /** Maximum steps per send/stream call. @default 1 */
50
+ maxSteps?: number;
51
+ /** Called when each step completes */
52
+ onStepFinish?: (step: StepResult) => void | Promise<void>;
53
+ /** Called when the model invokes a tool */
54
+ onToolCall?: (event: ToolCallEvent) => void | unknown | Promise<void | unknown>;
55
+ }
56
+ /** Result from chat.send() */
57
+ export interface ChatSendResult {
58
+ text: string;
59
+ usage?: any;
60
+ finishReason: any;
61
+ toolCalls: any[];
62
+ steps: StepResult[];
63
+ }
64
+ /** Result from chat.stream() */
65
+ export interface ChatStreamResult {
66
+ textStream: AsyncIterable<string>;
67
+ fullStream: AsyncIterable<any>;
68
+ toolStream: AsyncIterable<any>;
69
+ text: Promise<string>;
70
+ steps: Promise<StepResult[]>;
71
+ }
72
+ /** Chat instance for multi-turn conversations */
73
+ export interface Chat {
74
+ /** Send a message and get a complete response */
75
+ send(prompt: string): Promise<ChatSendResult>;
76
+ send(messages: MessageInput[]): Promise<ChatSendResult>;
77
+ /** Send a message and stream the response */
78
+ stream(prompt: string): ChatStreamResult;
79
+ stream(messages: MessageInput[]): ChatStreamResult;
80
+ /** Get context usage for this chat session */
81
+ getUsage(): Promise<ContextUsage | undefined>;
82
+ /** Compact the conversation context */
83
+ compact(): Promise<void>;
84
+ /** Clear conversation history */
85
+ clear(): Promise<void>;
86
+ /** Get the underlying session ID */
87
+ readonly sessionId: string;
88
+ /** Close the chat and clean up resources */
89
+ close(): Promise<void>;
90
+ }
91
+ /**
92
+ * Create a multi-turn chat session (convenience wrapper).
93
+ *
94
+ * For new code, prefer `client.createSession()` directly.
95
+ */
96
+ export declare function createChat(options: ChatOptions): Chat;
97
+ //# sourceMappingURL=chat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../ts/chat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;A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AiD;IACjD,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAC9C,IAAI,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAExD,6CAA6C;IAC7C,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAAC;IACzC,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,gBAAgB,CAAC;IAEnD,8CAA8C;IAC9C,QAAQ,IAAI,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAAC;IAE9C,uCAAuC;IACvC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB,iCAAiC;IACjC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB,oCAAoC;IACpC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,4CAA4C;IAC5C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAMD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAuJrD"}
package/dist/chat.js ADDED
@@ -0,0 +1,179 @@
1
+ /**
2
+ * Chat — Multi-turn Conversation (Convenience Wrapper)
3
+ *
4
+ * A thin wrapper around Session for backward compatibility.
5
+ * For new code, prefer using Session directly:
6
+ *
7
+ * ```typescript
8
+ * const session = await client.createSession({ model: openai('gpt-4o') });
9
+ * const { text } = await session.generateText({ prompt: 'Hello' });
10
+ * const { text: reply } = await session.generateText({ prompt: 'Follow up' });
11
+ * ```
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { createChat, createProvider, tool } from '@a3s-lab/code';
16
+ *
17
+ * const openai = createProvider({ name: 'openai', apiKey: 'sk-xxx' });
18
+ *
19
+ * const chat = createChat({
20
+ * model: openai('gpt-4o'),
21
+ * workspace: '/project',
22
+ * system: 'You are a helpful code assistant',
23
+ * });
24
+ *
25
+ * const { text } = await chat.send('Hello');
26
+ * const { textStream } = chat.stream('Follow up');
27
+ * for await (const chunk of textStream) {
28
+ * process.stdout.write(chunk);
29
+ * }
30
+ * await chat.close();
31
+ * ```
32
+ */
33
+ import { A3sClient } from './client.js';
34
+ // ============================================================================
35
+ // Implementation
36
+ // ============================================================================
37
+ /**
38
+ * Create a multi-turn chat session (convenience wrapper).
39
+ *
40
+ * For new code, prefer `client.createSession()` directly.
41
+ */
42
+ export function createChat(options) {
43
+ const client = new A3sClient(options.server);
44
+ let session = null;
45
+ let initPromise = null;
46
+ async function ensureSession() {
47
+ if (session)
48
+ return session;
49
+ if (!initPromise) {
50
+ initPromise = (async () => {
51
+ session = await client.createSession({
52
+ model: options.model,
53
+ workspace: options.workspace,
54
+ system: options.system,
55
+ });
56
+ })();
57
+ }
58
+ await initPromise;
59
+ return session;
60
+ }
61
+ function toMessages(input) {
62
+ if (typeof input === 'string') {
63
+ return [{ role: 'user', content: input }];
64
+ }
65
+ return input;
66
+ }
67
+ const chat = {
68
+ get sessionId() {
69
+ return session?.id ?? '';
70
+ },
71
+ async send(input) {
72
+ const s = await ensureSession();
73
+ return s.generateText({
74
+ messages: toMessages(input),
75
+ tools: options.tools,
76
+ maxSteps: options.maxSteps,
77
+ onStepFinish: options.onStepFinish,
78
+ onToolCall: options.onToolCall,
79
+ });
80
+ },
81
+ stream(input) {
82
+ // We need the session to exist before streaming
83
+ // Use a deferred pattern to handle the async init
84
+ let resolveText;
85
+ let rejectAll;
86
+ let resolveSteps;
87
+ const textPromise = new Promise((res, rej) => {
88
+ resolveText = res;
89
+ rejectAll = rej;
90
+ });
91
+ const stepsPromise = new Promise((res) => {
92
+ resolveSteps = res;
93
+ });
94
+ const chunks = [];
95
+ let done = false;
96
+ const waiters = [];
97
+ function notify() {
98
+ for (const w of waiters.splice(0))
99
+ w();
100
+ }
101
+ const produce = (async () => {
102
+ try {
103
+ const s = await ensureSession();
104
+ const result = s.streamText({
105
+ messages: toMessages(input),
106
+ tools: options.tools,
107
+ maxSteps: options.maxSteps,
108
+ onStepFinish: options.onStepFinish,
109
+ onToolCall: options.onToolCall,
110
+ });
111
+ for await (const chunk of result.fullStream) {
112
+ chunks.push(chunk);
113
+ notify();
114
+ }
115
+ resolveText(await result.text);
116
+ resolveSteps(await result.steps);
117
+ }
118
+ catch (err) {
119
+ rejectAll(err);
120
+ }
121
+ finally {
122
+ done = true;
123
+ notify();
124
+ }
125
+ })();
126
+ produce.catch(() => { });
127
+ function iterate(transform) {
128
+ return {
129
+ [Symbol.asyncIterator]() {
130
+ let i = 0;
131
+ return {
132
+ async next() {
133
+ while (true) {
134
+ if (i < chunks.length) {
135
+ const v = transform(chunks[i++]);
136
+ if (v !== null)
137
+ return { value: v, done: false };
138
+ continue;
139
+ }
140
+ if (done) {
141
+ return { value: undefined, done: true };
142
+ }
143
+ await new Promise((r) => waiters.push(r));
144
+ }
145
+ },
146
+ };
147
+ },
148
+ };
149
+ }
150
+ return {
151
+ textStream: iterate((c) => (c.content ? c.content : null)),
152
+ fullStream: iterate((c) => c),
153
+ toolStream: iterate((c) => (c.toolCall ? c.toolCall : null)),
154
+ text: textPromise,
155
+ steps: stepsPromise,
156
+ };
157
+ },
158
+ async getUsage() {
159
+ const s = await ensureSession();
160
+ return s.getContextUsage();
161
+ },
162
+ async compact() {
163
+ const s = await ensureSession();
164
+ await s.compactContext();
165
+ },
166
+ async clear() {
167
+ const s = await ensureSession();
168
+ await s.clearContext();
169
+ },
170
+ async close() {
171
+ if (session) {
172
+ await session.close();
173
+ }
174
+ client.close();
175
+ },
176
+ };
177
+ return chat;
178
+ }
179
+ //# sourceMappingURL=chat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat.js","sourceRoot":"","sources":["../ts/chat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AA+ExC,+EAA+E;AAC/E,iBAAiB;AACjB,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C,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBAC1D,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;gBAC7B,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBAC5D,IAAI,EAAE,WAAW;gBACjB,KAAK,EAAE,YAAY;aACpB,CAAC;QACJ,CAAC;QAED,KAAK,CAAC,QAAQ;YACZ,MAAM,CAAC,GAAG,MAAM,aAAa,EAAE,CAAC;YAChC,OAAO,CAAC,CAAC,eAAe,EAAE,CAAC;QAC7B,CAAC;QAED,KAAK,CAAC,OAAO;YACX,MAAM,CAAC,GAAG,MAAM,aAAa,EAAE,CAAC;YAChC,MAAM,CAAC,CAAC,cAAc,EAAE,CAAC;QAC3B,CAAC;QAED,KAAK,CAAC,KAAK;YACT,MAAM,CAAC,GAAG,MAAM,aAAa,EAAE,CAAC;YAChC,MAAM,CAAC,CAAC,YAAY,EAAE,CAAC;QACzB,CAAC;QAED,KAAK,CAAC,KAAK;YACT,IAAI,OAAO,EAAE,CAAC;gBACZ,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;YACxB,CAAC;YACD,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,CAAC;KACF,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC"}
package/dist/client.d.ts CHANGED
@@ -4,6 +4,8 @@
4
4
  * Full implementation of the CodeAgentService interface.
5
5
  */
6
6
  import { type OpenAIMessage, type OpenAIChatCompletion, type OpenAIChatCompletionChunk } from './openai-compat.js';
7
+ import { Session as CodeSession } from './session.js';
8
+ import type { SessionCreateOptions } from './session.js';
7
9
  export type HealthStatus = 'STATUS_UNKNOWN' | 'STATUS_HEALTHY' | 'STATUS_DEGRADED' | 'STATUS_UNHEALTHY';
8
10
  export type SessionState = 'SESSION_STATE_UNKNOWN' | 'SESSION_STATE_ACTIVE' | 'SESSION_STATE_PAUSED' | 'SESSION_STATE_COMPLETED' | 'SESSION_STATE_ERROR';
9
11
  export type MessageRole = 'user' | 'assistant' | 'system' | 'tool';
@@ -114,7 +116,7 @@ export interface ContextUsage {
114
116
  completionTokens: number;
115
117
  messageCount: number;
116
118
  }
117
- export interface Session {
119
+ export interface SessionInfo {
118
120
  sessionId: string;
119
121
  config?: SessionConfig;
120
122
  state: SessionState;
@@ -122,21 +124,23 @@ export interface Session {
122
124
  createdAt: number;
123
125
  updatedAt: number;
124
126
  }
127
+ /** @deprecated Use SessionInfo instead */
128
+ export type Session = SessionInfo;
125
129
  export interface CreateSessionResponse {
126
130
  sessionId: string;
127
- session?: Session;
131
+ session?: SessionInfo;
128
132
  }
129
133
  export interface DestroySessionResponse {
130
134
  success: boolean;
131
135
  }
132
136
  export interface ListSessionsResponse {
133
- sessions: Session[];
137
+ sessions: SessionInfo[];
134
138
  }
135
139
  export interface GetSessionResponse {
136
- session?: Session;
140
+ session?: SessionInfo;
137
141
  }
138
142
  export interface ConfigureSessionResponse {
139
- session?: Session;
143
+ session?: SessionInfo;
140
144
  }
141
145
  export interface Message {
142
146
  role: MessageRole;
@@ -221,29 +225,22 @@ export interface GenerateStructuredChunk {
221
225
  export interface Skill {
222
226
  name: string;
223
227
  description: string;
224
- tools: string[];
228
+ allowedTools?: string;
229
+ disableModelInvocation: boolean;
230
+ content: string;
225
231
  metadata: Record<string, string>;
226
232
  }
227
233
  export interface LoadSkillResponse {
228
234
  success: boolean;
229
- toolNames: string[];
230
235
  }
231
236
  export interface UnloadSkillResponse {
232
237
  success: boolean;
233
- removedTools: string[];
234
238
  }
235
239
  export interface ListSkillsResponse {
236
240
  skills: Skill[];
237
241
  }
238
- export interface ClaudeCodeSkill {
239
- name: string;
240
- description: string;
241
- allowedTools?: string;
242
- disableModelInvocation: boolean;
243
- content: string;
244
- }
245
- export interface GetClaudeCodeSkillsResponse {
246
- skills: ClaudeCodeSkill[];
242
+ export interface GetSkillResponse {
243
+ skills: Skill[];
247
244
  }
248
245
  export interface GetContextUsageResponse {
249
246
  usage?: ContextUsage;
@@ -693,6 +690,118 @@ export interface ParseCronScheduleResponse {
693
690
  description: string;
694
691
  error: string;
695
692
  }
693
+ export interface ToolStats {
694
+ toolName: string;
695
+ callCount: number;
696
+ successCount: number;
697
+ failureCount: number;
698
+ totalDurationMs: number;
699
+ avgDurationMs: number;
700
+ minDurationMs: number;
701
+ maxDurationMs: number;
702
+ }
703
+ export interface GetToolMetricsResponse {
704
+ tools: ToolStats[];
705
+ totalCalls: number;
706
+ totalDurationMs: number;
707
+ }
708
+ export interface ModelCostBreakdown {
709
+ model: string;
710
+ costUsd: number;
711
+ promptTokens: number;
712
+ completionTokens: number;
713
+ callCount: number;
714
+ }
715
+ export interface DayCostBreakdown {
716
+ date: string;
717
+ costUsd: number;
718
+ callCount: number;
719
+ }
720
+ export interface GetCostSummaryResponse {
721
+ totalCostUsd: number;
722
+ totalPromptTokens: number;
723
+ totalCompletionTokens: number;
724
+ totalTokens: number;
725
+ callCount: number;
726
+ byModel: ModelCostBreakdown[];
727
+ byDay: DayCostBreakdown[];
728
+ }
729
+ export type AgenticStrategyType = 'AGENTIC_STRATEGY_AUTO' | 'AGENTIC_STRATEGY_DIRECT' | 'AGENTIC_STRATEGY_PLANNED' | 'AGENTIC_STRATEGY_ITERATIVE' | 'AGENTIC_STRATEGY_PARALLEL';
730
+ export interface AgenticStep {
731
+ stepIndex: number;
732
+ text: string;
733
+ toolCalls: ToolCall[];
734
+ toolResults: ToolResult[];
735
+ usage?: Usage;
736
+ finishReason?: string;
737
+ }
738
+ export interface AgenticGenerateResponse {
739
+ sessionId: string;
740
+ text: string;
741
+ steps: AgenticStep[];
742
+ toolCalls: ToolCall[];
743
+ usage?: Usage;
744
+ finishReason: string;
745
+ plan?: ExecutionPlan;
746
+ }
747
+ export interface AgenticGenerateEvent {
748
+ type: string;
749
+ sessionId: string;
750
+ content?: string;
751
+ toolCall?: ToolCall;
752
+ toolResult?: ToolResult;
753
+ toolCallId?: string;
754
+ stepIndex?: number;
755
+ stepText?: string;
756
+ plan?: ExecutionPlan;
757
+ confidence?: number;
758
+ shouldRetry?: boolean;
759
+ insight?: string;
760
+ confirmationId?: string;
761
+ toolName?: string;
762
+ toolArgs?: string;
763
+ timeoutMs?: number;
764
+ approved?: boolean;
765
+ agentName?: string;
766
+ agentTask?: string;
767
+ agentSessionId?: string;
768
+ agentResult?: string;
769
+ beforeTokens?: number;
770
+ afterTokens?: number;
771
+ externalTask?: ExternalTask;
772
+ errorMessage?: string;
773
+ recoverable?: boolean;
774
+ finishReason?: string;
775
+ usage?: Usage;
776
+ }
777
+ export interface DelegateResponse {
778
+ sessionId: string;
779
+ agentSessionId: string;
780
+ text: string;
781
+ steps: AgenticStep[];
782
+ toolCalls: ToolCall[];
783
+ usage?: Usage;
784
+ finishReason: string;
785
+ }
786
+ export interface ProtoLaneStats {
787
+ pending: number;
788
+ active: number;
789
+ external: number;
790
+ completed: number;
791
+ failed: number;
792
+ }
793
+ export interface GetQueueStatsResponse {
794
+ control?: ProtoLaneStats;
795
+ query?: ProtoLaneStats;
796
+ execute?: ProtoLaneStats;
797
+ generate?: ProtoLaneStats;
798
+ deadLetters: number;
799
+ }
800
+ export interface LoadSkillsFromDirResponse {
801
+ success: boolean;
802
+ loadedSkills: string[];
803
+ errors: string[];
804
+ }
696
805
  export interface A3sClientOptions {
697
806
  /** gRPC server address (default: localhost:4088) */
698
807
  address?: string;
@@ -759,12 +868,28 @@ export declare class A3sClient {
759
868
  /**
760
869
  * Create a new session.
761
870
  *
762
- * @param config - Session configuration. The `workspace` field controls
763
- * per-session tool sandboxing: each session gets its own ToolContext
764
- * scoped to the given workspace directory. If omitted or empty, the
765
- * server falls back to its default workspace.
766
- * @param sessionId - Optional session ID. If omitted, the server generates one.
767
- * @param initialContext - Optional messages to seed the session context.
871
+ * Accepts either high-level options (with `model` from createProvider) or
872
+ * low-level SessionConfig. Returns a Session object with send(),
873
+ * sendStream(), generateText(), streamText(), etc.
874
+ *
875
+ * @example
876
+ * ```typescript
877
+ * // High-level (recommended)
878
+ * const openai = createProvider({ name: 'openai', apiKey: 'sk-xxx' });
879
+ * await using session = await client.createSession({
880
+ * model: openai('gpt-4o'),
881
+ * workspace: '/project',
882
+ * system: 'You are a helpful assistant',
883
+ * confirmation: { requireConfirmation: ['Bash', 'Write'] },
884
+ * lanes: { execute: { mode: 'external', timeout: 120_000 } },
885
+ * });
886
+ * const { text } = await session.send('Refactor the auth module');
887
+ * ```
888
+ */
889
+ createSession(options: SessionCreateOptions): Promise<CodeSession>;
890
+ /**
891
+ * Create a new session (low-level).
892
+ * @deprecated Use the high-level overload with `model` instead.
768
893
  */
769
894
  createSession(config?: SessionConfig, sessionId?: string, initialContext?: Message[]): Promise<CreateSessionResponse>;
770
895
  /**
@@ -860,9 +985,9 @@ export declare class A3sClient {
860
985
  */
861
986
  listSkills(sessionId?: string): Promise<ListSkillsResponse>;
862
987
  /**
863
- * Get Claude Code skills
988
+ * Get skills by name or all skills
864
989
  */
865
- getClaudeCodeSkills(name?: string): Promise<GetClaudeCodeSkillsResponse>;
990
+ getSkill(name?: string): Promise<GetSkillResponse>;
866
991
  /**
867
992
  * Get context usage for a session
868
993
  */
@@ -1116,6 +1241,55 @@ export declare class A3sClient {
1116
1241
  * @param input Natural language or cron expression
1117
1242
  */
1118
1243
  parseCronSchedule(input: string): Promise<ParseCronScheduleResponse>;
1244
+ getToolMetrics(sessionId?: string, toolName?: string): Promise<GetToolMetricsResponse>;
1245
+ getCostSummary(options?: {
1246
+ sessionId?: string;
1247
+ model?: string;
1248
+ startDate?: string;
1249
+ endDate?: string;
1250
+ }): Promise<GetCostSummaryResponse>;
1251
+ /**
1252
+ * Run the server-side AgenticLoop (non-streaming).
1253
+ * The server executes the full loop: generate → tool call → execute → reflect → repeat.
1254
+ */
1255
+ agenticGenerate(sessionId: string, prompt: string, options?: {
1256
+ strategy?: string;
1257
+ maxSteps?: number;
1258
+ reflection?: boolean;
1259
+ planning?: boolean;
1260
+ }): Promise<AgenticGenerateResponse>;
1261
+ /**
1262
+ * Stream the server-side AgenticLoop.
1263
+ * Returns a stream of AgenticGenerateEvent for real-time UI updates.
1264
+ */
1265
+ streamAgenticGenerate(sessionId: string, prompt: string, options?: {
1266
+ strategy?: string;
1267
+ maxSteps?: number;
1268
+ reflection?: boolean;
1269
+ planning?: boolean;
1270
+ }): AsyncIterable<AgenticGenerateEvent>;
1271
+ /**
1272
+ * Delegate a task to a built-in or custom subagent (non-streaming).
1273
+ */
1274
+ delegateToAgent(sessionId: string, agentName: string, task: string, options?: {
1275
+ maxSteps?: number;
1276
+ allowedTools?: string[];
1277
+ }): Promise<DelegateResponse>;
1278
+ /**
1279
+ * Delegate a task to a subagent with streaming events.
1280
+ */
1281
+ streamDelegateToAgent(sessionId: string, agentName: string, task: string, options?: {
1282
+ maxSteps?: number;
1283
+ allowedTools?: string[];
1284
+ }): AsyncIterable<AgenticGenerateEvent>;
1285
+ /**
1286
+ * Get per-lane queue statistics for a session.
1287
+ */
1288
+ getQueueStats(sessionId: string): Promise<GetQueueStatsResponse>;
1289
+ /**
1290
+ * Load all skills from a directory.
1291
+ */
1292
+ loadSkillsFromDir(sessionId: string, directory: string, recursive?: boolean): Promise<LoadSkillsFromDirResponse>;
1119
1293
  private streamToAsyncIterable;
1120
1294
  }
1121
1295
  //# sourceMappingURL=client.d.ts.map