@aleph-alpha/chat-kit 1.3.1 → 1.5.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.
Files changed (73) hide show
  1. package/dist/{CkInput.vue_vue_type_script_setup_true_lang-CyGLItQZ.js → CkInput.vue_vue_type_script_setup_true_lang-C5C09u0z.js} +9 -8
  2. package/dist/adapters/index.d.ts +18 -0
  3. package/dist/adapters/index.d.ts.map +1 -0
  4. package/dist/adapters/index.js +4 -0
  5. package/dist/adapters/responses-api.d.ts +180 -0
  6. package/dist/adapters/responses-api.d.ts.map +1 -0
  7. package/dist/adapters/responses-api.js +153 -0
  8. package/dist/components/base/CkPromptActionButton/CkPromptActionButton.vue.d.ts +1 -1
  9. package/dist/components/composed/CkConversation/CkConversation.stories.d.ts +11 -3
  10. package/dist/components/composed/CkConversation/CkConversation.stories.d.ts.map +1 -1
  11. package/dist/components/composed/CkConversation/CkConversation.vue.d.ts +5 -1
  12. package/dist/components/composed/CkConversation/CkConversation.vue.d.ts.map +1 -1
  13. package/dist/components/index.js +1 -1
  14. package/dist/composables/fileUpload/index.d.ts +7 -0
  15. package/dist/composables/fileUpload/index.d.ts.map +1 -0
  16. package/dist/composables/fileUpload/types.d.ts +295 -0
  17. package/dist/composables/fileUpload/types.d.ts.map +1 -0
  18. package/dist/composables/fileUpload/useFileUpload.d.ts +4 -0
  19. package/dist/composables/fileUpload/useFileUpload.d.ts.map +1 -0
  20. package/dist/composables/fileUpload/useFileUploadWrapper.d.ts +3 -0
  21. package/dist/composables/fileUpload/useFileUploadWrapper.d.ts.map +1 -0
  22. package/dist/composables/index.d.ts +2 -1
  23. package/dist/composables/index.d.ts.map +1 -1
  24. package/dist/composables/index.js +5 -2
  25. package/dist/composables/useConversations.d.ts +12 -0
  26. package/dist/composables/useConversations.d.ts.map +1 -1
  27. package/dist/generateId-BHf0W4Rq.js +6 -0
  28. package/dist/handlers/index.js +1 -1
  29. package/dist/handlers/useMessageHandler.d.ts +2 -2
  30. package/dist/handlers/useMessageHandler.d.ts.map +1 -1
  31. package/dist/index-BbTgIoYa.js +1557 -0
  32. package/dist/index.d.ts +2 -2
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +6 -8
  35. package/dist/services/index.d.ts +0 -2
  36. package/dist/services/index.d.ts.map +1 -1
  37. package/dist/services/index.js +1 -37
  38. package/dist/services/types.d.ts +2 -2
  39. package/dist/services/types.d.ts.map +1 -1
  40. package/dist/types.d.ts +47 -2
  41. package/dist/types.d.ts.map +1 -1
  42. package/dist/{useMessageHandler-BmBdu2EW.js → useMessageHandler-ZRC-gIOJ.js} +5 -5
  43. package/package.json +10 -2
  44. package/src/adapters/index.ts +17 -0
  45. package/src/adapters/responses-api.spec.ts +365 -0
  46. package/src/adapters/responses-api.ts +444 -0
  47. package/src/components/composed/CkConversation/CkConversation.spec.ts +171 -25
  48. package/src/components/composed/CkConversation/CkConversation.stories.ts +266 -46
  49. package/src/components/composed/CkConversation/CkConversation.vue +19 -7
  50. package/src/composables/fileUpload/index.spec.ts +213 -0
  51. package/src/composables/fileUpload/index.ts +83 -0
  52. package/src/composables/fileUpload/types.ts +409 -0
  53. package/src/composables/fileUpload/useFileUpload.ts +1242 -0
  54. package/src/composables/fileUpload/useFileUploadWrapper.ts +382 -0
  55. package/src/composables/index.ts +2 -1
  56. package/src/composables/useConversations.spec.ts +118 -0
  57. package/src/composables/useConversations.ts +32 -0
  58. package/src/handlers/useChatKitLabels.spec.ts +16 -2
  59. package/src/handlers/useMessageHandler.spec.ts +112 -44
  60. package/src/handlers/useMessageHandler.ts +16 -2
  61. package/src/helpers/conversationTree.spec.ts +46 -19
  62. package/src/index.ts +11 -2
  63. package/src/services/index.ts +0 -2
  64. package/src/services/types.ts +2 -2
  65. package/src/types.ts +55 -2
  66. package/dist/ChatService-LogwJNxh.js +0 -9
  67. package/dist/services/ChatService.d.ts +0 -42
  68. package/dist/services/ChatService.d.ts.map +0 -1
  69. package/dist/services/MockChatService.d.ts +0 -10
  70. package/dist/services/MockChatService.d.ts.map +0 -1
  71. package/dist/useConversationSessions-ulFhtpQr.js +0 -243
  72. package/src/services/ChatService.ts +0 -60
  73. package/src/services/MockChatService.ts +0 -47
@@ -1062,6 +1062,9 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
1062
1062
  () => Boolean(props.agentAvatarImage) || Boolean(props.agentAvatarFallback) || Boolean(slots["agent-message-icon"])
1063
1063
  );
1064
1064
  const isLoading = (message) => message.status === "started" || message.status === "sending";
1065
+ function getMessageText(message) {
1066
+ return message.content.filter((c) => c.type === "text").map((c) => c.text).join("");
1067
+ }
1065
1068
  return (_ctx, _cache) => {
1066
1069
  return openBlock(), createBlock(_sfc_main$e, { messages: __props.messages }, {
1067
1070
  "user-message": withCtx(({ message }) => [
@@ -1069,16 +1072,14 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
1069
1072
  class: normalizeClass({ "ml-8": hasIcon.value })
1070
1073
  }, [
1071
1074
  renderSlot(_ctx.$slots, "user-message", { message }, () => [
1072
- createVNode(_sfc_main$3, {
1073
- message: message.content
1074
- }, {
1075
+ createVNode(_sfc_main$3, null, {
1075
1076
  default: withCtx(() => [
1076
1077
  renderSlot(_ctx.$slots, "user-message-content", { message }, () => [
1077
- createTextVNode(toDisplayString(message.content), 1)
1078
+ createTextVNode(toDisplayString(getMessageText(message)), 1)
1078
1079
  ])
1079
1080
  ]),
1080
1081
  _: 2
1081
- }, 1032, ["message"])
1082
+ }, 1024)
1082
1083
  ])
1083
1084
  ], 2)
1084
1085
  ]),
@@ -1087,9 +1088,9 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
1087
1088
  createVNode(_sfc_main$f, null, createSlots({
1088
1089
  footer: withCtx(() => [
1089
1090
  renderSlot(_ctx.$slots, "agent-message-footer", { message }, () => [
1090
- message.content && !isLoading(message) ? (openBlock(), createBlock(CkCopyMessageActionButton, {
1091
+ getMessageText(message) && !isLoading(message) ? (openBlock(), createBlock(CkCopyMessageActionButton, {
1091
1092
  key: 0,
1092
- text: message.content,
1093
+ text: getMessageText(message),
1093
1094
  "aria-label-copy": unref(labels).copyMessageAction,
1094
1095
  "aria-label-copied": unref(labels).copyMessageActionCopied
1095
1096
  }, null, 8, ["text", "aria-label-copy", "aria-label-copied"])) : createCommentVNode("", true)
@@ -1098,7 +1099,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
1098
1099
  default: withCtx(() => [
1099
1100
  renderSlot(_ctx.$slots, "agent-message-content", { message }, () => [
1100
1101
  createVNode(_sfc_main$8, {
1101
- content: message.content,
1102
+ content: getMessageText(message),
1102
1103
  classes: __props.agentMarkdownClasses
1103
1104
  }, createSlots({ _: 2 }, [
1104
1105
  _ctx.$slots["agent-message-code-block"] ? {
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Format adapters for chat-kit.
3
+ *
4
+ * Adapters convert a transport-specific transcript shape into chat-kit's
5
+ * domain model (`ConversationTree`). They are intentionally optional — the
6
+ * message handler only knows about `setTree(tree)`, so apps that use a
7
+ * different format can write their own adapter (or skip the concept
8
+ * entirely and build trees by hand).
9
+ *
10
+ * Currently shipped:
11
+ * - `responses-api` — OpenAI-style `GET /conversations/{id}/responses`.
12
+ *
13
+ * Re-exported via `@aleph-alpha/chat-kit/adapters`. Use the more granular
14
+ * `@aleph-alpha/chat-kit/adapters/responses-api` subpath when you only
15
+ * need a specific adapter.
16
+ */
17
+ export * from './responses-api';
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { responsesToTree } from "./responses-api.js";
2
+ export {
3
+ responsesToTree
4
+ };
@@ -0,0 +1,180 @@
1
+ import type { ConversationTree } from '../types';
2
+ /**
3
+ * Annotation attached to a Responses-API content part (citations, file
4
+ * references, etc.). chat-kit does not render annotations itself; the shape
5
+ * is kept open so consumers can downcast to a more specific schema.
6
+ */
7
+ export interface ResponseAnnotation {
8
+ type: string;
9
+ [key: string]: unknown;
10
+ }
11
+ /**
12
+ * Plain text fragment inside a `ResponseOutputMessage`. Streamed by the
13
+ * Responses API as `output_text` (or the historical `text` alias).
14
+ */
15
+ export interface ResponseOutputTextPart {
16
+ type: 'output_text' | 'text';
17
+ text: string;
18
+ annotations?: ResponseAnnotation[];
19
+ }
20
+ /**
21
+ * One reasoning fragment inside a `ResponseOutputReasoning`. The Responses
22
+ * API streams chain-of-thought under `reasoning_text`; the body is exposed
23
+ * for consumers that want to render it (chat-kit itself only surfaces a
24
+ * "thinking" indicator).
25
+ */
26
+ export interface ResponseReasoningTextPart {
27
+ type: 'reasoning_text';
28
+ text: string;
29
+ annotations?: ResponseAnnotation[];
30
+ }
31
+ /**
32
+ * Forward-compatible catch-all for content parts whose `type` chat-kit does
33
+ * not yet model (e.g. refusals, future part kinds). Consumers narrow on
34
+ * `type` themselves when they need richer handling.
35
+ */
36
+ export interface ResponseUnknownContentPart {
37
+ type: string;
38
+ text?: string;
39
+ annotations?: ResponseAnnotation[];
40
+ [key: string]: unknown;
41
+ }
42
+ /**
43
+ * Discriminated union of content parts that can appear inside a Responses-
44
+ * API output item. `ResponseOutputTextPart` and `ResponseReasoningTextPart`
45
+ * cover the rendered shapes; the catch-all keeps the union open.
46
+ */
47
+ export type OutputContentPart = ResponseOutputTextPart | ResponseReasoningTextPart | ResponseUnknownContentPart;
48
+ /**
49
+ * Visible message produced by a Responses-API turn (assistant reply or
50
+ * echoed user input). Carries the renderable text content; `responsesToTree`
51
+ * extracts text from `content` to build the chat tree.
52
+ */
53
+ export interface ResponseOutputMessage {
54
+ type: 'message';
55
+ id: string;
56
+ status: string;
57
+ role: 'assistant' | 'user';
58
+ content: string | OutputContentPart[];
59
+ }
60
+ /**
61
+ * Chain-of-thought trail produced by the assistant during a turn. Surfaced
62
+ * in chat-kit only as a "thinking" indicator; consumers may render the
63
+ * underlying `reasoning_text` parts directly when desired.
64
+ */
65
+ export interface ResponseOutputReasoning {
66
+ type: 'reasoning';
67
+ id: string;
68
+ status: string;
69
+ role?: 'assistant' | null;
70
+ content: OutputContentPart[];
71
+ }
72
+ /**
73
+ * Single tool entry returned inside `mcp_list_tools` (and similar tool-
74
+ * discovery outputs). Schema fields are passed through verbatim because
75
+ * chat-kit does not model JSON Schema itself.
76
+ */
77
+ export interface ResponseToolDescriptor {
78
+ name: string;
79
+ description?: string;
80
+ annotations?: Record<string, unknown>;
81
+ input_schema?: unknown;
82
+ }
83
+ /**
84
+ * Wire-level Responses-API output kinds that represent tool activity rather
85
+ * than visible content. The list enumerates the values chat-kit recognises
86
+ * today; extend it as new tool kinds are introduced upstream.
87
+ */
88
+ export type ResponseOutputToolType = 'mcp_list_tools' | 'mcp_call' | 'tool_call' | 'function_call' | 'web_search_call' | 'file_search_call' | 'code_interpreter_call' | 'image_generation_call' | 'local_shell_call';
89
+ /**
90
+ * Tool-related output produced during a Responses-API turn. Covers tool
91
+ * discovery (`mcp_list_tools`), invocation (`mcp_call`, `function_call`,
92
+ * etc.) and the various built-in tool kinds. Common fields are typed; the
93
+ * rest is passed through so consumers can read kind-specific data without
94
+ * redefining the shape.
95
+ */
96
+ export interface ResponseOutputTool {
97
+ type: ResponseOutputToolType;
98
+ id: string;
99
+ status?: string;
100
+ /** `mcp_list_tools` / `mcp_call`: server identifier. */
101
+ server_label?: string;
102
+ /** `mcp_list_tools`: catalog of tools exposed by the server. */
103
+ tools?: ResponseToolDescriptor[];
104
+ /** `function_call` / `mcp_call`: invoked tool name. */
105
+ name?: string;
106
+ /** `function_call` / `mcp_call`: serialized JSON arguments. */
107
+ arguments?: string;
108
+ /** `function_call` / `tool_call`: correlation id for a paired result. */
109
+ call_id?: string;
110
+ /** Tool result payload (shape depends on the tool kind). */
111
+ output?: unknown;
112
+ [key: string]: unknown;
113
+ }
114
+ /**
115
+ * One output item produced by a Responses-API response, discriminated by
116
+ * `type`. Modelled in the same spirit as `MessageContent`: visible
117
+ * `'message'`, optional `'reasoning'` trail, and `tool` activity.
118
+ */
119
+ export type ResponseOutput = ResponseOutputMessage | ResponseOutputReasoning | ResponseOutputTool;
120
+ /**
121
+ * Attachment metadata stored under `metadata.attachments` on a Responses-API
122
+ * response. chat-kit does not render attachments itself; this type exists so
123
+ * consumers can read them off `StoredResponse.metadata` without redeclaring
124
+ * the shape.
125
+ */
126
+ export interface ResponseAttachment {
127
+ fileId: string;
128
+ fileName: string;
129
+ searchStoreId: string;
130
+ }
131
+ /**
132
+ * One stored response from the OpenAI-style Responses API, as returned by
133
+ * `GET /conversations/:id/responses`. `previous_response_id` chains
134
+ * responses into a tree; `responsesToTree` walks that chain to produce a
135
+ * `ConversationTree`.
136
+ */
137
+ export interface StoredResponse {
138
+ id: string;
139
+ object: 'response';
140
+ created_at: number;
141
+ completed_at: number;
142
+ status: string;
143
+ model: string;
144
+ previous_response_id?: string | null;
145
+ output: ResponseOutput[];
146
+ request_input: Record<string, unknown>[];
147
+ metadata?: Record<string, unknown> & {
148
+ attachments?: ResponseAttachment[];
149
+ };
150
+ conversation?: {
151
+ id: string;
152
+ };
153
+ ancestor_ids?: string[];
154
+ depth?: number;
155
+ }
156
+ /**
157
+ * Raw envelope returned by the Responses list endpoint. The endpoint is not
158
+ * paginated, so chat-kit unwraps `data` and exposes `StoredResponse[]` to
159
+ * callers; this type is kept exported for users implementing or mocking the
160
+ * `HttpClient`.
161
+ */
162
+ export interface ResponseList {
163
+ object: 'list';
164
+ data: StoredResponse[];
165
+ }
166
+ /**
167
+ * Convert an OpenAI Responses API list (already ordered by `created_at`
168
+ * ascending) into a chat-kit `ConversationTree`.
169
+ *
170
+ * The caller guarantees ordering, which lets us build the tree in a single
171
+ * pass: each response's `previous_response_id` always points to a response
172
+ * we have already processed, so we can wire its messages onto the parent's
173
+ * last message immediately. Sibling responses (same `previous_response_id`)
174
+ * surface as branches; the latest one wins as the active branch.
175
+ *
176
+ * Pair with `useMessageHandler().setTree(responsesToTree(responses))` when
177
+ * you want to hydrate a handler.
178
+ */
179
+ export declare function responsesToTree(responses: StoredResponse[]): ConversationTree;
180
+ //# sourceMappingURL=responses-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responses-api.d.ts","sourceRoot":"","sources":["../../src/adapters/responses-api.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EACV,gBAAgB,EAIjB,MAAM,UAAU,CAAC;AAMlB;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,aAAa,GAAG,MAAM,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,kBAAkB,EAAE,CAAC;CACpC;AAED;;;;;GAKG;AACH,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,gBAAgB,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,kBAAkB,EAAE,CAAC;CACpC;AAED;;;;GAIG;AACH,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,kBAAkB,EAAE,CAAC;IACnC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GACzB,sBAAsB,GACtB,yBAAyB,GACzB,0BAA0B,CAAC;AAE/B;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,SAAS,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,WAAW,GAAG,MAAM,CAAC;IAC3B,OAAO,EAAE,MAA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;AAEvB;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,UAAU,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;QACnC,WAAW,CAAC,EAAE,kBAAkB,EAAE,CAAC;KACpC,CAAC;IACF,YAAY,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,cAAc,EAAE,CAAC;CACxB;AA8ID;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,cAAc,EAAE,GAAG,gBAAgB,CAkE7E"}
@@ -0,0 +1,153 @@
1
+ import { g as generateId } from "../generateId-BHf0W4Rq.js";
2
+ function extractMessageText(content) {
3
+ if (typeof content === "string") return content.trim();
4
+ return extractTextFromParts(content);
5
+ }
6
+ function extractTextFromParts(parts) {
7
+ let text = "";
8
+ for (const part of parts) {
9
+ if (part.type === "output_text" || part.type === "text") {
10
+ text += part.text ?? "";
11
+ }
12
+ }
13
+ return text.trim();
14
+ }
15
+ function extractReasoningText(parts) {
16
+ let text = "";
17
+ for (const part of parts) {
18
+ if (part.type === "reasoning_text") {
19
+ text += part.text ?? "";
20
+ }
21
+ }
22
+ return text.trim();
23
+ }
24
+ function textPart(text, id) {
25
+ return { type: "text", id: id ?? generateId(), text, status: "completed" };
26
+ }
27
+ function toAssistantParts(resp) {
28
+ const parts = [];
29
+ for (const out of resp.output ?? []) {
30
+ switch (out.type) {
31
+ case "reasoning": {
32
+ const text = extractReasoningText(out.content);
33
+ parts.push({
34
+ type: "reasoning",
35
+ id: out.id,
36
+ ...text ? { text } : {},
37
+ status: "completed"
38
+ });
39
+ break;
40
+ }
41
+ case "message": {
42
+ if (out.role !== "assistant") break;
43
+ const text = extractMessageText(out.content);
44
+ if (!text) break;
45
+ parts.push(textPart(text, out.id || void 0));
46
+ break;
47
+ }
48
+ // Actual tool invocations surface as tool parts. `mcp_list_tools` is
49
+ // informational discovery (the server advertising tools) rather than
50
+ // a call the assistant made, so it is intentionally skipped.
51
+ case "mcp_call":
52
+ case "function_call":
53
+ case "tool_call": {
54
+ parts.push({
55
+ type: "tool",
56
+ id: out.id,
57
+ name: out.name ?? out.type
58
+ });
59
+ break;
60
+ }
61
+ }
62
+ }
63
+ return parts;
64
+ }
65
+ function getAssistantNodeId(resp) {
66
+ for (const out of resp.output ?? []) {
67
+ if (out.type === "message" && out.role === "assistant" && out.id) {
68
+ return out.id;
69
+ }
70
+ }
71
+ return `assistant-${resp.id}`;
72
+ }
73
+ function extractInputText(rawContent) {
74
+ if (typeof rawContent === "string") return rawContent.trim();
75
+ if (Array.isArray(rawContent)) {
76
+ return extractTextFromParts(rawContent);
77
+ }
78
+ return "";
79
+ }
80
+ function responseToMessageNodes(resp) {
81
+ const nodes = [];
82
+ if (resp.request_input) {
83
+ for (const [idx, input] of resp.request_input.entries()) {
84
+ const role = input.role;
85
+ const rawContent = input.content;
86
+ const text = extractInputText(rawContent);
87
+ if (role === "user" && text) {
88
+ nodes.push({
89
+ id: `user-${resp.id}-${idx}`,
90
+ role: "user",
91
+ content: [textPart(text)],
92
+ createdAt: new Date(resp.created_at * 1e3)
93
+ });
94
+ }
95
+ }
96
+ }
97
+ const assistantParts = toAssistantParts(resp);
98
+ if (assistantParts.length > 0) {
99
+ nodes.push({
100
+ id: getAssistantNodeId(resp),
101
+ role: "assistant",
102
+ content: assistantParts,
103
+ createdAt: new Date((resp.completed_at ?? resp.created_at) * 1e3)
104
+ });
105
+ }
106
+ return nodes;
107
+ }
108
+ function responsesToTree(responses) {
109
+ if (responses.length === 0) {
110
+ return { nodes: {}, rootId: null };
111
+ }
112
+ const treeNodes = {};
113
+ const tailMessageByResponse = /* @__PURE__ */ new Map();
114
+ let rootMessageId = null;
115
+ function appendNode(node, parentId) {
116
+ treeNodes[node.id] = {
117
+ id: node.id,
118
+ parentId,
119
+ childrenIds: [],
120
+ activeChildIndex: 0,
121
+ role: node.role,
122
+ content: node.content,
123
+ status: "completed",
124
+ createdAt: node.createdAt
125
+ };
126
+ if (parentId !== null) {
127
+ const parent = treeNodes[parentId];
128
+ if (parent) {
129
+ parent.childrenIds.push(node.id);
130
+ parent.activeChildIndex = parent.childrenIds.length - 1;
131
+ }
132
+ }
133
+ }
134
+ for (const resp of responses) {
135
+ const parentResponseId = resp.previous_response_id && tailMessageByResponse.has(resp.previous_response_id) ? resp.previous_response_id : null;
136
+ let chainParent = parentResponseId !== null ? tailMessageByResponse.get(parentResponseId) ?? null : null;
137
+ const messageNodes = responseToMessageNodes(resp);
138
+ let firstId = null;
139
+ for (const node of messageNodes) {
140
+ appendNode(node, chainParent);
141
+ if (firstId === null) firstId = node.id;
142
+ chainParent = node.id;
143
+ }
144
+ if (rootMessageId === null && firstId !== null) {
145
+ rootMessageId = firstId;
146
+ }
147
+ tailMessageByResponse.set(resp.id, chainParent);
148
+ }
149
+ return { nodes: treeNodes, rootId: rootMessageId };
150
+ }
151
+ export {
152
+ responsesToTree
153
+ };
@@ -4,8 +4,8 @@ type __VLS_Slots = {} & {
4
4
  default?: (props: typeof __VLS_8) => any;
5
5
  };
6
6
  declare const __VLS_base: import("vue").DefineComponent<CkPromptActionButtonProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<CkPromptActionButtonProps> & Readonly<{}>, {
7
- disabled: boolean;
8
7
  type: "button" | "submit";
8
+ disabled: boolean;
9
9
  loading: boolean;
10
10
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
11
11
  declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
@@ -4,11 +4,19 @@ declare const meta: Meta<typeof CkConversation>;
4
4
  export default meta;
5
5
  type Story = StoryObj<typeof meta>;
6
6
  /**
7
- * Drop-in conversation UI. Pass `messages` with `role`, `content`, and `status`
8
- * fields and CkConversation renders user bubbles, assistant markdown, avatars,
9
- * and a copy button on each reply.
7
+ * Drop-in conversation UI. Pass `messages` with `role`, `content` (a list of
8
+ * text / tool / reasoning parts), and `status` fields and CkConversation
9
+ * renders user bubbles, assistant markdown, avatars, and a copy button on
10
+ * each reply.
10
11
  */
11
12
  export declare const Default: Story;
13
+ /**
14
+ * Demonstrates a chain-of-thought assistant turn with reasoning and tool
15
+ * calls in `message.content`. By default only text parts are rendered, so
16
+ * use `#agent-message-content` to opt-in to a custom rendering of the
17
+ * non-text parts. The host owns the visual treatment for those segments.
18
+ */
19
+ export declare const ChainOfThought: Story;
12
20
  /**
13
21
  * Uses a remote avatar image (with fallback text). Use when you want a
14
22
  * branded agent identity in each reply.
@@ -1 +1 @@
1
- {"version":3,"file":"CkConversation.stories.d.ts","sourceRoot":"","sources":["../../../../src/components/composed/CkConversation/CkConversation.stories.ts"],"names":[],"mappings":"AAIA,OAAO,cAAc,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AA8D3D,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,cAAc,CAkCrC,CAAC;AAEF,eAAe,IAAI,CAAC;AACpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAiNnC;;;;GAIG;AACH,eAAO,MAAM,OAAO,EAAE,KAUrB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,QAAQ,EAAE,KAUtB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,KAYtC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,MAAM,EAAE,KASpB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,KAe5B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,EAAE,KA8B/B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,qBAAqB,EAAE,KAiBnC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,KAiBpC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,KAsFjC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,EAAE,KAmBvC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,KAgDjC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,KAAK,EAAE,KAMnB,CAAC"}
1
+ {"version":3,"file":"CkConversation.stories.d.ts","sourceRoot":"","sources":["../../../../src/components/composed/CkConversation/CkConversation.stories.ts"],"names":[],"mappings":"AAQA,OAAO,cAAc,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAiH3D,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,cAAc,CAkCrC,CAAC;AAEF,eAAe,IAAI,CAAC;AACpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAqTnC;;;;;GAKG;AACH,eAAO,MAAM,OAAO,EAAE,KAUrB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,KAyB5B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,QAAQ,EAAE,KAUtB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,KAYtC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,MAAM,EAAE,KASpB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,KAe5B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,EAAE,KAmC/B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,qBAAqB,EAAE,KAiBnC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,KAiBpC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,KA4GjC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,EAAE,KAmBvC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,KAoDjC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,KAAK,EAAE,KAMnB,CAAC"}
@@ -25,7 +25,11 @@ type __VLS_Slots = {
25
25
  'agent-message-header': (props: {
26
26
  message: BaseMessage;
27
27
  }) => void;
28
- /** Replace the agent message body */
28
+ /**
29
+ * Replace the agent message body. Receives the full `BaseMessage` so the
30
+ * consumer can inspect every content part (text, tool calls, reasoning)
31
+ * and render them however they want.
32
+ */
29
33
  'agent-message-content': (props: {
30
34
  message: BaseMessage;
31
35
  }) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"CkConversation.vue.d.ts","sourceRoot":"","sources":["../../../../src/components/composed/CkConversation/CkConversation.vue"],"names":[],"mappings":"AAsJA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAMlD,OAAO,KAAK,EAAE,mBAAmB,EAA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AAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
1
+ {"version":3,"file":"CkConversation.vue.d.ts","sourceRoot":"","sources":["../../../../src/components/composed/CkConversation/CkConversation.vue"],"names":[],"mappings":"AAkKA,OAAO,KAAK,EAAE,WAAW,EAAsB,MAAM,gBAAgB,CAAC;AAMtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAkBnD,KAAK,WAAW,GAAG;IACjB,gDAAgD;IAChD,cAAc,EAAE,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,WAAW,CAAA;KAAE,KAAK,IAAI,CAAC;IAC1D,yDAAyD;IACzD,sBAAsB,EAAE,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,WAAW,CAAA;KAAE,KAAK,IAAI,CAAC;IAClE,iDAAiD;IACjD,eAAe,EAAE,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,WAAW,CAAA;KAAE,KAAK,IAAI,CAAC;IAC3D,oCAAoC;IACpC,oBAAoB,EAAE,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,WAAW,CAAA;KAAE,KAAK,IAAI,CAAC;IAChE,8EAA8E;IAC9E,4BAA4B,EAAE,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,WAAW,CAAA;KAAE,KAAK,IAAI,CAAC;IACxE,uCAAuC;IACvC,sBAAsB,EAAE,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,WAAW,CAAA;KAAE,KAAK,IAAI,CAAC;IAClE;;;;OAIG;IACH,uBAAuB,EAAE,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,WAAW,CAAA;KAAE,KAAK,IAAI,CAAC;IACnE,mDAAmD;IACnD,sBAAsB,EAAE,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,WAAW,CAAA;KAAE,KAAK,IAAI,CAAC;IAClE,qEAAqE;IACrE,0BAA0B,EAAE,CAAC,KAAK,EAAE;QAClC,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;KAClB,KAAK,IAAI,CAAC;CACZ,CAAC;AA2RF,QAAA,MAAM,UAAU;;;;6EAGd,CAAC;AACH,QAAA,MAAM,YAAY,EAAS,eAAe,CAAC,OAAO,UAAU,EAAE,WAAW,CAAC,CAAC;wBACtD,OAAO,YAAY;AAAxC,wBAAyC;AAWzC,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
@@ -1,4 +1,4 @@
1
- import { _, a, b, C, c, d, e, f, g, h, i, j, k, l, m, n, o, p } from "../CkInput.vue_vue_type_script_setup_true_lang-CyGLItQZ.js";
1
+ import { _, a, b, C, c, d, e, f, g, h, i, j, k, l, m, n, o, p } from "../CkInput.vue_vue_type_script_setup_true_lang-C5C09u0z.js";
2
2
  export {
3
3
  _ as CkAgentMessage,
4
4
  a as CkConversation,
@@ -0,0 +1,7 @@
1
+ import type { DocumentUploadConfig, DocumentUploadProvider } from './types';
2
+ import { createDocumentUploadProvider } from './useFileUploadWrapper';
3
+ export declare const defaultDocumentUploadConfig: DocumentUploadConfig;
4
+ declare const useDocumentUploadWithDefaultConfig: (conversationIdRef: import("vue").MaybeRef<string>) => import("./types").DocumentUploadReturn;
5
+ export { useDocumentUploadWithDefaultConfig, createDocumentUploadProvider };
6
+ export type { DocumentUploadConfig, DocumentUploadProvider };
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/composables/fileUpload/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAItE,eAAO,MAAM,2BAA2B,EAAE,oBAsEzC,CAAC;AAEF,QAAA,MAA2B,kCAAkC,+FACF,CAAC;AAE5D,OAAO,EAAE,kCAAkC,EAAE,4BAA4B,EAAE,CAAC;AAE5E,YAAY,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,CAAC"}