@valon-technologies/gestalt 0.0.1-alpha.36 → 0.0.1-alpha.38

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valon-technologies/gestalt",
3
- "version": "0.0.1-alpha.36",
3
+ "version": "0.0.1-alpha.38",
4
4
  "description": "TypeScript SDK for Gestalt executable providers",
5
5
  "type": "module",
6
6
  "repository": {
@@ -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,
@@ -165,18 +164,14 @@ export interface Agent {
165
164
 
166
165
  /**
167
166
  * 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
167
  */
172
168
  class AgentImpl implements Agent {
173
169
  private readonly client: Client<typeof AgentProviderService>;
174
- private readonly invocationContext: ReturnType<typeof hostInvocationContext>;
170
+ private readonly context: Request["__requestContext"];
175
171
 
176
172
  constructor(request: Request);
177
- constructor(invocationToken: string);
178
- constructor(requestOrToken: Request | string) {
179
- this.invocationContext = hostInvocationContext(requestOrToken);
173
+ constructor(request: Request) {
174
+ this.context = request.__requestContext;
180
175
 
181
176
  const target = process.env[ENV_HOST_SERVICE_SOCKET]?.trim();
182
177
  if (!target) {
@@ -203,7 +198,7 @@ class AgentImpl implements Agent {
203
198
  clientRef: request.clientRef ?? "",
204
199
  metadata: optionalStruct(request.metadata),
205
200
  idempotencyKey: request.idempotencyKey ?? "",
206
- ...this.invocationContext,
201
+ context: this.context,
207
202
  workspace: workspaceToProto(request.workspace),
208
203
  }),
209
204
  );
@@ -214,18 +209,18 @@ class AgentImpl implements Agent {
214
209
  return agentSessionFromProto(
215
210
  await this.client.getSession({
216
211
  sessionId: request.sessionId,
217
- ...this.invocationContext,
212
+ context: this.context,
218
213
  }),
219
214
  );
220
215
  }
221
216
 
222
- /** Lists agent sessions visible to the invocation token. */
217
+ /** Lists agent sessions visible to the request context. */
223
218
  async listSessions(
224
219
  request: AgentListSessions = {},
225
220
  ): Promise<AgentSession[]> {
226
221
  const response = await this.client.listSessions({
227
222
  providerName: request.providerName ?? "",
228
- ...this.invocationContext,
223
+ context: this.context,
229
224
  state: request.state ?? AgentSessionState.UNSPECIFIED,
230
225
  limit: request.limit ?? 0,
231
226
  summaryOnly: request.summaryOnly ?? false,
@@ -243,7 +238,7 @@ class AgentImpl implements Agent {
243
238
  clientRef: request.clientRef ?? "",
244
239
  state: request.state ?? AgentSessionState.UNSPECIFIED,
245
240
  metadata: optionalStruct(request.metadata),
246
- ...this.invocationContext,
241
+ context: this.context,
247
242
  }),
248
243
  );
249
244
  }
@@ -264,7 +259,7 @@ class AgentImpl implements Agent {
264
259
  output: agentOutputToProto(request.output),
265
260
  metadata: optionalStruct(request.metadata),
266
261
  idempotencyKey: request.idempotencyKey ?? "",
267
- ...this.invocationContext,
262
+ context: this.context,
268
263
  modelOptions: optionalStruct(request.modelOptions),
269
264
  timeoutSeconds,
270
265
  }),
@@ -276,7 +271,7 @@ class AgentImpl implements Agent {
276
271
  return agentTurnFromProto(
277
272
  await this.client.getTurn({
278
273
  turnId: request.turnId,
279
- ...this.invocationContext,
274
+ context: this.context,
280
275
  }),
281
276
  );
282
277
  }
@@ -285,7 +280,7 @@ class AgentImpl implements Agent {
285
280
  async listTurns(request: AgentListTurns): Promise<AgentTurn[]> {
286
281
  const response = await this.client.listTurns({
287
282
  sessionId: request.sessionId,
288
- ...this.invocationContext,
283
+ context: this.context,
289
284
  status: request.status ?? AgentExecutionStatus.UNSPECIFIED,
290
285
  limit: request.limit ?? 0,
291
286
  summaryOnly: request.summaryOnly ?? false,
@@ -299,7 +294,7 @@ class AgentImpl implements Agent {
299
294
  await this.client.cancelTurn({
300
295
  turnId: request.turnId,
301
296
  reason: request.reason ?? "",
302
- ...this.invocationContext,
297
+ context: this.context,
303
298
  }),
304
299
  );
305
300
  }
@@ -312,7 +307,7 @@ class AgentImpl implements Agent {
312
307
  turnId: request.turnId,
313
308
  afterSeq: BigInt(request.afterSeq ?? 0),
314
309
  limit: request.limit ?? 0,
315
- ...this.invocationContext,
310
+ context: this.context,
316
311
  });
317
312
  return response.events.map(agentTurnEventFromProto);
318
313
  }
@@ -323,7 +318,7 @@ class AgentImpl implements Agent {
323
318
  ): Promise<AgentInteraction[]> {
324
319
  const response = await this.client.listInteractions({
325
320
  turnId: request.turnId,
326
- ...this.invocationContext,
321
+ context: this.context,
327
322
  });
328
323
  return response.interactions.map(agentInteractionFromProto);
329
324
  }
@@ -337,7 +332,7 @@ class AgentImpl implements Agent {
337
332
  turnId: request.turnId,
338
333
  interactionId: request.interactionId,
339
334
  resolution: optionalStruct(request.resolution),
340
- ...this.invocationContext,
335
+ context: this.context,
341
336
  }),
342
337
  );
343
338
  }
@@ -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,
@@ -271,6 +273,7 @@ export function agentToolRefFromProto(ref: ProtoAgentToolRef): AgentToolRef {
271
273
  instance: ref.instance,
272
274
  title: ref.title,
273
275
  description: ref.description,
276
+ credentialMode: ref.credentialMode,
274
277
  system: ref.system,
275
278
  runAs: agentRunAsSubjectFromProto(ref.runAs),
276
279
  };
@@ -284,6 +287,7 @@ export function agentToolRefToProto(ref: AgentToolRef): ProtoAgentToolRef {
284
287
  instance: ref.instance ?? "",
285
288
  title: ref.title ?? "",
286
289
  description: ref.description ?? "",
290
+ credentialMode: ref.credentialMode ?? "",
287
291
  system: ref.system ?? "",
288
292
  runAs: agentRunAsSubjectToProto(ref.runAs),
289
293
  });
@@ -299,11 +303,14 @@ function agentRunAsSubjectFromProto(
299
303
  id: subject.id,
300
304
  credentialSubjectId: subject.credentialSubjectId,
301
305
  email: subject.email,
306
+ displayName: subject.displayName,
307
+ scopes: [...subject.scopes],
308
+ permissions: subjectPermissionsFromProto(subject.permissions),
302
309
  };
303
310
  }
304
311
 
305
312
  function agentRunAsSubjectToProto(
306
- subject?: SubjectInput | undefined,
313
+ subject?: SubjectInput | Subject | undefined,
307
314
  ): ProtoSubjectContext | undefined {
308
315
  if (subject === undefined) {
309
316
  return undefined;
@@ -312,5 +319,27 @@ function agentRunAsSubjectToProto(
312
319
  id: subject.id ?? "",
313
320
  credentialSubjectId: subject.credentialSubjectId ?? "",
314
321
  email: subject.email ?? "",
322
+ displayName: subject.displayName ?? "",
323
+ scopes: [...(subject.scopes ?? [])],
324
+ permissions: subjectPermissionsToProto(subject.permissions),
315
325
  });
316
326
  }
327
+
328
+ function subjectPermissionsFromProto(
329
+ permissions: readonly ProtoSubjectPermissionContext[],
330
+ ): SubjectPermission[] {
331
+ return permissions.map((permission) => ({
332
+ app: permission.app,
333
+ operations: permission.allOperations ? [] : [...permission.operations],
334
+ }));
335
+ }
336
+
337
+ function subjectPermissionsToProto(
338
+ permissions?: readonly SubjectPermission[] | undefined,
339
+ ): ProtoSubjectPermissionContext[] {
340
+ return permissions?.map((permission) => create(SubjectPermissionContextSchema, {
341
+ app: permission.app,
342
+ operations: [...permission.operations],
343
+ allOperations: permission.operations.length === 0,
344
+ })) ?? [];
345
+ }
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,
@@ -205,6 +208,7 @@ export interface AgentToolRef {
205
208
  instance?: string | undefined;
206
209
  title?: string | undefined;
207
210
  description?: string | undefined;
211
+ credentialMode?: string | undefined;
208
212
  system?: string | undefined;
209
213
  runAs?: SubjectInput | undefined;
210
214
  }
@@ -274,24 +278,25 @@ export interface CreateAgentProviderSessionRequest {
274
278
  metadata?: JsonObjectInput | undefined;
275
279
  createdBySubjectId?: string | undefined;
276
280
  subject?: Subject | undefined;
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
- invocationToken: string;
289
+ context?: ProtoRequestContext | undefined;
286
290
  }
287
291
 
288
292
  export interface ListAgentProviderSessionsRequest {
293
+ providerName?: string | undefined;
289
294
  subject?: Subject | undefined;
295
+ context?: ProtoRequestContext | undefined;
290
296
  sessionIds: readonly string[];
291
297
  state: AgentSessionState;
292
298
  limit: number;
293
299
  summaryOnly: boolean;
294
- invocationToken: string;
295
300
  }
296
301
 
297
302
  export interface ListAgentProviderSessionsResponse {
@@ -304,7 +309,7 @@ export interface UpdateAgentProviderSessionRequest {
304
309
  state: AgentSessionState;
305
310
  metadata?: JsonObjectInput | undefined;
306
311
  subject?: Subject | undefined;
307
- invocationToken: string;
312
+ context?: ProtoRequestContext | undefined;
308
313
  }
309
314
 
310
315
  export interface AgentTurn {
@@ -362,9 +367,8 @@ export interface CreateAgentProviderTurnRequest {
362
367
  toolSource: AgentToolSourceMode;
363
368
  subject?: Subject | undefined;
364
369
  modelOptions?: JsonObjectInput | undefined;
365
- runGrant: string;
370
+ context?: ProtoRequestContext | undefined;
366
371
  timeoutSeconds: number;
367
- invocationToken: string;
368
372
  }
369
373
 
370
374
  export interface AgentTextOutput {
@@ -381,17 +385,17 @@ export type AgentOutput =
381
385
  export interface GetAgentProviderTurnRequest {
382
386
  turnId: string;
383
387
  subject?: Subject | undefined;
384
- invocationToken: string;
388
+ context?: ProtoRequestContext | undefined;
385
389
  }
386
390
 
387
391
  export interface ListAgentProviderTurnsRequest {
388
392
  sessionId: string;
389
393
  subject?: Subject | undefined;
394
+ context?: ProtoRequestContext | undefined;
390
395
  turnIds: readonly string[];
391
396
  status: AgentExecutionStatus;
392
397
  limit: number;
393
398
  summaryOnly: boolean;
394
- invocationToken: string;
395
399
  }
396
400
 
397
401
  export interface ListAgentProviderTurnsResponse {
@@ -402,7 +406,7 @@ export interface CancelAgentProviderTurnRequest {
402
406
  turnId: string;
403
407
  reason: string;
404
408
  subject?: Subject | undefined;
405
- invocationToken: string;
409
+ context?: ProtoRequestContext | undefined;
406
410
  }
407
411
 
408
412
  export interface AgentTurnEvent {
@@ -422,7 +426,7 @@ export interface ListAgentProviderTurnEventsRequest {
422
426
  afterSeq: bigint;
423
427
  limit: number;
424
428
  subject?: Subject | undefined;
425
- invocationToken: string;
429
+ context?: ProtoRequestContext | undefined;
426
430
  }
427
431
 
428
432
  export interface ListAgentProviderTurnEventsResponse {
@@ -446,13 +450,13 @@ export interface AgentInteraction {
446
450
  export interface GetAgentProviderInteractionRequest {
447
451
  interactionId: string;
448
452
  subject?: Subject | undefined;
449
- invocationToken: string;
453
+ context?: ProtoRequestContext | undefined;
450
454
  }
451
455
 
452
456
  export interface ListAgentProviderInteractionsRequest {
453
457
  turnId: string;
454
458
  subject?: Subject | undefined;
455
- invocationToken: string;
459
+ context?: ProtoRequestContext | undefined;
456
460
  }
457
461
 
458
462
  export interface ListAgentProviderInteractionsResponse {
@@ -460,10 +464,11 @@ export interface ListAgentProviderInteractionsResponse {
460
464
  }
461
465
 
462
466
  export interface ResolveAgentProviderInteractionRequest {
467
+ turnId?: string | undefined;
463
468
  interactionId: string;
464
469
  resolution?: JsonObjectInput | undefined;
465
470
  subject?: Subject | undefined;
466
- invocationToken: string;
471
+ context?: ProtoRequestContext | undefined;
467
472
  }
468
473
 
469
474
  export interface GetAgentProviderCapabilitiesRequest {}
@@ -475,7 +480,7 @@ export interface ExecuteAgentToolRequest {
475
480
  toolId: string;
476
481
  arguments?: JsonObjectInput | undefined;
477
482
  idempotencyKey?: string | undefined;
478
- runGrant?: string | undefined;
483
+ context?: ProtoRequestContext | undefined;
479
484
  }
480
485
 
481
486
  export interface ExecuteAgentToolResponse {
@@ -508,8 +513,8 @@ export interface ListAgentToolsRequest {
508
513
  turnId: string;
509
514
  pageSize?: number | undefined;
510
515
  pageToken?: string | undefined;
511
- runGrant?: string | undefined;
512
516
  query?: string | undefined;
517
+ context?: ProtoRequestContext | undefined;
513
518
  }
514
519
 
515
520
  export interface ListAgentToolsResponse {
@@ -522,7 +527,7 @@ export interface ResolveAgentConnectionRequest {
522
527
  turnId: string;
523
528
  connection: string;
524
529
  instance?: string | undefined;
525
- runGrant?: string | undefined;
530
+ context?: ProtoRequestContext | undefined;
526
531
  }
527
532
 
528
533
  export interface ResolvedAgentConnection {
@@ -538,10 +543,10 @@ export interface ResolvedAgentConnection {
538
543
  export interface AgentHostListToolsInput {
539
544
  sessionId: string;
540
545
  turnId: string;
541
- runGrant?: string | undefined;
542
546
  pageSize?: number | undefined;
543
547
  pageToken?: string | undefined;
544
548
  query?: string | undefined;
549
+ context?: ProtoRequestContext | undefined;
545
550
  }
546
551
 
547
552
  /** Plain-object input for executing a tool during one agent turn. */
@@ -551,8 +556,8 @@ export interface AgentHostExecuteToolInput {
551
556
  toolCallId: string;
552
557
  toolId: string;
553
558
  arguments?: JsonObjectInput | undefined;
554
- runGrant?: string | undefined;
555
559
  idempotencyKey?: string | undefined;
560
+ context?: ProtoRequestContext | undefined;
556
561
  }
557
562
 
558
563
  /** Plain-object input for resolving a configured connection during one turn. */
@@ -561,7 +566,7 @@ export interface AgentHostResolveConnectionInput {
561
566
  turnId: string;
562
567
  connection: string;
563
568
  instance?: string | undefined;
564
- runGrant?: string | undefined;
569
+ context?: ProtoRequestContext | undefined;
565
570
  }
566
571
 
567
572
  /** Fakeable client contract for agent host calls. */
@@ -808,7 +813,8 @@ function createAgentProviderSessionRequestFromProto(
808
813
  clientRef: request.clientRef,
809
814
  metadata: optionalObjectFromStruct(request.metadata),
810
815
  createdBySubjectId: request.createdBySubjectId ?? "",
811
- subject: agentSubjectFromProto(request.subject),
816
+ subject: agentRequestSubjectFromProto(request),
817
+ context: request.context,
812
818
  sessionStart: request.sessionStart === undefined ? undefined : {
813
819
  hooks: request.sessionStart.hooks.map((hook) => ({
814
820
  id: hook.id,
@@ -827,7 +833,6 @@ function createAgentProviderSessionRequestFromProto(
827
833
  root: request.preparedWorkspace.root,
828
834
  cwd: request.preparedWorkspace.cwd,
829
835
  },
830
- invocationToken: request.invocationToken,
831
836
  };
832
837
  }
833
838
 
@@ -836,8 +841,8 @@ function getAgentProviderSessionRequestFromProto(
836
841
  ): GetAgentProviderSessionRequest {
837
842
  return {
838
843
  sessionId: request.sessionId,
839
- subject: agentSubjectFromProto(request.subject),
840
- invocationToken: request.invocationToken,
844
+ subject: agentRequestSubjectFromProto(request),
845
+ context: request.context,
841
846
  };
842
847
  }
843
848
 
@@ -845,12 +850,13 @@ function listAgentProviderSessionsRequestFromProto(
845
850
  request: ProtoListAgentProviderSessionsRequest,
846
851
  ): ListAgentProviderSessionsRequest {
847
852
  return {
848
- subject: agentSubjectFromProto(request.subject),
853
+ providerName: request.providerName,
854
+ subject: agentRequestSubjectFromProto(request),
855
+ context: request.context,
849
856
  sessionIds: [...request.sessionIds],
850
857
  state: request.state as AgentSessionState,
851
858
  limit: request.limit,
852
859
  summaryOnly: request.summaryOnly,
853
- invocationToken: request.invocationToken,
854
860
  };
855
861
  }
856
862
 
@@ -862,8 +868,8 @@ function updateAgentProviderSessionRequestFromProto(
862
868
  clientRef: request.clientRef,
863
869
  state: request.state as AgentSessionState,
864
870
  metadata: optionalObjectFromStruct(request.metadata),
865
- subject: agentSubjectFromProto(request.subject),
866
- invocationToken: request.invocationToken,
871
+ subject: agentRequestSubjectFromProto(request),
872
+ context: request.context,
867
873
  };
868
874
  }
869
875
 
@@ -898,11 +904,10 @@ function createAgentProviderTurnRequestFromProto(
898
904
  executionRef: request.executionRef,
899
905
  toolRefs: request.toolRefs.map(agentToolRefFromProto),
900
906
  toolSource: request.toolSource as AgentToolSourceMode,
901
- subject: agentSubjectFromProto(request.subject),
907
+ subject: agentRequestSubjectFromProto(request),
902
908
  modelOptions: optionalObjectFromStruct(request.modelOptions),
903
- runGrant: request.runGrant,
909
+ context: request.context,
904
910
  timeoutSeconds: request.timeoutSeconds,
905
- invocationToken: request.invocationToken,
906
911
  };
907
912
  }
908
913
 
@@ -911,8 +916,8 @@ function getAgentProviderTurnRequestFromProto(
911
916
  ): GetAgentProviderTurnRequest {
912
917
  return {
913
918
  turnId: request.turnId,
914
- subject: agentSubjectFromProto(request.subject),
915
- invocationToken: request.invocationToken,
919
+ subject: agentRequestSubjectFromProto(request),
920
+ context: request.context,
916
921
  };
917
922
  }
918
923
 
@@ -921,12 +926,12 @@ function listAgentProviderTurnsRequestFromProto(
921
926
  ): ListAgentProviderTurnsRequest {
922
927
  return {
923
928
  sessionId: request.sessionId,
924
- subject: agentSubjectFromProto(request.subject),
929
+ subject: agentRequestSubjectFromProto(request),
930
+ context: request.context,
925
931
  turnIds: [...request.turnIds],
926
932
  status: request.status as AgentExecutionStatus,
927
933
  limit: request.limit,
928
934
  summaryOnly: request.summaryOnly,
929
- invocationToken: request.invocationToken,
930
935
  };
931
936
  }
932
937
 
@@ -936,8 +941,8 @@ function cancelAgentProviderTurnRequestFromProto(
936
941
  return {
937
942
  turnId: request.turnId,
938
943
  reason: request.reason,
939
- subject: agentSubjectFromProto(request.subject),
940
- invocationToken: request.invocationToken,
944
+ subject: agentRequestSubjectFromProto(request),
945
+ context: request.context,
941
946
  };
942
947
  }
943
948
 
@@ -948,8 +953,8 @@ function listAgentProviderTurnEventsRequestFromProto(
948
953
  turnId: request.turnId,
949
954
  afterSeq: request.afterSeq,
950
955
  limit: request.limit,
951
- subject: agentSubjectFromProto(request.subject),
952
- invocationToken: request.invocationToken,
956
+ subject: agentRequestSubjectFromProto(request),
957
+ context: request.context,
953
958
  };
954
959
  }
955
960
 
@@ -958,8 +963,8 @@ function getAgentProviderInteractionRequestFromProto(
958
963
  ): GetAgentProviderInteractionRequest {
959
964
  return {
960
965
  interactionId: request.interactionId,
961
- subject: agentSubjectFromProto(request.subject),
962
- invocationToken: request.invocationToken,
966
+ subject: agentRequestSubjectFromProto(request),
967
+ context: request.context,
963
968
  };
964
969
  }
965
970
 
@@ -968,8 +973,8 @@ function listAgentProviderInteractionsRequestFromProto(
968
973
  ): ListAgentProviderInteractionsRequest {
969
974
  return {
970
975
  turnId: request.turnId,
971
- subject: agentSubjectFromProto(request.subject),
972
- invocationToken: request.invocationToken,
976
+ subject: agentRequestSubjectFromProto(request),
977
+ context: request.context,
973
978
  };
974
979
  }
975
980
 
@@ -977,10 +982,11 @@ function resolveAgentProviderInteractionRequestFromProto(
977
982
  request: ProtoResolveAgentProviderInteractionRequest,
978
983
  ): ResolveAgentProviderInteractionRequest {
979
984
  return {
985
+ turnId: request.turnId,
980
986
  interactionId: request.interactionId,
981
987
  resolution: optionalObjectFromStruct(request.resolution),
982
- subject: agentSubjectFromProto(request.subject),
983
- invocationToken: request.invocationToken,
988
+ subject: agentRequestSubjectFromProto(request),
989
+ context: request.context,
984
990
  };
985
991
  }
986
992
 
@@ -1079,6 +1085,15 @@ function resolvedAgentToolFromProto(tool: ProtoResolvedAgentTool): ResolvedAgent
1079
1085
  };
1080
1086
  }
1081
1087
 
1088
+ function agentRequestSubjectFromProto(
1089
+ request: {
1090
+ context?: { subject?: ProtoSubjectContext | undefined } | undefined;
1091
+ subject?: ProtoSubjectContext | undefined;
1092
+ },
1093
+ ): Subject | undefined {
1094
+ return agentSubjectFromProto(request.context?.subject ?? request.subject);
1095
+ }
1096
+
1082
1097
  function agentSubjectFromProto(
1083
1098
  subject?: ProtoSubjectContext | undefined,
1084
1099
  ): Subject | undefined {
@@ -1089,9 +1104,21 @@ function agentSubjectFromProto(
1089
1104
  id: subject.id,
1090
1105
  credentialSubjectId: subject.credentialSubjectId,
1091
1106
  email: subject.email,
1107
+ displayName: subject.displayName,
1108
+ scopes: [...subject.scopes],
1109
+ permissions: agentSubjectPermissionsFromProto(subject.permissions),
1092
1110
  };
1093
1111
  }
1094
1112
 
1113
+ function agentSubjectPermissionsFromProto(
1114
+ permissions: readonly ProtoSubjectPermissionContext[],
1115
+ ): SubjectPermission[] {
1116
+ return permissions.map((permission) => ({
1117
+ app: permission.app,
1118
+ operations: permission.allOperations ? [] : [...permission.operations],
1119
+ }));
1120
+ }
1121
+
1095
1122
  function optionalTimestamp(value?: Date | undefined) {
1096
1123
  return value === undefined ? undefined : timestampFromDate(value);
1097
1124
  }
@@ -1106,7 +1133,7 @@ function executeToolRequestToProto(
1106
1133
  toolId: request.toolId,
1107
1134
  arguments: optionalStruct(request.arguments),
1108
1135
  idempotencyKey: request.idempotencyKey ?? "",
1109
- runGrant: request.runGrant ?? "",
1136
+ context: request.context,
1110
1137
  });
1111
1138
  }
1112
1139
 
@@ -1125,8 +1152,8 @@ function listToolsRequestToProto(request: ListAgentToolsRequest): ProtoListAgent
1125
1152
  turnId: request.turnId,
1126
1153
  pageSize: request.pageSize ?? 0,
1127
1154
  pageToken: request.pageToken ?? "",
1128
- runGrant: request.runGrant ?? "",
1129
1155
  query: request.query ?? "",
1156
+ context: request.context,
1130
1157
  });
1131
1158
  }
1132
1159
 
@@ -1167,7 +1194,7 @@ function resolveConnectionRequestToProto(
1167
1194
  turnId: request.turnId,
1168
1195
  connection: request.connection,
1169
1196
  instance: request.instance ?? "",
1170
- runGrant: request.runGrant ?? "",
1197
+ context: request.context,
1171
1198
  });
1172
1199
  }
1173
1200
 
@@ -1237,8 +1264,8 @@ class AgentHostImpl implements AgentHost {
1237
1264
  toolCallId: input.toolCallId,
1238
1265
  toolId: input.toolId,
1239
1266
  arguments: input.arguments,
1240
- runGrant: input.runGrant ?? "",
1241
1267
  idempotencyKey: input.idempotencyKey ?? "",
1268
+ context: input.context,
1242
1269
  },
1243
1270
  );
1244
1271
  }
@@ -1260,10 +1287,10 @@ class AgentHostImpl implements AgentHost {
1260
1287
  {
1261
1288
  sessionId: input.sessionId,
1262
1289
  turnId: input.turnId,
1263
- runGrant: input.runGrant ?? "",
1264
1290
  pageSize: input.pageSize ?? 0,
1265
1291
  pageToken: input.pageToken ?? "",
1266
1292
  query: input.query ?? "",
1293
+ context: input.context,
1267
1294
  },
1268
1295
  );
1269
1296
  }
@@ -1287,7 +1314,7 @@ class AgentHostImpl implements AgentHost {
1287
1314
  turnId: input.turnId,
1288
1315
  connection: input.connection,
1289
1316
  instance: input.instance ?? "",
1290
- runGrant: input.runGrant ?? "",
1317
+ context: input.context,
1291
1318
  },
1292
1319
  );
1293
1320
  }