Skip to content

Commit a410305

Browse files
docs: update examples for SDK 0.11.0 (#83)
* docs: update examples for SDK 0.11.0 Add the workstream and REST API examples that ship in the 0.11.0 package, document the removed Software Factory resource and held cron sessions, and list the new workstreams, environments and elicitation APIs. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> * docs: answer the 0.11.0 examples review - start-workstream.ts reads DROID_WORKSTREAM_COMPUTER_ID, so the example harness's DROID_ scrub keeps a developer's Computer out of isolated runs. - The reference says generated REST operations put only HTTP error bodies in `error`; network, abort and parse failures reject, and throwOnError makes HTTP errors reject too. - Drop the reference's Software Factory list methods and its "REST remote-session support provides listing only" limitation, both false for 0.11.0. - rest-api.ts says session listing needs the feature on the key's organization. - The reference's example index, inputs list and unstable resources section name start-workstream.ts and rest-api.ts. - package-lock.json root version fields read 0.11.0. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --------- Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
1 parent 6d4046d commit a410305

8 files changed

Lines changed: 523 additions & 80 deletions

File tree

‎MIGRATION.md‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,54 @@
11
# Migration Guide
22

3+
## Migrating from 0.10.0 to 0.11.0
4+
5+
### 1. Upgrade the package
6+
7+
```bash
8+
npm install @factory/droid-sdk@^0.11.0
9+
```
10+
11+
Applications that use `run()`, `createSession()`, `resumeSession()`, or
12+
`connectToDaemon()` sessions need no changes. Two unstable daemon resources
13+
lost methods.
14+
15+
### 2. Remove Software Factory calls
16+
17+
`droid.unstable.softwareFactory` is gone, with its `workstreams`, `signals`,
18+
`changes`, `activities`, and `events` resources and their types
19+
(`SoftwareFactoryResource`, `SoftwareFactoryWorkstreamsResource`,
20+
`SoftwareFactorySignalsResource`, `SoftwareFactoryChangesResource`,
21+
`SoftwareFactoryActivitiesResource`, `SoftwareFactoryEventsResource`, and
22+
`SoftwareFactoryWorkstreamEntry`). Daemons no longer serve them.
23+
24+
### 3. Remove held cron sessions
25+
26+
`droid.unstable.crons.holdSession()` and `resumeSession()` are gone, with the
27+
`CronOperationsResource` type. A loop tick now reaches its session as a steering
28+
message, so there is no held state to set or clear. `list`, `create`, `update`,
29+
and `delete` are unchanged.
30+
31+
### 4. New in 0.11.0
32+
33+
- `droid.unstable.workstreams` starts, lists, and updates workstreams on a
34+
daemon. See
35+
[`examples/node/start-workstream.ts`](./examples/node/start-workstream.ts).
36+
- `@factory/droid-sdk/api` exports a client generated from the public Factory
37+
API spec. See [`examples/node/rest-api.ts`](./examples/node/rest-api.ts).
38+
- The root entry point adds `listEnvironments`, `listRemoteSessionElicitations`,
39+
and `answerRemoteSessionElicitation`.
40+
- `@factory/droid-sdk/node` adds `DroidConnectionEndedError`,
41+
`RequestCancelledError`, and `isDroidConnectionEnded`.
42+
43+
### 5. Verify the migration
44+
45+
```bash
46+
npm run typecheck
47+
npm run lint
48+
npm run format:check
49+
npx tsx examples/node/list-sessions.ts
50+
```
51+
352
## Migrating from 0.9.x to 0.10.0
453

554
### 1. Upgrade the package

‎README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ Run Node examples with `npx tsx examples/node/<file>.ts`. To connect a Node
6161
application to a running daemon with an API key, run
6262
`FACTORY_API_KEY=... npx tsx examples/node/daemon-session.ts`.
6363
To start a mission with orchestrator and worker progress, run
64-
`npx tsx examples/node/mission.ts`.
64+
`npx tsx examples/node/mission.ts`. To start a workstream on a running daemon
65+
and leave it running, run
66+
`DROID_DAEMON_URL=... FACTORY_API_KEY=... npx tsx examples/node/start-workstream.ts "<goal>"`.
6567

6668
For browser examples, start a local daemon and run
6769
`npm run serve:browser-example`, then open `http://127.0.0.1:8420/`. The

‎docs/typescript-sdk-reference.md‎

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ The namespaced daemon facade normalizes common collection results:
936936
- `sessions.getMessages()` returns the message array directly.
937937
- Collection methods such as `customModels.list()`, `terminals.list()`,
938938
`mcp.listRegistry()`, `mcp.listTools()`, `commands.list()`, and the plugin,
939-
marketplace, automation, and Software Factory list methods return arrays.
939+
marketplace, and automation list methods return arrays.
940940
- Methods whose protocol result includes additional metadata retain the result
941941
object. This includes `sessions.search()`, `mcp.listServers()`, and
942942
`skills.list()`.
@@ -1095,22 +1095,44 @@ different Factory API host.
10951095
| Resource | Functions |
10961096
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
10971097
| Machine templates | `listMachineTemplates`, `getMachineTemplate` |
1098+
| Environments | `listEnvironments` |
10981099
| Computers | `listComputers`, `getComputer`, `getComputerByName`, `createComputer`, `updateComputer`, `deleteComputer`, `restartComputer`, `refreshComputer` |
10991100
| Computer operations | `getComputerMetrics`, `retryInstallDeps` |
1100-
| Remote sessions | `listRemoteSessions` |
1101+
| Remote sessions | `listRemoteSessions`, `listRemoteSessionElicitations`, `answerRemoteSessionElicitation` |
1102+
1103+
The `@factory/droid-sdk/api` entry point exports a client generated from the
1104+
public Factory API spec, with one function per operation. Each operation takes
1105+
`{ client }` from `createFactoryClient()` and resolves `{ data, error }`,
1106+
where `error` holds the body of an HTTP error response. A network failure, an
1107+
abort, or a response that cannot be parsed rejects the call instead, and
1108+
`throwOnError: true` makes HTTP errors reject too. Several names, such as
1109+
`listComputers`, exist on both entry points with different contracts, so a
1110+
file that imports both should alias the shared names.
1111+
1112+
```ts
1113+
import { createFactoryClient, listComputers } from '@factory/droid-sdk/api';
1114+
1115+
const client = createFactoryClient({ apiKey: process.env.FACTORY_API_KEY! });
1116+
const { data, error } = await listComputers({ client });
1117+
```
1118+
1119+
See [`examples/node/rest-api.ts`](../examples/node/rest-api.ts).
11011120

11021121
### Unstable daemon resources
11031122

11041123
APIs under `droid.unstable` may change between SDK releases.
11051124

1106-
| Namespace | Main methods or resources |
1107-
| ----------------- | ------------------------------------------------------------------------- |
1108-
| `crons` | `list`, `create`, `update`, `delete`, `holdSession`, `resumeSession` |
1109-
| `missions` | `inspectReadiness`, `acknowledgeReadinessWarning` |
1110-
| `semanticDiff` | `getCache`, `saveCache`, `generate` |
1111-
| `fileTransfers` | `push`, `pull` |
1112-
| `proxy` | `getToken` |
1113-
| `softwareFactory` | `workstreams`, `signals`, `changes`, `activities`, and `events` resources |
1125+
| Namespace | Main methods or resources |
1126+
| --------------- | ------------------------------------------------- |
1127+
| `crons` | `list`, `create`, `update`, `delete` |
1128+
| `missions` | `inspectReadiness`, `acknowledgeReadinessWarning` |
1129+
| `workstreams` | `start`, `list`, `updateSettings` |
1130+
| `semanticDiff` | `getCache`, `saveCache`, `generate` |
1131+
| `fileTransfers` | `push`, `pull` |
1132+
| `proxy` | `getToken` |
1133+
1134+
See [`examples/node/start-workstream.ts`](../examples/node/start-workstream.ts)
1135+
for `workstreams.start()`.
11141136

11151137
Keep unstable API use behind an application-owned adapter.
11161138

@@ -1317,15 +1339,15 @@ switch (result.subtype) {
13171339
- Daemon replacement locking does not coordinate separate clients.
13181340
- Browser daemon authentication currently requires an API key.
13191341
- New-session spec handoff IDs require raw notification inspection.
1320-
- REST remote-session support currently provides listing only.
13211342

13221343
## Runnable examples
13231344

13241345
The package includes runnable examples for one-shot runs, streaming, partial
13251346
events, sessions, resume, model selection, permissions, AskUser, image and
13261347
document attachments, structured output, SDK and external MCP tools, skills,
13271348
hooks, observability, spec mode, replacement lifecycle, daemon sessions,
1328-
concurrent browser sessions, daemon lifecycle operations, and missions.
1349+
concurrent browser sessions, daemon lifecycle operations, missions,
1350+
workstreams, and the Factory REST API.
13291351

13301352
All examples are under:
13311353

@@ -1352,26 +1374,29 @@ Some examples need additional input:
13521374
- `document-input.ts`: optionally pass a text or PDF path.
13531375
- `external-mcp.ts`: set `MCP_SERVER_URL` and, if necessary, `MCP_SERVER_TOKEN`.
13541376
- `daemon-session.ts`: start a daemon first. Set `DROID_DAEMON_URL` for a non-default address.
1377+
- `start-workstream.ts`: pass the workstream goal, and set `DROID_DAEMON_URL` for a running daemon whose account has access to workstreams.
1378+
- `rest-api.ts`: optionally pass the API base URL.
13551379

13561380
Use compatible SDK and CLI versions. SDK 0.9.1 and earlier can reject newer
13571381
protocol messages, including model providers and Script permission requests.
13581382
Use SDK 0.10.0 or later with current CLI releases.
13591383
A successful result without assistant text does not prove that streaming works.
13601384
Do not remove permission checks to bypass a protocol mismatch.
13611385

1362-
| Topic | Node examples |
1363-
| -------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
1364-
| Runs and results | `run.ts`, `result-metadata.ts` |
1365-
| Sessions | `multi-turn-session.ts`, `resume-session.ts`, `list-sessions.ts`, `rename-session.ts`, `init-metadata.ts`, `session-settings.ts` |
1366-
| Streaming and cancellation | `session-stream.ts`, `partial-stream.ts`, `abort-session-stream.ts`, `interrupt-session.ts` |
1367-
| Models | `model-discovery.ts`, `model-selection.ts` |
1368-
| Inputs and outputs | `image-attachment.ts`, `document-input.ts`, `structured-output.ts` |
1369-
| Permissions and user input | `permission-handler.ts`, `ask-user-elicitation.ts`, `tool-controls.ts` |
1370-
| Extensions | `sdk-mcp-tool.ts`, `external-mcp.ts`, `skills.ts`, `hook-execution.ts` |
1371-
| Session lifecycle | `fork-session.ts`, `compact-session.ts`, `rewind-session.ts` |
1372-
| Spec mode | `enter-spec-mode.ts`, `spec-mode-same-session.ts`, `spec-mode-new-session.ts` |
1373-
| Daemon and missions | `daemon-session.ts`, `mission.ts` |
1374-
| Observability | `observability.ts` |
1386+
| Topic | Node examples |
1387+
| --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
1388+
| Runs and results | `run.ts`, `result-metadata.ts` |
1389+
| Sessions | `multi-turn-session.ts`, `resume-session.ts`, `list-sessions.ts`, `rename-session.ts`, `init-metadata.ts`, `session-settings.ts` |
1390+
| Streaming and cancellation | `session-stream.ts`, `partial-stream.ts`, `abort-session-stream.ts`, `interrupt-session.ts` |
1391+
| Models | `model-discovery.ts`, `model-selection.ts` |
1392+
| Inputs and outputs | `image-attachment.ts`, `document-input.ts`, `structured-output.ts` |
1393+
| Permissions and user input | `permission-handler.ts`, `ask-user-elicitation.ts`, `tool-controls.ts` |
1394+
| Extensions | `sdk-mcp-tool.ts`, `external-mcp.ts`, `skills.ts`, `hook-execution.ts` |
1395+
| Session lifecycle | `fork-session.ts`, `compact-session.ts`, `rewind-session.ts` |
1396+
| Spec mode | `enter-spec-mode.ts`, `spec-mode-same-session.ts`, `spec-mode-new-session.ts` |
1397+
| Daemon, missions, and workstreams | `daemon-session.ts`, `mission.ts`, `start-workstream.ts` |
1398+
| Factory REST API | `rest-api.ts` |
1399+
| Observability | `observability.ts` |
13751400

13761401
Start a mission in a test project and print orchestrator and worker progress.
13771402
`interactionMode: DroidInteractionMode.Mission` alone does not give the session

‎examples/node/rest-api.ts‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Factory REST API example.
3+
*
4+
* Lists the Computers and remote sessions an API key can see, using the
5+
* client generated from the public Factory API spec. Listing sessions works
6+
* only for organizations that have that feature enabled.
7+
*
8+
* These operations take `{ client }` from `createFactoryClient({ apiKey, baseUrl })`
9+
* and resolve `{ data, error }`. The root `@factory/droid-sdk` REST helpers
10+
* take `{ apiKey, baseUrl }` and resolve the response body. Several names
11+
* exist on both with different contracts, so a file that imports both should
12+
* alias the shared names or import this entry under a namespace. A root
13+
* options object cannot be passed here: generated operations require a
14+
* `client` created with `createFactoryClient`.
15+
*
16+
* Usage:
17+
* FACTORY_API_KEY=... npx tsx examples/node/rest-api.ts [baseUrl]
18+
*/
19+
20+
import {
21+
createFactoryClient,
22+
listComputers,
23+
listSessions,
24+
} from '@factory/droid-sdk/api';
25+
26+
const apiKey = process.env.FACTORY_API_KEY;
27+
if (!apiKey) {
28+
throw new Error('Set FACTORY_API_KEY.');
29+
}
30+
31+
const client = createFactoryClient({
32+
apiKey,
33+
baseUrl: process.argv[2],
34+
});
35+
36+
const computers = await listComputers({ client });
37+
if (computers.error !== undefined) {
38+
throw new Error(
39+
`Listing Computers failed: ${JSON.stringify(computers.error)}`
40+
);
41+
}
42+
console.log(`Computers (${computers.data.computers.length}):`);
43+
for (const computer of computers.data.computers) {
44+
console.log(` ${computer.id} ${computer.name} ${computer.status ?? ''}`);
45+
}
46+
47+
const sessions = await listSessions({ client, query: { limit: 5 } });
48+
if (sessions.error !== undefined) {
49+
throw new Error(`Listing sessions failed: ${JSON.stringify(sessions.error)}`);
50+
}
51+
console.log(`Recent sessions (${sessions.data.sessions.length}):`);
52+
for (const session of sessions.data.sessions) {
53+
console.log(
54+
` ${session.sessionId} ${session.status} ${session.messageCount} messages`
55+
);
56+
}

‎examples/node/start-workstream.ts‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* Start a workstream on a running daemon and leave it running.
3+
*
4+
* The orchestrator plans the goal and runs agents in the daemon, which keeps
5+
* the workstream going after this script exits. Without an `askUserHandler`,
6+
* any question the orchestrator asks is declined (see ask-user-elicitation.ts).
7+
* An agent's questions and permission prompts are answered only by a client
8+
* that attaches that agent with handlers (`droid.sessions.resume(agentId, ...)`).
9+
*
10+
* Set DROID_DAEMON_URL and FACTORY_API_KEY for an existing daemon whose account
11+
* has access to workstreams. Set DROID_WORKSTREAM_COMPUTER_ID to let agents also run
12+
* on that computer instead of only on this daemon's machine.
13+
* Usage: npx tsx examples/node/start-workstream.ts "<goal>" [cwd]
14+
*/
15+
16+
import {
17+
AutonomyLevel,
18+
DroidMessageType,
19+
ReasoningEffort,
20+
WorkstreamMachineTargetKind,
21+
connectToDaemon,
22+
} from '@factory/droid-sdk';
23+
24+
const url = process.env.DROID_DAEMON_URL;
25+
const apiKey = process.env.FACTORY_API_KEY;
26+
const computerId = process.env.DROID_WORKSTREAM_COMPUTER_ID;
27+
if (!url || !apiKey) {
28+
throw new Error('Set DROID_DAEMON_URL and FACTORY_API_KEY.');
29+
}
30+
31+
const [goal, cwd = process.cwd()] = process.argv.slice(2);
32+
if (!goal) {
33+
throw new Error('Pass the workstream goal as the first argument.');
34+
}
35+
36+
const droid = await connectToDaemon({ url, auth: { apiKey } });
37+
try {
38+
// Agents on another machine reach this daemon through its relay.
39+
if (computerId) await droid.relay.start();
40+
const orchestrator = await droid.unstable.workstreams.start({
41+
cwd,
42+
title: goal.slice(0, 80),
43+
// Agents inherit the orchestrator's autonomy; below High they stop to ask.
44+
autonomyLevel: AutonomyLevel.High,
45+
agentReasoningEffort: ReasoningEffort.High,
46+
...(computerId
47+
? {
48+
machines: [
49+
{
50+
label: 'remote',
51+
target: {
52+
kind: WorkstreamMachineTargetKind.Computer,
53+
computerId,
54+
},
55+
},
56+
],
57+
defaultMachineLabel: 'remote',
58+
}
59+
: {}),
60+
});
61+
console.log(`Workstream ${orchestrator.id} started.`);
62+
63+
for await (const msg of orchestrator.stream(goal)) {
64+
if (msg.type === DroidMessageType.Assistant) {
65+
process.stdout.write(msg.text);
66+
} else if (msg.type === DroidMessageType.Result && !msg.success) {
67+
throw new Error(msg.error?.message ?? `Turn ended: ${msg.subtype}`);
68+
}
69+
}
70+
71+
// Detach, not close: closing would end the workstream in the daemon.
72+
await orchestrator.detach();
73+
console.log(`\nWorkstream ${orchestrator.id} keeps running in the daemon.`);
74+
} finally {
75+
droid.disconnect();
76+
}

0 commit comments

Comments
 (0)