gnhf 0.1.13 → 0.1.14

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.
Files changed (2) hide show
  1. package/dist/cli.mjs +11 -20
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -1516,7 +1516,7 @@ var OpenCodeAgent = class {
1516
1516
  let messageRequestError = null;
1517
1517
  const messageRequest = (async () => {
1518
1518
  try {
1519
- const body = await this.requestText(server, `/session/${sessionId}/message`, {
1519
+ await this.request(server, `/session/${sessionId}/prompt_async`, {
1520
1520
  method: "POST",
1521
1521
  body: {
1522
1522
  role: "user",
@@ -1530,12 +1530,11 @@ var OpenCodeAgent = class {
1530
1530
  });
1531
1531
  appendDebugLog("opencode:message-post:end", {
1532
1532
  sessionId,
1533
- elapsedMs: Date.now() - messagePostStartedAt,
1534
- bodyLength: body.length
1533
+ elapsedMs: Date.now() - messagePostStartedAt
1535
1534
  });
1536
1535
  return {
1537
1536
  ok: true,
1538
- body
1537
+ body: ""
1539
1538
  };
1540
1539
  } catch (error) {
1541
1540
  messageRequestError = error;
@@ -1565,6 +1564,7 @@ var OpenCodeAgent = class {
1565
1564
  let lastText = null;
1566
1565
  let lastFinalAnswerText = null;
1567
1566
  let lastUsageSignature = "0:0:0:0";
1567
+ let structuredOutputFromSSE = null;
1568
1568
  const eventCounts = {};
1569
1569
  let firstEventAtMs = null;
1570
1570
  let lastEventAtMs = null;
@@ -1689,6 +1689,7 @@ var OpenCodeAgent = class {
1689
1689
  }
1690
1690
  if (payload?.type === "message.updated") {
1691
1691
  if (properties.info?.role === "assistant") updateUsage(properties.info.id, properties.info.tokens);
1692
+ if (properties.info?.structured) structuredOutputFromSSE = properties.info.structured;
1692
1693
  return false;
1693
1694
  }
1694
1695
  return payload?.type === "session.idle";
@@ -1796,9 +1797,8 @@ var OpenCodeAgent = class {
1796
1797
  throw messageResult.error;
1797
1798
  }
1798
1799
  const body = messageResult.body;
1799
- let response;
1800
- try {
1801
- response = JSON.parse(body);
1800
+ if (body) try {
1801
+ JSON.parse(body);
1802
1802
  } catch (error) {
1803
1803
  appendDebugLog("opencode:response:parse-error", {
1804
1804
  sessionId,
@@ -1806,22 +1806,14 @@ var OpenCodeAgent = class {
1806
1806
  bodySample: body.slice(0, 512),
1807
1807
  error: serializeError(error)
1808
1808
  });
1809
- throw new Error(`Failed to parse opencode response: ${error instanceof Error ? error.message : String(error)}`);
1810
- }
1811
- if (response.info?.role === "assistant") updateUsage(response.info.id, response.info.tokens);
1812
- for (const part of response.parts ?? []) {
1813
- if (part.type !== "text" || typeof part.text !== "string") continue;
1814
- if (!part.text.trim()) continue;
1815
- lastText = part.text;
1816
- if (part.metadata?.openai?.phase === "final_answer") lastFinalAnswerText = part.text;
1817
1809
  }
1818
- if (response.info?.structured) {
1810
+ if (structuredOutputFromSSE) {
1819
1811
  appendDebugLog("opencode:output:structured", {
1820
1812
  sessionId,
1821
- source: "response.info.structured"
1813
+ source: "sse"
1822
1814
  });
1823
1815
  return {
1824
- output: response.info.structured,
1816
+ output: structuredOutputFromSSE,
1825
1817
  usage
1826
1818
  };
1827
1819
  }
@@ -1829,8 +1821,7 @@ var OpenCodeAgent = class {
1829
1821
  if (!outputText) {
1830
1822
  appendDebugLog("opencode:output:missing", {
1831
1823
  sessionId,
1832
- hasInfo: response.info !== void 0,
1833
- partCount: response.parts?.length ?? 0
1824
+ hasStructuredOutput: structuredOutputFromSSE !== null
1834
1825
  });
1835
1826
  throw new Error("opencode returned no text output");
1836
1827
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gnhf",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "description": "Before I go to bed, I tell my agents: good night, have fun",
5
5
  "type": "module",
6
6
  "bin": {