@colixsystems/widget-sdk 0.334.0 → 0.336.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 CHANGED
@@ -91,7 +91,32 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
91
91
 
92
92
  ## Status
93
93
 
94
- `v0.334.0` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
94
+ `v0.336.0` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
95
+
96
+ ### What's new in 0.336.0 (contract 1.274.0)
97
+
98
+ **A file dropped on `<FilePicker>` on the web is picked, not opened.** The web picker only answered clicks, so a widget that drew a "drag and drop" area inside it let the browser open the dropped file instead. Leaving the app that way loses everything the user had filled in. A file dropped on the picker now reaches `onPick` as if picked. Any file `accept` rules out is left out, and only the first is passed on unless `multiple` is set. A drop is claimed even while the picker is disabled. The new `onDragActiveChange(active)` prop reports a file being dragged over the picker, so a drop area you draw can highlight. When pickers are nested, the outermost one takes the drop. React Native has no events for files dragged onto an app, so on a device the trigger opens the picker on tap only: show "drag and drop" wording only when the new `FilePicker.acceptsDrop` is true (it is false on native). `<FileUpload>` still takes a drop anywhere on its field. The web Player also claims a file dropped outside every drop target, so the browser never replaces the app with it.
99
+
100
+ ```jsx
101
+ const [over, setOver] = useState(false);
102
+ <FilePicker accept="image/*" multiple onPick={addPhotos} onDragActiveChange={setOver}>
103
+ <View style={{ borderStyle: "dashed", borderWidth: 2, borderColor: over ? colors.primary : colors.border }}>
104
+ <Text>{FilePicker.acceptsDrop ? t("drop_or_click", "Drop photos here or click to choose") : t("tap_to_choose", "Tap to choose photos")}</Text>
105
+ </View>
106
+ </FilePicker>
107
+ ```
108
+
109
+ ### What's new in 0.335.0 (contract 1.273.0)
110
+
111
+ **An AI chat can let each app user connect their own tools.** Call `useAgent(agentRef, { connections: true })` and `connections` lists the signed-in app user's own MCP servers for that agent: `{ supported, items, loading, error, add, test, remove, refresh }`. Each item is `{ id, name, server_url, auth_kind, status, last_error_code, tool_count, tools, tools_fetched_at, created_at }`; the access token is sent once with `add({ name, server_url, token })` and never returned. Offer the control only while `supported` is true. It stays false on the Studio canvas, in a preview, for a signed-out visitor (`error.code` `APP_USER_SESSION_REQUIRED`) and when the agent's author has not allowed it (`TOOLS_NOT_ENABLED`). `add`, `test` and `remove` reject with an `AgentError` whose `code` is `TOO_MANY_CONNECTIONS` or `NAME_IN_USE` (409), or `INVALID_SERVER_URL`, `SERVER_UNREACHABLE`, `NOT_AN_MCP_SERVER` or `SERVER_REQUIRES_SIGN_IN` (422, ask for an access token). Without the option nothing is requested. A host older than this release returns no `connections`, so read it defensively. Additive.
112
+
113
+ ```jsx
114
+ const { connections } = useAgent(props.agentId, { connections: true });
115
+ if (connections && connections.supported) {
116
+ // render connections.items, and an add form calling
117
+ // connections.add({ name, server_url, token })
118
+ }
119
+ ```
95
120
 
96
121
  ### What's new in 0.334.0 (contract 1.272.0)
97
122
 
@@ -0,0 +1,17 @@
1
+ // sc-17588 — one of the caller's own MCP server connections, as the wire
2
+ // carries it. The single source: widget-sdk's build copies this file, so it
3
+ // must import nothing.
4
+
5
+ /** The token is write-only and never returned. */
6
+ export interface AgentMcpConnection {
7
+ id: string;
8
+ name: string;
9
+ server_url: string;
10
+ auth_kind: string;
11
+ status: "connected" | "error";
12
+ last_error_code: string | null;
13
+ tool_count: number;
14
+ tools: Array<{ name: string; description: string }>;
15
+ tools_fetched_at: string | null;
16
+ created_at: string;
17
+ }
package/dist/contract.cjs CHANGED
@@ -2276,6 +2276,20 @@ const HOOKS = [
2276
2276
  "signed-in user, reaches the model on that turn only, and a user message " +
2277
2277
  "that carried files has `attachments` ({ file_id, name, mime_type, size_bytes }). " +
2278
2278
  "Without { files: true } `acceptsFiles` stays false and nothing extra is requested. " +
2279
+ "CONNECTED TOOLS (sc-17588): call useAgent(agentRef, { connections: true }) and " +
2280
+ "`connections` lists the signed-in app user's OWN MCP servers for this agent: " +
2281
+ "{ supported, items, loading, error, add({ name, server_url, token }), test(id), remove(id), refresh() }. " +
2282
+ "Each item is { id, name, server_url, auth_kind, status ('connected' | 'error'), last_error_code, " +
2283
+ "tool_count, tools: [{ name, description }], tools_fetched_at, created_at }; the token is never returned. " +
2284
+ "Offer the control ONLY while `supported` is true: it is false until the server answers, and stays " +
2285
+ "false on a 403 — APP_USER_SESSION_REQUIRED (the studio canvas, a preview or a signed-out visitor) or " +
2286
+ "TOOLS_NOT_ENABLED (the author has not let app users connect tools to this agent). add, test and " +
2287
+ "remove reject with AgentError: TOO_MANY_CONNECTIONS and NAME_IN_USE (409), INVALID_SERVER_URL, " +
2288
+ "SERVER_UNREACHABLE, NOT_AN_MCP_SERVER and SERVER_REQUIRES_SIGN_IN (422, ask for an access token). " +
2289
+ "A turn that used one of them carries an activity entry { tool: 'mcp', ok, server } " +
2290
+ "naming the server, never a table: show it as 'Used <server>'. " +
2291
+ "Take the token in a secure input, confirm a removal in your own dialog, and on a host older " +
2292
+ "than this contract `connections` is absent, so read it defensively. " +
2279
2293
  "Reads ctx.agents.",
2280
2294
  returnShape: {
2281
2295
  send: "(text, { files }?) => Promise<{ id, role, content, created_at } | null>",
@@ -2288,6 +2302,8 @@ const HOOKS = [
2288
2302
  available: "boolean // false when no agent is bound, or the host brokers none",
2289
2303
  acceptsFiles: "boolean // asked only with { files: true }; false until the server says the agent reads files",
2290
2304
  fileLimits: "{ types, maxFiles, maxPdfs, maxFileBytes, maxTotalBytes } | null",
2305
+ connections:
2306
+ "{ supported, items, loading, error, add({ name, server_url, token }), test(id), remove(id), refresh() } // asked only with { connections: true }",
2291
2307
  },
2292
2308
  requiredContextSlice: ["agents.conversations"],
2293
2309
  scopes: ["ai.invoke:*"],
@@ -3663,7 +3679,7 @@ const PRIMITIVES = [
3663
3679
  {
3664
3680
  name: "FilePicker",
3665
3681
  description:
3666
- 'End-user file picker primitive. `<FilePicker accept="image/*" multiple={false} disabled={false} onPick={(file) => …}>…trigger…</FilePicker>`. Children render as the visible click target (a Pressable + Icon + Text is the common shape) and are wrapped in a hidden-input <label> so the click reaches the file dialog without any ref plumbing. Pair with useFilestoreUpload to upload the picked File to the end-user filestore. `onFocus` / `onBlur` report the picker\'s keyboard focus, so a trigger you draw can show it. `FilePicker.isSupported` is `true` on the web Player and on the native Expo export, which opens the system document picker; a host without a picker sets it `false`, so disable the trigger and say why. For an upload field use `<FileUpload>`, which draws the button, the chosen files and the uploading and error states around this picker; the bare FilePicker is for a trigger that is not a field, such as a photo the user taps to replace.',
3682
+ 'End-user file picker primitive. `<FilePicker accept="image/*" multiple={false} disabled={false} onPick={(file) => …}>…trigger…</FilePicker>`. Children render as the visible click target (a Pressable + Icon + Text is the common shape) and are wrapped in a hidden-input <label> so the click reaches the file dialog without any ref plumbing. Pair with useFilestoreUpload to upload the picked File to the end-user filestore. `onFocus` / `onBlur` report the picker\'s keyboard focus, so a trigger you draw can show it. On the web a file can also be dropped onto the picker: dropped files reach `onPick` as if picked, leaving out any that `accept` rules out (and all but the first unless `multiple`), and `onDragActiveChange(active)` reports a file being dragged over it so a drop area you draw can highlight. When pickers are nested, the outermost one takes the drop. React Native has no events for files dragged onto an app, so on a device the trigger opens the picker on tap only: show "drag and drop" wording only when `FilePicker.acceptsDrop` is true. `FilePicker.isSupported` is `true` on the web Player and on the native Expo export, which opens the system document picker; a host without a picker sets it `false`, so disable the trigger and say why. For an upload field use `<FileUpload>`, which draws the button, the chosen files and the uploading and error states around this picker; the bare FilePicker is for a trigger that is not a field, such as a photo the user taps to replace.',
3667
3683
  rnComponent: null,
3668
3684
  docsUrl: null,
3669
3685
  },
@@ -4488,7 +4504,8 @@ const WIDGET_CONTEXT_SHAPE = {
4488
4504
  "sc-7991 — injected @colixsystems/agents-client instance. " +
4489
4505
  "{ conversations(agentId) -> { create(), list(query), remove(conversationId), " +
4490
4506
  "messages(conversationId) -> { list(query), send({ content, file_ids? }) } }, " +
4491
- "capabilities(agentId) -> Promise<{ accepts_files, accepted_file_types, max_files, max_pdfs, max_file_bytes, max_total_bytes }> }. " +
4507
+ "capabilities(agentId) -> Promise<{ accepts_files, accepted_file_types, max_files, max_pdfs, max_file_bytes, max_total_bytes }>, " +
4508
+ "connections(agentId) -> { list(), create({ name, server_url, token }), test(id), remove(id) } (sc-17588; optional on older hosts) }. " +
4492
4509
  "Backs useAgent(). The workspace's agent owns the system prompt and the " +
4493
4510
  "server owns the transcript, so `send` puts ONLY `content` and `file_ids` on the wire — " +
4494
4511
  "a prompt, a history or a model id cannot be smuggled through. " +
@@ -7076,7 +7093,12 @@ const CONTRACT = deepFreeze({
7076
7093
  // 1.272.0: stricter lint (sc-17552) — a widget that calls
7077
7094
  // useAccessPlans().purchase without cancel is the publish-blocking
7078
7095
  // `access-plan-cancel-missing` finding.
7079
- version: "1.272.0",
7096
+ // 1.273.0: additive (sc-17588) — `useAgent(agentRef, { connections: true })`
7097
+ // returns `connections`: the signed-in app user's own MCP servers for the
7098
+ // agent, with add, test, remove and refresh.
7099
+ // 1.274.0: additive (sc-17683) — the web `<FilePicker>` takes dropped files
7100
+ // through `onPick`; new `onDragActiveChange` prop and `FilePicker.acceptsDrop`.
7101
+ version: "1.274.0",
7080
7102
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
7081
7103
  hooks: HOOKS,
7082
7104
  primitives: PRIMITIVES,
package/dist/contract.js CHANGED
@@ -2271,6 +2271,20 @@ const HOOKS = [
2271
2271
  "signed-in user, reaches the model on that turn only, and a user message " +
2272
2272
  "that carried files has `attachments` ({ file_id, name, mime_type, size_bytes }). " +
2273
2273
  "Without { files: true } `acceptsFiles` stays false and nothing extra is requested. " +
2274
+ "CONNECTED TOOLS (sc-17588): call useAgent(agentRef, { connections: true }) and " +
2275
+ "`connections` lists the signed-in app user's OWN MCP servers for this agent: " +
2276
+ "{ supported, items, loading, error, add({ name, server_url, token }), test(id), remove(id), refresh() }. " +
2277
+ "Each item is { id, name, server_url, auth_kind, status ('connected' | 'error'), last_error_code, " +
2278
+ "tool_count, tools: [{ name, description }], tools_fetched_at, created_at }; the token is never returned. " +
2279
+ "Offer the control ONLY while `supported` is true: it is false until the server answers, and stays " +
2280
+ "false on a 403 — APP_USER_SESSION_REQUIRED (the studio canvas, a preview or a signed-out visitor) or " +
2281
+ "TOOLS_NOT_ENABLED (the author has not let app users connect tools to this agent). add, test and " +
2282
+ "remove reject with AgentError: TOO_MANY_CONNECTIONS and NAME_IN_USE (409), INVALID_SERVER_URL, " +
2283
+ "SERVER_UNREACHABLE, NOT_AN_MCP_SERVER and SERVER_REQUIRES_SIGN_IN (422, ask for an access token). " +
2284
+ "A turn that used one of them carries an activity entry { tool: 'mcp', ok, server } " +
2285
+ "naming the server, never a table: show it as 'Used <server>'. " +
2286
+ "Take the token in a secure input, confirm a removal in your own dialog, and on a host older " +
2287
+ "than this contract `connections` is absent, so read it defensively. " +
2274
2288
  "Reads ctx.agents.",
2275
2289
  returnShape: {
2276
2290
  send: "(text, { files }?) => Promise<{ id, role, content, created_at } | null>",
@@ -2283,6 +2297,8 @@ const HOOKS = [
2283
2297
  available: "boolean // false when no agent is bound, or the host brokers none",
2284
2298
  acceptsFiles: "boolean // asked only with { files: true }; false until the server says the agent reads files",
2285
2299
  fileLimits: "{ types, maxFiles, maxPdfs, maxFileBytes, maxTotalBytes } | null",
2300
+ connections:
2301
+ "{ supported, items, loading, error, add({ name, server_url, token }), test(id), remove(id), refresh() } // asked only with { connections: true }",
2286
2302
  },
2287
2303
  requiredContextSlice: ["agents.conversations"],
2288
2304
  scopes: ["ai.invoke:*"],
@@ -3658,7 +3674,7 @@ const PRIMITIVES = [
3658
3674
  {
3659
3675
  name: "FilePicker",
3660
3676
  description:
3661
- 'End-user file picker primitive. `<FilePicker accept="image/*" multiple={false} disabled={false} onPick={(file) => …}>…trigger…</FilePicker>`. Children render as the visible click target (a Pressable + Icon + Text is the common shape) and are wrapped in a hidden-input <label> so the click reaches the file dialog without any ref plumbing. Pair with useFilestoreUpload to upload the picked File to the end-user filestore. `onFocus` / `onBlur` report the picker\'s keyboard focus, so a trigger you draw can show it. `FilePicker.isSupported` is `true` on the web Player and on the native Expo export, which opens the system document picker; a host without a picker sets it `false`, so disable the trigger and say why. For an upload field use `<FileUpload>`, which draws the button, the chosen files and the uploading and error states around this picker; the bare FilePicker is for a trigger that is not a field, such as a photo the user taps to replace.',
3677
+ 'End-user file picker primitive. `<FilePicker accept="image/*" multiple={false} disabled={false} onPick={(file) => …}>…trigger…</FilePicker>`. Children render as the visible click target (a Pressable + Icon + Text is the common shape) and are wrapped in a hidden-input <label> so the click reaches the file dialog without any ref plumbing. Pair with useFilestoreUpload to upload the picked File to the end-user filestore. `onFocus` / `onBlur` report the picker\'s keyboard focus, so a trigger you draw can show it. On the web a file can also be dropped onto the picker: dropped files reach `onPick` as if picked, leaving out any that `accept` rules out (and all but the first unless `multiple`), and `onDragActiveChange(active)` reports a file being dragged over it so a drop area you draw can highlight. When pickers are nested, the outermost one takes the drop. React Native has no events for files dragged onto an app, so on a device the trigger opens the picker on tap only: show "drag and drop" wording only when `FilePicker.acceptsDrop` is true. `FilePicker.isSupported` is `true` on the web Player and on the native Expo export, which opens the system document picker; a host without a picker sets it `false`, so disable the trigger and say why. For an upload field use `<FileUpload>`, which draws the button, the chosen files and the uploading and error states around this picker; the bare FilePicker is for a trigger that is not a field, such as a photo the user taps to replace.',
3662
3678
  rnComponent: null,
3663
3679
  docsUrl: null,
3664
3680
  },
@@ -4483,7 +4499,8 @@ const WIDGET_CONTEXT_SHAPE = {
4483
4499
  "sc-7991 — injected @colixsystems/agents-client instance. " +
4484
4500
  "{ conversations(agentId) -> { create(), list(query), remove(conversationId), " +
4485
4501
  "messages(conversationId) -> { list(query), send({ content, file_ids? }) } }, " +
4486
- "capabilities(agentId) -> Promise<{ accepts_files, accepted_file_types, max_files, max_pdfs, max_file_bytes, max_total_bytes }> }. " +
4502
+ "capabilities(agentId) -> Promise<{ accepts_files, accepted_file_types, max_files, max_pdfs, max_file_bytes, max_total_bytes }>, " +
4503
+ "connections(agentId) -> { list(), create({ name, server_url, token }), test(id), remove(id) } (sc-17588; optional on older hosts) }. " +
4487
4504
  "Backs useAgent(). The workspace's agent owns the system prompt and the " +
4488
4505
  "server owns the transcript, so `send` puts ONLY `content` and `file_ids` on the wire — " +
4489
4506
  "a prompt, a history or a model id cannot be smuggled through. " +
@@ -7071,7 +7088,12 @@ const CONTRACT = deepFreeze({
7071
7088
  // 1.272.0: stricter lint (sc-17552) — a widget that calls
7072
7089
  // useAccessPlans().purchase without cancel is the publish-blocking
7073
7090
  // `access-plan-cancel-missing` finding.
7074
- version: "1.272.0",
7091
+ // 1.273.0: additive (sc-17588) — `useAgent(agentRef, { connections: true })`
7092
+ // returns `connections`: the signed-in app user's own MCP servers for the
7093
+ // agent, with add, test, remove and refresh.
7094
+ // 1.274.0: additive (sc-17683) — the web `<FilePicker>` takes dropped files
7095
+ // through `onPick`; new `onDragActiveChange` prop and `FilePicker.acceptsDrop`.
7096
+ version: "1.274.0",
7075
7097
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
7076
7098
  hooks: HOOKS,
7077
7099
  primitives: PRIMITIVES,
@@ -0,0 +1,58 @@
1
+ // The web's file drop target, shared by `<FilePicker>` and `<FileUpload>`.
2
+ // React Native has no events for files dragged onto an app, so native never uses it.
3
+
4
+ import React from "react";
5
+
6
+ // Drops a target already took; read instead of defaultPrevented, which
7
+ // another library's capture listener may set.
8
+ const claimedDrops = new WeakSet();
9
+
10
+ function carriesFiles(event) {
11
+ const types = event.dataTransfer && event.dataTransfer.types;
12
+ return Boolean(types) && Array.from(types).includes("Files");
13
+ }
14
+
15
+ /**
16
+ * The handlers that make an element take dropped files. A drop is always
17
+ * claimed, even while disabled, so the browser never opens the dropped file.
18
+ * The outermost target takes it (capture phase): a `<FilePicker>` inside a
19
+ * `<FileUpload>` field, or inside another picker, leaves the drop to it.
20
+ *
21
+ * @param {{ disabled?: boolean, onFiles: (files: File[]) => void,
22
+ * onActiveChange?: (active: boolean) => void }} options
23
+ */
24
+ export function useFileDropTarget({ disabled, onFiles, onActiveChange }) {
25
+ // Entering a child fires dragleave on the parent; count the depth.
26
+ const depth = React.useRef(0);
27
+ const setActive = (active) => {
28
+ if (typeof onActiveChange === "function") onActiveChange(active);
29
+ };
30
+ return {
31
+ onDragEnter: (event) => {
32
+ if (!carriesFiles(event)) return;
33
+ event.preventDefault();
34
+ depth.current += 1;
35
+ if (!disabled) setActive(true);
36
+ },
37
+ onDragOver: (event) => {
38
+ if (!carriesFiles(event)) return;
39
+ event.preventDefault();
40
+ event.dataTransfer.dropEffect = disabled ? "none" : "copy";
41
+ },
42
+ onDragLeave: (event) => {
43
+ if (!carriesFiles(event)) return;
44
+ depth.current = Math.max(0, depth.current - 1);
45
+ if (depth.current === 0) setActive(false);
46
+ },
47
+ onDropCapture: (event) => {
48
+ if (!carriesFiles(event)) return;
49
+ const native = event.nativeEvent || event;
50
+ const claimedOutside = claimedDrops.has(native);
51
+ claimedDrops.add(native);
52
+ event.preventDefault();
53
+ depth.current = 0;
54
+ setActive(false);
55
+ if (!disabled && !claimedOutside) onFiles(Array.from(event.dataTransfer.files || []));
56
+ },
57
+ };
58
+ }
@@ -10,51 +10,14 @@ import { makeFileUpload } from "./file-upload-view.js";
10
10
  import { FilePicker } from "./filepicker.js";
11
11
  import { Button } from "./button.js";
12
12
  import { Spinner } from "./loading.js";
13
+ import { useFileDropTarget } from "./drop-target.js";
13
14
 
14
15
  const DROP_ZONE_STYLE = { display: "flex", flexDirection: "column", minWidth: 0 };
15
16
 
16
- function carriesFiles(event) {
17
- const types = event.dataTransfer && event.dataTransfer.types;
18
- return Boolean(types) && Array.from(types).includes("Files");
19
- }
20
-
21
- /**
22
- * The field's drop target. A drop is always claimed, even while disabled,
23
- * so the browser never navigates away to the dropped file.
24
- */
17
+ /** The field's drop target: the whole field, not only its button. */
25
18
  function DropZone({ disabled, onFiles, onActiveChange, children }) {
26
- // Entering a child fires dragleave on the parent; count the depth.
27
- const depth = React.useRef(0);
28
- return React.createElement(
29
- "div",
30
- {
31
- style: DROP_ZONE_STYLE,
32
- onDragEnter: (event) => {
33
- if (!carriesFiles(event)) return;
34
- event.preventDefault();
35
- depth.current += 1;
36
- if (!disabled) onActiveChange(true);
37
- },
38
- onDragOver: (event) => {
39
- if (!carriesFiles(event)) return;
40
- event.preventDefault();
41
- event.dataTransfer.dropEffect = disabled ? "none" : "copy";
42
- },
43
- onDragLeave: (event) => {
44
- if (!carriesFiles(event)) return;
45
- depth.current = Math.max(0, depth.current - 1);
46
- if (depth.current === 0) onActiveChange(false);
47
- },
48
- onDrop: (event) => {
49
- if (!carriesFiles(event)) return;
50
- event.preventDefault();
51
- depth.current = 0;
52
- onActiveChange(false);
53
- if (!disabled) onFiles(Array.from(event.dataTransfer.files || []));
54
- },
55
- },
56
- children,
57
- );
19
+ const dropTarget = useFileDropTarget({ disabled, onFiles, onActiveChange });
20
+ return React.createElement("div", { style: DROP_ZONE_STYLE, ...dropTarget }, children);
58
21
  }
59
22
 
60
23
  export const FileUpload = makeFileUpload(
@@ -23,9 +23,16 @@
23
23
  // accessibilityLabel: string? — written to the wrapper label.
24
24
  // onFocus / onBlur: () => void — the hidden input's focus, so a
25
25
  // caller can draw a focus ring on its visible trigger.
26
+ // onDragActiveChange: (active) => void — files are being dragged over the
27
+ // picker, so a caller can highlight its drop area. Files dropped
28
+ // on the picker reach `onPick` as if picked, filtered by
29
+ // `accept` (and only the first unless `multiple`); the native
30
+ // picker has no drop and never calls it.
26
31
  // aria-describedby / aria-invalid — tie the picker to a field's note.
27
32
 
28
33
  import React, { useRef, useCallback } from "react";
34
+ import { useFileDropTarget } from "./drop-target.js";
35
+ import { partitionAccepted } from "./file-upload-logic.js";
29
36
 
30
37
  const HIDDEN_INPUT_STYLE = {
31
38
  position: "absolute",
@@ -68,10 +75,20 @@ export function FilePicker({
68
75
  accessibilityLabel,
69
76
  onFocus,
70
77
  onBlur,
78
+ onDragActiveChange,
71
79
  "aria-describedby": describedBy,
72
80
  "aria-invalid": invalid,
73
81
  }) {
74
82
  const inputRef = useRef(null);
83
+ const dropTarget = useFileDropTarget({
84
+ disabled,
85
+ onActiveChange: onDragActiveChange,
86
+ onFiles: (files) => {
87
+ const { accepted } = partitionAccepted(files, accept);
88
+ if (accepted.length === 0 || typeof onPick !== "function") return;
89
+ onPick(multiple ? accepted : accepted[0]);
90
+ },
91
+ });
75
92
 
76
93
  const handleChange = useCallback(
77
94
  (event) => {
@@ -92,6 +109,7 @@ export function FilePicker({
92
109
  {
93
110
  style: disabled ? LABEL_STYLE_DISABLED : LABEL_STYLE,
94
111
  "aria-label": accessibilityLabel,
112
+ ...dropTarget,
95
113
  },
96
114
  React.createElement("input", {
97
115
  ref: inputRef,
@@ -111,3 +129,4 @@ export function FilePicker({
111
129
  }
112
130
 
113
131
  FilePicker.isSupported = true;
132
+ FilePicker.acceptsDrop = true;
@@ -8,6 +8,8 @@
8
8
  // directly. Both honour the same public contract — `accept` / `multiple`
9
9
  // / `disabled` / `onPick` / `children` / `accessibilityLabel` / `onFocus`
10
10
  // / `onBlur` / `aria-describedby` / `aria-invalid`.
11
+ // `onDragActiveChange` is accepted and never called: React Native has no events
12
+ // for files dragged onto an app.
11
13
  //
12
14
  // `onPick` receives the same shape on both platforms:
13
15
  // - web → the browser's `File` object (a `Blob` with name + type).
@@ -122,3 +124,5 @@ export function FilePicker({
122
124
  }
123
125
 
124
126
  FilePicker.isSupported = true;
127
+ // React Native has no events for files dragged onto an app; tap only.
128
+ FilePicker.acceptsDrop = false;
package/dist/hooks.js CHANGED
@@ -1217,12 +1217,7 @@ export class TranslateError extends Error {
1217
1217
 
1218
1218
  function toTranslateError(err) {
1219
1219
  if (err instanceof TranslateError) return err;
1220
- const status =
1221
- err && err.response && typeof err.response.status === "number"
1222
- ? err.response.status
1223
- : err && typeof err.status === "number"
1224
- ? err.status
1225
- : null;
1220
+ const status = statusOfAgentFailure(err);
1226
1221
  const bodyCode =
1227
1222
  (err && err.response && err.response.data && err.response.data.code) ||
1228
1223
  (err && typeof err.code === "string" ? err.code : null);
@@ -3669,6 +3664,19 @@ export class AgentError extends Error {
3669
3664
  }
3670
3665
  }
3671
3666
 
3667
+ function statusOfAgentFailure(err) {
3668
+ if (err && err.response && typeof err.response.status === "number") return err.response.status;
3669
+ return err && typeof err.status === "number" ? err.status : null;
3670
+ }
3671
+
3672
+ const NO_CONNECTIONS = Object.freeze({
3673
+ agentId: null,
3674
+ supported: false,
3675
+ items: Object.freeze([]),
3676
+ loading: false,
3677
+ error: null,
3678
+ });
3679
+
3672
3680
  function toAgentError(err) {
3673
3681
  if (err instanceof AgentError) return err;
3674
3682
  const status =
@@ -3731,6 +3739,12 @@ function toAgentError(err) {
3731
3739
  * whether this agent reads files: `acceptsFiles` and `fileLimits` answer it.
3732
3740
  * Without the option nothing extra is requested and `acceptsFiles` is false.
3733
3741
  *
3742
+ * sc-17588 — `{ connections: true }` lists the signed-in app user's own MCP
3743
+ * servers for this agent into `connections` ({ supported, items, loading,
3744
+ * error, add, test, remove, refresh }). `supported` is false until the server
3745
+ * offers them, and stays false when it refuses (a studio preview, a signed-out
3746
+ * visitor, or an agent the author has not opened to them).
3747
+ *
3734
3748
  * Routes through the injected `@colixsystems/agents-client` at `ctx.agents`,
3735
3749
  * so the Player and the Expo export resolve against the identical client.
3736
3750
  */
@@ -4010,6 +4024,121 @@ export function useAgent(agentRef, options) {
4010
4024
  }
4011
4025
  }, []);
4012
4026
 
4027
+ // sc-17588 — the caller's own MCP servers for this agent. Asked only with
4028
+ // `{ connections: true }`, so a widget without the control sends nothing.
4029
+ const wantsConnections = Boolean(options && options.connections === true);
4030
+ const [connectionState, setConnectionState] = useState(NO_CONNECTIONS);
4031
+ const connectionsGenerationRef = useRef(0);
4032
+
4033
+ const connectionsApi = useCallback(() => {
4034
+ const client = clientRef.current;
4035
+ const agentId = agentIdRef.current;
4036
+ if (!client || !agentId || typeof client.connections !== "function") return null;
4037
+ return { agentId, api: client.connections(agentId) };
4038
+ }, []);
4039
+
4040
+ const refreshConnections = useCallback(async () => {
4041
+ const handle = connectionsApi();
4042
+ if (!handle) return;
4043
+ connectionsGenerationRef.current += 1;
4044
+ const generation = connectionsGenerationRef.current;
4045
+ setConnectionState((prior) =>
4046
+ prior.agentId === handle.agentId
4047
+ ? { ...prior, loading: true, error: null }
4048
+ : { ...NO_CONNECTIONS, agentId: handle.agentId, loading: true },
4049
+ );
4050
+ try {
4051
+ const listed = await handle.api.list();
4052
+ if (connectionsGenerationRef.current !== generation) return;
4053
+ setConnectionState({
4054
+ agentId: handle.agentId,
4055
+ supported: true,
4056
+ items: listed && Array.isArray(listed.data) ? listed.data : [],
4057
+ loading: false,
4058
+ error: null,
4059
+ });
4060
+ } catch (err) {
4061
+ if (connectionsGenerationRef.current !== generation) return;
4062
+ const e = toAgentError(err);
4063
+ // A refusal (signed out, studio preview, switch off) hides the control;
4064
+ // a blip keeps what was already shown.
4065
+ const refused = statusOfAgentFailure(err) === 403;
4066
+ setConnectionState((prior) => ({
4067
+ ...prior,
4068
+ agentId: handle.agentId,
4069
+ supported: refused ? false : prior.supported,
4070
+ items: refused ? [] : prior.items,
4071
+ loading: false,
4072
+ error: e,
4073
+ }));
4074
+ }
4075
+ }, [connectionsApi]);
4076
+
4077
+ useEffect(() => {
4078
+ setConnectionState(NO_CONNECTIONS);
4079
+ if (wantsConnections && available) refreshConnections();
4080
+ return () => {
4081
+ connectionsGenerationRef.current += 1;
4082
+ };
4083
+ }, [available, agentRef, wantsConnections, refreshConnections]);
4084
+
4085
+ // Each change applies only to the agent it was made for.
4086
+ const changeConnections = useCallback(
4087
+ async (call, apply) => {
4088
+ const handle = connectionsApi();
4089
+ if (!handle) {
4090
+ throw new AgentError("UNAVAILABLE", "Connected tools are not available here");
4091
+ }
4092
+ let result;
4093
+ try {
4094
+ result = await call(handle.api);
4095
+ } catch (err) {
4096
+ throw toAgentError(err);
4097
+ }
4098
+ setConnectionState((prior) =>
4099
+ prior.agentId === handle.agentId ? { ...prior, items: apply(prior.items, result) } : prior,
4100
+ );
4101
+ return result;
4102
+ },
4103
+ [connectionsApi],
4104
+ );
4105
+
4106
+ const connections = useMemo(() => {
4107
+ // Before the first answer for this agent, a list that will run is loading.
4108
+ const listing =
4109
+ wantsConnections && available && Boolean(ctx.agents) && typeof ctx.agents.connections === "function";
4110
+ const current =
4111
+ connectionState.agentId === agentRef ? connectionState : { ...NO_CONNECTIONS, loading: listing };
4112
+ return {
4113
+ supported: available && current.supported,
4114
+ items: current.items,
4115
+ loading: current.loading,
4116
+ error: current.error,
4117
+ // The token is write-only: it is sent once and never read back.
4118
+ add: (body) =>
4119
+ changeConnections(
4120
+ (api) =>
4121
+ api.create({
4122
+ name: body && body.name,
4123
+ server_url: body && body.server_url,
4124
+ token: body && body.token,
4125
+ }),
4126
+ (items, created) => (created ? items.concat(created) : items),
4127
+ ),
4128
+ test: (id) =>
4129
+ changeConnections(
4130
+ (api) => api.test(id),
4131
+ (items, updated) => items.map((c) => (updated && c.id === updated.id ? updated : c)),
4132
+ ),
4133
+ remove: (id) =>
4134
+ changeConnections(
4135
+ (api) => api.remove(id),
4136
+ (items) => items.filter((c) => c.id !== id),
4137
+ ),
4138
+ refresh: refreshConnections,
4139
+ };
4140
+ }, [connectionState, agentRef, available, wantsConnections, ctx.agents, changeConnections, refreshConnections]);
4141
+
4013
4142
  // The binding changed this render: hand back the empty transcript now rather
4014
4143
  // than one frame of the previous agent's conversation.
4015
4144
  let visibleMessages = messages;
@@ -4043,6 +4172,7 @@ export function useAgent(agentRef, options) {
4043
4172
  available,
4044
4173
  acceptsFiles: available && fileLimits !== null,
4045
4174
  fileLimits: available ? fileLimits : null,
4175
+ connections,
4046
4176
  };
4047
4177
  }
4048
4178
 
package/dist/index.d.ts CHANGED
@@ -924,6 +924,8 @@ export interface WidgetContext<TProps = unknown> {
924
924
  conversations(agentId: string): unknown;
925
925
  /** sc-16546 — what the app may send an agent; optional on older hosts. */
926
926
  capabilities?(agentId: string): Promise<unknown>;
927
+ /** sc-17588 — the app user's own MCP servers; optional on older hosts. */
928
+ connections?(agentId: string): unknown;
927
929
  };
928
930
  /** sc-13843 — injected @colixsystems/actions-client backing useAction(). */
929
931
  actions?: {
@@ -2133,6 +2135,8 @@ export interface AgentFileLimits {
2133
2135
  export interface AgentActivity {
2134
2136
  tool: string;
2135
2137
  ok: boolean;
2138
+ /** sc-17588 — on a `tool: "mcp"` call, the person's connected server it used. */
2139
+ server?: string;
2136
2140
  table?: string;
2137
2141
  record_id?: string;
2138
2142
  fields?: string[];
@@ -2187,6 +2191,33 @@ export interface AgentApi {
2187
2191
  acceptsFiles: boolean;
2188
2192
  /** The types and limits when `acceptsFiles`, else null. */
2189
2193
  fileLimits: AgentFileLimits | null;
2194
+ /**
2195
+ * sc-17588 — the app user's own MCP servers for this agent, listed only when
2196
+ * the hook was called with `{ connections: true }`. Absent on older hosts.
2197
+ */
2198
+ connections: AgentConnections;
2199
+ }
2200
+
2201
+ // One wire type for both packages: the build copies agents-client's file in.
2202
+ import type { AgentMcpConnection } from "./agent-connection.js";
2203
+ export type { AgentMcpConnection } from "./agent-connection.js";
2204
+
2205
+ export interface AgentConnections {
2206
+ /**
2207
+ * True once the server lists them. False before it answers, and after a
2208
+ * 403 (APP_USER_SESSION_REQUIRED or TOOLS_NOT_ENABLED): hide the control.
2209
+ */
2210
+ supported: boolean;
2211
+ items: AgentMcpConnection[];
2212
+ loading: boolean;
2213
+ /** The last failed list; `code` says why. */
2214
+ error: AgentError | null;
2215
+ /** Rejects AgentError: TOO_MANY_CONNECTIONS, NAME_IN_USE, INVALID_SERVER_URL, SERVER_UNREACHABLE, NOT_AN_MCP_SERVER, SERVER_REQUIRES_SIGN_IN. */
2216
+ add(body: { name: string; server_url: string; token: string }): Promise<AgentMcpConnection>;
2217
+ /** Reconnects and re-reads the server's tools. */
2218
+ test(id: string): Promise<AgentMcpConnection>;
2219
+ remove(id: string): Promise<void>;
2220
+ refresh(): Promise<void>;
2190
2221
  }
2191
2222
 
2192
2223
  /**
@@ -2202,7 +2233,11 @@ export interface AgentApi {
2202
2233
  export function useAgent(
2203
2234
  agentRef: string | null | undefined,
2204
2235
  /** sc-16546 — `files: true` asks once (no credit spent) whether the agent reads files. */
2205
- options?: { files?: boolean },
2236
+ options?: {
2237
+ files?: boolean;
2238
+ /** sc-17588 — `connections: true` lists the app user's own MCP servers for this agent. */
2239
+ connections?: boolean;
2240
+ },
2206
2241
  ): AgentApi;
2207
2242
 
2208
2243
  export interface ActionApi {
@@ -5657,6 +5692,9 @@ export interface PickedFile {
5657
5692
  * hidden file input; native opens the OS document picker. `isSupported` is
5658
5693
  * false on a host with no picker. For an upload field use `<FileUpload>`.
5659
5694
  * It lays its children out like a `View`, a stretching column, on both hosts.
5695
+ * On the web a file dropped on it reaches `onPick` as if picked, leaving out
5696
+ * any `accept` rules out (the outermost of nested pickers takes it).
5697
+ * `acceptsDrop` is false on native: React Native has no file-drag events.
5660
5698
  */
5661
5699
  export const FilePicker: ((props: {
5662
5700
  /** An HTML accept value: "image/*", ".pdf", "application/pdf". */
@@ -5668,12 +5706,14 @@ export const FilePicker: ((props: {
5668
5706
  /** The picker's keyboard focus, for a trigger that draws its own ring. */
5669
5707
  onFocus?: () => void;
5670
5708
  onBlur?: () => void;
5709
+ /** A file is being dragged over the picker (web only), to highlight a drop area. */
5710
+ onDragActiveChange?: (active: boolean) => void;
5671
5711
  accessibilityLabel?: string;
5672
5712
  /** The id of the note that describes the picker, such as a field's error. */
5673
5713
  "aria-describedby"?: string;
5674
5714
  "aria-invalid"?: boolean;
5675
5715
  children?: ReactNode;
5676
- }) => any) & { isSupported: boolean };
5716
+ }) => any) & { isSupported: boolean; acceptsDrop: boolean };
5677
5717
 
5678
5718
  /**
5679
5719
  * Themed file chooser on `<FilePicker>`: a button (the `button` scope) in the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colixsystems/widget-sdk",
3
- "version": "0.334.0",
3
+ "version": "0.336.0",
4
4
  "description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
5
5
  "repository": {
6
6
  "type": "git",
package/src/contract.js CHANGED
@@ -2271,6 +2271,20 @@ const HOOKS = [
2271
2271
  "signed-in user, reaches the model on that turn only, and a user message " +
2272
2272
  "that carried files has `attachments` ({ file_id, name, mime_type, size_bytes }). " +
2273
2273
  "Without { files: true } `acceptsFiles` stays false and nothing extra is requested. " +
2274
+ "CONNECTED TOOLS (sc-17588): call useAgent(agentRef, { connections: true }) and " +
2275
+ "`connections` lists the signed-in app user's OWN MCP servers for this agent: " +
2276
+ "{ supported, items, loading, error, add({ name, server_url, token }), test(id), remove(id), refresh() }. " +
2277
+ "Each item is { id, name, server_url, auth_kind, status ('connected' | 'error'), last_error_code, " +
2278
+ "tool_count, tools: [{ name, description }], tools_fetched_at, created_at }; the token is never returned. " +
2279
+ "Offer the control ONLY while `supported` is true: it is false until the server answers, and stays " +
2280
+ "false on a 403 — APP_USER_SESSION_REQUIRED (the studio canvas, a preview or a signed-out visitor) or " +
2281
+ "TOOLS_NOT_ENABLED (the author has not let app users connect tools to this agent). add, test and " +
2282
+ "remove reject with AgentError: TOO_MANY_CONNECTIONS and NAME_IN_USE (409), INVALID_SERVER_URL, " +
2283
+ "SERVER_UNREACHABLE, NOT_AN_MCP_SERVER and SERVER_REQUIRES_SIGN_IN (422, ask for an access token). " +
2284
+ "A turn that used one of them carries an activity entry { tool: 'mcp', ok, server } " +
2285
+ "naming the server, never a table: show it as 'Used <server>'. " +
2286
+ "Take the token in a secure input, confirm a removal in your own dialog, and on a host older " +
2287
+ "than this contract `connections` is absent, so read it defensively. " +
2274
2288
  "Reads ctx.agents.",
2275
2289
  returnShape: {
2276
2290
  send: "(text, { files }?) => Promise<{ id, role, content, created_at } | null>",
@@ -2283,6 +2297,8 @@ const HOOKS = [
2283
2297
  available: "boolean // false when no agent is bound, or the host brokers none",
2284
2298
  acceptsFiles: "boolean // asked only with { files: true }; false until the server says the agent reads files",
2285
2299
  fileLimits: "{ types, maxFiles, maxPdfs, maxFileBytes, maxTotalBytes } | null",
2300
+ connections:
2301
+ "{ supported, items, loading, error, add({ name, server_url, token }), test(id), remove(id), refresh() } // asked only with { connections: true }",
2286
2302
  },
2287
2303
  requiredContextSlice: ["agents.conversations"],
2288
2304
  scopes: ["ai.invoke:*"],
@@ -3658,7 +3674,7 @@ const PRIMITIVES = [
3658
3674
  {
3659
3675
  name: "FilePicker",
3660
3676
  description:
3661
- 'End-user file picker primitive. `<FilePicker accept="image/*" multiple={false} disabled={false} onPick={(file) => …}>…trigger…</FilePicker>`. Children render as the visible click target (a Pressable + Icon + Text is the common shape) and are wrapped in a hidden-input <label> so the click reaches the file dialog without any ref plumbing. Pair with useFilestoreUpload to upload the picked File to the end-user filestore. `onFocus` / `onBlur` report the picker\'s keyboard focus, so a trigger you draw can show it. `FilePicker.isSupported` is `true` on the web Player and on the native Expo export, which opens the system document picker; a host without a picker sets it `false`, so disable the trigger and say why. For an upload field use `<FileUpload>`, which draws the button, the chosen files and the uploading and error states around this picker; the bare FilePicker is for a trigger that is not a field, such as a photo the user taps to replace.',
3677
+ 'End-user file picker primitive. `<FilePicker accept="image/*" multiple={false} disabled={false} onPick={(file) => …}>…trigger…</FilePicker>`. Children render as the visible click target (a Pressable + Icon + Text is the common shape) and are wrapped in a hidden-input <label> so the click reaches the file dialog without any ref plumbing. Pair with useFilestoreUpload to upload the picked File to the end-user filestore. `onFocus` / `onBlur` report the picker\'s keyboard focus, so a trigger you draw can show it. On the web a file can also be dropped onto the picker: dropped files reach `onPick` as if picked, leaving out any that `accept` rules out (and all but the first unless `multiple`), and `onDragActiveChange(active)` reports a file being dragged over it so a drop area you draw can highlight. When pickers are nested, the outermost one takes the drop. React Native has no events for files dragged onto an app, so on a device the trigger opens the picker on tap only: show "drag and drop" wording only when `FilePicker.acceptsDrop` is true. `FilePicker.isSupported` is `true` on the web Player and on the native Expo export, which opens the system document picker; a host without a picker sets it `false`, so disable the trigger and say why. For an upload field use `<FileUpload>`, which draws the button, the chosen files and the uploading and error states around this picker; the bare FilePicker is for a trigger that is not a field, such as a photo the user taps to replace.',
3662
3678
  rnComponent: null,
3663
3679
  docsUrl: null,
3664
3680
  },
@@ -4483,7 +4499,8 @@ const WIDGET_CONTEXT_SHAPE = {
4483
4499
  "sc-7991 — injected @colixsystems/agents-client instance. " +
4484
4500
  "{ conversations(agentId) -> { create(), list(query), remove(conversationId), " +
4485
4501
  "messages(conversationId) -> { list(query), send({ content, file_ids? }) } }, " +
4486
- "capabilities(agentId) -> Promise<{ accepts_files, accepted_file_types, max_files, max_pdfs, max_file_bytes, max_total_bytes }> }. " +
4502
+ "capabilities(agentId) -> Promise<{ accepts_files, accepted_file_types, max_files, max_pdfs, max_file_bytes, max_total_bytes }>, " +
4503
+ "connections(agentId) -> { list(), create({ name, server_url, token }), test(id), remove(id) } (sc-17588; optional on older hosts) }. " +
4487
4504
  "Backs useAgent(). The workspace's agent owns the system prompt and the " +
4488
4505
  "server owns the transcript, so `send` puts ONLY `content` and `file_ids` on the wire — " +
4489
4506
  "a prompt, a history or a model id cannot be smuggled through. " +
@@ -7071,7 +7088,12 @@ const CONTRACT = deepFreeze({
7071
7088
  // 1.272.0: stricter lint (sc-17552) — a widget that calls
7072
7089
  // useAccessPlans().purchase without cancel is the publish-blocking
7073
7090
  // `access-plan-cancel-missing` finding.
7074
- version: "1.272.0",
7091
+ // 1.273.0: additive (sc-17588) — `useAgent(agentRef, { connections: true })`
7092
+ // returns `connections`: the signed-in app user's own MCP servers for the
7093
+ // agent, with add, test, remove and refresh.
7094
+ // 1.274.0: additive (sc-17683) — the web `<FilePicker>` takes dropped files
7095
+ // through `onPick`; new `onDragActiveChange` prop and `FilePicker.acceptsDrop`.
7096
+ version: "1.274.0",
7075
7097
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
7076
7098
  hooks: HOOKS,
7077
7099
  primitives: PRIMITIVES,