@rozenite/agent-bridge
Advanced tools
| "use strict"; | ||
| Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); | ||
| const react = require("react"); | ||
| const pluginBridge = require("@rozenite/plugin-bridge"); | ||
| const AGENT_PLUGIN_ID = "rozenite-agent"; | ||
| const APP_DOMAIN = "app"; | ||
| const getQualifiedToolName = (domain, toolName) => { | ||
| return `${domain.trim()}.${toolName.trim()}`; | ||
| }; | ||
| function useRozeniteDomainAgentTool(domain, options) { | ||
| const { tool, handler, enabled = true } = options; | ||
| const toolName = getQualifiedToolName(domain, tool.name); | ||
| const qualifiedTool = { | ||
| ...tool, | ||
| name: toolName | ||
| }; | ||
| const client = pluginBridge.useRozeniteDevToolsClient({ | ||
| pluginId: AGENT_PLUGIN_ID | ||
| }); | ||
| const handlerRef = react.useRef(handler); | ||
| handlerRef.current = handler; | ||
| react.useEffect(() => { | ||
| if (!client || !enabled) { | ||
| return; | ||
| } | ||
| client.send("register-tool", { | ||
| tools: [qualifiedTool] | ||
| }); | ||
| const subscription = client.onMessage("tool-call", async (payload) => { | ||
| if (payload.toolName !== toolName) { | ||
| return; | ||
| } | ||
| try { | ||
| const result = await handlerRef.current(payload.arguments); | ||
| const response = { | ||
| callId: payload.callId, | ||
| success: true, | ||
| result | ||
| }; | ||
| client.send("tool-result", response); | ||
| } catch (error) { | ||
| const response = { | ||
| callId: payload.callId, | ||
| success: false, | ||
| error: error instanceof Error ? error.message : String(error) | ||
| }; | ||
| client.send("tool-result", response); | ||
| } | ||
| }); | ||
| return () => { | ||
| client.send("unregister-tool", { | ||
| toolNames: [toolName] | ||
| }); | ||
| subscription.remove(); | ||
| }; | ||
| }, [client, enabled, tool, toolName]); | ||
| } | ||
| function useRozenitePluginAgentTool(options) { | ||
| const { pluginId, ...toolOptions } = options; | ||
| useRozeniteDomainAgentTool(pluginId, toolOptions); | ||
| } | ||
| function useRozeniteInAppAgentTool(options) { | ||
| const { ...toolOptions } = options; | ||
| useRozeniteDomainAgentTool(APP_DOMAIN, toolOptions); | ||
| } | ||
| exports.useRozeniteInAppAgentTool = useRozeniteInAppAgentTool; | ||
| exports.useRozenitePluginAgentTool = useRozenitePluginAgentTool; |
+61
-4
@@ -1,4 +0,61 @@ | ||
| export { useRozenitePluginAgentTool, useRozeniteInAppAgentTool, } from './useRozeniteAgentTool.js'; | ||
| export type { UseRozeniteAgentToolOptions, UseRozenitePluginAgentToolOptions, UseRozeniteInAppAgentToolOptions, } from './useRozeniteAgentTool.js'; | ||
| export type { JSONSchema7, AgentTool, AgentMessage, RegisterToolMessage, UnregisterToolMessage, ToolCallMessage, ToolResultMessage, } from './types.js'; | ||
| //# sourceMappingURL=index.d.ts.map | ||
| import { AgentMessage } from '@rozenite/agent-shared'; | ||
| import { AgentTool } from '@rozenite/agent-shared'; | ||
| import { JSONSchema7 } from '@rozenite/agent-shared'; | ||
| import { RegisterToolMessage } from '@rozenite/agent-shared'; | ||
| import { ToolCallMessage } from '@rozenite/agent-shared'; | ||
| import { ToolResultMessage } from '@rozenite/agent-shared'; | ||
| import { UnregisterToolMessage } from '@rozenite/agent-shared'; | ||
| export { AgentMessage } | ||
| export { AgentTool } | ||
| export { JSONSchema7 } | ||
| export { RegisterToolMessage } | ||
| export { ToolCallMessage } | ||
| export { ToolResultMessage } | ||
| export { UnregisterToolMessage } | ||
| export declare interface UseRozeniteAgentToolOptions<TInput = unknown, TOutput = unknown> { | ||
| tool: AgentTool; | ||
| handler: (args: TInput) => Promise<TOutput> | TOutput; | ||
| enabled?: boolean; | ||
| } | ||
| /** | ||
| * Registers an agent tool under the `app` domain so external agents (e.g. CLI, Cursor) | ||
| * can invoke it via the Rozenite devtools bridge. | ||
| * | ||
| * The tool is qualified as `app.{tool.name}`. It is registered when the component | ||
| * mounts (and `enabled` is true) and unregistered on unmount. | ||
| * | ||
| * @typeParam TInput - Type of the arguments passed to the tool handler (default: `unknown`). | ||
| * @typeParam TOutput - Type of the value returned by the handler (default: `unknown`). | ||
| * @param options - Configuration: `tool` (AgentTool), `handler`, and optional `enabled`. | ||
| */ | ||
| export declare function useRozeniteInAppAgentTool<TInput = unknown, TOutput = unknown>(options: UseRozeniteInAppAgentToolOptions<TInput, TOutput>): void; | ||
| export declare type UseRozeniteInAppAgentToolOptions<TInput = unknown, TOutput = unknown> = UseRozeniteAgentToolOptions<TInput, TOutput>; | ||
| /** | ||
| * Registers an agent tool under a plugin domain so external agents (e.g. CLI, Cursor) | ||
| * can invoke it via the Rozenite devtools bridge. | ||
| * | ||
| * The tool is qualified as `{pluginId}.{tool.name}`. It is registered when the | ||
| * component mounts (and `enabled` is true) and unregistered on unmount. | ||
| * | ||
| * @typeParam TInput - Type of the arguments passed to the tool handler (default: `unknown`). | ||
| * @typeParam TOutput - Type of the value returned by the handler (default: `unknown`). | ||
| * @param options - Configuration: `tool` (AgentTool), `handler`, optional `enabled`, and `pluginId`. | ||
| */ | ||
| export declare function useRozenitePluginAgentTool<TInput = unknown, TOutput = unknown>(options: UseRozenitePluginAgentToolOptions<TInput, TOutput>): void; | ||
| export declare interface UseRozenitePluginAgentToolOptions<TInput = unknown, TOutput = unknown> extends UseRozeniteAgentToolOptions<TInput, TOutput> { | ||
| pluginId: string; | ||
| } | ||
| export { } |
+67
-1
@@ -1,1 +0,67 @@ | ||
| export { useRozenitePluginAgentTool, useRozeniteInAppAgentTool, } from './useRozeniteAgentTool.js'; | ||
| import { useRef, useEffect } from "react"; | ||
| import { useRozeniteDevToolsClient } from "@rozenite/plugin-bridge"; | ||
| const AGENT_PLUGIN_ID = "rozenite-agent"; | ||
| const APP_DOMAIN = "app"; | ||
| const getQualifiedToolName = (domain, toolName) => { | ||
| return `${domain.trim()}.${toolName.trim()}`; | ||
| }; | ||
| function useRozeniteDomainAgentTool(domain, options) { | ||
| const { tool, handler, enabled = true } = options; | ||
| const toolName = getQualifiedToolName(domain, tool.name); | ||
| const qualifiedTool = { | ||
| ...tool, | ||
| name: toolName | ||
| }; | ||
| const client = useRozeniteDevToolsClient({ | ||
| pluginId: AGENT_PLUGIN_ID | ||
| }); | ||
| const handlerRef = useRef(handler); | ||
| handlerRef.current = handler; | ||
| useEffect(() => { | ||
| if (!client || !enabled) { | ||
| return; | ||
| } | ||
| client.send("register-tool", { | ||
| tools: [qualifiedTool] | ||
| }); | ||
| const subscription = client.onMessage("tool-call", async (payload) => { | ||
| if (payload.toolName !== toolName) { | ||
| return; | ||
| } | ||
| try { | ||
| const result = await handlerRef.current(payload.arguments); | ||
| const response = { | ||
| callId: payload.callId, | ||
| success: true, | ||
| result | ||
| }; | ||
| client.send("tool-result", response); | ||
| } catch (error) { | ||
| const response = { | ||
| callId: payload.callId, | ||
| success: false, | ||
| error: error instanceof Error ? error.message : String(error) | ||
| }; | ||
| client.send("tool-result", response); | ||
| } | ||
| }); | ||
| return () => { | ||
| client.send("unregister-tool", { | ||
| toolNames: [toolName] | ||
| }); | ||
| subscription.remove(); | ||
| }; | ||
| }, [client, enabled, tool, toolName]); | ||
| } | ||
| function useRozenitePluginAgentTool(options) { | ||
| const { pluginId, ...toolOptions } = options; | ||
| useRozeniteDomainAgentTool(pluginId, toolOptions); | ||
| } | ||
| function useRozeniteInAppAgentTool(options) { | ||
| const { ...toolOptions } = options; | ||
| useRozeniteDomainAgentTool(APP_DOMAIN, toolOptions); | ||
| } | ||
| export { | ||
| useRozeniteInAppAgentTool, | ||
| useRozenitePluginAgentTool | ||
| }; |
+9
-6
| { | ||
| "name": "@rozenite/agent-bridge", | ||
| "version": "1.5.0", | ||
| "version": "1.5.1", | ||
| "description": "React hook API for registering agent tools in React Native", | ||
| "type": "module", | ||
| "main": "./dist/index.cjs", | ||
| "main": "./dist/index.js", | ||
| "module": "./dist/index.js", | ||
@@ -29,6 +29,8 @@ "types": "./dist/index.d.ts", | ||
| "exports": { | ||
| "./package.json": "./package.json", | ||
| ".": { | ||
| "development": "./src/index.ts", | ||
| "types": "./dist/index.d.ts", | ||
| "import": "./dist/index.js", | ||
| "require": "./dist/index.js" | ||
| "require": "./dist/index.cjs" | ||
| } | ||
@@ -38,4 +40,4 @@ }, | ||
| "tslib": "^2.3.0", | ||
| "@rozenite/agent-shared": "1.5.0", | ||
| "@rozenite/plugin-bridge": "1.5.0" | ||
| "@rozenite/plugin-bridge": "1.5.1", | ||
| "@rozenite/agent-shared": "1.5.1" | ||
| }, | ||
@@ -50,5 +52,6 @@ "devDependencies": {}, | ||
| "scripts": { | ||
| "build": "tsc -b tsconfig.lib.json", | ||
| "build": "vite build", | ||
| "typecheck": "tsc -p tsconfig.lib.json --noEmit", | ||
| "clean": "rm -rf dist" | ||
| } | ||
| } |
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,yBAAyB,GAC1B,MAAM,2BAA2B,CAAC;AACnC,YAAY,EACV,2BAA2B,EAC3B,iCAAiC,EACjC,gCAAgC,GACjC,MAAM,2BAA2B,CAAC;AACnC,YAAY,EACV,WAAW,EACX,SAAS,EACT,YAAY,EACZ,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,EACf,iBAAiB,GAClB,MAAM,YAAY,CAAC"} |
Sorry, the diff of this file is not supported yet
| export { AGENT_PLUGIN_ID, } from '@rozenite/agent-shared'; | ||
| export type { JSONSchema7, AgentTool, DevToolsPluginMessage, RegisterToolPayload, UnregisterToolPayload, ToolCallPayload, ToolResultPayload, RegisterToolMessage, UnregisterToolMessage, ToolCallMessage, ToolResultMessage, AgentMessage, } from '@rozenite/agent-shared'; | ||
| //# sourceMappingURL=types.d.ts.map |
| {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAEhC,YAAY,EACV,WAAW,EACX,SAAS,EACT,qBAAqB,EACrB,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,EACf,iBAAiB,EACjB,YAAY,GACb,MAAM,wBAAwB,CAAC"} |
| export { AGENT_PLUGIN_ID, } from '@rozenite/agent-shared'; |
| import { type AgentTool } from './types.js'; | ||
| export interface UseRozeniteAgentToolOptions<TInput = unknown, TOutput = unknown> { | ||
| tool: AgentTool; | ||
| handler: (args: TInput) => Promise<TOutput> | TOutput; | ||
| enabled?: boolean; | ||
| } | ||
| export interface UseRozenitePluginAgentToolOptions<TInput = unknown, TOutput = unknown> extends UseRozeniteAgentToolOptions<TInput, TOutput> { | ||
| pluginId: string; | ||
| } | ||
| export type UseRozeniteInAppAgentToolOptions<TInput = unknown, TOutput = unknown> = UseRozeniteAgentToolOptions<TInput, TOutput>; | ||
| /** | ||
| * Registers an agent tool under a plugin domain so external agents (e.g. CLI, Cursor) | ||
| * can invoke it via the Rozenite devtools bridge. | ||
| * | ||
| * The tool is qualified as `{pluginId}.{tool.name}`. It is registered when the | ||
| * component mounts (and `enabled` is true) and unregistered on unmount. | ||
| * | ||
| * @typeParam TInput - Type of the arguments passed to the tool handler (default: `unknown`). | ||
| * @typeParam TOutput - Type of the value returned by the handler (default: `unknown`). | ||
| * @param options - Configuration: `tool` (AgentTool), `handler`, optional `enabled`, and `pluginId`. | ||
| */ | ||
| export declare function useRozenitePluginAgentTool<TInput = unknown, TOutput = unknown>(options: UseRozenitePluginAgentToolOptions<TInput, TOutput>): void; | ||
| /** | ||
| * Registers an agent tool under the `app` domain so external agents (e.g. CLI, Cursor) | ||
| * can invoke it via the Rozenite devtools bridge. | ||
| * | ||
| * The tool is qualified as `app.{tool.name}`. It is registered when the component | ||
| * mounts (and `enabled` is true) and unregistered on unmount. | ||
| * | ||
| * @typeParam TInput - Type of the arguments passed to the tool handler (default: `unknown`). | ||
| * @typeParam TOutput - Type of the value returned by the handler (default: `unknown`). | ||
| * @param options - Configuration: `tool` (AgentTool), `handler`, and optional `enabled`. | ||
| */ | ||
| export declare function useRozeniteInAppAgentTool<TInput = unknown, TOutput = unknown>(options: UseRozeniteInAppAgentToolOptions<TInput, TOutput>): void; | ||
| //# sourceMappingURL=useRozeniteAgentTool.d.ts.map |
| {"version":3,"file":"useRozeniteAgentTool.d.ts","sourceRoot":"","sources":["../src/useRozeniteAgentTool.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,SAAS,EAKf,MAAM,YAAY,CAAC;AASpB,MAAM,WAAW,2BAA2B,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO;IAC9E,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IACtD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,iCAAiC,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,CACpF,SAAQ,2BAA2B,CAAC,MAAM,EAAE,OAAO,CAAC;IACpD,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,gCAAgC,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,2BAA2B,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAyEjI;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,EAC5E,OAAO,EAAE,iCAAiC,CAAC,MAAM,EAAE,OAAO,CAAC,GAC1D,IAAI,CAGN;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,EAC3E,OAAO,EAAE,gCAAgC,CAAC,MAAM,EAAE,OAAO,CAAC,GACzD,IAAI,CAGN"} |
| import { useEffect, useRef } from 'react'; | ||
| import { useRozeniteDevToolsClient } from '@rozenite/plugin-bridge'; | ||
| import { AGENT_PLUGIN_ID, } from './types.js'; | ||
| const APP_DOMAIN = 'app'; | ||
| const getQualifiedToolName = (domain, toolName) => { | ||
| return `${domain.trim()}.${toolName.trim()}`; | ||
| }; | ||
| function useRozeniteDomainAgentTool(domain, options) { | ||
| const { tool, handler, enabled = true } = options; | ||
| const toolName = getQualifiedToolName(domain, tool.name); | ||
| const qualifiedTool = { | ||
| ...tool, | ||
| name: toolName, | ||
| }; | ||
| const client = useRozeniteDevToolsClient({ | ||
| pluginId: AGENT_PLUGIN_ID, | ||
| }); | ||
| const handlerRef = useRef(handler); | ||
| handlerRef.current = handler; | ||
| useEffect(() => { | ||
| if (!client || !enabled) { | ||
| return; | ||
| } | ||
| // Register the tool | ||
| client.send('register-tool', { | ||
| tools: [qualifiedTool], | ||
| }); | ||
| // Listen for tool calls | ||
| const subscription = client.onMessage('tool-call', async (payload) => { | ||
| // Only handle calls for this tool | ||
| if (payload.toolName !== toolName) { | ||
| return; | ||
| } | ||
| try { | ||
| const result = await handlerRef.current(payload.arguments); | ||
| const response = { | ||
| callId: payload.callId, | ||
| success: true, | ||
| result, | ||
| }; | ||
| client.send('tool-result', response); | ||
| } | ||
| catch (error) { | ||
| const response = { | ||
| callId: payload.callId, | ||
| success: false, | ||
| error: error instanceof Error ? error.message : String(error), | ||
| }; | ||
| client.send('tool-result', response); | ||
| } | ||
| }); | ||
| return () => { | ||
| // Unregister the tool on unmount | ||
| client.send('unregister-tool', { | ||
| toolNames: [toolName], | ||
| }); | ||
| subscription.remove(); | ||
| }; | ||
| }, [client, enabled, tool, toolName]); | ||
| } | ||
| /** | ||
| * Registers an agent tool under a plugin domain so external agents (e.g. CLI, Cursor) | ||
| * can invoke it via the Rozenite devtools bridge. | ||
| * | ||
| * The tool is qualified as `{pluginId}.{tool.name}`. It is registered when the | ||
| * component mounts (and `enabled` is true) and unregistered on unmount. | ||
| * | ||
| * @typeParam TInput - Type of the arguments passed to the tool handler (default: `unknown`). | ||
| * @typeParam TOutput - Type of the value returned by the handler (default: `unknown`). | ||
| * @param options - Configuration: `tool` (AgentTool), `handler`, optional `enabled`, and `pluginId`. | ||
| */ | ||
| export function useRozenitePluginAgentTool(options) { | ||
| const { pluginId, ...toolOptions } = options; | ||
| useRozeniteDomainAgentTool(pluginId, toolOptions); | ||
| } | ||
| /** | ||
| * Registers an agent tool under the `app` domain so external agents (e.g. CLI, Cursor) | ||
| * can invoke it via the Rozenite devtools bridge. | ||
| * | ||
| * The tool is qualified as `app.{tool.name}`. It is registered when the component | ||
| * mounts (and `enabled` is true) and unregistered on unmount. | ||
| * | ||
| * @typeParam TInput - Type of the arguments passed to the tool handler (default: `unknown`). | ||
| * @typeParam TOutput - Type of the value returned by the handler (default: `unknown`). | ||
| * @param options - Configuration: `tool` (AgentTool), `handler`, and optional `enabled`. | ||
| */ | ||
| export function useRozeniteInAppAgentTool(options) { | ||
| const { ...toolOptions } = options; | ||
| useRozeniteDomainAgentTool(APP_DOMAIN, toolOptions); | ||
| } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
182
38.93%12831
-66.2%6
-53.85%1
Infinity%+ Added
+ Added
- Removed
- Removed
Updated