@statewavedev/sdk 0.7.0 → 0.8.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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @statewavedev/sdk
1
+ # Statewave TypeScript SDK
2
2
 
3
3
  [![CI](https://github.com/smaramwbc/statewave-ts/workflows/CI/badge.svg)](https://github.com/smaramwbc/statewave-ts/actions/workflows/ci.yml)
4
4
  [![npm](https://img.shields.io/npm/v/@statewavedev/sdk)](https://www.npmjs.com/package/@statewavedev/sdk)
@@ -16,8 +16,6 @@ Official TypeScript SDK for [Statewave](https://github.com/smaramwbc/statewave)
16
16
  npm install @statewavedev/sdk
17
17
  ```
18
18
 
19
- > Before public launch, this package used the internal name `statewave-ts`. New code should use `@statewavedev/sdk`.
20
-
21
19
  ## Quick start
22
20
 
23
21
  ```typescript
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { BatchCreateResult, ClientOptions, CompileJob, CompileResult, ContextBundle, CreateEpisodeParams, DeleteResult, Episode, GetContextParams, ListSubjectsResult, SearchMemoriesParams, SearchResult, Timeline } from "./types.js";
1
+ import type { BatchCreateResult, ClientOptions, CompileJob, CompileResult, ContextBundle, CreateEpisodeParams, DeleteResult, Episode, GetContextParams, ListReceiptsParams, ListSubjectsResult, Memory, Receipt, ReceiptList, SearchMemoriesParams, SearchResult, SetMemoryLabelsParams, Timeline } from "./types.js";
2
2
  /** Structured error from the Statewave API. */
3
3
  export declare class StatewaveAPIError extends Error {
4
4
  readonly statusCode: number;
@@ -30,8 +30,23 @@ export declare class StatewaveClient {
30
30
  }): Promise<CompileJob>;
31
31
  searchMemories(params: SearchMemoriesParams): Promise<SearchResult>;
32
32
  getContext(params: GetContextParams): Promise<ContextBundle>;
33
+ /**
34
+ * Replace a memory's sensitivity_labels. Server normalizes
35
+ * (dedup + lowercase + trim) and caps at 32 entries. Empty array
36
+ * clears all labels — the memory becomes untagged and any policy
37
+ * rule that depends on a label match falls through to default-allow.
38
+ */
39
+ setMemoryLabels(params: SetMemoryLabelsParams): Promise<Memory>;
33
40
  /** Return just the assembled context string, ready to inject into a prompt. */
34
41
  getContextString(params: GetContextParams): Promise<string>;
42
+ /** Fetch a single state-assembly receipt by ULID. */
43
+ getReceipt(receiptId: string): Promise<Receipt>;
44
+ /**
45
+ * List state-assembly receipts for a subject, newest first.
46
+ * Cursor-paginated — pass back the previous response's `next_cursor`
47
+ * to fetch the next page.
48
+ */
49
+ listReceipts(params: ListReceiptsParams): Promise<ReceiptList>;
35
50
  getTimeline(subjectId: string): Promise<Timeline>;
36
51
  deleteSubject(subjectId: string): Promise<DeleteResult>;
37
52
  listSubjects(params?: {
package/dist/client.js CHANGED
@@ -108,13 +108,54 @@ export class StatewaveClient {
108
108
  subject_id: params.subject_id,
109
109
  task: params.task,
110
110
  ...(params.max_tokens !== undefined && { max_tokens: params.max_tokens }),
111
+ ...(params.session_id !== undefined && { session_id: params.session_id }),
112
+ ...(params.emit_receipt !== undefined && { emit_receipt: params.emit_receipt }),
113
+ ...(params.query_id !== undefined && { query_id: params.query_id }),
114
+ ...(params.task_id !== undefined && { task_id: params.task_id }),
115
+ ...(params.parent_receipt_id !== undefined && {
116
+ parent_receipt_id: params.parent_receipt_id,
117
+ }),
118
+ ...(params.caller_id !== undefined && { caller_id: params.caller_id }),
119
+ ...(params.caller_type !== undefined && { caller_type: params.caller_type }),
111
120
  });
112
121
  }
122
+ // -- Memory labels (#50) ----------------------------------------------
123
+ /**
124
+ * Replace a memory's sensitivity_labels. Server normalizes
125
+ * (dedup + lowercase + trim) and caps at 32 entries. Empty array
126
+ * clears all labels — the memory becomes untagged and any policy
127
+ * rule that depends on a label match falls through to default-allow.
128
+ */
129
+ async setMemoryLabels(params) {
130
+ return this.request("PATCH", `/v1/memories/${encodeURIComponent(params.memory_id)}/labels`, { sensitivity_labels: params.sensitivity_labels });
131
+ }
113
132
  /** Return just the assembled context string, ready to inject into a prompt. */
114
133
  async getContextString(params) {
115
134
  const bundle = await this.getContext(params);
116
135
  return bundle.assembled_context;
117
136
  }
137
+ // -- Receipts --------------------------------------------------------
138
+ /** Fetch a single state-assembly receipt by ULID. */
139
+ async getReceipt(receiptId) {
140
+ return this.get(`/v1/receipts/${encodeURIComponent(receiptId)}`);
141
+ }
142
+ /**
143
+ * List state-assembly receipts for a subject, newest first.
144
+ * Cursor-paginated — pass back the previous response's `next_cursor`
145
+ * to fetch the next page.
146
+ */
147
+ async listReceipts(params) {
148
+ const qs = new URLSearchParams({ subject_id: params.subject_id });
149
+ if (params.since !== undefined)
150
+ qs.set("since", params.since);
151
+ if (params.until !== undefined)
152
+ qs.set("until", params.until);
153
+ if (params.cursor !== undefined)
154
+ qs.set("cursor", params.cursor);
155
+ if (params.limit !== undefined)
156
+ qs.set("limit", String(params.limit));
157
+ return this.get(`/v1/receipts?${qs}`);
158
+ }
118
159
  async getTimeline(subjectId) {
119
160
  return this.get(`/v1/timeline?subject_id=${encodeURIComponent(subjectId)}`);
120
161
  }
package/dist/types.d.ts CHANGED
@@ -21,6 +21,12 @@ export interface Memory {
21
21
  source_episode_ids: string[];
22
22
  metadata: Record<string, unknown>;
23
23
  status: string;
24
+ /**
25
+ * Per-memory capability tags consumed by the sensitivity-label
26
+ * policy layer (#50). Empty = untagged = policy default-allow.
27
+ * Older servers without the policy layer omit the field.
28
+ */
29
+ sensitivity_labels?: string[];
24
30
  created_at: string;
25
31
  updated_at: string;
26
32
  }
@@ -41,6 +47,83 @@ export interface ContextBundle {
41
47
  provenance: Record<string, unknown>;
42
48
  assembled_context: string;
43
49
  token_estimate: number;
50
+ /** ULID of the state-assembly receipt, when one was emitted. */
51
+ receipt_id?: string | null;
52
+ /** True iff a receipt was successfully written for this call. */
53
+ receipt_emitted?: boolean;
54
+ }
55
+ /**
56
+ * One entry inside a state-assembly receipt. Strict-superset shape —
57
+ * fields not relevant to the entry's `type` are null. See
58
+ * `docs/state-assembly-receipts.md` in the server repository for the
59
+ * full schema.
60
+ */
61
+ export interface ReceiptSelectedEntry {
62
+ type: "memory" | "episode";
63
+ /** Present when type === "memory". */
64
+ memory_id?: string;
65
+ /** Present when type === "memory". */
66
+ kind?: string;
67
+ valid_from?: string | null;
68
+ valid_to?: string | null;
69
+ supersession_status?: "active" | "superseded" | "tombstoned";
70
+ source_episode_ids?: string[];
71
+ provenance_hash?: string;
72
+ fact_key?: string | null;
73
+ conflict_status?: "none" | "merged" | "overridden" | "unresolved";
74
+ /** Present when type === "episode". */
75
+ episode_id?: string;
76
+ source?: string;
77
+ event_type?: string;
78
+ occurred_at?: string | null;
79
+ /** Final position in the assembled bundle. */
80
+ rank: number;
81
+ score?: number | null;
82
+ }
83
+ export interface ReceiptPolicy {
84
+ policy_bundle_hash: string | null;
85
+ filters_applied: unknown[];
86
+ filters_skipped: unknown[];
87
+ mode: "log_only" | "enforce";
88
+ }
89
+ export interface ReceiptOutput {
90
+ context_hash: string;
91
+ context_size_bytes: number;
92
+ canonicalization_version: number;
93
+ token_estimate: number;
94
+ }
95
+ /**
96
+ * Immutable per-retrieval audit artifact for a single context assembly.
97
+ * See `docs/state-assembly-receipts.md` in the server repository.
98
+ */
99
+ export interface Receipt {
100
+ receipt_id: string;
101
+ parent_receipt_id: string | null;
102
+ mode: "retrieval" | string;
103
+ query_id: string | null;
104
+ task_id: string | null;
105
+ tenant_id: string | null;
106
+ subject_id: string;
107
+ task: string;
108
+ as_of: string;
109
+ created_at: string;
110
+ selected_entries: ReceiptSelectedEntry[];
111
+ policy: ReceiptPolicy;
112
+ output: ReceiptOutput;
113
+ region: string | null;
114
+ receipt_signature: string | null;
115
+ }
116
+ export interface ReceiptList {
117
+ receipts: Receipt[];
118
+ /** Pass back as the `cursor` param to fetch the next page; null when no more. */
119
+ next_cursor: string | null;
120
+ }
121
+ export interface ListReceiptsParams {
122
+ subject_id: string;
123
+ since?: string;
124
+ until?: string;
125
+ cursor?: string;
126
+ limit?: number;
44
127
  }
45
128
  export interface Timeline {
46
129
  subject_id: string;
@@ -94,6 +177,32 @@ export interface GetContextParams {
94
177
  subject_id: string;
95
178
  task: string;
96
179
  max_tokens?: number;
180
+ session_id?: string;
181
+ /**
182
+ * Opt in to emitting a state-assembly receipt for this call. The
183
+ * tenant config can also force emission on or off independently of
184
+ * this flag. See `docs/state-assembly-receipts.md` in the server
185
+ * repository.
186
+ */
187
+ emit_receipt?: boolean;
188
+ query_id?: string;
189
+ task_id?: string;
190
+ parent_receipt_id?: string;
191
+ /**
192
+ * Caller identity consumed by the sensitivity-label policy layer
193
+ * (#50). When the tenant config sets `require_caller_identity:
194
+ * true`, both `caller_id` and `caller_type` are mandatory.
195
+ */
196
+ caller_id?: string;
197
+ caller_type?: string;
198
+ }
199
+ export interface SetMemoryLabelsParams {
200
+ memory_id: string;
201
+ /**
202
+ * Replacement label list. Server normalizes (dedup + lowercase +
203
+ * trim) and caps at 32 entries. Empty list clears all labels.
204
+ */
205
+ sensitivity_labels: string[];
97
206
  }
98
207
  export interface ClientOptions {
99
208
  baseUrl?: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@statewavedev/sdk",
3
- "version": "0.7.0",
4
- "description": "Official TypeScript SDK for Statewave — Memory OS for AI agents",
3
+ "version": "0.8.0",
4
+ "description": "Official TypeScript SDK for Statewave — the open-source memory runtime for AI agents.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",