opencode-sync-plugin 0.1.6 → 0.1.8
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/README.md +4 -0
- package/dist/chunk-V6SCOAXD.js +171 -0
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +21 -30
- package/dist/index.js +3 -1
- package/package.json +1 -1
- package/dist/chunk-46RJJUZ6.js +0 -260
package/README.md
CHANGED
|
@@ -158,6 +158,8 @@ export const OpenCodeSyncPlugin: Plugin = async ({ project, client, $, directory
|
|
|
158
158
|
};
|
|
159
159
|
```
|
|
160
160
|
|
|
161
|
+
This plugin exports both a named and default export so OpenCode can load it from npm reliably.
|
|
162
|
+
|
|
161
163
|
## Troubleshooting
|
|
162
164
|
|
|
163
165
|
### OpenCode won't start or shows blank screen
|
|
@@ -189,6 +191,8 @@ rm -rf ~/.cache/opencode/node_modules/opencode-sync-plugin
|
|
|
189
191
|
opencode
|
|
190
192
|
```
|
|
191
193
|
|
|
194
|
+
If the issue persists, reinstall the latest version and clear the cache again.
|
|
195
|
+
|
|
192
196
|
### "Not authenticated" errors
|
|
193
197
|
|
|
194
198
|
```bash
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// src/index.ts
|
|
9
|
+
var configDir = null;
|
|
10
|
+
var configFile = null;
|
|
11
|
+
function getConfigPaths() {
|
|
12
|
+
if (!configDir) {
|
|
13
|
+
const { homedir } = __require("os");
|
|
14
|
+
const { join } = __require("path");
|
|
15
|
+
configDir = join(homedir(), ".config", "opencode-sync");
|
|
16
|
+
configFile = join(configDir, "config.json");
|
|
17
|
+
}
|
|
18
|
+
return { configDir, configFile };
|
|
19
|
+
}
|
|
20
|
+
function readConfigFile() {
|
|
21
|
+
try {
|
|
22
|
+
const { existsSync, readFileSync } = __require("fs");
|
|
23
|
+
const { configFile: configFile2 } = getConfigPaths();
|
|
24
|
+
if (!existsSync(configFile2)) return null;
|
|
25
|
+
const content = readFileSync(configFile2, "utf8");
|
|
26
|
+
return JSON.parse(content);
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function writeConfigFile(config) {
|
|
32
|
+
try {
|
|
33
|
+
const { existsSync, writeFileSync, mkdirSync } = __require("fs");
|
|
34
|
+
const { configDir: configDir2, configFile: configFile2 } = getConfigPaths();
|
|
35
|
+
if (!existsSync(configDir2)) {
|
|
36
|
+
mkdirSync(configDir2, { recursive: true });
|
|
37
|
+
}
|
|
38
|
+
writeFileSync(configFile2, JSON.stringify(config, null, 2), "utf8");
|
|
39
|
+
} catch {
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function getConfig() {
|
|
43
|
+
const config = readConfigFile();
|
|
44
|
+
if (!config || !config.convexUrl) return null;
|
|
45
|
+
return config;
|
|
46
|
+
}
|
|
47
|
+
function setConfig(cfg) {
|
|
48
|
+
writeConfigFile(cfg);
|
|
49
|
+
}
|
|
50
|
+
function clearConfig() {
|
|
51
|
+
try {
|
|
52
|
+
const { existsSync, writeFileSync } = __require("fs");
|
|
53
|
+
const { configFile: configFile2 } = getConfigPaths();
|
|
54
|
+
if (existsSync(configFile2)) {
|
|
55
|
+
writeFileSync(configFile2, "{}", "utf8");
|
|
56
|
+
}
|
|
57
|
+
} catch {
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
var syncedMessages = /* @__PURE__ */ new Set();
|
|
61
|
+
var syncedSessions = /* @__PURE__ */ new Set();
|
|
62
|
+
function extractTextContent(content) {
|
|
63
|
+
if (typeof content === "string") return content;
|
|
64
|
+
if (Array.isArray(content)) {
|
|
65
|
+
return content.filter((p) => p.type === "text" && p.text).map((p) => p.text).join("\n");
|
|
66
|
+
}
|
|
67
|
+
return "";
|
|
68
|
+
}
|
|
69
|
+
function extractTitle(session) {
|
|
70
|
+
const firstMessage = session.messages?.find((m) => m.role === "user");
|
|
71
|
+
if (firstMessage) {
|
|
72
|
+
const text = extractTextContent(firstMessage.content);
|
|
73
|
+
if (text) {
|
|
74
|
+
return text.slice(0, 100) + (text.length > 100 ? "..." : "");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return "Untitled Session";
|
|
78
|
+
}
|
|
79
|
+
function syncSessionBackground(session) {
|
|
80
|
+
const config = getConfig();
|
|
81
|
+
if (!config?.apiKey || !config?.convexUrl) return;
|
|
82
|
+
const siteUrl = config.convexUrl.replace(".convex.cloud", ".convex.site");
|
|
83
|
+
fetch(`${siteUrl}/sync/session`, {
|
|
84
|
+
method: "POST",
|
|
85
|
+
headers: {
|
|
86
|
+
"Content-Type": "application/json",
|
|
87
|
+
Authorization: `Bearer ${config.apiKey}`
|
|
88
|
+
},
|
|
89
|
+
body: JSON.stringify({
|
|
90
|
+
externalId: session.id,
|
|
91
|
+
title: session.title || extractTitle(session),
|
|
92
|
+
projectPath: session.cwd,
|
|
93
|
+
projectName: session.cwd?.split("/").pop(),
|
|
94
|
+
model: session.model,
|
|
95
|
+
provider: session.provider,
|
|
96
|
+
promptTokens: session.usage?.promptTokens || 0,
|
|
97
|
+
completionTokens: session.usage?.completionTokens || 0,
|
|
98
|
+
cost: session.usage?.cost || 0
|
|
99
|
+
})
|
|
100
|
+
}).catch(() => {
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function syncMessageBackground(sessionId, message) {
|
|
104
|
+
const config = getConfig();
|
|
105
|
+
if (!config?.apiKey || !config?.convexUrl) return;
|
|
106
|
+
const siteUrl = config.convexUrl.replace(".convex.cloud", ".convex.site");
|
|
107
|
+
fetch(`${siteUrl}/sync/message`, {
|
|
108
|
+
method: "POST",
|
|
109
|
+
headers: {
|
|
110
|
+
"Content-Type": "application/json",
|
|
111
|
+
Authorization: `Bearer ${config.apiKey}`
|
|
112
|
+
},
|
|
113
|
+
body: JSON.stringify({
|
|
114
|
+
sessionExternalId: sessionId,
|
|
115
|
+
externalId: message.id,
|
|
116
|
+
role: message.role,
|
|
117
|
+
textContent: extractTextContent(message.content),
|
|
118
|
+
model: message.model,
|
|
119
|
+
promptTokens: message.usage?.promptTokens,
|
|
120
|
+
completionTokens: message.usage?.completionTokens,
|
|
121
|
+
durationMs: message.duration
|
|
122
|
+
})
|
|
123
|
+
}).catch(() => {
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
var OpenCodeSyncPlugin = async (ctx) => {
|
|
127
|
+
ctx.client.app.log({
|
|
128
|
+
service: "opencode-sync",
|
|
129
|
+
level: "info",
|
|
130
|
+
message: "Plugin loaded"
|
|
131
|
+
}).catch(() => {
|
|
132
|
+
});
|
|
133
|
+
return {
|
|
134
|
+
event: async (input) => {
|
|
135
|
+
try {
|
|
136
|
+
const { event } = input;
|
|
137
|
+
const props = event.properties;
|
|
138
|
+
if (event.type === "session.created" || event.type === "session.updated" || event.type === "session.idle") {
|
|
139
|
+
const session = props;
|
|
140
|
+
if (session?.id) {
|
|
141
|
+
if (event.type === "session.created" && syncedSessions.has(session.id)) return;
|
|
142
|
+
if (event.type === "session.created") syncedSessions.add(session.id);
|
|
143
|
+
syncSessionBackground(session);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (event.type === "message.updated" || event.type === "message.part.updated") {
|
|
147
|
+
const messageProps = props;
|
|
148
|
+
const sessionId = messageProps?.sessionId;
|
|
149
|
+
const message = messageProps?.message;
|
|
150
|
+
if (sessionId && message?.id && !syncedMessages.has(message.id)) {
|
|
151
|
+
if (event.type === "message.part.updated" && message.status !== "completed" && message.role !== "user") {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
syncedMessages.add(message.id);
|
|
155
|
+
syncMessageBackground(sessionId, message);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
} catch {
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
var index_default = OpenCodeSyncPlugin;
|
|
164
|
+
|
|
165
|
+
export {
|
|
166
|
+
getConfig,
|
|
167
|
+
setConfig,
|
|
168
|
+
clearConfig,
|
|
169
|
+
OpenCodeSyncPlugin,
|
|
170
|
+
index_default
|
|
171
|
+
};
|
package/dist/cli.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,30 +1,3 @@
|
|
|
1
|
-
interface PluginClient {
|
|
2
|
-
app: {
|
|
3
|
-
log: (entry: {
|
|
4
|
-
service: string;
|
|
5
|
-
level: "debug" | "info" | "warn" | "error";
|
|
6
|
-
message: string;
|
|
7
|
-
extra?: Record<string, unknown>;
|
|
8
|
-
}) => Promise<void>;
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
interface PluginContext {
|
|
12
|
-
project: unknown;
|
|
13
|
-
client: PluginClient;
|
|
14
|
-
$: unknown;
|
|
15
|
-
directory: string;
|
|
16
|
-
worktree: string;
|
|
17
|
-
}
|
|
18
|
-
interface PluginEvent {
|
|
19
|
-
type: string;
|
|
20
|
-
properties?: Record<string, unknown>;
|
|
21
|
-
}
|
|
22
|
-
interface PluginHooks {
|
|
23
|
-
event?: (input: {
|
|
24
|
-
event: PluginEvent;
|
|
25
|
-
}) => Promise<void>;
|
|
26
|
-
}
|
|
27
|
-
type Plugin = (ctx: PluginContext) => Promise<PluginHooks>;
|
|
28
1
|
interface Config {
|
|
29
2
|
convexUrl: string;
|
|
30
3
|
apiKey: string;
|
|
@@ -35,8 +8,26 @@ declare function clearConfig(): void;
|
|
|
35
8
|
/**
|
|
36
9
|
* OpenCode Sync Plugin
|
|
37
10
|
* Syncs sessions and messages to cloud storage via Convex backend
|
|
38
|
-
* Authentication: API Key (osk_*) from OpenSync Settings page
|
|
39
11
|
*/
|
|
40
|
-
declare const OpenCodeSyncPlugin:
|
|
12
|
+
declare const OpenCodeSyncPlugin: (ctx: {
|
|
13
|
+
client: {
|
|
14
|
+
app: {
|
|
15
|
+
log: (entry: {
|
|
16
|
+
service: string;
|
|
17
|
+
level: string;
|
|
18
|
+
message: string;
|
|
19
|
+
}) => Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
directory: string;
|
|
23
|
+
worktree: string;
|
|
24
|
+
}) => Promise<{
|
|
25
|
+
event: (input: {
|
|
26
|
+
event: {
|
|
27
|
+
type: string;
|
|
28
|
+
properties?: Record<string, unknown>;
|
|
29
|
+
};
|
|
30
|
+
}) => Promise<void>;
|
|
31
|
+
}>;
|
|
41
32
|
|
|
42
|
-
export { OpenCodeSyncPlugin, clearConfig, getConfig, setConfig };
|
|
33
|
+
export { OpenCodeSyncPlugin, clearConfig, OpenCodeSyncPlugin as default, getConfig, setConfig };
|
package/dist/index.js
CHANGED
|
@@ -2,11 +2,13 @@ import {
|
|
|
2
2
|
OpenCodeSyncPlugin,
|
|
3
3
|
clearConfig,
|
|
4
4
|
getConfig,
|
|
5
|
+
index_default,
|
|
5
6
|
setConfig
|
|
6
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-V6SCOAXD.js";
|
|
7
8
|
export {
|
|
8
9
|
OpenCodeSyncPlugin,
|
|
9
10
|
clearConfig,
|
|
11
|
+
index_default as default,
|
|
10
12
|
getConfig,
|
|
11
13
|
setConfig
|
|
12
14
|
};
|
package/package.json
CHANGED
package/dist/chunk-46RJJUZ6.js
DELETED
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import { homedir } from "os";
|
|
3
|
-
import { join } from "path";
|
|
4
|
-
import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
|
|
5
|
-
var CONFIG_DIR = join(homedir(), ".config", "opencode-sync");
|
|
6
|
-
var CONFIG_FILE = join(CONFIG_DIR, "config.json");
|
|
7
|
-
function readConfigFile() {
|
|
8
|
-
try {
|
|
9
|
-
if (!existsSync(CONFIG_FILE)) return null;
|
|
10
|
-
const content = readFileSync(CONFIG_FILE, "utf8");
|
|
11
|
-
return JSON.parse(content);
|
|
12
|
-
} catch {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
function writeConfigFile(config) {
|
|
17
|
-
try {
|
|
18
|
-
if (!existsSync(CONFIG_DIR)) {
|
|
19
|
-
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
20
|
-
}
|
|
21
|
-
writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), "utf8");
|
|
22
|
-
} catch {
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function getConfig() {
|
|
26
|
-
const config = readConfigFile();
|
|
27
|
-
if (!config || !config.convexUrl) return null;
|
|
28
|
-
return config;
|
|
29
|
-
}
|
|
30
|
-
function setConfig(cfg) {
|
|
31
|
-
writeConfigFile(cfg);
|
|
32
|
-
}
|
|
33
|
-
function clearConfig() {
|
|
34
|
-
try {
|
|
35
|
-
if (existsSync(CONFIG_FILE)) {
|
|
36
|
-
writeFileSync(CONFIG_FILE, "{}", "utf8");
|
|
37
|
-
}
|
|
38
|
-
} catch {
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function getApiKey() {
|
|
42
|
-
const cfg = getConfig();
|
|
43
|
-
if (!cfg || !cfg.apiKey) return null;
|
|
44
|
-
return cfg.apiKey;
|
|
45
|
-
}
|
|
46
|
-
function normalizeToSiteUrl(url) {
|
|
47
|
-
if (url.includes(".convex.cloud")) {
|
|
48
|
-
return url.replace(".convex.cloud", ".convex.site");
|
|
49
|
-
}
|
|
50
|
-
return url;
|
|
51
|
-
}
|
|
52
|
-
function getSiteUrl() {
|
|
53
|
-
const cfg = getConfig();
|
|
54
|
-
if (!cfg || !cfg.convexUrl) return null;
|
|
55
|
-
return normalizeToSiteUrl(cfg.convexUrl);
|
|
56
|
-
}
|
|
57
|
-
async function syncSession(session, client) {
|
|
58
|
-
const apiKey = getApiKey();
|
|
59
|
-
const siteUrl = getSiteUrl();
|
|
60
|
-
if (!apiKey || !siteUrl) {
|
|
61
|
-
await client.app.log({
|
|
62
|
-
service: "opencode-sync",
|
|
63
|
-
level: "warn",
|
|
64
|
-
message: "Not authenticated. Run: opencode-sync login"
|
|
65
|
-
});
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
try {
|
|
69
|
-
const response = await fetch(`${siteUrl}/sync/session`, {
|
|
70
|
-
method: "POST",
|
|
71
|
-
headers: {
|
|
72
|
-
"Content-Type": "application/json",
|
|
73
|
-
Authorization: `Bearer ${apiKey}`
|
|
74
|
-
},
|
|
75
|
-
body: JSON.stringify({
|
|
76
|
-
externalId: session.id,
|
|
77
|
-
title: session.title || extractTitle(session),
|
|
78
|
-
projectPath: session.cwd,
|
|
79
|
-
projectName: session.cwd?.split("/").pop(),
|
|
80
|
-
model: session.model,
|
|
81
|
-
provider: session.provider,
|
|
82
|
-
promptTokens: session.usage?.promptTokens || 0,
|
|
83
|
-
completionTokens: session.usage?.completionTokens || 0,
|
|
84
|
-
cost: session.usage?.cost || 0
|
|
85
|
-
})
|
|
86
|
-
});
|
|
87
|
-
if (!response.ok) {
|
|
88
|
-
const errorText = await response.text();
|
|
89
|
-
await client.app.log({
|
|
90
|
-
service: "opencode-sync",
|
|
91
|
-
level: "error",
|
|
92
|
-
message: `Session sync failed: ${errorText}`
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
} catch (e) {
|
|
96
|
-
await client.app.log({
|
|
97
|
-
service: "opencode-sync",
|
|
98
|
-
level: "error",
|
|
99
|
-
message: `Session sync error: ${e}`
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
async function syncMessage(sessionId, message, client) {
|
|
104
|
-
const apiKey = getApiKey();
|
|
105
|
-
const siteUrl = getSiteUrl();
|
|
106
|
-
if (!apiKey || !siteUrl) return;
|
|
107
|
-
const parts = extractParts(message.content);
|
|
108
|
-
try {
|
|
109
|
-
const response = await fetch(`${siteUrl}/sync/message`, {
|
|
110
|
-
method: "POST",
|
|
111
|
-
headers: {
|
|
112
|
-
"Content-Type": "application/json",
|
|
113
|
-
Authorization: `Bearer ${apiKey}`
|
|
114
|
-
},
|
|
115
|
-
body: JSON.stringify({
|
|
116
|
-
sessionExternalId: sessionId,
|
|
117
|
-
externalId: message.id,
|
|
118
|
-
role: message.role,
|
|
119
|
-
textContent: extractTextContent(message.content),
|
|
120
|
-
model: message.model,
|
|
121
|
-
promptTokens: message.usage?.promptTokens,
|
|
122
|
-
completionTokens: message.usage?.completionTokens,
|
|
123
|
-
durationMs: message.duration,
|
|
124
|
-
parts
|
|
125
|
-
})
|
|
126
|
-
});
|
|
127
|
-
if (!response.ok) {
|
|
128
|
-
const errorText = await response.text();
|
|
129
|
-
await client.app.log({
|
|
130
|
-
service: "opencode-sync",
|
|
131
|
-
level: "error",
|
|
132
|
-
message: `Message sync failed: ${errorText}`
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
} catch (e) {
|
|
136
|
-
await client.app.log({
|
|
137
|
-
service: "opencode-sync",
|
|
138
|
-
level: "error",
|
|
139
|
-
message: `Message sync error: ${e}`
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
function extractTitle(session) {
|
|
144
|
-
const firstMessage = session.messages?.find((m) => m.role === "user");
|
|
145
|
-
if (firstMessage) {
|
|
146
|
-
const text = extractTextContent(firstMessage.content);
|
|
147
|
-
if (text) {
|
|
148
|
-
return text.slice(0, 100) + (text.length > 100 ? "..." : "");
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return "Untitled Session";
|
|
152
|
-
}
|
|
153
|
-
function extractTextContent(content) {
|
|
154
|
-
if (typeof content === "string") return content;
|
|
155
|
-
if (Array.isArray(content)) {
|
|
156
|
-
return content.filter((p) => p.type === "text").map((p) => p.text).join("\n");
|
|
157
|
-
}
|
|
158
|
-
return "";
|
|
159
|
-
}
|
|
160
|
-
function extractParts(content) {
|
|
161
|
-
if (typeof content === "string") {
|
|
162
|
-
return [{ type: "text", content }];
|
|
163
|
-
}
|
|
164
|
-
if (Array.isArray(content)) {
|
|
165
|
-
return content.map((part) => {
|
|
166
|
-
if (part.type === "text") {
|
|
167
|
-
return { type: "text", content: part.text };
|
|
168
|
-
}
|
|
169
|
-
if (part.type === "tool_use" || part.type === "tool-call") {
|
|
170
|
-
const toolPart = part;
|
|
171
|
-
return {
|
|
172
|
-
type: "tool-call",
|
|
173
|
-
content: { name: toolPart.name, args: toolPart.input || toolPart.args || {} }
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
if (part.type === "tool_result" || part.type === "tool-result") {
|
|
177
|
-
const resultPart = part;
|
|
178
|
-
return {
|
|
179
|
-
type: "tool-result",
|
|
180
|
-
content: { result: resultPart.content || resultPart.result }
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
return { type: part.type, content: part };
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
return [];
|
|
187
|
-
}
|
|
188
|
-
var syncedMessages = /* @__PURE__ */ new Set();
|
|
189
|
-
var syncedSessions = /* @__PURE__ */ new Set();
|
|
190
|
-
var OpenCodeSyncPlugin = async ({ project, client, $, directory, worktree }) => {
|
|
191
|
-
const cfg = getConfig();
|
|
192
|
-
if (!cfg || !cfg.apiKey) {
|
|
193
|
-
await client.app.log({
|
|
194
|
-
service: "opencode-sync",
|
|
195
|
-
level: "warn",
|
|
196
|
-
message: "Not configured. Run: opencode-sync login"
|
|
197
|
-
});
|
|
198
|
-
} else {
|
|
199
|
-
await client.app.log({
|
|
200
|
-
service: "opencode-sync",
|
|
201
|
-
level: "info",
|
|
202
|
-
message: "Plugin initialized",
|
|
203
|
-
extra: { directory, worktree }
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
return {
|
|
207
|
-
// Handle all events via generic event handler
|
|
208
|
-
event: async ({ event }) => {
|
|
209
|
-
const props = event.properties;
|
|
210
|
-
if (event.type === "session.created") {
|
|
211
|
-
const session = props;
|
|
212
|
-
if (session?.id && !syncedSessions.has(session.id)) {
|
|
213
|
-
syncedSessions.add(session.id);
|
|
214
|
-
await syncSession(session, client);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
if (event.type === "session.updated") {
|
|
218
|
-
const session = props;
|
|
219
|
-
if (session?.id) {
|
|
220
|
-
await syncSession(session, client);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
if (event.type === "session.idle") {
|
|
224
|
-
const session = props;
|
|
225
|
-
if (session?.id) {
|
|
226
|
-
await syncSession(session, client);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
if (event.type === "message.updated") {
|
|
230
|
-
const messageProps = props;
|
|
231
|
-
const sessionId = messageProps?.sessionId;
|
|
232
|
-
const message = messageProps?.message;
|
|
233
|
-
if (sessionId && message?.id && !syncedMessages.has(message.id)) {
|
|
234
|
-
syncedMessages.add(message.id);
|
|
235
|
-
await syncMessage(sessionId, message, client);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
if (event.type === "message.part.updated") {
|
|
239
|
-
const messageProps = props;
|
|
240
|
-
const sessionId = messageProps?.sessionId;
|
|
241
|
-
const message = messageProps?.message;
|
|
242
|
-
if (sessionId && message?.id) {
|
|
243
|
-
if (message.status === "completed" || message.role === "user") {
|
|
244
|
-
if (!syncedMessages.has(message.id)) {
|
|
245
|
-
syncedMessages.add(message.id);
|
|
246
|
-
await syncMessage(sessionId, message, client);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
export {
|
|
256
|
-
getConfig,
|
|
257
|
-
setConfig,
|
|
258
|
-
clearConfig,
|
|
259
|
-
OpenCodeSyncPlugin
|
|
260
|
-
};
|