@ouispec/agent-react 0.17.0 → 0.19.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.
- package/README.md +3 -1
- package/dist/approvals/ApprovalCard.d.ts +20 -7
- package/dist/approvals/ApprovalCard.d.ts.map +1 -1
- package/dist/approvals/ApprovalCard.js +31 -8
- package/dist/approvals/ApprovalCard.js.map +1 -1
- package/dist/approvals/decision.d.ts +12 -1
- package/dist/approvals/decision.d.ts.map +1 -1
- package/dist/approvals/decision.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/provider/AgentProvider.d.ts.map +1 -1
- package/dist/provider/AgentProvider.js +182 -9
- package/dist/provider/AgentProvider.js.map +1 -1
- package/dist/provider/conversation-messages.d.ts +12 -0
- package/dist/provider/conversation-messages.d.ts.map +1 -0
- package/dist/provider/conversation-messages.js +22 -0
- package/dist/provider/conversation-messages.js.map +1 -0
- package/dist/provider/internals.d.ts +14 -0
- package/dist/provider/internals.d.ts.map +1 -0
- package/dist/provider/internals.js +8 -0
- package/dist/provider/internals.js.map +1 -0
- package/dist/provider/stored-messages.d.ts +4 -1
- package/dist/provider/stored-messages.d.ts.map +1 -1
- package/dist/provider/stored-messages.js +19 -2
- package/dist/provider/stored-messages.js.map +1 -1
- package/dist/provider/turn-progress.d.ts.map +1 -1
- package/dist/provider/turn-progress.js +2 -1
- package/dist/provider/turn-progress.js.map +1 -1
- package/dist/provider/types.d.ts +17 -2
- package/dist/provider/types.d.ts.map +1 -1
- package/dist/staff/useStaffConversation.d.ts +27 -0
- package/dist/staff/useStaffConversation.d.ts.map +1 -0
- package/dist/staff/useStaffConversation.js +186 -0
- package/dist/staff/useStaffConversation.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -13,7 +13,9 @@ npm install @ouispec/agent-react
|
|
|
13
13
|
- `sendMessage(content, options?)` on `useAgent`: sends the person's message. `options.attachments` gives the message's files by reference (an array alone as the second argument does the same); without them it carries the composer's ready files. `options.input` says how a message was entered when it was not typed: `{ mode: 'voice', language }` for one the person spoke, with the language the recogniser detected. It reaches `config.sendMessage` as `context.input`, for the platform to pass to the worker and store on the message; the message keeps it as `AgentMessage.input`, and a restored one from `AgentStoredMessage.input`. A spoken message sent while a turn runs supersedes it, as a typed one does. An input `readMessageInput` does not recognise is not sent.
|
|
14
14
|
- `history` on `useAgent`: the person's earlier conversations, from `config.listConversations`. A listed conversation keeps `previewInput`, how the message its preview is taken from was entered, and each search match its `input`, when the person spoke it, so a list can mark it; what `readMessageInput` does not recognise is dropped (`readConversationSummary`).
|
|
15
15
|
- `attachments` on `useAgent`: the files on the message being written. `attach(files)` checks each against the platform's limits and uploads it at once through `config.attachments.upload` (into the conversation, made then if there is none yet); each item shows its progress, or why it was refused; `remove(key)` cancels an upload or removes the file. `sendMessage` waits for uploads still running and sends the ready files' references; `waitingToSend` is true meanwhile. It sends nothing, and resolves `notSent: { reason, content }` so the composer keeps the draft, when a file on the message is refused, when a send already waits, or when the conversation changes or `stopTurn` gives the waiting send up. A file uploaded for a message that is not sent is removed through `config.attachments.remove`. A message's files are on `AgentMessage.attachments`.
|
|
16
|
-
- `
|
|
16
|
+
- `hold` on `useAgent`: who holds the conversation when a person on the staff has taken it over. With `config.conversationRoom`, the provider follows the conversation's room: a person's messages arrive as `role: 'staff'` messages with their `speaker`, the take-over and hand-back as `staff` messages with `takeover`, and a turn the worker declines while the conversation is held adds nothing (`isProcessing` stays false, and `status` does not say the agent is working or done), and a card that was waiting is cleared. A restored conversation shows the same from `getConversation`.
|
|
17
|
+
- `useStaffConversation(conversationId)`: the staff console's side, inside the provider. It loads the conversation through `config.staff.getConversation`, follows it live, and `takeOver`, `send` and `handBack` through the platform's own routes (`config.staff`), which check the staff member's permission; `heldByMe` says whether the viewer holds it.
|
|
18
|
+
- `ApprovalCard`: shows what an irreversible call will do and takes the person's decision. It can't be bound to the agent: only a person approves, by their click or, on a call or in a chat where the agent read the call back, by saying yes. With `config.conversationRoom`, the provider also shows the card of a turn of the open conversation it did not start (a call's), takes the grant the realtime server pushes when the person approves by voice (checked against its conversation and rooms, claimed on its own socket, handed to `config.grantApproval`, which should return the runtime's answer), and the card then says how they decided (`labels.approvedBy`, `labels.declinedBy`) instead of offering its buttons.
|
|
17
19
|
- `useFeedback`, `storedToAgentMessages`, and the view annotations.
|
|
18
20
|
|
|
19
21
|
React 18 or 19 is a peer dependency. It releases with the rest of the agent SDK, under one version: see [VERSIONING.md](https://github.com/wesreid/oui/blob/main/VERSIONING.md).
|
|
@@ -4,11 +4,15 @@
|
|
|
4
4
|
*
|
|
5
5
|
* It shows what the call does in the action's own declared words (its title,
|
|
6
6
|
* what it does, its arguments by their labels), never the assistant's. A
|
|
7
|
-
* click on Approve or Decline
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
7
|
+
* click on Approve or Decline goes to the approval store on the user's own
|
|
8
|
+
* socket, an approval's grant goes to this tab's OUI runtime (`grantApproval`
|
|
9
|
+
* in the client config), and the turn continues with the token outside the
|
|
10
|
+
* message text. A "yes" typed in the product's chat is only a message.
|
|
11
|
+
*
|
|
12
|
+
* On a call, or in a chat where the agent read the call back, the person may
|
|
13
|
+
* also decide by saying so. The card then shows how they decided
|
|
14
|
+
* ("Approved by voice") and its buttons go; the grant reaches this tab's
|
|
15
|
+
* runtime from the store, and the conversation's own turn carries the token.
|
|
12
16
|
*
|
|
13
17
|
* The card takes no `agent` prop, and the package declares it person-only
|
|
14
18
|
* (`oui.personOnly`), so the generator refuses to bind it: the assistant can
|
|
@@ -36,18 +40,27 @@ export interface ApprovalCardParts {
|
|
|
36
40
|
Card: ComponentType<ApprovalCardFrameProps>;
|
|
37
41
|
Button: ComponentType<ApprovalCardButtonProps>;
|
|
38
42
|
}
|
|
43
|
+
/** The conversation channels a person can decide an approval in, outside the card. */
|
|
44
|
+
export type ApprovalCardElsewhereChannel = 'voice' | 'phone' | 'chat' | 'sms';
|
|
39
45
|
export interface ApprovalCardLabels {
|
|
40
46
|
approve: string;
|
|
41
47
|
decline: string;
|
|
42
48
|
dismiss: string;
|
|
43
49
|
waiting: string;
|
|
44
50
|
expired: string;
|
|
51
|
+
/** What the card says once the person approved by voice, on the phone or in chat. */
|
|
52
|
+
approvedBy: Record<Exclude<ApprovalCardElsewhereChannel, 'sms'>, string>;
|
|
53
|
+
/** What the card says once the person declined in a conversation channel. */
|
|
54
|
+
declinedBy: Record<ApprovalCardElsewhereChannel, string>;
|
|
45
55
|
}
|
|
46
56
|
export interface ApprovalCardProps {
|
|
47
57
|
/** The host's own card and button. Default: plain, unstyled HTML. */
|
|
48
58
|
components?: Partial<ApprovalCardParts>;
|
|
49
|
-
/** The card's own words, for another language. */
|
|
50
|
-
labels?: Partial<ApprovalCardLabels
|
|
59
|
+
/** The card's own words, for another language. `approvedBy` and `declinedBy` may name only some channels. */
|
|
60
|
+
labels?: Partial<Omit<ApprovalCardLabels, 'approvedBy' | 'declinedBy'>> & {
|
|
61
|
+
approvedBy?: Partial<ApprovalCardLabels['approvedBy']>;
|
|
62
|
+
declinedBy?: Partial<ApprovalCardLabels['declinedBy']>;
|
|
63
|
+
};
|
|
51
64
|
}
|
|
52
65
|
/** Renders nothing until a turn stops for the user's approval. */
|
|
53
66
|
export declare function ApprovalCard({ components, labels }: ApprovalCardProps): React.JSX.Element | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApprovalCard.d.ts","sourceRoot":"","sources":["../../src/approvals/ApprovalCard.tsx"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ApprovalCard.d.ts","sourceRoot":"","sources":["../../src/approvals/ApprovalCard.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,EAAmC,KAAK,aAAa,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,MAAM,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,kBAAkB,EAAE,YAAY,GAAG,YAAY,CAAC,CAAC,GAAG;QACxE,UAAU,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC,CAAC;QACvD,UAAU,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC,CAAC;KACxD,CAAC;CACH;AA+BD,kEAAkE;AAClE,wBAAgB,YAAY,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,iBAAiB,4BA2ErE"}
|
|
@@ -5,11 +5,15 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
5
5
|
*
|
|
6
6
|
* It shows what the call does in the action's own declared words (its title,
|
|
7
7
|
* what it does, its arguments by their labels), never the assistant's. A
|
|
8
|
-
* click on Approve or Decline
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
8
|
+
* click on Approve or Decline goes to the approval store on the user's own
|
|
9
|
+
* socket, an approval's grant goes to this tab's OUI runtime (`grantApproval`
|
|
10
|
+
* in the client config), and the turn continues with the token outside the
|
|
11
|
+
* message text. A "yes" typed in the product's chat is only a message.
|
|
12
|
+
*
|
|
13
|
+
* On a call, or in a chat where the agent read the call back, the person may
|
|
14
|
+
* also decide by saying so. The card then shows how they decided
|
|
15
|
+
* ("Approved by voice") and its buttons go; the grant reaches this tab's
|
|
16
|
+
* runtime from the store, and the conversation's own turn carries the token.
|
|
13
17
|
*
|
|
14
18
|
* The card takes no `agent` prop, and the package declares it person-only
|
|
15
19
|
* (`oui.personOnly`), so the generator refuses to bind it: the assistant can
|
|
@@ -24,6 +28,8 @@ const DEFAULT_LABELS = {
|
|
|
24
28
|
dismiss: 'Dismiss',
|
|
25
29
|
waiting: 'This runs only if you approve it here.',
|
|
26
30
|
expired: 'This approval has expired.',
|
|
31
|
+
approvedBy: { voice: 'Approved by voice.', phone: 'Approved on the phone.', chat: 'Approved in the chat.' },
|
|
32
|
+
declinedBy: { voice: 'Declined by voice.', phone: 'Declined on the phone.', chat: 'Declined in the chat.', sms: 'Declined by text message.' },
|
|
27
33
|
};
|
|
28
34
|
function PlainCard({ title, subtitle, actions, children }) {
|
|
29
35
|
return (_jsxs("section", { "aria-label": typeof title === 'string' ? title : undefined, children: [_jsx("h3", { children: title }), subtitle ? _jsx("p", { children: subtitle }) : null, children, _jsx("div", { children: actions })] }));
|
|
@@ -36,16 +42,33 @@ export function ApprovalCard({ components, labels }) {
|
|
|
36
42
|
const decision = useContext(ApprovalDecisionContext);
|
|
37
43
|
if (!decision)
|
|
38
44
|
throw new Error('ApprovalCard must be used within an AgentProvider');
|
|
39
|
-
const { pending, deciding, error, decide, dismiss } = decision;
|
|
45
|
+
const { pending, decidedElsewhere, deciding, error, decide, dismiss } = decision;
|
|
40
46
|
const expired = useExpired(pending?.expiresAt);
|
|
41
47
|
if (!pending)
|
|
42
48
|
return null;
|
|
43
49
|
const Card = components?.Card ?? PlainCard;
|
|
44
50
|
const Button = components?.Button ?? PlainButton;
|
|
45
|
-
const text = {
|
|
51
|
+
const text = {
|
|
52
|
+
...DEFAULT_LABELS,
|
|
53
|
+
...labels,
|
|
54
|
+
approvedBy: { ...DEFAULT_LABELS.approvedBy, ...labels?.approvedBy },
|
|
55
|
+
declinedBy: { ...DEFAULT_LABELS.declinedBy, ...labels?.declinedBy },
|
|
56
|
+
};
|
|
46
57
|
const closed = expired || error !== null;
|
|
47
58
|
const { preview } = pending;
|
|
48
|
-
|
|
59
|
+
const argumentList = preview.arguments.length > 0 ? (_jsx("dl", { children: preview.arguments.map(arg => (_jsxs(React.Fragment, { children: [_jsx("dt", { children: arg.label }), _jsx("dd", { children: arg.value })] }, arg.name))) })) : null;
|
|
60
|
+
// Decided by voice, on the phone or in chat: the card says how, and no longer decides.
|
|
61
|
+
if (decidedElsewhere) {
|
|
62
|
+
const said = elsewhereText(text, decidedElsewhere.decision, decidedElsewhere.channel);
|
|
63
|
+
return (_jsxs(Card, { title: preview.title, subtitle: preview.consequence, tone: decidedElsewhere.decision === 'approve' ? 'default' : 'warning', actions: _jsx(Button, { variant: "secondary", onClick: dismiss, children: text.dismiss }), children: [argumentList, _jsx("p", { role: "status", children: said })] }));
|
|
64
|
+
}
|
|
65
|
+
return (_jsxs(Card, { title: preview.title, subtitle: preview.consequence, tone: "warning", actions: _jsxs(_Fragment, { children: [closed ? (_jsx(Button, { variant: "secondary", onClick: dismiss, disabled: deciding, children: error !== null ? text.dismiss : text.decline })) : (_jsx(Button, { variant: "secondary", onClick: () => decide('decline'), disabled: deciding, children: text.decline })), _jsx(Button, { variant: "primary", onClick: () => decide('approve'), disabled: deciding || closed, children: text.approve })] }), children: [argumentList, error !== null ? _jsx("p", { role: "alert", children: error }) : _jsx("p", { children: expired ? text.expired : text.waiting })] }));
|
|
66
|
+
}
|
|
67
|
+
/** What the card says of a decision made in a conversation channel. */
|
|
68
|
+
function elsewhereText(text, decision, channel) {
|
|
69
|
+
if (decision === 'approve')
|
|
70
|
+
return text.approvedBy[channel] ?? text.approvedBy.voice;
|
|
71
|
+
return text.declinedBy[channel] ?? text.declinedBy.voice;
|
|
49
72
|
}
|
|
50
73
|
/** Whether `expiresAt` has passed, turning true when it does. */
|
|
51
74
|
function useExpired(expiresAt) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApprovalCard.js","sourceRoot":"","sources":["../../src/approvals/ApprovalCard.tsx"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"ApprovalCard.js","sourceRoot":"","sources":["../../src/approvals/ApprovalCard.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAsC,MAAM,OAAO,CAAC;AACnG,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAkDxD,MAAM,cAAc,GAAu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O,GAAK,IACzF,CACR,CAAC;AACJ,CAAC;AAED,uEAAuE;AACvE,SAAS,aAAa,CAAC,IAAwB,EAAE,QAA+B,EAAE,OAAe;IAC/F,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC,UAAU,CAAC,OAAiD,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;IAC/H,OAAO,IAAI,CAAC,UAAU,CAAC,OAAuC,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;AAC3F,CAAC;AAED,iEAAiE;AACjE,SAAS,UAAU,CAAC,SAA6B;IAC/C,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IACjD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,SAAS,KAAK,SAAS;YAAE,OAAO;QACpC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QACnB,MAAM,IAAI,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACpC,IAAI,IAAI,IAAI,CAAC;YAAE,OAAO;QACtB,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;QACzD,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAChB,OAAO,SAAS,KAAK,SAAS,IAAI,GAAG,IAAI,SAAS,CAAC;AACrD,CAAC"}
|
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
import type { ApprovalDecision, ApprovalRefusal } from '@ouispec/agent-core';
|
|
1
|
+
import type { ApprovalChannel, ApprovalDecision, ApprovalRefusal } from '@ouispec/agent-core';
|
|
2
2
|
import type { AgentApprovalRequest } from '../provider/types.js';
|
|
3
|
+
/** How the person decided the pending approval outside the card: by voice, on the phone or in chat. */
|
|
4
|
+
export interface ApprovalDecidedElsewhere {
|
|
5
|
+
decision: ApprovalDecision;
|
|
6
|
+
channel: ApprovalChannel;
|
|
7
|
+
}
|
|
3
8
|
export interface ApprovalDecisionState {
|
|
4
9
|
pending: AgentApprovalRequest | null;
|
|
10
|
+
/**
|
|
11
|
+
* Set once the person decided the pending approval in a conversation
|
|
12
|
+
* channel: the card says so and no longer decides. The turn that carries
|
|
13
|
+
* the decision is the conversation's, not this tab's.
|
|
14
|
+
*/
|
|
15
|
+
decidedElsewhere: ApprovalDecidedElsewhere | null;
|
|
5
16
|
/** True while the approval store answers the click. */
|
|
6
17
|
deciding: boolean;
|
|
7
18
|
/** Why the last decision was refused, for the user. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decision.d.ts","sourceRoot":"","sources":["../../src/approvals/decision.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"decision.d.ts","sourceRoot":"","sources":["../../src/approvals/decision.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC9F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,uGAAuG;AACvG,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,OAAO,EAAE,eAAe,CAAC;CAC1B;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,oBAAoB,GAAG,IAAI,CAAC;IACrC;;;;OAIG;IACH,gBAAgB,EAAE,wBAAwB,GAAG,IAAI,CAAC;IAClD,uDAAuD;IACvD,QAAQ,EAAE,OAAO,CAAC;IAClB,uDAAuD;IACvD,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,8EAA8E;IAC9E,MAAM,EAAE,CAAC,QAAQ,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,8DAA8D;IAC9D,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,eAAO,MAAM,uBAAuB,uDAAoD,CAAC;AAEzF,mEAAmE;AACnE,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAcpE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decision.js","sourceRoot":"","sources":["../../src/approvals/decision.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"decision.js","sourceRoot":"","sources":["../../src/approvals/decision.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AA4BtC,MAAM,CAAC,MAAM,uBAAuB,GAAG,aAAa,CAA+B,IAAI,CAAC,CAAC;AAEzF,mEAAmE;AACnE,MAAM,UAAU,mBAAmB,CAAC,OAAwB;IAC1D,QAAQ,OAAO,CAAC,MAAM,EAAE,CAAC;QACvB,KAAK,SAAS;YACZ,OAAO,+EAA+E,CAAC;QACzF,KAAK,SAAS,CAAC;QACf,KAAK,MAAM;YACT,OAAO,gCAAgC,CAAC;QAC1C,KAAK,SAAS;YACZ,OAAO,wFAAwF,CAAC;QAClG,KAAK,WAAW;YACd,OAAO,wCAAwC,CAAC;QAClD;YACE,OAAO,wCAAwC,OAAO,CAAC,KAAK,GAAG,CAAC;IACpE,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,10 @@ export { useFeedback } from './hooks/useFeedback.js';
|
|
|
4
4
|
export { storedToAgentMessages } from './provider/stored-messages.js';
|
|
5
5
|
export { readConversationSummary, readConversationSummaries } from './provider/conversation-summaries.js';
|
|
6
6
|
export type { ComposerAttachment, ComposerAttachmentsState, NotSentReason } from './provider/attachments.js';
|
|
7
|
+
export { useStaffConversation } from './staff/useStaffConversation.js';
|
|
8
|
+
export type { StaffConversationState } from './staff/useStaffConversation.js';
|
|
7
9
|
export { ApprovalCard } from './approvals/ApprovalCard.js';
|
|
8
|
-
export type { ApprovalCardProps, ApprovalCardParts, ApprovalCardFrameProps, ApprovalCardButtonProps, ApprovalCardLabels, } from './approvals/ApprovalCard.js';
|
|
10
|
+
export type { ApprovalCardProps, ApprovalCardParts, ApprovalCardFrameProps, ApprovalCardButtonProps, ApprovalCardLabels, ApprovalCardElsewhereChannel, } from './approvals/ApprovalCard.js';
|
|
9
11
|
export type { AgentApprovalRequest, AgentClientConfig, AgentContextValue, AgentHistoryState, AgentMessage, AgentReasoning, AgentStatus, AgentStatusState, AgentTurnEnd, AgentToolCallState, AgentDebugState, AgentSessionRecord, DebugLogEntry, DebugLogLevel, DebugLogNamespace, SendMessageOptions, SendMessageResult, } from './provider/types.js';
|
|
10
12
|
export { AgentEntityComponent, defineAgentEntity, AgentEntity, asAgentEntity, useViewAnnotation, } from './entity/index.js';
|
|
11
13
|
export type { AgentEntityRenderContext, DefineAgentEntityConfig, AgentEntityProps, AgentEntityChildContext, AsAgentEntityConfig, InjectedAgentEntityProps, UseViewAnnotationOptions, UseViewAnnotationReturn, } from './entity/index.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC/G,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,OAAO,EAAE,uBAAuB,EAAE,y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iBAAiB,GAClB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,wBAAwB,EACxB,uBAAuB,EACvB,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,wBAAwB,EACxB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,YAAY,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,8 @@ export { useFeedback } from './hooks/useFeedback.js';
|
|
|
4
4
|
export { storedToAgentMessages } from './provider/stored-messages.js';
|
|
5
5
|
// A listed conversation's spoken marks, as the history hands them on.
|
|
6
6
|
export { readConversationSummary, readConversationSummaries } from './provider/conversation-summaries.js';
|
|
7
|
+
// A person on the staff takes a conversation over and hands it back: the staff console's side.
|
|
8
|
+
export { useStaffConversation } from './staff/useStaffConversation.js';
|
|
7
9
|
// Approvals: the card where the person approves an irreversible call.
|
|
8
10
|
export { ApprovalCard } from './approvals/ApprovalCard.js';
|
|
9
11
|
// Entity integration patterns
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC/G,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,sEAAsE;AACtE,OAAO,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AAG1G,sEAAsE;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC/G,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,sEAAsE;AACtE,OAAO,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AAG1G,+FAA+F;AAC/F,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE,sEAAsE;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AA8B3D,8BAA8B;AAC9B,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAa3B,2CAA2C;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAEzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentProvider.d.ts","sourceRoot":"","sources":["../../src/provider/AgentProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAuF,MAAM,OAAO,CAAC;AAC5G,OAAO,KAAK,EACV,iBAAiB,
|
|
1
|
+
{"version":3,"file":"AgentProvider.d.ts","sourceRoot":"","sources":["../../src/provider/AgentProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAuF,MAAM,OAAO,CAAC;AAC5G,OAAO,KAAK,EACV,iBAAiB,EAMlB,MAAM,qBAAqB,CAAC;AA4B7B,OAAO,KAAK,EAEV,iBAAiB,EAGjB,WAAW,EASZ,MAAM,YAAY,CAAC;AAmBpB,gGAAgG;AAChG,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAiE9C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE;IAAE,MAAM,EAAE,iBAAiB,CAAC;IAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,iFA4xC3G;AAED,wBAAgB,QAAQ,IAAI,iBAAiB,CAI5C;AAED;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,WAAW,CAE5C"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { createContext, useContext, useState, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
2
|
-
import { APPROVAL_DECIDE_EVENT, TURN_STOP_EVENT, readMessageInput } from '@ouispec/agent-core';
|
|
2
|
+
import { AGENT_SOCKET_EVENTS, APPROVAL_DECIDE_EVENT, APPROVAL_PUSH_EVENTS, CONVERSATION_EVENTS, approvalGrantRefusal, claimApprovalGrant, readApprovalDeclined, readApprovalGranted, TURN_STOP_EVENT, readConversationHold, readConversationMessage, readMessageInput, } from '@ouispec/agent-core';
|
|
3
3
|
import { useComposerAttachments } from './attachments.js';
|
|
4
4
|
import { ALL_AGENT_SOCKET_EVENTS, parseSocketEvent } from '@ouispec/agent-core';
|
|
5
5
|
import { browserTimeZone } from './time-zone.js';
|
|
@@ -10,6 +10,8 @@ import { storedToAgentMessages } from './stored-messages.js';
|
|
|
10
10
|
import { agentStatusOf, applyReasoningEvent, endOpenReasoning, turnEndOf } from './turn-progress.js';
|
|
11
11
|
import { readConversationSummaries, readConversationSummary } from './conversation-summaries.js';
|
|
12
12
|
import { SDK_PACKAGE, SDK_VERSION } from '../version.js';
|
|
13
|
+
import { AgentInternalsContext } from './internals.js';
|
|
14
|
+
import { conversationChangeMessage, staffAgentMessage } from './conversation-messages.js';
|
|
13
15
|
const AgentContext = createContext(null);
|
|
14
16
|
const MAX_DEBUG_LOGS = 500;
|
|
15
17
|
const DEFAULT_ACTIVE_CONVERSATION_KEY = 'agent-sdk.activeConversation';
|
|
@@ -133,6 +135,12 @@ export function AgentProvider({ config, children }) {
|
|
|
133
135
|
const [lastTurnEnd, setLastTurnEnd] = useState(null);
|
|
134
136
|
const [approvalDeciding, setApprovalDeciding] = useState(false);
|
|
135
137
|
const [approvalError, setApprovalError] = useState(null);
|
|
138
|
+
// An approval the person decided in a conversation channel (by voice, on the phone, in chat), as its card shows it.
|
|
139
|
+
const [approvalDecidedElsewhere, setApprovalDecidedElsewhere] = useState(null);
|
|
140
|
+
// Who holds the open conversation, when a person on the staff took it over.
|
|
141
|
+
const [hold, setHold] = useState(null);
|
|
142
|
+
// The open conversation's room, once joined: joined again on every reconnect, left on a switch.
|
|
143
|
+
const conversationRoomRef = useRef(null);
|
|
136
144
|
// The turn the person asked to stop, from their Stop until its end arrives.
|
|
137
145
|
const [isStopping, setIsStopping] = useState(false);
|
|
138
146
|
const stoppingRef = useRef(null);
|
|
@@ -220,7 +228,19 @@ export function AgentProvider({ config, children }) {
|
|
|
220
228
|
addDebugLog('info', 'agent:socket', `Rejoining turn room after reconnect: ${active.room}`, { room: active.room });
|
|
221
229
|
joinRoom(socket, active.room, active.token);
|
|
222
230
|
}
|
|
231
|
+
const following = conversationRoomRef.current;
|
|
232
|
+
if (following)
|
|
233
|
+
joinRoom(socket, following.room, following.token);
|
|
223
234
|
});
|
|
235
|
+
// The open conversation's take-over, hand-back and staff messages; an approval the person decided in a
|
|
236
|
+
// conversation channel; and an approval card from a turn of the conversation this tab did not start (a call's).
|
|
237
|
+
const conversationListeners = [
|
|
238
|
+
...Object.values(CONVERSATION_EVENTS).map((event) => [event, (data) => handleConversationEventRef.current(event, data)]),
|
|
239
|
+
...Object.values(APPROVAL_PUSH_EVENTS).map((event) => [event, (data) => handleApprovalPushRef.current(event, data)]),
|
|
240
|
+
[AGENT_SOCKET_EVENTS.APPROVAL_REQUIRED, (data) => handleOtherTurnApprovalRef.current(data)],
|
|
241
|
+
];
|
|
242
|
+
for (const [event, listener] of conversationListeners)
|
|
243
|
+
socket.on(event, listener);
|
|
224
244
|
socket.on('disconnect', (reason) => {
|
|
225
245
|
setConnected(false);
|
|
226
246
|
addDebugLog('warn', 'agent:socket', `Disconnected: ${reason}`, { reason });
|
|
@@ -235,6 +255,8 @@ export function AgentProvider({ config, children }) {
|
|
|
235
255
|
addDebugLog('info', 'agent:socket', 'Connecting...', { url });
|
|
236
256
|
socketRef.current = socket;
|
|
237
257
|
return () => {
|
|
258
|
+
for (const [event, listener] of conversationListeners)
|
|
259
|
+
socket.off(event, listener);
|
|
238
260
|
socket.disconnect();
|
|
239
261
|
socketRef.current = null;
|
|
240
262
|
setConnected(false);
|
|
@@ -309,10 +331,11 @@ export function AgentProvider({ config, children }) {
|
|
|
309
331
|
return { ...m, toolCall: { ...m.toolCall, status: 'stopped' } };
|
|
310
332
|
return m.isStreaming ? { ...m, isStreaming: false } : m;
|
|
311
333
|
});
|
|
312
|
-
// A turn stopped before it said anything still shows that it was stopped
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
334
|
+
// A turn stopped before it said anything still shows that it was stopped; one a take-over stopped
|
|
335
|
+
// shows nothing of its own, since the take-over is in the conversation.
|
|
336
|
+
if (marked.some((m) => m.id === msgId) || reason === 'taken_over')
|
|
337
|
+
return marked;
|
|
338
|
+
return [...marked, { id: msgId, role: 'assistant', content: '', timestamp: Date.now(), stopped: reason }];
|
|
316
339
|
};
|
|
317
340
|
/** A stop is no longer waited on: its turn ended, or the tab moved on. */
|
|
318
341
|
const clearStopping = () => {
|
|
@@ -603,6 +626,136 @@ export function AgentProvider({ config, children }) {
|
|
|
603
626
|
addDebugLog('info', 'agent:socket', `Unsubscribed from room: ${room}`, { room });
|
|
604
627
|
};
|
|
605
628
|
}, [handleProtocolEvent, addDebugLog, joinRoom]);
|
|
629
|
+
// --- The open conversation's room ---
|
|
630
|
+
// With the platform's `conversationRoom`, the tab follows its conversation between turns: a person on the
|
|
631
|
+
// staff taking it over, their messages, and the hand-back.
|
|
632
|
+
const appendOnce = useCallback((message) => {
|
|
633
|
+
setMessages(prev => (prev.some(m => m.id === message.id) ? prev : [...prev, message]));
|
|
634
|
+
}, []);
|
|
635
|
+
const handleConversationEventRef = useRef(() => { });
|
|
636
|
+
handleConversationEventRef.current = (event, data) => {
|
|
637
|
+
const payload = (data ?? {});
|
|
638
|
+
// Another conversation's event, from a room this tab is still leaving: not this one's.
|
|
639
|
+
if (typeof payload.conversationId !== 'string' || payload.conversationId !== conversationIdRef.current)
|
|
640
|
+
return;
|
|
641
|
+
addDebugLog('socket', 'agent:socket', `← ${event}`, { event, data });
|
|
642
|
+
if (event === CONVERSATION_EVENTS.MESSAGE) {
|
|
643
|
+
// The customer's and the agent's own messages reach this tab through its turns; a person's only here.
|
|
644
|
+
const message = readConversationMessage(payload.message);
|
|
645
|
+
if (message?.role === 'staff')
|
|
646
|
+
appendOnce(staffAgentMessage(message));
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
const changed = readConversationHold(payload.hold);
|
|
650
|
+
if (!changed)
|
|
651
|
+
return;
|
|
652
|
+
const change = event === CONVERSATION_EVENTS.TAKEN_OVER ? 'taken_over' : 'handed_back';
|
|
653
|
+
const at = typeof payload.at === 'number' ? payload.at : Date.now();
|
|
654
|
+
setHold(change === 'taken_over' ? changed : null);
|
|
655
|
+
// The person now answering did not ask for the card: it is withdrawn.
|
|
656
|
+
if (change === 'taken_over')
|
|
657
|
+
setPendingApproval(null);
|
|
658
|
+
appendOnce(conversationChangeMessage(change, changed, at));
|
|
659
|
+
addDebugLog('info', 'agent:state', change === 'taken_over' ? 'A person took the conversation over' : 'The conversation was handed back', {
|
|
660
|
+
holder: changed.holder.userId,
|
|
661
|
+
});
|
|
662
|
+
};
|
|
663
|
+
// --- An approval decided in a conversation channel, and a card from a turn this tab did not start ---
|
|
664
|
+
// The grants this tab has claimed or tried to, by grant id: a replayed push is not claimed twice.
|
|
665
|
+
const claimedGrantsRef = useRef(new Set());
|
|
666
|
+
const handleApprovalPushRef = useRef(() => { });
|
|
667
|
+
handleApprovalPushRef.current = (event, data) => {
|
|
668
|
+
if (event === APPROVAL_PUSH_EVENTS.DECLINED) {
|
|
669
|
+
const declined = readApprovalDeclined(data);
|
|
670
|
+
if (!declined || declined.conversationId !== conversationIdRef.current)
|
|
671
|
+
return;
|
|
672
|
+
addDebugLog('info', 'agent:state', `Approval declined ${declined.channel === 'phone' ? 'on the phone' : `by ${declined.channel}`}`, {
|
|
673
|
+
approvalId: declined.approvalId,
|
|
674
|
+
});
|
|
675
|
+
setApprovalDecidedElsewhere({ approvalId: declined.approvalId, decision: 'decline', channel: declined.channel });
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
const grant = readApprovalGranted(data);
|
|
679
|
+
if (!grant)
|
|
680
|
+
return;
|
|
681
|
+
const rooms = [conversationRoomRef.current?.room, activeRoomRef.current?.room].filter((r) => !!r);
|
|
682
|
+
const refusal = approvalGrantRefusal(grant, { conversationId: conversationIdRef.current, rooms }, Date.now());
|
|
683
|
+
if (refusal) {
|
|
684
|
+
addDebugLog('info', 'agent:state', `A pushed approval grant is not this tab's: ${refusal}`, { approvalId: grant.approvalId, room: grant.room });
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
// The person approved it: every tab on the conversation shows that, whichever of them takes the grant.
|
|
688
|
+
setApprovalDecidedElsewhere({ approvalId: grant.approvalId, decision: 'approve', channel: grant.channel });
|
|
689
|
+
if (claimedGrantsRef.current.has(grant.grantId))
|
|
690
|
+
return;
|
|
691
|
+
claimedGrantsRef.current.add(grant.grantId);
|
|
692
|
+
if (claimedGrantsRef.current.size > ENDED_TURNS_REMEMBERED) {
|
|
693
|
+
claimedGrantsRef.current.delete(claimedGrantsRef.current.values().next().value);
|
|
694
|
+
}
|
|
695
|
+
const grantApproval = configRef.current.grantApproval;
|
|
696
|
+
const socket = socketRef.current;
|
|
697
|
+
if (!grantApproval || !socket) {
|
|
698
|
+
addDebugLog('warn', 'agent:state', 'A pushed approval grant cannot be taken: this tab has no OUI runtime grant seam or no socket', {
|
|
699
|
+
approvalId: grant.approvalId,
|
|
700
|
+
});
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
void claimApprovalGrant(socket, grant).then((answer) => {
|
|
704
|
+
if (!answer.ok) {
|
|
705
|
+
// Another tab took it (`used`), or it was withdrawn or expired: this tab's runtime holds nothing.
|
|
706
|
+
addDebugLog('info', 'agent:state', `Approval grant not claimed: ${answer.reason}`, { approvalId: grant.approvalId, reason: answer.reason });
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
const taken = grantApproval({ approvalId: answer.approvalId, argsHash: answer.argsHash, expiresAt: answer.expiresAt });
|
|
710
|
+
if (taken === false) {
|
|
711
|
+
addDebugLog('warn', 'agent:state', 'The OUI runtime refused a claimed approval grant (one it held or used)', { approvalId: grant.approvalId });
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
addDebugLog('info', 'agent:state', `Approval grant claimed: approved by ${answer.channel}`, { approvalId: grant.approvalId });
|
|
715
|
+
});
|
|
716
|
+
};
|
|
717
|
+
const handleOtherTurnApprovalRef = useRef(() => { });
|
|
718
|
+
handleOtherTurnApprovalRef.current = (data) => {
|
|
719
|
+
const event = parseSocketEvent(AGENT_SOCKET_EVENTS.APPROVAL_REQUIRED, data, '');
|
|
720
|
+
if (event?.type !== 'approval_required' || !event.turnId || !event.approvalId)
|
|
721
|
+
return;
|
|
722
|
+
if (event.conversationId !== conversationIdRef.current)
|
|
723
|
+
return;
|
|
724
|
+
// The tab's own turns' cards come through the turn's own subscription; while a start is in flight, any card may be its.
|
|
725
|
+
const { starting, turnId: live } = liveTurnRef.current;
|
|
726
|
+
if (starting || event.turnId === live || endedTurnsRef.current.has(event.turnId))
|
|
727
|
+
return;
|
|
728
|
+
const { type: _type, ...request } = event;
|
|
729
|
+
addDebugLog('info', 'agent:state', 'An approval card from a turn of this conversation this tab did not start', {
|
|
730
|
+
turnId: event.turnId,
|
|
731
|
+
approvalId: event.approvalId,
|
|
732
|
+
});
|
|
733
|
+
setPendingApproval(request);
|
|
734
|
+
setApprovalError(null);
|
|
735
|
+
setApprovalDeciding(false);
|
|
736
|
+
};
|
|
737
|
+
useEffect(() => {
|
|
738
|
+
const seam = configRef.current.conversationRoom;
|
|
739
|
+
if (!seam || !conversationId)
|
|
740
|
+
return;
|
|
741
|
+
let cancelled = false;
|
|
742
|
+
void seam(conversationId).then(({ room, roomToken }) => {
|
|
743
|
+
if (cancelled)
|
|
744
|
+
return;
|
|
745
|
+
conversationRoomRef.current = { conversationId, room, ...(roomToken ? { token: roomToken } : {}) };
|
|
746
|
+
const socket = socketRef.current;
|
|
747
|
+
if (socket?.connected)
|
|
748
|
+
joinRoom(socket, room, roomToken);
|
|
749
|
+
}, (err) => addDebugLog('warn', 'agent:api', `The conversation's room could not be had: ${reasonOf(err)}`, { conversationId }));
|
|
750
|
+
return () => {
|
|
751
|
+
cancelled = true;
|
|
752
|
+
const followed = conversationRoomRef.current;
|
|
753
|
+
if (followed?.conversationId === conversationId) {
|
|
754
|
+
conversationRoomRef.current = null;
|
|
755
|
+
socketRef.current?.emit('unsubscribe', [followed.room]);
|
|
756
|
+
}
|
|
757
|
+
};
|
|
758
|
+
}, [conversationId, joinRoom, addDebugLog]);
|
|
606
759
|
// Collect context from visible annotations and current route
|
|
607
760
|
const collectContext = useCallback(() => {
|
|
608
761
|
const annotations = annotationRegistry.getVisibleAnnotations();
|
|
@@ -810,11 +963,16 @@ export function AgentProvider({ config, children }) {
|
|
|
810
963
|
// nothing an app binds for the assistant can reach it.
|
|
811
964
|
const pendingApprovalRef = useRef(null);
|
|
812
965
|
pendingApprovalRef.current = pendingApproval;
|
|
966
|
+
const approvalDecidedElsewhereRef = useRef(approvalDecidedElsewhere);
|
|
967
|
+
approvalDecidedElsewhereRef.current = approvalDecidedElsewhere;
|
|
813
968
|
const decideApproval = useCallback(async (decision) => {
|
|
814
969
|
const request = pendingApprovalRef.current;
|
|
815
970
|
const socket = socketRef.current;
|
|
816
971
|
if (!request)
|
|
817
972
|
return;
|
|
973
|
+
// Already decided by voice, on the phone or in chat: the card no longer decides.
|
|
974
|
+
if (approvalDecidedElsewhereRef.current?.approvalId === request.approvalId)
|
|
975
|
+
return;
|
|
818
976
|
if (!socket) {
|
|
819
977
|
setApprovalError('Not connected: try again once the assistant reconnects.');
|
|
820
978
|
return;
|
|
@@ -896,6 +1054,7 @@ export function AgentProvider({ config, children }) {
|
|
|
896
1054
|
setMessages(storedToAgentMessages(stored.messages));
|
|
897
1055
|
setReasoning([]);
|
|
898
1056
|
setLastTurnEnd(null);
|
|
1057
|
+
setHold(stored.hold ? readConversationHold(stored.hold) : null);
|
|
899
1058
|
setPresentedOptions(null);
|
|
900
1059
|
setPendingApproval(null);
|
|
901
1060
|
setHistoryError(null);
|
|
@@ -1027,6 +1186,7 @@ export function AgentProvider({ config, children }) {
|
|
|
1027
1186
|
setMessages([]);
|
|
1028
1187
|
setReasoning([]);
|
|
1029
1188
|
setLastTurnEnd(null);
|
|
1189
|
+
setHold(null);
|
|
1030
1190
|
clearComposer();
|
|
1031
1191
|
setPresentedOptions(null);
|
|
1032
1192
|
setPendingApproval(null);
|
|
@@ -1125,7 +1285,8 @@ export function AgentProvider({ config, children }) {
|
|
|
1125
1285
|
setLastTurnEnd(prev => (prev?.kind === 'done' && !prev.acknowledged ? { ...prev, acknowledged: true } : prev));
|
|
1126
1286
|
}, []);
|
|
1127
1287
|
const statusValue = useMemo(() => agentStatusOf({
|
|
1128
|
-
|
|
1288
|
+
// A turn the worker declines while a person holds the conversation is not the agent working.
|
|
1289
|
+
isStreaming: isStreaming && !hold,
|
|
1129
1290
|
currentTurnId,
|
|
1130
1291
|
messages,
|
|
1131
1292
|
reasoning,
|
|
@@ -1133,7 +1294,7 @@ export function AgentProvider({ config, children }) {
|
|
|
1133
1294
|
lastEnd: lastTurnEnd,
|
|
1134
1295
|
toolLabels: config.toolLabels,
|
|
1135
1296
|
planningText: config.planningText,
|
|
1136
|
-
}), [isStreaming, currentTurnId, messages, reasoning, pendingApproval, presentedOptions, lastTurnEnd, config.toolLabels, config.planningText]);
|
|
1297
|
+
}), [isStreaming, hold, currentTurnId, messages, reasoning, pendingApproval, presentedOptions, lastTurnEnd, config.toolLabels, config.planningText]);
|
|
1137
1298
|
const status = useMemo(() => ({ ...statusValue, clearDone }), [statusValue, clearDone]);
|
|
1138
1299
|
const contextValue = {
|
|
1139
1300
|
isOpen,
|
|
@@ -1147,7 +1308,8 @@ export function AgentProvider({ config, children }) {
|
|
|
1147
1308
|
acceptedTurnId,
|
|
1148
1309
|
messages,
|
|
1149
1310
|
isStreaming,
|
|
1150
|
-
|
|
1311
|
+
// A turn the worker declines while a person holds the conversation is not the agent answering.
|
|
1312
|
+
isProcessing: isStreaming && !hold,
|
|
1151
1313
|
currentTurnId,
|
|
1152
1314
|
conversationId,
|
|
1153
1315
|
connected,
|
|
@@ -1157,6 +1319,7 @@ export function AgentProvider({ config, children }) {
|
|
|
1157
1319
|
dismissOptions,
|
|
1158
1320
|
pendingApproval,
|
|
1159
1321
|
socket: socketRef.current,
|
|
1322
|
+
hold,
|
|
1160
1323
|
history: {
|
|
1161
1324
|
available: Boolean(config.listConversations && config.getConversation),
|
|
1162
1325
|
manage: {
|
|
@@ -1186,12 +1349,22 @@ export function AgentProvider({ config, children }) {
|
|
|
1186
1349
|
};
|
|
1187
1350
|
const approvalDecision = {
|
|
1188
1351
|
pending: pendingApproval,
|
|
1352
|
+
decidedElsewhere: pendingApproval && approvalDecidedElsewhere?.approvalId === pendingApproval.approvalId
|
|
1353
|
+
? { decision: approvalDecidedElsewhere.decision, channel: approvalDecidedElsewhere.channel }
|
|
1354
|
+
: null,
|
|
1189
1355
|
deciding: approvalDeciding,
|
|
1190
1356
|
error: approvalError,
|
|
1191
1357
|
decide: decideApproval,
|
|
1192
1358
|
dismiss: dismissApproval,
|
|
1193
1359
|
};
|
|
1194
|
-
|
|
1360
|
+
const internals = {
|
|
1361
|
+
config: () => configRef.current,
|
|
1362
|
+
socket: () => socketRef.current,
|
|
1363
|
+
connected,
|
|
1364
|
+
joinRoom,
|
|
1365
|
+
log: addDebugLog,
|
|
1366
|
+
};
|
|
1367
|
+
return React.createElement(AgentContext.Provider, { value: contextValue }, React.createElement(AgentInternalsContext.Provider, { value: internals }, React.createElement(ApprovalDecisionContext.Provider, { value: approvalDecision }, children)));
|
|
1195
1368
|
}
|
|
1196
1369
|
export function useAgent() {
|
|
1197
1370
|
const ctx = useContext(AgentContext);
|