@parallelworks/code 0.2.0 → 0.4.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 (126) hide show
  1. package/README.md +602 -84
  2. package/dist/accountApi.d.ts +31 -0
  3. package/dist/accountApi.js +182 -0
  4. package/dist/agentSwitcher.d.ts +109 -0
  5. package/dist/agentSwitcher.js +165 -0
  6. package/dist/ago.d.ts +8 -0
  7. package/dist/ago.js +26 -0
  8. package/dist/allocations.d.ts +41 -0
  9. package/dist/allocations.js +76 -0
  10. package/dist/api.d.ts +1213 -66
  11. package/dist/base64.d.ts +3 -0
  12. package/dist/base64.js +15 -0
  13. package/dist/chatHandoff.d.ts +12 -0
  14. package/dist/chatHandoff.js +27 -0
  15. package/dist/chatStrings.d.ts +188 -0
  16. package/dist/chatStrings.js +217 -0
  17. package/dist/claudeAccounts.d.ts +149 -0
  18. package/dist/claudeAccounts.js +328 -0
  19. package/dist/claudeApi.js +1 -1
  20. package/dist/claudeSignIn.d.ts +80 -0
  21. package/dist/claudeSignIn.js +249 -0
  22. package/dist/commandsApi.d.ts +11 -1
  23. package/dist/commandsApi.js +24 -5
  24. package/dist/contextRow.d.ts +25 -0
  25. package/dist/contextRow.js +16 -0
  26. package/dist/createPwCodeApi.d.ts +52 -5
  27. package/dist/createPwCodeApi.js +20 -2
  28. package/dist/directories.d.ts +161 -0
  29. package/dist/directories.js +301 -0
  30. package/dist/goal.d.ts +89 -0
  31. package/dist/goal.js +164 -0
  32. package/dist/howSessionsAppear.d.ts +12 -0
  33. package/dist/howSessionsAppear.js +24 -0
  34. package/dist/imageFit.d.ts +23 -0
  35. package/dist/imageFit.js +27 -0
  36. package/dist/images.d.ts +28 -0
  37. package/dist/images.js +38 -6
  38. package/dist/index.d.ts +41 -3
  39. package/dist/index.js +40 -4
  40. package/dist/loadError.d.ts +8 -0
  41. package/dist/loadError.js +19 -0
  42. package/dist/locales/en/agentTranscript.js +75 -22
  43. package/dist/locales/en/agents.js +76 -14
  44. package/dist/locales/en.d.ts +129 -21
  45. package/dist/locales/es/agentTranscript.js +75 -22
  46. package/dist/locales/es/agents.js +76 -14
  47. package/dist/locales/ja/agentTranscript.js +78 -25
  48. package/dist/locales/ja/agents.js +49 -124
  49. package/dist/locales/ko/agentTranscript.js +75 -22
  50. package/dist/locales/ko/agents.js +76 -14
  51. package/dist/locales/zh/agentTranscript.js +73 -20
  52. package/dist/locales/zh/agents.js +76 -14
  53. package/dist/machine.d.ts +4 -0
  54. package/dist/modelPicker.d.ts +79 -0
  55. package/dist/modelPicker.js +107 -0
  56. package/dist/models.d.ts +47 -0
  57. package/dist/models.js +49 -0
  58. package/dist/notices.d.ts +2 -1
  59. package/dist/notices.js +75 -21
  60. package/dist/platformDefaults.d.ts +22 -0
  61. package/dist/platformDefaults.js +30 -0
  62. package/dist/preferences.d.ts +78 -0
  63. package/dist/preferences.js +128 -0
  64. package/dist/pullRequestList.d.ts +60 -0
  65. package/dist/pullRequestList.js +125 -0
  66. package/dist/query.d.ts +6 -2
  67. package/dist/query.js +85 -10
  68. package/dist/session.d.ts +10 -2
  69. package/dist/session.js +12 -8
  70. package/dist/sessionActions.d.ts +115 -0
  71. package/dist/sessionActions.js +186 -0
  72. package/dist/sessionEvents.d.ts +8 -3
  73. package/dist/sessionEvents.js +10 -5
  74. package/dist/sessionGroups.d.ts +50 -0
  75. package/dist/sessionGroups.js +73 -0
  76. package/dist/sessionHeader.d.ts +14 -0
  77. package/dist/sessionHeader.js +16 -0
  78. package/dist/sessionList.d.ts +182 -0
  79. package/dist/sessionList.js +333 -0
  80. package/dist/sessionScreen.d.ts +193 -0
  81. package/dist/sessionScreen.js +213 -0
  82. package/dist/sessionsApi.d.ts +13 -3
  83. package/dist/sessionsApi.js +90 -33
  84. package/dist/settingsApi.d.ts +38 -0
  85. package/dist/settingsApi.js +151 -0
  86. package/dist/startPage.d.ts +153 -0
  87. package/dist/startPage.js +174 -0
  88. package/dist/startSession.d.ts +172 -0
  89. package/dist/startSession.js +256 -0
  90. package/dist/terminalHandoffPanel.d.ts +30 -0
  91. package/dist/terminalHandoffPanel.js +33 -0
  92. package/dist/transcript.d.ts +2 -0
  93. package/dist/transcript.js +62 -26
  94. package/dist/types.d.ts +11 -1
  95. package/dist/usageLimit.d.ts +8 -0
  96. package/dist/usageLimit.js +13 -0
  97. package/dist/useAwayRecap.d.ts +30 -0
  98. package/dist/useAwayRecap.js +75 -0
  99. package/dist/useComposer.d.ts +145 -0
  100. package/dist/useComposer.js +295 -0
  101. package/dist/useComposerImages.d.ts +71 -0
  102. package/dist/useComposerImages.js +218 -0
  103. package/dist/useComposerPastes.d.ts +70 -0
  104. package/dist/useComposerPastes.js +130 -0
  105. package/dist/useConversation.d.ts +199 -0
  106. package/dist/useConversation.js +314 -0
  107. package/dist/useSubagent.d.ts +104 -0
  108. package/dist/useSubagent.js +212 -0
  109. package/dist/useTranscript.d.ts +23 -3
  110. package/dist/useTranscript.js +76 -19
  111. package/dist/wording.js +2 -2
  112. package/dist/workingDirectories.d.ts +63 -0
  113. package/dist/workingDirectories.js +95 -0
  114. package/dist/worktreeChoice.d.ts +31 -0
  115. package/dist/worktreeChoice.js +38 -0
  116. package/locales/en/agentTranscript.json +69 -21
  117. package/locales/en/agents.json +73 -13
  118. package/locales/es/agentTranscript.json +69 -21
  119. package/locales/es/agents.json +73 -13
  120. package/locales/ja/agentTranscript.json +72 -24
  121. package/locales/ja/agents.json +73 -13
  122. package/locales/ko/agentTranscript.json +69 -21
  123. package/locales/ko/agents.json +73 -13
  124. package/locales/zh/agentTranscript.json +67 -19
  125. package/locales/zh/agents.json +73 -13
  126. package/package.json +6 -3
@@ -0,0 +1,107 @@
1
+ import { usePwCodeTranslations } from "./messages.js";
2
+ import { isClaudeModel, modelLabel, useModelCatalog } from "./models.js";
3
+ // src/modelPicker.ts
4
+ /** The issue that keeps a model's connection from serving it, if any. */
5
+ function providerIssueOf(issues, model) {
6
+ if (!model.provider_name) return;
7
+ return issues.find((issue) => issue.provider_name === model.provider_name && (issue.provider_owner ?? "") === (model.provider_owner ?? ""));
8
+ }
9
+ function groupDescription(model, issue, reader, t) {
10
+ const owner = model.provider_owner;
11
+ return [owner && owner !== "org" && owner !== reader ? t("modelPicker.sharedBy", { owner }) : "", issue ? issue.status === "unauthorized" ? t("providerIssue.keyRejected") : t("providerIssue.unreachable") : ""].filter(Boolean).join(" · ") || void 0;
12
+ }
13
+ /** The platform's models grouped by provider, the id's prefix. A connection
14
+ * that cannot serve its models leaves them listed, disabled, and its group
15
+ * says why; models another user shares name them. */
16
+ function modelGroups(models, issues, reader, t) {
17
+ const groups = /* @__PURE__ */ new Map();
18
+ for (const model of models) {
19
+ const key = model.id.split("/")[0] ?? model.provider ?? "";
20
+ const issue = providerIssueOf(issues, model);
21
+ let group = groups.get(key);
22
+ if (!group) {
23
+ group = {
24
+ label: model.provider || key,
25
+ description: groupDescription(model, issue, reader, t),
26
+ items: []
27
+ };
28
+ groups.set(key, group);
29
+ }
30
+ group.items = [...group.items, {
31
+ value: model.id,
32
+ label: modelLabel(model.id, model.name),
33
+ disabled: !!issue
34
+ }];
35
+ }
36
+ return [...groups.values()];
37
+ }
38
+ /** Why the platform offers no model: still loading, failed, or none. */
39
+ function platformModelStatus(list, t) {
40
+ if (list.error) return t("modelPicker.failed");
41
+ return list.isLoading ? t("modelPicker.loading") : t("modelPicker.none");
42
+ }
43
+ var ACCOUNTS_CHOICE = "claude-code-accounts";
44
+ var REFRESH_CHOICE = "refresh";
45
+ /** One picker for the platform's models and the machine's Claude ones. A
46
+ * model picked is remembered with the allocation it bills; the Claude
47
+ * accounts choice opens them instead, and the refresh choice reads both
48
+ * lists again. Which model and allocation stand before a pick is the host's. */
49
+ function useModelPicker(api, { machine, sessionId, claudeReady, canStart, account, open, model, allocation, platform, reader, names, errorMessage, remember, onAccounts }) {
50
+ const t = usePwCodeTranslations("agents");
51
+ const words = usePwCodeTranslations("agentTranscript");
52
+ const catalog = useModelCatalog(api, {
53
+ machine,
54
+ sessionId,
55
+ claudeReady,
56
+ canStart,
57
+ model: model.value,
58
+ account,
59
+ open
60
+ });
61
+ const groups = modelGroups(platform.models, platform.providerIssues, reader, words);
62
+ if (platform.models.length === 0) groups.push({
63
+ label: t("claude.platformModels"),
64
+ description: platformModelStatus(platform, words),
65
+ items: []
66
+ });
67
+ const claudeModels = catalog.models;
68
+ if (claudeReady) groups.push({
69
+ label: t("claude.models"),
70
+ description: catalog.error ? errorMessage(catalog.error) : catalog.isLoading ? t("claude.loadingModels") : void 0,
71
+ items: [...claudeModels.map((entry) => ({
72
+ value: entry.id,
73
+ label: modelLabel(entry.id, entry.name)
74
+ })), {
75
+ value: ACCOUNTS_CHOICE,
76
+ label: t("claude.accounts")
77
+ }]
78
+ });
79
+ const id = model.value ?? "";
80
+ const listed = platform.models.find((m) => m.id === model.value) ?? claudeModels.find((m) => m.id === model.value);
81
+ return {
82
+ entries: [...groups, {
83
+ value: REFRESH_CHOICE,
84
+ label: t("claude.refreshModels")
85
+ }],
86
+ label: modelLabel(id, names?.[id] ?? listed?.name) || words("modelPicker.select"),
87
+ opened: catalog.request,
88
+ pick: (value) => {
89
+ if (value === ACCOUNTS_CHOICE) onAccounts();
90
+ else if (value === REFRESH_CHOICE) {
91
+ catalog.refresh();
92
+ platform.refresh();
93
+ } else if (value) {
94
+ remember(value, allocation.value);
95
+ model.onChange(value);
96
+ }
97
+ },
98
+ allocation: isClaudeModel(model.value) ? null : {
99
+ ...allocation,
100
+ onChange: (next) => {
101
+ if (model.value) remember(model.value, next);
102
+ allocation.onChange(next);
103
+ }
104
+ }
105
+ };
106
+ }
107
+ export { modelGroups, platformModelStatus, providerIssueOf, useModelPicker };
@@ -0,0 +1,47 @@
1
+ import type { PwCodeApiError, Schemas } from './apiClient.js';
2
+ import type { PwCodeApi } from './createPwCodeApi.js';
3
+ /** A Claude Code subscription model, which bills no allocation. */
4
+ export declare const isClaudeModel: (model: string | null | undefined) => boolean;
5
+ /** Claude Code runs only where it is installed and its owner allows it. */
6
+ export declare function runsClaude(machine: {
7
+ claudeInstalled?: boolean | undefined;
8
+ claudeCodeAllowed?: boolean | undefined;
9
+ } | undefined): boolean;
10
+ /** Whether `model` is one the session could start on. A list still loading,
11
+ * or one that failed to load, is passed as undefined and keeps it. */
12
+ export declare function canRunModel(model: string | undefined, claudeReady: boolean, platformModels: readonly {
13
+ id: string;
14
+ }[] | undefined, claudeModels: readonly {
15
+ id: string;
16
+ }[] | undefined): boolean;
17
+ /** A model's name, or its id without the provider when it has none. */
18
+ export declare function modelLabel(id: string, name?: string, fallback?: string): string;
19
+ /** The picker a composer opens in place of sending: the model picker, or the
20
+ * Claude Code accounts. */
21
+ export type PwCodePicker = 'models' | 'claude' | null;
22
+ /** The picker a prompt typed as a command opens instead of being sent. */
23
+ export declare function pickerCommand(text: string): PwCodePicker;
24
+ /** The Claude models a model picker offers on a machine, and how their list stands. */
25
+ export interface PwCodeModelCatalog {
26
+ models: Schemas['AgentClaudeModel'][];
27
+ error: PwCodeApiError | undefined;
28
+ isLoading: boolean;
29
+ /** Asks for the list once the picker is opened, and keeps it after. */
30
+ request: () => void;
31
+ /** Asks the machine for its list again rather than the copy it keeps. */
32
+ refresh: () => void;
33
+ }
34
+ /** The machine's Claude models for a model picker. A session's own list is
35
+ * read only once the picker opens, since reading it adopts the session, which
36
+ * viewing it must not do; until then a Claude model chosen where a session
37
+ * could start reads the machine's. */
38
+ export declare function useModelCatalog(api: Pick<PwCodeApi, 'useClaudeModels'>, { machine, sessionId, claudeReady, canStart, model, account, open, }: {
39
+ machine: string;
40
+ sessionId?: string | undefined;
41
+ claudeReady: boolean;
42
+ canStart: boolean;
43
+ model: string | null | undefined;
44
+ account: string | undefined;
45
+ /** The picker is showing. */
46
+ open: boolean;
47
+ }): PwCodeModelCatalog;
package/dist/models.js ADDED
@@ -0,0 +1,49 @@
1
+ import { useState } from "react";
2
+ // src/models.ts
3
+ /** A Claude Code subscription model, which bills no allocation. */
4
+ var isClaudeModel = (model) => !!model?.startsWith("claude-code/");
5
+ /** Claude Code runs only where it is installed and its owner allows it. */
6
+ function runsClaude(machine) {
7
+ return machine?.claudeInstalled === true && machine.claudeCodeAllowed === true;
8
+ }
9
+ /** Whether `model` is one the session could start on. A list still loading,
10
+ * or one that failed to load, is passed as undefined and keeps it. */
11
+ function canRunModel(model, claudeReady, platformModels, claudeModels) {
12
+ if (isClaudeModel(model) && !claudeReady) return false;
13
+ const offered = isClaudeModel(model) ? claudeModels : platformModels;
14
+ return !offered || offered.some((m) => m.id === model);
15
+ }
16
+ /** A model's name, or its id without the provider when it has none. */
17
+ function modelLabel(id, name, fallback = "") {
18
+ return name || id.slice(id.indexOf("/") + 1) || fallback;
19
+ }
20
+ /** The picker a prompt typed as a command opens instead of being sent. */
21
+ function pickerCommand(text) {
22
+ switch (text.trim()) {
23
+ case "/model": return "models";
24
+ case "/claude-code":
25
+ case "/claude-code use": return "claude";
26
+ default: return null;
27
+ }
28
+ }
29
+ /** The machine's Claude models for a model picker. A session's own list is
30
+ * read only once the picker opens, since reading it adopts the session, which
31
+ * viewing it must not do; until then a Claude model chosen where a session
32
+ * could start reads the machine's. */
33
+ function useModelCatalog(api, { machine, sessionId, claudeReady, canStart, model, account, open }) {
34
+ const [requested, setRequested] = useState(false);
35
+ const [forceRefresh, setForceRefresh] = useState(false);
36
+ const hostCatalog = api.useClaudeModels(machine, void 0, account, claudeReady && canStart && isClaudeModel(model));
37
+ const local = api.useClaudeModels(machine, sessionId, account, claudeReady && (requested || open), forceRefresh);
38
+ return {
39
+ models: local.data ?? hostCatalog.data ?? [],
40
+ error: local.error,
41
+ isLoading: local.isLoading,
42
+ request: () => setRequested(true),
43
+ refresh: () => {
44
+ if (forceRefresh) local.mutate();
45
+ else setForceRefresh(true);
46
+ }
47
+ };
48
+ }
49
+ export { canRunModel, isClaudeModel, modelLabel, pickerCommand, runsClaude, useModelCatalog };
package/dist/notices.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { type PwCodeTranslator } from './messages.js';
2
- import type { CompactionNotice, RecapNotice, TranscriptWords } from './transcript.js';
2
+ import type { CompactionNotice, GoalNotice, RecapNotice, TranscriptWords } from './transcript.js';
3
3
  /** When a usage limit resets, as a session's notices name it. */
4
4
  export declare function useResumeTime(): (at: string) => string;
5
+ export declare function useGoalNotice(): GoalNotice;
5
6
  export declare function useCompactionNotice(): CompactionNotice;
6
7
  export declare function useRecapNotice(): RecapNotice;
7
8
  /** How long a turn took, as the terminal says it: 42s, 2m 5s, 1h 4m. */
package/dist/notices.js CHANGED
@@ -1,8 +1,10 @@
1
+ import { goalElapsed } from "./goal.js";
1
2
  import { usePwCodeTranslations } from "./messages.js";
2
3
  import { useCallback, useMemo } from "react";
3
- import { DateTime } from "luxon";
4
4
  import { sanitizeLabel } from "@parallelworks/ui/ai/headless";
5
- import { useFormatter } from "use-intl";
5
+ import { useFormatter, useLocale } from "use-intl";
6
+ import { DateTime } from "luxon";
7
+ import { formatDuration } from "@parallelworks/ui/headless";
6
8
  // src/notices.ts
7
9
  /** When a usage limit resets, as a session's notices name it. */
8
10
  function useResumeTime() {
@@ -12,6 +14,31 @@ function useResumeTime() {
12
14
  timeStyle: "short"
13
15
  }), [format]);
14
16
  }
17
+ function useGoalNotice() {
18
+ const t = usePwCodeTranslations("agents");
19
+ const format = useFormatter();
20
+ const locale = useLocale();
21
+ const resumeTime = useResumeTime();
22
+ return useCallback((p) => {
23
+ if (p.resumeAt) return t("detail.goalUsageLimit", { time: resumeTime(p.resumeAt) });
24
+ if (p.err) return t("detail.goalCheckFailed", { error: p.err });
25
+ if (p.outcome === "achieved") return t("detail.goalAchieved", {
26
+ elapsed: goalElapsed(p.elapsedMs ?? 0, "panel", locale),
27
+ turns: p.turns ?? 0,
28
+ tokens: format.number(p.tokens ?? 0, {
29
+ notation: "compact",
30
+ maximumFractionDigits: 1
31
+ })
32
+ });
33
+ if (p.waitedMs) return t("detail.goalCheckin", { waited: formatDuration(Math.floor(p.waitedMs / 6e4) * 6e4, locale) });
34
+ return t("detail.goalContinuing");
35
+ }, [
36
+ t,
37
+ format,
38
+ locale,
39
+ resumeTime
40
+ ]);
41
+ }
15
42
  function useCompactionNotice() {
16
43
  const t = usePwCodeTranslations("agents");
17
44
  return useMemo(() => ({
@@ -36,6 +63,48 @@ function turnDuration(t, ms) {
36
63
  minutes: Math.floor(total / 60) % 60
37
64
  });
38
65
  }
66
+ /** A monitor's line: the first line an event's script printed, or how the monitor ended. */
67
+ function monitorLine(t, n, name) {
68
+ const elapsed = turnDuration(t, n.elapsedMs ?? 0);
69
+ switch (n.ended) {
70
+ case "exited": return n.exitCode ? t("detail.monitorFailed", {
71
+ name,
72
+ code: n.exitCode
73
+ }) : t("detail.monitorEnded", { name });
74
+ case "expired": return t("detail.monitorExpired", {
75
+ name,
76
+ elapsed,
77
+ count: n.events ?? 0
78
+ });
79
+ case "flooded": return t("detail.monitorFlooded", {
80
+ name,
81
+ elapsed
82
+ });
83
+ default: return t("detail.monitorEvent", {
84
+ name,
85
+ line: n.preview
86
+ });
87
+ }
88
+ }
89
+ /** The line a background agent's report, a command's end or a monitor's notice enters the conversation with. */
90
+ function deliveryLine(t, n) {
91
+ const name = sanitizeLabel(n.description) || n.id;
92
+ if (n.monitor) return monitorLine(t, n, name);
93
+ if (n.interim) return t("detail.subagentMessage", { name });
94
+ if (n.shell) return n.exitCode ? t("detail.commandFailed", {
95
+ name,
96
+ code: n.exitCode
97
+ }) : t("detail.commandCompleted", { name });
98
+ const outcome = n.failed ? "failed" : "finished";
99
+ return n.elapsedMs ? t("detail.agentEndedAfter", {
100
+ name,
101
+ outcome,
102
+ elapsed: turnDuration(t, n.elapsedMs)
103
+ }) : t("detail.agentEnded", {
104
+ name,
105
+ outcome
106
+ });
107
+ }
39
108
  /** The session's own lines: what a goal step opens to, how a turn ended,
40
109
  * which plan a /plan showed, and how a background task reported back. */
41
110
  function useTranscriptWords() {
@@ -67,28 +136,13 @@ function useTranscriptWords() {
67
136
  });
68
137
  },
69
138
  planAnswer: (path, opened) => opened ? t("detail.planOpened", { path }) : path,
70
- deliveryLine: (n) => {
71
- const name = sanitizeLabel(n.description) || n.id;
72
- if (n.interim) return t("detail.subagentMessage", { name });
73
- if (n.shell) return n.exitCode ? t("detail.commandFailed", {
74
- name,
75
- code: n.exitCode
76
- }) : t("detail.commandCompleted", { name });
77
- const outcome = n.failed ? "failed" : "finished";
78
- return n.elapsedMs ? t("detail.agentEndedAfter", {
79
- name,
80
- outcome,
81
- elapsed: turnDuration(t, n.elapsedMs)
82
- }) : t("detail.agentEnded", {
83
- name,
84
- outcome
85
- });
86
- },
87
- allowDirectory: ({ path, subtree }) => subtree ? tTranscript("transcript.allowDirectoryTree", { path }) : tTranscript("transcript.allowDirectoryOnly", { path })
139
+ deliveryLine: (n) => deliveryLine(t, n),
140
+ allowDirectory: ({ path, subtree }) => subtree ? tTranscript("transcript.allowDirectoryTree", { path }) : tTranscript("transcript.allowDirectoryOnly", { path }),
141
+ mainConversation: t("switcher.main")
88
142
  }), [
89
143
  t,
90
144
  tTranscript,
91
145
  format
92
146
  ]);
93
147
  }
94
- export { turnDuration, useCompactionNotice, useRecapNotice, useResumeTime, useTranscriptWords };
148
+ export { turnDuration, useCompactionNotice, useGoalNotice, useRecapNotice, useResumeTime, useTranscriptWords };
@@ -0,0 +1,22 @@
1
+ import type { PwCodePlatformModels } from './accountApi.js';
2
+ import type { Schemas } from './apiClient.js';
3
+ import type { PwCodeApi } from './createPwCodeApi.js';
4
+ /** The platform model and allocation the AI chat selects, for a host with no
5
+ * chat to take them from. They fit `useStartModel`'s `platform`, and the
6
+ * allocation `useSessionSettings`'s `nativeAllocation`. */
7
+ export interface PwCodePlatformDefaults {
8
+ /** The platform's models, as `useModelPicker`'s `platform` takes them. */
9
+ list: PwCodePlatformModels;
10
+ /** The models once they load; undefined while they load or when they failed to. */
11
+ models: Schemas['ModelEntry'][] | undefined;
12
+ /** The chat model last chosen while the list still offers it, else the
13
+ * first whose provider has no issue, else the first; null until the list loads. */
14
+ model: string | null;
15
+ /** The allocation `model` bills: the first it can charge, once the
16
+ * allocations load; none for a model that bills none. */
17
+ allocation: string | null;
18
+ }
19
+ export declare function usePlatformDefaults(api: Pick<PwCodeApi, 'usePlatformModels' | 'useAllocations'>, { stored, }: {
20
+ /** The chat model last chosen, saved under `chatModelPreference`. */
21
+ stored: string | null | undefined;
22
+ }): PwCodePlatformDefaults;
@@ -0,0 +1,30 @@
1
+ import { aiAllocations, allocationProblem, billsAllocation } from "./allocations.js";
2
+ import { useMemo } from "react";
3
+ import { defaultAllocation, defaultModel } from "@parallelworks/ui/ai/headless";
4
+ // src/platformDefaults.ts
5
+ function usePlatformDefaults(api, { stored }) {
6
+ const list = api.usePlatformModels();
7
+ const model = defaultModel({
8
+ models: list.models,
9
+ providerIssues: list.providerIssues,
10
+ current: null,
11
+ stored: stored ?? null
12
+ });
13
+ const { data } = api.useAllocations(billsAllocation(model));
14
+ const allocations = useMemo(() => data ? aiAllocations(data).map((a) => ({
15
+ name: a.name,
16
+ total: a.total,
17
+ disabled: allocationProblem(a, false) !== null
18
+ })) : void 0, [data]);
19
+ return {
20
+ list,
21
+ models: list.loaded && !list.error ? list.models : void 0,
22
+ model,
23
+ allocation: defaultAllocation({
24
+ model,
25
+ allocations,
26
+ current: null
27
+ })
28
+ };
29
+ }
30
+ export { usePlatformDefaults };
@@ -0,0 +1,78 @@
1
+ import { type EffortLevel, type PermissionMode } from '@parallelworks/ui/ai/headless';
2
+ import { type Dispatch, type SetStateAction } from 'react';
3
+ import type { SessionGroup } from './sessionGroups.js';
4
+ import type { PwCodeLastModel } from './startSession.js';
5
+ /** A choice kept in the reader's account, which every client reads and
6
+ * writes under `key`; `fallback` stands until one is saved. */
7
+ export interface PwCodePreference<T> {
8
+ key: string;
9
+ fallback: T;
10
+ }
11
+ /** A preference as `useState` returns it: its value, and its setter. */
12
+ export type PwCodePreferenceState<T> = readonly [T, Dispatch<SetStateAction<T>>];
13
+ /** The key a preference is saved under in the account, which refuses a dot. */
14
+ export declare function preferenceKey(key: string): string;
15
+ export declare const startModePreference: PwCodePreference<PermissionMode>;
16
+ /** Empty starts a session at the machine's own pw code setting. */
17
+ export declare const startEffortPreference: PwCodePreference<string>;
18
+ /** The id of the machine new sessions were last started on. */
19
+ export declare const startMachinePreference: PwCodePreference<string>;
20
+ /** Each machine's account, by machine id. */
21
+ export declare const startAccountPreference: PwCodePreference<Record<string, string>>;
22
+ export declare const lastModelPreference: PwCodePreference<PwCodeLastModel>;
23
+ /** The model an AI chat last picked, which cannot be a Claude model. */
24
+ export declare const chatModelPreference: PwCodePreference<string | null>;
25
+ /** The keys of the session list's folded sections, which `useSessionList`
26
+ * takes as `folded`. */
27
+ export declare const foldedGroupsPreference: PwCodePreference<string[]>;
28
+ /** Whether a folder tree shows hidden folders, a choice the platform's file
29
+ * browser shares. */
30
+ export declare const showHiddenPreference: PwCodePreference<boolean>;
31
+ /** The reader's session groups, kept per user: a copy kept on a shared
32
+ * device would otherwise go to whoever signs in next, or to a user being
33
+ * impersonated. */
34
+ export declare function sessionGroupsPreference(userId: string): PwCodePreference<SessionGroup[]>;
35
+ /** The mode new sessions start in. Bypass is never kept, as in pw code, so a
36
+ * later session never starts in it unasked. */
37
+ export declare function useStartModePreference([saved, save,]: PwCodePreferenceState<PermissionMode>): {
38
+ saved: PermissionMode;
39
+ remember: (mode: PermissionMode) => void;
40
+ };
41
+ /** The effort new sessions start at; empty, or a level no longer offered,
42
+ * starts them at the machine's own. */
43
+ export declare function useStartEffortPreference([saved, save,]: PwCodePreferenceState<string>): {
44
+ saved: EffortLevel | '';
45
+ remember: (effort: string) => void;
46
+ };
47
+ /** The machine picked last, which `useStartLocation` starts on while it can. */
48
+ export declare function useStartMachinePreference([saved, save,]: PwCodePreferenceState<string>): {
49
+ saved: string | undefined;
50
+ remember: (id: string) => void;
51
+ };
52
+ /** The Claude Code account new sessions on `machine` start on. Kept per
53
+ * machine, whose accounts are its own, so a pick here never changes the one
54
+ * pw code starts on there. */
55
+ export declare function useStartAccountPreference([accounts, save]: PwCodePreferenceState<Record<string, string>>, machine: string | undefined): {
56
+ saved: string | undefined;
57
+ remember: (account: string) => void;
58
+ };
59
+ /** What an open session's settings report, so new sessions start where the
60
+ * reader last set one: the mode and effort as they are picked, and the
61
+ * account once the machine takes it, kept for that machine. Each follows
62
+ * its start preference's own rule. */
63
+ export declare function useStartDefaultsFromSession(preferences: {
64
+ mode: PwCodePreferenceState<PermissionMode>;
65
+ effort: PwCodePreferenceState<string>;
66
+ account: PwCodePreferenceState<Record<string, string>>;
67
+ }, machine: string): {
68
+ onModePicked: (mode: PermissionMode) => void;
69
+ onEffortPicked: (effort: string) => void;
70
+ onAccountSaved: (account: string) => void;
71
+ };
72
+ /** The model last picked for a session, and the allocation it billed. Kept
73
+ * apart from the chat's model, which cannot be a Claude one; a Claude pick
74
+ * bills no allocation, so the platform one waits for the next pick. */
75
+ export declare function useLastModelPreference([last, setLast,]: PwCodePreferenceState<PwCodeLastModel>): {
76
+ last: PwCodeLastModel;
77
+ remember: (model: string, allocation: string | null | undefined) => void;
78
+ };
@@ -0,0 +1,128 @@
1
+ import { useCallback } from "react";
2
+ import { isEffortLevel } from "@parallelworks/ui/ai/headless";
3
+ // src/preferences.ts
4
+ /** The key a preference is saved under in the account, which refuses a dot. */
5
+ function preferenceKey(key) {
6
+ return key.replaceAll(".", ":");
7
+ }
8
+ var startModePreference = {
9
+ key: "agents:startMode",
10
+ fallback: "auto"
11
+ };
12
+ /** Empty starts a session at the machine's own pw code setting. */
13
+ var startEffortPreference = {
14
+ key: "agents:startEffort",
15
+ fallback: ""
16
+ };
17
+ /** The id of the machine new sessions were last started on. */
18
+ var startMachinePreference = {
19
+ key: "agents:startMachine",
20
+ fallback: ""
21
+ };
22
+ /** Each machine's account, by machine id. */
23
+ var startAccountPreference = {
24
+ key: "agents:startAccount",
25
+ fallback: {}
26
+ };
27
+ var lastModelPreference = {
28
+ key: "agents:lastModel",
29
+ fallback: {}
30
+ };
31
+ /** The model an AI chat last picked, which cannot be a Claude model. */
32
+ var chatModelPreference = {
33
+ key: "aiChat:model",
34
+ fallback: null
35
+ };
36
+ /** The keys of the session list's folded sections, which `useSessionList`
37
+ * takes as `folded`. */
38
+ var foldedGroupsPreference = {
39
+ key: "aiChatSidebarCollapsedGroups",
40
+ fallback: []
41
+ };
42
+ /** Whether a folder tree shows hidden folders, a choice the platform's file
43
+ * browser shares. */
44
+ var showHiddenPreference = {
45
+ key: "computeExplorer:showHidden",
46
+ fallback: false
47
+ };
48
+ var NO_GROUPS = [];
49
+ /** The reader's session groups, kept per user: a copy kept on a shared
50
+ * device would otherwise go to whoever signs in next, or to a user being
51
+ * impersonated. */
52
+ function sessionGroupsPreference(userId) {
53
+ return {
54
+ key: `agentsSessionGroups:${userId}`,
55
+ fallback: NO_GROUPS
56
+ };
57
+ }
58
+ /** The mode new sessions start in. Bypass is never kept, as in pw code, so a
59
+ * later session never starts in it unasked. */
60
+ function useStartModePreference([saved, save]) {
61
+ return {
62
+ saved,
63
+ remember: useCallback((mode) => {
64
+ if (mode !== "bypass-permissions") save(mode);
65
+ }, [save])
66
+ };
67
+ }
68
+ /** The effort new sessions start at; empty, or a level no longer offered,
69
+ * starts them at the machine's own. */
70
+ function useStartEffortPreference([saved, save]) {
71
+ const remember = useCallback((effort) => save(isEffortLevel(effort) ? effort : ""), [save]);
72
+ return {
73
+ saved: isEffortLevel(saved) ? saved : "",
74
+ remember
75
+ };
76
+ }
77
+ /** The machine picked last, which `useStartLocation` starts on while it can. */
78
+ function useStartMachinePreference([saved, save]) {
79
+ const remember = useCallback((id) => save(id), [save]);
80
+ return {
81
+ saved: typeof saved === "string" && saved ? saved : void 0,
82
+ remember
83
+ };
84
+ }
85
+ /** The Claude Code account new sessions on `machine` start on. Kept per
86
+ * machine, whose accounts are its own, so a pick here never changes the one
87
+ * pw code starts on there. */
88
+ function useStartAccountPreference([accounts, save], machine) {
89
+ const remember = useCallback((account) => {
90
+ if (machine) save((previous) => ({
91
+ ...previous,
92
+ [machine]: account
93
+ }));
94
+ }, [machine, save]);
95
+ const saved = machine ? accounts[machine] : void 0;
96
+ return {
97
+ saved: typeof saved === "string" ? saved : void 0,
98
+ remember
99
+ };
100
+ }
101
+ /** What an open session's settings report, so new sessions start where the
102
+ * reader last set one: the mode and effort as they are picked, and the
103
+ * account once the machine takes it, kept for that machine. Each follows
104
+ * its start preference's own rule. */
105
+ function useStartDefaultsFromSession(preferences, machine) {
106
+ const { remember: onModePicked } = useStartModePreference(preferences.mode);
107
+ const { remember: onEffortPicked } = useStartEffortPreference(preferences.effort);
108
+ const { remember: onAccountSaved } = useStartAccountPreference(preferences.account, machine);
109
+ return {
110
+ onModePicked,
111
+ onEffortPicked,
112
+ onAccountSaved
113
+ };
114
+ }
115
+ /** The model last picked for a session, and the allocation it billed. Kept
116
+ * apart from the chat's model, which cannot be a Claude one; a Claude pick
117
+ * bills no allocation, so the platform one waits for the next pick. */
118
+ function useLastModelPreference([last, setLast]) {
119
+ const remember = (model, allocation) => setLast((previous) => ({
120
+ model,
121
+ allocation: allocation || previous.allocation
122
+ }));
123
+ return {
124
+ last,
125
+ remember
126
+ };
127
+ }
128
+ export { chatModelPreference, foldedGroupsPreference, lastModelPreference, preferenceKey, sessionGroupsPreference, showHiddenPreference, startAccountPreference, startEffortPreference, startMachinePreference, startModePreference, useLastModelPreference, useStartAccountPreference, useStartDefaultsFromSession, useStartEffortPreference, useStartMachinePreference, useStartModePreference };
@@ -0,0 +1,60 @@
1
+ import type { PwCodeTranslator } from './messages.js';
2
+ export type PullRequestState = 'open' | 'draft' | 'merged' | 'closed';
3
+ export declare function isPullRequestState(state: string | undefined): state is PullRequestState;
4
+ /** A pull or merge request's link and its `pullRequestLabel`. */
5
+ export type LabeledPullRequest = {
6
+ url: string;
7
+ pr: string;
8
+ };
9
+ /** The URLs that are plain GitHub pull requests or GitLab merge requests, each with its `pullRequestLabel`. */
10
+ export declare function labeledPullRequests(urls: readonly string[] | null | undefined): LabeledPullRequest[];
11
+ /** A pull request's state by its URL; undefined until one is read. */
12
+ export type PullRequestStateOf = (url: string) => string | undefined;
13
+ /** Reads a state from a session's pull request reads, or from the
14
+ * `pullRequestStates` a listed session carries. */
15
+ export declare function pullRequestStateOf(states: readonly {
16
+ url: string;
17
+ state?: string | undefined;
18
+ }[] | Readonly<Record<string, string>> | null | undefined): PullRequestStateOf;
19
+ /** Drafts, then open, merged and closed pull requests, the newest first within each; one whose state is unknown counts as open. */
20
+ export declare function orderPullRequests(pullRequests: readonly LabeledPullRequest[], stateOf: PullRequestStateOf): LabeledPullRequest[];
21
+ /** Whether each pull request folds into the merged-or-closed count rather than the open one. */
22
+ export declare function pullRequestFoldGroups(ordered: readonly LabeledPullRequest[], stateOf: PullRequestStateOf): boolean[];
23
+ /** Once a listed session's row has this many merged and closed pull requests to fold, they fold into their count even when they fit. */
24
+ export declare const FOLD_DONE_PULL_REQUESTS_FROM = 2;
25
+ /** How many of `ordered` fold whether or not they fit: its merged and closed ones, which come last, once there are `from` of them to fold; the first stays when every one is merged or closed. */
26
+ export declare function donePullRequestsToFold(ordered: readonly LabeledPullRequest[], stateOf: PullRequestStateOf, from?: number): number;
27
+ /** Folded pull requests count apart while open or draft and once merged or closed; `all` counts every one, for a line with room for nothing else. */
28
+ export type PullRequestFoldGroup = 'open' | 'done' | 'all';
29
+ export type PullRequestFold = {
30
+ shown: LabeledPullRequest[];
31
+ groups: {
32
+ group: Exclude<PullRequestFoldGroup, 'all'>;
33
+ pullRequests: LabeledPullRequest[];
34
+ }[];
35
+ };
36
+ /** `ordered` but its last `folded`, which fold into an open count and a merged-or-closed one; a group with none is left out. */
37
+ export declare function foldPullRequests(ordered: readonly LabeledPullRequest[], folded: number, stateOf: PullRequestStateOf): PullRequestFold;
38
+ /** The state a folded group shows: open over draft, and merged over closed. */
39
+ export declare function pullRequestGroupState(group: readonly LabeledPullRequest[], stateOf: PullRequestStateOf): PullRequestState | undefined;
40
+ /** Whether each pull request's state differs from the one before it, where a list marks the change. */
41
+ export declare function pullRequestStateBreaks(pullRequests: readonly LabeledPullRequest[], stateOf: PullRequestStateOf): boolean[];
42
+ /** The tone a pull request's state shows in, as the forges color them: `done`
43
+ * is their purple for merged work. */
44
+ export type PullRequestTone = 'success' | 'muted' | 'done' | 'error';
45
+ export declare function pullRequestTone(state: PullRequestState): PullRequestTone;
46
+ type Translate = PwCodeTranslator<'agents'>;
47
+ export interface PullRequestWords {
48
+ /** A pull request's tooltip, naming its state once it is known. */
49
+ title: (pr: string, state: string | undefined) => string;
50
+ /** A known state's name, which its icon is labeled with. */
51
+ state: (state: PullRequestState) => string;
52
+ /** How many pull requests a count folds away. */
53
+ more: (count: number) => string;
54
+ /** What a folded group's list is called. */
55
+ groupTitle: (group: PullRequestFoldGroup, count: number) => string;
56
+ /** The control that lists a folded group. */
57
+ showGroup: (group: Exclude<PullRequestFoldGroup, 'all'>, count: number) => string;
58
+ }
59
+ export declare function pullRequestWords(t: Translate): PullRequestWords;
60
+ export {};