@cossistant/core 0.0.32 → 0.1.0
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/client.d.ts +1 -0
- package/client.d.ts.map +1 -1
- package/client.js +5 -0
- package/client.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/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,YAAY,KAAK,eAAe,UAChD,QAAO;CAIR,MAAM,gBAAgB,KAAK,MAAM,QAAQ,SACxC,8BAA8B,MAAM,UAAU,KAAK,CACnD;AAGD,KAAI,cAAc,WAAW,EAC5B,QAAO;AAGR,QAAO;EACN,GAAG;EACH,OAA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AChB;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,eAAe,UAChD,QAAO;CAIR,MAAM,gBAAgB,KAAK,MAAM,QAAQ,SACxC,8BAA8B,MAAM,UAAU,KAAK,CACnD;AAGD,KAAI,cAAc,WAAW,EAC5B,QAAO;AAGR,QAAO;EACN,GAAG;EACH,OAAO;EACP;;;;;;;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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;EACS,UAAA,CAAA,cAAA,EAAA,MAAA,EAAA,IAAA,EAH3B,8BAG2B,CAAA,EAAA,IAAA;EAA2B,kBAAA,CAAA,IAAA,EADpC,cACoC,CAAA,EAAA,IAAA;EAKtD,0BAAA,CAAA,KAAA,EAL2B,wBA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