@meetopenbot/stagehand 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +52 -9
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ import { defineAgentPlugin } from "@meetopenbot/plugin-sdk";
3
3
 
4
4
  // src/agent.ts
5
5
  import { Stagehand } from "@browserbasehq/stagehand";
6
+ import { textReply as textReply2 } from "@meetopenbot/plugin-sdk";
6
7
 
7
8
  // src/config.ts
8
9
  import {
@@ -30,14 +31,52 @@ function resolveStagehandConfig(config) {
30
31
  };
31
32
  }
32
33
 
34
+ // src/stream.ts
35
+ import {
36
+ createTextReplyBuffer,
37
+ textReply
38
+ } from "@meetopenbot/plugin-sdk";
39
+ var classifyStagehandPart = (part) => {
40
+ if (part.type === "text-delta") {
41
+ const text = part.text ?? part.delta ?? "";
42
+ return text ? { type: "delta", text } : { type: "skip" };
43
+ }
44
+ if (part.type === "step-finish" || part.type === "finish" || part.type === "tool-call") {
45
+ return { type: "flush" };
46
+ }
47
+ return { type: "skip" };
48
+ };
49
+ async function* runStagehandStream(fullStream) {
50
+ const replies = createTextReplyBuffer();
51
+ for await (const part of fullStream) {
52
+ yield* replies.apply(classifyStagehandPart(part));
53
+ }
54
+ yield* replies.end();
55
+ }
56
+ function finalStagehandReply(args) {
57
+ const items = [];
58
+ if (!args.yielded && args.message?.trim()) items.push(textReply(args.message.trim()));
59
+ if (args.output && typeof args.output === "object" && Object.keys(args.output).length > 0) {
60
+ items.push(textReply(JSON.stringify(args.output, null, 2)));
61
+ }
62
+ return items;
63
+ }
64
+
33
65
  // src/agent.ts
34
- async function runStagehandTurn({ prompt, context }) {
66
+ async function* runStagehandTurn({
67
+ prompt,
68
+ context
69
+ }) {
35
70
  const config = resolveStagehandConfig(context.config);
36
71
  if (config.requestedEnv === "BROWSERBASE" && (!config.browserbaseApiKey || !config.browserbaseProjectId)) {
37
- return "Stagehand Browserbase setup is incomplete. Set `BROWSERBASE_API_KEY` and `BROWSERBASE_PROJECT_ID` in workspace settings.";
72
+ yield textReply2(
73
+ "Stagehand Browserbase setup is incomplete. Set `BROWSERBASE_API_KEY` and `BROWSERBASE_PROJECT_ID` in workspace settings."
74
+ );
75
+ return;
38
76
  }
39
77
  if (config.requestedEnv === "LOCAL" && !config.apiKey) {
40
- return "Stagehand local setup is incomplete. Set `OPENAI_API_KEY` in workspace settings.";
78
+ yield textReply2("Stagehand local setup is incomplete. Set `OPENAI_API_KEY` in workspace settings.");
79
+ return;
41
80
  }
42
81
  let stagehand = null;
43
82
  try {
@@ -58,15 +97,19 @@ async function runStagehandTurn({ prompt, context }) {
58
97
  instruction: prompt,
59
98
  maxSteps: config.maxSteps
60
99
  });
61
- for await (const _part of streamResult.fullStream) {
100
+ let yielded = false;
101
+ for await (const item of runStagehandStream(streamResult.fullStream)) {
102
+ yielded = true;
103
+ yield item;
62
104
  }
63
105
  const result = await streamResult.result;
64
- const parts = [];
65
- if (result.message) parts.push(result.message);
66
- if (result.output && Object.keys(result.output).length > 0) {
67
- parts.push(JSON.stringify(result.output, null, 2));
106
+ for (const item of finalStagehandReply({
107
+ yielded,
108
+ message: result.message,
109
+ output: result.output
110
+ })) {
111
+ yield item;
68
112
  }
69
- return parts.join("\n\n");
70
113
  } finally {
71
114
  if (stagehand) await stagehand.close().catch(() => {
72
115
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meetopenbot/stagehand",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "type": "module",
5
5
  "description": "Stagehand AI browser automation plugin for OpenBot",
6
6
  "main": "./dist/index.js",
@@ -24,7 +24,7 @@
24
24
  "@browserbasehq/stagehand": "^3.3.0",
25
25
  "playwright": "^1.52.0",
26
26
  "zod": "^4.3.5",
27
- "@meetopenbot/plugin-sdk": "^0.3.0"
27
+ "@meetopenbot/plugin-sdk": "^0.4.0"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/node": "^20.10.1",