@inkeep/agents-run-api 0.0.0-dev-20250910232631

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.
Files changed (152) hide show
  1. package/LICENSE.md +49 -0
  2. package/README.md +117 -0
  3. package/dist/__tests__/setup.d.ts +4 -0
  4. package/dist/__tests__/setup.d.ts.map +1 -0
  5. package/dist/__tests__/setup.js +80 -0
  6. package/dist/__tests__/utils/testProject.d.ts +18 -0
  7. package/dist/__tests__/utils/testProject.d.ts.map +1 -0
  8. package/dist/__tests__/utils/testProject.js +26 -0
  9. package/dist/__tests__/utils/testRequest.d.ts +8 -0
  10. package/dist/__tests__/utils/testRequest.d.ts.map +1 -0
  11. package/dist/__tests__/utils/testRequest.js +32 -0
  12. package/dist/__tests__/utils/testTenant.d.ts +64 -0
  13. package/dist/__tests__/utils/testTenant.d.ts.map +1 -0
  14. package/dist/__tests__/utils/testTenant.js +71 -0
  15. package/dist/a2a/client.d.ts +182 -0
  16. package/dist/a2a/client.d.ts.map +1 -0
  17. package/dist/a2a/client.js +645 -0
  18. package/dist/a2a/handlers.d.ts +4 -0
  19. package/dist/a2a/handlers.d.ts.map +1 -0
  20. package/dist/a2a/handlers.js +656 -0
  21. package/dist/a2a/transfer.d.ts +18 -0
  22. package/dist/a2a/transfer.d.ts.map +1 -0
  23. package/dist/a2a/transfer.js +22 -0
  24. package/dist/a2a/types.d.ts +63 -0
  25. package/dist/a2a/types.d.ts.map +1 -0
  26. package/dist/a2a/types.js +1 -0
  27. package/dist/agents/Agent.d.ts +151 -0
  28. package/dist/agents/Agent.d.ts.map +1 -0
  29. package/dist/agents/Agent.js +1164 -0
  30. package/dist/agents/ModelFactory.d.ts +62 -0
  31. package/dist/agents/ModelFactory.d.ts.map +1 -0
  32. package/dist/agents/ModelFactory.js +208 -0
  33. package/dist/agents/SystemPromptBuilder.d.ts +14 -0
  34. package/dist/agents/SystemPromptBuilder.d.ts.map +1 -0
  35. package/dist/agents/SystemPromptBuilder.js +62 -0
  36. package/dist/agents/ToolSessionManager.d.ts +53 -0
  37. package/dist/agents/ToolSessionManager.d.ts.map +1 -0
  38. package/dist/agents/ToolSessionManager.js +106 -0
  39. package/dist/agents/artifactTools.d.ts +30 -0
  40. package/dist/agents/artifactTools.d.ts.map +1 -0
  41. package/dist/agents/artifactTools.js +463 -0
  42. package/dist/agents/generateTaskHandler.d.ts +41 -0
  43. package/dist/agents/generateTaskHandler.d.ts.map +1 -0
  44. package/dist/agents/generateTaskHandler.js +350 -0
  45. package/dist/agents/relationTools.d.ts +35 -0
  46. package/dist/agents/relationTools.d.ts.map +1 -0
  47. package/dist/agents/relationTools.js +246 -0
  48. package/dist/agents/types.d.ts +23 -0
  49. package/dist/agents/types.d.ts.map +1 -0
  50. package/dist/agents/types.js +1 -0
  51. package/dist/agents/versions/V1Config.d.ts +21 -0
  52. package/dist/agents/versions/V1Config.d.ts.map +1 -0
  53. package/dist/agents/versions/V1Config.js +285 -0
  54. package/dist/app.d.ts +5 -0
  55. package/dist/app.d.ts.map +1 -0
  56. package/dist/app.js +219 -0
  57. package/dist/data/agentGraph.d.ts +4 -0
  58. package/dist/data/agentGraph.d.ts.map +1 -0
  59. package/dist/data/agentGraph.js +73 -0
  60. package/dist/data/agents.d.ts +4 -0
  61. package/dist/data/agents.d.ts.map +1 -0
  62. package/dist/data/agents.js +78 -0
  63. package/dist/data/conversations.d.ts +59 -0
  64. package/dist/data/conversations.d.ts.map +1 -0
  65. package/dist/data/conversations.js +216 -0
  66. package/dist/data/db/clean.d.ts +6 -0
  67. package/dist/data/db/clean.d.ts.map +1 -0
  68. package/dist/data/db/clean.js +77 -0
  69. package/dist/data/db/dbClient.d.ts +3 -0
  70. package/dist/data/db/dbClient.d.ts.map +1 -0
  71. package/dist/data/db/dbClient.js +13 -0
  72. package/dist/env.d.ts +45 -0
  73. package/dist/env.d.ts.map +1 -0
  74. package/dist/env.js +64 -0
  75. package/dist/handlers/executionHandler.d.ts +36 -0
  76. package/dist/handlers/executionHandler.d.ts.map +1 -0
  77. package/dist/handlers/executionHandler.js +415 -0
  78. package/dist/index.d.ts +11 -0
  79. package/dist/index.d.ts.map +1 -0
  80. package/dist/index.js +28 -0
  81. package/dist/instrumentation.d.ts +13 -0
  82. package/dist/instrumentation.d.ts.map +1 -0
  83. package/dist/instrumentation.js +66 -0
  84. package/dist/logger.d.ts +4 -0
  85. package/dist/logger.d.ts.map +1 -0
  86. package/dist/logger.js +32 -0
  87. package/dist/middleware/api-key-auth.d.ts +22 -0
  88. package/dist/middleware/api-key-auth.d.ts.map +1 -0
  89. package/dist/middleware/api-key-auth.js +139 -0
  90. package/dist/middleware/index.d.ts +2 -0
  91. package/dist/middleware/index.d.ts.map +1 -0
  92. package/dist/middleware/index.js +1 -0
  93. package/dist/openapi.d.ts +2 -0
  94. package/dist/openapi.d.ts.map +1 -0
  95. package/dist/openapi.js +36 -0
  96. package/dist/routes/agents.d.ts +10 -0
  97. package/dist/routes/agents.d.ts.map +1 -0
  98. package/dist/routes/agents.js +158 -0
  99. package/dist/routes/chat.d.ts +10 -0
  100. package/dist/routes/chat.d.ts.map +1 -0
  101. package/dist/routes/chat.js +307 -0
  102. package/dist/routes/chatDataStream.d.ts +10 -0
  103. package/dist/routes/chatDataStream.d.ts.map +1 -0
  104. package/dist/routes/chatDataStream.js +185 -0
  105. package/dist/routes/mcp.d.ts +10 -0
  106. package/dist/routes/mcp.d.ts.map +1 -0
  107. package/dist/routes/mcp.js +500 -0
  108. package/dist/tracer.d.ts +24 -0
  109. package/dist/tracer.d.ts.map +1 -0
  110. package/dist/tracer.js +107 -0
  111. package/dist/types/chat.d.ts +25 -0
  112. package/dist/types/chat.d.ts.map +1 -0
  113. package/dist/types/chat.js +1 -0
  114. package/dist/types/execution-context.d.ts +14 -0
  115. package/dist/types/execution-context.d.ts.map +1 -0
  116. package/dist/types/execution-context.js +14 -0
  117. package/dist/utils/agent-operations.d.ts +93 -0
  118. package/dist/utils/agent-operations.d.ts.map +1 -0
  119. package/dist/utils/agent-operations.js +78 -0
  120. package/dist/utils/artifact-component-schema.d.ts +29 -0
  121. package/dist/utils/artifact-component-schema.d.ts.map +1 -0
  122. package/dist/utils/artifact-component-schema.js +119 -0
  123. package/dist/utils/artifact-parser.d.ts +71 -0
  124. package/dist/utils/artifact-parser.d.ts.map +1 -0
  125. package/dist/utils/artifact-parser.js +253 -0
  126. package/dist/utils/cleanup.d.ts +19 -0
  127. package/dist/utils/cleanup.d.ts.map +1 -0
  128. package/dist/utils/cleanup.js +66 -0
  129. package/dist/utils/data-component-schema.d.ts +6 -0
  130. package/dist/utils/data-component-schema.d.ts.map +1 -0
  131. package/dist/utils/data-component-schema.js +43 -0
  132. package/dist/utils/graph-session.d.ts +230 -0
  133. package/dist/utils/graph-session.d.ts.map +1 -0
  134. package/dist/utils/graph-session.js +1199 -0
  135. package/dist/utils/incremental-stream-parser.d.ts +62 -0
  136. package/dist/utils/incremental-stream-parser.d.ts.map +1 -0
  137. package/dist/utils/incremental-stream-parser.js +330 -0
  138. package/dist/utils/response-formatter.d.ts +26 -0
  139. package/dist/utils/response-formatter.d.ts.map +1 -0
  140. package/dist/utils/response-formatter.js +158 -0
  141. package/dist/utils/stream-helpers.d.ts +186 -0
  142. package/dist/utils/stream-helpers.d.ts.map +1 -0
  143. package/dist/utils/stream-helpers.js +603 -0
  144. package/dist/utils/stream-registry.d.ts +18 -0
  145. package/dist/utils/stream-registry.d.ts.map +1 -0
  146. package/dist/utils/stream-registry.js +33 -0
  147. package/package.json +95 -0
  148. package/templates/v1/artifact.xml +7 -0
  149. package/templates/v1/data-component.xml +9 -0
  150. package/templates/v1/system-prompt.xml +52 -0
  151. package/templates/v1/thinking-preparation.xml +34 -0
  152. package/templates/v1/tool.xml +12 -0
package/LICENSE.md ADDED
@@ -0,0 +1,49 @@
1
+ # Inkeep SDK – Elastic License 2.0 with Supplemental Terms
2
+
3
+ NOTE: The Inkeep SDK is licensed under the Elastic License 2.0 (ELv2), subject to Supplemental Terms included in [SUPPLEMENTAL_TERMS.md](SUPPLEMENTAL_TERMS.md). In the event of conflict, the Supplemental Terms control.
4
+
5
+ # Elastic License 2.0
6
+
7
+ ## Acceptance
8
+ By using the software, you agree to all of the terms and conditions below.
9
+
10
+ ## Copyright License
11
+ The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below.
12
+
13
+ ## Limitations
14
+ You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
15
+
16
+ You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
17
+
18
+ You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
19
+
20
+ ## Patents
21
+ The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
22
+
23
+ ## Notices
24
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
25
+
26
+ If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
27
+
28
+ ## No Other Rights
29
+ These terms do not imply any licenses other than those expressly granted in these terms.
30
+
31
+ ## Termination
32
+ If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
33
+
34
+ ## No Liability
35
+ ***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
36
+
37
+ ## Definitions
38
+ The **licensor** is the entity offering these terms, and the **software** is the software the licensor makes available under these terms, including any portion of it.
39
+
40
+ **you** refers to the individual or entity agreeing to these terms.
41
+
42
+ **your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
43
+
44
+ **your licenses** are all the licenses granted to you for the software under these terms.
45
+
46
+ **use** means anything you do with the software requiring one of your licenses.
47
+
48
+ **trademark** means trademarks, service marks, and similar rights.
49
+
package/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # Inkeep Execution API
2
+
3
+ The Execution API is responsible for runtime agent operations, including Agent-to-Agent (A2A) communication, chat completions, and MCP (Model Context Protocol) tool integrations.
4
+
5
+ ## Overview
6
+
7
+ This API handles the execution layer of the Inkeep Agent Framework:
8
+ - **A2A Communication**: JSON-RPC based agent-to-agent communication following Google's A2A specification
9
+ - **Chat Completions**: OpenAI-compatible chat API with multi-agent orchestration
10
+ - **MCP Integration**: Model Context Protocol tools and external integrations
11
+ - **Task Execution**: Real-time task processing and delegation workflows
12
+
13
+ ## Architecture
14
+
15
+ ### Core Components
16
+
17
+ - **A2A Protocol**: Agent communication via JSON-RPC methods (`tasks/send`, `tasks/get`, `tasks/cancel`)
18
+ - **Chat API**: OpenAI-compatible endpoints with agent routing and context preservation
19
+ - **MCP Tools**: Dynamic tool discovery and execution from multiple transport types (stdio, SSE, HTTP)
20
+ - **Task Management**: Hierarchical task execution with parent-child relationships
21
+
22
+ ### Key Features
23
+
24
+ - **Context Preservation**: Maintains conversation state across agent transfers and delegations
25
+ - **Multi-Agent Orchestration**: Hub-and-spoke and graph-based agent networks
26
+ - **Real-time Communication**: WebSocket and HTTP-based agent interactions
27
+ - **Tool Health Monitoring**: Automated health checks for external MCP tools
28
+
29
+ ## Development
30
+
31
+ ### Setup
32
+ If you do not have the db setup:
33
+ ```bash
34
+ cd packages/core
35
+ pnpm db:push
36
+ ```
37
+
38
+ Then:
39
+ ```bash
40
+ cd agents-run-api
41
+ pnpm install
42
+ ```
43
+
44
+
45
+ ### Environment Variables
46
+ ```env
47
+ ENVIRONMENT=development|production|test
48
+ PORT=3003
49
+ DB_FILE_NAME=path/to/sqlite.db
50
+ ANTHROPIC_API_KEY=required
51
+ OPENAI_API_KEY=optional
52
+ LOG_LEVEL=debug|info|warn|error
53
+ ```
54
+
55
+ ### Development Commands
56
+ ```bash
57
+ pnpm dev # Start development server
58
+ pnpm test # Run test suite
59
+ pnpm test:coverage # Run tests with coverage
60
+ pnpm build # Build for production
61
+ pnpm lint # Run linting
62
+ pnpm format # Format code
63
+ ```
64
+
65
+ ### Testing
66
+ All tests are located in `src/__tests__/` and use Vitest with 60-second timeouts for A2A interactions.
67
+
68
+ ```bash
69
+ pnpm test # Run all tests
70
+ pnpm test:coverage # Run with coverage report
71
+ pnpm test src/__tests__/a2a/ # Run A2A-specific tests
72
+ ```
73
+
74
+ ## Configuration
75
+
76
+ The API uses environment-based configuration with defaults for local development. Key configuration areas:
77
+
78
+ - **Database**: SQLite connection via `DB_FILE_NAME`
79
+ - **AI Models**: Anthropic and OpenAI API keys
80
+ - **Observability**: OpenTelemetry tracing support
81
+ - **CORS**: Configurable for web clients
82
+
83
+ ## Integration
84
+
85
+ ### With Management API
86
+ The Execution API reads agent configurations and relationships created by the Management API but doesn't modify them during runtime.
87
+
88
+ ### With MCP Tools
89
+ Supports multiple MCP transport types:
90
+ - **stdio**: Local process-based tools
91
+ - **SSE**: Server-sent events for streaming tools
92
+ - **HTTP**: REST-based tool integrations
93
+
94
+ ### With Agent Builder
95
+ Provides runtime execution for agents configured via the Agent Builder UI.
96
+
97
+ ## Observability
98
+
99
+ - **Structured Logging**: JSON-formatted logs with correlation IDs
100
+ - **OpenTelemetry**: Distributed tracing for agent interactions
101
+ - **Health Checks**: Endpoint monitoring and tool availability
102
+ - **Performance Metrics**: Request timing and success rates
103
+
104
+ ## Error Handling
105
+
106
+ The API implements comprehensive error handling:
107
+ - **Validation Errors**: Request schema validation
108
+ - **Agent Errors**: Agent execution failures and timeouts
109
+ - **Tool Errors**: MCP tool failures and recovery
110
+ - **Network Errors**: Resilient communication patterns
111
+
112
+ ## Security
113
+
114
+ - **API Key Authentication**: Configurable authentication methods
115
+ - **Input Validation**: Request sanitization and type checking
116
+ - **CORS**: Configurable cross-origin policies
117
+ - **Rate Limiting**: Configurable request throttling
@@ -0,0 +1,4 @@
1
+ import { NodeSDK } from '@opentelemetry/sdk-node';
2
+ declare const sdk: NodeSDK;
3
+ export { sdk };
4
+ //# sourceMappingURL=setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/__tests__/setup.ts"],"names":[],"mappings":"AAqCA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAYlD,QAAA,MAAM,GAAG,SAgBP,CAAC;AA6BH,OAAO,EAAE,GAAG,EAAE,CAAC"}
@@ -0,0 +1,80 @@
1
+ import { vi } from 'vitest';
2
+ // Mock the local logger module globally - this will be hoisted automatically by Vitest
3
+ vi.mock('../logger.js', () => {
4
+ const mockLogger = {
5
+ info: vi.fn(),
6
+ warn: vi.fn(),
7
+ error: vi.fn(),
8
+ debug: vi.fn(),
9
+ child: vi.fn().mockReturnThis(),
10
+ };
11
+ return {
12
+ getLogger: vi.fn(() => mockLogger),
13
+ withRequestContext: vi.fn(async (_id, fn) => await fn()),
14
+ };
15
+ });
16
+ // Also mock the agents-core logger since api-key-auth imports from there
17
+ vi.mock('@inkeep/agents-core', async (importOriginal) => {
18
+ const actual = await importOriginal();
19
+ const mockLogger = {
20
+ info: vi.fn(),
21
+ warn: vi.fn(),
22
+ error: vi.fn(),
23
+ debug: vi.fn(),
24
+ child: vi.fn().mockReturnThis(),
25
+ };
26
+ return {
27
+ ...actual,
28
+ getLogger: vi.fn(() => mockLogger),
29
+ };
30
+ });
31
+ import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
32
+ import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
33
+ import { ConsoleMetricExporter, PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
34
+ /*instrumentation.ts*/
35
+ import { NodeSDK } from '@opentelemetry/sdk-node';
36
+ const { SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base');
37
+ import { sql } from 'drizzle-orm';
38
+ import { migrate } from 'drizzle-orm/libsql/migrator';
39
+ import { afterAll, afterEach, beforeAll } from 'vitest';
40
+ import dbClient from '../data/db/dbClient';
41
+ import { getLogger } from '../logger';
42
+ getLogger('Test Setup').debug({}, 'Setting up instrumentation');
43
+ const sdk = new NodeSDK({
44
+ serviceName: 'inkeep-execution-api',
45
+ spanProcessors: [
46
+ new SimpleSpanProcessor(new OTLPTraceExporter({
47
+ // optional - default url is http://localhost:4318/v1/traces
48
+ // url: 'http://localhost:4318/v1/traces',
49
+ })),
50
+ ],
51
+ instrumentations: [getNodeAutoInstrumentations()],
52
+ // optional - default url is http://localhost:4318/v1/metrics
53
+ // url: 'http://localhost:4318/v1/metrics',
54
+ metricReader: new PeriodicExportingMetricReader({
55
+ exporter: new ConsoleMetricExporter(),
56
+ }),
57
+ });
58
+ sdk.start();
59
+ // Initialize database schema for in-memory test databases using Drizzle migrations
60
+ beforeAll(async () => {
61
+ const logger = getLogger('Test Setup');
62
+ try {
63
+ logger.debug({}, 'Applying database migrations to in-memory test database');
64
+ // Temporarily disable foreign key constraints for tests due to composite key issues
65
+ await dbClient.run(sql `PRAGMA foreign_keys = OFF`);
66
+ await migrate(dbClient, { migrationsFolder: '../packages/agents-core/drizzle' });
67
+ logger.debug({}, 'Database migrations applied successfully');
68
+ }
69
+ catch (error) {
70
+ logger.error({ error }, 'Failed to apply database migrations');
71
+ throw error;
72
+ }
73
+ });
74
+ afterEach(() => {
75
+ // Any cleanup if needed
76
+ });
77
+ afterAll(() => {
78
+ // Any final cleanup if needed
79
+ });
80
+ export { sdk };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Ensures a project exists for a given tenant ID.
3
+ * This is needed because of foreign key constraints in the database.
4
+ *
5
+ * @param tenantId - The tenant ID
6
+ * @param projectId - The project ID (defaults to 'default')
7
+ * @returns Promise that resolves when the project is created
8
+ */
9
+ export declare function ensureTestProject(tenantId: string, projectId?: string): Promise<void>;
10
+ /**
11
+ * Creates multiple test projects for a tenant.
12
+ *
13
+ * @param tenantId - The tenant ID
14
+ * @param projectIds - Array of project IDs to create
15
+ * @returns Promise that resolves when all projects are created
16
+ */
17
+ export declare function ensureTestProjects(tenantId: string, projectIds: string[]): Promise<void>;
18
+ //# sourceMappingURL=testProject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testProject.d.ts","sourceRoot":"","sources":["../../../src/__tests__/utils/testProject.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,SAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAK9F;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAE9F"}
@@ -0,0 +1,26 @@
1
+ import { sql } from 'drizzle-orm';
2
+ import dbClient from '../../data/db/dbClient';
3
+ /**
4
+ * Ensures a project exists for a given tenant ID.
5
+ * This is needed because of foreign key constraints in the database.
6
+ *
7
+ * @param tenantId - The tenant ID
8
+ * @param projectId - The project ID (defaults to 'default')
9
+ * @returns Promise that resolves when the project is created
10
+ */
11
+ export async function ensureTestProject(tenantId, projectId = 'default') {
12
+ await dbClient.run(sql `
13
+ INSERT OR IGNORE INTO projects (tenant_id, id, name, description, created_at, updated_at)
14
+ VALUES (${tenantId}, ${projectId}, ${`Test Project ${projectId}`}, ${`Test project for ${projectId}`}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
15
+ `);
16
+ }
17
+ /**
18
+ * Creates multiple test projects for a tenant.
19
+ *
20
+ * @param tenantId - The tenant ID
21
+ * @param projectIds - Array of project IDs to create
22
+ * @returns Promise that resolves when all projects are created
23
+ */
24
+ export async function ensureTestProjects(tenantId, projectIds) {
25
+ await Promise.all(projectIds.map((projectId) => ensureTestProject(tenantId, projectId)));
26
+ }
@@ -0,0 +1,8 @@
1
+ export declare const makeRequest: (url: string, options?: RequestInit) => Promise<Response>;
2
+ export declare const makeRequestWithContext: (url: string, context: {
3
+ tenantId?: string;
4
+ projectId?: string;
5
+ graphId?: string;
6
+ agentId?: string;
7
+ }, options?: RequestInit) => Promise<Response>;
8
+ //# sourceMappingURL=testRequest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testRequest.d.ts","sourceRoot":"","sources":["../../../src/__tests__/utils/testRequest.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,WAAW,GAAU,KAAK,MAAM,EAAE,UAAS,WAAgB,sBAavE,CAAC;AAGF,eAAO,MAAM,sBAAsB,GACjC,KAAK,MAAM,EACX,SAAS;IACP,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,EACD,UAAS,WAAgB,sBAe1B,CAAC"}
@@ -0,0 +1,32 @@
1
+ import app from '../../index';
2
+ // Helper function to make requests with JSON headers and test authentication
3
+ export const makeRequest = async (url, options = {}) => {
4
+ return app.request(url, {
5
+ ...options,
6
+ headers: {
7
+ 'Content-Type': 'application/json',
8
+ Authorization: 'Bearer test-api-key',
9
+ 'x-inkeep-tenant-id': 'test-tenant',
10
+ 'x-inkeep-project-id': 'default',
11
+ 'x-inkeep-graph-id': 'test-graph',
12
+ 'x-test-bypass-auth': 'true',
13
+ ...options.headers,
14
+ },
15
+ });
16
+ };
17
+ // Helper function to make requests with custom execution context
18
+ export const makeRequestWithContext = async (url, context, options = {}) => {
19
+ return app.request(url, {
20
+ ...options,
21
+ headers: {
22
+ 'Content-Type': 'application/json',
23
+ Authorization: 'Bearer test-api-key',
24
+ 'x-inkeep-tenant-id': context.tenantId || 'test-tenant',
25
+ 'x-inkeep-project-id': context.projectId || 'test-project',
26
+ 'x-inkeep-graph-id': context.graphId || 'test-graph',
27
+ 'x-test-bypass-auth': 'true',
28
+ ...(context.agentId && { 'x-inkeep-agent-id': context.agentId }),
29
+ ...options.headers,
30
+ },
31
+ });
32
+ };
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Creates a unique tenant ID for test isolation.
3
+ *
4
+ * Each test run gets its own tenant to ensure parallel tests don't interfere with each other.
5
+ * The generated tenant ID follows the format: test-tenant-{prefix}-{uuid} or test-tenant-{uuid}
6
+ *
7
+ * @param prefix - Optional prefix to include in the tenant ID (e.g., test file name)
8
+ * @returns A unique tenant ID for test isolation
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { createTestTenantId } from './utils/testTenant';
13
+ *
14
+ * describe('My test suite', () => {
15
+ * const tenantId = createTestTenantId('agents');
16
+ *
17
+ * it('should work with isolated tenant', async () => {
18
+ * // Your test code using the unique tenant ID
19
+ * console.log(tenantId); // e.g., "test-tenant-agents-123e4567-e89b-12d3-a456-426614174000"
20
+ * });
21
+ * });
22
+ * ```
23
+ */
24
+ export declare function createTestTenantId(prefix?: string): string;
25
+ /**
26
+ * Creates multiple unique tenant IDs for test isolation.
27
+ *
28
+ * Useful when you need multiple tenants in a single test.
29
+ *
30
+ * @param count - Number of tenant IDs to generate
31
+ * @param prefix - Optional prefix to include in all tenant IDs
32
+ * @returns Array of unique tenant IDs
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * import { createTestTenantIds } from './utils/testTenant';
37
+ *
38
+ * describe('Multi-tenant test suite', () => {
39
+ * const [tenantA, tenantB] = createTestTenantIds(2, 'multi-tenant');
40
+ *
41
+ * it('should handle cross-tenant operations', async () => {
42
+ * // Test operations across different tenants
43
+ * });
44
+ * });
45
+ * ```
46
+ */
47
+ export declare function createTestTenantIds(count: number, prefix?: string): string[];
48
+ /**
49
+ * Checks if a tenant ID is a test tenant.
50
+ *
51
+ * @param tenantId - The tenant ID to check
52
+ * @returns True if the tenant ID is a test tenant
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * import { isTestTenant } from './utils/testTenant';
57
+ *
58
+ * const tenantId = createTestTenantId();
59
+ * console.log(isTestTenant(tenantId)); // true
60
+ * console.log(isTestTenant('production-tenant')); // false
61
+ * ```
62
+ */
63
+ export declare function isTestTenant(tenantId: string): boolean;
64
+ //# sourceMappingURL=testTenant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testTenant.d.ts","sourceRoot":"","sources":["../../../src/__tests__/utils/testTenant.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAG1D;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAE5E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEtD"}
@@ -0,0 +1,71 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ /**
3
+ * Creates a unique tenant ID for test isolation.
4
+ *
5
+ * Each test run gets its own tenant to ensure parallel tests don't interfere with each other.
6
+ * The generated tenant ID follows the format: test-tenant-{prefix}-{uuid} or test-tenant-{uuid}
7
+ *
8
+ * @param prefix - Optional prefix to include in the tenant ID (e.g., test file name)
9
+ * @returns A unique tenant ID for test isolation
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { createTestTenantId } from './utils/testTenant';
14
+ *
15
+ * describe('My test suite', () => {
16
+ * const tenantId = createTestTenantId('agents');
17
+ *
18
+ * it('should work with isolated tenant', async () => {
19
+ * // Your test code using the unique tenant ID
20
+ * console.log(tenantId); // e.g., "test-tenant-agents-123e4567-e89b-12d3-a456-426614174000"
21
+ * });
22
+ * });
23
+ * ```
24
+ */
25
+ export function createTestTenantId(prefix) {
26
+ const uuid = randomUUID();
27
+ return prefix ? `test-tenant-${prefix}-${uuid}` : `test-tenant-${uuid}`;
28
+ }
29
+ /**
30
+ * Creates multiple unique tenant IDs for test isolation.
31
+ *
32
+ * Useful when you need multiple tenants in a single test.
33
+ *
34
+ * @param count - Number of tenant IDs to generate
35
+ * @param prefix - Optional prefix to include in all tenant IDs
36
+ * @returns Array of unique tenant IDs
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * import { createTestTenantIds } from './utils/testTenant';
41
+ *
42
+ * describe('Multi-tenant test suite', () => {
43
+ * const [tenantA, tenantB] = createTestTenantIds(2, 'multi-tenant');
44
+ *
45
+ * it('should handle cross-tenant operations', async () => {
46
+ * // Test operations across different tenants
47
+ * });
48
+ * });
49
+ * ```
50
+ */
51
+ export function createTestTenantIds(count, prefix) {
52
+ return Array.from({ length: count }, () => createTestTenantId(prefix));
53
+ }
54
+ /**
55
+ * Checks if a tenant ID is a test tenant.
56
+ *
57
+ * @param tenantId - The tenant ID to check
58
+ * @returns True if the tenant ID is a test tenant
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * import { isTestTenant } from './utils/testTenant';
63
+ *
64
+ * const tenantId = createTestTenantId();
65
+ * console.log(isTestTenant(tenantId)); // true
66
+ * console.log(isTestTenant('production-tenant')); // false
67
+ * ```
68
+ */
69
+ export function isTestTenant(tenantId) {
70
+ return tenantId.startsWith('test-tenant-');
71
+ }