@company-semantics/contracts 9.0.0 → 9.2.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/package.json +6 -3
- package/src/__tests__/resource-keys.test.ts +30 -23
- package/src/admin/authz-simulate.ts +4 -4
- package/src/admin/direct-grants.ts +2 -2
- package/src/api/generated-spec-hash.ts +2 -2
- package/src/api/generated.ts +97 -0
- package/src/api/http/routes/ai-chat.ts +3 -3
- package/src/api/http/utils/resource-response.ts +5 -2
- package/src/api/index.ts +4 -4
- package/src/api/primitives.ts +6 -2
- package/src/auth/README.md +1 -0
- package/src/auth/index.ts +12 -5
- package/src/autotune.ts +5 -1
- package/src/billing/index.ts +1 -1
- package/src/billing/types.ts +1 -1
- package/src/chat/README.md +3 -0
- package/src/chat/__tests__/runtime-profile.test.ts +68 -48
- package/src/chat/index.ts +10 -4
- package/src/chat/runtime-profile.ts +25 -10
- package/src/chat/schemas.ts +49 -41
- package/src/chat/types.ts +48 -42
- package/src/ci-envelope/README.md +2 -0
- package/src/ci-envelope/__tests__/transitions.test.ts +56 -56
- package/src/ci-envelope/index.ts +2 -2
- package/src/ci-envelope/types.ts +20 -20
- package/src/ci-results/index.ts +2 -2
- package/src/ci-results/repo-ci-result.ts +15 -12
- package/src/compatibility.ts +6 -6
- package/src/content/index.ts +10 -4
- package/src/content/schemas.ts +42 -24
- package/src/dispatch/index.ts +18 -15
- package/src/email/__tests__/registry.test.ts +81 -77
- package/src/email/index.ts +3 -3
- package/src/email/registry.ts +25 -25
- package/src/email/types.ts +43 -43
- package/src/errors/index.ts +8 -8
- package/src/execution/__tests__/events.test.ts +42 -42
- package/src/execution/__tests__/lifecycle.test.ts +192 -190
- package/src/execution/__tests__/registry.test.ts +114 -114
- package/src/execution/audit-export.ts +4 -4
- package/src/execution/errors.ts +7 -7
- package/src/execution/event-metadata.ts +4 -4
- package/src/execution/events.ts +23 -21
- package/src/execution/expiry.ts +5 -5
- package/src/execution/hash-chain.ts +2 -2
- package/src/execution/index.ts +19 -28
- package/src/execution/kinds.ts +7 -7
- package/src/execution/lifecycle.ts +33 -33
- package/src/execution/registry.ts +63 -63
- package/src/execution/schemas.ts +31 -23
- package/src/execution/status.ts +45 -26
- package/src/execution/summary.ts +16 -17
- package/src/execution/timeline-ui.ts +9 -9
- package/src/execution/types.ts +31 -25
- package/src/generated/openapi-routes.ts +2 -0
- package/src/guards/config.ts +22 -18
- package/src/guards/index.ts +4 -4
- package/src/guards/types.ts +32 -24
- package/src/identity/__tests__/avatar.test.ts +68 -59
- package/src/identity/avatar.ts +8 -8
- package/src/identity/display-name.ts +3 -3
- package/src/identity/index.ts +8 -8
- package/src/identity/people-org-chart.ts +8 -4
- package/src/identity/schemas.ts +28 -18
- package/src/identity/types.ts +5 -5
- package/src/impersonation/index.ts +5 -5
- package/src/impersonation/schemas.ts +15 -9
- package/src/impersonation-events.ts +21 -21
- package/src/impersonation.ts +25 -24
- package/src/index.ts +118 -90
- package/src/interfaces/mcp/tools/help.ts +19 -19
- package/src/internal-admin.ts +6 -6
- package/src/mcp/README.md +2 -0
- package/src/mcp/__tests__/capability-graph.test.ts +290 -290
- package/src/mcp/capability-graph.ts +42 -40
- package/src/mcp/failure-context.ts +1 -3
- package/src/mcp/index.ts +69 -56
- package/src/mcp/resources.ts +9 -9
- package/src/meetings/index.ts +2 -2
- package/src/meetings/schemas.ts +51 -34
- package/src/message-parts/README.md +2 -0
- package/src/message-parts/__tests__/builder.test.ts +142 -142
- package/src/message-parts/__tests__/confirmation.test.ts +100 -86
- package/src/message-parts/__tests__/preview.test.ts +63 -63
- package/src/message-parts/__tests__/wire.test.ts +130 -124
- package/src/message-parts/builder.ts +23 -23
- package/src/message-parts/confirmation.ts +17 -14
- package/src/message-parts/execution.ts +7 -7
- package/src/message-parts/index.ts +10 -10
- package/src/message-parts/lifecycle.ts +25 -25
- package/src/message-parts/preview.ts +30 -30
- package/src/message-parts/types.ts +27 -27
- package/src/message-parts/wire.ts +24 -24
- package/src/mutations.ts +2 -2
- package/src/observability.ts +23 -11
- package/src/org/__tests__/org-units.test.ts +131 -96
- package/src/org/__tests__/tree-ordering.test.ts +57 -37
- package/src/org/__tests__/view-scopes.test.ts +40 -40
- package/src/org/domain.ts +9 -9
- package/src/org/index.ts +31 -21
- package/src/org/org-units.ts +34 -20
- package/src/org/schemas.ts +261 -124
- package/src/org/sharing.ts +17 -13
- package/src/org/tree-ordering.ts +3 -1
- package/src/org/types.ts +54 -47
- package/src/org/view-scopes.ts +9 -9
- package/src/permissions/access-levels.ts +7 -2
- package/src/permissions/access-source.ts +6 -6
- package/src/permissions/index.ts +5 -5
- package/src/permissions/orgchart-roles.ts +7 -7
- package/src/permissions/permission-introspection.ts +7 -5
- package/src/permissions/share-api.ts +19 -9
- package/src/pressure.ts +4 -4
- package/src/queryIntent.ts +21 -21
- package/src/ralph/__tests__/prd-groups.test.ts +159 -159
- package/src/ralph/__tests__/prd.test.ts +30 -30
- package/src/ralph/index.ts +3 -8
- package/src/ralph/prd.ts +33 -33
- package/src/ralph/progress.ts +1 -1
- package/src/rate-limit/README.md +4 -4
- package/src/rate-limit/index.ts +3 -3
- package/src/requests.ts +36 -8
- package/src/resource-keys.ts +207 -124
- package/src/resource-registry.ts +5 -5
- package/src/route-builder.ts +3 -3
- package/src/safe-mode.ts +2 -2
- package/src/security/index.ts +4 -4
- package/src/security/org-secrets.ts +13 -9
- package/src/security/secret.ts +3 -3
- package/src/sse.ts +3 -1
- package/src/system/README.md +3 -0
- package/src/system/capabilities.ts +22 -23
- package/src/system/diagram.ts +45 -45
- package/src/system/index.ts +14 -14
- package/src/tiers.ts +1 -1
- package/src/timeouts.ts +1 -1
- package/src/tracing.ts +30 -30
- package/src/types/analytics.ts +2 -2
- package/src/usage/README.md +3 -0
- package/src/usage/execution-types.ts +69 -69
- package/src/usage/types.ts +7 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@company-semantics/contracts",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -79,6 +79,8 @@
|
|
|
79
79
|
"typecheck": "tsc -b --noEmit",
|
|
80
80
|
"typecheck:ci": "tsc -p scripts/ci/tsconfig.json",
|
|
81
81
|
"lint:md": "markdownlint-cli2 '**/*.md' '#node_modules'",
|
|
82
|
+
"format": "prettier --write src/",
|
|
83
|
+
"format:check": "prettier --check src/",
|
|
82
84
|
"lint:json": "node -e \"JSON.parse(require('fs').readFileSync('package.json'))\"",
|
|
83
85
|
"prepare": "husky",
|
|
84
86
|
"guard:export": "npx tsx scripts/ci/export-guard.ts",
|
|
@@ -113,13 +115,14 @@
|
|
|
113
115
|
"zod": "^4.4.3"
|
|
114
116
|
},
|
|
115
117
|
"devDependencies": {
|
|
116
|
-
"@types/node": "^
|
|
118
|
+
"@types/node": "^22.19.19",
|
|
117
119
|
"husky": "^9.1.7",
|
|
118
120
|
"lint-staged": "^17.0.7",
|
|
119
121
|
"markdownlint-cli2": "^0.22.1",
|
|
120
122
|
"openapi-typescript": "^7.13.0",
|
|
123
|
+
"prettier": "^3.8.3",
|
|
121
124
|
"tsx": "^4.22.4",
|
|
122
|
-
"typescript": "^5",
|
|
125
|
+
"typescript": "^5.8.3",
|
|
123
126
|
"vitest": "^4.1.8",
|
|
124
127
|
"yaml": "^2.9.0"
|
|
125
128
|
},
|
|
@@ -1,55 +1,57 @@
|
|
|
1
|
-
import { describe, it, expect } from
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
2
|
import {
|
|
3
3
|
toQueryKey,
|
|
4
4
|
fromQueryKey,
|
|
5
5
|
matchesResourceKey,
|
|
6
6
|
type ResourceKey,
|
|
7
|
-
} from
|
|
7
|
+
} from "../resource-keys.js";
|
|
8
8
|
|
|
9
|
-
const ORG_ID =
|
|
9
|
+
const ORG_ID = "11111111-1111-4111-8111-111111111111";
|
|
10
10
|
|
|
11
|
-
describe(
|
|
12
|
-
const key: ResourceKey = { type:
|
|
11
|
+
describe("resource-keys: orgUnitOwners (org-scoped)", () => {
|
|
12
|
+
const key: ResourceKey = { type: "orgUnitOwners", orgId: ORG_ID };
|
|
13
13
|
|
|
14
|
-
it(
|
|
14
|
+
it("toQueryKey produces [type, orgId] with no unitId", () => {
|
|
15
15
|
const qk = toQueryKey(key);
|
|
16
|
-
expect(qk).toEqual([
|
|
16
|
+
expect(qk).toEqual(["orgUnitOwners", ORG_ID]);
|
|
17
17
|
// org-scoped: exactly two segments, no per-unit identity
|
|
18
18
|
expect(qk).toHaveLength(2);
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
it(
|
|
21
|
+
it("roundtrips through fromQueryKey", () => {
|
|
22
22
|
const parsed = fromQueryKey(toQueryKey(key));
|
|
23
23
|
expect(parsed).toEqual(key);
|
|
24
|
-
expect(
|
|
24
|
+
expect("unitId" in parsed).toBe(false);
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
it(
|
|
28
|
-
const other =
|
|
27
|
+
it("matchesResourceKey is org-scoped: rejects a different orgId", () => {
|
|
28
|
+
const other = "22222222-2222-4222-8222-222222222222";
|
|
29
29
|
expect(matchesResourceKey(toQueryKey(key), key)).toBe(true);
|
|
30
|
-
expect(matchesResourceKey([
|
|
30
|
+
expect(matchesResourceKey(["orgUnitOwners", other], key)).toBe(false);
|
|
31
31
|
});
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
describe(
|
|
34
|
+
describe("resource-keys: system-scoped internalAdmin* types", () => {
|
|
35
35
|
const systemTypes = [
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
"internalAdminAiProviders",
|
|
37
|
+
"internalAdminPrompts",
|
|
38
|
+
"internalAdminAiRuntimeDefaults",
|
|
39
|
+
"factoryFloor",
|
|
40
|
+
"factorySnapshot",
|
|
39
41
|
] as const;
|
|
40
42
|
|
|
41
43
|
for (const type of systemTypes) {
|
|
42
|
-
const key = { type, scope:
|
|
44
|
+
const key = { type, scope: "system" } as ResourceKey;
|
|
43
45
|
|
|
44
46
|
it(`${type}: toQueryKey produces [type, 'system']`, () => {
|
|
45
|
-
expect(toQueryKey(key)).toEqual([type,
|
|
47
|
+
expect(toQueryKey(key)).toEqual([type, "system"]);
|
|
46
48
|
});
|
|
47
49
|
|
|
48
50
|
it(`${type}: roundtrips through fromQueryKey with scope: 'system'`, () => {
|
|
49
51
|
const parsed = fromQueryKey(toQueryKey(key));
|
|
50
52
|
expect(parsed).toEqual(key);
|
|
51
|
-
expect(
|
|
52
|
-
expect(
|
|
53
|
+
expect("orgId" in parsed).toBe(false);
|
|
54
|
+
expect("userId" in parsed).toBe(false);
|
|
53
55
|
});
|
|
54
56
|
|
|
55
57
|
it(`${type}: matchesResourceKey accepts a matching system key`, () => {
|
|
@@ -57,8 +59,13 @@ describe('resource-keys: system-scoped internalAdmin* types', () => {
|
|
|
57
59
|
});
|
|
58
60
|
}
|
|
59
61
|
|
|
60
|
-
it(
|
|
61
|
-
const target: ResourceKey = {
|
|
62
|
-
|
|
62
|
+
it("matchesResourceKey rejects a mismatched system type", () => {
|
|
63
|
+
const target: ResourceKey = {
|
|
64
|
+
type: "internalAdminPrompts",
|
|
65
|
+
scope: "system",
|
|
66
|
+
};
|
|
67
|
+
expect(
|
|
68
|
+
matchesResourceKey(["internalAdminAiProviders", "system"], target),
|
|
69
|
+
).toBe(false);
|
|
63
70
|
});
|
|
64
71
|
});
|
|
@@ -6,21 +6,21 @@
|
|
|
6
6
|
* admins can debug denials by reading evaluator name + reason rather than
|
|
7
7
|
* guessing. See PRD-00544 and feedback_decision_logic_must_be_visible.md.
|
|
8
8
|
*/
|
|
9
|
-
import { z } from
|
|
9
|
+
import { z } from "zod";
|
|
10
10
|
|
|
11
11
|
export const SimulateRequest = z.object({
|
|
12
12
|
actor: z.object({
|
|
13
|
-
type: z.enum([
|
|
13
|
+
type: z.enum(["user", "agent"]),
|
|
14
14
|
id: z.string().uuid(),
|
|
15
15
|
}),
|
|
16
16
|
scope: z.string(),
|
|
17
|
-
resource_kind: z.enum([
|
|
17
|
+
resource_kind: z.enum(["system", "org", "team", "member", "doc"]),
|
|
18
18
|
resource_id: z.string().uuid().optional(),
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
export type SimulateRequest = z.infer<typeof SimulateRequest>;
|
|
22
22
|
|
|
23
|
-
export const SimulateResponse = z.discriminatedUnion(
|
|
23
|
+
export const SimulateResponse = z.discriminatedUnion("allow", [
|
|
24
24
|
z.object({
|
|
25
25
|
allow: z.literal(true),
|
|
26
26
|
matched_grant: z.unknown(),
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* body — it is set by the server from the authenticated actor (see PRD-00544
|
|
7
7
|
* direct-grant-audit-trail and the `direct-grant-audit` CI guard).
|
|
8
8
|
*/
|
|
9
|
-
import { z } from
|
|
9
|
+
import { z } from "zod";
|
|
10
10
|
|
|
11
11
|
export const DirectGrantCreate = z.object({
|
|
12
12
|
subject_id: z.string().uuid(),
|
|
@@ -22,7 +22,7 @@ export const DirectGrant = z.object({
|
|
|
22
22
|
org_id: z.string().uuid(),
|
|
23
23
|
subject_id: z.string().uuid(),
|
|
24
24
|
scope_pattern: z.string(),
|
|
25
|
-
source: z.literal(
|
|
25
|
+
source: z.literal("direct"),
|
|
26
26
|
granted_by: z.string().uuid(),
|
|
27
27
|
granted_at: z.string().datetime(),
|
|
28
28
|
expires_at: z.string().datetime().nullable(),
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// AUTO-GENERATED — do not edit. Run pnpm generate:spec-hash to regenerate.
|
|
2
|
-
export const SPEC_HASH = '
|
|
3
|
-
export const SPEC_HASH_FULL = '
|
|
2
|
+
export const SPEC_HASH = '1173d8fa2df9' as const;
|
|
3
|
+
export const SPEC_HASH_FULL = '1173d8fa2df90dbf7a46608635f61e69939616ed509f6109bdf478fc1cd4a9c0' as const;
|
package/src/api/generated.ts
CHANGED
|
@@ -2696,6 +2696,23 @@ export interface paths {
|
|
|
2696
2696
|
patch?: never;
|
|
2697
2697
|
trace?: never;
|
|
2698
2698
|
};
|
|
2699
|
+
"/api/factory/snapshot": {
|
|
2700
|
+
parameters: {
|
|
2701
|
+
query?: never;
|
|
2702
|
+
header?: never;
|
|
2703
|
+
path?: never;
|
|
2704
|
+
cookie?: never;
|
|
2705
|
+
};
|
|
2706
|
+
/** Read the freshest software-factory PRD snapshot */
|
|
2707
|
+
get: operations["factorySnapshot"];
|
|
2708
|
+
put?: never;
|
|
2709
|
+
post?: never;
|
|
2710
|
+
delete?: never;
|
|
2711
|
+
options?: never;
|
|
2712
|
+
head?: never;
|
|
2713
|
+
patch?: never;
|
|
2714
|
+
trace?: never;
|
|
2715
|
+
};
|
|
2699
2716
|
"/api/internal-admin/impersonate/start": {
|
|
2700
2717
|
parameters: {
|
|
2701
2718
|
query?: never;
|
|
@@ -4800,6 +4817,52 @@ export interface components {
|
|
|
4800
4817
|
}[];
|
|
4801
4818
|
}[];
|
|
4802
4819
|
};
|
|
4820
|
+
FactorySnapshotResponse: {
|
|
4821
|
+
snapshot: {
|
|
4822
|
+
/** Format: date-time */
|
|
4823
|
+
generatedAt: string;
|
|
4824
|
+
host: string;
|
|
4825
|
+
counts: {
|
|
4826
|
+
ready: number;
|
|
4827
|
+
running: number;
|
|
4828
|
+
blocked: number;
|
|
4829
|
+
done: number;
|
|
4830
|
+
};
|
|
4831
|
+
/** @default [] */
|
|
4832
|
+
prds: {
|
|
4833
|
+
id: string;
|
|
4834
|
+
title: string;
|
|
4835
|
+
repo: string;
|
|
4836
|
+
/** @enum {string} */
|
|
4837
|
+
status: "active" | "completed";
|
|
4838
|
+
/** @enum {string} */
|
|
4839
|
+
kanban: "ready" | "running" | "blocked" | "done";
|
|
4840
|
+
progress: number;
|
|
4841
|
+
running?: {
|
|
4842
|
+
executor: string | null;
|
|
4843
|
+
feature: string | null;
|
|
4844
|
+
startedAt: string | null;
|
|
4845
|
+
branch: string | null;
|
|
4846
|
+
};
|
|
4847
|
+
/** @default [] */
|
|
4848
|
+
blockedBy: {
|
|
4849
|
+
target: string;
|
|
4850
|
+
reason?: string;
|
|
4851
|
+
}[];
|
|
4852
|
+
}[];
|
|
4853
|
+
/** @default [] */
|
|
4854
|
+
actors: {
|
|
4855
|
+
id: string;
|
|
4856
|
+
role: string;
|
|
4857
|
+
/** @enum {string} */
|
|
4858
|
+
status: "working" | "idle";
|
|
4859
|
+
workingOn?: string;
|
|
4860
|
+
feature?: string;
|
|
4861
|
+
detected: boolean;
|
|
4862
|
+
}[];
|
|
4863
|
+
} | null;
|
|
4864
|
+
receivedAt: string | null;
|
|
4865
|
+
};
|
|
4803
4866
|
ImpersonationSessionResponse: {
|
|
4804
4867
|
session: {
|
|
4805
4868
|
impersonationSessionId: string;
|
|
@@ -9324,6 +9387,40 @@ export interface operations {
|
|
|
9324
9387
|
};
|
|
9325
9388
|
};
|
|
9326
9389
|
};
|
|
9390
|
+
factorySnapshot: {
|
|
9391
|
+
parameters: {
|
|
9392
|
+
query?: never;
|
|
9393
|
+
header?: never;
|
|
9394
|
+
path?: never;
|
|
9395
|
+
cookie?: never;
|
|
9396
|
+
};
|
|
9397
|
+
requestBody?: never;
|
|
9398
|
+
responses: {
|
|
9399
|
+
/** @description Factory snapshot (freshest by generatedAt, null if none) */
|
|
9400
|
+
200: {
|
|
9401
|
+
headers: {
|
|
9402
|
+
[name: string]: unknown;
|
|
9403
|
+
};
|
|
9404
|
+
content: {
|
|
9405
|
+
"application/json": components["schemas"]["FactorySnapshotResponse"];
|
|
9406
|
+
};
|
|
9407
|
+
};
|
|
9408
|
+
/** @description Not authenticated */
|
|
9409
|
+
401: {
|
|
9410
|
+
headers: {
|
|
9411
|
+
[name: string]: unknown;
|
|
9412
|
+
};
|
|
9413
|
+
content?: never;
|
|
9414
|
+
};
|
|
9415
|
+
/** @description Not an internal admin */
|
|
9416
|
+
403: {
|
|
9417
|
+
headers: {
|
|
9418
|
+
[name: string]: unknown;
|
|
9419
|
+
};
|
|
9420
|
+
content?: never;
|
|
9421
|
+
};
|
|
9422
|
+
};
|
|
9423
|
+
};
|
|
9327
9424
|
startImpersonation: {
|
|
9328
9425
|
parameters: {
|
|
9329
9426
|
query?: never;
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
* import { buildCapabilityGraph } from '@company-semantics/contracts'
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { buildCapabilityGraph } from
|
|
13
|
+
import { buildCapabilityGraph } from "../../../mcp/capability-graph";
|
|
14
14
|
import type {
|
|
15
15
|
MCPToolDescriptor,
|
|
16
16
|
ToolDiscoveryResponse,
|
|
17
17
|
CapabilityGraph,
|
|
18
|
-
} from
|
|
18
|
+
} from "../../../mcp/index";
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Build a ToolDiscoveryResponse, optionally including the capability graph.
|
|
@@ -33,5 +33,5 @@ export function buildToolDiscoveryResponse(
|
|
|
33
33
|
return {
|
|
34
34
|
tools,
|
|
35
35
|
...(includeGraph && { graph: buildCapabilityGraph(tools) }),
|
|
36
|
-
}
|
|
36
|
+
};
|
|
37
37
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ResourceResponse } from
|
|
1
|
+
import type { ResourceResponse } from "../../../resource-response";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Wrap resource data with version for cache invalidation.
|
|
@@ -6,6 +6,9 @@ import type { ResourceResponse } from '../../../resource-response';
|
|
|
6
6
|
* @param version - MUST be entity.updatedAt or DB row version. NEVER Date.now().
|
|
7
7
|
* Using request time defeats invalidation — race conditions reappear.
|
|
8
8
|
*/
|
|
9
|
-
export function resourceResponse<T>(
|
|
9
|
+
export function resourceResponse<T>(
|
|
10
|
+
data: T,
|
|
11
|
+
version: number,
|
|
12
|
+
): ResourceResponse<T> {
|
|
10
13
|
return { data, version };
|
|
11
14
|
}
|
package/src/api/index.ts
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
// OpenAPI generated types (from openapi/backend.yaml)
|
|
9
|
-
export type { paths, components, operations } from
|
|
9
|
+
export type { paths, components, operations } from "./generated";
|
|
10
10
|
|
|
11
11
|
// Spec hash (from openapi/backend.yaml SHA-256)
|
|
12
|
-
export { SPEC_HASH, SPEC_HASH_FULL } from
|
|
12
|
+
export { SPEC_HASH, SPEC_HASH_FULL } from "./generated-spec-hash";
|
|
13
13
|
|
|
14
14
|
// Reusable API primitive schemas (CursorPage, ErrorResponse)
|
|
15
|
-
export { CursorPageSchema, ErrorResponseSchema } from
|
|
16
|
-
export type { CursorPage, ErrorResponse } from
|
|
15
|
+
export { CursorPageSchema, ErrorResponseSchema } from "./primitives";
|
|
16
|
+
export type { CursorPage, ErrorResponse } from "./primitives";
|
package/src/api/primitives.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
3
|
/** Generic factory for cursor-paginated responses. */
|
|
4
4
|
export function CursorPageSchema<T extends z.ZodTypeAny>(itemSchema: T) {
|
|
@@ -19,5 +19,9 @@ export const ErrorResponseSchema = z.object({
|
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
// Inferred types
|
|
22
|
-
export type CursorPage<T> = {
|
|
22
|
+
export type CursorPage<T> = {
|
|
23
|
+
items: T[];
|
|
24
|
+
nextCursor: string | null;
|
|
25
|
+
hasMore: boolean;
|
|
26
|
+
};
|
|
23
27
|
export type ErrorResponse = z.infer<typeof ErrorResponseSchema>;
|
package/src/auth/README.md
CHANGED
|
@@ -12,6 +12,7 @@ Shared types for authentication flows across Company Semantics codebases. Define
|
|
|
12
12
|
## Public API
|
|
13
13
|
|
|
14
14
|
**Types:**
|
|
15
|
+
|
|
15
16
|
- `OTPErrorCode` — enum: `InvalidCode`, `Expired`, `AlreadyUsed`, `NotFound`
|
|
16
17
|
- `AuthStartMode` — `'otp' | 'sso' | 'hybrid'`
|
|
17
18
|
- `AuthStartResponse` — discriminated union describing auth flow entry point
|
package/src/auth/index.ts
CHANGED
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
* Frontend uses these to provide specific user messaging (e.g., expired vs invalid).
|
|
12
12
|
*/
|
|
13
13
|
export enum OTPErrorCode {
|
|
14
|
-
InvalidCode =
|
|
15
|
-
Expired =
|
|
16
|
-
AlreadyUsed =
|
|
17
|
-
NotFound =
|
|
14
|
+
InvalidCode = "invalid_code",
|
|
15
|
+
Expired = "expired",
|
|
16
|
+
AlreadyUsed = "already_used",
|
|
17
|
+
NotFound = "not_found",
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export type AuthStartMode = "otp" | "sso" | "hybrid";
|
|
@@ -22,4 +22,11 @@ export type AuthStartMode = "otp" | "sso" | "hybrid";
|
|
|
22
22
|
export type AuthStartResponse =
|
|
23
23
|
| { mode: "otp"; devOtp?: string }
|
|
24
24
|
| { mode: "sso"; providers: string[]; redirectUrl: string }
|
|
25
|
-
| {
|
|
25
|
+
| {
|
|
26
|
+
mode: "hybrid";
|
|
27
|
+
providers: string[];
|
|
28
|
+
redirectUrl: string;
|
|
29
|
+
recommendedProvider?: string;
|
|
30
|
+
otpAllowed: true;
|
|
31
|
+
devOtp?: string;
|
|
32
|
+
};
|
package/src/autotune.ts
CHANGED
|
@@ -85,6 +85,10 @@ export type ControllerInput = {
|
|
|
85
85
|
*/
|
|
86
86
|
export type ControllerOutput<Min extends number, Max extends number> = {
|
|
87
87
|
readonly value: Bounded<Min, Max>;
|
|
88
|
-
readonly reason:
|
|
88
|
+
readonly reason:
|
|
89
|
+
| "deadband-hold"
|
|
90
|
+
| "window-hold"
|
|
91
|
+
| "adjusted"
|
|
92
|
+
| "bounded-clamp";
|
|
89
93
|
readonly adjustmentWindowId: string;
|
|
90
94
|
};
|
package/src/billing/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export type { OrgPlanStatus, OrgBillingInfo } from
|
|
1
|
+
export type { OrgPlanStatus, OrgBillingInfo } from "./types";
|
package/src/billing/types.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
/**
|
|
11
11
|
* Organization plan status.
|
|
12
12
|
*/
|
|
13
|
-
export type OrgPlanStatus =
|
|
13
|
+
export type OrgPlanStatus = "active" | "trialing" | "past_due" | "canceled";
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Read-only billing information for an organization.
|
package/src/chat/README.md
CHANGED
|
@@ -16,6 +16,7 @@ Shared types for chat persistence, sharing, real-time events, and runtime profil
|
|
|
16
16
|
## Public API
|
|
17
17
|
|
|
18
18
|
**Types:**
|
|
19
|
+
|
|
19
20
|
- `ChatVisibility` — `'private' | 'public'` share visibility
|
|
20
21
|
- `ChatSummary`, `ChatSummaryExtended` — list view models
|
|
21
22
|
- `ChatShareInfo`, `SharedChatView`, `SharedChatMessage` — sharing types
|
|
@@ -25,11 +26,13 @@ Shared types for chat persistence, sharing, real-time events, and runtime profil
|
|
|
25
26
|
- `ChatRuntimeProfileInfo` — profile metadata for UI rendering
|
|
26
27
|
|
|
27
28
|
**SSE event types:**
|
|
29
|
+
|
|
28
30
|
- `ChatCreatedEvent`, `ChatUpdatedEvent`, `ChatDeletedEvent` — domain events
|
|
29
31
|
- `InvalidateChatEvent`, `InvalidateChatListEvent` — staleness signals
|
|
30
32
|
- `ChatSseEvent` — union of all SSE event types
|
|
31
33
|
|
|
32
34
|
**Runtime values:**
|
|
35
|
+
|
|
33
36
|
- `CHAT_RUNTIME_PROFILES` — ordered array of profile info for UI rendering
|
|
34
37
|
- `DEFAULT_CHAT_RUNTIME_PROFILE` — `'agentic'`
|
|
35
38
|
|
|
@@ -1,55 +1,75 @@
|
|
|
1
|
-
import { describe, it, expect } from
|
|
2
|
-
import {
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
CHAT_RUNTIME_PROFILES,
|
|
4
|
+
DEFAULT_CHAT_RUNTIME_PROFILE,
|
|
5
|
+
} from "../runtime-profile.js";
|
|
3
6
|
|
|
4
|
-
describe(
|
|
5
|
-
it(
|
|
7
|
+
describe("CHAT_RUNTIME_PROFILES golden snapshot", () => {
|
|
8
|
+
it("exact values are frozen", () => {
|
|
6
9
|
expect(CHAT_RUNTIME_PROFILES).toStrictEqual([
|
|
7
|
-
{
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
10
|
+
{
|
|
11
|
+
id: "fast",
|
|
12
|
+
label: "Fast",
|
|
13
|
+
description: "Single-step, no tools",
|
|
14
|
+
model: "gpt-3.5-turbo",
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: "balanced",
|
|
18
|
+
label: "Balanced",
|
|
19
|
+
description: "Multi-step with tools",
|
|
20
|
+
model: "gpt-4o",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: "agentic",
|
|
24
|
+
label: "Agentic",
|
|
25
|
+
description: "Agent loop, full reasoning",
|
|
26
|
+
model: "claude-sonnet-4-20250514",
|
|
27
|
+
},
|
|
28
|
+
]);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe("CHAT_RUNTIME_PROFILES invariants", () => {
|
|
33
|
+
it("covers all ChatRuntimeProfile values", () => {
|
|
34
|
+
const ids = CHAT_RUNTIME_PROFILES.map((p) => p.id);
|
|
35
|
+
expect(ids).toContain("fast");
|
|
36
|
+
expect(ids).toContain("balanced");
|
|
37
|
+
expect(ids).toContain("agentic");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("has no duplicate profile IDs", () => {
|
|
41
|
+
const ids = CHAT_RUNTIME_PROFILES.map((p) => p.id);
|
|
42
|
+
expect(new Set(ids).size).toBe(ids.length);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("all entries have non-empty label and description", () => {
|
|
28
46
|
for (const profile of CHAT_RUNTIME_PROFILES) {
|
|
29
|
-
expect(profile.label.length).toBeGreaterThan(0)
|
|
30
|
-
expect(profile.description.length).toBeGreaterThan(0)
|
|
47
|
+
expect(profile.label.length).toBeGreaterThan(0);
|
|
48
|
+
expect(profile.description.length).toBeGreaterThan(0);
|
|
31
49
|
}
|
|
32
|
-
})
|
|
50
|
+
});
|
|
33
51
|
|
|
34
|
-
it(
|
|
52
|
+
it("all entries have non-empty model strings", () => {
|
|
35
53
|
for (const profile of CHAT_RUNTIME_PROFILES) {
|
|
36
|
-
expect(profile.model.length).toBeGreaterThan(0)
|
|
54
|
+
expect(profile.model.length).toBeGreaterThan(0);
|
|
37
55
|
}
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
describe(
|
|
42
|
-
it(
|
|
43
|
-
expect(DEFAULT_CHAT_RUNTIME_PROFILE).toBe(
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
it(
|
|
47
|
-
const ids = CHAT_RUNTIME_PROFILES.map(p => p.id)
|
|
48
|
-
expect(ids).toContain(DEFAULT_CHAT_RUNTIME_PROFILE)
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
it(
|
|
52
|
-
const validIds = CHAT_RUNTIME_PROFILES.map(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe("DEFAULT_CHAT_RUNTIME_PROFILE", () => {
|
|
60
|
+
it("is agentic", () => {
|
|
61
|
+
expect(DEFAULT_CHAT_RUNTIME_PROFILE).toBe("agentic");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("exists in CHAT_RUNTIME_PROFILES", () => {
|
|
65
|
+
const ids = CHAT_RUNTIME_PROFILES.map((p) => p.id);
|
|
66
|
+
expect(ids).toContain(DEFAULT_CHAT_RUNTIME_PROFILE);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("is a valid ChatRuntimeProfile value", () => {
|
|
70
|
+
const validIds = CHAT_RUNTIME_PROFILES.map(
|
|
71
|
+
(p) => p.id,
|
|
72
|
+
) as readonly string[];
|
|
73
|
+
expect(validIds).toContain(DEFAULT_CHAT_RUNTIME_PROFILE);
|
|
74
|
+
});
|
|
75
|
+
});
|
package/src/chat/index.ts
CHANGED
|
@@ -49,7 +49,7 @@ export type {
|
|
|
49
49
|
ChatMessage,
|
|
50
50
|
ChatDetail,
|
|
51
51
|
GetChatResponse,
|
|
52
|
-
} from
|
|
52
|
+
} from "./types";
|
|
53
53
|
|
|
54
54
|
// =============================================================================
|
|
55
55
|
// Schemas (Zod runtime validation)
|
|
@@ -87,8 +87,14 @@ export {
|
|
|
87
87
|
ChatMessageSchema,
|
|
88
88
|
ChatDetailSchema,
|
|
89
89
|
GetChatResponseSchema,
|
|
90
|
-
} from
|
|
90
|
+
} from "./schemas";
|
|
91
91
|
|
|
92
92
|
// Runtime profile types and constants
|
|
93
|
-
export type {
|
|
94
|
-
|
|
93
|
+
export type {
|
|
94
|
+
ChatRuntimeProfile,
|
|
95
|
+
ChatRuntimeProfileInfo,
|
|
96
|
+
} from "./runtime-profile";
|
|
97
|
+
export {
|
|
98
|
+
CHAT_RUNTIME_PROFILES,
|
|
99
|
+
DEFAULT_CHAT_RUNTIME_PROFILE,
|
|
100
|
+
} from "./runtime-profile";
|