@jterrats/open-orchestra 1.0.16 → 1.0.17

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 (99) hide show
  1. package/CLAUDE.md +24 -2
  2. package/README.md +32 -9
  3. package/dist/benchmark.js +65 -27
  4. package/dist/benchmark.js.map +1 -1
  5. package/dist/metrics-commands.js +3 -0
  6. package/dist/metrics-commands.js.map +1 -1
  7. package/dist/runtime-bootstrap.js +33 -8
  8. package/dist/runtime-bootstrap.js.map +1 -1
  9. package/dist/runtime-capacity-policy.d.ts +38 -0
  10. package/dist/runtime-capacity-policy.js +117 -0
  11. package/dist/runtime-capacity-policy.js.map +1 -0
  12. package/dist/runtime-capacity-scheduler-helpers.d.ts +40 -0
  13. package/dist/runtime-capacity-scheduler-helpers.js +111 -0
  14. package/dist/runtime-capacity-scheduler-helpers.js.map +1 -0
  15. package/dist/runtime-capacity-scheduler-state.d.ts +44 -0
  16. package/dist/runtime-capacity-scheduler-state.js +128 -0
  17. package/dist/runtime-capacity-scheduler-state.js.map +1 -0
  18. package/dist/runtime-capacity-scheduler.d.ts +34 -0
  19. package/dist/runtime-capacity-scheduler.js +193 -0
  20. package/dist/runtime-capacity-scheduler.js.map +1 -0
  21. package/dist/runtime-capacity-snapshot.d.ts +14 -0
  22. package/dist/runtime-capacity-snapshot.js +87 -0
  23. package/dist/runtime-capacity-snapshot.js.map +1 -0
  24. package/dist/runtime-child-prompt.d.ts +2 -1
  25. package/dist/runtime-child-prompt.js +4 -1
  26. package/dist/runtime-child-prompt.js.map +1 -1
  27. package/dist/runtime-claude-native-bridge.js +2 -1
  28. package/dist/runtime-claude-native-bridge.js.map +1 -1
  29. package/dist/runtime-commands.js +6 -0
  30. package/dist/runtime-commands.js.map +1 -1
  31. package/dist/runtime-lifecycle-watch.d.ts +5 -2
  32. package/dist/runtime-lifecycle-watch.js +19 -3
  33. package/dist/runtime-lifecycle-watch.js.map +1 -1
  34. package/dist/runtime-load-balancer.d.ts +12 -0
  35. package/dist/runtime-load-balancer.js +106 -0
  36. package/dist/runtime-load-balancer.js.map +1 -0
  37. package/dist/runtime-spawn-bridge.js +23 -0
  38. package/dist/runtime-spawn-bridge.js.map +1 -1
  39. package/dist/runtime-spawn-guidance.js +15 -0
  40. package/dist/runtime-spawn-guidance.js.map +1 -1
  41. package/dist/runtime-worker-registry.d.ts +19 -0
  42. package/dist/runtime-worker-registry.js +84 -0
  43. package/dist/runtime-worker-registry.js.map +1 -0
  44. package/dist/security/content-classifier.d.ts +2 -0
  45. package/dist/security/content-classifier.js +147 -0
  46. package/dist/security/content-classifier.js.map +1 -0
  47. package/dist/security/operation-contract-types.d.ts +28 -0
  48. package/dist/security/operation-contract-types.js +2 -0
  49. package/dist/security/operation-contract-types.js.map +1 -0
  50. package/dist/security/operation-contract.d.ts +2 -0
  51. package/dist/security/operation-contract.js +169 -0
  52. package/dist/security/operation-contract.js.map +1 -0
  53. package/dist/security/policy-engine.d.ts +2 -0
  54. package/dist/security/policy-engine.js +142 -0
  55. package/dist/security/policy-engine.js.map +1 -0
  56. package/dist/security/policy-types.d.ts +79 -0
  57. package/dist/security/policy-types.js +7 -0
  58. package/dist/security/policy-types.js.map +1 -0
  59. package/dist/security/prompt-intake.d.ts +13 -0
  60. package/dist/security/prompt-intake.js +33 -0
  61. package/dist/security/prompt-intake.js.map +1 -0
  62. package/dist/security/redaction.d.ts +3 -0
  63. package/dist/security/redaction.js +64 -0
  64. package/dist/security/redaction.js.map +1 -0
  65. package/dist/security/sink-encoding.d.ts +6 -0
  66. package/dist/security/sink-encoding.js +40 -0
  67. package/dist/security/sink-encoding.js.map +1 -0
  68. package/dist/sprint-commands.js +33 -22
  69. package/dist/sprint-commands.js.map +1 -1
  70. package/dist/transcription-failures.d.ts +2 -0
  71. package/dist/transcription-failures.js +4 -0
  72. package/dist/transcription-failures.js.map +1 -0
  73. package/dist/transcription-media-preflight.d.ts +9 -0
  74. package/dist/transcription-media-preflight.js +147 -0
  75. package/dist/transcription-media-preflight.js.map +1 -0
  76. package/dist/transcription-request.d.ts +13 -0
  77. package/dist/transcription-request.js +150 -0
  78. package/dist/transcription-request.js.map +1 -0
  79. package/dist/transcription-source-policy.d.ts +4 -0
  80. package/dist/transcription-source-policy.js +43 -0
  81. package/dist/transcription-source-policy.js.map +1 -0
  82. package/dist/transcription-types.d.ts +161 -0
  83. package/dist/transcription-types.js +2 -0
  84. package/dist/transcription-types.js.map +1 -0
  85. package/dist/types/runtime.d.ts +147 -0
  86. package/dist/types.d.ts +3 -1
  87. package/dist/types.js +1 -0
  88. package/dist/types.js.map +1 -1
  89. package/dist/workflow-phase-planner.js +5 -3
  90. package/dist/workflow-phase-planner.js.map +1 -1
  91. package/dist/workflow-phases.js +5 -0
  92. package/dist/workflow-phases.js.map +1 -1
  93. package/dist/workflow-run-commands.js +89 -10
  94. package/dist/workflow-run-commands.js.map +1 -1
  95. package/docs/audio-video-transcription-skill.md +102 -70
  96. package/docs/runtime-adapters.md +7 -0
  97. package/docs/runtime-capacity.md +57 -0
  98. package/docs/security-saas-orchestrator.md +368 -0
  99. package/package.json +1 -1
@@ -0,0 +1,117 @@
1
+ export const LOCAL_RUNTIME_CAPACITY_SCOPE = {
2
+ platformId: "local",
3
+ tenantId: "local",
4
+ workspaceId: "local-workspace",
5
+ };
6
+ export const DEFAULT_RUNTIME_CAPACITY_UNIT = {
7
+ concurrencyUnits: 1,
8
+ };
9
+ export const DEFAULT_RUNTIME_QUOTA_POLICY = {
10
+ maxActive: 3,
11
+ maxQueued: 25,
12
+ maxActivePerProvider: 2,
13
+ maxActivePerRuntime: 3,
14
+ limitAction: "queue",
15
+ queueTtlMs: 30_000,
16
+ };
17
+ const WORKLOAD_CLASSES = [
18
+ "interactive",
19
+ "workflow-phase",
20
+ "runtime-native-spawn",
21
+ "provider-backed-phase",
22
+ "background-maintenance",
23
+ "evidence-processing",
24
+ ];
25
+ export function normalizeRuntimeScheduleRequest(request, mode, defaultScope = LOCAL_RUNTIME_CAPACITY_SCOPE) {
26
+ if (!request.scope && mode === "saas") {
27
+ return {
28
+ valid: false,
29
+ scope: defaultScope,
30
+ reasonCode: "rejected_missing_scope",
31
+ userSafeReason: "tenant and workspace scope are required",
32
+ };
33
+ }
34
+ const scope = request.scope ?? defaultScope;
35
+ if (!scope.platformId ||
36
+ !scope.tenantId ||
37
+ !scope.workspaceId ||
38
+ !WORKLOAD_CLASSES.includes(request.workloadClass) ||
39
+ !Number.isFinite(request.capacity.concurrencyUnits) ||
40
+ request.capacity.concurrencyUnits <= 0) {
41
+ return {
42
+ valid: false,
43
+ scope,
44
+ reasonCode: "rejected_invalid_request",
45
+ userSafeReason: "runtime capacity request is invalid",
46
+ };
47
+ }
48
+ return { valid: true, scope };
49
+ }
50
+ export function evaluateRuntimeCapacityLimits({ request, scope, counters, platformPolicy, tenantPolicy, workspacePolicy, }) {
51
+ const requestUnits = request.capacity.concurrencyUnits;
52
+ const checks = [
53
+ activeLimitCheck(sumActiveUnits(counters.active), requestUnits, platformPolicy.maxActive, "rejected_platform_limit", "platform runtime capacity is exhausted"),
54
+ activeLimitCheck(sumActiveUnits(counters.active.filter((item) => sameTenant(item, scope))), requestUnits, tenantPolicy.maxActive, "rejected_tenant_limit", "tenant runtime capacity is exhausted"),
55
+ activeLimitCheck(sumActiveUnits(counters.active.filter((item) => sameWorkspace(item, scope))), requestUnits, workspacePolicy.maxActive, "rejected_workspace_limit", "workspace runtime capacity is exhausted"),
56
+ providerLimitCheck(request, counters.active, tenantPolicy),
57
+ runtimeLimitCheck(request, counters.active, tenantPolicy),
58
+ ];
59
+ return checks.find((check) => !check.allowed) ?? { allowed: true };
60
+ }
61
+ export function canQueueRuntimeCapacity({ request, scope, counters, platformPolicy, tenantPolicy, workspacePolicy, }) {
62
+ const requestUnits = request.capacity.concurrencyUnits;
63
+ const checks = [
64
+ queuedLimitCheck(sumActiveUnits(counters.queued), requestUnits, platformPolicy.maxQueued, "rejected_queue_full", "platform runtime queue is full"),
65
+ queuedLimitCheck(sumActiveUnits(counters.queued.filter((item) => sameTenant(item, scope))), requestUnits, tenantPolicy.maxQueued, "rejected_tenant_limit", "tenant runtime queue is full"),
66
+ queuedLimitCheck(sumActiveUnits(counters.queued.filter((item) => sameWorkspace(item, scope))), requestUnits, workspacePolicy.maxQueued, "rejected_workspace_limit", "workspace runtime queue is full"),
67
+ ];
68
+ return checks.find((check) => !check.allowed) ?? { allowed: true };
69
+ }
70
+ export function queueReasonForLimit(reasonCode) {
71
+ if (reasonCode === "rejected_platform_limit")
72
+ return "queued_platform_limit";
73
+ if (reasonCode === "rejected_tenant_limit")
74
+ return "queued_tenant_limit";
75
+ if (reasonCode === "rejected_workspace_limit")
76
+ return "queued_workspace_limit";
77
+ if (reasonCode === "rejected_provider_limit")
78
+ return "queued_provider_limit";
79
+ if (reasonCode === "rejected_runtime_limit")
80
+ return "queued_runtime_limit";
81
+ return "queued_no_eligible_worker";
82
+ }
83
+ function activeLimitCheck(activeUnits, requestUnits, maxActive, reasonCode, userSafeReason) {
84
+ if (activeUnits + requestUnits <= maxActive)
85
+ return { allowed: true };
86
+ return { allowed: false, reasonCode, userSafeReason };
87
+ }
88
+ function queuedLimitCheck(queuedUnits, requestUnits, maxQueued, reasonCode, userSafeReason) {
89
+ if (queuedUnits + requestUnits <= maxQueued)
90
+ return { allowed: true };
91
+ return { allowed: false, reasonCode, userSafeReason };
92
+ }
93
+ function providerLimitCheck(request, active, policy) {
94
+ if (!request.provider || policy.maxActivePerProvider === undefined) {
95
+ return { allowed: true };
96
+ }
97
+ const activeUnits = sumActiveUnits(active.filter((item) => item.provider === request.provider));
98
+ return activeLimitCheck(activeUnits, request.capacity.concurrencyUnits, policy.maxActivePerProvider, "rejected_provider_limit", "provider runtime capacity is exhausted");
99
+ }
100
+ function runtimeLimitCheck(request, active, policy) {
101
+ if (!request.runtime || policy.maxActivePerRuntime === undefined) {
102
+ return { allowed: true };
103
+ }
104
+ const activeUnits = sumActiveUnits(active.filter((item) => item.runtime === request.runtime));
105
+ return activeLimitCheck(activeUnits, request.capacity.concurrencyUnits, policy.maxActivePerRuntime, "rejected_runtime_limit", "runtime capacity is exhausted");
106
+ }
107
+ function sameTenant(request, scope) {
108
+ return request.scope?.tenantId === scope.tenantId;
109
+ }
110
+ function sameWorkspace(request, scope) {
111
+ return (request.scope?.tenantId === scope.tenantId &&
112
+ request.scope.workspaceId === scope.workspaceId);
113
+ }
114
+ function sumActiveUnits(requests) {
115
+ return requests.reduce((total, request) => total + request.capacity.concurrencyUnits, 0);
116
+ }
117
+ //# sourceMappingURL=runtime-capacity-policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-capacity-policy.js","sourceRoot":"","sources":["../src/runtime-capacity-policy.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,MAAM,4BAA4B,GAAyB;IAChE,UAAU,EAAE,OAAO;IACnB,QAAQ,EAAE,OAAO;IACjB,WAAW,EAAE,iBAAiB;CAC/B,CAAC;AAEF,MAAM,CAAC,MAAM,6BAA6B,GAAwB;IAChE,gBAAgB,EAAE,CAAC;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,4BAA4B,GAAuB;IAC9D,SAAS,EAAE,CAAC;IACZ,SAAS,EAAE,EAAE;IACb,oBAAoB,EAAE,CAAC;IACvB,mBAAmB,EAAE,CAAC;IACtB,WAAW,EAAE,OAAO;IACpB,UAAU,EAAE,MAAM;CACnB,CAAC;AAoBF,MAAM,gBAAgB,GAA2B;IAC/C,aAAa;IACb,gBAAgB;IAChB,sBAAsB;IACtB,uBAAuB;IACvB,wBAAwB;IACxB,qBAAqB;CACtB,CAAC;AAEF,MAAM,UAAU,+BAA+B,CAC7C,OAA+B,EAC/B,IAAyB,EACzB,eAAqC,4BAA4B;IAEjE,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACtC,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,YAAY;YACnB,UAAU,EAAE,wBA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E,OAAO,EAAE,EAAE,CAAC,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,gBAAgB,EAC7D,CAAC,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,40 @@
1
+ import type { RuntimeCapacitySchedulerEvent, RuntimeCapacityScope, RuntimeLease, RuntimeQuotaPolicy, RuntimeScheduleDecision, RuntimeScheduleReasonCode, RuntimeScheduleRequest } from "./types.js";
2
+ export interface RuntimeCapacityQueuedRequest {
3
+ queueId: string;
4
+ request: RuntimeScheduleRequest;
5
+ enqueuedAt: number;
6
+ }
7
+ export declare function normalizeCapacityRequest({ request, defaultScope, tenantPolicy, }: {
8
+ request: RuntimeScheduleRequest;
9
+ defaultScope: RuntimeCapacityScope;
10
+ tenantPolicy: RuntimeQuotaPolicy;
11
+ }): RuntimeScheduleRequest;
12
+ export declare function sortQueuedRuntimeRequests(queue: RuntimeCapacityQueuedRequest[]): void;
13
+ export declare function optionalExpiresAt(request: RuntimeScheduleRequest): {
14
+ expiresAt: string;
15
+ } | Record<string, never>;
16
+ export declare function reasonForCode(reasonCode: RuntimeScheduleReasonCode): string;
17
+ export declare function createRuntimeScheduleDecision({ decisionId, status, request, reasonCode, userSafeReason, workerId, lease, queue, }: {
18
+ decisionId: string;
19
+ status: RuntimeScheduleDecision["status"];
20
+ request: RuntimeScheduleRequest;
21
+ reasonCode: RuntimeScheduleReasonCode;
22
+ userSafeReason: string;
23
+ workerId?: string;
24
+ lease?: RuntimeLease;
25
+ queue?: RuntimeScheduleDecision["queue"];
26
+ }): {
27
+ decision: RuntimeScheduleDecision;
28
+ event: RuntimeCapacitySchedulerEvent;
29
+ };
30
+ export declare function createRuntimeReleaseEvent({ decisionId, lease, leaseDurationMs, }: {
31
+ decisionId: string;
32
+ lease: RuntimeLease;
33
+ leaseDurationMs: number;
34
+ }): RuntimeCapacitySchedulerEvent;
35
+ export declare function createRuntimePromotedEvent({ decisionId, request, workerId, queueLatencyMs, }: {
36
+ decisionId: string;
37
+ request: RuntimeScheduleRequest;
38
+ workerId: string;
39
+ queueLatencyMs: number;
40
+ }): RuntimeCapacitySchedulerEvent;
@@ -0,0 +1,111 @@
1
+ import { DEFAULT_RUNTIME_CAPACITY_UNIT } from "./runtime-capacity-policy.js";
2
+ export function normalizeCapacityRequest({ request, defaultScope, tenantPolicy, }) {
3
+ return {
4
+ ...request,
5
+ scope: request.scope ?? defaultScope,
6
+ capacity: request.capacity ?? DEFAULT_RUNTIME_CAPACITY_UNIT,
7
+ queuePolicy: request.queuePolicy ?? {
8
+ priority: "normal",
9
+ limitAction: "queue",
10
+ ...(tenantPolicy.queueTtlMs
11
+ ? { maxQueueMs: tenantPolicy.queueTtlMs }
12
+ : {}),
13
+ },
14
+ };
15
+ }
16
+ export function sortQueuedRuntimeRequests(queue) {
17
+ queue.sort((left, right) => priorityWeight(right.request.queuePolicy?.priority) -
18
+ priorityWeight(left.request.queuePolicy?.priority) ||
19
+ left.request.scope.tenantId.localeCompare(right.request.scope.tenantId) ||
20
+ left.request.scope.workspaceId.localeCompare(right.request.scope.workspaceId) ||
21
+ left.enqueuedAt - right.enqueuedAt ||
22
+ left.queueId.localeCompare(right.queueId));
23
+ }
24
+ export function optionalExpiresAt(request) {
25
+ const ttl = request.queuePolicy?.maxQueueMs;
26
+ return ttl ? { expiresAt: new Date(Date.now() + ttl).toISOString() } : {};
27
+ }
28
+ export function reasonForCode(reasonCode) {
29
+ const reasons = {
30
+ admitted: "runtime capacity lease admitted",
31
+ queued_platform_limit: "queued until platform runtime capacity is available",
32
+ queued_tenant_limit: "queued until tenant runtime capacity is available",
33
+ queued_workspace_limit: "queued until workspace runtime capacity is available",
34
+ queued_provider_limit: "queued until provider runtime capacity is available",
35
+ queued_runtime_limit: "queued until runtime capacity is available",
36
+ queued_no_eligible_worker: "queued until an eligible runtime worker is available",
37
+ rejected_invalid_request: "runtime capacity request is invalid",
38
+ rejected_missing_scope: "tenant and workspace scope are required",
39
+ rejected_platform_limit: "platform runtime capacity is exhausted",
40
+ rejected_tenant_limit: "tenant runtime capacity is exhausted",
41
+ rejected_workspace_limit: "workspace runtime capacity is exhausted",
42
+ rejected_provider_limit: "provider runtime capacity is exhausted",
43
+ rejected_runtime_limit: "runtime capacity is exhausted",
44
+ rejected_queue_full: "runtime queue is full",
45
+ deferred_no_eligible_worker: "no eligible runtime worker is available",
46
+ };
47
+ return reasons[reasonCode];
48
+ }
49
+ export function createRuntimeScheduleDecision({ decisionId, status, request, reasonCode, userSafeReason, workerId, lease, queue, }) {
50
+ const decision = {
51
+ decisionId,
52
+ status,
53
+ scope: request.scope,
54
+ workloadClass: request.workloadClass,
55
+ reasonCode,
56
+ userSafeReason,
57
+ ...(workerId ? { workerId } : {}),
58
+ ...(lease ? { lease } : {}),
59
+ ...(queue ? { queue } : {}),
60
+ };
61
+ return {
62
+ decision,
63
+ event: {
64
+ decisionId,
65
+ type: status,
66
+ scope: request.scope,
67
+ workloadClass: request.workloadClass,
68
+ reasonCode,
69
+ timestamp: new Date().toISOString(),
70
+ ...(request.provider ? { provider: request.provider } : {}),
71
+ ...(request.runtime ? { runtime: request.runtime } : {}),
72
+ ...(workerId ? { workerId } : {}),
73
+ },
74
+ };
75
+ }
76
+ export function createRuntimeReleaseEvent({ decisionId, lease, leaseDurationMs, }) {
77
+ return {
78
+ decisionId,
79
+ type: "released",
80
+ scope: lease.scope,
81
+ workloadClass: lease.workloadClass,
82
+ workerId: lease.workerId,
83
+ reasonCode: "released",
84
+ leaseDurationMs,
85
+ timestamp: new Date().toISOString(),
86
+ ...(lease.provider ? { provider: lease.provider } : {}),
87
+ ...(lease.runtime ? { runtime: lease.runtime } : {}),
88
+ };
89
+ }
90
+ export function createRuntimePromotedEvent({ decisionId, request, workerId, queueLatencyMs, }) {
91
+ return {
92
+ decisionId,
93
+ type: "promoted",
94
+ scope: request.scope,
95
+ workloadClass: request.workloadClass,
96
+ workerId,
97
+ reasonCode: "admitted",
98
+ queueLatencyMs,
99
+ timestamp: new Date().toISOString(),
100
+ ...(request.provider ? { provider: request.provider } : {}),
101
+ ...(request.runtime ? { runtime: request.runtime } : {}),
102
+ };
103
+ }
104
+ function priorityWeight(priority = "normal") {
105
+ if (priority === "high")
106
+ return 3;
107
+ if (priority === "normal")
108
+ return 2;
109
+ return 1;
110
+ }
111
+ //# sourceMappingURL=runtime-capacity-scheduler-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-capacity-scheduler-helpers.js","sourceRoot":"","sources":["../src/runtime-capacity-scheduler-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AAiB7E,MAAM,UAAU,wBAAwB,CAAC,EACvC,OAAO,EACP,YAAY,EACZ,YAAY,GAKb;IACC,OAAO;QACL,GAAG,OAAO;QACV,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,YAAY;QACpC,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,6BAA6B;QAC3D,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI;YAClC,QAAQ,EAAE,QAAQ;YAClB,WAAW,EAAE,OAAO;YACpB,GAAG,CAAC,YAAY,CAAC,UAAU;gBACzB,CAAC,CAAC,EAAE,UAAU,EAAE,YAAY,CAAC,UAAU,EAAE;gBACzC,CAAC,CAAC,EAAE,CAAC;SACR;KACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,yBAAyB,CACvC,KAAqC;IAErC,KAAK,CAAC,IAAI,CACR,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CACd,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC;QACjD,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC;QACpD,IAAI,CAAC,OAAO,CAAC,KAAM,CAAC,QAAQ,CAAC,aAAa,CACxC,KAAK,CAAC,OAAO,CAAC,KAAM,CAAC,QAAQ,CAC9B;QACD,IAAI,CAAC,OAAO,CAAC,KAAM,CAAC,WAAW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from "./runtime-capacity-policy.js";
3
+ import type { RuntimeWorkerRegistry } from "./runtime-worker-registry.js";
4
+ import type { RuntimeCapacitySchedulerEvent, RuntimeCapacityScope, RuntimeLease, RuntimeScheduleDecision, RuntimeScheduleReasonCode, RuntimeScheduleRequest } from "./types.js";
5
+ export type RuntimeLeaseRecord = {
6
+ request: RuntimeScheduleRequest;
7
+ lease: RuntimeLease;
8
+ startedAt: number;
9
+ };
10
+ export declare class RuntimeCapacitySchedulerState {
11
+ private readonly queue;
12
+ private readonly leases;
13
+ private readonly events;
14
+ private rejected;
15
+ private nextDecision;
16
+ private nextQueue;
17
+ private nextLease;
18
+ activeRecords(): RuntimeLeaseRecord[];
19
+ queuedRequests(): RuntimeCapacityQueuedRequest[];
20
+ rejectedCount(): number;
21
+ counters(): RuntimeCapacityCounters;
22
+ drainEvents(): RuntimeCapacitySchedulerEvent[];
23
+ releaseLease(leaseId: string, registry: RuntimeWorkerRegistry): RuntimeLeaseRecord | undefined;
24
+ admit(request: RuntimeScheduleRequest, workerId: string, registry: RuntimeWorkerRegistry): RuntimeScheduleDecision;
25
+ queueRequest(request: RuntimeScheduleRequest, reasonCode: RuntimeScheduleReasonCode): RuntimeScheduleDecision;
26
+ reject(request: RuntimeScheduleRequest, scope: RuntimeCapacityScope, reasonCode: RuntimeScheduleReasonCode, userSafeReason: string): RuntimeScheduleDecision;
27
+ decision({ status, request, reasonCode, userSafeReason, workerId, lease, queue, }: {
28
+ status: RuntimeScheduleDecision["status"];
29
+ request: RuntimeScheduleRequest;
30
+ reasonCode: RuntimeScheduleReasonCode;
31
+ userSafeReason: string;
32
+ workerId?: string;
33
+ lease?: RuntimeLease;
34
+ queue?: RuntimeScheduleDecision["queue"];
35
+ }): RuntimeScheduleDecision;
36
+ sortQueue(): void;
37
+ removeQueuedAt(index: number): void;
38
+ recordPromoted({ decision, queued, workerId, }: {
39
+ decision: RuntimeScheduleDecision;
40
+ queued: RuntimeCapacityQueuedRequest;
41
+ workerId: string;
42
+ }): void;
43
+ private nextDecisionId;
44
+ }
@@ -0,0 +1,128 @@
1
+ import { createRuntimePromotedEvent, createRuntimeReleaseEvent, createRuntimeScheduleDecision, optionalExpiresAt, reasonForCode, sortQueuedRuntimeRequests, } from "./runtime-capacity-scheduler-helpers.js";
2
+ export class RuntimeCapacitySchedulerState {
3
+ queue = [];
4
+ leases = new Map();
5
+ events = [];
6
+ rejected = 0;
7
+ nextDecision = 0;
8
+ nextQueue = 0;
9
+ nextLease = 0;
10
+ activeRecords() {
11
+ return [...this.leases.values()];
12
+ }
13
+ queuedRequests() {
14
+ return this.queue;
15
+ }
16
+ rejectedCount() {
17
+ return this.rejected;
18
+ }
19
+ counters() {
20
+ return {
21
+ active: this.activeRecords().map((record) => record.request),
22
+ queued: this.queue.map((item) => item.request),
23
+ };
24
+ }
25
+ drainEvents() {
26
+ return this.events.splice(0);
27
+ }
28
+ releaseLease(leaseId, registry) {
29
+ const record = this.leases.get(leaseId);
30
+ if (!record)
31
+ return undefined;
32
+ this.leases.delete(leaseId);
33
+ registry.releaseWorkerCapacity(record.lease.workerId, record.lease.capacity);
34
+ this.events.push(createRuntimeReleaseEvent({
35
+ decisionId: this.nextDecisionId(),
36
+ lease: record.lease,
37
+ leaseDurationMs: Date.now() - record.startedAt,
38
+ }));
39
+ return record;
40
+ }
41
+ admit(request, workerId, registry) {
42
+ const lease = {
43
+ leaseId: `lease-${this.nextLease++}`,
44
+ workerId,
45
+ scope: request.scope,
46
+ workloadClass: request.workloadClass,
47
+ capacity: request.capacity,
48
+ expiresAt: new Date(Date.now() + (request.leaseTtlMs ?? 30_000)).toISOString(),
49
+ ...(request.provider ? { provider: request.provider } : {}),
50
+ ...(request.runtime ? { runtime: request.runtime } : {}),
51
+ };
52
+ registry.reserveWorkerCapacity(workerId, request.capacity);
53
+ this.leases.set(lease.leaseId, {
54
+ request,
55
+ lease,
56
+ startedAt: Date.now(),
57
+ });
58
+ return this.decision({
59
+ status: "admitted",
60
+ request,
61
+ reasonCode: "admitted",
62
+ userSafeReason: "runtime capacity lease admitted",
63
+ workerId,
64
+ lease,
65
+ });
66
+ }
67
+ queueRequest(request, reasonCode) {
68
+ const queueId = `queue-${this.nextQueue++}`;
69
+ this.queue.push({ queueId, request, enqueuedAt: Date.now() });
70
+ this.sortQueue();
71
+ const position = this.queue.findIndex((item) => item.queueId === queueId);
72
+ return this.decision({
73
+ status: "queued",
74
+ request,
75
+ reasonCode,
76
+ userSafeReason: reasonForCode(reasonCode),
77
+ queue: {
78
+ queueId,
79
+ position: position + 1,
80
+ reasonCode,
81
+ retryAfterMs: 1_000,
82
+ ...optionalExpiresAt(request),
83
+ },
84
+ });
85
+ }
86
+ reject(request, scope, reasonCode, userSafeReason) {
87
+ this.rejected += 1;
88
+ return this.decision({
89
+ status: "rejected",
90
+ request: { ...request, scope },
91
+ reasonCode,
92
+ userSafeReason,
93
+ });
94
+ }
95
+ decision({ status, request, reasonCode, userSafeReason, workerId, lease, queue, }) {
96
+ const decisionId = this.nextDecisionId();
97
+ const { decision, event } = createRuntimeScheduleDecision({
98
+ decisionId,
99
+ status,
100
+ request,
101
+ reasonCode,
102
+ userSafeReason,
103
+ ...(workerId ? { workerId } : {}),
104
+ ...(lease ? { lease } : {}),
105
+ ...(queue ? { queue } : {}),
106
+ });
107
+ this.events.push(event);
108
+ return decision;
109
+ }
110
+ sortQueue() {
111
+ sortQueuedRuntimeRequests(this.queue);
112
+ }
113
+ removeQueuedAt(index) {
114
+ this.queue.splice(index, 1);
115
+ }
116
+ recordPromoted({ decision, queued, workerId, }) {
117
+ this.events.push(createRuntimePromotedEvent({
118
+ decisionId: decision.decisionId,
119
+ request: queued.request,
120
+ workerId,
121
+ queueLatencyMs: Date.now() - queued.enqueuedAt,
122
+ }));
123
+ }
124
+ nextDecisionId() {
125
+ return `decision-${this.nextDecision++}`;
126
+ }
127
+ }
128
+ //# sourceMappingURL=runtime-capacity-scheduler-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-capacity-schedu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Mode } from "./runtime-capacity-policy.js";
2
+ import { type RuntimeWorkerRegistry } from "./runtime-worker-registry.js";
3
+ import type { RuntimeCapacitySchedulerEvent, RuntimeCapacityScope, RuntimeCapacitySnapshot, RuntimeQuotaPolicy, RuntimeScheduleDecision, RuntimeScheduleRequest } from "./types.js";
4
+ export interface RuntimeCapacitySchedulerOptions {
5
+ mode?: RuntimeCapacityMode;
6
+ defaultScope?: RuntimeCapacityScope;
7
+ platformPolicy?: RuntimeQuotaPolicy;
8
+ tenantPolicy?: RuntimeQuotaPolicy;
9
+ workspacePolicy?: RuntimeQuotaPolicy;
10
+ registry?: RuntimeWorkerRegistry;
11
+ }
12
+ export declare class RuntimeCapacityScheduler {
13
+ private readonly mode;
14
+ private readonly defaultScope;
15
+ private readonly platformPolicy;
16
+ private readonly tenantPolicy;
17
+ private readonly workspacePolicy;
18
+ private readonly registry;
19
+ private readonly state;
20
+ constructor(options?: RuntimeCapacitySchedulerOptions);
21
+ schedule(request: RuntimeScheduleRequest): RuntimeScheduleDecision;
22
+ release(leaseId: string): RuntimeScheduleDecision[];
23
+ drainQueued(): RuntimeScheduleDecision[];
24
+ snapshot(scope?: RuntimeCapacityScope): RuntimeCapacitySnapshot;
25
+ drainEvents(): RuntimeCapacitySchedulerEvent[];
26
+ private normalizeRequest;
27
+ private queueOrRejectLimit;
28
+ private queueOrDefer;
29
+ private shouldQueue;
30
+ private scheduleQueued;
31
+ private queueDepthByWorker;
32
+ private effectiveTenantPolicy;
33
+ private effectiveWorkspacePolicy;
34
+ }