@copilotkit/runtime 1.4.8-coagents-v0-3.1 → 1.4.8-next.1

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 (77) hide show
  1. package/CHANGELOG.md +5 -4
  2. package/__snapshots__/schema/schema.graphql +10 -7
  3. package/dist/{chunk-FVYNRYIB.mjs → chunk-5KJYPVQJ.mjs} +307 -423
  4. package/dist/chunk-5KJYPVQJ.mjs.map +1 -0
  5. package/dist/{chunk-RFF5IIZJ.mjs → chunk-B74M7FXG.mjs} +2 -3
  6. package/dist/chunk-B74M7FXG.mjs.map +1 -0
  7. package/dist/{chunk-BACNNHHI.mjs → chunk-CGGI46KC.mjs} +2 -2
  8. package/dist/{chunk-YFG3Q3YH.mjs → chunk-EU52BTKR.mjs} +2 -2
  9. package/dist/{chunk-MQJNZYAH.mjs → chunk-KO4QCMY4.mjs} +2 -2
  10. package/dist/{chunk-2PK2SFRB.mjs → chunk-W7GP2EOT.mjs} +106 -221
  11. package/dist/chunk-W7GP2EOT.mjs.map +1 -0
  12. package/dist/{copilot-runtime-b15b683d.d.ts → copilot-runtime-1c5bf72b.d.ts} +2 -2
  13. package/dist/graphql/types/converted/index.d.ts +1 -1
  14. package/dist/graphql/types/converted/index.js +1 -2
  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-50aa9621.d.ts → groq-adapter-b6a40422.d.ts} +1 -1
  18. package/dist/{index-ff3fbc33.d.ts → index-10b1c870.d.ts} +8 -7
  19. package/dist/index.d.ts +5 -5
  20. package/dist/index.js +515 -745
  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-8ec29cba.d.ts → langserve-6245df39.d.ts} +14 -52
  25. package/dist/lib/index.d.ts +4 -4
  26. package/dist/lib/index.js +442 -706
  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 +37 -71
  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 +37 -71
  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 +37 -71
  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 +37 -71
  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 +106 -219
  47. package/dist/service-adapters/index.js.map +1 -1
  48. package/dist/service-adapters/index.mjs +5 -1
  49. package/package.json +2 -2
  50. package/src/agents/langgraph/event-source.ts +148 -140
  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 +3 -15
  54. package/src/graphql/resolvers/copilot.resolver.ts +6 -32
  55. package/src/graphql/types/converted/index.ts +3 -4
  56. package/src/graphql/types/copilot-response.type.ts +3 -12
  57. package/src/graphql/types/enums.ts +11 -0
  58. package/src/lib/runtime/remote-action-constructors.ts +62 -60
  59. package/src/lib/runtime/remote-actions.ts +0 -1
  60. package/src/lib/runtime/remote-lg-action.ts +140 -161
  61. package/src/service-adapters/anthropic/anthropic-adapter.ts +6 -16
  62. package/src/service-adapters/conversion.ts +1 -2
  63. package/src/service-adapters/events.ts +52 -111
  64. package/src/service-adapters/experimental/empty/empty-adapter.ts +33 -0
  65. package/src/service-adapters/experimental/ollama/ollama-adapter.ts +3 -7
  66. package/src/service-adapters/groq/groq-adapter.ts +8 -23
  67. package/src/service-adapters/index.ts +7 -1
  68. package/src/service-adapters/langchain/utils.ts +31 -49
  69. package/src/service-adapters/openai/openai-adapter.ts +9 -22
  70. package/src/service-adapters/openai/openai-assistant-adapter.ts +8 -22
  71. package/src/service-adapters/unify/unify-adapter.ts +11 -28
  72. package/dist/chunk-2PK2SFRB.mjs.map +0 -1
  73. package/dist/chunk-FVYNRYIB.mjs.map +0 -1
  74. package/dist/chunk-RFF5IIZJ.mjs.map +0 -1
  75. /package/dist/{chunk-BACNNHHI.mjs.map → chunk-CGGI46KC.mjs.map} +0 -0
  76. /package/dist/{chunk-YFG3Q3YH.mjs.map → chunk-EU52BTKR.mjs.map} +0 -0
  77. /package/dist/{chunk-MQJNZYAH.mjs.map → chunk-KO4QCMY4.mjs.map} +0 -0
@@ -5,17 +5,13 @@ import { randomId } from "@copilotkit/shared";
5
5
 
6
6
  interface LangGraphEventWithState {
7
7
  event: LangGraphEvent | 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;
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;
19
15
  }
20
16
 
21
17
  export class RemoteLangGraphEventSource {
@@ -34,43 +30,6 @@ export class RemoteLangGraphEventSource {
34
30
  return shouldEmitToolCalls === toolCallName;
35
31
  }
36
32
 
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
-
74
33
  processLangGraphEvents() {
75
34
  let lastEventWithState: LangGraphEventWithState | null = null;
76
35
 
@@ -78,75 +37,104 @@ export class RemoteLangGraphEventSource {
78
37
  scan(
79
38
  (acc, event) => {
80
39
  if (event.event === LangGraphEventTypes.OnChatModelStream) {
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);
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
+ }
86
50
 
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 });
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;
95
83
  }
84
+
96
85
  acc.event = event;
97
86
  lastEventWithState = acc; // Capture the state
98
87
  return acc;
99
88
  },
100
89
  {
101
90
  event: 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,
91
+ toolCallId: null,
92
+ toolCallMessageId: null,
93
+ prevToolCallMessageId: null,
94
+ messageId: null,
95
+ toolCallName: null,
96
+ prevMessageId: null,
97
+ content: null,
111
98
  } as LangGraphEventWithState,
112
99
  ),
113
- mergeMap((acc): RuntimeEvent[] => {
100
+ mergeMap((eventWithState): RuntimeEvent[] => {
114
101
  const events: RuntimeEvent[] = [];
115
102
 
116
103
  let shouldEmitMessages = true;
117
- let shouldEmitToolCalls: string | string[] | boolean = true;
104
+ let shouldEmitToolCalls: string | string[] | boolean = false;
118
105
 
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"];
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"];
122
109
  }
123
- if ("copilotkit:emit-messages" in (acc.event.metadata || {})) {
124
- shouldEmitMessages = acc.event.metadata["copilotkit:emit-messages"];
110
+ if ("copilotkit:emit-messages" in (eventWithState.event.metadata || {})) {
111
+ shouldEmitMessages = eventWithState.event.metadata["copilotkit:emit-messages"];
125
112
  }
126
113
  }
127
114
 
128
- const responseMetadata = this.getResponseMetadata(acc.event);
129
-
130
115
  // Tool call ended: emit ActionExecutionEnd
131
116
  if (
132
- responseMetadata?.finish_reason === "tool_calls" &&
133
- this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)
117
+ eventWithState.prevToolCallMessageId !== null &&
118
+ eventWithState.prevToolCallMessageId !== eventWithState.toolCallMessageId &&
119
+ this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)
134
120
  ) {
135
121
  events.push({
136
122
  type: RuntimeEventTypes.ActionExecutionEnd,
137
- actionExecutionId: acc.lastToolCallId,
138
123
  });
139
124
  }
140
125
 
141
126
  // Message ended: emit TextMessageEnd
142
- if (responseMetadata?.finish_reason === "stop" && shouldEmitMessages) {
127
+ if (
128
+ eventWithState.prevMessageId !== null &&
129
+ eventWithState.prevMessageId !== eventWithState.messageId &&
130
+ shouldEmitMessages
131
+ ) {
143
132
  events.push({
144
133
  type: RuntimeEventTypes.TextMessageEnd,
145
- messageId: acc.lastMessageId,
146
134
  });
147
135
  }
148
136
 
149
- switch (acc.event!.event) {
137
+ switch (eventWithState.event!.event) {
150
138
  //
151
139
  // Custom events
152
140
  //
@@ -154,94 +142,118 @@ export class RemoteLangGraphEventSource {
154
142
  //
155
143
  // Manually emit a message
156
144
  //
157
- if (acc.event.name === CustomEventNames.CopilotKitManuallyEmitMessage) {
145
+ if (eventWithState.event.name === CustomEventNames.CopilotKitManuallyEmitMessage) {
158
146
  events.push({
159
147
  type: RuntimeEventTypes.TextMessageStart,
160
- messageId: acc.event.data.message_id,
148
+ messageId: eventWithState.event.data.message_id,
161
149
  });
162
150
  events.push({
163
151
  type: RuntimeEventTypes.TextMessageContent,
164
- messageId: acc.event.data.message_id,
165
- content: acc.event.data.message,
152
+ content: eventWithState.event.data.message,
166
153
  });
167
154
  events.push({
168
155
  type: RuntimeEventTypes.TextMessageEnd,
169
- messageId: acc.event.data.message_id,
170
156
  });
171
157
  }
172
158
  //
173
159
  // Manually emit a tool call
174
160
  //
175
- else if (acc.event.name === CustomEventNames.CopilotKitManuallyEmitToolCall) {
161
+ else if (
162
+ eventWithState.event.name === CustomEventNames.CopilotKitManuallyEmitToolCall
163
+ ) {
176
164
  events.push({
177
165
  type: RuntimeEventTypes.ActionExecutionStart,
178
- actionExecutionId: acc.event.data.id,
179
- actionName: acc.event.data.name,
180
- parentMessageId: acc.event.data.id,
166
+ actionExecutionId: eventWithState.event.data.id,
167
+ actionName: eventWithState.event.data.name,
181
168
  });
182
169
  events.push({
183
170
  type: RuntimeEventTypes.ActionExecutionArgs,
184
- actionExecutionId: acc.event.data.id,
185
- args: JSON.stringify(acc.event.data.args),
171
+ args: JSON.stringify(eventWithState.event.data.args),
186
172
  });
187
173
  events.push({
188
174
  type: RuntimeEventTypes.ActionExecutionEnd,
189
- actionExecutionId: acc.event.data.id,
190
175
  });
191
176
  }
192
177
  break;
193
178
  case LangGraphEventTypes.OnCopilotKitStateSync:
194
179
  events.push({
195
180
  type: RuntimeEventTypes.AgentStateMessage,
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,
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,
204
189
  });
205
190
  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;
206
207
  case LangGraphEventTypes.OnChatModelStream:
207
208
  if (
208
- acc.isToolCallStart &&
209
- this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)
209
+ eventWithState.toolCallMessageId !== null &&
210
+ eventWithState.prevToolCallMessageId !== eventWithState.toolCallMessageId
210
211
  ) {
211
- events.push({
212
- type: RuntimeEventTypes.ActionExecutionStart,
213
- actionExecutionId: acc.lastToolCallId,
214
- actionName: acc.lastToolCallName,
215
- parentMessageId: acc.lastMessageId,
216
- });
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
+ }
217
220
  }
218
221
  // Message started: emit TextMessageStart
219
- else if (acc.isMessageStart && shouldEmitMessages) {
220
- events.push({
221
- type: RuntimeEventTypes.TextMessageStart,
222
- messageId: acc.lastMessageId,
223
- });
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
+ }
224
232
  }
225
233
 
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
+
226
240
  // Tool call args: emit ActionExecutionArgs
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
- });
241
+ if (args) {
242
+ if (this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
243
+ events.push({
244
+ type: RuntimeEventTypes.ActionExecutionArgs,
245
+ args,
246
+ });
247
+ }
237
248
  }
238
249
  // Message content: emit TextMessageContent
239
- else if (!acc.isToolCall && acc.currentContent && shouldEmitMessages) {
240
- events.push({
241
- type: RuntimeEventTypes.TextMessageContent,
242
- messageId: acc.lastMessageId,
243
- content: acc.currentContent,
244
- });
250
+ else if (eventWithState.messageId !== null && content) {
251
+ if (shouldEmitMessages) {
252
+ events.push({
253
+ type: RuntimeEventTypes.TextMessageContent,
254
+ content,
255
+ });
256
+ }
245
257
  }
246
258
  break;
247
259
  }
@@ -251,16 +263,14 @@ export class RemoteLangGraphEventSource {
251
263
  console.error(error);
252
264
  const events: RuntimeEvent[] = [];
253
265
 
254
- if (lastEventWithState?.lastMessageId && !lastEventWithState.isToolCall) {
266
+ if (lastEventWithState?.messageId) {
255
267
  events.push({
256
268
  type: RuntimeEventTypes.TextMessageEnd,
257
- messageId: lastEventWithState.lastMessageId,
258
269
  });
259
270
  }
260
- if (lastEventWithState?.lastToolCallId) {
271
+ if (lastEventWithState?.toolCallMessageId) {
261
272
  events.push({
262
273
  type: RuntimeEventTypes.ActionExecutionEnd,
263
- actionExecutionId: lastEventWithState.lastToolCallId,
264
274
  });
265
275
  }
266
276
 
@@ -272,12 +282,10 @@ export class RemoteLangGraphEventSource {
272
282
  });
273
283
  events.push({
274
284
  type: RuntimeEventTypes.TextMessageContent,
275
- messageId: messageId,
276
285
  content: "❌ An error occurred. Please try again.",
277
286
  });
278
287
  events.push({
279
288
  type: RuntimeEventTypes.TextMessageEnd,
280
- messageId: messageId,
281
289
  });
282
290
 
283
291
  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 } from "../types/enums";
2
+ import { MessageRole, ActionExecutionScope } 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,9 +24,6 @@ export class TextMessageInput {
24
24
  @Field(() => String)
25
25
  content: string;
26
26
 
27
- @Field(() => String, { nullable: true })
28
- parentMessageId?: string;
29
-
30
27
  @Field(() => MessageRole)
31
28
  role: MessageRole;
32
29
  }
@@ -39,14 +36,8 @@ export class ActionExecutionMessageInput {
39
36
  @Field(() => String)
40
37
  arguments: string;
41
38
 
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;
39
+ @Field(() => ActionExecutionScope)
40
+ scope: ActionExecutionScope;
50
41
  }
51
42
 
52
43
  @InputType()
@@ -57,9 +48,6 @@ export class ResultMessageInput {
57
48
  @Field(() => String)
58
49
  actionName: string;
59
50
 
60
- @Field(() => String, { nullable: true })
61
- parentMessageId?: string;
62
-
63
51
  @Field(() => String)
64
52
  result: string;
65
53
  }
@@ -3,7 +3,6 @@ import {
3
3
  ReplaySubject,
4
4
  Subject,
5
5
  Subscription,
6
- filter,
7
6
  finalize,
8
7
  firstValueFrom,
9
8
  shareReplay,
@@ -289,19 +288,7 @@ export class CopilotResolver {
289
288
  // skip until this message start event
290
289
  skipWhile((e) => e !== event),
291
290
  // take until the message end event
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
- ),
291
+ takeWhile((e) => e.type != RuntimeEventTypes.TextMessageEnd),
305
292
  );
306
293
 
307
294
  // signal when we are done streaming
@@ -311,7 +298,6 @@ export class CopilotResolver {
311
298
  // push the new message
312
299
  pushMessage({
313
300
  id: messageId,
314
- parentMessageId: event.parentMessageId,
315
301
  status: firstValueFrom(streamingTextStatus),
316
302
  createdAt: new Date(),
317
303
  role: MessageRole.assistant,
@@ -383,28 +369,15 @@ export class CopilotResolver {
383
369
  logger.debug("Action execution start event received");
384
370
  const actionExecutionArgumentStream = eventStream.pipe(
385
371
  skipWhile((e) => e !== event),
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
- ),
372
+ takeWhile((e) => e.type != RuntimeEventTypes.ActionExecutionEnd),
400
373
  );
401
374
  const streamingArgumentsStatus = new Subject<typeof MessageStatusUnion>();
402
375
  pushMessage({
403
376
  id: event.actionExecutionId,
404
- parentMessageId: event.parentMessageId,
405
377
  status: firstValueFrom(streamingArgumentsStatus),
406
378
  createdAt: new Date(),
407
379
  name: event.actionName,
380
+ scope: event.scope!,
408
381
  arguments: new Repeater(async (pushArgumentsChunk, stopStreamingArguments) => {
409
382
  logger.debug("Action execution argument stream created");
410
383
 
@@ -440,6 +413,7 @@ export class CopilotResolver {
440
413
  id: event.actionExecutionId,
441
414
  createdAt: new Date(),
442
415
  name: event.actionName,
416
+ scope: event.scope!,
443
417
  arguments: argumentChunks.join(""),
444
418
  }),
445
419
  );
@@ -454,7 +428,7 @@ export class CopilotResolver {
454
428
  case RuntimeEventTypes.ActionExecutionResult:
455
429
  logger.debug({ result: event.result }, "Action execution result event received");
456
430
  pushMessage({
457
- id: "result-" + event.actionExecutionId,
431
+ id: randomId(),
458
432
  status: new SuccessMessageStatus(),
459
433
  createdAt: new Date(),
460
434
  actionExecutionId: event.actionExecutionId,
@@ -464,7 +438,7 @@ export class CopilotResolver {
464
438
 
465
439
  outputMessages.push(
466
440
  plainToInstance(ResultMessage, {
467
- id: "result-" + event.actionExecutionId,
441
+ id: randomId(),
468
442
  createdAt: new Date(),
469
443
  actionExecutionId: event.actionExecutionId,
470
444
  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 { MessageRole } from "../enums";
8
+ import { ActionExecutionScope, MessageRole } from "../enums";
9
9
 
10
10
  export type MessageType =
11
11
  | "TextMessage"
@@ -37,17 +37,16 @@ export class TextMessage extends Message implements TextMessageInput {
37
37
  type: MessageType = "TextMessage";
38
38
  content: string;
39
39
  role: MessageRole;
40
- parentMessageId?: string;
41
40
  }
42
41
 
43
42
  export class ActionExecutionMessage
44
43
  extends Message
45
- implements Omit<ActionExecutionMessageInput, "arguments" | "scope">
44
+ implements Omit<ActionExecutionMessageInput, "arguments">
46
45
  {
47
46
  type: MessageType = "ActionExecutionMessage";
48
47
  name: string;
49
48
  arguments: Record<string, any>;
50
- parentMessageId?: string;
49
+ scope: ActionExecutionScope;
51
50
  }
52
51
 
53
52
  export class ResultMessage extends Message implements ResultMessageInput {
@@ -1,5 +1,5 @@
1
1
  import { Field, InterfaceType, ObjectType } from "type-graphql";
2
- import { MessageRole } from "./enums";
2
+ import { MessageRole, ActionExecutionScope } from "./enums";
3
3
  import { MessageStatusUnion } from "./message-status.type";
4
4
  import { ResponseStatusUnion } from "./response-status.type";
5
5
 
@@ -35,9 +35,6 @@ export class TextMessageOutput {
35
35
 
36
36
  @Field(() => [String])
37
37
  content: string[];
38
-
39
- @Field(() => String, { nullable: true })
40
- parentMessageId?: string;
41
38
  }
42
39
 
43
40
  @ObjectType({ implements: BaseMessageOutput })
@@ -45,17 +42,11 @@ export class ActionExecutionMessageOutput {
45
42
  @Field(() => String)
46
43
  name: string;
47
44
 
48
- @Field(() => String, {
49
- nullable: true,
50
- deprecationReason: "This field will be removed in a future version",
51
- })
52
- scope?: string;
45
+ @Field(() => ActionExecutionScope)
46
+ scope: ActionExecutionScope;
53
47
 
54
48
  @Field(() => [String])
55
49
  arguments: string[];
56
-
57
- @Field(() => String, { nullable: true })
58
- parentMessageId?: string;
59
50
  }
60
51
 
61
52
  @ObjectType({ implements: BaseMessageOutput })
@@ -7,6 +7,12 @@ 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
+
10
16
  export enum CopilotRequestType {
11
17
  Chat = "Chat",
12
18
  Task = "Task",
@@ -26,6 +32,11 @@ registerEnumType(MessageRole, {
26
32
  description: "The role of the message",
27
33
  });
28
34
 
35
+ registerEnumType(ActionExecutionScope, {
36
+ name: "ActionExecutionScope",
37
+ description: "The scope of the action",
38
+ });
39
+
29
40
  registerEnumType(CopilotRequestType, {
30
41
  name: "CopilotRequestType",
31
42
  description: "The type of Copilot request",