@aparte/svelte 0.2.0-alpha.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/LICENSE +21 -0
- package/README.md +35 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1344 -0
- package/dist/index.js.map +1 -0
- package/dist/stores/aparteChat.d.ts +48 -0
- package/dist/stores/aparteChat.d.ts.map +1 -0
- package/dist/stores/aparteClient.d.ts +11 -0
- package/dist/stores/aparteClient.d.ts.map +1 -0
- package/dist/stores/conversationManager.d.ts +23 -0
- package/dist/stores/conversationManager.d.ts.map +1 -0
- package/dist/types.d.ts +28 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/lib/AparteChat.svelte","../src/lib/stores/aparteChat.ts","../src/lib/stores/aparteClient.ts","../src/lib/stores/conversationManager.ts","../src/lib/AparteUi.svelte"],"sourcesContent":["<script lang=\"ts\">\n import { onMount, onDestroy, tick, createEventDispatcher } from 'svelte';\n import { AparteChatHost, type AparteChatHostBinding, type AparteConfigClass, type AparteChatImperativeApi } from '@aparte/core';\n import type { AparteMessage, AparteSegment, AparteSendEventDetail, AparteActionEventDetail } from './types';\n\n export let messages: AparteMessage[] = [];\n export let placeholder = 'Type a message...';\n export let disabled = false;\n export let isTyping = false;\n export let typingText = 'Assistant is thinking...';\n /** When false, Shift+Enter submits and a bare Enter inserts a newline. */\n export let submitOnEnter = true;\n /** Freeze viewport spacer recalculation for this many ms after a conv swap. */\n export let layoutTransitionMs = 0;\n /**\n * Opt in to the \"centered composer when empty\" layout: the composer sits\n * vertically centered with the `empty-state` slot above it while the list is\n * empty, then slides to the bottom on the first message (~0.3s). Off by\n * default — additive.\n */\n export let centerWhenEmpty = false;\n /** Active conversation id (loads/persists via the registered ConversationManager). */\n export let conversationId: string | null = null;\n /**\n * Instance {@link AparteConfigClass} for this chat. When set, aparté components\n * inside resolve THIS config instead of the global `AparteConfig` singleton, so\n * several independently-configured chats can coexist on one page. Omit for the\n * global config. Read once when the host mounts.\n */\n export let config: AparteConfigClass | undefined = undefined;\n\n const dispatch = createEventDispatcher<{\n /**\n * User submitted a message from the composer. It is **appended to the\n * thread automatically** (optimistic UI) before this fires — do NOT add it\n * again (uncontrolled → duplicates; controlled → mirror into your own\n * `messages`). For side-effects: scroll, analytics, send.\n */\n messageSent: AparteSendEventDetail;\n /** A custom bubble action (registerBubbleAction) was clicked — typed aparte-action. */\n action: AparteActionEventDetail;\n /** Active path changed (branch nav/edit/retry/streaming) — bind back to `messages`. */\n messagesChange: AparteMessage[];\n messageAppended: AparteMessage;\n /** The typing/\"thinking\" indicator toggled (the host flips it off on the first streamed token). */\n typingChange: boolean;\n conversationCreated: string;\n }>();\n\n // Generated client-side in onMount (below): during SSR this stays empty so the\n // server and first client render agree on the id — no hydration mismatch.\n let hostId = '';\n\n let rootRef: HTMLElement;\n let viewportRef: HTMLElement;\n let composerRef: HTMLElement;\n let internalMessages: AparteMessage[] = [...messages];\n let typingActive = isTyping;\n let host: AparteChatHost | null = null;\n let teardown: (() => void) | null = null;\n\n // Parent push → internal list (guarded against the host's own emit round-trip).\n let lastProp = messages;\n $: if (messages !== lastProp) {\n lastProp = messages;\n internalMessages = [...messages];\n if (messages.length === 0) host?.clearRenderCache();\n }\n\n // Controlled typing indicator (host may flip it off on the first token).\n let lastTyping = isTyping;\n $: if (isTyping !== lastTyping) { lastTyping = isTyping; typingActive = isTyping; }\n\n // Conversation id changes (initial value loaded by the host on bind).\n let lastConv = conversationId;\n $: if (conversationId !== lastConv) {\n lastConv = conversationId;\n void host?.setConversationId(conversationId ?? null);\n }\n\n // Reconcile bubbles after the rendered list changes (host queries the DOM).\n $: if (host && internalMessages) { void tick().then(() => host?.syncBubbles()); }\n\n // Composer attributes set imperatively (like Angular's `[attr.x]`): Svelte's\n // custom-element binding assigns to *properties*, but aparte-composer exposes\n // some of these (e.g. `placeholder`) as getter-only — assigning throws.\n function toggleAttr(el: HTMLElement, name: string, on: boolean, value: string) {\n if (on) el.setAttribute(name, value); else el.removeAttribute(name);\n }\n $: if (composerRef) {\n composerRef.setAttribute('target', hostId);\n composerRef.setAttribute('placeholder', placeholder);\n toggleAttr(composerRef, 'disabled', disabled, '');\n toggleAttr(composerRef, 'submit-on-enter', !submitOnEnter, 'false');\n }\n\n function handleSend(event: Event) {\n (viewportRef as unknown as { requestSmoothScroll?: () => void })?.requestSmoothScroll?.();\n dispatch('messageSent', (event as CustomEvent<AparteSendEventDetail>).detail);\n }\n\n // Custom bubble actions bubble to the root as `aparte-action` — dispatch typed.\n function handleAction(event: Event) {\n dispatch('action', (event as CustomEvent<AparteActionEventDetail>).detail);\n }\n\n onMount(() => {\n hostId = `aparte-chat-${crypto.randomUUID()}`;\n // Set the id imperatively (deterministic, like Angular's ngAfterViewInit) rather\n // than waiting on a reactive re-render of `id={hostId}`; the composer target\n // reactive block below picks up the same hostId.\n if (rootRef) rootRef.id = hostId;\n const binding: AparteChatHostBinding = {\n hostId,\n host: rootRef,\n viewport: viewportRef,\n getMessages: () => internalMessages,\n setMessages: (m) => { internalMessages = m as AparteMessage[]; },\n onMessagesChange: (m) => dispatch('messagesChange', m as AparteMessage[]),\n onMessageAppended: (m) => dispatch('messageAppended', m as AparteMessage),\n onTypingChange: (t) => { typingActive = t; dispatch('typingChange', t); },\n onStreamingChange: () => { /* exposed via isStreaming() */ },\n afterRender: (cb) => { void tick().then(cb); },\n resetComposer: () => (composerRef as unknown as { reset?: () => void })?.reset?.(),\n };\n host = new AparteChatHost(binding, {\n layoutTransitionMs,\n conversationId: conversationId ?? null,\n onConversationCreated: (id) => dispatch('conversationCreated', id),\n config,\n });\n teardown = host.bind();\n host.syncBubbles();\n rootRef?.addEventListener('aparte-action', handleAction);\n });\n\n onDestroy(() => {\n rootRef?.removeEventListener('aparte-action', handleAction);\n teardown?.();\n teardown = null;\n host = null;\n });\n\n // ── Imperative API (bind:this on the component) ──\n export function appendMessage(m: AparteMessage) { host?.appendMessage(m); }\n export function updateMessage(id: string, u: Partial<AparteMessage>) { host?.updateMessage(id, u); }\n export function updateLastMessage(content: string, options?: { append?: boolean }) {\n host?.updateLastMessage(content, options);\n }\n export function addSegment(segment: AparteSegment) { host?.addSegment(segment); }\n export function updateSegment(segmentId: string, updates: Partial<AparteSegment>) {\n host?.updateSegment(segmentId, updates);\n }\n export function removeSegment(segmentId: string) { host?.removeSegment(segmentId); }\n export function appendToSegment(segmentId: string, content: string) {\n host?.appendToSegment(segmentId, content);\n }\n export function getMessages(): AparteMessage[] { return host?.getMessages() ?? internalMessages; }\n export function clearMessages() { host?.clearMessages(); }\n export function addBranch(messageId: string): number { return host?.addBranch(messageId) ?? 0; }\n export function addSiblingOf(existingId: string, message: AparteMessage): string | null {\n return host?.addSiblingOf(existingId, message) ?? null;\n }\n export function truncateFrom(messageId: string) { host?.truncateFrom(messageId); }\n export function truncateResponsesAfter(userMessageId: string) {\n host?.truncateResponsesAfter(userMessageId);\n }\n export function injectTokenStream(messageId: string, tokens: AsyncIterable<string>): Promise<void> {\n return host?.streamTokens(messageId, tokens) ?? Promise.resolve();\n }\n export function stopTokenStream() { host?.stopTokenStream(); }\n export function setConversationId(id: string | null): Promise<void> {\n return host?.setConversationId(id) ?? Promise.resolve();\n }\n export function scrollToBottom() {\n (viewportRef as unknown as { scrollToBottom?: () => void })?.scrollToBottom?.();\n }\n /**\n * The `<aparte-chat-viewport>` element — for custom scroll handling, an\n * IntersectionObserver, etc. Same `getViewport()` accessor on all four\n * wrappers.\n */\n export function getViewport(): HTMLElement | null { return viewportRef ?? null; }\n export function focusInput() {\n (composerRef as unknown as { focus?: () => void })?.focus?.();\n }\n export function isStreaming(): boolean { return host?.isStreaming ?? false; }\n\n // Compile-time parity check: Svelte 4 can't generic-annotate `export function`s,\n // so this never-called factory type-checks that the exported surface matches the\n // canonical AparteChatImperativeApi. A dropped/mistyped method is a build error.\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n function _assertImperativeParity(): AparteChatImperativeApi {\n return {\n appendMessage, updateMessage, updateLastMessage, addSegment, updateSegment, removeSegment,\n appendToSegment, getMessages, clearMessages, addBranch, addSiblingOf, truncateFrom,\n truncateResponsesAfter, injectTokenStream, stopTokenStream, setConversationId,\n scrollToBottom, focusInput, isStreaming, getViewport,\n };\n }\n</script>\n\n<div\n class=\"aparte-chat-container\"\n class:aparte-chat-container--auto-center={centerWhenEmpty}\n data-aparte-chat\n data-aparte-empty={centerWhenEmpty && internalMessages.length === 0 ? '' : null}\n id={hostId}\n bind:this={rootRef}\n>\n <aparte-chat-viewport bind:this={viewportRef} framework-managed=\"\">\n <!-- Welcome / placeholder shown inside the viewport while empty. -->\n {#if internalMessages.length === 0}\n <slot name=\"empty-state\" />\n {/if}\n <!-- `bubble` slot renders your OWN element per message in place of\n <aparte-chat-bubble>; driven by the reactive list so it streams live. -->\n {#each internalMessages as m (m.id)}\n <slot name=\"bubble\" message={m}>\n <aparte-chat-bubble\n message-id={m.id}\n data-role={m.role}\n timestamp={m.timestamp}\n content={m.content}\n streaming={(m.status === 'streaming' || m.status === 'pending') ? '' : null}\n />\n </slot>\n {/each}\n <aparte-chat-status visible={typingActive ? '' : null} text={typingText} />\n </aparte-chat-viewport>\n\n <!-- Content above the composer (banner, disclaimer, context chip). -->\n <slot name=\"above-composer\" />\n\n <aparte-composer\n bind:this={composerRef}\n on:aparte-send={handleSend}\n >\n <!-- Custom composer via the `composer` slot; falls back to the default\n shell (add-attachment · input · send). Compose the headless\n aparte-composer-* primitives freely for a skin-specific layout. -->\n <slot name=\"composer\">\n <div class=\"aparte-composer-shell\">\n <aparte-composer-attachments></aparte-composer-attachments>\n <div class=\"aparte-composer-row\">\n <aparte-composer-add-attachment></aparte-composer-add-attachment>\n <aparte-composer-input></aparte-composer-input>\n <aparte-composer-send></aparte-composer-send>\n </div>\n <!-- Footer slots (model selector, token counter…). The row is\n removed from view by .aparte-composer-footer:empty when unused. -->\n {#if $$slots['footer-left'] || $$slots['footer-center'] || $$slots['footer-right']}\n <div class=\"aparte-composer-footer\">\n <slot name=\"footer-left\" />\n <slot name=\"footer-center\" />\n <slot name=\"footer-right\" />\n </div>\n {/if}\n </div>\n </slot>\n </aparte-composer>\n</div>\n","import { writable, type Writable } from 'svelte/store';\nimport type { AparteChatImperativeApi } from '@aparte/core';\nimport type { AparteMessage, AparteSegment } from '../types.js';\n\n/**\n * The imperative surface `<AparteChat>` exposes (its `export function`s) — the\n * canonical contract shared by all four wrappers (`AparteChatImperativeApi`).\n */\nexport type AparteChatInstance = AparteChatImperativeApi;\n\nexport interface AparteChatStore {\n /** Subscribe with `$messages` and bind to `<AparteChat messages={$messages}>`. */\n messages: Writable<AparteMessage[]>;\n /** Register the component instance via `bind:this`. */\n connect(component: AparteChatInstance | null): void;\n /** Wire to `on:messagesChange={(e) => chat.onMessagesChange(e.detail)}`. */\n onMessagesChange(messages: AparteMessage[]): void;\n appendMessage(message: AparteMessage): void;\n updateMessage(messageId: string, updates: Partial<AparteMessage>): void;\n updateLastMessage(content: string, options?: { append?: boolean }): void;\n addSegment(segment: AparteSegment): void;\n updateSegment(segmentId: string, updates: Partial<AparteSegment>): void;\n removeSegment(segmentId: string): void;\n appendToSegment(segmentId: string, content: string): void;\n clearMessages(): void;\n addBranch(messageId: string): number;\n addSiblingOf(existingId: string, message: AparteMessage): string | null;\n truncateFrom(messageId: string): void;\n truncateResponsesAfter(userMessageId: string): void;\n injectTokenStream(messageId: string, tokens: AsyncIterable<string>): Promise<void>;\n stopTokenStream(): void;\n setConversationId(id: string | null): Promise<void>;\n isStreaming(): boolean;\n}\n\n/**\n * Idiomatic Svelte ergonomics for `<AparteChat>`. Owns the `messages` store so the\n * consumer skips the manual `on:messagesChange` → `messages` round-trip.\n *\n * @example\n * const chat = createAparteChat();\n * const { messages } = chat;\n * let comp;\n * $: chat.connect(comp);\n * // <AparteChat bind:this={comp} messages={$messages}\n * // on:messagesChange={(e) => chat.onMessagesChange(e.detail)} />\n */\nexport function createAparteChat(initial: AparteMessage[] = []): AparteChatStore {\n const messages = writable<AparteMessage[]>([...initial]);\n let comp: AparteChatInstance | null = null;\n return {\n messages,\n connect: (component) => { comp = component; },\n onMessagesChange: (m) => messages.set(m),\n appendMessage: (m) => comp?.appendMessage(m),\n updateMessage: (id, u) => comp?.updateMessage(id, u),\n updateLastMessage: (c, o) => comp?.updateLastMessage(c, o),\n addSegment: (s) => comp?.addSegment(s),\n updateSegment: (id, u) => comp?.updateSegment(id, u),\n removeSegment: (id) => comp?.removeSegment(id),\n appendToSegment: (id, c) => comp?.appendToSegment(id, c),\n clearMessages: () => comp?.clearMessages(),\n addBranch: (id) => comp?.addBranch(id) ?? 0,\n addSiblingOf: (id, m) => comp?.addSiblingOf(id, m) ?? null,\n truncateFrom: (id) => comp?.truncateFrom(id),\n truncateResponsesAfter: (id) => comp?.truncateResponsesAfter(id),\n injectTokenStream: (id, tokens) => comp?.injectTokenStream(id, tokens) ?? Promise.resolve(),\n stopTokenStream: () => comp?.stopTokenStream(),\n setConversationId: (id) => comp?.setConversationId(id) ?? Promise.resolve(),\n isStreaming: () => comp?.isStreaming() ?? false,\n };\n}\n","import { onMount, onDestroy } from 'svelte';\nimport { AparteClient, type AparteClientOptions } from '@aparte/core';\n\n/**\n * Mounts an `AparteClient` that bridges `aparte-send` events to the configured AI\n * providers. Starts on mount, stops on destroy. Call from a component's script.\n * Svelte equivalent of Angular's `AparteAiService`.\n */\nexport function createAparteClient(options?: AparteClientOptions) {\n const client = new AparteClient(options ?? {});\n onMount(() => { client.start(); });\n onDestroy(() => client.stop());\n return { client, abort: () => client.abort() };\n}\n","import { writable, derived } from 'svelte/store';\nimport { onDestroy } from 'svelte';\nimport {\n AparteConfig,\n ConversationManager,\n type AparteConversation,\n type AparteStorageAdapter,\n} from '@aparte/core';\nimport type { AparteMessage } from '../types.js';\n\n/**\n * Svelte-store wrapper around the core `ConversationManager`. The active\n * conversation is owned by the chat component's controller; switch by binding\n * `conversationId` on `<AparteChat>`. Call from a component's script. Svelte\n * equivalent of Angular's `ConversationManagerService`.\n */\nexport function createConversationManager() {\n let manager: ConversationManager | null = null;\n let unsub: (() => void) | null = null;\n\n const conversations = writable<AparteConversation[]>([]);\n const activeId = writable<string | null>(null);\n const activeConversations = derived(conversations, ($c) =>\n $c.filter((c) => !c.archivedAt).sort((a, b) => b.updatedAt - a.updatedAt),\n );\n const archivedConversations = derived(conversations, ($c) =>\n $c.filter((c) => !!c.archivedAt).sort((a, b) => b.updatedAt - a.updatedAt),\n );\n const activeConversation = derived([conversations, activeId], ([$c, $id]) =>\n $id ? $c.find((c) => c.id === $id) ?? null : null,\n );\n\n onDestroy(() => unsub?.());\n\n const assert = (): ConversationManager => {\n if (!manager) throw new Error('[createConversationManager] Not initialised. Call init(adapter) first.');\n return manager;\n };\n\n async function init(adapter: AparteStorageAdapter): Promise<void> {\n const m = new ConversationManager(adapter);\n manager = m;\n unsub = m.subscribe((convs) => {\n conversations.set([...convs]);\n activeId.set(m.activeId);\n });\n await m.init();\n activeId.set(m.activeId);\n AparteConfig.setConversationManager(m);\n }\n\n return {\n conversations,\n activeConversations,\n archivedConversations,\n activeId,\n activeConversation,\n init,\n createNew: (title?: string) => assert().createNew(title),\n addMessage: (convId: string, message: AparteMessage) => assert().addMessage(convId, message),\n updateMessages: (convId: string, messages: AparteMessage[]) => assert().updateMessages(convId, messages),\n delete: (id: string) => assert().delete(id),\n archive: (id: string) => assert().archive(id),\n unarchive: (id: string) => assert().unarchive(id),\n };\n}\n","<script lang=\"ts\">\n import { onMount, onDestroy, createEventDispatcher } from 'svelte';\n import { applyElementProps, DEFAULT_UI_EVENTS } from '@aparte/core';\n\n /** The custom element tag name (e.g. 'aparte-model-selector'). */\n export let name: string;\n /** Props to apply. Keys starting with `--` become CSS variables. */\n export let props: Record<string, unknown> = {};\n /**\n * Which custom events to forward through `elementEvent`. Defaults to the\n * interactive aparté surface (DEFAULT_UI_EVENTS); pass your own list to listen to\n * other events (e.g. ['aparte-composer-change'] for attachments).\n */\n export let events: string[] | undefined = undefined;\n\n const dispatch = createEventDispatcher<{ elementEvent: CustomEvent }>();\n\n let host: HTMLElement;\n let el: HTMLElement | null = null;\n let cleanups: Array<() => void> = [];\n\n function applyProps() {\n if (el) applyElementProps(el, props);\n }\n\n function create() {\n if (!host) return;\n el = document.createElement(name);\n applyProps();\n for (const ev of events ?? DEFAULT_UI_EVENTS) {\n const listener = (e: Event) => dispatch('elementEvent', e as CustomEvent);\n el.addEventListener(ev, listener);\n cleanups.push(() => el?.removeEventListener(ev, listener));\n }\n host.appendChild(el);\n }\n\n function destroy() {\n for (const c of cleanups) c();\n cleanups = [];\n el?.remove();\n el = null;\n }\n\n onMount(create);\n onDestroy(destroy);\n\n // Recreate the element when `name` (or the forwarded event set) changes. A\n // joined key so a fresh inline `events` array doesn't thrash the element.\n let lastName = name;\n let lastEvtsKey = (events ?? DEFAULT_UI_EVENTS).join('|');\n $: {\n const evtsKey = (events ?? DEFAULT_UI_EVENTS).join('|');\n if (el && (name !== lastName || evtsKey !== lastEvtsKey)) {\n lastName = name;\n lastEvtsKey = evtsKey;\n destroy();\n create();\n }\n }\n $: if (el && props) applyProps();\n\n export function getElement() { return el; }\n export function callMethod(methodName: string, ...args: unknown[]) {\n const fn = (el as unknown as Record<string, unknown>)?.[methodName];\n return typeof fn === 'function' ? (fn as (...a: unknown[]) => unknown).apply(el, args) : undefined;\n }\n</script>\n\n<span bind:this={host} style=\"display: contents\"></span>\n"],"names":["ctx","init"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;EA0NmC,IAAC,EAAA;AAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEd,8BAAA,oBAAA,cAAA;AAAA,MAAA,QAAE,EAAE;AACL,8BAAA,oBAAA,aAAA;AAAA,MAAA,QAAE,IAAI;AACN,8BAAA,oBA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KAAK,GAAG;AAYxC,WAAA,aAAA;AAAsB,WAAA;AAAA;AACtB,WAAA,WAAW,eAAuB,MAAA;AAC1C,UAAA,KAAM,KAA4C,UAAU;AACpD,WAAA,OAAA,OAAO,aAAc,GAAoC,MAAM,IAAI,IAAI,IAAA;AAAA;;;AAIxE,aAAI;;;;;;;;;;;;AAlBnB;cACQ,WAAW,UAAU,mBAAmB,KAAK,GAAG;YAClD,OAAO,SAAS,YAAY,YAAY,cAAA;0BAC1C,WAAW,IAAA;0BACX,cAAc,OAAA;AACd,kBAAA;AACA,iBAAA;AAAA;;;;;AAGJ,UAAO,MAAM,MAAO,YAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type Writable } from 'svelte/store';
|
|
2
|
+
import type { AparteChatImperativeApi } from '@aparte/core';
|
|
3
|
+
import type { AparteMessage, AparteSegment } from '../types.js';
|
|
4
|
+
/**
|
|
5
|
+
* The imperative surface `<AparteChat>` exposes (its `export function`s) — the
|
|
6
|
+
* canonical contract shared by all four wrappers (`AparteChatImperativeApi`).
|
|
7
|
+
*/
|
|
8
|
+
export type AparteChatInstance = AparteChatImperativeApi;
|
|
9
|
+
export interface AparteChatStore {
|
|
10
|
+
/** Subscribe with `$messages` and bind to `<AparteChat messages={$messages}>`. */
|
|
11
|
+
messages: Writable<AparteMessage[]>;
|
|
12
|
+
/** Register the component instance via `bind:this`. */
|
|
13
|
+
connect(component: AparteChatInstance | null): void;
|
|
14
|
+
/** Wire to `on:messagesChange={(e) => chat.onMessagesChange(e.detail)}`. */
|
|
15
|
+
onMessagesChange(messages: AparteMessage[]): void;
|
|
16
|
+
appendMessage(message: AparteMessage): void;
|
|
17
|
+
updateMessage(messageId: string, updates: Partial<AparteMessage>): void;
|
|
18
|
+
updateLastMessage(content: string, options?: {
|
|
19
|
+
append?: boolean;
|
|
20
|
+
}): void;
|
|
21
|
+
addSegment(segment: AparteSegment): void;
|
|
22
|
+
updateSegment(segmentId: string, updates: Partial<AparteSegment>): void;
|
|
23
|
+
removeSegment(segmentId: string): void;
|
|
24
|
+
appendToSegment(segmentId: string, content: string): void;
|
|
25
|
+
clearMessages(): void;
|
|
26
|
+
addBranch(messageId: string): number;
|
|
27
|
+
addSiblingOf(existingId: string, message: AparteMessage): string | null;
|
|
28
|
+
truncateFrom(messageId: string): void;
|
|
29
|
+
truncateResponsesAfter(userMessageId: string): void;
|
|
30
|
+
injectTokenStream(messageId: string, tokens: AsyncIterable<string>): Promise<void>;
|
|
31
|
+
stopTokenStream(): void;
|
|
32
|
+
setConversationId(id: string | null): Promise<void>;
|
|
33
|
+
isStreaming(): boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Idiomatic Svelte ergonomics for `<AparteChat>`. Owns the `messages` store so the
|
|
37
|
+
* consumer skips the manual `on:messagesChange` → `messages` round-trip.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* const chat = createAparteChat();
|
|
41
|
+
* const { messages } = chat;
|
|
42
|
+
* let comp;
|
|
43
|
+
* $: chat.connect(comp);
|
|
44
|
+
* // <AparteChat bind:this={comp} messages={$messages}
|
|
45
|
+
* // on:messagesChange={(e) => chat.onMessagesChange(e.detail)} />
|
|
46
|
+
*/
|
|
47
|
+
export declare function createAparteChat(initial?: AparteMessage[]): AparteChatStore;
|
|
48
|
+
//# sourceMappingURL=aparteChat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aparteChat.d.ts","sourceRoot":"","sources":["../../src/lib/stores/aparteChat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEhE;;;GAGG;AACH,MAAM,MAAM,kBAAkB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AC,CAAC;IACnF,eAAe,IAAI,IAAI,CAAC;IACxB,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,WAAW,IAAI,OAAO,CAAC;CAC1B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,aAAa,EAAO,GAAG,eAAe,CAwB/E"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AparteClient, type AparteClientOptions } from '@aparte/core';
|
|
2
|
+
/**
|
|
3
|
+
* Mounts an `AparteClient` that bridges `aparte-send` events to the configured AI
|
|
4
|
+
* providers. Starts on mount, stops on destroy. Call from a component's script.
|
|
5
|
+
* Svelte equivalent of Angular's `AparteAiService`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createAparteClient(options?: AparteClientOptions): {
|
|
8
|
+
client: AparteClient;
|
|
9
|
+
abort: () => void;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=aparteClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aparteClient.d.ts","sourceRoot":"","sources":["../../src/lib/stores/aparteClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEtE;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,mBAAmB;;;EAK/D"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type AparteConversation, type AparteStorageAdapter } from '@aparte/core';
|
|
2
|
+
import type { AparteMessage } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Svelte-store wrapper around the core `ConversationManager`. The active
|
|
5
|
+
* conversation is owned by the chat component's controller; switch by binding
|
|
6
|
+
* `conversationId` on `<AparteChat>`. Call from a component's script. Svelte
|
|
7
|
+
* equivalent of Angular's `ConversationManagerService`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createConversationManager(): {
|
|
10
|
+
conversations: import("svelte/store").Writable<AparteConversation[]>;
|
|
11
|
+
activeConversations: import("svelte/store").Readable<AparteConversation[]>;
|
|
12
|
+
archivedConversations: import("svelte/store").Readable<AparteConversation[]>;
|
|
13
|
+
activeId: import("svelte/store").Writable<string | null>;
|
|
14
|
+
activeConversation: import("svelte/store").Readable<AparteConversation | null>;
|
|
15
|
+
init: (adapter: AparteStorageAdapter) => Promise<void>;
|
|
16
|
+
createNew: (title?: string) => Promise<AparteConversation>;
|
|
17
|
+
addMessage: (convId: string, message: AparteMessage) => Promise<void>;
|
|
18
|
+
updateMessages: (convId: string, messages: AparteMessage[]) => Promise<void>;
|
|
19
|
+
delete: (id: string) => Promise<void>;
|
|
20
|
+
archive: (id: string) => Promise<void>;
|
|
21
|
+
unarchive: (id: string) => Promise<void>;
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=conversationManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversationManager.d.ts","sourceRoot":"","sources":["../../src/lib/stores/conversationManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAGH,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EAC5B,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD;;;;;GAKG;AACH,wBAAgB,yBAAyB;;;;;;oBAuBR,oBAAoB,KAAG,OAAO,CAAC,IAAI,CAAC;wBAmBzC,MAAM;yBACL,MAAM,WAAW,aAAa;6BAC1B,MAAM,YAAY,aAAa,EAAE;iBAC7C,MAAM;kBACL,MAAM;oBACJ,MAAM;EAE7B"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types for the Svelte wrapper — all re-exported from `@aparte/core`, the
|
|
3
|
+
* single source of truth. `AparteSendEventDetail` used to be re-declared here
|
|
4
|
+
* WITHOUT `targetId`, which the composer actually sends (multi-instance scoping);
|
|
5
|
+
* re-export the canonical one so the field isn't silently dropped from the type.
|
|
6
|
+
*/
|
|
7
|
+
export type { AparteMessage, AparteSegment, AparteTextSegment, AparteCodeSegment, AparteThinkingSegment, AparteTerminalSegment, AparteSendEventDetail, AparteActionEventDetail, } from '@aparte/core';
|
|
8
|
+
/** Props of the `<AparteUi>` universal pass-through proxy. */
|
|
9
|
+
export interface AparteUiProps {
|
|
10
|
+
/** The custom element tag name (e.g. 'aparte-model-selector'). */
|
|
11
|
+
name: string;
|
|
12
|
+
/** Props to apply. Keys starting with `--` become CSS variables. */
|
|
13
|
+
props?: Record<string, unknown>;
|
|
14
|
+
/**
|
|
15
|
+
* Which custom events to forward through `elementEvent`. Defaults to the
|
|
16
|
+
* interactive aparté surface (`DEFAULT_UI_EVENTS` from `@aparte/core`).
|
|
17
|
+
*/
|
|
18
|
+
events?: string[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The imperative surface `<AparteUi>` exposes (`bind:this`) — the same
|
|
22
|
+
* `getElement`/`callMethod` contract on all four wrappers.
|
|
23
|
+
*/
|
|
24
|
+
export interface AparteUiHandle {
|
|
25
|
+
getElement<T extends HTMLElement = HTMLElement>(): T | null;
|
|
26
|
+
callMethod<T = unknown>(methodName: string, ...args: unknown[]): T | undefined;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/lib/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,YAAY,EACR,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,GAC1B,MAAM,cAAc,CAAC;AAEtB,8DAA8D;AAC9D,MAAM,WAAW,aAAa;IAC1B,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,oEAAoE;IACpE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC3B,UAAU,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,KAAK,CAAC,GAAG,IAAI,CAAC;IAC5D,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;CAClF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aparte/svelte",
|
|
3
|
+
"version": "0.2.0-alpha.0",
|
|
4
|
+
"description": "Svelte 4 wrapper for aparté — an ergonomic <AparteChat> component plus stores over the framework-agnostic web components.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"@aparte-workspace/source": "./src/lib/index.ts",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"svelte": "^4.0.0",
|
|
28
|
+
"@aparte/core": "0.2.0-alpha.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@sveltejs/vite-plugin-svelte": "^3.0.0",
|
|
32
|
+
"@testing-library/svelte": "^5.2.0",
|
|
33
|
+
"jsdom": "^22.1.0",
|
|
34
|
+
"svelte": "^4.2.0",
|
|
35
|
+
"typescript": "^5.4.0",
|
|
36
|
+
"vite": "^6.0.0",
|
|
37
|
+
"@aparte/core": "0.2.0-alpha.0"
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"svelte",
|
|
41
|
+
"aparte",
|
|
42
|
+
"chat",
|
|
43
|
+
"ai",
|
|
44
|
+
"web-components"
|
|
45
|
+
],
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "git+https://github.com/apartejs/aparte.git",
|
|
50
|
+
"directory": "packages/wrappers/svelte"
|
|
51
|
+
},
|
|
52
|
+
"bugs": {
|
|
53
|
+
"url": "https://github.com/apartejs/aparte/issues"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"dev": "vite",
|
|
57
|
+
"build": "vite build && tsc -b --emitDeclarationOnly --force",
|
|
58
|
+
"preview": "vite preview",
|
|
59
|
+
"test": "vitest",
|
|
60
|
+
"test:run": "vitest run",
|
|
61
|
+
"test:coverage": "vitest run --coverage"
|
|
62
|
+
}
|
|
63
|
+
}
|