@react-grab/gemini 0.0.91 → 0.0.93
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/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/client.cjs +1 -1
- package/dist/client.global.js +3 -3
- package/dist/client.js +1 -1
- package/dist/server.cjs +45 -13
- package/dist/server.js +45 -13
- package/package.json +3 -3
package/dist/cli.cjs
CHANGED
|
@@ -7138,7 +7138,7 @@ var import_picocolors = __toESM(require_picocolors());
|
|
|
7138
7138
|
var DEFAULT_PORT = 8567;
|
|
7139
7139
|
|
|
7140
7140
|
// src/cli.ts
|
|
7141
|
-
var VERSION = "0.0.
|
|
7141
|
+
var VERSION = "0.0.93";
|
|
7142
7142
|
var serverPath = path2.join(__dirname, "server.cjs");
|
|
7143
7143
|
execa(process.execPath, [serverPath], {
|
|
7144
7144
|
detached: true,
|
package/dist/cli.js
CHANGED
|
@@ -7130,7 +7130,7 @@ var import_picocolors = __toESM(require_picocolors());
|
|
|
7130
7130
|
var DEFAULT_PORT = 8567;
|
|
7131
7131
|
|
|
7132
7132
|
// src/cli.ts
|
|
7133
|
-
var VERSION = "0.0.
|
|
7133
|
+
var VERSION = "0.0.93";
|
|
7134
7134
|
var serverPath = join(__dirname, "server.cjs");
|
|
7135
7135
|
execa(process.execPath, [serverPath], {
|
|
7136
7136
|
detached: true,
|
package/dist/client.cjs
CHANGED
|
@@ -71,7 +71,7 @@ var getStoredAgentContext = (storage, sessionId, storageKey = STORAGE_KEY) => {
|
|
|
71
71
|
if (!isRecord(context)) throw new Error(`Session ${sessionId} is invalid`);
|
|
72
72
|
const content = context.content;
|
|
73
73
|
const prompt = context.prompt;
|
|
74
|
-
if (
|
|
74
|
+
if (!Array.isArray(content) || typeof prompt !== "string") {
|
|
75
75
|
throw new Error(`Session ${sessionId} is invalid`);
|
|
76
76
|
}
|
|
77
77
|
const options = context.options;
|
package/dist/client.global.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var ReactGrabGemini=(function(exports){'use strict';var A=5e3,v="react-grab:agent-sessions",C=e=>{let t="",n="";for(let
|
|
2
|
-
`))
|
|
1
|
+
var ReactGrabGemini=(function(exports){'use strict';var A=5e3,v="react-grab:agent-sessions",C=e=>{let t="",n="";for(let o of e.split(`
|
|
2
|
+
`))o.startsWith("event:")?t=o.slice(6).trim():o.startsWith("data:")&&(n=o.slice(5).trim());return {eventType:t,data:n}},T=async function*(e,t){let n=e.getReader(),o=new TextDecoder,r="",s=false,a=()=>{s=true,n.cancel().catch(()=>{});};t.addEventListener("abort",a);try{if(t.aborted)throw new DOMException("Aborted","AbortError");for(;;){let d=await n.read();if(s||t.aborted)throw new DOMException("Aborted","AbortError");let{done:i,value:l}=d;l&&(r+=o.decode(l,{stream:!0}));let c;for(;(c=r.indexOf(`
|
|
3
3
|
|
|
4
|
-
`))!==-1;){let{eventType:f,data:p}=C(
|
|
4
|
+
`))!==-1;){let{eventType:f,data:p}=C(r.slice(0,c));if(r=r.slice(c+2),f==="done")return;if(f==="error")throw new Error(p||"Agent error");p&&(yield p);}if(i)break}}finally{t.removeEventListener("abort",a);try{n.releaseLock();}catch{}}},g=e=>typeof e=="object"&&e!==null,E=(e,t,n=v)=>{let o=e.getItem(n);if(!o)throw new Error("No sessions to resume");let r;try{r=JSON.parse(o);}catch{throw new Error("Failed to parse stored sessions")}if(!g(r))throw new Error("Invalid stored sessions");let s=r[t];if(!g(s))throw new Error(`Session ${t} not found`);let a=s.context;if(!g(a))throw new Error(`Session ${t} is invalid`);let d=a.content,i=a.prompt;if(!Array.isArray(d)||typeof i!="string")throw new Error(`Session ${t} is invalid`);let l=a.options,c=a.sessionId;return {content:d,prompt:i,options:l,sessionId:typeof c=="string"?c:void 0}},y=async function*(e,t,n){let o=Date.now(),r=t.sessionId,s=e.pollIntervalMs??100,a=`${e.serverUrl}${e.agentPath??"/agent"}`,d=()=>{if(!r)return;let i=e.abortPath?.(r)??`/abort/${r}`;fetch(`${e.serverUrl}${i}`,{method:"POST"}).catch(()=>{});};n.addEventListener("abort",d);try{let i=await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),signal:n});if(!i.ok)throw new Error(`Server error: ${i.status}`);if(!i.body)throw new Error("No response body");let l=T(i.body,n)[Symbol.asyncIterator](),c=!1,f=l.next(),p=null;for(;!c;){let S=await Promise.race([f.then(u=>({type:"status",iteratorResult:u})),new Promise(u=>setTimeout(()=>u({type:"timeout"}),s))]),m=(Date.now()-o)/1e3;if(S.type==="status"){let u=S.iteratorResult;c=u.done??!1,!c&&u.value&&(p=u.value,f=l.next());}p===e.completedStatus?yield `Completed in ${m.toFixed(1)}s`:p?yield `${p} ${m.toFixed(1)}s`:yield `Working\u2026 ${m.toFixed(1)}s`;}}finally{n.removeEventListener("abort",d);}},b=(e,t=A)=>{let n=null;return async()=>{let o=Date.now();if(n&&o-n.timestamp<t)return n.result;try{let r=await e();return n={result:r,timestamp:o},r}catch{return n={result:false,timestamp:o},false}}};var h="Completed successfully";var x=`http://localhost:${8567}`,w=e=>typeof e=="object"&&e!==null&&"setAgent"in e,_=(e={})=>{let{serverUrl:t=x,getOptions:n}=e,o=s=>({...n?.()??{},...s??{}}),r=b(async()=>(await fetch(`${t}/health`,{method:"GET"})).ok,A);return {send:async function*(s,a){let d={...s,options:o(s.options)};yield*y({serverUrl:t,completedStatus:h},d,a);},resume:async function*(s,a,d){let i=E(d,s),l={content:i.content,prompt:i.prompt,options:i.options,sessionId:i.sessionId??s},c={...l,options:o(l.options)};yield "Resuming...",yield*y({serverUrl:t,completedStatus:h},c,a);},supportsResume:true,supportsFollowUp:true,checkConnection:r,abort:async s=>{try{await fetch(`${t}/abort/${s}`,{method:"POST"});}catch{}},undo:async()=>{try{await fetch(`${t}/undo`,{method:"POST"});}catch{}}}},R=async()=>{if(typeof window>"u")return;let e=_(),t=r=>{r.setAgent({provider:e,storage:sessionStorage});},n=window.__REACT_GRAB__;if(w(n)){t(n);return}window.addEventListener("react-grab:init",r=>{r instanceof CustomEvent&&w(r.detail)&&t(r.detail);},{once:true});let o=window.__REACT_GRAB__;w(o)&&t(o);};R();
|
|
5
5
|
exports.attachAgent=R;exports.createGeminiAgentProvider=_;return exports;})({});
|
package/dist/client.js
CHANGED
|
@@ -69,7 +69,7 @@ var getStoredAgentContext = (storage, sessionId, storageKey = STORAGE_KEY) => {
|
|
|
69
69
|
if (!isRecord(context)) throw new Error(`Session ${sessionId} is invalid`);
|
|
70
70
|
const content = context.content;
|
|
71
71
|
const prompt = context.prompt;
|
|
72
|
-
if (
|
|
72
|
+
if (!Array.isArray(content) || typeof prompt !== "string") {
|
|
73
73
|
throw new Error(`Session ${sessionId} is invalid`);
|
|
74
74
|
}
|
|
75
75
|
const options = context.options;
|
package/dist/server.cjs
CHANGED
|
@@ -12129,7 +12129,7 @@ Check that the command is executable: chmod +x $(which ${commandName})`;
|
|
|
12129
12129
|
};
|
|
12130
12130
|
|
|
12131
12131
|
// src/server.ts
|
|
12132
|
-
var VERSION = "0.0.
|
|
12132
|
+
var VERSION = "0.0.93";
|
|
12133
12133
|
try {
|
|
12134
12134
|
fetch(
|
|
12135
12135
|
`https://www.react-grab.com/api/version?source=gemini&t=${Date.now()}`
|
|
@@ -12331,21 +12331,53 @@ var createServer = () => {
|
|
|
12331
12331
|
const { content, prompt, options, sessionId } = body;
|
|
12332
12332
|
const geminiSessionId = sessionId ? geminiSessionMap.get(sessionId) : void 0;
|
|
12333
12333
|
const isFollowUp = Boolean(geminiSessionId);
|
|
12334
|
-
const
|
|
12335
|
-
|
|
12336
|
-
${content}`;
|
|
12334
|
+
const contentItems = Array.isArray(content) ? content : [content];
|
|
12337
12335
|
return streamSSE(context, async (stream2) => {
|
|
12338
|
-
|
|
12339
|
-
|
|
12340
|
-
|
|
12341
|
-
|
|
12342
|
-
|
|
12336
|
+
if (isFollowUp) {
|
|
12337
|
+
for await (const message of runAgent(prompt, {
|
|
12338
|
+
...options,
|
|
12339
|
+
sessionId
|
|
12340
|
+
})) {
|
|
12341
|
+
if (message.type === "error") {
|
|
12342
|
+
await stream2.writeSSE({
|
|
12343
|
+
data: `Error: ${message.content}`,
|
|
12344
|
+
event: "error"
|
|
12345
|
+
});
|
|
12346
|
+
} else {
|
|
12347
|
+
await stream2.writeSSE({
|
|
12348
|
+
data: message.content,
|
|
12349
|
+
event: message.type
|
|
12350
|
+
});
|
|
12351
|
+
}
|
|
12352
|
+
}
|
|
12353
|
+
return;
|
|
12354
|
+
}
|
|
12355
|
+
for (let i2 = 0; i2 < contentItems.length; i2++) {
|
|
12356
|
+
const elementContent = contentItems[i2];
|
|
12357
|
+
const userPrompt = `${prompt}
|
|
12358
|
+
|
|
12359
|
+
${elementContent}`;
|
|
12360
|
+
if (contentItems.length > 1) {
|
|
12343
12361
|
await stream2.writeSSE({
|
|
12344
|
-
data: `
|
|
12345
|
-
event: "
|
|
12362
|
+
data: `Processing element ${i2 + 1} of ${contentItems.length}...`,
|
|
12363
|
+
event: "status"
|
|
12346
12364
|
});
|
|
12347
|
-
}
|
|
12348
|
-
|
|
12365
|
+
}
|
|
12366
|
+
for await (const message of runAgent(userPrompt, {
|
|
12367
|
+
...options,
|
|
12368
|
+
sessionId
|
|
12369
|
+
})) {
|
|
12370
|
+
if (message.type === "error") {
|
|
12371
|
+
await stream2.writeSSE({
|
|
12372
|
+
data: `Error: ${message.content}`,
|
|
12373
|
+
event: "error"
|
|
12374
|
+
});
|
|
12375
|
+
} else {
|
|
12376
|
+
await stream2.writeSSE({
|
|
12377
|
+
data: message.content,
|
|
12378
|
+
event: message.type
|
|
12379
|
+
});
|
|
12380
|
+
}
|
|
12349
12381
|
}
|
|
12350
12382
|
}
|
|
12351
12383
|
});
|
package/dist/server.js
CHANGED
|
@@ -12117,7 +12117,7 @@ Check that the command is executable: chmod +x $(which ${commandName})`;
|
|
|
12117
12117
|
};
|
|
12118
12118
|
|
|
12119
12119
|
// src/server.ts
|
|
12120
|
-
var VERSION = "0.0.
|
|
12120
|
+
var VERSION = "0.0.93";
|
|
12121
12121
|
try {
|
|
12122
12122
|
fetch(
|
|
12123
12123
|
`https://www.react-grab.com/api/version?source=gemini&t=${Date.now()}`
|
|
@@ -12319,21 +12319,53 @@ var createServer = () => {
|
|
|
12319
12319
|
const { content, prompt, options, sessionId } = body;
|
|
12320
12320
|
const geminiSessionId = sessionId ? geminiSessionMap.get(sessionId) : void 0;
|
|
12321
12321
|
const isFollowUp = Boolean(geminiSessionId);
|
|
12322
|
-
const
|
|
12323
|
-
|
|
12324
|
-
${content}`;
|
|
12322
|
+
const contentItems = Array.isArray(content) ? content : [content];
|
|
12325
12323
|
return streamSSE(context, async (stream2) => {
|
|
12326
|
-
|
|
12327
|
-
|
|
12328
|
-
|
|
12329
|
-
|
|
12330
|
-
|
|
12324
|
+
if (isFollowUp) {
|
|
12325
|
+
for await (const message of runAgent(prompt, {
|
|
12326
|
+
...options,
|
|
12327
|
+
sessionId
|
|
12328
|
+
})) {
|
|
12329
|
+
if (message.type === "error") {
|
|
12330
|
+
await stream2.writeSSE({
|
|
12331
|
+
data: `Error: ${message.content}`,
|
|
12332
|
+
event: "error"
|
|
12333
|
+
});
|
|
12334
|
+
} else {
|
|
12335
|
+
await stream2.writeSSE({
|
|
12336
|
+
data: message.content,
|
|
12337
|
+
event: message.type
|
|
12338
|
+
});
|
|
12339
|
+
}
|
|
12340
|
+
}
|
|
12341
|
+
return;
|
|
12342
|
+
}
|
|
12343
|
+
for (let i2 = 0; i2 < contentItems.length; i2++) {
|
|
12344
|
+
const elementContent = contentItems[i2];
|
|
12345
|
+
const userPrompt = `${prompt}
|
|
12346
|
+
|
|
12347
|
+
${elementContent}`;
|
|
12348
|
+
if (contentItems.length > 1) {
|
|
12331
12349
|
await stream2.writeSSE({
|
|
12332
|
-
data: `
|
|
12333
|
-
event: "
|
|
12350
|
+
data: `Processing element ${i2 + 1} of ${contentItems.length}...`,
|
|
12351
|
+
event: "status"
|
|
12334
12352
|
});
|
|
12335
|
-
}
|
|
12336
|
-
|
|
12353
|
+
}
|
|
12354
|
+
for await (const message of runAgent(userPrompt, {
|
|
12355
|
+
...options,
|
|
12356
|
+
sessionId
|
|
12357
|
+
})) {
|
|
12358
|
+
if (message.type === "error") {
|
|
12359
|
+
await stream2.writeSSE({
|
|
12360
|
+
data: `Error: ${message.content}`,
|
|
12361
|
+
event: "error"
|
|
12362
|
+
});
|
|
12363
|
+
} else {
|
|
12364
|
+
await stream2.writeSSE({
|
|
12365
|
+
data: message.content,
|
|
12366
|
+
event: message.type
|
|
12367
|
+
});
|
|
12368
|
+
}
|
|
12337
12369
|
}
|
|
12338
12370
|
}
|
|
12339
12371
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-grab/gemini",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.93",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"react-grab-gemini": "./dist/cli.cjs"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/node": "^22.10.7",
|
|
28
28
|
"tsup": "^8.4.0",
|
|
29
|
-
"@react-grab/utils": "0.0.
|
|
29
|
+
"@react-grab/utils": "0.0.93"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@hono/node-server": "^1.19.6",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"fkill": "^9.0.0",
|
|
35
35
|
"hono": "^4.0.0",
|
|
36
36
|
"picocolors": "^1.1.1",
|
|
37
|
-
"react-grab": "0.0.
|
|
37
|
+
"react-grab": "0.0.93"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"dev": "tsup --watch",
|