@react-grab/relay 0.1.15 → 0.1.16
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/client.cjs +64 -0
- package/dist/client.d.cts +17 -1
- package/dist/client.d.ts +17 -1
- package/dist/client.js +64 -1
- package/dist/connection.cjs +9 -1
- package/dist/connection.d.cts +2 -1
- package/dist/connection.d.ts +2 -1
- package/dist/connection.js +9 -2
- package/dist/index.cjs +73 -1
- package/dist/index.d.cts +18 -2
- package/dist/index.d.ts +18 -2
- package/dist/index.js +72 -2
- package/package.json +2 -2
package/dist/client.cjs
CHANGED
|
@@ -376,7 +376,71 @@ var getDefaultRelayClient = () => {
|
|
|
376
376
|
}
|
|
377
377
|
return defaultRelayClient;
|
|
378
378
|
};
|
|
379
|
+
var isReactGrabApi = (value) => typeof value === "object" && value !== null && "registerPlugin" in value;
|
|
380
|
+
var createProviderClientPlugin = (config) => {
|
|
381
|
+
const createAgentProvider = (providerOptions = {}) => {
|
|
382
|
+
const relayClient = providerOptions.relayClient ?? getDefaultRelayClient();
|
|
383
|
+
if (!relayClient) {
|
|
384
|
+
throw new Error("RelayClient is required in browser environments");
|
|
385
|
+
}
|
|
386
|
+
return createRelayAgentProvider({
|
|
387
|
+
relayClient,
|
|
388
|
+
agentId: config.agentId
|
|
389
|
+
});
|
|
390
|
+
};
|
|
391
|
+
const attachAgent = async () => {
|
|
392
|
+
if (typeof window === "undefined") return;
|
|
393
|
+
const relayClient = getDefaultRelayClient();
|
|
394
|
+
if (!relayClient) return;
|
|
395
|
+
try {
|
|
396
|
+
await relayClient.connect();
|
|
397
|
+
} catch {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
const provider = createRelayAgentProvider({
|
|
401
|
+
relayClient,
|
|
402
|
+
agentId: config.agentId
|
|
403
|
+
});
|
|
404
|
+
const attach = (api) => {
|
|
405
|
+
const agent = { provider, storage: sessionStorage };
|
|
406
|
+
api.registerPlugin({
|
|
407
|
+
name: config.pluginName,
|
|
408
|
+
actions: [
|
|
409
|
+
{
|
|
410
|
+
id: config.actionId,
|
|
411
|
+
label: config.actionLabel,
|
|
412
|
+
shortcut: "Enter",
|
|
413
|
+
onAction: (actionContext) => {
|
|
414
|
+
actionContext.enterPromptMode?.(agent);
|
|
415
|
+
},
|
|
416
|
+
agent
|
|
417
|
+
}
|
|
418
|
+
]
|
|
419
|
+
});
|
|
420
|
+
};
|
|
421
|
+
const existingApi = window.__REACT_GRAB__;
|
|
422
|
+
if (isReactGrabApi(existingApi)) {
|
|
423
|
+
attach(existingApi);
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
window.addEventListener(
|
|
427
|
+
"react-grab:init",
|
|
428
|
+
(event) => {
|
|
429
|
+
if (!(event instanceof CustomEvent)) return;
|
|
430
|
+
if (!isReactGrabApi(event.detail)) return;
|
|
431
|
+
attach(event.detail);
|
|
432
|
+
},
|
|
433
|
+
{ once: true }
|
|
434
|
+
);
|
|
435
|
+
const apiAfterListener = window.__REACT_GRAB__;
|
|
436
|
+
if (isReactGrabApi(apiAfterListener)) {
|
|
437
|
+
attach(apiAfterListener);
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
return { createAgentProvider, attachAgent };
|
|
441
|
+
};
|
|
379
442
|
|
|
443
|
+
exports.createProviderClientPlugin = createProviderClientPlugin;
|
|
380
444
|
exports.createRelayAgentProvider = createRelayAgentProvider;
|
|
381
445
|
exports.createRelayClient = createRelayClient;
|
|
382
446
|
exports.getDefaultRelayClient = getDefaultRelayClient;
|
package/dist/client.d.cts
CHANGED
|
@@ -34,11 +34,27 @@ interface CreateRelayAgentProviderOptions {
|
|
|
34
34
|
agentId: string;
|
|
35
35
|
}
|
|
36
36
|
declare const createRelayAgentProvider: (options: CreateRelayAgentProviderOptions) => AgentProvider;
|
|
37
|
+
interface ReactGrabApi {
|
|
38
|
+
registerPlugin: (plugin: unknown) => void;
|
|
39
|
+
}
|
|
37
40
|
declare global {
|
|
38
41
|
interface Window {
|
|
39
42
|
__REACT_GRAB_RELAY__?: RelayClient;
|
|
43
|
+
__REACT_GRAB__?: ReactGrabApi;
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
46
|
declare const getDefaultRelayClient: () => RelayClient | null;
|
|
47
|
+
interface ProviderPluginConfig {
|
|
48
|
+
agentId: string;
|
|
49
|
+
pluginName: string;
|
|
50
|
+
actionId: string;
|
|
51
|
+
actionLabel: string;
|
|
52
|
+
}
|
|
53
|
+
declare const createProviderClientPlugin: (config: ProviderPluginConfig) => {
|
|
54
|
+
createAgentProvider: (providerOptions?: {
|
|
55
|
+
relayClient?: RelayClient;
|
|
56
|
+
}) => AgentProvider;
|
|
57
|
+
attachAgent: () => Promise<void>;
|
|
58
|
+
};
|
|
43
59
|
|
|
44
|
-
export { type AgentProvider, type RelayClient, createRelayAgentProvider, createRelayClient, getDefaultRelayClient };
|
|
60
|
+
export { type AgentProvider, type RelayClient, createProviderClientPlugin, createRelayAgentProvider, createRelayClient, getDefaultRelayClient };
|
package/dist/client.d.ts
CHANGED
|
@@ -34,11 +34,27 @@ interface CreateRelayAgentProviderOptions {
|
|
|
34
34
|
agentId: string;
|
|
35
35
|
}
|
|
36
36
|
declare const createRelayAgentProvider: (options: CreateRelayAgentProviderOptions) => AgentProvider;
|
|
37
|
+
interface ReactGrabApi {
|
|
38
|
+
registerPlugin: (plugin: unknown) => void;
|
|
39
|
+
}
|
|
37
40
|
declare global {
|
|
38
41
|
interface Window {
|
|
39
42
|
__REACT_GRAB_RELAY__?: RelayClient;
|
|
43
|
+
__REACT_GRAB__?: ReactGrabApi;
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
46
|
declare const getDefaultRelayClient: () => RelayClient | null;
|
|
47
|
+
interface ProviderPluginConfig {
|
|
48
|
+
agentId: string;
|
|
49
|
+
pluginName: string;
|
|
50
|
+
actionId: string;
|
|
51
|
+
actionLabel: string;
|
|
52
|
+
}
|
|
53
|
+
declare const createProviderClientPlugin: (config: ProviderPluginConfig) => {
|
|
54
|
+
createAgentProvider: (providerOptions?: {
|
|
55
|
+
relayClient?: RelayClient;
|
|
56
|
+
}) => AgentProvider;
|
|
57
|
+
attachAgent: () => Promise<void>;
|
|
58
|
+
};
|
|
43
59
|
|
|
44
|
-
export { type AgentProvider, type RelayClient, createRelayAgentProvider, createRelayClient, getDefaultRelayClient };
|
|
60
|
+
export { type AgentProvider, type RelayClient, createProviderClientPlugin, createRelayAgentProvider, createRelayClient, getDefaultRelayClient };
|
package/dist/client.js
CHANGED
|
@@ -374,5 +374,68 @@ var getDefaultRelayClient = () => {
|
|
|
374
374
|
}
|
|
375
375
|
return defaultRelayClient;
|
|
376
376
|
};
|
|
377
|
+
var isReactGrabApi = (value) => typeof value === "object" && value !== null && "registerPlugin" in value;
|
|
378
|
+
var createProviderClientPlugin = (config) => {
|
|
379
|
+
const createAgentProvider = (providerOptions = {}) => {
|
|
380
|
+
const relayClient = providerOptions.relayClient ?? getDefaultRelayClient();
|
|
381
|
+
if (!relayClient) {
|
|
382
|
+
throw new Error("RelayClient is required in browser environments");
|
|
383
|
+
}
|
|
384
|
+
return createRelayAgentProvider({
|
|
385
|
+
relayClient,
|
|
386
|
+
agentId: config.agentId
|
|
387
|
+
});
|
|
388
|
+
};
|
|
389
|
+
const attachAgent = async () => {
|
|
390
|
+
if (typeof window === "undefined") return;
|
|
391
|
+
const relayClient = getDefaultRelayClient();
|
|
392
|
+
if (!relayClient) return;
|
|
393
|
+
try {
|
|
394
|
+
await relayClient.connect();
|
|
395
|
+
} catch {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
const provider = createRelayAgentProvider({
|
|
399
|
+
relayClient,
|
|
400
|
+
agentId: config.agentId
|
|
401
|
+
});
|
|
402
|
+
const attach = (api) => {
|
|
403
|
+
const agent = { provider, storage: sessionStorage };
|
|
404
|
+
api.registerPlugin({
|
|
405
|
+
name: config.pluginName,
|
|
406
|
+
actions: [
|
|
407
|
+
{
|
|
408
|
+
id: config.actionId,
|
|
409
|
+
label: config.actionLabel,
|
|
410
|
+
shortcut: "Enter",
|
|
411
|
+
onAction: (actionContext) => {
|
|
412
|
+
actionContext.enterPromptMode?.(agent);
|
|
413
|
+
},
|
|
414
|
+
agent
|
|
415
|
+
}
|
|
416
|
+
]
|
|
417
|
+
});
|
|
418
|
+
};
|
|
419
|
+
const existingApi = window.__REACT_GRAB__;
|
|
420
|
+
if (isReactGrabApi(existingApi)) {
|
|
421
|
+
attach(existingApi);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
window.addEventListener(
|
|
425
|
+
"react-grab:init",
|
|
426
|
+
(event) => {
|
|
427
|
+
if (!(event instanceof CustomEvent)) return;
|
|
428
|
+
if (!isReactGrabApi(event.detail)) return;
|
|
429
|
+
attach(event.detail);
|
|
430
|
+
},
|
|
431
|
+
{ once: true }
|
|
432
|
+
);
|
|
433
|
+
const apiAfterListener = window.__REACT_GRAB__;
|
|
434
|
+
if (isReactGrabApi(apiAfterListener)) {
|
|
435
|
+
attach(apiAfterListener);
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
return { createAgentProvider, attachAgent };
|
|
439
|
+
};
|
|
377
440
|
|
|
378
|
-
export { createRelayAgentProvider, createRelayClient, getDefaultRelayClient };
|
|
441
|
+
export { createProviderClientPlugin, createRelayAgentProvider, createRelayClient, getDefaultRelayClient };
|
package/dist/connection.cjs
CHANGED
|
@@ -8014,7 +8014,7 @@ ${context.content.join("\n\n")}`;
|
|
|
8014
8014
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
8015
8015
|
|
|
8016
8016
|
// src/connection.ts
|
|
8017
|
-
var VERSION = "0.1.
|
|
8017
|
+
var VERSION = "0.1.16";
|
|
8018
8018
|
var checkIfRelayServerIsRunning = async (port, token) => {
|
|
8019
8019
|
try {
|
|
8020
8020
|
const healthUrl = token ? `http://localhost:${port}/health?${RELAY_TOKEN_PARAM}=${encodeURIComponent(token)}` : `http://localhost:${port}/health`;
|
|
@@ -8246,5 +8246,13 @@ var printStartupMessage = (agentId, port) => {
|
|
|
8246
8246
|
);
|
|
8247
8247
|
console.log(`- Local: ${import_picocolors.default.cyan(`ws://localhost:${port}`)}`);
|
|
8248
8248
|
};
|
|
8249
|
+
var startProviderServer = (source, handler) => {
|
|
8250
|
+
fetch(
|
|
8251
|
+
`https://www.react-grab.com/api/version?source=${source}&t=${Date.now()}`
|
|
8252
|
+
).catch(() => {
|
|
8253
|
+
});
|
|
8254
|
+
connectRelay({ handler });
|
|
8255
|
+
};
|
|
8249
8256
|
|
|
8250
8257
|
exports.connectRelay = connectRelay;
|
|
8258
|
+
exports.startProviderServer = startProviderServer;
|
package/dist/connection.d.cts
CHANGED
|
@@ -9,5 +9,6 @@ interface RelayConnection {
|
|
|
9
9
|
disconnect: () => Promise<void>;
|
|
10
10
|
}
|
|
11
11
|
declare const connectRelay: (options: ConnectRelayOptions) => Promise<RelayConnection>;
|
|
12
|
+
declare const startProviderServer: (source: string, handler: AgentHandler) => void;
|
|
12
13
|
|
|
13
|
-
export { connectRelay };
|
|
14
|
+
export { connectRelay, startProviderServer };
|
package/dist/connection.d.ts
CHANGED
|
@@ -9,5 +9,6 @@ interface RelayConnection {
|
|
|
9
9
|
disconnect: () => Promise<void>;
|
|
10
10
|
}
|
|
11
11
|
declare const connectRelay: (options: ConnectRelayOptions) => Promise<RelayConnection>;
|
|
12
|
+
declare const startProviderServer: (source: string, handler: AgentHandler) => void;
|
|
12
13
|
|
|
13
|
-
export { connectRelay };
|
|
14
|
+
export { connectRelay, startProviderServer };
|
package/dist/connection.js
CHANGED
|
@@ -8004,7 +8004,7 @@ ${context.content.join("\n\n")}`;
|
|
|
8004
8004
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
8005
8005
|
|
|
8006
8006
|
// src/connection.ts
|
|
8007
|
-
var VERSION = "0.1.
|
|
8007
|
+
var VERSION = "0.1.16";
|
|
8008
8008
|
var checkIfRelayServerIsRunning = async (port, token) => {
|
|
8009
8009
|
try {
|
|
8010
8010
|
const healthUrl = token ? `http://localhost:${port}/health?${RELAY_TOKEN_PARAM}=${encodeURIComponent(token)}` : `http://localhost:${port}/health`;
|
|
@@ -8236,5 +8236,12 @@ var printStartupMessage = (agentId, port) => {
|
|
|
8236
8236
|
);
|
|
8237
8237
|
console.log(`- Local: ${import_picocolors.default.cyan(`ws://localhost:${port}`)}`);
|
|
8238
8238
|
};
|
|
8239
|
+
var startProviderServer = (source, handler) => {
|
|
8240
|
+
fetch(
|
|
8241
|
+
`https://www.react-grab.com/api/version?source=${source}&t=${Date.now()}`
|
|
8242
|
+
).catch(() => {
|
|
8243
|
+
});
|
|
8244
|
+
connectRelay({ handler });
|
|
8245
|
+
};
|
|
8239
8246
|
|
|
8240
|
-
export { connectRelay };
|
|
8247
|
+
export { connectRelay, startProviderServer };
|
package/dist/index.cjs
CHANGED
|
@@ -8016,7 +8016,7 @@ async function fkill(inputs, options = {}) {
|
|
|
8016
8016
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
8017
8017
|
|
|
8018
8018
|
// src/connection.ts
|
|
8019
|
-
var VERSION = "0.1.
|
|
8019
|
+
var VERSION = "0.1.16";
|
|
8020
8020
|
var checkIfRelayServerIsRunning = async (port, token) => {
|
|
8021
8021
|
try {
|
|
8022
8022
|
const healthUrl = token ? `http://localhost:${port}/health?${RELAY_TOKEN_PARAM}=${encodeURIComponent(token)}` : `http://localhost:${port}/health`;
|
|
@@ -8248,6 +8248,13 @@ var printStartupMessage = (agentId, port) => {
|
|
|
8248
8248
|
);
|
|
8249
8249
|
console.log(`- Local: ${import_picocolors.default.cyan(`ws://localhost:${port}`)}`);
|
|
8250
8250
|
};
|
|
8251
|
+
var startProviderServer = (source, handler) => {
|
|
8252
|
+
fetch(
|
|
8253
|
+
`https://www.react-grab.com/api/version?source=${source}&t=${Date.now()}`
|
|
8254
|
+
).catch(() => {
|
|
8255
|
+
});
|
|
8256
|
+
connectRelay({ handler });
|
|
8257
|
+
};
|
|
8251
8258
|
|
|
8252
8259
|
// src/client.ts
|
|
8253
8260
|
var createRelayClient = (options = {}) => {
|
|
@@ -8620,6 +8627,69 @@ var getDefaultRelayClient = () => {
|
|
|
8620
8627
|
}
|
|
8621
8628
|
return defaultRelayClient;
|
|
8622
8629
|
};
|
|
8630
|
+
var isReactGrabApi = (value) => typeof value === "object" && value !== null && "registerPlugin" in value;
|
|
8631
|
+
var createProviderClientPlugin = (config) => {
|
|
8632
|
+
const createAgentProvider = (providerOptions = {}) => {
|
|
8633
|
+
const relayClient = providerOptions.relayClient ?? getDefaultRelayClient();
|
|
8634
|
+
if (!relayClient) {
|
|
8635
|
+
throw new Error("RelayClient is required in browser environments");
|
|
8636
|
+
}
|
|
8637
|
+
return createRelayAgentProvider({
|
|
8638
|
+
relayClient,
|
|
8639
|
+
agentId: config.agentId
|
|
8640
|
+
});
|
|
8641
|
+
};
|
|
8642
|
+
const attachAgent = async () => {
|
|
8643
|
+
if (typeof window === "undefined") return;
|
|
8644
|
+
const relayClient = getDefaultRelayClient();
|
|
8645
|
+
if (!relayClient) return;
|
|
8646
|
+
try {
|
|
8647
|
+
await relayClient.connect();
|
|
8648
|
+
} catch {
|
|
8649
|
+
return;
|
|
8650
|
+
}
|
|
8651
|
+
const provider = createRelayAgentProvider({
|
|
8652
|
+
relayClient,
|
|
8653
|
+
agentId: config.agentId
|
|
8654
|
+
});
|
|
8655
|
+
const attach = (api) => {
|
|
8656
|
+
const agent = { provider, storage: sessionStorage };
|
|
8657
|
+
api.registerPlugin({
|
|
8658
|
+
name: config.pluginName,
|
|
8659
|
+
actions: [
|
|
8660
|
+
{
|
|
8661
|
+
id: config.actionId,
|
|
8662
|
+
label: config.actionLabel,
|
|
8663
|
+
shortcut: "Enter",
|
|
8664
|
+
onAction: (actionContext) => {
|
|
8665
|
+
actionContext.enterPromptMode?.(agent);
|
|
8666
|
+
},
|
|
8667
|
+
agent
|
|
8668
|
+
}
|
|
8669
|
+
]
|
|
8670
|
+
});
|
|
8671
|
+
};
|
|
8672
|
+
const existingApi = window.__REACT_GRAB__;
|
|
8673
|
+
if (isReactGrabApi(existingApi)) {
|
|
8674
|
+
attach(existingApi);
|
|
8675
|
+
return;
|
|
8676
|
+
}
|
|
8677
|
+
window.addEventListener(
|
|
8678
|
+
"react-grab:init",
|
|
8679
|
+
(event) => {
|
|
8680
|
+
if (!(event instanceof CustomEvent)) return;
|
|
8681
|
+
if (!isReactGrabApi(event.detail)) return;
|
|
8682
|
+
attach(event.detail);
|
|
8683
|
+
},
|
|
8684
|
+
{ once: true }
|
|
8685
|
+
);
|
|
8686
|
+
const apiAfterListener = window.__REACT_GRAB__;
|
|
8687
|
+
if (isReactGrabApi(apiAfterListener)) {
|
|
8688
|
+
attach(apiAfterListener);
|
|
8689
|
+
}
|
|
8690
|
+
};
|
|
8691
|
+
return { createAgentProvider, attachAgent };
|
|
8692
|
+
};
|
|
8623
8693
|
|
|
8624
8694
|
exports.COMPLETED_STATUS = COMPLETED_STATUS;
|
|
8625
8695
|
exports.DEFAULT_RECONNECT_INTERVAL_MS = DEFAULT_RECONNECT_INTERVAL_MS;
|
|
@@ -8628,7 +8698,9 @@ exports.HEALTH_CHECK_TIMEOUT_MS = HEALTH_CHECK_TIMEOUT_MS;
|
|
|
8628
8698
|
exports.POST_KILL_DELAY_MS = POST_KILL_DELAY_MS;
|
|
8629
8699
|
exports.RELAY_TOKEN_PARAM = RELAY_TOKEN_PARAM;
|
|
8630
8700
|
exports.connectRelay = connectRelay;
|
|
8701
|
+
exports.createProviderClientPlugin = createProviderClientPlugin;
|
|
8631
8702
|
exports.createRelayAgentProvider = createRelayAgentProvider;
|
|
8632
8703
|
exports.createRelayClient = createRelayClient;
|
|
8633
8704
|
exports.createRelayServer = createRelayServer;
|
|
8634
8705
|
exports.getDefaultRelayClient = getDefaultRelayClient;
|
|
8706
|
+
exports.startProviderServer = startProviderServer;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AgentContext, RelayToBrowserMessage } from './protocol.cjs';
|
|
2
2
|
export { AgentHandler, AgentMessage, AgentRunOptions, BrowserToRelayMessage, COMPLETED_STATUS, DEFAULT_RECONNECT_INTERVAL_MS, DEFAULT_RELAY_PORT, HEALTH_CHECK_TIMEOUT_MS, HandlerRegistrationMessage, HandlerToRelayMessage, HandlerUnregisterMessage, POST_KILL_DELAY_MS, RELAY_TOKEN_PARAM, RelayToHandlerMessage } from './protocol.cjs';
|
|
3
3
|
export { RelayServer, createRelayServer } from './server.cjs';
|
|
4
|
-
export { connectRelay } from './connection.cjs';
|
|
4
|
+
export { connectRelay, startProviderServer } from './connection.cjs';
|
|
5
5
|
|
|
6
6
|
interface RelayClient {
|
|
7
7
|
connect: () => Promise<void>;
|
|
@@ -37,11 +37,27 @@ interface CreateRelayAgentProviderOptions {
|
|
|
37
37
|
agentId: string;
|
|
38
38
|
}
|
|
39
39
|
declare const createRelayAgentProvider: (options: CreateRelayAgentProviderOptions) => AgentProvider;
|
|
40
|
+
interface ReactGrabApi {
|
|
41
|
+
registerPlugin: (plugin: unknown) => void;
|
|
42
|
+
}
|
|
40
43
|
declare global {
|
|
41
44
|
interface Window {
|
|
42
45
|
__REACT_GRAB_RELAY__?: RelayClient;
|
|
46
|
+
__REACT_GRAB__?: ReactGrabApi;
|
|
43
47
|
}
|
|
44
48
|
}
|
|
45
49
|
declare const getDefaultRelayClient: () => RelayClient | null;
|
|
50
|
+
interface ProviderPluginConfig {
|
|
51
|
+
agentId: string;
|
|
52
|
+
pluginName: string;
|
|
53
|
+
actionId: string;
|
|
54
|
+
actionLabel: string;
|
|
55
|
+
}
|
|
56
|
+
declare const createProviderClientPlugin: (config: ProviderPluginConfig) => {
|
|
57
|
+
createAgentProvider: (providerOptions?: {
|
|
58
|
+
relayClient?: RelayClient;
|
|
59
|
+
}) => AgentProvider;
|
|
60
|
+
attachAgent: () => Promise<void>;
|
|
61
|
+
};
|
|
46
62
|
|
|
47
|
-
export { AgentContext, type AgentProvider, type RelayClient, RelayToBrowserMessage, createRelayAgentProvider, createRelayClient, getDefaultRelayClient };
|
|
63
|
+
export { AgentContext, type AgentProvider, type RelayClient, RelayToBrowserMessage, createProviderClientPlugin, createRelayAgentProvider, createRelayClient, getDefaultRelayClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AgentContext, RelayToBrowserMessage } from './protocol.js';
|
|
2
2
|
export { AgentHandler, AgentMessage, AgentRunOptions, BrowserToRelayMessage, COMPLETED_STATUS, DEFAULT_RECONNECT_INTERVAL_MS, DEFAULT_RELAY_PORT, HEALTH_CHECK_TIMEOUT_MS, HandlerRegistrationMessage, HandlerToRelayMessage, HandlerUnregisterMessage, POST_KILL_DELAY_MS, RELAY_TOKEN_PARAM, RelayToHandlerMessage } from './protocol.js';
|
|
3
3
|
export { RelayServer, createRelayServer } from './server.js';
|
|
4
|
-
export { connectRelay } from './connection.js';
|
|
4
|
+
export { connectRelay, startProviderServer } from './connection.js';
|
|
5
5
|
|
|
6
6
|
interface RelayClient {
|
|
7
7
|
connect: () => Promise<void>;
|
|
@@ -37,11 +37,27 @@ interface CreateRelayAgentProviderOptions {
|
|
|
37
37
|
agentId: string;
|
|
38
38
|
}
|
|
39
39
|
declare const createRelayAgentProvider: (options: CreateRelayAgentProviderOptions) => AgentProvider;
|
|
40
|
+
interface ReactGrabApi {
|
|
41
|
+
registerPlugin: (plugin: unknown) => void;
|
|
42
|
+
}
|
|
40
43
|
declare global {
|
|
41
44
|
interface Window {
|
|
42
45
|
__REACT_GRAB_RELAY__?: RelayClient;
|
|
46
|
+
__REACT_GRAB__?: ReactGrabApi;
|
|
43
47
|
}
|
|
44
48
|
}
|
|
45
49
|
declare const getDefaultRelayClient: () => RelayClient | null;
|
|
50
|
+
interface ProviderPluginConfig {
|
|
51
|
+
agentId: string;
|
|
52
|
+
pluginName: string;
|
|
53
|
+
actionId: string;
|
|
54
|
+
actionLabel: string;
|
|
55
|
+
}
|
|
56
|
+
declare const createProviderClientPlugin: (config: ProviderPluginConfig) => {
|
|
57
|
+
createAgentProvider: (providerOptions?: {
|
|
58
|
+
relayClient?: RelayClient;
|
|
59
|
+
}) => AgentProvider;
|
|
60
|
+
attachAgent: () => Promise<void>;
|
|
61
|
+
};
|
|
46
62
|
|
|
47
|
-
export { AgentContext, type AgentProvider, type RelayClient, RelayToBrowserMessage, createRelayAgentProvider, createRelayClient, getDefaultRelayClient };
|
|
63
|
+
export { AgentContext, type AgentProvider, type RelayClient, RelayToBrowserMessage, createProviderClientPlugin, createRelayAgentProvider, createRelayClient, getDefaultRelayClient };
|
package/dist/index.js
CHANGED
|
@@ -8006,7 +8006,7 @@ async function fkill(inputs, options = {}) {
|
|
|
8006
8006
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
8007
8007
|
|
|
8008
8008
|
// src/connection.ts
|
|
8009
|
-
var VERSION = "0.1.
|
|
8009
|
+
var VERSION = "0.1.16";
|
|
8010
8010
|
var checkIfRelayServerIsRunning = async (port, token) => {
|
|
8011
8011
|
try {
|
|
8012
8012
|
const healthUrl = token ? `http://localhost:${port}/health?${RELAY_TOKEN_PARAM}=${encodeURIComponent(token)}` : `http://localhost:${port}/health`;
|
|
@@ -8238,6 +8238,13 @@ var printStartupMessage = (agentId, port) => {
|
|
|
8238
8238
|
);
|
|
8239
8239
|
console.log(`- Local: ${import_picocolors.default.cyan(`ws://localhost:${port}`)}`);
|
|
8240
8240
|
};
|
|
8241
|
+
var startProviderServer = (source, handler) => {
|
|
8242
|
+
fetch(
|
|
8243
|
+
`https://www.react-grab.com/api/version?source=${source}&t=${Date.now()}`
|
|
8244
|
+
).catch(() => {
|
|
8245
|
+
});
|
|
8246
|
+
connectRelay({ handler });
|
|
8247
|
+
};
|
|
8241
8248
|
|
|
8242
8249
|
// src/client.ts
|
|
8243
8250
|
var createRelayClient = (options = {}) => {
|
|
@@ -8610,5 +8617,68 @@ var getDefaultRelayClient = () => {
|
|
|
8610
8617
|
}
|
|
8611
8618
|
return defaultRelayClient;
|
|
8612
8619
|
};
|
|
8620
|
+
var isReactGrabApi = (value) => typeof value === "object" && value !== null && "registerPlugin" in value;
|
|
8621
|
+
var createProviderClientPlugin = (config) => {
|
|
8622
|
+
const createAgentProvider = (providerOptions = {}) => {
|
|
8623
|
+
const relayClient = providerOptions.relayClient ?? getDefaultRelayClient();
|
|
8624
|
+
if (!relayClient) {
|
|
8625
|
+
throw new Error("RelayClient is required in browser environments");
|
|
8626
|
+
}
|
|
8627
|
+
return createRelayAgentProvider({
|
|
8628
|
+
relayClient,
|
|
8629
|
+
agentId: config.agentId
|
|
8630
|
+
});
|
|
8631
|
+
};
|
|
8632
|
+
const attachAgent = async () => {
|
|
8633
|
+
if (typeof window === "undefined") return;
|
|
8634
|
+
const relayClient = getDefaultRelayClient();
|
|
8635
|
+
if (!relayClient) return;
|
|
8636
|
+
try {
|
|
8637
|
+
await relayClient.connect();
|
|
8638
|
+
} catch {
|
|
8639
|
+
return;
|
|
8640
|
+
}
|
|
8641
|
+
const provider = createRelayAgentProvider({
|
|
8642
|
+
relayClient,
|
|
8643
|
+
agentId: config.agentId
|
|
8644
|
+
});
|
|
8645
|
+
const attach = (api) => {
|
|
8646
|
+
const agent = { provider, storage: sessionStorage };
|
|
8647
|
+
api.registerPlugin({
|
|
8648
|
+
name: config.pluginName,
|
|
8649
|
+
actions: [
|
|
8650
|
+
{
|
|
8651
|
+
id: config.actionId,
|
|
8652
|
+
label: config.actionLabel,
|
|
8653
|
+
shortcut: "Enter",
|
|
8654
|
+
onAction: (actionContext) => {
|
|
8655
|
+
actionContext.enterPromptMode?.(agent);
|
|
8656
|
+
},
|
|
8657
|
+
agent
|
|
8658
|
+
}
|
|
8659
|
+
]
|
|
8660
|
+
});
|
|
8661
|
+
};
|
|
8662
|
+
const existingApi = window.__REACT_GRAB__;
|
|
8663
|
+
if (isReactGrabApi(existingApi)) {
|
|
8664
|
+
attach(existingApi);
|
|
8665
|
+
return;
|
|
8666
|
+
}
|
|
8667
|
+
window.addEventListener(
|
|
8668
|
+
"react-grab:init",
|
|
8669
|
+
(event) => {
|
|
8670
|
+
if (!(event instanceof CustomEvent)) return;
|
|
8671
|
+
if (!isReactGrabApi(event.detail)) return;
|
|
8672
|
+
attach(event.detail);
|
|
8673
|
+
},
|
|
8674
|
+
{ once: true }
|
|
8675
|
+
);
|
|
8676
|
+
const apiAfterListener = window.__REACT_GRAB__;
|
|
8677
|
+
if (isReactGrabApi(apiAfterListener)) {
|
|
8678
|
+
attach(apiAfterListener);
|
|
8679
|
+
}
|
|
8680
|
+
};
|
|
8681
|
+
return { createAgentProvider, attachAgent };
|
|
8682
|
+
};
|
|
8613
8683
|
|
|
8614
|
-
export { COMPLETED_STATUS, DEFAULT_RECONNECT_INTERVAL_MS, DEFAULT_RELAY_PORT, HEALTH_CHECK_TIMEOUT_MS, POST_KILL_DELAY_MS, RELAY_TOKEN_PARAM, connectRelay, createRelayAgentProvider, createRelayClient, createRelayServer, getDefaultRelayClient };
|
|
8684
|
+
export { COMPLETED_STATUS, DEFAULT_RECONNECT_INTERVAL_MS, DEFAULT_RELAY_PORT, HEALTH_CHECK_TIMEOUT_MS, POST_KILL_DELAY_MS, RELAY_TOKEN_PARAM, connectRelay, createProviderClientPlugin, createRelayAgentProvider, createRelayClient, createRelayServer, getDefaultRelayClient, startProviderServer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-grab/relay",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist"
|
|
6
6
|
],
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"fkill": "^9.0.0",
|
|
32
32
|
"picocolors": "^1.1.1",
|
|
33
33
|
"ws": "^8.18.0",
|
|
34
|
-
"@react-grab/utils": "0.1.
|
|
34
|
+
"@react-grab/utils": "0.1.16"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "^22.10.7",
|