Skip to content

Commit d74a0c2

Browse files
committed
Update turnPolicy
1 parent daf9793 commit d74a0c2

9 files changed

Lines changed: 620 additions & 324 deletions

File tree

apps/web/src/app/api/telegram/webhook/route.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ function buildRoutedTurn(input: {
150150
? { mutationInputSource: "recovered_proposal" as const }
151151
: input.action === "execute_mutation"
152152
? { mutationInputSource: "direct_user_turn" as const }
153-
: {})
153+
: {}),
154+
committedSlots: {}
154155
}
155156
};
156157
}

apps/web/src/lib/server/conversation-state.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ describe("deriveConversationReplyState", () => {
3333
const result = deriveConversationReplyState({
3434
snapshot: buildSnapshot(),
3535
policy: {
36-
action: "ask_clarification"
36+
action: "ask_clarification",
37+
committedSlots: {}
3738
},
3839
interpretation: {
3940
turnType: "planning_request",
@@ -71,7 +72,8 @@ describe("deriveConversationReplyState", () => {
7172
snapshot: buildSnapshot(),
7273
policy: {
7374
action: "ask_clarification",
74-
clarificationSlots: ["proposal"]
75+
clarificationSlots: ["proposal"],
76+
committedSlots: {}
7577
},
7678
interpretation: {
7779
turnType: "confirmation",
@@ -94,7 +96,8 @@ describe("deriveConversationReplyState", () => {
9496
const result = deriveConversationReplyState({
9597
snapshot: buildSnapshot(),
9698
policy: {
97-
action: "ask_clarification"
99+
action: "ask_clarification",
100+
committedSlots: {}
98101
},
99102
interpretation: {
100103
turnType: "unknown",
@@ -154,7 +157,8 @@ describe("deriveConversationReplyState", () => {
154157
const result = deriveConversationReplyState({
155158
snapshot,
156159
policy: {
157-
action: "present_proposal"
160+
action: "present_proposal",
161+
committedSlots: {}
158162
},
159163
interpretation: {
160164
turnType: "clarification_answer",

apps/web/src/lib/server/conversation-state.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { type ProcessedInboxResult } from "@atlas/db";
1919

2020
type DeriveConversationReplyStateInput = {
2121
snapshot: ConversationStateSnapshot;
22-
policy: Pick<TurnPolicyDecision, "action" | "clarificationSlots" | "targetProposalId"> & {
22+
policy: Pick<TurnPolicyDecision, "action" | "clarificationSlots" | "targetProposalId" | "committedSlots"> & {
2323
action: Extract<TurnPolicyAction, "reply_only" | "ask_clarification" | "present_proposal">;
2424
};
2525
interpretation: TurnInterpretation;
@@ -134,7 +134,7 @@ export function deriveConversationReplyState(input: DeriveConversationReplyState
134134
});
135135
nextFocusEntityId ??= clarificationEntity.id;
136136
}
137-
const nextDiscourseState = updateDiscourseStateFromAssistantTurn(discourseState, {
137+
const updatedDiscourseState = updateDiscourseStateFromAssistantTurn(discourseState, {
138138
...(presentedItems.length > 0 ? { presentedItems } : {}),
139139
...(newClarifications.length > 0 ? { newClarifications } : {}),
140140
...(resolvedClarificationIds.length > 0 ? { resolvedClarificationIds } : {}),
@@ -143,6 +143,12 @@ export function deriveConversationReplyState(input: DeriveConversationReplyState
143143
validEntityIds: entityRegistry.map((entity) => entity.id)
144144
}).state;
145145

146+
const committedSlots = input.policy.committedSlots;
147+
const nextDiscourseState =
148+
committedSlots && Object.keys(committedSlots).length > 0
149+
? { ...updatedDiscourseState, resolved_slots: committedSlots }
150+
: updatedDiscourseState;
151+
146152
return {
147153
summaryText: input.summaryText,
148154
mode: getConversationModeForPolicy(input.policy.action),

0 commit comments

Comments
 (0)