@treeseed/sdk 0.8.11 → 0.8.12
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/README.md +7 -0
- package/dist/capacity.d.ts +233 -1
- package/dist/capacity.js +1227 -44
- package/dist/control-plane.d.ts +2 -1
- package/dist/control-plane.js +7 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +61 -1
- package/dist/operations/services/d1-migration.js +27 -0
- package/dist/sdk-types.d.ts +231 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,6 +23,7 @@ If you are unsure, use `AgentSdk`.
|
|
|
23
23
|
- generic model reads and mutations across content-backed and D1-backed models
|
|
24
24
|
- operational runtime state such as messages, runs, cursors, and leases
|
|
25
25
|
- control-plane orchestration for work days, tasks, task events, graph runs, and reports
|
|
26
|
+
- provider-neutral capacity scheduling contracts for task classification, admission, execution profiles, routing, estimates, planning proposals, attention load, utility, predictive reserve, hybrid execution, checkpoints, and usage actuals
|
|
26
27
|
- graph-first context retrieval through `parseGraphDsl()`, `resolveSeeds()`, `queryGraph()`, and `buildContextPack()`
|
|
27
28
|
- agent scoping through `scopeForAgent()`
|
|
28
29
|
|
|
@@ -102,6 +103,12 @@ ctx <target>
|
|
|
102
103
|
|
|
103
104
|
The old `key=value` graph DSL is no longer supported.
|
|
104
105
|
|
|
106
|
+
## Capacity Scheduling Contracts
|
|
107
|
+
|
|
108
|
+
The SDK owns the provider-neutral capacity runtime helpers used by the agent manager, workers, and market control plane. These helpers keep work estimation separate from provider cost by normalizing `taskSignature + executionProfileId` estimates, then routing against grants, provider lanes, quality requirements, quota/congestion pressure, attention/context saturation, utility, predictive reserve, and hybrid phase metadata.
|
|
109
|
+
|
|
110
|
+
Capacity records remain metadata-compatible: advanced scheduling data lives in task payload JSON, routing decision candidates/scores, reservation metadata, capacity plan metadata, checkpoint artifacts, and usage actual metadata. Missing metadata is neutral, so older callers continue to use the credit-only behavior.
|
|
111
|
+
|
|
105
112
|
## Shared Fixture Support
|
|
106
113
|
|
|
107
114
|
SDK also owns the shared fixture support model used across the Treeseed workspace.
|
package/dist/capacity.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CapacityEstimateConfidence, CapacityGrant, CapacityPlan, CapacityProvider, CapacityProviderLane, CapacityReservation, CreateCapacityReservationRequest, CreateCapacityRoutingDecisionRequest, RecordCapacityUsageRequest, TaskEstimateProfile } from './sdk-types.ts';
|
|
1
|
+
import type { AttentionEstimate, AttentionPolicy, CapacityEstimateConfidence, CapacityGrant, CapacityPlan, CapacityProvider, CapacityProviderLane, CapacityReservation, CreateCapacityReservationRequest, CreateCapacityRoutingDecisionRequest, ExecutionProfile, HybridExecutionPlan, PlannedTaskNode, PlanningAdmissionResult, PlanningPolicy, PredictiveReservePolicy, RecordCapacityUsageRequest, ReservePrediction, TaskAdmissionDecision, TaskAdmissionPolicy, TaskClassification, TaskEstimateProfile, TaskPlanProposal, TaskMutationScope, TaskUsageActual, UtilityEstimate, UtilityPolicy, WorkdayBudgetEnvelope } from './sdk-types.ts';
|
|
2
2
|
import type { AgentProviderProfile } from './types/agents.ts';
|
|
3
3
|
export type ProcessingEnvironment = 'local' | 'staging' | 'prod';
|
|
4
4
|
export interface CapacityProviderRegistration {
|
|
@@ -40,7 +40,11 @@ export interface CapacityEstimateInput {
|
|
|
40
40
|
estimatedCreditsP50?: number | null;
|
|
41
41
|
estimatedCreditsP90?: number | null;
|
|
42
42
|
profile?: TaskEstimateProfile | null;
|
|
43
|
+
profiles?: TaskEstimateProfile[] | null;
|
|
43
44
|
defaultCredits?: number | null;
|
|
45
|
+
executionProfile?: ExecutionProfile | null;
|
|
46
|
+
executionProfileId?: string | null;
|
|
47
|
+
costMultiplier?: number | null;
|
|
44
48
|
}
|
|
45
49
|
export interface CapacityLaneCandidate {
|
|
46
50
|
lane: CapacityProviderLane;
|
|
@@ -60,6 +64,25 @@ export interface CapacityLaneScore {
|
|
|
60
64
|
scarcityPenalty: number;
|
|
61
65
|
fairnessScore: number;
|
|
62
66
|
costPenalty: number;
|
|
67
|
+
qualityFit?: number;
|
|
68
|
+
latencyPenalty?: number;
|
|
69
|
+
quotaPressure?: number;
|
|
70
|
+
congestionPenalty?: number;
|
|
71
|
+
attentionPenalty?: number;
|
|
72
|
+
contextPenalty?: number;
|
|
73
|
+
utilityScore?: number;
|
|
74
|
+
utilityPerCredit?: number;
|
|
75
|
+
predictedReserveImpact?: number;
|
|
76
|
+
trustScore?: number | null;
|
|
77
|
+
successProbability?: number | null;
|
|
78
|
+
executionProfileId?: string | null;
|
|
79
|
+
reservedCredits?: number | null;
|
|
80
|
+
attentionEstimate?: AttentionEstimate | null;
|
|
81
|
+
utilityEstimate?: UtilityEstimate | null;
|
|
82
|
+
reservePrediction?: ReservePrediction | null;
|
|
83
|
+
spilloverReason?: string | null;
|
|
84
|
+
trustScore?: number | null;
|
|
85
|
+
successProbability?: number | null;
|
|
63
86
|
reasons: string[];
|
|
64
87
|
}
|
|
65
88
|
export interface CapacityTaskEstimate {
|
|
@@ -68,6 +91,37 @@ export interface CapacityTaskEstimate {
|
|
|
68
91
|
estimatedCreditsP50: number;
|
|
69
92
|
estimatedCreditsP90: number;
|
|
70
93
|
reservedCredits: number;
|
|
94
|
+
baseReservedCredits?: number;
|
|
95
|
+
executionProfileId?: string | null;
|
|
96
|
+
costMultiplier?: number | null;
|
|
97
|
+
}
|
|
98
|
+
export interface AdmissionEstimateInput extends CapacityEstimateInput {
|
|
99
|
+
classification?: TaskClassification | null;
|
|
100
|
+
}
|
|
101
|
+
export interface WorkdayBudgetEnvelopeInput {
|
|
102
|
+
dailyCreditBudget: number;
|
|
103
|
+
usedCredits?: number | null;
|
|
104
|
+
queuedCredits?: number | null;
|
|
105
|
+
reserveBufferPercent?: number | null;
|
|
106
|
+
recoveryBudgetCredits?: number | null;
|
|
107
|
+
}
|
|
108
|
+
export interface TaskAdmissionInput {
|
|
109
|
+
classification: TaskClassification;
|
|
110
|
+
estimate: CapacityTaskEstimate;
|
|
111
|
+
budget: WorkdayBudgetEnvelopeInput;
|
|
112
|
+
policy?: Partial<TaskAdmissionPolicy> | null;
|
|
113
|
+
source?: string | null;
|
|
114
|
+
metadata?: Record<string, unknown>;
|
|
115
|
+
}
|
|
116
|
+
export interface CapacityInterruptionInput {
|
|
117
|
+
reservedCredits?: number | null;
|
|
118
|
+
consumedCredits?: number | null;
|
|
119
|
+
estimatedRemainingCreditsP50?: number | null;
|
|
120
|
+
estimatedRemainingCreditsP90?: number | null;
|
|
121
|
+
reservationUsedPercentThreshold?: number | null;
|
|
122
|
+
recoveryBudgetRemainingCredits?: number | null;
|
|
123
|
+
recoveryBudgetMinimumCredits?: number | null;
|
|
124
|
+
providerAvailable?: boolean | null;
|
|
71
125
|
}
|
|
72
126
|
export interface TeamCapacitySummary {
|
|
73
127
|
teamId: string;
|
|
@@ -94,6 +148,7 @@ export interface ProjectCapacitySummary extends TeamCapacitySummary {
|
|
|
94
148
|
export interface RouteAndReserveInput {
|
|
95
149
|
plan: CapacityPlan;
|
|
96
150
|
estimate: CapacityTaskEstimate;
|
|
151
|
+
classification?: TaskClassification | null;
|
|
97
152
|
taskId?: string | null;
|
|
98
153
|
workDayId?: string | null;
|
|
99
154
|
taskKind?: string | null;
|
|
@@ -104,6 +159,29 @@ export interface RouteAndReserveInput {
|
|
|
104
159
|
repositoryMutation?: boolean;
|
|
105
160
|
production?: boolean;
|
|
106
161
|
selectedModel?: string | null;
|
|
162
|
+
executionProfile?: ExecutionProfile | string | null;
|
|
163
|
+
executionProfiles?: Array<ExecutionProfile | string> | null;
|
|
164
|
+
estimateProfiles?: TaskEstimateProfile[] | null;
|
|
165
|
+
minimumQualityWeight?: number | null;
|
|
166
|
+
requiredContextTokens?: number | null;
|
|
167
|
+
estimatedContextTokens?: number | null;
|
|
168
|
+
attentionWeight?: number | null;
|
|
169
|
+
coordinationWeight?: number | null;
|
|
170
|
+
minimumAttentionAvailable?: number | null;
|
|
171
|
+
attentionPolicy?: Partial<AttentionPolicy> | null;
|
|
172
|
+
attentionEstimate?: AttentionEstimate | null;
|
|
173
|
+
utilityPolicy?: Partial<UtilityPolicy> | null;
|
|
174
|
+
utilityEstimate?: UtilityEstimate | null;
|
|
175
|
+
utilityValue?: number | null;
|
|
176
|
+
maintenanceValue?: number | null;
|
|
177
|
+
deadlineAt?: string | null;
|
|
178
|
+
successProbability?: number | null;
|
|
179
|
+
trustRequirement?: number | null;
|
|
180
|
+
cooperativeRouting?: boolean | null;
|
|
181
|
+
predictiveReservePolicy?: Partial<PredictiveReservePolicy> | null;
|
|
182
|
+
hybridExecutionPlan?: HybridExecutionPlan | Record<string, unknown> | null;
|
|
183
|
+
preferredExecutionProfiles?: string[] | null;
|
|
184
|
+
disallowedExecutionProfiles?: string[] | null;
|
|
107
185
|
source?: string;
|
|
108
186
|
metadata?: Record<string, unknown>;
|
|
109
187
|
}
|
|
@@ -112,10 +190,35 @@ export interface RouteAndReserveCandidate {
|
|
|
112
190
|
providerId: string;
|
|
113
191
|
laneId: string;
|
|
114
192
|
grantId: string;
|
|
193
|
+
executionProfileId?: string | null;
|
|
115
194
|
remainingCredits: number | null;
|
|
116
195
|
score: CapacityLaneScore;
|
|
117
196
|
eligible: boolean;
|
|
118
197
|
reasons: string[];
|
|
198
|
+
estimate?: CapacityTaskEstimate;
|
|
199
|
+
pressure?: CapacityRoutePressure;
|
|
200
|
+
qualityFit?: number;
|
|
201
|
+
attentionEstimate?: AttentionEstimate;
|
|
202
|
+
utilityEstimate?: UtilityEstimate;
|
|
203
|
+
reservePrediction?: ReservePrediction | null;
|
|
204
|
+
trustScore?: number | null;
|
|
205
|
+
successProbability?: number | null;
|
|
206
|
+
spilloverReason?: string | null;
|
|
207
|
+
}
|
|
208
|
+
export interface CapacityRoutePressure {
|
|
209
|
+
activeReservations: number;
|
|
210
|
+
maxActiveReservations: number | null;
|
|
211
|
+
congestionRatio: number;
|
|
212
|
+
quotaRemainingPercent: number | null;
|
|
213
|
+
sessionRemainingMinutes: number | null;
|
|
214
|
+
subscriptionSaturationPercent: number | null;
|
|
215
|
+
providerUnavailable: boolean;
|
|
216
|
+
activeAttentionLoad: number;
|
|
217
|
+
maxAttentionLoad: number | null;
|
|
218
|
+
attentionSaturationPercent: number | null;
|
|
219
|
+
activeContextTokens: number;
|
|
220
|
+
maxContextTokens: number | null;
|
|
221
|
+
contextSaturationPercent: number | null;
|
|
119
222
|
}
|
|
120
223
|
export type RouteAndReserveResult = {
|
|
121
224
|
ok: true;
|
|
@@ -136,6 +239,14 @@ export type RouteAndReserveResult = {
|
|
|
136
239
|
estimatedCreditsP50: number;
|
|
137
240
|
estimatedCreditsP90: number;
|
|
138
241
|
reservedCredits: number;
|
|
242
|
+
executionProfileId?: string | null;
|
|
243
|
+
costMultiplier?: number | null;
|
|
244
|
+
score?: number | null;
|
|
245
|
+
attentionEstimate?: AttentionEstimate | null;
|
|
246
|
+
utilityEstimate?: UtilityEstimate | null;
|
|
247
|
+
reservePrediction?: ReservePrediction | null;
|
|
248
|
+
hybridExecutionPlan?: HybridExecutionPlan | null;
|
|
249
|
+
candidates?: Record<string, unknown>[];
|
|
139
250
|
};
|
|
140
251
|
candidates: RouteAndReserveCandidate[];
|
|
141
252
|
} | {
|
|
@@ -167,12 +278,121 @@ export interface CapacitySettlement {
|
|
|
167
278
|
releasedCredits: number;
|
|
168
279
|
overrunCredits: number;
|
|
169
280
|
}
|
|
281
|
+
export declare const DEFAULT_EXECUTION_PROFILE_ID = "standard-code-model";
|
|
282
|
+
export declare function estimateLearningPercentile(values: Array<number | null | undefined>, percentile: number): number | null;
|
|
283
|
+
export declare function estimateLearningVariance(values: Array<number | null | undefined>): number;
|
|
284
|
+
export declare function isInterruptedUsageActual(actual: Pick<TaskUsageActual, 'metadata'> | {
|
|
285
|
+
metadata?: Record<string, unknown> | null;
|
|
286
|
+
}): boolean;
|
|
287
|
+
export declare function estimateProfileConfidenceScore(input: {
|
|
288
|
+
sampleCount?: number | null;
|
|
289
|
+
creditsVariance?: number | null;
|
|
290
|
+
creditsP50?: number | null;
|
|
291
|
+
lastSampleAt?: string | null;
|
|
292
|
+
now?: Date | string | null;
|
|
293
|
+
}): number;
|
|
294
|
+
export declare function estimateConfidenceFromProfile(profile: TaskEstimateProfile | null | undefined, now?: Date | string | null): CapacityEstimateConfidence;
|
|
295
|
+
export declare function selectTaskEstimateProfile(input: {
|
|
296
|
+
profiles?: TaskEstimateProfile[] | null;
|
|
297
|
+
taskSignature?: string | null;
|
|
298
|
+
executionProfile?: ExecutionProfile | string | null;
|
|
299
|
+
executionProfileId?: string | null;
|
|
300
|
+
}): TaskEstimateProfile | null;
|
|
301
|
+
export declare function buildTaskEstimateProfileFromActuals(input: {
|
|
302
|
+
taskSignature: string;
|
|
303
|
+
executionProfileId?: string | null;
|
|
304
|
+
actuals: TaskUsageActual[];
|
|
305
|
+
now?: Date | string | null;
|
|
306
|
+
}): TaskEstimateProfile;
|
|
307
|
+
export declare const DEFAULT_EXECUTION_PROFILES: Record<string, ExecutionProfile>;
|
|
308
|
+
export declare const DEFAULT_TASK_ADMISSION_POLICY: TaskAdmissionPolicy;
|
|
309
|
+
export declare function normalizeExecutionProfile(input?: ExecutionProfile | string | null): ExecutionProfile;
|
|
310
|
+
export declare function normalizeTaskAdmissionPolicy(input?: Partial<TaskAdmissionPolicy> | null | undefined): {
|
|
311
|
+
planningThresholdCredits: number;
|
|
312
|
+
approvalThresholdCredits: number;
|
|
313
|
+
reserveBufferPercent: number;
|
|
314
|
+
recoveryBudgetCredits: number;
|
|
315
|
+
maxDownstreamTasks: number;
|
|
316
|
+
maxPlanningDepth: number;
|
|
317
|
+
maxAdmittedPlanTasksPerCycle: number;
|
|
318
|
+
planningTaskSignature: string;
|
|
319
|
+
allowBackfill: boolean | undefined;
|
|
320
|
+
maxAttentionLoad: number | null | undefined;
|
|
321
|
+
reserveAttentionPercent: number;
|
|
322
|
+
maxContextTokens: number | null | undefined;
|
|
323
|
+
maxContextSaturationPercent: number;
|
|
324
|
+
coordinationOverheadFactor: number;
|
|
325
|
+
predictiveReservePolicy?: Partial<PredictiveReservePolicy> | null;
|
|
326
|
+
utilityPolicy?: Partial<UtilityPolicy> | null;
|
|
327
|
+
};
|
|
328
|
+
export declare function normalizeAttentionPolicy(input?: Partial<AttentionPolicy | TaskAdmissionPolicy> | null | undefined): AttentionPolicy;
|
|
329
|
+
export declare function normalizeUtilityPolicy(input?: Partial<UtilityPolicy> | null | undefined): UtilityPolicy;
|
|
330
|
+
export declare function normalizePredictiveReservePolicy(input?: Partial<PredictiveReservePolicy> | null | undefined): PredictiveReservePolicy;
|
|
331
|
+
export declare function estimateUtilityForTask(input: {
|
|
332
|
+
classification?: TaskClassification | null;
|
|
333
|
+
executionProfile?: ExecutionProfile | string | null;
|
|
334
|
+
estimate?: Pick<CapacityTaskEstimate, 'reservedCredits'> | null;
|
|
335
|
+
utilityPolicy?: Partial<UtilityPolicy> | null;
|
|
336
|
+
utilityValue?: number | null;
|
|
337
|
+
maintenanceValue?: number | null;
|
|
338
|
+
priority?: number | null;
|
|
339
|
+
deadlineAt?: string | null;
|
|
340
|
+
successProbability?: number | null;
|
|
341
|
+
metadata?: Record<string, unknown> | null;
|
|
342
|
+
source?: string | null;
|
|
343
|
+
now?: Date | string | null;
|
|
344
|
+
}): UtilityEstimate;
|
|
345
|
+
export declare function predictReserveForCapacityPlan(input: {
|
|
346
|
+
plan?: CapacityPlan | null;
|
|
347
|
+
policy?: Partial<PredictiveReservePolicy> | null;
|
|
348
|
+
dailyCreditBudget?: number | null;
|
|
349
|
+
remainingCredits?: number | null;
|
|
350
|
+
metadata?: Record<string, unknown> | null;
|
|
351
|
+
}): ReservePrediction;
|
|
352
|
+
export declare function normalizeHybridExecutionPlan(input: HybridExecutionPlan | Record<string, unknown> | null | undefined): HybridExecutionPlan | null;
|
|
353
|
+
export declare function normalizePlanningPolicy(input?: Partial<PlanningPolicy | TaskAdmissionPolicy> | null | undefined): PlanningPolicy;
|
|
354
|
+
export declare function synthesizePlanEstimate(tasks: PlannedTaskNode[]): {
|
|
355
|
+
totalEstimatedCreditsP50: number;
|
|
356
|
+
totalEstimatedCreditsP90: number;
|
|
357
|
+
};
|
|
358
|
+
export declare function rankPlannedTaskNodes(tasks: PlannedTaskNode[]): PlannedTaskNode[];
|
|
359
|
+
export declare function normalizeTaskPlanProposal(input: unknown, policyInput?: Partial<PlanningPolicy | TaskAdmissionPolicy> | null): TaskPlanProposal;
|
|
360
|
+
export declare function validateTaskPlanProposal(input: TaskPlanProposal, policyInput?: Partial<PlanningPolicy | TaskAdmissionPolicy> | null): {
|
|
361
|
+
ok: boolean;
|
|
362
|
+
reasons: string[];
|
|
363
|
+
rejected: {
|
|
364
|
+
node: PlannedTaskNode;
|
|
365
|
+
reasons: string[];
|
|
366
|
+
}[];
|
|
367
|
+
};
|
|
368
|
+
export declare function progressivelyAdmitPlanProposal(input: {
|
|
369
|
+
proposal: TaskPlanProposal;
|
|
370
|
+
policy?: Partial<PlanningPolicy | TaskAdmissionPolicy> | null;
|
|
371
|
+
availableCredits?: number | null;
|
|
372
|
+
remainingQueuedCredits?: number | null;
|
|
373
|
+
remainingQueuedSlots?: number | null;
|
|
374
|
+
}): PlanningAdmissionResult;
|
|
375
|
+
export declare function computeWorkdayBudgetEnvelope(input: WorkdayBudgetEnvelopeInput): WorkdayBudgetEnvelope;
|
|
376
|
+
export declare function mutationRequiresRepositoryClaim(scope: TaskMutationScope | null | undefined): scope is "repository_write" | "production";
|
|
170
377
|
export declare function reserveCreditsForEstimate(input: CapacityEstimateInput): {
|
|
171
378
|
taskSignature: string;
|
|
172
379
|
confidence: CapacityEstimateConfidence;
|
|
173
380
|
estimatedCreditsP50: number;
|
|
174
381
|
estimatedCreditsP90: number;
|
|
175
382
|
reservedCredits: number;
|
|
383
|
+
baseReservedCredits: number;
|
|
384
|
+
executionProfileId: string | null;
|
|
385
|
+
costMultiplier: number;
|
|
386
|
+
};
|
|
387
|
+
export declare function estimateForClassification(input: AdmissionEstimateInput): CapacityTaskEstimate;
|
|
388
|
+
export declare function decideTaskAdmission(input: TaskAdmissionInput): TaskAdmissionDecision;
|
|
389
|
+
export declare function shouldInterruptForCapacity(input: CapacityInterruptionInput): {
|
|
390
|
+
interrupt: boolean;
|
|
391
|
+
reasons: string[];
|
|
392
|
+
usedPercent: number;
|
|
393
|
+
estimatedRemainingP50: number;
|
|
394
|
+
estimatedRemainingP90: number;
|
|
395
|
+
remainingReservationCredits: number;
|
|
176
396
|
};
|
|
177
397
|
export declare function summarizeCapacityPlan(plan: CapacityPlan): {
|
|
178
398
|
grantedDailyCredits: number;
|
|
@@ -202,4 +422,16 @@ export declare function createReservationReleaseEntry(input: {
|
|
|
202
422
|
metadata?: Record<string, unknown>;
|
|
203
423
|
}): RecordCapacityUsageRequest;
|
|
204
424
|
export declare function settleCapacityActuals(input: CapacitySettlementInput): CapacitySettlement;
|
|
425
|
+
export declare function estimateAttentionForTask(input: {
|
|
426
|
+
classification?: TaskClassification | null;
|
|
427
|
+
executionProfile?: ExecutionProfile | string | null;
|
|
428
|
+
attentionPolicy?: Partial<AttentionPolicy | TaskAdmissionPolicy> | null;
|
|
429
|
+
attentionWeight?: number | null;
|
|
430
|
+
coordinationWeight?: number | null;
|
|
431
|
+
estimatedContextTokens?: number | null;
|
|
432
|
+
requiredContextTokens?: number | null;
|
|
433
|
+
source?: string | null;
|
|
434
|
+
metadata?: Record<string, unknown>;
|
|
435
|
+
}): AttentionEstimate;
|
|
436
|
+
export declare function capacityRoutePressure(plan: CapacityPlan, provider: CapacityProvider, lane: CapacityProviderLane): CapacityRoutePressure;
|
|
205
437
|
export declare function routeAndReserveCapacity(input: RouteAndReserveInput): RouteAndReserveResult;
|