@copilotkit/runtime 1.50.0-beta.10 → 1.50.0-beta.11

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/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import 'reflect-metadata';
2
- import { TelemetryClient, CopilotKitLowLevelError, CopilotKitErrorCode, randomUUID, randomId, CopilotKitMisuseError, getZodParameters, readBody, CopilotKitError, CopilotKitAgentDiscoveryError, parseJson, convertJsonSchemaToZodSchema } from '@copilotkit/shared';
2
+ import { TelemetryClient, CopilotKitLowLevelError, CopilotKitErrorCode, randomUUID, randomId, isTelemetryDisabled, CopilotKitMisuseError, getZodParameters, readBody, CopilotKitError, CopilotKitAgentDiscoveryError, parseJson, convertJsonSchemaToZodSchema } from '@copilotkit/shared';
3
3
  import { HumanMessage, AIMessage, SystemMessage, ToolMessage } from '@langchain/core/messages';
4
4
  import { DynamicStructuredTool } from '@langchain/core/tools';
5
5
  import { registerEnumType, Field, InputType, ObjectType, createUnionType, InterfaceType, Query, Ctx, Mutation, Arg, Resolver, buildSchemaSync } from 'type-graphql';
@@ -65,7 +65,7 @@ var require_package = __commonJS({
65
65
  publishConfig: {
66
66
  access: "public"
67
67
  },
68
- version: "1.50.0-beta.9",
68
+ version: "1.50.0-beta.10",
69
69
  sideEffects: false,
70
70
  main: "./dist/index.js",
71
71
  module: "./dist/index.mjs",
@@ -3462,14 +3462,16 @@ var CopilotRuntime = class {
3462
3462
  constructor(params) {
3463
3463
  const agents = (params == null ? void 0 : params.agents) ?? {};
3464
3464
  const endpointAgents = this.assignEndpointsToAgents((params == null ? void 0 : params.remoteEndpoints) ?? []);
3465
+ const baseRunner = (params == null ? void 0 : params.runner) ?? new InMemoryAgentRunner();
3466
+ const runner = isTelemetryDisabled() ? baseRunner : new TelemetryAgentRunner({
3467
+ runner: baseRunner
3468
+ });
3465
3469
  this.runtimeArgs = {
3466
3470
  agents: {
3467
3471
  ...endpointAgents,
3468
3472
  ...agents
3469
3473
  },
3470
- // Use TelemetryAgentRunner by default to track agent execution telemetry
3471
- // Users can pass their own runner which will be wrapped for telemetry
3472
- runner: (params == null ? void 0 : params.runner) ?? new TelemetryAgentRunner(),
3474
+ runner,
3473
3475
  // TODO: add support for transcriptionService from CopilotRuntimeOptionsVNext once it is ready
3474
3476
  // transcriptionService: params?.transcriptionService,
3475
3477
  beforeRequestMiddleware: this.createOnBeforeRequestHandler(params).bind(this),
@@ -3562,11 +3564,24 @@ var CopilotRuntime = class {
3562
3564
  }
3563
3565
  createOnBeforeRequestHandler(params) {
3564
3566
  return async (hookParams) => {
3565
- var _a, _b;
3566
- (_a = params == null ? void 0 : params.beforeRequestMiddleware) == null ? void 0 : _a.call(params, hookParams);
3567
- if ((_b = params == null ? void 0 : params.middleware) == null ? void 0 : _b.onBeforeRequest) {
3568
- const { request, runtime, path } = hookParams;
3569
- const body = await readBody(request);
3567
+ var _a, _b, _c, _d;
3568
+ const { request } = hookParams;
3569
+ const publicApiKey = request.headers.get("x-copilotcloud-public-api-key");
3570
+ const body = await readBody(request);
3571
+ const forwardedProps = body.forwardedProps;
3572
+ const cloudBaseUrl = process.env.COPILOT_CLOUD_BASE_URL || "https://api.cloud.copilotkit.ai";
3573
+ telemetry_client_default.capture("oss.runtime.copilot_request_created", {
3574
+ "cloud.guardrails.enabled": ((_a = forwardedProps == null ? void 0 : forwardedProps.cloud) == null ? void 0 : _a.guardrails) !== void 0,
3575
+ requestType: ((_b = forwardedProps == null ? void 0 : forwardedProps.metadata) == null ? void 0 : _b.requestType) ?? "unknown",
3576
+ "cloud.api_key_provided": !!publicApiKey,
3577
+ ...publicApiKey ? {
3578
+ "cloud.public_api_key": publicApiKey
3579
+ } : {},
3580
+ "cloud.base_url": cloudBaseUrl
3581
+ });
3582
+ (_c = params == null ? void 0 : params.beforeRequestMiddleware) == null ? void 0 : _c.call(params, hookParams);
3583
+ if ((_d = params == null ? void 0 : params.middleware) == null ? void 0 : _d.onBeforeRequest) {
3584
+ const { request: request2, runtime, path } = hookParams;
3570
3585
  const gqlMessages = aguiToGQL(body.messages).reduce((acc, msg) => {
3571
3586
  if ("role" in msg && msg.role === "user") {
3572
3587
  acc.inputMessages.push(msg);
@@ -3584,7 +3599,7 @@ var CopilotRuntime = class {
3584
3599
  runId: body.runId,
3585
3600
  inputMessages,
3586
3601
  properties: body.forwardedProps,
3587
- url: request.url
3602
+ url: request2.url
3588
3603
  });
3589
3604
  }
3590
3605
  };