@copilotkit/runtime 0.37.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/.eslintrc.js +7 -0
- package/.turbo/turbo-build.log +70 -0
- package/CHANGELOG.md +1 -0
- package/__snapshots__/schema/schema.graphql +178 -0
- package/dist/chunk-2CCVVJDU.mjs +56 -0
- package/dist/chunk-2CCVVJDU.mjs.map +1 -0
- package/dist/chunk-4UA4RB4C.mjs +185 -0
- package/dist/chunk-4UA4RB4C.mjs.map +1 -0
- package/dist/chunk-5HGYI6EG.mjs +678 -0
- package/dist/chunk-5HGYI6EG.mjs.map +1 -0
- package/dist/chunk-7IFP53C6.mjs +169 -0
- package/dist/chunk-7IFP53C6.mjs.map +1 -0
- package/dist/chunk-BLTAUVRP.mjs +30 -0
- package/dist/chunk-BLTAUVRP.mjs.map +1 -0
- package/dist/chunk-NFCPM5AM.mjs +43 -0
- package/dist/chunk-NFCPM5AM.mjs.map +1 -0
- package/dist/chunk-XPAUPJMW.mjs +1051 -0
- package/dist/chunk-XPAUPJMW.mjs.map +1 -0
- package/dist/graphql/types/base/index.d.ts +6 -0
- package/dist/graphql/types/base/index.js +63 -0
- package/dist/graphql/types/base/index.js.map +1 -0
- package/dist/graphql/types/base/index.mjs +7 -0
- package/dist/graphql/types/base/index.mjs.map +1 -0
- package/dist/graphql/types/converted/index.d.ts +2 -0
- package/dist/graphql/types/converted/index.js +88 -0
- package/dist/graphql/types/converted/index.js.map +1 -0
- package/dist/graphql/types/converted/index.mjs +12 -0
- package/dist/graphql/types/converted/index.mjs.map +1 -0
- package/dist/index-aa091e3c.d.ts +49 -0
- package/dist/index-f0875df3.d.ts +197 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +2171 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +49 -0
- package/dist/index.mjs.map +1 -0
- package/dist/langchain-adapter-9ce103f3.d.ts +200 -0
- package/dist/langserve-fd5066ee.d.ts +96 -0
- package/dist/lib/index.d.ts +15 -0
- package/dist/lib/index.js +2170 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/index.mjs +46 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/lib/integrations/index.d.ts +9 -0
- package/dist/lib/integrations/index.js +1024 -0
- package/dist/lib/integrations/index.js.map +1 -0
- package/dist/lib/integrations/index.mjs +24 -0
- package/dist/lib/integrations/index.mjs.map +1 -0
- package/dist/lib/integrations/node-http/index.d.ts +8 -0
- package/dist/lib/integrations/node-http/index.js +969 -0
- package/dist/lib/integrations/node-http/index.js.map +1 -0
- package/dist/lib/integrations/node-http/index.mjs +10 -0
- package/dist/lib/integrations/node-http/index.mjs.map +1 -0
- package/dist/pages-router-b6bc6c60.d.ts +30 -0
- package/dist/service-adapters/index.d.ts +11 -0
- package/dist/service-adapters/index.js +912 -0
- package/dist/service-adapters/index.js.map +1 -0
- package/dist/service-adapters/index.mjs +18 -0
- package/dist/service-adapters/index.mjs.map +1 -0
- package/jest.config.js +5 -0
- package/package.json +63 -0
- package/scripts/generate-gql-schema.ts +13 -0
- package/src/graphql/inputs/action.input.ts +13 -0
- package/src/graphql/inputs/cloud-guardrails.input.ts +19 -0
- package/src/graphql/inputs/cloud.input.ts +8 -0
- package/src/graphql/inputs/context-property.input.ts +10 -0
- package/src/graphql/inputs/custom-property.input.ts +15 -0
- package/src/graphql/inputs/frontend.input.ts +11 -0
- package/src/graphql/inputs/generate-copilot-response.input.ts +22 -0
- package/src/graphql/inputs/message.input.ts +50 -0
- package/src/graphql/resolvers/copilot.resolver.ts +147 -0
- package/src/graphql/types/base/index.ts +10 -0
- package/src/graphql/types/converted/index.ts +29 -0
- package/src/graphql/types/copilot-response.type.ts +75 -0
- package/src/graphql/types/enums.ts +22 -0
- package/src/graphql/types/guardrails-result.type.ts +20 -0
- package/src/graphql/types/message-status.type.ts +40 -0
- package/src/graphql/types/response-status.type.ts +52 -0
- package/src/index.ts +2 -0
- package/src/lib/copilot-cloud.ts +63 -0
- package/src/lib/copilot-runtime.ts +261 -0
- package/src/lib/guardrails.ts +3 -0
- package/src/lib/index.ts +7 -0
- package/src/lib/integrations/index.ts +4 -0
- package/src/lib/integrations/nextjs/app-router.ts +29 -0
- package/src/lib/integrations/nextjs/pages-router.ts +36 -0
- package/src/lib/integrations/node-http/index.ts +23 -0
- package/src/lib/integrations/shared.ts +68 -0
- package/src/service-adapters/conversion.ts +47 -0
- package/src/service-adapters/events.ts +197 -0
- package/src/service-adapters/experimental/groq/groq-adapter.ts +124 -0
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +75 -0
- package/src/service-adapters/google/google-genai-adapter.ts +149 -0
- package/src/service-adapters/google/utils.ts +94 -0
- package/src/service-adapters/index.ts +6 -0
- package/src/service-adapters/langchain/langchain-adapter.ts +82 -0
- package/src/service-adapters/langchain/langserve.ts +81 -0
- package/src/service-adapters/langchain/types.ts +14 -0
- package/src/service-adapters/langchain/utils.ts +235 -0
- package/src/service-adapters/openai/openai-adapter.ts +142 -0
- package/src/service-adapters/openai/openai-assistant-adapter.ts +260 -0
- package/src/service-adapters/openai/utils.ts +164 -0
- package/src/service-adapters/service-adapter.ts +29 -0
- package/tsconfig.json +11 -0
- package/tsup.config.ts +17 -0
- package/typedoc.json +4 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2171 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
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
|
+
CopilotBackend: () => CopilotBackend,
|
|
34
|
+
CopilotCloud: () => CopilotCloud,
|
|
35
|
+
CopilotRuntime: () => CopilotRuntime,
|
|
36
|
+
GoogleGenerativeAIAdapter: () => GoogleGenerativeAIAdapter,
|
|
37
|
+
LangChainAdapter: () => LangChainAdapter,
|
|
38
|
+
OpenAIAdapter: () => OpenAIAdapter,
|
|
39
|
+
OpenAIAssistantAdapter: () => OpenAIAssistantAdapter,
|
|
40
|
+
RemoteCopilotCloud: () => RemoteCopilotCloud,
|
|
41
|
+
buildSchema: () => buildSchema,
|
|
42
|
+
config: () => config,
|
|
43
|
+
copilotRuntimeNextJSAppRouterEndpoint: () => copilotRuntimeNextJSAppRouterEndpoint,
|
|
44
|
+
copilotRuntimeNextJSPagesRouterEndpoint: () => copilotRuntimeNextJSPagesRouterEndpoint,
|
|
45
|
+
copilotRuntimeNodeHttpEndpoint: () => copilotRuntimeNodeHttpEndpoint,
|
|
46
|
+
createContext: () => createContext,
|
|
47
|
+
flattenToolCallsNoDuplicates: () => flattenToolCallsNoDuplicates,
|
|
48
|
+
getCommonConfig: () => getCommonConfig
|
|
49
|
+
});
|
|
50
|
+
module.exports = __toCommonJS(src_exports);
|
|
51
|
+
var import_reflect_metadata = require("reflect-metadata");
|
|
52
|
+
|
|
53
|
+
// src/lib/copilot-runtime.ts
|
|
54
|
+
var import_shared2 = require("@copilotkit/shared");
|
|
55
|
+
|
|
56
|
+
// src/service-adapters/openai/openai-adapter.ts
|
|
57
|
+
var import_openai = __toESM(require("openai"));
|
|
58
|
+
|
|
59
|
+
// src/graphql/types/base/index.ts
|
|
60
|
+
var import_type_graphql = require("type-graphql");
|
|
61
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
62
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
63
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
64
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
65
|
+
else
|
|
66
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
67
|
+
if (d = decorators[i])
|
|
68
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
69
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
70
|
+
}
|
|
71
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
72
|
+
function _ts_metadata(k, v) {
|
|
73
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
74
|
+
return Reflect.metadata(k, v);
|
|
75
|
+
}
|
|
76
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
77
|
+
var BaseMessage = class {
|
|
78
|
+
id;
|
|
79
|
+
createdAt;
|
|
80
|
+
};
|
|
81
|
+
__name(BaseMessage, "BaseMessage");
|
|
82
|
+
_ts_decorate([
|
|
83
|
+
(0, import_type_graphql.Field)(() => String),
|
|
84
|
+
_ts_metadata("design:type", String)
|
|
85
|
+
], BaseMessage.prototype, "id", void 0);
|
|
86
|
+
_ts_decorate([
|
|
87
|
+
(0, import_type_graphql.Field)(() => Date),
|
|
88
|
+
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
89
|
+
], BaseMessage.prototype, "createdAt", void 0);
|
|
90
|
+
BaseMessage = _ts_decorate([
|
|
91
|
+
(0, import_type_graphql.InputType)()
|
|
92
|
+
], BaseMessage);
|
|
93
|
+
|
|
94
|
+
// src/graphql/types/converted/index.ts
|
|
95
|
+
var TextMessage = class extends BaseMessage {
|
|
96
|
+
content;
|
|
97
|
+
role;
|
|
98
|
+
};
|
|
99
|
+
__name(TextMessage, "TextMessage");
|
|
100
|
+
var ActionExecutionMessage = class extends BaseMessage {
|
|
101
|
+
name;
|
|
102
|
+
arguments;
|
|
103
|
+
scope;
|
|
104
|
+
};
|
|
105
|
+
__name(ActionExecutionMessage, "ActionExecutionMessage");
|
|
106
|
+
var ResultMessage = class extends BaseMessage {
|
|
107
|
+
actionExecutionId;
|
|
108
|
+
actionName;
|
|
109
|
+
result;
|
|
110
|
+
};
|
|
111
|
+
__name(ResultMessage, "ResultMessage");
|
|
112
|
+
|
|
113
|
+
// src/service-adapters/openai/utils.ts
|
|
114
|
+
var import_js_tiktoken = require("js-tiktoken");
|
|
115
|
+
function limitMessagesToTokenCount(messages, tools, model, maxTokens) {
|
|
116
|
+
maxTokens || (maxTokens = maxTokensForOpenAIModel(model));
|
|
117
|
+
const result = [];
|
|
118
|
+
const toolsNumTokens = countToolsTokens(model, tools);
|
|
119
|
+
if (toolsNumTokens > maxTokens) {
|
|
120
|
+
throw new Error(`Too many tokens in function definitions: ${toolsNumTokens} > ${maxTokens}`);
|
|
121
|
+
}
|
|
122
|
+
maxTokens -= toolsNumTokens;
|
|
123
|
+
for (const message of messages) {
|
|
124
|
+
if (message.role === "system") {
|
|
125
|
+
const numTokens = countMessageTokens(model, message);
|
|
126
|
+
maxTokens -= numTokens;
|
|
127
|
+
if (maxTokens < 0) {
|
|
128
|
+
throw new Error("Not enough tokens for system message.");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
let cutoff = false;
|
|
133
|
+
const reversedMessages = [
|
|
134
|
+
...messages
|
|
135
|
+
].reverse();
|
|
136
|
+
for (const message of reversedMessages) {
|
|
137
|
+
if (message.role === "system") {
|
|
138
|
+
result.unshift(message);
|
|
139
|
+
continue;
|
|
140
|
+
} else if (cutoff) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
let numTokens = countMessageTokens(model, message);
|
|
144
|
+
if (maxTokens < numTokens) {
|
|
145
|
+
cutoff = true;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
result.unshift(message);
|
|
149
|
+
maxTokens -= numTokens;
|
|
150
|
+
}
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
__name(limitMessagesToTokenCount, "limitMessagesToTokenCount");
|
|
154
|
+
function maxTokensForOpenAIModel(model) {
|
|
155
|
+
return maxTokensByModel[model] || DEFAULT_MAX_TOKENS;
|
|
156
|
+
}
|
|
157
|
+
__name(maxTokensForOpenAIModel, "maxTokensForOpenAIModel");
|
|
158
|
+
var DEFAULT_MAX_TOKENS = 128e3;
|
|
159
|
+
var maxTokensByModel = {
|
|
160
|
+
// GPT-4
|
|
161
|
+
"gpt-4o": 128e3,
|
|
162
|
+
"gpt-4o-2024-05-13": 128e3,
|
|
163
|
+
"gpt-4-turbo": 128e3,
|
|
164
|
+
"gpt-4-turbo-2024-04-09": 128e3,
|
|
165
|
+
"gpt-4-0125-preview": 128e3,
|
|
166
|
+
"gpt-4-turbo-preview": 128e3,
|
|
167
|
+
"gpt-4-1106-preview": 128e3,
|
|
168
|
+
"gpt-4-vision-preview": 128e3,
|
|
169
|
+
"gpt-4-1106-vision-preview": 128e3,
|
|
170
|
+
"gpt-4-32k": 32768,
|
|
171
|
+
"gpt-4-32k-0613": 32768,
|
|
172
|
+
"gpt-4-32k-0314": 32768,
|
|
173
|
+
"gpt-4": 8192,
|
|
174
|
+
"gpt-4-0613": 8192,
|
|
175
|
+
"gpt-4-0314": 8192,
|
|
176
|
+
// GPT-3.5
|
|
177
|
+
"gpt-3.5-turbo-0125": 16385,
|
|
178
|
+
"gpt-3.5-turbo": 16385,
|
|
179
|
+
"gpt-3.5-turbo-1106": 16385,
|
|
180
|
+
"gpt-3.5-turbo-instruct": 4096,
|
|
181
|
+
"gpt-3.5-turbo-16k": 16385,
|
|
182
|
+
"gpt-3.5-turbo-0613": 4096,
|
|
183
|
+
"gpt-3.5-turbo-16k-0613": 16385,
|
|
184
|
+
"gpt-3.5-turbo-0301": 4097
|
|
185
|
+
};
|
|
186
|
+
function countToolsTokens(model, tools) {
|
|
187
|
+
if (tools.length === 0) {
|
|
188
|
+
return 0;
|
|
189
|
+
}
|
|
190
|
+
const json = JSON.stringify(tools);
|
|
191
|
+
return countTokens(model, json);
|
|
192
|
+
}
|
|
193
|
+
__name(countToolsTokens, "countToolsTokens");
|
|
194
|
+
function countMessageTokens(model, message) {
|
|
195
|
+
return countTokens(model, message.content || "");
|
|
196
|
+
}
|
|
197
|
+
__name(countMessageTokens, "countMessageTokens");
|
|
198
|
+
function countTokens(model, text) {
|
|
199
|
+
let enc;
|
|
200
|
+
try {
|
|
201
|
+
enc = (0, import_js_tiktoken.encodingForModel)(model);
|
|
202
|
+
} catch (e) {
|
|
203
|
+
enc = (0, import_js_tiktoken.encodingForModel)("gpt-4");
|
|
204
|
+
}
|
|
205
|
+
return enc.encode(text).length;
|
|
206
|
+
}
|
|
207
|
+
__name(countTokens, "countTokens");
|
|
208
|
+
function convertActionInputToOpenAITool(action) {
|
|
209
|
+
return {
|
|
210
|
+
type: "function",
|
|
211
|
+
function: {
|
|
212
|
+
name: action.name,
|
|
213
|
+
description: action.description,
|
|
214
|
+
parameters: JSON.parse(action.jsonSchema)
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
__name(convertActionInputToOpenAITool, "convertActionInputToOpenAITool");
|
|
219
|
+
function convertMessageToOpenAIMessage(message) {
|
|
220
|
+
if (message instanceof TextMessage) {
|
|
221
|
+
return {
|
|
222
|
+
role: message.role,
|
|
223
|
+
content: message.content
|
|
224
|
+
};
|
|
225
|
+
} else if (message instanceof ActionExecutionMessage) {
|
|
226
|
+
return {
|
|
227
|
+
role: "assistant",
|
|
228
|
+
tool_calls: [
|
|
229
|
+
{
|
|
230
|
+
id: message.id,
|
|
231
|
+
type: "function",
|
|
232
|
+
function: {
|
|
233
|
+
name: message.name,
|
|
234
|
+
arguments: JSON.stringify(message.arguments)
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
]
|
|
238
|
+
};
|
|
239
|
+
} else if (message instanceof ResultMessage) {
|
|
240
|
+
return {
|
|
241
|
+
role: "tool",
|
|
242
|
+
content: message.result,
|
|
243
|
+
tool_call_id: message.actionExecutionId
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
__name(convertMessageToOpenAIMessage, "convertMessageToOpenAIMessage");
|
|
248
|
+
function convertSystemMessageToAssistantAPI(message) {
|
|
249
|
+
return {
|
|
250
|
+
...message,
|
|
251
|
+
...message.role === "system" && {
|
|
252
|
+
role: "assistant",
|
|
253
|
+
content: "THE FOLLOWING MESSAGE IS A SYSTEM MESSAGE: " + message.content
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
__name(convertSystemMessageToAssistantAPI, "convertSystemMessageToAssistantAPI");
|
|
258
|
+
|
|
259
|
+
// src/service-adapters/openai/openai-adapter.ts
|
|
260
|
+
var DEFAULT_MODEL = "gpt-4o";
|
|
261
|
+
var OpenAIAdapter = class {
|
|
262
|
+
model = DEFAULT_MODEL;
|
|
263
|
+
_openai;
|
|
264
|
+
get openai() {
|
|
265
|
+
return this._openai;
|
|
266
|
+
}
|
|
267
|
+
constructor(params) {
|
|
268
|
+
this._openai = (params == null ? void 0 : params.openai) || new import_openai.default({});
|
|
269
|
+
if (params == null ? void 0 : params.model) {
|
|
270
|
+
this.model = params.model;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
async process({ model = this.model, messages, actions, eventSource }) {
|
|
274
|
+
const tools = actions.map(convertActionInputToOpenAITool);
|
|
275
|
+
let openaiMessages = messages.map(convertMessageToOpenAIMessage);
|
|
276
|
+
openaiMessages = limitMessagesToTokenCount(openaiMessages, tools, model);
|
|
277
|
+
const stream = this.openai.beta.chat.completions.stream({
|
|
278
|
+
model,
|
|
279
|
+
stream: true,
|
|
280
|
+
messages: openaiMessages,
|
|
281
|
+
...tools.length > 0 && {
|
|
282
|
+
tools
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
eventSource.stream(async (eventStream$) => {
|
|
286
|
+
var _a, _b;
|
|
287
|
+
let mode = null;
|
|
288
|
+
for await (const chunk of stream) {
|
|
289
|
+
const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
|
|
290
|
+
const content = chunk.choices[0].delta.content;
|
|
291
|
+
if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
|
|
292
|
+
mode = null;
|
|
293
|
+
eventStream$.sendTextMessageEnd();
|
|
294
|
+
} else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
|
|
295
|
+
mode = null;
|
|
296
|
+
eventStream$.sendActionExecutionEnd();
|
|
297
|
+
}
|
|
298
|
+
if (mode === null) {
|
|
299
|
+
if (toolCall == null ? void 0 : toolCall.id) {
|
|
300
|
+
mode = "function";
|
|
301
|
+
eventStream$.sendActionExecutionStart(toolCall.id, toolCall.function.name);
|
|
302
|
+
} else if (content) {
|
|
303
|
+
mode = "message";
|
|
304
|
+
eventStream$.sendTextMessageStart(chunk.id);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (mode === "message" && content) {
|
|
308
|
+
eventStream$.sendTextMessageContent(content);
|
|
309
|
+
} else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
|
|
310
|
+
eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (mode === "message") {
|
|
314
|
+
eventStream$.sendTextMessageEnd();
|
|
315
|
+
} else if (mode === "function") {
|
|
316
|
+
eventStream$.sendActionExecutionEnd();
|
|
317
|
+
}
|
|
318
|
+
eventStream$.complete();
|
|
319
|
+
});
|
|
320
|
+
return {};
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
__name(OpenAIAdapter, "OpenAIAdapter");
|
|
324
|
+
|
|
325
|
+
// src/service-adapters/openai/openai-assistant-adapter.ts
|
|
326
|
+
var import_openai2 = __toESM(require("openai"));
|
|
327
|
+
var OpenAIAssistantAdapter = class {
|
|
328
|
+
openai;
|
|
329
|
+
codeInterpreterEnabled;
|
|
330
|
+
assistantId;
|
|
331
|
+
fileSearchEnabled;
|
|
332
|
+
constructor(params) {
|
|
333
|
+
this.openai = params.openai || new import_openai2.default({});
|
|
334
|
+
this.codeInterpreterEnabled = params.codeInterpreterEnabled === false || true;
|
|
335
|
+
this.fileSearchEnabled = params.fileSearchEnabled === false || true;
|
|
336
|
+
this.assistantId = params.assistantId;
|
|
337
|
+
}
|
|
338
|
+
async process({ messages, actions, eventSource, threadId, runId }) {
|
|
339
|
+
threadId || (threadId = (await this.openai.beta.threads.create()).id);
|
|
340
|
+
const lastMessage = messages.at(-1);
|
|
341
|
+
let nextRunId = void 0;
|
|
342
|
+
if (lastMessage instanceof ResultMessage && runId) {
|
|
343
|
+
nextRunId = await this.submitToolOutputs(threadId, runId, messages, eventSource);
|
|
344
|
+
} else if (lastMessage instanceof TextMessage) {
|
|
345
|
+
nextRunId = await this.submitUserMessage(threadId, messages, actions, eventSource);
|
|
346
|
+
} else {
|
|
347
|
+
throw new Error("No actionable message found in the messages");
|
|
348
|
+
}
|
|
349
|
+
return {
|
|
350
|
+
threadId,
|
|
351
|
+
runId: nextRunId
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
async submitToolOutputs(threadId, runId, messages, eventSource) {
|
|
355
|
+
let run = await this.openai.beta.threads.runs.retrieve(threadId, runId);
|
|
356
|
+
if (!run.required_action) {
|
|
357
|
+
throw new Error("No tool outputs required");
|
|
358
|
+
}
|
|
359
|
+
const toolCallsIds = run.required_action.submit_tool_outputs.tool_calls.map((toolCall) => toolCall.id);
|
|
360
|
+
const resultMessages = messages.filter((message) => message instanceof ResultMessage && toolCallsIds.includes(message.actionExecutionId));
|
|
361
|
+
if (toolCallsIds.length != resultMessages.length) {
|
|
362
|
+
throw new Error("Number of function results does not match the number of tool calls");
|
|
363
|
+
}
|
|
364
|
+
const toolOutputs = resultMessages.map((message) => {
|
|
365
|
+
return {
|
|
366
|
+
tool_call_id: message.actionExecutionId,
|
|
367
|
+
output: message.result
|
|
368
|
+
};
|
|
369
|
+
});
|
|
370
|
+
const stream = this.openai.beta.threads.runs.submitToolOutputsStream(threadId, runId, {
|
|
371
|
+
tool_outputs: toolOutputs
|
|
372
|
+
});
|
|
373
|
+
await this.streamResponse(stream, eventSource);
|
|
374
|
+
return runId;
|
|
375
|
+
}
|
|
376
|
+
async submitUserMessage(threadId, messages, actions, eventSource) {
|
|
377
|
+
messages = [
|
|
378
|
+
...messages
|
|
379
|
+
];
|
|
380
|
+
const instructionsMessage = messages.shift();
|
|
381
|
+
const instructions = instructionsMessage instanceof TextMessage ? instructionsMessage.content : "";
|
|
382
|
+
const userMessage = messages.map(convertMessageToOpenAIMessage).map(convertSystemMessageToAssistantAPI).at(-1);
|
|
383
|
+
if (userMessage.role !== "user") {
|
|
384
|
+
throw new Error("No user message found");
|
|
385
|
+
}
|
|
386
|
+
await this.openai.beta.threads.messages.create(threadId, {
|
|
387
|
+
role: "user",
|
|
388
|
+
content: userMessage.content
|
|
389
|
+
});
|
|
390
|
+
const openaiTools = actions.map(convertActionInputToOpenAITool);
|
|
391
|
+
const tools = [
|
|
392
|
+
...openaiTools,
|
|
393
|
+
...this.codeInterpreterEnabled ? [
|
|
394
|
+
{
|
|
395
|
+
type: "code_interpreter"
|
|
396
|
+
}
|
|
397
|
+
] : [],
|
|
398
|
+
...this.fileSearchEnabled ? [
|
|
399
|
+
{
|
|
400
|
+
type: "file_search"
|
|
401
|
+
}
|
|
402
|
+
] : []
|
|
403
|
+
];
|
|
404
|
+
let stream = this.openai.beta.threads.runs.stream(threadId, {
|
|
405
|
+
assistant_id: this.assistantId,
|
|
406
|
+
instructions,
|
|
407
|
+
tools
|
|
408
|
+
});
|
|
409
|
+
await this.streamResponse(stream, eventSource);
|
|
410
|
+
return getRunIdFromStream(stream);
|
|
411
|
+
}
|
|
412
|
+
async streamResponse(stream, eventSource) {
|
|
413
|
+
eventSource.stream(async (eventStream$) => {
|
|
414
|
+
var _a, _b, _c, _d, _e, _f;
|
|
415
|
+
let inFunctionCall = false;
|
|
416
|
+
for await (const chunk of stream) {
|
|
417
|
+
switch (chunk.event) {
|
|
418
|
+
case "thread.message.created":
|
|
419
|
+
if (inFunctionCall) {
|
|
420
|
+
eventStream$.sendActionExecutionEnd();
|
|
421
|
+
}
|
|
422
|
+
eventStream$.sendTextMessageStart(chunk.data.id);
|
|
423
|
+
break;
|
|
424
|
+
case "thread.message.delta":
|
|
425
|
+
if (((_a = chunk.data.delta.content) == null ? void 0 : _a[0].type) === "text") {
|
|
426
|
+
eventStream$.sendTextMessageContent((_b = chunk.data.delta.content) == null ? void 0 : _b[0].text.value);
|
|
427
|
+
}
|
|
428
|
+
break;
|
|
429
|
+
case "thread.message.completed":
|
|
430
|
+
eventStream$.sendTextMessageEnd();
|
|
431
|
+
break;
|
|
432
|
+
case "thread.run.step.delta":
|
|
433
|
+
let toolCallId;
|
|
434
|
+
let toolCallName;
|
|
435
|
+
let toolCallArgs;
|
|
436
|
+
if (chunk.data.delta.step_details.type === "tool_calls" && ((_c = chunk.data.delta.step_details.tool_calls) == null ? void 0 : _c[0].type) === "function") {
|
|
437
|
+
toolCallId = (_d = chunk.data.delta.step_details.tool_calls) == null ? void 0 : _d[0].id;
|
|
438
|
+
toolCallName = (_e = chunk.data.delta.step_details.tool_calls) == null ? void 0 : _e[0].function.name;
|
|
439
|
+
toolCallArgs = (_f = chunk.data.delta.step_details.tool_calls) == null ? void 0 : _f[0].function.arguments;
|
|
440
|
+
}
|
|
441
|
+
if (toolCallName && toolCallId) {
|
|
442
|
+
if (inFunctionCall) {
|
|
443
|
+
eventStream$.sendActionExecutionEnd();
|
|
444
|
+
}
|
|
445
|
+
inFunctionCall = true;
|
|
446
|
+
eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
|
|
447
|
+
} else if (toolCallArgs) {
|
|
448
|
+
eventStream$.sendActionExecutionArgs(toolCallArgs);
|
|
449
|
+
}
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
if (inFunctionCall) {
|
|
454
|
+
eventStream$.sendActionExecutionEnd();
|
|
455
|
+
}
|
|
456
|
+
eventStream$.complete();
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
__name(OpenAIAssistantAdapter, "OpenAIAssistantAdapter");
|
|
461
|
+
function getRunIdFromStream(stream) {
|
|
462
|
+
return new Promise((resolve, reject) => {
|
|
463
|
+
let runIdGetter = /* @__PURE__ */ __name((event) => {
|
|
464
|
+
if (event.event === "thread.run.created") {
|
|
465
|
+
const runId = event.data.id;
|
|
466
|
+
stream.off("event", runIdGetter);
|
|
467
|
+
resolve(runId);
|
|
468
|
+
}
|
|
469
|
+
}, "runIdGetter");
|
|
470
|
+
stream.on("event", runIdGetter);
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
__name(getRunIdFromStream, "getRunIdFromStream");
|
|
474
|
+
|
|
475
|
+
// src/service-adapters/google/google-genai-adapter.ts
|
|
476
|
+
var import_generative_ai = require("@google/generative-ai");
|
|
477
|
+
|
|
478
|
+
// src/service-adapters/google/utils.ts
|
|
479
|
+
function convertMessageToGoogleGenAIMessage(message) {
|
|
480
|
+
if (message instanceof TextMessage) {
|
|
481
|
+
const role = {
|
|
482
|
+
user: "user",
|
|
483
|
+
assistant: "model",
|
|
484
|
+
system: "user"
|
|
485
|
+
}[message.role];
|
|
486
|
+
const text = message.role === "system" ? "THE FOLLOWING MESSAGE IS A SYSTEM MESSAGE: " + message.content : message.content;
|
|
487
|
+
return {
|
|
488
|
+
role,
|
|
489
|
+
parts: [
|
|
490
|
+
{
|
|
491
|
+
text
|
|
492
|
+
}
|
|
493
|
+
]
|
|
494
|
+
};
|
|
495
|
+
} else if (message instanceof ActionExecutionMessage) {
|
|
496
|
+
return {
|
|
497
|
+
role: "model",
|
|
498
|
+
parts: [
|
|
499
|
+
{
|
|
500
|
+
functionCall: {
|
|
501
|
+
name: message.name,
|
|
502
|
+
args: message.arguments
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
]
|
|
506
|
+
};
|
|
507
|
+
} else if (message instanceof ResultMessage) {
|
|
508
|
+
return {
|
|
509
|
+
role: "model",
|
|
510
|
+
parts: [
|
|
511
|
+
{
|
|
512
|
+
functionResponse: {
|
|
513
|
+
name: message.actionName,
|
|
514
|
+
response: {
|
|
515
|
+
name: message.actionName,
|
|
516
|
+
content: tryParseJson(message.result)
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
]
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
__name(convertMessageToGoogleGenAIMessage, "convertMessageToGoogleGenAIMessage");
|
|
525
|
+
function transformActionToGoogleGenAITool(action) {
|
|
526
|
+
const name = action.name;
|
|
527
|
+
const description = action.description;
|
|
528
|
+
const parameters = JSON.parse(action.jsonSchema);
|
|
529
|
+
const transformProperties = /* @__PURE__ */ __name((props) => {
|
|
530
|
+
for (const key in props) {
|
|
531
|
+
if (props[key].type) {
|
|
532
|
+
props[key].type = props[key].type.toUpperCase();
|
|
533
|
+
}
|
|
534
|
+
if (props[key].properties) {
|
|
535
|
+
transformProperties(props[key].properties);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}, "transformProperties");
|
|
539
|
+
transformProperties(parameters);
|
|
540
|
+
return {
|
|
541
|
+
functionDeclarations: [
|
|
542
|
+
{
|
|
543
|
+
name,
|
|
544
|
+
description,
|
|
545
|
+
parameters
|
|
546
|
+
}
|
|
547
|
+
]
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
__name(transformActionToGoogleGenAITool, "transformActionToGoogleGenAITool");
|
|
551
|
+
function tryParseJson(str) {
|
|
552
|
+
if (!str) {
|
|
553
|
+
return "";
|
|
554
|
+
}
|
|
555
|
+
try {
|
|
556
|
+
return JSON.parse(str);
|
|
557
|
+
} catch (e) {
|
|
558
|
+
return str;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
__name(tryParseJson, "tryParseJson");
|
|
562
|
+
|
|
563
|
+
// src/service-adapters/google/google-genai-adapter.ts
|
|
564
|
+
var import_nanoid = require("nanoid");
|
|
565
|
+
var GoogleGenerativeAIAdapter = class {
|
|
566
|
+
model;
|
|
567
|
+
constructor(options) {
|
|
568
|
+
if (options == null ? void 0 : options.model) {
|
|
569
|
+
this.model = options.model;
|
|
570
|
+
} else {
|
|
571
|
+
const genAI = new import_generative_ai.GoogleGenerativeAI(process.env["GOOGLE_API_KEY"]);
|
|
572
|
+
this.model = genAI.getGenerativeModel({
|
|
573
|
+
model: "gemini-pro"
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
async process(request) {
|
|
578
|
+
const { messages, actions, eventSource } = request;
|
|
579
|
+
const history = messages.slice(1, -1).map(convertMessageToGoogleGenAIMessage);
|
|
580
|
+
const currentMessage = convertMessageToGoogleGenAIMessage(messages.at(-1));
|
|
581
|
+
if (!currentMessage) {
|
|
582
|
+
throw new Error("No current message");
|
|
583
|
+
}
|
|
584
|
+
let systemMessage;
|
|
585
|
+
const firstMessage = messages.at(0);
|
|
586
|
+
if (firstMessage instanceof TextMessage && firstMessage.role === "system") {
|
|
587
|
+
systemMessage = firstMessage.content.trim();
|
|
588
|
+
} else {
|
|
589
|
+
throw new Error("First message is not a system message");
|
|
590
|
+
}
|
|
591
|
+
const tools = actions.map(transformActionToGoogleGenAITool);
|
|
592
|
+
const isFirstGenGeminiPro = this.model.model === "gemini-pro" || this.model.model === "models/gemini-pro";
|
|
593
|
+
const chat = this.model.startChat({
|
|
594
|
+
history: [
|
|
595
|
+
...history,
|
|
596
|
+
// gemini-pro does not support system instructions, so we need to add them to the history
|
|
597
|
+
...isFirstGenGeminiPro ? [
|
|
598
|
+
{
|
|
599
|
+
role: "user",
|
|
600
|
+
parts: [
|
|
601
|
+
{
|
|
602
|
+
text: systemMessage
|
|
603
|
+
}
|
|
604
|
+
]
|
|
605
|
+
}
|
|
606
|
+
] : []
|
|
607
|
+
],
|
|
608
|
+
// only gemini-1.5-pro-latest and later supports setting system instructions
|
|
609
|
+
...isFirstGenGeminiPro ? {} : {
|
|
610
|
+
systemInstruction: {
|
|
611
|
+
role: "user",
|
|
612
|
+
parts: [
|
|
613
|
+
{
|
|
614
|
+
text: systemMessage
|
|
615
|
+
}
|
|
616
|
+
]
|
|
617
|
+
}
|
|
618
|
+
},
|
|
619
|
+
tools
|
|
620
|
+
});
|
|
621
|
+
const result = await chat.sendMessageStream(currentMessage.parts);
|
|
622
|
+
eventSource.stream(async (eventStream$) => {
|
|
623
|
+
let isTextMessage = false;
|
|
624
|
+
for await (const chunk of result.stream) {
|
|
625
|
+
const chunkText = chunk.text();
|
|
626
|
+
if (!isTextMessage) {
|
|
627
|
+
isTextMessage = true;
|
|
628
|
+
eventStream$.sendTextMessageStart((0, import_nanoid.nanoid)());
|
|
629
|
+
}
|
|
630
|
+
eventStream$.sendTextMessageContent(chunkText);
|
|
631
|
+
}
|
|
632
|
+
if (isTextMessage) {
|
|
633
|
+
eventStream$.sendTextMessageEnd();
|
|
634
|
+
}
|
|
635
|
+
let calls = (await result.response).functionCalls();
|
|
636
|
+
if (calls) {
|
|
637
|
+
for (let call of calls) {
|
|
638
|
+
eventStream$.sendActionExecution((0, import_nanoid.nanoid)(), call.name, JSON.stringify(replaceNewlinesInObject(call.args)));
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
eventStream$.complete();
|
|
642
|
+
});
|
|
643
|
+
return {};
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
__name(GoogleGenerativeAIAdapter, "GoogleGenerativeAIAdapter");
|
|
647
|
+
function replaceNewlinesInObject(obj) {
|
|
648
|
+
if (typeof obj === "string") {
|
|
649
|
+
return obj.replace(/\\\\n/g, "\n");
|
|
650
|
+
} else if (Array.isArray(obj)) {
|
|
651
|
+
return obj.map(replaceNewlinesInObject);
|
|
652
|
+
} else if (typeof obj === "object" && obj !== null) {
|
|
653
|
+
const newObj = {};
|
|
654
|
+
for (const key in obj) {
|
|
655
|
+
if (obj.hasOwnProperty(key)) {
|
|
656
|
+
newObj[key] = replaceNewlinesInObject(obj[key]);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
return newObj;
|
|
660
|
+
}
|
|
661
|
+
return obj;
|
|
662
|
+
}
|
|
663
|
+
__name(replaceNewlinesInObject, "replaceNewlinesInObject");
|
|
664
|
+
|
|
665
|
+
// src/service-adapters/langchain/utils.ts
|
|
666
|
+
var import_messages = require("@langchain/core/messages");
|
|
667
|
+
var import_tools = require("@langchain/core/tools");
|
|
668
|
+
var import_zod = require("zod");
|
|
669
|
+
var import_nanoid2 = require("nanoid");
|
|
670
|
+
function convertMessageToLangChainMessage(message) {
|
|
671
|
+
if (message instanceof TextMessage) {
|
|
672
|
+
if (message.role == "user") {
|
|
673
|
+
return new import_messages.HumanMessage(message.content);
|
|
674
|
+
} else if (message.role == "assistant") {
|
|
675
|
+
return new import_messages.AIMessage(message.content);
|
|
676
|
+
} else if (message.role === "system") {
|
|
677
|
+
return new import_messages.SystemMessage(message.content);
|
|
678
|
+
}
|
|
679
|
+
} else if (message instanceof ActionExecutionMessage) {
|
|
680
|
+
return new import_messages.AIMessage({
|
|
681
|
+
content: "",
|
|
682
|
+
tool_calls: [
|
|
683
|
+
{
|
|
684
|
+
id: message.id,
|
|
685
|
+
args: message.arguments,
|
|
686
|
+
name: message.name
|
|
687
|
+
}
|
|
688
|
+
]
|
|
689
|
+
});
|
|
690
|
+
} else if (message instanceof ResultMessage) {
|
|
691
|
+
return new import_messages.ToolMessage({
|
|
692
|
+
content: message.result,
|
|
693
|
+
tool_call_id: message.actionExecutionId
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
__name(convertMessageToLangChainMessage, "convertMessageToLangChainMessage");
|
|
698
|
+
function convertJsonSchemaToZodSchema(jsonSchema, required) {
|
|
699
|
+
if (jsonSchema.type === "object") {
|
|
700
|
+
const spec = {};
|
|
701
|
+
for (const [key, value] of Object.entries(jsonSchema.properties)) {
|
|
702
|
+
spec[key] = convertJsonSchemaToZodSchema(value, jsonSchema.required ? jsonSchema.required.includes(key) : false);
|
|
703
|
+
}
|
|
704
|
+
let schema = import_zod.z.object(spec);
|
|
705
|
+
return !required ? schema.optional() : schema;
|
|
706
|
+
} else if (jsonSchema.type === "string") {
|
|
707
|
+
let schema = import_zod.z.string().describe(jsonSchema.description);
|
|
708
|
+
return !required ? schema.optional() : schema;
|
|
709
|
+
} else if (jsonSchema.type === "number") {
|
|
710
|
+
let schema = import_zod.z.number().describe(jsonSchema.description);
|
|
711
|
+
return !required ? schema.optional() : schema;
|
|
712
|
+
} else if (jsonSchema.type === "boolean") {
|
|
713
|
+
let schema = import_zod.z.boolean().describe(jsonSchema.description);
|
|
714
|
+
return !required ? schema.optional() : schema;
|
|
715
|
+
} else if (jsonSchema.type === "array") {
|
|
716
|
+
let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, false);
|
|
717
|
+
let schema = import_zod.z.array(itemSchema);
|
|
718
|
+
return !required ? schema.optional() : schema;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
__name(convertJsonSchemaToZodSchema, "convertJsonSchemaToZodSchema");
|
|
722
|
+
function convertActionInputToLangChainTool(actionInput) {
|
|
723
|
+
return new import_tools.DynamicStructuredTool({
|
|
724
|
+
name: actionInput.name,
|
|
725
|
+
description: actionInput.description,
|
|
726
|
+
schema: convertJsonSchemaToZodSchema(JSON.parse(actionInput.jsonSchema), true),
|
|
727
|
+
func: async () => {
|
|
728
|
+
return "";
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
__name(convertActionInputToLangChainTool, "convertActionInputToLangChainTool");
|
|
733
|
+
async function streamLangChainResponse({ result, eventStream$, actionExecution }) {
|
|
734
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
735
|
+
if (typeof result === "string") {
|
|
736
|
+
if (!actionExecution) {
|
|
737
|
+
eventStream$.sendTextMessage((0, import_nanoid2.nanoid)(), result);
|
|
738
|
+
} else {
|
|
739
|
+
eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, result);
|
|
740
|
+
}
|
|
741
|
+
} else if (result instanceof import_messages.AIMessage) {
|
|
742
|
+
if (result.content) {
|
|
743
|
+
eventStream$.sendTextMessage((0, import_nanoid2.nanoid)(), result.content);
|
|
744
|
+
}
|
|
745
|
+
for (const toolCall of result.tool_calls) {
|
|
746
|
+
eventStream$.sendActionExecution(toolCall.id || (0, import_nanoid2.nanoid)(), toolCall.name, JSON.stringify(toolCall.args));
|
|
747
|
+
}
|
|
748
|
+
} else if (result instanceof import_messages.BaseMessageChunk) {
|
|
749
|
+
if ((_a = result.lc_kwargs) == null ? void 0 : _a.content) {
|
|
750
|
+
eventStream$.sendTextMessage((0, import_nanoid2.nanoid)(), result.content);
|
|
751
|
+
}
|
|
752
|
+
if ((_b = result.lc_kwargs) == null ? void 0 : _b.tool_calls) {
|
|
753
|
+
for (const toolCall of (_c = result.lc_kwargs) == null ? void 0 : _c.tool_calls) {
|
|
754
|
+
eventStream$.sendActionExecution(toolCall.id || (0, import_nanoid2.nanoid)(), toolCall.name, JSON.stringify(toolCall.args));
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
} else if ("getReader" in result) {
|
|
758
|
+
let reader = result.getReader();
|
|
759
|
+
let mode = null;
|
|
760
|
+
while (true) {
|
|
761
|
+
try {
|
|
762
|
+
const { done, value } = await reader.read();
|
|
763
|
+
let toolCallName = void 0;
|
|
764
|
+
let toolCallId = void 0;
|
|
765
|
+
let toolCallArgs = void 0;
|
|
766
|
+
let hasToolCall = false;
|
|
767
|
+
let content = value.content;
|
|
768
|
+
if (value instanceof import_messages.AIMessageChunk) {
|
|
769
|
+
let chunk = (_d = value.tool_call_chunks) == null ? void 0 : _d[0];
|
|
770
|
+
toolCallName = chunk == null ? void 0 : chunk.name;
|
|
771
|
+
toolCallId = chunk == null ? void 0 : chunk.id;
|
|
772
|
+
toolCallArgs = chunk == null ? void 0 : chunk.args;
|
|
773
|
+
hasToolCall = chunk != void 0;
|
|
774
|
+
} else if (value instanceof import_messages.BaseMessageChunk) {
|
|
775
|
+
let chunk = (_f = (_e = value.additional_kwargs) == null ? void 0 : _e.tool_calls) == null ? void 0 : _f[0];
|
|
776
|
+
toolCallName = (_g = chunk == null ? void 0 : chunk.function) == null ? void 0 : _g.name;
|
|
777
|
+
toolCallId = chunk == null ? void 0 : chunk.id;
|
|
778
|
+
toolCallArgs = (_h = chunk == null ? void 0 : chunk.function) == null ? void 0 : _h.arguments;
|
|
779
|
+
hasToolCall = (chunk == null ? void 0 : chunk.function) != void 0;
|
|
780
|
+
}
|
|
781
|
+
if (mode === "message" && (toolCallId || done)) {
|
|
782
|
+
mode = null;
|
|
783
|
+
eventStream$.sendTextMessageEnd();
|
|
784
|
+
} else if (mode === "function" && (!hasToolCall || done)) {
|
|
785
|
+
mode = null;
|
|
786
|
+
eventStream$.sendActionExecutionEnd();
|
|
787
|
+
}
|
|
788
|
+
if (done) {
|
|
789
|
+
break;
|
|
790
|
+
}
|
|
791
|
+
if (mode === null) {
|
|
792
|
+
if (hasToolCall) {
|
|
793
|
+
mode = "function";
|
|
794
|
+
eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
|
|
795
|
+
} else if (content) {
|
|
796
|
+
mode = "message";
|
|
797
|
+
eventStream$.sendTextMessageStart((0, import_nanoid2.nanoid)());
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
if (mode === "message" && content) {
|
|
801
|
+
eventStream$.sendTextMessageContent(content);
|
|
802
|
+
} else if (mode === "function" && toolCallArgs) {
|
|
803
|
+
eventStream$.sendActionExecutionArgs(toolCallArgs);
|
|
804
|
+
}
|
|
805
|
+
} catch (error) {
|
|
806
|
+
console.error("Error reading from stream", error);
|
|
807
|
+
break;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
} else if (actionExecution) {
|
|
811
|
+
eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, JSON.stringify(result));
|
|
812
|
+
} else {
|
|
813
|
+
throw new Error("Invalid return type from LangChain function.");
|
|
814
|
+
}
|
|
815
|
+
eventStream$.complete();
|
|
816
|
+
}
|
|
817
|
+
__name(streamLangChainResponse, "streamLangChainResponse");
|
|
818
|
+
|
|
819
|
+
// src/service-adapters/langchain/langchain-adapter.ts
|
|
820
|
+
var LangChainAdapter = class {
|
|
821
|
+
options;
|
|
822
|
+
/**
|
|
823
|
+
* To use LangChain as a backend, provide a handler function to the adapter with your custom LangChain logic.
|
|
824
|
+
*/
|
|
825
|
+
constructor(options) {
|
|
826
|
+
this.options = options;
|
|
827
|
+
}
|
|
828
|
+
async process({ eventSource, model, actions, messages, threadId, runId }) {
|
|
829
|
+
const result = await this.options.chainFn({
|
|
830
|
+
messages: messages.map(convertMessageToLangChainMessage),
|
|
831
|
+
tools: actions.map(convertActionInputToLangChainTool),
|
|
832
|
+
model,
|
|
833
|
+
threadId,
|
|
834
|
+
runId
|
|
835
|
+
});
|
|
836
|
+
eventSource.stream(async (eventStream$) => {
|
|
837
|
+
await streamLangChainResponse({
|
|
838
|
+
result,
|
|
839
|
+
eventStream$
|
|
840
|
+
});
|
|
841
|
+
});
|
|
842
|
+
return {};
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
__name(LangChainAdapter, "LangChainAdapter");
|
|
846
|
+
|
|
847
|
+
// src/service-adapters/langchain/langserve.ts
|
|
848
|
+
var import_remote = require("langchain/runnables/remote");
|
|
849
|
+
var RemoteChain = class {
|
|
850
|
+
constructor(options) {
|
|
851
|
+
this.name = options.name;
|
|
852
|
+
this.description = options.description;
|
|
853
|
+
this.chainUrl = options.chainUrl;
|
|
854
|
+
this.parameters = options.parameters;
|
|
855
|
+
this.parameterType = options.parameterType || "multi";
|
|
856
|
+
}
|
|
857
|
+
async toAction() {
|
|
858
|
+
if (!this.parameters) {
|
|
859
|
+
await this.inferLangServeParameters();
|
|
860
|
+
}
|
|
861
|
+
return {
|
|
862
|
+
name: this.name,
|
|
863
|
+
description: this.description,
|
|
864
|
+
parameters: this.parameters,
|
|
865
|
+
handler: async (args) => {
|
|
866
|
+
const runnable = new import_remote.RemoteRunnable({
|
|
867
|
+
url: this.chainUrl
|
|
868
|
+
});
|
|
869
|
+
let input;
|
|
870
|
+
if (this.parameterType === "single") {
|
|
871
|
+
input = args[Object.keys(args)[0]];
|
|
872
|
+
} else {
|
|
873
|
+
input = args;
|
|
874
|
+
}
|
|
875
|
+
return await runnable.invoke(input);
|
|
876
|
+
}
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
async inferLangServeParameters() {
|
|
880
|
+
const supportedTypes = [
|
|
881
|
+
"string",
|
|
882
|
+
"number",
|
|
883
|
+
"boolean"
|
|
884
|
+
];
|
|
885
|
+
let schemaUrl = this.chainUrl.replace(/\/+$/, "") + "/input_schema";
|
|
886
|
+
let schema = await fetch(schemaUrl).then((res) => res.json()).catch(() => {
|
|
887
|
+
throw new Error("Failed to fetch langserve schema at " + schemaUrl);
|
|
888
|
+
});
|
|
889
|
+
if (supportedTypes.includes(schema.type)) {
|
|
890
|
+
this.parameterType = "single";
|
|
891
|
+
this.parameters = [
|
|
892
|
+
{
|
|
893
|
+
name: "input",
|
|
894
|
+
type: schema.type,
|
|
895
|
+
description: "The input to the chain"
|
|
896
|
+
}
|
|
897
|
+
];
|
|
898
|
+
} else if (schema.type === "object") {
|
|
899
|
+
this.parameterType = "multi";
|
|
900
|
+
this.parameters = Object.keys(schema.properties).map((key) => {
|
|
901
|
+
var _a;
|
|
902
|
+
let property = schema.properties[key];
|
|
903
|
+
if (!supportedTypes.includes(property.type)) {
|
|
904
|
+
throw new Error("Unsupported schema type");
|
|
905
|
+
}
|
|
906
|
+
return {
|
|
907
|
+
name: key,
|
|
908
|
+
type: property.type,
|
|
909
|
+
description: property.description || "",
|
|
910
|
+
required: ((_a = schema.required) == null ? void 0 : _a.includes(key)) || false
|
|
911
|
+
};
|
|
912
|
+
});
|
|
913
|
+
} else {
|
|
914
|
+
throw new Error("Unsupported schema type");
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
};
|
|
918
|
+
__name(RemoteChain, "RemoteChain");
|
|
919
|
+
|
|
920
|
+
// src/lib/copilot-cloud.ts
|
|
921
|
+
var import_shared = require("@copilotkit/shared");
|
|
922
|
+
var CopilotCloud = class {
|
|
923
|
+
};
|
|
924
|
+
__name(CopilotCloud, "CopilotCloud");
|
|
925
|
+
var RemoteCopilotCloud = class extends CopilotCloud {
|
|
926
|
+
cloudApiUrl;
|
|
927
|
+
constructor(cloudApiUrl = import_shared.COPILOT_CLOUD_API_URL) {
|
|
928
|
+
super();
|
|
929
|
+
this.cloudApiUrl = cloudApiUrl;
|
|
930
|
+
}
|
|
931
|
+
async checkGuardrailsInput({ cloud, publicApiKey, messages }) {
|
|
932
|
+
const url = `${this.cloudApiUrl}/${import_shared.COPILOT_CLOUD_VERSION}/copilotkit/guardrails/input`;
|
|
933
|
+
const response = await fetch(url, {
|
|
934
|
+
method: "PUT",
|
|
935
|
+
headers: {
|
|
936
|
+
"Content-Type": "application/json",
|
|
937
|
+
[import_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey
|
|
938
|
+
},
|
|
939
|
+
body: JSON.stringify({
|
|
940
|
+
messages,
|
|
941
|
+
cloud
|
|
942
|
+
})
|
|
943
|
+
});
|
|
944
|
+
if (!response.ok) {
|
|
945
|
+
let message = response.statusText;
|
|
946
|
+
try {
|
|
947
|
+
const json2 = await response.json();
|
|
948
|
+
if (json2.message) {
|
|
949
|
+
message = json2.message;
|
|
950
|
+
}
|
|
951
|
+
} catch (error) {
|
|
952
|
+
}
|
|
953
|
+
throw new Error("Failed to check input guardrails: " + message);
|
|
954
|
+
}
|
|
955
|
+
const json = await response.json();
|
|
956
|
+
return {
|
|
957
|
+
status: json.status,
|
|
958
|
+
reason: json.reason
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
};
|
|
962
|
+
__name(RemoteCopilotCloud, "RemoteCopilotCloud");
|
|
963
|
+
|
|
964
|
+
// src/service-adapters/events.ts
|
|
965
|
+
var import_rxjs = require("rxjs");
|
|
966
|
+
var RuntimeEventTypes;
|
|
967
|
+
(function(RuntimeEventTypes2) {
|
|
968
|
+
RuntimeEventTypes2["TextMessageStart"] = "TextMessageStart";
|
|
969
|
+
RuntimeEventTypes2["TextMessageContent"] = "TextMessageContent";
|
|
970
|
+
RuntimeEventTypes2["TextMessageEnd"] = "TextMessageEnd";
|
|
971
|
+
RuntimeEventTypes2["ActionExecutionStart"] = "ActionExecutionStart";
|
|
972
|
+
RuntimeEventTypes2["ActionExecutionArgs"] = "ActionExecutionArgs";
|
|
973
|
+
RuntimeEventTypes2["ActionExecutionEnd"] = "ActionExecutionEnd";
|
|
974
|
+
RuntimeEventTypes2["ActionExecutionResult"] = "ActionExecutionResult";
|
|
975
|
+
})(RuntimeEventTypes || (RuntimeEventTypes = {}));
|
|
976
|
+
var RuntimeEventSubject = class extends import_rxjs.ReplaySubject {
|
|
977
|
+
constructor() {
|
|
978
|
+
super();
|
|
979
|
+
}
|
|
980
|
+
sendTextMessageStart(messageId) {
|
|
981
|
+
this.next({
|
|
982
|
+
type: "TextMessageStart",
|
|
983
|
+
messageId
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
sendTextMessageContent(content) {
|
|
987
|
+
this.next({
|
|
988
|
+
type: "TextMessageContent",
|
|
989
|
+
content
|
|
990
|
+
});
|
|
991
|
+
}
|
|
992
|
+
sendTextMessageEnd() {
|
|
993
|
+
this.next({
|
|
994
|
+
type: "TextMessageEnd"
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
sendTextMessage(messageId, content) {
|
|
998
|
+
this.sendTextMessageStart(messageId);
|
|
999
|
+
this.sendTextMessageContent(content);
|
|
1000
|
+
this.sendTextMessageEnd();
|
|
1001
|
+
}
|
|
1002
|
+
sendActionExecutionStart(actionExecutionId, actionName) {
|
|
1003
|
+
this.next({
|
|
1004
|
+
type: "ActionExecutionStart",
|
|
1005
|
+
actionExecutionId,
|
|
1006
|
+
actionName
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
sendActionExecutionArgs(args) {
|
|
1010
|
+
this.next({
|
|
1011
|
+
type: "ActionExecutionArgs",
|
|
1012
|
+
args
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
sendActionExecutionEnd() {
|
|
1016
|
+
this.next({
|
|
1017
|
+
type: "ActionExecutionEnd"
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
sendActionExecution(actionExecutionId, toolName, args) {
|
|
1021
|
+
this.sendActionExecutionStart(actionExecutionId, toolName);
|
|
1022
|
+
this.sendActionExecutionArgs(args);
|
|
1023
|
+
this.sendActionExecutionEnd();
|
|
1024
|
+
}
|
|
1025
|
+
sendActionExecutionResult(actionExecutionId, actionName, result) {
|
|
1026
|
+
this.next({
|
|
1027
|
+
type: "ActionExecutionResult",
|
|
1028
|
+
actionName,
|
|
1029
|
+
actionExecutionId,
|
|
1030
|
+
result
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
};
|
|
1034
|
+
__name(RuntimeEventSubject, "RuntimeEventSubject");
|
|
1035
|
+
var RuntimeEventSource = class {
|
|
1036
|
+
eventStream$ = new RuntimeEventSubject();
|
|
1037
|
+
callback;
|
|
1038
|
+
async stream(callback) {
|
|
1039
|
+
this.callback = callback;
|
|
1040
|
+
}
|
|
1041
|
+
process(serversideActions) {
|
|
1042
|
+
this.callback(this.eventStream$).catch((error) => {
|
|
1043
|
+
console.error("Error in event source callback", error);
|
|
1044
|
+
});
|
|
1045
|
+
return this.eventStream$.pipe(
|
|
1046
|
+
// mark tools for server side execution
|
|
1047
|
+
(0, import_rxjs.map)((event) => {
|
|
1048
|
+
if (event.type === "ActionExecutionStart") {
|
|
1049
|
+
event.scope = serversideActions.find((action) => action.name === event.actionName) ? "server" : "client";
|
|
1050
|
+
}
|
|
1051
|
+
return event;
|
|
1052
|
+
}),
|
|
1053
|
+
// track state
|
|
1054
|
+
(0, import_rxjs.scan)((acc, event) => {
|
|
1055
|
+
if (event.type === "ActionExecutionStart") {
|
|
1056
|
+
acc.callActionServerSide = event.scope === "server";
|
|
1057
|
+
acc.args = "";
|
|
1058
|
+
acc.actionExecutionId = event.actionExecutionId;
|
|
1059
|
+
if (acc.callActionServerSide) {
|
|
1060
|
+
acc.action = serversideActions.find((action) => action.name === event.actionName);
|
|
1061
|
+
}
|
|
1062
|
+
} else if (event.type === "ActionExecutionArgs") {
|
|
1063
|
+
acc.args += event.args;
|
|
1064
|
+
}
|
|
1065
|
+
acc.event = event;
|
|
1066
|
+
return acc;
|
|
1067
|
+
}, {
|
|
1068
|
+
event: null,
|
|
1069
|
+
callActionServerSide: false,
|
|
1070
|
+
args: "",
|
|
1071
|
+
actionExecutionId: null,
|
|
1072
|
+
action: null
|
|
1073
|
+
}),
|
|
1074
|
+
(0, import_rxjs.concatMap)((eventWithState) => {
|
|
1075
|
+
if (eventWithState.event.type === "ActionExecutionEnd" && eventWithState.callActionServerSide) {
|
|
1076
|
+
const toolCallEventStream$ = new RuntimeEventSubject();
|
|
1077
|
+
executeAction(toolCallEventStream$, eventWithState.action, eventWithState.args, eventWithState.actionExecutionId).catch((error) => {
|
|
1078
|
+
console.error(error);
|
|
1079
|
+
});
|
|
1080
|
+
return (0, import_rxjs.concat)((0, import_rxjs.of)(eventWithState.event), toolCallEventStream$);
|
|
1081
|
+
} else {
|
|
1082
|
+
return (0, import_rxjs.of)(eventWithState.event);
|
|
1083
|
+
}
|
|
1084
|
+
})
|
|
1085
|
+
);
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1088
|
+
__name(RuntimeEventSource, "RuntimeEventSource");
|
|
1089
|
+
async function executeAction(eventStream$, action, actionArguments, actionExecutionId) {
|
|
1090
|
+
let args = [];
|
|
1091
|
+
if (actionArguments) {
|
|
1092
|
+
args = JSON.parse(actionArguments);
|
|
1093
|
+
}
|
|
1094
|
+
const result = await action.handler(args);
|
|
1095
|
+
await streamLangChainResponse({
|
|
1096
|
+
result,
|
|
1097
|
+
eventStream$,
|
|
1098
|
+
actionExecution: {
|
|
1099
|
+
name: action.name,
|
|
1100
|
+
id: actionExecutionId
|
|
1101
|
+
}
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
__name(executeAction, "executeAction");
|
|
1105
|
+
|
|
1106
|
+
// src/service-adapters/conversion.ts
|
|
1107
|
+
var import_class_transformer = require("class-transformer");
|
|
1108
|
+
function convertGqlInputToMessages(inputMessages) {
|
|
1109
|
+
const messages = [];
|
|
1110
|
+
for (const message of inputMessages) {
|
|
1111
|
+
if (message.textMessage) {
|
|
1112
|
+
messages.push((0, import_class_transformer.plainToInstance)(TextMessage, {
|
|
1113
|
+
id: message.id,
|
|
1114
|
+
createdAt: message.createdAt,
|
|
1115
|
+
role: message.textMessage.role,
|
|
1116
|
+
content: message.textMessage.content
|
|
1117
|
+
}));
|
|
1118
|
+
} else if (message.actionExecutionMessage) {
|
|
1119
|
+
messages.push((0, import_class_transformer.plainToInstance)(ActionExecutionMessage, {
|
|
1120
|
+
id: message.id,
|
|
1121
|
+
createdAt: message.createdAt,
|
|
1122
|
+
name: message.actionExecutionMessage.name,
|
|
1123
|
+
arguments: JSON.parse(message.actionExecutionMessage.arguments),
|
|
1124
|
+
scope: message.actionExecutionMessage.scope
|
|
1125
|
+
}));
|
|
1126
|
+
} else if (message.resultMessage) {
|
|
1127
|
+
messages.push((0, import_class_transformer.plainToInstance)(ResultMessage, {
|
|
1128
|
+
id: message.id,
|
|
1129
|
+
createdAt: message.createdAt,
|
|
1130
|
+
actionExecutionId: message.resultMessage.actionExecutionId,
|
|
1131
|
+
actionName: message.resultMessage.actionName,
|
|
1132
|
+
result: message.resultMessage.result
|
|
1133
|
+
}));
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
return messages;
|
|
1137
|
+
}
|
|
1138
|
+
__name(convertGqlInputToMessages, "convertGqlInputToMessages");
|
|
1139
|
+
|
|
1140
|
+
// src/lib/copilot-runtime.ts
|
|
1141
|
+
var CopilotRuntime = class {
|
|
1142
|
+
actions = [];
|
|
1143
|
+
langserve = [];
|
|
1144
|
+
debug = false;
|
|
1145
|
+
copilotCloud;
|
|
1146
|
+
constructor(params) {
|
|
1147
|
+
this.actions = (params == null ? void 0 : params.actions) || [];
|
|
1148
|
+
for (const chain of (params == null ? void 0 : params.langserve) || []) {
|
|
1149
|
+
const remoteChain = new RemoteChain(chain);
|
|
1150
|
+
this.langserve.push(remoteChain.toAction());
|
|
1151
|
+
}
|
|
1152
|
+
this.debug = (params == null ? void 0 : params.debug) || false;
|
|
1153
|
+
this.copilotCloud = (params == null ? void 0 : params.copilotCloud) || new RemoteCopilotCloud();
|
|
1154
|
+
}
|
|
1155
|
+
addAction(action) {
|
|
1156
|
+
this.removeAction(action.name);
|
|
1157
|
+
this.actions.push(action);
|
|
1158
|
+
}
|
|
1159
|
+
removeAction(actionName) {
|
|
1160
|
+
this.actions = this.actions.filter((f) => f.name !== actionName);
|
|
1161
|
+
}
|
|
1162
|
+
async process({ serviceAdapter, messages, actions: clientSideActionsInput, threadId, runId, publicApiKey }) {
|
|
1163
|
+
const langserveFunctions = [];
|
|
1164
|
+
for (const chainPromise of this.langserve) {
|
|
1165
|
+
try {
|
|
1166
|
+
const chain = await chainPromise;
|
|
1167
|
+
langserveFunctions.push(chain);
|
|
1168
|
+
} catch (error) {
|
|
1169
|
+
console.error("Error loading langserve chain:", error);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
const serverSideActionsInput = [
|
|
1173
|
+
...this.actions,
|
|
1174
|
+
...langserveFunctions
|
|
1175
|
+
].map((action) => ({
|
|
1176
|
+
name: action.name,
|
|
1177
|
+
description: action.description,
|
|
1178
|
+
jsonSchema: JSON.stringify((0, import_shared2.actionParametersToJsonSchema)(action.parameters))
|
|
1179
|
+
}));
|
|
1180
|
+
const actions = flattenToolCallsNoDuplicates([
|
|
1181
|
+
...serverSideActionsInput,
|
|
1182
|
+
...clientSideActionsInput
|
|
1183
|
+
]);
|
|
1184
|
+
try {
|
|
1185
|
+
const eventSource = new RuntimeEventSource();
|
|
1186
|
+
const result = await serviceAdapter.process({
|
|
1187
|
+
messages: convertGqlInputToMessages(messages),
|
|
1188
|
+
actions,
|
|
1189
|
+
threadId,
|
|
1190
|
+
runId,
|
|
1191
|
+
eventSource
|
|
1192
|
+
});
|
|
1193
|
+
return {
|
|
1194
|
+
threadId: result.threadId,
|
|
1195
|
+
runId: result.runId,
|
|
1196
|
+
eventSource
|
|
1197
|
+
};
|
|
1198
|
+
} catch (error) {
|
|
1199
|
+
console.error("Error getting response:", error);
|
|
1200
|
+
throw error;
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
};
|
|
1204
|
+
__name(CopilotRuntime, "CopilotRuntime");
|
|
1205
|
+
function flattenToolCallsNoDuplicates(toolsByPriority) {
|
|
1206
|
+
let allTools = [];
|
|
1207
|
+
const allToolNames = [];
|
|
1208
|
+
for (const tool of toolsByPriority) {
|
|
1209
|
+
if (!allToolNames.includes(tool.name)) {
|
|
1210
|
+
allTools.push(tool);
|
|
1211
|
+
allToolNames.push(tool.name);
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
return allTools;
|
|
1215
|
+
}
|
|
1216
|
+
__name(flattenToolCallsNoDuplicates, "flattenToolCallsNoDuplicates");
|
|
1217
|
+
var CopilotBackend = class extends CopilotRuntime {
|
|
1218
|
+
};
|
|
1219
|
+
__name(CopilotBackend, "CopilotBackend");
|
|
1220
|
+
|
|
1221
|
+
// src/lib/integrations/shared.ts
|
|
1222
|
+
var import_type_graphql13 = require("type-graphql");
|
|
1223
|
+
|
|
1224
|
+
// src/graphql/resolvers/copilot.resolver.ts
|
|
1225
|
+
var import_type_graphql12 = require("type-graphql");
|
|
1226
|
+
var import_rxjs2 = require("rxjs");
|
|
1227
|
+
|
|
1228
|
+
// src/graphql/inputs/generate-copilot-response.input.ts
|
|
1229
|
+
var import_type_graphql8 = require("type-graphql");
|
|
1230
|
+
|
|
1231
|
+
// src/graphql/inputs/message.input.ts
|
|
1232
|
+
var import_type_graphql3 = require("type-graphql");
|
|
1233
|
+
|
|
1234
|
+
// src/graphql/types/enums.ts
|
|
1235
|
+
var import_type_graphql2 = require("type-graphql");
|
|
1236
|
+
var MessageRole;
|
|
1237
|
+
(function(MessageRole2) {
|
|
1238
|
+
MessageRole2["user"] = "user";
|
|
1239
|
+
MessageRole2["assistant"] = "assistant";
|
|
1240
|
+
MessageRole2["system"] = "system";
|
|
1241
|
+
})(MessageRole || (MessageRole = {}));
|
|
1242
|
+
var ActionExecutionScope;
|
|
1243
|
+
(function(ActionExecutionScope2) {
|
|
1244
|
+
ActionExecutionScope2["server"] = "server";
|
|
1245
|
+
ActionExecutionScope2["client"] = "client";
|
|
1246
|
+
})(ActionExecutionScope || (ActionExecutionScope = {}));
|
|
1247
|
+
(0, import_type_graphql2.registerEnumType)(MessageRole, {
|
|
1248
|
+
name: "MessageRole",
|
|
1249
|
+
description: "The role of the message"
|
|
1250
|
+
});
|
|
1251
|
+
(0, import_type_graphql2.registerEnumType)(ActionExecutionScope, {
|
|
1252
|
+
name: "ActionExecutionScope",
|
|
1253
|
+
description: "The scope of the action"
|
|
1254
|
+
});
|
|
1255
|
+
|
|
1256
|
+
// src/graphql/inputs/message.input.ts
|
|
1257
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
1258
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1259
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
1260
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
1261
|
+
else
|
|
1262
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
1263
|
+
if (d = decorators[i])
|
|
1264
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1265
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1266
|
+
}
|
|
1267
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
1268
|
+
function _ts_metadata2(k, v) {
|
|
1269
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
1270
|
+
return Reflect.metadata(k, v);
|
|
1271
|
+
}
|
|
1272
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
1273
|
+
var MessageInput = class extends BaseMessage {
|
|
1274
|
+
textMessage;
|
|
1275
|
+
actionExecutionMessage;
|
|
1276
|
+
resultMessage;
|
|
1277
|
+
};
|
|
1278
|
+
__name(MessageInput, "MessageInput");
|
|
1279
|
+
_ts_decorate2([
|
|
1280
|
+
(0, import_type_graphql3.Field)(() => TextMessageInput, {
|
|
1281
|
+
nullable: true
|
|
1282
|
+
}),
|
|
1283
|
+
_ts_metadata2("design:type", typeof TextMessageInput === "undefined" ? Object : TextMessageInput)
|
|
1284
|
+
], MessageInput.prototype, "textMessage", void 0);
|
|
1285
|
+
_ts_decorate2([
|
|
1286
|
+
(0, import_type_graphql3.Field)(() => ActionExecutionMessageInput, {
|
|
1287
|
+
nullable: true
|
|
1288
|
+
}),
|
|
1289
|
+
_ts_metadata2("design:type", typeof ActionExecutionMessageInput === "undefined" ? Object : ActionExecutionMessageInput)
|
|
1290
|
+
], MessageInput.prototype, "actionExecutionMessage", void 0);
|
|
1291
|
+
_ts_decorate2([
|
|
1292
|
+
(0, import_type_graphql3.Field)(() => ResultMessageInput, {
|
|
1293
|
+
nullable: true
|
|
1294
|
+
}),
|
|
1295
|
+
_ts_metadata2("design:type", typeof ResultMessageInput === "undefined" ? Object : ResultMessageInput)
|
|
1296
|
+
], MessageInput.prototype, "resultMessage", void 0);
|
|
1297
|
+
MessageInput = _ts_decorate2([
|
|
1298
|
+
(0, import_type_graphql3.InputType)()
|
|
1299
|
+
], MessageInput);
|
|
1300
|
+
var TextMessageInput = class {
|
|
1301
|
+
content;
|
|
1302
|
+
role;
|
|
1303
|
+
};
|
|
1304
|
+
__name(TextMessageInput, "TextMessageInput");
|
|
1305
|
+
_ts_decorate2([
|
|
1306
|
+
(0, import_type_graphql3.Field)(() => String),
|
|
1307
|
+
_ts_metadata2("design:type", String)
|
|
1308
|
+
], TextMessageInput.prototype, "content", void 0);
|
|
1309
|
+
_ts_decorate2([
|
|
1310
|
+
(0, import_type_graphql3.Field)(() => MessageRole),
|
|
1311
|
+
_ts_metadata2("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
|
|
1312
|
+
], TextMessageInput.prototype, "role", void 0);
|
|
1313
|
+
TextMessageInput = _ts_decorate2([
|
|
1314
|
+
(0, import_type_graphql3.InputType)()
|
|
1315
|
+
], TextMessageInput);
|
|
1316
|
+
var ActionExecutionMessageInput = class {
|
|
1317
|
+
name;
|
|
1318
|
+
arguments;
|
|
1319
|
+
scope;
|
|
1320
|
+
};
|
|
1321
|
+
__name(ActionExecutionMessageInput, "ActionExecutionMessageInput");
|
|
1322
|
+
_ts_decorate2([
|
|
1323
|
+
(0, import_type_graphql3.Field)(() => String),
|
|
1324
|
+
_ts_metadata2("design:type", String)
|
|
1325
|
+
], ActionExecutionMessageInput.prototype, "name", void 0);
|
|
1326
|
+
_ts_decorate2([
|
|
1327
|
+
(0, import_type_graphql3.Field)(() => String),
|
|
1328
|
+
_ts_metadata2("design:type", String)
|
|
1329
|
+
], ActionExecutionMessageInput.prototype, "arguments", void 0);
|
|
1330
|
+
_ts_decorate2([
|
|
1331
|
+
(0, import_type_graphql3.Field)(() => ActionExecutionScope),
|
|
1332
|
+
_ts_metadata2("design:type", typeof ActionExecutionScope === "undefined" ? Object : ActionExecutionScope)
|
|
1333
|
+
], ActionExecutionMessageInput.prototype, "scope", void 0);
|
|
1334
|
+
ActionExecutionMessageInput = _ts_decorate2([
|
|
1335
|
+
(0, import_type_graphql3.InputType)()
|
|
1336
|
+
], ActionExecutionMessageInput);
|
|
1337
|
+
var ResultMessageInput = class {
|
|
1338
|
+
actionExecutionId;
|
|
1339
|
+
actionName;
|
|
1340
|
+
result;
|
|
1341
|
+
};
|
|
1342
|
+
__name(ResultMessageInput, "ResultMessageInput");
|
|
1343
|
+
_ts_decorate2([
|
|
1344
|
+
(0, import_type_graphql3.Field)(() => String),
|
|
1345
|
+
_ts_metadata2("design:type", String)
|
|
1346
|
+
], ResultMessageInput.prototype, "actionExecutionId", void 0);
|
|
1347
|
+
_ts_decorate2([
|
|
1348
|
+
(0, import_type_graphql3.Field)(() => String),
|
|
1349
|
+
_ts_metadata2("design:type", String)
|
|
1350
|
+
], ResultMessageInput.prototype, "actionName", void 0);
|
|
1351
|
+
_ts_decorate2([
|
|
1352
|
+
(0, import_type_graphql3.Field)(() => String),
|
|
1353
|
+
_ts_metadata2("design:type", String)
|
|
1354
|
+
], ResultMessageInput.prototype, "result", void 0);
|
|
1355
|
+
ResultMessageInput = _ts_decorate2([
|
|
1356
|
+
(0, import_type_graphql3.InputType)()
|
|
1357
|
+
], ResultMessageInput);
|
|
1358
|
+
|
|
1359
|
+
// src/graphql/inputs/frontend.input.ts
|
|
1360
|
+
var import_type_graphql5 = require("type-graphql");
|
|
1361
|
+
|
|
1362
|
+
// src/graphql/inputs/action.input.ts
|
|
1363
|
+
var import_type_graphql4 = require("type-graphql");
|
|
1364
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
1365
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1366
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
1367
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
1368
|
+
else
|
|
1369
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
1370
|
+
if (d = decorators[i])
|
|
1371
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1372
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1373
|
+
}
|
|
1374
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
1375
|
+
function _ts_metadata3(k, v) {
|
|
1376
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
1377
|
+
return Reflect.metadata(k, v);
|
|
1378
|
+
}
|
|
1379
|
+
__name(_ts_metadata3, "_ts_metadata");
|
|
1380
|
+
var ActionInput = class {
|
|
1381
|
+
name;
|
|
1382
|
+
description;
|
|
1383
|
+
jsonSchema;
|
|
1384
|
+
};
|
|
1385
|
+
__name(ActionInput, "ActionInput");
|
|
1386
|
+
_ts_decorate3([
|
|
1387
|
+
(0, import_type_graphql4.Field)(() => String),
|
|
1388
|
+
_ts_metadata3("design:type", String)
|
|
1389
|
+
], ActionInput.prototype, "name", void 0);
|
|
1390
|
+
_ts_decorate3([
|
|
1391
|
+
(0, import_type_graphql4.Field)(() => String),
|
|
1392
|
+
_ts_metadata3("design:type", String)
|
|
1393
|
+
], ActionInput.prototype, "description", void 0);
|
|
1394
|
+
_ts_decorate3([
|
|
1395
|
+
(0, import_type_graphql4.Field)(() => String),
|
|
1396
|
+
_ts_metadata3("design:type", String)
|
|
1397
|
+
], ActionInput.prototype, "jsonSchema", void 0);
|
|
1398
|
+
ActionInput = _ts_decorate3([
|
|
1399
|
+
(0, import_type_graphql4.InputType)()
|
|
1400
|
+
], ActionInput);
|
|
1401
|
+
|
|
1402
|
+
// src/graphql/inputs/frontend.input.ts
|
|
1403
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
1404
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1405
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
1406
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
1407
|
+
else
|
|
1408
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
1409
|
+
if (d = decorators[i])
|
|
1410
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1411
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1412
|
+
}
|
|
1413
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
1414
|
+
function _ts_metadata4(k, v) {
|
|
1415
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
1416
|
+
return Reflect.metadata(k, v);
|
|
1417
|
+
}
|
|
1418
|
+
__name(_ts_metadata4, "_ts_metadata");
|
|
1419
|
+
var FrontendInput = class {
|
|
1420
|
+
toDeprecate_fullContext;
|
|
1421
|
+
actions;
|
|
1422
|
+
};
|
|
1423
|
+
__name(FrontendInput, "FrontendInput");
|
|
1424
|
+
_ts_decorate4([
|
|
1425
|
+
(0, import_type_graphql5.Field)(() => String, {
|
|
1426
|
+
nullable: true
|
|
1427
|
+
}),
|
|
1428
|
+
_ts_metadata4("design:type", String)
|
|
1429
|
+
], FrontendInput.prototype, "toDeprecate_fullContext", void 0);
|
|
1430
|
+
_ts_decorate4([
|
|
1431
|
+
(0, import_type_graphql5.Field)(() => [
|
|
1432
|
+
ActionInput
|
|
1433
|
+
]),
|
|
1434
|
+
_ts_metadata4("design:type", Array)
|
|
1435
|
+
], FrontendInput.prototype, "actions", void 0);
|
|
1436
|
+
FrontendInput = _ts_decorate4([
|
|
1437
|
+
(0, import_type_graphql5.InputType)()
|
|
1438
|
+
], FrontendInput);
|
|
1439
|
+
|
|
1440
|
+
// src/graphql/inputs/cloud.input.ts
|
|
1441
|
+
var import_type_graphql7 = require("type-graphql");
|
|
1442
|
+
|
|
1443
|
+
// src/graphql/inputs/cloud-guardrails.input.ts
|
|
1444
|
+
var import_type_graphql6 = require("type-graphql");
|
|
1445
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
1446
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1447
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
1448
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
1449
|
+
else
|
|
1450
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
1451
|
+
if (d = decorators[i])
|
|
1452
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1453
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1454
|
+
}
|
|
1455
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
1456
|
+
function _ts_metadata5(k, v) {
|
|
1457
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
1458
|
+
return Reflect.metadata(k, v);
|
|
1459
|
+
}
|
|
1460
|
+
__name(_ts_metadata5, "_ts_metadata");
|
|
1461
|
+
var GuardrailsRuleInput = class {
|
|
1462
|
+
id;
|
|
1463
|
+
allowList = [];
|
|
1464
|
+
denyList = [];
|
|
1465
|
+
};
|
|
1466
|
+
__name(GuardrailsRuleInput, "GuardrailsRuleInput");
|
|
1467
|
+
_ts_decorate5([
|
|
1468
|
+
(0, import_type_graphql6.Field)(() => String),
|
|
1469
|
+
_ts_metadata5("design:type", String)
|
|
1470
|
+
], GuardrailsRuleInput.prototype, "id", void 0);
|
|
1471
|
+
_ts_decorate5([
|
|
1472
|
+
(0, import_type_graphql6.Field)(() => [
|
|
1473
|
+
String
|
|
1474
|
+
], {
|
|
1475
|
+
nullable: true
|
|
1476
|
+
}),
|
|
1477
|
+
_ts_metadata5("design:type", Array)
|
|
1478
|
+
], GuardrailsRuleInput.prototype, "allowList", void 0);
|
|
1479
|
+
_ts_decorate5([
|
|
1480
|
+
(0, import_type_graphql6.Field)(() => [
|
|
1481
|
+
String
|
|
1482
|
+
], {
|
|
1483
|
+
nullable: true
|
|
1484
|
+
}),
|
|
1485
|
+
_ts_metadata5("design:type", Array)
|
|
1486
|
+
], GuardrailsRuleInput.prototype, "denyList", void 0);
|
|
1487
|
+
GuardrailsRuleInput = _ts_decorate5([
|
|
1488
|
+
(0, import_type_graphql6.InputType)()
|
|
1489
|
+
], GuardrailsRuleInput);
|
|
1490
|
+
var GuardrailsInput = class {
|
|
1491
|
+
inputValidationRules = [];
|
|
1492
|
+
};
|
|
1493
|
+
__name(GuardrailsInput, "GuardrailsInput");
|
|
1494
|
+
_ts_decorate5([
|
|
1495
|
+
(0, import_type_graphql6.Field)(() => [
|
|
1496
|
+
GuardrailsRuleInput
|
|
1497
|
+
], {
|
|
1498
|
+
nullable: true
|
|
1499
|
+
}),
|
|
1500
|
+
_ts_metadata5("design:type", Array)
|
|
1501
|
+
], GuardrailsInput.prototype, "inputValidationRules", void 0);
|
|
1502
|
+
GuardrailsInput = _ts_decorate5([
|
|
1503
|
+
(0, import_type_graphql6.InputType)()
|
|
1504
|
+
], GuardrailsInput);
|
|
1505
|
+
|
|
1506
|
+
// src/graphql/inputs/cloud.input.ts
|
|
1507
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
1508
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1509
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
1510
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
1511
|
+
else
|
|
1512
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
1513
|
+
if (d = decorators[i])
|
|
1514
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1515
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1516
|
+
}
|
|
1517
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
1518
|
+
function _ts_metadata6(k, v) {
|
|
1519
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
1520
|
+
return Reflect.metadata(k, v);
|
|
1521
|
+
}
|
|
1522
|
+
__name(_ts_metadata6, "_ts_metadata");
|
|
1523
|
+
var CloudInput = class {
|
|
1524
|
+
guardrails;
|
|
1525
|
+
};
|
|
1526
|
+
__name(CloudInput, "CloudInput");
|
|
1527
|
+
_ts_decorate6([
|
|
1528
|
+
(0, import_type_graphql7.Field)(() => GuardrailsInput),
|
|
1529
|
+
_ts_metadata6("design:type", typeof GuardrailsInput === "undefined" ? Object : GuardrailsInput)
|
|
1530
|
+
], CloudInput.prototype, "guardrails", void 0);
|
|
1531
|
+
CloudInput = _ts_decorate6([
|
|
1532
|
+
(0, import_type_graphql7.InputType)()
|
|
1533
|
+
], CloudInput);
|
|
1534
|
+
|
|
1535
|
+
// src/graphql/inputs/generate-copilot-response.input.ts
|
|
1536
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
1537
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1538
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
1539
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
1540
|
+
else
|
|
1541
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
1542
|
+
if (d = decorators[i])
|
|
1543
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1544
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1545
|
+
}
|
|
1546
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
1547
|
+
function _ts_metadata7(k, v) {
|
|
1548
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
1549
|
+
return Reflect.metadata(k, v);
|
|
1550
|
+
}
|
|
1551
|
+
__name(_ts_metadata7, "_ts_metadata");
|
|
1552
|
+
var GenerateCopilotResponseInput = class {
|
|
1553
|
+
threadId;
|
|
1554
|
+
runId;
|
|
1555
|
+
messages;
|
|
1556
|
+
frontend;
|
|
1557
|
+
cloud;
|
|
1558
|
+
};
|
|
1559
|
+
__name(GenerateCopilotResponseInput, "GenerateCopilotResponseInput");
|
|
1560
|
+
_ts_decorate7([
|
|
1561
|
+
(0, import_type_graphql8.Field)(() => String, {
|
|
1562
|
+
nullable: true
|
|
1563
|
+
}),
|
|
1564
|
+
_ts_metadata7("design:type", String)
|
|
1565
|
+
], GenerateCopilotResponseInput.prototype, "threadId", void 0);
|
|
1566
|
+
_ts_decorate7([
|
|
1567
|
+
(0, import_type_graphql8.Field)(() => String, {
|
|
1568
|
+
nullable: true
|
|
1569
|
+
}),
|
|
1570
|
+
_ts_metadata7("design:type", String)
|
|
1571
|
+
], GenerateCopilotResponseInput.prototype, "runId", void 0);
|
|
1572
|
+
_ts_decorate7([
|
|
1573
|
+
(0, import_type_graphql8.Field)(() => [
|
|
1574
|
+
MessageInput
|
|
1575
|
+
]),
|
|
1576
|
+
_ts_metadata7("design:type", Array)
|
|
1577
|
+
], GenerateCopilotResponseInput.prototype, "messages", void 0);
|
|
1578
|
+
_ts_decorate7([
|
|
1579
|
+
(0, import_type_graphql8.Field)(() => FrontendInput),
|
|
1580
|
+
_ts_metadata7("design:type", typeof FrontendInput === "undefined" ? Object : FrontendInput)
|
|
1581
|
+
], GenerateCopilotResponseInput.prototype, "frontend", void 0);
|
|
1582
|
+
_ts_decorate7([
|
|
1583
|
+
(0, import_type_graphql8.Field)(() => CloudInput, {
|
|
1584
|
+
nullable: true
|
|
1585
|
+
}),
|
|
1586
|
+
_ts_metadata7("design:type", typeof CloudInput === "undefined" ? Object : CloudInput)
|
|
1587
|
+
], GenerateCopilotResponseInput.prototype, "cloud", void 0);
|
|
1588
|
+
GenerateCopilotResponseInput = _ts_decorate7([
|
|
1589
|
+
(0, import_type_graphql8.InputType)()
|
|
1590
|
+
], GenerateCopilotResponseInput);
|
|
1591
|
+
|
|
1592
|
+
// src/graphql/types/copilot-response.type.ts
|
|
1593
|
+
var import_type_graphql11 = require("type-graphql");
|
|
1594
|
+
|
|
1595
|
+
// src/graphql/types/message-status.type.ts
|
|
1596
|
+
var import_type_graphql9 = require("type-graphql");
|
|
1597
|
+
function _ts_decorate8(decorators, target, key, desc) {
|
|
1598
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1599
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
1600
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
1601
|
+
else
|
|
1602
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
1603
|
+
if (d = decorators[i])
|
|
1604
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1605
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1606
|
+
}
|
|
1607
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
1608
|
+
function _ts_metadata8(k, v) {
|
|
1609
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
1610
|
+
return Reflect.metadata(k, v);
|
|
1611
|
+
}
|
|
1612
|
+
__name(_ts_metadata8, "_ts_metadata");
|
|
1613
|
+
var MessageStatusCode;
|
|
1614
|
+
(function(MessageStatusCode2) {
|
|
1615
|
+
MessageStatusCode2["Pending"] = "pending";
|
|
1616
|
+
MessageStatusCode2["Success"] = "success";
|
|
1617
|
+
MessageStatusCode2["Failed"] = "failed";
|
|
1618
|
+
})(MessageStatusCode || (MessageStatusCode = {}));
|
|
1619
|
+
(0, import_type_graphql9.registerEnumType)(MessageStatusCode, {
|
|
1620
|
+
name: "MessageStatusCode"
|
|
1621
|
+
});
|
|
1622
|
+
var BaseMessageStatus = /* @__PURE__ */ __name(class BaseMessageStatus2 {
|
|
1623
|
+
code;
|
|
1624
|
+
}, "BaseMessageStatus");
|
|
1625
|
+
_ts_decorate8([
|
|
1626
|
+
(0, import_type_graphql9.Field)(() => MessageStatusCode),
|
|
1627
|
+
_ts_metadata8("design:type", String)
|
|
1628
|
+
], BaseMessageStatus.prototype, "code", void 0);
|
|
1629
|
+
BaseMessageStatus = _ts_decorate8([
|
|
1630
|
+
(0, import_type_graphql9.ObjectType)()
|
|
1631
|
+
], BaseMessageStatus);
|
|
1632
|
+
var PendingMessageStatus = class extends BaseMessageStatus {
|
|
1633
|
+
code = "pending";
|
|
1634
|
+
};
|
|
1635
|
+
__name(PendingMessageStatus, "PendingMessageStatus");
|
|
1636
|
+
PendingMessageStatus = _ts_decorate8([
|
|
1637
|
+
(0, import_type_graphql9.ObjectType)()
|
|
1638
|
+
], PendingMessageStatus);
|
|
1639
|
+
var SuccessMessageStatus = class extends BaseMessageStatus {
|
|
1640
|
+
code = "success";
|
|
1641
|
+
};
|
|
1642
|
+
__name(SuccessMessageStatus, "SuccessMessageStatus");
|
|
1643
|
+
SuccessMessageStatus = _ts_decorate8([
|
|
1644
|
+
(0, import_type_graphql9.ObjectType)()
|
|
1645
|
+
], SuccessMessageStatus);
|
|
1646
|
+
var FailedMessageStatus = class extends BaseMessageStatus {
|
|
1647
|
+
code = "failed";
|
|
1648
|
+
reason;
|
|
1649
|
+
};
|
|
1650
|
+
__name(FailedMessageStatus, "FailedMessageStatus");
|
|
1651
|
+
_ts_decorate8([
|
|
1652
|
+
(0, import_type_graphql9.Field)(() => String),
|
|
1653
|
+
_ts_metadata8("design:type", String)
|
|
1654
|
+
], FailedMessageStatus.prototype, "reason", void 0);
|
|
1655
|
+
FailedMessageStatus = _ts_decorate8([
|
|
1656
|
+
(0, import_type_graphql9.ObjectType)()
|
|
1657
|
+
], FailedMessageStatus);
|
|
1658
|
+
var MessageStatusUnion = (0, import_type_graphql9.createUnionType)({
|
|
1659
|
+
name: "MessageStatus",
|
|
1660
|
+
types: () => [
|
|
1661
|
+
PendingMessageStatus,
|
|
1662
|
+
SuccessMessageStatus,
|
|
1663
|
+
FailedMessageStatus
|
|
1664
|
+
]
|
|
1665
|
+
});
|
|
1666
|
+
|
|
1667
|
+
// src/graphql/types/response-status.type.ts
|
|
1668
|
+
var import_type_graphql10 = require("type-graphql");
|
|
1669
|
+
function _ts_decorate9(decorators, target, key, desc) {
|
|
1670
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1671
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
1672
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
1673
|
+
else
|
|
1674
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
1675
|
+
if (d = decorators[i])
|
|
1676
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1677
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1678
|
+
}
|
|
1679
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
1680
|
+
function _ts_metadata9(k, v) {
|
|
1681
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
1682
|
+
return Reflect.metadata(k, v);
|
|
1683
|
+
}
|
|
1684
|
+
__name(_ts_metadata9, "_ts_metadata");
|
|
1685
|
+
var ResponseStatusCode;
|
|
1686
|
+
(function(ResponseStatusCode2) {
|
|
1687
|
+
ResponseStatusCode2["Pending"] = "pending";
|
|
1688
|
+
ResponseStatusCode2["Success"] = "success";
|
|
1689
|
+
ResponseStatusCode2["Failed"] = "failed";
|
|
1690
|
+
})(ResponseStatusCode || (ResponseStatusCode = {}));
|
|
1691
|
+
(0, import_type_graphql10.registerEnumType)(ResponseStatusCode, {
|
|
1692
|
+
name: "ResponseStatusCode"
|
|
1693
|
+
});
|
|
1694
|
+
var BaseResponseStatus = /* @__PURE__ */ __name(class BaseResponseStatus2 {
|
|
1695
|
+
code;
|
|
1696
|
+
}, "BaseResponseStatus");
|
|
1697
|
+
_ts_decorate9([
|
|
1698
|
+
(0, import_type_graphql10.Field)(() => ResponseStatusCode),
|
|
1699
|
+
_ts_metadata9("design:type", String)
|
|
1700
|
+
], BaseResponseStatus.prototype, "code", void 0);
|
|
1701
|
+
BaseResponseStatus = _ts_decorate9([
|
|
1702
|
+
(0, import_type_graphql10.InterfaceType)({
|
|
1703
|
+
resolveType(value) {
|
|
1704
|
+
if (value.code === "success") {
|
|
1705
|
+
return SuccessResponseStatus;
|
|
1706
|
+
} else if (value.code === "failed") {
|
|
1707
|
+
return FailedResponseStatus;
|
|
1708
|
+
} else if (value.code === "pending") {
|
|
1709
|
+
return PendingResponseStatus;
|
|
1710
|
+
}
|
|
1711
|
+
return void 0;
|
|
1712
|
+
}
|
|
1713
|
+
}),
|
|
1714
|
+
(0, import_type_graphql10.ObjectType)()
|
|
1715
|
+
], BaseResponseStatus);
|
|
1716
|
+
var PendingResponseStatus = class extends BaseResponseStatus {
|
|
1717
|
+
code = "pending";
|
|
1718
|
+
};
|
|
1719
|
+
__name(PendingResponseStatus, "PendingResponseStatus");
|
|
1720
|
+
PendingResponseStatus = _ts_decorate9([
|
|
1721
|
+
(0, import_type_graphql10.ObjectType)({
|
|
1722
|
+
implements: BaseResponseStatus
|
|
1723
|
+
})
|
|
1724
|
+
], PendingResponseStatus);
|
|
1725
|
+
var SuccessResponseStatus = class extends BaseResponseStatus {
|
|
1726
|
+
code = "success";
|
|
1727
|
+
};
|
|
1728
|
+
__name(SuccessResponseStatus, "SuccessResponseStatus");
|
|
1729
|
+
SuccessResponseStatus = _ts_decorate9([
|
|
1730
|
+
(0, import_type_graphql10.ObjectType)({
|
|
1731
|
+
implements: BaseResponseStatus
|
|
1732
|
+
})
|
|
1733
|
+
], SuccessResponseStatus);
|
|
1734
|
+
var FailedResponseStatus = class extends BaseResponseStatus {
|
|
1735
|
+
code = "failed";
|
|
1736
|
+
reason;
|
|
1737
|
+
};
|
|
1738
|
+
__name(FailedResponseStatus, "FailedResponseStatus");
|
|
1739
|
+
_ts_decorate9([
|
|
1740
|
+
(0, import_type_graphql10.Field)(() => String),
|
|
1741
|
+
_ts_metadata9("design:type", String)
|
|
1742
|
+
], FailedResponseStatus.prototype, "reason", void 0);
|
|
1743
|
+
FailedResponseStatus = _ts_decorate9([
|
|
1744
|
+
(0, import_type_graphql10.ObjectType)({
|
|
1745
|
+
implements: BaseResponseStatus
|
|
1746
|
+
})
|
|
1747
|
+
], FailedResponseStatus);
|
|
1748
|
+
var ResponseStatusUnion = (0, import_type_graphql10.createUnionType)({
|
|
1749
|
+
name: "ResponseStatus",
|
|
1750
|
+
types: () => [
|
|
1751
|
+
PendingResponseStatus,
|
|
1752
|
+
SuccessResponseStatus,
|
|
1753
|
+
FailedResponseStatus
|
|
1754
|
+
]
|
|
1755
|
+
});
|
|
1756
|
+
|
|
1757
|
+
// src/graphql/types/copilot-response.type.ts
|
|
1758
|
+
function _ts_decorate10(decorators, target, key, desc) {
|
|
1759
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1760
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
1761
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
1762
|
+
else
|
|
1763
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
1764
|
+
if (d = decorators[i])
|
|
1765
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1766
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1767
|
+
}
|
|
1768
|
+
__name(_ts_decorate10, "_ts_decorate");
|
|
1769
|
+
function _ts_metadata10(k, v) {
|
|
1770
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
1771
|
+
return Reflect.metadata(k, v);
|
|
1772
|
+
}
|
|
1773
|
+
__name(_ts_metadata10, "_ts_metadata");
|
|
1774
|
+
var BaseMessageOutput = /* @__PURE__ */ __name(class BaseMessageOutput2 {
|
|
1775
|
+
id;
|
|
1776
|
+
createdAt;
|
|
1777
|
+
status;
|
|
1778
|
+
}, "BaseMessageOutput");
|
|
1779
|
+
_ts_decorate10([
|
|
1780
|
+
(0, import_type_graphql11.Field)(() => String),
|
|
1781
|
+
_ts_metadata10("design:type", String)
|
|
1782
|
+
], BaseMessageOutput.prototype, "id", void 0);
|
|
1783
|
+
_ts_decorate10([
|
|
1784
|
+
(0, import_type_graphql11.Field)(() => Date),
|
|
1785
|
+
_ts_metadata10("design:type", typeof Date === "undefined" ? Object : Date)
|
|
1786
|
+
], BaseMessageOutput.prototype, "createdAt", void 0);
|
|
1787
|
+
_ts_decorate10([
|
|
1788
|
+
(0, import_type_graphql11.Field)(() => MessageStatusUnion),
|
|
1789
|
+
_ts_metadata10("design:type", Object)
|
|
1790
|
+
], BaseMessageOutput.prototype, "status", void 0);
|
|
1791
|
+
BaseMessageOutput = _ts_decorate10([
|
|
1792
|
+
(0, import_type_graphql11.InterfaceType)({
|
|
1793
|
+
resolveType(value) {
|
|
1794
|
+
if (value.hasOwnProperty("content")) {
|
|
1795
|
+
return TextMessageOutput;
|
|
1796
|
+
} else if (value.hasOwnProperty("name")) {
|
|
1797
|
+
return ActionExecutionMessageOutput;
|
|
1798
|
+
} else if (value.hasOwnProperty("result")) {
|
|
1799
|
+
return ResultMessageOutput;
|
|
1800
|
+
}
|
|
1801
|
+
return void 0;
|
|
1802
|
+
}
|
|
1803
|
+
})
|
|
1804
|
+
], BaseMessageOutput);
|
|
1805
|
+
var TextMessageOutput = class {
|
|
1806
|
+
role;
|
|
1807
|
+
content;
|
|
1808
|
+
};
|
|
1809
|
+
__name(TextMessageOutput, "TextMessageOutput");
|
|
1810
|
+
_ts_decorate10([
|
|
1811
|
+
(0, import_type_graphql11.Field)(() => MessageRole),
|
|
1812
|
+
_ts_metadata10("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
|
|
1813
|
+
], TextMessageOutput.prototype, "role", void 0);
|
|
1814
|
+
_ts_decorate10([
|
|
1815
|
+
(0, import_type_graphql11.Field)(() => [
|
|
1816
|
+
String
|
|
1817
|
+
]),
|
|
1818
|
+
_ts_metadata10("design:type", Array)
|
|
1819
|
+
], TextMessageOutput.prototype, "content", void 0);
|
|
1820
|
+
TextMessageOutput = _ts_decorate10([
|
|
1821
|
+
(0, import_type_graphql11.ObjectType)({
|
|
1822
|
+
implements: BaseMessageOutput
|
|
1823
|
+
})
|
|
1824
|
+
], TextMessageOutput);
|
|
1825
|
+
var ActionExecutionMessageOutput = class {
|
|
1826
|
+
name;
|
|
1827
|
+
scope;
|
|
1828
|
+
arguments;
|
|
1829
|
+
};
|
|
1830
|
+
__name(ActionExecutionMessageOutput, "ActionExecutionMessageOutput");
|
|
1831
|
+
_ts_decorate10([
|
|
1832
|
+
(0, import_type_graphql11.Field)(() => String),
|
|
1833
|
+
_ts_metadata10("design:type", String)
|
|
1834
|
+
], ActionExecutionMessageOutput.prototype, "name", void 0);
|
|
1835
|
+
_ts_decorate10([
|
|
1836
|
+
(0, import_type_graphql11.Field)(() => ActionExecutionScope),
|
|
1837
|
+
_ts_metadata10("design:type", typeof ActionExecutionScope === "undefined" ? Object : ActionExecutionScope)
|
|
1838
|
+
], ActionExecutionMessageOutput.prototype, "scope", void 0);
|
|
1839
|
+
_ts_decorate10([
|
|
1840
|
+
(0, import_type_graphql11.Field)(() => [
|
|
1841
|
+
String
|
|
1842
|
+
]),
|
|
1843
|
+
_ts_metadata10("design:type", Array)
|
|
1844
|
+
], ActionExecutionMessageOutput.prototype, "arguments", void 0);
|
|
1845
|
+
ActionExecutionMessageOutput = _ts_decorate10([
|
|
1846
|
+
(0, import_type_graphql11.ObjectType)({
|
|
1847
|
+
implements: BaseMessageOutput
|
|
1848
|
+
})
|
|
1849
|
+
], ActionExecutionMessageOutput);
|
|
1850
|
+
var ResultMessageOutput = class {
|
|
1851
|
+
actionExecutionId;
|
|
1852
|
+
actionName;
|
|
1853
|
+
result;
|
|
1854
|
+
};
|
|
1855
|
+
__name(ResultMessageOutput, "ResultMessageOutput");
|
|
1856
|
+
_ts_decorate10([
|
|
1857
|
+
(0, import_type_graphql11.Field)(() => String),
|
|
1858
|
+
_ts_metadata10("design:type", String)
|
|
1859
|
+
], ResultMessageOutput.prototype, "actionExecutionId", void 0);
|
|
1860
|
+
_ts_decorate10([
|
|
1861
|
+
(0, import_type_graphql11.Field)(() => String),
|
|
1862
|
+
_ts_metadata10("design:type", String)
|
|
1863
|
+
], ResultMessageOutput.prototype, "actionName", void 0);
|
|
1864
|
+
_ts_decorate10([
|
|
1865
|
+
(0, import_type_graphql11.Field)(() => String),
|
|
1866
|
+
_ts_metadata10("design:type", String)
|
|
1867
|
+
], ResultMessageOutput.prototype, "result", void 0);
|
|
1868
|
+
ResultMessageOutput = _ts_decorate10([
|
|
1869
|
+
(0, import_type_graphql11.ObjectType)({
|
|
1870
|
+
implements: BaseMessageOutput
|
|
1871
|
+
})
|
|
1872
|
+
], ResultMessageOutput);
|
|
1873
|
+
var CopilotResponse = class {
|
|
1874
|
+
threadId;
|
|
1875
|
+
status;
|
|
1876
|
+
runId;
|
|
1877
|
+
messages;
|
|
1878
|
+
};
|
|
1879
|
+
__name(CopilotResponse, "CopilotResponse");
|
|
1880
|
+
_ts_decorate10([
|
|
1881
|
+
(0, import_type_graphql11.Field)(() => String),
|
|
1882
|
+
_ts_metadata10("design:type", String)
|
|
1883
|
+
], CopilotResponse.prototype, "threadId", void 0);
|
|
1884
|
+
_ts_decorate10([
|
|
1885
|
+
(0, import_type_graphql11.Field)(() => ResponseStatusUnion),
|
|
1886
|
+
_ts_metadata10("design:type", Object)
|
|
1887
|
+
], CopilotResponse.prototype, "status", void 0);
|
|
1888
|
+
_ts_decorate10([
|
|
1889
|
+
(0, import_type_graphql11.Field)({
|
|
1890
|
+
nullable: true
|
|
1891
|
+
}),
|
|
1892
|
+
_ts_metadata10("design:type", String)
|
|
1893
|
+
], CopilotResponse.prototype, "runId", void 0);
|
|
1894
|
+
_ts_decorate10([
|
|
1895
|
+
(0, import_type_graphql11.Field)(() => [
|
|
1896
|
+
BaseMessageOutput
|
|
1897
|
+
]),
|
|
1898
|
+
_ts_metadata10("design:type", Array)
|
|
1899
|
+
], CopilotResponse.prototype, "messages", void 0);
|
|
1900
|
+
CopilotResponse = _ts_decorate10([
|
|
1901
|
+
(0, import_type_graphql11.ObjectType)()
|
|
1902
|
+
], CopilotResponse);
|
|
1903
|
+
|
|
1904
|
+
// src/graphql/resolvers/copilot.resolver.ts
|
|
1905
|
+
var import_graphql_yoga = require("graphql-yoga");
|
|
1906
|
+
var import_nanoid3 = require("nanoid");
|
|
1907
|
+
var import_graphql_scalars = require("graphql-scalars");
|
|
1908
|
+
function _ts_decorate11(decorators, target, key, desc) {
|
|
1909
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1910
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
1911
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
1912
|
+
else
|
|
1913
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
1914
|
+
if (d = decorators[i])
|
|
1915
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1916
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1917
|
+
}
|
|
1918
|
+
__name(_ts_decorate11, "_ts_decorate");
|
|
1919
|
+
function _ts_metadata11(k, v) {
|
|
1920
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
1921
|
+
return Reflect.metadata(k, v);
|
|
1922
|
+
}
|
|
1923
|
+
__name(_ts_metadata11, "_ts_metadata");
|
|
1924
|
+
function _ts_param(paramIndex, decorator) {
|
|
1925
|
+
return function(target, key) {
|
|
1926
|
+
decorator(target, key, paramIndex);
|
|
1927
|
+
};
|
|
1928
|
+
}
|
|
1929
|
+
__name(_ts_param, "_ts_param");
|
|
1930
|
+
var CopilotResolver = class {
|
|
1931
|
+
async hello() {
|
|
1932
|
+
return "Hello World";
|
|
1933
|
+
}
|
|
1934
|
+
async generateCopilotResponse(ctx, data, properties) {
|
|
1935
|
+
if (properties) {
|
|
1936
|
+
ctx._copilotkit.properties = {
|
|
1937
|
+
...ctx._copilotkit.properties,
|
|
1938
|
+
...properties
|
|
1939
|
+
};
|
|
1940
|
+
}
|
|
1941
|
+
const copilotRuntime = ctx._copilotkit.runtime;
|
|
1942
|
+
const serviceAdapter = ctx._copilotkit.serviceAdapter;
|
|
1943
|
+
const responseStatus = new import_rxjs2.Subject();
|
|
1944
|
+
const { eventSource, threadId = (0, import_nanoid3.nanoid)(), runId } = await copilotRuntime.process({
|
|
1945
|
+
serviceAdapter,
|
|
1946
|
+
messages: data.messages,
|
|
1947
|
+
actions: data.frontend.actions,
|
|
1948
|
+
threadId: data.threadId,
|
|
1949
|
+
runId: data.runId,
|
|
1950
|
+
publicApiKey: void 0
|
|
1951
|
+
});
|
|
1952
|
+
const response = {
|
|
1953
|
+
threadId,
|
|
1954
|
+
runId,
|
|
1955
|
+
status: (0, import_rxjs2.firstValueFrom)(responseStatus),
|
|
1956
|
+
messages: new import_graphql_yoga.Repeater(async (pushMessage, stopStreamingMessages) => {
|
|
1957
|
+
const eventStream = eventSource.process(copilotRuntime.actions).pipe(
|
|
1958
|
+
// shareReplay() ensures that later subscribers will see the whole stream instead of
|
|
1959
|
+
// just the events that were emitted after the subscriber was added.
|
|
1960
|
+
(0, import_rxjs2.shareReplay)()
|
|
1961
|
+
);
|
|
1962
|
+
eventStream.subscribe({
|
|
1963
|
+
next: async (event) => {
|
|
1964
|
+
switch (event.type) {
|
|
1965
|
+
case RuntimeEventTypes.TextMessageStart:
|
|
1966
|
+
const textMessageContentStream = eventStream.pipe(
|
|
1967
|
+
// skip until this message start event
|
|
1968
|
+
(0, import_rxjs2.skipWhile)((e) => e !== event),
|
|
1969
|
+
// take until the message end event
|
|
1970
|
+
(0, import_rxjs2.takeWhile)((e) => e.type != RuntimeEventTypes.TextMessageEnd)
|
|
1971
|
+
);
|
|
1972
|
+
const streamingTextStatus = new import_rxjs2.Subject();
|
|
1973
|
+
pushMessage({
|
|
1974
|
+
id: (0, import_nanoid3.nanoid)(),
|
|
1975
|
+
status: (0, import_rxjs2.firstValueFrom)(streamingTextStatus),
|
|
1976
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
1977
|
+
role: MessageRole.assistant,
|
|
1978
|
+
content: new import_graphql_yoga.Repeater(async (pushTextChunk, stopStreamingText) => {
|
|
1979
|
+
await textMessageContentStream.forEach(async (e) => {
|
|
1980
|
+
if (e.type == RuntimeEventTypes.TextMessageContent) {
|
|
1981
|
+
await pushTextChunk(e.content);
|
|
1982
|
+
}
|
|
1983
|
+
});
|
|
1984
|
+
stopStreamingText();
|
|
1985
|
+
streamingTextStatus.next(new SuccessMessageStatus());
|
|
1986
|
+
})
|
|
1987
|
+
});
|
|
1988
|
+
break;
|
|
1989
|
+
case RuntimeEventTypes.ActionExecutionStart:
|
|
1990
|
+
const actionExecutionArgumentStream = eventStream.pipe((0, import_rxjs2.skipWhile)((e) => e !== event), (0, import_rxjs2.takeWhile)((e) => e.type != RuntimeEventTypes.ActionExecutionEnd));
|
|
1991
|
+
const streamingArgumentsStatus = new import_rxjs2.Subject();
|
|
1992
|
+
pushMessage({
|
|
1993
|
+
id: event.actionExecutionId,
|
|
1994
|
+
status: (0, import_rxjs2.firstValueFrom)(streamingArgumentsStatus),
|
|
1995
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
1996
|
+
name: event.actionName,
|
|
1997
|
+
scope: event.scope,
|
|
1998
|
+
arguments: new import_graphql_yoga.Repeater(async (pushArgumentsChunk, stopStreamingArguments) => {
|
|
1999
|
+
await actionExecutionArgumentStream.forEach(async (e) => {
|
|
2000
|
+
if (e.type == RuntimeEventTypes.ActionExecutionArgs) {
|
|
2001
|
+
await pushArgumentsChunk(e.args);
|
|
2002
|
+
}
|
|
2003
|
+
});
|
|
2004
|
+
stopStreamingArguments();
|
|
2005
|
+
streamingArgumentsStatus.next(new SuccessMessageStatus());
|
|
2006
|
+
})
|
|
2007
|
+
});
|
|
2008
|
+
break;
|
|
2009
|
+
case RuntimeEventTypes.ActionExecutionResult:
|
|
2010
|
+
pushMessage({
|
|
2011
|
+
id: (0, import_nanoid3.nanoid)(),
|
|
2012
|
+
status: new SuccessMessageStatus(),
|
|
2013
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
2014
|
+
actionExecutionId: event.actionExecutionId,
|
|
2015
|
+
actionName: event.actionName,
|
|
2016
|
+
result: event.result
|
|
2017
|
+
});
|
|
2018
|
+
break;
|
|
2019
|
+
}
|
|
2020
|
+
},
|
|
2021
|
+
error: (err) => console.error("Error in event source", err),
|
|
2022
|
+
complete: () => {
|
|
2023
|
+
responseStatus.next(new SuccessResponseStatus());
|
|
2024
|
+
stopStreamingMessages();
|
|
2025
|
+
}
|
|
2026
|
+
});
|
|
2027
|
+
})
|
|
2028
|
+
};
|
|
2029
|
+
return response;
|
|
2030
|
+
}
|
|
2031
|
+
};
|
|
2032
|
+
__name(CopilotResolver, "CopilotResolver");
|
|
2033
|
+
_ts_decorate11([
|
|
2034
|
+
(0, import_type_graphql12.Query)(() => String),
|
|
2035
|
+
_ts_metadata11("design:type", Function),
|
|
2036
|
+
_ts_metadata11("design:paramtypes", []),
|
|
2037
|
+
_ts_metadata11("design:returntype", Promise)
|
|
2038
|
+
], CopilotResolver.prototype, "hello", null);
|
|
2039
|
+
_ts_decorate11([
|
|
2040
|
+
(0, import_type_graphql12.Mutation)(() => CopilotResponse),
|
|
2041
|
+
_ts_param(0, (0, import_type_graphql12.Ctx)()),
|
|
2042
|
+
_ts_param(1, (0, import_type_graphql12.Arg)("data")),
|
|
2043
|
+
_ts_param(2, (0, import_type_graphql12.Arg)("properties", () => import_graphql_scalars.GraphQLJSONObject, {
|
|
2044
|
+
nullable: true
|
|
2045
|
+
})),
|
|
2046
|
+
_ts_metadata11("design:type", Function),
|
|
2047
|
+
_ts_metadata11("design:paramtypes", [
|
|
2048
|
+
typeof GraphQLContext === "undefined" ? Object : GraphQLContext,
|
|
2049
|
+
typeof GenerateCopilotResponseInput === "undefined" ? Object : GenerateCopilotResponseInput,
|
|
2050
|
+
typeof CopilotRequestContextProperties === "undefined" ? Object : CopilotRequestContextProperties
|
|
2051
|
+
]),
|
|
2052
|
+
_ts_metadata11("design:returntype", Promise)
|
|
2053
|
+
], CopilotResolver.prototype, "generateCopilotResponse", null);
|
|
2054
|
+
CopilotResolver = _ts_decorate11([
|
|
2055
|
+
(0, import_type_graphql12.Resolver)(() => CopilotResponse)
|
|
2056
|
+
], CopilotResolver);
|
|
2057
|
+
|
|
2058
|
+
// src/lib/integrations/shared.ts
|
|
2059
|
+
var import_plugin_defer_stream = require("@graphql-yoga/plugin-defer-stream");
|
|
2060
|
+
async function createContext(initialContext, copilotKitContext) {
|
|
2061
|
+
const ctx = {
|
|
2062
|
+
...initialContext,
|
|
2063
|
+
_copilotkit: {
|
|
2064
|
+
...copilotKitContext
|
|
2065
|
+
}
|
|
2066
|
+
};
|
|
2067
|
+
return ctx;
|
|
2068
|
+
}
|
|
2069
|
+
__name(createContext, "createContext");
|
|
2070
|
+
function buildSchema(options = {}) {
|
|
2071
|
+
const schema = (0, import_type_graphql13.buildSchemaSync)({
|
|
2072
|
+
resolvers: [
|
|
2073
|
+
CopilotResolver
|
|
2074
|
+
],
|
|
2075
|
+
emitSchemaFile: options.emitSchemaFile
|
|
2076
|
+
});
|
|
2077
|
+
return schema;
|
|
2078
|
+
}
|
|
2079
|
+
__name(buildSchema, "buildSchema");
|
|
2080
|
+
function getCommonConfig(options) {
|
|
2081
|
+
return {
|
|
2082
|
+
schema: buildSchema(),
|
|
2083
|
+
plugins: [
|
|
2084
|
+
(0, import_plugin_defer_stream.useDeferStream)()
|
|
2085
|
+
],
|
|
2086
|
+
context: (ctx) => createContext(ctx, {
|
|
2087
|
+
runtime: options.runtime,
|
|
2088
|
+
serviceAdapter: options.serviceAdapter,
|
|
2089
|
+
properties: {}
|
|
2090
|
+
})
|
|
2091
|
+
};
|
|
2092
|
+
}
|
|
2093
|
+
__name(getCommonConfig, "getCommonConfig");
|
|
2094
|
+
|
|
2095
|
+
// src/lib/integrations/nextjs/app-router.ts
|
|
2096
|
+
var import_graphql_yoga2 = require("graphql-yoga");
|
|
2097
|
+
function copilotRuntimeNextJSAppRouterEndpoint({ runtime, endpoint, serviceAdapter }) {
|
|
2098
|
+
const commonConfig = getCommonConfig({
|
|
2099
|
+
runtime,
|
|
2100
|
+
serviceAdapter
|
|
2101
|
+
});
|
|
2102
|
+
const yoga = (0, import_graphql_yoga2.createYoga)({
|
|
2103
|
+
...commonConfig,
|
|
2104
|
+
graphqlEndpoint: endpoint,
|
|
2105
|
+
fetchAPI: {
|
|
2106
|
+
Response: globalThis.Response
|
|
2107
|
+
}
|
|
2108
|
+
});
|
|
2109
|
+
return {
|
|
2110
|
+
handleRequest: yoga,
|
|
2111
|
+
GET: yoga,
|
|
2112
|
+
POST: yoga,
|
|
2113
|
+
OPTIONS: yoga
|
|
2114
|
+
};
|
|
2115
|
+
}
|
|
2116
|
+
__name(copilotRuntimeNextJSAppRouterEndpoint, "copilotRuntimeNextJSAppRouterEndpoint");
|
|
2117
|
+
|
|
2118
|
+
// src/lib/integrations/nextjs/pages-router.ts
|
|
2119
|
+
var import_graphql_yoga3 = require("graphql-yoga");
|
|
2120
|
+
var config = {
|
|
2121
|
+
api: {
|
|
2122
|
+
bodyParser: false
|
|
2123
|
+
}
|
|
2124
|
+
};
|
|
2125
|
+
function copilotRuntimeNextJSPagesRouterEndpoint({ runtime, endpoint, serviceAdapter }) {
|
|
2126
|
+
const commonConfig = getCommonConfig({
|
|
2127
|
+
runtime,
|
|
2128
|
+
serviceAdapter
|
|
2129
|
+
});
|
|
2130
|
+
const yoga = (0, import_graphql_yoga3.createYoga)({
|
|
2131
|
+
...commonConfig,
|
|
2132
|
+
graphqlEndpoint: endpoint
|
|
2133
|
+
});
|
|
2134
|
+
return yoga;
|
|
2135
|
+
}
|
|
2136
|
+
__name(copilotRuntimeNextJSPagesRouterEndpoint, "copilotRuntimeNextJSPagesRouterEndpoint");
|
|
2137
|
+
|
|
2138
|
+
// src/lib/integrations/node-http/index.ts
|
|
2139
|
+
var import_graphql_yoga4 = require("graphql-yoga");
|
|
2140
|
+
function copilotRuntimeNodeHttpEndpoint({ runtime, endpoint, serviceAdapter }) {
|
|
2141
|
+
const commonConfig = getCommonConfig({
|
|
2142
|
+
runtime,
|
|
2143
|
+
serviceAdapter
|
|
2144
|
+
});
|
|
2145
|
+
const yoga = (0, import_graphql_yoga4.createYoga)({
|
|
2146
|
+
...commonConfig,
|
|
2147
|
+
graphqlEndpoint: endpoint
|
|
2148
|
+
});
|
|
2149
|
+
return yoga;
|
|
2150
|
+
}
|
|
2151
|
+
__name(copilotRuntimeNodeHttpEndpoint, "copilotRuntimeNodeHttpEndpoint");
|
|
2152
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2153
|
+
0 && (module.exports = {
|
|
2154
|
+
CopilotBackend,
|
|
2155
|
+
CopilotCloud,
|
|
2156
|
+
CopilotRuntime,
|
|
2157
|
+
GoogleGenerativeAIAdapter,
|
|
2158
|
+
LangChainAdapter,
|
|
2159
|
+
OpenAIAdapter,
|
|
2160
|
+
OpenAIAssistantAdapter,
|
|
2161
|
+
RemoteCopilotCloud,
|
|
2162
|
+
buildSchema,
|
|
2163
|
+
config,
|
|
2164
|
+
copilotRuntimeNextJSAppRouterEndpoint,
|
|
2165
|
+
copilotRuntimeNextJSPagesRouterEndpoint,
|
|
2166
|
+
copilotRuntimeNodeHttpEndpoint,
|
|
2167
|
+
createContext,
|
|
2168
|
+
flattenToolCallsNoDuplicates,
|
|
2169
|
+
getCommonConfig
|
|
2170
|
+
});
|
|
2171
|
+
//# sourceMappingURL=index.js.map
|