@opengeni/tool-gateway 0.1.0-canary.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 +190 -0
- package/README.md +69 -0
- package/dist/catalog.d.ts +7 -0
- package/dist/declarations.d.ts +21 -0
- package/dist/errors.d.ts +32 -0
- package/dist/index.d.ts +136 -0
- package/dist/index.js +663 -0
- package/dist/index.js.map +1 -0
- package/package.json +43 -0
- package/src/catalog.ts +57 -0
- package/src/declarations.ts +334 -0
- package/src/errors.ts +75 -0
- package/src/index.ts +525 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
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
|
|
95
|
+
Derivative 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
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying 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
|
+
Copyright 2026 Cloudgeni-ai
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# `@opengeni/tool-gateway`
|
|
2
|
+
|
|
3
|
+
Protocol-neutral catalog validation, authorization, and execution for OpenGeni
|
|
4
|
+
tools. Runtime composition supplies already-admitted first-party and integration
|
|
5
|
+
definitions; this package gives model MCP, Codemode, HTTP/SDK, external MCP, and
|
|
6
|
+
Site adapters one canonical identity and execution path.
|
|
7
|
+
|
|
8
|
+
The package owns:
|
|
9
|
+
|
|
10
|
+
- deterministic catalog digests that exclude non-authoritative timestamps;
|
|
11
|
+
- exact `{ serverId, toolName }` identities, normalized exact-name
|
|
12
|
+
disambiguation, and catalog-time rejection of namespace/tool prefix
|
|
13
|
+
collisions;
|
|
14
|
+
- bounded catalog, JSON Schema input/output validation, and generated SDK
|
|
15
|
+
declarations;
|
|
16
|
+
- caller-aware authorization and approval classification; and
|
|
17
|
+
- result-shape preservation around the supplied executor closures.
|
|
18
|
+
|
|
19
|
+
It does not discover providers, resolve credentials, persist attempt lifecycle,
|
|
20
|
+
or mint authority. Those responsibilities remain in runtime and transport
|
|
21
|
+
adapters. A catalog digest or friendly name never grants access by itself.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { createWorkspaceToolGateway } from "@opengeni/tool-gateway";
|
|
25
|
+
|
|
26
|
+
const { catalog, gateway } = createWorkspaceToolGateway({
|
|
27
|
+
accountId,
|
|
28
|
+
workspaceId,
|
|
29
|
+
generation,
|
|
30
|
+
definitions,
|
|
31
|
+
authorize,
|
|
32
|
+
requireApproval,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const result = await gateway.call({
|
|
36
|
+
operationId: crypto.randomUUID(),
|
|
37
|
+
catalogDigest: catalog.digest,
|
|
38
|
+
identity: { serverId: "docs", toolName: "search" },
|
|
39
|
+
arguments: { query: "roadmap" },
|
|
40
|
+
caller: { kind: "http", subjectId },
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Approval evidence is transport-owned. Current-human HTTP calls classified for
|
|
45
|
+
human approval use a server-issued, hash-only, single-use capability. The
|
|
46
|
+
capability binds the public catalog identity and arguments plus a private
|
|
47
|
+
provider-authority digest, so changing an Integration instance, revision, or
|
|
48
|
+
connection invalidates an older approval without changing the public catalog.
|
|
49
|
+
Connection-backed approval issuance first resolves credentials in a preflight
|
|
50
|
+
mode that neither refreshes tokens nor records provider usage; a provider adapter
|
|
51
|
+
without that side-effect-free preflight is omitted from the current-human
|
|
52
|
+
catalog. Agent attempts keep their existing durable approval and operation
|
|
53
|
+
lifecycle. A model call to an `approval: human` entry is rejected by the gateway
|
|
54
|
+
unless the attempt host confirms the exact model name and subject from its
|
|
55
|
+
approved SDK invocation context; model-supplied arguments or transport metadata
|
|
56
|
+
cannot grant that authority. A Site version's requested identities are only a
|
|
57
|
+
host-filtered maximum allowlist. Publishing grants no tool authority; the API
|
|
58
|
+
revalidates the active version and the viewer's live authority before using the
|
|
59
|
+
ordinary gateway approval and execution path. The
|
|
60
|
+
external/current-human MCP adapter has no
|
|
61
|
+
server-verifiable one-shot approval exchange, so it projects only entries whose
|
|
62
|
+
classification is not `human`; a direct call to a hidden projected name is
|
|
63
|
+
rejected instead of advertising a tool that can never execute.
|
|
64
|
+
|
|
65
|
+
`prepareCall` performs catalog, identity, approval, input-schema, and
|
|
66
|
+
authorization checks without invoking the supplied executor. Attempt transports
|
|
67
|
+
use that seam before crossing their durable side-effect marker, then invoke the
|
|
68
|
+
returned execution closure. Ordinary `call` remains the compatible
|
|
69
|
+
combined preflight-plus-execution API.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ToolGatewayCatalog as ToolGatewayCatalogValue } from "@opengeni/contracts";
|
|
2
|
+
export declare function digestToolGatewayCatalog(catalog: Omit<ToolGatewayCatalogValue, "digest">): string;
|
|
3
|
+
export declare function parseVerifiedToolGatewayCatalog(input: unknown): ToolGatewayCatalogValue;
|
|
4
|
+
export declare function digestCanonicalJson(value: unknown): string;
|
|
5
|
+
/** Compare canonical JSON keys by JavaScript UTF-16 code units, independent of host locale. */
|
|
6
|
+
export declare function compareCanonicalStrings(left: string, right: string): number;
|
|
7
|
+
export declare function assertToolGatewayCatalogSize(catalog: ToolGatewayCatalogValue): void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ToolGatewayCatalogEntry } from "@opengeni/contracts";
|
|
2
|
+
import { parseVerifiedToolGatewayCatalog } from "./catalog.js";
|
|
3
|
+
export type GenerateToolGatewayDeclarationsOptions = {
|
|
4
|
+
moduleSpecifier?: string;
|
|
5
|
+
interfaceName?: string;
|
|
6
|
+
};
|
|
7
|
+
/** Generate declaration merging for one exact digest-pinned workspace catalog. */
|
|
8
|
+
export declare function generateToolGatewayDeclarations(catalog: Parameters<typeof parseVerifiedToolGatewayCatalog>[0], options?: GenerateToolGatewayDeclarationsOptions): string;
|
|
9
|
+
export declare function generateToolDeclarations(catalog: {
|
|
10
|
+
digest: string;
|
|
11
|
+
entries: readonly ToolGatewayCatalogEntry[];
|
|
12
|
+
}, options: {
|
|
13
|
+
moduleSpecifier: string;
|
|
14
|
+
interfaceName: string;
|
|
15
|
+
callOptionsType: string;
|
|
16
|
+
fallbackResultType: string;
|
|
17
|
+
generatedBy: string;
|
|
18
|
+
catalogDigestLabel?: string;
|
|
19
|
+
}): string;
|
|
20
|
+
/** Honest bounded JSON-Schema-to-TypeScript projection for generated declarations. */
|
|
21
|
+
export declare function jsonSchemaToTypeScript(schema: unknown): string;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare class ToolGatewayCatalogStaleError extends Error {
|
|
2
|
+
readonly code = "catalog_stale";
|
|
3
|
+
constructor();
|
|
4
|
+
}
|
|
5
|
+
export declare class ToolGatewayToolNotFoundError extends Error {
|
|
6
|
+
readonly code = "tool_not_found";
|
|
7
|
+
constructor();
|
|
8
|
+
}
|
|
9
|
+
export declare class ToolGatewayApprovalRequiredError extends Error {
|
|
10
|
+
readonly code = "approval_required";
|
|
11
|
+
constructor();
|
|
12
|
+
}
|
|
13
|
+
export declare class ToolGatewayCatalogIntegrityError extends Error {
|
|
14
|
+
readonly code = "catalog_integrity_failed";
|
|
15
|
+
constructor();
|
|
16
|
+
}
|
|
17
|
+
export declare class ToolGatewayCatalogTooLargeError extends Error {
|
|
18
|
+
readonly code = "catalog_too_large";
|
|
19
|
+
constructor();
|
|
20
|
+
}
|
|
21
|
+
export declare class ToolGatewayPathCollisionError extends Error {
|
|
22
|
+
readonly code = "tool_path_collision";
|
|
23
|
+
constructor(path: readonly string[], kind: "collision" | "extends_leaf");
|
|
24
|
+
}
|
|
25
|
+
export declare class ToolGatewayInputValidationError extends Error {
|
|
26
|
+
readonly code = "invalid_tool_arguments";
|
|
27
|
+
constructor();
|
|
28
|
+
}
|
|
29
|
+
export declare class ToolGatewayOutputValidationError extends Error {
|
|
30
|
+
readonly code = "invalid_tool_result";
|
|
31
|
+
constructor();
|
|
32
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { type ValidateFunction } from "ajv";
|
|
2
|
+
import { type ToolGatewayCaller, type ToolGatewayCatalog as ToolGatewayCatalogValue, type ToolGatewayCatalogEntry as ToolGatewayCatalogEntryValue, type ToolGatewayIdentity, type ToolGatewayResult as ToolGatewayResultValue } from "@opengeni/contracts";
|
|
3
|
+
export type ToolGatewayExecutionContext = {
|
|
4
|
+
operationId: string;
|
|
5
|
+
caller: ToolGatewayCaller;
|
|
6
|
+
/** In-process transport metadata; never part of catalog identity or digest. */
|
|
7
|
+
transportMeta?: Record<string, unknown> | null;
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
};
|
|
10
|
+
export type ToolGatewayCallContext = Pick<ToolGatewayExecutionContext, "transportMeta" | "signal">;
|
|
11
|
+
export type ToolGatewayDefinition = Omit<ToolGatewayCatalogEntryValue, "codemodePath"> & {
|
|
12
|
+
/** Optional human-readable path. Unsafe/colliding segments are normalized. */
|
|
13
|
+
codemodePath?: readonly string[];
|
|
14
|
+
/** Internal authority revision bound into human approval capabilities. */
|
|
15
|
+
approvalAuthorityDigest?: string;
|
|
16
|
+
/** Connection-backed calls must have a side-effect-free provider preflight before approval. */
|
|
17
|
+
requiresProviderPreflight?: boolean;
|
|
18
|
+
/** In-process provider preflight; never enters the public catalog or its digest. */
|
|
19
|
+
preflightCall?: (input: {
|
|
20
|
+
call: ToolGatewayCall;
|
|
21
|
+
entry: ToolGatewayCatalogEntryValue;
|
|
22
|
+
context: ToolGatewayCallContext;
|
|
23
|
+
}) => Promise<void> | void;
|
|
24
|
+
/** In-process execution lifecycle; never enters the public catalog or its digest. */
|
|
25
|
+
lifecycle?: ToolGatewayCallLifecycle;
|
|
26
|
+
execute: (args: Record<string, unknown>, context: ToolGatewayExecutionContext) => Promise<ToolGatewayResultValue> | ToolGatewayResultValue;
|
|
27
|
+
};
|
|
28
|
+
export type ToolGatewayAuthorization = (input: {
|
|
29
|
+
call: ToolGatewayCall;
|
|
30
|
+
entry: ToolGatewayCatalogEntryValue;
|
|
31
|
+
}) => Promise<void> | void;
|
|
32
|
+
export type ToolGatewayCall = {
|
|
33
|
+
operationId: string;
|
|
34
|
+
catalogDigest: string;
|
|
35
|
+
identity: ToolGatewayIdentity;
|
|
36
|
+
arguments: Record<string, unknown>;
|
|
37
|
+
caller: ToolGatewayCaller;
|
|
38
|
+
};
|
|
39
|
+
export type ToolGatewayCallSettlement = {
|
|
40
|
+
outcome: "completed";
|
|
41
|
+
result: ToolGatewayResultValue;
|
|
42
|
+
} | {
|
|
43
|
+
outcome: "failed";
|
|
44
|
+
error: unknown;
|
|
45
|
+
};
|
|
46
|
+
export type PreparedToolGatewayCallLifecycle = {
|
|
47
|
+
/** Cross the side-effect boundary immediately before the executor closure. */
|
|
48
|
+
begin?: () => Promise<void> | void;
|
|
49
|
+
/** Settle the side-effect lifecycle after a returned result or thrown failure. */
|
|
50
|
+
complete?: (settlement: ToolGatewayCallSettlement) => Promise<void> | void;
|
|
51
|
+
};
|
|
52
|
+
export type ToolGatewayCallLifecycle = {
|
|
53
|
+
/** Argument-sensitive preflight. Throwing here guarantees the executor never runs. */
|
|
54
|
+
prepare: (input: {
|
|
55
|
+
call: ToolGatewayCall;
|
|
56
|
+
entry: ToolGatewayCatalogEntryValue;
|
|
57
|
+
context: ToolGatewayCallContext;
|
|
58
|
+
}) => Promise<PreparedToolGatewayCallLifecycle | void> | PreparedToolGatewayCallLifecycle | void;
|
|
59
|
+
};
|
|
60
|
+
export type ModelToolGatewayCall = {
|
|
61
|
+
operationId?: string;
|
|
62
|
+
modelName: string;
|
|
63
|
+
arguments: Record<string, unknown>;
|
|
64
|
+
subjectId: string;
|
|
65
|
+
transportMeta?: Record<string, unknown> | null;
|
|
66
|
+
signal?: AbortSignal;
|
|
67
|
+
};
|
|
68
|
+
type CompiledDefinition = {
|
|
69
|
+
entry: ToolGatewayCatalogEntryValue;
|
|
70
|
+
execute: ToolGatewayDefinition["execute"];
|
|
71
|
+
approvalAuthorityDigest: string | undefined;
|
|
72
|
+
preflightCall: ToolGatewayDefinition["preflightCall"];
|
|
73
|
+
lifecycle: ToolGatewayCallLifecycle | undefined;
|
|
74
|
+
validateInput: ValidateFunction<unknown>;
|
|
75
|
+
validateOutput: ValidateFunction<unknown> | null;
|
|
76
|
+
};
|
|
77
|
+
export type PreparedToolGatewayCall = {
|
|
78
|
+
readonly call: ToolGatewayCall;
|
|
79
|
+
readonly entry: ToolGatewayCatalogEntryValue;
|
|
80
|
+
readonly approvalAuthorityDigest: string;
|
|
81
|
+
execute: () => Promise<ToolGatewayResultValue>;
|
|
82
|
+
};
|
|
83
|
+
export declare class PreparedToolGatewayDefinitions {
|
|
84
|
+
private readonly definitions;
|
|
85
|
+
readonly entries: readonly ToolGatewayCatalogEntryValue[];
|
|
86
|
+
constructor(definitions: readonly CompiledDefinition[]);
|
|
87
|
+
create(input: {
|
|
88
|
+
catalogDigest: string;
|
|
89
|
+
authorize?: ToolGatewayAuthorization;
|
|
90
|
+
requireApproval?: (entry: ToolGatewayCatalogEntryValue, caller: ToolGatewayCaller, context: {
|
|
91
|
+
transportMeta?: Record<string, unknown> | null;
|
|
92
|
+
}) => boolean;
|
|
93
|
+
confirmModelApproval?: (input: {
|
|
94
|
+
entry: ToolGatewayCatalogEntryValue;
|
|
95
|
+
modelName: string;
|
|
96
|
+
subjectId: string;
|
|
97
|
+
}) => boolean;
|
|
98
|
+
}): ToolGateway;
|
|
99
|
+
}
|
|
100
|
+
export declare class ToolGateway {
|
|
101
|
+
readonly catalogDigest: string;
|
|
102
|
+
private readonly authorize;
|
|
103
|
+
private readonly requireApproval;
|
|
104
|
+
private readonly confirmModelApproval;
|
|
105
|
+
private readonly byIdentity;
|
|
106
|
+
private readonly byModelName;
|
|
107
|
+
constructor(catalogDigest: string, definitions: readonly CompiledDefinition[], authorize: ToolGatewayAuthorization | undefined, requireApproval: ((entry: ToolGatewayCatalogEntryValue, caller: ToolGatewayCaller, context: {
|
|
108
|
+
transportMeta?: Record<string, unknown> | null;
|
|
109
|
+
}) => boolean) | undefined, confirmModelApproval: ((input: {
|
|
110
|
+
entry: ToolGatewayCatalogEntryValue;
|
|
111
|
+
modelName: string;
|
|
112
|
+
subjectId: string;
|
|
113
|
+
}) => boolean) | undefined);
|
|
114
|
+
call(input: ToolGatewayCall, context?: ToolGatewayCallContext): Promise<ToolGatewayResultValue>;
|
|
115
|
+
prepareCall(input: ToolGatewayCall, context?: ToolGatewayCallContext): Promise<PreparedToolGatewayCall>;
|
|
116
|
+
private prepareCallWithModelApproval;
|
|
117
|
+
callModel(input: ModelToolGatewayCall): Promise<ToolGatewayResultValue>;
|
|
118
|
+
}
|
|
119
|
+
export declare function prepareToolGatewayDefinitions(definitions: readonly ToolGatewayDefinition[]): PreparedToolGatewayDefinitions;
|
|
120
|
+
export declare function createWorkspaceToolGateway(input: {
|
|
121
|
+
accountId: string;
|
|
122
|
+
workspaceId: string;
|
|
123
|
+
generation: number;
|
|
124
|
+
definitions: readonly ToolGatewayDefinition[];
|
|
125
|
+
createdAt?: Date;
|
|
126
|
+
authorize?: ToolGatewayAuthorization;
|
|
127
|
+
requireApproval?: (entry: ToolGatewayCatalogEntryValue, caller: ToolGatewayCaller, context: {
|
|
128
|
+
transportMeta?: Record<string, unknown> | null;
|
|
129
|
+
}) => boolean;
|
|
130
|
+
}): {
|
|
131
|
+
catalog: ToolGatewayCatalogValue;
|
|
132
|
+
gateway: ToolGateway;
|
|
133
|
+
};
|
|
134
|
+
export * from "./catalog.js";
|
|
135
|
+
export * from "./declarations.js";
|
|
136
|
+
export * from "./errors.js";
|