@theoremjs/agents 0.3.5-next.938.g3cbd0dd → 0.3.5-next.940.g78c83ac

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.
@@ -12,7 +12,7 @@ export interface RunConversationOptions<Item extends InboxItem> {
12
12
  inbox: ConversationInbox<Item>;
13
13
  policy: InboxPolicy<Item>;
14
14
  start: ReplyStart;
15
- /** Makes the ids of holds and replies. */
15
+ /** Makes the ids of replies, and of holds the start does not name. */
16
16
  newId: () => string;
17
17
  /** How often the hold renews its lease while the reply runs, in milliseconds. */
18
18
  renewEveryMs: number;
@@ -8,7 +8,7 @@
8
8
  /** Runs one reply under a hold of the conversation. See {@link ConversationRun}. */
9
9
  export async function runConversation(options) {
10
10
  const { conversation, inbox, start } = options;
11
- const hold = start.opening === 'follow_up' ? start.hold : options.newId();
11
+ const hold = start.hold ?? options.newId();
12
12
  // why: A follow-up's hold is checked where it acts: handing, giving up, and before `continue`.
13
13
  if (start.opening === 'message' && start.takeOver) {
14
14
  await inbox.takeOver(conversation, hold);
@@ -117,6 +117,28 @@ export function conversationScenarios(options) {
117
117
  fail('a wake with nothing waiting ran a reply');
118
118
  expectOutcome(await s.run({ opening: 'message' }), 'released', 'the next message');
119
119
  }),
120
+ scenario('a message under the hold the app already took runs, and lets go', async (s) => {
121
+ await s.h.arrive('r');
122
+ const opened = await s.h.inbox.open(s.h.conversation, 'app-hold');
123
+ if (opened.outcome !== 'opened')
124
+ fail('the app did not take the conversation');
125
+ const ran = await s.run({ opening: 'message', hold: 'app-hold' });
126
+ expectOutcome(ran, 'released', 'the message');
127
+ await s.expectTold(['r']);
128
+ }),
129
+ scenario('a message under a hold the app does not have is held', async (s) => {
130
+ const opened = await s.h.inbox.open(s.h.conversation, 'other-hold');
131
+ if (opened.outcome !== 'opened')
132
+ fail('the other hold did not take the conversation');
133
+ let replied = false;
134
+ const ran = await s.run({ opening: 'message', hold: 'app-hold' }, () => {
135
+ replied = true;
136
+ return Promise.resolve();
137
+ });
138
+ expectOutcome(ran, 'held', 'the message');
139
+ if (replied)
140
+ fail('a message under a hold it does not have ran a reply');
141
+ }),
120
142
  scenario('an item that arrives during a step is read at the next moment', async (s) => {
121
143
  const ran = await s.run({ opening: 'message' }, async (reply) => {
122
144
  await s.h.arrive('b');
@@ -98,15 +98,21 @@ export interface ConversationInbox<Item extends InboxItem = InboxItem> {
98
98
  release(conversation: string, hold: string, version: string): Promise<'released' | 'moved' | 'lost'>;
99
99
  }
100
100
  /**
101
- * What opens a reply. A `message` or a `wake` opens the conversation under a new hold; a message
102
- * with `takeOver` takes it from any hold that has it. A `follow_up` runs under the hold a run
103
- * before it returned with `continue`.
101
+ * What opens a reply. A `message` or a `wake` opens the conversation under a new hold, or under
102
+ * `hold` when the app names it; a message with `takeOver` takes it from any hold that has it. A
103
+ * `follow_up` runs under the hold a run before it returned with `continue`.
104
+ *
105
+ * @remarks Name the `hold` when the app takes the conversation itself, such as in the write that
106
+ * saves the person's message. `open` with the hold that has the conversation keeps it, so the run
107
+ * goes on under that hold.
104
108
  */
105
109
  export type ReplyStart = {
106
110
  opening: 'message';
107
111
  takeOver?: boolean;
112
+ hold?: string;
108
113
  } | {
109
114
  opening: 'wake';
115
+ hold?: string;
110
116
  } | {
111
117
  opening: 'follow_up';
112
118
  hold: string;
@@ -70,7 +70,7 @@ export interface ProfileImageSpec {
70
70
  */
71
71
  includeText?: boolean;
72
72
  }
73
- import type { InboxItem, InboxPolicy } from '../conversation/types.js';
73
+ import type { InboxItem, PolicyChoice, PolicyMoment } from '../conversation/types.js';
74
74
  import type { DecisionModelBinding, ModelBinding } from './protocols/binding.js';
75
75
  import type { ProviderHostOptions } from './protocols/runtime.js';
76
76
  export type { DecisionModelBinding, ModelBinding };
@@ -1278,6 +1278,11 @@ export interface LateResult {
1278
1278
  export interface LateResultItem extends InboxItem<'late_result'> {
1279
1279
  outcome: ToolOperationOutcome;
1280
1280
  }
1281
+ /** A moment the decider's policy is asked at, and whose chat it is. */
1282
+ export interface LateResultsPolicyMoment extends PolicyMoment {
1283
+ /** The `host` of the request the reply runs for, as `ended` gets it: whose chat it is. */
1284
+ host: unknown;
1285
+ }
1281
1286
  /** A background call ended, and what Theorem lets the decider do about it. */
1282
1287
  export interface LateResultEnded {
1283
1288
  /** The `host` of the request that started the call. */
@@ -1306,7 +1311,7 @@ export interface LateResultsDecider {
1306
1311
  * (`opening: 'wake'`, to say whether the page wakes it). It must change nothing. A result it
1307
1312
  * leaves waits for a later reply; one it gives up is reported once to `onError`.
1308
1313
  */
1309
- policy: InboxPolicy<LateResultItem>;
1314
+ policy(items: readonly LateResultItem[], moment: LateResultsPolicyMoment): PolicyChoice | Promise<PolicyChoice>;
1310
1315
  /** A background call ended. Use `wake` to reply from the server, with no page open. */
1311
1316
  ended?(ended: LateResultEnded): void | Promise<void>;
1312
1317
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theoremjs/agents",
3
- "version": "0.3.5-next.938.g3cbd0dd",
3
+ "version": "0.3.5-next.940.g78c83ac",
4
4
  "description": "A flat TypeScript agent kernel for typed profiles, deterministic turn execution, registered tools, provider adapters, guardrails, and host-injected traces.",
5
5
  "keywords": [
6
6
  "agent",