@sealant/api-contracts-next 0.40.0-next.785 → 0.40.0-next.786

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.
@@ -1,5 +1,6 @@
1
1
  import { HttpApi, OpenApi } from "effect/http-api";
2
2
  import { AccessTokensGroup } from "./access-tokens.js";
3
+ import { RequestBudget } from "./budgets.js";
3
4
  import { ConnectedAccountsGroup } from "./connected-accounts.js";
4
5
  import { GitHubGroup } from "./github.js";
5
6
  import { InferenceGroup } from "./inference.js";
@@ -33,6 +34,7 @@ export const ControlPlaneAPI = HttpApi.make("sealantControlPlaneApi")
33
34
  .add(ResourceInstancesGroup.prefix("/v1/resource-domains"))
34
35
  // Last, so it reaches every endpoint above (`HttpApi.middleware` skips endpoints added after it).
35
36
  .middleware(RequestRefusal)
37
+ .middleware(RequestBudget)
36
38
  .annotate(OpenApi.Title, "Sealant Control Plane API")
37
39
  .annotate(OpenApi.Version, "0.0.0")
38
40
  .annotate(OpenApi.Description, "Sealant control-plane HTTP API.");
@@ -14,6 +14,7 @@
14
14
  * everything it wrote arrived. {@link ForwardFlow} keeps this ledger for either side.
15
15
  */
16
16
  import { Schema } from "effect";
17
+ import { type BudgetExceededError } from "./budgets.js";
17
18
  export declare const FORWARD_V2_SUBPROTOCOL = "sealant.forward.v2";
18
19
  /** The largest binary frame either side may send. */
19
20
  export declare const FORWARD_V2_MAX_FRAME_BYTES: number;
@@ -76,9 +77,16 @@ export declare const forwardRefusedFrameSchema: Schema.Struct<{
76
77
  readonly reason: Schema.String;
77
78
  readonly message: Schema.String;
78
79
  readonly status: Schema.Int;
80
+ readonly budget: Schema.optional<Schema.String>;
81
+ readonly limit: Schema.optional<Schema.Number>;
82
+ readonly retryAfterSeconds: Schema.optional<Schema.Number>;
83
+ readonly refusal: Schema.optional<Schema.Struct<{
84
+ readonly phase: Schema.Literal<"before-work">;
85
+ readonly bucket: Schema.Literals<readonly ["owner", "unowned", "key", "principal"]>;
86
+ }>>;
79
87
  }>;
80
88
  export type ForwardRefusedFrame = typeof forwardRefusedFrameSchema.Type;
81
- export declare const forwardRefusedFrame: (reason: ForwardRefusalReason, message: string) => ForwardRefusedFrame;
89
+ export declare const forwardRefusedFrame: (reason: ForwardRefusalReason, message: string, budget?: Pick<BudgetExceededError, "budget" | "limit" | "retryAfterSeconds" | "refusal">) => ForwardRefusedFrame;
82
90
  /** The first frame the server sends on a v2 forward, as JSON text. */
83
91
  export declare const forwardOpenFrameSchema: Schema.Union<readonly [Schema.Struct<{
84
92
  readonly t: Schema.Literal<"ready">;
@@ -94,6 +102,13 @@ export declare const forwardOpenFrameSchema: Schema.Union<readonly [Schema.Struc
94
102
  readonly reason: Schema.String;
95
103
  readonly message: Schema.String;
96
104
  readonly status: Schema.Int;
105
+ readonly budget: Schema.optional<Schema.String>;
106
+ readonly limit: Schema.optional<Schema.Number>;
107
+ readonly retryAfterSeconds: Schema.optional<Schema.Number>;
108
+ readonly refusal: Schema.optional<Schema.Struct<{
109
+ readonly phase: Schema.Literal<"before-work">;
110
+ readonly bucket: Schema.Literals<readonly ["owner", "unowned", "key", "principal"]>;
111
+ }>>;
97
112
  }>]>;
98
113
  export type ForwardOpenFrame = typeof forwardOpenFrameSchema.Type;
99
114
  /** What each direction of a v2 forward may have in flight beyond what its receiver consumed. */
@@ -14,6 +14,7 @@
14
14
  * everything it wrote arrived. {@link ForwardFlow} keeps this ledger for either side.
15
15
  */
16
16
  import { Option, Schema } from "effect";
17
+ import { requestBudgetRefusalSchema } from "./budgets.js";
17
18
  export const FORWARD_V2_SUBPROTOCOL = "sealant.forward.v2";
18
19
  /** The largest binary frame either side may send. */
19
20
  export const FORWARD_V2_MAX_FRAME_BYTES = 64 * 1024;
@@ -87,12 +88,24 @@ export const forwardRefusedFrameSchema = Schema.Struct({
87
88
  reason: Schema.String,
88
89
  message: Schema.String,
89
90
  status: Schema.Int,
91
+ budget: Schema.optional(Schema.String),
92
+ limit: Schema.optional(Schema.Number),
93
+ retryAfterSeconds: Schema.optional(Schema.Number),
94
+ refusal: Schema.optional(requestBudgetRefusalSchema),
90
95
  });
91
- export const forwardRefusedFrame = (reason, message) => ({
96
+ export const forwardRefusedFrame = (reason, message, budget) => ({
92
97
  t: "refused",
93
98
  reason,
94
99
  message,
95
100
  status: FORWARD_REFUSAL_STATUS[reason],
101
+ ...(budget === undefined
102
+ ? {}
103
+ : {
104
+ budget: budget.budget,
105
+ limit: budget.limit,
106
+ retryAfterSeconds: budget.retryAfterSeconds,
107
+ ...(budget.refusal === undefined ? {} : { refusal: budget.refusal }),
108
+ }),
96
109
  });
97
110
  /** The first frame the server sends on a v2 forward, as JSON text. */
98
111
  export const forwardOpenFrameSchema = Schema.Union([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sealant/api-contracts-next",
3
- "version": "0.40.0-next.785",
3
+ "version": "0.40.0-next.786",
4
4
  "description": "Contract-first HTTP API definitions for Sealant services",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -36,7 +36,7 @@
36
36
  "peerDependencies": {
37
37
  "effect": "^4.0.5"
38
38
  },
39
- "gitHead": "03a1f14dbaaa8584fe9cf0c90f2078ac32f5d48c",
39
+ "gitHead": "1c95b9b2df6c068034efdcdeb05d253e5e842100",
40
40
  "publishConfig": {
41
41
  "access": "public"
42
42
  }