@copilotkit/runtime 0.37.0 → 0.38.0-beta.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/.turbo/turbo-build.log +69 -54
- package/CHANGELOG.md +11 -0
- package/__snapshots__/schema/schema.graphql +15 -4
- package/dist/{chunk-2CCVVJDU.mjs → chunk-2PJG3NAC.mjs} +13 -15
- package/dist/chunk-2PJG3NAC.mjs.map +1 -0
- package/dist/{chunk-NFCPM5AM.mjs → chunk-6NZ4UMOD.mjs} +4 -4
- package/dist/chunk-6NZ4UMOD.mjs.map +1 -0
- package/dist/{chunk-XPAUPJMW.mjs → chunk-6YGDE3YI.mjs} +432 -220
- package/dist/chunk-6YGDE3YI.mjs.map +1 -0
- package/dist/chunk-BYB2LNMK.mjs +152 -0
- package/dist/chunk-BYB2LNMK.mjs.map +1 -0
- package/dist/{chunk-7IFP53C6.mjs → chunk-FRK6BXXV.mjs} +49 -11
- package/dist/chunk-FRK6BXXV.mjs.map +1 -0
- package/dist/{chunk-5HGYI6EG.mjs → chunk-JBDOA7MK.mjs} +34 -15
- package/dist/chunk-JBDOA7MK.mjs.map +1 -0
- package/dist/{chunk-4UA4RB4C.mjs → chunk-JIKPSUGQ.mjs} +45 -76
- package/dist/chunk-JIKPSUGQ.mjs.map +1 -0
- package/dist/{chunk-BLTAUVRP.mjs → chunk-OZMCHYYR.mjs} +5 -3
- package/dist/{chunk-BLTAUVRP.mjs.map → chunk-OZMCHYYR.mjs.map} +1 -1
- package/dist/chunk-RHQLCJGG.mjs +7 -0
- package/dist/chunk-RHQLCJGG.mjs.map +1 -0
- package/dist/failed-response-status-reasons-0ab19e06.d.ts +49 -0
- package/dist/graphql/types/base/index.mjs +2 -1
- package/dist/graphql/types/converted/index.mjs +3 -2
- package/dist/{index-f0875df3.d.ts → index-0e75acd2.d.ts} +86 -59
- package/dist/index.d.ts +7 -4
- package/dist/index.js +536 -169
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -13
- package/dist/index.mjs.map +1 -1
- package/dist/{langchain-adapter-9ce103f3.d.ts → langchain-adapter-a02d1d38.d.ts} +4 -4
- package/dist/{langserve-fd5066ee.d.ts → langserve-75ebbc38.d.ts} +25 -9
- package/dist/lib/cloud/index.d.ts +6 -0
- package/dist/lib/cloud/index.js +18 -0
- package/dist/lib/cloud/index.js.map +1 -0
- package/dist/lib/cloud/index.mjs +1 -0
- package/dist/lib/cloud/index.mjs.map +1 -0
- package/dist/lib/index.d.ts +6 -4
- package/dist/lib/index.js +530 -169
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +9 -13
- package/dist/lib/integrations/index.d.ts +5 -3
- package/dist/lib/integrations/index.js +426 -64
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +7 -5
- package/dist/lib/integrations/node-http/index.d.ts +4 -2
- package/dist/lib/integrations/node-http/index.js +416 -52
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +6 -4
- package/dist/pages-router-e81920d5.d.ts +21 -0
- package/dist/service-adapters/index.d.ts +2 -2
- package/dist/service-adapters/index.js +82 -25
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +5 -4
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +174 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +12 -0
- package/dist/utils/index.mjs.map +1 -0
- package/package.json +6 -4
- package/src/graphql/inputs/cloud-guardrails.input.ts +2 -5
- package/src/graphql/inputs/cloud.input.ts +2 -2
- package/src/graphql/resolvers/copilot.resolver.ts +340 -30
- package/src/graphql/types/response-status.type.ts +16 -2
- package/src/index.ts +1 -0
- package/src/lib/cloud/index.ts +4 -0
- package/src/lib/copilot-runtime.ts +116 -70
- package/src/lib/index.ts +0 -1
- package/src/lib/integrations/nextjs/app-router.ts +9 -17
- package/src/lib/integrations/nextjs/pages-router.ts +9 -15
- package/src/lib/integrations/node-http/index.ts +6 -14
- package/src/lib/integrations/shared.ts +38 -18
- package/src/lib/logger.ts +28 -0
- package/src/service-adapters/events.ts +20 -2
- package/src/service-adapters/experimental/groq/groq-adapter.ts +3 -1
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +3 -1
- package/src/service-adapters/google/google-genai-adapter.ts +6 -1
- package/src/service-adapters/google/utils.ts +1 -1
- package/src/service-adapters/index.ts +1 -1
- package/src/service-adapters/langchain/langchain-adapter.ts +8 -9
- package/src/service-adapters/langchain/langserve.ts +10 -4
- package/src/service-adapters/langchain/utils.ts +58 -9
- package/src/service-adapters/openai/openai-adapter.ts +8 -7
- package/src/service-adapters/openai/openai-assistant-adapter.ts +6 -8
- package/src/service-adapters/service-adapter.ts +1 -2
- package/src/utils/failed-response-status-reasons.ts +48 -0
- package/src/utils/index.ts +1 -0
- package/dist/chunk-2CCVVJDU.mjs.map +0 -1
- package/dist/chunk-4UA4RB4C.mjs.map +0 -1
- package/dist/chunk-5HGYI6EG.mjs.map +0 -1
- package/dist/chunk-7IFP53C6.mjs.map +0 -1
- package/dist/chunk-NFCPM5AM.mjs.map +0 -1
- package/dist/chunk-XPAUPJMW.mjs.map +0 -1
- package/dist/pages-router-b6bc6c60.d.ts +0 -30
- package/src/lib/copilot-cloud.ts +0 -63
- package/src/lib/guardrails.ts +0 -3
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
2
|
streamLangChainResponse
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-FRK6BXXV.mjs";
|
|
4
|
+
import {
|
|
5
|
+
GuardrailsValidationFailureResponse,
|
|
6
|
+
MessageStreamInterruptedResponse,
|
|
7
|
+
ResponseStatusUnion,
|
|
8
|
+
SuccessResponseStatus,
|
|
9
|
+
UnknownErrorResponse
|
|
10
|
+
} from "./chunk-BYB2LNMK.mjs";
|
|
11
|
+
import {
|
|
12
|
+
ActionExecutionMessage,
|
|
13
|
+
ResultMessage,
|
|
14
|
+
TextMessage
|
|
15
|
+
} from "./chunk-OZMCHYYR.mjs";
|
|
16
|
+
import {
|
|
17
|
+
BaseMessage
|
|
18
|
+
} from "./chunk-6NZ4UMOD.mjs";
|
|
4
19
|
import {
|
|
5
|
-
BaseMessage,
|
|
6
20
|
__name
|
|
7
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-RHQLCJGG.mjs";
|
|
8
22
|
|
|
9
23
|
// src/lib/integrations/node-http/index.ts
|
|
10
24
|
import { createYoga } from "graphql-yoga";
|
|
@@ -14,7 +28,7 @@ import { buildSchemaSync } from "type-graphql";
|
|
|
14
28
|
|
|
15
29
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
16
30
|
import { Arg, Ctx, Mutation, Query, Resolver } from "type-graphql";
|
|
17
|
-
import { Subject, firstValueFrom, shareReplay, skipWhile, takeWhile } from "rxjs";
|
|
31
|
+
import { ReplaySubject as ReplaySubject2, Subject, finalize, firstValueFrom as firstValueFrom2, shareReplay, skipWhile, take, takeWhile, tap } from "rxjs";
|
|
18
32
|
|
|
19
33
|
// src/graphql/inputs/generate-copilot-response.input.ts
|
|
20
34
|
import { Field as Field6, InputType as InputType6 } from "type-graphql";
|
|
@@ -250,15 +264,10 @@ function _ts_metadata4(k, v) {
|
|
|
250
264
|
}
|
|
251
265
|
__name(_ts_metadata4, "_ts_metadata");
|
|
252
266
|
var GuardrailsRuleInput = class {
|
|
253
|
-
id;
|
|
254
267
|
allowList = [];
|
|
255
268
|
denyList = [];
|
|
256
269
|
};
|
|
257
270
|
__name(GuardrailsRuleInput, "GuardrailsRuleInput");
|
|
258
|
-
_ts_decorate4([
|
|
259
|
-
Field4(() => String),
|
|
260
|
-
_ts_metadata4("design:type", String)
|
|
261
|
-
], GuardrailsRuleInput.prototype, "id", void 0);
|
|
262
271
|
_ts_decorate4([
|
|
263
272
|
Field4(() => [
|
|
264
273
|
String
|
|
@@ -279,16 +288,17 @@ GuardrailsRuleInput = _ts_decorate4([
|
|
|
279
288
|
InputType4()
|
|
280
289
|
], GuardrailsRuleInput);
|
|
281
290
|
var GuardrailsInput = class {
|
|
282
|
-
inputValidationRules =
|
|
291
|
+
inputValidationRules = {
|
|
292
|
+
allowList: [],
|
|
293
|
+
denyList: []
|
|
294
|
+
};
|
|
283
295
|
};
|
|
284
296
|
__name(GuardrailsInput, "GuardrailsInput");
|
|
285
297
|
_ts_decorate4([
|
|
286
|
-
Field4(() =>
|
|
287
|
-
GuardrailsRuleInput
|
|
288
|
-
], {
|
|
298
|
+
Field4(() => GuardrailsRuleInput, {
|
|
289
299
|
nullable: true
|
|
290
300
|
}),
|
|
291
|
-
_ts_metadata4("design:type",
|
|
301
|
+
_ts_metadata4("design:type", typeof GuardrailsRuleInput === "undefined" ? Object : GuardrailsRuleInput)
|
|
292
302
|
], GuardrailsInput.prototype, "inputValidationRules", void 0);
|
|
293
303
|
GuardrailsInput = _ts_decorate4([
|
|
294
304
|
InputType4()
|
|
@@ -316,7 +326,9 @@ var CloudInput = class {
|
|
|
316
326
|
};
|
|
317
327
|
__name(CloudInput, "CloudInput");
|
|
318
328
|
_ts_decorate5([
|
|
319
|
-
Field5(() => GuardrailsInput
|
|
329
|
+
Field5(() => GuardrailsInput, {
|
|
330
|
+
nullable: true
|
|
331
|
+
}),
|
|
320
332
|
_ts_metadata5("design:type", typeof GuardrailsInput === "undefined" ? Object : GuardrailsInput)
|
|
321
333
|
], CloudInput.prototype, "guardrails", void 0);
|
|
322
334
|
CloudInput = _ts_decorate5([
|
|
@@ -381,7 +393,7 @@ GenerateCopilotResponseInput = _ts_decorate6([
|
|
|
381
393
|
], GenerateCopilotResponseInput);
|
|
382
394
|
|
|
383
395
|
// src/graphql/types/copilot-response.type.ts
|
|
384
|
-
import { Field as
|
|
396
|
+
import { Field as Field8, InterfaceType, ObjectType as ObjectType2 } from "type-graphql";
|
|
385
397
|
|
|
386
398
|
// src/graphql/types/message-status.type.ts
|
|
387
399
|
import { Field as Field7, ObjectType, createUnionType, registerEnumType as registerEnumType2 } from "type-graphql";
|
|
@@ -455,8 +467,7 @@ var MessageStatusUnion = createUnionType({
|
|
|
455
467
|
]
|
|
456
468
|
});
|
|
457
469
|
|
|
458
|
-
// src/graphql/types/response
|
|
459
|
-
import { Field as Field8, InterfaceType, ObjectType as ObjectType2, createUnionType as createUnionType2, registerEnumType as registerEnumType3 } from "type-graphql";
|
|
470
|
+
// src/graphql/types/copilot-response.type.ts
|
|
460
471
|
function _ts_decorate8(decorators, target, key, desc) {
|
|
461
472
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
462
473
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -473,114 +484,25 @@ function _ts_metadata8(k, v) {
|
|
|
473
484
|
return Reflect.metadata(k, v);
|
|
474
485
|
}
|
|
475
486
|
__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
487
|
var BaseMessageOutput = /* @__PURE__ */ __name(class BaseMessageOutput2 {
|
|
566
488
|
id;
|
|
567
489
|
createdAt;
|
|
568
490
|
status;
|
|
569
491
|
}, "BaseMessageOutput");
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
492
|
+
_ts_decorate8([
|
|
493
|
+
Field8(() => String),
|
|
494
|
+
_ts_metadata8("design:type", String)
|
|
573
495
|
], BaseMessageOutput.prototype, "id", void 0);
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
496
|
+
_ts_decorate8([
|
|
497
|
+
Field8(() => Date),
|
|
498
|
+
_ts_metadata8("design:type", typeof Date === "undefined" ? Object : Date)
|
|
577
499
|
], BaseMessageOutput.prototype, "createdAt", void 0);
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
500
|
+
_ts_decorate8([
|
|
501
|
+
Field8(() => MessageStatusUnion),
|
|
502
|
+
_ts_metadata8("design:type", Object)
|
|
581
503
|
], BaseMessageOutput.prototype, "status", void 0);
|
|
582
|
-
BaseMessageOutput =
|
|
583
|
-
|
|
504
|
+
BaseMessageOutput = _ts_decorate8([
|
|
505
|
+
InterfaceType({
|
|
584
506
|
resolveType(value) {
|
|
585
507
|
if (value.hasOwnProperty("content")) {
|
|
586
508
|
return TextMessageOutput;
|
|
@@ -598,18 +520,18 @@ var TextMessageOutput = class {
|
|
|
598
520
|
content;
|
|
599
521
|
};
|
|
600
522
|
__name(TextMessageOutput, "TextMessageOutput");
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
523
|
+
_ts_decorate8([
|
|
524
|
+
Field8(() => MessageRole),
|
|
525
|
+
_ts_metadata8("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
|
|
604
526
|
], TextMessageOutput.prototype, "role", void 0);
|
|
605
|
-
|
|
606
|
-
|
|
527
|
+
_ts_decorate8([
|
|
528
|
+
Field8(() => [
|
|
607
529
|
String
|
|
608
530
|
]),
|
|
609
|
-
|
|
531
|
+
_ts_metadata8("design:type", Array)
|
|
610
532
|
], TextMessageOutput.prototype, "content", void 0);
|
|
611
|
-
TextMessageOutput =
|
|
612
|
-
|
|
533
|
+
TextMessageOutput = _ts_decorate8([
|
|
534
|
+
ObjectType2({
|
|
613
535
|
implements: BaseMessageOutput
|
|
614
536
|
})
|
|
615
537
|
], TextMessageOutput);
|
|
@@ -619,22 +541,22 @@ var ActionExecutionMessageOutput = class {
|
|
|
619
541
|
arguments;
|
|
620
542
|
};
|
|
621
543
|
__name(ActionExecutionMessageOutput, "ActionExecutionMessageOutput");
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
544
|
+
_ts_decorate8([
|
|
545
|
+
Field8(() => String),
|
|
546
|
+
_ts_metadata8("design:type", String)
|
|
625
547
|
], ActionExecutionMessageOutput.prototype, "name", void 0);
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
548
|
+
_ts_decorate8([
|
|
549
|
+
Field8(() => ActionExecutionScope),
|
|
550
|
+
_ts_metadata8("design:type", typeof ActionExecutionScope === "undefined" ? Object : ActionExecutionScope)
|
|
629
551
|
], ActionExecutionMessageOutput.prototype, "scope", void 0);
|
|
630
|
-
|
|
631
|
-
|
|
552
|
+
_ts_decorate8([
|
|
553
|
+
Field8(() => [
|
|
632
554
|
String
|
|
633
555
|
]),
|
|
634
|
-
|
|
556
|
+
_ts_metadata8("design:type", Array)
|
|
635
557
|
], ActionExecutionMessageOutput.prototype, "arguments", void 0);
|
|
636
|
-
ActionExecutionMessageOutput =
|
|
637
|
-
|
|
558
|
+
ActionExecutionMessageOutput = _ts_decorate8([
|
|
559
|
+
ObjectType2({
|
|
638
560
|
implements: BaseMessageOutput
|
|
639
561
|
})
|
|
640
562
|
], ActionExecutionMessageOutput);
|
|
@@ -644,20 +566,20 @@ var ResultMessageOutput = class {
|
|
|
644
566
|
result;
|
|
645
567
|
};
|
|
646
568
|
__name(ResultMessageOutput, "ResultMessageOutput");
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
569
|
+
_ts_decorate8([
|
|
570
|
+
Field8(() => String),
|
|
571
|
+
_ts_metadata8("design:type", String)
|
|
650
572
|
], ResultMessageOutput.prototype, "actionExecutionId", void 0);
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
573
|
+
_ts_decorate8([
|
|
574
|
+
Field8(() => String),
|
|
575
|
+
_ts_metadata8("design:type", String)
|
|
654
576
|
], ResultMessageOutput.prototype, "actionName", void 0);
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
577
|
+
_ts_decorate8([
|
|
578
|
+
Field8(() => String),
|
|
579
|
+
_ts_metadata8("design:type", String)
|
|
658
580
|
], ResultMessageOutput.prototype, "result", void 0);
|
|
659
|
-
ResultMessageOutput =
|
|
660
|
-
|
|
581
|
+
ResultMessageOutput = _ts_decorate8([
|
|
582
|
+
ObjectType2({
|
|
661
583
|
implements: BaseMessageOutput
|
|
662
584
|
})
|
|
663
585
|
], ResultMessageOutput);
|
|
@@ -668,28 +590,28 @@ var CopilotResponse = class {
|
|
|
668
590
|
messages;
|
|
669
591
|
};
|
|
670
592
|
__name(CopilotResponse, "CopilotResponse");
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
593
|
+
_ts_decorate8([
|
|
594
|
+
Field8(() => String),
|
|
595
|
+
_ts_metadata8("design:type", String)
|
|
674
596
|
], CopilotResponse.prototype, "threadId", void 0);
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
597
|
+
_ts_decorate8([
|
|
598
|
+
Field8(() => ResponseStatusUnion),
|
|
599
|
+
_ts_metadata8("design:type", Object)
|
|
678
600
|
], CopilotResponse.prototype, "status", void 0);
|
|
679
|
-
|
|
680
|
-
|
|
601
|
+
_ts_decorate8([
|
|
602
|
+
Field8({
|
|
681
603
|
nullable: true
|
|
682
604
|
}),
|
|
683
|
-
|
|
605
|
+
_ts_metadata8("design:type", String)
|
|
684
606
|
], CopilotResponse.prototype, "runId", void 0);
|
|
685
|
-
|
|
686
|
-
|
|
607
|
+
_ts_decorate8([
|
|
608
|
+
Field8(() => [
|
|
687
609
|
BaseMessageOutput
|
|
688
610
|
]),
|
|
689
|
-
|
|
611
|
+
_ts_metadata8("design:type", Array)
|
|
690
612
|
], CopilotResponse.prototype, "messages", void 0);
|
|
691
|
-
CopilotResponse =
|
|
692
|
-
|
|
613
|
+
CopilotResponse = _ts_decorate8([
|
|
614
|
+
ObjectType2()
|
|
693
615
|
], CopilotResponse);
|
|
694
616
|
|
|
695
617
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
@@ -697,7 +619,7 @@ import { Repeater } from "graphql-yoga";
|
|
|
697
619
|
import { nanoid } from "nanoid";
|
|
698
620
|
|
|
699
621
|
// src/service-adapters/events.ts
|
|
700
|
-
import { of, concat, map, scan, concatMap, ReplaySubject } from "rxjs";
|
|
622
|
+
import { of, concat, map, scan, concatMap, ReplaySubject, firstValueFrom } from "rxjs";
|
|
701
623
|
var RuntimeEventTypes;
|
|
702
624
|
(function(RuntimeEventTypes2) {
|
|
703
625
|
RuntimeEventTypes2["TextMessageStart"] = "TextMessageStart";
|
|
@@ -773,7 +695,7 @@ var RuntimeEventSource = class {
|
|
|
773
695
|
async stream(callback) {
|
|
774
696
|
this.callback = callback;
|
|
775
697
|
}
|
|
776
|
-
process(serversideActions) {
|
|
698
|
+
process({ serversideActions, guardrailsResult$ }) {
|
|
777
699
|
this.callback(this.eventStream$).catch((error) => {
|
|
778
700
|
console.error("Error in event source callback", error);
|
|
779
701
|
});
|
|
@@ -809,7 +731,7 @@ var RuntimeEventSource = class {
|
|
|
809
731
|
concatMap((eventWithState) => {
|
|
810
732
|
if (eventWithState.event.type === "ActionExecutionEnd" && eventWithState.callActionServerSide) {
|
|
811
733
|
const toolCallEventStream$ = new RuntimeEventSubject();
|
|
812
|
-
executeAction(toolCallEventStream$, eventWithState.action, eventWithState.args, eventWithState.actionExecutionId).catch((error) => {
|
|
734
|
+
executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.actionExecutionId).catch((error) => {
|
|
813
735
|
console.error(error);
|
|
814
736
|
});
|
|
815
737
|
return concat(of(eventWithState.event), toolCallEventStream$);
|
|
@@ -821,7 +743,14 @@ var RuntimeEventSource = class {
|
|
|
821
743
|
}
|
|
822
744
|
};
|
|
823
745
|
__name(RuntimeEventSource, "RuntimeEventSource");
|
|
824
|
-
async function executeAction(eventStream$, action, actionArguments, actionExecutionId) {
|
|
746
|
+
async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionId) {
|
|
747
|
+
if (guardrailsResult$) {
|
|
748
|
+
const { status } = await firstValueFrom(guardrailsResult$);
|
|
749
|
+
if (status === "denied") {
|
|
750
|
+
eventStream$.complete();
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
825
754
|
let args = [];
|
|
826
755
|
if (actionArguments) {
|
|
827
756
|
args = JSON.parse(actionArguments);
|
|
@@ -840,7 +769,9 @@ __name(executeAction, "executeAction");
|
|
|
840
769
|
|
|
841
770
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
842
771
|
import { GraphQLJSONObject } from "graphql-scalars";
|
|
843
|
-
|
|
772
|
+
import { plainToInstance } from "class-transformer";
|
|
773
|
+
import { GraphQLError } from "graphql";
|
|
774
|
+
function _ts_decorate9(decorators, target, key, desc) {
|
|
844
775
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
845
776
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
846
777
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -850,51 +781,185 @@ function _ts_decorate10(decorators, target, key, desc) {
|
|
|
850
781
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
851
782
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
852
783
|
}
|
|
853
|
-
__name(
|
|
854
|
-
function
|
|
784
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
785
|
+
function _ts_metadata9(k, v) {
|
|
855
786
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
856
787
|
return Reflect.metadata(k, v);
|
|
857
788
|
}
|
|
858
|
-
__name(
|
|
789
|
+
__name(_ts_metadata9, "_ts_metadata");
|
|
859
790
|
function _ts_param(paramIndex, decorator) {
|
|
860
791
|
return function(target, key) {
|
|
861
792
|
decorator(target, key, paramIndex);
|
|
862
793
|
};
|
|
863
794
|
}
|
|
864
795
|
__name(_ts_param, "_ts_param");
|
|
796
|
+
var invokeGuardrails = /* @__PURE__ */ __name(async ({ baseUrl, copilotCloudPublicApiKey, data, onResult, onError }) => {
|
|
797
|
+
var _a;
|
|
798
|
+
if (data.messages.length && ((_a = data.messages[data.messages.length - 1].textMessage) == null ? void 0 : _a.role) === MessageRole.user) {
|
|
799
|
+
const messages = data.messages.filter((m) => m.textMessage !== void 0 && (m.textMessage.role === MessageRole.user || m.textMessage.role === MessageRole.assistant)).map((m) => ({
|
|
800
|
+
role: m.textMessage.role,
|
|
801
|
+
content: m.textMessage.content
|
|
802
|
+
}));
|
|
803
|
+
const lastMessage = messages[messages.length - 1];
|
|
804
|
+
const restOfMessages = messages.slice(0, -1);
|
|
805
|
+
const body = {
|
|
806
|
+
input: lastMessage.content,
|
|
807
|
+
validTopics: data.cloud.guardrails.inputValidationRules.allowList,
|
|
808
|
+
invalidTopics: data.cloud.guardrails.inputValidationRules.denyList,
|
|
809
|
+
messages: restOfMessages
|
|
810
|
+
};
|
|
811
|
+
const guardrailsResult = await fetch(`${baseUrl}/guardrails/validate`, {
|
|
812
|
+
method: "POST",
|
|
813
|
+
headers: {
|
|
814
|
+
"Content-Type": "application/json",
|
|
815
|
+
"X-CopilotCloud-Public-API-Key": copilotCloudPublicApiKey
|
|
816
|
+
},
|
|
817
|
+
body: JSON.stringify(body)
|
|
818
|
+
});
|
|
819
|
+
if (guardrailsResult.ok) {
|
|
820
|
+
const resultJson = await guardrailsResult.json();
|
|
821
|
+
onResult(resultJson);
|
|
822
|
+
} else {
|
|
823
|
+
onError(await guardrailsResult.json());
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}, "invokeGuardrails");
|
|
865
827
|
var CopilotResolver = class {
|
|
866
828
|
async hello() {
|
|
867
829
|
return "Hello World";
|
|
868
830
|
}
|
|
869
831
|
async generateCopilotResponse(ctx, data, properties) {
|
|
832
|
+
let logger2 = ctx.logger.child({
|
|
833
|
+
component: "CopilotResolver.generateCopilotResponse"
|
|
834
|
+
});
|
|
835
|
+
logger2.debug({
|
|
836
|
+
data
|
|
837
|
+
}, "Generating Copilot response");
|
|
838
|
+
const copilotRuntime = ctx._copilotkit.runtime;
|
|
839
|
+
const serviceAdapter = ctx._copilotkit.serviceAdapter;
|
|
870
840
|
if (properties) {
|
|
871
|
-
|
|
872
|
-
|
|
841
|
+
logger2.debug("Properties provided, merging with context properties");
|
|
842
|
+
ctx.properties = {
|
|
843
|
+
...ctx.properties,
|
|
873
844
|
...properties
|
|
874
845
|
};
|
|
875
846
|
}
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
847
|
+
let copilotCloudPublicApiKey = null;
|
|
848
|
+
let copilotCloudBaseUrl;
|
|
849
|
+
if (data.cloud) {
|
|
850
|
+
logger2 = logger2.child({
|
|
851
|
+
cloud: true
|
|
852
|
+
});
|
|
853
|
+
logger2.debug("Cloud configuration provided, checking for public API key in headers");
|
|
854
|
+
const key = ctx.request.headers.get("x-copilotcloud-public-api-key");
|
|
855
|
+
if (key) {
|
|
856
|
+
logger2.debug("Public API key found in headers");
|
|
857
|
+
copilotCloudPublicApiKey = key;
|
|
858
|
+
} else {
|
|
859
|
+
logger2.error("Public API key not found in headers");
|
|
860
|
+
throw new GraphQLError("X-CopilotCloud-Public-API-Key header is required");
|
|
861
|
+
}
|
|
862
|
+
if (process.env.COPILOT_CLOUD_BASE_URL) {
|
|
863
|
+
copilotCloudBaseUrl = process.env.COPILOT_CLOUD_BASE_URL;
|
|
864
|
+
} else if (ctx._copilotkit.baseUrl) {
|
|
865
|
+
copilotCloudBaseUrl = ctx._copilotkit.baseUrl;
|
|
866
|
+
} else {
|
|
867
|
+
copilotCloudBaseUrl = "https://api.cloud.copilotkit.ai";
|
|
868
|
+
}
|
|
869
|
+
logger2 = logger2.child({
|
|
870
|
+
copilotCloudBaseUrl
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
logger2.debug("Setting up subjects");
|
|
874
|
+
const responseStatus$ = new ReplaySubject2();
|
|
875
|
+
const interruptStreaming$ = new ReplaySubject2();
|
|
876
|
+
const guardrailsResult$ = new ReplaySubject2();
|
|
877
|
+
let outputMessages = [];
|
|
878
|
+
let resolveOutputMessagesPromise;
|
|
879
|
+
let rejectOutputMessagesPromise;
|
|
880
|
+
const outputMessagesPromise = new Promise((resolve, reject) => {
|
|
881
|
+
resolveOutputMessagesPromise = resolve;
|
|
882
|
+
rejectOutputMessagesPromise = reject;
|
|
883
|
+
});
|
|
884
|
+
logger2.debug("Processing");
|
|
885
|
+
const { eventSource, threadId = nanoid(), runId, actions } = await copilotRuntime.process({
|
|
880
886
|
serviceAdapter,
|
|
881
887
|
messages: data.messages,
|
|
882
888
|
actions: data.frontend.actions,
|
|
883
889
|
threadId: data.threadId,
|
|
884
890
|
runId: data.runId,
|
|
885
|
-
publicApiKey: void 0
|
|
891
|
+
publicApiKey: void 0,
|
|
892
|
+
properties: ctx.properties || {},
|
|
893
|
+
outputMessagesPromise
|
|
886
894
|
});
|
|
895
|
+
logger2.debug("Event source created, creating response");
|
|
887
896
|
const response = {
|
|
888
897
|
threadId,
|
|
889
898
|
runId,
|
|
890
|
-
status:
|
|
899
|
+
status: firstValueFrom2(responseStatus$),
|
|
891
900
|
messages: new Repeater(async (pushMessage, stopStreamingMessages) => {
|
|
892
|
-
|
|
901
|
+
var _a, _b;
|
|
902
|
+
logger2.debug("Messages repeater created");
|
|
903
|
+
if ((_a = data.cloud) == null ? void 0 : _a.guardrails) {
|
|
904
|
+
logger2 = logger2.child({
|
|
905
|
+
guardrails: true
|
|
906
|
+
});
|
|
907
|
+
logger2.debug("Guardrails is enabled, validating input");
|
|
908
|
+
invokeGuardrails({
|
|
909
|
+
baseUrl: copilotCloudBaseUrl,
|
|
910
|
+
copilotCloudPublicApiKey,
|
|
911
|
+
data,
|
|
912
|
+
onResult: (result) => {
|
|
913
|
+
logger2.debug({
|
|
914
|
+
status: result.status
|
|
915
|
+
}, "Guardrails validation done");
|
|
916
|
+
guardrailsResult$.next(result);
|
|
917
|
+
if (result.status === "denied") {
|
|
918
|
+
responseStatus$.next(new GuardrailsValidationFailureResponse({
|
|
919
|
+
guardrailsReason: result.reason
|
|
920
|
+
}));
|
|
921
|
+
interruptStreaming$.next({
|
|
922
|
+
reason: `Interrupted due to Guardrails validation failure. Reason: ${result.reason}`
|
|
923
|
+
});
|
|
924
|
+
outputMessages = [
|
|
925
|
+
plainToInstance(TextMessage, {
|
|
926
|
+
id: nanoid(),
|
|
927
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
928
|
+
content: result.reason,
|
|
929
|
+
role: MessageRole.assistant
|
|
930
|
+
})
|
|
931
|
+
];
|
|
932
|
+
resolveOutputMessagesPromise(outputMessages);
|
|
933
|
+
}
|
|
934
|
+
},
|
|
935
|
+
onError: (err) => {
|
|
936
|
+
logger2.error({
|
|
937
|
+
err
|
|
938
|
+
}, "Error in guardrails validation");
|
|
939
|
+
responseStatus$.next(new UnknownErrorResponse({
|
|
940
|
+
description: `An unknown error has occurred in the guardrails validation`
|
|
941
|
+
}));
|
|
942
|
+
interruptStreaming$.next({
|
|
943
|
+
reason: `Interrupted due to unknown error in guardrails validation`
|
|
944
|
+
});
|
|
945
|
+
rejectOutputMessagesPromise(err);
|
|
946
|
+
}
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
let eventStreamSubscription;
|
|
950
|
+
const eventStream = eventSource.process({
|
|
951
|
+
serversideActions: actions,
|
|
952
|
+
guardrailsResult$: ((_b = data.cloud) == null ? void 0 : _b.guardrails) ? guardrailsResult$ : null
|
|
953
|
+
}).pipe(
|
|
893
954
|
// shareReplay() ensures that later subscribers will see the whole stream instead of
|
|
894
955
|
// just the events that were emitted after the subscriber was added.
|
|
895
|
-
shareReplay()
|
|
956
|
+
shareReplay(),
|
|
957
|
+
finalize(() => {
|
|
958
|
+
logger2.debug("Event stream finalized");
|
|
959
|
+
})
|
|
896
960
|
);
|
|
897
|
-
|
|
961
|
+
logger2.debug("Event stream created, subscribing to event stream");
|
|
962
|
+
eventStreamSubscription = eventStream.subscribe({
|
|
898
963
|
next: async (event) => {
|
|
899
964
|
switch (event.type) {
|
|
900
965
|
case RuntimeEventTypes.TextMessageStart:
|
|
@@ -905,43 +970,117 @@ var CopilotResolver = class {
|
|
|
905
970
|
takeWhile((e) => e.type != RuntimeEventTypes.TextMessageEnd)
|
|
906
971
|
);
|
|
907
972
|
const streamingTextStatus = new Subject();
|
|
973
|
+
const messageId = nanoid();
|
|
908
974
|
pushMessage({
|
|
909
|
-
id:
|
|
910
|
-
status:
|
|
975
|
+
id: messageId,
|
|
976
|
+
status: firstValueFrom2(streamingTextStatus),
|
|
911
977
|
createdAt: /* @__PURE__ */ new Date(),
|
|
912
978
|
role: MessageRole.assistant,
|
|
913
979
|
content: new Repeater(async (pushTextChunk, stopStreamingText) => {
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
980
|
+
logger2.debug("Text message content repeater created");
|
|
981
|
+
const textChunks = [];
|
|
982
|
+
let textSubscription;
|
|
983
|
+
interruptStreaming$.pipe(shareReplay(), take(1), tap(({ reason, messageId: messageId2 }) => {
|
|
984
|
+
logger2.debug({
|
|
985
|
+
reason,
|
|
986
|
+
messageId: messageId2
|
|
987
|
+
}, "Text streaming interrupted");
|
|
988
|
+
streamingTextStatus.next(plainToInstance(FailedMessageStatus, {
|
|
989
|
+
reason
|
|
990
|
+
}));
|
|
991
|
+
responseStatus$.next(new MessageStreamInterruptedResponse({
|
|
992
|
+
messageId: messageId2
|
|
993
|
+
}));
|
|
994
|
+
stopStreamingText();
|
|
995
|
+
textSubscription == null ? void 0 : textSubscription.unsubscribe();
|
|
996
|
+
})).subscribe();
|
|
997
|
+
logger2.debug("Subscribing to text message content stream");
|
|
998
|
+
textSubscription = textMessageContentStream.subscribe({
|
|
999
|
+
next: async (e) => {
|
|
1000
|
+
if (e.type == RuntimeEventTypes.TextMessageContent) {
|
|
1001
|
+
await pushTextChunk(e.content);
|
|
1002
|
+
textChunks.push(e.content);
|
|
1003
|
+
}
|
|
1004
|
+
},
|
|
1005
|
+
error: (err) => {
|
|
1006
|
+
logger2.error({
|
|
1007
|
+
err
|
|
1008
|
+
}, "Error in text message content stream");
|
|
1009
|
+
interruptStreaming$.next({
|
|
1010
|
+
reason: "Error streaming message content",
|
|
1011
|
+
messageId
|
|
1012
|
+
});
|
|
1013
|
+
stopStreamingText();
|
|
1014
|
+
textSubscription == null ? void 0 : textSubscription.unsubscribe();
|
|
1015
|
+
},
|
|
1016
|
+
complete: () => {
|
|
1017
|
+
logger2.debug("Text message content stream completed");
|
|
1018
|
+
streamingTextStatus.next(new SuccessMessageStatus());
|
|
1019
|
+
stopStreamingText();
|
|
1020
|
+
textSubscription == null ? void 0 : textSubscription.unsubscribe();
|
|
1021
|
+
outputMessages.push(plainToInstance(TextMessage, {
|
|
1022
|
+
id: messageId,
|
|
1023
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
1024
|
+
content: textChunks.join(""),
|
|
1025
|
+
role: MessageRole.assistant
|
|
1026
|
+
}));
|
|
917
1027
|
}
|
|
918
1028
|
});
|
|
919
|
-
stopStreamingText();
|
|
920
|
-
streamingTextStatus.next(new SuccessMessageStatus());
|
|
921
1029
|
})
|
|
922
1030
|
});
|
|
923
1031
|
break;
|
|
924
1032
|
case RuntimeEventTypes.ActionExecutionStart:
|
|
1033
|
+
logger2.debug("Action execution start event received");
|
|
925
1034
|
const actionExecutionArgumentStream = eventStream.pipe(skipWhile((e) => e !== event), takeWhile((e) => e.type != RuntimeEventTypes.ActionExecutionEnd));
|
|
926
1035
|
const streamingArgumentsStatus = new Subject();
|
|
927
1036
|
pushMessage({
|
|
928
1037
|
id: event.actionExecutionId,
|
|
929
|
-
status:
|
|
1038
|
+
status: firstValueFrom2(streamingArgumentsStatus),
|
|
930
1039
|
createdAt: /* @__PURE__ */ new Date(),
|
|
931
1040
|
name: event.actionName,
|
|
932
1041
|
scope: event.scope,
|
|
933
1042
|
arguments: new Repeater(async (pushArgumentsChunk, stopStreamingArguments) => {
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
1043
|
+
logger2.debug("Action execution argument stream created");
|
|
1044
|
+
const argumentChunks = [];
|
|
1045
|
+
let actionExecutionArgumentSubscription;
|
|
1046
|
+
actionExecutionArgumentSubscription = actionExecutionArgumentStream.subscribe({
|
|
1047
|
+
next: async (e) => {
|
|
1048
|
+
if (e.type == RuntimeEventTypes.ActionExecutionArgs) {
|
|
1049
|
+
await pushArgumentsChunk(e.args);
|
|
1050
|
+
argumentChunks.push(e.args);
|
|
1051
|
+
}
|
|
1052
|
+
},
|
|
1053
|
+
error: (err) => {
|
|
1054
|
+
logger2.error({
|
|
1055
|
+
err
|
|
1056
|
+
}, "Error in action execution argument stream");
|
|
1057
|
+
streamingArgumentsStatus.next(plainToInstance(FailedMessageStatus, {
|
|
1058
|
+
reason: "An unknown error has occurred in the action execution argument stream"
|
|
1059
|
+
}));
|
|
1060
|
+
stopStreamingArguments();
|
|
1061
|
+
actionExecutionArgumentSubscription == null ? void 0 : actionExecutionArgumentSubscription.unsubscribe();
|
|
1062
|
+
},
|
|
1063
|
+
complete: () => {
|
|
1064
|
+
logger2.debug("Action execution argument stream completed");
|
|
1065
|
+
streamingArgumentsStatus.next(new SuccessMessageStatus());
|
|
1066
|
+
stopStreamingArguments();
|
|
1067
|
+
actionExecutionArgumentSubscription == null ? void 0 : actionExecutionArgumentSubscription.unsubscribe();
|
|
1068
|
+
outputMessages.push(plainToInstance(ActionExecutionMessage, {
|
|
1069
|
+
id: event.actionExecutionId,
|
|
1070
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
1071
|
+
name: event.actionName,
|
|
1072
|
+
scope: event.scope,
|
|
1073
|
+
arguments: argumentChunks.join("")
|
|
1074
|
+
}));
|
|
937
1075
|
}
|
|
938
1076
|
});
|
|
939
|
-
stopStreamingArguments();
|
|
940
|
-
streamingArgumentsStatus.next(new SuccessMessageStatus());
|
|
941
1077
|
})
|
|
942
1078
|
});
|
|
943
1079
|
break;
|
|
944
1080
|
case RuntimeEventTypes.ActionExecutionResult:
|
|
1081
|
+
logger2.debug({
|
|
1082
|
+
result: event.result
|
|
1083
|
+
}, "Action execution result event received");
|
|
945
1084
|
pushMessage({
|
|
946
1085
|
id: nanoid(),
|
|
947
1086
|
status: new SuccessMessageStatus(),
|
|
@@ -950,13 +1089,38 @@ var CopilotResolver = class {
|
|
|
950
1089
|
actionName: event.actionName,
|
|
951
1090
|
result: event.result
|
|
952
1091
|
});
|
|
1092
|
+
outputMessages.push(plainToInstance(ResultMessage, {
|
|
1093
|
+
id: nanoid(),
|
|
1094
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
1095
|
+
actionExecutionId: event.actionExecutionId,
|
|
1096
|
+
actionName: event.actionName,
|
|
1097
|
+
result: event.result
|
|
1098
|
+
}));
|
|
953
1099
|
break;
|
|
954
1100
|
}
|
|
955
1101
|
},
|
|
956
|
-
error: (err) =>
|
|
957
|
-
|
|
958
|
-
|
|
1102
|
+
error: (err) => {
|
|
1103
|
+
logger2.error({
|
|
1104
|
+
err
|
|
1105
|
+
}, "Error in event stream");
|
|
1106
|
+
responseStatus$.next(new UnknownErrorResponse({
|
|
1107
|
+
description: `An unknown error has occurred in the event stream`
|
|
1108
|
+
}));
|
|
1109
|
+
eventStreamSubscription == null ? void 0 : eventStreamSubscription.unsubscribe();
|
|
1110
|
+
stopStreamingMessages();
|
|
1111
|
+
rejectOutputMessagesPromise(err);
|
|
1112
|
+
},
|
|
1113
|
+
complete: async () => {
|
|
1114
|
+
var _a2;
|
|
1115
|
+
logger2.debug("Event stream completed");
|
|
1116
|
+
if ((_a2 = data.cloud) == null ? void 0 : _a2.guardrails) {
|
|
1117
|
+
logger2.debug("Guardrails is enabled, waiting for guardrails result");
|
|
1118
|
+
await firstValueFrom2(guardrailsResult$);
|
|
1119
|
+
}
|
|
1120
|
+
responseStatus$.next(new SuccessResponseStatus());
|
|
1121
|
+
eventStreamSubscription == null ? void 0 : eventStreamSubscription.unsubscribe();
|
|
959
1122
|
stopStreamingMessages();
|
|
1123
|
+
resolveOutputMessagesPromise(outputMessages);
|
|
960
1124
|
}
|
|
961
1125
|
});
|
|
962
1126
|
})
|
|
@@ -965,77 +1129,125 @@ var CopilotResolver = class {
|
|
|
965
1129
|
}
|
|
966
1130
|
};
|
|
967
1131
|
__name(CopilotResolver, "CopilotResolver");
|
|
968
|
-
|
|
1132
|
+
_ts_decorate9([
|
|
969
1133
|
Query(() => String),
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
1134
|
+
_ts_metadata9("design:type", Function),
|
|
1135
|
+
_ts_metadata9("design:paramtypes", []),
|
|
1136
|
+
_ts_metadata9("design:returntype", Promise)
|
|
973
1137
|
], CopilotResolver.prototype, "hello", null);
|
|
974
|
-
|
|
1138
|
+
_ts_decorate9([
|
|
975
1139
|
Mutation(() => CopilotResponse),
|
|
976
1140
|
_ts_param(0, Ctx()),
|
|
977
1141
|
_ts_param(1, Arg("data")),
|
|
978
1142
|
_ts_param(2, Arg("properties", () => GraphQLJSONObject, {
|
|
979
1143
|
nullable: true
|
|
980
1144
|
})),
|
|
981
|
-
|
|
982
|
-
|
|
1145
|
+
_ts_metadata9("design:type", Function),
|
|
1146
|
+
_ts_metadata9("design:paramtypes", [
|
|
983
1147
|
typeof GraphQLContext === "undefined" ? Object : GraphQLContext,
|
|
984
1148
|
typeof GenerateCopilotResponseInput === "undefined" ? Object : GenerateCopilotResponseInput,
|
|
985
1149
|
typeof CopilotRequestContextProperties === "undefined" ? Object : CopilotRequestContextProperties
|
|
986
1150
|
]),
|
|
987
|
-
|
|
1151
|
+
_ts_metadata9("design:returntype", Promise)
|
|
988
1152
|
], CopilotResolver.prototype, "generateCopilotResponse", null);
|
|
989
|
-
CopilotResolver =
|
|
1153
|
+
CopilotResolver = _ts_decorate9([
|
|
990
1154
|
Resolver(() => CopilotResponse)
|
|
991
1155
|
], CopilotResolver);
|
|
992
1156
|
|
|
993
1157
|
// src/lib/integrations/shared.ts
|
|
994
1158
|
import { useDeferStream } from "@graphql-yoga/plugin-defer-stream";
|
|
995
|
-
|
|
1159
|
+
|
|
1160
|
+
// src/lib/logger.ts
|
|
1161
|
+
import createPinoLogger from "pino";
|
|
1162
|
+
import pretty from "pino-pretty";
|
|
1163
|
+
function createLogger(options) {
|
|
1164
|
+
const { level, component } = options || {};
|
|
1165
|
+
const stream = pretty({
|
|
1166
|
+
colorize: true
|
|
1167
|
+
});
|
|
1168
|
+
const logger2 = createPinoLogger({
|
|
1169
|
+
level: process.env.LOG_LEVEL || level || "error",
|
|
1170
|
+
redact: {
|
|
1171
|
+
paths: [
|
|
1172
|
+
"pid",
|
|
1173
|
+
"hostname"
|
|
1174
|
+
],
|
|
1175
|
+
remove: true
|
|
1176
|
+
}
|
|
1177
|
+
}, stream);
|
|
1178
|
+
if (component) {
|
|
1179
|
+
return logger2.child({
|
|
1180
|
+
component
|
|
1181
|
+
});
|
|
1182
|
+
} else {
|
|
1183
|
+
return logger2;
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
__name(createLogger, "createLogger");
|
|
1187
|
+
|
|
1188
|
+
// src/lib/integrations/shared.ts
|
|
1189
|
+
var logger = createLogger();
|
|
1190
|
+
async function createContext(initialContext, copilotKitContext, contextLogger, properties = {}) {
|
|
1191
|
+
logger.debug({
|
|
1192
|
+
copilotKitContext
|
|
1193
|
+
}, "Creating GraphQL context");
|
|
996
1194
|
const ctx = {
|
|
997
1195
|
...initialContext,
|
|
998
1196
|
_copilotkit: {
|
|
999
1197
|
...copilotKitContext
|
|
1000
|
-
}
|
|
1198
|
+
},
|
|
1199
|
+
properties: {
|
|
1200
|
+
...properties
|
|
1201
|
+
},
|
|
1202
|
+
logger: contextLogger
|
|
1001
1203
|
};
|
|
1002
1204
|
return ctx;
|
|
1003
1205
|
}
|
|
1004
1206
|
__name(createContext, "createContext");
|
|
1005
1207
|
function buildSchema(options = {}) {
|
|
1208
|
+
logger.debug("Building GraphQL schema...");
|
|
1006
1209
|
const schema = buildSchemaSync({
|
|
1007
1210
|
resolvers: [
|
|
1008
1211
|
CopilotResolver
|
|
1009
1212
|
],
|
|
1010
1213
|
emitSchemaFile: options.emitSchemaFile
|
|
1011
1214
|
});
|
|
1215
|
+
logger.debug("GraphQL schema built successfully");
|
|
1012
1216
|
return schema;
|
|
1013
1217
|
}
|
|
1014
1218
|
__name(buildSchema, "buildSchema");
|
|
1015
1219
|
function getCommonConfig(options) {
|
|
1220
|
+
const logLevel = process.env.LOG_LEVEL || options.logLevel || "error";
|
|
1221
|
+
const logger2 = createLogger({
|
|
1222
|
+
level: logLevel,
|
|
1223
|
+
component: "getCommonConfig"
|
|
1224
|
+
});
|
|
1225
|
+
logger2.debug("Getting common config");
|
|
1226
|
+
const contextLogger = createLogger({
|
|
1227
|
+
level: logLevel
|
|
1228
|
+
});
|
|
1016
1229
|
return {
|
|
1230
|
+
logging: createLogger({
|
|
1231
|
+
component: "Yoga GraphQL",
|
|
1232
|
+
level: logLevel
|
|
1233
|
+
}),
|
|
1017
1234
|
schema: buildSchema(),
|
|
1018
1235
|
plugins: [
|
|
1019
1236
|
useDeferStream()
|
|
1020
1237
|
],
|
|
1021
|
-
context: (ctx) => createContext(ctx,
|
|
1022
|
-
runtime: options.runtime,
|
|
1023
|
-
serviceAdapter: options.serviceAdapter,
|
|
1024
|
-
properties: {}
|
|
1025
|
-
})
|
|
1238
|
+
context: (ctx) => createContext(ctx, options, contextLogger, options.properties)
|
|
1026
1239
|
};
|
|
1027
1240
|
}
|
|
1028
1241
|
__name(getCommonConfig, "getCommonConfig");
|
|
1029
1242
|
|
|
1030
1243
|
// src/lib/integrations/node-http/index.ts
|
|
1031
|
-
function copilotRuntimeNodeHttpEndpoint(
|
|
1032
|
-
const commonConfig = getCommonConfig(
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
});
|
|
1244
|
+
function copilotRuntimeNodeHttpEndpoint(options) {
|
|
1245
|
+
const commonConfig = getCommonConfig(options);
|
|
1246
|
+
const logger2 = commonConfig.logging;
|
|
1247
|
+
logger2.debug("Creating Node HTTP endpoint");
|
|
1036
1248
|
const yoga = createYoga({
|
|
1037
1249
|
...commonConfig,
|
|
1038
|
-
graphqlEndpoint: endpoint
|
|
1250
|
+
graphqlEndpoint: options.endpoint
|
|
1039
1251
|
});
|
|
1040
1252
|
return yoga;
|
|
1041
1253
|
}
|
|
@@ -1048,4 +1260,4 @@ export {
|
|
|
1048
1260
|
getCommonConfig,
|
|
1049
1261
|
copilotRuntimeNodeHttpEndpoint
|
|
1050
1262
|
};
|
|
1051
|
-
//# sourceMappingURL=chunk-
|
|
1263
|
+
//# sourceMappingURL=chunk-6YGDE3YI.mjs.map
|