@lambforge/agent-chat 0.0.6 → 0.0.8

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()
@@ -2634,6 +2639,12 @@ var resume = action(
2634
2639
  var agentEvent = action("[chat] event", payload());
2635
2640
  var runEnded = action("[chat] run ended");
2636
2641
  var stop = action("[chat] stop", payload());
2642
+ var rate = action("[chat] rate", payload());
2643
+ var rateFailed = action(
2644
+ "[chat] rate failed",
2645
+ payload()
2646
+ );
2647
+ var closeComment = action("[chat] close comment");
2637
2648
 
2638
2649
  // ../../node_modules/@rxdi/redux-store/dist/esm/interfaces.js
2639
2650
  var FlattenOperator;
@@ -2943,9 +2954,14 @@ var ChatEffects = class {
2943
2954
  action$.pipe(
2944
2955
  ofType(sendMessage),
2945
2956
  map3(({ payload: payload2 }) => {
2946
- const { agentId, conversationId, text } = payload2;
2957
+ const { agentId, conversationId, text, files } = payload2;
2947
2958
  const c9 = this.conversation(agentId, conversationId);
2948
- return { c: c9, events: c9.send(text) };
2959
+ const attachments = (files ?? []).map((file) => ({
2960
+ name: file.name,
2961
+ mimeType: file.type || void 0,
2962
+ data: file
2963
+ }));
2964
+ return { c: c9, events: attachments.length ? c9.send(text, { attachments }) : c9.send(text) };
2949
2965
  })
2950
2966
  ),
2951
2967
  action$.pipe(
@@ -2979,6 +2995,20 @@ var ChatEffects = class {
2979
2995
  })
2980
2996
  )
2981
2997
  );
2998
+ /** Send a rating; a refusal puts the earlier one back. */
2999
+ this.rate$ = createEffect()(
3000
+ (action$) => action$.pipe(
3001
+ ofType(rate),
3002
+ mergeMap2(({ payload: payload2 }) => {
3003
+ const { agentId, conversationId, messageId, rating, comment, previous } = payload2;
3004
+ if (!this.ctx.client) return EMPTY2;
3005
+ return this.conversation(agentId, conversationId).rate(messageId, rating, comment).pipe(
3006
+ ignoreElements2(),
3007
+ catchError3(() => of5(rateFailed({ messageId, previous })))
3008
+ );
3009
+ })
3010
+ )
3011
+ );
2982
3012
  /** Failures also reach the page as an `error` event. */
2983
3013
  this.failures$ = createEffect()(
2984
3014
  (action$) => action$.pipe(
@@ -3008,6 +3038,9 @@ var ChatEffects = class {
3008
3038
  }
3009
3039
  };
3010
3040
 
3041
+ // src/store/chat-reducer.ts
3042
+ import { attachmentsProblem } from "@lambforge/agents";
3043
+
3011
3044
  // src/store/chat-state.ts
3012
3045
  var initialChatState = {
3013
3046
  shown: false,
@@ -3017,16 +3050,33 @@ var initialChatState = {
3017
3050
  messages: [],
3018
3051
  answering: false,
3019
3052
  live: null,
3020
- notice: null
3053
+ notice: null,
3054
+ files: [],
3055
+ commentFor: null
3021
3056
  };
3022
3057
  function toMessage(m4) {
3023
3058
  const tools = (m4.toolCalls ?? []).map((c9) => c9?.name).filter((n11) => !!n11);
3024
- return { id: m4.id, role: m4.role, text: m4.text ?? "", tools: Array.from(new Set(tools)) };
3059
+ return {
3060
+ id: m4.id,
3061
+ role: m4.role,
3062
+ text: m4.text ?? "",
3063
+ tools: Array.from(new Set(tools)),
3064
+ attachments: (m4.attachments ?? []).map((a5) => a5.name),
3065
+ feedback: m4.feedback?.rating ?? null
3066
+ };
3025
3067
  }
3026
3068
 
3027
3069
  // src/store/chat-reducer.ts
3028
3070
  var LOCAL_ID = /^local:/;
3029
- var empty = { conversationId: null, messages: [], answering: false, live: null, notice: null };
3071
+ var empty = {
3072
+ conversationId: null,
3073
+ messages: [],
3074
+ answering: false,
3075
+ live: null,
3076
+ notice: null,
3077
+ files: [],
3078
+ commentFor: null
3079
+ };
3030
3080
  var chatReducer = reducer(
3031
3081
  initialChatState,
3032
3082
  on(shown, (s9, { payload: payload2 }) => s9.shown || !payload2 ? s9 : { ...s9, shown: true }),
@@ -3065,11 +3115,32 @@ var chatReducer = reducer(
3065
3115
  // shown at once; replaced by the stored copy when it arrives
3066
3116
  messages: [
3067
3117
  ...s9.messages,
3068
- { id: `local:${s9.messages.length}`, role: "user", text: payload2.text, tools: [] }
3118
+ {
3119
+ id: `local:${s9.messages.length}`,
3120
+ role: "user",
3121
+ text: payload2.text,
3122
+ tools: [],
3123
+ attachments: (payload2.files ?? []).map((f4) => f4.name),
3124
+ feedback: null
3125
+ }
3069
3126
  ],
3127
+ files: [],
3070
3128
  answering: true,
3071
3129
  notice: { kind: "busy", what: "thinking" }
3072
3130
  })),
3131
+ on(addFiles, (s9, { payload: payload2 }) => {
3132
+ const agent = s9.agents.find((a5) => a5.id === s9.agentId);
3133
+ if (!agent?.allowAttachments) return { ...s9, notice: { kind: "error", code: "attachments-off" } };
3134
+ const files = [...s9.files, ...payload2];
3135
+ const problem = attachmentsProblem(files);
3136
+ if (problem) return { ...s9, notice: { kind: "error", code: problem } };
3137
+ return { ...s9, files, notice: s9.notice?.kind === "error" ? null : s9.notice };
3138
+ }),
3139
+ on(removeFile, (s9, { payload: payload2 }) => ({
3140
+ ...s9,
3141
+ files: s9.files.filter((_2, i12) => i12 !== payload2),
3142
+ notice: s9.notice?.kind === "error" ? null : s9.notice
3143
+ })),
3073
3144
  on(agentEvent, (s9, { payload: payload2 }) => withEvent(s9, payload2)),
3074
3145
  on(runEnded, (s9) => ({
3075
3146
  ...s9,
@@ -3077,6 +3148,22 @@ var chatReducer = reducer(
3077
3148
  live: null,
3078
3149
  notice: s9.notice?.kind === "busy" ? null : s9.notice
3079
3150
  })),
3151
+ on(rate, (s9, { payload: payload2 }) => ({
3152
+ ...s9,
3153
+ messages: s9.messages.map(
3154
+ (m4) => m4.id === payload2.messageId ? { ...m4, feedback: payload2.rating } : m4
3155
+ ),
3156
+ // a fresh thumbs down asks what was wrong; a comment or anything else closes it
3157
+ commentFor: payload2.rating === "down" && payload2.comment === void 0 && payload2.previous !== "down" ? payload2.messageId : null
3158
+ })),
3159
+ on(rateFailed, (s9, { payload: payload2 }) => ({
3160
+ ...s9,
3161
+ messages: s9.messages.map(
3162
+ (m4) => m4.id === payload2.messageId ? { ...m4, feedback: payload2.previous } : m4
3163
+ ),
3164
+ commentFor: s9.commentFor === payload2.messageId ? null : s9.commentFor
3165
+ })),
3166
+ on(closeComment, (s9) => ({ ...s9, commentFor: null })),
3080
3167
  on(stop, (s9) => ({ ...s9, answering: false, live: null, notice: { kind: "info", what: "stopped" } }))
3081
3168
  );
3082
3169
  function withEvent(s9, event) {
@@ -3128,6 +3215,7 @@ var ChatStore = class {
3128
3215
  effects.select$,
3129
3216
  effects.run$,
3130
3217
  effects.abort$,
3218
+ effects.rate$,
3131
3219
  effects.failures$,
3132
3220
  effects.connect$
3133
3221
  ),
@@ -3158,6 +3246,16 @@ var en = {
3158
3246
  pickAgent: "Assistant",
3159
3247
  usedTools: "Used",
3160
3248
  verifying: "Checking that you are human",
3249
+ attach: "Attach files",
3250
+ attached: "Attached files",
3251
+ removeFile: "Remove",
3252
+ filesOnly: "Please look at the attached files.",
3253
+ helpful: "Helpful",
3254
+ notHelpful: "Not helpful",
3255
+ whatWentWrong: "What was wrong? (optional)",
3256
+ sendFeedback: "Send",
3257
+ skipFeedback: "Skip",
3258
+ thanks: "Thanks for the feedback",
3161
3259
  errors: {
3162
3260
  "limit-reached": "This conversation is full - start a new one.",
3163
3261
  "cap-reached": "The assistant is not available right now - try again later.",
@@ -3169,6 +3267,13 @@ var en = {
3169
3267
  unauthorized: "This chat is not allowed here.",
3170
3268
  "bad-request": "That did not work - try again.",
3171
3269
  network: "No connection - try again.",
3270
+ "attachments-off": "This assistant does not take files.",
3271
+ "attachments-unsupported": "This assistant cannot read that kind of file.",
3272
+ "attachment-invalid": "Only images, PDF and text files can be attached.",
3273
+ "attachment-too-large": "That file is too large (images 5 MB, PDF 10 MB, text 1 MB).",
3274
+ "attachment-limit": "At most 5 files and 15 MB in one message.",
3275
+ "attachment-missing": "A file was lost - attach it again.",
3276
+ "attachment-not-uploaded": "A file did not finish uploading - attach it again.",
3172
3277
  default: "Something went wrong - try again."
3173
3278
  }
3174
3279
  };
@@ -3185,6 +3290,16 @@ var bg = {
3185
3290
  pickAgent: "\u0410\u0441\u0438\u0441\u0442\u0435\u043D\u0442",
3186
3291
  usedTools: "\u0418\u0437\u043F\u043E\u043B\u0437\u0432\u0430\u043D\u043E",
3187
3292
  verifying: "\u041F\u0440\u043E\u0432\u0435\u0440\u043A\u0430, \u0447\u0435 \u0441\u0442\u0435 \u0447\u043E\u0432\u0435\u043A",
3293
+ attach: "\u041F\u0440\u0438\u043A\u0430\u0447\u0438 \u0444\u0430\u0439\u043B\u043E\u0432\u0435",
3294
+ attached: "\u041F\u0440\u0438\u043A\u0430\u0447\u0435\u043D\u0438 \u0444\u0430\u0439\u043B\u043E\u0432\u0435",
3295
+ removeFile: "\u041F\u0440\u0435\u043C\u0430\u0445\u043D\u0438",
3296
+ 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.",
3297
+ helpful: "\u041F\u043E\u043B\u0435\u0437\u043D\u043E",
3298
+ notHelpful: "\u041D\u0435 \u0435 \u043F\u043E\u043B\u0435\u0437\u043D\u043E",
3299
+ whatWentWrong: "\u041A\u0430\u043A\u0432\u043E \u043D\u0435 \u0431\u0435\u0448\u0435 \u043D\u0430\u0440\u0435\u0434? (\u043F\u043E \u0436\u0435\u043B\u0430\u043D\u0438\u0435)",
3300
+ sendFeedback: "\u0418\u0437\u043F\u0440\u0430\u0442\u0438",
3301
+ skipFeedback: "\u041F\u0440\u043E\u043F\u0443\u0441\u043D\u0438",
3302
+ thanks: "\u0411\u043B\u0430\u0433\u043E\u0434\u0430\u0440\u0438\u043C \u0437\u0430 \u043E\u0442\u0437\u0438\u0432\u0430",
3188
3303
  errors: {
3189
3304
  "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.",
3190
3305
  "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.",
@@ -3196,6 +3311,13 @@ var bg = {
3196
3311
  unauthorized: "\u0422\u043E\u0437\u0438 \u0447\u0430\u0442 \u043D\u0435 \u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043D \u0442\u0443\u043A.",
3197
3312
  "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.",
3198
3313
  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.",
3314
+ "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.",
3315
+ "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.",
3316
+ "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.",
3317
+ "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).",
3318
+ "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.",
3319
+ "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.",
3320
+ "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.",
3199
3321
  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."
3200
3322
  }
3201
3323
  };
@@ -3341,6 +3463,26 @@ header select {
3341
3463
  @keyframes lf-caret { 50% { opacity: 0; } }
3342
3464
  @media (prefers-reduced-motion: reduce) { .msg.live > :last-child::after { animation: none; } }
3343
3465
  .tools { font-size: 12px; color: var(--_muted); margin-top: 4px; }
3466
+ .rate { display: flex; align-items: center; gap: 2px; margin-top: -6px; }
3467
+ .thumb {
3468
+ border: 0; background: transparent; color: var(--_muted);
3469
+ width: 26px; height: 26px; border-radius: 6px; display: grid; place-items: center; cursor: pointer;
3470
+ }
3471
+ .thumb svg { width: 14px; height: 14px; }
3472
+ .thumb:hover, .thumb:focus-visible { background: var(--_bot-bg); color: var(--_fg); }
3473
+ .thumb.on { color: var(--_accent); }
3474
+ .thanks { font-size: 12px; color: var(--_muted); margin-left: 4px; }
3475
+ .comment { display: flex; gap: 6px; align-items: center; max-width: 85%; }
3476
+ .comment input {
3477
+ flex: 1; min-width: 0; font: inherit; font-size: 13px; color: var(--_fg); background: var(--_bg);
3478
+ border: 1px solid var(--_border); border-radius: 8px; padding: 6px 8px;
3479
+ }
3480
+ .comment button {
3481
+ border: 1px solid var(--_border); background: transparent; color: var(--_fg);
3482
+ border-radius: 8px; padding: 5px 9px; font-size: 13px; cursor: pointer;
3483
+ }
3484
+ .comment button[type='submit'] { border-color: var(--_accent); color: var(--_accent); }
3485
+ .comment .skip { color: var(--_muted); }
3344
3486
 
3345
3487
  .welcome { color: var(--_muted); }
3346
3488
  .suggestions { display: flex; flex-wrap: wrap; gap: 6px; }
@@ -3384,6 +3526,26 @@ textarea:focus-visible { outline: 2px solid var(--_accent); outline-offset: 0; b
3384
3526
  padding: 0 14px; height: 40px; font-weight: 600;
3385
3527
  }
3386
3528
  .send:disabled { opacity: 0.5; cursor: default; }
3529
+ .attach { flex: none; height: 40px; }
3530
+ .attach:disabled { opacity: 0.5; cursor: default; }
3531
+ .files {
3532
+ list-style: none; margin: 0; padding: 8px 12px 0; display: flex; flex-wrap: wrap; gap: 6px;
3533
+ border-top: 1px solid var(--_border);
3534
+ }
3535
+ .file {
3536
+ display: inline-flex; align-items: center; gap: 2px; max-width: 100%;
3537
+ border: 1px solid var(--_border); border-radius: 999px; padding: 2px 2px 2px 10px; font-size: 13px;
3538
+ }
3539
+ .file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
3540
+ .file-remove {
3541
+ border: 0; background: transparent; color: var(--_muted); width: 22px; height: 22px;
3542
+ border-radius: 999px; display: grid; place-items: center; padding: 0;
3543
+ }
3544
+ .file-remove:hover, .file-remove:focus-visible { background: var(--_bot-bg); color: var(--_fg); }
3545
+ .file-remove svg { width: 14px; height: 14px; }
3546
+ .files + form { border-top: 0; }
3547
+ .msg-files { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
3548
+ .msg-file { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: rgba(255,255,255,0.2); }
3387
3549
  .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
3388
3550
  `;
3389
3551
 
@@ -3472,6 +3634,10 @@ var TAG = "lambforge-agent-chat";
3472
3634
  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"/>`;
3473
3635
  var ICON_CLOSE = import_lit_html19.svg`<path d="M18 6 6 18M6 6l12 12"/>`;
3474
3636
  var ICON_NEW = import_lit_html19.svg`<path d="M12 5v14M5 12h14"/>`;
3637
+ var ICON_UP = import_lit_html19.svg`<path d="M7 10v12M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2a3.13 3.13 0 0 1 3 3.88Z"/>`;
3638
+ var ICON_DOWN = import_lit_html19.svg`<path d="M17 14V2M9 18.12 10 14H4.17a2 2 0 0 1-1.92-2.56l2.33-8A2 2 0 0 1 6.5 2H20a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2.76a2 2 0 0 0-1.79 1.11L12 22a3.13 3.13 0 0 1-3-3.88Z"/>`;
3639
+ 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"/>`;
3640
+ var ACCEPT = [...ACCEPTED_ATTACHMENT_TYPES, ".md", ".csv", ".yaml", ".yml", ".json", ".txt"].join(",");
3475
3641
  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>`;
3476
3642
  var LambforgeAgentChat = class extends import_lit_html19.LitElement {
3477
3643
  constructor() {
@@ -3581,16 +3747,36 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
3581
3747
  throw new Error("turnstile: the chat is not rendered");
3582
3748
  }
3583
3749
  // ------------------------------------------------------------ actions
3584
- /** Send a message to the selected agent. */
3750
+ /** Send a message (with the picked files) to the selected agent. */
3585
3751
  send(text) {
3586
3752
  return ([state]) => {
3587
- const clean = String(text ?? "").trim();
3753
+ const files = state.files;
3754
+ const clean = String(text ?? "").trim() || (files.length ? this.t.filesOnly : "");
3588
3755
  if (!clean || state.answering || !state.agentId) return;
3589
3756
  this.dispatch(
3590
- sendMessage({ agentId: state.agentId, conversationId: state.conversationId, text: clean })
3757
+ sendMessage({
3758
+ agentId: state.agentId,
3759
+ conversationId: state.conversationId,
3760
+ text: clean,
3761
+ ...files.length ? { files } : {}
3762
+ })
3591
3763
  );
3592
3764
  };
3593
3765
  }
3766
+ /** Files for the next message (the reducer refuses what the API would). */
3767
+ attach(files) {
3768
+ const list = Array.from(files ?? []);
3769
+ if (list.length) this.dispatch(addFiles(list));
3770
+ }
3771
+ detach(index) {
3772
+ this.dispatch(removeFile(index));
3773
+ }
3774
+ onPaste(ev, allowed) {
3775
+ const files = Array.from(ev.clipboardData?.files ?? []);
3776
+ if (!allowed || !files.length) return;
3777
+ ev.preventDefault();
3778
+ this.attach(files);
3779
+ }
3594
3780
  /** Stop the answer in progress. */
3595
3781
  stopAnswer() {
3596
3782
  return ([state]) => {
@@ -3678,6 +3864,7 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
3678
3864
  const drawer = this.mode === "drawer";
3679
3865
  const agent = state.agents.find((a5) => a5.id === state.agentId) ?? null;
3680
3866
  const title = this.heading || agent?.name || t9.title;
3867
+ const canAttach = !!agent?.allowAttachments;
3681
3868
  const live = state.live?.text ? state.live : null;
3682
3869
  const notice = live && state.notice?.kind === "busy" ? null : state.notice;
3683
3870
  const size = `${state.messages.length}:${live?.text.length ?? 0}`;
@@ -3737,7 +3924,7 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
3737
3924
  aria-relevant="additions"
3738
3925
  aria-busy=${String(!!live)}
3739
3926
  >
3740
- ${state.messages.length ? state.messages.map((m4) => this.bubble(m4)) : this.intro(state)}
3927
+ ${state.messages.length ? state.messages.map((m4) => this.bubble(m4, state)) : this.intro(state)}
3741
3928
  ${live ? import_lit_html19.html`<div class="msg assistant live" part="message assistant live">${renderMarkdown(live.text)}</div>` : ""}
3742
3929
  </div>
3743
3930
  <div class="turnstile" ?hidden=${notice?.kind !== "busy" || notice.what !== "verifying"}></div>
@@ -3746,7 +3933,40 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
3746
3933
  part="status"
3747
3934
  role="status"
3748
3935
  >${this.noticeText(notice)}</div>
3936
+ ${canAttach && state.files.length ? import_lit_html19.html`<ul class="files" part="files" aria-label=${t9.attached}>
3937
+ ${state.files.map(
3938
+ (f4, i12) => import_lit_html19.html`<li class="file" part="file">
3939
+ <span class="file-name" title=${f4.name}>${f4.name}</span>
3940
+ <button type="button" class="file-remove" aria-label=${`${t9.removeFile}: ${f4.name}`} @click=${() => this.detach(i12)}>
3941
+ ${icon(ICON_CLOSE)}
3942
+ </button>
3943
+ </li>`
3944
+ )}
3945
+ </ul>` : ""}
3749
3946
  <form part="composer" @submit=${(ev) => this.submit(ev, state)}>
3947
+ ${canAttach ? import_lit_html19.html`<input
3948
+ class="file-input"
3949
+ type="file"
3950
+ multiple
3951
+ accept=${ACCEPT}
3952
+ hidden
3953
+ @change=${(ev) => {
3954
+ const input = ev.target;
3955
+ this.attach(input.files);
3956
+ input.value = "";
3957
+ }}
3958
+ />
3959
+ <button
3960
+ class="icon attach"
3961
+ part="attach"
3962
+ type="button"
3963
+ title=${t9.attach}
3964
+ aria-label=${t9.attach}
3965
+ ?disabled=${state.answering}
3966
+ @click=${() => this.shadowRoot?.querySelector(".file-input")?.click()}
3967
+ >
3968
+ ${icon(ICON_ATTACH)}
3969
+ </button>` : ""}
3750
3970
  <label class="sr-only" for="lf-input">${t9.placeholder}</label>
3751
3971
  <textarea
3752
3972
  id="lf-input"
@@ -3755,6 +3975,7 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
3755
3975
  placeholder=${t9.placeholder}
3756
3976
  @keydown=${(ev) => this.onInputKey(ev, state)}
3757
3977
  @input=${(ev) => this.autosize(ev.target)}
3978
+ @paste=${(ev) => this.onPaste(ev, canAttach && !state.answering)}
3758
3979
  ></textarea>
3759
3980
  <button class="send" part="send" type="submit" aria-label=${state.answering ? t9.stop : t9.send}>
3760
3981
  ${state.answering ? t9.stop : t9.send}
@@ -3763,14 +3984,67 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
3763
3984
  </section>
3764
3985
  `;
3765
3986
  }
3766
- bubble(m4) {
3987
+ /**
3988
+ * Rate an answer: the same thumb again clears it. Only stored answers of
3989
+ * an agent that takes ratings (plan 51 §15 #7).
3990
+ */
3991
+ rateAnswer(m4, rating, comment) {
3992
+ return ([state]) => {
3993
+ if (!state.agentId || !state.conversationId) return;
3994
+ const next = comment === void 0 && m4.feedback === rating ? null : rating;
3995
+ this.dispatch(
3996
+ rate({
3997
+ agentId: state.agentId,
3998
+ conversationId: state.conversationId,
3999
+ messageId: m4.id,
4000
+ rating: next,
4001
+ ...comment !== void 0 ? { comment } : {},
4002
+ previous: m4.feedback
4003
+ })
4004
+ );
4005
+ };
4006
+ }
4007
+ sendComment(ev, m4, state) {
4008
+ ev.preventDefault();
4009
+ const input = ev.target.querySelector("input");
4010
+ const text = input?.value.trim() ?? "";
4011
+ if (!text) {
4012
+ this.dispatch(closeComment());
4013
+ return;
4014
+ }
4015
+ this.rateAnswer(m4, "down", text)([state]);
4016
+ }
4017
+ feedback(m4, state) {
4018
+ const agent = state.agents.find((a5) => a5.id === state.agentId);
4019
+ if (agent?.allowFeedback === false || m4.id.startsWith("local:") || !state.conversationId) return "";
4020
+ const t9 = this.t;
4021
+ return import_lit_html19.html`
4022
+ <div class="rate" part="rate">
4023
+ <button type="button" class="thumb ${m4.feedback === "up" ? "on" : ""}" part="thumb-up"
4024
+ title=${t9.helpful} aria-label=${t9.helpful} aria-pressed=${m4.feedback === "up" ? "true" : "false"}
4025
+ @click=${() => this.rateAnswer(m4, "up")([state])}>${icon(ICON_UP)}</button>
4026
+ <button type="button" class="thumb ${m4.feedback === "down" ? "on" : ""}" part="thumb-down"
4027
+ title=${t9.notHelpful} aria-label=${t9.notHelpful} aria-pressed=${m4.feedback === "down" ? "true" : "false"}
4028
+ @click=${() => this.rateAnswer(m4, "down")([state])}>${icon(ICON_DOWN)}</button>
4029
+ ${m4.feedback && state.commentFor !== m4.id ? import_lit_html19.html`<span class="thanks" aria-live="polite">${t9.thanks}</span>` : ""}
4030
+ </div>
4031
+ ${state.commentFor === m4.id ? import_lit_html19.html`<form class="comment" part="feedback-comment" @submit=${(ev) => this.sendComment(ev, m4, state)}>
4032
+ <input type="text" maxlength="1000" placeholder=${t9.whatWentWrong} aria-label=${t9.whatWentWrong}
4033
+ @keydown=${(ev) => ev.key === "Escape" && this.dispatch(closeComment())} />
4034
+ <button type="submit">${t9.sendFeedback}</button>
4035
+ <button type="button" class="skip" @click=${() => this.dispatch(closeComment())}>${t9.skipFeedback}</button>
4036
+ </form>` : ""}
4037
+ `;
4038
+ }
4039
+ bubble(m4, state) {
3767
4040
  if (m4.role === "user") {
3768
- return import_lit_html19.html`<div class="msg user" part="message user">${m4.text}</div>`;
4041
+ 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>`;
3769
4042
  }
3770
4043
  return import_lit_html19.html`<div class="msg assistant" part="message assistant">
3771
4044
  ${renderMarkdown(m4.text)}
3772
4045
  ${m4.tools.length ? import_lit_html19.html`<div class="tools">${this.t.usedTools}: ${m4.tools.join(", ")}</div>` : ""}
3773
- </div>`;
4046
+ </div>
4047
+ ${this.feedback(m4, state)}`;
3774
4048
  }
3775
4049
  intro(state) {
3776
4050
  const agent = state.agents.find((a5) => a5.id === state.agentId);
@@ -3861,9 +4135,11 @@ export {
3861
4135
  LOCALES,
3862
4136
  LambforgeAgentChat,
3863
4137
  TAG,
4138
+ addFiles,
3864
4139
  agentEvent,
3865
4140
  agentsLoaded,
3866
4141
  chatReducer,
4142
+ closeComment,
3867
4143
  connecting,
3868
4144
  errorCode,
3869
4145
  failed,
@@ -3873,6 +4149,9 @@ export {
3873
4149
  newConversation,
3874
4150
  pickAgent,
3875
4151
  pickAgents,
4152
+ rate,
4153
+ rateFailed,
4154
+ removeFile,
3876
4155
  renderMarkdown,
3877
4156
  resume,
3878
4157
  runEnded,