@modelprofile.com/flexharness 6.0.0 → 7.0.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_ts/00_commitinfo_data.js +1 -1
- package/dist_ts_chat/classes.chatsession.d.ts +37 -0
- package/dist_ts_chat/classes.chatsession.js +102 -0
- package/dist_ts_chat/index.d.ts +2 -0
- package/dist_ts_chat/index.js +2 -0
- package/dist_ts_chat/interfaces.d.ts +72 -0
- package/dist_ts_chat/interfaces.js +2 -0
- package/dist_ts_chat/plugins.d.ts +4 -0
- package/dist_ts_chat/plugins.js +4 -0
- package/dist_ts_chat_cli/components.chatapp.d.ts +10 -0
- package/dist_ts_chat_cli/components.chatapp.js +75 -0
- package/dist_ts_chat_cli/components.inputarea.d.ts +7 -0
- package/dist_ts_chat_cli/components.inputarea.js +18 -0
- package/dist_ts_chat_cli/components.message.d.ts +12 -0
- package/dist_ts_chat_cli/components.message.js +21 -0
- package/dist_ts_chat_cli/components.messagelist.d.ts +9 -0
- package/dist_ts_chat_cli/components.messagelist.js +19 -0
- package/dist_ts_chat_cli/components.statusbar.d.ts +9 -0
- package/dist_ts_chat_cli/components.statusbar.js +15 -0
- package/dist_ts_chat_cli/index.d.ts +2 -0
- package/dist_ts_chat_cli/index.js +2 -0
- package/dist_ts_chat_cli/plugins.d.ts +12 -0
- package/dist_ts_chat_cli/plugins.js +14 -0
- package/dist_ts_chat_cli/startchat.d.ts +18 -0
- package/dist_ts_chat_cli/startchat.js +17 -0
- package/dist_ts_chat_web/flexchat-input.d.ts +21 -0
- package/dist_ts_chat_web/flexchat-input.js +172 -0
- package/dist_ts_chat_web/flexchat-message.d.ts +26 -0
- package/dist_ts_chat_web/flexchat-message.js +174 -0
- package/dist_ts_chat_web/flexchat-window.d.ts +34 -0
- package/dist_ts_chat_web/flexchat-window.js +394 -0
- package/dist_ts_chat_web/index.d.ts +3 -0
- package/dist_ts_chat_web/index.js +4 -0
- package/dist_ts_chat_web/plugins.d.ts +6 -0
- package/dist_ts_chat_web/plugins.js +4 -0
- package/dist_ts_compaction/index.d.ts +2 -0
- package/dist_ts_compaction/index.js +2 -0
- package/dist_ts_compaction/plugins.d.ts +4 -0
- package/dist_ts_compaction/plugins.js +3 -0
- package/dist_ts_compaction/smartagent.compaction.d.ts +14 -0
- package/dist_ts_compaction/smartagent.compaction.js +49 -0
- package/dist_ts_document/index.d.ts +19 -0
- package/dist_ts_document/index.js +55 -0
- package/dist_ts_document/plugins.d.ts +3 -0
- package/dist_ts_document/plugins.js +4 -0
- package/dist_ts_kvm/classes.browserkvm.d.ts +22 -0
- package/dist_ts_kvm/classes.browserkvm.js +271 -0
- package/dist_ts_kvm/classes.kvmterminal.d.ts +8 -0
- package/dist_ts_kvm/classes.kvmterminal.js +88 -0
- package/dist_ts_kvm/commandwrappers.d.ts +14 -0
- package/dist_ts_kvm/commandwrappers.js +58 -0
- package/dist_ts_kvm/index.d.ts +6 -0
- package/dist_ts_kvm/index.js +7 -0
- package/dist_ts_kvm/interfaces.d.ts +106 -0
- package/dist_ts_kvm/interfaces.js +2 -0
- package/dist_ts_kvm/ocr.d.ts +14 -0
- package/dist_ts_kvm/ocr.js +23 -0
- package/dist_ts_kvm/plugins.d.ts +6 -0
- package/dist_ts_kvm/plugins.js +10 -0
- package/dist_ts_kvm/tools.d.ts +15 -0
- package/dist_ts_kvm/tools.js +40 -0
- package/dist_ts_mcp/index.d.ts +86 -0
- package/dist_ts_mcp/index.js +284 -0
- package/dist_ts_mcp/requestcontext.d.ts +11 -0
- package/dist_ts_mcp/requestcontext.js +42 -0
- package/dist_ts_media/index.d.ts +8 -0
- package/dist_ts_media/index.js +21 -0
- package/dist_ts_media/plugins.d.ts +2 -0
- package/dist_ts_media/plugins.js +3 -0
- package/dist_ts_ocr/classes.imageocr.d.ts +19 -0
- package/dist_ts_ocr/classes.imageocr.js +27 -0
- package/dist_ts_ocr/index.d.ts +2 -0
- package/dist_ts_ocr/index.js +3 -0
- package/dist_ts_ocr/ocr.mistral.d.ts +75 -0
- package/dist_ts_ocr/ocr.mistral.js +77 -0
- package/dist_ts_tools/index.d.ts +17 -0
- package/dist_ts_tools/index.js +10 -0
- package/dist_ts_tools/plugins.d.ts +7 -0
- package/dist_ts_tools/plugins.js +6 -0
- package/dist_ts_tools/tool.browser.d.ts +11 -0
- package/dist_ts_tools/tool.browser.js +128 -0
- package/dist_ts_tools/tool.context.d.ts +4 -0
- package/dist_ts_tools/tool.context.js +23 -0
- package/dist_ts_tools/tool.filesystem.d.ts +11 -0
- package/dist_ts_tools/tool.filesystem.js +106 -0
- package/dist_ts_tools/tool.http.d.ts +2 -0
- package/dist_ts_tools/tool.http.js +65 -0
- package/dist_ts_tools/tool.json.d.ts +2 -0
- package/dist_ts_tools/tool.json.js +47 -0
- package/dist_ts_tools/tool.shell.d.ts +15 -0
- package/dist_ts_tools/tool.shell.js +329 -0
- package/dist_ts_tools/utils.truncation.d.ts +10 -0
- package/dist_ts_tools/utils.truncation.js +26 -0
- package/dist_ts_tools_node/index.d.ts +5 -0
- package/dist_ts_tools_node/index.js +4 -0
- package/dist_ts_tools_node/plugins.d.ts +13 -0
- package/dist_ts_tools_node/plugins.js +13 -0
- package/dist_ts_tools_node/tool.context.d.ts +31 -0
- package/dist_ts_tools_node/tool.context.js +837 -0
- package/dist_ts_tools_node/tool.persistence.d.ts +15 -0
- package/dist_ts_tools_node/tool.persistence.js +129 -0
- package/dist_ts_tools_node/tools.local.d.ts +11 -0
- package/dist_ts_tools_node/tools.local.js +15 -0
- package/package.json +112 -4
- package/readme.md +122 -66
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/readme.md +122 -66
- package/ts_chat/classes.chatsession.ts +116 -0
- package/ts_chat/index.ts +8 -0
- package/ts_chat/interfaces.ts +64 -0
- package/ts_chat/plugins.ts +7 -0
- package/ts_chat/readme.md +49 -0
- package/ts_chat_cli/components.chatapp.ts +103 -0
- package/ts_chat_cli/components.inputarea.ts +29 -0
- package/ts_chat_cli/components.message.ts +48 -0
- package/ts_chat_cli/components.messagelist.ts +45 -0
- package/ts_chat_cli/components.statusbar.ts +31 -0
- package/ts_chat_cli/index.ts +2 -0
- package/ts_chat_cli/plugins.ts +21 -0
- package/ts_chat_cli/readme.md +40 -0
- package/ts_chat_cli/startchat.ts +34 -0
- package/ts_chat_web/flexchat-input.ts +184 -0
- package/ts_chat_web/flexchat-message.ts +185 -0
- package/ts_chat_web/flexchat-window.ts +416 -0
- package/ts_chat_web/index.ts +3 -0
- package/ts_chat_web/plugins.ts +9 -0
- package/ts_chat_web/readme.md +46 -0
- package/ts_compaction/index.ts +2 -0
- package/ts_compaction/plugins.ts +6 -0
- package/ts_compaction/readme.md +37 -0
- package/ts_compaction/smartagent.compaction.ts +59 -0
- package/ts_document/index.ts +82 -0
- package/ts_document/plugins.ts +3 -0
- package/ts_document/readme.md +49 -0
- package/ts_kvm/classes.browserkvm.ts +335 -0
- package/ts_kvm/classes.kvmterminal.ts +103 -0
- package/ts_kvm/commandwrappers.ts +83 -0
- package/ts_kvm/index.ts +6 -0
- package/ts_kvm/interfaces.ts +152 -0
- package/ts_kvm/ocr.ts +41 -0
- package/ts_kvm/plugins.ts +13 -0
- package/ts_kvm/readme.md +482 -0
- package/ts_kvm/tools.ts +58 -0
- package/ts_mcp/index.ts +470 -0
- package/ts_mcp/readme.md +37 -0
- package/ts_mcp/requestcontext.ts +66 -0
- package/ts_media/index.ts +29 -0
- package/ts_media/plugins.ts +2 -0
- package/ts_media/readme.md +37 -0
- package/ts_ocr/classes.imageocr.ts +53 -0
- package/ts_ocr/index.ts +2 -0
- package/ts_ocr/ocr.mistral.ts +192 -0
- package/ts_ocr/readme.md +48 -0
- package/ts_tools/index.ts +49 -0
- package/ts_tools/plugins.ts +7 -0
- package/ts_tools/readme.md +37 -0
- package/ts_tools/tool.browser.ts +159 -0
- package/ts_tools/tool.context.ts +23 -0
- package/ts_tools/tool.filesystem.ts +144 -0
- package/ts_tools/tool.http.ts +78 -0
- package/ts_tools/tool.json.ts +53 -0
- package/ts_tools/tool.shell.ts +418 -0
- package/ts_tools/utils.truncation.ts +39 -0
- package/ts_tools_node/index.ts +5 -0
- package/ts_tools_node/plugins.ts +16 -0
- package/ts_tools_node/readme.md +37 -0
- package/ts_tools_node/tool.context.ts +991 -0
- package/ts_tools_node/tool.persistence.ts +146 -0
- package/ts_tools_node/tools.local.ts +26 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { React, h, Box, Text } from './plugins.js';
|
|
2
|
+
import { Message, type IChatMessage } from './components.message.js';
|
|
3
|
+
|
|
4
|
+
interface IMessageListProps {
|
|
5
|
+
messages: IChatMessage[];
|
|
6
|
+
streamingText: string;
|
|
7
|
+
busy: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function MessageList({ messages, streamingText, busy }: IMessageListProps): React.ReactElement {
|
|
11
|
+
const children: React.ReactNode[] = [];
|
|
12
|
+
|
|
13
|
+
if (messages.length === 0 && !busy) {
|
|
14
|
+
children.push(
|
|
15
|
+
h(Box, { justifyContent: 'center', marginY: 1, key: 'empty' },
|
|
16
|
+
h(Text, { dimColor: true }, 'Type a message to start chatting.'),
|
|
17
|
+
),
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
for (let i = 0; i < messages.length; i++) {
|
|
22
|
+
children.push(h(Message, { key: `msg-${i}`, message: messages[i]! }));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (busy && streamingText) {
|
|
26
|
+
children.push(
|
|
27
|
+
h(Box, { marginY: 0, key: 'streaming' },
|
|
28
|
+
h(Text, { bold: true, color: 'green' }, 'Assistant: '),
|
|
29
|
+
h(Text, null, streamingText),
|
|
30
|
+
h(Text, { dimColor: true }, '\u2588'),
|
|
31
|
+
),
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (busy && !streamingText) {
|
|
36
|
+
children.push(
|
|
37
|
+
h(Box, { marginY: 0, key: 'spinner' },
|
|
38
|
+
h(Text, { color: 'yellow' }, '\u25CF'),
|
|
39
|
+
h(Text, { dimColor: true }, ' Thinking...'),
|
|
40
|
+
),
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return h(Box, { flexDirection: 'column' as const, flexGrow: 1 }, ...children);
|
|
45
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { React, h, Box, Text } from './plugins.js';
|
|
2
|
+
import type { IChatUsage } from './plugins.js';
|
|
3
|
+
|
|
4
|
+
interface IStatusBarProps {
|
|
5
|
+
modelName?: string;
|
|
6
|
+
usage: IChatUsage;
|
|
7
|
+
busy: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function StatusBar({ modelName, usage, busy }: IStatusBarProps): React.ReactElement {
|
|
11
|
+
const children: React.ReactNode[] = [
|
|
12
|
+
h(Text, { dimColor: true, key: 'model' }, modelName ? `model: ${modelName}` : 'FlexChat'),
|
|
13
|
+
h(Text, { dimColor: true, key: 'sep1' }, ' | '),
|
|
14
|
+
h(Text, { dimColor: true, key: 'tokens' }, `tokens: ${usage.totalTokens.toLocaleString()}`),
|
|
15
|
+
h(Text, { dimColor: true, key: 'sep2' }, ' | '),
|
|
16
|
+
h(Text, { dimColor: true, key: 'turns' }, `turns: ${usage.turns}`),
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
if (busy) {
|
|
20
|
+
children.push(
|
|
21
|
+
h(Text, { dimColor: true, key: 'sep3' }, ' | '),
|
|
22
|
+
h(Text, { color: 'yellow', key: 'thinking' }, 'thinking...'),
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return h(
|
|
27
|
+
Box,
|
|
28
|
+
{ borderStyle: 'single' as const, borderTop: true, borderBottom: false, borderLeft: false, borderRight: false, paddingX: 1 },
|
|
29
|
+
...children,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// ink (React-based terminal UI)
|
|
2
|
+
import { render, Box, Text, Static, Newline, Spacer, useInput, useApp } from 'ink';
|
|
3
|
+
export { render, Box, Text, Static, Newline, Spacer, useInput, useApp };
|
|
4
|
+
|
|
5
|
+
// ink components
|
|
6
|
+
import TextInput from 'ink-text-input';
|
|
7
|
+
export { TextInput };
|
|
8
|
+
|
|
9
|
+
// React
|
|
10
|
+
import React from 'react';
|
|
11
|
+
export { React };
|
|
12
|
+
export const h = React.createElement;
|
|
13
|
+
|
|
14
|
+
// Core (cross-folder import)
|
|
15
|
+
import { ChatSession } from '@modelprofile.com/flexharness/chat';
|
|
16
|
+
export { ChatSession };
|
|
17
|
+
export type { IChatSessionOptions, IChatCallbacks, IChatUsage } from '@modelprofile.com/flexharness/chat';
|
|
18
|
+
|
|
19
|
+
// FlexHarness agent types
|
|
20
|
+
export type { IAgentRunResult } from '@modelprofile.com/flexharness-agent';
|
|
21
|
+
export type { TSmartAiLanguageModel, ToolSet } from '@modelprofile.com/flexharness-models';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Interactive terminal chat built with Ink and React, backed by the FlexHarness chat core.
|
|
2
|
+
|
|
3
|
+
```sh
|
|
4
|
+
pnpm add @modelprofile.com/flexharness ink ink-text-input react
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { startChat } from '@modelprofile.com/flexharness/chat/cli';
|
|
9
|
+
|
|
10
|
+
await startChat({ model, modelName: 'My selected model', system: 'Answer concisely.' });
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Supply a model from a separately installed FlexHarness provider. `startChat` also accepts `tools` and `maxSteps`. It renders the terminal conversation and resolves when the user exits. Install the terminal UI peer dependencies shown above; TypeScript projects also need `@types/react`. Chat core and browser projects do not need these peers.
|
|
14
|
+
|
|
15
|
+
This replaces `@push.rocks/smartchat/cli` and retains `startChat` and `IStartChatOptions`.
|
|
16
|
+
|
|
17
|
+
## Issue Reporting and Security
|
|
18
|
+
|
|
19
|
+
Report issues and security concerns through [community.foss.global](https://community.foss.global).
|
|
20
|
+
|
|
21
|
+
## License and Legal Information
|
|
22
|
+
|
|
23
|
+
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the repository license file.
|
|
24
|
+
|
|
25
|
+
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
|
26
|
+
|
|
27
|
+
### Trademarks
|
|
28
|
+
|
|
29
|
+
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
|
|
30
|
+
|
|
31
|
+
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
|
|
32
|
+
|
|
33
|
+
### Company Information
|
|
34
|
+
|
|
35
|
+
Task Venture Capital GmbH<br>
|
|
36
|
+
Registered at District Court Bremen HRB 35230 HB, Germany
|
|
37
|
+
|
|
38
|
+
For any legal inquiries or further information, please contact us via email at hello@task.vc.
|
|
39
|
+
|
|
40
|
+
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { React, h, render } from './plugins.js';
|
|
2
|
+
import type { TSmartAiLanguageModel, ToolSet } from './plugins.js';
|
|
3
|
+
import { ChatApp } from './components.chatapp.js';
|
|
4
|
+
|
|
5
|
+
export interface IStartChatOptions {
|
|
6
|
+
/** The language model to use */
|
|
7
|
+
model: TSmartAiLanguageModel;
|
|
8
|
+
/** System prompt for the agent */
|
|
9
|
+
system?: string;
|
|
10
|
+
/** Tools available to the agent */
|
|
11
|
+
tools?: ToolSet;
|
|
12
|
+
/** Maximum agentic steps per turn */
|
|
13
|
+
maxSteps?: number;
|
|
14
|
+
/** Display name for the model (shown in header/status) */
|
|
15
|
+
modelName?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Start an interactive chat TUI in the terminal.
|
|
20
|
+
* Returns a promise that resolves when the user exits.
|
|
21
|
+
*/
|
|
22
|
+
export async function startChat(options: IStartChatOptions): Promise<void> {
|
|
23
|
+
const instance = render(
|
|
24
|
+
h(ChatApp, {
|
|
25
|
+
model: options.model,
|
|
26
|
+
system: options.system,
|
|
27
|
+
tools: options.tools,
|
|
28
|
+
maxSteps: options.maxSteps,
|
|
29
|
+
modelName: options.modelName,
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
await instance.waitUntilExit();
|
|
34
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { LitElement, html, css } from './plugins.js';
|
|
2
|
+
import type { CSSResult, TemplateResult } from './plugins.js';
|
|
3
|
+
|
|
4
|
+
export class FlexChatInput extends LitElement {
|
|
5
|
+
declare disabled: boolean;
|
|
6
|
+
declare placeholder: string;
|
|
7
|
+
private value = '';
|
|
8
|
+
|
|
9
|
+
static properties = {
|
|
10
|
+
disabled: { type: Boolean },
|
|
11
|
+
placeholder: { type: String },
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
static styles: CSSResult = css`
|
|
15
|
+
:host {
|
|
16
|
+
display: block;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.input-wrap {
|
|
20
|
+
display: flex;
|
|
21
|
+
align-items: flex-end;
|
|
22
|
+
gap: 8px;
|
|
23
|
+
padding: 10px 12px;
|
|
24
|
+
background: rgba(255, 255, 255, 0.04);
|
|
25
|
+
border-radius: 16px;
|
|
26
|
+
border: 1px solid rgba(255, 255, 255, 0.07);
|
|
27
|
+
transition: border-color 0.2s ease, box-shadow 0.2s ease;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.input-wrap:focus-within {
|
|
31
|
+
border-color: rgba(99, 102, 241, 0.45);
|
|
32
|
+
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.08);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.input-wrap.disabled {
|
|
36
|
+
opacity: 0.45;
|
|
37
|
+
pointer-events: none;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
textarea {
|
|
41
|
+
flex: 1;
|
|
42
|
+
background: transparent;
|
|
43
|
+
border: none;
|
|
44
|
+
outline: none;
|
|
45
|
+
color: #e4e4e7;
|
|
46
|
+
font-size: 14px;
|
|
47
|
+
font-family: inherit;
|
|
48
|
+
line-height: 1.5;
|
|
49
|
+
resize: none;
|
|
50
|
+
min-height: 22px;
|
|
51
|
+
max-height: 110px;
|
|
52
|
+
padding: 2px 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
textarea::placeholder {
|
|
56
|
+
color: rgba(255, 255, 255, 0.22);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.send-btn {
|
|
60
|
+
width: 32px;
|
|
61
|
+
height: 32px;
|
|
62
|
+
border-radius: 50%;
|
|
63
|
+
border: none;
|
|
64
|
+
background: linear-gradient(135deg, #6366f1, #7c3aed);
|
|
65
|
+
color: #fff;
|
|
66
|
+
cursor: pointer;
|
|
67
|
+
display: flex;
|
|
68
|
+
align-items: center;
|
|
69
|
+
justify-content: center;
|
|
70
|
+
flex-shrink: 0;
|
|
71
|
+
transition: transform 0.12s ease, opacity 0.12s ease, box-shadow 0.12s ease;
|
|
72
|
+
box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.send-btn:hover:not(:disabled) {
|
|
76
|
+
transform: scale(1.08);
|
|
77
|
+
box-shadow: 0 3px 12px rgba(99, 102, 241, 0.45);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.send-btn:active:not(:disabled) {
|
|
81
|
+
transform: scale(0.94);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.send-btn:disabled {
|
|
85
|
+
opacity: 0.25;
|
|
86
|
+
cursor: default;
|
|
87
|
+
box-shadow: none;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.send-btn svg {
|
|
91
|
+
width: 15px;
|
|
92
|
+
height: 15px;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.hint {
|
|
96
|
+
display: flex;
|
|
97
|
+
justify-content: flex-end;
|
|
98
|
+
padding: 5px 2px 0;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.hint-text {
|
|
102
|
+
font-size: 10.5px;
|
|
103
|
+
color: rgba(255, 255, 255, 0.13);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
kbd {
|
|
107
|
+
padding: 0 3px;
|
|
108
|
+
border-radius: 3px;
|
|
109
|
+
background: rgba(255, 255, 255, 0.05);
|
|
110
|
+
border: 1px solid rgba(255, 255, 255, 0.07);
|
|
111
|
+
font-family: inherit;
|
|
112
|
+
font-size: 10px;
|
|
113
|
+
}
|
|
114
|
+
`;
|
|
115
|
+
|
|
116
|
+
constructor() {
|
|
117
|
+
super();
|
|
118
|
+
this.disabled = false;
|
|
119
|
+
this.placeholder = 'Type a message...';
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
private handleKeydown(e: KeyboardEvent) {
|
|
123
|
+
if (e.key === 'Enter' && !e.shiftKey) {
|
|
124
|
+
e.preventDefault();
|
|
125
|
+
this.submit();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private handleInput(e: Event) {
|
|
130
|
+
const textarea = e.target as HTMLTextAreaElement;
|
|
131
|
+
this.value = textarea.value;
|
|
132
|
+
textarea.style.height = 'auto';
|
|
133
|
+
textarea.style.height = Math.min(textarea.scrollHeight, 110) + 'px';
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private submit() {
|
|
137
|
+
if (!this.value.trim() || this.disabled) return;
|
|
138
|
+
this.dispatchEvent(
|
|
139
|
+
new CustomEvent('send', {
|
|
140
|
+
detail: { text: this.value.trim() },
|
|
141
|
+
bubbles: true,
|
|
142
|
+
composed: true,
|
|
143
|
+
}),
|
|
144
|
+
);
|
|
145
|
+
this.value = '';
|
|
146
|
+
const textarea = this.shadowRoot?.querySelector('textarea');
|
|
147
|
+
if (textarea) {
|
|
148
|
+
textarea.value = '';
|
|
149
|
+
textarea.style.height = 'auto';
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
render(): TemplateResult {
|
|
154
|
+
const canSend = !this.disabled && !!this.value.trim();
|
|
155
|
+
return html`
|
|
156
|
+
<div class="input-wrap ${this.disabled ? 'disabled' : ''}">
|
|
157
|
+
<textarea
|
|
158
|
+
rows="1"
|
|
159
|
+
.value=${this.value}
|
|
160
|
+
@input=${this.handleInput}
|
|
161
|
+
@keydown=${this.handleKeydown}
|
|
162
|
+
placeholder=${this.disabled ? 'Waiting for response...' : this.placeholder}
|
|
163
|
+
?disabled=${this.disabled}
|
|
164
|
+
></textarea>
|
|
165
|
+
<button
|
|
166
|
+
class="send-btn"
|
|
167
|
+
@click=${this.submit}
|
|
168
|
+
?disabled=${!canSend}
|
|
169
|
+
aria-label="Send message"
|
|
170
|
+
>
|
|
171
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
|
172
|
+
<line x1="12" y1="19" x2="12" y2="5"></line>
|
|
173
|
+
<polyline points="5 12 12 5 19 12"></polyline>
|
|
174
|
+
</svg>
|
|
175
|
+
</button>
|
|
176
|
+
</div>
|
|
177
|
+
<div class="hint">
|
|
178
|
+
<span class="hint-text"><kbd>Enter</kbd> send · <kbd>Shift+Enter</kbd> new line</span>
|
|
179
|
+
</div>
|
|
180
|
+
`;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
customElements.define('flexchat-input', FlexChatInput);
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { LitElement, html, css } from './plugins.js';
|
|
2
|
+
import type { CSSResult, TemplateResult } from './plugins.js';
|
|
3
|
+
|
|
4
|
+
export class FlexChatMessage extends LitElement {
|
|
5
|
+
declare role: 'user' | 'assistant' | 'tool';
|
|
6
|
+
declare content: string;
|
|
7
|
+
declare toolName: string;
|
|
8
|
+
declare timestamp: number;
|
|
9
|
+
|
|
10
|
+
static properties = {
|
|
11
|
+
role: { type: String },
|
|
12
|
+
content: { type: String },
|
|
13
|
+
toolName: { type: String },
|
|
14
|
+
timestamp: { type: Number },
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
static styles: CSSResult = css`
|
|
18
|
+
:host {
|
|
19
|
+
display: block;
|
|
20
|
+
animation: msg-in 0.3s ease-out both;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@keyframes msg-in {
|
|
24
|
+
from {
|
|
25
|
+
opacity: 0;
|
|
26
|
+
transform: translateY(6px);
|
|
27
|
+
}
|
|
28
|
+
to {
|
|
29
|
+
opacity: 1;
|
|
30
|
+
transform: translateY(0);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/* ── Message Row ── */
|
|
35
|
+
.row {
|
|
36
|
+
display: flex;
|
|
37
|
+
gap: 10px;
|
|
38
|
+
align-items: flex-end;
|
|
39
|
+
margin-bottom: 4px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.row.user {
|
|
43
|
+
justify-content: flex-end;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.row.assistant {
|
|
47
|
+
justify-content: flex-start;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/* ── Avatar ── */
|
|
51
|
+
.avatar {
|
|
52
|
+
width: 28px;
|
|
53
|
+
height: 28px;
|
|
54
|
+
border-radius: 50%;
|
|
55
|
+
display: flex;
|
|
56
|
+
align-items: center;
|
|
57
|
+
justify-content: center;
|
|
58
|
+
font-size: 12px;
|
|
59
|
+
flex-shrink: 0;
|
|
60
|
+
line-height: 1;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.avatar.user {
|
|
64
|
+
background: linear-gradient(135deg, #3b82f6, #2563eb);
|
|
65
|
+
color: #fff;
|
|
66
|
+
order: 2;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.avatar.assistant {
|
|
70
|
+
background: linear-gradient(135deg, #6366f1, #7c3aed);
|
|
71
|
+
color: #fff;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* ── Bubble ── */
|
|
75
|
+
.bubble {
|
|
76
|
+
padding: 10px 14px;
|
|
77
|
+
border-radius: 18px;
|
|
78
|
+
word-break: break-word;
|
|
79
|
+
white-space: pre-wrap;
|
|
80
|
+
font-size: 14px;
|
|
81
|
+
line-height: 1.55;
|
|
82
|
+
max-width: min(75%, 480px);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.bubble.user {
|
|
86
|
+
background: linear-gradient(135deg, #3b82f6, #2563eb);
|
|
87
|
+
color: #fff;
|
|
88
|
+
border-bottom-right-radius: 6px;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.bubble.assistant {
|
|
92
|
+
background: var(--flexchat-assistant-bg, #1e1e2e);
|
|
93
|
+
border: 1px solid var(--flexchat-assistant-border, rgba(255, 255, 255, 0.08));
|
|
94
|
+
color: var(--flexchat-assistant-text, #d1d5db);
|
|
95
|
+
border-bottom-left-radius: 6px;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* ── Tool ── */
|
|
99
|
+
.tool-row {
|
|
100
|
+
display: flex;
|
|
101
|
+
justify-content: flex-start;
|
|
102
|
+
padding: 2px 0 2px 38px;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.tool-pill {
|
|
106
|
+
display: inline-flex;
|
|
107
|
+
align-items: center;
|
|
108
|
+
gap: 6px;
|
|
109
|
+
padding: 4px 10px;
|
|
110
|
+
background: rgba(99, 102, 241, 0.1);
|
|
111
|
+
border: 1px solid rgba(99, 102, 241, 0.15);
|
|
112
|
+
border-radius: 20px;
|
|
113
|
+
font-size: 11px;
|
|
114
|
+
font-family: 'SF Mono', 'Fira Code', ui-monospace, monospace;
|
|
115
|
+
color: #a5b4fc;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.tool-icon {
|
|
119
|
+
font-size: 10px;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.tool-name {
|
|
123
|
+
font-weight: 600;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/* ── Timestamp ── */
|
|
127
|
+
.time-row {
|
|
128
|
+
padding: 1px 38px 6px;
|
|
129
|
+
font-size: 10px;
|
|
130
|
+
color: rgba(255, 255, 255, 0.2);
|
|
131
|
+
font-variant-numeric: tabular-nums;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.time-row.user {
|
|
135
|
+
text-align: right;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.time-row.assistant {
|
|
139
|
+
text-align: left;
|
|
140
|
+
}
|
|
141
|
+
`;
|
|
142
|
+
|
|
143
|
+
constructor() {
|
|
144
|
+
super();
|
|
145
|
+
this.role = 'user';
|
|
146
|
+
this.content = '';
|
|
147
|
+
this.toolName = '';
|
|
148
|
+
this.timestamp = 0;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private formatTime(ts: number): string {
|
|
152
|
+
if (!ts) return '';
|
|
153
|
+
const d = new Date(ts);
|
|
154
|
+
return d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
render(): TemplateResult {
|
|
158
|
+
if (this.role === 'tool') {
|
|
159
|
+
return html`
|
|
160
|
+
<div class="tool-row">
|
|
161
|
+
<div class="tool-pill">
|
|
162
|
+
<span class="tool-icon">⚡</span>
|
|
163
|
+
<span class="tool-name">${this.toolName || 'tool'}</span>
|
|
164
|
+
</div>
|
|
165
|
+
</div>
|
|
166
|
+
`;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return html`
|
|
170
|
+
<div class="row ${this.role}">
|
|
171
|
+
<div class="avatar ${this.role}">
|
|
172
|
+
${this.role === 'user' ? '⬆' : '✦'}
|
|
173
|
+
</div>
|
|
174
|
+
<div class="bubble ${this.role}">
|
|
175
|
+
${this.content}
|
|
176
|
+
</div>
|
|
177
|
+
</div>
|
|
178
|
+
${this.timestamp
|
|
179
|
+
? html`<div class="time-row ${this.role}">${this.formatTime(this.timestamp)}</div>`
|
|
180
|
+
: ''}
|
|
181
|
+
`;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
customElements.define('flexchat-message', FlexChatMessage);
|