doer-agent 0.8.2 → 0.8.3

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.
@@ -29,6 +29,7 @@ function buildNotesAiPrompt(request) {
29
29
  "You are editing a Markdown note inside Doer.",
30
30
  "Return only Markdown content. Do not include explanations, preambles, or code fences unless the requested content itself needs them.",
31
31
  "If a selection is provided, return only the replacement for that selection. If no selection is provided, return content to insert at the cursor.",
32
+ "When you generate an image, do not write attachment:image links. The generated image will be inserted into the note automatically.",
32
33
  "",
33
34
  `<instruction>\n${instruction}\n</instruction>`,
34
35
  `<document>\n${document}\n</document>`,
@@ -64,6 +65,18 @@ function agentMessageDeltaFromParams(params) {
64
65
  }
65
66
  return stringValue(record.delta) || stringValue(record.text);
66
67
  }
68
+ function generatedImageMarkdownFromParams(params, threadId) {
69
+ const record = recordValue(params);
70
+ const item = recordValue(record?.item);
71
+ if (!record || !item || stringValue(item.type) !== "imageGeneration") {
72
+ return "";
73
+ }
74
+ const imageId = stringValue(item.id);
75
+ if (!threadId || !imageId) {
76
+ return "";
77
+ }
78
+ return `\n\n![generated image](.codex/generated_images/${threadId}/${imageId}.png)\n\n`;
79
+ }
67
80
  function terminalErrorFromParams(params) {
68
81
  const record = recordValue(params);
69
82
  const error = recordValue(record?.error);
@@ -71,7 +84,7 @@ function terminalErrorFromParams(params) {
71
84
  stringValue(error?.message) ||
72
85
  stringValue(record?.reason);
73
86
  }
74
- async function archiveThread(args) {
87
+ async function archiveCompletedThread(args) {
75
88
  try {
76
89
  await args.manager.request("thread/archive", { threadId: args.threadId }, 30_000);
77
90
  }
@@ -109,7 +122,7 @@ async function runNotesAiSession(args) {
109
122
  callback();
110
123
  };
111
124
  args.abortController.signal.addEventListener("abort", () => {
112
- settleCompleted(() => resolve());
125
+ settleCompleted(() => resolve("aborted"));
113
126
  }, { once: true });
114
127
  cleanupNotification = args.manager.onNotification((method, params) => {
115
128
  const eventThreadId = threadIdFromParams(params);
@@ -134,6 +147,18 @@ async function runNotesAiSession(args) {
134
147
  });
135
148
  return;
136
149
  }
150
+ if (method === "item/completed") {
151
+ const markdown = generatedImageMarkdownFromParams(params, threadId);
152
+ if (!markdown) {
153
+ return;
154
+ }
155
+ publishEvent({
156
+ nc: args.nc,
157
+ subject: args.eventsSubject,
158
+ payload: { type: "delta", sessionId: args.sessionId, text: markdown },
159
+ });
160
+ return;
161
+ }
137
162
  if (!isTerminalTurnMethod(method)) {
138
163
  return;
139
164
  }
@@ -144,7 +169,7 @@ async function runNotesAiSession(args) {
144
169
  subject: args.eventsSubject,
145
170
  payload: { type: "done", sessionId: args.sessionId },
146
171
  });
147
- resolve();
172
+ resolve("completed");
148
173
  });
149
174
  return;
150
175
  }
@@ -177,21 +202,19 @@ async function runNotesAiSession(args) {
177
202
  if (args.abortController.signal.aborted) {
178
203
  return;
179
204
  }
180
- await completed.finally(() => cleanupNotification());
181
- }
182
- catch (error) {
183
- settleCompleted(() => { });
184
- throw error;
185
- }
186
- finally {
187
- if (threadId) {
188
- await archiveThread({
205
+ const completion = await completed.finally(() => cleanupNotification());
206
+ if (completion === "completed") {
207
+ await archiveCompletedThread({
189
208
  manager: args.manager,
190
209
  threadId,
191
210
  onError: args.onError,
192
211
  });
193
212
  }
194
213
  }
214
+ catch (error) {
215
+ settleCompleted(() => { });
216
+ throw error;
217
+ }
195
218
  }
196
219
  async function handleStart(args) {
197
220
  const sessionId = stringValue(args.request.sessionId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doer-agent",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "Reverse-polling agent runtime for doer",
5
5
  "type": "module",
6
6
  "main": "dist/agent.js",