@factory/droid-sdk 0.6.0 → 0.8.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.
Files changed (92) hide show
  1. package/README.md +35 -482
  2. package/dist/chunk-4G2RKM2H.js +25831 -0
  3. package/dist/chunk-4G2RKM2H.js.map +1 -0
  4. package/dist/chunk-ROFAQUG4.mjs +25831 -0
  5. package/dist/chunk-ROFAQUG4.mjs.map +1 -0
  6. package/dist/{index-CwXX5IUH.d.cts → index-_nUPGHpH.d.mts} +92630 -79659
  7. package/dist/{index-CwXX5IUH.d.ts → index-_nUPGHpH.d.ts} +92630 -79659
  8. package/dist/index.d.mts +4 -0
  9. package/dist/index.d.ts +4 -93103
  10. package/dist/index.js +829 -11745
  11. package/dist/index.js.map +1 -1
  12. package/dist/index.mjs +830 -0
  13. package/dist/index.mjs.map +1 -0
  14. package/dist/node.d.mts +757 -0
  15. package/dist/node.d.ts +757 -0
  16. package/dist/node.js +4731 -0
  17. package/dist/node.js.map +1 -0
  18. package/dist/node.mjs +4731 -0
  19. package/dist/node.mjs.map +1 -0
  20. package/docs/typescript-sdk-reference.md +1437 -0
  21. package/examples/browser/daemon-lifecycle.ts +95 -0
  22. package/examples/browser/daemon-model-discovery.ts +47 -0
  23. package/examples/browser/daemon-multi-session.ts +66 -0
  24. package/examples/browser/daemon-session.ts +73 -0
  25. package/examples/browser/index.html +69 -0
  26. package/examples/browser/list-sessions.ts +50 -0
  27. package/examples/node/abort-session-stream.ts +34 -0
  28. package/examples/node/ask-user-elicitation.ts +39 -0
  29. package/examples/node/compact-session.ts +63 -0
  30. package/examples/node/custom-system-prompt.ts +35 -0
  31. package/examples/node/document-input.ts +58 -0
  32. package/examples/node/enter-spec-mode.ts +87 -0
  33. package/examples/node/external-mcp.ts +45 -0
  34. package/examples/node/fork-session.ts +56 -0
  35. package/examples/node/hook-execution.ts +94 -0
  36. package/examples/node/image-attachment.ts +41 -0
  37. package/examples/node/init-metadata.ts +24 -0
  38. package/examples/node/interrupt-session.ts +55 -0
  39. package/examples/node/list-sessions.ts +20 -0
  40. package/examples/node/model-discovery.ts +28 -0
  41. package/examples/node/model-selection.ts +35 -0
  42. package/examples/node/multi-turn-session.ts +37 -0
  43. package/examples/node/observability.ts +75 -0
  44. package/examples/node/partial-stream.ts +56 -0
  45. package/examples/node/permission-handler.ts +60 -0
  46. package/examples/node/rename-session.ts +33 -0
  47. package/examples/node/result-metadata.ts +43 -0
  48. package/examples/node/resume-session.ts +41 -0
  49. package/examples/node/rewind-session.ts +79 -0
  50. package/examples/node/run.ts +32 -0
  51. package/examples/node/sdk-mcp-tool.ts +56 -0
  52. package/examples/node/session-settings.ts +35 -0
  53. package/examples/node/session-stream.ts +59 -0
  54. package/examples/node/skills.ts +24 -0
  55. package/examples/node/spec-mode-new-session.ts +120 -0
  56. package/examples/node/spec-mode-same-session.ts +119 -0
  57. package/examples/node/structured-output.ts +96 -0
  58. package/examples/node/tool-controls.ts +26 -0
  59. package/examples/package.json +3 -0
  60. package/package.json +20 -42
  61. package/dist/index.cjs +0 -12135
  62. package/dist/index.cjs.map +0 -1
  63. package/dist/index.d.cts +0 -93103
  64. package/dist/protocol/index.cjs +0 -6466
  65. package/dist/protocol/index.cjs.map +0 -1
  66. package/dist/protocol/index.d.cts +0 -2
  67. package/dist/protocol/index.d.ts +0 -2
  68. package/dist/protocol/index.js +0 -6078
  69. package/dist/protocol/index.js.map +0 -1
  70. package/docs/daemon-usage-guide.md +0 -544
  71. package/docs/sdk-usage-guide.md +0 -748
  72. package/examples/abort-session-stream.ts +0 -34
  73. package/examples/daemon-multi-session.ts +0 -67
  74. package/examples/droid-dev-structured-output.ts +0 -44
  75. package/examples/fork-session.ts +0 -68
  76. package/examples/hook-execution.ts +0 -68
  77. package/examples/init-metadata.ts +0 -24
  78. package/examples/interrupt-session.ts +0 -35
  79. package/examples/list-sessions.ts +0 -19
  80. package/examples/multi-turn-session.ts +0 -40
  81. package/examples/permission-handler.ts +0 -41
  82. package/examples/readme-structured-output.ts +0 -26
  83. package/examples/result-metadata.ts +0 -63
  84. package/examples/run.ts +0 -39
  85. package/examples/sdk-mcp-tool.ts +0 -44
  86. package/examples/session-stream.ts +0 -57
  87. package/examples/spec-mode-new-session.ts +0 -61
  88. package/examples/spec-mode-same-session.ts +0 -72
  89. package/examples/structured-output.ts +0 -60
  90. package/examples/test-compact.ts +0 -65
  91. package/examples/test-rewind.ts +0 -87
  92. package/examples/tool-controls.ts +0 -37
package/README.md CHANGED
@@ -1,11 +1,7 @@
1
1
  # @factory/droid-sdk
2
2
 
3
- TypeScript SDK for the [Factory](https://factory.ai) Droid CLI. Provides a high-level API for interacting with Droid as a subprocess, with one-shot prompts, streaming messages, multi-turn sessions, structured output, SDK-backed MCP tools, spec mode, tool controls, initialization metadata, session forking, session discovery, and tool permission handling.
4
-
5
- ## Requirements
6
-
7
- - **Node.js 18+**
8
- - The `droid` CLI installed and available on your PATH
3
+ The Factory TypeScript SDK lets applications run Droid, continue conversations,
4
+ stream work, control tools, and connect to a running Droid daemon.
9
5
 
10
6
  ## Installation
11
7
 
@@ -13,500 +9,57 @@ TypeScript SDK for the [Factory](https://factory.ai) Droid CLI. Provides a high-
13
9
  npm install @factory/droid-sdk
14
10
  ```
15
11
 
16
- ## Quick Start
17
-
18
- Send a one-shot prompt and get the aggregated result:
19
-
20
- ```ts
21
- import { run } from '@factory/droid-sdk';
22
-
23
- const result = await run('What files are in the current directory?', {
24
- cwd: '/my/project',
25
- });
26
-
27
- console.log(result.text);
28
- ```
29
-
30
- Create a session when you want to stream one or more turns:
31
-
32
- ```ts
33
- import { DroidMessageType, createSession } from '@factory/droid-sdk';
34
-
35
- const session = await createSession({ cwd: '/my/project' });
36
-
37
- try {
38
- for await (const msg of session.stream(
39
- 'What files are in the current directory?'
40
- )) {
41
- if (msg.type === DroidMessageType.AssistantTextDelta) {
42
- process.stdout.write(msg.text);
43
- }
44
- if (msg.type === DroidMessageType.Result) {
45
- console.log('\nDone!');
46
- }
47
- }
48
- } finally {
49
- await session.close();
50
- }
51
- ```
52
-
53
- ## Structured Output
54
-
55
- Request a JSON object that matches a JSON Schema:
56
-
57
- ```ts
58
- import { OutputFormatType, run } from '@factory/droid-sdk';
59
-
60
- const result = await run('Pick a favorite number between 1 and 42.', {
61
- cwd: '/my/project',
62
- outputFormat: {
63
- type: OutputFormatType.JsonSchema,
64
- schema: {
65
- type: 'object',
66
- properties: {
67
- favoriteNumber: {
68
- type: 'number',
69
- minimum: 1,
70
- maximum: 42,
71
- },
72
- },
73
- required: ['favoriteNumber'],
74
- },
75
- },
76
- });
77
-
78
- console.log(result.structuredOutput?.favoriteNumber);
79
- ```
80
-
81
- Structured output is available on `run()` and `session.stream(prompt, options)` through the `outputFormat` message option. `run()` parses the final object into `result.structuredOutput`; streaming callers can read and parse the final assistant message themselves.
82
-
83
- ## Multi-Turn Sessions
84
-
85
- Use `createSession()` for persistent conversations with multiple turns:
86
-
87
- ```ts
88
- import { createSession, DroidMessageType } from '@factory/droid-sdk';
89
-
90
- const session = await createSession({ cwd: '/my/project' });
91
- console.log(session.sessionId);
92
-
93
- // Streaming turn
94
- for await (const msg of session.stream('List all TypeScript files')) {
95
- if (msg.type === DroidMessageType.AssistantTextDelta) {
96
- process.stdout.write(msg.text);
97
- }
98
- }
99
-
100
- // Later turns use the same streaming API
101
- for await (const msg of session.stream('Summarize the project')) {
102
- if (msg.type === DroidMessageType.AssistantTextDelta) {
103
- process.stdout.write(msg.text);
104
- }
105
- }
106
-
107
- await session.close();
108
- ```
109
-
110
- Use `session.sessionId` to persist the session ID, then resume it later:
111
-
112
- ```ts
113
- import { resumeSession } from '@factory/droid-sdk';
114
-
115
- const session = await resumeSession(savedSessionId);
116
- for await (const msg of session.stream('Continue where we left off')) {
117
- // Handle streamed DroidMessage events.
118
- }
119
- await session.close();
120
- ```
121
-
122
- The returned `DroidSession` also exposes `session.initResult`, which contains the raw `initialize_session` or `load_session` result returned by the JSON-RPC server.
123
-
124
- ## SDK-backed MCP Tools
125
-
126
- Expose in-process TypeScript tools to Droid through MCP:
127
-
128
- ```ts
129
- import { z } from 'zod';
130
-
131
- import {
132
- DroidMessageType,
133
- ToolConfirmationOutcome,
134
- createSession,
135
- createSdkMcpServer,
136
- tool,
137
- } from '@factory/droid-sdk';
138
-
139
- const sdkTools = createSdkMcpServer({
140
- name: 'sdk-tools',
141
- tools: [
142
- tool(
143
- 'favorite_number',
144
- 'Returns a favorite number for a person',
145
- { name: z.string() },
146
- ({ name }) => `${name}'s favorite number is 42.`
147
- ),
148
- ],
149
- });
150
-
151
- const session = await createSession({
152
- cwd: '/my/project',
153
- mcpServers: [sdkTools],
154
- permissionHandler: () => ToolConfirmationOutcome.ProceedOnce,
155
- });
156
-
157
- for await (const msg of session.stream(
158
- 'Use the favorite_number tool for Ada and tell me the answer.'
159
- )) {
160
- if (msg.type === DroidMessageType.AssistantTextDelta) {
161
- process.stdout.write(msg.text);
162
- }
163
- }
164
-
165
- await session.close();
166
- ```
167
-
168
- `createSdkMcpServer()` is managed by the SDK session lifecycle. Use `tool()` with a Zod object shape for typed tool input validation.
169
-
170
- ## Initialization Metadata
171
-
172
- Inspect the raw initialization metadata from `createSession()` and `resumeSession()`:
173
-
174
- ```ts
175
- import { createSession, resumeSession } from '@factory/droid-sdk';
176
-
177
- const session = await createSession({ cwd: '/my/project' });
178
- console.log(session.sessionId);
179
- console.log(session.initResult.settings.modelId);
180
-
181
- const resumed = await resumeSession(session.sessionId);
182
- console.log(resumed.initResult.cwd);
183
-
184
- await resumed.close();
185
- await session.close();
186
- ```
187
-
188
- ## Spec Mode
189
-
190
- Start a session directly in spec mode, or enter spec mode later on an existing session:
191
-
192
- ```ts
193
- import {
194
- DroidMessageType,
195
- createSession,
196
- DroidInteractionMode,
197
- ReasoningEffort,
198
- } from '@factory/droid-sdk';
199
-
200
- const session = await createSession({
201
- cwd: '/my/project',
202
- interactionMode: DroidInteractionMode.Spec,
203
- specModeReasoningEffort: ReasoningEffort.High,
204
- specModeModelId: 'claude-sonnet-4-20250514',
205
- });
206
-
207
- for await (const msg of session.stream(
208
- 'Draft a plan for adding integration tests'
209
- )) {
210
- if (msg.type === DroidMessageType.AssistantTextDelta) {
211
- process.stdout.write(msg.text);
212
- }
213
- }
214
-
215
- await session.enterSpecMode({
216
- specModeReasoningEffort: ReasoningEffort.High,
217
- });
218
-
219
- await session.close();
220
- ```
221
-
222
- When handling spec-mode approval, you can approve implementation in the same session with `ToolConfirmationOutcome.ProceedOnce`, or hand off to a fresh session with `ToolConfirmationOutcome.ProceedNewSessionHigh`.
12
+ The SDK requires Node.js 18 or later.
223
13
 
224
- ## Tool Controls
14
+ ## Entrypoints
225
15
 
226
- Control which exec tools are available at session start, inspect the current tool catalog, and update tool overrides later:
16
+ | Import | Runtime | Purpose |
17
+ | ------------------------- | --------------- | ----------------------------------------------------------------------------------------- |
18
+ | `@factory/droid-sdk/node` | Node | Start Droid subprocesses, run prompts, manage local sessions, and define SDK MCP tools |
19
+ | `@factory/droid-sdk` | Browser or Node | Connect to an existing Droid daemon and use browser-safe schemas, types, and REST helpers |
227
20
 
228
- ```ts
229
- import { createSession } from '@factory/droid-sdk';
21
+ By default, Node session APIs start the `droid` CLI from `PATH` and read
22
+ `FACTORY_API_KEY`. A custom executable, API key, or transport can be supplied
23
+ through session options.
230
24
 
231
- const session = await createSession({
232
- cwd: '/my/project',
233
- enabledToolIds: ['Read'],
234
- disabledToolIds: ['Execute'],
235
- });
236
-
237
- const { tools } = await session.listTools();
238
- console.log(
239
- tools.map((tool) => ({
240
- id: tool.llmId,
241
- allowed: tool.currentlyAllowed,
242
- }))
243
- );
244
-
245
- await session.updateSettings({
246
- disabledToolIds: ['Read', 'Execute'],
247
- });
248
-
249
- await session.close();
250
- ```
251
-
252
- ## Forking Sessions
253
-
254
- Fork the current server-side session and continue from the new session ID:
25
+ ## Quick start
255
26
 
256
27
  ```ts
257
- import {
258
- DroidMessageType,
259
- createSession,
260
- resumeSession,
261
- } from '@factory/droid-sdk';
28
+ import { run } from '@factory/droid-sdk/node';
262
29
 
263
- const session = await createSession({ cwd: '/my/project' });
30
+ const result = await run('Summarize this repository.');
264
31
 
265
- for await (const _msg of session.stream(
266
- 'Remember this phrase: mango sunrise'
267
- )) {
268
- // Consume the turn.
32
+ if (!result.success) {
33
+ throw new Error(result.error?.message ?? 'The run did not complete.');
269
34
  }
270
35
 
271
- const { newSessionId } = await session.forkSession();
272
- const fork = await resumeSession(newSessionId);
273
-
274
- for await (const msg of fork.stream('What phrase did I ask you to remember?')) {
275
- if (msg.type === DroidMessageType.AssistantTextDelta) {
276
- process.stdout.write(msg.text);
277
- }
278
- }
279
-
280
- await fork.close();
281
- await session.close();
282
- ```
283
-
284
- ## Listing Sessions
285
-
286
- Discover droid sessions saved on disk (mirrors the CLI's `/sessions` command). Reads `~/.factory/sessions/` directly — no droid process is spawned, so this works even when no session is running:
287
-
288
- ```ts
289
- import { listSessions } from '@factory/droid-sdk';
290
-
291
- // Sessions for the current project (cwd defaults to process.cwd())
292
- const current = await listSessions();
293
-
294
- // 10 most recent sessions in the current project
295
- const recent = await listSessions({ numSessions: 10 });
296
-
297
- // Every session on disk, most recent first
298
- const all = await listSessions({ fetchOutsideCWD: true });
299
-
300
- // 10 most recent sessions across all projects
301
- const recentAcrossProjects = await listSessions({
302
- fetchOutsideCWD: true,
303
- numSessions: 10,
304
- });
305
-
306
- // Sessions for a specific other project
307
- const other = await listSessions({ cwd: '/Users/me/other-repo' });
308
-
309
- for (const s of current) {
310
- console.log(`[${s.id}] ${s.title} (${s.messageCount} msgs)`);
311
- }
312
- ```
313
-
314
- Each `SessionMetadata` record includes `id`, `title`, `sessionTitle`, `owner`, `messageCount`, `modifiedTime`, `createdTime`, `isFavorite`, `cwd`, `decompSessionType`, and `decompMissionId`. Archived sessions (those with an `archivedAt` in their settings file) are excluded automatically. Results are sorted by `modifiedTime` descending.
315
-
316
- `ListSessionsOptions`:
317
-
318
- - **`cwd`** — working directory to scope the listing to (default `process.cwd()`). Ignored when `fetchOutsideCWD` is `true`.
319
- - **`fetchOutsideCWD`** — return sessions from every working directory on disk (default `false`)
320
- - **`numSessions`** — cap on total sessions returned
321
- - **`sessionsDir`** — override the sessions root (default `~/.factory/sessions/`)
322
-
323
- ## Permission Handling
324
-
325
- Handle tool confirmation requests with a custom permission handler:
326
-
327
- ```ts
328
- import {
329
- DroidMessageType,
330
- createSession,
331
- ToolConfirmationOutcome,
332
- } from '@factory/droid-sdk';
333
-
334
- const session = await createSession({
335
- cwd: '/my/project',
336
- permissionHandler(params) {
337
- console.log('Tool permission requested:', params);
338
- return ToolConfirmationOutcome.ProceedOnce;
339
- },
340
- });
341
-
342
- try {
343
- for await (const msg of session.stream('Create a hello.txt file')) {
344
- if (msg.type === DroidMessageType.AssistantTextDelta) {
345
- process.stdout.write(msg.text);
346
- }
347
- }
348
- } finally {
349
- await session.close();
350
- }
351
- ```
352
-
353
- ## API Reference
354
-
355
- ### Top-Level Functions
356
-
357
- | Function | Description |
358
- | ----------------------------- | ---------------------------------------------------------------- |
359
- | `run(prompt, options?)` | One-shot prompt → aggregated `DroidResult` |
360
- | `createSession(options?)` | Create a new multi-turn session → `DroidSession` |
361
- | `resumeSession(id, options?)` | Resume an existing session → `DroidSession` |
362
- | `listSessions(options?)` | List droid sessions saved on disk → `Promise<SessionMetadata[]>` |
363
- | `createSdkMcpServer(options)` | Create an SDK-managed MCP server for in-process tools |
364
- | `tool(...)` | Define a typed SDK-backed MCP tool |
365
-
366
- ### `DroidSession`
367
-
368
- Returned by `createSession()` and `resumeSession()`. Key methods:
369
-
370
- - **`stream(prompt, options?)`** — stream `DroidMessage` events for one turn
371
- - **`interrupt()`** — interrupt the current turn
372
- - **`close()`** — close the session and release resources
373
- - **`updateSettings(params)`** — update model, autonomy level, etc.
374
- - **`enterSpecMode(params?)`** — switch the current session into spec mode
375
- - **`forkSession()`** — create a forked server-side session and return its new session ID
376
- - **`compactSession(params?)`** — compact session history and return the new session ID
377
- - **`getContextStats()`** — read current context window utilization
378
- - **`addMcpServer(params)`** / **`removeMcpServer(params)`** / **`toggleMcpServer(params)`** — manage MCP servers
379
- - **`listMcpServers()`** / **`listMcpTools()`** / **`authenticateMcpServer(params)`** — inspect and authenticate MCP servers
380
- - **`listTools(params?)`** — inspect the exec tool catalog and current allow/deny state
381
- - **`renameSession(params)`** — rename the current session
382
- - **`getRewindInfo(params)`** / **`executeRewind(params)`** — inspect and execute file rewind operations
383
- - **`sessionId`** — the session ID
384
- - **`initResult`** — cached `initialize_session` or `load_session` result
385
-
386
- ### `DroidResult`
387
-
388
- Returned by `run()`:
389
-
390
- - **`sessionId`** — session that produced the result
391
- - **`text`** — concatenated assistant response text
392
- - **`messages`** — all `DroidMessage` objects from the turn
393
- - **`tokenUsage`** — final token usage, or `null`
394
- - **`durationMs`** — wall-clock time spent consuming the turn
395
- - **`turnCount`** — number of completed turns observed while consuming the stream
396
- - **`error`** — first Droid error event from the turn, or `null`
397
- - **`structuredOutput`** — parsed structured JSON object, or `null`
398
- - **`success`** — `true` when no Droid error event was emitted
399
-
400
- ### `DroidMessage` Types
401
-
402
- All messages have a discriminated `type` field:
403
-
404
- ```ts
405
- import { DroidMessageType } from '@factory/droid-sdk';
406
-
407
- if (msg.type === DroidMessageType.AssistantTextDelta) {
408
- process.stdout.write(msg.text);
409
- }
36
+ console.log(result.text);
410
37
  ```
411
38
 
412
- | Type | Description |
413
- | -------------------------- | ----------------------------------------------- |
414
- | `assistant` | Complete assistant message |
415
- | `user` | Complete user message |
416
- | `assistant_text_delta` | Streaming text token from the assistant |
417
- | `assistant_text_complete` | End of an assistant text block |
418
- | `thinking_text_delta` | Streaming reasoning/thinking token |
419
- | `thinking_text_complete` | End of a thinking block |
420
- | `tool_call` | Tool invocation by the assistant |
421
- | `tool_call_delta` | Streaming tool call input |
422
- | `tool_result` | Result from a tool execution |
423
- | `tool_progress` | Progress update during tool execution |
424
- | `hook` | File hook execution event (started or finished) |
425
- | `working_state_changed` | Agent working state transition |
426
- | `token_usage_update` | Updated token usage counters |
427
- | `result` | End-of-turn sentinel with aggregated metadata |
428
- | `session_title_updated` | Session title changed |
429
- | `settings_updated` | Session settings changed |
430
- | `permission_resolved` | Tool permission request resolved |
431
- | `mcp_status_changed` | MCP server status changed |
432
- | `mcp_auth_required` | MCP authentication required |
433
- | `mcp_auth_completed` | MCP authentication completed |
434
- | `error` | Error event from the process |
435
- | `mission_state_changed` | Mission state changed |
436
- | `mission_features_changed` | Mission features changed |
437
- | `mission_progress_entry` | Mission progress log changed |
438
- | `mission_heartbeat` | Mission heartbeat |
439
- | `mission_worker_started` | Mission worker started |
440
- | `mission_worker_completed` | Mission worker completed |
441
-
442
- ### Options
443
-
444
- Session creation options used by `run()` and `createSession()` include:
445
-
446
- - **`cwd`** — working directory for the session
447
- - **`execPath`** — path to `droid` executable (default: `"droid"`)
448
- - **`execArgs`** — extra CLI arguments for the spawned droid process
449
- - **`env`** — environment variables for the spawned process
450
- - **`transport`** — provide a custom transport instead of spawning a process
451
- - **`modelId`** — LLM model identifier
452
- - **`autonomyLevel`** — `AutonomyLevel` enum value
453
- - **`interactionMode`** — `DroidInteractionMode` enum value
454
- - **`reasoningEffort`** — `ReasoningEffort` enum value
455
- - **`specModeModelId`** — override model used in spec mode
456
- - **`specModeReasoningEffort`** — override reasoning level used in spec mode
457
- - **`mcpServers`** — initial MCP server configurations, including SDK-backed MCP servers from `createSdkMcpServer()`
458
- - **`enabledToolIds`** — explicit exec tool allowlist
459
- - **`disabledToolIds`** — explicit exec tool denylist
460
- - **`permissionHandler`** — callback for tool confirmations
461
- - **`askUserHandler`** — callback for interactive questions
462
- - **`abortSignal`** — standard `AbortSignal` for cancellation
463
-
464
- `resumeSession()` accepts the process, transport, handler, `mcpServers`, and `abortSignal` options needed to reconnect to an existing session, but does not accept new-session-only options such as `modelId` or `interactionMode`. `cwd` is intentionally not accepted on resume: the persisted session's working directory is always used. To run in a different directory, create a new session or fork the existing one.
465
-
466
- Message APIs (`run()` and `session.stream()`) also accept:
467
-
468
- - **`images`** — base64 image attachments
469
- - **`files`** — document/file attachments
470
- - **`outputFormat`** — structured output request, currently `OutputFormatType.JsonSchema`
471
- - **`abortSignal`** — standard `AbortSignal` for turn cancellation
472
-
473
- ### `DroidClient`
39
+ Use `createSession()` for multi-turn Node conversations. Use
40
+ `connectToDaemon()` from the root entrypoint to manage sessions through an
41
+ existing daemon.
474
42
 
475
- Low-level JSON-RPC client for advanced use. Provides typed methods for the underlying protocol operations, including `listTools()`, `renameSession()`, `getRewindInfo()`, and `executeRewind()`. Most users should prefer `run()` and `createSession()`.
43
+ ## Documentation
476
44
 
477
- ### Error Types
45
+ The [TypeScript SDK reference](./docs/typescript-sdk-reference.md) is the
46
+ single user-facing guide to:
478
47
 
479
- | Error | Description |
480
- | ---------------------- | -------------------------------------- |
481
- | `ConnectionError` | Failed to connect to the droid process |
482
- | `ProtocolError` | JSON-RPC protocol error |
483
- | `SessionError` | Base session error |
484
- | `SessionNotFoundError` | Session ID not found |
485
- | `TimeoutError` | Request timed out |
486
- | `ProcessExitError` | Droid subprocess exited unexpectedly |
48
+ - Node and daemon runtimes
49
+ - Runs, sessions, streaming, attachments, and structured output
50
+ - Permissions, AskUser, tools, skills, MCP, and hooks
51
+ - Session replacement and cleanup behavior
52
+ - Browser and daemon integration
53
+ - Observability, REST helpers, advanced resources, and the public API
487
54
 
488
- ## Examples
55
+ Runnable examples are available under [`examples/node`](./examples/node) and
56
+ [`examples/browser`](./examples/browser).
489
57
 
490
- See the [`examples/`](./examples) directory for runnable examples:
58
+ ## Browser security
491
59
 
492
- - **[`session-stream.ts`](./examples/session-stream.ts)** — session streaming output
493
- - **[`run.ts`](./examples/run.ts)** — one-shot prompt with aggregated result
494
- - **[`multi-turn-session.ts`](./examples/multi-turn-session.ts)** — multi-turn session lifecycle
495
- - **[`abort-session-stream.ts`](./examples/abort-session-stream.ts)** — cancel an in-flight streaming session turn with `AbortSignal`
496
- - **[`interrupt-session.ts`](./examples/interrupt-session.ts)** — interrupt a running session turn
497
- - **[`init-metadata.ts`](./examples/init-metadata.ts)** — read initialization and load metadata from session APIs
498
- - **[`result-metadata.ts`](./examples/result-metadata.ts)** — inspect `DroidResult` metadata from `run()`
499
- - **[`structured-output.ts`](./examples/structured-output.ts)** — request and parse structured output
500
- - **[`droid-dev-structured-output.ts`](./examples/droid-dev-structured-output.ts)** — structured output smoke test with configurable Droid executable
501
- - **[`permission-handler.ts`](./examples/permission-handler.ts)** — custom permission handling
502
- - **[`spec-mode-same-session.ts`](./examples/spec-mode-same-session.ts)** — approve a spec and continue in the same session
503
- - **[`spec-mode-new-session.ts`](./examples/spec-mode-new-session.ts)** — approve a spec and hand off implementation to a new session
504
- - **[`tool-controls.ts`](./examples/tool-controls.ts)** — configure allow/deny lists and inspect tool availability
505
- - **[`sdk-mcp-tool.ts`](./examples/sdk-mcp-tool.ts)** — expose SDK-defined tools to Droid through MCP
506
- - **[`fork-session.ts`](./examples/fork-session.ts)** — fork a session and continue from the new session ID
507
- - **[`list-sessions.ts`](./examples/list-sessions.ts)** — discover droid sessions saved on disk
508
- - **[`test-compact.ts`](./examples/test-compact.ts)** — compact session history
509
- - **[`test-rewind.ts`](./examples/test-rewind.ts)** — use low-level rewind APIs
60
+ The daemon client currently authenticates with a Factory API key. Browser
61
+ integration is intended for trusted local tools. Do not ship a Factory API key
62
+ in a public website, commit it to source control, or put it in a URL.
510
63
 
511
64
  ## License
512
65