@locusai/locus-gateway 0.22.13
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/commands.d.ts +14 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/executor.d.ts +44 -0
- package/dist/executor.d.ts.map +1 -0
- package/dist/formatter.d.ts +14 -0
- package/dist/formatter.d.ts.map +1 -0
- package/dist/gateway.d.ts +50 -0
- package/dist/gateway.d.ts.map +1 -0
- package/dist/index.cjs +592 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +550 -0
- package/dist/router.d.ts +14 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/tracker.d.ts +25 -0
- package/dist/tracker.d.ts.map +1 -0
- package/dist/types.d.ts +180 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +46 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core type definitions for the Locus Gateway.
|
|
3
|
+
*
|
|
4
|
+
* These interfaces define the contract between the gateway core
|
|
5
|
+
* and platform-specific adapters (Telegram, Discord, WhatsApp, etc.).
|
|
6
|
+
*/
|
|
7
|
+
import type { ChildProcess } from "node:child_process";
|
|
8
|
+
/** Every platform implements this interface to bridge messages into the gateway. */
|
|
9
|
+
export interface PlatformAdapter {
|
|
10
|
+
/** Platform identifier (e.g., "telegram", "discord", "whatsapp"). */
|
|
11
|
+
readonly platform: string;
|
|
12
|
+
/** Start listening for messages. */
|
|
13
|
+
start(): Promise<void>;
|
|
14
|
+
/** Stop the adapter gracefully. */
|
|
15
|
+
stop(): Promise<void>;
|
|
16
|
+
/** Send a message to a session. */
|
|
17
|
+
send(sessionId: string, message: OutboundMessage): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Edit a previously sent message (if supported).
|
|
20
|
+
* Adapters that don't support editing should omit this method.
|
|
21
|
+
*/
|
|
22
|
+
edit?(sessionId: string, messageId: string, message: OutboundMessage): Promise<void>;
|
|
23
|
+
/** Platform capabilities — informs the gateway how to format output. */
|
|
24
|
+
capabilities: PlatformCapabilities;
|
|
25
|
+
}
|
|
26
|
+
/** Declares what a platform supports so the gateway can adapt its output. */
|
|
27
|
+
export interface PlatformCapabilities {
|
|
28
|
+
/** Whether sent messages can be edited (streaming via edit). */
|
|
29
|
+
supportsEditing: boolean;
|
|
30
|
+
/** Whether inline action buttons are supported. */
|
|
31
|
+
supportsInlineButtons: boolean;
|
|
32
|
+
/** Whether Markdown formatting is supported. */
|
|
33
|
+
supportsMarkdown: boolean;
|
|
34
|
+
/** Whether HTML formatting is supported. */
|
|
35
|
+
supportsHTML: boolean;
|
|
36
|
+
/** Whether file uploads are supported. */
|
|
37
|
+
supportsFileUpload: boolean;
|
|
38
|
+
/** Maximum message length (chars) before splitting. */
|
|
39
|
+
maxMessageLength: number;
|
|
40
|
+
/** Whether the platform can "stream" output by editing messages in place. */
|
|
41
|
+
supportsStreaming: boolean;
|
|
42
|
+
}
|
|
43
|
+
/** A message arriving from a platform into the gateway. */
|
|
44
|
+
export interface InboundMessage {
|
|
45
|
+
/** Platform identifier. */
|
|
46
|
+
platform: string;
|
|
47
|
+
/** Platform-specific chat/channel ID (string for cross-platform compat). */
|
|
48
|
+
sessionId: string;
|
|
49
|
+
/** Platform-specific user ID. */
|
|
50
|
+
userId: string;
|
|
51
|
+
/** Message text content. */
|
|
52
|
+
text: string;
|
|
53
|
+
/** Optional file attachments. */
|
|
54
|
+
attachments?: Attachment[];
|
|
55
|
+
/** ID of the message being replied to (if any). */
|
|
56
|
+
replyTo?: string;
|
|
57
|
+
/** Platform-specific extra data. */
|
|
58
|
+
metadata?: Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
/** A message going from the gateway to a platform. */
|
|
61
|
+
export interface OutboundMessage {
|
|
62
|
+
/** Message text content. */
|
|
63
|
+
text: string;
|
|
64
|
+
/** Desired format — the adapter will convert if the platform doesn't support it. */
|
|
65
|
+
format: "plain" | "markdown" | "html";
|
|
66
|
+
/** Platform-agnostic actions (buttons, links). */
|
|
67
|
+
actions?: Action[];
|
|
68
|
+
/** File attachments. */
|
|
69
|
+
attachments?: Attachment[];
|
|
70
|
+
}
|
|
71
|
+
/** A platform-agnostic action (button or link). */
|
|
72
|
+
export interface Action {
|
|
73
|
+
/** Unique identifier for callback routing. */
|
|
74
|
+
id: string;
|
|
75
|
+
/** Display text for the action. */
|
|
76
|
+
label: string;
|
|
77
|
+
/** Action type. */
|
|
78
|
+
type: "button" | "link";
|
|
79
|
+
/** URL for link-type actions. */
|
|
80
|
+
url?: string;
|
|
81
|
+
}
|
|
82
|
+
/** A file attachment. */
|
|
83
|
+
export interface Attachment {
|
|
84
|
+
/** Filename. */
|
|
85
|
+
name: string;
|
|
86
|
+
/** MIME type. */
|
|
87
|
+
mimeType: string;
|
|
88
|
+
/** File content as a Buffer, or a URL to download. */
|
|
89
|
+
content: Buffer | string;
|
|
90
|
+
}
|
|
91
|
+
/** A parsed slash command. */
|
|
92
|
+
export interface ParsedCommand {
|
|
93
|
+
type: "command";
|
|
94
|
+
command: string;
|
|
95
|
+
args: string[];
|
|
96
|
+
raw: string;
|
|
97
|
+
}
|
|
98
|
+
/** Free-text input (not a command). */
|
|
99
|
+
export interface FreeText {
|
|
100
|
+
type: "freetext";
|
|
101
|
+
text: string;
|
|
102
|
+
}
|
|
103
|
+
/** Context passed to command handlers. */
|
|
104
|
+
export interface RouteContext {
|
|
105
|
+
/** The platform the message came from. */
|
|
106
|
+
platform: string;
|
|
107
|
+
/** Session (chat/channel) ID. */
|
|
108
|
+
sessionId: string;
|
|
109
|
+
/** User ID. */
|
|
110
|
+
userId: string;
|
|
111
|
+
/** Platform capabilities. */
|
|
112
|
+
capabilities: PlatformCapabilities;
|
|
113
|
+
/** Send a reply back through the gateway. */
|
|
114
|
+
reply(message: OutboundMessage): Promise<void>;
|
|
115
|
+
/** Edit a previously sent message (if supported). Returns false if unsupported. */
|
|
116
|
+
editReply?(messageId: string, message: OutboundMessage): Promise<boolean>;
|
|
117
|
+
/** Platform-specific metadata from the inbound message. */
|
|
118
|
+
metadata?: Record<string, unknown>;
|
|
119
|
+
}
|
|
120
|
+
/** Result from executing a command. */
|
|
121
|
+
export interface CommandResult {
|
|
122
|
+
/** Output text. */
|
|
123
|
+
text: string;
|
|
124
|
+
/** Format of the output text. */
|
|
125
|
+
format: "plain" | "markdown" | "html";
|
|
126
|
+
/** Optional actions to include with the response. */
|
|
127
|
+
actions?: Action[];
|
|
128
|
+
/** Whether the output was streamed (for logging/telemetry). */
|
|
129
|
+
streaming?: boolean;
|
|
130
|
+
}
|
|
131
|
+
/** A tracked active command. */
|
|
132
|
+
export interface ActiveCommand {
|
|
133
|
+
/** Unique tracking ID. */
|
|
134
|
+
id: string;
|
|
135
|
+
/** Command name. */
|
|
136
|
+
command: string;
|
|
137
|
+
/** Command arguments. */
|
|
138
|
+
args: string[];
|
|
139
|
+
/** Associated subprocess (if any). */
|
|
140
|
+
childProcess: ChildProcess | null;
|
|
141
|
+
/** When the command started. */
|
|
142
|
+
startedAt: Date;
|
|
143
|
+
}
|
|
144
|
+
/** Exclusivity group for concurrent command management. */
|
|
145
|
+
export type ExclusivityGroup = "workspace" | "git";
|
|
146
|
+
/** Returned when a command is blocked by an exclusive conflict. */
|
|
147
|
+
export interface ConflictResult {
|
|
148
|
+
blocked: true;
|
|
149
|
+
runningCommand: ActiveCommand;
|
|
150
|
+
group: ExclusivityGroup;
|
|
151
|
+
}
|
|
152
|
+
/** Maps command names to CLI arguments. */
|
|
153
|
+
export interface CommandDefinition {
|
|
154
|
+
/** The locus CLI arguments for this command. */
|
|
155
|
+
cliArgs: string[];
|
|
156
|
+
/** Whether this command produces streaming output. */
|
|
157
|
+
streaming: boolean;
|
|
158
|
+
/** If set, the command requires arguments. Value is the help message. */
|
|
159
|
+
requiresArgs?: string;
|
|
160
|
+
}
|
|
161
|
+
/** Events emitted by the gateway. */
|
|
162
|
+
export type GatewayEvent = {
|
|
163
|
+
type: "message_received";
|
|
164
|
+
message: InboundMessage;
|
|
165
|
+
} | {
|
|
166
|
+
type: "command_started";
|
|
167
|
+
sessionId: string;
|
|
168
|
+
command: string;
|
|
169
|
+
args: string[];
|
|
170
|
+
} | {
|
|
171
|
+
type: "command_completed";
|
|
172
|
+
sessionId: string;
|
|
173
|
+
command: string;
|
|
174
|
+
exitCode: number;
|
|
175
|
+
} | {
|
|
176
|
+
type: "error";
|
|
177
|
+
error: Error;
|
|
178
|
+
context?: string;
|
|
179
|
+
};
|
|
180
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIvD,oFAAoF;AACpF,MAAM,WAAW,eAAe;IAC9B,qEAAqE;IACrE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B,oCAAoC;IACpC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB,mCAAmC;IACnC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtB,mCAAmC;IACnC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjE;;;OAGG;IACH,IAAI,CAAC,CACH,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB,wEAAwE;IACxE,YAAY,EAAE,oBAAoB,CAAC;CACpC;AAED,6EAA6E;AAC7E,MAAM,WAAW,oBAAoB;IACnC,gEAAgE;IAChE,eAAe,EAAE,OAAO,CAAC;IACzB,mDAAmD;IACnD,qBAAqB,EAAE,OAAO,CAAC;IAC/B,gDAAgD;IAChD,g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|
4
|
+
"description": "Channel-agnostic message gateway for Locus platform adapters",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "bun build ./src/index.ts --outdir ./dist --target node --format esm && bun build ./src/index.ts --outfile ./dist/index.cjs --target node --format cjs && tsc -p tsconfig.build.json --emitDeclarationOnly",
|
|
26
|
+
"typecheck": "tsc --noEmit",
|
|
27
|
+
"lint": "biome lint .",
|
|
28
|
+
"format": "biome format --write .",
|
|
29
|
+
"clean": "rm -rf dist node_modules"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@locusai/sdk": "^0.22.13"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"typescript": "^5.8.3"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"locusai-package",
|
|
39
|
+
"locus",
|
|
40
|
+
"gateway"
|
|
41
|
+
],
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=18"
|
|
44
|
+
},
|
|
45
|
+
"license": "MIT"
|
|
46
|
+
}
|