@cat-factory/server 0.324.0 → 0.325.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 (39) hide show
  1. package/dist/modules/publicApi/PublicApiController.d.ts.map +1 -1
  2. package/dist/modules/publicApi/PublicApiController.js +5 -292
  3. package/dist/modules/publicApi/PublicApiController.js.map +1 -1
  4. package/dist/modules/publicApi/PublicDecisionController.d.ts.map +1 -1
  5. package/dist/modules/publicApi/PublicDecisionController.js +2 -0
  6. package/dist/modules/publicApi/PublicDecisionController.js.map +1 -1
  7. package/dist/modules/publicApi/decisions/bugFishingProjection.d.ts +19 -0
  8. package/dist/modules/publicApi/decisions/bugFishingProjection.d.ts.map +1 -0
  9. package/dist/modules/publicApi/decisions/bugFishingProjection.js +130 -0
  10. package/dist/modules/publicApi/decisions/bugFishingProjection.js.map +1 -0
  11. package/dist/modules/publicApi/decisions/bugFishingRoutes.d.ts +4 -0
  12. package/dist/modules/publicApi/decisions/bugFishingRoutes.d.ts.map +1 -0
  13. package/dist/modules/publicApi/decisions/bugFishingRoutes.js +73 -0
  14. package/dist/modules/publicApi/decisions/bugFishingRoutes.js.map +1 -0
  15. package/dist/modules/publicApi/decisions/projection.d.ts +21 -0
  16. package/dist/modules/publicApi/decisions/projection.d.ts.map +1 -1
  17. package/dist/modules/publicApi/decisions/projection.js +65 -11
  18. package/dist/modules/publicApi/decisions/projection.js.map +1 -1
  19. package/dist/modules/publicApi/openapiDocument.generated.d.ts +1 -1
  20. package/dist/modules/publicApi/openapiDocument.generated.d.ts.map +1 -1
  21. package/dist/modules/publicApi/openapiDocument.generated.js +1 -1
  22. package/dist/modules/publicApi/openapiDocument.generated.js.map +1 -1
  23. package/dist/modules/publicApi/publicApiAdmission.d.ts +1 -1
  24. package/dist/modules/publicApi/publicApiAdmission.d.ts.map +1 -1
  25. package/dist/modules/publicApi/publicApiAdmission.js +5 -1
  26. package/dist/modules/publicApi/publicApiAdmission.js.map +1 -1
  27. package/dist/modules/publicApi/publicApiStream.d.ts +50 -1
  28. package/dist/modules/publicApi/publicApiStream.d.ts.map +1 -1
  29. package/dist/modules/publicApi/publicApiStream.js +83 -5
  30. package/dist/modules/publicApi/publicApiStream.js.map +1 -1
  31. package/dist/modules/publicApi/publicApiStreamRoutes.d.ts +30 -0
  32. package/dist/modules/publicApi/publicApiStreamRoutes.d.ts.map +1 -0
  33. package/dist/modules/publicApi/publicApiStreamRoutes.js +275 -0
  34. package/dist/modules/publicApi/publicApiStreamRoutes.js.map +1 -0
  35. package/dist/modules/publicApi/runProjection.d.ts +30 -0
  36. package/dist/modules/publicApi/runProjection.d.ts.map +1 -0
  37. package/dist/modules/publicApi/runProjection.js +127 -0
  38. package/dist/modules/publicApi/runProjection.js.map +1 -0
  39. package/package.json +8 -8
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runProjection.d.ts","sourceRoot":"","sources":["../../../src/modules/publicApi/runProjection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAC5F,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAe/C;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,SAAS,EAAE,iBAAiB,EAC5B,cAAc,EAAE,MAAM,GAAG,IAAI,GAC5B,SAAS,CAwCX;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,SAAS,EAAE,iBAAiB,EAC5B,KAAK,EAAE,KAAK,EACZ,cAAc,EAAE,MAAM,GAAG,IAAI,GAC5B,SAAS,CA4CX;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,CAAC,SAAS,MAAM,EAClD,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EACb,WAAW,EAAE,MAAM,EACnB,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAMnC"}
@@ -0,0 +1,127 @@
1
+ import { jobSortKey, mapStatus } from './publicApiPaging.js';
2
+ import { viewRunIdentity } from './runIdentityVisibility.js';
3
+ // The two RUN projections the public surface serves, plus the scoped load behind the job half.
4
+ //
5
+ // Extracted from `PublicApiController` because they have three consumers rather than one: the
6
+ // point reads in that controller, the two SSE loops in `publicApiStreamRoutes.ts`, and (through
7
+ // the stream) the decision channel. Keeping them there would have made the stream file import the
8
+ // controller that registers it.
9
+ //
10
+ // Both are PURE functions of the run plus the reading key's identity, which is what lets an SSE
11
+ // loop render frame after frame without a second read: see `runIdentityVisibility.ts` for why the
12
+ // reader is a parameter rather than something looked up in here.
13
+ /**
14
+ * Project a persisted execution onto the external job resource (no block/board internals).
15
+ *
16
+ * Takes the READING key's own identity because the run's pinned one is not visible to every key
17
+ * (`runIdentityVisibility.ts` holds the rule and why there is one). Passed as a parameter rather
18
+ * than read off the context here, so the projection stays a pure function of the run plus the
19
+ * caller and the SSE loops can render frame after frame without re-reading anything.
20
+ */
21
+ export function toPublicJob(execution, readerIdentity) {
22
+ const status = mapStatus(execution.status);
23
+ const identity = viewRunIdentity(execution.initiatedByExternalIdentity, readerIdentity);
24
+ // The deliverable is the LAST step that actually produced output, normally the terminal step,
25
+ // but scanning from the end keeps the result meaningful for a multi-step public pipeline whose
26
+ // final step is a side-effect-only tail that emits nothing (the built-in initiative pipeline is
27
+ // single-step, so this simply picks that step). Fall back to the terminal step so a `succeeded`
28
+ // run always carries a (possibly empty) result rather than null.
29
+ const withOutput = [...execution.steps]
30
+ .reverse()
31
+ .find((s) => (s.output ?? '') !== '' || s.custom != null);
32
+ const deliverable = withOutput ?? execution.steps[execution.steps.length - 1];
33
+ const result = status === 'succeeded' && deliverable
34
+ ? { output: deliverable.output ?? '', data: deliverable.custom ?? null }
35
+ : null;
36
+ const error = status === 'failed'
37
+ ? execution.failure
38
+ ? { code: execution.failure.kind, message: execution.failure.message }
39
+ : { code: 'run_failed', message: 'The run failed' }
40
+ : null;
41
+ return {
42
+ jobId: execution.id,
43
+ status,
44
+ pipelineId: execution.pipelineId,
45
+ // Pinned at admission from the starting key, so it survives that key's revocation and costs
46
+ // this projection no lookup (`toPublicJob` also renders every row of a paged list). Withheld
47
+ // from a key that acts for someone else, which the flag STATES rather than blanking to a
48
+ // `null` that already means "this run names nobody". Named field by field rather than spread,
49
+ // for the reason `keyProjection.ts` gives: a spread is exempt from excess-property checking,
50
+ // so a member added to the view type later would reach the wire with nothing to stop it.
51
+ externalIdentity: identity.externalIdentity,
52
+ externalIdentityWithheld: identity.externalIdentityWithheld,
53
+ // The run's own creation stamp: the SAME value the list's keyset cursor is minted from
54
+ // (`jobSortKey`), so a caller can page and correlate on one consistent number.
55
+ createdAt: jobSortKey(execution),
56
+ result,
57
+ error,
58
+ };
59
+ }
60
+ /**
61
+ * Project a task's persisted run + its block onto the RICH external run resource: per-step
62
+ * state/progress/subtasks, the failure kind+message, and the PR (url + branch). The run's
63
+ * `status` is the raw execution status (`running`/`blocked`/`paused`/`done`/`failed`): the
64
+ * public run view deliberately surfaces the parked states (unlike the coarse `publicJob`), so
65
+ * a caller can tell an awaiting-a-human `blocked` from a still-`running` step. The PR branch
66
+ * lives on the BLOCK (`block.pullRequest`), not the run, so both are joined here.
67
+ */
68
+ export function toPublicRun(execution, block, readerIdentity) {
69
+ const pr = block.pullRequest;
70
+ const identity = viewRunIdentity(execution.initiatedByExternalIdentity, readerIdentity);
71
+ return {
72
+ runId: execution.id,
73
+ taskId: block.id,
74
+ status: execution.status,
75
+ createdAt: jobSortKey(execution),
76
+ currentStep: execution.currentStep,
77
+ steps: execution.steps.map((s) => ({
78
+ agentKind: s.agentKind,
79
+ state: s.state,
80
+ progress: s.progress,
81
+ subtasks: s.subtasks
82
+ ? {
83
+ completed: s.subtasks.completed,
84
+ inProgress: s.subtasks.inProgress,
85
+ total: s.subtasks.total,
86
+ }
87
+ : null,
88
+ // The step's deliverable. An EMPTY output is projected as null, matching the way
89
+ // `toPublicJob` reads "produced something": a step that ran and wrote nothing and a step
90
+ // that has not run yet are the same fact to a caller reading for a result, and the step's
91
+ // own `state` is what distinguishes them.
92
+ output: (s.output ?? '') === '' ? null : (s.output ?? null),
93
+ data: s.custom ?? null,
94
+ // Only when true: a step that RAN carries no flag at all, so the field never has to be read
95
+ // as "false, and also this run is old enough to predate the projection".
96
+ ...(s.skipped ? { skipped: true } : {}),
97
+ })),
98
+ // Who the run was started for, as pinned at admission; null for a run the app, a schedule or
99
+ // an identity-less key started, and withheld (flagged, not blanked) from a key that acts for
100
+ // someone else. See `runIdentityVisibility.ts`, and `toPublicJob` for why both members are
101
+ // named rather than spread.
102
+ externalIdentity: identity.externalIdentity,
103
+ externalIdentityWithheld: identity.externalIdentityWithheld,
104
+ pullRequest: pr ? { url: pr.url, branch: pr.branch ?? null } : null,
105
+ error: execution.status === 'failed'
106
+ ? execution.failure
107
+ ? { code: execution.failure.kind, message: execution.failure.message }
108
+ : { code: 'run_failed', message: 'The run failed' }
109
+ : null,
110
+ };
111
+ }
112
+ /**
113
+ * Load a public JOB by id for an authenticated key: the persisted execution, but ONLY when it is
114
+ * anchored on a HEADLESS internal block (a run this public surface created). Returns null when no
115
+ * such run exists in the key's workspace OR the id points at a normal board execution, so an
116
+ * external key can never read an arbitrary in-workspace run's output, only its own headless jobs.
117
+ * Runtime-symmetric: one `executionRepository.get` + one `boardService.getInternalTask` point-read.
118
+ */
119
+ export async function loadPublicJob(c, workspaceId, id) {
120
+ const container = c.get('container');
121
+ const execution = await container.executionRepository.get(workspaceId, id);
122
+ if (!execution)
123
+ return null;
124
+ const anchor = await container.boardService.getInternalTask(workspaceId, execution.blockId);
125
+ return anchor ? execution : null;
126
+ }
127
+ //# sourceMappingURL=runProjection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runProjection.js","sourceRoot":"","sources":["../../../src/modules/publicApi/runProjection.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,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;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,CAAa,EACb,WAAmB,EACnB,EAAU;IAEV,MAAM,SAAS,GAAG,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;IACpC,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,mBAAmB,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;IAC1E,IAAI,CAAC,SAAS;QAAE,OAAO,IAAI,CAAA;IAC3B,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,eAAe,CAAC,WAAW,EAAE,SAAS,CAAC,OAAO,CAAC,CAAA;IAC3F,OAAO,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAA;AAClC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cat-factory/server",
3
- "version": "0.324.0",
3
+ "version": "0.325.0",
4
4
  "description": "Runtime-neutral HTTP layer for the Agent Architecture Board: the Hono controllers, middleware (auth/authz/CORS/error), request helpers and the gateway seams shared by every deployment facade (Cloudflare Worker, Node service).",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,13 +24,13 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "@cat-factory/agents": "0.166.0",
28
- "@cat-factory/contracts": "0.354.0",
29
- "@cat-factory/integrations": "0.173.2",
30
- "@cat-factory/kernel": "0.346.2",
31
- "@cat-factory/mcp-server": "0.51.0",
32
- "@cat-factory/orchestration": "0.312.0",
33
- "@cat-factory/spend": "0.21.8",
27
+ "@cat-factory/agents": "0.166.1",
28
+ "@cat-factory/contracts": "0.355.0",
29
+ "@cat-factory/integrations": "0.174.0",
30
+ "@cat-factory/kernel": "0.347.0",
31
+ "@cat-factory/mcp-server": "0.52.0",
32
+ "@cat-factory/orchestration": "0.313.0",
33
+ "@cat-factory/spend": "0.21.9",
34
34
  "@toad-contracts/core": "0.4.0",
35
35
  "@toad-contracts/hono": "0.3.2",
36
36
  "@toad-contracts/valibot": "0.5.0",