@copilotkit/runtime 1.50.0-beta.9 → 1.50.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/CHANGELOG.md +157 -0
- package/dist/chunk-27JKTS6P.mjs +1704 -0
- package/dist/chunk-27JKTS6P.mjs.map +1 -0
- package/dist/{chunk-FMU55SEU.mjs → chunk-2GPTVDTO.mjs} +2 -2
- package/dist/chunk-3AJVKDZX.mjs +3097 -0
- package/dist/chunk-3AJVKDZX.mjs.map +1 -0
- package/dist/{chunk-BJEYMRDD.mjs → chunk-45RCC3ZS.mjs} +2 -2
- package/dist/chunk-4EHJ4XFJ.mjs +25 -0
- package/dist/chunk-4EHJ4XFJ.mjs.map +1 -0
- package/dist/chunk-4IANB4TC.mjs +25 -0
- package/dist/chunk-4IANB4TC.mjs.map +1 -0
- package/dist/{chunk-Z752VE75.mjs → chunk-4KES76K3.mjs} +2 -2
- package/dist/chunk-4OGE3SLW.mjs +3100 -0
- package/dist/chunk-4OGE3SLW.mjs.map +1 -0
- package/dist/chunk-54YJBMCP.mjs +3097 -0
- package/dist/chunk-54YJBMCP.mjs.map +1 -0
- package/dist/chunk-6ER4SZYH.mjs +74 -0
- package/dist/chunk-6ER4SZYH.mjs.map +1 -0
- package/dist/chunk-6TNSLHVR.mjs +74 -0
- package/dist/chunk-6TNSLHVR.mjs.map +1 -0
- package/dist/chunk-7V4BK7TZ.mjs +25 -0
- package/dist/chunk-7V4BK7TZ.mjs.map +1 -0
- package/dist/chunk-7YZIEXD2.mjs +74 -0
- package/dist/chunk-7YZIEXD2.mjs.map +1 -0
- package/dist/chunk-A4XHOAFU.mjs +25 -0
- package/dist/chunk-A4XHOAFU.mjs.map +1 -0
- package/dist/chunk-A555KEAD.mjs +6020 -0
- package/dist/chunk-A555KEAD.mjs.map +1 -0
- package/dist/chunk-AF73TFTX.mjs +74 -0
- package/dist/chunk-AF73TFTX.mjs.map +1 -0
- package/dist/chunk-AQG2SVCA.mjs +25 -0
- package/dist/chunk-AQG2SVCA.mjs.map +1 -0
- package/dist/chunk-BJZHMXND.mjs +74 -0
- package/dist/chunk-BJZHMXND.mjs.map +1 -0
- package/dist/chunk-CB2OJXF6.mjs +25 -0
- package/dist/chunk-CB2OJXF6.mjs.map +1 -0
- package/dist/chunk-CEOMFPJU.mjs +6020 -0
- package/dist/chunk-CEOMFPJU.mjs.map +1 -0
- package/dist/chunk-CZVLR7CC.mjs +175 -0
- package/dist/chunk-CZVLR7CC.mjs.map +1 -0
- package/dist/{chunk-SBCOROE4.mjs → chunk-DCEEHMLJ.mjs} +16 -1
- package/dist/chunk-DCEEHMLJ.mjs.map +1 -0
- package/dist/chunk-DE3CLKUG.mjs +25 -0
- package/dist/chunk-DE3CLKUG.mjs.map +1 -0
- package/dist/chunk-DTPRUTNV.mjs +25 -0
- package/dist/chunk-DTPRUTNV.mjs.map +1 -0
- package/dist/{chunk-TTUAEJLD.mjs → chunk-ERUOA47O.mjs} +11 -2
- package/dist/chunk-ERUOA47O.mjs.map +1 -0
- package/dist/chunk-ESSRC64W.mjs +74 -0
- package/dist/chunk-ESSRC64W.mjs.map +1 -0
- package/dist/chunk-GRAN6K6N.mjs +25 -0
- package/dist/chunk-GRAN6K6N.mjs.map +1 -0
- package/dist/chunk-I27F2UPA.mjs +175 -0
- package/dist/chunk-I27F2UPA.mjs.map +1 -0
- package/dist/chunk-IAZKTOQW.mjs +25 -0
- package/dist/chunk-IAZKTOQW.mjs.map +1 -0
- package/dist/chunk-J6XZ5MFB.mjs +25 -0
- package/dist/chunk-J6XZ5MFB.mjs.map +1 -0
- package/dist/chunk-JJ32MA4C.mjs +73 -0
- package/dist/chunk-JJ32MA4C.mjs.map +1 -0
- package/dist/chunk-JJY4ZTHQ.mjs +25 -0
- package/dist/chunk-JJY4ZTHQ.mjs.map +1 -0
- package/dist/chunk-KEYLBFU2.mjs +3117 -0
- package/dist/chunk-KEYLBFU2.mjs.map +1 -0
- package/dist/chunk-KQ53L4WZ.mjs +3094 -0
- package/dist/chunk-KQ53L4WZ.mjs.map +1 -0
- package/dist/chunk-KTELVQ67.mjs +3098 -0
- package/dist/chunk-KTELVQ67.mjs.map +1 -0
- package/dist/chunk-LPEPX6NH.mjs +25 -0
- package/dist/chunk-LPEPX6NH.mjs.map +1 -0
- package/dist/chunk-MDXE55DK.mjs +3117 -0
- package/dist/chunk-MDXE55DK.mjs.map +1 -0
- package/dist/chunk-MMFUVOXH.mjs +73 -0
- package/dist/chunk-MMFUVOXH.mjs.map +1 -0
- package/dist/chunk-N3Y4U66N.mjs +253 -0
- package/dist/chunk-N3Y4U66N.mjs.map +1 -0
- package/dist/chunk-O7UYB4MH.mjs +25 -0
- package/dist/chunk-O7UYB4MH.mjs.map +1 -0
- package/dist/chunk-OFNVQHNM.mjs +3089 -0
- package/dist/chunk-OFNVQHNM.mjs.map +1 -0
- package/dist/{chunk-DZV4ZIAR.mjs → chunk-OFSV5GET.mjs} +17 -6
- package/dist/chunk-OFSV5GET.mjs.map +1 -0
- package/dist/chunk-OMRST67R.mjs +25 -0
- package/dist/chunk-OMRST67R.mjs.map +1 -0
- package/dist/chunk-PRZHE74A.mjs +25 -0
- package/dist/chunk-PRZHE74A.mjs.map +1 -0
- package/dist/chunk-PTYRVXXP.mjs +80 -0
- package/dist/chunk-PTYRVXXP.mjs.map +1 -0
- package/dist/chunk-R22B5CCO.mjs +25 -0
- package/dist/chunk-R22B5CCO.mjs.map +1 -0
- package/dist/chunk-SHBDMA63.mjs +141 -0
- package/dist/chunk-SHBDMA63.mjs.map +1 -0
- package/dist/chunk-SPVXBPRA.mjs +74 -0
- package/dist/chunk-SPVXBPRA.mjs.map +1 -0
- package/dist/chunk-T72G46ME.mjs +25 -0
- package/dist/chunk-T72G46ME.mjs.map +1 -0
- package/dist/chunk-TGELROPU.mjs +25 -0
- package/dist/chunk-TGELROPU.mjs.map +1 -0
- package/dist/chunk-UNX4IAAD.mjs +25 -0
- package/dist/chunk-UNX4IAAD.mjs.map +1 -0
- package/dist/chunk-V4DHVC7M.mjs +3085 -0
- package/dist/chunk-V4DHVC7M.mjs.map +1 -0
- package/dist/chunk-VVRFOB66.mjs +25 -0
- package/dist/chunk-VVRFOB66.mjs.map +1 -0
- package/dist/chunk-W6NVBYM6.mjs +80 -0
- package/dist/chunk-W6NVBYM6.mjs.map +1 -0
- package/dist/chunk-W7MBACGC.mjs +74 -0
- package/dist/chunk-W7MBACGC.mjs.map +1 -0
- package/dist/chunk-WMD4XZZS.mjs +25 -0
- package/dist/chunk-WMD4XZZS.mjs.map +1 -0
- package/dist/chunk-WX2ZNCRT.mjs +74 -0
- package/dist/chunk-WX2ZNCRT.mjs.map +1 -0
- package/dist/chunk-Y2Z62E2T.mjs +74 -0
- package/dist/chunk-Y2Z62E2T.mjs.map +1 -0
- package/dist/chunk-YO4I6RVI.mjs +25 -0
- package/dist/chunk-YO4I6RVI.mjs.map +1 -0
- package/dist/chunk-Z6Q5IW6I.mjs +3098 -0
- package/dist/chunk-Z6Q5IW6I.mjs.map +1 -0
- package/dist/chunk-Z726O3G2.mjs +25 -0
- package/dist/chunk-Z726O3G2.mjs.map +1 -0
- package/dist/chunk-ZE4SMZZR.mjs +3097 -0
- package/dist/chunk-ZE4SMZZR.mjs.map +1 -0
- package/dist/chunk-ZULZB33C.mjs +73 -0
- package/dist/chunk-ZULZB33C.mjs.map +1 -0
- package/dist/chunk-ZVRGXMY7.mjs +25 -0
- package/dist/chunk-ZVRGXMY7.mjs.map +1 -0
- package/dist/chunk-ZZ35WBYQ.mjs +25 -0
- package/dist/chunk-ZZ35WBYQ.mjs.map +1 -0
- package/dist/graphql/types/converted/index.d.ts +1 -1
- package/dist/graphql/types/converted/index.js +16 -110
- package/dist/graphql/types/converted/index.js.map +1 -1
- package/dist/graphql/types/converted/index.mjs +2 -3
- package/dist/{groq-adapter-50bc6e4a.d.ts → groq-adapter-540da9c3.d.ts} +6 -1
- package/dist/groq-adapter-a6f5e9d2.d.ts +331 -0
- package/dist/groq-adapter-c8aec5c5.d.ts +321 -0
- package/dist/index-96b330da.d.ts +119 -0
- package/dist/index.d.ts +67 -8
- package/dist/index.js +118 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +120 -31
- package/dist/index.mjs.map +1 -1
- package/dist/langserve-0c6100e3.d.ts +257 -0
- package/dist/langserve-978d5790.d.ts +243 -0
- package/dist/{langserve-74a52292.d.ts → langserve-9fc76ce5.d.ts} +1 -0
- package/dist/lib/index.d.ts +5 -59
- package/dist/lib/index.js +3702 -803
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +20 -18
- package/dist/lib/integrations/index.d.ts +15 -9
- package/dist/lib/integrations/index.js +215 -187
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +8 -7
- package/dist/lib/integrations/nest/index.d.ts +5 -6
- package/dist/lib/integrations/nest/index.js +197 -175
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +6 -5
- package/dist/lib/integrations/node-express/index.d.ts +5 -6
- package/dist/lib/integrations/node-express/index.js +197 -175
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +6 -5
- package/dist/lib/integrations/node-http/index.d.ts +5 -6
- package/dist/lib/integrations/node-http/index.js +197 -175
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +5 -4
- package/dist/service-adapters/index.d.ts +7 -11
- package/dist/service-adapters/index.js +8 -21
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +2 -4
- package/dist/shared-0a7346ce.d.ts +466 -0
- package/dist/{shared-f6d43ef8.d.ts → shared-35c6eb04.d.ts} +3 -1
- package/dist/shared-9ed1dc31.d.ts +414 -0
- package/dist/shared-da5708fe.d.ts +449 -0
- package/package.json +14 -20
- package/src/lib/index.ts +7 -6
- package/src/lib/runtime/copilot-runtime.ts +62 -26
- package/src/lib/runtime/telemetry-agent-runner.ts +139 -0
- package/dist/chunk-DZV4ZIAR.mjs.map +0 -1
- package/dist/chunk-SBCOROE4.mjs.map +0 -1
- package/dist/chunk-TTUAEJLD.mjs.map +0 -1
- /package/dist/{chunk-FMU55SEU.mjs.map → chunk-2GPTVDTO.mjs.map} +0 -0
- /package/dist/{chunk-BJEYMRDD.mjs.map → chunk-45RCC3ZS.mjs.map} +0 -0
- /package/dist/{chunk-Z752VE75.mjs.map → chunk-4KES76K3.mjs.map} +0 -0
|
@@ -13,47 +13,50 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import {
|
|
16
|
-
Action,
|
|
17
|
-
CopilotErrorHandler,
|
|
16
|
+
type Action,
|
|
17
|
+
type CopilotErrorHandler,
|
|
18
18
|
CopilotKitMisuseError,
|
|
19
|
-
MaybePromise,
|
|
20
|
-
NonEmptyRecord,
|
|
21
|
-
Parameter,
|
|
19
|
+
type MaybePromise,
|
|
20
|
+
type NonEmptyRecord,
|
|
21
|
+
type Parameter,
|
|
22
22
|
readBody,
|
|
23
23
|
getZodParameters,
|
|
24
|
-
PartialBy,
|
|
24
|
+
type PartialBy,
|
|
25
|
+
isTelemetryDisabled,
|
|
25
26
|
} from "@copilotkit/shared";
|
|
26
|
-
import {
|
|
27
|
+
import type { RunAgentInput } from "@ag-ui/core";
|
|
27
28
|
import { aguiToGQL } from "../../graphql/message-conversion/agui-to-gql";
|
|
28
|
-
import { CopilotServiceAdapter, RemoteChainParameters } from "../../service-adapters";
|
|
29
|
+
import type { CopilotServiceAdapter, RemoteChainParameters } from "../../service-adapters";
|
|
29
30
|
import {
|
|
30
31
|
CopilotRuntime as CopilotRuntimeVNext,
|
|
31
|
-
CopilotRuntimeOptions,
|
|
32
|
-
CopilotRuntimeOptions as CopilotRuntimeOptionsVNext,
|
|
33
|
-
InMemoryAgentRunner
|
|
32
|
+
type CopilotRuntimeOptions,
|
|
33
|
+
type CopilotRuntimeOptions as CopilotRuntimeOptionsVNext,
|
|
34
|
+
InMemoryAgentRunner,
|
|
34
35
|
} from "@copilotkitnext/runtime";
|
|
36
|
+
import { TelemetryAgentRunner } from "./telemetry-agent-runner";
|
|
37
|
+
import telemetry from "../telemetry-client";
|
|
35
38
|
|
|
36
|
-
import { MessageInput } from "../../graphql/inputs/message.input";
|
|
37
|
-
import { Message } from "../../graphql/types/converted";
|
|
39
|
+
import type { MessageInput } from "../../graphql/inputs/message.input";
|
|
40
|
+
import type { Message } from "../../graphql/types/converted";
|
|
38
41
|
|
|
39
42
|
import {
|
|
40
43
|
EndpointType,
|
|
41
|
-
EndpointDefinition,
|
|
42
|
-
CopilotKitEndpoint,
|
|
43
|
-
LangGraphPlatformEndpoint,
|
|
44
|
+
type EndpointDefinition,
|
|
45
|
+
type CopilotKitEndpoint,
|
|
46
|
+
type LangGraphPlatformEndpoint,
|
|
44
47
|
} from "./types";
|
|
45
48
|
|
|
46
|
-
import { CopilotObservabilityConfig, LLMRequestData, LLMResponseData } from "../observability";
|
|
47
|
-
import { AbstractAgent } from "@ag-ui/client";
|
|
49
|
+
import type { CopilotObservabilityConfig, LLMRequestData, LLMResponseData } from "../observability";
|
|
50
|
+
import type { AbstractAgent } from "@ag-ui/client";
|
|
48
51
|
|
|
49
52
|
// +++ MCP Imports +++
|
|
50
53
|
import {
|
|
51
|
-
MCPClient,
|
|
52
|
-
MCPEndpointConfig,
|
|
53
|
-
MCPTool,
|
|
54
|
+
type MCPClient,
|
|
55
|
+
type MCPEndpointConfig,
|
|
56
|
+
type MCPTool,
|
|
54
57
|
extractParametersFromSchema,
|
|
55
58
|
} from "./mcp-tools-utils";
|
|
56
|
-
import { BasicAgent, BasicAgentConfiguration } from "@copilotkitnext/agent";
|
|
59
|
+
import { BasicAgent, type BasicAgentConfiguration } from "@copilotkitnext/agent";
|
|
57
60
|
// Define the function type alias here or import if defined elsewhere
|
|
58
61
|
type CreateMCPClientFunction = (config: MCPEndpointConfig) => Promise<MCPClient>;
|
|
59
62
|
|
|
@@ -308,9 +311,19 @@ export class CopilotRuntime<const T extends Parameter[] | [] = []> {
|
|
|
308
311
|
const agents = params?.agents ?? {};
|
|
309
312
|
const endpointAgents = this.assignEndpointsToAgents(params?.remoteEndpoints ?? []);
|
|
310
313
|
|
|
314
|
+
// Determine the base runner (user-provided or default)
|
|
315
|
+
const baseRunner = params?.runner ?? new InMemoryAgentRunner();
|
|
316
|
+
|
|
317
|
+
// Wrap with TelemetryAgentRunner unless telemetry is disabled
|
|
318
|
+
// This ensures we always capture agent execution telemetry when enabled,
|
|
319
|
+
// even if the user provides their own custom runner
|
|
320
|
+
const runner = isTelemetryDisabled()
|
|
321
|
+
? baseRunner
|
|
322
|
+
: new TelemetryAgentRunner({ runner: baseRunner });
|
|
323
|
+
|
|
311
324
|
this.runtimeArgs = {
|
|
312
325
|
agents: { ...endpointAgents, ...agents },
|
|
313
|
-
runner
|
|
326
|
+
runner,
|
|
314
327
|
// TODO: add support for transcriptionService from CopilotRuntimeOptionsVNext once it is ready
|
|
315
328
|
// transcriptionService: params?.transcriptionService,
|
|
316
329
|
|
|
@@ -372,10 +385,11 @@ export class CopilotRuntime<const T extends Parameter[] | [] = []> {
|
|
|
372
385
|
});
|
|
373
386
|
}
|
|
374
387
|
|
|
375
|
-
|
|
388
|
+
const actions = this.params?.actions;
|
|
389
|
+
if (actions) {
|
|
376
390
|
const mcpTools = await this.getToolsFromMCP();
|
|
377
391
|
agentsList = this.assignToolsToAgents(agents, [
|
|
378
|
-
...this.getToolsFromActions(
|
|
392
|
+
...this.getToolsFromActions(actions),
|
|
379
393
|
...mcpTools,
|
|
380
394
|
]);
|
|
381
395
|
}
|
|
@@ -437,6 +451,29 @@ export class CopilotRuntime<const T extends Parameter[] | [] = []> {
|
|
|
437
451
|
params?: CopilotRuntimeConstructorParams<T> & PartialBy<CopilotRuntimeOptions, "agents">,
|
|
438
452
|
) {
|
|
439
453
|
return async (hookParams: BeforeRequestMiddlewareFnParameters[0]) => {
|
|
454
|
+
const { request } = hookParams;
|
|
455
|
+
|
|
456
|
+
// Capture telemetry for copilot request creation
|
|
457
|
+
const publicApiKey = request.headers.get("x-copilotcloud-public-api-key");
|
|
458
|
+
const body = (await readBody(request)) as RunAgentInput;
|
|
459
|
+
const forwardedProps = body.forwardedProps as
|
|
460
|
+
| {
|
|
461
|
+
cloud?: { guardrails?: unknown };
|
|
462
|
+
metadata?: { requestType?: string };
|
|
463
|
+
}
|
|
464
|
+
| undefined;
|
|
465
|
+
|
|
466
|
+
// Get cloud base URL from environment or default
|
|
467
|
+
const cloudBaseUrl = process.env.COPILOT_CLOUD_BASE_URL || "https://api.cloud.copilotkit.ai";
|
|
468
|
+
|
|
469
|
+
telemetry.capture("oss.runtime.copilot_request_created", {
|
|
470
|
+
"cloud.guardrails.enabled": forwardedProps?.cloud?.guardrails !== undefined,
|
|
471
|
+
requestType: forwardedProps?.metadata?.requestType ?? "unknown",
|
|
472
|
+
"cloud.api_key_provided": !!publicApiKey,
|
|
473
|
+
...(publicApiKey ? { "cloud.public_api_key": publicApiKey } : {}),
|
|
474
|
+
"cloud.base_url": cloudBaseUrl,
|
|
475
|
+
});
|
|
476
|
+
|
|
440
477
|
// TODO: get public api key and run with expected data
|
|
441
478
|
// if (this.observability?.enabled && this.params.publicApiKey) {
|
|
442
479
|
// this.logObservabilityBeforeRequest()
|
|
@@ -447,7 +484,6 @@ export class CopilotRuntime<const T extends Parameter[] | [] = []> {
|
|
|
447
484
|
|
|
448
485
|
if (params?.middleware?.onBeforeRequest) {
|
|
449
486
|
const { request, runtime, path } = hookParams;
|
|
450
|
-
const body = (await readBody(request)) as RunAgentInput;
|
|
451
487
|
const gqlMessages = (aguiToGQL(body.messages) as Message[]).reduce(
|
|
452
488
|
(acc, msg) => {
|
|
453
489
|
if ("role" in msg && msg.role === "user") {
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TelemetryAgentRunner - A wrapper around AgentRunner that adds telemetry
|
|
3
|
+
* for agent execution streams.
|
|
4
|
+
*
|
|
5
|
+
* This captures the following telemetry events:
|
|
6
|
+
* - oss.runtime.agent_execution_stream_started - when an agent execution starts
|
|
7
|
+
* - oss.runtime.agent_execution_stream_ended - when an agent execution completes
|
|
8
|
+
* - oss.runtime.agent_execution_stream_errored - when an agent execution fails
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { type AgentRunner, InMemoryAgentRunner } from "@copilotkitnext/runtime";
|
|
12
|
+
import { createHash } from "node:crypto";
|
|
13
|
+
import { tap, catchError, finalize } from "rxjs";
|
|
14
|
+
import telemetry from "../telemetry-client";
|
|
15
|
+
import type { AgentExecutionResponseInfo } from "@copilotkit/shared/src/telemetry/events";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Configuration options for TelemetryAgentRunner
|
|
19
|
+
*/
|
|
20
|
+
export interface TelemetryAgentRunnerConfig {
|
|
21
|
+
/**
|
|
22
|
+
* The underlying runner to delegate to
|
|
23
|
+
* If not provided, defaults to InMemoryAgentRunner
|
|
24
|
+
*/
|
|
25
|
+
runner?: AgentRunner;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Optional LangSmith API key (will be hashed for telemetry)
|
|
29
|
+
*/
|
|
30
|
+
langsmithApiKey?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* An AgentRunner wrapper that adds telemetry tracking for agent executions.
|
|
35
|
+
*
|
|
36
|
+
* Usage:
|
|
37
|
+
* ```ts
|
|
38
|
+
* const runtime = new CopilotRuntime({
|
|
39
|
+
* runner: new TelemetryAgentRunner(),
|
|
40
|
+
* // or with custom runner:
|
|
41
|
+
* runner: new TelemetryAgentRunner({ runner: customRunner }),
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export class TelemetryAgentRunner implements AgentRunner {
|
|
46
|
+
private readonly _runner: AgentRunner;
|
|
47
|
+
private readonly hashedLgcKey: string | undefined;
|
|
48
|
+
|
|
49
|
+
constructor(config?: TelemetryAgentRunnerConfig) {
|
|
50
|
+
this._runner = config?.runner ?? new InMemoryAgentRunner();
|
|
51
|
+
this.hashedLgcKey = config?.langsmithApiKey
|
|
52
|
+
? createHash("sha256").update(config.langsmithApiKey).digest("hex")
|
|
53
|
+
: undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Runs an agent with telemetry tracking.
|
|
58
|
+
* Wraps the underlying runner's Observable stream with telemetry events.
|
|
59
|
+
*/
|
|
60
|
+
run(...args: Parameters<AgentRunner["run"]>): ReturnType<AgentRunner["run"]> {
|
|
61
|
+
const streamInfo: AgentExecutionResponseInfo = {
|
|
62
|
+
hashedLgcKey: this.hashedLgcKey,
|
|
63
|
+
};
|
|
64
|
+
let streamErrored = false;
|
|
65
|
+
|
|
66
|
+
// Capture stream started event
|
|
67
|
+
telemetry.capture("oss.runtime.agent_execution_stream_started", {
|
|
68
|
+
hashedLgcKey: this.hashedLgcKey,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Delegate to the underlying runner and wrap with telemetry
|
|
72
|
+
return this._runner.run(...args).pipe(
|
|
73
|
+
// Extract metadata from events if available
|
|
74
|
+
tap((event) => {
|
|
75
|
+
// Try to extract provider/model info from raw events
|
|
76
|
+
const rawEvent = (
|
|
77
|
+
event as {
|
|
78
|
+
rawEvent?: { metadata?: Record<string, unknown>; data?: Record<string, unknown> };
|
|
79
|
+
}
|
|
80
|
+
).rawEvent;
|
|
81
|
+
if (rawEvent?.data) {
|
|
82
|
+
const data = rawEvent.data as { output?: { model?: string } };
|
|
83
|
+
if (data?.output?.model) {
|
|
84
|
+
streamInfo.model = data.output.model;
|
|
85
|
+
streamInfo.provider = data.output.model;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (rawEvent?.metadata) {
|
|
89
|
+
const metadata = rawEvent.metadata as {
|
|
90
|
+
langgraph_host?: string;
|
|
91
|
+
langgraph_version?: string;
|
|
92
|
+
};
|
|
93
|
+
if (metadata?.langgraph_host) {
|
|
94
|
+
streamInfo.langGraphHost = metadata.langgraph_host;
|
|
95
|
+
}
|
|
96
|
+
if (metadata?.langgraph_version) {
|
|
97
|
+
streamInfo.langGraphVersion = metadata.langgraph_version;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}),
|
|
101
|
+
catchError((error) => {
|
|
102
|
+
// Capture stream error event
|
|
103
|
+
streamErrored = true;
|
|
104
|
+
telemetry.capture("oss.runtime.agent_execution_stream_errored", {
|
|
105
|
+
...streamInfo,
|
|
106
|
+
error: error instanceof Error ? error.message : String(error),
|
|
107
|
+
});
|
|
108
|
+
throw error;
|
|
109
|
+
}),
|
|
110
|
+
finalize(() => {
|
|
111
|
+
// Capture stream ended event (only if not errored)
|
|
112
|
+
if (!streamErrored) {
|
|
113
|
+
telemetry.capture("oss.runtime.agent_execution_stream_ended", streamInfo);
|
|
114
|
+
}
|
|
115
|
+
}),
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Delegates to the underlying runner's connect method
|
|
121
|
+
*/
|
|
122
|
+
connect(...args: Parameters<AgentRunner["connect"]>): ReturnType<AgentRunner["connect"]> {
|
|
123
|
+
return this._runner.connect(...args);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Delegates to the underlying runner's isRunning method
|
|
128
|
+
*/
|
|
129
|
+
isRunning(...args: Parameters<AgentRunner["isRunning"]>): ReturnType<AgentRunner["isRunning"]> {
|
|
130
|
+
return this._runner.isRunning(...args);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Delegates to the underlying runner's stop method
|
|
135
|
+
*/
|
|
136
|
+
stop(...args: Parameters<AgentRunner["stop"]>): ReturnType<AgentRunner["stop"]> {
|
|
137
|
+
return this._runner.stop(...args);
|
|
138
|
+
}
|
|
139
|
+
}
|