Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
458 changes: 0 additions & 458 deletions nx2/blocks/chat/chat-controller.js

This file was deleted.

41 changes: 27 additions & 14 deletions nx2/blocks/chat/chat.css
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
padding: 0 var(--s2-spacing-300);
box-sizing: border-box;
justify-content: flex-end;
gap: var(--s2-spacing-300);
gap: var(--s2-spacing-100);

.chat-header-btn {
display: inline-flex;
Expand All @@ -98,7 +98,7 @@
color: var(--s2-gray-800);
cursor: pointer;
font-family: inherit;
font-size: var(--s2-body-size-s);
font-size: var(--s2-body-size-xs);

&.clear-btn {
padding: 0 var(--s2-spacing-100);
Expand Down Expand Up @@ -149,7 +149,7 @@
width: 10px;
height: 10px;
background-color: currentcolor;
mask-image: url("/nx2/img/icons/S2_Icon_ChevronUp_20_N.svg");
mask-image: url("https://da.live/img/icons/s2-icon-chevronup-20-n.svg");
mask-size: contain;
mask-repeat: no-repeat;
mask-position: center;
Expand Down Expand Up @@ -190,6 +190,10 @@
color: var(--s2-gray-500);
overflow-wrap: break-word;
}

&.tool-card-detail {
margin-left: 14px;
}
}

.directive {
Expand All @@ -203,6 +207,7 @@

.directive-checklist ul {
list-style: none;
padding: 0;
}

.directive-toggle-list {
Expand Down Expand Up @@ -300,21 +305,29 @@
gap: var(--s2-spacing-75);
}

.message-content p {
margin: 0;
}
.message-content {
p {
margin: 0;
}

.message-content code {
background: var(--s2-gray-75);
border-radius: var(--s2-corner-radius-75);
padding: var(--s2-spacing-50);
overflow-x: auto;
margin: 0;
font-size: var(--s2-body-size-xs);
code {
background: var(--s2-gray-75);
border-radius: var(--s2-corner-radius-75);
padding: var(--s2-spacing-50);
overflow-x: auto;
margin: 0;
font-size: var(--s2-body-size-xs);
}

hr {
border: none;
height: 1px;
background: var(--s2-gray-200);
}
}

.message-action-copy {
align-self: flex-end;
align-self: flex-start;
visibility: hidden;
box-sizing: border-box;
width: 20px;
Expand Down
18 changes: 12 additions & 6 deletions nx2/blocks/chat/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { LitElement, html, nothing } from 'da-lit';
import { loadStyle, hashChange } from '../../utils/utils.js';
import { readFileAsBase64 } from './utils/stream.js';
import '../shared/menu/menu.js';
import ChatController from './chat-controller.js';
import ChatController from './controllers/chat-controller.js';
import { renderMessage, renderApprovalCard } from './renderers.js';
import './welcome/welcome.js';
import './prompts/prompts.js';
Expand Down Expand Up @@ -180,12 +180,16 @@ class NxChat extends LitElement {
}));
},
onUpdate: ({ messages, thinking, streamingText, connected, toolCards }) => {
this.messages = streamingText
const newMessages = streamingText
? [...(messages ?? []), { role: ROLE.ASSISTANT, content: streamingText, streaming: true }]
: messages;
this.thinking = thinking;
this.connected = connected;
this.toolCards = toolCards;
cancelAnimationFrame(this._updateRaf);
this._updateRaf = requestAnimationFrame(() => {
this.messages = newMessages;
this.thinking = thinking;
this.connected = connected;
this.toolCards = toolCards;
});
},
});
if (this._context) this._controller.setContext(this._context);
Expand All @@ -200,6 +204,7 @@ class NxChat extends LitElement {

disconnectedCallback() {
super.disconnectedCallback();
cancelAnimationFrame(this._updateRaf);
(this._items ?? []).forEach((item) => {
if (item.thumbnail) URL.revokeObjectURL(item.thumbnail);
});
Expand Down Expand Up @@ -243,7 +248,8 @@ class NxChat extends LitElement {
if (changed.has('messages')) {
const log = this.shadowRoot.querySelector('.chat-scroll-container');
if (log && this._wasNearBottom) {
requestAnimationFrame(() => { log.scrollTop = log.scrollHeight; });
cancelAnimationFrame(this._scrollRaf);
this._scrollRaf = requestAnimationFrame(() => { log.scrollTop = log.scrollHeight; });
}
}
if (changed.has('thinking') && !this.thinking && changed.get('thinking')) {
Expand Down
16 changes: 8 additions & 8 deletions nx2/blocks/chat/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@ const MENU_OPTIONS = {

const ADD_MENU_ITEMS = [
{ section: 'Add' },
{ id: 'files', label: 'Files or images', icon: 'link' },
{ id: MENU_OPTIONS.PROMPT, label: 'Prompt' },
{ id: 'command', label: '"/" Command' },
{ id: MENU_OPTIONS.FILES, label: 'Files or images', icon: 'link' },
{ id: MENU_OPTIONS.PROMPT, label: 'Prompt', icon: 'commentremove' },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you confirm MENU_OPTIONS.FILES and MENU_OPTIONS.COMMAND are defined in the full MENU_OPTIONS object? the diff doesn't show them and the old code used string literals 'files' and 'command'.

{ id: MENU_OPTIONS.COMMAND, label: '"/" Command', icon: 'prompt' },
{ divider: true },
{ id: 'prompts', label: 'Manage Prompts' },
{ id: 'skills', label: 'Manage Skills' },
];

const CHAT_ICONS = {
add: 'Add', clear: 'RemoveCircle', close: 'SplitLeft', send: 'ArrowUpSend', stop: 'Stop', up: 'ChevronUp',
};

/**
* Agent stream event types.
* Source: Vercel AI SDK v6 UIMessageStream format, as emitted by da-agent.
Expand Down Expand Up @@ -86,6 +82,10 @@ const TOOL_SCOPE = {
[TOOL_NAME.CONTENT_UPLOAD]: 'document',
};

const FINISH_REASON = {
TOOL_CALLS: 'tool-calls',
};

const ROLE = {
USER: 'user',
ASSISTANT: 'assistant',
Expand All @@ -96,7 +96,7 @@ export {
ADOBE_AI_GUIDELINES_URL,
ADD_MENU_ITEMS,
AGENT_EVENT,
CHAT_ICONS,
FINISH_REASON,
MENU_OPTIONS,
ROLE,
TOOL_INPUT,
Expand Down
Loading
Loading