@shipfox/api-integration-core 2.0.0
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/.turbo/turbo-build.log +2 -0
- package/.turbo/turbo-type$colon$emit.log +1 -0
- package/.turbo/turbo-type.log +1 -0
- package/CHANGELOG.md +264 -0
- package/LICENSE +21 -0
- package/dist/config.d.ts +9 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +29 -0
- package/dist/config.js.map +1 -0
- package/dist/core/agent-tool-selection.d.ts +15 -0
- package/dist/core/agent-tool-selection.d.ts.map +1 -0
- package/dist/core/agent-tool-selection.js +48 -0
- package/dist/core/agent-tool-selection.js.map +1 -0
- package/dist/core/entities/connection.d.ts +2 -0
- package/dist/core/entities/connection.d.ts.map +1 -0
- package/dist/core/entities/connection.js +3 -0
- package/dist/core/entities/connection.js.map +1 -0
- package/dist/core/entities/provider.d.ts +6 -0
- package/dist/core/entities/provider.d.ts.map +1 -0
- package/dist/core/entities/provider.js +3 -0
- package/dist/core/entities/provider.js.map +1 -0
- package/dist/core/errors.d.ts +29 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +40 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/providers/agent-tools.d.ts +2 -0
- package/dist/core/providers/agent-tools.d.ts.map +1 -0
- package/dist/core/providers/agent-tools.js +3 -0
- package/dist/core/providers/agent-tools.js.map +1 -0
- package/dist/core/providers/redact-checkout-spec.d.ts +9 -0
- package/dist/core/providers/redact-checkout-spec.d.ts.map +1 -0
- package/dist/core/providers/redact-checkout-spec.js +25 -0
- package/dist/core/providers/redact-checkout-spec.js.map +1 -0
- package/dist/core/providers/registry.d.ts +9 -0
- package/dist/core/providers/registry.d.ts.map +1 -0
- package/dist/core/providers/registry.js +52 -0
- package/dist/core/providers/registry.js.map +1 -0
- package/dist/core/providers/source-control.d.ts +2 -0
- package/dist/core/providers/source-control.d.ts.map +1 -0
- package/dist/core/providers/source-control.js +3 -0
- package/dist/core/providers/source-control.js.map +1 -0
- package/dist/core/source-control-service.d.ts +46 -0
- package/dist/core/source-control-service.d.ts.map +1 -0
- package/dist/core/source-control-service.js +84 -0
- package/dist/core/source-control-service.js.map +1 -0
- package/dist/db/connections.d.ts +67 -0
- package/dist/db/connections.d.ts.map +1 -0
- package/dist/db/connections.js +130 -0
- package/dist/db/connections.js.map +1 -0
- package/dist/db/db.d.ts +865 -0
- package/dist/db/db.d.ts.map +1 -0
- package/dist/db/db.js +22 -0
- package/dist/db/db.js.map +1 -0
- package/dist/db/migrations.d.ts +2 -0
- package/dist/db/migrations.d.ts.map +1 -0
- package/dist/db/migrations.js +5 -0
- package/dist/db/migrations.js.map +1 -0
- package/dist/db/schema/common.d.ts +2 -0
- package/dist/db/schema/common.d.ts.map +1 -0
- package/dist/db/schema/common.js +4 -0
- package/dist/db/schema/common.js.map +1 -0
- package/dist/db/schema/connections.d.ts +165 -0
- package/dist/db/schema/connections.d.ts.map +1 -0
- package/dist/db/schema/connections.js +37 -0
- package/dist/db/schema/connections.js.map +1 -0
- package/dist/db/schema/outbox.d.ts +195 -0
- package/dist/db/schema/outbox.d.ts.map +1 -0
- package/dist/db/schema/outbox.js +5 -0
- package/dist/db/schema/outbox.js.map +1 -0
- package/dist/db/schema/webhook-deliveries.d.ts +76 -0
- package/dist/db/schema/webhook-deliveries.d.ts.map +1 -0
- package/dist/db/schema/webhook-deliveries.js +22 -0
- package/dist/db/schema/webhook-deliveries.js.map +1 -0
- package/dist/db/webhook-deliveries.d.ts +55 -0
- package/dist/db/webhook-deliveries.d.ts.map +1 -0
- package/dist/db/webhook-deliveries.js +132 -0
- package/dist/db/webhook-deliveries.js.map +1 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +105 -0
- package/dist/index.js.map +1 -0
- package/dist/metrics/index.d.ts +2 -0
- package/dist/metrics/index.d.ts.map +1 -0
- package/dist/metrics/index.js +3 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/metrics/instance.d.ts +8 -0
- package/dist/metrics/instance.d.ts.map +1 -0
- package/dist/metrics/instance.js +17 -0
- package/dist/metrics/instance.js.map +1 -0
- package/dist/presentation/dto/integrations.d.ts +36 -0
- package/dist/presentation/dto/integrations.d.ts.map +1 -0
- package/dist/presentation/dto/integrations.js +26 -0
- package/dist/presentation/dto/integrations.js.map +1 -0
- package/dist/presentation/routes/agent-tools-gateway/audit.d.ts +24 -0
- package/dist/presentation/routes/agent-tools-gateway/audit.d.ts.map +1 -0
- package/dist/presentation/routes/agent-tools-gateway/audit.js +52 -0
- package/dist/presentation/routes/agent-tools-gateway/audit.js.map +1 -0
- package/dist/presentation/routes/agent-tools-gateway/dispatch.d.ts +7 -0
- package/dist/presentation/routes/agent-tools-gateway/dispatch.d.ts.map +1 -0
- package/dist/presentation/routes/agent-tools-gateway/dispatch.js +108 -0
- package/dist/presentation/routes/agent-tools-gateway/dispatch.js.map +1 -0
- package/dist/presentation/routes/agent-tools-gateway/index.d.ts +12 -0
- package/dist/presentation/routes/agent-tools-gateway/index.d.ts.map +1 -0
- package/dist/presentation/routes/agent-tools-gateway/index.js +46 -0
- package/dist/presentation/routes/agent-tools-gateway/index.js.map +1 -0
- package/dist/presentation/routes/agent-tools-gateway/mcp-server.d.ts +17 -0
- package/dist/presentation/routes/agent-tools-gateway/mcp-server.d.ts.map +1 -0
- package/dist/presentation/routes/agent-tools-gateway/mcp-server.js +126 -0
- package/dist/presentation/routes/agent-tools-gateway/mcp-server.js.map +1 -0
- package/dist/presentation/routes/agent-tools-gateway/resolve-authorized-tools.d.ts +37 -0
- package/dist/presentation/routes/agent-tools-gateway/resolve-authorized-tools.d.ts.map +1 -0
- package/dist/presentation/routes/agent-tools-gateway/resolve-authorized-tools.js +145 -0
- package/dist/presentation/routes/agent-tools-gateway/resolve-authorized-tools.js.map +1 -0
- package/dist/presentation/routes/errors.d.ts +2 -0
- package/dist/presentation/routes/errors.d.ts.map +1 -0
- package/dist/presentation/routes/errors.js +53 -0
- package/dist/presentation/routes/errors.js.map +1 -0
- package/dist/presentation/routes/index.d.ts +14 -0
- package/dist/presentation/routes/index.d.ts.map +1 -0
- package/dist/presentation/routes/index.js +26 -0
- package/dist/presentation/routes/index.js.map +1 -0
- package/dist/presentation/routes/list-connections.d.ts +3 -0
- package/dist/presentation/routes/list-connections.d.ts.map +1 -0
- package/dist/presentation/routes/list-connections.js +58 -0
- package/dist/presentation/routes/list-connections.js.map +1 -0
- package/dist/presentation/routes/list-providers.d.ts +3 -0
- package/dist/presentation/routes/list-providers.d.ts.map +1 -0
- package/dist/presentation/routes/list-providers.js +27 -0
- package/dist/presentation/routes/list-providers.js.map +1 -0
- package/dist/presentation/routes/list-repositories.d.ts +3 -0
- package/dist/presentation/routes/list-repositories.d.ts.map +1 -0
- package/dist/presentation/routes/list-repositories.js +41 -0
- package/dist/presentation/routes/list-repositories.js.map +1 -0
- package/dist/presentation/routes/manage-connections.d.ts +4 -0
- package/dist/presentation/routes/manage-connections.d.ts.map +1 -0
- package/dist/presentation/routes/manage-connections.js +81 -0
- package/dist/presentation/routes/manage-connections.js.map +1 -0
- package/dist/providers/connection-slug.d.ts +2 -0
- package/dist/providers/connection-slug.d.ts.map +1 -0
- package/dist/providers/connection-slug.js +19 -0
- package/dist/providers/connection-slug.js.map +1 -0
- package/dist/providers/cron.d.ts +3 -0
- package/dist/providers/cron.d.ts.map +1 -0
- package/dist/providers/cron.js +13 -0
- package/dist/providers/cron.js.map +1 -0
- package/dist/providers/gitea.d.ts +3 -0
- package/dist/providers/gitea.d.ts.map +1 -0
- package/dist/providers/gitea.js +75 -0
- package/dist/providers/gitea.js.map +1 -0
- package/dist/providers/github.d.ts +3 -0
- package/dist/providers/github.d.ts.map +1 -0
- package/dist/providers/github.js +109 -0
- package/dist/providers/github.js.map +1 -0
- package/dist/providers/linear.d.ts +3 -0
- package/dist/providers/linear.d.ts.map +1 -0
- package/dist/providers/linear.js +134 -0
- package/dist/providers/linear.js.map +1 -0
- package/dist/providers/modules.d.ts +3 -0
- package/dist/providers/modules.d.ts.map +1 -0
- package/dist/providers/modules.js +26 -0
- package/dist/providers/modules.js.map +1 -0
- package/dist/providers/sentry.d.ts +3 -0
- package/dist/providers/sentry.d.ts.map +1 -0
- package/dist/providers/sentry.js +83 -0
- package/dist/providers/sentry.js.map +1 -0
- package/dist/providers/types.d.ts +58 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +3 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/providers/webhook.d.ts +3 -0
- package/dist/providers/webhook.d.ts.map +1 -0
- package/dist/providers/webhook.js +24 -0
- package/dist/providers/webhook.js.map +1 -0
- package/dist/temporal/activities/index.d.ts +5 -0
- package/dist/temporal/activities/index.d.ts.map +1 -0
- package/dist/temporal/activities/index.js +8 -0
- package/dist/temporal/activities/index.js.map +1 -0
- package/dist/temporal/activities/prune-webhook-deliveries.d.ts +4 -0
- package/dist/temporal/activities/prune-webhook-deliveries.d.ts.map +1 -0
- package/dist/temporal/activities/prune-webhook-deliveries.js +11 -0
- package/dist/temporal/activities/prune-webhook-deliveries.js.map +1 -0
- package/dist/temporal/constants.d.ts +3 -0
- package/dist/temporal/constants.d.ts.map +1 -0
- package/dist/temporal/constants.js +4 -0
- package/dist/temporal/constants.js.map +1 -0
- package/dist/temporal/workflows/index.d.ts +2 -0
- package/dist/temporal/workflows/index.d.ts.map +1 -0
- package/dist/temporal/workflows/index.js +3 -0
- package/dist/temporal/workflows/index.js.map +1 -0
- package/dist/temporal/workflows/prune-webhook-deliveries-cron.d.ts +2 -0
- package/dist/temporal/workflows/prune-webhook-deliveries-cron.d.ts.map +1 -0
- package/dist/temporal/workflows/prune-webhook-deliveries-cron.js +14 -0
- package/dist/temporal/workflows/prune-webhook-deliveries-cron.js.map +1 -0
- package/dist/tsconfig.test.tsbuildinfo +1 -0
- package/drizzle/0000_initial.sql +41 -0
- package/drizzle/meta/0001_snapshot.json +341 -0
- package/drizzle/meta/_journal.json +13 -0
- package/drizzle.config.ts +7 -0
- package/package.json +85 -0
- package/src/config.test.ts +32 -0
- package/src/config.ts +28 -0
- package/src/core/agent-tool-selection.test.ts +137 -0
- package/src/core/agent-tool-selection.ts +80 -0
- package/src/core/entities/connection.ts +4 -0
- package/src/core/entities/provider.ts +21 -0
- package/src/core/errors.ts +55 -0
- package/src/core/providers/agent-tools.ts +10 -0
- package/src/core/providers/redact-checkout-spec.test.ts +78 -0
- package/src/core/providers/redact-checkout-spec.ts +20 -0
- package/src/core/providers/registry.test.ts +138 -0
- package/src/core/providers/registry.ts +90 -0
- package/src/core/providers/source-control.ts +17 -0
- package/src/core/source-control-service.test.ts +230 -0
- package/src/core/source-control-service.ts +161 -0
- package/src/db/connections.test.ts +296 -0
- package/src/db/connections.ts +262 -0
- package/src/db/db.ts +22 -0
- package/src/db/migrations.ts +4 -0
- package/src/db/schema/common.ts +3 -0
- package/src/db/schema/connections.ts +49 -0
- package/src/db/schema/outbox.ts +4 -0
- package/src/db/schema/webhook-deliveries.ts +19 -0
- package/src/db/webhook-deliveries.test.ts +267 -0
- package/src/db/webhook-deliveries.ts +207 -0
- package/src/index.ts +212 -0
- package/src/metrics/index.ts +1 -0
- package/src/metrics/instance.ts +35 -0
- package/src/presentation/dto/integrations.ts +39 -0
- package/src/presentation/routes/agent-tools-gateway/agent-tools-gateway.route.test.ts +371 -0
- package/src/presentation/routes/agent-tools-gateway/audit.test.ts +86 -0
- package/src/presentation/routes/agent-tools-gateway/audit.ts +90 -0
- package/src/presentation/routes/agent-tools-gateway/dispatch.ts +139 -0
- package/src/presentation/routes/agent-tools-gateway/index.ts +62 -0
- package/src/presentation/routes/agent-tools-gateway/mcp-server.test.ts +308 -0
- package/src/presentation/routes/agent-tools-gateway/mcp-server.ts +155 -0
- package/src/presentation/routes/agent-tools-gateway/resolve-authorized-tools.test.ts +181 -0
- package/src/presentation/routes/agent-tools-gateway/resolve-authorized-tools.ts +245 -0
- package/src/presentation/routes/errors.ts +63 -0
- package/src/presentation/routes/index.ts +53 -0
- package/src/presentation/routes/list-connections.test.ts +227 -0
- package/src/presentation/routes/list-connections.ts +56 -0
- package/src/presentation/routes/list-providers.test.ts +113 -0
- package/src/presentation/routes/list-providers.ts +28 -0
- package/src/presentation/routes/list-repositories.test.ts +150 -0
- package/src/presentation/routes/list-repositories.ts +47 -0
- package/src/presentation/routes/manage-connections.test.ts +125 -0
- package/src/presentation/routes/manage-connections.ts +77 -0
- package/src/providers/connection-slug.ts +19 -0
- package/src/providers/cron.ts +13 -0
- package/src/providers/gitea.ts +103 -0
- package/src/providers/github.ts +150 -0
- package/src/providers/linear.ts +179 -0
- package/src/providers/modules.test.ts +40 -0
- package/src/providers/modules.ts +32 -0
- package/src/providers/sentry.ts +113 -0
- package/src/providers/types.ts +52 -0
- package/src/providers/webhook.ts +30 -0
- package/src/temporal/activities/index.ts +7 -0
- package/src/temporal/activities/prune-webhook-deliveries.test.ts +39 -0
- package/src/temporal/activities/prune-webhook-deliveries.ts +9 -0
- package/src/temporal/constants.ts +3 -0
- package/src/temporal/workflows/index.ts +1 -0
- package/src/temporal/workflows/prune-webhook-deliveries-cron.ts +15 -0
- package/test/agent-tools-gateway-helpers.ts +210 -0
- package/test/env.ts +23 -0
- package/test/factories/connection.ts +21 -0
- package/test/globalSetup.ts +22 -0
- package/test/index.ts +1 -0
- package/test/route-utils.ts +104 -0
- package/test/setup.ts +19 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +3 -0
- package/tsconfig.test.json +8 -0
- package/vitest.config.ts +13 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import type {CallToolResult} from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
import type {
|
|
3
|
+
MaterializedAgentIntegrationConfigDto,
|
|
4
|
+
MaterializedAgentIntegrationToolConfigDto,
|
|
5
|
+
} from '@shipfox/api-agent-dto';
|
|
6
|
+
import type {LeasedJobContext} from '@shipfox/api-auth-context';
|
|
7
|
+
import type {IntegrationConnection} from '#core/entities/connection.js';
|
|
8
|
+
import type {AgentToolCatalogEntry, AgentToolsProvider} from '#core/providers/agent-tools.js';
|
|
9
|
+
import {createIntegrationProviderRegistry} from '#core/providers/registry.js';
|
|
10
|
+
|
|
11
|
+
export function leaseContext(overrides: Partial<LeasedJobContext> = {}): LeasedJobContext {
|
|
12
|
+
const now = Math.floor(Date.now() / 1000);
|
|
13
|
+
return {
|
|
14
|
+
workflowRunId: crypto.randomUUID(),
|
|
15
|
+
workflowRunAttemptId: crypto.randomUUID(),
|
|
16
|
+
jobId: crypto.randomUUID(),
|
|
17
|
+
jobExecutionId: crypto.randomUUID(),
|
|
18
|
+
projectId: crypto.randomUUID(),
|
|
19
|
+
workspaceId: crypto.randomUUID(),
|
|
20
|
+
runnerSessionId: crypto.randomUUID(),
|
|
21
|
+
currentStepId: crypto.randomUUID(),
|
|
22
|
+
currentStepAttempt: 1,
|
|
23
|
+
aud: 'runner-job-lease',
|
|
24
|
+
iat: now,
|
|
25
|
+
exp: now + 3600,
|
|
26
|
+
...overrides,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function connection(overrides: Partial<IntegrationConnection> = {}): IntegrationConnection {
|
|
31
|
+
const now = new Date();
|
|
32
|
+
return {
|
|
33
|
+
id: crypto.randomUUID(),
|
|
34
|
+
workspaceId: crypto.randomUUID(),
|
|
35
|
+
provider: 'github',
|
|
36
|
+
externalAccountId: 'installation-1',
|
|
37
|
+
slug: 'github-main',
|
|
38
|
+
displayName: 'GitHub',
|
|
39
|
+
lifecycleStatus: 'active',
|
|
40
|
+
createdAt: now,
|
|
41
|
+
updatedAt: now,
|
|
42
|
+
...overrides,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function materializedTool(
|
|
47
|
+
overrides: Partial<MaterializedAgentIntegrationToolConfigDto> = {},
|
|
48
|
+
): MaterializedAgentIntegrationToolConfigDto {
|
|
49
|
+
return {
|
|
50
|
+
id: 'issue_read',
|
|
51
|
+
sensitivity: 'read',
|
|
52
|
+
sensitive: false,
|
|
53
|
+
requiredScope: [],
|
|
54
|
+
inputSchema: {
|
|
55
|
+
type: 'object',
|
|
56
|
+
additionalProperties: false,
|
|
57
|
+
properties: {
|
|
58
|
+
method: {
|
|
59
|
+
type: 'string',
|
|
60
|
+
enum: ['get', 'get_comments', 'get_labels'],
|
|
61
|
+
},
|
|
62
|
+
owner: {type: 'string'},
|
|
63
|
+
repo: {type: 'string'},
|
|
64
|
+
issue_number: {type: 'integer'},
|
|
65
|
+
},
|
|
66
|
+
required: ['method', 'owner', 'repo', 'issue_number'],
|
|
67
|
+
oneOf: [
|
|
68
|
+
{properties: {method: {const: 'get'}}, required: ['issue_number']},
|
|
69
|
+
{properties: {method: {const: 'get_comments'}}, required: ['issue_number']},
|
|
70
|
+
{properties: {method: {const: 'get_labels'}}, required: ['issue_number']},
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
methods: [
|
|
74
|
+
{
|
|
75
|
+
id: 'get',
|
|
76
|
+
token: 'issue_read.get',
|
|
77
|
+
description: 'Get one issue.',
|
|
78
|
+
sensitivity: 'read',
|
|
79
|
+
sensitive: false,
|
|
80
|
+
requiredScope: [],
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: 'get_comments',
|
|
84
|
+
token: 'issue_read.get_comments',
|
|
85
|
+
description: 'Get issue comments.',
|
|
86
|
+
sensitivity: 'read',
|
|
87
|
+
sensitive: false,
|
|
88
|
+
requiredScope: [],
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
...overrides,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function materializedIntegration(
|
|
96
|
+
overrides: Partial<MaterializedAgentIntegrationConfigDto> = {},
|
|
97
|
+
): MaterializedAgentIntegrationConfigDto {
|
|
98
|
+
return {
|
|
99
|
+
connectionId: crypto.randomUUID(),
|
|
100
|
+
connectionSlug: 'github-main',
|
|
101
|
+
provider: 'github',
|
|
102
|
+
requiredScope: [],
|
|
103
|
+
tools: [materializedTool()],
|
|
104
|
+
...overrides,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function agentStepConfig(
|
|
109
|
+
integrations: MaterializedAgentIntegrationConfigDto[] = [materializedIntegration()],
|
|
110
|
+
): Record<string, unknown> {
|
|
111
|
+
return {
|
|
112
|
+
provider: 'openai',
|
|
113
|
+
model: 'gpt-5',
|
|
114
|
+
thinking: 'off',
|
|
115
|
+
prompt: 'Use tools',
|
|
116
|
+
integrations,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function catalogTool(overrides: Partial<AgentToolCatalogEntry> = {}): AgentToolCatalogEntry {
|
|
121
|
+
return {
|
|
122
|
+
id: 'issue_read',
|
|
123
|
+
description: 'Read issue metadata from GitHub.',
|
|
124
|
+
sensitivity: 'read',
|
|
125
|
+
sensitive: false,
|
|
126
|
+
requiredScope: [],
|
|
127
|
+
inputSchema: {type: 'object', properties: {}, additionalProperties: false},
|
|
128
|
+
outputSchema: {type: 'object', additionalProperties: true},
|
|
129
|
+
methods: [
|
|
130
|
+
{
|
|
131
|
+
id: 'get',
|
|
132
|
+
description: 'Get one issue.',
|
|
133
|
+
sensitivity: 'read',
|
|
134
|
+
sensitive: false,
|
|
135
|
+
requiredScope: [],
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
id: 'get_comments',
|
|
139
|
+
description: 'Get issue comments.',
|
|
140
|
+
sensitivity: 'read',
|
|
141
|
+
sensitive: false,
|
|
142
|
+
requiredScope: [],
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
...overrides,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface AgentToolsProviderOptions {
|
|
150
|
+
result?: CallToolResult | undefined;
|
|
151
|
+
openSessionError?: unknown;
|
|
152
|
+
callError?: unknown;
|
|
153
|
+
onOpenSession?(input: {
|
|
154
|
+
connection: IntegrationConnection;
|
|
155
|
+
tools: readonly AgentToolCatalogEntry[];
|
|
156
|
+
}): void;
|
|
157
|
+
onCall?(input: {toolId: string; arguments: Record<string, unknown>}): void;
|
|
158
|
+
onClose?(): void;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function agentToolsProvider(
|
|
162
|
+
catalog: readonly AgentToolCatalogEntry[] = [catalogTool()],
|
|
163
|
+
options: AgentToolsProviderOptions = {},
|
|
164
|
+
): AgentToolsProvider {
|
|
165
|
+
return {
|
|
166
|
+
catalog: () => catalog,
|
|
167
|
+
selectionCatalog: () => ({selectors: []}),
|
|
168
|
+
openSession: (input) => {
|
|
169
|
+
if (options.openSessionError) return Promise.reject(options.openSessionError);
|
|
170
|
+
options.onOpenSession?.({connection: input.connection, tools: input.tools});
|
|
171
|
+
return Promise.resolve({
|
|
172
|
+
call: (call) => {
|
|
173
|
+
options.onCall?.(call);
|
|
174
|
+
if (options.callError) return Promise.reject(options.callError);
|
|
175
|
+
return Promise.resolve(
|
|
176
|
+
options.result ?? {
|
|
177
|
+
content: [{type: 'text', text: 'dispatched'}],
|
|
178
|
+
structuredContent: {
|
|
179
|
+
status: 'dispatched',
|
|
180
|
+
provider: input.connection.provider,
|
|
181
|
+
connection_id: input.connection.id,
|
|
182
|
+
tool_id: call.toolId,
|
|
183
|
+
method: call.arguments.method,
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
);
|
|
187
|
+
},
|
|
188
|
+
close: () => {
|
|
189
|
+
options.onClose?.();
|
|
190
|
+
return Promise.resolve();
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function registryWithAgentTools(
|
|
198
|
+
catalog: readonly AgentToolCatalogEntry[] = [catalogTool()],
|
|
199
|
+
options: AgentToolsProviderOptions = {},
|
|
200
|
+
) {
|
|
201
|
+
return createIntegrationProviderRegistry([
|
|
202
|
+
{
|
|
203
|
+
provider: 'github',
|
|
204
|
+
displayName: 'GitHub',
|
|
205
|
+
adapters: {
|
|
206
|
+
agent_tools: agentToolsProvider(catalog, options),
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
]);
|
|
210
|
+
}
|
package/test/env.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
process.env.POSTGRES_HOST ??= 'localhost';
|
|
2
|
+
process.env.POSTGRES_PORT ??= '5432';
|
|
3
|
+
process.env.POSTGRES_USERNAME ??= 'shipfox';
|
|
4
|
+
process.env.POSTGRES_PASSWORD ??= 'password';
|
|
5
|
+
process.env.POSTGRES_DATABASE = 'api_test';
|
|
6
|
+
process.env.POSTGRES_MAX_CONNECTIONS ??= '5';
|
|
7
|
+
process.env.TZ = 'UTC';
|
|
8
|
+
process.env.GITHUB_APP_ID = '1';
|
|
9
|
+
process.env.GITHUB_APP_PRIVATE_KEY = 'test-private-key';
|
|
10
|
+
process.env.GITHUB_APP_CLIENT_ID = 'test-client-id';
|
|
11
|
+
process.env.GITHUB_APP_CLIENT_SECRET = 'test-client-secret';
|
|
12
|
+
process.env.GITHUB_APP_WEBHOOK_SECRET = 'test-webhook-secret';
|
|
13
|
+
process.env.GITHUB_APP_SLUG = 'shipfox-test';
|
|
14
|
+
process.env.GITHUB_INSTALL_STATE_SECRET = 'test-install-state-secret';
|
|
15
|
+
process.env.LINEAR_OAUTH_CLIENT_ID = 'test-client-id';
|
|
16
|
+
process.env.LINEAR_OAUTH_CLIENT_SECRET = 'test-client-secret';
|
|
17
|
+
process.env.LINEAR_WEBHOOK_SIGNING_SECRET = 'test-webhook-secret';
|
|
18
|
+
process.env.LINEAR_OAUTH_REDIRECT_URL = 'https://shipfox.example.com/integrations/linear/callback';
|
|
19
|
+
process.env.LINEAR_MCP_ENDPOINT = 'https://mcp.linear.app/mcp';
|
|
20
|
+
process.env.GITEA_BASE_URL = 'https://gitea.example.com';
|
|
21
|
+
process.env.GITEA_SERVICE_USERNAME = 'shipfox-bot';
|
|
22
|
+
process.env.GITEA_SERVICE_TOKEN = 'test-service-token';
|
|
23
|
+
process.env.GITEA_WEBHOOK_SECRET = 'test-webhook-secret';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {Factory} from 'fishery';
|
|
2
|
+
import type {IntegrationConnection} from '#core/entities/connection.js';
|
|
3
|
+
import {upsertIntegrationConnection} from '#db/connections.js';
|
|
4
|
+
|
|
5
|
+
export const integrationConnectionFactory = Factory.define<IntegrationConnection>(
|
|
6
|
+
({sequence, onCreate}) => {
|
|
7
|
+
onCreate(upsertIntegrationConnection);
|
|
8
|
+
|
|
9
|
+
return {
|
|
10
|
+
id: crypto.randomUUID(),
|
|
11
|
+
workspaceId: crypto.randomUUID(),
|
|
12
|
+
provider: 'gitea',
|
|
13
|
+
externalAccountId: `gitea-${sequence}`,
|
|
14
|
+
slug: `gitea_${sequence}`,
|
|
15
|
+
displayName: `Gitea Connection ${sequence}`,
|
|
16
|
+
lifecycleStatus: 'active',
|
|
17
|
+
createdAt: new Date(),
|
|
18
|
+
updatedAt: new Date(),
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import './env.js';
|
|
2
|
+
import {
|
|
3
|
+
db as githubDb,
|
|
4
|
+
migrationsPath as githubMigrationsPath,
|
|
5
|
+
} from '@shipfox/api-integration-github';
|
|
6
|
+
import {runMigrations} from '@shipfox/node-drizzle';
|
|
7
|
+
import {closePostgresClient, createPostgresClient} from '@shipfox/node-postgres';
|
|
8
|
+
import {sql} from 'drizzle-orm';
|
|
9
|
+
import {closeDb, db} from '#db/db.js';
|
|
10
|
+
import {migrationsPath} from '#db/migrations.js';
|
|
11
|
+
|
|
12
|
+
export async function setup() {
|
|
13
|
+
createPostgresClient();
|
|
14
|
+
|
|
15
|
+
await runMigrations(db(), migrationsPath, '__drizzle_migrations_integrations');
|
|
16
|
+
await runMigrations(githubDb(), githubMigrationsPath, '__drizzle_migrations_integrations_github');
|
|
17
|
+
await db().execute(sql`TRUNCATE integrations_connections CASCADE`);
|
|
18
|
+
await db().execute(sql`TRUNCATE integrations_webhook_deliveries CASCADE`);
|
|
19
|
+
|
|
20
|
+
closeDb();
|
|
21
|
+
await closePostgresClient();
|
|
22
|
+
}
|
package/test/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {integrationConnectionFactory} from './factories/connection.js';
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AUTH_USER,
|
|
3
|
+
buildUserContext,
|
|
4
|
+
setUserContext,
|
|
5
|
+
type UserContextMembership,
|
|
6
|
+
} from '@shipfox/api-auth-context';
|
|
7
|
+
import {type AuthMethod, ClientError, closeApp, createApp} from '@shipfox/node-fastify';
|
|
8
|
+
import {afterEach, beforeEach} from '@shipfox/vitest/vi';
|
|
9
|
+
import type {FastifyInstance, FastifyRequest} from 'fastify';
|
|
10
|
+
import {createIntegrationsModule, type IntegrationProvider} from '#index.js';
|
|
11
|
+
|
|
12
|
+
let authenticatedMemberships: UserContextMembership[] = [];
|
|
13
|
+
|
|
14
|
+
const fakeUserAuth: AuthMethod = {
|
|
15
|
+
name: AUTH_USER,
|
|
16
|
+
authenticate: (request: FastifyRequest) => {
|
|
17
|
+
if (request.headers.authorization !== 'Bearer user') {
|
|
18
|
+
throw new ClientError('Invalid user token', 'unauthorized', {status: 401});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
setUserContext(
|
|
22
|
+
request,
|
|
23
|
+
buildUserContext({
|
|
24
|
+
userId: 'user-1',
|
|
25
|
+
email: 'user@example.com',
|
|
26
|
+
memberships: authenticatedMemberships,
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
return Promise.resolve();
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export function sourceProvider(overrides: Partial<IntegrationProvider> = {}): IntegrationProvider {
|
|
34
|
+
return {
|
|
35
|
+
provider: 'gitea',
|
|
36
|
+
displayName: 'Gitea',
|
|
37
|
+
adapters: {
|
|
38
|
+
source_control: {
|
|
39
|
+
listRepositories: async () => {
|
|
40
|
+
await Promise.resolve();
|
|
41
|
+
return {
|
|
42
|
+
repositories: [
|
|
43
|
+
{
|
|
44
|
+
externalRepositoryId: 'gitea:gitea-owner/platform',
|
|
45
|
+
owner: 'gitea-owner',
|
|
46
|
+
name: 'platform',
|
|
47
|
+
fullName: 'gitea-owner/platform',
|
|
48
|
+
defaultBranch: 'main',
|
|
49
|
+
visibility: 'private',
|
|
50
|
+
cloneUrl: 'https://gitea.local/gitea-owner/platform.git',
|
|
51
|
+
htmlUrl: 'https://gitea.local/gitea-owner/platform',
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
nextCursor: null,
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
resolveRepository: async () => {
|
|
58
|
+
await Promise.resolve();
|
|
59
|
+
throw new Error('not used');
|
|
60
|
+
},
|
|
61
|
+
listFiles: async () => {
|
|
62
|
+
await Promise.resolve();
|
|
63
|
+
return {files: [], nextCursor: null};
|
|
64
|
+
},
|
|
65
|
+
fetchFile: async () => {
|
|
66
|
+
await Promise.resolve();
|
|
67
|
+
throw new Error('not used');
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
...overrides,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function createTestApp(providers: IntegrationProvider[]): Promise<FastifyInstance> {
|
|
76
|
+
const integrationsModule = await createIntegrationsModule({providers});
|
|
77
|
+
const app = await createApp({
|
|
78
|
+
auth: [fakeUserAuth],
|
|
79
|
+
routes: integrationsModule.routes ?? [],
|
|
80
|
+
swagger: false,
|
|
81
|
+
});
|
|
82
|
+
await app.ready();
|
|
83
|
+
return app;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function useIntegrationRouteTest() {
|
|
87
|
+
let workspaceId: string;
|
|
88
|
+
|
|
89
|
+
beforeEach(async () => {
|
|
90
|
+
await closeApp();
|
|
91
|
+
workspaceId = crypto.randomUUID();
|
|
92
|
+
authenticatedMemberships = [{workspaceId, role: 'admin'}];
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
afterEach(async () => {
|
|
96
|
+
await closeApp();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
get workspaceId() {
|
|
101
|
+
return workspaceId;
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
package/test/setup.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import './env.js';
|
|
2
|
+
import {closeDb as closeGithubDb} from '@shipfox/api-integration-github';
|
|
3
|
+
import {closePostgresClient, createPostgresClient} from '@shipfox/node-postgres';
|
|
4
|
+
import {afterAll, afterEach, beforeAll, vi} from '@shipfox/vitest/vi';
|
|
5
|
+
import {closeDb} from '#db/db.js';
|
|
6
|
+
|
|
7
|
+
beforeAll(() => {
|
|
8
|
+
createPostgresClient();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
vi.restoreAllMocks();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
afterAll(async () => {
|
|
16
|
+
closeDb();
|
|
17
|
+
closeGithubDb();
|
|
18
|
+
await closePostgresClient();
|
|
19
|
+
});
|