@defend-tech/opencode-optima 0.1.18 → 0.1.19

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 CHANGED
@@ -9238,20 +9238,30 @@ async function createOpenCodeSession(client, { title, directory } = {}) {
9238
9238
  const result = await client.session.create({ query: { directory }, body: { title } });
9239
9239
  return result?.data?.id || result?.id;
9240
9240
  }
9241
+ function assertOpenCodePromptAccepted(result) {
9242
+ const status = Number(result?.status || result?.response?.status || result?.error?.status || 0);
9243
+ if (status >= 400 || result?.ok === false || result?.error) {
9244
+ const message = result?.error?.message || result?.message || `OpenCode prompt request failed${status ? ` with status ${status}` : ""}.`;
9245
+ throw new Error(message);
9246
+ }
9247
+ return result;
9248
+ }
9241
9249
  async function callOpenCodePromptWithFallbacks(method, sessionId, flatPayload, structuredPayload) {
9242
- try {
9243
- return await method({ sessionID: sessionId, ...flatPayload });
9244
- } catch (flatError) {
9250
+ const attempts = [
9251
+ { id: sessionId, ...flatPayload },
9252
+ { sessionID: sessionId, ...flatPayload },
9253
+ { ...structuredPayload, path: { sessionID: sessionId } },
9254
+ { ...structuredPayload, path: { id: sessionId } }
9255
+ ];
9256
+ let firstError = null;
9257
+ for (const attempt of attempts) {
9245
9258
  try {
9246
- return await method({ ...structuredPayload, path: { sessionID: sessionId } });
9247
- } catch {
9248
- try {
9249
- return await method({ ...structuredPayload, path: { id: sessionId } });
9250
- } catch {
9251
- throw flatError;
9252
- }
9259
+ return assertOpenCodePromptAccepted(await method(attempt));
9260
+ } catch (error) {
9261
+ firstError ??= error;
9253
9262
  }
9254
9263
  }
9264
+ throw firstError;
9255
9265
  }
9256
9266
  async function sendOpenCodeSessionEvent(client, { sessionId, agent, text, directory } = {}) {
9257
9267
  const parts = [{ type: "text", text }];
@@ -9245,20 +9245,30 @@ async function createOpenCodeSession(client, { title, directory } = {}) {
9245
9245
  const result = await client.session.create({ query: { directory }, body: { title } });
9246
9246
  return result?.data?.id || result?.id;
9247
9247
  }
9248
+ function assertOpenCodePromptAccepted(result) {
9249
+ const status = Number(result?.status || result?.response?.status || result?.error?.status || 0);
9250
+ if (status >= 400 || result?.ok === false || result?.error) {
9251
+ const message = result?.error?.message || result?.message || `OpenCode prompt request failed${status ? ` with status ${status}` : ""}.`;
9252
+ throw new Error(message);
9253
+ }
9254
+ return result;
9255
+ }
9248
9256
  async function callOpenCodePromptWithFallbacks(method, sessionId, flatPayload, structuredPayload) {
9249
- try {
9250
- return await method({ sessionID: sessionId, ...flatPayload });
9251
- } catch (flatError) {
9257
+ const attempts = [
9258
+ { id: sessionId, ...flatPayload },
9259
+ { sessionID: sessionId, ...flatPayload },
9260
+ { ...structuredPayload, path: { sessionID: sessionId } },
9261
+ { ...structuredPayload, path: { id: sessionId } }
9262
+ ];
9263
+ let firstError = null;
9264
+ for (const attempt of attempts) {
9252
9265
  try {
9253
- return await method({ ...structuredPayload, path: { sessionID: sessionId } });
9254
- } catch {
9255
- try {
9256
- return await method({ ...structuredPayload, path: { id: sessionId } });
9257
- } catch {
9258
- throw flatError;
9259
- }
9266
+ return assertOpenCodePromptAccepted(await method(attempt));
9267
+ } catch (error) {
9268
+ firstError ??= error;
9260
9269
  }
9261
9270
  }
9271
+ throw firstError;
9262
9272
  }
9263
9273
  async function sendOpenCodeSessionEvent(client, { sessionId, agent, text, directory } = {}) {
9264
9274
  const parts = [{ type: "text", text }];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defend-tech/opencode-optima",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+ssh://git@github.com/defend-tech/opencode-optima.git"