@copilotkit/runtime 1.5.0-tyler-reset-chat.0 → 1.5.1-custom-tag-pre.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 (78) hide show
  1. package/CHANGELOG.md +150 -3
  2. package/__snapshots__/schema/schema.graphql +8 -9
  3. package/dist/{chunk-K67A6XOJ.mjs → chunk-3ECBC2K2.mjs} +462 -328
  4. package/dist/chunk-3ECBC2K2.mjs.map +1 -0
  5. package/dist/{chunk-QNQ6UT3D.mjs → chunk-5E6LOP76.mjs} +2 -2
  6. package/dist/{chunk-OKQVDDJ2.mjs → chunk-CLGKEUOA.mjs} +298 -63
  7. package/dist/chunk-CLGKEUOA.mjs.map +1 -0
  8. package/dist/{chunk-ZBG4KJW5.mjs → chunk-MKDG5ZHT.mjs} +2 -2
  9. package/dist/{chunk-AGSBOD2T.mjs → chunk-MYZB2EKG.mjs} +2 -2
  10. package/dist/{chunk-B74M7FXG.mjs → chunk-RFF5IIZJ.mjs} +3 -2
  11. package/dist/chunk-RFF5IIZJ.mjs.map +1 -0
  12. package/dist/{copilot-runtime-12e7ac40.d.ts → copilot-runtime-6285d897.d.ts} +2 -2
  13. package/dist/graphql/types/converted/index.d.ts +1 -1
  14. package/dist/graphql/types/converted/index.js +2 -1
  15. package/dist/graphql/types/converted/index.js.map +1 -1
  16. package/dist/graphql/types/converted/index.mjs +1 -1
  17. package/dist/{groq-adapter-24abe931.d.ts → groq-adapter-15d41154.d.ts} +1 -1
  18. package/dist/{index-10b1c870.d.ts → index-ff3fbc33.d.ts} +7 -8
  19. package/dist/index.d.ts +5 -5
  20. package/dist/index.js +852 -480
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +10 -6
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/{langserve-f021ab9c.d.ts → langserve-48e976ac.d.ts} +54 -14
  25. package/dist/lib/index.d.ts +4 -4
  26. package/dist/lib/index.js +754 -459
  27. package/dist/lib/index.js.map +1 -1
  28. package/dist/lib/index.mjs +6 -6
  29. package/dist/lib/integrations/index.d.ts +4 -4
  30. package/dist/lib/integrations/index.js +78 -30
  31. package/dist/lib/integrations/index.js.map +1 -1
  32. package/dist/lib/integrations/index.mjs +6 -6
  33. package/dist/lib/integrations/nest/index.d.ts +3 -3
  34. package/dist/lib/integrations/nest/index.js +78 -30
  35. package/dist/lib/integrations/nest/index.js.map +1 -1
  36. package/dist/lib/integrations/nest/index.mjs +4 -4
  37. package/dist/lib/integrations/node-express/index.d.ts +3 -3
  38. package/dist/lib/integrations/node-express/index.js +78 -30
  39. package/dist/lib/integrations/node-express/index.js.map +1 -1
  40. package/dist/lib/integrations/node-express/index.mjs +4 -4
  41. package/dist/lib/integrations/node-http/index.d.ts +3 -3
  42. package/dist/lib/integrations/node-http/index.js +78 -30
  43. package/dist/lib/integrations/node-http/index.js.map +1 -1
  44. package/dist/lib/integrations/node-http/index.mjs +3 -3
  45. package/dist/service-adapters/index.d.ts +36 -5
  46. package/dist/service-adapters/index.js +298 -61
  47. package/dist/service-adapters/index.js.map +1 -1
  48. package/dist/service-adapters/index.mjs +5 -1
  49. package/package.json +4 -4
  50. package/src/agents/langgraph/event-source.ts +140 -148
  51. package/src/agents/langgraph/events.ts +1 -1
  52. package/src/graphql/inputs/forwarded-parameters.input.ts +3 -0
  53. package/src/graphql/inputs/message.input.ts +15 -3
  54. package/src/graphql/resolvers/copilot.resolver.ts +32 -6
  55. package/src/graphql/types/converted/index.ts +4 -3
  56. package/src/graphql/types/copilot-response.type.ts +12 -3
  57. package/src/graphql/types/enums.ts +0 -11
  58. package/src/lib/runtime/copilot-runtime.ts +1 -7
  59. package/src/lib/runtime/remote-action-constructors.ts +64 -58
  60. package/src/lib/runtime/remote-actions.ts +1 -0
  61. package/src/lib/runtime/remote-lg-action.ts +184 -154
  62. package/src/service-adapters/anthropic/anthropic-adapter.ts +17 -6
  63. package/src/service-adapters/conversion.ts +2 -1
  64. package/src/service-adapters/events.ts +118 -54
  65. package/src/service-adapters/experimental/empty/empty-adapter.ts +33 -0
  66. package/src/service-adapters/experimental/ollama/ollama-adapter.ts +7 -3
  67. package/src/service-adapters/groq/groq-adapter.ts +24 -8
  68. package/src/service-adapters/index.ts +7 -1
  69. package/src/service-adapters/langchain/utils.ts +55 -32
  70. package/src/service-adapters/openai/openai-adapter.ts +23 -9
  71. package/src/service-adapters/openai/openai-assistant-adapter.ts +22 -8
  72. package/src/service-adapters/unify/unify-adapter.ts +30 -11
  73. package/dist/chunk-B74M7FXG.mjs.map +0 -1
  74. package/dist/chunk-K67A6XOJ.mjs.map +0 -1
  75. package/dist/chunk-OKQVDDJ2.mjs.map +0 -1
  76. /package/dist/{chunk-QNQ6UT3D.mjs.map → chunk-5E6LOP76.mjs.map} +0 -0
  77. /package/dist/{chunk-ZBG4KJW5.mjs.map → chunk-MKDG5ZHT.mjs.map} +0 -0
  78. /package/dist/{chunk-AGSBOD2T.mjs.map → chunk-MYZB2EKG.mjs.map} +0 -0
@@ -5,13 +5,17 @@ import { randomId } from "@copilotkit/shared";
5
5
 
6
6
  interface LangGraphEventWithState {
7
7
  event: LangGraphEvent | null;
8
- content: string | null;
9
- toolCallName: string | null;
10
- toolCallId: string | null;
11
- toolCallMessageId: string | null;
12
- prevToolCallMessageId: string | null;
13
- messageId: string | null;
14
- prevMessageId: string | null;
8
+
9
+ isMessageStart: boolean;
10
+ isMessageEnd: boolean;
11
+ isToolCallStart: boolean;
12
+ isToolCallEnd: boolean;
13
+ isToolCall: boolean;
14
+
15
+ lastMessageId: string | null;
16
+ lastToolCallId: string | null;
17
+ lastToolCallName: string | null;
18
+ currentContent: string | null;
15
19
  }
16
20
 
17
21
  export class RemoteLangGraphEventSource {
@@ -30,6 +34,43 @@ export class RemoteLangGraphEventSource {
30
34
  return shouldEmitToolCalls === toolCallName;
31
35
  }
32
36
 
37
+ private getCurrentContent(event: LangGraphEvent) {
38
+ // @ts-expect-error -- LangGraph Platform implementation stores data outside of kwargs
39
+ const content = event.data?.chunk?.kwargs?.content ?? event.data?.chunk?.content;
40
+
41
+ if (!content) {
42
+ const toolCallChunks = this.getCurrentToolCallChunks(event) ?? [];
43
+ for (const chunk of toolCallChunks) {
44
+ if (chunk.args) {
45
+ return chunk.args;
46
+ }
47
+ }
48
+ }
49
+
50
+ if (typeof content === "string") {
51
+ return content;
52
+ } else if (Array.isArray(content) && content.length > 0) {
53
+ return content[0].text;
54
+ }
55
+
56
+ return null;
57
+ }
58
+
59
+ private getCurrentMessageId(event: LangGraphEvent) {
60
+ // @ts-expect-error -- LangGraph Platform implementation stores data outside of kwargs
61
+ return event.data?.chunk?.kwargs?.id ?? event.data?.chunk?.id;
62
+ }
63
+
64
+ private getCurrentToolCallChunks(event: LangGraphEvent) {
65
+ // @ts-expect-error -- LangGraph Platform implementation stores data outside of kwargs
66
+ return event.data?.chunk?.kwargs?.tool_call_chunks ?? event.data?.chunk?.tool_call_chunks;
67
+ }
68
+
69
+ private getResponseMetadata(event: LangGraphEvent) {
70
+ // @ts-expect-error -- LangGraph Platform implementation stores data outside of kwargs
71
+ return event.data?.chunk?.kwargs?.response_metadata ?? event.data?.chunk?.response_metadata;
72
+ }
73
+
33
74
  processLangGraphEvents() {
34
75
  let lastEventWithState: LangGraphEventWithState | null = null;
35
76
 
@@ -37,104 +78,75 @@ export class RemoteLangGraphEventSource {
37
78
  scan(
38
79
  (acc, event) => {
39
80
  if (event.event === LangGraphEventTypes.OnChatModelStream) {
40
- // @ts-expect-error -- LangGraph Platform implementation stores data outside of kwargs
41
- const content = event.data?.chunk?.kwargs?.content ?? event.data?.chunk?.content;
42
-
43
- if (typeof content === "string") {
44
- acc.content = content;
45
- } else if (Array.isArray(content) && content.length > 0) {
46
- acc.content = content[0].text;
47
- } else {
48
- acc.content = null;
49
- }
81
+ const prevMessageId = acc.lastMessageId;
82
+ acc.currentContent = this.getCurrentContent(event);
83
+ acc.lastMessageId = this.getCurrentMessageId(event) ?? acc.lastMessageId;
84
+ const toolCallChunks = this.getCurrentToolCallChunks(event) ?? [];
85
+ const responseMetadata = this.getResponseMetadata(event);
50
86
 
51
- const toolCallChunks =
52
- // @ts-expect-error -- LangGraph Platform implementation stores data outside of kwargs
53
- event.data?.chunk?.kwargs?.tool_call_chunks ?? event.data?.chunk?.tool_call_chunks;
54
-
55
- const toolCallMessageId =
56
- event.data?.chunk?.kwargs?.id ??
57
- (event.data?.chunk?.id as unknown as string | undefined);
58
-
59
- if (toolCallChunks && toolCallChunks.length > 0) {
60
- acc.prevToolCallMessageId = acc.toolCallMessageId;
61
- acc.toolCallMessageId = toolCallMessageId;
62
- if (toolCallChunks[0]?.name) {
63
- acc.toolCallName = toolCallChunks[0].name;
64
- }
65
- if (toolCallChunks[0]?.id) {
66
- acc.toolCallId = toolCallChunks[0].id;
67
- }
68
- acc.prevMessageId = acc.messageId;
69
- acc.messageId = toolCallMessageId;
70
- } else if (acc.content && acc.content != "") {
71
- acc.prevMessageId = acc.messageId;
72
- acc.messageId = toolCallMessageId;
73
- } else {
74
- acc.prevToolCallMessageId = acc.toolCallMessageId;
75
- acc.prevMessageId = acc.messageId;
76
- }
77
- } else {
78
- acc.prevToolCallMessageId = acc.toolCallMessageId;
79
- acc.toolCallMessageId = null;
80
- acc.prevMessageId = acc.messageId;
81
- acc.messageId = null;
82
- acc.toolCallName = null;
87
+ acc.isToolCallStart = toolCallChunks.some((chunk: any) => chunk.name && chunk.id);
88
+ acc.isMessageStart = prevMessageId !== acc.lastMessageId && !acc.isToolCallStart;
89
+ acc.isToolCall = toolCallChunks && toolCallChunks.length > 0;
90
+ acc.isToolCallEnd = responseMetadata?.finish_reason === "tool_calls";
91
+ acc.isMessageEnd = responseMetadata?.finish_reason === "stop";
92
+ ({ name: acc.lastToolCallName, id: acc.lastToolCallId } = toolCallChunks.find(
93
+ (chunk: any) => chunk.name && chunk.id,
94
+ ) ?? { name: acc.lastToolCallName, id: acc.lastToolCallId });
83
95
  }
84
-
85
96
  acc.event = event;
86
97
  lastEventWithState = acc; // Capture the state
87
98
  return acc;
88
99
  },
89
100
  {
90
101
  event: null,
91
- toolCallId: null,
92
- toolCallMessageId: null,
93
- prevToolCallMessageId: null,
94
- messageId: null,
95
- toolCallName: null,
96
- prevMessageId: null,
97
- content: null,
102
+ isMessageStart: false,
103
+ isMessageEnd: false,
104
+ isToolCallStart: false,
105
+ isToolCallEnd: false,
106
+ isToolCall: false,
107
+ lastMessageId: null,
108
+ lastToolCallId: null,
109
+ lastToolCallName: null,
110
+ currentContent: null,
98
111
  } as LangGraphEventWithState,
99
112
  ),
100
- mergeMap((eventWithState): RuntimeEvent[] => {
113
+ mergeMap((acc): RuntimeEvent[] => {
101
114
  const events: RuntimeEvent[] = [];
102
115
 
103
116
  let shouldEmitMessages = true;
104
- let shouldEmitToolCalls: string | string[] | boolean = false;
117
+ let shouldEmitToolCalls: string | string[] | boolean = true;
105
118
 
106
- if (eventWithState.event.event == LangGraphEventTypes.OnChatModelStream) {
107
- if ("copilotkit:emit-tool-calls" in (eventWithState.event.metadata || {})) {
108
- shouldEmitToolCalls = eventWithState.event.metadata["copilotkit:emit-tool-calls"];
119
+ if (acc.event.event == LangGraphEventTypes.OnChatModelStream) {
120
+ if ("copilotkit:emit-tool-calls" in (acc.event.metadata || {})) {
121
+ shouldEmitToolCalls = acc.event.metadata["copilotkit:emit-tool-calls"];
109
122
  }
110
- if ("copilotkit:emit-messages" in (eventWithState.event.metadata || {})) {
111
- shouldEmitMessages = eventWithState.event.metadata["copilotkit:emit-messages"];
123
+ if ("copilotkit:emit-messages" in (acc.event.metadata || {})) {
124
+ shouldEmitMessages = acc.event.metadata["copilotkit:emit-messages"];
112
125
  }
113
126
  }
114
127
 
128
+ const responseMetadata = this.getResponseMetadata(acc.event);
129
+
115
130
  // Tool call ended: emit ActionExecutionEnd
116
131
  if (
117
- eventWithState.prevToolCallMessageId !== null &&
118
- eventWithState.prevToolCallMessageId !== eventWithState.toolCallMessageId &&
119
- this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)
132
+ responseMetadata?.finish_reason === "tool_calls" &&
133
+ this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)
120
134
  ) {
121
135
  events.push({
122
136
  type: RuntimeEventTypes.ActionExecutionEnd,
137
+ actionExecutionId: acc.lastToolCallId,
123
138
  });
124
139
  }
125
140
 
126
141
  // Message ended: emit TextMessageEnd
127
- if (
128
- eventWithState.prevMessageId !== null &&
129
- eventWithState.prevMessageId !== eventWithState.messageId &&
130
- shouldEmitMessages
131
- ) {
142
+ if (responseMetadata?.finish_reason === "stop" && shouldEmitMessages) {
132
143
  events.push({
133
144
  type: RuntimeEventTypes.TextMessageEnd,
145
+ messageId: acc.lastMessageId,
134
146
  });
135
147
  }
136
148
 
137
- switch (eventWithState.event!.event) {
149
+ switch (acc.event!.event) {
138
150
  //
139
151
  // Custom events
140
152
  //
@@ -142,118 +154,94 @@ export class RemoteLangGraphEventSource {
142
154
  //
143
155
  // Manually emit a message
144
156
  //
145
- if (eventWithState.event.name === CustomEventNames.CopilotKitManuallyEmitMessage) {
157
+ if (acc.event.name === CustomEventNames.CopilotKitManuallyEmitMessage) {
146
158
  events.push({
147
159
  type: RuntimeEventTypes.TextMessageStart,
148
- messageId: eventWithState.event.data.message_id,
160
+ messageId: acc.event.data.message_id,
149
161
  });
150
162
  events.push({
151
163
  type: RuntimeEventTypes.TextMessageContent,
152
- content: eventWithState.event.data.message,
164
+ messageId: acc.event.data.message_id,
165
+ content: acc.event.data.message,
153
166
  });
154
167
  events.push({
155
168
  type: RuntimeEventTypes.TextMessageEnd,
169
+ messageId: acc.event.data.message_id,
156
170
  });
157
171
  }
158
172
  //
159
173
  // Manually emit a tool call
160
174
  //
161
- else if (
162
- eventWithState.event.name === CustomEventNames.CopilotKitManuallyEmitToolCall
163
- ) {
175
+ else if (acc.event.name === CustomEventNames.CopilotKitManuallyEmitToolCall) {
164
176
  events.push({
165
177
  type: RuntimeEventTypes.ActionExecutionStart,
166
- actionExecutionId: eventWithState.event.data.id,
167
- actionName: eventWithState.event.data.name,
178
+ actionExecutionId: acc.event.data.id,
179
+ actionName: acc.event.data.name,
180
+ parentMessageId: acc.event.data.id,
168
181
  });
169
182
  events.push({
170
183
  type: RuntimeEventTypes.ActionExecutionArgs,
171
- args: JSON.stringify(eventWithState.event.data.args),
184
+ actionExecutionId: acc.event.data.id,
185
+ args: JSON.stringify(acc.event.data.args),
172
186
  });
173
187
  events.push({
174
188
  type: RuntimeEventTypes.ActionExecutionEnd,
189
+ actionExecutionId: acc.event.data.id,
175
190
  });
176
191
  }
177
192
  break;
178
193
  case LangGraphEventTypes.OnCopilotKitStateSync:
179
194
  events.push({
180
195
  type: RuntimeEventTypes.AgentStateMessage,
181
- threadId: eventWithState.event.thread_id,
182
- role: eventWithState.event.role,
183
- agentName: eventWithState.event.agent_name,
184
- nodeName: eventWithState.event.node_name,
185
- runId: eventWithState.event.run_id,
186
- active: eventWithState.event.active,
187
- state: JSON.stringify(eventWithState.event.state),
188
- running: eventWithState.event.running,
196
+ threadId: acc.event.thread_id,
197
+ role: acc.event.role,
198
+ agentName: acc.event.agent_name,
199
+ nodeName: acc.event.node_name,
200
+ runId: acc.event.run_id,
201
+ active: acc.event.active,
202
+ state: JSON.stringify(acc.event.state),
203
+ running: acc.event.running,
189
204
  });
190
205
  break;
191
- case LangGraphEventTypes.OnToolEnd:
192
- // TODO-AGENTS: emit ActionExecutionResult when needed
193
- // Need a special tool node for that?
194
-
195
- // const result = eventWithState.event.data?.output?.kwargs?.content?.[0];
196
- // const toolCallId = eventWithState.event.data?.output?.kwargs?.tool_call_id;
197
- // const toolCallName = eventWithState.event.data?.output?.kwargs?.name;
198
- // if (result && toolCallId && toolCallName) {
199
- // events.push({
200
- // type: RuntimeEventTypes.ActionExecutionResult,
201
- // actionExecutionId: toolCallId,
202
- // actionName: toolCallName,
203
- // result,
204
- // });
205
- // }
206
- break;
207
206
  case LangGraphEventTypes.OnChatModelStream:
208
207
  if (
209
- eventWithState.toolCallMessageId !== null &&
210
- eventWithState.prevToolCallMessageId !== eventWithState.toolCallMessageId
208
+ acc.isToolCallStart &&
209
+ this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)
211
210
  ) {
212
- if (this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
213
- events.push({
214
- type: RuntimeEventTypes.ActionExecutionStart,
215
- actionExecutionId: eventWithState.toolCallMessageId,
216
- actionName: eventWithState.toolCallName,
217
- scope: "client",
218
- });
219
- }
211
+ events.push({
212
+ type: RuntimeEventTypes.ActionExecutionStart,
213
+ actionExecutionId: acc.lastToolCallId,
214
+ actionName: acc.lastToolCallName,
215
+ parentMessageId: acc.lastMessageId,
216
+ });
220
217
  }
221
218
  // Message started: emit TextMessageStart
222
- else if (
223
- eventWithState.messageId !== null &&
224
- eventWithState.prevMessageId !== eventWithState.messageId
225
- ) {
226
- if (shouldEmitMessages) {
227
- events.push({
228
- type: RuntimeEventTypes.TextMessageStart,
229
- messageId: eventWithState.messageId,
230
- });
231
- }
219
+ else if (acc.isMessageStart && shouldEmitMessages) {
220
+ events.push({
221
+ type: RuntimeEventTypes.TextMessageStart,
222
+ messageId: acc.lastMessageId,
223
+ });
232
224
  }
233
225
 
234
- const args =
235
- eventWithState.event.data?.chunk?.kwargs?.tool_call_chunks?.[0]?.args ??
236
- // @ts-expect-error -- sdf
237
- eventWithState.event.data?.chunk?.tool_call_chunks?.[0]?.args;
238
- const content = eventWithState.content;
239
-
240
226
  // Tool call args: emit ActionExecutionArgs
241
- if (args) {
242
- if (this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
243
- events.push({
244
- type: RuntimeEventTypes.ActionExecutionArgs,
245
- args,
246
- });
247
- }
227
+ if (
228
+ acc.isToolCall &&
229
+ acc.currentContent &&
230
+ this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)
231
+ ) {
232
+ events.push({
233
+ type: RuntimeEventTypes.ActionExecutionArgs,
234
+ actionExecutionId: acc.lastToolCallId,
235
+ args: acc.currentContent,
236
+ });
248
237
  }
249
238
  // Message content: emit TextMessageContent
250
- else if (eventWithState.messageId !== null && content) {
251
- if (shouldEmitMessages) {
252
- events.push({
253
- type: RuntimeEventTypes.TextMessageContent,
254
- content,
255
- });
256
- }
239
+ else if (!acc.isToolCall && acc.currentContent && shouldEmitMessages) {
240
+ events.push({
241
+ type: RuntimeEventTypes.TextMessageContent,
242
+ messageId: acc.lastMessageId,
243
+ content: acc.currentContent,
244
+ });
257
245
  }
258
246
  break;
259
247
  }
@@ -263,14 +251,16 @@ export class RemoteLangGraphEventSource {
263
251
  console.error(error);
264
252
  const events: RuntimeEvent[] = [];
265
253
 
266
- if (lastEventWithState?.messageId) {
254
+ if (lastEventWithState?.lastMessageId && !lastEventWithState.isToolCall) {
267
255
  events.push({
268
256
  type: RuntimeEventTypes.TextMessageEnd,
257
+ messageId: lastEventWithState.lastMessageId,
269
258
  });
270
259
  }
271
- if (lastEventWithState?.toolCallMessageId) {
260
+ if (lastEventWithState?.lastToolCallId) {
272
261
  events.push({
273
262
  type: RuntimeEventTypes.ActionExecutionEnd,
263
+ actionExecutionId: lastEventWithState.lastToolCallId,
274
264
  });
275
265
  }
276
266
 
@@ -282,10 +272,12 @@ export class RemoteLangGraphEventSource {
282
272
  });
283
273
  events.push({
284
274
  type: RuntimeEventTypes.TextMessageContent,
275
+ messageId: messageId,
285
276
  content: "❌ An error occurred. Please try again.",
286
277
  });
287
278
  events.push({
288
279
  type: RuntimeEventTypes.TextMessageEnd,
280
+ messageId: messageId,
289
281
  });
290
282
 
291
283
  return events;
@@ -119,7 +119,7 @@ type LangGraphOnChatModelStreamEvent = {
119
119
  chunk: {
120
120
  lc: number;
121
121
  type: string;
122
- id: string[];
122
+ id: string;
123
123
  kwargs: {
124
124
  content: string | { text: string; type: string; index: number }[];
125
125
  additional_kwargs: {
@@ -16,4 +16,7 @@ export class ForwardedParametersInput {
16
16
 
17
17
  @Field(() => String, { nullable: true })
18
18
  toolChoiceFunctionName?: string;
19
+
20
+ @Field(() => Number, { nullable: true })
21
+ temperature?: number;
19
22
  }
@@ -1,5 +1,5 @@
1
1
  import { Field, InputType } from "type-graphql";
2
- import { MessageRole, ActionExecutionScope } from "../types/enums";
2
+ import { MessageRole } from "../types/enums";
3
3
  import { BaseMessageInput } from "../types/base";
4
4
 
5
5
  // GraphQL does not support union types in inputs, so we need to use
@@ -24,6 +24,9 @@ export class TextMessageInput {
24
24
  @Field(() => String)
25
25
  content: string;
26
26
 
27
+ @Field(() => String, { nullable: true })
28
+ parentMessageId?: string;
29
+
27
30
  @Field(() => MessageRole)
28
31
  role: MessageRole;
29
32
  }
@@ -36,8 +39,14 @@ export class ActionExecutionMessageInput {
36
39
  @Field(() => String)
37
40
  arguments: string;
38
41
 
39
- @Field(() => ActionExecutionScope)
40
- scope: ActionExecutionScope;
42
+ @Field(() => String, { nullable: true })
43
+ parentMessageId?: string;
44
+
45
+ @Field(() => String, {
46
+ nullable: true,
47
+ deprecationReason: "This field will be removed in a future version",
48
+ })
49
+ scope?: String;
41
50
  }
42
51
 
43
52
  @InputType()
@@ -48,6 +57,9 @@ export class ResultMessageInput {
48
57
  @Field(() => String)
49
58
  actionName: string;
50
59
 
60
+ @Field(() => String, { nullable: true })
61
+ parentMessageId?: string;
62
+
51
63
  @Field(() => String)
52
64
  result: string;
53
65
  }
@@ -3,6 +3,7 @@ import {
3
3
  ReplaySubject,
4
4
  Subject,
5
5
  Subscription,
6
+ filter,
6
7
  finalize,
7
8
  firstValueFrom,
8
9
  shareReplay,
@@ -288,7 +289,19 @@ export class CopilotResolver {
288
289
  // skip until this message start event
289
290
  skipWhile((e) => e !== event),
290
291
  // take until the message end event
291
- takeWhile((e) => e.type != RuntimeEventTypes.TextMessageEnd),
292
+ takeWhile(
293
+ (e) =>
294
+ !(
295
+ e.type === RuntimeEventTypes.TextMessageEnd &&
296
+ e.messageId == event.messageId
297
+ ),
298
+ ),
299
+ // filter out any other message events or message ids
300
+ filter(
301
+ (e) =>
302
+ e.type == RuntimeEventTypes.TextMessageContent &&
303
+ e.messageId == event.messageId,
304
+ ),
292
305
  );
293
306
 
294
307
  // signal when we are done streaming
@@ -298,6 +311,7 @@ export class CopilotResolver {
298
311
  // push the new message
299
312
  pushMessage({
300
313
  id: messageId,
314
+ parentMessageId: event.parentMessageId,
301
315
  status: firstValueFrom(streamingTextStatus),
302
316
  createdAt: new Date(),
303
317
  role: MessageRole.assistant,
@@ -369,15 +383,28 @@ export class CopilotResolver {
369
383
  logger.debug("Action execution start event received");
370
384
  const actionExecutionArgumentStream = eventStream.pipe(
371
385
  skipWhile((e) => e !== event),
372
- takeWhile((e) => e.type != RuntimeEventTypes.ActionExecutionEnd),
386
+ // take until the action execution end event
387
+ takeWhile(
388
+ (e) =>
389
+ !(
390
+ e.type === RuntimeEventTypes.ActionExecutionEnd &&
391
+ e.actionExecutionId == event.actionExecutionId
392
+ ),
393
+ ),
394
+ // filter out any other action execution events or action execution ids
395
+ filter(
396
+ (e) =>
397
+ e.type == RuntimeEventTypes.ActionExecutionArgs &&
398
+ e.actionExecutionId == event.actionExecutionId,
399
+ ),
373
400
  );
374
401
  const streamingArgumentsStatus = new Subject<typeof MessageStatusUnion>();
375
402
  pushMessage({
376
403
  id: event.actionExecutionId,
404
+ parentMessageId: event.parentMessageId,
377
405
  status: firstValueFrom(streamingArgumentsStatus),
378
406
  createdAt: new Date(),
379
407
  name: event.actionName,
380
- scope: event.scope!,
381
408
  arguments: new Repeater(async (pushArgumentsChunk, stopStreamingArguments) => {
382
409
  logger.debug("Action execution argument stream created");
383
410
 
@@ -413,7 +440,6 @@ export class CopilotResolver {
413
440
  id: event.actionExecutionId,
414
441
  createdAt: new Date(),
415
442
  name: event.actionName,
416
- scope: event.scope!,
417
443
  arguments: argumentChunks.join(""),
418
444
  }),
419
445
  );
@@ -428,7 +454,7 @@ export class CopilotResolver {
428
454
  case RuntimeEventTypes.ActionExecutionResult:
429
455
  logger.debug({ result: event.result }, "Action execution result event received");
430
456
  pushMessage({
431
- id: randomId(),
457
+ id: "result-" + event.actionExecutionId,
432
458
  status: new SuccessMessageStatus(),
433
459
  createdAt: new Date(),
434
460
  actionExecutionId: event.actionExecutionId,
@@ -438,7 +464,7 @@ export class CopilotResolver {
438
464
 
439
465
  outputMessages.push(
440
466
  plainToInstance(ResultMessage, {
441
- id: randomId(),
467
+ id: "result-" + event.actionExecutionId,
442
468
  createdAt: new Date(),
443
469
  actionExecutionId: event.actionExecutionId,
444
470
  actionName: event.actionName,
@@ -5,7 +5,7 @@ import {
5
5
  AgentStateMessageInput,
6
6
  } from "../../inputs/message.input";
7
7
  import { BaseMessageInput } from "../base";
8
- import { ActionExecutionScope, MessageRole } from "../enums";
8
+ import { MessageRole } from "../enums";
9
9
 
10
10
  export type MessageType =
11
11
  | "TextMessage"
@@ -37,16 +37,17 @@ export class TextMessage extends Message implements TextMessageInput {
37
37
  type: MessageType = "TextMessage";
38
38
  content: string;
39
39
  role: MessageRole;
40
+ parentMessageId?: string;
40
41
  }
41
42
 
42
43
  export class ActionExecutionMessage
43
44
  extends Message
44
- implements Omit<ActionExecutionMessageInput, "arguments">
45
+ implements Omit<ActionExecutionMessageInput, "arguments" | "scope">
45
46
  {
46
47
  type: MessageType = "ActionExecutionMessage";
47
48
  name: string;
48
49
  arguments: Record<string, any>;
49
- scope: ActionExecutionScope;
50
+ parentMessageId?: string;
50
51
  }
51
52
 
52
53
  export class ResultMessage extends Message implements ResultMessageInput {
@@ -1,5 +1,5 @@
1
1
  import { Field, InterfaceType, ObjectType } from "type-graphql";
2
- import { MessageRole, ActionExecutionScope } from "./enums";
2
+ import { MessageRole } from "./enums";
3
3
  import { MessageStatusUnion } from "./message-status.type";
4
4
  import { ResponseStatusUnion } from "./response-status.type";
5
5
 
@@ -35,6 +35,9 @@ export class TextMessageOutput {
35
35
 
36
36
  @Field(() => [String])
37
37
  content: string[];
38
+
39
+ @Field(() => String, { nullable: true })
40
+ parentMessageId?: string;
38
41
  }
39
42
 
40
43
  @ObjectType({ implements: BaseMessageOutput })
@@ -42,11 +45,17 @@ export class ActionExecutionMessageOutput {
42
45
  @Field(() => String)
43
46
  name: string;
44
47
 
45
- @Field(() => ActionExecutionScope)
46
- scope: ActionExecutionScope;
48
+ @Field(() => String, {
49
+ nullable: true,
50
+ deprecationReason: "This field will be removed in a future version",
51
+ })
52
+ scope?: string;
47
53
 
48
54
  @Field(() => [String])
49
55
  arguments: string[];
56
+
57
+ @Field(() => String, { nullable: true })
58
+ parentMessageId?: string;
50
59
  }
51
60
 
52
61
  @ObjectType({ implements: BaseMessageOutput })
@@ -7,12 +7,6 @@ export enum MessageRole {
7
7
  tool = "tool",
8
8
  }
9
9
 
10
- export enum ActionExecutionScope {
11
- server = "server",
12
- client = "client",
13
- passThrough = "passThrough",
14
- }
15
-
16
10
  export enum CopilotRequestType {
17
11
  Chat = "Chat",
18
12
  Task = "Task",
@@ -32,11 +26,6 @@ registerEnumType(MessageRole, {
32
26
  description: "The role of the message",
33
27
  });
34
28
 
35
- registerEnumType(ActionExecutionScope, {
36
- name: "ActionExecutionScope",
37
- description: "The scope of the action",
38
- });
39
-
40
29
  registerEnumType(CopilotRequestType, {
41
30
  name: "CopilotRequestType",
42
31
  description: "The type of Copilot request",
@@ -249,13 +249,7 @@ export class CopilotRuntime<const T extends Parameter[] | [] = []> {
249
249
  } catch (error) {
250
250
  console.error("Error getting response:", error);
251
251
  eventSource.sendErrorMessageToChat();
252
- return {
253
- threadId: threadId || randomId(),
254
- runId: runId || randomId(),
255
- eventSource,
256
- serverSideActions: [],
257
- actionInputsWithoutAgents: [],
258
- };
252
+ throw error;
259
253
  }
260
254
  }
261
255