@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/README.md +15 -0
- package/dist/agent-chat.js +124 -39
- package/dist/agent-chat.js.map +4 -4
- package/dist/index.cjs +297 -18
- package/dist/index.cjs.map +4 -4
- package/dist/index.mjs +294 -15
- package/dist/index.mjs.map +4 -4
- package/package.json +3 -3
- package/types/index.d.ts +19 -0
package/dist/index.cjs
CHANGED
|
@@ -2436,9 +2436,11 @@ __export(index_exports, {
|
|
|
2436
2436
|
LOCALES: () => LOCALES,
|
|
2437
2437
|
LambforgeAgentChat: () => LambforgeAgentChat,
|
|
2438
2438
|
TAG: () => TAG,
|
|
2439
|
+
addFiles: () => addFiles,
|
|
2439
2440
|
agentEvent: () => agentEvent,
|
|
2440
2441
|
agentsLoaded: () => agentsLoaded,
|
|
2441
2442
|
chatReducer: () => chatReducer,
|
|
2443
|
+
closeComment: () => closeComment,
|
|
2442
2444
|
connecting: () => connecting,
|
|
2443
2445
|
errorCode: () => errorCode,
|
|
2444
2446
|
failed: () => failed,
|
|
@@ -2448,6 +2450,9 @@ __export(index_exports, {
|
|
|
2448
2450
|
newConversation: () => newConversation,
|
|
2449
2451
|
pickAgent: () => pickAgent,
|
|
2450
2452
|
pickAgents: () => pickAgents,
|
|
2453
|
+
rate: () => rate,
|
|
2454
|
+
rateFailed: () => rateFailed,
|
|
2455
|
+
removeFile: () => removeFile,
|
|
2451
2456
|
renderMarkdown: () => renderMarkdown,
|
|
2452
2457
|
resume: () => resume,
|
|
2453
2458
|
runEnded: () => runEnded,
|
|
@@ -2462,7 +2467,7 @@ __export(index_exports, {
|
|
|
2462
2467
|
module.exports = __toCommonJS(index_exports);
|
|
2463
2468
|
|
|
2464
2469
|
// src/element.ts
|
|
2465
|
-
var
|
|
2470
|
+
var import_agents2 = require("@lambforge/agents");
|
|
2466
2471
|
var import_component = __toESM(require_dist3());
|
|
2467
2472
|
var import_lit_html19 = __toESM(require_dist());
|
|
2468
2473
|
var import_rxjs8 = require("rxjs");
|
|
@@ -2660,7 +2665,12 @@ var historyLoaded = action(
|
|
|
2660
2665
|
payload()
|
|
2661
2666
|
);
|
|
2662
2667
|
var newConversation = action("[chat] new conversation");
|
|
2663
|
-
var sendMessage = action(
|
|
2668
|
+
var sendMessage = action(
|
|
2669
|
+
"[chat] send",
|
|
2670
|
+
payload()
|
|
2671
|
+
);
|
|
2672
|
+
var addFiles = action("[chat] add files", payload());
|
|
2673
|
+
var removeFile = action("[chat] remove file", payload());
|
|
2664
2674
|
var resume = action(
|
|
2665
2675
|
"[chat] resume",
|
|
2666
2676
|
payload()
|
|
@@ -2668,6 +2678,12 @@ var resume = action(
|
|
|
2668
2678
|
var agentEvent = action("[chat] event", payload());
|
|
2669
2679
|
var runEnded = action("[chat] run ended");
|
|
2670
2680
|
var stop = action("[chat] stop", payload());
|
|
2681
|
+
var rate = action("[chat] rate", payload());
|
|
2682
|
+
var rateFailed = action(
|
|
2683
|
+
"[chat] rate failed",
|
|
2684
|
+
payload()
|
|
2685
|
+
);
|
|
2686
|
+
var closeComment = action("[chat] close comment");
|
|
2671
2687
|
|
|
2672
2688
|
// ../../node_modules/@rxdi/redux-store/dist/esm/interfaces.js
|
|
2673
2689
|
var FlattenOperator;
|
|
@@ -2965,9 +2981,14 @@ var ChatEffects = class {
|
|
|
2965
2981
|
action$.pipe(
|
|
2966
2982
|
ofType(sendMessage),
|
|
2967
2983
|
(0, import_operators7.map)(({ payload: payload2 }) => {
|
|
2968
|
-
const { agentId, conversationId, text } = payload2;
|
|
2984
|
+
const { agentId, conversationId, text, files } = payload2;
|
|
2969
2985
|
const c9 = this.conversation(agentId, conversationId);
|
|
2970
|
-
|
|
2986
|
+
const attachments = (files ?? []).map((file) => ({
|
|
2987
|
+
name: file.name,
|
|
2988
|
+
mimeType: file.type || void 0,
|
|
2989
|
+
data: file
|
|
2990
|
+
}));
|
|
2991
|
+
return { c: c9, events: attachments.length ? c9.send(text, { attachments }) : c9.send(text) };
|
|
2971
2992
|
})
|
|
2972
2993
|
),
|
|
2973
2994
|
action$.pipe(
|
|
@@ -3001,6 +3022,20 @@ var ChatEffects = class {
|
|
|
3001
3022
|
})
|
|
3002
3023
|
)
|
|
3003
3024
|
);
|
|
3025
|
+
/** Send a rating; a refusal puts the earlier one back. */
|
|
3026
|
+
this.rate$ = createEffect()(
|
|
3027
|
+
(action$) => action$.pipe(
|
|
3028
|
+
ofType(rate),
|
|
3029
|
+
(0, import_operators7.mergeMap)(({ payload: payload2 }) => {
|
|
3030
|
+
const { agentId, conversationId, messageId, rating, comment, previous } = payload2;
|
|
3031
|
+
if (!this.ctx.client) return import_rxjs6.EMPTY;
|
|
3032
|
+
return this.conversation(agentId, conversationId).rate(messageId, rating, comment).pipe(
|
|
3033
|
+
(0, import_operators7.ignoreElements)(),
|
|
3034
|
+
(0, import_operators7.catchError)(() => (0, import_rxjs6.of)(rateFailed({ messageId, previous })))
|
|
3035
|
+
);
|
|
3036
|
+
})
|
|
3037
|
+
)
|
|
3038
|
+
);
|
|
3004
3039
|
/** Failures also reach the page as an `error` event. */
|
|
3005
3040
|
this.failures$ = createEffect()(
|
|
3006
3041
|
(action$) => action$.pipe(
|
|
@@ -3030,6 +3065,9 @@ var ChatEffects = class {
|
|
|
3030
3065
|
}
|
|
3031
3066
|
};
|
|
3032
3067
|
|
|
3068
|
+
// src/store/chat-reducer.ts
|
|
3069
|
+
var import_agents = require("@lambforge/agents");
|
|
3070
|
+
|
|
3033
3071
|
// src/store/chat-state.ts
|
|
3034
3072
|
var initialChatState = {
|
|
3035
3073
|
shown: false,
|
|
@@ -3039,16 +3077,33 @@ var initialChatState = {
|
|
|
3039
3077
|
messages: [],
|
|
3040
3078
|
answering: false,
|
|
3041
3079
|
live: null,
|
|
3042
|
-
notice: null
|
|
3080
|
+
notice: null,
|
|
3081
|
+
files: [],
|
|
3082
|
+
commentFor: null
|
|
3043
3083
|
};
|
|
3044
3084
|
function toMessage(m4) {
|
|
3045
3085
|
const tools = (m4.toolCalls ?? []).map((c9) => c9?.name).filter((n11) => !!n11);
|
|
3046
|
-
return {
|
|
3086
|
+
return {
|
|
3087
|
+
id: m4.id,
|
|
3088
|
+
role: m4.role,
|
|
3089
|
+
text: m4.text ?? "",
|
|
3090
|
+
tools: Array.from(new Set(tools)),
|
|
3091
|
+
attachments: (m4.attachments ?? []).map((a5) => a5.name),
|
|
3092
|
+
feedback: m4.feedback?.rating ?? null
|
|
3093
|
+
};
|
|
3047
3094
|
}
|
|
3048
3095
|
|
|
3049
3096
|
// src/store/chat-reducer.ts
|
|
3050
3097
|
var LOCAL_ID = /^local:/;
|
|
3051
|
-
var empty = {
|
|
3098
|
+
var empty = {
|
|
3099
|
+
conversationId: null,
|
|
3100
|
+
messages: [],
|
|
3101
|
+
answering: false,
|
|
3102
|
+
live: null,
|
|
3103
|
+
notice: null,
|
|
3104
|
+
files: [],
|
|
3105
|
+
commentFor: null
|
|
3106
|
+
};
|
|
3052
3107
|
var chatReducer = reducer(
|
|
3053
3108
|
initialChatState,
|
|
3054
3109
|
on(shown, (s9, { payload: payload2 }) => s9.shown || !payload2 ? s9 : { ...s9, shown: true }),
|
|
@@ -3087,11 +3142,32 @@ var chatReducer = reducer(
|
|
|
3087
3142
|
// shown at once; replaced by the stored copy when it arrives
|
|
3088
3143
|
messages: [
|
|
3089
3144
|
...s9.messages,
|
|
3090
|
-
{
|
|
3145
|
+
{
|
|
3146
|
+
id: `local:${s9.messages.length}`,
|
|
3147
|
+
role: "user",
|
|
3148
|
+
text: payload2.text,
|
|
3149
|
+
tools: [],
|
|
3150
|
+
attachments: (payload2.files ?? []).map((f4) => f4.name),
|
|
3151
|
+
feedback: null
|
|
3152
|
+
}
|
|
3091
3153
|
],
|
|
3154
|
+
files: [],
|
|
3092
3155
|
answering: true,
|
|
3093
3156
|
notice: { kind: "busy", what: "thinking" }
|
|
3094
3157
|
})),
|
|
3158
|
+
on(addFiles, (s9, { payload: payload2 }) => {
|
|
3159
|
+
const agent = s9.agents.find((a5) => a5.id === s9.agentId);
|
|
3160
|
+
if (!agent?.allowAttachments) return { ...s9, notice: { kind: "error", code: "attachments-off" } };
|
|
3161
|
+
const files = [...s9.files, ...payload2];
|
|
3162
|
+
const problem = (0, import_agents.attachmentsProblem)(files);
|
|
3163
|
+
if (problem) return { ...s9, notice: { kind: "error", code: problem } };
|
|
3164
|
+
return { ...s9, files, notice: s9.notice?.kind === "error" ? null : s9.notice };
|
|
3165
|
+
}),
|
|
3166
|
+
on(removeFile, (s9, { payload: payload2 }) => ({
|
|
3167
|
+
...s9,
|
|
3168
|
+
files: s9.files.filter((_2, i12) => i12 !== payload2),
|
|
3169
|
+
notice: s9.notice?.kind === "error" ? null : s9.notice
|
|
3170
|
+
})),
|
|
3095
3171
|
on(agentEvent, (s9, { payload: payload2 }) => withEvent(s9, payload2)),
|
|
3096
3172
|
on(runEnded, (s9) => ({
|
|
3097
3173
|
...s9,
|
|
@@ -3099,6 +3175,22 @@ var chatReducer = reducer(
|
|
|
3099
3175
|
live: null,
|
|
3100
3176
|
notice: s9.notice?.kind === "busy" ? null : s9.notice
|
|
3101
3177
|
})),
|
|
3178
|
+
on(rate, (s9, { payload: payload2 }) => ({
|
|
3179
|
+
...s9,
|
|
3180
|
+
messages: s9.messages.map(
|
|
3181
|
+
(m4) => m4.id === payload2.messageId ? { ...m4, feedback: payload2.rating } : m4
|
|
3182
|
+
),
|
|
3183
|
+
// a fresh thumbs down asks what was wrong; a comment or anything else closes it
|
|
3184
|
+
commentFor: payload2.rating === "down" && payload2.comment === void 0 && payload2.previous !== "down" ? payload2.messageId : null
|
|
3185
|
+
})),
|
|
3186
|
+
on(rateFailed, (s9, { payload: payload2 }) => ({
|
|
3187
|
+
...s9,
|
|
3188
|
+
messages: s9.messages.map(
|
|
3189
|
+
(m4) => m4.id === payload2.messageId ? { ...m4, feedback: payload2.previous } : m4
|
|
3190
|
+
),
|
|
3191
|
+
commentFor: s9.commentFor === payload2.messageId ? null : s9.commentFor
|
|
3192
|
+
})),
|
|
3193
|
+
on(closeComment, (s9) => ({ ...s9, commentFor: null })),
|
|
3102
3194
|
on(stop, (s9) => ({ ...s9, answering: false, live: null, notice: { kind: "info", what: "stopped" } }))
|
|
3103
3195
|
);
|
|
3104
3196
|
function withEvent(s9, event) {
|
|
@@ -3150,6 +3242,7 @@ var ChatStore = class {
|
|
|
3150
3242
|
effects.select$,
|
|
3151
3243
|
effects.run$,
|
|
3152
3244
|
effects.abort$,
|
|
3245
|
+
effects.rate$,
|
|
3153
3246
|
effects.failures$,
|
|
3154
3247
|
effects.connect$
|
|
3155
3248
|
),
|
|
@@ -3180,6 +3273,16 @@ var en = {
|
|
|
3180
3273
|
pickAgent: "Assistant",
|
|
3181
3274
|
usedTools: "Used",
|
|
3182
3275
|
verifying: "Checking that you are human",
|
|
3276
|
+
attach: "Attach files",
|
|
3277
|
+
attached: "Attached files",
|
|
3278
|
+
removeFile: "Remove",
|
|
3279
|
+
filesOnly: "Please look at the attached files.",
|
|
3280
|
+
helpful: "Helpful",
|
|
3281
|
+
notHelpful: "Not helpful",
|
|
3282
|
+
whatWentWrong: "What was wrong? (optional)",
|
|
3283
|
+
sendFeedback: "Send",
|
|
3284
|
+
skipFeedback: "Skip",
|
|
3285
|
+
thanks: "Thanks for the feedback",
|
|
3183
3286
|
errors: {
|
|
3184
3287
|
"limit-reached": "This conversation is full - start a new one.",
|
|
3185
3288
|
"cap-reached": "The assistant is not available right now - try again later.",
|
|
@@ -3191,6 +3294,13 @@ var en = {
|
|
|
3191
3294
|
unauthorized: "This chat is not allowed here.",
|
|
3192
3295
|
"bad-request": "That did not work - try again.",
|
|
3193
3296
|
network: "No connection - try again.",
|
|
3297
|
+
"attachments-off": "This assistant does not take files.",
|
|
3298
|
+
"attachments-unsupported": "This assistant cannot read that kind of file.",
|
|
3299
|
+
"attachment-invalid": "Only images, PDF and text files can be attached.",
|
|
3300
|
+
"attachment-too-large": "That file is too large (images 5 MB, PDF 10 MB, text 1 MB).",
|
|
3301
|
+
"attachment-limit": "At most 5 files and 15 MB in one message.",
|
|
3302
|
+
"attachment-missing": "A file was lost - attach it again.",
|
|
3303
|
+
"attachment-not-uploaded": "A file did not finish uploading - attach it again.",
|
|
3194
3304
|
default: "Something went wrong - try again."
|
|
3195
3305
|
}
|
|
3196
3306
|
};
|
|
@@ -3207,6 +3317,16 @@ var bg = {
|
|
|
3207
3317
|
pickAgent: "\u0410\u0441\u0438\u0441\u0442\u0435\u043D\u0442",
|
|
3208
3318
|
usedTools: "\u0418\u0437\u043F\u043E\u043B\u0437\u0432\u0430\u043D\u043E",
|
|
3209
3319
|
verifying: "\u041F\u0440\u043E\u0432\u0435\u0440\u043A\u0430, \u0447\u0435 \u0441\u0442\u0435 \u0447\u043E\u0432\u0435\u043A",
|
|
3320
|
+
attach: "\u041F\u0440\u0438\u043A\u0430\u0447\u0438 \u0444\u0430\u0439\u043B\u043E\u0432\u0435",
|
|
3321
|
+
attached: "\u041F\u0440\u0438\u043A\u0430\u0447\u0435\u043D\u0438 \u0444\u0430\u0439\u043B\u043E\u0432\u0435",
|
|
3322
|
+
removeFile: "\u041F\u0440\u0435\u043C\u0430\u0445\u043D\u0438",
|
|
3323
|
+
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.",
|
|
3324
|
+
helpful: "\u041F\u043E\u043B\u0435\u0437\u043D\u043E",
|
|
3325
|
+
notHelpful: "\u041D\u0435 \u0435 \u043F\u043E\u043B\u0435\u0437\u043D\u043E",
|
|
3326
|
+
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)",
|
|
3327
|
+
sendFeedback: "\u0418\u0437\u043F\u0440\u0430\u0442\u0438",
|
|
3328
|
+
skipFeedback: "\u041F\u0440\u043E\u043F\u0443\u0441\u043D\u0438",
|
|
3329
|
+
thanks: "\u0411\u043B\u0430\u0433\u043E\u0434\u0430\u0440\u0438\u043C \u0437\u0430 \u043E\u0442\u0437\u0438\u0432\u0430",
|
|
3210
3330
|
errors: {
|
|
3211
3331
|
"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.",
|
|
3212
3332
|
"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.",
|
|
@@ -3218,6 +3338,13 @@ var bg = {
|
|
|
3218
3338
|
unauthorized: "\u0422\u043E\u0437\u0438 \u0447\u0430\u0442 \u043D\u0435 \u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043D \u0442\u0443\u043A.",
|
|
3219
3339
|
"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.",
|
|
3220
3340
|
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.",
|
|
3341
|
+
"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.",
|
|
3342
|
+
"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.",
|
|
3343
|
+
"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.",
|
|
3344
|
+
"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).",
|
|
3345
|
+
"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.",
|
|
3346
|
+
"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.",
|
|
3347
|
+
"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.",
|
|
3221
3348
|
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."
|
|
3222
3349
|
}
|
|
3223
3350
|
};
|
|
@@ -3363,6 +3490,26 @@ header select {
|
|
|
3363
3490
|
@keyframes lf-caret { 50% { opacity: 0; } }
|
|
3364
3491
|
@media (prefers-reduced-motion: reduce) { .msg.live > :last-child::after { animation: none; } }
|
|
3365
3492
|
.tools { font-size: 12px; color: var(--_muted); margin-top: 4px; }
|
|
3493
|
+
.rate { display: flex; align-items: center; gap: 2px; margin-top: -6px; }
|
|
3494
|
+
.thumb {
|
|
3495
|
+
border: 0; background: transparent; color: var(--_muted);
|
|
3496
|
+
width: 26px; height: 26px; border-radius: 6px; display: grid; place-items: center; cursor: pointer;
|
|
3497
|
+
}
|
|
3498
|
+
.thumb svg { width: 14px; height: 14px; }
|
|
3499
|
+
.thumb:hover, .thumb:focus-visible { background: var(--_bot-bg); color: var(--_fg); }
|
|
3500
|
+
.thumb.on { color: var(--_accent); }
|
|
3501
|
+
.thanks { font-size: 12px; color: var(--_muted); margin-left: 4px; }
|
|
3502
|
+
.comment { display: flex; gap: 6px; align-items: center; max-width: 85%; }
|
|
3503
|
+
.comment input {
|
|
3504
|
+
flex: 1; min-width: 0; font: inherit; font-size: 13px; color: var(--_fg); background: var(--_bg);
|
|
3505
|
+
border: 1px solid var(--_border); border-radius: 8px; padding: 6px 8px;
|
|
3506
|
+
}
|
|
3507
|
+
.comment button {
|
|
3508
|
+
border: 1px solid var(--_border); background: transparent; color: var(--_fg);
|
|
3509
|
+
border-radius: 8px; padding: 5px 9px; font-size: 13px; cursor: pointer;
|
|
3510
|
+
}
|
|
3511
|
+
.comment button[type='submit'] { border-color: var(--_accent); color: var(--_accent); }
|
|
3512
|
+
.comment .skip { color: var(--_muted); }
|
|
3366
3513
|
|
|
3367
3514
|
.welcome { color: var(--_muted); }
|
|
3368
3515
|
.suggestions { display: flex; flex-wrap: wrap; gap: 6px; }
|
|
@@ -3406,6 +3553,26 @@ textarea:focus-visible { outline: 2px solid var(--_accent); outline-offset: 0; b
|
|
|
3406
3553
|
padding: 0 14px; height: 40px; font-weight: 600;
|
|
3407
3554
|
}
|
|
3408
3555
|
.send:disabled { opacity: 0.5; cursor: default; }
|
|
3556
|
+
.attach { flex: none; height: 40px; }
|
|
3557
|
+
.attach:disabled { opacity: 0.5; cursor: default; }
|
|
3558
|
+
.files {
|
|
3559
|
+
list-style: none; margin: 0; padding: 8px 12px 0; display: flex; flex-wrap: wrap; gap: 6px;
|
|
3560
|
+
border-top: 1px solid var(--_border);
|
|
3561
|
+
}
|
|
3562
|
+
.file {
|
|
3563
|
+
display: inline-flex; align-items: center; gap: 2px; max-width: 100%;
|
|
3564
|
+
border: 1px solid var(--_border); border-radius: 999px; padding: 2px 2px 2px 10px; font-size: 13px;
|
|
3565
|
+
}
|
|
3566
|
+
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
|
|
3567
|
+
.file-remove {
|
|
3568
|
+
border: 0; background: transparent; color: var(--_muted); width: 22px; height: 22px;
|
|
3569
|
+
border-radius: 999px; display: grid; place-items: center; padding: 0;
|
|
3570
|
+
}
|
|
3571
|
+
.file-remove:hover, .file-remove:focus-visible { background: var(--_bot-bg); color: var(--_fg); }
|
|
3572
|
+
.file-remove svg { width: 14px; height: 14px; }
|
|
3573
|
+
.files + form { border-top: 0; }
|
|
3574
|
+
.msg-files { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
|
|
3575
|
+
.msg-file { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: rgba(255,255,255,0.2); }
|
|
3409
3576
|
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
3410
3577
|
`;
|
|
3411
3578
|
|
|
@@ -3494,6 +3661,10 @@ var TAG = "lambforge-agent-chat";
|
|
|
3494
3661
|
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"/>`;
|
|
3495
3662
|
var ICON_CLOSE = import_lit_html19.svg`<path d="M18 6 6 18M6 6l12 12"/>`;
|
|
3496
3663
|
var ICON_NEW = import_lit_html19.svg`<path d="M12 5v14M5 12h14"/>`;
|
|
3664
|
+
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"/>`;
|
|
3665
|
+
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"/>`;
|
|
3666
|
+
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"/>`;
|
|
3667
|
+
var ACCEPT = [...import_agents2.ACCEPTED_ATTACHMENT_TYPES, ".md", ".csv", ".yaml", ".yml", ".json", ".txt"].join(",");
|
|
3497
3668
|
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>`;
|
|
3498
3669
|
var LambforgeAgentChat = class extends import_lit_html19.LitElement {
|
|
3499
3670
|
constructor() {
|
|
@@ -3556,10 +3727,10 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
|
|
|
3556
3727
|
const url = this.url || void 0;
|
|
3557
3728
|
if (this.getToken) {
|
|
3558
3729
|
const source = this.getToken;
|
|
3559
|
-
this.client = new
|
|
3730
|
+
this.client = new import_agents2.AgentClient({ url, getToken: () => source() });
|
|
3560
3731
|
} else if (this.tokenUrl) {
|
|
3561
3732
|
const tokenUrl = this.tokenUrl;
|
|
3562
|
-
this.client = new
|
|
3733
|
+
this.client = new import_agents2.AgentClient({
|
|
3563
3734
|
url,
|
|
3564
3735
|
getToken: () => fetch(tokenUrl, {
|
|
3565
3736
|
credentials: "include",
|
|
@@ -3570,7 +3741,7 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
|
|
|
3570
3741
|
})
|
|
3571
3742
|
});
|
|
3572
3743
|
} else if (this.publishableKey) {
|
|
3573
|
-
this.client = new
|
|
3744
|
+
this.client = new import_agents2.AgentClient({
|
|
3574
3745
|
url,
|
|
3575
3746
|
anonymous: {
|
|
3576
3747
|
publishableKey: this.publishableKey,
|
|
@@ -3603,16 +3774,36 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
|
|
|
3603
3774
|
throw new Error("turnstile: the chat is not rendered");
|
|
3604
3775
|
}
|
|
3605
3776
|
// ------------------------------------------------------------ actions
|
|
3606
|
-
/** Send a message to the selected agent. */
|
|
3777
|
+
/** Send a message (with the picked files) to the selected agent. */
|
|
3607
3778
|
send(text) {
|
|
3608
3779
|
return ([state]) => {
|
|
3609
|
-
const
|
|
3780
|
+
const files = state.files;
|
|
3781
|
+
const clean = String(text ?? "").trim() || (files.length ? this.t.filesOnly : "");
|
|
3610
3782
|
if (!clean || state.answering || !state.agentId) return;
|
|
3611
3783
|
this.dispatch(
|
|
3612
|
-
sendMessage({
|
|
3784
|
+
sendMessage({
|
|
3785
|
+
agentId: state.agentId,
|
|
3786
|
+
conversationId: state.conversationId,
|
|
3787
|
+
text: clean,
|
|
3788
|
+
...files.length ? { files } : {}
|
|
3789
|
+
})
|
|
3613
3790
|
);
|
|
3614
3791
|
};
|
|
3615
3792
|
}
|
|
3793
|
+
/** Files for the next message (the reducer refuses what the API would). */
|
|
3794
|
+
attach(files) {
|
|
3795
|
+
const list = Array.from(files ?? []);
|
|
3796
|
+
if (list.length) this.dispatch(addFiles(list));
|
|
3797
|
+
}
|
|
3798
|
+
detach(index) {
|
|
3799
|
+
this.dispatch(removeFile(index));
|
|
3800
|
+
}
|
|
3801
|
+
onPaste(ev, allowed) {
|
|
3802
|
+
const files = Array.from(ev.clipboardData?.files ?? []);
|
|
3803
|
+
if (!allowed || !files.length) return;
|
|
3804
|
+
ev.preventDefault();
|
|
3805
|
+
this.attach(files);
|
|
3806
|
+
}
|
|
3616
3807
|
/** Stop the answer in progress. */
|
|
3617
3808
|
stopAnswer() {
|
|
3618
3809
|
return ([state]) => {
|
|
@@ -3700,6 +3891,7 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
|
|
|
3700
3891
|
const drawer = this.mode === "drawer";
|
|
3701
3892
|
const agent = state.agents.find((a5) => a5.id === state.agentId) ?? null;
|
|
3702
3893
|
const title = this.heading || agent?.name || t9.title;
|
|
3894
|
+
const canAttach = !!agent?.allowAttachments;
|
|
3703
3895
|
const live = state.live?.text ? state.live : null;
|
|
3704
3896
|
const notice = live && state.notice?.kind === "busy" ? null : state.notice;
|
|
3705
3897
|
const size = `${state.messages.length}:${live?.text.length ?? 0}`;
|
|
@@ -3759,7 +3951,7 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
|
|
|
3759
3951
|
aria-relevant="additions"
|
|
3760
3952
|
aria-busy=${String(!!live)}
|
|
3761
3953
|
>
|
|
3762
|
-
${state.messages.length ? state.messages.map((m4) => this.bubble(m4)) : this.intro(state)}
|
|
3954
|
+
${state.messages.length ? state.messages.map((m4) => this.bubble(m4, state)) : this.intro(state)}
|
|
3763
3955
|
${live ? import_lit_html19.html`<div class="msg assistant live" part="message assistant live">${renderMarkdown(live.text)}</div>` : ""}
|
|
3764
3956
|
</div>
|
|
3765
3957
|
<div class="turnstile" ?hidden=${notice?.kind !== "busy" || notice.what !== "verifying"}></div>
|
|
@@ -3768,7 +3960,40 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
|
|
|
3768
3960
|
part="status"
|
|
3769
3961
|
role="status"
|
|
3770
3962
|
>${this.noticeText(notice)}</div>
|
|
3963
|
+
${canAttach && state.files.length ? import_lit_html19.html`<ul class="files" part="files" aria-label=${t9.attached}>
|
|
3964
|
+
${state.files.map(
|
|
3965
|
+
(f4, i12) => import_lit_html19.html`<li class="file" part="file">
|
|
3966
|
+
<span class="file-name" title=${f4.name}>${f4.name}</span>
|
|
3967
|
+
<button type="button" class="file-remove" aria-label=${`${t9.removeFile}: ${f4.name}`} @click=${() => this.detach(i12)}>
|
|
3968
|
+
${icon(ICON_CLOSE)}
|
|
3969
|
+
</button>
|
|
3970
|
+
</li>`
|
|
3971
|
+
)}
|
|
3972
|
+
</ul>` : ""}
|
|
3771
3973
|
<form part="composer" @submit=${(ev) => this.submit(ev, state)}>
|
|
3974
|
+
${canAttach ? import_lit_html19.html`<input
|
|
3975
|
+
class="file-input"
|
|
3976
|
+
type="file"
|
|
3977
|
+
multiple
|
|
3978
|
+
accept=${ACCEPT}
|
|
3979
|
+
hidden
|
|
3980
|
+
@change=${(ev) => {
|
|
3981
|
+
const input = ev.target;
|
|
3982
|
+
this.attach(input.files);
|
|
3983
|
+
input.value = "";
|
|
3984
|
+
}}
|
|
3985
|
+
/>
|
|
3986
|
+
<button
|
|
3987
|
+
class="icon attach"
|
|
3988
|
+
part="attach"
|
|
3989
|
+
type="button"
|
|
3990
|
+
title=${t9.attach}
|
|
3991
|
+
aria-label=${t9.attach}
|
|
3992
|
+
?disabled=${state.answering}
|
|
3993
|
+
@click=${() => this.shadowRoot?.querySelector(".file-input")?.click()}
|
|
3994
|
+
>
|
|
3995
|
+
${icon(ICON_ATTACH)}
|
|
3996
|
+
</button>` : ""}
|
|
3772
3997
|
<label class="sr-only" for="lf-input">${t9.placeholder}</label>
|
|
3773
3998
|
<textarea
|
|
3774
3999
|
id="lf-input"
|
|
@@ -3777,6 +4002,7 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
|
|
|
3777
4002
|
placeholder=${t9.placeholder}
|
|
3778
4003
|
@keydown=${(ev) => this.onInputKey(ev, state)}
|
|
3779
4004
|
@input=${(ev) => this.autosize(ev.target)}
|
|
4005
|
+
@paste=${(ev) => this.onPaste(ev, canAttach && !state.answering)}
|
|
3780
4006
|
></textarea>
|
|
3781
4007
|
<button class="send" part="send" type="submit" aria-label=${state.answering ? t9.stop : t9.send}>
|
|
3782
4008
|
${state.answering ? t9.stop : t9.send}
|
|
@@ -3785,14 +4011,67 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
|
|
|
3785
4011
|
</section>
|
|
3786
4012
|
`;
|
|
3787
4013
|
}
|
|
3788
|
-
|
|
4014
|
+
/**
|
|
4015
|
+
* Rate an answer: the same thumb again clears it. Only stored answers of
|
|
4016
|
+
* an agent that takes ratings (plan 51 §15 #7).
|
|
4017
|
+
*/
|
|
4018
|
+
rateAnswer(m4, rating, comment) {
|
|
4019
|
+
return ([state]) => {
|
|
4020
|
+
if (!state.agentId || !state.conversationId) return;
|
|
4021
|
+
const next = comment === void 0 && m4.feedback === rating ? null : rating;
|
|
4022
|
+
this.dispatch(
|
|
4023
|
+
rate({
|
|
4024
|
+
agentId: state.agentId,
|
|
4025
|
+
conversationId: state.conversationId,
|
|
4026
|
+
messageId: m4.id,
|
|
4027
|
+
rating: next,
|
|
4028
|
+
...comment !== void 0 ? { comment } : {},
|
|
4029
|
+
previous: m4.feedback
|
|
4030
|
+
})
|
|
4031
|
+
);
|
|
4032
|
+
};
|
|
4033
|
+
}
|
|
4034
|
+
sendComment(ev, m4, state) {
|
|
4035
|
+
ev.preventDefault();
|
|
4036
|
+
const input = ev.target.querySelector("input");
|
|
4037
|
+
const text = input?.value.trim() ?? "";
|
|
4038
|
+
if (!text) {
|
|
4039
|
+
this.dispatch(closeComment());
|
|
4040
|
+
return;
|
|
4041
|
+
}
|
|
4042
|
+
this.rateAnswer(m4, "down", text)([state]);
|
|
4043
|
+
}
|
|
4044
|
+
feedback(m4, state) {
|
|
4045
|
+
const agent = state.agents.find((a5) => a5.id === state.agentId);
|
|
4046
|
+
if (agent?.allowFeedback === false || m4.id.startsWith("local:") || !state.conversationId) return "";
|
|
4047
|
+
const t9 = this.t;
|
|
4048
|
+
return import_lit_html19.html`
|
|
4049
|
+
<div class="rate" part="rate">
|
|
4050
|
+
<button type="button" class="thumb ${m4.feedback === "up" ? "on" : ""}" part="thumb-up"
|
|
4051
|
+
title=${t9.helpful} aria-label=${t9.helpful} aria-pressed=${m4.feedback === "up" ? "true" : "false"}
|
|
4052
|
+
@click=${() => this.rateAnswer(m4, "up")([state])}>${icon(ICON_UP)}</button>
|
|
4053
|
+
<button type="button" class="thumb ${m4.feedback === "down" ? "on" : ""}" part="thumb-down"
|
|
4054
|
+
title=${t9.notHelpful} aria-label=${t9.notHelpful} aria-pressed=${m4.feedback === "down" ? "true" : "false"}
|
|
4055
|
+
@click=${() => this.rateAnswer(m4, "down")([state])}>${icon(ICON_DOWN)}</button>
|
|
4056
|
+
${m4.feedback && state.commentFor !== m4.id ? import_lit_html19.html`<span class="thanks" aria-live="polite">${t9.thanks}</span>` : ""}
|
|
4057
|
+
</div>
|
|
4058
|
+
${state.commentFor === m4.id ? import_lit_html19.html`<form class="comment" part="feedback-comment" @submit=${(ev) => this.sendComment(ev, m4, state)}>
|
|
4059
|
+
<input type="text" maxlength="1000" placeholder=${t9.whatWentWrong} aria-label=${t9.whatWentWrong}
|
|
4060
|
+
@keydown=${(ev) => ev.key === "Escape" && this.dispatch(closeComment())} />
|
|
4061
|
+
<button type="submit">${t9.sendFeedback}</button>
|
|
4062
|
+
<button type="button" class="skip" @click=${() => this.dispatch(closeComment())}>${t9.skipFeedback}</button>
|
|
4063
|
+
</form>` : ""}
|
|
4064
|
+
`;
|
|
4065
|
+
}
|
|
4066
|
+
bubble(m4, state) {
|
|
3789
4067
|
if (m4.role === "user") {
|
|
3790
|
-
return import_lit_html19.html`<div class="msg user" part="message user">${m4.text}</div>`;
|
|
4068
|
+
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>`;
|
|
3791
4069
|
}
|
|
3792
4070
|
return import_lit_html19.html`<div class="msg assistant" part="message assistant">
|
|
3793
4071
|
${renderMarkdown(m4.text)}
|
|
3794
4072
|
${m4.tools.length ? import_lit_html19.html`<div class="tools">${this.t.usedTools}: ${m4.tools.join(", ")}</div>` : ""}
|
|
3795
|
-
</div
|
|
4073
|
+
</div>
|
|
4074
|
+
${this.feedback(m4, state)}`;
|
|
3796
4075
|
}
|
|
3797
4076
|
intro(state) {
|
|
3798
4077
|
const agent = state.agents.find((a5) => a5.id === state.agentId);
|