@react-grab/amp 0.1.0-beta.9 → 0.1.1
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 +13 -4
- package/dist/cli.js +13 -4
- package/dist/client.cjs +1 -1
- package/dist/client.global.js +1 -1
- package/dist/client.js +1 -1
- package/package.json +13 -13
package/dist/cli.cjs
CHANGED
|
@@ -4945,8 +4945,13 @@ ${context.content.join("\n\n")}`;
|
|
|
4945
4945
|
signal
|
|
4946
4946
|
})) {
|
|
4947
4947
|
if (signal.aborted) break;
|
|
4948
|
+
const getBrowserMessageType = (messageType) => {
|
|
4949
|
+
if (messageType === "status") return "agent-status";
|
|
4950
|
+
if (messageType === "error") return "agent-error";
|
|
4951
|
+
return "agent-done";
|
|
4952
|
+
};
|
|
4948
4953
|
sendToBrowser(browserSocket, {
|
|
4949
|
-
type: message.type
|
|
4954
|
+
type: getBrowserMessageType(message.type),
|
|
4950
4955
|
agentId: handler.agentId,
|
|
4951
4956
|
sessionId,
|
|
4952
4957
|
content: message.content
|
|
@@ -5149,9 +5154,13 @@ ${context.content.join("\n\n")}`;
|
|
|
5149
5154
|
} else if (message.type === "agent-status" || message.type === "agent-done" || message.type === "agent-error") {
|
|
5150
5155
|
const messageQueue = sessionMessageQueues.get(message.sessionId);
|
|
5151
5156
|
if (messageQueue) {
|
|
5152
|
-
const
|
|
5157
|
+
const getQueueMessageType = (handlerMessageType) => {
|
|
5158
|
+
if (handlerMessageType === "agent-status") return "status";
|
|
5159
|
+
if (handlerMessageType === "agent-done") return "done";
|
|
5160
|
+
return "error";
|
|
5161
|
+
};
|
|
5153
5162
|
messageQueue.push({
|
|
5154
|
-
type:
|
|
5163
|
+
type: getQueueMessageType(message.type),
|
|
5155
5164
|
content: message.content ?? ""
|
|
5156
5165
|
});
|
|
5157
5166
|
if (message.type === "agent-done" || message.type === "agent-error") {
|
|
@@ -7849,7 +7858,7 @@ async function fkill(inputs, options = {}) {
|
|
|
7849
7858
|
}
|
|
7850
7859
|
}
|
|
7851
7860
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
7852
|
-
var VERSION = "0.1.0
|
|
7861
|
+
var VERSION = "0.1.0";
|
|
7853
7862
|
var checkIfRelayServerIsRunning = async (port, token) => {
|
|
7854
7863
|
try {
|
|
7855
7864
|
const healthUrl = token ? `http://localhost:${port}/health?${RELAY_TOKEN_PARAM}=${encodeURIComponent(token)}` : `http://localhost:${port}/health`;
|
package/dist/cli.js
CHANGED
|
@@ -4934,8 +4934,13 @@ ${context.content.join("\n\n")}`;
|
|
|
4934
4934
|
signal
|
|
4935
4935
|
})) {
|
|
4936
4936
|
if (signal.aborted) break;
|
|
4937
|
+
const getBrowserMessageType = (messageType) => {
|
|
4938
|
+
if (messageType === "status") return "agent-status";
|
|
4939
|
+
if (messageType === "error") return "agent-error";
|
|
4940
|
+
return "agent-done";
|
|
4941
|
+
};
|
|
4937
4942
|
sendToBrowser(browserSocket, {
|
|
4938
|
-
type: message.type
|
|
4943
|
+
type: getBrowserMessageType(message.type),
|
|
4939
4944
|
agentId: handler.agentId,
|
|
4940
4945
|
sessionId,
|
|
4941
4946
|
content: message.content
|
|
@@ -5138,9 +5143,13 @@ ${context.content.join("\n\n")}`;
|
|
|
5138
5143
|
} else if (message.type === "agent-status" || message.type === "agent-done" || message.type === "agent-error") {
|
|
5139
5144
|
const messageQueue = sessionMessageQueues.get(message.sessionId);
|
|
5140
5145
|
if (messageQueue) {
|
|
5141
|
-
const
|
|
5146
|
+
const getQueueMessageType = (handlerMessageType) => {
|
|
5147
|
+
if (handlerMessageType === "agent-status") return "status";
|
|
5148
|
+
if (handlerMessageType === "agent-done") return "done";
|
|
5149
|
+
return "error";
|
|
5150
|
+
};
|
|
5142
5151
|
messageQueue.push({
|
|
5143
|
-
type:
|
|
5152
|
+
type: getQueueMessageType(message.type),
|
|
5144
5153
|
content: message.content ?? ""
|
|
5145
5154
|
});
|
|
5146
5155
|
if (message.type === "agent-done" || message.type === "agent-error") {
|
|
@@ -7838,7 +7847,7 @@ async function fkill(inputs, options = {}) {
|
|
|
7838
7847
|
}
|
|
7839
7848
|
}
|
|
7840
7849
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
7841
|
-
var VERSION = "0.1.0
|
|
7850
|
+
var VERSION = "0.1.0";
|
|
7842
7851
|
var checkIfRelayServerIsRunning = async (port, token) => {
|
|
7843
7852
|
try {
|
|
7844
7853
|
const healthUrl = token ? `http://localhost:${port}/health?${RELAY_TOKEN_PARAM}=${encodeURIComponent(token)}` : `http://localhost:${port}/health`;
|
package/dist/client.cjs
CHANGED
|
@@ -210,7 +210,7 @@ var createRelayAgentProvider = (options) => {
|
|
|
210
210
|
rejectNextMessage = null;
|
|
211
211
|
}
|
|
212
212
|
};
|
|
213
|
-
signal.addEventListener("abort", handleAbort);
|
|
213
|
+
signal.addEventListener("abort", handleAbort, { once: true });
|
|
214
214
|
const handleConnectionChange = (connected) => {
|
|
215
215
|
if (!connected && !isDone) {
|
|
216
216
|
errorMessage = "Relay connection lost";
|
package/dist/client.global.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var ReactGrabAmp=(function(exports){'use strict';var q=4722,x=3e3,D="token",G=(i={})=>{let n=i.serverUrl??`ws://localhost:${q}`,c=i.autoReconnect??true,E=i.reconnectIntervalMs??x,h=i.token,s=null,f=false,w=[],p=null,t=null,o=null,A=false,y=new Set,g=new Set,r=new Set,d=()=>{!c||p||A||(p=setTimeout(()=>{p=null,C().catch(()=>{});},E));},l=e=>{try{let a=JSON.parse(e.data);if(a.type==="handlers"&&a.handlers){w=a.handlers;for(let m of g)m(w);}for(let m of y)m(a);}catch{}},C=()=>s?.readyState===WebSocket.OPEN?Promise.resolve():t||(A=false,t=new Promise((e,a)=>{o=a;let m=h?`${n}?${D}=${encodeURIComponent(h)}`:n;s=new WebSocket(m),s.onopen=()=>{t=null,o=null,f=true;for(let S of r)S(true);e();},s.onmessage=l,s.onclose=()=>{o&&(o(new Error("WebSocket connection closed")),o=null),t=null,f=false,w=[];for(let S of g)S(w);for(let S of r)S(false);d();},s.onerror=()=>{t=null,o=null,f=false,a(new Error("WebSocket connection failed"));};}),t),v=()=>{A=true,p&&(clearTimeout(p),p=null),o&&(o(new Error("Connection aborted")),o=null),t=null,s?.close(),s=null,f=false,w=[];},M=()=>f,R=e=>s?.readyState===WebSocket.OPEN?(s.send(JSON.stringify(e)),true):false;return {connect:C,disconnect:v,isConnected:M,sendAgentRequest:(e,a)=>R({type:"agent-request",agentId:e,sessionId:a.sessionId,context:a}),abortAgent:(e,a)=>{R({type:"agent-abort",agentId:e,sessionId:a});},undoAgent:(e,a)=>R({type:"agent-undo",agentId:e,sessionId:a}),redoAgent:(e,a)=>R({type:"agent-redo",agentId:e,sessionId:a}),onMessage:e=>(y.add(e),()=>y.delete(e)),onHandlersChange:e=>(g.add(e),()=>g.delete(e)),onConnectionChange:e=>(r.add(e),queueMicrotask(()=>{r.has(e)&&e(f);}),()=>r.delete(e)),getAvailableHandlers:()=>w}},I=i=>{let{relayClient:n,agentId:c}=i,E=async()=>{if(!n.isConnected())try{await n.connect();}catch{return false}return n.getAvailableHandlers().includes(c)},h=async function*(t,o){if(o.aborted)throw new DOMException("Aborted","AbortError");yield "Connecting\u2026";let A=t.sessionId??`session-${Date.now()}-${Math.random().toString(36).slice(2)}`,y={...t,sessionId:A},g=[],r=null,d=null,l=false,C=null,v=()=>{n.abortAgent(c,A),l=true,r&&(r({value:void 0,done:true}),r=null,d=null);};o.addEventListener("abort",v);let M=u=>{!u&&!l&&(C="Relay connection lost",l=true,d&&(d(new Error(C)),r=null,d=null));},R=n.onConnectionChange(M),P=n.onMessage(u=>{if(u.sessionId===A)if(u.type==="agent-status"&&u.content){if(g.push(u.content),r){let b=g.shift();b!==void 0&&(r({value:b,done:false}),r=null,d=null);}}else u.type==="agent-done"?(l=true,r&&(r({value:void 0,done:true}),r=null,d=null)):u.type==="agent-error"&&(C=u.content??"Unknown error",l=true,d&&(d(new Error(C)),r=null,d=null));});if(!n.isConnected())throw R(),P(),o.removeEventListener("abort",v),new Error("Relay connection is not open");if(!n.sendAgentRequest(c,y))throw R(),P(),o.removeEventListener("abort",v),new Error("Failed to send agent request: connection not open");try{for(;;){if(g.length>0){let b=g.shift();b!==void 0&&(yield b);continue}if(l||o.aborted)break;let u=await new Promise((b,L)=>{r=b,d=L;});if(u.done)break;yield u.value;}if(C)throw new Error(C)}finally{o.removeEventListener("abort",v),R(),P();}},s=async t=>{n.abortAgent(c,t);},f=t=>new Promise((o,A)=>{let y=false,g=()=>{y||(y=true,r(),d());},r=n.onMessage(l=>{l.sessionId===t&&(g(),l.type==="agent-done"?o():l.type==="agent-error"&&A(new Error(l.content??"Operation failed")));}),d=n.onConnectionChange(l=>{l||(g(),A(new Error("Connection lost while waiting for operation response")));});});return {send:h,abort:s,undo:async()=>{let t=`undo-${c}-${Date.now()}-${Math.random().toString(36).slice(2)}`;if(!n.undoAgent(c,t))throw new Error("Failed to send undo request: connection not open");return f(t)},redo:async()=>{let t=`redo-${c}-${Date.now()}-${Math.random().toString(36).slice(2)}`;if(!n.redoAgent(c,t))throw new Error("Failed to send redo request: connection not open");return f(t)},checkConnection:E,supportsResume:true,supportsFollowUp:true}},_=null,k=()=>typeof window>"u"?null:window.__REACT_GRAB_RELAY__?(_=window.__REACT_GRAB_RELAY__,_):(_||(_=G(),window.__REACT_GRAB_RELAY__=_),_);var O="amp",T=i=>typeof i=="object"&&i!==null&&"registerPlugin"in i,Y=(i={})=>{let n=i.relayClient??k();if(!n)throw new Error("RelayClient is required in browser environments");return I({relayClient:n,agentId:O})},N=async()=>{if(typeof window>"u")return;let i=k();if(!i)return;try{await i.connect();}catch{return}let n=I({relayClient:i,agentId:O}),c=s=>{let f={provider:n,storage:sessionStorage},w={name:"amp-agent",actions:[{id:"edit-with-amp",label:"Edit with Amp",shortcut:"Enter",onAction:p=>{p.enterPromptMode?.(f);},agent:f}]};s.registerPlugin(w);},E=window.__REACT_GRAB__;if(T(E)){c(E);return}window.addEventListener("react-grab:init",s=>{s instanceof CustomEvent&&T(s.detail)&&c(s.detail);},{once:true});let h=window.__REACT_GRAB__;T(h)&&c(h);};N();
|
|
1
|
+
var ReactGrabAmp=(function(exports){'use strict';var q=4722,x=3e3,D="token",G=(i={})=>{let n=i.serverUrl??`ws://localhost:${q}`,c=i.autoReconnect??true,E=i.reconnectIntervalMs??x,h=i.token,s=null,f=false,w=[],p=null,t=null,o=null,A=false,y=new Set,g=new Set,r=new Set,d=()=>{!c||p||A||(p=setTimeout(()=>{p=null,C().catch(()=>{});},E));},l=e=>{try{let a=JSON.parse(e.data);if(a.type==="handlers"&&a.handlers){w=a.handlers;for(let m of g)m(w);}for(let m of y)m(a);}catch{}},C=()=>s?.readyState===WebSocket.OPEN?Promise.resolve():t||(A=false,t=new Promise((e,a)=>{o=a;let m=h?`${n}?${D}=${encodeURIComponent(h)}`:n;s=new WebSocket(m),s.onopen=()=>{t=null,o=null,f=true;for(let S of r)S(true);e();},s.onmessage=l,s.onclose=()=>{o&&(o(new Error("WebSocket connection closed")),o=null),t=null,f=false,w=[];for(let S of g)S(w);for(let S of r)S(false);d();},s.onerror=()=>{t=null,o=null,f=false,a(new Error("WebSocket connection failed"));};}),t),v=()=>{A=true,p&&(clearTimeout(p),p=null),o&&(o(new Error("Connection aborted")),o=null),t=null,s?.close(),s=null,f=false,w=[];},M=()=>f,R=e=>s?.readyState===WebSocket.OPEN?(s.send(JSON.stringify(e)),true):false;return {connect:C,disconnect:v,isConnected:M,sendAgentRequest:(e,a)=>R({type:"agent-request",agentId:e,sessionId:a.sessionId,context:a}),abortAgent:(e,a)=>{R({type:"agent-abort",agentId:e,sessionId:a});},undoAgent:(e,a)=>R({type:"agent-undo",agentId:e,sessionId:a}),redoAgent:(e,a)=>R({type:"agent-redo",agentId:e,sessionId:a}),onMessage:e=>(y.add(e),()=>y.delete(e)),onHandlersChange:e=>(g.add(e),()=>g.delete(e)),onConnectionChange:e=>(r.add(e),queueMicrotask(()=>{r.has(e)&&e(f);}),()=>r.delete(e)),getAvailableHandlers:()=>w}},I=i=>{let{relayClient:n,agentId:c}=i,E=async()=>{if(!n.isConnected())try{await n.connect();}catch{return false}return n.getAvailableHandlers().includes(c)},h=async function*(t,o){if(o.aborted)throw new DOMException("Aborted","AbortError");yield "Connecting\u2026";let A=t.sessionId??`session-${Date.now()}-${Math.random().toString(36).slice(2)}`,y={...t,sessionId:A},g=[],r=null,d=null,l=false,C=null,v=()=>{n.abortAgent(c,A),l=true,r&&(r({value:void 0,done:true}),r=null,d=null);};o.addEventListener("abort",v,{once:true});let M=u=>{!u&&!l&&(C="Relay connection lost",l=true,d&&(d(new Error(C)),r=null,d=null));},R=n.onConnectionChange(M),P=n.onMessage(u=>{if(u.sessionId===A)if(u.type==="agent-status"&&u.content){if(g.push(u.content),r){let b=g.shift();b!==void 0&&(r({value:b,done:false}),r=null,d=null);}}else u.type==="agent-done"?(l=true,r&&(r({value:void 0,done:true}),r=null,d=null)):u.type==="agent-error"&&(C=u.content??"Unknown error",l=true,d&&(d(new Error(C)),r=null,d=null));});if(!n.isConnected())throw R(),P(),o.removeEventListener("abort",v),new Error("Relay connection is not open");if(!n.sendAgentRequest(c,y))throw R(),P(),o.removeEventListener("abort",v),new Error("Failed to send agent request: connection not open");try{for(;;){if(g.length>0){let b=g.shift();b!==void 0&&(yield b);continue}if(l||o.aborted)break;let u=await new Promise((b,L)=>{r=b,d=L;});if(u.done)break;yield u.value;}if(C)throw new Error(C)}finally{o.removeEventListener("abort",v),R(),P();}},s=async t=>{n.abortAgent(c,t);},f=t=>new Promise((o,A)=>{let y=false,g=()=>{y||(y=true,r(),d());},r=n.onMessage(l=>{l.sessionId===t&&(g(),l.type==="agent-done"?o():l.type==="agent-error"&&A(new Error(l.content??"Operation failed")));}),d=n.onConnectionChange(l=>{l||(g(),A(new Error("Connection lost while waiting for operation response")));});});return {send:h,abort:s,undo:async()=>{let t=`undo-${c}-${Date.now()}-${Math.random().toString(36).slice(2)}`;if(!n.undoAgent(c,t))throw new Error("Failed to send undo request: connection not open");return f(t)},redo:async()=>{let t=`redo-${c}-${Date.now()}-${Math.random().toString(36).slice(2)}`;if(!n.redoAgent(c,t))throw new Error("Failed to send redo request: connection not open");return f(t)},checkConnection:E,supportsResume:true,supportsFollowUp:true}},_=null,k=()=>typeof window>"u"?null:window.__REACT_GRAB_RELAY__?(_=window.__REACT_GRAB_RELAY__,_):(_||(_=G(),window.__REACT_GRAB_RELAY__=_),_);var O="amp",T=i=>typeof i=="object"&&i!==null&&"registerPlugin"in i,Y=(i={})=>{let n=i.relayClient??k();if(!n)throw new Error("RelayClient is required in browser environments");return I({relayClient:n,agentId:O})},N=async()=>{if(typeof window>"u")return;let i=k();if(!i)return;try{await i.connect();}catch{return}let n=I({relayClient:i,agentId:O}),c=s=>{let f={provider:n,storage:sessionStorage},w={name:"amp-agent",actions:[{id:"edit-with-amp",label:"Edit with Amp",shortcut:"Enter",onAction:p=>{p.enterPromptMode?.(f);},agent:f}]};s.registerPlugin(w);},E=window.__REACT_GRAB__;if(T(E)){c(E);return}window.addEventListener("react-grab:init",s=>{s instanceof CustomEvent&&T(s.detail)&&c(s.detail);},{once:true});let h=window.__REACT_GRAB__;T(h)&&c(h);};N();
|
|
2
2
|
exports.attachAgent=N;exports.createAmpAgentProvider=Y;return exports;})({});
|
package/dist/client.js
CHANGED
|
@@ -208,7 +208,7 @@ var createRelayAgentProvider = (options) => {
|
|
|
208
208
|
rejectNextMessage = null;
|
|
209
209
|
}
|
|
210
210
|
};
|
|
211
|
-
signal.addEventListener("abort", handleAbort);
|
|
211
|
+
signal.addEventListener("abort", handleAbort, { once: true });
|
|
212
212
|
const handleConnectionChange = (connected) => {
|
|
213
213
|
if (!connected && !isDone) {
|
|
214
214
|
errorMessage = "Relay connection lost";
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-grab/amp",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "0.1.1",
|
|
5
4
|
"bin": {
|
|
6
5
|
"react-grab-amp": "./dist/cli.cjs"
|
|
7
6
|
},
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"type": "module",
|
|
11
|
+
"browser": "dist/client.global.js",
|
|
8
12
|
"exports": {
|
|
9
13
|
"./client": {
|
|
10
14
|
"types": "./dist/client.d.ts",
|
|
@@ -19,20 +23,16 @@
|
|
|
19
23
|
"./dist/*": "./dist/*.js",
|
|
20
24
|
"./dist/*.js": "./dist/*.js"
|
|
21
25
|
},
|
|
22
|
-
"browser": "dist/client.global.js",
|
|
23
|
-
"files": [
|
|
24
|
-
"dist"
|
|
25
|
-
],
|
|
26
|
-
"devDependencies": {
|
|
27
|
-
"@types/node": "^22.10.7",
|
|
28
|
-
"tsup": "^8.4.0",
|
|
29
|
-
"@react-grab/utils": "0.1.0-beta.9"
|
|
30
|
-
},
|
|
31
26
|
"dependencies": {
|
|
32
27
|
"@sourcegraph/amp": "^0.0.1767830505-ga62310",
|
|
33
28
|
"@sourcegraph/amp-sdk": "^0.1.0-20251210081226-g90e3892",
|
|
34
|
-
"react-grab": "0.1.
|
|
35
|
-
"
|
|
29
|
+
"@react-grab/relay": "0.1.1",
|
|
30
|
+
"react-grab": "0.1.1"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "^22.10.7",
|
|
34
|
+
"tsup": "^8.4.0",
|
|
35
|
+
"@react-grab/utils": "0.1.1"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"dev": "tsup --watch",
|