@inkeep/agents-core 0.29.11 → 0.30.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.
@@ -675,6 +675,7 @@ var ProjectApiUpdateSchema = ProjectUpdateSchema.omit({ tenantId: true }).openap
675
675
  var FullProjectDefinitionSchema = ProjectApiInsertSchema.extend({
676
676
  agents: z.record(z.string(), AgentWithinContextOfProjectSchema),
677
677
  tools: z.record(z.string(), ToolApiInsertSchema),
678
+ functionTools: z.record(z.string(), FunctionToolApiInsertSchema).optional(),
678
679
  functions: z.record(z.string(), FunctionApiInsertSchema).optional(),
679
680
  dataComponents: z.record(z.string(), DataComponentApiInsertSchema).optional(),
680
681
  artifactComponents: z.record(z.string(), ArtifactComponentApiInsertSchema).optional(),
@@ -1,6 +1,51 @@
1
- import { AgentWithinContextOfProjectSchema, resourceIdSchema, MAX_ID_LENGTH } from './chunk-C2QU7WTO.js';
1
+ import { AgentWithinContextOfProjectSchema, resourceIdSchema, MAX_ID_LENGTH } from './chunk-37BY2EHU.js';
2
2
  import { z } from 'zod';
3
3
 
4
+ // src/validation/cycleDetection.ts
5
+ function detectDelegationCycles(agentData) {
6
+ const graph = buildDelegationGraph(agentData);
7
+ const cycles = [];
8
+ const visited = /* @__PURE__ */ new Set();
9
+ const stack = /* @__PURE__ */ new Set();
10
+ const path = [];
11
+ function dfs(node) {
12
+ visited.add(node);
13
+ stack.add(node);
14
+ path.push(node);
15
+ for (const neighbor of graph.get(node) || []) {
16
+ if (!visited.has(neighbor)) {
17
+ if (dfs(neighbor)) return true;
18
+ } else if (stack.has(neighbor)) {
19
+ const cycleStart = path.indexOf(neighbor);
20
+ cycles.push(`Circular delegation detected: ${[...path.slice(cycleStart), neighbor].join(" \u2192 ")}`);
21
+ return true;
22
+ }
23
+ }
24
+ stack.delete(node);
25
+ path.pop();
26
+ return false;
27
+ }
28
+ for (const node of graph.keys()) {
29
+ if (!visited.has(node)) {
30
+ path.length = 0;
31
+ dfs(node);
32
+ }
33
+ }
34
+ return cycles;
35
+ }
36
+ function buildDelegationGraph(agentData) {
37
+ const graph = /* @__PURE__ */ new Map();
38
+ for (const [subAgentId, subAgent] of Object.entries(agentData.subAgents)) {
39
+ const delegates = subAgent.canDelegateTo?.filter(
40
+ (d) => typeof d === "string"
41
+ );
42
+ if (delegates?.length) {
43
+ graph.set(subAgentId, delegates);
44
+ }
45
+ }
46
+ return graph;
47
+ }
48
+
4
49
  // src/validation/agentFull.ts
5
50
  function validateAndTypeAgentData(data) {
6
51
  return AgentWithinContextOfProjectSchema.parse(data);
@@ -94,6 +139,10 @@ function validateAgentRelationships(agentData) {
94
139
  }
95
140
  }
96
141
  }
142
+ const cycles = detectDelegationCycles(agentData);
143
+ if (cycles.length > 0) {
144
+ errors.push(...cycles);
145
+ }
97
146
  if (errors.length > 0)
98
147
  throw new Error(`Agent relationship validation failed:
99
148
  ${errors.join("\n")}`);
@@ -290,5 +339,56 @@ function validateRender(render) {
290
339
  errors
291
340
  };
292
341
  }
342
+ var TextStartEventSchema = z.object({
343
+ type: z.literal("text-start"),
344
+ id: z.string()
345
+ });
346
+ var TextDeltaEventSchema = z.object({
347
+ type: z.literal("text-delta"),
348
+ id: z.string(),
349
+ delta: z.string()
350
+ });
351
+ var TextEndEventSchema = z.object({
352
+ type: z.literal("text-end"),
353
+ id: z.string()
354
+ });
355
+ var DataComponentStreamEventSchema = z.object({
356
+ type: z.literal("data-component"),
357
+ id: z.string(),
358
+ data: z.any()
359
+ });
360
+ var DataOperationStreamEventSchema = z.object({
361
+ type: z.literal("data-operation"),
362
+ data: z.any()
363
+ // Contains OperationEvent types (AgentInitializingEvent, CompletionEvent, etc.)
364
+ });
365
+ var DataSummaryStreamEventSchema = z.object({
366
+ type: z.literal("data-summary"),
367
+ data: z.any()
368
+ // Contains SummaryEvent from entities.ts
369
+ });
370
+ var StreamErrorEventSchema = z.object({
371
+ type: z.literal("error"),
372
+ error: z.string()
373
+ });
374
+ var StreamFinishEventSchema = z.object({
375
+ type: z.literal("finish"),
376
+ finishReason: z.string().optional(),
377
+ usage: z.object({
378
+ promptTokens: z.number().optional(),
379
+ completionTokens: z.number().optional(),
380
+ totalTokens: z.number().optional()
381
+ }).optional()
382
+ });
383
+ var StreamEventSchema = z.discriminatedUnion("type", [
384
+ TextStartEventSchema,
385
+ TextDeltaEventSchema,
386
+ TextEndEventSchema,
387
+ DataComponentStreamEventSchema,
388
+ DataOperationStreamEventSchema,
389
+ DataSummaryStreamEventSchema,
390
+ StreamErrorEventSchema,
391
+ StreamFinishEventSchema
392
+ ]);
293
393
 
294
- export { A2AMessageMetadataSchema, DataOperationDetailsSchema, DataOperationEventSchema, DelegationReturnedDataSchema, DelegationSentDataSchema, TransferDataSchema, generateIdFromName, isValidResourceId, validateAgentRelationships, validateAgentStructure, validateAndTypeAgentData, validateArtifactComponentReferences, validateDataComponentReferences, validateRender, validateSubAgentExternalAgentRelations, validateToolReferences };
394
+ export { A2AMessageMetadataSchema, DataComponentStreamEventSchema, DataOperationDetailsSchema, DataOperationEventSchema, DataOperationStreamEventSchema, DataSummaryStreamEventSchema, DelegationReturnedDataSchema, DelegationSentDataSchema, StreamErrorEventSchema, StreamEventSchema, StreamFinishEventSchema, TextDeltaEventSchema, TextEndEventSchema, TextStartEventSchema, TransferDataSchema, generateIdFromName, isValidResourceId, validateAgentRelationships, validateAgentStructure, validateAndTypeAgentData, validateArtifactComponentReferences, validateDataComponentReferences, validateRender, validateSubAgentExternalAgentRelations, validateToolReferences };
@@ -1626,6 +1626,7 @@ ProjectUpdateSchema.omit({ tenantId: true }).openapi(
1626
1626
  ProjectApiInsertSchema.extend({
1627
1627
  agents: zodOpenapi.z.record(zodOpenapi.z.string(), AgentWithinContextOfProjectSchema),
1628
1628
  tools: zodOpenapi.z.record(zodOpenapi.z.string(), ToolApiInsertSchema),
1629
+ functionTools: zodOpenapi.z.record(zodOpenapi.z.string(), FunctionToolApiInsertSchema).optional(),
1629
1630
  functions: zodOpenapi.z.record(zodOpenapi.z.string(), FunctionApiInsertSchema).optional(),
1630
1631
  dataComponents: zodOpenapi.z.record(zodOpenapi.z.string(), DataComponentApiInsertSchema).optional(),
1631
1632
  artifactComponents: zodOpenapi.z.record(zodOpenapi.z.string(), ArtifactComponentApiInsertSchema).optional(),
@@ -1,7 +1,7 @@
1
1
  export { i as ACTIVITY_NAMES, g as ACTIVITY_STATUS, f as ACTIVITY_TYPES, h as AGENT_IDS, p as AGGREGATE_OPERATORS, A as AI_OPERATIONS, j as AI_TOOL_TYPES, o as DATA_SOURCES, k as DATA_TYPES, D as DELEGATION_FROM_SUB_AGENT_ID, b as DELEGATION_ID, a as DELEGATION_TO_SUB_AGENT_ID, F as FIELD_TYPES, O as OPERATORS, m as ORDER_DIRECTIONS, P as PANEL_TYPES, q as QUERY_DEFAULTS, l as QUERY_EXPRESSIONS, Q as QUERY_FIELD_CONFIGS, n as QUERY_TYPES, R as REDUCE_OPERATIONS, e as SPAN_KEYS, S as SPAN_NAMES, T as TRANSFER_FROM_SUB_AGENT_ID, c as TRANSFER_TO_SUB_AGENT_ID, U as UNKNOWN_VALUE, d as detectAuthenticationRequired } from './auth-detection-DtO-n2WD.cjs';
2
2
  import { z } from 'zod';
3
- import { C as ConversationHistoryConfig, F as FunctionApiInsertSchema, A as ApiKeyApiUpdateSchema, a as FullAgentAgentInsertSchema } from './utility-DhRaNM5g.cjs';
4
- export { e as AgentStopWhen, b as AgentStopWhenSchema, h as CredentialStoreType, j as FunctionApiSelectSchema, k as FunctionApiUpdateSchema, i as MCPTransportType, g as ModelSettings, M as ModelSettingsSchema, d as StopWhen, S as StopWhenSchema, f as SubAgentStopWhen, c as SubAgentStopWhenSchema } from './utility-DhRaNM5g.cjs';
3
+ import { C as ConversationHistoryConfig, F as FunctionApiInsertSchema, A as ApiKeyApiUpdateSchema, a as FullAgentAgentInsertSchema } from './utility-eADYCyd-.cjs';
4
+ export { e as AgentStopWhen, b as AgentStopWhenSchema, h as CredentialStoreType, j as FunctionApiSelectSchema, k as FunctionApiUpdateSchema, i as MCPTransportType, g as ModelSettings, M as ModelSettingsSchema, d as StopWhen, S as StopWhenSchema, f as SubAgentStopWhen, c as SubAgentStopWhenSchema } from './utility-eADYCyd-.cjs';
5
5
  export { v as validatePropsAsJsonSchema } from './props-validation-BMR1qNiy.cjs';
6
6
  import 'pino';
7
7
  import 'drizzle-zod';
@@ -134,8 +134,8 @@ declare const DataComponentApiInsertSchema: z.ZodObject<{
134
134
  }, z.core.$strip>>>;
135
135
  }, z.core.$strip>;
136
136
  declare const ArtifactComponentApiInsertSchema: z.ZodObject<{
137
- name: z.ZodString;
138
137
  id: z.ZodString;
138
+ name: z.ZodString;
139
139
  description: z.ZodString;
140
140
  props: z.ZodOptional<z.ZodNullable<z.ZodType<Record<string, unknown>, Record<string, unknown>, z.core.$ZodTypeInternals<Record<string, unknown>, Record<string, unknown>>>>>;
141
141
  }, {
@@ -170,11 +170,12 @@ declare const FullAgentDefinitionSchema: z.ZodObject<{
170
170
  description: z.ZodOptional<z.ZodString>;
171
171
  defaultSubAgentId: z.ZodOptional<z.ZodString>;
172
172
  subAgents: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
173
- name: z.ZodString;
174
173
  id: z.ZodString;
174
+ name: z.ZodString;
175
+ description: z.ZodString;
176
+ prompt: z.ZodString;
175
177
  createdAt: z.ZodOptional<z.ZodString>;
176
178
  updatedAt: z.ZodOptional<z.ZodString>;
177
- description: z.ZodString;
178
179
  models: z.ZodOptional<z.ZodObject<{
179
180
  base: z.ZodOptional<z.ZodObject<{
180
181
  model: z.ZodOptional<z.ZodString>;
@@ -198,7 +199,6 @@ declare const FullAgentDefinitionSchema: z.ZodObject<{
198
199
  }, {
199
200
  stepCountIs?: number | undefined;
200
201
  }>>>>;
201
- prompt: z.ZodString;
202
202
  conversationHistoryConfig: z.ZodOptional<z.ZodNullable<z.ZodType<ConversationHistoryConfig, ConversationHistoryConfig, z.core.$ZodTypeInternals<ConversationHistoryConfig, ConversationHistoryConfig>>>>;
203
203
  type: z.ZodLiteral<"internal">;
204
204
  canUse: z.ZodArray<z.ZodObject<{
@@ -1,7 +1,7 @@
1
1
  export { i as ACTIVITY_NAMES, g as ACTIVITY_STATUS, f as ACTIVITY_TYPES, h as AGENT_IDS, p as AGGREGATE_OPERATORS, A as AI_OPERATIONS, j as AI_TOOL_TYPES, o as DATA_SOURCES, k as DATA_TYPES, D as DELEGATION_FROM_SUB_AGENT_ID, b as DELEGATION_ID, a as DELEGATION_TO_SUB_AGENT_ID, F as FIELD_TYPES, O as OPERATORS, m as ORDER_DIRECTIONS, P as PANEL_TYPES, q as QUERY_DEFAULTS, l as QUERY_EXPRESSIONS, Q as QUERY_FIELD_CONFIGS, n as QUERY_TYPES, R as REDUCE_OPERATIONS, e as SPAN_KEYS, S as SPAN_NAMES, T as TRANSFER_FROM_SUB_AGENT_ID, c as TRANSFER_TO_SUB_AGENT_ID, U as UNKNOWN_VALUE, d as detectAuthenticationRequired } from './auth-detection-DtO-n2WD.js';
2
2
  import { z } from 'zod';
3
- import { C as ConversationHistoryConfig, F as FunctionApiInsertSchema, A as ApiKeyApiUpdateSchema, a as FullAgentAgentInsertSchema } from './utility-DhRaNM5g.js';
4
- export { e as AgentStopWhen, b as AgentStopWhenSchema, h as CredentialStoreType, j as FunctionApiSelectSchema, k as FunctionApiUpdateSchema, i as MCPTransportType, g as ModelSettings, M as ModelSettingsSchema, d as StopWhen, S as StopWhenSchema, f as SubAgentStopWhen, c as SubAgentStopWhenSchema } from './utility-DhRaNM5g.js';
3
+ import { C as ConversationHistoryConfig, F as FunctionApiInsertSchema, A as ApiKeyApiUpdateSchema, a as FullAgentAgentInsertSchema } from './utility-eADYCyd-.js';
4
+ export { e as AgentStopWhen, b as AgentStopWhenSchema, h as CredentialStoreType, j as FunctionApiSelectSchema, k as FunctionApiUpdateSchema, i as MCPTransportType, g as ModelSettings, M as ModelSettingsSchema, d as StopWhen, S as StopWhenSchema, f as SubAgentStopWhen, c as SubAgentStopWhenSchema } from './utility-eADYCyd-.js';
5
5
  export { v as validatePropsAsJsonSchema } from './props-validation-BMR1qNiy.js';
6
6
  import 'pino';
7
7
  import 'drizzle-zod';
@@ -134,8 +134,8 @@ declare const DataComponentApiInsertSchema: z.ZodObject<{
134
134
  }, z.core.$strip>>>;
135
135
  }, z.core.$strip>;
136
136
  declare const ArtifactComponentApiInsertSchema: z.ZodObject<{
137
- name: z.ZodString;
138
137
  id: z.ZodString;
138
+ name: z.ZodString;
139
139
  description: z.ZodString;
140
140
  props: z.ZodOptional<z.ZodNullable<z.ZodType<Record<string, unknown>, Record<string, unknown>, z.core.$ZodTypeInternals<Record<string, unknown>, Record<string, unknown>>>>>;
141
141
  }, {
@@ -170,11 +170,12 @@ declare const FullAgentDefinitionSchema: z.ZodObject<{
170
170
  description: z.ZodOptional<z.ZodString>;
171
171
  defaultSubAgentId: z.ZodOptional<z.ZodString>;
172
172
  subAgents: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
173
- name: z.ZodString;
174
173
  id: z.ZodString;
174
+ name: z.ZodString;
175
+ description: z.ZodString;
176
+ prompt: z.ZodString;
175
177
  createdAt: z.ZodOptional<z.ZodString>;
176
178
  updatedAt: z.ZodOptional<z.ZodString>;
177
- description: z.ZodString;
178
179
  models: z.ZodOptional<z.ZodObject<{
179
180
  base: z.ZodOptional<z.ZodObject<{
180
181
  model: z.ZodOptional<z.ZodString>;
@@ -198,7 +199,6 @@ declare const FullAgentDefinitionSchema: z.ZodObject<{
198
199
  }, {
199
200
  stepCountIs?: number | undefined;
200
201
  }>>>>;
201
- prompt: z.ZodString;
202
202
  conversationHistoryConfig: z.ZodOptional<z.ZodNullable<z.ZodType<ConversationHistoryConfig, ConversationHistoryConfig, z.core.$ZodTypeInternals<ConversationHistoryConfig, ConversationHistoryConfig>>>>;
203
203
  type: z.ZodLiteral<"internal">;
204
204
  canUse: z.ZodArray<z.ZodObject<{
@@ -1,6 +1,6 @@
1
1
  export { ACTIVITY_NAMES, ACTIVITY_STATUS, ACTIVITY_TYPES, AGENT_IDS, AGGREGATE_OPERATORS, AI_OPERATIONS, AI_TOOL_TYPES, DATA_SOURCES, DATA_TYPES, DELEGATION_FROM_SUB_AGENT_ID, DELEGATION_ID, DELEGATION_TO_SUB_AGENT_ID, FIELD_TYPES, OPERATORS, ORDER_DIRECTIONS, PANEL_TYPES, QUERY_DEFAULTS, QUERY_EXPRESSIONS, QUERY_FIELD_CONFIGS, QUERY_TYPES, REDUCE_OPERATIONS, SPAN_KEYS, SPAN_NAMES, TRANSFER_FROM_SUB_AGENT_ID, TRANSFER_TO_SUB_AGENT_ID, UNKNOWN_VALUE, detectAuthenticationRequired } from './chunk-FGRAVXBC.js';
2
- import { ModelSettingsSchema, FullAgentAgentInsertSchema, ArtifactComponentApiInsertSchema } from './chunk-C2QU7WTO.js';
3
- export { AgentStopWhenSchema, FunctionApiInsertSchema, FunctionApiSelectSchema, FunctionApiUpdateSchema, ModelSettingsSchema, StopWhenSchema, SubAgentStopWhenSchema, validatePropsAsJsonSchema } from './chunk-C2QU7WTO.js';
2
+ import { ModelSettingsSchema, FullAgentAgentInsertSchema, ArtifactComponentApiInsertSchema } from './chunk-37BY2EHU.js';
3
+ export { AgentStopWhenSchema, FunctionApiInsertSchema, FunctionApiSelectSchema, FunctionApiUpdateSchema, ModelSettingsSchema, StopWhenSchema, SubAgentStopWhenSchema, validatePropsAsJsonSchema } from './chunk-37BY2EHU.js';
4
4
  import { CredentialStoreType } from './chunk-YFHT5M2R.js';
5
5
  export { CredentialStoreType, MCPTransportType } from './chunk-YFHT5M2R.js';
6
6
  import { z } from 'zod';
@@ -1,7 +1,7 @@
1
1
  import 'drizzle-orm';
2
2
  import 'drizzle-orm/sqlite-core';
3
- import '../utility-DhRaNM5g.cjs';
4
- export { G as agentRelations, J as agentToolRelationsRelations, a as agents, y as apiKeys, I as apiKeysRelations, j as artifactComponents, O as artifactComponentsRelations, b as contextCache, E as contextCacheRelations, c as contextConfigs, D as contextConfigsRelations, v as conversations, M as conversationsRelations, z as credentialReferences, K as credentialReferencesRelations, h as dataComponents, Q as dataComponentsRelations, f as externalAgents, H as externalAgentsRelations, m as functionTools, V as functionToolsRelations, n as functions, T as functionsRelations, x as ledgerArtifacts, S as ledgerArtifactsRelations, w as messages, N as messagesRelations, p as projects, B as projectsRelations, k as subAgentArtifactComponents, P as subAgentArtifactComponentsRelations, i as subAgentDataComponents, R as subAgentDataComponentsRelations, q as subAgentExternalAgentRelations, X as subAgentExternalAgentRelationsRelations, u as subAgentFunctionToolRelations, W as subAgentFunctionToolRelationsRelations, e as subAgentRelations, U as subAgentRelationsRelations, r as subAgentTeamAgentRelations, Y as subAgentTeamAgentRelationsRelations, o as subAgentToolRelations, d as subAgents, F as subAgentsRelations, g as taskRelations, C as taskRelationsRelations, t as tasks, A as tasksRelations, l as tools, L as toolsRelations } from '../schema-BiOhaqXf.cjs';
3
+ import '../utility-eADYCyd-.cjs';
4
+ export { G as agentRelations, J as agentToolRelationsRelations, a as agents, y as apiKeys, I as apiKeysRelations, j as artifactComponents, O as artifactComponentsRelations, b as contextCache, E as contextCacheRelations, c as contextConfigs, D as contextConfigsRelations, v as conversations, M as conversationsRelations, z as credentialReferences, K as credentialReferencesRelations, h as dataComponents, Q as dataComponentsRelations, f as externalAgents, H as externalAgentsRelations, m as functionTools, V as functionToolsRelations, n as functions, T as functionsRelations, x as ledgerArtifacts, S as ledgerArtifactsRelations, w as messages, N as messagesRelations, p as projects, B as projectsRelations, k as subAgentArtifactComponents, P as subAgentArtifactComponentsRelations, i as subAgentDataComponents, R as subAgentDataComponentsRelations, q as subAgentExternalAgentRelations, X as subAgentExternalAgentRelationsRelations, u as subAgentFunctionToolRelations, W as subAgentFunctionToolRelationsRelations, e as subAgentRelations, U as subAgentRelationsRelations, r as subAgentTeamAgentRelations, Y as subAgentTeamAgentRelationsRelations, o as subAgentToolRelations, d as subAgents, F as subAgentsRelations, g as taskRelations, C as taskRelationsRelations, t as tasks, A as tasksRelations, l as tools, L as toolsRelations } from '../schema-DgEdaA4i.cjs';
5
5
  import 'zod';
6
6
  import 'drizzle-zod';
7
7
  import '@hono/zod-openapi';
@@ -1,7 +1,7 @@
1
1
  import 'drizzle-orm';
2
2
  import 'drizzle-orm/sqlite-core';
3
- import '../utility-DhRaNM5g.js';
4
- export { G as agentRelations, J as agentToolRelationsRelations, a as agents, y as apiKeys, I as apiKeysRelations, j as artifactComponents, O as artifactComponentsRelations, b as contextCache, E as contextCacheRelations, c as contextConfigs, D as contextConfigsRelations, v as conversations, M as conversationsRelations, z as credentialReferences, K as credentialReferencesRelations, h as dataComponents, Q as dataComponentsRelations, f as externalAgents, H as externalAgentsRelations, m as functionTools, V as functionToolsRelations, n as functions, T as functionsRelations, x as ledgerArtifacts, S as ledgerArtifactsRelations, w as messages, N as messagesRelations, p as projects, B as projectsRelations, k as subAgentArtifactComponents, P as subAgentArtifactComponentsRelations, i as subAgentDataComponents, R as subAgentDataComponentsRelations, q as subAgentExternalAgentRelations, X as subAgentExternalAgentRelationsRelations, u as subAgentFunctionToolRelations, W as subAgentFunctionToolRelationsRelations, e as subAgentRelations, U as subAgentRelationsRelations, r as subAgentTeamAgentRelations, Y as subAgentTeamAgentRelationsRelations, o as subAgentToolRelations, d as subAgents, F as subAgentsRelations, g as taskRelations, C as taskRelationsRelations, t as tasks, A as tasksRelations, l as tools, L as toolsRelations } from '../schema-B7LgU7Uc.js';
3
+ import '../utility-eADYCyd-.js';
4
+ export { G as agentRelations, J as agentToolRelationsRelations, a as agents, y as apiKeys, I as apiKeysRelations, j as artifactComponents, O as artifactComponentsRelations, b as contextCache, E as contextCacheRelations, c as contextConfigs, D as contextConfigsRelations, v as conversations, M as conversationsRelations, z as credentialReferences, K as credentialReferencesRelations, h as dataComponents, Q as dataComponentsRelations, f as externalAgents, H as externalAgentsRelations, m as functionTools, V as functionToolsRelations, n as functions, T as functionsRelations, x as ledgerArtifacts, S as ledgerArtifactsRelations, w as messages, N as messagesRelations, p as projects, B as projectsRelations, k as subAgentArtifactComponents, P as subAgentArtifactComponentsRelations, i as subAgentDataComponents, R as subAgentDataComponentsRelations, q as subAgentExternalAgentRelations, X as subAgentExternalAgentRelationsRelations, u as subAgentFunctionToolRelations, W as subAgentFunctionToolRelationsRelations, e as subAgentRelations, U as subAgentRelationsRelations, r as subAgentTeamAgentRelations, Y as subAgentTeamAgentRelationsRelations, o as subAgentToolRelations, d as subAgents, F as subAgentsRelations, g as taskRelations, C as taskRelationsRelations, t as tasks, A as tasksRelations, l as tools, L as toolsRelations } from '../schema-DfnCgRwo.js';
5
5
  import 'zod';
6
6
  import 'drizzle-zod';
7
7
  import '@hono/zod-openapi';
package/dist/index.cjs CHANGED
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var zod = require('zod');
4
- var nanoid = require('nanoid');
5
4
  var pino = require('pino');
6
5
  var pinoPretty = require('pino-pretty');
7
6
  var zodOpenapi = require('@hono/zod-openapi');
@@ -11,6 +10,7 @@ var sqliteCore = require('drizzle-orm/sqlite-core');
11
10
  var jmespath = require('jmespath');
12
11
  var client = require('@libsql/client');
13
12
  var libsql = require('drizzle-orm/libsql');
13
+ var nanoid = require('nanoid');
14
14
  var crypto = require('crypto');
15
15
  var util = require('util');
16
16
  var auth_js = require('@modelcontextprotocol/sdk/client/auth.js');
@@ -2520,7 +2520,7 @@ var require_typescript = __commonJS({
2520
2520
  affectsEmitOptionDeclarations: () => affectsEmitOptionDeclarations,
2521
2521
  allKeysStartWithDot: () => allKeysStartWithDot,
2522
2522
  altDirectorySeparator: () => altDirectorySeparator,
2523
- and: () => and22,
2523
+ and: () => and23,
2524
2524
  append: () => append,
2525
2525
  appendIfUnique: () => appendIfUnique,
2526
2526
  arrayFrom: () => arrayFrom,
@@ -5971,7 +5971,7 @@ var require_typescript = __commonJS({
5971
5971
  function isPatternMatch({ prefix, suffix }, candidate) {
5972
5972
  return candidate.length >= prefix.length + suffix.length && startsWith(candidate, prefix) && endsWith(candidate, suffix);
5973
5973
  }
5974
- function and22(f, g) {
5974
+ function and23(f, g) {
5975
5975
  return (arg) => f(arg) && g(arg);
5976
5976
  }
5977
5977
  function or(...fs2) {
@@ -56966,7 +56966,7 @@ ${lanes.join("\n")}
56966
56966
  SignatureCheckMode3[SignatureCheckMode3["Callback"] = 3] = "Callback";
56967
56967
  return SignatureCheckMode3;
56968
56968
  })(SignatureCheckMode || {});
56969
- var isNotOverloadAndNotAccessor = and22(isNotOverload, isNotAccessor);
56969
+ var isNotOverloadAndNotAccessor = and23(isNotOverload, isNotAccessor);
56970
56970
  var intrinsicTypeKinds = new Map(Object.entries({
56971
56971
  Uppercase: 0,
56972
56972
  Lowercase: 1,
@@ -99777,7 +99777,7 @@ ${lanes.join("\n")}
99777
99777
  if (flags & (1920 | 384)) {
99778
99778
  return;
99779
99779
  }
99780
- const exportedDeclarationsCount = countWhere(declarations, and22(isNotOverloadAndNotAccessor, not2(isInterfaceDeclaration)));
99780
+ const exportedDeclarationsCount = countWhere(declarations, and23(isNotOverloadAndNotAccessor, not2(isInterfaceDeclaration)));
99781
99781
  if (flags & 524288 && exportedDeclarationsCount <= 2) {
99782
99782
  return;
99783
99783
  }
@@ -170565,7 +170565,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
170565
170565
  const maybeHeritageClauseSymbol = getHeritageClauseSymbolTable(classDeclaration, checker);
170566
170566
  const implementedType = checker.getTypeAtLocation(implementedTypeNode);
170567
170567
  const implementedTypeSymbols = checker.getPropertiesOfType(implementedType);
170568
- const nonPrivateAndNotExistedInHeritageClauseMembers = implementedTypeSymbols.filter(and22(symbolPointsToNonPrivateMember, (symbol) => !maybeHeritageClauseSymbol.has(symbol.escapedName)));
170568
+ const nonPrivateAndNotExistedInHeritageClauseMembers = implementedTypeSymbols.filter(and23(symbolPointsToNonPrivateMember, (symbol) => !maybeHeritageClauseSymbol.has(symbol.escapedName)));
170569
170569
  const classType = checker.getTypeAtLocation(classDeclaration);
170570
170570
  const constructor = find(classDeclaration.members, (m) => isConstructorDeclaration(m));
170571
170571
  if (!classType.getNumberIndexType()) {
@@ -185222,8 +185222,8 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
185222
185222
  function isAmbientModuleDeclaration(node) {
185223
185223
  return node.kind === 268 && node.name.kind === 11;
185224
185224
  }
185225
- function isExternalModuleImportEquals(eq22) {
185226
- return eq22.moduleReference.kind === 284 && eq22.moduleReference.expression.kind === 11;
185225
+ function isExternalModuleImportEquals(eq23) {
185226
+ return eq23.moduleReference.kind === 284 && eq23.moduleReference.expression.kind === 11;
185227
185227
  }
185228
185228
  var DefinitionKind = /* @__PURE__ */ ((DefinitionKind2) => {
185229
185229
  DefinitionKind2[DefinitionKind2["Symbol"] = 0] = "Symbol";
@@ -197855,7 +197855,7 @@ ${options.prefix}` : "\n" : options.prefix
197855
197855
  affectsEmitOptionDeclarations: () => affectsEmitOptionDeclarations,
197856
197856
  allKeysStartWithDot: () => allKeysStartWithDot,
197857
197857
  altDirectorySeparator: () => altDirectorySeparator,
197858
- and: () => and22,
197858
+ and: () => and23,
197859
197859
  append: () => append,
197860
197860
  appendIfUnique: () => appendIfUnique,
197861
197861
  arrayFrom: () => arrayFrom,
@@ -213211,10 +213211,6 @@ var QUERY_DEFAULTS = {
213211
213211
  LIMIT_UNLIMITED: 1e10,
213212
213212
  EMPTY_GROUP_BY: []
213213
213213
  };
213214
- var generateId = nanoid.customAlphabet("abcdefghijklmnopqrstuvwxyz0123456789", 21);
213215
- function getConversationId() {
213216
- return generateId();
213217
- }
213218
213214
  var PinoLogger = class {
213219
213215
  constructor(name, config = {}) {
213220
213216
  this.name = name;
@@ -215104,6 +215100,7 @@ var ProjectApiUpdateSchema = ProjectUpdateSchema.omit({ tenantId: true }).openap
215104
215100
  var FullProjectDefinitionSchema = ProjectApiInsertSchema.extend({
215105
215101
  agents: zodOpenapi.z.record(zodOpenapi.z.string(), AgentWithinContextOfProjectSchema),
215106
215102
  tools: zodOpenapi.z.record(zodOpenapi.z.string(), ToolApiInsertSchema),
215103
+ functionTools: zodOpenapi.z.record(zodOpenapi.z.string(), FunctionToolApiInsertSchema).optional(),
215107
215104
  functions: zodOpenapi.z.record(zodOpenapi.z.string(), FunctionApiInsertSchema).optional(),
215108
215105
  dataComponents: zodOpenapi.z.record(zodOpenapi.z.string(), DataComponentApiInsertSchema).optional(),
215109
215106
  artifactComponents: zodOpenapi.z.record(zodOpenapi.z.string(), ArtifactComponentApiInsertSchema).optional(),
@@ -215322,8 +215319,11 @@ var ContextConfigBuilder = class {
215322
215319
  );
215323
215320
  }
215324
215321
  }
215322
+ if (!options.id) {
215323
+ throw new Error("contextConfig requires an explicit id field");
215324
+ }
215325
215325
  this.config = {
215326
- id: options.id || generateId(),
215326
+ id: options.id,
215327
215327
  tenantId: this.tenantId,
215328
215328
  projectId: this.projectId,
215329
215329
  headersSchema: headers2,
@@ -215945,6 +215945,55 @@ function createInMemoryDatabaseClient() {
215945
215945
  const db = createDatabaseClient({ url: ":memory:" });
215946
215946
  return db;
215947
215947
  }
215948
+ var generateId = nanoid.customAlphabet("abcdefghijklmnopqrstuvwxyz0123456789", 21);
215949
+ function getConversationId() {
215950
+ return generateId();
215951
+ }
215952
+
215953
+ // src/validation/cycleDetection.ts
215954
+ function detectDelegationCycles(agentData) {
215955
+ const graph = buildDelegationGraph(agentData);
215956
+ const cycles = [];
215957
+ const visited = /* @__PURE__ */ new Set();
215958
+ const stack = /* @__PURE__ */ new Set();
215959
+ const path2 = [];
215960
+ function dfs(node) {
215961
+ visited.add(node);
215962
+ stack.add(node);
215963
+ path2.push(node);
215964
+ for (const neighbor of graph.get(node) || []) {
215965
+ if (!visited.has(neighbor)) {
215966
+ if (dfs(neighbor)) return true;
215967
+ } else if (stack.has(neighbor)) {
215968
+ const cycleStart = path2.indexOf(neighbor);
215969
+ cycles.push(`Circular delegation detected: ${[...path2.slice(cycleStart), neighbor].join(" \u2192 ")}`);
215970
+ return true;
215971
+ }
215972
+ }
215973
+ stack.delete(node);
215974
+ path2.pop();
215975
+ return false;
215976
+ }
215977
+ for (const node of graph.keys()) {
215978
+ if (!visited.has(node)) {
215979
+ path2.length = 0;
215980
+ dfs(node);
215981
+ }
215982
+ }
215983
+ return cycles;
215984
+ }
215985
+ function buildDelegationGraph(agentData) {
215986
+ const graph = /* @__PURE__ */ new Map();
215987
+ for (const [subAgentId, subAgent] of Object.entries(agentData.subAgents)) {
215988
+ const delegates = subAgent.canDelegateTo?.filter(
215989
+ (d) => typeof d === "string"
215990
+ );
215991
+ if (delegates?.length) {
215992
+ graph.set(subAgentId, delegates);
215993
+ }
215994
+ }
215995
+ return graph;
215996
+ }
215948
215997
 
215949
215998
  // src/validation/agentFull.ts
215950
215999
  function validateAndTypeAgentData(data) {
@@ -216039,6 +216088,10 @@ function validateAgentRelationships(agentData) {
216039
216088
  }
216040
216089
  }
216041
216090
  }
216091
+ const cycles = detectDelegationCycles(agentData);
216092
+ if (cycles.length > 0) {
216093
+ errors.push(...cycles);
216094
+ }
216042
216095
  if (errors.length > 0)
216043
216096
  throw new Error(`Agent relationship validation failed:
216044
216097
  ${errors.join("\n")}`);
@@ -223945,6 +223998,7 @@ var getFullProject = (db, logger15 = defaultLogger2) => async (params) => {
223945
223998
  for (const credential of credentialReferencesList) {
223946
223999
  projectCredentialReferences[credential.id] = {
223947
224000
  id: credential.id,
224001
+ name: credential.name,
223948
224002
  type: credential.type,
223949
224003
  credentialStoreId: credential.credentialStoreId,
223950
224004
  retrievalParams: credential.retrievalParams
@@ -223960,6 +224014,39 @@ var getFullProject = (db, logger15 = defaultLogger2) => async (params) => {
223960
224014
  "Failed to retrieve credentialReferences for project"
223961
224015
  );
223962
224016
  }
224017
+ const projectFunctions = {};
224018
+ try {
224019
+ const functionToolsWithFunctions = await db.select({
224020
+ functionToolId: functionTools.id,
224021
+ functionToolName: functionTools.name,
224022
+ functionToolDescription: functionTools.description,
224023
+ functionId: functions.id,
224024
+ inputSchema: functions.inputSchema,
224025
+ executeCode: functions.executeCode,
224026
+ dependencies: functions.dependencies
224027
+ }).from(functionTools).innerJoin(functions, drizzleOrm.eq(functionTools.functionId, functions.id)).where(
224028
+ drizzleOrm.and(
224029
+ drizzleOrm.eq(functionTools.tenantId, tenantId),
224030
+ drizzleOrm.eq(functionTools.projectId, projectId)
224031
+ )
224032
+ );
224033
+ for (const item of functionToolsWithFunctions) {
224034
+ projectFunctions[item.functionToolId] = {
224035
+ id: item.functionId,
224036
+ name: item.functionToolName,
224037
+ description: item.functionToolDescription,
224038
+ inputSchema: item.inputSchema,
224039
+ executeCode: item.executeCode,
224040
+ dependencies: item.dependencies
224041
+ };
224042
+ }
224043
+ logger15.info(
224044
+ { tenantId, projectId, functionCount: Object.keys(projectFunctions).length },
224045
+ "Function tools with function data retrieved for project"
224046
+ );
224047
+ } catch (error) {
224048
+ logger15.warn({ tenantId, projectId, error }, "Failed to retrieve function tools for project");
224049
+ }
223963
224050
  const agents2 = {};
223964
224051
  if (agentList.length > 0) {
223965
224052
  const agentPromises = agentList.map(async (agent) => {
@@ -224002,6 +224089,7 @@ var getFullProject = (db, logger15 = defaultLogger2) => async (params) => {
224002
224089
  stopWhen: project.stopWhen || void 0,
224003
224090
  agents: agents2,
224004
224091
  tools: projectTools,
224092
+ functions: projectFunctions,
224005
224093
  externalAgents: projectExternalAgents,
224006
224094
  dataComponents: projectDataComponents,
224007
224095
  artifactComponents: projectArtifactComponents,
@@ -226373,6 +226461,57 @@ function generateIdFromName(name) {
226373
226461
  }
226374
226462
  return truncatedId;
226375
226463
  }
226464
+ var TextStartEventSchema = zod.z.object({
226465
+ type: zod.z.literal("text-start"),
226466
+ id: zod.z.string()
226467
+ });
226468
+ var TextDeltaEventSchema = zod.z.object({
226469
+ type: zod.z.literal("text-delta"),
226470
+ id: zod.z.string(),
226471
+ delta: zod.z.string()
226472
+ });
226473
+ var TextEndEventSchema = zod.z.object({
226474
+ type: zod.z.literal("text-end"),
226475
+ id: zod.z.string()
226476
+ });
226477
+ var DataComponentStreamEventSchema = zod.z.object({
226478
+ type: zod.z.literal("data-component"),
226479
+ id: zod.z.string(),
226480
+ data: zod.z.any()
226481
+ });
226482
+ var DataOperationStreamEventSchema = zod.z.object({
226483
+ type: zod.z.literal("data-operation"),
226484
+ data: zod.z.any()
226485
+ // Contains OperationEvent types (AgentInitializingEvent, CompletionEvent, etc.)
226486
+ });
226487
+ var DataSummaryStreamEventSchema = zod.z.object({
226488
+ type: zod.z.literal("data-summary"),
226489
+ data: zod.z.any()
226490
+ // Contains SummaryEvent from entities.ts
226491
+ });
226492
+ var StreamErrorEventSchema = zod.z.object({
226493
+ type: zod.z.literal("error"),
226494
+ error: zod.z.string()
226495
+ });
226496
+ var StreamFinishEventSchema = zod.z.object({
226497
+ type: zod.z.literal("finish"),
226498
+ finishReason: zod.z.string().optional(),
226499
+ usage: zod.z.object({
226500
+ promptTokens: zod.z.number().optional(),
226501
+ completionTokens: zod.z.number().optional(),
226502
+ totalTokens: zod.z.number().optional()
226503
+ }).optional()
226504
+ });
226505
+ var StreamEventSchema = zod.z.discriminatedUnion("type", [
226506
+ TextStartEventSchema,
226507
+ TextDeltaEventSchema,
226508
+ TextEndEventSchema,
226509
+ DataComponentStreamEventSchema,
226510
+ DataOperationStreamEventSchema,
226511
+ DataSummaryStreamEventSchema,
226512
+ StreamErrorEventSchema,
226513
+ StreamFinishEventSchema
226514
+ ]);
226376
226515
  /*! Bundled license information:
226377
226516
 
226378
226517
  typescript/lib/typescript.js:
@@ -226480,9 +226619,12 @@ exports.DataComponentInsertSchema = DataComponentInsertSchema;
226480
226619
  exports.DataComponentListResponse = DataComponentListResponse;
226481
226620
  exports.DataComponentResponse = DataComponentResponse;
226482
226621
  exports.DataComponentSelectSchema = DataComponentSelectSchema;
226622
+ exports.DataComponentStreamEventSchema = DataComponentStreamEventSchema;
226483
226623
  exports.DataComponentUpdateSchema = DataComponentUpdateSchema;
226484
226624
  exports.DataOperationDetailsSchema = DataOperationDetailsSchema;
226485
226625
  exports.DataOperationEventSchema = DataOperationEventSchema;
226626
+ exports.DataOperationStreamEventSchema = DataOperationStreamEventSchema;
226627
+ exports.DataSummaryStreamEventSchema = DataSummaryStreamEventSchema;
226486
226628
  exports.DelegationReturnedDataSchema = DelegationReturnedDataSchema;
226487
226629
  exports.DelegationSentDataSchema = DelegationSentDataSchema;
226488
226630
  exports.ERROR_DOCS_BASE_URL = ERROR_DOCS_BASE_URL;
@@ -226581,6 +226723,9 @@ exports.SingleResponseSchema = SingleResponseSchema;
226581
226723
  exports.StatusComponentSchema = StatusComponentSchema;
226582
226724
  exports.StatusUpdateSchema = StatusUpdateSchema;
226583
226725
  exports.StopWhenSchema = StopWhenSchema;
226726
+ exports.StreamErrorEventSchema = StreamErrorEventSchema;
226727
+ exports.StreamEventSchema = StreamEventSchema;
226728
+ exports.StreamFinishEventSchema = StreamFinishEventSchema;
226584
226729
  exports.SubAgentApiInsertSchema = SubAgentApiInsertSchema;
226585
226730
  exports.SubAgentApiSelectSchema = SubAgentApiSelectSchema;
226586
226731
  exports.SubAgentApiUpdateSchema = SubAgentApiUpdateSchema;
@@ -226661,6 +226806,9 @@ exports.TenantProjectAgentSubAgentIdParamsSchema = TenantProjectAgentSubAgentIdP
226661
226806
  exports.TenantProjectAgentSubAgentParamsSchema = TenantProjectAgentSubAgentParamsSchema;
226662
226807
  exports.TenantProjectIdParamsSchema = TenantProjectIdParamsSchema;
226663
226808
  exports.TenantProjectParamsSchema = TenantProjectParamsSchema;
226809
+ exports.TextDeltaEventSchema = TextDeltaEventSchema;
226810
+ exports.TextEndEventSchema = TextEndEventSchema;
226811
+ exports.TextStartEventSchema = TextStartEventSchema;
226664
226812
  exports.ToolApiInsertSchema = ToolApiInsertSchema;
226665
226813
  exports.ToolApiSelectSchema = ToolApiSelectSchema;
226666
226814
  exports.ToolApiUpdateSchema = ToolApiUpdateSchema;