@treeseed/sdk 0.10.10 → 0.10.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 +2 -2
- package/dist/capacity-provider.d.ts +53 -1
- package/dist/capacity.d.ts +80 -1
- package/dist/capacity.js +687 -8
- package/dist/db/d1.d.ts +109 -3227
- package/dist/db/index.d.ts +1 -0
- package/dist/db/index.js +1 -0
- package/dist/db/market-schema.d.ts +42517 -0
- package/dist/db/market-schema.js +1822 -0
- package/dist/db/node-sqlite.d.ts +109 -3227
- package/dist/db/schema.d.ts +226 -5757
- package/dist/db/schema.js +35 -226
- package/dist/index.d.ts +4 -4
- package/dist/index.js +14 -0
- package/dist/market-client.d.ts +28 -0
- package/dist/market-client.js +43 -0
- package/dist/operations/services/commit-message-provider.js +1 -1
- package/dist/operations/services/d1-migration.js +0 -59
- package/dist/operations/services/deploy.js +2 -1
- package/dist/operations/services/local-dev.js +3 -3
- package/dist/operations/services/release-candidate.js +9 -9
- package/dist/operations/services/runtime-paths.d.ts +1 -1
- package/dist/operations/services/runtime-paths.js +2 -2
- package/dist/operations/services/template-registry.js +10 -1
- package/dist/scripts/tenant-d1-migrate-local.js +2 -3
- package/dist/sdk-types.d.ts +172 -2
- package/dist/seeds/normalize.js +6 -0
- package/dist/seeds/schema.js +61 -1
- package/dist/seeds/types.d.ts +32 -0
- package/drizzle/d1/0000_treeseed_d1.sql +37 -0
- package/drizzle/market/0000_market_control_plane.sql +2863 -0
- package/drizzle/market/0001_capacity_budget_mode_default.sql +4 -0
- package/package.json +8 -1
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ If you are unsure, use `AgentSdk`.
|
|
|
20
20
|
|
|
21
21
|
`AgentSdk` covers five main areas:
|
|
22
22
|
|
|
23
|
-
- generic model reads and mutations across content-backed and
|
|
23
|
+
- generic model reads and mutations across content-backed models and the static-hub D1 form store
|
|
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
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
|
|
@@ -49,7 +49,7 @@ const sdk = new AgentSdk({
|
|
|
49
49
|
});
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
Use `AgentSdk.createLocal()` when you want
|
|
52
|
+
Use `AgentSdk.createLocal()` when you want the local static-hub D1 form store:
|
|
53
53
|
|
|
54
54
|
```ts
|
|
55
55
|
import { AgentSdk } from '@treeseed/sdk/sdk';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { NativeUsageObservation } from './sdk-types.ts';
|
|
1
2
|
export declare const CAPACITY_PROVIDER_ENDPOINTS: {
|
|
2
3
|
readonly register: "/v1/provider/register";
|
|
3
4
|
readonly heartbeat: "/v1/provider/heartbeat";
|
|
@@ -35,11 +36,59 @@ export interface CapacityProviderCapability {
|
|
|
35
36
|
verification: string[];
|
|
36
37
|
metadata?: Record<string, unknown>;
|
|
37
38
|
}
|
|
39
|
+
export type NativeCapacityUnit = 'wall_minute' | 'quota_minute' | 'usd' | 'token' | 'request' | 'gpu_second' | 'human_minute' | 'custom' | string;
|
|
40
|
+
export type NativeCapacityLimitScope = 'daily' | 'weekly' | 'monthly' | 'session' | 'rolling_window' | string;
|
|
41
|
+
export type NativeCapacityConfidence = 'exact' | 'estimated' | 'opaque' | string;
|
|
42
|
+
export type NativeCapacityLimitSource = 'configured' | 'observed' | 'learned' | 'manual_override' | string;
|
|
43
|
+
export type ProviderQuotaVisibility = 'exact' | 'partial' | 'opaque' | string;
|
|
44
|
+
export interface ExecutionProviderNativeLimitCapacity {
|
|
45
|
+
id?: string;
|
|
46
|
+
scope?: NativeCapacityLimitScope;
|
|
47
|
+
limitScope?: NativeCapacityLimitScope;
|
|
48
|
+
nativeUnit?: NativeCapacityUnit;
|
|
49
|
+
limitAmount: number;
|
|
50
|
+
reserveBufferPercent?: number | null;
|
|
51
|
+
resetCadence?: string | null;
|
|
52
|
+
resetAt?: string | null;
|
|
53
|
+
confidence?: NativeCapacityConfidence;
|
|
54
|
+
source?: NativeCapacityLimitSource;
|
|
55
|
+
metadata?: Record<string, unknown>;
|
|
56
|
+
}
|
|
57
|
+
export interface ExecutionProviderObservationCapacity {
|
|
58
|
+
id?: string;
|
|
59
|
+
observedAt?: string;
|
|
60
|
+
health?: string;
|
|
61
|
+
activeWorkers?: number | null;
|
|
62
|
+
queuedTasks?: number | null;
|
|
63
|
+
throttleState?: string | null;
|
|
64
|
+
nativeRemaining?: Record<string, unknown>;
|
|
65
|
+
resetAt?: string | null;
|
|
66
|
+
confidence?: NativeCapacityConfidence;
|
|
67
|
+
metadata?: Record<string, unknown>;
|
|
68
|
+
}
|
|
69
|
+
export interface ExecutionProviderNativeCapacity {
|
|
70
|
+
id?: string;
|
|
71
|
+
name: string;
|
|
72
|
+
kind: string;
|
|
73
|
+
status?: string;
|
|
74
|
+
nativeUnit: NativeCapacityUnit;
|
|
75
|
+
quotaVisibility?: ProviderQuotaVisibility;
|
|
76
|
+
maxConcurrentWorkers?: number | null;
|
|
77
|
+
resetCadence?: string | null;
|
|
78
|
+
config?: Record<string, unknown>;
|
|
79
|
+
metadata?: Record<string, unknown>;
|
|
80
|
+
nativeLimits?: ExecutionProviderNativeLimitCapacity[];
|
|
81
|
+
observation?: ExecutionProviderObservationCapacity;
|
|
82
|
+
}
|
|
83
|
+
export interface CapacityProviderNativeCapacity {
|
|
84
|
+
executionProviders: ExecutionProviderNativeCapacity[];
|
|
85
|
+
}
|
|
38
86
|
export interface CapacityProviderBudgetCapacity {
|
|
39
87
|
dailyCreditBudget?: number | null;
|
|
40
88
|
monthlyCreditBudget?: number | null;
|
|
41
89
|
maxConcurrentWorkdays?: number | null;
|
|
42
90
|
maxConcurrentRunners?: number | null;
|
|
91
|
+
nativeCapacity?: CapacityProviderNativeCapacity;
|
|
43
92
|
[key: string]: unknown;
|
|
44
93
|
}
|
|
45
94
|
export interface CapacityProviderHealthState {
|
|
@@ -181,6 +230,7 @@ export interface ProviderUsageReport {
|
|
|
181
230
|
projectId?: string | null;
|
|
182
231
|
taskSignature?: string | null;
|
|
183
232
|
executionProfileId?: string | null;
|
|
233
|
+
executionProviderId?: string | null;
|
|
184
234
|
modelName?: string | null;
|
|
185
235
|
inputTokens?: number | null;
|
|
186
236
|
outputTokens?: number | null;
|
|
@@ -193,8 +243,10 @@ export interface ProviderUsageReport {
|
|
|
193
243
|
diffLinesRemoved?: number | null;
|
|
194
244
|
testRuns?: number | null;
|
|
195
245
|
retryCount?: number | null;
|
|
196
|
-
actualCredits
|
|
246
|
+
actualCredits?: number | null;
|
|
247
|
+
actualCreditsOverride?: boolean | null;
|
|
197
248
|
actualUsd?: number | null;
|
|
249
|
+
nativeUsage?: NativeUsageObservation | Record<string, unknown> | null;
|
|
198
250
|
metadata?: Record<string, unknown> | null;
|
|
199
251
|
}
|
|
200
252
|
export interface ProviderUsageReportResponse {
|
package/dist/capacity.d.ts
CHANGED
|
@@ -1,5 +1,58 @@
|
|
|
1
|
-
import type { AttentionEstimate, AttentionPolicy, CapacityEstimateConfidence, CapacityGrant, CapacityPlan, CapacityProvider, CapacityProviderLane, CapacityReservation, CreateCapacityReservationRequest, CreateCapacityRoutingDecisionRequest, ExecutionProfile, HybridExecutionPlan, PlannedTaskNode, PlanningAdmissionResult, PlanningPolicy, PredictiveReservePolicy, ProjectEnvironmentName, RecordCapacityUsageRequest, ReservePrediction, TaskAdmissionDecision, TaskAdmissionPolicy, TaskClassification, TaskEstimateProfile, TaskPlanProposal, TaskMutationScope, TaskUsageActual, UtilityEstimate, UtilityPolicy, WorkdayBudgetEnvelope } from './sdk-types.ts';
|
|
1
|
+
import type { AttentionEstimate, AttentionPolicy, CapacityEstimateConfidence, CapacityGrant, CapacityPlan, CapacityProvider, CapacityProviderLane, CapacityReservation, CreditConversionProfile, CreateCapacityReservationRequest, CreateCapacityRoutingDecisionRequest, DerivedCapacityAvailability, DerivedCapacityInput, ExecutionProfile, HybridExecutionPlan, NativeUsageObservation, PlannedTaskNode, PlanningAdmissionResult, PlanningPolicy, PredictiveReservePolicy, ProjectEnvironmentName, 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
|
+
export declare const ACTUAL_CREDIT_FORMULA_VERSION = "treeseed.actual-credits.v1";
|
|
4
|
+
export interface ActualCreditCalculationInput {
|
|
5
|
+
nativeUsage?: NativeUsageObservation | Record<string, unknown> | null;
|
|
6
|
+
conversionProfile?: CreditConversionProfile | null;
|
|
7
|
+
legacyActualCredits?: number | null;
|
|
8
|
+
actualCreditsOverride?: boolean | null;
|
|
9
|
+
reservedCredits?: number | null;
|
|
10
|
+
actualUsd?: number | null;
|
|
11
|
+
inputTokens?: number | null;
|
|
12
|
+
outputTokens?: number | null;
|
|
13
|
+
cachedInputTokens?: number | null;
|
|
14
|
+
quotaMinutes?: number | null;
|
|
15
|
+
wallMinutes?: number | null;
|
|
16
|
+
filesOpened?: number | null;
|
|
17
|
+
filesChanged?: number | null;
|
|
18
|
+
diffLinesAdded?: number | null;
|
|
19
|
+
diffLinesRemoved?: number | null;
|
|
20
|
+
testRuns?: number | null;
|
|
21
|
+
retryCount?: number | null;
|
|
22
|
+
source?: string | null;
|
|
23
|
+
}
|
|
24
|
+
export interface ActualCreditCalculation {
|
|
25
|
+
actualCredits: number;
|
|
26
|
+
formulaVersion: string;
|
|
27
|
+
source: 'central_calculator' | 'conversion_profile' | 'blended_conversion_profile' | 'legacy_override' | 'legacy_fallback' | 'reserved_fallback' | 'zero_fallback';
|
|
28
|
+
nativeUsage: NativeUsageObservation;
|
|
29
|
+
components: Record<string, number>;
|
|
30
|
+
partial: boolean;
|
|
31
|
+
interrupted: boolean;
|
|
32
|
+
conversionProfileId?: string | null;
|
|
33
|
+
conversionConfidence?: string | null;
|
|
34
|
+
}
|
|
35
|
+
export declare function nativeUsageUnit(input: NativeUsageObservation | Record<string, unknown> | null | undefined): string | null;
|
|
36
|
+
export declare function nativeUsageAmount(input: NativeUsageObservation | Record<string, unknown> | null | undefined, nativeUnit?: string | null): number | null;
|
|
37
|
+
export declare function selectCreditConversionProfile(input: {
|
|
38
|
+
profiles?: CreditConversionProfile[] | null;
|
|
39
|
+
taskSignature?: string | null;
|
|
40
|
+
executionProfileId?: string | null;
|
|
41
|
+
executionProviderKind?: string | null;
|
|
42
|
+
nativeUnit?: string | null;
|
|
43
|
+
}): CreditConversionProfile | null;
|
|
44
|
+
export declare function buildCreditConversionProfileFromActuals(input: {
|
|
45
|
+
taskSignature: string;
|
|
46
|
+
executionProfileId?: string | null;
|
|
47
|
+
executionProviderKind: string;
|
|
48
|
+
nativeUnit: string;
|
|
49
|
+
actuals: TaskUsageActual[];
|
|
50
|
+
formulaVersion?: string | null;
|
|
51
|
+
now?: Date | string | null;
|
|
52
|
+
id?: string | null;
|
|
53
|
+
}): CreditConversionProfile;
|
|
54
|
+
export declare function deriveAvailableCredits(input: DerivedCapacityInput): DerivedCapacityAvailability;
|
|
55
|
+
export declare function calculateActualCredits(input: ActualCreditCalculationInput): ActualCreditCalculation;
|
|
3
56
|
export interface CapacityEstimateInput {
|
|
4
57
|
taskSignature?: string | null;
|
|
5
58
|
taskKind?: string | null;
|
|
@@ -37,6 +90,7 @@ export interface CapacityLaneScore {
|
|
|
37
90
|
congestionPenalty?: number;
|
|
38
91
|
attentionPenalty?: number;
|
|
39
92
|
contextPenalty?: number;
|
|
93
|
+
nativePressurePenalty?: number;
|
|
40
94
|
utilityScore?: number;
|
|
41
95
|
utilityPerCredit?: number;
|
|
42
96
|
predictedReserveImpact?: number;
|
|
@@ -157,13 +211,21 @@ export interface RouteAndReserveCandidate {
|
|
|
157
211
|
providerId: string;
|
|
158
212
|
laneId: string;
|
|
159
213
|
grantId: string;
|
|
214
|
+
executionProviderId?: string | null;
|
|
160
215
|
executionProfileId?: string | null;
|
|
216
|
+
nativeUnit?: string | null;
|
|
161
217
|
remainingCredits: number | null;
|
|
218
|
+
staticRemainingCredits?: number | null;
|
|
219
|
+
derivedAvailableCredits?: number | null;
|
|
220
|
+
reservedNativeAmount?: number | null;
|
|
221
|
+
derivedCapacity?: DerivedCapacityAvailability | null;
|
|
222
|
+
derivedCapacityMode?: 'static' | 'hybrid' | 'derived';
|
|
162
223
|
score: CapacityLaneScore;
|
|
163
224
|
eligible: boolean;
|
|
164
225
|
reasons: string[];
|
|
165
226
|
estimate?: CapacityTaskEstimate;
|
|
166
227
|
pressure?: CapacityRoutePressure;
|
|
228
|
+
nativePressure?: CapacityRouteNativePressure | null;
|
|
167
229
|
qualityFit?: number;
|
|
168
230
|
attentionEstimate?: AttentionEstimate;
|
|
169
231
|
utilityEstimate?: UtilityEstimate;
|
|
@@ -172,6 +234,17 @@ export interface RouteAndReserveCandidate {
|
|
|
172
234
|
successProbability?: number | null;
|
|
173
235
|
spilloverReason?: string | null;
|
|
174
236
|
}
|
|
237
|
+
export interface CapacityRouteNativePressure {
|
|
238
|
+
executionProviderId: string;
|
|
239
|
+
nativeUnit: string;
|
|
240
|
+
availableNativeAmount: number;
|
|
241
|
+
activeReservedNativeAmount: number;
|
|
242
|
+
reserveBufferNativeAmount: number;
|
|
243
|
+
reservedNativeAmount: number | null;
|
|
244
|
+
pressureRatio: number | null;
|
|
245
|
+
confidence: string;
|
|
246
|
+
reasons: string[];
|
|
247
|
+
}
|
|
175
248
|
export interface CapacityRoutePressure {
|
|
176
249
|
activeReservations: number;
|
|
177
250
|
maxActiveReservations: number | null;
|
|
@@ -206,6 +279,12 @@ export type RouteAndReserveResult = {
|
|
|
206
279
|
estimatedCreditsP50: number;
|
|
207
280
|
estimatedCreditsP90: number;
|
|
208
281
|
reservedCredits: number;
|
|
282
|
+
executionProviderId?: string | null;
|
|
283
|
+
nativeUnit?: string | null;
|
|
284
|
+
reservedNativeAmount?: number | null;
|
|
285
|
+
derivedAvailableCredits?: number | null;
|
|
286
|
+
derivedCapacityMode?: 'static' | 'hybrid' | 'derived';
|
|
287
|
+
nativePressure?: CapacityRouteNativePressure | null;
|
|
209
288
|
executionProfileId?: string | null;
|
|
210
289
|
costMultiplier?: number | null;
|
|
211
290
|
score?: number | null;
|