@browserless.io/cli 0.6.1 → 0.7.0
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.
- package/CHANGELOG.md +7 -0
- package/README.md +15 -6
- package/build/api/profiles.js +1 -1
- package/build/cli-utils/agent-format.js +4 -7
- package/build/cli-utils/prompts.js +1 -4
- package/build/commands/agent/chat.js +11 -10
- package/build/commands/agent/index.js +1 -1
- package/build/version.js +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -303,19 +303,28 @@ browserless agent "find the opening hours of the Louvre"
|
|
|
303
303
|
|
|
304
304
|
# Scripts: stdout carries only the final result as JSON (progress goes to stderr)
|
|
305
305
|
browserless agent "find the opening hours of the Louvre" --json
|
|
306
|
+
|
|
307
|
+
# Save a signed-in local browser once, then use its cloud profile
|
|
308
|
+
browserless profile upload --browser chrome --profile Personal --name github
|
|
309
|
+
browserless agent --cloud-profile github "star browserless/browserless on GitHub"
|
|
306
310
|
```
|
|
307
311
|
|
|
308
312
|
- Follow-up messages continue the same session. Ctrl-C stops the current
|
|
309
313
|
turn; press it again (or send an empty line) to exit.
|
|
310
314
|
- When the agent pauses for input — for example a one-time code — the CLI
|
|
311
315
|
prompts you for it.
|
|
312
|
-
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
+
- For signed-in tasks, upload a signed-in browser with
|
|
317
|
+
`browserless profile upload --name <name> --browser <browser> --profile <local-profile>` and pass that cloud name with
|
|
318
|
+
`browserless agent --cloud-profile <name>`. The CLI validates the name and
|
|
319
|
+
checks that it exists before starting the agent. Run `browserless profile list`
|
|
320
|
+
to see your cloud profiles. A login-looking first message without the flag
|
|
321
|
+
prints a tip instead of asking for credentials. The agent is instructed never
|
|
322
|
+
to ask for passwords or other secrets and to stop when sign-in is needed.
|
|
323
|
+
If the saved profile is no longer signed in, update it with
|
|
324
|
+
`browserless profile refresh --name <name>`.
|
|
316
325
|
- Prompts you type are kept in `~/.browserless/agent_history` (mode 0600,
|
|
317
|
-
last 200) so the up arrow recalls them across sessions;
|
|
318
|
-
|
|
326
|
+
last 200) so the up arrow recalls them across sessions; one-time codes
|
|
327
|
+
are never written there. `--no-history` turns the
|
|
319
328
|
file off.
|
|
320
329
|
|
|
321
330
|
## ⚙️ Shared Flags
|
package/build/api/profiles.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var n=Object.defineProperty;var t=(e
|
|
1
|
+
var n=Object.defineProperty;var t=(o,e)=>n(o,"name",{value:e,configurable:!0});import{apiFetch as i}from"./client.js";import{UsageError as f}from"../errors.js";import{terminalSafe as s}from"../utils/terminal.js";const a=t(o=>{if(!o||o.length>255||!/^[^\s/?#]+$/.test(o)||o==="."||o==="..")throw new f(`"${s(o)}" is not a valid cloud profile name: use 1-255 characters with no whitespace, "/", "?" or "#".`,"invalid-cloud-profile-name");return o},"assertCloudProfileName"),m=t(async(o,e={})=>i(o,{method:"GET",path:"/profiles",query:{...e.limit!==void 0?{limit:e.limit}:{},...e.offset!==void 0?{offset:e.offset}:{}}}),"listProfiles"),r=t(o=>{if(o==="."||o==="..")throw new f(`"${o}" is not a valid profile name.`);return`/profile/${encodeURIComponent(o)}`},"profilePath"),u=t(async(o,e)=>i(o,{method:"GET",path:r(e)}),"getProfile"),P=t(async(o,e,l)=>i(o,{method:"PUT",path:r(e),body:{name:l}}),"renameProfile"),w=t(async(o,e)=>i(o,{method:"DELETE",path:r(e)}),"deleteProfile");export{a as assertCloudProfileName,w as deleteProfile,u as getProfile,m as listProfiles,P as renameProfile};
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
var d=Object.defineProperty;var
|
|
2
|
-
${n.join(`
|
|
3
|
-
`)}
|
|
4
|
-
|
|
5
|
-
`+t},"withCredentials"),b=s((t,e)=>{const n=typeof t=="string"?t:t===null||typeof t!="object"?String(t):JSON.stringify(t),o=[...n];return o.length>e?`${o.slice(0,e-1).join("")}\u2026`:n},"previewValue"),_=/^(pass(word|code)?|secret|token|auth(orization)?|cookie|credentials?|api[-_]?key|otp|mfa|text|value)$/i,w=s((t,e=60)=>{if(!t||typeof t!="object")return"";const n=t;if(Array.isArray(n.commands)){const r=n.commands;return[...`${r.length} cmds: ${r.map(i=>i&&typeof i=="object"&&"method"in i&&typeof i.method=="string"?i.method:"?").join(" \u2192 ")}`].slice(0,e).join("")}const o=Object.entries(n).filter(([,r])=>r!==void 0);if(o.length===0)return"";const c=[];let l=0;for(const[r,a]of o){const i=_.test(r)?"[REDACTED]":b(a,30),u=`${r}=${i}`,f=[...u].length;if(l+f+2>e)break;c.push(u),l+=f+2}return c.join(" ")},"summarizeParams"),N=s((t,e)=>{const n=e&&typeof e=="object"?e:{};if(t==="browserless_skill")return{method:"skill",params:{id:n.id}};if(t==="browserless_agent"){const o=n.commands;return Array.isArray(o)&&o.length>0?{method:"commands",params:{commands:o}}:{method:typeof n.method=="string"?n.method:"agent",params:n.params}}return{method:typeof t=="string"?t:"?",params:e}},"unwrapToolCall"),x=s(t=>{if(!h(t.result))return"";const e=t.result,n=[`Result: ${e.success?m("success"):p("failed")}`];for(const o of["reason_code","final_url","evidence"])if(typeof e[o]=="string"){const c=` ${o}: `;n.push(c+g(e[o],{preserveLayout:o==="evidence"}).replaceAll(`
|
|
1
|
+
var d=Object.defineProperty;var o=(e,t)=>d(e,"name",{value:t,configurable:!0});import{green as h,red as p}from"../utils/ansi.js";import{isAgentEndResult as m}from"../agent/types.js";import{terminalSafe as g}from"../utils/terminal.js";const y=/\b(log[- _]?in|sign[- _]?in|sign[- _]?up|authenticate|log on)/i,v=o(e=>y.test(e),"hasLoginIntent"),A=o(e=>{if(typeof e!="string")return;const t=e.trim();return t||void 0},"normalizeRationale"),j="Tip: the agent can't sign in for you. Save a signed-in browser with `browserless profile upload --name <name> --browser <browser> --profile <local-profile>`, then rerun with `browserless agent --cloud-profile <name>`.",E=o((e,t={})=>{const s=JSON.stringify(t.cloudProfile),r=t.cloudProfile&&/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(t.cloudProfile)?`\`browserless profile refresh --name ${t.cloudProfile}\``:"`browserless profile refresh --name <name>`, quoting the profile name for their shell";return["Instructions from the Browserless CLI (not typed by the user):",...t.cloudProfile?[`- Open every new browser session with the user's saved cloud profile ${s}: pass "profile": ${s} to browserless_agent whenever you start a session without a sessionId. Keep reusing that session's sessionId afterwards.`,`- Never ask the user for a password, API key, or other secret, and never ask them to type one into this chat. If a site still asks you to sign in, stop and say the saved profile is not signed in there; the user can update it with ${r}.`]:["- Never ask the user for a password, API key, or other secret, and never ask them to type one into this chat. If a site requires signing in, stop and say sign-in is needed; the user can save a signed-in browser with `browserless profile upload --name <name> --browser <browser> --profile <local-profile>` and rerun with `browserless agent --cloud-profile <name>`."],"- You may still ask the user for a one-time verification code that a site sends during sign-in.","","User task:",e].join(`
|
|
2
|
+
`)},"buildFirstTurn"),w=o((e,t)=>{const s=typeof e=="string"?e:e===null||typeof e!="object"?String(e):JSON.stringify(e),r=[...s];return r.length>t?`${r.slice(0,t-1).join("")}\u2026`:s},"previewValue"),b=/^(pass(word|code)?|secret|token|auth(orization)?|cookie|credentials?|api[-_]?key|otp|mfa|text|value)$/i,P=o((e,t=60)=>{if(!e||typeof e!="object")return"";const s=e;if(Array.isArray(s.commands)){const n=s.commands;return[...`${n.length} cmds: ${n.map(i=>i&&typeof i=="object"&&"method"in i&&typeof i.method=="string"?i.method:"?").join(" \u2192 ")}`].slice(0,t).join("")}const r=Object.entries(s).filter(([,n])=>n!==void 0);if(r.length===0)return"";const a=[];let l=0;for(const[n,c]of r){const i=b.test(n)?"[REDACTED]":w(c,30),u=`${n}=${i}`,f=[...u].length;if(l+f+2>t)break;a.push(u),l+=f+2}return a.join(" ")},"summarizeParams"),N=o((e,t)=>{const s=t&&typeof t=="object"?t:{};if(e==="browserless_skill")return{method:"skill",params:{id:s.id}};if(e==="browserless_agent"){const r=s.commands;return Array.isArray(r)&&r.length>0?{method:"commands",params:{commands:r}}:{method:typeof s.method=="string"?s.method:"agent",params:s.params}}return{method:typeof e=="string"?e:"?",params:t}},"unwrapToolCall"),R=o(e=>{if(!m(e.result))return"";const t=e.result,s=[`Result: ${t.success?h("success"):p("failed")}`];for(const r of["reason_code","final_url","evidence"])if(typeof t[r]=="string"){const a=` ${r}: `;s.push(a+g(t[r],{preserveLayout:r==="evidence"}).replaceAll(`
|
|
6
3
|
`,`
|
|
7
|
-
${" ".repeat(
|
|
8
|
-
`)},"formatEndResult");export{
|
|
4
|
+
${" ".repeat(a.length)}`))}return s.join(`
|
|
5
|
+
`)},"formatEndResult");export{j as LOGIN_TIP,E as buildFirstTurn,R as formatEndResult,v as hasLoginIntent,A as normalizeRationale,P as summarizeParams,N as unwrapToolCall};
|
|
@@ -1,4 +1 @@
|
|
|
1
|
-
var
|
|
2
|
-
`){f(),e.write(`
|
|
3
|
-
`),r(a);return}if(n===p){f(),e.write(`
|
|
4
|
-
`),i(new Error("aborted"));return}if(n===T||n==="\b"){a.length>0&&(a=a.slice(0,-1),e.write("\b \b"));continue}a+=n,e.write("*")}},"onData");t.on("data",l)})}}),"buildPrompts");export{g as buildPrompts};
|
|
1
|
+
var c=Object.defineProperty;var a=(e,r)=>c(e,"name",{value:r,configurable:!0});import s from"node:readline/promises";import{stdin as l,stdout as p}from"node:process";const m=200,I=a((e,r,i=p,o=l)=>({async line(n){const t=s.createInterface({input:o,output:i,history:e,historySize:m,removeHistoryDuplicates:!0});try{const u=(await t.question(n)).trim();return r(e).catch(()=>{}),u}finally{t.close()}},async linePrivate(n){const t=s.createInterface({input:o,output:i});try{return(await t.question(n)).trim()}finally{t.close()}}}),"buildPrompts");export{I as buildPrompts};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
var
|
|
2
|
-
`))},"ensureTextStart"),
|
|
3
|
-
`),s==="status"&&
|
|
4
|
-
`);const{method:
|
|
5
|
-
`),
|
|
6
|
-
${
|
|
1
|
+
var C=Object.defineProperty;var n=(e,c)=>C(e,"name",{value:c,configurable:!0});import{stdout as x,stderr as P}from"node:process";import{buildClient as S,printJson as _}from"../../cli-utils/client.js";import{buildPrompts as T}from"../../cli-utils/prompts.js";import{ApiError as E,UsageError as $}from"../../errors.js";import{assertCloudProfileName as A,getProfile as I}from"../../api/profiles.js";import{AgentClient as L}from"../../agent/ws-client.js";import{loadHistory as R,saveHistory as v}from"../../agent/history.js";import{normalizeRationale as B,formatEndResult as F,hasLoginIntent as G,summarizeParams as N,unwrapToolCall as z,buildFirstTurn as H,LOGIN_TIP as M}from"../../cli-utils/agent-format.js";import{colorsFor as g}from"../../utils/ansi.js";import{Spinner as U}from"../../utils/spinner.js";import{terminalSafe as w}from"../../utils/terminal.js";const j={buildClient:S,getProfile:I,makeClient:n(e=>new L(e),"makeClient")},b=n(e=>new Promise(c=>{const r=n(()=>{e.off("end",d),e.off("awaiting_input",i),e.off("agent_error",a),e.off("close",s)},"cleanup"),d=n(u=>{r(),c({kind:"end",payload:u})},"onEnd"),i=n(u=>{r(),c({kind:"awaiting_input",payload:u})},"onAwait"),a=n(u=>{r(),c({kind:"error",payload:u})},"onErr"),s=n(()=>{r(),c({kind:"closed"})},"onClose");e.once("end",d),e.once("awaiting_input",i),e.once("agent_error",a),e.once("close",s)}),"waitForTurnEnd"),D=n((e,c)=>{const r=c?P:x,d=g(r),i=new U({out:r}),a=new Map;let s="idle";const u=n(()=>{s==="status"&&(i.clear(),r.write(`
|
|
2
|
+
`))},"ensureTextStart"),h=n(()=>{s==="text"&&r.write(`
|
|
3
|
+
`),s==="status"&&i.clear()},"ensureLineEndedBeforeBlock");e.on("data",t=>{typeof t.text!="string"||t.text.length===0||(u(),s="text",r.write(w(t.text.replace(/\r$/,""),{preserveLayout:!0})))});const y=n(({rationale:t,method:l,summary:m})=>{const o=[];return t&&o.push({text:`${t}: `}),l&&l!=="commands"&&(o.push({text:l,style:d.gray}),m&&o.push({text:" "})),m&&o.push({text:m,style:d.dim}),o},"formatLine");return e.on("tool_call",t=>{s==="text"&&r.write(`
|
|
4
|
+
`);const{method:l,params:m}=z(t.method,t.params),o=B(t.rationale),f={rationale:o?w(o):void 0,summary:w(N(m)),method:w(l)};a.set(t.id??"",f),s="status",i.set(y(f))}),e.on("tool_result",t=>{const l=a.get(t.id??"")??{method:"?",summary:""};a.delete(t.id??""),s==="text"&&r.write(`
|
|
5
|
+
`),i.done([{text:t.ok?"\u2713":"\u2717",style:t.ok?d.green:d.red},{text:" "},...y(l)]),s="idle"}),e.on("usage",()=>{}),{printEnd:n(t=>{if(h(),s="idle",c){_({type:"end",result:t.result??null});return}const l=F(t);r.write(l?`
|
|
6
|
+
${l}
|
|
7
7
|
`:`
|
|
8
|
-
`)},"printEnd"),clearStatus:
|
|
8
|
+
`)},"printEnd"),clearStatus:n(()=>{h(),s="idle"},"clearStatus"),dispose:n(()=>i.clear(),"dispose")}},"createRenderer"),J=n((e,c)=>{let r=0;const d=n(()=>{if(r+=1,r===1){c(),process.stderr.write(g(process.stderr).gray(`
|
|
9
9
|
(stop sent \u2014 press Ctrl-C again to exit)
|
|
10
|
-
`));try{e.stop()}catch{}}else process.exit(130)},"handler"),
|
|
11
|
-
`))
|
|
10
|
+
`));try{e.stop()}catch{}}else process.exit(130)},"handler"),i=["SIGINT","SIGBREAK"];return i.forEach(a=>process.on(a,d)),()=>i.forEach(a=>process.off(a,d))},"installSigint"),oe=n(async(e,c,r=j)=>{e.cloudProfile!==void 0&&A(e.cloudProfile);const d=!!e.json,i=await r.buildClient(e),a=d?P:x;if(a.write(g(a).dim(`agent \u2192 ${i.server} (token from ${i.source})
|
|
11
|
+
`)),e.cloudProfile)try{await r.getProfile(i,e.cloudProfile)}catch(o){throw o instanceof E&&o.status===404?new $(`Cloud profile "${w(e.cloudProfile)}" was not found for this token. Use the name you passed to --name when you ran \`browserless profile upload\`; run \`browserless profile list\` to see your profiles.`,"cloud-profile-not-found"):o}const s=e.history!==!1&&!c,u=s?await R().catch(()=>[]):[],y=c??T(u,s?o=>v(o):async()=>{},a),t=r.makeClient({server:i.server,token:i.token});await t.connect();const l=D(t,d),m=J(t,l.clearStatus);try{let o=!0;for(;;){let f;if(o&&e.prompt)f=e.prompt;else{try{f=await y.line("> ")}catch{break}if(f===""){if(o)continue;break}}o&&!e.cloudProfile&&G(f)&&a.write(`${M}
|
|
12
|
+
`),o?t.start(H(f,{cloudProfile:e.cloudProfile})):t.send(f),o=!1;let p=await b(t);for(;p.kind==="awaiting_input";){const k=await y.linePrivate("Enter code: ");if(!k){p={kind:"closed"};break}t.send(k),p=await b(t)}if(p.kind==="closed")break;if(p.kind==="error"){if(l.clearStatus(),process.stderr.write(`error: ${w(p.payload.message||p.payload.code||"unknown",{preserveLayout:!0}).replaceAll(`
|
|
12
13
|
`,`
|
|
13
14
|
`)}
|
|
14
|
-
`),
|
|
15
|
+
`),p.payload.retryable!==!0)throw new E("Agent session ended with an error.",0,void 0,"agent-session-error");continue}l.printEnd(p.payload)}}finally{m(),l.dispose(),t.close()}},"runAgentChat");export{oe as runAgentChat};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var i=Object.defineProperty;var
|
|
1
|
+
var i=Object.defineProperty;var o=(e,r)=>i(e,"name",{value:r,configurable:!0});import{addClientFlags as n}from"../../cli-utils/client.js";import{runAgentChat as a}from"./chat.js";const h=o(e=>{const r=e.command("agent [prompt]").description("Interactive chat with the Browserless hosted agent. The LLM runs server-side; the browser is driven for you.").option("--no-history","Disable reading + writing ~/.browserless/agent_history").option("--cloud-profile <name>","Open every browser session with this saved cloud profile (see `browserless profile list`)").action((s,t)=>a({...t,prompt:s}));n(r)},"registerAgent");export{h as registerAgent};
|
package/build/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const o="0.
|
|
1
|
+
const o="0.7.0";export{o as version};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@browserless.io/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Browserless CLI — manage authentication profiles, sessions, and other Browserless features from your terminal.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"commander": "^15.1.0",
|
|
49
|
-
"string-width": "^
|
|
50
|
-
"ws": "^8.
|
|
49
|
+
"string-width": "^9.0.0",
|
|
50
|
+
"ws": "^8.23.0"
|
|
51
51
|
},
|
|
52
52
|
"optionalDependencies": {
|
|
53
53
|
"@napi-rs/keyring": "^2.1.2"
|
|
@@ -63,15 +63,15 @@
|
|
|
63
63
|
"chai": "^6.3.0",
|
|
64
64
|
"chrome-remote-interface": "^0.34.0",
|
|
65
65
|
"esbuild": "^0.28.2",
|
|
66
|
-
"eslint": "^10.
|
|
66
|
+
"eslint": "^10.15.0",
|
|
67
67
|
"globals": "^17.14.0",
|
|
68
68
|
"husky": "^9.1.7",
|
|
69
|
-
"lint-staged": "^17.6.
|
|
69
|
+
"lint-staged": "^17.6.1",
|
|
70
70
|
"mocha": "^12.0.3",
|
|
71
|
-
"prettier": "3.
|
|
71
|
+
"prettier": "3.10.1",
|
|
72
72
|
"sinon": "^22.1.0",
|
|
73
73
|
"typescript": "^6.0.3",
|
|
74
|
-
"typescript-eslint": "^8.
|
|
74
|
+
"typescript-eslint": "^8.73.0"
|
|
75
75
|
},
|
|
76
76
|
"overrides": {
|
|
77
77
|
"mocha": {
|