@axiom-lattice/gateway 8.1.1 → 8.3.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.
Files changed (31) hide show
  1. package/dist/embed/{embed-page-AgentDetailSideApp-RY4FAEAM.js → embed-page-AgentDetailSideApp-7YTMN643.js} +1 -1
  2. package/dist/embed/{embed-page-AgentGovernanceWorkbench-UFDULZ5A.js → embed-page-AgentGovernanceWorkbench-YWJ4ZLEV.js} +1 -1
  3. package/dist/embed/{embed-page-LangfuseDashboard-GNNJGAA2.js → embed-page-LangfuseDashboard-BEOJDMWF.js} +1 -1
  4. package/dist/embed/embed-page-MessageGraph-N2DXVMEK.js +6 -0
  5. package/dist/embed/{embed-page-ReactChart-LWZPH244.js → embed-page-ReactChart-3QDZX2WG.js} +1 -1
  6. package/dist/embed/{embed-page-SkillFlow-OVIGJFUH.js → embed-page-SkillFlow-3X24ILKU.js} +1 -1
  7. package/dist/embed/{embed-page-TasksSideApp-AOS4MZAI.js → embed-page-TasksSideApp-MYIRJWFM.js} +1 -1
  8. package/dist/embed/{embed-page-ThreadMaintenancePanel-PXL2TJBO.js → embed-page-ThreadMaintenancePanel-V327PV5R.js} +1 -1
  9. package/dist/embed/{embed-page-TopologyRuntimeView-GRM34Z2Z.js → embed-page-TopologyRuntimeView-3O6VJUZR.js} +1 -1
  10. package/dist/embed/{embed-page-WorkflowAutomationView-JV26AHRB.js → embed-page-WorkflowAutomationView-YHOS4WQR.js} +1 -1
  11. package/dist/embed/embed-page-chunk-4XKCMM5C.js +211 -0
  12. package/dist/embed/{embed-page-chunk-YCTDKWKW.js → embed-page-chunk-ASEIOK7X.js} +1 -1
  13. package/dist/embed/{embed-page-chunk-6ZHR5GWS.js → embed-page-chunk-BSRASK7V.js} +6 -6
  14. package/dist/embed/{embed-page-chunk-GSUSX54K.js → embed-page-chunk-FE6KYRCO.js} +1 -1
  15. package/dist/embed/{embed-page-chunk-SQSVDSG6.js → embed-page-chunk-IBRMWDHE.js} +292 -203
  16. package/dist/embed/{embed-page-chunk-5XP4FJW7.js → embed-page-chunk-IELKCYQX.js} +1 -1
  17. package/dist/embed/{embed-page-chunk-ABGWNVMG.js → embed-page-chunk-JTL73EBV.js} +1 -1
  18. package/dist/embed/{embed-page-chunk-ONXC5S22.js → embed-page-chunk-PMOGSY6W.js} +1 -1
  19. package/dist/embed/{embed-page-chunk-3UK7XM33.js → embed-page-chunk-PROZXFWS.js} +1 -1
  20. package/dist/embed/{embed-page-chunk-YM76GTXK.js → embed-page-chunk-WGEXK773.js} +2 -2
  21. package/dist/embed/{embed-page-chunk-OQUMCCF5.js → embed-page-chunk-YMVKQQXJ.js} +1 -1
  22. package/dist/embed/{embed-page-en-G5J7KW6V.js → embed-page-en-JOTELYAL.js} +1 -1
  23. package/dist/embed/{embed-page-zh-72QSTYRF.js → embed-page-zh-BPO6ZSJM.js} +1 -1
  24. package/dist/embed/embed-page.js +3 -3
  25. package/dist/index.js +206 -53
  26. package/dist/index.js.map +1 -1
  27. package/dist/index.mjs +206 -53
  28. package/dist/index.mjs.map +1 -1
  29. package/package.json +4 -4
  30. package/dist/embed/embed-page-MessageGraph-S7GCLNLR.js +0 -6
  31. package/dist/embed/embed-page-chunk-NNQHJZ5Q.js +0 -211
package/dist/index.mjs CHANGED
@@ -3112,6 +3112,29 @@ async function listAllRuns(ledger, tenantId, threadId) {
3112
3112
  if (page.length < ACTIVE_RUN_PAGE_SIZE) return runs;
3113
3113
  }
3114
3114
  }
3115
+ var INPUT_PREVIEW_MAX = 200;
3116
+ function contentToPreview(content) {
3117
+ if (typeof content === "string") return content;
3118
+ if (!Array.isArray(content)) return "";
3119
+ return content.map((part) => {
3120
+ if (typeof part === "string") return part;
3121
+ return isRecord(part) && typeof part.text === "string" ? part.text : "";
3122
+ }).join("");
3123
+ }
3124
+ function inputPreview(input) {
3125
+ if (!isRecord(input)) return null;
3126
+ if (typeof input.message === "string") {
3127
+ return input.message.trim().slice(0, INPUT_PREVIEW_MAX) || null;
3128
+ }
3129
+ const messages = Array.isArray(input.messages) ? input.messages : [];
3130
+ for (const message of messages) {
3131
+ if (!isRecord(message)) continue;
3132
+ if (message.role !== void 0 && message.role !== "human") continue;
3133
+ const text = contentToPreview(message.content).trim();
3134
+ if (text) return text.slice(0, INPUT_PREVIEW_MAX);
3135
+ }
3136
+ return null;
3137
+ }
3115
3138
  function toSafeRun(run2) {
3116
3139
  return {
3117
3140
  runId: run2.runId,
@@ -3123,7 +3146,9 @@ function toSafeRun(run2) {
3123
3146
  createdAt: run2.createdAt,
3124
3147
  updatedAt: run2.updatedAt,
3125
3148
  startedAt: run2.startedAt,
3126
- finishedAt: run2.finishedAt
3149
+ finishedAt: run2.finishedAt,
3150
+ messageId: run2.inputMessageIds[0] ?? null,
3151
+ inputPreview: inputPreview(run2.input)
3127
3152
  };
3128
3153
  }
3129
3154
  function isTerminal(run2) {
@@ -3253,6 +3278,35 @@ function createRunLifecycleHandlers(deps = {}) {
3253
3278
  const pollIntervalMs = deps.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
3254
3279
  const now = deps.now ?? Date.now;
3255
3280
  const sleep = deps.sleep ?? ((ms) => new Promise((resolve3) => setTimeout(resolve3, ms)));
3281
+ const withRunCreateLock = async (request, reply, tenantId, assistantId, threadId, operation) => {
3282
+ const key = runCreateScopeKey(tenantId, assistantId, threadId);
3283
+ return serializeRunCreate(key, async () => {
3284
+ const leaseStore = resolveLeaseStore();
3285
+ if (!leaseStore) return operation();
3286
+ try {
3287
+ return await withLease(
3288
+ leaseStore,
3289
+ key,
3290
+ getReplicaId2(),
3291
+ operation,
3292
+ RUN_CREATE_LEASE
3293
+ );
3294
+ } catch (error) {
3295
+ if (error instanceof LeaseAcquisitionTimeoutError) {
3296
+ request.log.warn(
3297
+ { err: error, leaseKey: key },
3298
+ "Run create lease acquisition timed out"
3299
+ );
3300
+ return unavailable(
3301
+ reply,
3302
+ RUN_CREATE_LOCK_TIMEOUT,
3303
+ "Could not serialize run creation for this thread; retry shortly"
3304
+ );
3305
+ }
3306
+ throw error;
3307
+ }
3308
+ });
3309
+ };
3256
3310
  const waitForTerminal = async (tenantId, params, initial) => {
3257
3311
  let current3 = initial;
3258
3312
  const deadline = now() + waitTimeoutMs;
@@ -3482,35 +3536,6 @@ function createRunLifecycleHandlers(deps = {}) {
3482
3536
  const outcome = await createPending();
3483
3537
  return outcome.ok ? respondCreated(outcome.run) : outcome.response;
3484
3538
  };
3485
- const withRunCreateLock = async (operation) => {
3486
- const key = runCreateScopeKey(tenantId, assistantId, threadId);
3487
- return serializeRunCreate(key, async () => {
3488
- const leaseStore = resolveLeaseStore();
3489
- if (!leaseStore) return operation();
3490
- try {
3491
- return await withLease(
3492
- leaseStore,
3493
- key,
3494
- getReplicaId2(),
3495
- operation,
3496
- RUN_CREATE_LEASE
3497
- );
3498
- } catch (error) {
3499
- if (error instanceof LeaseAcquisitionTimeoutError) {
3500
- request.log.warn(
3501
- { err: error, leaseKey: key },
3502
- "Run create lease acquisition timed out"
3503
- );
3504
- return unavailable(
3505
- reply,
3506
- RUN_CREATE_LOCK_TIMEOUT,
3507
- "Could not serialize run creation for this thread; retry shortly"
3508
- );
3509
- }
3510
- throw error;
3511
- }
3512
- });
3513
- };
3514
3539
  const scopedRunApiRuns = (runs) => runs.filter(
3515
3540
  (run2) => run2.tenantId === tenantId && run2.threadId === threadId && run2.assistantId === assistantId && run2.source === "run_api"
3516
3541
  );
@@ -3530,7 +3555,7 @@ function createRunLifecycleHandlers(deps = {}) {
3530
3555
  }
3531
3556
  };
3532
3557
  if (strategy === "reject") {
3533
- return withRunCreateLock(async () => {
3558
+ return withRunCreateLock(request, reply, tenantId, assistantId, threadId, async () => {
3534
3559
  const read = await readThreadRuns();
3535
3560
  if (!read.ok) return read.response;
3536
3561
  const active2 = scopedRunApiRuns(read.runs).filter(isActiveRun);
@@ -3546,7 +3571,7 @@ function createRunLifecycleHandlers(deps = {}) {
3546
3571
  });
3547
3572
  }
3548
3573
  if (strategy === "interrupt") {
3549
- return withRunCreateLock(async () => {
3574
+ return withRunCreateLock(request, reply, tenantId, assistantId, threadId, async () => {
3550
3575
  const read = await readThreadRuns();
3551
3576
  if (!read.ok) return read.response;
3552
3577
  const scoped = scopedRunApiRuns(read.runs);
@@ -3609,8 +3634,8 @@ function createRunLifecycleHandlers(deps = {}) {
3609
3634
  return createAndRespond();
3610
3635
  });
3611
3636
  }
3612
- if (strategy !== "rollback") return withRunCreateLock(createAndRespond);
3613
- return withRunCreateLock(async () => {
3637
+ if (strategy !== "rollback") return withRunCreateLock(request, reply, tenantId, assistantId, threadId, createAndRespond);
3638
+ return withRunCreateLock(request, reply, tenantId, assistantId, threadId, async () => {
3614
3639
  const active2 = (await listAllRuns(ledger, tenantId, threadId)).filter(
3615
3640
  (run2) => run2.tenantId === tenantId && run2.threadId === threadId && run2.assistantId === assistantId && run2.source !== "legacy" && (run2.status === "pending" || run2.status === "running")
3616
3641
  );
@@ -3745,6 +3770,76 @@ function createRunLifecycleHandlers(deps = {}) {
3745
3770
  return createAndRespond();
3746
3771
  });
3747
3772
  };
3773
+ const cancelActive = async (request, reply) => {
3774
+ if (!ledger) {
3775
+ return unavailable(reply, RUN_LEDGER_UNAVAILABLE, "Run ledger is not available");
3776
+ }
3777
+ const tenantId = getTenantId4(request);
3778
+ const { assistantId, threadId } = request.params;
3779
+ if (!await ownsThread(tenantId, assistantId, threadId)) {
3780
+ return notFound2(reply, THREAD_NOT_FOUND2, "Thread not found");
3781
+ }
3782
+ const router = resolveRouter();
3783
+ return withRunCreateLock(request, reply, tenantId, assistantId, threadId, async () => {
3784
+ let runs;
3785
+ try {
3786
+ runs = await listAllRuns(ledger, tenantId, threadId);
3787
+ } catch (error) {
3788
+ request.log.error({ err: error }, "Active run read failed");
3789
+ return unavailable(reply, RUN_CREATE_UNAVAILABLE2, "Run queue is not available");
3790
+ }
3791
+ const active2 = runs.filter(
3792
+ (run2) => run2.tenantId === tenantId && run2.assistantId === assistantId && run2.threadId === threadId && run2.source === "run_api" && isActiveRun(run2)
3793
+ );
3794
+ const cancelled = [];
3795
+ const requested = [];
3796
+ const failed = [];
3797
+ for (const run2 of active2) {
3798
+ try {
3799
+ if (run2.status === "pending") {
3800
+ const status2 = await ledger.requestCancel(tenantId, run2.runId);
3801
+ if (status2 === "cancelled") {
3802
+ const latest = await ledger.getRun(tenantId, run2.runId);
3803
+ if (latest) cancelled.push(toSafeRun(latest));
3804
+ } else if (status2 === "requested") {
3805
+ requested.push(toSafeRun(run2));
3806
+ }
3807
+ continue;
3808
+ }
3809
+ if (router) {
3810
+ const status2 = await router.requestCancelById({
3811
+ tenantId,
3812
+ assistantId,
3813
+ threadId,
3814
+ runId: run2.runId,
3815
+ reason: "abort"
3816
+ });
3817
+ if (status2 === "requested" || status2 === "cancelled") {
3818
+ requested.push(toSafeRun(run2));
3819
+ }
3820
+ continue;
3821
+ }
3822
+ const status = await ledger.requestCancel(tenantId, run2.runId);
3823
+ if (status === "requested" || status === "cancelled") {
3824
+ requested.push(toSafeRun(run2));
3825
+ }
3826
+ } catch (error) {
3827
+ failed.push({
3828
+ runId: run2.runId,
3829
+ code: "RUN_CANCEL_FAILED",
3830
+ message: error instanceof Error ? error.message : String(error)
3831
+ });
3832
+ }
3833
+ }
3834
+ return reply.status(200).send({
3835
+ success: true,
3836
+ accepted: failed.length === 0,
3837
+ cancelled,
3838
+ requested,
3839
+ failed
3840
+ });
3841
+ });
3842
+ };
3748
3843
  const list = async (request, reply) => {
3749
3844
  if (!ledger) {
3750
3845
  return unavailable(reply, RUN_LEDGER_UNAVAILABLE, "Run ledger is not available");
@@ -3754,12 +3849,14 @@ function createRunLifecycleHandlers(deps = {}) {
3754
3849
  if (!await ownsThread(tenantId, assistantId, threadId)) {
3755
3850
  return notFound2(reply, THREAD_NOT_FOUND2, "Thread not found");
3756
3851
  }
3757
- const runs = (await ledger.listRuns(tenantId, threadId)).filter(
3758
- (run2) => run2.tenantId === tenantId && run2.threadId === threadId && run2.assistantId === assistantId
3852
+ const activeOnly = request.query.active === "true" || request.query.active === "1";
3853
+ const source = request.query.source;
3854
+ const scoped = (activeOnly ? await listAllRuns(ledger, tenantId, threadId) : await ledger.listRuns(tenantId, threadId)).filter(
3855
+ (run2) => run2.tenantId === tenantId && run2.threadId === threadId && run2.assistantId === assistantId && (!activeOnly || isActiveRun(run2)) && (source === void 0 || run2.source === source)
3759
3856
  );
3760
3857
  return reply.status(200).send({
3761
3858
  success: true,
3762
- data: { runs: runs.map(toSafeRun) }
3859
+ data: { runs: scoped.map(toSafeRun) }
3763
3860
  });
3764
3861
  };
3765
3862
  const get = async (request, reply) => {
@@ -4115,7 +4212,7 @@ function createRunLifecycleHandlers(deps = {}) {
4115
4212
  run: toSafeRun(outcome.run)
4116
4213
  });
4117
4214
  };
4118
- return { create, list, get, join: join4, cancel };
4215
+ return { create, list, get, join: join4, cancel, cancelActive };
4119
4216
  }
4120
4217
  function registerRunLifecycleRoutes(app2, deps = {}) {
4121
4218
  const handlers = createRunLifecycleHandlers(deps);
@@ -4127,6 +4224,10 @@ function registerRunLifecycleRoutes(app2, deps = {}) {
4127
4224
  "/api/assistants/:assistantId/threads/:threadId/runs",
4128
4225
  handlers.list
4129
4226
  );
4227
+ app2.post(
4228
+ "/api/assistants/:assistantId/threads/:threadId/runs/cancel-active",
4229
+ handlers.cancelActive
4230
+ );
4130
4231
  app2.get(
4131
4232
  "/api/assistants/:assistantId/threads/:threadId/runs/:runId",
4132
4233
  handlers.get
@@ -11917,15 +12018,25 @@ var ProjectAccessService = class {
11917
12018
  input.projectId,
11918
12019
  input.userId
11919
12020
  );
11920
- if (membership?.status === "active") {
12021
+ if (project.kind === "personal") {
12022
+ if (!this.isActiveMembership(membership, input)) this.accessDenied();
11921
12023
  this.requireCapability(membership, input.capability);
11922
12024
  return { project, membership };
11923
12025
  }
12026
+ if (this.isActiveMembership(membership, input) && this.hasCapability(membership, input.capability)) {
12027
+ return { project, membership };
12028
+ }
12029
+ const tenantAdmin = await this.tenantAdminMembership(project, input);
12030
+ if (this.isActiveMembership(membership, input)) {
12031
+ if (tenantAdmin) return { project, membership: tenantAdmin };
12032
+ this.requireCapability(membership, input.capability);
12033
+ }
11924
12034
  const memberships = await this.deps.membershipStore.list(input.tenantId, input.projectId);
11925
- if (memberships.length !== 0) this.accessDenied();
11926
- if (project.kind === "personal") this.accessDenied();
11927
- const tenantLink = await this.deps.userTenantLinkStore.getLink(input.userId, input.tenantId);
11928
- if (tenantLink?.role !== "owner" && tenantLink?.role !== "admin") this.accessDenied();
12035
+ if (memberships.length !== 0) {
12036
+ if (tenantAdmin) return { project, membership: tenantAdmin };
12037
+ this.accessDenied();
12038
+ }
12039
+ if (!tenantAdmin) this.accessDenied();
11929
12040
  let claim;
11930
12041
  try {
11931
12042
  claim = await this.deps.membershipStore.createInitialOwner({
@@ -11968,9 +12079,19 @@ var ProjectAccessService = class {
11968
12079
  input.projectId,
11969
12080
  input.userId
11970
12081
  );
11971
- if (!membership || membership.tenantId !== input.tenantId || membership.projectId !== input.projectId || membership.userId !== input.userId || membership.status !== "active") this.accessDenied();
11972
- this.requireCapability(membership, input.capability);
11973
- return { project, membership };
12082
+ const activeMembership = this.isActiveMembership(membership, input) ? membership : void 0;
12083
+ if (project.kind === "personal") {
12084
+ if (!activeMembership) this.accessDenied();
12085
+ this.requireCapability(activeMembership, input.capability);
12086
+ return { project, membership: activeMembership };
12087
+ }
12088
+ if (activeMembership && this.hasCapability(activeMembership, input.capability)) {
12089
+ return { project, membership: activeMembership };
12090
+ }
12091
+ const tenantAdmin = await this.tenantAdminMembership(project, input);
12092
+ if (tenantAdmin) return { project, membership: tenantAdmin };
12093
+ if (activeMembership) this.requireCapability(activeMembership, input.capability);
12094
+ this.accessDenied();
11974
12095
  }
11975
12096
  /**
11976
12097
  * Authorizes roster visibility for any active participant (owner/admin/member/viewer).
@@ -11992,6 +12113,9 @@ var ProjectAccessService = class {
11992
12113
  input.userId
11993
12114
  );
11994
12115
  if (membership?.status === "active") {
12116
+ if (this.hasCapability(membership, input.capability)) return { project, membership };
12117
+ const tenantAdmin = await this.tenantAdminMembership(project, input);
12118
+ if (tenantAdmin) return { project, membership: tenantAdmin };
11995
12119
  this.requireCapability(membership, input.capability);
11996
12120
  return { project, membership };
11997
12121
  }
@@ -12006,6 +12130,9 @@ var ProjectAccessService = class {
12006
12130
  input.userId
12007
12131
  );
12008
12132
  if (membership?.status === "active") {
12133
+ if (this.hasCapability(membership, input.capability)) return { project, membership };
12134
+ const tenantAdmin = await this.tenantAdminMembership(project, input);
12135
+ if (tenantAdmin) return { project, membership: tenantAdmin };
12009
12136
  this.requireCapability(membership, input.capability);
12010
12137
  return { project, membership };
12011
12138
  }
@@ -12057,8 +12184,29 @@ var ProjectAccessService = class {
12057
12184
  throw error;
12058
12185
  }
12059
12186
  }
12187
+ hasCapability(membership, capability2) {
12188
+ return allowedRoles[capability2].has(membership.role);
12189
+ }
12060
12190
  requireCapability(membership, capability2) {
12061
- if (!allowedRoles[capability2].has(membership.role)) this.accessDenied();
12191
+ if (!this.hasCapability(membership, capability2)) this.accessDenied();
12192
+ }
12193
+ async tenantAdminMembership(project, input) {
12194
+ if (project.kind === "personal") return void 0;
12195
+ const tenantLink = await this.deps.userTenantLinkStore.getLink(input.userId, input.tenantId);
12196
+ if (tenantLink?.role !== "owner" && tenantLink?.role !== "admin") return void 0;
12197
+ return {
12198
+ id: `tenant-admin:${input.userId}`,
12199
+ tenantId: input.tenantId,
12200
+ projectId: project.id,
12201
+ userId: input.userId,
12202
+ role: "admin",
12203
+ status: "active",
12204
+ joinedAt: project.createdAt,
12205
+ updatedAt: project.updatedAt
12206
+ };
12207
+ }
12208
+ isActiveMembership(membership, input) {
12209
+ return membership != null && membership.tenantId === input.tenantId && membership.projectId === input.projectId && membership.userId === input.userId && membership.status === "active";
12062
12210
  }
12063
12211
  accessDenied() {
12064
12212
  throw new ProjectCollaborationError("PROJECT_ACCESS_DENIED", 403, "Project access denied");
@@ -21023,6 +21171,15 @@ function registerAgentWebAppRuntimeRoutes(app2, deps) {
21023
21171
  return normalizeError2(reply, error);
21024
21172
  }
21025
21173
  });
21174
+ routes.post(`${prefix}/assistants/:assistantId/threads/:threadId/runs/cancel-active`, async (request, reply) => {
21175
+ try {
21176
+ const params = mirrorThreadParams.parse(request.params);
21177
+ const { proxy } = await authorizeRunMirror(request, params);
21178
+ return await runLifecycle.cancelActive(proxy, reply);
21179
+ } catch (error) {
21180
+ return normalizeError2(reply, error);
21181
+ }
21182
+ });
21026
21183
  routes.post(`${prefix}/assistants/:assistantId/threads/:threadId/runs/:runId/cancel`, async (request, reply) => {
21027
21184
  try {
21028
21185
  const params = mirrorRunParams.parse(request.params);
@@ -23339,8 +23496,6 @@ var ProjectMembershipService = class {
23339
23496
  }
23340
23497
  async list(actor3) {
23341
23498
  await this.deps.accessService.requireRosterAccess(actor3);
23342
- const membership = await this.deps.membershipStore.findByUser(actor3.tenantId, actor3.projectId, actor3.userId);
23343
- if (!membership || membership.status !== "active") this.accessDenied();
23344
23499
  return this.deps.membershipStore.list(actor3.tenantId, actor3.projectId);
23345
23500
  }
23346
23501
  async add(actor3, input) {
@@ -23398,10 +23553,8 @@ var ProjectMembershipService = class {
23398
23553
  });
23399
23554
  }
23400
23555
  async authorize(actor3) {
23401
- await this.deps.accessService.requireProjectAccess({ ...actor3, capability: "manage" });
23402
- const membership = await this.deps.membershipStore.findByUser(actor3.tenantId, actor3.projectId, actor3.userId);
23403
- if (!membership || membership.status !== "active") this.accessDenied();
23404
- return membership;
23556
+ const access = await this.deps.accessService.requireProjectAccess({ ...actor3, capability: "manage" });
23557
+ return access.membership;
23405
23558
  }
23406
23559
  async target(actor3, id3) {
23407
23560
  const target = (await this.deps.membershipStore.list(actor3.tenantId, actor3.projectId)).find((item) => item.id === id3);