@@ -61,22 +61,8 @@ export function normalizeMessagesForCurrentPromptBoundary(params: {
|
61 | 61 | includeTimestamp?: boolean; |
62 | 62 | currentUserTimestamp?: number; |
63 | 63 | }): AgentMessage[] { |
64 | | -const promptMessage = { |
65 | | -role: "user" as const, |
66 | | -content: [{ type: "text" as const, text: params.prompt }], |
67 | | -timestamp: params.currentUserTimestamp ?? Date.now(), |
68 | | -}; |
69 | | -const boundaryOptions = |
70 | | -params.timezone || params.includeTimestamp === false |
71 | | - ? { |
72 | | - ...(params.timezone ? { timezone: params.timezone } : {}), |
73 | | - ...(params.includeTimestamp === false ? { includeTimestamp: false } : {}), |
74 | | -} |
75 | | - : undefined; |
76 | | -return normalizeMessagesForLlmBoundary( |
77 | | -[...params.messages, promptMessage], |
78 | | -boundaryOptions, |
79 | | -).slice(0, -1); |
| 64 | +const { message, options } = buildCurrentPromptBoundaryInput(params); |
| 65 | +return normalizeMessagesForLlmBoundary([...params.messages, message], options).slice(0, -1); |
80 | 66 | } |
81 | 67 | |
82 | 68 | export function normalizeCurrentPromptTextForLlmBoundary(params: { |
@@ -85,21 +71,33 @@ export function normalizeCurrentPromptTextForLlmBoundary(params: {
|
85 | 71 | includeTimestamp?: boolean; |
86 | 72 | currentUserTimestamp?: number; |
87 | 73 | }): string { |
88 | | -const promptMessage = { |
89 | | -role: "user" as const, |
90 | | -content: [{ type: "text" as const, text: params.prompt }], |
91 | | -timestamp: params.currentUserTimestamp ?? Date.now(), |
92 | | -}; |
93 | | -const boundaryOptions = |
| 74 | +const { message, options } = buildCurrentPromptBoundaryInput(params); |
| 75 | +const [normalized] = normalizeMessagesForLlmBoundary([message], options); |
| 76 | +const content = (normalized as { content?: unknown } | undefined)?.content; |
| 77 | +return typeof content === "string" ? content : params.prompt; |
| 78 | +} |
| 79 | + |
| 80 | +function buildCurrentPromptBoundaryInput(params: { |
| 81 | +prompt: string; |
| 82 | +timezone?: string; |
| 83 | +includeTimestamp?: boolean; |
| 84 | +currentUserTimestamp?: number; |
| 85 | +}): { message: AgentMessage; options?: LlmBoundaryOptions } { |
| 86 | +const options = |
94 | 87 | params.timezone || params.includeTimestamp === false |
95 | 88 | ? { |
96 | 89 | ...(params.timezone ? { timezone: params.timezone } : {}), |
97 | 90 | ...(params.includeTimestamp === false ? { includeTimestamp: false } : {}), |
98 | 91 | } |
99 | 92 | : undefined; |
100 | | -const [normalized] = normalizeMessagesForLlmBoundary([promptMessage], boundaryOptions); |
101 | | -const content = (normalized as { content?: unknown } | undefined)?.content; |
102 | | -return typeof content === "string" ? content : params.prompt; |
| 93 | +return { |
| 94 | +message: { |
| 95 | +role: "user", |
| 96 | +content: [{ type: "text", text: params.prompt }], |
| 97 | +timestamp: params.currentUserTimestamp ?? Date.now(), |
| 98 | +}, |
| 99 | + options, |
| 100 | +}; |
103 | 101 | } |
104 | 102 | |
105 | 103 | /** |
|