@shipfox/api-agent 8.0.0 → 9.0.2
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 +1 -1
- package/CHANGELOG.md +67 -0
- package/dist/config.js +2 -1
- package/dist/config.js.map +1 -1
- package/dist/core/credential-fingerprints.js +1 -1
- package/dist/core/credential-fingerprints.js.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/model-provider-config-service.d.ts.map +1 -1
- package/dist/core/model-provider-config-service.js +2 -1
- package/dist/core/model-provider-config-service.js.map +1 -1
- package/dist/core/model-provider-policy.d.ts +7 -0
- package/dist/core/model-provider-policy.d.ts.map +1 -0
- package/dist/core/model-provider-policy.js +23 -0
- package/dist/core/model-provider-policy.js.map +1 -0
- package/dist/core/model-provider-validation.d.ts +1 -1
- package/dist/core/model-provider-validation.d.ts.map +1 -1
- package/dist/core/model-provider-validation.js +1 -1
- package/dist/core/model-provider-validation.js.map +1 -1
- package/dist/core/resolve-agent-config.d.ts.map +1 -1
- package/dist/core/resolve-agent-config.js +2 -1
- package/dist/core/resolve-agent-config.js.map +1 -1
- package/dist/core/resolve-runtime-credentials.d.ts +1 -1
- package/dist/core/resolve-runtime-credentials.d.ts.map +1 -1
- package/dist/core/resolve-runtime-credentials.js +1 -1
- package/dist/core/resolve-runtime-credentials.js.map +1 -1
- package/dist/core/validation-catalog.d.ts.map +1 -1
- package/dist/core/validation-catalog.js +2 -1
- package/dist/core/validation-catalog.js.map +1 -1
- package/dist/db/schema/model-provider-configs.d.ts.map +1 -1
- package/dist/db/schema/model-provider-configs.js +5 -4
- package/dist/db/schema/model-provider-configs.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/presentation/e2eRoutes/create-model-provider.d.ts.map +1 -1
- package/dist/presentation/e2eRoutes/create-model-provider.js +2 -1
- package/dist/presentation/e2eRoutes/create-model-provider.js.map +1 -1
- package/dist/presentation/routes/errors.js +1 -1
- package/dist/presentation/routes/errors.js.map +1 -1
- package/dist/presentation/routes/set-default-model-provider.js +2 -1
- package/dist/presentation/routes/set-default-model-provider.js.map +1 -1
- package/dist/tsconfig.test.tsbuildinfo +1 -1
- package/drizzle/0000_daffy_leopardon.sql +5 -5
- package/drizzle/meta/0000_snapshot.json +10 -10
- package/drizzle/meta/0001_snapshot.json +10 -10
- package/package.json +25 -18
- package/src/config.ts +1 -1
- package/src/core/catalog-registry.test.ts +8 -1
- package/src/core/credential-fingerprints.ts +1 -1
- package/src/core/index.ts +7 -0
- package/src/core/model-provider-config-service.ts +1 -2
- package/src/core/model-provider-policy.ts +35 -0
- package/src/core/model-provider-validation.ts +6 -6
- package/src/core/resolve-agent-config.ts +1 -1
- package/src/core/resolve-runtime-credentials.ts +7 -8
- package/src/core/validation-catalog.ts +1 -1
- package/src/db/schema/model-provider-configs.ts +4 -4
- package/src/index.ts +6 -1
- package/src/presentation/e2eRoutes/create-model-provider.ts +2 -1
- package/src/presentation/routes/errors.ts +1 -1
- package/src/presentation/routes/set-default-model-provider.ts +1 -1
- package/test/globalSetup.ts +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
CREATE TYPE "public"."
|
|
2
|
-
CREATE TABLE "
|
|
1
|
+
CREATE TYPE "public"."agent_model_provider_config_kind" AS ENUM('builtin', 'custom');--> statement-breakpoint
|
|
2
|
+
CREATE TABLE "agent_model_provider_configs" (
|
|
3
3
|
"id" uuid PRIMARY KEY DEFAULT uuidv7() NOT NULL,
|
|
4
4
|
"workspace_id" uuid NOT NULL,
|
|
5
5
|
"provider_id" text NOT NULL,
|
|
6
|
-
"kind" "
|
|
6
|
+
"kind" "agent_model_provider_config_kind" DEFAULT 'builtin' NOT NULL,
|
|
7
7
|
"display_name" text,
|
|
8
8
|
"api" text,
|
|
9
9
|
"base_url" text,
|
|
@@ -15,7 +15,7 @@ CREATE TABLE "model_provider_configs" (
|
|
|
15
15
|
"default_thinking" text NOT NULL,
|
|
16
16
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
17
17
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
18
|
-
CONSTRAINT "
|
|
18
|
+
CONSTRAINT "agent_model_provider_configs_custom_required_fields" CHECK ("kind" <> 'custom' OR ("api" IS NOT NULL AND "base_url" IS NOT NULL AND "models" IS NOT NULL AND "display_name" IS NOT NULL))
|
|
19
19
|
);
|
|
20
20
|
--> statement-breakpoint
|
|
21
21
|
CREATE TABLE "agent_workspace_settings" (
|
|
@@ -25,4 +25,4 @@ CREATE TABLE "agent_workspace_settings" (
|
|
|
25
25
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
26
26
|
);
|
|
27
27
|
--> statement-breakpoint
|
|
28
|
-
CREATE UNIQUE INDEX "
|
|
28
|
+
CREATE UNIQUE INDEX "agent_model_provider_configs_workspace_provider_unique" ON "agent_model_provider_configs" USING btree ("workspace_id","provider_id");
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"version": "7",
|
|
5
5
|
"dialect": "postgresql",
|
|
6
6
|
"tables": {
|
|
7
|
-
"public.
|
|
8
|
-
"name": "
|
|
7
|
+
"public.agent_model_provider_configs": {
|
|
8
|
+
"name": "agent_model_provider_configs",
|
|
9
9
|
"schema": "",
|
|
10
10
|
"columns": {
|
|
11
11
|
"id": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"kind": {
|
|
31
31
|
"name": "kind",
|
|
32
|
-
"type": "
|
|
32
|
+
"type": "agent_model_provider_config_kind",
|
|
33
33
|
"primaryKey": false,
|
|
34
34
|
"notNull": true,
|
|
35
35
|
"default": "'builtin'"
|
|
@@ -105,8 +105,8 @@
|
|
|
105
105
|
}
|
|
106
106
|
},
|
|
107
107
|
"indexes": {
|
|
108
|
-
"
|
|
109
|
-
"name": "
|
|
108
|
+
"agent_model_provider_configs_workspace_provider_unique": {
|
|
109
|
+
"name": "agent_model_provider_configs_workspace_provider_unique",
|
|
110
110
|
"columns": [
|
|
111
111
|
{
|
|
112
112
|
"expression": "workspace_id",
|
|
@@ -132,9 +132,9 @@
|
|
|
132
132
|
"uniqueConstraints": {},
|
|
133
133
|
"policies": {},
|
|
134
134
|
"checkConstraints": {
|
|
135
|
-
"
|
|
136
|
-
"name": "
|
|
137
|
-
"value": "\"
|
|
135
|
+
"agent_model_provider_configs_custom_required_fields": {
|
|
136
|
+
"name": "agent_model_provider_configs_custom_required_fields",
|
|
137
|
+
"value": "\"agent_model_provider_configs\".\"kind\" <> 'custom' OR (\"agent_model_provider_configs\".\"api\" IS NOT NULL AND \"agent_model_provider_configs\".\"base_url\" IS NOT NULL AND \"agent_model_provider_configs\".\"models\" IS NOT NULL AND \"agent_model_provider_configs\".\"display_name\" IS NOT NULL)"
|
|
138
138
|
}
|
|
139
139
|
},
|
|
140
140
|
"isRLSEnabled": false
|
|
@@ -180,8 +180,8 @@
|
|
|
180
180
|
}
|
|
181
181
|
},
|
|
182
182
|
"enums": {
|
|
183
|
-
"public.
|
|
184
|
-
"name": "
|
|
183
|
+
"public.agent_model_provider_config_kind": {
|
|
184
|
+
"name": "agent_model_provider_config_kind",
|
|
185
185
|
"schema": "public",
|
|
186
186
|
"values": ["builtin", "custom"]
|
|
187
187
|
}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"version": "7",
|
|
5
5
|
"dialect": "postgresql",
|
|
6
6
|
"tables": {
|
|
7
|
-
"public.
|
|
8
|
-
"name": "
|
|
7
|
+
"public.agent_model_provider_configs": {
|
|
8
|
+
"name": "agent_model_provider_configs",
|
|
9
9
|
"schema": "",
|
|
10
10
|
"columns": {
|
|
11
11
|
"id": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"kind": {
|
|
31
31
|
"name": "kind",
|
|
32
|
-
"type": "
|
|
32
|
+
"type": "agent_model_provider_config_kind",
|
|
33
33
|
"primaryKey": false,
|
|
34
34
|
"notNull": true,
|
|
35
35
|
"default": "'builtin'"
|
|
@@ -105,8 +105,8 @@
|
|
|
105
105
|
}
|
|
106
106
|
},
|
|
107
107
|
"indexes": {
|
|
108
|
-
"
|
|
109
|
-
"name": "
|
|
108
|
+
"agent_model_provider_configs_workspace_provider_unique": {
|
|
109
|
+
"name": "agent_model_provider_configs_workspace_provider_unique",
|
|
110
110
|
"columns": [
|
|
111
111
|
{
|
|
112
112
|
"expression": "workspace_id",
|
|
@@ -132,9 +132,9 @@
|
|
|
132
132
|
"uniqueConstraints": {},
|
|
133
133
|
"policies": {},
|
|
134
134
|
"checkConstraints": {
|
|
135
|
-
"
|
|
136
|
-
"name": "
|
|
137
|
-
"value": "\"
|
|
135
|
+
"agent_model_provider_configs_custom_required_fields": {
|
|
136
|
+
"name": "agent_model_provider_configs_custom_required_fields",
|
|
137
|
+
"value": "\"agent_model_provider_configs\".\"kind\" <> 'custom' OR (\"agent_model_provider_configs\".\"api\" IS NOT NULL AND \"agent_model_provider_configs\".\"base_url\" IS NOT NULL AND \"agent_model_provider_configs\".\"models\" IS NOT NULL AND \"agent_model_provider_configs\".\"display_name\" IS NOT NULL)"
|
|
138
138
|
}
|
|
139
139
|
},
|
|
140
140
|
"isRLSEnabled": false
|
|
@@ -186,8 +186,8 @@
|
|
|
186
186
|
}
|
|
187
187
|
},
|
|
188
188
|
"enums": {
|
|
189
|
-
"public.
|
|
190
|
-
"name": "
|
|
189
|
+
"public.agent_model_provider_config_kind": {
|
|
190
|
+
"name": "agent_model_provider_config_kind",
|
|
191
191
|
"schema": "public",
|
|
192
192
|
"values": ["builtin", "custom"]
|
|
193
193
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shipfox/api-agent",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "9.0.2",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/ShipfoxHQ/shipfox.git",
|
|
@@ -11,10 +11,6 @@
|
|
|
11
11
|
"type": "module",
|
|
12
12
|
"main": "dist/index.js",
|
|
13
13
|
"types": "dist/index.d.ts",
|
|
14
|
-
"imports": {
|
|
15
|
-
"#test/*": "./test/*",
|
|
16
|
-
"#*": "./dist/*"
|
|
17
|
-
},
|
|
18
14
|
"exports": {
|
|
19
15
|
".": {
|
|
20
16
|
"types": "./dist/index.d.ts",
|
|
@@ -42,19 +38,30 @@
|
|
|
42
38
|
"@opentelemetry/api": "^1.9.1",
|
|
43
39
|
"drizzle-orm": "^0.45.2",
|
|
44
40
|
"zod": "^4.4.3",
|
|
45
|
-
"@shipfox/node-error-monitoring": "0.2.
|
|
46
|
-
"@shipfox/api-agent-dto": "
|
|
47
|
-
"@shipfox/api-auth-context": "
|
|
48
|
-
"@shipfox/api-secrets-dto": "
|
|
49
|
-
"@shipfox/inter-module": "0.2.
|
|
50
|
-
"@shipfox/config": "1.2.
|
|
51
|
-
"@shipfox/node-drizzle": "0.3.
|
|
52
|
-
"@shipfox/node-egress-guard": "0.1.
|
|
53
|
-
"@shipfox/node-fastify": "0.3.
|
|
54
|
-
"@shipfox/node-module": "0.
|
|
55
|
-
"@shipfox/node-opentelemetry": "0.6.
|
|
56
|
-
"@shipfox/node-postgres": "0.4.
|
|
57
|
-
"@shipfox/redact": "0.2.
|
|
41
|
+
"@shipfox/node-error-monitoring": "0.2.2",
|
|
42
|
+
"@shipfox/api-agent-dto": "9.0.2",
|
|
43
|
+
"@shipfox/api-auth-context": "9.0.2",
|
|
44
|
+
"@shipfox/api-secrets-dto": "9.0.2",
|
|
45
|
+
"@shipfox/inter-module": "0.2.2",
|
|
46
|
+
"@shipfox/config": "1.2.4",
|
|
47
|
+
"@shipfox/node-drizzle": "0.3.4",
|
|
48
|
+
"@shipfox/node-egress-guard": "0.1.3",
|
|
49
|
+
"@shipfox/node-fastify": "0.3.2",
|
|
50
|
+
"@shipfox/node-module": "1.0.1",
|
|
51
|
+
"@shipfox/node-opentelemetry": "0.6.2",
|
|
52
|
+
"@shipfox/node-postgres": "0.4.4",
|
|
53
|
+
"@shipfox/redact": "0.2.5"
|
|
54
|
+
},
|
|
55
|
+
"imports": {
|
|
56
|
+
"#*": "./dist/*"
|
|
57
|
+
},
|
|
58
|
+
"shipfox": {
|
|
59
|
+
"architecture": {
|
|
60
|
+
"schema": 1,
|
|
61
|
+
"realm": "source-available",
|
|
62
|
+
"kind": "implementation",
|
|
63
|
+
"context": "agent"
|
|
64
|
+
}
|
|
58
65
|
},
|
|
59
66
|
"scripts": {
|
|
60
67
|
"build": "shipfox-swc",
|
package/src/config.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
agentThinkingSchema,
|
|
3
3
|
buildHarnessToolDeploymentConfig,
|
|
4
|
-
getModelProviderEntry,
|
|
5
4
|
SUPPORTED_MODEL_PROVIDER_IDS,
|
|
6
5
|
type SupportedModelProviderId,
|
|
7
6
|
} from '@shipfox/api-agent-dto';
|
|
8
7
|
import {bool, createConfig, num, str} from '@shipfox/config';
|
|
8
|
+
import {getModelProviderEntry} from '#core/model-provider-policy.js';
|
|
9
9
|
|
|
10
10
|
const AGENT_THINKING_CHOICES = agentThinkingSchema.options;
|
|
11
11
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {getModels, getProviders, type KnownProvider} from '@earendil-works/pi-ai';
|
|
2
2
|
import {
|
|
3
|
-
getModelProviderEntry,
|
|
4
3
|
MODEL_PROVIDER_CATALOG_SEED,
|
|
5
4
|
MODEL_PROVIDER_IDS,
|
|
6
5
|
type ModelProviderId,
|
|
7
6
|
SUPPORTED_MODEL_PROVIDER_IDS,
|
|
8
7
|
} from '@shipfox/api-agent-dto';
|
|
8
|
+
import {getModelProviderEntry, isReservedModelProviderId} from './model-provider-policy.js';
|
|
9
9
|
|
|
10
10
|
const STORE_COMPATIBLE_CREDENTIAL_KEY_PATTERN = /^[a-z_][a-z0-9_]*$/;
|
|
11
11
|
|
|
@@ -17,6 +17,13 @@ describe('model provider catalog registry', () => {
|
|
|
17
17
|
expect(catalogModelProviderIds).toEqual(piModelProviderIds);
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
+
it('keeps the Agent reserved-provider helper aligned with every known provider ID', () => {
|
|
21
|
+
const reservedProviderIds = MODEL_PROVIDER_IDS.filter(isReservedModelProviderId).sort();
|
|
22
|
+
|
|
23
|
+
expect(reservedProviderIds).toEqual([...MODEL_PROVIDER_IDS].sort());
|
|
24
|
+
expect(isReservedModelProviderId('custom-provider')).toBe(false);
|
|
25
|
+
});
|
|
26
|
+
|
|
20
27
|
it('keeps supported catalog default models present in the pinned Pi model registry', () => {
|
|
21
28
|
const supportedEntries = MODEL_PROVIDER_CATALOG_SEED.filter(
|
|
22
29
|
(entry) => entry.support_status === 'supported',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {SupportedModelProviderId} from '@shipfox/api-agent-dto';
|
|
2
|
-
import {getModelProviderEntry} from '@shipfox/api-agent-dto';
|
|
3
2
|
import {UnsupportedModelProviderError} from './errors.js';
|
|
3
|
+
import {getModelProviderEntry} from './model-provider-policy.js';
|
|
4
4
|
|
|
5
5
|
export function agentSystemNamespace(providerId: string): string {
|
|
6
6
|
return `system/agent/model-provider/${providerId}`;
|
package/src/core/index.ts
CHANGED
|
@@ -41,6 +41,13 @@ export {
|
|
|
41
41
|
testAndSaveModelProviderConfig,
|
|
42
42
|
updateModelProviderConfigDefaultModel,
|
|
43
43
|
} from './model-provider-config-service.js';
|
|
44
|
+
export {
|
|
45
|
+
getModelProviderCredentialKeys,
|
|
46
|
+
getModelProviderEntry,
|
|
47
|
+
isReservedModelProviderId,
|
|
48
|
+
listSupportedModelProviders,
|
|
49
|
+
modelProviderCredentialKeysMatch,
|
|
50
|
+
} from './model-provider-policy.js';
|
|
44
51
|
export {
|
|
45
52
|
type AgentConfigResolutionContext,
|
|
46
53
|
type AgentDefaultsResolver,
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DEFAULT_AGENT_THINKING,
|
|
3
|
-
getModelProviderEntry,
|
|
4
3
|
type ModelProviderRef,
|
|
5
|
-
modelProviderCredentialKeysMatch,
|
|
6
4
|
type SupportedModelProviderId,
|
|
7
5
|
} from '@shipfox/api-agent-dto';
|
|
8
6
|
import {reportError} from '@shipfox/node-error-monitoring';
|
|
@@ -22,6 +20,7 @@ import {
|
|
|
22
20
|
UnsupportedModelProviderError,
|
|
23
21
|
} from './errors.js';
|
|
24
22
|
import {buildModelProviderCatalog} from './model-provider-catalog.js';
|
|
23
|
+
import {getModelProviderEntry, modelProviderCredentialKeysMatch} from './model-provider-policy.js';
|
|
25
24
|
import {probeModelProviderCredentials, runProviderProbe} from './model-provider-validation.js';
|
|
26
25
|
import {type AgentSecretsClient, requireAgentSecretsClient} from './secrets-client.js';
|
|
27
26
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type {ModelProviderCatalogSeedDto, SupportedModelProviderId} from '@shipfox/api-agent-dto';
|
|
2
|
+
import {MODEL_PROVIDER_CATALOG_SEED, MODEL_PROVIDER_IDS} from '@shipfox/api-agent-dto';
|
|
3
|
+
|
|
4
|
+
export function getModelProviderEntry(id: string): ModelProviderCatalogSeedDto | undefined {
|
|
5
|
+
return MODEL_PROVIDER_CATALOG_SEED.find((entry) => entry.id === id);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function getModelProviderCredentialKeys(
|
|
9
|
+
providerId: SupportedModelProviderId,
|
|
10
|
+
): string[] | undefined {
|
|
11
|
+
const entry = getModelProviderEntry(providerId);
|
|
12
|
+
if (entry === undefined || entry.support_status !== 'supported') return undefined;
|
|
13
|
+
return entry.credential_fields.map((field) => field.key).sort();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function modelProviderCredentialKeysMatch(
|
|
17
|
+
providerId: SupportedModelProviderId,
|
|
18
|
+
credentials: Record<string, string>,
|
|
19
|
+
): boolean {
|
|
20
|
+
const expectedKeys = getModelProviderCredentialKeys(providerId);
|
|
21
|
+
if (expectedKeys === undefined) return false;
|
|
22
|
+
const actualKeys = Object.keys(credentials).sort();
|
|
23
|
+
return (
|
|
24
|
+
actualKeys.length === expectedKeys.length &&
|
|
25
|
+
actualKeys.every((key, index) => key === expectedKeys[index])
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function listSupportedModelProviders(): readonly ModelProviderCatalogSeedDto[] {
|
|
30
|
+
return MODEL_PROVIDER_CATALOG_SEED.filter((entry) => entry.support_status === 'supported');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function isReservedModelProviderId(value: string): boolean {
|
|
34
|
+
return (MODEL_PROVIDER_IDS as readonly string[]).includes(value);
|
|
35
|
+
}
|
|
@@ -5,12 +5,11 @@ import {
|
|
|
5
5
|
getModels,
|
|
6
6
|
type ProviderStreamOptions,
|
|
7
7
|
} from '@earendil-works/pi-ai';
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
type SupportedModelProviderId,
|
|
8
|
+
import type {
|
|
9
|
+
CustomAgentModelDto,
|
|
10
|
+
ModelProviderApi,
|
|
11
|
+
ModelProviderRef,
|
|
12
|
+
SupportedModelProviderId,
|
|
14
13
|
} from '@shipfox/api-agent-dto';
|
|
15
14
|
import {type EgressPolicy, parseEgressHostDenylist} from '@shipfox/node-egress-guard';
|
|
16
15
|
import {redactSecrets, secretWireForms} from '@shipfox/redact';
|
|
@@ -24,6 +23,7 @@ import {
|
|
|
24
23
|
ModelProviderValidationUnavailableError,
|
|
25
24
|
UnsupportedModelProviderError,
|
|
26
25
|
} from './errors.js';
|
|
26
|
+
import {getModelProviderEntry} from './model-provider-policy.js';
|
|
27
27
|
|
|
28
28
|
const PROBE_MAX_TOKENS = 64;
|
|
29
29
|
const MAX_SANITIZED_ERROR_LENGTH = 500;
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
type CustomAgentModelDto,
|
|
5
5
|
DEFAULT_HARNESS,
|
|
6
6
|
getHarnessDescriptor,
|
|
7
|
-
getModelProviderEntry,
|
|
8
7
|
type Harness,
|
|
9
8
|
type ModelProviderRef,
|
|
10
9
|
type SupportedModelProviderId,
|
|
@@ -16,6 +15,7 @@ import {
|
|
|
16
15
|
UnsupportedModelProviderError,
|
|
17
16
|
} from './errors.js';
|
|
18
17
|
import {listHarnessProviderModels} from './harness/index.js';
|
|
18
|
+
import {getModelProviderEntry} from './model-provider-policy.js';
|
|
19
19
|
|
|
20
20
|
export interface ContextualAgentConfig {
|
|
21
21
|
readonly harness?: Harness | undefined;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
modelProviderCredentialKeysMatch,
|
|
8
|
-
type SupportedModelProviderId,
|
|
1
|
+
import type {
|
|
2
|
+
AgentRuntimeCredentialsResponseDto,
|
|
3
|
+
AgentThinking,
|
|
4
|
+
Harness,
|
|
5
|
+
ModelProviderRef,
|
|
6
|
+
SupportedModelProviderId,
|
|
9
7
|
} from '@shipfox/api-agent-dto';
|
|
10
8
|
import {secretsInterModuleContract} from '@shipfox/api-secrets-dto/inter-module';
|
|
11
9
|
import {isInterModuleKnownError} from '@shipfox/inter-module';
|
|
@@ -19,6 +17,7 @@ import {
|
|
|
19
17
|
} from './credential-fingerprints.js';
|
|
20
18
|
import type {ModelProviderConfig} from './entities/model-provider-config.js';
|
|
21
19
|
import {ModelProviderConfigNotFoundError} from './errors.js';
|
|
20
|
+
import {getModelProviderEntry, modelProviderCredentialKeysMatch} from './model-provider-policy.js';
|
|
22
21
|
import {type AgentSecretsClient, requireAgentSecretsClient} from './secrets-client.js';
|
|
23
22
|
|
|
24
23
|
export interface ResolveRuntimeCredentialsParams {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
getModelProviderEntry,
|
|
3
2
|
listEnabledHarnessTools,
|
|
4
3
|
listHarnessDescriptors,
|
|
5
4
|
MODEL_PROVIDER_IDS,
|
|
6
5
|
} from '@shipfox/api-agent-dto';
|
|
7
6
|
import type {AgentValidationCatalog} from '@shipfox/api-agent-dto/inter-module';
|
|
8
7
|
import {harnessToolDeploymentConfig} from '#config.js';
|
|
8
|
+
import {getModelProviderEntry} from './model-provider-policy.js';
|
|
9
9
|
|
|
10
10
|
/** Produces the versioned, JSON-safe policy snapshot consumed by Definitions. */
|
|
11
11
|
export function getAgentValidationCatalog(): AgentValidationCatalog {
|
|
@@ -12,15 +12,15 @@ import {
|
|
|
12
12
|
check,
|
|
13
13
|
jsonb,
|
|
14
14
|
pgEnum,
|
|
15
|
-
pgTable,
|
|
16
15
|
text,
|
|
17
16
|
timestamp,
|
|
18
17
|
uniqueIndex,
|
|
19
18
|
uuid,
|
|
20
19
|
} from 'drizzle-orm/pg-core';
|
|
21
20
|
import type {ModelProviderConfig} from '#core/entities/model-provider-config.js';
|
|
21
|
+
import {pgTable} from './common.js';
|
|
22
22
|
|
|
23
|
-
export const modelProviderConfigKindEnum = pgEnum('
|
|
23
|
+
export const modelProviderConfigKindEnum = pgEnum('agent_model_provider_config_kind', [
|
|
24
24
|
'builtin',
|
|
25
25
|
'custom',
|
|
26
26
|
]);
|
|
@@ -45,12 +45,12 @@ export const modelProviderConfigs = pgTable(
|
|
|
45
45
|
updatedAt: timestamp('updated_at', {withTimezone: true}).notNull().defaultNow(),
|
|
46
46
|
},
|
|
47
47
|
(table) => [
|
|
48
|
-
uniqueIndex('
|
|
48
|
+
uniqueIndex('agent_model_provider_configs_workspace_provider_unique').on(
|
|
49
49
|
table.workspaceId,
|
|
50
50
|
table.providerId,
|
|
51
51
|
),
|
|
52
52
|
check(
|
|
53
|
-
'
|
|
53
|
+
'agent_model_provider_configs_custom_required_fields',
|
|
54
54
|
sql`${table.kind} <> 'custom' OR (${table.api} IS NOT NULL AND ${table.baseUrl} IS NOT NULL AND ${table.models} IS NOT NULL AND ${table.displayName} IS NOT NULL)`,
|
|
55
55
|
),
|
|
56
56
|
],
|
package/src/index.ts
CHANGED
|
@@ -15,12 +15,17 @@ export {
|
|
|
15
15
|
createCustomModelProviderConfig,
|
|
16
16
|
createWorkspaceAgentDefaultsResolver,
|
|
17
17
|
deleteModelProviderConfig,
|
|
18
|
+
getModelProviderCredentialKeys,
|
|
19
|
+
getModelProviderEntry,
|
|
18
20
|
InvalidAgentModelError,
|
|
19
21
|
InvalidCredentialFieldsError,
|
|
22
|
+
isReservedModelProviderId,
|
|
23
|
+
listSupportedModelProviders,
|
|
20
24
|
type ModelProviderConfig,
|
|
21
25
|
ModelProviderConfigNotFoundError,
|
|
22
26
|
ModelProviderValidationError,
|
|
23
27
|
ModelProviderValidationUnavailableError,
|
|
28
|
+
modelProviderCredentialKeysMatch,
|
|
24
29
|
type ResolvedAgentConfig,
|
|
25
30
|
type ResolveRuntimeCredentialsParams,
|
|
26
31
|
resolveAgentConfig,
|
|
@@ -40,7 +45,7 @@ export {
|
|
|
40
45
|
export function createAgentModule(params: {secrets: AgentSecretsClient}): ShipfoxModule {
|
|
41
46
|
return {
|
|
42
47
|
name: 'agent',
|
|
43
|
-
database: {db, migrationsPath},
|
|
48
|
+
database: {db, migrationsPath, databaseNamespace: 'agent'},
|
|
44
49
|
routes: createAgentRoutes(params.secrets),
|
|
45
50
|
e2eRoutes: [createAgentE2eRoutes(params.secrets)],
|
|
46
51
|
interModulePresentations: [createAgentInterModulePresentation(params)],
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {DEFAULT_AGENT_THINKING
|
|
1
|
+
import {DEFAULT_AGENT_THINKING} from '@shipfox/api-agent-dto';
|
|
2
2
|
import {ClientError, defineRoute} from '@shipfox/node-fastify';
|
|
3
3
|
import {z} from 'zod';
|
|
4
4
|
import {agentSystemNamespace} from '#core/credential-fingerprints.js';
|
|
5
5
|
import {listHarnessProviderModels} from '#core/harness/registry.js';
|
|
6
|
+
import {getModelProviderEntry} from '#core/model-provider-policy.js';
|
|
6
7
|
import type {AgentSecretsClient} from '#core/secrets-client.js';
|
|
7
8
|
import {upsertModelProviderConfig} from '#db/index.js';
|
|
8
9
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {getModelProviderCredentialKeys} from '@shipfox/api-agent-dto';
|
|
2
1
|
import {secretsInterModuleContract} from '@shipfox/api-secrets-dto/inter-module';
|
|
3
2
|
import {isInterModuleKnownError} from '@shipfox/inter-module';
|
|
4
3
|
import {EgressDeniedError} from '@shipfox/node-egress-guard';
|
|
@@ -14,6 +13,7 @@ import {
|
|
|
14
13
|
ModelProviderValidationError,
|
|
15
14
|
UnsupportedModelProviderError,
|
|
16
15
|
} from '#core/index.js';
|
|
16
|
+
import {getModelProviderCredentialKeys} from '#core/model-provider-policy.js';
|
|
17
17
|
|
|
18
18
|
export function translateModelProviderRouteError(error: unknown): never {
|
|
19
19
|
if (error instanceof ModelProviderValidationError) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
getModelProviderEntry,
|
|
3
2
|
setDefaultModelProviderBodySchema,
|
|
4
3
|
setDefaultModelProviderResponseSchema,
|
|
5
4
|
} from '@shipfox/api-agent-dto';
|
|
@@ -7,6 +6,7 @@ import {requireWorkspaceAccess} from '@shipfox/api-auth-context';
|
|
|
7
6
|
import {defineRoute} from '@shipfox/node-fastify';
|
|
8
7
|
import {z} from 'zod';
|
|
9
8
|
import {UnsupportedModelProviderError} from '#core/index.js';
|
|
9
|
+
import {getModelProviderEntry} from '#core/model-provider-policy.js';
|
|
10
10
|
import {getModelProviderConfig, setDefaultModelProvider} from '#db/index.js';
|
|
11
11
|
import {translateModelProviderRouteError} from './errors.js';
|
|
12
12
|
|
package/test/globalSetup.ts
CHANGED
|
@@ -8,7 +8,7 @@ export async function setup() {
|
|
|
8
8
|
createPostgresClient();
|
|
9
9
|
|
|
10
10
|
await runMigrations(db(), migrationsPath, '__drizzle_migrations_agent');
|
|
11
|
-
await db().execute(sql`TRUNCATE
|
|
11
|
+
await db().execute(sql`TRUNCATE agent_model_provider_configs CASCADE`);
|
|
12
12
|
await db().execute(sql`TRUNCATE agent_workspace_settings CASCADE`);
|
|
13
13
|
|
|
14
14
|
closeDb();
|