@copilotkit/runtime-client-gql 1.5.9 → 1.5.10-next.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 (58) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/chunk-256E264G.mjs +24 -0
  3. package/dist/chunk-256E264G.mjs.map +1 -0
  4. package/dist/chunk-3BOGJG6W.mjs +78 -0
  5. package/dist/chunk-3BOGJG6W.mjs.map +1 -0
  6. package/dist/chunk-7ECCT6PK.mjs +1 -0
  7. package/dist/chunk-7ECCT6PK.mjs.map +1 -0
  8. package/dist/chunk-AOS57GRG.mjs +54 -0
  9. package/dist/chunk-AOS57GRG.mjs.map +1 -0
  10. package/dist/chunk-AXHVBZ73.mjs +200 -0
  11. package/dist/chunk-AXHVBZ73.mjs.map +1 -0
  12. package/dist/chunk-IZDC2R6Y.mjs +77 -0
  13. package/dist/chunk-IZDC2R6Y.mjs.map +1 -0
  14. package/dist/chunk-WK75ISB2.mjs +18 -0
  15. package/dist/chunk-WK75ISB2.mjs.map +1 -0
  16. package/dist/chunk-WSDHT4CI.mjs +89 -0
  17. package/dist/chunk-WSDHT4CI.mjs.map +1 -0
  18. package/dist/client/CopilotRuntimeClient.d.ts +32 -0
  19. package/dist/client/CopilotRuntimeClient.js +205 -0
  20. package/dist/client/CopilotRuntimeClient.js.map +1 -0
  21. package/dist/client/CopilotRuntimeClient.mjs +11 -0
  22. package/dist/client/CopilotRuntimeClient.mjs.map +1 -0
  23. package/dist/client/conversion.d.ts +11 -0
  24. package/dist/client/conversion.js +296 -0
  25. package/dist/client/conversion.js.map +1 -0
  26. package/dist/client/conversion.mjs +17 -0
  27. package/dist/client/conversion.mjs.map +1 -0
  28. package/dist/client/index.d.ts +8 -0
  29. package/dist/client/index.js +495 -0
  30. package/dist/client/index.js.map +1 -0
  31. package/dist/client/index.mjs +38 -0
  32. package/dist/client/index.mjs.map +1 -0
  33. package/dist/client/types.d.ts +55 -0
  34. package/dist/client/types.js +113 -0
  35. package/dist/client/types.js.map +1 -0
  36. package/dist/client/types.mjs +18 -0
  37. package/dist/client/types.mjs.map +1 -0
  38. package/dist/graphql/definitions/mutations.d.ts +9 -0
  39. package/dist/graphql/definitions/mutations.js +113 -0
  40. package/dist/graphql/definitions/mutations.js.map +1 -0
  41. package/dist/graphql/definitions/mutations.mjs +9 -0
  42. package/dist/graphql/definitions/mutations.mjs.map +1 -0
  43. package/dist/graphql/definitions/queries.d.ts +8 -0
  44. package/dist/graphql/definitions/queries.js +59 -0
  45. package/dist/graphql/definitions/queries.js.map +1 -0
  46. package/dist/graphql/definitions/queries.mjs +9 -0
  47. package/dist/graphql/definitions/queries.mjs.map +1 -0
  48. package/dist/graphql-21970cc1.d.ts +422 -0
  49. package/dist/index.d.ts +8 -0
  50. package/dist/index.js +543 -0
  51. package/dist/index.js.map +1 -0
  52. package/dist/index.mjs +55 -0
  53. package/dist/index.mjs.map +1 -0
  54. package/package.json +3 -3
  55. package/src/graphql/@generated/fragment-masking.ts +87 -0
  56. package/src/graphql/@generated/gql.ts +47 -0
  57. package/src/graphql/@generated/graphql.ts +317 -0
  58. package/src/graphql/@generated/index.ts +2 -0
package/dist/index.js ADDED
@@ -0,0 +1,543 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ ActionExecutionMessage: () => ActionExecutionMessage,
34
+ ActionInputAvailability: () => ActionInputAvailability,
35
+ AgentStateMessage: () => AgentStateMessage,
36
+ AvailableAgentsDocument: () => AvailableAgentsDocument,
37
+ CopilotRequestType: () => CopilotRequestType,
38
+ CopilotRuntimeClient: () => CopilotRuntimeClient,
39
+ FailedResponseStatusReason: () => FailedResponseStatusReason,
40
+ GenerateCopilotResponseDocument: () => GenerateCopilotResponseDocument,
41
+ Message: () => Message,
42
+ MessageRole: () => MessageRole,
43
+ MessageStatusCode: () => MessageStatusCode,
44
+ ResponseStatusCode: () => ResponseStatusCode,
45
+ ResultMessage: () => ResultMessage,
46
+ Role: () => Role,
47
+ TextMessage: () => TextMessage,
48
+ convertGqlOutputToMessages: () => convertGqlOutputToMessages,
49
+ convertMessagesToGqlInput: () => convertMessagesToGqlInput,
50
+ filterAdjacentAgentStateMessages: () => filterAdjacentAgentStateMessages,
51
+ filterAgentStateMessages: () => filterAgentStateMessages,
52
+ loadMessagesFromJsonRepresentation: () => loadMessagesFromJsonRepresentation
53
+ });
54
+ module.exports = __toCommonJS(src_exports);
55
+
56
+ // src/client/CopilotRuntimeClient.ts
57
+ var import_core = require("@urql/core");
58
+
59
+ // package.json
60
+ var version = "1.5.10-next.0";
61
+
62
+ // src/graphql/@generated/graphql.ts
63
+ var ActionInputAvailability = /* @__PURE__ */ ((ActionInputAvailability2) => {
64
+ ActionInputAvailability2["Disabled"] = "disabled";
65
+ ActionInputAvailability2["Enabled"] = "enabled";
66
+ ActionInputAvailability2["Remote"] = "remote";
67
+ return ActionInputAvailability2;
68
+ })(ActionInputAvailability || {});
69
+ var CopilotRequestType = /* @__PURE__ */ ((CopilotRequestType2) => {
70
+ CopilotRequestType2["Chat"] = "Chat";
71
+ CopilotRequestType2["Suggestion"] = "Suggestion";
72
+ CopilotRequestType2["Task"] = "Task";
73
+ CopilotRequestType2["TextareaCompletion"] = "TextareaCompletion";
74
+ CopilotRequestType2["TextareaPopover"] = "TextareaPopover";
75
+ return CopilotRequestType2;
76
+ })(CopilotRequestType || {});
77
+ var FailedResponseStatusReason = /* @__PURE__ */ ((FailedResponseStatusReason2) => {
78
+ FailedResponseStatusReason2["GuardrailsValidationFailed"] = "GUARDRAILS_VALIDATION_FAILED";
79
+ FailedResponseStatusReason2["MessageStreamInterrupted"] = "MESSAGE_STREAM_INTERRUPTED";
80
+ FailedResponseStatusReason2["UnknownError"] = "UNKNOWN_ERROR";
81
+ return FailedResponseStatusReason2;
82
+ })(FailedResponseStatusReason || {});
83
+ var MessageRole = /* @__PURE__ */ ((MessageRole2) => {
84
+ MessageRole2["Assistant"] = "assistant";
85
+ MessageRole2["System"] = "system";
86
+ MessageRole2["Tool"] = "tool";
87
+ MessageRole2["User"] = "user";
88
+ return MessageRole2;
89
+ })(MessageRole || {});
90
+ var MessageStatusCode = /* @__PURE__ */ ((MessageStatusCode2) => {
91
+ MessageStatusCode2["Failed"] = "Failed";
92
+ MessageStatusCode2["Pending"] = "Pending";
93
+ MessageStatusCode2["Success"] = "Success";
94
+ return MessageStatusCode2;
95
+ })(MessageStatusCode || {});
96
+ var ResponseStatusCode = /* @__PURE__ */ ((ResponseStatusCode2) => {
97
+ ResponseStatusCode2["Failed"] = "Failed";
98
+ ResponseStatusCode2["Pending"] = "Pending";
99
+ ResponseStatusCode2["Success"] = "Success";
100
+ return ResponseStatusCode2;
101
+ })(ResponseStatusCode || {});
102
+ var GenerateCopilotResponseDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "generateCopilotResponse" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "data" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "GenerateCopilotResponseInput" } } } }, { "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "properties" } }, "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "JSONObject" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "generateCopilotResponse" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "data" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "data" } } }, { "kind": "Argument", "name": { "kind": "Name", "value": "properties" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "properties" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "threadId" } }, { "kind": "Field", "name": { "kind": "Name", "value": "runId" } }, { "kind": "InlineFragment", "typeCondition": { "kind": "NamedType", "name": { "kind": "Name", "value": "CopilotResponse" } }, "directives": [{ "kind": "Directive", "name": { "kind": "Name", "value": "defer" } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "status" }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "InlineFragment", "typeCondition": { "kind": "NamedType", "name": { "kind": "Name", "value": "BaseResponseStatus" } }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "code" } }] } }, { "kind": "InlineFragment", "typeCondition": { "kind": "NamedType", "name": { "kind": "Name", "value": "FailedResponseStatus" } }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "reason" } }, { "kind": "Field", "name": { "kind": "Name", "value": "details" } }] } }] } }] } }, { "kind": "Field", "name": { "kind": "Name", "value": "messages" }, "directives": [{ "kind": "Directive", "name": { "kind": "Name", "value": "stream" } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "__typename" } }, { "kind": "InlineFragment", "typeCondition": { "kind": "NamedType", "name": { "kind": "Name", "value": "BaseMessageOutput" } }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "id" } }, { "kind": "Field", "name": { "kind": "Name", "value": "createdAt" } }] } }, { "kind": "InlineFragment", "typeCondition": { "kind": "NamedType", "name": { "kind": "Name", "value": "BaseMessageOutput" } }, "directives": [{ "kind": "Directive", "name": { "kind": "Name", "value": "defer" } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "status" }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "InlineFragment", "typeCondition": { "kind": "NamedType", "name": { "kind": "Name", "value": "SuccessMessageStatus" } }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "code" } }] } }, { "kind": "InlineFragment", "typeCondition": { "kind": "NamedType", "name": { "kind": "Name", "value": "FailedMessageStatus" } }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "code" } }, { "kind": "Field", "name": { "kind": "Name", "value": "reason" } }] } }, { "kind": "InlineFragment", "typeCondition": { "kind": "NamedType", "name": { "kind": "Name", "value": "PendingMessageStatus" } }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "code" } }] } }] } }] } }, { "kind": "InlineFragment", "typeCondition": { "kind": "NamedType", "name": { "kind": "Name", "value": "TextMessageOutput" } }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "content" }, "directives": [{ "kind": "Directive", "name": { "kind": "Name", "value": "stream" } }] }, { "kind": "Field", "name": { "kind": "Name", "value": "role" } }, { "kind": "Field", "name": { "kind": "Name", "value": "parentMessageId" } }] } }, { "kind": "InlineFragment", "typeCondition": { "kind": "NamedType", "name": { "kind": "Name", "value": "ActionExecutionMessageOutput" } }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "name" } }, { "kind": "Field", "name": { "kind": "Name", "value": "arguments" }, "directives": [{ "kind": "Directive", "name": { "kind": "Name", "value": "stream" } }] }, { "kind": "Field", "name": { "kind": "Name", "value": "parentMessageId" } }] } }, { "kind": "InlineFragment", "typeCondition": { "kind": "NamedType", "name": { "kind": "Name", "value": "ResultMessageOutput" } }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "result" } }, { "kind": "Field", "name": { "kind": "Name", "value": "actionExecutionId" } }, { "kind": "Field", "name": { "kind": "Name", "value": "actionName" } }] } }, { "kind": "InlineFragment", "typeCondition": { "kind": "NamedType", "name": { "kind": "Name", "value": "AgentStateMessageOutput" } }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "threadId" } }, { "kind": "Field", "name": { "kind": "Name", "value": "state" } }, { "kind": "Field", "name": { "kind": "Name", "value": "running" } }, { "kind": "Field", "name": { "kind": "Name", "value": "agentName" } }, { "kind": "Field", "name": { "kind": "Name", "value": "nodeName" } }, { "kind": "Field", "name": { "kind": "Name", "value": "runId" } }, { "kind": "Field", "name": { "kind": "Name", "value": "active" } }, { "kind": "Field", "name": { "kind": "Name", "value": "role" } }] } }] } }] } }] } }] };
103
+ var AvailableAgentsDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "query", "name": { "kind": "Name", "value": "availableAgents" }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "availableAgents" }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "agents" }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "name" } }, { "kind": "Field", "name": { "kind": "Name", "value": "id" } }, { "kind": "Field", "name": { "kind": "Name", "value": "description" } }] } }] } }] } }] };
104
+
105
+ // src/graphql/@generated/gql.ts
106
+ var documents = {
107
+ "\n mutation generateCopilotResponse($data: GenerateCopilotResponseInput!, $properties: JSONObject) {\n generateCopilotResponse(data: $data, properties: $properties) {\n threadId\n runId\n ... on CopilotResponse @defer {\n status {\n ... on BaseResponseStatus {\n code\n }\n ... on FailedResponseStatus {\n reason\n details\n }\n }\n }\n messages @stream {\n __typename\n ... on BaseMessageOutput {\n id\n createdAt\n }\n ... on BaseMessageOutput @defer {\n status {\n ... on SuccessMessageStatus {\n code\n }\n ... on FailedMessageStatus {\n code\n reason\n }\n ... on PendingMessageStatus {\n code\n }\n }\n }\n ... on TextMessageOutput {\n content @stream\n role\n parentMessageId\n }\n ... on ActionExecutionMessageOutput {\n name\n arguments @stream\n parentMessageId\n }\n ... on ResultMessageOutput {\n result\n actionExecutionId\n actionName\n }\n ... on AgentStateMessageOutput {\n threadId\n state\n running\n agentName\n nodeName\n runId\n active\n role\n }\n }\n }\n }\n": GenerateCopilotResponseDocument,
108
+ "\n query availableAgents {\n availableAgents {\n agents {\n name\n id\n description\n }\n }\n }\n": AvailableAgentsDocument
109
+ };
110
+ function graphql(source) {
111
+ return documents[source] ?? {};
112
+ }
113
+
114
+ // src/graphql/definitions/mutations.ts
115
+ var generateCopilotResponseMutation = graphql(
116
+ /** GraphQL **/
117
+ `
118
+ mutation generateCopilotResponse($data: GenerateCopilotResponseInput!, $properties: JSONObject) {
119
+ generateCopilotResponse(data: $data, properties: $properties) {
120
+ threadId
121
+ runId
122
+ ... on CopilotResponse @defer {
123
+ status {
124
+ ... on BaseResponseStatus {
125
+ code
126
+ }
127
+ ... on FailedResponseStatus {
128
+ reason
129
+ details
130
+ }
131
+ }
132
+ }
133
+ messages @stream {
134
+ __typename
135
+ ... on BaseMessageOutput {
136
+ id
137
+ createdAt
138
+ }
139
+ ... on BaseMessageOutput @defer {
140
+ status {
141
+ ... on SuccessMessageStatus {
142
+ code
143
+ }
144
+ ... on FailedMessageStatus {
145
+ code
146
+ reason
147
+ }
148
+ ... on PendingMessageStatus {
149
+ code
150
+ }
151
+ }
152
+ }
153
+ ... on TextMessageOutput {
154
+ content @stream
155
+ role
156
+ parentMessageId
157
+ }
158
+ ... on ActionExecutionMessageOutput {
159
+ name
160
+ arguments @stream
161
+ parentMessageId
162
+ }
163
+ ... on ResultMessageOutput {
164
+ result
165
+ actionExecutionId
166
+ actionName
167
+ }
168
+ ... on AgentStateMessageOutput {
169
+ threadId
170
+ state
171
+ running
172
+ agentName
173
+ nodeName
174
+ runId
175
+ active
176
+ role
177
+ }
178
+ }
179
+ }
180
+ }
181
+ `
182
+ );
183
+
184
+ // src/graphql/definitions/queries.ts
185
+ var getAvailableAgentsQuery = graphql(
186
+ /** GraphQL **/
187
+ `
188
+ query availableAgents {
189
+ availableAgents {
190
+ agents {
191
+ name
192
+ id
193
+ description
194
+ }
195
+ }
196
+ }
197
+ `
198
+ );
199
+
200
+ // src/client/CopilotRuntimeClient.ts
201
+ var createFetchFn = (signal) => async (...args) => {
202
+ const result = await fetch(args[0], { ...args[1] ?? {}, signal });
203
+ if (result.status !== 200) {
204
+ switch (result.status) {
205
+ case 404:
206
+ throw new Error(
207
+ "Runtime URL seems to be invalid - got 404 response. Please check the runtimeUrl passed to CopilotKit"
208
+ );
209
+ default:
210
+ throw new Error("Could not fetch copilot response");
211
+ }
212
+ }
213
+ return result;
214
+ };
215
+ var CopilotRuntimeClient = class {
216
+ constructor(options) {
217
+ const headers = {};
218
+ this.handleGQLErrors = options.handleGQLErrors;
219
+ if (options.headers) {
220
+ Object.assign(headers, options.headers);
221
+ }
222
+ if (options.publicApiKey) {
223
+ headers["x-copilotcloud-public-api-key"] = options.publicApiKey;
224
+ }
225
+ this.client = new import_core.Client({
226
+ url: options.url,
227
+ exchanges: [import_core.cacheExchange, import_core.fetchExchange],
228
+ fetchOptions: {
229
+ headers: {
230
+ ...headers,
231
+ "X-CopilotKit-Runtime-Client-GQL-Version": version
232
+ },
233
+ ...options.credentials ? { credentials: options.credentials } : {}
234
+ }
235
+ });
236
+ }
237
+ generateCopilotResponse({
238
+ data,
239
+ properties,
240
+ signal
241
+ }) {
242
+ const fetchFn = createFetchFn(signal);
243
+ const result = this.client.mutation(generateCopilotResponseMutation, { data, properties }, { fetch: fetchFn });
244
+ return result;
245
+ }
246
+ asStream(source) {
247
+ const handleGQLErrors = this.handleGQLErrors;
248
+ return new ReadableStream({
249
+ start(controller) {
250
+ source.subscribe(({ data, hasNext, error }) => {
251
+ if (error) {
252
+ controller.error(error);
253
+ if (handleGQLErrors) {
254
+ handleGQLErrors(error);
255
+ }
256
+ } else {
257
+ controller.enqueue(data);
258
+ if (!hasNext) {
259
+ controller.close();
260
+ }
261
+ }
262
+ });
263
+ }
264
+ });
265
+ }
266
+ availableAgents() {
267
+ const fetchFn = createFetchFn();
268
+ return this.client.query(getAvailableAgentsQuery, {}, { fetch: fetchFn });
269
+ }
270
+ };
271
+
272
+ // src/client/types.ts
273
+ var import_shared = require("@copilotkit/shared");
274
+ var Message = class {
275
+ constructor(props) {
276
+ props.id ?? (props.id = (0, import_shared.randomId)());
277
+ props.status ?? (props.status = { code: "Success" /* Success */ });
278
+ props.createdAt ?? (props.createdAt = /* @__PURE__ */ new Date());
279
+ Object.assign(this, props);
280
+ }
281
+ isTextMessage() {
282
+ return this.type === "TextMessage";
283
+ }
284
+ isActionExecutionMessage() {
285
+ return this.type === "ActionExecutionMessage";
286
+ }
287
+ isResultMessage() {
288
+ return this.type === "ResultMessage";
289
+ }
290
+ isAgentStateMessage() {
291
+ return this.type === "AgentStateMessage";
292
+ }
293
+ };
294
+ var Role = MessageRole;
295
+ var TextMessage = class extends Message {
296
+ constructor(props) {
297
+ super(props);
298
+ this.type = "TextMessage";
299
+ }
300
+ };
301
+ var ActionExecutionMessage = class extends Message {
302
+ constructor(props) {
303
+ super(props);
304
+ this.type = "ActionExecutionMessage";
305
+ }
306
+ };
307
+ var ResultMessage = class extends Message {
308
+ constructor(props) {
309
+ super(props);
310
+ this.type = "ResultMessage";
311
+ }
312
+ static decodeResult(result) {
313
+ try {
314
+ return JSON.parse(result);
315
+ } catch (e) {
316
+ return result;
317
+ }
318
+ }
319
+ static encodeResult(result) {
320
+ if (result === void 0) {
321
+ return "";
322
+ } else if (typeof result === "string") {
323
+ return result;
324
+ } else {
325
+ return JSON.stringify(result);
326
+ }
327
+ }
328
+ };
329
+ var AgentStateMessage = class extends Message {
330
+ constructor(props) {
331
+ super(props);
332
+ this.type = "AgentStateMessage";
333
+ }
334
+ };
335
+
336
+ // src/client/conversion.ts
337
+ var import_untruncate_json = __toESM(require("untruncate-json"));
338
+ function filterAgentStateMessages(messages) {
339
+ return messages.filter((message) => !message.isAgentStateMessage());
340
+ }
341
+ function convertMessagesToGqlInput(messages) {
342
+ return messages.map((message) => {
343
+ if (message.isTextMessage()) {
344
+ return {
345
+ id: message.id,
346
+ createdAt: message.createdAt,
347
+ textMessage: {
348
+ content: message.content,
349
+ role: message.role,
350
+ parentMessageId: message.parentMessageId
351
+ }
352
+ };
353
+ } else if (message.isActionExecutionMessage()) {
354
+ return {
355
+ id: message.id,
356
+ createdAt: message.createdAt,
357
+ actionExecutionMessage: {
358
+ name: message.name,
359
+ arguments: JSON.stringify(message.arguments),
360
+ parentMessageId: message.parentMessageId
361
+ }
362
+ };
363
+ } else if (message.isResultMessage()) {
364
+ return {
365
+ id: message.id,
366
+ createdAt: message.createdAt,
367
+ resultMessage: {
368
+ result: message.result,
369
+ actionExecutionId: message.actionExecutionId,
370
+ actionName: message.actionName
371
+ }
372
+ };
373
+ } else if (message.isAgentStateMessage()) {
374
+ return {
375
+ id: message.id,
376
+ createdAt: message.createdAt,
377
+ agentStateMessage: {
378
+ threadId: message.threadId,
379
+ role: message.role,
380
+ agentName: message.agentName,
381
+ nodeName: message.nodeName,
382
+ runId: message.runId,
383
+ active: message.active,
384
+ running: message.running,
385
+ state: JSON.stringify(message.state)
386
+ }
387
+ };
388
+ } else {
389
+ throw new Error("Unknown message type");
390
+ }
391
+ });
392
+ }
393
+ function filterAdjacentAgentStateMessages(messages) {
394
+ const filteredMessages = [];
395
+ messages.forEach((message, i) => {
396
+ if (message.__typename !== "AgentStateMessageOutput") {
397
+ filteredMessages.push(message);
398
+ } else {
399
+ const prevAgentStateMessageIndex = filteredMessages.findIndex(
400
+ // TODO: also check runId
401
+ (m) => m.__typename === "AgentStateMessageOutput" && m.agentName === message.agentName
402
+ );
403
+ if (prevAgentStateMessageIndex === -1) {
404
+ filteredMessages.push(message);
405
+ } else {
406
+ filteredMessages[prevAgentStateMessageIndex] = message;
407
+ }
408
+ }
409
+ });
410
+ return filteredMessages;
411
+ }
412
+ function convertGqlOutputToMessages(messages) {
413
+ return messages.map((message) => {
414
+ if (message.__typename === "TextMessageOutput") {
415
+ return new TextMessage({
416
+ id: message.id,
417
+ role: message.role,
418
+ content: message.content.join(""),
419
+ parentMessageId: message.parentMessageId,
420
+ createdAt: /* @__PURE__ */ new Date(),
421
+ status: message.status || { code: "Pending" /* Pending */ }
422
+ });
423
+ } else if (message.__typename === "ActionExecutionMessageOutput") {
424
+ return new ActionExecutionMessage({
425
+ id: message.id,
426
+ name: message.name,
427
+ arguments: getPartialArguments(message.arguments),
428
+ parentMessageId: message.parentMessageId,
429
+ createdAt: /* @__PURE__ */ new Date(),
430
+ status: message.status || { code: "Pending" /* Pending */ }
431
+ });
432
+ } else if (message.__typename === "ResultMessageOutput") {
433
+ return new ResultMessage({
434
+ id: message.id,
435
+ result: message.result,
436
+ actionExecutionId: message.actionExecutionId,
437
+ actionName: message.actionName,
438
+ createdAt: /* @__PURE__ */ new Date(),
439
+ status: message.status || { code: "Pending" /* Pending */ }
440
+ });
441
+ } else if (message.__typename === "AgentStateMessageOutput") {
442
+ return new AgentStateMessage({
443
+ id: message.id,
444
+ threadId: message.threadId,
445
+ role: message.role,
446
+ agentName: message.agentName,
447
+ nodeName: message.nodeName,
448
+ runId: message.runId,
449
+ active: message.active,
450
+ running: message.running,
451
+ state: JSON.parse(message.state),
452
+ createdAt: /* @__PURE__ */ new Date()
453
+ });
454
+ }
455
+ throw new Error("Unknown message type");
456
+ });
457
+ }
458
+ function loadMessagesFromJsonRepresentation(json) {
459
+ const result = [];
460
+ for (const item of json) {
461
+ if ("content" in item) {
462
+ result.push(
463
+ new TextMessage({
464
+ id: item.id,
465
+ role: item.role,
466
+ content: item.content,
467
+ parentMessageId: item.parentMessageId,
468
+ createdAt: item.createdAt || /* @__PURE__ */ new Date(),
469
+ status: item.status || { code: "Success" /* Success */ }
470
+ })
471
+ );
472
+ } else if ("arguments" in item) {
473
+ result.push(
474
+ new ActionExecutionMessage({
475
+ id: item.id,
476
+ name: item.name,
477
+ arguments: item.arguments,
478
+ parentMessageId: item.parentMessageId,
479
+ createdAt: item.createdAt || /* @__PURE__ */ new Date(),
480
+ status: item.status || { code: "Success" /* Success */ }
481
+ })
482
+ );
483
+ } else if ("result" in item) {
484
+ result.push(
485
+ new ResultMessage({
486
+ id: item.id,
487
+ result: item.result,
488
+ actionExecutionId: item.actionExecutionId,
489
+ actionName: item.actionName,
490
+ createdAt: item.createdAt || /* @__PURE__ */ new Date(),
491
+ status: item.status || { code: "Success" /* Success */ }
492
+ })
493
+ );
494
+ } else if ("state" in item) {
495
+ result.push(
496
+ new AgentStateMessage({
497
+ id: item.id,
498
+ threadId: item.threadId,
499
+ role: item.role,
500
+ agentName: item.agentName,
501
+ nodeName: item.nodeName,
502
+ runId: item.runId,
503
+ active: item.active,
504
+ running: item.running,
505
+ state: item.state,
506
+ createdAt: item.createdAt || /* @__PURE__ */ new Date()
507
+ })
508
+ );
509
+ }
510
+ }
511
+ return result;
512
+ }
513
+ function getPartialArguments(args) {
514
+ try {
515
+ return JSON.parse((0, import_untruncate_json.default)(args.join("")));
516
+ } catch (e) {
517
+ return {};
518
+ }
519
+ }
520
+ // Annotate the CommonJS export names for ESM import in node:
521
+ 0 && (module.exports = {
522
+ ActionExecutionMessage,
523
+ ActionInputAvailability,
524
+ AgentStateMessage,
525
+ AvailableAgentsDocument,
526
+ CopilotRequestType,
527
+ CopilotRuntimeClient,
528
+ FailedResponseStatusReason,
529
+ GenerateCopilotResponseDocument,
530
+ Message,
531
+ MessageRole,
532
+ MessageStatusCode,
533
+ ResponseStatusCode,
534
+ ResultMessage,
535
+ Role,
536
+ TextMessage,
537
+ convertGqlOutputToMessages,
538
+ convertMessagesToGqlInput,
539
+ filterAdjacentAgentStateMessages,
540
+ filterAgentStateMessages,
541
+ loadMessagesFromJsonRepresentation
542
+ });
543
+ //# sourceMappingURL=index.js.map