An oil monkey-based multi-web AI access agent interaction system

By combining the Tampermonkey bridging module with the Go local server, the problem of unified management and security isolation between multiple WebAI platforms is solved. This enables unified registration, initialization, tool call authentication, and configuration persistence for sessions, thereby improving system security and session continuity.

CN123048108APending Publication Date: 2026-11-06GUIYANG LONGMASTER INFORMATION & TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611332440.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-31
Publication Date
2026-11-06

AI Technical Summary

Technical Problem

In existing technologies, there is a lack of unified management among multiple WebAI platforms, making it impossible to uniformly monitor, switch, and schedule sessions in a local interface. This results in security isolation issues, non-persistent configurations, and the inability to recover sessions after network disconnection.

Method used

The Tampermonkey bridging module works in conjunction with a local Go server to achieve long WebSocket connections. Through modules such as registration, session management, tool call authentication and security control, and client configuration persistence, it enables unified management and secure isolation of multiple WebAI sessions. It also uses an SQLite database for persistent configuration and supports reconnection after disconnection.

Benefits of technology

It achieves unified registration, initialization, tool call authentication, configuration persistence, and reconnection after disconnection for multiple WebAI sessions, solving the problem of inconsistent session management, improving security and session continuity, and meeting the traceability requirements of enterprise-level applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123048108A_ABST
    Figure CN123048108A_ABST
Patent Text Reader

Abstract

The application provides an intelligent agent interaction system based on oil monkey multi-WebAI access, comprising an oil monkey bridging module with embedded WebAI page deployed on a browser end, the oil monkey bridging module comprising a registration module, a DOM injection communication module and a keep-alive reconnection module; a Go local server comprising an HTTP external interface, a WebSocket service, and a registration module, a session management module, a directory switching module, a tool calling authentication and security control module, a tool executor module, a client configuration persistence module, a connection keep-alive and disconnection reconnection management module, a log auditing module, a WebAI state management module and a session history management module driven by the WebSocket service; a local Web management page in communication with the Go local server through the HTTP external interface; the tool calling authentication and security control module is used for authenticating and checking tool calling messages before the tool executor module executes local tools; and the problem that multi-WebAI sessions cannot be uniformly managed is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of artificial intelligence interaction, and in particular relates to an intelligent agent interaction system based on multiple WebAI access from Tampermonkey. Background Technology

[0002] With the rapid development of Large Language Model (LLM) technology, various web-based AI services have emerged. Users often need to switch between multiple different WebAI platforms to obtain the best question-answering results. However, existing technologies have the following drawbacks: (1) Lack of unified central management: Each WebAI page is independent of the others, and users cannot monitor, switch and schedule multiple WebAI sessions in a unified local management interface; (2) Lack of security isolation for local tool calls: When WebAI needs to call the local file system or execute local commands, existing solutions usually directly expose the complete system path, which poses a serious risk of unauthorized access and high-risk command execution. (3) Configuration cannot be persisted: After the service restarts, all personalized configurations of the client (allowed toolsets, security policies, working directories, etc.) are lost and need to be re-initialized; (4) Session cannot be recovered after network disconnection: After the WebSocket connection is disconnected due to network jitter, the existing solution usually requires to go through the entire registration process again, resulting in the loss of session context. Summary of the Invention

[0003] The purpose of this embodiment is to provide an intelligent agent interaction system based on Tampermonkey for multi-WebAI access, in order to solve the problem of the inability to manage multiple WebAI sessions in a unified manner.

[0004] A multi-WebAI access intelligent agent interaction system based on Tampermonkey includes: On the browser side, a Tampermonkey bridging module embedded in the WebAI page is deployed. The Tampermonkey bridging module includes a registration module, a DOM injection communication module, and a keep-alive and reconnect module. The Go local server includes an HTTP external interface, a WebSocket service, and a registration module, a session management module, a directory switching module, a tool call authentication and security control module, a tool executor module, a client configuration persistence module, a connection keep-alive and disconnection reconnection management module, a log auditing module, a WebAI state management module, and a session history management module driven by the WebSocket service. The local web management page communicates with the local Go server through the HTTP external interface. The Tampermonkey bridging module establishes a long connection with the WebSocket service of the Go local server via WebSocket; The registration module is used to receive the registration message carrying the clientId reported by the Tampermonkey bridging module, and return a registration response carrying the initialization configuration and the local tool call directory prefix to the Tampermonkey bridging module; The tool call authentication and security control module is used to authenticate and verify the tool call message before the tool executor module executes the local tool; The client configuration persistence module is used to persistently store the configuration information of each clientId, and to provide the connection keep-alive and disconnection reconnection management module with the information to restore the session context during disconnection and reconnection.

[0005] Furthermore, the registration module receives a registration message including clientId, pageUrl, and title; the registration response is REGISTER_ACK; and the initialization configuration includes the allowed tool set, tool call parameter specifications, local machine operation security specifications, and tool message protocol.

[0006] Furthermore, the tool message protocol stipulates that the tool call content is marked with TOOLB as the prefix and TOOLE as the suffix, and the tool call JSON parameters inside the package are Base64 encoded.

[0007] Furthermore, the tool's authentication and security control module includes: The tool blacklist / whitelist verification unit is used to maintain a list of tools that are allowed or prohibited from being called by clientId; The parameter validation unit is used to perform regular expression validation on file paths and intercept high-risk commands. The interception notification unit is used to return a TOOL_DENY message to the Tampermonkey bridging module when authentication fails.

[0008] Furthermore, the tool executor module includes: The message parsing unit is used to identify TOOLB / TOOLE tags and Base64 decode them to extract JSON data that the tool calls. The path concatenation unit is used to concatenate the relative path in the tool call JSON with the work_dir_prefix maintained by the directory switching module to form an absolute path; The execution unit is used to perform local file reading and writing, directory listing, or restricted command calls after the tool call authentication and security control module has passed the verification, and to set timeout control.

[0009] Furthermore, the directory switching module is used for: Maintain the local tool operation directory prefix work_dir_prefix corresponding to each clientId; The system receives a directory change request from an HTTP interface, updates the work_dir_prefix, and sends a DIR_UPDATE message to the Tampermonkey bridging module via WebSocket, so that the DOM injection communication module updates the effective directory prefix within the page.

[0010] Furthermore, the client configuration persistence module uses an SQLite local file database to store the initialization configuration, allowed toolset, security policy, and working directory prefix for each clientId; when the connection keep-alive and disconnection reconnection management module detects that Tampermonkey has initiated a reconnection with the original clientId, it reads the corresponding configuration from the SQLite to restore the session context and returns RECONNECT_ACK.

[0011] Furthermore, the connection keep-alive and disconnection reconnection management module includes: The heartbeat detection unit is used to periodically send ping heartbeat packets to the Tampermonkey bridging module and wait for pong responses; if the timeout occurs, the connection is determined to be disconnected. Disconnection differentiation unit is used to distinguish between temporary network jitter disconnection and actual tab closure; The session recovery unit is used to skip the full registration initialization process and directly restore the session state during reconnection.

[0012] Furthermore, the log auditing module is used to record registration, reconnection, directory changes, message sending and receiving, tool calls, tool interception, and status change events throughout the entire process; each audit log includes a timestamp, clientId, event type, original message, execution result, and whether it was intercepted.

[0013] Furthermore, the local web management page performs the following operations through the HTTP external interface: retrieves the list of registered WebAIs and displays it using a dropdown selection method; sends a chat message to the specified clientId; Modify the local working directory prefix and tool security policy for the specified clientId; query session history and audit logs.

[0014] This invention provides an intelligent agent interaction system based on Tampermonkey for multi-WebAI access. By establishing a bridge layer on the browser side through Tampermonkey scripts, it communicates with a local Go-language server via a WebSocket long connection, realizing unified registration, initialization, tool call authentication, configuration persistence, disconnection reconnection, and log auditing for multiple WebAI sessions, thus solving the problem of the inability to manage multiple WebAI sessions in a unified manner.

[0015] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description

[0016] Figure 1 : This is an overall architecture diagram provided for an embodiment of the present invention; Figure 2 : This is a sequence diagram of session registration and initialization provided in an embodiment of the present invention; Figure 3 : A flowchart illustrating the tool invocation authentication and execution process provided in this embodiment of the invention; Figure 4 : A flowchart of disconnection reconnection and configuration recovery provided in an embodiment of the present invention; Figure 5 : A flowchart of dynamic directory change and configuration persistence provided in an embodiment of the present invention. Detailed Implementation

[0017] The technical solutions of the present invention will now be described with reference to the accompanying drawings in the embodiments of the present invention.

[0018] I. This invention provides an intelligent agent interaction system based on Tampermonkey with multi-WebAI access (see...) Figure 1 The system consists of two main parts: a browser-based application and a local Go server.

[0019] 1.1 Browser side: The browser side has a local web management page and a Tampermonkey bridging module embedded in each WebAI page.

[0020] The local web management page communicates with the Go local server's HTTP external interface via the HTTP protocol, providing the following functions: selecting registered WebAI instances from a dropdown menu, initiating chat messages, viewing the running status of each WebAI instance, viewing session history, changing the local working directory prefix, configuring tool security policies, and viewing audit logs.

[0021] The oil monkey bridging module further includes: Registration module: After the WebAI page is loaded, a unique `clientId` is automatically generated, and a `REGISTER` registration data packet is sent to the Go service via WebSocket, carrying parameters including `clientId` (unique client identifier), `pageUrl` (WebAI page address), and `title` (page title, used to manage the drop-down list display on the page).

[0022] DOM Injection Communication Module: By manipulating the Document Object Model (DOM) of the WebAI page, it enables the input of messages to WebAI and the reading of AI output responses; it is also responsible for recognizing and parsing tool call messages wrapped in `TOOLB` / `TOOLE` tags, performing Base64 decoding on the intermediate content to extract the tool call JSON; it receives `DIR_UPDATE` messages to update the local directory prefix `work_dir_prefix` in memory, and notifies WebAI that subsequent tool call paths must be appended with this prefix.

[0023] Keep-alive and reconnect module: periodically sends a `PONG` heartbeat response to the Go service; detects WebSocket disconnection events, retains the original `clientId`, and automatically initiates reconnection; after receiving a `RECONNECT_ACK` reconnection response, it restores the context without having to re-execute the complete registration and initialization process.

[0024] The Tampermonkey bridging module interacts in parallel with multiple WebAI page instances (WebAI-1, WebAI-2, WebAI-3, etc.), with each WebAI page corresponding to an independent bridging context.

[0025] 1.2 Go Local Server-Side: The Go local server serves as the system's central hub, providing two main communication entry points: an HTTP external interface and a WebSocket service. Internally, it consists of the following functional modules: Registration module: Receives WebSocket registration requests from Tampermonkey scripts, verifies the validity of the message format, stores client metadata (pageUrl, title, WebSocket connection handle) using `clientId` as a unique identifier, calls the state management module to set the initial state, calls the session management module to read the initialization configuration, calls the directory switching module to read `work_dir_prefix`, and returns a `REGISTER_ACK` registration response.

[0026] Directory switching module: Maintains the local tool operation directory prefix for each `clientId` corresponding to `work_dir_prefix`; provides the directory prefix to the registration response during the registration phase; receives HTTP interface requests to modify the specified client directory prefix; after the directory change is completed, calls the configuration persistence module to save it, and sends a `DIR_UPDATE` message to notify Tampermonkey and WebAI via WebSocket.

[0027] Tool Invocation Authentication and Security Control Module (New High-Priority Module): Located after session management receives the tool invocation message and before the tool executor executes; maintains a blacklist and whitelist for each `clientId` tool; performs regular expression validation on file paths and intercepts high-risk commands; directly intercepts risky operations and returns a `TOOL_DENY` message; pushes all allowed / intercepted events to the log audit module; supports configuring security policies for HTTP interfaces by `clientId`.

[0028] Tool Executor Module (New High-Priority Module): Parses `TOOLB+base64+TOOLE` messages, decodes them using Base64 to obtain the tool call JSON; reads the `work_dir_prefix` from the directory switching module and concatenates the file path; calls the security control module for authentication verification, returning an error directly if verification fails; executes local tool logic such as file reading and writing, directory listing, and restricted command calls; sets timeout controls to prevent tool execution from freezing; encapsulates the execution results into a message and sends it back to the session management module, which then stores it in the session history and audit logs.

[0029] Client configuration persistence module (new high-priority module): Uses SQLite local file database as storage medium, eliminating the need for additional database service deployment; persisted content includes initial configuration, allowed toolsets, security policies, and working directory prefix for each `clientId`; writes to the database during registration, configuration changes, and directory changes; reads the database to restore all client configurations when the service starts or reconnects after a disconnection, resolving the issue of configuration loss caused by service restart due to the original in-memory storage.

[0030] Connection keep-alive and reconnection management module (new high-priority module): It periodically sends `ping` heartbeat packets at the WebSocket layer, waits for the Tampermonkey `pong` response, and determines the connection is broken upon timeout; it distinguishes between temporary network jitter disconnections and actual tab destruction / closing; when Tampermonkey reconnects with the original `clientId`, it reads the persistent configuration to directly restore the session, skipping the complete registration process; it notifies the state management module to update the client state; and it sends events to the audit log.

[0031] Log auditing module (new high-priority module): Records events across the entire chain, including registration, reconnection, directory changes, message sending and receiving, tool calls, tool interception, and status changes; each log entry includes fields such as timestamp, `clientId`, event type, original message, execution result, and whether it was intercepted; supports outputting log files to local disks; provides an HTTP interface for querying audit logs via a web management page.

[0032] The WebAI state management module maintains the running status of each WebAI client. The state enumeration includes `online` (connection is normal), `idle` (available to receive new conversations), `busy` (working on a conversation), and `offline` (tab closed or WebSocket disconnected). When the WebSocket connection is disconnected, the state is set to `offline`, but historical session data and persistent configuration are retained.

[0033] Session Management Module: Binds `clientId` to session instances; reads WebAI initialization parameters (tool limitations, operation specifications) configured in the management interface; interfaces with the directory switching module to synchronize directory prefixes during registration / directory changes; receives chat commands from the Web management page and forwards them to the corresponding Tampermonkey client via WebSocket routing; receives tool call messages reported by Tampermonkey, forwards them for verification by the security control module, and hands them over to the tool executor after successful verification; supports manual start and stop control of sessions; receives AI responses and tool execution results and sends them to the session history module and audit log module.

[0034] The conversation history management module stores conversation records using `clientId` as the isolation dimension; message fields include `role` (role), `content` (message content), and `timestamp` (time stamp); tool calls are also stored in the conversation history; and it provides interfaces for querying and clearing the history.

[0035] II. Session Registration and Initialization Process: Reference Figure 2 The session registration and initialization process includes the following steps: Step S101: The WebAI page is loaded. The Tampermonkey bridging registration module generates a unique `clientId`, and the keep-alive reconnection module starts the WebSocket heartbeat.

[0036] Step S102: Tampermonkey sends a `REGISTER` registration data packet to the Go service via WebSocket. An example of the JSON format is as follows: json { "type": "REGISTER", "clientId": "ai_xxxxxx", "pageUrl": "https: / / xxx-webai.com / chat", Title: GPT-4o Web Version} ``` Step S103: The Go registration module receives the registration message and calls the configuration persistence module to read the existing configuration of the `clientId`; the session management module simultaneously reads the `work_dir_prefix` from the directory switching module and the client initialization configuration maintained by the management interface.

[0037] Step S104: The session management module reads the WebAI initialization content corresponding to the `clientId` from the local Web management interface. The initialization content preferably includes: a limited set of subsequently available WebAI tools (which tools are allowed to be called), a specification of tool parameter calls, a local machine operation security specification, a local tool call directory prefix `work_dir_prefix`, and a tool JSON packet sending protocol.

[0038] Step S105: The session management module reads the local directory prefix `work_dir_prefix` from the directory switching module.

[0039] Step S106: The Go registration module returns a `REGISTER_ACK` registration response to Tampermonkey, carrying the initialization configuration and the `work_dir_prefix` payload.

[0040] Step S107: After receiving the initialization configuration and `work_dir_prefix`, Tampermonkey injects the output format constraints, tool message protocol, and directory prefix into the WebAI page context.

[0041] Step S108: After the WebAI page receives all initialization constraints, it sends an `INIT_CONFIRM` confirmation message to Tampermonkey.

[0042] Step S109: Tampermonkey forwards the `INIT_CONFIRM` confirmation message to the Go service.

[0043] Step S110: The Go service marks the session initialization as complete, sets the status to `idle`, and the log auditing module records the initialization completion event.

[0044] Preferably, the tool JSON packet sending protocol specifies that: the tool call content is wrapped by the `TOOLB` and `TOOLE` tags; the tool call JSON parameters inside the package are Base64 encoded to prevent string conflicts between the tool parameter content and the `TOOLB` / `TOOLE` identifiers.

[0045] For example, the tool call message format is as follows: ``` TOOLBeyJ0b29sX25hbWUiOiJmaWxlX3JlYWQiLCJwYXRoIjoiLi9kb2MvdGVzdC50eHQifQ==TOOLE ``` The middle string is the result of the tool calling JSON after Base64 encoding, and the file path needs to be concatenated with the `work_dir_prefix` issued by the service.

[0046] III. Tool Invocation Authentication and Execution Process: Reference Figure 3 When WebAI output contains a tool invocation intent, the following process is executed: Step S201: The Tampermonkey DOM injection communication module detects the `TOOLB` and `TOOLE` tags in the AI ​​output text, extracts the Base64 string between the two tags, and decodes it to obtain the original tool call JSON.

[0047] Step S202: Tampermonkey reports the tool call message to the Go service via WebSocket.

[0048] Step S203: The Go session management module receives the tool call message.

[0049] Step S204: The session management module sends the tool call to the tool call authentication and security control module for verification. The verification preferably includes: tool blacklist / whitelist verification (determining whether the `clientId` is allowed to call this tool), file path regular expression verification (determining whether the path contains illegal crossing characters such as `.. / `), and high-risk command interception (determining whether the command belongs to system-level dangerous operations).

[0050] Step S205: Determine whether the verification passes.

[0051] If the verification fails, proceed to step S206: the security control module returns a `TOOL_DENY` message to notify WebAI that the tool call was rejected, and the log audit module records the interception event.

[0052] If the verification passes, proceed to step S207: The tool executor module reads the `work_dir_prefix` from the directory switching module, concatenates it with the relative path in the tool's JSON to form an absolute operation path; executes local tool logic (such as file reading and writing, directory listing, and restricted command invocation); and sets timeout controls to prevent the tool from freezing.

[0053] Step S208: The tool executor sends the execution result back to the session management module.

[0054] Step S209: The session management module sends the tool execution result to the session history management module for storage and pushes it to the log audit module for recording; at the same time, it sends the result back to Tampermonkey via WebSocket, and Tampermonkey injects the result into the WebAI page, forming a complete tool call loop.

[0055] IV. Disconnection Reconnection and Configuration Recovery Process: Reference Figure 4 This system has designed a complete reconnection mechanism for scenarios with unstable networks: Network branch disconnected abnormally: Step S301: The WebSocket connection was abnormally disconnected due to network jitter.

[0056] Step S302: The Go service connection keep-alive and disconnection reconnection management module detects a heartbeat timeout and determines that the connection is broken.

[0057] Step S303: The WebAI state management module sets the client state to `offline`, but retains historical session data and does not delete persistent configuration.

[0058] Step S304: The log audit module records the [disconnection event].

[0059] Step S305: The Tampermonkey keep-alive reconnection module retains the original `clientId` and starts the automatic reconnection timer.

[0060] Step S306: Tampermonkey initiates a WebSocket reconnection request carrying the original `clientId`.

[0061] Configure recovery branch: Step S307: The Go service receives the reconnection request and extracts the `clientId` from the message.

[0062] Step S308: Configure the persistence module to read all historical configurations of the `clientId` in SQLite, including allowed tool sets, security policies, and working directory prefix `work_dir_prefix`.

[0063] Step S309: The session management module restores the session context without having to re-execute the complete registration initialization process.

[0064] Step S310: The Go service returns a `RECONNECT_ACK` response to Tampermonkey indicating a successful reconnection.

[0065] Step S311: The state management module updates the client state to `online`, and the session is restored to the `idle` state.

[0066] Truly closing the branch on the tab: If the WebAI tab is actually closed by the user, causing the WebSocket to disconnect, and Tampermonkey does not initiate a reconnection within the scheduled time, the Go service will determine it as a non-reconnection scenario and set the status to `offline`, but will retain the session history and persistent configuration so that the user can quickly resume when opening the same WebAI page again.

[0067] V. Dynamic directory changes and configuration persistence process: Reference Figure 5 When a user needs to change the local working directory of a WebAI instance, the following process is executed: Step S401: The user submits a new local working directory prefix to the Go service directory switching module by calling the HTTP interface through the local web management interface.

[0068] Step S402: The directory switching module calls the configuration persistence module to write the new directory configuration to the SQLite database.

[0069] Step S403: Configure the persistence module and return a confirmation that persistence is complete.

[0070] Step S404: The directory switching module sends a `DIR_UPDATE` message to the corresponding Tampermonkey via WebSocket, carrying the new `work_dir_prefix`.

[0071] Step S405: Tampermonkey updates the local directory prefixes that are effective on the page, notifying WebAI that subsequent file-related operations must use the new prefix.

[0072] Step S406: The log audit module records the [directory prefix change event].

[0073] Preferably, all paths invoked by local file-related tools must be appended with `work_dir_prefix` to prevent unauthorized access to other directories in the system. The directory switching module maintains a unique directory prefix for each `clientId`, and changes are immediately announced via WebSocket without requiring re-registration.

[0074] VI. WebSocket Message Protocol The WebSocket message protocol defined in this system is shown in Table 1: Table 1 WebSocket Message Protocol | Message type | Direction | Description | | `REGISTER` | Tampermonkey → Go Service | Tampermonkey reports client registration information | | `REGISTER_ACK` | Go Service → Tampermonkey | Registration Response, carrying WebAI initialization configuration and local directory prefix | | `INIT_CONFIRM` | Tampermonkey → Go Service | WebAI Initialization Complete Confirmation | | `DIR_UPDATE` | Go Service → Tampermonkey | Local Directory Prefix Change Notification | | `PONG` | Tampermonkey → Go Service | Heartbeat Response | | `RECONNECT_ACK` | Go Service → Tampermonkey | Successful Reconnection Response | | `TOOL_DENY` | Go Service → Tampermonkey | Notification of tool call being blocked by security module | | `CHAT_OUT` | Go service → Tampermonkey | Send user question messages | | `CHAT_IN` | Tampermonkey → Go Service | Report AI response content, including TOOLB / TOOLE tool call messages | | `STATE_REPORT` | Tampermonkey → Go Service | Tampermonkey reports its own busy / idle status | VII. HTTP Interface Design: The local web management page interacts with the Go service through the following HTTP interfaces, as shown in Table 2: Table 2 HTTP Interface List | Interface | Request Method | Interface Description | | ` / api / clients` | GET | Retrieves a complete list of registered WebAI clients, returning `clientId`, `title`, `pageUrl`, and `state` for use in dropdown list rendering. | | ` / api / client / :clientId / config` | PUT | Sets the WebAI initialization configuration for the specified `clientId` (tool-specific, security-compliant) | | ` / api / client / :clientId / workdir` | PUT | Modifies the local tool operation directory prefix for the specified `clientId`, and sends `DIR_UPDATE` via WebSocket after the change. | ` / api / client / :clientId / tool_security` | PUT | Configure client tool security blacklists / whitelists and risk interception policies | | ` / api / client / :clientId / history` | GET | Retrieves the specified WebAI session history | | ` / api / send` | POST | Sends a chat message to the specified `clientId` | | ` / api / session / :clientId / stop` | POST | Stop the specified WebAI session | | ` / api / client / :clientId / clear_history` | POST | Clear the session history of the specified AI | | ` / api / audit / logs` | GET | Query system audit logs | VIII. Core Data Structures: The core data structures defined in this system are exemplified as follows: Registration data package (reported by Tampermonkey): ```go type RegisterMsg struct { Type string `json:"type"` ClientId string `json:"clientId"` PageUrl string `json:"pageUrl"` Title string `json:"title"` } ``` WebAI initialization configuration: ```go type WebAIInitConfig struct { AllowTools []string `json:"allow_tools"` ToolCallSpec string `json:"tool_call_spec"` LocalSafeRules string `json:"local_safe_rules"` ToolWrapPrefix string `json:"tool_wrap_prefix"` ToolWrapSuffix string `json:"tool_wrap_suffix"` WorkDirPrefix string `json:"work_dir_prefix"` } ``` Audit log recording structure: ```go type AuditLog struct { Timestamp int64 `json:"ts"` ClientId string `json:"clientId"` EventType string `json:"event_type"` Payload string `json:"payload"` Result string `json:"result"` } ``` AI status enumeration: ```go type AIState string const ( AIStateOnline AIState = "online" AIStateIdle AIState = "idle" AIStateBusy AIState = "busy" AIStateOffline AIState = "offline" ) ``` This invention provides an intelligent agent interaction system based on Tampermonkey with multi-WebAI access, which has the following advantages compared with existing technologies: (1) Unified central management: Through the cooperation of Go local server and Tampermonkey script, unified registration, status monitoring, session management and history query of multiple heterogeneous WebAI instances are realized, so that users do not need to manually switch between multiple browser tabs.

[0075] (2) Tool call security isolation: By using the `work_dir_prefix` directory prefix forced concatenation mechanism, combined with the blacklist and whitelist of the tool call authentication and security control module, path regular expression verification, and high-risk command interception, WebAI is effectively prevented from accessing the local file system or performing dangerous operations without authorization.

[0076] (3) Persistent configuration without loss: The complete configuration of each `clientId` is stored in a local SQLite database and is automatically restored after the service restarts, which solves the defect of traditional memory storage solutions that lose configurations upon restart.

[0077] (4) Automatic recovery after disconnection: Through keep-alive heartbeat and disconnection reconnection mechanism, after temporary disconnection caused by network jitter, Tampermonkey carries the original `clientId` and automatically reconnects. The Go service directly restores the session context from persistent storage without having to re-execute the complete registration initialization process, thus ensuring session continuity.

[0078] (5) Full-link auditability: The log audit module records events from registration, message sending and receiving, tool invocation, security interception to state change, which meets the compliance requirements of enterprise-level applications for operational traceability.

[0079] (6) Protocol compatibility: The `TOOLB+Base64+TOOLE` message wrapping protocol avoids string conflicts between tool parameter content and boundary markers, ensuring the robustness of tool call message parsing.

[0080] The above description is merely an embodiment of the present invention and is not intended to limit the scope of protection of the present invention. For those skilled in the art, the present invention can have various modifications and variations. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A multi-WebAI access intelligent agent interaction system based on Tampermonkey, characterized in that, include: On the browser side, a Tampermonkey bridging module embedded in the WebAI page is deployed. The Tampermonkey bridging module includes a registration module, a DOM injection communication module, and a keep-alive and reconnect module. The Go local server includes an HTTP external interface, a WebSocket service, and a registration module, a session management module, a directory switching module, a tool call authentication and security control module, a tool executor module, a client configuration persistence module, a connection keep-alive and disconnection reconnection management module, a log auditing module, a WebAI state management module, and a session history management module driven by the WebSocket service. The local web management page communicates with the local Go server through the HTTP external interface. The Tampermonkey bridging module establishes a long connection with the WebSocket service of the Go local server via WebSocket; The registration module is used to receive the registration message carrying the clientId reported by the Tampermonkey bridging module, and return a registration response carrying the initialization configuration and the local tool call directory prefix to the Tampermonkey bridging module; The tool call authentication and security control module is used to authenticate and verify the tool call message before the tool executor module executes the local tool; The client configuration persistence module is used to persistently store the configuration information of each clientId, and to provide the connection keep-alive and disconnection reconnection management module with the information to restore the session context during disconnection and reconnection.

2. The intelligent agent interaction system based on multiple WebAI access using Tampermonkey according to claim 1, characterized in that, The registration module receives a registration message including clientId, pageUrl, and title; the registration response is REGISTER_ACK; and the initialization configuration includes the allowed tool set, tool call parameter specifications, local machine operation security specifications, and tool message protocol.

3. The intelligent agent interaction system based on multiple WebAI access using Tampermonkey according to claim 2, characterized in that, The tool message protocol stipulates that the tool call content is marked with TOOLB as the prefix and TOOLE as the suffix and is wrapped, and the tool call JSON parameters inside the wrapper are Base64 encoded.

4. The intelligent agent interaction system based on multiple WebAI access using Tampermonkey according to claim 1, characterized in that, The tool invokes the authentication and security control module, including: The tool blacklist / whitelist verification unit is used to maintain a list of tools that are allowed or prohibited from being called by clientId; The parameter validation unit is used to perform regular expression validation on file paths and intercept high-risk commands. The interception notification unit is used to return a TOOL_DENY message to the Tampermonkey bridging module when authentication fails.

5. The intelligent agent interaction system based on multiple WebAI access using Tampermonkey according to claim 1, characterized in that, The tool executor module includes: The message parsing unit is used to identify TOOLB / TOOLE tags and Base64 decode them to extract JSON data that the tool calls. The path concatenation unit is used to concatenate the relative path in the tool call JSON with the work_dir_prefix maintained by the directory switching module to form an absolute path; The execution unit is used to perform local file reading and writing, directory listing, or restricted command calls after the tool call authentication and security control module has passed the verification, and to set timeout control.

6. The intelligent agent interaction system based on multiple WebAI access using Tampermonkey according to claim 1, characterized in that, The directory switching module is used for: Maintain the local tool operation directory prefix work_dir_prefix corresponding to each clientId; The system receives a directory change request from an HTTP interface, updates the work_dir_prefix, and sends a DIR_UPDATE message to the Tampermonkey bridging module via WebSocket, so that the DOM injection communication module updates the effective directory prefix within the page.

7. The intelligent agent interaction system based on multiple WebAI access using Tampermonkey according to claim 1, characterized in that, The client configuration persistence module uses an SQLite local file database to store the initialization configuration, allowed toolset, security policy, and working directory prefix for each clientId. When the connection keep-alive and disconnection reconnection management module detects that Tampermonkey has initiated a reconnection with the original clientId, it reads the corresponding configuration from the SQLite to restore the session context and returns RECONNECT_ACK.

8. The intelligent agent interaction system based on multiple WebAI access using Tampermonkey according to claim 7, characterized in that, The connection keep-alive and disconnection reconnection management module includes: The heartbeat detection unit is used to periodically send ping heartbeat packets to the Tampermonkey bridging module and wait for pong responses; if the timeout occurs, the connection is determined to be disconnected. Disconnection differentiation unit is used to distinguish between temporary network jitter disconnection and actual tab closure; The session recovery unit is used to skip the full registration initialization process and directly restore the session state during reconnection.

9. The intelligent agent interaction system based on multiple WebAI access using Tampermonkey according to claim 1, characterized in that, The log auditing module is used to record registration, reconnection, directory changes, message sending and receiving, tool calls, tool interception, and status change events throughout the entire process. Each audit log includes a timestamp, clientId, event type, original message, execution result, and whether it was intercepted.

10. The intelligent agent interaction system based on multiple WebAI access using Tampermonkey according to claim 1, characterized in that, The local web management page performs the following operations through the HTTP external interface: retrieves the list of registered WebAIs and displays it using a dropdown selection method; sends a chat message to a specified clientId; Modify the local working directory prefix and tool security policy for the specified clientId; query session history and audit logs.