@@ -15,12 +15,12 @@ import {
1515 type Memory ,
1616 MemoryType ,
1717 ModelType ,
18- parseToonKeyValue ,
1918 type State ,
2019 splitChunks ,
2120 trimTokens ,
2221} from "@elizaos/core" ;
2322import { requireActionSpec } from "../generated/specs/spec-helpers" ;
23+ import { getActionParameters , parseJsonObjectFromText } from "../utils" ;
2424
2525/**
2626 * Normalizes a numeric timestamp to milliseconds.
@@ -137,7 +137,28 @@ const getDateRange = async (
137137 runtime : IAgentRuntime ,
138138 _message : Memory ,
139139 state : State ,
140+ options ?: HandlerOptions ,
140141) : Promise < { objective : string ; start : number ; end : number } | null > => {
142+ const parameters = getActionParameters ( options ) ;
143+ if ( parameters . objective && parameters . start && parameters . end ) {
144+ const startRaw = parseTimeToTimestamp (
145+ parameters . start as string | number ,
146+ ) ;
147+ const endRaw = parseTimeToTimestamp ( parameters . end as string | number ) ;
148+ if ( Number . isFinite ( startRaw ) && Number . isFinite ( endRaw ) ) {
149+ let start = startRaw <= endRaw ? startRaw : endRaw ;
150+ const end = startRaw <= endRaw ? endRaw : startRaw ;
151+ if ( start === end ) {
152+ start = end - 3600 * 1000 ;
153+ }
154+ return {
155+ objective : String ( parameters . objective ) ,
156+ start,
157+ end,
158+ } ;
159+ }
160+ }
161+
141162 const prompt = composePromptFromState ( {
142163 state,
143164 template : dateRangeTemplate ,
@@ -148,10 +169,7 @@ const getDateRange = async (
148169 prompt,
149170 } ) ;
150171
151- // Try parsing the TOON response.
152- const parsedResponse = parseToonKeyValue < Record < string , unknown > > (
153- response ,
154- ) as {
172+ const parsedResponse = parseJsonObjectFromText ( response ) as {
155173 objective : string ;
156174 start : string | number ;
157175 end : string | number ;
@@ -311,7 +329,7 @@ export const summarize: Action = {
311329 runtime : IAgentRuntime ,
312330 message : Memory ,
313331 state ?: State ,
314- _options ?: HandlerOptions ,
332+ options ?: HandlerOptions ,
315333 callback ?: HandlerCallback ,
316334 ) : Promise < ActionResult | undefined > => {
317335 if ( ! state ) {
@@ -333,7 +351,7 @@ export const summarize: Action = {
333351 const { roomId } = message ;
334352
335353 // 1. extract date range from the message
336- const dateRange = await getDateRange ( runtime , message , state ) ;
354+ const dateRange = await getDateRange ( runtime , message , state , options ) ;
337355 if ( ! dateRange ) {
338356 runtime . logger . warn (
339357 {
0 commit comments