@segmentstream/ontology 0.189.0 → 0.190.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 +3 -0
- package/dist/analyze.js +4 -5
- package/dist/bin/check.d.ts +5 -0
- package/dist/bin/check.js +7 -0
- package/dist/bin/installed.d.ts +23 -0
- package/dist/bin/installed.js +62 -0
- package/dist/bin/main.d.ts +2 -0
- package/dist/bin.js +16 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/permissions.d.ts +4 -3
- package/dist/permissions.js +4 -3
- package/dist/runtime/agents.js +5 -1
- package/dist/service/agent/source.d.ts +4 -0
- package/dist/service/agent/source.js +43 -7
- package/dist/service/runtime-contract.d.ts +1 -0
- package/dist/service/service.js +11 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.190.0
|
|
4
|
+
|
|
5
|
+
Let a linked member authorize source reads for selected workspaces in a private conversation, with an expiry and revocation.
|
|
6
|
+
|
|
7
|
+
## 0.189.1
|
|
8
|
+
|
|
9
|
+
`segmentstream-ontology check` first compares its own release with the one the component's
|
|
10
|
+
`package-lock.json` pins, which a deployment installs. When they differ, as after a `git pull`
|
|
11
|
+
that brings a new lockfile without reinstalling `node_modules`, it checks nothing and says so,
|
|
12
|
+
naming both releases and the reinstall command, such as `npm --prefix ontology ci`. Before, it
|
|
13
|
+
judged the new code by the installed release's rules and could report errors, such as a lower
|
|
14
|
+
limit, that the deployment does not have.
|
|
15
|
+
|
|
3
16
|
## 0.189.0
|
|
4
17
|
|
|
5
18
|
A staff read of a chat may ask for what the agent kept in it for staff.
|
package/README.md
CHANGED
|
@@ -1793,6 +1793,9 @@ npx segmentstream-ontology migrate [entry] # plan and apply the migrat
|
|
|
1793
1793
|
```
|
|
1794
1794
|
|
|
1795
1795
|
- `check` prints errors and warnings on stderr with their paths. It fails on any error.
|
|
1796
|
+
When the folder's `package-lock.json` pins another release of the SDK than the one installed,
|
|
1797
|
+
which a deployment would install instead, `check` judges nothing and names the reinstall
|
|
1798
|
+
command, such as `npm --prefix ontology ci`.
|
|
1796
1799
|
- `migrate` checks the ontology, reads the catalog recorded in the database, plans the
|
|
1797
1800
|
migration and applies it with the planner and applier the deploy pipeline uses. Use
|
|
1798
1801
|
the owner connection string (`ontology_owner`, direct connection) of a Neon development
|
package/dist/analyze.js
CHANGED
|
@@ -3141,7 +3141,7 @@ function ownMembers(candidate, entitiesByName) {
|
|
|
3141
3141
|
* The verbs each entity has: `read`, its generated actions, and what its actions require. The
|
|
3142
3142
|
* built-in user also has its member management verbs, and the built-in sign-in identities their
|
|
3143
3143
|
* attach and revoke, which roles may grant. The built-in `workspace_source`, which is no entity,
|
|
3144
|
-
* has `read`
|
|
3144
|
+
* has `read` and `connect`, and the built-in `agent_tool`, no entity either, the agent's own tools.
|
|
3145
3145
|
*/
|
|
3146
3146
|
function knownVerbs(entities, toolsets = []) {
|
|
3147
3147
|
const verbs = new Map();
|
|
@@ -3178,7 +3178,7 @@ function knownVerbs(entities, toolsets = []) {
|
|
|
3178
3178
|
}
|
|
3179
3179
|
}
|
|
3180
3180
|
// Last, so that an entity or a toolset of the name, which check refuses, adds no verb to it.
|
|
3181
|
-
verbs.set(WORKSPACE_SOURCE, new Set([READ_VERB]));
|
|
3181
|
+
verbs.set(WORKSPACE_SOURCE, new Set([READ_VERB, "connect"]));
|
|
3182
3182
|
verbs.set(AGENT_TOOL, new Set(AGENT_TOOL_VERBS));
|
|
3183
3183
|
return verbs;
|
|
3184
3184
|
}
|
|
@@ -3741,9 +3741,8 @@ function checkScope(input) {
|
|
|
3741
3741
|
"permission by name, such as staff_member:update, or list the wildcard as a string.");
|
|
3742
3742
|
return;
|
|
3743
3743
|
}
|
|
3744
|
-
if (parsed.entity === WORKSPACE_SOURCE
|
|
3745
|
-
report("invalid-scope", path, `${permission}
|
|
3746
|
-
`${WORKSPACE_SOURCE_PERMISSION} as a string in the roles that may read the code.`);
|
|
3744
|
+
if (parsed.entity === WORKSPACE_SOURCE) {
|
|
3745
|
+
report("invalid-scope", path, `${permission} has no records to scope; grant it as a string to the roles that may use it.`);
|
|
3747
3746
|
return;
|
|
3748
3747
|
}
|
|
3749
3748
|
if (parsed.entity === AGENT_TOOL && verbs.get(AGENT_TOOL)?.has(parsed.verb) === true) {
|
package/dist/bin/check.d.ts
CHANGED
|
@@ -10,6 +10,11 @@ export interface CheckInput {
|
|
|
10
10
|
export interface CheckDependencies {
|
|
11
11
|
readonly load: OntologyLoader;
|
|
12
12
|
readonly output: Output;
|
|
13
|
+
/**
|
|
14
|
+
* Why this SDK must not judge the ontology at an entry, such as another release pinned in the
|
|
15
|
+
* project's lockfile; see `lockedReleaseMismatch`. Without it, nothing is compared.
|
|
16
|
+
*/
|
|
17
|
+
readonly lockedRelease?: (entry: string) => Promise<string | undefined>;
|
|
13
18
|
}
|
|
14
19
|
type Loaded = Extract<LoadResult, {
|
|
15
20
|
readonly _tag: "Loaded";
|
package/dist/bin/check.js
CHANGED
|
@@ -78,6 +78,13 @@ export async function loadCheckedOntology(entry, dependencies) {
|
|
|
78
78
|
*/
|
|
79
79
|
export async function checkCommand(input, dependencies) {
|
|
80
80
|
const { output } = dependencies;
|
|
81
|
+
// Checked by another release than a deployment installs, the ontology could fail on rules the
|
|
82
|
+
// deployment does not have, or pass ones it does.
|
|
83
|
+
const mismatch = await dependencies.lockedRelease?.(input.entry);
|
|
84
|
+
if (mismatch !== undefined) {
|
|
85
|
+
output.stderr(`${mismatch}\n`);
|
|
86
|
+
return EXIT_CODES.failed;
|
|
87
|
+
}
|
|
81
88
|
const loaded = await loadCheckedOntology(input.entry, dependencies);
|
|
82
89
|
if (loaded === undefined) {
|
|
83
90
|
return EXIT_CODES.failed;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** The SDK's name, as a project's package-lock.json lists it. */
|
|
2
|
+
export declare const SDK_PACKAGE = "@segmentstream/ontology";
|
|
3
|
+
/** Reads a file's text, or undefined when there is none. */
|
|
4
|
+
export type ReadText = (path: string) => Promise<string | undefined>;
|
|
5
|
+
/**
|
|
6
|
+
* Why this SDK must not check the ontology at `entry`: its package's package-lock.json pins
|
|
7
|
+
* another release of the SDK, the one a deployment installs. That happens after a pull brings a
|
|
8
|
+
* new lockfile and node_modules is not reinstalled; the check would then judge the ontology by an
|
|
9
|
+
* older or newer release's rules. Undefined when they agree, when the package has no
|
|
10
|
+
* package-lock.json, and for an unreleased build of the SDK (version 0.0.0).
|
|
11
|
+
*/
|
|
12
|
+
export declare function lockedReleaseMismatch(input: {
|
|
13
|
+
readonly entry: string;
|
|
14
|
+
readonly cwd: string;
|
|
15
|
+
/**
|
|
16
|
+
* Where the person or agent ran the command, which the reinstall command is relative to:
|
|
17
|
+
* `npm --prefix ontology run check` runs in ontology/ but is typed above it. Defaults to `cwd`.
|
|
18
|
+
*/
|
|
19
|
+
readonly invokedFrom?: string | undefined;
|
|
20
|
+
/** The version of the SDK running this command. */
|
|
21
|
+
readonly version: string | undefined;
|
|
22
|
+
readonly read: ReadText;
|
|
23
|
+
}): Promise<string | undefined>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
2
|
+
/** The SDK's name, as a project's package-lock.json lists it. */
|
|
3
|
+
export const SDK_PACKAGE = "@segmentstream/ontology";
|
|
4
|
+
function record(value) {
|
|
5
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
6
|
+
? value
|
|
7
|
+
: undefined;
|
|
8
|
+
}
|
|
9
|
+
function parsed(text) {
|
|
10
|
+
if (text === undefined) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
return record(JSON.parse(text));
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** The directory of the package that holds the entry: the nearest one with a package.json. */
|
|
21
|
+
async function packageDirectory(entry, read) {
|
|
22
|
+
let directory = dirname(entry);
|
|
23
|
+
for (;;) {
|
|
24
|
+
if ((await read(join(directory, "package.json"))) !== undefined) {
|
|
25
|
+
return directory;
|
|
26
|
+
}
|
|
27
|
+
const parent = dirname(directory);
|
|
28
|
+
if (parent === directory) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
directory = parent;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Why this SDK must not check the ontology at `entry`: its package's package-lock.json pins
|
|
36
|
+
* another release of the SDK, the one a deployment installs. That happens after a pull brings a
|
|
37
|
+
* new lockfile and node_modules is not reinstalled; the check would then judge the ontology by an
|
|
38
|
+
* older or newer release's rules. Undefined when they agree, when the package has no
|
|
39
|
+
* package-lock.json, and for an unreleased build of the SDK (version 0.0.0).
|
|
40
|
+
*/
|
|
41
|
+
export async function lockedReleaseMismatch(input) {
|
|
42
|
+
const { version, read } = input;
|
|
43
|
+
if (version === undefined || version === "0.0.0") {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
const directory = await packageDirectory(resolve(input.cwd, input.entry), read);
|
|
47
|
+
if (directory === undefined) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
const lock = parsed(await read(join(directory, "package-lock.json")));
|
|
51
|
+
const pinned = record(record(lock?.packages)?.[`node_modules/${SDK_PACKAGE}`]);
|
|
52
|
+
const locked = pinned?.version;
|
|
53
|
+
if (typeof locked !== "string" || pinned?.link === true || locked === version) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
const prefix = relative(input.invokedFrom ?? input.cwd, directory) || ".";
|
|
57
|
+
const command = prefix === "." ? "npm ci" : `npm --prefix ${prefix} ci`;
|
|
58
|
+
return (`This command runs ${SDK_PACKAGE} ${version} from node_modules, but ` +
|
|
59
|
+
`${join(prefix, "package-lock.json")} pins ${locked}, which a deployment installs. Their ` +
|
|
60
|
+
`rules can differ, so the ontology was not checked: run \`${command}\` and run the command ` +
|
|
61
|
+
"again.");
|
|
62
|
+
}
|
package/dist/bin/main.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export interface MainDependencies {
|
|
|
26
26
|
readonly output: Output;
|
|
27
27
|
readonly load: OntologyLoader;
|
|
28
28
|
readonly connect: OwnerConnection;
|
|
29
|
+
/** See `CheckDependencies.lockedRelease`. */
|
|
30
|
+
readonly lockedRelease?: (entry: string) => Promise<string | undefined>;
|
|
29
31
|
}
|
|
30
32
|
/** Runs one command line and returns the process exit code. */
|
|
31
33
|
export declare function runMain(args: ReadonlyArray<string>, dependencies: MainDependencies): Promise<ExitCode>;
|
package/dist/bin.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// The `segmentstream-ontology` binary: wires the process to the commands in ./bin/.
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { lockedReleaseMismatch } from "./bin/installed.js";
|
|
3
5
|
import { importWithTsx, loadOntology } from "./bin/load.js";
|
|
4
6
|
import { runMain } from "./bin/main.js";
|
|
5
7
|
import { connectOwnerDatabase } from "./bin/migrate.js";
|
|
@@ -20,11 +22,25 @@ function flushed(stream) {
|
|
|
20
22
|
});
|
|
21
23
|
}
|
|
22
24
|
const cwd = process.cwd();
|
|
25
|
+
const readText = (path) => readFile(path, "utf8").catch(() => undefined);
|
|
26
|
+
// This file is dist/bin.js; the package's own package.json carries the released version.
|
|
27
|
+
const sdk = JSON.parse((await readText(new URL("../package.json", import.meta.url))) ?? "{}");
|
|
28
|
+
const version = typeof sdk === "object" && sdk !== null && "version" in sdk && typeof sdk.version === "string"
|
|
29
|
+
? sdk.version
|
|
30
|
+
: undefined;
|
|
23
31
|
const exitCode = await runMain(process.argv.slice(2), {
|
|
24
32
|
environment: process.env,
|
|
25
33
|
output: { stdout: writer(process.stdout), stderr: writer(process.stderr) },
|
|
26
34
|
load: (entry) => loadOntology({ entry, cwd }, importWithTsx),
|
|
27
35
|
connect: connectOwnerDatabase,
|
|
36
|
+
lockedRelease: (entry) => lockedReleaseMismatch({
|
|
37
|
+
entry,
|
|
38
|
+
cwd,
|
|
39
|
+
// npm names the directory a script was started from; see `invokedFrom`.
|
|
40
|
+
invokedFrom: process.env.INIT_CWD,
|
|
41
|
+
version,
|
|
42
|
+
read: readText,
|
|
43
|
+
}),
|
|
28
44
|
});
|
|
29
45
|
await Promise.all([flushed(process.stdout), flushed(process.stderr)]);
|
|
30
46
|
// The ontology's modules may hold timers or sockets open; the command is done.
|
package/dist/index.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export { check, defineOntology } from "./ontology.js";
|
|
|
33
33
|
export { webhookDeliveryJsonSchema } from "./analyze.js";
|
|
34
34
|
export { webhookSigningKey, webhookSigningSecret, webhookToken, webhookTokenMatches, webhookUrl, WebhookUrlUnavailable, WEBHOOK_ORIGIN_VARIABLE, WEBHOOK_SIGNING_CONTEXT, WEBHOOK_TOKEN_CONTEXT, } from "./webhook-token.js";
|
|
35
35
|
export type { Ontology } from "./ontology.js";
|
|
36
|
-
export { AGENT_TOOL_VERBS, agentToolPermission, agentToolsOf, DEFAULT_MEMBER_PERMISSIONS, effectiveScope, generatedActionPermissions, grants, isAllowed, parsePermission, permissionsOf, principalScopes, READ_VERB, readScope, rolesGranting, scopesOf, USER_IDENTITY_VERBS, USER_MEMBER_VERBS, WILDCARD, WILDCARD_ENTITY_VERBS, WORKSPACE_SOURCE_PERMISSION, } from "./permissions.js";
|
|
36
|
+
export { AGENT_TOOL_VERBS, agentToolPermission, agentToolsOf, DEFAULT_MEMBER_PERMISSIONS, effectiveScope, generatedActionPermissions, grants, isAllowed, parsePermission, permissionsOf, principalScopes, READ_VERB, readScope, rolesGranting, scopesOf, USER_IDENTITY_VERBS, USER_MEMBER_VERBS, WILDCARD, WILDCARD_ENTITY_VERBS, WORKSPACE_SOURCE_PERMISSION, WORKSPACE_SOURCE_CONNECT, } from "./permissions.js";
|
|
37
37
|
export type { AgentToolVerb, ParsedPermission, PermissionHolder, RolePermissions, ScopedPermission, ScopeFilter, ScopeValue, ScopeWhere, UserMemberVerb, } from "./permissions.js";
|
|
38
38
|
export { p, PROPERTY_TYPES, propertyDefinition } from "./property.js";
|
|
39
39
|
export type { AnyProperty, NumberOptions, Property, PropertyDefinition, PropertyOf, PropertyOptions, BlobOptions, ListOptions, PropertyType, ReferenceOptions, SelectOption, SelectOptionInput, TextOptions, } from "./property.js";
|
package/dist/index.js
CHANGED
|
@@ -19,7 +19,7 @@ export { isMe, isMeMarker, MAX_ME_HOPS, me, ME_KEY, MeMarker, mePathOf, meToWire
|
|
|
19
19
|
export { check, defineOntology } from "./ontology.js";
|
|
20
20
|
export { webhookDeliveryJsonSchema } from "./analyze.js";
|
|
21
21
|
export { webhookSigningKey, webhookSigningSecret, webhookToken, webhookTokenMatches, webhookUrl, WebhookUrlUnavailable, WEBHOOK_ORIGIN_VARIABLE, WEBHOOK_SIGNING_CONTEXT, WEBHOOK_TOKEN_CONTEXT, } from "./webhook-token.js";
|
|
22
|
-
export { AGENT_TOOL_VERBS, agentToolPermission, agentToolsOf, DEFAULT_MEMBER_PERMISSIONS, effectiveScope, generatedActionPermissions, grants, isAllowed, parsePermission, permissionsOf, principalScopes, READ_VERB, readScope, rolesGranting, scopesOf, USER_IDENTITY_VERBS, USER_MEMBER_VERBS, WILDCARD, WILDCARD_ENTITY_VERBS, WORKSPACE_SOURCE_PERMISSION, } from "./permissions.js";
|
|
22
|
+
export { AGENT_TOOL_VERBS, agentToolPermission, agentToolsOf, DEFAULT_MEMBER_PERMISSIONS, effectiveScope, generatedActionPermissions, grants, isAllowed, parsePermission, permissionsOf, principalScopes, READ_VERB, readScope, rolesGranting, scopesOf, USER_IDENTITY_VERBS, USER_MEMBER_VERBS, WILDCARD, WILDCARD_ENTITY_VERBS, WORKSPACE_SOURCE_PERMISSION, WORKSPACE_SOURCE_CONNECT, } from "./permissions.js";
|
|
23
23
|
export { p, PROPERTY_TYPES, propertyDefinition } from "./property.js";
|
|
24
24
|
export { ON_DELETE, rel } from "./relationship.js";
|
|
25
25
|
export { renderCatalog } from "./render.js";
|
package/dist/permissions.d.ts
CHANGED
|
@@ -28,14 +28,15 @@ export declare const READ_VERB = "read";
|
|
|
28
28
|
export declare const EXPLICIT_GRANT_ENTITIES: ReadonlySet<string>;
|
|
29
29
|
/**
|
|
30
30
|
* The built-in permission's entity for the workspace's deployed code. It names no entity: `check`
|
|
31
|
-
* refuses an entity or a toolset of this name, and any verb of it but `read`.
|
|
31
|
+
* refuses an entity or a toolset of this name, and any verb of it but `read` or `connect`.
|
|
32
32
|
*/
|
|
33
33
|
export declare const WORKSPACE_SOURCE = "workspace_source";
|
|
34
34
|
/**
|
|
35
|
-
* Reading the workspace's deployed code,
|
|
36
|
-
* member it acts for, through `GET /api/ontology/agent/source`. Only a role that names it grants it.
|
|
35
|
+
* Reading the workspace's deployed code, through the agent's list, search and read tools. Only a role that names it grants it.
|
|
37
36
|
*/
|
|
38
37
|
export declare const WORKSPACE_SOURCE_PERMISSION = "workspace_source:read";
|
|
38
|
+
/** Use source access that this member granted to the receiving workspace. */
|
|
39
|
+
export declare const WORKSPACE_SOURCE_CONNECT = "workspace_source:connect";
|
|
39
40
|
/**
|
|
40
41
|
* The built-in permissions' entity for the tools the app's agent has of its own, beside the
|
|
41
42
|
* ontology's: `agent_tool:<tool>`. It names no entity: `check` refuses an entity or a toolset of
|
package/dist/permissions.js
CHANGED
|
@@ -36,14 +36,15 @@ export const EXPLICIT_GRANT_ENTITIES = new Set([
|
|
|
36
36
|
]);
|
|
37
37
|
/**
|
|
38
38
|
* The built-in permission's entity for the workspace's deployed code. It names no entity: `check`
|
|
39
|
-
* refuses an entity or a toolset of this name, and any verb of it but `read`.
|
|
39
|
+
* refuses an entity or a toolset of this name, and any verb of it but `read` or `connect`.
|
|
40
40
|
*/
|
|
41
41
|
export const WORKSPACE_SOURCE = "workspace_source";
|
|
42
42
|
/**
|
|
43
|
-
* Reading the workspace's deployed code,
|
|
44
|
-
* member it acts for, through `GET /api/ontology/agent/source`. Only a role that names it grants it.
|
|
43
|
+
* Reading the workspace's deployed code, through the agent's list, search and read tools. Only a role that names it grants it.
|
|
45
44
|
*/
|
|
46
45
|
export const WORKSPACE_SOURCE_PERMISSION = `${WORKSPACE_SOURCE}:${READ_VERB}`;
|
|
46
|
+
/** Use source access that this member granted to the receiving workspace. */
|
|
47
|
+
export const WORKSPACE_SOURCE_CONNECT = `${WORKSPACE_SOURCE}:connect`;
|
|
47
48
|
/**
|
|
48
49
|
* The built-in permissions' entity for the tools the app's agent has of its own, beside the
|
|
49
50
|
* ontology's: `agent_tool:<tool>`. It names no entity: `check` refuses an entity or a toolset of
|
package/dist/runtime/agents.js
CHANGED
|
@@ -28,7 +28,7 @@ import { ACTION_TRANSACTION_LIMITS, ActionTransactions } from "./action-transact
|
|
|
28
28
|
import { actionTransaction } from "./action-deadlocks.js";
|
|
29
29
|
import { canonicalInstant } from "./records.js";
|
|
30
30
|
import { actionTriggers, evaluateTriggers, insertStarts, startCommitted, WorkflowStarter, } from "./workflow-starts.js";
|
|
31
|
-
import { CHANNEL_IDENTITIES_FROM, CHANNEL_ORIGIN_SQL, CHANNEL_REVOKED_AT, LIVE_CHANNEL_IDENTITY, makeIdentityWriter, USER_IDENTITY_TABLE, } from "./user-identities.js";
|
|
31
|
+
import { liveSignInIdentities, CHANNEL_IDENTITIES_FROM, CHANNEL_ORIGIN_SQL, CHANNEL_REVOKED_AT, LIVE_CHANNEL_IDENTITY, makeIdentityWriter, USER_IDENTITY_TABLE, } from "./user-identities.js";
|
|
32
32
|
const PAIRINGS = `"${AGENT_PAIRINGS_TABLE}"`;
|
|
33
33
|
/** The legacy channel accounts, written beside `user_identity` for earlier SDKs. */
|
|
34
34
|
const LEGACY_IDENTITIES = `"${AGENT_IDENTITIES_TABLE}"`;
|
|
@@ -546,6 +546,10 @@ export function sqlAgentStore(ontology, sql) {
|
|
|
546
546
|
`ORDER BY ${REVOKED_AT} IS NOT NULL, ${REVOKED_AT} DESC`,
|
|
547
547
|
`LIMIT 1`,
|
|
548
548
|
].join("\n"), [provider, externalId]).pipe(Effect.map(([row]) => (row === undefined ? undefined : identityOf(row)))),
|
|
549
|
+
segmentStreamSubject: (userId, issuer) => liveSignInIdentities(sql, userId).pipe(Effect.map((rows) => {
|
|
550
|
+
const identities = rows.filter((row) => row.provider === "oidc" && row.issuer === issuer);
|
|
551
|
+
return identities.length === 1 ? identities[0].subject : undefined;
|
|
552
|
+
}), Effect.orDie),
|
|
549
553
|
listIdentities: (userId) => isRecordId(userId)
|
|
550
554
|
? rows([
|
|
551
555
|
`SELECT ${IDENTITY_COLUMNS}`,
|
|
@@ -10,6 +10,10 @@ export interface WorkspaceSourceEnvironment {
|
|
|
10
10
|
readonly segmentstreamUrl: string;
|
|
11
11
|
readonly workspaceId: string;
|
|
12
12
|
readonly organizationId: string;
|
|
13
|
+
readonly oidc?: {
|
|
14
|
+
readonly issuer: string;
|
|
15
|
+
readonly clientId: string;
|
|
16
|
+
};
|
|
13
17
|
}
|
|
14
18
|
/**
|
|
15
19
|
* The agent's source endpoint rechecks the current paired member's explicit permission for every
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effect, Layer, Result } from "effect";
|
|
2
2
|
import { HttpRouter, HttpServerResponse } from "effect/unstable/http";
|
|
3
|
-
import { isAllowed, WORKSPACE_SOURCE_PERMISSION } from "../../permissions.js";
|
|
3
|
+
import { isAllowed, WORKSPACE_SOURCE_CONNECT, WORKSPACE_SOURCE_PERMISSION, } from "../../permissions.js";
|
|
4
4
|
import { RequestId, errorBodyForWire } from "../errors.js";
|
|
5
5
|
import { describeError } from "../metric-query-platform.js";
|
|
6
6
|
import { identityToken } from "../operations.js";
|
|
@@ -20,7 +20,7 @@ function refusal(status, error, detail, requestId) {
|
|
|
20
20
|
function fetchQuery(input) {
|
|
21
21
|
const { environment, token, member, requestId } = input;
|
|
22
22
|
const url = `${environment.segmentstreamUrl}/api/internal/v1/workspaces/` +
|
|
23
|
-
`${encodeURIComponent(environment.workspaceId)}/ontology/source
|
|
23
|
+
`${encodeURIComponent(environment.workspaceId)}/ontology/source/${input.delegated ? "authorized" : "query"}`;
|
|
24
24
|
return Effect.tryPromise({
|
|
25
25
|
try: async (signal) => {
|
|
26
26
|
const response = await input.fetch(url, {
|
|
@@ -57,7 +57,7 @@ export function workspaceSourceLayer(options) {
|
|
|
57
57
|
if (agents === undefined || verify === undefined) {
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
|
-
const query = (request) => Effect.gen(function* () {
|
|
60
|
+
const query = (request, delegated = false) => Effect.gen(function* () {
|
|
61
61
|
const requestId = yield* RequestId;
|
|
62
62
|
const authenticated = yield* authenticateAgentRuntimeMember({ request, agents, verify });
|
|
63
63
|
if (!authenticated.ok) {
|
|
@@ -67,8 +67,9 @@ export function workspaceSourceLayer(options) {
|
|
|
67
67
|
if (member === undefined) {
|
|
68
68
|
return refusal(403, "permission_denied", "The member is inactive or has not paired with the agent.", requestId);
|
|
69
69
|
}
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
const permission = delegated ? WORKSPACE_SOURCE_CONNECT : WORKSPACE_SOURCE_PERMISSION;
|
|
71
|
+
if (!isAllowed(permission, member)) {
|
|
72
|
+
return refusal(403, "permission_denied", `${permission} is required.`, requestId);
|
|
72
73
|
}
|
|
73
74
|
const token = identityToken(request);
|
|
74
75
|
if (token === undefined || token === "") {
|
|
@@ -79,12 +80,42 @@ export function workspaceSourceLayer(options) {
|
|
|
79
80
|
if (Result.isFailure(input) || !input.success || input.success.length > 8192) {
|
|
80
81
|
return refusal(400, "invalid_request", "Invalid source query.", requestId);
|
|
81
82
|
}
|
|
83
|
+
let queryBody = input.success;
|
|
84
|
+
let manageUrl;
|
|
85
|
+
if (delegated) {
|
|
86
|
+
const oidc = options.environment.oidc;
|
|
87
|
+
const subject = oidc && agents.segmentStreamSubject
|
|
88
|
+
? yield* agents.segmentStreamSubject(member.id, oidc.issuer)
|
|
89
|
+
: undefined;
|
|
90
|
+
if (!oidc || !subject) {
|
|
91
|
+
return refusal(403, "identity_required", "Connect your SegmentStream account first.", requestId);
|
|
92
|
+
}
|
|
93
|
+
let body;
|
|
94
|
+
try {
|
|
95
|
+
body = JSON.parse(queryBody);
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return refusal(400, "invalid_request", "Invalid source request.", requestId);
|
|
99
|
+
}
|
|
100
|
+
if (!body || typeof body !== "object" || !("operation" in body)) {
|
|
101
|
+
return refusal(400, "invalid_request", "Invalid source request.", requestId);
|
|
102
|
+
}
|
|
103
|
+
queryBody = JSON.stringify({ ...body, subject });
|
|
104
|
+
if (body.operation === "connections") {
|
|
105
|
+
const link = new URL("/auth/workspace-access", "https://segmentstream.com");
|
|
106
|
+
link.searchParams.set("recipient", options.environment.workspaceId);
|
|
107
|
+
link.searchParams.set("org", options.environment.organizationId);
|
|
108
|
+
link.searchParams.set("subject", subject);
|
|
109
|
+
manageUrl = link.href;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
82
112
|
const answered = yield* Effect.result(fetchQuery({
|
|
83
113
|
environment: options.environment,
|
|
84
114
|
fetch: fetchImpl,
|
|
85
115
|
token,
|
|
86
116
|
member,
|
|
87
|
-
query:
|
|
117
|
+
query: queryBody,
|
|
118
|
+
delegated,
|
|
88
119
|
requestId,
|
|
89
120
|
}));
|
|
90
121
|
if (Result.isFailure(answered)) {
|
|
@@ -99,11 +130,16 @@ export function workspaceSourceLayer(options) {
|
|
|
99
130
|
requestId,
|
|
100
131
|
memberId: member.id,
|
|
101
132
|
}));
|
|
133
|
+
if (manageUrl && status === 200) {
|
|
134
|
+
const data = JSON.parse(new TextDecoder().decode(body));
|
|
135
|
+
return HttpServerResponse.jsonUnsafe({ manageUrl, workspaces: data.workspaces }, { headers: { "cache-control": "no-store" } });
|
|
136
|
+
}
|
|
102
137
|
return HttpServerResponse.uint8Array(body, {
|
|
103
138
|
status,
|
|
104
139
|
headers: { "content-type": "application/json", "cache-control": "no-store" },
|
|
105
140
|
});
|
|
106
141
|
});
|
|
107
|
-
yield* router.add("POST", WORKSPACE_SOURCE_PATH, query);
|
|
142
|
+
yield* router.add("POST", WORKSPACE_SOURCE_PATH, (request) => query(request));
|
|
143
|
+
yield* router.add("POST", `${AGENT_PATH}/source/authorized`, (request) => query(request, true));
|
|
108
144
|
}));
|
|
109
145
|
}
|
|
@@ -658,6 +658,7 @@ export interface AgentStore {
|
|
|
658
658
|
readonly externalId: string;
|
|
659
659
|
}) => Effect.Effect<AgentIdentity | undefined>;
|
|
660
660
|
/** The member's live identities, oldest first. */
|
|
661
|
+
readonly segmentStreamSubject?: (userId: string, issuer: string) => Effect.Effect<string | undefined>;
|
|
661
662
|
readonly listIdentities: (userId: string) => Effect.Effect<ReadonlyArray<AgentIdentity>>;
|
|
662
663
|
/** Revokes one of the member's live identities; false when they have no such identity. */
|
|
663
664
|
readonly revokeIdentity: (input: {
|
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, isAllowed, WORKSPACE_SOURCE_PERMISSION } from "../permissions.js";
|
|
14
|
+
import { allowsAction, isAllowed, WORKSPACE_SOURCE_CONNECT, 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";
|
|
@@ -435,9 +435,16 @@ export function createOntologyService(ontology, config) {
|
|
|
435
435
|
// Every answer that tells the agent whom it acts for names the agent's own tools they hold.
|
|
436
436
|
const agentTools = (principal) => {
|
|
437
437
|
const tools = agentToolsFor(ontology, principal);
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
438
|
+
if (principal.kind !== "member") {
|
|
439
|
+
return tools;
|
|
440
|
+
}
|
|
441
|
+
return [
|
|
442
|
+
...tools,
|
|
443
|
+
...(isAllowed(WORKSPACE_SOURCE_PERMISSION, principal) ? ["workspace_source"] : []),
|
|
444
|
+
...(federationConfig && isAllowed(WORKSPACE_SOURCE_CONNECT, principal)
|
|
445
|
+
? ["workspace_source_connect"]
|
|
446
|
+
: []),
|
|
447
|
+
];
|
|
441
448
|
};
|
|
442
449
|
const guest = guestOf(ontology.manifest);
|
|
443
450
|
// A guest proves an address with the app's own code email, which needs the production app.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.190.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",
|