@teable/agent-gateway 0.0.0-stage → 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Teable, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,39 @@
1
- # Temporary Holding Version
1
+ # @teable/agent-gateway
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The agent gateway in a person's Teable sandbox. It dials the person's agent
4
+ hub on Teable, so the sandbox opens no port, and on the hub's request starts
5
+ one [ACP](https://agentclientprotocol.com) agent per session in the app's
6
+ checkout, relaying ACP's JSON-RPC both ways unchanged. Teable's builder shows
7
+ the sessions; agents keep theirs on the sandbox's disk and resume them after a
8
+ restart (`session/load`).
9
+
10
+ ```sh
11
+ teable-agent-gateway
12
+ ```
13
+
14
+ It runs until it is stopped or a newer gateway replaces it (exit code 0), or
15
+ until Teable refuses its token or its protocol, or its token expires (exit
16
+ code 1): then only a fresh start with a fresh token helps.
17
+
18
+ It runs with Bun or Node 22.4 and later, and installs nothing. Teable starts
19
+ it with:
20
+
21
+ | Variable | What |
22
+ | --------------------------- | ------------------------------------------------------------------------- |
23
+ | `TEABLE_NEXT_AGENT_URL` | The hub: `wss://<Teable host>/api/v4/agent/gateway` |
24
+ | `TEABLE_NEXT_GATEWAY_TOKEN` | The gateway token the hub accepts |
25
+ | `TEABLE_ENDPOINT` | Teable, as the sandbox reaches it |
26
+ | `TEABLE_TOKEN` | The person's own token, for model tokens and for `teable-next` |
27
+ | `TEABLE_NEXT_ENDPOINT` | Optional: where teable-next is served, when `TEABLE_ENDPOINT` is internal |
28
+
29
+ Apps are checked out in `~/apps/<appId>` with `teable-next clone`
30
+ ([`@teable/next-cli`](https://www.npmjs.com/package/@teable/next-cli)); the
31
+ gateway keeps its own files in `~/.teable-agent-gateway`. Its agent today is
32
+ grok-build (`grok agent --always-approve stdio`), configured to reach nothing
33
+ but Teable's AI proxy, with a model token per session that the gateway renews.
34
+ It acts without asking, but when it asks the person a question, or to approve
35
+ its plan, the gateway puts that to them in Teable's builder and gives the
36
+ answer back.
37
+
38
+ `@teable/agent-gateway/protocol` holds the types of what travels between the
39
+ gateway, the hub and the builder.
@@ -0,0 +1,33 @@
1
+ import { type AcpMessage, type JsonRpcId } from "./protocol.js";
2
+ import type { AskShim } from "./shims.js";
3
+ interface AgentStart {
4
+ command: string;
5
+ args: string[];
6
+ cwd: string;
7
+ env: NodeJS.ProcessEnv;
8
+ /** What the agent says, for the hub. */
9
+ onMessage(message: AcpMessage): void;
10
+ /** The process ended, and why. */
11
+ onExit(message: string): void;
12
+ log(line: string): void;
13
+ /** The vendor requests with which the agent asks the person, by method (shims.ts). */
14
+ asks?: Readonly<Record<string, AskShim>>;
15
+ }
16
+ export declare class AgentProcess {
17
+ #private;
18
+ constructor(start: AgentStart);
19
+ get running(): boolean;
20
+ /** The hub's prompts the agent is working on. */
21
+ get prompts(): JsonRpcId[];
22
+ /** A request of the gateway's own; rejects with the agent's error, or when it takes too long. */
23
+ request(method: string, params: unknown, timeoutMs: number): Promise<unknown>;
24
+ /** A request whose replayed updates the hub must not see again: `session/load`. */
25
+ load(params: unknown, timeoutMs: number): Promise<unknown>;
26
+ /** Relay the hub's message to the agent: unchanged, but an answer to what a shim asked, in the agent's words. */
27
+ send(message: AcpMessage): void;
28
+ /** Stop reading what the agent says (its writes then wait), and read on. */
29
+ pause(): void;
30
+ resume(): void;
31
+ kill(): void;
32
+ }
33
+ export {};
@@ -0,0 +1,24 @@
1
+ import type { ModelKey } from "./platform.js";
2
+ import type { AgentCapabilities, AgentName } from "./protocol.js";
3
+ import { type AskShim } from "./shims.js";
4
+ /** What a session's agent is prepared with. */
5
+ interface AgentContext {
6
+ /** The gateway's own directory: agents keep their state under it. */
7
+ stateDir: string;
8
+ key: ModelKey;
9
+ /** The file holding the session's model token, kept fresh by the gateway. */
10
+ tokenFile: string;
11
+ }
12
+ interface AgentDefinition {
13
+ capabilities: AgentCapabilities;
14
+ command: string;
15
+ args: string[];
16
+ /** Write the agent's configuration for a session; the environment to start it with. */
17
+ prepare(context: AgentContext): Record<string, string>;
18
+ /** Its vendor requests that ask the person, by method, and the shims that relay them (shims.ts). */
19
+ asks?: Readonly<Record<string, AskShim>>;
20
+ }
21
+ /** Write a file whole or not at all: an agent starting meanwhile reads the old one or the new one. */
22
+ export declare function writeAtomically(path: string, text: string, mode?: number): void;
23
+ export declare const AGENTS: Record<AgentName, AgentDefinition>;
24
+ export {};
@@ -0,0 +1,13 @@
1
+ /** Where the agent works, and what it must be told first, if anything. */
2
+ interface Checkout {
3
+ cwd: string;
4
+ /** Prepended to the session's first prompt; null when the checkout speaks for itself. */
5
+ rules: string | null;
6
+ }
7
+ /**
8
+ * The app's checkout under `home`, cloned first if it is missing. The CLI
9
+ * gets `env`: the person's token and where Teable is (TEABLE_TOKEN,
10
+ * TEABLE_ENDPOINT, TEABLE_NEXT_ENDPOINT).
11
+ */
12
+ export declare function checkout(home: string, appId: string, env: NodeJS.ProcessEnv, log: (line: string) => void): Promise<Checkout>;
13
+ export {};
@@ -0,0 +1,47 @@
1
+ // src/protocol.ts
2
+ var GATEWAY_PATH = "/api/v4/agent/gateway";
3
+ var AGENT_PROTOCOL = 1;
4
+ var PING = "ping";
5
+ var PONG = "pong";
6
+ var GATEWAY_CLOSE = { replaced: 4e3, expired: 4001, unsupported: 4002 };
7
+ var SESSION_ID = /^ses[0-9A-Za-z]{16}$/;
8
+ var ACP = {
9
+ initialize: "initialize",
10
+ newSession: "session/new",
11
+ loadSession: "session/load",
12
+ prompt: "session/prompt",
13
+ cancel: "session/cancel",
14
+ update: "session/update",
15
+ requestPermission: "session/request_permission"
16
+ };
17
+ var ASK = {
18
+ /** Questions for the person (AgentQuestionRequest), answered with an AgentQuestionOutcome. */
19
+ question: "_teable/question",
20
+ /** A plan for the person to approve before the agent acts on it (AgentPlanRequest), answered with an AgentPlanOutcome. */
21
+ plan: "_teable/plan"
22
+ };
23
+ function isAcpRequest(message) {
24
+ return "method" in message && "id" in message;
25
+ }
26
+ function isAcpNotification(message) {
27
+ return "method" in message && !("id" in message);
28
+ }
29
+ function isAcpResponse(message) {
30
+ return !("method" in message) && "id" in message;
31
+ }
32
+ var AGENT_NAMES = ["grok"];
33
+
34
+ export {
35
+ GATEWAY_PATH,
36
+ AGENT_PROTOCOL,
37
+ PING,
38
+ PONG,
39
+ GATEWAY_CLOSE,
40
+ SESSION_ID,
41
+ ACP,
42
+ ASK,
43
+ isAcpRequest,
44
+ isAcpNotification,
45
+ isAcpResponse,
46
+ AGENT_NAMES
47
+ };
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};