@copilotkit/runtime 1.10.7-next.0 → 1.50.0-beta.1
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/CHANGELOG.md +0 -6
- package/dist/index.d.ts +1655 -27
- package/dist/index.js +2172 -5049
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5441 -99
- package/dist/index.mjs.map +1 -1
- package/dist/v2/index.d.ts +1 -0
- package/dist/v2/index.js +15 -0
- package/dist/v2/index.js.map +1 -0
- package/dist/v2/index.mjs +4 -0
- package/dist/v2/index.mjs.map +1 -0
- package/package.json +17 -5
- package/src/graphql/message-conversion/agui-to-gql.test.ts +1263 -0
- package/src/graphql/message-conversion/agui-to-gql.ts +333 -0
- package/src/graphql/message-conversion/gql-to-agui.test.ts +1578 -0
- package/src/graphql/message-conversion/gql-to-agui.ts +278 -0
- package/src/graphql/message-conversion/index.ts +2 -0
- package/src/graphql/message-conversion/roundtrip-conversion.test.ts +526 -0
- package/src/graphql/resolvers/copilot.resolver.ts +3 -48
- package/src/graphql/resolvers/state.resolver.ts +3 -2
- package/src/graphql/types/converted/index.ts +32 -6
- package/src/graphql/types/enums.ts +2 -2
- package/src/graphql/types/message-status.type.ts +3 -1
- package/src/lib/index.ts +1 -1
- package/src/lib/integrations/nextjs/app-router.ts +10 -11
- package/src/lib/integrations/nextjs/pages-router.ts +4 -11
- package/src/lib/integrations/node-http/index.ts +64 -5
- package/src/lib/integrations/shared.ts +1 -1
- package/src/lib/observability.ts +87 -0
- package/src/lib/runtime/{langgraph/langgraph-agent.ts → agent-integrations/langgraph.agent.ts} +5 -0
- package/src/lib/runtime/copilot-runtime.ts +346 -1333
- package/src/lib/runtime/types.ts +49 -0
- package/src/lib/runtime/utils.ts +87 -0
- package/src/lib/telemetry-client.ts +6 -5
- package/src/service-adapters/anthropic/anthropic-adapter.ts +5 -1
- package/src/service-adapters/bedrock/bedrock-adapter.ts +6 -1
- package/src/service-adapters/empty/empty-adapter.ts +3 -0
- package/src/service-adapters/events.ts +0 -254
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +5 -1
- package/src/service-adapters/google/google-genai-adapter.ts +7 -1
- package/src/service-adapters/groq/groq-adapter.ts +5 -1
- package/src/service-adapters/langchain/langchain-adapter.ts +3 -0
- package/src/service-adapters/openai/openai-adapter.ts +5 -1
- package/src/service-adapters/openai/openai-assistant-adapter.ts +4 -0
- package/src/service-adapters/service-adapter.ts +3 -0
- package/src/service-adapters/unify/unify-adapter.ts +6 -1
- package/src/v2/index.ts +2 -0
- package/tsup.config.ts +2 -1
- package/dist/chunk-27JKTS6P.mjs +0 -1704
- package/dist/chunk-27JKTS6P.mjs.map +0 -1
- package/dist/chunk-2OZAGFV3.mjs +0 -43
- package/dist/chunk-2OZAGFV3.mjs.map +0 -1
- package/dist/chunk-5BW5IBTZ.mjs +0 -80
- package/dist/chunk-5BW5IBTZ.mjs.map +0 -1
- package/dist/chunk-AMUJQ6IR.mjs +0 -50
- package/dist/chunk-AMUJQ6IR.mjs.map +0 -1
- package/dist/chunk-BMIYSM5W.mjs +0 -25
- package/dist/chunk-BMIYSM5W.mjs.map +0 -1
- package/dist/chunk-FDTCG47E.mjs +0 -25
- package/dist/chunk-FDTCG47E.mjs.map +0 -1
- package/dist/chunk-FHD4JECV.mjs +0 -33
- package/dist/chunk-FHD4JECV.mjs.map +0 -1
- package/dist/chunk-LRCKLBMO.mjs +0 -6020
- package/dist/chunk-LRCKLBMO.mjs.map +0 -1
- package/dist/chunk-R7RMYEPZ.mjs +0 -175
- package/dist/chunk-R7RMYEPZ.mjs.map +0 -1
- package/dist/chunk-SHBDMA63.mjs +0 -141
- package/dist/chunk-SHBDMA63.mjs.map +0 -1
- package/dist/chunk-XWBDEXDA.mjs +0 -153
- package/dist/chunk-XWBDEXDA.mjs.map +0 -1
- package/dist/graphql/types/base/index.d.ts +0 -6
- package/dist/graphql/types/base/index.js +0 -63
- package/dist/graphql/types/base/index.js.map +0 -1
- package/dist/graphql/types/base/index.mjs +0 -8
- package/dist/graphql/types/base/index.mjs.map +0 -1
- package/dist/graphql/types/converted/index.d.ts +0 -2
- package/dist/graphql/types/converted/index.js +0 -200
- package/dist/graphql/types/converted/index.js.map +0 -1
- package/dist/graphql/types/converted/index.mjs +0 -19
- package/dist/graphql/types/converted/index.mjs.map +0 -1
- package/dist/groq-adapter-c8aec5c5.d.ts +0 -321
- package/dist/index-96b330da.d.ts +0 -119
- package/dist/langserve-0c6100e3.d.ts +0 -257
- package/dist/lib/cloud/index.d.ts +0 -6
- package/dist/lib/cloud/index.js +0 -18
- package/dist/lib/cloud/index.js.map +0 -1
- package/dist/lib/cloud/index.mjs +0 -1
- package/dist/lib/cloud/index.mjs.map +0 -1
- package/dist/lib/index.d.ts +0 -212
- package/dist/lib/index.js +0 -7843
- package/dist/lib/index.js.map +0 -1
- package/dist/lib/index.mjs +0 -76
- package/dist/lib/index.mjs.map +0 -1
- package/dist/lib/integrations/index.d.ts +0 -34
- package/dist/lib/integrations/index.js +0 -3052
- package/dist/lib/integrations/index.js.map +0 -1
- package/dist/lib/integrations/index.mjs +0 -37
- package/dist/lib/integrations/index.mjs.map +0 -1
- package/dist/lib/integrations/nest/index.d.ts +0 -15
- package/dist/lib/integrations/nest/index.js +0 -2959
- package/dist/lib/integrations/nest/index.js.map +0 -1
- package/dist/lib/integrations/nest/index.mjs +0 -14
- package/dist/lib/integrations/nest/index.mjs.map +0 -1
- package/dist/lib/integrations/node-express/index.d.ts +0 -15
- package/dist/lib/integrations/node-express/index.js +0 -2959
- package/dist/lib/integrations/node-express/index.js.map +0 -1
- package/dist/lib/integrations/node-express/index.mjs +0 -14
- package/dist/lib/integrations/node-express/index.mjs.map +0 -1
- package/dist/lib/integrations/node-http/index.d.ts +0 -15
- package/dist/lib/integrations/node-http/index.js +0 -2945
- package/dist/lib/integrations/node-http/index.js.map +0 -1
- package/dist/lib/integrations/node-http/index.mjs +0 -13
- package/dist/lib/integrations/node-http/index.mjs.map +0 -1
- package/dist/service-adapters/index.d.ts +0 -162
- package/dist/service-adapters/index.js +0 -1787
- package/dist/service-adapters/index.js.map +0 -1
- package/dist/service-adapters/index.mjs +0 -34
- package/dist/service-adapters/index.mjs.map +0 -1
- package/dist/service-adapters/shared/index.d.ts +0 -9
- package/dist/service-adapters/shared/index.js +0 -72
- package/dist/service-adapters/shared/index.js.map +0 -1
- package/dist/service-adapters/shared/index.mjs +0 -8
- package/dist/service-adapters/shared/index.mjs.map +0 -1
- package/dist/shared-0a7346ce.d.ts +0 -466
- package/dist/utils/index.d.ts +0 -65
- package/dist/utils/index.js +0 -175
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/index.mjs +0 -12
- package/dist/utils/index.mjs.map +0 -1
- package/src/lib/runtime/__tests__/remote-action-constructors.test.ts +0 -246
- package/src/lib/runtime/agui-action.ts +0 -180
- package/src/lib/runtime/remote-action-constructors.ts +0 -331
- package/src/lib/runtime/remote-actions.ts +0 -217
- package/src/lib/runtime/remote-lg-action.ts +0 -1006
package/dist/utils/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/index.ts","../../src/graphql/types/response-status.type.ts","../../src/utils/failed-response-status-reasons.ts"],"sourcesContent":["export * from \"./failed-response-status-reasons\";\n","import { GraphQLJSON } from \"graphql-scalars\";\nimport { Field, InterfaceType, ObjectType, createUnionType, registerEnumType } from \"type-graphql\";\n\nexport enum ResponseStatusCode {\n Pending = \"pending\",\n Success = \"success\",\n Failed = \"failed\",\n}\n\nregisterEnumType(ResponseStatusCode, {\n name: \"ResponseStatusCode\",\n});\n\n@InterfaceType({\n resolveType(value) {\n if (value.code === ResponseStatusCode.Success) {\n return SuccessResponseStatus;\n } else if (value.code === ResponseStatusCode.Failed) {\n return FailedResponseStatus;\n } else if (value.code === ResponseStatusCode.Pending) {\n return PendingResponseStatus;\n }\n return undefined;\n },\n})\n@ObjectType()\nabstract class BaseResponseStatus {\n @Field(() => ResponseStatusCode)\n code: ResponseStatusCode;\n}\n\n@ObjectType({ implements: BaseResponseStatus })\nexport class PendingResponseStatus extends BaseResponseStatus {\n code: ResponseStatusCode = ResponseStatusCode.Pending;\n}\n\n@ObjectType({ implements: BaseResponseStatus })\nexport class SuccessResponseStatus extends BaseResponseStatus {\n code: ResponseStatusCode = ResponseStatusCode.Success;\n}\n\nexport enum FailedResponseStatusReason {\n GUARDRAILS_VALIDATION_FAILED = \"GUARDRAILS_VALIDATION_FAILED\",\n MESSAGE_STREAM_INTERRUPTED = \"MESSAGE_STREAM_INTERRUPTED\",\n UNKNOWN_ERROR = \"UNKNOWN_ERROR\",\n}\n\nregisterEnumType(FailedResponseStatusReason, {\n name: \"FailedResponseStatusReason\",\n});\n\n@ObjectType({ implements: BaseResponseStatus })\nexport class FailedResponseStatus extends BaseResponseStatus {\n code: ResponseStatusCode = ResponseStatusCode.Failed;\n\n @Field(() => FailedResponseStatusReason)\n reason: FailedResponseStatusReason;\n\n @Field(() => GraphQLJSON, { nullable: true })\n details?: Record<string, any> = null;\n}\n\nexport const ResponseStatusUnion = createUnionType({\n name: \"ResponseStatus\",\n types: () => [PendingResponseStatus, SuccessResponseStatus, FailedResponseStatus] as const,\n});\n","import {\n FailedResponseStatus,\n FailedResponseStatusReason,\n} from \"../graphql/types/response-status.type\";\n\nexport class GuardrailsValidationFailureResponse extends FailedResponseStatus {\n reason = FailedResponseStatusReason.GUARDRAILS_VALIDATION_FAILED;\n declare details: {\n guardrailsReason: string;\n };\n\n constructor({ guardrailsReason }) {\n super();\n this.details = {\n guardrailsReason,\n };\n }\n}\n\nexport class MessageStreamInterruptedResponse extends FailedResponseStatus {\n reason = FailedResponseStatusReason.MESSAGE_STREAM_INTERRUPTED;\n declare details: {\n messageId: string;\n description: string;\n };\n\n constructor({ messageId }: { messageId: string }) {\n super();\n this.details = {\n messageId,\n description: \"Check the message for mode details\",\n };\n }\n}\n\nexport class UnknownErrorResponse extends FailedResponseStatus {\n reason = FailedResponseStatusReason.UNKNOWN_ERROR;\n declare details: {\n description?: string;\n originalError?: {\n code?: string;\n statusCode?: number;\n severity?: string;\n visibility?: string;\n originalErrorType?: string;\n extensions?: any;\n };\n };\n\n constructor({\n description,\n originalError,\n }: {\n description?: string;\n originalError?: {\n code?: string;\n statusCode?: number;\n severity?: string;\n visibility?: string;\n originalErrorType?: string;\n extensions?: any;\n };\n }) {\n super();\n this.details = {\n description,\n originalError,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACAA,6BAA4B;AAC5B,0BAAoF;;;;;;;;;;;;;;;;;;UAExEA,qBAAAA;;;;GAAAA,uBAAAA,qBAAAA,CAAAA,EAAAA;IAMZC,sCAAiBD,oBAAoB;EACnCE,MAAM;AACR,CAAA;AAeA,IAAeC,qBAAf,6BAAeA,oBAAAA;EAEbC;AACF,GAHA;;MACGC,2BAAM,MAAML,kBAAAA;;GADAG,mBAAAA,WAAAA,QAAAA,MAAAA;AAAAA,qBAAAA,aAAAA;MAbdG,mCAAc;IACbC,YAAYC,OAAK;AACf,UAAIA,MAAMJ,SAAI,WAAiC;AAC7C,eAAOK;MACT,WAAWD,MAAMJ,SAAI,UAAgC;AACnD,eAAOM;MACT,WAAWF,MAAMJ,SAAI,WAAiC;AACpD,eAAOO;MACT;AACA,aAAOC;IACT;EACF,CAAA;MACCC,gCAAAA;GACcV,kBAAAA;AAMR,IAAMQ,wBAAN,cAAoCR,mBAAAA;EACzCC,OAAAA;AACF;AAFaO;AAAAA,wBAAAA,aAAAA;MADZE,gCAAW;IAAEC,YAAYX;EAAmB,CAAA;GAChCQ,qBAAAA;AAKN,IAAMF,wBAAN,cAAoCN,mBAAAA;EACzCC,OAAAA;AACF;AAFaK;AAAAA,wBAAAA,aAAAA;MADZI,gCAAW;IAAEC,YAAYX;EAAmB,CAAA;GAChCM,qBAAAA;;UAIDM,6BAAAA;;;;GAAAA,+BAAAA,6BAAAA,CAAAA,EAAAA;IAMZd,sCAAiBc,4BAA4B;EAC3Cb,MAAM;AACR,CAAA;AAGO,IAAMQ,uBAAN,cAAmCP,mBAAAA;EACxCC,OAAAA;EAGAY;EAGAC,UAAgC;AAClC;AARaP;;MAGVL,2BAAM,MAAMU,0BAAAA;;GAHFL,qBAAAA,WAAAA,UAAAA,MAAAA;;MAMVL,2BAAM,MAAMa,oCAAa;IAAEC,UAAU;EAAK,CAAA;qCACjC,WAAA,cAAA,SAAA,MAAA;GAPCT,qBAAAA,WAAAA,WAAAA,MAAAA;AAAAA,uBAAAA,aAAAA;MADZG,gCAAW;IAAEC,YAAYX;EAAmB,CAAA;GAChCO,oBAAAA;AAUN,IAAMU,0BAAsBC,qCAAgB;EACjDnB,MAAM;EACNoB,OAAO,MAAM;IAACX;IAAuBF;IAAuBC;;AAC9D,CAAA;;;AC5DO,IAAMa,sCAAN,cAAkDC,qBAAAA;EACvDC,SAASC,2BAA2BC;EAKpCC,YAAY,EAAEC,iBAAgB,GAAI;AAChC,UAAK;AACL,SAAKC,UAAU;MACbD;IACF;EACF;AACF;AAZaN;AAcN,IAAMQ,mCAAN,cAA+CP,qBAAAA;EACpDC,SAASC,2BAA2BM;EAMpCJ,YAAY,EAAEK,UAAS,GAA2B;AAChD,UAAK;AACL,SAAKH,UAAU;MACbG;MACAC,aAAa;IACf;EACF;AACF;AAdaH;AAgBN,IAAMI,uBAAN,cAAmCX,qBAAAA;EACxCC,SAASC,2BAA2BU;EAapCR,YAAY,EACVM,aACAG,cAAa,GAWZ;AACD,UAAK;AACL,SAAKP,UAAU;MACbI;MACAG;IACF;EACF;AACF;AAlCaF;","names":["ResponseStatusCode","registerEnumType","name","BaseResponseStatus","code","Field","InterfaceType","resolveType","value","SuccessResponseStatus","FailedResponseStatus","PendingResponseStatus","undefined","ObjectType","implements","FailedResponseStatusReason","reason","details","GraphQLJSON","nullable","ResponseStatusUnion","createUnionType","types","GuardrailsValidationFailureResponse","FailedResponseStatus","reason","FailedResponseStatusReason","GUARDRAILS_VALIDATION_FAILED","constructor","guardrailsReason","details","MessageStreamInterruptedResponse","MESSAGE_STREAM_INTERRUPTED","messageId","description","UnknownErrorResponse","UNKNOWN_ERROR","originalError"]}
|
package/dist/utils/index.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
GuardrailsValidationFailureResponse,
|
|
3
|
-
MessageStreamInterruptedResponse,
|
|
4
|
-
UnknownErrorResponse
|
|
5
|
-
} from "../chunk-XWBDEXDA.mjs";
|
|
6
|
-
import "../chunk-FHD4JECV.mjs";
|
|
7
|
-
export {
|
|
8
|
-
GuardrailsValidationFailureResponse,
|
|
9
|
-
MessageStreamInterruptedResponse,
|
|
10
|
-
UnknownErrorResponse
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/utils/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
import { TextEncoder } from "util";
|
|
3
|
-
import { RemoteLangGraphEventSource } from "../../../agents/langgraph/event-source";
|
|
4
|
-
import telemetry from "../../telemetry-client";
|
|
5
|
-
import {
|
|
6
|
-
constructLGCRemoteAction,
|
|
7
|
-
constructRemoteActions,
|
|
8
|
-
createHeaders,
|
|
9
|
-
} from "../remote-action-constructors";
|
|
10
|
-
import { execute } from "../remote-lg-action";
|
|
11
|
-
import { ReplaySubject } from "rxjs";
|
|
12
|
-
|
|
13
|
-
// Mock external dependencies
|
|
14
|
-
jest.mock("../remote-lg-action", () => ({
|
|
15
|
-
execute: jest.fn(),
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
jest.mock("../../telemetry-client", () => ({
|
|
19
|
-
capture: jest.fn(),
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
jest.mock("../../../agents/langgraph/event-source", () => ({
|
|
23
|
-
RemoteLangGraphEventSource: jest.fn(),
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
// Dummy logger
|
|
27
|
-
const logger = {
|
|
28
|
-
debug: jest.fn(),
|
|
29
|
-
error: jest.fn(),
|
|
30
|
-
child: jest.fn(() => logger),
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// Dummy graphqlContext
|
|
34
|
-
const graphqlContext = { properties: { dummyProp: "value" } } as any;
|
|
35
|
-
|
|
36
|
-
// Dummy agent state
|
|
37
|
-
const agentStates = [{ agentName: "agent1", state: "{}", configurable: "{}" }];
|
|
38
|
-
|
|
39
|
-
// Dummy agent used in constructLGCRemoteAction
|
|
40
|
-
const dummyAgent = { name: "agent1", description: "test agent" };
|
|
41
|
-
const endpoint = {
|
|
42
|
-
agents: [dummyAgent],
|
|
43
|
-
deploymentUrl: "http://dummy.deployment",
|
|
44
|
-
langsmithApiKey: "dummykey",
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
// Clear mocks before each test
|
|
48
|
-
beforeEach(() => {
|
|
49
|
-
jest.clearAllMocks();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe("remote action constructors", () => {
|
|
53
|
-
describe("constructLGCRemoteAction", () => {
|
|
54
|
-
it("should create an agent with remoteAgentHandler that processes events", async () => {
|
|
55
|
-
// Arrange: simulate execute returning a dummy ReadableStream
|
|
56
|
-
const dummyEncodedEvent = new TextEncoder().encode(JSON.stringify({ event: "test" }) + "\n");
|
|
57
|
-
const readerMock = {
|
|
58
|
-
read: jest
|
|
59
|
-
.fn()
|
|
60
|
-
.mockResolvedValueOnce({ done: false, value: dummyEncodedEvent })
|
|
61
|
-
.mockResolvedValueOnce({ done: true, value: new Uint8Array() }),
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const dummyResponse = {
|
|
65
|
-
getReader: () => readerMock,
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
(execute as jest.Mock).mockResolvedValue(dummyResponse);
|
|
69
|
-
|
|
70
|
-
// Mock RemoteLangGraphEventSource to return a dummy processed result
|
|
71
|
-
const processLangGraphEventsMock = jest.fn(() => "processed events");
|
|
72
|
-
(RemoteLangGraphEventSource as jest.Mock).mockImplementation(() => ({
|
|
73
|
-
eventStream$: { next: jest.fn(), complete: jest.fn(), error: jest.fn() },
|
|
74
|
-
processLangGraphEvents: processLangGraphEventsMock,
|
|
75
|
-
}));
|
|
76
|
-
|
|
77
|
-
// Act: build the action and call remoteAgentHandler
|
|
78
|
-
const actions = constructLGCRemoteAction({
|
|
79
|
-
endpoint,
|
|
80
|
-
graphqlContext,
|
|
81
|
-
logger,
|
|
82
|
-
messages: [],
|
|
83
|
-
agentStates,
|
|
84
|
-
});
|
|
85
|
-
expect(actions).toHaveLength(1);
|
|
86
|
-
const action = actions[0];
|
|
87
|
-
expect(action.name).toEqual(dummyAgent.name);
|
|
88
|
-
|
|
89
|
-
const result = await action.remoteAgentHandler({
|
|
90
|
-
name: dummyAgent.name,
|
|
91
|
-
actionInputsWithoutAgents: [],
|
|
92
|
-
threadId: "thread1",
|
|
93
|
-
nodeName: "node1",
|
|
94
|
-
additionalMessages: [],
|
|
95
|
-
metaEvents: [],
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
// Assert: processLangGraphEvents is called and result returned
|
|
99
|
-
expect(processLangGraphEventsMock).toHaveBeenCalled();
|
|
100
|
-
expect(result).toBe("processed events");
|
|
101
|
-
|
|
102
|
-
// Check telemetry.capture was called with agentExecution true
|
|
103
|
-
expect(telemetry.capture).toHaveBeenCalledWith(
|
|
104
|
-
"oss.runtime.remote_action_executed",
|
|
105
|
-
expect.objectContaining({
|
|
106
|
-
agentExecution: true,
|
|
107
|
-
type: "langgraph-platform",
|
|
108
|
-
agentsAmount: 1,
|
|
109
|
-
}),
|
|
110
|
-
);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
describe("constructRemoteActions", () => {
|
|
115
|
-
const json = {
|
|
116
|
-
agents: [{ name: "agent2", description: "agent desc" }],
|
|
117
|
-
actions: [
|
|
118
|
-
{
|
|
119
|
-
name: "action1",
|
|
120
|
-
description: "action desc",
|
|
121
|
-
parameters: { param: "value" },
|
|
122
|
-
},
|
|
123
|
-
],
|
|
124
|
-
};
|
|
125
|
-
const url = "http://dummy.api";
|
|
126
|
-
const onBeforeRequest = jest.fn(() => ({ headers: { Authorization: "Bearer token" } }));
|
|
127
|
-
|
|
128
|
-
it("should create remote action handler that calls fetch and returns the result", async () => {
|
|
129
|
-
// Arrange: mock fetch for action handler
|
|
130
|
-
global.fetch = jest.fn().mockResolvedValue({
|
|
131
|
-
ok: true,
|
|
132
|
-
json: jest.fn().mockResolvedValue({ result: "action result" }),
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
const actionsArray = constructRemoteActions({
|
|
136
|
-
json,
|
|
137
|
-
url,
|
|
138
|
-
onBeforeRequest,
|
|
139
|
-
graphqlContext,
|
|
140
|
-
logger,
|
|
141
|
-
messages: [],
|
|
142
|
-
agentStates,
|
|
143
|
-
});
|
|
144
|
-
// There should be one action (from json.actions) and one agent (from json.agents)
|
|
145
|
-
expect(actionsArray).toHaveLength(2);
|
|
146
|
-
const actionHandler = actionsArray[0].handler;
|
|
147
|
-
|
|
148
|
-
const result = await actionHandler({ foo: "bar" });
|
|
149
|
-
expect(result).toEqual("action result");
|
|
150
|
-
|
|
151
|
-
expect(global.fetch).toHaveBeenCalledWith(
|
|
152
|
-
`${url}/actions/execute`,
|
|
153
|
-
expect.objectContaining({
|
|
154
|
-
method: "POST",
|
|
155
|
-
headers: expect.objectContaining({
|
|
156
|
-
"Content-Type": "application/json",
|
|
157
|
-
Authorization: "Bearer token",
|
|
158
|
-
}),
|
|
159
|
-
body: expect.any(String),
|
|
160
|
-
}),
|
|
161
|
-
);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it("should create remote agent handler that processes events", async () => {
|
|
165
|
-
const json = {
|
|
166
|
-
agents: [
|
|
167
|
-
{
|
|
168
|
-
name: "agent2",
|
|
169
|
-
description: "agent desc",
|
|
170
|
-
type: "langgraph", // Add type to match RemoteAgentType.LangGraph
|
|
171
|
-
},
|
|
172
|
-
],
|
|
173
|
-
actions: [
|
|
174
|
-
{
|
|
175
|
-
name: "action1",
|
|
176
|
-
description: "action desc",
|
|
177
|
-
parameters: { param: "value" },
|
|
178
|
-
},
|
|
179
|
-
],
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
const dummyEncodedAgentEvent = new TextEncoder().encode('{"type":"data","content":"test"}\n');
|
|
183
|
-
|
|
184
|
-
const mockResponse = new Response(
|
|
185
|
-
new ReadableStream({
|
|
186
|
-
start(controller) {
|
|
187
|
-
controller.enqueue(dummyEncodedAgentEvent);
|
|
188
|
-
controller.close();
|
|
189
|
-
},
|
|
190
|
-
}),
|
|
191
|
-
{
|
|
192
|
-
status: 200,
|
|
193
|
-
statusText: "OK",
|
|
194
|
-
headers: new Headers({
|
|
195
|
-
"content-type": "application/json",
|
|
196
|
-
}),
|
|
197
|
-
},
|
|
198
|
-
);
|
|
199
|
-
|
|
200
|
-
global.fetch = jest.fn().mockResolvedValue(mockResponse);
|
|
201
|
-
|
|
202
|
-
const processLangGraphEventsMock = jest.fn().mockResolvedValue("agent events processed");
|
|
203
|
-
(RemoteLangGraphEventSource as jest.Mock).mockImplementation(() => ({
|
|
204
|
-
eventStream$: new ReplaySubject(),
|
|
205
|
-
processLangGraphEvents: processLangGraphEventsMock,
|
|
206
|
-
}));
|
|
207
|
-
|
|
208
|
-
const actionsArray = constructRemoteActions({
|
|
209
|
-
json,
|
|
210
|
-
url,
|
|
211
|
-
onBeforeRequest,
|
|
212
|
-
graphqlContext,
|
|
213
|
-
logger,
|
|
214
|
-
messages: [],
|
|
215
|
-
agentStates,
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
const remoteAgentHandler = (actionsArray[1] as any).remoteAgentHandler;
|
|
219
|
-
const result = await remoteAgentHandler({
|
|
220
|
-
name: "agent2",
|
|
221
|
-
actionInputsWithoutAgents: [],
|
|
222
|
-
threadId: "thread2",
|
|
223
|
-
nodeName: "node2",
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
expect(processLangGraphEventsMock).toHaveBeenCalled();
|
|
227
|
-
expect(result).toBe("agent events processed");
|
|
228
|
-
});
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
describe("createHeaders", () => {
|
|
232
|
-
it("should merge headers from onBeforeRequest", () => {
|
|
233
|
-
const onBeforeRequest = jest.fn(() => ({ headers: { "X-Test": "123" } }));
|
|
234
|
-
const headers = createHeaders(onBeforeRequest, graphqlContext);
|
|
235
|
-
expect(headers).toEqual({
|
|
236
|
-
"Content-Type": "application/json",
|
|
237
|
-
"X-Test": "123",
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
it("should return only Content-Type if no additional headers", () => {
|
|
242
|
-
const headers = createHeaders(undefined, graphqlContext);
|
|
243
|
-
expect(headers).toEqual({ "Content-Type": "application/json" });
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
});
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { Logger } from "pino";
|
|
2
|
-
import { catchError, mergeMap, Observable, of, throwError } from "rxjs";
|
|
3
|
-
import { AgentStateInput } from "../../graphql/inputs/agent-state.input";
|
|
4
|
-
import { Message } from "../../graphql/types/converted";
|
|
5
|
-
import { RuntimeErrorEvent, RuntimeEvent, RuntimeEventTypes } from "../../service-adapters/events";
|
|
6
|
-
import telemetry from "../telemetry-client";
|
|
7
|
-
import { RemoteAgentHandlerParams } from "./remote-actions";
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
AssistantMessage as AGUIAssistantMessage,
|
|
11
|
-
Message as AGUIMessage,
|
|
12
|
-
ToolCall,
|
|
13
|
-
} from "@ag-ui/client";
|
|
14
|
-
|
|
15
|
-
import { AbstractAgent } from "@ag-ui/client";
|
|
16
|
-
import { Action, CopilotKitError, CopilotKitErrorCode, parseJson } from "@copilotkit/shared";
|
|
17
|
-
import { MetaEventInput } from "../../graphql/inputs/meta-event.input";
|
|
18
|
-
import { GraphQLContext } from "../integrations/shared";
|
|
19
|
-
import { CopilotContextInput } from "../../graphql/inputs/copilot-context.input";
|
|
20
|
-
|
|
21
|
-
export type RemoteAgentAction = Action<[]> & {
|
|
22
|
-
remoteAgentHandler: (params: RemoteAgentHandlerParams) => Promise<Observable<RuntimeEvent>>;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export function constructAGUIRemoteAction({
|
|
26
|
-
logger,
|
|
27
|
-
messages,
|
|
28
|
-
agentStates,
|
|
29
|
-
agent,
|
|
30
|
-
metaEvents,
|
|
31
|
-
threadMetadata,
|
|
32
|
-
nodeName,
|
|
33
|
-
context,
|
|
34
|
-
graphqlContext,
|
|
35
|
-
}: {
|
|
36
|
-
logger: Logger;
|
|
37
|
-
messages: Message[];
|
|
38
|
-
agentStates?: AgentStateInput[];
|
|
39
|
-
agent: AbstractAgent;
|
|
40
|
-
metaEvents?: MetaEventInput[];
|
|
41
|
-
threadMetadata?: Record<string, any>;
|
|
42
|
-
nodeName?: string;
|
|
43
|
-
context?: CopilotContextInput[];
|
|
44
|
-
graphqlContext: GraphQLContext;
|
|
45
|
-
}): RemoteAgentAction[] {
|
|
46
|
-
const action: RemoteAgentAction = {
|
|
47
|
-
name: agent.agentId,
|
|
48
|
-
description: agent.description,
|
|
49
|
-
parameters: [],
|
|
50
|
-
handler: async () => {},
|
|
51
|
-
remoteAgentHandler: async ({
|
|
52
|
-
actionInputsWithoutAgents,
|
|
53
|
-
threadId,
|
|
54
|
-
}: RemoteAgentHandlerParams): Promise<Observable<RuntimeEvent>> => {
|
|
55
|
-
graphqlContext.request.signal.addEventListener(
|
|
56
|
-
"abort",
|
|
57
|
-
() => {
|
|
58
|
-
agent.abortRun();
|
|
59
|
-
},
|
|
60
|
-
{ once: true }, // optional: fire only once
|
|
61
|
-
);
|
|
62
|
-
logger.debug({ actionName: agent.agentId }, "Executing remote agent");
|
|
63
|
-
|
|
64
|
-
const agentWireMessages = convertMessagesToAGUIMessage(messages);
|
|
65
|
-
agent.messages = agentWireMessages;
|
|
66
|
-
agent.threadId = threadId;
|
|
67
|
-
|
|
68
|
-
telemetry.capture("oss.runtime.remote_action_executed", {
|
|
69
|
-
agentExecution: true,
|
|
70
|
-
type: "self-hosted",
|
|
71
|
-
agentsAmount: 1,
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
let state = {};
|
|
75
|
-
let config: Record<string, unknown> = {};
|
|
76
|
-
if (agentStates) {
|
|
77
|
-
const jsonState = agentStates.find((state) => state.agentName === agent.agentId);
|
|
78
|
-
if (jsonState) {
|
|
79
|
-
state = parseJson(jsonState.state, {});
|
|
80
|
-
config = parseJson(jsonState.config, {});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
agent.state = state;
|
|
84
|
-
|
|
85
|
-
const tools = actionInputsWithoutAgents.map((input) => {
|
|
86
|
-
return {
|
|
87
|
-
name: input.name,
|
|
88
|
-
description: input.description,
|
|
89
|
-
parameters: JSON.parse(input.jsonSchema),
|
|
90
|
-
};
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
const { streamSubgraphs, ...restConfig } = config;
|
|
94
|
-
|
|
95
|
-
const forwardedProps = {
|
|
96
|
-
config: restConfig,
|
|
97
|
-
...(metaEvents?.length ? { command: { resume: metaEvents[0]?.response } } : {}),
|
|
98
|
-
...(threadMetadata ? { threadMetadata } : {}),
|
|
99
|
-
...(nodeName ? { nodeName } : {}),
|
|
100
|
-
...(streamSubgraphs ? { streamSubgraphs } : {}),
|
|
101
|
-
// Forward properties from the graphql context to the agent, e.g Authorization token
|
|
102
|
-
...graphqlContext.properties,
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
return (
|
|
106
|
-
agent.legacy_to_be_removed_runAgentBridged({
|
|
107
|
-
tools,
|
|
108
|
-
forwardedProps,
|
|
109
|
-
context,
|
|
110
|
-
}) as Observable<RuntimeEvent>
|
|
111
|
-
).pipe(
|
|
112
|
-
mergeMap((event) => {
|
|
113
|
-
if (event.type === RuntimeEventTypes.RunError) {
|
|
114
|
-
const { message } = event as RuntimeErrorEvent;
|
|
115
|
-
return throwError(
|
|
116
|
-
() => new CopilotKitError({ message, code: CopilotKitErrorCode.UNKNOWN }),
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
// pass through non-error events
|
|
120
|
-
return of(event);
|
|
121
|
-
}),
|
|
122
|
-
catchError((err) => {
|
|
123
|
-
throw new CopilotKitError({
|
|
124
|
-
message: err.message,
|
|
125
|
-
code: CopilotKitErrorCode.UNKNOWN,
|
|
126
|
-
});
|
|
127
|
-
}),
|
|
128
|
-
);
|
|
129
|
-
},
|
|
130
|
-
};
|
|
131
|
-
return [action];
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export function convertMessagesToAGUIMessage(messages: Message[]): AGUIMessage[] {
|
|
135
|
-
const result: AGUIMessage[] = [];
|
|
136
|
-
|
|
137
|
-
for (const message of messages) {
|
|
138
|
-
if (message.isTextMessage()) {
|
|
139
|
-
result.push({
|
|
140
|
-
id: message.id,
|
|
141
|
-
role: message.role as any,
|
|
142
|
-
content: message.content,
|
|
143
|
-
});
|
|
144
|
-
} else if (message.isActionExecutionMessage()) {
|
|
145
|
-
const toolCall: ToolCall = {
|
|
146
|
-
id: message.id,
|
|
147
|
-
type: "function",
|
|
148
|
-
function: {
|
|
149
|
-
name: message.name,
|
|
150
|
-
arguments: JSON.stringify(message.arguments),
|
|
151
|
-
},
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
if (message.parentMessageId && result.some((m) => m.id === message.parentMessageId)) {
|
|
155
|
-
const parentMessage: AGUIAssistantMessage | undefined = result.find(
|
|
156
|
-
(m) => m.id === message.parentMessageId,
|
|
157
|
-
) as AGUIAssistantMessage;
|
|
158
|
-
if (parentMessage.toolCalls === undefined) {
|
|
159
|
-
parentMessage.toolCalls = [];
|
|
160
|
-
}
|
|
161
|
-
parentMessage.toolCalls.push(toolCall);
|
|
162
|
-
} else {
|
|
163
|
-
result.push({
|
|
164
|
-
id: message.parentMessageId ?? message.id,
|
|
165
|
-
role: "assistant",
|
|
166
|
-
toolCalls: [toolCall],
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
} else if (message.isResultMessage()) {
|
|
170
|
-
result.push({
|
|
171
|
-
id: message.id,
|
|
172
|
-
role: "tool",
|
|
173
|
-
content: message.result,
|
|
174
|
-
toolCallId: message.actionExecutionId,
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return result;
|
|
180
|
-
}
|