@agents24/chat-react 0.5.46 → 0.5.48
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 +31 -1
- package/dist/{chunk-YRUYJFPJ.js → chunk-3UKX2RRE.js} +2 -5
- package/dist/chunk-3UKX2RRE.js.map +1 -0
- package/dist/generated/run-usage.d.ts +2 -0
- package/dist/index.cjs +1 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/registry/agents24-chat.json +16 -16
- package/dist/runtime/index.cjs +7 -1
- package/dist/runtime/index.cjs.map +1 -1
- package/dist/runtime/index.js +7 -1
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/use-agent-chat-runtime.d.ts +7 -0
- package/dist/scaffold/app.d.ts +5 -3
- package/dist/scaffold/components/chat/chat-composer.d.ts +4 -2
- package/dist/scaffold/components/chat/chat-message.d.ts +3 -2
- package/dist/scaffold/components/chat/chat-shell.d.ts +3 -2
- package/dist/scaffold/components/chat/message-parts.d.ts +3 -2
- package/dist/scaffold/index.cjs +284 -384
- package/dist/scaffold/index.cjs.map +1 -1
- package/dist/scaffold/index.d.ts +1 -1
- package/dist/scaffold/index.js +267 -366
- package/dist/scaffold/index.js.map +1 -1
- package/dist/styles.css +41 -5
- package/dist/ui/agent-chat-composer.d.ts +4 -1
- package/dist/ui/agent-chat-message.d.ts +3 -1
- package/dist/ui/agent-response-timeline.d.ts +3 -2
- package/dist/ui/attachment-text.d.ts +14 -0
- package/dist/ui/bubble.d.ts +1 -1
- package/dist/ui/completed-tool-activity.d.ts +36 -0
- package/dist/ui/composer-attachments.d.ts +2 -0
- package/dist/ui/index.cjs +2412 -1439
- package/dist/ui/index.cjs.map +1 -1
- package/dist/ui/index.d.ts +6 -0
- package/dist/ui/index.js +2340 -1371
- package/dist/ui/index.js.map +1 -1
- package/dist/ui/message-response.d.ts +1 -1
- package/dist/ui/microphone-input.d.ts +24 -0
- package/dist/ui/pcm-capture.d.ts +14 -0
- package/dist/ui/realtime-dictation.d.ts +30 -0
- package/dist/ui/tool-sessions.d.ts +18 -2
- package/dist/ui/use-agent-chat-composer.d.ts +7 -2
- package/dist/ui/use-agent-chat-dictation.d.ts +65 -0
- package/dist/ui/voice-dictation.d.ts +32 -0
- package/package.json +5 -4
- package/scaffold/src/app.tsx +13 -4
- package/scaffold/src/chat.css +0 -1
- package/scaffold/src/components/chat/chat-composer.tsx +29 -25
- package/scaffold/src/components/chat/chat-message.tsx +4 -1
- package/scaffold/src/components/chat/chat-shell.tsx +8 -3
- package/scaffold/src/components/chat/external-link-dialog.tsx +30 -20
- package/scaffold/src/components/chat/message-parts.tsx +4 -1
- package/scaffold/src/index.tsx +1 -0
- package/dist/chunk-YRUYJFPJ.js.map +0 -1
|
@@ -4,4 +4,4 @@ export type MessageResponseProps = React.ComponentProps<typeof Streamdown> & {
|
|
|
4
4
|
streaming?: boolean;
|
|
5
5
|
streamingId?: string;
|
|
6
6
|
};
|
|
7
|
-
export declare const MessageResponse: React.MemoExoticComponent<({ children, className, components, rehypePlugins, streaming, streamingId, ...props }: MessageResponseProps) => import("react/jsx-runtime").JSX.Element>;
|
|
7
|
+
export declare const MessageResponse: React.MemoExoticComponent<({ children, className, components, linkSafety, urlTransform, rehypePlugins, streaming, streamingId, ...props }: MessageResponseProps) => import("react/jsx-runtime").JSX.Element>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { DictationPhase } from './voice-dictation';
|
|
2
|
+
/** One microphone entry point. The user explicitly chooses when both input modes are available. */
|
|
3
|
+
export declare function MicrophoneInput({ dictation, audioEnabled, onRecorded, scopeKey, acceptedMimeTypes, disabled, className, onRecordingChange, onStreamChange, onStartAudio, chooseLabel, dictationLabel, audioLabel, stopLabel, }: {
|
|
4
|
+
dictation?: {
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
phase: DictationPhase;
|
|
7
|
+
start(): unknown;
|
|
8
|
+
stop(): unknown;
|
|
9
|
+
cancel(): unknown;
|
|
10
|
+
};
|
|
11
|
+
audioEnabled?: boolean;
|
|
12
|
+
onRecorded(file: File): void;
|
|
13
|
+
scopeKey?: string | null;
|
|
14
|
+
acceptedMimeTypes?: readonly string[];
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
className?: string;
|
|
17
|
+
onRecordingChange?(active: boolean): void;
|
|
18
|
+
onStreamChange?(stream: MediaStream | null): void;
|
|
19
|
+
onStartAudio?(): void;
|
|
20
|
+
chooseLabel?: string;
|
|
21
|
+
dictationLabel?: string;
|
|
22
|
+
audioLabel?: string;
|
|
23
|
+
stopLabel?: string;
|
|
24
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Captures one microphone stream as bounded mono PCM16; never creates an audio file. */
|
|
2
|
+
declare const processorSource = "\nclass DictationPcm extends AudioWorkletProcessor {\n constructor(options) {\n super();\n this.rate = options.processorOptions.targetRate;\n this.buffer = new Int16Array(this.rate / 10);\n this.offset = this.phase = this.sum = this.count = 0;\n this.port.onmessage = event => {\n if (event.data === 'flush') {\n if (this.offset) this.emit();\n this.port.postMessage('flushed');\n }\n };\n }\n emit() {\n const bytes = new ArrayBuffer(this.offset * 2);\n const view = new DataView(bytes);\n for (let i = 0; i < this.offset; i++) view.setInt16(i * 2, this.buffer[i], true);\n this.port.postMessage(bytes, [bytes]);\n this.offset = 0;\n }\n process(inputs) {\n const samples = inputs[0]?.[0];\n if (!samples) return true;\n for (const value of samples) {\n this.sum += value; this.count++; this.phase += this.rate;\n if (this.phase >= sampleRate) {\n const normalized = Math.max(-1, Math.min(1, this.sum / this.count));\n this.buffer[this.offset++] = Math.round(normalized * (normalized < 0 ? 32768 : 32767));\n this.phase -= sampleRate; this.sum = this.count = 0;\n if (this.offset === this.buffer.length) this.emit();\n }\n }\n return true;\n }\n}\nregisterProcessor('agents24-dictation-pcm', DictationPcm);";
|
|
3
|
+
export declare function captureDictationPcm(options: {
|
|
4
|
+
stream: MediaStream;
|
|
5
|
+
sampleRate: number;
|
|
6
|
+
onFrame(frame: Uint8Array): void;
|
|
7
|
+
onError(): void;
|
|
8
|
+
/** Hosts with a restrictive CSP can serve the package-owned worklet from this URL. */
|
|
9
|
+
workletUrl?: string;
|
|
10
|
+
}): Promise<{
|
|
11
|
+
cancel: () => void;
|
|
12
|
+
stop(): Promise<void>;
|
|
13
|
+
}>;
|
|
14
|
+
export { processorSource as dictationPcmWorkletSource };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type AgentClient, type DictationFeature } from "@agents24/client";
|
|
2
|
+
import type { DictationIntent, DictationState } from "./voice-dictation";
|
|
3
|
+
export type RealtimeDictationOptions = {
|
|
4
|
+
client: Pick<AgentClient, "dictation">;
|
|
5
|
+
agentId?: string;
|
|
6
|
+
feature: DictationFeature;
|
|
7
|
+
workletUrl?: string;
|
|
8
|
+
};
|
|
9
|
+
/** One recording, one provider connection, one finalization, no file fallback. */
|
|
10
|
+
export declare class RealtimeDictation<Draft> {
|
|
11
|
+
private callbacks;
|
|
12
|
+
private operation;
|
|
13
|
+
private phase;
|
|
14
|
+
constructor(callbacks: {
|
|
15
|
+
options(): RealtimeDictationOptions;
|
|
16
|
+
canCommit(): boolean;
|
|
17
|
+
onState(value: DictationState): void;
|
|
18
|
+
onStream(value: MediaStream | null): void;
|
|
19
|
+
onError(): void;
|
|
20
|
+
edit(text: string, draft: Draft, sessionId: string): void;
|
|
21
|
+
send(text: string, draft: Draft, sessionId: string): Promise<void>;
|
|
22
|
+
});
|
|
23
|
+
private state;
|
|
24
|
+
start(draft: Draft): Promise<void>;
|
|
25
|
+
finish(intent: DictationIntent): Promise<void> | undefined;
|
|
26
|
+
private finalize;
|
|
27
|
+
private fail;
|
|
28
|
+
private release;
|
|
29
|
+
cancel(notify?: boolean): void;
|
|
30
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import type { ChatComputerResourceTarget, ChatModelTurnPart, ChatNodeActivityPart, ChatPart, ChatToolChild, ChatToolPart } from "../types";
|
|
2
|
+
import type { ChatComputerResourceTarget, ChatModelTurnPart, ChatNodeActivityPart, ChatPart, ChatToolChild, ChatToolPart, ChatToolSessionRecap } from "../types";
|
|
3
|
+
import { type AgentChatCompletedToolAction, type AgentChatCompletedToolIconContext } from "./completed-tool-activity";
|
|
4
|
+
export type { AgentChatCompletedToolAction, AgentChatCompletedToolIconContext, AgentChatToolIconKey } from "./completed-tool-activity";
|
|
3
5
|
export type AgentChatToolViewMode = "closed" | "expanded";
|
|
6
|
+
export type AgentChatToolLabelMode = "agent" | "deterministic";
|
|
4
7
|
export type AgentChatToolTimelineSegment = {
|
|
5
8
|
kind: "part";
|
|
6
9
|
part: ChatPart;
|
|
@@ -28,7 +31,18 @@ export type AgentChatActivityIconContext = {
|
|
|
28
31
|
kind: "tool" | "group" | "planning" | "node";
|
|
29
32
|
part?: ChatToolPart | ChatNodeActivityPart;
|
|
30
33
|
};
|
|
34
|
+
export type AgentChatToolGroupLabelContext = {
|
|
35
|
+
parts: readonly ChatToolPart[];
|
|
36
|
+
phase: "live" | "completed";
|
|
37
|
+
label: string;
|
|
38
|
+
actions: readonly AgentChatCompletedToolAction[];
|
|
39
|
+
recap?: ChatToolSessionRecap;
|
|
40
|
+
};
|
|
31
41
|
export type AgentChatToolSlots = {
|
|
42
|
+
groupIconMode?: "leading" | "per-action" | "none";
|
|
43
|
+
renderCompletedToolIcon?: (context: AgentChatCompletedToolIconContext) => React.ReactNode;
|
|
44
|
+
renderToolGroupLabel?: (context: AgentChatToolGroupLabelContext) => React.ReactNode;
|
|
45
|
+
toolLabelMode?: AgentChatToolLabelMode;
|
|
32
46
|
renderActivityIcon?: (context: AgentChatActivityIconContext) => React.ReactNode;
|
|
33
47
|
onExpandedChange?: (open: boolean, part?: ChatToolPart) => void;
|
|
34
48
|
onToolSelect?: (part: ChatToolPart) => void;
|
|
@@ -64,10 +78,12 @@ export declare function AgentChatToolRow({ activeToolId, part, root, showOrb, sl
|
|
|
64
78
|
showOrb?: boolean;
|
|
65
79
|
slots?: AgentChatToolSlots;
|
|
66
80
|
}): import("react/jsx-runtime").JSX.Element;
|
|
67
|
-
export declare function AgentChatToolSession({ activeToolId, isLatestActivity, isLive, leadingModelTurn, modelTurn, parts, slots, }: {
|
|
81
|
+
export declare function AgentChatToolSession({ activeToolId, isLatestActivity, isLive, isSessionOpen, completedRecap, leadingModelTurn, modelTurn, parts, slots, }: {
|
|
68
82
|
activeToolId?: string | null;
|
|
69
83
|
isLatestActivity?: boolean;
|
|
70
84
|
isLive?: boolean;
|
|
85
|
+
isSessionOpen?: boolean;
|
|
86
|
+
completedRecap?: ChatToolSessionRecap;
|
|
71
87
|
leadingModelTurn?: ChatModelTurnPart;
|
|
72
88
|
modelTurn?: ChatModelTurnPart;
|
|
73
89
|
parts: readonly ChatToolPart[];
|
|
@@ -2,10 +2,13 @@ import * as React from "react";
|
|
|
2
2
|
import type { AgentChatInputContract } from "../runtime/input-contract";
|
|
3
3
|
import { type AgentChatComposerFile } from "./composer-attachments";
|
|
4
4
|
import { type RecordingCompletionContext } from "./use-audio-recorder";
|
|
5
|
+
export type AgentChatSubmissionContext = {
|
|
6
|
+
dictationSessionId?: string;
|
|
7
|
+
};
|
|
5
8
|
export type AgentChatComposerSubmission = {
|
|
6
9
|
text: string;
|
|
7
10
|
files: AgentChatComposerFile[];
|
|
8
|
-
};
|
|
11
|
+
} & AgentChatSubmissionContext;
|
|
9
12
|
export type AgentChatComposerTextOptions = {
|
|
10
13
|
/** Focus after the controlled textarea has committed the new text. Defaults to false. */
|
|
11
14
|
focus?: boolean;
|
|
@@ -17,6 +20,8 @@ export type AgentChatComposerTextOptions = {
|
|
|
17
20
|
};
|
|
18
21
|
};
|
|
19
22
|
export type AgentChatComposerOptions = {
|
|
23
|
+
dictationSessionId?: string;
|
|
24
|
+
inputProcessing?: boolean;
|
|
20
25
|
inputContract?: AgentChatInputContract | null;
|
|
21
26
|
recordingEnabled?: boolean;
|
|
22
27
|
textareaRef?: React.RefObject<HTMLTextAreaElement | null>;
|
|
@@ -33,7 +38,7 @@ export type AgentChatComposerOptions = {
|
|
|
33
38
|
text: string;
|
|
34
39
|
files: AgentChatComposerFile[];
|
|
35
40
|
} | null;
|
|
36
|
-
onSubmit(text: string, files: AgentChatComposerFile[]): void | Promise<void>;
|
|
41
|
+
onSubmit(text: string, files: AgentChatComposerFile[], context?: AgentChatSubmissionContext): void | Promise<void>;
|
|
37
42
|
/** Observe the shared recorder. Do not stop its tracks or start another capture. */
|
|
38
43
|
onRecordingStreamChange?: (stream: MediaStream | null) => void;
|
|
39
44
|
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
import { type AgentChatComposerOptions } from './use-agent-chat-composer';
|
|
3
|
+
import { type AgentChatComposerFile } from './composer-attachments';
|
|
4
|
+
import { type RealtimeDictationOptions } from './realtime-dictation';
|
|
5
|
+
import type { AgentChatSubmissionContext } from './use-agent-chat-composer';
|
|
6
|
+
import { type DictationIntent } from './voice-dictation';
|
|
7
|
+
type TranscribeRecording = (file: File, options: {
|
|
8
|
+
signal: AbortSignal;
|
|
9
|
+
operationId: string;
|
|
10
|
+
}) => Promise<string>;
|
|
11
|
+
export type AgentChatDictationOptions = {
|
|
12
|
+
onStartRecording?(): void;
|
|
13
|
+
props: AgentChatComposerOptions;
|
|
14
|
+
textareaRef: RefObject<HTMLTextAreaElement | null>;
|
|
15
|
+
scopeKey: string;
|
|
16
|
+
realtime?: RealtimeDictationOptions;
|
|
17
|
+
transcribe?: TranscribeRecording;
|
|
18
|
+
onStreamChange(stream: MediaStream | null): void;
|
|
19
|
+
onSubmit(text: string, files: AgentChatComposerFile[], context?: AgentChatSubmissionContext): Promise<void>;
|
|
20
|
+
onEdit(): void;
|
|
21
|
+
};
|
|
22
|
+
export declare function useAgentChatDictation(options: AgentChatDictationOptions): {
|
|
23
|
+
error: string | null;
|
|
24
|
+
composer: {
|
|
25
|
+
text: string;
|
|
26
|
+
setText: (value: string, interaction?: import("./use-agent-chat-composer").AgentChatComposerTextOptions) => boolean;
|
|
27
|
+
files: AgentChatComposerFile[];
|
|
28
|
+
addFiles: (selected: readonly File[]) => void;
|
|
29
|
+
removeFile: (id: string) => void;
|
|
30
|
+
textareaRef: RefObject<HTMLTextAreaElement | null>;
|
|
31
|
+
submit: (submission?: import("./use-agent-chat-composer").AgentChatComposerSubmission) => Promise<boolean>;
|
|
32
|
+
canSubmit: boolean;
|
|
33
|
+
isSubmitting: boolean;
|
|
34
|
+
attachmentError: string | null;
|
|
35
|
+
attachmentMimeTypes: string[];
|
|
36
|
+
validationError: string | null;
|
|
37
|
+
recorder: {
|
|
38
|
+
error: string | null;
|
|
39
|
+
isRecording: boolean;
|
|
40
|
+
isStarting: boolean;
|
|
41
|
+
isProcessing: boolean;
|
|
42
|
+
isCapturing: () => boolean;
|
|
43
|
+
start: (startOptions?: {
|
|
44
|
+
operationId?: string;
|
|
45
|
+
}) => Promise<void>;
|
|
46
|
+
stop: () => void;
|
|
47
|
+
cancel: () => void;
|
|
48
|
+
};
|
|
49
|
+
isProcessing: boolean;
|
|
50
|
+
recordingAllowed: boolean;
|
|
51
|
+
fileAccept: string;
|
|
52
|
+
onKeyDown: (event: React.KeyboardEvent<HTMLTextAreaElement>) => void;
|
|
53
|
+
allowAttachments: boolean;
|
|
54
|
+
isExpanded: boolean;
|
|
55
|
+
action: "stop" | "send";
|
|
56
|
+
};
|
|
57
|
+
busy: boolean;
|
|
58
|
+
isRecording: boolean;
|
|
59
|
+
start: () => Promise<void>;
|
|
60
|
+
finish: (intent: DictationIntent) => void;
|
|
61
|
+
cancel: () => void;
|
|
62
|
+
phase: import("./voice-dictation").DictationPhase;
|
|
63
|
+
intent: DictationIntent;
|
|
64
|
+
};
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type DictationPhase = 'idle' | 'requesting' | 'recording' | 'stopping' | 'transcribing' | 'submitting';
|
|
2
|
+
export type DictationIntent = 'edit' | 'send';
|
|
3
|
+
export type DictationState = {
|
|
4
|
+
phase: DictationPhase;
|
|
5
|
+
intent: DictationIntent;
|
|
6
|
+
};
|
|
7
|
+
type DictationCallbacks<Draft> = {
|
|
8
|
+
onState(state: DictationState): void;
|
|
9
|
+
transcribe(file: File, signal: AbortSignal, operationId: string): Promise<string>;
|
|
10
|
+
edit(text: string, draft: Draft): void;
|
|
11
|
+
send(text: string, draft: Draft): Promise<void>;
|
|
12
|
+
sendAudio(file: File, draft: Draft): Promise<void>;
|
|
13
|
+
canCommit(): boolean;
|
|
14
|
+
text(draft: Draft): string;
|
|
15
|
+
};
|
|
16
|
+
/** Send captured audio directly; stopping to edit uses the host transcriber. */
|
|
17
|
+
export declare class VoiceDictation<Draft> {
|
|
18
|
+
private operation;
|
|
19
|
+
private phase;
|
|
20
|
+
private callbacks;
|
|
21
|
+
constructor(callbacks: DictationCallbacks<Draft>);
|
|
22
|
+
get state(): DictationState;
|
|
23
|
+
private update;
|
|
24
|
+
begin(draft: Draft): string | null;
|
|
25
|
+
isCurrent(id: string): boolean;
|
|
26
|
+
recording(): void;
|
|
27
|
+
/** Returns true only when the capture itself needs to stop. */
|
|
28
|
+
finish(intent: DictationIntent): boolean;
|
|
29
|
+
captured(file: File, signal?: AbortSignal): Promise<void>;
|
|
30
|
+
cancel(notify?: boolean): void;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agents24/chat-react",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.48",
|
|
4
4
|
"description": "Accessible web UI and complete default layout for Agents24 chat applications.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@untitledui/file-icons": "0.0.9",
|
|
67
|
-
"@agents24/client": "0.2.
|
|
68
|
-
"@agents24/react": "0.2.
|
|
67
|
+
"@agents24/client": "0.2.26",
|
|
68
|
+
"@agents24/react": "0.2.32",
|
|
69
69
|
"@fontsource-variable/inter": "^5.3.0",
|
|
70
70
|
"@fontsource-variable/jetbrains-mono": "^5.3.0",
|
|
71
71
|
"@fontsource-variable/merriweather": "^5.3.0",
|
|
@@ -93,6 +93,7 @@
|
|
|
93
93
|
"shadcn": "4.13.1",
|
|
94
94
|
"tsup": "^8.5.1",
|
|
95
95
|
"tsx": "^4.20.6",
|
|
96
|
-
"typescript": "^5.9.3"
|
|
96
|
+
"typescript": "^5.9.3",
|
|
97
|
+
"@types/react-dom": "^19.2.3"
|
|
97
98
|
}
|
|
98
99
|
}
|
package/scaffold/src/app.tsx
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
type AgentChatRuntimeAgent,
|
|
7
7
|
useAgentChatRuntime,
|
|
8
8
|
} from "@agents24/chat-react/runtime"
|
|
9
|
-
import type { HitlActionState } from "@agents24/chat-react/ui"
|
|
9
|
+
import type { AgentResponseTimelineProps, HitlActionState } from "@agents24/chat-react/ui"
|
|
10
10
|
import {
|
|
11
11
|
Agents24Provider,
|
|
12
12
|
type ChatHitlPart,
|
|
@@ -24,7 +24,11 @@ import { GUEST_CHAT_IDENTITY, type Agents24ChatIdentity } from "./identity"
|
|
|
24
24
|
const createBrowserAbortController = () => new AbortController()
|
|
25
25
|
const browserVisibility = createBrowserVisibility()
|
|
26
26
|
|
|
27
|
-
export type
|
|
27
|
+
export type Agents24ChatTimelineOptions = Pick<AgentResponseTimelineProps,
|
|
28
|
+
"nodeActivityMode" | "renderUiBlocks" | "toolLabelMode" | "toolSlots" | "toolViewMode">
|
|
29
|
+
|
|
30
|
+
export type Agents24ChatAppProps = Agents24ChatTimelineOptions & {
|
|
31
|
+
attachmentTextOutputs?: readonly string[]
|
|
28
32
|
activeThreadId?: string | null
|
|
29
33
|
agent?: AgentChatRuntimeAgent
|
|
30
34
|
client: AgentClient
|
|
@@ -47,7 +51,7 @@ export type Agents24ChatScaffoldComponents = {
|
|
|
47
51
|
|
|
48
52
|
export type ChatHitlResponse = HitlResponse
|
|
49
53
|
|
|
50
|
-
export type Agents24ChatTimelineSlotProps = {
|
|
54
|
+
export type Agents24ChatTimelineSlotProps = Agents24ChatTimelineOptions & {
|
|
51
55
|
message: ChatMessage
|
|
52
56
|
parts: readonly ChatPart[]
|
|
53
57
|
isLoading: boolean
|
|
@@ -58,6 +62,11 @@ export type Agents24ChatTimelineSlotProps = {
|
|
|
58
62
|
function RuntimeChat({
|
|
59
63
|
components,
|
|
60
64
|
identity = GUEST_CHAT_IDENTITY,
|
|
65
|
+
nodeActivityMode,
|
|
66
|
+
renderUiBlocks,
|
|
67
|
+
toolLabelMode,
|
|
68
|
+
toolSlots,
|
|
69
|
+
toolViewMode,
|
|
61
70
|
...props
|
|
62
71
|
}: Agents24ChatAppProps) {
|
|
63
72
|
const runtime = useAgentChatRuntime({
|
|
@@ -67,7 +76,7 @@ function RuntimeChat({
|
|
|
67
76
|
),
|
|
68
77
|
})
|
|
69
78
|
|
|
70
|
-
return <ChatShell components={components} identity={identity} runtime={runtime} sidebar={props.sidebar} />
|
|
79
|
+
return <ChatShell components={components} identity={identity} runtime={runtime} sidebar={props.sidebar} timelineOptions={{ nodeActivityMode, renderUiBlocks, toolLabelMode, toolSlots, toolViewMode }} />
|
|
71
80
|
}
|
|
72
81
|
|
|
73
82
|
export function App(props: Agents24ChatAppProps) {
|
package/scaffold/src/chat.css
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { RealtimeDictationOptions, AgentChatSubmissionContext } from "@agents24/chat-react/ui";
|
|
2
|
+
import { ArrowUp, ChevronDown, LoaderCircle, Square } from "lucide-react"
|
|
2
3
|
import * as React from "react"
|
|
3
4
|
import {
|
|
5
|
+
MicrophoneInput,
|
|
4
6
|
AgentChatContextStatus,
|
|
5
7
|
ChatAttachmentRows,
|
|
6
|
-
|
|
8
|
+
useAgentChatDictation,
|
|
7
9
|
type AgentChatComposerFile,
|
|
8
10
|
} from "@agents24/chat-react/ui"
|
|
9
11
|
import { attachmentFileAccept, type AgentChatInputContract } from "@agents24/chat-react/runtime"
|
|
@@ -20,6 +22,7 @@ import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip"
|
|
|
20
22
|
import { cn } from "../../lib/utils"
|
|
21
23
|
|
|
22
24
|
export type Agents24ChatComposerProps = {
|
|
25
|
+
realtimeDictation?: RealtimeDictationOptions;
|
|
23
26
|
queue?: React.ReactNode
|
|
24
27
|
onRecordingStreamChange?: (stream: MediaStream | null) => void
|
|
25
28
|
inputContract: AgentChatInputContract
|
|
@@ -37,13 +40,13 @@ export type Agents24ChatComposerProps = {
|
|
|
37
40
|
onModelChange: (modelId: string) => void
|
|
38
41
|
onAgentChange: (agentId: string) => void
|
|
39
42
|
onStop: () => void
|
|
40
|
-
onSubmit: (text: string, files: AgentChatComposerFile[]) => Promise<void>
|
|
43
|
+
onSubmit: (text: string, files: AgentChatComposerFile[], context?: AgentChatSubmissionContext) => Promise<void>
|
|
41
44
|
restoredDraft?: { revision: number; text: string; files: AgentChatComposerFile[] } | null
|
|
42
45
|
utilityRow?: "inline" | "below"
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
export function ChatComposer({
|
|
46
|
-
inputContract,
|
|
49
|
+
inputContract, realtimeDictation,
|
|
47
50
|
queue,
|
|
48
51
|
onRecordingStreamChange,
|
|
49
52
|
disabled,
|
|
@@ -64,13 +67,18 @@ export function ChatComposer({
|
|
|
64
67
|
restoredDraft,
|
|
65
68
|
utilityRow = "inline",
|
|
66
69
|
}: Agents24ChatComposerProps) {
|
|
70
|
+
const [audioRecording, setAudioRecording] = React.useState(false);
|
|
67
71
|
const inputRef = React.useRef<HTMLInputElement>(null)
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
const textareaRef = React.useRef<HTMLTextAreaElement>(null)
|
|
73
|
+
const voice = useAgentChatDictation({
|
|
74
|
+
props:{inputContract,disabled:disabled || audioRecording,scopeKey,focusKey,forceExpanded,isCancelling,isRunning,restoredDraft,onSubmit},
|
|
75
|
+
textareaRef,scopeKey:scopeKey||"default",realtime:realtimeDictation,
|
|
76
|
+
onSubmit,onEdit:()=>undefined,onStreamChange:stream=>onRecordingStreamChange?.(stream),
|
|
77
|
+
})
|
|
78
|
+
const sendingDictation = voice.intent === "send" && ["stopping", "transcribing", "submitting"].includes(voice.phase);
|
|
79
|
+
const { text, setText, files, removeFile, addFiles, submit,
|
|
80
|
+
attachmentError, attachmentMimeTypes, allowAttachments,
|
|
81
|
+
recorder, isExpanded, validationError, action, canSubmit } = voice.composer
|
|
74
82
|
|
|
75
83
|
const selectedAgent = agents.find((item) => item.id === agentId)
|
|
76
84
|
const selectedModel = models.find((item) => item.id === modelId)
|
|
@@ -183,7 +191,7 @@ export function ChatComposer({
|
|
|
183
191
|
rows={1}
|
|
184
192
|
placeholder="Message the agent"
|
|
185
193
|
aria-label="Message"
|
|
186
|
-
disabled={disabled}
|
|
194
|
+
disabled={disabled || voice.busy || audioRecording}
|
|
187
195
|
className={cn(
|
|
188
196
|
"agents24-composer-textarea max-h-56 min-h-9 field-sizing-content resize-none overflow-y-auto border-0 bg-transparent px-2 shadow-none focus-visible:ring-0 dark:bg-transparent",
|
|
189
197
|
isExpanded ? "py-2" : "h-9 py-2",
|
|
@@ -201,33 +209,29 @@ export function ChatComposer({
|
|
|
201
209
|
<div className="agents24-composer-actions flex items-center gap-1">
|
|
202
210
|
{utilityRow === "inline" ? <AgentChatContextStatus contextWindow={contextWindow} /> : null}
|
|
203
211
|
{utilityRow === "inline" ? runtimeSelector : null}
|
|
204
|
-
{
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
>
|
|
212
|
-
{recorder.isRecording ? <Square className="fill-current" /> : <Mic />}
|
|
213
|
-
</Button>
|
|
214
|
-
) : null}
|
|
212
|
+
<MicrophoneInput scopeKey={scopeKey} className="inline-flex size-9 items-center justify-center rounded-full"
|
|
213
|
+
disabled={disabled || voice.composer.isSubmitting}
|
|
214
|
+
dictation={{enabled:realtimeDictation?.feature.enabled === true,phase:voice.phase,start:voice.start,stop:()=>voice.finish('edit'),cancel:voice.cancel}}
|
|
215
|
+
audioEnabled={inputContract.modalities.audio.enabled && inputContract.modalities.audio.recording_enabled}
|
|
216
|
+
acceptedMimeTypes={inputContract.modalities.audio.allowed_mime_types}
|
|
217
|
+
onRecordingChange={setAudioRecording} onStreamChange={onRecordingStreamChange}
|
|
218
|
+
onRecorded={file=>addFiles([file])} />
|
|
215
219
|
{action === "stop" ? (
|
|
216
220
|
<Button size="icon" aria-label={isCancelling ? "Cancelling response" : "Stop response"}
|
|
217
221
|
disabled={disabled || isCancelling} onClick={onStop}>
|
|
218
222
|
{isCancelling ? <LoaderCircle className="animate-spin" /> : <Square className="fill-current" />}
|
|
219
223
|
</Button>
|
|
220
|
-
) : validationError ? (
|
|
224
|
+
) : validationError && !voice.busy ? (
|
|
221
225
|
<Tooltip>
|
|
222
226
|
<TooltipTrigger asChild>
|
|
223
227
|
<span tabIndex={0} aria-label={validationError}>
|
|
224
|
-
<Button size="icon" aria-label={isRunning ? "Queue message" : "Send message"} disabled onClick={() => void submit()}
|
|
228
|
+
<Button size="icon" aria-label={isRunning ? "Queue message" : "Send message"} disabled onClick={() => void submit()}>{sendingDictation ? <LoaderCircle className="animate-spin" /> : <ArrowUp />}</Button>
|
|
225
229
|
</span>
|
|
226
230
|
</TooltipTrigger>
|
|
227
231
|
<TooltipContent>{validationError}</TooltipContent>
|
|
228
232
|
</Tooltip>
|
|
229
233
|
) : (
|
|
230
|
-
<Button size="icon" aria-label={isRunning ? "Queue message" : "Send message"} disabled={!canSubmit} onClick={() => void submit()}
|
|
234
|
+
<Button size="icon" aria-label={isRunning ? "Queue message" : "Send message"} aria-busy={sendingDictation || undefined} disabled={sendingDictation || !canSubmit} onClick={() => void submit()}>{sendingDictation ? <LoaderCircle className="animate-spin" /> : <ArrowUp />}</Button>
|
|
231
235
|
)}
|
|
232
236
|
</div>
|
|
233
237
|
</div>
|
|
@@ -7,13 +7,14 @@ import * as React from "react"
|
|
|
7
7
|
import { MessageParts } from "./message-parts"
|
|
8
8
|
import { Bubble, BubbleContent } from "../ui/bubble"
|
|
9
9
|
import { Message, MessageContent, MessageFooter } from "../ui/message"
|
|
10
|
-
import type { Agents24ChatTimelineSlotProps } from "../../app"
|
|
10
|
+
import type { Agents24ChatTimelineSlotProps, Agents24ChatTimelineOptions } from "../../app"
|
|
11
11
|
|
|
12
12
|
type Props = {
|
|
13
13
|
animateCompletion: boolean
|
|
14
14
|
message: ChatMessageModel
|
|
15
15
|
getHitlActionState: (part: ChatHitlPart) => AgentChatRuntimeHitlActionState | undefined
|
|
16
16
|
isLoading: boolean
|
|
17
|
+
timelineOptions?: Agents24ChatTimelineOptions
|
|
17
18
|
onHitlAction: (part: ChatHitlPart, response: HitlResponse, options?: HitlSubmissionOptions) => Promise<void>
|
|
18
19
|
onRegenerate: () => Promise<void>
|
|
19
20
|
allowFeedback: boolean
|
|
@@ -29,6 +30,7 @@ export function ChatMessage({
|
|
|
29
30
|
allowFeedback,
|
|
30
31
|
getHitlActionState,
|
|
31
32
|
isLoading,
|
|
33
|
+
timelineOptions,
|
|
32
34
|
message,
|
|
33
35
|
onHitlAction,
|
|
34
36
|
onRegenerate,
|
|
@@ -54,6 +56,7 @@ export function ChatMessage({
|
|
|
54
56
|
<MessageParts
|
|
55
57
|
getHitlActionState={getHitlActionState}
|
|
56
58
|
isLoading={isLoading}
|
|
59
|
+
timelineOptions={timelineOptions}
|
|
57
60
|
message={message}
|
|
58
61
|
onHitlAction={onHitlAction}
|
|
59
62
|
Timeline={Timeline}
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
agentChatRuntimeErrorMessage,
|
|
3
3
|
type AgentChatRuntime,
|
|
4
4
|
} from "@agents24/chat-react/runtime"
|
|
5
|
-
import type { Agents24ChatScaffoldComponents } from "../../app"
|
|
5
|
+
import type { Agents24ChatScaffoldComponents, Agents24ChatTimelineOptions } from "../../app"
|
|
6
6
|
import type { ThreadMessage } from "@agents24/client"
|
|
7
7
|
import { AgentChatQueue, queuedMessageComposerFiles, useLiveCompletionRuns, type AgentChatComposerFile } from "@agents24/chat-react/ui"
|
|
8
8
|
import { CircleAlert, LoaderCircle, SquarePen, X } from "lucide-react"
|
|
@@ -87,11 +87,13 @@ export function ChatShell({
|
|
|
87
87
|
identity,
|
|
88
88
|
runtime,
|
|
89
89
|
sidebar,
|
|
90
|
+
timelineOptions,
|
|
90
91
|
}: {
|
|
91
92
|
components?: Agents24ChatScaffoldComponents
|
|
92
93
|
identity: Agents24ChatIdentity
|
|
93
94
|
runtime: AgentChatRuntime
|
|
94
95
|
sidebar?: React.ReactNode
|
|
96
|
+
timelineOptions?: Agents24ChatTimelineOptions
|
|
95
97
|
}) {
|
|
96
98
|
const Composer = components?.Composer || ChatComposer
|
|
97
99
|
const { controller } = runtime
|
|
@@ -218,6 +220,7 @@ export function ChatShell({
|
|
|
218
220
|
onSetFeedback={(input) => controller.setFeedback(message, input)}
|
|
219
221
|
resolveAttachmentContent={runtime.resolveAttachmentContent}
|
|
220
222
|
Timeline={components?.Timeline}
|
|
223
|
+
timelineOptions={timelineOptions}
|
|
221
224
|
/>
|
|
222
225
|
</LatestThreadScroller.Item>
|
|
223
226
|
))}
|
|
@@ -248,6 +251,7 @@ export function ChatShell({
|
|
|
248
251
|
onEdit={retractForEdit} onResume={controller.resumeQueue} />}
|
|
249
252
|
restoredDraft={restoredDraft}
|
|
250
253
|
inputContract={runtime.inputContract || LOADING_INPUT_CONTRACT}
|
|
254
|
+
realtimeDictation={runtime.dictation}
|
|
251
255
|
contextWindow={runtime.contextWindow}
|
|
252
256
|
disabled={runtime.isBootstrapping || runtime.isChangingAgent || isUploading || hasBlockingError}
|
|
253
257
|
scopeKey={controller.activeThreadId}
|
|
@@ -262,10 +266,11 @@ export function ChatShell({
|
|
|
262
266
|
modelId={runtime.modelId}
|
|
263
267
|
models={runtime.models}
|
|
264
268
|
onModelChange={runtime.changeModel}
|
|
265
|
-
onSubmit={(text, files) => runtime.submit({
|
|
266
|
-
text,
|
|
269
|
+
onSubmit={(text, files, context) => runtime.submit({
|
|
270
|
+
text, dictationSessionId: context?.dictationSessionId,
|
|
267
271
|
files: files.filter((file) => file.source).map((file) => ({
|
|
268
272
|
data: file.source!,
|
|
273
|
+
transcriptPresentation: file.transcriptPresentation,
|
|
269
274
|
mediaType: file.mediaType,
|
|
270
275
|
name: file.filename,
|
|
271
276
|
})),
|
|
@@ -2,18 +2,20 @@ import type { LinkSafetyModalProps } from "streamdown"
|
|
|
2
2
|
import * as React from "react"
|
|
3
3
|
|
|
4
4
|
import { Button } from "../ui/button"
|
|
5
|
-
import {
|
|
6
|
-
Dialog,
|
|
7
|
-
DialogContent,
|
|
8
|
-
DialogDescription,
|
|
9
|
-
DialogFooter,
|
|
10
|
-
DialogHeader,
|
|
11
|
-
DialogTitle,
|
|
12
|
-
} from "../ui/dialog"
|
|
13
5
|
|
|
14
6
|
export function ExternalLinkDialog({ isOpen, onClose, onConfirm, url }: LinkSafetyModalProps) {
|
|
7
|
+
const dialogRef = React.useRef<HTMLDialogElement>(null)
|
|
8
|
+
const headingId = React.useId()
|
|
9
|
+
const descriptionId = React.useId()
|
|
15
10
|
const [copied, setCopied] = React.useState(false)
|
|
16
11
|
|
|
12
|
+
React.useEffect(() => {
|
|
13
|
+
const dialog = dialogRef.current
|
|
14
|
+
if (!dialog) return
|
|
15
|
+
if (isOpen && !dialog.open) dialog.showModal()
|
|
16
|
+
if (!isOpen && dialog.open) dialog.close()
|
|
17
|
+
}, [isOpen])
|
|
18
|
+
|
|
17
19
|
const close = () => {
|
|
18
20
|
setCopied(false)
|
|
19
21
|
onClose()
|
|
@@ -30,20 +32,28 @@ export function ExternalLinkDialog({ isOpen, onClose, onConfirm, url }: LinkSafe
|
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
return (
|
|
33
|
-
<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
<dialog
|
|
36
|
+
aria-describedby={descriptionId}
|
|
37
|
+
aria-labelledby={headingId}
|
|
38
|
+
className="m-auto max-h-[calc(100dvh-2rem)] w-[calc(100%-2rem)] max-w-md overflow-auto rounded-lg border bg-background p-0 text-foreground shadow-lg backdrop:bg-black/50"
|
|
39
|
+
onCancel={(event) => { event.preventDefault(); close() }}
|
|
40
|
+
onClick={(event) => { if (event.target === event.currentTarget) close() }}
|
|
41
|
+
ref={dialogRef}
|
|
42
|
+
>
|
|
43
|
+
<div className="grid gap-4 p-6">
|
|
44
|
+
<div className="grid gap-2">
|
|
45
|
+
<h2 className="text-lg leading-none font-semibold" id={headingId}>Open external link?</h2>
|
|
46
|
+
<p className="text-sm text-muted-foreground" id={descriptionId}>You’re about to visit an external website.</p>
|
|
47
|
+
</div>
|
|
39
48
|
<div className="max-h-32 overflow-auto rounded-md bg-muted p-3 font-mono text-xs wrap-break-word">
|
|
40
49
|
{url}
|
|
41
50
|
</div>
|
|
42
|
-
<
|
|
43
|
-
<Button
|
|
44
|
-
<Button onClick={
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
51
|
+
<div className="flex flex-col-reverse gap-2 sm:flex-row sm:justify-end">
|
|
52
|
+
<Button onClick={close} type="button" variant="ghost">Cancel</Button>
|
|
53
|
+
<Button onClick={() => void copyUrl()} type="button" variant="outline">{copied ? "Copied" : "Copy link"}</Button>
|
|
54
|
+
<Button onClick={openUrl} type="button">Open link</Button>
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
</dialog>
|
|
48
58
|
)
|
|
49
59
|
}
|
|
@@ -10,7 +10,7 @@ import type { LinkSafetyConfig } from "streamdown"
|
|
|
10
10
|
|
|
11
11
|
import { CollapsibleUserMessage } from "./collapsible-user-message"
|
|
12
12
|
import { ExternalLinkDialog } from "./external-link-dialog"
|
|
13
|
-
import type { Agents24ChatTimelineSlotProps } from "../../app"
|
|
13
|
+
import type { Agents24ChatTimelineSlotProps, Agents24ChatTimelineOptions } from "../../app"
|
|
14
14
|
|
|
15
15
|
const linkSafety = {
|
|
16
16
|
enabled: true,
|
|
@@ -33,12 +33,14 @@ export function MessageParts({
|
|
|
33
33
|
message,
|
|
34
34
|
getHitlActionState,
|
|
35
35
|
isLoading,
|
|
36
|
+
timelineOptions,
|
|
36
37
|
onHitlAction,
|
|
37
38
|
Timeline = ScaffoldTimeline,
|
|
38
39
|
}: {
|
|
39
40
|
message: ChatMessage
|
|
40
41
|
getHitlActionState: (part: ChatHitlPart) => AgentChatRuntimeHitlActionState | undefined
|
|
41
42
|
isLoading: boolean
|
|
43
|
+
timelineOptions?: Agents24ChatTimelineOptions
|
|
42
44
|
onHitlAction: (part: ChatHitlPart, response: HitlResponse, options?: HitlSubmissionOptions) => Promise<void>
|
|
43
45
|
Timeline?: React.ComponentType<Agents24ChatTimelineSlotProps>
|
|
44
46
|
}) {
|
|
@@ -47,6 +49,7 @@ export function MessageParts({
|
|
|
47
49
|
<Timeline
|
|
48
50
|
getHitlActionState={getHitlActionState}
|
|
49
51
|
isLoading={isLoading}
|
|
52
|
+
{...timelineOptions}
|
|
50
53
|
message={message}
|
|
51
54
|
onHitlAction={(part, response, options) => {
|
|
52
55
|
void onHitlAction(part, response, options).catch(() => undefined)
|