conversationalist 0.0.7 → 0.0.8

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 (97) hide show
  1. package/README.md +150 -90
  2. package/dist/adapters/anthropic/index.d.ts +11 -6
  3. package/dist/adapters/anthropic/index.d.ts.map +1 -1
  4. package/dist/adapters/anthropic/index.js +16 -3
  5. package/dist/adapters/anthropic/index.js.map +5 -4
  6. package/dist/adapters/gemini/index.d.ts +2 -2
  7. package/dist/adapters/gemini/index.d.ts.map +1 -1
  8. package/dist/adapters/gemini/index.js +52 -9
  9. package/dist/adapters/gemini/index.js.map +5 -4
  10. package/dist/adapters/openai/index.d.ts +32 -5
  11. package/dist/adapters/openai/index.d.ts.map +1 -1
  12. package/dist/adapters/openai/index.js +30 -8
  13. package/dist/adapters/openai/index.js.map +5 -4
  14. package/dist/context.d.ts.map +1 -1
  15. package/dist/conversation/append.d.ts +4 -4
  16. package/dist/conversation/append.d.ts.map +1 -1
  17. package/dist/conversation/create.d.ts +2 -3
  18. package/dist/conversation/create.d.ts.map +1 -1
  19. package/dist/conversation/index.d.ts +2 -2
  20. package/dist/conversation/index.d.ts.map +1 -1
  21. package/dist/conversation/modify.d.ts.map +1 -1
  22. package/dist/conversation/query.d.ts +9 -5
  23. package/dist/conversation/query.d.ts.map +1 -1
  24. package/dist/conversation/serialization.d.ts +6 -28
  25. package/dist/conversation/serialization.d.ts.map +1 -1
  26. package/dist/conversation/system-messages.d.ts +3 -3
  27. package/dist/conversation/system-messages.d.ts.map +1 -1
  28. package/dist/conversation/transform.d.ts.map +1 -1
  29. package/dist/conversation.d.ts +74 -18
  30. package/dist/conversation.d.ts.map +1 -1
  31. package/dist/export/index.d.ts +7 -0
  32. package/dist/export/index.d.ts.map +1 -0
  33. package/dist/export/index.js +3762 -0
  34. package/dist/export/index.js.map +62 -0
  35. package/dist/history.d.ts +102 -24
  36. package/dist/history.d.ts.map +1 -1
  37. package/dist/index.d.ts +7 -8
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +392 -4075
  40. package/dist/index.js.map +15 -60
  41. package/dist/markdown/index.d.ts +15 -0
  42. package/dist/markdown/index.d.ts.map +1 -0
  43. package/dist/markdown/index.js +4969 -0
  44. package/dist/markdown/index.js.map +69 -0
  45. package/dist/message.d.ts +1 -1
  46. package/dist/message.d.ts.map +1 -1
  47. package/dist/multi-modal.d.ts +3 -0
  48. package/dist/multi-modal.d.ts.map +1 -1
  49. package/dist/plugins/index.d.ts +1 -1
  50. package/dist/plugins/index.d.ts.map +1 -1
  51. package/dist/plugins/index.js +59 -0
  52. package/dist/plugins/index.js.map +10 -0
  53. package/dist/plugins/pii-redaction.d.ts +10 -1
  54. package/dist/plugins/pii-redaction.d.ts.map +1 -1
  55. package/dist/redaction/index.d.ts +2 -0
  56. package/dist/redaction/index.d.ts.map +1 -0
  57. package/dist/redaction/index.js +59 -0
  58. package/dist/redaction/index.js.map +10 -0
  59. package/dist/schemas/index.d.ts +2 -0
  60. package/dist/schemas/index.d.ts.map +1 -0
  61. package/dist/schemas/index.js +114 -0
  62. package/dist/schemas/index.js.map +10 -0
  63. package/dist/schemas.d.ts +324 -15
  64. package/dist/schemas.d.ts.map +1 -1
  65. package/dist/sort/index.d.ts +2 -0
  66. package/dist/sort/index.d.ts.map +1 -0
  67. package/dist/sort/index.js +32 -0
  68. package/dist/sort/index.js.map +10 -0
  69. package/dist/streaming.d.ts +3 -3
  70. package/dist/streaming.d.ts.map +1 -1
  71. package/dist/types.d.ts +72 -50
  72. package/dist/types.d.ts.map +1 -1
  73. package/dist/utilities/index.d.ts +1 -3
  74. package/dist/utilities/index.d.ts.map +1 -1
  75. package/dist/utilities/line-endings.d.ts +5 -0
  76. package/dist/utilities/line-endings.d.ts.map +1 -0
  77. package/dist/utilities/markdown.d.ts +1 -1
  78. package/dist/utilities/markdown.d.ts.map +1 -1
  79. package/dist/utilities/message-store.d.ts +6 -0
  80. package/dist/utilities/message-store.d.ts.map +1 -0
  81. package/dist/utilities/message.d.ts +9 -3
  82. package/dist/utilities/message.d.ts.map +1 -1
  83. package/dist/utilities/tool-calls.d.ts +4 -4
  84. package/dist/utilities/tool-calls.d.ts.map +1 -1
  85. package/dist/utilities/tool-results.d.ts +10 -0
  86. package/dist/utilities/tool-results.d.ts.map +1 -0
  87. package/dist/utilities/transient.d.ts +2 -2
  88. package/dist/utilities/transient.d.ts.map +1 -1
  89. package/dist/utilities.d.ts +3 -5
  90. package/dist/utilities.d.ts.map +1 -1
  91. package/dist/versioning/index.d.ts +3 -0
  92. package/dist/versioning/index.d.ts.map +1 -0
  93. package/dist/versioning/index.js +58 -0
  94. package/dist/versioning/index.js.map +11 -0
  95. package/dist/with-conversation.d.ts +8 -8
  96. package/dist/with-conversation.d.ts.map +1 -1
  97. package/package.json +26 -1
package/dist/schemas.d.ts CHANGED
@@ -1,6 +1,14 @@
1
+ import type { MultiModalContent } from '@lasercat/homogenaize';
1
2
  import { z } from 'zod';
2
- import type { ConversationJSON, ConversationStatus, MessageInput, MessageJSON, MessageRole, TokenUsage, ToolCall, ToolResult } from './types';
3
- export declare const multiModalContentSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
3
+ import type { JSONValue } from './types';
4
+ /**
5
+ * Zod schema for JSON-serializable values.
6
+ */
7
+ export declare const jsonValueSchema: z.ZodType<JSONValue>;
8
+ /**
9
+ * Zod schema for multi-modal content parts (text or image).
10
+ */
11
+ export declare const multiModalContentSchema: z.ZodPipe<z.ZodDiscriminatedUnion<[z.ZodObject<{
4
12
  type: z.ZodLiteral<"text">;
5
13
  text: z.ZodString;
6
14
  }, z.core.$strip>, z.ZodObject<{
@@ -8,24 +16,325 @@ export declare const multiModalContentSchema: z.ZodDiscriminatedUnion<[z.ZodObje
8
16
  url: z.ZodString;
9
17
  mimeType: z.ZodOptional<z.ZodString>;
10
18
  text: z.ZodOptional<z.ZodString>;
11
- }, z.core.$strip>], "type">;
12
- export declare const messageRoleSchema: z.ZodType<MessageRole>;
13
- export declare const toolCallSchema: z.ZodType<ToolCall>;
14
- export declare const toolResultSchema: z.ZodType<ToolResult>;
15
- export declare const tokenUsageSchema: z.ZodType<TokenUsage>;
16
- export declare const messageInputSchema: z.ZodType<MessageInput>;
17
- export declare const messageJSONSchema: z.ZodType<MessageJSON>;
18
- export declare const conversationStatusSchema: z.ZodType<ConversationStatus>;
19
+ }, z.core.$strip>], "type">, z.ZodTransform<MultiModalContent, {
20
+ type: "text";
21
+ text: string;
22
+ } | {
23
+ type: "image";
24
+ url: string;
25
+ mimeType?: string | undefined;
26
+ text?: string | undefined;
27
+ }>>;
28
+ /**
29
+ * Zod schema for valid message roles.
30
+ */
31
+ export declare const messageRoleSchema: z.ZodEnum<{
32
+ user: "user";
33
+ assistant: "assistant";
34
+ system: "system";
35
+ developer: "developer";
36
+ "tool-use": "tool-use";
37
+ "tool-result": "tool-result";
38
+ snapshot: "snapshot";
39
+ }>;
40
+ /**
41
+ * Zod schema for tool call metadata.
42
+ */
43
+ export declare const toolCallSchema: z.ZodObject<{
44
+ id: z.ZodString;
45
+ name: z.ZodString;
46
+ arguments: z.ZodType<JSONValue, unknown, z.core.$ZodTypeInternals<JSONValue, unknown>>;
47
+ }, z.core.$strip>;
48
+ /**
49
+ * Zod schema for tool result metadata.
50
+ */
51
+ export declare const toolResultSchema: z.ZodObject<{
52
+ callId: z.ZodString;
53
+ outcome: z.ZodEnum<{
54
+ success: "success";
55
+ error: "error";
56
+ }>;
57
+ content: z.ZodType<JSONValue, unknown, z.core.$ZodTypeInternals<JSONValue, unknown>>;
58
+ toolCallId: z.ZodOptional<z.ZodString>;
59
+ toolName: z.ZodOptional<z.ZodString>;
60
+ result: z.ZodOptional<z.ZodType<JSONValue, unknown, z.core.$ZodTypeInternals<JSONValue, unknown>>>;
61
+ error: z.ZodOptional<z.ZodString>;
62
+ }, z.core.$strip>;
63
+ /**
64
+ * Zod schema for token usage accounting.
65
+ */
66
+ export declare const tokenUsageSchema: z.ZodObject<{
67
+ prompt: z.ZodNumber;
68
+ completion: z.ZodNumber;
69
+ total: z.ZodNumber;
70
+ }, z.core.$strip>;
71
+ /**
72
+ * Zod schema for message input payloads.
73
+ */
74
+ export declare const messageInputSchema: z.ZodObject<{
75
+ role: z.ZodEnum<{
76
+ user: "user";
77
+ assistant: "assistant";
78
+ system: "system";
79
+ developer: "developer";
80
+ "tool-use": "tool-use";
81
+ "tool-result": "tool-result";
82
+ snapshot: "snapshot";
83
+ }>;
84
+ content: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodPipe<z.ZodDiscriminatedUnion<[z.ZodObject<{
85
+ type: z.ZodLiteral<"text">;
86
+ text: z.ZodString;
87
+ }, z.core.$strip>, z.ZodObject<{
88
+ type: z.ZodLiteral<"image">;
89
+ url: z.ZodString;
90
+ mimeType: z.ZodOptional<z.ZodString>;
91
+ text: z.ZodOptional<z.ZodString>;
92
+ }, z.core.$strip>], "type">, z.ZodTransform<MultiModalContent, {
93
+ type: "text";
94
+ text: string;
95
+ } | {
96
+ type: "image";
97
+ url: string;
98
+ mimeType?: string | undefined;
99
+ text?: string | undefined;
100
+ }>>>]>;
101
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<JSONValue, unknown, z.core.$ZodTypeInternals<JSONValue, unknown>>>>;
102
+ hidden: z.ZodOptional<z.ZodBoolean>;
103
+ toolCall: z.ZodOptional<z.ZodObject<{
104
+ id: z.ZodString;
105
+ name: z.ZodString;
106
+ arguments: z.ZodType<JSONValue, unknown, z.core.$ZodTypeInternals<JSONValue, unknown>>;
107
+ }, z.core.$strip>>;
108
+ toolResult: z.ZodOptional<z.ZodObject<{
109
+ callId: z.ZodString;
110
+ outcome: z.ZodEnum<{
111
+ success: "success";
112
+ error: "error";
113
+ }>;
114
+ content: z.ZodType<JSONValue, unknown, z.core.$ZodTypeInternals<JSONValue, unknown>>;
115
+ toolCallId: z.ZodOptional<z.ZodString>;
116
+ toolName: z.ZodOptional<z.ZodString>;
117
+ result: z.ZodOptional<z.ZodType<JSONValue, unknown, z.core.$ZodTypeInternals<JSONValue, unknown>>>;
118
+ error: z.ZodOptional<z.ZodString>;
119
+ }, z.core.$strip>>;
120
+ tokenUsage: z.ZodOptional<z.ZodObject<{
121
+ prompt: z.ZodNumber;
122
+ completion: z.ZodNumber;
123
+ total: z.ZodNumber;
124
+ }, z.core.$strip>>;
125
+ goalCompleted: z.ZodOptional<z.ZodBoolean>;
126
+ }, z.core.$strip>;
127
+ /**
128
+ * Zod schema for serialized messages.
129
+ */
130
+ export declare const messageJSONSchema: z.ZodObject<{
131
+ id: z.ZodString;
132
+ role: z.ZodEnum<{
133
+ user: "user";
134
+ assistant: "assistant";
135
+ system: "system";
136
+ developer: "developer";
137
+ "tool-use": "tool-use";
138
+ "tool-result": "tool-result";
139
+ snapshot: "snapshot";
140
+ }>;
141
+ content: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodPipe<z.ZodDiscriminatedUnion<[z.ZodObject<{
142
+ type: z.ZodLiteral<"text">;
143
+ text: z.ZodString;
144
+ }, z.core.$strip>, z.ZodObject<{
145
+ type: z.ZodLiteral<"image">;
146
+ url: z.ZodString;
147
+ mimeType: z.ZodOptional<z.ZodString>;
148
+ text: z.ZodOptional<z.ZodString>;
149
+ }, z.core.$strip>], "type">, z.ZodTransform<MultiModalContent, {
150
+ type: "text";
151
+ text: string;
152
+ } | {
153
+ type: "image";
154
+ url: string;
155
+ mimeType?: string | undefined;
156
+ text?: string | undefined;
157
+ }>>>]>;
158
+ position: z.ZodNumber;
159
+ createdAt: z.ZodString;
160
+ metadata: z.ZodRecord<z.ZodString, z.ZodType<JSONValue, unknown, z.core.$ZodTypeInternals<JSONValue, unknown>>>;
161
+ hidden: z.ZodBoolean;
162
+ toolCall: z.ZodOptional<z.ZodObject<{
163
+ id: z.ZodString;
164
+ name: z.ZodString;
165
+ arguments: z.ZodType<JSONValue, unknown, z.core.$ZodTypeInternals<JSONValue, unknown>>;
166
+ }, z.core.$strip>>;
167
+ toolResult: z.ZodOptional<z.ZodObject<{
168
+ callId: z.ZodString;
169
+ outcome: z.ZodEnum<{
170
+ success: "success";
171
+ error: "error";
172
+ }>;
173
+ content: z.ZodType<JSONValue, unknown, z.core.$ZodTypeInternals<JSONValue, unknown>>;
174
+ toolCallId: z.ZodOptional<z.ZodString>;
175
+ toolName: z.ZodOptional<z.ZodString>;
176
+ result: z.ZodOptional<z.ZodType<JSONValue, unknown, z.core.$ZodTypeInternals<JSONValue, unknown>>>;
177
+ error: z.ZodOptional<z.ZodString>;
178
+ }, z.core.$strip>>;
179
+ tokenUsage: z.ZodOptional<z.ZodObject<{
180
+ prompt: z.ZodNumber;
181
+ completion: z.ZodNumber;
182
+ total: z.ZodNumber;
183
+ }, z.core.$strip>>;
184
+ goalCompleted: z.ZodOptional<z.ZodBoolean>;
185
+ }, z.core.$loose>;
186
+ /**
187
+ * Zod schema for conversation status values.
188
+ */
189
+ export declare const conversationStatusSchema: z.ZodEnum<{
190
+ active: "active";
191
+ archived: "archived";
192
+ deleted: "deleted";
193
+ }>;
194
+ /**
195
+ * Raw conversation shape for storage systems that need direct access to fields.
196
+ */
19
197
  export declare const conversationShape: {
20
198
  readonly schemaVersion: z.ZodNumber;
21
199
  readonly id: z.ZodString;
22
200
  readonly title: z.ZodOptional<z.ZodString>;
23
- readonly status: z.ZodType<ConversationStatus, unknown, z.core.$ZodTypeInternals<ConversationStatus, unknown>>;
24
- readonly metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
25
- readonly tags: z.ZodArray<z.ZodString>;
26
- readonly messages: z.ZodArray<z.ZodType<MessageJSON, unknown, z.core.$ZodTypeInternals<MessageJSON, unknown>>>;
201
+ readonly status: z.ZodEnum<{
202
+ active: "active";
203
+ archived: "archived";
204
+ deleted: "deleted";
205
+ }>;
206
+ readonly metadata: z.ZodRecord<z.ZodString, z.ZodType<JSONValue, unknown, z.core.$ZodTypeInternals<JSONValue, unknown>>>;
207
+ readonly ids: z.ZodArray<z.ZodString>;
208
+ readonly messages: z.ZodRecord<z.ZodString, z.ZodObject<{
209
+ id: z.ZodString;
210
+ role: z.ZodEnum<{
211
+ user: "user";
212
+ assistant: "assistant";
213
+ system: "system";
214
+ developer: "developer";
215
+ "tool-use": "tool-use";
216
+ "tool-result": "tool-result";
217
+ snapshot: "snapshot";
218
+ }>;
219
+ content: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodPipe<z.ZodDiscriminatedUnion<[z.ZodObject<{
220
+ type: z.ZodLiteral<"text">;
221
+ text: z.ZodString;
222
+ }, z.core.$strip>, z.ZodObject<{
223
+ type: z.ZodLiteral<"image">;
224
+ url: z.ZodString;
225
+ mimeType: z.ZodOptional<z.ZodString>;
226
+ text: z.ZodOptional<z.ZodString>;
227
+ }, z.core.$strip>], "type">, z.ZodTransform<MultiModalContent, {
228
+ type: "text";
229
+ text: string;
230
+ } | {
231
+ type: "image";
232
+ url: string;
233
+ mimeType?: string | undefined;
234
+ text?: string | undefined;
235
+ }>>>]>;
236
+ position: z.ZodNumber;
237
+ createdAt: z.ZodString;
238
+ metadata: z.ZodRecord<z.ZodString, z.ZodType<JSONValue, unknown, z.core.$ZodTypeInternals<JSONValue, unknown>>>;
239
+ hidden: z.ZodBoolean;
240
+ toolCall: z.ZodOptional<z.ZodObject<{
241
+ id: z.ZodString;
242
+ name: z.ZodString;
243
+ arguments: z.ZodType<JSONValue, unknown, z.core.$ZodTypeInternals<JSONValue, unknown>>;
244
+ }, z.core.$strip>>;
245
+ toolResult: z.ZodOptional<z.ZodObject<{
246
+ callId: z.ZodString;
247
+ outcome: z.ZodEnum<{
248
+ success: "success";
249
+ error: "error";
250
+ }>;
251
+ content: z.ZodType<JSONValue, unknown, z.core.$ZodTypeInternals<JSONValue, unknown>>;
252
+ toolCallId: z.ZodOptional<z.ZodString>;
253
+ toolName: z.ZodOptional<z.ZodString>;
254
+ result: z.ZodOptional<z.ZodType<JSONValue, unknown, z.core.$ZodTypeInternals<JSONValue, unknown>>>;
255
+ error: z.ZodOptional<z.ZodString>;
256
+ }, z.core.$strip>>;
257
+ tokenUsage: z.ZodOptional<z.ZodObject<{
258
+ prompt: z.ZodNumber;
259
+ completion: z.ZodNumber;
260
+ total: z.ZodNumber;
261
+ }, z.core.$strip>>;
262
+ goalCompleted: z.ZodOptional<z.ZodBoolean>;
263
+ }, z.core.$loose>>;
27
264
  readonly createdAt: z.ZodString;
28
265
  readonly updatedAt: z.ZodString;
29
266
  };
30
- export declare const conversationSchema: z.ZodType<ConversationJSON>;
267
+ /**
268
+ * Zod schema for serialized conversations.
269
+ */
270
+ export declare const conversationSchema: z.ZodObject<{
271
+ schemaVersion: z.ZodNumber;
272
+ id: z.ZodString;
273
+ title: z.ZodOptional<z.ZodString>;
274
+ status: z.ZodEnum<{
275
+ active: "active";
276
+ archived: "archived";
277
+ deleted: "deleted";
278
+ }>;
279
+ metadata: z.ZodRecord<z.ZodString, z.ZodType<JSONValue, unknown, z.core.$ZodTypeInternals<JSONValue, unknown>>>;
280
+ ids: z.ZodArray<z.ZodString>;
281
+ messages: z.ZodRecord<z.ZodString, z.ZodObject<{
282
+ id: z.ZodString;
283
+ role: z.ZodEnum<{
284
+ user: "user";
285
+ assistant: "assistant";
286
+ system: "system";
287
+ developer: "developer";
288
+ "tool-use": "tool-use";
289
+ "tool-result": "tool-result";
290
+ snapshot: "snapshot";
291
+ }>;
292
+ content: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodPipe<z.ZodDiscriminatedUnion<[z.ZodObject<{
293
+ type: z.ZodLiteral<"text">;
294
+ text: z.ZodString;
295
+ }, z.core.$strip>, z.ZodObject<{
296
+ type: z.ZodLiteral<"image">;
297
+ url: z.ZodString;
298
+ mimeType: z.ZodOptional<z.ZodString>;
299
+ text: z.ZodOptional<z.ZodString>;
300
+ }, z.core.$strip>], "type">, z.ZodTransform<MultiModalContent, {
301
+ type: "text";
302
+ text: string;
303
+ } | {
304
+ type: "image";
305
+ url: string;
306
+ mimeType?: string | undefined;
307
+ text?: string | undefined;
308
+ }>>>]>;
309
+ position: z.ZodNumber;
310
+ createdAt: z.ZodString;
311
+ metadata: z.ZodRecord<z.ZodString, z.ZodType<JSONValue, unknown, z.core.$ZodTypeInternals<JSONValue, unknown>>>;
312
+ hidden: z.ZodBoolean;
313
+ toolCall: z.ZodOptional<z.ZodObject<{
314
+ id: z.ZodString;
315
+ name: z.ZodString;
316
+ arguments: z.ZodType<JSONValue, unknown, z.core.$ZodTypeInternals<JSONValue, unknown>>;
317
+ }, z.core.$strip>>;
318
+ toolResult: z.ZodOptional<z.ZodObject<{
319
+ callId: z.ZodString;
320
+ outcome: z.ZodEnum<{
321
+ success: "success";
322
+ error: "error";
323
+ }>;
324
+ content: z.ZodType<JSONValue, unknown, z.core.$ZodTypeInternals<JSONValue, unknown>>;
325
+ toolCallId: z.ZodOptional<z.ZodString>;
326
+ toolName: z.ZodOptional<z.ZodString>;
327
+ result: z.ZodOptional<z.ZodType<JSONValue, unknown, z.core.$ZodTypeInternals<JSONValue, unknown>>>;
328
+ error: z.ZodOptional<z.ZodString>;
329
+ }, z.core.$strip>>;
330
+ tokenUsage: z.ZodOptional<z.ZodObject<{
331
+ prompt: z.ZodNumber;
332
+ completion: z.ZodNumber;
333
+ total: z.ZodNumber;
334
+ }, z.core.$strip>>;
335
+ goalCompleted: z.ZodOptional<z.ZodBoolean>;
336
+ }, z.core.$loose>>;
337
+ createdAt: z.ZodString;
338
+ updatedAt: z.ZodString;
339
+ }, z.core.$strip>;
31
340
  //# sourceMappingURL=schemas.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EACV,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,WAAW,EACX,WAAW,EACX,UAAU,EACV,QAAQ,EACR,UAAU,EACX,MAAM,SAAS,CAAC;AAEjB,eAAO,M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,gBAAgB;;;;;;;;;;;iBAQK,CAAC;AAEnC;;GAEG;AACH,eAAO,MAAM,gBAAgB;;;;iBAIK,CAAC;AAEnC;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBASK,CAAC;AAErC;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAcS,CAAC;AAExC;;GAEG;AACH,eAAO,MAAM,wBAAwB;;;;EAIK,CAAC;AAE3C;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAUpB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAEI,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { sortMessagesByPosition, sortObjectKeys } from '../utilities/deterministic';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sort/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,32 @@
1
+ // src/utilities/deterministic.ts
2
+ function sortObjectKeys(obj) {
3
+ if (obj === null || typeof obj !== "object") {
4
+ return obj;
5
+ }
6
+ if (Array.isArray(obj)) {
7
+ return obj.map(sortObjectKeys);
8
+ }
9
+ const sorted = {};
10
+ const keys = Object.keys(obj).sort();
11
+ for (const key of keys) {
12
+ sorted[key] = sortObjectKeys(obj[key]);
13
+ }
14
+ return sorted;
15
+ }
16
+ function sortMessagesByPosition(messages) {
17
+ return [...messages].sort((a, b) => {
18
+ if (a.position !== b.position) {
19
+ return a.position - b.position;
20
+ }
21
+ if (a.createdAt !== b.createdAt) {
22
+ return a.createdAt.localeCompare(b.createdAt);
23
+ }
24
+ return a.id.localeCompare(b.id);
25
+ });
26
+ }
27
+ export {
28
+ sortObjectKeys,
29
+ sortMessagesByPosition
30
+ };
31
+
32
+ //# debugId=9E6B840DBB18422664756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utilities/deterministic.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * Recursively sorts object keys alphabetically for deterministic JSON output.\n * Arrays are processed recursively but maintain their element order.\n * Primitives and null are returned as-is.\n *\n * @param obj - The value to process\n * @returns A new object with sorted keys (or the original value for non-objects)\n *\n * @example\n * ```ts\n * sortObjectKeys({ z: 1, a: 2 });\n * // Returns: { a: 2, z: 1 }\n *\n * sortObjectKeys({ b: { y: 1, x: 2 }, a: 1 });\n * // Returns: { a: 1, b: { x: 2, y: 1 } }\n * ```\n */\nexport function sortObjectKeys<T>(obj: T): T {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map(sortObjectKeys) as T;\n }\n\n const sorted: Record<string, unknown> = {};\n const keys = Object.keys(obj as object).sort();\n\n for (const key of keys) {\n sorted[key] = sortObjectKeys((obj as Record<string, unknown>)[key]);\n }\n\n return sorted as T;\n}\n\n/**\n * Sorts messages by position for deterministic output.\n * When positions are equal, falls back to createdAt, then id.\n *\n * @param messages - Array of messages to sort\n * @returns A new sorted array (does not mutate the original)\n *\n * @example\n * ```ts\n * const sorted = sortMessagesByPosition(messages);\n * // Messages are ordered by position (ascending)\n * ```\n */\nexport function sortMessagesByPosition<\n T extends { position: number; createdAt: string; id: string },\n>(messages: readonly T[]): T[] {\n return [...messages].sort((a, b) => {\n if (a.position !== b.position) {\n return a.position - b.position;\n }\n if (a.createdAt !== b.createdAt) {\n return a.createdAt.localeCompare(b.createdAt);\n }\n return a.id.localeCompare(b.id);\n });\n}\n"
6
+ ],
7
+ "mappings": ";AAiBO,SAAS,cAAiB,CAAC,KAAW;AAAA,EAC3C,IAAI,QAAQ,QAAQ,OAAO,QAAQ,UAAU;AAAA,IAC3C,OAAO;AAAA,EACT;AAAA,EAEA,IAAI,MAAM,QAAQ,GAAG,GAAG;AAAA,IACtB,OAAO,IAAI,IAAI,cAAc;AAAA,EAC/B;AAAA,EAEA,MAAM,SAAkC,CAAC;AAAA,EACzC,MAAM,OAAO,OAAO,KAAK,GAAa,EAAE,KAAK;AAAA,EAE7C,WAAW,OAAO,MAAM;AAAA,IACtB,OAAO,OAAO,eAAgB,IAAgC,IAAI;AAAA,EACpE;AAAA,EAEA,OAAO;AAAA;AAgBF,SAAS,sBAEf,CAAC,UAA6B;AAAA,EAC7B,OAAO,CAAC,GAAG,QAAQ,EAAE,KAAK,CAAC,GAAG,MAAM;AAAA,IAClC,IAAI,EAAE,aAAa,EAAE,UAAU;AAAA,MAC7B,OAAO,EAAE,WAAW,EAAE;AAAA,IACxB;AAAA,IACA,IAAI,EAAE,cAAc,EAAE,WAAW;AAAA,MAC/B,OAAO,EAAE,UAAU,cAAc,EAAE,SAAS;AAAA,IAC9C;AAAA,IACA,OAAO,EAAE,GAAG,cAAc,EAAE,EAAE;AAAA,GAC/B;AAAA;",
8
+ "debugId": "9E6B840DBB18422664756E2164756E21",
9
+ "names": []
10
+ }
@@ -1,6 +1,6 @@
1
1
  import type { MultiModalContent } from '@lasercat/homogenaize';
2
2
  import { type ConversationEnvironment } from './environment';
3
- import type { Conversation, Message, TokenUsage } from './types';
3
+ import type { Conversation, JSONValue, Message, TokenUsage } from './types';
4
4
  /**
5
5
  * Checks if a message is currently streaming (has the streaming metadata flag).
6
6
  */
@@ -13,7 +13,7 @@ export declare function getStreamingMessage(conversation: Conversation): Message
13
13
  * Creates a pending/streaming message placeholder and appends it to the conversation.
14
14
  * Returns both the updated conversation and the ID of the new streaming message.
15
15
  */
16
- export declare function appendStreamingMessage(conversation: Conversation, role: 'assistant' | 'user', metadata?: Record<string, unknown>, environment?: Partial<ConversationEnvironment>): {
16
+ export declare function appendStreamingMessage(conversation: Conversation, role: 'assistant' | 'user', metadata?: Record<string, JSONValue>, environment?: Partial<ConversationEnvironment>): {
17
17
  conversation: Conversation;
18
18
  messageId: string;
19
19
  };
@@ -28,7 +28,7 @@ export declare function updateStreamingMessage(conversation: Conversation, messa
28
28
  */
29
29
  export declare function finalizeStreamingMessage(conversation: Conversation, messageId: string, options?: {
30
30
  tokenUsage?: TokenUsage;
31
- metadata?: Record<string, unknown>;
31
+ metadata?: Record<string, JSONValue>;
32
32
  }, environment?: Partial<ConversationEnvironment>): Conversation;
33
33
  /**
34
34
  * Cancels a streaming message by removing it from the conversation.
@@ -1 +1 @@
1
- {"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../src/streaming.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,OAAO,EACL,KAAK,uBAAuB,EAE7B,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAKjE;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAE5D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,GAAG,SAAS,CAEnF;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,YAAY,EAC1B,IAAI,EAAE,WAAW,GAAG,MAAM,EAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,WAAW,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,GAC7C;IAAE,YAAY,EAAE,YAAY,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAyBnD;AAED;;;GAGG;AACH,wBAAgB,sBAAsB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AE,OAAO,CAAC,uBAAuB,CAAC,GAC7C;IAAE,YAAY,EAAE,YAAY,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CA0BnD;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GAAG,iBAAiB,EAAE,EACrC,WAAW,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,GAC7C,YAAY,CA2Bd;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE;IACR,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;CACtC,EACD,WAAW,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,GAC7C,YAAY,CAqCd;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,MAAM,EACjB,WAAW,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,GAC7C,YAAY,CA8Bd"}
package/dist/types.d.ts CHANGED
@@ -1,29 +1,55 @@
1
1
  import type { MultiModalContent } from '@lasercat/homogenaize';
2
2
  /**
3
- * Current schema version for ConversationJSON.
3
+ * Current schema version for serialized conversation data.
4
4
  * Increment when making breaking changes to the schema.
5
5
  */
6
- export declare const CURRENT_SCHEMA_VERSION = 1;
6
+ export declare const CURRENT_SCHEMA_VERSION = 3;
7
+ /**
8
+ * JSON-serializable value types.
9
+ */
10
+ export type JSONPrimitive = string | number | boolean | null;
11
+ export type JSONValue = JSONPrimitive | JSONValue[] | {
12
+ [key: string]: JSONValue;
13
+ };
14
+ /**
15
+ * Supported message roles in a conversation.
16
+ */
7
17
  export type MessageRole = 'user' | 'assistant' | 'system' | 'developer' | 'tool-use' | 'tool-result' | 'snapshot';
18
+ /**
19
+ * Tool call metadata for tool-use messages.
20
+ */
8
21
  export interface ToolCall {
9
22
  id: string;
10
23
  name: string;
11
- arguments: unknown;
24
+ arguments: JSONValue;
12
25
  }
26
+ /**
27
+ * Tool execution result metadata for tool-result messages.
28
+ */
13
29
  export interface ToolResult {
14
30
  callId: string;
15
31
  outcome: 'success' | 'error';
16
- content: unknown;
32
+ content: JSONValue;
33
+ toolCallId?: string | undefined;
34
+ toolName?: string | undefined;
35
+ result?: JSONValue | undefined;
36
+ error?: string | undefined;
17
37
  }
38
+ /**
39
+ * Token usage accounting for a message.
40
+ */
18
41
  export interface TokenUsage {
19
42
  prompt: number;
20
43
  completion: number;
21
44
  total: number;
22
45
  }
46
+ /**
47
+ * Mutable input shape for creating a message.
48
+ */
23
49
  export interface MessageInput {
24
50
  role: MessageRole;
25
51
  content: string | MultiModalContent[];
26
- metadata?: Record<string, unknown> | undefined;
52
+ metadata?: Record<string, JSONValue> | undefined;
27
53
  hidden?: boolean | undefined;
28
54
  toolCall?: ToolCall | undefined;
29
55
  toolResult?: ToolResult | undefined;
@@ -31,53 +57,44 @@ export interface MessageInput {
31
57
  /** Indicates if this message represents goal completion (assistant only) */
32
58
  goalCompleted?: boolean | undefined;
33
59
  }
34
- export interface MessageJSON {
35
- id: string;
36
- role: MessageRole;
37
- content: string | MultiModalContent[];
38
- position: number;
39
- createdAt: string;
40
- metadata: Record<string, unknown>;
41
- hidden: boolean;
42
- toolCall?: ToolCall | undefined;
43
- toolResult?: ToolResult | undefined;
44
- tokenUsage?: TokenUsage | undefined;
45
- /** Indicates if this message represents goal completion (assistant only) */
46
- goalCompleted?: boolean | undefined;
47
- }
60
+ /**
61
+ * Immutable message shape exposed by the library.
62
+ */
48
63
  export interface Message {
49
64
  id: string;
50
65
  role: MessageRole;
51
66
  content: string | ReadonlyArray<MultiModalContent>;
52
67
  position: number;
53
68
  createdAt: string;
54
- metadata: Readonly<Record<string, unknown>>;
69
+ metadata: Readonly<Record<string, JSONValue>>;
55
70
  hidden: boolean;
56
71
  toolCall?: Readonly<ToolCall> | undefined;
57
72
  toolResult?: Readonly<ToolResult> | undefined;
58
73
  tokenUsage?: Readonly<TokenUsage> | undefined;
59
- /** Indicates if this message represents goal completion (assistant only) */
74
+ }
75
+ /**
76
+ * Assistant-only message shape with optional goal completion metadata.
77
+ */
78
+ export interface AssistantMessage extends Message {
79
+ role: 'assistant';
80
+ /** Indicates if this message represents goal completion */
60
81
  goalCompleted?: boolean | undefined;
61
82
  }
83
+ /**
84
+ * Status values for a conversation lifecycle.
85
+ */
62
86
  export type ConversationStatus = 'active' | 'archived' | 'deleted';
63
- export interface ConversationJSON {
64
- schemaVersion: number;
65
- id: string;
66
- title?: string | undefined;
67
- status: ConversationStatus;
68
- metadata: Record<string, unknown>;
69
- tags: string[];
70
- messages: MessageJSON[];
71
- createdAt: string;
72
- updatedAt: string;
73
- }
87
+ /**
88
+ * Immutable conversation state.
89
+ */
74
90
  export interface Conversation {
91
+ schemaVersion: number;
75
92
  id: string;
76
93
  title?: string | undefined;
77
94
  status: ConversationStatus;
78
- metadata: Readonly<Record<string, unknown>>;
79
- tags: ReadonlyArray<string>;
80
- messages: ReadonlyArray<Message>;
95
+ metadata: Readonly<Record<string, JSONValue>>;
96
+ ids: ReadonlyArray<string>;
97
+ messages: Readonly<Record<string, Message>>;
81
98
  createdAt: string;
82
99
  updatedAt: string;
83
100
  }
@@ -92,15 +109,15 @@ export type MessagePlugin = (input: MessageInput) => MessageInput;
92
109
  /**
93
110
  * Serialized form of a single node in the conversation history tree.
94
111
  */
95
- export interface HistoryNodeJSON {
96
- conversation: ConversationJSON;
97
- children: HistoryNodeJSON[];
112
+ export interface HistoryNodeSnapshot {
113
+ conversation: Conversation;
114
+ children: HistoryNodeSnapshot[];
98
115
  }
99
116
  /**
100
117
  * Serialized form of the entire conversation history.
101
118
  */
102
- export interface ConversationHistoryJSON {
103
- root: HistoryNodeJSON;
119
+ export interface ConversationHistorySnapshot {
120
+ root: HistoryNodeSnapshot;
104
121
  currentPath: number[];
105
122
  }
106
123
  /**
@@ -108,16 +125,26 @@ export interface ConversationHistoryJSON {
108
125
  */
109
126
  export interface ExportOptions {
110
127
  /**
111
- * When true, produces deterministic output with sorted keys and messages.
112
- * Useful for testing, diffing, and content-addressable storage.
128
+ * When true, strips transient metadata (keys starting with '_').
113
129
  * @default false
114
130
  */
115
- deterministic?: boolean;
131
+ stripTransient?: boolean;
116
132
  /**
117
- * When true, strips transient metadata (keys starting with '_').
133
+ * When false, hidden messages are omitted from export output.
134
+ * @default true
135
+ */
136
+ includeHidden?: boolean;
137
+ /**
138
+ * When true, hidden message content is replaced with a redacted placeholder.
139
+ * Only applies when includeHidden is true.
118
140
  * @default false
119
141
  */
120
- stripTransient?: boolean;
142
+ redactHiddenContent?: boolean;
143
+ /**
144
+ * Placeholder used when redacting tool or hidden content.
145
+ * @default "[REDACTED]"
146
+ */
147
+ redactedPlaceholder?: string;
121
148
  /**
122
149
  * When true, redacts tool call arguments with '[REDACTED]'.
123
150
  * @default false
@@ -140,9 +167,4 @@ export interface ToMarkdownOptions extends ExportOptions {
140
167
  */
141
168
  includeMetadata?: boolean;
142
169
  }
143
- /**
144
- * Options for serializing conversations to JSON.
145
- * Alias for ExportOptions for API consistency.
146
- */
147
- export type SerializeOptions = ExportOptions;
148
170
  //# sourceMappingURL=types.d.ts.map