@anthusai/papyrus 5.136.0 → 5.137.0-next.1

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.
@@ -1432,12 +1432,20 @@ const schema = a.schema({
1432
1432
  newsroomFeedKey: a.string(),
1433
1433
  usage: a.json(),
1434
1434
  costUsd: a.float(),
1435
+ /** `attention`, only while the run needs a person (it failed, or its outcome is unknown) and nobody has acknowledged it; absent otherwise, so the attention index is sparse (PPY-577310). A shared stack puts the tenant in front. */
1436
+ attentionKey: a.string(),
1437
+ /** When the run needed attention (its finish time). The sort key of the attention index; absent with `attentionKey`. */
1438
+ dueAt: a.datetime(),
1439
+ /** Who acknowledged the run and when. Acknowledging clears `attentionKey` and `dueAt`; the run stays as history. */
1440
+ acknowledgedAt: a.datetime(),
1441
+ acknowledgedBy: a.string(),
1435
1442
  })
1436
1443
  .secondaryIndexes((index) => [
1437
1444
  index("procedureId").sortKeys(["requestedAt"]).queryField("listProcedureRunsByProcedureAndRequestedAt"),
1438
1445
  index("assignmentId").sortKeys(["requestedAt"]).queryField("listProcedureRunsByAssignmentAndRequestedAt"),
1439
1446
  index("runStatus").sortKeys(["requestedAt"]).queryField("listProcedureRunsByStatusAndRequestedAt"),
1440
1447
  index("newsroomFeedKey").sortKeys(["requestedAt"]).queryField("listProcedureRunsByFeedAndRequestedAt"),
1448
+ index("attentionKey").sortKeys(["dueAt"]).queryField("listProcedureRunsByAttentionKeyAndDueAt"),
1441
1449
  ])
1442
1450
  .authorization((allow) => [
1443
1451
  allow.group("editor").to(["read"]),
@@ -1557,12 +1557,20 @@ const schema = a.schema({
1557
1557
  newsroomFeedKey: a.string(),
1558
1558
  usage: a.json(),
1559
1559
  costUsd: a.float(),
1560
+ /** `attention`, only while the run needs a person (it failed, or its outcome is unknown) and nobody has acknowledged it; absent otherwise, so the attention index is sparse (PPY-577310). A shared stack puts the tenant in front. */
1561
+ attentionKey: a.string(),
1562
+ /** When the run needed attention (its finish time). The sort key of the attention index; absent with `attentionKey`. */
1563
+ dueAt: a.datetime(),
1564
+ /** Who acknowledged the run and when. Acknowledging clears `attentionKey` and `dueAt`; the run stays as history. */
1565
+ acknowledgedAt: a.datetime(),
1566
+ acknowledgedBy: a.string(),
1560
1567
  })
1561
1568
  .secondaryIndexes((index) => [
1562
1569
  index("procedureId").sortKeys(["requestedAt"]).queryField("listProcedureRunsByProcedureAndRequestedAt"),
1563
1570
  index("assignmentId").sortKeys(["requestedAt"]).queryField("listProcedureRunsByAssignmentAndRequestedAt"),
1564
1571
  index("runStatus").sortKeys(["requestedAt"]).queryField("listProcedureRunsByStatusAndRequestedAt"),
1565
1572
  index("newsroomFeedKey").sortKeys(["requestedAt"]).queryField("listProcedureRunsByFeedAndRequestedAt"),
1573
+ index("attentionKey").sortKeys(["dueAt"]).queryField("listProcedureRunsByAttentionKeyAndDueAt"),
1566
1574
  ])
1567
1575
  .authorization((allow) => [
1568
1576
  allow.group("editor").to(["read"]),
@@ -1405,12 +1405,20 @@ function buildBaseDefinitions(excludedGroups = []) {
1405
1405
  newsroomFeedKey: a.string(),
1406
1406
  usage: a.json(),
1407
1407
  costUsd: a.float(),
1408
+ /** `attention`, only while the run needs a person (it failed, or its outcome is unknown) and nobody has acknowledged it; absent otherwise, so the attention index is sparse (PPY-577310). A shared stack puts the tenant in front. */
1409
+ attentionKey: a.string(),
1410
+ /** When the run needed attention (its finish time). The sort key of the attention index; absent with `attentionKey`. */
1411
+ dueAt: a.datetime(),
1412
+ /** Who acknowledged the run and when. Acknowledging clears `attentionKey` and `dueAt`; the run stays as history. */
1413
+ acknowledgedAt: a.datetime(),
1414
+ acknowledgedBy: a.string(),
1408
1415
  })
1409
1416
  .secondaryIndexes((index) => [
1410
1417
  index("procedureId").sortKeys(["requestedAt"]).queryField("listProcedureRunsByProcedureAndRequestedAt"),
1411
1418
  index("assignmentId").sortKeys(["requestedAt"]).queryField("listProcedureRunsByAssignmentAndRequestedAt"),
1412
1419
  index("runStatus").sortKeys(["requestedAt"]).queryField("listProcedureRunsByStatusAndRequestedAt"),
1413
1420
  index("newsroomFeedKey").sortKeys(["requestedAt"]).queryField("listProcedureRunsByFeedAndRequestedAt"),
1421
+ index("attentionKey").sortKeys(["dueAt"]).queryField("listProcedureRunsByAttentionKeyAndDueAt"),
1414
1422
  ])
1415
1423
  .authorization((allow) => [
1416
1424
  allow.group("editor").to(["read"]),
@@ -1533,12 +1533,20 @@ const definitions = {
1533
1533
  newsroomFeedKey: a.string(),
1534
1534
  usage: a.json(),
1535
1535
  costUsd: a.float(),
1536
+ /** `attention`, only while the run needs a person (it failed, or its outcome is unknown) and nobody has acknowledged it; absent otherwise, so the attention index is sparse (PPY-577310). A shared stack puts the tenant in front. */
1537
+ attentionKey: a.string(),
1538
+ /** When the run needed attention (its finish time). The sort key of the attention index; absent with `attentionKey`. */
1539
+ dueAt: a.datetime(),
1540
+ /** Who acknowledged the run and when. Acknowledging clears `attentionKey` and `dueAt`; the run stays as history. */
1541
+ acknowledgedAt: a.datetime(),
1542
+ acknowledgedBy: a.string(),
1536
1543
  })
1537
1544
  .secondaryIndexes((index) => [
1538
1545
  index("procedureId").sortKeys(["requestedAt"]).queryField("listProcedureRunsByProcedureAndRequestedAt"),
1539
1546
  index("assignmentId").sortKeys(["requestedAt"]).queryField("listProcedureRunsByAssignmentAndRequestedAt"),
1540
1547
  index("runStatus").sortKeys(["requestedAt"]).queryField("listProcedureRunsByStatusAndRequestedAt"),
1541
1548
  index("newsroomFeedKey").sortKeys(["requestedAt"]).queryField("listProcedureRunsByFeedAndRequestedAt"),
1549
+ index("attentionKey").sortKeys(["dueAt"]).queryField("listProcedureRunsByAttentionKeyAndDueAt"),
1542
1550
  ])
1543
1551
  .authorization((allow) => [
1544
1552
  allow.group("editor").to(["read"]),
@@ -49,17 +49,17 @@ async function listProcedureDefinitions(getClient: () => Promise<DataClient>) {
49
49
  const client = await getClient();
50
50
  const definitions = await listProcedureDefinitionsPage(client);
51
51
  const versions = await listProcedureVersionsPage(client);
52
- const runs = await listProcedureRunsPage(client);
53
52
  const versionsByProcedureId = groupBy(versions, (entry) => normalizeOptionalString(entry.procedureId) ?? "");
54
- const runsByProcedureId = groupBy(runs, (entry) => normalizeOptionalString(entry.procedureId) ?? "");
53
+ // Each definition's ten latest runs are one indexed query; no read lists the whole run table.
54
+ const recentRunsByProcedureId = new Map<string, any[]>(
55
+ await Promise.all(definitions.map(async (definition): Promise<[string, any[]]> => [definition.id, await listRecentProcedureRuns(client, definition.id)])),
56
+ );
55
57
  return {
56
58
  items: definitions.map((definition) => {
57
59
  const currentVersion = normalizeOptionalString(definition.currentVersionId)
58
60
  ? versions.find((entry) => entry.id === definition.currentVersionId) ?? null
59
61
  : null;
60
- const recentRuns = (runsByProcedureId.get(definition.id) ?? [])
61
- .sort((left, right) => String(right.requestedAt ?? "").localeCompare(String(left.requestedAt ?? "")))
62
- .slice(0, 10);
62
+ const recentRuns = recentRunsByProcedureId.get(definition.id) ?? [];
63
63
  return {
64
64
  ...definition,
65
65
  currentVersion,
@@ -417,10 +417,6 @@ async function listProcedureVersionsPage(client: DataClient): Promise<any[]> {
417
417
  return await listModelPages((client.models.ProcedureVersion as any));
418
418
  }
419
419
 
420
- async function listProcedureRunsPage(client: DataClient): Promise<any[]> {
421
- return await listModelPages((client.models.ProcedureRun as any));
422
- }
423
-
424
420
  async function listProcedureVersionsByProcedure(client: DataClient, procedureId: string): Promise<any[]> {
425
421
  const model = client.models.ProcedureVersion as any;
426
422
  if (typeof model.listProcedureVersionsByProcedureAndVersion === "function") {
@@ -431,12 +427,17 @@ async function listProcedureVersionsByProcedure(client: DataClient, procedureId:
431
427
  }
432
428
 
433
429
  async function listProcedureRunsByProcedureId(client: DataClient, procedureId: string): Promise<any[]> {
434
- const model = client.models.ProcedureRun as any;
435
- if (typeof model.listProcedureRunsByProcedureAndRequestedAt === "function") {
436
- return await listByIndexPages(model.listProcedureRunsByProcedureAndRequestedAt, { procedureId });
437
- }
438
- const all = await listProcedureRunsPage(client);
439
- return all.filter((entry) => normalizeOptionalString(entry.procedureId) === procedureId);
430
+ return await listByIndexPages((client.models.ProcedureRun as any).listProcedureRunsByProcedureAndRequestedAt, { procedureId });
431
+ }
432
+
433
+ /** The ten latest runs of one procedure, newest first: one key-condition query on the procedure index. */
434
+ async function listRecentProcedureRuns(client: DataClient, procedureId: string): Promise<any[]> {
435
+ const response: DataClientResult<any[]> = await (client.models.ProcedureRun as any).listProcedureRunsByProcedureAndRequestedAt(
436
+ { procedureId },
437
+ { authMode: LAMBDA_DATA_AUTH_MODE, limit: 10, sortDirection: "DESC" },
438
+ );
439
+ assertNoDataErrors(response.errors, "list recent ProcedureRuns");
440
+ return response.data ?? [];
440
441
  }
441
442
 
442
443
  async function listModelPages(model: any): Promise<any[]> {
package/package.json CHANGED
@@ -650,7 +650,7 @@
650
650
  "optional": true
651
651
  }
652
652
  },
653
- "version": "5.136.0",
653
+ "version": "5.137.0-next.1",
654
654
  "dependencies": {
655
655
  "@aws-amplify/adapter-nextjs": "^1.7.3",
656
656
  "@aws-crypto/sha256-js": "5.2.0",
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.136.0",
2
+ "version": "5.137.0-next.1",
3
3
  "routes": [
4
4
  {
5
5
  "file": "app/%5F_preview/[[...path]]/route.ts",