@lambforge/agent-chat 0.0.5 → 0.0.7

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/index.mjs CHANGED
@@ -2430,7 +2430,7 @@ var require_dist3 = __commonJS({
2430
2430
  // src/element.ts
2431
2431
  var import_component = __toESM(require_dist3());
2432
2432
  var import_lit_html19 = __toESM(require_dist());
2433
- import { AgentClient } from "@lambforge/agents";
2433
+ import { ACCEPTED_ATTACHMENT_TYPES, AgentClient } from "@lambforge/agents";
2434
2434
  import { defer } from "rxjs";
2435
2435
  import { finalize } from "rxjs/operators";
2436
2436
 
@@ -2626,7 +2626,12 @@ var historyLoaded = action(
2626
2626
  payload()
2627
2627
  );
2628
2628
  var newConversation = action("[chat] new conversation");
2629
- var sendMessage = action("[chat] send", payload());
2629
+ var sendMessage = action(
2630
+ "[chat] send",
2631
+ payload()
2632
+ );
2633
+ var addFiles = action("[chat] add files", payload());
2634
+ var removeFile = action("[chat] remove file", payload());
2630
2635
  var resume = action(
2631
2636
  "[chat] resume",
2632
2637
  payload()
@@ -2943,9 +2948,14 @@ var ChatEffects = class {
2943
2948
  action$.pipe(
2944
2949
  ofType(sendMessage),
2945
2950
  map3(({ payload: payload2 }) => {
2946
- const { agentId, conversationId, text } = payload2;
2951
+ const { agentId, conversationId, text, files } = payload2;
2947
2952
  const c9 = this.conversation(agentId, conversationId);
2948
- return { c: c9, events: c9.send(text) };
2953
+ const attachments = (files ?? []).map((file) => ({
2954
+ name: file.name,
2955
+ mimeType: file.type || void 0,
2956
+ data: file
2957
+ }));
2958
+ return { c: c9, events: attachments.length ? c9.send(text, { attachments }) : c9.send(text) };
2949
2959
  })
2950
2960
  ),
2951
2961
  action$.pipe(
@@ -3008,6 +3018,9 @@ var ChatEffects = class {
3008
3018
  }
3009
3019
  };
3010
3020
 
3021
+ // src/store/chat-reducer.ts
3022
+ import { attachmentsProblem } from "@lambforge/agents";
3023
+
3011
3024
  // src/store/chat-state.ts
3012
3025
  var initialChatState = {
3013
3026
  shown: false,
@@ -3016,16 +3029,31 @@ var initialChatState = {
3016
3029
  conversationId: null,
3017
3030
  messages: [],
3018
3031
  answering: false,
3019
- notice: null
3032
+ live: null,
3033
+ notice: null,
3034
+ files: []
3020
3035
  };
3021
3036
  function toMessage(m4) {
3022
3037
  const tools = (m4.toolCalls ?? []).map((c9) => c9?.name).filter((n11) => !!n11);
3023
- return { id: m4.id, role: m4.role, text: m4.text ?? "", tools: Array.from(new Set(tools)) };
3038
+ return {
3039
+ id: m4.id,
3040
+ role: m4.role,
3041
+ text: m4.text ?? "",
3042
+ tools: Array.from(new Set(tools)),
3043
+ attachments: (m4.attachments ?? []).map((a5) => a5.name)
3044
+ };
3024
3045
  }
3025
3046
 
3026
3047
  // src/store/chat-reducer.ts
3027
3048
  var LOCAL_ID = /^local:/;
3028
- var empty = { conversationId: null, messages: [], answering: false, notice: null };
3049
+ var empty = {
3050
+ conversationId: null,
3051
+ messages: [],
3052
+ answering: false,
3053
+ live: null,
3054
+ notice: null,
3055
+ files: []
3056
+ };
3029
3057
  var chatReducer = reducer(
3030
3058
  initialChatState,
3031
3059
  on(shown, (s9, { payload: payload2 }) => s9.shown || !payload2 ? s9 : { ...s9, shown: true }),
@@ -3033,6 +3061,7 @@ var chatReducer = reducer(
3033
3061
  on(failed, (s9, { payload: payload2 }) => ({
3034
3062
  ...s9,
3035
3063
  answering: false,
3064
+ live: null,
3036
3065
  notice: { kind: "error", code: payload2 }
3037
3066
  })),
3038
3067
  on(verifying, (s9, { payload: payload2 }) => ({
@@ -3053,6 +3082,7 @@ var chatReducer = reducer(
3053
3082
  conversationId: payload2.detail.id,
3054
3083
  messages: (payload2.detail.messages ?? []).map(toMessage),
3055
3084
  answering: !!payload2.detail.answering,
3085
+ live: null,
3056
3086
  notice: payload2.detail.answering ? { kind: "busy", what: "thinking" } : null
3057
3087
  }
3058
3088
  ),
@@ -3062,25 +3092,52 @@ var chatReducer = reducer(
3062
3092
  // shown at once; replaced by the stored copy when it arrives
3063
3093
  messages: [
3064
3094
  ...s9.messages,
3065
- { id: `local:${s9.messages.length}`, role: "user", text: payload2.text, tools: [] }
3095
+ {
3096
+ id: `local:${s9.messages.length}`,
3097
+ role: "user",
3098
+ text: payload2.text,
3099
+ tools: [],
3100
+ attachments: (payload2.files ?? []).map((f4) => f4.name)
3101
+ }
3066
3102
  ],
3103
+ files: [],
3067
3104
  answering: true,
3068
3105
  notice: { kind: "busy", what: "thinking" }
3069
3106
  })),
3107
+ on(addFiles, (s9, { payload: payload2 }) => {
3108
+ const agent = s9.agents.find((a5) => a5.id === s9.agentId);
3109
+ if (!agent?.allowAttachments) return { ...s9, notice: { kind: "error", code: "attachments-off" } };
3110
+ const files = [...s9.files, ...payload2];
3111
+ const problem = attachmentsProblem(files);
3112
+ if (problem) return { ...s9, notice: { kind: "error", code: problem } };
3113
+ return { ...s9, files, notice: s9.notice?.kind === "error" ? null : s9.notice };
3114
+ }),
3115
+ on(removeFile, (s9, { payload: payload2 }) => ({
3116
+ ...s9,
3117
+ files: s9.files.filter((_2, i12) => i12 !== payload2),
3118
+ notice: s9.notice?.kind === "error" ? null : s9.notice
3119
+ })),
3070
3120
  on(agentEvent, (s9, { payload: payload2 }) => withEvent(s9, payload2)),
3071
3121
  on(runEnded, (s9) => ({
3072
3122
  ...s9,
3073
3123
  answering: false,
3124
+ live: null,
3074
3125
  notice: s9.notice?.kind === "busy" ? null : s9.notice
3075
3126
  })),
3076
- on(stop, (s9) => ({ ...s9, answering: false, notice: { kind: "info", what: "stopped" } }))
3127
+ on(stop, (s9) => ({ ...s9, answering: false, live: null, notice: { kind: "info", what: "stopped" } }))
3077
3128
  );
3078
3129
  function withEvent(s9, event) {
3079
3130
  const conversationId = s9.conversationId ?? event.conversationId;
3080
3131
  if (event.conversationId !== conversationId) return s9;
3081
3132
  if (event.type === "error") {
3082
- return { ...s9, conversationId, notice: { kind: "error", code: event.data?.code ?? "internal" } };
3133
+ return {
3134
+ ...s9,
3135
+ conversationId,
3136
+ live: null,
3137
+ notice: { kind: "error", code: event.data?.code ?? "internal" }
3138
+ };
3083
3139
  }
3140
+ if (event.type === "delta") return withDelta({ ...s9, conversationId }, event);
3084
3141
  if (event.type !== "message" || !event.data?.id) return { ...s9, conversationId };
3085
3142
  const message = toMessage(event.data);
3086
3143
  if (s9.messages.some((m4) => m4.id === message.id)) return { ...s9, conversationId };
@@ -3088,7 +3145,17 @@ function withEvent(s9, event) {
3088
3145
  const local = message.role === "user" ? messages.findIndex((m4) => LOCAL_ID.test(m4.id) && m4.text === message.text) : -1;
3089
3146
  if (local >= 0) messages[local] = message;
3090
3147
  else messages.push(message);
3091
- return { ...s9, conversationId, messages };
3148
+ const live = message.role === "assistant" ? null : s9.live;
3149
+ return { ...s9, conversationId, messages, live };
3150
+ }
3151
+ function withDelta(s9, event) {
3152
+ if (!s9.answering || !event.runId) return s9;
3153
+ const segment = Number(event.data?.segment) || 0;
3154
+ const text = typeof event.data?.text === "string" ? event.data.text : "";
3155
+ const current = s9.live?.runId === event.runId ? s9.live : null;
3156
+ if (current && segment < current.segment) return s9;
3157
+ if (current && segment === current.segment && text.length < current.text.length) return s9;
3158
+ return { ...s9, live: { runId: event.runId, segment, text } };
3092
3159
  }
3093
3160
 
3094
3161
  // src/store/chat-store.ts
@@ -3138,6 +3205,10 @@ var en = {
3138
3205
  pickAgent: "Assistant",
3139
3206
  usedTools: "Used",
3140
3207
  verifying: "Checking that you are human",
3208
+ attach: "Attach files",
3209
+ attached: "Attached files",
3210
+ removeFile: "Remove",
3211
+ filesOnly: "Please look at the attached files.",
3141
3212
  errors: {
3142
3213
  "limit-reached": "This conversation is full - start a new one.",
3143
3214
  "cap-reached": "The assistant is not available right now - try again later.",
@@ -3149,6 +3220,13 @@ var en = {
3149
3220
  unauthorized: "This chat is not allowed here.",
3150
3221
  "bad-request": "That did not work - try again.",
3151
3222
  network: "No connection - try again.",
3223
+ "attachments-off": "This assistant does not take files.",
3224
+ "attachments-unsupported": "This assistant cannot read that kind of file.",
3225
+ "attachment-invalid": "Only images, PDF and text files can be attached.",
3226
+ "attachment-too-large": "That file is too large (images 5 MB, PDF 10 MB, text 1 MB).",
3227
+ "attachment-limit": "At most 5 files and 15 MB in one message.",
3228
+ "attachment-missing": "A file was lost - attach it again.",
3229
+ "attachment-not-uploaded": "A file did not finish uploading - attach it again.",
3152
3230
  default: "Something went wrong - try again."
3153
3231
  }
3154
3232
  };
@@ -3165,6 +3243,10 @@ var bg = {
3165
3243
  pickAgent: "\u0410\u0441\u0438\u0441\u0442\u0435\u043D\u0442",
3166
3244
  usedTools: "\u0418\u0437\u043F\u043E\u043B\u0437\u0432\u0430\u043D\u043E",
3167
3245
  verifying: "\u041F\u0440\u043E\u0432\u0435\u0440\u043A\u0430, \u0447\u0435 \u0441\u0442\u0435 \u0447\u043E\u0432\u0435\u043A",
3246
+ attach: "\u041F\u0440\u0438\u043A\u0430\u0447\u0438 \u0444\u0430\u0439\u043B\u043E\u0432\u0435",
3247
+ attached: "\u041F\u0440\u0438\u043A\u0430\u0447\u0435\u043D\u0438 \u0444\u0430\u0439\u043B\u043E\u0432\u0435",
3248
+ removeFile: "\u041F\u0440\u0435\u043C\u0430\u0445\u043D\u0438",
3249
+ filesOnly: "\u041C\u043E\u043B\u044F, \u0440\u0430\u0437\u0433\u043B\u0435\u0434\u0430\u0439\u0442\u0435 \u043F\u0440\u0438\u043A\u0430\u0447\u0435\u043D\u0438\u0442\u0435 \u0444\u0430\u0439\u043B\u043E\u0432\u0435.",
3168
3250
  errors: {
3169
3251
  "limit-reached": "\u0420\u0430\u0437\u0433\u043E\u0432\u043E\u0440\u044A\u0442 \u0435 \u043F\u044A\u043B\u0435\u043D - \u0437\u0430\u043F\u043E\u0447\u043D\u0435\u0442\u0435 \u043D\u043E\u0432.",
3170
3252
  "cap-reached": "\u0410\u0441\u0438\u0441\u0442\u0435\u043D\u0442\u044A\u0442 \u043D\u0435 \u0435 \u0434\u043E\u0441\u0442\u044A\u043F\u0435\u043D \u0432 \u043C\u043E\u043C\u0435\u043D\u0442\u0430 - \u043E\u043F\u0438\u0442\u0430\u0439\u0442\u0435 \u043F\u043E-\u043A\u044A\u0441\u043D\u043E.",
@@ -3176,6 +3258,13 @@ var bg = {
3176
3258
  unauthorized: "\u0422\u043E\u0437\u0438 \u0447\u0430\u0442 \u043D\u0435 \u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043D \u0442\u0443\u043A.",
3177
3259
  "bad-request": "\u041D\u0435 \u0441\u0435 \u043F\u043E\u043B\u0443\u0447\u0438 - \u043E\u043F\u0438\u0442\u0430\u0439\u0442\u0435 \u043E\u0442\u043D\u043E\u0432\u043E.",
3178
3260
  network: "\u041D\u044F\u043C\u0430 \u0432\u0440\u044A\u0437\u043A\u0430 - \u043E\u043F\u0438\u0442\u0430\u0439\u0442\u0435 \u043E\u0442\u043D\u043E\u0432\u043E.",
3261
+ "attachments-off": "\u0422\u043E\u0437\u0438 \u0430\u0441\u0438\u0441\u0442\u0435\u043D\u0442 \u043D\u0435 \u043F\u0440\u0438\u0435\u043C\u0430 \u0444\u0430\u0439\u043B\u043E\u0432\u0435.",
3262
+ "attachments-unsupported": "\u0422\u043E\u0437\u0438 \u0430\u0441\u0438\u0441\u0442\u0435\u043D\u0442 \u043D\u0435 \u043C\u043E\u0436\u0435 \u0434\u0430 \u0447\u0435\u0442\u0435 \u0442\u0430\u043A\u044A\u0432 \u0444\u0430\u0439\u043B.",
3263
+ "attachment-invalid": "\u041C\u043E\u0436\u0435 \u0434\u0430 \u043F\u0440\u0438\u043A\u0430\u0447\u0438\u0442\u0435 \u0441\u0430\u043C\u043E \u0438\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F, PDF \u0438 \u0442\u0435\u043A\u0441\u0442\u043E\u0432\u0438 \u0444\u0430\u0439\u043B\u043E\u0432\u0435.",
3264
+ "attachment-too-large": "\u0424\u0430\u0439\u043B\u044A\u0442 \u0435 \u0442\u0432\u044A\u0440\u0434\u0435 \u0433\u043E\u043B\u044F\u043C (\u0438\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F 5 MB, PDF 10 MB, \u0442\u0435\u043A\u0441\u0442 1 MB).",
3265
+ "attachment-limit": "\u041D\u0430\u0439-\u043C\u043D\u043E\u0433\u043E 5 \u0444\u0430\u0439\u043B\u0430 \u0438 15 MB \u0432 \u0435\u0434\u043D\u043E \u0441\u044A\u043E\u0431\u0449\u0435\u043D\u0438\u0435.",
3266
+ "attachment-missing": "\u0424\u0430\u0439\u043B \u0441\u0435 \u0438\u0437\u0433\u0443\u0431\u0438 - \u043F\u0440\u0438\u043A\u0430\u0447\u0435\u0442\u0435 \u0433\u043E \u043E\u0442\u043D\u043E\u0432\u043E.",
3267
+ "attachment-not-uploaded": "\u0424\u0430\u0439\u043B \u043D\u0435 \u0441\u0435 \u043A\u0430\u0447\u0438 \u0434\u043E\u043A\u0440\u0430\u0439 - \u043F\u0440\u0438\u043A\u0430\u0447\u0435\u0442\u0435 \u0433\u043E \u043E\u0442\u043D\u043E\u0432\u043E.",
3179
3268
  default: "\u041D\u0435\u0449\u043E \u0441\u0435 \u043E\u0431\u044A\u0440\u043A\u0430 - \u043E\u043F\u0438\u0442\u0430\u0439\u0442\u0435 \u043E\u0442\u043D\u043E\u0432\u043E."
3180
3269
  }
3181
3270
  };
@@ -3317,6 +3406,9 @@ header select {
3317
3406
  .msg pre { margin: 6px 0; padding: 8px; overflow-x: auto; border-radius: 8px; background: rgba(0,0,0,0.06); font-size: 13px; }
3318
3407
  .msg code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }
3319
3408
  .msg a { color: inherit; }
3409
+ .msg.live > :last-child::after { content: '\\258D'; margin-left: 1px; opacity: 0.6; animation: lf-caret 1s steps(1) infinite; }
3410
+ @keyframes lf-caret { 50% { opacity: 0; } }
3411
+ @media (prefers-reduced-motion: reduce) { .msg.live > :last-child::after { animation: none; } }
3320
3412
  .tools { font-size: 12px; color: var(--_muted); margin-top: 4px; }
3321
3413
 
3322
3414
  .welcome { color: var(--_muted); }
@@ -3361,6 +3453,26 @@ textarea:focus-visible { outline: 2px solid var(--_accent); outline-offset: 0; b
3361
3453
  padding: 0 14px; height: 40px; font-weight: 600;
3362
3454
  }
3363
3455
  .send:disabled { opacity: 0.5; cursor: default; }
3456
+ .attach { flex: none; height: 40px; }
3457
+ .attach:disabled { opacity: 0.5; cursor: default; }
3458
+ .files {
3459
+ list-style: none; margin: 0; padding: 8px 12px 0; display: flex; flex-wrap: wrap; gap: 6px;
3460
+ border-top: 1px solid var(--_border);
3461
+ }
3462
+ .file {
3463
+ display: inline-flex; align-items: center; gap: 2px; max-width: 100%;
3464
+ border: 1px solid var(--_border); border-radius: 999px; padding: 2px 2px 2px 10px; font-size: 13px;
3465
+ }
3466
+ .file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
3467
+ .file-remove {
3468
+ border: 0; background: transparent; color: var(--_muted); width: 22px; height: 22px;
3469
+ border-radius: 999px; display: grid; place-items: center; padding: 0;
3470
+ }
3471
+ .file-remove:hover, .file-remove:focus-visible { background: var(--_bot-bg); color: var(--_fg); }
3472
+ .file-remove svg { width: 14px; height: 14px; }
3473
+ .files + form { border-top: 0; }
3474
+ .msg-files { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
3475
+ .msg-file { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: rgba(255,255,255,0.2); }
3364
3476
  .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
3365
3477
  `;
3366
3478
 
@@ -3449,6 +3561,8 @@ var TAG = "lambforge-agent-chat";
3449
3561
  var ICON_CHAT = import_lit_html19.svg`<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/>`;
3450
3562
  var ICON_CLOSE = import_lit_html19.svg`<path d="M18 6 6 18M6 6l12 12"/>`;
3451
3563
  var ICON_NEW = import_lit_html19.svg`<path d="M12 5v14M5 12h14"/>`;
3564
+ var ICON_ATTACH = import_lit_html19.svg`<path d="m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"/>`;
3565
+ var ACCEPT = [...ACCEPTED_ATTACHMENT_TYPES, ".md", ".csv", ".yaml", ".yml", ".json", ".txt"].join(",");
3452
3566
  var icon = (paths) => import_lit_html19.html`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${paths}</svg>`;
3453
3567
  var LambforgeAgentChat = class extends import_lit_html19.LitElement {
3454
3568
  constructor() {
@@ -3467,7 +3581,8 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
3467
3581
  this.turnstileSitekey = "";
3468
3582
  this.turnstileUrl = "";
3469
3583
  this.strings = {};
3470
- this.lastCount = 0;
3584
+ /** messages + live text length: scroll when either grows */
3585
+ this.lastSize = "";
3471
3586
  }
3472
3587
  get shown() {
3473
3588
  return this.mode !== "drawer" || this.open;
@@ -3557,16 +3672,36 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
3557
3672
  throw new Error("turnstile: the chat is not rendered");
3558
3673
  }
3559
3674
  // ------------------------------------------------------------ actions
3560
- /** Send a message to the selected agent. */
3675
+ /** Send a message (with the picked files) to the selected agent. */
3561
3676
  send(text) {
3562
3677
  return ([state]) => {
3563
- const clean = String(text ?? "").trim();
3678
+ const files = state.files;
3679
+ const clean = String(text ?? "").trim() || (files.length ? this.t.filesOnly : "");
3564
3680
  if (!clean || state.answering || !state.agentId) return;
3565
3681
  this.dispatch(
3566
- sendMessage({ agentId: state.agentId, conversationId: state.conversationId, text: clean })
3682
+ sendMessage({
3683
+ agentId: state.agentId,
3684
+ conversationId: state.conversationId,
3685
+ text: clean,
3686
+ ...files.length ? { files } : {}
3687
+ })
3567
3688
  );
3568
3689
  };
3569
3690
  }
3691
+ /** Files for the next message (the reducer refuses what the API would). */
3692
+ attach(files) {
3693
+ const list = Array.from(files ?? []);
3694
+ if (list.length) this.dispatch(addFiles(list));
3695
+ }
3696
+ detach(index) {
3697
+ this.dispatch(removeFile(index));
3698
+ }
3699
+ onPaste(ev, allowed) {
3700
+ const files = Array.from(ev.clipboardData?.files ?? []);
3701
+ if (!allowed || !files.length) return;
3702
+ ev.preventDefault();
3703
+ this.attach(files);
3704
+ }
3570
3705
  /** Stop the answer in progress. */
3571
3706
  stopAnswer() {
3572
3707
  return ([state]) => {
@@ -3654,10 +3789,15 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
3654
3789
  const drawer = this.mode === "drawer";
3655
3790
  const agent = state.agents.find((a5) => a5.id === state.agentId) ?? null;
3656
3791
  const title = this.heading || agent?.name || t9.title;
3657
- const notice = state.notice;
3658
- if (state.messages.length !== this.lastCount) {
3659
- this.lastCount = state.messages.length;
3660
- this.updateComplete.then(() => requestAnimationFrame(() => this.scrollDown()));
3792
+ const canAttach = !!agent?.allowAttachments;
3793
+ const live = state.live?.text ? state.live : null;
3794
+ const notice = live && state.notice?.kind === "busy" ? null : state.notice;
3795
+ const size = `${state.messages.length}:${live?.text.length ?? 0}`;
3796
+ if (size !== this.lastSize) {
3797
+ const newMessage = size.split(":")[0] !== this.lastSize.split(":")[0];
3798
+ this.lastSize = size;
3799
+ const follow = newMessage || this.atBottom();
3800
+ if (follow) this.updateComplete.then(() => requestAnimationFrame(() => this.scrollDown()));
3661
3801
  }
3662
3802
  return import_lit_html19.html`
3663
3803
  <button
@@ -3701,8 +3841,16 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
3701
3841
  ${icon(ICON_CLOSE)}
3702
3842
  </button>
3703
3843
  </header>
3704
- <div class="messages" part="messages" role="log" aria-live="polite" aria-relevant="additions">
3844
+ <div
3845
+ class="messages"
3846
+ part="messages"
3847
+ role="log"
3848
+ aria-live="polite"
3849
+ aria-relevant="additions"
3850
+ aria-busy=${String(!!live)}
3851
+ >
3705
3852
  ${state.messages.length ? state.messages.map((m4) => this.bubble(m4)) : this.intro(state)}
3853
+ ${live ? import_lit_html19.html`<div class="msg assistant live" part="message assistant live">${renderMarkdown(live.text)}</div>` : ""}
3706
3854
  </div>
3707
3855
  <div class="turnstile" ?hidden=${notice?.kind !== "busy" || notice.what !== "verifying"}></div>
3708
3856
  <div
@@ -3710,7 +3858,40 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
3710
3858
  part="status"
3711
3859
  role="status"
3712
3860
  >${this.noticeText(notice)}</div>
3861
+ ${canAttach && state.files.length ? import_lit_html19.html`<ul class="files" part="files" aria-label=${t9.attached}>
3862
+ ${state.files.map(
3863
+ (f4, i12) => import_lit_html19.html`<li class="file" part="file">
3864
+ <span class="file-name" title=${f4.name}>${f4.name}</span>
3865
+ <button type="button" class="file-remove" aria-label=${`${t9.removeFile}: ${f4.name}`} @click=${() => this.detach(i12)}>
3866
+ ${icon(ICON_CLOSE)}
3867
+ </button>
3868
+ </li>`
3869
+ )}
3870
+ </ul>` : ""}
3713
3871
  <form part="composer" @submit=${(ev) => this.submit(ev, state)}>
3872
+ ${canAttach ? import_lit_html19.html`<input
3873
+ class="file-input"
3874
+ type="file"
3875
+ multiple
3876
+ accept=${ACCEPT}
3877
+ hidden
3878
+ @change=${(ev) => {
3879
+ const input = ev.target;
3880
+ this.attach(input.files);
3881
+ input.value = "";
3882
+ }}
3883
+ />
3884
+ <button
3885
+ class="icon attach"
3886
+ part="attach"
3887
+ type="button"
3888
+ title=${t9.attach}
3889
+ aria-label=${t9.attach}
3890
+ ?disabled=${state.answering}
3891
+ @click=${() => this.shadowRoot?.querySelector(".file-input")?.click()}
3892
+ >
3893
+ ${icon(ICON_ATTACH)}
3894
+ </button>` : ""}
3714
3895
  <label class="sr-only" for="lf-input">${t9.placeholder}</label>
3715
3896
  <textarea
3716
3897
  id="lf-input"
@@ -3719,6 +3900,7 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
3719
3900
  placeholder=${t9.placeholder}
3720
3901
  @keydown=${(ev) => this.onInputKey(ev, state)}
3721
3902
  @input=${(ev) => this.autosize(ev.target)}
3903
+ @paste=${(ev) => this.onPaste(ev, canAttach && !state.answering)}
3722
3904
  ></textarea>
3723
3905
  <button class="send" part="send" type="submit" aria-label=${state.answering ? t9.stop : t9.send}>
3724
3906
  ${state.answering ? t9.stop : t9.send}
@@ -3729,7 +3911,7 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
3729
3911
  }
3730
3912
  bubble(m4) {
3731
3913
  if (m4.role === "user") {
3732
- return import_lit_html19.html`<div class="msg user" part="message user">${m4.text}</div>`;
3914
+ return import_lit_html19.html`<div class="msg user" part="message user">${m4.text}${m4.attachments?.length ? import_lit_html19.html`<div class="msg-files">${m4.attachments.map((name) => import_lit_html19.html`<span class="msg-file">${name}</span>`)}</div>` : ""}</div>`;
3733
3915
  }
3734
3916
  return import_lit_html19.html`<div class="msg assistant" part="message assistant">
3735
3917
  ${renderMarkdown(m4.text)}
@@ -3748,6 +3930,10 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
3748
3930
  </div>` : ""}
3749
3931
  `;
3750
3932
  }
3933
+ atBottom() {
3934
+ const m4 = this.shadowRoot?.querySelector(".messages");
3935
+ return !m4 || m4.scrollHeight - m4.scrollTop - m4.clientHeight < 80;
3936
+ }
3751
3937
  scrollDown() {
3752
3938
  const m4 = this.shadowRoot?.querySelector(".messages");
3753
3939
  if (m4) m4.scrollTop = m4.scrollHeight;
@@ -3821,6 +4007,7 @@ export {
3821
4007
  LOCALES,
3822
4008
  LambforgeAgentChat,
3823
4009
  TAG,
4010
+ addFiles,
3824
4011
  agentEvent,
3825
4012
  agentsLoaded,
3826
4013
  chatReducer,
@@ -3833,6 +4020,7 @@ export {
3833
4020
  newConversation,
3834
4021
  pickAgent,
3835
4022
  pickAgents,
4023
+ removeFile,
3836
4024
  renderMarkdown,
3837
4025
  resume,
3838
4026
  runEnded,