@colixsystems/widget-sdk 0.333.0 → 0.335.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 +19 -1
- package/dist/agent-connection.d.ts +17 -0
- package/dist/contract.cjs +27 -4
- package/dist/contract.js +27 -4
- package/dist/hooks.js +136 -6
- package/dist/index.d.ts +41 -2
- package/dist/linter.cjs +61 -22
- package/dist/linter.js +61 -22
- package/package.json +1 -1
- package/src/contract.js +27 -4
package/README.md
CHANGED
|
@@ -91,7 +91,25 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
91
91
|
|
|
92
92
|
## Status
|
|
93
93
|
|
|
94
|
-
`v0.
|
|
94
|
+
`v0.335.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.335.0 (contract 1.273.0)
|
|
97
|
+
|
|
98
|
+
**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.
|
|
99
|
+
|
|
100
|
+
```jsx
|
|
101
|
+
const { connections } = useAgent(props.agentId, { connections: true });
|
|
102
|
+
if (connections && connections.supported) {
|
|
103
|
+
// render connections.items, and an add form calling
|
|
104
|
+
// connections.add({ name, server_url, token })
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### What's new in 0.334.0 (contract 1.272.0)
|
|
109
|
+
|
|
110
|
+
**A widget that sells access plans must let a buyer cancel.** A held monthly plan renews until `useAccessPlans().cancel(planId)` stops it, so a widget that calls `purchase` but never `cancel` left its subscribers no way to stop paying. The linter now refuses it with `access-plan-cancel-missing` (an error, so it blocks the publish). For a held plan with `renews: true`, render a "Cancel renewal" control that calls `cancel(plan.id)`, and once it resolves show `access_ends_at`, the day access ends. A one-time plan never renews, so the control never shows for it. The check reads the whole file, so one component may buy and another cancel; `cancel` counts only where it is called or passed on, never in text such as "Cancel any time". A widget that hands the whole hook result to a child component (`<PlanList plans={ap} />`) is left to that child.
|
|
111
|
+
|
|
112
|
+
**A plan taken off sale stays listed to its holders.** `plans` now also holds a plan the signed-in user holds after the workspace stopped selling it, with `purchase_available: false`, so they can still see it and cancel it. Show the buy control only where `purchase_available` is true.
|
|
95
113
|
|
|
96
114
|
### What's new in 0.332.0 (contract 1.271.0)
|
|
97
115
|
|
|
@@ -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:*"],
|
|
@@ -2484,7 +2500,7 @@ const HOOKS = [
|
|
|
2484
2500
|
signature: "useAccessPlans()",
|
|
2485
2501
|
returnShape: {
|
|
2486
2502
|
plans:
|
|
2487
|
-
"Array<{ id, name, price_cents, currency, billing: \"one_time\" | \"monthly\", owned, renews, access_ends_at, purchase_available }> // owned: the user holds it; renews: a held monthly plan will charge again; access_ends_at: end of held access without a renewal (null for one-time); purchase_available: this plan can be bought here — false in an iOS/Android build for a plan the workspace does not sell in-app",
|
|
2503
|
+
"Array<{ id, name, price_cents, currency, billing: \"one_time\" | \"monthly\", owned, renews, access_ends_at, purchase_available }> // owned: the user holds it; renews: a held monthly plan will charge again; access_ends_at: end of held access without a renewal (null for one-time); purchase_available: this plan can be bought here — false in an iOS/Android build for a plan the workspace does not sell in-app, and for a plan the user holds that is no longer on sale (listed so they can still cancel it)",
|
|
2488
2504
|
loading: "boolean",
|
|
2489
2505
|
error: "PaymentError | null",
|
|
2490
2506
|
purchaseAvailable:
|
|
@@ -2492,7 +2508,7 @@ const HOOKS = [
|
|
|
2492
2508
|
purchase:
|
|
2493
2509
|
"(planId, { return_path? }?) => Promise<{ plan_id, status: \"ACTIVE\" | \"PENDING\" }> // pass ONLY the plan id; the server sets price and group; the host opens hosted Checkout on the web and the store's in-app purchase sheet in an iOS/Android build; access arrives with the payment confirmation, so refresh() a moment later",
|
|
2494
2510
|
cancel:
|
|
2495
|
-
"(planId) => Promise<{ plan_id, renews: false, access_ends_at }> // stop a renewing monthly plan; access runs to access_ends_at — offer it beside every plan with renews: true",
|
|
2511
|
+
"(planId) => Promise<{ plan_id, renews: false, access_ends_at }> // stop a renewing monthly plan; access runs to access_ends_at — offer it beside every plan with renews: true; a widget that calls purchase without it is refused (access-plan-cancel-missing)",
|
|
2496
2512
|
refresh: "() => Promise<void> // re-read after returning from Checkout",
|
|
2497
2513
|
},
|
|
2498
2514
|
requiredContextSlice: [
|
|
@@ -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. " +
|
|
@@ -7073,7 +7090,13 @@ const CONTRACT = deepFreeze({
|
|
|
7073
7090
|
// value, and an update may still change it.
|
|
7074
7091
|
// 1.271.0: additive (sc-17551) — `useDatastoreAggregate` groups by a
|
|
7075
7092
|
// relation column; new warning lint `aggregate-error-not-read`.
|
|
7076
|
-
|
|
7093
|
+
// 1.272.0: stricter lint (sc-17552) — a widget that calls
|
|
7094
|
+
// useAccessPlans().purchase without cancel is the publish-blocking
|
|
7095
|
+
// `access-plan-cancel-missing` finding.
|
|
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
|
+
version: "1.273.0",
|
|
7077
7100
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7078
7101
|
hooks: HOOKS,
|
|
7079
7102
|
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:*"],
|
|
@@ -2479,7 +2495,7 @@ const HOOKS = [
|
|
|
2479
2495
|
signature: "useAccessPlans()",
|
|
2480
2496
|
returnShape: {
|
|
2481
2497
|
plans:
|
|
2482
|
-
"Array<{ id, name, price_cents, currency, billing: \"one_time\" | \"monthly\", owned, renews, access_ends_at, purchase_available }> // owned: the user holds it; renews: a held monthly plan will charge again; access_ends_at: end of held access without a renewal (null for one-time); purchase_available: this plan can be bought here — false in an iOS/Android build for a plan the workspace does not sell in-app",
|
|
2498
|
+
"Array<{ id, name, price_cents, currency, billing: \"one_time\" | \"monthly\", owned, renews, access_ends_at, purchase_available }> // owned: the user holds it; renews: a held monthly plan will charge again; access_ends_at: end of held access without a renewal (null for one-time); purchase_available: this plan can be bought here — false in an iOS/Android build for a plan the workspace does not sell in-app, and for a plan the user holds that is no longer on sale (listed so they can still cancel it)",
|
|
2483
2499
|
loading: "boolean",
|
|
2484
2500
|
error: "PaymentError | null",
|
|
2485
2501
|
purchaseAvailable:
|
|
@@ -2487,7 +2503,7 @@ const HOOKS = [
|
|
|
2487
2503
|
purchase:
|
|
2488
2504
|
"(planId, { return_path? }?) => Promise<{ plan_id, status: \"ACTIVE\" | \"PENDING\" }> // pass ONLY the plan id; the server sets price and group; the host opens hosted Checkout on the web and the store's in-app purchase sheet in an iOS/Android build; access arrives with the payment confirmation, so refresh() a moment later",
|
|
2489
2505
|
cancel:
|
|
2490
|
-
"(planId) => Promise<{ plan_id, renews: false, access_ends_at }> // stop a renewing monthly plan; access runs to access_ends_at — offer it beside every plan with renews: true",
|
|
2506
|
+
"(planId) => Promise<{ plan_id, renews: false, access_ends_at }> // stop a renewing monthly plan; access runs to access_ends_at — offer it beside every plan with renews: true; a widget that calls purchase without it is refused (access-plan-cancel-missing)",
|
|
2491
2507
|
refresh: "() => Promise<void> // re-read after returning from Checkout",
|
|
2492
2508
|
},
|
|
2493
2509
|
requiredContextSlice: [
|
|
@@ -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. " +
|
|
@@ -7068,7 +7085,13 @@ const CONTRACT = deepFreeze({
|
|
|
7068
7085
|
// value, and an update may still change it.
|
|
7069
7086
|
// 1.271.0: additive (sc-17551) — `useDatastoreAggregate` groups by a
|
|
7070
7087
|
// relation column; new warning lint `aggregate-error-not-read`.
|
|
7071
|
-
|
|
7088
|
+
// 1.272.0: stricter lint (sc-17552) — a widget that calls
|
|
7089
|
+
// useAccessPlans().purchase without cancel is the publish-blocking
|
|
7090
|
+
// `access-plan-cancel-missing` finding.
|
|
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
|
+
version: "1.273.0",
|
|
7072
7095
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7073
7096
|
hooks: HOOKS,
|
|
7074
7097
|
primitives: PRIMITIVES,
|
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?: {
|
|
@@ -1676,7 +1678,11 @@ export interface AccessPlan {
|
|
|
1676
1678
|
renews: boolean;
|
|
1677
1679
|
/** ISO time held access ends without a renewal; null for one-time access. */
|
|
1678
1680
|
access_ends_at: string | null;
|
|
1679
|
-
/**
|
|
1681
|
+
/**
|
|
1682
|
+
* Whether this plan can be bought here: false in a store build that does not
|
|
1683
|
+
* sell it in-app, and for a plan the user holds that is no longer on sale
|
|
1684
|
+
* (listed so they can still cancel it).
|
|
1685
|
+
*/
|
|
1680
1686
|
purchase_available: boolean;
|
|
1681
1687
|
}
|
|
1682
1688
|
|
|
@@ -2129,6 +2135,8 @@ export interface AgentFileLimits {
|
|
|
2129
2135
|
export interface AgentActivity {
|
|
2130
2136
|
tool: string;
|
|
2131
2137
|
ok: boolean;
|
|
2138
|
+
/** sc-17588 — on a `tool: "mcp"` call, the person's connected server it used. */
|
|
2139
|
+
server?: string;
|
|
2132
2140
|
table?: string;
|
|
2133
2141
|
record_id?: string;
|
|
2134
2142
|
fields?: string[];
|
|
@@ -2183,6 +2191,33 @@ export interface AgentApi {
|
|
|
2183
2191
|
acceptsFiles: boolean;
|
|
2184
2192
|
/** The types and limits when `acceptsFiles`, else null. */
|
|
2185
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>;
|
|
2186
2221
|
}
|
|
2187
2222
|
|
|
2188
2223
|
/**
|
|
@@ -2198,7 +2233,11 @@ export interface AgentApi {
|
|
|
2198
2233
|
export function useAgent(
|
|
2199
2234
|
agentRef: string | null | undefined,
|
|
2200
2235
|
/** sc-16546 — `files: true` asks once (no credit spent) whether the agent reads files. */
|
|
2201
|
-
options?: {
|
|
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
|
+
},
|
|
2202
2241
|
): AgentApi;
|
|
2203
2242
|
|
|
2204
2243
|
export interface ActionApi {
|
package/dist/linter.cjs
CHANGED
|
@@ -1925,34 +1925,51 @@ function _destructuredLocals(pattern) {
|
|
|
1925
1925
|
return locals;
|
|
1926
1926
|
}
|
|
1927
1927
|
|
|
1928
|
-
//
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
const
|
|
1939
|
-
|
|
1940
|
-
|
|
1928
|
+
// What the code reads, scanned once: bare identifiers, `name.field` member
|
|
1929
|
+
// reads, names handed whole to a child (`={ap}`, `...ap`), which does the work,
|
|
1930
|
+
// and names called or passed on: JSX text ("cancel any time") is neither.
|
|
1931
|
+
function _codeReads(code) {
|
|
1932
|
+
const members = new Set();
|
|
1933
|
+
for (const m of code.matchAll(/(?<![\w$])([\w$]+)(?=\s*\??\.\s*([\w$]+))/g)) members.add(`${m[1]}.${m[2]}`);
|
|
1934
|
+
const handedOn = new Set();
|
|
1935
|
+
for (const m of code.matchAll(/=\{\s*([\w$]+)\s*\}|\.\.\.\s*([\w$]+)/g)) handedOn.add(m[1] || m[2]);
|
|
1936
|
+
const used = new Set(handedOn);
|
|
1937
|
+
// No variable-length lookbehind: masked strings are long space runs.
|
|
1938
|
+
for (const m of code.matchAll(/(?<![\w$.])([\w$]+)(?=\s*\()|[,(]\s*([\w$]+)(?=\s*[,)])/g)) used.add(m[1] || m[2]);
|
|
1939
|
+
return { words: new Set(code.match(/(?<![\w$.])[\w$]+/g)), members, handedOn, used };
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
// Each `const x = hook(` binding: its line, and which of its fields the code
|
|
1943
|
+
// reads (any read) or uses (calls or passes on). One scan per hook: a
|
|
1944
|
+
// per-binding scan was quadratic in the bindings.
|
|
1945
|
+
function _hookBindings(code, hook) {
|
|
1946
|
+
const bindings = new RegExp(String.raw`\b(?:const|let|var)\s+([\w$]+|\{[^{}]*\})\s*=\s*${hook}\s*\(`, "g");
|
|
1947
|
+
const calls = [...code.matchAll(bindings)];
|
|
1948
|
+
if (calls.length === 0) return [];
|
|
1949
|
+
// A destructure names every field; only reads elsewhere count.
|
|
1950
|
+
const { words, members, handedOn, used } = _codeReads(code.replace(bindings, (m) => " ".repeat(m.length)));
|
|
1951
|
+
const lineAt = _lineCounter(code);
|
|
1952
|
+
return calls.map((call) => {
|
|
1953
|
+
const binding = call[1];
|
|
1954
|
+
const locals = binding.startsWith("{") ? _destructuredLocals(binding) : null;
|
|
1955
|
+
const local = (field, seen) => (locals ? !!locals[field] && seen.has(locals[field]) : members.has(`${binding}.${field}`));
|
|
1956
|
+
return {
|
|
1957
|
+
line: lineAt(call.index),
|
|
1958
|
+
reads: (field) => local(field, words),
|
|
1959
|
+
uses: (field) => local(field, used),
|
|
1960
|
+
handedOn: !locals && handedOn.has(binding),
|
|
1961
|
+
};
|
|
1962
|
+
});
|
|
1941
1963
|
}
|
|
1942
1964
|
|
|
1943
1965
|
function _bankIdOrderRules(source) {
|
|
1944
1966
|
const code = _stripNonCode(source);
|
|
1967
|
+
const lines = source.split(/\r?\n/);
|
|
1945
1968
|
const findings = [];
|
|
1946
1969
|
for (const { hook, verb, sameDevice } of BANKID_ORDER_HOOKS) {
|
|
1947
|
-
const
|
|
1948
|
-
|
|
1949
|
-
// The destructure itself names every field; only reads elsewhere count.
|
|
1950
|
-
const rest = code.slice(0, call.index) + " ".repeat(call[0].length) + code.slice(call.index + call[0].length);
|
|
1951
|
-
const { read, handedOn } = _bankIdOrderReads(call[1]);
|
|
1952
|
-
const reads = (field) => !!read(field) && read(field).test(rest);
|
|
1953
|
-
if (!reads(verb) || (handedOn && handedOn.test(rest))) continue;
|
|
1970
|
+
for (const { line, reads, handedOn } of _hookBindings(code, hook)) {
|
|
1971
|
+
if (!reads(verb) || handedOn) continue;
|
|
1954
1972
|
if (reads("qr") && (!sameDevice || reads("autoStartToken"))) continue;
|
|
1955
|
-
const line = code.slice(0, call.index).split(/\r?\n/).length;
|
|
1956
1973
|
findings.push({
|
|
1957
1974
|
rule: "bankid-order-not-shown",
|
|
1958
1975
|
severity: "error",
|
|
@@ -1962,13 +1979,34 @@ function _bankIdOrderRules(source) {
|
|
|
1962
1979
|
(sameDevice ? ` and a button calling Linking.openURL(bankIdAppUrl(autoStartToken))` : "") +
|
|
1963
1980
|
`, or BankID ends it unopened.`,
|
|
1964
1981
|
line,
|
|
1965
|
-
snippet: (
|
|
1982
|
+
snippet: (lines[line - 1] || "").trim().slice(0, 200),
|
|
1966
1983
|
});
|
|
1967
1984
|
}
|
|
1968
1985
|
}
|
|
1969
1986
|
return findings;
|
|
1970
1987
|
}
|
|
1971
1988
|
|
|
1989
|
+
// sc-17552 — a plan a widget sells, its holder can stop renewing there.
|
|
1990
|
+
// One-time plans never renew, so the control never shows for them. Judged per
|
|
1991
|
+
// file: one component may buy and another cancel.
|
|
1992
|
+
function _accessPlanCancelRules(source) {
|
|
1993
|
+
const code = _stripNonCode(source);
|
|
1994
|
+
const lines = source.split(/\r?\n/);
|
|
1995
|
+
const bindings = _hookBindings(code, "useAccessPlans");
|
|
1996
|
+
if (bindings.some(({ uses, handedOn }) => uses("cancel") || handedOn)) return [];
|
|
1997
|
+
return bindings
|
|
1998
|
+
.filter(({ uses }) => uses("purchase"))
|
|
1999
|
+
.map(({ line }) => ({
|
|
2000
|
+
rule: "access-plan-cancel-missing",
|
|
2001
|
+
severity: "error",
|
|
2002
|
+
label:
|
|
2003
|
+
"useAccessPlans().purchase() sells a plan its buyer can never cancel. For a held plan with renews: true, " +
|
|
2004
|
+
"render a \"Cancel renewal\" control that calls cancel(plan.id), and show access_ends_at once it is cancelled.",
|
|
2005
|
+
line,
|
|
2006
|
+
snippet: (lines[line - 1] || "").trim().slice(0, 200),
|
|
2007
|
+
}));
|
|
2008
|
+
}
|
|
2009
|
+
|
|
1972
2010
|
// sc-16511 — soft warning, the read twin of `datastore-error-not-branched`.
|
|
1973
2011
|
// A read refused because the viewer may not see the table (a signed-out
|
|
1974
2012
|
// visitor gets NOT_FOUND, a signed-in one FORBIDDEN) never clears on a retry,
|
|
@@ -3802,6 +3840,7 @@ function lintSource(source, options) {
|
|
|
3802
3840
|
findings.push(..._readErrorHandlingRules(source));
|
|
3803
3841
|
findings.push(..._aggregateErrorRules(source));
|
|
3804
3842
|
findings.push(..._bankIdOrderRules(source));
|
|
3843
|
+
findings.push(..._accessPlanCancelRules(source));
|
|
3805
3844
|
// sc-5206 — soft warnings steering a widget toward the two new hooks.
|
|
3806
3845
|
findings.push(..._rawUseMemoIntoDatastoreQueryRules(source));
|
|
3807
3846
|
findings.push(..._handRolledWriteGateRules(source));
|
package/dist/linter.js
CHANGED
|
@@ -1920,34 +1920,51 @@ function _destructuredLocals(pattern) {
|
|
|
1920
1920
|
return locals;
|
|
1921
1921
|
}
|
|
1922
1922
|
|
|
1923
|
-
//
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
const
|
|
1934
|
-
|
|
1935
|
-
|
|
1923
|
+
// What the code reads, scanned once: bare identifiers, `name.field` member
|
|
1924
|
+
// reads, names handed whole to a child (`={ap}`, `...ap`), which does the work,
|
|
1925
|
+
// and names called or passed on: JSX text ("cancel any time") is neither.
|
|
1926
|
+
function _codeReads(code) {
|
|
1927
|
+
const members = new Set();
|
|
1928
|
+
for (const m of code.matchAll(/(?<![\w$])([\w$]+)(?=\s*\??\.\s*([\w$]+))/g)) members.add(`${m[1]}.${m[2]}`);
|
|
1929
|
+
const handedOn = new Set();
|
|
1930
|
+
for (const m of code.matchAll(/=\{\s*([\w$]+)\s*\}|\.\.\.\s*([\w$]+)/g)) handedOn.add(m[1] || m[2]);
|
|
1931
|
+
const used = new Set(handedOn);
|
|
1932
|
+
// No variable-length lookbehind: masked strings are long space runs.
|
|
1933
|
+
for (const m of code.matchAll(/(?<![\w$.])([\w$]+)(?=\s*\()|[,(]\s*([\w$]+)(?=\s*[,)])/g)) used.add(m[1] || m[2]);
|
|
1934
|
+
return { words: new Set(code.match(/(?<![\w$.])[\w$]+/g)), members, handedOn, used };
|
|
1935
|
+
}
|
|
1936
|
+
|
|
1937
|
+
// Each `const x = hook(` binding: its line, and which of its fields the code
|
|
1938
|
+
// reads (any read) or uses (calls or passes on). One scan per hook: a
|
|
1939
|
+
// per-binding scan was quadratic in the bindings.
|
|
1940
|
+
function _hookBindings(code, hook) {
|
|
1941
|
+
const bindings = new RegExp(String.raw`\b(?:const|let|var)\s+([\w$]+|\{[^{}]*\})\s*=\s*${hook}\s*\(`, "g");
|
|
1942
|
+
const calls = [...code.matchAll(bindings)];
|
|
1943
|
+
if (calls.length === 0) return [];
|
|
1944
|
+
// A destructure names every field; only reads elsewhere count.
|
|
1945
|
+
const { words, members, handedOn, used } = _codeReads(code.replace(bindings, (m) => " ".repeat(m.length)));
|
|
1946
|
+
const lineAt = _lineCounter(code);
|
|
1947
|
+
return calls.map((call) => {
|
|
1948
|
+
const binding = call[1];
|
|
1949
|
+
const locals = binding.startsWith("{") ? _destructuredLocals(binding) : null;
|
|
1950
|
+
const local = (field, seen) => (locals ? !!locals[field] && seen.has(locals[field]) : members.has(`${binding}.${field}`));
|
|
1951
|
+
return {
|
|
1952
|
+
line: lineAt(call.index),
|
|
1953
|
+
reads: (field) => local(field, words),
|
|
1954
|
+
uses: (field) => local(field, used),
|
|
1955
|
+
handedOn: !locals && handedOn.has(binding),
|
|
1956
|
+
};
|
|
1957
|
+
});
|
|
1936
1958
|
}
|
|
1937
1959
|
|
|
1938
1960
|
function _bankIdOrderRules(source) {
|
|
1939
1961
|
const code = _stripNonCode(source);
|
|
1962
|
+
const lines = source.split(/\r?\n/);
|
|
1940
1963
|
const findings = [];
|
|
1941
1964
|
for (const { hook, verb, sameDevice } of BANKID_ORDER_HOOKS) {
|
|
1942
|
-
const
|
|
1943
|
-
|
|
1944
|
-
// The destructure itself names every field; only reads elsewhere count.
|
|
1945
|
-
const rest = code.slice(0, call.index) + " ".repeat(call[0].length) + code.slice(call.index + call[0].length);
|
|
1946
|
-
const { read, handedOn } = _bankIdOrderReads(call[1]);
|
|
1947
|
-
const reads = (field) => !!read(field) && read(field).test(rest);
|
|
1948
|
-
if (!reads(verb) || (handedOn && handedOn.test(rest))) continue;
|
|
1965
|
+
for (const { line, reads, handedOn } of _hookBindings(code, hook)) {
|
|
1966
|
+
if (!reads(verb) || handedOn) continue;
|
|
1949
1967
|
if (reads("qr") && (!sameDevice || reads("autoStartToken"))) continue;
|
|
1950
|
-
const line = code.slice(0, call.index).split(/\r?\n/).length;
|
|
1951
1968
|
findings.push({
|
|
1952
1969
|
rule: "bankid-order-not-shown",
|
|
1953
1970
|
severity: "error",
|
|
@@ -1957,13 +1974,34 @@ function _bankIdOrderRules(source) {
|
|
|
1957
1974
|
(sameDevice ? ` and a button calling Linking.openURL(bankIdAppUrl(autoStartToken))` : "") +
|
|
1958
1975
|
`, or BankID ends it unopened.`,
|
|
1959
1976
|
line,
|
|
1960
|
-
snippet: (
|
|
1977
|
+
snippet: (lines[line - 1] || "").trim().slice(0, 200),
|
|
1961
1978
|
});
|
|
1962
1979
|
}
|
|
1963
1980
|
}
|
|
1964
1981
|
return findings;
|
|
1965
1982
|
}
|
|
1966
1983
|
|
|
1984
|
+
// sc-17552 — a plan a widget sells, its holder can stop renewing there.
|
|
1985
|
+
// One-time plans never renew, so the control never shows for them. Judged per
|
|
1986
|
+
// file: one component may buy and another cancel.
|
|
1987
|
+
function _accessPlanCancelRules(source) {
|
|
1988
|
+
const code = _stripNonCode(source);
|
|
1989
|
+
const lines = source.split(/\r?\n/);
|
|
1990
|
+
const bindings = _hookBindings(code, "useAccessPlans");
|
|
1991
|
+
if (bindings.some(({ uses, handedOn }) => uses("cancel") || handedOn)) return [];
|
|
1992
|
+
return bindings
|
|
1993
|
+
.filter(({ uses }) => uses("purchase"))
|
|
1994
|
+
.map(({ line }) => ({
|
|
1995
|
+
rule: "access-plan-cancel-missing",
|
|
1996
|
+
severity: "error",
|
|
1997
|
+
label:
|
|
1998
|
+
"useAccessPlans().purchase() sells a plan its buyer can never cancel. For a held plan with renews: true, " +
|
|
1999
|
+
"render a \"Cancel renewal\" control that calls cancel(plan.id), and show access_ends_at once it is cancelled.",
|
|
2000
|
+
line,
|
|
2001
|
+
snippet: (lines[line - 1] || "").trim().slice(0, 200),
|
|
2002
|
+
}));
|
|
2003
|
+
}
|
|
2004
|
+
|
|
1967
2005
|
// sc-16511 — soft warning, the read twin of `datastore-error-not-branched`.
|
|
1968
2006
|
// A read refused because the viewer may not see the table (a signed-out
|
|
1969
2007
|
// visitor gets NOT_FOUND, a signed-in one FORBIDDEN) never clears on a retry,
|
|
@@ -3797,6 +3835,7 @@ export function lintSource(source, options) {
|
|
|
3797
3835
|
findings.push(..._readErrorHandlingRules(source));
|
|
3798
3836
|
findings.push(..._aggregateErrorRules(source));
|
|
3799
3837
|
findings.push(..._bankIdOrderRules(source));
|
|
3838
|
+
findings.push(..._accessPlanCancelRules(source));
|
|
3800
3839
|
// sc-5206 — soft warnings steering a widget toward the two new hooks.
|
|
3801
3840
|
findings.push(..._rawUseMemoIntoDatastoreQueryRules(source));
|
|
3802
3841
|
findings.push(..._handRolledWriteGateRules(source));
|
package/package.json
CHANGED
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:*"],
|
|
@@ -2479,7 +2495,7 @@ const HOOKS = [
|
|
|
2479
2495
|
signature: "useAccessPlans()",
|
|
2480
2496
|
returnShape: {
|
|
2481
2497
|
plans:
|
|
2482
|
-
"Array<{ id, name, price_cents, currency, billing: \"one_time\" | \"monthly\", owned, renews, access_ends_at, purchase_available }> // owned: the user holds it; renews: a held monthly plan will charge again; access_ends_at: end of held access without a renewal (null for one-time); purchase_available: this plan can be bought here — false in an iOS/Android build for a plan the workspace does not sell in-app",
|
|
2498
|
+
"Array<{ id, name, price_cents, currency, billing: \"one_time\" | \"monthly\", owned, renews, access_ends_at, purchase_available }> // owned: the user holds it; renews: a held monthly plan will charge again; access_ends_at: end of held access without a renewal (null for one-time); purchase_available: this plan can be bought here — false in an iOS/Android build for a plan the workspace does not sell in-app, and for a plan the user holds that is no longer on sale (listed so they can still cancel it)",
|
|
2483
2499
|
loading: "boolean",
|
|
2484
2500
|
error: "PaymentError | null",
|
|
2485
2501
|
purchaseAvailable:
|
|
@@ -2487,7 +2503,7 @@ const HOOKS = [
|
|
|
2487
2503
|
purchase:
|
|
2488
2504
|
"(planId, { return_path? }?) => Promise<{ plan_id, status: \"ACTIVE\" | \"PENDING\" }> // pass ONLY the plan id; the server sets price and group; the host opens hosted Checkout on the web and the store's in-app purchase sheet in an iOS/Android build; access arrives with the payment confirmation, so refresh() a moment later",
|
|
2489
2505
|
cancel:
|
|
2490
|
-
"(planId) => Promise<{ plan_id, renews: false, access_ends_at }> // stop a renewing monthly plan; access runs to access_ends_at — offer it beside every plan with renews: true",
|
|
2506
|
+
"(planId) => Promise<{ plan_id, renews: false, access_ends_at }> // stop a renewing monthly plan; access runs to access_ends_at — offer it beside every plan with renews: true; a widget that calls purchase without it is refused (access-plan-cancel-missing)",
|
|
2491
2507
|
refresh: "() => Promise<void> // re-read after returning from Checkout",
|
|
2492
2508
|
},
|
|
2493
2509
|
requiredContextSlice: [
|
|
@@ -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. " +
|
|
@@ -7068,7 +7085,13 @@ const CONTRACT = deepFreeze({
|
|
|
7068
7085
|
// value, and an update may still change it.
|
|
7069
7086
|
// 1.271.0: additive (sc-17551) — `useDatastoreAggregate` groups by a
|
|
7070
7087
|
// relation column; new warning lint `aggregate-error-not-read`.
|
|
7071
|
-
|
|
7088
|
+
// 1.272.0: stricter lint (sc-17552) — a widget that calls
|
|
7089
|
+
// useAccessPlans().purchase without cancel is the publish-blocking
|
|
7090
|
+
// `access-plan-cancel-missing` finding.
|
|
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
|
+
version: "1.273.0",
|
|
7072
7095
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7073
7096
|
hooks: HOOKS,
|
|
7074
7097
|
primitives: PRIMITIVES,
|