experimental-a2 0.0.0

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 (68) hide show
  1. package/CHANGELOG.md +128 -0
  2. package/dist/ai-server.browser.d.ts +1 -0
  3. package/dist/ai-server.browser.js +4 -0
  4. package/dist/ai-server.d.ts +65 -0
  5. package/dist/ai-server.js +494 -0
  6. package/dist/ai.d.ts +282 -0
  7. package/dist/ai.js +922 -0
  8. package/dist/cache-indexeddb.d.ts +1 -0
  9. package/dist/cache-indexeddb.js +0 -0
  10. package/dist/client.d.ts +90 -0
  11. package/dist/client.js +410 -0
  12. package/dist/contract-B0kAXoaL.js +60 -0
  13. package/dist/contract-DL8btVd9.d.ts +161 -0
  14. package/dist/devtools-server.browser.d.ts +1 -0
  15. package/dist/devtools-server.browser.js +4 -0
  16. package/dist/devtools-server.d.ts +22 -0
  17. package/dist/devtools-server.js +1087 -0
  18. package/dist/errors-BJRMd-h6.js +23 -0
  19. package/dist/errors-xL_JTXsY.d.ts +20 -0
  20. package/dist/http.d.ts +44 -0
  21. package/dist/http.js +119 -0
  22. package/dist/index.d.ts +5 -0
  23. package/dist/index.js +3 -0
  24. package/dist/inspection-E7qbD0Xj.js +10 -0
  25. package/dist/internal-Dm8Ejnud.js +36 -0
  26. package/dist/log-Dg1I8NRr.d.ts +245 -0
  27. package/dist/log-memory.d.ts +11 -0
  28. package/dist/log-memory.js +345 -0
  29. package/dist/log-polling-RO7kclzR.js +83 -0
  30. package/dist/log-postgres.d.ts +40 -0
  31. package/dist/log-postgres.js +628 -0
  32. package/dist/log-redis.d.ts +31 -0
  33. package/dist/log-redis.js +711 -0
  34. package/dist/log-sqlite.d.ts +17 -0
  35. package/dist/log-sqlite.js +450 -0
  36. package/dist/log-yJbXUf72.js +5 -0
  37. package/dist/otel.d.ts +12 -0
  38. package/dist/otel.js +41 -0
  39. package/dist/react.d.ts +54 -0
  40. package/dist/react.js +85 -0
  41. package/dist/recovery-vercel.d.ts +60 -0
  42. package/dist/recovery-vercel.js +120 -0
  43. package/dist/retryable-lazy-DZWmHpii.js +19 -0
  44. package/dist/server-DYsnKTTy.js +780 -0
  45. package/dist/server.browser.d.ts +1 -0
  46. package/dist/server.browser.js +11 -0
  47. package/dist/server.d.ts +136 -0
  48. package/dist/server.js +2 -0
  49. package/dist/telemetry-C78al20p.d.ts +32 -0
  50. package/dist/validate-XKT4FSNn.js +28 -0
  51. package/dist/wire-2QpU1EtJ.js +62 -0
  52. package/docs/01-quickstart.mdx +214 -0
  53. package/docs/concepts/01-contracts.mdx +138 -0
  54. package/docs/concepts/02-handlers.mdx +146 -0
  55. package/docs/concepts/03-durability.mdx +230 -0
  56. package/docs/concepts/04-state.mdx +133 -0
  57. package/docs/guides/01-timers.mdx +85 -0
  58. package/docs/guides/02-cancellation.mdx +107 -0
  59. package/docs/guides/03-react.mdx +234 -0
  60. package/docs/guides/04-local-first.mdx +88 -0
  61. package/docs/guides/05-production.mdx +179 -0
  62. package/docs/guides/06-ai-agents.mdx +659 -0
  63. package/docs/guides/07-devtools.mdx +101 -0
  64. package/docs/guides/08-application-data.mdx +114 -0
  65. package/docs/index.mdx +282 -0
  66. package/docs/reference/01-api.mdx +637 -0
  67. package/docs/reference/02-errors.mdx +77 -0
  68. package/package.json +111 -0
@@ -0,0 +1,161 @@
1
+ //#region src/standard-schema.d.ts
2
+ /**
3
+ * The Standard Schema interface, vendored per the spec's guidance
4
+ * (https://standardschema.dev — the interface is designed to be copied
5
+ * into libraries rather than depended on). Types only; nothing here
6
+ * exists at runtime.
7
+ */
8
+ /** The Standard Schema interface. */
9
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
10
+ /** The Standard Schema properties. */
11
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
12
+ }
13
+ declare namespace StandardSchemaV1 {
14
+ /** The Standard Schema properties interface. */
15
+ export interface Props<Input = unknown, Output = Input> {
16
+ /** The version number of the standard. */
17
+ readonly version: 1;
18
+ /** The vendor name of the schema library. */
19
+ readonly vendor: string;
20
+ /** Validates unknown input values. */
21
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
22
+ /** Inferred types associated with the schema. */
23
+ readonly types?: Types<Input, Output> | undefined;
24
+ }
25
+ /** The result interface of the validate function. */
26
+ export type Result<Output> = SuccessResult<Output> | FailureResult;
27
+ /** The result interface if validation succeeds. */
28
+ export interface SuccessResult<Output> {
29
+ /** The typed output value. */
30
+ readonly value: Output;
31
+ /** The non-existent issues. */
32
+ readonly issues?: undefined;
33
+ }
34
+ /** The result interface if validation fails. */
35
+ export interface FailureResult {
36
+ /** The issues of failed validation. */
37
+ readonly issues: ReadonlyArray<Issue>;
38
+ }
39
+ /** The issue interface of the failure output. */
40
+ export interface Issue {
41
+ /** The error message of the issue. */
42
+ readonly message: string;
43
+ /** The path of the issue, if any. */
44
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
45
+ }
46
+ /** The path segment interface of the issue. */
47
+ export interface PathSegment {
48
+ /** The key representing a path segment. */
49
+ readonly key: PropertyKey;
50
+ }
51
+ /** The Standard Schema types interface. */
52
+ export interface Types<Input = unknown, Output = Input> {
53
+ /** The input type of the schema. */
54
+ readonly input: Input;
55
+ /** The output type of the schema. */
56
+ readonly output: Output;
57
+ }
58
+ /** Infers the input type of a Standard Schema. */
59
+ export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
60
+ /** Infers the output type of a Standard Schema. */
61
+ export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
62
+ }
63
+ //#endregion
64
+ //#region src/reducer.d.ts
65
+ /**
66
+ * A pure fold over a session's events — `(state, event) => state` —
67
+ * derived from a contract via `contract.reducer(options).fold(fn)`.
68
+ *
69
+ * The name is the reducer's identity. Cached folds (server snapshots,
70
+ * the browser cache) are keyed by it, which makes it the invalidation
71
+ * knob too: changed the fold's logic? Change the name. Snapshots under
72
+ * the old name are ignored and the next read refolds from raw events.
73
+ * See docs/concepts/04-state.mdx.
74
+ */
75
+ type Reducer<D extends EventDefs = EventDefs, S = unknown> = {
76
+ /** Identity and cache key. Rename when the fold's logic changes. */
77
+ readonly name: string;
78
+ /** The contract's vocabulary — types every event in the fold. */
79
+ readonly events: Readonly<D>;
80
+ readonly fold: (state: S, event: ContractEvent<D>) => S;
81
+ readonly initialState: S;
82
+ /**
83
+ * When present: `initialState` was validated against it at
84
+ * definition, and any cached fold a2 rehydrates (server snapshots,
85
+ * the browser cache) is checked against it — failing snapshots are
86
+ * discarded and refolded, catching shape drift a stale name can't.
87
+ */
88
+ readonly stateSchema: StandardSchemaV1<unknown, S> | undefined;
89
+ };
90
+ /** The second step of `contract.reducer` — see the method's doc. */
91
+ type ReducerBuilder<D extends EventDefs, S> = {
92
+ fold(fold: (state: S, event: ContractEvent<D>) => S): Reducer<D, S>;
93
+ };
94
+ //#endregion
95
+ //#region src/contract.d.ts
96
+ /** The event vocabulary shape: event name → payload schema. */
97
+ type EventDefs = Record<string, StandardSchemaV1>;
98
+ /** One event of a contract, narrowed to type `K`. */
99
+ type ContractEvent<D extends EventDefs, K extends keyof D & string = keyof D & string> = { [T in keyof D & string]: {
100
+ id: string;
101
+ type: T;
102
+ payload: StandardSchemaV1.InferOutput<D[T]>;
103
+ index: number;
104
+ sessionId: string;
105
+ createdAt: Date;
106
+ }; }[K];
107
+ /** Input to `append`/`push`, typed against the contract's schemas. */
108
+ type AppendInput<D extends EventDefs> = { [T in keyof D & string]: {
109
+ type: T;
110
+ payload: StandardSchemaV1.InferInput<D[T]>;
111
+ id?: string;
112
+ }; }[keyof D & string];
113
+ type ReducerOptions<Seed, S> = {
114
+ /**
115
+ * Identity and snapshot cache key. Rename it when the fold's logic
116
+ * changes — snapshots under the old name are ignored and refolded.
117
+ */
118
+ name: string;
119
+ /**
120
+ * The seed the fold starts from. With a `stateSchema`, it's typed as
121
+ * the schema's *input*: validated at definition, and the validated
122
+ * output (defaults applied) is what the fold actually starts from.
123
+ */
124
+ initialState: Seed;
125
+ /**
126
+ * Optional: declares the state's shape (the fold's state type becomes
127
+ * the schema's output) and guards cached folds — server snapshots and
128
+ * the browser cache reject mismatching shapes and refold.
129
+ */
130
+ stateSchema?: StandardSchemaV1<Seed, S>;
131
+ };
132
+ type Contract<D extends EventDefs = EventDefs> = {
133
+ /** Identity — prefixes storage keys and queue messages. */
134
+ readonly name: string;
135
+ /** The vocabulary. */
136
+ readonly events: Readonly<D>;
137
+ /**
138
+ * Derive a view from this contract. The reducer's `name` is its
139
+ * identity and snapshot cache key: rename it when the fold's logic
140
+ * changes. Two steps by design: this call fixes the state and event
141
+ * types, so `.fold()` receives fully concrete types — literal unions
142
+ * in your state survive, with zero annotations. (A single call can't
143
+ * do this: TypeScript never contextually types the returns of a
144
+ * context-sensitive argument against generics inferred in the same
145
+ * call.)
146
+ */
147
+ reducer<Seed, S = Seed>(options: ReducerOptions<Seed, S>): ReducerBuilder<D, S>;
148
+ };
149
+ /**
150
+ * Define a contract: a name plus the events it understands. Validators
151
+ * must be synchronous — async ones are rejected here, at definition
152
+ * time. The result is a plain, importable, isomorphic value.
153
+ */
154
+ declare function contract<D extends EventDefs>(options: {
155
+ /** Identity — prefixes storage keys and queue messages. */
156
+ name: string;
157
+ /** The vocabulary: event name → payload schema (Standard Schema). */
158
+ events: D;
159
+ }): Contract<D>;
160
+ //#endregion
161
+ export { ReducerOptions as a, ReducerBuilder as c, EventDefs as i, StandardSchemaV1 as l, Contract as n, contract as o, ContractEvent as r, Reducer as s, AppendInput as t };
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1,4 @@
1
+ //#region src/devtools-server.browser.ts
2
+ /** a2/devtools/server owns log access and is server-only. */
3
+ throw new Error("a2/devtools/server is server-only — mount its handler in a server route and open that URL in the browser.");
4
+ //#endregion
@@ -0,0 +1,22 @@
1
+ //#region src/devtools-server.d.ts
2
+ type DevtoolsServer = {
3
+ readonly contract: {
4
+ readonly name: string;
5
+ };
6
+ };
7
+ type DevtoolsAuthorization = (request: Request) => boolean | Response | Promise<boolean | Response>;
8
+ type DevtoolsOptions = {
9
+ servers: readonly DevtoolsServer[];
10
+ /**
11
+ * Application-owned access control. Returning a Response short-circuits
12
+ * the request. Without this option, devtools is available outside
13
+ * production and returns 404 in production.
14
+ */
15
+ authorize?: DevtoolsAuthorization;
16
+ };
17
+ type Devtools = {
18
+ handler(): (request: Request) => Promise<Response>;
19
+ };
20
+ declare function createDevtools(options: DevtoolsOptions): Devtools;
21
+ //#endregion
22
+ export { Devtools, DevtoolsAuthorization, DevtoolsOptions, DevtoolsServer, createDevtools };