@capybara-hq/kernel 0.1.0-rc.7 → 0.1.0-rc.8
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/identity/me.controller.d.ts +1 -3
- package/dist/identity/me.controller.js +1 -9
- package/dist/identity/me.schemas.d.ts +14 -0
- package/dist/identity/me.schemas.js +17 -0
- package/dist/platform/exclusions.js +0 -10
- package/dist/platform/operation.js +1 -1
- package/dist/platform/ops/platform.ops.d.ts +7 -2
- package/dist/platform/ops/platform.ops.js +50 -3
- package/dist/platform/route-schemas.js +3 -0
- package/package.json +2 -2
|
@@ -6,6 +6,7 @@ import { OrgsService } from "../orgs/orgs.service.js";
|
|
|
6
6
|
import type { OrgRole } from "../orgs/roles.js";
|
|
7
7
|
import { type Account, AccountsService } from "./accounts.js";
|
|
8
8
|
import { type ApiTokenRecord, ApiTokenService } from "./api-tokens.js";
|
|
9
|
+
import { type PreferencesSchema } from "./me.schemas.js";
|
|
9
10
|
import { type Principal } from "./principal.js";
|
|
10
11
|
import { SessionService } from "./sessions.js";
|
|
11
12
|
import { SettingsService } from "./settings.js";
|
|
@@ -17,9 +18,6 @@ declare const TokenSchema: z.ZodObject<{
|
|
|
17
18
|
name: z.ZodString;
|
|
18
19
|
expiresAt: z.ZodOptional<z.ZodPipe<z.ZodISODateTime, z.ZodTransform<Date, string>>>;
|
|
19
20
|
}, z.core.$strip>;
|
|
20
|
-
declare const PreferencesSchema: z.ZodObject<{
|
|
21
|
-
timeZone: z.ZodNullable<z.ZodString>;
|
|
22
|
-
}, z.core.$strict>;
|
|
23
21
|
declare const CurrentOrgSchema: z.ZodObject<{
|
|
24
22
|
orgId: z.ZodNullable<z.ZodString>;
|
|
25
23
|
}, z.core.$strip>;
|
|
@@ -15,10 +15,10 @@ import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
|
15
15
|
import { createZodDto } from "../infra/validation/create-zod-dto.js";
|
|
16
16
|
import { ZBody } from "../infra/validation/zod-params.js";
|
|
17
17
|
import { OrgsService } from "../orgs/orgs.service.js";
|
|
18
|
-
import { IanaTimeZone } from "../time-zone.js";
|
|
19
18
|
import { AccountsService } from "./accounts.js";
|
|
20
19
|
import { ApiTokenService, FutureIsoDate } from "./api-tokens.js";
|
|
21
20
|
import { MAX_PASSWORD_LENGTH } from "./login.js";
|
|
21
|
+
import { PreferencesBody } from "./me.schemas.js";
|
|
22
22
|
import { AllowPendingPasswordChange, CurrentPrincipal, requireUser, SessionOnly, } from "./principal.js";
|
|
23
23
|
import { SessionService } from "./sessions.js";
|
|
24
24
|
import { SettingsService } from "./settings.js";
|
|
@@ -36,14 +36,6 @@ const TokenSchema = z.object({
|
|
|
36
36
|
});
|
|
37
37
|
class PersonalTokenBody extends createZodDto(TokenSchema, "PersonalTokenBody") {
|
|
38
38
|
}
|
|
39
|
-
const PreferencesSchema = z
|
|
40
|
-
.object({
|
|
41
|
-
/** The person's time zone (IANA); null = follow the browser (run context spec §3.4). */
|
|
42
|
-
timeZone: IanaTimeZone.nullable(),
|
|
43
|
-
})
|
|
44
|
-
.strict();
|
|
45
|
-
class PreferencesBody extends createZodDto(PreferencesSchema, "PreferencesBody") {
|
|
46
|
-
}
|
|
47
39
|
const CurrentOrgSchema = z.object({ orgId: z.string().min(1).nullable() });
|
|
48
40
|
class CurrentOrgBody extends createZodDto(CurrentOrgSchema, "CurrentOrgBody") {
|
|
49
41
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { RouteSchemas } from "../platform/route-schemas.js";
|
|
3
|
+
/** `PUT /me/preferences`: the person's preferences (run context spec §3.4). */
|
|
4
|
+
export declare const PreferencesSchema: z.ZodObject<{
|
|
5
|
+
timeZone: z.ZodNullable<z.ZodString>;
|
|
6
|
+
}, z.core.$strict>;
|
|
7
|
+
declare const PreferencesBody_base: import("../infra/validation/create-zod-dto.js").ZodDtoClass<z.ZodObject<{
|
|
8
|
+
timeZone: z.ZodNullable<z.ZodString>;
|
|
9
|
+
}, z.core.$strict>>;
|
|
10
|
+
export declare class PreferencesBody extends PreferencesBody_base {
|
|
11
|
+
}
|
|
12
|
+
/** The `/me` routes the Platform operations mirror (`check:platform-ops` keys). */
|
|
13
|
+
export declare const ME_ROUTES: readonly RouteSchemas[];
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { createZodDto } from "../infra/validation/create-zod-dto.js";
|
|
3
|
+
import { IanaTimeZone } from "../time-zone.js";
|
|
4
|
+
/** `PUT /me/preferences`: the person's preferences (run context spec §3.4). */
|
|
5
|
+
export const PreferencesSchema = z
|
|
6
|
+
.object({
|
|
7
|
+
/** The person's time zone (IANA); null = follow the browser (run context spec §3.4). */
|
|
8
|
+
timeZone: IanaTimeZone.nullable(),
|
|
9
|
+
})
|
|
10
|
+
.strict();
|
|
11
|
+
export class PreferencesBody extends createZodDto(PreferencesSchema, "PreferencesBody") {
|
|
12
|
+
}
|
|
13
|
+
/** The `/me` routes the Platform operations mirror (`check:platform-ops` keys). */
|
|
14
|
+
export const ME_ROUTES = [
|
|
15
|
+
{ route: "GET /api/v1/me/preferences" },
|
|
16
|
+
{ route: "PUT /api/v1/me/preferences", body: PreferencesSchema },
|
|
17
|
+
];
|
|
@@ -330,16 +330,6 @@ export const PLATFORM_EXCLUSIONS = [
|
|
|
330
330
|
category: "human-only",
|
|
331
331
|
reason: "Switches the web session's current org",
|
|
332
332
|
},
|
|
333
|
-
{
|
|
334
|
-
route: "GET /api/v1/me/preferences",
|
|
335
|
-
category: "internal",
|
|
336
|
-
reason: "The person's time zone setting the web's preferences page reads; the run context already gives the agent the zone in effect",
|
|
337
|
-
},
|
|
338
|
-
{
|
|
339
|
-
route: "PUT /api/v1/me/preferences",
|
|
340
|
-
category: "human-only",
|
|
341
|
-
reason: "A person's own time zone setting, chosen on their preferences page",
|
|
342
|
-
},
|
|
343
333
|
{
|
|
344
334
|
route: "PUT /api/v1/me/password",
|
|
345
335
|
category: "human-only",
|
|
@@ -12,7 +12,7 @@ export const operationDomain = (id) => id.slice(0, id.indexOf("."));
|
|
|
12
12
|
export const PLATFORM_DOMAINS = [
|
|
13
13
|
{
|
|
14
14
|
id: "platform",
|
|
15
|
-
description: "What this platform is, its tool families,
|
|
15
|
+
description: "What this platform is, its tool families, what you and this agent can do, and your own preferences (time zone).",
|
|
16
16
|
},
|
|
17
17
|
{ id: "skills", description: "The org's skill library: list, read, create, switch on or off." },
|
|
18
18
|
{
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import { type OnModuleInit } from "@nestjs/common";
|
|
2
2
|
import { AgentsService } from "../../agents/agents.service.js";
|
|
3
|
+
import { AccountsService } from "../../identity/accounts.js";
|
|
3
4
|
import { OrgSettingsService } from "../../orgs/settings.service.js";
|
|
4
5
|
import { ToolRegistry } from "../../tools/registry.js";
|
|
5
6
|
import { PlatformActor } from "../actor.js";
|
|
6
7
|
import { PlatformOperations } from "../registry.js";
|
|
7
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* The `platform` domain: orientation and what this agent is (spec §7, synthetic), and the
|
|
10
|
+
* person's own preferences (`/me/preferences`).
|
|
11
|
+
*/
|
|
8
12
|
export declare class PlatformOperationsProvider implements OnModuleInit {
|
|
9
13
|
private readonly registry;
|
|
10
14
|
private readonly actor;
|
|
11
15
|
private readonly agents;
|
|
12
16
|
private readonly settings;
|
|
13
17
|
private readonly tools;
|
|
14
|
-
|
|
18
|
+
private readonly accounts;
|
|
19
|
+
constructor(registry: PlatformOperations, actor: PlatformActor, agents: AgentsService, settings: OrgSettingsService, tools: ToolRegistry, accounts: AccountsService);
|
|
15
20
|
/**
|
|
16
21
|
* The agent's tools by the keys the model sees, as the registry resolves them for a run (tools
|
|
17
22
|
* default-on spec §8): every tool the org offers that the definition does not turn off, builtins
|
|
@@ -10,6 +10,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { Inject, Injectable } from "@nestjs/common";
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
import { AgentsService } from "../../agents/agents.service.js";
|
|
13
|
+
import { AccountsService } from "../../identity/accounts.js";
|
|
14
|
+
import { PreferencesSchema } from "../../identity/me.schemas.js";
|
|
13
15
|
import { can } from "../../orgs/roles.js";
|
|
14
16
|
import { effectiveSandboxEgress, OrgSettingsService } from "../../orgs/settings.service.js";
|
|
15
17
|
import { SANDBOX_TOOL_NAMES } from "../../tools/builtin-names.js";
|
|
@@ -34,19 +36,24 @@ const FAMILIES = [
|
|
|
34
36
|
"Plugin and connector tools, named plugin__<plugin>__<tool> and mcp__<connector>__<tool>.",
|
|
35
37
|
];
|
|
36
38
|
const EMPTY = z.object({}).strict();
|
|
37
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* The `platform` domain: orientation and what this agent is (spec §7, synthetic), and the
|
|
41
|
+
* person's own preferences (`/me/preferences`).
|
|
42
|
+
*/
|
|
38
43
|
let PlatformOperationsProvider = class PlatformOperationsProvider {
|
|
39
44
|
registry;
|
|
40
45
|
actor;
|
|
41
46
|
agents;
|
|
42
47
|
settings;
|
|
43
48
|
tools;
|
|
44
|
-
|
|
49
|
+
accounts;
|
|
50
|
+
constructor(registry, actor, agents, settings, tools, accounts) {
|
|
45
51
|
this.registry = registry;
|
|
46
52
|
this.actor = actor;
|
|
47
53
|
this.agents = agents;
|
|
48
54
|
this.settings = settings;
|
|
49
55
|
this.tools = tools;
|
|
56
|
+
this.accounts = accounts;
|
|
50
57
|
}
|
|
51
58
|
/**
|
|
52
59
|
* The agent's tools by the keys the model sees, as the registry resolves them for a run (tools
|
|
@@ -143,6 +150,45 @@ let PlatformOperationsProvider = class PlatformOperationsProvider {
|
|
|
143
150
|
};
|
|
144
151
|
},
|
|
145
152
|
}),
|
|
153
|
+
defineOperation({
|
|
154
|
+
id: "platform.preferences",
|
|
155
|
+
description: "Read your own preferences: your time zone (an IANA name such as Asia/Shanghai), or null when it follows the time zone of the browser you send messages from. The run context already tells you the zone in effect for this message.",
|
|
156
|
+
input: EMPTY,
|
|
157
|
+
example: {},
|
|
158
|
+
// any signed-in person may call the route; every run's actor is a member of this org
|
|
159
|
+
authz: { orgAction: "agents.use" },
|
|
160
|
+
mirrors: ["GET /api/v1/me/preferences"],
|
|
161
|
+
confirm: "read",
|
|
162
|
+
run: async (_input, ctx) => this.accounts.preferences(ctx.actorAccountId),
|
|
163
|
+
}),
|
|
164
|
+
defineOperation({
|
|
165
|
+
id: "platform.set-preferences",
|
|
166
|
+
description: "Set your own time zone (an IANA name such as Europe/Berlin), or null to follow the time zone of the browser you send messages from. It applies to the messages you send afterwards, on the web and in IM; the current run keeps its zone.",
|
|
167
|
+
input: PreferencesSchema,
|
|
168
|
+
example: { timeZone: "Asia/Shanghai" },
|
|
169
|
+
authz: { orgAction: "agents.use" },
|
|
170
|
+
mirrors: ["PUT /api/v1/me/preferences"],
|
|
171
|
+
confirm: "personal",
|
|
172
|
+
errors: [
|
|
173
|
+
{
|
|
174
|
+
code: "validation_failed",
|
|
175
|
+
next: "Use an IANA time zone name such as Asia/Shanghai or America/New_York, or null.",
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
summary: async (input, ctx) => {
|
|
179
|
+
const now = (await this.accounts.preferences(ctx.actorAccountId)).timeZone;
|
|
180
|
+
const from = { zh: now ?? "跟随浏览器", en: now ?? "follow the browser" };
|
|
181
|
+
const to = {
|
|
182
|
+
zh: input.timeZone ?? "跟随浏览器",
|
|
183
|
+
en: input.timeZone ?? "follow the browser",
|
|
184
|
+
};
|
|
185
|
+
return {
|
|
186
|
+
zh: `把你的时区从「${from.zh}」改为「${to.zh}」`,
|
|
187
|
+
en: `Change your time zone from "${from.en}" to "${to.en}"`,
|
|
188
|
+
};
|
|
189
|
+
},
|
|
190
|
+
run: async (input, ctx) => this.accounts.setPreferences(ctx.actorAccountId, { timeZone: input.timeZone }),
|
|
191
|
+
}),
|
|
146
192
|
]);
|
|
147
193
|
}
|
|
148
194
|
};
|
|
@@ -152,6 +198,7 @@ PlatformOperationsProvider = __decorate([
|
|
|
152
198
|
__param(1, Inject(PlatformActor)),
|
|
153
199
|
__param(2, Inject(AgentsService)),
|
|
154
200
|
__param(3, Inject(OrgSettingsService)),
|
|
155
|
-
__param(4, Inject(ToolRegistry))
|
|
201
|
+
__param(4, Inject(ToolRegistry)),
|
|
202
|
+
__param(5, Inject(AccountsService))
|
|
156
203
|
], PlatformOperationsProvider);
|
|
157
204
|
export { PlatformOperationsProvider };
|
|
@@ -15,6 +15,7 @@ import { ENVIRONMENT_ROUTES } from "../environments/environments.schemas.js";
|
|
|
15
15
|
import { EVAL_ROUTES } from "../evals/evals.schemas.js";
|
|
16
16
|
import { EXTENSION_POINT_ROUTES } from "../extensions/point-defaults.schemas.js";
|
|
17
17
|
import { FILE_PREVIEWER_ROUTES } from "../files/previewers.schemas.js";
|
|
18
|
+
import { ME_ROUTES } from "../identity/me.schemas.js";
|
|
18
19
|
import { INBOX_ROUTES } from "../inbox/inbox.schemas.js";
|
|
19
20
|
import { ORG_MODEL_ROUTES } from "../models/org-models.schemas.js";
|
|
20
21
|
import { ORG_ROUTES, ORG_SETTINGS_ROUTES } from "../orgs/orgs.schemas.js";
|
|
@@ -57,4 +58,6 @@ export const ROUTE_SCHEMAS = [
|
|
|
57
58
|
...FILE_PREVIEWER_ROUTES,
|
|
58
59
|
// Task 11b: environments
|
|
59
60
|
...ENVIRONMENT_ROUTES,
|
|
61
|
+
// personal preferences (run context spec §3.4)
|
|
62
|
+
...ME_ROUTES,
|
|
60
63
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capybara-hq/kernel",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.8",
|
|
4
4
|
"description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"@types/pg": "^8.23.1",
|
|
72
72
|
"@types/semver": "^7.8.0",
|
|
73
73
|
"@types/yauzl": "3.4.0",
|
|
74
|
-
"@capybara-hq/testing": "0.1.0-rc.
|
|
74
|
+
"@capybara-hq/testing": "0.1.0-rc.9"
|
|
75
75
|
},
|
|
76
76
|
"scripts": {
|
|
77
77
|
"build": "tsc -b"
|