@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/README.md +9 -0
- package/dist/agent-chat.js +94 -35
- package/dist/agent-chat.js.map +4 -4
- package/dist/index.cjs +212 -24
- package/dist/index.cjs.map +4 -4
- package/dist/index.mjs +209 -21
- package/dist/index.mjs.map +4 -4
- package/package.json +3 -3
- package/types/index.d.ts +11 -0
package/dist/index.cjs
CHANGED
|
@@ -2436,6 +2436,7 @@ __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,
|
|
@@ -2448,6 +2449,7 @@ __export(index_exports, {
|
|
|
2448
2449
|
newConversation: () => newConversation,
|
|
2449
2450
|
pickAgent: () => pickAgent,
|
|
2450
2451
|
pickAgents: () => pickAgents,
|
|
2452
|
+
removeFile: () => removeFile,
|
|
2451
2453
|
renderMarkdown: () => renderMarkdown,
|
|
2452
2454
|
resume: () => resume,
|
|
2453
2455
|
runEnded: () => runEnded,
|
|
@@ -2462,7 +2464,7 @@ __export(index_exports, {
|
|
|
2462
2464
|
module.exports = __toCommonJS(index_exports);
|
|
2463
2465
|
|
|
2464
2466
|
// src/element.ts
|
|
2465
|
-
var
|
|
2467
|
+
var import_agents2 = require("@lambforge/agents");
|
|
2466
2468
|
var import_component = __toESM(require_dist3());
|
|
2467
2469
|
var import_lit_html19 = __toESM(require_dist());
|
|
2468
2470
|
var import_rxjs8 = require("rxjs");
|
|
@@ -2660,7 +2662,12 @@ var historyLoaded = action(
|
|
|
2660
2662
|
payload()
|
|
2661
2663
|
);
|
|
2662
2664
|
var newConversation = action("[chat] new conversation");
|
|
2663
|
-
var sendMessage = action(
|
|
2665
|
+
var sendMessage = action(
|
|
2666
|
+
"[chat] send",
|
|
2667
|
+
payload()
|
|
2668
|
+
);
|
|
2669
|
+
var addFiles = action("[chat] add files", payload());
|
|
2670
|
+
var removeFile = action("[chat] remove file", payload());
|
|
2664
2671
|
var resume = action(
|
|
2665
2672
|
"[chat] resume",
|
|
2666
2673
|
payload()
|
|
@@ -2965,9 +2972,14 @@ var ChatEffects = class {
|
|
|
2965
2972
|
action$.pipe(
|
|
2966
2973
|
ofType(sendMessage),
|
|
2967
2974
|
(0, import_operators7.map)(({ payload: payload2 }) => {
|
|
2968
|
-
const { agentId, conversationId, text } = payload2;
|
|
2975
|
+
const { agentId, conversationId, text, files } = payload2;
|
|
2969
2976
|
const c9 = this.conversation(agentId, conversationId);
|
|
2970
|
-
|
|
2977
|
+
const attachments = (files ?? []).map((file) => ({
|
|
2978
|
+
name: file.name,
|
|
2979
|
+
mimeType: file.type || void 0,
|
|
2980
|
+
data: file
|
|
2981
|
+
}));
|
|
2982
|
+
return { c: c9, events: attachments.length ? c9.send(text, { attachments }) : c9.send(text) };
|
|
2971
2983
|
})
|
|
2972
2984
|
),
|
|
2973
2985
|
action$.pipe(
|
|
@@ -3030,6 +3042,9 @@ var ChatEffects = class {
|
|
|
3030
3042
|
}
|
|
3031
3043
|
};
|
|
3032
3044
|
|
|
3045
|
+
// src/store/chat-reducer.ts
|
|
3046
|
+
var import_agents = require("@lambforge/agents");
|
|
3047
|
+
|
|
3033
3048
|
// src/store/chat-state.ts
|
|
3034
3049
|
var initialChatState = {
|
|
3035
3050
|
shown: false,
|
|
@@ -3038,16 +3053,31 @@ var initialChatState = {
|
|
|
3038
3053
|
conversationId: null,
|
|
3039
3054
|
messages: [],
|
|
3040
3055
|
answering: false,
|
|
3041
|
-
|
|
3056
|
+
live: null,
|
|
3057
|
+
notice: null,
|
|
3058
|
+
files: []
|
|
3042
3059
|
};
|
|
3043
3060
|
function toMessage(m4) {
|
|
3044
3061
|
const tools = (m4.toolCalls ?? []).map((c9) => c9?.name).filter((n11) => !!n11);
|
|
3045
|
-
return {
|
|
3062
|
+
return {
|
|
3063
|
+
id: m4.id,
|
|
3064
|
+
role: m4.role,
|
|
3065
|
+
text: m4.text ?? "",
|
|
3066
|
+
tools: Array.from(new Set(tools)),
|
|
3067
|
+
attachments: (m4.attachments ?? []).map((a5) => a5.name)
|
|
3068
|
+
};
|
|
3046
3069
|
}
|
|
3047
3070
|
|
|
3048
3071
|
// src/store/chat-reducer.ts
|
|
3049
3072
|
var LOCAL_ID = /^local:/;
|
|
3050
|
-
var empty = {
|
|
3073
|
+
var empty = {
|
|
3074
|
+
conversationId: null,
|
|
3075
|
+
messages: [],
|
|
3076
|
+
answering: false,
|
|
3077
|
+
live: null,
|
|
3078
|
+
notice: null,
|
|
3079
|
+
files: []
|
|
3080
|
+
};
|
|
3051
3081
|
var chatReducer = reducer(
|
|
3052
3082
|
initialChatState,
|
|
3053
3083
|
on(shown, (s9, { payload: payload2 }) => s9.shown || !payload2 ? s9 : { ...s9, shown: true }),
|
|
@@ -3055,6 +3085,7 @@ var chatReducer = reducer(
|
|
|
3055
3085
|
on(failed, (s9, { payload: payload2 }) => ({
|
|
3056
3086
|
...s9,
|
|
3057
3087
|
answering: false,
|
|
3088
|
+
live: null,
|
|
3058
3089
|
notice: { kind: "error", code: payload2 }
|
|
3059
3090
|
})),
|
|
3060
3091
|
on(verifying, (s9, { payload: payload2 }) => ({
|
|
@@ -3075,6 +3106,7 @@ var chatReducer = reducer(
|
|
|
3075
3106
|
conversationId: payload2.detail.id,
|
|
3076
3107
|
messages: (payload2.detail.messages ?? []).map(toMessage),
|
|
3077
3108
|
answering: !!payload2.detail.answering,
|
|
3109
|
+
live: null,
|
|
3078
3110
|
notice: payload2.detail.answering ? { kind: "busy", what: "thinking" } : null
|
|
3079
3111
|
}
|
|
3080
3112
|
),
|
|
@@ -3084,25 +3116,52 @@ var chatReducer = reducer(
|
|
|
3084
3116
|
// shown at once; replaced by the stored copy when it arrives
|
|
3085
3117
|
messages: [
|
|
3086
3118
|
...s9.messages,
|
|
3087
|
-
{
|
|
3119
|
+
{
|
|
3120
|
+
id: `local:${s9.messages.length}`,
|
|
3121
|
+
role: "user",
|
|
3122
|
+
text: payload2.text,
|
|
3123
|
+
tools: [],
|
|
3124
|
+
attachments: (payload2.files ?? []).map((f4) => f4.name)
|
|
3125
|
+
}
|
|
3088
3126
|
],
|
|
3127
|
+
files: [],
|
|
3089
3128
|
answering: true,
|
|
3090
3129
|
notice: { kind: "busy", what: "thinking" }
|
|
3091
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 = (0, import_agents.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
|
+
})),
|
|
3092
3144
|
on(agentEvent, (s9, { payload: payload2 }) => withEvent(s9, payload2)),
|
|
3093
3145
|
on(runEnded, (s9) => ({
|
|
3094
3146
|
...s9,
|
|
3095
3147
|
answering: false,
|
|
3148
|
+
live: null,
|
|
3096
3149
|
notice: s9.notice?.kind === "busy" ? null : s9.notice
|
|
3097
3150
|
})),
|
|
3098
|
-
on(stop, (s9) => ({ ...s9, answering: false, notice: { kind: "info", what: "stopped" } }))
|
|
3151
|
+
on(stop, (s9) => ({ ...s9, answering: false, live: null, notice: { kind: "info", what: "stopped" } }))
|
|
3099
3152
|
);
|
|
3100
3153
|
function withEvent(s9, event) {
|
|
3101
3154
|
const conversationId = s9.conversationId ?? event.conversationId;
|
|
3102
3155
|
if (event.conversationId !== conversationId) return s9;
|
|
3103
3156
|
if (event.type === "error") {
|
|
3104
|
-
return {
|
|
3157
|
+
return {
|
|
3158
|
+
...s9,
|
|
3159
|
+
conversationId,
|
|
3160
|
+
live: null,
|
|
3161
|
+
notice: { kind: "error", code: event.data?.code ?? "internal" }
|
|
3162
|
+
};
|
|
3105
3163
|
}
|
|
3164
|
+
if (event.type === "delta") return withDelta({ ...s9, conversationId }, event);
|
|
3106
3165
|
if (event.type !== "message" || !event.data?.id) return { ...s9, conversationId };
|
|
3107
3166
|
const message = toMessage(event.data);
|
|
3108
3167
|
if (s9.messages.some((m4) => m4.id === message.id)) return { ...s9, conversationId };
|
|
@@ -3110,7 +3169,17 @@ function withEvent(s9, event) {
|
|
|
3110
3169
|
const local = message.role === "user" ? messages.findIndex((m4) => LOCAL_ID.test(m4.id) && m4.text === message.text) : -1;
|
|
3111
3170
|
if (local >= 0) messages[local] = message;
|
|
3112
3171
|
else messages.push(message);
|
|
3113
|
-
|
|
3172
|
+
const live = message.role === "assistant" ? null : s9.live;
|
|
3173
|
+
return { ...s9, conversationId, messages, live };
|
|
3174
|
+
}
|
|
3175
|
+
function withDelta(s9, event) {
|
|
3176
|
+
if (!s9.answering || !event.runId) return s9;
|
|
3177
|
+
const segment = Number(event.data?.segment) || 0;
|
|
3178
|
+
const text = typeof event.data?.text === "string" ? event.data.text : "";
|
|
3179
|
+
const current = s9.live?.runId === event.runId ? s9.live : null;
|
|
3180
|
+
if (current && segment < current.segment) return s9;
|
|
3181
|
+
if (current && segment === current.segment && text.length < current.text.length) return s9;
|
|
3182
|
+
return { ...s9, live: { runId: event.runId, segment, text } };
|
|
3114
3183
|
}
|
|
3115
3184
|
|
|
3116
3185
|
// src/store/chat-store.ts
|
|
@@ -3160,6 +3229,10 @@ var en = {
|
|
|
3160
3229
|
pickAgent: "Assistant",
|
|
3161
3230
|
usedTools: "Used",
|
|
3162
3231
|
verifying: "Checking that you are human",
|
|
3232
|
+
attach: "Attach files",
|
|
3233
|
+
attached: "Attached files",
|
|
3234
|
+
removeFile: "Remove",
|
|
3235
|
+
filesOnly: "Please look at the attached files.",
|
|
3163
3236
|
errors: {
|
|
3164
3237
|
"limit-reached": "This conversation is full - start a new one.",
|
|
3165
3238
|
"cap-reached": "The assistant is not available right now - try again later.",
|
|
@@ -3171,6 +3244,13 @@ var en = {
|
|
|
3171
3244
|
unauthorized: "This chat is not allowed here.",
|
|
3172
3245
|
"bad-request": "That did not work - try again.",
|
|
3173
3246
|
network: "No connection - try again.",
|
|
3247
|
+
"attachments-off": "This assistant does not take files.",
|
|
3248
|
+
"attachments-unsupported": "This assistant cannot read that kind of file.",
|
|
3249
|
+
"attachment-invalid": "Only images, PDF and text files can be attached.",
|
|
3250
|
+
"attachment-too-large": "That file is too large (images 5 MB, PDF 10 MB, text 1 MB).",
|
|
3251
|
+
"attachment-limit": "At most 5 files and 15 MB in one message.",
|
|
3252
|
+
"attachment-missing": "A file was lost - attach it again.",
|
|
3253
|
+
"attachment-not-uploaded": "A file did not finish uploading - attach it again.",
|
|
3174
3254
|
default: "Something went wrong - try again."
|
|
3175
3255
|
}
|
|
3176
3256
|
};
|
|
@@ -3187,6 +3267,10 @@ var bg = {
|
|
|
3187
3267
|
pickAgent: "\u0410\u0441\u0438\u0441\u0442\u0435\u043D\u0442",
|
|
3188
3268
|
usedTools: "\u0418\u0437\u043F\u043E\u043B\u0437\u0432\u0430\u043D\u043E",
|
|
3189
3269
|
verifying: "\u041F\u0440\u043E\u0432\u0435\u0440\u043A\u0430, \u0447\u0435 \u0441\u0442\u0435 \u0447\u043E\u0432\u0435\u043A",
|
|
3270
|
+
attach: "\u041F\u0440\u0438\u043A\u0430\u0447\u0438 \u0444\u0430\u0439\u043B\u043E\u0432\u0435",
|
|
3271
|
+
attached: "\u041F\u0440\u0438\u043A\u0430\u0447\u0435\u043D\u0438 \u0444\u0430\u0439\u043B\u043E\u0432\u0435",
|
|
3272
|
+
removeFile: "\u041F\u0440\u0435\u043C\u0430\u0445\u043D\u0438",
|
|
3273
|
+
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.",
|
|
3190
3274
|
errors: {
|
|
3191
3275
|
"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.",
|
|
3192
3276
|
"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.",
|
|
@@ -3198,6 +3282,13 @@ var bg = {
|
|
|
3198
3282
|
unauthorized: "\u0422\u043E\u0437\u0438 \u0447\u0430\u0442 \u043D\u0435 \u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043D \u0442\u0443\u043A.",
|
|
3199
3283
|
"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.",
|
|
3200
3284
|
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.",
|
|
3285
|
+
"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.",
|
|
3286
|
+
"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.",
|
|
3287
|
+
"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.",
|
|
3288
|
+
"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).",
|
|
3289
|
+
"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.",
|
|
3290
|
+
"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.",
|
|
3291
|
+
"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.",
|
|
3201
3292
|
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."
|
|
3202
3293
|
}
|
|
3203
3294
|
};
|
|
@@ -3339,6 +3430,9 @@ header select {
|
|
|
3339
3430
|
.msg pre { margin: 6px 0; padding: 8px; overflow-x: auto; border-radius: 8px; background: rgba(0,0,0,0.06); font-size: 13px; }
|
|
3340
3431
|
.msg code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }
|
|
3341
3432
|
.msg a { color: inherit; }
|
|
3433
|
+
.msg.live > :last-child::after { content: '\\258D'; margin-left: 1px; opacity: 0.6; animation: lf-caret 1s steps(1) infinite; }
|
|
3434
|
+
@keyframes lf-caret { 50% { opacity: 0; } }
|
|
3435
|
+
@media (prefers-reduced-motion: reduce) { .msg.live > :last-child::after { animation: none; } }
|
|
3342
3436
|
.tools { font-size: 12px; color: var(--_muted); margin-top: 4px; }
|
|
3343
3437
|
|
|
3344
3438
|
.welcome { color: var(--_muted); }
|
|
@@ -3383,6 +3477,26 @@ textarea:focus-visible { outline: 2px solid var(--_accent); outline-offset: 0; b
|
|
|
3383
3477
|
padding: 0 14px; height: 40px; font-weight: 600;
|
|
3384
3478
|
}
|
|
3385
3479
|
.send:disabled { opacity: 0.5; cursor: default; }
|
|
3480
|
+
.attach { flex: none; height: 40px; }
|
|
3481
|
+
.attach:disabled { opacity: 0.5; cursor: default; }
|
|
3482
|
+
.files {
|
|
3483
|
+
list-style: none; margin: 0; padding: 8px 12px 0; display: flex; flex-wrap: wrap; gap: 6px;
|
|
3484
|
+
border-top: 1px solid var(--_border);
|
|
3485
|
+
}
|
|
3486
|
+
.file {
|
|
3487
|
+
display: inline-flex; align-items: center; gap: 2px; max-width: 100%;
|
|
3488
|
+
border: 1px solid var(--_border); border-radius: 999px; padding: 2px 2px 2px 10px; font-size: 13px;
|
|
3489
|
+
}
|
|
3490
|
+
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
|
|
3491
|
+
.file-remove {
|
|
3492
|
+
border: 0; background: transparent; color: var(--_muted); width: 22px; height: 22px;
|
|
3493
|
+
border-radius: 999px; display: grid; place-items: center; padding: 0;
|
|
3494
|
+
}
|
|
3495
|
+
.file-remove:hover, .file-remove:focus-visible { background: var(--_bot-bg); color: var(--_fg); }
|
|
3496
|
+
.file-remove svg { width: 14px; height: 14px; }
|
|
3497
|
+
.files + form { border-top: 0; }
|
|
3498
|
+
.msg-files { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
|
|
3499
|
+
.msg-file { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: rgba(255,255,255,0.2); }
|
|
3386
3500
|
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
3387
3501
|
`;
|
|
3388
3502
|
|
|
@@ -3471,6 +3585,8 @@ var TAG = "lambforge-agent-chat";
|
|
|
3471
3585
|
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"/>`;
|
|
3472
3586
|
var ICON_CLOSE = import_lit_html19.svg`<path d="M18 6 6 18M6 6l12 12"/>`;
|
|
3473
3587
|
var ICON_NEW = import_lit_html19.svg`<path d="M12 5v14M5 12h14"/>`;
|
|
3588
|
+
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"/>`;
|
|
3589
|
+
var ACCEPT = [...import_agents2.ACCEPTED_ATTACHMENT_TYPES, ".md", ".csv", ".yaml", ".yml", ".json", ".txt"].join(",");
|
|
3474
3590
|
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>`;
|
|
3475
3591
|
var LambforgeAgentChat = class extends import_lit_html19.LitElement {
|
|
3476
3592
|
constructor() {
|
|
@@ -3489,7 +3605,8 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
|
|
|
3489
3605
|
this.turnstileSitekey = "";
|
|
3490
3606
|
this.turnstileUrl = "";
|
|
3491
3607
|
this.strings = {};
|
|
3492
|
-
|
|
3608
|
+
/** messages + live text length: scroll when either grows */
|
|
3609
|
+
this.lastSize = "";
|
|
3493
3610
|
}
|
|
3494
3611
|
get shown() {
|
|
3495
3612
|
return this.mode !== "drawer" || this.open;
|
|
@@ -3532,10 +3649,10 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
|
|
|
3532
3649
|
const url = this.url || void 0;
|
|
3533
3650
|
if (this.getToken) {
|
|
3534
3651
|
const source = this.getToken;
|
|
3535
|
-
this.client = new
|
|
3652
|
+
this.client = new import_agents2.AgentClient({ url, getToken: () => source() });
|
|
3536
3653
|
} else if (this.tokenUrl) {
|
|
3537
3654
|
const tokenUrl = this.tokenUrl;
|
|
3538
|
-
this.client = new
|
|
3655
|
+
this.client = new import_agents2.AgentClient({
|
|
3539
3656
|
url,
|
|
3540
3657
|
getToken: () => fetch(tokenUrl, {
|
|
3541
3658
|
credentials: "include",
|
|
@@ -3546,7 +3663,7 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
|
|
|
3546
3663
|
})
|
|
3547
3664
|
});
|
|
3548
3665
|
} else if (this.publishableKey) {
|
|
3549
|
-
this.client = new
|
|
3666
|
+
this.client = new import_agents2.AgentClient({
|
|
3550
3667
|
url,
|
|
3551
3668
|
anonymous: {
|
|
3552
3669
|
publishableKey: this.publishableKey,
|
|
@@ -3579,16 +3696,36 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
|
|
|
3579
3696
|
throw new Error("turnstile: the chat is not rendered");
|
|
3580
3697
|
}
|
|
3581
3698
|
// ------------------------------------------------------------ actions
|
|
3582
|
-
/** Send a message to the selected agent. */
|
|
3699
|
+
/** Send a message (with the picked files) to the selected agent. */
|
|
3583
3700
|
send(text) {
|
|
3584
3701
|
return ([state]) => {
|
|
3585
|
-
const
|
|
3702
|
+
const files = state.files;
|
|
3703
|
+
const clean = String(text ?? "").trim() || (files.length ? this.t.filesOnly : "");
|
|
3586
3704
|
if (!clean || state.answering || !state.agentId) return;
|
|
3587
3705
|
this.dispatch(
|
|
3588
|
-
sendMessage({
|
|
3706
|
+
sendMessage({
|
|
3707
|
+
agentId: state.agentId,
|
|
3708
|
+
conversationId: state.conversationId,
|
|
3709
|
+
text: clean,
|
|
3710
|
+
...files.length ? { files } : {}
|
|
3711
|
+
})
|
|
3589
3712
|
);
|
|
3590
3713
|
};
|
|
3591
3714
|
}
|
|
3715
|
+
/** Files for the next message (the reducer refuses what the API would). */
|
|
3716
|
+
attach(files) {
|
|
3717
|
+
const list = Array.from(files ?? []);
|
|
3718
|
+
if (list.length) this.dispatch(addFiles(list));
|
|
3719
|
+
}
|
|
3720
|
+
detach(index) {
|
|
3721
|
+
this.dispatch(removeFile(index));
|
|
3722
|
+
}
|
|
3723
|
+
onPaste(ev, allowed) {
|
|
3724
|
+
const files = Array.from(ev.clipboardData?.files ?? []);
|
|
3725
|
+
if (!allowed || !files.length) return;
|
|
3726
|
+
ev.preventDefault();
|
|
3727
|
+
this.attach(files);
|
|
3728
|
+
}
|
|
3592
3729
|
/** Stop the answer in progress. */
|
|
3593
3730
|
stopAnswer() {
|
|
3594
3731
|
return ([state]) => {
|
|
@@ -3676,10 +3813,15 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
|
|
|
3676
3813
|
const drawer = this.mode === "drawer";
|
|
3677
3814
|
const agent = state.agents.find((a5) => a5.id === state.agentId) ?? null;
|
|
3678
3815
|
const title = this.heading || agent?.name || t9.title;
|
|
3679
|
-
const
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3816
|
+
const canAttach = !!agent?.allowAttachments;
|
|
3817
|
+
const live = state.live?.text ? state.live : null;
|
|
3818
|
+
const notice = live && state.notice?.kind === "busy" ? null : state.notice;
|
|
3819
|
+
const size = `${state.messages.length}:${live?.text.length ?? 0}`;
|
|
3820
|
+
if (size !== this.lastSize) {
|
|
3821
|
+
const newMessage = size.split(":")[0] !== this.lastSize.split(":")[0];
|
|
3822
|
+
this.lastSize = size;
|
|
3823
|
+
const follow = newMessage || this.atBottom();
|
|
3824
|
+
if (follow) this.updateComplete.then(() => requestAnimationFrame(() => this.scrollDown()));
|
|
3683
3825
|
}
|
|
3684
3826
|
return import_lit_html19.html`
|
|
3685
3827
|
<button
|
|
@@ -3723,8 +3865,16 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
|
|
|
3723
3865
|
${icon(ICON_CLOSE)}
|
|
3724
3866
|
</button>
|
|
3725
3867
|
</header>
|
|
3726
|
-
<div
|
|
3868
|
+
<div
|
|
3869
|
+
class="messages"
|
|
3870
|
+
part="messages"
|
|
3871
|
+
role="log"
|
|
3872
|
+
aria-live="polite"
|
|
3873
|
+
aria-relevant="additions"
|
|
3874
|
+
aria-busy=${String(!!live)}
|
|
3875
|
+
>
|
|
3727
3876
|
${state.messages.length ? state.messages.map((m4) => this.bubble(m4)) : this.intro(state)}
|
|
3877
|
+
${live ? import_lit_html19.html`<div class="msg assistant live" part="message assistant live">${renderMarkdown(live.text)}</div>` : ""}
|
|
3728
3878
|
</div>
|
|
3729
3879
|
<div class="turnstile" ?hidden=${notice?.kind !== "busy" || notice.what !== "verifying"}></div>
|
|
3730
3880
|
<div
|
|
@@ -3732,7 +3882,40 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
|
|
|
3732
3882
|
part="status"
|
|
3733
3883
|
role="status"
|
|
3734
3884
|
>${this.noticeText(notice)}</div>
|
|
3885
|
+
${canAttach && state.files.length ? import_lit_html19.html`<ul class="files" part="files" aria-label=${t9.attached}>
|
|
3886
|
+
${state.files.map(
|
|
3887
|
+
(f4, i12) => import_lit_html19.html`<li class="file" part="file">
|
|
3888
|
+
<span class="file-name" title=${f4.name}>${f4.name}</span>
|
|
3889
|
+
<button type="button" class="file-remove" aria-label=${`${t9.removeFile}: ${f4.name}`} @click=${() => this.detach(i12)}>
|
|
3890
|
+
${icon(ICON_CLOSE)}
|
|
3891
|
+
</button>
|
|
3892
|
+
</li>`
|
|
3893
|
+
)}
|
|
3894
|
+
</ul>` : ""}
|
|
3735
3895
|
<form part="composer" @submit=${(ev) => this.submit(ev, state)}>
|
|
3896
|
+
${canAttach ? import_lit_html19.html`<input
|
|
3897
|
+
class="file-input"
|
|
3898
|
+
type="file"
|
|
3899
|
+
multiple
|
|
3900
|
+
accept=${ACCEPT}
|
|
3901
|
+
hidden
|
|
3902
|
+
@change=${(ev) => {
|
|
3903
|
+
const input = ev.target;
|
|
3904
|
+
this.attach(input.files);
|
|
3905
|
+
input.value = "";
|
|
3906
|
+
}}
|
|
3907
|
+
/>
|
|
3908
|
+
<button
|
|
3909
|
+
class="icon attach"
|
|
3910
|
+
part="attach"
|
|
3911
|
+
type="button"
|
|
3912
|
+
title=${t9.attach}
|
|
3913
|
+
aria-label=${t9.attach}
|
|
3914
|
+
?disabled=${state.answering}
|
|
3915
|
+
@click=${() => this.shadowRoot?.querySelector(".file-input")?.click()}
|
|
3916
|
+
>
|
|
3917
|
+
${icon(ICON_ATTACH)}
|
|
3918
|
+
</button>` : ""}
|
|
3736
3919
|
<label class="sr-only" for="lf-input">${t9.placeholder}</label>
|
|
3737
3920
|
<textarea
|
|
3738
3921
|
id="lf-input"
|
|
@@ -3741,6 +3924,7 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
|
|
|
3741
3924
|
placeholder=${t9.placeholder}
|
|
3742
3925
|
@keydown=${(ev) => this.onInputKey(ev, state)}
|
|
3743
3926
|
@input=${(ev) => this.autosize(ev.target)}
|
|
3927
|
+
@paste=${(ev) => this.onPaste(ev, canAttach && !state.answering)}
|
|
3744
3928
|
></textarea>
|
|
3745
3929
|
<button class="send" part="send" type="submit" aria-label=${state.answering ? t9.stop : t9.send}>
|
|
3746
3930
|
${state.answering ? t9.stop : t9.send}
|
|
@@ -3751,7 +3935,7 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
|
|
|
3751
3935
|
}
|
|
3752
3936
|
bubble(m4) {
|
|
3753
3937
|
if (m4.role === "user") {
|
|
3754
|
-
return import_lit_html19.html`<div class="msg user" part="message user">${m4.text}</div>`;
|
|
3938
|
+
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>`;
|
|
3755
3939
|
}
|
|
3756
3940
|
return import_lit_html19.html`<div class="msg assistant" part="message assistant">
|
|
3757
3941
|
${renderMarkdown(m4.text)}
|
|
@@ -3770,6 +3954,10 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
|
|
|
3770
3954
|
</div>` : ""}
|
|
3771
3955
|
`;
|
|
3772
3956
|
}
|
|
3957
|
+
atBottom() {
|
|
3958
|
+
const m4 = this.shadowRoot?.querySelector(".messages");
|
|
3959
|
+
return !m4 || m4.scrollHeight - m4.scrollTop - m4.clientHeight < 80;
|
|
3960
|
+
}
|
|
3773
3961
|
scrollDown() {
|
|
3774
3962
|
const m4 = this.shadowRoot?.querySelector(".messages");
|
|
3775
3963
|
if (m4) m4.scrollTop = m4.scrollHeight;
|