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