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.
- package/README.md +137 -11
- package/dist/{activities-Coafq5zr.d.cts → activities-CPwKoUlD.d.cts} +22 -2
- package/dist/{activities-CrN-ghLo.d.ts → activities-DlaBxNID.d.ts} +22 -2
- package/dist/adapters/thread/anthropic/index.cjs +276 -71
- package/dist/adapters/thread/anthropic/index.cjs.map +1 -1
- package/dist/adapters/thread/anthropic/index.d.cts +62 -8
- package/dist/adapters/thread/anthropic/index.d.ts +62 -8
- package/dist/adapters/thread/anthropic/index.js +275 -72
- package/dist/adapters/thread/anthropic/index.js.map +1 -1
- package/dist/adapters/thread/anthropic/workflow.cjs +38 -20
- package/dist/adapters/thread/anthropic/workflow.cjs.map +1 -1
- package/dist/adapters/thread/anthropic/workflow.d.cts +5 -4
- package/dist/adapters/thread/anthropic/workflow.d.ts +5 -4
- package/dist/adapters/thread/anthropic/workflow.js +38 -20
- package/dist/adapters/thread/anthropic/workflow.js.map +1 -1
- package/dist/adapters/thread/google-genai/index.cjs +171 -69
- package/dist/adapters/thread/google-genai/index.cjs.map +1 -1
- package/dist/adapters/thread/google-genai/index.d.cts +6 -4
- package/dist/adapters/thread/google-genai/index.d.ts +6 -4
- package/dist/adapters/thread/google-genai/index.js +171 -69
- package/dist/adapters/thread/google-genai/index.js.map +1 -1
- package/dist/adapters/thread/google-genai/workflow.cjs +38 -20
- package/dist/adapters/thread/google-genai/workflow.cjs.map +1 -1
- package/dist/adapters/thread/google-genai/workflow.d.cts +7 -4
- package/dist/adapters/thread/google-genai/workflow.d.ts +7 -4
- package/dist/adapters/thread/google-genai/workflow.js +38 -20
- package/dist/adapters/thread/google-genai/workflow.js.map +1 -1
- package/dist/adapters/thread/langchain/index.cjs +170 -66
- package/dist/adapters/thread/langchain/index.cjs.map +1 -1
- package/dist/adapters/thread/langchain/index.d.cts +19 -4
- package/dist/adapters/thread/langchain/index.d.ts +19 -4
- package/dist/adapters/thread/langchain/index.js +170 -66
- package/dist/adapters/thread/langchain/index.js.map +1 -1
- package/dist/adapters/thread/langchain/workflow.cjs +38 -20
- package/dist/adapters/thread/langchain/workflow.cjs.map +1 -1
- package/dist/adapters/thread/langchain/workflow.d.cts +5 -4
- package/dist/adapters/thread/langchain/workflow.d.ts +5 -4
- package/dist/adapters/thread/langchain/workflow.js +38 -20
- package/dist/adapters/thread/langchain/workflow.js.map +1 -1
- package/dist/cold-store-BDgJpwLI.d.ts +114 -0
- package/dist/cold-store-Z2wvK2cV.d.cts +114 -0
- package/dist/index.cjs +440 -67
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +150 -8
- package/dist/index.d.ts +150 -8
- package/dist/index.js +432 -68
- package/dist/index.js.map +1 -1
- package/dist/proxy-CDh3Rsa7.d.cts +40 -0
- package/dist/proxy-Du8ggERu.d.ts +40 -0
- package/dist/{thread-manager-wRVVBFgj.d.cts → thread-manager-BjoYYXgd.d.cts} +8 -2
- package/dist/{thread-manager-BsLO3Fgc.d.cts → thread-manager-D8zKNFZ9.d.cts} +8 -2
- package/dist/{thread-manager-Bi1XlbpJ.d.ts → thread-manager-DtHYws2F.d.ts} +8 -2
- package/dist/{thread-manager-BhkOyQ1I.d.ts → thread-manager-Dw96FKH1.d.ts} +8 -2
- package/dist/{types-C66-BVBr.d.cts → types-BMJrsHo0.d.cts} +17 -1
- package/dist/{types-BkX4HLzi.d.ts → types-CtdOquo3.d.ts} +17 -1
- package/dist/{types-CdALEF3z.d.cts → types-DNEl5uxQ.d.cts} +38 -0
- package/dist/{types-ChAy_jSP.d.ts → types-qQVZfhoT.d.ts} +38 -0
- package/dist/{workflow-DMmiaw6w.d.cts → workflow-BH9ImDGq.d.cts} +48 -2
- package/dist/{workflow-BwT5EybR.d.ts → workflow-Cdw3-RNB.d.ts} +48 -2
- package/dist/workflow.cjs +47 -4
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +2 -2
- package/dist/workflow.d.ts +2 -2
- package/dist/workflow.js +47 -5
- package/dist/workflow.js.map +1 -1
- package/package.json +14 -3
- package/src/adapters/thread/anthropic/activities.ts +82 -39
- package/src/adapters/thread/anthropic/index.ts +8 -0
- package/src/adapters/thread/anthropic/model-invoker.test.ts +110 -0
- package/src/adapters/thread/anthropic/model-invoker.ts +26 -5
- package/src/adapters/thread/anthropic/prompt-cache.test.ts +134 -0
- package/src/adapters/thread/anthropic/prompt-cache.ts +163 -0
- package/src/adapters/thread/anthropic/proxy.ts +1 -0
- package/src/adapters/thread/anthropic/thread-manager.ts +9 -1
- package/src/adapters/thread/google-genai/activities.ts +64 -40
- package/src/adapters/thread/google-genai/proxy.ts +1 -0
- package/src/adapters/thread/google-genai/thread-manager.ts +9 -1
- package/src/adapters/thread/langchain/activities.ts +63 -36
- package/src/adapters/thread/langchain/proxy.ts +1 -0
- package/src/adapters/thread/langchain/thread-manager.ts +9 -1
- package/src/index.ts +21 -2
- package/src/lib/session/session-edge-cases.integration.test.ts +12 -0
- package/src/lib/session/session.integration.test.ts +138 -0
- package/src/lib/session/session.ts +29 -0
- package/src/lib/session/types.ts +22 -0
- package/src/lib/subagent/define.ts +1 -0
- package/src/lib/subagent/handler.ts +11 -2
- package/src/lib/subagent/subagent.integration.test.ts +139 -0
- package/src/lib/subagent/types.ts +16 -0
- package/src/lib/thread/cold-store.test.ts +221 -0
- package/src/lib/thread/cold-store.ts +269 -0
- package/src/lib/thread/index.ts +32 -0
- package/src/lib/thread/keys.ts +20 -0
- package/src/lib/thread/manager.ts +16 -27
- package/src/lib/thread/proxy.ts +79 -27
- package/src/lib/thread/snapshot.test.ts +443 -0
- package/src/lib/thread/snapshot.ts +163 -0
- package/src/lib/thread/test-utils.ts +228 -0
- package/src/lib/thread/tiered.test.ts +281 -0
- package/src/lib/thread/tiered.ts +135 -0
- package/src/lib/thread/types.ts +16 -0
- package/src/tools/edit/handler.test.ts +177 -0
- package/src/tools/edit/handler.ts +249 -47
- package/src/tools/edit/tool.ts +40 -0
- package/src/tools/task-create/handler.ts +1 -1
- package/src/tools/task-update/handler.ts +1 -1
- package/src/workflow.ts +2 -2
- package/dist/proxy-Bf7uI-Hw.d.cts +0 -24
- 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 };
|