@capybara-hq/kernel 0.1.0-rc.35 → 0.1.0-rc.36
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/agents/agents.module.js +3 -0
- package/dist/agents/readiness.controller.d.ts +8 -11
- package/dist/agents/readiness.controller.js +11 -17
- package/dist/agents/readiness.service.d.ts +30 -0
- package/dist/agents/readiness.service.js +61 -0
- package/dist/platform/ops/agents.ops.d.ts +3 -3
- package/dist/platform/ops/agents.ops.js +7 -10
- package/package.json +1 -1
|
@@ -22,6 +22,7 @@ import { AgentsFromTemplate } from "./from-template.service.js";
|
|
|
22
22
|
import { OrgAgentTemplates } from "./org-templates.js";
|
|
23
23
|
import { PendingConnectorRequests } from "./pending-connector-requests.js";
|
|
24
24
|
import { PendingConnectorsService } from "./pending-connectors.service.js";
|
|
25
|
+
import { ReadinessService } from "./readiness.service.js";
|
|
25
26
|
import { AgentTemplatesService } from "./templates.js";
|
|
26
27
|
/**
|
|
27
28
|
* Agents: the one {@link AgentsService} (definitions, versions, visibility; writes under the org
|
|
@@ -61,6 +62,7 @@ AgentsModule = __decorate([
|
|
|
61
62
|
AgentsFromTemplate,
|
|
62
63
|
PendingConnectorRequests,
|
|
63
64
|
PendingConnectorsService,
|
|
65
|
+
ReadinessService,
|
|
64
66
|
],
|
|
65
67
|
exports: [
|
|
66
68
|
AgentLookupModule,
|
|
@@ -72,6 +74,7 @@ AgentsModule = __decorate([
|
|
|
72
74
|
AgentsFromTemplate,
|
|
73
75
|
PendingConnectorRequests,
|
|
74
76
|
PendingConnectorsService,
|
|
77
|
+
ReadinessService,
|
|
75
78
|
],
|
|
76
79
|
})
|
|
77
80
|
], AgentsModule);
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { type Principal } from "../identity/principal.js";
|
|
2
2
|
import { type OrgContext } from "../orgs/org.guard.js";
|
|
3
|
-
import {
|
|
4
|
-
import { AgentsService } from "./agents.service.js";
|
|
3
|
+
import { type OrgReadiness, ReadinessService } from "./readiness.service.js";
|
|
5
4
|
/**
|
|
6
5
|
* Whether the org can run (`/api/v1/orgs/:orgId/readiness`, web-order spec §3.8): the web app
|
|
7
6
|
* decides between the shell and the setup layout with it. `modelProvider` is `ready` when a
|
|
8
7
|
* model-provider extension is loaded (enabled and configured), from extension state only, never
|
|
9
|
-
* a vendor call; `
|
|
10
|
-
*
|
|
8
|
+
* a vendor call; `orgCanAddModel` says whether an org admin can make one usable from the org's
|
|
9
|
+
* 扩展 page (switch on a provider the platform offers, or fill its org config) or only the super
|
|
10
|
+
* admin can; `agents` is the number of agents the caller can see (the agent list's visibility).
|
|
11
|
+
* Humans and service tokens (`org.read`).
|
|
11
12
|
*
|
|
12
13
|
* `modelProvider` counts the deployment's providers whose effective config is valid in this org
|
|
13
14
|
* (spec B §5.5: a provider the platform installed without a key needs each org's own). It is read
|
|
@@ -16,11 +17,7 @@ import { AgentsService } from "./agents.service.js";
|
|
|
16
17
|
* a moment.
|
|
17
18
|
*/
|
|
18
19
|
export declare class ReadinessController {
|
|
19
|
-
private readonly
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
get(principal: Principal, org: OrgContext): Promise<{
|
|
23
|
-
modelProvider: "ready" | "none";
|
|
24
|
-
agents: number;
|
|
25
|
-
}>;
|
|
20
|
+
private readonly readiness;
|
|
21
|
+
constructor(readiness: ReadinessService);
|
|
22
|
+
get(principal: Principal, org: OrgContext): Promise<OrgReadiness>;
|
|
26
23
|
}
|
|
@@ -10,16 +10,17 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { Controller, Get, Inject } from "@nestjs/common";
|
|
11
11
|
import { CurrentPrincipal } from "../identity/principal.js";
|
|
12
12
|
import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
|
|
13
|
-
import {
|
|
14
|
-
import { AgentsService } from "./agents.service.js";
|
|
13
|
+
import { ReadinessService } from "./readiness.service.js";
|
|
15
14
|
/** Service tokens have no account: they see `visibility='org'` agents only (as the agent list). */
|
|
16
15
|
const viewerOf = (p) => (p.kind === "user" ? p.account.id : null);
|
|
17
16
|
/**
|
|
18
17
|
* Whether the org can run (`/api/v1/orgs/:orgId/readiness`, web-order spec §3.8): the web app
|
|
19
18
|
* decides between the shell and the setup layout with it. `modelProvider` is `ready` when a
|
|
20
19
|
* model-provider extension is loaded (enabled and configured), from extension state only, never
|
|
21
|
-
* a vendor call; `
|
|
22
|
-
*
|
|
20
|
+
* a vendor call; `orgCanAddModel` says whether an org admin can make one usable from the org's
|
|
21
|
+
* 扩展 page (switch on a provider the platform offers, or fill its org config) or only the super
|
|
22
|
+
* admin can; `agents` is the number of agents the caller can see (the agent list's visibility).
|
|
23
|
+
* Humans and service tokens (`org.read`).
|
|
23
24
|
*
|
|
24
25
|
* `modelProvider` counts the deployment's providers whose effective config is valid in this org
|
|
25
26
|
* (spec B §5.5: a provider the platform installed without a key needs each org's own). It is read
|
|
@@ -28,18 +29,12 @@ const viewerOf = (p) => (p.kind === "user" ? p.account.id : null);
|
|
|
28
29
|
* a moment.
|
|
29
30
|
*/
|
|
30
31
|
let ReadinessController = class ReadinessController {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.registry = registry;
|
|
35
|
-
this.agents = agents;
|
|
32
|
+
readiness;
|
|
33
|
+
constructor(readiness) {
|
|
34
|
+
this.readiness = readiness;
|
|
36
35
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
modelProvider: (await this.registry.hasProvider(org.orgId)) ? "ready" : "none",
|
|
41
|
-
agents: visible.length,
|
|
42
|
-
};
|
|
36
|
+
get(principal, org) {
|
|
37
|
+
return this.readiness.get(org.orgId, viewerOf(principal));
|
|
43
38
|
}
|
|
44
39
|
};
|
|
45
40
|
__decorate([
|
|
@@ -50,7 +45,6 @@ __decorate([
|
|
|
50
45
|
], ReadinessController.prototype, "get", null);
|
|
51
46
|
ReadinessController = __decorate([
|
|
52
47
|
Controller("api/v1/orgs/:orgId/readiness"),
|
|
53
|
-
__param(0, Inject(
|
|
54
|
-
__param(1, Inject(AgentsService))
|
|
48
|
+
__param(0, Inject(ReadinessService))
|
|
55
49
|
], ReadinessController);
|
|
56
50
|
export { ReadinessController };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { OrgExtensionConfigs } from "../extensions/org-config.js";
|
|
2
|
+
import { ProviderRegistry } from "../runtime/providers.js";
|
|
3
|
+
import { AgentsService } from "./agents.service.js";
|
|
4
|
+
/** What `GET /orgs/:orgId/readiness` and the `agents.readiness` operation answer. */
|
|
5
|
+
export interface OrgReadiness {
|
|
6
|
+
/** `ready` when a model provider is usable in the org (extension state only, no vendor call). */
|
|
7
|
+
modelProvider: "ready" | "none";
|
|
8
|
+
/**
|
|
9
|
+
* Whether an org admin can make a model provider usable from the org's 扩展 page: a provider
|
|
10
|
+
* loaded on the deployment that is off in this org (and the org may switch it), or on but
|
|
11
|
+
* waiting for the org's own config. False when only the super admin can help (no provider is
|
|
12
|
+
* loaded on the deployment). Meaningful while `modelProvider` is `none`.
|
|
13
|
+
*/
|
|
14
|
+
orgCanAddModel: boolean;
|
|
15
|
+
/** The agents the caller can see (the agent list's visibility). */
|
|
16
|
+
agents: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Whether the org can run (web-order spec §3.8): the web app decides between the shell and the
|
|
20
|
+
* setup layout with it, and the setup checklist sends the viewer to the org's 扩展 page or to the
|
|
21
|
+
* admin console by `orgCanAddModel`.
|
|
22
|
+
*/
|
|
23
|
+
export declare class ReadinessService {
|
|
24
|
+
private readonly registry;
|
|
25
|
+
private readonly configs;
|
|
26
|
+
private readonly agents;
|
|
27
|
+
constructor(registry: ProviderRegistry, configs: OrgExtensionConfigs, agents: AgentsService);
|
|
28
|
+
get(orgId: string, viewer: string | null): Promise<OrgReadiness>;
|
|
29
|
+
private orgCanAddModel;
|
|
30
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
+
};
|
|
10
|
+
import { MODEL_PROVIDER_EXTENSION_POINT_V2, parseExtensionPoint } from "@capybara-hq/plugin-sdk";
|
|
11
|
+
import { Inject, Injectable } from "@nestjs/common";
|
|
12
|
+
import { OrgExtensionConfigs, providesOf, } from "../extensions/org-config.js";
|
|
13
|
+
import { ProviderRegistry } from "../runtime/providers.js";
|
|
14
|
+
import { AgentsService } from "./agents.service.js";
|
|
15
|
+
const MODEL_PROVIDER = parseExtensionPoint(MODEL_PROVIDER_EXTENSION_POINT_V2).name;
|
|
16
|
+
const isModelProvider = (v) => providesOf(v).some((ref) => parseExtensionPoint(ref).name === MODEL_PROVIDER);
|
|
17
|
+
/**
|
|
18
|
+
* Whether the org admin can turn `v` into a usable provider here: it is loaded on the deployment
|
|
19
|
+
* and either switchable while off, or on and waiting for the org's config (an org-level field or
|
|
20
|
+
* an overridable platform field).
|
|
21
|
+
*/
|
|
22
|
+
const orgCanFix = (v) => v.available &&
|
|
23
|
+
((!v.enabled && v.switchable) ||
|
|
24
|
+
(v.enabled && v.needsConfig && (v.configurable || v.overrideState !== "none")));
|
|
25
|
+
/**
|
|
26
|
+
* Whether the org can run (web-order spec §3.8): the web app decides between the shell and the
|
|
27
|
+
* setup layout with it, and the setup checklist sends the viewer to the org's 扩展 page or to the
|
|
28
|
+
* admin console by `orgCanAddModel`.
|
|
29
|
+
*/
|
|
30
|
+
let ReadinessService = class ReadinessService {
|
|
31
|
+
registry;
|
|
32
|
+
configs;
|
|
33
|
+
agents;
|
|
34
|
+
constructor(registry, configs, agents) {
|
|
35
|
+
this.registry = registry;
|
|
36
|
+
this.configs = configs;
|
|
37
|
+
this.agents = agents;
|
|
38
|
+
}
|
|
39
|
+
async get(orgId, viewer) {
|
|
40
|
+
const [ready, visible] = await Promise.all([
|
|
41
|
+
this.registry.hasProvider(orgId),
|
|
42
|
+
this.agents.listVisible(orgId, viewer),
|
|
43
|
+
]);
|
|
44
|
+
return {
|
|
45
|
+
modelProvider: ready ? "ready" : "none",
|
|
46
|
+
orgCanAddModel: ready ? false : await this.orgCanAddModel(orgId),
|
|
47
|
+
agents: visible.length,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
async orgCanAddModel(orgId) {
|
|
51
|
+
const views = await this.configs.list(orgId);
|
|
52
|
+
return views.some((v) => isModelProvider(v) && orgCanFix(v));
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
ReadinessService = __decorate([
|
|
56
|
+
Injectable(),
|
|
57
|
+
__param(0, Inject(ProviderRegistry)),
|
|
58
|
+
__param(1, Inject(OrgExtensionConfigs)),
|
|
59
|
+
__param(2, Inject(AgentsService))
|
|
60
|
+
], ReadinessService);
|
|
61
|
+
export { ReadinessService };
|
|
@@ -4,9 +4,9 @@ import { AgentsService } from "../../agents/agents.service.js";
|
|
|
4
4
|
import { AgentsFromTemplate } from "../../agents/from-template.service.js";
|
|
5
5
|
import { OrgAgentTemplates } from "../../agents/org-templates.js";
|
|
6
6
|
import { PendingConnectorsService } from "../../agents/pending-connectors.service.js";
|
|
7
|
+
import { ReadinessService } from "../../agents/readiness.service.js";
|
|
7
8
|
import { CatalogRequestsService } from "../../catalog/requests.service.js";
|
|
8
9
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
9
|
-
import { ProviderRegistry } from "../../runtime/providers.js";
|
|
10
10
|
import { ConnectorsService } from "../../tools/connectors.service.js";
|
|
11
11
|
import { PlatformOperations } from "../registry.js";
|
|
12
12
|
/** Agent operations of the `Platform` tool (spec §7); visibility is the person's own agents. */
|
|
@@ -19,9 +19,9 @@ export declare class AgentsOperations implements OnModuleInit {
|
|
|
19
19
|
private readonly pending;
|
|
20
20
|
private readonly requests;
|
|
21
21
|
private readonly connectors;
|
|
22
|
-
private readonly
|
|
22
|
+
private readonly readiness;
|
|
23
23
|
private readonly kdb;
|
|
24
|
-
constructor(registry: PlatformOperations, agents: AgentsService, profiles: AgentProfileService, fromTemplate: AgentsFromTemplate, orgTemplates: OrgAgentTemplates, pending: PendingConnectorsService, requests: CatalogRequestsService, connectors: ConnectorsService,
|
|
24
|
+
constructor(registry: PlatformOperations, agents: AgentsService, profiles: AgentProfileService, fromTemplate: AgentsFromTemplate, orgTemplates: OrgAgentTemplates, pending: PendingConnectorsService, requests: CatalogRequestsService, connectors: ConnectorsService, readiness: ReadinessService, kdb: KernelDb);
|
|
25
25
|
/**
|
|
26
26
|
* The edit rule the service enforces, read before the card: the agent is visible, and the actor
|
|
27
27
|
* owns it or is an org admin. Returns the agent too for the checks that follow.
|
|
@@ -18,10 +18,10 @@ import { AgentsFromTemplate } from "../../agents/from-template.service.js";
|
|
|
18
18
|
import { OrgAgentTemplates } from "../../agents/org-templates.js";
|
|
19
19
|
import { PendingConnectorsService } from "../../agents/pending-connectors.service.js";
|
|
20
20
|
import { PresetAvatarSchema } from "../../agents/profile.js";
|
|
21
|
+
import { ReadinessService } from "../../agents/readiness.service.js";
|
|
21
22
|
import { CatalogRequestsService } from "../../catalog/requests.service.js";
|
|
22
23
|
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
23
24
|
import { roleAtLeast } from "../../orgs/roles.js";
|
|
24
|
-
import { ProviderRegistry } from "../../runtime/providers.js";
|
|
25
25
|
import { rootConversationOf } from "../../runtime/subagents/child.js";
|
|
26
26
|
import { ConnectorsService } from "../../tools/connectors.service.js";
|
|
27
27
|
import { defineOperation, } from "../operation.js";
|
|
@@ -113,9 +113,9 @@ let AgentsOperations = class AgentsOperations {
|
|
|
113
113
|
pending;
|
|
114
114
|
requests;
|
|
115
115
|
connectors;
|
|
116
|
-
|
|
116
|
+
readiness;
|
|
117
117
|
kdb;
|
|
118
|
-
constructor(registry, agents, profiles, fromTemplate, orgTemplates, pending, requests, connectors,
|
|
118
|
+
constructor(registry, agents, profiles, fromTemplate, orgTemplates, pending, requests, connectors, readiness, kdb) {
|
|
119
119
|
this.registry = registry;
|
|
120
120
|
this.agents = agents;
|
|
121
121
|
this.profiles = profiles;
|
|
@@ -124,7 +124,7 @@ let AgentsOperations = class AgentsOperations {
|
|
|
124
124
|
this.pending = pending;
|
|
125
125
|
this.requests = requests;
|
|
126
126
|
this.connectors = connectors;
|
|
127
|
-
this.
|
|
127
|
+
this.readiness = readiness;
|
|
128
128
|
this.kdb = kdb;
|
|
129
129
|
}
|
|
130
130
|
/**
|
|
@@ -696,16 +696,13 @@ let AgentsOperations = class AgentsOperations {
|
|
|
696
696
|
}),
|
|
697
697
|
defineOperation({
|
|
698
698
|
id: "agents.readiness",
|
|
699
|
-
description: "Whether the org can run agents: modelProvider is ready when a model provider is available in the org (none otherwise), and how many agents you can see.",
|
|
699
|
+
description: "Whether the org can run agents: modelProvider is ready when a model provider is available in the org (none otherwise); orgCanAddModel is true when an org admin can make one available on the org's extensions page (switch on a provider the platform offers, or fill its org config), false when only the super admin can; and how many agents you can see.",
|
|
700
700
|
input: z.object({}).strict(),
|
|
701
701
|
example: {},
|
|
702
702
|
authz: { orgAction: "org.read" },
|
|
703
703
|
mirrors: ["GET /api/v1/orgs/:orgId/readiness"],
|
|
704
704
|
confirm: "read",
|
|
705
|
-
run:
|
|
706
|
-
modelProvider: (await this.providers.hasProvider(ctx.orgId)) ? "ready" : "none",
|
|
707
|
-
agents: (await this.agents.listVisible(ctx.orgId, ctx.actorAccountId)).length,
|
|
708
|
-
}),
|
|
705
|
+
run: (_input, ctx) => this.readiness.get(ctx.orgId, ctx.actorAccountId),
|
|
709
706
|
}),
|
|
710
707
|
]);
|
|
711
708
|
}
|
|
@@ -720,7 +717,7 @@ AgentsOperations = __decorate([
|
|
|
720
717
|
__param(5, Inject(PendingConnectorsService)),
|
|
721
718
|
__param(6, Inject(CatalogRequestsService)),
|
|
722
719
|
__param(7, Inject(ConnectorsService)),
|
|
723
|
-
__param(8, Inject(
|
|
720
|
+
__param(8, Inject(ReadinessService)),
|
|
724
721
|
__param(9, Inject(KernelDb))
|
|
725
722
|
], AgentsOperations);
|
|
726
723
|
export { AgentsOperations };
|
package/package.json
CHANGED