@parallelworks/code 0.1.0 → 0.3.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 +171 -24
- package/dist/ago.d.ts +8 -0
- package/dist/ago.js +26 -0
- package/dist/api.d.ts +3547 -0
- package/dist/apiClient.d.ts +26 -0
- package/dist/apiClient.js +5 -0
- package/dist/base64.d.ts +3 -0
- package/dist/base64.js +15 -0
- package/dist/chatHandoff.d.ts +12 -0
- package/dist/chatHandoff.js +27 -0
- package/dist/claudeAccounts.d.ts +112 -0
- package/dist/claudeAccounts.js +234 -0
- package/dist/claudeApi.d.ts +27 -0
- package/dist/claudeApi.js +250 -0
- package/dist/claudeSignIn.d.ts +62 -0
- package/dist/claudeSignIn.js +239 -0
- package/dist/command.d.ts +47 -0
- package/dist/command.js +64 -0
- package/dist/commandsApi.d.ts +64 -0
- package/dist/commandsApi.js +267 -0
- package/dist/contextRow.d.ts +25 -0
- package/dist/contextRow.js +16 -0
- package/dist/createPwCodeApi.d.ts +696 -0
- package/dist/createPwCodeApi.js +33 -0
- package/dist/howSessionsAppear.d.ts +12 -0
- package/dist/howSessionsAppear.js +24 -0
- package/dist/index.d.ts +39 -3
- package/dist/index.js +38 -3
- package/dist/locales/en/agentTranscript.js +162 -0
- package/dist/locales/en/agents.js +380 -0
- package/dist/locales/en.d.ts +523 -0
- package/dist/locales/en.js +8 -0
- package/dist/locales/es/agentTranscript.js +162 -0
- package/dist/locales/es/agents.js +380 -0
- package/dist/locales/es.d.ts +3 -0
- package/dist/locales/es.js +8 -0
- package/dist/locales/ja/agentTranscript.js +162 -0
- package/dist/locales/ja/agents.js +380 -0
- package/dist/locales/ja.d.ts +3 -0
- package/dist/locales/ja.js +8 -0
- package/dist/locales/ko/agentTranscript.js +162 -0
- package/dist/locales/ko/agents.js +380 -0
- package/dist/locales/ko.d.ts +3 -0
- package/dist/locales/ko.js +8 -0
- package/dist/locales/zh/agentTranscript.js +162 -0
- package/dist/locales/zh/agents.js +380 -0
- package/dist/locales/zh.d.ts +3 -0
- package/dist/locales/zh.js +8 -0
- package/dist/machine.d.ts +51 -0
- package/dist/machine.js +60 -0
- package/dist/messages.d.ts +17 -0
- package/dist/messages.js +31 -0
- package/dist/models.d.ts +47 -0
- package/dist/models.js +49 -0
- package/dist/notices.d.ts +12 -0
- package/dist/notices.js +120 -0
- package/dist/pullRequest.d.ts +8 -0
- package/dist/pullRequest.js +29 -0
- package/dist/pullRequestList.d.ts +52 -0
- package/dist/pullRequestList.js +106 -0
- package/dist/query.d.ts +28 -0
- package/dist/query.js +25 -0
- package/dist/session.d.ts +75 -1
- package/dist/session.js +101 -1
- package/dist/sessionActions.d.ts +105 -0
- package/dist/sessionActions.js +178 -0
- package/dist/sessionEvents.d.ts +27 -0
- package/dist/sessionEvents.js +212 -0
- package/dist/sessionGroups.d.ts +49 -0
- package/dist/sessionGroups.js +72 -0
- package/dist/sessionHeader.d.ts +14 -0
- package/dist/sessionHeader.js +16 -0
- package/dist/sessionList.d.ts +134 -0
- package/dist/sessionList.js +271 -0
- package/dist/sessionsApi.d.ts +105 -0
- package/dist/sessionsApi.js +511 -0
- package/dist/settingsApi.d.ts +36 -0
- package/dist/settingsApi.js +151 -0
- package/dist/startSession.d.ts +138 -0
- package/dist/startSession.js +234 -0
- package/dist/terminalHandoffPanel.d.ts +30 -0
- package/dist/terminalHandoffPanel.js +33 -0
- package/dist/toolStrings.d.ts +4 -0
- package/dist/toolStrings.js +95 -0
- package/dist/transcript.d.ts +14 -1
- package/dist/transcript.js +55 -14
- package/dist/types.d.ts +20 -1
- package/dist/usageLimit.d.ts +8 -0
- package/dist/usageLimit.js +13 -0
- package/dist/useAwayRecap.d.ts +30 -0
- package/dist/useAwayRecap.js +75 -0
- package/dist/useComposer.d.ts +121 -0
- package/dist/useComposer.js +244 -0
- package/dist/useComposerImages.d.ts +66 -0
- package/dist/useComposerImages.js +195 -0
- package/dist/useConversation.d.ts +190 -0
- package/dist/useConversation.js +287 -0
- package/dist/useSubagent.d.ts +58 -0
- package/dist/useSubagent.js +149 -0
- package/dist/useTranscript.d.ts +4 -1
- package/dist/useTranscript.js +54 -11
- package/dist/wording.d.ts +43 -0
- package/dist/wording.js +101 -0
- package/dist/workingDirectories.d.ts +32 -0
- package/dist/workingDirectories.js +71 -0
- package/dist/worktreeChoice.d.ts +31 -0
- package/dist/worktreeChoice.js +38 -0
- package/locales/en/agentTranscript.json +154 -0
- package/locales/en/agents.json +366 -0
- package/locales/es/agentTranscript.json +154 -0
- package/locales/es/agents.json +366 -0
- package/locales/ja/agentTranscript.json +154 -0
- package/locales/ja/agents.json +366 -0
- package/locales/ko/agentTranscript.json +154 -0
- package/locales/ko/agents.json +366 -0
- package/locales/zh/agentTranscript.json +154 -0
- package/locales/zh/agents.json +366 -0
- package/package.json +24 -9
package/README.md
CHANGED
|
@@ -1,24 +1,34 @@
|
|
|
1
1
|
# @parallelworks/code
|
|
2
2
|
|
|
3
|
-
Shared client logic for pw code sessions on Parallel Works ACTIVATE:
|
|
4
|
-
session's
|
|
5
|
-
history and live event stream reduce to. Every app that
|
|
6
|
-
the same code, so a session reads the same in each.
|
|
3
|
+
Shared client logic for pw code sessions on Parallel Works ACTIVATE: the calls
|
|
4
|
+
and data hooks a session's pages read through, what a session's daemon sends,
|
|
5
|
+
and the transcript its history and live event stream reduce to. Every app that
|
|
6
|
+
shows a session uses the same code, so a session reads the same in each.
|
|
7
7
|
|
|
8
|
-
It draws nothing
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
It draws nothing. The host hands it an API client, which carries the
|
|
9
|
+
platform's address and signs each request, and a way to open its sockets; it
|
|
10
|
+
renders the messages this package turns the session into, worded in the
|
|
11
|
+
reader's language.
|
|
11
12
|
|
|
12
13
|
```bash
|
|
13
|
-
pnpm add @parallelworks/code @parallelworks/ui react
|
|
14
|
+
pnpm add @parallelworks/code @parallelworks/ui react openapi-fetch swr use-intl
|
|
14
15
|
```
|
|
15
16
|
|
|
16
|
-
`@parallelworks/ui` and `
|
|
17
|
-
|
|
18
|
-
message and part types and the
|
|
17
|
+
`@parallelworks/ui`, `react`, `openapi-fetch`, `swr` and `use-intl` are peer
|
|
18
|
+
dependencies. Only the ui package's two entries without a DOM are imported:
|
|
19
|
+
`@parallelworks/ui/ai/headless`, for the message and part types and the
|
|
20
|
+
reducers that build them, and `@parallelworks/ui/headless`, for its duration
|
|
21
|
+
format, its strings and its clock.
|
|
19
22
|
|
|
20
23
|
## What is in it
|
|
21
24
|
|
|
25
|
+
- `createPwCodeApi(client, options)`, the calls and SWR data hooks of pw code
|
|
26
|
+
sessions over the host's `openapi-fetch` client: the sessions and machines
|
|
27
|
+
listed (`useSessions`, `useMachines`), a session's transcript
|
|
28
|
+
(`useSessionDetail`), its live event feed (`useSessionEvents`), what can be
|
|
29
|
+
done to it (`useSessionMutations`, `sendMessage`, `steer`, `answerApproval`,
|
|
30
|
+
`resolveTyped`, ...), its subagents, pull requests and worktree, and the
|
|
31
|
+
Claude Code models, accounts and sign-in of its machine.
|
|
22
32
|
- The wire types (`PwCodeSessionDetail`, `PwCodeStreamEvent`,
|
|
23
33
|
`PwCodeApprovalRequest`, ...): a session's replayed history, its event
|
|
24
34
|
frames and the answers it accepts. A host that generates its API types can
|
|
@@ -32,34 +42,166 @@ message and part types and the reducers that build them.
|
|
|
32
42
|
requests and the answer it accepts.
|
|
33
43
|
- The paths a session's images are served from (`sessionImageUrl`,
|
|
34
44
|
`sessionGitHubImageUrl`).
|
|
45
|
+
- What a list of sessions and machines means, as pure functions over the
|
|
46
|
+
structural `PwCodeSession` and `PwCodeMachine`: which sessions wait on the
|
|
47
|
+
reader and in what order they show (`triageSessions`, `newestFirst`,
|
|
48
|
+
`needsYou`, `isActiveSession`, `isMidTurn`), the tone a row takes
|
|
49
|
+
(`sessionVariant`), whether a machine can be reached or can start a session
|
|
50
|
+
(`isMachineDown`, `canStartHere`), the folders a machine's sessions suggest
|
|
51
|
+
(`recentDirectories`), and the command that picks a session up in a terminal
|
|
52
|
+
(`terminalHandoff`).
|
|
53
|
+
- Starting a session, as hooks a host draws its own start screen over:
|
|
54
|
+
where it starts (`useStartLocation`, `startMachines`), the permission mode
|
|
55
|
+
it starts in (`useStartPermissionMode`, `startingMode`), its model,
|
|
56
|
+
allocation and Claude Code account (`useStartModel`), and the start itself
|
|
57
|
+
with its first prompt and images (`useStartSession`). The host passes in its
|
|
58
|
+
saved preferences and opens the session once it starts.
|
|
59
|
+
- The models a session can run (`isClaudeModel`, `runsClaude`, `canRunModel`,
|
|
60
|
+
`modelLabel`), the picker a typed command opens (`pickerCommand`), and the
|
|
61
|
+
machine's Claude models a model picker offers (`useModelCatalog`).
|
|
62
|
+
- A session's working directories: the path helpers that cut a long path to
|
|
63
|
+
fit (`pathSegments`, `shortestPath`, `cutToFit`, `cutSpacing`,
|
|
64
|
+
`lastSegmentAt`), where a directory is saved (`isSavedDirectory`,
|
|
65
|
+
`directoryScopes`), what an approval allowed in one (`allowedAccess`), and
|
|
66
|
+
closing one added for the session only (`useRemoveSessionDirectory`).
|
|
67
|
+
- The choice to keep or remove a session's worktree when the session is
|
|
68
|
+
deleted (`useWorktreeChoice`), and what removing it would delete
|
|
69
|
+
(`worktreeWork`).
|
|
70
|
+
- Where typed text goes (`slashAction`, `shellCommand`) and the commands a
|
|
71
|
+
session offers (`paletteOptions`), read from the structural `PwCodePalette`.
|
|
72
|
+
- The short label of a pull or merge request link (`pullRequestLabel`,
|
|
73
|
+
`pastedPullRequestLabel`), and how a session's pull requests are listed:
|
|
74
|
+
their order (`orderPullRequests`), which fold into a count and how the
|
|
75
|
+
counts read (`foldPullRequests`, `donePullRequestsToFold`,
|
|
76
|
+
`pullRequestGroupState`, `pullRequestWords`), and the row of directories
|
|
77
|
+
and pull requests under a session's title (`sessionContextRow`).
|
|
78
|
+
- What a session's header offers: picking the session up in a terminal
|
|
79
|
+
(`terminalHandoffPanel`), the line a turn shows while it waits for a usage
|
|
80
|
+
limit (`useUsageLimitWait`), the worktree the session works in, read again
|
|
81
|
+
when it moves (`useFollowedWorktree`), and how sessions get listed
|
|
82
|
+
(`howSessionsAppear`).
|
|
83
|
+
- The messages a session is shown in, in English, Spanish, Japanese, Korean
|
|
84
|
+
and Chinese (`loadPwCodeMessages`), and the words built from them: a
|
|
85
|
+
session's label and status (`sessionLabel`, `sessionStateText`), why a
|
|
86
|
+
machine can't be reached (`machineHint`), what the composer says while it is
|
|
87
|
+
locked (`composerState`), and the transcript's own lines
|
|
88
|
+
(`useTranscriptWords`, `useGoalNotice`, `useCompactionNotice`,
|
|
89
|
+
`useRecapNotice`, `useToolStrings`).
|
|
90
|
+
- How long ago something happened, as "5m", for labels passed as strings
|
|
91
|
+
(`useCompactAgo`). It reads `@parallelworks/ui`'s `time` strings, which a
|
|
92
|
+
host sets on `UIProvider`, or on `UIStringsProvider` where there is no DOM,
|
|
93
|
+
and re-reads every 30 seconds on the ui package's clock.
|
|
94
|
+
|
|
95
|
+
## Messages
|
|
96
|
+
|
|
97
|
+
The messages are use-intl catalogs, keyed by namespace (`agents`,
|
|
98
|
+
`agentTranscript`). Load them for the reader's language and merge them into the
|
|
99
|
+
host's own, wherever its `IntlProvider` takes messages:
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
import { loadPwCodeMessages, pwCodeLocales } from '@parallelworks/code'
|
|
103
|
+
import { IntlProvider } from 'use-intl'
|
|
104
|
+
|
|
105
|
+
// One of pwCodeLocales; any other locale rejects.
|
|
106
|
+
const code = await loadPwCodeMessages(locale)
|
|
107
|
+
|
|
108
|
+
root.render(
|
|
109
|
+
<IntlProvider locale={locale} messages={{ ...hostMessages, ...code }}>
|
|
110
|
+
<App />
|
|
111
|
+
</IntlProvider>
|
|
112
|
+
)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Each language is its own import, so a bundler that splits code loads only the
|
|
116
|
+
one shown. The JSON files themselves ship too, as
|
|
117
|
+
`@parallelworks/code/locales/<lang>/<namespace>.json`.
|
|
118
|
+
|
|
119
|
+
The functions that word a session take a translator over the `agents`
|
|
120
|
+
namespace. `usePwCodeTranslations('agents')` gives one typed from these
|
|
121
|
+
catalogs, whatever the host declares to use-intl; outside React, use-intl's
|
|
122
|
+
`createTranslator` makes one:
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import { createTranslator } from 'use-intl'
|
|
126
|
+
import { loadPwCodeMessages, sessionStatusText } from '@parallelworks/code'
|
|
127
|
+
|
|
128
|
+
const t = createTranslator({
|
|
129
|
+
locale: 'es',
|
|
130
|
+
messages: await loadPwCodeMessages('es'),
|
|
131
|
+
namespace: 'agents',
|
|
132
|
+
})
|
|
133
|
+
sessionStatusText({ status: 'awaiting_approval' }, t) // "aprobación necesaria"
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
A host that types its own messages for use-intl adds `PwCodeMessages` to them,
|
|
137
|
+
so its `useTranslations('agents')` checks keys too.
|
|
138
|
+
|
|
139
|
+
## The API
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
import { createPwCodeApi } from '@parallelworks/code'
|
|
143
|
+
import createClient from 'openapi-fetch'
|
|
144
|
+
import type { paths } from './api' // the host's own types of the platform's API
|
|
145
|
+
|
|
146
|
+
const client = createClient<paths>({ baseUrl: 'https://activate.example.com' })
|
|
147
|
+
export const pwCode = createPwCodeApi(client, {
|
|
148
|
+
// The event feed's socket, opened on the platform's host and signed in as
|
|
149
|
+
// the client is. It may resolve asynchronously, after fetching a token.
|
|
150
|
+
openSocket: path => new WebSocket(`wss://activate.example.com${path}`),
|
|
151
|
+
})
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Create it once per client, at module level. Its hooks key SWR's cache as
|
|
155
|
+
`@parallelworks/client/swr`'s hooks do (`['api', path, init]`, or `null` for a
|
|
156
|
+
read they skip), and throw the client's error as those do, so a host that reads
|
|
157
|
+
the same routes through those shares their cache entries, and revalidating one
|
|
158
|
+
revalidates the other. `hidden`, when given, says the app is out of sight,
|
|
159
|
+
where animation frames do not run and feed frames are applied as they arrive.
|
|
160
|
+
|
|
161
|
+
The package carries the types of the routes it calls (`PwCodePaths`), generated
|
|
162
|
+
from the platform's OpenAPI spec. A client whose own API types lack one of
|
|
163
|
+
those routes, or type one differently, is refused at compile time, naming the
|
|
164
|
+
routes it lacks; regenerate the host's types from a newer spec.
|
|
35
165
|
|
|
36
166
|
## Using the hook
|
|
37
167
|
|
|
38
168
|
```tsx
|
|
39
169
|
import {
|
|
170
|
+
pasteRefs,
|
|
40
171
|
pendingMessages,
|
|
41
172
|
turnRunning,
|
|
42
173
|
usePwCodeTranscript,
|
|
43
174
|
} from '@parallelworks/code'
|
|
175
|
+
import { pwCode } from './pwCode'
|
|
44
176
|
|
|
45
|
-
function useSession(sessionId: string) {
|
|
46
|
-
// The
|
|
47
|
-
const { detail,
|
|
177
|
+
function useSession(machine: string, sessionId: string) {
|
|
178
|
+
// The session's status, history and last seq.
|
|
179
|
+
const { data: detail, mutate } = pwCode.useSessionDetail(
|
|
180
|
+
machine,
|
|
181
|
+
sessionId,
|
|
182
|
+
undefined
|
|
183
|
+
)
|
|
48
184
|
const { transcript, onEvent, cursor, sendMessage } = usePwCodeTranscript({
|
|
49
185
|
sessionId,
|
|
50
186
|
detail,
|
|
51
187
|
// Resolves to { turnId, queued } once accepted, or { error } to show.
|
|
52
|
-
send: (text, pastes, images) =>
|
|
53
|
-
|
|
188
|
+
send: async (text, pastes, images) => {
|
|
189
|
+
const { data, error } = await pwCode.sendMessage(machine, sessionId, {
|
|
190
|
+
text,
|
|
191
|
+
...pasteRefs(pastes),
|
|
192
|
+
...(images ? { images } : {}),
|
|
193
|
+
})
|
|
194
|
+
return error ? { error: error.message } : data
|
|
195
|
+
},
|
|
54
196
|
onEffect: effect => {
|
|
55
197
|
// What a frame asks of the host: 'refetch', 'cleared', 'state' or 'notice'.
|
|
56
198
|
if (effect.type === 'refetch') {
|
|
57
|
-
|
|
199
|
+
void mutate()
|
|
58
200
|
}
|
|
59
201
|
},
|
|
60
202
|
})
|
|
61
|
-
// The
|
|
62
|
-
useSessionEvents(sessionId, cursor, onEvent)
|
|
203
|
+
// The feed reconnects from cursor(), the last seq applied.
|
|
204
|
+
pwCode.useSessionEvents(machine, sessionId, cursor, onEvent)
|
|
63
205
|
|
|
64
206
|
return {
|
|
65
207
|
messages: transcript?.messages ?? [],
|
|
@@ -74,17 +216,22 @@ function useSession(sessionId: string) {
|
|
|
74
216
|
`steer` hands text to the turn that is running and `withdraw` takes a queued
|
|
75
217
|
message back; without them every message sent during a turn waits for it to
|
|
76
218
|
end. `goalNotice`, `compactionNotice`, `recapNotice` and `words` supply the
|
|
77
|
-
transcript's own lines in the reader's language
|
|
78
|
-
|
|
219
|
+
transcript's own lines in the reader's language: `useGoalNotice()`,
|
|
220
|
+
`useCompactionNotice()`, `useRecapNotice()` and `useTranscriptWords()` give
|
|
221
|
+
them from this package's messages. `imageUrl` turns an image's `ref` into the URL the host serves it
|
|
222
|
+
from.
|
|
79
223
|
|
|
80
224
|
On the web, `SessionView` from `@parallelworks/ui/ai` draws these messages. A
|
|
81
225
|
host with its own components renders `ChatMessage` and its parts itself.
|
|
82
226
|
|
|
83
227
|
## No DOM
|
|
84
228
|
|
|
85
|
-
The build imports `react`, `luxon`
|
|
86
|
-
|
|
87
|
-
|
|
229
|
+
The build imports `react`, `luxon`, `swr`, `use-intl`, `gemoji` (for the
|
|
230
|
+
emoji shortcodes in a session's name), `@parallelworks/ui/ai/headless` and
|
|
231
|
+
`@parallelworks/ui/headless`, and its declarations `openapi-fetch` too, and
|
|
232
|
+
nothing else, so it loads where there
|
|
233
|
+
is no DOM: a React Native bundle, a server, a test. It opens sockets only
|
|
234
|
+
through the host's `openSocket`. The reducers need no React at all.
|
|
88
235
|
|
|
89
236
|
## Versions
|
|
90
237
|
|
package/dist/ago.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** "5m" since a time, in `@parallelworks/ui`'s `time` strings as a compact
|
|
2
|
+
* RelativeTime reads, for labels built into sentences and passed as strings.
|
|
3
|
+
* It re-reads every 30 seconds. */
|
|
4
|
+
export declare function useCompactAgo(): {
|
|
5
|
+
now: number;
|
|
6
|
+
compact: (iso: string | undefined) => string;
|
|
7
|
+
compactMinutes: (minutes: number) => string;
|
|
8
|
+
};
|
package/dist/ago.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useCallback, useMemo } from "react";
|
|
2
|
+
import { DateTime } from "luxon";
|
|
3
|
+
import { useClock, useStrings } from "@parallelworks/ui/headless";
|
|
4
|
+
// src/ago.ts
|
|
5
|
+
/** "5m" since a time, in `@parallelworks/ui`'s `time` strings as a compact
|
|
6
|
+
* RelativeTime reads, for labels built into sentences and passed as strings.
|
|
7
|
+
* It re-reads every 30 seconds. */
|
|
8
|
+
function useCompactAgo() {
|
|
9
|
+
const t = useStrings().time;
|
|
10
|
+
const tick = useClock((current) => Math.floor(current / 3e4));
|
|
11
|
+
const now = useMemo(() => DateTime.now().toMillis(), [tick]);
|
|
12
|
+
const compactMinutes = useCallback((minutes) => {
|
|
13
|
+
if (!Number.isFinite(minutes) || minutes < 1) return t.now;
|
|
14
|
+
if (minutes < 60) return t.minutes(minutes);
|
|
15
|
+
const hours = Math.floor(minutes / 60);
|
|
16
|
+
if (hours < 24) return t.hours(hours);
|
|
17
|
+
const days = Math.floor(hours / 24);
|
|
18
|
+
return days < 365 ? t.days(days) : t.years(Math.floor(days / 365));
|
|
19
|
+
}, [t]);
|
|
20
|
+
return {
|
|
21
|
+
now,
|
|
22
|
+
compact: useCallback((iso) => iso ? compactMinutes(Math.floor((now - DateTime.fromISO(iso).toMillis()) / 6e4)) : "", [now, compactMinutes]),
|
|
23
|
+
compactMinutes
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export { useCompactAgo };
|