@robota-sdk/agent-sdk 3.0.0-beta.5 → 3.0.0-beta.51
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 +335 -21
- package/dist/node/index.cjs +2675 -265
- package/dist/node/index.d.cts +1011 -226
- package/dist/node/index.d.ts +1011 -226
- package/dist/node/index.js +2691 -273
- package/package.json +12 -5
package/README.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# @robota-sdk/agent-sdk
|
|
2
2
|
|
|
3
|
-
Programmatic SDK for building AI agents with Robota. Provides
|
|
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
|
-
This is the **assembly layer** of the Robota ecosystem
|
|
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
|
+
|
|
7
|
+
**Version**: 3.0.0-beta.33
|
|
6
8
|
|
|
7
9
|
## Installation
|
|
8
10
|
|
|
@@ -31,39 +33,351 @@ const response = await query('Analyze the code', {
|
|
|
31
33
|
|
|
32
34
|
## Features
|
|
33
35
|
|
|
34
|
-
- **
|
|
35
|
-
- **
|
|
36
|
-
- **
|
|
37
|
-
- **
|
|
38
|
-
- **
|
|
39
|
-
- **
|
|
40
|
-
- **
|
|
41
|
-
- **
|
|
42
|
-
- **
|
|
43
|
-
- **
|
|
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
|
|
40
|
+
- **createSession()** — Assembly factory: wires tools, provider, config, and context into a Session
|
|
41
|
+
- **Built-in Tools** — Bash, Read, Write, Edit, Glob, Grep (re-exported from `@robota-sdk/agent-tools`)
|
|
42
|
+
- **Agent Tool** — Sub-agent session creation for multi-agent workflows
|
|
43
|
+
- **Permissions** — 3-step evaluation (deny list, allow list, mode policy) with four modes: `plan`, `default`, `acceptEdits`, `bypassPermissions`
|
|
44
|
+
- **Hooks** — `PreToolUse`, `PostToolUse`, `PreCompact`, `PostCompact`, `SessionStart`, `UserPromptSubmit`, `Stop` events with shell command execution
|
|
45
|
+
- **Streaming** — Real-time text delta callbacks via `onTextDelta`
|
|
46
|
+
- **Context Loading** — AGENTS.md / CLAUDE.md walk-up discovery and system prompt assembly
|
|
47
|
+
- **Config Loading** — 6-layer merge (CLI flags, local, project, Claude Code compat, user global, user global Claude Code compat) with `$ENV:VAR` substitution
|
|
48
|
+
- **Context Window Management** — Token tracking, auto-compaction at ~83.5%, manual `session.compact()`
|
|
49
|
+
- **Bundle Plugin System** — Install and manage reusable extensions packaged as bundle plugins
|
|
44
50
|
|
|
45
51
|
## Architecture
|
|
46
52
|
|
|
47
53
|
```
|
|
48
54
|
agent-sdk (assembly layer)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
|
52
69
|
```
|
|
53
70
|
|
|
54
|
-
|
|
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.
|
|
72
|
+
|
|
73
|
+
## API
|
|
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, // SessionStore instance for persistence
|
|
88
|
+
resumeSessionId, // Session ID to restore (optional)
|
|
89
|
+
forkSession, // Session ID to fork from (optional)
|
|
90
|
+
permissionMode: 'default',
|
|
91
|
+
maxTurns: 10,
|
|
92
|
+
cwd: process.cwd(),
|
|
93
|
+
permissionHandler: async (toolName, toolArgs) => ({ allowed: true }),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Subscribe to events
|
|
97
|
+
session.on('text_delta', (delta: string) => {
|
|
98
|
+
process.stdout.write(delta); // streaming text chunk
|
|
99
|
+
});
|
|
100
|
+
session.on('tool_start', (state) => {
|
|
101
|
+
console.log(`Running: ${state.toolName}`);
|
|
102
|
+
});
|
|
103
|
+
session.on('tool_end', (state) => {
|
|
104
|
+
console.log(`Done: ${state.toolName} — ${state.result}`);
|
|
105
|
+
});
|
|
106
|
+
session.on('thinking', (isThinking: boolean) => {
|
|
107
|
+
// show/hide spinner
|
|
108
|
+
});
|
|
109
|
+
session.on('complete', (result) => {
|
|
110
|
+
console.log(result.response);
|
|
111
|
+
});
|
|
112
|
+
session.on('error', (error: Error) => {
|
|
113
|
+
console.error(error);
|
|
114
|
+
});
|
|
115
|
+
session.on('context_update', (state) => {
|
|
116
|
+
// token usage updated
|
|
117
|
+
});
|
|
118
|
+
session.on('interrupted', (result) => {
|
|
119
|
+
// abort completed
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// Submit a prompt (queues if already executing, max 1 queued)
|
|
123
|
+
await session.submit('Explain this code');
|
|
124
|
+
|
|
125
|
+
// Submit with display override (shown in UI) and raw input (for hook matching)
|
|
126
|
+
await session.submit(fullPrompt, '/audit', '/rulebased-harness:audit');
|
|
127
|
+
|
|
128
|
+
// Abort current execution and clear queue
|
|
129
|
+
session.abort();
|
|
130
|
+
|
|
131
|
+
// Cancel queued prompt without aborting current execution
|
|
132
|
+
session.cancelQueue();
|
|
133
|
+
|
|
134
|
+
// Execute system commands
|
|
135
|
+
const result = await session.executeCommand('context', '');
|
|
136
|
+
// result.message, result.success, result.data
|
|
137
|
+
|
|
138
|
+
// List all registered system commands
|
|
139
|
+
session.listCommands(); // Array<{ name, description }>
|
|
140
|
+
|
|
141
|
+
// State queries
|
|
142
|
+
session.isExecuting(); // boolean
|
|
143
|
+
session.getPendingPrompt(); // string | null
|
|
144
|
+
session.getMessages(); // TUniversalMessage[]
|
|
145
|
+
session.getContextState(); // IContextWindowState
|
|
146
|
+
session.getStreamingText(); // string (accumulated so far)
|
|
147
|
+
session.getActiveTools(); // IToolState[]
|
|
148
|
+
|
|
149
|
+
// Session naming
|
|
150
|
+
session.getName(); // string | undefined
|
|
151
|
+
session.setName('my-task'); // sets the session name
|
|
152
|
+
|
|
153
|
+
// Access underlying Session for advanced use
|
|
154
|
+
session.getSession(); // Session
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### SystemCommandExecutor — SDK-Level Commands
|
|
158
|
+
|
|
159
|
+
`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.
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
import { SystemCommandExecutor, createSystemCommands } from '@robota-sdk/agent-sdk';
|
|
163
|
+
import type { ICommandResult } from '@robota-sdk/agent-sdk';
|
|
164
|
+
|
|
165
|
+
const executor = new SystemCommandExecutor(); // loads built-in commands by default
|
|
166
|
+
|
|
167
|
+
// Execute a command
|
|
168
|
+
const result: ICommandResult | null = await executor.execute('context', session, '');
|
|
169
|
+
if (result) {
|
|
170
|
+
console.log(result.message); // "Context: 12,345 / 200,000 tokens (6%)"
|
|
171
|
+
console.log(result.data); // { usedTokens, maxTokens, percentage }
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Register a custom command
|
|
175
|
+
executor.register({
|
|
176
|
+
name: 'status',
|
|
177
|
+
description: 'Show agent status',
|
|
178
|
+
execute: (session, args) => ({ message: 'OK', success: true }),
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
// List all commands
|
|
182
|
+
executor.listCommands(); // ISystemCommand[]
|
|
183
|
+
executor.hasCommand('mode'); // boolean
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Built-in commands:
|
|
187
|
+
|
|
188
|
+
| Command | Description |
|
|
189
|
+
| ------------- | ------------------------------------------------------- |
|
|
190
|
+
| `help` | Show available commands |
|
|
191
|
+
| `clear` | Clear conversation history |
|
|
192
|
+
| `compact` | Compress context window (optional focus instructions) |
|
|
193
|
+
| `mode [m]` | Show or change permission mode |
|
|
194
|
+
| `model <id>` | Change AI model |
|
|
195
|
+
| `language` | Set response language (ko, en, ja, zh) |
|
|
196
|
+
| `cost` | Show session info (session ID, message count) |
|
|
197
|
+
| `context` | Context window token usage |
|
|
198
|
+
| `permissions` | Show current permission mode and session-approved tools |
|
|
199
|
+
| `reset` | Delete settings (caller handles file I/O and exit) |
|
|
200
|
+
|
|
201
|
+
### CommandRegistry, BuiltinCommandSource, SkillCommandSource
|
|
202
|
+
|
|
203
|
+
These classes provide slash command discovery and aggregation for clients that expose a command palette or autocomplete UI.
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
import { CommandRegistry, BuiltinCommandSource, SkillCommandSource } from '@robota-sdk/agent-sdk';
|
|
207
|
+
|
|
208
|
+
const registry = new CommandRegistry();
|
|
209
|
+
registry.addSource(new BuiltinCommandSource());
|
|
210
|
+
registry.addSource(new SkillCommandSource(process.cwd()));
|
|
211
|
+
|
|
212
|
+
// Get all commands (returns ICommand[])
|
|
213
|
+
const commands = registry.getCommands();
|
|
214
|
+
|
|
215
|
+
// Filter by prefix (for autocomplete)
|
|
216
|
+
const filtered = registry.getCommands('mod'); // matches "mode", "model"
|
|
217
|
+
|
|
218
|
+
// Resolve short plugin name to fully qualified form
|
|
219
|
+
registry.resolveQualifiedName('audit'); // "my-plugin:audit"
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
`SkillCommandSource` discovers skills from (highest priority first):
|
|
223
|
+
|
|
224
|
+
- `<cwd>/.claude/skills/*/SKILL.md`
|
|
225
|
+
- `<cwd>/.claude/commands/*.md` (Claude Code compatible)
|
|
226
|
+
- `~/.robota/skills/*/SKILL.md`
|
|
227
|
+
- `<cwd>/.agents/skills/*/SKILL.md`
|
|
228
|
+
|
|
229
|
+
### query()
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
import { query } from '@robota-sdk/agent-sdk';
|
|
233
|
+
|
|
234
|
+
const response = await query('Show me the file list');
|
|
235
|
+
|
|
236
|
+
const response = await query('Analyze the code', {
|
|
237
|
+
cwd: '/path/to/project',
|
|
238
|
+
permissionMode: 'acceptEdits',
|
|
239
|
+
maxTurns: 10,
|
|
240
|
+
onTextDelta: (delta) => process.stdout.write(delta),
|
|
241
|
+
onCompact: () => console.log('Context compacted'),
|
|
242
|
+
});
|
|
243
|
+
```
|
|
55
244
|
|
|
56
|
-
|
|
245
|
+
### createSession()
|
|
57
246
|
|
|
58
247
|
```typescript
|
|
59
|
-
import {
|
|
248
|
+
import { createSession, loadConfig, loadContext, detectProject } from '@robota-sdk/agent-sdk';
|
|
60
249
|
|
|
61
|
-
const
|
|
250
|
+
const [config, context, projectInfo] = await Promise.all([
|
|
251
|
+
loadConfig(cwd),
|
|
252
|
+
loadContext(cwd),
|
|
253
|
+
detectProject(cwd),
|
|
254
|
+
]);
|
|
255
|
+
|
|
256
|
+
const session = createSession({ config, context, terminal, projectInfo, permissionMode });
|
|
62
257
|
const response = await session.run('Hello');
|
|
63
|
-
session.getHistory();
|
|
64
|
-
session.clearHistory();
|
|
65
258
|
```
|
|
66
259
|
|
|
260
|
+
### Built-in Tools
|
|
261
|
+
|
|
262
|
+
`@robota-sdk/agent-sdk` re-exports 6 of the 8 built-in tools from `@robota-sdk/agent-tools`:
|
|
263
|
+
|
|
264
|
+
```typescript
|
|
265
|
+
import { bashTool, readTool, writeTool, editTool, globTool, grepTool } from '@robota-sdk/agent-sdk';
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
`webFetchTool` and `webSearchTool` are **not** re-exported from `@robota-sdk/agent-sdk`. Import them directly from the owning package:
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
import { webFetchTool, webSearchTool } from '@robota-sdk/agent-tools';
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## Subagent Sessions
|
|
275
|
+
|
|
276
|
+
`createSubagentSession()` creates an isolated child session for delegating subtasks. The subagent receives pre-resolved config and context from the parent — it does not load config files or context from disk.
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
import { createSubagentSession } from '@robota-sdk/agent-sdk';
|
|
280
|
+
|
|
281
|
+
const subSession = createSubagentSession({
|
|
282
|
+
parentSession: session,
|
|
283
|
+
agentDefinition: 'explore',
|
|
284
|
+
prompt: 'Analyze the test coverage gaps',
|
|
285
|
+
});
|
|
286
|
+
const result = await subSession.run();
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Agent Definitions
|
|
290
|
+
|
|
291
|
+
`IAgentDefinition` describes a reusable agent configuration (system prompt, allowed tools, permission mode). Custom agents are discovered from `.robota/agents/` (project), `.claude/agents/` (Claude Code compatible), and `~/.robota/agents/` (user). `AgentDefinitionLoader` is an internal class — it is not part of the public API.
|
|
292
|
+
|
|
293
|
+
Built-in agents: `general-purpose` (full tool access), `Explore` (read-only, Haiku model), `Plan` (read-only planning).
|
|
294
|
+
|
|
295
|
+
### createAgentTool()
|
|
296
|
+
|
|
297
|
+
`createAgentTool()` wraps subagent creation into a tool the AI can invoke directly. The parent session's hooks, permissions, and context are forwarded to the child.
|
|
298
|
+
|
|
299
|
+
## Hook Executors (SDK-Specific)
|
|
300
|
+
|
|
301
|
+
`agent-sdk` provides two `IHookTypeExecutor` implementations beyond the `command` and `http` executors in `agent-core`:
|
|
302
|
+
|
|
303
|
+
| Executor | Hook Type | Description |
|
|
304
|
+
| ---------------- | --------- | ------------------------------------------------------------------------- |
|
|
305
|
+
| `PromptExecutor` | `prompt` | Injects the hook's prompt text into the session as a system instruction |
|
|
306
|
+
| `AgentExecutor` | `agent` | Creates a sub-agent session to process the hook input and return a result |
|
|
307
|
+
|
|
308
|
+
## Bundle Plugin System
|
|
309
|
+
|
|
310
|
+
Bundle plugins package reusable extensions (tools, hooks, permissions, system prompt additions) into installable units.
|
|
311
|
+
|
|
312
|
+
### Types
|
|
313
|
+
|
|
314
|
+
| Type | Description |
|
|
315
|
+
| ----------------------- | --------------------------------------------------------------- |
|
|
316
|
+
| `IBundlePluginManifest` | Plugin metadata: name, version, description, author, keywords |
|
|
317
|
+
| `ILoadedBundlePlugin` | Full bundle: manifest + tools, hooks, permissions, systemPrompt |
|
|
318
|
+
|
|
319
|
+
### BundlePluginLoader
|
|
320
|
+
|
|
321
|
+
Loads a bundle plugin from a directory path. Reads the manifest, resolves tool/hook definitions, and validates the bundle structure.
|
|
322
|
+
|
|
323
|
+
### BundlePluginInstaller
|
|
324
|
+
|
|
325
|
+
Manages plugin installation and uninstallation:
|
|
326
|
+
|
|
327
|
+
- Installs bundles to `~/.robota/plugins/` (user) or `.robota/plugins/` (project)
|
|
328
|
+
- Tracks installed plugins in a registry file
|
|
329
|
+
- Handles enable/disable state per plugin
|
|
330
|
+
|
|
331
|
+
## Configuration
|
|
332
|
+
|
|
333
|
+
Settings are loaded from (highest priority first):
|
|
334
|
+
|
|
335
|
+
| Layer | Path | Scope |
|
|
336
|
+
| ----- | --------------------------------- | ------------------------------------ |
|
|
337
|
+
| 1 | CLI flags / environment variables | Invocation |
|
|
338
|
+
| 2 | `.robota/settings.local.json` | Project (local) |
|
|
339
|
+
| 3 | `.robota/settings.json` | Project |
|
|
340
|
+
| 4 | `.claude/settings.json` | Project (Claude Code compatible) |
|
|
341
|
+
| 5 | `~/.robota/settings.json` | User global |
|
|
342
|
+
| 6 | `~/.claude/settings.json` | User global (Claude Code compatible) |
|
|
343
|
+
|
|
344
|
+
`$ENV:VAR` substitution is applied after merge.
|
|
345
|
+
|
|
346
|
+
```json
|
|
347
|
+
{
|
|
348
|
+
"defaultMode": "default",
|
|
349
|
+
"provider": {
|
|
350
|
+
"name": "anthropic",
|
|
351
|
+
"model": "claude-sonnet-4-6",
|
|
352
|
+
"apiKey": "$ENV:ANTHROPIC_API_KEY"
|
|
353
|
+
},
|
|
354
|
+
"permissions": {
|
|
355
|
+
"allow": ["Bash(pnpm *)"],
|
|
356
|
+
"deny": ["Bash(rm -rf *)"]
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
## Permission Modes
|
|
362
|
+
|
|
363
|
+
| Mode | Read/Glob/Grep | Write/Edit | Bash |
|
|
364
|
+
| ------------------- | :------------: | :--------: | :-----: |
|
|
365
|
+
| `plan` | auto | deny | deny |
|
|
366
|
+
| `default` | auto | approve | approve |
|
|
367
|
+
| `acceptEdits` | auto | auto | approve |
|
|
368
|
+
| `bypassPermissions` | auto | auto | auto |
|
|
369
|
+
|
|
370
|
+
## Dependencies
|
|
371
|
+
|
|
372
|
+
| Package | Purpose |
|
|
373
|
+
| -------------------------------------- | ------------------------------------- |
|
|
374
|
+
| `@robota-sdk/agent-core` | Engine, providers, permissions, hooks |
|
|
375
|
+
| `@robota-sdk/agent-sessions` | Session, SessionStore |
|
|
376
|
+
| `@robota-sdk/agent-tools` | Tool infrastructure + built-in tools |
|
|
377
|
+
| `@robota-sdk/agent-provider-anthropic` | Anthropic LLM provider |
|
|
378
|
+
| `chalk` | Terminal colors (permission prompt) |
|
|
379
|
+
| `zod` | Settings schema validation |
|
|
380
|
+
|
|
67
381
|
## Documentation
|
|
68
382
|
|
|
69
383
|
See [docs/SPEC.md](./docs/SPEC.md) for the full specification, architecture details, and design decisions.
|