@darqlabs/curator-sdk-react 0.6.1 → 0.8.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 +18 -0
- package/dist/cjs/CuratorAdapter.d.ts +37 -2
- package/dist/cjs/CuratorAdapter.d.ts.map +1 -1
- package/dist/cjs/CuratorAdapter.js +119 -20
- package/dist/cjs/CuratorAdapter.js.map +1 -1
- package/dist/cjs/CuratorChat.d.ts +8 -0
- package/dist/cjs/CuratorChat.d.ts.map +1 -1
- package/dist/cjs/CuratorChat.js +28 -8
- package/dist/cjs/CuratorChat.js.map +1 -1
- package/dist/cjs/historyMessages.d.ts +20 -1
- package/dist/cjs/historyMessages.d.ts.map +1 -1
- package/dist/cjs/historyMessages.js +25 -3
- package/dist/cjs/historyMessages.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/mcpApps/McpAppContext.d.ts +39 -0
- package/dist/cjs/mcpApps/McpAppContext.d.ts.map +1 -0
- package/dist/cjs/mcpApps/McpAppContext.js +19 -0
- package/dist/cjs/mcpApps/McpAppContext.js.map +1 -0
- package/dist/cjs/mcpApps/McpAppToolPart.d.ts +27 -0
- package/dist/cjs/mcpApps/McpAppToolPart.d.ts.map +1 -0
- package/dist/cjs/mcpApps/McpAppToolPart.js +275 -0
- package/dist/cjs/mcpApps/McpAppToolPart.js.map +1 -0
- package/dist/cjs/mcpApps/hostBridge.d.ts +127 -0
- package/dist/cjs/mcpApps/hostBridge.d.ts.map +1 -0
- package/dist/cjs/mcpApps/hostBridge.js +306 -0
- package/dist/cjs/mcpApps/hostBridge.js.map +1 -0
- package/dist/esm/CuratorAdapter.d.ts +37 -2
- package/dist/esm/CuratorAdapter.d.ts.map +1 -1
- package/dist/esm/CuratorAdapter.js +119 -20
- package/dist/esm/CuratorAdapter.js.map +1 -1
- package/dist/esm/CuratorChat.d.ts +8 -0
- package/dist/esm/CuratorChat.d.ts.map +1 -1
- package/dist/esm/CuratorChat.js +28 -8
- package/dist/esm/CuratorChat.js.map +1 -1
- package/dist/esm/historyMessages.d.ts +20 -1
- package/dist/esm/historyMessages.d.ts.map +1 -1
- package/dist/esm/historyMessages.js +25 -3
- package/dist/esm/historyMessages.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/mcpApps/McpAppContext.d.ts +39 -0
- package/dist/esm/mcpApps/McpAppContext.d.ts.map +1 -0
- package/dist/esm/mcpApps/McpAppContext.js +15 -0
- package/dist/esm/mcpApps/McpAppContext.js.map +1 -0
- package/dist/esm/mcpApps/McpAppToolPart.d.ts +27 -0
- package/dist/esm/mcpApps/McpAppToolPart.d.ts.map +1 -0
- package/dist/esm/mcpApps/McpAppToolPart.js +271 -0
- package/dist/esm/mcpApps/McpAppToolPart.js.map +1 -0
- package/dist/esm/mcpApps/hostBridge.d.ts +127 -0
- package/dist/esm/mcpApps/hostBridge.d.ts.map +1 -0
- package/dist/esm/mcpApps/hostBridge.js +300 -0
- package/dist/esm/mcpApps/hostBridge.js.map +1 -0
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -124,6 +124,24 @@ Non-planned agents never emit it, so adding the handler is always safe.
|
|
|
124
124
|
|
|
125
125
|
`onPlanProgress` is also available on `<CuratorChatLauncher />`.
|
|
126
126
|
|
|
127
|
+
### Interactive MCP Apps (`mcpApps`)
|
|
128
|
+
|
|
129
|
+
An MCP tool attached to the agent may ship its own view (the [MCP Apps](https://apps.extensions.modelcontextprotocol.io/) extension: a `ui://` HTML resource declared in the tool's `_meta`). When the deployment's admin has exposed that tool's call data, the agent's call renders as an interactive view inline in the transcript — a customer picker, a form, a map — sandboxed on a separate origin. Nothing to configure on your side; it is on by default.
|
|
130
|
+
|
|
131
|
+
```tsx
|
|
132
|
+
<CuratorChat
|
|
133
|
+
agent="booking-bot"
|
|
134
|
+
mcpApps={{
|
|
135
|
+
maxHeight: 520, // cap on a view's height (default 480)
|
|
136
|
+
onModelContextUpdate: (ctx) => log(ctx), // `ui/update-model-context` from a view, surfaced to you
|
|
137
|
+
}}
|
|
138
|
+
/>
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The widget declares `clientCapabilities: { mcpApps: true }` on every send (SDK ≥ 0.8.0); the server mints app sessions and steers the agent's prose around the view only for clients that declare it. Pass `mcpApps={{ enabled: false }}` to declare the opposite and show a static card instead of a view. Views render only while the widget is consuming a live streaming response; a conversation reloaded from history shows an "Interactive view expired" card where the view was. A turn a view sends on the person's behalf is labelled "via <tool>" in the transcript — it is app-reported, not typed.
|
|
142
|
+
|
|
143
|
+
Your page's Content-Security-Policy must allow `https://*.scf.auiusercontent.com` in `frame-src` for views to load.
|
|
144
|
+
|
|
127
145
|
### Message actions
|
|
128
146
|
|
|
129
147
|
| Prop | Default | Effect |
|
|
@@ -19,7 +19,33 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import type { CuratorAttachmentAdapter } from "./CuratorAttachmentAdapter.js";
|
|
21
21
|
import type { ChatModelAdapter } from "@assistant-ui/react";
|
|
22
|
-
import type { AssistantMessage, Chat, CuratorError, StreamState, StreamPlanProgress } from "@darqlabs/curator-sdk";
|
|
22
|
+
import type { AssistantMessage, Chat, CuratorError, McpCallToolResult, StreamState, StreamPlanProgress } from "@darqlabs/curator-sdk";
|
|
23
|
+
/**
|
|
24
|
+
* A tool-call part as assistant-ui renders it. `mcp.app.serverId` carries the
|
|
25
|
+
* Curator APP SESSION, not a server id: it is the opaque routing key the view
|
|
26
|
+
* renderer threads through every data-plane call, and a session is exactly
|
|
27
|
+
* "which server, which tool call, for whom".
|
|
28
|
+
*/
|
|
29
|
+
/** JSON as assistant-ui types a tool call's arguments. Stream arguments ARE JSON (they were parsed from it). */
|
|
30
|
+
export type JsonValue = string | number | boolean | null | readonly JsonValue[] | JsonObject;
|
|
31
|
+
export type JsonObject = {
|
|
32
|
+
readonly [k: string]: JsonValue;
|
|
33
|
+
};
|
|
34
|
+
export interface McpAppToolCallPart {
|
|
35
|
+
type: "tool-call";
|
|
36
|
+
toolCallId: string;
|
|
37
|
+
toolName: string;
|
|
38
|
+
args: JsonObject;
|
|
39
|
+
argsText: string;
|
|
40
|
+
result?: McpCallToolResult;
|
|
41
|
+
isError?: boolean;
|
|
42
|
+
mcp: {
|
|
43
|
+
app: {
|
|
44
|
+
resourceUri: string;
|
|
45
|
+
serverId: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
}
|
|
23
49
|
export interface CuratorAdapterCallbacks {
|
|
24
50
|
/** Fired once per successfully-returned assistant message. */
|
|
25
51
|
onMessage?: (message: AssistantMessage) => void;
|
|
@@ -40,11 +66,20 @@ export interface CuratorAdapterCallbacks {
|
|
|
40
66
|
/** Fired on any send-time error surfaced through the stream. */
|
|
41
67
|
onError?: (error: CuratorError | Error) => void;
|
|
42
68
|
}
|
|
69
|
+
export interface CuratorAdapterOptions {
|
|
70
|
+
/**
|
|
71
|
+
* Declare to the server that this client renders MCP App views. Default
|
|
72
|
+
* true — the widget does. When false (the host passed
|
|
73
|
+
* `mcpApps={{ enabled: false }}`), the server mints no app session, sends
|
|
74
|
+
* plain tool-call frames, and does not tell the agent a view is showing.
|
|
75
|
+
*/
|
|
76
|
+
rendersMcpApps?: boolean;
|
|
77
|
+
}
|
|
43
78
|
export declare function createCuratorAdapter(chat: Chat, callbacks?: CuratorAdapterCallbacks,
|
|
44
79
|
/**
|
|
45
80
|
* Supplies the storage references for this turn's attachments. Absent when
|
|
46
81
|
* the widget was mounted without attachment support, in which case the send
|
|
47
82
|
* behaves exactly as before.
|
|
48
83
|
*/
|
|
49
|
-
attachments?: Pick<CuratorAttachmentAdapter, "takeReferences"
|
|
84
|
+
attachments?: Pick<CuratorAttachmentAdapter, "takeReferences">, options?: CuratorAdapterOptions): ChatModelAdapter;
|
|
50
85
|
//# sourceMappingURL=CuratorAdapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CuratorAdapter.d.ts","sourceRoot":"","sources":["../../src/CuratorAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAA;AAC7E,OAAO,KAAK,EAAE,gBAAgB,EAAsB,MAAM,qBAAqB,CAAA;AAC/E,OAAO,KAAK,EACV,gBAAgB,EAChB,IAAI,EACJ,YAAY,EACZ,WAAW,EACX,kBAAkB,EACnB,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"CuratorAdapter.d.ts","sourceRoot":"","sources":["../../src/CuratorAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAA;AAC7E,OAAO,KAAK,EAAE,gBAAgB,EAAsB,MAAM,qBAAqB,CAAA;AAC/E,OAAO,KAAK,EACV,gBAAgB,EAChB,IAAI,EACJ,YAAY,EACZ,iBAAiB,EACjB,WAAW,EACX,kBAAkB,EACnB,MAAM,uBAAuB,CAAA;AAG9B;;;;;GAKG;AACH,gHAAgH;AAChH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,SAAS,EAAE,GAAG,UAAU,CAAA;AAC5F,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAA;AAE5D,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,WAAW,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,UAAU,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,iBAAiB,CAAA;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,GAAG,EAAE;QAAE,GAAG,EAAE;YAAE,WAAW,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAA;CACxD;AAKD,MAAM,WAAW,uBAAuB;IACtC,8DAA8D;IAC9D,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,IAAI,CAAA;IAC/C;;;;;OAKG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAA;IACtC;;;;;OAKG;IACH,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,kBAAkB,KAAK,IAAI,CAAA;IACvD,gEAAgE;IAChE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,GAAG,KAAK,KAAK,IAAI,CAAA;CAChD;AAED,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,IAAI,EACV,SAAS,GAAE,uBAA4B;AACvC;;;;GAIG;AACH,WAAW,CAAC,EAAE,IAAI,CAAC,wBAAwB,EAAE,gBAAgB,CAAC,EAC9D,OAAO,GAAE,qBAA0B,GAClC,gBAAgB,CA8PlB"}
|
|
@@ -20,19 +20,29 @@
|
|
|
20
20
|
*/
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
22
|
exports.createCuratorAdapter = createCuratorAdapter;
|
|
23
|
+
const McpAppContext_js_1 = require("./mcpApps/McpAppContext.js");
|
|
23
24
|
function createCuratorAdapter(chat, callbacks = {},
|
|
24
25
|
/**
|
|
25
26
|
* Supplies the storage references for this turn's attachments. Absent when
|
|
26
27
|
* the widget was mounted without attachment support, in which case the send
|
|
27
28
|
* behaves exactly as before.
|
|
28
29
|
*/
|
|
29
|
-
attachments) {
|
|
30
|
+
attachments, options = {}) {
|
|
31
|
+
// Declared on every send, never inferred server-side: this is how the
|
|
32
|
+
// server tells the browser widget apart from a customer's own caller on the
|
|
33
|
+
// same API key.
|
|
34
|
+
const clientCapabilities = { mcpApps: options.rendersMcpApps !== false };
|
|
30
35
|
return {
|
|
31
36
|
async *run({ messages, abortSignal }) {
|
|
32
37
|
const userText = extractLatestUserText(messages);
|
|
33
38
|
const files = attachments
|
|
34
39
|
? attachments.takeReferences(latestUserAttachmentIds(messages))
|
|
35
40
|
: [];
|
|
41
|
+
// MCP Apps: a turn a rendered VIEW sent (`ui/message`). The session it was
|
|
42
|
+
// rendered under rides on the message metadata and goes to the server as
|
|
43
|
+
// `app_session`, which validates it and stores the row with a `source`
|
|
44
|
+
// marker — the record says a view sent it, never that a person typed it.
|
|
45
|
+
const appSession = latestUserAppSession(messages);
|
|
36
46
|
// A file with no caption is a complete message — the SDK accepts content
|
|
37
47
|
// OR files, and a bill of lading dropped in with nothing typed is the
|
|
38
48
|
// single most common way this widget is used. Returning early on empty
|
|
@@ -49,16 +59,41 @@ attachments) {
|
|
|
49
59
|
// then `done` (whose message is the terminal reply ALONE) replaced the
|
|
50
60
|
// whole thing — so the user watched a paragraph appear and then get
|
|
51
61
|
// overwritten by different text. Segments keep every token the user saw.
|
|
52
|
-
|
|
62
|
+
// Ordered list of settled parts — text segments and MCP App tool-call
|
|
63
|
+
// parts interleaved in arrival order — plus the in-flight text.
|
|
64
|
+
const settled = [];
|
|
65
|
+
/** Live tool-call parts by id, so completed/failed can update in place. */
|
|
66
|
+
const appParts = new Map();
|
|
53
67
|
let acc = "";
|
|
54
|
-
/**
|
|
68
|
+
/** Settled parts plus the in-flight text, as assistant-ui parts. */
|
|
55
69
|
const partsWith = (trailing) => {
|
|
56
|
-
const
|
|
70
|
+
const out = [...settled];
|
|
71
|
+
if (trailing.length > 0)
|
|
72
|
+
out.push({ type: "text", text: trailing });
|
|
57
73
|
// assistant-ui expects at least one part; an empty run yields empty text.
|
|
58
|
-
return
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
74
|
+
return out.length > 0 ? out : [{ type: "text", text: "" }];
|
|
75
|
+
};
|
|
76
|
+
/** Settle the in-flight text as its own segment, if there is any. */
|
|
77
|
+
const settleText = () => {
|
|
78
|
+
if (acc.trim().length > 0)
|
|
79
|
+
settled.push({ type: "text", text: acc });
|
|
80
|
+
acc = "";
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* A view whose call never got a terminal event would spin forever. Give
|
|
84
|
+
* every unresolved app part a valid error result so the frame receives a
|
|
85
|
+
* terminal tool-result.
|
|
86
|
+
*/
|
|
87
|
+
const interruptUnresolvedApps = (text) => {
|
|
88
|
+
for (const [id, p] of appParts) {
|
|
89
|
+
if (p.result !== undefined)
|
|
90
|
+
continue;
|
|
91
|
+
const updated = { ...p, isError: true, result: { isError: true, content: [{ type: "text", text }] } };
|
|
92
|
+
appParts.set(id, updated);
|
|
93
|
+
const idx = settled.indexOf(p);
|
|
94
|
+
if (idx >= 0)
|
|
95
|
+
settled[idx] = updated;
|
|
96
|
+
}
|
|
62
97
|
};
|
|
63
98
|
try {
|
|
64
99
|
// The options object is now always passed, including when there are no
|
|
@@ -73,9 +108,12 @@ attachments) {
|
|
|
73
108
|
// the local stream and left the agent running to completion — burning
|
|
74
109
|
// tokens for a reply nobody would ever see. Checking an abort is not
|
|
75
110
|
// the same as acting on it.
|
|
76
|
-
const stream =
|
|
77
|
-
?
|
|
78
|
-
|
|
111
|
+
const stream = chat.stream(userText, {
|
|
112
|
+
...(files.length ? { files } : {}),
|
|
113
|
+
...(appSession ? { appSession } : {}),
|
|
114
|
+
clientCapabilities,
|
|
115
|
+
signal: abortSignal,
|
|
116
|
+
});
|
|
79
117
|
for await (const event of stream) {
|
|
80
118
|
if (abortSignal.aborted)
|
|
81
119
|
return;
|
|
@@ -92,14 +130,58 @@ attachments) {
|
|
|
92
130
|
// Turn boundary: anything streamed before this belongs to the turn
|
|
93
131
|
// that decided to call a tool. Settle it so the next turn's tokens
|
|
94
132
|
// start a new part instead of extending someone else's sentence.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
133
|
+
// (Whitespace-only narration is dropped by settleText.)
|
|
134
|
+
const hadText = acc.trim().length > 0;
|
|
135
|
+
settleText();
|
|
136
|
+
// MCP Apps: a call that renders a view becomes a tool-call part.
|
|
137
|
+
// Only when the server minted a session for it — a plain tool call
|
|
138
|
+
// stays what it always was, a boundary and nothing rendered.
|
|
139
|
+
if (event.app) {
|
|
140
|
+
const partForApp = {
|
|
141
|
+
type: "tool-call",
|
|
142
|
+
toolCallId: event.toolCallId,
|
|
143
|
+
toolName: event.toolName,
|
|
144
|
+
args: (event.arguments ?? {}),
|
|
145
|
+
argsText: JSON.stringify(event.arguments ?? {}),
|
|
146
|
+
mcp: { app: { resourceUri: event.app.resourceUri, serverId: event.app.session } },
|
|
147
|
+
};
|
|
148
|
+
appParts.set(event.toolCallId, partForApp);
|
|
149
|
+
settled.push(partForApp);
|
|
98
150
|
yield { content: partsWith(acc) };
|
|
99
151
|
}
|
|
100
|
-
else {
|
|
101
|
-
|
|
102
|
-
|
|
152
|
+
else if (hadText) {
|
|
153
|
+
yield { content: partsWith(acc) };
|
|
154
|
+
}
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (event.type === "tool_call.completed" || event.type === "tool_call.failed") {
|
|
158
|
+
// Only MCP App parts exist to update; every other tool call was a
|
|
159
|
+
// boundary. Idempotent: a duplicate terminal event for the same id
|
|
160
|
+
// is a no-op once the result is set.
|
|
161
|
+
const existing = appParts.get(event.toolCallId);
|
|
162
|
+
if (existing && existing.result === undefined) {
|
|
163
|
+
const idx = settled.indexOf(existing);
|
|
164
|
+
const updated = event.type === "tool_call.completed"
|
|
165
|
+
? { ...existing, result: event.result ?? { content: [] }, isError: event.result?.isError === true }
|
|
166
|
+
: {
|
|
167
|
+
...existing,
|
|
168
|
+
isError: true,
|
|
169
|
+
result: event.result ?? {
|
|
170
|
+
isError: true,
|
|
171
|
+
content: [
|
|
172
|
+
{
|
|
173
|
+
type: "text",
|
|
174
|
+
text: event.reason === "policy_denied"
|
|
175
|
+
? "This action was not allowed."
|
|
176
|
+
: "The tool could not complete.",
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
appParts.set(event.toolCallId, updated);
|
|
182
|
+
if (idx >= 0)
|
|
183
|
+
settled[idx] = updated;
|
|
184
|
+
yield { content: partsWith(acc) };
|
|
103
185
|
}
|
|
104
186
|
continue;
|
|
105
187
|
}
|
|
@@ -117,6 +199,7 @@ attachments) {
|
|
|
117
199
|
// `done` carries the TERMINAL reply only, so it replaces the
|
|
118
200
|
// in-flight segment — never the settled ones.
|
|
119
201
|
const finalText = event.message?.content ?? acc;
|
|
202
|
+
interruptUnresolvedApps("The turn ended before this view received a result.");
|
|
120
203
|
yield {
|
|
121
204
|
content: partsWith(finalText),
|
|
122
205
|
status: { type: "complete", reason: "stop" },
|
|
@@ -126,8 +209,9 @@ attachments) {
|
|
|
126
209
|
return;
|
|
127
210
|
}
|
|
128
211
|
if (event.type === "error") {
|
|
212
|
+
interruptUnresolvedApps("The agent failed before this view received a result.");
|
|
129
213
|
yield {
|
|
130
|
-
content: [{ type: "text", text: event.message }],
|
|
214
|
+
content: [...settled.filter((p) => p.type === "tool-call"), { type: "text", text: event.message }],
|
|
131
215
|
status: { type: "incomplete", reason: "error" },
|
|
132
216
|
};
|
|
133
217
|
callbacks.onError?.(new Error(event.message));
|
|
@@ -170,10 +254,11 @@ attachments) {
|
|
|
170
254
|
//
|
|
171
255
|
// Anything already streamed is kept — partial text the user watched
|
|
172
256
|
// arrive is real — and the status marks the turn incomplete.
|
|
173
|
-
const
|
|
257
|
+
const hadAnything = settled.some((p) => p.type === "text") || acc.length > 0;
|
|
174
258
|
const truncatedNotice = "The connection to the agent ended unexpectedly. Please try again.";
|
|
259
|
+
interruptUnresolvedApps("The stream was interrupted before this view received a result.");
|
|
175
260
|
yield {
|
|
176
|
-
content: partsWith(
|
|
261
|
+
content: partsWith(hadAnything ? acc : truncatedNotice),
|
|
177
262
|
status: { type: "incomplete", reason: "error" },
|
|
178
263
|
};
|
|
179
264
|
callbacks.onError?.(new Error("Stream ended without a terminal event"));
|
|
@@ -206,6 +291,20 @@ function latestUserAttachmentIds(messages) {
|
|
|
206
291
|
}
|
|
207
292
|
return [];
|
|
208
293
|
}
|
|
294
|
+
/**
|
|
295
|
+
* The app session on the latest user turn, when a rendered view sent it.
|
|
296
|
+
* Stamped by `McpAppToolPart` on `metadata.custom`; absent for typed turns.
|
|
297
|
+
*/
|
|
298
|
+
function latestUserAppSession(messages) {
|
|
299
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
300
|
+
const m = messages[i];
|
|
301
|
+
if (m.role !== "user")
|
|
302
|
+
continue;
|
|
303
|
+
const v = m.metadata?.custom?.[McpAppContext_js_1.APP_SESSION_METADATA_KEY];
|
|
304
|
+
return typeof v === "string" && v ? v : undefined;
|
|
305
|
+
}
|
|
306
|
+
return undefined;
|
|
307
|
+
}
|
|
209
308
|
/**
|
|
210
309
|
* Pull the latest user-turn text out of assistant-ui's structured
|
|
211
310
|
* message array. Text parts are concatenated with newlines; other
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CuratorAdapter.js","sourceRoot":"","sources":["../../src/CuratorAdapter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;
|
|
1
|
+
{"version":3,"file":"CuratorAdapter.js","sourceRoot":"","sources":["../../src/CuratorAdapter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;AAqEH,oDAwQC;AAjUD,iEAAqE;AAyDrE,SAAgB,oBAAoB,CAClC,IAAU,EACV,YAAqC,EAAE;AACvC;;;;GAIG;AACH,WAA8D,EAC9D,UAAiC,EAAE;IAEnC,sEAAsE;IACtE,4EAA4E;IAC5E,gBAAgB;IAChB,MAAM,kBAAkB,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,cA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C;AAED;;;;;GAKG;AACH,SAAS,qBAAqB,CAAC,QAAkE;IAC/F,KAAK,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9C,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;QACrB,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM;YAAE,SAAQ;QAC/B,MAAM,IAAI,GAAG,CAAC,CAAC,OAAO;aACnB,MAAM,CAAC,CAAC,CAAC,EAAuC,EAAE,CACjD,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAK,CAAuB,CAAC,IAAI,KAAK,MAAM,CAChF;aACA,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;aAClB,IAAI,CAAC,IAAI,CAAC,CAAA;QACb,OAAO,IAAI,CAAC,IAAI,EAAE,CAAA;IACpB,CAAC;IACD,OAAO,EAAE,CAAA;AACX,CAAC"}
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { type CSSProperties, type ReactNode } from "react";
|
|
13
13
|
import type { AssistantMessage, Curator, CuratorError, Environment, StreamState, StreamPlanProgress } from "@darqlabs/curator-sdk";
|
|
14
|
+
import { type McpAppsOptions } from "./mcpApps/McpAppContext.js";
|
|
14
15
|
/**
|
|
15
16
|
* A starter prompt offered in the empty thread.
|
|
16
17
|
*
|
|
@@ -103,6 +104,13 @@ export interface CuratorChatProps {
|
|
|
103
104
|
onPlanProgress?: (progress: StreamPlanProgress) => void;
|
|
104
105
|
/** Fired on any terminal stream error or thrown exception. */
|
|
105
106
|
onError?: (error: CuratorError | Error) => void;
|
|
107
|
+
/**
|
|
108
|
+
* MCP Apps (SEP-1865). When an attached MCP tool declares a `ui://` view AND
|
|
109
|
+
* the deployment's admin exposed its call data, the agent's call renders as
|
|
110
|
+
* an interactive view inline in the transcript, sandboxed on a separate
|
|
111
|
+
* origin. Default: enabled. See `McpAppsOptions`.
|
|
112
|
+
*/
|
|
113
|
+
mcpApps?: McpAppsOptions;
|
|
106
114
|
/**
|
|
107
115
|
* Show a retry (↻) button under the latest assistant message. Default:
|
|
108
116
|
* off. Retry re-sends the preceding user message through the SDK — note
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CuratorChat.d.ts","sourceRoot":"","sources":["../../src/CuratorChat.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAgF,KAAK,aAAa,EAAsB,KAAK,SAAS,EAAmB,MAAM,OAAO,CAAA;AAW7K,OAAO,KAAK,EACV,gBAAgB,EAEhB,OAAO,EACP,YAAY,EACZ,WAAW,EACX,WAAW,EACX,kBAAkB,EACnB,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"CuratorChat.d.ts","sourceRoot":"","sources":["../../src/CuratorChat.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAgF,KAAK,aAAa,EAAsB,KAAK,SAAS,EAAmB,MAAM,OAAO,CAAA;AAW7K,OAAO,KAAK,EACV,gBAAgB,EAEhB,OAAO,EACP,YAAY,EACZ,WAAW,EACX,WAAW,EACX,kBAAkB,EACnB,MAAM,uBAAuB,CAAA;AAQ9B,OAAO,EAAkE,KAAK,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAGhI;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,GACrB,MAAM,GACN;IACE,mBAAmB;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAEL,MAAM,WAAW,gBAAgB;IAC/B,oEAAoE;IACpE,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,oCAAoC;IACpC,KAAK,EAAE,MAAM,CAAA;IACb,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAA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CAAC,EAAE,OAAO,CAAA;IACxB;;;;;;;;;;;OAWG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B;;;;;;;OAOG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,EAAE,aAAa,EAAE,CAAA;IACzB;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,aAAa,CAAA;IACtB,8EAA8E;IAC9E,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,+BAsQlD;AAuND,iBAAS,gBAAgB,gCAqDxB;AAiaD;;;;;;;;;GASG;AACH,QAAA,MAAM,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAkCtC,CAAA;AAED,sEAAsE;AACtE,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,OAAO,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAA"}
|
package/dist/cjs/CuratorChat.js
CHANGED
|
@@ -22,8 +22,10 @@ const Markdown_js_1 = require("./Markdown.js");
|
|
|
22
22
|
const attachmentEnvelope_js_1 = require("./attachmentEnvelope.js");
|
|
23
23
|
const CuratorAttachmentAdapter_js_1 = require("./CuratorAttachmentAdapter.js");
|
|
24
24
|
const historyMessages_js_1 = require("./historyMessages.js");
|
|
25
|
+
const McpAppContext_js_1 = require("./mcpApps/McpAppContext.js");
|
|
26
|
+
const McpAppToolPart_js_1 = require("./mcpApps/McpAppToolPart.js");
|
|
25
27
|
function CuratorChat(props) {
|
|
26
|
-
const { curator, agent, project, environment, system, conversationId, title = "Chat", placeholder = "Type a message…", welcomeMessage, theme = "light", className, style, onClose, loadingIndicator, onMessage, onState, onPlanProgress, onError, enableRetry = false, enableCopy = false, showTimestamps = true, enableAttachments = false, hideHeader = false, historyLimit = 50, prompts, tokens, acceptedFileTypes, maxFileSize, queueWhileRunning = true, } = props;
|
|
28
|
+
const { curator, agent, project, environment, system, conversationId, title = "Chat", placeholder = "Type a message…", welcomeMessage, theme = "light", className, style, onClose, loadingIndicator, onMessage, onState, onPlanProgress, onError, mcpApps, enableRetry = false, enableCopy = false, showTimestamps = true, enableAttachments = false, hideHeader = false, historyLimit = 50, prompts, tokens, acceptedFileTypes, maxFileSize, queueWhileRunning = true, } = props;
|
|
27
29
|
const contextClient = (0, CuratorProvider_js_1.useCuratorOrNull)();
|
|
28
30
|
const client = curator ?? contextClient;
|
|
29
31
|
if (!client) {
|
|
@@ -78,8 +80,12 @@ function CuratorChat(props) {
|
|
|
78
80
|
onState: (state) => callbacksRef.current.onState?.(state),
|
|
79
81
|
onPlanProgress: (progress) => callbacksRef.current.onPlanProgress?.(progress),
|
|
80
82
|
onError: (error) => callbacksRef.current.onError?.(error),
|
|
81
|
-
}, attachmentAdapter), [chat, attachmentAdapter]);
|
|
83
|
+
}, attachmentAdapter, { rendersMcpApps: mcpApps?.enabled !== false }), [chat, attachmentAdapter, mcpApps?.enabled]);
|
|
82
84
|
const runtime = (0, react_2.useLocalRuntime)(adapter, attachmentAdapter ? { adapters: { attachments: attachmentAdapter } } : undefined);
|
|
85
|
+
// MCP Apps: what a rendered view needs from the widget. The data plane is
|
|
86
|
+
// the same Chat handle the adapter streams on, so a view's calls carry the
|
|
87
|
+
// same API key / end-user identity as the person's own messages.
|
|
88
|
+
const mcpAppContextValue = (0, react_1.useMemo)(() => ({ chat, theme, options: mcpApps ?? {} }), [chat, theme, mcpApps]);
|
|
83
89
|
// Branding is a server-resolved entitlement (org subscription tier), not a
|
|
84
90
|
// client prop — the widget runs on the customer's own page, so a local
|
|
85
91
|
// boolean would be trivially flippable. We fetch the deployment config on
|
|
@@ -172,10 +178,10 @@ function CuratorChat(props) {
|
|
|
172
178
|
...containerStyle,
|
|
173
179
|
...style,
|
|
174
180
|
};
|
|
175
|
-
return ((0, jsx_runtime_1.jsxs)("div", { ref: hostRef, className: className, style: wrapperStyle, "data-curator-chat": true, "data-theme": theme, children: [!hideHeader && (0, jsx_runtime_1.jsx)(Header, { title: title, onClose: onClose }), (0, jsx_runtime_1.jsx)(LoadingIndicatorContext.Provider, { value: loadingIndicator ?? (0, jsx_runtime_1.jsx)(TypingDots, {}), children: (0, jsx_runtime_1.jsx)(RetryEnabledContext.Provider, { value: enableRetry, children: (0, jsx_runtime_1.jsx)(CopyEnabledContext.Provider, { value: enableCopy, children: (0, jsx_runtime_1.jsx)(TimestampsEnabledContext.Provider, { value: showTimestamps, children: (0, jsx_runtime_1.jsx)(react_2.AssistantRuntimeProvider, { runtime: runtime, children: (0, jsx_runtime_1.jsxs)(react_2.ThreadPrimitive.Root, { "data-curator-part": "thread", style: threadRootStyle, children: [(0, jsx_runtime_1.jsxs)(react_2.ThreadPrimitive.Viewport, { autoScroll: true, "data-curator-part": "viewport", style: viewportStyle, children: [(0, jsx_runtime_1.jsx)(react_2.ThreadPrimitive.Empty, { children: !historyLoading && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [welcomeMessage ? (0, jsx_runtime_1.jsx)(Welcome, { text: welcomeMessage }) : null, prompts && prompts.length > 0 && (0, jsx_runtime_1.jsx)(Prompts, { prompts: prompts })] })) }), (0, jsx_runtime_1.jsx)(react_2.ThreadPrimitive.Messages, { components: {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
181
|
+
return ((0, jsx_runtime_1.jsxs)("div", { ref: hostRef, className: className, style: wrapperStyle, "data-curator-chat": true, "data-theme": theme, children: [!hideHeader && (0, jsx_runtime_1.jsx)(Header, { title: title, onClose: onClose }), (0, jsx_runtime_1.jsx)(LoadingIndicatorContext.Provider, { value: loadingIndicator ?? (0, jsx_runtime_1.jsx)(TypingDots, {}), children: (0, jsx_runtime_1.jsx)(RetryEnabledContext.Provider, { value: enableRetry, children: (0, jsx_runtime_1.jsx)(CopyEnabledContext.Provider, { value: enableCopy, children: (0, jsx_runtime_1.jsx)(TimestampsEnabledContext.Provider, { value: showTimestamps, children: (0, jsx_runtime_1.jsx)(react_2.AssistantRuntimeProvider, { runtime: runtime, children: (0, jsx_runtime_1.jsx)(McpAppContext_js_1.McpAppContext.Provider, { value: mcpAppContextValue, children: (0, jsx_runtime_1.jsxs)(react_2.ThreadPrimitive.Root, { "data-curator-part": "thread", style: threadRootStyle, children: [(0, jsx_runtime_1.jsxs)(react_2.ThreadPrimitive.Viewport, { autoScroll: true, "data-curator-part": "viewport", style: viewportStyle, children: [(0, jsx_runtime_1.jsx)(react_2.ThreadPrimitive.Empty, { children: !historyLoading && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [welcomeMessage ? (0, jsx_runtime_1.jsx)(Welcome, { text: welcomeMessage }) : null, prompts && prompts.length > 0 && (0, jsx_runtime_1.jsx)(Prompts, { prompts: prompts })] })) }), (0, jsx_runtime_1.jsx)(react_2.ThreadPrimitive.Messages, { components: {
|
|
182
|
+
UserMessage,
|
|
183
|
+
AssistantMessage,
|
|
184
|
+
} })] }), (0, jsx_runtime_1.jsx)(Composer, { placeholder: placeholder, allowQueue: queueWhileRunning, allowAttachments: !!attachmentAdapter })] }) }) }) }) }) }) }), hidePoweredBy === false && (0, jsx_runtime_1.jsx)(brand_js_1.PoweredByCurator, {})] }));
|
|
179
185
|
}
|
|
180
186
|
// Context for threading the loading indicator into the message-component
|
|
181
187
|
// callbacks without remounting them on every render. Default is rendered
|
|
@@ -227,11 +233,19 @@ function UserMessage() {
|
|
|
227
233
|
// `UserTextPart` is the fallback for transcripts written before the server
|
|
228
234
|
// stored them as a field; both render the same chip.
|
|
229
235
|
const attachments = (0, react_2.useAuiState)((s) => s.message?.attachments) ?? [];
|
|
236
|
+
// MCP Apps: a turn a rendered view sent on the person's behalf. Labelled so
|
|
237
|
+
// the transcript never presents app-reported text as something typed.
|
|
238
|
+
const viaApp = (0, react_2.useAuiState)((s) => {
|
|
239
|
+
const custom = s.message?.metadata?.custom;
|
|
240
|
+
const session = custom?.[McpAppContext_js_1.APP_SESSION_METADATA_KEY];
|
|
241
|
+
const tool = custom?.[McpAppContext_js_1.APP_TOOL_METADATA_KEY];
|
|
242
|
+
return typeof session === "string" && session ? (typeof tool === "string" ? tool : "app") : null;
|
|
243
|
+
});
|
|
230
244
|
const hasText = (0, react_2.useAuiState)((s) => s.message?.content?.some((p) => p.type === "text" && p.text.length > 0) ?? false);
|
|
231
245
|
return ((0, jsx_runtime_1.jsxs)(react_2.MessagePrimitive.Root, { "data-curator-part": "message message-user", style: rowEndStyle, children: [(0, jsx_runtime_1.jsxs)("div", { "data-curator-part": "bubble bubble-user", style: { ...bubbleBaseStyle, ...userBubbleStyle }, children: [attachments.map((a, i) => ((0, jsx_runtime_1.jsx)(SentAttachmentChip, { name: a.name,
|
|
232
246
|
// A file sent with no caption is the common case; the chip is then
|
|
233
247
|
// the whole bubble and must not carry a top margin.
|
|
234
|
-
first: i === 0 && !hasText }, a.id))), (0, jsx_runtime_1.jsx)(react_2.MessagePrimitive.Parts, { components: { Text: UserTextPart } })] }), (0, jsx_runtime_1.jsx)(Timestamp, { align: "end" })] }));
|
|
248
|
+
first: i === 0 && !hasText }, a.id))), (0, jsx_runtime_1.jsx)(react_2.MessagePrimitive.Parts, { components: { Text: UserTextPart } }), viaApp && ((0, jsx_runtime_1.jsxs)("span", { "data-curator-part": "via-app", style: viaAppStyle, title: "Sent by an interactive view, not typed", children: ["via ", (0, McpAppToolPart_js_1.humanizeToolName)(viaApp)] }))] }), (0, jsx_runtime_1.jsx)(Timestamp, { align: "end" })] }));
|
|
235
249
|
}
|
|
236
250
|
/** One attachment on a sent message. Shared by the structural and envelope paths. */
|
|
237
251
|
function SentAttachmentChip({ name, size, mimeType, first, }) {
|
|
@@ -274,7 +288,7 @@ function AssistantMessage() {
|
|
|
274
288
|
const indicator = (0, react_1.useContext)(LoadingIndicatorContext);
|
|
275
289
|
const retryEnabled = (0, react_1.useContext)(RetryEnabledContext);
|
|
276
290
|
const copyEnabled = (0, react_1.useContext)(CopyEnabledContext);
|
|
277
|
-
return ((0, jsx_runtime_1.jsxs)(react_2.MessagePrimitive.Root, { "data-curator-part": "message message-assistant", style: rowStartStyle, children: [(0, jsx_runtime_1.jsxs)("div", { "data-curator-part": "bubble bubble-assistant", style: { ...bubbleBaseStyle, ...assistantBubbleStyle }, children: [(0, jsx_runtime_1.jsx)(react_2.MessagePrimitive.If, { hasContent: false, children: indicator }), (0, jsx_runtime_1.jsx)(react_2.MessagePrimitive.Parts, { components: { Text: AssistantTextPart } })] }), (0, jsx_runtime_1.jsxs)("div", { "data-curator-part": "message-meta", style: messageMetaStyle, children: [(0, jsx_runtime_1.jsx)(Timestamp, { align: "start" }), (retryEnabled || copyEnabled) && (
|
|
291
|
+
return ((0, jsx_runtime_1.jsxs)(react_2.MessagePrimitive.Root, { "data-curator-part": "message message-assistant", style: rowStartStyle, children: [(0, jsx_runtime_1.jsxs)("div", { "data-curator-part": "bubble bubble-assistant", style: { ...bubbleBaseStyle, ...assistantBubbleStyle }, children: [(0, jsx_runtime_1.jsx)(react_2.MessagePrimitive.If, { hasContent: false, children: indicator }), (0, jsx_runtime_1.jsx)(react_2.MessagePrimitive.Parts, { components: { Text: AssistantTextPart, tools: { Fallback: McpAppToolPart_js_1.McpAppToolPart } } })] }), (0, jsx_runtime_1.jsxs)("div", { "data-curator-part": "message-meta", style: messageMetaStyle, children: [(0, jsx_runtime_1.jsx)(Timestamp, { align: "start" }), (retryEnabled || copyEnabled) && (
|
|
278
292
|
// `hideWhenRunning` still applies: actions on a half-written reply
|
|
279
293
|
// would copy a fragment.
|
|
280
294
|
(0, jsx_runtime_1.jsxs)(react_2.ActionBarPrimitive.Root, { hideWhenRunning: true, "data-curator-part": "action-bar", style: actionBarStyle, children: [copyEnabled && ((0, jsx_runtime_1.jsxs)(react_2.ActionBarPrimitive.Copy, { "aria-label": "Copy", "data-curator-part": "action-button", style: actionButtonStyle, children: [(0, jsx_runtime_1.jsx)(react_2.MessagePrimitive.If, { copied: true, children: (0, jsx_runtime_1.jsx)(CheckGlyph, {}) }), (0, jsx_runtime_1.jsx)(react_2.MessagePrimitive.If, { copied: false, children: (0, jsx_runtime_1.jsx)(CopyGlyph, {}) })] })), retryEnabled && ((0, jsx_runtime_1.jsx)(react_2.ActionBarPrimitive.Reload, { "aria-label": "Retry", "data-curator-part": "action-button", style: actionButtonStyle, children: (0, jsx_runtime_1.jsx)(RetryGlyph, {}) }))] }))] })] }));
|
|
@@ -775,6 +789,12 @@ const actionButtonStyle = {
|
|
|
775
789
|
cursor: "pointer",
|
|
776
790
|
transition: "color 120ms ease, background 120ms ease",
|
|
777
791
|
};
|
|
792
|
+
const viaAppStyle = {
|
|
793
|
+
display: "block",
|
|
794
|
+
marginTop: 4,
|
|
795
|
+
fontSize: 11,
|
|
796
|
+
opacity: 0.7,
|
|
797
|
+
};
|
|
778
798
|
const bubbleBaseStyle = {
|
|
779
799
|
// Two caps, both needed. The percentage keeps the bubble proportional in a
|
|
780
800
|
// narrow widget; the absolute stops a bubble spanning a 2000px-wide desktop
|