@segmentstream/ontology 0.192.0 → 0.193.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 +8 -0
- package/README.md +11 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/permissions.d.ts +2 -1
- package/dist/permissions.js +2 -1
- package/dist/service/agent/server.js +1 -1
- package/dist/service/workflow-callback.d.ts +9 -0
- package/dist/service/workflow-callback.js +7 -0
- package/dist/service/workflows.js +6 -2
- package/dist/workspace-source-history.d.ts +35 -0
- package/dist/workspace-source-history.js +97 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.193.0
|
|
4
|
+
|
|
5
|
+
`workspaceSourceHistory({ since, until, offset? })` reads main's commits of the workspace's own repository whose commit time is in `[since, until)`, at most 31 days, newest first: each commit's `sha`, `author` (`name`, `email`), `committedAt`, `title` and `parents`, with `nextOffset` to continue the window. A production deployment calls it in a workflow step's `run` or an action's `prepare`, for a caller (a member or the workflow's user) whose role grants `workspace_source:read`.
|
|
6
|
+
|
|
7
|
+
## 0.192.1
|
|
8
|
+
|
|
9
|
+
Show the originating chat title in private persona notices and render a labeled settings link as a native channel button.
|
|
10
|
+
|
|
3
11
|
## 0.192.0
|
|
4
12
|
|
|
5
13
|
Apps can opt in to the workspace_memberships sign-in scope with shareWorkspaceMemberships. With the person’s consent, a production ontology action can call workspaceMemberships(principal) during preparation to read current accessible workspace IDs. The person can withdraw consent. Reading workspace content still requires its own grant.
|
package/README.md
CHANGED
|
@@ -1007,7 +1007,8 @@ built-in `agent_chat`, `agent_draft`, `agent_tool`, `app_feedback`, `app_feedbac
|
|
|
1007
1007
|
such as `agent_chat:read` or `agent_chat:*`.
|
|
1008
1008
|
|
|
1009
1009
|
`workspace_source:read` (`WORKSPACE_SOURCE_PERMISSION`) is the built-in permission to read the
|
|
1010
|
-
workspace's deployed code through the agent
|
|
1010
|
+
workspace's deployed code through the agent and main's commit history through
|
|
1011
|
+
`workspaceSourceHistory` (see [The workspace's code](#the-workspaces-code)).
|
|
1011
1012
|
`workspace_source` is no entity: `check` refuses any other verb of it, a scoped grant of it, and
|
|
1012
1013
|
an entity or toolset named `workspace_source`. Only `workspace_source:read` or
|
|
1013
1014
|
`workspace_source:*` grants it; `*:read`, `*:*` and a pipeline workload's `*:*` do not.
|
|
@@ -1688,6 +1689,15 @@ platform resolves the production commit and returns paths or numbered lines. Pas
|
|
|
1688
1689
|
commit to pin follow-up reads. Continue listing or searching with `nextOffset`, including when a
|
|
1689
1690
|
search page has no matches. Source queries work with the sandbox switched off.
|
|
1690
1691
|
|
|
1692
|
+
`workspaceSourceHistory({ since, until, offset? })` reads main's commits whose commit time is in
|
|
1693
|
+
`[since, until)`, at most 31 days, newest first, as the production deployment: `{ commits,
|
|
1694
|
+
nextOffset }`, each commit with `sha`, `author` (`name`, `email`), `committedAt`, `title` and
|
|
1695
|
+
`parents`. Call it in a workflow step's `run` or an action's `prepare`; the caller, a member or
|
|
1696
|
+
the workflow's user, needs `workspace_source:read`. Pass a non-null `nextOffset` back as `offset`
|
|
1697
|
+
with the same window, and count commits by `sha`, since a push between calls can repeat one. It
|
|
1698
|
+
fails with `ActionRejected`: `workspace_source_not_permitted`, `workspace_source_history_invalid`
|
|
1699
|
+
or `workspace_source_unavailable` (outside production, or the platform did not answer).
|
|
1700
|
+
|
|
1691
1701
|
### Agent attachments
|
|
1692
1702
|
|
|
1693
1703
|
Attachments remain separate member-authorized capabilities. Chat posting accepts text only;
|
package/dist/index.d.ts
CHANGED
|
@@ -122,4 +122,6 @@ export type { WorkflowEngine, WorkflowPage, WorkflowRunRecord, WorkflowStepRecor
|
|
|
122
122
|
export { validateBrowserSignIn } from "./sign-in.js";
|
|
123
123
|
export type { BrowserSignInOptions, BrowserSignInMethod } from "./sign-in.js";
|
|
124
124
|
export { workspaceMemberships } from "./workspace-memberships.js";
|
|
125
|
+
export { workspaceSourceHistory } from "./workspace-source-history.js";
|
|
126
|
+
export type { WorkspaceSourceHistory, WorkspaceSourceHistoryQuery, } from "./workspace-source-history.js";
|
|
125
127
|
export { isPrivateReply } from "./runtime-source.js";
|
package/dist/index.js
CHANGED
|
@@ -85,4 +85,5 @@ export { callbackIdentityToken, serveWorkflowCallback } from "./service/workflow
|
|
|
85
85
|
export { compiledWorkflowId, triggerPath, vercelWorkflowEngine, WorkflowStepFailed, } from "./service/workflows.js";
|
|
86
86
|
export { validateBrowserSignIn } from "./sign-in.js";
|
|
87
87
|
export { workspaceMemberships } from "./workspace-memberships.js";
|
|
88
|
+
export { workspaceSourceHistory } from "./workspace-source-history.js";
|
|
88
89
|
export { isPrivateReply } from "./runtime-source.js";
|
package/dist/permissions.d.ts
CHANGED
|
@@ -32,7 +32,8 @@ export declare const EXPLICIT_GRANT_ENTITIES: ReadonlySet<string>;
|
|
|
32
32
|
*/
|
|
33
33
|
export declare const WORKSPACE_SOURCE = "workspace_source";
|
|
34
34
|
/**
|
|
35
|
-
* Reading the workspace's deployed code, through the agent's list, search and read tools
|
|
35
|
+
* Reading the workspace's deployed code, through the agent's list, search and read tools, and main's
|
|
36
|
+
* commit history, through `workspaceSourceHistory`. Only a role that names it grants it.
|
|
36
37
|
*/
|
|
37
38
|
export declare const WORKSPACE_SOURCE_PERMISSION = "workspace_source:read";
|
|
38
39
|
/** Use source access that this member granted to the receiving workspace. */
|
package/dist/permissions.js
CHANGED
|
@@ -40,7 +40,8 @@ export const EXPLICIT_GRANT_ENTITIES = new Set([
|
|
|
40
40
|
*/
|
|
41
41
|
export const WORKSPACE_SOURCE = "workspace_source";
|
|
42
42
|
/**
|
|
43
|
-
* Reading the workspace's deployed code, through the agent's list, search and read tools
|
|
43
|
+
* Reading the workspace's deployed code, through the agent's list, search and read tools, and main's
|
|
44
|
+
* commit history, through `workspaceSourceHistory`. Only a role that names it grants it.
|
|
44
45
|
*/
|
|
45
46
|
export const WORKSPACE_SOURCE_PERMISSION = `${WORKSPACE_SOURCE}:${READ_VERB}`;
|
|
46
47
|
/** Use source access that this member granted to the receiving workspace. */
|
|
@@ -1005,7 +1005,7 @@ export function agentLayer(options) {
|
|
|
1005
1005
|
return json({ chat: null });
|
|
1006
1006
|
}
|
|
1007
1007
|
const id = String(chat.id);
|
|
1008
|
-
return json(
|
|
1008
|
+
return json((yield* claim(id, memberId)) ? { chat: id, title: chat.title } : { chat: null });
|
|
1009
1009
|
})));
|
|
1010
1010
|
}
|
|
1011
1011
|
if (store.readChatPersona !== undefined) {
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
import { Context } from "effect";
|
|
1
2
|
/** The OIDC token of the callback request whose step is running, if it carried one. */
|
|
2
3
|
export declare function callbackIdentityToken(): string | undefined;
|
|
4
|
+
declare const StepIdentityToken_base: Context.ServiceClass<StepIdentityToken, "@segmentstream/ontology/StepIdentityToken", string>;
|
|
5
|
+
/**
|
|
6
|
+
* The deployment's OIDC token a running step captured when it started, for the step's calls to
|
|
7
|
+
* the platform: the callback request's async context may be gone once the step's effect resumes.
|
|
8
|
+
*/
|
|
9
|
+
export declare class StepIdentityToken extends StepIdentityToken_base {
|
|
10
|
+
}
|
|
3
11
|
/** The ontology service of this instance could not be started before a step. */
|
|
4
12
|
export declare class WorkflowServiceUnavailable extends Error {
|
|
5
13
|
constructor(status: number, requestId: string | null);
|
|
@@ -20,3 +28,4 @@ export interface WorkflowCallbackOptions {
|
|
|
20
28
|
* delivery fails and the queue retries it. The request's OIDC token stays available to the steps.
|
|
21
29
|
*/
|
|
22
30
|
export declare function serveWorkflowCallback(request: Request, handler: (request: Request) => Promise<Response>, options: WorkflowCallbackOptions): Promise<Response>;
|
|
31
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Context } from "effect";
|
|
1
2
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
3
|
import { deploymentFromEnv, DeploymentAdmissionError, requireDeploymentCapability, } from "../deployment.js";
|
|
3
4
|
import { workflowBinding, workflowSdk } from "../workflow-runtime.js";
|
|
@@ -9,6 +10,12 @@ const storage = (globalThis[STORAGE] ??= new AsyncLocalStorage());
|
|
|
9
10
|
export function callbackIdentityToken() {
|
|
10
11
|
return storage.getStore()?.identityToken;
|
|
11
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* The deployment's OIDC token a running step captured when it started, for the step's calls to
|
|
15
|
+
* the platform: the callback request's async context may be gone once the step's effect resumes.
|
|
16
|
+
*/
|
|
17
|
+
export class StepIdentityToken extends Context.Service()("@segmentstream/ontology/StepIdentityToken") {
|
|
18
|
+
}
|
|
12
19
|
/**
|
|
13
20
|
* The queue a delivery came from: Vercel Queues name it in the CloudEvent header
|
|
14
21
|
* `ce-vqsqueuename`, the SDK's local world in `x-vqs-queue-name`.
|
|
@@ -26,7 +26,7 @@ import { triggerContext, WorkflowStartFailed, } from "../runtime/workflow-starts
|
|
|
26
26
|
import { RECOVERY_CONFIRM_MS, RECOVERY_COVERAGE_MARGIN_MS, RECOVERY_FIRST_SWEEP_MS, } from "../start-recovery-contract.js";
|
|
27
27
|
import { nextCronTime, } from "../workflow.js";
|
|
28
28
|
import { platformWorkflows, setWorkflowBinding, WORKFLOW_BASE_PATH, workflowSdk, workflowStructures, } from "../workflow-runtime.js";
|
|
29
|
-
import { callbackIdentityToken } from "./workflow-callback.js";
|
|
29
|
+
import { callbackIdentityToken, StepIdentityToken } from "./workflow-callback.js";
|
|
30
30
|
import { bearerEquals } from "./cron-secret.js";
|
|
31
31
|
import { expireAgentTask, startAgentTask, } from "./agent/task-start.js";
|
|
32
32
|
import { CurrentPrincipal, WORKLOAD_TOKEN_TYPE, withPrincipal, workloadKind, } from "./authentication.js";
|
|
@@ -971,7 +971,11 @@ export function workflowsLayer(options) {
|
|
|
971
971
|
.update(`${step.workflowRunId}:${step.stepId}`)
|
|
972
972
|
.digest("hex"),
|
|
973
973
|
}) ?? unavailableFiles;
|
|
974
|
-
|
|
974
|
+
// The workflow user and the step's identity token, for helpers that call the platform
|
|
975
|
+
// as the deployment, such as `workspaceSourceHistory`.
|
|
976
|
+
const services = Context.make(OntologyReads, reads).pipe(Context.add(CurrentPrincipal, Context.get(caller, CurrentPrincipal)), Context.add(RequestId, requestId), Context.merge(identityToken === undefined
|
|
977
|
+
? Context.empty()
|
|
978
|
+
: Context.make(StepIdentityToken, identityToken)), Context.add(Files, files), Context.add(OntologyWrites, writes), Context.add(OntologyActions, actions), Context.merge(connectionContext(workflow.declaration.connections, options.connections({
|
|
975
979
|
identityToken,
|
|
976
980
|
audit: {
|
|
977
981
|
action: `workflow.${workflow.manifest.name}`,
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { ActionRejected } from "./errors.js";
|
|
3
|
+
declare const Result: Schema.Struct<{
|
|
4
|
+
readonly commits: Schema.$Array<Schema.Struct<{
|
|
5
|
+
readonly sha: Schema.String;
|
|
6
|
+
readonly author: Schema.Struct<{
|
|
7
|
+
readonly name: Schema.String;
|
|
8
|
+
readonly email: Schema.String;
|
|
9
|
+
}>;
|
|
10
|
+
/** ISO timestamp of the commit. */
|
|
11
|
+
readonly committedAt: Schema.String;
|
|
12
|
+
/** The first line of the commit message. */
|
|
13
|
+
readonly title: Schema.String;
|
|
14
|
+
/** How many parents the commit has: more than one for a merge. */
|
|
15
|
+
readonly parents: Schema.Int;
|
|
16
|
+
}>>;
|
|
17
|
+
readonly nextOffset: Schema.NullOr<Schema.Int>;
|
|
18
|
+
}>;
|
|
19
|
+
/** A page of main's commits, newest first; `nextOffset` continues the window, or is null. */
|
|
20
|
+
export type WorkspaceSourceHistory = typeof Result.Type;
|
|
21
|
+
export interface WorkspaceSourceHistoryQuery {
|
|
22
|
+
/** The window's start, included: a `Date` or an ISO timestamp with its offset. */
|
|
23
|
+
readonly since: Date | string;
|
|
24
|
+
/** The window's end, excluded, at most 31 days after `since`. */
|
|
25
|
+
readonly until: Date | string;
|
|
26
|
+
/** The `nextOffset` of the previous page of the same window. */
|
|
27
|
+
readonly offset?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Main's commits in the workspace's own repository whose commit time is in `[since, until)`, as the
|
|
31
|
+
* production deployment reads them. The caller (a member, or a workflow's user in a step) must
|
|
32
|
+
* hold `workspace_source:read`. Use it in an action's `prepare` or in a workflow step's `run`.
|
|
33
|
+
*/
|
|
34
|
+
export declare const workspaceSourceHistory: (query: WorkspaceSourceHistoryQuery) => Effect.Effect<WorkspaceSourceHistory, ActionRejected>;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Effect, Option, Schema } from "effect";
|
|
2
|
+
import { HttpServerRequest } from "effect/unstable/http";
|
|
3
|
+
import { ActionRejected } from "./errors.js";
|
|
4
|
+
import { isAllowed, WORKSPACE_SOURCE_PERMISSION } from "./permissions.js";
|
|
5
|
+
import { CurrentPrincipal } from "./service/authentication.js";
|
|
6
|
+
import { OIDC_TOKEN_HEADER } from "./service/connections.js";
|
|
7
|
+
import { RequestId } from "./service/errors.js";
|
|
8
|
+
import { StepIdentityToken } from "./service/workflow-callback.js";
|
|
9
|
+
const UNAVAILABLE = "workspace_source_unavailable";
|
|
10
|
+
const NOT_PERMITTED = "workspace_source_not_permitted";
|
|
11
|
+
const INVALID = "workspace_source_history_invalid";
|
|
12
|
+
const TIMEOUT_MS = 60_000;
|
|
13
|
+
const Result = Schema.Struct({
|
|
14
|
+
commits: Schema.Array(Schema.Struct({
|
|
15
|
+
sha: Schema.String,
|
|
16
|
+
author: Schema.Struct({ name: Schema.String, email: Schema.String }),
|
|
17
|
+
/** ISO timestamp of the commit. */
|
|
18
|
+
committedAt: Schema.String,
|
|
19
|
+
/** The first line of the commit message. */
|
|
20
|
+
title: Schema.String,
|
|
21
|
+
/** How many parents the commit has: more than one for a merge. */
|
|
22
|
+
parents: Schema.Int,
|
|
23
|
+
})),
|
|
24
|
+
nextOffset: Schema.NullOr(Schema.Int),
|
|
25
|
+
});
|
|
26
|
+
const timestamp = (value) => typeof value === "string"
|
|
27
|
+
? value
|
|
28
|
+
: Number.isNaN(value.getTime())
|
|
29
|
+
? undefined
|
|
30
|
+
: value.toISOString();
|
|
31
|
+
/**
|
|
32
|
+
* Main's commits in the workspace's own repository whose commit time is in `[since, until)`, as the
|
|
33
|
+
* production deployment reads them. The caller (a member, or a workflow's user in a step) must
|
|
34
|
+
* hold `workspace_source:read`. Use it in an action's `prepare` or in a workflow step's `run`.
|
|
35
|
+
*/
|
|
36
|
+
export const workspaceSourceHistory = (query) => Effect.gen(function* () {
|
|
37
|
+
const principal = yield* Effect.serviceOption(CurrentPrincipal);
|
|
38
|
+
if (Option.isNone(principal)) {
|
|
39
|
+
return yield* new ActionRejected({ message: UNAVAILABLE });
|
|
40
|
+
}
|
|
41
|
+
if (!isAllowed(WORKSPACE_SOURCE_PERMISSION, principal.value)) {
|
|
42
|
+
return yield* new ActionRejected({ message: NOT_PERMITTED });
|
|
43
|
+
}
|
|
44
|
+
const since = timestamp(query.since);
|
|
45
|
+
const until = timestamp(query.until);
|
|
46
|
+
if (since === undefined || until === undefined) {
|
|
47
|
+
return yield* new ActionRejected({ message: INVALID });
|
|
48
|
+
}
|
|
49
|
+
const { configFromEnv } = yield* Effect.promise(() => import("./service/config.js"));
|
|
50
|
+
const config = yield* Effect.try({
|
|
51
|
+
try: () => configFromEnv(),
|
|
52
|
+
catch: (cause) => new ActionRejected({ message: UNAVAILABLE, cause }),
|
|
53
|
+
});
|
|
54
|
+
if (config.deployment?.target !== "production") {
|
|
55
|
+
return yield* new ActionRejected({ message: UNAVAILABLE });
|
|
56
|
+
}
|
|
57
|
+
const step = yield* Effect.serviceOption(StepIdentityToken);
|
|
58
|
+
const request = yield* Effect.serviceOption(HttpServerRequest.HttpServerRequest);
|
|
59
|
+
const token = Option.getOrUndefined(step) ||
|
|
60
|
+
(Option.isSome(request) ? request.value.headers[OIDC_TOKEN_HEADER] : undefined) ||
|
|
61
|
+
process.env.VERCEL_OIDC_TOKEN;
|
|
62
|
+
if (!token) {
|
|
63
|
+
return yield* new ActionRejected({ message: UNAVAILABLE });
|
|
64
|
+
}
|
|
65
|
+
const requestId = Option.getOrUndefined(yield* Effect.serviceOption(RequestId));
|
|
66
|
+
const url = new URL("/api/internal/v1/workspaces/" +
|
|
67
|
+
encodeURIComponent(config.workspaceId) +
|
|
68
|
+
"/ontology/source/history", config.segmentstreamUrl);
|
|
69
|
+
const body = { since, until, ...(query.offset === undefined ? {} : { offset: query.offset }) };
|
|
70
|
+
const answer = yield* Effect.tryPromise({
|
|
71
|
+
try: async (signal) => {
|
|
72
|
+
const response = await fetch(url, {
|
|
73
|
+
method: "POST",
|
|
74
|
+
cache: "no-store",
|
|
75
|
+
redirect: "error",
|
|
76
|
+
signal: AbortSignal.any([signal, AbortSignal.timeout(TIMEOUT_MS)]),
|
|
77
|
+
headers: {
|
|
78
|
+
"content-type": "application/json",
|
|
79
|
+
"x-segmentstream-organization-id": config.organizationId,
|
|
80
|
+
"x-segmentstream-runtime-identity": token,
|
|
81
|
+
"x-segmentstream-ontology-principal": principal.value.id,
|
|
82
|
+
...(requestId === undefined ? {} : { "x-segmentstream-request-id": requestId }),
|
|
83
|
+
},
|
|
84
|
+
body: JSON.stringify(body),
|
|
85
|
+
});
|
|
86
|
+
return { status: response.status, body: response.ok ? await response.json() : undefined };
|
|
87
|
+
},
|
|
88
|
+
catch: (cause) => new ActionRejected({ message: UNAVAILABLE, cause }),
|
|
89
|
+
});
|
|
90
|
+
if (answer.status === 400) {
|
|
91
|
+
return yield* new ActionRejected({ message: INVALID });
|
|
92
|
+
}
|
|
93
|
+
if (answer.status !== 200) {
|
|
94
|
+
return yield* new ActionRejected({ message: UNAVAILABLE, cause: { status: answer.status } });
|
|
95
|
+
}
|
|
96
|
+
return yield* Schema.decodeUnknownEffect(Result)(answer.body).pipe(Effect.mapError((cause) => new ActionRejected({ message: UNAVAILABLE, cause })));
|
|
97
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.193.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",
|