mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-30 20:25:50 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4abe1e9ca0 |
@@ -1583,7 +1583,11 @@ export const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
|
||||
const autoSend = sendAfterTranscriptRef.current;
|
||||
sendAfterTranscriptRef.current = false;
|
||||
applyDictationTranscript(text, {
|
||||
value: valueRef.current,
|
||||
input: getComposerInputSnapshot(
|
||||
textInputRef.current,
|
||||
valueRef.current,
|
||||
selectionRef.current,
|
||||
),
|
||||
defaultSendBehavior,
|
||||
isAgentRunning,
|
||||
onQueue,
|
||||
|
||||
@@ -172,11 +172,37 @@ describe("dictation keyboard behavior", () => {
|
||||
});
|
||||
|
||||
describe("dictation transcript behavior", () => {
|
||||
it("inserts dictated words into the paragraph at the cursor", () => {
|
||||
const value = "Intro: \n\nKeep this as the second paragraph.";
|
||||
let draft = value;
|
||||
let selection = { start: 7, end: 7 };
|
||||
|
||||
applyDictationTranscript("Spoken words.", {
|
||||
input: { text: value, selection: { start: 7, end: 7 } },
|
||||
defaultSendBehavior: "interrupt" as const,
|
||||
isAgentRunning: false,
|
||||
onQueue: undefined,
|
||||
replaceText: (text, caret) => {
|
||||
draft = text;
|
||||
selection = caret ?? selection;
|
||||
},
|
||||
onSubmit: () => {
|
||||
throw new Error("Insert must leave the message unsent");
|
||||
},
|
||||
attachments: [],
|
||||
cwd: "/repo",
|
||||
autoSend: false,
|
||||
});
|
||||
|
||||
expect(draft).toBe("Intro: Spoken words.\n\nKeep this as the second paragraph.");
|
||||
expect(selection).toEqual({ start: 20, end: 20 });
|
||||
});
|
||||
|
||||
it("publishes an auto-sent transcript to the composer before submitting it", () => {
|
||||
const actions: string[] = [];
|
||||
|
||||
applyDictationTranscript("spoken prompt", {
|
||||
value: "typed context",
|
||||
input: { text: "typed context", selection: { start: 13, end: 13 } },
|
||||
defaultSendBehavior: "interrupt",
|
||||
isAgentRunning: false,
|
||||
onQueue: undefined,
|
||||
|
||||
@@ -3,6 +3,8 @@ import type { DaemonClient } from "@getpaseo/client/internal/daemon-client";
|
||||
import type { ActiveTurnBehavior } from "@getpaseo/protocol/messages";
|
||||
import type { MessagePayload, TextReplacement } from "@/composer/types";
|
||||
import type { MessageInputKeyboardActionKind } from "@/keyboard/actions";
|
||||
import { insertAtSelection } from "../insert-text";
|
||||
import type { ComposerInputSnapshot } from "./input";
|
||||
|
||||
export type SendBehavior = ActiveTurnBehavior | "queue";
|
||||
|
||||
@@ -56,12 +58,12 @@ interface SendActionContext {
|
||||
}
|
||||
|
||||
interface DictationTranscriptContext {
|
||||
value: string;
|
||||
input: ComposerInputSnapshot;
|
||||
defaultSendBehavior: SendBehavior;
|
||||
isAgentRunning: boolean;
|
||||
onQueue: ((payload: MessagePayload) => void) | undefined;
|
||||
onSubmit: (payload: MessagePayload) => void;
|
||||
replaceText: (text: string) => void;
|
||||
replaceText: (text: string, selection?: ComposerInputSnapshot["selection"]) => void;
|
||||
attachments: MessagePayload["attachments"];
|
||||
cwd: string;
|
||||
autoSend: boolean;
|
||||
@@ -69,24 +71,27 @@ interface DictationTranscriptContext {
|
||||
|
||||
export function applyDictationTranscript(text: string, ctx: DictationTranscriptContext): void {
|
||||
if (!text) return;
|
||||
const shouldPad = ctx.value.length > 0 && !/\s$/.test(ctx.value);
|
||||
const nextValue = `${ctx.value}${shouldPad ? " " : ""}${text}`;
|
||||
const selection = resolveRetainedSelection(ctx.input.selection, ctx.input.text.length);
|
||||
const before = ctx.input.text.slice(0, selection.start);
|
||||
const after = ctx.input.text.slice(selection.end);
|
||||
const leadingSpace = /\S$/.test(before) ? " " : "";
|
||||
const trailingSpace = /^[\p{L}\p{N}]/u.test(after) ? " " : "";
|
||||
const next = insertAtSelection(
|
||||
{ text: ctx.input.text, selection },
|
||||
`${leadingSpace}${text}${trailingSpace}`,
|
||||
);
|
||||
|
||||
if (!ctx.autoSend) {
|
||||
ctx.replaceText(nextValue);
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.replaceText(nextValue);
|
||||
ctx.replaceText(next.text, next.selection);
|
||||
if (!ctx.autoSend) return;
|
||||
|
||||
if (ctx.defaultSendBehavior === "queue" && ctx.isAgentRunning && ctx.onQueue) {
|
||||
ctx.onQueue({ text: nextValue, attachments: ctx.attachments, cwd: ctx.cwd });
|
||||
ctx.onQueue({ text: next.text, attachments: ctx.attachments, cwd: ctx.cwd });
|
||||
ctx.replaceText("");
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.onSubmit({
|
||||
text: nextValue,
|
||||
text: next.text,
|
||||
attachments: ctx.attachments,
|
||||
cwd: ctx.cwd,
|
||||
forceSend: ctx.isAgentRunning || undefined,
|
||||
|
||||
Reference in New Issue
Block a user