Refine onboarding state and nickname checks
This commit is contained in:
1 parent
5579db54da
commit
9c013f7d4f
33 files changed
+1523
-119
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import type { AgentRequest, AgentResponse, ConversationMessage } from "@agent/types";
|
||||
import { getConversationSummaryKey } from "@conv/conversation-store";
|
||||
import type { GarnetClient } from "@common/garnet";
|
||||
import type { NatsClient } from "@common/nats";
|
||||
import { getContext, getRequestLogger } from "@obs/context";
|
||||
import type { LlmClient } from "@llm/llm-client";
|
||||
import type { ChatMessage } from "@llm/types";
|
||||
@@ -36,7 +37,12 @@ import { OnboardingIntentClassifier } from "./state/classifier.js";
|
||||
import type { DerivedState, Intent } from "./state/onboarding-state.js";
|
||||
import { OnboardingOrchestrator } from "./runtime/orchestrator.js";
|
||||
import { validateOnboardingResponse } from "./runtime/validator.js";
|
||||
import type { OnboardingSession, PromptContext } from "./types.js";
|
||||
import { normalizeOnboardingSession } from "./session.js";
|
||||
import type {
|
||||
OnboardingSession,
|
||||
PromptContext,
|
||||
StoredOnboardingSession,
|
||||
} from "./types.js";
|
||||
|
||||
type LlmTextResult =
|
||||
| { status: "success"; text: string }
|
||||
@@ -56,6 +62,7 @@ export class OnboardingSkill implements Skill {
|
||||
private readonly llmClient: LlmClient,
|
||||
private readonly roomContextService?: RoomContextService,
|
||||
shadowEvalPublisher?: ShadowEvalPublisher,
|
||||
private readonly natsClient?: Pick<NatsClient, "request">,
|
||||
) {
|
||||
this.classifier = new OnboardingIntentClassifier(llmClient);
|
||||
this.blackboardStore = new OnboardingBlackboardStore(garnetClient);
|
||||
@@ -124,6 +131,16 @@ export class OnboardingSkill implements Skill {
|
||||
}
|
||||
}
|
||||
|
||||
if (derived.intent.kind === "discord-verify-question") {
|
||||
logger.debug(
|
||||
{
|
||||
responseSource: response.source,
|
||||
responseText: response.text,
|
||||
},
|
||||
"[OnboardingSkill] Final discord verification response",
|
||||
);
|
||||
}
|
||||
|
||||
if (response.text.trim()) {
|
||||
await this.rememberTurn(request, derived).catch((error) => {
|
||||
logger.warn({ err: error }, "[OnboardingSkill] Failed to update blackboard");
|
||||
@@ -148,7 +165,8 @@ export class OnboardingSkill implements Skill {
|
||||
): Promise<OnboardingSession | null> {
|
||||
const prefix = getOnboardingSessionKeyPrefix();
|
||||
const key = `${prefix}:onboarding:${chatroomId}:${userId}`;
|
||||
return this.garnetClient.getJson<OnboardingSession>(key);
|
||||
const rawSession = await this.garnetClient.getJson<StoredOnboardingSession>(key);
|
||||
return normalizeOnboardingSession(rawSession);
|
||||
}
|
||||
|
||||
private async handleLlm(
|
||||
@@ -260,7 +278,8 @@ export class OnboardingSkill implements Skill {
|
||||
derived.intent.kind === "help-where" ||
|
||||
derived.intent.kind === "nickname-question" ||
|
||||
derived.intent.kind === "photo-question" ||
|
||||
derived.intent.kind === "discord-question"
|
||||
derived.intent.kind === "discord-question" ||
|
||||
derived.intent.kind === "discord-verify-question"
|
||||
)
|
||||
? [...current.openQuestions, userMessage].slice(-3)
|
||||
: current.openQuestions;
|
||||
@@ -400,6 +419,8 @@ export class OnboardingSkill implements Skill {
|
||||
return getGenericHelpMessage(nickname, session);
|
||||
case "discord-question":
|
||||
return getDiscordMessage(nickname, session);
|
||||
case "discord-verify-question":
|
||||
return getDiscordMessage(nickname, session);
|
||||
case "age-question":
|
||||
return getAgeRequirementMessage();
|
||||
case "chitchat":
|
||||
@@ -514,6 +535,7 @@ export class OnboardingSkill implements Skill {
|
||||
): ToolContext {
|
||||
return {
|
||||
chatroomId: request.chatroomId,
|
||||
natsClient: this.natsClient,
|
||||
userId: request.userId,
|
||||
session,
|
||||
garnetClient: this.garnetClient,
|
||||
@@ -524,6 +546,12 @@ export class OnboardingSkill implements Skill {
|
||||
private selectToolsForDerived(
|
||||
derived: DerivedState,
|
||||
): readonly Tool<unknown, unknown>[] {
|
||||
if (derived.intent.kind === "discord-verify-question") {
|
||||
return this.tools.filter((tool) =>
|
||||
tool.name === "verify-discord-nickname",
|
||||
);
|
||||
}
|
||||
|
||||
if (derived.phase.kind === "nickname-rejected") {
|
||||
return this.tools.filter((tool) =>
|
||||
tool.name === "validate-nickname" ||
|
||||
@@ -538,6 +566,13 @@ export class OnboardingSkill implements Skill {
|
||||
);
|
||||
}
|
||||
|
||||
if (derived.intent.kind === "discord-question") {
|
||||
return this.tools.filter((tool) =>
|
||||
tool.name === "lookup-community-rule" ||
|
||||
tool.name === "verify-discord-nickname",
|
||||
);
|
||||
}
|
||||
|
||||
return this.tools;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user