@lambforge/agent-chat 0.0.7 → 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 +6 -0
- package/dist/agent-chat.js +75 -38
- package/dist/agent-chat.js.map +3 -3
- package/dist/index.cjs +138 -7
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +138 -7
- package/dist/index.mjs.map +2 -2
- package/package.json +3 -3
- package/types/index.d.ts +8 -0
package/dist/index.mjs
CHANGED
|
@@ -2639,6 +2639,12 @@ var resume = action(
|
|
|
2639
2639
|
var agentEvent = action("[chat] event", payload());
|
|
2640
2640
|
var runEnded = action("[chat] run ended");
|
|
2641
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");
|
|
2642
2648
|
|
|
2643
2649
|
// ../../node_modules/@rxdi/redux-store/dist/esm/interfaces.js
|
|
2644
2650
|
var FlattenOperator;
|
|
@@ -2989,6 +2995,20 @@ var ChatEffects = class {
|
|
|
2989
2995
|
})
|
|
2990
2996
|
)
|
|
2991
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
|
+
);
|
|
2992
3012
|
/** Failures also reach the page as an `error` event. */
|
|
2993
3013
|
this.failures$ = createEffect()(
|
|
2994
3014
|
(action$) => action$.pipe(
|
|
@@ -3031,7 +3051,8 @@ var initialChatState = {
|
|
|
3031
3051
|
answering: false,
|
|
3032
3052
|
live: null,
|
|
3033
3053
|
notice: null,
|
|
3034
|
-
files: []
|
|
3054
|
+
files: [],
|
|
3055
|
+
commentFor: null
|
|
3035
3056
|
};
|
|
3036
3057
|
function toMessage(m4) {
|
|
3037
3058
|
const tools = (m4.toolCalls ?? []).map((c9) => c9?.name).filter((n11) => !!n11);
|
|
@@ -3040,7 +3061,8 @@ function toMessage(m4) {
|
|
|
3040
3061
|
role: m4.role,
|
|
3041
3062
|
text: m4.text ?? "",
|
|
3042
3063
|
tools: Array.from(new Set(tools)),
|
|
3043
|
-
attachments: (m4.attachments ?? []).map((a5) => a5.name)
|
|
3064
|
+
attachments: (m4.attachments ?? []).map((a5) => a5.name),
|
|
3065
|
+
feedback: m4.feedback?.rating ?? null
|
|
3044
3066
|
};
|
|
3045
3067
|
}
|
|
3046
3068
|
|
|
@@ -3052,7 +3074,8 @@ var empty = {
|
|
|
3052
3074
|
answering: false,
|
|
3053
3075
|
live: null,
|
|
3054
3076
|
notice: null,
|
|
3055
|
-
files: []
|
|
3077
|
+
files: [],
|
|
3078
|
+
commentFor: null
|
|
3056
3079
|
};
|
|
3057
3080
|
var chatReducer = reducer(
|
|
3058
3081
|
initialChatState,
|
|
@@ -3097,7 +3120,8 @@ var chatReducer = reducer(
|
|
|
3097
3120
|
role: "user",
|
|
3098
3121
|
text: payload2.text,
|
|
3099
3122
|
tools: [],
|
|
3100
|
-
attachments: (payload2.files ?? []).map((f4) => f4.name)
|
|
3123
|
+
attachments: (payload2.files ?? []).map((f4) => f4.name),
|
|
3124
|
+
feedback: null
|
|
3101
3125
|
}
|
|
3102
3126
|
],
|
|
3103
3127
|
files: [],
|
|
@@ -3124,6 +3148,22 @@ var chatReducer = reducer(
|
|
|
3124
3148
|
live: null,
|
|
3125
3149
|
notice: s9.notice?.kind === "busy" ? null : s9.notice
|
|
3126
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 })),
|
|
3127
3167
|
on(stop, (s9) => ({ ...s9, answering: false, live: null, notice: { kind: "info", what: "stopped" } }))
|
|
3128
3168
|
);
|
|
3129
3169
|
function withEvent(s9, event) {
|
|
@@ -3175,6 +3215,7 @@ var ChatStore = class {
|
|
|
3175
3215
|
effects.select$,
|
|
3176
3216
|
effects.run$,
|
|
3177
3217
|
effects.abort$,
|
|
3218
|
+
effects.rate$,
|
|
3178
3219
|
effects.failures$,
|
|
3179
3220
|
effects.connect$
|
|
3180
3221
|
),
|
|
@@ -3209,6 +3250,12 @@ var en = {
|
|
|
3209
3250
|
attached: "Attached files",
|
|
3210
3251
|
removeFile: "Remove",
|
|
3211
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",
|
|
3212
3259
|
errors: {
|
|
3213
3260
|
"limit-reached": "This conversation is full - start a new one.",
|
|
3214
3261
|
"cap-reached": "The assistant is not available right now - try again later.",
|
|
@@ -3247,6 +3294,12 @@ var bg = {
|
|
|
3247
3294
|
attached: "\u041F\u0440\u0438\u043A\u0430\u0447\u0435\u043D\u0438 \u0444\u0430\u0439\u043B\u043E\u0432\u0435",
|
|
3248
3295
|
removeFile: "\u041F\u0440\u0435\u043C\u0430\u0445\u043D\u0438",
|
|
3249
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",
|
|
3250
3303
|
errors: {
|
|
3251
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.",
|
|
3252
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.",
|
|
@@ -3410,6 +3463,26 @@ header select {
|
|
|
3410
3463
|
@keyframes lf-caret { 50% { opacity: 0; } }
|
|
3411
3464
|
@media (prefers-reduced-motion: reduce) { .msg.live > :last-child::after { animation: none; } }
|
|
3412
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); }
|
|
3413
3486
|
|
|
3414
3487
|
.welcome { color: var(--_muted); }
|
|
3415
3488
|
.suggestions { display: flex; flex-wrap: wrap; gap: 6px; }
|
|
@@ -3561,6 +3634,8 @@ var TAG = "lambforge-agent-chat";
|
|
|
3561
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"/>`;
|
|
3562
3635
|
var ICON_CLOSE = import_lit_html19.svg`<path d="M18 6 6 18M6 6l12 12"/>`;
|
|
3563
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"/>`;
|
|
3564
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"/>`;
|
|
3565
3640
|
var ACCEPT = [...ACCEPTED_ATTACHMENT_TYPES, ".md", ".csv", ".yaml", ".yml", ".json", ".txt"].join(",");
|
|
3566
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>`;
|
|
@@ -3849,7 +3924,7 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
|
|
|
3849
3924
|
aria-relevant="additions"
|
|
3850
3925
|
aria-busy=${String(!!live)}
|
|
3851
3926
|
>
|
|
3852
|
-
${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)}
|
|
3853
3928
|
${live ? import_lit_html19.html`<div class="msg assistant live" part="message assistant live">${renderMarkdown(live.text)}</div>` : ""}
|
|
3854
3929
|
</div>
|
|
3855
3930
|
<div class="turnstile" ?hidden=${notice?.kind !== "busy" || notice.what !== "verifying"}></div>
|
|
@@ -3909,14 +3984,67 @@ var LambforgeAgentChat = class extends import_lit_html19.LitElement {
|
|
|
3909
3984
|
</section>
|
|
3910
3985
|
`;
|
|
3911
3986
|
}
|
|
3912
|
-
|
|
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) {
|
|
3913
4040
|
if (m4.role === "user") {
|
|
3914
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>`;
|
|
3915
4042
|
}
|
|
3916
4043
|
return import_lit_html19.html`<div class="msg assistant" part="message assistant">
|
|
3917
4044
|
${renderMarkdown(m4.text)}
|
|
3918
4045
|
${m4.tools.length ? import_lit_html19.html`<div class="tools">${this.t.usedTools}: ${m4.tools.join(", ")}</div>` : ""}
|
|
3919
|
-
</div
|
|
4046
|
+
</div>
|
|
4047
|
+
${this.feedback(m4, state)}`;
|
|
3920
4048
|
}
|
|
3921
4049
|
intro(state) {
|
|
3922
4050
|
const agent = state.agents.find((a5) => a5.id === state.agentId);
|
|
@@ -4011,6 +4139,7 @@ export {
|
|
|
4011
4139
|
agentEvent,
|
|
4012
4140
|
agentsLoaded,
|
|
4013
4141
|
chatReducer,
|
|
4142
|
+
closeComment,
|
|
4014
4143
|
connecting,
|
|
4015
4144
|
errorCode,
|
|
4016
4145
|
failed,
|
|
@@ -4020,6 +4149,8 @@ export {
|
|
|
4020
4149
|
newConversation,
|
|
4021
4150
|
pickAgent,
|
|
4022
4151
|
pickAgents,
|
|
4152
|
+
rate,
|
|
4153
|
+
rateFailed,
|
|
4023
4154
|
removeFile,
|
|
4024
4155
|
renderMarkdown,
|
|
4025
4156
|
resume,
|