@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.
Files changed (118) hide show
  1. package/README.md +171 -24
  2. package/dist/ago.d.ts +8 -0
  3. package/dist/ago.js +26 -0
  4. package/dist/api.d.ts +3547 -0
  5. package/dist/apiClient.d.ts +26 -0
  6. package/dist/apiClient.js +5 -0
  7. package/dist/base64.d.ts +3 -0
  8. package/dist/base64.js +15 -0
  9. package/dist/chatHandoff.d.ts +12 -0
  10. package/dist/chatHandoff.js +27 -0
  11. package/dist/claudeAccounts.d.ts +112 -0
  12. package/dist/claudeAccounts.js +234 -0
  13. package/dist/claudeApi.d.ts +27 -0
  14. package/dist/claudeApi.js +250 -0
  15. package/dist/claudeSignIn.d.ts +62 -0
  16. package/dist/claudeSignIn.js +239 -0
  17. package/dist/command.d.ts +47 -0
  18. package/dist/command.js +64 -0
  19. package/dist/commandsApi.d.ts +64 -0
  20. package/dist/commandsApi.js +267 -0
  21. package/dist/contextRow.d.ts +25 -0
  22. package/dist/contextRow.js +16 -0
  23. package/dist/createPwCodeApi.d.ts +696 -0
  24. package/dist/createPwCodeApi.js +33 -0
  25. package/dist/howSessionsAppear.d.ts +12 -0
  26. package/dist/howSessionsAppear.js +24 -0
  27. package/dist/index.d.ts +39 -3
  28. package/dist/index.js +38 -3
  29. package/dist/locales/en/agentTranscript.js +162 -0
  30. package/dist/locales/en/agents.js +380 -0
  31. package/dist/locales/en.d.ts +523 -0
  32. package/dist/locales/en.js +8 -0
  33. package/dist/locales/es/agentTranscript.js +162 -0
  34. package/dist/locales/es/agents.js +380 -0
  35. package/dist/locales/es.d.ts +3 -0
  36. package/dist/locales/es.js +8 -0
  37. package/dist/locales/ja/agentTranscript.js +162 -0
  38. package/dist/locales/ja/agents.js +380 -0
  39. package/dist/locales/ja.d.ts +3 -0
  40. package/dist/locales/ja.js +8 -0
  41. package/dist/locales/ko/agentTranscript.js +162 -0
  42. package/dist/locales/ko/agents.js +380 -0
  43. package/dist/locales/ko.d.ts +3 -0
  44. package/dist/locales/ko.js +8 -0
  45. package/dist/locales/zh/agentTranscript.js +162 -0
  46. package/dist/locales/zh/agents.js +380 -0
  47. package/dist/locales/zh.d.ts +3 -0
  48. package/dist/locales/zh.js +8 -0
  49. package/dist/machine.d.ts +51 -0
  50. package/dist/machine.js +60 -0
  51. package/dist/messages.d.ts +17 -0
  52. package/dist/messages.js +31 -0
  53. package/dist/models.d.ts +47 -0
  54. package/dist/models.js +49 -0
  55. package/dist/notices.d.ts +12 -0
  56. package/dist/notices.js +120 -0
  57. package/dist/pullRequest.d.ts +8 -0
  58. package/dist/pullRequest.js +29 -0
  59. package/dist/pullRequestList.d.ts +52 -0
  60. package/dist/pullRequestList.js +106 -0
  61. package/dist/query.d.ts +28 -0
  62. package/dist/query.js +25 -0
  63. package/dist/session.d.ts +75 -1
  64. package/dist/session.js +101 -1
  65. package/dist/sessionActions.d.ts +105 -0
  66. package/dist/sessionActions.js +178 -0
  67. package/dist/sessionEvents.d.ts +27 -0
  68. package/dist/sessionEvents.js +212 -0
  69. package/dist/sessionGroups.d.ts +49 -0
  70. package/dist/sessionGroups.js +72 -0
  71. package/dist/sessionHeader.d.ts +14 -0
  72. package/dist/sessionHeader.js +16 -0
  73. package/dist/sessionList.d.ts +134 -0
  74. package/dist/sessionList.js +271 -0
  75. package/dist/sessionsApi.d.ts +105 -0
  76. package/dist/sessionsApi.js +511 -0
  77. package/dist/settingsApi.d.ts +36 -0
  78. package/dist/settingsApi.js +151 -0
  79. package/dist/startSession.d.ts +138 -0
  80. package/dist/startSession.js +234 -0
  81. package/dist/terminalHandoffPanel.d.ts +30 -0
  82. package/dist/terminalHandoffPanel.js +33 -0
  83. package/dist/toolStrings.d.ts +4 -0
  84. package/dist/toolStrings.js +95 -0
  85. package/dist/transcript.d.ts +14 -1
  86. package/dist/transcript.js +55 -14
  87. package/dist/types.d.ts +20 -1
  88. package/dist/usageLimit.d.ts +8 -0
  89. package/dist/usageLimit.js +13 -0
  90. package/dist/useAwayRecap.d.ts +30 -0
  91. package/dist/useAwayRecap.js +75 -0
  92. package/dist/useComposer.d.ts +121 -0
  93. package/dist/useComposer.js +244 -0
  94. package/dist/useComposerImages.d.ts +66 -0
  95. package/dist/useComposerImages.js +195 -0
  96. package/dist/useConversation.d.ts +190 -0
  97. package/dist/useConversation.js +287 -0
  98. package/dist/useSubagent.d.ts +58 -0
  99. package/dist/useSubagent.js +149 -0
  100. package/dist/useTranscript.d.ts +4 -1
  101. package/dist/useTranscript.js +54 -11
  102. package/dist/wording.d.ts +43 -0
  103. package/dist/wording.js +101 -0
  104. package/dist/workingDirectories.d.ts +32 -0
  105. package/dist/workingDirectories.js +71 -0
  106. package/dist/worktreeChoice.d.ts +31 -0
  107. package/dist/worktreeChoice.js +38 -0
  108. package/locales/en/agentTranscript.json +154 -0
  109. package/locales/en/agents.json +366 -0
  110. package/locales/es/agentTranscript.json +154 -0
  111. package/locales/es/agents.json +366 -0
  112. package/locales/ja/agentTranscript.json +154 -0
  113. package/locales/ja/agents.json +366 -0
  114. package/locales/ko/agentTranscript.json +154 -0
  115. package/locales/ko/agents.json +366 -0
  116. package/locales/zh/agentTranscript.json +154 -0
  117. package/locales/zh/agents.json +366 -0
  118. package/package.json +24 -9
@@ -0,0 +1,26 @@
1
+ import type { Client } from 'openapi-fetch';
2
+ import type { SWRResponse } from 'swr';
3
+ import type { components, paths } from './api.js';
4
+ /** The routes this package calls, as the platform's OpenAPI spec types them. A
5
+ * host's client typed over the whole spec has them all. */
6
+ export type PwCodePaths = paths;
7
+ export type PwCodeComponents = components;
8
+ export type PwCodeClient = Client<PwCodePaths>;
9
+ export type Schemas = components['schemas'];
10
+ /** The body of a refusal: the platform's error, with its stable `code`. */
11
+ export type PwCodeApiError = Schemas['Error'];
12
+ /** A data hook's state, as SWR keeps it. */
13
+ export type PwCodeQuery<Data> = SWRResponse<Data, PwCodeApiError>;
14
+ /** What a call resolves to, as the API client returns it. */
15
+ export type PwCodeResult<Data> = {
16
+ data: Data;
17
+ error?: never;
18
+ response: Response;
19
+ } | {
20
+ data?: never;
21
+ error: PwCodeApiError;
22
+ response: Response;
23
+ };
24
+ /** The key prefix `@parallelworks/client/swr`'s hooks use by default, so a host
25
+ * that reads these routes through them shares this package's cache entries. */
26
+ export declare const QUERY_KEY_PREFIX = "api";
@@ -0,0 +1,5 @@
1
+ // src/apiClient.ts
2
+ /** The key prefix `@parallelworks/client/swr`'s hooks use by default, so a host
3
+ * that reads these routes through them shares this package's cache entries. */
4
+ var QUERY_KEY_PREFIX = "api";
5
+ export { QUERY_KEY_PREFIX };
@@ -0,0 +1,3 @@
1
+ export declare function bytesToBase64(bytes: Uint8Array): string;
2
+ /** Decodes base64, URL-safe or not, padded or not. */
3
+ export declare function base64ToBytes(data: string): Uint8Array;
package/dist/base64.js ADDED
@@ -0,0 +1,15 @@
1
+ // src/base64.ts
2
+ function bytesToBase64(bytes) {
3
+ let binary = "";
4
+ for (let i = 0; i < bytes.length; i += 32768) binary += String.fromCharCode(...bytes.subarray(i, i + 32768));
5
+ return btoa(binary);
6
+ }
7
+ /** Decodes base64, URL-safe or not, padded or not. */
8
+ function base64ToBytes(data) {
9
+ const base64 = data.replace(/-/g, "+").replace(/_/g, "/");
10
+ const binary = atob(base64 + "=".repeat((4 - base64.length % 4) % 4));
11
+ const bytes = new Uint8Array(binary.length);
12
+ for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
13
+ return bytes;
14
+ }
15
+ export { base64ToBytes, bytesToBase64 };
@@ -0,0 +1,12 @@
1
+ import type { PwCodeTranslator } from './messages.js';
2
+ /** The parts of an AI chat conversation a session started from it reads. */
3
+ export interface PwCodeHandoffChat {
4
+ title?: string | null | undefined;
5
+ messages?: readonly {
6
+ role: string;
7
+ content?: string | null | undefined;
8
+ }[] | null | undefined;
9
+ }
10
+ /** The first turn of a session started from a chat: the reader's task, then
11
+ * the conversation it continues, newest messages kept when it is long. */
12
+ export declare function chatHandoffPrompt(conversation: PwCodeHandoffChat, task: string, t: PwCodeTranslator<'agents'>): string;
@@ -0,0 +1,27 @@
1
+ // src/chatHandoff.ts
2
+ var HANDOFF_MAX_CHARS = 5e4;
3
+ /** The first turn of a session started from a chat: the reader's task, then
4
+ * the conversation it continues, newest messages kept when it is long. */
5
+ function chatHandoffPrompt(conversation, task, t) {
6
+ const turns = (conversation.messages ?? []).flatMap((m) => {
7
+ const text = m.content?.trim();
8
+ if (!text || m.role !== "user" && m.role !== "assistant") return [];
9
+ return [`## ${m.role === "user" ? t("start.handoffUser") : t("start.handoffAssistant")}\n\n${text}`];
10
+ });
11
+ const kept = [];
12
+ let size = 0;
13
+ for (let i = turns.length - 1; i >= 0; i--) {
14
+ const turn = turns[i] ?? "";
15
+ if (kept.length > 0 && size + turn.length > HANDOFF_MAX_CHARS) break;
16
+ kept.unshift(turn);
17
+ size += turn.length;
18
+ }
19
+ const omitted = turns.length - kept.length;
20
+ return [
21
+ task.trim() || t("start.handoffDefaultTask"),
22
+ t("start.handoffIntro", { title: conversation.title || "" }),
23
+ ...omitted > 0 ? [t("start.handoffOmitted", { count: omitted })] : [],
24
+ kept.join("\n\n")
25
+ ].join("\n\n");
26
+ }
27
+ export { chatHandoffPrompt };
@@ -0,0 +1,112 @@
1
+ import type { BoundSetting } from '@parallelworks/ui/ai/headless';
2
+ import type { Schemas } from './apiClient.js';
3
+ import type { claudeApi } from './claudeApi.js';
4
+ export type ClaudeAccount = Schemas['AgentClaudeAccount'];
5
+ /** The account hooks of `createPwCodeApi`. */
6
+ export type ClaudeAccountCalls = Pick<ReturnType<typeof claudeApi>, 'useClaudeAccounts' | 'useRefreshClaudeModels' | 'useRemoveClaudeAccount'>;
7
+ /** What the account panel shows: the list, or one step taken from it. */
8
+ export type ClaudeAccountView = {
9
+ kind: 'list';
10
+ } | {
11
+ kind: 'add';
12
+ } | {
13
+ kind: 'signIn';
14
+ account: string;
15
+ } | {
16
+ kind: 'remove';
17
+ account: string;
18
+ };
19
+ export interface ClaudeAccountAction {
20
+ kind: 'use' | 'signIn' | 'signInAgain' | 'remove';
21
+ label: string;
22
+ destructive: boolean;
23
+ run: () => void;
24
+ }
25
+ export interface ClaudeAccountPanelState {
26
+ /** Claude Code is allowed and installed on the machine. */
27
+ available: boolean;
28
+ view: ClaudeAccountView;
29
+ accounts: ClaudeAccount[];
30
+ loading: boolean;
31
+ loadedUsage: boolean;
32
+ /** Why the list or its last refresh failed. */
33
+ error: unknown;
34
+ /** Loaded, without error, and holding no account. */
35
+ empty: boolean;
36
+ refreshing: boolean;
37
+ canAdd: boolean;
38
+ isDisabled: (account: ClaudeAccount) => boolean;
39
+ /** Picks a row: an account that needs signing in opens its sign-in. */
40
+ choose: (account: ClaudeAccount) => void;
41
+ /** Makes the account the setting's value and closes the panel. */
42
+ select: (name: string) => void;
43
+ /** What a row's menu offers, empty while the setting can't change. */
44
+ actions: (account: ClaudeAccount) => ClaudeAccountAction[];
45
+ add: () => void;
46
+ startSignIn: (name: string) => void;
47
+ /** Reloads the list and models once the sign-in shown has completed. */
48
+ finishSignIn: () => void;
49
+ /** Selects the account just signed in, unless the setting can't change. */
50
+ selectSignedIn: (() => void) | undefined;
51
+ /** Leaves the step shown for the list; leaving a sign-in reloads it. */
52
+ back: () => void;
53
+ refresh: () => Promise<void>;
54
+ /** Signs the account out and deletes it, then returns to the list. A
55
+ * selected account falls back to `default`. */
56
+ removeAccount: (name: string) => Promise<void>;
57
+ }
58
+ /** The refusal of a read that needs the account signed in first. */
59
+ export declare function claudeSignInRequired(error: unknown): boolean;
60
+ /** The account name `input` gives once trimmed, or null when Claude Code
61
+ * can't take it. */
62
+ export declare function claudeAccountName(input: string): string | null;
63
+ /** The Claude Code accounts on a machine, and the steps a panel listing them
64
+ * takes: adding, signing in, removing after a confirmation the host shows,
65
+ * and choosing one for the `account` setting. */
66
+ export declare function useClaudeAccountPanel(calls: ClaudeAccountCalls, { machine, sessionId, claudeInstalled, claudeAllowed, claudeLogin, claudeAccountRemove, account, onClose, }: {
67
+ machine: string;
68
+ sessionId?: string | undefined;
69
+ claudeInstalled: boolean;
70
+ claudeAllowed: boolean;
71
+ /** The machine can sign accounts in from here. */
72
+ claudeLogin?: boolean | undefined;
73
+ /** The machine can remove accounts from here. */
74
+ claudeAccountRemove?: boolean | undefined;
75
+ account: BoundSetting;
76
+ onClose: () => void;
77
+ }): ClaudeAccountPanelState;
78
+ /** The confirmation of a removal: whether it runs, and why it last failed. */
79
+ export declare function useClaudeAccountRemoval(remove: () => Promise<void>): {
80
+ pending: boolean;
81
+ error: unknown;
82
+ confirm: () => Promise<void>;
83
+ };
84
+ /** The name field of a new account, which continues to its sign-in only with
85
+ * a name Claude Code can take. */
86
+ export declare function useClaudeAccountName(onContinue: (name: string) => void): {
87
+ name: string;
88
+ invalid: boolean;
89
+ change: (value: string) => void;
90
+ submit: () => void;
91
+ };
92
+ export interface ClaudeUsageReset {
93
+ /** When, as "resets Fri, Oct 30, 5:00 PM". */
94
+ at: string;
95
+ countdown: string;
96
+ /** The countdown for a narrow row. */
97
+ shortCountdown: string;
98
+ }
99
+ export interface ClaudeUsageLimit {
100
+ window: 'fiveHour' | 'week';
101
+ label: string;
102
+ /** Percent of the window used; undefined when not reported. */
103
+ used: number | undefined;
104
+ reset: ClaudeUsageReset | null;
105
+ }
106
+ export interface ClaudeAccountUsage {
107
+ /** Shown in place of the limits, which are then empty. */
108
+ status: string | null;
109
+ limits: ClaudeUsageLimit[];
110
+ }
111
+ /** An account's usage limits as its row words them. */
112
+ export declare function useClaudeAccountUsage(account: ClaudeAccount, loaded: boolean): ClaudeAccountUsage;
@@ -0,0 +1,234 @@
1
+ import { usePwCodeTranslations } from "./messages.js";
2
+ import { useEffect, useRef, useState } from "react";
3
+ import { DateTime } from "luxon";
4
+ import { useFormatter } from "use-intl";
5
+ // src/claudeAccounts.ts
6
+ var signInRequiredCode = "agents_claude_sign_in_required";
7
+ /** The refusal of a read that needs the account signed in first. */
8
+ function claudeSignInRequired(error) {
9
+ return error?.code === signInRequiredCode;
10
+ }
11
+ /** The account name `input` gives once trimmed, or null when Claude Code
12
+ * can't take it. */
13
+ function claudeAccountName(input) {
14
+ const name = input.trim();
15
+ if (!/^[a-zA-Z0-9_.@-]{1,64}$/.test(name) || name === "." || name === ".." || name.endsWith(".lock")) return null;
16
+ return name;
17
+ }
18
+ /** The Claude Code accounts on a machine, and the steps a panel listing them
19
+ * takes: adding, signing in, removing after a confirmation the host shows,
20
+ * and choosing one for the `account` setting. */
21
+ function useClaudeAccountPanel(calls, { machine, sessionId, claudeInstalled, claudeAllowed, claudeLogin = false, claudeAccountRemove = false, account, onClose }) {
22
+ const t = usePwCodeTranslations("agents");
23
+ const [adding, setAdding] = useState(false);
24
+ const [signIn, setSignIn] = useState(null);
25
+ const [removing, setRemoving] = useState(null);
26
+ const [refreshError, setRefreshError] = useState(null);
27
+ const [refreshingModels, setRefreshingModels] = useState(false);
28
+ const available = claudeAllowed && claudeInstalled;
29
+ const catalog = calls.useClaudeAccounts(machine, sessionId, available);
30
+ const refreshModels = calls.useRefreshClaudeModels(machine, sessionId);
31
+ const deleteAccount = calls.useRemoveClaudeAccount(machine, sessionId);
32
+ const selected = account.value || void 0;
33
+ const disabled = useRef(account.disabled);
34
+ disabled.current = account.disabled;
35
+ useEffect(() => {
36
+ if (!available || !claudeLogin) {
37
+ setSignIn(null);
38
+ setAdding(false);
39
+ }
40
+ }, [available, claudeLogin]);
41
+ useEffect(() => {
42
+ if (!available || !claudeAccountRemove) setRemoving(null);
43
+ }, [available, claudeAccountRemove]);
44
+ const refresh = async (signedInAccount) => {
45
+ const signedInSelected = signedInAccount !== void 0 && signedInAccount === selected;
46
+ setRefreshError(null);
47
+ setRefreshingModels(true);
48
+ try {
49
+ await Promise.all([
50
+ catalog.refresh(),
51
+ claudeLogin && refreshModels(selected).catch((cause) => {
52
+ if (signedInSelected || !claudeSignInRequired(cause)) throw cause;
53
+ }),
54
+ ...signedInAccount !== void 0 && !signedInSelected && claudeLogin ? [refreshModels(signedInAccount)] : []
55
+ ]);
56
+ } catch (cause) {
57
+ setRefreshError(cause);
58
+ } finally {
59
+ setRefreshingModels(false);
60
+ }
61
+ };
62
+ const select = (name) => {
63
+ account.onChange(name);
64
+ onClose();
65
+ };
66
+ const unlessDisabled = (run) => () => {
67
+ if (!disabled.current) run();
68
+ };
69
+ const actions = (a) => {
70
+ if (account.disabled) return [];
71
+ const entries = [];
72
+ if (!a.signInRequired) entries.push({
73
+ kind: "use",
74
+ label: t("claude.useAccount"),
75
+ destructive: false,
76
+ run: unlessDisabled(() => select(a.name))
77
+ });
78
+ if (claudeLogin) entries.push({
79
+ kind: a.signInRequired ? "signIn" : "signInAgain",
80
+ label: a.signInRequired ? t("claude.signIn") : t("claude.signInAgain"),
81
+ destructive: false,
82
+ run: unlessDisabled(() => setSignIn(a.name))
83
+ });
84
+ if (claudeAccountRemove && a.name !== "default") entries.push({
85
+ kind: "remove",
86
+ label: t("claude.remove"),
87
+ destructive: true,
88
+ run: unlessDisabled(() => setRemoving(a.name))
89
+ });
90
+ return entries;
91
+ };
92
+ const view = signIn !== null && claudeLogin ? {
93
+ kind: "signIn",
94
+ account: signIn
95
+ } : adding ? { kind: "add" } : removing !== null ? {
96
+ kind: "remove",
97
+ account: removing
98
+ } : { kind: "list" };
99
+ return {
100
+ available,
101
+ view,
102
+ accounts: catalog.accounts,
103
+ loading: catalog.loading,
104
+ loadedUsage: catalog.loadedUsage,
105
+ error: catalog.error || refreshError,
106
+ empty: !catalog.loading && !catalog.error && catalog.accounts.length === 0,
107
+ refreshing: catalog.refreshing || refreshingModels,
108
+ canAdd: claudeLogin && !account.disabled,
109
+ isDisabled: (a) => !!account.disabled || !!a.signInRequired && !claudeLogin,
110
+ choose: (a) => {
111
+ if (a.signInRequired && claudeLogin) {
112
+ setSignIn(a.name);
113
+ return;
114
+ }
115
+ select(a.name);
116
+ },
117
+ select,
118
+ actions,
119
+ add: () => setAdding(true),
120
+ startSignIn: (name) => {
121
+ setSignIn(name);
122
+ setAdding(false);
123
+ },
124
+ finishSignIn: () => {
125
+ if (signIn !== null) refresh(signIn);
126
+ },
127
+ selectSignedIn: view.kind === "signIn" && !account.disabled ? () => select(view.account) : void 0,
128
+ back: () => {
129
+ if (view.kind === "signIn") {
130
+ setSignIn(null);
131
+ refresh();
132
+ } else if (view.kind === "remove") setRemoving(null);
133
+ else setAdding(false);
134
+ },
135
+ refresh: () => refresh(),
136
+ removeAccount: async (name) => {
137
+ await deleteAccount(name);
138
+ if (account.value === name && !account.disabled) account.onChange("default");
139
+ setRemoving(null);
140
+ }
141
+ };
142
+ }
143
+ /** The confirmation of a removal: whether it runs, and why it last failed. */
144
+ function useClaudeAccountRemoval(remove) {
145
+ const [pending, setPending] = useState(false);
146
+ const [error, setError] = useState(null);
147
+ const confirm = async () => {
148
+ setPending(true);
149
+ setError(null);
150
+ try {
151
+ await remove();
152
+ } catch (cause) {
153
+ setError(cause);
154
+ } finally {
155
+ setPending(false);
156
+ }
157
+ };
158
+ return {
159
+ pending,
160
+ error,
161
+ confirm
162
+ };
163
+ }
164
+ /** The name field of a new account, which continues to its sign-in only with
165
+ * a name Claude Code can take. */
166
+ function useClaudeAccountName(onContinue) {
167
+ const [name, setName] = useState("");
168
+ const [invalid, setInvalid] = useState(false);
169
+ return {
170
+ name,
171
+ invalid,
172
+ change: (value) => {
173
+ setName(value);
174
+ setInvalid(false);
175
+ },
176
+ submit: () => {
177
+ const valid = claudeAccountName(name);
178
+ if (valid === null) {
179
+ setInvalid(true);
180
+ return;
181
+ }
182
+ setInvalid(false);
183
+ onContinue(valid);
184
+ }
185
+ };
186
+ }
187
+ /** An account's usage limits as its row words them. */
188
+ function useClaudeAccountUsage(account, loaded) {
189
+ const t = usePwCodeTranslations("agents");
190
+ const format = useFormatter();
191
+ const status = account.signInRequired ? t("claude.signedOut") : account.error ? t("claude.usageUnavailable") : !loaded ? t("claude.loadingUsage") : null;
192
+ if (status) return {
193
+ status,
194
+ limits: []
195
+ };
196
+ const reset = (resetsAt) => {
197
+ const at = resetsAt ? DateTime.fromISO(resetsAt) : null;
198
+ if (!at?.isValid) return null;
199
+ const minutes = Math.max(0, Math.ceil(at.diffNow("minutes").minutes));
200
+ const unit = minutes >= 1440 ? "day" : minutes >= 60 ? "hour" : "minute";
201
+ const duration = format.number(Math.ceil(minutes / (unit === "day" ? 1440 : unit === "hour" ? 60 : 1)), {
202
+ style: "unit",
203
+ unit,
204
+ unitDisplay: "narrow"
205
+ });
206
+ return {
207
+ at: t("claude.resets", { time: format.dateTime(at.toJSDate(), {
208
+ weekday: "short",
209
+ month: "short",
210
+ day: "numeric",
211
+ hour: "numeric",
212
+ minute: "2-digit",
213
+ timeZoneName: "short"
214
+ }) }),
215
+ countdown: t("claude.resetsIn", { time: duration }),
216
+ shortCountdown: t("claude.resetsInShort", { time: duration })
217
+ };
218
+ };
219
+ return {
220
+ status: null,
221
+ limits: [{
222
+ window: "fiveHour",
223
+ label: t("claude.fiveHourColumn"),
224
+ used: account.fiveHourUsedPercent,
225
+ reset: reset(account.fiveHourResetsAt)
226
+ }, {
227
+ window: "week",
228
+ label: t("claude.weekColumn"),
229
+ used: account.weeklyUsedPercent,
230
+ reset: reset(account.weeklyResetsAt)
231
+ }]
232
+ };
233
+ }
234
+ export { claudeAccountName, claudeSignInRequired, useClaudeAccountName, useClaudeAccountPanel, useClaudeAccountRemoval, useClaudeAccountUsage };
@@ -0,0 +1,27 @@
1
+ import { type PwCodeApiError, type PwCodeClient, type PwCodeQuery, type Schemas } from './apiClient.js';
2
+ type ClaudeAccount = Schemas['AgentClaudeAccount'];
3
+ type ClaudeModels = Schemas['AgentClaudeModel'][] | null;
4
+ type ClaudeAccounts = ClaudeAccount[] | null;
5
+ export type ClaudeLoginEvent = Schemas['AgentClaudeLoginEvent'];
6
+ export type ClaudeLogin = ClaudeLoginEvent['login'];
7
+ export type ClaudeLoginInput = Schemas['AgentClaudeLoginInput'];
8
+ export declare function claudeLoginFinished(status: ClaudeLogin['status']): boolean;
9
+ export declare function claudeApi(client: PwCodeClient): {
10
+ useClaudeModels: (machine: string, sessionId: string | undefined, account: string | undefined, enabled: boolean, refresh?: boolean) => PwCodeQuery<ClaudeModels>;
11
+ useRefreshClaudeModels: (machine: string, sessionId: string | undefined) => (account: string | undefined) => Promise<void>;
12
+ useClaudeAccountNames: (machine: string, enabled: boolean) => PwCodeQuery<ClaudeAccounts>;
13
+ useClaudeAccounts: (machine: string, sessionId: string | undefined, enabled: boolean) => {
14
+ accounts: ClaudeAccount[];
15
+ loadedUsage: boolean;
16
+ loading: boolean;
17
+ error: PwCodeApiError | undefined;
18
+ refreshing: boolean;
19
+ refresh: () => Promise<void>;
20
+ };
21
+ useRemoveClaudeAccount: (machine: string, sessionId: string | undefined) => (name: string) => Promise<void>;
22
+ startClaudeLogin: (machine: string, account: string, sessionId: string | undefined, columns: number, rows: number) => Promise<ClaudeLoginEvent>;
23
+ writeClaudeLogin: (machine: string, loginId: string, input: ClaudeLoginInput) => Promise<void>;
24
+ cancelClaudeLogin: (machine: string, loginId: string) => Promise<void>;
25
+ followClaudeLogin: (machine: string, login: ClaudeLogin, after: number, signal: AbortSignal, receive: (event: ClaudeLoginEvent) => void) => Promise<void>;
26
+ };
27
+ export {};