@parallelworks/code 0.4.0 → 0.6.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.
- package/README.md +92 -24
- package/dist/agentSwitcher.d.ts +13 -2
- package/dist/agentSwitcher.js +28 -6
- package/dist/ago.d.ts +1 -3
- package/dist/ago.js +1 -3
- package/dist/api.d.ts +267 -5
- package/dist/chatStrings.d.ts +4 -0
- package/dist/chatStrings.js +5 -1
- package/dist/claudeAccounts.d.ts +20 -2
- package/dist/claudeAccounts.js +51 -7
- package/dist/claudeApi.d.ts +2 -1
- package/dist/claudeApi.js +49 -3
- package/dist/command.d.ts +7 -1
- package/dist/command.js +11 -2
- package/dist/commandsApi.d.ts +8 -3
- package/dist/commandsApi.js +25 -4
- package/dist/createPwCodeApi.d.ts +92 -58
- package/dist/createPwCodeApi.js +4 -2
- package/dist/index.d.ts +11 -9
- package/dist/index.js +7 -5
- package/dist/locales/en/agentTranscript.js +6 -2
- package/dist/locales/en/agents.js +50 -6
- package/dist/locales/en.d.ts +46 -0
- package/dist/locales/es/agentTranscript.js +6 -2
- package/dist/locales/es/agents.js +50 -6
- package/dist/locales/ja/agentTranscript.js +6 -2
- package/dist/locales/ja/agents.js +45 -6
- package/dist/locales/ko/agentTranscript.js +6 -2
- package/dist/locales/ko/agents.js +50 -6
- package/dist/locales/zh/agentTranscript.js +6 -2
- package/dist/locales/zh/agents.js +50 -6
- package/dist/machine.d.ts +27 -2
- package/dist/machine.js +23 -2
- package/dist/notices.d.ts +2 -0
- package/dist/notices.js +29 -14
- package/dist/pwUpdate.d.ts +52 -0
- package/dist/pwUpdate.js +115 -0
- package/dist/query.d.ts +4 -1
- package/dist/query.js +9 -3
- package/dist/session.d.ts +7 -1
- package/dist/session.js +6 -2
- package/dist/sessionActions.js +5 -2
- package/dist/sessionEvents.d.ts +39 -5
- package/dist/sessionEvents.js +213 -83
- package/dist/sessionGroups.d.ts +3 -3
- package/dist/sessionGroups.js +3 -3
- package/dist/sessionHeader.js +6 -2
- package/dist/sessionList.d.ts +13 -8
- package/dist/sessionList.js +20 -10
- package/dist/sessionScreen.d.ts +8 -3
- package/dist/sessionScreen.js +20 -9
- package/dist/sessionsApi.d.ts +27 -5
- package/dist/sessionsApi.js +128 -17
- package/dist/sessionsFeed.d.ts +22 -0
- package/dist/sessionsFeed.js +125 -0
- package/dist/startPage.d.ts +6 -3
- package/dist/startPage.js +34 -12
- package/dist/startSession.d.ts +31 -11
- package/dist/startSession.js +126 -44
- package/dist/terminalHandoffPanel.js +8 -1
- package/dist/todos.d.ts +42 -0
- package/dist/todos.js +104 -0
- package/dist/transcript.d.ts +27 -5
- package/dist/transcript.js +148 -112
- package/dist/transcriptRead.d.ts +57 -0
- package/dist/transcriptRead.js +122 -0
- package/dist/types.d.ts +13 -1
- package/dist/useComposer.d.ts +36 -15
- package/dist/useComposer.js +94 -31
- package/dist/useComposerImages.d.ts +38 -1
- package/dist/useComposerImages.js +62 -8
- package/dist/useComposerPastes.js +3 -8
- package/dist/useConversation.d.ts +16 -0
- package/dist/useConversation.js +78 -8
- package/dist/useMounted.d.ts +3 -0
- package/dist/useMounted.js +14 -0
- package/dist/useSubagent.d.ts +22 -5
- package/dist/useSubagent.js +41 -17
- package/dist/useTranscript.d.ts +27 -1
- package/dist/useTranscript.js +217 -45
- package/dist/wording.d.ts +6 -3
- package/dist/wording.js +20 -6
- package/locales/en/agentTranscript.json +6 -2
- package/locales/en/agents.json +46 -4
- package/locales/es/agentTranscript.json +6 -2
- package/locales/es/agents.json +46 -4
- package/locales/ja/agentTranscript.json +6 -2
- package/locales/ja/agents.json +46 -4
- package/locales/ko/agentTranscript.json +6 -2
- package/locales/ko/agents.json +46 -4
- package/locales/zh/agentTranscript.json +6 -2
- package/locales/zh/agents.json +46 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ reader's language, with its own components.
|
|
|
15
15
|
pnpm add @parallelworks/code @parallelworks/ui @parallelworks/problem react openapi-fetch swr use-intl
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
`@parallelworks/ui` (0.
|
|
18
|
+
`@parallelworks/ui` (0.148.0 or newer), `@parallelworks/problem`, `react`,
|
|
19
19
|
`openapi-fetch`, `swr` and `use-intl` are peer dependencies. Only the ui
|
|
20
20
|
package's two entries without a DOM are imported:
|
|
21
21
|
`@parallelworks/ui/ai/headless`, for the message and part types, the reducers
|
|
@@ -80,6 +80,13 @@ showing a toast, wording an error. Types are exported beside each.
|
|
|
80
80
|
`removeQueued`), or every one the machine still holds at once, each with
|
|
81
81
|
its pastes and images, and the first refusal, since one the model read
|
|
82
82
|
meanwhile stays sent (`takeBackPending`, each a `PwCodeTakenBack`).
|
|
83
|
+
A message this window sent comes back too when its turn fails or stops
|
|
84
|
+
before the model reads it, which leaves it out of the conversation:
|
|
85
|
+
`handedBack` counts what is waiting to come back, and `takeBackPending`
|
|
86
|
+
returns it first. One its turn failed on stays drawn where it was sent,
|
|
87
|
+
as the machine records it; one a stop gave back leaves the transcript.
|
|
88
|
+
Another window's message a stop gave back leaves the transcript too, as
|
|
89
|
+
the machine keeps nothing of it, but only its own window gets it back.
|
|
83
90
|
The `typed` option of its `sendMessage` keeps what was typed when a command
|
|
84
91
|
resolved it to other text, so it comes back as typed.
|
|
85
92
|
- `approvalToPart` and `approvalAnswerBody`, between a session's approval
|
|
@@ -105,21 +112,39 @@ showing a toast, wording an error. Types are exported beside each.
|
|
|
105
112
|
can come back, and `take` resolves to each message's text and pastes, in
|
|
106
113
|
the order they would have reached the model (to none while another `take`
|
|
107
114
|
runs), having put their images back
|
|
108
|
-
through the `images` option's `restore`.
|
|
115
|
+
through the `images` option's `restore`. A message still drawn where it was
|
|
116
|
+
sent, as a failed turn leaves it, is marked `shown`, and its images wait
|
|
117
|
+
for `placed`, which the composer calls with the messages it put in its box
|
|
118
|
+
(from `@parallelworks/ui` 0.148.0): it may let that message go for what was
|
|
119
|
+
typed meanwhile. A host drawing its own composer calls `placed` too. It has
|
|
120
|
+
the shape of the `recall`
|
|
109
121
|
that `@parallelworks/ui/ai`'s composer takes from 0.139.0. A host drawing
|
|
110
122
|
its own composer stops a turn with `stopTurn`, as that composer's stop
|
|
111
123
|
does: while anything can come back, the composer's own take-back runs
|
|
112
124
|
first, then the turn stops, even when the take-back threw, which
|
|
113
|
-
`stopTurn` resolves to. Its
|
|
125
|
+
`stopTurn` resolves to. Its `handedBack` grows as a turn gives back a
|
|
126
|
+
message the model never read: a host takes it into the composer then, such
|
|
127
|
+
as with `recall()` on the session view's handle, as the terminal puts it
|
|
128
|
+
back in its box. While `handedBackShown` says something waiting is still
|
|
129
|
+
drawn where it was sent, as a failed turn leaves it, it goes back only into
|
|
130
|
+
an empty composer (`recall({ ifEmpty: true })`, from `@parallelworks/ui`
|
|
131
|
+
0.147.0), and `dropShownHandedBack` lets it go when the composer held
|
|
132
|
+
something: it stays in the transcript and its history, as the terminal
|
|
133
|
+
refills only an empty line, and what a stop gave back then comes back as
|
|
134
|
+
`handedBack` drops. `recall`'s `take` marks such a message `shown`, so a
|
|
135
|
+
composer typed into while it comes back lets it go too. Its command
|
|
114
136
|
outputs (`useCommandOutputs`) and sent prompts (`promptHistory`, per
|
|
115
137
|
person) go with it.
|
|
116
138
|
- `usePwCodeSessionScreen`, the screen around those two: the banner while
|
|
117
139
|
nothing new can reach the transcript (`sessionBanner`, whose `tone` is
|
|
118
140
|
`danger` for a machine that does not answer and `info` for a session live
|
|
119
|
-
elsewhere), the activity line (`sessionActivity`), the
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
(`
|
|
141
|
+
elsewhere), the activity line (`sessionActivity`), whether the turn waits
|
|
142
|
+
at its account's usage limit as that line says, which it doesn't while the
|
|
143
|
+
feed reconnects (`waitingAtLimit`, for the Claude Code account panel), the
|
|
144
|
+
goal (`goalLabel`, whose dot, a `PwCodeGoalMark`, has the `info` tone,
|
|
145
|
+
unlit while paused and pulsing while a check runs), what shows when the
|
|
146
|
+
transcript never loaded (`loadErrorMessage`), the command menu and the
|
|
147
|
+
settings row.
|
|
123
148
|
The goal itself is read, edited, paused, resumed and cleared from a panel
|
|
124
149
|
over `useSessionGoal` (a `PwCodeSessionGoal`), which also gives the panel's
|
|
125
150
|
`view` and `note`, the run's `state`, `lastCheck` and `pausedNote`, which
|
|
@@ -134,12 +159,20 @@ showing a toast, wording an error. Types are exported beside each.
|
|
|
134
159
|
(`sessionSettingsOptions`), what the machine allows
|
|
135
160
|
of Claude Code (`claudeOnMachine`), and the account a Claude model runs as
|
|
136
161
|
(`claudeAccountChip`).
|
|
162
|
+
The task list pinned above the composer (`useTodoPanel`, a
|
|
163
|
+
`PwCodeTodoPanel`) gives its title, how far along it is (`progress`), the
|
|
164
|
+
running task a folded panel names (`running`), up to six rows from the one
|
|
165
|
+
before the running task, each with its status in words (`rows`), and the
|
|
166
|
+
control that shows the rest or fewer again (`more`).
|
|
137
167
|
- Images and pastes sent with a message. `useComposerImages` holds the images
|
|
138
168
|
until there is a session to save them with, through the host's encoder,
|
|
139
169
|
which throws `PwCodeImageTooLarge` for one it cannot fit; `fitImageWith`
|
|
140
170
|
works out the sizes an image is written at to fit `IMAGE_MAX_BYTES` and
|
|
141
171
|
`IMAGE_MAX_SIDE`, `IMAGE_TYPES` are the types a session takes, and
|
|
142
|
-
`nextImageSeq` numbers an image's placeholder.
|
|
172
|
+
`nextImageSeq` numbers an image's placeholder. Each image is saved under its
|
|
173
|
+
number, so every composer on one session's screen passes `useComposerImages`
|
|
174
|
+
the same `numbering` counter, and none gives a number another's unsent image
|
|
175
|
+
holds. `useComposerImages`'
|
|
143
176
|
`restore` puts back the images of a message taken back, already saved with
|
|
144
177
|
the session, and `withoutAppendedImages` takes the placeholders its send
|
|
145
178
|
appended out of that message's text. `useComposerPastes` says where a
|
|
@@ -155,15 +188,22 @@ showing a toast, wording an error. Types are exported beside each.
|
|
|
155
188
|
read's `error`), whether messages show their author (`showAuthor`), its
|
|
156
189
|
activity line (`activity`), where a queued message goes
|
|
157
190
|
(`queueDelivery`), taking one back (`canRemoveQueued`, `removeQueued`) or
|
|
158
|
-
all of them into the composer (`recall`, as the main
|
|
159
|
-
composer's
|
|
191
|
+
all of them into the composer (`recall` and `handedBack`, as the main
|
|
192
|
+
composer's), its
|
|
193
|
+
composer's draft key (`draftKey`), the `id` its `promptHistory` takes
|
|
194
|
+
(`historyId`), and the model it runs on (`model`) and
|
|
160
195
|
that model's name (`modelLabel`, from the `modelNames` option, the session
|
|
161
|
-
state's).
|
|
196
|
+
state's). Its `images` option, which `useComposerImages` returns for the
|
|
197
|
+
subagent's own composer, sends images with what is typed, as the main
|
|
198
|
+
composer's does. Beside it, the switcher that lists them
|
|
162
199
|
(`usePwCodeAgentSwitcher`, `switcherAgent`, `usePwCodeAgentLine`,
|
|
163
|
-
`useAgentTypeLabel`),
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
shows
|
|
200
|
+
`useAgentTypeLabel`), taking one that is not running off the list, which
|
|
201
|
+
shows the main conversation again when it was the one in view and the
|
|
202
|
+
screen that asked is still open (`useDismissSubagent`), the mark each
|
|
203
|
+
agent shows for its state (`agentMark`), and the tone of its state's word
|
|
204
|
+
(`stateTone`, a `PwCodeStateTone` the host maps to its colors) and whether
|
|
205
|
+
that word shows beside the mark (`flagged`), the main conversation's
|
|
206
|
+
included.
|
|
167
207
|
- Where typed text goes (`slashAction`, `shellCommand`), the commands a
|
|
168
208
|
session offers (`paletteOptions`), read from the structural
|
|
169
209
|
`PwCodePalette`, whether a direction that got no answer may have landed
|
|
@@ -245,7 +285,8 @@ showing a toast, wording an error. Types are exported beside each.
|
|
|
245
285
|
starts in and the machine's bounds on its picker (`useStartPermissionMode`,
|
|
246
286
|
a `PwCodeStartPermission`, `startingMode`), its model, allocation and
|
|
247
287
|
Claude Code account (`useStartModel`), and the start itself with its first
|
|
248
|
-
prompt and images
|
|
288
|
+
prompt and images, or a `/goal` or `/plan` typed first (`useStartSession`,
|
|
289
|
+
whose `blocked` says why a start was not tried). The host passes in its saved
|
|
249
290
|
preferences and opens the session once it starts. `startControls`
|
|
250
291
|
(`PwCodeStartControls`) says which controls are locked while it starts or
|
|
251
292
|
until a machine is chosen, and whether the model picker reads the
|
|
@@ -312,6 +353,11 @@ showing a toast, wording an error. Types are exported beside each.
|
|
|
312
353
|
whenever the selected or first enabled row changes, such as when the
|
|
313
354
|
accounts' sign-in states arrive. Its setter must keep its identity, as a
|
|
314
355
|
`useState` setter does: a new one moves the highlight back too.
|
|
356
|
+
Given `waitingAtLimit`, the session screen's, it asks for another account
|
|
357
|
+
to continue on (`handoff`) and offers to take the other sessions on the
|
|
358
|
+
spent one along (`others`, `moveOthers`, `setMoveOthers`), under the label
|
|
359
|
+
`moveOthersLabel`, null when the option doesn't show. `onMovedOthers` is
|
|
360
|
+
handed the words that say how many moved.
|
|
315
361
|
- The sign-in itself, run in the host's terminal (`useClaudeSignIn`, also
|
|
316
362
|
given `machineName`), with the sign-in page to offer opening, what to do,
|
|
317
363
|
a note when earlier output was dropped, the label that leaves it, and,
|
|
@@ -426,13 +472,23 @@ that session, so the connection goes to the one the reader moved on to.
|
|
|
426
472
|
Its other options:
|
|
427
473
|
|
|
428
474
|
- `hidden`, when given, says the app is out of sight, where animation frames
|
|
429
|
-
do not run
|
|
475
|
+
do not run. There a reply streaming into a session is applied about once a
|
|
476
|
+
second, and every other feed frame as it arrives.
|
|
477
|
+
- `whenShown` calls the function it is given each time the app comes back
|
|
478
|
+
into sight, until the call it returns, so what streamed while the app was
|
|
479
|
+
hidden is drawn at once.
|
|
430
480
|
- `onPreferenceError` hears a preference that failed to save; it shows its
|
|
431
481
|
saved value again.
|
|
432
482
|
- `previewsByRef` reads a transcript with each image's preview left to its
|
|
433
483
|
ref, to be loaded when it is drawn. Set it only where the host loads an
|
|
434
484
|
image from its URL on the platform's API signed in as the API client is, as
|
|
435
485
|
a browser on the platform's origin does.
|
|
486
|
+
- `transcriptEndFirst` reads a session's transcript end first and draws the
|
|
487
|
+
end of the conversation while the rest arrives, which over a slow
|
|
488
|
+
connection is most of the wait. Set it only where the client's `fetch` hands
|
|
489
|
+
over a response's body as it arrives (`response.body`), as a browser's does
|
|
490
|
+
and React Native's own does not. Until the whole transcript is there the
|
|
491
|
+
composer is disabled and nothing that waits on the reader is drawn.
|
|
436
492
|
|
|
437
493
|
The package carries the types of the routes it calls (`PwCodePaths`), generated
|
|
438
494
|
from the platform's OpenAPI spec. A client whose own API types lack one of
|
|
@@ -608,9 +664,10 @@ and navigates nowhere. The host supplies each:
|
|
|
608
664
|
}),
|
|
609
665
|
```
|
|
610
666
|
|
|
611
|
-
- Whether the app is out of sight, as `hidden`, and whether
|
|
612
|
-
from a session, as `useAwayRecap`'s `presence` (`away`,
|
|
613
|
-
calls `leave` and `back` as that changes),
|
|
667
|
+
- Whether the app is out of sight, as `hidden` and `whenShown`, and whether
|
|
668
|
+
the reader is away from a session, as `useAwayRecap`'s `presence` (`away`,
|
|
669
|
+
and `watch`, which calls `leave` and `back` as that changes), all read from
|
|
670
|
+
the app's state.
|
|
614
671
|
- Images: `useComposerImages`' `encode`, which writes a picked image as base64
|
|
615
672
|
within `IMAGE_MAX_BYTES` and `IMAGE_MAX_SIDE` and throws
|
|
616
673
|
`PwCodeImageTooLarge` for one it cannot fit (`fitImageWith` works out the
|
|
@@ -629,9 +686,13 @@ and navigates nowhere. The host supplies each:
|
|
|
629
686
|
`useSessionActions`' `showStart` and `showSession`,
|
|
630
687
|
`usePwCodeConversation`'s `onCleared` and `onMoved`, `usePwCodeComposer`'s
|
|
631
688
|
`onCleared` and `onArchived`, `useSessionLink`'s `open`, `useSessionList`'s
|
|
632
|
-
`newSession`, `useModelPicker`'s `onAccounts
|
|
633
|
-
`useClaudeAccountPanel`'s `onClose`.
|
|
634
|
-
|
|
689
|
+
`newSession`, `useModelPicker`'s `onAccounts`,
|
|
690
|
+
`useClaudeAccountPanel`'s `onClose` and `useDismissSubagent`'s `showMain`.
|
|
691
|
+
Of these, `usePwCodeComposer`'s `onCleared` and `onArchived` and
|
|
692
|
+
`useDismissSubagent`'s `showMain` are not called once the screen that asked
|
|
693
|
+
has closed, so an answer that comes late leaves the reader where they went.
|
|
694
|
+
- What the reader is told and asked: `describeError`, `notify`,
|
|
695
|
+
`useClaudeAccountPanel`'s `onMovedOthers`, and
|
|
635
696
|
`useSessionActions`' `confirm`; Claude Code's sign-in runs in the host's
|
|
636
697
|
terminal, `useClaudeSignIn`'s `terminal`.
|
|
637
698
|
|
|
@@ -658,6 +719,11 @@ change them.
|
|
|
658
719
|
|
|
659
720
|
### Breaking changes since 0.3.0
|
|
660
721
|
|
|
722
|
+
- `useStartSession` takes `runSlashAction` and `useSessionMutations` from the
|
|
723
|
+
API as well, reads pw code's messages as the composer does, and returns
|
|
724
|
+
`blocked`, why a start was not tried, such as a `/goal` sent with images,
|
|
725
|
+
for the host to show where it shows `error`. A start that fails once its
|
|
726
|
+
session exists deletes that session, rather than keeping it for a retry.
|
|
661
727
|
- `usePwCodeSubagent` takes `listed`, the subagent's switcher row
|
|
662
728
|
(`switcherAgent`), and `usage`, its tokens as the session's feed last
|
|
663
729
|
counted them, and no longer takes `name`: it names the subagent itself and
|
|
@@ -679,7 +745,9 @@ change them.
|
|
|
679
745
|
`useComposerImages` returns it, so a host passing what that returns
|
|
680
746
|
changes nothing; one passing its own `{ take, taking }` adds it.
|
|
681
747
|
- Peer dependencies: `@parallelworks/problem` (`>=0.6.1 <1`) is new, and
|
|
682
|
-
`@parallelworks/ui` needs 0.
|
|
748
|
+
`@parallelworks/ui` needs 0.148.0 or newer, up from 0.132.0, so its
|
|
749
|
+
composer calls `recall.placed`. A host drawing its own composer calls
|
|
750
|
+
`placed` too, or a failed message it takes back comes without its images.
|
|
683
751
|
- The host's API types must include eight more routes, which
|
|
684
752
|
`createPwCodeApi` now calls: `/api/allocations`, `/api/openai/v1/models`,
|
|
685
753
|
`/api/previews`, `/api/user/preferences`,
|
package/dist/agentSwitcher.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Schemas } from './apiClient.js';
|
|
2
2
|
import type { PwCodeSubagentUsage } from './types.js';
|
|
3
|
-
import type { PwCodeConversationState } from './useConversation.js';
|
|
3
|
+
import type { PwCodeConversation, PwCodeConversationState } from './useConversation.js';
|
|
4
4
|
/** One subagent as the switcher lists it. */
|
|
5
5
|
export interface PwCodeSwitcherAgent {
|
|
6
6
|
id: string;
|
|
@@ -45,12 +45,23 @@ export interface PwCodeAgentLine {
|
|
|
45
45
|
stateTone: PwCodeStateTone;
|
|
46
46
|
/** The state needs the reader, so it is said in words beside its mark. */
|
|
47
47
|
flagged: boolean;
|
|
48
|
-
/** Still running, so it can be stopped. */
|
|
48
|
+
/** Still running, so it can be stopped; once it is not, it can be taken off the list instead. */
|
|
49
49
|
stoppable: boolean;
|
|
50
50
|
/** Names the agent, for a stop button among others. */
|
|
51
51
|
stopLabel: string;
|
|
52
|
+
/** Names the agent, for a button among others that takes it off the list. */
|
|
53
|
+
dismissLabel: string;
|
|
52
54
|
}
|
|
53
55
|
export declare function usePwCodeAgentLine(): (agent: PwCodeSwitcherAgent) => PwCodeAgentLine;
|
|
56
|
+
/** Takes an agent that is not running off the session's list, resolving to
|
|
57
|
+
* whether it went. The main conversation comes back into view when the agent
|
|
58
|
+
* that went is the one in view by then, since the reader may have opened
|
|
59
|
+
* another meanwhile, and only while the screen that asked is still open. */
|
|
60
|
+
export declare function useDismissSubagent(conversation: Pick<PwCodeConversation, 'dismissSubagent'>, { viewing, showMain, }: {
|
|
61
|
+
/** The subagent in view; null for the main conversation. */
|
|
62
|
+
viewing: string | null;
|
|
63
|
+
showMain: () => void;
|
|
64
|
+
}): (id: string) => Promise<boolean>;
|
|
54
65
|
/** A subagent's row in the switcher's list. */
|
|
55
66
|
export interface PwCodeSwitcherRow extends PwCodeAgentLine {
|
|
56
67
|
/** How long it has run, or ran; null before it started. */
|
package/dist/agentSwitcher.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { usePwCodeTranslations } from "./messages.js";
|
|
2
2
|
import { turnDuration } from "./notices.js";
|
|
3
|
-
import {
|
|
3
|
+
import { useMounted } from "./useMounted.js";
|
|
4
|
+
import { useCallback, useMemo, useRef } from "react";
|
|
4
5
|
import { sanitizeLabel } from "@parallelworks/ui/ai/headless";
|
|
5
6
|
import { useFormatter } from "use-intl";
|
|
6
7
|
import { DateTime } from "luxon";
|
|
@@ -63,6 +64,10 @@ function usePwCodeAgentLine() {
|
|
|
63
64
|
const state = agentState(agent);
|
|
64
65
|
const type = typeLabel(agent.agentType);
|
|
65
66
|
const description = sanitizeLabel(agent.description);
|
|
67
|
+
const name = t("switcher.agentName", {
|
|
68
|
+
type,
|
|
69
|
+
description
|
|
70
|
+
});
|
|
66
71
|
return {
|
|
67
72
|
agent,
|
|
68
73
|
type,
|
|
@@ -72,13 +77,30 @@ function usePwCodeAgentLine() {
|
|
|
72
77
|
stateTone: stateTone(state),
|
|
73
78
|
flagged: flagged(state),
|
|
74
79
|
stoppable: agent.status === "running",
|
|
75
|
-
stopLabel: t("switcher.stop", { name
|
|
76
|
-
|
|
77
|
-
description
|
|
78
|
-
}) })
|
|
80
|
+
stopLabel: t("switcher.stop", { name }),
|
|
81
|
+
dismissLabel: t("switcher.dismiss", { name })
|
|
79
82
|
};
|
|
80
83
|
}, [t, typeLabel]);
|
|
81
84
|
}
|
|
85
|
+
/** Takes an agent that is not running off the session's list, resolving to
|
|
86
|
+
* whether it went. The main conversation comes back into view when the agent
|
|
87
|
+
* that went is the one in view by then, since the reader may have opened
|
|
88
|
+
* another meanwhile, and only while the screen that asked is still open. */
|
|
89
|
+
function useDismissSubagent(conversation, { viewing, showMain }) {
|
|
90
|
+
const inView = useRef(viewing);
|
|
91
|
+
inView.current = viewing;
|
|
92
|
+
const mounted = useMounted();
|
|
93
|
+
const { dismissSubagent } = conversation;
|
|
94
|
+
return useCallback(async (id) => {
|
|
95
|
+
const taken = await dismissSubagent(id);
|
|
96
|
+
if (taken && mounted.current && id === inView.current) showMain();
|
|
97
|
+
return taken;
|
|
98
|
+
}, [
|
|
99
|
+
dismissSubagent,
|
|
100
|
+
mounted,
|
|
101
|
+
showMain
|
|
102
|
+
]);
|
|
103
|
+
}
|
|
82
104
|
function elapsedMs(agent, nowSeconds) {
|
|
83
105
|
if (!agent.startedAt) return null;
|
|
84
106
|
const started = DateTime.fromISO(agent.startedAt).toMillis();
|
|
@@ -162,4 +184,4 @@ function usePwCodeAgentSwitcher({ agents, mainState, viewing, open, earlierOpen
|
|
|
162
184
|
line
|
|
163
185
|
]);
|
|
164
186
|
}
|
|
165
|
-
export { agentMark, switcherAgent, useAgentTypeLabel, usePwCodeAgentLine, usePwCodeAgentSwitcher };
|
|
187
|
+
export { agentMark, switcherAgent, useAgentTypeLabel, useDismissSubagent, usePwCodeAgentLine, usePwCodeAgentSwitcher };
|
package/dist/ago.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
/** "5m" since a time,
|
|
2
|
-
* than turning into a date as a compact RelativeTime does, and re-reads every
|
|
3
|
-
* 30 seconds. */
|
|
1
|
+
/** "5m" since a time, counting days where a compact RelativeTime shows a date. */
|
|
4
2
|
export declare function useCompactAgo(): {
|
|
5
3
|
now: number;
|
|
6
4
|
compact: (iso: string | undefined) => string;
|
package/dist/ago.js
CHANGED
|
@@ -3,9 +3,7 @@ import { useCallback, useMemo } from "react";
|
|
|
3
3
|
import { DateTime } from "luxon";
|
|
4
4
|
import { useClock } from "@parallelworks/ui/headless";
|
|
5
5
|
// src/ago.ts
|
|
6
|
-
/** "5m" since a time,
|
|
7
|
-
* than turning into a date as a compact RelativeTime does, and re-reads every
|
|
8
|
-
* 30 seconds. */
|
|
6
|
+
/** "5m" since a time, counting days where a compact RelativeTime shows a date. */
|
|
9
7
|
function useCompactAgo() {
|
|
10
8
|
const t = usePwCodeTranslations("agents");
|
|
11
9
|
const tick = useClock((current) => Math.floor(current / 3e4));
|