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