@skein-js/core 0.2.1 → 0.4.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.
package/dist/index.d.ts CHANGED
@@ -1,8 +1,11 @@
1
- import { Run, Config, Metadata, Assistant, StreamMode, Thread, ThreadStatus, DefaultValues, Interrupt, Item, SearchItem } from '@langchain/langgraph-sdk';
2
- export { Assistant, AssistantBase, AssistantGraph, Checkpoint, Config, DefaultValues, GraphSchema, Interrupt, Item, Metadata, Run, SearchItem, StreamMode, Thread, ThreadState, ThreadStatus, ThreadTask } from '@langchain/langgraph-sdk';
1
+ import { Run as Run$1, Config, Metadata, Assistant, StreamMode, Thread, DefaultValues, ThreadStatus, Interrupt, Item, SearchItem } from '@langchain/langgraph-sdk';
2
+ export { Assistant, AssistantBase, AssistantGraph, Checkpoint, Config, DefaultValues, GraphSchema, Interrupt, Item, Metadata, SearchItem, StreamMode, Thread, ThreadState, ThreadStatus, ThreadTask } from '@langchain/langgraph-sdk';
3
3
 
4
- type RunStatus = Run["status"];
5
- type MultitaskStrategy = NonNullable<Run["multitask_strategy"]>;
4
+ type RunStatus = Run$1["status"] | "cancelled";
5
+ type Run = Omit<Run$1, "status"> & {
6
+ status: RunStatus;
7
+ };
8
+ type MultitaskStrategy = NonNullable<Run$1["multitask_strategy"]>;
6
9
 
7
10
  /** Fields accepted when registering an assistant (from a langgraph.json graph or the API). */
8
11
  interface AssistantCreate {
@@ -37,13 +40,42 @@ interface ThreadUpdate {
37
40
  /** Pending human-in-the-loop interrupts, mirrored from the graph state onto the thread row. */
38
41
  interrupts?: Record<string, Interrupt[]>;
39
42
  }
43
+ /** Filter + pagination for `POST /threads/search`. Omitted fields don't constrain the result. */
44
+ interface ThreadSearchQuery {
45
+ /** Match threads whose metadata contains every one of these key/value pairs (subset match). */
46
+ metadata?: Metadata;
47
+ /** Match threads whose mirrored graph values contain every one of these key/value pairs. */
48
+ values?: DefaultValues;
49
+ /** Restrict to threads in this status. */
50
+ status?: ThreadStatus;
51
+ /** Restrict to these thread ids. */
52
+ ids?: string[];
53
+ limit?: number;
54
+ offset?: number;
55
+ /** Sort key; defaults to `created_at`. */
56
+ sortBy?: "thread_id" | "status" | "created_at" | "updated_at";
57
+ /** Sort direction; defaults to `desc`. */
58
+ sortOrder?: "asc" | "desc";
59
+ }
40
60
  interface ThreadRepo {
41
61
  list(): Promise<Thread[]>;
62
+ /** Filtered + paginated listing backing `POST /threads/search`. */
63
+ search(query: ThreadSearchQuery): Promise<Thread[]>;
42
64
  get(threadId: string): Promise<Thread | null>;
43
65
  create(input?: ThreadCreate): Promise<Thread>;
44
66
  update(threadId: string, patch: ThreadUpdate): Promise<Thread>;
67
+ /** Duplicate a thread's row (new id, fresh timestamps); checkpoint history is copied at the service layer. */
68
+ copy(threadId: string): Promise<Thread>;
45
69
  delete(threadId: string): Promise<void>;
46
70
  }
71
+ /**
72
+ * True if `subject` contains `filter`, mirroring Postgres' JSONB `@>` operator so the memory driver,
73
+ * the conformance suite, and the Postgres driver all agree on metadata/values matching. Containment is
74
+ * recursive: an object matches on a *subset* of its keys (nested objects included), an array matches as
75
+ * a set (every filter element is contained in some subject element), and scalars match by equality. An
76
+ * empty (or absent) filter matches everything.
77
+ */
78
+ declare function isMetadataSubset(subject: unknown, filter: unknown): boolean;
47
79
  /**
48
80
  * The execution payload of a run — everything the run engine needs to (re)start a graph. Stored
49
81
  * *opaquely* alongside the run (it is NOT part of the wire {@link Run}), so a background run picked
@@ -109,12 +141,32 @@ interface StoreSearchQuery {
109
141
  limit?: number;
110
142
  offset?: number;
111
143
  }
144
+ /**
145
+ * Expiry policy for long-term store items (from `langgraph.json` `store.ttl`). All durations are in
146
+ * minutes. A driver applies `defaultTtl` when a `put` gives no explicit `ttl`, refreshes an item's
147
+ * expiry on read when `refreshOnRead` is set, and a background sweeper (interval `sweepIntervalMinutes`)
148
+ * deletes expired rows via {@link StoreRepo.sweepExpired}.
149
+ */
150
+ interface StoreTtlConfig {
151
+ /** Default item lifetime in minutes when `put` doesn't pass its own `ttl`. */
152
+ defaultTtl?: number;
153
+ /** Extend an item's expiry when it is read. Defaults to true. */
154
+ refreshOnRead?: boolean;
155
+ /** Sweeper cadence in minutes. Defaults to 60. */
156
+ sweepIntervalMinutes?: number;
157
+ }
158
+ /** Per-`put` options. `ttl` (minutes) overrides the configured `defaultTtl` for this item. */
159
+ interface StorePutOptions {
160
+ ttl?: number;
161
+ }
112
162
  interface StoreRepo {
113
163
  get(namespace: string[], key: string): Promise<Item | null>;
114
- put(namespace: string[], key: string, value: Record<string, unknown>): Promise<Item>;
164
+ put(namespace: string[], key: string, value: Record<string, unknown>, options?: StorePutOptions): Promise<Item>;
115
165
  delete(namespace: string[], key: string): Promise<void>;
116
166
  search(query: StoreSearchQuery): Promise<SearchItem[]>;
117
167
  listNamespaces(prefix?: string[]): Promise<string[][]>;
168
+ /** Delete every expired item; returns how many were removed. No-op when TTL is unconfigured. */
169
+ sweepExpired(): Promise<number>;
118
170
  }
119
171
  /** The single persistence seam for Agent Protocol resources. One implementation per driver. */
120
172
  interface SkeinStore {
@@ -123,6 +175,24 @@ interface SkeinStore {
123
175
  runs: RunRepo;
124
176
  store: StoreRepo;
125
177
  }
178
+ /**
179
+ * A driver-agnostic, JSON-serializable snapshot of every resource row — the unit of bulk
180
+ * transfer for persistence and migration tooling (e.g. `skein dev`'s cross-restart snapshot, and
181
+ * importing an existing LangGraph in-memory dev state). Each entry is an `[id, row]` tuple: the id
182
+ * is the entity's own id, except `items` (keyed by `JSON.stringify([namespace, key])`) and
183
+ * `runKwargs` (keyed by `run_id`, since {@link RunKwargs} has no id of its own).
184
+ *
185
+ * A driver MAY expose `restore(snapshot)` to bulk-load one of these verbatim — ids and timestamps
186
+ * preserved — which is what makes an import lossless. It is intentionally not part of
187
+ * {@link SkeinStore}: only migration tooling needs it, and consumers feature-detect it.
188
+ */
189
+ interface SkeinStoreSnapshot {
190
+ assistants: [string, Assistant][];
191
+ threads: [string, Thread][];
192
+ runs: [string, Run][];
193
+ runKwargs: [string, RunKwargs][];
194
+ items: [string, Item][];
195
+ }
126
196
 
127
197
  /**
128
198
  * A normalized stream frame produced during a run. Adapters map these onto SSE
@@ -281,4 +351,4 @@ interface AuthEngine {
281
351
  matchesFilters(metadata: Record<string, unknown> | undefined, filters?: AuthFilters): boolean;
282
352
  }
283
353
 
284
- export { type AssistantCreate, type AssistantRepo, type AuthAction, type AuthContext, type AuthEngine, type AuthFilterValue, type AuthFilters, type AuthResource, type AuthUser, type MultitaskStrategy, type QueuedRun, type RunConsumer, type RunConsumerOptions, type RunCreate, type RunEventBus, type RunFrame, type RunKwargs, type RunProcessor, type RunQueue, type RunRepo, type RunStatus, SkeinHttpError, type SkeinHttpErrorOptions, type SkeinStore, type StoreRepo, type StoreSearchQuery, TERMINAL_RUN_STATUSES, type ThreadCreate, type ThreadRepo, type ThreadUpdate, isSkeinHttpError, isTerminalRunStatus, serializeWireJson };
354
+ export { type AssistantCreate, type AssistantRepo, type AuthAction, type AuthContext, type AuthEngine, type AuthFilterValue, type AuthFilters, type AuthResource, type AuthUser, type MultitaskStrategy, type QueuedRun, type Run, type RunConsumer, type RunConsumerOptions, type RunCreate, type RunEventBus, type RunFrame, type RunKwargs, type RunProcessor, type RunQueue, type RunRepo, type RunStatus, SkeinHttpError, type SkeinHttpErrorOptions, type SkeinStore, type SkeinStoreSnapshot, type StorePutOptions, type StoreRepo, type StoreSearchQuery, type StoreTtlConfig, TERMINAL_RUN_STATUSES, type ThreadCreate, type ThreadRepo, type ThreadSearchQuery, type ThreadUpdate, isMetadataSubset, isSkeinHttpError, isTerminalRunStatus, serializeWireJson };
package/dist/index.js CHANGED
@@ -1,9 +1,26 @@
1
1
  // src/store/skein-store.ts
2
+ function isMetadataSubset(subject, filter) {
3
+ if (filter === void 0 || filter === null) return true;
4
+ return jsonbContains(subject, filter);
5
+ }
6
+ function jsonbContains(subject, filter) {
7
+ if (filter === null || typeof filter !== "object") return subject === filter;
8
+ if (Array.isArray(filter)) {
9
+ if (!Array.isArray(subject)) return false;
10
+ return filter.every((wanted) => subject.some((candidate) => jsonbContains(candidate, wanted)));
11
+ }
12
+ const entries = Object.entries(filter);
13
+ if (entries.length === 0) return true;
14
+ if (subject === null || typeof subject !== "object" || Array.isArray(subject)) return false;
15
+ const row = subject;
16
+ return entries.every(([key, value]) => key in row && jsonbContains(row[key], value));
17
+ }
2
18
  var TERMINAL_RUN_STATUSES = [
3
19
  "success",
4
20
  "error",
5
21
  "timeout",
6
- "interrupted"
22
+ "interrupted",
23
+ "cancelled"
7
24
  ];
8
25
  function isTerminalRunStatus(status) {
9
26
  return TERMINAL_RUN_STATUSES.includes(status);
@@ -66,6 +83,7 @@ function isSkeinHttpError(value) {
66
83
  export {
67
84
  SkeinHttpError,
68
85
  TERMINAL_RUN_STATUSES,
86
+ isMetadataSubset,
69
87
  isSkeinHttpError,
70
88
  isTerminalRunStatus,
71
89
  serializeWireJson
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skein-js/core",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "description": "Framework-agnostic Agent Protocol engine for LangGraph.js — the heart of skein-js.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Maina Wycliffe <wmmaina7@gmail.com>",