@cotal-ai/connector-core 0.92.2 → 0.94.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/dist/agent.d.ts +9 -0
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +43 -5
- package/dist/agent.js.map +1 -1
- package/dist/config.d.ts +3 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/control.d.ts +3 -1
- package/dist/control.d.ts.map +1 -1
- package/dist/control.js +3 -3
- package/dist/control.js.map +1 -1
- package/dist/docs-bundle.generated.d.ts +1 -1
- package/dist/docs-bundle.generated.js +9 -9
- package/dist/docs-bundle.generated.js.map +1 -1
- package/dist/framing.d.ts +3 -0
- package/dist/framing.d.ts.map +1 -1
- package/dist/framing.js +13 -1
- package/dist/framing.js.map +1 -1
- package/dist/gateway.d.ts +62 -11
- package/dist/gateway.d.ts.map +1 -1
- package/dist/gateway.js +143 -30
- package/dist/gateway.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/inline-delivery.d.ts +25 -0
- package/dist/inline-delivery.d.ts.map +1 -0
- package/dist/inline-delivery.js +57 -0
- package/dist/inline-delivery.js.map +1 -0
- package/dist/relay.d.ts +3 -1
- package/dist/relay.d.ts.map +1 -1
- package/dist/relay.js +6 -2
- package/dist/relay.js.map +1 -1
- package/dist/tool-specs.d.ts.map +1 -1
- package/dist/tool-specs.js +63 -9
- package/dist/tool-specs.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"docs-bundle.generated.js","sourceRoot":"","sources":["../src/docs-bundle.generated.ts"],"names":[],"mappings":"AAKA,yFAAyF;AACzF,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC;AAErC,MAAM,UAAU,cAAc;IAC5B,OAAO;QACP,SAAS,EAAE,QAAQ;QACnB,eAAe,EAAE,mEAAmE;QACpF,OAAO,EAAE;YACP;gBACE,MAAM,EAAE,eAAe;gBACvB,OAAO,EAAE,eAAe;gBACxB,MAAM,EAAE,0BAA0B;gBAClC,SAAS,EAAE,+FAA+F;gBAC1G,MAAM,EAAE,s5IAAs5I;aAC/5I;YACD;gBACE,MAAM,EAAE,iBAAiB;gBACzB,OAAO,EAAE,YAAY;gBACrB,MAAM,EAAE,0BAA0B;gBAClC,SAAS,EAAE,gHAAgH;gBAC3H,MAAM,EAAE,wrbAAwrb;aACjsb;YACD;gBACE,MAAM,EAAE,cAAc;gBACtB,OAAO,EAAE,cAAc;gBACvB,MAAM,EAAE,uBAAuB;gBAC/B,SAAS,EAAE,wMAAwM;gBACnN,MAAM,EAAE,iwpCAAiwpC;aAC1wpC;YACD;gBACE,MAAM,EAAE,WAAW;gBACnB,OAAO,EAAE,kBAAkB;gBAC3B,MAAM,EAAE,mEAAmE;gBAC3E,SAAS,EAAE,wMAAwM;gBACnN,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"docs-bundle.generated.js","sourceRoot":"","sources":["../src/docs-bundle.generated.ts"],"names":[],"mappings":"AAKA,yFAAyF;AACzF,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC;AAErC,MAAM,UAAU,cAAc;IAC5B,OAAO;QACP,SAAS,EAAE,QAAQ;QACnB,eAAe,EAAE,mEAAmE;QACpF,OAAO,EAAE;YACP;gBACE,MAAM,EAAE,eAAe;gBACvB,OAAO,EAAE,eAAe;gBACxB,MAAM,EAAE,0BAA0B;gBAClC,SAAS,EAAE,+FAA+F;gBAC1G,MAAM,EAAE,s5IAAs5I;aAC/5I;YACD;gBACE,MAAM,EAAE,iBAAiB;gBACzB,OAAO,EAAE,YAAY;gBACrB,MAAM,EAAE,0BAA0B;gBAClC,SAAS,EAAE,gHAAgH;gBAC3H,MAAM,EAAE,wrbAAwrb;aACjsb;YACD;gBACE,MAAM,EAAE,cAAc;gBACtB,OAAO,E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DAA2D;gBACtE,MAAM,EAAE,u/KAAu/K;aAChgL;YACD;gBACE,MAAM,EAAE,WAAW;gBACnB,OAAO,EAAE,qBAAqB;gBAC9B,MAAM,EAAE,uBAAuB;gBAC/B,SAAS,EAAE,kGAAkG;gBAC7G,MAAM,EAAE,ktPAAktP;aAC3tP;YACD;gBACE,MAAM,EAAE,WAAW;gBACnB,OAAO,EAAE,uBAAuB;gBAChC,MAAM,EAAE,uBAAuB;gBAC/B,SAAS,EAAE,kGAAkG;gBAC7G,MAAM,EAAE,ugQAAugQ;aAChhQ;YACD;gBACE,MAAM,EAAE,WAAW;gBACnB,OAAO,EAAE,gCAAgC;gBACzC,MAAM,EAAE,qBAAqB;gBAC7B,SAAS,EAAE,iEAAiE;gBAC5E,MAAM,EAAE,482IAA482I;aACr92I;YACD;gBACE,MAAM,EAAE,cAAc;gBACtB,OAAO,EAAE,cAAc;gBACvB,MAAM,EAAE,qBAAqB;gBAC7B,SAAS,EAAE,uHAAuH;gBAClI,MAAM,EAAE,kjoBAAkjoB;aAC3joB;YACD;gBACE,MAAM,EAAE,WAAW;gBACnB,OAAO,EAAE,eAAe;gBACxB,MAAM,EAAE,uBAAuB;gBAC/B,SAAS,EAAE,yFAAyF;gBACpG,MAAM,EAAE,uyxDAAuyxD;aAChzxD;SACF;QACD,MAAM,EAAE;YACN,OAAO,EAAE,0BAA0B;YACnC,MAAM,EAAE,s/zoBAAs/zoB;SAC//zoB;QACD,MAAM,EAAE;YACN,OAAO,EAAE,mCAAmC;YAC5C,MAAM,EAAE,qmqGAAqmqG;SAC9mqG;QACD,QAAQ,EAAE;YACR,OAAO,EAAE,oCAAoC;YAC7C,MAAM,EAAE,s8tBAAs8tB;SAC/8tB;KACF,CAAC;AACF,CAAC"}
|
package/dist/framing.d.ts
CHANGED
|
@@ -40,6 +40,9 @@ export declare function fmtBody(text: string): string;
|
|
|
40
40
|
* validated what.
|
|
41
41
|
*/
|
|
42
42
|
export declare function fmtItem(i: InboxItem): string;
|
|
43
|
+
/** Full delivery metadata lets an inline recipient select the same reply as an inbox reader.
|
|
44
|
+
* JSON escaping preserves opaque IDs without allowing them to create another attribution row. */
|
|
45
|
+
export declare function fmtDeliveryItem(i: InboxItem): string;
|
|
43
46
|
/**
|
|
44
47
|
* A message's channel, as a wake hint may name it.
|
|
45
48
|
*
|
package/dist/framing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"framing.d.ts","sourceRoot":"","sources":["../src/framing.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3D,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAoBD,kGAAkG;AAClG,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,aAAa,EAAE,gBAAgB,SAAM,GAAG,oBAAoB,CAOxG;AAcD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,iFAAiF;AACjF,wBAAgB,OAAO,CAAC,CAAC,EAAE,SAAS,GAAG,MAAM,CAE5C;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,SAAS,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"framing.d.ts","sourceRoot":"","sources":["../src/framing.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3D,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAoBD,kGAAkG;AAClG,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,aAAa,EAAE,gBAAgB,SAAM,GAAG,oBAAoB,CAOxG;AAcD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,iFAAiF;AACjF,wBAAgB,OAAO,CAAC,CAAC,EAAE,SAAS,GAAG,MAAM,CAE5C;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,SAAS,GAAG,MAAM,CAE5C;AAED;iGACiG;AACjG,wBAAgB,eAAe,CAAC,CAAC,EAAE,SAAS,GAAG,MAAM,CAOpD;AAYD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAG9D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAGxD"}
|
package/dist/framing.js
CHANGED
|
@@ -93,10 +93,22 @@ export function fmtBody(text) {
|
|
|
93
93
|
* validated what.
|
|
94
94
|
*/
|
|
95
95
|
export function fmtItem(i) {
|
|
96
|
+
return formatItem(i);
|
|
97
|
+
}
|
|
98
|
+
/** Full delivery metadata lets an inline recipient select the same reply as an inbox reader.
|
|
99
|
+
* JSON escaping preserves opaque IDs without allowing them to create another attribution row. */
|
|
100
|
+
export function fmtDeliveryItem(i) {
|
|
101
|
+
const field = (value) => Array.from(JSON.stringify(value), (char) => [91, 93, 133, 8232, 8233].includes(char.charCodeAt(0))
|
|
102
|
+
? `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}` : char).join("");
|
|
103
|
+
const metadata = [`sender_id=${field(i.fromId)}`, ...(i.id ? [`message_id=${field(i.id)}`] : []),
|
|
104
|
+
...(i.contextId ? [`context_id=${field(i.contextId)}`] : []), ...(i.replyTo ? [`reply_to=${field(i.replyTo)}`] : [])];
|
|
105
|
+
return formatItem(i, `[${metadata.join(" ")}] `);
|
|
106
|
+
}
|
|
107
|
+
function formatItem(i, metadata = "") {
|
|
96
108
|
const h = i.historical ? "(history) " : ""; // backfilled on join, so it pre-dates you and is not live
|
|
97
109
|
// The broker's count, so a peer cannot forge or hide it: an earlier copy outlived its ack wait.
|
|
98
110
|
const r = i.deliveryCount !== undefined && i.deliveryCount > 1 ? `(redelivered, delivery ${i.deliveryCount}: an earlier delivery may already have run) ` : "";
|
|
99
|
-
const body = `${h}${r}${fmtBody(i.text)}`;
|
|
111
|
+
const body = `${metadata}${h}${r}${fmtBody(i.text)}`;
|
|
100
112
|
if (i.kind === "dm")
|
|
101
113
|
return `[DM from ${fmtFrom(i)}] ${body}`;
|
|
102
114
|
if (i.kind === "anycast")
|
package/dist/framing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"framing.js","sourceRoot":"","sources":["../src/framing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAQtD;;;;;;;;;GASG;AACH,MAAM,eAAe,GAAG,wBAAwB,CAAC;AAEjD,mGAAmG;AACnG,SAAS,UAAU,CAAC,GAAW,EAAE,aAAqB;IACpD,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/B,OAAO,MAAM,CAAC,MAAM,IAAI,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,aAAa,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC;AAClG,CAAC;AAED,kGAAkG;AAClG,MAAM,UAAU,kBAAkB,CAAC,QAAuB,EAAE,gBAAgB,GAAG,GAAG;IAChF,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC,IAAI,gBAAg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CAAC;IACrG,OAAO,KAAK,eAAe,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;AACtG,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,UAAU,CAAC,OAA2B;IACpD,MAAM,IAAI,GAAG,eAAe,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACnD,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;AAClC,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,OAAO,CAAC,IAAwB;IAC9C,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAChD,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AACxC,CAAC"}
|
package/dist/gateway.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ import type { IncomingMessage, ServerResponse } from "node:http";
|
|
|
18
18
|
import type { Readable, Writable } from "node:stream";
|
|
19
19
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
20
20
|
import type { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types.js";
|
|
21
|
+
import { type ConversationPending, type ConversationSelection } from "@cotal-ai/core";
|
|
21
22
|
import type { MeshAgent } from "./agent.js";
|
|
22
23
|
import type { AgentConfig } from "./config.js";
|
|
23
24
|
import { type RenderedInboxPreview } from "./framing.js";
|
|
@@ -29,11 +30,20 @@ export declare class NameTaken extends Error {
|
|
|
29
30
|
readonly taken: string;
|
|
30
31
|
constructor(taken: string);
|
|
31
32
|
}
|
|
33
|
+
/** An issuer is waiting for the person to review permissions. This is not a connection or an
|
|
34
|
+
* authorization; only the authority's authenticated approval page can record the decision. */
|
|
35
|
+
export declare class ApprovalRequired extends Error {
|
|
36
|
+
readonly pending: ConversationPending;
|
|
37
|
+
constructor(pending: ConversationPending);
|
|
38
|
+
}
|
|
32
39
|
/** One live connection: a mesh identity serving one conversation. */
|
|
33
40
|
export interface GatewayConnection {
|
|
34
41
|
readonly id: string;
|
|
35
42
|
readonly agent: MeshAgent;
|
|
36
43
|
readonly config: AgentConfig;
|
|
44
|
+
/** The tools this connection may call, when its host grants it more than {@link GATEWAY_TOOLS}.
|
|
45
|
+
* Only tools the embedder registers count (see {@link GatewayOptions.tools}). */
|
|
46
|
+
readonly tools?: ReadonlySet<string>;
|
|
37
47
|
}
|
|
38
48
|
/** What the embedding service supplies. Every method receives the authenticated account, never a
|
|
39
49
|
* value a tool argument chose. */
|
|
@@ -45,16 +55,29 @@ export interface GatewayHost {
|
|
|
45
55
|
* an authoritative name collision. The collision check and the issue must be one atomic step per
|
|
46
56
|
* account: an `open` racing another for the same name throws `NameTaken` rather than also
|
|
47
57
|
* succeeding, or two conversations end up sharing one name. Error messages reach the caller,
|
|
48
|
-
* so they must not carry secrets.
|
|
49
|
-
|
|
50
|
-
|
|
58
|
+
* so they must not carry secrets. `selection` is only a proposal, never the person's consent.
|
|
59
|
+
* Throw {@link ApprovalRequired} until the person approves through the authority's own UI; issue
|
|
60
|
+
* only their approved selection within their current access. `approvalId` is an untrusted resume
|
|
61
|
+
* handle, never proof of approval. Bind it to this account, name and unchanged request, and do not
|
|
62
|
+
* reuse an issued approval for another connection. */
|
|
63
|
+
open(account: string, name: string, context?: string, selection?: ConversationSelection, approvalId?: string): Promise<GatewayConnection>;
|
|
64
|
+
/** The connection `id` if `account` owns it, otherwise undefined. Never a default. Throw, with the
|
|
65
|
+
* reason and the retry, when `account` owns `id` but it can no longer serve, such as a
|
|
66
|
+
* disconnected connection whose cleanup is unfinished. */
|
|
51
67
|
find(account: string, id: string): Promise<GatewayConnection | undefined>;
|
|
52
68
|
/** Stop and release one connection `account` owns. False when it owns no such connection. */
|
|
53
69
|
close(account: string, id: string): Promise<boolean>;
|
|
54
70
|
}
|
|
55
71
|
/** The mesh tools a remote conversation may call. Process and seat authority (spawn, despawn,
|
|
56
|
-
* persona, run, yield, reconnect) belongs to a supervised local seat and is not offered here
|
|
72
|
+
* persona, run, yield, reconnect) belongs to a supervised local seat and is not offered here; a
|
|
73
|
+
* native embedder may offer part of it per connection with {@link NATIVE_GATEWAY_TOOLS}. */
|
|
57
74
|
export declare const GATEWAY_TOOLS: ReadonlySet<string>;
|
|
75
|
+
/** What a native embedder may register beyond {@link GATEWAY_TOOLS}: process, workflow and
|
|
76
|
+
* reconnect tools. A connection calls one only when its host lists it in
|
|
77
|
+
* {@link GatewayConnection.tools}, and the manager or endpoint that serves the call still decides
|
|
78
|
+
* it from the connection's own grant. `cotal_yield` is not here: a conversation is not a managed
|
|
79
|
+
* seat, so no run turn is ever addressed to it. */
|
|
80
|
+
export declare const NATIVE_GATEWAY_TOOLS: ReadonlySet<string>;
|
|
58
81
|
/** How many names `cotal_connect` tries: the requested one, then `_2` up to this suffix. */
|
|
59
82
|
export declare const GATEWAY_NAME_ATTEMPTS = 20;
|
|
60
83
|
/** The longest `cotal_wait` holds one call when the embedder sets no bound, in seconds. A held call
|
|
@@ -64,6 +87,18 @@ export declare const GATEWAY_NAME_ATTEMPTS = 20;
|
|
|
64
87
|
export declare const GATEWAY_WAIT_SECONDS = 50;
|
|
65
88
|
/** How an embedder tunes the surface for what sits in front of it. */
|
|
66
89
|
export interface GatewayOptions {
|
|
90
|
+
/** A native embedder binds the connect call to a host-observed conversation. The value is only
|
|
91
|
+
* a routing key, never authentication; the host must validate its own binding before issue. */
|
|
92
|
+
connectContext?: boolean;
|
|
93
|
+
/** The tools to register, within {@link NATIVE_GATEWAY_TOOLS}. Defaults to {@link GATEWAY_TOOLS}.
|
|
94
|
+
* Registering a tool offers it to no connection by itself: see {@link GatewayConnection.tools}. */
|
|
95
|
+
tools?: ReadonlySet<string>;
|
|
96
|
+
/** `cotal_connect` takes the channels, role and capabilities a connection requests
|
|
97
|
+
* within the person's own access, and hands the canonical selection to {@link GatewayHost.open}. */
|
|
98
|
+
selection?: boolean;
|
|
99
|
+
/** Offer an `approval_id` resume handle for hosted permission requests. The host must validate
|
|
100
|
+
* its exact request binding and record the person's decision independently of this handle. */
|
|
101
|
+
approvalResume?: boolean;
|
|
67
102
|
/** The longest `cotal_wait` may hold one call, in whole seconds. Defaults to
|
|
68
103
|
* {@link GATEWAY_WAIT_SECONDS}. Keep it under every proxy and client timeout on the path. */
|
|
69
104
|
waitSeconds?: number;
|
|
@@ -74,15 +109,19 @@ export interface GatewayOptions {
|
|
|
74
109
|
/** How an embedder wakes its client when a connection has something to read. */
|
|
75
110
|
export interface GatewayWake {
|
|
76
111
|
/** Called when a connection gets something that ends a `cotal_wait` while none holds it, and
|
|
77
|
-
* not again
|
|
78
|
-
*
|
|
112
|
+
* not again until a read or explicit settlement rearms that connection. A true return means
|
|
113
|
+
* a reader heard the signal, not that content was admitted or acknowledged. */
|
|
79
114
|
signal(connection: GatewayConnection, preview: RenderedInboxPreview): boolean;
|
|
80
115
|
/** What `cotal_connect` adds about listening, read when the connection opens: whether this
|
|
81
116
|
* client will be woken. */
|
|
82
|
-
listening(): string;
|
|
83
|
-
/**
|
|
84
|
-
*
|
|
85
|
-
|
|
117
|
+
listening(connection: GatewayConnection): string;
|
|
118
|
+
/** Whether other tool results should recommend an inbox read. A full-content native reader can
|
|
119
|
+
* suppress that advice while it owns delivery; notification-only clients keep the default. */
|
|
120
|
+
inboxNotice?(connection: GatewayConnection): boolean;
|
|
121
|
+
/** Called once with the rearm callback. With no connection, reoffer unread work to a replacement
|
|
122
|
+
* reader. A settled inline handoff rearms only its own connection; false clears its latch without
|
|
123
|
+
* immediately retrying a refused delivery. */
|
|
124
|
+
attach?(rewake: (connection?: GatewayConnection, fireNow?: boolean) => void): void;
|
|
86
125
|
}
|
|
87
126
|
/** The names `cotal_connect` tries for `base`, in order. */
|
|
88
127
|
export declare function gatewayNames(base: string, attempts?: number): string[];
|
|
@@ -104,7 +143,7 @@ export declare const GATEWAY_LISTENING: string;
|
|
|
104
143
|
/** How a conversation joins and names its connection: the first part of {@link GATEWAY_INSTRUCTIONS}. */
|
|
105
144
|
export declare const GATEWAY_CONNECTING: string;
|
|
106
145
|
/** The server instructions {@link handleGatewayRequest} sends when the embedder gives none. */
|
|
107
|
-
export declare const GATEWAY_INSTRUCTIONS = "Cotal connects this conversation to the person's Cotal space. Call cotal_connect
|
|
146
|
+
export declare const GATEWAY_INSTRUCTIONS = "Cotal connects this conversation to the person's Cotal space after they approve its permissions. Call cotal_connect with a short name. If approval is pending, show the person its link and wait for their decision; do not approve for them or poll. Then resume the same request as directed. Only a successful connection returns connection_id, required on every other cotal tool call. Each conversation needs its own connection. Never reuse another conversation's connection_id or approval_id. Messages reach you only when you call a tool: to listen, call cotal_wait, which returns as soon as a message arrives. When the person asks you to stay on Cotal or keep listening, call cotal_wait again each time it returns and handle each message as it arrives, until they ask you to stop.";
|
|
108
147
|
/** One HTTP request to a gateway endpoint. */
|
|
109
148
|
export interface GatewayRequest {
|
|
110
149
|
req: IncomingMessage;
|
|
@@ -118,6 +157,10 @@ export interface GatewayRequest {
|
|
|
118
157
|
/** The source tag on messages this endpoint sends. */
|
|
119
158
|
source?: string;
|
|
120
159
|
instructions?: string;
|
|
160
|
+
/** See {@link GatewayOptions.connectContext}. */
|
|
161
|
+
connectContext?: boolean;
|
|
162
|
+
/** See {@link GatewayOptions.approvalResume}. */
|
|
163
|
+
approvalResume?: boolean;
|
|
121
164
|
/** See {@link GatewayOptions.waitSeconds}. */
|
|
122
165
|
waitSeconds?: number;
|
|
123
166
|
}
|
|
@@ -141,6 +184,14 @@ export interface GatewayStdio {
|
|
|
141
184
|
/** The source tag on messages this server sends. */
|
|
142
185
|
source?: string;
|
|
143
186
|
instructions?: string;
|
|
187
|
+
/** See {@link GatewayOptions.connectContext}. */
|
|
188
|
+
connectContext?: boolean;
|
|
189
|
+
/** See {@link GatewayOptions.tools}. */
|
|
190
|
+
tools?: ReadonlySet<string>;
|
|
191
|
+
/** See {@link GatewayOptions.selection}. */
|
|
192
|
+
selection?: boolean;
|
|
193
|
+
/** See {@link GatewayOptions.approvalResume}. */
|
|
194
|
+
approvalResume?: boolean;
|
|
144
195
|
/** See {@link GatewayOptions.waitSeconds}. */
|
|
145
196
|
waitSeconds?: number;
|
|
146
197
|
/** See {@link GatewayOptions.wake}. */
|
package/dist/gateway.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../src/gateway.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gDAAgD,CAAC;
|
|
1
|
+
{"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../src/gateway.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gDAAgD,CAAC;AAG/E,OAAO,EAA+D,KAAK,mBAAmB,EAAE,KAAK,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAGnJ,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,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C,EAAE,OAAO,CAAC;IACzB,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uCAAuC;IACvC,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,WAAW,EAAE,CAAC,GAAE,YAAiB,GAAG,OAAO,CAAC;IAAE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAAC,CAYpH"}
|
package/dist/gateway.js
CHANGED
|
@@ -2,7 +2,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
2
2
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
3
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
-
import { assertValidName } from "@cotal-ai/core";
|
|
5
|
+
import { assertValidName, conversationSelection, SELECTION_MAX_ITEMS } from "@cotal-ai/core";
|
|
6
6
|
import { DOCS_VERSION } from "./docs.js";
|
|
7
7
|
import { cotalToolSpecs, parseToolArgs } from "./tool-specs.js";
|
|
8
8
|
import { renderInboxPreview } from "./framing.js";
|
|
@@ -18,12 +18,24 @@ export class NameTaken extends Error {
|
|
|
18
18
|
this.name = "NameTaken";
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
+
/** An issuer is waiting for the person to review permissions. This is not a connection or an
|
|
22
|
+
* authorization; only the authority's authenticated approval page can record the decision. */
|
|
23
|
+
export class ApprovalRequired extends Error {
|
|
24
|
+
pending;
|
|
25
|
+
constructor(pending) {
|
|
26
|
+
super("the person must approve this connection's permissions");
|
|
27
|
+
this.pending = pending;
|
|
28
|
+
this.name = "ApprovalRequired";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
21
31
|
/** The mesh tools a remote conversation may call. Process and seat authority (spawn, despawn,
|
|
22
|
-
* persona, run, yield, reconnect) belongs to a supervised local seat and is not offered here
|
|
32
|
+
* persona, run, yield, reconnect) belongs to a supervised local seat and is not offered here; a
|
|
33
|
+
* native embedder may offer part of it per connection with {@link NATIVE_GATEWAY_TOOLS}. */
|
|
23
34
|
export const GATEWAY_TOOLS = new Set([
|
|
24
35
|
"cotal_orientation",
|
|
25
36
|
"cotal_connection_status",
|
|
26
37
|
"cotal_roster",
|
|
38
|
+
"cotal_docs",
|
|
27
39
|
"cotal_inbox",
|
|
28
40
|
"cotal_send",
|
|
29
41
|
"cotal_dm",
|
|
@@ -35,6 +47,20 @@ export const GATEWAY_TOOLS = new Set([
|
|
|
35
47
|
"cotal_join",
|
|
36
48
|
"cotal_leave",
|
|
37
49
|
]);
|
|
50
|
+
/** What a native embedder may register beyond {@link GATEWAY_TOOLS}: process, workflow and
|
|
51
|
+
* reconnect tools. A connection calls one only when its host lists it in
|
|
52
|
+
* {@link GatewayConnection.tools}, and the manager or endpoint that serves the call still decides
|
|
53
|
+
* it from the connection's own grant. `cotal_yield` is not here: a conversation is not a managed
|
|
54
|
+
* seat, so no run turn is ever addressed to it. */
|
|
55
|
+
export const NATIVE_GATEWAY_TOOLS = new Set([
|
|
56
|
+
...GATEWAY_TOOLS,
|
|
57
|
+
"cotal_spawn",
|
|
58
|
+
"cotal_persona",
|
|
59
|
+
"cotal_personas",
|
|
60
|
+
"cotal_despawn",
|
|
61
|
+
"cotal_run",
|
|
62
|
+
"cotal_reconnect",
|
|
63
|
+
]);
|
|
38
64
|
const READ_ONLY = { readOnlyHint: true, destructiveHint: false };
|
|
39
65
|
const ADDITIVE = { readOnlyHint: false, destructiveHint: false };
|
|
40
66
|
const UPDATING = { readOnlyHint: false, destructiveHint: true };
|
|
@@ -47,6 +73,7 @@ const GATEWAY_ANNOTATIONS = {
|
|
|
47
73
|
cotal_orientation: READ_ONLY,
|
|
48
74
|
cotal_connection_status: READ_ONLY,
|
|
49
75
|
cotal_roster: READ_ONLY,
|
|
76
|
+
cotal_docs: READ_ONLY,
|
|
50
77
|
cotal_inbox: UPDATING,
|
|
51
78
|
cotal_send: ADDITIVE,
|
|
52
79
|
cotal_dm: ADDITIVE,
|
|
@@ -57,6 +84,12 @@ const GATEWAY_ANNOTATIONS = {
|
|
|
57
84
|
cotal_channel_mode: UPDATING,
|
|
58
85
|
cotal_join: ADDITIVE,
|
|
59
86
|
cotal_leave: UPDATING,
|
|
87
|
+
cotal_spawn: ADDITIVE,
|
|
88
|
+
cotal_persona: UPDATING,
|
|
89
|
+
cotal_personas: READ_ONLY,
|
|
90
|
+
cotal_despawn: UPDATING,
|
|
91
|
+
cotal_run: UPDATING,
|
|
92
|
+
cotal_reconnect: ADDITIVE,
|
|
60
93
|
};
|
|
61
94
|
function gatewayAnnotations(name) {
|
|
62
95
|
const annotations = GATEWAY_ANNOTATIONS[name];
|
|
@@ -64,6 +97,30 @@ function gatewayAnnotations(name) {
|
|
|
64
97
|
throw new Error(`Missing gateway tool annotations for ${name}`);
|
|
65
98
|
return annotations;
|
|
66
99
|
}
|
|
100
|
+
/** What `cotal_connect` says about selection when the embedder enables it. */
|
|
101
|
+
const SELECTION_TEXT = "Channels, role and capabilities are a proposal for the person to review, edit and approve in Cotal, " +
|
|
102
|
+
"not permission to connect. Without them the proposal has no ordinary channel access or role, but still " +
|
|
103
|
+
"allows direct messages and publication of this conversation's own activity. Only the person's approved " +
|
|
104
|
+
"permissions within their current access may be issued. Joining an approved channel is a separate step.";
|
|
105
|
+
const SELECTION_SHAPE = {
|
|
106
|
+
channels: z
|
|
107
|
+
.array(z.strictObject({ channel: z.string().min(1), access: z.enum(["read", "read-post"]) }))
|
|
108
|
+
.max(SELECTION_MAX_ITEMS)
|
|
109
|
+
.optional()
|
|
110
|
+
.describe("Channels this connection may join and read, or read and post to. No wildcards."),
|
|
111
|
+
role: z.string().min(1).optional().describe("A role to hold, so role requests (cotal_anycast) reach this connection."),
|
|
112
|
+
capabilities: z
|
|
113
|
+
.array(z.enum(["spawn", "run"]))
|
|
114
|
+
.optional()
|
|
115
|
+
.describe("spawn: start and stop agents through a manager. run: start and manage workflow runs."),
|
|
116
|
+
};
|
|
117
|
+
/** The canonical selection a `cotal_connect` call names, or undefined when it names none. */
|
|
118
|
+
function selectionOf(input) {
|
|
119
|
+
const { channels, role, capabilities } = input;
|
|
120
|
+
if (channels === undefined && role === undefined && capabilities === undefined)
|
|
121
|
+
return undefined;
|
|
122
|
+
return conversationSelection({ channels, role, capabilities });
|
|
123
|
+
}
|
|
67
124
|
/** How many names `cotal_connect` tries: the requested one, then `_2` up to this suffix. */
|
|
68
125
|
export const GATEWAY_NAME_ATTEMPTS = 20;
|
|
69
126
|
/** The longest `cotal_wait` holds one call when the embedder sets no bound, in seconds. A held call
|
|
@@ -103,6 +160,12 @@ function toContent(r) {
|
|
|
103
160
|
return r.isError ? { content, isError: true } : { content };
|
|
104
161
|
}
|
|
105
162
|
const refuse = (text) => toContent({ text, isError: true });
|
|
163
|
+
/** What a new connection may read and post, from the configuration its grant produced, so the
|
|
164
|
+
* conversation learns its real access before it tries a channel. */
|
|
165
|
+
function accessLine(config) {
|
|
166
|
+
const list = (cs) => (cs.length ? cs.map((c) => `#${c}`).join(", ") : "none");
|
|
167
|
+
return `Reads ${list(config.subscribe)}; may join ${list(config.allowSubscribe)}; may post to ${list(config.allowPublish)}.`;
|
|
168
|
+
}
|
|
106
169
|
function errorText(e) {
|
|
107
170
|
return e instanceof Error ? e.message : String(e);
|
|
108
171
|
}
|
|
@@ -197,15 +260,24 @@ export function registerCotalGatewayTools(server, host, source = "gateway", opti
|
|
|
197
260
|
if (!Number.isInteger(waitSeconds) || waitSeconds < 1) {
|
|
198
261
|
throw new Error(`waitSeconds must be a whole number of seconds, at least 1; got ${waitSeconds}`);
|
|
199
262
|
}
|
|
263
|
+
const offered = options.tools ?? GATEWAY_TOOLS;
|
|
264
|
+
for (const name of offered)
|
|
265
|
+
if (!NATIVE_GATEWAY_TOOLS.has(name))
|
|
266
|
+
throw new Error(`the gateway cannot offer ${name}`);
|
|
267
|
+
// What one connection may call: what is registered and what its host granted it.
|
|
268
|
+
const toolsOf = (c) => new Set([...offered].filter((name) => (c.tools ?? GATEWAY_TOOLS).has(name)));
|
|
200
269
|
const wake = options.wake;
|
|
201
270
|
// Connections signalled and not read since, how many cotal_wait calls hold each one, and the
|
|
202
271
|
// check for each watched connection, which the rewake runs again.
|
|
203
272
|
const signalled = new WeakSet();
|
|
204
273
|
const holding = new WeakMap();
|
|
205
|
-
const watched = new
|
|
206
|
-
wake?.attach?.(() => {
|
|
207
|
-
|
|
208
|
-
|
|
274
|
+
const watched = new Map();
|
|
275
|
+
wake?.attach?.((connection, fireNow) => {
|
|
276
|
+
if (connection)
|
|
277
|
+
watched.get(connection)?.(fireNow);
|
|
278
|
+
else
|
|
279
|
+
for (const fire of watched.values())
|
|
280
|
+
fire(fireNow);
|
|
209
281
|
});
|
|
210
282
|
const watch = (c) => {
|
|
211
283
|
if (!wake)
|
|
@@ -218,16 +290,17 @@ export function registerCotalGatewayTools(server, host, source = "gateway", opti
|
|
|
218
290
|
if (wake.signal(c, renderInboxPreview(c.agent.inboxSnapshot())))
|
|
219
291
|
signalled.add(c.agent);
|
|
220
292
|
};
|
|
221
|
-
const replay = () => {
|
|
222
|
-
// A previous reader may have exited
|
|
293
|
+
const replay = (fireNow = true) => {
|
|
294
|
+
// A previous reader may have exited, or an inline handoff has settled.
|
|
223
295
|
signalled.delete(c.agent);
|
|
224
|
-
|
|
296
|
+
if (fireNow)
|
|
297
|
+
fire();
|
|
225
298
|
};
|
|
226
|
-
watched.
|
|
299
|
+
watched.set(c, replay);
|
|
227
300
|
c.agent.on("incoming", fire);
|
|
228
301
|
c.agent.on("mention-wake", fire);
|
|
229
302
|
c.agent.once("stopping", () => {
|
|
230
|
-
watched.delete(
|
|
303
|
+
watched.delete(c);
|
|
231
304
|
c.agent.off("incoming", fire);
|
|
232
305
|
c.agent.off("mention-wake", fire);
|
|
233
306
|
});
|
|
@@ -235,14 +308,21 @@ export function registerCotalGatewayTools(server, host, source = "gateway", opti
|
|
|
235
308
|
server.registerTool("cotal_connect", {
|
|
236
309
|
title: "Cotal: connect this conversation",
|
|
237
310
|
annotations: gatewayAnnotations("cotal_connect"),
|
|
238
|
-
description: "
|
|
239
|
-
"
|
|
240
|
-
"
|
|
241
|
-
"
|
|
311
|
+
description: "Request a Cotal connection for THIS conversation. The person must review, edit and approve its " +
|
|
312
|
+
"permissions in Cotal before it receives a connection_id. When approval is pending, show them the " +
|
|
313
|
+
"approval link and stop; never approve for them or poll. After their decision, retry the same request " +
|
|
314
|
+
"as the pending result directs. Keep the returned connection_id and pass it on every other cotal_* " +
|
|
315
|
+
"call. If a new name is taken, the next free name is chosen (name_2, name_3, ...) and reported. " +
|
|
316
|
+
"Never reuse another conversation's connection_id or approval_id." +
|
|
317
|
+
(options.selection ? ` ${SELECTION_TEXT}` : ""),
|
|
242
318
|
inputSchema: z.strictObject({
|
|
243
319
|
name: z.string().min(1).describe("The agent name to request, for example claude_web."),
|
|
320
|
+
...(options.connectContext ? { context: z.string().min(1).max(128).optional().describe("Conversation binding supplied by the native host.") } : {}),
|
|
321
|
+
...(options.selection ? SELECTION_SHAPE : {}),
|
|
322
|
+
...(options.approvalResume ? { approval_id: z.string().regex(/^[a-z2-7]{26}$/).optional()
|
|
323
|
+
.describe("The approval.id from THIS conversation's pending result. Resumes only that unchanged request; it does not approve it.") } : {}),
|
|
244
324
|
}),
|
|
245
|
-
}, async ({ name }, extra) => {
|
|
325
|
+
}, async ({ name, ...input }, extra) => {
|
|
246
326
|
let account;
|
|
247
327
|
try {
|
|
248
328
|
account = host.account(extra.authInfo);
|
|
@@ -250,7 +330,15 @@ export function registerCotalGatewayTools(server, host, source = "gateway", opti
|
|
|
250
330
|
catch (e) {
|
|
251
331
|
return refuse(`not authenticated: ${errorText(e)}`);
|
|
252
332
|
}
|
|
253
|
-
|
|
333
|
+
let selection;
|
|
334
|
+
try {
|
|
335
|
+
selection = selectionOf(input);
|
|
336
|
+
}
|
|
337
|
+
catch (e) {
|
|
338
|
+
return refuse(`cotal_connect: ${errorText(e)}. Nothing was connected.`);
|
|
339
|
+
}
|
|
340
|
+
const approvalId = typeof input.approval_id === "string" ? input.approval_id : undefined;
|
|
341
|
+
for (const candidate of approvalId ? [name] : gatewayNames(name)) {
|
|
254
342
|
// A name the mesh would refuse is the caller's to fix, not a collision to rename around.
|
|
255
343
|
try {
|
|
256
344
|
assertValidName(candidate);
|
|
@@ -259,17 +347,36 @@ export function registerCotalGatewayTools(server, host, source = "gateway", opti
|
|
|
259
347
|
return refuse(`cotal_connect: ${errorText(e)}`);
|
|
260
348
|
}
|
|
261
349
|
try {
|
|
262
|
-
const
|
|
350
|
+
const context = "context" in input && typeof input.context === "string" ? input.context : undefined;
|
|
351
|
+
const c = await host.open(account, candidate, context, selection, approvalId);
|
|
263
352
|
watch(c);
|
|
264
353
|
const renamed = candidate === name ? "" : ` (${JSON.stringify(name)} was taken)`;
|
|
265
|
-
const listening = wake ? `\n${wake.listening()}` : "";
|
|
354
|
+
const listening = wake ? `\n${wake.listening(c)}` : "";
|
|
266
355
|
return toContent({
|
|
267
|
-
text: `Connected as ${c.config.name}${renamed}.\nconnection_id: ${c.id}\nPass this connection_id on every cotal_* call in this conversation
|
|
356
|
+
text: `Connected as ${c.config.name}${renamed}.\nconnection_id: ${c.id}\nPass this connection_id on every cotal_* call in this conversation.\n${accessLine(c.config)}${listening}`,
|
|
268
357
|
});
|
|
269
358
|
}
|
|
270
359
|
catch (e) {
|
|
271
|
-
if (e instanceof
|
|
360
|
+
if (e instanceof ApprovalRequired) {
|
|
361
|
+
const structuredContent = { v: 1, status: "pending", name: candidate,
|
|
362
|
+
requestId: e.pending.requestId, approval: e.pending.approval, proposed: e.pending.proposed };
|
|
363
|
+
const resume = options.approvalResume ? ` and approval_id ${JSON.stringify(e.pending.approval.id)}` : "";
|
|
364
|
+
return {
|
|
365
|
+
content: [
|
|
366
|
+
{ type: "text", text: `Permission approval required. This conversation is not connected.\n` +
|
|
367
|
+
`The person must open ${e.pending.approval.url}, review or edit the permissions, and choose Approve or Deny.\n` +
|
|
368
|
+
`Expires: ${e.pending.approval.expiresAt}. Only the person's decision in Cotal counts; do not open the decision page or approve on their behalf.\n` +
|
|
369
|
+
`After they approve, retry cotal_connect with name ${JSON.stringify(candidate)}${resume} and the same requested permissions. Do not poll or start another request while waiting.` },
|
|
370
|
+
{ type: "text", text: JSON.stringify(structuredContent) },
|
|
371
|
+
],
|
|
372
|
+
structuredContent,
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
if (e instanceof NameTaken) {
|
|
376
|
+
if (approvalId)
|
|
377
|
+
return refuse("The approved name is no longer available. Nothing was connected; a different name requires a new permission approval.");
|
|
272
378
|
continue;
|
|
379
|
+
}
|
|
273
380
|
return refuse(`cotal_connect failed for ${JSON.stringify(candidate)}: ${errorText(e)}`);
|
|
274
381
|
}
|
|
275
382
|
}
|
|
@@ -320,7 +427,7 @@ export function registerCotalGatewayTools(server, host, source = "gateway", opti
|
|
|
320
427
|
const c = await host.find(account, connection_id);
|
|
321
428
|
if (!c)
|
|
322
429
|
return refuse(CONNECTION_REQUIRED);
|
|
323
|
-
const inbox = cotalToolSpecs(c.config, source, undefined,
|
|
430
|
+
const inbox = cotalToolSpecs(c.config, source, undefined, toolsOf(c)).find((s) => s.name === "cotal_inbox");
|
|
324
431
|
if (!inbox)
|
|
325
432
|
return refuse("cotal_wait is not available on this connection.");
|
|
326
433
|
const limit = seconds ?? waitSeconds;
|
|
@@ -345,7 +452,7 @@ export function registerCotalGatewayTools(server, host, source = "gateway", opti
|
|
|
345
452
|
return refuse(errorText(e));
|
|
346
453
|
}
|
|
347
454
|
});
|
|
348
|
-
for (const spec of cotalToolSpecs(ADVERTISED, source, undefined,
|
|
455
|
+
for (const spec of cotalToolSpecs(ADVERTISED, source, undefined, offered)) {
|
|
349
456
|
const channel = spec.name === "cotal_send" ? spec.schema.shape.channel : undefined;
|
|
350
457
|
const shape = channel ? spec.schema.extend({ channel: channel.describe(SEND_CHANNEL) }) : spec.schema;
|
|
351
458
|
server.registerTool(spec.name, {
|
|
@@ -365,8 +472,8 @@ export function registerCotalGatewayTools(server, host, source = "gateway", opti
|
|
|
365
472
|
const c = await host.find(account, connection_id);
|
|
366
473
|
if (!c)
|
|
367
474
|
return refuse(CONNECTION_REQUIRED);
|
|
368
|
-
|
|
369
|
-
|
|
475
|
+
// A tool the host did not grant this connection, or whose capability its credential lacks.
|
|
476
|
+
const own = cotalToolSpecs(c.config, source, undefined, toolsOf(c)).find((s) => s.name === spec.name);
|
|
370
477
|
if (!own)
|
|
371
478
|
return refuse(`${spec.name} is not available on this connection.`);
|
|
372
479
|
let result;
|
|
@@ -379,7 +486,7 @@ export function registerCotalGatewayTools(server, host, source = "gateway", opti
|
|
|
379
486
|
result = refuse(errorText(e));
|
|
380
487
|
}
|
|
381
488
|
// cotal_inbox already says what it left buffered.
|
|
382
|
-
const notice = spec.name === "cotal_inbox" ? undefined : waitingNotice(c.agent);
|
|
489
|
+
const notice = spec.name === "cotal_inbox" || wake?.inboxNotice?.(c) === false ? undefined : waitingNotice(c.agent);
|
|
383
490
|
return notice ? { ...result, content: [...result.content, notice] } : result;
|
|
384
491
|
});
|
|
385
492
|
}
|
|
@@ -390,9 +497,11 @@ export const GATEWAY_LISTENING = "Messages reach you only when you call a tool:
|
|
|
390
497
|
"message arrives. When the person asks you to stay on Cotal or keep listening, call cotal_wait again each " +
|
|
391
498
|
"time it returns and handle each message as it arrives, until they ask you to stop.";
|
|
392
499
|
/** How a conversation joins and names its connection: the first part of {@link GATEWAY_INSTRUCTIONS}. */
|
|
393
|
-
export const GATEWAY_CONNECTING = "Cotal connects this conversation to the person's Cotal space
|
|
394
|
-
"
|
|
395
|
-
"
|
|
500
|
+
export const GATEWAY_CONNECTING = "Cotal connects this conversation to the person's Cotal space after they approve its permissions. " +
|
|
501
|
+
"Call cotal_connect with a short name. If approval is pending, show the person its link and wait for " +
|
|
502
|
+
"their decision; do not approve for them or poll. Then resume the same request as directed. Only a " +
|
|
503
|
+
"successful connection returns connection_id, required on every other cotal tool call. Each conversation " +
|
|
504
|
+
"needs its own connection. Never reuse another conversation's connection_id or approval_id.";
|
|
396
505
|
/** The server instructions {@link handleGatewayRequest} sends when the embedder gives none. */
|
|
397
506
|
export const GATEWAY_INSTRUCTIONS = `${GATEWAY_CONNECTING} ${GATEWAY_LISTENING}`;
|
|
398
507
|
/**
|
|
@@ -413,7 +522,7 @@ export async function handleGatewayRequest(host, r) {
|
|
|
413
522
|
return;
|
|
414
523
|
}
|
|
415
524
|
const server = new McpServer({ name: "cotal", version: DOCS_VERSION }, { instructions: r.instructions ?? GATEWAY_INSTRUCTIONS });
|
|
416
|
-
registerCotalGatewayTools(server, host, r.source, r.waitSeconds === undefined ? {} : { waitSeconds: r.waitSeconds });
|
|
525
|
+
registerCotalGatewayTools(server, host, r.source, { approvalResume: r.approvalResume, ...(r.waitSeconds === undefined ? {} : { waitSeconds: r.waitSeconds }) });
|
|
417
526
|
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined, enableJsonResponse: true });
|
|
418
527
|
r.res.on("close", () => {
|
|
419
528
|
void transport.close();
|
|
@@ -433,6 +542,10 @@ export async function handleGatewayRequest(host, r) {
|
|
|
433
542
|
export async function serveGatewayStdio(host, o = {}) {
|
|
434
543
|
const server = new McpServer({ name: "cotal", version: DOCS_VERSION }, { instructions: o.instructions ?? GATEWAY_INSTRUCTIONS });
|
|
435
544
|
registerCotalGatewayTools(server, host, o.source, {
|
|
545
|
+
...(o.connectContext ? { connectContext: true } : {}),
|
|
546
|
+
...(o.tools ? { tools: o.tools } : {}),
|
|
547
|
+
...(o.selection ? { selection: true } : {}),
|
|
548
|
+
...(o.approvalResume ? { approvalResume: true } : {}),
|
|
436
549
|
...(o.waitSeconds === undefined ? {} : { waitSeconds: o.waitSeconds }),
|
|
437
550
|
...(o.wake ? { wake: o.wake } : {}),
|
|
438
551
|
});
|