@teaflask/assistant 0.10.3 → 0.11.1
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/dist/appearance/theme.d.ts +21 -18
- package/dist/components/composer-banner.js +38 -3
- package/dist/components/composer-chip-shelf.js +136 -0
- package/dist/components/composer.js +2 -2
- package/dist/components/connector-add-flow.js +173 -0
- package/dist/components/connector-reconnect-notice.js +66 -0
- package/dist/components/connector-sign-in-flow.js +331 -0
- package/dist/components/connector-sign-in.js +103 -0
- package/dist/components/connectors-chip.js +78 -0
- package/dist/components/connectors-menu.js +186 -0
- package/dist/components/conversation-view.js +2 -2
- package/dist/components/icons.js +3 -0
- package/dist/components/model-picker-chip.js +10 -84
- package/dist/components/primitives/button.js +3 -0
- package/dist/components/primitives/disclosure.js +2 -1
- package/dist/components/primitives/text-input.js +6 -0
- package/dist/components/provider-chip.js +11 -63
- package/dist/components/subscription-plan-notice.js +9 -6
- package/dist/components/teaflask-assistant-provider.d.ts +14 -0
- package/dist/components/teaflask-assistant-provider.js +17 -0
- package/dist/components/use-store-cell.d.ts +2 -1
- package/dist/components/use-store-cell.js +5 -0
- package/dist/contract/mcp-servers.d.ts +10 -0
- package/dist/contract/mcp-servers.js +28 -0
- package/dist/core/assistant-session-registry.d.ts +65 -0
- package/dist/core/assistant-session-registry.js +66 -2
- package/dist/generated/models/addPersonMcpServerRequest.d.ts +9 -0
- package/dist/generated/models/addPersonMcpServerRequest.js +1 -0
- package/dist/generated/models/apiErrorCode.d.ts +17 -0
- package/dist/generated/models/apiErrorCode.js +17 -0
- package/dist/generated/models/assistantConfigResponse.d.ts +2 -0
- package/dist/generated/models/beginPersonMcpServerSignInRequest.d.ts +5 -0
- package/dist/generated/models/beginPersonMcpServerSignInRequest.js +1 -0
- package/dist/generated/models/completePersonMcpServerSignInRequest.d.ts +6 -0
- package/dist/generated/models/completePersonMcpServerSignInRequest.js +1 -0
- package/dist/generated/models/endUserMcpServerState.d.ts +5 -0
- package/dist/generated/models/endUserMcpServerState.js +4 -0
- package/dist/generated/models/handOffPersonMcpServerSignInRequest.d.ts +4 -0
- package/dist/generated/models/handOffPersonMcpServerSignInRequest.js +1 -0
- package/dist/generated/models/headersPersonMcpServerCredential.d.ts +5 -0
- package/dist/generated/models/headersPersonMcpServerCredential.js +1 -0
- package/dist/generated/models/index.d.ts +26 -0
- package/dist/generated/models/index.js +26 -0
- package/dist/generated/models/inspectPersonMcpServerRequest.d.ts +3 -0
- package/dist/generated/models/inspectPersonMcpServerRequest.js +1 -0
- package/dist/generated/models/mcpCredentialKind.d.ts +6 -0
- package/dist/generated/models/mcpCredentialKind.js +5 -0
- package/dist/generated/models/mcpServerSignInHandoff.d.ts +6 -0
- package/dist/generated/models/mcpServerSignInHandoff.js +1 -0
- package/dist/generated/models/mcpServerSignInPending.d.ts +4 -0
- package/dist/generated/models/mcpServerSignInPending.js +3 -0
- package/dist/generated/models/mcpServerSignInStatus.d.ts +7 -0
- package/dist/generated/models/mcpServerSignInStatus.js +6 -0
- package/dist/generated/models/mcpSignInMode.d.ts +6 -0
- package/dist/generated/models/mcpSignInMode.js +5 -0
- package/dist/generated/models/mcpSkipReason.d.ts +9 -0
- package/dist/generated/models/mcpSkipReason.js +8 -0
- package/dist/generated/models/newPersonMcpServerSignInTarget.d.ts +3 -0
- package/dist/generated/models/newPersonMcpServerSignInTarget.js +1 -0
- package/dist/generated/models/newPersonMcpServerTarget.d.ts +3 -0
- package/dist/generated/models/newPersonMcpServerTarget.js +1 -0
- package/dist/generated/models/noPersonMcpServerCredential.d.ts +4 -0
- package/dist/generated/models/noPersonMcpServerCredential.js +3 -0
- package/dist/generated/models/personMcpServer.d.ts +15 -0
- package/dist/generated/models/personMcpServer.js +1 -0
- package/dist/generated/models/personMcpServerHeader.d.ts +4 -0
- package/dist/generated/models/personMcpServerHeader.js +1 -0
- package/dist/generated/models/personMcpServerInspection.d.ts +5 -0
- package/dist/generated/models/personMcpServerInspection.js +1 -0
- package/dist/generated/models/personMcpServerSignInBegun.d.ts +6 -0
- package/dist/generated/models/personMcpServerSignInBegun.js +1 -0
- package/dist/generated/models/personMcpServersProjection.d.ts +3 -0
- package/dist/generated/models/personMcpServersProjection.js +1 -0
- package/dist/generated/models/personMcpServersResponse.d.ts +6 -0
- package/dist/generated/models/personMcpServersResponse.js +1 -0
- package/dist/generated/models/personSkippedTool.d.ts +6 -0
- package/dist/generated/models/personSkippedTool.js +1 -0
- package/dist/generated/models/reconnectedPersonMcpServerSignInTarget.d.ts +3 -0
- package/dist/generated/models/reconnectedPersonMcpServerSignInTarget.js +1 -0
- package/dist/generated/models/reconnectedPersonMcpServerTarget.d.ts +4 -0
- package/dist/generated/models/reconnectedPersonMcpServerTarget.js +1 -0
- package/dist/generated/models/servingErrorCode.d.ts +10 -2
- package/dist/generated/models/servingErrorCode.js +4 -0
- package/dist/generated/models/tokenPersonMcpServerCredential.d.ts +4 -0
- package/dist/generated/models/tokenPersonMcpServerCredential.js +1 -0
- package/dist/generated/serving.js +142 -0
- package/dist/styles.css +1 -1
- package/dist/transport/connectors-api.js +47 -0
- package/dist/transport/serving-api.js +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -64,6 +64,7 @@ import { TeaflaskAssistant } from "@teaflask/assistant";
|
|
|
64
64
|
## What your agent can do
|
|
65
65
|
|
|
66
66
|
- **Take actions.** It calls your API on the user's behalf, with the user's own session. You set every action to Allow, Ask or Deny. On a [GraphQL](https://docs.teaflask.com/adapters#graphql) API, it runs them through your app's own client.
|
|
67
|
+
- **Use your MCP servers.** It calls tools on the MCP servers your organization connects, as the account you connected. You set every tool to Allow, Ask or Deny.
|
|
67
68
|
- **Follow your workflows.** Write a procedure once, like how refunds work or when to escalate, and the agent follows it.
|
|
68
69
|
- **Guide users around your app.** It takes people to the right page and highlights what to click.
|
|
69
70
|
- **Fill in forms.** It fills the fields; the user reviews and submits.
|
|
@@ -89,6 +90,7 @@ Everything you'd otherwise build by hand to put an agent in front of your users:
|
|
|
89
90
|
- The model of your choice, on your own provider key or your user's own plan
|
|
90
91
|
- Conversation history across devices, file attachments, and markdown with code highlighting
|
|
91
92
|
- Anonymous visitors or [signed-in users](https://docs.teaflask.com/identity)
|
|
93
|
+
- Signed-in users can connect their own apps over MCP, and the agent uses them in their conversations
|
|
92
94
|
- Every conversation, action and approval recorded for review
|
|
93
95
|
- Keyboard-complete, screen-reader friendly, and respects reduced motion
|
|
94
96
|
- A React component, a script tag for any other stack, or a headless entry point for your own UI
|
|
@@ -39,21 +39,22 @@ export interface AssistantThemeTokens {
|
|
|
39
39
|
/**
|
|
40
40
|
* Sets `--tf-popover`, the fill of the floating menus: the conversation
|
|
41
41
|
* history menu, the panel-position menu, the model picker, the ChatGPT plan
|
|
42
|
-
* menu, the command palette and the sub-agent preview.
|
|
43
|
-
* translucent, so the color is applied as a tint over
|
|
44
|
-
* them; give it the same light or dark polarity as
|
|
45
|
-
* floating panel, the mobile sheet and the sub-agent chip
|
|
46
|
-
* `background`. Defaults to the same value as `background`.
|
|
42
|
+
* menu, the Connectors menu, the command palette and the sub-agent preview.
|
|
43
|
+
* These surfaces are translucent, so the color is applied as a tint over
|
|
44
|
+
* what sits behind them; give it the same light or dark polarity as
|
|
45
|
+
* `background`. The floating panel, the mobile sheet and the sub-agent chip
|
|
46
|
+
* keep `background`. Defaults to the same value as `background`.
|
|
47
47
|
*/
|
|
48
48
|
popover?: string;
|
|
49
49
|
/**
|
|
50
50
|
* Sets `--tf-popover-foreground`, the text color the `popover` surfaces
|
|
51
51
|
* inherit: a menu's heading, the ChatGPT plan menu's connected standing,
|
|
52
|
-
* the
|
|
53
|
-
* use `mutedForeground` at rest and
|
|
54
|
-
* New conversation row at the top of
|
|
55
|
-
*
|
|
56
|
-
* colors. Defaults to the same value as
|
|
52
|
+
* the Connectors menu's server names, the command palette's heading and the
|
|
53
|
+
* sub-agent preview's text. Menu rows use `mutedForeground` at rest and
|
|
54
|
+
* `accentForeground` when hovered, the New conversation row at the top of
|
|
55
|
+
* the history menu keeps `foreground`, and the conversation shown inside
|
|
56
|
+
* the command palette keeps its own colors. Defaults to the same value as
|
|
57
|
+
* `foreground`.
|
|
57
58
|
*/
|
|
58
59
|
popoverForeground?: string;
|
|
59
60
|
/**
|
|
@@ -69,11 +70,12 @@ export interface AssistantThemeTokens {
|
|
|
69
70
|
primaryForeground?: string;
|
|
70
71
|
/**
|
|
71
72
|
* Sets `--tf-secondary`, the fill of the secondary buttons: Deny and Back
|
|
72
|
-
* on an approval card, Cancel and Keep editing under a question,
|
|
73
|
-
* while a
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
73
|
+
* on an approval card, Cancel and Keep editing under a question, Cancel
|
|
74
|
+
* while a sign-in is in progress, and Cancel and Dismiss in the Connectors
|
|
75
|
+
* menu and its reconnect notice. Hovered, the fill shifts slightly toward
|
|
76
|
+
* its own text color under a light `accent` wash, so a themed fill stays
|
|
77
|
+
* visible. Defaults to transparent, so these buttons stay quiet until you
|
|
78
|
+
* set it.
|
|
77
79
|
*/
|
|
78
80
|
secondary?: string;
|
|
79
81
|
/**
|
|
@@ -100,7 +102,8 @@ export interface AssistantThemeTokens {
|
|
|
100
102
|
accent?: string;
|
|
101
103
|
/**
|
|
102
104
|
* Sets `--tf-accent-foreground`, the text color over the `accent` fill:
|
|
103
|
-
* hovered menu rows, list rows, answer rows and quiet buttons, the
|
|
105
|
+
* hovered menu rows, list rows, answer rows and quiet buttons, the hovered
|
|
106
|
+
* Connectors chip and the Connectors menu's hovered buttons, the selected
|
|
104
107
|
* conversation in the history menu, and the title and badge of a hovered
|
|
105
108
|
* link row in a tool view. Defaults to the same value as `foreground`.
|
|
106
109
|
*/
|
|
@@ -116,8 +119,8 @@ export interface AssistantThemeTokens {
|
|
|
116
119
|
*/
|
|
117
120
|
border?: string;
|
|
118
121
|
/**
|
|
119
|
-
* Sets `--tf-input`, the border color of the message box
|
|
120
|
-
* shortcut hints.
|
|
122
|
+
* Sets `--tf-input`, the border color of the message box, of keyboard
|
|
123
|
+
* shortcut hints and of the text fields in the Connectors menu.
|
|
121
124
|
*/
|
|
122
125
|
input?: string;
|
|
123
126
|
/**
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { lazy, Suspense, useEffect } from "react";
|
|
3
4
|
import { ConversationGateCard } from "./conversation-gate-card.js";
|
|
4
|
-
import { SubscriptionPlanNotice } from "./subscription-plan-notice.js";
|
|
5
|
-
import {
|
|
5
|
+
import { planNoticeShows, SubscriptionPlanNotice, } from "./subscription-plan-notice.js";
|
|
6
|
+
import { SurfaceBoundary } from "./surface-boundary.js";
|
|
7
|
+
import { useAssistantSession, useOptionalAssistantSession, } from "./teaflask-assistant-provider.js";
|
|
8
|
+
import { useCell, useOptionalCell } from "./use-store-cell.js";
|
|
9
|
+
const ConnectorReconnectNotice = lazy(() => import("./connector-reconnect-notice.js"));
|
|
6
10
|
export function ComposerBanner({ gate }) {
|
|
7
11
|
const session = useOptionalAssistantSession();
|
|
8
12
|
if (gate.kind === "connect" ||
|
|
@@ -11,7 +15,38 @@ export function ComposerBanner({ gate }) {
|
|
|
11
15
|
return _jsx(ConversationGateCard, { gate: gate });
|
|
12
16
|
}
|
|
13
17
|
if (gate.kind === "none" && session !== null) {
|
|
14
|
-
return _jsx(
|
|
18
|
+
return _jsx(UngatedComposerBanner, {});
|
|
15
19
|
}
|
|
16
20
|
return null;
|
|
17
21
|
}
|
|
22
|
+
function UngatedComposerBanner() {
|
|
23
|
+
const session = useAssistantSession();
|
|
24
|
+
const due = useCell(session.planNoticeDue);
|
|
25
|
+
const statuses = useCell(session.subscriptions);
|
|
26
|
+
const reconnecting = useConnectorNeedingReconnect();
|
|
27
|
+
if (planNoticeShows(session, due, statuses)) {
|
|
28
|
+
return _jsx(SubscriptionPlanNotice, {});
|
|
29
|
+
}
|
|
30
|
+
return reconnecting !== null ? (_jsx(SurfaceBoundary, { surface: "connector-reconnect-notice", degrade: "silent", children: _jsx(Suspense, { fallback: null, children: _jsx(ConnectorReconnectNotice, { server: reconnecting, onSettled: () => {
|
|
31
|
+
session.settleReconnectNotice?.(_noticeKeyOf(reconnecting));
|
|
32
|
+
} }, reconnecting.id) }) })) : null;
|
|
33
|
+
}
|
|
34
|
+
function useConnectorNeedingReconnect() {
|
|
35
|
+
const session = useAssistantSession();
|
|
36
|
+
const projected = useOptionalCell(session.mcpServersProjection) !== null;
|
|
37
|
+
const list = useOptionalCell(session.mcpServers);
|
|
38
|
+
const settled = useOptionalCell(session.reconnectNoticesSettled);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (projected) {
|
|
41
|
+
session.ensureMcpServers?.();
|
|
42
|
+
}
|
|
43
|
+
}, [projected, session]);
|
|
44
|
+
if (!list?.offered) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return (list.servers.find((server) => server.state === "needs_reconnect" &&
|
|
48
|
+
settled?.has(_noticeKeyOf(server)) !== true) ?? null);
|
|
49
|
+
}
|
|
50
|
+
function _noticeKeyOf(server) {
|
|
51
|
+
return `${server.id}:${String(server.generation)}`;
|
|
52
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { ObservableCell } from "../core/observable-cell.js";
|
|
5
|
+
import { ConnectorsChip } from "./connectors-chip.js";
|
|
6
|
+
import { ModelPickerChip } from "./model-picker-chip.js";
|
|
7
|
+
import { ProviderChip } from "./provider-chip.js";
|
|
8
|
+
import { pollStanding } from "./standing-poll.js";
|
|
9
|
+
import { useAssistantSession, useOptionalAssistantSession, } from "./teaflask-assistant-provider.js";
|
|
10
|
+
import { useCell, useOptionalCell } from "./use-store-cell.js";
|
|
11
|
+
import { useLatestRef } from "./use-latest-ref.js";
|
|
12
|
+
const SETTLED = new ObservableCell(true);
|
|
13
|
+
const FUNDING_NOTE = "Models your plan serves run on it; other picks run on this site's own funding.";
|
|
14
|
+
function pressLandsOnAComposerMenu(event) {
|
|
15
|
+
return event
|
|
16
|
+
.composedPath()
|
|
17
|
+
.some((target) => target instanceof Element &&
|
|
18
|
+
target.hasAttribute("data-tf-composer-menu"));
|
|
19
|
+
}
|
|
20
|
+
export function useComposerMenuLightDismiss(open, onOpenChange, triggerRef) {
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (!open) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const doc = triggerRef.current?.ownerDocument ?? document;
|
|
26
|
+
const closeUnlessOnAMenu = (event) => {
|
|
27
|
+
if (!pressLandsOnAComposerMenu(event)) {
|
|
28
|
+
onOpenChange(false);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
doc.addEventListener("pointerdown", closeUnlessOnAMenu);
|
|
32
|
+
return () => {
|
|
33
|
+
doc.removeEventListener("pointerdown", closeUnlessOnAMenu);
|
|
34
|
+
};
|
|
35
|
+
}, [open, onOpenChange, triggerRef]);
|
|
36
|
+
}
|
|
37
|
+
export function ComposerChipShelf({ awaitsConfig = true, }) {
|
|
38
|
+
const session = useOptionalAssistantSession();
|
|
39
|
+
if (session === null) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return _jsx(MountedComposerChipShelf, { awaitsConfig: awaitsConfig });
|
|
43
|
+
}
|
|
44
|
+
function MountedComposerChipShelf({ awaitsConfig }) {
|
|
45
|
+
const { stored, setStored } = useStoredComposerMenu();
|
|
46
|
+
const tenants = useShelfTenants(awaitsConfig, stored);
|
|
47
|
+
const openMenu = useOpenComposerMenu(tenants.shows, stored, setStored);
|
|
48
|
+
if (!tenants.settled || !_anyTenantShows(tenants.shows)) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const { connectors, account, picker } = tenants;
|
|
52
|
+
const crowded = tenants.shows.connectors && tenants.shows.account && tenants.shows.picker;
|
|
53
|
+
const onOpenChangeOf = (menu) => (next) => {
|
|
54
|
+
setStored(next ? menu : null);
|
|
55
|
+
};
|
|
56
|
+
return (_jsxs("div", { className: "tf:@container tf:relative tf:mt-1.5 tf:flex tf:items-center tf:justify-end tf:gap-2 tf:px-1", children: [connectors !== null ? (_jsx(ConnectorsChip, { projection: connectors, open: openMenu === "connectors", onOpenChange: onOpenChangeOf("connectors") })) : null, tenants.shows.account ? (_jsx(ProviderChip, { statuses: account, open: openMenu === "account", onOpenChange: onOpenChangeOf("account"), compactWhenNarrow: crowded, fundingNote: picker !== null && account.some((status) => status.offered)
|
|
57
|
+
? FUNDING_NOTE
|
|
58
|
+
: undefined })) : null, picker !== null ? (_jsx(ModelPickerChip, { menu: picker, open: openMenu === "picker", onOpenChange: onOpenChangeOf("picker"), holdsMinimumWidth: crowded })) : null] }));
|
|
59
|
+
}
|
|
60
|
+
function useShelfTenants(awaitsConfig, stored) {
|
|
61
|
+
const session = useAssistantSession();
|
|
62
|
+
const settled = useCell(awaitsConfig ? session.configAnswered : SETTLED);
|
|
63
|
+
useConfigReadRetry(awaitsConfig);
|
|
64
|
+
const picker = useOptionalCell(awaitsConfig ? session.modelChoice : undefined);
|
|
65
|
+
const projection = useOptionalCell(session.mcpServersProjection);
|
|
66
|
+
const list = useOptionalCell(session.mcpServers);
|
|
67
|
+
const connectorsShow = settled &&
|
|
68
|
+
projection !== null &&
|
|
69
|
+
(!_connectorsAreGone(list) || stored === "connectors");
|
|
70
|
+
const identified = session.tier === "identified";
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (identified) {
|
|
73
|
+
session.ensureSubscriptions();
|
|
74
|
+
}
|
|
75
|
+
}, [identified, session]);
|
|
76
|
+
const statuses = useCell(session.subscriptions);
|
|
77
|
+
const account = identified
|
|
78
|
+
? (statuses ?? []).filter((status) => status.offered || status.connected)
|
|
79
|
+
: [];
|
|
80
|
+
return {
|
|
81
|
+
settled,
|
|
82
|
+
connectors: connectorsShow ? projection : null,
|
|
83
|
+
account,
|
|
84
|
+
picker,
|
|
85
|
+
shows: {
|
|
86
|
+
connectors: connectorsShow,
|
|
87
|
+
account: settled && account.length > 0,
|
|
88
|
+
picker: settled && picker !== null,
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function useConfigReadRetry(awaitsConfig) {
|
|
93
|
+
const { configReadFailed, refreshAssistantConfig } = useAssistantSession();
|
|
94
|
+
const failed = useOptionalCell(awaitsConfig ? configReadFailed : undefined) === true;
|
|
95
|
+
useEffect(() => (failed ? pollStanding(refreshAssistantConfig) : undefined), [failed, refreshAssistantConfig]);
|
|
96
|
+
}
|
|
97
|
+
function useStoredComposerMenu() {
|
|
98
|
+
const session = useAssistantSession();
|
|
99
|
+
const [localCell] = useState(() => new ObservableCell(null));
|
|
100
|
+
const setStored = session.setOpenComposerMenu ??
|
|
101
|
+
((next) => {
|
|
102
|
+
localCell.set(next);
|
|
103
|
+
});
|
|
104
|
+
const stored = useCell(session.openComposerMenu ?? localCell);
|
|
105
|
+
return { stored, setStored };
|
|
106
|
+
}
|
|
107
|
+
function useOpenComposerMenu(shows, stored, setStored) {
|
|
108
|
+
const session = useAssistantSession();
|
|
109
|
+
const openRequested = useCell(session.connectOpenRequested);
|
|
110
|
+
const askHonored = openRequested && shows.account;
|
|
111
|
+
const openMenu = askHonored
|
|
112
|
+
? "account"
|
|
113
|
+
: stored !== null && shows[stored]
|
|
114
|
+
? stored
|
|
115
|
+
: null;
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
if (askHonored) {
|
|
118
|
+
setStored("account");
|
|
119
|
+
session.acknowledgeSubscriptionConnect();
|
|
120
|
+
}
|
|
121
|
+
else if (stored !== null && !shows[stored]) {
|
|
122
|
+
setStored(null);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
const setStoredRef = useLatestRef(setStored);
|
|
126
|
+
useEffect(() => () => {
|
|
127
|
+
setStoredRef.current(null);
|
|
128
|
+
}, [setStoredRef]);
|
|
129
|
+
return openMenu;
|
|
130
|
+
}
|
|
131
|
+
function _connectorsAreGone(list) {
|
|
132
|
+
return list !== null && !list.offered && list.servers.length === 0;
|
|
133
|
+
}
|
|
134
|
+
function _anyTenantShows(shows) {
|
|
135
|
+
return shows.connectors || shows.account || shows.picker;
|
|
136
|
+
}
|
|
@@ -3,12 +3,12 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
3
3
|
import { useEffect, useLayoutEffect, useRef, useState, } from "react";
|
|
4
4
|
import { attachmentAcceptOf, ComposerAttachmentChip, } from "./composer-attachment-chip.js";
|
|
5
5
|
import { ComposerBanner } from "./composer-banner.js";
|
|
6
|
+
import { ComposerChipShelf } from "./composer-chip-shelf.js";
|
|
6
7
|
import { useConversation } from "./conversation-context.js";
|
|
7
8
|
import { ArrowUpIcon, PlusIcon, StopIcon } from "./icons.js";
|
|
8
9
|
import { TfButton } from "./primitives/button.js";
|
|
9
10
|
import { TfFileInput } from "./primitives/file-input.js";
|
|
10
11
|
import { TfTextarea } from "./primitives/textarea.js";
|
|
11
|
-
import { ModelPickerShelf } from "./model-picker-chip.js";
|
|
12
12
|
import { useOptionalAssistantSession } from "./teaflask-assistant-provider.js";
|
|
13
13
|
import { NO_GATE } from "../core/connect-gate.js";
|
|
14
14
|
import { attachmentRoomOf } from "../core/composer-attachments.js";
|
|
@@ -173,7 +173,7 @@ function ComposerSlabAndShelf({ draft, setDraft, attachments, policy, gate, busy
|
|
|
173
173
|
attach.removeAttachment(item.localId);
|
|
174
174
|
} }, item.localId))) })) : null, _jsx(TfTextarea, { ref: textareaRef, rows: 2, variant: "bare", "data-tf-autofocus": "", value: draft, placeholder: "Ask anything", "aria-label": "Message", onChange: (event) => {
|
|
175
175
|
setDraft(event.target.value);
|
|
176
|
-
}, onKeyDown: composerKeys, onFocus: onTextareaFocus, onBlur: onTextareaBlur }), _jsx(ComposerControlsRow, { attachments: attachments, policy: policy, busy: busy, pendingSend: pendingSend, stopping: stopping, stopTurn: stopTurn, stopOnEscape: stopOnEscape, send: send, attach: attach, textareaRef: textareaRef })] }), gate.kind === "none" ? _jsx(
|
|
176
|
+
}, onKeyDown: composerKeys, onFocus: onTextareaFocus, onBlur: onTextareaBlur }), _jsx(ComposerControlsRow, { attachments: attachments, policy: policy, busy: busy, pendingSend: pendingSend, stopping: stopping, stopTurn: stopTurn, stopOnEscape: stopOnEscape, send: send, attach: attach, textareaRef: textareaRef })] }), gate.kind === "none" ? _jsx(ComposerChipShelf, {}) : null] }));
|
|
177
177
|
}
|
|
178
178
|
function ComposerControlsRow({ attachments, policy, busy, pendingSend, stopping, stopTurn, stopOnEscape, send, attach, textareaRef, }) {
|
|
179
179
|
const fileInputRef = useRef(null);
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
4
|
+
import { failureSentenceOf } from "../core/error-copy.js";
|
|
5
|
+
import { addMcpServer, inspectMcpServer, reconnectTargetOf, } from "../transport/connectors-api.js";
|
|
6
|
+
import { SignInStep } from "./connector-sign-in.js";
|
|
7
|
+
import { focusAutofocusTarget } from "./primitives/autofocus.js";
|
|
8
|
+
import { Disclosure, DisclosureChevron } from "./primitives/disclosure.js";
|
|
9
|
+
import { TfButton } from "./primitives/button.js";
|
|
10
|
+
import { TfTextInput } from "./primitives/text-input.js";
|
|
11
|
+
import { useAssistantSession } from "./teaflask-assistant-provider.js";
|
|
12
|
+
const ACTION_ROW = "tf:flex tf:flex-wrap tf:justify-end tf:gap-2";
|
|
13
|
+
const STEP_STACK = "tf:flex tf:flex-col tf:gap-3";
|
|
14
|
+
const TEXT_LINE = "tf:m-0 tf:text-tf-label";
|
|
15
|
+
const EMPTY_DRAFT = {
|
|
16
|
+
tokenChosen: false,
|
|
17
|
+
headersChosen: false,
|
|
18
|
+
token: "",
|
|
19
|
+
headerName: "",
|
|
20
|
+
headerValue: "",
|
|
21
|
+
};
|
|
22
|
+
export default function ConnectorAddFlow({ reconnecting, onConnected, onCancel, onSignInChange, }) {
|
|
23
|
+
const session = useAssistantSession();
|
|
24
|
+
const [address, setAddress] = useState("");
|
|
25
|
+
const [inspection, setInspection] = useState(reconnecting === null
|
|
26
|
+
? null
|
|
27
|
+
: { host: reconnecting.host, sign_in: "token" });
|
|
28
|
+
const [draft, setDraft] = useState(EMPTY_DRAFT);
|
|
29
|
+
const [work, setWork] = useState(null);
|
|
30
|
+
const [error, setError] = useState(null);
|
|
31
|
+
const rootRef = useStepFocus(work === null ? _stepKeyOf(inspection, draft, error) : null);
|
|
32
|
+
const inspect = async () => {
|
|
33
|
+
setWork("inspecting");
|
|
34
|
+
setError(null);
|
|
35
|
+
try {
|
|
36
|
+
setInspection(await inspectMcpServer(session.session, address.trim()));
|
|
37
|
+
}
|
|
38
|
+
catch (failure) {
|
|
39
|
+
setError(failureSentenceOf(failure));
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
setWork(null);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const connect = async (credential) => {
|
|
46
|
+
setWork("connecting");
|
|
47
|
+
setError(null);
|
|
48
|
+
try {
|
|
49
|
+
await addMcpServer(session.session, {
|
|
50
|
+
target: reconnecting === null
|
|
51
|
+
? { url: address.trim() }
|
|
52
|
+
: reconnectTargetOf(reconnecting, session.mcpServers?.get() ?? null),
|
|
53
|
+
credential,
|
|
54
|
+
});
|
|
55
|
+
onConnected();
|
|
56
|
+
}
|
|
57
|
+
catch (failure) {
|
|
58
|
+
setError(failureSentenceOf(failure));
|
|
59
|
+
setWork(null);
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
session.refreshMcpServers?.();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const changeDraft = (next) => {
|
|
66
|
+
if (_methodOf(next) !== _methodOf(draft)) {
|
|
67
|
+
setError(null);
|
|
68
|
+
}
|
|
69
|
+
setDraft(next);
|
|
70
|
+
};
|
|
71
|
+
return (_jsx("div", { ref: rootRef, className: "tf:contents", children: work === "inspecting" ? (_jsx(WorkLine, { children: `Checking ${_hostOfTyped(address)}…` })) : work === "connecting" && inspection !== null ? (_jsx(WorkLine, { children: `Connecting ${inspection.host}…` })) : inspection === null ? (_jsx(AddressStep, { address: address, onAddressChange: setAddress, error: error, onContinue: () => void inspect(), onCancel: onCancel })) : (_jsx(CredentialStep, { inspection: inspection, address: address.trim(), draft: draft, onDraftChange: changeDraft, error: error, onConnect: (credential) => void connect(credential), onSignedIn: onConnected, onCancel: onCancel, onSignInChange: onSignInChange })) }));
|
|
72
|
+
}
|
|
73
|
+
function useStepFocus(stepKey) {
|
|
74
|
+
const rootRef = useRef(null);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
const root = rootRef.current;
|
|
77
|
+
if (stepKey !== null && root !== null) {
|
|
78
|
+
focusAutofocusTarget(root, () => rootRef.current !== null);
|
|
79
|
+
}
|
|
80
|
+
}, [stepKey]);
|
|
81
|
+
return rootRef;
|
|
82
|
+
}
|
|
83
|
+
function WorkLine({ children }) {
|
|
84
|
+
return (_jsx("p", { className: TEXT_LINE, role: "status", children: children }));
|
|
85
|
+
}
|
|
86
|
+
function AddressStep({ address, onAddressChange, error, onContinue, onCancel, }) {
|
|
87
|
+
const helpId = useId();
|
|
88
|
+
return (_jsxs("form", { className: STEP_STACK, onSubmit: (event) => {
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
onContinue();
|
|
91
|
+
}, children: [_jsx("p", { className: "tf:m-0 tf:text-tf-label tf:font-medium", children: "Add a connector" }), _jsx(LabelledField, { label: "Address", type: "text", placeholder: "https://example.com/\u2026", value: address, onChange: onAddressChange, error: error, helpId: helpId, autofocus: true }), _jsx("p", { id: helpId, className: "tf:m-0 tf:text-xs tf:text-tf-muted-foreground", children: "The address the app gives for connecting AI assistants. If the app gives you a key, use the access token option instead of putting the key in the address." }), _jsxs("div", { className: ACTION_ROW, children: [_jsx(TfButton, { variant: "secondary", onClick: onCancel, children: "Cancel" }), _jsx(TfButton, { type: "submit", disabled: address.trim() === "", children: "Continue" })] })] }));
|
|
92
|
+
}
|
|
93
|
+
function CredentialStep(props) {
|
|
94
|
+
const { inspection, address, draft, onDraftChange, error } = props;
|
|
95
|
+
const { onConnect, onSignedIn, onCancel, onSignInChange } = props;
|
|
96
|
+
const { host } = inspection;
|
|
97
|
+
if (inspection.sign_in === "none") {
|
|
98
|
+
return (_jsxs("div", { className: STEP_STACK, children: [_jsx("p", { className: TEXT_LINE, children: `${host} doesn't need you to sign in.` }), _jsx(FailureLine, { error: error }), _jsx(StepActions, { onCancel: onCancel, onConnect: () => {
|
|
99
|
+
onConnect({ kind: "none" });
|
|
100
|
+
}, autofocusConnect: true })] }));
|
|
101
|
+
}
|
|
102
|
+
if (inspection.sign_in === "oauth" && !draft.tokenChosen) {
|
|
103
|
+
return (_jsx(SignInStep, { host: host, target: { url: address }, onUseToken: () => {
|
|
104
|
+
onDraftChange({ ...draft, tokenChosen: true });
|
|
105
|
+
}, onConnected: onSignedIn, onCancel: onCancel, onSignInChange: onSignInChange }));
|
|
106
|
+
}
|
|
107
|
+
return _jsx(TokenForm, { ...props });
|
|
108
|
+
}
|
|
109
|
+
function TokenForm({ inspection, draft, onDraftChange, error, onConnect, onCancel, }) {
|
|
110
|
+
const credential = _credentialOf(draft);
|
|
111
|
+
const fieldOf = (key) => ({
|
|
112
|
+
value: draft[key],
|
|
113
|
+
onChange: (value) => {
|
|
114
|
+
onDraftChange({ ...draft, [key]: value });
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
const headers = draft.headersChosen;
|
|
118
|
+
return (_jsxs("form", { className: STEP_STACK, onSubmit: (event) => {
|
|
119
|
+
event.preventDefault();
|
|
120
|
+
if (credential !== null) {
|
|
121
|
+
onConnect(credential);
|
|
122
|
+
}
|
|
123
|
+
}, children: [_jsx("p", { className: TEXT_LINE, children: `${inspection.host} needs an access token.` }), _jsx(LabelledField, { label: "Access token", type: "password", disabled: headers, error: headers ? null : error, autofocus: !headers, ...fieldOf("token") }), _jsxs(Disclosure, { variant: "bare", open: headers || undefined, onToggle: (open) => {
|
|
124
|
+
onDraftChange({ ...draft, headersChosen: open });
|
|
125
|
+
}, summaryClassName: "tf:flex tf:items-center tf:gap-1 tf:text-xs", bodyClassName: "tf:flex tf:flex-col tf:gap-3 tf:pt-3", summary: _jsxs(_Fragment, { children: ["Use a custom header instead", _jsx(DisclosureChevron, {})] }), children: [_jsx(LabelledField, { label: "Header name", type: "text", autofocus: headers && error === null, ...fieldOf("headerName") }), _jsx(LabelledField, { label: "Header value", type: "password", error: headers ? error : null, autofocus: headers && error !== null, ...fieldOf("headerValue") })] }), _jsx(StepActions, { onCancel: onCancel, connectDisabled: credential === null, submits: true })] }));
|
|
126
|
+
}
|
|
127
|
+
function LabelledField({ label, type, value, onChange, placeholder, disabled = false, error = null, helpId, autofocus = false, }) {
|
|
128
|
+
const fieldId = useId();
|
|
129
|
+
const errorId = useId();
|
|
130
|
+
const describedBy = [error !== null ? errorId : null, helpId ?? null]
|
|
131
|
+
.filter((id) => id !== null)
|
|
132
|
+
.join(" ");
|
|
133
|
+
return (_jsxs("div", { className: "tf:flex tf:flex-col tf:gap-1", children: [_jsx("label", { htmlFor: fieldId, className: "tf:text-xs tf:font-medium", children: label }), _jsx(TfTextInput, { id: fieldId, type: type, autoComplete: "off", placeholder: placeholder, disabled: disabled, "aria-invalid": error !== null ? true : undefined, "aria-describedby": describedBy === "" ? undefined : describedBy, "data-tf-autofocus": autofocus ? "" : undefined, value: value, onChange: (event) => {
|
|
134
|
+
onChange(event.target.value);
|
|
135
|
+
} }), _jsx(FailureLine, { id: errorId, error: error })] }));
|
|
136
|
+
}
|
|
137
|
+
function StepActions({ onCancel, onConnect, connectDisabled = false, submits = false, autofocusConnect = false, }) {
|
|
138
|
+
return (_jsxs("div", { className: ACTION_ROW, children: [_jsx(TfButton, { variant: "secondary", onClick: onCancel, children: "Cancel" }), _jsx(TfButton, { type: submits ? "submit" : "button", disabled: connectDisabled, "data-tf-autofocus": autofocusConnect ? "" : undefined, onClick: onConnect, children: "Connect" })] }));
|
|
139
|
+
}
|
|
140
|
+
function FailureLine({ id, error }) {
|
|
141
|
+
if (error === null) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
return (_jsx("p", { id: id, className: "tf:m-0 tf:text-tf-label tf:text-tf-destructive", role: "alert", children: error }));
|
|
145
|
+
}
|
|
146
|
+
function _credentialOf(draft) {
|
|
147
|
+
if (draft.headersChosen) {
|
|
148
|
+
const name = draft.headerName.trim();
|
|
149
|
+
const value = draft.headerValue.trim();
|
|
150
|
+
return name === "" || value === ""
|
|
151
|
+
? null
|
|
152
|
+
: { kind: "headers", headers: [{ name, value }] };
|
|
153
|
+
}
|
|
154
|
+
const token = draft.token.trim();
|
|
155
|
+
return token === "" ? null : { kind: "token", token };
|
|
156
|
+
}
|
|
157
|
+
function _methodOf(draft) {
|
|
158
|
+
return draft.headersChosen ? "headers" : draft.tokenChosen ? "token" : "";
|
|
159
|
+
}
|
|
160
|
+
function _stepKeyOf(inspection, draft, error) {
|
|
161
|
+
const step = inspection === null
|
|
162
|
+
? "address"
|
|
163
|
+
: `${inspection.sign_in}:${_methodOf(draft)}`;
|
|
164
|
+
return `${step}:${error ?? ""}`;
|
|
165
|
+
}
|
|
166
|
+
function _hostOfTyped(address) {
|
|
167
|
+
try {
|
|
168
|
+
return new URL(address.trim()).hostname;
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
return address.trim();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useRef, useState } from "react";
|
|
4
|
+
import { failureSentenceOf } from "../core/error-copy.js";
|
|
5
|
+
import { addMcpServer, reconnectTargetOf, } from "../transport/connectors-api.js";
|
|
6
|
+
import { ConnectorSignInArms, useRefocusWhenTheSignInEnds, } from "./connector-sign-in.js";
|
|
7
|
+
import { useConnectorSignInFlow } from "./connector-sign-in-flow.js";
|
|
8
|
+
import { TfButton } from "./primitives/button.js";
|
|
9
|
+
import { useAssistantSession } from "./teaflask-assistant-provider.js";
|
|
10
|
+
const NOTICE_FRAME = "tf:mb-3 tf:flex tf:flex-col tf:gap-2 tf:rounded-xl tf:p-3";
|
|
11
|
+
const WASHED = `${NOTICE_FRAME} tf:bg-tf-accent`;
|
|
12
|
+
const FAILED = `${NOTICE_FRAME} tf:border tf:bg-tf-background`;
|
|
13
|
+
const ACTION_ROW = "tf:flex tf:flex-wrap tf:gap-2";
|
|
14
|
+
export default function ConnectorReconnectNotice({ server, onSettled, }) {
|
|
15
|
+
const flow = useConnectorSignInFlow(onSettled);
|
|
16
|
+
const reconnect = useReconnectWithoutCredential(server, onSettled);
|
|
17
|
+
const rootRef = useRef(null);
|
|
18
|
+
useRefocusWhenTheSignInEnds(flow, rootRef);
|
|
19
|
+
if (flow.state.kind !== "idle") {
|
|
20
|
+
return (_jsx("div", { ref: rootRef, className: flow.state.kind === "ended" ? FAILED : WASHED, "data-tf-reconnect-notice": "", children: _jsx(ConnectorSignInArms, { flow: flow, align: "start" }) }));
|
|
21
|
+
}
|
|
22
|
+
const token = server.credential_kind === "headers";
|
|
23
|
+
return (_jsxs("div", { ref: rootRef, className: WASHED, "data-tf-reconnect-notice": "", children: [_jsx("p", { className: "tf:m-0 tf:text-tf-label tf:font-medium tf:text-tf-foreground", role: "status", children: token
|
|
24
|
+
? `${server.name} needs a new access token.`
|
|
25
|
+
: `${server.name} needs you to sign in again.` }), reconnect.error !== null ? (_jsx("p", { className: "tf:m-0 tf:text-tf-label tf:text-tf-destructive", role: "alert", children: reconnect.error })) : null, _jsxs("div", { className: ACTION_ROW, children: [token ? (_jsx(ReplaceTokenButton, { server: server })) : (_jsx(TfButton, { disabled: reconnect.busy, "data-tf-autofocus": "", onClick: () => {
|
|
26
|
+
if (server.credential_kind === "oauth") {
|
|
27
|
+
flow.start({
|
|
28
|
+
target: { server_id: server.id },
|
|
29
|
+
host: server.host,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
void reconnect.run();
|
|
34
|
+
}
|
|
35
|
+
}, children: "Reconnect" })), _jsx(TfButton, { variant: "secondary", disabled: reconnect.busy, onClick: onSettled, children: "Dismiss" })] })] }));
|
|
36
|
+
}
|
|
37
|
+
function ReplaceTokenButton({ server }) {
|
|
38
|
+
const session = useAssistantSession();
|
|
39
|
+
return (_jsx(TfButton, { onClick: () => {
|
|
40
|
+
session.openConnectorTokenForm?.(server.id);
|
|
41
|
+
}, children: "Replace token" }));
|
|
42
|
+
}
|
|
43
|
+
function useReconnectWithoutCredential(server, onReconnected) {
|
|
44
|
+
const session = useAssistantSession();
|
|
45
|
+
const [busy, setBusy] = useState(false);
|
|
46
|
+
const [error, setError] = useState(null);
|
|
47
|
+
const run = async () => {
|
|
48
|
+
setBusy(true);
|
|
49
|
+
setError(null);
|
|
50
|
+
try {
|
|
51
|
+
await addMcpServer(session.session, {
|
|
52
|
+
target: reconnectTargetOf(server, session.mcpServers?.get() ?? null),
|
|
53
|
+
credential: { kind: "none" },
|
|
54
|
+
});
|
|
55
|
+
onReconnected();
|
|
56
|
+
}
|
|
57
|
+
catch (failure) {
|
|
58
|
+
setError(failureSentenceOf(failure));
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
setBusy(false);
|
|
62
|
+
session.refreshMcpServers?.();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
return { busy, error, run };
|
|
66
|
+
}
|