+36
![github-actions[bot]](/assets/img/avatar_default.png)








Julius Marminge
maria-rcks
Bilal Bakr
shivam
Vitalii Yehorov
Jake Leventhal
Claude Opus 5
Alex Southwell
github-actions[bot]
Nicholas Wasmiller
PB
Exotic
Yash Singh
Devin
Theo Browne
Gabriel De Andrade
Dara Adedeji
scratchyone
Dominic Roy
chukfinley
Primož Ajdišek
benthecarman
NaveDanan
aaditagrawal
Aditya Garud
Nick Anisimov
MacKinley Smith
Yordis Prieto
t3-code[bot]
AKolenda
Guillermo Casanova
Otavio Salvador
Shirish Pothi
Ishaan Kothari
Bob Fowler
Anton Bezdenezhnykh
ValeraZSD
Ephraim
Ryan Ilano
Alex
maco
Cursor
Tristan Knight
PR Batch Tester
oliver
kamkm
de34391427
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Bilal Bakr <[email protected]> Co-authored-by: shivam <[email protected]> Co-authored-by: Vitalii Yehorov <[email protected]> Co-authored-by: Jake Leventhal <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Alex Southwell <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Nicholas Wasmiller <[email protected]> Co-authored-by: PB <[email protected]> Co-authored-by: Exotic <[email protected]> Co-authored-by: Yash Singh <[email protected]> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Theo Browne <[email protected]> Co-authored-by: Gabriel De Andrade <[email protected]> Co-authored-by: Dara Adedeji <[email protected]> Co-authored-by: scratchyone <[email protected]> Co-authored-by: Dominic Roy <[email protected]> Co-authored-by: chukfinley <[email protected]> Co-authored-by: Primož Ajdišek <[email protected]> Co-authored-by: benthecarman <[email protected]> Co-authored-by: NaveDanan <[email protected]> Co-authored-by: aaditagrawal <[email protected]> Co-authored-by: Aditya Garud <[email protected]> Co-authored-by: Nick Anisimov <[email protected]> Co-authored-by: MacKinley Smith <[email protected]> Co-authored-by: Yordis Prieto <[email protected]> Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com> Co-authored-by: AKolenda <[email protected]> Co-authored-by: Guillermo Casanova <[email protected]> Co-authored-by: Otavio Salvador <[email protected]> Co-authored-by: Shirish Pothi <[email protected]> Co-authored-by: Ishaan Kothari <[email protected]> Co-authored-by: Bob Fowler <[email protected]> Co-authored-by: Anton Bezdenezhnykh <[email protected]> Co-authored-by: ValeraZSD <[email protected]> Co-authored-by: Ephraim <[email protected]> Co-authored-by: Ryan Ilano <[email protected]> Co-authored-by: Alex <[email protected]> Co-authored-by: maco <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: Tristan Knight <[email protected]> Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: oliver <[email protected]> Co-authored-by: kamkm <[email protected]> Signed-off-by: Yordis Prieto <[email protected]>
224 lines
9.1 KiB
TypeScript
224 lines
9.1 KiB
TypeScript
import * as Effect from "effect/Effect";
|
|
import * as Option from "effect/Option";
|
|
import * as Schema from "effect/Schema";
|
|
import * as SchemaTransformation from "effect/SchemaTransformation";
|
|
|
|
export const TrimmedString = Schema.String.pipe(
|
|
Schema.decodeTo(
|
|
Schema.String,
|
|
SchemaTransformation.transformEffect({
|
|
decode: (value) => Effect.succeed(value.trim()),
|
|
encode: (value) => Effect.succeed(value.trim()),
|
|
}),
|
|
),
|
|
);
|
|
export const TrimmedNonEmptyString = TrimmedString.check(Schema.isNonEmpty());
|
|
|
|
export const NonNegativeInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
|
|
export const PositiveInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(1));
|
|
export const PortSchema = Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 65535 }));
|
|
|
|
/**
|
|
* Safe categories for a failed DPoP proof. These describe the class of failure
|
|
* without exposing proof contents or server-side authentication details.
|
|
*/
|
|
export const DpopFailureReason = Schema.Literals([
|
|
"time_window",
|
|
"key_mismatch",
|
|
"request_mismatch",
|
|
"token_mismatch",
|
|
"replay",
|
|
"invalid_proof",
|
|
]);
|
|
export type DpopFailureReason = typeof DpopFailureReason.Type;
|
|
|
|
export const IsoDateTime = Schema.String;
|
|
export type IsoDateTime = typeof IsoDateTime.Type;
|
|
|
|
/**
|
|
* Wire codec for server→client arrays whose element unions grow over time
|
|
* (new literal members, new struct variants). Decoding drops elements the
|
|
* current build cannot decode instead of failing the whole payload — a client
|
|
* has to keep decoding configs sent by servers newer than itself, and
|
|
* rejecting the payload would take down the connection over data the client
|
|
* couldn't act on anyway. Encoding is the plain array encoding.
|
|
*/
|
|
/**
|
|
* Same idea for one optional value whose literal set grows over time: a
|
|
* member this build does not know decodes as absent rather than failing the
|
|
* enclosing struct. Encoding is the plain encoding.
|
|
*/
|
|
export const ForwardCompatibleOptional = <Value extends Schema.Top>(value: Value) => {
|
|
const decodeValue = Schema.decodeUnknownOption(value as never);
|
|
return Schema.optionalKey(
|
|
Schema.Unknown.pipe(
|
|
Schema.decodeTo(
|
|
Schema.UndefinedOr(value),
|
|
SchemaTransformation.transform<Value["Encoded"] | undefined, unknown>({
|
|
decode: (raw) =>
|
|
Option.isSome(decodeValue(raw)) ? (raw as Value["Encoded"]) : undefined,
|
|
encode: (raw) => raw,
|
|
}),
|
|
),
|
|
),
|
|
);
|
|
};
|
|
|
|
/**
|
|
* The nullable form, for a persisted setting whose literal set grows over
|
|
* time: a member this build does not know (or a missing key) decodes as null
|
|
* rather than failing the enclosing struct. Encoding is the plain encoding.
|
|
*/
|
|
export const ForwardCompatibleNullable = <Value extends Schema.Top>(value: Value) => {
|
|
const decodeValue = Schema.decodeUnknownOption(value as never);
|
|
return Schema.Unknown.pipe(
|
|
Schema.decodeTo(
|
|
Schema.NullOr(value),
|
|
SchemaTransformation.transform<Value["Encoded"] | null, unknown>({
|
|
decode: (raw) => (Option.isSome(decodeValue(raw)) ? (raw as Value["Encoded"]) : null),
|
|
encode: (raw) => raw,
|
|
}),
|
|
),
|
|
);
|
|
};
|
|
|
|
/**
|
|
* A nullable setting whose null is "unset" and never crosses the wire: it
|
|
* decodes from a missing or unknown key and encodes back to a missing key.
|
|
* For a field that older clients decode as a required literal, so a null
|
|
* on the wire would fail their whole settings snapshot.
|
|
*/
|
|
export const OmittedWhenNull = <Value extends Schema.Top>(value: Value) => {
|
|
const decodeValue = Schema.decodeUnknownOption(value as never);
|
|
return Schema.optionalKey(Schema.Unknown).pipe(
|
|
Schema.decodeTo(
|
|
Schema.NullOr(value),
|
|
SchemaTransformation.transformOptional<Value["Encoded"] | null, unknown>({
|
|
decode: (raw) =>
|
|
Option.some(
|
|
Option.isSome(raw) && Option.isSome(decodeValue(raw.value))
|
|
? (raw.value as Value["Encoded"])
|
|
: null,
|
|
),
|
|
encode: (raw) =>
|
|
Option.isSome(raw) && raw.value !== null ? Option.some(raw.value) : Option.none(),
|
|
}),
|
|
),
|
|
);
|
|
};
|
|
|
|
export const ForwardCompatibleArray = <Element extends Schema.Top>(element: Element) => {
|
|
const decodeElement = Schema.decodeUnknownOption(element as never);
|
|
return Schema.Array(Schema.Unknown).pipe(
|
|
Schema.decodeTo(
|
|
Schema.Array(element),
|
|
SchemaTransformation.transform<ReadonlyArray<Element["Encoded"]>, ReadonlyArray<unknown>>({
|
|
decode: (values) =>
|
|
values.filter((value) => Option.isSome(decodeElement(value))) as ReadonlyArray<
|
|
Element["Encoded"]
|
|
>,
|
|
encode: (values) => values,
|
|
}),
|
|
),
|
|
);
|
|
};
|
|
|
|
/**
|
|
* Construct a branded identifier. Enforces non-empty trimmed strings
|
|
*/
|
|
const makeEntityId = <Brand extends string>(brand: Brand) => {
|
|
return TrimmedNonEmptyString.pipe(Schema.brand(brand));
|
|
};
|
|
|
|
export const ThreadId = makeEntityId("ThreadId");
|
|
export type ThreadId = typeof ThreadId.Type;
|
|
export const ProjectId = makeEntityId("ProjectId");
|
|
export type ProjectId = typeof ProjectId.Type;
|
|
export const EnvironmentId = makeEntityId("EnvironmentId");
|
|
export type EnvironmentId = typeof EnvironmentId.Type;
|
|
export const CommandId = makeEntityId("CommandId");
|
|
export type CommandId = typeof CommandId.Type;
|
|
export const EventId = makeEntityId("EventId");
|
|
export type EventId = typeof EventId.Type;
|
|
export const MessageId = makeEntityId("MessageId");
|
|
export type MessageId = typeof MessageId.Type;
|
|
export const TurnId = makeEntityId("TurnId");
|
|
export type TurnId = typeof TurnId.Type;
|
|
export const RunId = makeEntityId("RunId");
|
|
export type RunId = typeof RunId.Type;
|
|
export const RunAttemptId = makeEntityId("RunAttemptId");
|
|
export type RunAttemptId = typeof RunAttemptId.Type;
|
|
export const NodeId = makeEntityId("NodeId");
|
|
export type NodeId = typeof NodeId.Type;
|
|
export const AuthSessionId = makeEntityId("AuthSessionId");
|
|
export type AuthSessionId = typeof AuthSessionId.Type;
|
|
export const RpcClientId = NonNegativeInt.pipe(Schema.brand("RpcClientId"));
|
|
export type RpcClientId = typeof RpcClientId.Type;
|
|
|
|
/**
|
|
* Which client surface a connection or command comes from. Unlike
|
|
* `AuthClientMetadataDeviceType` (a UA-style device class where web and
|
|
* desktop are both "desktop"), this names the actual product surface.
|
|
* Optional everywhere it appears: old clients never send it.
|
|
*/
|
|
export const ClientSurface = Schema.Literals(["web", "desktop", "mobile", "cli"]);
|
|
export type ClientSurface = typeof ClientSurface.Type;
|
|
|
|
export const ClientOs = Schema.Literals([
|
|
"macOS",
|
|
"Windows",
|
|
"Linux",
|
|
"iOS",
|
|
"Android",
|
|
"ChromeOS",
|
|
"other",
|
|
"unknown",
|
|
]);
|
|
export type ClientOs = typeof ClientOs.Type;
|
|
|
|
export const ClientDeviceType = Schema.Literals(["desktop", "phone", "tablet", "unknown"]);
|
|
export type ClientDeviceType = typeof ClientDeviceType.Type;
|
|
|
|
export const ClientWebDeployment = Schema.Literals(["hosted", "server"]);
|
|
export type ClientWebDeployment = typeof ClientWebDeployment.Type;
|
|
|
|
export const ClientConnectionMethod = Schema.Literals(["direct", "ssh", "relay", "unknown"]);
|
|
export type ClientConnectionMethod = typeof ClientConnectionMethod.Type;
|
|
|
|
export const ProviderItemId = makeEntityId("ProviderItemId");
|
|
export type ProviderItemId = typeof ProviderItemId.Type;
|
|
export const ProviderSessionId = makeEntityId("ProviderSessionId");
|
|
export type ProviderSessionId = typeof ProviderSessionId.Type;
|
|
export const ProviderThreadId = makeEntityId("ProviderThreadId");
|
|
export type ProviderThreadId = typeof ProviderThreadId.Type;
|
|
export const ProviderTurnId = makeEntityId("ProviderTurnId");
|
|
export type ProviderTurnId = typeof ProviderTurnId.Type;
|
|
export const RuntimeSessionId = makeEntityId("RuntimeSessionId");
|
|
export type RuntimeSessionId = typeof RuntimeSessionId.Type;
|
|
export const RuntimeItemId = makeEntityId("RuntimeItemId");
|
|
export type RuntimeItemId = typeof RuntimeItemId.Type;
|
|
export const TurnItemId = makeEntityId("TurnItemId");
|
|
export type TurnItemId = typeof TurnItemId.Type;
|
|
export const RuntimeRequestId = makeEntityId("RuntimeRequestId");
|
|
export type RuntimeRequestId = typeof RuntimeRequestId.Type;
|
|
export const RuntimeTaskId = makeEntityId("RuntimeTaskId");
|
|
export type RuntimeTaskId = typeof RuntimeTaskId.Type;
|
|
export const ScheduledTaskId = makeEntityId("ScheduledTaskId");
|
|
export type ScheduledTaskId = typeof ScheduledTaskId.Type;
|
|
export const ApprovalRequestId = makeEntityId("ApprovalRequestId");
|
|
export type ApprovalRequestId = typeof ApprovalRequestId.Type;
|
|
export const CheckpointRef = makeEntityId("CheckpointRef");
|
|
export type CheckpointRef = typeof CheckpointRef.Type;
|
|
export const CheckpointId = makeEntityId("CheckpointId");
|
|
export type CheckpointId = typeof CheckpointId.Type;
|
|
export const CheckpointScopeId = makeEntityId("CheckpointScopeId");
|
|
export type CheckpointScopeId = typeof CheckpointScopeId.Type;
|
|
export const ContextHandoffId = makeEntityId("ContextHandoffId");
|
|
export type ContextHandoffId = typeof ContextHandoffId.Type;
|
|
export const ContextTransferId = makeEntityId("ContextTransferId");
|
|
export type ContextTransferId = typeof ContextTransferId.Type;
|
|
export const RawEventId = makeEntityId("RawEventId");
|
|
export type RawEventId = typeof RawEventId.Type;
|
|
export const PlanId = makeEntityId("PlanId");
|
|
export type PlanId = typeof PlanId.Type;
|