@tapicker/bridge 1.0.0
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 +21 -0
- package/README.md +46 -0
- package/dist/bridge/bridge-service.d.ts +46 -0
- package/dist/bridge/bridge-service.js +245 -0
- package/dist/bridge/control.d.ts +7 -0
- package/dist/bridge/control.js +211 -0
- package/dist/bridge/daemon.d.ts +16 -0
- package/dist/bridge/daemon.js +97 -0
- package/dist/bridge/extension-session.d.ts +43 -0
- package/dist/bridge/extension-session.js +204 -0
- package/dist/bridge/pairing-state.d.ts +22 -0
- package/dist/bridge/pairing-state.js +76 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +835 -0
- package/dist/commands.d.ts +33 -0
- package/dist/commands.js +123 -0
- package/dist/constants.d.ts +10 -0
- package/dist/constants.js +10 -0
- package/dist/errors.d.ts +27 -0
- package/dist/errors.js +52 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +8 -0
- package/dist/mcp.d.ts +13 -0
- package/dist/mcp.js +300 -0
- package/dist/protocol/schema.d.ts +149 -0
- package/dist/protocol/schema.js +155 -0
- package/dist/server.d.ts +63 -0
- package/dist/server.js +486 -0
- package/dist/workflow-watch.d.ts +31 -0
- package/dist/workflow-watch.js +304 -0
- package/docs/cli.md +112 -0
- package/docs/http-api.md +149 -0
- package/docs/mcp.md +90 -0
- package/docs/operations.md +85 -0
- package/docs/workflow-watch.md +86 -0
- package/package.json +55 -0
- package/src/bridge/bridge-service.ts +291 -0
- package/src/bridge/control.ts +281 -0
- package/src/bridge/daemon.ts +102 -0
- package/src/bridge/extension-session.ts +286 -0
- package/src/bridge/pairing-state.ts +92 -0
- package/src/cli.ts +1019 -0
- package/src/commands.ts +158 -0
- package/src/constants.ts +10 -0
- package/src/errors.ts +72 -0
- package/src/index.ts +35 -0
- package/src/mcp.ts +386 -0
- package/src/protocol/schema.ts +202 -0
- package/src/server.ts +623 -0
- package/src/workflow-watch.ts +364 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const MessageEnvelopeSchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodString;
|
|
4
|
+
time: z.ZodNumber;
|
|
5
|
+
type: z.ZodString;
|
|
6
|
+
data: z.ZodOptional<z.ZodUnknown>;
|
|
7
|
+
cb: z.ZodOptional<z.ZodLiteral<false>>;
|
|
8
|
+
}, z.core.$strict>;
|
|
9
|
+
export type MessageEnvelope = z.infer<typeof MessageEnvelopeSchema>;
|
|
10
|
+
export declare const SafeResultSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
11
|
+
ok: z.ZodLiteral<true>;
|
|
12
|
+
data: z.ZodOptional<z.ZodUnknown>;
|
|
13
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
14
|
+
ok: z.ZodLiteral<false>;
|
|
15
|
+
error: z.ZodObject<{
|
|
16
|
+
code: z.ZodString;
|
|
17
|
+
message: z.ZodString;
|
|
18
|
+
details: z.ZodOptional<z.ZodUnknown>;
|
|
19
|
+
}, z.core.$strict>;
|
|
20
|
+
}, z.core.$strict>]>;
|
|
21
|
+
export type SafeResult = z.infer<typeof SafeResultSchema>;
|
|
22
|
+
export declare const ExtensionHelloInputSchema: z.ZodObject<{
|
|
23
|
+
clientId: z.ZodUUID;
|
|
24
|
+
clientName: z.ZodString;
|
|
25
|
+
credential: z.ZodOptional<z.ZodString>;
|
|
26
|
+
extensionVersion: z.ZodOptional<z.ZodString>;
|
|
27
|
+
capabilities: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
28
|
+
}, z.core.$strict>;
|
|
29
|
+
export type ExtensionHelloInput = z.infer<typeof ExtensionHelloInputSchema>;
|
|
30
|
+
export declare const ExtensionPairInputSchema: z.ZodObject<{
|
|
31
|
+
clientId: z.ZodUUID;
|
|
32
|
+
clientName: z.ZodString;
|
|
33
|
+
pairingCode: z.ZodString;
|
|
34
|
+
}, z.core.$strict>;
|
|
35
|
+
export type ExtensionPairInput = z.infer<typeof ExtensionPairInputSchema>;
|
|
36
|
+
export declare const BridgeHelloDataSchema: z.ZodObject<{
|
|
37
|
+
accepted: z.ZodBoolean;
|
|
38
|
+
requiresPairing: z.ZodBoolean;
|
|
39
|
+
bridgeVersion: z.ZodString;
|
|
40
|
+
protocolVersion: z.ZodLiteral<1>;
|
|
41
|
+
capabilities: z.ZodArray<z.ZodString>;
|
|
42
|
+
}, z.core.$strict>;
|
|
43
|
+
export declare const BridgePairDataSchema: z.ZodObject<{
|
|
44
|
+
accepted: z.ZodLiteral<true>;
|
|
45
|
+
clientId: z.ZodUUID;
|
|
46
|
+
credential: z.ZodString;
|
|
47
|
+
}, z.core.$strict>;
|
|
48
|
+
export declare const TabTargetSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
49
|
+
mode: z.ZodLiteral<"active">;
|
|
50
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
51
|
+
mode: z.ZodLiteral<"new">;
|
|
52
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
53
|
+
mode: z.ZodLiteral<"id">;
|
|
54
|
+
tabId: z.ZodNumber;
|
|
55
|
+
}, z.core.$strict>], "mode">;
|
|
56
|
+
export declare const WorkflowStartInputSchema: z.ZodObject<{
|
|
57
|
+
workflowId: z.ZodString;
|
|
58
|
+
args: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
59
|
+
tab: z.ZodDefault<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
60
|
+
mode: z.ZodLiteral<"active">;
|
|
61
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
62
|
+
mode: z.ZodLiteral<"new">;
|
|
63
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
64
|
+
mode: z.ZodLiteral<"id">;
|
|
65
|
+
tabId: z.ZodNumber;
|
|
66
|
+
}, z.core.$strict>], "mode">>;
|
|
67
|
+
}, z.core.$strict>;
|
|
68
|
+
export type WorkflowStartInput = z.infer<typeof WorkflowStartInputSchema>;
|
|
69
|
+
export declare const WorkflowControlInputSchema: z.ZodObject<{
|
|
70
|
+
workflowId: z.ZodString;
|
|
71
|
+
}, z.core.$strict>;
|
|
72
|
+
export type WorkflowControlInput = z.infer<typeof WorkflowControlInputSchema>;
|
|
73
|
+
export declare const DataInputSchema: z.ZodObject<{
|
|
74
|
+
tableId: z.ZodString;
|
|
75
|
+
}, z.core.$strict>;
|
|
76
|
+
export type DataInput = z.infer<typeof DataInputSchema>;
|
|
77
|
+
export declare const WorkflowLifecycleStateSchema: z.ZodEnum<{
|
|
78
|
+
running: "running";
|
|
79
|
+
paused: "paused";
|
|
80
|
+
stopping: "stopping";
|
|
81
|
+
completed: "completed";
|
|
82
|
+
stopped: "stopped";
|
|
83
|
+
failed: "failed";
|
|
84
|
+
}>;
|
|
85
|
+
export declare const WorkflowStatusDataSchema: z.ZodObject<{
|
|
86
|
+
workflowId: z.ZodString;
|
|
87
|
+
state: z.ZodEnum<{
|
|
88
|
+
running: "running";
|
|
89
|
+
paused: "paused";
|
|
90
|
+
stopping: "stopping";
|
|
91
|
+
completed: "completed";
|
|
92
|
+
stopped: "stopped";
|
|
93
|
+
failed: "failed";
|
|
94
|
+
}>;
|
|
95
|
+
updatedAt: z.ZodISODateTime;
|
|
96
|
+
}, z.core.$strict>;
|
|
97
|
+
export type WorkflowStatusData = z.infer<typeof WorkflowStatusDataSchema>;
|
|
98
|
+
export declare const WorkflowStatusEventSchema: z.ZodObject<{
|
|
99
|
+
workflowId: z.ZodString;
|
|
100
|
+
state: z.ZodEnum<{
|
|
101
|
+
running: "running";
|
|
102
|
+
paused: "paused";
|
|
103
|
+
stopping: "stopping";
|
|
104
|
+
completed: "completed";
|
|
105
|
+
stopped: "stopped";
|
|
106
|
+
failed: "failed";
|
|
107
|
+
}>;
|
|
108
|
+
updatedAt: z.ZodISODateTime;
|
|
109
|
+
clientId: z.ZodUUID;
|
|
110
|
+
}, z.core.$strict>;
|
|
111
|
+
export type WorkflowStatusEvent = z.infer<typeof WorkflowStatusEventSchema>;
|
|
112
|
+
export declare const WorkflowWatchRequestSchema: z.ZodObject<{
|
|
113
|
+
clientId: z.ZodOptional<z.ZodUUID>;
|
|
114
|
+
input: z.ZodObject<{
|
|
115
|
+
workflowId: z.ZodString;
|
|
116
|
+
}, z.core.$strict>;
|
|
117
|
+
}, z.core.$strict>;
|
|
118
|
+
export type WorkflowWatchRequest = z.infer<typeof WorkflowWatchRequestSchema>;
|
|
119
|
+
export declare const WorkflowStartResultSchema: z.ZodObject<{
|
|
120
|
+
clientId: z.ZodUUID;
|
|
121
|
+
workflowId: z.ZodString;
|
|
122
|
+
workflowName: z.ZodString;
|
|
123
|
+
state: z.ZodOptional<z.ZodEnum<{
|
|
124
|
+
accepted: "accepted";
|
|
125
|
+
running: "running";
|
|
126
|
+
starting: "starting";
|
|
127
|
+
}>>;
|
|
128
|
+
}, z.core.$strict>;
|
|
129
|
+
export type WorkflowStartResult = z.infer<typeof WorkflowStartResultSchema>;
|
|
130
|
+
export declare function createEnvelope<TData>(type: string, data: TData, options?: {
|
|
131
|
+
id?: string;
|
|
132
|
+
callback?: boolean;
|
|
133
|
+
}): MessageEnvelope;
|
|
134
|
+
export declare function parseEnvelope(data: unknown): {
|
|
135
|
+
success: false;
|
|
136
|
+
error: Error;
|
|
137
|
+
data?: undefined;
|
|
138
|
+
} | {
|
|
139
|
+
success: true;
|
|
140
|
+
data: {
|
|
141
|
+
id: string;
|
|
142
|
+
time: number;
|
|
143
|
+
type: string;
|
|
144
|
+
data?: unknown;
|
|
145
|
+
cb?: false | undefined;
|
|
146
|
+
};
|
|
147
|
+
error?: undefined;
|
|
148
|
+
};
|
|
149
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { PROTOCOL_VERSION } from '../constants.js';
|
|
4
|
+
export const MessageEnvelopeSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
id: z.string().min(1),
|
|
7
|
+
time: z.number().int().nonnegative(),
|
|
8
|
+
type: z.string().min(1),
|
|
9
|
+
data: z.unknown().optional(),
|
|
10
|
+
cb: z.literal(false).optional(),
|
|
11
|
+
})
|
|
12
|
+
.strict();
|
|
13
|
+
export const SafeResultSchema = z.union([
|
|
14
|
+
z
|
|
15
|
+
.object({
|
|
16
|
+
ok: z.literal(true),
|
|
17
|
+
data: z.unknown().optional(),
|
|
18
|
+
})
|
|
19
|
+
.strict(),
|
|
20
|
+
z
|
|
21
|
+
.object({
|
|
22
|
+
ok: z.literal(false),
|
|
23
|
+
error: z
|
|
24
|
+
.object({
|
|
25
|
+
code: z.string().min(1),
|
|
26
|
+
message: z.string(),
|
|
27
|
+
details: z.unknown().optional(),
|
|
28
|
+
})
|
|
29
|
+
.strict(),
|
|
30
|
+
})
|
|
31
|
+
.strict(),
|
|
32
|
+
]);
|
|
33
|
+
export const ExtensionHelloInputSchema = z
|
|
34
|
+
.object({
|
|
35
|
+
clientId: z.uuid(),
|
|
36
|
+
clientName: z.string().trim().min(1).max(80),
|
|
37
|
+
credential: z.string().min(1).optional(),
|
|
38
|
+
extensionVersion: z.string().min(1).optional(),
|
|
39
|
+
capabilities: z.array(z.string().min(1)).default([]),
|
|
40
|
+
})
|
|
41
|
+
.strict();
|
|
42
|
+
export const ExtensionPairInputSchema = z
|
|
43
|
+
.object({
|
|
44
|
+
clientId: z.uuid(),
|
|
45
|
+
clientName: z.string().trim().min(1).max(80),
|
|
46
|
+
pairingCode: z.string().regex(/^\d{4}$/),
|
|
47
|
+
})
|
|
48
|
+
.strict();
|
|
49
|
+
export const BridgeHelloDataSchema = z
|
|
50
|
+
.object({
|
|
51
|
+
accepted: z.boolean(),
|
|
52
|
+
requiresPairing: z.boolean(),
|
|
53
|
+
bridgeVersion: z.string().min(1),
|
|
54
|
+
protocolVersion: z.literal(PROTOCOL_VERSION),
|
|
55
|
+
capabilities: z.array(z.string().min(1)),
|
|
56
|
+
})
|
|
57
|
+
.strict();
|
|
58
|
+
export const BridgePairDataSchema = z
|
|
59
|
+
.object({
|
|
60
|
+
accepted: z.literal(true),
|
|
61
|
+
clientId: z.uuid(),
|
|
62
|
+
credential: z.string().min(1),
|
|
63
|
+
})
|
|
64
|
+
.strict();
|
|
65
|
+
export const TabTargetSchema = z.discriminatedUnion('mode', [
|
|
66
|
+
z.object({ mode: z.literal('active') }).strict(),
|
|
67
|
+
z.object({ mode: z.literal('new') }).strict(),
|
|
68
|
+
z.object({ mode: z.literal('id'), tabId: z.number().int().positive() }).strict(),
|
|
69
|
+
]);
|
|
70
|
+
export const WorkflowStartInputSchema = z
|
|
71
|
+
.object({
|
|
72
|
+
workflowId: z.string().min(1),
|
|
73
|
+
args: z.record(z.string(), z.unknown()).default({}),
|
|
74
|
+
tab: TabTargetSchema.default({ mode: 'active' }),
|
|
75
|
+
})
|
|
76
|
+
.strict();
|
|
77
|
+
export const WorkflowControlInputSchema = z
|
|
78
|
+
.object({
|
|
79
|
+
workflowId: z.string().min(1),
|
|
80
|
+
})
|
|
81
|
+
.strict();
|
|
82
|
+
export const DataInputSchema = z
|
|
83
|
+
.object({
|
|
84
|
+
tableId: z.string().trim().min(1).max(128),
|
|
85
|
+
})
|
|
86
|
+
.strict();
|
|
87
|
+
export const WorkflowLifecycleStateSchema = z.enum(['running', 'paused', 'stopping', 'completed', 'stopped', 'failed']);
|
|
88
|
+
export const WorkflowStatusDataSchema = z
|
|
89
|
+
.object({
|
|
90
|
+
workflowId: z.string().min(1),
|
|
91
|
+
state: WorkflowLifecycleStateSchema,
|
|
92
|
+
updatedAt: z.iso.datetime(),
|
|
93
|
+
})
|
|
94
|
+
.strict();
|
|
95
|
+
export const WorkflowStatusEventSchema = z
|
|
96
|
+
.object({
|
|
97
|
+
clientId: z.uuid(),
|
|
98
|
+
...WorkflowStatusDataSchema.shape,
|
|
99
|
+
})
|
|
100
|
+
.strict();
|
|
101
|
+
export const WorkflowWatchRequestSchema = z
|
|
102
|
+
.object({
|
|
103
|
+
clientId: z.uuid().optional(),
|
|
104
|
+
input: WorkflowControlInputSchema,
|
|
105
|
+
})
|
|
106
|
+
.strict();
|
|
107
|
+
export const WorkflowStartResultSchema = z
|
|
108
|
+
.object({
|
|
109
|
+
clientId: z.uuid(),
|
|
110
|
+
workflowId: z.string().min(1),
|
|
111
|
+
workflowName: z.string().min(1),
|
|
112
|
+
state: z.enum(['accepted', 'starting', 'running']).optional(),
|
|
113
|
+
})
|
|
114
|
+
.strict();
|
|
115
|
+
export function createEnvelope(type, data, options = {}) {
|
|
116
|
+
const envelope = {
|
|
117
|
+
id: options.id ?? randomUUID(),
|
|
118
|
+
time: Date.now(),
|
|
119
|
+
type,
|
|
120
|
+
data,
|
|
121
|
+
};
|
|
122
|
+
if (options.callback === false) {
|
|
123
|
+
envelope.cb = false;
|
|
124
|
+
}
|
|
125
|
+
return envelope;
|
|
126
|
+
}
|
|
127
|
+
export function parseEnvelope(data) {
|
|
128
|
+
let value = data;
|
|
129
|
+
if (Buffer.isBuffer(value)) {
|
|
130
|
+
value = value.toString('utf8');
|
|
131
|
+
}
|
|
132
|
+
if (typeof value === 'string') {
|
|
133
|
+
try {
|
|
134
|
+
value = JSON.parse(value);
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return {
|
|
138
|
+
success: false,
|
|
139
|
+
error: new Error('WebSocket message is not valid JSON'),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const result = MessageEnvelopeSchema.safeParse(value);
|
|
144
|
+
if (!result.success) {
|
|
145
|
+
return {
|
|
146
|
+
success: false,
|
|
147
|
+
error: result.error,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
success: true,
|
|
152
|
+
data: result.data,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=schema.js.map
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { BridgeService } from './bridge/bridge-service.js';
|
|
2
|
+
export type BridgeTlsOptions = {
|
|
3
|
+
key: string;
|
|
4
|
+
cert: string;
|
|
5
|
+
};
|
|
6
|
+
export type BridgeServerOptions = {
|
|
7
|
+
host?: string;
|
|
8
|
+
port?: number;
|
|
9
|
+
portMax?: number;
|
|
10
|
+
token?: string;
|
|
11
|
+
corsOrigins?: string[];
|
|
12
|
+
tls?: BridgeTlsOptions;
|
|
13
|
+
pairingCode?: string;
|
|
14
|
+
dataDir?: string;
|
|
15
|
+
};
|
|
16
|
+
export declare class BridgeServer {
|
|
17
|
+
readonly bridgeId: `${string}-${string}-${string}-${string}-${string}`;
|
|
18
|
+
readonly bridge: BridgeService;
|
|
19
|
+
private readonly host;
|
|
20
|
+
private readonly requestedPort?;
|
|
21
|
+
private readonly portMax;
|
|
22
|
+
private readonly token?;
|
|
23
|
+
private readonly corsOrigins;
|
|
24
|
+
private readonly tls?;
|
|
25
|
+
private readonly mcpHandler;
|
|
26
|
+
private readonly mcpNodeHandler;
|
|
27
|
+
private readonly validateLocalMcpHost;
|
|
28
|
+
private server;
|
|
29
|
+
private webSocketServer;
|
|
30
|
+
private port;
|
|
31
|
+
private readonly workflowSubscriptions;
|
|
32
|
+
constructor(options?: BridgeServerOptions);
|
|
33
|
+
getPairingCode(): string | undefined;
|
|
34
|
+
refreshPairingCode(): string;
|
|
35
|
+
start(): Promise<{
|
|
36
|
+
host: string;
|
|
37
|
+
port: number;
|
|
38
|
+
httpUrl: string;
|
|
39
|
+
wsUrl: string;
|
|
40
|
+
workflowWatchWsUrl: string;
|
|
41
|
+
mcpUrl: string;
|
|
42
|
+
}>;
|
|
43
|
+
close(): Promise<void>;
|
|
44
|
+
getAddress(): {
|
|
45
|
+
host: string;
|
|
46
|
+
port: number;
|
|
47
|
+
httpUrl: string;
|
|
48
|
+
wsUrl: string;
|
|
49
|
+
workflowWatchWsUrl: string;
|
|
50
|
+
mcpUrl: string;
|
|
51
|
+
};
|
|
52
|
+
private getPorts;
|
|
53
|
+
private createRuntime;
|
|
54
|
+
private handleRequest;
|
|
55
|
+
private assertAuthorized;
|
|
56
|
+
private attachWorkflowWatcher;
|
|
57
|
+
private sendWorkflowWatchResult;
|
|
58
|
+
private publishWorkflowStatus;
|
|
59
|
+
private getOrigin;
|
|
60
|
+
private applyCors;
|
|
61
|
+
private sendJson;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=server.d.ts.map
|