opencode-sync-plugin 0.1.8 → 0.1.9

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,67 @@
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
+ function getConfigPaths() {
10
+ const { homedir } = __require("os");
11
+ const { join } = __require("path");
12
+ const configDir = join(homedir(), ".config", "opencode-sync");
13
+ const configFile = join(configDir, "config.json");
14
+ return { configDir, configFile };
15
+ }
16
+ function readConfigFile() {
17
+ try {
18
+ const { existsSync, readFileSync } = __require("fs");
19
+ const { configFile } = getConfigPaths();
20
+ if (!existsSync(configFile)) return null;
21
+ const content = readFileSync(configFile, "utf8");
22
+ return JSON.parse(content);
23
+ } catch {
24
+ return null;
25
+ }
26
+ }
27
+ function writeConfigFile(config) {
28
+ try {
29
+ const { existsSync, writeFileSync, mkdirSync } = __require("fs");
30
+ const { configDir, configFile } = getConfigPaths();
31
+ if (!existsSync(configDir)) {
32
+ mkdirSync(configDir, { recursive: true });
33
+ }
34
+ writeFileSync(configFile, JSON.stringify(config, null, 2), "utf8");
35
+ } catch {
36
+ }
37
+ }
38
+ function getConfig() {
39
+ const config = readConfigFile();
40
+ if (!config || !config.convexUrl) return null;
41
+ return config;
42
+ }
43
+ function setConfig(cfg) {
44
+ writeConfigFile(cfg);
45
+ }
46
+ function clearConfig() {
47
+ try {
48
+ const { existsSync, writeFileSync } = __require("fs");
49
+ const { configFile } = getConfigPaths();
50
+ if (existsSync(configFile)) {
51
+ writeFileSync(configFile, "{}", "utf8");
52
+ }
53
+ } catch {
54
+ }
55
+ }
56
+ var OpenCodeSyncPlugin = async (ctx) => {
57
+ return {};
58
+ };
59
+ var index_default = OpenCodeSyncPlugin;
60
+
61
+ export {
62
+ getConfig,
63
+ setConfig,
64
+ clearConfig,
65
+ OpenCodeSyncPlugin,
66
+ index_default
67
+ };
package/dist/cli.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  clearConfig,
4
4
  getConfig,
5
5
  setConfig
6
- } from "./chunk-V6SCOAXD.js";
6
+ } from "./chunk-SLPXDOH3.js";
7
7
 
8
8
  // src/cli.ts
9
9
  import { readFileSync, existsSync } from "fs";
package/dist/index.d.ts CHANGED
@@ -5,29 +5,6 @@ interface Config {
5
5
  declare function getConfig(): Config | null;
6
6
  declare function setConfig(cfg: Config): void;
7
7
  declare function clearConfig(): void;
8
- /**
9
- * OpenCode Sync Plugin
10
- * Syncs sessions and messages to cloud storage via Convex backend
11
- */
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
- }>;
8
+ declare const OpenCodeSyncPlugin: (ctx: Record<string, unknown>) => Promise<{}>;
32
9
 
33
10
  export { OpenCodeSyncPlugin, clearConfig, OpenCodeSyncPlugin as default, getConfig, setConfig };
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  getConfig,
5
5
  index_default,
6
6
  setConfig
7
- } from "./chunk-V6SCOAXD.js";
7
+ } from "./chunk-SLPXDOH3.js";
8
8
  export {
9
9
  OpenCodeSyncPlugin,
10
10
  clearConfig,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-sync-plugin",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Sync your OpenCode sessions to the cloud",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,171 +0,0 @@
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
- };