@theoremjs/react 0.3.4-next.373.gab46e23 → 0.3.4-next.375.ga2d1878
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 +2 -0
- package/hooks/use-page-tool-warnings.d.ts +1 -4
- package/hooks/use-page-tool-warnings.js +3 -14
- package/hooks/use-theorem-chat.d.ts +35 -80
- package/hooks/use-theorem-chat.js +30 -517
- package/package.json +3 -3
- package/ui/ChatComposerBar.js +1 -3
- package/ui/labels.d.ts +1 -2
- package/client/composer-drawer.d.ts +0 -19
- package/client/composer-drawer.js +0 -15
- package/client/composer-hints.d.ts +0 -25
- package/client/composer-hints.js +0 -20
- package/client/composer-primary.d.ts +0 -16
- package/client/composer-primary.js +0 -25
- package/hooks/use-theorem-chat-actions.d.ts +0 -77
- package/hooks/use-theorem-chat-actions.js +0 -285
- package/hooks/use-theorem-chat-state.d.ts +0 -65
- package/hooks/use-theorem-chat-state.js +0 -122
package/README.md
CHANGED
|
@@ -408,6 +408,8 @@ The hooks give you the same state and actions that the ready-made components use
|
|
|
408
408
|
|
|
409
409
|
`useTheoremInterface` reads the interface of the profile from the server. `useTheoremChat` keeps the transcript, the streaming state, the drafts, the queue, and the gates.
|
|
410
410
|
|
|
411
|
+
`useTheoremChat` binds `createChatController` from `@theoremjs/web/client` to React. To draw the chat in another framework, or in none, use the controller directly. See [A chat with no framework](https://github.com/masudl-hub/theoremai/blob/main/web/README.md#a-chat-with-no-framework).
|
|
412
|
+
|
|
411
413
|
```tsx
|
|
412
414
|
import { createHttpTransport, useTheoremChat, useTheoremInterface } from '@theoremjs/react';
|
|
413
415
|
|
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
import { type PageTools } from '@theoremjs/web/client';
|
|
2
|
-
/**
|
|
3
|
-
* Says in the console, once, where the page's tools and the profile's disagree. A wrong name is
|
|
4
|
-
* the builder's to fix, so it is never said to the visitor.
|
|
5
|
-
*/
|
|
2
|
+
/** Says in the console, once for each set of names, where the page's tools and the profile's disagree. */
|
|
6
3
|
export declare function usePageToolWarnings(declared: readonly string[] | undefined, pageTools: PageTools | undefined): void;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { warnPageToolMismatch } from '@theoremjs/web/client';
|
|
2
2
|
import { useEffect } from 'react';
|
|
3
|
-
/**
|
|
4
|
-
* Says in the console, once, where the page's tools and the profile's disagree. A wrong name is
|
|
5
|
-
* the builder's to fix, so it is never said to the visitor.
|
|
6
|
-
*/
|
|
3
|
+
/** Says in the console, once for each set of names, where the page's tools and the profile's disagree. */
|
|
7
4
|
export function usePageToolWarnings(declared, pageTools) {
|
|
8
5
|
const handled = Object.keys(pageTools ?? {})
|
|
9
6
|
.sort()
|
|
@@ -12,14 +9,6 @@ export function usePageToolWarnings(declared, pageTools) {
|
|
|
12
9
|
useEffect(() => {
|
|
13
10
|
if (named === undefined)
|
|
14
11
|
return;
|
|
15
|
-
|
|
16
|
-
for (const name of unanswered) {
|
|
17
|
-
// labels-exempt: builder diagnostic
|
|
18
|
-
console.warn(`Theorem: page tool '${name}' has no handler in pageTools; the agent gets no answer.`);
|
|
19
|
-
}
|
|
20
|
-
for (const name of unused) {
|
|
21
|
-
// labels-exempt: builder diagnostic
|
|
22
|
-
console.warn(`Theorem: pageTools has '${name}', which the profile does not declare answeredBy: 'page'.`);
|
|
23
|
-
}
|
|
12
|
+
warnPageToolMismatch(named ? named.split('\n') : [], handled ? handled.split('\n') : []);
|
|
24
13
|
}, [named, handled]);
|
|
25
14
|
}
|
|
@@ -1,96 +1,51 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export type UseTheoremChatOptions = {
|
|
5
|
-
transport: TheoremTransport;
|
|
6
|
-
/** Composer interface for the host profile — see `useTheoremInterface`. `null` while loading. */
|
|
7
|
-
iface: ComposerProfileInterface | null;
|
|
8
|
-
/**
|
|
9
|
-
* The ref of a conversation to resume, as `onConversationChange` reported it. Read once, when
|
|
10
|
-
* the chat mounts: the chat draws the conversation as the host keeps it. A stateless profile
|
|
11
|
-
* keeps no conversation, so it has no ref.
|
|
12
|
-
*/
|
|
13
|
-
conversation?: string;
|
|
14
|
-
/**
|
|
15
|
-
* The conversation under `conversation` as the host showed it with the ref, as
|
|
16
|
-
* `startConversation` returns it. Read once, when the chat mounts: the chat draws it at once,
|
|
17
|
-
* and does not read it from the host again.
|
|
18
|
-
*/
|
|
19
|
-
conversationView?: ConversationView;
|
|
20
|
-
/** The text the composer starts with. Read once, when the chat mounts. */
|
|
21
|
-
initialText?: string;
|
|
22
|
-
/**
|
|
23
|
-
* Each new ref the host issues for the conversation: once the message posts, and again as the
|
|
24
|
-
* reply's runs are saved. Keep the latest to resume the chat later.
|
|
25
|
-
*/
|
|
26
|
-
onConversationChange?: (ref: string) => void;
|
|
27
|
-
/**
|
|
28
|
-
* The value chosen for each of the profile's `inputs.slots`. Sent with every turn. A slot you
|
|
29
|
-
* name here is fixed to that value; one you leave out is chosen in the composer, starting at
|
|
30
|
-
* its first allowed value.
|
|
31
|
-
*/
|
|
32
|
-
slots?: Record<string, string>;
|
|
33
|
-
/** Told each time the visitor chooses a slot in the composer, with every slot's value. */
|
|
34
|
-
onSlotsChange?: (slots: Record<string, string>) => void;
|
|
35
|
-
/** What the page wants the agent to know: any JSON. The latest value goes with every turn. */
|
|
36
|
-
context?: unknown;
|
|
37
|
-
/** The page's tools, by name: each answers a tool the profile declares with `answeredBy: 'page'`. */
|
|
38
|
-
pageTools?: PageTools;
|
|
39
|
-
/**
|
|
40
|
-
* Every event of every turn, as it arrives and before the transcript takes it: the ones the
|
|
41
|
-
* transcript shows, and the ones it does not (a stage, a session, a guardrail decision).
|
|
42
|
-
*/
|
|
43
|
-
onTurnEvent?: TurnEventSink;
|
|
44
|
-
};
|
|
45
|
-
/** What `sendText` hands back: the blocks the turn added, its user message, and the reply. */
|
|
46
|
-
export type SentTurn = {
|
|
47
|
-
blocks: TranscriptBlock[];
|
|
48
|
-
};
|
|
1
|
+
import { type ChatOptions, type SentTurn } from '@theoremjs/web/client';
|
|
2
|
+
export type { SentTurn };
|
|
3
|
+
export type UseTheoremChatOptions = ChatOptions;
|
|
49
4
|
/**
|
|
50
5
|
* Headless chat model: transcript, streaming, composer drafts, pending
|
|
51
6
|
* queue / steer / stash, tool gates. Render it with `@theoremjs/react/ui` or
|
|
52
|
-
* your own components.
|
|
7
|
+
* your own components. A React binding of `createChatController` from
|
|
8
|
+
* `@theoremjs/web/client`, which works with no framework.
|
|
53
9
|
*/
|
|
54
|
-
export declare function useTheoremChat(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
pendingVoice: File[];
|
|
66
|
-
phase: ComposerRunPhase;
|
|
67
|
-
session: InterfaceTurnSession;
|
|
68
|
-
/** The latest message's delivery; `null` before the first and once its turn failed. */
|
|
69
|
-
delivery: MessageDelivery | null;
|
|
70
|
-
streamBlocks: TranscriptBlock[];
|
|
71
|
-
streaming: boolean;
|
|
72
|
-
setDraftText: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
73
|
-
setPendingFiles: import("react").Dispatch<import("react").SetStateAction<File[]>>;
|
|
74
|
-
setPendingVoice: import("react").Dispatch<import("react").SetStateAction<File[]>>;
|
|
75
|
-
setPendingMessages: import("react").Dispatch<import("react").SetStateAction<ComposerPendingMessage[]>>;
|
|
76
|
-
setIssues: import("react").Dispatch<import("react").SetStateAction<import("@theoremjs/agents").AttachmentValidationIssue[]>>;
|
|
10
|
+
export declare function useTheoremChat(options: UseTheoremChatOptions): {
|
|
11
|
+
slotChoices: {
|
|
12
|
+
onChange: (name: string, value: string) => void;
|
|
13
|
+
declared: Record<string, string[]>;
|
|
14
|
+
values: Record<string, string>;
|
|
15
|
+
} | undefined;
|
|
16
|
+
setDraftText: (value: import("@theoremjs/web/client").ChatUpdate<string>) => void;
|
|
17
|
+
setPendingFiles: (value: import("@theoremjs/web/client").ChatUpdate<File[]>) => void;
|
|
18
|
+
setPendingVoice: (value: import("@theoremjs/web/client").ChatUpdate<File[]>) => void;
|
|
19
|
+
setPendingMessages: (value: import("@theoremjs/web/client").ChatUpdate<import("../../../src/interface/pending").ComposerPendingMessage[]>) => void;
|
|
20
|
+
setIssues: (value: import("@theoremjs/web/client").ChatUpdate<import("../../../mod").AttachmentValidationIssue[]>) => void;
|
|
77
21
|
handleAuthenticated: (_index: number, secret?: string) => Promise<void>;
|
|
78
22
|
handleBranch: (index: number) => Promise<void>;
|
|
79
23
|
handleSubmit: () => Promise<void>;
|
|
80
24
|
handleStop: () => void;
|
|
81
|
-
handleMenuAction: (action: import("
|
|
25
|
+
handleMenuAction: (action: import("../../../src/interface/composer-actions").ComposerMenuAction) => void;
|
|
82
26
|
handlePendingQueue: (id: string) => void;
|
|
83
27
|
handlePendingRestore: (id: string) => Promise<void>;
|
|
84
|
-
handleSendNow: (
|
|
85
|
-
handleToolDecision: (_index: number, action:
|
|
28
|
+
handleSendNow: (source?: import("../../../src/interface/pending").ComposerPendingMessage) => Promise<void>;
|
|
29
|
+
handleToolDecision: (_index: number, action: "allow" | "deny") => Promise<void>;
|
|
86
30
|
handleGenerationChange: (next: {
|
|
87
31
|
modelId: string;
|
|
88
32
|
effort?: string;
|
|
89
33
|
}) => void;
|
|
90
|
-
slotChoices: {
|
|
91
|
-
declared: Record<string, string[]>;
|
|
92
|
-
values: Record<string, string>;
|
|
93
|
-
onChange: (name: string, value: string) => void;
|
|
94
|
-
} | undefined;
|
|
95
34
|
sendText: (text: string, files?: readonly File[]) => Promise<SentTurn | null>;
|
|
35
|
+
iface: import("../../../src/interface/types").ComposerProfileInterface | null;
|
|
36
|
+
blocks: import("../../../src/interface/types").TranscriptBlock[];
|
|
37
|
+
streamBlocks: import("../../../src/interface/types").TranscriptBlock[];
|
|
38
|
+
chatStarted: boolean;
|
|
39
|
+
draftText: string;
|
|
40
|
+
pendingFiles: File[];
|
|
41
|
+
pendingVoice: File[];
|
|
42
|
+
pendingMessages: import("../../../src/interface/pending").ComposerPendingMessage[];
|
|
43
|
+
issues: import("../../../mod").AttachmentValidationIssue[];
|
|
44
|
+
failure: import("@theoremjs/web/client").ClientFailure | null;
|
|
45
|
+
answering: import("@theoremjs/web/client").AnsweringGate | null;
|
|
46
|
+
phase: import("../../../src/interface/composer-actions").ComposerRunPhase;
|
|
47
|
+
session: import("../../../src/interface/session").InterfaceTurnSession;
|
|
48
|
+
delivery: import("@theoremjs/web/client").MessageDelivery | null;
|
|
49
|
+
streaming: boolean;
|
|
50
|
+
slots: import("@theoremjs/web/client").ChatSlots | undefined;
|
|
96
51
|
};
|