@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.
@@ -0,0 +1,53 @@
1
+ import type { Platform } from "./platform.js";
2
+ /** How often things happen; tests shorten them. */
3
+ interface Timing {
4
+ reconnectMinMs: number;
5
+ reconnectMaxMs: number;
6
+ /** How often the gateway checks the socket is alive, and how long it waits for the answer. */
7
+ pingEveryMs: number;
8
+ pongWithinMs: number;
9
+ /** How often the sandbox is touched while a turn runs. */
10
+ touchEveryMs: number;
11
+ /** How long before a model token expires the gateway replaces it, and retries if that fails. */
12
+ refreshBeforeMs: number;
13
+ refreshRetryMs: number;
14
+ /** How long an agent with no turn running is kept; session/load brings it back. */
15
+ idleMs: number;
16
+ /** How long the agent may take to answer initialize, session/new and session/load. */
17
+ startMs: number;
18
+ }
19
+ export interface GatewayOptions {
20
+ /** TEABLE_NEXT_AGENT_URL. */
21
+ hubUrl: string;
22
+ /** TEABLE_NEXT_GATEWAY_TOKEN. */
23
+ token: string;
24
+ platform: Pick<Platform, "modelKey" | "touch">;
25
+ /** The person's home: apps are checked out in `apps/<appId>` under it. */
26
+ home: string;
27
+ /** Where the gateway keeps its files: agents' state, model tokens. */
28
+ stateDir: string;
29
+ /** The environment agents and the CLI start with (the gateway's own, less its token). */
30
+ env: NodeJS.ProcessEnv;
31
+ /** The package's version, for the hello. */
32
+ version: string;
33
+ log(line: string): void;
34
+ /**
35
+ * The gateway stopped for good: a newer gateway replaced it, or the hub
36
+ * refused it (`refused`: its token, refused or expired, or its protocol).
37
+ * A refused gateway can do nothing until it is started with a fresh token.
38
+ */
39
+ onStop?(stop: {
40
+ reason: string;
41
+ refused: boolean;
42
+ }): void;
43
+ timing?: Partial<Timing>;
44
+ }
45
+ export declare class Gateway {
46
+ #private;
47
+ readonly instance: `${string}-${string}-${string}-${string}-${string}`;
48
+ constructor(options: GatewayOptions);
49
+ start(): void;
50
+ /** Stop: the socket, every agent, every timer. */
51
+ stop(): void;
52
+ }
53
+ export {};
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The old platform's two routes the gateway calls (ADR 0006 §6), with the
3
+ * person's own temporary token (TEABLE_TOKEN):
4
+ *
5
+ * - `POST /api/teable-next/agent/model-key` with `{ baseId }`: an AI proxy
6
+ * token for this person and that project (the session's app), valid for
7
+ * an hour, whose credits go to the project's space; 403 without
8
+ * membership or teable-next, 404 for a project not in teable-next;
9
+ * - `POST /api/teable-next/agent/sandbox/touch`: keeps the sandbox up while a
10
+ * turn runs.
11
+ */
12
+ /** A model token, and where and what it reaches. */
13
+ export interface ModelKey {
14
+ token: string;
15
+ /** In milliseconds since the epoch. */
16
+ expiresAt: number;
17
+ /** The model the old platform's settings choose. */
18
+ model: string;
19
+ /** The AI proxy as an OpenAI client's base URL takes it. */
20
+ openaiBaseUrl: string;
21
+ /** The AI proxy as an Anthropic client's base URL takes it. */
22
+ anthropicBaseUrl: string;
23
+ }
24
+ /**
25
+ * When a token expires: an ISO 8601 date, or a number of milliseconds (or
26
+ * of seconds, if it is too small to be milliseconds) since the epoch.
27
+ */
28
+ export declare function expiryOf(value: unknown): number | undefined;
29
+ export declare class Platform {
30
+ #private;
31
+ constructor(endpoint: string, token: string);
32
+ /** A model token for the project `baseId` (an app's id). */
33
+ modelKey(baseId: string): Promise<ModelKey>;
34
+ touch(): Promise<void>;
35
+ }