@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/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and do
|
|
117
|
+
not modify the License. You may add Your own attribution notices
|
|
118
|
+
within Derivative Works that You distribute, alongside or as an
|
|
119
|
+
addendum to the NOTICE text from the Work, provided that such
|
|
120
|
+
additional attribution notices cannot be construed as modifying
|
|
121
|
+
the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 NeuralTrust
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# @neuraltrust/trustgate
|
|
2
|
+
|
|
3
|
+
The TrustGate SDK for TypeScript. Node 18+, no runtime dependencies. ESM only:
|
|
4
|
+
import it, or `require()` it on Node 20.19+ or 22.12+.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
npm install @neuraltrust/trustgate
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Setup
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { TrustGate, ToolFormat } from '@neuraltrust/trustgate'
|
|
14
|
+
|
|
15
|
+
const tg = new TrustGate() // TRUSTGATE_URL + TRUSTGATE_API_KEY
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Two values, or none if they are in the environment. The applications behind
|
|
19
|
+
the key are asked for: `tg.identity()` asks the gateway once and remembers it.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
const { gateway, key, consumers } = await tg.identity()
|
|
23
|
+
// key: { name: 'prod', expiresAt: Date | undefined } — undefined means never
|
|
24
|
+
// consumers:
|
|
25
|
+
// [{ slug: 'support-agent', type: 'MCP', url: 'https://…/support-agent/mcp',
|
|
26
|
+
// upstreams: [{ server: 'Notion', account: 'shared', connected: true }] },
|
|
27
|
+
// { slug: 'support-llm', type: 'LLM', url: 'https://…/support-llm/v1' }]
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`key.expiresAt` is the 401 you would otherwise meet mid-run, and `upstreams`
|
|
31
|
+
is the refusal you would otherwise meet on the first tool call — both answered
|
|
32
|
+
before anything starts.
|
|
33
|
+
|
|
34
|
+
`mcpConsumer` and `llmConsumer` (or `TRUSTGATE_MCP_CONSUMER` /
|
|
35
|
+
`TRUSTGATE_LLM_CONSUMER`) are only needed when a key reaches two applications on
|
|
36
|
+
the same plane — the SDK names them and refuses rather than guessing.
|
|
37
|
+
|
|
38
|
+
## An agent that acts as the application
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
const agent = await tg.connect({ requires: ['search'] })
|
|
42
|
+
|
|
43
|
+
agent.mcp // { url, headers } for a framework
|
|
44
|
+
await tg.llm() // baseUrl for OpenAI, anthropicBaseUrl for Anthropic
|
|
45
|
+
agent.toolkit(ToolFormat.OpenAIResponses) // { tools, execute, warnings }
|
|
46
|
+
await agent.callTool('search', { query: 'runbook' })
|
|
47
|
+
await agent.refresh() // re-read the toolkit
|
|
48
|
+
agent.connections // its own upstream accounts
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The gateway serves a tool under the server it came from — Notion's `search` as
|
|
52
|
+
`notion_search` — so two servers with a `search` stay apart. That prefix is the
|
|
53
|
+
gateway's, so `requires` and `callTool` take the name the server itself gave the
|
|
54
|
+
tool and add it; naming a tool two of your servers serve is the one case they
|
|
55
|
+
ask instead.
|
|
56
|
+
|
|
57
|
+
## An agent acting for one of its users
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
const alice = await tg.forEndUser('user_123')
|
|
61
|
+
// or, from an agent you already have — no round trip, same toolkit:
|
|
62
|
+
const bob = agent.forEndUser('user_456')
|
|
63
|
+
|
|
64
|
+
await alice.connections()
|
|
65
|
+
await alice.connectLink('com.notion/mcp')
|
|
66
|
+
alice.toolkit(ToolFormat.AnthropicMessages)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Both handles work on the same application and the same key: who a call runs as
|
|
70
|
+
comes from the call, not from anything configured on the application. Each user
|
|
71
|
+
needs their own handle because the MCP endpoint fixes its headers when a client
|
|
72
|
+
connects, and the user travels in one.
|
|
73
|
+
|
|
74
|
+
The name is yours to choose and the gateway namespaces it, so two applications
|
|
75
|
+
naming `user_123` never reach the same account.
|
|
76
|
+
|
|
77
|
+
## The provider's types
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
const { tools, execute } = agent.toolkit<
|
|
81
|
+
OpenAI.Responses.Tool,
|
|
82
|
+
OpenAI.Responses.ResponseInputItem
|
|
83
|
+
>(ToolFormat.OpenAIResponses)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`toolkit<Tool, Output>()` names the two types the provider cares about: what
|
|
87
|
+
`tools` is, and what `execute()` hands back to it. Both default to `unknown`,
|
|
88
|
+
so naming them is what lets `tools` go straight into `openai.responses.create`
|
|
89
|
+
without a cast. The SDK depends on no provider package — the types come from
|
|
90
|
+
yours.
|
|
91
|
+
|
|
92
|
+
`tools` and `execute` are safe to destructure; the executor stays bound to the
|
|
93
|
+
format it was made with.
|
|
94
|
+
|
|
95
|
+
## Strict mode
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
const { tools, warnings } = agent.toolkit(ToolFormat.OpenAIResponses, { strict: true })
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Strict buys a guarantee — the model cannot invent an argument — by closing
|
|
102
|
+
every object, naming every property as required, and letting the optional ones
|
|
103
|
+
accept `null`. Some schemas cannot be said that way (arbitrary keys, `allOf`,
|
|
104
|
+
`prefixItems`, an unresolvable `$ref`); those are emitted unchanged and listed
|
|
105
|
+
in `warnings`, because a tool the model calls imperfectly beats one it cannot
|
|
106
|
+
call.
|
|
107
|
+
|
|
108
|
+
`execute()` undoes the rewrite before the call reaches the gateway: the nulls
|
|
109
|
+
strict asked for are stripped unless the tool's own schema accepts them.
|
|
110
|
+
|
|
111
|
+
## Errors
|
|
112
|
+
|
|
113
|
+
| Class | When |
|
|
114
|
+
|---|---|
|
|
115
|
+
| `MissingToolsError` | `requires` names a tool the application does not serve |
|
|
116
|
+
| `UpstreamNotConnectedError` | a server the application calls has no account behind it; `servers` names them and the message says who connects it |
|
|
117
|
+
| `ConsentRequiredError` | an end user has not connected; carries `connectUrl` |
|
|
118
|
+
| `PolicyBlockedError` | a gateway policy refused the call |
|
|
119
|
+
| `ToolNotFoundError` | the tool left the toolkit under a running agent |
|
|
120
|
+
| `PlaneUnavailableError` | the key reaches no application on that plane |
|
|
121
|
+
| `AuthenticationError`, `RateLimitedError`, `ServiceUnavailableError`, `TrustGateServerError` | as named |
|
|
122
|
+
|
|
123
|
+
## Development
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
npm ci
|
|
127
|
+
npm run typecheck
|
|
128
|
+
npm test
|
|
129
|
+
npm run build
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
[CONTRIBUTING.md](../CONTRIBUTING.md) has every check CI runs.
|
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { type ResolvedConfig } from './config.js';
|
|
2
|
+
import { ToolNotFoundError } from './errors.js';
|
|
3
|
+
import { type ConversionWarning } from './formats.js';
|
|
4
|
+
import { MCPTransport } from './mcp.js';
|
|
5
|
+
import { ToolFormat, type ConnectLink, type Connection, type Endpoint, type GatewayTool, type JSONSchema, type ToolCall } from './types.js';
|
|
6
|
+
export type ToolkitOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* Ask the provider to hold the model to the schema. Off by default: it is
|
|
9
|
+
* a stricter promise bought with a lossy rewrite, and some tools cannot be
|
|
10
|
+
* expressed under it at all (see `warnings`).
|
|
11
|
+
*/
|
|
12
|
+
strict?: boolean;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* A tool surface in one provider's dialect, with the executor that belongs to
|
|
16
|
+
* it.
|
|
17
|
+
*
|
|
18
|
+
* They travel together because they are two halves of one translation: what
|
|
19
|
+
* `tools` added on the way out, `execute` has to undo on the way back.
|
|
20
|
+
*
|
|
21
|
+
* `Tool` and `Output` are the provider's own types, named by the caller:
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* const { tools, execute } = agent.toolkit<
|
|
25
|
+
* OpenAI.Responses.Tool,
|
|
26
|
+
* OpenAI.Responses.ResponseInputItem
|
|
27
|
+
* >(ToolFormat.OpenAIResponses)
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* They default to `unknown`, so nothing breaks by leaving them out — but then
|
|
31
|
+
* "pass this straight to the provider's API" is a promise the type does not
|
|
32
|
+
* keep, and the caller casts at the boundary. The SDK cannot name them itself:
|
|
33
|
+
* it carries no dependency on any provider's package, which is what lets one
|
|
34
|
+
* install serve all of them.
|
|
35
|
+
*/
|
|
36
|
+
export declare class Toolkit<Tool = unknown, Output = unknown> {
|
|
37
|
+
/** Pass this straight to the provider's API. */
|
|
38
|
+
readonly tools: Tool[];
|
|
39
|
+
/** Tools whose schema could not be expressed in the requested dialect. */
|
|
40
|
+
readonly warnings: ConversionWarning[];
|
|
41
|
+
private readonly format;
|
|
42
|
+
private readonly originals;
|
|
43
|
+
private readonly transport;
|
|
44
|
+
constructor(
|
|
45
|
+
/** Pass this straight to the provider's API. */
|
|
46
|
+
tools: Tool[],
|
|
47
|
+
/** Tools whose schema could not be expressed in the requested dialect. */
|
|
48
|
+
warnings: ConversionWarning[], format: ToolFormat, originals: Map<string, JSONSchema>, transport: MCPTransport);
|
|
49
|
+
/** The calls the model asked for, read out of the provider's response. */
|
|
50
|
+
calls(output: unknown): ToolCall[];
|
|
51
|
+
/**
|
|
52
|
+
* Runs the calls the model asked for and returns what to send back.
|
|
53
|
+
*
|
|
54
|
+
* Every call goes to the gateway, so the policy, the audit trail and the
|
|
55
|
+
* upstream credentials stay where they were. The caller's process only
|
|
56
|
+
* decides whether to make the call at all.
|
|
57
|
+
*/
|
|
58
|
+
execute(output: unknown, signal?: AbortSignal): Promise<Output[]>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* An application's handle on its gateway.
|
|
62
|
+
*
|
|
63
|
+
* It speaks as the application itself: one principal, its own upstream
|
|
64
|
+
* accounts, nothing per-user. Which handle you get is not a choice made here —
|
|
65
|
+
* it follows from how the consumer was configured, which is why `connect()`
|
|
66
|
+
* returns one of these or refuses.
|
|
67
|
+
*/
|
|
68
|
+
export declare class Agent {
|
|
69
|
+
private readonly config;
|
|
70
|
+
readonly slug: string;
|
|
71
|
+
private readonly transport;
|
|
72
|
+
/** The tools this consumer serves, as the gateway named them. */
|
|
73
|
+
tools: GatewayTool[];
|
|
74
|
+
/** Tools asked for in `requires` that the toolkit does not carry. */
|
|
75
|
+
readonly missing: string[];
|
|
76
|
+
/** The application's own upstream accounts, as of `connect()`. */
|
|
77
|
+
readonly connections: Connection[];
|
|
78
|
+
readonly actor: "application";
|
|
79
|
+
constructor(config: ResolvedConfig, slug: string, transport: MCPTransport,
|
|
80
|
+
/** The tools this consumer serves, as the gateway named them. */
|
|
81
|
+
tools: GatewayTool[],
|
|
82
|
+
/** Tools asked for in `requires` that the toolkit does not carry. */
|
|
83
|
+
missing: string[],
|
|
84
|
+
/** The application's own upstream accounts, as of `connect()`. */
|
|
85
|
+
connections: Connection[]);
|
|
86
|
+
/** URL and headers for a framework that brings its own MCP client. */
|
|
87
|
+
get mcp(): Endpoint;
|
|
88
|
+
/**
|
|
89
|
+
* The same surface, translated for a provider you call directly.
|
|
90
|
+
*
|
|
91
|
+
* Name the provider's types to have them travel with it:
|
|
92
|
+
* `toolkit<OpenAI.Responses.Tool, OpenAI.Responses.ResponseInputItem>(…)`.
|
|
93
|
+
*/
|
|
94
|
+
toolkit<Tool = unknown, Output = unknown>(format: ToolFormat, options?: ToolkitOptions): Toolkit<Tool, Output>;
|
|
95
|
+
/**
|
|
96
|
+
* One tool, called directly. The escape hatch under the toolkits.
|
|
97
|
+
*
|
|
98
|
+
* The server prefix is optional here: "list_issues" reaches
|
|
99
|
+
* "linear_list_issues" while Linear is the only server of this application
|
|
100
|
+
* that serves it. The gateway put that prefix there, so a caller writing the
|
|
101
|
+
* name by hand should not have to.
|
|
102
|
+
*/
|
|
103
|
+
callTool(name: string, args?: Record<string, unknown>, signal?: AbortSignal): Promise<Record<string, unknown>>;
|
|
104
|
+
/**
|
|
105
|
+
* Re-reads the surface.
|
|
106
|
+
*
|
|
107
|
+
* An admin owns this toolkit and can change it under a running agent, so a
|
|
108
|
+
* long-lived process re-reads rather than trusting the list it took at
|
|
109
|
+
* startup.
|
|
110
|
+
*/
|
|
111
|
+
refresh(signal?: AbortSignal): Promise<GatewayTool[]>;
|
|
112
|
+
/** What the application still owes before it can call every server. */
|
|
113
|
+
refreshConnections(signal?: AbortSignal): Promise<Connection[]>;
|
|
114
|
+
/**
|
|
115
|
+
* The same application, acting for one named person.
|
|
116
|
+
*
|
|
117
|
+
* No round trip and no second surface to read: the toolkit an admin bound
|
|
118
|
+
* is the application's, identical for everyone it acts for. What changes is
|
|
119
|
+
* one header, and with it whose upstream account the gateway reaches for.
|
|
120
|
+
*/
|
|
121
|
+
forEndUser(endUser: string): EndUserAgent;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* An application's handle for one of its own end users.
|
|
125
|
+
*
|
|
126
|
+
* The user travels in a header, so a handle is a header and nothing more —
|
|
127
|
+
* but the MCP endpoint's headers are fixed when a client connects, which is
|
|
128
|
+
* why each user needs their own transport rather than a shared one.
|
|
129
|
+
*/
|
|
130
|
+
export declare class EndUserAgent {
|
|
131
|
+
private readonly config;
|
|
132
|
+
readonly slug: string;
|
|
133
|
+
readonly endUser: string;
|
|
134
|
+
private readonly transport;
|
|
135
|
+
tools: GatewayTool[];
|
|
136
|
+
readonly actor: "end_user";
|
|
137
|
+
constructor(config: ResolvedConfig, slug: string, endUser: string, transport: MCPTransport, tools: GatewayTool[]);
|
|
138
|
+
get mcp(): Endpoint;
|
|
139
|
+
toolkit<Tool = unknown, Output = unknown>(format: ToolFormat, options?: ToolkitOptions): Toolkit<Tool, Output>;
|
|
140
|
+
callTool(name: string, args?: Record<string, unknown>, signal?: AbortSignal): Promise<Record<string, unknown>>;
|
|
141
|
+
refresh(signal?: AbortSignal): Promise<GatewayTool[]>;
|
|
142
|
+
/** Which servers this user has connected, and which they have not. */
|
|
143
|
+
connections(signal?: AbortSignal): Promise<Connection[]>;
|
|
144
|
+
/**
|
|
145
|
+
* The page to put in front of this user so they can connect an account.
|
|
146
|
+
*
|
|
147
|
+
* Naming a provider narrows it to that one server; omitting it covers every
|
|
148
|
+
* server of the application that forwards a credential. The link expires,
|
|
149
|
+
* so it is minted when it is about to be shown, not cached.
|
|
150
|
+
*/
|
|
151
|
+
connectLink(provider?: string, signal?: AbortSignal): Promise<ConnectLink>;
|
|
152
|
+
}
|
|
153
|
+
/** Builds the per-user handle, with the header that names them. */
|
|
154
|
+
export declare function endUserAgent(config: ResolvedConfig, slug: string, rawEndUser: string, url: string, tools: GatewayTool[]): EndUserAgent;
|
|
155
|
+
export { ToolNotFoundError };
|
|
156
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,cAAc,EAAE,MAAM,aAAa,CAAA;AAElE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAgC,KAAK,iBAAiB,EAAmB,MAAM,cAAc,CAAA;AACpG,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,EAEN,UAAU,EAEV,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,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