Skip to content

Commit 7691ba4

Browse files
author
Shaw
committed
updates
1 parent 0e8487a commit 7691ba4

9 files changed

Lines changed: 178 additions & 103 deletions

File tree

cloud/packages/lib/services/containers/agent-warm-pool.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,4 @@ function emptyState(): PoolStateSnapshot {
383383
};
384384
}
385385

386-
/**
387-
* Helper used by the claim flow to persist a row update + delete pool row
388-
* in one transaction. Lives on the repo; this re-export is purely for
389-
* call-site clarity.
390-
*/
391-
export const claimWarmContainer = agentSandboxesRepository.claimWarmContainer.bind(
392-
agentSandboxesRepository,
393-
);
394-
395386
export type { AgentSandbox };

cloud/packages/tests/unit/agent-warm-pool-manager.test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,21 +187,27 @@ describe("WarmPoolManager", () => {
187187
});
188188
const { WarmPoolManager } = await importManager();
189189
const creator: CreatorMock = {
190-
...makeCreator(),
190+
createCalls: 0,
191+
destroyCalls: [],
192+
probeReturns: new Map(),
191193
async createPoolContainer() {
192194
this.createCalls++;
193195
if (this.createCalls === 2) throw new Error("hcloud quota exceeded");
194196
return { id: `c-${this.createCalls}`, nodeId: "node-1" };
195197
},
198+
async destroyPoolContainer(id: string) {
199+
this.destroyCalls.push(id);
200+
},
201+
async healthProbe() {
202+
return true;
203+
},
196204
} as CreatorMock;
205+
const mgr = new WarmPoolManager(creator, DEFAULT_WARM_POOL_POLICY, () => NOW);
197206

198-
const result = await mgr.replenishWithCreator(creator);
207+
const result = await mgr.replenish(IMAGE);
199208
expect(result.created.length).toBe(1);
200209
expect(result.failed.length).toBe(1);
201210
expect(result.failed[0]?.error).toContain("hcloud quota");
202-
203-
function _ignored<T>(_v: T): void {}
204-
_ignored(creator);
205211
});
206212

207213
test("drainIdle removes only past-idle-window entries when target == floor", async () => {

packages/core/src/features/advanced-capabilities/actions/roles.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@ interface RoleAssignmentToon {
2424
newRole?: string;
2525
}
2626

27-
/** Shape of the role extraction structured response. */
28-
interface RoleExtractionResult {
29-
assignments?:
30-
| {
31-
assignment?: RoleAssignmentToon | RoleAssignmentToon[];
32-
}
33-
| RoleAssignmentToon[];
34-
}
35-
3627
function isRecord(value: unknown): value is Record<string, unknown> {
3728
return typeof value === "object" && value !== null && !Array.isArray(value);
3829
}

packages/core/src/services/message.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ import {
2828
} from "../prompts/message-handler";
2929
import { filterByContextGate } from "../runtime/context-gates";
3030
import { createContextObject } from "../runtime/context-object";
31+
import type { ContextRegistry } from "../runtime/context-registry";
32+
import { checkSenderRole } from "../roles";
33+
import type { ContextDefinition, RoleGateRole } from "../types/contexts";
3134
import {
3235
type EvaluatorEffects,
3336
type EvaluatorOutput,
@@ -51,6 +54,11 @@ import {
5154
runPlannerLoop,
5255
} from "../runtime/planner-loop";
5356
import { actionHasSubActions, runSubPlanner } from "../runtime/sub-planner";
57+
import {
58+
createJsonFileTrajectoryRecorder,
59+
isTrajectoryRecordingEnabled,
60+
type TrajectoryRecorder,
61+
} from "../runtime/trajectory-recorder";
5462
import { isExplicitSelfModificationRequest } from "../should-respond";
5563
import {
5664
getModelStreamChunkDeliveryDepth,

plugins/plugin-discord/actions/chatWithAttachments.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
type Memory,
1515
MemoryType,
1616
ModelType,
17-
parseToonKeyValue,
1817
type State,
1918
trimTokens,
2019
} from "@elizaos/core";
@@ -23,6 +22,7 @@ import {
2322
attachmentSummarizationTemplate as summarizationTemplate,
2423
} from "../generated/prompts/typescript/prompts.js";
2524
import { requireActionSpec } from "../generated/specs/spec-helpers";
25+
import { getActionParameters, parseJsonObjectFromText } from "../utils";
2626

2727
const SPEC_NAME = "DISCORD_CHAT_WITH_ATTACHMENTS";
2828

@@ -37,7 +37,16 @@ const getAttachmentIds = async (
3737
runtime: IAgentRuntime,
3838
_message: Memory,
3939
state: State,
40+
options?: HandlerOptions,
4041
): Promise<{ objective: string; attachmentIds: string[] } | null> => {
42+
const parameters = getActionParameters(options);
43+
if (parameters.objective && Array.isArray(parameters.attachmentIds)) {
44+
return {
45+
objective: String(parameters.objective),
46+
attachmentIds: parameters.attachmentIds.map(String),
47+
};
48+
}
49+
4150
const prompt = composePromptFromState({
4251
state,
4352
template: attachmentIdsTemplate,
@@ -47,10 +56,7 @@ const getAttachmentIds = async (
4756
const response = await runtime.useModel(ModelType.TEXT_SMALL, {
4857
prompt,
4958
});
50-
// Try parsing the TOON response.
51-
const parsedResponse = parseToonKeyValue<Record<string, unknown>>(
52-
response,
53-
) as {
59+
const parsedResponse = parseJsonObjectFromText(response) as {
5460
objective: string;
5561
attachmentIds: string[];
5662
} | null;
@@ -176,7 +182,7 @@ export const chatWithAttachments: Action = {
176182
runtime: IAgentRuntime,
177183
message: Memory,
178184
state?: State,
179-
_options?: HandlerOptions,
185+
options?: HandlerOptions,
180186
callback?: HandlerCallback,
181187
): Promise<ActionResult | undefined> => {
182188
if (!state) {
@@ -196,7 +202,7 @@ export const chatWithAttachments: Action = {
196202
};
197203

198204
// 1. extract attachment IDs from the message
199-
const attachmentData = await getAttachmentIds(runtime, message, state);
205+
const attachmentData = await getAttachmentIds(runtime, message, state, options);
200206
if (!attachmentData) {
201207
runtime.logger.warn(
202208
{

plugins/plugin-discord/actions/summarizeConversation.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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";
2322
import { 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

Comments
 (0)