@neuraltrust/trustgate 0.1.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/LICENSE +201 -0
- package/README.md +132 -0
- package/dist/agent.d.ts +156 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +216 -0
- package/dist/agent.js.map +1 -0
- package/dist/client.d.ts +88 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +152 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +44 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +40 -0
- package/dist/config.js.map +1 -0
- package/dist/connections.d.ts +13 -0
- package/dist/connections.d.ts.map +1 -0
- package/dist/connections.js +46 -0
- package/dist/connections.js.map +1 -0
- package/dist/errors.d.ts +91 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +144 -0
- package/dist/errors.js.map +1 -0
- package/dist/formats.d.ts +44 -0
- package/dist/formats.d.ts.map +1 -0
- package/dist/formats.js +299 -0
- package/dist/formats.js.map +1 -0
- package/dist/http.d.ts +23 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +94 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp.d.ts +43 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +175 -0
- package/dist/mcp.js.map +1 -0
- package/dist/schema.d.ts +52 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +168 -0
- package/dist/schema.js.map +1 -0
- package/dist/types.d.ts +78 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +52 -0
- package/dist/types.js.map +1 -0
- package/dist/whoami.d.ts +73 -0
- package/dist/whoami.d.ts.map +1 -0
- package/dist/whoami.js +79 -0
- package/dist/whoami.js.map +1 -0
- package/package.json +29 -0
- package/src/agent.ts +267 -0
- package/src/client.ts +203 -0
- package/src/config.ts +78 -0
- package/src/connections.ts +90 -0
- package/src/errors.ts +154 -0
- package/src/formats.ts +362 -0
- package/src/http.ts +106 -0
- package/src/index.ts +41 -0
- package/src/mcp.ts +203 -0
- package/src/schema.ts +193 -0
- package/src/types.ts +98 -0
- package/src/whoami.ts +172 -0
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every failure the SDK raises, as a type you can catch.
|
|
3
|
+
*
|
|
4
|
+
* The gateway answers a tool call with a JSON-RPC error and the connections
|
|
5
|
+
* API with `{error, message}`. Both are relayed here as classes rather than
|
|
6
|
+
* status codes, because the useful question is never "what number came back"
|
|
7
|
+
* but "is this mine to fix, my user's, or my admin's".
|
|
8
|
+
*/
|
|
9
|
+
export declare class TrustGateError extends Error {
|
|
10
|
+
readonly status?: number;
|
|
11
|
+
readonly code?: string;
|
|
12
|
+
constructor(message: string, options?: {
|
|
13
|
+
status?: number;
|
|
14
|
+
code?: string;
|
|
15
|
+
cause?: unknown;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/** The API key is wrong, or it does not belong to this consumer. */
|
|
19
|
+
export declare class AuthenticationError extends TrustGateError {
|
|
20
|
+
}
|
|
21
|
+
/** The request was malformed — a bad end-user id, an unknown provider. */
|
|
22
|
+
export declare class InvalidRequestError extends TrustGateError {
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The consumer's toolkit does not carry every tool the agent declared.
|
|
26
|
+
*
|
|
27
|
+
* An admin owns that toolkit, so this is not something the caller can fix in
|
|
28
|
+
* code: it is raised at startup, by name, so the agent never reaches a user
|
|
29
|
+
* only to find the tool it was written around is not there.
|
|
30
|
+
*/
|
|
31
|
+
export declare class MissingToolsError extends TrustGateError {
|
|
32
|
+
readonly missing: string[];
|
|
33
|
+
readonly available: string[];
|
|
34
|
+
constructor(missing: string[], available: string[]);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Servers the application cannot call yet, and who has to fix that.
|
|
38
|
+
*
|
|
39
|
+
* Raised at startup only, for the application handle: nobody is present to
|
|
40
|
+
* follow a connect link once a batch is running, so the run either knows
|
|
41
|
+
* beforehand or fails halfway through. The remedy is never the caller's — an
|
|
42
|
+
* account a whole team rides on is an administrator's to connect, and a
|
|
43
|
+
* per-caller account wants the person this call is for, which is what
|
|
44
|
+
* `forEndUser` is.
|
|
45
|
+
*/
|
|
46
|
+
export declare class UpstreamNotConnectedError extends TrustGateError {
|
|
47
|
+
readonly upstreams: BlockedUpstream[];
|
|
48
|
+
constructor(upstreams: BlockedUpstream[]);
|
|
49
|
+
/** The server names, for a caller that wants to log or list them. */
|
|
50
|
+
get servers(): string[];
|
|
51
|
+
}
|
|
52
|
+
/** One server from {@link UpstreamNotConnectedError}. */
|
|
53
|
+
export type BlockedUpstream = {
|
|
54
|
+
server: string;
|
|
55
|
+
blocked?: 'administrator' | 'end_user';
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* An end user has not connected the account this call needs.
|
|
59
|
+
*
|
|
60
|
+
* The link comes with the error because the gateway mints it there: it is the
|
|
61
|
+
* page to put in front of that user, and it expires.
|
|
62
|
+
*/
|
|
63
|
+
export declare class ConsentRequiredError extends TrustGateError {
|
|
64
|
+
readonly provider: string;
|
|
65
|
+
readonly connectUrl: string;
|
|
66
|
+
readonly cause_: string;
|
|
67
|
+
constructor(provider: string, connectUrl: string, cause_: string, message?: string);
|
|
68
|
+
}
|
|
69
|
+
/** A policy on the gateway refused the call. Not retryable. */
|
|
70
|
+
export declare class PolicyBlockedError extends TrustGateError {
|
|
71
|
+
}
|
|
72
|
+
/** The tool is not on this consumer's surface — usually because it just left it. */
|
|
73
|
+
export declare class ToolNotFoundError extends TrustGateError {
|
|
74
|
+
readonly tool: string;
|
|
75
|
+
constructor(tool: string, message?: string);
|
|
76
|
+
}
|
|
77
|
+
/** The connect-attempt limiter refused this call. */
|
|
78
|
+
export declare class RateLimitedError extends TrustGateError {
|
|
79
|
+
readonly retryAfterMs?: number | undefined;
|
|
80
|
+
constructor(message: string, retryAfterMs?: number | undefined);
|
|
81
|
+
}
|
|
82
|
+
/** The gateway could not serve the request and says so. Retryable. */
|
|
83
|
+
export declare class ServiceUnavailableError extends TrustGateError {
|
|
84
|
+
}
|
|
85
|
+
/** The gateway failed on its own account. */
|
|
86
|
+
export declare class TrustGateServerError extends TrustGateError {
|
|
87
|
+
}
|
|
88
|
+
/** The SDK was pointed at a plane this API key does not reach. */
|
|
89
|
+
export declare class PlaneUnavailableError extends TrustGateError {
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACxC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;gBAEV,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAO;CAM9F;AAED,oEAAoE;AACpE,qBAAa,mBAAoB,SAAQ,cAAc;CAAG;AAE1D,0EAA0E;AAC1E,qBAAa,mBAAoB,SAAQ,cAAc;CAAG;AAE1D;;;;;;GAMG;AACH,qBAAa,iBAAkB,SAAQ,cAAc;IACxC,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE;IAAE,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE;gBAA/C,OAAO,EAAE,MAAM,EAAE,EAAW,SAAS,EAAE,MAAM,EAAE;CAOpE;AAED;;;;;;;;;GASG;AACH,qBAAa,yBAA0B,SAAQ,cAAc;IAChD,QAAQ,CAAC,SAAS,EAAE,eAAe,EAAE;gBAA5B,SAAS,EAAE,eAAe,EAAE;IAIjD,qEAAqE;IACrE,IAAI,OAAO,IAAI,MAAM,EAAE,CAEtB;CACD;AAED,yDAAyD;AACzD,MAAM,MAAM,eAAe,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,eAAe,GAAG,UAAU,CAAA;CACtC,CAAA;AA4CD;;;;;GAKG;AACH,qBAAa,oBAAqB,SAAQ,cAAc;IAEtD,QAAQ,CAAC,QAAQ,EAAE,MAAM;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM;gBAFd,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACvB,OAAO,CAAC,EAAE,MAAM;CAIjB;AAED,+DAA+D;AAC/D,qBAAa,kBAAmB,SAAQ,cAAc;CAAG;AAEzD,oFAAoF;AACpF,qBAAa,iBAAkB,SAAQ,cAAc;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM;gBAAZ,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;CAGnD;AAED,qDAAqD;AACrD,qBAAa,gBAAiB,SAAQ,cAAc;IACtB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM;gBAA/C,OAAO,EAAE,MAAM,EAAW,YAAY,CAAC,EAAE,MAAM,YAAA;CAG3D;AAED,sEAAsE;AACtE,qBAAa,uBAAwB,SAAQ,cAAc;CAAG;AAE9D,6CAA6C;AAC7C,qBAAa,oBAAqB,SAAQ,cAAc;CAAG;AAE3D,kEAAkE;AAClE,qBAAa,qBAAsB,SAAQ,cAAc;CAAG"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every failure the SDK raises, as a type you can catch.
|
|
3
|
+
*
|
|
4
|
+
* The gateway answers a tool call with a JSON-RPC error and the connections
|
|
5
|
+
* API with `{error, message}`. Both are relayed here as classes rather than
|
|
6
|
+
* status codes, because the useful question is never "what number came back"
|
|
7
|
+
* but "is this mine to fix, my user's, or my admin's".
|
|
8
|
+
*/
|
|
9
|
+
export class TrustGateError extends Error {
|
|
10
|
+
status;
|
|
11
|
+
code;
|
|
12
|
+
constructor(message, options = {}) {
|
|
13
|
+
super(message, { cause: options.cause });
|
|
14
|
+
this.name = new.target.name;
|
|
15
|
+
this.status = options.status;
|
|
16
|
+
this.code = options.code;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** The API key is wrong, or it does not belong to this consumer. */
|
|
20
|
+
export class AuthenticationError extends TrustGateError {
|
|
21
|
+
}
|
|
22
|
+
/** The request was malformed — a bad end-user id, an unknown provider. */
|
|
23
|
+
export class InvalidRequestError extends TrustGateError {
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The consumer's toolkit does not carry every tool the agent declared.
|
|
27
|
+
*
|
|
28
|
+
* An admin owns that toolkit, so this is not something the caller can fix in
|
|
29
|
+
* code: it is raised at startup, by name, so the agent never reaches a user
|
|
30
|
+
* only to find the tool it was written around is not there.
|
|
31
|
+
*/
|
|
32
|
+
export class MissingToolsError extends TrustGateError {
|
|
33
|
+
missing;
|
|
34
|
+
available;
|
|
35
|
+
constructor(missing, available) {
|
|
36
|
+
super(`the consumer's toolkit is missing ${missing.map((t) => `"${t}"`).join(', ')}. ` +
|
|
37
|
+
`It offers: ${available.length ? available.join(', ') : '(nothing)'}. ` +
|
|
38
|
+
'Ask the admin who owns this application to add them.');
|
|
39
|
+
this.missing = missing;
|
|
40
|
+
this.available = available;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Servers the application cannot call yet, and who has to fix that.
|
|
45
|
+
*
|
|
46
|
+
* Raised at startup only, for the application handle: nobody is present to
|
|
47
|
+
* follow a connect link once a batch is running, so the run either knows
|
|
48
|
+
* beforehand or fails halfway through. The remedy is never the caller's — an
|
|
49
|
+
* account a whole team rides on is an administrator's to connect, and a
|
|
50
|
+
* per-caller account wants the person this call is for, which is what
|
|
51
|
+
* `forEndUser` is.
|
|
52
|
+
*/
|
|
53
|
+
export class UpstreamNotConnectedError extends TrustGateError {
|
|
54
|
+
upstreams;
|
|
55
|
+
constructor(upstreams) {
|
|
56
|
+
super(describeBlocked(upstreams));
|
|
57
|
+
this.upstreams = upstreams;
|
|
58
|
+
}
|
|
59
|
+
/** The server names, for a caller that wants to log or list them. */
|
|
60
|
+
get servers() {
|
|
61
|
+
return this.upstreams.map((upstream) => upstream.server);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Says who fixes each server, with the line of code when it is the caller.
|
|
66
|
+
*
|
|
67
|
+
* Read on a terminal at startup, so it is written to be acted on there: the
|
|
68
|
+
* per-user case is the one a developer hits first, and the fix is one call
|
|
69
|
+
* they have not seen yet, so the call is in the message.
|
|
70
|
+
*/
|
|
71
|
+
function describeBlocked(upstreams) {
|
|
72
|
+
const byAdmin = upstreams.filter((upstream) => upstream.blocked === 'administrator');
|
|
73
|
+
const byUser = upstreams.filter((upstream) => upstream.blocked === 'end_user');
|
|
74
|
+
const parts = [];
|
|
75
|
+
if (byUser.length > 0) {
|
|
76
|
+
parts.push(`${names(byUser)} ${verb(byUser, 'keeps', 'keep')} one account per user, and ` +
|
|
77
|
+
'connect() runs as the application, which has none there.\n' +
|
|
78
|
+
'\n' +
|
|
79
|
+
'Run as the person the work is for:\n' +
|
|
80
|
+
'\n' +
|
|
81
|
+
" const agent = await tg.forEndUser('user_123')\n" +
|
|
82
|
+
'\n' +
|
|
83
|
+
`or have an administrator set ${names(byUser)} to a shared account in the ` +
|
|
84
|
+
"console (Registry, on the server's instance), and connect() works as it is.");
|
|
85
|
+
}
|
|
86
|
+
if (byAdmin.length > 0) {
|
|
87
|
+
parts.push(`${names(byAdmin)} ${verb(byAdmin, 'uses', 'use')} one shared account for every ` +
|
|
88
|
+
'caller, and nobody has connected it yet. An administrator connects it in the ' +
|
|
89
|
+
"console: Registry, on the server's instance, Connect.");
|
|
90
|
+
}
|
|
91
|
+
return parts.length > 0 ? parts.join('\n\n') : `${names(upstreams)} ${verb(upstreams, 'is', 'are')} not connected.`;
|
|
92
|
+
}
|
|
93
|
+
function names(upstreams) {
|
|
94
|
+
return upstreams.map((upstream) => `"${upstream.server}"`).join(', ');
|
|
95
|
+
}
|
|
96
|
+
function verb(upstreams, one, many) {
|
|
97
|
+
return upstreams.length === 1 ? one : many;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* An end user has not connected the account this call needs.
|
|
101
|
+
*
|
|
102
|
+
* The link comes with the error because the gateway mints it there: it is the
|
|
103
|
+
* page to put in front of that user, and it expires.
|
|
104
|
+
*/
|
|
105
|
+
export class ConsentRequiredError extends TrustGateError {
|
|
106
|
+
provider;
|
|
107
|
+
connectUrl;
|
|
108
|
+
cause_;
|
|
109
|
+
constructor(provider, connectUrl, cause_, message) {
|
|
110
|
+
super(message ?? `user consent required for ${provider}: open ${connectUrl}`, { code: 'consent_required' });
|
|
111
|
+
this.provider = provider;
|
|
112
|
+
this.connectUrl = connectUrl;
|
|
113
|
+
this.cause_ = cause_;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/** A policy on the gateway refused the call. Not retryable. */
|
|
117
|
+
export class PolicyBlockedError extends TrustGateError {
|
|
118
|
+
}
|
|
119
|
+
/** The tool is not on this consumer's surface — usually because it just left it. */
|
|
120
|
+
export class ToolNotFoundError extends TrustGateError {
|
|
121
|
+
tool;
|
|
122
|
+
constructor(tool, message) {
|
|
123
|
+
super(message ?? `the gateway does not serve a tool named "${tool}"`);
|
|
124
|
+
this.tool = tool;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/** The connect-attempt limiter refused this call. */
|
|
128
|
+
export class RateLimitedError extends TrustGateError {
|
|
129
|
+
retryAfterMs;
|
|
130
|
+
constructor(message, retryAfterMs) {
|
|
131
|
+
super(message, { status: 429, code: 'rate_limited' });
|
|
132
|
+
this.retryAfterMs = retryAfterMs;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/** The gateway could not serve the request and says so. Retryable. */
|
|
136
|
+
export class ServiceUnavailableError extends TrustGateError {
|
|
137
|
+
}
|
|
138
|
+
/** The gateway failed on its own account. */
|
|
139
|
+
export class TrustGateServerError extends TrustGateError {
|
|
140
|
+
}
|
|
141
|
+
/** The SDK was pointed at a plane this API key does not reach. */
|
|
142
|
+
export class PlaneUnavailableError extends TrustGateError {
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC/B,MAAM,CAAS;IACf,IAAI,CAAS;IAEtB,YAAY,OAAe,EAAE,UAA+D,EAAE;QAC7F,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAA;QACxC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAA;QAC3B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;QAC5B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;IACzB,CAAC;CACD;AAED,oEAAoE;AACpE,MAAM,OAAO,mBAAoB,SAAQ,cAAc;CAAG;AAE1D,0EAA0E;AAC1E,MAAM,OAAO,mBAAoB,SAAQ,cAAc;CAAG;AAE1D;;;;;;GAMG;AACH,MAAM,OAAO,iBAAkB,SAAQ,cAAc;IAC/B;IAA4B;IAAjD,YAAqB,OAAiB,EAAW,SAAmB;QACnE,KAAK,CACJ,qCAAqC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,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CAAG;AAEzD,oFAAoF;AACpF,MAAM,OAAO,iBAAkB,SAAQ,cAAc;IAC/B;IAArB,YAAqB,IAAY,EAAE,OAAgB;QAClD,KAAK,CAAC,OAAO,IAAI,4CAA4C,IAAI,GAAG,CAAC,CAAA;QADjD,SAAI,GAAJ,IAAI,CAAQ;IAEjC,CAAC;CACD;AAED,qDAAqD;AACrD,MAAM,OAAO,gBAAiB,SAAQ,cAAc;IACb;IAAtC,YAAY,OAAe,EAAW,YAAqB;QAC1D,KAAK,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAA;QADhB,iBAAY,GAAZ,YAAY,CAAS;IAE3D,CAAC;CACD;AAED,sEAAsE;AACtE,MAAM,OAAO,uBAAwB,SAAQ,cAAc;CAAG;AAE9D,6CAA6C;AAC7C,MAAM,OAAO,oBAAqB,SAAQ,cAAc;CAAG;AAE3D,kEAAkE;AAClE,MAAM,OAAO,qBAAsB,SAAQ,cAAc;CAAG"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ToolFormat, type GatewayTool, type JSONSchema, type ToolCall } from "./types.js";
|
|
2
|
+
export type ConversionWarning = {
|
|
3
|
+
tool: string;
|
|
4
|
+
reason: string;
|
|
5
|
+
};
|
|
6
|
+
export type Conversion = {
|
|
7
|
+
tools: unknown[];
|
|
8
|
+
warnings: ConversionWarning[];
|
|
9
|
+
/** The schema each tool had before translation, for the return trip. */
|
|
10
|
+
originals: Map<string, JSONSchema>;
|
|
11
|
+
};
|
|
12
|
+
export type ToolResult = {
|
|
13
|
+
call: ToolCall;
|
|
14
|
+
result: Record<string, unknown>;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Each provider's function-calling dialect, in one place.
|
|
18
|
+
*
|
|
19
|
+
* A format knows three things: how to describe a tool, how to recognise the
|
|
20
|
+
* model asking for one, and how to hand the answer back. They are grouped per
|
|
21
|
+
* provider rather than per agent framework on purpose — a framework brings its
|
|
22
|
+
* own MCP client and never sees any of this.
|
|
23
|
+
*/
|
|
24
|
+
export type FormatAdapter = {
|
|
25
|
+
convert(tools: GatewayTool[], options: {
|
|
26
|
+
strict: boolean;
|
|
27
|
+
}): Conversion;
|
|
28
|
+
extractCalls(output: unknown): ToolCall[];
|
|
29
|
+
toOutputs(results: ToolResult[]): unknown[];
|
|
30
|
+
};
|
|
31
|
+
export declare function adapterFor(format: ToolFormat): FormatAdapter;
|
|
32
|
+
/** Undoes whatever the outbound conversion added to the arguments. */
|
|
33
|
+
export declare function restoreArguments(args: Record<string, unknown>, original: JSONSchema | undefined): Record<string, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* What the model gets back from a tool.
|
|
36
|
+
*
|
|
37
|
+
* A structured result is the one worth giving it, since that is what the tool
|
|
38
|
+
* promised in its output schema; the text blocks are the fallback, and the
|
|
39
|
+
* whole result is the last resort. A tool that failed still answers here
|
|
40
|
+
* rather than throwing: MCP puts tool errors in the result precisely so the
|
|
41
|
+
* model can read them and correct itself.
|
|
42
|
+
*/
|
|
43
|
+
export declare function resultToText(result: Record<string, unknown>): string;
|
|
44
|
+
//# sourceMappingURL=formats.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formats.d.ts","sourceRoot":"","sources":["../src/formats.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EACV,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,QAAQ,EACd,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,iBAAiB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjE,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,QAAQ,EAAE,iBAAiB,EAAE,CAAC;IAC9B,wEAAwE;IACxE,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CAAC;AAE7E;;;;;;;GAOG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE,OAAO,EAAE;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,GAAG,UAAU,CAAC;IACxE,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,QAAQ,EAAE,CAAC;IAC1C,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,OAAO,EAAE,CAAC;CAC7C,CAAC;AAEF,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,aAAa,CAI5D;AAED,sEAAsE;AACtE,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,QAAQ,EAAE,UAAU,GAAG,SAAS,GAC/B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzB;AA2RD;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAYpE"}
|
package/dist/formats.js
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { inlineRefs, stripInjectedNulls, toStrict } from "./schema.js";
|
|
2
|
+
import { ToolFormat, } from "./types.js";
|
|
3
|
+
export function adapterFor(format) {
|
|
4
|
+
const adapter = ADAPTERS[format];
|
|
5
|
+
if (!adapter)
|
|
6
|
+
throw new Error(`unknown tool format "${format}"`);
|
|
7
|
+
return adapter;
|
|
8
|
+
}
|
|
9
|
+
/** Undoes whatever the outbound conversion added to the arguments. */
|
|
10
|
+
export function restoreArguments(args, original) {
|
|
11
|
+
return stripInjectedNulls(args, original);
|
|
12
|
+
}
|
|
13
|
+
function convertWith(tools, options, shape) {
|
|
14
|
+
const warnings = [];
|
|
15
|
+
const originals = new Map();
|
|
16
|
+
const converted = tools.map((tool) => {
|
|
17
|
+
originals.set(tool.name, tool.inputSchema);
|
|
18
|
+
if (!options.strict)
|
|
19
|
+
return shape(tool, inlineRefs(tool.inputSchema), false);
|
|
20
|
+
const result = toStrict(tool.inputSchema);
|
|
21
|
+
if (!result.strict)
|
|
22
|
+
warnings.push({ tool: tool.name, reason: result.reason ?? "unknown" });
|
|
23
|
+
return shape(tool, result.schema, result.strict);
|
|
24
|
+
});
|
|
25
|
+
return { tools: converted, warnings, originals };
|
|
26
|
+
}
|
|
27
|
+
const openAIResponses = {
|
|
28
|
+
convert: (tools, options) => convertWith(tools, options, (tool, schema, strict) => ({
|
|
29
|
+
type: "function",
|
|
30
|
+
name: tool.name,
|
|
31
|
+
description: tool.description ?? "",
|
|
32
|
+
parameters: schema,
|
|
33
|
+
strict,
|
|
34
|
+
})),
|
|
35
|
+
extractCalls(output) {
|
|
36
|
+
// Accepts the whole response or just its output array, because both are
|
|
37
|
+
// what people have in hand at the call site.
|
|
38
|
+
const items = Array.isArray(output)
|
|
39
|
+
? output
|
|
40
|
+
: (output?.output ?? []);
|
|
41
|
+
return items.flatMap((item) => {
|
|
42
|
+
const call = item;
|
|
43
|
+
if (call.type !== "function_call")
|
|
44
|
+
return [];
|
|
45
|
+
return [
|
|
46
|
+
{
|
|
47
|
+
id: String(call.call_id ?? call.id ?? ""),
|
|
48
|
+
name: String(call.name ?? ""),
|
|
49
|
+
arguments: parseArguments(call.arguments),
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
toOutputs: (results) => results.map(({ call, result }) => ({
|
|
55
|
+
type: "function_call_output",
|
|
56
|
+
call_id: call.id,
|
|
57
|
+
output: resultToText(result),
|
|
58
|
+
})),
|
|
59
|
+
};
|
|
60
|
+
const openAIChat = {
|
|
61
|
+
convert: (tools, options) => convertWith(tools, options, (tool, schema, strict) => ({
|
|
62
|
+
type: "function",
|
|
63
|
+
function: {
|
|
64
|
+
name: tool.name,
|
|
65
|
+
description: tool.description ?? "",
|
|
66
|
+
parameters: schema,
|
|
67
|
+
strict,
|
|
68
|
+
},
|
|
69
|
+
})),
|
|
70
|
+
extractCalls(output) {
|
|
71
|
+
const calls = Array.isArray(output)
|
|
72
|
+
? output
|
|
73
|
+
: (output
|
|
74
|
+
?.choices?.[0]?.message?.tool_calls ?? []);
|
|
75
|
+
return calls.flatMap((item) => {
|
|
76
|
+
const call = item;
|
|
77
|
+
if (!call.function)
|
|
78
|
+
return [];
|
|
79
|
+
return [
|
|
80
|
+
{
|
|
81
|
+
id: String(call.id ?? ""),
|
|
82
|
+
name: String(call.function.name ?? ""),
|
|
83
|
+
arguments: parseArguments(call.function.arguments),
|
|
84
|
+
},
|
|
85
|
+
];
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
toOutputs: (results) => results.map(({ call, result }) => ({
|
|
89
|
+
role: "tool",
|
|
90
|
+
tool_call_id: call.id,
|
|
91
|
+
content: resultToText(result),
|
|
92
|
+
})),
|
|
93
|
+
};
|
|
94
|
+
const anthropicMessages = {
|
|
95
|
+
convert: (tools, options) =>
|
|
96
|
+
// Anthropic takes plain JSON Schema, so strict has nothing to add here:
|
|
97
|
+
// asking for it would close objects for no gain.
|
|
98
|
+
convertWith(tools, { strict: false }, (tool, schema) => ({
|
|
99
|
+
name: tool.name,
|
|
100
|
+
description: tool.description ?? "",
|
|
101
|
+
input_schema: schema,
|
|
102
|
+
})),
|
|
103
|
+
extractCalls(output) {
|
|
104
|
+
const content = Array.isArray(output)
|
|
105
|
+
? output
|
|
106
|
+
: (output?.content ?? []);
|
|
107
|
+
return content.flatMap((item) => {
|
|
108
|
+
const block = item;
|
|
109
|
+
if (block.type !== "tool_use")
|
|
110
|
+
return [];
|
|
111
|
+
return [
|
|
112
|
+
{
|
|
113
|
+
id: String(block.id ?? ""),
|
|
114
|
+
name: String(block.name ?? ""),
|
|
115
|
+
arguments: block.input ?? {},
|
|
116
|
+
},
|
|
117
|
+
];
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
// No results means the model called nothing, and that is what an empty array
|
|
121
|
+
// says. A message wrapped around no blocks says the opposite — and Anthropic
|
|
122
|
+
// refuses a user message with no content, so the turn a caller reads as "keep
|
|
123
|
+
// going" is the one that cannot be sent.
|
|
124
|
+
toOutputs: (results) => results.length === 0
|
|
125
|
+
? []
|
|
126
|
+
: [
|
|
127
|
+
{
|
|
128
|
+
role: "user",
|
|
129
|
+
content: results.map(({ call, result }) => ({
|
|
130
|
+
type: "tool_result",
|
|
131
|
+
tool_use_id: call.id,
|
|
132
|
+
content: resultToText(result),
|
|
133
|
+
...(result.isError === true ? { is_error: true } : {}),
|
|
134
|
+
})),
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
};
|
|
138
|
+
const gemini = {
|
|
139
|
+
convert(tools, _options) {
|
|
140
|
+
const warnings = [];
|
|
141
|
+
const originals = new Map();
|
|
142
|
+
const declarations = tools.map((tool) => {
|
|
143
|
+
originals.set(tool.name, tool.inputSchema);
|
|
144
|
+
const { schema, dropped } = geminiSchema(inlineRefs(tool.inputSchema));
|
|
145
|
+
if (dropped.length > 0) {
|
|
146
|
+
warnings.push({
|
|
147
|
+
tool: tool.name,
|
|
148
|
+
reason: `dropped keywords Gemini does not accept: ${[...new Set(dropped)].join(", ")}`,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
name: tool.name,
|
|
153
|
+
description: tool.description ?? "",
|
|
154
|
+
parameters: schema,
|
|
155
|
+
};
|
|
156
|
+
});
|
|
157
|
+
return {
|
|
158
|
+
tools: [{ functionDeclarations: declarations }],
|
|
159
|
+
warnings,
|
|
160
|
+
originals,
|
|
161
|
+
};
|
|
162
|
+
},
|
|
163
|
+
extractCalls(output) {
|
|
164
|
+
const parts = Array.isArray(output)
|
|
165
|
+
? output
|
|
166
|
+
: (output
|
|
167
|
+
?.candidates?.[0]?.content?.parts ?? []);
|
|
168
|
+
return parts.flatMap((item, index) => {
|
|
169
|
+
const part = item;
|
|
170
|
+
if (!part.functionCall)
|
|
171
|
+
return [];
|
|
172
|
+
const name = String(part.functionCall.name ?? "");
|
|
173
|
+
return [
|
|
174
|
+
{
|
|
175
|
+
// Gemini does not give a call an id, so one is made from its
|
|
176
|
+
// position — enough to pair a result with its call.
|
|
177
|
+
id: `${name}:${index}`,
|
|
178
|
+
name,
|
|
179
|
+
arguments: part.functionCall.args ?? {},
|
|
180
|
+
},
|
|
181
|
+
];
|
|
182
|
+
});
|
|
183
|
+
},
|
|
184
|
+
// Empty means the model called nothing; see anthropicMessages.
|
|
185
|
+
toOutputs: (results) => results.length === 0
|
|
186
|
+
? []
|
|
187
|
+
: [
|
|
188
|
+
{
|
|
189
|
+
role: "user",
|
|
190
|
+
parts: results.map(({ call, result }) => ({
|
|
191
|
+
functionResponse: {
|
|
192
|
+
name: call.name,
|
|
193
|
+
response: resultToResponse(result),
|
|
194
|
+
},
|
|
195
|
+
})),
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
};
|
|
199
|
+
const ADAPTERS = {
|
|
200
|
+
[ToolFormat.OpenAIResponses]: openAIResponses,
|
|
201
|
+
[ToolFormat.OpenAIChat]: openAIChat,
|
|
202
|
+
[ToolFormat.AnthropicMessages]: anthropicMessages,
|
|
203
|
+
[ToolFormat.Gemini]: gemini,
|
|
204
|
+
};
|
|
205
|
+
/** Keywords Gemini's function declarations accept; everything else is dropped. */
|
|
206
|
+
const GEMINI_KEYWORDS = new Set([
|
|
207
|
+
"type",
|
|
208
|
+
"format",
|
|
209
|
+
"description",
|
|
210
|
+
"nullable",
|
|
211
|
+
"enum",
|
|
212
|
+
"properties",
|
|
213
|
+
"required",
|
|
214
|
+
"items",
|
|
215
|
+
"anyOf",
|
|
216
|
+
"minimum",
|
|
217
|
+
"maximum",
|
|
218
|
+
]);
|
|
219
|
+
function geminiSchema(schema) {
|
|
220
|
+
const dropped = [];
|
|
221
|
+
// Inside `properties` the keys are the caller's own property names, not
|
|
222
|
+
// schema keywords, so they are carried across untouched — filtering them
|
|
223
|
+
// would delete the arguments rather than the syntax.
|
|
224
|
+
const walkProperties = (node) => {
|
|
225
|
+
if (typeof node !== "object" || node === null)
|
|
226
|
+
return node;
|
|
227
|
+
const out = {};
|
|
228
|
+
for (const [name, value] of Object.entries(node)) {
|
|
229
|
+
out[name] = walk(value);
|
|
230
|
+
}
|
|
231
|
+
return out;
|
|
232
|
+
};
|
|
233
|
+
const walk = (node) => {
|
|
234
|
+
if (Array.isArray(node))
|
|
235
|
+
return node.map(walk);
|
|
236
|
+
if (typeof node !== "object" || node === null)
|
|
237
|
+
return node;
|
|
238
|
+
const out = {};
|
|
239
|
+
for (const [key, value] of Object.entries(node)) {
|
|
240
|
+
if (!GEMINI_KEYWORDS.has(key)) {
|
|
241
|
+
dropped.push(key);
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
if (key === "properties") {
|
|
245
|
+
out[key] = walkProperties(value);
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
out[key] = key === "required" || key === "enum" ? value : walk(value);
|
|
249
|
+
}
|
|
250
|
+
return out;
|
|
251
|
+
};
|
|
252
|
+
return { schema: walk(schema), dropped };
|
|
253
|
+
}
|
|
254
|
+
function parseArguments(raw) {
|
|
255
|
+
if (typeof raw === "object" && raw !== null)
|
|
256
|
+
return raw;
|
|
257
|
+
if (typeof raw !== "string" || raw.trim() === "")
|
|
258
|
+
return {};
|
|
259
|
+
try {
|
|
260
|
+
const parsed = JSON.parse(raw);
|
|
261
|
+
return typeof parsed === "object" && parsed !== null
|
|
262
|
+
? parsed
|
|
263
|
+
: {};
|
|
264
|
+
}
|
|
265
|
+
catch {
|
|
266
|
+
return {};
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* What the model gets back from a tool.
|
|
271
|
+
*
|
|
272
|
+
* A structured result is the one worth giving it, since that is what the tool
|
|
273
|
+
* promised in its output schema; the text blocks are the fallback, and the
|
|
274
|
+
* whole result is the last resort. A tool that failed still answers here
|
|
275
|
+
* rather than throwing: MCP puts tool errors in the result precisely so the
|
|
276
|
+
* model can read them and correct itself.
|
|
277
|
+
*/
|
|
278
|
+
export function resultToText(result) {
|
|
279
|
+
if (result.structuredContent !== undefined)
|
|
280
|
+
return JSON.stringify(result.structuredContent);
|
|
281
|
+
const content = result.content;
|
|
282
|
+
if (Array.isArray(content)) {
|
|
283
|
+
const text = content
|
|
284
|
+
.filter((block) => block.type === "text")
|
|
285
|
+
.map((block) => String(block.text ?? ""))
|
|
286
|
+
.join("\n");
|
|
287
|
+
if (text)
|
|
288
|
+
return text;
|
|
289
|
+
}
|
|
290
|
+
return JSON.stringify(result);
|
|
291
|
+
}
|
|
292
|
+
function resultToResponse(result) {
|
|
293
|
+
if (result.structuredContent !== undefined &&
|
|
294
|
+
typeof result.structuredContent === "object") {
|
|
295
|
+
return result.structuredContent;
|
|
296
|
+
}
|
|
297
|
+
return { result: resultToText(result) };
|
|
298
|
+
}
|
|
299
|
+
//# sourceMappingURL=formats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formats.js","sourceRoot":"","sources":["../src/formats.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EACL,UAAU,GAIX,MAAM,YAAY,CAAC;AA2BpB,MAAM,UAAU,UAAU,CAAC,MAAkB;IAC3C,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,MAAM,GAAG,CAAC,CAAC;IACjE,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,gBAAgB,CAC9B,IAA6B,EAC7B,QAAgC;IAEhC,OAAO,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,KAAK,EAAE,EAAE,CAAE,KAA2B,CAAC,IAAI,KAAK,MAAM,CAAC;aAC/D,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAE,KAA4B,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;aAChE,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,IAAI,IAAI;YAAE,OAAO,IAAI,CAAC;IACxB,CAAC;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC;AAED,SAAS,gBAAgB,CACvB,MAA+B;IAE/B,IACE,MAAM,CAAC,iBAAiB,KAAK,SAAS;QACtC,OAAO,MAAM,CAAC,iBAAiB,KAAK,QAAQ,EAC5C,CAAC;QACD,OAAO,MAAM,CAAC,iBAA4C,CAAC;IAC7D,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;AAC1C,CAAC"}
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ResolvedConfig } from './config.js';
|
|
2
|
+
export type ErrorBody = {
|
|
3
|
+
error?: string;
|
|
4
|
+
message?: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* A JSON request against the gateway's REST surface (the connections API).
|
|
8
|
+
*
|
|
9
|
+
* The gateway answers `{error, message}` on failure; this turns each `error`
|
|
10
|
+
* code into the type that says whose problem it is. `expect` names statuses
|
|
11
|
+
* the caller handles itself — the actor probe uses it to read a 409 as an
|
|
12
|
+
* answer rather than a failure.
|
|
13
|
+
*/
|
|
14
|
+
export declare function requestJSON<T>(config: ResolvedConfig, method: string, path: string, options?: {
|
|
15
|
+
body?: unknown;
|
|
16
|
+
headers?: Record<string, string>;
|
|
17
|
+
expect?: number[];
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
}): Promise<{
|
|
20
|
+
status: number;
|
|
21
|
+
body: T;
|
|
22
|
+
}>;
|
|
23
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,aAAa,CAAA;AAUjE,MAAM,MAAM,SAAS,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAE5D;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAClC,MAAM,EAAE,cAAc,EACtB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAO,GACzG,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC,CA8BtC"}
|