@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
|
@@ -0,0 +1,1051 @@
|
|
|
1
|
+
import {
|
|
2
|
+
streamLangChainResponse
|
|
3
|
+
} from "./chunk-7IFP53C6.mjs";
|
|
4
|
+
import {
|
|
5
|
+
BaseMessage,
|
|
6
|
+
__name
|
|
7
|
+
} from "./chunk-NFCPM5AM.mjs";
|
|
8
|
+
|
|
9
|
+
// src/lib/integrations/node-http/index.ts
|
|
10
|
+
import { createYoga } from "graphql-yoga";
|
|
11
|
+
|
|
12
|
+
// src/lib/integrations/shared.ts
|
|
13
|
+
import { buildSchemaSync } from "type-graphql";
|
|
14
|
+
|
|
15
|
+
// src/graphql/resolvers/copilot.resolver.ts
|
|
16
|
+
import { Arg, Ctx, Mutation, Query, Resolver } from "type-graphql";
|
|
17
|
+
import { Subject, firstValueFrom, shareReplay, skipWhile, takeWhile } from "rxjs";
|
|
18
|
+
|
|
19
|
+
// src/graphql/inputs/generate-copilot-response.input.ts
|
|
20
|
+
import { Field as Field6, InputType as InputType6 } from "type-graphql";
|
|
21
|
+
|
|
22
|
+
// src/graphql/inputs/message.input.ts
|
|
23
|
+
import { Field, InputType } from "type-graphql";
|
|
24
|
+
|
|
25
|
+
// src/graphql/types/enums.ts
|
|
26
|
+
import { registerEnumType } from "type-graphql";
|
|
27
|
+
var MessageRole;
|
|
28
|
+
(function(MessageRole2) {
|
|
29
|
+
MessageRole2["user"] = "user";
|
|
30
|
+
MessageRole2["assistant"] = "assistant";
|
|
31
|
+
MessageRole2["system"] = "system";
|
|
32
|
+
})(MessageRole || (MessageRole = {}));
|
|
33
|
+
var ActionExecutionScope;
|
|
34
|
+
(function(ActionExecutionScope2) {
|
|
35
|
+
ActionExecutionScope2["server"] = "server";
|
|
36
|
+
ActionExecutionScope2["client"] = "client";
|
|
37
|
+
})(ActionExecutionScope || (ActionExecutionScope = {}));
|
|
38
|
+
registerEnumType(MessageRole, {
|
|
39
|
+
name: "MessageRole",
|
|
40
|
+
description: "The role of the message"
|
|
41
|
+
});
|
|
42
|
+
registerEnumType(ActionExecutionScope, {
|
|
43
|
+
name: "ActionExecutionScope",
|
|
44
|
+
description: "The scope of the action"
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// src/graphql/inputs/message.input.ts
|
|
48
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
49
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
50
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
51
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
52
|
+
else
|
|
53
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
54
|
+
if (d = decorators[i])
|
|
55
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
56
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
57
|
+
}
|
|
58
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
59
|
+
function _ts_metadata(k, v) {
|
|
60
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
61
|
+
return Reflect.metadata(k, v);
|
|
62
|
+
}
|
|
63
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
64
|
+
var MessageInput = class extends BaseMessage {
|
|
65
|
+
textMessage;
|
|
66
|
+
actionExecutionMessage;
|
|
67
|
+
resultMessage;
|
|
68
|
+
};
|
|
69
|
+
__name(MessageInput, "MessageInput");
|
|
70
|
+
_ts_decorate([
|
|
71
|
+
Field(() => TextMessageInput, {
|
|
72
|
+
nullable: true
|
|
73
|
+
}),
|
|
74
|
+
_ts_metadata("design:type", typeof TextMessageInput === "undefined" ? Object : TextMessageInput)
|
|
75
|
+
], MessageInput.prototype, "textMessage", void 0);
|
|
76
|
+
_ts_decorate([
|
|
77
|
+
Field(() => ActionExecutionMessageInput, {
|
|
78
|
+
nullable: true
|
|
79
|
+
}),
|
|
80
|
+
_ts_metadata("design:type", typeof ActionExecutionMessageInput === "undefined" ? Object : ActionExecutionMessageInput)
|
|
81
|
+
], MessageInput.prototype, "actionExecutionMessage", void 0);
|
|
82
|
+
_ts_decorate([
|
|
83
|
+
Field(() => ResultMessageInput, {
|
|
84
|
+
nullable: true
|
|
85
|
+
}),
|
|
86
|
+
_ts_metadata("design:type", typeof ResultMessageInput === "undefined" ? Object : ResultMessageInput)
|
|
87
|
+
], MessageInput.prototype, "resultMessage", void 0);
|
|
88
|
+
MessageInput = _ts_decorate([
|
|
89
|
+
InputType()
|
|
90
|
+
], MessageInput);
|
|
91
|
+
var TextMessageInput = class {
|
|
92
|
+
content;
|
|
93
|
+
role;
|
|
94
|
+
};
|
|
95
|
+
__name(TextMessageInput, "TextMessageInput");
|
|
96
|
+
_ts_decorate([
|
|
97
|
+
Field(() => String),
|
|
98
|
+
_ts_metadata("design:type", String)
|
|
99
|
+
], TextMessageInput.prototype, "content", void 0);
|
|
100
|
+
_ts_decorate([
|
|
101
|
+
Field(() => MessageRole),
|
|
102
|
+
_ts_metadata("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
|
|
103
|
+
], TextMessageInput.prototype, "role", void 0);
|
|
104
|
+
TextMessageInput = _ts_decorate([
|
|
105
|
+
InputType()
|
|
106
|
+
], TextMessageInput);
|
|
107
|
+
var ActionExecutionMessageInput = class {
|
|
108
|
+
name;
|
|
109
|
+
arguments;
|
|
110
|
+
scope;
|
|
111
|
+
};
|
|
112
|
+
__name(ActionExecutionMessageInput, "ActionExecutionMessageInput");
|
|
113
|
+
_ts_decorate([
|
|
114
|
+
Field(() => String),
|
|
115
|
+
_ts_metadata("design:type", String)
|
|
116
|
+
], ActionExecutionMessageInput.prototype, "name", void 0);
|
|
117
|
+
_ts_decorate([
|
|
118
|
+
Field(() => String),
|
|
119
|
+
_ts_metadata("design:type", String)
|
|
120
|
+
], ActionExecutionMessageInput.prototype, "arguments", void 0);
|
|
121
|
+
_ts_decorate([
|
|
122
|
+
Field(() => ActionExecutionScope),
|
|
123
|
+
_ts_metadata("design:type", typeof ActionExecutionScope === "undefined" ? Object : ActionExecutionScope)
|
|
124
|
+
], ActionExecutionMessageInput.prototype, "scope", void 0);
|
|
125
|
+
ActionExecutionMessageInput = _ts_decorate([
|
|
126
|
+
InputType()
|
|
127
|
+
], ActionExecutionMessageInput);
|
|
128
|
+
var ResultMessageInput = class {
|
|
129
|
+
actionExecutionId;
|
|
130
|
+
actionName;
|
|
131
|
+
result;
|
|
132
|
+
};
|
|
133
|
+
__name(ResultMessageInput, "ResultMessageInput");
|
|
134
|
+
_ts_decorate([
|
|
135
|
+
Field(() => String),
|
|
136
|
+
_ts_metadata("design:type", String)
|
|
137
|
+
], ResultMessageInput.prototype, "actionExecutionId", void 0);
|
|
138
|
+
_ts_decorate([
|
|
139
|
+
Field(() => String),
|
|
140
|
+
_ts_metadata("design:type", String)
|
|
141
|
+
], ResultMessageInput.prototype, "actionName", void 0);
|
|
142
|
+
_ts_decorate([
|
|
143
|
+
Field(() => String),
|
|
144
|
+
_ts_metadata("design:type", String)
|
|
145
|
+
], ResultMessageInput.prototype, "result", void 0);
|
|
146
|
+
ResultMessageInput = _ts_decorate([
|
|
147
|
+
InputType()
|
|
148
|
+
], ResultMessageInput);
|
|
149
|
+
|
|
150
|
+
// src/graphql/inputs/frontend.input.ts
|
|
151
|
+
import { Field as Field3, InputType as InputType3 } from "type-graphql";
|
|
152
|
+
|
|
153
|
+
// src/graphql/inputs/action.input.ts
|
|
154
|
+
import { Field as Field2, InputType as InputType2 } from "type-graphql";
|
|
155
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
156
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
157
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
158
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
159
|
+
else
|
|
160
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
161
|
+
if (d = decorators[i])
|
|
162
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
163
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
164
|
+
}
|
|
165
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
166
|
+
function _ts_metadata2(k, v) {
|
|
167
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
168
|
+
return Reflect.metadata(k, v);
|
|
169
|
+
}
|
|
170
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
171
|
+
var ActionInput = class {
|
|
172
|
+
name;
|
|
173
|
+
description;
|
|
174
|
+
jsonSchema;
|
|
175
|
+
};
|
|
176
|
+
__name(ActionInput, "ActionInput");
|
|
177
|
+
_ts_decorate2([
|
|
178
|
+
Field2(() => String),
|
|
179
|
+
_ts_metadata2("design:type", String)
|
|
180
|
+
], ActionInput.prototype, "name", void 0);
|
|
181
|
+
_ts_decorate2([
|
|
182
|
+
Field2(() => String),
|
|
183
|
+
_ts_metadata2("design:type", String)
|
|
184
|
+
], ActionInput.prototype, "description", void 0);
|
|
185
|
+
_ts_decorate2([
|
|
186
|
+
Field2(() => String),
|
|
187
|
+
_ts_metadata2("design:type", String)
|
|
188
|
+
], ActionInput.prototype, "jsonSchema", void 0);
|
|
189
|
+
ActionInput = _ts_decorate2([
|
|
190
|
+
InputType2()
|
|
191
|
+
], ActionInput);
|
|
192
|
+
|
|
193
|
+
// src/graphql/inputs/frontend.input.ts
|
|
194
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
195
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
196
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
197
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
198
|
+
else
|
|
199
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
200
|
+
if (d = decorators[i])
|
|
201
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
202
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
203
|
+
}
|
|
204
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
205
|
+
function _ts_metadata3(k, v) {
|
|
206
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
207
|
+
return Reflect.metadata(k, v);
|
|
208
|
+
}
|
|
209
|
+
__name(_ts_metadata3, "_ts_metadata");
|
|
210
|
+
var FrontendInput = class {
|
|
211
|
+
toDeprecate_fullContext;
|
|
212
|
+
actions;
|
|
213
|
+
};
|
|
214
|
+
__name(FrontendInput, "FrontendInput");
|
|
215
|
+
_ts_decorate3([
|
|
216
|
+
Field3(() => String, {
|
|
217
|
+
nullable: true
|
|
218
|
+
}),
|
|
219
|
+
_ts_metadata3("design:type", String)
|
|
220
|
+
], FrontendInput.prototype, "toDeprecate_fullContext", void 0);
|
|
221
|
+
_ts_decorate3([
|
|
222
|
+
Field3(() => [
|
|
223
|
+
ActionInput
|
|
224
|
+
]),
|
|
225
|
+
_ts_metadata3("design:type", Array)
|
|
226
|
+
], FrontendInput.prototype, "actions", void 0);
|
|
227
|
+
FrontendInput = _ts_decorate3([
|
|
228
|
+
InputType3()
|
|
229
|
+
], FrontendInput);
|
|
230
|
+
|
|
231
|
+
// src/graphql/inputs/cloud.input.ts
|
|
232
|
+
import { Field as Field5, InputType as InputType5 } from "type-graphql";
|
|
233
|
+
|
|
234
|
+
// src/graphql/inputs/cloud-guardrails.input.ts
|
|
235
|
+
import { Field as Field4, InputType as InputType4 } from "type-graphql";
|
|
236
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
237
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
238
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
239
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
240
|
+
else
|
|
241
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
242
|
+
if (d = decorators[i])
|
|
243
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
244
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
245
|
+
}
|
|
246
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
247
|
+
function _ts_metadata4(k, v) {
|
|
248
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
249
|
+
return Reflect.metadata(k, v);
|
|
250
|
+
}
|
|
251
|
+
__name(_ts_metadata4, "_ts_metadata");
|
|
252
|
+
var GuardrailsRuleInput = class {
|
|
253
|
+
id;
|
|
254
|
+
allowList = [];
|
|
255
|
+
denyList = [];
|
|
256
|
+
};
|
|
257
|
+
__name(GuardrailsRuleInput, "GuardrailsRuleInput");
|
|
258
|
+
_ts_decorate4([
|
|
259
|
+
Field4(() => String),
|
|
260
|
+
_ts_metadata4("design:type", String)
|
|
261
|
+
], GuardrailsRuleInput.prototype, "id", void 0);
|
|
262
|
+
_ts_decorate4([
|
|
263
|
+
Field4(() => [
|
|
264
|
+
String
|
|
265
|
+
], {
|
|
266
|
+
nullable: true
|
|
267
|
+
}),
|
|
268
|
+
_ts_metadata4("design:type", Array)
|
|
269
|
+
], GuardrailsRuleInput.prototype, "allowList", void 0);
|
|
270
|
+
_ts_decorate4([
|
|
271
|
+
Field4(() => [
|
|
272
|
+
String
|
|
273
|
+
], {
|
|
274
|
+
nullable: true
|
|
275
|
+
}),
|
|
276
|
+
_ts_metadata4("design:type", Array)
|
|
277
|
+
], GuardrailsRuleInput.prototype, "denyList", void 0);
|
|
278
|
+
GuardrailsRuleInput = _ts_decorate4([
|
|
279
|
+
InputType4()
|
|
280
|
+
], GuardrailsRuleInput);
|
|
281
|
+
var GuardrailsInput = class {
|
|
282
|
+
inputValidationRules = [];
|
|
283
|
+
};
|
|
284
|
+
__name(GuardrailsInput, "GuardrailsInput");
|
|
285
|
+
_ts_decorate4([
|
|
286
|
+
Field4(() => [
|
|
287
|
+
GuardrailsRuleInput
|
|
288
|
+
], {
|
|
289
|
+
nullable: true
|
|
290
|
+
}),
|
|
291
|
+
_ts_metadata4("design:type", Array)
|
|
292
|
+
], GuardrailsInput.prototype, "inputValidationRules", void 0);
|
|
293
|
+
GuardrailsInput = _ts_decorate4([
|
|
294
|
+
InputType4()
|
|
295
|
+
], GuardrailsInput);
|
|
296
|
+
|
|
297
|
+
// src/graphql/inputs/cloud.input.ts
|
|
298
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
299
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
300
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
301
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
302
|
+
else
|
|
303
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
304
|
+
if (d = decorators[i])
|
|
305
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
306
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
307
|
+
}
|
|
308
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
309
|
+
function _ts_metadata5(k, v) {
|
|
310
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
311
|
+
return Reflect.metadata(k, v);
|
|
312
|
+
}
|
|
313
|
+
__name(_ts_metadata5, "_ts_metadata");
|
|
314
|
+
var CloudInput = class {
|
|
315
|
+
guardrails;
|
|
316
|
+
};
|
|
317
|
+
__name(CloudInput, "CloudInput");
|
|
318
|
+
_ts_decorate5([
|
|
319
|
+
Field5(() => GuardrailsInput),
|
|
320
|
+
_ts_metadata5("design:type", typeof GuardrailsInput === "undefined" ? Object : GuardrailsInput)
|
|
321
|
+
], CloudInput.prototype, "guardrails", void 0);
|
|
322
|
+
CloudInput = _ts_decorate5([
|
|
323
|
+
InputType5()
|
|
324
|
+
], CloudInput);
|
|
325
|
+
|
|
326
|
+
// src/graphql/inputs/generate-copilot-response.input.ts
|
|
327
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
328
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
329
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
330
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
331
|
+
else
|
|
332
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
333
|
+
if (d = decorators[i])
|
|
334
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
335
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
336
|
+
}
|
|
337
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
338
|
+
function _ts_metadata6(k, v) {
|
|
339
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
340
|
+
return Reflect.metadata(k, v);
|
|
341
|
+
}
|
|
342
|
+
__name(_ts_metadata6, "_ts_metadata");
|
|
343
|
+
var GenerateCopilotResponseInput = class {
|
|
344
|
+
threadId;
|
|
345
|
+
runId;
|
|
346
|
+
messages;
|
|
347
|
+
frontend;
|
|
348
|
+
cloud;
|
|
349
|
+
};
|
|
350
|
+
__name(GenerateCopilotResponseInput, "GenerateCopilotResponseInput");
|
|
351
|
+
_ts_decorate6([
|
|
352
|
+
Field6(() => String, {
|
|
353
|
+
nullable: true
|
|
354
|
+
}),
|
|
355
|
+
_ts_metadata6("design:type", String)
|
|
356
|
+
], GenerateCopilotResponseInput.prototype, "threadId", void 0);
|
|
357
|
+
_ts_decorate6([
|
|
358
|
+
Field6(() => String, {
|
|
359
|
+
nullable: true
|
|
360
|
+
}),
|
|
361
|
+
_ts_metadata6("design:type", String)
|
|
362
|
+
], GenerateCopilotResponseInput.prototype, "runId", void 0);
|
|
363
|
+
_ts_decorate6([
|
|
364
|
+
Field6(() => [
|
|
365
|
+
MessageInput
|
|
366
|
+
]),
|
|
367
|
+
_ts_metadata6("design:type", Array)
|
|
368
|
+
], GenerateCopilotResponseInput.prototype, "messages", void 0);
|
|
369
|
+
_ts_decorate6([
|
|
370
|
+
Field6(() => FrontendInput),
|
|
371
|
+
_ts_metadata6("design:type", typeof FrontendInput === "undefined" ? Object : FrontendInput)
|
|
372
|
+
], GenerateCopilotResponseInput.prototype, "frontend", void 0);
|
|
373
|
+
_ts_decorate6([
|
|
374
|
+
Field6(() => CloudInput, {
|
|
375
|
+
nullable: true
|
|
376
|
+
}),
|
|
377
|
+
_ts_metadata6("design:type", typeof CloudInput === "undefined" ? Object : CloudInput)
|
|
378
|
+
], GenerateCopilotResponseInput.prototype, "cloud", void 0);
|
|
379
|
+
GenerateCopilotResponseInput = _ts_decorate6([
|
|
380
|
+
InputType6()
|
|
381
|
+
], GenerateCopilotResponseInput);
|
|
382
|
+
|
|
383
|
+
// src/graphql/types/copilot-response.type.ts
|
|
384
|
+
import { Field as Field9, InterfaceType as InterfaceType2, ObjectType as ObjectType3 } from "type-graphql";
|
|
385
|
+
|
|
386
|
+
// src/graphql/types/message-status.type.ts
|
|
387
|
+
import { Field as Field7, ObjectType, createUnionType, registerEnumType as registerEnumType2 } from "type-graphql";
|
|
388
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
389
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
390
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
391
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
392
|
+
else
|
|
393
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
394
|
+
if (d = decorators[i])
|
|
395
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
396
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
397
|
+
}
|
|
398
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
399
|
+
function _ts_metadata7(k, v) {
|
|
400
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
401
|
+
return Reflect.metadata(k, v);
|
|
402
|
+
}
|
|
403
|
+
__name(_ts_metadata7, "_ts_metadata");
|
|
404
|
+
var MessageStatusCode;
|
|
405
|
+
(function(MessageStatusCode2) {
|
|
406
|
+
MessageStatusCode2["Pending"] = "pending";
|
|
407
|
+
MessageStatusCode2["Success"] = "success";
|
|
408
|
+
MessageStatusCode2["Failed"] = "failed";
|
|
409
|
+
})(MessageStatusCode || (MessageStatusCode = {}));
|
|
410
|
+
registerEnumType2(MessageStatusCode, {
|
|
411
|
+
name: "MessageStatusCode"
|
|
412
|
+
});
|
|
413
|
+
var BaseMessageStatus = /* @__PURE__ */ __name(class BaseMessageStatus2 {
|
|
414
|
+
code;
|
|
415
|
+
}, "BaseMessageStatus");
|
|
416
|
+
_ts_decorate7([
|
|
417
|
+
Field7(() => MessageStatusCode),
|
|
418
|
+
_ts_metadata7("design:type", String)
|
|
419
|
+
], BaseMessageStatus.prototype, "code", void 0);
|
|
420
|
+
BaseMessageStatus = _ts_decorate7([
|
|
421
|
+
ObjectType()
|
|
422
|
+
], BaseMessageStatus);
|
|
423
|
+
var PendingMessageStatus = class extends BaseMessageStatus {
|
|
424
|
+
code = "pending";
|
|
425
|
+
};
|
|
426
|
+
__name(PendingMessageStatus, "PendingMessageStatus");
|
|
427
|
+
PendingMessageStatus = _ts_decorate7([
|
|
428
|
+
ObjectType()
|
|
429
|
+
], PendingMessageStatus);
|
|
430
|
+
var SuccessMessageStatus = class extends BaseMessageStatus {
|
|
431
|
+
code = "success";
|
|
432
|
+
};
|
|
433
|
+
__name(SuccessMessageStatus, "SuccessMessageStatus");
|
|
434
|
+
SuccessMessageStatus = _ts_decorate7([
|
|
435
|
+
ObjectType()
|
|
436
|
+
], SuccessMessageStatus);
|
|
437
|
+
var FailedMessageStatus = class extends BaseMessageStatus {
|
|
438
|
+
code = "failed";
|
|
439
|
+
reason;
|
|
440
|
+
};
|
|
441
|
+
__name(FailedMessageStatus, "FailedMessageStatus");
|
|
442
|
+
_ts_decorate7([
|
|
443
|
+
Field7(() => String),
|
|
444
|
+
_ts_metadata7("design:type", String)
|
|
445
|
+
], FailedMessageStatus.prototype, "reason", void 0);
|
|
446
|
+
FailedMessageStatus = _ts_decorate7([
|
|
447
|
+
ObjectType()
|
|
448
|
+
], FailedMessageStatus);
|
|
449
|
+
var MessageStatusUnion = createUnionType({
|
|
450
|
+
name: "MessageStatus",
|
|
451
|
+
types: () => [
|
|
452
|
+
PendingMessageStatus,
|
|
453
|
+
SuccessMessageStatus,
|
|
454
|
+
FailedMessageStatus
|
|
455
|
+
]
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
// src/graphql/types/response-status.type.ts
|
|
459
|
+
import { Field as Field8, InterfaceType, ObjectType as ObjectType2, createUnionType as createUnionType2, registerEnumType as registerEnumType3 } from "type-graphql";
|
|
460
|
+
function _ts_decorate8(decorators, target, key, desc) {
|
|
461
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
462
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
463
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
464
|
+
else
|
|
465
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
466
|
+
if (d = decorators[i])
|
|
467
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
468
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
469
|
+
}
|
|
470
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
471
|
+
function _ts_metadata8(k, v) {
|
|
472
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
473
|
+
return Reflect.metadata(k, v);
|
|
474
|
+
}
|
|
475
|
+
__name(_ts_metadata8, "_ts_metadata");
|
|
476
|
+
var ResponseStatusCode;
|
|
477
|
+
(function(ResponseStatusCode2) {
|
|
478
|
+
ResponseStatusCode2["Pending"] = "pending";
|
|
479
|
+
ResponseStatusCode2["Success"] = "success";
|
|
480
|
+
ResponseStatusCode2["Failed"] = "failed";
|
|
481
|
+
})(ResponseStatusCode || (ResponseStatusCode = {}));
|
|
482
|
+
registerEnumType3(ResponseStatusCode, {
|
|
483
|
+
name: "ResponseStatusCode"
|
|
484
|
+
});
|
|
485
|
+
var BaseResponseStatus = /* @__PURE__ */ __name(class BaseResponseStatus2 {
|
|
486
|
+
code;
|
|
487
|
+
}, "BaseResponseStatus");
|
|
488
|
+
_ts_decorate8([
|
|
489
|
+
Field8(() => ResponseStatusCode),
|
|
490
|
+
_ts_metadata8("design:type", String)
|
|
491
|
+
], BaseResponseStatus.prototype, "code", void 0);
|
|
492
|
+
BaseResponseStatus = _ts_decorate8([
|
|
493
|
+
InterfaceType({
|
|
494
|
+
resolveType(value) {
|
|
495
|
+
if (value.code === "success") {
|
|
496
|
+
return SuccessResponseStatus;
|
|
497
|
+
} else if (value.code === "failed") {
|
|
498
|
+
return FailedResponseStatus;
|
|
499
|
+
} else if (value.code === "pending") {
|
|
500
|
+
return PendingResponseStatus;
|
|
501
|
+
}
|
|
502
|
+
return void 0;
|
|
503
|
+
}
|
|
504
|
+
}),
|
|
505
|
+
ObjectType2()
|
|
506
|
+
], BaseResponseStatus);
|
|
507
|
+
var PendingResponseStatus = class extends BaseResponseStatus {
|
|
508
|
+
code = "pending";
|
|
509
|
+
};
|
|
510
|
+
__name(PendingResponseStatus, "PendingResponseStatus");
|
|
511
|
+
PendingResponseStatus = _ts_decorate8([
|
|
512
|
+
ObjectType2({
|
|
513
|
+
implements: BaseResponseStatus
|
|
514
|
+
})
|
|
515
|
+
], PendingResponseStatus);
|
|
516
|
+
var SuccessResponseStatus = class extends BaseResponseStatus {
|
|
517
|
+
code = "success";
|
|
518
|
+
};
|
|
519
|
+
__name(SuccessResponseStatus, "SuccessResponseStatus");
|
|
520
|
+
SuccessResponseStatus = _ts_decorate8([
|
|
521
|
+
ObjectType2({
|
|
522
|
+
implements: BaseResponseStatus
|
|
523
|
+
})
|
|
524
|
+
], SuccessResponseStatus);
|
|
525
|
+
var FailedResponseStatus = class extends BaseResponseStatus {
|
|
526
|
+
code = "failed";
|
|
527
|
+
reason;
|
|
528
|
+
};
|
|
529
|
+
__name(FailedResponseStatus, "FailedResponseStatus");
|
|
530
|
+
_ts_decorate8([
|
|
531
|
+
Field8(() => String),
|
|
532
|
+
_ts_metadata8("design:type", String)
|
|
533
|
+
], FailedResponseStatus.prototype, "reason", void 0);
|
|
534
|
+
FailedResponseStatus = _ts_decorate8([
|
|
535
|
+
ObjectType2({
|
|
536
|
+
implements: BaseResponseStatus
|
|
537
|
+
})
|
|
538
|
+
], FailedResponseStatus);
|
|
539
|
+
var ResponseStatusUnion = createUnionType2({
|
|
540
|
+
name: "ResponseStatus",
|
|
541
|
+
types: () => [
|
|
542
|
+
PendingResponseStatus,
|
|
543
|
+
SuccessResponseStatus,
|
|
544
|
+
FailedResponseStatus
|
|
545
|
+
]
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
// src/graphql/types/copilot-response.type.ts
|
|
549
|
+
function _ts_decorate9(decorators, target, key, desc) {
|
|
550
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
551
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
552
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
553
|
+
else
|
|
554
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
555
|
+
if (d = decorators[i])
|
|
556
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
557
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
558
|
+
}
|
|
559
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
560
|
+
function _ts_metadata9(k, v) {
|
|
561
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
562
|
+
return Reflect.metadata(k, v);
|
|
563
|
+
}
|
|
564
|
+
__name(_ts_metadata9, "_ts_metadata");
|
|
565
|
+
var BaseMessageOutput = /* @__PURE__ */ __name(class BaseMessageOutput2 {
|
|
566
|
+
id;
|
|
567
|
+
createdAt;
|
|
568
|
+
status;
|
|
569
|
+
}, "BaseMessageOutput");
|
|
570
|
+
_ts_decorate9([
|
|
571
|
+
Field9(() => String),
|
|
572
|
+
_ts_metadata9("design:type", String)
|
|
573
|
+
], BaseMessageOutput.prototype, "id", void 0);
|
|
574
|
+
_ts_decorate9([
|
|
575
|
+
Field9(() => Date),
|
|
576
|
+
_ts_metadata9("design:type", typeof Date === "undefined" ? Object : Date)
|
|
577
|
+
], BaseMessageOutput.prototype, "createdAt", void 0);
|
|
578
|
+
_ts_decorate9([
|
|
579
|
+
Field9(() => MessageStatusUnion),
|
|
580
|
+
_ts_metadata9("design:type", Object)
|
|
581
|
+
], BaseMessageOutput.prototype, "status", void 0);
|
|
582
|
+
BaseMessageOutput = _ts_decorate9([
|
|
583
|
+
InterfaceType2({
|
|
584
|
+
resolveType(value) {
|
|
585
|
+
if (value.hasOwnProperty("content")) {
|
|
586
|
+
return TextMessageOutput;
|
|
587
|
+
} else if (value.hasOwnProperty("name")) {
|
|
588
|
+
return ActionExecutionMessageOutput;
|
|
589
|
+
} else if (value.hasOwnProperty("result")) {
|
|
590
|
+
return ResultMessageOutput;
|
|
591
|
+
}
|
|
592
|
+
return void 0;
|
|
593
|
+
}
|
|
594
|
+
})
|
|
595
|
+
], BaseMessageOutput);
|
|
596
|
+
var TextMessageOutput = class {
|
|
597
|
+
role;
|
|
598
|
+
content;
|
|
599
|
+
};
|
|
600
|
+
__name(TextMessageOutput, "TextMessageOutput");
|
|
601
|
+
_ts_decorate9([
|
|
602
|
+
Field9(() => MessageRole),
|
|
603
|
+
_ts_metadata9("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
|
|
604
|
+
], TextMessageOutput.prototype, "role", void 0);
|
|
605
|
+
_ts_decorate9([
|
|
606
|
+
Field9(() => [
|
|
607
|
+
String
|
|
608
|
+
]),
|
|
609
|
+
_ts_metadata9("design:type", Array)
|
|
610
|
+
], TextMessageOutput.prototype, "content", void 0);
|
|
611
|
+
TextMessageOutput = _ts_decorate9([
|
|
612
|
+
ObjectType3({
|
|
613
|
+
implements: BaseMessageOutput
|
|
614
|
+
})
|
|
615
|
+
], TextMessageOutput);
|
|
616
|
+
var ActionExecutionMessageOutput = class {
|
|
617
|
+
name;
|
|
618
|
+
scope;
|
|
619
|
+
arguments;
|
|
620
|
+
};
|
|
621
|
+
__name(ActionExecutionMessageOutput, "ActionExecutionMessageOutput");
|
|
622
|
+
_ts_decorate9([
|
|
623
|
+
Field9(() => String),
|
|
624
|
+
_ts_metadata9("design:type", String)
|
|
625
|
+
], ActionExecutionMessageOutput.prototype, "name", void 0);
|
|
626
|
+
_ts_decorate9([
|
|
627
|
+
Field9(() => ActionExecutionScope),
|
|
628
|
+
_ts_metadata9("design:type", typeof ActionExecutionScope === "undefined" ? Object : ActionExecutionScope)
|
|
629
|
+
], ActionExecutionMessageOutput.prototype, "scope", void 0);
|
|
630
|
+
_ts_decorate9([
|
|
631
|
+
Field9(() => [
|
|
632
|
+
String
|
|
633
|
+
]),
|
|
634
|
+
_ts_metadata9("design:type", Array)
|
|
635
|
+
], ActionExecutionMessageOutput.prototype, "arguments", void 0);
|
|
636
|
+
ActionExecutionMessageOutput = _ts_decorate9([
|
|
637
|
+
ObjectType3({
|
|
638
|
+
implements: BaseMessageOutput
|
|
639
|
+
})
|
|
640
|
+
], ActionExecutionMessageOutput);
|
|
641
|
+
var ResultMessageOutput = class {
|
|
642
|
+
actionExecutionId;
|
|
643
|
+
actionName;
|
|
644
|
+
result;
|
|
645
|
+
};
|
|
646
|
+
__name(ResultMessageOutput, "ResultMessageOutput");
|
|
647
|
+
_ts_decorate9([
|
|
648
|
+
Field9(() => String),
|
|
649
|
+
_ts_metadata9("design:type", String)
|
|
650
|
+
], ResultMessageOutput.prototype, "actionExecutionId", void 0);
|
|
651
|
+
_ts_decorate9([
|
|
652
|
+
Field9(() => String),
|
|
653
|
+
_ts_metadata9("design:type", String)
|
|
654
|
+
], ResultMessageOutput.prototype, "actionName", void 0);
|
|
655
|
+
_ts_decorate9([
|
|
656
|
+
Field9(() => String),
|
|
657
|
+
_ts_metadata9("design:type", String)
|
|
658
|
+
], ResultMessageOutput.prototype, "result", void 0);
|
|
659
|
+
ResultMessageOutput = _ts_decorate9([
|
|
660
|
+
ObjectType3({
|
|
661
|
+
implements: BaseMessageOutput
|
|
662
|
+
})
|
|
663
|
+
], ResultMessageOutput);
|
|
664
|
+
var CopilotResponse = class {
|
|
665
|
+
threadId;
|
|
666
|
+
status;
|
|
667
|
+
runId;
|
|
668
|
+
messages;
|
|
669
|
+
};
|
|
670
|
+
__name(CopilotResponse, "CopilotResponse");
|
|
671
|
+
_ts_decorate9([
|
|
672
|
+
Field9(() => String),
|
|
673
|
+
_ts_metadata9("design:type", String)
|
|
674
|
+
], CopilotResponse.prototype, "threadId", void 0);
|
|
675
|
+
_ts_decorate9([
|
|
676
|
+
Field9(() => ResponseStatusUnion),
|
|
677
|
+
_ts_metadata9("design:type", Object)
|
|
678
|
+
], CopilotResponse.prototype, "status", void 0);
|
|
679
|
+
_ts_decorate9([
|
|
680
|
+
Field9({
|
|
681
|
+
nullable: true
|
|
682
|
+
}),
|
|
683
|
+
_ts_metadata9("design:type", String)
|
|
684
|
+
], CopilotResponse.prototype, "runId", void 0);
|
|
685
|
+
_ts_decorate9([
|
|
686
|
+
Field9(() => [
|
|
687
|
+
BaseMessageOutput
|
|
688
|
+
]),
|
|
689
|
+
_ts_metadata9("design:type", Array)
|
|
690
|
+
], CopilotResponse.prototype, "messages", void 0);
|
|
691
|
+
CopilotResponse = _ts_decorate9([
|
|
692
|
+
ObjectType3()
|
|
693
|
+
], CopilotResponse);
|
|
694
|
+
|
|
695
|
+
// src/graphql/resolvers/copilot.resolver.ts
|
|
696
|
+
import { Repeater } from "graphql-yoga";
|
|
697
|
+
import { nanoid } from "nanoid";
|
|
698
|
+
|
|
699
|
+
// src/service-adapters/events.ts
|
|
700
|
+
import { of, concat, map, scan, concatMap, ReplaySubject } from "rxjs";
|
|
701
|
+
var RuntimeEventTypes;
|
|
702
|
+
(function(RuntimeEventTypes2) {
|
|
703
|
+
RuntimeEventTypes2["TextMessageStart"] = "TextMessageStart";
|
|
704
|
+
RuntimeEventTypes2["TextMessageContent"] = "TextMessageContent";
|
|
705
|
+
RuntimeEventTypes2["TextMessageEnd"] = "TextMessageEnd";
|
|
706
|
+
RuntimeEventTypes2["ActionExecutionStart"] = "ActionExecutionStart";
|
|
707
|
+
RuntimeEventTypes2["ActionExecutionArgs"] = "ActionExecutionArgs";
|
|
708
|
+
RuntimeEventTypes2["ActionExecutionEnd"] = "ActionExecutionEnd";
|
|
709
|
+
RuntimeEventTypes2["ActionExecutionResult"] = "ActionExecutionResult";
|
|
710
|
+
})(RuntimeEventTypes || (RuntimeEventTypes = {}));
|
|
711
|
+
var RuntimeEventSubject = class extends ReplaySubject {
|
|
712
|
+
constructor() {
|
|
713
|
+
super();
|
|
714
|
+
}
|
|
715
|
+
sendTextMessageStart(messageId) {
|
|
716
|
+
this.next({
|
|
717
|
+
type: "TextMessageStart",
|
|
718
|
+
messageId
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
sendTextMessageContent(content) {
|
|
722
|
+
this.next({
|
|
723
|
+
type: "TextMessageContent",
|
|
724
|
+
content
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
sendTextMessageEnd() {
|
|
728
|
+
this.next({
|
|
729
|
+
type: "TextMessageEnd"
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
sendTextMessage(messageId, content) {
|
|
733
|
+
this.sendTextMessageStart(messageId);
|
|
734
|
+
this.sendTextMessageContent(content);
|
|
735
|
+
this.sendTextMessageEnd();
|
|
736
|
+
}
|
|
737
|
+
sendActionExecutionStart(actionExecutionId, actionName) {
|
|
738
|
+
this.next({
|
|
739
|
+
type: "ActionExecutionStart",
|
|
740
|
+
actionExecutionId,
|
|
741
|
+
actionName
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
sendActionExecutionArgs(args) {
|
|
745
|
+
this.next({
|
|
746
|
+
type: "ActionExecutionArgs",
|
|
747
|
+
args
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
sendActionExecutionEnd() {
|
|
751
|
+
this.next({
|
|
752
|
+
type: "ActionExecutionEnd"
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
sendActionExecution(actionExecutionId, toolName, args) {
|
|
756
|
+
this.sendActionExecutionStart(actionExecutionId, toolName);
|
|
757
|
+
this.sendActionExecutionArgs(args);
|
|
758
|
+
this.sendActionExecutionEnd();
|
|
759
|
+
}
|
|
760
|
+
sendActionExecutionResult(actionExecutionId, actionName, result) {
|
|
761
|
+
this.next({
|
|
762
|
+
type: "ActionExecutionResult",
|
|
763
|
+
actionName,
|
|
764
|
+
actionExecutionId,
|
|
765
|
+
result
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
};
|
|
769
|
+
__name(RuntimeEventSubject, "RuntimeEventSubject");
|
|
770
|
+
var RuntimeEventSource = class {
|
|
771
|
+
eventStream$ = new RuntimeEventSubject();
|
|
772
|
+
callback;
|
|
773
|
+
async stream(callback) {
|
|
774
|
+
this.callback = callback;
|
|
775
|
+
}
|
|
776
|
+
process(serversideActions) {
|
|
777
|
+
this.callback(this.eventStream$).catch((error) => {
|
|
778
|
+
console.error("Error in event source callback", error);
|
|
779
|
+
});
|
|
780
|
+
return this.eventStream$.pipe(
|
|
781
|
+
// mark tools for server side execution
|
|
782
|
+
map((event) => {
|
|
783
|
+
if (event.type === "ActionExecutionStart") {
|
|
784
|
+
event.scope = serversideActions.find((action) => action.name === event.actionName) ? "server" : "client";
|
|
785
|
+
}
|
|
786
|
+
return event;
|
|
787
|
+
}),
|
|
788
|
+
// track state
|
|
789
|
+
scan((acc, event) => {
|
|
790
|
+
if (event.type === "ActionExecutionStart") {
|
|
791
|
+
acc.callActionServerSide = event.scope === "server";
|
|
792
|
+
acc.args = "";
|
|
793
|
+
acc.actionExecutionId = event.actionExecutionId;
|
|
794
|
+
if (acc.callActionServerSide) {
|
|
795
|
+
acc.action = serversideActions.find((action) => action.name === event.actionName);
|
|
796
|
+
}
|
|
797
|
+
} else if (event.type === "ActionExecutionArgs") {
|
|
798
|
+
acc.args += event.args;
|
|
799
|
+
}
|
|
800
|
+
acc.event = event;
|
|
801
|
+
return acc;
|
|
802
|
+
}, {
|
|
803
|
+
event: null,
|
|
804
|
+
callActionServerSide: false,
|
|
805
|
+
args: "",
|
|
806
|
+
actionExecutionId: null,
|
|
807
|
+
action: null
|
|
808
|
+
}),
|
|
809
|
+
concatMap((eventWithState) => {
|
|
810
|
+
if (eventWithState.event.type === "ActionExecutionEnd" && eventWithState.callActionServerSide) {
|
|
811
|
+
const toolCallEventStream$ = new RuntimeEventSubject();
|
|
812
|
+
executeAction(toolCallEventStream$, eventWithState.action, eventWithState.args, eventWithState.actionExecutionId).catch((error) => {
|
|
813
|
+
console.error(error);
|
|
814
|
+
});
|
|
815
|
+
return concat(of(eventWithState.event), toolCallEventStream$);
|
|
816
|
+
} else {
|
|
817
|
+
return of(eventWithState.event);
|
|
818
|
+
}
|
|
819
|
+
})
|
|
820
|
+
);
|
|
821
|
+
}
|
|
822
|
+
};
|
|
823
|
+
__name(RuntimeEventSource, "RuntimeEventSource");
|
|
824
|
+
async function executeAction(eventStream$, action, actionArguments, actionExecutionId) {
|
|
825
|
+
let args = [];
|
|
826
|
+
if (actionArguments) {
|
|
827
|
+
args = JSON.parse(actionArguments);
|
|
828
|
+
}
|
|
829
|
+
const result = await action.handler(args);
|
|
830
|
+
await streamLangChainResponse({
|
|
831
|
+
result,
|
|
832
|
+
eventStream$,
|
|
833
|
+
actionExecution: {
|
|
834
|
+
name: action.name,
|
|
835
|
+
id: actionExecutionId
|
|
836
|
+
}
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
__name(executeAction, "executeAction");
|
|
840
|
+
|
|
841
|
+
// src/graphql/resolvers/copilot.resolver.ts
|
|
842
|
+
import { GraphQLJSONObject } from "graphql-scalars";
|
|
843
|
+
function _ts_decorate10(decorators, target, key, desc) {
|
|
844
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
845
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
846
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
847
|
+
else
|
|
848
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
849
|
+
if (d = decorators[i])
|
|
850
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
851
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
852
|
+
}
|
|
853
|
+
__name(_ts_decorate10, "_ts_decorate");
|
|
854
|
+
function _ts_metadata10(k, v) {
|
|
855
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
856
|
+
return Reflect.metadata(k, v);
|
|
857
|
+
}
|
|
858
|
+
__name(_ts_metadata10, "_ts_metadata");
|
|
859
|
+
function _ts_param(paramIndex, decorator) {
|
|
860
|
+
return function(target, key) {
|
|
861
|
+
decorator(target, key, paramIndex);
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
__name(_ts_param, "_ts_param");
|
|
865
|
+
var CopilotResolver = class {
|
|
866
|
+
async hello() {
|
|
867
|
+
return "Hello World";
|
|
868
|
+
}
|
|
869
|
+
async generateCopilotResponse(ctx, data, properties) {
|
|
870
|
+
if (properties) {
|
|
871
|
+
ctx._copilotkit.properties = {
|
|
872
|
+
...ctx._copilotkit.properties,
|
|
873
|
+
...properties
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
const copilotRuntime = ctx._copilotkit.runtime;
|
|
877
|
+
const serviceAdapter = ctx._copilotkit.serviceAdapter;
|
|
878
|
+
const responseStatus = new Subject();
|
|
879
|
+
const { eventSource, threadId = nanoid(), runId } = await copilotRuntime.process({
|
|
880
|
+
serviceAdapter,
|
|
881
|
+
messages: data.messages,
|
|
882
|
+
actions: data.frontend.actions,
|
|
883
|
+
threadId: data.threadId,
|
|
884
|
+
runId: data.runId,
|
|
885
|
+
publicApiKey: void 0
|
|
886
|
+
});
|
|
887
|
+
const response = {
|
|
888
|
+
threadId,
|
|
889
|
+
runId,
|
|
890
|
+
status: firstValueFrom(responseStatus),
|
|
891
|
+
messages: new Repeater(async (pushMessage, stopStreamingMessages) => {
|
|
892
|
+
const eventStream = eventSource.process(copilotRuntime.actions).pipe(
|
|
893
|
+
// shareReplay() ensures that later subscribers will see the whole stream instead of
|
|
894
|
+
// just the events that were emitted after the subscriber was added.
|
|
895
|
+
shareReplay()
|
|
896
|
+
);
|
|
897
|
+
eventStream.subscribe({
|
|
898
|
+
next: async (event) => {
|
|
899
|
+
switch (event.type) {
|
|
900
|
+
case RuntimeEventTypes.TextMessageStart:
|
|
901
|
+
const textMessageContentStream = eventStream.pipe(
|
|
902
|
+
// skip until this message start event
|
|
903
|
+
skipWhile((e) => e !== event),
|
|
904
|
+
// take until the message end event
|
|
905
|
+
takeWhile((e) => e.type != RuntimeEventTypes.TextMessageEnd)
|
|
906
|
+
);
|
|
907
|
+
const streamingTextStatus = new Subject();
|
|
908
|
+
pushMessage({
|
|
909
|
+
id: nanoid(),
|
|
910
|
+
status: firstValueFrom(streamingTextStatus),
|
|
911
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
912
|
+
role: MessageRole.assistant,
|
|
913
|
+
content: new Repeater(async (pushTextChunk, stopStreamingText) => {
|
|
914
|
+
await textMessageContentStream.forEach(async (e) => {
|
|
915
|
+
if (e.type == RuntimeEventTypes.TextMessageContent) {
|
|
916
|
+
await pushTextChunk(e.content);
|
|
917
|
+
}
|
|
918
|
+
});
|
|
919
|
+
stopStreamingText();
|
|
920
|
+
streamingTextStatus.next(new SuccessMessageStatus());
|
|
921
|
+
})
|
|
922
|
+
});
|
|
923
|
+
break;
|
|
924
|
+
case RuntimeEventTypes.ActionExecutionStart:
|
|
925
|
+
const actionExecutionArgumentStream = eventStream.pipe(skipWhile((e) => e !== event), takeWhile((e) => e.type != RuntimeEventTypes.ActionExecutionEnd));
|
|
926
|
+
const streamingArgumentsStatus = new Subject();
|
|
927
|
+
pushMessage({
|
|
928
|
+
id: event.actionExecutionId,
|
|
929
|
+
status: firstValueFrom(streamingArgumentsStatus),
|
|
930
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
931
|
+
name: event.actionName,
|
|
932
|
+
scope: event.scope,
|
|
933
|
+
arguments: new Repeater(async (pushArgumentsChunk, stopStreamingArguments) => {
|
|
934
|
+
await actionExecutionArgumentStream.forEach(async (e) => {
|
|
935
|
+
if (e.type == RuntimeEventTypes.ActionExecutionArgs) {
|
|
936
|
+
await pushArgumentsChunk(e.args);
|
|
937
|
+
}
|
|
938
|
+
});
|
|
939
|
+
stopStreamingArguments();
|
|
940
|
+
streamingArgumentsStatus.next(new SuccessMessageStatus());
|
|
941
|
+
})
|
|
942
|
+
});
|
|
943
|
+
break;
|
|
944
|
+
case RuntimeEventTypes.ActionExecutionResult:
|
|
945
|
+
pushMessage({
|
|
946
|
+
id: nanoid(),
|
|
947
|
+
status: new SuccessMessageStatus(),
|
|
948
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
949
|
+
actionExecutionId: event.actionExecutionId,
|
|
950
|
+
actionName: event.actionName,
|
|
951
|
+
result: event.result
|
|
952
|
+
});
|
|
953
|
+
break;
|
|
954
|
+
}
|
|
955
|
+
},
|
|
956
|
+
error: (err) => console.error("Error in event source", err),
|
|
957
|
+
complete: () => {
|
|
958
|
+
responseStatus.next(new SuccessResponseStatus());
|
|
959
|
+
stopStreamingMessages();
|
|
960
|
+
}
|
|
961
|
+
});
|
|
962
|
+
})
|
|
963
|
+
};
|
|
964
|
+
return response;
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
__name(CopilotResolver, "CopilotResolver");
|
|
968
|
+
_ts_decorate10([
|
|
969
|
+
Query(() => String),
|
|
970
|
+
_ts_metadata10("design:type", Function),
|
|
971
|
+
_ts_metadata10("design:paramtypes", []),
|
|
972
|
+
_ts_metadata10("design:returntype", Promise)
|
|
973
|
+
], CopilotResolver.prototype, "hello", null);
|
|
974
|
+
_ts_decorate10([
|
|
975
|
+
Mutation(() => CopilotResponse),
|
|
976
|
+
_ts_param(0, Ctx()),
|
|
977
|
+
_ts_param(1, Arg("data")),
|
|
978
|
+
_ts_param(2, Arg("properties", () => GraphQLJSONObject, {
|
|
979
|
+
nullable: true
|
|
980
|
+
})),
|
|
981
|
+
_ts_metadata10("design:type", Function),
|
|
982
|
+
_ts_metadata10("design:paramtypes", [
|
|
983
|
+
typeof GraphQLContext === "undefined" ? Object : GraphQLContext,
|
|
984
|
+
typeof GenerateCopilotResponseInput === "undefined" ? Object : GenerateCopilotResponseInput,
|
|
985
|
+
typeof CopilotRequestContextProperties === "undefined" ? Object : CopilotRequestContextProperties
|
|
986
|
+
]),
|
|
987
|
+
_ts_metadata10("design:returntype", Promise)
|
|
988
|
+
], CopilotResolver.prototype, "generateCopilotResponse", null);
|
|
989
|
+
CopilotResolver = _ts_decorate10([
|
|
990
|
+
Resolver(() => CopilotResponse)
|
|
991
|
+
], CopilotResolver);
|
|
992
|
+
|
|
993
|
+
// src/lib/integrations/shared.ts
|
|
994
|
+
import { useDeferStream } from "@graphql-yoga/plugin-defer-stream";
|
|
995
|
+
async function createContext(initialContext, copilotKitContext) {
|
|
996
|
+
const ctx = {
|
|
997
|
+
...initialContext,
|
|
998
|
+
_copilotkit: {
|
|
999
|
+
...copilotKitContext
|
|
1000
|
+
}
|
|
1001
|
+
};
|
|
1002
|
+
return ctx;
|
|
1003
|
+
}
|
|
1004
|
+
__name(createContext, "createContext");
|
|
1005
|
+
function buildSchema(options = {}) {
|
|
1006
|
+
const schema = buildSchemaSync({
|
|
1007
|
+
resolvers: [
|
|
1008
|
+
CopilotResolver
|
|
1009
|
+
],
|
|
1010
|
+
emitSchemaFile: options.emitSchemaFile
|
|
1011
|
+
});
|
|
1012
|
+
return schema;
|
|
1013
|
+
}
|
|
1014
|
+
__name(buildSchema, "buildSchema");
|
|
1015
|
+
function getCommonConfig(options) {
|
|
1016
|
+
return {
|
|
1017
|
+
schema: buildSchema(),
|
|
1018
|
+
plugins: [
|
|
1019
|
+
useDeferStream()
|
|
1020
|
+
],
|
|
1021
|
+
context: (ctx) => createContext(ctx, {
|
|
1022
|
+
runtime: options.runtime,
|
|
1023
|
+
serviceAdapter: options.serviceAdapter,
|
|
1024
|
+
properties: {}
|
|
1025
|
+
})
|
|
1026
|
+
};
|
|
1027
|
+
}
|
|
1028
|
+
__name(getCommonConfig, "getCommonConfig");
|
|
1029
|
+
|
|
1030
|
+
// src/lib/integrations/node-http/index.ts
|
|
1031
|
+
function copilotRuntimeNodeHttpEndpoint({ runtime, endpoint, serviceAdapter }) {
|
|
1032
|
+
const commonConfig = getCommonConfig({
|
|
1033
|
+
runtime,
|
|
1034
|
+
serviceAdapter
|
|
1035
|
+
});
|
|
1036
|
+
const yoga = createYoga({
|
|
1037
|
+
...commonConfig,
|
|
1038
|
+
graphqlEndpoint: endpoint
|
|
1039
|
+
});
|
|
1040
|
+
return yoga;
|
|
1041
|
+
}
|
|
1042
|
+
__name(copilotRuntimeNodeHttpEndpoint, "copilotRuntimeNodeHttpEndpoint");
|
|
1043
|
+
|
|
1044
|
+
export {
|
|
1045
|
+
RuntimeEventSource,
|
|
1046
|
+
createContext,
|
|
1047
|
+
buildSchema,
|
|
1048
|
+
getCommonConfig,
|
|
1049
|
+
copilotRuntimeNodeHttpEndpoint
|
|
1050
|
+
};
|
|
1051
|
+
//# sourceMappingURL=chunk-XPAUPJMW.mjs.map
|