@jush-agent/sdk 0.2.6342 → 0.2.6368

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 CHANGED
@@ -386,16 +386,19 @@ turn it starts ended, with that turn's blocks and outcome, also when your
386
386
  program's connection to the process dropped while the turn ended. It fails
387
387
  when the message leaves the queue without running, as an abort that clears
388
388
  the queue or gives the message back makes it, or when the conversation
389
- closes first. `options.senderId` names who sent the message, by your own
390
- id, such as a person of a team's chat: the message's `user` block keeps it
391
- as `senderId`, so a page can show who wrote what, the model does not read
392
- it, and [Usage](#usage) says what it counts. The other actions are the ones
393
- the app has:
389
+ closes first. `options.labels` are your own key-value pairs for the
390
+ message, such as `{ sender: 'alex', scene: 'review' }`: the message's `user`
391
+ block keeps them as `labels`, so a page can show who wrote what, the model
392
+ does not read them, and [Usage](#usage) says what they count. At most 16; a
393
+ key is 1 to 64 letters, digits, `.`, `_` and `-`, the first a letter or a
394
+ digit, and a value 1 to 512 characters. `options.assignmentId` names the
395
+ earlier work the message continues ([Usage](#usage)). The other actions are
396
+ the ones the app has:
394
397
 
395
398
  | Method | What it does |
396
399
  | --- | --- |
397
- | `send(input, messageId?, options?)` | Sends a message, queued behind a running turn; resolves once the conversation holds it; `options.senderId` as `run` takes it |
398
- | `steer(input, steerId?, options?)` | Hands a message to the running turn; resolves once the turn took it; `options.senderId` as `run` takes it |
400
+ | `send(input, messageId?, options?)` | Sends a message, queued behind a running turn; resolves once the conversation holds it; `options` as `run` takes them |
401
+ | `steer(input, steerId?, options?)` | Hands a message to the running turn; resolves once the turn took it; `options` as `run` takes them |
399
402
  | `abort()` | Stops the running turn |
400
403
  | `retry()` | Runs the latest turn again from your message |
401
404
  | `resume()` | Finishes a turn that did not finish |
@@ -511,7 +514,8 @@ to one subagent, named by its id in `conversation.agents`. A subagent at work
511
514
  takes it as a steer, an idle one starts a turn with it, and one that ended is
512
515
  resumed with it. Give the message an id when you may send it again, such as
513
516
  after a lost answer: the subagent takes a message once, however often it
514
- arrives. `options.senderId` names who sent it, as `run` takes it.
517
+ arrives. `options` names its labels and the work it continues, as `run`
518
+ takes them.
515
519
 
516
520
  ```ts
517
521
  const tester = conversation.agents.find((agent) => agent.role.kind === 'subagent' && agent.role.profile === 'tester')
@@ -671,6 +675,39 @@ for one, and then fails, telling the agent that the plugin's program is
671
675
  unreachable. A `context` call does not wait: when your program stops
672
676
  during one, the agent goes on without its block.
673
677
 
678
+ ### Versions
679
+
680
+ Several builds of your program can serve its plugins at once, such as a
681
+ production node and a canary node connected to one process, each
682
+ conversation running on one of them. A connection with `pluginVersion`
683
+ declares its plugins as that version; one without it, as their current
684
+ versions:
685
+
686
+ ```ts
687
+ // The canary node.
688
+ const jush = await Jush.connect({ url, token, plugins: [acme], pluginVersion: 'canary-1126' })
689
+
690
+ // A conversation moves to the canary, and back to the current versions.
691
+ await conversation.update({ pluginVersions: { acme: 'canary-1126' } })
692
+ await conversation.update({ pluginVersions: {} })
693
+ ```
694
+
695
+ A conversation's agents run the commands of the version it names of the
696
+ plugin, with their `--help`, the index of its system prompt and its
697
+ context; a plugin it names none of runs on its current version. Everything
698
+ else of a plugin is its current version's: what it keeps of a conversation
699
+ as it is forked or deleted, a project's search, and its sign-ins. A core's
700
+ notifications go to a connection of the current versions while one is
701
+ open. A change of `pluginVersions` gives its agents their commands at
702
+ once; a command already running goes on where it is. The core refuses
703
+ versions whose commands take a name another plugin's take, and a version
704
+ of a plugin of its own. A version no connection declares leaves the
705
+ conversation without that plugin's commands, and while no connection of a
706
+ version is open, its commands wait 10 seconds and fail, as above. A
707
+ plugin's store, secrets and sign-ins, and the user's switches of it, are
708
+ the plugin's, whichever version reads them. A process of a release before
709
+ versions refuses a connection with `pluginVersion`.
710
+
674
711
  ## Product state and notifications
675
712
 
676
713
  `core.state` is the core's product state: its workspaces, projects, provider
@@ -700,9 +737,10 @@ conversation already.
700
737
 
701
738
  ## Usage
702
739
 
703
- `core.usage.report` sums the calls of a period by hour or by day of a time
704
- zone, grouped by any of `conversation`, `sender`, `model`, `provider`,
705
- `account`, `turn` and `purpose`:
740
+ `core.usage.report` sums the calls of a period by minute, hour or day of a
741
+ time zone, grouped by any of `conversation`, `agent`, `model`, `provider`,
742
+ `account`, `turn`, `assignment` and `purpose`, and by the labels your
743
+ messages carry, each as `label:<key>`:
706
744
 
707
745
  ```ts
708
746
  const report = await core.usage.report({
@@ -710,15 +748,18 @@ const report = await core.usage.report({
710
748
  to: new Date('2026-12-01T00:00:00+08:00'),
711
749
  bucket: 'day',
712
750
  timeZone: 'Asia/Shanghai',
713
- groupBy: ['conversation', 'sender', 'model'],
751
+ groupBy: ['conversation', 'label:sender', 'model'],
714
752
  })
715
753
  for (const bucket of report.buckets) {
716
754
  for (const group of bucket.groups) {
717
- console.log(bucket.start, group.sender, group.model, group.calls, group.cost.usd, group.apiPrice)
755
+ console.log(bucket.start, group.labels?.sender, group.model, group.calls, group.cost.usd, group.apiPrice)
718
756
  }
719
757
  }
720
758
  ```
721
759
 
760
+ A group names the value of each label it is grouped by in `labels`, null
761
+ for calls without it, such as `{ sender: 'alex' }` or `{ sender: null }`.
762
+ Jush gives a label no meaning: group by as many as your program counts by.
722
763
  A group counts its calls and their tokens, `cost` is what the vendors said
723
764
  the calls cost, by currency and never converted, and `apiPrice` what their
724
765
  tokens would cost on the vendors' APIs in dollars, leaving out the
@@ -727,28 +768,137 @@ made calls, and a period without calls has no bucket; the first and the last
727
768
  bucket start and end with the period, so two reports of adjoining periods
728
769
  never hold the same bucket.
729
770
 
730
- A call's sender is that of the latest message that handed its agent work,
731
- by the `senderId` your program sent it with: a message, a steer, a side
732
- question, or another agent's message; or that of the work whose end opened
733
- its turn.
734
-
735
- - Alice's message starts a turn: the turn's calls are Alice's, and so are
736
- those of the turn that continues once a command it started ends.
737
- - A subagent the agent starts while working for Alice works for Alice,
738
- and its calls and those of the commands it runs are hers. So is the work
739
- of a subagent or a conversation the agent sends a message to then.
740
- - Bob steers the running turn: the calls after the agent read his steer
741
- are Bob's.
742
- - A turn that work for Alice wakes once it ends is Alice's, even after
743
- Bob's message: a command started in her turn, a subagent working for
744
- her, or another conversation her turn sent a message to with
771
+ `conversations` keeps the calls of the conversations it names, and
772
+ `agents` those of the agents of them it names; an empty list keeps none.
773
+ An agent is the number its conversation knows it by: 0 for the main agent,
774
+ and a subagent's `number` in `conversation.agents`, whose `parent` names
775
+ the agent that started it, once the conversation is open
776
+ (`await conversation.open()`). To count what a subagent did, name it and
777
+ the subagents below it; a call in a minute bucket falls in the minute it
778
+ ended:
779
+
780
+ ```ts
781
+ // Agent 3 and every subagent below it, by number.
782
+ const agents = conversation.agents
783
+ const below = (parent: string): number[] => agents.flatMap((each) =>
784
+ each.role.kind === 'subagent' && each.role.parent === parent ? [each.role.number, ...below(each.id)] : [])
785
+ const reviewer = agents.find((each) => each.role.kind === 'subagent' && each.role.number === 3)!
786
+ const review = await core.usage.report({
787
+ from: startedAt,
788
+ to: new Date(),
789
+ bucket: 'minute',
790
+ conversations: [conversation.id],
791
+ agents: [3, ...below(reviewer.id)],
792
+ groupBy: ['agent', 'model'],
793
+ })
794
+ ```
795
+
796
+ `agent` is null for a side question's call and for one no agent made, such
797
+ as a title's, and `agents` keeps neither.
798
+
799
+ A call carries the labels of the latest message that handed its agent
800
+ work: a message, a steer, a side question, or another agent's message; or
801
+ those of the work whose end opened its turn.
802
+
803
+ - A message labeled `{ sender: 'alice' }` starts a turn: the turn's calls
804
+ carry its labels, and so do those of the turn that continues once a
805
+ command it started ends.
806
+ - A subagent the agent starts during that work carries Alice's labels, and
807
+ so do its calls and the commands it runs. So does the work of a subagent
808
+ or a conversation the agent sends a message to then.
809
+ - A steer labeled `{ sender: 'bob' }` reaches the running turn: the calls
810
+ after the agent read it carry Bob's labels, in place of Alice's rather
811
+ than merged with them, so a `scene` Alice's message named is gone. A
812
+ steer that names no labels leaves the calls after it none.
813
+ - A turn that Alice's work wakes once it ends carries her labels, even
814
+ after Bob's message: a command started in her turn, a subagent of her
815
+ work, or another conversation her turn sent a message to with
745
816
  `--wake-when-done`. What ends while Bob's turn runs joins that turn,
746
- which stays Bob's.
817
+ which keeps Bob's.
818
+ - A schedule the agent makes during Alice's work runs with her labels.
819
+
820
+ After a message that names no labels, as one from the app or from a
821
+ schedule your program or the user made, the calls carry none, and neither
822
+ does a turn that the end of work it started opens. Nor do the calls
823
+ outside an agent's work, such as a title's or the suggested replies after
824
+ a turn.
825
+
826
+ A call's `assignment` is the id of the message that handed its agent the
827
+ work: the id you sent the message under, a side question's or its
828
+ follow-up's (`sideQuestions.followUp(side, input, messageId)`), or a
829
+ schedule run's `turn`. The turns that continue that work share it, as they
830
+ share its labels: those a background command's end, a subagent's end or
831
+ another conversation's end opens, a retry, a resume or a compaction, and
832
+ the runs of a schedule the agent made then. A steer joins the running
833
+ turn's assignment. What continues work that names no assignment, such as
834
+ work begun before assignments were kept, names none either. So a report
835
+ grouped by `assignment` sums each piece of work, and a program that names
836
+ its messages by what started them, such as `listener:ops-alerts:8812`,
837
+ sums the cost of each kind:
838
+
839
+ ```ts
840
+ await conversation.send('Summarize the incident', 'listener:ops-alerts:8812')
841
+ const report = await core.usage.report({ from, to, bucket: 'day', timeZone: 'Asia/Shanghai', groupBy: ['conversation', 'assignment', 'model'] })
842
+ ```
843
+
844
+ A message your program sends to continue earlier work names that work's
845
+ assignment with `assignmentId`, and its labels with `labels`. A plugin's
846
+ command call names the assignment and the labels of the work it was part
847
+ of; a program that follows something for the conversation keeps them, and
848
+ wakes it within that work:
849
+
850
+ ```ts
851
+ // In the command that starts following a merge request.
852
+ const caller = call.invocation.caller
853
+ // Hours later, as a commit lands.
854
+ await conversation.send('A commit landed on !42; review it again.', 'acme:review-42:3', {
855
+ labels: caller?.labels,
856
+ assignmentId: caller?.assignmentId,
857
+ })
858
+ ```
859
+
860
+ The turn it opens, its commands and the work that continues it are counted
861
+ in that assignment, in `usage.report` and in `commands.history`. A steer the
862
+ running turn reads joins that turn's whatever it names, and so does a
863
+ message to a running subagent.
864
+
865
+ ## Commands your agents ran
866
+
867
+ `core.commands.history` reads the core's command history, in the order its
868
+ rows were written, which is the order their commands ended. Each command
869
+ an agent's `shell` call started has a row once it ends, however long after
870
+ the call: it exited with its code, was stopped, or was lost. A call that
871
+ returned an error before its command started, such as one that named a
872
+ device that is offline, has a row too, `not_started` with the error.
873
+
874
+ ```ts
875
+ let page = await core.commands.history({ from: new Date(Date.now() - 30 * 86_400_000), limit: 500 })
876
+ for (const command of page.commands) {
877
+ // command.conversation, command.agent (0 for the main agent, null for a
878
+ // side question), command.command, command.device, command.turn,
879
+ // command.labels, command.assignment, command.title, command.script,
880
+ // command.startedAt (a wait for its device included), command.endedAt,
881
+ // and command.end:
882
+ // { kind: 'exited', exitCode } | { kind: 'stopped' } | { kind: 'lost', reason } | { kind: 'not_started', reason }
883
+ }
884
+ // Later, from where the last page ended:
885
+ page = await core.commands.history({ after: page.next })
886
+ ```
747
887
 
748
- After a message that names no sender, as one from the app or from a
749
- schedule, the calls have a null sender, and so does a turn that the end of
750
- work it started opens. So do the calls outside an agent's work, such as a
751
- title's or the suggested replies after a turn.
888
+ `after` reads on after a page's `next`; `from` starts at the first row
889
+ written of those that ended at or after a moment; with neither, the first
890
+ row. A page holds `limit` rows, 1 to 1,000 and 100 by default, and `more`
891
+ says rows wait after it. `next` is always where to read on from, also for
892
+ an empty page, so a reader that keeps it and follows it reads each row
893
+ once, also rows written while it reads. It is opaque: keep it as it is. A
894
+ cursor past every row this core's history wrote, such as one of another
895
+ core, is refused.
896
+
897
+ A row can be read a moment before `conversation.history.commandOutput` has
898
+ its command's output. A conversation's deletion removes its rows, which
899
+ hold its scripts. Commands that ended before the core kept the history
900
+ have none, and so do `device.exec` and a schedule's watch command, which
901
+ no agent ran.
752
902
 
753
903
  ## Everything else a core does
754
904
 
@@ -777,6 +927,7 @@ const token = await core.credentials.create({
777
927
  | `conversation.plugins` | `state(plugin)`, `call(plugin, method, input)` |
778
928
  | `core` | `search(text)`, `blob(sha256)`, `upload` |
779
929
  | `core.usage` | `totals()`, `report(options)` |
930
+ | `core.commands` | `history(options)` |
780
931
  | `core.models` | `search(text)`, `refresh()` |
781
932
  | `core.providers` | `list`, `create`, `update`, `remove`, `catalog`, `order`, `status`, `quota`, `test`, `cli`, `installCli`, `accounts(id)`, `signIn` |
782
933
  | `core.credentials` | `list`, `create`, `update`, `remove`, `reveal(id, field)` |