@bridgebrew/sessions 0.0.7 → 0.0.9
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/browser/decision-questions.tsx +3 -3
- package/browser/index.tsx +12 -3
- package/browser/mobile.tsx +8 -2
- package/package.json +1 -1
- package/server.ts +10 -3
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// field where a free answer is allowed, and one Submit for the whole request (enabled once every required question has
|
|
4
4
|
// an answer, `checkAnswer`), beside Dismiss.
|
|
5
5
|
import * as React from 'react';
|
|
6
|
-
import { Button, Checkbox, Icon, Textarea, cn } from '@bridge/ui';
|
|
6
|
+
import { Button, Checkbox, Icon, Textarea, cn, isComposing } from '@bridge/ui';
|
|
7
7
|
import { checkAnswer, type Answers, type Question } from '../answers.ts';
|
|
8
8
|
|
|
9
9
|
export function DecisionQuestions({
|
|
@@ -161,8 +161,8 @@ export function DecisionQuestions({
|
|
|
161
161
|
setChosen((was) => ({ ...was, [question.id]: [] }));
|
|
162
162
|
}}
|
|
163
163
|
onKeyDown={(event) => {
|
|
164
|
-
// ⌘↵ submits the request; ↵ alone is a new line.
|
|
165
|
-
if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {
|
|
164
|
+
// ⌘↵ submits the request; ↵ alone is a new line; an input method's ↵ is its own.
|
|
165
|
+
if (event.key === 'Enter' && (event.metaKey || event.ctrlKey) && !isComposing(event)) {
|
|
166
166
|
event.preventDefault();
|
|
167
167
|
event.currentTarget.form?.requestSubmit();
|
|
168
168
|
}
|
package/browser/index.tsx
CHANGED
|
@@ -1398,6 +1398,12 @@ function Sessions({
|
|
|
1398
1398
|
if ((cause as Error)?.name !== 'AbortError')
|
|
1399
1399
|
setError(cause instanceof Error ? cause.message : String(cause));
|
|
1400
1400
|
};
|
|
1401
|
+
/** A queued message the queue started meanwhile (plugins#91): said so, and the queue shown as it is now. */
|
|
1402
|
+
const started = (cause: unknown) => {
|
|
1403
|
+
if ((cause as { code?: unknown })?.code !== 'not_found') return report(cause);
|
|
1404
|
+
setError('This message has already been sent');
|
|
1405
|
+
void load();
|
|
1406
|
+
};
|
|
1401
1407
|
// Stable: the views' fallback (`renderComponent`) takes it, and a new one would redraw every turn (bridge#193).
|
|
1402
1408
|
const post = React.useCallback(
|
|
1403
1409
|
(path: string, body: object) =>
|
|
@@ -2194,6 +2200,9 @@ function Sessions({
|
|
|
2194
2200
|
onKey.current = (event) => {
|
|
2195
2201
|
// Another window is the one the user works in, or a modal dialog is open over the page: the keys are its own.
|
|
2196
2202
|
if (focused === false || modalOpen()) return;
|
|
2203
|
+
// A key of an input method's composition (Japanese, Chinese, Korean…) is the composition's: the Escape that cancels
|
|
2204
|
+
// a conversion never counts toward stopping the turn (#90).
|
|
2205
|
+
if (isComposing(event)) return;
|
|
2197
2206
|
// Escape twice within a second stops the running turn (a dialog, a menu or a popup list open takes the first one;
|
|
2198
2207
|
// the session lists, always there, do not count).
|
|
2199
2208
|
if (
|
|
@@ -2529,12 +2538,12 @@ function Sessions({
|
|
|
2529
2538
|
prompt?.addText(id, item.text, back);
|
|
2530
2539
|
promptHandle.current?.focus();
|
|
2531
2540
|
return load();
|
|
2532
|
-
},
|
|
2541
|
+
}, started);
|
|
2533
2542
|
}}
|
|
2534
2543
|
onRemove={(item) =>
|
|
2535
2544
|
void post(`/queue/remove?id=${encodeURIComponent(session.id)}`, { item }).then(
|
|
2536
2545
|
load,
|
|
2537
|
-
|
|
2546
|
+
started,
|
|
2538
2547
|
)
|
|
2539
2548
|
}
|
|
2540
2549
|
/>
|
|
@@ -2903,7 +2912,7 @@ function Sessions({
|
|
|
2903
2912
|
onKeyDown={(event) => {
|
|
2904
2913
|
if (event.key === 'Enter' && !isComposing(event))
|
|
2905
2914
|
event.currentTarget.blur();
|
|
2906
|
-
else if (event.key === 'Escape') {
|
|
2915
|
+
else if (event.key === 'Escape' && !isComposing(event)) {
|
|
2907
2916
|
setDraft(undefined);
|
|
2908
2917
|
requestAnimationFrame(() => titleField.current?.blur());
|
|
2909
2918
|
}
|
package/browser/mobile.tsx
CHANGED
|
@@ -405,6 +405,12 @@ function MobileSession({
|
|
|
405
405
|
if ((cause as Error)?.name !== 'AbortError')
|
|
406
406
|
setError(cause instanceof Error ? cause.message : String(cause));
|
|
407
407
|
};
|
|
408
|
+
/** A queued message the queue started meanwhile (plugins#91): said so, and the queue shown as it is now. */
|
|
409
|
+
const started = (cause: unknown) => {
|
|
410
|
+
if ((cause as { code?: unknown })?.code !== 'not_found') return report(cause);
|
|
411
|
+
setError('This message has already been sent');
|
|
412
|
+
void load();
|
|
413
|
+
};
|
|
408
414
|
const post = (path: string, body: object) =>
|
|
409
415
|
workspace
|
|
410
416
|
.fetch(`${api}${path}`, {
|
|
@@ -626,12 +632,12 @@ function MobileSession({
|
|
|
626
632
|
prompt?.addText(id, queued.text, back);
|
|
627
633
|
promptHandle.current?.focus();
|
|
628
634
|
return load();
|
|
629
|
-
},
|
|
635
|
+
}, started);
|
|
630
636
|
}}
|
|
631
637
|
onRemove={(queued) =>
|
|
632
638
|
void post(`/queue/remove?id=${encodeURIComponent(id)}`, {
|
|
633
639
|
item: queued,
|
|
634
|
-
}).then(load,
|
|
640
|
+
}).then(load, started)
|
|
635
641
|
}
|
|
636
642
|
/>
|
|
637
643
|
)}
|
package/package.json
CHANGED
package/server.ts
CHANGED
|
@@ -888,12 +888,16 @@ const unwoken = ({ wokeAt: _at, ...rest }: Session): Session => rest;
|
|
|
888
888
|
const imagesLabel = (attachments: { name: string }[]) =>
|
|
889
889
|
attachments.length === 1 ? `Image: ${attachments[0]!.name}` : `${attachments.length} images`;
|
|
890
890
|
|
|
891
|
+
/** Under the desktop app, `process.execPath` is the app's own binary: it runs the CLI only as Node
|
|
892
|
+
* (`ELECTRON_RUN_AS_NODE`), which an agent's processes do not inherit (the host's guard keeps it from them). */
|
|
893
|
+
const asNode = () => process.versions.electron !== undefined;
|
|
894
|
+
|
|
891
895
|
/** The `bridge` command on workspace `slug`, with absolute paths: the host gives its workers `BRIDGE_HOST_CLI` and
|
|
892
896
|
* `BRIDGE_HOST_ROOT`, but an agent's shell may not get them (Hermes keeps only its own allowlist). */
|
|
893
897
|
const bridgeCommand = (slug: string) => {
|
|
894
898
|
const { BRIDGE_HOST_CLI: cli, BRIDGE_HOST_ROOT: root } = process.env;
|
|
895
899
|
return cli && root
|
|
896
|
-
?
|
|
900
|
+
? `${asNode() ? 'ELECTRON_RUN_AS_NODE=1 ' : ''}"${process.execPath}" "${cli}" --root "${root}" --workspace ${slug}`
|
|
897
901
|
: `bridge --workspace ${slug}`;
|
|
898
902
|
};
|
|
899
903
|
|
|
@@ -966,10 +970,11 @@ const mcpServers = (slug: string, token?: string, worktree?: string) => {
|
|
|
966
970
|
name: 'bridge',
|
|
967
971
|
command: process.execPath,
|
|
968
972
|
args: [cli, 'mcp', '--root', root, '--workspace', worktree ?? slug],
|
|
969
|
-
...((token !== undefined || worktree !== undefined) && {
|
|
973
|
+
...((token !== undefined || worktree !== undefined || asNode()) && {
|
|
970
974
|
env: {
|
|
971
975
|
...(token !== undefined && { BRIDGE_MCP_TOKEN: token }),
|
|
972
976
|
...(worktree !== undefined && { BRIDGE_MCP_PARENT: slug }),
|
|
977
|
+
...(asNode() && { ELECTRON_RUN_AS_NODE: '1' }),
|
|
973
978
|
},
|
|
974
979
|
}),
|
|
975
980
|
approved: UNASKED_TOOLS,
|
|
@@ -5003,8 +5008,10 @@ export async function apply(ctx: Context, config?: unknown) {
|
|
|
5003
5008
|
handle: async ({ query, body }) => {
|
|
5004
5009
|
const found = await find(query);
|
|
5005
5010
|
const { item } = parse(queuedBody, body, 'POST /sessions/queue/remove takes { item }');
|
|
5011
|
+
// A message the queue has already started is refused, as Send now: Edit then does not copy it back (plugins#91).
|
|
5006
5012
|
await change(found.id, ({ queue, ...now }) => {
|
|
5007
|
-
|
|
5013
|
+
if (!queue?.some((each) => each.id === item)) throw refused('not_found', `no queued message ${item}`, 404);
|
|
5014
|
+
const rest = queue.filter((each) => each.id !== item);
|
|
5008
5015
|
return rest.length ? { ...now, queue: rest } : now;
|
|
5009
5016
|
});
|
|
5010
5017
|
emit(found.id, { type: 'queue' });
|