@segmentstream/ontology 0.147.0 → 0.149.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 +39 -0
- package/README.md +24 -15
- package/dist/analyze.d.ts +11 -3
- package/dist/analyze.js +21 -4
- package/dist/connection.d.ts +20 -3
- package/dist/connection.js +36 -8
- package/dist/diagnostics.d.ts +3 -3
- package/dist/diagnostics.js +1 -0
- package/dist/files.d.ts +21 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/internal/diagnostics.js +3 -0
- package/dist/manifest.d.ts +125 -77
- package/dist/manifest.js +34 -2
- package/dist/migrate/model.d.ts +68 -56
- package/dist/migrate/plan.js +1 -1
- package/dist/migrate/preview.js +4 -1
- package/dist/migrate/storage.d.ts +15 -3
- package/dist/migrate/storage.js +86 -3
- package/dist/runtime/agents.js +2 -0
- package/dist/runtime/chat-messages.d.ts +233 -0
- package/dist/runtime/chat-messages.js +523 -0
- package/dist/runtime/pipeline.js +1 -0
- package/dist/service/agent/archive-routes.d.ts +2 -0
- package/dist/service/agent/archive-routes.js +2 -1
- package/dist/service/agent/chat-archive.d.ts +12 -3
- package/dist/service/agent/chat-archive.js +5 -1
- package/dist/service/agent/chat-message-routes.d.ts +124 -0
- package/dist/service/agent/chat-message-routes.js +235 -0
- package/dist/service/agent/server.d.ts +5 -1
- package/dist/service/agent/server.js +15 -0
- package/dist/service/chat/local-reads.d.ts +71 -0
- package/dist/service/chat/local-reads.js +148 -0
- package/dist/service/chat/reads.js +7 -0
- package/dist/service/chat/routes.js +4 -1
- package/dist/service/chat/schemas.d.ts +5 -0
- package/dist/service/chat/schemas.js +5 -0
- package/dist/service/connection-stream.d.ts +7 -0
- package/dist/service/connection-stream.js +9 -1
- package/dist/service/connections.js +56 -5
- package/dist/service/cron-secret.d.ts +6 -0
- package/dist/service/cron-secret.js +14 -0
- package/dist/service/discovery-search.d.ts +1 -1
- package/dist/service/mcp/server.js +4 -2
- package/dist/service/runtime-contract.d.ts +2 -0
- package/dist/service/schemas.d.ts +8 -2
- package/dist/service/service.js +4 -1
- package/dist/service/workflows.js +6 -12
- package/dist/storage/sessions.js +26 -0
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@ import { Cause, Effect, Layer, Schema } from "effect";
|
|
|
2
2
|
import { HttpApiBuilder, HttpApiSecurity } from "effect/unstable/httpapi";
|
|
3
3
|
import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
|
|
4
4
|
import { ActionRejected } from "../../errors.js";
|
|
5
|
+
import { declaredChatRetentionDaysOf } from "../../manifest.js";
|
|
5
6
|
import { withPrincipal, CurrentPrincipal, } from "../authentication.js";
|
|
6
7
|
import { runtimeCredential } from "../runtime-identity.js";
|
|
7
8
|
import { RequestId, failureResponse } from "../errors.js";
|
|
@@ -11,12 +12,14 @@ import { ChatSearch } from "../agent/chat-archive.js";
|
|
|
11
12
|
import { chatKind, listedChatProviders } from "./providers/index.js";
|
|
12
13
|
import { chatReads } from "./reads.js";
|
|
13
14
|
import { withChatMembership } from "./resolve.js";
|
|
15
|
+
import { withChatStore } from "./local-reads.js";
|
|
14
16
|
import { ChatList, ChatHistory } from "./schemas.js";
|
|
15
17
|
export function chatRoutes(options) {
|
|
16
18
|
return Layer.effectDiscard(Effect.gen(function* () {
|
|
17
19
|
const router = yield* HttpRouter.HttpRouter;
|
|
18
20
|
const backend = yield* OntologyBackend;
|
|
19
|
-
const chatHistory = options.chatHistory &&
|
|
21
|
+
const chatHistory = options.chatHistory &&
|
|
22
|
+
withChatMembership(withChatStore(options.chatHistory, backend, declaredChatRetentionDaysOf(options.built.plan.ontology.manifest)), backend);
|
|
20
23
|
const reads = chatReads(backend, {
|
|
21
24
|
providers: listedChatProviders(options.built.plan.ontology.manifest.chat),
|
|
22
25
|
kindOf: (channel) => chatKind(options.built.plan.ontology.manifest.chat, channel),
|
|
@@ -22,6 +22,11 @@ export declare const ChatList: Schema.Struct<{
|
|
|
22
22
|
export declare const ChatHistory: Schema.Struct<{
|
|
23
23
|
readonly chat: Schema.String;
|
|
24
24
|
readonly before: Schema.optionalKey<Schema.String>;
|
|
25
|
+
/**
|
|
26
|
+
* A `revision` of the workspace's chat store, an event's `sequence` there: the chat's messages
|
|
27
|
+
* changed since, oldest change first, and `next_cursor` the revision to read after next.
|
|
28
|
+
*/
|
|
29
|
+
readonly after: Schema.optionalKey<Schema.String>;
|
|
25
30
|
readonly limit: Schema.optionalKey<Schema.Int>;
|
|
26
31
|
}>;
|
|
27
32
|
export declare const ChatDestination: Schema.Struct<{
|
|
@@ -17,6 +17,11 @@ export const ChatList = Schema.Struct({
|
|
|
17
17
|
export const ChatHistory = Schema.Struct({
|
|
18
18
|
chat: Id,
|
|
19
19
|
before: Schema.optionalKey(Id),
|
|
20
|
+
/**
|
|
21
|
+
* A `revision` of the workspace's chat store, an event's `sequence` there: the chat's messages
|
|
22
|
+
* changed since, oldest change first, and `next_cursor` the revision to read after next.
|
|
23
|
+
*/
|
|
24
|
+
after: Schema.optionalKey(Schema.String.check(Schema.isPattern(/^\d{1,18}$/))),
|
|
20
25
|
limit: Schema.optionalKey(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 200 }))),
|
|
21
26
|
});
|
|
22
27
|
export const ChatDestination = Schema.Struct({
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { Effect, type Scope } from "effect";
|
|
2
2
|
import { ConnectionError, type ConnectionReply, type ConnectionStreamReply } from "../connection.js";
|
|
3
3
|
export declare const CONNECTION_STREAM_MEDIA_TYPE = "application/vnd.segmentstream.proxy-stream.v1+ndjson";
|
|
4
|
+
/**
|
|
5
|
+
* The extra time a call that sends a stored file allows backend-next to read it from file
|
|
6
|
+
* storage before the provider request starts; backend-next's read deadline matches it.
|
|
7
|
+
*/
|
|
8
|
+
export declare const STORED_FILE_READ_MS = 15000;
|
|
4
9
|
/** Negotiates once; never retries a provider operation to change response formats. */
|
|
5
10
|
export declare function openConnectionStream(input: {
|
|
6
11
|
readonly connection: string;
|
|
7
12
|
readonly request: (signal: AbortSignal) => Promise<Response>;
|
|
8
13
|
readonly legacy: (value: unknown) => ConnectionReply;
|
|
9
14
|
readonly refusal: (status: number, value: unknown, cause?: unknown) => ConnectionError;
|
|
15
|
+
/** Whether backend-next reads the body from file storage first, which takes longer. */
|
|
16
|
+
readonly storedFile?: boolean;
|
|
10
17
|
}): Effect.Effect<ConnectionStreamReply, ConnectionError, Scope.Scope>;
|
|
@@ -5,6 +5,11 @@ const MAX_FRAME_BYTES = 128 * 1024;
|
|
|
5
5
|
const MAX_CHUNK_BYTES = 65_536;
|
|
6
6
|
const MAX_LEGACY_BYTES = 4 * 1024 * 1024;
|
|
7
7
|
const CALL_TIMEOUT_MS = 40_000;
|
|
8
|
+
/**
|
|
9
|
+
* The extra time a call that sends a stored file allows backend-next to read it from file
|
|
10
|
+
* storage before the provider request starts; backend-next's read deadline matches it.
|
|
11
|
+
*/
|
|
12
|
+
export const STORED_FILE_READ_MS = 15_000;
|
|
8
13
|
function invalid(connection, cause) {
|
|
9
14
|
return new ConnectionError({
|
|
10
15
|
connection,
|
|
@@ -69,7 +74,10 @@ async function* frames(reader, connection) {
|
|
|
69
74
|
export function openConnectionStream(input) {
|
|
70
75
|
return Effect.gen(function* () {
|
|
71
76
|
const controller = yield* Effect.acquireRelease(Effect.sync(() => new AbortController()), (controller) => Effect.sync(() => controller.abort()));
|
|
72
|
-
const signal = AbortSignal.any([
|
|
77
|
+
const signal = AbortSignal.any([
|
|
78
|
+
controller.signal,
|
|
79
|
+
AbortSignal.timeout(CALL_TIMEOUT_MS + (input.storedFile === true ? STORED_FILE_READ_MS : 0)),
|
|
80
|
+
]);
|
|
73
81
|
const failure = (cause) => {
|
|
74
82
|
if (cause instanceof ConnectionError) {
|
|
75
83
|
return cause;
|
|
@@ -104,9 +104,59 @@ function collected(connection, reply) {
|
|
|
104
104
|
body: new Uint8Array(Buffer.concat(chunks)),
|
|
105
105
|
})));
|
|
106
106
|
}
|
|
107
|
-
/**
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
/**
|
|
108
|
+
* A file's signed byte range, read by this process: the local proxy route takes no file, so a
|
|
109
|
+
* request run with `segmentstream exec` sends it inline, within the 2 MiB body limit.
|
|
110
|
+
*/
|
|
111
|
+
function readFileRange(fetchImpl, connection, source) {
|
|
112
|
+
const length = source.end - source.start + 1;
|
|
113
|
+
if (length > MAXIMUM_CONNECTION_BODY_BYTES) {
|
|
114
|
+
return Effect.fail(failure(connection, "invalid_request", "file_inline_too_large"));
|
|
115
|
+
}
|
|
116
|
+
return Effect.tryPromise({
|
|
117
|
+
try: async (signal) => {
|
|
118
|
+
const response = await fetchImpl(source.url, {
|
|
119
|
+
headers: { ...source.headers, range: `bytes=${source.start}-${source.end}` },
|
|
120
|
+
redirect: "error",
|
|
121
|
+
signal,
|
|
122
|
+
});
|
|
123
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
124
|
+
if (![200, 206].includes(response.status) || bytes.byteLength !== length) {
|
|
125
|
+
throw new Error(`file storage answered ${response.status} with ${bytes.byteLength} bytes`);
|
|
126
|
+
}
|
|
127
|
+
return bytes;
|
|
128
|
+
},
|
|
129
|
+
catch: (cause) => failure(connection, "unavailable", "file_storage_unavailable", undefined, cause),
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Shared admission and wire requests for buffered and streamed responses. A deployed service
|
|
134
|
+
* sends a request's `file` as its signed read, which backend-next fetches from the workspace's
|
|
135
|
+
* file storage; `inlineFiles` reads it here instead and sends its bytes.
|
|
136
|
+
*/
|
|
137
|
+
function transport(fetchImpl, resolve, options = {}) {
|
|
138
|
+
const payload = (call) => Effect.gen(function* () {
|
|
139
|
+
const source = call.source;
|
|
140
|
+
if (call.file !== undefined && source === undefined) {
|
|
141
|
+
return yield* Effect.fail(failure(call.connection, "invalid_request", "file_storage_unavailable"));
|
|
142
|
+
}
|
|
143
|
+
if (source === undefined) {
|
|
144
|
+
return { body: Buffer.from(call.body).toString("base64") };
|
|
145
|
+
}
|
|
146
|
+
if (options.inlineFiles === true) {
|
|
147
|
+
const bytes = yield* readFileRange(fetchImpl, call.connection, source);
|
|
148
|
+
return { body: Buffer.from(bytes).toString("base64") };
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
file: {
|
|
152
|
+
url: source.url,
|
|
153
|
+
headers: Object.entries(source.headers),
|
|
154
|
+
start: source.start,
|
|
155
|
+
end: source.end,
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
});
|
|
159
|
+
const open = (call) => Effect.all([resolve(call), payload(call)]).pipe(Effect.flatMap(([selected, content]) => openConnectionStream({
|
|
110
160
|
connection: call.connection,
|
|
111
161
|
request: (signal) => fetchImpl(selected.url, {
|
|
112
162
|
method: "POST",
|
|
@@ -120,13 +170,14 @@ function transport(fetchImpl, resolve) {
|
|
|
120
170
|
method: selected.call.method,
|
|
121
171
|
path: selected.call.path,
|
|
122
172
|
headers: selected.call.headers,
|
|
123
|
-
|
|
173
|
+
...content,
|
|
124
174
|
}),
|
|
125
175
|
redirect: "error",
|
|
126
176
|
signal,
|
|
127
177
|
}),
|
|
128
178
|
legacy: (value) => reply(call.connection, value),
|
|
129
179
|
refusal: (status, value, cause) => refusal(call.connection, status, value, cause),
|
|
180
|
+
storedFile: "file" in content,
|
|
130
181
|
})));
|
|
131
182
|
return {
|
|
132
183
|
request: (call) => open(call).pipe(Effect.flatMap((reply) => collected(call.connection, reply)), Effect.scoped),
|
|
@@ -183,7 +234,7 @@ export function localConnections(context, fetchImpl = fetch) {
|
|
|
183
234
|
headers: { "x-segmentstream-connection-grant": context.proxyGrant },
|
|
184
235
|
call: { ...call, api },
|
|
185
236
|
});
|
|
186
|
-
});
|
|
237
|
+
}, { inlineFiles: true });
|
|
187
238
|
}
|
|
188
239
|
function localConnection(value) {
|
|
189
240
|
if (!isRecord(value) ||
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Redacted } from "effect";
|
|
2
|
+
/**
|
|
3
|
+
* Whether an `Authorization` header carries the project's cron secret, as Vercel sends it on each
|
|
4
|
+
* cron invocation: compared in constant time, and never equal to an empty secret.
|
|
5
|
+
*/
|
|
6
|
+
export declare function bearerEquals(header: string | undefined, secret: Redacted.Redacted<string>): boolean;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { timingSafeEqual } from "node:crypto";
|
|
2
|
+
import { Redacted } from "effect";
|
|
3
|
+
/**
|
|
4
|
+
* Whether an `Authorization` header carries the project's cron secret, as Vercel sends it on each
|
|
5
|
+
* cron invocation: compared in constant time, and never equal to an empty secret.
|
|
6
|
+
*/
|
|
7
|
+
export function bearerEquals(header, secret) {
|
|
8
|
+
if (Redacted.value(secret) === "") {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
const expected = Buffer.from(`Bearer ${Redacted.value(secret)}`);
|
|
12
|
+
const received = Buffer.from(header ?? "");
|
|
13
|
+
return received.length === expected.length && timingSafeEqual(received, expected);
|
|
14
|
+
}
|
|
@@ -12,8 +12,8 @@ export declare function normalizeSearch(text: string): string;
|
|
|
12
12
|
/** Rank only caller-projected documents; forbidden fields never affect ranking or explanations. */
|
|
13
13
|
export declare function searchDocuments(documents: ReadonlyArray<SearchDocument>, input: DiscoverInput): {
|
|
14
14
|
readonly kind: "entity" | "metric" | "action";
|
|
15
|
-
readonly name: string;
|
|
16
15
|
readonly description: string;
|
|
16
|
+
readonly name: string;
|
|
17
17
|
readonly label: string;
|
|
18
18
|
readonly ref: string;
|
|
19
19
|
readonly matched_on: readonly {
|
|
@@ -4,7 +4,7 @@ import { HttpApiBuilder, HttpApiSecurity } from "effect/unstable/httpapi";
|
|
|
4
4
|
import { ActionRejected } from "../../errors.js";
|
|
5
5
|
import { DeploymentAdmissionError } from "../../deployment.js";
|
|
6
6
|
import { effectivePermissions } from "../../permissions.js";
|
|
7
|
-
import { encodeManifest } from "../../manifest.js";
|
|
7
|
+
import { declaredChatRetentionDaysOf, encodeManifest } from "../../manifest.js";
|
|
8
8
|
import { describeError, SCOPE_MISMATCH } from "../metric-query-platform.js";
|
|
9
9
|
import { gatewayCredential, gatewayDecisions } from "../decisions.js";
|
|
10
10
|
import { CurrentPrincipal, withPrincipal } from "../authentication.js";
|
|
@@ -19,6 +19,7 @@ import { ChatPostResult } from "../../chat.js";
|
|
|
19
19
|
import { chatKind, listedChatProviders } from "../chat/providers/index.js";
|
|
20
20
|
import { chatReads } from "../chat/reads.js";
|
|
21
21
|
import { withChatMembership } from "../chat/resolve.js";
|
|
22
|
+
import { withChatStore } from "../chat/local-reads.js";
|
|
22
23
|
import { catalogFor } from "../catalog.js";
|
|
23
24
|
import { createDiscovery, DiscoveryError } from "../discovery.js";
|
|
24
25
|
import { suggestNames, suggestionDetail } from "../name-suggestions.js";
|
|
@@ -827,7 +828,8 @@ export function mcpLayer(options) {
|
|
|
827
828
|
files: backend.blobs !== undefined,
|
|
828
829
|
}, options.navigation !== undefined);
|
|
829
830
|
const operations = makeOperations(backend, options.built.plan, options.hooks, options.connections, options.replicate, options.chatDelivery);
|
|
830
|
-
const chatHistory = options.chatHistory &&
|
|
831
|
+
const chatHistory = options.chatHistory &&
|
|
832
|
+
withChatMembership(withChatStore(options.chatHistory, backend, declaredChatRetentionDaysOf(options.built.plan.ontology.manifest)), backend);
|
|
831
833
|
const server = {
|
|
832
834
|
chats: chatReads(backend, {
|
|
833
835
|
providers: listedChatProviders(options.built.plan.ontology.manifest.chat),
|
|
@@ -725,6 +725,8 @@ export interface AgentStore {
|
|
|
725
725
|
readonly sessionReviews?: (sessionId: string) => Effect.Effect<ReadonlyArray<SessionReview>>;
|
|
726
726
|
/** The grants behind agent tokens for the web. Absent on stores that predate them. */
|
|
727
727
|
readonly web?: AgentWebStore;
|
|
728
|
+
/** The chats' messages, in `_chat_messages`. Absent on stores that predate the chat store. */
|
|
729
|
+
readonly chatMessages?: import("../runtime/chat-messages.js").ChatMessageStore;
|
|
728
730
|
}
|
|
729
731
|
/** A reply the agent held for review, as `POST /api/ontology/agent/reviews` reports it. */
|
|
730
732
|
export interface HeldReplyInput {
|
|
@@ -527,7 +527,7 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
527
527
|
readonly description: Schema.String;
|
|
528
528
|
readonly delivers: Schema.optionalKey<Schema.Literal<true>>;
|
|
529
529
|
}>>>;
|
|
530
|
-
readonly chat: Schema.optionalKey<Schema.Struct<{
|
|
530
|
+
readonly chat: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
|
|
531
531
|
readonly telegram: Schema.optionalKey<Schema.Struct<{
|
|
532
532
|
readonly connection: Schema.String;
|
|
533
533
|
}>>;
|
|
@@ -548,6 +548,9 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
548
548
|
readonly template: Schema.optionalKey<Schema.String>;
|
|
549
549
|
readonly separator: Schema.optionalKey<Schema.String>;
|
|
550
550
|
}>>;
|
|
551
|
+
readonly retentionDays: Schema.optionalKey<Schema.Int>;
|
|
552
|
+
}>, {
|
|
553
|
+
readonly retentionDays: "retention_days";
|
|
551
554
|
}>>;
|
|
552
555
|
readonly inbox: Schema.optionalKey<Schema.Struct<{
|
|
553
556
|
readonly roles: Schema.$Array<Schema.String>;
|
|
@@ -892,7 +895,7 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
892
895
|
readonly description: Schema.String;
|
|
893
896
|
readonly delivers: Schema.optionalKey<Schema.Literal<true>>;
|
|
894
897
|
}>>>>;
|
|
895
|
-
readonly chat: Schema.toEncoded<Schema.optionalKey<Schema.Struct<{
|
|
898
|
+
readonly chat: Schema.toEncoded<Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
|
|
896
899
|
readonly telegram: Schema.optionalKey<Schema.Struct<{
|
|
897
900
|
readonly connection: Schema.String;
|
|
898
901
|
}>>;
|
|
@@ -913,6 +916,9 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
913
916
|
readonly template: Schema.optionalKey<Schema.String>;
|
|
914
917
|
readonly separator: Schema.optionalKey<Schema.String>;
|
|
915
918
|
}>>;
|
|
919
|
+
readonly retentionDays: Schema.optionalKey<Schema.Int>;
|
|
920
|
+
}>, {
|
|
921
|
+
readonly retentionDays: "retention_days";
|
|
916
922
|
}>>>;
|
|
917
923
|
readonly inbox: Schema.toEncoded<Schema.optionalKey<Schema.Struct<{
|
|
918
924
|
readonly roles: Schema.$Array<Schema.String>;
|
package/dist/service/service.js
CHANGED
|
@@ -9,7 +9,7 @@ import { RuntimeDeployment } from "../runtime/deployment.js";
|
|
|
9
9
|
import { nameToWire } from "../authoring-names.js";
|
|
10
10
|
import { bundledNavigationCatalog } from "../navigation-artifact.js";
|
|
11
11
|
import { parsePageCatalog } from "../navigation-catalog.js";
|
|
12
|
-
import { guestOf, signUpOriginsOf, signUpRolesOf } from "../manifest.js";
|
|
12
|
+
import { chatRetentionDaysOf, declaredChatRetentionDaysOf, guestOf, signUpOriginsOf, signUpRolesOf, } from "../manifest.js";
|
|
13
13
|
import { isAllowed } from "../permissions.js";
|
|
14
14
|
import { agentToolsFor } from "../runtime/guests.js";
|
|
15
15
|
import { implicitMemberOf } from "../role.js";
|
|
@@ -425,6 +425,8 @@ export function createOntologyService(ontology, config) {
|
|
|
425
425
|
}),
|
|
426
426
|
emailSignUp: signUpRolesOf(ontology.manifest, "email") !== undefined,
|
|
427
427
|
emailCodes,
|
|
428
|
+
cronSecret: config.cronSecret,
|
|
429
|
+
chatRetentionDays: chatRetentionDaysOf(ontology.manifest),
|
|
428
430
|
});
|
|
429
431
|
const agentTasks = preview
|
|
430
432
|
? Layer.empty
|
|
@@ -472,6 +474,7 @@ export function createOntologyService(ontology, config) {
|
|
|
472
474
|
? Layer.empty
|
|
473
475
|
: archiveRoutes({
|
|
474
476
|
transport: chatHistory,
|
|
477
|
+
chatRetentionDays: declaredChatRetentionDaysOf(ontology.manifest),
|
|
475
478
|
verifyToken,
|
|
476
479
|
verifyRuntime,
|
|
477
480
|
exchangeSession,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createHash
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
2
|
import { Cause, Context, Effect, Exit, Layer, Redacted, Schema } from "effect";
|
|
3
3
|
import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
|
|
4
4
|
import { HttpApiBuilder, HttpApiSecurity } from "effect/unstable/httpapi";
|
|
@@ -27,6 +27,7 @@ import { RECOVERY_CONFIRM_MS, RECOVERY_COVERAGE_MARGIN_MS, RECOVERY_FIRST_SWEEP_
|
|
|
27
27
|
import { nextCronTime, } from "../workflow.js";
|
|
28
28
|
import { platformWorkflows, setWorkflowBinding, WORKFLOW_BASE_PATH, workflowSdk, workflowStructures, } from "../workflow-runtime.js";
|
|
29
29
|
import { callbackIdentityToken } from "./workflow-callback.js";
|
|
30
|
+
import { bearerEquals } from "./cron-secret.js";
|
|
30
31
|
import { expireAgentTask, startAgentTask, } from "./agent/task-start.js";
|
|
31
32
|
import { CurrentPrincipal, WORKLOAD_TOKEN_TYPE, withPrincipal, workloadKind, } from "./authentication.js";
|
|
32
33
|
import { CurrentCaller } from "./caller-context.js";
|
|
@@ -571,14 +572,6 @@ function workflowView(workflow, now) {
|
|
|
571
572
|
: []),
|
|
572
573
|
};
|
|
573
574
|
}
|
|
574
|
-
function bearerEquals(header, secret) {
|
|
575
|
-
if (Redacted.value(secret) === "") {
|
|
576
|
-
return false;
|
|
577
|
-
}
|
|
578
|
-
const expected = Buffer.from(`Bearer ${Redacted.value(secret)}`);
|
|
579
|
-
const received = Buffer.from(header ?? "");
|
|
580
|
-
return received.length === expected.length && timingSafeEqual(received, expected);
|
|
581
|
-
}
|
|
582
575
|
function isWorkloadToken(token) {
|
|
583
576
|
try {
|
|
584
577
|
return decodeProtectedHeader(token).typ === WORKLOAD_TOKEN_TYPE;
|
|
@@ -972,19 +965,20 @@ export function workflowsLayer(options) {
|
|
|
972
965
|
"ConnectionError",
|
|
973
966
|
])),
|
|
974
967
|
});
|
|
975
|
-
const
|
|
968
|
+
const files = backend.blobs?.files?.({
|
|
976
969
|
principal,
|
|
977
970
|
idempotencyKey: createHash("sha256")
|
|
978
971
|
.update(`${step.workflowRunId}:${step.stepId}`)
|
|
979
972
|
.digest("hex"),
|
|
980
|
-
}) ?? unavailableFiles
|
|
973
|
+
}) ?? unavailableFiles;
|
|
974
|
+
const services = Context.make(OntologyReads, reads).pipe(Context.add(Files, files), Context.add(OntologyWrites, writes), Context.add(OntologyActions, actions), Context.merge(connectionContext(workflow.declaration.connections, options.connections({
|
|
981
975
|
identityToken,
|
|
982
976
|
audit: {
|
|
983
977
|
action: `workflow.${workflow.manifest.name}`,
|
|
984
978
|
principalId: principal.id,
|
|
985
979
|
requestId,
|
|
986
980
|
},
|
|
987
|
-
}))));
|
|
981
|
+
}), { files })));
|
|
988
982
|
console.info(JSON.stringify({
|
|
989
983
|
event: "ontology.workflow.step.started",
|
|
990
984
|
workflow: workflow.manifest.name,
|
package/dist/storage/sessions.js
CHANGED
|
@@ -682,6 +682,32 @@ export function blobRuntime(ontology, sql, provider, fetchImpl = fetch) {
|
|
|
682
682
|
body: yield* openFile({ grant, size: Number(blob.size), fetch: fetchImpl }),
|
|
683
683
|
};
|
|
684
684
|
})),
|
|
685
|
+
source: (input) => publicErrors(Effect.gen(function* () {
|
|
686
|
+
const blob = yield* prepareDownload(input.entity, input.id, input.property, { revisionId: input.revisionId }, invocation.principal);
|
|
687
|
+
const size = Number(blob.size);
|
|
688
|
+
const start = input.start ?? 0;
|
|
689
|
+
const end = input.end ?? size - 1;
|
|
690
|
+
if (!Number.isSafeInteger(start) ||
|
|
691
|
+
!Number.isSafeInteger(end) ||
|
|
692
|
+
start < 0 ||
|
|
693
|
+
end < start ||
|
|
694
|
+
end >= size) {
|
|
695
|
+
return yield* new ActionRejected({ message: "file_range_invalid" });
|
|
696
|
+
}
|
|
697
|
+
const grant = yield* provider.download({
|
|
698
|
+
key: blob.key,
|
|
699
|
+
filename: blob.filename,
|
|
700
|
+
contentType: blob.content_type,
|
|
701
|
+
inline: false,
|
|
702
|
+
});
|
|
703
|
+
return {
|
|
704
|
+
url: grant.url,
|
|
705
|
+
headers: grant.headers,
|
|
706
|
+
start,
|
|
707
|
+
end,
|
|
708
|
+
contentType: blob.content_type,
|
|
709
|
+
};
|
|
710
|
+
})),
|
|
685
711
|
});
|
|
686
712
|
};
|
|
687
713
|
return { begin, list, status, target, part, complete, cancel, download, downloadFile, files };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.149.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",
|