zeitlich 0.2.45 → 0.2.47

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 (109) hide show
  1. package/README.md +137 -11
  2. package/dist/{activities-Coafq5zr.d.cts → activities-CPwKoUlD.d.cts} +22 -2
  3. package/dist/{activities-CrN-ghLo.d.ts → activities-DlaBxNID.d.ts} +22 -2
  4. package/dist/adapters/thread/anthropic/index.cjs +276 -71
  5. package/dist/adapters/thread/anthropic/index.cjs.map +1 -1
  6. package/dist/adapters/thread/anthropic/index.d.cts +62 -8
  7. package/dist/adapters/thread/anthropic/index.d.ts +62 -8
  8. package/dist/adapters/thread/anthropic/index.js +275 -72
  9. package/dist/adapters/thread/anthropic/index.js.map +1 -1
  10. package/dist/adapters/thread/anthropic/workflow.cjs +38 -20
  11. package/dist/adapters/thread/anthropic/workflow.cjs.map +1 -1
  12. package/dist/adapters/thread/anthropic/workflow.d.cts +5 -4
  13. package/dist/adapters/thread/anthropic/workflow.d.ts +5 -4
  14. package/dist/adapters/thread/anthropic/workflow.js +38 -20
  15. package/dist/adapters/thread/anthropic/workflow.js.map +1 -1
  16. package/dist/adapters/thread/google-genai/index.cjs +171 -69
  17. package/dist/adapters/thread/google-genai/index.cjs.map +1 -1
  18. package/dist/adapters/thread/google-genai/index.d.cts +6 -4
  19. package/dist/adapters/thread/google-genai/index.d.ts +6 -4
  20. package/dist/adapters/thread/google-genai/index.js +171 -69
  21. package/dist/adapters/thread/google-genai/index.js.map +1 -1
  22. package/dist/adapters/thread/google-genai/workflow.cjs +38 -20
  23. package/dist/adapters/thread/google-genai/workflow.cjs.map +1 -1
  24. package/dist/adapters/thread/google-genai/workflow.d.cts +7 -4
  25. package/dist/adapters/thread/google-genai/workflow.d.ts +7 -4
  26. package/dist/adapters/thread/google-genai/workflow.js +38 -20
  27. package/dist/adapters/thread/google-genai/workflow.js.map +1 -1
  28. package/dist/adapters/thread/langchain/index.cjs +170 -66
  29. package/dist/adapters/thread/langchain/index.cjs.map +1 -1
  30. package/dist/adapters/thread/langchain/index.d.cts +19 -4
  31. package/dist/adapters/thread/langchain/index.d.ts +19 -4
  32. package/dist/adapters/thread/langchain/index.js +170 -66
  33. package/dist/adapters/thread/langchain/index.js.map +1 -1
  34. package/dist/adapters/thread/langchain/workflow.cjs +38 -20
  35. package/dist/adapters/thread/langchain/workflow.cjs.map +1 -1
  36. package/dist/adapters/thread/langchain/workflow.d.cts +5 -4
  37. package/dist/adapters/thread/langchain/workflow.d.ts +5 -4
  38. package/dist/adapters/thread/langchain/workflow.js +38 -20
  39. package/dist/adapters/thread/langchain/workflow.js.map +1 -1
  40. package/dist/cold-store-BDgJpwLI.d.ts +114 -0
  41. package/dist/cold-store-Z2wvK2cV.d.cts +114 -0
  42. package/dist/index.cjs +440 -67
  43. package/dist/index.cjs.map +1 -1
  44. package/dist/index.d.cts +150 -8
  45. package/dist/index.d.ts +150 -8
  46. package/dist/index.js +432 -68
  47. package/dist/index.js.map +1 -1
  48. package/dist/proxy-CDh3Rsa7.d.cts +40 -0
  49. package/dist/proxy-Du8ggERu.d.ts +40 -0
  50. package/dist/{thread-manager-wRVVBFgj.d.cts → thread-manager-BjoYYXgd.d.cts} +8 -2
  51. package/dist/{thread-manager-BsLO3Fgc.d.cts → thread-manager-D8zKNFZ9.d.cts} +8 -2
  52. package/dist/{thread-manager-Bi1XlbpJ.d.ts → thread-manager-DtHYws2F.d.ts} +8 -2
  53. package/dist/{thread-manager-BhkOyQ1I.d.ts → thread-manager-Dw96FKH1.d.ts} +8 -2
  54. package/dist/{types-C66-BVBr.d.cts → types-BMJrsHo0.d.cts} +17 -1
  55. package/dist/{types-BkX4HLzi.d.ts → types-CtdOquo3.d.ts} +17 -1
  56. package/dist/{types-CdALEF3z.d.cts → types-DNEl5uxQ.d.cts} +38 -0
  57. package/dist/{types-ChAy_jSP.d.ts → types-qQVZfhoT.d.ts} +38 -0
  58. package/dist/{workflow-DMmiaw6w.d.cts → workflow-BH9ImDGq.d.cts} +48 -2
  59. package/dist/{workflow-BwT5EybR.d.ts → workflow-Cdw3-RNB.d.ts} +48 -2
  60. package/dist/workflow.cjs +47 -4
  61. package/dist/workflow.cjs.map +1 -1
  62. package/dist/workflow.d.cts +2 -2
  63. package/dist/workflow.d.ts +2 -2
  64. package/dist/workflow.js +47 -5
  65. package/dist/workflow.js.map +1 -1
  66. package/package.json +14 -3
  67. package/src/adapters/thread/anthropic/activities.ts +82 -39
  68. package/src/adapters/thread/anthropic/index.ts +8 -0
  69. package/src/adapters/thread/anthropic/model-invoker.test.ts +110 -0
  70. package/src/adapters/thread/anthropic/model-invoker.ts +26 -5
  71. package/src/adapters/thread/anthropic/prompt-cache.test.ts +134 -0
  72. package/src/adapters/thread/anthropic/prompt-cache.ts +163 -0
  73. package/src/adapters/thread/anthropic/proxy.ts +1 -0
  74. package/src/adapters/thread/anthropic/thread-manager.ts +9 -1
  75. package/src/adapters/thread/google-genai/activities.ts +64 -40
  76. package/src/adapters/thread/google-genai/proxy.ts +1 -0
  77. package/src/adapters/thread/google-genai/thread-manager.ts +9 -1
  78. package/src/adapters/thread/langchain/activities.ts +63 -36
  79. package/src/adapters/thread/langchain/proxy.ts +1 -0
  80. package/src/adapters/thread/langchain/thread-manager.ts +9 -1
  81. package/src/index.ts +21 -2
  82. package/src/lib/session/session-edge-cases.integration.test.ts +12 -0
  83. package/src/lib/session/session.integration.test.ts +138 -0
  84. package/src/lib/session/session.ts +29 -0
  85. package/src/lib/session/types.ts +22 -0
  86. package/src/lib/subagent/define.ts +1 -0
  87. package/src/lib/subagent/handler.ts +11 -2
  88. package/src/lib/subagent/subagent.integration.test.ts +139 -0
  89. package/src/lib/subagent/types.ts +16 -0
  90. package/src/lib/thread/cold-store.test.ts +221 -0
  91. package/src/lib/thread/cold-store.ts +269 -0
  92. package/src/lib/thread/index.ts +32 -0
  93. package/src/lib/thread/keys.ts +20 -0
  94. package/src/lib/thread/manager.ts +16 -27
  95. package/src/lib/thread/proxy.ts +79 -27
  96. package/src/lib/thread/snapshot.test.ts +443 -0
  97. package/src/lib/thread/snapshot.ts +163 -0
  98. package/src/lib/thread/test-utils.ts +228 -0
  99. package/src/lib/thread/tiered.test.ts +281 -0
  100. package/src/lib/thread/tiered.ts +135 -0
  101. package/src/lib/thread/types.ts +16 -0
  102. package/src/tools/edit/handler.test.ts +177 -0
  103. package/src/tools/edit/handler.ts +249 -47
  104. package/src/tools/edit/tool.ts +40 -0
  105. package/src/tools/task-create/handler.ts +1 -1
  106. package/src/tools/task-update/handler.ts +1 -1
  107. package/src/workflow.ts +2 -2
  108. package/dist/proxy-Bf7uI-Hw.d.cts +0 -24
  109. package/dist/proxy-COqA95FW.d.ts +0 -24
@@ -0,0 +1,114 @@
1
+ import { P as PersistedThreadState } from './types-qQVZfhoT.js';
2
+ import { S3Client } from '@aws-sdk/client-s3';
3
+
4
+ /**
5
+ * Pluggable cold-tier interface for thread archives.
6
+ *
7
+ * Zeitlich's thread manager is a Redis-backed hot tier optimized for
8
+ * the duration of a workflow run. A `ColdThreadStore` provides the
9
+ * durable archive: each thread is serialized to a single
10
+ * {@link ThreadSnapshot} blob (messages + persisted state slice +
11
+ * dedup-id ledger) at session-exit time, and restored at session-entry
12
+ * time when the workflow is resumed or forked.
13
+ *
14
+ * The contract is intentionally minimal — one read, one write, one
15
+ * delete keyed by `(threadKey, threadId)`. Any storage backend that
16
+ * can satisfy these three calls (S3, R2, GCS, Postgres, the local
17
+ * filesystem, etc.) can plug into the same tiered manager.
18
+ *
19
+ * Concurrency assumption: zeitlich assumes a single active session
20
+ * per `(threadKey, threadId)` at a time, so cold writes are
21
+ * last-writer-wins; no compare-and-swap is required.
22
+ */
23
+
24
+ /**
25
+ * Serialized form of a thread that can be written to and read from a
26
+ * {@link ColdThreadStore}.
27
+ *
28
+ * `messages` is the list of raw-serialized message strings exactly as
29
+ * they were stored in the Redis list — keeping the cold tier opaque
30
+ * to the adapter-specific message envelope. `state` is the
31
+ * {@link PersistedThreadState} that the session writes via
32
+ * `saveThreadState` on every exit path, or `null` if none has been
33
+ * written yet. `dedupIds` lets the tiered manager re-prime the
34
+ * idempotent-append dedup markers when restoring, so a rewind retry
35
+ * after a continue cannot accidentally re-append a message.
36
+ */
37
+ interface ThreadSnapshot {
38
+ v: 1;
39
+ messages: string[];
40
+ state: PersistedThreadState | null;
41
+ dedupIds: string[];
42
+ }
43
+ /** Pluggable cold archive for thread snapshots. */
44
+ interface ColdThreadStore {
45
+ /**
46
+ * Read the latest snapshot for `(threadKey, threadId)`, or return
47
+ * `null` if no snapshot has ever been written.
48
+ */
49
+ read(threadKey: string, threadId: string): Promise<ThreadSnapshot | null>;
50
+ /**
51
+ * Persist `snapshot` as the latest archive for `(threadKey,
52
+ * threadId)`. Overwrites any prior snapshot in place.
53
+ */
54
+ write(threadKey: string, threadId: string, snapshot: ThreadSnapshot): Promise<void>;
55
+ /**
56
+ * Permanently remove the archive for `(threadKey, threadId)`.
57
+ * No-op if no snapshot exists.
58
+ */
59
+ delete(threadKey: string, threadId: string): Promise<void>;
60
+ }
61
+ /**
62
+ * Alias for `@aws-sdk/client-s3`'s `S3Client`. The built-in store
63
+ * calls `send(...)` and accesses `client.config` (read by
64
+ * `@aws-sdk/lib-storage`'s `Upload`) — a duck-type with just `send`
65
+ * is not sufficient.
66
+ */
67
+ type S3LikeClient = S3Client;
68
+ /** Configuration for the built-in S3 cold store. */
69
+ interface S3ColdStoreConfig {
70
+ /** An `@aws-sdk/client-s3` `S3Client`. */
71
+ s3: S3LikeClient;
72
+ /** S3 bucket that holds the archive. */
73
+ bucket: string;
74
+ /**
75
+ * Optional key prefix applied to every object. The final key layout
76
+ * is `${prefix}/${threadKey}/${threadId}.json[.gz]` with leading
77
+ * slashes stripped. Defaults to `"threads"`.
78
+ */
79
+ prefix?: string;
80
+ /**
81
+ * Gzip the JSON payload before uploading and assume gzip on read.
82
+ * Defaults to `true` — message lists are highly compressible.
83
+ */
84
+ gzip?: boolean;
85
+ /**
86
+ * Optional `Content-Type` override. Defaults to
87
+ * `application/json` (or `application/gzip` when `gzip: true`).
88
+ */
89
+ contentType?: string;
90
+ }
91
+ /**
92
+ * Build an S3-backed {@link ColdThreadStore}.
93
+ *
94
+ * One object per thread at
95
+ * `${prefix}/${threadKey}/${threadId}.json[.gz]`, JSON-encoded and
96
+ * gzip-compressed by default. The consumer owns the `S3Client`
97
+ * instance, so credentials, region, and endpoint configuration live
98
+ * outside zeitlich.
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * import { S3Client } from "@aws-sdk/client-s3";
103
+ * import { createS3ColdStore } from "zeitlich";
104
+ *
105
+ * const coldStore = createS3ColdStore({
106
+ * s3: new S3Client({ region: "us-east-1" }),
107
+ * bucket: "my-threads",
108
+ * prefix: "prod/threads",
109
+ * });
110
+ * ```
111
+ */
112
+ declare function createS3ColdStore(config: S3ColdStoreConfig): ColdThreadStore;
113
+
114
+ export { type ColdThreadStore as C, type S3ColdStoreConfig as S, type ThreadSnapshot as T, type S3LikeClient as a, createS3ColdStore as c };
@@ -0,0 +1,114 @@
1
+ import { P as PersistedThreadState } from './types-DNEl5uxQ.cjs';
2
+ import { S3Client } from '@aws-sdk/client-s3';
3
+
4
+ /**
5
+ * Pluggable cold-tier interface for thread archives.
6
+ *
7
+ * Zeitlich's thread manager is a Redis-backed hot tier optimized for
8
+ * the duration of a workflow run. A `ColdThreadStore` provides the
9
+ * durable archive: each thread is serialized to a single
10
+ * {@link ThreadSnapshot} blob (messages + persisted state slice +
11
+ * dedup-id ledger) at session-exit time, and restored at session-entry
12
+ * time when the workflow is resumed or forked.
13
+ *
14
+ * The contract is intentionally minimal — one read, one write, one
15
+ * delete keyed by `(threadKey, threadId)`. Any storage backend that
16
+ * can satisfy these three calls (S3, R2, GCS, Postgres, the local
17
+ * filesystem, etc.) can plug into the same tiered manager.
18
+ *
19
+ * Concurrency assumption: zeitlich assumes a single active session
20
+ * per `(threadKey, threadId)` at a time, so cold writes are
21
+ * last-writer-wins; no compare-and-swap is required.
22
+ */
23
+
24
+ /**
25
+ * Serialized form of a thread that can be written to and read from a
26
+ * {@link ColdThreadStore}.
27
+ *
28
+ * `messages` is the list of raw-serialized message strings exactly as
29
+ * they were stored in the Redis list — keeping the cold tier opaque
30
+ * to the adapter-specific message envelope. `state` is the
31
+ * {@link PersistedThreadState} that the session writes via
32
+ * `saveThreadState` on every exit path, or `null` if none has been
33
+ * written yet. `dedupIds` lets the tiered manager re-prime the
34
+ * idempotent-append dedup markers when restoring, so a rewind retry
35
+ * after a continue cannot accidentally re-append a message.
36
+ */
37
+ interface ThreadSnapshot {
38
+ v: 1;
39
+ messages: string[];
40
+ state: PersistedThreadState | null;
41
+ dedupIds: string[];
42
+ }
43
+ /** Pluggable cold archive for thread snapshots. */
44
+ interface ColdThreadStore {
45
+ /**
46
+ * Read the latest snapshot for `(threadKey, threadId)`, or return
47
+ * `null` if no snapshot has ever been written.
48
+ */
49
+ read(threadKey: string, threadId: string): Promise<ThreadSnapshot | null>;
50
+ /**
51
+ * Persist `snapshot` as the latest archive for `(threadKey,
52
+ * threadId)`. Overwrites any prior snapshot in place.
53
+ */
54
+ write(threadKey: string, threadId: string, snapshot: ThreadSnapshot): Promise<void>;
55
+ /**
56
+ * Permanently remove the archive for `(threadKey, threadId)`.
57
+ * No-op if no snapshot exists.
58
+ */
59
+ delete(threadKey: string, threadId: string): Promise<void>;
60
+ }
61
+ /**
62
+ * Alias for `@aws-sdk/client-s3`'s `S3Client`. The built-in store
63
+ * calls `send(...)` and accesses `client.config` (read by
64
+ * `@aws-sdk/lib-storage`'s `Upload`) — a duck-type with just `send`
65
+ * is not sufficient.
66
+ */
67
+ type S3LikeClient = S3Client;
68
+ /** Configuration for the built-in S3 cold store. */
69
+ interface S3ColdStoreConfig {
70
+ /** An `@aws-sdk/client-s3` `S3Client`. */
71
+ s3: S3LikeClient;
72
+ /** S3 bucket that holds the archive. */
73
+ bucket: string;
74
+ /**
75
+ * Optional key prefix applied to every object. The final key layout
76
+ * is `${prefix}/${threadKey}/${threadId}.json[.gz]` with leading
77
+ * slashes stripped. Defaults to `"threads"`.
78
+ */
79
+ prefix?: string;
80
+ /**
81
+ * Gzip the JSON payload before uploading and assume gzip on read.
82
+ * Defaults to `true` — message lists are highly compressible.
83
+ */
84
+ gzip?: boolean;
85
+ /**
86
+ * Optional `Content-Type` override. Defaults to
87
+ * `application/json` (or `application/gzip` when `gzip: true`).
88
+ */
89
+ contentType?: string;
90
+ }
91
+ /**
92
+ * Build an S3-backed {@link ColdThreadStore}.
93
+ *
94
+ * One object per thread at
95
+ * `${prefix}/${threadKey}/${threadId}.json[.gz]`, JSON-encoded and
96
+ * gzip-compressed by default. The consumer owns the `S3Client`
97
+ * instance, so credentials, region, and endpoint configuration live
98
+ * outside zeitlich.
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * import { S3Client } from "@aws-sdk/client-s3";
103
+ * import { createS3ColdStore } from "zeitlich";
104
+ *
105
+ * const coldStore = createS3ColdStore({
106
+ * s3: new S3Client({ region: "us-east-1" }),
107
+ * bucket: "my-threads",
108
+ * prefix: "prod/threads",
109
+ * });
110
+ * ```
111
+ */
112
+ declare function createS3ColdStore(config: S3ColdStoreConfig): ColdThreadStore;
113
+
114
+ export { type ColdThreadStore as C, type S3ColdStoreConfig as S, type ThreadSnapshot as T, type S3LikeClient as a, createS3ColdStore as c };