@robota-sdk/agent-sdk 3.0.0-beta.34 → 3.0.0-beta.36

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @robota-sdk/agent-sdk
2
2
 
3
- Programmatic SDK for building AI agents with Robota. Provides a single `query()` entry point along with session management, built-in tools, permissions, hooks, streaming, and context loading.
3
+ Programmatic SDK for building AI agents with Robota. Provides `InteractiveSession` as the central client-facing API, `query()` for one-shot use, session management, built-in tools, permissions, hooks, streaming, and context loading.
4
4
 
5
5
  This is the **assembly layer** of the Robota ecosystem — it composes lower-level packages (`agent-core`, `agent-tools`, `agent-sessions`, `agent-provider-anthropic`) into a cohesive SDK.
6
6
 
@@ -33,7 +33,10 @@ const response = await query('Analyze the code', {
33
33
 
34
34
  ## Features
35
35
 
36
- - **query()** — Single entry point for AI agent interactions with streaming support
36
+ - **InteractiveSession** — Event-driven session wrapper (composition over Session). Central client-facing API for CLI, web, API server, or any other client
37
+ - **SystemCommandExecutor + ISystemCommand** — SDK-level command execution. Built-in commands: `help`, `clear`, `compact`, `mode`, `model`, `language`, `cost`, `context`, `permissions`, `reset`
38
+ - **CommandRegistry, BuiltinCommandSource, SkillCommandSource** — Slash command registry and discovery (owned by SDK; agent-cli re-exports `CommandRegistry` from here)
39
+ - **query()** — Single entry point for one-shot AI agent interactions with streaming support
37
40
  - **createSession()** — Assembly factory: wires tools, provider, config, and context into a Session
38
41
  - **Built-in Tools** — Bash, Read, Write, Edit, Glob, Grep (re-exported from `@robota-sdk/agent-tools`)
39
42
  - **Agent Tool** — Sub-agent session creation for multi-agent workflows
@@ -49,16 +52,167 @@ const response = await query('Analyze the code', {
49
52
 
50
53
  ```
51
54
  agent-sdk (assembly layer)
52
- -> agent-sessions (Session, SessionStore)
53
- -> agent-tools (tool infrastructure + 8 built-in tools)
54
- -> agent-provider-anthropic (Anthropic LLM provider)
55
- -> agent-core (Robota engine, providers, permissions, hooks)
55
+ ├── InteractiveSession ← central client-facing API (event-driven)
56
+ └── Session ← generic session (agent-sessions)
57
+ ├── SystemCommandExecutor ← SDK-level command execution
58
+ ├── CommandRegistry / BuiltinCommandSource / SkillCommandSource
59
+ ├── query() ← one-shot entry point
60
+ ├── createSession() ← assembly factory
61
+ └── deps:
62
+ agent-sessions (Session, SessionStore)
63
+ agent-tools (tool infrastructure + 8 built-in tools)
64
+ agent-provider-anthropic (Anthropic LLM provider)
65
+ agent-core (Robota engine, providers, permissions, hooks)
66
+
67
+ agent-cli (TUI layer — bridges InteractiveSession events to React/Ink state)
68
+ → agent-sdk
56
69
  ```
57
70
 
58
- `agent-sdk` assembles existing packages it does not re-implement functionality that belongs in lower layers.
71
+ The SDK is **pure TypeScript with no React dependency**. The CLI is a thin TUI-only layer that consumes `InteractiveSession` events and maps them to React state. Any other client (web app, API server, worker) can do the same.
59
72
 
60
73
  ## API
61
74
 
75
+ ### InteractiveSession — Central Client-Facing API
76
+
77
+ `InteractiveSession` wraps `Session` (composition over inheritance) to provide event-driven interaction for any client. It manages streaming text accumulation, tool execution state tracking, prompt queuing, abort orchestration, and message history. Logic that was previously embedded in CLI React hooks now lives here.
78
+
79
+ ```typescript
80
+ import { InteractiveSession } from '@robota-sdk/agent-sdk';
81
+ import type { IInteractiveSessionOptions } from '@robota-sdk/agent-sdk';
82
+
83
+ const session = new InteractiveSession({
84
+ config,
85
+ context,
86
+ projectInfo,
87
+ sessionStore,
88
+ permissionMode: 'default',
89
+ maxTurns: 10,
90
+ cwd: process.cwd(),
91
+ permissionHandler: async (toolName, toolArgs) => ({ allowed: true }),
92
+ });
93
+
94
+ // Subscribe to events
95
+ session.on('text_delta', (delta: string) => {
96
+ process.stdout.write(delta); // streaming text chunk
97
+ });
98
+ session.on('tool_start', (state) => {
99
+ console.log(`Running: ${state.toolName}`);
100
+ });
101
+ session.on('tool_end', (state) => {
102
+ console.log(`Done: ${state.toolName} — ${state.result}`);
103
+ });
104
+ session.on('thinking', (isThinking: boolean) => {
105
+ // show/hide spinner
106
+ });
107
+ session.on('complete', (result) => {
108
+ console.log(result.response);
109
+ });
110
+ session.on('error', (error: Error) => {
111
+ console.error(error);
112
+ });
113
+ session.on('context_update', (state) => {
114
+ // token usage updated
115
+ });
116
+ session.on('interrupted', (result) => {
117
+ // abort completed
118
+ });
119
+
120
+ // Submit a prompt (queues if already executing, max 1 queued)
121
+ await session.submit('Explain this code');
122
+
123
+ // Submit with display override (shown in UI) and raw input (for hook matching)
124
+ await session.submit(fullPrompt, '/audit', '/rulebased-harness:audit');
125
+
126
+ // Abort current execution and clear queue
127
+ session.abort();
128
+
129
+ // Cancel queued prompt without aborting current execution
130
+ session.cancelQueue();
131
+
132
+ // State queries
133
+ session.isExecuting(); // boolean
134
+ session.getPendingPrompt(); // string | null
135
+ session.getMessages(); // TUniversalMessage[]
136
+ session.getContextState(); // IContextWindowState
137
+ session.getStreamingText(); // string (accumulated so far)
138
+ session.getActiveTools(); // IToolState[]
139
+
140
+ // Access underlying Session for advanced use
141
+ session.getSession(); // Session
142
+ ```
143
+
144
+ ### SystemCommandExecutor — SDK-Level Commands
145
+
146
+ `SystemCommandExecutor` executes named system commands against an `InteractiveSession`. Commands are pure TypeScript — no React, no TUI dependency. The CLI wraps them as slash commands with UI chrome.
147
+
148
+ ```typescript
149
+ import { SystemCommandExecutor, createSystemCommands } from '@robota-sdk/agent-sdk';
150
+ import type { ICommandResult } from '@robota-sdk/agent-sdk';
151
+
152
+ const executor = new SystemCommandExecutor(); // loads built-in commands by default
153
+
154
+ // Execute a command
155
+ const result: ICommandResult | null = await executor.execute('context', session, '');
156
+ if (result) {
157
+ console.log(result.message); // "Context: 12,345 / 200,000 tokens (6%)"
158
+ console.log(result.data); // { usedTokens, maxTokens, percentage }
159
+ }
160
+
161
+ // Register a custom command
162
+ executor.register({
163
+ name: 'status',
164
+ description: 'Show agent status',
165
+ execute: (session, args) => ({ message: 'OK', success: true }),
166
+ });
167
+
168
+ // List all commands
169
+ executor.listCommands(); // ISystemCommand[]
170
+ executor.hasCommand('mode'); // boolean
171
+ ```
172
+
173
+ Built-in commands:
174
+
175
+ | Command | Description |
176
+ | ------------- | ------------------------------------------------------- |
177
+ | `help` | Show available commands |
178
+ | `clear` | Clear conversation history |
179
+ | `compact` | Compress context window (optional focus instructions) |
180
+ | `mode [m]` | Show or change permission mode |
181
+ | `model <id>` | Change AI model |
182
+ | `language` | Set response language (ko, en, ja, zh) |
183
+ | `cost` | Show session info (session ID, message count) |
184
+ | `context` | Context window token usage |
185
+ | `permissions` | Show current permission mode and session-approved tools |
186
+ | `reset` | Delete settings (caller handles file I/O and exit) |
187
+
188
+ ### CommandRegistry, BuiltinCommandSource, SkillCommandSource
189
+
190
+ These classes provide slash command discovery and aggregation for clients that expose a command palette or autocomplete UI.
191
+
192
+ ```typescript
193
+ import { CommandRegistry, BuiltinCommandSource, SkillCommandSource } from '@robota-sdk/agent-sdk';
194
+
195
+ const registry = new CommandRegistry();
196
+ registry.addSource(new BuiltinCommandSource());
197
+ registry.addSource(new SkillCommandSource(process.cwd()));
198
+
199
+ // Get all commands (returns ISlashCommand[])
200
+ const commands = registry.getCommands();
201
+
202
+ // Filter by prefix (for autocomplete)
203
+ const filtered = registry.getCommands('mod'); // matches "mode", "model"
204
+
205
+ // Resolve short plugin name to fully qualified form
206
+ registry.resolveQualifiedName('audit'); // "my-plugin:audit"
207
+ ```
208
+
209
+ `SkillCommandSource` discovers skills from (highest priority first):
210
+
211
+ - `<cwd>/.claude/skills/*/SKILL.md`
212
+ - `<cwd>/.claude/commands/*.md` (Claude Code compatible)
213
+ - `~/.robota/skills/*/SKILL.md`
214
+ - `<cwd>/.agents/skills/*/SKILL.md`
215
+
62
216
  ### query()
63
217
 
64
218
  ```typescript