@defend-tech/opencode-optima 0.1.14 → 0.1.15
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/index.js +14 -8
- package/dist/sanitize_cli.js +14 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9207,24 +9207,30 @@ async function createOpenCodeSession(client, { title, directory } = {}) {
|
|
|
9207
9207
|
const result = await client.session.create({ query: { directory }, body: { title } });
|
|
9208
9208
|
return result?.data?.id || result?.id;
|
|
9209
9209
|
}
|
|
9210
|
-
async function
|
|
9210
|
+
async function callOpenCodePromptWithFallbacks(method, sessionId, flatPayload, structuredPayload) {
|
|
9211
9211
|
try {
|
|
9212
|
-
return await method({
|
|
9213
|
-
} catch (
|
|
9212
|
+
return await method({ sessionID: sessionId, ...flatPayload });
|
|
9213
|
+
} catch (flatError) {
|
|
9214
9214
|
try {
|
|
9215
|
-
return await method({ ...
|
|
9215
|
+
return await method({ ...structuredPayload, path: { sessionID: sessionId } });
|
|
9216
9216
|
} catch {
|
|
9217
|
-
|
|
9217
|
+
try {
|
|
9218
|
+
return await method({ ...structuredPayload, path: { id: sessionId } });
|
|
9219
|
+
} catch {
|
|
9220
|
+
throw flatError;
|
|
9221
|
+
}
|
|
9218
9222
|
}
|
|
9219
9223
|
}
|
|
9220
9224
|
}
|
|
9221
9225
|
async function sendOpenCodeSessionEvent(client, { sessionId, agent, text, directory } = {}) {
|
|
9222
|
-
const
|
|
9226
|
+
const parts = [{ type: "text", text }];
|
|
9227
|
+
const flatPayload = { directory, agent, parts };
|
|
9228
|
+
const structuredPayload = { query: { directory }, body: { agent, parts } };
|
|
9223
9229
|
if (typeof client?.session?.prompt === "function") {
|
|
9224
|
-
return
|
|
9230
|
+
return callOpenCodePromptWithFallbacks(client.session.prompt.bind(client.session), sessionId, flatPayload, structuredPayload);
|
|
9225
9231
|
}
|
|
9226
9232
|
if (typeof client?.session?.promptAsync === "function") {
|
|
9227
|
-
return
|
|
9233
|
+
return callOpenCodePromptWithFallbacks(client.session.promptAsync.bind(client.session), sessionId, flatPayload, structuredPayload);
|
|
9228
9234
|
}
|
|
9229
9235
|
throw new Error("OpenCode client does not expose session.prompt or session.promptAsync.");
|
|
9230
9236
|
}
|
package/dist/sanitize_cli.js
CHANGED
|
@@ -9214,24 +9214,30 @@ async function createOpenCodeSession(client, { title, directory } = {}) {
|
|
|
9214
9214
|
const result = await client.session.create({ query: { directory }, body: { title } });
|
|
9215
9215
|
return result?.data?.id || result?.id;
|
|
9216
9216
|
}
|
|
9217
|
-
async function
|
|
9217
|
+
async function callOpenCodePromptWithFallbacks(method, sessionId, flatPayload, structuredPayload) {
|
|
9218
9218
|
try {
|
|
9219
|
-
return await method({
|
|
9220
|
-
} catch (
|
|
9219
|
+
return await method({ sessionID: sessionId, ...flatPayload });
|
|
9220
|
+
} catch (flatError) {
|
|
9221
9221
|
try {
|
|
9222
|
-
return await method({ ...
|
|
9222
|
+
return await method({ ...structuredPayload, path: { sessionID: sessionId } });
|
|
9223
9223
|
} catch {
|
|
9224
|
-
|
|
9224
|
+
try {
|
|
9225
|
+
return await method({ ...structuredPayload, path: { id: sessionId } });
|
|
9226
|
+
} catch {
|
|
9227
|
+
throw flatError;
|
|
9228
|
+
}
|
|
9225
9229
|
}
|
|
9226
9230
|
}
|
|
9227
9231
|
}
|
|
9228
9232
|
async function sendOpenCodeSessionEvent(client, { sessionId, agent, text, directory } = {}) {
|
|
9229
|
-
const
|
|
9233
|
+
const parts = [{ type: "text", text }];
|
|
9234
|
+
const flatPayload = { directory, agent, parts };
|
|
9235
|
+
const structuredPayload = { query: { directory }, body: { agent, parts } };
|
|
9230
9236
|
if (typeof client?.session?.prompt === "function") {
|
|
9231
|
-
return
|
|
9237
|
+
return callOpenCodePromptWithFallbacks(client.session.prompt.bind(client.session), sessionId, flatPayload, structuredPayload);
|
|
9232
9238
|
}
|
|
9233
9239
|
if (typeof client?.session?.promptAsync === "function") {
|
|
9234
|
-
return
|
|
9240
|
+
return callOpenCodePromptWithFallbacks(client.session.promptAsync.bind(client.session), sessionId, flatPayload, structuredPayload);
|
|
9235
9241
|
}
|
|
9236
9242
|
throw new Error("OpenCode client does not expose session.prompt or session.promptAsync.");
|
|
9237
9243
|
}
|