conversationalist 0.0.6 → 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.
- package/README.md +227 -58
- package/dist/adapters/anthropic/index.d.ts +11 -6
- package/dist/adapters/anthropic/index.d.ts.map +1 -1
- package/dist/adapters/anthropic/index.js +16 -3
- package/dist/adapters/anthropic/index.js.map +5 -4
- package/dist/adapters/gemini/index.d.ts +2 -2
- package/dist/adapters/gemini/index.d.ts.map +1 -1
- package/dist/adapters/gemini/index.js +52 -9
- package/dist/adapters/gemini/index.js.map +5 -4
- package/dist/adapters/openai/index.d.ts +32 -5
- package/dist/adapters/openai/index.d.ts.map +1 -1
- package/dist/adapters/openai/index.js +30 -8
- package/dist/adapters/openai/index.js.map +5 -4
- package/dist/context.d.ts.map +1 -1
- package/dist/conversation/append.d.ts +4 -4
- package/dist/conversation/append.d.ts.map +1 -1
- package/dist/conversation/create.d.ts +2 -3
- package/dist/conversation/create.d.ts.map +1 -1
- package/dist/conversation/index.d.ts +2 -2
- package/dist/conversation/index.d.ts.map +1 -1
- package/dist/conversation/modify.d.ts.map +1 -1
- package/dist/conversation/query.d.ts +9 -5
- package/dist/conversation/query.d.ts.map +1 -1
- package/dist/conversation/serialization.d.ts +21 -5
- package/dist/conversation/serialization.d.ts.map +1 -1
- package/dist/conversation/system-messages.d.ts +3 -3
- package/dist/conversation/system-messages.d.ts.map +1 -1
- package/dist/conversation/transform.d.ts.map +1 -1
- package/dist/conversation.d.ts +84 -14
- package/dist/conversation.d.ts.map +1 -1
- package/dist/export/index.d.ts +7 -0
- package/dist/export/index.d.ts.map +1 -0
- package/dist/export/index.js +3762 -0
- package/dist/export/index.js.map +62 -0
- package/dist/history.d.ts +102 -24
- package/dist/history.d.ts.map +1 -1
- package/dist/index.d.ts +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +440 -3982
- package/dist/index.js.map +15 -57
- package/dist/markdown/index.d.ts +15 -0
- package/dist/markdown/index.d.ts.map +1 -0
- package/dist/markdown/index.js +4969 -0
- package/dist/markdown/index.js.map +69 -0
- package/dist/message.d.ts +1 -1
- package/dist/message.d.ts.map +1 -1
- package/dist/multi-modal.d.ts +3 -0
- package/dist/multi-modal.d.ts.map +1 -1
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +59 -0
- package/dist/plugins/index.js.map +10 -0
- package/dist/plugins/pii-redaction.d.ts +10 -1
- package/dist/plugins/pii-redaction.d.ts.map +1 -1
- package/dist/redaction/index.d.ts +2 -0
- package/dist/redaction/index.d.ts.map +1 -0
- package/dist/redaction/index.js +59 -0
- package/dist/redaction/index.js.map +10 -0
- package/dist/schemas/index.d.ts +2 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +114 -0
- package/dist/schemas/index.js.map +10 -0
- package/dist/schemas.d.ts +325 -15
- package/dist/schemas.d.ts.map +1 -1
- package/dist/sort/index.d.ts +2 -0
- package/dist/sort/index.d.ts.map +1 -0
- package/dist/sort/index.js +32 -0
- package/dist/sort/index.js.map +10 -0
- package/dist/streaming.d.ts +3 -3
- package/dist/streaming.d.ts.map +1 -1
- package/dist/types.d.ts +107 -37
- package/dist/types.d.ts.map +1 -1
- package/dist/utilities/deterministic.d.ts +37 -0
- package/dist/utilities/deterministic.d.ts.map +1 -0
- package/dist/utilities/index.d.ts +3 -3
- package/dist/utilities/index.d.ts.map +1 -1
- package/dist/utilities/line-endings.d.ts +5 -0
- package/dist/utilities/line-endings.d.ts.map +1 -0
- package/dist/utilities/markdown.d.ts +47 -21
- package/dist/utilities/markdown.d.ts.map +1 -1
- package/dist/utilities/message-store.d.ts +6 -0
- package/dist/utilities/message-store.d.ts.map +1 -0
- package/dist/utilities/message.d.ts +9 -3
- package/dist/utilities/message.d.ts.map +1 -1
- package/dist/utilities/tool-calls.d.ts +4 -4
- package/dist/utilities/tool-calls.d.ts.map +1 -1
- package/dist/utilities/tool-results.d.ts +10 -0
- package/dist/utilities/tool-results.d.ts.map +1 -0
- package/dist/utilities/transient.d.ts +47 -0
- package/dist/utilities/transient.d.ts.map +1 -0
- package/dist/utilities.d.ts +6 -4
- package/dist/utilities.d.ts.map +1 -1
- package/dist/versioning/index.d.ts +3 -0
- package/dist/versioning/index.d.ts.map +1 -0
- package/dist/versioning/index.js +58 -0
- package/dist/versioning/index.js.map +11 -0
- package/dist/with-conversation.d.ts +8 -8
- package/dist/with-conversation.d.ts.map +1 -1
- package/package.json +26 -1
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,MAAM,MAAM,WAAW,GACnB,MAAM,GACN,WAAW,GACX,QAAQ,GACR,WAAW,GACX,UAAU,GACV,aAAa,GACb,UAAU,CAAC;AAEf,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE/D;;;GAGG;AACH,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAC7D,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,SAAS,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEnF;;GAEG;AACH,MAAM,MAAM,WAAW,GACnB,MAAM,GACN,WAAW,GACX,QAAQ,GACR,WAAW,GACX,UAAU,GACV,aAAa,GACb,UAAU,CAAC;AAE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AElE;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,YAAY,CAAC;IAC3B,QAAQ,EAAE,mBAAmB,EAAE,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,mBAAmB,CAAC;IAC1B,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAE9B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAE9B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,aAAa;IACtD;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively sorts object keys alphabetically for deterministic JSON output.
|
|
3
|
+
* Arrays are processed recursively but maintain their element order.
|
|
4
|
+
* Primitives and null are returned as-is.
|
|
5
|
+
*
|
|
6
|
+
* @param obj - The value to process
|
|
7
|
+
* @returns A new object with sorted keys (or the original value for non-objects)
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* sortObjectKeys({ z: 1, a: 2 });
|
|
12
|
+
* // Returns: { a: 2, z: 1 }
|
|
13
|
+
*
|
|
14
|
+
* sortObjectKeys({ b: { y: 1, x: 2 }, a: 1 });
|
|
15
|
+
* // Returns: { a: 1, b: { x: 2, y: 1 } }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function sortObjectKeys<T>(obj: T): T;
|
|
19
|
+
/**
|
|
20
|
+
* Sorts messages by position for deterministic output.
|
|
21
|
+
* When positions are equal, falls back to createdAt, then id.
|
|
22
|
+
*
|
|
23
|
+
* @param messages - Array of messages to sort
|
|
24
|
+
* @returns A new sorted array (does not mutate the original)
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const sorted = sortMessagesByPosition(messages);
|
|
29
|
+
* // Messages are ordered by position (ascending)
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function sortMessagesByPosition<T extends {
|
|
33
|
+
position: number;
|
|
34
|
+
createdAt: string;
|
|
35
|
+
id: string;
|
|
36
|
+
}>(messages: readonly T[]): T[];
|
|
37
|
+
//# sourceMappingURL=deterministic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deterministic.d.ts","sourceRoot":"","sources":["../../src/utilities/deterministic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAiB3C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CACpC,CAAC,SAAS;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,EAC7D,QAAQ,EAAE,SAAS,CAAC,EAAE,GAAG,CAAC,EAAE,CAU7B"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
export type { ToMarkdownOptions } from '../types';
|
|
1
2
|
export { normalizeContent, toMultiModalArray } from './content';
|
|
2
|
-
export
|
|
3
|
-
export { fromMarkdown, MarkdownParseError, toMarkdown } from './markdown';
|
|
4
|
-
export { createMessage, messageHasImages, messageParts, messageText, messageToJSON, messageToString, } from './message';
|
|
3
|
+
export { createMessage, isAssistantMessage, messageHasImages, messageParts, messageText, messageToJSON, messageToString, } from './message';
|
|
5
4
|
export type { ToolCallPair } from './tool-calls';
|
|
6
5
|
export { pairToolCallsWithResults } from './tool-calls';
|
|
6
|
+
export { isTransientKey, stripTransientFromRecord, stripTransientMetadata, } from './transient';
|
|
7
7
|
export { hasOwnProperty, toReadonly } from './type-helpers';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utilities/index.ts"],"names":[],"mappings":"AACA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utilities/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAGlD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAKhE,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,aAAa,EACb,eAAe,GAChB,MAAM,WAAW,CAAC;AAGnB,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAGxD,OAAO,EACL,cAAc,EACd,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line-endings.d.ts","sourceRoot":"","sources":["../../src/utilities/line-endings.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzD"}
|
|
@@ -1,25 +1,51 @@
|
|
|
1
|
-
import type { Conversation } from '../types';
|
|
1
|
+
import type { Conversation, MessageRole, ToMarkdownOptions } from '../types';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Maps message roles to human-readable display labels.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* ROLE_LABELS['tool-use']; // 'Tool Use'
|
|
8
|
+
* ROLE_LABELS.assistant; // 'Assistant'
|
|
9
|
+
* ```
|
|
4
10
|
*/
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
export declare const ROLE_LABELS: Record<MessageRole, string>;
|
|
12
|
+
/**
|
|
13
|
+
* Maps display labels back to message roles.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* LABEL_TO_ROLE['Tool Use']; // 'tool-use'
|
|
18
|
+
* LABEL_TO_ROLE.User; // 'user'
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const LABEL_TO_ROLE: Record<string, MessageRole>;
|
|
22
|
+
/**
|
|
23
|
+
* Gets the human-readable display label for a message role.
|
|
24
|
+
*
|
|
25
|
+
* @param role - The message role
|
|
26
|
+
* @returns The display label for the role
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* getRoleLabel('assistant'); // 'Assistant'
|
|
31
|
+
* getRoleLabel('tool-use'); // 'Tool Use'
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function getRoleLabel(role: MessageRole): string;
|
|
35
|
+
/**
|
|
36
|
+
* Gets the message role from a display label.
|
|
37
|
+
*
|
|
38
|
+
* @param label - The display label
|
|
39
|
+
* @returns The message role, or undefined if the label is not recognized
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* getRoleFromLabel('Assistant'); // 'assistant'
|
|
44
|
+
* getRoleFromLabel('Tool Use'); // 'tool-use'
|
|
45
|
+
* getRoleFromLabel('Unknown'); // undefined
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare function getRoleFromLabel(label: string): MessageRole | undefined;
|
|
23
49
|
/**
|
|
24
50
|
* Converts a conversation to a Markdown string representation.
|
|
25
51
|
*
|
|
@@ -66,7 +92,7 @@ export declare class MarkdownParseError extends Error {
|
|
|
66
92
|
* - Conversation ID and timestamps are generated
|
|
67
93
|
* - Message IDs are generated, positions are inferred from order
|
|
68
94
|
* - Content is parsed from markdown body
|
|
69
|
-
* - Defaults: status='active', hidden=false, empty metadata
|
|
95
|
+
* - Defaults: status='active', hidden=false, empty metadata
|
|
70
96
|
*
|
|
71
97
|
* @param markdown - The markdown string to parse
|
|
72
98
|
* @returns A Conversation object
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/utilities/markdown.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/utilities/markdown.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAEV,YAAY,EAIZ,WAAW,EAEX,iBAAiB,EAGlB,MAAM,UAAU,CAAC;AAQlB;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAQnD,CAAC;AAKF;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAQrD,CAAC;AAKF;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CAEtD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAEvE;AAgKD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,UAAU,CACxB,YAAY,EAAE,YAAY,EAC1B,OAAO,GAAE,iBAAsB,GAC9B,MAAM,CASR;AAwFD;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;gBAC/B,OAAO,EAAE,MAAM;CAI5B;AASD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,CAW3D"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Conversation, Message } from '../types';
|
|
2
|
+
export declare function getOrderedMessages(conversation: Conversation): Message[];
|
|
3
|
+
export declare function toIdRecord<T extends {
|
|
4
|
+
id: string;
|
|
5
|
+
}>(items: readonly T[]): Record<string, T>;
|
|
6
|
+
//# sourceMappingURL=message-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-store.d.ts","sourceRoot":"","sources":["../../src/utilities/message-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEtD,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,EAAE,CASxE;AAED,wBAAgB,UAAU,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EACjD,KAAK,EAAE,SAAS,CAAC,EAAE,GAClB,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAMnB"}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import type { MultiModalContent } from '@lasercat/homogenaize';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AssistantMessage, Message } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Creates an immutable Message from a JSON representation.
|
|
5
5
|
* Deep copies nested objects and arrays to ensure immutability.
|
|
6
6
|
*/
|
|
7
|
-
export declare function createMessage(props:
|
|
7
|
+
export declare function createMessage(props: AssistantMessage): AssistantMessage;
|
|
8
|
+
export declare function createMessage(props: Message): Message;
|
|
8
9
|
/**
|
|
9
10
|
* Converts an immutable Message to a mutable JSON representation.
|
|
10
11
|
* Creates deep copies of all nested objects.
|
|
11
12
|
*/
|
|
12
|
-
export declare function messageToJSON(message:
|
|
13
|
+
export declare function messageToJSON(message: AssistantMessage): AssistantMessage;
|
|
14
|
+
export declare function messageToJSON(message: Message): Message;
|
|
13
15
|
/**
|
|
14
16
|
* Extracts the content parts from a message as a multi-modal array.
|
|
15
17
|
* String content is converted to a single text part.
|
|
@@ -29,4 +31,8 @@ export declare function messageHasImages(message: Message): boolean;
|
|
|
29
31
|
* Images are rendered as markdown image syntax.
|
|
30
32
|
*/
|
|
31
33
|
export declare function messageToString(message: Message): string;
|
|
34
|
+
/**
|
|
35
|
+
* Type guard for narrowing a Message to an AssistantMessage.
|
|
36
|
+
*/
|
|
37
|
+
export declare function isAssistantMessage(message: Message): message is AssistantMessage;
|
|
32
38
|
//# sourceMappingURL=message.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/utilities/message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG/D,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/utilities/message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAG1D;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,gBAAgB,GAAG,gBAAgB,CAAC;AACzE,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;AAiCvD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,gBAAgB,GAAG,gBAAgB,CAAC;AAC3E,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC;AA4BzD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,aAAa,CAAC,iBAAiB,CAAC,CAO/E;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,GAAE,MAAe,GAAG,MAAM,CAM7E;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAE1D;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CASxD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,gBAAgB,CAEhF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { JSONValue, Message, ToolResult } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Represents a paired tool call with its optional result.
|
|
4
4
|
*/
|
|
@@ -7,7 +7,7 @@ export interface ToolCallPair {
|
|
|
7
7
|
call: {
|
|
8
8
|
id: string;
|
|
9
9
|
name: string;
|
|
10
|
-
arguments:
|
|
10
|
+
arguments: JSONValue;
|
|
11
11
|
};
|
|
12
12
|
/** The corresponding result, if available */
|
|
13
13
|
result?: ToolResult | undefined;
|
|
@@ -20,7 +20,7 @@ export interface ToolCallPair {
|
|
|
20
20
|
* 1. Collects all tool results into a map by their callId
|
|
21
21
|
* 2. Pairs each tool call with its matching result (if any)
|
|
22
22
|
*
|
|
23
|
-
* @param messages -
|
|
23
|
+
* @param messages - Messages that may contain tool calls and results (array or record)
|
|
24
24
|
* @returns Array of tool call pairs, preserving the order of tool calls
|
|
25
25
|
*
|
|
26
26
|
* @example
|
|
@@ -29,5 +29,5 @@ export interface ToolCallPair {
|
|
|
29
29
|
* // pairs: [{ call: ToolCall, result?: ToolResult }, ...]
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
|
-
export declare function pairToolCallsWithResults(messages:
|
|
32
|
+
export declare function pairToolCallsWithResults(messages: ReadonlyArray<Message> | Readonly<Record<string, Message>>): ToolCallPair[];
|
|
33
33
|
//# sourceMappingURL=tool-calls.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-calls.d.ts","sourceRoot":"","sources":["../../src/utilities/tool-calls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"tool-calls.d.ts","sourceRoot":"","sources":["../../src/utilities/tool-calls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,oBAAoB;IACpB,IAAI,EAAE;QACJ,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,SAAS,CAAC;KACtB,CAAC;IACF,6CAA6C;IAC7C,MAAM,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;CACjC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACnE,YAAY,EAAE,CA6BhB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ToolResult } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a shallow copy of a tool result.
|
|
4
|
+
*/
|
|
5
|
+
export declare function copyToolResult(toolResult: ToolResult): ToolResult;
|
|
6
|
+
/**
|
|
7
|
+
* Redacts tool result payload fields while preserving the original shape.
|
|
8
|
+
*/
|
|
9
|
+
export declare function redactToolResult(toolResult: ToolResult, placeholder: string): ToolResult;
|
|
10
|
+
//# sourceMappingURL=tool-results.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-results.d.ts","sourceRoot":"","sources":["../../src/utilities/tool-results.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C;;GAEG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAEjE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,MAAM,GAClB,UAAU,CASZ"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Conversation, JSONValue } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a metadata key is transient (starts with '_').
|
|
4
|
+
* Transient metadata is intended for temporary UI state and should not be persisted.
|
|
5
|
+
*
|
|
6
|
+
* @param key - The metadata key to check
|
|
7
|
+
* @returns true if the key starts with '_'
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* isTransientKey('_tempId'); // true
|
|
12
|
+
* isTransientKey('__internal'); // true
|
|
13
|
+
* isTransientKey('source'); // false
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function isTransientKey(key: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Strips transient metadata (keys starting with '_') from a metadata object.
|
|
19
|
+
*
|
|
20
|
+
* @param metadata - The metadata object to filter
|
|
21
|
+
* @returns A new object with transient keys removed
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* stripTransientFromRecord({ _temp: 1, source: 'web' });
|
|
26
|
+
* // Returns: { source: 'web' }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function stripTransientFromRecord(metadata: Record<string, JSONValue>): Record<string, JSONValue>;
|
|
30
|
+
/**
|
|
31
|
+
* Strips all transient metadata from a conversation.
|
|
32
|
+
* Transient metadata is identified by keys starting with '_'.
|
|
33
|
+
* This is useful for persisting conversations without temporary UI state.
|
|
34
|
+
*
|
|
35
|
+
* @param conversation - The conversation to process
|
|
36
|
+
* @returns A new conversation with transient metadata removed from both
|
|
37
|
+
* the conversation and all messages
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const cleaned = stripTransientMetadata(conversation);
|
|
42
|
+
* // conversation.metadata._tempState is removed
|
|
43
|
+
* // message.metadata._deliveryStatus is removed
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function stripTransientMetadata(conversation: Conversation): Conversation;
|
|
47
|
+
//# sourceMappingURL=transient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transient.d.ts","sourceRoot":"","sources":["../../src/utilities/transient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,YAAY,EAAE,SAAS,EAAW,MAAM,UAAU,CAAC;AAKnF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAClC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAQ3B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,YAAY,GAAG,YAAY,CAsC/E"}
|
package/dist/utilities.d.ts
CHANGED
|
@@ -2,16 +2,18 @@
|
|
|
2
2
|
* This file re-exports all utilities from the utilities/ directory.
|
|
3
3
|
* For new code, prefer importing directly from the specific modules:
|
|
4
4
|
* - './utilities/content' for content normalization
|
|
5
|
-
* - './utilities/
|
|
5
|
+
* - './utilities/deterministic' for sort utilities (also exported via conversationalist/sort)
|
|
6
|
+
* - './utilities/markdown' for markdown conversion (exposed via conversationalist/markdown)
|
|
6
7
|
* - './utilities/message' for message utilities
|
|
7
8
|
* - './utilities/tool-calls' for tool call pairing
|
|
9
|
+
* - './utilities/transient' for transient metadata handling
|
|
8
10
|
* - './utilities/type-helpers' for type guard helpers
|
|
9
11
|
*/
|
|
12
|
+
export type { ToMarkdownOptions } from './types';
|
|
10
13
|
export { normalizeContent, toMultiModalArray } from './utilities/content';
|
|
11
|
-
export
|
|
12
|
-
export { fromMarkdown, MarkdownParseError, toMarkdown } from './utilities/markdown';
|
|
13
|
-
export { createMessage, messageHasImages, messageParts, messageText, messageToJSON, messageToString, } from './utilities/message';
|
|
14
|
+
export { createMessage, isAssistantMessage, messageHasImages, messageParts, messageText, messageToJSON, messageToString, } from './utilities/message';
|
|
14
15
|
export type { ToolCallPair } from './utilities/tool-calls';
|
|
15
16
|
export { pairToolCallsWithResults } from './utilities/tool-calls';
|
|
17
|
+
export { isTransientKey, stripTransientFromRecord, stripTransientMetadata, } from './utilities/transient';
|
|
16
18
|
export { hasOwnProperty, toReadonly } from './utilities/type-helpers';
|
|
17
19
|
//# sourceMappingURL=utilities.d.ts.map
|
package/dist/utilities.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAGjD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAK1E,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,aAAa,EACb,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAG7B,YAAY,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAGlE,OAAO,EACL,cAAc,EACd,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/versioning/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// src/types.ts
|
|
2
|
+
var CURRENT_SCHEMA_VERSION = 3;
|
|
3
|
+
// src/conversation/serialization.ts
|
|
4
|
+
function migrateConversation(json) {
|
|
5
|
+
if (typeof json !== "object" || json === null || Array.isArray(json)) {
|
|
6
|
+
return {
|
|
7
|
+
schemaVersion: CURRENT_SCHEMA_VERSION,
|
|
8
|
+
id: "",
|
|
9
|
+
status: "active",
|
|
10
|
+
metadata: {},
|
|
11
|
+
ids: [],
|
|
12
|
+
messages: {},
|
|
13
|
+
createdAt: new Date().toISOString(),
|
|
14
|
+
updatedAt: new Date().toISOString()
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const data = json;
|
|
18
|
+
const rawMessages = data.messages;
|
|
19
|
+
let messages = {};
|
|
20
|
+
let ids = [];
|
|
21
|
+
const rawIds = data.ids;
|
|
22
|
+
const isStringArray = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
23
|
+
if (Array.isArray(rawMessages)) {
|
|
24
|
+
const rawMessageArray = rawMessages;
|
|
25
|
+
ids = rawMessageArray.map((message) => message.id);
|
|
26
|
+
messages = Object.fromEntries(rawMessageArray.map((message) => [message.id, message]));
|
|
27
|
+
} else if (rawMessages && typeof rawMessages === "object") {
|
|
28
|
+
messages = { ...rawMessages };
|
|
29
|
+
if (isStringArray(rawIds) && rawIds.length > 0) {
|
|
30
|
+
ids = [...rawIds];
|
|
31
|
+
} else {
|
|
32
|
+
ids = Object.values(messages).sort((a, b) => a.position - b.position).map((message) => message.id);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (ids.length > 0) {
|
|
36
|
+
ids = ids.filter((id) => (id in messages));
|
|
37
|
+
const missing = Object.keys(messages).filter((id) => !ids.includes(id));
|
|
38
|
+
if (missing.length > 0) {
|
|
39
|
+
const sortedMissing = missing.sort((a, b) => (messages[a]?.position ?? 0) - (messages[b]?.position ?? 0));
|
|
40
|
+
ids = [...ids, ...sortedMissing];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (!("schemaVersion" in json)) {
|
|
44
|
+
return {
|
|
45
|
+
...data,
|
|
46
|
+
schemaVersion: CURRENT_SCHEMA_VERSION,
|
|
47
|
+
ids,
|
|
48
|
+
messages
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return { ...data, ids, messages };
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
migrateConversation,
|
|
55
|
+
CURRENT_SCHEMA_VERSION
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
//# debugId=F3F48096769F752764756E2164756E21
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/types.ts", "../../src/conversation/serialization.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { MultiModalContent } from '@lasercat/homogenaize';\n\n/**\n * Current schema version for serialized conversation data.\n * Increment when making breaking changes to the schema.\n */\nexport const CURRENT_SCHEMA_VERSION = 3;\n\n/**\n * JSON-serializable value types.\n */\nexport type JSONPrimitive = string | number | boolean | null;\nexport type JSONValue = JSONPrimitive | JSONValue[] | { [key: string]: JSONValue };\n\n/**\n * Supported message roles in a conversation.\n */\nexport type MessageRole =\n | 'user'\n | 'assistant'\n | 'system'\n | 'developer'\n | 'tool-use'\n | 'tool-result'\n | 'snapshot';\n\n/**\n * Tool call metadata for tool-use messages.\n */\nexport interface ToolCall {\n id: string;\n name: string;\n arguments: JSONValue;\n}\n\n/**\n * Tool execution result metadata for tool-result messages.\n */\nexport interface ToolResult {\n callId: string;\n outcome: 'success' | 'error';\n content: JSONValue;\n toolCallId?: string | undefined;\n toolName?: string | undefined;\n result?: JSONValue | undefined;\n error?: string | undefined;\n}\n\n/**\n * Token usage accounting for a message.\n */\nexport interface TokenUsage {\n prompt: number;\n completion: number;\n total: number;\n}\n\n/**\n * Mutable input shape for creating a message.\n */\nexport interface MessageInput {\n role: MessageRole;\n content: string | MultiModalContent[];\n metadata?: Record<string, JSONValue> | undefined;\n hidden?: boolean | undefined;\n toolCall?: ToolCall | undefined;\n toolResult?: ToolResult | undefined;\n tokenUsage?: TokenUsage | undefined;\n /** Indicates if this message represents goal completion (assistant only) */\n goalCompleted?: boolean | undefined;\n}\n\n/**\n * Immutable message shape exposed by the library.\n */\nexport interface Message {\n id: string;\n role: MessageRole;\n content: string | ReadonlyArray<MultiModalContent>;\n position: number;\n createdAt: string;\n metadata: Readonly<Record<string, JSONValue>>;\n hidden: boolean;\n toolCall?: Readonly<ToolCall> | undefined;\n toolResult?: Readonly<ToolResult> | undefined;\n tokenUsage?: Readonly<TokenUsage> | undefined;\n}\n\n/**\n * Assistant-only message shape with optional goal completion metadata.\n */\nexport interface AssistantMessage extends Message {\n role: 'assistant';\n /** Indicates if this message represents goal completion */\n goalCompleted?: boolean | undefined;\n}\n\n/**\n * Status values for a conversation lifecycle.\n */\nexport type ConversationStatus = 'active' | 'archived' | 'deleted';\n\n/**\n * Immutable conversation state.\n */\nexport interface Conversation {\n schemaVersion: number;\n id: string;\n title?: string | undefined;\n status: ConversationStatus;\n metadata: Readonly<Record<string, JSONValue>>;\n ids: ReadonlyArray<string>;\n messages: Readonly<Record<string, Message>>;\n createdAt: string;\n updatedAt: string;\n}\n\n/**\n * A function that estimates the number of tokens in a message.\n */\nexport type TokenEstimator = (message: Message) => number;\n\n/**\n * A plugin that can transform a MessageInput before it is appended.\n */\nexport type MessagePlugin = (input: MessageInput) => MessageInput;\n\n/**\n * Serialized form of a single node in the conversation history tree.\n */\nexport interface HistoryNodeSnapshot {\n conversation: Conversation;\n children: HistoryNodeSnapshot[];\n}\n\n/**\n * Serialized form of the entire conversation history.\n */\nexport interface ConversationHistorySnapshot {\n root: HistoryNodeSnapshot;\n currentPath: number[];\n}\n\n/**\n * Base options for all export operations.\n */\nexport interface ExportOptions {\n /**\n * When true, strips transient metadata (keys starting with '_').\n * @default false\n */\n stripTransient?: boolean;\n\n /**\n * When false, hidden messages are omitted from export output.\n * @default true\n */\n includeHidden?: boolean;\n\n /**\n * When true, hidden message content is replaced with a redacted placeholder.\n * Only applies when includeHidden is true.\n * @default false\n */\n redactHiddenContent?: boolean;\n\n /**\n * Placeholder used when redacting tool or hidden content.\n * @default \"[REDACTED]\"\n */\n redactedPlaceholder?: string;\n\n /**\n * When true, redacts tool call arguments with '[REDACTED]'.\n * @default false\n */\n redactToolArguments?: boolean;\n\n /**\n * When true, redacts tool result content with '[REDACTED]'.\n * @default false\n */\n redactToolResults?: boolean;\n}\n\n/**\n * Options for exporting to markdown format.\n */\nexport interface ToMarkdownOptions extends ExportOptions {\n /**\n * When true, includes YAML frontmatter with full metadata for lossless round-trip.\n * Headers include message ID: `### Role (msg-id)`\n * @default false\n */\n includeMetadata?: boolean;\n}\n",
|
|
6
|
+
"import { createInvalidPositionError, createSerializationError } from '../errors';\nimport type { Conversation, Message } from '../types';\nimport { CURRENT_SCHEMA_VERSION } from '../types';\nimport { createMessage, toReadonly } from '../utilities';\nimport { toIdRecord } from '../utilities/message-store';\nimport { assertToolReference, registerToolUse, type ToolUseIndex } from './tool-tracking';\n\n/**\n * Migrates a serialized conversation object to the current schema version.\n * Handles data from older versions that may not have a schemaVersion field.\n *\n * @param json - The conversation data to migrate (may be from an older version)\n * @returns A Conversation with the current schema version\n *\n * @example\n * ```ts\n * // Old data without schemaVersion\n * const old = { id: 'conv-1', status: 'active', ... };\n * const migrated = migrateConversation(old);\n * // migrated.schemaVersion === CURRENT_SCHEMA_VERSION\n * ```\n */\nexport function migrateConversation(json: unknown): Conversation {\n // Handle non-object input\n if (typeof json !== 'object' || json === null || Array.isArray(json)) {\n return {\n schemaVersion: CURRENT_SCHEMA_VERSION,\n id: '',\n status: 'active',\n metadata: {},\n ids: [],\n messages: {},\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n };\n }\n\n const data = json as Conversation & { messages?: unknown };\n const rawMessages = data.messages;\n\n let messages: Record<string, Message> = {};\n let ids: string[] = [];\n const rawIds = (data as { ids?: unknown }).ids;\n const isStringArray = (value: unknown): value is string[] =>\n Array.isArray(value) && value.every((item) => typeof item === 'string');\n\n if (Array.isArray(rawMessages)) {\n const rawMessageArray = rawMessages as Message[];\n ids = rawMessageArray.map((message) => message.id);\n messages = Object.fromEntries(\n rawMessageArray.map((message) => [message.id, message]),\n );\n } else if (rawMessages && typeof rawMessages === 'object') {\n messages = { ...(rawMessages as Record<string, Message>) };\n if (isStringArray(rawIds) && rawIds.length > 0) {\n ids = [...rawIds];\n } else {\n ids = Object.values(messages)\n .sort((a, b) => a.position - b.position)\n .map((message) => message.id);\n }\n }\n\n if (ids.length > 0) {\n ids = ids.filter((id) => id in messages);\n const missing = Object.keys(messages).filter((id) => !ids.includes(id));\n if (missing.length > 0) {\n const sortedMissing = missing.sort(\n (a, b) => (messages[a]?.position ?? 0) - (messages[b]?.position ?? 0),\n );\n ids = [...ids, ...sortedMissing];\n }\n }\n\n // If no schemaVersion, assume pre-versioning data (version 0) and add it\n if (!('schemaVersion' in json)) {\n return {\n ...data,\n schemaVersion: CURRENT_SCHEMA_VERSION,\n ids,\n messages,\n };\n }\n\n // Future: add migration logic between versions here\n return { ...data, ids, messages };\n}\n\n/**\n * Reconstructs a conversation from a JSON object.\n * Automatically migrates data from older schema versions.\n * Validates message positions are contiguous and tool results reference valid calls.\n * Throws a serialization error if validation fails.\n *\n * @param json - The conversation JSON to deserialize (may be from an older version)\n * @returns A Conversation object\n * @throws {SerializationError} If validation fails\n */\nexport function deserializeConversation(json: unknown): Conversation {\n // Migrate to current schema version\n const migrated = migrateConversation(json);\n\n try {\n const orderedMessages = migrated.ids.map((id, index) => {\n const message = migrated.messages[id];\n if (!message) {\n throw createSerializationError(`missing message for id ${id}`);\n }\n if (message.position !== index) {\n throw createInvalidPositionError(index, message.position);\n }\n return message;\n });\n\n orderedMessages.reduce<{ toolUses: ToolUseIndex }>(\n (state, message) => {\n if (message.role === 'tool-use' && message.toolCall) {\n return {\n toolUses: registerToolUse(state.toolUses, message.toolCall),\n };\n }\n\n if (message.role === 'tool-result' && message.toolResult) {\n assertToolReference(state.toolUses, message.toolResult.callId);\n }\n\n return state;\n },\n { toolUses: new Map<string, { name: string }>() },\n );\n\n const messageInstances: Message[] = orderedMessages.map((m) => createMessage(m));\n const conv: Conversation = {\n schemaVersion: migrated.schemaVersion,\n id: migrated.id,\n title: migrated.title,\n status: migrated.status,\n metadata: { ...migrated.metadata },\n ids: orderedMessages.map((message) => message.id),\n messages: toIdRecord(messageInstances),\n createdAt: migrated.createdAt,\n updatedAt: migrated.updatedAt,\n };\n return toReadonly(conv);\n } catch (error) {\n throw createSerializationError(\n `failed to deserialize conversation: ${\n error instanceof Error ? error.message : String(error)\n }`,\n error as Error,\n );\n }\n}\n"
|
|
7
|
+
],
|
|
8
|
+
"mappings": ";AAMO,IAAM,yBAAyB;;ACgB/B,SAAS,mBAAmB,CAAC,MAA6B;AAAA,EAE/D,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,MAAM,QAAQ,IAAI,GAAG;AAAA,IACpE,OAAO;AAAA,MACL,eAAe;AAAA,MACf,IAAI;AAAA,MACJ,QAAQ;AAAA,MACR,UAAU,CAAC;AAAA,MACX,KAAK,CAAC;AAAA,MACN,UAAU,CAAC;AAAA,MACX,WAAW,IAAI,KAAK,EAAE,YAAY;AAAA,MAClC,WAAW,IAAI,KAAK,EAAE,YAAY;AAAA,IACpC;AAAA,EACF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IAAI,EAAE,mBAAmB,OAAO;AAAA,IAC9B,OAAO;AAAA,SACF;AAAA,MACH,eAAe;AAAA,MACf;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EAGA,OAAO,KAAK,MAAM,KAAK,SAAS;AAAA;",
|
|
9
|
+
"debugId": "F3F48096769F752764756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MultiModalContent } from '@lasercat/homogenaize';
|
|
2
|
-
import type { Conversation, Message, MessageInput, TokenUsage } from './types';
|
|
2
|
+
import type { Conversation, JSONValue, Message, MessageInput, TokenUsage } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* A mutable draft wrapper around a conversation.
|
|
5
5
|
* Methods return the draft for chaining and mutate the internal state.
|
|
@@ -27,31 +27,31 @@ export interface ConversationDraft {
|
|
|
27
27
|
* @param content - Text or multi-modal content.
|
|
28
28
|
* @param metadata - Optional metadata to attach to the message.
|
|
29
29
|
*/
|
|
30
|
-
appendUserMessage: (content: MessageInput['content'], metadata?: Record<string,
|
|
30
|
+
appendUserMessage: (content: MessageInput['content'], metadata?: Record<string, JSONValue>) => ConversationDraft;
|
|
31
31
|
/**
|
|
32
32
|
* Appends an assistant message to the conversation.
|
|
33
33
|
* @param content - Text or multi-modal content.
|
|
34
34
|
* @param metadata - Optional metadata to attach to the message.
|
|
35
35
|
*/
|
|
36
|
-
appendAssistantMessage: (content: MessageInput['content'], metadata?: Record<string,
|
|
36
|
+
appendAssistantMessage: (content: MessageInput['content'], metadata?: Record<string, JSONValue>) => ConversationDraft;
|
|
37
37
|
/**
|
|
38
38
|
* Appends a system message to the conversation.
|
|
39
39
|
* @param content - The system message content.
|
|
40
40
|
* @param metadata - Optional metadata to attach to the message.
|
|
41
41
|
*/
|
|
42
|
-
appendSystemMessage: (content: string, metadata?: Record<string,
|
|
42
|
+
appendSystemMessage: (content: string, metadata?: Record<string, JSONValue>) => ConversationDraft;
|
|
43
43
|
/**
|
|
44
44
|
* Prepends a system message at position 0, renumbering existing messages.
|
|
45
45
|
* @param content - The system message content.
|
|
46
46
|
* @param metadata - Optional metadata to attach to the message.
|
|
47
47
|
*/
|
|
48
|
-
prependSystemMessage: (content: string, metadata?: Record<string,
|
|
48
|
+
prependSystemMessage: (content: string, metadata?: Record<string, JSONValue>) => ConversationDraft;
|
|
49
49
|
/**
|
|
50
50
|
* Replaces the first system message, or prepends if none exists.
|
|
51
51
|
* @param content - The new system message content.
|
|
52
52
|
* @param metadata - Optional metadata (uses original if not provided).
|
|
53
53
|
*/
|
|
54
|
-
replaceSystemMessage: (content: string, metadata?: Record<string,
|
|
54
|
+
replaceSystemMessage: (content: string, metadata?: Record<string, JSONValue>) => ConversationDraft;
|
|
55
55
|
/**
|
|
56
56
|
* Collapses all system messages into the first one, deduplicating content.
|
|
57
57
|
*/
|
|
@@ -68,7 +68,7 @@ export interface ConversationDraft {
|
|
|
68
68
|
* @param role - The role of the streaming message ('assistant' or 'user').
|
|
69
69
|
* @param metadata - Optional metadata to attach to the message.
|
|
70
70
|
*/
|
|
71
|
-
appendStreamingMessage: (role: 'assistant' | 'user', metadata?: Record<string,
|
|
71
|
+
appendStreamingMessage: (role: 'assistant' | 'user', metadata?: Record<string, JSONValue>) => {
|
|
72
72
|
draft: ConversationDraft;
|
|
73
73
|
messageId: string;
|
|
74
74
|
};
|
|
@@ -85,7 +85,7 @@ export interface ConversationDraft {
|
|
|
85
85
|
*/
|
|
86
86
|
finalizeStreamingMessage: (messageId: string, options?: {
|
|
87
87
|
tokenUsage?: TokenUsage;
|
|
88
|
-
metadata?: Record<string,
|
|
88
|
+
metadata?: Record<string, JSONValue>;
|
|
89
89
|
}) => ConversationDraft;
|
|
90
90
|
/**
|
|
91
91
|
* Cancels a streaming message by removing it from the conversation.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-conversation.d.ts","sourceRoot":"","sources":["../src/with-conversation.ts"],"names":[],"mappings":"AAAA,OA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AO,CAAC;QACjC,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,KACE,iBAAiB,CAAC;CACxB;AAoFD;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,YAAY,EAC1B,EAAE,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GACrD,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAWtC;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,YAAY,EAC1B,GAAG,GAAG,EAAE,KAAK,CAAC,CAAC,YAAY,EAAE,YAAY,KAAK,YAAY,CAAC,GAC1D,YAAY,CAEd"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "conversationalist",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "A TypeScript library for managing AI conversation state",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"conversation",
|
|
@@ -25,6 +25,18 @@
|
|
|
25
25
|
"types": "./dist/index.d.ts",
|
|
26
26
|
"import": "./dist/index.js"
|
|
27
27
|
},
|
|
28
|
+
"./markdown": {
|
|
29
|
+
"types": "./dist/markdown/index.d.ts",
|
|
30
|
+
"import": "./dist/markdown/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./export": {
|
|
33
|
+
"types": "./dist/export/index.d.ts",
|
|
34
|
+
"import": "./dist/export/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./schemas": {
|
|
37
|
+
"types": "./dist/schemas/index.d.ts",
|
|
38
|
+
"import": "./dist/schemas/index.js"
|
|
39
|
+
},
|
|
28
40
|
"./openai": {
|
|
29
41
|
"types": "./dist/adapters/openai/index.d.ts",
|
|
30
42
|
"import": "./dist/adapters/openai/index.js"
|
|
@@ -40,6 +52,18 @@
|
|
|
40
52
|
"./plugins": {
|
|
41
53
|
"types": "./dist/plugins/index.d.ts",
|
|
42
54
|
"import": "./dist/plugins/index.js"
|
|
55
|
+
},
|
|
56
|
+
"./redaction": {
|
|
57
|
+
"types": "./dist/redaction/index.d.ts",
|
|
58
|
+
"import": "./dist/redaction/index.js"
|
|
59
|
+
},
|
|
60
|
+
"./versioning": {
|
|
61
|
+
"types": "./dist/versioning/index.d.ts",
|
|
62
|
+
"import": "./dist/versioning/index.js"
|
|
63
|
+
},
|
|
64
|
+
"./sort": {
|
|
65
|
+
"types": "./dist/sort/index.d.ts",
|
|
66
|
+
"import": "./dist/sort/index.js"
|
|
43
67
|
}
|
|
44
68
|
},
|
|
45
69
|
"main": "./dist/index.js",
|
|
@@ -94,6 +118,7 @@
|
|
|
94
118
|
"@types/bun": "^1.3.5",
|
|
95
119
|
"@typescript-eslint/eslint-plugin": "^8.50.0",
|
|
96
120
|
"@typescript-eslint/parser": "^8.50.0",
|
|
121
|
+
"armorer": "^0.1.0",
|
|
97
122
|
"chalk": "^5.6.2",
|
|
98
123
|
"eslint": "^9.39.2",
|
|
99
124
|
"eslint-config-prettier": "^10.1.8",
|