@colixsystems/widget-sdk 0.336.0 → 0.337.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 +17 -3
- package/dist/agent-connection.d.ts +4 -2
- package/dist/contract.cjs +19 -5
- package/dist/contract.js +19 -5
- package/dist/hooks.js +40 -7
- package/dist/index.d.ts +15 -2
- package/dist/linter.cjs +79 -7
- package/dist/linter.js +79 -7
- package/package.json +1 -1
- package/src/contract.js +19 -5
package/README.md
CHANGED
|
@@ -91,7 +91,21 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
91
91
|
|
|
92
92
|
## Status
|
|
93
93
|
|
|
94
|
-
`v0.
|
|
94
|
+
`v0.337.1` — 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.337.1 (contract 1.275.0)
|
|
97
|
+
|
|
98
|
+
**The two permission-gate lint rules accept the code the contract prescribes.** `row-action-not-gated` no longer flags an `update` or `delete` of the row the widget's own `create()` just returned, as in the record-file attach flow (`const row = await create(values)`, then `upload(file, { recordId: row.id })`, then `update(row.id, …)`). That row carries no `_capabilities`, and whether its creator may edit it is set by the table's permissions. The exemption holds only while that name is bound once, so a listed `row` elsewhere in the file still needs its per-row gate. `write-not-gated-on-user` now accepts a `_capabilities` read as the gate when the widget only edits or deletes existing rows; a widget that also creates rows still gates the create on `useCanWrite(tableId)` or `useUser()`. Both findings now name the fix for each case. Fix-only: no rule was added or renamed.
|
|
99
|
+
|
|
100
|
+
### What's new in 0.337.0 (contract 1.275.0)
|
|
101
|
+
|
|
102
|
+
**An app user can sign in to a tools server that asks for it.** Call `connections.add({ name, server_url, token: "" })` for a server that asks people to sign in and the item comes back with `auth_kind: "oauth"` and `status: "needs_sign_in"`. Offer a "Sign in" action on an `oauth` item whose `status` is not `connected`, and only when `connections.signIn` is a function: the host runs the sign-in, and it is absent on the Studio canvas and on older hosts, so a widget never shows a dead button. `signIn(id)` resolves to the connected item, or rejects with an `AgentError` whose `code` is `SIGN_IN_CANCELLED`, `SIGN_IN_FAILED`, `CONFIRM_INVALID`, `NOT_A_SIGN_IN_SERVER`, `SERVER_UNREACHABLE` or `RATE_LIMITED`. In a phone app the sign-in opens in the in-app browser and the call settles when it closes. On the web the page itself goes to the sign-in, so the call never settles; when the page loads again, `connections.signInResult` is `{ connection, error }` for that sign-in (otherwise `null`), and the item is already connected. A server whose sign-in this app cannot use is refused on `add` with `SIGN_IN_NOT_SUPPORTED`. Additive.
|
|
103
|
+
|
|
104
|
+
```jsx
|
|
105
|
+
const { connections } = useAgent(props.agentId, { connections: true });
|
|
106
|
+
const canSignIn = (c) =>
|
|
107
|
+
c.auth_kind === "oauth" && c.status !== "connected" && typeof connections.signIn === "function";
|
|
108
|
+
// <Button title="Sign in" onPress={() => connections.signIn(c.id)} /> for each item where canSignIn(c)
|
|
95
109
|
|
|
96
110
|
### What's new in 0.336.0 (contract 1.274.0)
|
|
97
111
|
|
|
@@ -108,7 +122,7 @@ const [over, setOver] = useState(false);
|
|
|
108
122
|
|
|
109
123
|
### What's new in 0.335.0 (contract 1.273.0)
|
|
110
124
|
|
|
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
|
|
125
|
+
**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). Without the option nothing is requested. A host older than this release returns no `connections`, so read it defensively. Additive.
|
|
112
126
|
|
|
113
127
|
```jsx
|
|
114
128
|
const { connections } = useAgent(props.agentId, { connections: true });
|
|
@@ -4183,7 +4197,7 @@ Pass `--manifest` to enable `style-field-unread` and the three editability rules
|
|
|
4183
4197
|
|
|
4184
4198
|
`comment-as-jsx-text` refuses a `//` or `/* */` comment written between JSX tags, where it is text the web Player shows and the native app refuses. Write it as `{/* … */}`. An error.
|
|
4185
4199
|
|
|
4186
|
-
`row-action-not-gated` flags a widget that calls `update` or `delete` from `useDatastoreMutation` without a per-row permission check: no `_capabilities` read and no `useCanWrite(tableId, { recordId })`. The table-level `useCanWrite(tableId)` only answers "may create", so a list gated on it shows Edit / Delete on rows the server will refuse. A warning.
|
|
4200
|
+
`row-action-not-gated` flags a widget that calls `update` or `delete` from `useDatastoreMutation` without a per-row permission check: no `_capabilities` read and no `useCanWrite(tableId, { recordId })`. An `update` or `delete` of the row the widget's own `create()` just returned is exempt. The table-level `useCanWrite(tableId)` only answers "may create", so a list gated on it shows Edit / Delete on rows the server will refuse. A warning.
|
|
4187
4201
|
|
|
4188
4202
|
`no-html-in-content` flags an HTML tag inside a **string** — `"<strong>"`, `"<br>"`, `"<p>…</p>"`. There is no HTML renderer on either host, so the tag reaches the reader as literal text; author formatted text with `<MarkdownInput>` and render it with `<RichText>` instead. Only string and template content is scanned, so your own `<View>` / `<Text>` JSX can never trip it. A warning for a human author, blocking for the AI widget agent.
|
|
4189
4203
|
|
|
@@ -7,8 +7,10 @@ export interface AgentMcpConnection {
|
|
|
7
7
|
id: string;
|
|
8
8
|
name: string;
|
|
9
9
|
server_url: string;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
/** sc-17590 — "oauth" servers are reached by signing in, not by a token. */
|
|
11
|
+
auth_kind: "bearer" | "oauth";
|
|
12
|
+
/** "needs_sign_in": an "oauth" server the person has not (or no longer) signed in to. */
|
|
13
|
+
status: "connected" | "error" | "needs_sign_in";
|
|
12
14
|
last_error_code: string | null;
|
|
13
15
|
tool_count: number;
|
|
14
16
|
tools: Array<{ name: string; description: string }>;
|
package/dist/contract.cjs
CHANGED
|
@@ -2279,13 +2279,21 @@ const HOOKS = [
|
|
|
2279
2279
|
"CONNECTED TOOLS (sc-17588): call useAgent(agentRef, { connections: true }) and " +
|
|
2280
2280
|
"`connections` lists the signed-in app user's OWN MCP servers for this agent: " +
|
|
2281
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, " +
|
|
2282
|
+
"Each item is { id, name, server_url, auth_kind ('bearer' | 'oauth'), status ('connected' | 'error' | 'needs_sign_in'), last_error_code, " +
|
|
2283
2283
|
"tool_count, tools: [{ name, description }], tools_fetched_at, created_at }; the token is never returned. " +
|
|
2284
2284
|
"Offer the control ONLY while `supported` is true: it is false until the server answers, and stays " +
|
|
2285
2285
|
"false on a 403 — APP_USER_SESSION_REQUIRED (the studio canvas, a preview or a signed-out visitor) or " +
|
|
2286
2286
|
"TOOLS_NOT_ENABLED (the author has not let app users connect tools to this agent). add, test and " +
|
|
2287
2287
|
"remove reject with AgentError: TOO_MANY_CONNECTIONS and NAME_IN_USE (409), INVALID_SERVER_URL, " +
|
|
2288
|
-
"SERVER_UNREACHABLE, NOT_AN_MCP_SERVER and
|
|
2288
|
+
"SERVER_UNREACHABLE, NOT_AN_MCP_SERVER, SERVER_REQUIRES_SIGN_IN and SIGN_IN_NOT_SUPPORTED (422). " +
|
|
2289
|
+
"SIGN-IN (sc-17590): add with an empty token to a server that asks people to sign in answers " +
|
|
2290
|
+
"auth_kind 'oauth', status 'needs_sign_in'. Offer a Sign in action on an 'oauth' item whose status is " +
|
|
2291
|
+
"not 'connected', and ONLY when `connections.signIn` is a function (the host runs the sign-in; it is " +
|
|
2292
|
+
"absent on the studio canvas and on older hosts, so never show a dead button). signIn(id) resolves to " +
|
|
2293
|
+
"the connected item or rejects AgentError: SIGN_IN_CANCELLED, SIGN_IN_FAILED, CONFIRM_INVALID, " +
|
|
2294
|
+
"NOT_A_SIGN_IN_SERVER, SERVER_UNREACHABLE, RATE_LIMITED. On web the page leaves for the sign-in and " +
|
|
2295
|
+
"the call never settles; when the page loads again `connections.signInResult` is " +
|
|
2296
|
+
"{ connection, error } for that sign-in (null otherwise): show the outcome from it. " +
|
|
2289
2297
|
"A turn that used one of them carries an activity entry { tool: 'mcp', ok, server } " +
|
|
2290
2298
|
"naming the server, never a table: show it as 'Used <server>'. " +
|
|
2291
2299
|
"Take the token in a secure input, confirm a removal in your own dialog, and on a host older " +
|
|
@@ -2303,7 +2311,7 @@ const HOOKS = [
|
|
|
2303
2311
|
acceptsFiles: "boolean // asked only with { files: true }; false until the server says the agent reads files",
|
|
2304
2312
|
fileLimits: "{ types, maxFiles, maxPdfs, maxFileBytes, maxTotalBytes } | null",
|
|
2305
2313
|
connections:
|
|
2306
|
-
"{ supported, items, loading, error, add({ name, server_url, token }), test(id), remove(id), refresh() } // asked only with { connections: true }",
|
|
2314
|
+
"{ supported, items, loading, error, add({ name, server_url, token }), test(id), remove(id), refresh(), signIn?(id), signInResult } // asked only with { connections: true }",
|
|
2307
2315
|
},
|
|
2308
2316
|
requiredContextSlice: ["agents.conversations"],
|
|
2309
2317
|
scopes: ["ai.invoke:*"],
|
|
@@ -4505,7 +4513,9 @@ const WIDGET_CONTEXT_SHAPE = {
|
|
|
4505
4513
|
"{ conversations(agentId) -> { create(), list(query), remove(conversationId), " +
|
|
4506
4514
|
"messages(conversationId) -> { list(query), send({ content, file_ids? }) } }, " +
|
|
4507
4515
|
"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)
|
|
4516
|
+
"connections(agentId) -> { list(), create({ name, server_url, token }), test(id), remove(id), " +
|
|
4517
|
+
"consent(id, { return_url }), confirm(id, { confirm }), and where the host runs a sign-in signIn(id) and resumeSignIn() } " +
|
|
4518
|
+
"(sc-17588, sc-17590; optional on older hosts) }. " +
|
|
4509
4519
|
"Backs useAgent(). The workspace's agent owns the system prompt and the " +
|
|
4510
4520
|
"server owns the transcript, so `send` puts ONLY `content` and `file_ids` on the wire — " +
|
|
4511
4521
|
"a prompt, a history or a model id cannot be smuggled through. " +
|
|
@@ -7098,7 +7108,11 @@ const CONTRACT = deepFreeze({
|
|
|
7098
7108
|
// agent, with add, test, remove and refresh.
|
|
7099
7109
|
// 1.274.0: additive (sc-17683) — the web `<FilePicker>` takes dropped files
|
|
7100
7110
|
// through `onPick`; new `onDragActiveChange` prop and `FilePicker.acceptsDrop`.
|
|
7101
|
-
|
|
7111
|
+
// 1.275.0: additive (sc-17590) — `connections.signIn(id)` signs the app user
|
|
7112
|
+
// in to a server that asks for it, brokered by the host, and
|
|
7113
|
+
// `connections.signInResult` reports a web sign-in on the page's return.
|
|
7114
|
+
// Items gain status 'needs_sign_in' and auth_kind 'oauth'.
|
|
7115
|
+
version: "1.275.0",
|
|
7102
7116
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7103
7117
|
hooks: HOOKS,
|
|
7104
7118
|
primitives: PRIMITIVES,
|
package/dist/contract.js
CHANGED
|
@@ -2274,13 +2274,21 @@ const HOOKS = [
|
|
|
2274
2274
|
"CONNECTED TOOLS (sc-17588): call useAgent(agentRef, { connections: true }) and " +
|
|
2275
2275
|
"`connections` lists the signed-in app user's OWN MCP servers for this agent: " +
|
|
2276
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, " +
|
|
2277
|
+
"Each item is { id, name, server_url, auth_kind ('bearer' | 'oauth'), status ('connected' | 'error' | 'needs_sign_in'), last_error_code, " +
|
|
2278
2278
|
"tool_count, tools: [{ name, description }], tools_fetched_at, created_at }; the token is never returned. " +
|
|
2279
2279
|
"Offer the control ONLY while `supported` is true: it is false until the server answers, and stays " +
|
|
2280
2280
|
"false on a 403 — APP_USER_SESSION_REQUIRED (the studio canvas, a preview or a signed-out visitor) or " +
|
|
2281
2281
|
"TOOLS_NOT_ENABLED (the author has not let app users connect tools to this agent). add, test and " +
|
|
2282
2282
|
"remove reject with AgentError: TOO_MANY_CONNECTIONS and NAME_IN_USE (409), INVALID_SERVER_URL, " +
|
|
2283
|
-
"SERVER_UNREACHABLE, NOT_AN_MCP_SERVER and
|
|
2283
|
+
"SERVER_UNREACHABLE, NOT_AN_MCP_SERVER, SERVER_REQUIRES_SIGN_IN and SIGN_IN_NOT_SUPPORTED (422). " +
|
|
2284
|
+
"SIGN-IN (sc-17590): add with an empty token to a server that asks people to sign in answers " +
|
|
2285
|
+
"auth_kind 'oauth', status 'needs_sign_in'. Offer a Sign in action on an 'oauth' item whose status is " +
|
|
2286
|
+
"not 'connected', and ONLY when `connections.signIn` is a function (the host runs the sign-in; it is " +
|
|
2287
|
+
"absent on the studio canvas and on older hosts, so never show a dead button). signIn(id) resolves to " +
|
|
2288
|
+
"the connected item or rejects AgentError: SIGN_IN_CANCELLED, SIGN_IN_FAILED, CONFIRM_INVALID, " +
|
|
2289
|
+
"NOT_A_SIGN_IN_SERVER, SERVER_UNREACHABLE, RATE_LIMITED. On web the page leaves for the sign-in and " +
|
|
2290
|
+
"the call never settles; when the page loads again `connections.signInResult` is " +
|
|
2291
|
+
"{ connection, error } for that sign-in (null otherwise): show the outcome from it. " +
|
|
2284
2292
|
"A turn that used one of them carries an activity entry { tool: 'mcp', ok, server } " +
|
|
2285
2293
|
"naming the server, never a table: show it as 'Used <server>'. " +
|
|
2286
2294
|
"Take the token in a secure input, confirm a removal in your own dialog, and on a host older " +
|
|
@@ -2298,7 +2306,7 @@ const HOOKS = [
|
|
|
2298
2306
|
acceptsFiles: "boolean // asked only with { files: true }; false until the server says the agent reads files",
|
|
2299
2307
|
fileLimits: "{ types, maxFiles, maxPdfs, maxFileBytes, maxTotalBytes } | null",
|
|
2300
2308
|
connections:
|
|
2301
|
-
"{ supported, items, loading, error, add({ name, server_url, token }), test(id), remove(id), refresh() } // asked only with { connections: true }",
|
|
2309
|
+
"{ supported, items, loading, error, add({ name, server_url, token }), test(id), remove(id), refresh(), signIn?(id), signInResult } // asked only with { connections: true }",
|
|
2302
2310
|
},
|
|
2303
2311
|
requiredContextSlice: ["agents.conversations"],
|
|
2304
2312
|
scopes: ["ai.invoke:*"],
|
|
@@ -4500,7 +4508,9 @@ const WIDGET_CONTEXT_SHAPE = {
|
|
|
4500
4508
|
"{ conversations(agentId) -> { create(), list(query), remove(conversationId), " +
|
|
4501
4509
|
"messages(conversationId) -> { list(query), send({ content, file_ids? }) } }, " +
|
|
4502
4510
|
"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)
|
|
4511
|
+
"connections(agentId) -> { list(), create({ name, server_url, token }), test(id), remove(id), " +
|
|
4512
|
+
"consent(id, { return_url }), confirm(id, { confirm }), and where the host runs a sign-in signIn(id) and resumeSignIn() } " +
|
|
4513
|
+
"(sc-17588, sc-17590; optional on older hosts) }. " +
|
|
4504
4514
|
"Backs useAgent(). The workspace's agent owns the system prompt and the " +
|
|
4505
4515
|
"server owns the transcript, so `send` puts ONLY `content` and `file_ids` on the wire — " +
|
|
4506
4516
|
"a prompt, a history or a model id cannot be smuggled through. " +
|
|
@@ -7093,7 +7103,11 @@ const CONTRACT = deepFreeze({
|
|
|
7093
7103
|
// agent, with add, test, remove and refresh.
|
|
7094
7104
|
// 1.274.0: additive (sc-17683) — the web `<FilePicker>` takes dropped files
|
|
7095
7105
|
// through `onPick`; new `onDragActiveChange` prop and `FilePicker.acceptsDrop`.
|
|
7096
|
-
|
|
7106
|
+
// 1.275.0: additive (sc-17590) — `connections.signIn(id)` signs the app user
|
|
7107
|
+
// in to a server that asks for it, brokered by the host, and
|
|
7108
|
+
// `connections.signInResult` reports a web sign-in on the page's return.
|
|
7109
|
+
// Items gain status 'needs_sign_in' and auth_kind 'oauth'.
|
|
7110
|
+
version: "1.275.0",
|
|
7097
7111
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7098
7112
|
hooks: HOOKS,
|
|
7099
7113
|
primitives: PRIMITIVES,
|
package/dist/hooks.js
CHANGED
|
@@ -3675,6 +3675,7 @@ const NO_CONNECTIONS = Object.freeze({
|
|
|
3675
3675
|
items: Object.freeze([]),
|
|
3676
3676
|
loading: false,
|
|
3677
3677
|
error: null,
|
|
3678
|
+
signInResult: null,
|
|
3678
3679
|
});
|
|
3679
3680
|
|
|
3680
3681
|
function toAgentError(err) {
|
|
@@ -3745,6 +3746,10 @@ function toAgentError(err) {
|
|
|
3745
3746
|
* offers them, and stays false when it refuses (a studio preview, a signed-out
|
|
3746
3747
|
* visitor, or an agent the author has not opened to them).
|
|
3747
3748
|
*
|
|
3749
|
+
* sc-17590 — `connections.signIn(id)` signs the person in to a server that
|
|
3750
|
+
* asks for it, run by the host; absent where the host cannot. On web the tab
|
|
3751
|
+
* leaves and the outcome arrives in `connections.signInResult` on its return.
|
|
3752
|
+
*
|
|
3748
3753
|
* Routes through the injected `@colixsystems/agents-client` at `ctx.agents`,
|
|
3749
3754
|
* so the Player and the Expo export resolve against the identical client.
|
|
3750
3755
|
*/
|
|
@@ -4047,16 +4052,26 @@ export function useAgent(agentRef, options) {
|
|
|
4047
4052
|
? { ...prior, loading: true, error: null }
|
|
4048
4053
|
: { ...NO_CONNECTIONS, agentId: handle.agentId, loading: true },
|
|
4049
4054
|
);
|
|
4055
|
+
// sc-17590 — a sign-in this page came back from is finished before the
|
|
4056
|
+
// list, so the list already shows its outcome. The host answers it once.
|
|
4057
|
+
let returned = null;
|
|
4058
|
+
if (typeof handle.api.resumeSignIn === "function") {
|
|
4059
|
+
const back = await handle.api.resumeSignIn().catch(() => null);
|
|
4060
|
+
if (back) returned = { connection: back.connection || null, error: back.error ? toAgentError(back.error) : null };
|
|
4061
|
+
}
|
|
4062
|
+
const keepResult = (prior) =>
|
|
4063
|
+
(prior.agentId === handle.agentId && prior.signInResult) || returned;
|
|
4050
4064
|
try {
|
|
4051
4065
|
const listed = await handle.api.list();
|
|
4052
4066
|
if (connectionsGenerationRef.current !== generation) return;
|
|
4053
|
-
setConnectionState({
|
|
4067
|
+
setConnectionState((prior) => ({
|
|
4054
4068
|
agentId: handle.agentId,
|
|
4055
4069
|
supported: true,
|
|
4056
4070
|
items: listed && Array.isArray(listed.data) ? listed.data : [],
|
|
4057
4071
|
loading: false,
|
|
4058
4072
|
error: null,
|
|
4059
|
-
|
|
4073
|
+
signInResult: keepResult(prior),
|
|
4074
|
+
}));
|
|
4060
4075
|
} catch (err) {
|
|
4061
4076
|
if (connectionsGenerationRef.current !== generation) return;
|
|
4062
4077
|
const e = toAgentError(err);
|
|
@@ -4070,6 +4085,7 @@ export function useAgent(agentRef, options) {
|
|
|
4070
4085
|
items: refused ? [] : prior.items,
|
|
4071
4086
|
loading: false,
|
|
4072
4087
|
error: e,
|
|
4088
|
+
signInResult: keepResult(prior),
|
|
4073
4089
|
}));
|
|
4074
4090
|
}
|
|
4075
4091
|
}, [connectionsApi]);
|
|
@@ -4109,11 +4125,20 @@ export function useAgent(agentRef, options) {
|
|
|
4109
4125
|
wantsConnections && available && Boolean(ctx.agents) && typeof ctx.agents.connections === "function";
|
|
4110
4126
|
const current =
|
|
4111
4127
|
connectionState.agentId === agentRef ? connectionState : { ...NO_CONNECTIONS, loading: listing };
|
|
4128
|
+
// sc-17590 — only a host that can run the sign-in round trip offers it.
|
|
4129
|
+
let hostSignsIn;
|
|
4130
|
+
try {
|
|
4131
|
+
hostSignsIn = listing && Boolean(agentRef) && typeof ctx.agents.connections(agentRef).signIn === "function";
|
|
4132
|
+
} catch {
|
|
4133
|
+
hostSignsIn = false;
|
|
4134
|
+
}
|
|
4135
|
+
const replaceItem = (items, updated) => items.map((c) => (updated && c.id === updated.id ? updated : c));
|
|
4112
4136
|
return {
|
|
4113
4137
|
supported: available && current.supported,
|
|
4114
4138
|
items: current.items,
|
|
4115
4139
|
loading: current.loading,
|
|
4116
4140
|
error: current.error,
|
|
4141
|
+
signInResult: current.signInResult,
|
|
4117
4142
|
// The token is write-only: it is sent once and never read back.
|
|
4118
4143
|
add: (body) =>
|
|
4119
4144
|
changeConnections(
|
|
@@ -4125,11 +4150,19 @@ export function useAgent(agentRef, options) {
|
|
|
4125
4150
|
}),
|
|
4126
4151
|
(items, created) => (created ? items.concat(created) : items),
|
|
4127
4152
|
),
|
|
4128
|
-
test: (id) =>
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4153
|
+
test: (id) => changeConnections((api) => api.test(id), replaceItem),
|
|
4154
|
+
// On web the tab leaves for the sign-in and this never settles; the
|
|
4155
|
+
// page that loads on the way back reports it in `signInResult`.
|
|
4156
|
+
...(hostSignsIn
|
|
4157
|
+
? {
|
|
4158
|
+
signIn: (id) =>
|
|
4159
|
+
changeConnections((api) => api.signIn(id), replaceItem).catch((err) => {
|
|
4160
|
+
// A refused sign-in may have changed the row's status.
|
|
4161
|
+
refreshConnections();
|
|
4162
|
+
throw err;
|
|
4163
|
+
}),
|
|
4164
|
+
}
|
|
4165
|
+
: {}),
|
|
4133
4166
|
remove: (id) =>
|
|
4134
4167
|
changeConnections(
|
|
4135
4168
|
(api) => api.remove(id),
|
package/dist/index.d.ts
CHANGED
|
@@ -924,7 +924,7 @@ 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. */
|
|
927
|
+
/** sc-17588 — the app user's own MCP servers; optional on older hosts. sc-17590 adds signIn where the host runs it. */
|
|
928
928
|
connections?(agentId: string): unknown;
|
|
929
929
|
};
|
|
930
930
|
/** sc-13843 — injected @colixsystems/actions-client backing useAction(). */
|
|
@@ -2212,12 +2212,25 @@ export interface AgentConnections {
|
|
|
2212
2212
|
loading: boolean;
|
|
2213
2213
|
/** The last failed list; `code` says why. */
|
|
2214
2214
|
error: AgentError | null;
|
|
2215
|
-
/**
|
|
2215
|
+
/**
|
|
2216
|
+
* Rejects AgentError: TOO_MANY_CONNECTIONS, NAME_IN_USE, INVALID_SERVER_URL, SERVER_UNREACHABLE,
|
|
2217
|
+
* NOT_AN_MCP_SERVER, SERVER_REQUIRES_SIGN_IN, SIGN_IN_NOT_SUPPORTED. An empty token to a server that
|
|
2218
|
+
* asks people to sign in answers an `oauth` item with status `needs_sign_in`.
|
|
2219
|
+
*/
|
|
2216
2220
|
add(body: { name: string; server_url: string; token: string }): Promise<AgentMcpConnection>;
|
|
2217
2221
|
/** Reconnects and re-reads the server's tools. */
|
|
2218
2222
|
test(id: string): Promise<AgentMcpConnection>;
|
|
2219
2223
|
remove(id: string): Promise<void>;
|
|
2220
2224
|
refresh(): Promise<void>;
|
|
2225
|
+
/**
|
|
2226
|
+
* sc-17590 — signs the person in to an `oauth` server, run by the host. Absent where the host
|
|
2227
|
+
* cannot (the studio canvas, older hosts): offer no Sign in action then. Rejects AgentError:
|
|
2228
|
+
* SIGN_IN_CANCELLED, SIGN_IN_FAILED, CONFIRM_INVALID, NOT_A_SIGN_IN_SERVER, SERVER_UNREACHABLE,
|
|
2229
|
+
* RATE_LIMITED. On web the page leaves for the sign-in and the promise never settles.
|
|
2230
|
+
*/
|
|
2231
|
+
signIn?(id: string): Promise<AgentMcpConnection>;
|
|
2232
|
+
/** sc-17590 — the web sign-in this page load returned from, once; null otherwise. */
|
|
2233
|
+
signInResult: { connection: AgentMcpConnection | null; error: AgentError | null } | null;
|
|
2221
2234
|
}
|
|
2222
2235
|
|
|
2223
2236
|
/**
|
package/dist/linter.cjs
CHANGED
|
@@ -1803,6 +1803,9 @@ function _writeGatedOnUserRules(source) {
|
|
|
1803
1803
|
if (!call) return [];
|
|
1804
1804
|
if (/\buseCanWrite\s*\(/.test(code)) return [];
|
|
1805
1805
|
if (_IDENTITY_GUARD_RES.some((re) => re.test(code))) return [];
|
|
1806
|
+
// Story 17720 — a widget that only edits existing rows gates each on its
|
|
1807
|
+
// `_capabilities`, which is false for a visitor too; row-action-not-gated polices it.
|
|
1808
|
+
if (/\b_capabilities\b/.test(code) && _mutationCallSites(code, "create")?.length === 0) return [];
|
|
1806
1809
|
const line = code.slice(0, call.index).split(/\r?\n/).length;
|
|
1807
1810
|
return [
|
|
1808
1811
|
{
|
|
@@ -1811,9 +1814,9 @@ function _writeGatedOnUserRules(source) {
|
|
|
1811
1814
|
// Kept under ~210 chars: a finding is truncated at 300 downstream, and
|
|
1812
1815
|
// the fix instruction is the half worth keeping.
|
|
1813
1816
|
label:
|
|
1814
|
-
`writes
|
|
1815
|
-
|
|
1816
|
-
`
|
|
1817
|
+
`writes but never checks who may write - gate a create on ` +
|
|
1818
|
+
`useCanWrite(tableId) (useUser() if it needs sign-in) and an existing ` +
|
|
1819
|
+
`row's edit on row._capabilities, never a live-but-doomed control.`,
|
|
1817
1820
|
line,
|
|
1818
1821
|
snippet: (source.split(/\r?\n/)[line - 1] || "").trim().slice(0, 200),
|
|
1819
1822
|
},
|
|
@@ -2251,21 +2254,88 @@ function _rowActionGatingRules(source) {
|
|
|
2251
2254
|
if (!call) return [];
|
|
2252
2255
|
if (/\b_capabilities\b/.test(code)) return [];
|
|
2253
2256
|
if (/\buseCanWrite\s*\([^)]*\brecordId\b/.test(code)) return [];
|
|
2257
|
+
if (_rowEditsTargetOnlyCreatedRows(code)) return [];
|
|
2254
2258
|
const line = code.slice(0, call.index).split(/\r?\n/).length;
|
|
2255
2259
|
return [
|
|
2256
2260
|
{
|
|
2257
2261
|
rule: "row-action-not-gated",
|
|
2258
2262
|
severity: "warning",
|
|
2259
2263
|
label:
|
|
2260
|
-
`edits or deletes
|
|
2261
|
-
`with { includeCapabilities: true }
|
|
2262
|
-
`row._capabilities.can_write / can_delete
|
|
2264
|
+
`edits or deletes an existing row without checking its permission - read ` +
|
|
2265
|
+
`it with { includeCapabilities: true } (useDatastoreQuery or useDatastoreRecord) ` +
|
|
2266
|
+
`and offer the edit only when row._capabilities.can_write / can_delete.`,
|
|
2263
2267
|
line,
|
|
2264
2268
|
snippet: (source.split(/\r?\n/)[line - 1] || "").trim().slice(0, 200),
|
|
2265
2269
|
},
|
|
2266
2270
|
];
|
|
2267
2271
|
}
|
|
2268
2272
|
|
|
2273
|
+
/**
|
|
2274
|
+
* Story 17720 — every update/delete targets `<name>.id` of a row the widget's
|
|
2275
|
+
* own create() returned, as the record-file attach flow does. That row carries
|
|
2276
|
+
* no `_capabilities`, and whether its creator may edit it is the table ACL's
|
|
2277
|
+
* job, so no per-row gate exists to ask for.
|
|
2278
|
+
*/
|
|
2279
|
+
function _rowEditsTargetOnlyCreatedRows(code) {
|
|
2280
|
+
const [updates, deletes, creates] = ["update", "delete", "create"].map((verb) => _mutationCallSites(code, verb));
|
|
2281
|
+
if (!updates || !deletes || !creates) return false;
|
|
2282
|
+
const sites = [...updates, ...deletes];
|
|
2283
|
+
if (sites.length === 0) return false;
|
|
2284
|
+
const created = new Set();
|
|
2285
|
+
for (const site of creates) {
|
|
2286
|
+
const before = code.slice(Math.max(0, site - 200), site);
|
|
2287
|
+
const bound = /(?<![\w$.])([A-Za-z_$][\w$]*)\s*=\s*await\s+(?:[\w$]+\s*\.\s*)?[\w$]+\s*$/.exec(before);
|
|
2288
|
+
if (bound && _boundOnlyByCreate(code, bound[1])) created.add(bound[1]);
|
|
2289
|
+
}
|
|
2290
|
+
return sites.every((open) => {
|
|
2291
|
+
const target = /^\s*([A-Za-z_$][\w$]*)\s*\??\.\s*id\s*[,)]/.exec(code.slice(open + 1));
|
|
2292
|
+
return Boolean(target) && created.has(target[1]);
|
|
2293
|
+
});
|
|
2294
|
+
}
|
|
2295
|
+
|
|
2296
|
+
// One declaration, assigned only by that create (a `let row; try { row =
|
|
2297
|
+
// await create(…) }` too). Any other binding of the name, such as a
|
|
2298
|
+
// `.map((row) =>` parameter or a destructure, could be a listed row.
|
|
2299
|
+
function _boundOnlyByCreate(code, name) {
|
|
2300
|
+
const n = name.replace(/\$/g, "\\$");
|
|
2301
|
+
const count = (re) => (code.match(re) || []).length;
|
|
2302
|
+
const emptyDeclaration = new RegExp(`\\blet\\s+${n}\\s*(?:=\\s*(?:null|undefined)\\s*)?[;,]`);
|
|
2303
|
+
return (
|
|
2304
|
+
count(new RegExp(`\\b(?:const|let|var)\\s+${n}(?![\\w$])`, "g")) === 1 &&
|
|
2305
|
+
count(new RegExp(`(?<![\\w$.])${n}\\s*=(?![=>])`, "g")) ===
|
|
2306
|
+
1 + count(new RegExp(`\\blet\\s+${n}\\s*=\\s*(?:null|undefined)\\b`, "g")) &&
|
|
2307
|
+
(count(new RegExp(`\\bconst\\s+${n}\\s*=\\s*await\\b`, "g")) === 1 || emptyDeclaration.test(code)) &&
|
|
2308
|
+
count(new RegExp(`(?<![\\w$.])${n}\\s*(?:=>|[-+*/%&|^?]{1,3}=)`, "g")) === 0 &&
|
|
2309
|
+
count(new RegExp(`\\bfor\\s*\\(\\s*${n}\\s+(?:of|in)\\b`, "g")) === 0 &&
|
|
2310
|
+
count(new RegExp(`[({\\[,:]\\s*(?:\\.\\.\\.)?${n}\\s*[,)}\\]]`, "g")) === 0
|
|
2311
|
+
);
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
/**
|
|
2315
|
+
* Index of the `(` of each call the widget makes to `verb` on a
|
|
2316
|
+
* useDatastoreMutation() result: `verb(` through its destructured local, or
|
|
2317
|
+
* `name.verb(` on a named mutation object. Null when a local cannot be read.
|
|
2318
|
+
*/
|
|
2319
|
+
function _mutationCallSites(code, verb) {
|
|
2320
|
+
const callees = [];
|
|
2321
|
+
for (const call of _mutationHookCalls(code)) {
|
|
2322
|
+
if (!call.destructured) {
|
|
2323
|
+
callees.push(`(?<![\\w$])${call.name.replace(/\$/g, "\\$")}\\s*\\.\\s*${verb}`);
|
|
2324
|
+
continue;
|
|
2325
|
+
}
|
|
2326
|
+
for (const entry of call.destructured.split(",")) {
|
|
2327
|
+
const [key, local = key] = entry.split(":").map((part) => part.trim());
|
|
2328
|
+
if (key !== verb) continue;
|
|
2329
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(local)) return null;
|
|
2330
|
+
callees.push(`(?<![\\w$.])${local.replace(/\$/g, "\\$")}`);
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
if (callees.length === 0) return [];
|
|
2334
|
+
return [...code.matchAll(new RegExp(`(?:${callees.join("|")})\\s*\\(`, "g"))].map(
|
|
2335
|
+
(m) => m.index + m[0].length - 1,
|
|
2336
|
+
);
|
|
2337
|
+
}
|
|
2338
|
+
|
|
2269
2339
|
// The useDatastoreMutation() call whose update or delete the widget uses,
|
|
2270
2340
|
// either as `m.update(` / `m.delete(` or destructured `{ update, delete }`.
|
|
2271
2341
|
function _rowMutationCall(code) {
|
|
@@ -2314,7 +2384,9 @@ function _mutationHookCalls(code) {
|
|
|
2314
2384
|
tails.set(close, _MUTATION_TAIL_RE.test(code) ? _MUTATION_TAIL_RE.lastIndex : -1);
|
|
2315
2385
|
}
|
|
2316
2386
|
if (tails.get(close) !== -1) {
|
|
2317
|
-
|
|
2387
|
+
// The run from an enclosing body brace holds its statements too.
|
|
2388
|
+
const open = code.lastIndexOf("{", close);
|
|
2389
|
+
destructured = { index: open, destructured: code.slice(open + 1, close) };
|
|
2318
2390
|
break;
|
|
2319
2391
|
}
|
|
2320
2392
|
}
|
package/dist/linter.js
CHANGED
|
@@ -1798,6 +1798,9 @@ function _writeGatedOnUserRules(source) {
|
|
|
1798
1798
|
if (!call) return [];
|
|
1799
1799
|
if (/\buseCanWrite\s*\(/.test(code)) return [];
|
|
1800
1800
|
if (_IDENTITY_GUARD_RES.some((re) => re.test(code))) return [];
|
|
1801
|
+
// Story 17720 — a widget that only edits existing rows gates each on its
|
|
1802
|
+
// `_capabilities`, which is false for a visitor too; row-action-not-gated polices it.
|
|
1803
|
+
if (/\b_capabilities\b/.test(code) && _mutationCallSites(code, "create")?.length === 0) return [];
|
|
1801
1804
|
const line = code.slice(0, call.index).split(/\r?\n/).length;
|
|
1802
1805
|
return [
|
|
1803
1806
|
{
|
|
@@ -1806,9 +1809,9 @@ function _writeGatedOnUserRules(source) {
|
|
|
1806
1809
|
// Kept under ~210 chars: a finding is truncated at 300 downstream, and
|
|
1807
1810
|
// the fix instruction is the half worth keeping.
|
|
1808
1811
|
label:
|
|
1809
|
-
`writes
|
|
1810
|
-
|
|
1811
|
-
`
|
|
1812
|
+
`writes but never checks who may write - gate a create on ` +
|
|
1813
|
+
`useCanWrite(tableId) (useUser() if it needs sign-in) and an existing ` +
|
|
1814
|
+
`row's edit on row._capabilities, never a live-but-doomed control.`,
|
|
1812
1815
|
line,
|
|
1813
1816
|
snippet: (source.split(/\r?\n/)[line - 1] || "").trim().slice(0, 200),
|
|
1814
1817
|
},
|
|
@@ -2246,21 +2249,88 @@ function _rowActionGatingRules(source) {
|
|
|
2246
2249
|
if (!call) return [];
|
|
2247
2250
|
if (/\b_capabilities\b/.test(code)) return [];
|
|
2248
2251
|
if (/\buseCanWrite\s*\([^)]*\brecordId\b/.test(code)) return [];
|
|
2252
|
+
if (_rowEditsTargetOnlyCreatedRows(code)) return [];
|
|
2249
2253
|
const line = code.slice(0, call.index).split(/\r?\n/).length;
|
|
2250
2254
|
return [
|
|
2251
2255
|
{
|
|
2252
2256
|
rule: "row-action-not-gated",
|
|
2253
2257
|
severity: "warning",
|
|
2254
2258
|
label:
|
|
2255
|
-
`edits or deletes
|
|
2256
|
-
`with { includeCapabilities: true }
|
|
2257
|
-
`row._capabilities.can_write / can_delete
|
|
2259
|
+
`edits or deletes an existing row without checking its permission - read ` +
|
|
2260
|
+
`it with { includeCapabilities: true } (useDatastoreQuery or useDatastoreRecord) ` +
|
|
2261
|
+
`and offer the edit only when row._capabilities.can_write / can_delete.`,
|
|
2258
2262
|
line,
|
|
2259
2263
|
snippet: (source.split(/\r?\n/)[line - 1] || "").trim().slice(0, 200),
|
|
2260
2264
|
},
|
|
2261
2265
|
];
|
|
2262
2266
|
}
|
|
2263
2267
|
|
|
2268
|
+
/**
|
|
2269
|
+
* Story 17720 — every update/delete targets `<name>.id` of a row the widget's
|
|
2270
|
+
* own create() returned, as the record-file attach flow does. That row carries
|
|
2271
|
+
* no `_capabilities`, and whether its creator may edit it is the table ACL's
|
|
2272
|
+
* job, so no per-row gate exists to ask for.
|
|
2273
|
+
*/
|
|
2274
|
+
function _rowEditsTargetOnlyCreatedRows(code) {
|
|
2275
|
+
const [updates, deletes, creates] = ["update", "delete", "create"].map((verb) => _mutationCallSites(code, verb));
|
|
2276
|
+
if (!updates || !deletes || !creates) return false;
|
|
2277
|
+
const sites = [...updates, ...deletes];
|
|
2278
|
+
if (sites.length === 0) return false;
|
|
2279
|
+
const created = new Set();
|
|
2280
|
+
for (const site of creates) {
|
|
2281
|
+
const before = code.slice(Math.max(0, site - 200), site);
|
|
2282
|
+
const bound = /(?<![\w$.])([A-Za-z_$][\w$]*)\s*=\s*await\s+(?:[\w$]+\s*\.\s*)?[\w$]+\s*$/.exec(before);
|
|
2283
|
+
if (bound && _boundOnlyByCreate(code, bound[1])) created.add(bound[1]);
|
|
2284
|
+
}
|
|
2285
|
+
return sites.every((open) => {
|
|
2286
|
+
const target = /^\s*([A-Za-z_$][\w$]*)\s*\??\.\s*id\s*[,)]/.exec(code.slice(open + 1));
|
|
2287
|
+
return Boolean(target) && created.has(target[1]);
|
|
2288
|
+
});
|
|
2289
|
+
}
|
|
2290
|
+
|
|
2291
|
+
// One declaration, assigned only by that create (a `let row; try { row =
|
|
2292
|
+
// await create(…) }` too). Any other binding of the name, such as a
|
|
2293
|
+
// `.map((row) =>` parameter or a destructure, could be a listed row.
|
|
2294
|
+
function _boundOnlyByCreate(code, name) {
|
|
2295
|
+
const n = name.replace(/\$/g, "\\$");
|
|
2296
|
+
const count = (re) => (code.match(re) || []).length;
|
|
2297
|
+
const emptyDeclaration = new RegExp(`\\blet\\s+${n}\\s*(?:=\\s*(?:null|undefined)\\s*)?[;,]`);
|
|
2298
|
+
return (
|
|
2299
|
+
count(new RegExp(`\\b(?:const|let|var)\\s+${n}(?![\\w$])`, "g")) === 1 &&
|
|
2300
|
+
count(new RegExp(`(?<![\\w$.])${n}\\s*=(?![=>])`, "g")) ===
|
|
2301
|
+
1 + count(new RegExp(`\\blet\\s+${n}\\s*=\\s*(?:null|undefined)\\b`, "g")) &&
|
|
2302
|
+
(count(new RegExp(`\\bconst\\s+${n}\\s*=\\s*await\\b`, "g")) === 1 || emptyDeclaration.test(code)) &&
|
|
2303
|
+
count(new RegExp(`(?<![\\w$.])${n}\\s*(?:=>|[-+*/%&|^?]{1,3}=)`, "g")) === 0 &&
|
|
2304
|
+
count(new RegExp(`\\bfor\\s*\\(\\s*${n}\\s+(?:of|in)\\b`, "g")) === 0 &&
|
|
2305
|
+
count(new RegExp(`[({\\[,:]\\s*(?:\\.\\.\\.)?${n}\\s*[,)}\\]]`, "g")) === 0
|
|
2306
|
+
);
|
|
2307
|
+
}
|
|
2308
|
+
|
|
2309
|
+
/**
|
|
2310
|
+
* Index of the `(` of each call the widget makes to `verb` on a
|
|
2311
|
+
* useDatastoreMutation() result: `verb(` through its destructured local, or
|
|
2312
|
+
* `name.verb(` on a named mutation object. Null when a local cannot be read.
|
|
2313
|
+
*/
|
|
2314
|
+
function _mutationCallSites(code, verb) {
|
|
2315
|
+
const callees = [];
|
|
2316
|
+
for (const call of _mutationHookCalls(code)) {
|
|
2317
|
+
if (!call.destructured) {
|
|
2318
|
+
callees.push(`(?<![\\w$])${call.name.replace(/\$/g, "\\$")}\\s*\\.\\s*${verb}`);
|
|
2319
|
+
continue;
|
|
2320
|
+
}
|
|
2321
|
+
for (const entry of call.destructured.split(",")) {
|
|
2322
|
+
const [key, local = key] = entry.split(":").map((part) => part.trim());
|
|
2323
|
+
if (key !== verb) continue;
|
|
2324
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(local)) return null;
|
|
2325
|
+
callees.push(`(?<![\\w$.])${local.replace(/\$/g, "\\$")}`);
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
if (callees.length === 0) return [];
|
|
2329
|
+
return [...code.matchAll(new RegExp(`(?:${callees.join("|")})\\s*\\(`, "g"))].map(
|
|
2330
|
+
(m) => m.index + m[0].length - 1,
|
|
2331
|
+
);
|
|
2332
|
+
}
|
|
2333
|
+
|
|
2264
2334
|
// The useDatastoreMutation() call whose update or delete the widget uses,
|
|
2265
2335
|
// either as `m.update(` / `m.delete(` or destructured `{ update, delete }`.
|
|
2266
2336
|
function _rowMutationCall(code) {
|
|
@@ -2309,7 +2379,9 @@ function _mutationHookCalls(code) {
|
|
|
2309
2379
|
tails.set(close, _MUTATION_TAIL_RE.test(code) ? _MUTATION_TAIL_RE.lastIndex : -1);
|
|
2310
2380
|
}
|
|
2311
2381
|
if (tails.get(close) !== -1) {
|
|
2312
|
-
|
|
2382
|
+
// The run from an enclosing body brace holds its statements too.
|
|
2383
|
+
const open = code.lastIndexOf("{", close);
|
|
2384
|
+
destructured = { index: open, destructured: code.slice(open + 1, close) };
|
|
2313
2385
|
break;
|
|
2314
2386
|
}
|
|
2315
2387
|
}
|
package/package.json
CHANGED
package/src/contract.js
CHANGED
|
@@ -2274,13 +2274,21 @@ const HOOKS = [
|
|
|
2274
2274
|
"CONNECTED TOOLS (sc-17588): call useAgent(agentRef, { connections: true }) and " +
|
|
2275
2275
|
"`connections` lists the signed-in app user's OWN MCP servers for this agent: " +
|
|
2276
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, " +
|
|
2277
|
+
"Each item is { id, name, server_url, auth_kind ('bearer' | 'oauth'), status ('connected' | 'error' | 'needs_sign_in'), last_error_code, " +
|
|
2278
2278
|
"tool_count, tools: [{ name, description }], tools_fetched_at, created_at }; the token is never returned. " +
|
|
2279
2279
|
"Offer the control ONLY while `supported` is true: it is false until the server answers, and stays " +
|
|
2280
2280
|
"false on a 403 — APP_USER_SESSION_REQUIRED (the studio canvas, a preview or a signed-out visitor) or " +
|
|
2281
2281
|
"TOOLS_NOT_ENABLED (the author has not let app users connect tools to this agent). add, test and " +
|
|
2282
2282
|
"remove reject with AgentError: TOO_MANY_CONNECTIONS and NAME_IN_USE (409), INVALID_SERVER_URL, " +
|
|
2283
|
-
"SERVER_UNREACHABLE, NOT_AN_MCP_SERVER and
|
|
2283
|
+
"SERVER_UNREACHABLE, NOT_AN_MCP_SERVER, SERVER_REQUIRES_SIGN_IN and SIGN_IN_NOT_SUPPORTED (422). " +
|
|
2284
|
+
"SIGN-IN (sc-17590): add with an empty token to a server that asks people to sign in answers " +
|
|
2285
|
+
"auth_kind 'oauth', status 'needs_sign_in'. Offer a Sign in action on an 'oauth' item whose status is " +
|
|
2286
|
+
"not 'connected', and ONLY when `connections.signIn` is a function (the host runs the sign-in; it is " +
|
|
2287
|
+
"absent on the studio canvas and on older hosts, so never show a dead button). signIn(id) resolves to " +
|
|
2288
|
+
"the connected item or rejects AgentError: SIGN_IN_CANCELLED, SIGN_IN_FAILED, CONFIRM_INVALID, " +
|
|
2289
|
+
"NOT_A_SIGN_IN_SERVER, SERVER_UNREACHABLE, RATE_LIMITED. On web the page leaves for the sign-in and " +
|
|
2290
|
+
"the call never settles; when the page loads again `connections.signInResult` is " +
|
|
2291
|
+
"{ connection, error } for that sign-in (null otherwise): show the outcome from it. " +
|
|
2284
2292
|
"A turn that used one of them carries an activity entry { tool: 'mcp', ok, server } " +
|
|
2285
2293
|
"naming the server, never a table: show it as 'Used <server>'. " +
|
|
2286
2294
|
"Take the token in a secure input, confirm a removal in your own dialog, and on a host older " +
|
|
@@ -2298,7 +2306,7 @@ const HOOKS = [
|
|
|
2298
2306
|
acceptsFiles: "boolean // asked only with { files: true }; false until the server says the agent reads files",
|
|
2299
2307
|
fileLimits: "{ types, maxFiles, maxPdfs, maxFileBytes, maxTotalBytes } | null",
|
|
2300
2308
|
connections:
|
|
2301
|
-
"{ supported, items, loading, error, add({ name, server_url, token }), test(id), remove(id), refresh() } // asked only with { connections: true }",
|
|
2309
|
+
"{ supported, items, loading, error, add({ name, server_url, token }), test(id), remove(id), refresh(), signIn?(id), signInResult } // asked only with { connections: true }",
|
|
2302
2310
|
},
|
|
2303
2311
|
requiredContextSlice: ["agents.conversations"],
|
|
2304
2312
|
scopes: ["ai.invoke:*"],
|
|
@@ -4500,7 +4508,9 @@ const WIDGET_CONTEXT_SHAPE = {
|
|
|
4500
4508
|
"{ conversations(agentId) -> { create(), list(query), remove(conversationId), " +
|
|
4501
4509
|
"messages(conversationId) -> { list(query), send({ content, file_ids? }) } }, " +
|
|
4502
4510
|
"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)
|
|
4511
|
+
"connections(agentId) -> { list(), create({ name, server_url, token }), test(id), remove(id), " +
|
|
4512
|
+
"consent(id, { return_url }), confirm(id, { confirm }), and where the host runs a sign-in signIn(id) and resumeSignIn() } " +
|
|
4513
|
+
"(sc-17588, sc-17590; optional on older hosts) }. " +
|
|
4504
4514
|
"Backs useAgent(). The workspace's agent owns the system prompt and the " +
|
|
4505
4515
|
"server owns the transcript, so `send` puts ONLY `content` and `file_ids` on the wire — " +
|
|
4506
4516
|
"a prompt, a history or a model id cannot be smuggled through. " +
|
|
@@ -7093,7 +7103,11 @@ const CONTRACT = deepFreeze({
|
|
|
7093
7103
|
// agent, with add, test, remove and refresh.
|
|
7094
7104
|
// 1.274.0: additive (sc-17683) — the web `<FilePicker>` takes dropped files
|
|
7095
7105
|
// through `onPick`; new `onDragActiveChange` prop and `FilePicker.acceptsDrop`.
|
|
7096
|
-
|
|
7106
|
+
// 1.275.0: additive (sc-17590) — `connections.signIn(id)` signs the app user
|
|
7107
|
+
// in to a server that asks for it, brokered by the host, and
|
|
7108
|
+
// `connections.signInResult` reports a web sign-in on the page's return.
|
|
7109
|
+
// Items gain status 'needs_sign_in' and auth_kind 'oauth'.
|
|
7110
|
+
version: "1.275.0",
|
|
7097
7111
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7098
7112
|
hooks: HOOKS,
|
|
7099
7113
|
primitives: PRIMITIVES,
|