@valon-technologies/gestalt 0.0.1-alpha.36 → 0.0.1-alpha.37
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/package.json +1 -1
- package/src/agent-access.ts +2 -5
- package/src/agent-conversions.ts +29 -2
- package/src/agent.ts +90 -26
- package/src/api.ts +36 -1
- package/src/app-access.ts +5 -2
- package/src/index.ts +1 -1
- package/src/internal/gen/v1/agent_pb.ts +77 -2
- package/src/internal/gen/v1/app_pb.ts +184 -23
- package/src/internal/gen/v1/runtime_pb.ts +6 -1
- package/src/internal/gen/v1/test_pb.ts +66 -0
- package/src/internal/gen/v1/workflow_pb.ts +77 -2
- package/src/invocation-context.ts +20 -7
- package/src/runtime.ts +46 -26
- package/src/workflow-access.ts +26 -43
- package/src/workflow.ts +94 -14
package/package.json
CHANGED
package/src/agent-access.ts
CHANGED
|
@@ -37,7 +37,6 @@ import {
|
|
|
37
37
|
dateFromTimestamp,
|
|
38
38
|
type JsonObjectInput,
|
|
39
39
|
} from "./protocol.ts";
|
|
40
|
-
import { hostInvocationContext } from "./invocation-context.ts";
|
|
41
40
|
import {
|
|
42
41
|
optionalObjectFromStruct,
|
|
43
42
|
optionalStruct,
|
|
@@ -49,6 +48,7 @@ import {
|
|
|
49
48
|
ENV_HOST_SERVICE_SOCKET,
|
|
50
49
|
ENV_HOST_SERVICE_TOKEN,
|
|
51
50
|
} from "./host-service.ts";
|
|
51
|
+
import { hostInvocationContext } from "./invocation-context.ts";
|
|
52
52
|
|
|
53
53
|
export interface AgentWorkspaceGitCheckout {
|
|
54
54
|
url?: string | undefined;
|
|
@@ -165,9 +165,6 @@ export interface Agent {
|
|
|
165
165
|
|
|
166
166
|
/**
|
|
167
167
|
* Client for managing agent sessions, turns, events, and interactions.
|
|
168
|
-
*
|
|
169
|
-
* The constructor accepts either a Gestalt request or an invocation token. Each
|
|
170
|
-
* agent call forwards that token to the agent-provider facade.
|
|
171
168
|
*/
|
|
172
169
|
class AgentImpl implements Agent {
|
|
173
170
|
private readonly client: Client<typeof AgentProviderService>;
|
|
@@ -219,7 +216,7 @@ class AgentImpl implements Agent {
|
|
|
219
216
|
);
|
|
220
217
|
}
|
|
221
218
|
|
|
222
|
-
/** Lists agent sessions visible to the
|
|
219
|
+
/** Lists agent sessions visible to the request context. */
|
|
223
220
|
async listSessions(
|
|
224
221
|
request: AgentListSessions = {},
|
|
225
222
|
): Promise<AgentSession[]> {
|
package/src/agent-conversions.ts
CHANGED
|
@@ -21,8 +21,10 @@ import {
|
|
|
21
21
|
} from "./internal/gen/v1/agent_pb.ts";
|
|
22
22
|
import {
|
|
23
23
|
SubjectContextSchema,
|
|
24
|
+
SubjectPermissionContextSchema,
|
|
24
25
|
AgentToolRefSchema,
|
|
25
26
|
type SubjectContext as ProtoSubjectContext,
|
|
27
|
+
type SubjectPermissionContext as ProtoSubjectPermissionContext,
|
|
26
28
|
type AgentToolRef as ProtoAgentToolRef,
|
|
27
29
|
} from "./internal/gen/v1/app_pb.ts";
|
|
28
30
|
import {
|
|
@@ -43,7 +45,7 @@ import type {
|
|
|
43
45
|
AgentTurnOutput,
|
|
44
46
|
AgentTurnDisplay,
|
|
45
47
|
} from "./agent.ts";
|
|
46
|
-
import type { Subject, SubjectInput } from "./api.ts";
|
|
48
|
+
import type { Subject, SubjectInput, SubjectPermission } from "./api.ts";
|
|
47
49
|
|
|
48
50
|
export function agentTurnDisplayFromProto(
|
|
49
51
|
display?: ProtoAgentTurnDisplay | undefined,
|
|
@@ -299,11 +301,14 @@ function agentRunAsSubjectFromProto(
|
|
|
299
301
|
id: subject.id,
|
|
300
302
|
credentialSubjectId: subject.credentialSubjectId,
|
|
301
303
|
email: subject.email,
|
|
304
|
+
displayName: subject.displayName,
|
|
305
|
+
scopes: [...subject.scopes],
|
|
306
|
+
permissions: subjectPermissionsFromProto(subject.permissions),
|
|
302
307
|
};
|
|
303
308
|
}
|
|
304
309
|
|
|
305
310
|
function agentRunAsSubjectToProto(
|
|
306
|
-
subject?: SubjectInput | undefined,
|
|
311
|
+
subject?: SubjectInput | Subject | undefined,
|
|
307
312
|
): ProtoSubjectContext | undefined {
|
|
308
313
|
if (subject === undefined) {
|
|
309
314
|
return undefined;
|
|
@@ -312,5 +317,27 @@ function agentRunAsSubjectToProto(
|
|
|
312
317
|
id: subject.id ?? "",
|
|
313
318
|
credentialSubjectId: subject.credentialSubjectId ?? "",
|
|
314
319
|
email: subject.email ?? "",
|
|
320
|
+
displayName: subject.displayName ?? "",
|
|
321
|
+
scopes: [...(subject.scopes ?? [])],
|
|
322
|
+
permissions: subjectPermissionsToProto(subject.permissions),
|
|
315
323
|
});
|
|
316
324
|
}
|
|
325
|
+
|
|
326
|
+
function subjectPermissionsFromProto(
|
|
327
|
+
permissions: readonly ProtoSubjectPermissionContext[],
|
|
328
|
+
): SubjectPermission[] {
|
|
329
|
+
return permissions.map((permission) => ({
|
|
330
|
+
app: permission.app,
|
|
331
|
+
operations: permission.allOperations ? [] : [...permission.operations],
|
|
332
|
+
}));
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function subjectPermissionsToProto(
|
|
336
|
+
permissions?: readonly SubjectPermission[] | undefined,
|
|
337
|
+
): ProtoSubjectPermissionContext[] {
|
|
338
|
+
return permissions?.map((permission) => create(SubjectPermissionContextSchema, {
|
|
339
|
+
app: permission.app,
|
|
340
|
+
operations: [...permission.operations],
|
|
341
|
+
allOperations: permission.operations.length === 0,
|
|
342
|
+
})) ?? [];
|
|
343
|
+
}
|
package/src/agent.ts
CHANGED
|
@@ -70,13 +70,16 @@ import {
|
|
|
70
70
|
} from "./internal/gen/v1/agent_pb.ts";
|
|
71
71
|
import {
|
|
72
72
|
type SubjectContext as ProtoSubjectContext,
|
|
73
|
+
type SubjectPermissionContext as ProtoSubjectPermissionContext,
|
|
73
74
|
type AgentToolRef as ProtoAgentToolRef,
|
|
75
|
+
type RequestContext as ProtoRequestContext,
|
|
74
76
|
} from "./internal/gen/v1/app_pb.ts";
|
|
75
77
|
import {
|
|
76
78
|
errorMessage,
|
|
77
79
|
type MaybePromise,
|
|
78
80
|
type Subject,
|
|
79
81
|
type SubjectInput,
|
|
82
|
+
type SubjectPermission,
|
|
80
83
|
} from "./api.ts";
|
|
81
84
|
import {
|
|
82
85
|
agentOutputFromProto,
|
|
@@ -274,24 +277,28 @@ export interface CreateAgentProviderSessionRequest {
|
|
|
274
277
|
metadata?: JsonObjectInput | undefined;
|
|
275
278
|
createdBySubjectId?: string | undefined;
|
|
276
279
|
subject?: Subject | undefined;
|
|
280
|
+
invocationToken: string;
|
|
281
|
+
context?: ProtoRequestContext | undefined;
|
|
277
282
|
sessionStart?: AgentSessionStartConfig | undefined;
|
|
278
283
|
preparedWorkspace?: AgentPreparedWorkspace | undefined;
|
|
279
|
-
invocationToken: string;
|
|
280
284
|
}
|
|
281
285
|
|
|
282
286
|
export interface GetAgentProviderSessionRequest {
|
|
283
287
|
sessionId: string;
|
|
284
288
|
subject?: Subject | undefined;
|
|
285
289
|
invocationToken: string;
|
|
290
|
+
context?: ProtoRequestContext | undefined;
|
|
286
291
|
}
|
|
287
292
|
|
|
288
293
|
export interface ListAgentProviderSessionsRequest {
|
|
294
|
+
providerName?: string | undefined;
|
|
289
295
|
subject?: Subject | undefined;
|
|
296
|
+
invocationToken: string;
|
|
297
|
+
context?: ProtoRequestContext | undefined;
|
|
290
298
|
sessionIds: readonly string[];
|
|
291
299
|
state: AgentSessionState;
|
|
292
300
|
limit: number;
|
|
293
301
|
summaryOnly: boolean;
|
|
294
|
-
invocationToken: string;
|
|
295
302
|
}
|
|
296
303
|
|
|
297
304
|
export interface ListAgentProviderSessionsResponse {
|
|
@@ -305,6 +312,7 @@ export interface UpdateAgentProviderSessionRequest {
|
|
|
305
312
|
metadata?: JsonObjectInput | undefined;
|
|
306
313
|
subject?: Subject | undefined;
|
|
307
314
|
invocationToken: string;
|
|
315
|
+
context?: ProtoRequestContext | undefined;
|
|
308
316
|
}
|
|
309
317
|
|
|
310
318
|
export interface AgentTurn {
|
|
@@ -363,8 +371,9 @@ export interface CreateAgentProviderTurnRequest {
|
|
|
363
371
|
subject?: Subject | undefined;
|
|
364
372
|
modelOptions?: JsonObjectInput | undefined;
|
|
365
373
|
runGrant: string;
|
|
366
|
-
timeoutSeconds: number;
|
|
367
374
|
invocationToken: string;
|
|
375
|
+
context?: ProtoRequestContext | undefined;
|
|
376
|
+
timeoutSeconds: number;
|
|
368
377
|
}
|
|
369
378
|
|
|
370
379
|
export interface AgentTextOutput {
|
|
@@ -382,16 +391,18 @@ export interface GetAgentProviderTurnRequest {
|
|
|
382
391
|
turnId: string;
|
|
383
392
|
subject?: Subject | undefined;
|
|
384
393
|
invocationToken: string;
|
|
394
|
+
context?: ProtoRequestContext | undefined;
|
|
385
395
|
}
|
|
386
396
|
|
|
387
397
|
export interface ListAgentProviderTurnsRequest {
|
|
388
398
|
sessionId: string;
|
|
389
399
|
subject?: Subject | undefined;
|
|
400
|
+
invocationToken: string;
|
|
401
|
+
context?: ProtoRequestContext | undefined;
|
|
390
402
|
turnIds: readonly string[];
|
|
391
403
|
status: AgentExecutionStatus;
|
|
392
404
|
limit: number;
|
|
393
405
|
summaryOnly: boolean;
|
|
394
|
-
invocationToken: string;
|
|
395
406
|
}
|
|
396
407
|
|
|
397
408
|
export interface ListAgentProviderTurnsResponse {
|
|
@@ -403,6 +414,7 @@ export interface CancelAgentProviderTurnRequest {
|
|
|
403
414
|
reason: string;
|
|
404
415
|
subject?: Subject | undefined;
|
|
405
416
|
invocationToken: string;
|
|
417
|
+
context?: ProtoRequestContext | undefined;
|
|
406
418
|
}
|
|
407
419
|
|
|
408
420
|
export interface AgentTurnEvent {
|
|
@@ -423,6 +435,7 @@ export interface ListAgentProviderTurnEventsRequest {
|
|
|
423
435
|
limit: number;
|
|
424
436
|
subject?: Subject | undefined;
|
|
425
437
|
invocationToken: string;
|
|
438
|
+
context?: ProtoRequestContext | undefined;
|
|
426
439
|
}
|
|
427
440
|
|
|
428
441
|
export interface ListAgentProviderTurnEventsResponse {
|
|
@@ -447,12 +460,14 @@ export interface GetAgentProviderInteractionRequest {
|
|
|
447
460
|
interactionId: string;
|
|
448
461
|
subject?: Subject | undefined;
|
|
449
462
|
invocationToken: string;
|
|
463
|
+
context?: ProtoRequestContext | undefined;
|
|
450
464
|
}
|
|
451
465
|
|
|
452
466
|
export interface ListAgentProviderInteractionsRequest {
|
|
453
467
|
turnId: string;
|
|
454
468
|
subject?: Subject | undefined;
|
|
455
469
|
invocationToken: string;
|
|
470
|
+
context?: ProtoRequestContext | undefined;
|
|
456
471
|
}
|
|
457
472
|
|
|
458
473
|
export interface ListAgentProviderInteractionsResponse {
|
|
@@ -460,10 +475,12 @@ export interface ListAgentProviderInteractionsResponse {
|
|
|
460
475
|
}
|
|
461
476
|
|
|
462
477
|
export interface ResolveAgentProviderInteractionRequest {
|
|
478
|
+
turnId?: string | undefined;
|
|
463
479
|
interactionId: string;
|
|
464
480
|
resolution?: JsonObjectInput | undefined;
|
|
465
481
|
subject?: Subject | undefined;
|
|
466
482
|
invocationToken: string;
|
|
483
|
+
context?: ProtoRequestContext | undefined;
|
|
467
484
|
}
|
|
468
485
|
|
|
469
486
|
export interface GetAgentProviderCapabilitiesRequest {}
|
|
@@ -476,6 +493,7 @@ export interface ExecuteAgentToolRequest {
|
|
|
476
493
|
arguments?: JsonObjectInput | undefined;
|
|
477
494
|
idempotencyKey?: string | undefined;
|
|
478
495
|
runGrant?: string | undefined;
|
|
496
|
+
context?: ProtoRequestContext | undefined;
|
|
479
497
|
}
|
|
480
498
|
|
|
481
499
|
export interface ExecuteAgentToolResponse {
|
|
@@ -508,8 +526,9 @@ export interface ListAgentToolsRequest {
|
|
|
508
526
|
turnId: string;
|
|
509
527
|
pageSize?: number | undefined;
|
|
510
528
|
pageToken?: string | undefined;
|
|
511
|
-
runGrant?: string | undefined;
|
|
512
529
|
query?: string | undefined;
|
|
530
|
+
runGrant?: string | undefined;
|
|
531
|
+
context?: ProtoRequestContext | undefined;
|
|
513
532
|
}
|
|
514
533
|
|
|
515
534
|
export interface ListAgentToolsResponse {
|
|
@@ -523,6 +542,7 @@ export interface ResolveAgentConnectionRequest {
|
|
|
523
542
|
connection: string;
|
|
524
543
|
instance?: string | undefined;
|
|
525
544
|
runGrant?: string | undefined;
|
|
545
|
+
context?: ProtoRequestContext | undefined;
|
|
526
546
|
}
|
|
527
547
|
|
|
528
548
|
export interface ResolvedAgentConnection {
|
|
@@ -538,10 +558,11 @@ export interface ResolvedAgentConnection {
|
|
|
538
558
|
export interface AgentHostListToolsInput {
|
|
539
559
|
sessionId: string;
|
|
540
560
|
turnId: string;
|
|
541
|
-
runGrant?: string | undefined;
|
|
542
561
|
pageSize?: number | undefined;
|
|
543
562
|
pageToken?: string | undefined;
|
|
544
563
|
query?: string | undefined;
|
|
564
|
+
runGrant?: string | undefined;
|
|
565
|
+
context?: ProtoRequestContext | undefined;
|
|
545
566
|
}
|
|
546
567
|
|
|
547
568
|
/** Plain-object input for executing a tool during one agent turn. */
|
|
@@ -551,8 +572,9 @@ export interface AgentHostExecuteToolInput {
|
|
|
551
572
|
toolCallId: string;
|
|
552
573
|
toolId: string;
|
|
553
574
|
arguments?: JsonObjectInput | undefined;
|
|
554
|
-
runGrant?: string | undefined;
|
|
555
575
|
idempotencyKey?: string | undefined;
|
|
576
|
+
runGrant?: string | undefined;
|
|
577
|
+
context?: ProtoRequestContext | undefined;
|
|
556
578
|
}
|
|
557
579
|
|
|
558
580
|
/** Plain-object input for resolving a configured connection during one turn. */
|
|
@@ -562,6 +584,7 @@ export interface AgentHostResolveConnectionInput {
|
|
|
562
584
|
connection: string;
|
|
563
585
|
instance?: string | undefined;
|
|
564
586
|
runGrant?: string | undefined;
|
|
587
|
+
context?: ProtoRequestContext | undefined;
|
|
565
588
|
}
|
|
566
589
|
|
|
567
590
|
/** Fakeable client contract for agent host calls. */
|
|
@@ -808,7 +831,9 @@ function createAgentProviderSessionRequestFromProto(
|
|
|
808
831
|
clientRef: request.clientRef,
|
|
809
832
|
metadata: optionalObjectFromStruct(request.metadata),
|
|
810
833
|
createdBySubjectId: request.createdBySubjectId ?? "",
|
|
811
|
-
subject:
|
|
834
|
+
subject: agentRequestSubjectFromProto(request),
|
|
835
|
+
invocationToken: request.invocationToken,
|
|
836
|
+
context: request.context,
|
|
812
837
|
sessionStart: request.sessionStart === undefined ? undefined : {
|
|
813
838
|
hooks: request.sessionStart.hooks.map((hook) => ({
|
|
814
839
|
id: hook.id,
|
|
@@ -827,7 +852,6 @@ function createAgentProviderSessionRequestFromProto(
|
|
|
827
852
|
root: request.preparedWorkspace.root,
|
|
828
853
|
cwd: request.preparedWorkspace.cwd,
|
|
829
854
|
},
|
|
830
|
-
invocationToken: request.invocationToken,
|
|
831
855
|
};
|
|
832
856
|
}
|
|
833
857
|
|
|
@@ -836,8 +860,9 @@ function getAgentProviderSessionRequestFromProto(
|
|
|
836
860
|
): GetAgentProviderSessionRequest {
|
|
837
861
|
return {
|
|
838
862
|
sessionId: request.sessionId,
|
|
839
|
-
subject:
|
|
863
|
+
subject: agentRequestSubjectFromProto(request),
|
|
840
864
|
invocationToken: request.invocationToken,
|
|
865
|
+
context: request.context,
|
|
841
866
|
};
|
|
842
867
|
}
|
|
843
868
|
|
|
@@ -845,12 +870,14 @@ function listAgentProviderSessionsRequestFromProto(
|
|
|
845
870
|
request: ProtoListAgentProviderSessionsRequest,
|
|
846
871
|
): ListAgentProviderSessionsRequest {
|
|
847
872
|
return {
|
|
848
|
-
|
|
873
|
+
providerName: request.providerName,
|
|
874
|
+
subject: agentRequestSubjectFromProto(request),
|
|
875
|
+
invocationToken: request.invocationToken,
|
|
876
|
+
context: request.context,
|
|
849
877
|
sessionIds: [...request.sessionIds],
|
|
850
878
|
state: request.state as AgentSessionState,
|
|
851
879
|
limit: request.limit,
|
|
852
880
|
summaryOnly: request.summaryOnly,
|
|
853
|
-
invocationToken: request.invocationToken,
|
|
854
881
|
};
|
|
855
882
|
}
|
|
856
883
|
|
|
@@ -862,8 +889,9 @@ function updateAgentProviderSessionRequestFromProto(
|
|
|
862
889
|
clientRef: request.clientRef,
|
|
863
890
|
state: request.state as AgentSessionState,
|
|
864
891
|
metadata: optionalObjectFromStruct(request.metadata),
|
|
865
|
-
subject:
|
|
892
|
+
subject: agentRequestSubjectFromProto(request),
|
|
866
893
|
invocationToken: request.invocationToken,
|
|
894
|
+
context: request.context,
|
|
867
895
|
};
|
|
868
896
|
}
|
|
869
897
|
|
|
@@ -898,11 +926,12 @@ function createAgentProviderTurnRequestFromProto(
|
|
|
898
926
|
executionRef: request.executionRef,
|
|
899
927
|
toolRefs: request.toolRefs.map(agentToolRefFromProto),
|
|
900
928
|
toolSource: request.toolSource as AgentToolSourceMode,
|
|
901
|
-
subject:
|
|
929
|
+
subject: agentRequestSubjectFromProto(request),
|
|
902
930
|
modelOptions: optionalObjectFromStruct(request.modelOptions),
|
|
903
931
|
runGrant: request.runGrant,
|
|
904
|
-
timeoutSeconds: request.timeoutSeconds,
|
|
905
932
|
invocationToken: request.invocationToken,
|
|
933
|
+
context: request.context,
|
|
934
|
+
timeoutSeconds: request.timeoutSeconds,
|
|
906
935
|
};
|
|
907
936
|
}
|
|
908
937
|
|
|
@@ -911,8 +940,9 @@ function getAgentProviderTurnRequestFromProto(
|
|
|
911
940
|
): GetAgentProviderTurnRequest {
|
|
912
941
|
return {
|
|
913
942
|
turnId: request.turnId,
|
|
914
|
-
subject:
|
|
943
|
+
subject: agentRequestSubjectFromProto(request),
|
|
915
944
|
invocationToken: request.invocationToken,
|
|
945
|
+
context: request.context,
|
|
916
946
|
};
|
|
917
947
|
}
|
|
918
948
|
|
|
@@ -921,12 +951,13 @@ function listAgentProviderTurnsRequestFromProto(
|
|
|
921
951
|
): ListAgentProviderTurnsRequest {
|
|
922
952
|
return {
|
|
923
953
|
sessionId: request.sessionId,
|
|
924
|
-
subject:
|
|
954
|
+
subject: agentRequestSubjectFromProto(request),
|
|
955
|
+
invocationToken: request.invocationToken,
|
|
956
|
+
context: request.context,
|
|
925
957
|
turnIds: [...request.turnIds],
|
|
926
958
|
status: request.status as AgentExecutionStatus,
|
|
927
959
|
limit: request.limit,
|
|
928
960
|
summaryOnly: request.summaryOnly,
|
|
929
|
-
invocationToken: request.invocationToken,
|
|
930
961
|
};
|
|
931
962
|
}
|
|
932
963
|
|
|
@@ -936,8 +967,9 @@ function cancelAgentProviderTurnRequestFromProto(
|
|
|
936
967
|
return {
|
|
937
968
|
turnId: request.turnId,
|
|
938
969
|
reason: request.reason,
|
|
939
|
-
subject:
|
|
970
|
+
subject: agentRequestSubjectFromProto(request),
|
|
940
971
|
invocationToken: request.invocationToken,
|
|
972
|
+
context: request.context,
|
|
941
973
|
};
|
|
942
974
|
}
|
|
943
975
|
|
|
@@ -948,8 +980,9 @@ function listAgentProviderTurnEventsRequestFromProto(
|
|
|
948
980
|
turnId: request.turnId,
|
|
949
981
|
afterSeq: request.afterSeq,
|
|
950
982
|
limit: request.limit,
|
|
951
|
-
subject:
|
|
983
|
+
subject: agentRequestSubjectFromProto(request),
|
|
952
984
|
invocationToken: request.invocationToken,
|
|
985
|
+
context: request.context,
|
|
953
986
|
};
|
|
954
987
|
}
|
|
955
988
|
|
|
@@ -958,8 +991,9 @@ function getAgentProviderInteractionRequestFromProto(
|
|
|
958
991
|
): GetAgentProviderInteractionRequest {
|
|
959
992
|
return {
|
|
960
993
|
interactionId: request.interactionId,
|
|
961
|
-
subject:
|
|
994
|
+
subject: agentRequestSubjectFromProto(request),
|
|
962
995
|
invocationToken: request.invocationToken,
|
|
996
|
+
context: request.context,
|
|
963
997
|
};
|
|
964
998
|
}
|
|
965
999
|
|
|
@@ -968,8 +1002,9 @@ function listAgentProviderInteractionsRequestFromProto(
|
|
|
968
1002
|
): ListAgentProviderInteractionsRequest {
|
|
969
1003
|
return {
|
|
970
1004
|
turnId: request.turnId,
|
|
971
|
-
subject:
|
|
1005
|
+
subject: agentRequestSubjectFromProto(request),
|
|
972
1006
|
invocationToken: request.invocationToken,
|
|
1007
|
+
context: request.context,
|
|
973
1008
|
};
|
|
974
1009
|
}
|
|
975
1010
|
|
|
@@ -977,10 +1012,12 @@ function resolveAgentProviderInteractionRequestFromProto(
|
|
|
977
1012
|
request: ProtoResolveAgentProviderInteractionRequest,
|
|
978
1013
|
): ResolveAgentProviderInteractionRequest {
|
|
979
1014
|
return {
|
|
1015
|
+
turnId: request.turnId,
|
|
980
1016
|
interactionId: request.interactionId,
|
|
981
1017
|
resolution: optionalObjectFromStruct(request.resolution),
|
|
982
|
-
subject:
|
|
1018
|
+
subject: agentRequestSubjectFromProto(request),
|
|
983
1019
|
invocationToken: request.invocationToken,
|
|
1020
|
+
context: request.context,
|
|
984
1021
|
};
|
|
985
1022
|
}
|
|
986
1023
|
|
|
@@ -1079,6 +1116,15 @@ function resolvedAgentToolFromProto(tool: ProtoResolvedAgentTool): ResolvedAgent
|
|
|
1079
1116
|
};
|
|
1080
1117
|
}
|
|
1081
1118
|
|
|
1119
|
+
function agentRequestSubjectFromProto(
|
|
1120
|
+
request: {
|
|
1121
|
+
context?: { subject?: ProtoSubjectContext | undefined } | undefined;
|
|
1122
|
+
subject?: ProtoSubjectContext | undefined;
|
|
1123
|
+
},
|
|
1124
|
+
): Subject | undefined {
|
|
1125
|
+
return agentSubjectFromProto(request.context?.subject ?? request.subject);
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1082
1128
|
function agentSubjectFromProto(
|
|
1083
1129
|
subject?: ProtoSubjectContext | undefined,
|
|
1084
1130
|
): Subject | undefined {
|
|
@@ -1089,9 +1135,21 @@ function agentSubjectFromProto(
|
|
|
1089
1135
|
id: subject.id,
|
|
1090
1136
|
credentialSubjectId: subject.credentialSubjectId,
|
|
1091
1137
|
email: subject.email,
|
|
1138
|
+
displayName: subject.displayName,
|
|
1139
|
+
scopes: [...subject.scopes],
|
|
1140
|
+
permissions: agentSubjectPermissionsFromProto(subject.permissions),
|
|
1092
1141
|
};
|
|
1093
1142
|
}
|
|
1094
1143
|
|
|
1144
|
+
function agentSubjectPermissionsFromProto(
|
|
1145
|
+
permissions: readonly ProtoSubjectPermissionContext[],
|
|
1146
|
+
): SubjectPermission[] {
|
|
1147
|
+
return permissions.map((permission) => ({
|
|
1148
|
+
app: permission.app,
|
|
1149
|
+
operations: permission.allOperations ? [] : [...permission.operations],
|
|
1150
|
+
}));
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1095
1153
|
function optionalTimestamp(value?: Date | undefined) {
|
|
1096
1154
|
return value === undefined ? undefined : timestampFromDate(value);
|
|
1097
1155
|
}
|
|
@@ -1107,6 +1165,7 @@ function executeToolRequestToProto(
|
|
|
1107
1165
|
arguments: optionalStruct(request.arguments),
|
|
1108
1166
|
idempotencyKey: request.idempotencyKey ?? "",
|
|
1109
1167
|
runGrant: request.runGrant ?? "",
|
|
1168
|
+
context: request.context,
|
|
1110
1169
|
});
|
|
1111
1170
|
}
|
|
1112
1171
|
|
|
@@ -1125,8 +1184,9 @@ function listToolsRequestToProto(request: ListAgentToolsRequest): ProtoListAgent
|
|
|
1125
1184
|
turnId: request.turnId,
|
|
1126
1185
|
pageSize: request.pageSize ?? 0,
|
|
1127
1186
|
pageToken: request.pageToken ?? "",
|
|
1128
|
-
runGrant: request.runGrant ?? "",
|
|
1129
1187
|
query: request.query ?? "",
|
|
1188
|
+
runGrant: request.runGrant ?? "",
|
|
1189
|
+
context: request.context,
|
|
1130
1190
|
});
|
|
1131
1191
|
}
|
|
1132
1192
|
|
|
@@ -1168,6 +1228,7 @@ function resolveConnectionRequestToProto(
|
|
|
1168
1228
|
connection: request.connection,
|
|
1169
1229
|
instance: request.instance ?? "",
|
|
1170
1230
|
runGrant: request.runGrant ?? "",
|
|
1231
|
+
context: request.context,
|
|
1171
1232
|
});
|
|
1172
1233
|
}
|
|
1173
1234
|
|
|
@@ -1237,8 +1298,9 @@ class AgentHostImpl implements AgentHost {
|
|
|
1237
1298
|
toolCallId: input.toolCallId,
|
|
1238
1299
|
toolId: input.toolId,
|
|
1239
1300
|
arguments: input.arguments,
|
|
1240
|
-
runGrant: input.runGrant ?? "",
|
|
1241
1301
|
idempotencyKey: input.idempotencyKey ?? "",
|
|
1302
|
+
runGrant: input.runGrant ?? "",
|
|
1303
|
+
context: input.context,
|
|
1242
1304
|
},
|
|
1243
1305
|
);
|
|
1244
1306
|
}
|
|
@@ -1260,10 +1322,11 @@ class AgentHostImpl implements AgentHost {
|
|
|
1260
1322
|
{
|
|
1261
1323
|
sessionId: input.sessionId,
|
|
1262
1324
|
turnId: input.turnId,
|
|
1263
|
-
runGrant: input.runGrant ?? "",
|
|
1264
1325
|
pageSize: input.pageSize ?? 0,
|
|
1265
1326
|
pageToken: input.pageToken ?? "",
|
|
1266
1327
|
query: input.query ?? "",
|
|
1328
|
+
runGrant: input.runGrant ?? "",
|
|
1329
|
+
context: input.context,
|
|
1267
1330
|
},
|
|
1268
1331
|
);
|
|
1269
1332
|
}
|
|
@@ -1288,6 +1351,7 @@ class AgentHostImpl implements AgentHost {
|
|
|
1288
1351
|
connection: input.connection,
|
|
1289
1352
|
instance: input.instance ?? "",
|
|
1290
1353
|
runGrant: input.runGrant ?? "",
|
|
1354
|
+
context: input.context,
|
|
1291
1355
|
},
|
|
1292
1356
|
);
|
|
1293
1357
|
}
|
package/src/api.ts
CHANGED
|
@@ -2,16 +2,24 @@
|
|
|
2
2
|
* Common request and response types shared across authored Gestalt providers.
|
|
3
3
|
*/
|
|
4
4
|
import type { AgentToolRef } from "./agent.ts";
|
|
5
|
+
import type { RequestContext as ProtoRequestContext } from "./internal/gen/v1/app_pb.ts";
|
|
5
6
|
|
|
6
7
|
export interface Subject {
|
|
7
8
|
id: string;
|
|
8
9
|
credentialSubjectId: string;
|
|
9
10
|
email: string;
|
|
11
|
+
scopes?: string[] | undefined;
|
|
12
|
+
permissions?: SubjectPermission[] | undefined;
|
|
10
13
|
kind?: string | undefined;
|
|
11
14
|
displayName?: string | undefined;
|
|
12
15
|
authSource?: string | undefined;
|
|
13
16
|
}
|
|
14
17
|
|
|
18
|
+
export interface SubjectPermission {
|
|
19
|
+
app: string;
|
|
20
|
+
operations: string[];
|
|
21
|
+
}
|
|
22
|
+
|
|
15
23
|
/**
|
|
16
24
|
* Subject payload authored by provider-side hooks.
|
|
17
25
|
*/
|
|
@@ -19,6 +27,9 @@ export interface SubjectInput {
|
|
|
19
27
|
id: string;
|
|
20
28
|
credentialSubjectId?: string | undefined;
|
|
21
29
|
email?: string | undefined;
|
|
30
|
+
displayName?: string | undefined;
|
|
31
|
+
scopes?: readonly string[] | undefined;
|
|
32
|
+
permissions?: readonly SubjectPermission[] | undefined;
|
|
22
33
|
}
|
|
23
34
|
|
|
24
35
|
/**
|
|
@@ -64,6 +75,7 @@ export interface Request {
|
|
|
64
75
|
toolRefs: AgentToolRef[];
|
|
65
76
|
toolRefsSet: boolean;
|
|
66
77
|
invocationToken: string;
|
|
78
|
+
__requestContext?: ProtoRequestContext | undefined;
|
|
67
79
|
}
|
|
68
80
|
|
|
69
81
|
/**
|
|
@@ -162,6 +174,7 @@ export function request(
|
|
|
162
174
|
agentSubject: Partial<Subject> = {},
|
|
163
175
|
toolRefs: readonly AgentToolRef[] = [],
|
|
164
176
|
toolRefsSet = false,
|
|
177
|
+
requestContext?: ProtoRequestContext,
|
|
165
178
|
): Request {
|
|
166
179
|
return {
|
|
167
180
|
token,
|
|
@@ -172,6 +185,8 @@ export function request(
|
|
|
172
185
|
id: subject.id ?? "",
|
|
173
186
|
credentialSubjectId: subject.credentialSubjectId ?? "",
|
|
174
187
|
email: subject.email ?? "",
|
|
188
|
+
scopes: [...(subject.scopes ?? [])],
|
|
189
|
+
permissions: cloneSubjectPermissions(subject.permissions),
|
|
175
190
|
kind: subject.kind,
|
|
176
191
|
displayName: subject.displayName,
|
|
177
192
|
authSource: subject.authSource,
|
|
@@ -180,6 +195,8 @@ export function request(
|
|
|
180
195
|
id: agentSubject.id ?? "",
|
|
181
196
|
credentialSubjectId: agentSubject.credentialSubjectId ?? "",
|
|
182
197
|
email: agentSubject.email ?? "",
|
|
198
|
+
scopes: [...(agentSubject.scopes ?? [])],
|
|
199
|
+
permissions: cloneSubjectPermissions(agentSubject.permissions),
|
|
183
200
|
kind: agentSubject.kind,
|
|
184
201
|
displayName: agentSubject.displayName,
|
|
185
202
|
authSource: agentSubject.authSource,
|
|
@@ -199,17 +216,35 @@ export function request(
|
|
|
199
216
|
},
|
|
200
217
|
toolRefs: toolRefs.map((ref) => ({
|
|
201
218
|
...ref,
|
|
202
|
-
runAs: ref.runAs === undefined ? undefined :
|
|
219
|
+
runAs: ref.runAs === undefined ? undefined : cloneSubjectInput(ref.runAs),
|
|
203
220
|
})),
|
|
204
221
|
toolRefsSet,
|
|
205
222
|
host: {
|
|
206
223
|
publicBaseUrl: host.publicBaseUrl ?? "",
|
|
207
224
|
},
|
|
208
225
|
invocationToken,
|
|
226
|
+
__requestContext: requestContext,
|
|
209
227
|
idempotencyKey: idempotencyKey.trim(),
|
|
210
228
|
};
|
|
211
229
|
}
|
|
212
230
|
|
|
231
|
+
export function cloneSubjectInput<T extends SubjectInput | Subject>(subject: T): T {
|
|
232
|
+
return {
|
|
233
|
+
...subject,
|
|
234
|
+
scopes: [...(subject.scopes ?? [])],
|
|
235
|
+
permissions: cloneSubjectPermissions(subject.permissions),
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export function cloneSubjectPermissions(
|
|
240
|
+
permissions?: readonly SubjectPermission[] | undefined,
|
|
241
|
+
): SubjectPermission[] {
|
|
242
|
+
return permissions?.map((permission) => ({
|
|
243
|
+
app: permission.app,
|
|
244
|
+
operations: [...permission.operations],
|
|
245
|
+
})) ?? [];
|
|
246
|
+
}
|
|
247
|
+
|
|
213
248
|
/**
|
|
214
249
|
* Looks up a single connection parameter from a request.
|
|
215
250
|
*/
|
package/src/app-access.ts
CHANGED
|
@@ -27,6 +27,7 @@ export interface AppInvokeOptions {
|
|
|
27
27
|
/** Credential mode requested for the target operation. */
|
|
28
28
|
credentialMode?: ConnectionMode;
|
|
29
29
|
}
|
|
30
|
+
|
|
30
31
|
/** Grant included when exchanging an invocation token for a child token. */
|
|
31
32
|
export interface AppInvocationGrant {
|
|
32
33
|
/** App name that the child token may invoke. */
|
|
@@ -68,8 +69,9 @@ export interface App {
|
|
|
68
69
|
/**
|
|
69
70
|
* Transport-backed implementation for invoking sibling app operations.
|
|
70
71
|
*
|
|
71
|
-
* The constructor accepts either a Gestalt request or an invocation token.
|
|
72
|
-
*
|
|
72
|
+
* The constructor accepts either a Gestalt request or an invocation token. A
|
|
73
|
+
* request forwards both its host request context and legacy invocation token
|
|
74
|
+
* when available.
|
|
73
75
|
*/
|
|
74
76
|
class AppImpl implements App {
|
|
75
77
|
private readonly client: Client<typeof AppService>;
|
|
@@ -125,6 +127,7 @@ class AppImpl implements App {
|
|
|
125
127
|
|
|
126
128
|
const response = await this.client.invokeGraphQL({
|
|
127
129
|
invocationToken: this.invocationContext.invocationToken,
|
|
130
|
+
context: this.invocationContext.context,
|
|
128
131
|
app,
|
|
129
132
|
document: trimmedDocument,
|
|
130
133
|
...(options?.variables !== undefined
|