@swirls/looms 0.11.1 → 0.11.2

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @swirls/looms
2
2
 
3
+ ## 0.11.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 58c214c: Rerun a conversational agent turn when a steer or user message arrives while the LLM call is in flight, so the late message is not lost after a final reply.
8
+
3
9
  ## 0.11.1
4
10
 
5
11
  ### Patch Changes
@@ -21,6 +21,8 @@ export function summarizeAgentEvent(event) {
21
21
  return { title: 'user message', detail: messageContent(event.payload) };
22
22
  case 'agent.turn.started':
23
23
  return { title: 'turn started', detail: `turn ${jsonNumberText(payload.turn) ?? ''}` };
24
+ case 'agent.turn.settled':
25
+ return { title: 'turn settled', detail: `turn ${jsonNumberText(payload.turn) ?? ''}` };
24
26
  case 'agent.turn.text_delta':
25
27
  return { title: 'text delta', detail: jsonText(payload.delta) };
26
28
  case 'agent.message':
@@ -23,6 +23,254 @@ export declare const callLlmEffect: NoInfer<import("@swirls/looms/core").LocalEf
23
23
  readonly alreadyCompacted?: boolean | undefined;
24
24
  readonly consumedSteerMessageIds?: readonly string[] | undefined;
25
25
  }, AgentDefinitionsTag | LlmTag, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
26
+ readonly type: "agent.context.compacted";
27
+ readonly payload: {
28
+ readonly turn: number;
29
+ readonly originalCount: number;
30
+ readonly compactedCount: number;
31
+ readonly summary?: string | undefined;
32
+ readonly reason?: "manual" | "overflow" | "threshold" | undefined;
33
+ readonly messages?: readonly {
34
+ readonly role: "assistant" | "system" | "tool" | "user";
35
+ readonly content: string;
36
+ readonly toolCallId?: string | undefined;
37
+ readonly name?: string | undefined;
38
+ readonly toolCalls?: {
39
+ readonly id: string;
40
+ readonly name: string;
41
+ readonly arguments: Schema.Json;
42
+ }[] | undefined;
43
+ }[] | undefined;
44
+ };
45
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
46
+ readonly type: "agent.effects.requested";
47
+ readonly payload: {
48
+ readonly toolCallId: string;
49
+ readonly effects: readonly ({
50
+ readonly type: "runtime.spawn";
51
+ readonly childThreadId: string;
52
+ readonly kind: string;
53
+ readonly definitionName: string;
54
+ readonly definitionVersion: string;
55
+ readonly input: Schema.Json;
56
+ } | {
57
+ readonly type: "runtime.wait";
58
+ readonly waitId: string;
59
+ readonly on: {
60
+ readonly type: string | readonly string[];
61
+ readonly match?: Schema.Json | undefined;
62
+ } | {
63
+ readonly timerAt: number;
64
+ };
65
+ readonly tag?: Schema.Json | undefined;
66
+ } | {
67
+ readonly type: "runtime.emit";
68
+ readonly event: {
69
+ readonly type: string;
70
+ readonly payload: Schema.Json;
71
+ readonly threadId?: string | null | undefined;
72
+ readonly parentThreadId?: string | null | undefined;
73
+ readonly causationId?: string | null | undefined;
74
+ readonly correlationId?: string | null | undefined;
75
+ readonly effectId?: string | null | undefined;
76
+ readonly origin?: {
77
+ readonly type: "thread";
78
+ readonly threadId: string;
79
+ } | {
80
+ readonly type: "external";
81
+ readonly actorId?: string | undefined;
82
+ } | {
83
+ readonly type: "system";
84
+ } | {
85
+ readonly type: "run";
86
+ readonly runId: string;
87
+ } | undefined;
88
+ readonly ephemeral?: boolean | undefined;
89
+ readonly id?: string | undefined;
90
+ readonly ts?: number | undefined;
91
+ readonly idempotencyKey?: string | null | undefined;
92
+ };
93
+ readonly tag?: string | undefined;
94
+ } | {
95
+ readonly type: "runtime.complete";
96
+ readonly output: Schema.Json;
97
+ } | {
98
+ readonly type: "runtime.fail";
99
+ readonly error: string;
100
+ } | {
101
+ readonly type: "runtime.cancel";
102
+ readonly threadId: string;
103
+ readonly tag?: string | undefined;
104
+ } | {
105
+ readonly type: "runtime.launch";
106
+ readonly runId: string;
107
+ readonly kind: string;
108
+ readonly definitionName: string;
109
+ readonly definitionVersion: string;
110
+ readonly input: Schema.Json;
111
+ readonly close: "terminate" | "wait";
112
+ readonly tag?: string | undefined;
113
+ } | {
114
+ readonly type: "runtime.cancelRun";
115
+ readonly runId: string;
116
+ readonly tag?: string | undefined;
117
+ } | {
118
+ readonly type: string;
119
+ readonly input: Schema.Json;
120
+ readonly tag?: string | undefined;
121
+ readonly at?: number | undefined;
122
+ })[];
123
+ readonly waitOn?: {
124
+ readonly type: string | readonly string[];
125
+ readonly match?: Schema.Json | undefined;
126
+ } | undefined;
127
+ };
128
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
129
+ readonly type: "agent.lineage";
130
+ readonly payload: {
131
+ readonly depth: number;
132
+ };
133
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
134
+ readonly type: "agent.message";
135
+ readonly payload: {
136
+ readonly turn: number;
137
+ readonly message: {
138
+ readonly role: "assistant" | "system" | "tool" | "user";
139
+ readonly content: string;
140
+ readonly toolCallId?: string | undefined;
141
+ readonly name?: string | undefined;
142
+ readonly toolCalls?: {
143
+ readonly id: string;
144
+ readonly name: string;
145
+ readonly arguments: Schema.Json;
146
+ }[] | undefined;
147
+ };
148
+ readonly usage?: {
149
+ readonly input: number;
150
+ readonly output: number;
151
+ } | undefined;
152
+ };
153
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
154
+ readonly type: "agent.message.received";
155
+ readonly payload: {
156
+ readonly message: {
157
+ readonly role: "assistant" | "system" | "tool" | "user";
158
+ readonly content: string;
159
+ readonly toolCallId?: string | undefined;
160
+ readonly name?: string | undefined;
161
+ readonly toolCalls?: {
162
+ readonly id: string;
163
+ readonly name: string;
164
+ readonly arguments: Schema.Json;
165
+ }[] | undefined;
166
+ };
167
+ };
168
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
169
+ readonly type: "agent.session.cancel.requested";
170
+ readonly payload: {};
171
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
172
+ readonly type: "agent.session.message.submitted";
173
+ readonly payload: {
174
+ readonly messageId: string;
175
+ readonly text: string;
176
+ readonly delivery?: "followUp" | "nextTurn" | "steer" | undefined;
177
+ readonly activeChildThreadId?: string | undefined;
178
+ };
179
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
180
+ readonly type: "agent.session.steer.delivered";
181
+ readonly payload: {
182
+ readonly messageId: string;
183
+ readonly activeMessageId: string;
184
+ };
185
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
186
+ readonly type: "agent.session.turn.closed";
187
+ readonly payload: {
188
+ readonly messageId: string;
189
+ readonly status: "cancelled" | "completed" | "failed";
190
+ readonly error?: string | undefined;
191
+ };
192
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
193
+ readonly type: "agent.session.turn.started";
194
+ readonly payload: {
195
+ readonly messageId: string;
196
+ readonly childThreadId: string;
197
+ };
198
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
199
+ readonly type: "agent.spawn.requested";
200
+ readonly payload: {
201
+ readonly childThreadId: string;
202
+ readonly kind: string;
203
+ readonly definitionName: string;
204
+ readonly definitionVersion: string;
205
+ readonly toolCallId: string;
206
+ readonly input: Schema.Json;
207
+ readonly depth?: number | undefined;
208
+ };
209
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
210
+ readonly type: "agent.steered";
211
+ readonly payload: {
212
+ readonly turn: number;
213
+ readonly messageId?: string | undefined;
214
+ readonly message: {
215
+ readonly role: "assistant" | "system" | "tool" | "user";
216
+ readonly content: string;
217
+ readonly toolCallId?: string | undefined;
218
+ readonly name?: string | undefined;
219
+ readonly toolCalls?: {
220
+ readonly id: string;
221
+ readonly name: string;
222
+ readonly arguments: Schema.Json;
223
+ }[] | undefined;
224
+ };
225
+ readonly interrupt?: boolean | undefined;
226
+ };
227
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
228
+ readonly type: "agent.tool.result";
229
+ readonly payload: {
230
+ readonly turn: number;
231
+ readonly toolCallId: string;
232
+ readonly name: string;
233
+ readonly result: Schema.Json;
234
+ readonly error: string | null;
235
+ };
236
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
237
+ readonly type: "agent.tool_call.requested";
238
+ readonly payload: {
239
+ readonly turn: number;
240
+ readonly toolCall: {
241
+ readonly id: string;
242
+ readonly name: string;
243
+ readonly arguments: Schema.Json;
244
+ };
245
+ };
246
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
247
+ readonly type: "agent.turn.settled";
248
+ readonly payload: {
249
+ readonly turn: number;
250
+ };
251
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
252
+ readonly type: "agent.turn.started";
253
+ readonly payload: {
254
+ readonly turn: number;
255
+ readonly messageCount?: number | undefined;
256
+ };
257
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
258
+ readonly type: "agent.turn.stopped";
259
+ readonly payload: {};
260
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
261
+ readonly type: "agent.turn.text_delta";
262
+ readonly payload: {
263
+ readonly turn: number;
264
+ readonly delta: string;
265
+ };
266
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
267
+ readonly type: "agent.turn.usage";
268
+ readonly payload: {
269
+ readonly turn: number;
270
+ readonly input: number;
271
+ readonly output: number;
272
+ };
273
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
26
274
  readonly type: "runtime.child.close.requested";
27
275
  readonly payload: {
28
276
  readonly policy: "terminate" | "wait";
@@ -268,7 +516,19 @@ export declare const callLlmEffect: NoInfer<import("@swirls/looms/core").LocalEf
268
516
  readonly payload: Schema.Json;
269
517
  };
270
518
  };
271
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
519
+ })>>;
520
+ export declare const executeToolEffect: NoInfer<import("@swirls/looms/core").LocalEffectDefinition<{
521
+ readonly turn: number;
522
+ readonly definitionName?: string | undefined;
523
+ readonly definitionVersion: string;
524
+ readonly toolCall: {
525
+ readonly id: string;
526
+ readonly name: string;
527
+ readonly arguments: Schema.Json;
528
+ };
529
+ readonly input?: Schema.Json | undefined;
530
+ readonly depth?: number | undefined;
531
+ }, AgentDefinitionsTag, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
272
532
  readonly type: "agent.context.compacted";
273
533
  readonly payload: {
274
534
  readonly turn: number;
@@ -489,10 +749,16 @@ export declare const callLlmEffect: NoInfer<import("@swirls/looms/core").LocalEf
489
749
  readonly arguments: Schema.Json;
490
750
  };
491
751
  };
752
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
753
+ readonly type: "agent.turn.settled";
754
+ readonly payload: {
755
+ readonly turn: number;
756
+ };
492
757
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
493
758
  readonly type: "agent.turn.started";
494
759
  readonly payload: {
495
760
  readonly turn: number;
761
+ readonly messageCount?: number | undefined;
496
762
  };
497
763
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
498
764
  readonly type: "agent.turn.stopped";
@@ -510,19 +776,7 @@ export declare const callLlmEffect: NoInfer<import("@swirls/looms/core").LocalEf
510
776
  readonly input: number;
511
777
  readonly output: number;
512
778
  };
513
- })>>;
514
- export declare const executeToolEffect: NoInfer<import("@swirls/looms/core").LocalEffectDefinition<{
515
- readonly turn: number;
516
- readonly definitionName?: string | undefined;
517
- readonly definitionVersion: string;
518
- readonly toolCall: {
519
- readonly id: string;
520
- readonly name: string;
521
- readonly arguments: Schema.Json;
522
- };
523
- readonly input?: Schema.Json | undefined;
524
- readonly depth?: number | undefined;
525
- }, AgentDefinitionsTag, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
779
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
526
780
  readonly type: "runtime.child.close.requested";
527
781
  readonly payload: {
528
782
  readonly policy: "terminate" | "wait";
@@ -768,247 +1022,5 @@ export declare const executeToolEffect: NoInfer<import("@swirls/looms/core").Loc
768
1022
  readonly payload: Schema.Json;
769
1023
  };
770
1024
  };
771
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
772
- readonly type: "agent.context.compacted";
773
- readonly payload: {
774
- readonly turn: number;
775
- readonly originalCount: number;
776
- readonly compactedCount: number;
777
- readonly summary?: string | undefined;
778
- readonly reason?: "manual" | "overflow" | "threshold" | undefined;
779
- readonly messages?: readonly {
780
- readonly role: "assistant" | "system" | "tool" | "user";
781
- readonly content: string;
782
- readonly toolCallId?: string | undefined;
783
- readonly name?: string | undefined;
784
- readonly toolCalls?: {
785
- readonly id: string;
786
- readonly name: string;
787
- readonly arguments: Schema.Json;
788
- }[] | undefined;
789
- }[] | undefined;
790
- };
791
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
792
- readonly type: "agent.effects.requested";
793
- readonly payload: {
794
- readonly toolCallId: string;
795
- readonly effects: readonly ({
796
- readonly type: "runtime.spawn";
797
- readonly childThreadId: string;
798
- readonly kind: string;
799
- readonly definitionName: string;
800
- readonly definitionVersion: string;
801
- readonly input: Schema.Json;
802
- } | {
803
- readonly type: "runtime.wait";
804
- readonly waitId: string;
805
- readonly on: {
806
- readonly type: string | readonly string[];
807
- readonly match?: Schema.Json | undefined;
808
- } | {
809
- readonly timerAt: number;
810
- };
811
- readonly tag?: Schema.Json | undefined;
812
- } | {
813
- readonly type: "runtime.emit";
814
- readonly event: {
815
- readonly type: string;
816
- readonly payload: Schema.Json;
817
- readonly threadId?: string | null | undefined;
818
- readonly parentThreadId?: string | null | undefined;
819
- readonly causationId?: string | null | undefined;
820
- readonly correlationId?: string | null | undefined;
821
- readonly effectId?: string | null | undefined;
822
- readonly origin?: {
823
- readonly type: "thread";
824
- readonly threadId: string;
825
- } | {
826
- readonly type: "external";
827
- readonly actorId?: string | undefined;
828
- } | {
829
- readonly type: "system";
830
- } | {
831
- readonly type: "run";
832
- readonly runId: string;
833
- } | undefined;
834
- readonly ephemeral?: boolean | undefined;
835
- readonly id?: string | undefined;
836
- readonly ts?: number | undefined;
837
- readonly idempotencyKey?: string | null | undefined;
838
- };
839
- readonly tag?: string | undefined;
840
- } | {
841
- readonly type: "runtime.complete";
842
- readonly output: Schema.Json;
843
- } | {
844
- readonly type: "runtime.fail";
845
- readonly error: string;
846
- } | {
847
- readonly type: "runtime.cancel";
848
- readonly threadId: string;
849
- readonly tag?: string | undefined;
850
- } | {
851
- readonly type: "runtime.launch";
852
- readonly runId: string;
853
- readonly kind: string;
854
- readonly definitionName: string;
855
- readonly definitionVersion: string;
856
- readonly input: Schema.Json;
857
- readonly close: "terminate" | "wait";
858
- readonly tag?: string | undefined;
859
- } | {
860
- readonly type: "runtime.cancelRun";
861
- readonly runId: string;
862
- readonly tag?: string | undefined;
863
- } | {
864
- readonly type: string;
865
- readonly input: Schema.Json;
866
- readonly tag?: string | undefined;
867
- readonly at?: number | undefined;
868
- })[];
869
- readonly waitOn?: {
870
- readonly type: string | readonly string[];
871
- readonly match?: Schema.Json | undefined;
872
- } | undefined;
873
- };
874
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
875
- readonly type: "agent.lineage";
876
- readonly payload: {
877
- readonly depth: number;
878
- };
879
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
880
- readonly type: "agent.message";
881
- readonly payload: {
882
- readonly turn: number;
883
- readonly message: {
884
- readonly role: "assistant" | "system" | "tool" | "user";
885
- readonly content: string;
886
- readonly toolCallId?: string | undefined;
887
- readonly name?: string | undefined;
888
- readonly toolCalls?: {
889
- readonly id: string;
890
- readonly name: string;
891
- readonly arguments: Schema.Json;
892
- }[] | undefined;
893
- };
894
- readonly usage?: {
895
- readonly input: number;
896
- readonly output: number;
897
- } | undefined;
898
- };
899
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
900
- readonly type: "agent.message.received";
901
- readonly payload: {
902
- readonly message: {
903
- readonly role: "assistant" | "system" | "tool" | "user";
904
- readonly content: string;
905
- readonly toolCallId?: string | undefined;
906
- readonly name?: string | undefined;
907
- readonly toolCalls?: {
908
- readonly id: string;
909
- readonly name: string;
910
- readonly arguments: Schema.Json;
911
- }[] | undefined;
912
- };
913
- };
914
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
915
- readonly type: "agent.session.cancel.requested";
916
- readonly payload: {};
917
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
918
- readonly type: "agent.session.message.submitted";
919
- readonly payload: {
920
- readonly messageId: string;
921
- readonly text: string;
922
- readonly delivery?: "followUp" | "nextTurn" | "steer" | undefined;
923
- readonly activeChildThreadId?: string | undefined;
924
- };
925
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
926
- readonly type: "agent.session.steer.delivered";
927
- readonly payload: {
928
- readonly messageId: string;
929
- readonly activeMessageId: string;
930
- };
931
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
932
- readonly type: "agent.session.turn.closed";
933
- readonly payload: {
934
- readonly messageId: string;
935
- readonly status: "cancelled" | "completed" | "failed";
936
- readonly error?: string | undefined;
937
- };
938
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
939
- readonly type: "agent.session.turn.started";
940
- readonly payload: {
941
- readonly messageId: string;
942
- readonly childThreadId: string;
943
- };
944
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
945
- readonly type: "agent.spawn.requested";
946
- readonly payload: {
947
- readonly childThreadId: string;
948
- readonly kind: string;
949
- readonly definitionName: string;
950
- readonly definitionVersion: string;
951
- readonly toolCallId: string;
952
- readonly input: Schema.Json;
953
- readonly depth?: number | undefined;
954
- };
955
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
956
- readonly type: "agent.steered";
957
- readonly payload: {
958
- readonly turn: number;
959
- readonly messageId?: string | undefined;
960
- readonly message: {
961
- readonly role: "assistant" | "system" | "tool" | "user";
962
- readonly content: string;
963
- readonly toolCallId?: string | undefined;
964
- readonly name?: string | undefined;
965
- readonly toolCalls?: {
966
- readonly id: string;
967
- readonly name: string;
968
- readonly arguments: Schema.Json;
969
- }[] | undefined;
970
- };
971
- readonly interrupt?: boolean | undefined;
972
- };
973
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
974
- readonly type: "agent.tool.result";
975
- readonly payload: {
976
- readonly turn: number;
977
- readonly toolCallId: string;
978
- readonly name: string;
979
- readonly result: Schema.Json;
980
- readonly error: string | null;
981
- };
982
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
983
- readonly type: "agent.tool_call.requested";
984
- readonly payload: {
985
- readonly turn: number;
986
- readonly toolCall: {
987
- readonly id: string;
988
- readonly name: string;
989
- readonly arguments: Schema.Json;
990
- };
991
- };
992
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
993
- readonly type: "agent.turn.started";
994
- readonly payload: {
995
- readonly turn: number;
996
- };
997
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
998
- readonly type: "agent.turn.stopped";
999
- readonly payload: {};
1000
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1001
- readonly type: "agent.turn.text_delta";
1002
- readonly payload: {
1003
- readonly turn: number;
1004
- readonly delta: string;
1005
- };
1006
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1007
- readonly type: "agent.turn.usage";
1008
- readonly payload: {
1009
- readonly turn: number;
1010
- readonly input: number;
1011
- readonly output: number;
1012
- };
1013
1025
  })>>;
1014
1026
  export declare function readToolCall(value: JsonValue): ToolCall | null;
@@ -133,7 +133,7 @@ function runCallLlm(args) {
133
133
  const events = [
134
134
  {
135
135
  type: 'agent.turn.started',
136
- payload: { turn },
136
+ payload: { turn, messageCount: messages.length },
137
137
  threadId,
138
138
  },
139
139
  ];
@@ -227,28 +227,17 @@ function runCallLlm(args) {
227
227
  threadId,
228
228
  });
229
229
  }
230
- if (shouldStop) {
231
- if (!definition.conversational) {
232
- const output = structuredOutput ?? result.output ?? { text: result.message.content };
230
+ if (!shouldStop) {
231
+ for (const toolCall of toolCalls) {
233
232
  events.push({
234
- type: 'runtime.thread.completed',
235
- payload: {
236
- threadId,
237
- output: consumedSteerMessageIds.length === 0 ? output : { output, consumedSteerMessageIds },
238
- },
233
+ type: 'agent.tool_call.requested',
234
+ payload: { turn, toolCall },
239
235
  threadId,
240
236
  });
241
237
  }
242
- return events;
243
- }
244
- for (const toolCall of toolCalls) {
245
- events.push({
246
- type: 'agent.tool_call.requested',
247
- payload: { turn, toolCall },
248
- threadId,
249
- });
250
238
  }
251
- if (toolCalls.length === 0 && !definition.conversational) {
239
+ const completeThread = !definition.conversational && (shouldStop || toolCalls.length === 0);
240
+ if (completeThread) {
252
241
  const output = structuredOutput ?? result.output ?? { text: result.message.content };
253
242
  events.push({
254
243
  type: 'runtime.thread.completed',
@@ -259,6 +248,11 @@ function runCallLlm(args) {
259
248
  threadId,
260
249
  });
261
250
  }
251
+ events.push({
252
+ type: 'agent.turn.settled',
253
+ payload: { turn },
254
+ threadId,
255
+ });
262
256
  return events;
263
257
  });
264
258
  }
@@ -14,6 +14,11 @@ export declare const AgentMessageReceivedPayloadSchema: Schema.Struct<{
14
14
  }>;
15
15
  export declare const AgentTurnStartedPayloadSchema: Schema.Struct<{
16
16
  readonly turn: Schema.Finite;
17
+ /** Snapshot of `lines.length` when the LLM call began. Used to detect mid-call steers. */
18
+ readonly messageCount: Schema.optional<Schema.Finite>;
19
+ }>;
20
+ export declare const AgentTurnSettledPayloadSchema: Schema.Struct<{
21
+ readonly turn: Schema.Finite;
17
22
  }>;
18
23
  export declare const AgentTurnTextDeltaPayloadSchema: Schema.Struct<{
19
24
  readonly turn: Schema.Finite;
@@ -223,6 +228,11 @@ export declare const agentCatalog: import("@swirls/looms/core").EventCatalog<"ag
223
228
  }>;
224
229
  'turn.started': Schema.Struct<{
225
230
  readonly turn: Schema.Finite;
231
+ /** Snapshot of `lines.length` when the LLM call began. Used to detect mid-call steers. */
232
+ readonly messageCount: Schema.optional<Schema.Finite>;
233
+ }>;
234
+ 'turn.settled': Schema.Struct<{
235
+ readonly turn: Schema.Finite;
226
236
  }>;
227
237
  'turn.text_delta': Schema.Struct<{
228
238
  readonly turn: Schema.Finite;
@@ -6,6 +6,11 @@ export const AgentMessageReceivedPayloadSchema = Schema.Struct({
6
6
  });
7
7
  export const AgentTurnStartedPayloadSchema = Schema.Struct({
8
8
  turn: Schema.Finite,
9
+ /** Snapshot of `lines.length` when the LLM call began. Used to detect mid-call steers. */
10
+ messageCount: Schema.optional(Schema.Finite),
11
+ });
12
+ export const AgentTurnSettledPayloadSchema = Schema.Struct({
13
+ turn: Schema.Finite,
9
14
  });
10
15
  export const AgentTurnTextDeltaPayloadSchema = Schema.Struct({
11
16
  turn: Schema.Finite,
@@ -104,6 +109,7 @@ export const AgentEffectsRequestedPayloadSchema = Schema.Struct({
104
109
  export const agentCatalog = defineEventCatalog('agent', {
105
110
  'message.received': AgentMessageReceivedPayloadSchema,
106
111
  'turn.started': AgentTurnStartedPayloadSchema,
112
+ 'turn.settled': AgentTurnSettledPayloadSchema,
107
113
  'turn.text_delta': AgentTurnTextDeltaPayloadSchema,
108
114
  message: AgentMessageEventPayloadSchema,
109
115
  'tool_call.requested': AgentToolCallRequestedPayloadSchema,