@stigmer/server 3.22.1-dev.20260922095755 → 3.22.1
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/authorization/authorizer.d.ts +8 -4
- package/dist/authorization/authorizer.d.ts.map +1 -1
- package/dist/authorization/authorizer.js +9 -5
- package/dist/authorization/authorizer.js.map +1 -1
- package/dist/authorization/derived-tuples.d.ts.map +1 -1
- package/dist/authorization/derived-tuples.js +25 -10
- package/dist/authorization/derived-tuples.js.map +1 -1
- package/dist/authorization/evaluator.d.ts +8 -7
- package/dist/authorization/evaluator.d.ts.map +1 -1
- package/dist/authorization/evaluator.js +20 -4
- package/dist/authorization/evaluator.js.map +1 -1
- package/dist/authorization/list-read-scope.d.ts.map +1 -1
- package/dist/authorization/list-read-scope.js +9 -5
- package/dist/authorization/list-read-scope.js.map +1 -1
- package/dist/authorization/model/agent.d.ts.map +1 -1
- package/dist/authorization/model/agent.js +5 -4
- package/dist/authorization/model/agent.js.map +1 -1
- package/dist/authorization/model/agent_instance.d.ts.map +1 -1
- package/dist/authorization/model/agent_instance.js +2 -2
- package/dist/authorization/model/agent_instance.js.map +1 -1
- package/dist/authorization/model/mcp_server.d.ts.map +1 -1
- package/dist/authorization/model/mcp_server.js +2 -2
- package/dist/authorization/model/mcp_server.js.map +1 -1
- package/dist/authorization/model/plugin.d.ts.map +1 -1
- package/dist/authorization/model/plugin.js +4 -3
- package/dist/authorization/model/plugin.js.map +1 -1
- package/dist/authorization/model/rewrite.d.ts +10 -8
- package/dist/authorization/model/rewrite.d.ts.map +1 -1
- package/dist/authorization/model/rewrite.js +3 -0
- package/dist/authorization/model/rewrite.js.map +1 -1
- package/dist/authorization/model/skill.d.ts.map +1 -1
- package/dist/authorization/model/skill.js +2 -2
- package/dist/authorization/model/skill.js.map +1 -1
- package/dist/authorization/model/workflow.d.ts.map +1 -1
- package/dist/authorization/model/workflow.js +2 -2
- package/dist/authorization/model/workflow.js.map +1 -1
- package/dist/authorization/model/workflow_instance.d.ts.map +1 -1
- package/dist/authorization/model/workflow_instance.js +2 -2
- package/dist/authorization/model/workflow_instance.js.map +1 -1
- package/dist/authorization/organization-directory.d.ts.map +1 -1
- package/dist/authorization/organization-directory.js +3 -2
- package/dist/authorization/organization-directory.js.map +1 -1
- package/dist/authorization/store-test-kit.d.ts +6 -0
- package/dist/authorization/store-test-kit.d.ts.map +1 -1
- package/dist/authorization/store-test-kit.js +62 -16
- package/dist/authorization/store-test-kit.js.map +1 -1
- package/dist/authorization/tuples.d.ts +32 -13
- package/dist/authorization/tuples.d.ts.map +1 -1
- package/dist/authorization/tuples.js +11 -3
- package/dist/authorization/tuples.js.map +1 -1
- package/dist/domain/agent/controller.d.ts.map +1 -1
- package/dist/domain/agent/controller.js +4 -4
- package/dist/domain/agent/controller.js.map +1 -1
- package/dist/domain/agentchannel/controller.d.ts.map +1 -1
- package/dist/domain/agentchannel/controller.js +1 -3
- package/dist/domain/agentchannel/controller.js.map +1 -1
- package/dist/domain/agentexecution/controller.d.ts.map +1 -1
- package/dist/domain/agentexecution/controller.js +1 -3
- package/dist/domain/agentexecution/controller.js.map +1 -1
- package/dist/domain/agentinstance/controller.d.ts.map +1 -1
- package/dist/domain/agentinstance/controller.js +4 -3
- package/dist/domain/agentinstance/controller.js.map +1 -1
- package/dist/domain/agentshare/constants.d.ts +11 -6
- package/dist/domain/agentshare/constants.d.ts.map +1 -1
- package/dist/domain/agentshare/constants.js +16 -8
- package/dist/domain/agentshare/constants.js.map +1 -1
- package/dist/domain/agentshare/controller.d.ts.map +1 -1
- package/dist/domain/agentshare/controller.js +1 -3
- package/dist/domain/agentshare/controller.js.map +1 -1
- package/dist/domain/agentshare/steps.d.ts +25 -18
- package/dist/domain/agentshare/steps.d.ts.map +1 -1
- package/dist/domain/agentshare/steps.js +142 -41
- package/dist/domain/agentshare/steps.js.map +1 -1
- package/dist/domain/environment/controller.d.ts.map +1 -1
- package/dist/domain/environment/controller.js +3 -2
- package/dist/domain/environment/controller.js.map +1 -1
- package/dist/domain/executioncontext/controller.d.ts.map +1 -1
- package/dist/domain/executioncontext/controller.js +1 -2
- package/dist/domain/executioncontext/controller.js.map +1 -1
- package/dist/domain/mcpserver/controller.d.ts.map +1 -1
- package/dist/domain/mcpserver/controller.js +4 -3
- package/dist/domain/mcpserver/controller.js.map +1 -1
- package/dist/domain/plugin/controller.d.ts.map +1 -1
- package/dist/domain/plugin/controller.js +3 -1
- package/dist/domain/plugin/controller.js.map +1 -1
- package/dist/domain/plugin/push.d.ts +5 -7
- package/dist/domain/plugin/push.d.ts.map +1 -1
- package/dist/domain/plugin/push.js +14 -8
- package/dist/domain/plugin/push.js.map +1 -1
- package/dist/domain/schedule/controller.d.ts.map +1 -1
- package/dist/domain/schedule/controller.js +1 -3
- package/dist/domain/schedule/controller.js.map +1 -1
- package/dist/domain/session/controller.d.ts.map +1 -1
- package/dist/domain/session/controller.js +2 -3
- package/dist/domain/session/controller.js.map +1 -1
- package/dist/domain/skill/controller.d.ts.map +1 -1
- package/dist/domain/skill/controller.js +2 -0
- package/dist/domain/skill/controller.js.map +1 -1
- package/dist/domain/workflow/controller.d.ts.map +1 -1
- package/dist/domain/workflow/controller.js +6 -14
- package/dist/domain/workflow/controller.js.map +1 -1
- package/dist/domain/workflow/registry/data/task-kind-registry.json +1 -1
- package/dist/domain/workflow/validation/task-config-constraints.d.ts +1 -10
- package/dist/domain/workflow/validation/task-config-constraints.d.ts.map +1 -1
- package/dist/domain/workflow/validation/task-config-constraints.js +2 -3
- package/dist/domain/workflow/validation/task-config-constraints.js.map +1 -1
- package/dist/domain/workflowexecution/controller.d.ts.map +1 -1
- package/dist/domain/workflowexecution/controller.js +2 -4
- package/dist/domain/workflowexecution/controller.js.map +1 -1
- package/dist/domain/workflowinstance/controller.d.ts.map +1 -1
- package/dist/domain/workflowinstance/controller.js +4 -3
- package/dist/domain/workflowinstance/controller.js.map +1 -1
- package/dist/extensions/authorization-queries.d.ts +5 -6
- package/dist/extensions/authorization-queries.d.ts.map +1 -1
- package/dist/extensions/list-read-scope.d.ts +1 -1
- package/dist/extensions/resource-authorization.d.ts +2 -3
- package/dist/extensions/resource-authorization.d.ts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/pipeline/apiresource-meta.d.ts +3 -12
- package/dist/pipeline/apiresource-meta.d.ts.map +1 -1
- package/dist/pipeline/apiresource-meta.js +10 -21
- package/dist/pipeline/apiresource-meta.js.map +1 -1
- package/dist/pipeline/steps/authorization-tuples.d.ts +3 -9
- package/dist/pipeline/steps/authorization-tuples.d.ts.map +1 -1
- package/dist/pipeline/steps/authorization-tuples.js +11 -9
- package/dist/pipeline/steps/authorization-tuples.js.map +1 -1
- package/dist/pipeline/steps/references.d.ts +20 -178
- package/dist/pipeline/steps/references.d.ts.map +1 -1
- package/dist/pipeline/steps/references.js +43 -344
- package/dist/pipeline/steps/references.js.map +1 -1
- package/dist/pipeline/steps/visibility-gates.d.ts +27 -0
- package/dist/pipeline/steps/visibility-gates.d.ts.map +1 -0
- package/dist/pipeline/steps/visibility-gates.js +139 -0
- package/dist/pipeline/steps/visibility-gates.js.map +1 -0
- package/dist/query/search/controller.js +1 -0
- package/dist/query/search/controller.js.map +1 -1
- package/dist/query/search/criteria.d.ts +5 -1
- package/dist/query/search/criteria.d.ts.map +1 -1
- package/dist/query/search/criteria.js +13 -3
- package/dist/query/search/criteria.js.map +1 -1
- package/dist/query/search/handler.d.ts +4 -5
- package/dist/query/search/handler.d.ts.map +1 -1
- package/dist/query/search/handler.js +6 -7
- package/dist/query/search/handler.js.map +1 -1
- package/dist/query/search/query-store.d.ts.map +1 -1
- package/dist/query/search/query-store.js +2 -0
- package/dist/query/search/query-store.js.map +1 -1
- package/dist/store/interface.d.ts +6 -3
- package/dist/store/interface.d.ts.map +1 -1
- package/dist/store/interface.js.map +1 -1
- package/dist/store/postgres/migrations.d.ts +1 -3
- package/dist/store/postgres/migrations.d.ts.map +1 -1
- package/dist/store/postgres/migrations.js +1 -35
- package/dist/store/postgres/migrations.js.map +1 -1
- package/dist/store/postgres/store.d.ts.map +1 -1
- package/dist/store/postgres/store.js +9 -4
- package/dist/store/postgres/store.js.map +1 -1
- package/dist/store/sqlite/migrations.d.ts +1 -3
- package/dist/store/sqlite/migrations.d.ts.map +1 -1
- package/dist/store/sqlite/migrations.js +1 -36
- package/dist/store/sqlite/migrations.js.map +1 -1
- package/dist/store/sqlite/store.d.ts.map +1 -1
- package/dist/store/sqlite/store.js +8 -4
- package/dist/store/sqlite/store.js.map +1 -1
- package/package.json +6 -6
- package/src/authorization/README.md +26 -24
- package/src/authorization/__tests__/authorizer.test.ts +9 -10
- package/src/authorization/__tests__/derived-tuples.test.ts +11 -4
- package/src/authorization/__tests__/evaluator.test.ts +73 -14
- package/src/authorization/__tests__/facts.test.ts +2 -2
- package/src/authorization/__tests__/fixtures/fga/agent-instance-creation.fga.yaml +185 -0
- package/src/authorization/__tests__/fixtures/fga/blueprint-private-visibility.fga.yaml +98 -6
- package/src/authorization/__tests__/fixtures/fga/cross-org-share-creation.fga.yaml +98 -0
- package/src/authorization/__tests__/fixtures/fga/default-instance-inheritance.fga.yaml +61 -4
- package/src/authorization/__tests__/fixtures/fga/mcp-server-authoring.fga.yaml +143 -0
- package/src/authorization/__tests__/fixtures/fga/org-admin-owner-inheritance.fga.yaml +21 -1
- package/src/authorization/__tests__/fixtures/fga/platform-visibility.fga.yaml +25 -1
- package/src/authorization/__tests__/fixtures/fga/public-visibility-setter.fga.yaml +52 -0
- package/src/authorization/__tests__/fixtures/fga/workflow-execution-sharing.fga.yaml +3 -1
- package/src/authorization/__tests__/list-read-scope.test.ts +17 -18
- package/src/authorization/__tests__/store-tests.test.ts +8 -1
- package/src/authorization/__tests__/tuples.test.ts +11 -12
- package/src/authorization/authorizer.ts +9 -4
- package/src/authorization/derived-tuples.ts +31 -14
- package/src/authorization/evaluator.ts +44 -8
- package/src/authorization/list-read-scope.ts +11 -5
- package/src/authorization/model/agent.ts +5 -2
- package/src/authorization/model/agent_instance.ts +2 -0
- package/src/authorization/model/mcp_server.ts +2 -0
- package/src/authorization/model/plugin.ts +4 -1
- package/src/authorization/model/rewrite.ts +13 -8
- package/src/authorization/model/skill.ts +2 -0
- package/src/authorization/model/workflow.ts +2 -0
- package/src/authorization/model/workflow_instance.ts +2 -0
- package/src/authorization/organization-directory.ts +3 -1
- package/src/authorization/store-test-kit.ts +75 -16
- package/src/authorization/tuples.ts +39 -16
- package/src/domain/agent/__tests__/agent.test.ts +4 -11
- package/src/domain/agent/controller.ts +7 -7
- package/src/domain/agentchannel/__tests__/agentchannel.test.ts +48 -223
- package/src/domain/agentchannel/controller.ts +1 -6
- package/src/domain/agentexecution/controller.ts +1 -6
- package/src/domain/agentinstance/controller.ts +12 -6
- package/src/domain/agentshare/__tests__/agentshare.test.ts +172 -196
- package/src/domain/agentshare/__tests__/create-authorization.test.ts +31 -16
- package/src/domain/agentshare/constants.ts +26 -14
- package/src/domain/agentshare/controller.ts +1 -6
- package/src/domain/agentshare/steps.ts +194 -41
- package/src/domain/environment/controller.ts +8 -5
- package/src/domain/executioncontext/controller.ts +1 -5
- package/src/domain/mcpserver/__tests__/mcpserver.test.ts +28 -115
- package/src/domain/mcpserver/__tests__/oauth-handshake.test.ts +18 -53
- package/src/domain/mcpserver/controller.ts +12 -6
- package/src/domain/plugin/controller.ts +8 -1
- package/src/domain/plugin/push.ts +16 -8
- package/src/domain/schedule/controller.ts +1 -6
- package/src/domain/session/controller.ts +4 -12
- package/src/domain/skill/controller.ts +7 -0
- package/src/domain/workflow/controller.ts +10 -28
- package/src/domain/workflow/registry/data/task-kind-registry.json +1 -1
- package/src/domain/workflow/validation/task-config-constraints.ts +3 -7
- package/src/domain/workflowexecution/controller.ts +2 -7
- package/src/domain/workflowinstance/controller.ts +12 -6
- package/src/extensions/__tests__/built-in-authorization-composed.test.ts +19 -32
- package/src/extensions/__tests__/extension-composition.test.ts +4 -4
- package/src/extensions/__tests__/list-read-scope-composed.test.ts +6 -9
- package/src/extensions/authorization-queries.ts +5 -6
- package/src/extensions/list-read-scope.ts +1 -1
- package/src/extensions/resource-authorization.ts +5 -3
- package/src/index.ts +14 -0
- package/src/pipeline/apiresource-meta.ts +10 -21
- package/src/pipeline/steps/__tests__/authorization-tuples.test.ts +31 -18
- package/src/pipeline/steps/__tests__/visibility-gates.test.ts +187 -0
- package/src/pipeline/steps/authorization-tuples.ts +11 -9
- package/src/pipeline/steps/references.ts +70 -578
- package/src/pipeline/steps/visibility-gates.ts +174 -0
- package/src/query/search/__tests__/criteria.test.ts +4 -0
- package/src/query/search/__tests__/query-store.test.ts +40 -11
- package/src/query/search/controller.ts +1 -0
- package/src/query/search/criteria.ts +14 -0
- package/src/query/search/handler.ts +7 -6
- package/src/query/search/query-store.ts +2 -0
- package/src/store/__tests__/store-contract.ts +51 -6
- package/src/store/interface.ts +6 -3
- package/src/store/postgres/__tests__/migrations.test.ts +6 -187
- package/src/store/postgres/__tests__/store-contract.test.ts +2 -0
- package/src/store/postgres/migrations.ts +1 -48
- package/src/store/postgres/store.ts +11 -4
- package/src/store/sqlite/__tests__/migrations.test.ts +5 -191
- package/src/store/sqlite/migrations.ts +1 -45
- package/src/store/sqlite/store.ts +10 -4
- package/dist/domain/workflow/agent-call-references.d.ts +0 -54
- package/dist/domain/workflow/agent-call-references.d.ts.map +0 -1
- package/dist/domain/workflow/agent-call-references.js +0 -97
- package/dist/domain/workflow/agent-call-references.js.map +0 -1
- package/dist/store/public-visibility-retired.d.ts +0 -67
- package/dist/store/public-visibility-retired.d.ts.map +0 -1
- package/dist/store/public-visibility-retired.js +0 -55
- package/dist/store/public-visibility-retired.js.map +0 -1
- package/src/domain/workflow/__tests__/agent-call-references.test.ts +0 -222
- package/src/domain/workflow/agent-call-references.ts +0 -157
- package/src/pipeline/__tests__/supports-visibility.test.ts +0 -112
- package/src/pipeline/steps/__tests__/references.test.ts +0 -703
- package/src/store/__tests__/public-visibility-retired.test.ts +0 -127
- package/src/store/public-visibility-retired.ts +0 -119
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pins the driver-neutral half of the public-visibility data migration
|
|
3
|
-
* (public-visibility-retired.ts): the frozen kind table is exactly the
|
|
4
|
-
* seven kinds that could hold the level, a public row is moved to org with
|
|
5
|
-
* every other byte it carried intact (an unknown field a newer release
|
|
6
|
-
* wrote included), a row at any other level is left alone (undefined, so
|
|
7
|
-
* the driver never rewrites bytes it did not change; a row with no
|
|
8
|
-
* metadata holds no level and is one of these), and bytes that do not
|
|
9
|
-
* decode are a thrown fault, never a skipped row.
|
|
10
|
-
* The drivers' replay tests pin the SQL around this function.
|
|
11
|
-
*/
|
|
12
|
-
import { create, fromBinary, toBinary } from "@bufbuild/protobuf";
|
|
13
|
-
import { BinaryWriter, WireType } from "@bufbuild/protobuf/wire";
|
|
14
|
-
import { describe, expect, it } from "vitest";
|
|
15
|
-
|
|
16
|
-
import { AgentSchema } from "@stigmer/protos/ai/stigmer/agentic/agent/v1/api_pb";
|
|
17
|
-
import { SkillSchema } from "@stigmer/protos/ai/stigmer/agentic/skill/v1/api_pb";
|
|
18
|
-
import { ApiResourceVisibility } from "@stigmer/protos/ai/stigmer/commons/apiresource/enum_pb";
|
|
19
|
-
|
|
20
|
-
import {
|
|
21
|
-
LEVEL_AFTER_RETIREMENT,
|
|
22
|
-
PUBLIC_ROW_KINDS_AT_RETIREMENT,
|
|
23
|
-
movePublicRowToOrg,
|
|
24
|
-
} from "../public-visibility-retired.js";
|
|
25
|
-
|
|
26
|
-
const AGENT = PUBLIC_ROW_KINDS_AT_RETIREMENT[0]!;
|
|
27
|
-
|
|
28
|
-
function agentBytes(visibility: ApiResourceVisibility): Uint8Array {
|
|
29
|
-
return toBinary(
|
|
30
|
-
AgentSchema,
|
|
31
|
-
create(AgentSchema, {
|
|
32
|
-
apiVersion: "agentic.stigmer.ai/v1",
|
|
33
|
-
kind: "Agent",
|
|
34
|
-
metadata: {
|
|
35
|
-
id: "agt_1",
|
|
36
|
-
name: "Public Agent",
|
|
37
|
-
slug: "public-agent",
|
|
38
|
-
org: "acme",
|
|
39
|
-
visibility,
|
|
40
|
-
labels: { team: "platform" },
|
|
41
|
-
},
|
|
42
|
-
spec: { instructions: "a conformant instruction body" },
|
|
43
|
-
}),
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** `bytes` followed by one field this schema does not declare (a newer release's). */
|
|
48
|
-
function withUnknownField(bytes: Uint8Array): Uint8Array {
|
|
49
|
-
const trailer = new BinaryWriter()
|
|
50
|
-
.tag(4093, WireType.LengthDelimited)
|
|
51
|
-
.string("written by a release this one does not know")
|
|
52
|
-
.finish();
|
|
53
|
-
const joined = new Uint8Array(bytes.length + trailer.length);
|
|
54
|
-
joined.set(bytes, 0);
|
|
55
|
-
joined.set(trailer, bytes.length);
|
|
56
|
-
return joined;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
describe("the frozen kind table", () => {
|
|
60
|
-
it("is exactly the seven kinds that could hold the level, by the enum names the drivers store", () => {
|
|
61
|
-
expect(PUBLIC_ROW_KINDS_AT_RETIREMENT.map((entry) => entry.kind)).toEqual([
|
|
62
|
-
"agent",
|
|
63
|
-
"skill",
|
|
64
|
-
"mcp_server",
|
|
65
|
-
"agent_instance",
|
|
66
|
-
"workflow",
|
|
67
|
-
"workflow_instance",
|
|
68
|
-
"plugin",
|
|
69
|
-
]);
|
|
70
|
-
expect(AGENT.schema).toBe(AgentSchema);
|
|
71
|
-
expect(PUBLIC_ROW_KINDS_AT_RETIREMENT[1]!.schema).toBe(SkillSchema);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
describe("movePublicRowToOrg", () => {
|
|
76
|
-
it("moves a public row to org and changes nothing else", () => {
|
|
77
|
-
const moved = movePublicRowToOrg(
|
|
78
|
-
AGENT,
|
|
79
|
-
agentBytes(ApiResourceVisibility.visibility_public),
|
|
80
|
-
);
|
|
81
|
-
expect(moved).toBeDefined();
|
|
82
|
-
const after = fromBinary(AgentSchema, moved!);
|
|
83
|
-
expect(after.metadata?.visibility).toBe(LEVEL_AFTER_RETIREMENT);
|
|
84
|
-
expect(after.metadata?.visibility).toBe(
|
|
85
|
-
ApiResourceVisibility.visibility_org,
|
|
86
|
-
);
|
|
87
|
-
// Every other byte: the moved row re-encodes to exactly the bytes an
|
|
88
|
-
// org row with the same content encodes to.
|
|
89
|
-
expect(moved).toEqual(agentBytes(ApiResourceVisibility.visibility_org));
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("keeps an unknown field a newer release wrote through the round trip", () => {
|
|
93
|
-
const moved = movePublicRowToOrg(
|
|
94
|
-
AGENT,
|
|
95
|
-
withUnknownField(agentBytes(ApiResourceVisibility.visibility_public)),
|
|
96
|
-
);
|
|
97
|
-
expect(moved).toEqual(
|
|
98
|
-
withUnknownField(agentBytes(ApiResourceVisibility.visibility_org)),
|
|
99
|
-
);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("leaves a row at any other level alone", () => {
|
|
103
|
-
for (const level of [
|
|
104
|
-
ApiResourceVisibility.api_resource_visibility_unspecified,
|
|
105
|
-
ApiResourceVisibility.visibility_private,
|
|
106
|
-
ApiResourceVisibility.visibility_org,
|
|
107
|
-
ApiResourceVisibility.visibility_platform,
|
|
108
|
-
]) {
|
|
109
|
-
expect(movePublicRowToOrg(AGENT, agentBytes(level))).toBeUndefined();
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("leaves a message with no metadata alone — it holds no level", () => {
|
|
114
|
-
expect(
|
|
115
|
-
movePublicRowToOrg(
|
|
116
|
-
AGENT,
|
|
117
|
-
toBinary(AgentSchema, create(AgentSchema, { kind: "Agent" })),
|
|
118
|
-
),
|
|
119
|
-
).toBeUndefined();
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("refuses bytes that do not decode as the kind", () => {
|
|
123
|
-
expect(() =>
|
|
124
|
-
movePublicRowToOrg(AGENT, new Uint8Array([0xff, 0xff, 0xff])),
|
|
125
|
-
).toThrow();
|
|
126
|
-
});
|
|
127
|
-
});
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The one data migration both store drivers run when the public visibility
|
|
3
|
-
* level is retired: every stored row that holds `visibility_public` is moved
|
|
4
|
-
* to `visibility_org`, once, in place. The drivers own the SQL (which rows
|
|
5
|
-
* to read, how to write them back, the transaction); this module owns what
|
|
6
|
-
* is edition- and driver-neutral: WHICH kinds could hold the level and HOW
|
|
7
|
-
* one row's bytes are moved.
|
|
8
|
-
*
|
|
9
|
-
* Why a migration and not a sweep. The migration chain is the one place
|
|
10
|
-
* that runs exactly once per database, before any request is served. A
|
|
11
|
-
* public row nobody can set again would otherwise stay readable by every
|
|
12
|
-
* account on a self-hosted install forever, because the level's grant was
|
|
13
|
-
* derived from the row itself; on the hosted edition the rows are moved
|
|
14
|
-
* through the API before this release deploys (the tuple lifecycle is
|
|
15
|
-
* row-driven, and only that path deletes the grant's stored tuple), so the
|
|
16
|
-
* migration there finds none and is the safety net, never the mechanism.
|
|
17
|
-
*
|
|
18
|
-
* Why the kind table is frozen here and not read from the live kind
|
|
19
|
-
* configuration. A migration is a statement about the store AS IT WAS when
|
|
20
|
-
* the level was retired: the seven kinds whose VisibilityConfig declared
|
|
21
|
-
* `supports_public` at that moment are the only kinds a public row can
|
|
22
|
-
* exist under, and a later release that adds or removes a kind must not
|
|
23
|
-
* change what this step does. The list is spelled out with its schemas, the
|
|
24
|
-
* per-consumer kind-to-schema idiom the tree already uses; nothing here
|
|
25
|
-
* reads `kind_meta`. The `kind` strings are the enum NAMES the drivers'
|
|
26
|
-
* `kind` column holds (proto-fields.ts `apiResourceKindName`).
|
|
27
|
-
*
|
|
28
|
-
* Why decode and re-encode rather than patch bytes. `resources.data` is the
|
|
29
|
-
* marshaled proto message; the level is one enum field on the metadata
|
|
30
|
-
* message, and only a decode knows where it is. protobuf-es keeps unknown
|
|
31
|
-
* fields through `fromBinary` and writes them back in `toBinary`, so a row
|
|
32
|
-
* written by a newer or older release than this one loses nothing it
|
|
33
|
-
* carried; every other field is re-encoded from the same values. A row this
|
|
34
|
-
* step cannot decode is a fault that fails the whole transaction (the
|
|
35
|
-
* driver's `applyInTransaction` rolls back and the boot stops): skipping it
|
|
36
|
-
* would leave the one row the migration exists for readable by everyone,
|
|
37
|
-
* silently.
|
|
38
|
-
*
|
|
39
|
-
* `resource_audit` is deliberately untouched: it is the version history,
|
|
40
|
-
* and a snapshot that said "public" at the time is true history. The search
|
|
41
|
-
* index is left to boot's rebuild, which re-derives it from the rows.
|
|
42
|
-
*/
|
|
43
|
-
import type { DescMessage } from "@bufbuild/protobuf";
|
|
44
|
-
import { fromBinary, toBinary } from "@bufbuild/protobuf";
|
|
45
|
-
import { reflect } from "@bufbuild/protobuf/reflect";
|
|
46
|
-
|
|
47
|
-
import { AgentSchema } from "@stigmer/protos/ai/stigmer/agentic/agent/v1/api_pb";
|
|
48
|
-
import { AgentInstanceSchema } from "@stigmer/protos/ai/stigmer/agentic/agentinstance/v1/api_pb";
|
|
49
|
-
import { McpServerSchema } from "@stigmer/protos/ai/stigmer/agentic/mcpserver/v1/api_pb";
|
|
50
|
-
import { PluginSchema } from "@stigmer/protos/ai/stigmer/agentic/plugin/v1/api_pb";
|
|
51
|
-
import { SkillSchema } from "@stigmer/protos/ai/stigmer/agentic/skill/v1/api_pb";
|
|
52
|
-
import { WorkflowSchema } from "@stigmer/protos/ai/stigmer/agentic/workflow/v1/api_pb";
|
|
53
|
-
import { WorkflowInstanceSchema } from "@stigmer/protos/ai/stigmer/agentic/workflowinstance/v1/api_pb";
|
|
54
|
-
import { ApiResourceVisibility } from "@stigmer/protos/ai/stigmer/commons/apiresource/enum_pb";
|
|
55
|
-
|
|
56
|
-
/** One kind that could hold the public level, with the schema its rows decode through. */
|
|
57
|
-
export interface PublicRowKind {
|
|
58
|
-
/** The enum NAME the drivers' `kind` column holds. */
|
|
59
|
-
readonly kind: string;
|
|
60
|
-
readonly schema: DescMessage;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* The seven kinds whose VisibilityConfig declared `supports_public` when the
|
|
65
|
-
* level was retired — frozen (the module header). Order is the order the
|
|
66
|
-
* drivers walk the kinds; it has no other meaning.
|
|
67
|
-
*/
|
|
68
|
-
export const PUBLIC_ROW_KINDS_AT_RETIREMENT: ReadonlyArray<PublicRowKind> = [
|
|
69
|
-
{ kind: "agent", schema: AgentSchema },
|
|
70
|
-
{ kind: "skill", schema: SkillSchema },
|
|
71
|
-
{ kind: "mcp_server", schema: McpServerSchema },
|
|
72
|
-
{ kind: "agent_instance", schema: AgentInstanceSchema },
|
|
73
|
-
{ kind: "workflow", schema: WorkflowSchema },
|
|
74
|
-
{ kind: "workflow_instance", schema: WorkflowInstanceSchema },
|
|
75
|
-
{ kind: "plugin", schema: PluginSchema },
|
|
76
|
-
];
|
|
77
|
-
|
|
78
|
-
/** The level every moved row takes: the widest level that stays inside the owning organization. */
|
|
79
|
-
export const LEVEL_AFTER_RETIREMENT = ApiResourceVisibility.visibility_org;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* The moved bytes of one row when it holds the public level, or undefined
|
|
83
|
-
* when it does not (the driver then leaves the row's bytes exactly as they
|
|
84
|
-
* are; a row with no metadata holds no level and is one of these). Throws
|
|
85
|
-
* when the bytes do not decode as the kind's message: a row this migration
|
|
86
|
-
* cannot read is a row it must not pass over (the module header).
|
|
87
|
-
*/
|
|
88
|
-
export function movePublicRowToOrg(
|
|
89
|
-
entry: PublicRowKind,
|
|
90
|
-
data: Uint8Array,
|
|
91
|
-
): Uint8Array | undefined {
|
|
92
|
-
const message = fromBinary(entry.schema, data);
|
|
93
|
-
const root = reflect(entry.schema, message);
|
|
94
|
-
const metadataField = root.fields.find((field) => field.name === "metadata");
|
|
95
|
-
if (metadataField === undefined || metadataField.fieldKind !== "message") {
|
|
96
|
-
throw new Error(
|
|
97
|
-
`${entry.kind}: the schema declares no metadata message field`,
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
if (!root.isSet(metadataField)) {
|
|
101
|
-
return undefined;
|
|
102
|
-
}
|
|
103
|
-
const metadata = root.get(metadataField);
|
|
104
|
-
const visibilityField = metadata.fields.find(
|
|
105
|
-
(field) => field.name === "visibility",
|
|
106
|
-
);
|
|
107
|
-
if (visibilityField === undefined || visibilityField.fieldKind !== "enum") {
|
|
108
|
-
throw new Error(
|
|
109
|
-
`${entry.kind}: the metadata message declares no visibility enum field`,
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
if (
|
|
113
|
-
metadata.get(visibilityField) !== ApiResourceVisibility.visibility_public
|
|
114
|
-
) {
|
|
115
|
-
return undefined;
|
|
116
|
-
}
|
|
117
|
-
metadata.set(visibilityField, LEVEL_AFTER_RETIREMENT);
|
|
118
|
-
return toBinary(entry.schema, message);
|
|
119
|
-
}
|