@jush-agent/sdk 0.2.6250 → 0.2.6254
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 +87 -0
- package/dist/index.d.mts +759 -140
- package/dist/index.mjs +380 -203
- package/package.json +7 -7
- package/release/commands/jush-browser/descriptor.json +13 -13
- package/release/commands/jush-claude-code/descriptor.json +13 -13
- package/release/commands/jush-fetch/descriptor.json +13 -13
- package/release/commands/jush-file/descriptor.json +10 -10
- package/release/commands/jush-mobile/descriptor.json +13 -13
package/README.md
CHANGED
|
@@ -216,6 +216,55 @@ for (const listed of core.state.devices) {
|
|
|
216
216
|
}
|
|
217
217
|
```
|
|
218
218
|
|
|
219
|
+
### Scripts outside a conversation
|
|
220
|
+
|
|
221
|
+
`device.exec(script, options)` runs a script on a paired device as the agent's
|
|
222
|
+
shell runs a command, for work that is no conversation's, such as a filter a
|
|
223
|
+
chat message goes through before the agent hears of it. No transcript holds
|
|
224
|
+
it, and no model reads it:
|
|
225
|
+
|
|
226
|
+
```ts
|
|
227
|
+
const { exitCode, stdout } = await device.exec('bun filter.js', {
|
|
228
|
+
cwd: '/work/filters/release-notes',
|
|
229
|
+
env: { CHAT_TOKEN: token },
|
|
230
|
+
stdin: JSON.stringify(event),
|
|
231
|
+
timeout: 10_000,
|
|
232
|
+
})
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
- It starts in `cwd`, the home directory of the device's runner by default,
|
|
236
|
+
with `env` above the device's environment; `env` reaches the script's
|
|
237
|
+
process and no file on the device.
|
|
238
|
+
- It resolves once the script exited, whatever its status, with its
|
|
239
|
+
`exitCode`, `stdout` and `stderr` read as UTF-8. A device keeps 16 MiB of a
|
|
240
|
+
script's output and leaves out the middle of more, and a read of it that
|
|
241
|
+
failed keeps only its first and newest bytes; `leftOutBytes` counts what is
|
|
242
|
+
missing.
|
|
243
|
+
- Each run is a job of its own, so runs on one device go side by side.
|
|
244
|
+
- The request, the script and `stdin` with it, is JSON of at most 1 MiB.
|
|
245
|
+
- A device whose runner drops keeps running the script, and the result comes
|
|
246
|
+
once the runner is back. `timeout`, in milliseconds, bounds the wait; 0, the
|
|
247
|
+
default, sets no limit. A script past its time gets `SIGTERM`, and
|
|
248
|
+
`SIGKILL` 5 seconds later if it is still running.
|
|
249
|
+
- A runner that ends, or whose connection breaks, after the core sent it the
|
|
250
|
+
whole of `stdin` but before the script read all of it, loses the rest: the
|
|
251
|
+
script reads the input's end there, as a program whose `ssh` client went
|
|
252
|
+
does.
|
|
253
|
+
- `signal` stops the script, and the promise rejects with its reason, as a
|
|
254
|
+
`fetch`'s does. The end of your program's connection to the core stops it
|
|
255
|
+
too.
|
|
256
|
+
|
|
257
|
+
It rejects with a `JushError` only when the script has no exit status:
|
|
258
|
+
|
|
259
|
+
- `device_offline`: the runner was not connected, and the script never ran.
|
|
260
|
+
- `command_timed_out`: it ran past `timeout` and was stopped; what it printed
|
|
261
|
+
is in `error.body.output`.
|
|
262
|
+
- `device_lost`: the device lost it; its runner was away when it was to be
|
|
263
|
+
stopped; or the runner's connection broke before the core sent it the
|
|
264
|
+
whole of `stdin`.
|
|
265
|
+
- `backend_closing`: the core closed while it ran. The device stops the
|
|
266
|
+
script when it connects to the core again.
|
|
267
|
+
|
|
219
268
|
`device.revoke()` revokes a device, as the app's Revoke does: its token opens
|
|
220
269
|
nothing from then on, the commands running on it are lost, and the commands of
|
|
221
270
|
a conversation whose target it is fail until `update({ target })` names
|
|
@@ -363,6 +412,44 @@ if (tester) {
|
|
|
363
412
|
}
|
|
364
413
|
```
|
|
365
414
|
|
|
415
|
+
## Schedules
|
|
416
|
+
|
|
417
|
+
A schedule wakes its conversation with a message: at set times, when a
|
|
418
|
+
command's output changes, when its URL is called, or when another
|
|
419
|
+
conversation finishes. The conversation's agent makes one with
|
|
420
|
+
`jush schedule`; your program makes, changes, runs and removes any
|
|
421
|
+
conversation's schedules with `conversation.schedules`, which takes the same
|
|
422
|
+
fields:
|
|
423
|
+
|
|
424
|
+
```ts
|
|
425
|
+
const { schedule } = await conversation.schedules.create({
|
|
426
|
+
name: 'Daily report',
|
|
427
|
+
trigger: { kind: 'time', timing: { kind: 'cron', expression: '0 10 * * 1-5' } },
|
|
428
|
+
timeZone: 'America/New_York',
|
|
429
|
+
prompt: 'Post the daily report.',
|
|
430
|
+
})
|
|
431
|
+
await conversation.schedules.update(schedule.id, { paused: true })
|
|
432
|
+
await conversation.schedules.run(schedule.id)
|
|
433
|
+
const runs = await conversation.schedules.runs(schedule.id)
|
|
434
|
+
await conversation.schedules.remove(schedule.id)
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
A new schedule starts from the defaults of `jush schedule create`, every day
|
|
438
|
+
at 09:00, and is on unless the patch says `paused: true`. `create` and
|
|
439
|
+
`update` answer the schedule with `secret`, a URL trigger's secret when the
|
|
440
|
+
call made one, and null otherwise: it is the only time the secret is shown.
|
|
441
|
+
|
|
442
|
+
`runs(id, before?)` answers 50 runs at most, newest first; pass the last
|
|
443
|
+
one's id as `before` for the 50 before it. Each run says what fired it
|
|
444
|
+
(`cause`) and the turn its message started (`turn`), whose id is the
|
|
445
|
+
message's: null until the message goes, such as in the answer of `run`,
|
|
446
|
+
and for a run skipped before it went. A schedule's `createdIn` and
|
|
447
|
+
`editedIn` name the agent's turn that made it and that last changed what it
|
|
448
|
+
does; both are null when your program did.
|
|
449
|
+
|
|
450
|
+
Each conversation in `core.state` lists its schedules with their next time
|
|
451
|
+
and last run, and `core.on('state')` hears of each change and each run.
|
|
452
|
+
|
|
366
453
|
## Permission requests
|
|
367
454
|
|
|
368
455
|
A command that acts on Jush itself, such as `jush credentials`, which hands
|