@segmentstream/ontology 0.210.1 → 0.210.2
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 +4 -0
- package/dist/service/agent/server.js +11 -1
- package/dist/service/authentication.js +5 -1
- package/dist/service/database-activity.d.ts +7 -0
- package/dist/service/database-activity.js +25 -0
- package/dist/service/workflows.js +5 -0
- package/dist/storage/maintenance-auth.js +5 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.210.2
|
|
4
|
+
|
|
5
|
+
Report verified caller types with SQL activity so builders can distinguish workspace app sessions, API keys, agents and platform operations in Usage.
|
|
6
|
+
|
|
3
7
|
## 0.210.1
|
|
4
8
|
|
|
5
9
|
Private agent turns on HTTP channels with hyphens in their names can now record and read messages under the original channel name.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CurrentDatabaseActivity } from "../database-activity.js";
|
|
1
2
|
import { chatPersona, chatPersonaContext, chatPersonaNames, deployedChatPersonas, } from "../../chat-personas.js";
|
|
2
3
|
import { isAllowed, effectiveScope } from "../../permissions.js";
|
|
3
4
|
import { confirmationCommand } from "./confirmations.js";
|
|
@@ -842,6 +843,10 @@ export function agentLayer(options) {
|
|
|
842
843
|
backend.resolveApiKeyCredential !== undefined) {
|
|
843
844
|
const resolved = yield* backend.resolveApiKeyCredential(bearer);
|
|
844
845
|
if (resolved?.delegation === true) {
|
|
846
|
+
const activity = yield* CurrentDatabaseActivity;
|
|
847
|
+
if (activity) {
|
|
848
|
+
activity.credentialKind = "delegated_agent";
|
|
849
|
+
}
|
|
845
850
|
return agentTaskSecret(request) === undefined
|
|
846
851
|
? yield* answer(request)
|
|
847
852
|
: toServerResponse(forbidden(requestId, `This route does not accept ${AGENT_TASK_HEADER}.`));
|
|
@@ -851,11 +856,16 @@ export function agentLayer(options) {
|
|
|
851
856
|
? undefined
|
|
852
857
|
: yield* Effect.promise(() => options.verifyRuntime(token));
|
|
853
858
|
switch (verified?.status) {
|
|
854
|
-
case "valid":
|
|
859
|
+
case "valid": {
|
|
860
|
+
const activity = yield* CurrentDatabaseActivity;
|
|
861
|
+
if (activity) {
|
|
862
|
+
activity.credentialKind = "agent";
|
|
863
|
+
}
|
|
855
864
|
// A task acts as its workflow's user, which pairs, resolves and records nothing here.
|
|
856
865
|
return agentTaskSecret(request) === undefined
|
|
857
866
|
? yield* answer(request)
|
|
858
867
|
: toServerResponse(forbidden(requestId, `This route does not accept ${AGENT_TASK_HEADER}.`));
|
|
868
|
+
}
|
|
859
869
|
case "invalid":
|
|
860
870
|
yield* logRuntimeRejection(verified.reason);
|
|
861
871
|
return toServerResponse(unauthorized(requestId, "The bearer token is invalid, expired or revoked."));
|
|
@@ -11,6 +11,7 @@ import { browserRevisionAdmitted, browserRevisionObservation, browserSessionAdmi
|
|
|
11
11
|
import { platformTokenIssuer } from "./config.js";
|
|
12
12
|
import { RequestId, crossOriginSession, forbidden, internalError, notInvited, toServerResponse, unauthorized, unavailable, } from "./errors.js";
|
|
13
13
|
import { ACCESS_TOKEN_PREFIX, appSessionResource, publicOrigin, callerOfAccessToken, READ_SCOPE, rejectedAccessToken, scopedPrincipal, } from "./oauth/protocol.js";
|
|
14
|
+
import { CurrentDatabaseActivity } from "./database-activity.js";
|
|
14
15
|
import { CurrentCaller } from "./caller-context.js";
|
|
15
16
|
import { OntologyBackend } from "./runtime-contract.js";
|
|
16
17
|
import { ACT_AS_HEADER, ACT_AS_PROVIDER_HEADER, AGENT_GRANT_HEADER, AGENT_SCOPE_HEADER, AGENT_TASK_HEADER, WEB_PROVIDER, logRuntimeRejection, runtimeCredential, } from "./runtime-identity.js";
|
|
@@ -877,8 +878,11 @@ export function withPrincipal(credential, verifyToken, backend, effect, options
|
|
|
877
878
|
? Effect.failCause(cause)
|
|
878
879
|
: Effect.logError("ontology.authentication.failed", cause).pipe(Effect.annotateLogs({ requestId }), Effect.as({ status: "failed" }))));
|
|
879
880
|
switch (outcome.status) {
|
|
880
|
-
case "authenticated":
|
|
881
|
+
case "authenticated": {
|
|
882
|
+
const activity = yield* CurrentDatabaseActivity;
|
|
883
|
+
activity?.identify(outcome.principal, outcome.caller);
|
|
881
884
|
return yield* Effect.provideContext(effect, Context.make(CurrentPrincipal, outcome.principal).pipe(Context.add(CurrentCaller, outcome.caller)));
|
|
885
|
+
}
|
|
882
886
|
case "missing":
|
|
883
887
|
return toServerResponse(unauthorized(requestId, "A bearer token is required.", options.challenge?.(true)));
|
|
884
888
|
case "rejected":
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Context, Tracer } from "effect";
|
|
2
|
+
import type { Principal } from "../runtime.js";
|
|
3
|
+
import type { VerifiedCaller } from "./caller-context.js";
|
|
2
4
|
/** One observation per request or workflow SDK call. Never inspect SQL, parameters or row values. */
|
|
3
5
|
export declare class DatabaseActivity {
|
|
4
6
|
queries: number;
|
|
@@ -7,6 +9,9 @@ export declare class DatabaseActivity {
|
|
|
7
9
|
failedQueries: number;
|
|
8
10
|
truncated: boolean;
|
|
9
11
|
tool?: string;
|
|
12
|
+
credentialKind?: "platform" | "agent" | "delegated_agent" | "pipeline" | "app_session" | "api_key" | "service_key" | "oauth" | "workflow";
|
|
13
|
+
workflow?: string;
|
|
14
|
+
identify(principal: Principal, caller: VerifiedCaller): void;
|
|
10
15
|
readonly intervals: Array<[number, number]>;
|
|
11
16
|
tracer(delegate: Tracer.Tracer): Tracer.Tracer;
|
|
12
17
|
/** Coalesce intervals separated by at most one second of a serverless idle window. The reader applies the observed endpoint idle policy. */
|
|
@@ -18,6 +23,8 @@ export declare class DatabaseActivity {
|
|
|
18
23
|
returnedRows: number;
|
|
19
24
|
intervals: [number, number][];
|
|
20
25
|
truncated: boolean;
|
|
26
|
+
workflow?: string | undefined;
|
|
27
|
+
credentialKind?: "oauth" | "agent" | "workflow" | "platform" | "delegated_agent" | "pipeline" | "app_session" | "api_key" | "service_key" | undefined;
|
|
21
28
|
event: string;
|
|
22
29
|
source: string;
|
|
23
30
|
};
|
|
@@ -7,6 +7,29 @@ export class DatabaseActivity {
|
|
|
7
7
|
failedQueries = 0;
|
|
8
8
|
truncated = false;
|
|
9
9
|
tool;
|
|
10
|
+
credentialKind;
|
|
11
|
+
workflow;
|
|
12
|
+
identify(principal, caller) {
|
|
13
|
+
if (principal.workflow && caller.kind === "runtime") {
|
|
14
|
+
this.credentialKind = "workflow";
|
|
15
|
+
this.workflow = principal.workflow.name;
|
|
16
|
+
}
|
|
17
|
+
else if (principal.execution || caller.kind === "workload") {
|
|
18
|
+
this.credentialKind = "pipeline";
|
|
19
|
+
}
|
|
20
|
+
else if (caller.kind === "runtime") {
|
|
21
|
+
this.credentialKind = caller.delegatedBy ? "delegated_agent" : "agent";
|
|
22
|
+
}
|
|
23
|
+
else if (caller.kind === "oauth") {
|
|
24
|
+
this.credentialKind = "oauth";
|
|
25
|
+
}
|
|
26
|
+
else if (caller.kind === "service") {
|
|
27
|
+
this.credentialKind = "service_key";
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
this.credentialKind = principal.authenticatedVia === "api_key" ? "api_key" : "app_session";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
10
33
|
intervals = [];
|
|
11
34
|
tracer(delegate) {
|
|
12
35
|
return Tracer.make({
|
|
@@ -55,6 +78,8 @@ export class DatabaseActivity {
|
|
|
55
78
|
return {
|
|
56
79
|
event: "ontology.database.activity",
|
|
57
80
|
source: this.tool ? "mcp:" + this.tool : source,
|
|
81
|
+
...(this.credentialKind ? { credentialKind: this.credentialKind } : {}),
|
|
82
|
+
...(this.workflow ? { workflow: this.workflow } : {}),
|
|
58
83
|
...context,
|
|
59
84
|
queries: this.queries,
|
|
60
85
|
failedQueries: this.failedQueries,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CurrentDatabaseActivity } from "./database-activity.js";
|
|
1
2
|
import { Tracer } from "effect";
|
|
2
3
|
import { DatabaseActivity } from "./database-activity.js";
|
|
3
4
|
import { createHash } from "node:crypto";
|
|
@@ -1524,6 +1525,10 @@ export function workflowsLayer(options) {
|
|
|
1524
1525
|
new URL(request.source instanceof Request ? request.source.url : request.url, `https://${request.headers.host ?? "ontology.invalid"}`).origin)) {
|
|
1525
1526
|
return toServerResponse(forbidden(requestId, "This workload may not use the workflow routes."));
|
|
1526
1527
|
}
|
|
1528
|
+
const activity = yield* CurrentDatabaseActivity;
|
|
1529
|
+
if (activity) {
|
|
1530
|
+
activity.credentialKind = "platform";
|
|
1531
|
+
}
|
|
1527
1532
|
return yield* handle({ kind: "platform", execution: verification.execution }, request);
|
|
1528
1533
|
}
|
|
1529
1534
|
const runtime = runtimeCredential(options.verifyRuntime, request);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash, timingSafeEqual } from "node:crypto";
|
|
2
2
|
import { Effect, Layer, Redacted } from "effect";
|
|
3
3
|
import { HttpApiMiddleware, HttpApiSecurity } from "effect/unstable/httpapi";
|
|
4
|
+
import { CurrentDatabaseActivity } from "../service/database-activity.js";
|
|
4
5
|
import { RequestId, toServerResponse, unauthorized } from "../service/errors.js";
|
|
5
6
|
import { ErrorSchemas } from "../service/schemas.js";
|
|
6
7
|
/** Deployment scheduler identity: this credential grants only orphan maintenance. */
|
|
@@ -18,6 +19,10 @@ export function storageMaintenanceAuthenticationLayer(key) {
|
|
|
18
19
|
!timingSafeEqual(digest(Redacted.value(credential)), digest(Redacted.value(key)))) {
|
|
19
20
|
return toServerResponse(unauthorized(requestId, "A deployment maintenance credential is required."));
|
|
20
21
|
}
|
|
22
|
+
const activity = yield* CurrentDatabaseActivity;
|
|
23
|
+
if (activity) {
|
|
24
|
+
activity.credentialKind = "platform";
|
|
25
|
+
}
|
|
21
26
|
return yield* httpEffect;
|
|
22
27
|
}),
|
|
23
28
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.210.
|
|
3
|
+
"version": "0.210.2",
|
|
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",
|