@valon-technologies/gestalt 0.0.1-alpha.12 → 0.0.1-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/gen/v1/agent_pb.ts +1916 -0
- package/gen/v1/authentication_pb.ts +1 -1
- package/gen/v1/authorization_pb.ts +28 -28
- package/gen/v1/cache_pb.ts +4 -4
- package/gen/v1/datastore_pb.ts +10 -10
- package/gen/v1/external_credential_pb.ts +274 -0
- package/gen/v1/plugin_pb.ts +35 -30
- package/gen/v1/pluginruntime_pb.ts +593 -0
- package/gen/v1/runtime_pb.ts +18 -3
- package/gen/v1/s3_pb.ts +19 -19
- package/gen/v1/secrets_pb.ts +1 -1
- package/gen/v1/workflow_pb.ts +248 -82
- package/package.json +1 -1
- package/src/agent-manager.ts +247 -0
- package/src/agent.ts +492 -0
- package/src/authorization.ts +88 -18
- package/src/index.ts +67 -0
- package/src/manifest-metadata.ts +1 -0
- package/src/plugin.ts +85 -4
- package/src/provider-kind.ts +6 -0
- package/src/provider.ts +12 -1
- package/src/runtime.ts +153 -44
- package/src/s3.ts +89 -38
- package/src/workflow-manager.ts +67 -9
package/package.json
CHANGED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import type { MessageInitShape } from "@bufbuild/protobuf";
|
|
2
|
+
import {
|
|
3
|
+
createClient,
|
|
4
|
+
type Client,
|
|
5
|
+
type Interceptor,
|
|
6
|
+
} from "@connectrpc/connect";
|
|
7
|
+
import { createGrpcTransport } from "@connectrpc/connect-node";
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
AgentManagerCancelTurnRequestSchema,
|
|
11
|
+
AgentManagerCreateSessionRequestSchema,
|
|
12
|
+
AgentManagerCreateTurnRequestSchema,
|
|
13
|
+
AgentManagerGetSessionRequestSchema,
|
|
14
|
+
AgentManagerGetTurnRequestSchema,
|
|
15
|
+
AgentManagerHost as AgentManagerHostService,
|
|
16
|
+
AgentManagerListInteractionsRequestSchema,
|
|
17
|
+
AgentManagerListSessionsRequestSchema,
|
|
18
|
+
AgentManagerListTurnEventsRequestSchema,
|
|
19
|
+
AgentManagerListTurnsRequestSchema,
|
|
20
|
+
AgentManagerResolveInteractionRequestSchema,
|
|
21
|
+
AgentManagerUpdateSessionRequestSchema,
|
|
22
|
+
type AgentInteraction,
|
|
23
|
+
type AgentSession,
|
|
24
|
+
type AgentTurn,
|
|
25
|
+
type AgentTurnEvent,
|
|
26
|
+
} from "../gen/v1/agent_pb.ts";
|
|
27
|
+
import type { Request } from "./api.ts";
|
|
28
|
+
|
|
29
|
+
export const ENV_AGENT_MANAGER_SOCKET = "GESTALT_AGENT_MANAGER_SOCKET";
|
|
30
|
+
export const ENV_AGENT_MANAGER_SOCKET_TOKEN = `${ENV_AGENT_MANAGER_SOCKET}_TOKEN`;
|
|
31
|
+
const AGENT_MANAGER_RELAY_TOKEN_HEADER = "x-gestalt-host-service-relay-token";
|
|
32
|
+
|
|
33
|
+
export type AgentManagerCreateSessionInput = MessageInitShape<
|
|
34
|
+
typeof AgentManagerCreateSessionRequestSchema
|
|
35
|
+
>;
|
|
36
|
+
export type AgentManagerGetSessionInput = MessageInitShape<
|
|
37
|
+
typeof AgentManagerGetSessionRequestSchema
|
|
38
|
+
>;
|
|
39
|
+
export type AgentManagerListSessionsInput = MessageInitShape<
|
|
40
|
+
typeof AgentManagerListSessionsRequestSchema
|
|
41
|
+
>;
|
|
42
|
+
export type AgentManagerUpdateSessionInput = MessageInitShape<
|
|
43
|
+
typeof AgentManagerUpdateSessionRequestSchema
|
|
44
|
+
>;
|
|
45
|
+
export type AgentManagerCreateTurnInput = MessageInitShape<
|
|
46
|
+
typeof AgentManagerCreateTurnRequestSchema
|
|
47
|
+
>;
|
|
48
|
+
export type AgentManagerGetTurnInput = MessageInitShape<
|
|
49
|
+
typeof AgentManagerGetTurnRequestSchema
|
|
50
|
+
>;
|
|
51
|
+
export type AgentManagerListTurnsInput = MessageInitShape<
|
|
52
|
+
typeof AgentManagerListTurnsRequestSchema
|
|
53
|
+
>;
|
|
54
|
+
export type AgentManagerCancelTurnInput = MessageInitShape<
|
|
55
|
+
typeof AgentManagerCancelTurnRequestSchema
|
|
56
|
+
>;
|
|
57
|
+
export type AgentManagerListTurnEventsInput = MessageInitShape<
|
|
58
|
+
typeof AgentManagerListTurnEventsRequestSchema
|
|
59
|
+
>;
|
|
60
|
+
export type AgentManagerListInteractionsInput = MessageInitShape<
|
|
61
|
+
typeof AgentManagerListInteractionsRequestSchema
|
|
62
|
+
>;
|
|
63
|
+
export type AgentManagerResolveInteractionInput = MessageInitShape<
|
|
64
|
+
typeof AgentManagerResolveInteractionRequestSchema
|
|
65
|
+
>;
|
|
66
|
+
|
|
67
|
+
export class AgentManager {
|
|
68
|
+
private readonly client: Client<typeof AgentManagerHostService>;
|
|
69
|
+
private readonly invocationToken: string;
|
|
70
|
+
|
|
71
|
+
constructor(request: Request);
|
|
72
|
+
constructor(invocationToken: string);
|
|
73
|
+
constructor(requestOrToken: Request | string) {
|
|
74
|
+
this.invocationToken = normalizeInvocationToken(requestOrToken);
|
|
75
|
+
|
|
76
|
+
const target = process.env[ENV_AGENT_MANAGER_SOCKET];
|
|
77
|
+
if (!target) {
|
|
78
|
+
throw new Error(`agent manager: ${ENV_AGENT_MANAGER_SOCKET} is not set`);
|
|
79
|
+
}
|
|
80
|
+
const relayToken =
|
|
81
|
+
process.env[ENV_AGENT_MANAGER_SOCKET_TOKEN]?.trim() ?? "";
|
|
82
|
+
|
|
83
|
+
const transport = createGrpcTransport({
|
|
84
|
+
...agentManagerTransportOptions(target),
|
|
85
|
+
interceptors: relayToken
|
|
86
|
+
? [agentManagerRelayTokenInterceptor(relayToken)]
|
|
87
|
+
: [],
|
|
88
|
+
});
|
|
89
|
+
this.client = createClient(AgentManagerHostService, transport);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async createSession(
|
|
93
|
+
request: AgentManagerCreateSessionInput,
|
|
94
|
+
): Promise<AgentSession> {
|
|
95
|
+
return await this.client.createSession({
|
|
96
|
+
...request,
|
|
97
|
+
invocationToken: this.invocationToken,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async getSession(request: AgentManagerGetSessionInput): Promise<AgentSession> {
|
|
102
|
+
return await this.client.getSession({
|
|
103
|
+
...request,
|
|
104
|
+
invocationToken: this.invocationToken,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async listSessions(
|
|
109
|
+
request: AgentManagerListSessionsInput = {},
|
|
110
|
+
): Promise<AgentSession[]> {
|
|
111
|
+
const response = await this.client.listSessions({
|
|
112
|
+
...request,
|
|
113
|
+
invocationToken: this.invocationToken,
|
|
114
|
+
});
|
|
115
|
+
return [...response.sessions];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async updateSession(
|
|
119
|
+
request: AgentManagerUpdateSessionInput,
|
|
120
|
+
): Promise<AgentSession> {
|
|
121
|
+
return await this.client.updateSession({
|
|
122
|
+
...request,
|
|
123
|
+
invocationToken: this.invocationToken,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async createTurn(request: AgentManagerCreateTurnInput): Promise<AgentTurn> {
|
|
128
|
+
return await this.client.createTurn({
|
|
129
|
+
...request,
|
|
130
|
+
invocationToken: this.invocationToken,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async getTurn(request: AgentManagerGetTurnInput): Promise<AgentTurn> {
|
|
135
|
+
return await this.client.getTurn({
|
|
136
|
+
...request,
|
|
137
|
+
invocationToken: this.invocationToken,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async listTurns(request: AgentManagerListTurnsInput): Promise<AgentTurn[]> {
|
|
142
|
+
const response = await this.client.listTurns({
|
|
143
|
+
...request,
|
|
144
|
+
invocationToken: this.invocationToken,
|
|
145
|
+
});
|
|
146
|
+
return [...response.turns];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async cancelTurn(request: AgentManagerCancelTurnInput): Promise<AgentTurn> {
|
|
150
|
+
return await this.client.cancelTurn({
|
|
151
|
+
...request,
|
|
152
|
+
invocationToken: this.invocationToken,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async listTurnEvents(
|
|
157
|
+
request: AgentManagerListTurnEventsInput,
|
|
158
|
+
): Promise<AgentTurnEvent[]> {
|
|
159
|
+
const response = await this.client.listTurnEvents({
|
|
160
|
+
...request,
|
|
161
|
+
invocationToken: this.invocationToken,
|
|
162
|
+
});
|
|
163
|
+
return [...response.events];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async listInteractions(
|
|
167
|
+
request: AgentManagerListInteractionsInput,
|
|
168
|
+
): Promise<AgentInteraction[]> {
|
|
169
|
+
const response = await this.client.listInteractions({
|
|
170
|
+
...request,
|
|
171
|
+
invocationToken: this.invocationToken,
|
|
172
|
+
});
|
|
173
|
+
return [...response.interactions];
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async resolveInteraction(
|
|
177
|
+
request: AgentManagerResolveInteractionInput,
|
|
178
|
+
): Promise<AgentInteraction> {
|
|
179
|
+
return await this.client.resolveInteraction({
|
|
180
|
+
...request,
|
|
181
|
+
invocationToken: this.invocationToken,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function normalizeInvocationToken(requestOrToken: Request | string): string {
|
|
187
|
+
const invocationToken =
|
|
188
|
+
typeof requestOrToken === "string"
|
|
189
|
+
? requestOrToken
|
|
190
|
+
: requestOrToken.invocationToken;
|
|
191
|
+
const trimmed = invocationToken.trim();
|
|
192
|
+
if (!trimmed) {
|
|
193
|
+
throw new Error("agent manager: invocation token is not available");
|
|
194
|
+
}
|
|
195
|
+
return trimmed;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function agentManagerTransportOptions(rawTarget: string): {
|
|
199
|
+
baseUrl: string;
|
|
200
|
+
nodeOptions?: { path: string };
|
|
201
|
+
} {
|
|
202
|
+
const target = rawTarget.trim();
|
|
203
|
+
if (!target) {
|
|
204
|
+
throw new Error("agent manager: transport target is required");
|
|
205
|
+
}
|
|
206
|
+
if (target.startsWith("tcp://")) {
|
|
207
|
+
const address = target.slice("tcp://".length).trim();
|
|
208
|
+
if (!address) {
|
|
209
|
+
throw new Error(
|
|
210
|
+
`agent manager: tcp target ${JSON.stringify(rawTarget)} is missing host:port`,
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
return { baseUrl: `http://${address}` };
|
|
214
|
+
}
|
|
215
|
+
if (target.startsWith("tls://")) {
|
|
216
|
+
const address = target.slice("tls://".length).trim();
|
|
217
|
+
if (!address) {
|
|
218
|
+
throw new Error(
|
|
219
|
+
`agent manager: tls target ${JSON.stringify(rawTarget)} is missing host:port`,
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
return { baseUrl: `https://${address}` };
|
|
223
|
+
}
|
|
224
|
+
if (target.startsWith("unix://")) {
|
|
225
|
+
const socketPath = target.slice("unix://".length).trim();
|
|
226
|
+
if (!socketPath) {
|
|
227
|
+
throw new Error(
|
|
228
|
+
`agent manager: unix target ${JSON.stringify(rawTarget)} is missing a socket path`,
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
return { baseUrl: "http://localhost", nodeOptions: { path: socketPath } };
|
|
232
|
+
}
|
|
233
|
+
if (target.includes("://")) {
|
|
234
|
+
const parsed = new URL(target);
|
|
235
|
+
throw new Error(
|
|
236
|
+
`agent manager: unsupported target scheme ${JSON.stringify(parsed.protocol.replace(/:$/, ""))}`,
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
return { baseUrl: "http://localhost", nodeOptions: { path: target } };
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function agentManagerRelayTokenInterceptor(token: string): Interceptor {
|
|
243
|
+
return (next) => async (req) => {
|
|
244
|
+
req.header.set(AGENT_MANAGER_RELAY_TOKEN_HEADER, token);
|
|
245
|
+
return next(req);
|
|
246
|
+
};
|
|
247
|
+
}
|