@jush-agent/sdk 0.2.6342 → 0.2.6346
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 +126 -6
- package/dist/index.d.mts +224 -8
- package/dist/index.mjs +176 -18
- package/package.json +7 -7
- package/release/commands/jush-browser/descriptor.json +13 -13
- package/release/commands/jush-fetch/descriptor.json +12 -12
- package/release/commands/jush-file/descriptor.json +12 -12
- package/release/commands/jush-mobile/descriptor.json +13 -13
- package/release/commands/jush-subscription-cli/descriptor.json +13 -13
package/README.md
CHANGED
|
@@ -671,6 +671,39 @@ for one, and then fails, telling the agent that the plugin's program is
|
|
|
671
671
|
unreachable. A `context` call does not wait: when your program stops
|
|
672
672
|
during one, the agent goes on without its block.
|
|
673
673
|
|
|
674
|
+
### Versions
|
|
675
|
+
|
|
676
|
+
Several builds of your program can serve its plugins at once, such as a
|
|
677
|
+
production node and a canary node connected to one process, each
|
|
678
|
+
conversation running on one of them. A connection with `pluginVersion`
|
|
679
|
+
declares its plugins as that version; one without it, as their current
|
|
680
|
+
versions:
|
|
681
|
+
|
|
682
|
+
```ts
|
|
683
|
+
// The canary node.
|
|
684
|
+
const jush = await Jush.connect({ url, token, plugins: [acme], pluginVersion: 'canary-1126' })
|
|
685
|
+
|
|
686
|
+
// A conversation moves to the canary, and back to the current versions.
|
|
687
|
+
await conversation.update({ pluginVersions: { acme: 'canary-1126' } })
|
|
688
|
+
await conversation.update({ pluginVersions: {} })
|
|
689
|
+
```
|
|
690
|
+
|
|
691
|
+
A conversation's agents run the commands of the version it names of the
|
|
692
|
+
plugin, with their `--help`, the index of its system prompt and its
|
|
693
|
+
context; a plugin it names none of runs on its current version. Everything
|
|
694
|
+
else of a plugin is its current version's: what it keeps of a conversation
|
|
695
|
+
as it is forked or deleted, a project's search, and its sign-ins. A core's
|
|
696
|
+
notifications go to a connection of the current versions while one is
|
|
697
|
+
open. A change of `pluginVersions` gives its agents their commands at
|
|
698
|
+
once; a command already running goes on where it is. The core refuses
|
|
699
|
+
versions whose commands take a name another plugin's take, and a version
|
|
700
|
+
of a plugin of its own. A version no connection declares leaves the
|
|
701
|
+
conversation without that plugin's commands, and while no connection of a
|
|
702
|
+
version is open, its commands wait 10 seconds and fail, as above. A
|
|
703
|
+
plugin's store, secrets and sign-ins, and the user's switches of it, are
|
|
704
|
+
the plugin's, whichever version reads them. A process of a release before
|
|
705
|
+
versions refuses a connection with `pluginVersion`.
|
|
706
|
+
|
|
674
707
|
## Product state and notifications
|
|
675
708
|
|
|
676
709
|
`core.state` is the core's product state: its workspaces, projects, provider
|
|
@@ -700,9 +733,9 @@ conversation already.
|
|
|
700
733
|
|
|
701
734
|
## Usage
|
|
702
735
|
|
|
703
|
-
`core.usage.report` sums the calls of a period by hour or
|
|
704
|
-
zone, grouped by any of `conversation`, `
|
|
705
|
-
`account`, `turn` and `purpose`:
|
|
736
|
+
`core.usage.report` sums the calls of a period by minute, hour or day of a
|
|
737
|
+
time zone, grouped by any of `conversation`, `agent`, `sender`, `model`,
|
|
738
|
+
`provider`, `account`, `turn`, `assignment` and `purpose`:
|
|
706
739
|
|
|
707
740
|
```ts
|
|
708
741
|
const report = await core.usage.report({
|
|
@@ -727,6 +760,34 @@ made calls, and a period without calls has no bucket; the first and the last
|
|
|
727
760
|
bucket start and end with the period, so two reports of adjoining periods
|
|
728
761
|
never hold the same bucket.
|
|
729
762
|
|
|
763
|
+
`conversations` keeps the calls of the conversations it names, and
|
|
764
|
+
`agents` those of the agents of them it names; an empty list keeps none.
|
|
765
|
+
An agent is the number its conversation knows it by: 0 for the main agent,
|
|
766
|
+
and a subagent's `number` in `conversation.agents`, whose `parent` names
|
|
767
|
+
the agent that started it, once the conversation is open
|
|
768
|
+
(`await conversation.open()`). To count what a subagent did, name it and
|
|
769
|
+
the subagents below it; a call in a minute bucket falls in the minute it
|
|
770
|
+
ended:
|
|
771
|
+
|
|
772
|
+
```ts
|
|
773
|
+
// Agent 3 and every subagent below it, by number.
|
|
774
|
+
const agents = conversation.agents
|
|
775
|
+
const below = (parent: string): number[] => agents.flatMap((each) =>
|
|
776
|
+
each.role.kind === 'subagent' && each.role.parent === parent ? [each.role.number, ...below(each.id)] : [])
|
|
777
|
+
const reviewer = agents.find((each) => each.role.kind === 'subagent' && each.role.number === 3)!
|
|
778
|
+
const review = await core.usage.report({
|
|
779
|
+
from: startedAt,
|
|
780
|
+
to: new Date(),
|
|
781
|
+
bucket: 'minute',
|
|
782
|
+
conversations: [conversation.id],
|
|
783
|
+
agents: [3, ...below(reviewer.id)],
|
|
784
|
+
groupBy: ['agent', 'model'],
|
|
785
|
+
})
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
`agent` is null for a side question's call and for one no agent made, such
|
|
789
|
+
as a title's, and `agents` keeps neither.
|
|
790
|
+
|
|
730
791
|
A call's sender is that of the latest message that handed its agent work,
|
|
731
792
|
by the `senderId` your program sent it with: a message, a steer, a side
|
|
732
793
|
question, or another agent's message; or that of the work whose end opened
|
|
@@ -744,11 +805,69 @@ its turn.
|
|
|
744
805
|
her, or another conversation her turn sent a message to with
|
|
745
806
|
`--wake-when-done`. What ends while Bob's turn runs joins that turn,
|
|
746
807
|
which stays Bob's.
|
|
808
|
+
- A schedule the agent makes while working for Alice runs for Alice.
|
|
747
809
|
|
|
748
810
|
After a message that names no sender, as one from the app or from a
|
|
749
|
-
schedule, the calls have a null sender, and
|
|
750
|
-
work it started opens. So do the calls
|
|
751
|
-
title's or the suggested replies after
|
|
811
|
+
schedule your program or the user made, the calls have a null sender, and
|
|
812
|
+
so does a turn that the end of work it started opens. So do the calls
|
|
813
|
+
outside an agent's work, such as a title's or the suggested replies after
|
|
814
|
+
a turn.
|
|
815
|
+
|
|
816
|
+
A call's `assignment` is the id of the message that handed its agent the
|
|
817
|
+
work: the id you sent the message under, a side question's or its
|
|
818
|
+
follow-up's (`sideQuestions.followUp(side, input, messageId)`), or a
|
|
819
|
+
schedule run's `turn`. The turns that continue that work share it, as they
|
|
820
|
+
share its sender: those a background command's end, a subagent's end or
|
|
821
|
+
another conversation's end opens, a retry, a resume or a compaction, and
|
|
822
|
+
the runs of a schedule the agent made then. A steer joins the running
|
|
823
|
+
turn's assignment. What continues work that names no assignment, such as
|
|
824
|
+
work begun before assignments were kept, names none either. So a report
|
|
825
|
+
grouped by `assignment` sums each piece of work, and a program that names
|
|
826
|
+
its messages by what started them, such as `listener:ops-alerts:8812`,
|
|
827
|
+
sums the cost of each kind:
|
|
828
|
+
|
|
829
|
+
```ts
|
|
830
|
+
await conversation.send('Summarize the incident', 'listener:ops-alerts:8812')
|
|
831
|
+
const report = await core.usage.report({ from, to, bucket: 'day', timeZone: 'Asia/Shanghai', groupBy: ['conversation', 'assignment', 'model'] })
|
|
832
|
+
```
|
|
833
|
+
|
|
834
|
+
## Commands your agents ran
|
|
835
|
+
|
|
836
|
+
`core.commands.history` reads the core's command history, in the order its
|
|
837
|
+
rows were written, which is the order their commands ended. Each command
|
|
838
|
+
an agent's `shell` call started has a row once it ends, however long after
|
|
839
|
+
the call: it exited with its code, was stopped, or was lost. A call that
|
|
840
|
+
returned an error before its command started, such as one that named a
|
|
841
|
+
device that is offline, has a row too, `not_started` with the error.
|
|
842
|
+
|
|
843
|
+
```ts
|
|
844
|
+
let page = await core.commands.history({ from: new Date(Date.now() - 30 * 86_400_000), limit: 500 })
|
|
845
|
+
for (const command of page.commands) {
|
|
846
|
+
// command.conversation, command.agent (0 for the main agent, null for a
|
|
847
|
+
// side question), command.command, command.device, command.turn,
|
|
848
|
+
// command.sender, command.assignment, command.title, command.script,
|
|
849
|
+
// command.startedAt (a wait for its device included), command.endedAt,
|
|
850
|
+
// and command.end:
|
|
851
|
+
// { kind: 'exited', exitCode } | { kind: 'stopped' } | { kind: 'lost', reason } | { kind: 'not_started', reason }
|
|
852
|
+
}
|
|
853
|
+
// Later, from where the last page ended:
|
|
854
|
+
page = await core.commands.history({ after: page.next })
|
|
855
|
+
```
|
|
856
|
+
|
|
857
|
+
`after` reads on after a page's `next`; `from` starts at the first row
|
|
858
|
+
written of those that ended at or after a moment; with neither, the first
|
|
859
|
+
row. A page holds `limit` rows, 1 to 1,000 and 100 by default, and `more`
|
|
860
|
+
says rows wait after it. `next` is always where to read on from, also for
|
|
861
|
+
an empty page, so a reader that keeps it and follows it reads each row
|
|
862
|
+
once, also rows written while it reads. It is opaque: keep it as it is. A
|
|
863
|
+
cursor past every row this core's history wrote, such as one of another
|
|
864
|
+
core, is refused.
|
|
865
|
+
|
|
866
|
+
A row can be read a moment before `conversation.history.commandOutput` has
|
|
867
|
+
its command's output. A conversation's deletion removes its rows, which
|
|
868
|
+
hold its scripts. Commands that ended before the core kept the history
|
|
869
|
+
have none, and so do `device.exec` and a schedule's watch command, which
|
|
870
|
+
no agent ran.
|
|
752
871
|
|
|
753
872
|
## Everything else a core does
|
|
754
873
|
|
|
@@ -777,6 +896,7 @@ const token = await core.credentials.create({
|
|
|
777
896
|
| `conversation.plugins` | `state(plugin)`, `call(plugin, method, input)` |
|
|
778
897
|
| `core` | `search(text)`, `blob(sha256)`, `upload` |
|
|
779
898
|
| `core.usage` | `totals()`, `report(options)` |
|
|
899
|
+
| `core.commands` | `history(options)` |
|
|
780
900
|
| `core.models` | `search(text)`, `refresh()` |
|
|
781
901
|
| `core.providers` | `list`, `create`, `update`, `remove`, `catalog`, `order`, `status`, `quota`, `test`, `cli`, `installCli`, `accounts(id)`, `signIn` |
|
|
782
902
|
| `core.credentials` | `list`, `create`, `update`, `remove`, `reveal(id, field)` |
|