conversationalist 0.0.9 → 0.0.11
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 +148 -30
- package/dist/adapters/anthropic/index.d.ts.map +1 -1
- package/dist/adapters/anthropic/index.js +255 -2
- package/dist/adapters/anthropic/index.js.map +8 -4
- package/dist/adapters/gemini/index.d.ts.map +1 -1
- package/dist/adapters/gemini/index.js +255 -3
- package/dist/adapters/gemini/index.js.map +8 -4
- package/dist/adapters/openai/index.d.ts.map +1 -1
- package/dist/adapters/openai/index.js +247 -3
- package/dist/adapters/openai/index.js.map +8 -4
- package/dist/context.d.ts +6 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/conversation/append.d.ts +5 -0
- package/dist/conversation/append.d.ts.map +1 -1
- package/dist/conversation/create.d.ts +9 -0
- package/dist/conversation/create.d.ts.map +1 -1
- package/dist/conversation/index.d.ts +8 -3
- package/dist/conversation/index.d.ts.map +1 -1
- package/dist/conversation/integrity.d.ts +16 -0
- package/dist/conversation/integrity.d.ts.map +1 -0
- package/dist/conversation/modify.d.ts +8 -2
- package/dist/conversation/modify.d.ts.map +1 -1
- package/dist/conversation/serialization.d.ts +0 -17
- package/dist/conversation/serialization.d.ts.map +1 -1
- package/dist/conversation/system-messages.d.ts.map +1 -1
- package/dist/conversation/tool-interactions.d.ts +45 -0
- package/dist/conversation/tool-interactions.d.ts.map +1 -0
- package/dist/conversation/transform.d.ts.map +1 -1
- package/dist/conversation/validation.d.ts +8 -0
- package/dist/conversation/validation.d.ts.map +1 -0
- package/dist/errors.d.ts +6 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/export/index.js +249 -12
- package/dist/export/index.js.map +10 -6
- package/dist/guards.d.ts +13 -0
- package/dist/guards.d.ts.map +1 -0
- package/dist/history.d.ts +21 -8
- package/dist/history.d.ts.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2212 -259
- package/dist/index.js.map +26 -13
- package/dist/markdown/index.js +2169 -253
- package/dist/markdown/index.js.map +23 -12
- package/dist/schemas/index.d.ts +1 -1
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +38 -22
- package/dist/schemas/index.js.map +3 -3
- package/dist/schemas.d.ts +17 -37
- package/dist/schemas.d.ts.map +1 -1
- package/dist/streaming.d.ts.map +1 -1
- package/dist/types.d.ts +0 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/utilities/index.d.ts +0 -1
- package/dist/utilities/index.d.ts.map +1 -1
- package/dist/utilities/markdown.d.ts.map +1 -1
- package/dist/utilities/tool-calls.d.ts +2 -6
- package/dist/utilities/tool-calls.d.ts.map +1 -1
- package/dist/utilities/tool-results.d.ts.map +1 -1
- package/dist/utilities/transient.d.ts.map +1 -1
- package/dist/utilities.d.ts +0 -1
- package/dist/utilities.d.ts.map +1 -1
- package/dist/versioning/index.d.ts +0 -1
- package/dist/versioning/index.d.ts.map +1 -1
- package/dist/versioning/index.js +1 -52
- package/dist/versioning/index.js.map +4 -5
- package/dist/with-conversation.d.ts +4 -1
- package/dist/with-conversation.d.ts.map +1 -1
- package/package.json +7 -4
- package/dist/conversation.d.ts +0 -109
- package/dist/conversation.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/conversation/transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,IAAI,eAAe,EAE3B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/conversation/transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,IAAI,eAAe,EAE3B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAI7C;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,YAAY,EAAE,YAAY,GAAG,eAAe,EAAE,CAsB5E"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Conversation } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Ensures a conversation conforms to the schema (JSON-safe) and integrity rules.
|
|
4
|
+
* Internal helper for public API enforcement points.
|
|
5
|
+
*/
|
|
6
|
+
export declare function assertConversationSafe(conversation: Conversation): void;
|
|
7
|
+
export declare function ensureConversationSafe(conversation: Conversation): Conversation;
|
|
8
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/conversation/validation.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG7C;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI,CASvE;AAED,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,YAAY,GAAG,YAAY,CAG/E"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Error codes for Conversationalist errors (kebab-case with `error:` prefix).
|
|
3
3
|
*/
|
|
4
|
-
export type ConversationalistErrorCode = 'error:locked' | 'error:invalid-input' | 'error:invalid-position' | 'error:invalid-tool-reference' | 'error:duplicate-id' | 'error:not-found' | 'error:serialization' | 'error:validation';
|
|
4
|
+
export type ConversationalistErrorCode = 'error:locked' | 'error:invalid-input' | 'error:invalid-position' | 'error:invalid-tool-reference' | 'error:duplicate-id' | 'error:not-found' | 'error:serialization' | 'error:validation' | 'error:integrity';
|
|
5
5
|
/**
|
|
6
6
|
* Base error class for all Conversationalist errors.
|
|
7
7
|
*
|
|
@@ -64,4 +64,9 @@ export declare function createSerializationError(message: string, cause?: Error)
|
|
|
64
64
|
* Thrown when data validation fails (e.g., Zod schema validation).
|
|
65
65
|
*/
|
|
66
66
|
export declare function createValidationError(message: string, context?: Record<string, unknown>, cause?: Error): ConversationalistError;
|
|
67
|
+
/**
|
|
68
|
+
* Creates an integrity error (ERR_INTEGRITY).
|
|
69
|
+
* Thrown when conversation invariants are violated.
|
|
70
|
+
*/
|
|
71
|
+
export declare function createIntegrityError(message: string, context?: Record<string, unknown>): ConversationalistError;
|
|
67
72
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAClC,cAAc,GACd,qBAAqB,GACrB,wBAAwB,GACxB,8BAA8B,GAC9B,oBAAoB,GACpB,iBAAiB,GACjB,qBAAqB,GACrB,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAClC,cAAc,GACd,qBAAqB,GACrB,wBAAwB,GACxB,8BAA8B,GAC9B,oBAAoB,GACpB,iBAAiB,GACjB,qBAAqB,GACrB,kBAAkB,GAClB,iBAAiB,CAAC;AAEtB;;;;;GAKG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,4BAA4B;IAC5B,QAAQ,CAAC,IAAI,EAAE,0BAA0B,CAAC;IAE1C,8BAA8B;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAEvD,gCAAgC;IAChC,SAAkB,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;gBAG1C,IAAI,EAAE,0BAA0B,EAChC,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;QAC9C,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;KAC3B;IAcH;;OAEG;IACH,gBAAgB,IAAI,MAAM;CAa3B;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,cAAc,EAAE,MAAM,GAAG,sBAAsB,CAMhF;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,sBAAsB,CAExB;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,sBAAsB,CAMxB;AAED;;;GAGG;AACH,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,MAAM,GAAG,sBAAsB,CAMtF;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,MAAM,GAAG,sBAAsB,CAMzE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,MAAM,GAAG,sBAAsB,CAQtE;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,KAAK,GACZ,sBAAsB,CAExB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,KAAK,CAAC,EAAE,KAAK,GACZ,sBAAsB,CAExB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,sBAAsB,CAExB"}
|
package/dist/export/index.js
CHANGED
|
@@ -3501,6 +3501,250 @@ function normalizeLineEndings(text) {
|
|
|
3501
3501
|
// src/utilities/markdown.ts
|
|
3502
3502
|
var import_gray_matter = __toESM(require_gray_matter(), 1);
|
|
3503
3503
|
|
|
3504
|
+
// src/errors.ts
|
|
3505
|
+
class ConversationalistError extends Error {
|
|
3506
|
+
code;
|
|
3507
|
+
context;
|
|
3508
|
+
cause;
|
|
3509
|
+
constructor(code, message, options2) {
|
|
3510
|
+
super(message);
|
|
3511
|
+
this.name = "ConversationalistError";
|
|
3512
|
+
this.code = code;
|
|
3513
|
+
this.context = options2?.context;
|
|
3514
|
+
this.cause = options2?.cause;
|
|
3515
|
+
if (Error.captureStackTrace) {
|
|
3516
|
+
Error.captureStackTrace(this, ConversationalistError);
|
|
3517
|
+
}
|
|
3518
|
+
}
|
|
3519
|
+
toDetailedString() {
|
|
3520
|
+
const parts = [`[${this.code}] ${this.message}`];
|
|
3521
|
+
if (this.context && Object.keys(this.context).length > 0) {
|
|
3522
|
+
parts.push(`Context: ${JSON.stringify(this.context, null, 2)}`);
|
|
3523
|
+
}
|
|
3524
|
+
if (this.cause) {
|
|
3525
|
+
parts.push(`Caused by: ${this.cause.message}`);
|
|
3526
|
+
}
|
|
3527
|
+
return parts.join(`
|
|
3528
|
+
`);
|
|
3529
|
+
}
|
|
3530
|
+
}
|
|
3531
|
+
function createValidationError(message, context, cause) {
|
|
3532
|
+
return new ConversationalistError("error:validation", message, { context, cause });
|
|
3533
|
+
}
|
|
3534
|
+
function createIntegrityError(message, context) {
|
|
3535
|
+
return new ConversationalistError("error:integrity", message, { context });
|
|
3536
|
+
}
|
|
3537
|
+
|
|
3538
|
+
// src/schemas.ts
|
|
3539
|
+
import { z } from "zod";
|
|
3540
|
+
var isPlainObject = (value) => {
|
|
3541
|
+
if (!value || typeof value !== "object")
|
|
3542
|
+
return false;
|
|
3543
|
+
const prototype = Reflect.getPrototypeOf(value);
|
|
3544
|
+
return prototype === Object.prototype || prototype === null;
|
|
3545
|
+
};
|
|
3546
|
+
function toMultiModalContent(value) {
|
|
3547
|
+
const result = { type: value.type };
|
|
3548
|
+
if (value.text !== undefined)
|
|
3549
|
+
result.text = value.text;
|
|
3550
|
+
if (value.url !== undefined)
|
|
3551
|
+
result.url = value.url;
|
|
3552
|
+
if (value.mimeType !== undefined)
|
|
3553
|
+
result.mimeType = value.mimeType;
|
|
3554
|
+
return result;
|
|
3555
|
+
}
|
|
3556
|
+
var jsonValueSchema = z.lazy(() => {
|
|
3557
|
+
const jsonObjectSchema = z.preprocess((value, ctx) => {
|
|
3558
|
+
if (!isPlainObject(value)) {
|
|
3559
|
+
ctx.addIssue({
|
|
3560
|
+
code: z.ZodIssueCode.custom,
|
|
3561
|
+
message: "expected a plain object"
|
|
3562
|
+
});
|
|
3563
|
+
return z.NEVER;
|
|
3564
|
+
}
|
|
3565
|
+
return value;
|
|
3566
|
+
}, z.record(z.string(), jsonValueSchema));
|
|
3567
|
+
return z.union([
|
|
3568
|
+
z.string(),
|
|
3569
|
+
z.number().refine((value) => Number.isFinite(value), {
|
|
3570
|
+
message: "expected a finite number"
|
|
3571
|
+
}),
|
|
3572
|
+
z.boolean(),
|
|
3573
|
+
z.null(),
|
|
3574
|
+
z.array(jsonValueSchema),
|
|
3575
|
+
jsonObjectSchema
|
|
3576
|
+
]);
|
|
3577
|
+
});
|
|
3578
|
+
var multiModalContentSchema = z.discriminatedUnion("type", [
|
|
3579
|
+
z.object({
|
|
3580
|
+
type: z.literal("text"),
|
|
3581
|
+
text: z.string()
|
|
3582
|
+
}),
|
|
3583
|
+
z.object({
|
|
3584
|
+
type: z.literal("image"),
|
|
3585
|
+
url: z.string().url(),
|
|
3586
|
+
mimeType: z.string().optional(),
|
|
3587
|
+
text: z.string().optional()
|
|
3588
|
+
})
|
|
3589
|
+
]).transform(toMultiModalContent);
|
|
3590
|
+
var messageRoleSchema = z.enum([
|
|
3591
|
+
"user",
|
|
3592
|
+
"assistant",
|
|
3593
|
+
"system",
|
|
3594
|
+
"developer",
|
|
3595
|
+
"tool-use",
|
|
3596
|
+
"tool-result",
|
|
3597
|
+
"snapshot"
|
|
3598
|
+
]);
|
|
3599
|
+
var toolCallSchema = z.object({
|
|
3600
|
+
id: z.string(),
|
|
3601
|
+
name: z.string(),
|
|
3602
|
+
arguments: jsonValueSchema
|
|
3603
|
+
}).strict();
|
|
3604
|
+
var toolResultSchema = z.object({
|
|
3605
|
+
callId: z.string(),
|
|
3606
|
+
outcome: z.enum(["success", "error"]),
|
|
3607
|
+
content: jsonValueSchema
|
|
3608
|
+
}).strict();
|
|
3609
|
+
var tokenUsageSchema = z.object({
|
|
3610
|
+
prompt: z.number().int().min(0),
|
|
3611
|
+
completion: z.number().int().min(0),
|
|
3612
|
+
total: z.number().int().min(0)
|
|
3613
|
+
});
|
|
3614
|
+
var messageInputSchema = z.object({
|
|
3615
|
+
role: messageRoleSchema,
|
|
3616
|
+
content: z.union([z.string(), z.array(multiModalContentSchema)]),
|
|
3617
|
+
metadata: z.record(z.string(), jsonValueSchema).optional(),
|
|
3618
|
+
hidden: z.boolean().optional(),
|
|
3619
|
+
toolCall: toolCallSchema.optional(),
|
|
3620
|
+
toolResult: toolResultSchema.optional(),
|
|
3621
|
+
tokenUsage: tokenUsageSchema.optional(),
|
|
3622
|
+
goalCompleted: z.boolean().optional()
|
|
3623
|
+
}).strict();
|
|
3624
|
+
var messageSchema = z.object({
|
|
3625
|
+
id: z.string(),
|
|
3626
|
+
role: messageRoleSchema,
|
|
3627
|
+
content: z.union([z.string(), z.array(multiModalContentSchema)]),
|
|
3628
|
+
position: z.number().int().min(0),
|
|
3629
|
+
createdAt: z.string(),
|
|
3630
|
+
metadata: z.record(z.string(), jsonValueSchema),
|
|
3631
|
+
hidden: z.boolean(),
|
|
3632
|
+
toolCall: toolCallSchema.optional(),
|
|
3633
|
+
toolResult: toolResultSchema.optional(),
|
|
3634
|
+
tokenUsage: tokenUsageSchema.optional(),
|
|
3635
|
+
goalCompleted: z.boolean().optional()
|
|
3636
|
+
}).strict();
|
|
3637
|
+
var conversationStatusSchema = z.enum([
|
|
3638
|
+
"active",
|
|
3639
|
+
"archived",
|
|
3640
|
+
"deleted"
|
|
3641
|
+
]);
|
|
3642
|
+
var conversationShape = {
|
|
3643
|
+
schemaVersion: z.number().int().min(1),
|
|
3644
|
+
id: z.string(),
|
|
3645
|
+
title: z.string().optional(),
|
|
3646
|
+
status: conversationStatusSchema,
|
|
3647
|
+
metadata: z.record(z.string(), jsonValueSchema),
|
|
3648
|
+
ids: z.array(z.string()),
|
|
3649
|
+
messages: z.record(z.string(), messageSchema),
|
|
3650
|
+
createdAt: z.string(),
|
|
3651
|
+
updatedAt: z.string()
|
|
3652
|
+
};
|
|
3653
|
+
var conversationSchema = z.object(conversationShape).strict();
|
|
3654
|
+
|
|
3655
|
+
// src/conversation/integrity.ts
|
|
3656
|
+
function validateConversationIntegrity(conversation) {
|
|
3657
|
+
const issues = [];
|
|
3658
|
+
const seenIds = new Set;
|
|
3659
|
+
conversation.ids.forEach((id, index) => {
|
|
3660
|
+
if (seenIds.has(id)) {
|
|
3661
|
+
issues.push({
|
|
3662
|
+
code: "integrity:duplicate-message-id",
|
|
3663
|
+
message: `duplicate message id in ids: ${id}`,
|
|
3664
|
+
data: { id, position: index }
|
|
3665
|
+
});
|
|
3666
|
+
} else {
|
|
3667
|
+
seenIds.add(id);
|
|
3668
|
+
}
|
|
3669
|
+
if (!conversation.messages[id]) {
|
|
3670
|
+
issues.push({
|
|
3671
|
+
code: "integrity:missing-message",
|
|
3672
|
+
message: `missing message for id ${id}`,
|
|
3673
|
+
data: { id, position: index }
|
|
3674
|
+
});
|
|
3675
|
+
}
|
|
3676
|
+
});
|
|
3677
|
+
for (const id of Object.keys(conversation.messages)) {
|
|
3678
|
+
if (!seenIds.has(id)) {
|
|
3679
|
+
issues.push({
|
|
3680
|
+
code: "integrity:unlisted-message",
|
|
3681
|
+
message: `message ${id} is not listed in ids`,
|
|
3682
|
+
data: { id }
|
|
3683
|
+
});
|
|
3684
|
+
}
|
|
3685
|
+
}
|
|
3686
|
+
const toolUses = new Map;
|
|
3687
|
+
conversation.ids.forEach((id, index) => {
|
|
3688
|
+
const message = conversation.messages[id];
|
|
3689
|
+
if (!message)
|
|
3690
|
+
return;
|
|
3691
|
+
if (message.role === "tool-use" && message.toolCall) {
|
|
3692
|
+
if (toolUses.has(message.toolCall.id)) {
|
|
3693
|
+
issues.push({
|
|
3694
|
+
code: "integrity:duplicate-tool-call",
|
|
3695
|
+
message: `duplicate toolCall.id ${message.toolCall.id}`,
|
|
3696
|
+
data: { toolCallId: message.toolCall.id, messageId: message.id }
|
|
3697
|
+
});
|
|
3698
|
+
} else {
|
|
3699
|
+
toolUses.set(message.toolCall.id, { position: index, messageId: message.id });
|
|
3700
|
+
}
|
|
3701
|
+
}
|
|
3702
|
+
});
|
|
3703
|
+
conversation.ids.forEach((id, index) => {
|
|
3704
|
+
const message = conversation.messages[id];
|
|
3705
|
+
if (!message)
|
|
3706
|
+
return;
|
|
3707
|
+
if (message.role === "tool-result" && message.toolResult) {
|
|
3708
|
+
const toolUse = toolUses.get(message.toolResult.callId);
|
|
3709
|
+
if (!toolUse) {
|
|
3710
|
+
issues.push({
|
|
3711
|
+
code: "integrity:orphan-tool-result",
|
|
3712
|
+
message: `tool-result references missing tool-use ${message.toolResult.callId}`,
|
|
3713
|
+
data: { callId: message.toolResult.callId, messageId: message.id }
|
|
3714
|
+
});
|
|
3715
|
+
} else if (toolUse.position >= index) {
|
|
3716
|
+
issues.push({
|
|
3717
|
+
code: "integrity:tool-result-before-call",
|
|
3718
|
+
message: `tool-result ${message.toolResult.callId} occurs before tool-use`,
|
|
3719
|
+
data: {
|
|
3720
|
+
callId: message.toolResult.callId,
|
|
3721
|
+
messageId: message.id,
|
|
3722
|
+
toolUseMessageId: toolUse.messageId
|
|
3723
|
+
}
|
|
3724
|
+
});
|
|
3725
|
+
}
|
|
3726
|
+
}
|
|
3727
|
+
});
|
|
3728
|
+
return issues;
|
|
3729
|
+
}
|
|
3730
|
+
function assertConversationIntegrity(conversation) {
|
|
3731
|
+
const issues = validateConversationIntegrity(conversation);
|
|
3732
|
+
if (issues.length === 0)
|
|
3733
|
+
return;
|
|
3734
|
+
throw createIntegrityError("conversation integrity check failed", { issues });
|
|
3735
|
+
}
|
|
3736
|
+
|
|
3737
|
+
// src/conversation/validation.ts
|
|
3738
|
+
function assertConversationSafe(conversation) {
|
|
3739
|
+
const parsed = conversationSchema.safeParse(conversation);
|
|
3740
|
+
if (!parsed.success) {
|
|
3741
|
+
throw createValidationError("conversation failed schema validation", {
|
|
3742
|
+
issues: parsed.error.issues
|
|
3743
|
+
});
|
|
3744
|
+
}
|
|
3745
|
+
assertConversationIntegrity(conversation);
|
|
3746
|
+
}
|
|
3747
|
+
|
|
3504
3748
|
// src/multi-modal.ts
|
|
3505
3749
|
function copyMultiModalContent(item) {
|
|
3506
3750
|
if (item.type === "text") {
|
|
@@ -3565,14 +3809,7 @@ function copyToolResult(toolResult) {
|
|
|
3565
3809
|
return { ...toolResult };
|
|
3566
3810
|
}
|
|
3567
3811
|
function redactToolResult(toolResult, placeholder) {
|
|
3568
|
-
|
|
3569
|
-
if (result.result !== undefined) {
|
|
3570
|
-
result.result = placeholder;
|
|
3571
|
-
}
|
|
3572
|
-
if (result.error !== undefined) {
|
|
3573
|
-
result.error = placeholder;
|
|
3574
|
-
}
|
|
3575
|
-
return result;
|
|
3812
|
+
return { ...toolResult, content: placeholder };
|
|
3576
3813
|
}
|
|
3577
3814
|
|
|
3578
3815
|
// src/utilities/transient.ts
|
|
@@ -3599,7 +3836,6 @@ var ROLE_LABELS = {
|
|
|
3599
3836
|
"tool-result": "Tool Result",
|
|
3600
3837
|
snapshot: "Snapshot"
|
|
3601
3838
|
};
|
|
3602
|
-
var ROLE_DISPLAY_NAMES = ROLE_LABELS;
|
|
3603
3839
|
var DEFAULT_REDACTED_PLACEHOLDER = "[REDACTED]";
|
|
3604
3840
|
function resolveMarkdownOptions(options2 = {}) {
|
|
3605
3841
|
return {
|
|
@@ -3676,6 +3912,7 @@ function formatMessageContent(message) {
|
|
|
3676
3912
|
`);
|
|
3677
3913
|
}
|
|
3678
3914
|
function toMarkdown(conversation, options2 = {}) {
|
|
3915
|
+
assertConversationSafe(conversation);
|
|
3679
3916
|
const resolved = resolveMarkdownOptions(options2);
|
|
3680
3917
|
const prepared = prepareConversationForMarkdown(conversation, resolved);
|
|
3681
3918
|
if (resolved.includeMetadata) {
|
|
@@ -3686,7 +3923,7 @@ function toMarkdown(conversation, options2 = {}) {
|
|
|
3686
3923
|
function toMarkdownSimple(conversation) {
|
|
3687
3924
|
const sections = [];
|
|
3688
3925
|
for (const message of getOrderedMessages(conversation)) {
|
|
3689
|
-
const roleName =
|
|
3926
|
+
const roleName = ROLE_LABELS[message.role];
|
|
3690
3927
|
const header = `### ${roleName}`;
|
|
3691
3928
|
const content = formatMessageContent(message);
|
|
3692
3929
|
sections.push(`${header}
|
|
@@ -3737,7 +3974,7 @@ function toMarkdownWithMetadata(conversation, _options) {
|
|
|
3737
3974
|
}
|
|
3738
3975
|
const messageSections = [];
|
|
3739
3976
|
for (const message of getOrderedMessages(conversation)) {
|
|
3740
|
-
const roleName =
|
|
3977
|
+
const roleName = ROLE_LABELS[message.role];
|
|
3741
3978
|
const header = `### ${roleName} (${message.id})`;
|
|
3742
3979
|
const content = formatMessageContent(message);
|
|
3743
3980
|
messageSections.push(`${header}
|
|
@@ -3759,4 +3996,4 @@ export {
|
|
|
3759
3996
|
exportMarkdown
|
|
3760
3997
|
};
|
|
3761
3998
|
|
|
3762
|
-
//# debugId=
|
|
3999
|
+
//# debugId=23462BBCDD76F94964756E2164756E21
|