@opengeni/api-router 6.5.2-canary.41607687019001 → 6.7.0

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/dist/app.js CHANGED
@@ -29,7 +29,7 @@ import {
29
29
  withDefaultEnabledCapabilityMcpTools,
30
30
  workflowIdForSession,
31
31
  workspaceActorContextExempt
32
- } from "./chunk-VTWD6SYW.js";
32
+ } from "./chunk-WXI5VFFM.js";
33
33
  import "./chunk-OGQDXVXY.js";
34
34
  export {
35
35
  API_MAX_REQUEST_BODY_BYTES,
@@ -22,6 +22,7 @@ import {
22
22
  isDatabaseConnectionLoss,
23
23
  SessionUsageLimitUnavailableError,
24
24
  nestedPostgresSqlState,
25
+ SessionApprovalForbiddenError,
25
26
  WorkspaceControlBusyError,
26
27
  WorkspaceContentFlowRefusedError
27
28
  } from "@opengeni/db";
@@ -57,6 +58,19 @@ function missingPermissionHttpError(error) {
57
58
  details: error.details
58
59
  });
59
60
  }
61
+ function approvalForbiddenHttpError(error) {
62
+ if (!(error instanceof SessionApprovalForbiddenError)) return null;
63
+ return new ApiHttpError(403, {
64
+ code: "forbidden",
65
+ message: error.message,
66
+ retryable: false,
67
+ outcomeUnknown: false,
68
+ details: {
69
+ code: error.code,
70
+ ...error.owner.label ? { accountOwnerLabel: error.owner.label } : {}
71
+ }
72
+ });
73
+ }
60
74
  function scheduledTaskTargetAccessHttpError(error) {
61
75
  if (!(error instanceof HTTPException) || error.status !== 409) return null;
62
76
  const result2 = ScheduledTaskTargetAccessChange.safeParse(error.cause);
@@ -24686,7 +24700,7 @@ async function disconnectPersonalGitHub(deps, input) {
24686
24700
  }
24687
24701
  if (error instanceof ConnectionDisconnectGenerationError) {
24688
24702
  throw new HTTPException29(409, {
24689
- message: "personal GitHub connection changed; refresh before disconnecting"
24703
+ message: "Your GitHub connection changed while disconnecting. Try again."
24690
24704
  });
24691
24705
  }
24692
24706
  throw error;
@@ -34774,6 +34788,7 @@ import {
34774
34788
  acceptSessionHumanInputResponse,
34775
34789
  acceptSessionApprovalDecision,
34776
34790
  SessionApprovalAnswerError,
34791
+ SessionApprovalForbiddenError as SessionApprovalForbiddenError2,
34777
34792
  approveSlackUserLinkAccessRequest,
34778
34793
  advanceSlackInteractionDelivery,
34779
34794
  bindSlackInteractionSession,
@@ -34790,6 +34805,7 @@ import {
34790
34805
  enqueueSlackAppHomeRefresh,
34791
34806
  enqueueSlackInteractionInbox as enqueueSlackInteractionInbox2,
34792
34807
  getConnectionMetadata as getConnectionMetadata7,
34808
+ getToolActionAccountOwner,
34793
34809
  getToolActionReview,
34794
34810
  getOrCreateSlackInteraction,
34795
34811
  getLatestSessionModelForSubject,
@@ -41977,6 +41993,12 @@ async function executeSlackAction(deps, grant, interaction, handle) {
41977
41993
  clientEventId: `slack-action:${handle.id}`
41978
41994
  });
41979
41995
  } catch (error) {
41996
+ if (error instanceof SessionApprovalForbiddenError2) {
41997
+ return {
41998
+ result: "forbidden",
41999
+ text: `${mention}${error.message} ${openSessionText(deps, interaction.workspaceId, handle.sessionId)}`
42000
+ };
42001
+ }
41980
42002
  if (!(error instanceof SessionApprovalAnswerError)) throw error;
41981
42003
  return {
41982
42004
  result: "needs_answer",
@@ -42406,13 +42428,29 @@ async function slackApprovalCard(deps, interaction, event, mention, requesterAut
42406
42428
  const reviewById = new Map(
42407
42429
  reviews.flatMap((review) => review ? [[review.id, review]] : [])
42408
42430
  );
42431
+ const owners = await Promise.all(
42432
+ approvals.map(
42433
+ (approval) => getToolActionAccountOwner(deps.db, {
42434
+ accountId: interaction.accountId,
42435
+ workspaceId: interaction.workspaceId,
42436
+ sessionId: interaction.sessionId,
42437
+ approvalId: approval.id
42438
+ })
42439
+ )
42440
+ );
42441
+ const otherOwnerById = new Map(
42442
+ approvals.flatMap((approval, index) => {
42443
+ const owner2 = owners[index];
42444
+ return owner2 && owner2.subjectId !== interaction.owningSubjectId ? [[approval.id, owner2]] : [];
42445
+ })
42446
+ );
42409
42447
  const actionable = approvals.filter((approval) => {
42410
42448
  if (approval.question) return true;
42411
42449
  const review = reviewById.get(approval.id);
42412
42450
  return review && slackToolReviewCanDecide(review);
42413
42451
  });
42414
42452
  const specs = actionable.flatMap((approval) => [
42415
- ...approval.question && !slackServerQuestion(approval.question).answerableInSlack ? [] : [
42453
+ ...approval.question && !slackServerQuestion(approval.question).answerableInSlack || otherOwnerById.has(approval.id) ? [] : [
42416
42454
  {
42417
42455
  actionKind: "approval_approve",
42418
42456
  actionKey: approval.question ? `approval:${approval.id}:approve:${approval.question.round}` : `approval:${approval.id}:approve`,
@@ -42446,6 +42484,8 @@ async function slackApprovalCard(deps, interaction, event, mention, requesterAut
42446
42484
  }
42447
42485
  const question = slackServerQuestion(approval.question);
42448
42486
  blocks.push(question.block);
42487
+ const questionOwner = otherOwnerById.get(approval.id);
42488
+ if (questionOwner) blocks.push(slackAccountOwnerNote(questionOwner.label));
42449
42489
  if (!question.answerableInSlack && link) {
42450
42490
  blocks.push({
42451
42491
  type: "section",
@@ -42481,6 +42521,23 @@ async function slackApprovalCard(deps, interaction, event, mention, requesterAut
42481
42521
  }
42482
42522
  if (!review) continue;
42483
42523
  blocks.push(...slackToolReviewBlocks(review, privateAudience));
42524
+ const owner2 = otherOwnerById.get(approval.id);
42525
+ if (owner2 && reject) {
42526
+ blocks.push(slackAccountOwnerNote(owner2.label));
42527
+ blocks.push({
42528
+ type: "actions",
42529
+ block_id: `opengeni_approval_${event.sequence}_${blocks.length}`,
42530
+ elements: [
42531
+ {
42532
+ type: "button",
42533
+ action_id: SLACK_ACTION_ID_BY_KIND.approval_reject,
42534
+ value: reject.id,
42535
+ text: { type: "plain_text", text: "Decline", emoji: true }
42536
+ }
42537
+ ]
42538
+ });
42539
+ continue;
42540
+ }
42484
42541
  if (approve && reject) {
42485
42542
  blocks.push({
42486
42543
  type: "actions",
@@ -42515,6 +42572,16 @@ async function slackApprovalCard(deps, interaction, event, mention, requesterAut
42515
42572
  operationId
42516
42573
  };
42517
42574
  }
42575
+ function slackAccountOwnerNote(label) {
42576
+ const who = label ? escapeSlackMrkdwn(label) : "the person whose own account this runs on";
42577
+ return {
42578
+ type: "section",
42579
+ text: {
42580
+ type: "mrkdwn",
42581
+ text: `Only ${who} can approve this, because it runs on their own account. You can decline it.`
42582
+ }
42583
+ };
42584
+ }
42518
42585
  async function slackSharedResultPublicationBlocks(deps, interaction, event, requesterAuthorized, messageOperationId) {
42519
42586
  if (!safePayloadText(event.payload, "output").trim()) return [];
42520
42587
  if (!requesterAuthorized || !interaction.sessionId || !interaction.initiatingSlackUserId) {
@@ -79242,7 +79309,7 @@ var PolicyMcpServer = class extends McpServer3 {
79242
79309
  if (!memory) return dispatch();
79243
79310
  return withSecretValueMasking(memory, async () => {
79244
79311
  try {
79245
- return memory.mask(await dispatch(), "first_party_result");
79312
+ return memory.maskData(await dispatch(), "first_party_result");
79246
79313
  } catch (error) {
79247
79314
  throw maskSecretValuesInError(error, memory);
79248
79315
  }
@@ -83638,7 +83705,7 @@ function registerWorkspaceOrchestrationTools(server, deps, grant, can, callerSes
83638
83705
  )
83639
83706
  );
83640
83707
  if (callerSessionId !== null) {
83641
- const commandReadNotes = "Output larger than maxOutputBytes (default 16384) returns its start and its end, with the size of the omitted middle and a cursor to read it; a read with a cursor pages on from there (pass waitSeconds 0 to page without waiting), and the end cursor continues after the newest output. Output remains readable after the process exits. A terminal read observes completion and suppresses only its still-pending inbox notification; running reads and already claimed history are unchanged. These execution-wait limits do not cap wait_for_input: use it for long out-of-turn waits, except pending Codemode calls require observation in the same live attempt. Neither tool sends stdin or cancels the command.";
83708
+ const commandReadNotes = "Output larger than maxOutputBytes (default 16384) returns its start and its end, with the size of the omitted middle and a cursor to read it; a read with a cursor pages on from there (pass waitSeconds 0 to page without waiting), and the end cursor continues after the newest output. Output remains readable after the process exits. A terminal read observes completion and suppresses only its still-pending inbox notification; running reads and already claimed history are unchanged. A finished command's result, with its exit status and output, also reaches the session on its own, so there is no need to read only to learn that it finished. These execution-wait limits do not cap wait_for_input: use it for long out-of-turn waits, except pending Codemode calls require observation in the same live attempt. Neither tool sends stdin or cancels the command.";
83642
83709
  for (const toolName of ["command_read", "command_wait"]) {
83643
83710
  const multi = toolName === "command_wait";
83644
83711
  server.registerTool(
@@ -98735,7 +98802,7 @@ function registerSessionRoutes(app, deps) {
98735
98802
  sessionId: c.req.param("sessionId"),
98736
98803
  approvalId: c.req.param("approvalId")
98737
98804
  };
98738
- const review = await getToolActionReview2(db, input);
98805
+ const review = await getToolActionReview2(db, { ...input, viewerSubjectId: grant.subjectId });
98739
98806
  if (!review) throw new HTTPException68(404, { message: "Review not found" });
98740
98807
  c.header("Cache-Control", "private, no-store");
98741
98808
  return c.json(review);
@@ -101534,6 +101601,8 @@ function registerSessionRoutes(app, deps) {
101534
101601
  if (error instanceof SessionApprovalAnswerError2) {
101535
101602
  throw new HTTPException68(422, { message: error.message });
101536
101603
  }
101604
+ const forbidden = approvalForbiddenHttpError(error);
101605
+ if (forbidden) throw forbidden;
101537
101606
  throw error;
101538
101607
  }
101539
101608
  if (accepted.action === "conflict") {
@@ -130512,6 +130581,17 @@ async function personalGitHubProviderFetch(deps, connection, subjectId, url, exp
130512
130581
  forceRefresh
130513
130582
  });
130514
130583
  if (credential.status !== "ok") {
130584
+ if (credential.reason === "refresh_failed") {
130585
+ const current2 = await getConnectionMetadata15(
130586
+ deps.db,
130587
+ connection.workspaceId,
130588
+ connection.id,
130589
+ subjectId
130590
+ );
130591
+ if (current2?.status === "active") {
130592
+ throw new PersonalGitHubRepositoryProviderError("provider_unavailable");
130593
+ }
130594
+ }
130515
130595
  throw new PersonalGitHubRepositoryProviderError("connection_inactive");
130516
130596
  }
130517
130597
  if (credential.connectionId !== connection.id || credential.connectionVersion === void 0) {
@@ -130909,8 +130989,10 @@ function personalGitHubRepositoryRouteError(error) {
130909
130989
  import {
130910
130990
  PERSONAL_GITHUB_API_ORIGIN as PERSONAL_GITHUB_API_ORIGIN2,
130911
130991
  PERSONAL_GITHUB_PROVIDER_DOMAIN as PERSONAL_GITHUB_PROVIDER_DOMAIN4,
130992
+ PERSONAL_GITHUB_RECONNECT_MESSAGE,
130912
130993
  PersonalGitHubConnectionMetadata as PersonalGitHubConnectionMetadata3,
130913
- isPersonalGitHubConnection as isPersonalGitHubConnection5
130994
+ isPersonalGitHubConnection as isPersonalGitHubConnection5,
130995
+ personalGitHubConnectionNeedsReconnect
130914
130996
  } from "@opengeni/contracts/personal-github";
130915
130997
  import {
130916
130998
  resourcesIncludeRepository
@@ -131101,8 +131183,27 @@ var BrokerRepositoryRemovedError = class extends Error {
131101
131183
  super("personal GitHub repository was removed from the session");
131102
131184
  }
131103
131185
  };
131186
+ var BrokerReconnectRequiredError = class extends Error {
131187
+ constructor() {
131188
+ super("personal GitHub connection must be reconnected");
131189
+ }
131190
+ };
131191
+ var BrokerProviderUnavailableError = class extends Error {
131192
+ constructor() {
131193
+ super("personal GitHub token refresh is temporarily unavailable");
131194
+ }
131195
+ };
131104
131196
  function brokerAuthorityError(error) {
131105
- return error instanceof BrokerRepositoryRemovedError ? brokerError(403, "This repository was removed from this chat.") : brokerError(401, "Git broker authorization is no longer current.");
131197
+ if (error instanceof BrokerRepositoryRemovedError) {
131198
+ return brokerError(403, "This repository was removed from this chat.");
131199
+ }
131200
+ if (error instanceof BrokerReconnectRequiredError) {
131201
+ return brokerError(403, PERSONAL_GITHUB_RECONNECT_MESSAGE);
131202
+ }
131203
+ if (error instanceof BrokerProviderUnavailableError) {
131204
+ return brokerError(502, "GitHub is temporarily unavailable. Try again.");
131205
+ }
131206
+ return brokerError(401, "Git broker authorization is no longer current.");
131106
131207
  }
131107
131208
  async function resolveBrokerAuthority(deps, secret, claims, routeId) {
131108
131209
  const turn = await getSessionTurnForAttempt(
@@ -131160,6 +131261,10 @@ async function authorizeBrokerProviderRequest(deps, authority, destinationUrl, o
131160
131261
  }
131161
131262
  });
131162
131263
  if (credential.status !== "ok" || credential.connectionId !== claims.connectionId || credential.connectionUseAttribution?.connectionGeneration !== claims.connectionAuthorityGeneration || credential.connectionUseAttribution.ownerSubjectId !== claims.ownerSubjectId || credential.connectionUseAttribution.workspaceId !== claims.workspaceId) {
131264
+ await assertCurrentConnectionAndSelection(deps, claims, repository);
131265
+ if (credential.status !== "ok" && credential.reason === "refresh_failed") {
131266
+ throw new BrokerProviderUnavailableError();
131267
+ }
131163
131268
  throw new Error("personal GitHub credential resolution was denied");
131164
131269
  }
131165
131270
  await assertCurrentConnectionAndSelection(deps, claims, repository);
@@ -131223,6 +131328,9 @@ async function assertCurrentConnectionAndSelection(deps, claims, repository) {
131223
131328
  claims.connectionId,
131224
131329
  claims.ownerSubjectId
131225
131330
  );
131331
+ if (connection && connection.accountId === claims.accountId && connection.workspaceId === claims.originWorkspaceId && connection.subjectId === claims.ownerSubjectId && personalGitHubConnectionNeedsReconnect(connection) && PersonalGitHubConnectionMetadata3.safeParse(connection.metadata).data?.credentialBindingId === claims.credentialBindingId) {
131332
+ throw new BrokerReconnectRequiredError();
131333
+ }
131226
131334
  if (!connection || connection.accountId !== claims.accountId || connection.workspaceId !== claims.originWorkspaceId || connection.subjectId !== claims.ownerSubjectId || connection.status !== "active" || connection.grantedScopes.length !== 1 || connection.grantedScopes[0] !== "repo" || !isPersonalGitHubConnection5(connection)) {
131227
131335
  throw new Error("personal GitHub connection changed");
131228
131336
  }
@@ -132317,6 +132425,8 @@ function interactionResourceRouteError(error) {
132317
132425
  if (error instanceof InteractionResourceNotFoundError2 || error instanceof BrowserSessionNotFoundError2 || error instanceof ComputerSessionNotFoundError2) {
132318
132426
  return new HTTPException112(404, { message: error.message, cause: error });
132319
132427
  }
132428
+ const forbidden = approvalForbiddenHttpError(error);
132429
+ if (forbidden) return forbidden;
132320
132430
  if (error instanceof InteractionResourceConflictError2 || error instanceof InteractionResourceStateError3) {
132321
132431
  return new HTTPException112(409, { message: error.message, cause: error });
132322
132432
  }
@@ -157235,4 +157345,4 @@ export {
157235
157345
  withDefaultEnabledCapabilityMcpTools,
157236
157346
  workflowIdForSession4 as workflowIdForSession
157237
157347
  };
157238
- //# sourceMappingURL=chunk-VTWD6SYW.js.map
157348
+ //# sourceMappingURL=chunk-WXI5VFFM.js.map