Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hyperbrowser/agent",
"version": "1.0.9",
"version": "1.0.10",
"description": "Hyperbrowsers Web Agent",
"author": "",
"main": "dist/index.js",
Expand Down
22 changes: 20 additions & 2 deletions src/agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,9 @@ export class HyperAgent<T extends BrowserProviders = "Local"> {
};
} else if (step.actionType === "extract") {
try {
if (!step.instruction) {
throw new Error("Missing objective/instruction for extract action");
}
const extractResult = await hyperPage.extract(step.instruction);
result = {
taskId: cache.taskId,
Expand Down Expand Up @@ -783,7 +786,7 @@ export class HyperAgent<T extends BrowserProviders = "Local"> {
const method = step.method;
if (method && validHelperMethods.has(method)) {
const options: PerformOptions = {
performInstruction: step.instruction,
performInstruction: step.instruction ?? null,
maxSteps: maxXPathRetries,
};
if (step.frameIndex !== null && step.frameIndex !== undefined) {
Expand All @@ -797,8 +800,23 @@ export class HyperAgent<T extends BrowserProviders = "Local"> {
valueArg,
options
);
} else {
} else if (step.instruction) {
result = await hyperPage.perform(step.instruction);
} else {
result = {
taskId: cache.taskId,
status: TaskStatus.FAILED,
steps: [],
output: `Cannot replay action type "${step.actionType}" without instruction`,
replayStepMeta: {
usedCachedAction: false,
fallbackUsed: false,
retries: 0,
cachedXPath: null,
fallbackXPath: null,
fallbackElementId: null,
},
};
}
}

Expand Down
19 changes: 15 additions & 4 deletions src/agent/shared/action-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,23 @@ const normalizeXPath = (raw?: string | null): string | null => {
return raw.replace(TEXT_NODE_SUFFIX, "");
};

const extractInstruction = (action: ActionType): string => {
const extractInstruction = (action: ActionType): string | undefined => {
const params = action.params as Record<string, unknown>;
if (isString(params.instruction)) {
return params.instruction;
switch (action.type) {
case "extract":
if (isString(params.objective)) {
return params.objective;
}
throw new Error(`Missing objective for extract action`);
case "actElement":
if (isString(params.instruction)) {
return params.instruction;
}
throw new Error(`Missing instruction for actElement action`);
default:
// Actions like goToUrl, refreshPage, wait, analyzePdf do not require an instruction
return isString(params.instruction) ? params.instruction : undefined;
}
return action.type;
};

const extractElementId = (action: ActionType): string | null => {
Expand Down
2 changes: 1 addition & 1 deletion src/types/agent/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface AgentStep {

export interface ActionCacheEntry {
stepIndex: number;
instruction: string;
instruction: string | undefined;
elementId: string | null;
method: string | null;
arguments: string[];
Expand Down