@copilotkit/runtime-client-gql 1.51.4 → 1.51.5-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 (176) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  3. package/dist/client/CopilotRuntimeClient.cjs +119 -0
  4. package/dist/client/CopilotRuntimeClient.cjs.map +1 -0
  5. package/dist/client/CopilotRuntimeClient.d.cts +44 -0
  6. package/dist/client/CopilotRuntimeClient.d.cts.map +1 -0
  7. package/dist/client/CopilotRuntimeClient.d.mts +44 -0
  8. package/dist/client/CopilotRuntimeClient.d.mts.map +1 -0
  9. package/dist/client/CopilotRuntimeClient.mjs +116 -10
  10. package/dist/client/CopilotRuntimeClient.mjs.map +1 -1
  11. package/dist/client/conversion.cjs +194 -0
  12. package/dist/client/conversion.cjs.map +1 -0
  13. package/dist/client/{conversion.d.ts → conversion.d.cts} +5 -4
  14. package/dist/client/conversion.d.cts.map +1 -0
  15. package/dist/client/conversion.d.mts +12 -0
  16. package/dist/client/conversion.d.mts.map +1 -0
  17. package/dist/client/conversion.mjs +187 -17
  18. package/dist/client/conversion.mjs.map +1 -1
  19. package/dist/client/index.d.cts +5 -0
  20. package/dist/client/index.d.mts +5 -0
  21. package/dist/client/types.cjs +86 -0
  22. package/dist/client/types.cjs.map +1 -0
  23. package/dist/client/types.d.cts +76 -0
  24. package/dist/client/types.d.cts.map +1 -0
  25. package/dist/client/types.d.mts +76 -0
  26. package/dist/client/types.d.mts.map +1 -0
  27. package/dist/client/types.mjs +76 -21
  28. package/dist/client/types.mjs.map +1 -1
  29. package/dist/graphql/@generated/gql.cjs +15 -0
  30. package/dist/graphql/@generated/gql.cjs.map +1 -0
  31. package/dist/graphql/@generated/gql.mjs +13 -7
  32. package/dist/graphql/@generated/gql.mjs.map +1 -1
  33. package/dist/graphql/@generated/graphql.cjs +1154 -0
  34. package/dist/graphql/@generated/graphql.cjs.map +1 -0
  35. package/dist/graphql/@generated/graphql.d.cts +642 -0
  36. package/dist/graphql/@generated/graphql.d.cts.map +1 -0
  37. package/dist/graphql/@generated/graphql.d.mts +642 -0
  38. package/dist/graphql/@generated/graphql.d.mts.map +1 -0
  39. package/dist/graphql/@generated/graphql.mjs +1142 -24
  40. package/dist/graphql/@generated/graphql.mjs.map +1 -1
  41. package/dist/{chunk-E5FOLXLN.mjs → graphql/definitions/mutations.cjs} +8 -11
  42. package/dist/graphql/definitions/mutations.cjs.map +1 -0
  43. package/dist/graphql/definitions/mutations.mjs +140 -9
  44. package/dist/graphql/definitions/mutations.mjs.map +1 -1
  45. package/dist/graphql/definitions/queries.cjs +35 -0
  46. package/dist/graphql/definitions/queries.cjs.map +1 -0
  47. package/dist/graphql/definitions/queries.mjs +33 -11
  48. package/dist/graphql/definitions/queries.mjs.map +1 -1
  49. package/dist/index.cjs +43 -0
  50. package/dist/index.d.cts +9 -0
  51. package/dist/index.d.mts +9 -0
  52. package/dist/index.mjs +8 -91
  53. package/dist/index.umd.js +2080 -2
  54. package/dist/index.umd.js.map +1 -1
  55. package/dist/message-conversion/agui-to-gql.cjs +162 -0
  56. package/dist/message-conversion/agui-to-gql.cjs.map +1 -0
  57. package/dist/message-conversion/{agui-to-gql.d.ts → agui-to-gql.d.cts} +6 -5
  58. package/dist/message-conversion/agui-to-gql.d.cts.map +1 -0
  59. package/dist/message-conversion/agui-to-gql.d.mts +14 -0
  60. package/dist/message-conversion/agui-to-gql.d.mts.map +1 -0
  61. package/dist/message-conversion/agui-to-gql.mjs +156 -25
  62. package/dist/message-conversion/agui-to-gql.mjs.map +1 -1
  63. package/dist/message-conversion/gql-to-agui.cjs +169 -0
  64. package/dist/message-conversion/gql-to-agui.cjs.map +1 -0
  65. package/dist/message-conversion/{gql-to-agui.d.ts → gql-to-agui.d.cts} +6 -5
  66. package/dist/message-conversion/gql-to-agui.d.cts.map +1 -0
  67. package/dist/message-conversion/gql-to-agui.d.mts +13 -0
  68. package/dist/message-conversion/gql-to-agui.d.mts.map +1 -0
  69. package/dist/message-conversion/gql-to-agui.mjs +164 -23
  70. package/dist/message-conversion/gql-to-agui.mjs.map +1 -1
  71. package/dist/message-conversion/index.d.cts +2 -0
  72. package/dist/message-conversion/index.d.mts +2 -0
  73. package/dist/package.cjs +12 -0
  74. package/dist/package.cjs.map +1 -0
  75. package/dist/package.mjs +6 -0
  76. package/dist/package.mjs.map +1 -0
  77. package/package.json +15 -15
  78. package/src/message-conversion/agui-to-gql.test.ts +70 -0
  79. package/src/message-conversion/agui-to-gql.ts +4 -0
  80. package/tsdown.config.ts +49 -0
  81. package/vitest.config.mjs +11 -0
  82. package/dist/chunk-2XWNDVTL.mjs +0 -176
  83. package/dist/chunk-2XWNDVTL.mjs.map +0 -1
  84. package/dist/chunk-7ECCT6PK.mjs +0 -1
  85. package/dist/chunk-7ECCT6PK.mjs.map +0 -1
  86. package/dist/chunk-A4INSSNE.mjs +0 -17722
  87. package/dist/chunk-A4INSSNE.mjs.map +0 -1
  88. package/dist/chunk-CA4VMP2C.mjs +0 -1
  89. package/dist/chunk-CA4VMP2C.mjs.map +0 -1
  90. package/dist/chunk-DELDZXUX.mjs +0 -31
  91. package/dist/chunk-DELDZXUX.mjs.map +0 -1
  92. package/dist/chunk-E5FOLXLN.mjs.map +0 -1
  93. package/dist/chunk-LTVE64IE.mjs +0 -241
  94. package/dist/chunk-LTVE64IE.mjs.map +0 -1
  95. package/dist/chunk-M4CK5HDR.mjs +0 -237
  96. package/dist/chunk-M4CK5HDR.mjs.map +0 -1
  97. package/dist/chunk-OBDQ5BWD.mjs +0 -63
  98. package/dist/chunk-OBDQ5BWD.mjs.map +0 -1
  99. package/dist/chunk-QUH7QWUA.mjs +0 -38
  100. package/dist/chunk-QUH7QWUA.mjs.map +0 -1
  101. package/dist/chunk-SDQPJXLL.mjs +0 -20
  102. package/dist/chunk-SDQPJXLL.mjs.map +0 -1
  103. package/dist/chunk-UOAPP5IN.mjs +0 -93
  104. package/dist/chunk-UOAPP5IN.mjs.map +0 -1
  105. package/dist/chunk-VIHKTLUA.mjs +0 -221
  106. package/dist/chunk-VIHKTLUA.mjs.map +0 -1
  107. package/dist/chunk-XZPL6QVK.mjs +0 -24
  108. package/dist/chunk-XZPL6QVK.mjs.map +0 -1
  109. package/dist/client/CopilotRuntimeClient.d.ts +0 -39
  110. package/dist/client/CopilotRuntimeClient.js +0 -366
  111. package/dist/client/CopilotRuntimeClient.js.map +0 -1
  112. package/dist/client/conversion.js +0 -339
  113. package/dist/client/conversion.js.map +0 -1
  114. package/dist/client/index.d.ts +0 -8
  115. package/dist/client/index.js +0 -711
  116. package/dist/client/index.js.map +0 -1
  117. package/dist/client/index.mjs +0 -43
  118. package/dist/client/index.mjs.map +0 -1
  119. package/dist/client/types.d.ts +0 -75
  120. package/dist/client/types.js +0 -132
  121. package/dist/client/types.js.map +0 -1
  122. package/dist/graphql/@generated/fragment-masking.d.ts +0 -22
  123. package/dist/graphql/@generated/fragment-masking.js +0 -50
  124. package/dist/graphql/@generated/fragment-masking.js.map +0 -1
  125. package/dist/graphql/@generated/fragment-masking.mjs +0 -12
  126. package/dist/graphql/@generated/fragment-masking.mjs.map +0 -1
  127. package/dist/graphql/@generated/gql.d.ts +0 -48
  128. package/dist/graphql/@generated/gql.js +0 -45
  129. package/dist/graphql/@generated/gql.js.map +0 -1
  130. package/dist/graphql/@generated/graphql.d.ts +0 -655
  131. package/dist/graphql/@generated/graphql.js +0 -96
  132. package/dist/graphql/@generated/graphql.js.map +0 -1
  133. package/dist/graphql/@generated/index.d.ts +0 -4
  134. package/dist/graphql/@generated/index.js +0 -69
  135. package/dist/graphql/@generated/index.js.map +0 -1
  136. package/dist/graphql/@generated/index.mjs +0 -17
  137. package/dist/graphql/@generated/index.mjs.map +0 -1
  138. package/dist/graphql/definitions/mutations.d.ts +0 -9
  139. package/dist/graphql/definitions/mutations.js +0 -181
  140. package/dist/graphql/definitions/mutations.js.map +0 -1
  141. package/dist/graphql/definitions/queries.d.ts +0 -11
  142. package/dist/graphql/definitions/queries.js +0 -76
  143. package/dist/graphql/definitions/queries.js.map +0 -1
  144. package/dist/index.d.ts +0 -11
  145. package/dist/index.js +0 -1222
  146. package/dist/index.js.map +0 -1
  147. package/dist/index.mjs.map +0 -1
  148. package/dist/magic-string.es-XBKSJO3K.mjs +0 -1389
  149. package/dist/magic-string.es-XBKSJO3K.mjs.map +0 -1
  150. package/dist/message-conversion/agui-to-gql.js +0 -344
  151. package/dist/message-conversion/agui-to-gql.js.map +0 -1
  152. package/dist/message-conversion/agui-to-gql.test.d.ts +0 -2
  153. package/dist/message-conversion/agui-to-gql.test.js +0 -20553
  154. package/dist/message-conversion/agui-to-gql.test.js.map +0 -1
  155. package/dist/message-conversion/agui-to-gql.test.mjs +0 -1137
  156. package/dist/message-conversion/agui-to-gql.test.mjs.map +0 -1
  157. package/dist/message-conversion/gql-to-agui.js +0 -262
  158. package/dist/message-conversion/gql-to-agui.js.map +0 -1
  159. package/dist/message-conversion/gql-to-agui.test.d.ts +0 -2
  160. package/dist/message-conversion/gql-to-agui.test.js +0 -20850
  161. package/dist/message-conversion/gql-to-agui.test.js.map +0 -1
  162. package/dist/message-conversion/gql-to-agui.test.mjs +0 -1447
  163. package/dist/message-conversion/gql-to-agui.test.mjs.map +0 -1
  164. package/dist/message-conversion/index.d.ts +0 -6
  165. package/dist/message-conversion/index.js +0 -563
  166. package/dist/message-conversion/index.js.map +0 -1
  167. package/dist/message-conversion/index.mjs +0 -39
  168. package/dist/message-conversion/index.mjs.map +0 -1
  169. package/dist/message-conversion/roundtrip-conversion.test.d.ts +0 -2
  170. package/dist/message-conversion/roundtrip-conversion.test.js +0 -20095
  171. package/dist/message-conversion/roundtrip-conversion.test.js.map +0 -1
  172. package/dist/message-conversion/roundtrip-conversion.test.mjs +0 -489
  173. package/dist/message-conversion/roundtrip-conversion.test.mjs.map +0 -1
  174. package/jest.config.js +0 -5
  175. package/rollup.config.mjs +0 -62
  176. package/tsup.config.ts +0 -12
package/dist/index.js DELETED
@@ -1,1222 +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
- AvailableAgentsDocument: () => AvailableAgentsDocument,
37
- CopilotRequestType: () => CopilotRequestType,
38
- CopilotRuntimeClient: () => CopilotRuntimeClient,
39
- FailedResponseStatusReason: () => FailedResponseStatusReason,
40
- GenerateCopilotResponseDocument: () => GenerateCopilotResponseDocument,
41
- ImageMessage: () => ImageMessage,
42
- LoadAgentStateDocument: () => LoadAgentStateDocument,
43
- Message: () => Message,
44
- MessageRole: () => MessageRole,
45
- MessageStatusCode: () => MessageStatusCode,
46
- MetaEventName: () => MetaEventName,
47
- ResponseStatusCode: () => ResponseStatusCode,
48
- ResultMessage: () => ResultMessage,
49
- Role: () => Role,
50
- TextMessage: () => TextMessage,
51
- aguiMessageWithImageToGQLMessage: () => aguiMessageWithImageToGQLMessage,
52
- aguiMessageWithRenderToGQL: () => aguiMessageWithRenderToGQL,
53
- aguiTextMessageToGQLMessage: () => aguiTextMessageToGQLMessage,
54
- aguiToGQL: () => aguiToGQL,
55
- aguiToolCallToGQLActionExecution: () => aguiToolCallToGQLActionExecution,
56
- aguiToolMessageToGQLResultMessage: () => aguiToolMessageToGQLResultMessage,
57
- convertGqlOutputToMessages: () => convertGqlOutputToMessages,
58
- convertMessagesToGqlInput: () => convertMessagesToGqlInput,
59
- filterAdjacentAgentStateMessages: () => filterAdjacentAgentStateMessages,
60
- filterAgentStateMessages: () => filterAgentStateMessages,
61
- gqlActionExecutionMessageToAGUIMessage: () => gqlActionExecutionMessageToAGUIMessage,
62
- gqlImageMessageToAGUIMessage: () => gqlImageMessageToAGUIMessage,
63
- gqlResultMessageToAGUIMessage: () => gqlResultMessageToAGUIMessage,
64
- gqlTextMessageToAGUIMessage: () => gqlTextMessageToAGUIMessage,
65
- gqlToAGUI: () => gqlToAGUI,
66
- langGraphInterruptEvent: () => langGraphInterruptEvent,
67
- loadMessagesFromJsonRepresentation: () => loadMessagesFromJsonRepresentation
68
- });
69
- module.exports = __toCommonJS(src_exports);
70
-
71
- // src/client/CopilotRuntimeClient.ts
72
- var import_core = require("@urql/core");
73
-
74
- // package.json
75
- var version = "1.51.4";
76
-
77
- // src/graphql/@generated/graphql.ts
78
- var ActionInputAvailability = /* @__PURE__ */ ((ActionInputAvailability2) => {
79
- ActionInputAvailability2["Disabled"] = "disabled";
80
- ActionInputAvailability2["Enabled"] = "enabled";
81
- ActionInputAvailability2["Remote"] = "remote";
82
- return ActionInputAvailability2;
83
- })(ActionInputAvailability || {});
84
- var CopilotRequestType = /* @__PURE__ */ ((CopilotRequestType2) => {
85
- CopilotRequestType2["Chat"] = "Chat";
86
- CopilotRequestType2["Suggestion"] = "Suggestion";
87
- CopilotRequestType2["Task"] = "Task";
88
- CopilotRequestType2["TextareaCompletion"] = "TextareaCompletion";
89
- CopilotRequestType2["TextareaPopover"] = "TextareaPopover";
90
- return CopilotRequestType2;
91
- })(CopilotRequestType || {});
92
- var FailedResponseStatusReason = /* @__PURE__ */ ((FailedResponseStatusReason2) => {
93
- FailedResponseStatusReason2["GuardrailsValidationFailed"] = "GUARDRAILS_VALIDATION_FAILED";
94
- FailedResponseStatusReason2["MessageStreamInterrupted"] = "MESSAGE_STREAM_INTERRUPTED";
95
- FailedResponseStatusReason2["UnknownError"] = "UNKNOWN_ERROR";
96
- return FailedResponseStatusReason2;
97
- })(FailedResponseStatusReason || {});
98
- var MessageRole = /* @__PURE__ */ ((MessageRole2) => {
99
- MessageRole2["Assistant"] = "assistant";
100
- MessageRole2["Developer"] = "developer";
101
- MessageRole2["System"] = "system";
102
- MessageRole2["Tool"] = "tool";
103
- MessageRole2["User"] = "user";
104
- return MessageRole2;
105
- })(MessageRole || {});
106
- var MessageStatusCode = /* @__PURE__ */ ((MessageStatusCode2) => {
107
- MessageStatusCode2["Failed"] = "Failed";
108
- MessageStatusCode2["Pending"] = "Pending";
109
- MessageStatusCode2["Success"] = "Success";
110
- return MessageStatusCode2;
111
- })(MessageStatusCode || {});
112
- var MetaEventName = /* @__PURE__ */ ((MetaEventName2) => {
113
- MetaEventName2["CopilotKitLangGraphInterruptEvent"] = "CopilotKitLangGraphInterruptEvent";
114
- MetaEventName2["LangGraphInterruptEvent"] = "LangGraphInterruptEvent";
115
- return MetaEventName2;
116
- })(MetaEventName || {});
117
- var ResponseStatusCode = /* @__PURE__ */ ((ResponseStatusCode2) => {
118
- ResponseStatusCode2["Failed"] = "Failed";
119
- ResponseStatusCode2["Pending"] = "Pending";
120
- ResponseStatusCode2["Success"] = "Success";
121
- return ResponseStatusCode2;
122
- })(ResponseStatusCode || {});
123
- 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": "Field", "name": { "kind": "Name", "value": "extensions" }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "openaiAssistantAPI" }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "runId" } }, { "kind": "Field", "name": { "kind": "Name", "value": "threadId" } }] } }] } }, { "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": "ImageMessageOutput" } }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "format" } }, { "kind": "Field", "name": { "kind": "Name", "value": "bytes" } }, { "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" } }] } }] } }, { "kind": "Field", "name": { "kind": "Name", "value": "metaEvents" }, "directives": [{ "kind": "Directive", "name": { "kind": "Name", "value": "stream" } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "InlineFragment", "typeCondition": { "kind": "NamedType", "name": { "kind": "Name", "value": "LangGraphInterruptEvent" } }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "type" } }, { "kind": "Field", "name": { "kind": "Name", "value": "name" } }, { "kind": "Field", "name": { "kind": "Name", "value": "value" } }] } }, { "kind": "InlineFragment", "typeCondition": { "kind": "NamedType", "name": { "kind": "Name", "value": "CopilotKitLangGraphInterruptEvent" } }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "type" } }, { "kind": "Field", "name": { "kind": "Name", "value": "name" } }, { "kind": "Field", "name": { "kind": "Name", "value": "data" }, "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "messages" }, "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" } }, { "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" } }, { "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": "Field", "name": { "kind": "Name", "value": "value" } }] } }] } }] } }] } }] } }] };
124
- 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" } }] } }] } }] } }] };
125
- var LoadAgentStateDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "query", "name": { "kind": "Name", "value": "loadAgentState" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "data" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "LoadAgentStateInput" } } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "loadAgentState" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "data" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "data" } } }], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "threadId" } }, { "kind": "Field", "name": { "kind": "Name", "value": "threadExists" } }, { "kind": "Field", "name": { "kind": "Name", "value": "state" } }, { "kind": "Field", "name": { "kind": "Name", "value": "messages" } }] } }] } }] };
126
-
127
- // src/graphql/@generated/gql.ts
128
- var documents = {
129
- "\n mutation generateCopilotResponse(\n $data: GenerateCopilotResponseInput!\n $properties: JSONObject\n ) {\n generateCopilotResponse(data: $data, properties: $properties) {\n threadId\n runId\n extensions {\n openaiAssistantAPI {\n runId\n threadId\n }\n }\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 ImageMessageOutput {\n format\n bytes\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 metaEvents @stream {\n ... on LangGraphInterruptEvent {\n type\n name\n value\n }\n\n ... on CopilotKitLangGraphInterruptEvent {\n type\n name\n data {\n messages {\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\n role\n parentMessageId\n }\n ... on ActionExecutionMessageOutput {\n name\n arguments\n parentMessageId\n }\n ... on ResultMessageOutput {\n result\n actionExecutionId\n actionName\n }\n }\n value\n }\n }\n }\n }\n }\n": GenerateCopilotResponseDocument,
130
- "\n query availableAgents {\n availableAgents {\n agents {\n name\n id\n description\n }\n }\n }\n": AvailableAgentsDocument,
131
- "\n query loadAgentState($data: LoadAgentStateInput!) {\n loadAgentState(data: $data) {\n threadId\n threadExists\n state\n messages\n }\n }\n": LoadAgentStateDocument
132
- };
133
- function graphql(source) {
134
- return documents[source] ?? {};
135
- }
136
-
137
- // src/graphql/definitions/mutations.ts
138
- var generateCopilotResponseMutation = graphql(
139
- /** GraphQL **/
140
- `
141
- mutation generateCopilotResponse(
142
- $data: GenerateCopilotResponseInput!
143
- $properties: JSONObject
144
- ) {
145
- generateCopilotResponse(data: $data, properties: $properties) {
146
- threadId
147
- runId
148
- extensions {
149
- openaiAssistantAPI {
150
- runId
151
- threadId
152
- }
153
- }
154
- ... on CopilotResponse @defer {
155
- status {
156
- ... on BaseResponseStatus {
157
- code
158
- }
159
- ... on FailedResponseStatus {
160
- reason
161
- details
162
- }
163
- }
164
- }
165
- messages @stream {
166
- __typename
167
- ... on BaseMessageOutput {
168
- id
169
- createdAt
170
- }
171
- ... on BaseMessageOutput @defer {
172
- status {
173
- ... on SuccessMessageStatus {
174
- code
175
- }
176
- ... on FailedMessageStatus {
177
- code
178
- reason
179
- }
180
- ... on PendingMessageStatus {
181
- code
182
- }
183
- }
184
- }
185
- ... on TextMessageOutput {
186
- content @stream
187
- role
188
- parentMessageId
189
- }
190
- ... on ImageMessageOutput {
191
- format
192
- bytes
193
- role
194
- parentMessageId
195
- }
196
- ... on ActionExecutionMessageOutput {
197
- name
198
- arguments @stream
199
- parentMessageId
200
- }
201
- ... on ResultMessageOutput {
202
- result
203
- actionExecutionId
204
- actionName
205
- }
206
- ... on AgentStateMessageOutput {
207
- threadId
208
- state
209
- running
210
- agentName
211
- nodeName
212
- runId
213
- active
214
- role
215
- }
216
- }
217
- metaEvents @stream {
218
- ... on LangGraphInterruptEvent {
219
- type
220
- name
221
- value
222
- }
223
-
224
- ... on CopilotKitLangGraphInterruptEvent {
225
- type
226
- name
227
- data {
228
- messages {
229
- __typename
230
- ... on BaseMessageOutput {
231
- id
232
- createdAt
233
- }
234
- ... on BaseMessageOutput @defer {
235
- status {
236
- ... on SuccessMessageStatus {
237
- code
238
- }
239
- ... on FailedMessageStatus {
240
- code
241
- reason
242
- }
243
- ... on PendingMessageStatus {
244
- code
245
- }
246
- }
247
- }
248
- ... on TextMessageOutput {
249
- content
250
- role
251
- parentMessageId
252
- }
253
- ... on ActionExecutionMessageOutput {
254
- name
255
- arguments
256
- parentMessageId
257
- }
258
- ... on ResultMessageOutput {
259
- result
260
- actionExecutionId
261
- actionName
262
- }
263
- }
264
- value
265
- }
266
- }
267
- }
268
- }
269
- }
270
- `
271
- );
272
-
273
- // src/graphql/definitions/queries.ts
274
- var getAvailableAgentsQuery = graphql(
275
- /** GraphQL **/
276
- `
277
- query availableAgents {
278
- availableAgents {
279
- agents {
280
- name
281
- id
282
- description
283
- }
284
- }
285
- }
286
- `
287
- );
288
- var loadAgentStateQuery = graphql(
289
- /** GraphQL **/
290
- `
291
- query loadAgentState($data: LoadAgentStateInput!) {
292
- loadAgentState(data: $data) {
293
- threadId
294
- threadExists
295
- state
296
- messages
297
- }
298
- }
299
- `
300
- );
301
-
302
- // src/client/CopilotRuntimeClient.ts
303
- var import_shared = require("@copilotkit/shared");
304
- var createFetchFn = (signal, handleGQLWarning) => async (...args) => {
305
- var _a, _b;
306
- const publicApiKey = (_b = (_a = args[1]) == null ? void 0 : _a.headers) == null ? void 0 : _b["x-copilotcloud-public-api-key"];
307
- try {
308
- const result = await fetch(args[0], { ...args[1] ?? {}, signal });
309
- const mismatch = publicApiKey ? null : await (0, import_shared.getPossibleVersionMismatch)({
310
- runtimeVersion: result.headers.get("X-CopilotKit-Runtime-Version"),
311
- runtimeClientGqlVersion: version
312
- });
313
- if (result.status !== 200) {
314
- if (result.status >= 400 && result.status <= 500) {
315
- if (mismatch) {
316
- throw new import_shared.CopilotKitVersionMismatchError(mismatch);
317
- }
318
- throw new import_shared.ResolvedCopilotKitError({ status: result.status });
319
- }
320
- }
321
- if (mismatch && handleGQLWarning) {
322
- handleGQLWarning(mismatch.message);
323
- }
324
- return result;
325
- } catch (error) {
326
- if (error.message.includes("BodyStreamBuffer was aborted") || error.message.includes("signal is aborted without reason")) {
327
- throw error;
328
- }
329
- if (error instanceof import_shared.CopilotKitError) {
330
- throw error;
331
- }
332
- throw new import_shared.CopilotKitLowLevelError({
333
- error,
334
- url: args[0]
335
- });
336
- }
337
- };
338
- var CopilotRuntimeClient = class {
339
- constructor(options) {
340
- const headers = {};
341
- this.handleGQLErrors = options.handleGQLErrors;
342
- this.handleGQLWarning = options.handleGQLWarning;
343
- if (options.headers) {
344
- Object.assign(headers, options.headers);
345
- }
346
- if (options.publicApiKey) {
347
- headers["x-copilotcloud-public-api-key"] = options.publicApiKey;
348
- }
349
- this.client = new import_core.Client({
350
- url: options.url,
351
- exchanges: [import_core.cacheExchange, import_core.fetchExchange],
352
- fetchOptions: {
353
- headers: {
354
- ...headers,
355
- "X-CopilotKit-Runtime-Client-GQL-Version": version
356
- },
357
- ...options.credentials ? { credentials: options.credentials } : {}
358
- }
359
- });
360
- }
361
- generateCopilotResponse({
362
- data,
363
- properties,
364
- signal
365
- }) {
366
- const fetchFn = createFetchFn(signal, this.handleGQLWarning);
367
- const result = this.client.mutation(
368
- generateCopilotResponseMutation,
369
- { data, properties },
370
- { fetch: fetchFn }
371
- );
372
- return result;
373
- }
374
- asStream(source) {
375
- const handleGQLErrors = this.handleGQLErrors;
376
- return new ReadableStream({
377
- start(controller) {
378
- source.subscribe(({ data, hasNext, error }) => {
379
- var _a;
380
- if (error) {
381
- if (error.message.includes("BodyStreamBuffer was aborted") || error.message.includes("signal is aborted without reason")) {
382
- if (!hasNext)
383
- controller.close();
384
- console.warn("Abort error suppressed");
385
- return;
386
- }
387
- if ((_a = error.extensions) == null ? void 0 : _a.visibility) {
388
- const syntheticError = {
389
- ...error,
390
- graphQLErrors: [
391
- {
392
- message: error.message,
393
- extensions: error.extensions
394
- }
395
- ]
396
- };
397
- if (handleGQLErrors) {
398
- handleGQLErrors(syntheticError);
399
- }
400
- return;
401
- }
402
- controller.error(error);
403
- if (handleGQLErrors) {
404
- handleGQLErrors(error);
405
- }
406
- } else {
407
- controller.enqueue(data);
408
- if (!hasNext) {
409
- controller.close();
410
- }
411
- }
412
- });
413
- }
414
- });
415
- }
416
- availableAgents() {
417
- const fetchFn = createFetchFn();
418
- return this.client.query(
419
- getAvailableAgentsQuery,
420
- {},
421
- { fetch: fetchFn }
422
- );
423
- }
424
- loadAgentState(data) {
425
- const fetchFn = createFetchFn();
426
- const result = this.client.query(
427
- loadAgentStateQuery,
428
- { data },
429
- { fetch: fetchFn }
430
- );
431
- result.toPromise().then(({ error }) => {
432
- if (error && this.handleGQLErrors) {
433
- this.handleGQLErrors(error);
434
- }
435
- }).catch(() => {
436
- });
437
- return result;
438
- }
439
- static removeGraphQLTypename(data) {
440
- if (Array.isArray(data)) {
441
- data.forEach((item) => CopilotRuntimeClient.removeGraphQLTypename(item));
442
- } else if (typeof data === "object" && data !== null) {
443
- delete data.__typename;
444
- Object.keys(data).forEach((key) => {
445
- if (typeof data[key] === "object" && data[key] !== null) {
446
- CopilotRuntimeClient.removeGraphQLTypename(data[key]);
447
- }
448
- });
449
- }
450
- return data;
451
- }
452
- };
453
-
454
- // src/client/types.ts
455
- var import_shared2 = require("@copilotkit/shared");
456
- var import_shared3 = require("@copilotkit/shared");
457
- var Message = class {
458
- constructor(props) {
459
- props.id ?? (props.id = (0, import_shared2.randomId)());
460
- props.status ?? (props.status = { code: "Success" /* Success */ });
461
- props.createdAt ?? (props.createdAt = /* @__PURE__ */ new Date());
462
- Object.assign(this, props);
463
- }
464
- isTextMessage() {
465
- return this.type === "TextMessage";
466
- }
467
- isActionExecutionMessage() {
468
- return this.type === "ActionExecutionMessage";
469
- }
470
- isResultMessage() {
471
- return this.type === "ResultMessage";
472
- }
473
- isAgentStateMessage() {
474
- return this.type === "AgentStateMessage";
475
- }
476
- isImageMessage() {
477
- return this.type === "ImageMessage";
478
- }
479
- };
480
- var Role = MessageRole;
481
- var TextMessage = class extends Message {
482
- constructor(props) {
483
- super(props);
484
- this.type = "TextMessage";
485
- this.type = "TextMessage";
486
- }
487
- };
488
- var ActionExecutionMessage = class extends Message {
489
- constructor(props) {
490
- super(props);
491
- this.type = "ActionExecutionMessage";
492
- }
493
- };
494
- var ResultMessage = class extends Message {
495
- constructor(props) {
496
- super(props);
497
- this.type = "ResultMessage";
498
- }
499
- static decodeResult(result) {
500
- return (0, import_shared3.parseJson)(result, result);
501
- }
502
- static encodeResult(result) {
503
- if (result === void 0) {
504
- return "";
505
- } else if (typeof result === "string") {
506
- return result;
507
- } else {
508
- return JSON.stringify(result);
509
- }
510
- }
511
- };
512
- var AgentStateMessage = class extends Message {
513
- constructor(props) {
514
- super(props);
515
- this.type = "AgentStateMessage";
516
- }
517
- };
518
- var ImageMessage = class extends Message {
519
- constructor(props) {
520
- super(props);
521
- this.type = "ImageMessage";
522
- }
523
- };
524
- function langGraphInterruptEvent(eventProps) {
525
- return {
526
- ...eventProps,
527
- name: "LangGraphInterruptEvent" /* LangGraphInterruptEvent */,
528
- type: "MetaEvent"
529
- };
530
- }
531
-
532
- // src/client/conversion.ts
533
- var import_untruncate_json = __toESM(require("untruncate-json"));
534
- var import_shared4 = require("@copilotkit/shared");
535
- function filterAgentStateMessages(messages) {
536
- return messages.filter((message) => !message.isAgentStateMessage());
537
- }
538
- function convertMessagesToGqlInput(messages) {
539
- return messages.map((message) => {
540
- if (message.isTextMessage()) {
541
- return {
542
- id: message.id,
543
- createdAt: message.createdAt,
544
- textMessage: {
545
- content: message.content,
546
- role: message.role,
547
- parentMessageId: message.parentMessageId
548
- }
549
- };
550
- } else if (message.isActionExecutionMessage()) {
551
- return {
552
- id: message.id,
553
- createdAt: message.createdAt,
554
- actionExecutionMessage: {
555
- name: message.name,
556
- arguments: JSON.stringify(message.arguments),
557
- parentMessageId: message.parentMessageId
558
- }
559
- };
560
- } else if (message.isResultMessage()) {
561
- return {
562
- id: message.id,
563
- createdAt: message.createdAt,
564
- resultMessage: {
565
- result: message.result,
566
- actionExecutionId: message.actionExecutionId,
567
- actionName: message.actionName
568
- }
569
- };
570
- } else if (message.isAgentStateMessage()) {
571
- return {
572
- id: message.id,
573
- createdAt: message.createdAt,
574
- agentStateMessage: {
575
- threadId: message.threadId,
576
- role: message.role,
577
- agentName: message.agentName,
578
- nodeName: message.nodeName,
579
- runId: message.runId,
580
- active: message.active,
581
- running: message.running,
582
- state: JSON.stringify(message.state)
583
- }
584
- };
585
- } else if (message.isImageMessage()) {
586
- return {
587
- id: message.id,
588
- createdAt: message.createdAt,
589
- imageMessage: {
590
- format: message.format,
591
- bytes: message.bytes,
592
- role: message.role,
593
- parentMessageId: message.parentMessageId
594
- }
595
- };
596
- } else {
597
- throw new Error("Unknown message type");
598
- }
599
- });
600
- }
601
- function filterAdjacentAgentStateMessages(messages) {
602
- const filteredMessages = [];
603
- messages.forEach((message, i) => {
604
- if (message.__typename !== "AgentStateMessageOutput") {
605
- filteredMessages.push(message);
606
- } else {
607
- const prevAgentStateMessageIndex = filteredMessages.findIndex(
608
- // TODO: also check runId
609
- (m) => m.__typename === "AgentStateMessageOutput" && m.agentName === message.agentName
610
- );
611
- if (prevAgentStateMessageIndex === -1) {
612
- filteredMessages.push(message);
613
- } else {
614
- filteredMessages[prevAgentStateMessageIndex] = message;
615
- }
616
- }
617
- });
618
- return filteredMessages;
619
- }
620
- function convertGqlOutputToMessages(messages) {
621
- return messages.map((message) => {
622
- if (message.__typename === "TextMessageOutput") {
623
- return new TextMessage({
624
- id: message.id,
625
- role: message.role,
626
- content: message.content.join(""),
627
- parentMessageId: message.parentMessageId,
628
- createdAt: /* @__PURE__ */ new Date(),
629
- status: message.status || { code: "Pending" /* Pending */ }
630
- });
631
- } else if (message.__typename === "ActionExecutionMessageOutput") {
632
- return new ActionExecutionMessage({
633
- id: message.id,
634
- name: message.name,
635
- arguments: getPartialArguments(message.arguments),
636
- parentMessageId: message.parentMessageId,
637
- createdAt: /* @__PURE__ */ new Date(),
638
- status: message.status || { code: "Pending" /* Pending */ }
639
- });
640
- } else if (message.__typename === "ResultMessageOutput") {
641
- return new ResultMessage({
642
- id: message.id,
643
- result: message.result,
644
- actionExecutionId: message.actionExecutionId,
645
- actionName: message.actionName,
646
- createdAt: /* @__PURE__ */ new Date(),
647
- status: message.status || { code: "Pending" /* Pending */ }
648
- });
649
- } else if (message.__typename === "AgentStateMessageOutput") {
650
- return new AgentStateMessage({
651
- id: message.id,
652
- threadId: message.threadId,
653
- role: message.role,
654
- agentName: message.agentName,
655
- nodeName: message.nodeName,
656
- runId: message.runId,
657
- active: message.active,
658
- running: message.running,
659
- state: (0, import_shared4.parseJson)(message.state, {}),
660
- createdAt: /* @__PURE__ */ new Date()
661
- });
662
- } else if (message.__typename === "ImageMessageOutput") {
663
- return new ImageMessage({
664
- id: message.id,
665
- format: message.format,
666
- bytes: message.bytes,
667
- role: message.role,
668
- parentMessageId: message.parentMessageId,
669
- createdAt: /* @__PURE__ */ new Date(),
670
- status: message.status || { code: "Pending" /* Pending */ }
671
- });
672
- }
673
- throw new Error("Unknown message type");
674
- });
675
- }
676
- function loadMessagesFromJsonRepresentation(json) {
677
- const result = [];
678
- for (const item of json) {
679
- if ("content" in item) {
680
- result.push(
681
- new TextMessage({
682
- id: item.id,
683
- role: item.role,
684
- content: item.content,
685
- parentMessageId: item.parentMessageId,
686
- createdAt: item.createdAt || /* @__PURE__ */ new Date(),
687
- status: item.status || { code: "Success" /* Success */ }
688
- })
689
- );
690
- } else if ("arguments" in item) {
691
- result.push(
692
- new ActionExecutionMessage({
693
- id: item.id,
694
- name: item.name,
695
- arguments: item.arguments,
696
- parentMessageId: item.parentMessageId,
697
- createdAt: item.createdAt || /* @__PURE__ */ new Date(),
698
- status: item.status || { code: "Success" /* Success */ }
699
- })
700
- );
701
- } else if ("result" in item) {
702
- result.push(
703
- new ResultMessage({
704
- id: item.id,
705
- result: item.result,
706
- actionExecutionId: item.actionExecutionId,
707
- actionName: item.actionName,
708
- createdAt: item.createdAt || /* @__PURE__ */ new Date(),
709
- status: item.status || { code: "Success" /* Success */ }
710
- })
711
- );
712
- } else if ("state" in item) {
713
- result.push(
714
- new AgentStateMessage({
715
- id: item.id,
716
- threadId: item.threadId,
717
- role: item.role,
718
- agentName: item.agentName,
719
- nodeName: item.nodeName,
720
- runId: item.runId,
721
- active: item.active,
722
- running: item.running,
723
- state: item.state,
724
- createdAt: item.createdAt || /* @__PURE__ */ new Date()
725
- })
726
- );
727
- } else if ("format" in item && "bytes" in item) {
728
- result.push(
729
- new ImageMessage({
730
- id: item.id,
731
- format: item.format,
732
- bytes: item.bytes,
733
- role: item.role,
734
- parentMessageId: item.parentMessageId,
735
- createdAt: item.createdAt || /* @__PURE__ */ new Date(),
736
- status: item.status || { code: "Success" /* Success */ }
737
- })
738
- );
739
- }
740
- }
741
- return result;
742
- }
743
- function getPartialArguments(args) {
744
- try {
745
- if (!args.length)
746
- return {};
747
- return JSON.parse((0, import_untruncate_json.default)(args.join("")));
748
- } catch (e) {
749
- return {};
750
- }
751
- }
752
-
753
- // src/message-conversion/agui-to-gql.ts
754
- function extractAgentName(message) {
755
- if (message.role !== "assistant") {
756
- throw new Error(
757
- `Cannot extract agent name from message with role ${message.role}`
758
- );
759
- }
760
- return message.agentName || "unknown";
761
- }
762
- function isAgentStateMessage(message) {
763
- return message.role === "assistant" && "agentName" in message && "state" in message;
764
- }
765
- function hasImageProperty(message) {
766
- const canContainImage = message.role === "assistant" || message.role === "user";
767
- if (!canContainImage || message.image === void 0) {
768
- return false;
769
- }
770
- const isMalformed = message.image.format === void 0 || message.image.bytes === void 0;
771
- if (isMalformed) {
772
- return false;
773
- }
774
- return true;
775
- }
776
- function aguiToGQL(messages, actions, coAgentStateRenders) {
777
- const gqlMessages = [];
778
- messages = Array.isArray(messages) ? messages : [messages];
779
- const toolCallNames = {};
780
- for (const message of messages) {
781
- if (isAgentStateMessage(message)) {
782
- const agentName = extractAgentName(message);
783
- const state = "state" in message && message.state ? message.state : {};
784
- gqlMessages.push(
785
- new AgentStateMessage({
786
- id: message.id,
787
- agentName,
788
- state,
789
- role: Role.Assistant
790
- })
791
- );
792
- if ("generativeUI" in message && message.generativeUI && coAgentStateRenders) {
793
- coAgentStateRenders[agentName] = {
794
- name: agentName,
795
- render: message.generativeUI
796
- };
797
- }
798
- continue;
799
- }
800
- if (hasImageProperty(message)) {
801
- gqlMessages.push(aguiMessageWithImageToGQLMessage(message));
802
- continue;
803
- }
804
- if (message.role === "assistant" && message.toolCalls) {
805
- gqlMessages.push(aguiTextMessageToGQLMessage(message));
806
- for (const toolCall of message.toolCalls) {
807
- toolCallNames[toolCall.id] = toolCall.function.name;
808
- const actionExecMsg = aguiToolCallToGQLActionExecution(
809
- toolCall,
810
- message.id
811
- );
812
- if ("generativeUI" in message && message.generativeUI && actions) {
813
- const actionName = toolCall.function.name;
814
- const specificAction = Object.values(actions).find(
815
- (action) => action.name === actionName
816
- );
817
- const wildcardAction = Object.values(actions).find(
818
- (action) => action.name === "*"
819
- );
820
- if (specificAction) {
821
- specificAction.render = message.generativeUI;
822
- } else if (wildcardAction) {
823
- wildcardAction.render = message.generativeUI;
824
- }
825
- }
826
- gqlMessages.push(actionExecMsg);
827
- }
828
- continue;
829
- }
830
- if (message.role === "developer" || message.role === "system" || message.role === "assistant" || message.role === "user") {
831
- gqlMessages.push(aguiTextMessageToGQLMessage(message));
832
- continue;
833
- }
834
- if (message.role === "tool") {
835
- gqlMessages.push(
836
- aguiToolMessageToGQLResultMessage(message, toolCallNames)
837
- );
838
- continue;
839
- }
840
- throw new Error(
841
- `Unknown message role: "${message.role}" in message with id: ${message.id}`
842
- );
843
- }
844
- return gqlMessages;
845
- }
846
- function aguiTextMessageToGQLMessage(message) {
847
- if (message.role !== "developer" && message.role !== "system" && message.role !== "assistant" && message.role !== "user") {
848
- throw new Error(
849
- `Cannot convert message with role ${message.role} to TextMessage`
850
- );
851
- }
852
- let roleValue;
853
- if (message.role === "developer") {
854
- roleValue = Role.Developer;
855
- } else if (message.role === "system") {
856
- roleValue = Role.System;
857
- } else if (message.role === "assistant") {
858
- roleValue = Role.Assistant;
859
- } else {
860
- roleValue = Role.User;
861
- }
862
- return new TextMessage({
863
- id: message.id,
864
- content: message.content || "",
865
- role: roleValue
866
- });
867
- }
868
- function aguiToolCallToGQLActionExecution(toolCall, parentMessageId) {
869
- if (toolCall.type !== "function") {
870
- throw new Error(`Unsupported tool call type: ${toolCall.type}`);
871
- }
872
- let argumentsObj;
873
- if (typeof toolCall.function.arguments === "string") {
874
- try {
875
- argumentsObj = JSON.parse(toolCall.function.arguments);
876
- } catch (error) {
877
- console.warn(
878
- `Failed to parse tool call arguments for ${toolCall.function.name}:`,
879
- error
880
- );
881
- argumentsObj = {};
882
- }
883
- } else if (typeof toolCall.function.arguments === "object" && toolCall.function.arguments !== null) {
884
- argumentsObj = toolCall.function.arguments;
885
- } else {
886
- console.warn(
887
- `Invalid tool call arguments type for ${toolCall.function.name}:`,
888
- typeof toolCall.function.arguments
889
- );
890
- argumentsObj = {};
891
- }
892
- return new ActionExecutionMessage({
893
- id: toolCall.id,
894
- name: toolCall.function.name,
895
- arguments: argumentsObj,
896
- parentMessageId
897
- });
898
- }
899
- function aguiToolMessageToGQLResultMessage(message, toolCallNames) {
900
- if (message.role !== "tool") {
901
- throw new Error(
902
- `Cannot convert message with role ${message.role} to ResultMessage`
903
- );
904
- }
905
- if (!message.toolCallId) {
906
- throw new Error("Tool message must have a toolCallId");
907
- }
908
- const actionName = toolCallNames[message.toolCallId] || "unknown";
909
- let resultContent;
910
- const messageContent = message.content || "";
911
- if (typeof messageContent === "string") {
912
- resultContent = messageContent;
913
- } else if (typeof messageContent === "object" && messageContent !== null) {
914
- try {
915
- resultContent = JSON.stringify(messageContent);
916
- } catch (error) {
917
- console.warn(`Failed to stringify tool result for ${actionName}:`, error);
918
- resultContent = String(messageContent);
919
- }
920
- } else {
921
- resultContent = String(messageContent);
922
- }
923
- return new ResultMessage({
924
- id: message.id,
925
- result: resultContent,
926
- actionExecutionId: message.toolCallId,
927
- actionName: message.toolName || actionName
928
- });
929
- }
930
- function aguiMessageWithRenderToGQL(message, actions, coAgentStateRenders) {
931
- if (message.role === "assistant" && "generativeUI" in message && message.generativeUI && !message.toolCalls) {
932
- const gqlMessages = [];
933
- gqlMessages.push(
934
- new AgentStateMessage({
935
- id: message.id,
936
- agentName: "unknown",
937
- state: {},
938
- role: Role.Assistant
939
- })
940
- );
941
- if (coAgentStateRenders) {
942
- coAgentStateRenders.unknown = {
943
- name: "unknown",
944
- render: message.generativeUI
945
- };
946
- }
947
- return gqlMessages;
948
- }
949
- return aguiToGQL([message], actions, coAgentStateRenders);
950
- }
951
- function aguiMessageWithImageToGQLMessage(message) {
952
- if (!hasImageProperty(message)) {
953
- throw new Error(
954
- `Cannot convert message to ImageMessage: missing format or bytes`
955
- );
956
- }
957
- let roleValue;
958
- if (message.role === "assistant") {
959
- roleValue = Role.Assistant;
960
- } else {
961
- roleValue = Role.User;
962
- }
963
- if (message.role !== "assistant" && message.role !== "user") {
964
- throw new Error(
965
- `Cannot convert message with role ${message.role} to ImageMessage`
966
- );
967
- }
968
- return new ImageMessage({
969
- id: message.id,
970
- format: message.image.format,
971
- bytes: message.image.bytes,
972
- role: roleValue
973
- });
974
- }
975
-
976
- // src/message-conversion/gql-to-agui.ts
977
- var VALID_IMAGE_FORMATS = ["jpeg", "png", "webp", "gif"];
978
- function validateImageFormat(format) {
979
- return VALID_IMAGE_FORMATS.includes(format);
980
- }
981
- function gqlToAGUI(messages, actions, coAgentStateRenders) {
982
- let aguiMessages = [];
983
- messages = Array.isArray(messages) ? messages : [messages];
984
- const actionResults = /* @__PURE__ */ new Map();
985
- for (const message of messages) {
986
- if (message.isResultMessage()) {
987
- actionResults.set(message.actionExecutionId, message.result);
988
- }
989
- }
990
- for (const message of messages) {
991
- if (message.isTextMessage()) {
992
- aguiMessages.push(gqlTextMessageToAGUIMessage(message));
993
- } else if (message.isResultMessage()) {
994
- aguiMessages.push(gqlResultMessageToAGUIMessage(message));
995
- } else if (message.isActionExecutionMessage()) {
996
- aguiMessages.push(
997
- gqlActionExecutionMessageToAGUIMessage(message, actions, actionResults)
998
- );
999
- } else if (message.isAgentStateMessage()) {
1000
- aguiMessages.push(
1001
- gqlAgentStateMessageToAGUIMessage(message, coAgentStateRenders)
1002
- );
1003
- } else if (message.isImageMessage()) {
1004
- aguiMessages.push(gqlImageMessageToAGUIMessage(message));
1005
- } else {
1006
- throw new Error("Unknown message type");
1007
- }
1008
- }
1009
- return aguiMessages;
1010
- }
1011
- function gqlActionExecutionMessageToAGUIMessage(message, actions, actionResults) {
1012
- const hasSpecificAction = actions && Object.values(actions).some((action2) => action2.name === message.name);
1013
- const hasWildcardAction = actions && Object.values(actions).some((action2) => action2.name === "*");
1014
- if (!actions || !hasSpecificAction && !hasWildcardAction) {
1015
- return {
1016
- id: message.id,
1017
- role: "assistant",
1018
- toolCalls: [actionExecutionMessageToAGUIMessage(message)],
1019
- name: message.name
1020
- };
1021
- }
1022
- const action = Object.values(actions).find(
1023
- (action2) => action2.name === message.name
1024
- ) || Object.values(actions).find((action2) => action2.name === "*");
1025
- const createRenderWrapper = (originalRender) => {
1026
- if (!originalRender)
1027
- return void 0;
1028
- return (props) => {
1029
- var _a;
1030
- let actionResult = actionResults == null ? void 0 : actionResults.get(message.id);
1031
- let status = "inProgress";
1032
- if (actionResult !== void 0) {
1033
- status = "complete";
1034
- } else if (((_a = message.status) == null ? void 0 : _a.code) !== "Pending" /* Pending */) {
1035
- status = "executing";
1036
- }
1037
- if (typeof (props == null ? void 0 : props.result) === "string") {
1038
- try {
1039
- props.result = JSON.parse(props.result);
1040
- } catch (e) {
1041
- }
1042
- }
1043
- if (typeof actionResult === "string") {
1044
- try {
1045
- actionResult = JSON.parse(actionResult);
1046
- } catch (e) {
1047
- }
1048
- }
1049
- const baseProps = {
1050
- status: (props == null ? void 0 : props.status) || status,
1051
- args: message.arguments || {},
1052
- result: (props == null ? void 0 : props.result) || actionResult || void 0,
1053
- messageId: message.id
1054
- };
1055
- if (action.name === "*") {
1056
- return originalRender({
1057
- ...baseProps,
1058
- ...props,
1059
- name: message.name
1060
- });
1061
- } else {
1062
- const respond = (props == null ? void 0 : props.respond) ?? (() => {
1063
- });
1064
- return originalRender({
1065
- ...baseProps,
1066
- ...props,
1067
- respond
1068
- });
1069
- }
1070
- };
1071
- };
1072
- return {
1073
- id: message.id,
1074
- role: "assistant",
1075
- content: "",
1076
- toolCalls: [actionExecutionMessageToAGUIMessage(message)],
1077
- generativeUI: createRenderWrapper(action.render),
1078
- name: message.name
1079
- };
1080
- }
1081
- function gqlAgentStateMessageToAGUIMessage(message, coAgentStateRenders) {
1082
- if (coAgentStateRenders && Object.values(coAgentStateRenders).some(
1083
- (render) => render.name === message.agentName
1084
- )) {
1085
- const render = Object.values(coAgentStateRenders).find(
1086
- (render2) => render2.name === message.agentName
1087
- );
1088
- const createRenderWrapper = (originalRender) => {
1089
- if (!originalRender)
1090
- return void 0;
1091
- return (props) => {
1092
- const state = message.state;
1093
- const renderProps = {
1094
- state
1095
- };
1096
- return originalRender(renderProps);
1097
- };
1098
- };
1099
- return {
1100
- id: message.id,
1101
- role: "assistant",
1102
- generativeUI: createRenderWrapper(render.render),
1103
- agentName: message.agentName,
1104
- state: message.state
1105
- };
1106
- }
1107
- return {
1108
- id: message.id,
1109
- role: "assistant",
1110
- agentName: message.agentName,
1111
- state: message.state
1112
- };
1113
- }
1114
- function actionExecutionMessageToAGUIMessage(actionExecutionMessage) {
1115
- return {
1116
- id: actionExecutionMessage.id,
1117
- function: {
1118
- name: actionExecutionMessage.name,
1119
- arguments: JSON.stringify(actionExecutionMessage.arguments)
1120
- },
1121
- type: "function"
1122
- };
1123
- }
1124
- function gqlTextMessageToAGUIMessage(message) {
1125
- switch (message.role) {
1126
- case Role.Developer:
1127
- return {
1128
- id: message.id,
1129
- role: "developer",
1130
- content: message.content
1131
- };
1132
- case Role.System:
1133
- return {
1134
- id: message.id,
1135
- role: "system",
1136
- content: message.content
1137
- };
1138
- case Role.Assistant:
1139
- return {
1140
- id: message.id,
1141
- role: "assistant",
1142
- content: message.content
1143
- };
1144
- case Role.User:
1145
- return {
1146
- id: message.id,
1147
- role: "user",
1148
- content: message.content
1149
- };
1150
- default:
1151
- throw new Error("Unknown message role");
1152
- }
1153
- }
1154
- function gqlResultMessageToAGUIMessage(message) {
1155
- return {
1156
- id: message.id,
1157
- role: "tool",
1158
- content: message.result,
1159
- toolCallId: message.actionExecutionId,
1160
- toolName: message.actionName
1161
- };
1162
- }
1163
- function gqlImageMessageToAGUIMessage(message) {
1164
- if (!validateImageFormat(message.format)) {
1165
- throw new Error(
1166
- `Invalid image format: ${message.format}. Supported formats are: ${VALID_IMAGE_FORMATS.join(", ")}`
1167
- );
1168
- }
1169
- if (!message.bytes || typeof message.bytes !== "string" || message.bytes.trim() === "") {
1170
- throw new Error("Image bytes must be a non-empty string");
1171
- }
1172
- const role = message.role === Role.Assistant ? "assistant" : "user";
1173
- const imageMessage = {
1174
- id: message.id,
1175
- role,
1176
- content: "",
1177
- image: {
1178
- format: message.format,
1179
- bytes: message.bytes
1180
- }
1181
- };
1182
- return imageMessage;
1183
- }
1184
- // Annotate the CommonJS export names for ESM import in node:
1185
- 0 && (module.exports = {
1186
- ActionExecutionMessage,
1187
- ActionInputAvailability,
1188
- AgentStateMessage,
1189
- AvailableAgentsDocument,
1190
- CopilotRequestType,
1191
- CopilotRuntimeClient,
1192
- FailedResponseStatusReason,
1193
- GenerateCopilotResponseDocument,
1194
- ImageMessage,
1195
- LoadAgentStateDocument,
1196
- Message,
1197
- MessageRole,
1198
- MessageStatusCode,
1199
- MetaEventName,
1200
- ResponseStatusCode,
1201
- ResultMessage,
1202
- Role,
1203
- TextMessage,
1204
- aguiMessageWithImageToGQLMessage,
1205
- aguiMessageWithRenderToGQL,
1206
- aguiTextMessageToGQLMessage,
1207
- aguiToGQL,
1208
- aguiToolCallToGQLActionExecution,
1209
- aguiToolMessageToGQLResultMessage,
1210
- convertGqlOutputToMessages,
1211
- convertMessagesToGqlInput,
1212
- filterAdjacentAgentStateMessages,
1213
- filterAgentStateMessages,
1214
- gqlActionExecutionMessageToAGUIMessage,
1215
- gqlImageMessageToAGUIMessage,
1216
- gqlResultMessageToAGUIMessage,
1217
- gqlTextMessageToAGUIMessage,
1218
- gqlToAGUI,
1219
- langGraphInterruptEvent,
1220
- loadMessagesFromJsonRepresentation
1221
- });
1222
- //# sourceMappingURL=index.js.map