@farmslot/agent-runtime 0.42.0 → 0.43.0

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 (50) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/dist/native/client.d.ts +10 -2
  3. package/dist/native/client.d.ts.map +1 -1
  4. package/dist/native/client.js +54 -2
  5. package/dist/native/client.js.map +1 -1
  6. package/dist/native/conversation-ipc.d.ts +12 -0
  7. package/dist/native/conversation-ipc.d.ts.map +1 -0
  8. package/dist/native/conversation-ipc.js +126 -0
  9. package/dist/native/conversation-ipc.js.map +1 -0
  10. package/dist/native/conversation.d.ts +52 -0
  11. package/dist/native/conversation.d.ts.map +1 -0
  12. package/dist/native/conversation.js +313 -0
  13. package/dist/native/conversation.js.map +1 -0
  14. package/dist/native/host.js +48 -1
  15. package/dist/native/host.js.map +1 -1
  16. package/dist/native/ipc.d.ts +20 -1
  17. package/dist/native/ipc.d.ts.map +1 -1
  18. package/dist/native/ipc.js +42 -1
  19. package/dist/native/ipc.js.map +1 -1
  20. package/dist/native/manager.d.ts +12 -2
  21. package/dist/native/manager.d.ts.map +1 -1
  22. package/dist/native/manager.js +175 -3
  23. package/dist/native/manager.js.map +1 -1
  24. package/dist/native/msp-stream.d.ts +14 -0
  25. package/dist/native/msp-stream.d.ts.map +1 -0
  26. package/dist/native/msp-stream.js +65 -0
  27. package/dist/native/msp-stream.js.map +1 -0
  28. package/dist/native/observation.d.ts +1 -2
  29. package/dist/native/observation.d.ts.map +1 -1
  30. package/dist/native/observation.js +18 -61
  31. package/dist/native/observation.js.map +1 -1
  32. package/dist/native/service.d.ts +1 -1
  33. package/dist/native/service.d.ts.map +1 -1
  34. package/dist/native/service.js +2 -1
  35. package/dist/native/service.js.map +1 -1
  36. package/dist/native/supervisor.js +1 -0
  37. package/dist/native/supervisor.js.map +1 -1
  38. package/dist/native/worker-history.d.ts +2 -2
  39. package/dist/native/worker-history.d.ts.map +1 -1
  40. package/dist/native/worker-history.js +30 -19
  41. package/dist/native/worker-history.js.map +1 -1
  42. package/dist/native/worker-service.d.ts +1 -1
  43. package/dist/native/worker-service.d.ts.map +1 -1
  44. package/dist/native/worker-service.js +2 -1
  45. package/dist/native/worker-service.js.map +1 -1
  46. package/dist/version.d.ts +3 -0
  47. package/dist/version.d.ts.map +1 -0
  48. package/dist/version.js +10 -0
  49. package/dist/version.js.map +1 -0
  50. package/package.json +7 -2
@@ -1,4 +1,5 @@
1
- import { type NativeApprovalMode, type NativeCommandReceipt, type NativeSessionCreateParams, type NativeSessionEnsureParams, type NativeSessionEvent, type NativeSessionInfo, type NativeSessionRequester, type NativeSessionResponse, type NativeSessionSendResult } from '@farmslot/protocol';
1
+ import { type NativeApprovalMode, type NativeCommandObservation, type NativeCommandReceipt, type NativeSessionCreateParams, type NativeSessionEnsureParams, type NativeSessionEvent, type NativeSessionInfo, type NativeSessionRequester, type NativeSessionResponse, type NativeSessionSendResult } from '@farmslot/protocol';
2
+ import { NativeConversationJournal } from './conversation.js';
2
3
  import { type NativeWorkerCancelResult, type NativeWorkerLaunch, type NativeWorkerResumeParams } from './worker-launch.js';
3
4
  export declare function resolveNativeExecutable(binary: string, cwd: string, environment?: NodeJS.ProcessEnv): Promise<{
4
5
  executable: string;
@@ -9,6 +10,7 @@ export declare class NativeSessionManager {
9
10
  private readonly root;
10
11
  private readonly executionNodeId;
11
12
  private sessions;
13
+ private readonly conversationGeneration;
12
14
  private readonly processObservations;
13
15
  /** Responses being delivered, by request ID. A resolution outside delivery has no known decision. */
14
16
  private readonly delivering;
@@ -34,7 +36,12 @@ export declare class NativeSessionManager {
34
36
  cancelWorker(owner: string, id: string, leaseId: string, generation?: string, sourceLeaseId?: string, resumeCommandId?: string): Promise<NativeWorkerCancelResult>;
35
37
  transferWorker(owner: string, id: string, generation: string, leaseId: string, launch: NativeWorkerLaunch): NativeSessionInfo;
36
38
  private append;
39
+ private sessionRecord;
37
40
  private owned;
41
+ inspect(owner: string, id: string): NativeSessionInfo;
42
+ commandStatus(owner: string, id: string, commandId: string): NativeCommandObservation;
43
+ /** Command acceptance observes receipt metadata, never a transcript read or a retry. */
44
+ waitCommandStatus(owner: string, id: string, commandId: string, signal: AbortSignal): Promise<NativeCommandObservation>;
38
45
  private reconcileMissingProcess;
39
46
  private snapshot;
40
47
  list(owner: string): NativeSessionInfo[];
@@ -57,7 +64,7 @@ export declare class NativeSessionManager {
57
64
  }[];
58
65
  pendingRequests: NativeSessionEvent[];
59
66
  };
60
- readWorker(owner: string, id: string, leaseId: string, after?: number, limit?: number): {
67
+ readWorker(owner: string, id: string, leaseId: string, after?: number, limit?: number, generation?: string): {
61
68
  session: NativeSessionInfo;
62
69
  events: NativeSessionEvent[];
63
70
  cursor: number;
@@ -67,6 +74,9 @@ export declare class NativeSessionManager {
67
74
  scope?: import("@farmslot/protocol").NativeWorkerHistoryScope;
68
75
  };
69
76
  setApprovalMode(owner: string, id: string, mode: NativeApprovalMode): Promise<NativeSessionInfo>;
77
+ private updateConversation;
78
+ /** Observation is passive: it neither creates nor resumes the runner. */
79
+ conversation(owner: string, id: string, leaseId?: string, generation?: string): NativeConversationJournal;
70
80
  private assertAccountCurrent;
71
81
  send(owner: string, id: string, commandId: string, text: string): Promise<NativeSessionSendResult>;
72
82
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/native/manager.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EAEzB,KAAK,yBAAyB,EAC9B,KAAK,yBAAyB,EAC9B,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAG7B,MAAM,oBAAoB,CAAC;AA2B5B,OAAO,EACL,KAAK,wBAAwB,EAE7B,KAAK,kBAAkB,EAGvB,KAAK,wBAAwB,EAE9B,MAAM,oBAAoB,CAAC;AAuC5B,wBAAsB,u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,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,uBAAuB,CAAC;IAmDnC;;;;;OAKG;IACG,KAAK,CACT,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,uBAAuB,CAAC;YAqDrB,aAAa;IAkC3B;;;OAGG;IACH,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,oBAAoB;IA+BjF,OAAO,CAAC,mBAAmB;IAgDrB,OAAO,CACX,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,qBAAqB,GAC9B,OAAO,CAAC,IAAI,CAAC;IA0BV,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMnD,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiDrD;;;OAGG;IACH,OAAO,CAAC,aAAa;IAarB,OAAO,CAAC,mBAAmB;IAI3B,gGAAgG;YAClF,iBAAiB;IAe/B;;;OAGG;YACW,gBAAgB;IA6B9B,gFAAgF;IAChF,OAAO,CAAC,eAAe;IAiCvB,4FAA4F;YAC9E,eAAe;CAY9B"}
@@ -8,6 +8,7 @@ import { promisify } from 'node:util';
8
8
  import { nativeStructuredResult, } from '@farmslot/protocol';
9
9
  import { assertNativeProfileCurrent, nativeProfileEnvironment, requireNativeProfile, } from './account-profiles.js';
10
10
  import { NATIVE_CHECKPOINT_WAIT_MS, NativeCheckpoints, withinMs } from './checkpoint.js';
11
+ import { NativeConversationJournal, splitNativeText } from './conversation.js';
11
12
  import { effectiveModelQuestions } from './model-questions.js';
12
13
  import { NativeRequestRefused } from './process.js';
13
14
  import { journalProcesses } from './process-tree.js';
@@ -146,6 +147,7 @@ export class NativeSessionManager {
146
147
  this.root = root;
147
148
  this.executionNodeId = executionNodeId;
148
149
  this.sessions = new Map();
150
+ this.conversationGeneration = randomUUID();
149
151
  this.processObservations = new Map();
150
152
  /** Responses being delivered, by request ID. A resolution outside delivery has no known decision. */
151
153
  this.delivering = new Map();
@@ -164,6 +166,7 @@ export class NativeSessionManager {
164
166
  const commands = new Map();
165
167
  const events = [];
166
168
  const workerHistory = new NativeWorkerHistory();
169
+ const conversations = new Map();
167
170
  for (const entry of entries) {
168
171
  workerHistory.observe(entry);
169
172
  info = entry.info ?? info;
@@ -173,6 +176,15 @@ export class NativeSessionManager {
173
176
  commands.set(command.commandId, command);
174
177
  if (entry.event)
175
178
  events.push(entry.event);
179
+ if (info)
180
+ this.updateConversation({
181
+ info,
182
+ events,
183
+ commands,
184
+ pendingRequests: new Map(pending.map((event) => [event.request.id, event])),
185
+ workerHistory,
186
+ conversations,
187
+ }, entry.event, Boolean(entry.info || entry.commands || entry.pending));
176
188
  }
177
189
  if (!info || !context)
178
190
  throw new Error('Native journal has no durable session identity');
@@ -180,6 +192,7 @@ export class NativeSessionManager {
180
192
  throw new Error('Native journal belongs to another execution node');
181
193
  const record = {
182
194
  workerHistory,
195
+ conversations,
183
196
  info,
184
197
  context,
185
198
  processes,
@@ -210,6 +223,7 @@ export class NativeSessionManager {
210
223
  });
211
224
  }
212
225
  }
226
+ durableWrite(join(this.root, 'metadata.json'), { revision: randomUUID() });
213
227
  }
214
228
  persist(record, event) {
215
229
  const previous = this.persisted.get(record) ?? { commands: new Map() };
@@ -254,6 +268,9 @@ export class NativeSessionManager {
254
268
  previous.commands.set(command.commandId, JSON.stringify(command));
255
269
  this.persisted.set(record, { info, context, pending, processes, commands: previous.commands });
256
270
  record.workerHistory.observe(entry);
271
+ if (entry.info || entry.commands || entry.pending)
272
+ durableWrite(join(this.root, 'metadata.json'), { revision: randomUUID() });
273
+ this.updateConversation(record, event, Boolean(entry.info || entry.commands || entry.pending));
257
274
  }
258
275
  create(owner, params, workerLaunch, requester) {
259
276
  return this.start(owner, params, undefined, workerLaunch, undefined, undefined, requester);
@@ -479,6 +496,7 @@ export class NativeSessionManager {
479
496
  };
480
497
  const record = {
481
498
  workerHistory: previous?.workerHistory ?? new NativeWorkerHistory(),
499
+ conversations: previous?.conversations ?? new Map(),
482
500
  info,
483
501
  events: previous?.events ?? [],
484
502
  commands: previous?.commands ?? new Map(),
@@ -856,6 +874,13 @@ export class NativeSessionManager {
856
874
  return this.snapshot(record);
857
875
  }
858
876
  append(record, event) {
877
+ if (event.type === 'text.delta' &&
878
+ event.text &&
879
+ Buffer.byteLength(JSON.stringify(event.text)) > 60 * 1024) {
880
+ for (const text of splitNativeText(event.text))
881
+ this.append(record, { ...event, text });
882
+ return;
883
+ }
859
884
  event = compactEventDiagnostics(event);
860
885
  const structuredResult = event.type === 'turn.completed' &&
861
886
  event.status === 'completed' &&
@@ -962,15 +987,69 @@ export class NativeSessionManager {
962
987
  this.scheduleQueuedInput(record);
963
988
  }
964
989
  }
965
- owned(owner, id, observations) {
990
+ sessionRecord(owner, id) {
966
991
  const record = this.sessions.get(id);
967
992
  if (!record || record.info.ownerPrincipalId !== owner)
968
993
  throw Object.assign(new Error('Native session not found for this principal'), {
969
994
  code: 'NOT_FOUND',
970
995
  });
996
+ return record;
997
+ }
998
+ owned(owner, id, observations) {
999
+ const record = this.sessionRecord(owner, id);
971
1000
  this.reconcileMissingProcess(record, observations);
972
1001
  return record;
973
1002
  }
1003
+ inspect(owner, id) {
1004
+ return this.snapshot(this.sessionRecord(owner, id));
1005
+ }
1006
+ commandStatus(owner, id, commandId) {
1007
+ const record = this.sessionRecord(owner, id);
1008
+ const command = record.commands.get(commandId);
1009
+ if (!command)
1010
+ return { session: this.snapshot(record) };
1011
+ const { text: _text, leaseId: _lease, ...receipt } = command;
1012
+ return { session: this.snapshot(record), receipt: structuredClone(receipt) };
1013
+ }
1014
+ /** Command acceptance observes receipt metadata, never a transcript read or a retry. */
1015
+ waitCommandStatus(owner, id, commandId, signal) {
1016
+ const journal = this.conversation(owner, id);
1017
+ return new Promise((resolve, reject) => {
1018
+ let stopped = false;
1019
+ let timer;
1020
+ let unlisten = () => { };
1021
+ const cleanup = () => {
1022
+ stopped = true;
1023
+ unlisten();
1024
+ if (timer)
1025
+ clearTimeout(timer);
1026
+ signal.removeEventListener('abort', abort);
1027
+ };
1028
+ const abort = () => {
1029
+ cleanup();
1030
+ reject(new Error('Native command observation connection closed'));
1031
+ };
1032
+ const sample = (deadline = false) => {
1033
+ if (stopped)
1034
+ return;
1035
+ const observed = this.commandStatus(owner, id, commandId);
1036
+ if (deadline ||
1037
+ observed.receipt?.accepted ||
1038
+ ['failed', 'unknown'].includes(observed.receipt?.state ?? '') ||
1039
+ ['closed', 'failed'].includes(observed.session.state)) {
1040
+ cleanup();
1041
+ resolve(observed);
1042
+ }
1043
+ };
1044
+ unlisten = journal.listen(() => sample());
1045
+ signal.addEventListener('abort', abort, { once: true });
1046
+ timer = setTimeout(() => sample(true), 30_000);
1047
+ if (signal.aborted)
1048
+ abort();
1049
+ else
1050
+ sample();
1051
+ });
1052
+ }
974
1053
  reconcileMissingProcess(record, observations) {
975
1054
  const pid = record.info.processPid;
976
1055
  // A live adapter owns descendant cleanup. A recovered journal has no
@@ -1054,11 +1133,11 @@ export class NativeSessionManager {
1054
1133
  pendingRequests: [...record.pendingRequests.values()],
1055
1134
  };
1056
1135
  }
1057
- readWorker(owner, id, leaseId, after, limit) {
1136
+ readWorker(owner, id, leaseId, after, limit, generation) {
1058
1137
  const record = this.owned(owner, id, this.processObservations);
1059
1138
  if (record.workerLeaseError)
1060
1139
  throw record.workerLeaseError;
1061
- const result = record.workerHistory.read(leaseId, record.events, [...record.pendingRequests.values()], after, limit);
1140
+ const result = record.workerHistory.read(leaseId, record.events, [...record.pendingRequests.values()], after, limit, generation);
1062
1141
  return { ...result, session: this.snapshot({ info: result.session }) };
1063
1142
  }
1064
1143
  async setApprovalMode(owner, id, mode) {
@@ -1090,6 +1169,99 @@ export class NativeSessionManager {
1090
1169
  record.configuring = false;
1091
1170
  }
1092
1171
  }
1172
+ updateConversation(record, event, metadataChanged = true) {
1173
+ if (!event && !metadataChanged)
1174
+ return;
1175
+ const lease = record.info.workerLeaseId ?? '';
1176
+ const key = lease ? JSON.stringify([lease, record.info.generation]) : '';
1177
+ if (!record.conversations.has(key))
1178
+ record.conversations.set(key, new NativeConversationJournal(this.conversationGeneration));
1179
+ for (const [identity, journal] of record.conversations) {
1180
+ const previous = journal.metadata;
1181
+ if (identity !== key) {
1182
+ if (!journal.listenerCount) {
1183
+ record.conversations.delete(identity);
1184
+ continue;
1185
+ }
1186
+ // A resumed process can keep its lease. Freeze its predecessor before publishing
1187
+ // successor events, just as a released task lease freezes its journal window.
1188
+ if (previous && !journal.released)
1189
+ journal.commit({
1190
+ ...previous,
1191
+ events: [],
1192
+ pendingRequests: [],
1193
+ ...(previous.scope ? { scope: { ...previous.scope, released: true } } : {}),
1194
+ });
1195
+ continue;
1196
+ }
1197
+ if (event && !metadataChanged && previous) {
1198
+ journal.commit({
1199
+ ...previous,
1200
+ events: [event],
1201
+ cursor: event.sequence,
1202
+ ...(previous.scope ? { scope: { ...previous.scope, endAt: event.sequence } } : {}),
1203
+ });
1204
+ continue;
1205
+ }
1206
+ const page = lease
1207
+ ? record.workerHistory.read(lease, record.events, [...record.pendingRequests.values()], journal.sequence || undefined, 1)
1208
+ : {
1209
+ session: this.snapshot(record),
1210
+ events: [],
1211
+ cursor: record.events.length,
1212
+ hasMore: false,
1213
+ commands: [...record.commands.values()]
1214
+ .slice(-100)
1215
+ .map(({ text: _text, leaseId: _lease, ...receipt }) => receipt),
1216
+ pendingRequests: [...record.pendingRequests.values()],
1217
+ };
1218
+ page.session = this.snapshot({ info: page.session });
1219
+ page.events =
1220
+ event &&
1221
+ event.sequence > (page.scope?.startAfter ?? 0) &&
1222
+ event.sequence <= (page.scope?.endAt ?? page.cursor)
1223
+ ? [event]
1224
+ : [];
1225
+ page.cursor = page.scope?.endAt ?? record.events.length;
1226
+ page.hasMore = false;
1227
+ journal.commit(page);
1228
+ }
1229
+ }
1230
+ /** Observation is passive: it neither creates nor resumes the runner. */
1231
+ conversation(owner, id, leaseId, generation) {
1232
+ const record = this.sessionRecord(owner, id);
1233
+ if (Boolean(record.info.workerManaged) !== Boolean(leaseId) ||
1234
+ Boolean(leaseId) !== Boolean(generation))
1235
+ throw new Error('Worker conversations require their pinned history lease and generation');
1236
+ if (record.workerLeaseError)
1237
+ throw record.workerLeaseError;
1238
+ const key = leaseId ? JSON.stringify([leaseId, generation]) : '';
1239
+ let journal = record.conversations.get(key);
1240
+ if (!journal && leaseId && generation) {
1241
+ const metadata = record.workerHistory.read(leaseId, record.events, [], undefined, 1, generation);
1242
+ const end = metadata.scope.endAt;
1243
+ let start = end, bytes = 0;
1244
+ while (start > metadata.scope.startAfter && end - start < 128) {
1245
+ const size = Buffer.byteLength(JSON.stringify(record.events[start - 1]));
1246
+ if (bytes + size > 512 * 1024)
1247
+ break;
1248
+ bytes += size;
1249
+ start--;
1250
+ }
1251
+ const page = record.workerHistory.read(leaseId, record.events, [...record.pendingRequests.values()], start, 128, generation);
1252
+ journal = new NativeConversationJournal(this.conversationGeneration);
1253
+ journal.reset({
1254
+ ...page,
1255
+ session: this.snapshot({ info: page.session }),
1256
+ historyBefore: start,
1257
+ truncated: start > metadata.scope.startAfter,
1258
+ });
1259
+ record.conversations.set(key, journal);
1260
+ }
1261
+ if (!journal)
1262
+ throw new Error('Native conversation history generation is unknown');
1263
+ return journal;
1264
+ }
1093
1265
  assertAccountCurrent(record) {
1094
1266
  if (record.info.approvalModePending)
1095
1267
  throw new Error('Approval mode is unconfirmed; set it again before sending input');