@veltra/ai 2.1.7 → 2.1.9

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.
@@ -3,7 +3,7 @@ import { AskQuestionItem } from "../tools/ask-question/ask-question.js";
3
3
  import "../tools/index.js";
4
4
  import { ChatSessionEvent } from "./session.js";
5
5
  //#region src/chat/fold.d.ts
6
- interface ChatPendingApproval {
6
+ export interface ChatPendingApproval {
7
7
  approvalId: string;
8
8
  toolName: string;
9
9
  callId?: string;
@@ -11,7 +11,7 @@ interface ChatPendingApproval {
11
11
  rpcId: string;
12
12
  }
13
13
  /** 历史回放与实时 onEvent 共用的折叠状态 */
14
- interface ChatFoldState {
14
+ export interface ChatFoldState {
15
15
  lastSeq: number | null;
16
16
  messages: ChatMessage[];
17
17
  queue: ChatQueuedMessage[];
@@ -30,12 +30,11 @@ interface ChatFoldState {
30
30
  message: string;
31
31
  } | null;
32
32
  }
33
- declare function createFoldState(): ChatFoldState;
33
+ export declare function createFoldState(): ChatFoldState;
34
34
  /**
35
35
  * 纯函数 fold:历史回放与实时 onEvent 走同一套。
36
36
  * 后到的更小/重复 seq 不覆盖已应用事件。
37
37
  */
38
- declare function foldSessionEvent(state: ChatFoldState, event: ChatSessionEvent): ChatFoldState;
38
+ export declare function foldSessionEvent(state: ChatFoldState, event: ChatSessionEvent): ChatFoldState;
39
39
  //#endregion
40
- export { ChatFoldState, ChatPendingApproval, createFoldState, foldSessionEvent };
41
40
  //# sourceMappingURL=fold.d.ts.map
@@ -3,7 +3,7 @@ import { AskQuestionItem } from "../tools/ask-question/ask-question.js";
3
3
  import "../tools/index.js";
4
4
  //#region src/chat/session.d.ts
5
5
  /** 归一化后的服务端会话事件(协议无关) */
6
- type ChatSessionEvent = {
6
+ export type ChatSessionEvent = {
7
7
  type: 'user/message';
8
8
  messageId: string;
9
9
  seq: number;
@@ -78,7 +78,7 @@ type ChatSessionEvent = {
78
78
  message: string;
79
79
  };
80
80
  /** 服务端会话 transport:对象形态,与函数型 ChatTransport 互斥 */
81
- interface ChatSessionTransport {
81
+ export interface ChatSessionTransport {
82
82
  readonly kind: 'session';
83
83
  open(handlers: {
84
84
  onEvent(event: ChatSessionEvent): void;
@@ -97,7 +97,7 @@ interface ChatSessionTransport {
97
97
  * 协议翻译层:订阅事件流、把动作打到远端、拉历史。
98
98
  * 时序校验 / dispose / 断线补拉 / in-flight 去重由 createServerTransport 完成。
99
99
  */
100
- interface ChatSessionAdapter {
100
+ export interface ChatSessionAdapter {
101
101
  subscribe(handlers: {
102
102
  onEvent(event: ChatSessionEvent): void;
103
103
  onDisconnect?(): void;
@@ -112,12 +112,11 @@ interface ChatSessionAdapter {
112
112
  selectModel(provider: string, model: string): Promise<void>;
113
113
  }
114
114
  /** 仅带 kind: 'session' 的对象为 true;函数 / null / 无 kind 均为 false */
115
- declare function isServerTransport(t: unknown): t is ChatSessionTransport;
115
+ export declare function isServerTransport(t: unknown): t is ChatSessionTransport;
116
116
  /**
117
117
  * 用 adapter 包出 ChatSessionTransport。
118
118
  * 包内完成 seq 校验、disposer、断线补拉、动作 in-flight 去重。
119
119
  */
120
- declare function createServerTransport(adapter: ChatSessionAdapter): ChatSessionTransport;
120
+ export declare function createServerTransport(adapter: ChatSessionAdapter): ChatSessionTransport;
121
121
  //#endregion
122
- export { ChatSessionAdapter, ChatSessionEvent, ChatSessionTransport, createServerTransport, isServerTransport };
123
122
  //# sourceMappingURL=session.d.ts.map
@@ -2,7 +2,7 @@ import { ChatTransport } from "../types.js";
2
2
  import { ChatModelOption, ChatProvider } from "../../providers/types.js";
3
3
  //#region src/chat/transports/openai.d.ts
4
4
  /** createOpenAITransport 的配置项(多 Provider) */
5
- interface OpenAITransportOptions {
5
+ export interface OpenAITransportOptions {
6
6
  /** 至少一个 Provider;模型 id 须跨 Provider 全局唯一 */
7
7
  providers: ChatProvider[];
8
8
  /** 全局额外请求头(与各 Provider headers 合并,Provider 优先) */
@@ -11,7 +11,7 @@ interface OpenAITransportOptions {
11
11
  body?: Record<string, unknown>;
12
12
  }
13
13
  /** 带扁平模型列表元数据的 OpenAI 兼容 transport */
14
- type OpenAITransport = ChatTransport & {
14
+ export type OpenAITransport = ChatTransport & {
15
15
  /** 供 UI 使用的扁平模型列表 */
16
16
  readonly models: ChatModelOption[];
17
17
  /** 默认模型 id(首个 Provider 的首个模型) */
@@ -21,7 +21,6 @@ type OpenAITransport = ChatTransport & {
21
21
  * 创建 OpenAI 兼容协议的传输层(chat/completions SSE)。
22
22
  * 按 request.model 路由到对应 Provider 的 endpoint;手写 fetch + SSE,无第三方依赖。
23
23
  */
24
- declare function createOpenAITransport(options: OpenAITransportOptions): OpenAITransport;
24
+ export declare function createOpenAITransport(options: OpenAITransportOptions): OpenAITransport;
25
25
  //#endregion
26
- export { OpenAITransport, OpenAITransportOptions, createOpenAITransport };
27
26
  //# sourceMappingURL=openai.d.ts.map
@@ -1,7 +1,7 @@
1
1
  import { Component } from "vue";
2
2
  //#region src/chat/types.d.ts
3
3
  /** 聊天附件(首版仅支持图片) */
4
- interface ChatAttachment {
4
+ export interface ChatAttachment {
5
5
  /** 文件名 */
6
6
  name: string;
7
7
  /** MIME 类型 */
@@ -12,9 +12,9 @@ interface ChatAttachment {
12
12
  dataUrl: string;
13
13
  }
14
14
  /** 工具调用状态 */
15
- type ToolCallStatus = 'pending' | 'awaiting-confirm' | 'running' | 'success' | 'error' | 'rejected';
15
+ export type ToolCallStatus = 'pending' | 'awaiting-confirm' | 'running' | 'success' | 'error' | 'rejected';
16
16
  /** 一次工具调用 */
17
- interface ChatToolCall {
17
+ export interface ChatToolCall {
18
18
  /** 调用 id(由模型生成) */
19
19
  id: string;
20
20
  /** 工具名 */
@@ -31,7 +31,7 @@ interface ChatToolCall {
31
31
  view?: unknown;
32
32
  }
33
33
  /** 聊天消息 */
34
- interface ChatMessage {
34
+ export interface ChatMessage {
35
35
  /** 消息 id */
36
36
  id: string;
37
37
  /** 角色 */
@@ -50,7 +50,7 @@ interface ChatMessage {
50
50
  status?: 'streaming' | 'done' | 'error' | 'aborted';
51
51
  }
52
52
  /** 队列中的待发送消息(会话进行中提交的消息按序排队) */
53
- interface ChatQueuedMessage {
53
+ export interface ChatQueuedMessage {
54
54
  /** 队列项 id */
55
55
  id: string;
56
56
  /** 消息内容 */
@@ -59,7 +59,7 @@ interface ChatQueuedMessage {
59
59
  attachments?: ChatAttachment[];
60
60
  }
61
61
  /** 工具执行上下文 */
62
- interface ChatToolContext {
62
+ export interface ChatToolContext {
63
63
  /** 本次工具调用 */
64
64
  toolCall: ChatToolCall;
65
65
  /** 中断信号(用户点击停止时触发) */
@@ -69,7 +69,7 @@ interface ChatToolContext {
69
69
  * 对话工具定义。
70
70
  * 在不同场景传入不同的工具数组,即可赋予对话助手不同的能力。
71
71
  */
72
- interface ChatTool<A = any> {
72
+ export interface ChatTool<A = any> {
73
73
  /** 工具名(传给模型,需唯一) */
74
74
  name: string;
75
75
  /** 工具描述(传给模型) */
@@ -122,7 +122,7 @@ interface ChatTool<A = any> {
122
122
  * 服务端驱动模式下 tools 的合法形态:纯渲染元信息(执行在服务端)。
123
123
  * 没有 execute / description / parameters / needsConfirm / terminal。
124
124
  */
125
- interface ChatToolMeta {
125
+ export interface ChatToolMeta {
126
126
  /** 与服务端 tool/call.name 匹配 */
127
127
  name: string;
128
128
  /** 覆盖通用图标 */
@@ -141,9 +141,9 @@ interface ChatToolMeta {
141
141
  autoCollapse?: boolean;
142
142
  }
143
143
  /** 作业条项状态:至少区分进行中与终态 */
144
- type ChatJobStatus = 'running' | 'done' | 'error';
144
+ export type ChatJobStatus = 'running' | 'done' | 'error';
145
145
  /** 服务端下发的作业条项 */
146
- interface ChatJob {
146
+ export interface ChatJob {
147
147
  /** 稳定 id */
148
148
  id: string;
149
149
  /** 作业类型(用于图标映射) */
@@ -154,12 +154,12 @@ interface ChatJob {
154
154
  status: ChatJobStatus;
155
155
  }
156
156
  /** 工具自定义渲染组件 / 渲染函数的 props */
157
- interface ChatToolRenderProps {
157
+ export interface ChatToolRenderProps {
158
158
  /** 本次工具调用(含 status/arguments/result/error,可自行渲染进度与错误) */
159
159
  toolCall: ChatToolCall;
160
160
  }
161
161
  /** transport 请求参数 */
162
- interface ChatTransportRequest {
162
+ export interface ChatTransportRequest {
163
163
  /** 完整消息历史(内部模型,transport 自行转换为 wire 格式) */
164
164
  messages: ChatMessage[];
165
165
  /** 系统提示词 */
@@ -177,7 +177,7 @@ interface ChatTransportRequest {
177
177
  * 一次模型请求的 token 用量。
178
178
  * 仅包含接口实际返回的字段;缓存类数字缺省为 undefined,不补 0。
179
179
  */
180
- interface ChatTokenUsage {
180
+ export interface ChatTokenUsage {
181
181
  /** 输入 token */
182
182
  promptTokens: number;
183
183
  /** 输出 token */
@@ -199,7 +199,7 @@ interface ChatTokenUsage {
199
199
  cacheCreationTokens?: number;
200
200
  }
201
201
  /** transport 流式事件回调 */
202
- interface ChatTransportHandlers {
202
+ export interface ChatTransportHandlers {
203
203
  /** 文本增量 */
204
204
  onTextDelta(delta: string): void;
205
205
  /** 思考内容增量 */
@@ -225,7 +225,6 @@ interface ChatTransportHandlers {
225
225
  * 对话传输层抽象。组件不关心具体的 LLM 协议,
226
226
  * 可传入内置的 createOpenAITransport(),也可自行实现接入任意后端。
227
227
  */
228
- type ChatTransport = (request: ChatTransportRequest, handlers: ChatTransportHandlers) => Promise<void> | void;
228
+ export type ChatTransport = (request: ChatTransportRequest, handlers: ChatTransportHandlers) => Promise<void> | void;
229
229
  //#endregion
230
- export { ChatAttachment, ChatJob, ChatJobStatus, ChatMessage, ChatQueuedMessage, ChatTokenUsage, ChatTool, ChatToolCall, ChatToolContext, ChatToolMeta, ChatToolRenderProps, ChatTransport, ChatTransportHandlers, ChatTransportRequest, ToolCallStatus };
231
230
  //# sourceMappingURL=types.d.ts.map
@@ -6,7 +6,7 @@ import "../types/index.js";
6
6
  import { ChatPendingApproval } from "./fold.js";
7
7
  import { Ref } from "vue";
8
8
  //#region src/chat/use-chat.d.ts
9
- interface UseChatOptions {
9
+ export interface UseChatOptions {
10
10
  props: AiChatProps;
11
11
  emit: AiChatEmits;
12
12
  }
@@ -15,7 +15,7 @@ interface UseChatOptions {
15
15
  * 与 UI 解耦,ai-chat.vue 只负责渲染与交互转发。
16
16
  * 函数型 transport 注入内置工具;session transport 不注入、不执行客户端工具。
17
17
  */
18
- declare function useChat(options: UseChatOptions): {
18
+ export declare function useChat(options: UseChatOptions): {
19
19
  messages: Ref<ChatMessage[], ChatMessage[]>;
20
20
  model: Ref<string | undefined, string | undefined>;
21
21
  reasoningLevel: Ref<string | undefined, string | undefined>;
@@ -124,5 +124,4 @@ declare function useChat(options: UseChatOptions): {
124
124
  removeQueued: (id: string) => ChatQueuedMessage | undefined;
125
125
  };
126
126
  //#endregion
127
- export { UseChatOptions, useChat };
128
127
  //# sourceMappingURL=use-chat.d.ts.map
@@ -173,6 +173,8 @@
173
173
  max-width: 800px;
174
174
  display: flex;
175
175
  flex-direction: column;
176
+ padding: var(--u-gap-default) 0;
177
+ box-sizing: border-box;
176
178
  }
177
179
  .u-ai-chat__list {
178
180
  flex: 1;
@@ -1,13 +1,13 @@
1
1
  //#region src/providers/types.d.ts
2
2
  /** 推理等级选项(值不透明,由宿主/服务商约定) */
3
- interface ChatReasoningLevel {
3
+ export interface ChatReasoningLevel {
4
4
  /** 写入请求的值 */
5
5
  value: string;
6
6
  /** UI 文案 */
7
7
  label: string;
8
8
  }
9
9
  /** 单个模型配置 */
10
- interface ChatModel {
10
+ export interface ChatModel {
11
11
  /** 模型 id(跨 Provider 全局唯一) */
12
12
  id: string;
13
13
  /** UI 显示名,缺省取 id */
@@ -20,7 +20,7 @@ interface ChatModel {
20
20
  defaultReasoningLevel?: string;
21
21
  }
22
22
  /** 模型服务商配置(内嵌 models) */
23
- interface ChatProvider {
23
+ export interface ChatProvider {
24
24
  id: string;
25
25
  /** UI 显示名 */
26
26
  label?: string;
@@ -38,10 +38,9 @@ interface ChatProvider {
38
38
  models: ChatModel[];
39
39
  }
40
40
  /** UI / useChat 使用的扁平模型项(带 providerId) */
41
- interface ChatModelOption extends ChatModel {
41
+ export interface ChatModelOption extends ChatModel {
42
42
  providerId: string;
43
43
  providerLabel?: string;
44
44
  }
45
45
  //#endregion
46
- export { ChatModel, ChatModelOption, ChatProvider, ChatReasoningLevel };
47
46
  //# sourceMappingURL=types.d.ts.map
@@ -2,7 +2,7 @@ import "../../chat/types.js";
2
2
  import { Component } from "vue";
3
3
  //#region src/tools/ask-question/ask-question.d.ts
4
4
  /** 单个提问项 */
5
- interface AskQuestionItem {
5
+ export interface AskQuestionItem {
6
6
  /** 问题文案 */
7
7
  question: string;
8
8
  /** 预设选项(单选);缺省为纯文本题 */
@@ -11,20 +11,19 @@ interface AskQuestionItem {
11
11
  placeholder?: string;
12
12
  }
13
13
  /** 一条问答结果 */
14
- interface AskQuestionAnswer {
14
+ export interface AskQuestionAnswer {
15
15
  /** 问题文案 */
16
16
  question: string;
17
17
  /** 用户回答(选中的选项或自定义输入) */
18
18
  answer: string;
19
19
  }
20
20
  /** 提问工具参数(模型输出) */
21
- interface AskQuestionArgs {
21
+ export interface AskQuestionArgs {
22
22
  questions: AskQuestionItem[];
23
23
  }
24
24
  /** 提问工具结果(序列化后回灌模型,渲染层据此展示问答摘要) */
25
- interface AskQuestionResult {
25
+ export interface AskQuestionResult {
26
26
  answers: AskQuestionAnswer[];
27
27
  }
28
28
  //#endregion
29
- export { AskQuestionAnswer, AskQuestionArgs, AskQuestionItem, AskQuestionResult };
30
29
  //# sourceMappingURL=ask-question.d.ts.map
@@ -4,7 +4,7 @@ import { ChatModelOption } from "../providers/types.js";
4
4
  import { Component, Ref } from "vue";
5
5
  import { DeconstructValue } from "@veltra/utils";
6
6
  //#region src/types/ai-chat.d.ts
7
- interface AiChatProps {
7
+ export interface AiChatProps {
8
8
  /** 传输层(必填);函数型 ChatTransport 或 session 对象,可使用 createOpenAITransport / createServerTransport */
9
9
  transport: ChatTransport | ChatSessionTransport;
10
10
  /**
@@ -53,7 +53,7 @@ interface AiChatProps {
53
53
  /** 只读:不展示输入区、欢迎语不可发送、队列无插队/编辑/移除。默认 false */
54
54
  readonly?: boolean;
55
55
  }
56
- interface AiChatEmits {
56
+ export interface AiChatEmits {
57
57
  /** 消息列表变化 */
58
58
  (e: 'update:messages', messages: ChatMessage[]): void;
59
59
  /** 当前模型变化 */
@@ -69,7 +69,7 @@ interface AiChatEmits {
69
69
  /** 模型发起工具调用 */
70
70
  (e: 'tool-call', toolCall: ChatToolCall): void;
71
71
  }
72
- interface _AiChatExposed {
72
+ export interface _AiChatExposed {
73
73
  /** 发送一条用户消息(会话进行中时进入待发送队列) */
74
74
  send: (content: string, attachments?: ChatAttachment[]) => void;
75
75
  /** 中断当前生成(保留待发送队列) */
@@ -91,7 +91,6 @@ interface _AiChatExposed {
91
91
  /** 向队列插入一条消息(beforeId 插到某条之前,缺省追加尾部;空闲时自动消耗队首) */
92
92
  enqueue: (content: string, attachments?: ChatAttachment[], beforeId?: string) => ChatQueuedMessage;
93
93
  }
94
- type AiChatExposed = DeconstructValue<_AiChatExposed>;
94
+ export type AiChatExposed = DeconstructValue<_AiChatExposed>;
95
95
  //#endregion
96
- export { AiChatEmits, AiChatExposed, AiChatProps, _AiChatExposed };
97
96
  //# sourceMappingURL=ai-chat.d.ts.map
@@ -1,27 +1,26 @@
1
1
  //#region src/types/ai-orb.d.ts
2
2
  /** 活体球生命状态:驱动常态动画(平静 / 思考 / 输出) */
3
- type AiOrbStatus = 'idle' | 'thinking' | 'speaking';
3
+ export type AiOrbStatus = 'idle' | 'thinking' | 'speaking';
4
4
  /**
5
5
  * 瞬时表情:播放约 1-2s 后自动回到 status 驱动的常态。
6
6
  * - happy:成功 / 回答完毕 —— 先睁大眼睛,再弯眼大笑 + 点头
7
7
  * - shock:惊讶 —— 睁大眼睛 + 小嘴微张 + 轻微后仰
8
8
  * - frustrated:受挫(如工具调用失败)—— 闭紧眼睛 + 摇头 + 嘴角下撇
9
9
  */
10
- type AiOrbReaction = 'happy' | 'shock' | 'frustrated';
11
- interface AiOrbProps {
10
+ export type AiOrbReaction = 'happy' | 'shock' | 'frustrated';
11
+ export interface AiOrbProps {
12
12
  /** 球体直径(px),默认 48 */
13
13
  size?: number;
14
14
  /** 生命状态,默认 idle */
15
15
  status?: AiOrbStatus;
16
16
  }
17
- interface AiOrbEmits {
17
+ export interface AiOrbEmits {
18
18
  /** 点击球体(球体同时会做 Q 弹反馈) */
19
19
  (e: 'click'): void;
20
20
  }
21
- interface AiOrbExposed {
21
+ export interface AiOrbExposed {
22
22
  /** 播放一次瞬时表情(对应阶段性事件,如回答完毕 / 工具调用失败) */
23
23
  react: (reaction: AiOrbReaction) => void;
24
24
  }
25
25
  //#endregion
26
- export { AiOrbEmits, AiOrbExposed, AiOrbProps, AiOrbReaction, AiOrbStatus };
27
26
  //# sourceMappingURL=ai-orb.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veltra/ai",
3
- "version": "2.1.7",
3
+ "version": "2.1.9",
4
4
  "homepage": "https://github.com/cabinet-fe/ultra-ui#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/cabinet-fe/ultra-ui/issues"
@@ -36,14 +36,14 @@
36
36
  }
37
37
  },
38
38
  "dependencies": {
39
- "markstream-vue": "^2.0.7"
39
+ "markstream-vue": "^2.0.11"
40
40
  },
41
41
  "peerDependencies": {
42
- "@veltra/compositions": "^1.7.4",
43
- "@veltra/desktop": "^1.7.4",
42
+ "@veltra/compositions": "^1.7.14",
43
+ "@veltra/desktop": "^1.7.14",
44
44
  "@veltra/icons": "^1.5.0",
45
- "@veltra/styles": "^1.7.4",
46
- "@veltra/utils": "^1.7.4",
45
+ "@veltra/styles": "^1.7.14",
46
+ "@veltra/utils": "^1.7.14",
47
47
  "vue": ">=3.5.42"
48
48
  }
49
49
  }
@@ -186,6 +186,9 @@ $root-name: ai-chat;
186
186
  max-width: 800px;
187
187
  display: flex;
188
188
  flex-direction: column;
189
+ // 纵向留出呼吸位:首条消息不贴容器顶,滚动时内容不顶边;横向由各消息自身 padding 控制
190
+ padding: fn.use-var(gap, default) 0;
191
+ box-sizing: border-box;
189
192
  }
190
193
 
191
194
  @include m.e(list) {