@axiom-lattice/gateway 8.1.0 → 8.2.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 (30) hide show
  1. package/dist/embed/{embed-page-AgentDetailSideApp-RY4FAEAM.js → embed-page-AgentDetailSideApp-WDDE7BEH.js} +1 -1
  2. package/dist/embed/{embed-page-AgentGovernanceWorkbench-UFDULZ5A.js → embed-page-AgentGovernanceWorkbench-7YPU3QB2.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-S7GCLNLR.js → embed-page-MessageGraph-LNNMCH6I.js} +1 -1
  5. package/dist/embed/{embed-page-ReactChart-LWZPH244.js → embed-page-ReactChart-D7RZQB2H.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-KD4S22SL.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-Z7MY6U5T.js} +1 -1
  10. package/dist/embed/{embed-page-WorkflowAutomationView-JV26AHRB.js → embed-page-WorkflowAutomationView-4MY4HG7R.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-ABGWNVMG.js → embed-page-chunk-BZKAPY7M.js} +1 -1
  15. package/dist/embed/embed-page-chunk-CFFDP526.js +6835 -0
  16. package/dist/embed/{embed-page-chunk-5XP4FJW7.js → embed-page-chunk-EM6VGUZ2.js} +1 -1
  17. package/dist/embed/{embed-page-chunk-3UK7XM33.js → embed-page-chunk-G5MXFDNZ.js} +1 -1
  18. package/dist/embed/{embed-page-chunk-OQUMCCF5.js → embed-page-chunk-G5PDHDBZ.js} +1 -1
  19. package/dist/embed/{embed-page-chunk-YM76GTXK.js → embed-page-chunk-HZZ5HNTF.js} +1 -1
  20. package/dist/embed/{embed-page-chunk-ONXC5S22.js → embed-page-chunk-PMOGSY6W.js} +1 -1
  21. package/dist/embed/{embed-page-en-G5J7KW6V.js → embed-page-en-JOTELYAL.js} +1 -1
  22. package/dist/embed/{embed-page-zh-72QSTYRF.js → embed-page-zh-BPO6ZSJM.js} +1 -1
  23. package/dist/embed/embed-page.js +1 -1
  24. package/dist/index.js +198 -40
  25. package/dist/index.js.map +1 -1
  26. package/dist/index.mjs +198 -40
  27. package/dist/index.mjs.map +1 -1
  28. package/package.json +4 -4
  29. package/dist/embed/embed-page-chunk-NNQHJZ5Q.js +0 -211
  30. package/dist/embed/embed-page-chunk-SQSVDSG6.js +0 -6746
package/dist/index.mjs CHANGED
@@ -2782,6 +2782,52 @@ import {
2782
2782
 
2783
2783
  // src/services/threads/threadOwnership.ts
2784
2784
  import { getStoreLattice as getStoreLattice5 } from "@axiom-lattice/core";
2785
+ var DELEGATED_THREAD_SEPARATOR = "____";
2786
+ var MAX_DELEGATED_THREAD_LINEAGE = 8;
2787
+ async function threadHasTenantRecord(tenantId, threadId) {
2788
+ try {
2789
+ const thread = await getStoreLattice5("default", "thread").store.getThreadById(
2790
+ tenantId,
2791
+ threadId
2792
+ );
2793
+ if (thread) return true;
2794
+ } catch {
2795
+ }
2796
+ try {
2797
+ const ledger = getStoreLattice5("default", "agentRun").store;
2798
+ const runs = await ledger.listRuns(tenantId, threadId, { limit: 1 });
2799
+ if (runs.length > 0) return true;
2800
+ } catch {
2801
+ }
2802
+ try {
2803
+ const tasks = getStoreLattice5("default", "task").store;
2804
+ const matches = await tasks.list({ tenantId, threadId, limit: 1 });
2805
+ return matches.length > 0;
2806
+ } catch {
2807
+ return false;
2808
+ }
2809
+ }
2810
+ async function threadLineageRootedInTenant(tenantId, threadId) {
2811
+ let candidate = threadId;
2812
+ for (let depth = 0; depth < MAX_DELEGATED_THREAD_LINEAGE; depth += 1) {
2813
+ if (await threadHasTenantRecord(tenantId, candidate)) return true;
2814
+ const boundary = candidate.lastIndexOf(DELEGATED_THREAD_SEPARATOR);
2815
+ if (boundary <= 0) return false;
2816
+ candidate = candidate.slice(0, boundary);
2817
+ }
2818
+ return false;
2819
+ }
2820
+ async function delegatedThreadOwnedBy(tenantId, assistantId, threadId) {
2821
+ const marker = `${DELEGATED_THREAD_SEPARATOR}${assistantId}_`;
2822
+ let boundary = threadId.indexOf(marker);
2823
+ while (boundary > 0) {
2824
+ if (await threadLineageRootedInTenant(tenantId, threadId.slice(0, boundary))) {
2825
+ return true;
2826
+ }
2827
+ boundary = threadId.indexOf(marker, boundary + DELEGATED_THREAD_SEPARATOR.length);
2828
+ }
2829
+ return false;
2830
+ }
2785
2831
  async function threadOwnedBy(tenantId, assistantId, threadId) {
2786
2832
  try {
2787
2833
  const thread = await getStoreLattice5("default", "thread").store.getThreadById(
@@ -2800,10 +2846,12 @@ async function threadOwnedBy(tenantId, assistantId, threadId) {
2800
2846
  try {
2801
2847
  const tasks = getStoreLattice5("default", "task").store;
2802
2848
  const matches = await tasks.list({ tenantId, threadId, limit: 1 });
2803
- return matches.some((task) => task.ownerType === "agent" && task.ownerId === assistantId);
2849
+ if (matches.some((task) => task.ownerType === "agent" && task.ownerId === assistantId)) {
2850
+ return true;
2851
+ }
2804
2852
  } catch {
2805
- return false;
2806
2853
  }
2854
+ return delegatedThreadOwnedBy(tenantId, assistantId, threadId);
2807
2855
  }
2808
2856
  async function threadIsNewForTenant(tenantId, threadId) {
2809
2857
  try {
@@ -3064,6 +3112,29 @@ async function listAllRuns(ledger, tenantId, threadId) {
3064
3112
  if (page.length < ACTIVE_RUN_PAGE_SIZE) return runs;
3065
3113
  }
3066
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
+ }
3067
3138
  function toSafeRun(run2) {
3068
3139
  return {
3069
3140
  runId: run2.runId,
@@ -3075,7 +3146,9 @@ function toSafeRun(run2) {
3075
3146
  createdAt: run2.createdAt,
3076
3147
  updatedAt: run2.updatedAt,
3077
3148
  startedAt: run2.startedAt,
3078
- finishedAt: run2.finishedAt
3149
+ finishedAt: run2.finishedAt,
3150
+ messageId: run2.inputMessageIds[0] ?? null,
3151
+ inputPreview: inputPreview(run2.input)
3079
3152
  };
3080
3153
  }
3081
3154
  function isTerminal(run2) {
@@ -3205,6 +3278,35 @@ function createRunLifecycleHandlers(deps = {}) {
3205
3278
  const pollIntervalMs = deps.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
3206
3279
  const now = deps.now ?? Date.now;
3207
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
+ };
3208
3310
  const waitForTerminal = async (tenantId, params, initial) => {
3209
3311
  let current3 = initial;
3210
3312
  const deadline = now() + waitTimeoutMs;
@@ -3434,35 +3536,6 @@ function createRunLifecycleHandlers(deps = {}) {
3434
3536
  const outcome = await createPending();
3435
3537
  return outcome.ok ? respondCreated(outcome.run) : outcome.response;
3436
3538
  };
3437
- const withRunCreateLock = async (operation) => {
3438
- const key = runCreateScopeKey(tenantId, assistantId, threadId);
3439
- return serializeRunCreate(key, async () => {
3440
- const leaseStore = resolveLeaseStore();
3441
- if (!leaseStore) return operation();
3442
- try {
3443
- return await withLease(
3444
- leaseStore,
3445
- key,
3446
- getReplicaId2(),
3447
- operation,
3448
- RUN_CREATE_LEASE
3449
- );
3450
- } catch (error) {
3451
- if (error instanceof LeaseAcquisitionTimeoutError) {
3452
- request.log.warn(
3453
- { err: error, leaseKey: key },
3454
- "Run create lease acquisition timed out"
3455
- );
3456
- return unavailable(
3457
- reply,
3458
- RUN_CREATE_LOCK_TIMEOUT,
3459
- "Could not serialize run creation for this thread; retry shortly"
3460
- );
3461
- }
3462
- throw error;
3463
- }
3464
- });
3465
- };
3466
3539
  const scopedRunApiRuns = (runs) => runs.filter(
3467
3540
  (run2) => run2.tenantId === tenantId && run2.threadId === threadId && run2.assistantId === assistantId && run2.source === "run_api"
3468
3541
  );
@@ -3482,7 +3555,7 @@ function createRunLifecycleHandlers(deps = {}) {
3482
3555
  }
3483
3556
  };
3484
3557
  if (strategy === "reject") {
3485
- return withRunCreateLock(async () => {
3558
+ return withRunCreateLock(request, reply, tenantId, assistantId, threadId, async () => {
3486
3559
  const read = await readThreadRuns();
3487
3560
  if (!read.ok) return read.response;
3488
3561
  const active2 = scopedRunApiRuns(read.runs).filter(isActiveRun);
@@ -3498,7 +3571,7 @@ function createRunLifecycleHandlers(deps = {}) {
3498
3571
  });
3499
3572
  }
3500
3573
  if (strategy === "interrupt") {
3501
- return withRunCreateLock(async () => {
3574
+ return withRunCreateLock(request, reply, tenantId, assistantId, threadId, async () => {
3502
3575
  const read = await readThreadRuns();
3503
3576
  if (!read.ok) return read.response;
3504
3577
  const scoped = scopedRunApiRuns(read.runs);
@@ -3561,8 +3634,8 @@ function createRunLifecycleHandlers(deps = {}) {
3561
3634
  return createAndRespond();
3562
3635
  });
3563
3636
  }
3564
- if (strategy !== "rollback") return withRunCreateLock(createAndRespond);
3565
- return withRunCreateLock(async () => {
3637
+ if (strategy !== "rollback") return withRunCreateLock(request, reply, tenantId, assistantId, threadId, createAndRespond);
3638
+ return withRunCreateLock(request, reply, tenantId, assistantId, threadId, async () => {
3566
3639
  const active2 = (await listAllRuns(ledger, tenantId, threadId)).filter(
3567
3640
  (run2) => run2.tenantId === tenantId && run2.threadId === threadId && run2.assistantId === assistantId && run2.source !== "legacy" && (run2.status === "pending" || run2.status === "running")
3568
3641
  );
@@ -3697,6 +3770,76 @@ function createRunLifecycleHandlers(deps = {}) {
3697
3770
  return createAndRespond();
3698
3771
  });
3699
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
+ };
3700
3843
  const list = async (request, reply) => {
3701
3844
  if (!ledger) {
3702
3845
  return unavailable(reply, RUN_LEDGER_UNAVAILABLE, "Run ledger is not available");
@@ -3706,12 +3849,14 @@ function createRunLifecycleHandlers(deps = {}) {
3706
3849
  if (!await ownsThread(tenantId, assistantId, threadId)) {
3707
3850
  return notFound2(reply, THREAD_NOT_FOUND2, "Thread not found");
3708
3851
  }
3709
- const runs = (await ledger.listRuns(tenantId, threadId)).filter(
3710
- (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)
3711
3856
  );
3712
3857
  return reply.status(200).send({
3713
3858
  success: true,
3714
- data: { runs: runs.map(toSafeRun) }
3859
+ data: { runs: scoped.map(toSafeRun) }
3715
3860
  });
3716
3861
  };
3717
3862
  const get = async (request, reply) => {
@@ -4067,7 +4212,7 @@ function createRunLifecycleHandlers(deps = {}) {
4067
4212
  run: toSafeRun(outcome.run)
4068
4213
  });
4069
4214
  };
4070
- return { create, list, get, join: join4, cancel };
4215
+ return { create, list, get, join: join4, cancel, cancelActive };
4071
4216
  }
4072
4217
  function registerRunLifecycleRoutes(app2, deps = {}) {
4073
4218
  const handlers = createRunLifecycleHandlers(deps);
@@ -4079,6 +4224,10 @@ function registerRunLifecycleRoutes(app2, deps = {}) {
4079
4224
  "/api/assistants/:assistantId/threads/:threadId/runs",
4080
4225
  handlers.list
4081
4226
  );
4227
+ app2.post(
4228
+ "/api/assistants/:assistantId/threads/:threadId/runs/cancel-active",
4229
+ handlers.cancelActive
4230
+ );
4082
4231
  app2.get(
4083
4232
  "/api/assistants/:assistantId/threads/:threadId/runs/:runId",
4084
4233
  handlers.get
@@ -20975,6 +21124,15 @@ function registerAgentWebAppRuntimeRoutes(app2, deps) {
20975
21124
  return normalizeError2(reply, error);
20976
21125
  }
20977
21126
  });
21127
+ routes.post(`${prefix}/assistants/:assistantId/threads/:threadId/runs/cancel-active`, async (request, reply) => {
21128
+ try {
21129
+ const params = mirrorThreadParams.parse(request.params);
21130
+ const { proxy } = await authorizeRunMirror(request, params);
21131
+ return await runLifecycle.cancelActive(proxy, reply);
21132
+ } catch (error) {
21133
+ return normalizeError2(reply, error);
21134
+ }
21135
+ });
20978
21136
  routes.post(`${prefix}/assistants/:assistantId/threads/:threadId/runs/:runId/cancel`, async (request, reply) => {
20979
21137
  try {
20980
21138
  const params = mirrorRunParams.parse(request.params);