@agentorg/cli 0.0.7 → 0.0.8

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.
@@ -31,8 +31,10 @@ export declare function createChats(options: {
31
31
  log: Log;
32
32
  }): {
33
33
  /**
34
- * Say a message in a chat, or in a new chat it starts. With no turn in the chat it starts one;
35
- * a turn running there takes it at its next model request.
34
+ * Say a message in a chat, or in a new chat it starts. A new chat's first message is put to
35
+ * the agent's main loop, which gives it to new work or to work in a turn; from then on the
36
+ * chat's messages are that work's: with no turn of it running one starts a turn, and a turn
37
+ * running takes it at its next model request.
36
38
  */
37
39
  send({ chat, text }: Input<"send">): Promise<{
38
40
  chat: string;
@@ -77,14 +79,14 @@ export declare function createChats(options: {
77
79
  */
78
80
  stop: () => Promise<void>;
79
81
  start: () => void;
80
- /** Go on with the turns that were cut off when the agent last ran, each once. */
82
+ /** Go on with what was cut off when the agent last ran, each once: turns, and messages waiting. */
81
83
  resume(): Promise<void>;
82
84
  /**
83
- * Close for good: its turns are cut, and none starts after. They stay marked, so the engine
84
- * that opens this store next goes on with them.
85
+ * Close for good: its turns are cut, and none starts after. They stay marked, as do messages
86
+ * no work has taken, so the engine that opens this store next goes on with them.
85
87
  */
86
88
  close: () => Promise<void>;
87
- /** Settles when every chat's latest turn has written all it will. */
89
+ /** Settles when every piece of work's latest turn has written all it will. */
88
90
  settled(): Promise<void>;
89
91
  /** Streamed text of the model request running now. */
90
92
  delta(requestId: string, text: string): void;
@@ -106,10 +106,10 @@ export function createChats(options) {
106
106
  /** The chats, by id, once their entries are read. */
107
107
  const chats = new Map();
108
108
  let loaded;
109
- /** The chats whose loops are at work now: the agent is working while there is one. */
110
- const atWork = new Set();
111
- const stateNow = () => ({ state: atWork.size > 0 ? "working" : "idle" });
112
- /** The chats' loops: a chat is the looper's thread of the same name. */
109
+ /** Whether the agent is working, as its looper last said. */
110
+ let working = false;
111
+ const stateNow = () => ({ state: working ? "working" : "idle" });
112
+ /** The agent's loops: a chat is the looper's thread of the same name. */
113
113
  const looper = forChats(createLooper({
114
114
  store: forLooper(store),
115
115
  model: options.model,
@@ -122,22 +122,18 @@ export function createChats(options) {
122
122
  emit.message({ ...message, chat: thread });
123
123
  },
124
124
  delta: (thread, id, text) => emit.delta({ chat: thread, id, text }),
125
- status(thread, status) {
126
- const was = atWork.size > 0;
127
- if (status.state === "thinking" || status.state === "tool")
128
- atWork.add(thread);
129
- else
130
- atWork.delete(thread);
131
- // A turn that failed left its chat's message with no answer: the chat is told why,
132
- // before the agent is said to be idle.
125
+ working(on) {
126
+ working = on;
127
+ emit.status(stateNow());
128
+ },
129
+ // A message in the chat got no answer: the chat is told why. The looper says this before
130
+ // it says the agent is idle.
131
+ failed(thread, { code, message }) {
133
132
  const held = chats.get(thread);
134
- if (status.state === "error" && held) {
135
- const { code, message } = status.detail;
136
- held.stored.problem = { code: head(code, 128), message: head(message, 2000) };
137
- told(held);
138
- }
139
- if (atWork.size > 0 !== was)
140
- emit.status(stateNow());
133
+ if (!held)
134
+ return;
135
+ held.stored.problem = { code: head(code, 128), message: head(message, 2000) };
136
+ told(held);
141
137
  },
142
138
  },
143
139
  stopped: options.stopped,
@@ -267,8 +263,10 @@ export function createChats(options) {
267
263
  };
268
264
  return {
269
265
  /**
270
- * Say a message in a chat, or in a new chat it starts. With no turn in the chat it starts one;
271
- * a turn running there takes it at its next model request.
266
+ * Say a message in a chat, or in a new chat it starts. A new chat's first message is put to
267
+ * the agent's main loop, which gives it to new work or to work in a turn; from then on the
268
+ * chat's messages are that work's: with no turn of it running one starts a turn, and a turn
269
+ * running takes it at its next model request.
272
270
  */
273
271
  async send({ chat, text }) {
274
272
  if (chat !== undefined) {
@@ -332,18 +330,18 @@ export function createChats(options) {
332
330
  */
333
331
  stop: () => looper.stop(),
334
332
  start: () => looper.start(),
335
- /** Go on with the turns that were cut off when the agent last ran, each once. */
333
+ /** Go on with what was cut off when the agent last ran, each once: turns, and messages waiting. */
336
334
  async resume() {
337
335
  // The chats first: what a turn says moves its chat in the list.
338
336
  await load();
339
337
  await looper.resume();
340
338
  },
341
339
  /**
342
- * Close for good: its turns are cut, and none starts after. They stay marked, so the engine
343
- * that opens this store next goes on with them.
340
+ * Close for good: its turns are cut, and none starts after. They stay marked, as do messages
341
+ * no work has taken, so the engine that opens this store next goes on with them.
344
342
  */
345
343
  close: () => looper.close(),
346
- /** Settles when every chat's latest turn has written all it will. */
344
+ /** Settles when every piece of work's latest turn has written all it will. */
347
345
  async settled() {
348
346
  await loaded?.catch(() => undefined);
349
347
  await looper.settled();
@@ -68,7 +68,7 @@ export function startEngine(ctx, options) {
68
68
  * settings answer, and no tools slot is away. As the agent starts, what it is bound to may not
69
69
  * be running yet, so this is looked at again whenever that may have changed: a slot's provider
70
70
  * is back, a tools slot is made or gone, or one says its tools changed. A tools slot that stays
71
- * away holds them back; a message in a chat starts that chat's turn anyway.
71
+ * away holds them back; a message in a chat starts a turn anyway.
72
72
  */
73
73
  let wentOn = false;
74
74
  /** Each tools slot heard for its tools changing, with how to stop hearing it. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentorg/cli",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "AgentOrg as one app: the Hub, the person's gateway and the shell, on loopback.",
5
5
  "license": "MIT",
6
6
  "repository": {