@autumnsgrove/lyra 0.2.0 → 0.3.1

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 (138) hide show
  1. package/dist/adapters/cloudflare/index.d.ts +1 -0
  2. package/dist/adapters/cloudflare/index.d.ts.map +1 -1
  3. package/dist/adapters/cloudflare/index.js +1 -0
  4. package/dist/adapters/cloudflare/index.js.map +1 -1
  5. package/dist/adapters/cloudflare/session.d.ts +102 -0
  6. package/dist/adapters/cloudflare/session.d.ts.map +1 -0
  7. package/dist/adapters/cloudflare/session.js +595 -0
  8. package/dist/adapters/cloudflare/session.js.map +1 -0
  9. package/dist/core/approval.d.ts +38 -0
  10. package/dist/core/approval.d.ts.map +1 -0
  11. package/dist/core/approval.js +47 -0
  12. package/dist/core/approval.js.map +1 -0
  13. package/dist/core/compaction.d.ts +193 -0
  14. package/dist/core/compaction.d.ts.map +1 -0
  15. package/dist/core/compaction.js +460 -0
  16. package/dist/core/compaction.js.map +1 -0
  17. package/dist/core/define-recipe.d.ts +8 -1
  18. package/dist/core/define-recipe.d.ts.map +1 -1
  19. package/dist/core/define-recipe.js +13 -0
  20. package/dist/core/define-recipe.js.map +1 -1
  21. package/dist/core/events.d.ts +32 -2
  22. package/dist/core/events.d.ts.map +1 -1
  23. package/dist/core/events.js +16 -1
  24. package/dist/core/events.js.map +1 -1
  25. package/dist/core/execute-tools.d.ts +7 -0
  26. package/dist/core/execute-tools.d.ts.map +1 -1
  27. package/dist/core/execute-tools.js +6 -0
  28. package/dist/core/execute-tools.js.map +1 -1
  29. package/dist/core/hash.d.ts +10 -0
  30. package/dist/core/hash.d.ts.map +1 -0
  31. package/dist/core/hash.js +14 -0
  32. package/dist/core/hash.js.map +1 -0
  33. package/dist/core/model.d.ts +12 -0
  34. package/dist/core/model.d.ts.map +1 -1
  35. package/dist/core/propose.d.ts +29 -0
  36. package/dist/core/propose.d.ts.map +1 -0
  37. package/dist/core/propose.js +75 -0
  38. package/dist/core/propose.js.map +1 -0
  39. package/dist/core/recipe.d.ts +2 -0
  40. package/dist/core/recipe.d.ts.map +1 -1
  41. package/dist/core/recipe.js +5 -8
  42. package/dist/core/recipe.js.map +1 -1
  43. package/dist/core/resume.d.ts +19 -1
  44. package/dist/core/resume.d.ts.map +1 -1
  45. package/dist/core/resume.js +64 -6
  46. package/dist/core/resume.js.map +1 -1
  47. package/dist/core/retry.d.ts +9 -0
  48. package/dist/core/retry.d.ts.map +1 -0
  49. package/dist/core/retry.js +9 -0
  50. package/dist/core/retry.js.map +1 -0
  51. package/dist/core/run-handle.d.ts +5 -0
  52. package/dist/core/run-handle.d.ts.map +1 -1
  53. package/dist/core/run-handle.js +1 -0
  54. package/dist/core/run-handle.js.map +1 -1
  55. package/dist/core/run.d.ts +29 -2
  56. package/dist/core/run.d.ts.map +1 -1
  57. package/dist/core/run.js +526 -132
  58. package/dist/core/run.js.map +1 -1
  59. package/dist/core/runtime.d.ts +12 -0
  60. package/dist/core/runtime.d.ts.map +1 -1
  61. package/dist/core/runtime.js +34 -2
  62. package/dist/core/runtime.js.map +1 -1
  63. package/dist/core/tool.d.ts +55 -0
  64. package/dist/core/tool.d.ts.map +1 -1
  65. package/dist/core/tool.js +16 -0
  66. package/dist/core/tool.js.map +1 -1
  67. package/dist/core/usage.d.ts +27 -0
  68. package/dist/core/usage.d.ts.map +1 -0
  69. package/dist/core/usage.js +67 -0
  70. package/dist/core/usage.js.map +1 -0
  71. package/dist/index.d.ts +7 -0
  72. package/dist/index.d.ts.map +1 -1
  73. package/dist/index.js +7 -0
  74. package/dist/index.js.map +1 -1
  75. package/dist/protocol/answers.d.ts +33 -0
  76. package/dist/protocol/answers.d.ts.map +1 -0
  77. package/dist/protocol/answers.js +86 -0
  78. package/dist/protocol/answers.js.map +1 -0
  79. package/dist/protocol/commands.d.ts +84 -0
  80. package/dist/protocol/commands.d.ts.map +1 -0
  81. package/dist/protocol/commands.js +232 -0
  82. package/dist/protocol/commands.js.map +1 -0
  83. package/dist/protocol/events.d.ts +145 -0
  84. package/dist/protocol/events.d.ts.map +1 -0
  85. package/dist/protocol/events.js +195 -0
  86. package/dist/protocol/events.js.map +1 -0
  87. package/dist/protocol/frames.d.ts +72 -0
  88. package/dist/protocol/frames.d.ts.map +1 -0
  89. package/dist/protocol/frames.js +134 -0
  90. package/dist/protocol/frames.js.map +1 -0
  91. package/dist/protocol/http.d.ts +52 -0
  92. package/dist/protocol/http.d.ts.map +1 -0
  93. package/dist/protocol/http.js +357 -0
  94. package/dist/protocol/http.js.map +1 -0
  95. package/dist/protocol/reader.d.ts +35 -0
  96. package/dist/protocol/reader.d.ts.map +1 -0
  97. package/dist/protocol/reader.js +71 -0
  98. package/dist/protocol/reader.js.map +1 -0
  99. package/dist/protocol/session.d.ts +85 -0
  100. package/dist/protocol/session.d.ts.map +1 -0
  101. package/dist/protocol/session.js +801 -0
  102. package/dist/protocol/session.js.map +1 -0
  103. package/dist/record/entries.d.ts +110 -2
  104. package/dist/record/entries.d.ts.map +1 -1
  105. package/dist/record/entries.js +337 -10
  106. package/dist/record/entries.js.map +1 -1
  107. package/dist/record/replay.d.ts +6 -0
  108. package/dist/record/replay.d.ts.map +1 -1
  109. package/dist/record/replay.js +11 -3
  110. package/dist/record/replay.js.map +1 -1
  111. package/dist/record/truncate.d.ts +12 -0
  112. package/dist/record/truncate.d.ts.map +1 -1
  113. package/dist/record/truncate.js +72 -1
  114. package/dist/record/truncate.js.map +1 -1
  115. package/dist/testkit/fake-model-server.d.ts +17 -0
  116. package/dist/testkit/fake-model-server.d.ts.map +1 -1
  117. package/dist/testkit/fake-model-server.js +33 -7
  118. package/dist/testkit/fake-model-server.js.map +1 -1
  119. package/dist/testkit/index.d.ts +9 -1
  120. package/dist/testkit/index.d.ts.map +1 -1
  121. package/dist/testkit/index.js +9 -1
  122. package/dist/testkit/index.js.map +1 -1
  123. package/dist/testkit/model.d.ts +18 -0
  124. package/dist/testkit/model.d.ts.map +1 -1
  125. package/dist/testkit/model.js +47 -1
  126. package/dist/testkit/model.js.map +1 -1
  127. package/dist/testkit/scenario.d.ts +26 -2
  128. package/dist/testkit/scenario.d.ts.map +1 -1
  129. package/dist/testkit/scenario.js +97 -14
  130. package/dist/testkit/scenario.js.map +1 -1
  131. package/dist/testkit/timeline-recipe.d.ts.map +1 -1
  132. package/dist/testkit/timeline-recipe.js +3 -0
  133. package/dist/testkit/timeline-recipe.js.map +1 -1
  134. package/dist/testkit/tools.d.ts +15 -1
  135. package/dist/testkit/tools.d.ts.map +1 -1
  136. package/dist/testkit/tools.js +19 -0
  137. package/dist/testkit/tools.js.map +1 -1
  138. package/package.json +1 -1
@@ -6,6 +6,7 @@
6
6
  * imports this, and this imports the core and nothing else.
7
7
  */
8
8
  export * from "./secrets.js";
9
+ export * from "./session.js";
9
10
  export * from "./storage.js";
10
11
  export * from "./waking.js";
11
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/cloudflare/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/cloudflare/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
@@ -6,6 +6,7 @@
6
6
  * imports this, and this imports the core and nothing else.
7
7
  */
8
8
  export * from "./secrets.js";
9
+ export * from "./session.js";
9
10
  export * from "./storage.js";
10
11
  export * from "./waking.js";
11
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/adapters/cloudflare/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/adapters/cloudflare/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * A session as a Durable Object, and the Worker that routes to it
3
+ * (docs/implementation/06-protocol-http.md, slice 5; decisions 12, 45 and 47).
4
+ *
5
+ * One object is one session, so one record, one run and one alarm, which is what
6
+ * the storage and waking adapters already assume. The object answers the protocol
7
+ * through the same handler a test and `wrangler dev` use, resumes itself through
8
+ * its alarm, and offers a second door for a trusted Grove worker: a method that
9
+ * names the tenant, because a service binding has no bearer token and a binding's
10
+ * caller is not reachable from the public `fetch` route at all.
11
+ *
12
+ * The types here are structural, like the storage and waking adapters': the core
13
+ * builds with no platform types, and a Worker's real `DurableObjectState` and
14
+ * namespace satisfy these shapes.
15
+ */
16
+ import type { Clock, Ids } from "../../core/clock.js";
17
+ import type { ModelSlot } from "../../core/model.js";
18
+ import { type Result } from "../../core/result.js";
19
+ import { type RunDefinition } from "../../core/runtime.js";
20
+ import { type DurableObjectAlarmStorage } from "./waking.js";
21
+ /** What this adapter needs from a Durable Object's id, and nothing else. */
22
+ export interface DurableObjectIdLike {
23
+ toString(): string;
24
+ }
25
+ /** What it needs from a stub: a request in, a response out. */
26
+ export interface DurableObjectStubLike {
27
+ fetch(request: Request): Promise<Response>;
28
+ }
29
+ /** What it needs from the namespace: the three ways to name an object. */
30
+ export interface DurableObjectNamespaceLike {
31
+ idFromName(name: string): DurableObjectIdLike;
32
+ idFromString(hex: string): DurableObjectIdLike;
33
+ newUniqueId(): DurableObjectIdLike;
34
+ get(id: DurableObjectIdLike): DurableObjectStubLike;
35
+ }
36
+ /** What a session object needs from its `DurableObjectState`. */
37
+ export interface DurableObjectStateLike {
38
+ readonly id: DurableObjectIdLike;
39
+ readonly storage: DurableObjectAlarmStorage;
40
+ /** Hibernating sockets: the platform keeps them and wakes the object for a frame. */
41
+ acceptWebSocket(socket: WebSocket): void;
42
+ getWebSockets(): WebSocket[];
43
+ }
44
+ export interface CloudflareSessionOptions {
45
+ /** The tasks this host runs, by name. A Worker's own code is where these come from. */
46
+ recipes: ReadonlyMap<string, RunDefinition>;
47
+ model: ModelSlot;
48
+ clock: Clock;
49
+ ids: Ids;
50
+ /** Tenant to token, from a secret binding. Never logged, never recorded. */
51
+ tokens: Readonly<Record<string, string>>;
52
+ host: string;
53
+ /** How many events may queue for one watching client before it is dropped. */
54
+ maxQueuedEvents?: number;
55
+ /** How many bytes may queue for one socket before it is closed with 1008. */
56
+ maxQueuedBytes?: number;
57
+ }
58
+ export interface CloudflareSession {
59
+ /** The public door: the protocol over HTTP, with a bearer token. */
60
+ fetch(request: Request): Promise<Response>;
61
+ /** The object's alarm, which continues a run whose host died. */
62
+ alarm(): Promise<void>;
63
+ /** Hibernating sockets: the platform wakes the object for a frame or a close. */
64
+ webSocketMessage(socket: WebSocket, message: string | ArrayBuffer): Promise<void>;
65
+ webSocketClose(socket: WebSocket, code: number, reason: string): void;
66
+ webSocketError(socket: WebSocket): void;
67
+ /**
68
+ * The trusted door: run one command frame for a tenant a service binding named.
69
+ * It answers with the response frame, exactly as the wire would, so the caller
70
+ * needs no second parser.
71
+ */
72
+ send(request: {
73
+ tenant: string;
74
+ frame: string;
75
+ }): Promise<string>;
76
+ }
77
+ /**
78
+ * The object id a `start` lands on: the named session, the tenant and idempotency
79
+ * key, or a fresh one. A repeated command with the same key therefore reaches the
80
+ * same object, which is what makes a cron retry safe (`CMD02`, `CMD03`).
81
+ */
82
+ export declare function sessionIdFor(namespace: DurableObjectNamespaceLike, request: {
83
+ tenant: string;
84
+ session?: string;
85
+ key?: string;
86
+ }): Result<DurableObjectIdLike>;
87
+ export declare function createCloudflareSession(state: DurableObjectStateLike, options: CloudflareSessionOptions): CloudflareSession;
88
+ export interface CloudflareWorkerOptions {
89
+ namespace: DurableObjectNamespaceLike;
90
+ tokens: Readonly<Record<string, string>>;
91
+ /** How many events may queue for one client; passed through to the object. */
92
+ maxQueuedEvents?: number;
93
+ }
94
+ /**
95
+ * The public `fetch` of a Worker whose sessions are Durable Objects: it authenticates,
96
+ * finds which object the request is about, and hands the request over. The service
97
+ * binding's entry point is the host's own class (a `WorkerEntrypoint` with a method
98
+ * that calls the object's `send`), because declaring one needs the Workers runtime's
99
+ * types, which the core's program does not have.
100
+ */
101
+ export declare function createSessionWorker(options: CloudflareWorkerOptions): (request: Request) => Promise<Response>;
102
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/adapters/cloudflare/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAY,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAiB,KAAK,aAAa,EAAgB,MAAM,uBAAuB,CAAC;AAgBxF,OAAO,EAA8B,KAAK,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAEzF,4EAA4E;AAC5E,MAAM,WAAW,mBAAmB;IACnC,QAAQ,IAAI,MAAM,CAAC;CACnB;AAED,+DAA+D;AAC/D,MAAM,WAAW,qBAAqB;IACrC,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC3C;AAED,0EAA0E;AAC1E,MAAM,WAAW,0BAA0B;IAC1C,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,CAAC;IAC9C,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,mBAAmB,CAAC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