@wildo-ai/saas-minions-lib 1.1.3 → 1.1.4
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/esm/base-classes/services/services/minion-scoped-services-registry-handler.backend.service.d.ts.map +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/inject/models/container.d.ts.map +1 -1
- package/dist/esm/inject/models/service-types.d.ts.map +1 -1
- package/dist/esm/runtime/queue/minion-tick-consumer.backend.service.d.ts.map +1 -1
- package/dist/esm/runtime/services/define-minion-init.d.ts.map +1 -1
- package/dist/esm/runtime/services/define-minion-init.js.map +1 -1
- package/dist/esm/runtime/services/own-schedule-reader.backend.service.d.ts.map +1 -1
- package/dist/esm/runtime/services/own-schedule-reader.backend.service.js +10 -0
- package/dist/esm/runtime/services/own-schedule-reader.backend.service.js.map +1 -1
- package/dist/esm/runtime/services/start-minion-application.backend.service.d.ts.map +1 -1
- package/dist/esm/runtime/services/start-minion-application.backend.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/runtime/services/own-schedule-reader.backend.service.ts +11 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"minion-scoped-services-registry-handler.backend.service.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"minion-scoped-services-registry-handler.backend.service.d.ts","sourceRoot":"","sources":["../../../../../src/base-classes/services/services/minion-scoped-services-registry-handler.backend.service.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,gBAAgB,EAEhB,qCAAqC,EACtC,MAAM,4BAA4B,CAAC;AAEpC,KAAK,0BAA0B,GAAG,WAAW,CAC3C,WAAW,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,gBAAgB,CAAC,CACnE,CAAC;AAgFF,qBAAa,iDAAiD;IAM1D,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAN7B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAc;IAC5C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAc;IAC7C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA8B;gBAG7C,YAAY,EAAE,qCAAqC,EACnD,UAAU,EAAE,MAAM,EACnC,cAAc,EAAE,0BAA0B,GAAG,SAAS;IAMjD,mBAAmB,IAAI,qCAAqC;IAiDnE,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,iBAAiB;YAKX,iBAAiB;YAiBjB,oBAAoB;IAelC,OAAO,CAAC,kBAAkB;IAc1B,OAAO,CAAC,WAAW;IAuFnB,OAAO,CAAC,6BAA6B;IAUrC,OAAO,CAAC,iBAAiB;IAUzB,OAAO,CAAC,aAAa;CAatB"}
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uCAAuC,CAAC;AACtD,cAAc,6DAA6D,CAAC;AAC5E,cAAc,sDAAsD,CAAC;AACrE,cAAc,0FAA0F,CAAC;AACzG,OAAO,EACL,8CAA8C,EAC9C,KAAK,mCAAmC,GACzC,MAAM,4BAA4B,CAAC;AACpC,cAAc,wDAAwD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../../../../src/inject/models/container.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAIxB,MAAM,4BAA4B,CAAC;AAMpC,KAAK,SAAS,GAAG,kBAAkB,CAAC;AAmCpC,wBAAgB,wBAAwB,CAAC,QAAQ,CAAC,EAAE,SAAS,GAAG,SAAS,CAYxE;AAED,wBAAgB,yBAAyB,IAAI,SAAS,CAErD;AAED,wBAAgB,2BAA2B,IAAI,IAAI,CAGlD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-types.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"service-types.d.ts","sourceRoot":"","sources":["../../../../src/inject/models/service-types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,6BAA6B,EAAE,MAAM,CAAC;IAC/C,QAAQ,CAAC,yBAAyB,EAAE,MAAM,CAAC;IAC3C,QAAQ,CAAC,wBAAwB,EAAE,MAAM,CAAC;CAC3C;AAED,eAAO,MAAM,0BAA0B,EAAE,uBAIxC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"minion-tick-consumer.backend.service.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"minion-tick-consumer.backend.service.d.ts","sourceRoot":"","sources":["../../../../src/runtime/queue/minion-tick-consumer.backend.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,aAAa,EACb,6BAA6B,EAE7B,sCAAsC,EACtC,KAAK,kBAAkB,EACxB,MAAM,4BAA4B,CAAC;AAGpC;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE7E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBACa,gCAAgC;IAQzC,OAAO,CAAC,QAAQ,CAAC,OAAO;IAExB,OAAO,CAAC,QAAQ,CAAC,wBAAwB;IAEzC,OAAO,CAAC,QAAQ,CAAC,MAAM;IAXzB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,kBAAkB,CAAC,CAAS;IAEpC,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;gBAIvE,OAAO,EAAE,6BAA6B,EAEtC,wBAAwB,EAAE,sCAAsC,EAEhE,MAAM,EAAE,aAAa;IAM3B,KAAK,CAAC,KAAK,EAAE;QACxB,aAAa,EAAE,MAAM,CAAC;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,iBAAiB,CAAC;KAC5B,GAAG,OAAO,CAAC,IAAI,CAAC;IAsDJ,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAS3B,SAAS,IAAI,OAAO;YAIb,aAAa;CAiD5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-minion-init.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"define-minion-init.d.ts","sourceRoot":"","sources":["../../../../src/runtime/services/define-minion-init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mCAAmC,EACnC,uBAAuB,EACvB,0BAA0B,EAC3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AACvF,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,uCAAuC,CAAC;AAE7F,KAAK,oBAAoB,GAAG,uBAAuB,CAAC,OAAO,CAAC,CAAC;AAC7D,KAAK,sBAAsB,GAAG,uBAAuB,CAAC,SAAS,CAAC,CAAC;AAEjE,MAAM,WAAW,6BAA6B;IAC5C,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,uBAAuB,CAAC,aAAa,CAAC,CAAC;IACpD,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,uBAAuB,CAAC,cAAc,CAAC,CAAC;IACvD;;;;;;OAMG;IACH,sBAAsB,CAAC,EAAE,uBAAuB,CAAC,wBAAwB,CAAC,CAAC;IAC3E,mBAAmB,CAAC,EAAE,uBAAuB,CAAC,qBAAqB,CAAC,CAAC;IACrE,qBAAqB,CAAC,EAAE,uBAAuB,CAAC,uBAAuB,CAAC,CAAC;IACzE,YAAY,EAAE,SAAS,CAAC;IACxB,OAAO,EAAE,sBAAsB,CAAC;IAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;CAC9C;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;;;OAOG;IACH,YAAY,EAAE,0BAA0B,CAAC;IACzC,2EAA2E;IAC3E,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;;;;;;;;;OAaG;IACH,WAAW,EAAE,+BAA+B,CAAC;CAC9C;AAED;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG,CACpC,KAAK,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,EACvC,OAAO,EAAE,iBAAiB,KACvB,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnB,MAAM,MAAM,0BAA0B,GAAG,IAAI,CAAC,mCAAmC,EAAE,iBAAiB,CAAC,GAAG;IACtG,eAAe,CAAC,EAAE,uBAAuB,GAAG,6BAA6B,CAAC;IAC1E;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,uBAAuB,CAAC;CAClC,CAAC;AAEF,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,0BAA0B,GACjC,0BAA0B,CAE5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-minion-init.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"define-minion-init.js","sourceRoot":"","sources":["../../../../src/runtime/services/define-minion-init.ts"],"names":[],"mappings":"AA4GA,MAAM,UAAU,gBAAgB,CAC9B,MAAkC;IAElC,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type {\n ProjectedMinionInitializationConfig,\n ProviderRuntimeArtifact,\n SystemAccessBackendService,\n} from '@wildo-ai/saas-backend-lib';\nimport type { MinionTickHandler } from '../queue/minion-tick-consumer.backend.service';\nimport type { OwnScheduleReaderBackendService } from './own-schedule-reader.backend.service';\n\ntype ProviderRuntimeScope = ProviderRuntimeArtifact['scope'];\ntype ProviderRuntimeModules = ProviderRuntimeArtifact['modules'];\n\nexport interface MinionProviderRuntimeArtifact {\n __AUTOGENERATED__: string;\n generatedBy: ProviderRuntimeArtifact['generatedBy'];\n generatedAt: string;\n sourceDigest: string;\n providerRefs?: ProviderRuntimeArtifact['providerRefs'];\n /**\n * Mirrored from the engine artifact so the per-host projection can FORWARD it (#330).\n *\n * This interface is a hand-written mirror of the CLI's multi-scope artifact, so a field the\n * CLI emits and this shape omits is a field the projection can only reach through a cast —\n * which would assert, across a package boundary, the very thing nobody checked.\n */\n providerRuntimeImports?: ProviderRuntimeArtifact['providerRuntimeImports'];\n providerGraphDigest?: ProviderRuntimeArtifact['providerGraphDigest'];\n lockfileSectionDigest?: ProviderRuntimeArtifact['lockfileSectionDigest'];\n artifactKind: 'minions';\n modules: ProviderRuntimeModules;\n scopes: Record<string, ProviderRuntimeScope>;\n}\n\n/**\n * The surface a minion's tick handler is given to do its work with.\n *\n * Handed to the handler rather than left for each author to resolve from the\n * container, for the same reason the runtime identity is established in\n * framework-owned startup: a boundary an author has to find is a boundary an author\n * can get wrong. What arrives here is already the CONTAINED surface —\n * `systemAccess` routes through the minion's `resourceAccess` ACL proxy, because\n * minion startup rebinds the services registry to the scoped decorator before any\n * tick is delivered.\n *\n * So a minion's effective authority is the INTERSECTION of two independent doors\n * (see `.claude/plans/minion-runtime-scope.md` D6):\n *\n * - `resourceAccess` — operator-declared containment, enforced by the DI proxy;\n * - the system-access door — the sanctioned per-tenant-authorization bypass, which\n * for a minion is fail-closed on audit (D9 + OQ-5b): audited, or refused.\n *\n * Neither subsumes the other. A resource the ACL forbids is refused even though the\n * system-access door would have allowed it, and a read the ACL permits is still\n * refused if it cannot be recorded.\n */\nexport interface MinionTickContext {\n /**\n * The sanctioned privileged-access door, already contained by this minion's\n * `resourceAccess` whitelist.\n *\n * Use this — never a repository directly (the `no-direct-repo-from-minion` ESLint\n * rule enforces that) — so every access stays inside both doors and leaves an\n * attributable audit record naming this minion.\n */\n systemAccess: SystemAccessBackendService;\n /** This minion's name, as declared in `wildo.saas.config.ts > minions`. */\n minionName: string;\n /**\n * Read this minion's OWN cron schedule and recent runs (R4).\n *\n * Present only when the application declared the `own_cron_records` scope in\n * this minion's `platformAccess`; otherwise the platform refuses and `read()`\n * rejects. It is deliberately NOT absent from the type in that case — the\n * authority decision belongs to the platform, and a client-side `undefined`\n * would be this process guessing at it, which drifts the moment the\n * declaration changes under a running minion.\n *\n * `read()` takes no arguments, and that is the contract rather than a\n * convenience: the subject is derived from this runtime's attested identity,\n * so another minion's schedule is not something this call could be asked for.\n */\n ownSchedule: OwnScheduleReaderBackendService;\n}\n\n/**\n * Tick handler invoked by `MinionTickConsumerBackendService` once per verified\n * `MINION_TICK` token addressed to this minion (KD-12).\n */\nexport type MinionTickAuthorHandler = (\n token: Parameters<MinionTickHandler>[0],\n context: MinionTickContext,\n) => Promise<void>;\n\nexport type MinionInitializationConfig = Omit<ProjectedMinionInitializationConfig, 'providerRuntime'> & {\n providerRuntime?: ProviderRuntimeArtifact | MinionProviderRuntimeArtifact;\n /**\n * Tick handler invoked once per verified `MINION_TICK` token addressed to this\n * minion (KD-12), receiving the framework-supplied {@link MinionTickContext}.\n *\n * Minion authors typically route the tick into the locally-hosted\n * `flowsActorsRegistry` (per Q9 LOCKED — per-minion-local actor\n * catalog). If omitted, the consumer still subscribes to the\n * per-minion queue but logs a warning on every tick — useful as a\n * fail-loud signal that ticks are arriving while the minion has not\n * registered any tick-handling logic yet.\n */\n onTick?: MinionTickAuthorHandler;\n};\n\nexport function defineMinionInit(\n config: MinionInitializationConfig,\n): MinionInitializationConfig {\n return config;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"own-schedule-reader.backend.service.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"own-schedule-reader.backend.service.d.ts","sourceRoot":"","sources":["../../../../src/runtime/services/own-schedule-reader.backend.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,kBAAkB,CAAC;AAK1B,OAAO,EACL,uBAAuB,EAEvB,yCAAyC,EAEzC,KAAK,0BAA0B,EAC/B,KAAK,aAAa,EACnB,MAAM,4BAA4B,CAAC;AAEpC;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE;QACH,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,QAAQ,CAAC,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;YAAC,OAAO,CAAC,EAAE,OAAO,CAAA;SAAE,CAAC;QAClE,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;KAC1B,CAAC;IACF,gBAAgB,EAAE,KAAK,CAAC;QACtB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;KAC1B,CAAC,CAAC;CACJ;AAcD,qBACa,+BAA+B;IAIL,OAAO,CAAC,QAAQ,CAAC,MAAM;IACV,OAAO,CAAC,QAAQ,CAAC,YAAY;IAChC,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IAE9E,OAAO,CAAC,QAAQ,CAAC,YAAY;IAP/B,OAAO,CAAC,OAAO,CAAuB;gBAGgB,MAAM,EAAE,aAAa,EACR,YAAY,EAAE,0BAA0B,EAC3C,gBAAgB,EAAE,uBAAuB,EAEtF,YAAY,EAAE,yCAAyC;IAG1E;;;;;;OAMG;IACU,IAAI,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAqChD,OAAO,CAAC,cAAc;CAqBvB"}
|
|
@@ -43,6 +43,15 @@ import { inject, injectable } from 'inversify';
|
|
|
43
43
|
import { ErrorCustomMessageReference, ErrorType, WildoHeaderKeys } from '@wildo-ai/saas-models';
|
|
44
44
|
import { AppConfigurationService, PlatformApplicationType, RuntimePrincipalAttestationBackendService, SAAS_SERVICE_TYPES, } from '@wildo-ai/saas-backend-lib';
|
|
45
45
|
const OWN_SCHEDULE_PATH = '/api/v1/runtime-self/cron-jobs';
|
|
46
|
+
/**
|
|
47
|
+
* Hard deadline for the own-schedule read.
|
|
48
|
+
*
|
|
49
|
+
* The crontabs manager is ours rather than a vendor's, which changes who is at fault and not what
|
|
50
|
+
* happens: a peer that accepts the connection and never answers holds this call open indefinitely,
|
|
51
|
+
* and Node's `fetch` supplies no bound of its own. 10s, because the response is a small JSON list
|
|
52
|
+
* of this minion's jobs — nothing legitimate here spends time moving bytes.
|
|
53
|
+
*/
|
|
54
|
+
const OWN_SCHEDULE_REQUEST_TIMEOUT_MS = 10_000;
|
|
46
55
|
let OwnScheduleReaderBackendService = class OwnScheduleReaderBackendService {
|
|
47
56
|
logger;
|
|
48
57
|
errorBuilder;
|
|
@@ -75,6 +84,7 @@ let OwnScheduleReaderBackendService = class OwnScheduleReaderBackendService {
|
|
|
75
84
|
// invite the server to read the weaker of the two.
|
|
76
85
|
[WildoHeaderKeys.RUNTIME_PRINCIPAL_TOKEN]: attestation,
|
|
77
86
|
},
|
|
87
|
+
signal: AbortSignal.timeout(OWN_SCHEDULE_REQUEST_TIMEOUT_MS),
|
|
78
88
|
});
|
|
79
89
|
if (!response.ok) {
|
|
80
90
|
// Surfaced rather than swallowed into an empty schedule. A refusal and "you
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"own-schedule-reader.backend.service.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"own-schedule-reader.backend.service.js","sourceRoot":"","sources":["../../../../src/runtime/services/own-schedule-reader.backend.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;;;;;;;;;;;;;AAEH,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,EAAE,2BAA2B,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,yCAAyC,EACzC,kBAAkB,GAGnB,MAAM,4BAA4B,CAAC;AA0BpC,MAAM,iBAAiB,GAAG,gCAAgC,CAAC;AAE3D;;;;;;;GAOG;AACH,MAAM,+BAA+B,GAAG,MAAM,CAAC;AAGxC,IAAM,+BAA+B,GAArC,MAAM,+BAA+B;IAIY;IACa;IACH;IAE7C;IAPX,OAAO,GAAkB,IAAI,CAAC;IAEtC,YACsD,MAAqB,EACR,YAAwC,EAC3C,gBAAyC,EAEtF,YAAuD;QAJpB,WAAM,GAAN,MAAM,CAAe;QACR,iBAAY,GAAZ,YAAY,CAA4B;QAC3C,qBAAgB,GAAhB,gBAAgB,CAAyB;QAEtF,iBAAY,GAAZ,YAAY,CAA2C;IACvE,CAAC;IAEJ;;;;;;OAMG;IACI,KAAK,CAAC,IAAI;QACf,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;QACtC,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,cAAc,CACxD,uBAAuB,CAAC,iCAAiC,CAC1D,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,OAAO,GAAG,iBAAiB,EAAE,EAAE;YAC7D,MAAM,EAAE,KAAK;YACb,OAAO,EAAE;gBACP,CAAC,eAAe,CAAC,YAAY,CAAC,EAAE,kBAAkB;gBAClD,wEAAwE;gBACxE,u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AE,CAAC,CAAC;QAC3C,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,oDAAoD,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QACrG,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF,CAAA;AA5EY,+BAA+B;IAD3C,UAAU,EAAE;IAKR,WAAA,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAA;IACjC,WAAA,MAAM,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,CAAA;IAC9C,WAAA,MAAM,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAA;IAC3C,WAAA,MAAM,CAAC,kBAAkB,CAAC,kCAAkC,CAAC,CAAA;yDADkB,uBAAuB;QAExE,yCAAyC;GAR/D,+BAA+B,CA4E3C","sourcesContent":["/**\n * A minion reading its OWN cron records from the platform (R4).\n *\n * ## The client is as selector-free as the route\n *\n * `read()` takes no arguments. Not a minion name, not an application id, not a\n * job id — there is nothing to pass, so there is nothing an author could pass\n * wrongly and nothing a later caller could parameterise. The route it calls\n * derives its subject from the attestation, and this client's shape mirrors that\n * rather than merely respecting it.\n *\n * That symmetry is deliberate. A client with a `minionName` argument that always\n * happens to be filled with the caller's own name is one refactor away from being\n * filled with something else, and the server would still be correct while every\n * reader of this file had been taught the wrong mental model.\n *\n * ## Authority, and where it is decided\n *\n * Nothing here checks `platformAccess`. Two other places do, and both are better\n * placed: apps-manager refuses to mint an attestation for a minion whose\n * application declared no scope, and crontabs re-checks the scope before it\n * queries. A third check here would be a client-side guess about a server-side\n * decision — it would drift, and the day it drifted it would either refuse work\n * the platform allows or promise work the platform refuses.\n *\n * So a minion without the scope gets a refusal from the platform, which is the\n * party that knows.\n */\n\nimport 'reflect-metadata';\n\nimport { inject, injectable } from 'inversify';\n\nimport { ErrorCustomMessageReference, ErrorType, WildoHeaderKeys } from '@wildo-ai/saas-models';\nimport {\n AppConfigurationService,\n PlatformApplicationType,\n RuntimePrincipalAttestationBackendService,\n SAAS_SERVICE_TYPES,\n type ErrorBuilderBackendService,\n type LoggerService,\n} from '@wildo-ai/saas-backend-lib';\n\n/**\n * One cron job that ticks this minion, with its recent runs.\n *\n * Typed structurally rather than importing the platform's `CronJob` — a minion\n * runtime has no dependency on `platform-shared-lib` and giving it one to name a\n * response body would be a package boundary crossed for a type alias.\n */\nexport interface OwnScheduleEntry {\n job: {\n jobId: string;\n name?: string;\n schedule?: { cron: string; timezone?: string; enabled?: boolean };\n status?: string;\n [field: string]: unknown;\n };\n recentExecutions: Array<{\n status?: string;\n startTime?: string;\n endTime?: string;\n error?: string;\n [field: string]: unknown;\n }>;\n}\n\nconst OWN_SCHEDULE_PATH = '/api/v1/runtime-self/cron-jobs';\n\n/**\n * Hard deadline for the own-schedule read.\n *\n * The crontabs manager is ours rather than a vendor's, which changes who is at fault and not what\n * happens: a peer that accepts the connection and never answers holds this call open indefinitely,\n * and Node's `fetch` supplies no bound of its own. 10s, because the response is a small JSON list\n * of this minion's jobs — nothing legitimate here spends time moving bytes.\n */\nconst OWN_SCHEDULE_REQUEST_TIMEOUT_MS = 10_000;\n\n@injectable()\nexport class OwnScheduleReaderBackendService {\n private baseUrl: string | null = null;\n\n constructor(\n @inject(SAAS_SERVICE_TYPES.Logger) private readonly logger: LoggerService,\n @inject(SAAS_SERVICE_TYPES.ErrorBuilderService) private readonly errorBuilder: ErrorBuilderBackendService,\n @inject(SAAS_SERVICE_TYPES.AppConfigService) private readonly appConfigService: AppConfigurationService,\n @inject(SAAS_SERVICE_TYPES.RuntimePrincipalAttestationService)\n private readonly attestations: RuntimePrincipalAttestationBackendService,\n ) {}\n\n /**\n * This minion's cron job definitions and their recent runs.\n *\n * The attestation is fetched per call rather than held: the exchange caches it,\n * so this costs nothing, and a client that cached it itself would eventually\n * present an expired one.\n */\n public async read(): Promise<OwnScheduleEntry[]> {\n const baseUrl = this.resolveBaseUrl();\n const attestation = await this.attestations.getAttestation(\n PlatformApplicationType.PLATFORM_CRONTABS_BATCHES_MANAGER,\n );\n\n const response = await fetch(`${baseUrl}${OWN_SCHEDULE_PATH}`, {\n method: 'GET',\n headers: {\n [WildoHeaderKeys.CONTENT_TYPE]: 'application/json',\n // Deliberately the ONLY credential. A minion is not a platform service,\n // so no `X-Service-Id`; and an application JWT would carry an identity\n // meaning \"some runtime of this app\" — attaching one as well would only\n // invite the server to read the weaker of the two.\n [WildoHeaderKeys.RUNTIME_PRINCIPAL_TOKEN]: attestation,\n },\n signal: AbortSignal.timeout(OWN_SCHEDULE_REQUEST_TIMEOUT_MS),\n });\n\n if (!response.ok) {\n // Surfaced rather than swallowed into an empty schedule. A refusal and \"you\n // have no jobs\" are different answers, and returning `[]` for both would\n // make a missing `platformAccess` declaration look like a correctly-empty\n // schedule — the one failure an author cannot debug from the result.\n throw this.errorBuilder.buildError(ErrorType.AUTHORIZATION, undefined, {\n customMessageReference: ErrorCustomMessageReference.AUTHORIZATION,\n context: {\n message: 'The platform refused this runtime\\'s own-schedule read',\n status: response.status,\n },\n });\n }\n\n const body = (await response.json()) as { jobs?: OwnScheduleEntry[] } | null;\n return body?.jobs ?? [];\n }\n\n private resolveBaseUrl(): string {\n if (this.baseUrl) return this.baseUrl;\n\n const baseUrl =\n this.appConfigService.config.runtime.endPoints[PlatformApplicationType.PLATFORM_CRONTABS_BATCHES_MANAGER]\n ?.internalUrl;\n\n if (!baseUrl) {\n // A CONFIGURATION failure, not an authorization one. Blurring them would\n // send an operator to inspect the minion's `platformAccess` declaration\n // over what is really a missing endpoint in this deployment's topology.\n throw this.errorBuilder.buildError(ErrorType.CONFIGURATION, undefined, {\n customMessageReference: ErrorCustomMessageReference.CONFIGURATION,\n context: { message: 'The crontabs-manager endpoint is not configured for this runtime' },\n });\n }\n\n this.baseUrl = baseUrl.replace(/\\/+$/, '');\n this.logger.debug?.('Own-schedule reader bound to the crontabs endpoint', { baseUrl: this.baseUrl });\n return this.baseUrl;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start-minion-application.backend.service.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"start-minion-application.backend.service.d.ts","sourceRoot":"","sources":["../../../../src/runtime/services/start-minion-application.backend.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,uBAAuB,EAI5B,KAAK,aAAa,EAElB,KAAK,8BAA8B,EACnC,KAAK,0BAA0B,EAE/B,KAAK,8BAA8B,EACpC,MAAM,4BAA4B,CAAC;AAKpC,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,uCAAuC,CAAC;AAC7F,OAAO,EACL,gCAAgC,EAEjC,MAAM,+CAA+C,CAAC;AACvD,OAAO,KAAK,EACV,0BAA0B,EAI3B,MAAM,sBAAsB,CAAC;AAQ9B,qBACa,oCAAoC;IAK7C,OAAO,CAAC,QAAQ,CAAC,uBAAuB;IAExC,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IAEjC,OAAO,CAAC,QAAQ,CAAC,YAAY;IAE7B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAEvB,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IAEjC,OAAO,CAAC,QAAQ,CAAC,YAAY;IAE7B,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAhBpC,OAAO,CAAC,mBAAmB,CAAS;gBAIjB,uBAAuB,EAAE,8BAA8B,EAEvD,gBAAgB,EAAE,uBAAuB,EAEzC,YAAY,EAAE,gCAAgC,EAE9C,MAAM,EAAE,aAAa,EAErB,gBAAgB,EAAE,8BAA8B,EAEhD,YAAY,EAAE,0BAA0B,EAExC,iBAAiB,EAAE,+BAA+B;IAGxD,UAAU,CAAC,MAAM,EAAE,0BAA0B,GAAG,OAAO,CAAC,IAAI,CAAC;IAmI7D,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAe/B,wBAAwB,IAAI,OAAO;YAI5B,iBAAiB;IA4C/B,OAAO,CAAC,sBAAsB;IAkC9B;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,OAAO,CAAC,wBAAwB;IAoBhC,OAAO,CAAC,gCAAgC;CAoEzC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start-minion-application.backend.service.js","sourceRoot":"","sources":["../../../../../src/runtime/services/start-minion-application.backend.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAGL,yBAAyB,EACzB,MAAM,EACN,UAAU,EAKV,kBAAkB,GAEnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,2BAA2B,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EAAE,8BAA8B,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,EAAE,iDAAiD,EAAE,MAAM,8FAA8F,CAAC;AACjK,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAE/E,OAAO,EACL,gCAAgC,GAEjC,MAAM,+CAA+C,CAAC;AAehD,IAAM,oCAAoC,GAA1C,MAAM,oCAAoC;IAK5B;IAEA;IAEA;IAEA;IAEA;IAEA;IAEA;IAhBX,mBAAmB,GAAG,KAAK,CAAC;IAEpC,YAEmB,uBAAuD,EAEvD,gBAAyC,EAEzC,YAA8C,EAE9C,MAAqB,EAErB,gBAAgD,EAEhD,YAAwC,EAExC,iBAAkD;QAZlD,4BAAuB,GAAvB,uBAAuB,CAAgC;QAEvD,qBAAgB,GAAhB,gBAAgB,CAAyB;QAEzC,iBAAY,GAAZ,YAAY,CAAkC;QAE9C,WAAM,GAAN,MAAM,CAAe;QAErB,qBAAgB,GAAhB,gBAAgB,CAAgC;QAEhD,iBAAY,GAAZ,YAAY,CAA4B;QAExC,sBAAiB,GAAjB,iBAAiB,CAAiC;IAClE,CAAC;IAEG,KAAK,CAAC,UAAU,CAAC,MAAkC;QACxD,MAAM,EACJ,UAAU,EACV,iBAAiB,EACjB,MAAM,EACN,GAAG,aAAa,EACjB,GAAG,MAAM,CAAC;QACX,+EAA+E;QAC/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kB,CAAC,uBAAuB,CAAC,CAAA;IAElD,WAAA,MAAM,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,CAAA;IAE9C,WAAA,MAAM,CAAC,0BAA0B,CAAC,wBAAwB,CAAC,CAAA;yDAP7B,gCAAgC;GATtD,oCAAoC,CAyWhD","sourcesContent":["import {\n type AppConfiguration,\n type AppConfigurationService,\n ApplicationRuntimeProfile,\n inject,\n injectable,\n type LoggerService,\n type ProviderRuntimeArtifact,\n type RuntimePrincipalBackendService,\n type SystemAccessBackendService,\n SAAS_SERVICE_TYPES,\n type StartApplicationBackendService,\n} from '@wildo-ai/saas-backend-lib';\nimport { ErrorCustomMessageReference, ErrorType } from '@wildo-ai/saas-models';\nimport { assertProviderRuntimeEnvInSync } from '@wildo-ai/platform-config-lib';\nimport { MinionScopedServicesRegistryHandlerBackendService } from '../../base-classes/services/services/minion-scoped-services-registry-handler.backend.service';\nimport { SAAS_MINIONS_SERVICE_TYPES } from '../../inject/models/service-types';\nimport type { OwnScheduleReaderBackendService } from './own-schedule-reader.backend.service';\nimport {\n MinionTickConsumerBackendService,\n type MinionTickHandler,\n} from '../queue/minion-tick-consumer.backend.service';\nimport type {\n MinionInitializationConfig,\n MinionProviderRuntimeArtifact,\n MinionTickAuthorHandler,\n MinionTickContext,\n} from './define-minion-init';\n\ntype MinionAwareAppConfiguration = AppConfiguration & {\n minions?: Record<string, MinionRuntimeConfig>;\n};\n\ntype MinionRuntimeConfig = NonNullable<NonNullable<AppConfiguration['minions']>[string]>;\n\n@injectable()\nexport class StartMinionApplicationBackendService {\n private tickConsumerStarted = false;\n\n constructor(\n @inject(SAAS_SERVICE_TYPES.StartApplicationService)\n private readonly startApplicationService: StartApplicationBackendService,\n @inject(SAAS_SERVICE_TYPES.AppConfigService)\n private readonly appConfigService: AppConfigurationService,\n @inject(SAAS_MINIONS_SERVICE_TYPES.MinionTickConsumerService)\n private readonly tickConsumer: MinionTickConsumerBackendService,\n @inject(SAAS_SERVICE_TYPES.Logger)\n private readonly logger: LoggerService,\n @inject(SAAS_SERVICE_TYPES.RuntimePrincipalService)\n private readonly runtimePrincipal: RuntimePrincipalBackendService,\n @inject(SAAS_SERVICE_TYPES.SystemAccessService)\n private readonly systemAccess: SystemAccessBackendService,\n @inject(SAAS_MINIONS_SERVICE_TYPES.OwnScheduleReaderService)\n private readonly ownScheduleReader: OwnScheduleReaderBackendService,\n ) {}\n\n public async initialize(config: MinionInitializationConfig): Promise<void> {\n const {\n minionName,\n serviceIdentifier,\n onTick,\n ...startupConfig\n } = config;\n // Declare WHO this process is before anything can perform a privileged access.\n //\n // Established here, in framework-owned minion startup, rather than left to each\n // minion author — attribution that an author can forget is attribution that will\n // be missing exactly when an auditor needs it. Every minion therefore carries its\n // identity structurally, by virtue of being a minion.\n //\n // Attribution only: this grants nothing. A minion's operations are governed by its\n // role and its `resourceAccess` whitelist; its cross-tenant reach comes from the\n // system-access door. See `.claude/plans/minion-runtime-scope.md` (D9).\n //\n // assurance-control: WILDO.AUDIT.SECURITY_EVENT — privileged access by a non-human\n // background runtime is attributable to that runtime.\n this.runtimePrincipal.initialize({\n runtimeProfile: ApplicationRuntimeProfile.MINION,\n runtimeKey: minionName,\n serviceIdentifier: serviceIdentifier ?? `minions.${minionName}`,\n });\n\n const normalizedProviderRuntime = this.normalizeProviderRuntime(\n startupConfig.providerRuntime,\n minionName,\n );\n\n // Boot-time fail-closed reconciliation between the typed\n // `wildo-provider-runtime.generated.ts` artifact and the\n // `.wildo-providers.env` file mounted into this process. Catches\n // stale-sync drift (operator regenerated one surface but not the\n // other) BEFORE the registry filter would silently boot with\n // mismatched topology.\n //\n // Skipped when:\n // - the artifact is absent (host authored zero providers AND no\n // scope block in `wildo.saas.config.ts`); or\n // - the artifact has zero `providerRefs` (host authored an\n // explicit empty scope `providers: {}`). The CLI emitter\n // deliberately does NOT write `.wildo-providers.env` in that\n // case, so the env-vars are absent — running the assertion\n // would raise a false-positive fail-closed.\n // Defensive `?? []` — the schema marks `providerRefs` optional, so\n // a hand-crafted artifact (test fixture / future format drift)\n // could omit it. Without the fallback `.length` would TypeError\n // before fail-closed produced its actionable message. Production\n // CLI emit always defaults to `[]`, so this is hardening only.\n const projectedProviderRefs = normalizedProviderRuntime?.providerRefs ?? [];\n if (normalizedProviderRuntime && projectedProviderRefs.length > 0) {\n assertProviderRuntimeEnvInSync({\n artifactProviderRefs: projectedProviderRefs,\n artifactSourceDigest: normalizedProviderRuntime.sourceDigest,\n hostKind: 'minion',\n hostKey: minionName,\n });\n }\n\n await this.startApplicationService.initialize({\n ...startupConfig,\n providerRuntime: normalizedProviderRuntime,\n headlessMode: true,\n skipCronSync: true,\n // A minion reuses the full backend startup lifecycle but is NOT a job\n // worker for the shared application queues — it consumes ONLY its own\n // `minion-tick.<name>` queue (subscribed below via `startTickConsumer`).\n // Skipping the shared job consumers keeps RabbitMQ from round-robining\n // scheduled-cron ticks onto this process (which would dead-letter every\n // tick it can't interpret). The broker connection itself is still made,\n // because the tick consumer depends on it.\n skipJobConsumers: true,\n serviceIdentifier: serviceIdentifier ?? `minions.${minionName}`,\n afterResourcesRegistryInitialized: async ({\n appConfig,\n resourcesRegistryService,\n errorBuilder,\n }) => {\n const minionConfig = this.getMinionRuntimeConfig(\n appConfig as MinionAwareAppConfiguration,\n minionName,\n errorBuilder,\n );\n const resourceAccess = minionConfig.resourceAccess;\n const knownResourceTypes = new Set(resourcesRegistryService.getResourceTypes());\n const unknownResourceTypes = [\n ...(resourceAccess?.read ?? []),\n ...(resourceAccess?.write ?? []),\n ].filter((resourceType, index, all) => (\n resourceType !== '*'\n && !knownResourceTypes.has(resourceType)\n && all.indexOf(resourceType) === index\n ));\n\n if (unknownResourceTypes.length > 0) {\n throw errorBuilder.buildError(ErrorType.CONFIGURATION, undefined, {\n customMessageReference: ErrorCustomMessageReference.CONFIGURATION,\n context: {\n message:\n `Minion '${minionName}' references unknown resources in resourceAccess: `\n + `[${unknownResourceTypes.join(', ')}].`,\n minionName,\n unknownResourceTypes,\n },\n });\n }\n },\n servicesRegistryDecoratorFactory: (registry, { appConfig, errorBuilder }) => (\n new MinionScopedServicesRegistryHandlerBackendService(\n registry as any,\n minionName,\n this.getMinionRuntimeConfig(\n appConfig as MinionAwareAppConfiguration,\n minionName,\n errorBuilder,\n ).resourceAccess,\n ).asDecoratedRegistry()\n ),\n });\n\n // KD-12 auto-wiring: every minion subscribes to its dedicated tick\n // queue (`wildo.queue.<appId>.minion-tick.<minionName>`). Cron-mode\n // minions receive ticks from `platform-crontabs-batches-manager`;\n // always-up minions receive nothing on this queue under normal\n // operation but the subscription is harmless (no message ⇒ no\n // dispatch) and keeps the runtime contract symmetric across modes.\n await this.startTickConsumer(minionName, onTick);\n }\n\n public async shutdown(): Promise<void> {\n if (this.tickConsumerStarted) {\n try {\n await this.tickConsumer.stop();\n } catch (error) {\n this.logger.warn('Failed to stop minion tick consumer cleanly', {\n error: error instanceof Error ? error.message : String(error),\n });\n } finally {\n this.tickConsumerStarted = false;\n }\n }\n await this.startApplicationService.shutdown();\n }\n\n public isApplicationInitialized(): boolean {\n return this.startApplicationService.isApplicationInitialized();\n }\n\n private async startTickConsumer(\n minionName: string,\n onTick: MinionTickAuthorHandler | undefined,\n ): Promise<void> {\n // The surface the handler is ALLOWED to work with, assembled once at the tick\n // boundary. Handed to the author rather than left for them to resolve from the\n // container: `systemAccess` here is already contained by this minion's\n // `resourceAccess` ACL, because startup rebinds the services registry to the\n // scoped decorator before any tick can be delivered. An author who resolved the\n // door themselves could bypass that; an author handed this one cannot.\n const context: MinionTickContext = {\n systemAccess: this.systemAccess,\n minionName,\n // Same reasoning as `systemAccess`: handed to the author rather than left\n // to be resolved from the container. A reader an author constructs is a\n // reader an author could construct with a different identity; this one is\n // bound to the process's own attested principal and cannot be pointed\n // elsewhere.\n ownSchedule: this.ownScheduleReader,\n };\n\n const handler: MinionTickHandler = onTick\n ? async (token) => onTick(token, context)\n : async (token) => {\n this.logger.warn(\n 'Minion tick received but no onTick handler is registered — ' +\n 'wire `defineMinionInit({ ..., onTick })` to route ticks into ' +\n 'the locally-hosted actor system (per Q9 LOCKED).',\n {\n jobId: token.jobId,\n minionName: token.minionName,\n applicationId: token.applicationId,\n },\n );\n };\n\n await this.tickConsumer.start({\n applicationId: this.appConfigService.applicationId,\n minionName,\n handler,\n });\n this.tickConsumerStarted = true;\n }\n\n private getMinionRuntimeConfig(\n appConfig: MinionAwareAppConfiguration,\n minionName: string,\n errorBuilder?: {\n buildError: (\n errorType: ErrorType,\n executionContext: undefined,\n options: {\n customMessageReference?: ErrorCustomMessageReference;\n context?: Record<string, unknown>;\n },\n ) => unknown;\n },\n ): MinionRuntimeConfig {\n const minionConfig = appConfig.minions?.[minionName];\n if (minionConfig) {\n return minionConfig;\n }\n\n if (!errorBuilder) {\n throw new Error(`Minion '${minionName}' is missing from appConfig.minions.`);\n }\n\n throw errorBuilder.buildError(ErrorType.CONFIGURATION, undefined, {\n customMessageReference: ErrorCustomMessageReference.CONFIGURATION,\n context: {\n message:\n `Minion '${minionName}' is not declared in the managed runtime config. `\n + 'Re-sync the application bootstrap material before starting the minion.',\n minionName,\n },\n });\n }\n\n /**\n * Bridge the per-minion materialized provider runtime artifact into the\n * `ProviderRuntimeArtifact` shape consumed by `StartApplicationBackendService`\n * (and ultimately filtered by `BackendProviderRegistryBackendService`).\n *\n * Three accepted input shapes:\n *\n * 1. `{ artifactKind: 'backend', scope: ... }` — already projected to a\n * backend-shaped single-scope artifact (e.g. produced by an\n * embedding host that pre-selected the scope).\n * 2. `{ artifactKind: 'minions', scope: ..., scopes: undefined }` —\n * what `wildo config sync` writes to each minion's\n * `src/generated/wildo-provider-runtime.generated.ts`. The CLI calls\n * `selectScopedProviderRuntimeArtifact(artifacts.minions, minionKey)`\n * so the file already carries only this minion's scope. We unwrap\n * it here to the canonical backend-shaped artifact.\n * 3. `{ artifactKind: 'minions', scopes: { [name]: ... } }` —\n * multi-scope minion artifact (legacy / non-CLI-driven hosts that\n * pass the unscoped artifact). We resolve `scopes[minionName]`.\n *\n * Anything else fails fast with a clear locator. Each minion process\n * must only see its own scope — there is no fallback to other scopes,\n * no merging across minions, and no silent recovery from a missing\n * scope.\n */\n private normalizeProviderRuntime(\n providerRuntime: MinionInitializationConfig['providerRuntime'],\n minionName: string,\n ): ProviderRuntimeArtifact | undefined {\n if (!providerRuntime) {\n return undefined;\n }\n if (providerRuntime.artifactKind === 'backend') {\n return providerRuntime;\n }\n const artifactKind = providerRuntime.artifactKind;\n if (artifactKind !== 'minions') {\n throw new Error(\n `Unsupported provider runtime artifactKind '${artifactKind}' for minion '${minionName}'.`,\n );\n }\n\n return this.selectMinionProviderRuntimeScope(providerRuntime, minionName);\n }\n\n private selectMinionProviderRuntimeScope(\n providerRuntime: MinionProviderRuntimeArtifact,\n minionName: string,\n ): ProviderRuntimeArtifact {\n const preScopedScope = (providerRuntime as MinionProviderRuntimeArtifact & {\n scope?: ProviderRuntimeArtifact['scope'];\n }).scope;\n const scopes = providerRuntime.scopes as\n | Record<string, ProviderRuntimeArtifact['scope']>\n | undefined;\n\n let scope: ProviderRuntimeArtifact['scope'] | undefined;\n\n if (preScopedScope && (!scopes || Object.keys(scopes).length === 0)) {\n // Shape 2 — the CLI-emitted per-minion module.\n scope = preScopedScope;\n } else if (scopes) {\n // Shape 3 — unscoped multi-scope artifact.\n scope = scopes[minionName];\n if (!scope) {\n throw new Error(\n `Provider runtime artifact does not contain a scope for minion '${minionName}'. `\n + `Re-run \\`wildo config sync\\` and verify the minion is declared in `\n + `wildo.saas.config.ts \\`providers.scopes.minions\\`.`,\n );\n }\n }\n\n if (!scope) {\n throw new Error(\n `Provider runtime artifact for minion '${minionName}' is missing both a `\n + `pre-scoped \\`scope\\` and a multi-scope \\`scopes\\` map. The artifact is malformed.`,\n );\n }\n\n // Recompute `providerRefs` from the projected per-host scope, NOT\n // from the multi-scope union the parent artifact carries. The\n // `buildMultiScopeArtifactMetadata` upstream computes\n // `providerRefs` as the union across all hosts; preserving that\n // here would make the boot-time `assertProviderRuntimeEnvInSync`\n // guard treat sibling-scope refs as \"this host has providers\" and\n // mistakenly run reconciliation on hosts whose own scope is empty.\n // Mirrors `selectScopedProviderRuntimeArtifact` in\n // `provider-runtime-artifacts.ts`.\n const projectedProviderRefs = Object.keys(scope.providers ?? {}).sort();\n // Narrowed with the refs, for the same reason (#330): the import map on a multi-scope artifact\n // is the union across every host, and handing this host a sibling's package specifiers would\n // tell it that it may load something it never declared.\n const projectedProviderRuntimeImports = Object.fromEntries(\n Object.entries(\n providerRuntime.providerRuntimeImports ?? {},\n ).filter(([providerRef]) => projectedProviderRefs.includes(providerRef)),\n );\n\n return {\n __AUTOGENERATED__: providerRuntime.__AUTOGENERATED__,\n generatedBy: providerRuntime.generatedBy,\n generatedAt: providerRuntime.generatedAt,\n sourceDigest: providerRuntime.sourceDigest,\n providerRefs: projectedProviderRefs,\n providerRuntimeImports: projectedProviderRuntimeImports,\n providerGraphDigest: providerRuntime.providerGraphDigest,\n lockfileSectionDigest: providerRuntime.lockfileSectionDigest,\n artifactKind: 'backend',\n modules: providerRuntime.modules,\n scope,\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"start-minion-application.backend.service.js","sourceRoot":"","sources":["../../../../src/runtime/services/start-minion-application.backend.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAGL,yBAAyB,EACzB,MAAM,EACN,UAAU,EAKV,kBAAkB,GAEnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,2BAA2B,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EAAE,8BAA8B,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,EAAE,iDAAiD,EAAE,MAAM,8FAA8F,CAAC;AACjK,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAE/E,OAAO,EACL,gCAAgC,GAEjC,MAAM,+CAA+C,CAAC;AAehD,IAAM,oCAAoC,GAA1C,MAAM,oCAAoC;IAK5B;IAEA;IAEA;I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C,YAAY,EAAE,eAAe,CAAC,YAAY;YAC1C,YAAY,EAAE,qBAAqB;YACnC,sBAAsB,EAAE,+BAA+B;YACvD,mBAAmB,EAAE,eAAe,CAAC,mBAAmB;YACxD,qBAAqB,EAAE,eAAe,CAAC,qBAAqB;YAC5D,YAAY,EAAE,SAAS;YACvB,OAAO,EAAE,eAAe,CAAC,OAAO;YAChC,KAAK;SACN,CAAC;IACJ,CAAC;CACF,CAAA;AAzWY,oCAAoC;IADhD,UAAU,EAAE;IAKR,WAAA,MAAM,CAAC,kBAAkB,CAAC,uBAAuB,CAAC,CAAA;IAElD,WAAA,MAAM,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAA;IAE3C,WAAA,MAAM,CAAC,0BAA0B,CAAC,yBAAyB,CAAC,CAAA;IAE5D,WAAA,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAA;IAEjC,WAAA,MAAM,CAAC,kBAAkB,CAAC,uBAAuB,CAAC,CAAA;IAElD,WAAA,MAAM,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,CAAA;IAE9C,WAAA,MAAM,CAAC,0BAA0B,CAAC,wBAAwB,CAAC,CAAA;yDAP7B,gCAAgC;GATtD,oCAAoC,CAyWhD","sourcesContent":["import {\n type AppConfiguration,\n type AppConfigurationService,\n ApplicationRuntimeProfile,\n inject,\n injectable,\n type LoggerService,\n type ProviderRuntimeArtifact,\n type RuntimePrincipalBackendService,\n type SystemAccessBackendService,\n SAAS_SERVICE_TYPES,\n type StartApplicationBackendService,\n} from '@wildo-ai/saas-backend-lib';\nimport { ErrorCustomMessageReference, ErrorType } from '@wildo-ai/saas-models';\nimport { assertProviderRuntimeEnvInSync } from '@wildo-ai/platform-config-lib';\nimport { MinionScopedServicesRegistryHandlerBackendService } from '../../base-classes/services/services/minion-scoped-services-registry-handler.backend.service';\nimport { SAAS_MINIONS_SERVICE_TYPES } from '../../inject/models/service-types';\nimport type { OwnScheduleReaderBackendService } from './own-schedule-reader.backend.service';\nimport {\n MinionTickConsumerBackendService,\n type MinionTickHandler,\n} from '../queue/minion-tick-consumer.backend.service';\nimport type {\n MinionInitializationConfig,\n MinionProviderRuntimeArtifact,\n MinionTickAuthorHandler,\n MinionTickContext,\n} from './define-minion-init';\n\ntype MinionAwareAppConfiguration = AppConfiguration & {\n minions?: Record<string, MinionRuntimeConfig>;\n};\n\ntype MinionRuntimeConfig = NonNullable<NonNullable<AppConfiguration['minions']>[string]>;\n\n@injectable()\nexport class StartMinionApplicationBackendService {\n private tickConsumerStarted = false;\n\n constructor(\n @inject(SAAS_SERVICE_TYPES.StartApplicationService)\n private readonly startApplicationService: StartApplicationBackendService,\n @inject(SAAS_SERVICE_TYPES.AppConfigService)\n private readonly appConfigService: AppConfigurationService,\n @inject(SAAS_MINIONS_SERVICE_TYPES.MinionTickConsumerService)\n private readonly tickConsumer: MinionTickConsumerBackendService,\n @inject(SAAS_SERVICE_TYPES.Logger)\n private readonly logger: LoggerService,\n @inject(SAAS_SERVICE_TYPES.RuntimePrincipalService)\n private readonly runtimePrincipal: RuntimePrincipalBackendService,\n @inject(SAAS_SERVICE_TYPES.SystemAccessService)\n private readonly systemAccess: SystemAccessBackendService,\n @inject(SAAS_MINIONS_SERVICE_TYPES.OwnScheduleReaderService)\n private readonly ownScheduleReader: OwnScheduleReaderBackendService,\n ) {}\n\n public async initialize(config: MinionInitializationConfig): Promise<void> {\n const {\n minionName,\n serviceIdentifier,\n onTick,\n ...startupConfig\n } = config;\n // Declare WHO this process is before anything can perform a privileged access.\n //\n // Established here, in framework-owned minion startup, rather than left to each\n // minion author — attribution that an author can forget is attribution that will\n // be missing exactly when an auditor needs it. Every minion therefore carries its\n // identity structurally, by virtue of being a minion.\n //\n // Attribution only: this grants nothing. A minion's operations are governed by its\n // role and its `resourceAccess` whitelist; its cross-tenant reach comes from the\n // system-access door. See `.claude/plans/minion-runtime-scope.md` (D9).\n //\n // assurance-control: WILDO.AUDIT.SECURITY_EVENT — privileged access by a non-human\n // background runtime is attributable to that runtime.\n this.runtimePrincipal.initialize({\n runtimeProfile: ApplicationRuntimeProfile.MINION,\n runtimeKey: minionName,\n serviceIdentifier: serviceIdentifier ?? `minions.${minionName}`,\n });\n\n const normalizedProviderRuntime = this.normalizeProviderRuntime(\n startupConfig.providerRuntime,\n minionName,\n );\n\n // Boot-time fail-closed reconciliation between the typed\n // `wildo-provider-runtime.generated.ts` artifact and the\n // `.wildo-providers.env` file mounted into this process. Catches\n // stale-sync drift (operator regenerated one surface but not the\n // other) BEFORE the registry filter would silently boot with\n // mismatched topology.\n //\n // Skipped when:\n // - the artifact is absent (host authored zero providers AND no\n // scope block in `wildo.saas.config.ts`); or\n // - the artifact has zero `providerRefs` (host authored an\n // explicit empty scope `providers: {}`). The CLI emitter\n // deliberately does NOT write `.wildo-providers.env` in that\n // case, so the env-vars are absent — running the assertion\n // would raise a false-positive fail-closed.\n // Defensive `?? []` — the schema marks `providerRefs` optional, so\n // a hand-crafted artifact (test fixture / future format drift)\n // could omit it. Without the fallback `.length` would TypeError\n // before fail-closed produced its actionable message. Production\n // CLI emit always defaults to `[]`, so this is hardening only.\n const projectedProviderRefs = normalizedProviderRuntime?.providerRefs ?? [];\n if (normalizedProviderRuntime && projectedProviderRefs.length > 0) {\n assertProviderRuntimeEnvInSync({\n artifactProviderRefs: projectedProviderRefs,\n artifactSourceDigest: normalizedProviderRuntime.sourceDigest,\n hostKind: 'minion',\n hostKey: minionName,\n });\n }\n\n await this.startApplicationService.initialize({\n ...startupConfig,\n providerRuntime: normalizedProviderRuntime,\n headlessMode: true,\n skipCronSync: true,\n // A minion reuses the full backend startup lifecycle but is NOT a job\n // worker for the shared application queues — it consumes ONLY its own\n // `minion-tick.<name>` queue (subscribed below via `startTickConsumer`).\n // Skipping the shared job consumers keeps RabbitMQ from round-robining\n // scheduled-cron ticks onto this process (which would dead-letter every\n // tick it can't interpret). The broker connection itself is still made,\n // because the tick consumer depends on it.\n skipJobConsumers: true,\n serviceIdentifier: serviceIdentifier ?? `minions.${minionName}`,\n afterResourcesRegistryInitialized: async ({\n appConfig,\n resourcesRegistryService,\n errorBuilder,\n }) => {\n const minionConfig = this.getMinionRuntimeConfig(\n appConfig as MinionAwareAppConfiguration,\n minionName,\n errorBuilder,\n );\n const resourceAccess = minionConfig.resourceAccess;\n const knownResourceTypes = new Set(resourcesRegistryService.getResourceTypes());\n const unknownResourceTypes = [\n ...(resourceAccess?.read ?? []),\n ...(resourceAccess?.write ?? []),\n ].filter((resourceType, index, all) => (\n resourceType !== '*'\n && !knownResourceTypes.has(resourceType)\n && all.indexOf(resourceType) === index\n ));\n\n if (unknownResourceTypes.length > 0) {\n throw errorBuilder.buildError(ErrorType.CONFIGURATION, undefined, {\n customMessageReference: ErrorCustomMessageReference.CONFIGURATION,\n context: {\n message:\n `Minion '${minionName}' references unknown resources in resourceAccess: `\n + `[${unknownResourceTypes.join(', ')}].`,\n minionName,\n unknownResourceTypes,\n },\n });\n }\n },\n servicesRegistryDecoratorFactory: (registry, { appConfig, errorBuilder }) => (\n new MinionScopedServicesRegistryHandlerBackendService(\n registry as any,\n minionName,\n this.getMinionRuntimeConfig(\n appConfig as MinionAwareAppConfiguration,\n minionName,\n errorBuilder,\n ).resourceAccess,\n ).asDecoratedRegistry()\n ),\n });\n\n // KD-12 auto-wiring: every minion subscribes to its dedicated tick\n // queue (`wildo.queue.<appId>.minion-tick.<minionName>`). Cron-mode\n // minions receive ticks from `platform-crontabs-batches-manager`;\n // always-up minions receive nothing on this queue under normal\n // operation but the subscription is harmless (no message ⇒ no\n // dispatch) and keeps the runtime contract symmetric across modes.\n await this.startTickConsumer(minionName, onTick);\n }\n\n public async shutdown(): Promise<void> {\n if (this.tickConsumerStarted) {\n try {\n await this.tickConsumer.stop();\n } catch (error) {\n this.logger.warn('Failed to stop minion tick consumer cleanly', {\n error: error instanceof Error ? error.message : String(error),\n });\n } finally {\n this.tickConsumerStarted = false;\n }\n }\n await this.startApplicationService.shutdown();\n }\n\n public isApplicationInitialized(): boolean {\n return this.startApplicationService.isApplicationInitialized();\n }\n\n private async startTickConsumer(\n minionName: string,\n onTick: MinionTickAuthorHandler | undefined,\n ): Promise<void> {\n // The surface the handler is ALLOWED to work with, assembled once at the tick\n // boundary. Handed to the author rather than left for them to resolve from the\n // container: `systemAccess` here is already contained by this minion's\n // `resourceAccess` ACL, because startup rebinds the services registry to the\n // scoped decorator before any tick can be delivered. An author who resolved the\n // door themselves could bypass that; an author handed this one cannot.\n const context: MinionTickContext = {\n systemAccess: this.systemAccess,\n minionName,\n // Same reasoning as `systemAccess`: handed to the author rather than left\n // to be resolved from the container. A reader an author constructs is a\n // reader an author could construct with a different identity; this one is\n // bound to the process's own attested principal and cannot be pointed\n // elsewhere.\n ownSchedule: this.ownScheduleReader,\n };\n\n const handler: MinionTickHandler = onTick\n ? async (token) => onTick(token, context)\n : async (token) => {\n this.logger.warn(\n 'Minion tick received but no onTick handler is registered — ' +\n 'wire `defineMinionInit({ ..., onTick })` to route ticks into ' +\n 'the locally-hosted actor system (per Q9 LOCKED).',\n {\n jobId: token.jobId,\n minionName: token.minionName,\n applicationId: token.applicationId,\n },\n );\n };\n\n await this.tickConsumer.start({\n applicationId: this.appConfigService.applicationId,\n minionName,\n handler,\n });\n this.tickConsumerStarted = true;\n }\n\n private getMinionRuntimeConfig(\n appConfig: MinionAwareAppConfiguration,\n minionName: string,\n errorBuilder?: {\n buildError: (\n errorType: ErrorType,\n executionContext: undefined,\n options: {\n customMessageReference?: ErrorCustomMessageReference;\n context?: Record<string, unknown>;\n },\n ) => unknown;\n },\n ): MinionRuntimeConfig {\n const minionConfig = appConfig.minions?.[minionName];\n if (minionConfig) {\n return minionConfig;\n }\n\n if (!errorBuilder) {\n throw new Error(`Minion '${minionName}' is missing from appConfig.minions.`);\n }\n\n throw errorBuilder.buildError(ErrorType.CONFIGURATION, undefined, {\n customMessageReference: ErrorCustomMessageReference.CONFIGURATION,\n context: {\n message:\n `Minion '${minionName}' is not declared in the managed runtime config. `\n + 'Re-sync the application bootstrap material before starting the minion.',\n minionName,\n },\n });\n }\n\n /**\n * Bridge the per-minion materialized provider runtime artifact into the\n * `ProviderRuntimeArtifact` shape consumed by `StartApplicationBackendService`\n * (and ultimately filtered by `BackendProviderRegistryBackendService`).\n *\n * Three accepted input shapes:\n *\n * 1. `{ artifactKind: 'backend', scope: ... }` — already projected to a\n * backend-shaped single-scope artifact (e.g. produced by an\n * embedding host that pre-selected the scope).\n * 2. `{ artifactKind: 'minions', scope: ..., scopes: undefined }` —\n * what `wildo config sync` writes to each minion's\n * `src/generated/wildo-provider-runtime.generated.ts`. The CLI calls\n * `selectScopedProviderRuntimeArtifact(artifacts.minions, minionKey)`\n * so the file already carries only this minion's scope. We unwrap\n * it here to the canonical backend-shaped artifact.\n * 3. `{ artifactKind: 'minions', scopes: { [name]: ... } }` —\n * multi-scope minion artifact (legacy / non-CLI-driven hosts that\n * pass the unscoped artifact). We resolve `scopes[minionName]`.\n *\n * Anything else fails fast with a clear locator. Each minion process\n * must only see its own scope — there is no fallback to other scopes,\n * no merging across minions, and no silent recovery from a missing\n * scope.\n */\n private normalizeProviderRuntime(\n providerRuntime: MinionInitializationConfig['providerRuntime'],\n minionName: string,\n ): ProviderRuntimeArtifact | undefined {\n if (!providerRuntime) {\n return undefined;\n }\n if (providerRuntime.artifactKind === 'backend') {\n return providerRuntime;\n }\n const artifactKind = providerRuntime.artifactKind;\n if (artifactKind !== 'minions') {\n throw new Error(\n `Unsupported provider runtime artifactKind '${artifactKind}' for minion '${minionName}'.`,\n );\n }\n\n return this.selectMinionProviderRuntimeScope(providerRuntime, minionName);\n }\n\n private selectMinionProviderRuntimeScope(\n providerRuntime: MinionProviderRuntimeArtifact,\n minionName: string,\n ): ProviderRuntimeArtifact {\n const preScopedScope = (providerRuntime as MinionProviderRuntimeArtifact & {\n scope?: ProviderRuntimeArtifact['scope'];\n }).scope;\n const scopes = providerRuntime.scopes as\n | Record<string, ProviderRuntimeArtifact['scope']>\n | undefined;\n\n let scope: ProviderRuntimeArtifact['scope'] | undefined;\n\n if (preScopedScope && (!scopes || Object.keys(scopes).length === 0)) {\n // Shape 2 — the CLI-emitted per-minion module.\n scope = preScopedScope;\n } else if (scopes) {\n // Shape 3 — unscoped multi-scope artifact.\n scope = scopes[minionName];\n if (!scope) {\n throw new Error(\n `Provider runtime artifact does not contain a scope for minion '${minionName}'. `\n + `Re-run \\`wildo config sync\\` and verify the minion is declared in `\n + `wildo.saas.config.ts \\`providers.scopes.minions\\`.`,\n );\n }\n }\n\n if (!scope) {\n throw new Error(\n `Provider runtime artifact for minion '${minionName}' is missing both a `\n + `pre-scoped \\`scope\\` and a multi-scope \\`scopes\\` map. The artifact is malformed.`,\n );\n }\n\n // Recompute `providerRefs` from the projected per-host scope, NOT\n // from the multi-scope union the parent artifact carries. The\n // `buildMultiScopeArtifactMetadata` upstream computes\n // `providerRefs` as the union across all hosts; preserving that\n // here would make the boot-time `assertProviderRuntimeEnvInSync`\n // guard treat sibling-scope refs as \"this host has providers\" and\n // mistakenly run reconciliation on hosts whose own scope is empty.\n // Mirrors `selectScopedProviderRuntimeArtifact` in\n // `provider-runtime-artifacts.ts`.\n const projectedProviderRefs = Object.keys(scope.providers ?? {}).sort();\n // Narrowed with the refs, for the same reason (#330): the import map on a multi-scope artifact\n // is the union across every host, and handing this host a sibling's package specifiers would\n // tell it that it may load something it never declared.\n const projectedProviderRuntimeImports = Object.fromEntries(\n Object.entries(\n providerRuntime.providerRuntimeImports ?? {},\n ).filter(([providerRef]) => projectedProviderRefs.includes(providerRef)),\n );\n\n return {\n __AUTOGENERATED__: providerRuntime.__AUTOGENERATED__,\n generatedBy: providerRuntime.generatedBy,\n generatedAt: providerRuntime.generatedAt,\n sourceDigest: providerRuntime.sourceDigest,\n providerRefs: projectedProviderRefs,\n providerRuntimeImports: projectedProviderRuntimeImports,\n providerGraphDigest: providerRuntime.providerGraphDigest,\n lockfileSectionDigest: providerRuntime.lockfileSectionDigest,\n artifactKind: 'backend',\n modules: providerRuntime.modules,\n scope,\n };\n }\n}\n"]}
|