conversationalist 0.0.4 → 0.0.6
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 +37 -21
- package/dist/history.d.ts +7 -1
- package/dist/history.d.ts.map +1 -1
- package/dist/index.js +48 -34
- package/dist/index.js.map +9 -5
- package/dist/utilities/content.d.ts +12 -0
- package/dist/utilities/content.d.ts.map +1 -0
- package/dist/utilities/index.d.ts +8 -0
- package/dist/utilities/index.d.ts.map +1 -0
- package/dist/utilities/markdown.d.ts +76 -0
- package/dist/utilities/markdown.d.ts.map +1 -0
- package/dist/utilities/message.d.ts +32 -0
- package/dist/utilities/message.d.ts.map +1 -0
- package/dist/utilities/tool-calls.d.ts +33 -0
- package/dist/utilities/tool-calls.d.ts.map +1 -0
- package/dist/utilities/type-helpers.d.ts +11 -0
- package/dist/utilities/type-helpers.d.ts.map +1 -0
- package/dist/utilities.d.ts +15 -151
- package/dist/utilities.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -511,14 +511,11 @@ const conversation = pipeConversation(
|
|
|
511
511
|
|
|
512
512
|
Use the `ConversationHistory` class to manage a stack of conversation states. Because every change returns a new immutable object, supporting undo/redo is built into the architecture.
|
|
513
513
|
|
|
514
|
-
|
|
515
|
-
import {
|
|
516
|
-
ConversationHistory,
|
|
517
|
-
createConversation,
|
|
518
|
-
appendUserMessage,
|
|
519
|
-
} from 'conversationalist';
|
|
514
|
+
```ts
|
|
515
|
+
import { ConversationHistory } from 'conversationalist';
|
|
520
516
|
|
|
521
|
-
|
|
517
|
+
// Create a new history (defaults to an empty conversation)
|
|
518
|
+
const history = new ConversationHistory();
|
|
522
519
|
|
|
523
520
|
// You can use convenience methods that automatically track state
|
|
524
521
|
history.appendUserMessage('Hello!');
|
|
@@ -545,7 +542,7 @@ const tokens = history.estimateTokens();
|
|
|
545
542
|
#### Using DOM Events
|
|
546
543
|
|
|
547
544
|
```ts
|
|
548
|
-
const history = new ConversationHistory(
|
|
545
|
+
const history = new ConversationHistory();
|
|
549
546
|
|
|
550
547
|
// addEventListener returns a convenient unsubscribe function
|
|
551
548
|
const unsubscribe = history.addEventListener('change', (event) => {
|
|
@@ -582,12 +579,12 @@ controller.abort();
|
|
|
582
579
|
The `ConversationHistory` class supports branching. When you undo to a previous state and push a new update, it creates an alternate path instead of deleting the old history.
|
|
583
580
|
|
|
584
581
|
```ts
|
|
585
|
-
const history = new ConversationHistory(
|
|
582
|
+
const history = new ConversationHistory();
|
|
586
583
|
|
|
587
|
-
history.
|
|
584
|
+
history.appendUserMessage('Path A');
|
|
588
585
|
history.undo();
|
|
589
586
|
|
|
590
|
-
history.
|
|
587
|
+
history.appendUserMessage('Path B');
|
|
591
588
|
|
|
592
589
|
console.log(history.branchCount); // 2
|
|
593
590
|
console.log(history.current.messages[0].content); // "Path B"
|
|
@@ -614,6 +611,28 @@ const restoredWithEnv = ConversationHistory.from(json, {
|
|
|
614
611
|
});
|
|
615
612
|
```
|
|
616
613
|
|
|
614
|
+
### Markdown Serialization
|
|
615
|
+
|
|
616
|
+
You can also convert a conversation to Markdown format for human-readable storage or export, and restore it later.
|
|
617
|
+
|
|
618
|
+
```ts
|
|
619
|
+
// Export to clean, readable Markdown
|
|
620
|
+
const markdown = history.toMarkdown();
|
|
621
|
+
// ### User
|
|
622
|
+
//
|
|
623
|
+
// Hello!
|
|
624
|
+
//
|
|
625
|
+
// ### Assistant
|
|
626
|
+
//
|
|
627
|
+
// Hi there!
|
|
628
|
+
|
|
629
|
+
// Export with full metadata (lossless round-trip)
|
|
630
|
+
const markdownWithMetadata = history.toMarkdown({ includeMetadata: true });
|
|
631
|
+
|
|
632
|
+
// Restore from Markdown
|
|
633
|
+
const restored = ConversationHistory.fromMarkdown(markdownWithMetadata);
|
|
634
|
+
```
|
|
635
|
+
|
|
617
636
|
## Integration
|
|
618
637
|
|
|
619
638
|
### Using with React
|
|
@@ -649,16 +668,14 @@ For more complex applications, you can wrap the logic into a custom hook. This e
|
|
|
649
668
|
|
|
650
669
|
```tsx
|
|
651
670
|
import { useState, useCallback, useEffect } from 'react';
|
|
652
|
-
import {
|
|
653
|
-
createConversation,
|
|
654
|
-
ConversationHistory,
|
|
655
|
-
toChatMessages,
|
|
656
|
-
} from 'conversationalist';
|
|
671
|
+
import { createConversation, ConversationHistory } from 'conversationalist';
|
|
657
672
|
|
|
658
673
|
export function useChat(initialTitle?: string) {
|
|
659
674
|
// 1. Initialize history (this could also come from context or props)
|
|
660
|
-
const [history] = useState(
|
|
661
|
-
|
|
675
|
+
const [history] = useState(() =>
|
|
676
|
+
initialTitle
|
|
677
|
+
? new ConversationHistory(createConversation({ title: initialTitle }))
|
|
678
|
+
: new ConversationHistory(),
|
|
662
679
|
);
|
|
663
680
|
|
|
664
681
|
// 2. Sync history with local state for reactivity
|
|
@@ -762,10 +779,10 @@ Svelte 5's runes pair perfectly with **Conversationalist**. You can use the `Con
|
|
|
762
779
|
|
|
763
780
|
```svelte
|
|
764
781
|
<script lang="ts">
|
|
765
|
-
import { ConversationHistory
|
|
782
|
+
import { ConversationHistory } from 'conversationalist';
|
|
766
783
|
|
|
767
784
|
// history implements the Svelte store contract
|
|
768
|
-
const history = new ConversationHistory(
|
|
785
|
+
const history = new ConversationHistory();
|
|
769
786
|
</script>
|
|
770
787
|
|
|
771
788
|
<div>
|
|
@@ -813,4 +830,3 @@ bun install
|
|
|
813
830
|
bun test
|
|
814
831
|
bun run build
|
|
815
832
|
```
|
|
816
|
-
````
|
package/dist/history.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type TruncateOptions } from './context';
|
|
2
2
|
import { type ConversationEnvironment } from './environment';
|
|
3
3
|
import type { Conversation, ConversationHistoryJSON, Message, MessageInput, TokenUsage } from './types';
|
|
4
|
+
import { type ToMarkdownOptions } from './utilities';
|
|
4
5
|
/**
|
|
5
6
|
* Event detail for conversation history changes.
|
|
6
7
|
*/
|
|
@@ -20,7 +21,7 @@ export declare class ConversationHistoryEvent extends CustomEvent<ConversationHi
|
|
|
20
21
|
export declare class ConversationHistory extends EventTarget {
|
|
21
22
|
private currentNode;
|
|
22
23
|
private environment;
|
|
23
|
-
constructor(initial
|
|
24
|
+
constructor(initial?: Conversation, environment?: Partial<ConversationEnvironment>);
|
|
24
25
|
/**
|
|
25
26
|
* Dispatches a change event.
|
|
26
27
|
*/
|
|
@@ -113,6 +114,7 @@ export declare class ConversationHistory extends EventTarget {
|
|
|
113
114
|
getSystemMessages(): ReadonlyArray<Message>;
|
|
114
115
|
serialize(): import("./types").ConversationJSON;
|
|
115
116
|
toChatMessages(): import("@lasercat/homogenaize").Message[];
|
|
117
|
+
toMarkdown(options?: ToMarkdownOptions): string;
|
|
116
118
|
estimateTokens(estimator?: (message: Message) => number): number;
|
|
117
119
|
getRecentMessages(count: number, options?: {
|
|
118
120
|
includeHidden?: boolean;
|
|
@@ -146,6 +148,10 @@ export declare class ConversationHistory extends EventTarget {
|
|
|
146
148
|
* Reconstructs a ConversationHistory instance from JSON.
|
|
147
149
|
*/
|
|
148
150
|
static from(json: ConversationHistoryJSON, environment?: Partial<ConversationEnvironment>): ConversationHistory;
|
|
151
|
+
/**
|
|
152
|
+
* Creates a ConversationHistory instance from a Markdown string.
|
|
153
|
+
*/
|
|
154
|
+
static fromMarkdown(markdown: string, environment?: Partial<ConversationEnvironment>): ConversationHistory;
|
|
149
155
|
/**
|
|
150
156
|
* Binds a function to this history instance.
|
|
151
157
|
* The first argument of the function must be a Conversation.
|
package/dist/history.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EAErB,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EAErB,MAAM,WAAW,CAAC;AAuBn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
3588
3588
|
updatedAt: z.string()
|
|
3589
3589
|
};
|
|
3590
3590
|
var conversationSchema = z.object(conversationShape);
|
|
3591
|
-
// src/utilities.ts
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
pairs.push({
|
|
3604
|
-
call: msg.toolCall,
|
|
3605
|
-
result: resultsMap.get(msg.toolCall.id)
|
|
3606
|
-
});
|
|
3607
|
-
}
|
|
3608
|
-
}
|
|
3609
|
-
return pairs;
|
|
3591
|
+
// src/utilities/content.ts
|
|
3592
|
+
function toMultiModalArray(input) {
|
|
3593
|
+
if (typeof input === "string")
|
|
3594
|
+
return [{ type: "text", text: input }];
|
|
3595
|
+
return Array.isArray(input) ? input : [input];
|
|
3596
|
+
}
|
|
3597
|
+
function normalizeContent(content) {
|
|
3598
|
+
if (content === undefined)
|
|
3599
|
+
return;
|
|
3600
|
+
if (typeof content === "string")
|
|
3601
|
+
return content;
|
|
3602
|
+
return Array.isArray(content) ? content : [content];
|
|
3610
3603
|
}
|
|
3604
|
+
// src/utilities/markdown.ts
|
|
3605
|
+
var import_gray_matter = __toESM(require_gray_matter(), 1);
|
|
3606
|
+
|
|
3607
|
+
// src/utilities/type-helpers.ts
|
|
3611
3608
|
function toReadonly(value) {
|
|
3612
3609
|
return value;
|
|
3613
3610
|
}
|
|
3611
|
+
|
|
3612
|
+
// src/utilities/message.ts
|
|
3614
3613
|
function createMessage(props) {
|
|
3615
3614
|
const content = Array.isArray(props.content) ? toReadonly([...props.content]) : props.content;
|
|
3616
3615
|
const message = {
|
|
@@ -3628,18 +3627,6 @@ function createMessage(props) {
|
|
|
3628
3627
|
};
|
|
3629
3628
|
return toReadonly(message);
|
|
3630
3629
|
}
|
|
3631
|
-
function toMultiModalArray(input) {
|
|
3632
|
-
if (typeof input === "string")
|
|
3633
|
-
return [{ type: "text", text: input }];
|
|
3634
|
-
return Array.isArray(input) ? input : [input];
|
|
3635
|
-
}
|
|
3636
|
-
function normalizeContent(content) {
|
|
3637
|
-
if (content === undefined)
|
|
3638
|
-
return;
|
|
3639
|
-
if (typeof content === "string")
|
|
3640
|
-
return content;
|
|
3641
|
-
return Array.isArray(content) ? content : [content];
|
|
3642
|
-
}
|
|
3643
3630
|
function messageParts(message) {
|
|
3644
3631
|
if (typeof message.content === "string") {
|
|
3645
3632
|
return message.content ? [{ type: "text", text: message.content }] : [];
|
|
@@ -3656,6 +3643,8 @@ function messageText(message, joiner = `
|
|
|
3656
3643
|
function messageHasImages(message) {
|
|
3657
3644
|
return messageParts(message).some((p) => p.type === "image");
|
|
3658
3645
|
}
|
|
3646
|
+
|
|
3647
|
+
// src/utilities/markdown.ts
|
|
3659
3648
|
var ROLE_DISPLAY_NAMES = {
|
|
3660
3649
|
user: "User",
|
|
3661
3650
|
assistant: "Assistant",
|
|
@@ -3876,7 +3865,25 @@ function parseMarkdownSimple(body) {
|
|
|
3876
3865
|
};
|
|
3877
3866
|
return toReadonly(conversation);
|
|
3878
3867
|
}
|
|
3879
|
-
|
|
3868
|
+
// src/utilities/tool-calls.ts
|
|
3869
|
+
function pairToolCallsWithResults(messages) {
|
|
3870
|
+
const pairs = [];
|
|
3871
|
+
const resultsMap = new Map;
|
|
3872
|
+
for (const msg of messages) {
|
|
3873
|
+
if (msg.toolResult) {
|
|
3874
|
+
resultsMap.set(msg.toolResult.callId, msg.toolResult);
|
|
3875
|
+
}
|
|
3876
|
+
}
|
|
3877
|
+
for (const msg of messages) {
|
|
3878
|
+
if (msg.toolCall) {
|
|
3879
|
+
pairs.push({
|
|
3880
|
+
call: msg.toolCall,
|
|
3881
|
+
result: resultsMap.get(msg.toolCall.id)
|
|
3882
|
+
});
|
|
3883
|
+
}
|
|
3884
|
+
}
|
|
3885
|
+
return pairs;
|
|
3886
|
+
}
|
|
3880
3887
|
// src/environment.ts
|
|
3881
3888
|
function simpleTokenEstimator(message) {
|
|
3882
3889
|
const text = messageText(message);
|
|
@@ -4651,7 +4658,7 @@ class ConversationHistoryEvent extends CustomEvent {
|
|
|
4651
4658
|
class ConversationHistory extends EventTarget {
|
|
4652
4659
|
currentNode;
|
|
4653
4660
|
environment;
|
|
4654
|
-
constructor(initial, environment) {
|
|
4661
|
+
constructor(initial = createConversation(), environment) {
|
|
4655
4662
|
super();
|
|
4656
4663
|
this.environment = resolveConversationEnvironment(environment);
|
|
4657
4664
|
this.currentNode = {
|
|
@@ -4788,6 +4795,9 @@ class ConversationHistory extends EventTarget {
|
|
|
4788
4795
|
toChatMessages() {
|
|
4789
4796
|
return toChatMessages(this.current);
|
|
4790
4797
|
}
|
|
4798
|
+
toMarkdown(options2) {
|
|
4799
|
+
return toMarkdown(this.current, options2);
|
|
4800
|
+
}
|
|
4791
4801
|
estimateTokens(estimator) {
|
|
4792
4802
|
return estimateConversationTokens(this.current, estimator, this.env);
|
|
4793
4803
|
}
|
|
@@ -4890,6 +4900,10 @@ class ConversationHistory extends EventTarget {
|
|
|
4890
4900
|
h.currentNode = current;
|
|
4891
4901
|
return history;
|
|
4892
4902
|
}
|
|
4903
|
+
static fromMarkdown(markdown, environment) {
|
|
4904
|
+
const conversation = fromMarkdown(markdown);
|
|
4905
|
+
return new ConversationHistory(conversation, environment);
|
|
4906
|
+
}
|
|
4893
4907
|
bind(fn) {
|
|
4894
4908
|
return bindToConversationHistory(this, fn);
|
|
4895
4909
|
}
|
|
@@ -4990,4 +5004,4 @@ export {
|
|
|
4990
5004
|
ConversationHistory
|
|
4991
5005
|
};
|
|
4992
5006
|
|
|
4993
|
-
//# debugId=
|
|
5007
|
+
//# debugId=5ABC5C6EA1F008F764756E2164756E21
|