@valon-technologies/gestalt 0.0.1-alpha.33 → 0.0.1-alpha.35
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 +4 -5
- package/package.json +1 -1
- package/src/agent-access.ts +7 -4
- package/src/agent-conversions.ts +0 -37
- package/src/agent.ts +14 -20
- package/src/api.ts +17 -13
- package/src/authorization.ts +675 -1400
- package/src/index.ts +47 -229
- package/src/internal/gen/v1/agent_pb.ts +55 -84
- package/src/internal/gen/v1/app_pb.ts +4 -19
- package/src/internal/gen/v1/authorization_pb.ts +407 -781
- package/src/internal/gen/v1/runtime_provider_pb.ts +1 -0
- package/src/internal/gen/v1/workflow_pb.ts +678 -737
- package/src/provider-kind.ts +6 -6
- package/src/provider.ts +1 -1
- package/src/runtime.ts +15 -23
- package/src/workflow-access.ts +340 -385
- package/src/workflow.ts +1201 -2443
package/README.md
CHANGED
|
@@ -19,9 +19,9 @@ explicitly names a submodule.
|
|
|
19
19
|
| --- | --- | --- |
|
|
20
20
|
| Provider authoring | `defineApp`, `operation`, `ok` | Executable app providers, typed request handlers, and operation results. |
|
|
21
21
|
| Runtime schemas | `s`, `object`, `string` | Runtime validation and generated catalog metadata for operation inputs and outputs. |
|
|
22
|
-
| Provider runtimes | `defineAuthenticationProvider`, `
|
|
22
|
+
| Provider runtimes | `defineAuthenticationProvider`, `defineCacheProvider`, `defineS3Provider`, `defineWorkflowProvider`, `defineAgentProvider` | Host-service backends implemented as TypeScript providers. |
|
|
23
23
|
| Workflow and agent models | `WorkflowProvider`, `Workflow`, `AgentProvider`, `Agent` | Native workflow values, agent sessions, turns, messages, tools, and host-service access. |
|
|
24
|
-
| Host-service clients | `Cache`, `IndexedDB`, `S3`, `App
|
|
24
|
+
| Host-service clients | `Cache`, `IndexedDB`, `S3`, `App` | Calling sibling services exposed to a provider process by `gestaltd`. |
|
|
25
25
|
| Telemetry | `withModelOperation`, `withToolExecution`, `withAgentInvocation` | Provider-authored GenAI spans and metrics inside a running provider process. |
|
|
26
26
|
|
|
27
27
|
```ts
|
|
@@ -77,8 +77,8 @@ is omitted, the runtime looks for `provider`, then `app`, then the default
|
|
|
77
77
|
export.
|
|
78
78
|
|
|
79
79
|
Use `"app"` as the kind token for executable app providers. Use an object
|
|
80
|
-
target with an explicit kind for authentication,
|
|
81
|
-
|
|
80
|
+
target with an explicit kind for authentication, cache, IndexedDB, S3,
|
|
81
|
+
secrets, workflow, agent, and hosted-runtime providers.
|
|
82
82
|
|
|
83
83
|
## Public surface
|
|
84
84
|
|
|
@@ -86,7 +86,6 @@ The root package exports provider definition helpers:
|
|
|
86
86
|
|
|
87
87
|
- `defineApp` for integration operations and session catalogs.
|
|
88
88
|
- `defineAuthenticationProvider` for authentication surfaces.
|
|
89
|
-
- `defineAuthorizationProvider` for custom authorization providers.
|
|
90
89
|
- `defineCacheProvider`, `defineIndexedDBProvider`, `defineS3Provider`, and
|
|
91
90
|
`defineSecretsProvider` for host-service backends.
|
|
92
91
|
- `defineWorkflowProvider`, `defineAgentProvider`, and
|
package/package.json
CHANGED
package/src/agent-access.ts
CHANGED
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
} from "./internal/gen/v1/agent_pb.ts";
|
|
13
13
|
import type { Request } from "./api.ts";
|
|
14
14
|
import {
|
|
15
|
-
agentActorFromProto,
|
|
16
15
|
agentOutputToProto,
|
|
17
16
|
agentMessageFromProto,
|
|
18
17
|
agentMessageToProto,
|
|
@@ -251,6 +250,10 @@ class AgentImpl implements Agent {
|
|
|
251
250
|
|
|
252
251
|
/** Creates an agent turn. */
|
|
253
252
|
async createTurn(request: AgentCreateTurn): Promise<AgentTurn> {
|
|
253
|
+
const timeoutSeconds = request.timeoutSeconds ?? 0;
|
|
254
|
+
if (!Number.isInteger(timeoutSeconds) || timeoutSeconds < 0) {
|
|
255
|
+
throw new Error("agent create turn timeoutSeconds must not be negative");
|
|
256
|
+
}
|
|
254
257
|
return agentTurnFromProto(
|
|
255
258
|
await this.client.createTurn({
|
|
256
259
|
sessionId: request.sessionId,
|
|
@@ -263,7 +266,7 @@ class AgentImpl implements Agent {
|
|
|
263
266
|
idempotencyKey: request.idempotencyKey ?? "",
|
|
264
267
|
...this.invocationContext,
|
|
265
268
|
modelOptions: optionalStruct(request.modelOptions),
|
|
266
|
-
timeoutSeconds
|
|
269
|
+
timeoutSeconds,
|
|
267
270
|
}),
|
|
268
271
|
);
|
|
269
272
|
}
|
|
@@ -364,7 +367,7 @@ function agentSessionFromProto(session: ProtoAgentSession): AgentSession {
|
|
|
364
367
|
clientRef: session.clientRef,
|
|
365
368
|
state: session.state as AgentSessionState,
|
|
366
369
|
metadata: optionalObjectFromStruct(session.metadata),
|
|
367
|
-
|
|
370
|
+
createdBySubjectId: session.createdBySubjectId ?? "",
|
|
368
371
|
createdAt: optionalDate(session.createdAt),
|
|
369
372
|
updatedAt: optionalDate(session.updatedAt),
|
|
370
373
|
lastTurnAt: optionalDate(session.lastTurnAt),
|
|
@@ -381,7 +384,7 @@ function agentTurnFromProto(turn: ProtoAgentTurn): AgentTurn {
|
|
|
381
384
|
messages: turn.messages.map(agentMessageFromProto),
|
|
382
385
|
output: agentTurnOutputFromProto(turn.output),
|
|
383
386
|
statusMessage: turn.statusMessage,
|
|
384
|
-
|
|
387
|
+
createdBySubjectId: turn.createdBySubjectId ?? "",
|
|
385
388
|
createdAt: optionalDate(turn.createdAt),
|
|
386
389
|
startedAt: optionalDate(turn.startedAt),
|
|
387
390
|
completedAt: optionalDate(turn.completedAt),
|
package/src/agent-conversions.ts
CHANGED
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
} from "@bufbuild/protobuf";
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
-
AgentActorSchema,
|
|
8
7
|
AgentOutputSchema,
|
|
9
8
|
AgentStructuredOutputSchema,
|
|
10
9
|
AgentTextOutputSchema,
|
|
@@ -14,7 +13,6 @@ import {
|
|
|
14
13
|
AgentTurnDisplaySchema,
|
|
15
14
|
AgentTurnStructuredOutputSchema,
|
|
16
15
|
AgentTurnTextOutputSchema,
|
|
17
|
-
type AgentActor as ProtoAgentActor,
|
|
18
16
|
type AgentMessage as ProtoAgentMessage,
|
|
19
17
|
type AgentMessagePart as ProtoAgentMessagePart,
|
|
20
18
|
type AgentOutput as ProtoAgentOutput,
|
|
@@ -37,7 +35,6 @@ import {
|
|
|
37
35
|
optionalStruct,
|
|
38
36
|
} from "./protocol-internal.ts";
|
|
39
37
|
import type {
|
|
40
|
-
AgentActor,
|
|
41
38
|
AgentOutput,
|
|
42
39
|
AgentMessage,
|
|
43
40
|
AgentMessagePart,
|
|
@@ -266,34 +263,6 @@ export function agentMessagePartToProto(
|
|
|
266
263
|
};
|
|
267
264
|
}
|
|
268
265
|
|
|
269
|
-
export function agentActorFromProto(
|
|
270
|
-
actor?: ProtoAgentActor | undefined,
|
|
271
|
-
): AgentActor | undefined {
|
|
272
|
-
if (actor === undefined) {
|
|
273
|
-
return undefined;
|
|
274
|
-
}
|
|
275
|
-
return {
|
|
276
|
-
subjectId: actor.subjectId,
|
|
277
|
-
subjectKind: actor.subjectKind,
|
|
278
|
-
displayName: actor.displayName,
|
|
279
|
-
authSource: actor.authSource,
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
export function agentActorToProto(
|
|
284
|
-
actor?: AgentActor | undefined,
|
|
285
|
-
): ProtoAgentActor | undefined {
|
|
286
|
-
if (actor === undefined) {
|
|
287
|
-
return undefined;
|
|
288
|
-
}
|
|
289
|
-
return create(AgentActorSchema, {
|
|
290
|
-
subjectId: actor.subjectId ?? "",
|
|
291
|
-
subjectKind: actor.subjectKind ?? "",
|
|
292
|
-
displayName: actor.displayName ?? "",
|
|
293
|
-
authSource: actor.authSource ?? "",
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
|
|
297
266
|
export function agentToolRefFromProto(ref: ProtoAgentToolRef): AgentToolRef {
|
|
298
267
|
return {
|
|
299
268
|
app: ref.app,
|
|
@@ -328,10 +297,7 @@ function agentRunAsSubjectFromProto(
|
|
|
328
297
|
}
|
|
329
298
|
return {
|
|
330
299
|
id: subject.id,
|
|
331
|
-
kind: subject.kind,
|
|
332
300
|
credentialSubjectId: subject.credentialSubjectId,
|
|
333
|
-
displayName: subject.displayName,
|
|
334
|
-
authSource: subject.authSource,
|
|
335
301
|
email: subject.email,
|
|
336
302
|
};
|
|
337
303
|
}
|
|
@@ -344,10 +310,7 @@ function agentRunAsSubjectToProto(
|
|
|
344
310
|
}
|
|
345
311
|
return create(SubjectContextSchema, {
|
|
346
312
|
id: subject.id ?? "",
|
|
347
|
-
kind: subject.kind ?? "",
|
|
348
313
|
credentialSubjectId: subject.credentialSubjectId ?? "",
|
|
349
|
-
displayName: subject.displayName ?? "",
|
|
350
|
-
authSource: subject.authSource ?? "",
|
|
351
314
|
email: subject.email ?? "",
|
|
352
315
|
});
|
|
353
316
|
}
|
package/src/agent.ts
CHANGED
|
@@ -39,7 +39,6 @@ import {
|
|
|
39
39
|
ListAgentProviderTurnEventsResponseSchema,
|
|
40
40
|
ListAgentProviderTurnsResponseSchema,
|
|
41
41
|
ResolveAgentConnectionRequestSchema,
|
|
42
|
-
type AgentActor as ProtoAgentActor,
|
|
43
42
|
type AgentInteraction as ProtoAgentInteraction,
|
|
44
43
|
type AgentMessagePartImageRef as ProtoAgentMessagePartImageRef,
|
|
45
44
|
type AgentMessagePartToolCall as ProtoAgentMessagePartToolCall,
|
|
@@ -80,8 +79,6 @@ import {
|
|
|
80
79
|
type SubjectInput,
|
|
81
80
|
} from "./api.ts";
|
|
82
81
|
import {
|
|
83
|
-
agentActorFromProto,
|
|
84
|
-
agentActorToProto,
|
|
85
82
|
agentOutputFromProto,
|
|
86
83
|
agentOutputToProto,
|
|
87
84
|
agentMessageFromProto,
|
|
@@ -200,12 +197,6 @@ export interface AgentMessage {
|
|
|
200
197
|
metadata?: JsonObjectInput | undefined;
|
|
201
198
|
}
|
|
202
199
|
|
|
203
|
-
export interface AgentActor {
|
|
204
|
-
subjectId?: string | undefined;
|
|
205
|
-
subjectKind?: string | undefined;
|
|
206
|
-
displayName?: string | undefined;
|
|
207
|
-
authSource?: string | undefined;
|
|
208
|
-
}
|
|
209
200
|
|
|
210
201
|
export interface AgentToolRef {
|
|
211
202
|
app?: string | undefined;
|
|
@@ -245,7 +236,7 @@ export interface AgentSession {
|
|
|
245
236
|
clientRef?: string | undefined;
|
|
246
237
|
state?: AgentSessionState | undefined;
|
|
247
238
|
metadata?: JsonObjectInput | undefined;
|
|
248
|
-
|
|
239
|
+
createdBySubjectId?: string | undefined;
|
|
249
240
|
createdAt?: Date | undefined;
|
|
250
241
|
updatedAt?: Date | undefined;
|
|
251
242
|
lastTurnAt?: Date | undefined;
|
|
@@ -281,7 +272,7 @@ export interface CreateAgentProviderSessionRequest {
|
|
|
281
272
|
model: string;
|
|
282
273
|
clientRef: string;
|
|
283
274
|
metadata?: JsonObjectInput | undefined;
|
|
284
|
-
|
|
275
|
+
createdBySubjectId?: string | undefined;
|
|
285
276
|
subject?: Subject | undefined;
|
|
286
277
|
sessionStart?: AgentSessionStartConfig | undefined;
|
|
287
278
|
preparedWorkspace?: AgentPreparedWorkspace | undefined;
|
|
@@ -325,7 +316,7 @@ export interface AgentTurn {
|
|
|
325
316
|
messages?: readonly AgentMessage[] | undefined;
|
|
326
317
|
output?: AgentTurnOutput | undefined;
|
|
327
318
|
statusMessage?: string | undefined;
|
|
328
|
-
|
|
319
|
+
createdBySubjectId?: string | undefined;
|
|
329
320
|
createdAt?: Date | undefined;
|
|
330
321
|
startedAt?: Date | undefined;
|
|
331
322
|
completedAt?: Date | undefined;
|
|
@@ -365,7 +356,7 @@ export interface CreateAgentProviderTurnRequest {
|
|
|
365
356
|
tools: readonly ResolvedAgentTool[];
|
|
366
357
|
output: AgentOutput;
|
|
367
358
|
metadata?: JsonObjectInput | undefined;
|
|
368
|
-
|
|
359
|
+
createdBySubjectId?: string | undefined;
|
|
369
360
|
executionRef: string;
|
|
370
361
|
toolRefs: readonly AgentToolRef[];
|
|
371
362
|
toolSource: AgentToolSourceMode;
|
|
@@ -816,7 +807,7 @@ function createAgentProviderSessionRequestFromProto(
|
|
|
816
807
|
model: request.model,
|
|
817
808
|
clientRef: request.clientRef,
|
|
818
809
|
metadata: optionalObjectFromStruct(request.metadata),
|
|
819
|
-
|
|
810
|
+
createdBySubjectId: request.createdBySubjectId ?? "",
|
|
820
811
|
subject: agentSubjectFromProto(request.subject),
|
|
821
812
|
sessionStart: request.sessionStart === undefined ? undefined : {
|
|
822
813
|
hooks: request.sessionStart.hooks.map((hook) => ({
|
|
@@ -888,6 +879,12 @@ function createAgentProviderTurnRequestFromProto(
|
|
|
888
879
|
if (output === undefined) {
|
|
889
880
|
throw new ConnectError("create turn output is required", Code.InvalidArgument);
|
|
890
881
|
}
|
|
882
|
+
if (!Number.isInteger(request.timeoutSeconds) || request.timeoutSeconds < 0) {
|
|
883
|
+
throw new ConnectError(
|
|
884
|
+
"agent create turn timeoutSeconds must not be negative",
|
|
885
|
+
Code.InvalidArgument,
|
|
886
|
+
);
|
|
887
|
+
}
|
|
891
888
|
return {
|
|
892
889
|
turnId: request.turnId,
|
|
893
890
|
sessionId: request.sessionId,
|
|
@@ -897,7 +894,7 @@ function createAgentProviderTurnRequestFromProto(
|
|
|
897
894
|
tools: request.tools.map(resolvedAgentToolFromProto),
|
|
898
895
|
output,
|
|
899
896
|
metadata: optionalObjectFromStruct(request.metadata),
|
|
900
|
-
|
|
897
|
+
createdBySubjectId: request.createdBySubjectId ?? "",
|
|
901
898
|
executionRef: request.executionRef,
|
|
902
899
|
toolRefs: request.toolRefs.map(agentToolRefFromProto),
|
|
903
900
|
toolSource: request.toolSource as AgentToolSourceMode,
|
|
@@ -997,7 +994,7 @@ function agentSessionToProto(
|
|
|
997
994
|
clientRef: session.clientRef ?? "",
|
|
998
995
|
state: session.state ?? AgentSessionState.UNSPECIFIED,
|
|
999
996
|
metadata: optionalStruct(session.metadata),
|
|
1000
|
-
|
|
997
|
+
createdBySubjectId: session.createdBySubjectId ?? "",
|
|
1001
998
|
createdAt: optionalTimestamp(session.createdAt),
|
|
1002
999
|
updatedAt: optionalTimestamp(session.updatedAt),
|
|
1003
1000
|
lastTurnAt: optionalTimestamp(session.lastTurnAt),
|
|
@@ -1014,7 +1011,7 @@ function agentTurnToProto(turn: AgentTurn): MessageInitShape<typeof AgentTurnSch
|
|
|
1014
1011
|
messages: turn.messages?.map(agentMessageToProto) ?? [],
|
|
1015
1012
|
output: agentTurnOutputToProto(turn.output),
|
|
1016
1013
|
statusMessage: turn.statusMessage ?? "",
|
|
1017
|
-
|
|
1014
|
+
createdBySubjectId: turn.createdBySubjectId ?? "",
|
|
1018
1015
|
createdAt: optionalTimestamp(turn.createdAt),
|
|
1019
1016
|
startedAt: optionalTimestamp(turn.startedAt),
|
|
1020
1017
|
completedAt: optionalTimestamp(turn.completedAt),
|
|
@@ -1090,10 +1087,7 @@ function agentSubjectFromProto(
|
|
|
1090
1087
|
}
|
|
1091
1088
|
return {
|
|
1092
1089
|
id: subject.id,
|
|
1093
|
-
kind: subject.kind,
|
|
1094
1090
|
credentialSubjectId: subject.credentialSubjectId,
|
|
1095
|
-
displayName: subject.displayName,
|
|
1096
|
-
authSource: subject.authSource,
|
|
1097
1091
|
email: subject.email,
|
|
1098
1092
|
};
|
|
1099
1093
|
}
|
package/src/api.ts
CHANGED
|
@@ -5,10 +5,7 @@ import type { AgentToolRef } from "./agent.ts";
|
|
|
5
5
|
|
|
6
6
|
export interface Subject {
|
|
7
7
|
id: string;
|
|
8
|
-
kind: string;
|
|
9
8
|
credentialSubjectId: string;
|
|
10
|
-
displayName: string;
|
|
11
|
-
authSource: string;
|
|
12
9
|
email: string;
|
|
13
10
|
}
|
|
14
11
|
|
|
@@ -17,10 +14,7 @@ export interface Subject {
|
|
|
17
14
|
*/
|
|
18
15
|
export interface SubjectInput {
|
|
19
16
|
id: string;
|
|
20
|
-
kind: string;
|
|
21
17
|
credentialSubjectId?: string | undefined;
|
|
22
|
-
displayName: string;
|
|
23
|
-
authSource: string;
|
|
24
18
|
email?: string | undefined;
|
|
25
19
|
}
|
|
26
20
|
|
|
@@ -62,7 +56,7 @@ export interface Request {
|
|
|
62
56
|
host: Host;
|
|
63
57
|
idempotencyKey: string;
|
|
64
58
|
// Workflow callback metadata uses a JSON-style lowerCamelCase object such as
|
|
65
|
-
// runId, target.steps, trigger.
|
|
59
|
+
// runId, target.steps, trigger.activationId, and trigger.event.specVersion.
|
|
66
60
|
workflow: Record<string, unknown>;
|
|
67
61
|
toolRefs: AgentToolRef[];
|
|
68
62
|
toolRefsSet: boolean;
|
|
@@ -136,6 +130,22 @@ export function ok<T>(body: T, headers?: ResponseHeaders): Response<T> {
|
|
|
136
130
|
* const input = request("token", { region: "us-east-1" }, { id: "usr_123" });
|
|
137
131
|
* ```
|
|
138
132
|
*/
|
|
133
|
+
export function parseSubjectId(
|
|
134
|
+
subjectId: string,
|
|
135
|
+
): { kind: string; id: string } | undefined {
|
|
136
|
+
const trimmed = subjectId.trim();
|
|
137
|
+
const index = trimmed.indexOf(":");
|
|
138
|
+
if (index <= 0 || index >= trimmed.length - 1) {
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
const kind = trimmed.slice(0, index).trim();
|
|
142
|
+
const id = trimmed.slice(index + 1).trim();
|
|
143
|
+
if (!kind || !id) {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
return { kind, id };
|
|
147
|
+
}
|
|
148
|
+
|
|
139
149
|
export function request(
|
|
140
150
|
token = "",
|
|
141
151
|
connectionParams: Record<string, string> = {},
|
|
@@ -157,18 +167,12 @@ export function request(
|
|
|
157
167
|
},
|
|
158
168
|
subject: {
|
|
159
169
|
id: subject.id ?? "",
|
|
160
|
-
kind: subject.kind ?? "",
|
|
161
170
|
credentialSubjectId: subject.credentialSubjectId ?? "",
|
|
162
|
-
displayName: subject.displayName ?? "",
|
|
163
|
-
authSource: subject.authSource ?? "",
|
|
164
171
|
email: subject.email ?? "",
|
|
165
172
|
},
|
|
166
173
|
agentSubject: {
|
|
167
174
|
id: agentSubject.id ?? "",
|
|
168
|
-
kind: agentSubject.kind ?? "",
|
|
169
175
|
credentialSubjectId: agentSubject.credentialSubjectId ?? "",
|
|
170
|
-
displayName: agentSubject.displayName ?? "",
|
|
171
|
-
authSource: agentSubject.authSource ?? "",
|
|
172
176
|
email: agentSubject.email ?? "",
|
|
173
177
|
},
|
|
174
178
|
credential: {
|