@inkeep/agents-sdk 0.0.0-dev-20250912172534 → 0.0.0-dev-20250912184011

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.js CHANGED
@@ -1960,10 +1960,10 @@ var AgentGraph = class {
1960
1960
  */
1961
1961
  async getProjectModelDefaults() {
1962
1962
  try {
1963
- const project = await getProject(this.dbClient)({
1963
+ const project2 = await getProject(this.dbClient)({
1964
1964
  scopes: { tenantId: this.tenantId, projectId: this.projectId }
1965
1965
  });
1966
- return project?.models;
1966
+ return project2?.models;
1967
1967
  } catch (error) {
1968
1968
  logger7.warn(
1969
1969
  {
@@ -1981,10 +1981,10 @@ var AgentGraph = class {
1981
1981
  */
1982
1982
  async getProjectStopWhenDefaults() {
1983
1983
  try {
1984
- const project = await getProject(this.dbClient)({
1984
+ const project2 = await getProject(this.dbClient)({
1985
1985
  scopes: { tenantId: this.tenantId, projectId: this.projectId }
1986
1986
  });
1987
- return project?.stopWhen;
1987
+ return project2?.stopWhen;
1988
1988
  } catch (error) {
1989
1989
  logger7.warn(
1990
1990
  {
@@ -2481,6 +2481,511 @@ var AgentGraph = class {
2481
2481
  }
2482
2482
  }
2483
2483
  };
2484
+ var logger8 = getLogger("projectFullClient");
2485
+ async function createFullProjectViaAPI(tenantId, apiUrl, projectData) {
2486
+ logger8.info(
2487
+ {
2488
+ tenantId,
2489
+ projectId: projectData.id,
2490
+ apiUrl
2491
+ },
2492
+ "Creating full project via API"
2493
+ );
2494
+ const url = `${apiUrl}/tenants/${tenantId}/project-full`;
2495
+ const response = await fetch(url, {
2496
+ method: "POST",
2497
+ headers: {
2498
+ "Content-Type": "application/json"
2499
+ },
2500
+ body: JSON.stringify(projectData)
2501
+ });
2502
+ if (!response.ok) {
2503
+ const errorText = await response.text();
2504
+ let errorMessage = `Failed to create project: ${response.status} ${response.statusText}`;
2505
+ try {
2506
+ const errorJson = JSON.parse(errorText);
2507
+ if (errorJson.error) {
2508
+ errorMessage = errorJson.error;
2509
+ }
2510
+ } catch {
2511
+ if (errorText) {
2512
+ errorMessage = errorText;
2513
+ }
2514
+ }
2515
+ logger8.error(
2516
+ {
2517
+ status: response.status,
2518
+ error: errorMessage
2519
+ },
2520
+ "Failed to create project via API"
2521
+ );
2522
+ throw new Error(errorMessage);
2523
+ }
2524
+ const result = await response.json();
2525
+ logger8.info(
2526
+ {
2527
+ projectId: projectData.id
2528
+ },
2529
+ "Successfully created project via API"
2530
+ );
2531
+ return result.data;
2532
+ }
2533
+ async function updateFullProjectViaAPI(tenantId, apiUrl, projectId, projectData) {
2534
+ logger8.info(
2535
+ {
2536
+ tenantId,
2537
+ projectId,
2538
+ apiUrl
2539
+ },
2540
+ "Updating full project via API"
2541
+ );
2542
+ const url = `${apiUrl}/tenants/${tenantId}/project-full/${projectId}`;
2543
+ const response = await fetch(url, {
2544
+ method: "PUT",
2545
+ headers: {
2546
+ "Content-Type": "application/json"
2547
+ },
2548
+ body: JSON.stringify(projectData)
2549
+ });
2550
+ if (!response.ok) {
2551
+ const errorText = await response.text();
2552
+ let errorMessage = `Failed to update project: ${response.status} ${response.statusText}`;
2553
+ try {
2554
+ const errorJson = JSON.parse(errorText);
2555
+ if (errorJson.error) {
2556
+ errorMessage = errorJson.error;
2557
+ }
2558
+ } catch {
2559
+ if (errorText) {
2560
+ errorMessage = errorText;
2561
+ }
2562
+ }
2563
+ logger8.error(
2564
+ {
2565
+ status: response.status,
2566
+ error: errorMessage
2567
+ },
2568
+ "Failed to update project via API"
2569
+ );
2570
+ throw new Error(errorMessage);
2571
+ }
2572
+ const result = await response.json();
2573
+ logger8.info(
2574
+ {
2575
+ projectId
2576
+ },
2577
+ "Successfully updated project via API"
2578
+ );
2579
+ return result.data;
2580
+ }
2581
+ async function getFullProjectViaAPI(tenantId, apiUrl, projectId) {
2582
+ logger8.info(
2583
+ {
2584
+ tenantId,
2585
+ projectId,
2586
+ apiUrl
2587
+ },
2588
+ "Getting full project via API"
2589
+ );
2590
+ const url = `${apiUrl}/tenants/${tenantId}/project-full/${projectId}`;
2591
+ const response = await fetch(url, {
2592
+ method: "GET",
2593
+ headers: {
2594
+ "Content-Type": "application/json"
2595
+ }
2596
+ });
2597
+ if (!response.ok) {
2598
+ if (response.status === 404) {
2599
+ logger8.info(
2600
+ {
2601
+ projectId
2602
+ },
2603
+ "Project not found"
2604
+ );
2605
+ return null;
2606
+ }
2607
+ const errorText = await response.text();
2608
+ let errorMessage = `Failed to get project: ${response.status} ${response.statusText}`;
2609
+ try {
2610
+ const errorJson = JSON.parse(errorText);
2611
+ if (errorJson.error) {
2612
+ errorMessage = errorJson.error;
2613
+ }
2614
+ } catch {
2615
+ if (errorText) {
2616
+ errorMessage = errorText;
2617
+ }
2618
+ }
2619
+ logger8.error(
2620
+ {
2621
+ status: response.status,
2622
+ error: errorMessage
2623
+ },
2624
+ "Failed to get project via API"
2625
+ );
2626
+ throw new Error(errorMessage);
2627
+ }
2628
+ const result = await response.json();
2629
+ logger8.info(
2630
+ {
2631
+ projectId
2632
+ },
2633
+ "Successfully retrieved project via API"
2634
+ );
2635
+ return result.data;
2636
+ }
2637
+ async function deleteFullProjectViaAPI(tenantId, apiUrl, projectId) {
2638
+ logger8.info(
2639
+ {
2640
+ tenantId,
2641
+ projectId,
2642
+ apiUrl
2643
+ },
2644
+ "Deleting full project via API"
2645
+ );
2646
+ const url = `${apiUrl}/tenants/${tenantId}/project-full/${projectId}`;
2647
+ const response = await fetch(url, {
2648
+ method: "DELETE",
2649
+ headers: {
2650
+ "Content-Type": "application/json"
2651
+ }
2652
+ });
2653
+ if (!response.ok) {
2654
+ const errorText = await response.text();
2655
+ let errorMessage = `Failed to delete project: ${response.status} ${response.statusText}`;
2656
+ try {
2657
+ const errorJson = JSON.parse(errorText);
2658
+ if (errorJson.error) {
2659
+ errorMessage = errorJson.error;
2660
+ }
2661
+ } catch {
2662
+ if (errorText) {
2663
+ errorMessage = errorText;
2664
+ }
2665
+ }
2666
+ logger8.error(
2667
+ {
2668
+ status: response.status,
2669
+ error: errorMessage
2670
+ },
2671
+ "Failed to delete project via API"
2672
+ );
2673
+ throw new Error(errorMessage);
2674
+ }
2675
+ logger8.info(
2676
+ {
2677
+ projectId
2678
+ },
2679
+ "Successfully deleted project via API"
2680
+ );
2681
+ }
2682
+
2683
+ // src/project.ts
2684
+ var logger9 = getLogger("project");
2685
+ var Project = class {
2686
+ constructor(config) {
2687
+ __publicField(this, "projectId");
2688
+ __publicField(this, "projectName");
2689
+ __publicField(this, "projectDescription");
2690
+ __publicField(this, "tenantId");
2691
+ __publicField(this, "baseURL");
2692
+ __publicField(this, "initialized", false);
2693
+ __publicField(this, "models");
2694
+ __publicField(this, "stopWhen");
2695
+ __publicField(this, "graphs", []);
2696
+ __publicField(this, "graphMap", /* @__PURE__ */ new Map());
2697
+ this.projectId = config.id;
2698
+ this.projectName = config.name;
2699
+ this.projectDescription = config.description;
2700
+ this.tenantId = config.tenantId || "default";
2701
+ this.baseURL = process.env.INKEEP_API_URL || "http://localhost:3002";
2702
+ this.models = config.models;
2703
+ this.stopWhen = config.stopWhen;
2704
+ if (config.graphs) {
2705
+ this.graphs = config.graphs();
2706
+ this.graphMap = new Map(this.graphs.map((graph) => [graph.getId(), graph]));
2707
+ for (const graph of this.graphs) {
2708
+ graph.setConfig(this.tenantId, this.projectId, this.baseURL);
2709
+ }
2710
+ }
2711
+ logger9.info(
2712
+ {
2713
+ projectId: this.projectId,
2714
+ tenantId: this.tenantId,
2715
+ graphCount: this.graphs.length
2716
+ },
2717
+ "Project created"
2718
+ );
2719
+ }
2720
+ /**
2721
+ * Set or update the configuration (tenantId and apiUrl)
2722
+ * This is used by the CLI to inject configuration from inkeep.config.ts
2723
+ */
2724
+ setConfig(tenantId, apiUrl) {
2725
+ if (this.initialized) {
2726
+ throw new Error("Cannot set config after project has been initialized");
2727
+ }
2728
+ this.tenantId = tenantId;
2729
+ this.baseURL = apiUrl;
2730
+ for (const graph of this.graphs) {
2731
+ graph.setConfig(tenantId, this.projectId, apiUrl);
2732
+ }
2733
+ logger9.info(
2734
+ {
2735
+ projectId: this.projectId,
2736
+ tenantId: this.tenantId,
2737
+ apiUrl: this.baseURL
2738
+ },
2739
+ "Project configuration updated"
2740
+ );
2741
+ }
2742
+ /**
2743
+ * Initialize the project and create/update it in the backend using full project approach
2744
+ */
2745
+ async init() {
2746
+ if (this.initialized) {
2747
+ logger9.info({ projectId: this.projectId }, "Project already initialized");
2748
+ return;
2749
+ }
2750
+ logger9.info(
2751
+ {
2752
+ projectId: this.projectId,
2753
+ tenantId: this.tenantId,
2754
+ graphCount: this.graphs.length
2755
+ },
2756
+ "Initializing project using full project endpoint"
2757
+ );
2758
+ try {
2759
+ const initPromises = this.graphs.map(async (graph) => {
2760
+ try {
2761
+ await graph.init();
2762
+ logger9.debug(
2763
+ {
2764
+ projectId: this.projectId,
2765
+ graphId: graph.getId()
2766
+ },
2767
+ "Graph initialized in project"
2768
+ );
2769
+ } catch (error) {
2770
+ logger9.error(
2771
+ {
2772
+ projectId: this.projectId,
2773
+ graphId: graph.getId(),
2774
+ error: error instanceof Error ? error.message : "Unknown error"
2775
+ },
2776
+ "Failed to initialize graph in project"
2777
+ );
2778
+ throw error;
2779
+ }
2780
+ });
2781
+ await Promise.all(initPromises);
2782
+ const projectDefinition = await this.toFullProjectDefinition();
2783
+ logger9.info(
2784
+ {
2785
+ projectId: this.projectId,
2786
+ mode: "api-client",
2787
+ apiUrl: this.baseURL
2788
+ },
2789
+ "Using API client to create/update full project"
2790
+ );
2791
+ const createdProject = await updateFullProjectViaAPI(
2792
+ this.tenantId,
2793
+ this.baseURL,
2794
+ this.projectId,
2795
+ projectDefinition
2796
+ );
2797
+ this.initialized = true;
2798
+ logger9.info(
2799
+ {
2800
+ projectId: this.projectId,
2801
+ tenantId: this.tenantId,
2802
+ graphCount: Object.keys(createdProject.graphs || {}).length
2803
+ },
2804
+ "Project initialized successfully using full project endpoint"
2805
+ );
2806
+ } catch (error) {
2807
+ logger9.error(
2808
+ {
2809
+ projectId: this.projectId,
2810
+ error: error instanceof Error ? error.message : "Unknown error"
2811
+ },
2812
+ "Failed to initialize project using full project endpoint"
2813
+ );
2814
+ throw error;
2815
+ }
2816
+ }
2817
+ /**
2818
+ * Get the project ID
2819
+ */
2820
+ getId() {
2821
+ return this.projectId;
2822
+ }
2823
+ /**
2824
+ * Get the project name
2825
+ */
2826
+ getName() {
2827
+ return this.projectName;
2828
+ }
2829
+ /**
2830
+ * Get the project description
2831
+ */
2832
+ getDescription() {
2833
+ return this.projectDescription;
2834
+ }
2835
+ /**
2836
+ * Get the tenant ID
2837
+ */
2838
+ getTenantId() {
2839
+ return this.tenantId;
2840
+ }
2841
+ /**
2842
+ * Get the project's model configuration
2843
+ */
2844
+ getModels() {
2845
+ return this.models;
2846
+ }
2847
+ /**
2848
+ * Set the project's model configuration
2849
+ */
2850
+ setModels(models) {
2851
+ this.models = models;
2852
+ }
2853
+ /**
2854
+ * Get the project's stopWhen configuration
2855
+ */
2856
+ getStopWhen() {
2857
+ return this.stopWhen;
2858
+ }
2859
+ /**
2860
+ * Set the project's stopWhen configuration
2861
+ */
2862
+ setStopWhen(stopWhen) {
2863
+ this.stopWhen = stopWhen;
2864
+ }
2865
+ /**
2866
+ * Get all graphs in the project
2867
+ */
2868
+ getGraphs() {
2869
+ return this.graphs;
2870
+ }
2871
+ /**
2872
+ * Get a graph by ID
2873
+ */
2874
+ getGraph(id) {
2875
+ return this.graphMap.get(id);
2876
+ }
2877
+ /**
2878
+ * Add a graph to the project
2879
+ */
2880
+ addGraph(graph) {
2881
+ this.graphs.push(graph);
2882
+ this.graphMap.set(graph.getId(), graph);
2883
+ graph.setConfig(this.tenantId, this.projectId, this.baseURL);
2884
+ logger9.info(
2885
+ {
2886
+ projectId: this.projectId,
2887
+ graphId: graph.getId()
2888
+ },
2889
+ "Graph added to project"
2890
+ );
2891
+ }
2892
+ /**
2893
+ * Remove a graph from the project
2894
+ */
2895
+ removeGraph(id) {
2896
+ const graphToRemove = this.graphMap.get(id);
2897
+ if (graphToRemove) {
2898
+ this.graphMap.delete(id);
2899
+ this.graphs = this.graphs.filter((graph) => graph.getId() !== id);
2900
+ logger9.info(
2901
+ {
2902
+ projectId: this.projectId,
2903
+ graphId: id
2904
+ },
2905
+ "Graph removed from project"
2906
+ );
2907
+ return true;
2908
+ }
2909
+ return false;
2910
+ }
2911
+ /**
2912
+ * Get project statistics
2913
+ */
2914
+ getStats() {
2915
+ return {
2916
+ projectId: this.projectId,
2917
+ tenantId: this.tenantId,
2918
+ graphCount: this.graphs.length,
2919
+ initialized: this.initialized
2920
+ };
2921
+ }
2922
+ /**
2923
+ * Validate the project configuration
2924
+ */
2925
+ validate() {
2926
+ const errors = [];
2927
+ if (!this.projectId) {
2928
+ errors.push("Project must have an ID");
2929
+ }
2930
+ if (!this.projectName) {
2931
+ errors.push("Project must have a name");
2932
+ }
2933
+ const graphIds = /* @__PURE__ */ new Set();
2934
+ for (const graph of this.graphs) {
2935
+ const id = graph.getId();
2936
+ if (graphIds.has(id)) {
2937
+ errors.push(`Duplicate graph ID: ${id}`);
2938
+ }
2939
+ graphIds.add(id);
2940
+ }
2941
+ for (const graph of this.graphs) {
2942
+ const graphValidation = graph.validate();
2943
+ if (!graphValidation.valid) {
2944
+ errors.push(...graphValidation.errors.map((error) => `Graph '${graph.getId()}': ${error}`));
2945
+ }
2946
+ }
2947
+ return {
2948
+ valid: errors.length === 0,
2949
+ errors
2950
+ };
2951
+ }
2952
+ /**
2953
+ * Convert the Project to FullProjectDefinition format
2954
+ */
2955
+ async toFullProjectDefinition() {
2956
+ const graphsObject = {};
2957
+ for (const graph of this.graphs) {
2958
+ const graphDefinition = await graph.toFullGraphDefinition();
2959
+ graphsObject[graph.getId()] = graphDefinition;
2960
+ }
2961
+ return {
2962
+ id: this.projectId,
2963
+ name: this.projectName,
2964
+ description: this.projectDescription || "",
2965
+ models: this.models,
2966
+ stopWhen: this.stopWhen,
2967
+ graphs: graphsObject,
2968
+ tools: {},
2969
+ // Empty tools object as SDK doesn't manage tools directly yet
2970
+ credentialReferences: void 0,
2971
+ // Projects don't directly hold credentials yet
2972
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
2973
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
2974
+ };
2975
+ }
2976
+ /**
2977
+ * Convert project configuration to API format
2978
+ */
2979
+ toApiFormat() {
2980
+ return {
2981
+ id: this.projectId,
2982
+ name: this.projectName,
2983
+ description: this.projectDescription || "",
2984
+ models: this.models,
2985
+ stopWhen: this.stopWhen
2986
+ };
2987
+ }
2988
+ };
2484
2989
 
2485
2990
  // src/utils/generateIdFromName.ts
2486
2991
  function generateIdFromName3(name) {
@@ -2491,6 +2996,9 @@ function generateIdFromName3(name) {
2491
2996
  function agentGraph(config) {
2492
2997
  return new AgentGraph(config);
2493
2998
  }
2999
+ function project(config) {
3000
+ return new Project(config);
3001
+ }
2494
3002
  function agent(config) {
2495
3003
  if (!config.id) {
2496
3004
  throw new Error(
@@ -2619,7 +3127,7 @@ var MaxTurnsExceededError = class extends AgentError {
2619
3127
  };
2620
3128
 
2621
3129
  // src/runner.ts
2622
- var logger8 = getLogger("runner");
3130
+ var logger10 = getLogger("runner");
2623
3131
  var Runner = class _Runner {
2624
3132
  /**
2625
3133
  * Run a graph until completion, handling transfers and tool calls
@@ -2631,7 +3139,7 @@ var Runner = class _Runner {
2631
3139
  let turnCount = 0;
2632
3140
  const messageHistory = _Runner.normalizeToMessageHistory(messages);
2633
3141
  const allToolCalls = [];
2634
- logger8.info(
3142
+ logger10.info(
2635
3143
  {
2636
3144
  graphId: graph.getId(),
2637
3145
  defaultAgent: graph.getDefaultAgent()?.getName(),
@@ -2641,7 +3149,7 @@ var Runner = class _Runner {
2641
3149
  "Starting graph run"
2642
3150
  );
2643
3151
  while (turnCount < maxTurns) {
2644
- logger8.debug(
3152
+ logger10.debug(
2645
3153
  {
2646
3154
  graphId: graph.getId(),
2647
3155
  turnCount,
@@ -2651,7 +3159,7 @@ var Runner = class _Runner {
2651
3159
  );
2652
3160
  const response = await graph.generate(messageHistory, options);
2653
3161
  turnCount++;
2654
- logger8.info(
3162
+ logger10.info(
2655
3163
  {
2656
3164
  graphId: graph.getId(),
2657
3165
  turnCount,
@@ -2671,7 +3179,7 @@ var Runner = class _Runner {
2671
3179
  }
2672
3180
  };
2673
3181
  }
2674
- logger8.error(
3182
+ logger10.error(
2675
3183
  {
2676
3184
  graphId: graph.getId(),
2677
3185
  maxTurns,
@@ -2685,7 +3193,7 @@ var Runner = class _Runner {
2685
3193
  * Stream a graph's response
2686
3194
  */
2687
3195
  static async stream(graph, messages, options) {
2688
- logger8.info(
3196
+ logger10.info(
2689
3197
  {
2690
3198
  graphId: graph.getId(),
2691
3199
  defaultAgent: graph.getDefaultAgent()?.getName()
@@ -2701,7 +3209,7 @@ var Runner = class _Runner {
2701
3209
  if (graphs.length === 0) {
2702
3210
  throw new Error("No graphs provided for race");
2703
3211
  }
2704
- logger8.info(
3212
+ logger10.info(
2705
3213
  {
2706
3214
  graphCount: graphs.length,
2707
3215
  graphIds: graphs.map((g) => g.getId())
@@ -2713,7 +3221,7 @@ var Runner = class _Runner {
2713
3221
  const result2 = await _Runner.run(graph, messages, options);
2714
3222
  return { ...result2, raceIndex: index };
2715
3223
  } catch (error) {
2716
- logger8.error(
3224
+ logger10.error(
2717
3225
  {
2718
3226
  graphId: graph.getId(),
2719
3227
  error: error instanceof Error ? error.message : "Unknown error"
@@ -2724,7 +3232,7 @@ var Runner = class _Runner {
2724
3232
  }
2725
3233
  });
2726
3234
  const result = await Promise.race(promises);
2727
- logger8.info(
3235
+ logger10.info(
2728
3236
  {
2729
3237
  winningGraphId: result.graphId || "unknown",
2730
3238
  raceIndex: result.raceIndex
@@ -2798,4 +3306,4 @@ var run = Runner.run.bind(Runner);
2798
3306
  var stream = Runner.stream.bind(Runner);
2799
3307
  var raceGraphs = Runner.raceGraphs.bind(Runner);
2800
3308
 
2801
- export { Agent, ArtifactComponent, DataComponent, ExternalAgent, Runner, Tool, agent, agentGraph, agentMcp, artifactComponent, createEnvironmentSettings, credential, dataComponent, externalAgent, externalAgents, mcpServer, mcpTool, raceGraphs, registerEnvironmentSettings, run, stream, transfer };
3309
+ export { Agent, ArtifactComponent, DataComponent, ExternalAgent, Project, Runner, Tool, agent, agentGraph, agentMcp, artifactComponent, createEnvironmentSettings, createFullProjectViaAPI, credential, dataComponent, deleteFullProjectViaAPI, externalAgent, externalAgents, getFullProjectViaAPI, mcpServer, mcpTool, project, raceGraphs, registerEnvironmentSettings, run, stream, transfer, updateFullProjectViaAPI };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/agents-sdk",
3
- "version": "0.0.0-dev-20250912172534",
3
+ "version": "0.0.0-dev-20250912184011",
4
4
  "description": "Agents SDK for building and managing agents in the Inkeep Agent Framework",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -8,7 +8,7 @@
8
8
  "dependencies": {
9
9
  "nanoid": "^5.1.5",
10
10
  "zod": "^4.1.5",
11
- "@inkeep/agents-core": "^0.0.0-dev-20250912172534"
11
+ "@inkeep/agents-core": "^0.0.0-dev-20250912184011"
12
12
  },
13
13
  "devDependencies": {
14
14
  "@types/node": "^20.11.24",