@copilotkit/runtime-client-gql 0.0.0-mme-load-agent-state-20250117154700

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