hermes-agent-web-chat 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/dist/hermes-agent-web-chat.css +10 -0
- package/dist/hermes-agent-web-chat.js +10574 -0
- package/dist/hermes-agent-web-chat.umd.cjs +57 -0
- package/dist/types/api.d.ts +28 -0
- package/dist/types/components/ApiExplorer.vue.d.ts +2 -0
- package/dist/types/components/ChatInput.vue.d.ts +2 -0
- package/dist/types/components/ChatView.vue.d.ts +2 -0
- package/dist/types/components/HermesChat.vue.d.ts +8 -0
- package/dist/types/components/Markdown.vue.d.ts +5 -0
- package/dist/types/components/MessageItem.vue.d.ts +6 -0
- package/dist/types/components/ProcessPanel.vue.d.ts +8 -0
- package/dist/types/components/Sidebar.vue.d.ts +2 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/inject.d.ts +5 -0
- package/dist/types/store.d.ts +37 -0
- package/dist/types/types.d.ts +110 -0
- package/dist/types/utils.d.ts +14 -0
- package/package.json +45 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AttachedFile, HermesConfig, StreamEvent } from './types';
|
|
2
|
+
/** 通用请求:返回状态码与原始文本,供 API 调试台使用 */
|
|
3
|
+
export declare function apiRequest(cfg: HermesConfig, method: string, subPath: string, body?: unknown, signal?: AbortSignal): Promise<{
|
|
4
|
+
status: number;
|
|
5
|
+
statusText: string;
|
|
6
|
+
headers: Headers;
|
|
7
|
+
text: string;
|
|
8
|
+
}>;
|
|
9
|
+
/** 流式 SSE 请求:逐行回调,供 /v1/responses、/v1/runs/{id}/events 等端点使用 */
|
|
10
|
+
export declare function apiStream(cfg: HermesConfig, method: string, subPath: string, body: unknown | undefined, onLine: (line: string) => void, signal?: AbortSignal): Promise<{
|
|
11
|
+
status: number;
|
|
12
|
+
statusText: string;
|
|
13
|
+
}>;
|
|
14
|
+
/** 健康检查(探活) */
|
|
15
|
+
export declare function healthProbe(cfg: HermesConfig): Promise<boolean>;
|
|
16
|
+
/** 删除服务端存储的响应(清理会话时使用) */
|
|
17
|
+
export declare function deleteResponse(cfg: HermesConfig, responseId: string): Promise<void>;
|
|
18
|
+
interface SendParams {
|
|
19
|
+
cfg: HermesConfig;
|
|
20
|
+
input: string;
|
|
21
|
+
conversation?: string;
|
|
22
|
+
instructions?: string;
|
|
23
|
+
files?: AttachedFile[];
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
onEvent: (ev: StreamEvent) => void;
|
|
26
|
+
}
|
|
27
|
+
export declare function streamResponse(p: SendParams): Promise<void>;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
export default _default;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
export default _default;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
export default _default;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { HermesChatProps } from '../types';
|
|
2
|
+
declare const _default: import("vue").DefineComponent<HermesChatProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<HermesChatProps> & Readonly<{}>, {
|
|
3
|
+
model: string;
|
|
4
|
+
title: string;
|
|
5
|
+
storageKey: string;
|
|
6
|
+
defaultView: "chat" | "api";
|
|
7
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
text: string;
|
|
3
|
+
};
|
|
4
|
+
declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
5
|
+
export default _default;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ChatMessage } from '../types';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
message: ChatMessage;
|
|
4
|
+
};
|
|
5
|
+
declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ProcessStep } from '../types';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
steps: ProcessStep[];
|
|
4
|
+
reasoning: string;
|
|
5
|
+
streaming: boolean;
|
|
6
|
+
};
|
|
7
|
+
declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
export default _default;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Plugin } from 'vue';
|
|
2
|
+
import HermesChat from './components/HermesChat.vue';
|
|
3
|
+
|
|
4
|
+
export { HermesChat };
|
|
5
|
+
export { createHermesStore } from './store';
|
|
6
|
+
export type { HermesStore, HermesStoreOptions } from './store';
|
|
7
|
+
export { useHermes, HermesKey } from './inject';
|
|
8
|
+
export type { HermesChatProps, HermesConfig, Conversation, ChatMessage, UserMessage, AssistantMessage, AttachedFile, FileMeta, StreamEvent, } from './types';
|
|
9
|
+
declare const HermesChatPlugin: Plugin;
|
|
10
|
+
export default HermesChatPlugin;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type ComputedRef } from 'vue';
|
|
2
|
+
import type { AttachedFile, Conversation, HermesConfig } from './types';
|
|
3
|
+
type HealthState = 'unknown' | 'online' | 'offline' | 'checking';
|
|
4
|
+
interface State {
|
|
5
|
+
conversations: Conversation[];
|
|
6
|
+
currentConversationId: string;
|
|
7
|
+
streaming: boolean;
|
|
8
|
+
error: string;
|
|
9
|
+
systemInstructions: string;
|
|
10
|
+
health: HealthState;
|
|
11
|
+
ready: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface HermesStoreOptions {
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
token?: string;
|
|
16
|
+
model?: string;
|
|
17
|
+
instructions?: string;
|
|
18
|
+
storageKey?: string;
|
|
19
|
+
uploadHandler?: (file: File) => Promise<string>;
|
|
20
|
+
}
|
|
21
|
+
export interface HermesStore {
|
|
22
|
+
config: HermesConfig;
|
|
23
|
+
state: State;
|
|
24
|
+
currentConversation: ComputedRef<Conversation | undefined>;
|
|
25
|
+
uploadHandler?: (file: File) => Promise<string>;
|
|
26
|
+
init(): Promise<void>;
|
|
27
|
+
checkHealth(): Promise<void>;
|
|
28
|
+
newConversation(): void;
|
|
29
|
+
deleteConversation(id: string): void;
|
|
30
|
+
selectConversation(id: string): void;
|
|
31
|
+
setSystemInstructions(v: string): void;
|
|
32
|
+
sendMessage(text: string, files?: AttachedFile[]): Promise<void>;
|
|
33
|
+
stopStreaming(): void;
|
|
34
|
+
updateConfig(opts: Partial<HermesStoreOptions>): void;
|
|
35
|
+
}
|
|
36
|
+
export declare function createHermesStore(opts: HermesStoreOptions): HermesStore;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/** Hermes 后端连接配置(组件内部使用) */
|
|
2
|
+
export interface HermesConfig {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
token?: string;
|
|
5
|
+
model: string;
|
|
6
|
+
}
|
|
7
|
+
/** <HermesChat> 组件 props */
|
|
8
|
+
export interface HermesChatProps {
|
|
9
|
+
/** Hermes 后端地址,例如 http://localhost:8642 */
|
|
10
|
+
baseUrl: string;
|
|
11
|
+
/** 可选 Bearer token;为空则不附加 Authorization 头 */
|
|
12
|
+
token?: string;
|
|
13
|
+
/** 模型名(仅展示用),默认 hermes-agent */
|
|
14
|
+
model?: string;
|
|
15
|
+
/** 初始系统指令(用户仍可在面板内修改) */
|
|
16
|
+
instructions?: string;
|
|
17
|
+
/** 顶部品牌标题,默认 Hermes Agent */
|
|
18
|
+
title?: string;
|
|
19
|
+
/** localStorage 命名空间,默认 default;多实例隔离用不同 key */
|
|
20
|
+
storageKey?: string;
|
|
21
|
+
/** 自定义文件上传:返回公开 URL;不提供则图片走 data URL、文本内联、二进制拒绝 */
|
|
22
|
+
uploadHandler?: (file: File) => Promise<string>;
|
|
23
|
+
/** 初始视图,默认 chat */
|
|
24
|
+
defaultView?: 'chat' | 'api';
|
|
25
|
+
}
|
|
26
|
+
export interface AttachedFile {
|
|
27
|
+
name: string;
|
|
28
|
+
type: string;
|
|
29
|
+
size: number;
|
|
30
|
+
kind: 'image' | 'text' | 'binary';
|
|
31
|
+
url?: string;
|
|
32
|
+
dataUrl?: string;
|
|
33
|
+
text?: string;
|
|
34
|
+
uploading?: boolean;
|
|
35
|
+
uploadError?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface FileMeta {
|
|
38
|
+
name: string;
|
|
39
|
+
type: string;
|
|
40
|
+
size: number;
|
|
41
|
+
kind: 'image' | 'text' | 'binary';
|
|
42
|
+
url?: string;
|
|
43
|
+
dataUrl?: string;
|
|
44
|
+
text?: string;
|
|
45
|
+
}
|
|
46
|
+
export type StepKind = 'tool_call' | 'tool_result' | 'reasoning';
|
|
47
|
+
export interface ProcessStep {
|
|
48
|
+
kind: StepKind;
|
|
49
|
+
callId?: string;
|
|
50
|
+
name?: string;
|
|
51
|
+
arguments?: string;
|
|
52
|
+
output?: string;
|
|
53
|
+
status?: 'running' | 'done';
|
|
54
|
+
text?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface UserMessage {
|
|
57
|
+
id: string;
|
|
58
|
+
role: 'user';
|
|
59
|
+
content: string;
|
|
60
|
+
files?: FileMeta[];
|
|
61
|
+
}
|
|
62
|
+
export interface AssistantMessage {
|
|
63
|
+
id: string;
|
|
64
|
+
role: 'assistant';
|
|
65
|
+
text: string;
|
|
66
|
+
reasoning: string;
|
|
67
|
+
steps: ProcessStep[];
|
|
68
|
+
status: 'streaming' | 'done' | 'error' | 'aborted';
|
|
69
|
+
usage: Record<string, unknown> | null;
|
|
70
|
+
error: string | null;
|
|
71
|
+
responseId: string | null;
|
|
72
|
+
}
|
|
73
|
+
export type ChatMessage = UserMessage | AssistantMessage;
|
|
74
|
+
export interface Conversation {
|
|
75
|
+
id: string;
|
|
76
|
+
title: string;
|
|
77
|
+
createdAt: number;
|
|
78
|
+
updatedAt: number;
|
|
79
|
+
messages: ChatMessage[];
|
|
80
|
+
}
|
|
81
|
+
export type StreamEvent = {
|
|
82
|
+
kind: 'created';
|
|
83
|
+
responseId?: string;
|
|
84
|
+
} | {
|
|
85
|
+
kind: 'text_delta';
|
|
86
|
+
delta: string;
|
|
87
|
+
} | {
|
|
88
|
+
kind: 'reasoning';
|
|
89
|
+
delta: string;
|
|
90
|
+
} | {
|
|
91
|
+
kind: 'tool_call';
|
|
92
|
+
callId: string;
|
|
93
|
+
name: string;
|
|
94
|
+
arguments: string;
|
|
95
|
+
} | {
|
|
96
|
+
kind: 'tool_result';
|
|
97
|
+
callId: string;
|
|
98
|
+
output: string;
|
|
99
|
+
} | {
|
|
100
|
+
kind: 'completed';
|
|
101
|
+
responseId?: string;
|
|
102
|
+
usage?: Record<string, unknown>;
|
|
103
|
+
} | {
|
|
104
|
+
kind: 'error';
|
|
105
|
+
message: string;
|
|
106
|
+
} | {
|
|
107
|
+
kind: 'other';
|
|
108
|
+
type: string;
|
|
109
|
+
raw: unknown;
|
|
110
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AttachedFile } from './types';
|
|
2
|
+
export declare function classifyFile(file: File): AttachedFile;
|
|
3
|
+
export declare function readFileAsDataUrl(file: File): Promise<string>;
|
|
4
|
+
export declare function readFileAsText(file: File): Promise<string>;
|
|
5
|
+
export declare function formatSize(n: number): string;
|
|
6
|
+
export declare function formatTime(ts: number): string;
|
|
7
|
+
export declare function toolLabel(name?: string): string;
|
|
8
|
+
export declare function tryPrettyJson(s: string): string;
|
|
9
|
+
/** 归一化 usage 对象为 {input, output, total},兼容 Responses / Chat Completions 字段名 */
|
|
10
|
+
export declare function normalizeUsage(u: Record<string, unknown> | null | undefined): {
|
|
11
|
+
input: number;
|
|
12
|
+
output: number;
|
|
13
|
+
total: number;
|
|
14
|
+
} | null;
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "hermes-agent-web-chat",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Vue 3 组件包:接入 Hermes 适配智能体的对话界面与 HTTP API 调试台",
|
|
6
|
+
"keywords": ["vue", "vue3", "hermes", "agent", "chat", "component"],
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"main": "./dist/hermes-agent-web-chat.umd.cjs",
|
|
9
|
+
"module": "./dist/hermes-agent-web-chat.js",
|
|
10
|
+
"types": "./dist/types/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/types/index.d.ts",
|
|
14
|
+
"import": "./dist/hermes-agent-web-chat.js",
|
|
15
|
+
"require": "./dist/hermes-agent-web-chat.umd.cjs"
|
|
16
|
+
},
|
|
17
|
+
"./style.css": "./dist/hermes-agent-web-chat.css"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"sideEffects": ["**/*.css"],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"dev": "vite",
|
|
25
|
+
"build": "vue-tsc -b && vite build && vue-tsc -p tsconfig.build.json && node scripts/strip-css-imports.mjs",
|
|
26
|
+
"preview": "vite preview",
|
|
27
|
+
"typecheck": "vue-tsc -b",
|
|
28
|
+
"prepublishOnly": "npm run build"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"vue": "^3.4.0"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^20.12.12",
|
|
36
|
+
"@vitejs/plugin-vue": "^5.0.4",
|
|
37
|
+
"dompurify": "^3.1.5",
|
|
38
|
+
"highlight.js": "^11.9.0",
|
|
39
|
+
"marked": "^12.0.2",
|
|
40
|
+
"typescript": "^5.4.5",
|
|
41
|
+
"vite": "^5.2.11",
|
|
42
|
+
"vue": "^3.4.27",
|
|
43
|
+
"vue-tsc": "^2.0.19"
|
|
44
|
+
}
|
|
45
|
+
}
|