Merge branch 'main' into feat/1883-1885-chat-dock
This commit is contained in:
commit
07e4e8f727
7 files changed
+133
-8
No files matched your search
@@ -230,7 +230,7 @@ func (a *LocalChatAdapter) runStreamedTurn(ctx context.Context, in Inbound, id s
|
||||
run := func(turnCtx context.Context) ChatEvent {
|
||||
reply, err := a.Router.streamTurn(turnCtx, in, stream)
|
||||
if err != nil {
|
||||
return ChatEvent{Kind: "error", Text: err.Error(), SessionID: id}
|
||||
return ChatEvent{Kind: "error", Text: turnFailureText(err), SessionID: id}
|
||||
}
|
||||
resolvedID := id
|
||||
if resolved, err := a.Router.ResolveSessionKey(turnCtx, in); err == nil {
|
||||
@@ -306,7 +306,7 @@ func (a *LocalChatAdapter) prelude(ctx context.Context, in Inbound, id string) s
|
||||
}
|
||||
ready, mine, err := a.Router.CollectTurn(ctx, in)
|
||||
if err != nil {
|
||||
return streamPrelude{event: &ChatEvent{Kind: "error", Text: err.Error(), SessionID: id}}
|
||||
return streamPrelude{event: &ChatEvent{Kind: "error", Text: turnFailureText(err), SessionID: id}}
|
||||
}
|
||||
return streamPrelude{ready: ready, proceeds: mine}
|
||||
}
|
||||
|
||||
@@ -580,7 +580,7 @@ func (r *TurnRunner) failTurn(ctx context.Context, turn TurnRecord, cause error)
|
||||
} else {
|
||||
turn.Status = TurnStatusFailed
|
||||
}
|
||||
turn.Error = cause.Error()
|
||||
turn.Error = turnFailureText(cause)
|
||||
turn.UpdatedAt = time.Now().UTC()
|
||||
if r.Log != nil {
|
||||
level := slog.LevelError
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/samcharles93/ai-sdk/chat"
|
||||
)
|
||||
|
||||
// turnFailureText is what a chat reader sees when a turn fails. The cause
|
||||
// carries provider bodies, URLs and wrapping that belong in the log, which
|
||||
// failTurn writes, not in front of whoever is chatting.
|
||||
func turnFailureText(err error) string {
|
||||
switch {
|
||||
case errors.Is(err, chat.ErrRateLimited):
|
||||
return "the model provider is refusing requests (rate limit or spending cap). Try again later, or switch model with /model."
|
||||
case errors.Is(err, chat.ErrAuthFailed):
|
||||
return "the model provider rejected Archie's credentials. Check the provider key in settings."
|
||||
case errors.Is(err, chat.ErrProviderUnavailable):
|
||||
return "the model provider is unavailable. Try again in a moment."
|
||||
case errors.Is(err, chat.ErrContextLength):
|
||||
return "this conversation is too long for the model. Start a new chat, or shorten it with /compress."
|
||||
case errors.Is(err, chat.ErrUnsupportedContent):
|
||||
return "the model can't read one of the attachments. Remove it, or switch model with /model."
|
||||
case errors.Is(err, context.DeadlineExceeded):
|
||||
return "the model took too long to answer. Try again."
|
||||
default:
|
||||
return "something went wrong on Archie's side. Try again; the gateway log has the cause."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/samcharles93/ai-sdk/chat"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/messaging"
|
||||
)
|
||||
|
||||
// A failed turn shows the reader what to do, never the provider's response
|
||||
// body or the error's wrapping.
|
||||
func TestStreamedTurnFailureHidesCause(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
cause error
|
||||
want string
|
||||
}{
|
||||
{name: "spending cap", cause: chat.ErrRateLimited, want: "rate limit or spending cap"},
|
||||
{name: "bad key", cause: chat.ErrAuthFailed, want: "credentials"},
|
||||
{name: "unknown", cause: errors.New("dial tcp 10.0.0.1:5432: refused"), want: "gateway log"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
raw := fmt.Errorf(`llm chat stream: gemini: status 429: {"message":"https://ai.studio/spend"}: %w`, tc.cause)
|
||||
router := &Router{LLMStream: func(context.Context, Inbound, TurnStream) (string, error) { return "", raw }}
|
||||
adapter := &LocalChatAdapter{Router: router}
|
||||
events := make(chan ChatEvent, 32)
|
||||
go adapter.runStreamedTurn(context.Background(), Inbound{Message: messaging.Message{Text: "hi"}}, "s1", events)
|
||||
for event := range events {
|
||||
if event.Kind != "error" {
|
||||
continue
|
||||
}
|
||||
for _, leak := range []string{"gemini", "429", "ai.studio", "10.0.0.1", "llm chat stream"} {
|
||||
if strings.Contains(event.Text, leak) {
|
||||
t.Fatalf("error text %q exposes %q", event.Text, leak)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(event.Text, tc.want) {
|
||||
t.Fatalf("error text %q, want it to mention %q", event.Text, tc.want)
|
||||
}
|
||||
return
|
||||
}
|
||||
t.Fatal("no error event")
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -100,6 +100,9 @@ func splitLegacyChannelSettings(orgID string, stored []byte) (rewritten []byte,
|
||||
return nil, telegramConnection{}, false, fmt.Errorf("decode telegram: %w", err)
|
||||
}
|
||||
delete(doc, "telegram")
|
||||
// A document old enough to carry telegram can also carry the per-channel
|
||||
// models that model aliases replaced, which the current schema rejects.
|
||||
delete(doc, "models")
|
||||
if orgID == storecontract.DefaultOrgID {
|
||||
moved = telegramConnection{Token: legacy.TokenRef, Users: legacy.AllowedUserIDs}
|
||||
} else if len(legacy.AllowedUserIDs) > 0 {
|
||||
|
||||
@@ -15,6 +15,8 @@ import {
|
||||
commandSelection,
|
||||
commandSpecs,
|
||||
addTaskTag,
|
||||
clearPageTag,
|
||||
pageTag,
|
||||
composerText,
|
||||
editQueued,
|
||||
menuTrigger,
|
||||
@@ -219,7 +221,16 @@ function onKeydown(event: KeyboardEvent): void {
|
||||
</Tooltip>
|
||||
</li>
|
||||
</ul>
|
||||
<ul v-if="taskTags.length" aria-label="Attached tasks" class="mb-2 flex flex-wrap gap-1">
|
||||
<ul v-if="pageTag || taskTags.length" aria-label="Message context" class="mb-2 flex flex-wrap gap-1">
|
||||
<li
|
||||
v-if="pageTag"
|
||||
class="flex max-w-full items-center gap-1 rounded-md border border-border bg-muted px-2 py-0.5 text-label"
|
||||
>
|
||||
<span class="truncate">{{ pageTag.label }}</span>
|
||||
<Button variant="ghost" size="icon" class="size-5" aria-label="Remove page context" @click="clearPageTag"
|
||||
><X
|
||||
/></Button>
|
||||
</li>
|
||||
<li
|
||||
v-for="tag in taskTags"
|
||||
:key="tag.id"
|
||||
|
||||
+35
-4
@@ -1,6 +1,7 @@
|
||||
import { computed, onMounted, onUnmounted, ref, watch, type Ref } from "vue";
|
||||
|
||||
import { api } from "@/lib/api";
|
||||
import { router } from "@/router";
|
||||
import { randomUUID } from "@/lib/uuid";
|
||||
import { channelID } from "./channel";
|
||||
import { commandCompletions, detectTrigger, taskCompletions, type Completion, type Trigger } from "./commands";
|
||||
@@ -335,7 +336,7 @@ async function sendCommand(
|
||||
channel_id: channelID(),
|
||||
source_id: randomUUID(),
|
||||
text,
|
||||
page: currentPage(),
|
||||
page: sentPage(),
|
||||
});
|
||||
if (!response.body) throw new Error("the chat stream returned no body");
|
||||
const reader = response.body.getReader();
|
||||
@@ -631,9 +632,39 @@ export function moveCommandSelection(delta: number): void {
|
||||
commandSelection.value = (commandSelection.value + delta + length) % length;
|
||||
}
|
||||
|
||||
/** The page the operator asked from, so an answer can be about what they saw. */
|
||||
/** The page the operator is on, without the hash the server never sees. */
|
||||
function currentPage(): string {
|
||||
return location.pathname + location.search || "/";
|
||||
return router.currentRoute.value.fullPath.split("#")[0] || "/";
|
||||
}
|
||||
|
||||
// The page whose tag the operator removed. Navigating elsewhere shows the tag
|
||||
// again, so the dismissal never outlives the page it was made on.
|
||||
const clearedPage = ref("");
|
||||
watch(currentPage, () => {
|
||||
clearedPage.value = "";
|
||||
});
|
||||
|
||||
/** What the next message is about, named for the tag above the composer. */
|
||||
export const pageTag = computed(() => {
|
||||
const page = currentPage();
|
||||
if (page === clearedPage.value) return null;
|
||||
const route = router.currentRoute.value;
|
||||
const label =
|
||||
route.name === "task-detail"
|
||||
? `Task #${route.params.id}`
|
||||
: typeof route.meta.label === "string"
|
||||
? route.meta.label
|
||||
: page;
|
||||
return { page, label };
|
||||
});
|
||||
|
||||
export function clearPageTag(): void {
|
||||
clearedPage.value = currentPage();
|
||||
}
|
||||
|
||||
/** The page sent with a message: the tag's page, or none once it is cleared. */
|
||||
function sentPage(): string | undefined {
|
||||
return pageTag.value?.page;
|
||||
}
|
||||
|
||||
export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
|
||||
@@ -731,7 +762,7 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
|
||||
channel_id: channelID(),
|
||||
source_id: turn.sourceID,
|
||||
text: turn.text,
|
||||
page: currentPage(),
|
||||
page: sentPage(),
|
||||
voice: turn.voice,
|
||||
},
|
||||
{ signal: ctrl.signal },
|
||||
|
||||
Reference in new issue
Block a user