@opengeni/core 0.18.1 → 0.20.2

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.
@@ -68,6 +68,12 @@ export declare function controlAgentSessionWorkstream(deps: {
68
68
  workspaceControlEventId: string;
69
69
  interruptionCount: number;
70
70
  wakeCount: number;
71
+ cancelledSessionCount: number;
72
+ cancelledTurnCount: number;
73
+ affectedSessionEvents: Array<{
74
+ sessionId: string;
75
+ eventIds: string[];
76
+ }>;
71
77
  replay: boolean;
72
78
  authorization: ResolvedSessionAuthorization | null;
73
79
  }>;
@@ -1,5 +1,5 @@
1
1
  import type { Settings } from "@opengeni/config";
2
- import type { ConnectionCredentialsPort, Document, GitHubAppApiPort, ScheduledTask, SessionAuthorizationPort, TurnInitiator } from "@opengeni/contracts";
2
+ import type { ConnectionCredentialsPort, Document, DocumentAuthorityKind, GitHubAppApiPort, ScheduledTask, SessionAuthorizationPort, TurnInitiator } from "@opengeni/contracts";
3
3
  import type { Database } from "@opengeni/db";
4
4
  import type { DocumentServices } from "@opengeni/documents";
5
5
  import type { EventBus } from "@opengeni/events";
@@ -65,6 +65,9 @@ export type DocumentIndexClient = {
65
65
  accountId: string;
66
66
  workspaceId: string;
67
67
  documentId: string;
68
+ authorityKind: DocumentAuthorityKind;
69
+ authorityWorkspaceId: string | null;
70
+ authoritySubjectId: string | null;
68
71
  }) => Promise<Document | void>;
69
72
  };
70
73
  export type AppDependencies = {
@@ -57,6 +57,8 @@ export declare function createAndStartSession(input: {
57
57
  accountId: string;
58
58
  workspaceId: string;
59
59
  initialMessage: string;
60
+ /** Create the session shell without an initial user event/agent turn. */
61
+ deferInitialTurn?: boolean;
60
62
  turnInstructions?: string | null;
61
63
  resources: ResourceRef[];
62
64
  skills?: SessionSkill[];
@@ -83,6 +85,7 @@ export declare function createAndStartSession(input: {
83
85
  rigVersionId?: string | null;
84
86
  goal?: GoalSpec | null;
85
87
  instructions?: string | null;
88
+ policyRole?: string | null;
86
89
  firstPartyMcpPermissions?: Permission[] | null;
87
90
  firstPartyMcpTools: FirstPartyMcpToolName[];
88
91
  mcpServers?: CreateSessionMcpServerInput[];
package/dist/index.js CHANGED
@@ -705,6 +705,7 @@ async function runOnSandbox(services, ctx, target, op) {
705
705
  if (sandbox.kind !== "selfhosted" || !sandbox.enrollmentId) {
706
706
  return {
707
707
  target,
708
+ targetName: sandbox.name,
708
709
  kind: op.kind,
709
710
  ok: false,
710
711
  reason: `run_on routes one-off ops to enrolled selfhosted machines; ${sandbox.kind} targets are reached via the active sandbox (swap to it first)`
@@ -712,9 +713,15 @@ async function runOnSandbox(services, ctx, target, op) {
712
713
  }
713
714
  const enrollment = await getEnrollment(services.db, ctx.workspaceId, sandbox.enrollmentId);
714
715
  if (!enrollment || enrollment.status !== "active") {
715
- return { target, kind: op.kind, ok: false, reason: `sandbox ${target} is not enrolled/active` };
716
+ return {
717
+ target,
718
+ targetName: sandbox.name,
719
+ kind: op.kind,
720
+ ok: false,
721
+ reason: `sandbox ${target} is not enrolled/active`
722
+ };
716
723
  }
717
- return executeRunOnSelfhostedMachine(
724
+ const result = await executeRunOnSelfhostedMachine(
718
725
  {
719
726
  workspaceId: ctx.workspaceId,
720
727
  agentId: sandbox.enrollmentId,
@@ -726,6 +733,7 @@ async function runOnSandbox(services, ctx, target, op) {
726
733
  target,
727
734
  op
728
735
  );
736
+ return { ...result, targetName: sandbox.name };
729
737
  }
730
738
  async function provisionSandbox(services, ctx, input) {
731
739
  if (input.kind === "selfhosted") {
@@ -3327,6 +3335,7 @@ import {
3327
3335
  normalizeRepositorySubpath,
3328
3336
  normalizeResourceMountPath,
3329
3337
  resourceIdentityKey,
3338
+ resourceMountPath,
3330
3339
  resourceMountPathCollisionKey,
3331
3340
  ResourceRefConflictError,
3332
3341
  ResourceMountPathError,
@@ -3388,7 +3397,7 @@ function normalizeResources(resources) {
3388
3397
  for (const resource of resources) {
3389
3398
  let normalized;
3390
3399
  if (resource.kind === "file") {
3391
- const mountPath = normalizeMountPath(resource.mountPath ?? `files/${resource.fileId}`);
3400
+ const mountPath = normalizeMountPath(resourceMountPath(resource));
3392
3401
  normalized = {
3393
3402
  kind: "file",
3394
3403
  fileId: resource.fileId,
@@ -4172,6 +4181,7 @@ async function createAndStartSession(input) {
4172
4181
  firstPartyMcpPermissions: input.firstPartyMcpPermissions ?? null,
4173
4182
  firstPartyMcpTools: input.firstPartyMcpTools,
4174
4183
  instructions: input.instructions ?? null,
4184
+ policyRole: input.policyRole ?? null,
4175
4185
  parentSessionId: input.parentSessionId ?? null,
4176
4186
  createIdempotencyKey: input.createIdempotencyKey,
4177
4187
  sandboxGroupId: input.sandboxGroupId ?? null,
@@ -4218,6 +4228,7 @@ async function createAndStartSession(input) {
4218
4228
  firstPartyMcpPermissions: input.firstPartyMcpPermissions ?? null,
4219
4229
  firstPartyMcpTools: input.firstPartyMcpTools,
4220
4230
  instructions: input.instructions ?? null,
4231
+ policyRole: input.policyRole ?? null,
4221
4232
  parentSessionId: input.parentSessionId ?? null,
4222
4233
  sandboxGroupId: input.sandboxGroupId ?? null,
4223
4234
  ...input.sandboxOs ? { sandboxOs: input.sandboxOs } : {},
@@ -4280,7 +4291,8 @@ async function finishStartSession(input, session) {
4280
4291
  ...input.goal.successCriteria !== void 0 ? { successCriteria: input.goal.successCriteria } : {},
4281
4292
  ...input.goal.maxAutoContinuations !== void 0 ? { maxAutoContinuations: input.goal.maxAutoContinuations } : {}
4282
4293
  } : null,
4283
- consumeNewSessionDraft: input.consumeNewSessionDraft ?? null
4294
+ consumeNewSessionDraft: input.consumeNewSessionDraft ?? null,
4295
+ deferInitialTurn: input.deferInitialTurn === true
4284
4296
  });
4285
4297
  await publishDurableSessionEvents(input.bus, session.workspaceId, session.id, started.events);
4286
4298
  if (started.workflowWakeRevision !== null) {
@@ -4597,7 +4609,7 @@ async function createSessionForRequest(deps, grant, workspaceId, rawPayload) {
4597
4609
  workspaceId,
4598
4610
  payload.variableSetId
4599
4611
  ) : null;
4600
- const requestedRigId = payload.rigId ?? await getWorkspaceDefaultRigId(db, workspaceId);
4612
+ const requestedRigId = payload.rigId === void 0 ? await getWorkspaceDefaultRigId(db, workspaceId) : payload.rigId;
4601
4613
  let frozenRigId = null;
4602
4614
  let frozenRigVersionId = null;
4603
4615
  if (requestedRigId) {
@@ -4765,13 +4777,15 @@ async function createSessionForRequest(deps, grant, workspaceId, rawPayload) {
4765
4777
  }
4766
4778
  }
4767
4779
  }
4768
- await requireLimit(deps, {
4769
- accountId: grant.accountId,
4770
- workspaceId,
4771
- action: "agent_run:create",
4772
- quantity: 1,
4773
- model
4774
- });
4780
+ if (payload.startMode !== "realtime") {
4781
+ await requireLimit(deps, {
4782
+ accountId: grant.accountId,
4783
+ workspaceId,
4784
+ action: "agent_run:create",
4785
+ quantity: 1,
4786
+ model
4787
+ });
4788
+ }
4775
4789
  const creationInitiator = creationInitiatorForGrant(grant);
4776
4790
  let session;
4777
4791
  try {
@@ -4782,7 +4796,8 @@ async function createSessionForRequest(deps, grant, workspaceId, rawPayload) {
4782
4796
  workflowClient,
4783
4797
  accountId: grant.accountId,
4784
4798
  workspaceId,
4785
- initialMessage: payload.initialMessage,
4799
+ initialMessage: payload.initialMessage ?? "",
4800
+ deferInitialTurn: payload.startMode === "realtime",
4786
4801
  turnInstructions: payload.turnInstructions ?? null,
4787
4802
  resources,
4788
4803
  skills,
@@ -4817,6 +4832,7 @@ async function createSessionForRequest(deps, grant, workspaceId, rawPayload) {
4817
4832
  // contracts schema). Persisted on the row; composed system-level at turn
4818
4833
  // time. Not surfaced as an event.
4819
4834
  instructions: payload.instructions ?? null,
4835
+ policyRole: payload.policyRole ?? null,
4820
4836
  firstPartyMcpPermissions,
4821
4837
  firstPartyMcpTools,
4822
4838
  mcpServers: sessionMcpServers.dbServers,
@@ -4848,21 +4864,23 @@ async function createSessionForRequest(deps, grant, workspaceId, rawPayload) {
4848
4864
  }
4849
4865
  throw error;
4850
4866
  }
4851
- await recordWorkspaceUsage(deps, {
4852
- accountId: grant.accountId,
4853
- workspaceId,
4854
- subjectId: grant.subjectId,
4855
- eventType: "agent_run.created",
4856
- quantity: 1,
4857
- unit: "run",
4858
- sourceResourceType: "session",
4859
- sourceResourceId: session.id,
4860
- sessionId: session.id,
4861
- initiator: session.createdBy,
4862
- initiatorContext: session.createdByContext,
4863
- origin: creationInitiator.actor ? "system" : "user",
4864
- idempotencyKey: `agent_run.created:${workspaceId}:${session.id}`
4865
- });
4867
+ if (payload.startMode !== "realtime") {
4868
+ await recordWorkspaceUsage(deps, {
4869
+ accountId: grant.accountId,
4870
+ workspaceId,
4871
+ subjectId: grant.subjectId,
4872
+ eventType: "agent_run.created",
4873
+ quantity: 1,
4874
+ unit: "run",
4875
+ sourceResourceType: "session",
4876
+ sourceResourceId: session.id,
4877
+ sessionId: session.id,
4878
+ initiator: session.createdBy,
4879
+ initiatorContext: session.createdByContext,
4880
+ origin: creationInitiator.actor ? "system" : "user",
4881
+ idempotencyKey: `agent_run.created:${workspaceId}:${session.id}`
4882
+ });
4883
+ }
4866
4884
  return session;
4867
4885
  }
4868
4886
  async function acceptSessionUserMessage(deps, grant, workspaceId, sessionId, input) {
@@ -6843,11 +6861,13 @@ async function controlHumanSessionWorkstream(deps, context, input) {
6843
6861
  authorization?.relatedSessionAccess ?? "root"
6844
6862
  ),
6845
6863
  interruptionCount: result.interruptionCount,
6846
- wakeCount: result.wakeCount
6864
+ wakeCount: result.wakeCount,
6865
+ cancelledSessionCount: result.cancelledSessionCount,
6866
+ cancelledTurnCount: result.cancelledTurnCount
6847
6867
  };
6848
- await publishSessionEventIds(deps, context.workspaceId, context.sessionId, [
6849
- result.sessionControlEventId
6850
- ]);
6868
+ for (const affected of result.affectedSessionEvents) {
6869
+ await publishSessionEventIds(deps, context.workspaceId, affected.sessionId, affected.eventIds);
6870
+ }
6851
6871
  await publishWorkspaceControlEvent(deps, context.workspaceId, result.workspaceControlEventId);
6852
6872
  await requestControlWakeDispatch(deps, result.wakeCount);
6853
6873
  return response;