2089 lines
64 KiB
JavaScript
2089 lines
64 KiB
JavaScript
(function(global, factory) {
|
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@urql/core'), require('@copilotkit/shared'), require('untruncate-json')) :
|
|
typeof define === 'function' && define.amd ? define(['exports', '@urql/core', '@copilotkit/shared', 'untruncate-json'], factory) :
|
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CopilotKitRuntimeClientGQL = {}), global.UrqlCore,global.CopilotKitShared,global.untruncateJson));
|
|
})(this, function(exports, _urql_core, _copilotkit_shared, untruncate_json) {
|
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
//#region \0rolldown/runtime.js
|
|
var __create = Object.create;
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __getProtoOf = Object.getPrototypeOf;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
key = keys[i];
|
|
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
__defProp(to, key, {
|
|
get: ((k) => from[k]).bind(null, key),
|
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
});
|
|
}
|
|
}
|
|
}
|
|
return to;
|
|
};
|
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
value: mod,
|
|
enumerable: true
|
|
}) : target, mod));
|
|
|
|
//#endregion
|
|
untruncate_json = __toESM(untruncate_json);
|
|
|
|
//#region package.json
|
|
var version = "1.54.0";
|
|
|
|
//#endregion
|
|
//#region src/graphql/@generated/graphql.ts
|
|
/** The availability of the frontend action */
|
|
let ActionInputAvailability = /* @__PURE__ */ function(ActionInputAvailability) {
|
|
ActionInputAvailability["Disabled"] = "disabled";
|
|
ActionInputAvailability["Enabled"] = "enabled";
|
|
ActionInputAvailability["Remote"] = "remote";
|
|
return ActionInputAvailability;
|
|
}({});
|
|
/** The type of Copilot request */
|
|
let CopilotRequestType = /* @__PURE__ */ function(CopilotRequestType) {
|
|
CopilotRequestType["Chat"] = "Chat";
|
|
CopilotRequestType["Suggestion"] = "Suggestion";
|
|
CopilotRequestType["Task"] = "Task";
|
|
CopilotRequestType["TextareaCompletion"] = "TextareaCompletion";
|
|
CopilotRequestType["TextareaPopover"] = "TextareaPopover";
|
|
return CopilotRequestType;
|
|
}({});
|
|
let FailedResponseStatusReason = /* @__PURE__ */ function(FailedResponseStatusReason) {
|
|
FailedResponseStatusReason["GuardrailsValidationFailed"] = "GUARDRAILS_VALIDATION_FAILED";
|
|
FailedResponseStatusReason["MessageStreamInterrupted"] = "MESSAGE_STREAM_INTERRUPTED";
|
|
FailedResponseStatusReason["UnknownError"] = "UNKNOWN_ERROR";
|
|
return FailedResponseStatusReason;
|
|
}({});
|
|
/** The role of the message */
|
|
let MessageRole = /* @__PURE__ */ function(MessageRole) {
|
|
MessageRole["Assistant"] = "assistant";
|
|
MessageRole["Developer"] = "developer";
|
|
MessageRole["System"] = "system";
|
|
MessageRole["Tool"] = "tool";
|
|
MessageRole["User"] = "user";
|
|
return MessageRole;
|
|
}({});
|
|
let MessageStatusCode = /* @__PURE__ */ function(MessageStatusCode) {
|
|
MessageStatusCode["Failed"] = "Failed";
|
|
MessageStatusCode["Pending"] = "Pending";
|
|
MessageStatusCode["Success"] = "Success";
|
|
return MessageStatusCode;
|
|
}({});
|
|
/** Meta event types */
|
|
let MetaEventName = /* @__PURE__ */ function(MetaEventName) {
|
|
MetaEventName["CopilotKitLangGraphInterruptEvent"] = "CopilotKitLangGraphInterruptEvent";
|
|
MetaEventName["LangGraphInterruptEvent"] = "LangGraphInterruptEvent";
|
|
return MetaEventName;
|
|
}({});
|
|
let ResponseStatusCode = /* @__PURE__ */ function(ResponseStatusCode) {
|
|
ResponseStatusCode["Failed"] = "Failed";
|
|
ResponseStatusCode["Pending"] = "Pending";
|
|
ResponseStatusCode["Success"] = "Success";
|
|
return ResponseStatusCode;
|
|
}({});
|
|
const 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"
|
|
}
|
|
}]
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}]
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}]
|
|
}
|
|
}]
|
|
};
|
|
const 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"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}]
|
|
}
|
|
}]
|
|
}
|
|
}]
|
|
};
|
|
const 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"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}]
|
|
}
|
|
}]
|
|
};
|
|
|
|
//#endregion
|
|
//#region src/graphql/@generated/gql.ts
|
|
const documents = {
|
|
"\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,
|
|
"\n query availableAgents {\n availableAgents {\n agents {\n name\n id\n description\n }\n }\n }\n": AvailableAgentsDocument,
|
|
"\n query loadAgentState($data: LoadAgentStateInput!) {\n loadAgentState(data: $data) {\n threadId\n threadExists\n state\n messages\n }\n }\n": LoadAgentStateDocument
|
|
};
|
|
function graphql(source) {
|
|
var _source;
|
|
return (_source = documents[source]) !== null && _source !== void 0 ? _source : {};
|
|
}
|
|
|
|
//#endregion
|
|
//#region src/graphql/definitions/mutations.ts
|
|
const generateCopilotResponseMutation = graphql(
|
|
/** GraphQL **/
|
|
`
|
|
mutation generateCopilotResponse(
|
|
$data: GenerateCopilotResponseInput!
|
|
$properties: JSONObject
|
|
) {
|
|
generateCopilotResponse(data: $data, properties: $properties) {
|
|
threadId
|
|
runId
|
|
extensions {
|
|
openaiAssistantAPI {
|
|
runId
|
|
threadId
|
|
}
|
|
}
|
|
... on CopilotResponse @defer {
|
|
status {
|
|
... on BaseResponseStatus {
|
|
code
|
|
}
|
|
... on FailedResponseStatus {
|
|
reason
|
|
details
|
|
}
|
|
}
|
|
}
|
|
messages @stream {
|
|
__typename
|
|
... on BaseMessageOutput {
|
|
id
|
|
createdAt
|
|
}
|
|
... on BaseMessageOutput @defer {
|
|
status {
|
|
... on SuccessMessageStatus {
|
|
code
|
|
}
|
|
... on FailedMessageStatus {
|
|
code
|
|
reason
|
|
}
|
|
... on PendingMessageStatus {
|
|
code
|
|
}
|
|
}
|
|
}
|
|
... on TextMessageOutput {
|
|
content @stream
|
|
role
|
|
parentMessageId
|
|
}
|
|
... on ImageMessageOutput {
|
|
format
|
|
bytes
|
|
role
|
|
parentMessageId
|
|
}
|
|
... on ActionExecutionMessageOutput {
|
|
name
|
|
arguments @stream
|
|
parentMessageId
|
|
}
|
|
... on ResultMessageOutput {
|
|
result
|
|
actionExecutionId
|
|
actionName
|
|
}
|
|
... on AgentStateMessageOutput {
|
|
threadId
|
|
state
|
|
running
|
|
agentName
|
|
nodeName
|
|
runId
|
|
active
|
|
role
|
|
}
|
|
}
|
|
metaEvents @stream {
|
|
... on LangGraphInterruptEvent {
|
|
type
|
|
name
|
|
value
|
|
}
|
|
|
|
... on CopilotKitLangGraphInterruptEvent {
|
|
type
|
|
name
|
|
data {
|
|
messages {
|
|
__typename
|
|
... on BaseMessageOutput {
|
|
id
|
|
createdAt
|
|
}
|
|
... on BaseMessageOutput @defer {
|
|
status {
|
|
... on SuccessMessageStatus {
|
|
code
|
|
}
|
|
... on FailedMessageStatus {
|
|
code
|
|
reason
|
|
}
|
|
... on PendingMessageStatus {
|
|
code
|
|
}
|
|
}
|
|
}
|
|
... on TextMessageOutput {
|
|
content
|
|
role
|
|
parentMessageId
|
|
}
|
|
... on ActionExecutionMessageOutput {
|
|
name
|
|
arguments
|
|
parentMessageId
|
|
}
|
|
... on ResultMessageOutput {
|
|
result
|
|
actionExecutionId
|
|
actionName
|
|
}
|
|
}
|
|
value
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`
|
|
);
|
|
|
|
//#endregion
|
|
//#region src/graphql/definitions/queries.ts
|
|
const getAvailableAgentsQuery = graphql(
|
|
/** GraphQL **/
|
|
`
|
|
query availableAgents {
|
|
availableAgents {
|
|
agents {
|
|
name
|
|
id
|
|
description
|
|
}
|
|
}
|
|
}
|
|
`
|
|
);
|
|
const loadAgentStateQuery = graphql(
|
|
/** GraphQL **/
|
|
`
|
|
query loadAgentState($data: LoadAgentStateInput!) {
|
|
loadAgentState(data: $data) {
|
|
threadId
|
|
threadExists
|
|
state
|
|
messages
|
|
}
|
|
}
|
|
`
|
|
);
|
|
|
|
//#endregion
|
|
//#region src/client/CopilotRuntimeClient.ts
|
|
const createFetchFn = (signal, handleGQLWarning) => async (...args) => {
|
|
var _args$;
|
|
const publicApiKey = (_args$ = args[1]) === null || _args$ === void 0 || (_args$ = _args$.headers) === null || _args$ === void 0 ? void 0 : _args$["x-copilotcloud-public-api-key"];
|
|
try {
|
|
var _args$2;
|
|
const result = await fetch(args[0], {
|
|
...(_args$2 = args[1]) !== null && _args$2 !== void 0 ? _args$2 : {},
|
|
signal
|
|
});
|
|
const mismatch = publicApiKey ? null : await (0, _copilotkit_shared.getPossibleVersionMismatch)({
|
|
runtimeVersion: result.headers.get("X-CopilotKit-Runtime-Version"),
|
|
runtimeClientGqlVersion: version
|
|
});
|
|
if (result.status !== 200) {
|
|
if (result.status >= 400 && result.status <= 500) {
|
|
if (mismatch) throw new _copilotkit_shared.CopilotKitVersionMismatchError(mismatch);
|
|
throw new _copilotkit_shared.ResolvedCopilotKitError({ status: result.status });
|
|
}
|
|
}
|
|
if (mismatch && handleGQLWarning) handleGQLWarning(mismatch.message);
|
|
return result;
|
|
} catch (error) {
|
|
if (error.message.includes("BodyStreamBuffer was aborted") || error.message.includes("signal is aborted without reason")) throw error;
|
|
if (error instanceof _copilotkit_shared.CopilotKitError) throw error;
|
|
throw new _copilotkit_shared.CopilotKitLowLevelError({
|
|
error,
|
|
url: args[0]
|
|
});
|
|
}
|
|
};
|
|
var CopilotRuntimeClient = class CopilotRuntimeClient {
|
|
constructor(options) {
|
|
const headers = {};
|
|
this.handleGQLErrors = options.handleGQLErrors;
|
|
this.handleGQLWarning = options.handleGQLWarning;
|
|
if (options.headers) Object.assign(headers, options.headers);
|
|
if (options.publicApiKey) headers["x-copilotcloud-public-api-key"] = options.publicApiKey;
|
|
this.client = new _urql_core.Client({
|
|
url: options.url,
|
|
exchanges: [_urql_core.cacheExchange, _urql_core.fetchExchange],
|
|
fetchOptions: {
|
|
headers: {
|
|
...headers,
|
|
"X-CopilotKit-Runtime-Client-GQL-Version": version
|
|
},
|
|
...options.credentials ? { credentials: options.credentials } : {}
|
|
}
|
|
});
|
|
}
|
|
generateCopilotResponse({ data, properties, signal }) {
|
|
const fetchFn = createFetchFn(signal, this.handleGQLWarning);
|
|
return this.client.mutation(generateCopilotResponseMutation, {
|
|
data,
|
|
properties
|
|
}, { fetch: fetchFn });
|
|
}
|
|
asStream(source) {
|
|
const handleGQLErrors = this.handleGQLErrors;
|
|
return new ReadableStream({ start(controller) {
|
|
source.subscribe(({ data, hasNext, error }) => {
|
|
if (error) {
|
|
var _extensions;
|
|
if (error.message.includes("BodyStreamBuffer was aborted") || error.message.includes("signal is aborted without reason")) {
|
|
if (!hasNext) controller.close();
|
|
console.warn("Abort error suppressed");
|
|
return;
|
|
}
|
|
if ((_extensions = error.extensions) === null || _extensions === void 0 ? void 0 : _extensions.visibility) {
|
|
const syntheticError = {
|
|
...error,
|
|
graphQLErrors: [{
|
|
message: error.message,
|
|
extensions: error.extensions
|
|
}]
|
|
};
|
|
if (handleGQLErrors) handleGQLErrors(syntheticError);
|
|
return;
|
|
}
|
|
controller.error(error);
|
|
if (handleGQLErrors) handleGQLErrors(error);
|
|
} else {
|
|
controller.enqueue(data);
|
|
if (!hasNext) controller.close();
|
|
}
|
|
});
|
|
} });
|
|
}
|
|
availableAgents() {
|
|
const fetchFn = createFetchFn();
|
|
return this.client.query(getAvailableAgentsQuery, {}, { fetch: fetchFn });
|
|
}
|
|
loadAgentState(data) {
|
|
const fetchFn = createFetchFn();
|
|
const result = this.client.query(loadAgentStateQuery, { data }, { fetch: fetchFn });
|
|
result.toPromise().then(({ error }) => {
|
|
if (error && this.handleGQLErrors) this.handleGQLErrors(error);
|
|
}).catch(() => {});
|
|
return result;
|
|
}
|
|
static removeGraphQLTypename(data) {
|
|
if (Array.isArray(data)) data.forEach((item) => CopilotRuntimeClient.removeGraphQLTypename(item));
|
|
else if (typeof data === "object" && data !== null) {
|
|
delete data.__typename;
|
|
Object.keys(data).forEach((key) => {
|
|
if (typeof data[key] === "object" && data[key] !== null) CopilotRuntimeClient.removeGraphQLTypename(data[key]);
|
|
});
|
|
}
|
|
return data;
|
|
}
|
|
};
|
|
|
|
//#endregion
|
|
//#region src/client/types.ts
|
|
var Message = class {
|
|
constructor(props) {
|
|
var _props$id, _props$status, _props$createdAt;
|
|
(_props$id = props.id) !== null && _props$id !== void 0 || (props.id = (0, _copilotkit_shared.randomId)());
|
|
(_props$status = props.status) !== null && _props$status !== void 0 || (props.status = { code: MessageStatusCode.Success });
|
|
(_props$createdAt = props.createdAt) !== null && _props$createdAt !== void 0 || (props.createdAt = /* @__PURE__ */ new Date());
|
|
Object.assign(this, props);
|
|
}
|
|
isTextMessage() {
|
|
return this.type === "TextMessage";
|
|
}
|
|
isActionExecutionMessage() {
|
|
return this.type === "ActionExecutionMessage";
|
|
}
|
|
isResultMessage() {
|
|
return this.type === "ResultMessage";
|
|
}
|
|
isAgentStateMessage() {
|
|
return this.type === "AgentStateMessage";
|
|
}
|
|
isImageMessage() {
|
|
return this.type === "ImageMessage";
|
|
}
|
|
};
|
|
const Role = MessageRole;
|
|
var TextMessage = class extends Message {
|
|
constructor(props) {
|
|
super(props);
|
|
this.type = "TextMessage";
|
|
this.type = "TextMessage";
|
|
}
|
|
};
|
|
var ActionExecutionMessage = class extends Message {
|
|
constructor(props) {
|
|
super(props);
|
|
this.type = "ActionExecutionMessage";
|
|
}
|
|
};
|
|
var ResultMessage = class extends Message {
|
|
constructor(props) {
|
|
super(props);
|
|
this.type = "ResultMessage";
|
|
}
|
|
static decodeResult(result) {
|
|
return (0, _copilotkit_shared.parseJson)(result, result);
|
|
}
|
|
static encodeResult(result) {
|
|
if (result === void 0) return "";
|
|
else if (typeof result === "string") return result;
|
|
else return JSON.stringify(result);
|
|
}
|
|
};
|
|
var AgentStateMessage = class extends Message {
|
|
constructor(props) {
|
|
super(props);
|
|
this.type = "AgentStateMessage";
|
|
}
|
|
};
|
|
var ImageMessage = class extends Message {
|
|
constructor(props) {
|
|
super(props);
|
|
this.type = "ImageMessage";
|
|
}
|
|
};
|
|
function langGraphInterruptEvent(eventProps) {
|
|
return {
|
|
...eventProps,
|
|
name: MetaEventName.LangGraphInterruptEvent,
|
|
type: "MetaEvent"
|
|
};
|
|
}
|
|
|
|
//#endregion
|
|
//#region src/client/conversion.ts
|
|
function filterAgentStateMessages(messages) {
|
|
return messages.filter((message) => !message.isAgentStateMessage());
|
|
}
|
|
function convertMessagesToGqlInput(messages) {
|
|
return messages.map((message) => {
|
|
if (message.isTextMessage()) return {
|
|
id: message.id,
|
|
createdAt: message.createdAt,
|
|
textMessage: {
|
|
content: message.content,
|
|
role: message.role,
|
|
parentMessageId: message.parentMessageId
|
|
}
|
|
};
|
|
else if (message.isActionExecutionMessage()) return {
|
|
id: message.id,
|
|
createdAt: message.createdAt,
|
|
actionExecutionMessage: {
|
|
name: message.name,
|
|
arguments: JSON.stringify(message.arguments),
|
|
parentMessageId: message.parentMessageId
|
|
}
|
|
};
|
|
else if (message.isResultMessage()) return {
|
|
id: message.id,
|
|
createdAt: message.createdAt,
|
|
resultMessage: {
|
|
result: message.result,
|
|
actionExecutionId: message.actionExecutionId,
|
|
actionName: message.actionName
|
|
}
|
|
};
|
|
else if (message.isAgentStateMessage()) return {
|
|
id: message.id,
|
|
createdAt: message.createdAt,
|
|
agentStateMessage: {
|
|
threadId: message.threadId,
|
|
role: message.role,
|
|
agentName: message.agentName,
|
|
nodeName: message.nodeName,
|
|
runId: message.runId,
|
|
active: message.active,
|
|
running: message.running,
|
|
state: JSON.stringify(message.state)
|
|
}
|
|
};
|
|
else if (message.isImageMessage()) return {
|
|
id: message.id,
|
|
createdAt: message.createdAt,
|
|
imageMessage: {
|
|
format: message.format,
|
|
bytes: message.bytes,
|
|
role: message.role,
|
|
parentMessageId: message.parentMessageId
|
|
}
|
|
};
|
|
else throw new Error("Unknown message type");
|
|
});
|
|
}
|
|
function filterAdjacentAgentStateMessages(messages) {
|
|
const filteredMessages = [];
|
|
messages.forEach((message, i) => {
|
|
if (message.__typename !== "AgentStateMessageOutput") filteredMessages.push(message);
|
|
else {
|
|
const prevAgentStateMessageIndex = filteredMessages.findIndex((m) => m.__typename === "AgentStateMessageOutput" && m.agentName === message.agentName);
|
|
if (prevAgentStateMessageIndex === -1) filteredMessages.push(message);
|
|
else filteredMessages[prevAgentStateMessageIndex] = message;
|
|
}
|
|
});
|
|
return filteredMessages;
|
|
}
|
|
function convertGqlOutputToMessages(messages) {
|
|
return messages.map((message) => {
|
|
if (message.__typename === "TextMessageOutput") return new TextMessage({
|
|
id: message.id,
|
|
role: message.role,
|
|
content: message.content.join(""),
|
|
parentMessageId: message.parentMessageId,
|
|
createdAt: /* @__PURE__ */ new Date(),
|
|
status: message.status || { code: MessageStatusCode.Pending }
|
|
});
|
|
else if (message.__typename === "ActionExecutionMessageOutput") return new ActionExecutionMessage({
|
|
id: message.id,
|
|
name: message.name,
|
|
arguments: getPartialArguments(message.arguments),
|
|
parentMessageId: message.parentMessageId,
|
|
createdAt: /* @__PURE__ */ new Date(),
|
|
status: message.status || { code: MessageStatusCode.Pending }
|
|
});
|
|
else if (message.__typename === "ResultMessageOutput") return new ResultMessage({
|
|
id: message.id,
|
|
result: message.result,
|
|
actionExecutionId: message.actionExecutionId,
|
|
actionName: message.actionName,
|
|
createdAt: /* @__PURE__ */ new Date(),
|
|
status: message.status || { code: MessageStatusCode.Pending }
|
|
});
|
|
else if (message.__typename === "AgentStateMessageOutput") return new AgentStateMessage({
|
|
id: message.id,
|
|
threadId: message.threadId,
|
|
role: message.role,
|
|
agentName: message.agentName,
|
|
nodeName: message.nodeName,
|
|
runId: message.runId,
|
|
active: message.active,
|
|
running: message.running,
|
|
state: (0, _copilotkit_shared.parseJson)(message.state, {}),
|
|
createdAt: /* @__PURE__ */ new Date()
|
|
});
|
|
else if (message.__typename === "ImageMessageOutput") return new ImageMessage({
|
|
id: message.id,
|
|
format: message.format,
|
|
bytes: message.bytes,
|
|
role: message.role,
|
|
parentMessageId: message.parentMessageId,
|
|
createdAt: /* @__PURE__ */ new Date(),
|
|
status: message.status || { code: MessageStatusCode.Pending }
|
|
});
|
|
throw new Error("Unknown message type");
|
|
});
|
|
}
|
|
function loadMessagesFromJsonRepresentation(json) {
|
|
const result = [];
|
|
for (const item of json) if ("content" in item) result.push(new TextMessage({
|
|
id: item.id,
|
|
role: item.role,
|
|
content: item.content,
|
|
parentMessageId: item.parentMessageId,
|
|
createdAt: item.createdAt || /* @__PURE__ */ new Date(),
|
|
status: item.status || { code: MessageStatusCode.Success }
|
|
}));
|
|
else if ("arguments" in item) result.push(new ActionExecutionMessage({
|
|
id: item.id,
|
|
name: item.name,
|
|
arguments: item.arguments,
|
|
parentMessageId: item.parentMessageId,
|
|
createdAt: item.createdAt || /* @__PURE__ */ new Date(),
|
|
status: item.status || { code: MessageStatusCode.Success }
|
|
}));
|
|
else if ("result" in item) result.push(new ResultMessage({
|
|
id: item.id,
|
|
result: item.result,
|
|
actionExecutionId: item.actionExecutionId,
|
|
actionName: item.actionName,
|
|
createdAt: item.createdAt || /* @__PURE__ */ new Date(),
|
|
status: item.status || { code: MessageStatusCode.Success }
|
|
}));
|
|
else if ("state" in item) result.push(new AgentStateMessage({
|
|
id: item.id,
|
|
threadId: item.threadId,
|
|
role: item.role,
|
|
agentName: item.agentName,
|
|
nodeName: item.nodeName,
|
|
runId: item.runId,
|
|
active: item.active,
|
|
running: item.running,
|
|
state: item.state,
|
|
createdAt: item.createdAt || /* @__PURE__ */ new Date()
|
|
}));
|
|
else if ("format" in item && "bytes" in item) result.push(new ImageMessage({
|
|
id: item.id,
|
|
format: item.format,
|
|
bytes: item.bytes,
|
|
role: item.role,
|
|
parentMessageId: item.parentMessageId,
|
|
createdAt: item.createdAt || /* @__PURE__ */ new Date(),
|
|
status: item.status || { code: MessageStatusCode.Success }
|
|
}));
|
|
return result;
|
|
}
|
|
function getPartialArguments(args) {
|
|
try {
|
|
if (!args.length) return {};
|
|
const parsed = JSON.parse((0, untruncate_json.default)(args.join("")));
|
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
console.warn(`[CopilotKit] Tool arguments parsed to non-object (${typeof parsed}), falling back to empty object`);
|
|
return {};
|
|
}
|
|
return parsed;
|
|
} catch (e) {
|
|
return {};
|
|
}
|
|
}
|
|
|
|
//#endregion
|
|
//#region src/message-conversion/agui-to-gql.ts
|
|
function extractAgentName(message) {
|
|
if (message.role !== "assistant") throw new Error(`Cannot extract agent name from message with role ${message.role}`);
|
|
return message.agentName || "unknown";
|
|
}
|
|
function isAgentStateMessage(message) {
|
|
return message.role === "assistant" && "agentName" in message && "state" in message;
|
|
}
|
|
function hasImageProperty(message) {
|
|
if (!(message.role === "assistant" || message.role === "user") || message.image === void 0) return false;
|
|
if (message.image.format === void 0 || message.image.bytes === void 0) return false;
|
|
return true;
|
|
}
|
|
function aguiToGQL(messages, actions, coAgentStateRenders) {
|
|
const gqlMessages = [];
|
|
messages = Array.isArray(messages) ? messages : [messages];
|
|
const toolCallNames = {};
|
|
for (const message of messages) {
|
|
if (isAgentStateMessage(message)) {
|
|
const agentName = extractAgentName(message);
|
|
const state = "state" in message && message.state ? message.state : {};
|
|
gqlMessages.push(new AgentStateMessage({
|
|
id: message.id,
|
|
agentName,
|
|
state,
|
|
role: Role.Assistant
|
|
}));
|
|
if ("generativeUI" in message && message.generativeUI && coAgentStateRenders) coAgentStateRenders[agentName] = {
|
|
name: agentName,
|
|
render: message.generativeUI
|
|
};
|
|
continue;
|
|
}
|
|
if (hasImageProperty(message)) {
|
|
gqlMessages.push(aguiMessageWithImageToGQLMessage(message));
|
|
continue;
|
|
}
|
|
if (message.role === "assistant" && message.toolCalls) {
|
|
gqlMessages.push(aguiTextMessageToGQLMessage(message));
|
|
for (const toolCall of message.toolCalls) {
|
|
toolCallNames[toolCall.id] = toolCall.function.name;
|
|
const actionExecMsg = aguiToolCallToGQLActionExecution(toolCall, message.id);
|
|
if ("generativeUI" in message && message.generativeUI && actions) {
|
|
const actionName = toolCall.function.name;
|
|
const specificAction = Object.values(actions).find((action) => action.name === actionName);
|
|
const wildcardAction = Object.values(actions).find((action) => action.name === "*");
|
|
if (specificAction) specificAction.render = message.generativeUI;
|
|
else if (wildcardAction) wildcardAction.render = message.generativeUI;
|
|
}
|
|
gqlMessages.push(actionExecMsg);
|
|
}
|
|
continue;
|
|
}
|
|
if (message.role === "reasoning") continue;
|
|
if (message.role === "developer" || message.role === "system" || message.role === "assistant" || message.role === "user") {
|
|
gqlMessages.push(aguiTextMessageToGQLMessage(message));
|
|
continue;
|
|
}
|
|
if (message.role === "tool") {
|
|
gqlMessages.push(aguiToolMessageToGQLResultMessage(message, toolCallNames));
|
|
continue;
|
|
}
|
|
throw new Error(`Unknown message role: "${message.role}" in message with id: ${message.id}`);
|
|
}
|
|
return gqlMessages;
|
|
}
|
|
function aguiTextMessageToGQLMessage(message) {
|
|
if (message.role !== "developer" && message.role !== "system" && message.role !== "assistant" && message.role !== "user") throw new Error(`Cannot convert message with role ${message.role} to TextMessage`);
|
|
let roleValue;
|
|
if (message.role === "developer") roleValue = Role.Developer;
|
|
else if (message.role === "system") roleValue = Role.System;
|
|
else if (message.role === "assistant") roleValue = Role.Assistant;
|
|
else roleValue = Role.User;
|
|
return new TextMessage({
|
|
id: message.id,
|
|
content: message.content || "",
|
|
role: roleValue
|
|
});
|
|
}
|
|
function aguiToolCallToGQLActionExecution(toolCall, parentMessageId) {
|
|
if (toolCall.type !== "function") throw new Error(`Unsupported tool call type: ${toolCall.type}`);
|
|
let argumentsObj;
|
|
if (typeof toolCall.function.arguments === "string") try {
|
|
argumentsObj = JSON.parse(toolCall.function.arguments);
|
|
} catch (error) {
|
|
console.warn(`[CopilotKit] Failed to parse tool arguments, falling back to empty object`);
|
|
argumentsObj = {};
|
|
}
|
|
else if (typeof toolCall.function.arguments === "object" && toolCall.function.arguments !== null) argumentsObj = toolCall.function.arguments;
|
|
else {
|
|
console.warn(`[CopilotKit] Tool arguments parsed to non-object (${typeof toolCall.function.arguments}), falling back to empty object`);
|
|
argumentsObj = {};
|
|
}
|
|
if (typeof argumentsObj !== "object" || argumentsObj === null || Array.isArray(argumentsObj)) {
|
|
console.warn(`[CopilotKit] Tool arguments parsed to non-object (${typeof argumentsObj}), falling back to empty object`);
|
|
argumentsObj = {};
|
|
}
|
|
return new ActionExecutionMessage({
|
|
id: toolCall.id,
|
|
name: toolCall.function.name,
|
|
arguments: argumentsObj,
|
|
parentMessageId
|
|
});
|
|
}
|
|
function aguiToolMessageToGQLResultMessage(message, toolCallNames) {
|
|
if (message.role !== "tool") throw new Error(`Cannot convert message with role ${message.role} to ResultMessage`);
|
|
if (!message.toolCallId) throw new Error("Tool message must have a toolCallId");
|
|
const actionName = toolCallNames[message.toolCallId] || "unknown";
|
|
let resultContent;
|
|
const messageContent = message.content || "";
|
|
if (typeof messageContent === "string") resultContent = messageContent;
|
|
else if (typeof messageContent === "object" && messageContent !== null) try {
|
|
resultContent = JSON.stringify(messageContent);
|
|
} catch (error) {
|
|
console.warn(`Failed to stringify tool result for ${actionName}:`, error);
|
|
resultContent = String(messageContent);
|
|
}
|
|
else resultContent = String(messageContent);
|
|
return new ResultMessage({
|
|
id: message.id,
|
|
result: resultContent,
|
|
actionExecutionId: message.toolCallId,
|
|
actionName: message.toolName || actionName
|
|
});
|
|
}
|
|
function aguiMessageWithRenderToGQL(message, actions, coAgentStateRenders) {
|
|
if (message.role === "assistant" && "generativeUI" in message && message.generativeUI && !message.toolCalls) {
|
|
const gqlMessages = [];
|
|
gqlMessages.push(new AgentStateMessage({
|
|
id: message.id,
|
|
agentName: "unknown",
|
|
state: {},
|
|
role: Role.Assistant
|
|
}));
|
|
if (coAgentStateRenders) coAgentStateRenders.unknown = {
|
|
name: "unknown",
|
|
render: message.generativeUI
|
|
};
|
|
return gqlMessages;
|
|
}
|
|
return aguiToGQL([message], actions, coAgentStateRenders);
|
|
}
|
|
function aguiMessageWithImageToGQLMessage(message) {
|
|
if (!hasImageProperty(message)) throw new Error(`Cannot convert message to ImageMessage: missing format or bytes`);
|
|
let roleValue;
|
|
if (message.role === "assistant") roleValue = Role.Assistant;
|
|
else roleValue = Role.User;
|
|
if (message.role !== "assistant" && message.role !== "user") throw new Error(`Cannot convert message with role ${message.role} to ImageMessage`);
|
|
return new ImageMessage({
|
|
id: message.id,
|
|
format: message.image.format,
|
|
bytes: message.image.bytes,
|
|
role: roleValue
|
|
});
|
|
}
|
|
|
|
//#endregion
|
|
//#region src/message-conversion/gql-to-agui.ts
|
|
const VALID_IMAGE_FORMATS = [
|
|
"jpeg",
|
|
"png",
|
|
"webp",
|
|
"gif"
|
|
];
|
|
function validateImageFormat(format) {
|
|
return VALID_IMAGE_FORMATS.includes(format);
|
|
}
|
|
function gqlToAGUI(messages, actions, coAgentStateRenders) {
|
|
let aguiMessages = [];
|
|
messages = Array.isArray(messages) ? messages : [messages];
|
|
const actionResults = /* @__PURE__ */ new Map();
|
|
for (const message of messages) if (message.isResultMessage()) actionResults.set(message.actionExecutionId, message.result);
|
|
for (const message of messages) if (message.isTextMessage()) aguiMessages.push(gqlTextMessageToAGUIMessage(message));
|
|
else if (message.isResultMessage()) aguiMessages.push(gqlResultMessageToAGUIMessage(message));
|
|
else if (message.isActionExecutionMessage()) aguiMessages.push(gqlActionExecutionMessageToAGUIMessage(message, actions, actionResults));
|
|
else if (message.isAgentStateMessage()) aguiMessages.push(gqlAgentStateMessageToAGUIMessage(message, coAgentStateRenders));
|
|
else if (message.isImageMessage()) aguiMessages.push(gqlImageMessageToAGUIMessage(message));
|
|
else throw new Error("Unknown message type");
|
|
return aguiMessages;
|
|
}
|
|
function gqlActionExecutionMessageToAGUIMessage(message, actions, actionResults) {
|
|
const hasSpecificAction = actions && Object.values(actions).some((action) => action.name === message.name);
|
|
const hasWildcardAction = actions && Object.values(actions).some((action) => action.name === "*");
|
|
if (!actions || !hasSpecificAction && !hasWildcardAction) return {
|
|
id: message.id,
|
|
role: "assistant",
|
|
toolCalls: [actionExecutionMessageToAGUIMessage(message)],
|
|
name: message.name
|
|
};
|
|
const action = Object.values(actions).find((action) => action.name === message.name) || Object.values(actions).find((action) => action.name === "*");
|
|
const createRenderWrapper = (originalRender) => {
|
|
if (!originalRender) return void 0;
|
|
return (props) => {
|
|
var _message$status;
|
|
let actionResult = actionResults === null || actionResults === void 0 ? void 0 : actionResults.get(message.id);
|
|
let status = "inProgress";
|
|
if (actionResult !== void 0) status = "complete";
|
|
else if (((_message$status = message.status) === null || _message$status === void 0 ? void 0 : _message$status.code) !== MessageStatusCode.Pending) status = "executing";
|
|
if (typeof (props === null || props === void 0 ? void 0 : props.result) === "string") try {
|
|
props.result = JSON.parse(props.result);
|
|
} catch (e) {}
|
|
if (typeof actionResult === "string") try {
|
|
actionResult = JSON.parse(actionResult);
|
|
} catch (e) {}
|
|
const baseProps = {
|
|
status: (props === null || props === void 0 ? void 0 : props.status) || status,
|
|
args: message.arguments || {},
|
|
result: (props === null || props === void 0 ? void 0 : props.result) || actionResult || void 0,
|
|
messageId: message.id
|
|
};
|
|
if (action.name === "*") return originalRender({
|
|
...baseProps,
|
|
...props,
|
|
name: message.name
|
|
});
|
|
else {
|
|
var _props$respond;
|
|
const respond = (_props$respond = props === null || props === void 0 ? void 0 : props.respond) !== null && _props$respond !== void 0 ? _props$respond : (() => {});
|
|
return originalRender({
|
|
...baseProps,
|
|
...props,
|
|
respond
|
|
});
|
|
}
|
|
};
|
|
};
|
|
return {
|
|
id: message.id,
|
|
role: "assistant",
|
|
content: "",
|
|
toolCalls: [actionExecutionMessageToAGUIMessage(message)],
|
|
generativeUI: createRenderWrapper(action.render),
|
|
name: message.name
|
|
};
|
|
}
|
|
function gqlAgentStateMessageToAGUIMessage(message, coAgentStateRenders) {
|
|
if (coAgentStateRenders && Object.values(coAgentStateRenders).some((render) => render.name === message.agentName)) {
|
|
const render = Object.values(coAgentStateRenders).find((render) => render.name === message.agentName);
|
|
const createRenderWrapper = (originalRender) => {
|
|
if (!originalRender) return void 0;
|
|
return (props) => {
|
|
return originalRender({ state: message.state });
|
|
};
|
|
};
|
|
return {
|
|
id: message.id,
|
|
role: "assistant",
|
|
generativeUI: createRenderWrapper(render.render),
|
|
agentName: message.agentName,
|
|
state: message.state
|
|
};
|
|
}
|
|
return {
|
|
id: message.id,
|
|
role: "assistant",
|
|
agentName: message.agentName,
|
|
state: message.state
|
|
};
|
|
}
|
|
function actionExecutionMessageToAGUIMessage(actionExecutionMessage) {
|
|
return {
|
|
id: actionExecutionMessage.id,
|
|
function: {
|
|
name: actionExecutionMessage.name,
|
|
arguments: JSON.stringify(actionExecutionMessage.arguments)
|
|
},
|
|
type: "function"
|
|
};
|
|
}
|
|
function gqlTextMessageToAGUIMessage(message) {
|
|
switch (message.role) {
|
|
case Role.Developer: return {
|
|
id: message.id,
|
|
role: "developer",
|
|
content: message.content
|
|
};
|
|
case Role.System: return {
|
|
id: message.id,
|
|
role: "system",
|
|
content: message.content
|
|
};
|
|
case Role.Assistant: return {
|
|
id: message.id,
|
|
role: "assistant",
|
|
content: message.content
|
|
};
|
|
case Role.User: return {
|
|
id: message.id,
|
|
role: "user",
|
|
content: message.content
|
|
};
|
|
default: throw new Error("Unknown message role");
|
|
}
|
|
}
|
|
function gqlResultMessageToAGUIMessage(message) {
|
|
return {
|
|
id: message.id,
|
|
role: "tool",
|
|
content: message.result,
|
|
toolCallId: message.actionExecutionId,
|
|
toolName: message.actionName
|
|
};
|
|
}
|
|
function gqlImageMessageToAGUIMessage(message) {
|
|
if (!validateImageFormat(message.format)) throw new Error(`Invalid image format: ${message.format}. Supported formats are: ${VALID_IMAGE_FORMATS.join(", ")}`);
|
|
if (!message.bytes || typeof message.bytes !== "string" || message.bytes.trim() === "") throw new Error("Image bytes must be a non-empty string");
|
|
const role = message.role === Role.Assistant ? "assistant" : "user";
|
|
return {
|
|
id: message.id,
|
|
role,
|
|
content: "",
|
|
image: {
|
|
format: message.format,
|
|
bytes: message.bytes
|
|
}
|
|
};
|
|
}
|
|
|
|
//#endregion
|
|
exports.ActionExecutionMessage = ActionExecutionMessage;
|
|
exports.ActionInputAvailability = ActionInputAvailability;
|
|
exports.AgentStateMessage = AgentStateMessage;
|
|
exports.AvailableAgentsDocument = AvailableAgentsDocument;
|
|
exports.CopilotRequestType = CopilotRequestType;
|
|
exports.CopilotRuntimeClient = CopilotRuntimeClient;
|
|
exports.FailedResponseStatusReason = FailedResponseStatusReason;
|
|
exports.GenerateCopilotResponseDocument = GenerateCopilotResponseDocument;
|
|
exports.ImageMessage = ImageMessage;
|
|
exports.LoadAgentStateDocument = LoadAgentStateDocument;
|
|
exports.Message = Message;
|
|
exports.MessageRole = MessageRole;
|
|
exports.MessageStatusCode = MessageStatusCode;
|
|
exports.MetaEventName = MetaEventName;
|
|
exports.ResponseStatusCode = ResponseStatusCode;
|
|
exports.ResultMessage = ResultMessage;
|
|
exports.Role = Role;
|
|
exports.TextMessage = TextMessage;
|
|
exports.aguiMessageWithImageToGQLMessage = aguiMessageWithImageToGQLMessage;
|
|
exports.aguiMessageWithRenderToGQL = aguiMessageWithRenderToGQL;
|
|
exports.aguiTextMessageToGQLMessage = aguiTextMessageToGQLMessage;
|
|
exports.aguiToGQL = aguiToGQL;
|
|
exports.aguiToolCallToGQLActionExecution = aguiToolCallToGQLActionExecution;
|
|
exports.aguiToolMessageToGQLResultMessage = aguiToolMessageToGQLResultMessage;
|
|
exports.convertGqlOutputToMessages = convertGqlOutputToMessages;
|
|
exports.convertMessagesToGqlInput = convertMessagesToGqlInput;
|
|
exports.filterAdjacentAgentStateMessages = filterAdjacentAgentStateMessages;
|
|
exports.filterAgentStateMessages = filterAgentStateMessages;
|
|
exports.gqlActionExecutionMessageToAGUIMessage = gqlActionExecutionMessageToAGUIMessage;
|
|
exports.gqlImageMessageToAGUIMessage = gqlImageMessageToAGUIMessage;
|
|
exports.gqlResultMessageToAGUIMessage = gqlResultMessageToAGUIMessage;
|
|
exports.gqlTextMessageToAGUIMessage = gqlTextMessageToAGUIMessage;
|
|
exports.gqlToAGUI = gqlToAGUI;
|
|
exports.langGraphInterruptEvent = langGraphInterruptEvent;
|
|
exports.loadMessagesFromJsonRepresentation = loadMessagesFromJsonRepresentation;
|
|
});
|
|
//# sourceMappingURL=index.umd.js.map
|