@clinebot/shared 0.0.14 → 0.0.16
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/connectors/events.d.ts +60 -2
- package/dist/db/index.js +1 -1
- package/dist/db/sqlite-db.d.ts +1 -0
- package/dist/index.browser.d.ts +4 -2
- package/dist/index.browser.js +12 -12
- package/dist/index.d.ts +4 -2
- package/dist/index.js +30 -30
- package/package.json +1 -1
- package/src/connectors/events.ts +45 -1
- package/src/db/sqlite-db.ts +7 -0
- package/src/index.browser.ts +10 -0
- package/src/index.ts +10 -0
- package/src/storage/paths.test.ts +99 -0
package/package.json
CHANGED
package/src/connectors/events.ts
CHANGED
|
@@ -3,12 +3,14 @@ import { z } from "zod";
|
|
|
3
3
|
export const ConnectorHookEventNameSchema = z.enum([
|
|
4
4
|
"connector.started",
|
|
5
5
|
"connector.stopping",
|
|
6
|
+
"session.authorize",
|
|
6
7
|
"message.received",
|
|
8
|
+
"message.denied",
|
|
7
9
|
"message.completed",
|
|
8
10
|
"message.failed",
|
|
9
11
|
"session.started",
|
|
10
12
|
"session.reused",
|
|
11
|
-
"
|
|
13
|
+
"session.reset",
|
|
12
14
|
"schedule.delivery.started",
|
|
13
15
|
"schedule.delivery.sent",
|
|
14
16
|
"schedule.delivery.failed",
|
|
@@ -18,6 +20,40 @@ export type ConnectorHookEventName = z.infer<
|
|
|
18
20
|
typeof ConnectorHookEventNameSchema
|
|
19
21
|
>;
|
|
20
22
|
|
|
23
|
+
export const ConnectorEventActorSchema = z.object({
|
|
24
|
+
id: z.string().optional(),
|
|
25
|
+
label: z.string().optional(),
|
|
26
|
+
role: z.string().optional(),
|
|
27
|
+
participantKey: z.string().optional(),
|
|
28
|
+
participantLabel: z.string().optional(),
|
|
29
|
+
platformUserId: z.string().optional(),
|
|
30
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export const ConnectorEventContextSchema = z.object({
|
|
34
|
+
source: z.string(),
|
|
35
|
+
sourceEvent: z.string(),
|
|
36
|
+
threadId: z.string(),
|
|
37
|
+
channelId: z.string(),
|
|
38
|
+
isDM: z.boolean(),
|
|
39
|
+
sessionId: z.string().optional(),
|
|
40
|
+
workspaceRoot: z.string().optional(),
|
|
41
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export const ConnectorAuthorizationRequestSchema = z.object({
|
|
45
|
+
actor: ConnectorEventActorSchema,
|
|
46
|
+
context: ConnectorEventContextSchema,
|
|
47
|
+
payload: z.record(z.string(), z.unknown()).optional(),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export const ConnectorAuthorizationDecisionSchema = z.object({
|
|
51
|
+
action: z.enum(["allow", "deny"]).default("allow"),
|
|
52
|
+
message: z.string().optional(),
|
|
53
|
+
reason: z.string().optional(),
|
|
54
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
55
|
+
});
|
|
56
|
+
|
|
21
57
|
export const ConnectorHookEventSchema = z.object({
|
|
22
58
|
adapter: z.string(),
|
|
23
59
|
botUserName: z.string().optional(),
|
|
@@ -27,3 +63,11 @@ export const ConnectorHookEventSchema = z.object({
|
|
|
27
63
|
});
|
|
28
64
|
|
|
29
65
|
export type ConnectorHookEvent = z.infer<typeof ConnectorHookEventSchema>;
|
|
66
|
+
export type ConnectorEventActor = z.infer<typeof ConnectorEventActorSchema>;
|
|
67
|
+
export type ConnectorEventContext = z.infer<typeof ConnectorEventContextSchema>;
|
|
68
|
+
export type ConnectorAuthorizationRequest = z.infer<
|
|
69
|
+
typeof ConnectorAuthorizationRequestSchema
|
|
70
|
+
>;
|
|
71
|
+
export type ConnectorAuthorizationDecision = z.infer<
|
|
72
|
+
typeof ConnectorAuthorizationDecisionSchema
|
|
73
|
+
>;
|
package/src/db/sqlite-db.ts
CHANGED
|
@@ -11,6 +11,7 @@ export type SqliteStatement = {
|
|
|
11
11
|
export type SqliteDb = {
|
|
12
12
|
prepare: (sql: string) => SqliteStatement;
|
|
13
13
|
exec: (sql: string) => void;
|
|
14
|
+
close?: () => void;
|
|
14
15
|
};
|
|
15
16
|
|
|
16
17
|
export function nowIso(): string {
|
|
@@ -38,10 +39,12 @@ export function asBool(value: unknown): boolean {
|
|
|
38
39
|
function wrapBunDb(db: {
|
|
39
40
|
query: (sql: string) => SqliteStatement;
|
|
40
41
|
exec: (sql: string) => void;
|
|
42
|
+
close?: () => void;
|
|
41
43
|
}): SqliteDb {
|
|
42
44
|
return {
|
|
43
45
|
prepare: (sql) => db.query(sql),
|
|
44
46
|
exec: (sql) => db.exec(sql),
|
|
47
|
+
close: () => db.close?.(),
|
|
45
48
|
};
|
|
46
49
|
}
|
|
47
50
|
|
|
@@ -52,6 +55,7 @@ function wrapNodeDb(db: {
|
|
|
52
55
|
all: (...params: unknown[]) => Record<string, unknown>[];
|
|
53
56
|
};
|
|
54
57
|
exec: (sql: string) => void;
|
|
58
|
+
close?: () => void;
|
|
55
59
|
}): SqliteDb {
|
|
56
60
|
return {
|
|
57
61
|
prepare: (sql) => {
|
|
@@ -63,6 +67,7 @@ function wrapNodeDb(db: {
|
|
|
63
67
|
};
|
|
64
68
|
},
|
|
65
69
|
exec: (sql) => db.exec(sql),
|
|
70
|
+
close: () => db.close?.(),
|
|
66
71
|
};
|
|
67
72
|
}
|
|
68
73
|
|
|
@@ -78,6 +83,7 @@ export function loadSqliteDb(filePath: string): SqliteDb {
|
|
|
78
83
|
) => {
|
|
79
84
|
query: (sql: string) => SqliteStatement;
|
|
80
85
|
exec: (sql: string) => void;
|
|
86
|
+
close?: () => void;
|
|
81
87
|
};
|
|
82
88
|
};
|
|
83
89
|
return wrapBunDb(new Database(filePath, { create: true }));
|
|
@@ -103,6 +109,7 @@ export function loadSqliteDb(filePath: string): SqliteDb {
|
|
|
103
109
|
all: (...params: unknown[]) => Record<string, unknown>[];
|
|
104
110
|
};
|
|
105
111
|
exec: (sql: string) => void;
|
|
112
|
+
close?: () => void;
|
|
106
113
|
};
|
|
107
114
|
};
|
|
108
115
|
process.emitWarning = originalEmit;
|
package/src/index.browser.ts
CHANGED
|
@@ -7,10 +7,18 @@ export {
|
|
|
7
7
|
} from "./auth/constants";
|
|
8
8
|
export type * from "./connectors/adapters";
|
|
9
9
|
export type {
|
|
10
|
+
ConnectorAuthorizationDecision,
|
|
11
|
+
ConnectorAuthorizationRequest,
|
|
12
|
+
ConnectorEventActor,
|
|
13
|
+
ConnectorEventContext,
|
|
10
14
|
ConnectorHookEvent,
|
|
11
15
|
ConnectorHookEventName,
|
|
12
16
|
} from "./connectors/events";
|
|
13
17
|
export {
|
|
18
|
+
ConnectorAuthorizationDecisionSchema,
|
|
19
|
+
ConnectorAuthorizationRequestSchema,
|
|
20
|
+
ConnectorEventActorSchema,
|
|
21
|
+
ConnectorEventContextSchema,
|
|
14
22
|
ConnectorHookEventNameSchema,
|
|
15
23
|
ConnectorHookEventSchema,
|
|
16
24
|
} from "./connectors/events";
|
|
@@ -38,6 +46,8 @@ export {
|
|
|
38
46
|
normalizeUserInput,
|
|
39
47
|
xmlTagsRemoval,
|
|
40
48
|
} from "./prompt/format";
|
|
49
|
+
export * from "./remote-config/constants";
|
|
50
|
+
export * from "./remote-config/schema";
|
|
41
51
|
export { CLINE_DEFAULT_RPC_ADDRESS, CLINE_DEFAULT_RPC_PORT } from "./rpc";
|
|
42
52
|
export type {
|
|
43
53
|
RpcAddProviderActionRequest,
|
package/src/index.ts
CHANGED
|
@@ -7,10 +7,18 @@ export {
|
|
|
7
7
|
} from "./auth/constants";
|
|
8
8
|
export type * from "./connectors/adapters";
|
|
9
9
|
export type {
|
|
10
|
+
ConnectorAuthorizationDecision,
|
|
11
|
+
ConnectorAuthorizationRequest,
|
|
12
|
+
ConnectorEventActor,
|
|
13
|
+
ConnectorEventContext,
|
|
10
14
|
ConnectorHookEvent,
|
|
11
15
|
ConnectorHookEventName,
|
|
12
16
|
} from "./connectors/events";
|
|
13
17
|
export {
|
|
18
|
+
ConnectorAuthorizationDecisionSchema,
|
|
19
|
+
ConnectorAuthorizationRequestSchema,
|
|
20
|
+
ConnectorEventActorSchema,
|
|
21
|
+
ConnectorEventContextSchema,
|
|
14
22
|
ConnectorHookEventNameSchema,
|
|
15
23
|
ConnectorHookEventSchema,
|
|
16
24
|
} from "./connectors/events";
|
|
@@ -38,6 +46,8 @@ export {
|
|
|
38
46
|
normalizeUserInput,
|
|
39
47
|
xmlTagsRemoval,
|
|
40
48
|
} from "./prompt/format";
|
|
49
|
+
export * from "./remote-config/constants";
|
|
50
|
+
export * from "./remote-config/schema";
|
|
41
51
|
export { CLINE_DEFAULT_RPC_ADDRESS, CLINE_DEFAULT_RPC_PORT } from "./rpc";
|
|
42
52
|
export type {
|
|
43
53
|
RpcAddProviderActionRequest,
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
AGENT_CONFIG_DIRECTORY_NAME,
|
|
5
|
+
CLINE_MCP_SETTINGS_FILE_NAME,
|
|
6
|
+
resolveAgentsConfigDirPath,
|
|
7
|
+
resolveClineDataDir,
|
|
8
|
+
resolveMcpSettingsPath,
|
|
9
|
+
resolveProviderSettingsPath,
|
|
10
|
+
resolveSessionDataDir,
|
|
11
|
+
resolveTeamDataDir,
|
|
12
|
+
} from "./paths";
|
|
13
|
+
|
|
14
|
+
type EnvSnapshot = {
|
|
15
|
+
CLINE_DATA_DIR: string | undefined;
|
|
16
|
+
CLINE_MCP_SETTINGS_PATH: string | undefined;
|
|
17
|
+
CLINE_PROVIDER_SETTINGS_PATH: string | undefined;
|
|
18
|
+
CLINE_SESSION_DATA_DIR: string | undefined;
|
|
19
|
+
CLINE_TEAM_DATA_DIR: string | undefined;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function captureEnv(): EnvSnapshot {
|
|
23
|
+
return {
|
|
24
|
+
CLINE_DATA_DIR: process.env.CLINE_DATA_DIR,
|
|
25
|
+
CLINE_MCP_SETTINGS_PATH: process.env.CLINE_MCP_SETTINGS_PATH,
|
|
26
|
+
CLINE_PROVIDER_SETTINGS_PATH: process.env.CLINE_PROVIDER_SETTINGS_PATH,
|
|
27
|
+
CLINE_SESSION_DATA_DIR: process.env.CLINE_SESSION_DATA_DIR,
|
|
28
|
+
CLINE_TEAM_DATA_DIR: process.env.CLINE_TEAM_DATA_DIR,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function restoreEnv(snapshot: EnvSnapshot): void {
|
|
33
|
+
process.env.CLINE_DATA_DIR = snapshot.CLINE_DATA_DIR;
|
|
34
|
+
process.env.CLINE_MCP_SETTINGS_PATH = snapshot.CLINE_MCP_SETTINGS_PATH;
|
|
35
|
+
process.env.CLINE_PROVIDER_SETTINGS_PATH =
|
|
36
|
+
snapshot.CLINE_PROVIDER_SETTINGS_PATH;
|
|
37
|
+
process.env.CLINE_SESSION_DATA_DIR = snapshot.CLINE_SESSION_DATA_DIR;
|
|
38
|
+
process.env.CLINE_TEAM_DATA_DIR = snapshot.CLINE_TEAM_DATA_DIR;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
describe("storage path resolution", () => {
|
|
42
|
+
let snapshot: EnvSnapshot = captureEnv();
|
|
43
|
+
|
|
44
|
+
afterEach(() => {
|
|
45
|
+
restoreEnv(snapshot);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("uses CLINE_DATA_DIR as-is when set", () => {
|
|
49
|
+
snapshot = captureEnv();
|
|
50
|
+
process.env.CLINE_DATA_DIR = "/tmp/cline-data";
|
|
51
|
+
|
|
52
|
+
expect(resolveClineDataDir()).toBe("/tmp/cline-data");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("falls back to CLINE_DATA_DIR/sessions for session storage", () => {
|
|
56
|
+
snapshot = captureEnv();
|
|
57
|
+
delete process.env.CLINE_SESSION_DATA_DIR;
|
|
58
|
+
process.env.CLINE_DATA_DIR = "/tmp/cline-data";
|
|
59
|
+
|
|
60
|
+
expect(resolveSessionDataDir()).toBe(join("/tmp/cline-data", "sessions"));
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("falls back to CLINE_DATA_DIR/teams for team storage", () => {
|
|
64
|
+
snapshot = captureEnv();
|
|
65
|
+
delete process.env.CLINE_TEAM_DATA_DIR;
|
|
66
|
+
process.env.CLINE_DATA_DIR = "/tmp/cline-data";
|
|
67
|
+
|
|
68
|
+
expect(resolveTeamDataDir()).toBe(join("/tmp/cline-data", "teams"));
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("falls back to CLINE_DATA_DIR/settings/providers.json for provider settings", () => {
|
|
72
|
+
snapshot = captureEnv();
|
|
73
|
+
delete process.env.CLINE_PROVIDER_SETTINGS_PATH;
|
|
74
|
+
process.env.CLINE_DATA_DIR = "/tmp/cline-data";
|
|
75
|
+
|
|
76
|
+
expect(resolveProviderSettingsPath()).toBe(
|
|
77
|
+
join("/tmp/cline-data", "settings", "providers.json"),
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("falls back to CLINE_DATA_DIR/settings/cline_mcp_settings.json for MCP settings", () => {
|
|
82
|
+
snapshot = captureEnv();
|
|
83
|
+
delete process.env.CLINE_MCP_SETTINGS_PATH;
|
|
84
|
+
process.env.CLINE_DATA_DIR = "/tmp/cline-data";
|
|
85
|
+
|
|
86
|
+
expect(resolveMcpSettingsPath()).toBe(
|
|
87
|
+
join("/tmp/cline-data", "settings", CLINE_MCP_SETTINGS_FILE_NAME),
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("falls back to CLINE_DATA_DIR/settings/agents for agent configs", () => {
|
|
92
|
+
snapshot = captureEnv();
|
|
93
|
+
process.env.CLINE_DATA_DIR = "/tmp/cline-data";
|
|
94
|
+
|
|
95
|
+
expect(resolveAgentsConfigDirPath()).toBe(
|
|
96
|
+
join("/tmp/cline-data", "settings", AGENT_CONFIG_DIRECTORY_NAME),
|
|
97
|
+
);
|
|
98
|
+
});
|
|
99
|
+
});
|