@segmentstream/ontology 0.186.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 +13 -0
- package/README.md +8 -12
- 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/dist/workflow.d.ts +2 -2
- package/dist/workflow.js +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
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
|
+
|
|
9
|
+
## 0.187.0
|
|
10
|
+
|
|
11
|
+
An ontology may declare 100 action triggers (`after(…)`), up from 50. `MAX_ACTION_TRIGGERS` is 100,
|
|
12
|
+
and `check` and publication report `workflow_trigger_limit_exceeded` above it. A workflow may carry
|
|
13
|
+
several action triggers, so the count can exceed the 50 workflows an ontology may declare. Each
|
|
14
|
+
trigger still adds its work to every action on its entity, inside that action's transaction.
|
|
15
|
+
|
|
3
16
|
## 0.186.0
|
|
4
17
|
|
|
5
18
|
The ontology's Slack messages, a post in either voice (`agent_chat.send`), a draft a member approves
|
package/README.md
CHANGED
|
@@ -627,7 +627,7 @@ export default workflow("remindStaleLeads", {
|
|
|
627
627
|
(`{ record, before, after }`, typed as the entity's records); `input` omitted means `{}`.
|
|
628
628
|
`changed(field, { from?, to? })` is a `when` for the common case. A workflow reacts to an action,
|
|
629
629
|
not to a field. The manifest records the kind, name, description, entity and action, never the
|
|
630
|
-
functions. At most
|
|
630
|
+
functions. At most 100 action triggers per ontology; `check` reports `invalid-trigger`,
|
|
631
631
|
`trigger_action_unknown`, `trigger_function_async` and `workflow_trigger_limit_exceeded`.
|
|
632
632
|
- `webhook(name, { description, signature?, headers? })` starts the workflow for each delivery a
|
|
633
633
|
provider pushes to `/api/webhooks/<name>`, whose wire name is unique across the ontology. The
|
|
@@ -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/dist/workflow.d.ts
CHANGED
|
@@ -16,9 +16,9 @@ export declare const MAX_WORKFLOWS = 50;
|
|
|
16
16
|
* action evaluates the triggers on its entity inside its own transaction, so this bounds the work
|
|
17
17
|
* one action can add: about 4 to 6 ms per trigger for a batch create of 100 records, nothing
|
|
18
18
|
* measurable for a single update. It does not bound the runs a bulk action starts, one per edited
|
|
19
|
-
* record.
|
|
19
|
+
* record. A workflow may carry several, so it exceeds the workflows an ontology may declare.
|
|
20
20
|
*/
|
|
21
|
-
export declare const MAX_ACTION_TRIGGERS =
|
|
21
|
+
export declare const MAX_ACTION_TRIGGERS = 100;
|
|
22
22
|
/**
|
|
23
23
|
* What a trigger listed in `defineOntology({ triggers })` runs instead of a workflow: one action,
|
|
24
24
|
* in a durable run retried like a step, as the trigger's own workflow user holding `role`. The
|
package/dist/workflow.js
CHANGED
|
@@ -10,9 +10,9 @@ export const MAX_WORKFLOWS = 50;
|
|
|
10
10
|
* action evaluates the triggers on its entity inside its own transaction, so this bounds the work
|
|
11
11
|
* one action can add: about 4 to 6 ms per trigger for a batch create of 100 records, nothing
|
|
12
12
|
* measurable for a single update. It does not bound the runs a bulk action starts, one per edited
|
|
13
|
-
* record.
|
|
13
|
+
* record. A workflow may carry several, so it exceeds the workflows an ontology may declare.
|
|
14
14
|
*/
|
|
15
|
-
export const MAX_ACTION_TRIGGERS =
|
|
15
|
+
export const MAX_ACTION_TRIGGERS = 100;
|
|
16
16
|
/** Declares a cron trigger; list it in `workflow(name, { triggers })`. UTC, five fields. */
|
|
17
17
|
export function cron(name, expression, options) {
|
|
18
18
|
return {
|
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",
|