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