@treeseed/sdk 0.13.0-rc.119 → 0.13.0-rc.120

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 (53) hide show
  1. package/dist/.treeseed-build-complete.json +1 -1
  2. package/dist/agent-capacity/allocation.d.ts +0 -3
  3. package/dist/agent-capacity/allocation.js +0 -221
  4. package/dist/agent-capacity/contracts/capacity/assignments/agent-execution.d.ts +280 -84
  5. package/dist/agent-capacity/contracts/capacity/assignments/agent-execution.js +22 -1
  6. package/dist/agent-capacity/contracts/capacity/assignments/assignment-records.d.ts +5 -0
  7. package/dist/agent-capacity/contracts/capacity/workdays/assignment-allocation.d.ts +82 -0
  8. package/dist/agent-capacity/contracts/capacity/workdays/assignment-allocation.js +115 -0
  9. package/dist/agent-capacity/contracts/capacity/workdays/capability-accounting.d.ts +142 -0
  10. package/dist/agent-capacity/contracts/capacity/workdays/capability-accounting.js +51 -0
  11. package/dist/agent-capacity/contracts/capacity/workdays/workday-allocation.d.ts +167 -35
  12. package/dist/agent-capacity/contracts/capacity/workdays/workday-allocation.js +59 -20
  13. package/dist/agent-capacity/contracts/capacity/workdays/workday-records.d.ts +2 -21
  14. package/dist/agent-capacity/contracts/support/execution-graph.d.ts +18 -18
  15. package/dist/agent-capacity/contracts/support/time-capacity.d.ts +0 -14
  16. package/dist/agent-capacity/contracts/support/time-capacity.js +1 -8
  17. package/dist/agent-capacity/validation/agent-definition-schema.d.ts +338 -338
  18. package/dist/capacity/agents/agent-capacity.d.ts +2 -0
  19. package/dist/capacity/agents/agent-capacity.js +2 -0
  20. package/dist/capacity-provider/client.d.ts +5 -3
  21. package/dist/capacity-provider/contracts/capacity-facts.d.ts +14 -0
  22. package/dist/capacity-provider/contracts/governance.d.ts +6 -0
  23. package/dist/capacity-provider/sandbox-contracts.d.ts +55 -1
  24. package/dist/capacity-provider/sandbox-contracts.js +4 -0
  25. package/dist/capacity-provider/source-workspace.d.ts +69 -37
  26. package/dist/capacity-provider/source-workspace.js +36 -5
  27. package/dist/content/validation/auxiliary-content-schemas.d.ts +10 -10
  28. package/dist/content/validation/content-model-schemas.d.ts +613 -613
  29. package/dist/content/validation/content-model-schemas.js +14 -2
  30. package/dist/content/validation/portable-content-data.d.ts +22 -22
  31. package/dist/deployment/postgres/requirements.d.ts +3 -2
  32. package/dist/deployment/postgres/requirements.js +3 -1
  33. package/dist/operator-contracts/canonical-command-tree.js +20 -6
  34. package/dist/operator-contracts/catalog/communication-operations.d.ts +2 -0
  35. package/dist/operator-contracts/catalog/workdays/profile-commands.js +4 -4
  36. package/dist/operator-contracts/catalog/workdays/profile-operations.d.ts +28 -3
  37. package/dist/operator-contracts/catalog/workdays/profile-operations.js +10 -8
  38. package/dist/operator-contracts/catalog/workdays/selection-commands.js +13 -0
  39. package/dist/operator-contracts/command-tree.d.ts +1 -1
  40. package/dist/operator-contracts/communication/contracts.d.ts +6 -0
  41. package/dist/operator-contracts/communication/contracts.js +2 -0
  42. package/dist/operator-contracts/control-plane-operations.d.ts +34 -3
  43. package/dist/operator-contracts/control-plane-operations.js +1 -0
  44. package/dist/operator-contracts/index.d.ts +0 -1
  45. package/dist/operator-contracts/index.js +0 -1
  46. package/dist/operator-contracts/workday-lifecycle.d.ts +8 -20
  47. package/dist/operator-contracts/workday-lifecycle.js +15 -5
  48. package/dist/secrets-capability/shared-resources.d.ts +6 -6
  49. package/package.json +1 -1
  50. package/dist/agent-capacity/policy/capacity/allocations/allocation-hierarchy.d.ts +0 -29
  51. package/dist/agent-capacity/policy/capacity/allocations/allocation-hierarchy.js +0 -110
  52. package/dist/operator-contracts/workday-profile.d.ts +0 -72
  53. package/dist/operator-contracts/workday-profile.js +0 -106
@@ -1 +1 @@
1
- {"completedAt":"2026-09-15T06:29:47.641Z"}
1
+ {"completedAt":"2026-09-19T16:34:57.882Z"}
@@ -181,6 +181,3 @@ export interface CapacityAdmissionCounterClaim {
181
181
  }
182
182
  export { validateCapacityAllocationSetV2, validateCapacityGrantV2 } from './validation/allocation.js';
183
183
  export type { CapacityAllocationDiagnostic, CapacityAllocationValidation } from './validation/allocation.js';
184
- export declare function timestamp(value: string | null | undefined): number | null;
185
- export declare function firstReason(reasons: CapacityAdmissionReasonCode[]): CapacityAdmissionReasonCode;
186
- export declare function evaluateCapacityAdmission(input: CapacityAdmissionInput): CapacityAdmissionDecision;
@@ -1,226 +1,5 @@
1
1
  import { validateCapacityAllocationSetV2, validateCapacityGrantV2 } from "./validation/allocation.js";
2
- function timestamp(value) {
3
- const parsed = value ? Date.parse(value) : Number.NaN;
4
- return Number.isFinite(parsed) ? parsed : null;
5
- }
6
- function firstReason(reasons) {
7
- return reasons[0] ?? "allowed";
8
- }
9
- function evaluateCapacityAdmission(input) {
10
- const reasons = [];
11
- const explanation = [];
12
- let remaining = Number.POSITIVE_INFINITY;
13
- let requiresApproval = false;
14
- let allocationCalculations = {};
15
- let allocationPriorityBand = "overflow";
16
- let allocationPriorityScore = 0;
17
- const counterClaims = [];
18
- const deny = (gate, code, detail) => {
19
- reasons.push(code);
20
- explanation.push({ gate, allowed: false, detail });
21
- };
22
- const allow = (gate, gateRemaining, detail) => {
23
- if (gateRemaining !== void 0) remaining = Math.min(remaining, Math.max(0, gateRemaining));
24
- explanation.push({ gate, allowed: true, remaining: gateRemaining, detail });
25
- };
26
- const now = timestamp(input.now) ?? Date.now();
27
- const request = input.request;
28
- const requestedTokens = Number(request.budget?.tokens.hardLimitTokens ?? 0);
29
- const requestedCost = Number(request.budget?.cost?.hardLimitAmount ?? 0);
30
- const requestedNative = (request.budget?.native ?? []).filter((entry) => entry.cap != null).map((entry) => ({ unit: entry.unit, amount: Number(entry.cap) }));
31
- if (!Number.isFinite(request.requestedSeconds) || request.requestedSeconds <= 0) deny("request", "requested_seconds_invalid");
32
- if (requestedTokens < 0 || requestedCost < 0 || requestedNative.some((entry) => !entry.unit || !Number.isFinite(entry.amount) || entry.amount < 0)) deny("request-budget", "requested_budget_invalid");
33
- if (input.membership.status !== "approved") deny("membership", input.membership.status === "suspended" ? "membership_suspended" : input.membership.status === "revoked" ? "membership_revoked" : "membership_not_approved");
34
- else allow("membership");
35
- if (input.membership.id !== request.membershipId) deny("membership-id", "membership_id_mismatch");
36
- else allow("membership-id");
37
- if (input.membership.teamId !== request.teamId) deny("membership-team", "membership_team_mismatch");
38
- else allow("membership-team");
39
- if (input.membership.providerId !== request.providerId) deny("membership-provider", "membership_provider_mismatch");
40
- else allow("membership-provider");
41
- if (input.availability.status !== "open") deny("availability", "availability_session_not_open");
42
- else if ((timestamp(input.availability.availableFrom) ?? Number.POSITIVE_INFINITY) > now || input.availability.availableUntil && (timestamp(input.availability.availableUntil) ?? 0) <= now) deny("availability", "outside_availability_window");
43
- else allow("availability");
44
- const grant = input.grant;
45
- if (!grant || grant.status !== "active") deny("grant", "missing_active_grant");
46
- else {
47
- if (grant.membershipId !== request.membershipId) deny("grant-membership", "grant_membership_mismatch");
48
- else allow("grant-membership");
49
- if (grant.teamId !== request.teamId) deny("grant-team", "grant_team_mismatch");
50
- else allow("grant-team");
51
- if (grant.providerId !== request.providerId) deny("grant-provider", "grant_provider_mismatch");
52
- else allow("grant-provider");
53
- if (grant.expiresAt && (timestamp(grant.expiresAt) ?? 0) <= now) deny("grant-expiry", "grant_expired");
54
- else allow("grant-expiry");
55
- if (grant.projectId !== request.projectId) deny("grant-project", "grant_project_mismatch");
56
- else allow("grant-project");
57
- if (grant.environment !== request.environment) deny("grant-environment", "grant_environment_mismatch");
58
- else allow("grant-environment");
59
- if (!grant.allowedModes.includes(request.mode)) deny("grant-mode", "grant_mode_denied");
60
- else allow("grant-mode");
61
- const missing = request.requiredCapabilities.filter((capability) => !grant.capabilities.includes(capability));
62
- if (missing.length) deny("grant-capabilities", "grant_capability_missing", missing.join(", "));
63
- else allow("grant-capabilities");
64
- if (request.executionProviderId && grant.executionProviderIds.length && !grant.executionProviderIds.includes(request.executionProviderId)) deny("grant-execution-provider", "grant_execution_provider_denied");
65
- else allow("grant-execution-provider");
66
- if (request.laneId && grant.laneIds.length && !grant.laneIds.includes(request.laneId)) deny("grant-lane", "grant_lane_denied");
67
- else allow("grant-lane");
68
- if (!grant.unmetered && grant.dailyAgentSecondsLimit == null && grant.monthlyAgentSecondsLimit == null) deny("grant-time", "grant_time_exhausted", "Grant must declare agent-time limits or explicit unmetered capacity.");
69
- if (grant.dailyAgentSecondsLimit != null) {
70
- const available = grant.dailyAgentSecondsLimit - input.grantCommitted.dailyAgentSeconds;
71
- if (available <= 0) deny("grant-daily", "grant_time_exhausted");
72
- else allow("grant-daily", available);
73
- counterClaims.push({ id: `grant-daily:${grant.id}:${input.now.slice(0, 10)}`, scope: "grant-daily", scopeId: grant.id, periodKey: input.now.slice(0, 10), hardLimit: grant.dailyAgentSecondsLimit, amount: request.requestedSeconds, release: "settlement-difference" });
74
- }
75
- if (grant.monthlyAgentSecondsLimit != null) {
76
- const available = grant.monthlyAgentSecondsLimit - input.grantCommitted.monthlyAgentSeconds;
77
- if (available <= 0) deny("grant-monthly", "grant_time_exhausted");
78
- else allow("grant-monthly", available);
79
- counterClaims.push({ id: `grant-monthly:${grant.id}:${input.now.slice(0, 7)}`, scope: "grant-monthly", scopeId: grant.id, periodKey: input.now.slice(0, 7), hardLimit: grant.monthlyAgentSecondsLimit, amount: request.requestedSeconds, release: "settlement-difference" });
80
- }
81
- if (grant.maxConcurrentAssignments != null) {
82
- const available = grant.maxConcurrentAssignments - input.grantCommitted.activeAssignments;
83
- if (available < 1) deny("grant-concurrency", "grant_concurrency_exhausted");
84
- else allow("grant-concurrency");
85
- counterClaims.push({ id: `grant-concurrency:${grant.id}:active`, scope: "grant-concurrency", scopeId: grant.id, periodKey: "active", hardLimit: grant.maxConcurrentAssignments, amount: 1, release: "assignment-terminal", dimension: "concurrency" });
86
- }
87
- const tokenLimit = Number(grant.budgetLimits?.tokens ?? Number.NaN);
88
- if (requestedTokens > 0 && Number.isFinite(tokenLimit)) {
89
- const available = tokenLimit - Number(input.grantCommitted.tokens ?? 0);
90
- if (available < requestedTokens) deny("grant-token", "grant_token_exhausted");
91
- else allow("grant-token", available);
92
- counterClaims.push({ id: `grant-token:${grant.id}:lifetime`, scope: "grant-token", scopeId: grant.id, periodKey: "lifetime", hardLimit: tokenLimit, amount: requestedTokens, release: "settlement-difference", dimension: "tokens" });
93
- }
94
- const costLimit = Number(grant.budgetLimits?.cost?.amount ?? Number.NaN);
95
- if (requestedCost > 0 && Number.isFinite(costLimit)) {
96
- const available = costLimit - Number(input.grantCommitted.cost ?? 0);
97
- if (available < requestedCost) deny("grant-cost", "grant_cost_exhausted");
98
- else allow("grant-cost", available);
99
- counterClaims.push({ id: `grant-cost:${grant.id}:${grant.budgetLimits?.cost?.currency ?? "USD"}`, scope: "grant-cost", scopeId: grant.id, periodKey: grant.budgetLimits?.cost?.currency ?? "USD", hardLimit: costLimit, amount: requestedCost, release: "settlement-difference", dimension: "cost", unit: grant.budgetLimits?.cost?.currency ?? "USD" });
100
- }
101
- for (const native of requestedNative) {
102
- const limit = grant.budgetLimits?.native?.find((entry) => entry.unit === native.unit)?.amount;
103
- if (limit == null) continue;
104
- const available = limit - Number(input.grantCommitted.native?.[native.unit] ?? 0);
105
- if (available < native.amount) deny(`grant-native:${native.unit}`, "grant_native_exhausted");
106
- else allow(`grant-native:${native.unit}`, available);
107
- counterClaims.push({ id: `grant-native:${grant.id}:${native.unit}`, scope: "grant-native", scopeId: grant.id, periodKey: native.unit, hardLimit: limit, amount: native.amount, release: "settlement-difference", dimension: "native", unit: native.unit });
108
- }
109
- }
110
- if (input.workday.status !== "active") deny("workday", "workday_not_active");
111
- else {
112
- const available = input.workday.totalSeconds - input.workday.committedSeconds;
113
- if (available <= 0) deny("workday-budget", "workday_budget_exhausted");
114
- else allow("workday-budget", available);
115
- counterClaims.push({ id: `workday:${input.workday.id}:lifetime`, scope: "workday", scopeId: input.workday.id, periodKey: "lifetime", hardLimit: input.workday.totalSeconds, amount: request.requestedSeconds, release: "settlement-difference" });
116
- }
117
- const allocation = input.allocationSet;
118
- if (!allocation || allocation.status !== "active") deny("allocation", "allocation_set_not_active");
119
- else if (allocation.teamId !== request.teamId) deny("allocation", "allocation_team_mismatch");
120
- else if ((timestamp(allocation.effectiveFrom) ?? Number.POSITIVE_INFINITY) > now || allocation.effectiveUntil && (timestamp(allocation.effectiveUntil) ?? 0) <= now) deny("allocation", "allocation_set_not_effective");
121
- else {
122
- allow("allocation");
123
- const hierarchy = evaluateAllocationHierarchy({
124
- allocation,
125
- workdayId: input.workday.id,
126
- totalSeconds: input.workday.totalSeconds,
127
- requestedSeconds: request.requestedSeconds,
128
- selectedSliceIds: input.allocationSliceIds,
129
- committedBySlice: input.committedSecondsBySlice,
130
- committedBorrowedByRule: input.committedBorrowedSecondsByRule,
131
- reserveCommittedSeconds: input.reserveCommittedSeconds,
132
- approvedBorrowingRuleIds: input.approvedBorrowingRuleIds
133
- });
134
- reasons.push(...hierarchy.reasons);
135
- explanation.push(...hierarchy.explanation);
136
- counterClaims.push(...hierarchy.counterClaims);
137
- remaining = Math.min(remaining, hierarchy.maxReservableSeconds);
138
- requiresApproval ||= hierarchy.requiresApproval;
139
- allocationCalculations = hierarchy.calculations;
140
- allocationPriorityBand = hierarchy.priorityBand;
141
- allocationPriorityScore = hierarchy.priorityScore;
142
- }
143
- if (input.providerCapacity.availableConcurrentAssignments < 1 || input.providerCapacity.availableAgentSeconds <= 0) deny("provider-capacity", "provider_capacity_exhausted");
144
- else {
145
- allow("provider-capacity", input.providerCapacity.availableAgentSeconds);
146
- const period = input.availability.availableFrom;
147
- counterClaims.push(
148
- { id: `provider-time:${request.providerId}:${period}`, scope: "provider-time", scopeId: request.providerId, periodKey: period, hardLimit: input.providerCapacity.availableAgentSeconds, amount: request.requestedSeconds, release: "settlement-difference", dimension: "time" },
149
- { id: `provider-concurrency:${request.providerId}:${period}`, scope: "provider-concurrency", scopeId: request.providerId, periodKey: period, hardLimit: input.providerCapacity.availableConcurrentAssignments, amount: 1, release: "assignment-terminal", dimension: "concurrency" }
150
- );
151
- }
152
- const advertisedCapabilities = input.providerCapacity.capabilities;
153
- if (advertisedCapabilities) {
154
- const missing = request.requiredCapabilities.filter((capability) => !advertisedCapabilities.includes(capability));
155
- if (missing.length) deny("provider-capabilities", "provider_capability_missing", missing.join(", "));
156
- else allow("provider-capabilities");
157
- }
158
- if (input.providerLocalLimits.availableConcurrentAssignments < 1 || input.providerLocalLimits.availableAgentSeconds <= 0) deny("provider-local", "provider_local_limit_exhausted");
159
- else {
160
- allow("provider-local", input.providerLocalLimits.availableAgentSeconds);
161
- const period = input.availability.availableFrom;
162
- counterClaims.push(
163
- { id: `provider-local-time:${request.providerId}:${period}`, scope: "provider-local-time", scopeId: request.providerId, periodKey: period, hardLimit: input.providerLocalLimits.availableAgentSeconds, amount: request.requestedSeconds, release: "settlement-difference", dimension: "time" },
164
- { id: `provider-local-concurrency:${request.providerId}:${period}`, scope: "provider-local-concurrency", scopeId: request.providerId, periodKey: period, hardLimit: input.providerLocalLimits.availableConcurrentAssignments, amount: 1, release: "assignment-terminal", dimension: "concurrency" }
165
- );
166
- }
167
- for (const [scope, available] of [["provider-token", input.providerCapacity.availableTokens], ["provider-local-token", input.providerLocalLimits.availableTokens]]) if (requestedTokens > 0 && available != null) {
168
- if (available < requestedTokens) deny(scope, "provider_budget_exhausted");
169
- counterClaims.push({ id: `${scope}:${request.providerId}:${input.availability.availableFrom}`, scope, scopeId: request.providerId, periodKey: input.availability.availableFrom, hardLimit: available, amount: requestedTokens, release: "settlement-difference", dimension: "tokens" });
170
- }
171
- for (const [scope, available] of [["provider-cost", input.providerCapacity.availableCost], ["provider-local-cost", input.providerLocalLimits.availableCost]]) if (requestedCost > 0 && available != null) {
172
- if (available < requestedCost) deny(scope, "provider_budget_exhausted");
173
- counterClaims.push({ id: `${scope}:${request.providerId}:${input.availability.availableFrom}`, scope, scopeId: request.providerId, periodKey: input.availability.availableFrom, hardLimit: available, amount: requestedCost, release: "settlement-difference", dimension: "cost", unit: request.budget?.cost?.currency ?? "USD" });
174
- }
175
- for (const native of requestedNative) for (const [scope, available] of [["provider-native", input.providerCapacity.availableNative?.[native.unit]], ["provider-local-native", input.providerLocalLimits.availableNative?.[native.unit]]]) if (available != null) {
176
- if (available < native.amount) deny(`${scope}:${native.unit}`, "provider_budget_exhausted");
177
- counterClaims.push({ id: `${scope}:${request.providerId}:${input.availability.availableFrom}:${native.unit}`, scope, scopeId: request.providerId, periodKey: native.unit, hardLimit: available, amount: native.amount, release: "settlement-difference", dimension: "native", unit: native.unit });
178
- }
179
- if (request.mode === "acting") {
180
- if (!input.acting?.decisionApproved) deny("acting-decision", "acting_decision_not_approved");
181
- else allow("acting-decision");
182
- if (!input.acting?.readinessReady) deny("acting-readiness", "acting_readiness_not_ready");
183
- else allow("acting-readiness");
184
- if (!input.acting?.capacityPlanAccepted) deny("acting-capacity-plan", "acting_capacity_plan_not_accepted");
185
- else allow("acting-capacity-plan");
186
- }
187
- if (remaining <= 0 && !reasons.includes("grant_time_exhausted") && !reasons.includes("workday_budget_exhausted") && !reasons.includes("allocation_hard_cap_exhausted")) reasons.push("allocation_hard_cap_exhausted");
188
- const maxReservableSeconds = Number.isFinite(remaining) ? Math.max(0, remaining) : 0;
189
- const allowed = reasons.length === 0 && maxReservableSeconds >= request.requestedSeconds;
190
- if (!allowed && reasons.length === 0) reasons.push("allocation_hard_cap_exhausted");
191
- return {
192
- allowed,
193
- reasonCode: firstReason(reasons),
194
- reasonCodes: reasons,
195
- maxReservableSeconds,
196
- requiresApproval,
197
- allocationPriorityBand,
198
- allocationPriorityScore,
199
- grantId: grant?.id ?? null,
200
- allocationSetId: allocation?.id ?? null,
201
- allocationVersion: allocation?.version ?? null,
202
- counterClaims,
203
- policySnapshot: {
204
- allocationSetId: allocation?.id ?? null,
205
- allocationVersion: allocation?.version ?? null,
206
- grantId: grant?.id ?? null,
207
- allocationSliceIds: [...input.allocationSliceIds],
208
- requestedSeconds: request.requestedSeconds,
209
- budget: request.budget ?? null,
210
- laneId: request.laneId ?? null,
211
- counterClaims,
212
- calculations: allocationCalculations,
213
- allocationPriorityBand,
214
- allocationPriorityScore
215
- },
216
- explanation
217
- };
218
- }
219
- import { evaluateAllocationHierarchy } from "./policy/capacity/allocations/allocation-hierarchy.js";
220
2
  export {
221
- evaluateCapacityAdmission,
222
- firstReason,
223
- timestamp,
224
3
  validateCapacityAllocationSetV2,
225
4
  validateCapacityGrantV2
226
5
  };