@segmentstream/ontology 0.187.0 → 0.188.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/CHANGELOG.md +6 -0
- package/README.md +7 -11
- package/dist/service/agent/source.d.ts +4 -10
- package/dist/service/agent/source.js +23 -42
- package/dist/service/service.js +7 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.188.0
|
|
4
|
+
|
|
5
|
+
List, search and read deployed workspace code with the current member’s explicit
|
|
6
|
+
`workspace_source:read` permission. Upgrade both SDKs together. Source tools run independently
|
|
7
|
+
of the sandbox and replace the workspace source copy.
|
|
8
|
+
|
|
3
9
|
## 0.187.0
|
|
4
10
|
|
|
5
11
|
An ontology may declare 100 action triggers (`after(…)`), up from 50. `MAX_ACTION_TRIGGERS` is 100,
|
package/README.md
CHANGED
|
@@ -1677,17 +1677,13 @@ remain readable. Use `segmentstream ontology member list --via PROVIDER` to find
|
|
|
1677
1677
|
|
|
1678
1678
|
### The workspace's code
|
|
1679
1679
|
|
|
1680
|
-
`
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
answers with SegmentStream's status, body (a gzip-compressed tar archive, or a JSON error) and
|
|
1688
|
-
`x-segmentstream-source-*` headers unchanged. Without a Vercel OIDC token it answers 503
|
|
1689
|
-
`workspace_source_unavailable`. It logs `ontology.workspace_source.page` with the request, the
|
|
1690
|
-
member and the commit, never a path. It is no MCP tool.
|
|
1680
|
+
Enable `workspaceSource` in `agent/segmentstream.json` and grant `workspace_source:read` to
|
|
1681
|
+
the roles allowed to inspect the deployed workspace. The agent gets
|
|
1682
|
+
`segmentstream__list_workspace_files`, `segmentstream__search_workspace_source` and
|
|
1683
|
+
`segmentstream__read_workspace_file`. The ontology checks the active member on every call. The
|
|
1684
|
+
platform resolves the production commit and returns paths or numbered lines. Pass the returned
|
|
1685
|
+
commit to pin follow-up reads. Continue listing or searching with `nextOffset`, including when a
|
|
1686
|
+
search page has no matches. Source queries work with the sandbox switched off.
|
|
1691
1687
|
|
|
1692
1688
|
### Agent attachments
|
|
1693
1689
|
|
|
@@ -3,8 +3,8 @@ import { HttpRouter } from "effect/unstable/http";
|
|
|
3
3
|
import { RequestId } from "../errors.js";
|
|
4
4
|
import { OntologyBackend } from "../runtime-contract.js";
|
|
5
5
|
import type { RuntimeTokenVerifier } from "../runtime-identity.js";
|
|
6
|
-
/**
|
|
7
|
-
export declare const WORKSPACE_SOURCE_PATH = "/api/ontology/agent/source";
|
|
6
|
+
/** Query the workspace's deployed source as the active member. */
|
|
7
|
+
export declare const WORKSPACE_SOURCE_PATH = "/api/ontology/agent/source/query";
|
|
8
8
|
/** Where the deployed ontology service reaches backend-next, as its connection calls do. */
|
|
9
9
|
export interface WorkspaceSourceEnvironment {
|
|
10
10
|
readonly segmentstreamUrl: string;
|
|
@@ -12,14 +12,8 @@ export interface WorkspaceSourceEnvironment {
|
|
|
12
12
|
readonly organizationId: string;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* deployment's runtime token authenticates, never an API key or a task's secret; the member named
|
|
18
|
-
* by `X-SegmentStream-Act-As` must be active, paired with the agent and hold
|
|
19
|
-
* `workspace_source:read`, which no wildcard grants, before backend-next is called. The route
|
|
20
|
-
* forwards the cursor with the request's Vercel OIDC token and answers with backend-next's status,
|
|
21
|
-
* body and `x-segmentstream-source-*` headers as they are. It is no MCP tool, and it is not served
|
|
22
|
-
* without runtime authentication or the agent's tables.
|
|
15
|
+
* The agent's source endpoint rechecks the current paired member's explicit permission for every
|
|
16
|
+
* query, then forwards it to the platform using the production deployment's OIDC identity.
|
|
23
17
|
*/
|
|
24
18
|
export declare function workspaceSourceLayer(options: {
|
|
25
19
|
readonly environment: WorkspaceSourceEnvironment;
|
|
@@ -7,13 +7,9 @@ import { identityToken } from "../operations.js";
|
|
|
7
7
|
import { OntologyBackend } from "../runtime-contract.js";
|
|
8
8
|
import { authenticateAgentRuntimeMember } from "./authentication.js";
|
|
9
9
|
import { AGENT_PATH } from "./server.js";
|
|
10
|
-
/**
|
|
11
|
-
export const WORKSPACE_SOURCE_PATH = `${AGENT_PATH}/source`;
|
|
12
|
-
|
|
13
|
-
const SOURCE_HEADER_PREFIX = "x-segmentstream-source-";
|
|
14
|
-
const COMMIT_HEADER = `${SOURCE_HEADER_PREFIX}commit`;
|
|
15
|
-
/** A page is at most a few megabytes, which backend-next reads from the workspace's repository. */
|
|
16
|
-
const PAGE_TIMEOUT_MS = 60_000;
|
|
10
|
+
/** Query the workspace's deployed source as the active member. */
|
|
11
|
+
export const WORKSPACE_SOURCE_PATH = `${AGENT_PATH}/source/query`;
|
|
12
|
+
const QUERY_TIMEOUT_MS = 60_000;
|
|
17
13
|
const UNAVAILABLE = "workspace_source_unavailable";
|
|
18
14
|
function refusal(status, error, detail, requestId) {
|
|
19
15
|
return HttpServerResponse.jsonUnsafe(errorBodyForWire({ error, detail, requestId }), {
|
|
@@ -21,37 +17,27 @@ function refusal(status, error, detail, requestId) {
|
|
|
21
17
|
headers: { "cache-control": "no-store" },
|
|
22
18
|
});
|
|
23
19
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
* Vercel OIDC token and takes the member's id for its log only.
|
|
27
|
-
*/
|
|
28
|
-
function fetchPage(input) {
|
|
29
|
-
const { environment, token, member, cursor, requestId } = input;
|
|
20
|
+
function fetchQuery(input) {
|
|
21
|
+
const { environment, token, member, requestId } = input;
|
|
30
22
|
const url = `${environment.segmentstreamUrl}/api/internal/v1/workspaces/` +
|
|
31
|
-
`${encodeURIComponent(environment.workspaceId)}/ontology/source
|
|
32
|
-
(cursor === null ? "" : `?cursor=${encodeURIComponent(cursor)}`);
|
|
23
|
+
`${encodeURIComponent(environment.workspaceId)}/ontology/source/query`;
|
|
33
24
|
return Effect.tryPromise({
|
|
34
25
|
try: async (signal) => {
|
|
35
26
|
const response = await input.fetch(url, {
|
|
36
|
-
method: "
|
|
27
|
+
method: "POST",
|
|
28
|
+
body: input.query,
|
|
37
29
|
redirect: "error",
|
|
38
30
|
headers: {
|
|
31
|
+
"content-type": "application/json",
|
|
39
32
|
"x-segmentstream-runtime-identity": token,
|
|
40
33
|
"x-segmentstream-organization-id": environment.organizationId,
|
|
41
34
|
"x-segmentstream-ontology-principal": member.id,
|
|
42
35
|
"x-segmentstream-request-id": requestId,
|
|
43
36
|
},
|
|
44
|
-
signal: AbortSignal.any([signal, AbortSignal.timeout(
|
|
45
|
-
});
|
|
46
|
-
const headers = {};
|
|
47
|
-
response.headers.forEach((value, name) => {
|
|
48
|
-
if (name === "content-type" || name.startsWith(SOURCE_HEADER_PREFIX)) {
|
|
49
|
-
headers[name] = value;
|
|
50
|
-
}
|
|
37
|
+
signal: AbortSignal.any([signal, AbortSignal.timeout(QUERY_TIMEOUT_MS)]),
|
|
51
38
|
});
|
|
52
39
|
return {
|
|
53
40
|
status: response.status,
|
|
54
|
-
headers,
|
|
55
41
|
body: new Uint8Array(await response.arrayBuffer()),
|
|
56
42
|
};
|
|
57
43
|
},
|
|
@@ -59,14 +45,8 @@ function fetchPage(input) {
|
|
|
59
45
|
});
|
|
60
46
|
}
|
|
61
47
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* deployment's runtime token authenticates, never an API key or a task's secret; the member named
|
|
65
|
-
* by `X-SegmentStream-Act-As` must be active, paired with the agent and hold
|
|
66
|
-
* `workspace_source:read`, which no wildcard grants, before backend-next is called. The route
|
|
67
|
-
* forwards the cursor with the request's Vercel OIDC token and answers with backend-next's status,
|
|
68
|
-
* body and `x-segmentstream-source-*` headers as they are. It is no MCP tool, and it is not served
|
|
69
|
-
* without runtime authentication or the agent's tables.
|
|
48
|
+
* The agent's source endpoint rechecks the current paired member's explicit permission for every
|
|
49
|
+
* query, then forwards it to the platform using the production deployment's OIDC identity.
|
|
70
50
|
*/
|
|
71
51
|
export function workspaceSourceLayer(options) {
|
|
72
52
|
return Layer.effectDiscard(Effect.gen(function* () {
|
|
@@ -77,7 +57,7 @@ export function workspaceSourceLayer(options) {
|
|
|
77
57
|
if (agents === undefined || verify === undefined) {
|
|
78
58
|
return;
|
|
79
59
|
}
|
|
80
|
-
const
|
|
60
|
+
const query = (request) => Effect.gen(function* () {
|
|
81
61
|
const requestId = yield* RequestId;
|
|
82
62
|
const authenticated = yield* authenticateAgentRuntimeMember({ request, agents, verify });
|
|
83
63
|
if (!authenticated.ok) {
|
|
@@ -95,13 +75,16 @@ export function workspaceSourceLayer(options) {
|
|
|
95
75
|
return refusal(503, UNAVAILABLE, "The request carries no Vercel OIDC token. The workspace's code is available to " +
|
|
96
76
|
"production deployments.", requestId);
|
|
97
77
|
}
|
|
98
|
-
const
|
|
99
|
-
|
|
78
|
+
const input = yield* Effect.result(request.text);
|
|
79
|
+
if (Result.isFailure(input) || !input.success || input.success.length > 8192) {
|
|
80
|
+
return refusal(400, "invalid_request", "Invalid source query.", requestId);
|
|
81
|
+
}
|
|
82
|
+
const answered = yield* Effect.result(fetchQuery({
|
|
100
83
|
environment: options.environment,
|
|
101
84
|
fetch: fetchImpl,
|
|
102
85
|
token,
|
|
103
86
|
member,
|
|
104
|
-
|
|
87
|
+
query: input.success,
|
|
105
88
|
requestId,
|
|
106
89
|
}));
|
|
107
90
|
if (Result.isFailure(answered)) {
|
|
@@ -111,18 +94,16 @@ export function workspaceSourceLayer(options) {
|
|
|
111
94
|
}));
|
|
112
95
|
return refusal(503, UNAVAILABLE, "The workspace's code could not be read.", requestId);
|
|
113
96
|
}
|
|
114
|
-
const { status,
|
|
115
|
-
|
|
116
|
-
yield* Effect.logInfo("ontology.workspace_source.page").pipe(Effect.annotateLogs({
|
|
97
|
+
const { status, body } = answered.success;
|
|
98
|
+
yield* Effect.logInfo("ontology.workspace_source.query").pipe(Effect.annotateLogs({
|
|
117
99
|
requestId,
|
|
118
100
|
memberId: member.id,
|
|
119
|
-
commit: headers[COMMIT_HEADER] ?? null,
|
|
120
101
|
}));
|
|
121
102
|
return HttpServerResponse.uint8Array(body, {
|
|
122
103
|
status,
|
|
123
|
-
headers: {
|
|
104
|
+
headers: { "content-type": "application/json", "cache-control": "no-store" },
|
|
124
105
|
});
|
|
125
106
|
});
|
|
126
|
-
yield* router.add("
|
|
107
|
+
yield* router.add("POST", WORKSPACE_SOURCE_PATH, query);
|
|
127
108
|
}));
|
|
128
109
|
}
|
package/dist/service/service.js
CHANGED
|
@@ -11,7 +11,7 @@ import { nameToWire } from "../authoring-names.js";
|
|
|
11
11
|
import { bundledNavigationCatalog } from "../navigation-artifact.js";
|
|
12
12
|
import { parsePageCatalog } from "../navigation-catalog.js";
|
|
13
13
|
import { chatRetentionDaysOf, declaredChatRetentionDaysOf, guestOf, signUpOriginsOf, signUpRolesOf, } from "../manifest.js";
|
|
14
|
-
import { allowsAction } from "../permissions.js";
|
|
14
|
+
import { allowsAction, isAllowed, WORKSPACE_SOURCE_PERMISSION } from "../permissions.js";
|
|
15
15
|
import { agentToolsFor } from "../runtime/guests.js";
|
|
16
16
|
import { implicitMemberOf } from "../role.js";
|
|
17
17
|
import { sqlServiceRuntime } from "../runtime/service-binding.js";
|
|
@@ -433,7 +433,12 @@ export function createOntologyService(ontology, config) {
|
|
|
433
433
|
decide: config.decisions,
|
|
434
434
|
}), oauth);
|
|
435
435
|
// Every answer that tells the agent whom it acts for names the agent's own tools they hold.
|
|
436
|
-
const agentTools = (principal) =>
|
|
436
|
+
const agentTools = (principal) => {
|
|
437
|
+
const tools = agentToolsFor(ontology, principal);
|
|
438
|
+
return principal.kind === "member" && isAllowed(WORKSPACE_SOURCE_PERMISSION, principal)
|
|
439
|
+
? [...tools, "workspace_source"]
|
|
440
|
+
: tools;
|
|
441
|
+
};
|
|
437
442
|
const guest = guestOf(ontology.manifest);
|
|
438
443
|
// A guest proves an address with the app's own code email, which needs the production app.
|
|
439
444
|
const emailCodes = config.emailCodes ??
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.188.0",
|
|
4
4
|
"description": "Define a SegmentStream workspace app's ontology: entities, relationships, roles and actions, written with Effect.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "SegmentStream",
|