@copilotkitnext/core 0.0.22-alpha.9 → 0.0.22

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,8 +1,13 @@
1
- import { HttpAgent, runHttpRequest, transformHttpEventStream } from '@ag-ui/client';
2
- import { logger, randomUUID, partialJSONParse } from '@copilotkitnext/shared';
3
- import { zodToJsonSchema } from 'zod-to-json-schema';
4
-
5
1
  // src/core/agent-registry.ts
2
+ import { HttpAgent as HttpAgent2 } from "@ag-ui/client";
3
+ import { logger } from "@copilotkitnext/shared";
4
+
5
+ // src/agent.ts
6
+ import {
7
+ HttpAgent,
8
+ runHttpRequest,
9
+ transformHttpEventStream
10
+ } from "@ag-ui/client";
6
11
  var ProxiedCopilotRuntimeAgent = class extends HttpAgent {
7
12
  runtimeUrl;
8
13
  transport;
@@ -234,7 +239,7 @@ var AgentRegistry = class {
234
239
  * Apply current headers to an agent
235
240
  */
236
241
  applyHeadersToAgent(agent) {
237
- if (agent instanceof HttpAgent) {
242
+ if (agent instanceof HttpAgent2) {
238
243
  agent.headers = { ...this.core.headers };
239
244
  }
240
245
  }
@@ -387,6 +392,9 @@ var AgentRegistry = class {
387
392
  );
388
393
  }
389
394
  };
395
+
396
+ // src/core/context-store.ts
397
+ import { randomUUID } from "@copilotkitnext/shared";
390
398
  var ContextStore = class {
391
399
  constructor(core) {
392
400
  this.core = core;
@@ -428,6 +436,9 @@ var ContextStore = class {
428
436
  );
429
437
  }
430
438
  };
439
+
440
+ // src/core/suggestion-engine.ts
441
+ import { randomUUID as randomUUID2, partialJSONParse } from "@copilotkitnext/shared";
431
442
  var SuggestionEngine = class {
432
443
  constructor(core) {
433
444
  this.core = core;
@@ -440,7 +451,7 @@ var SuggestionEngine = class {
440
451
  */
441
452
  initialize(suggestionsConfig) {
442
453
  for (const config of suggestionsConfig) {
443
- this._suggestionsConfig[randomUUID()] = config;
454
+ this._suggestionsConfig[randomUUID2()] = config;
444
455
  }
445
456
  }
446
457
  /**
@@ -448,7 +459,7 @@ var SuggestionEngine = class {
448
459
  * @returns The ID of the created config
449
460
  */
450
461
  addSuggestionsConfig(config) {
451
- const id = randomUUID();
462
+ const id = randomUUID2();
452
463
  this._suggestionsConfig[id] = config;
453
464
  void this.notifySuggestionsConfigChanged();
454
465
  return id;
@@ -479,7 +490,7 @@ var SuggestionEngine = class {
479
490
  if (!this.shouldShowSuggestions(config, messageCount)) {
480
491
  continue;
481
492
  }
482
- const suggestionId = randomUUID();
493
+ const suggestionId = randomUUID2();
483
494
  if (isDynamicSuggestionsConfig(config)) {
484
495
  if (!hasAnySuggestions) {
485
496
  hasAnySuggestions = true;
@@ -760,15 +771,18 @@ var SUGGEST_TOOL = {
760
771
  description: "The message to send when the suggestion is clicked. This should be a clear, complete sentence and will be sent as an instruction to the AI."
761
772
  }
762
773
  },
763
- required: ["title", "message"],
764
- additionalProperties: false
774
+ required: ["title", "message"]
765
775
  }
766
776
  }
767
777
  },
768
- required: ["suggestions"],
769
- additionalProperties: false
778
+ required: ["suggestions"]
770
779
  }
771
780
  };
781
+
782
+ // src/core/run-handler.ts
783
+ import { HttpAgent as HttpAgent3 } from "@ag-ui/client";
784
+ import { randomUUID as randomUUID3, logger as logger2 } from "@copilotkitnext/shared";
785
+ import { zodToJsonSchema } from "zod-to-json-schema";
772
786
  var RunHandler = class {
773
787
  constructor(core) {
774
788
  this.core = core;
@@ -793,7 +807,7 @@ var RunHandler = class {
793
807
  addTool(tool) {
794
808
  const existingToolIndex = this._tools.findIndex((t) => t.name === tool.name && t.agentId === tool.agentId);
795
809
  if (existingToolIndex !== -1) {
796
- logger.warn(`Tool already exists: '${tool.name}' for agent '${tool.agentId || "global"}', skipping.`);
810
+ logger2.warn(`Tool already exists: '${tool.name}' for agent '${tool.agentId || "global"}', skipping.`);
797
811
  return;
798
812
  }
799
813
  this._tools.push(tool);
@@ -835,7 +849,10 @@ var RunHandler = class {
835
849
  */
836
850
  async connectAgent({ agent }) {
837
851
  try {
838
- if (agent instanceof HttpAgent) {
852
+ await agent.detachActiveRun();
853
+ agent.setMessages([]);
854
+ agent.setState({});
855
+ if (agent instanceof HttpAgent3) {
839
856
  agent.headers = { ...this.core.headers };
840
857
  }
841
858
  const runAgentResult = await agent.connectAgent(
@@ -867,7 +884,7 @@ var RunHandler = class {
867
884
  if (agent.agentId) {
868
885
  void this.core.suggestionEngine.clearSuggestions(agent.agentId);
869
886
  }
870
- if (agent instanceof HttpAgent) {
887
+ if (agent instanceof HttpAgent3) {
871
888
  agent.headers = { ...this.core.headers };
872
889
  }
873
890
  if (withMessages) {
@@ -1031,7 +1048,7 @@ var RunHandler = class {
1031
1048
  if (!errorMessage || !isArgumentError) {
1032
1049
  const messageIndex = agent.messages.findIndex((m) => m.id === message.id);
1033
1050
  const toolMessage = {
1034
- id: randomUUID(),
1051
+ id: randomUUID3(),
1035
1052
  role: "tool",
1036
1053
  toolCallId: toolCall.id,
1037
1054
  content: toolCallResult
@@ -1136,7 +1153,7 @@ var RunHandler = class {
1136
1153
  if (!errorMessage || !isArgumentError) {
1137
1154
  const messageIndex = agent.messages.findIndex((m) => m.id === message.id);
1138
1155
  const toolMessage = {
1139
- id: randomUUID(),
1156
+ id: randomUUID3(),
1140
1157
  role: "tool",
1141
1158
  toolCallId: toolCall.id,
1142
1159
  content: toolCallResult
@@ -1197,12 +1214,11 @@ var RunHandler = class {
1197
1214
  };
1198
1215
  var EMPTY_TOOL_SCHEMA = {
1199
1216
  type: "object",
1200
- properties: {},
1201
- additionalProperties: false
1217
+ properties: {}
1202
1218
  };
1203
1219
  function createToolSchema(tool) {
1204
1220
  if (!tool.parameters) {
1205
- return EMPTY_TOOL_SCHEMA;
1221
+ return { ...EMPTY_TOOL_SCHEMA };
1206
1222
  }
1207
1223
  const rawSchema = zodToJsonSchema(tool.parameters, {
1208
1224
  $refStrategy: "none"
@@ -1217,11 +1233,25 @@ function createToolSchema(tool) {
1217
1233
  if (typeof schema.properties !== "object" || schema.properties === null) {
1218
1234
  schema.properties = {};
1219
1235
  }
1220
- if (schema.additionalProperties === void 0) {
1221
- schema.additionalProperties = false;
1222
- }
1236
+ stripAdditionalProperties(schema);
1223
1237
  return schema;
1224
1238
  }
1239
+ function stripAdditionalProperties(schema) {
1240
+ if (!schema || typeof schema !== "object") {
1241
+ return;
1242
+ }
1243
+ if (Array.isArray(schema)) {
1244
+ schema.forEach(stripAdditionalProperties);
1245
+ return;
1246
+ }
1247
+ const record = schema;
1248
+ if (record.additionalProperties !== void 0) {
1249
+ delete record.additionalProperties;
1250
+ }
1251
+ for (const value of Object.values(record)) {
1252
+ stripAdditionalProperties(value);
1253
+ }
1254
+ }
1225
1255
 
1226
1256
  // src/core/state-manager.ts
1227
1257
  var StateManager = class {
@@ -1617,13 +1647,12 @@ var CopilotKitCore = class {
1617
1647
  */
1618
1648
  subscribe(subscriber) {
1619
1649
  this.subscribers.add(subscriber);
1620
- return () => {
1621
- this.unsubscribe(subscriber);
1650
+ return {
1651
+ unsubscribe: () => {
1652
+ this.subscribers.delete(subscriber);
1653
+ }
1622
1654
  };
1623
1655
  }
1624
- unsubscribe(subscriber) {
1625
- this.subscribers.delete(subscriber);
1626
- }
1627
1656
  /**
1628
1657
  * Agent connectivity (delegated to RunHandler)
1629
1658
  */
@@ -1879,7 +1908,17 @@ ${indent}${fence}`;
1879
1908
  }
1880
1909
  return result;
1881
1910
  }
1882
-
1883
- export { AgentRegistry, ContextStore, CopilotKitCore, CopilotKitCoreErrorCode, CopilotKitCoreRuntimeConnectionStatus, ProxiedCopilotRuntimeAgent, RunHandler, StateManager, SuggestionEngine, ToolCallStatus, completePartialMarkdown };
1884
- //# sourceMappingURL=index.mjs.map
1911
+ export {
1912
+ AgentRegistry,
1913
+ ContextStore,
1914
+ CopilotKitCore,
1915
+ CopilotKitCoreErrorCode,
1916
+ CopilotKitCoreRuntimeConnectionStatus,
1917
+ ProxiedCopilotRuntimeAgent,
1918
+ RunHandler,
1919
+ StateManager,
1920
+ SuggestionEngine,
1921
+ ToolCallStatus,
1922
+ completePartialMarkdown
1923
+ };
1885
1924
  //# sourceMappingURL=index.mjs.map