@c4t4/heyamigo 0.8.11 → 0.8.12

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/ai/codex.js +30 -17
  2. package/package.json +1 -1
package/dist/ai/codex.js CHANGED
@@ -100,6 +100,27 @@ function buildExecArgs(params) {
100
100
  args.push(params.prompt);
101
101
  return args;
102
102
  }
103
+ function extractReply(ev) {
104
+ // Primary shape: item.completed with item.type === 'agent_message'
105
+ if (ev.type === 'item.completed' &&
106
+ ev.item &&
107
+ ev.item.type === 'agent_message' &&
108
+ typeof ev.item.text === 'string') {
109
+ return ev.item.text;
110
+ }
111
+ // Older shape: msg.type === 'agent_message' with msg.message
112
+ if (ev.msg &&
113
+ ev.msg.type === 'agent_message' &&
114
+ typeof ev.msg.message === 'string') {
115
+ return ev.msg.message;
116
+ }
117
+ // Last-ditch top-level fields
118
+ if (typeof ev.message === 'string')
119
+ return ev.message;
120
+ if (typeof ev.text === 'string')
121
+ return ev.text;
122
+ return null;
123
+ }
103
124
  function parseCodexOutput(stdout) {
104
125
  const events = [];
105
126
  for (const line of stdout.split(/\r?\n/)) {
@@ -115,37 +136,29 @@ function parseCodexOutput(stdout) {
115
136
  }
116
137
  if (events.length === 0)
117
138
  return null;
118
- // Find the final agent message. Codex labels it variously across
119
- // versions — try the common shapes in order.
139
+ // Latest agent message wins (handles multi-turn output).
120
140
  let reply = null;
121
141
  for (let i = events.length - 1; i >= 0; i--) {
122
- const ev = events[i];
123
- if (ev.msg?.type === 'agent_message' &&
124
- typeof ev.msg.message === 'string') {
125
- reply = ev.msg.message;
126
- break;
127
- }
128
- if (typeof ev.message === 'string') {
129
- reply = ev.message;
130
- break;
131
- }
132
- if (typeof ev.text === 'string') {
133
- reply = ev.text;
142
+ const r = extractReply(events[i]);
143
+ if (r !== null) {
144
+ reply = r;
134
145
  break;
135
146
  }
136
147
  }
137
148
  if (reply === null)
138
149
  return null;
139
- // Session id — Codex uses different field names across versions.
150
+ // Session id — `thread_id` on thread.started in current Codex; older
151
+ // builds used session_id / conversation_id / response_id.
140
152
  let sessionId;
141
153
  for (const ev of events) {
142
- const id = ev.session_id ?? ev.conversation_id ?? ev.response_id;
154
+ const id = ev.thread_id ?? ev.session_id ?? ev.conversation_id ?? ev.response_id;
143
155
  if (typeof id === 'string' && id) {
144
156
  sessionId = id;
145
157
  break;
146
158
  }
147
159
  }
148
- // Usage — last event with a usage object wins (final turn totals).
160
+ // Usage — turn.completed carries final totals; fall back to any event
161
+ // with a usage object if the type marker is missing.
149
162
  let inputTokens = 0;
150
163
  let outputTokens = 0;
151
164
  let cacheReadTokens = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c4t4/heyamigo",
3
- "version": "0.8.11",
3
+ "version": "0.8.12",
4
4
  "description": "WhatsApp AI bot powered by Claude with long-term memory, browser control, and role-based access",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",