@cossistant/core 0.0.32 → 0.0.33
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/ai-sdk-utils.d.ts +33 -3
- package/ai-sdk-utils.d.ts.map +1 -1
- package/ai-sdk-utils.js +85 -21
- package/ai-sdk-utils.js.map +1 -1
- package/index.d.ts +2 -2
- package/index.js +2 -2
- package/package.json +1 -1
- package/privacy-filter.d.ts.map +1 -1
- package/privacy-filter.js +7 -2
- package/privacy-filter.js.map +1 -1
- package/store/timeline-items-store.d.ts.map +1 -1
- package/types/src/api/conversation.d.ts +383 -8
- package/types/src/api/conversation.d.ts.map +1 -1
- package/types/src/api/timeline-item.d.ts +304 -4
- package/types/src/api/timeline-item.d.ts.map +1 -1
- package/types/src/api/timeline-item.js +14 -1
- package/types/src/api/timeline-item.js.map +1 -1
- package/types/src/realtime-events.d.ts +233 -8
- package/types/src/realtime-events.d.ts.map +1 -1
- package/types/src/schemas.d.ts +77 -2
- package/types/src/schemas.d.ts.map +1 -1
- package/types/src/tool-timeline-policy.js +16 -0
- package/types/src/tool-timeline-policy.js.map +1 -0
- package/utils.d.ts.map +1 -1
package/ai-sdk-utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TimelineItem, TimelineItemParts } from "@cossistant/types";
|
|
1
|
+
import { TimelineItem, TimelineItemParts, ToolTimelineLogType } from "@cossistant/types";
|
|
2
2
|
|
|
3
3
|
//#region src/ai-sdk-utils.d.ts
|
|
4
4
|
|
|
@@ -24,6 +24,7 @@ type AISDKToolPart = {
|
|
|
24
24
|
output?: unknown;
|
|
25
25
|
state: "partial" | "result" | "error";
|
|
26
26
|
errorText?: string;
|
|
27
|
+
callProviderMetadata?: Record<string, unknown>;
|
|
27
28
|
providerMetadata?: Record<string, unknown>;
|
|
28
29
|
};
|
|
29
30
|
type AISDKSourceUrlPart = {
|
|
@@ -66,15 +67,44 @@ type CossistantMessageMetadata = {
|
|
|
66
67
|
tool?: string | null;
|
|
67
68
|
};
|
|
68
69
|
/**
|
|
69
|
-
* Cossistant-specific metadata stored in part.providerMetadata.cossistant
|
|
70
|
+
* Cossistant-specific metadata stored in part.callProviderMetadata/providerMetadata.cossistant
|
|
70
71
|
*/
|
|
72
|
+
type CossistantToolTimelineMetadata = {
|
|
73
|
+
logType: ToolTimelineLogType;
|
|
74
|
+
triggerMessageId: string;
|
|
75
|
+
workflowRunId: string;
|
|
76
|
+
triggerVisibility?: "public" | "private";
|
|
77
|
+
};
|
|
71
78
|
type CossistantPartMetadata = {
|
|
72
79
|
visibility?: "public" | "private";
|
|
73
80
|
progressMessage?: string;
|
|
74
81
|
knowledgeId?: string;
|
|
82
|
+
toolTimeline?: CossistantToolTimelineMetadata;
|
|
83
|
+
};
|
|
84
|
+
type AISDKPartMetadataCarrier = {
|
|
85
|
+
providerMetadata?: Record<string, unknown>;
|
|
86
|
+
callProviderMetadata?: Record<string, unknown>;
|
|
75
87
|
};
|
|
76
88
|
type AISDKPart = AISDKTextPart | AISDKReasoningPart | AISDKToolPart | AISDKSourceUrlPart | AISDKSourceDocumentPart | AISDKStepStartPart | AISDKFilePart;
|
|
77
89
|
type CossistantPart = TimelineItemParts[number];
|
|
90
|
+
/**
|
|
91
|
+
* Read cossistant part metadata from AI SDK v6-compatible part metadata.
|
|
92
|
+
* Prefers callProviderMetadata but accepts providerMetadata for backward compatibility.
|
|
93
|
+
*/
|
|
94
|
+
declare function getCossistantPartMetadata(part: AISDKPartMetadataCarrier): CossistantPartMetadata | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Write cossistant part metadata into both callProviderMetadata and providerMetadata.
|
|
97
|
+
* This keeps AI SDK v6 semantics while remaining backward compatible.
|
|
98
|
+
*/
|
|
99
|
+
declare function setCossistantPartMetadata(part: AISDKPartMetadataCarrier, metadata: CossistantPartMetadata): AISDKPartMetadataCarrier;
|
|
100
|
+
/**
|
|
101
|
+
* Read tool timeline metadata from cossistant part metadata.
|
|
102
|
+
*/
|
|
103
|
+
declare function getCossistantToolTimelineMetadata(part: AISDKPartMetadataCarrier): CossistantToolTimelineMetadata | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* Write tool timeline metadata into cossistant part metadata.
|
|
106
|
+
*/
|
|
107
|
+
declare function setCossistantToolTimelineMetadata(part: AISDKPartMetadataCarrier, toolTimeline: CossistantToolTimelineMetadata): AISDKPartMetadataCarrier;
|
|
78
108
|
/**
|
|
79
109
|
* Cossistant-compatible UIMessage type
|
|
80
110
|
* This is structurally compatible with AI SDK v6 UIMessage
|
|
@@ -137,5 +167,5 @@ declare function extractToolCalls(parts: AISDKPart[]): AISDKToolPart[];
|
|
|
137
167
|
*/
|
|
138
168
|
declare function hasProcessingParts(parts: AISDKPart[]): boolean;
|
|
139
169
|
//#endregion
|
|
140
|
-
export { AISDKFilePart, AISDKPart, AISDKReasoningPart, AISDKSourceDocumentPart, AISDKSourceUrlPart, AISDKStepStartPart, AISDKTextPart, AISDKToolPart, CossistantMessageMetadata, CossistantPartMetadata, CossistantUIMessage, FromUIMessageContext, extractSources, extractToolCalls, fromUIMessage, fromUIMessages, hasProcessingParts, isAISDKCompatiblePart, toUIMessage, toUIMessages };
|
|
170
|
+
export { AISDKFilePart, AISDKPart, AISDKReasoningPart, AISDKSourceDocumentPart, AISDKSourceUrlPart, AISDKStepStartPart, AISDKTextPart, AISDKToolPart, CossistantMessageMetadata, CossistantPartMetadata, CossistantToolTimelineMetadata, CossistantUIMessage, FromUIMessageContext, extractSources, extractToolCalls, fromUIMessage, fromUIMessages, getCossistantPartMetadata, getCossistantToolTimelineMetadata, hasProcessingParts, isAISDKCompatiblePart, setCossistantPartMetadata, setCossistantToolTimelineMetadata, toUIMessage, toUIMessages };
|
|
141
171
|
//# sourceMappingURL=ai-sdk-utils.d.ts.map
|
package/ai-sdk-utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-sdk-utils.d.ts","names":[],"sources":["../src/ai-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A;EACD,gBAAA,CAAA,EApcU,MAocV,CAAA,MAAA,EAAA,OAAA,CAAA;CACP;AAAY,KAlcH,kBAAA,GAkcG;EA0HC,IAAA,EAAA,YAAA;AAUhB,CAAA;AACQ,KAnkBI,aAAA,GAmkBJ;EACJ,IAAA,EAAA,MAAA;EAAqB,GAAA,EAAA,MAAA;EAAuB,SAAA,EAAA,MAAA;EAUhC,QAAA,CAAA,EAAA,MAAA;AAUhB,CAAA;;;;KA1kBY,yBAAA;;;;;;;;;;;;;;;KAgBA,8BAAA;WACF;;;;;KAME,sBAAA;;;;iBAII;;KAGX,wBAAA;qBACe;yBACI;;KAOZ,SAAA,GACT,gBACA,qBACA,gBACA,qBACA,0BACA,qBACA;KAEE,cAAA,GAAiB;;;;;iBAuBN,yBAAA,OACT,2BACJ;;;;;iBAoBa,yBAAA,OACT,oCACI,yBACR;;;;iBAoBa,iCAAA,OACT,2BACJ;;;;iBAOa,iCAAA,OACT,wCACQ,iCACZ;;;;;;KAiGS,mBAAA;;;YAGD;SACH;;;;;;;;iBASQ,WAAA,OAAkB,eAAe;;;;iBAsBjC,YAAA,QAAoB,iBAAiB;;;;KA4HzC,oBAAA;;;;;;;;;;;;;;;iBAgBI,aAAA,UACN,8BACA,uBACP;;;;iBA0Ba,cAAA,WACL,gCACD,uBACP;;;;iBA0Ha,qBAAA,OAA4B;;;;iBAU5B,cAAA,QACR,eACJ,qBAAqB;;;;iBAUT,gBAAA,QAAwB,cAAc;;;;iBAUtC,kBAAA,QAA0B"}
|
package/ai-sdk-utils.js
CHANGED
|
@@ -1,4 +1,57 @@
|
|
|
1
1
|
//#region src/ai-sdk-utils.ts
|
|
2
|
+
function isRecord(value) {
|
|
3
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4
|
+
}
|
|
5
|
+
function getMetadataCarrier(part) {
|
|
6
|
+
return {
|
|
7
|
+
callProviderMetadata: part.callProviderMetadata ?? part.providerMetadata,
|
|
8
|
+
providerMetadata: part.providerMetadata ?? part.callProviderMetadata
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Read cossistant part metadata from AI SDK v6-compatible part metadata.
|
|
13
|
+
* Prefers callProviderMetadata but accepts providerMetadata for backward compatibility.
|
|
14
|
+
*/
|
|
15
|
+
function getCossistantPartMetadata(part) {
|
|
16
|
+
const { callProviderMetadata, providerMetadata } = getMetadataCarrier(part);
|
|
17
|
+
const metadata = callProviderMetadata ?? providerMetadata;
|
|
18
|
+
if (!isRecord(metadata)) return;
|
|
19
|
+
const cossistant = metadata.cossistant;
|
|
20
|
+
if (!isRecord(cossistant)) return;
|
|
21
|
+
return cossistant;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Write cossistant part metadata into both callProviderMetadata and providerMetadata.
|
|
25
|
+
* This keeps AI SDK v6 semantics while remaining backward compatible.
|
|
26
|
+
*/
|
|
27
|
+
function setCossistantPartMetadata(part, metadata) {
|
|
28
|
+
const { callProviderMetadata, providerMetadata } = getMetadataCarrier(part);
|
|
29
|
+
return {
|
|
30
|
+
callProviderMetadata: {
|
|
31
|
+
...isRecord(callProviderMetadata) ? callProviderMetadata : {},
|
|
32
|
+
cossistant: metadata
|
|
33
|
+
},
|
|
34
|
+
providerMetadata: {
|
|
35
|
+
...isRecord(providerMetadata) ? providerMetadata : {},
|
|
36
|
+
cossistant: metadata
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Read tool timeline metadata from cossistant part metadata.
|
|
42
|
+
*/
|
|
43
|
+
function getCossistantToolTimelineMetadata(part) {
|
|
44
|
+
return getCossistantPartMetadata(part)?.toolTimeline;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Write tool timeline metadata into cossistant part metadata.
|
|
48
|
+
*/
|
|
49
|
+
function setCossistantToolTimelineMetadata(part, toolTimeline) {
|
|
50
|
+
return setCossistantPartMetadata(part, {
|
|
51
|
+
...getCossistantPartMetadata(part) ?? {},
|
|
52
|
+
toolTimeline
|
|
53
|
+
});
|
|
54
|
+
}
|
|
2
55
|
function isTextPart(part) {
|
|
3
56
|
return part.type === "text" && "text" in part;
|
|
4
57
|
}
|
|
@@ -115,16 +168,20 @@ function toAISDKPart(part) {
|
|
|
115
168
|
filename: typedPart.filename ?? typedPart.fileName
|
|
116
169
|
};
|
|
117
170
|
}
|
|
118
|
-
if (isToolPart(part))
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
171
|
+
if (isToolPart(part)) {
|
|
172
|
+
const metadataCarrier = getMetadataCarrier(part);
|
|
173
|
+
return {
|
|
174
|
+
type: part.type,
|
|
175
|
+
toolCallId: part.toolCallId,
|
|
176
|
+
toolName: part.toolName,
|
|
177
|
+
input: part.input,
|
|
178
|
+
output: part.output,
|
|
179
|
+
state: part.state,
|
|
180
|
+
errorText: part.errorText,
|
|
181
|
+
callProviderMetadata: metadataCarrier.callProviderMetadata,
|
|
182
|
+
providerMetadata: metadataCarrier.providerMetadata
|
|
183
|
+
};
|
|
184
|
+
}
|
|
128
185
|
if (isEventPart(part) || isMetadataPart(part)) return null;
|
|
129
186
|
return null;
|
|
130
187
|
}
|
|
@@ -208,16 +265,23 @@ function fromAISDKPart(part) {
|
|
|
208
265
|
filename: typedPart.filename
|
|
209
266
|
};
|
|
210
267
|
default:
|
|
211
|
-
if (typedPart.type.startsWith("tool-"))
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
268
|
+
if (typedPart.type.startsWith("tool-")) {
|
|
269
|
+
const metadataCarrier = getMetadataCarrier({
|
|
270
|
+
callProviderMetadata: typedPart.callProviderMetadata,
|
|
271
|
+
providerMetadata: typedPart.providerMetadata
|
|
272
|
+
});
|
|
273
|
+
return {
|
|
274
|
+
type: typedPart.type,
|
|
275
|
+
toolCallId: String(typedPart.toolCallId ?? ""),
|
|
276
|
+
toolName: String(typedPart.toolName ?? ""),
|
|
277
|
+
input: typedPart.input ?? {},
|
|
278
|
+
output: typedPart.output,
|
|
279
|
+
state: typedPart.state ?? "partial",
|
|
280
|
+
errorText: typedPart.errorText,
|
|
281
|
+
callProviderMetadata: metadataCarrier.callProviderMetadata,
|
|
282
|
+
providerMetadata: metadataCarrier.providerMetadata
|
|
283
|
+
};
|
|
284
|
+
}
|
|
221
285
|
return null;
|
|
222
286
|
}
|
|
223
287
|
}
|
|
@@ -251,5 +315,5 @@ function hasProcessingParts(parts) {
|
|
|
251
315
|
}
|
|
252
316
|
|
|
253
317
|
//#endregion
|
|
254
|
-
export { extractSources, extractToolCalls, fromUIMessage, fromUIMessages, hasProcessingParts, isAISDKCompatiblePart, toUIMessage, toUIMessages };
|
|
318
|
+
export { extractSources, extractToolCalls, fromUIMessage, fromUIMessages, getCossistantPartMetadata, getCossistantToolTimelineMetadata, hasProcessingParts, isAISDKCompatiblePart, setCossistantPartMetadata, setCossistantToolTimelineMetadata, toUIMessage, toUIMessages };
|
|
255
319
|
//# sourceMappingURL=ai-sdk-utils.js.map
|
package/ai-sdk-utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-sdk-utils.js","names":[],"sources":["../src/ai-sdk-utils.ts"],"sourcesContent":["/**\n * AI SDK v6 Conversion Utilities\n *\n * This module provides utilities for converting between Cossistant's\n * TimelineItem format and Vercel AI SDK v6's UIMessage format.\n *\n * Key concepts:\n * - Cossistant uses TimelineItem with userId/aiAgentId/visitorId\n * - AI SDK uses UIMessage with role: 'user' | 'assistant' | 'system'\n * - Both use a parts array for content\n * - Extensions go in metadata (message level) and providerMetadata (part level)\n */\n\nimport type { TimelineItem, TimelineItemParts } from \"@cossistant/types\";\n\n// ============================================================================\n// AI SDK TYPES (re-export for convenience)\n// ============================================================================\n\n/**\n * AI SDK UIMessage part types - these are the standard AI SDK v6 parts\n */\nexport type AISDKTextPart = {\n\ttype: \"text\";\n\ttext: string;\n\tstate?: \"streaming\" | \"done\";\n};\n\nexport type AISDKReasoningPart = {\n\ttype: \"reasoning\";\n\ttext: string;\n\tstate?: \"streaming\" | \"done\";\n\tproviderMetadata?: Record<string, unknown>;\n};\n\nexport type AISDKToolPart = {\n\ttype: `tool-${string}`;\n\ttoolCallId: string;\n\ttoolName: string;\n\tinput: Record<string, unknown>;\n\toutput?: unknown;\n\tstate: \"partial\" | \"result\" | \"error\";\n\terrorText?: string;\n\tproviderMetadata?: Record<string, unknown>;\n};\n\nexport type AISDKSourceUrlPart = {\n\ttype: \"source-url\";\n\tsourceId: string;\n\turl: string;\n\ttitle?: string;\n\tproviderMetadata?: Record<string, unknown>;\n};\n\nexport type AISDKSourceDocumentPart = {\n\ttype: \"source-document\";\n\tsourceId: string;\n\tmediaType: string;\n\ttitle: string;\n\tfilename?: string;\n\tproviderMetadata?: Record<string, unknown>;\n};\n\nexport type AISDKStepStartPart = {\n\ttype: \"step-start\";\n};\n\nexport type AISDKFilePart = {\n\ttype: \"file\";\n\turl: string;\n\tmediaType: string;\n\tfilename?: string;\n};\n\n// ============================================================================\n// COSSISTANT METADATA TYPES\n// ============================================================================\n\n/**\n * Cossistant-specific metadata stored in UIMessage.metadata\n */\nexport type CossistantMessageMetadata = {\n\tconversationId: string;\n\torganizationId: string;\n\tvisibility: \"public\" | \"private\";\n\tuserId: string | null;\n\taiAgentId: string | null;\n\tvisitorId: string | null;\n\treplyToId?: string | null;\n\tcreatedAt: string;\n\tdeletedAt?: string | null;\n\ttool?: string | null;\n};\n\n/**\n * Cossistant-specific metadata stored in part.providerMetadata.cossistant\n */\nexport type CossistantPartMetadata = {\n\tvisibility?: \"public\" | \"private\";\n\tprogressMessage?: string;\n\tknowledgeId?: string;\n};\n\n// ============================================================================\n// TYPE HELPERS\n// ============================================================================\n\nexport type AISDKPart =\n\t| AISDKTextPart\n\t| AISDKReasoningPart\n\t| AISDKToolPart\n\t| AISDKSourceUrlPart\n\t| AISDKSourceDocumentPart\n\t| AISDKStepStartPart\n\t| AISDKFilePart;\n\ntype CossistantPart = TimelineItemParts[number];\n\n// Type guards for Cossistant parts\nfunction isTextPart(\n\tpart: CossistantPart\n): part is CossistantPart & { type: \"text\"; text: string } {\n\treturn part.type === \"text\" && \"text\" in part;\n}\n\nfunction isReasoningPart(\n\tpart: CossistantPart\n): part is CossistantPart & { type: \"reasoning\"; text: string } {\n\treturn part.type === \"reasoning\" && \"text\" in part;\n}\n\nfunction isSourceUrlPart(part: CossistantPart): part is CossistantPart & {\n\ttype: \"source-url\";\n\tsourceId: string;\n\turl: string;\n} {\n\treturn part.type === \"source-url\" && \"sourceId\" in part && \"url\" in part;\n}\n\nfunction isSourceDocumentPart(part: CossistantPart): part is CossistantPart & {\n\ttype: \"source-document\";\n\tsourceId: string;\n\tmediaType: string;\n\ttitle: string;\n} {\n\treturn (\n\t\tpart.type === \"source-document\" &&\n\t\t\"sourceId\" in part &&\n\t\t\"mediaType\" in part &&\n\t\t\"title\" in part\n\t);\n}\n\nfunction isStepStartPart(\n\tpart: CossistantPart\n): part is CossistantPart & { type: \"step-start\" } {\n\treturn part.type === \"step-start\";\n}\n\nfunction isFilePart(\n\tpart: CossistantPart\n): part is CossistantPart & { type: \"file\"; url: string; mediaType: string } {\n\treturn part.type === \"file\" && \"url\" in part && \"mediaType\" in part;\n}\n\nfunction isImagePart(\n\tpart: CossistantPart\n): part is CossistantPart & { type: \"image\"; url: string; mediaType: string } {\n\treturn part.type === \"image\" && \"url\" in part && \"mediaType\" in part;\n}\n\nfunction isToolPart(part: CossistantPart): part is CossistantPart & {\n\ttype: string;\n\ttoolCallId: string;\n\ttoolName: string;\n\tinput: Record<string, unknown>;\n\tstate: \"partial\" | \"result\" | \"error\";\n} {\n\treturn (\n\t\ttypeof part.type === \"string\" &&\n\t\tpart.type.startsWith(\"tool-\") &&\n\t\t\"toolCallId\" in part &&\n\t\t\"toolName\" in part\n\t);\n}\n\nfunction isEventPart(\n\tpart: CossistantPart\n): part is CossistantPart & { type: \"event\" } {\n\treturn part.type === \"event\";\n}\n\nfunction isMetadataPart(\n\tpart: CossistantPart\n): part is CossistantPart & { type: \"metadata\" } {\n\treturn part.type === \"metadata\";\n}\n\n// ============================================================================\n// CONVERSION: TIMELINE ITEM -> UI MESSAGE\n// ============================================================================\n\n/**\n * Cossistant-compatible UIMessage type\n * This is structurally compatible with AI SDK v6 UIMessage\n * but uses our own part types for flexibility\n */\nexport type CossistantUIMessage = {\n\tid: string;\n\trole: \"user\" | \"assistant\" | \"system\";\n\tmetadata: CossistantMessageMetadata;\n\tparts: AISDKPart[];\n};\n\n/**\n * Convert a Cossistant TimelineItem to AI SDK UIMessage format\n *\n * @param item - The Cossistant TimelineItem to convert\n * @returns AI SDK compatible UIMessage with Cossistant metadata\n */\nexport function toUIMessage(item: TimelineItem): CossistantUIMessage {\n\treturn {\n\t\tid: item.id ?? \"\",\n\t\trole: getAISDKRole(item),\n\t\tmetadata: {\n\t\t\tconversationId: item.conversationId,\n\t\t\torganizationId: item.organizationId,\n\t\t\tvisibility: item.visibility,\n\t\t\tuserId: item.userId,\n\t\t\taiAgentId: item.aiAgentId,\n\t\t\tvisitorId: item.visitorId,\n\t\t\tcreatedAt: item.createdAt,\n\t\t\tdeletedAt: item.deletedAt ?? null,\n\t\t\ttool: item.tool ?? null,\n\t\t},\n\t\tparts: item.parts.map(toAISDKPart).filter(Boolean) as AISDKPart[],\n\t};\n}\n\n/**\n * Convert multiple TimelineItems to UIMessages\n */\nexport function toUIMessages(items: TimelineItem[]): CossistantUIMessage[] {\n\treturn items.map(toUIMessage);\n}\n\n/**\n * Determine AI SDK role from TimelineItem sender fields\n */\nfunction getAISDKRole(item: TimelineItem): \"user\" | \"assistant\" | \"system\" {\n\t// AI agent messages become assistant\n\tif (item.aiAgentId) {\n\t\treturn \"assistant\";\n\t}\n\n\t// Both visitor and human user messages become user\n\t// (AI SDK doesn't distinguish between these)\n\treturn \"user\";\n}\n\n/**\n * Convert a Cossistant part to AI SDK part format\n */\nfunction toAISDKPart(part: CossistantPart): AISDKPart | null {\n\tif (isTextPart(part)) {\n\t\treturn {\n\t\t\ttype: \"text\",\n\t\t\ttext: part.text,\n\t\t\tstate: (part as { state?: \"streaming\" | \"done\" }).state,\n\t\t};\n\t}\n\n\tif (isReasoningPart(part)) {\n\t\treturn {\n\t\t\ttype: \"reasoning\",\n\t\t\ttext: part.text,\n\t\t\tstate: (part as { state?: \"streaming\" | \"done\" }).state,\n\t\t\tproviderMetadata: (part as { providerMetadata?: Record<string, unknown> })\n\t\t\t\t.providerMetadata,\n\t\t};\n\t}\n\n\tif (isSourceUrlPart(part)) {\n\t\treturn {\n\t\t\ttype: \"source-url\",\n\t\t\tsourceId: part.sourceId,\n\t\t\turl: part.url,\n\t\t\ttitle: (part as { title?: string }).title,\n\t\t\tproviderMetadata: (part as { providerMetadata?: Record<string, unknown> })\n\t\t\t\t.providerMetadata,\n\t\t};\n\t}\n\n\tif (isSourceDocumentPart(part)) {\n\t\treturn {\n\t\t\ttype: \"source-document\",\n\t\t\tsourceId: part.sourceId,\n\t\t\tmediaType: part.mediaType,\n\t\t\ttitle: part.title,\n\t\t\tfilename: (part as { filename?: string }).filename,\n\t\t\tproviderMetadata: (part as { providerMetadata?: Record<string, unknown> })\n\t\t\t\t.providerMetadata,\n\t\t};\n\t}\n\n\tif (isStepStartPart(part)) {\n\t\treturn {\n\t\t\ttype: \"step-start\",\n\t\t};\n\t}\n\n\tif (isFilePart(part)) {\n\t\t// Support both 'filename' (new) and 'fileName' (legacy) for backward compatibility\n\t\tconst typedPart = part as { filename?: string; fileName?: string };\n\t\treturn {\n\t\t\ttype: \"file\",\n\t\t\turl: part.url,\n\t\t\tmediaType: part.mediaType,\n\t\t\tfilename: typedPart.filename ?? typedPart.fileName,\n\t\t};\n\t}\n\n\tif (isImagePart(part)) {\n\t\t// Convert image to file part (AI SDK uses file for all media)\n\t\t// Support both 'filename' (new) and 'fileName' (legacy) for backward compatibility\n\t\tconst typedPart = part as { filename?: string; fileName?: string };\n\t\treturn {\n\t\t\ttype: \"file\",\n\t\t\turl: part.url,\n\t\t\tmediaType: part.mediaType,\n\t\t\tfilename: typedPart.filename ?? typedPart.fileName,\n\t\t};\n\t}\n\n\tif (isToolPart(part)) {\n\t\treturn {\n\t\t\ttype: part.type as `tool-${string}`,\n\t\t\ttoolCallId: part.toolCallId,\n\t\t\ttoolName: part.toolName,\n\t\t\tinput: part.input,\n\t\t\toutput: (part as { output?: unknown }).output,\n\t\t\tstate: part.state,\n\t\t\terrorText: (part as { errorText?: string }).errorText,\n\t\t\tproviderMetadata: (part as { providerMetadata?: Record<string, unknown> })\n\t\t\t\t.providerMetadata,\n\t\t};\n\t}\n\n\t// Event and metadata parts are Cossistant-specific, skip for AI SDK\n\tif (isEventPart(part) || isMetadataPart(part)) {\n\t\treturn null;\n\t}\n\n\treturn null;\n}\n\n// ============================================================================\n// CONVERSION: UI MESSAGE -> TIMELINE ITEM\n// ============================================================================\n\n/**\n * Context required to create a TimelineItem from UIMessage\n */\nexport type FromUIMessageContext = {\n\tconversationId: string;\n\torganizationId: string;\n\taiAgentId?: string | null;\n\tuserId?: string | null;\n\tvisitorId?: string | null;\n\tvisibility?: \"public\" | \"private\";\n};\n\n/**\n * Convert an AI SDK UIMessage to Cossistant TimelineItem format\n *\n * @param message - The AI SDK UIMessage to convert\n * @param context - Context for creating the TimelineItem\n * @returns Cossistant TimelineItem\n */\nexport function fromUIMessage(\n\tmessage: CossistantUIMessage,\n\tcontext: FromUIMessageContext\n): TimelineItem {\n\t// Extract metadata if available\n\tconst metadata = message.metadata;\n\n\treturn {\n\t\tid: message.id,\n\t\tconversationId: metadata?.conversationId ?? context.conversationId,\n\t\torganizationId: metadata?.organizationId ?? context.organizationId,\n\t\tvisibility: metadata?.visibility ?? context.visibility ?? \"public\",\n\t\ttype: \"message\",\n\t\ttext: extractTextFromParts(message.parts),\n\t\tparts: message.parts\n\t\t\t.map(fromAISDKPart)\n\t\t\t.filter(Boolean) as TimelineItemParts,\n\t\tuserId: metadata?.userId ?? context.userId ?? null,\n\t\taiAgentId: metadata?.aiAgentId ?? context.aiAgentId ?? null,\n\t\tvisitorId: metadata?.visitorId ?? context.visitorId ?? null,\n\t\tcreatedAt: metadata?.createdAt ?? new Date().toISOString(),\n\t\tdeletedAt: metadata?.deletedAt ?? null,\n\t\ttool: metadata?.tool ?? null,\n\t};\n}\n\n/**\n * Convert multiple UIMessages to TimelineItems\n */\nexport function fromUIMessages(\n\tmessages: CossistantUIMessage[],\n\tcontext: FromUIMessageContext\n): TimelineItem[] {\n\treturn messages.map((msg) => fromUIMessage(msg, context));\n}\n\n/**\n * Extract plain text content from message parts\n */\nfunction extractTextFromParts(parts: unknown[]): string | null {\n\tconst textParts = parts.filter(\n\t\t(part): part is AISDKTextPart =>\n\t\t\ttypeof part === \"object\" &&\n\t\t\tpart !== null &&\n\t\t\t\"type\" in part &&\n\t\t\tpart.type === \"text\"\n\t);\n\n\tif (textParts.length === 0) {\n\t\treturn null;\n\t}\n\treturn textParts.map((p) => p.text).join(\"\\n\");\n}\n\n/**\n * Convert an AI SDK part to Cossistant part format\n */\nfunction fromAISDKPart(part: unknown): CossistantPart | null {\n\tif (typeof part !== \"object\" || part === null || !(\"type\" in part)) {\n\t\treturn null;\n\t}\n\n\tconst typedPart = part as { type: string; [key: string]: unknown };\n\n\tswitch (typedPart.type) {\n\t\tcase \"text\":\n\t\t\treturn {\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext: String(typedPart.text ?? \"\"),\n\t\t\t\tstate: typedPart.state as \"streaming\" | \"done\" | undefined,\n\t\t\t};\n\n\t\tcase \"reasoning\":\n\t\t\treturn {\n\t\t\t\ttype: \"reasoning\",\n\t\t\t\ttext: String(typedPart.text ?? \"\"),\n\t\t\t\tstate: typedPart.state as \"streaming\" | \"done\" | undefined,\n\t\t\t\tproviderMetadata: typedPart.providerMetadata as\n\t\t\t\t\t| Record<string, unknown>\n\t\t\t\t\t| undefined,\n\t\t\t};\n\n\t\tcase \"source-url\":\n\t\t\treturn {\n\t\t\t\ttype: \"source-url\",\n\t\t\t\tsourceId: String(typedPart.sourceId ?? \"\"),\n\t\t\t\turl: String(typedPart.url ?? \"\"),\n\t\t\t\ttitle: typedPart.title as string | undefined,\n\t\t\t\tproviderMetadata: typedPart.providerMetadata as\n\t\t\t\t\t| Record<string, unknown>\n\t\t\t\t\t| undefined,\n\t\t\t};\n\n\t\tcase \"source-document\":\n\t\t\treturn {\n\t\t\t\ttype: \"source-document\",\n\t\t\t\tsourceId: String(typedPart.sourceId ?? \"\"),\n\t\t\t\tmediaType: String(typedPart.mediaType ?? \"\"),\n\t\t\t\ttitle: String(typedPart.title ?? \"\"),\n\t\t\t\tfilename: typedPart.filename as string | undefined,\n\t\t\t\tproviderMetadata: typedPart.providerMetadata as\n\t\t\t\t\t| Record<string, unknown>\n\t\t\t\t\t| undefined,\n\t\t\t};\n\n\t\tcase \"step-start\":\n\t\t\treturn {\n\t\t\t\ttype: \"step-start\",\n\t\t\t};\n\n\t\tcase \"file\":\n\t\t\treturn {\n\t\t\t\ttype: \"file\",\n\t\t\t\turl: String(typedPart.url ?? \"\"),\n\t\t\t\tmediaType: String(typedPart.mediaType ?? \"\"),\n\t\t\t\tfilename: typedPart.filename as string | undefined,\n\t\t\t};\n\n\t\tdefault:\n\t\t\t// Handle tool-* pattern\n\t\t\tif (typedPart.type.startsWith(\"tool-\")) {\n\t\t\t\treturn {\n\t\t\t\t\ttype: typedPart.type,\n\t\t\t\t\ttoolCallId: String(typedPart.toolCallId ?? \"\"),\n\t\t\t\t\ttoolName: String(typedPart.toolName ?? \"\"),\n\t\t\t\t\tinput: (typedPart.input as Record<string, unknown>) ?? {},\n\t\t\t\t\toutput: typedPart.output,\n\t\t\t\t\tstate:\n\t\t\t\t\t\t(typedPart.state as \"partial\" | \"result\" | \"error\") ?? \"partial\",\n\t\t\t\t\terrorText: typedPart.errorText as string | undefined,\n\t\t\t\t\tproviderMetadata: typedPart.providerMetadata as\n\t\t\t\t\t\t| Record<string, unknown>\n\t\t\t\t\t\t| undefined,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn null;\n\t}\n}\n\n// ============================================================================\n// HELPER UTILITIES\n// ============================================================================\n\n/**\n * Check if a part is an AI SDK compatible part type\n */\nexport function isAISDKCompatiblePart(part: CossistantPart): boolean {\n\tif (part.type === \"event\" || part.type === \"metadata\") {\n\t\treturn false;\n\t}\n\treturn true;\n}\n\n/**\n * Extract all sources from a message's parts\n */\nexport function extractSources(\n\tparts: AISDKPart[]\n): (AISDKSourceUrlPart | AISDKSourceDocumentPart)[] {\n\treturn parts.filter(\n\t\t(part): part is AISDKSourceUrlPart | AISDKSourceDocumentPart =>\n\t\t\tpart.type === \"source-url\" || part.type === \"source-document\"\n\t);\n}\n\n/**\n * Extract all tool calls from a message's parts\n */\nexport function extractToolCalls(parts: AISDKPart[]): AISDKToolPart[] {\n\treturn parts.filter(\n\t\t(part): part is AISDKToolPart =>\n\t\t\ttypeof part.type === \"string\" && part.type.startsWith(\"tool-\")\n\t);\n}\n\n/**\n * Check if any parts are still processing\n */\nexport function hasProcessingParts(parts: AISDKPart[]): boolean {\n\treturn parts.some((part) => {\n\t\tif (\n\t\t\t\"state\" in part &&\n\t\t\t(part.state === \"streaming\" || part.state === \"partial\")\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t});\n}\n"],"mappings":";AAuHA,SAAS,WACR,MAC0D;AAC1D,QAAO,KAAK,SAAS,UAAU,UAAU;;AAG1C,SAAS,gBACR,MAC+D;AAC/D,QAAO,KAAK,SAAS,eAAe,UAAU;;AAG/C,SAAS,gBAAgB,MAIvB;AACD,QAAO,KAAK,SAAS,gBAAgB,cAAc,QAAQ,SAAS;;AAGrE,SAAS,qBAAqB,MAK5B;AACD,QACC,KAAK,SAAS,qBACd,cAAc,QACd,eAAe,QACf,WAAW;;AAIb,SAA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UAAU;GACpB;EAEF;AAEC,OAAI,UAAU,KAAK,WAAW,QAAQ,CACrC,QAAO;IACN,MAAM,UAAU;IAChB,YAAY,OAAO,UAAU,cAAc,GAAG;IAC9C,UAAU,OAAO,UAAU,YAAY,GAAG;IAC1C,OAAQ,UAAU,SAAqC,EAAE;IACzD,QAAQ,UAAU;IAClB,OACE,UAAU,SAA4C;IACxD,WAAW,UAAU;IACrB,kBAAkB,UAAU;IAG5B;AAEF,UAAO;;;;;;AAWV,SAAgB,sBAAsB,MAA+B;AACpE,KAAI,KAAK,SAAS,WAAW,KAAK,SAAS,WAC1C,QAAO;AAER,QAAO;;;;;AAMR,SAAgB,eACf,OACmD;AACnD,QAAO,MAAM,QACX,SACA,KAAK,SAAS,gBAAgB,KAAK,SAAS,kBAC7C;;;;;AAMF,SAAgB,iBAAiB,OAAqC;AACrE,QAAO,MAAM,QACX,SACA,OAAO,KAAK,SAAS,YAAY,KAAK,KAAK,WAAW,QAAQ,CAC/D;;;;;AAMF,SAAgB,mBAAmB,OAA6B;AAC/D,QAAO,MAAM,MAAM,SAAS;AAC3B,MACC,WAAW,SACV,KAAK,UAAU,eAAe,KAAK,UAAU,WAE9C,QAAO;AAER,SAAO;GACN"}
|
|
1
|
+
{"version":3,"file":"ai-sdk-utils.js","names":[],"sources":["../src/ai-sdk-utils.ts"],"sourcesContent":["/**\n * AI SDK v6 Conversion Utilities\n *\n * This module provides utilities for converting between Cossistant's\n * TimelineItem format and Vercel AI SDK v6's UIMessage format.\n *\n * Key concepts:\n * - Cossistant uses TimelineItem with userId/aiAgentId/visitorId\n * - AI SDK uses UIMessage with role: 'user' | 'assistant' | 'system'\n * - Both use a parts array for content\n * - Extensions go in metadata (message level) and providerMetadata/callProviderMetadata (part level)\n */\n\nimport type {\n\tTimelineItem,\n\tTimelineItemParts,\n\tToolTimelineLogType,\n} from \"@cossistant/types\";\n\n// ============================================================================\n// AI SDK TYPES (re-export for convenience)\n// ============================================================================\n\n/**\n * AI SDK UIMessage part types - these are the standard AI SDK v6 parts\n */\nexport type AISDKTextPart = {\n\ttype: \"text\";\n\ttext: string;\n\tstate?: \"streaming\" | \"done\";\n};\n\nexport type AISDKReasoningPart = {\n\ttype: \"reasoning\";\n\ttext: string;\n\tstate?: \"streaming\" | \"done\";\n\tproviderMetadata?: Record<string, unknown>;\n};\n\nexport type AISDKToolPart = {\n\ttype: `tool-${string}`;\n\ttoolCallId: string;\n\ttoolName: string;\n\tinput: Record<string, unknown>;\n\toutput?: unknown;\n\tstate: \"partial\" | \"result\" | \"error\";\n\terrorText?: string;\n\tcallProviderMetadata?: Record<string, unknown>;\n\tproviderMetadata?: Record<string, unknown>;\n};\n\nexport type AISDKSourceUrlPart = {\n\ttype: \"source-url\";\n\tsourceId: string;\n\turl: string;\n\ttitle?: string;\n\tproviderMetadata?: Record<string, unknown>;\n};\n\nexport type AISDKSourceDocumentPart = {\n\ttype: \"source-document\";\n\tsourceId: string;\n\tmediaType: string;\n\ttitle: string;\n\tfilename?: string;\n\tproviderMetadata?: Record<string, unknown>;\n};\n\nexport type AISDKStepStartPart = {\n\ttype: \"step-start\";\n};\n\nexport type AISDKFilePart = {\n\ttype: \"file\";\n\turl: string;\n\tmediaType: string;\n\tfilename?: string;\n};\n\n// ============================================================================\n// COSSISTANT METADATA TYPES\n// ============================================================================\n\n/**\n * Cossistant-specific metadata stored in UIMessage.metadata\n */\nexport type CossistantMessageMetadata = {\n\tconversationId: string;\n\torganizationId: string;\n\tvisibility: \"public\" | \"private\";\n\tuserId: string | null;\n\taiAgentId: string | null;\n\tvisitorId: string | null;\n\treplyToId?: string | null;\n\tcreatedAt: string;\n\tdeletedAt?: string | null;\n\ttool?: string | null;\n};\n\n/**\n * Cossistant-specific metadata stored in part.callProviderMetadata/providerMetadata.cossistant\n */\nexport type CossistantToolTimelineMetadata = {\n\tlogType: ToolTimelineLogType;\n\ttriggerMessageId: string;\n\tworkflowRunId: string;\n\ttriggerVisibility?: \"public\" | \"private\";\n};\n\nexport type CossistantPartMetadata = {\n\tvisibility?: \"public\" | \"private\";\n\tprogressMessage?: string;\n\tknowledgeId?: string;\n\ttoolTimeline?: CossistantToolTimelineMetadata;\n};\n\ntype AISDKPartMetadataCarrier = {\n\tproviderMetadata?: Record<string, unknown>;\n\tcallProviderMetadata?: Record<string, unknown>;\n};\n\n// ============================================================================\n// TYPE HELPERS\n// ============================================================================\n\nexport type AISDKPart =\n\t| AISDKTextPart\n\t| AISDKReasoningPart\n\t| AISDKToolPart\n\t| AISDKSourceUrlPart\n\t| AISDKSourceDocumentPart\n\t| AISDKStepStartPart\n\t| AISDKFilePart;\n\ntype CossistantPart = TimelineItemParts[number];\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction getMetadataCarrier(\n\tpart: AISDKPartMetadataCarrier\n): AISDKPartMetadataCarrier {\n\tconst callProviderMetadata =\n\t\tpart.callProviderMetadata ?? part.providerMetadata;\n\tconst providerMetadata = part.providerMetadata ?? part.callProviderMetadata;\n\n\treturn {\n\t\tcallProviderMetadata,\n\t\tproviderMetadata,\n\t};\n}\n\n/**\n * Read cossistant part metadata from AI SDK v6-compatible part metadata.\n * Prefers callProviderMetadata but accepts providerMetadata for backward compatibility.\n */\nexport function getCossistantPartMetadata(\n\tpart: AISDKPartMetadataCarrier\n): CossistantPartMetadata | undefined {\n\tconst { callProviderMetadata, providerMetadata } = getMetadataCarrier(part);\n\tconst metadata = callProviderMetadata ?? providerMetadata;\n\n\tif (!isRecord(metadata)) {\n\t\treturn;\n\t}\n\n\tconst cossistant = metadata.cossistant;\n\tif (!isRecord(cossistant)) {\n\t\treturn;\n\t}\n\n\treturn cossistant as CossistantPartMetadata;\n}\n\n/**\n * Write cossistant part metadata into both callProviderMetadata and providerMetadata.\n * This keeps AI SDK v6 semantics while remaining backward compatible.\n */\nexport function setCossistantPartMetadata(\n\tpart: AISDKPartMetadataCarrier,\n\tmetadata: CossistantPartMetadata\n): AISDKPartMetadataCarrier {\n\tconst { callProviderMetadata, providerMetadata } = getMetadataCarrier(part);\n\tconst nextCallProviderMetadata = {\n\t\t...(isRecord(callProviderMetadata) ? callProviderMetadata : {}),\n\t\tcossistant: metadata,\n\t};\n\tconst nextProviderMetadata = {\n\t\t...(isRecord(providerMetadata) ? providerMetadata : {}),\n\t\tcossistant: metadata,\n\t};\n\n\treturn {\n\t\tcallProviderMetadata: nextCallProviderMetadata,\n\t\tproviderMetadata: nextProviderMetadata,\n\t};\n}\n\n/**\n * Read tool timeline metadata from cossistant part metadata.\n */\nexport function getCossistantToolTimelineMetadata(\n\tpart: AISDKPartMetadataCarrier\n): CossistantToolTimelineMetadata | undefined {\n\treturn getCossistantPartMetadata(part)?.toolTimeline;\n}\n\n/**\n * Write tool timeline metadata into cossistant part metadata.\n */\nexport function setCossistantToolTimelineMetadata(\n\tpart: AISDKPartMetadataCarrier,\n\ttoolTimeline: CossistantToolTimelineMetadata\n): AISDKPartMetadataCarrier {\n\tconst existing = getCossistantPartMetadata(part) ?? {};\n\treturn setCossistantPartMetadata(part, {\n\t\t...existing,\n\t\ttoolTimeline,\n\t});\n}\n\n// Type guards for Cossistant parts\nfunction isTextPart(\n\tpart: CossistantPart\n): part is CossistantPart & { type: \"text\"; text: string } {\n\treturn part.type === \"text\" && \"text\" in part;\n}\n\nfunction isReasoningPart(\n\tpart: CossistantPart\n): part is CossistantPart & { type: \"reasoning\"; text: string } {\n\treturn part.type === \"reasoning\" && \"text\" in part;\n}\n\nfunction isSourceUrlPart(part: CossistantPart): part is CossistantPart & {\n\ttype: \"source-url\";\n\tsourceId: string;\n\turl: string;\n} {\n\treturn part.type === \"source-url\" && \"sourceId\" in part && \"url\" in part;\n}\n\nfunction isSourceDocumentPart(part: CossistantPart): part is CossistantPart & {\n\ttype: \"source-document\";\n\tsourceId: string;\n\tmediaType: string;\n\ttitle: string;\n} {\n\treturn (\n\t\tpart.type === \"source-document\" &&\n\t\t\"sourceId\" in part &&\n\t\t\"mediaType\" in part &&\n\t\t\"title\" in part\n\t);\n}\n\nfunction isStepStartPart(\n\tpart: CossistantPart\n): part is CossistantPart & { type: \"step-start\" } {\n\treturn part.type === \"step-start\";\n}\n\nfunction isFilePart(\n\tpart: CossistantPart\n): part is CossistantPart & { type: \"file\"; url: string; mediaType: string } {\n\treturn part.type === \"file\" && \"url\" in part && \"mediaType\" in part;\n}\n\nfunction isImagePart(\n\tpart: CossistantPart\n): part is CossistantPart & { type: \"image\"; url: string; mediaType: string } {\n\treturn part.type === \"image\" && \"url\" in part && \"mediaType\" in part;\n}\n\nfunction isToolPart(part: CossistantPart): part is CossistantPart & {\n\ttype: string;\n\ttoolCallId: string;\n\ttoolName: string;\n\tinput: Record<string, unknown>;\n\tstate: \"partial\" | \"result\" | \"error\";\n} {\n\treturn (\n\t\ttypeof part.type === \"string\" &&\n\t\tpart.type.startsWith(\"tool-\") &&\n\t\t\"toolCallId\" in part &&\n\t\t\"toolName\" in part\n\t);\n}\n\nfunction isEventPart(\n\tpart: CossistantPart\n): part is CossistantPart & { type: \"event\" } {\n\treturn part.type === \"event\";\n}\n\nfunction isMetadataPart(\n\tpart: CossistantPart\n): part is CossistantPart & { type: \"metadata\" } {\n\treturn part.type === \"metadata\";\n}\n\n// ============================================================================\n// CONVERSION: TIMELINE ITEM -> UI MESSAGE\n// ============================================================================\n\n/**\n * Cossistant-compatible UIMessage type\n * This is structurally compatible with AI SDK v6 UIMessage\n * but uses our own part types for flexibility\n */\nexport type CossistantUIMessage = {\n\tid: string;\n\trole: \"user\" | \"assistant\" | \"system\";\n\tmetadata: CossistantMessageMetadata;\n\tparts: AISDKPart[];\n};\n\n/**\n * Convert a Cossistant TimelineItem to AI SDK UIMessage format\n *\n * @param item - The Cossistant TimelineItem to convert\n * @returns AI SDK compatible UIMessage with Cossistant metadata\n */\nexport function toUIMessage(item: TimelineItem): CossistantUIMessage {\n\treturn {\n\t\tid: item.id ?? \"\",\n\t\trole: getAISDKRole(item),\n\t\tmetadata: {\n\t\t\tconversationId: item.conversationId,\n\t\t\torganizationId: item.organizationId,\n\t\t\tvisibility: item.visibility,\n\t\t\tuserId: item.userId,\n\t\t\taiAgentId: item.aiAgentId,\n\t\t\tvisitorId: item.visitorId,\n\t\t\tcreatedAt: item.createdAt,\n\t\t\tdeletedAt: item.deletedAt ?? null,\n\t\t\ttool: item.tool ?? null,\n\t\t},\n\t\tparts: item.parts.map(toAISDKPart).filter(Boolean) as AISDKPart[],\n\t};\n}\n\n/**\n * Convert multiple TimelineItems to UIMessages\n */\nexport function toUIMessages(items: TimelineItem[]): CossistantUIMessage[] {\n\treturn items.map(toUIMessage);\n}\n\n/**\n * Determine AI SDK role from TimelineItem sender fields\n */\nfunction getAISDKRole(item: TimelineItem): \"user\" | \"assistant\" | \"system\" {\n\t// AI agent messages become assistant\n\tif (item.aiAgentId) {\n\t\treturn \"assistant\";\n\t}\n\n\t// Both visitor and human user messages become user\n\t// (AI SDK doesn't distinguish between these)\n\treturn \"user\";\n}\n\n/**\n * Convert a Cossistant part to AI SDK part format\n */\nfunction toAISDKPart(part: CossistantPart): AISDKPart | null {\n\tif (isTextPart(part)) {\n\t\treturn {\n\t\t\ttype: \"text\",\n\t\t\ttext: part.text,\n\t\t\tstate: (part as { state?: \"streaming\" | \"done\" }).state,\n\t\t};\n\t}\n\n\tif (isReasoningPart(part)) {\n\t\treturn {\n\t\t\ttype: \"reasoning\",\n\t\t\ttext: part.text,\n\t\t\tstate: (part as { state?: \"streaming\" | \"done\" }).state,\n\t\t\tproviderMetadata: (part as { providerMetadata?: Record<string, unknown> })\n\t\t\t\t.providerMetadata,\n\t\t};\n\t}\n\n\tif (isSourceUrlPart(part)) {\n\t\treturn {\n\t\t\ttype: \"source-url\",\n\t\t\tsourceId: part.sourceId,\n\t\t\turl: part.url,\n\t\t\ttitle: (part as { title?: string }).title,\n\t\t\tproviderMetadata: (part as { providerMetadata?: Record<string, unknown> })\n\t\t\t\t.providerMetadata,\n\t\t};\n\t}\n\n\tif (isSourceDocumentPart(part)) {\n\t\treturn {\n\t\t\ttype: \"source-document\",\n\t\t\tsourceId: part.sourceId,\n\t\t\tmediaType: part.mediaType,\n\t\t\ttitle: part.title,\n\t\t\tfilename: (part as { filename?: string }).filename,\n\t\t\tproviderMetadata: (part as { providerMetadata?: Record<string, unknown> })\n\t\t\t\t.providerMetadata,\n\t\t};\n\t}\n\n\tif (isStepStartPart(part)) {\n\t\treturn {\n\t\t\ttype: \"step-start\",\n\t\t};\n\t}\n\n\tif (isFilePart(part)) {\n\t\t// Support both 'filename' (new) and 'fileName' (legacy) for backward compatibility\n\t\tconst typedPart = part as { filename?: string; fileName?: string };\n\t\treturn {\n\t\t\ttype: \"file\",\n\t\t\turl: part.url,\n\t\t\tmediaType: part.mediaType,\n\t\t\tfilename: typedPart.filename ?? typedPart.fileName,\n\t\t};\n\t}\n\n\tif (isImagePart(part)) {\n\t\t// Convert image to file part (AI SDK uses file for all media)\n\t\t// Support both 'filename' (new) and 'fileName' (legacy) for backward compatibility\n\t\tconst typedPart = part as { filename?: string; fileName?: string };\n\t\treturn {\n\t\t\ttype: \"file\",\n\t\t\turl: part.url,\n\t\t\tmediaType: part.mediaType,\n\t\t\tfilename: typedPart.filename ?? typedPart.fileName,\n\t\t};\n\t}\n\n\tif (isToolPart(part)) {\n\t\tconst typedPart = part as AISDKPartMetadataCarrier;\n\t\tconst metadataCarrier = getMetadataCarrier(typedPart);\n\n\t\treturn {\n\t\t\ttype: part.type as `tool-${string}`,\n\t\t\ttoolCallId: part.toolCallId,\n\t\t\ttoolName: part.toolName,\n\t\t\tinput: part.input,\n\t\t\toutput: (part as { output?: unknown }).output,\n\t\t\tstate: part.state,\n\t\t\terrorText: (part as { errorText?: string }).errorText,\n\t\t\tcallProviderMetadata: metadataCarrier.callProviderMetadata,\n\t\t\tproviderMetadata: metadataCarrier.providerMetadata,\n\t\t};\n\t}\n\n\t// Event and metadata parts are Cossistant-specific, skip for AI SDK\n\tif (isEventPart(part) || isMetadataPart(part)) {\n\t\treturn null;\n\t}\n\n\treturn null;\n}\n\n// ============================================================================\n// CONVERSION: UI MESSAGE -> TIMELINE ITEM\n// ============================================================================\n\n/**\n * Context required to create a TimelineItem from UIMessage\n */\nexport type FromUIMessageContext = {\n\tconversationId: string;\n\torganizationId: string;\n\taiAgentId?: string | null;\n\tuserId?: string | null;\n\tvisitorId?: string | null;\n\tvisibility?: \"public\" | \"private\";\n};\n\n/**\n * Convert an AI SDK UIMessage to Cossistant TimelineItem format\n *\n * @param message - The AI SDK UIMessage to convert\n * @param context - Context for creating the TimelineItem\n * @returns Cossistant TimelineItem\n */\nexport function fromUIMessage(\n\tmessage: CossistantUIMessage,\n\tcontext: FromUIMessageContext\n): TimelineItem {\n\t// Extract metadata if available\n\tconst metadata = message.metadata;\n\n\treturn {\n\t\tid: message.id,\n\t\tconversationId: metadata?.conversationId ?? context.conversationId,\n\t\torganizationId: metadata?.organizationId ?? context.organizationId,\n\t\tvisibility: metadata?.visibility ?? context.visibility ?? \"public\",\n\t\ttype: \"message\",\n\t\ttext: extractTextFromParts(message.parts),\n\t\tparts: message.parts\n\t\t\t.map(fromAISDKPart)\n\t\t\t.filter(Boolean) as TimelineItemParts,\n\t\tuserId: metadata?.userId ?? context.userId ?? null,\n\t\taiAgentId: metadata?.aiAgentId ?? context.aiAgentId ?? null,\n\t\tvisitorId: metadata?.visitorId ?? context.visitorId ?? null,\n\t\tcreatedAt: metadata?.createdAt ?? new Date().toISOString(),\n\t\tdeletedAt: metadata?.deletedAt ?? null,\n\t\ttool: metadata?.tool ?? null,\n\t};\n}\n\n/**\n * Convert multiple UIMessages to TimelineItems\n */\nexport function fromUIMessages(\n\tmessages: CossistantUIMessage[],\n\tcontext: FromUIMessageContext\n): TimelineItem[] {\n\treturn messages.map((msg) => fromUIMessage(msg, context));\n}\n\n/**\n * Extract plain text content from message parts\n */\nfunction extractTextFromParts(parts: unknown[]): string | null {\n\tconst textParts = parts.filter(\n\t\t(part): part is AISDKTextPart =>\n\t\t\ttypeof part === \"object\" &&\n\t\t\tpart !== null &&\n\t\t\t\"type\" in part &&\n\t\t\tpart.type === \"text\"\n\t);\n\n\tif (textParts.length === 0) {\n\t\treturn null;\n\t}\n\treturn textParts.map((p) => p.text).join(\"\\n\");\n}\n\n/**\n * Convert an AI SDK part to Cossistant part format\n */\nfunction fromAISDKPart(part: unknown): CossistantPart | null {\n\tif (typeof part !== \"object\" || part === null || !(\"type\" in part)) {\n\t\treturn null;\n\t}\n\n\tconst typedPart = part as { type: string; [key: string]: unknown };\n\n\tswitch (typedPart.type) {\n\t\tcase \"text\":\n\t\t\treturn {\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext: String(typedPart.text ?? \"\"),\n\t\t\t\tstate: typedPart.state as \"streaming\" | \"done\" | undefined,\n\t\t\t};\n\n\t\tcase \"reasoning\":\n\t\t\treturn {\n\t\t\t\ttype: \"reasoning\",\n\t\t\t\ttext: String(typedPart.text ?? \"\"),\n\t\t\t\tstate: typedPart.state as \"streaming\" | \"done\" | undefined,\n\t\t\t\tproviderMetadata: typedPart.providerMetadata as\n\t\t\t\t\t| Record<string, unknown>\n\t\t\t\t\t| undefined,\n\t\t\t};\n\n\t\tcase \"source-url\":\n\t\t\treturn {\n\t\t\t\ttype: \"source-url\",\n\t\t\t\tsourceId: String(typedPart.sourceId ?? \"\"),\n\t\t\t\turl: String(typedPart.url ?? \"\"),\n\t\t\t\ttitle: typedPart.title as string | undefined,\n\t\t\t\tproviderMetadata: typedPart.providerMetadata as\n\t\t\t\t\t| Record<string, unknown>\n\t\t\t\t\t| undefined,\n\t\t\t};\n\n\t\tcase \"source-document\":\n\t\t\treturn {\n\t\t\t\ttype: \"source-document\",\n\t\t\t\tsourceId: String(typedPart.sourceId ?? \"\"),\n\t\t\t\tmediaType: String(typedPart.mediaType ?? \"\"),\n\t\t\t\ttitle: String(typedPart.title ?? \"\"),\n\t\t\t\tfilename: typedPart.filename as string | undefined,\n\t\t\t\tproviderMetadata: typedPart.providerMetadata as\n\t\t\t\t\t| Record<string, unknown>\n\t\t\t\t\t| undefined,\n\t\t\t};\n\n\t\tcase \"step-start\":\n\t\t\treturn {\n\t\t\t\ttype: \"step-start\",\n\t\t\t};\n\n\t\tcase \"file\":\n\t\t\treturn {\n\t\t\t\ttype: \"file\",\n\t\t\t\turl: String(typedPart.url ?? \"\"),\n\t\t\t\tmediaType: String(typedPart.mediaType ?? \"\"),\n\t\t\t\tfilename: typedPart.filename as string | undefined,\n\t\t\t};\n\n\t\tdefault:\n\t\t\t// Handle tool-* pattern\n\t\t\tif (typedPart.type.startsWith(\"tool-\")) {\n\t\t\t\tconst metadataCarrier = getMetadataCarrier({\n\t\t\t\t\tcallProviderMetadata: typedPart.callProviderMetadata as\n\t\t\t\t\t\t| Record<string, unknown>\n\t\t\t\t\t\t| undefined,\n\t\t\t\t\tproviderMetadata: typedPart.providerMetadata as\n\t\t\t\t\t\t| Record<string, unknown>\n\t\t\t\t\t\t| undefined,\n\t\t\t\t});\n\n\t\t\t\treturn {\n\t\t\t\t\ttype: typedPart.type,\n\t\t\t\t\ttoolCallId: String(typedPart.toolCallId ?? \"\"),\n\t\t\t\t\ttoolName: String(typedPart.toolName ?? \"\"),\n\t\t\t\t\tinput: (typedPart.input as Record<string, unknown>) ?? {},\n\t\t\t\t\toutput: typedPart.output,\n\t\t\t\t\tstate:\n\t\t\t\t\t\t(typedPart.state as \"partial\" | \"result\" | \"error\") ?? \"partial\",\n\t\t\t\t\terrorText: typedPart.errorText as string | undefined,\n\t\t\t\t\tcallProviderMetadata: metadataCarrier.callProviderMetadata,\n\t\t\t\t\tproviderMetadata: metadataCarrier.providerMetadata,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn null;\n\t}\n}\n\n// ============================================================================\n// HELPER UTILITIES\n// ============================================================================\n\n/**\n * Check if a part is an AI SDK compatible part type\n */\nexport function isAISDKCompatiblePart(part: CossistantPart): boolean {\n\tif (part.type === \"event\" || part.type === \"metadata\") {\n\t\treturn false;\n\t}\n\treturn true;\n}\n\n/**\n * Extract all sources from a message's parts\n */\nexport function extractSources(\n\tparts: AISDKPart[]\n): (AISDKSourceUrlPart | AISDKSourceDocumentPart)[] {\n\treturn parts.filter(\n\t\t(part): part is AISDKSourceUrlPart | AISDKSourceDocumentPart =>\n\t\t\tpart.type === \"source-url\" || part.type === \"source-document\"\n\t);\n}\n\n/**\n * Extract all tool calls from a message's parts\n */\nexport function extractToolCalls(parts: AISDKPart[]): AISDKToolPart[] {\n\treturn parts.filter(\n\t\t(part): part is AISDKToolPart =>\n\t\t\ttypeof part.type === \"string\" && part.type.startsWith(\"tool-\")\n\t);\n}\n\n/**\n * Check if any parts are still processing\n */\nexport function hasProcessingParts(parts: AISDKPart[]): boolean {\n\treturn parts.some((part) => {\n\t\tif (\n\t\t\t\"state\" in part &&\n\t\t\t(part.state === \"streaming\" || part.state === \"partial\")\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t});\n}\n"],"mappings":";AAwIA,SAAS,SAAS,OAAkD;AACnE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;;AAG5E,SAAS,mBACR,MAC2B;AAK3B,QAAO;EACN,sBAJA,KAAK,wBAAwB,KAAK;EAKlC,kBAJwB,KAAK,oBAAoB,KAAK;EAKtD;;;;;;AAOF,SAAgB,0BACf,MACqC;CACrC,MAAM,EAAE,sBAAsB,qBAAqB,mBAAmB,KAAK;CAC3E,MAAM,WAAW,wBAAwB;AAEzC,KAAI,CAAC,SAAS,SAAS,CACtB;CAGD,MAAM,aAAa,SAAS;AAC5B,KAAI,CAAC,SAAS,WAAW,CACxB;AAGD,QAAO;;;;;;AAOR,SAAgB,0BACf,MACA,UAC2B;CAC3B,MAAM,EAAE,sBAAsB,qBAAqB,mBAAmB,KAAK;AAU3E,QAAO;EACN,sBAVgC;GAChC,GAAI,SAAS,qBAAqB,GAAG,uBAAuB,EAAE;GAC9D,YAAY;GACZ;EAQA,kBAP4B;GAC5B,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;;;AAMF,SAAgB,iBAAiB,OAAqC;AACrE,QAAO,MAAM,QACX,SACA,OAAO,KAAK,SAAS,YAAY,KAAK,KAAK,WAAW,QAAQ,CAC/D;;;;;AAMF,SAAgB,mBAAmB,OAA6B;AAC/D,QAAO,MAAM,MAAM,SAAS;AAC3B,MACC,WAAW,SACV,KAAK,UAAU,eAAe,KAAK,UAAU,WAE9C,QAAO;AAER,SAAO;GACN"}
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AISDKFilePart, AISDKPart, AISDKReasoningPart, AISDKSourceDocumentPart, AISDKSourceUrlPart, AISDKStepStartPart, AISDKTextPart, AISDKToolPart, CossistantMessageMetadata, CossistantPartMetadata, CossistantUIMessage, FromUIMessageContext, extractSources, extractToolCalls, fromUIMessage, fromUIMessages, hasProcessingParts, isAISDKCompatiblePart, toUIMessage, toUIMessages } from "./ai-sdk-utils.js";
|
|
1
|
+
import { AISDKFilePart, AISDKPart, AISDKReasoningPart, AISDKSourceDocumentPart, AISDKSourceUrlPart, AISDKStepStartPart, AISDKTextPart, AISDKToolPart, CossistantMessageMetadata, CossistantPartMetadata, CossistantToolTimelineMetadata, CossistantUIMessage, FromUIMessageContext, extractSources, extractToolCalls, fromUIMessage, fromUIMessages, getCossistantPartMetadata, getCossistantToolTimelineMetadata, hasProcessingParts, isAISDKCompatiblePart, setCossistantPartMetadata, setCossistantToolTimelineMetadata, toUIMessage, toUIMessages } from "./ai-sdk-utils.js";
|
|
2
2
|
import { CossistantAPIError } from "./types.js";
|
|
3
3
|
import { CossistantRestClient } from "./rest-client.js";
|
|
4
4
|
import { ConversationPagination, ConversationWithSeen, ConversationsState, ConversationsStore, createConversationsStore, getConversationById, getConversationPagination, getConversations } from "./store/conversations-store.js";
|
|
@@ -17,4 +17,4 @@ import { VisitorData, collectVisitorData } from "./visitor-data.js";
|
|
|
17
17
|
import { generateVisitorName, getVisitorNameWithFallback } from "./visitor-name.js";
|
|
18
18
|
import { clearAllVisitorIds, clearVisitorId, getVisitorId, setVisitorId } from "./visitor-tracker.js";
|
|
19
19
|
import { CossistantConfig, CossistantError } from "@cossistant/types";
|
|
20
|
-
export { type AISDKFilePart, type AISDKPart, type AISDKReasoningPart, type AISDKSourceDocumentPart, type AISDKSourceUrlPart, type AISDKStepStartPart, type AISDKTextPart, type AISDKToolPart, ALLOWED_FILE_TYPES_DESCRIPTION, ALLOWED_MIME_TYPES, type Audience, type ConversationPagination, type ConversationSeenState, type ConversationTimelineItemsState, type ConversationTypingState, type ConversationWithSeen, type ConversationsState, type ConversationsStore, CossistantAPIError, CossistantClient, type CossistantConfig, type CossistantError, type CossistantMessageMetadata, type CossistantPartMetadata, CossistantRestClient, type CossistantUIMessage, type DefaultRoutes, FILE_INPUT_ACCEPT, type FilterOptions, type FromUIMessageContext, MAX_FILES_PER_MESSAGE, MAX_FILE_SIZE, type NavigationState, PrivacyPresets, type RouteRegistry, type SUPPORT_PAGES, type SeenActorType, type SeenEntry, type SeenState, type SeenStore, type SupportConfig, type SupportNavigation, type SupportPage, type SupportStore, type SupportStoreActions, type SupportStoreOptions, type SupportStoreState, type SupportStoreStorage, TYPING_KEEP_ALIVE_MS, TYPING_PREVIEW_MAX_LENGTH, TYPING_SEND_INTERVAL_MS, TYPING_STOP_DELAY_MS, type TimelineItemsState, type TimelineItemsStore, type TypingActorType, type TypingEntry, type TypingReporter, type TypingReporterConfig, type TypingState, type TypingStore, type TypingStoreDependencies, type VisitorData, type WebsiteError, type WebsiteState, type WebsiteStatus, type WebsiteStore, applyConversationSeenEvent, applyConversationTypingEvent, clearAllVisitorIds, clearTypingFromTimelineItem, clearTypingState, clearVisitorId, collectVisitorData, countVisibleParts, createConversationsStore, createSeenStore, createSupportStore, createTimelineItemsStore, createTypingReporter, createTypingStore, createWebsiteStore, CossistantClient as default, extractSources, extractToolCalls, extractVisibleText, filterMessageForAudience, filterMessagesForAudience, filterTimelineItemForAudience, filterTimelineItemsForAudience, formatFileSize, fromUIMessage, fromUIMessages, generateConversationId, generateMessageId, generateVisitorName, getConversationById, getConversationPagination, getConversationTimelineItems, getConversationTyping, getConversations, getVisitorId, getVisitorNameWithFallback, getWebsiteState, hasProcessingParts, hasVisibleContent, hydrateConversationSeen, isAISDKCompatiblePart, isAllowedMimeType, isImageMimeType, normalizeLocale, setTypingState, setVisitorId, toUIMessage, toUIMessages, upsertConversationSeen, validateFile, validateFiles };
|
|
20
|
+
export { type AISDKFilePart, type AISDKPart, type AISDKReasoningPart, type AISDKSourceDocumentPart, type AISDKSourceUrlPart, type AISDKStepStartPart, type AISDKTextPart, type AISDKToolPart, ALLOWED_FILE_TYPES_DESCRIPTION, ALLOWED_MIME_TYPES, type Audience, type ConversationPagination, type ConversationSeenState, type ConversationTimelineItemsState, type ConversationTypingState, type ConversationWithSeen, type ConversationsState, type ConversationsStore, CossistantAPIError, CossistantClient, type CossistantConfig, type CossistantError, type CossistantMessageMetadata, type CossistantPartMetadata, CossistantRestClient, type CossistantToolTimelineMetadata, type CossistantUIMessage, type DefaultRoutes, FILE_INPUT_ACCEPT, type FilterOptions, type FromUIMessageContext, MAX_FILES_PER_MESSAGE, MAX_FILE_SIZE, type NavigationState, PrivacyPresets, type RouteRegistry, type SUPPORT_PAGES, type SeenActorType, type SeenEntry, type SeenState, type SeenStore, type SupportConfig, type SupportNavigation, type SupportPage, type SupportStore, type SupportStoreActions, type SupportStoreOptions, type SupportStoreState, type SupportStoreStorage, TYPING_KEEP_ALIVE_MS, TYPING_PREVIEW_MAX_LENGTH, TYPING_SEND_INTERVAL_MS, TYPING_STOP_DELAY_MS, type TimelineItemsState, type TimelineItemsStore, type TypingActorType, type TypingEntry, type TypingReporter, type TypingReporterConfig, type TypingState, type TypingStore, type TypingStoreDependencies, type VisitorData, type WebsiteError, type WebsiteState, type WebsiteStatus, type WebsiteStore, applyConversationSeenEvent, applyConversationTypingEvent, clearAllVisitorIds, clearTypingFromTimelineItem, clearTypingState, clearVisitorId, collectVisitorData, countVisibleParts, createConversationsStore, createSeenStore, createSupportStore, createTimelineItemsStore, createTypingReporter, createTypingStore, createWebsiteStore, CossistantClient as default, extractSources, extractToolCalls, extractVisibleText, filterMessageForAudience, filterMessagesForAudience, filterTimelineItemForAudience, filterTimelineItemsForAudience, formatFileSize, fromUIMessage, fromUIMessages, generateConversationId, generateMessageId, generateVisitorName, getConversationById, getConversationPagination, getConversationTimelineItems, getConversationTyping, getConversations, getCossistantPartMetadata, getCossistantToolTimelineMetadata, getVisitorId, getVisitorNameWithFallback, getWebsiteState, hasProcessingParts, hasVisibleContent, hydrateConversationSeen, isAISDKCompatiblePart, isAllowedMimeType, isImageMimeType, normalizeLocale, setCossistantPartMetadata, setCossistantToolTimelineMetadata, setTypingState, setVisitorId, toUIMessage, toUIMessages, upsertConversationSeen, validateFile, validateFiles };
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { extractSources, extractToolCalls, fromUIMessage, fromUIMessages, hasProcessingParts, isAISDKCompatiblePart, toUIMessage, toUIMessages } from "./ai-sdk-utils.js";
|
|
1
|
+
import { extractSources, extractToolCalls, fromUIMessage, fromUIMessages, getCossistantPartMetadata, getCossistantToolTimelineMetadata, hasProcessingParts, isAISDKCompatiblePart, setCossistantPartMetadata, setCossistantToolTimelineMetadata, toUIMessage, toUIMessages } from "./ai-sdk-utils.js";
|
|
2
2
|
import { CossistantAPIError } from "./types.js";
|
|
3
3
|
import { ALLOWED_FILE_TYPES_DESCRIPTION, ALLOWED_MIME_TYPES, FILE_INPUT_ACCEPT, MAX_FILES_PER_MESSAGE, MAX_FILE_SIZE, formatFileSize, isAllowedMimeType, isImageMimeType, validateFile, validateFiles } from "./upload-constants.js";
|
|
4
4
|
import { generateConversationId, generateMessageId } from "./utils.js";
|
|
@@ -17,4 +17,4 @@ import { applyConversationTypingEvent, clearTypingFromTimelineItem, clearTypingS
|
|
|
17
17
|
import { TYPING_KEEP_ALIVE_MS, TYPING_PREVIEW_MAX_LENGTH, TYPING_SEND_INTERVAL_MS, TYPING_STOP_DELAY_MS, createTypingReporter } from "./typing-reporter.js";
|
|
18
18
|
import { generateVisitorName, getVisitorNameWithFallback } from "./visitor-name.js";
|
|
19
19
|
|
|
20
|
-
export { ALLOWED_FILE_TYPES_DESCRIPTION, ALLOWED_MIME_TYPES, CossistantAPIError, CossistantClient, CossistantRestClient, FILE_INPUT_ACCEPT, MAX_FILES_PER_MESSAGE, MAX_FILE_SIZE, PrivacyPresets, TYPING_KEEP_ALIVE_MS, TYPING_PREVIEW_MAX_LENGTH, TYPING_SEND_INTERVAL_MS, TYPING_STOP_DELAY_MS, applyConversationSeenEvent, applyConversationTypingEvent, clearAllVisitorIds, clearTypingFromTimelineItem, clearTypingState, clearVisitorId, collectVisitorData, countVisibleParts, createConversationsStore, createSeenStore, createSupportStore, createTimelineItemsStore, createTypingReporter, createTypingStore, createWebsiteStore, CossistantClient as default, extractSources, extractToolCalls, extractVisibleText, filterMessageForAudience, filterMessagesForAudience, filterTimelineItemForAudience, filterTimelineItemsForAudience, formatFileSize, fromUIMessage, fromUIMessages, generateConversationId, generateMessageId, generateVisitorName, getConversationById, getConversationPagination, getConversationTimelineItems, getConversationTyping, getConversations, getVisitorId, getVisitorNameWithFallback, getWebsiteState, hasProcessingParts, hasVisibleContent, hydrateConversationSeen, isAISDKCompatiblePart, isAllowedMimeType, isImageMimeType, normalizeLocale, setTypingState, setVisitorId, toUIMessage, toUIMessages, upsertConversationSeen, validateFile, validateFiles };
|
|
20
|
+
export { ALLOWED_FILE_TYPES_DESCRIPTION, ALLOWED_MIME_TYPES, CossistantAPIError, CossistantClient, CossistantRestClient, FILE_INPUT_ACCEPT, MAX_FILES_PER_MESSAGE, MAX_FILE_SIZE, PrivacyPresets, TYPING_KEEP_ALIVE_MS, TYPING_PREVIEW_MAX_LENGTH, TYPING_SEND_INTERVAL_MS, TYPING_STOP_DELAY_MS, applyConversationSeenEvent, applyConversationTypingEvent, clearAllVisitorIds, clearTypingFromTimelineItem, clearTypingState, clearVisitorId, collectVisitorData, countVisibleParts, createConversationsStore, createSeenStore, createSupportStore, createTimelineItemsStore, createTypingReporter, createTypingStore, createWebsiteStore, CossistantClient as default, extractSources, extractToolCalls, extractVisibleText, filterMessageForAudience, filterMessagesForAudience, filterTimelineItemForAudience, filterTimelineItemsForAudience, formatFileSize, fromUIMessage, fromUIMessages, generateConversationId, generateMessageId, generateVisitorName, getConversationById, getConversationPagination, getConversationTimelineItems, getConversationTyping, getConversations, getCossistantPartMetadata, getCossistantToolTimelineMetadata, getVisitorId, getVisitorNameWithFallback, getWebsiteState, hasProcessingParts, hasVisibleContent, hydrateConversationSeen, isAISDKCompatiblePart, isAllowedMimeType, isImageMimeType, normalizeLocale, setCossistantPartMetadata, setCossistantToolTimelineMetadata, setTypingState, setVisitorId, toUIMessage, toUIMessages, upsertConversationSeen, validateFile, validateFiles };
|
package/package.json
CHANGED
package/privacy-filter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"privacy-filter.d.ts","names":[],"sources":["../src/privacy-filter.ts"],"sourcesContent":[],"mappings":";;;;;;AAiHA;;AAEW,KA3FC,QAAA,GA2FD,WAAA,GAAA,QAAA;;;;AAoBK,KA1GJ,aAAA,GA0GI;EACT;;;;EAGQ,gBAAA,CAAA,EAAA,OAAA;EAgCC;;;;EAIb,YAAA,CAAA,EAAA,OAAA;EAAY;
|
|
1
|
+
{"version":3,"file":"privacy-filter.d.ts","names":[],"sources":["../src/privacy-filter.ts"],"sourcesContent":[],"mappings":";;;;;;AAiHA;;AAEW,KA3FC,QAAA,GA2FD,WAAA,GAAA,QAAA;;;;AAoBK,KA1GJ,aAAA,GA0GI;EACT;;;;EAGQ,gBAAA,CAAA,EAAA,OAAA;EAgCC;;;;EAIb,YAAA,CAAA,EAAA,OAAA;EAAY;AAyIf;AAuCA;;EAEW,cAAA,CAAA,EAAA,OAAA;CACA;;AAQX;;;;;AAYA;;iBAzSgB,wBAAA,UACN,+BACC,oBACA,gBACR;;;;;;;;;iBAgCa,yBAAA,WACL,iCACA,oBACA,gBACR;;;;;;;;;iBAkBa,6BAAA,OACT,wBACI,oBACA,gBACR;;;;;;;;;iBAgCa,8BAAA,QACR,0BACG,oBACA,gBACR;;;;cAyIU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuCG,iBAAA,UACN,+BACC,oBACA;;;;iBAQK,iBAAA,UACN,+BACC,oBACA;;;;iBASK,kBAAA,UACN,+BACC"}
|
package/privacy-filter.js
CHANGED
|
@@ -112,14 +112,19 @@ function shouldIncludeTimelineItemPart(part, audience, opts) {
|
|
|
112
112
|
* Extract visibility from an AI SDK part's providerMetadata
|
|
113
113
|
*/
|
|
114
114
|
function getPartVisibility(part) {
|
|
115
|
-
|
|
115
|
+
const metadataCarrier = part;
|
|
116
|
+
const metadata = metadataCarrier.callProviderMetadata ?? metadataCarrier.providerMetadata;
|
|
117
|
+
if (metadata) return metadata.cossistant?.visibility ?? "public";
|
|
116
118
|
return "public";
|
|
117
119
|
}
|
|
118
120
|
/**
|
|
119
121
|
* Extract visibility from a TimelineItem part's providerMetadata
|
|
120
122
|
*/
|
|
121
123
|
function getTimelineItemPartVisibility(part) {
|
|
122
|
-
if ("providerMetadata" in part
|
|
124
|
+
if ("providerMetadata" in part || "callProviderMetadata" in part) {
|
|
125
|
+
const typedPart = part;
|
|
126
|
+
return typedPart.callProviderMetadata?.cossistant?.visibility ?? typedPart.providerMetadata?.cossistant?.visibility ?? "public";
|
|
127
|
+
}
|
|
123
128
|
return "public";
|
|
124
129
|
}
|
|
125
130
|
/**
|
package/privacy-filter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"privacy-filter.js","names":["DEFAULT_OPTIONS: Record<Audience, Required<FilterOptions>>"],"sources":["../src/privacy-filter.ts"],"sourcesContent":["/**\n * Privacy Filter Utilities\n *\n * This module provides utilities for filtering timeline items and parts\n * based on audience (dashboard vs widget). The dashboard sees everything,\n * while the widget only sees public content.\n *\n * Filtering happens at the API layer, not baked into types.\n */\n\nimport type { TimelineItem, TimelineItemParts } from \"@cossistant/types\";\nimport type {\n\tAISDKPart,\n\tCossistantPartMetadata,\n\tCossistantUIMessage,\n} from \"./ai-sdk-utils\";\n\n// ============================================================================\n// TYPES\n// ============================================================================\n\n/**\n * Audience types for filtering\n */\nexport type Audience = \"dashboard\" | \"widget\";\n\n/**\n * Privacy filter options\n */\nexport type FilterOptions = {\n\t/**\n\t * Whether to include reasoning parts (AI chain-of-thought)\n\t * Default: true for dashboard, false for widget\n\t */\n\tincludeReasoning?: boolean;\n\n\t/**\n\t * Whether to include tool parts\n\t * Default: true for dashboard, based on visibility for widget\n\t */\n\tincludeTools?: boolean;\n\n\t/**\n\t * Whether to include source attributions\n\t * Default: true\n\t */\n\tincludeSources?: boolean;\n};\n\n/**\n * Default filter options for each audience\n */\nconst DEFAULT_OPTIONS: Record<Audience, Required<FilterOptions>> = {\n\tdashboard: {\n\t\tincludeReasoning: true,\n\t\tincludeTools: true,\n\t\tincludeSources: true,\n\t},\n\twidget: {\n\t\tincludeReasoning: false,\n\t\tincludeTools: true, // but filtered by visibility\n\t\tincludeSources: true,\n\t},\n};\n\n// ============================================================================\n// COSSISTANT UI MESSAGE FILTERING\n// ============================================================================\n\n/**\n * Filter a CossistantUIMessage for a specific audience\n *\n * @param message - The message to filter\n * @param audience - The target audience ('dashboard' or 'widget')\n * @param options - Optional filter options\n * @returns The filtered message, or null if the entire message should be hidden\n */\nexport function filterMessageForAudience(\n\tmessage: CossistantUIMessage,\n\taudience: Audience,\n\toptions?: FilterOptions\n): CossistantUIMessage | null {\n\tconst opts = { ...DEFAULT_OPTIONS[audience], ...options };\n\n\t// Widget can't see private messages\n\tif (audience === \"widget\" && message.metadata.visibility === \"private\") {\n\t\treturn null;\n\t}\n\n\t// Filter parts based on audience\n\tconst filteredParts = message.parts.filter((part) =>\n\t\tshouldIncludePart(part, audience, opts)\n\t);\n\n\t// If no parts remain, return null (empty message)\n\tif (filteredParts.length === 0) {\n\t\treturn null;\n\t}\n\n\treturn {\n\t\t...message,\n\t\tparts: filteredParts,\n\t};\n}\n\n/**\n * Filter multiple messages for an audience\n *\n * @param messages - The messages to filter\n * @param audience - The target audience\n * @param options - Optional filter options\n * @returns Filtered messages (excluding any that become null)\n */\nexport function filterMessagesForAudience(\n\tmessages: CossistantUIMessage[],\n\taudience: Audience,\n\toptions?: FilterOptions\n): CossistantUIMessage[] {\n\treturn messages\n\t\t.map((msg) => filterMessageForAudience(msg, audience, options))\n\t\t.filter((msg): msg is CossistantUIMessage => msg !== null);\n}\n\n// ============================================================================\n// TIMELINE ITEM FILTERING (Direct, without conversion)\n// ============================================================================\n\n/**\n * Filter a TimelineItem for a specific audience\n *\n * @param item - The timeline item to filter\n * @param audience - The target audience\n * @param options - Optional filter options\n * @returns The filtered item, or null if the entire item should be hidden\n */\nexport function filterTimelineItemForAudience(\n\titem: TimelineItem,\n\taudience: Audience,\n\toptions?: FilterOptions\n): TimelineItem | null {\n\tconst opts = { ...DEFAULT_OPTIONS[audience], ...options };\n\n\t// Widget can't see private items\n\tif (audience === \"widget\" && item.visibility === \"private\") {\n\t\treturn null;\n\t}\n\n\t// Filter parts based on audience\n\tconst filteredParts = item.parts.filter((part) =>\n\t\tshouldIncludeTimelineItemPart(part, audience, opts)\n\t);\n\n\t// If no parts remain, return null (empty item)\n\tif (filteredParts.length === 0) {\n\t\treturn null;\n\t}\n\n\treturn {\n\t\t...item,\n\t\tparts: filteredParts as TimelineItemParts,\n\t};\n}\n\n/**\n * Filter multiple timeline items for an audience\n *\n * @param items - The timeline items to filter\n * @param audience - The target audience\n * @param options - Optional filter options\n * @returns Filtered items (excluding any that become null)\n */\nexport function filterTimelineItemsForAudience(\n\titems: TimelineItem[],\n\taudience: Audience,\n\toptions?: FilterOptions\n): TimelineItem[] {\n\treturn items\n\t\t.map((item) => filterTimelineItemForAudience(item, audience, options))\n\t\t.filter((item): item is TimelineItem => item !== null);\n}\n\n// ============================================================================\n// PART-LEVEL FILTERING\n// ============================================================================\n\n/**\n * Determine if an AI SDK part should be included based on audience and options\n */\nfunction shouldIncludePart(\n\tpart: AISDKPart,\n\taudience: Audience,\n\topts: Required<FilterOptions>\n): boolean {\n\t// Check part visibility from providerMetadata\n\tconst visibility = getPartVisibility(part);\n\tif (audience === \"widget\" && visibility === \"private\") {\n\t\treturn false;\n\t}\n\n\t// Handle reasoning parts\n\tif (part.type === \"reasoning\") {\n\t\treturn opts.includeReasoning;\n\t}\n\n\t// Handle tool parts\n\tif (typeof part.type === \"string\" && part.type.startsWith(\"tool-\")) {\n\t\tif (!opts.includeTools) {\n\t\t\treturn false;\n\t\t}\n\t\t// For widget, check if the tool part is marked as public\n\t\tif (audience === \"widget\" && visibility !== \"public\") {\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Handle source parts\n\tif (part.type === \"source-url\" || part.type === \"source-document\") {\n\t\treturn opts.includeSources;\n\t}\n\n\t// Include all other parts by default\n\treturn true;\n}\n\n/**\n * Determine if a TimelineItem part should be included based on audience and options\n */\nfunction shouldIncludeTimelineItemPart(\n\tpart: TimelineItemParts[number],\n\taudience: Audience,\n\topts: Required<FilterOptions>\n): boolean {\n\t// Check part visibility from providerMetadata\n\tconst visibility = getTimelineItemPartVisibility(part);\n\tif (audience === \"widget\" && visibility === \"private\") {\n\t\treturn false;\n\t}\n\n\t// Handle reasoning parts\n\tif (part.type === \"reasoning\") {\n\t\treturn opts.includeReasoning;\n\t}\n\n\t// Handle tool parts\n\tif (typeof part.type === \"string\" && part.type.startsWith(\"tool-\")) {\n\t\tif (!opts.includeTools) {\n\t\t\treturn false;\n\t\t}\n\t\t// For widget, check if the tool part is marked as public\n\t\tif (audience === \"widget\" && visibility !== \"public\") {\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Handle source parts\n\tif (part.type === \"source-url\" || part.type === \"source-document\") {\n\t\treturn opts.includeSources;\n\t}\n\n\t// Include all other parts by default\n\treturn true;\n}\n\n/**\n * Extract visibility from an AI SDK part's providerMetadata\n */\nfunction getPartVisibility(part: AISDKPart): \"public\" | \"private\" {\n\tif (\"providerMetadata\" in part && part.providerMetadata) {\n\t\tconst metadata = part.providerMetadata as {\n\t\t\tcossistant?: CossistantPartMetadata;\n\t\t};\n\t\treturn metadata.cossistant?.visibility ?? \"public\";\n\t}\n\treturn \"public\";\n}\n\n/**\n * Extract visibility from a TimelineItem part's providerMetadata\n */\nfunction getTimelineItemPartVisibility(\n\tpart: TimelineItemParts[number]\n): \"public\" | \"private\" {\n\tif (\"providerMetadata\" in part) {\n\t\tconst typedPart = part as {\n\t\t\tproviderMetadata?: { cossistant?: CossistantPartMetadata };\n\t\t};\n\t\treturn typedPart.providerMetadata?.cossistant?.visibility ?? \"public\";\n\t}\n\treturn \"public\";\n}\n\n// ============================================================================\n// PRIVACY PRESETS\n// ============================================================================\n\n/**\n * Privacy presets for common use cases\n */\nexport const PrivacyPresets = {\n\t/**\n\t * TRANSPARENT: Show everything including AI reasoning\n\t * Use for: Internal debugging, transparency-focused products\n\t */\n\tTRANSPARENT: {\n\t\tincludeReasoning: true,\n\t\tincludeTools: true,\n\t\tincludeSources: true,\n\t} satisfies FilterOptions,\n\n\t/**\n\t * STANDARD: Default widget experience\n\t * Use for: Most customer-facing widgets\n\t */\n\tSTANDARD: {\n\t\tincludeReasoning: false,\n\t\tincludeTools: true,\n\t\tincludeSources: true,\n\t} satisfies FilterOptions,\n\n\t/**\n\t * MINIMAL: Only show text responses\n\t * Use for: Simple chatbots, text-only experiences\n\t */\n\tMINIMAL: {\n\t\tincludeReasoning: false,\n\t\tincludeTools: false,\n\t\tincludeSources: false,\n\t} satisfies FilterOptions,\n} as const;\n\n// ============================================================================\n// UTILITY FUNCTIONS\n// ============================================================================\n\n/**\n * Check if a message has any visible content for an audience\n */\nexport function hasVisibleContent(\n\tmessage: CossistantUIMessage,\n\taudience: Audience,\n\toptions?: FilterOptions\n): boolean {\n\treturn filterMessageForAudience(message, audience, options) !== null;\n}\n\n/**\n * Count visible parts for an audience\n */\nexport function countVisibleParts(\n\tmessage: CossistantUIMessage,\n\taudience: Audience,\n\toptions?: FilterOptions\n): number {\n\tconst filtered = filterMessageForAudience(message, audience, options);\n\treturn filtered?.parts.length ?? 0;\n}\n\n/**\n * Extract only text content from a message (for previews, notifications, etc.)\n */\nexport function extractVisibleText(\n\tmessage: CossistantUIMessage,\n\taudience: Audience\n): string | null {\n\tconst filtered = filterMessageForAudience(message, audience);\n\tif (!filtered) {\n\t\treturn null;\n\t}\n\n\tconst textParts = filtered.parts.filter(\n\t\t(part): part is { type: \"text\"; text: string } => part.type === \"text\"\n\t);\n\n\tif (textParts.length === 0) {\n\t\treturn null;\n\t}\n\treturn textParts.map((p) => p.text).join(\"\\n\");\n}\n"],"mappings":";;;;AAoDA,MAAMA,kBAA6D;CAClE,WAAW;EACV,kBAAkB;EAClB,cAAc;EACd,gBAAgB;EAChB;CACD,QAAQ;EACP,kBAAkB;EAClB,cAAc;EACd,gBAAgB;EAChB;CACD;;;;;;;;;AAcD,SAAgB,yBACf,SACA,UACA,SAC6B;CAC7B,MAAM,OAAO;EAAE,GAAG,gBAAgB;EAAW,GAAG;EAAS;AAGzD,KAAI,aAAa,YAAY,QAAQ,SAAS,eAAe,UAC5D,QAAO;CAIR,MAAM,gBAAgB,QAAQ,MAAM,QAAQ,SAC3C,kBAAkB,MAAM,UAAU,KAAK,CACvC;AAGD,KAAI,cAAc,WAAW,EAC5B,QAAO;AAGR,QAAO;EACN,GAAG;EACH,OAAO;EACP;;;;;;;;;;AAWF,SAAgB,0BACf,UACA,UACA,SACwB;AACxB,QAAO,SACL,KAAK,QAAQ,yBAAyB,KAAK,UAAU,QAAQ,CAAC,CAC9D,QAAQ,QAAoC,QAAQ,KAAK;;;;;;;;;;AAe5D,SAAgB,8BACf,MACA,UACA,SACsB;CACtB,MAAM,OAAO;EAAE,GAAG,gBAAgB;EAAW,GAAG;EAAS;AAGzD,KAAI,aAAa,Y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MR,SAAS,8BACR,MACuB;AACvB,KAAI,sBAAsB,KAIzB,QAHkB,KAGD,kBAAkB,YAAY,cAAc;AAE9D,QAAO;;;;;AAUR,MAAa,iBAAiB;CAK7B,aAAa;EACZ,kBAAkB;EAClB,cAAc;EACd,gBAAgB;EAChB;CAMD,UAAU;EACT,kBAAkB;EAClB,cAAc;EACd,gBAAgB;EAChB;CAMD,SAAS;EACR,kBAAkB;EAClB,cAAc;EACd,gBAAgB;EAChB;CACD;;;;AASD,SAAgB,kBACf,SACA,UACA,SACU;AACV,QAAO,yBAAyB,SAAS,UAAU,QAAQ,KAAK;;;;;AAMjE,SAAgB,kBACf,SACA,UACA,SACS;AAET,QADiB,yBAAyB,SAAS,UAAU,QAAQ,EACpD,MAAM,UAAU;;;;;AAMlC,SAAgB,mBACf,SACA,UACgB;CAChB,MAAM,WAAW,yBAAyB,SAAS,SAAS;AAC5D,KAAI,CAAC,SACJ,QAAO;CAGR,MAAM,YAAY,SAAS,MAAM,QAC/B,SAAiD,KAAK,SAAS,OAChE;AAED,KAAI,UAAU,WAAW,EACxB,QAAO;AAER,QAAO,UAAU,KAAK,MAAM,EAAE,KAAK,CAAC,KAAK,KAAK"}
|
|
1
|
+
{"version":3,"file":"privacy-filter.js","names":["DEFAULT_OPTIONS: Record<Audience, Required<FilterOptions>>"],"sources":["../src/privacy-filter.ts"],"sourcesContent":["/**\n * Privacy Filter Utilities\n *\n * This module provides utilities for filtering timeline items and parts\n * based on audience (dashboard vs widget). The dashboard sees everything,\n * while the widget only sees public content.\n *\n * Filtering happens at the API layer, not baked into types.\n */\n\nimport type { TimelineItem, TimelineItemParts } from \"@cossistant/types\";\nimport type {\n\tAISDKPart,\n\tCossistantPartMetadata,\n\tCossistantUIMessage,\n} from \"./ai-sdk-utils\";\n\n// ============================================================================\n// TYPES\n// ============================================================================\n\n/**\n * Audience types for filtering\n */\nexport type Audience = \"dashboard\" | \"widget\";\n\n/**\n * Privacy filter options\n */\nexport type FilterOptions = {\n\t/**\n\t * Whether to include reasoning parts (AI chain-of-thought)\n\t * Default: true for dashboard, false for widget\n\t */\n\tincludeReasoning?: boolean;\n\n\t/**\n\t * Whether to include tool parts\n\t * Default: true for dashboard, based on visibility for widget\n\t */\n\tincludeTools?: boolean;\n\n\t/**\n\t * Whether to include source attributions\n\t * Default: true\n\t */\n\tincludeSources?: boolean;\n};\n\n/**\n * Default filter options for each audience\n */\nconst DEFAULT_OPTIONS: Record<Audience, Required<FilterOptions>> = {\n\tdashboard: {\n\t\tincludeReasoning: true,\n\t\tincludeTools: true,\n\t\tincludeSources: true,\n\t},\n\twidget: {\n\t\tincludeReasoning: false,\n\t\tincludeTools: true, // but filtered by visibility\n\t\tincludeSources: true,\n\t},\n};\n\n// ============================================================================\n// COSSISTANT UI MESSAGE FILTERING\n// ============================================================================\n\n/**\n * Filter a CossistantUIMessage for a specific audience\n *\n * @param message - The message to filter\n * @param audience - The target audience ('dashboard' or 'widget')\n * @param options - Optional filter options\n * @returns The filtered message, or null if the entire message should be hidden\n */\nexport function filterMessageForAudience(\n\tmessage: CossistantUIMessage,\n\taudience: Audience,\n\toptions?: FilterOptions\n): CossistantUIMessage | null {\n\tconst opts = { ...DEFAULT_OPTIONS[audience], ...options };\n\n\t// Widget can't see private messages\n\tif (audience === \"widget\" && message.metadata.visibility === \"private\") {\n\t\treturn null;\n\t}\n\n\t// Filter parts based on audience\n\tconst filteredParts = message.parts.filter((part) =>\n\t\tshouldIncludePart(part, audience, opts)\n\t);\n\n\t// If no parts remain, return null (empty message)\n\tif (filteredParts.length === 0) {\n\t\treturn null;\n\t}\n\n\treturn {\n\t\t...message,\n\t\tparts: filteredParts,\n\t};\n}\n\n/**\n * Filter multiple messages for an audience\n *\n * @param messages - The messages to filter\n * @param audience - The target audience\n * @param options - Optional filter options\n * @returns Filtered messages (excluding any that become null)\n */\nexport function filterMessagesForAudience(\n\tmessages: CossistantUIMessage[],\n\taudience: Audience,\n\toptions?: FilterOptions\n): CossistantUIMessage[] {\n\treturn messages\n\t\t.map((msg) => filterMessageForAudience(msg, audience, options))\n\t\t.filter((msg): msg is CossistantUIMessage => msg !== null);\n}\n\n// ============================================================================\n// TIMELINE ITEM FILTERING (Direct, without conversion)\n// ============================================================================\n\n/**\n * Filter a TimelineItem for a specific audience\n *\n * @param item - The timeline item to filter\n * @param audience - The target audience\n * @param options - Optional filter options\n * @returns The filtered item, or null if the entire item should be hidden\n */\nexport function filterTimelineItemForAudience(\n\titem: TimelineItem,\n\taudience: Audience,\n\toptions?: FilterOptions\n): TimelineItem | null {\n\tconst opts = { ...DEFAULT_OPTIONS[audience], ...options };\n\n\t// Widget can't see private items\n\tif (audience === \"widget\" && item.visibility === \"private\") {\n\t\treturn null;\n\t}\n\n\t// Filter parts based on audience\n\tconst filteredParts = item.parts.filter((part) =>\n\t\tshouldIncludeTimelineItemPart(part, audience, opts)\n\t);\n\n\t// If no parts remain, return null (empty item)\n\tif (filteredParts.length === 0) {\n\t\treturn null;\n\t}\n\n\treturn {\n\t\t...item,\n\t\tparts: filteredParts as TimelineItemParts,\n\t};\n}\n\n/**\n * Filter multiple timeline items for an audience\n *\n * @param items - The timeline items to filter\n * @param audience - The target audience\n * @param options - Optional filter options\n * @returns Filtered items (excluding any that become null)\n */\nexport function filterTimelineItemsForAudience(\n\titems: TimelineItem[],\n\taudience: Audience,\n\toptions?: FilterOptions\n): TimelineItem[] {\n\treturn items\n\t\t.map((item) => filterTimelineItemForAudience(item, audience, options))\n\t\t.filter((item): item is TimelineItem => item !== null);\n}\n\n// ============================================================================\n// PART-LEVEL FILTERING\n// ============================================================================\n\n/**\n * Determine if an AI SDK part should be included based on audience and options\n */\nfunction shouldIncludePart(\n\tpart: AISDKPart,\n\taudience: Audience,\n\topts: Required<FilterOptions>\n): boolean {\n\t// Check part visibility from providerMetadata\n\tconst visibility = getPartVisibility(part);\n\tif (audience === \"widget\" && visibility === \"private\") {\n\t\treturn false;\n\t}\n\n\t// Handle reasoning parts\n\tif (part.type === \"reasoning\") {\n\t\treturn opts.includeReasoning;\n\t}\n\n\t// Handle tool parts\n\tif (typeof part.type === \"string\" && part.type.startsWith(\"tool-\")) {\n\t\tif (!opts.includeTools) {\n\t\t\treturn false;\n\t\t}\n\t\t// For widget, check if the tool part is marked as public\n\t\tif (audience === \"widget\" && visibility !== \"public\") {\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Handle source parts\n\tif (part.type === \"source-url\" || part.type === \"source-document\") {\n\t\treturn opts.includeSources;\n\t}\n\n\t// Include all other parts by default\n\treturn true;\n}\n\n/**\n * Determine if a TimelineItem part should be included based on audience and options\n */\nfunction shouldIncludeTimelineItemPart(\n\tpart: TimelineItemParts[number],\n\taudience: Audience,\n\topts: Required<FilterOptions>\n): boolean {\n\t// Check part visibility from providerMetadata\n\tconst visibility = getTimelineItemPartVisibility(part);\n\tif (audience === \"widget\" && visibility === \"private\") {\n\t\treturn false;\n\t}\n\n\t// Handle reasoning parts\n\tif (part.type === \"reasoning\") {\n\t\treturn opts.includeReasoning;\n\t}\n\n\t// Handle tool parts\n\tif (typeof part.type === \"string\" && part.type.startsWith(\"tool-\")) {\n\t\tif (!opts.includeTools) {\n\t\t\treturn false;\n\t\t}\n\t\t// For widget, check if the tool part is marked as public\n\t\tif (audience === \"widget\" && visibility !== \"public\") {\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Handle source parts\n\tif (part.type === \"source-url\" || part.type === \"source-document\") {\n\t\treturn opts.includeSources;\n\t}\n\n\t// Include all other parts by default\n\treturn true;\n}\n\n/**\n * Extract visibility from an AI SDK part's providerMetadata\n */\nfunction getPartVisibility(part: AISDKPart): \"public\" | \"private\" {\n\tconst metadataCarrier = part as {\n\t\tcallProviderMetadata?: Record<string, unknown>;\n\t\tproviderMetadata?: Record<string, unknown>;\n\t};\n\tconst metadata =\n\t\tmetadataCarrier.callProviderMetadata ?? metadataCarrier.providerMetadata;\n\n\tif (metadata) {\n\t\tconst typedMetadata = metadata as {\n\t\t\tcossistant?: CossistantPartMetadata;\n\t\t};\n\t\treturn typedMetadata.cossistant?.visibility ?? \"public\";\n\t}\n\treturn \"public\";\n}\n\n/**\n * Extract visibility from a TimelineItem part's providerMetadata\n */\nfunction getTimelineItemPartVisibility(\n\tpart: TimelineItemParts[number]\n): \"public\" | \"private\" {\n\tif (\"providerMetadata\" in part || \"callProviderMetadata\" in part) {\n\t\tconst typedPart = part as {\n\t\t\tcallProviderMetadata?: { cossistant?: CossistantPartMetadata };\n\t\t\tproviderMetadata?: { cossistant?: CossistantPartMetadata };\n\t\t};\n\t\treturn (\n\t\t\ttypedPart.callProviderMetadata?.cossistant?.visibility ??\n\t\t\ttypedPart.providerMetadata?.cossistant?.visibility ??\n\t\t\t\"public\"\n\t\t);\n\t}\n\treturn \"public\";\n}\n\n// ============================================================================\n// PRIVACY PRESETS\n// ============================================================================\n\n/**\n * Privacy presets for common use cases\n */\nexport const PrivacyPresets = {\n\t/**\n\t * TRANSPARENT: Show everything including AI reasoning\n\t * Use for: Internal debugging, transparency-focused products\n\t */\n\tTRANSPARENT: {\n\t\tincludeReasoning: true,\n\t\tincludeTools: true,\n\t\tincludeSources: true,\n\t} satisfies FilterOptions,\n\n\t/**\n\t * STANDARD: Default widget experience\n\t * Use for: Most customer-facing widgets\n\t */\n\tSTANDARD: {\n\t\tincludeReasoning: false,\n\t\tincludeTools: true,\n\t\tincludeSources: true,\n\t} satisfies FilterOptions,\n\n\t/**\n\t * MINIMAL: Only show text responses\n\t * Use for: Simple chatbots, text-only experiences\n\t */\n\tMINIMAL: {\n\t\tincludeReasoning: false,\n\t\tincludeTools: false,\n\t\tincludeSources: false,\n\t} satisfies FilterOptions,\n} as const;\n\n// ============================================================================\n// UTILITY FUNCTIONS\n// ============================================================================\n\n/**\n * Check if a message has any visible content for an audience\n */\nexport function hasVisibleContent(\n\tmessage: CossistantUIMessage,\n\taudience: Audience,\n\toptions?: FilterOptions\n): boolean {\n\treturn filterMessageForAudience(message, audience, options) !== null;\n}\n\n/**\n * Count visible parts for an audience\n */\nexport function countVisibleParts(\n\tmessage: CossistantUIMessage,\n\taudience: Audience,\n\toptions?: FilterOptions\n): number {\n\tconst filtered = filterMessageForAudience(message, audience, options);\n\treturn filtered?.parts.length ?? 0;\n}\n\n/**\n * Extract only text content from a message (for previews, notifications, etc.)\n */\nexport function extractVisibleText(\n\tmessage: CossistantUIMessage,\n\taudience: Audience\n): string | null {\n\tconst filtered = filterMessageForAudience(message, audience);\n\tif (!filtered) {\n\t\treturn null;\n\t}\n\n\tconst textParts = filtered.parts.filter(\n\t\t(part): part is { type: \"text\"; text: string } => part.type === \"text\"\n\t);\n\n\tif (textParts.length === 0) {\n\t\treturn null;\n\t}\n\treturn textParts.map((p) => p.text).join(\"\\n\");\n}\n"],"mappings":";;;;AAoDA,MAAMA,kBAA6D;CAClE,WAAW;EACV,kBAAkB;EAClB,cAAc;EACd,gBAAgB;EAChB;CACD,QAAQ;EACP,kBAAkB;EAClB,cAAc;EACd,gBAAgB;EAChB;CACD;;;;;;;;;AAcD,SAAgB,yBACf,SACA,UACA,SAC6B;CAC7B,MAAM,OAAO;EAAE,GAAG,gBAAgB;EAAW,GAAG;EAAS;AAGzD,KAAI,aAAa,YAAY,QAAQ,SAAS,eAAe,UAC5D,QAAO;CAIR,MAAM,gBAAgB,QAAQ,MAAM,QAAQ,SAC3C,kBAAkB,MAAM,UAAU,KAAK,CACvC;AAGD,KAAI,cAAc,WAAW,EAC5B,QAAO;AAGR,QAAO;EACN,GAAG;EACH,OAAO;EACP;;;;;;;;;;AAWF,SAAgB,0BACf,UACA,UACA,SACwB;AACxB,QAAO,SACL,KAAK,QAAQ,yBAAyB,KAAK,UAAU,QAAQ,CAAC,CAC9D,QAAQ,QAAoC,QAAQ,KAAK;;;;;;;;;;AAe5D,SAAgB,8BACf,MACA,UACA,SACsB;CACtB,MAAM,OAAO;EAAE,GAAG,gBAAgB;EAAW,GAAG;EAAS;AAGzD,KAAI,aAAa,YAAY,KAAK,eAA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AAEhD,QAAO;;;;;AAMR,SAAS,8BACR,MACuB;AACvB,KAAI,sBAAsB,QAAQ,0BAA0B,MAAM;EACjE,MAAM,YAAY;AAIlB,SACC,UAAU,sBAAsB,YAAY,cAC5C,UAAU,kBAAkB,YAAY,cACxC;;AAGF,QAAO;;;;;AAUR,MAAa,iBAAiB;CAK7B,aAAa;EACZ,kBAAkB;EAClB,cAAc;EACd,gBAAgB;EAChB;CAMD,UAAU;EACT,kBAAkB;EAClB,cAAc;EACd,gBAAgB;EAChB;CAMD,SAAS;EACR,kBAAkB;EAClB,cAAc;EACd,gBAAgB;EAChB;CACD;;;;AASD,SAAgB,kBACf,SACA,UACA,SACU;AACV,QAAO,yBAAyB,SAAS,UAAU,QAAQ,KAAK;;;;;AAMjE,SAAgB,kBACf,SACA,UACA,SACS;AAET,QADiB,yBAAyB,SAAS,UAAU,QAAQ,EACpD,MAAM,UAAU;;;;;AAMlC,SAAgB,mBACf,SACA,UACgB;CAChB,MAAM,WAAW,yBAAyB,SAAS,SAAS;AAC5D,KAAI,CAAC,SACJ,QAAO;CAGR,MAAM,YAAY,SAAS,MAAM,QAC/B,SAAiD,KAAK,SAAS,OAChE;AAED,KAAI,UAAU,WAAW,EACxB,QAAO;AAER,QAAO,UAAU,KAAK,MAAM,EAAE,KAAK,CAAC,KAAK,KAAK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeline-items-store.d.ts","names":[],"sources":["../../src/store/timeline-items-store.ts"],"sourcesContent":[],"mappings":";;;;;KAOK,wBAAA,GAA2B;KAEpB,8BAAA;EAFP,KAAA,EAGG,cAHH,EAAA;EAEO,WAAA,EAAA,OAAA;EAMA,UAAA,CAAA,EAAA,MAAA;AAiMZ,CAAA;AAAuC,KAjM3B,kBAAA,GAiM2B;EAAN,aAAA,EAhMjB,MAgMiB,CAAA,MAAA,EAhMF,8BAgME,CAAA;CAGzB;AAEkB,KALd,kBAAA,GAAqB,KAKP,CALa,kBAKb,CAAA,GAAA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