@agentshouse/kit 0.2.1-alpha.1 → 0.2.1-alpha.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.
@@ -14,6 +14,9 @@ const KILLED = 'the conversation was killed';
14
14
  function causeOf(error) {
15
15
  return error instanceof Error ? error.message : String(error);
16
16
  }
17
+ function answerMessage(request, response) {
18
+ return `The User answered a question you asked earlier.\nQuestion: ${JSON.stringify(request)}\nAnswer: ${JSON.stringify(response)}`;
19
+ }
17
20
  function logged(error) {
18
21
  process.stderr.write(`kit: ${causeOf(error)}\n`);
19
22
  }
@@ -36,11 +39,11 @@ class Turn {
36
39
  unsentFrom = null;
37
40
  draftSequence = 0;
38
41
  planSequence = 0;
42
+ entries = null;
39
43
  questions = 0;
40
44
  secrets = 0;
41
45
  prompt = null;
42
46
  ended = false;
43
- ready = Promise.resolve();
44
47
  }
45
48
  class Conversation {
46
49
  id;
@@ -140,8 +143,13 @@ export class Conversations {
140
143
  }
141
144
  if (input.kind === 'option')
142
145
  await this.option(conversation, String(input.option), input.value);
143
- if (input.kind === 'answer')
144
- this.questions.get(String(input.interaction_id))?.answer(input.response);
146
+ if (input.kind === 'answer') {
147
+ const question = this.questions.get(String(input.interaction_id));
148
+ if (question === undefined) {
149
+ return this.message(conversation, { ...input, text: answerMessage(input.request, input.response), files: [], first: false });
150
+ }
151
+ question.answer(input.response);
152
+ }
145
153
  return {};
146
154
  }
147
155
  async open(conversation, input) {
@@ -340,9 +348,19 @@ export class Conversations {
340
348
  report(conversation) {
341
349
  const turn = new Turn();
342
350
  conversation.open++;
343
- turn.ready = this.deliver(conversation, turn, 'started', {}).then(() => undefined, logged);
351
+ void this.deliver(conversation, turn, 'started', {})
352
+ .then(() => this.admitted(conversation, turn))
353
+ .catch(logged);
344
354
  return turn;
345
355
  }
356
+ admitted(conversation, turn) {
357
+ if (turn.text !== '') {
358
+ turn.unsentFrom = 0;
359
+ this.draft(conversation, turn);
360
+ }
361
+ if (turn.entries !== null)
362
+ this.plan(conversation, turn);
363
+ }
346
364
  begin(conversation) {
347
365
  const turn = this.report(conversation);
348
366
  conversation.turn = turn;
@@ -479,12 +497,12 @@ export class Conversations {
479
497
  if (update.sessionUpdate === 'agent_message_chunk' && update.content.type === 'text') {
480
498
  const turn = this.started(conversation);
481
499
  turn.text += update.content.text;
482
- const text = turn.text;
483
- void turn.ready.then(() => this.draft(conversation, turn, text));
500
+ this.draft(conversation, turn);
484
501
  }
485
502
  else if (update.sessionUpdate === 'plan') {
486
503
  const turn = this.started(conversation);
487
- void turn.ready.then(() => this.plan(conversation, turn, update.entries));
504
+ turn.entries = update.entries;
505
+ this.plan(conversation, turn);
488
506
  }
489
507
  else if (update.sessionUpdate === 'agent_thought_chunk' || update.sessionUpdate === 'tool_call') {
490
508
  this.started(conversation);
@@ -503,8 +521,8 @@ export class Conversations {
503
521
  conversation.jobs.delete(job.id);
504
522
  this.kit.changed();
505
523
  }
506
- draft(conversation, turn, text) {
507
- const blocks = blocksOf(text);
524
+ draft(conversation, turn) {
525
+ const blocks = blocksOf(turn.text);
508
526
  const from = Math.min(firstChange(turn.sent, blocks), turn.unsentFrom ?? Infinity);
509
527
  const sent = this.kit.send({
510
528
  type: 'draft',
@@ -523,14 +541,14 @@ export class Conversations {
523
541
  turn.unsentFrom = from;
524
542
  }
525
543
  }
526
- plan(conversation, turn, entries) {
544
+ plan(conversation, turn) {
527
545
  const sent = this.kit.send({
528
546
  type: 'plan',
529
547
  conversation_id: conversation.id,
530
548
  turn_id: turn.id,
531
549
  sequence: turn.planSequence + 1,
532
550
  from: 0,
533
- steps: entries.map((entry) => ({ label: entry.content, priority: entry.priority, status: entry.status })),
551
+ steps: turn.entries.map((entry) => ({ label: entry.content, priority: entry.priority, status: entry.status })),
534
552
  });
535
553
  if (sent)
536
554
  turn.planSequence++;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/kit",
3
- "version": "0.2.1-alpha.1",
3
+ "version": "0.2.1-alpha.3",
4
4
  "description": "House Kit connects an Environment to agents.house.",
5
5
  "license": "MIT",
6
6
  "repository": {