@segmentstream/ontology 0.147.0 → 0.148.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 +10 -0
- package/dist/connection.d.ts +20 -3
- package/dist/connection.js +36 -8
- package/dist/files.d.ts +21 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/internal/diagnostics.js +3 -0
- package/dist/manifest.d.ts +72 -72
- package/dist/migrate/model.d.ts +54 -54
- package/dist/runtime/pipeline.js +1 -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/discovery-search.d.ts +1 -1
- package/dist/service/workflows.js +4 -3
- package/dist/storage/sessions.js +26 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.148.0
|
|
4
|
+
|
|
5
|
+
A connection request in an action or workflow step can send a stored file as its body: pass
|
|
6
|
+
`file: { entity, id, property, start?, end? }` instead of `body`. The action's file access
|
|
7
|
+
checks that its principal may read the record, and SegmentStream reads the byte range from the
|
|
8
|
+
workspace's file storage, up to 64 MiB per request, so large uploads such as a video's parts no
|
|
9
|
+
longer need to fit the 2 MiB request body. `content-type` defaults to the file's. It needs the
|
|
10
|
+
workspace's file storage, which exists once the ontology declares a file property. Run locally
|
|
11
|
+
with `segmentstream exec`, the range is sent inline, up to 2 MiB.
|
|
12
|
+
|
|
3
13
|
## 0.147.0
|
|
4
14
|
|
|
5
15
|
A member whom only SegmentStream app tokens signed in, such as the CLI's, can now sign in to the app
|
package/dist/connection.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { Context, Effect, Layer, Schema, Stream, type Scope } from "effect";
|
|
2
|
+
import type { FileRange, Files, FileSource } from "./files.js";
|
|
2
3
|
export declare const ConnectionTypeId: unique symbol;
|
|
3
4
|
/** A connection key, as `connections/connections.py` declares it. */
|
|
4
5
|
export declare const CONNECTION_KEY: RegExp;
|
|
5
6
|
export declare const CONNECTION_METHODS: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"];
|
|
6
7
|
export type ConnectionMethod = (typeof CONNECTION_METHODS)[number];
|
|
7
|
-
/** The largest request body. */
|
|
8
|
+
/** The largest request body, except a `file`, which SegmentStream reads from file storage. */
|
|
8
9
|
export declare const MAXIMUM_CONNECTION_BODY_BYTES: number;
|
|
10
|
+
/** The largest byte range of a file one request may send as its body. */
|
|
11
|
+
export declare const MAXIMUM_CONNECTION_FILE_BYTES: number;
|
|
9
12
|
/**
|
|
10
13
|
* The largest response body `get`, `post` and `request` collect. A larger response fails with
|
|
11
14
|
* `invalid_response`; `stream` reads a response of any size.
|
|
@@ -51,6 +54,10 @@ export interface ConnectionCall {
|
|
|
51
54
|
readonly path: string;
|
|
52
55
|
readonly headers: ReadonlyArray<readonly [string, string]>;
|
|
53
56
|
readonly body: Uint8Array;
|
|
57
|
+
/** A file revision's byte range to send as the body instead of `body`, which is then empty. */
|
|
58
|
+
readonly file?: FileRange;
|
|
59
|
+
/** The signed read of `file` the proxy fetches, once the action's file access resolved it. */
|
|
60
|
+
readonly source?: FileSource;
|
|
54
61
|
}
|
|
55
62
|
/** What the proxy answered: the provider's status, headers and buffered body. */
|
|
56
63
|
export interface ConnectionReply {
|
|
@@ -123,8 +130,15 @@ export interface ConnectionRequestOptions {
|
|
|
123
130
|
readonly json?: unknown;
|
|
124
131
|
/** A form body, sent with `content-type: application/x-www-form-urlencoded`. */
|
|
125
132
|
readonly form?: Readonly<Record<string, string>>;
|
|
126
|
-
/** A raw body. Set at most one of `json`, `form` and `
|
|
133
|
+
/** A raw body. Set at most one of `json`, `form`, `body` and `file`. */
|
|
127
134
|
readonly body?: string | Uint8Array;
|
|
135
|
+
/**
|
|
136
|
+
* A byte range of a record's file to send as the body, such as one part of a chunked video
|
|
137
|
+
* upload. SegmentStream reads it from the workspace's file storage, so it is not held to the
|
|
138
|
+
* 2 MiB body limit: one request sends up to 64 MiB. The action's principal must be able to read
|
|
139
|
+
* the record. `content-type` defaults to the file's.
|
|
140
|
+
*/
|
|
141
|
+
readonly file?: FileRange;
|
|
128
142
|
}
|
|
129
143
|
export interface ConnectionRequest extends ConnectionRequestOptions {
|
|
130
144
|
readonly method: ConnectionMethod;
|
|
@@ -182,10 +196,13 @@ export declare function isConnection(value: unknown): value is AnyConnectionHand
|
|
|
182
196
|
export declare function bufferedStream(reply: ConnectionReply): ConnectionStreamReply;
|
|
183
197
|
/**
|
|
184
198
|
* The clients of the given handles over one transport: what `prepare` runs with. Only these
|
|
185
|
-
* connections can be called; the transport is never exposed to the action.
|
|
199
|
+
* connections can be called; the transport is never exposed to the action. `files` is the
|
|
200
|
+
* action's file access, which signs the read of a request's `file` after checking the principal
|
|
201
|
+
* may read the record; without it, the call reaches the transport with its `file` unresolved.
|
|
186
202
|
*/
|
|
187
203
|
export declare function connectionContext<const C extends ReadonlyArray<AnyConnectionHandle>>(handles: C, transport: ConnectionTransport["Service"], options?: {
|
|
188
204
|
readonly readOnly?: boolean;
|
|
205
|
+
readonly files?: Files["Service"];
|
|
189
206
|
}): Context.Context<ConnectionsOf<C>>;
|
|
190
207
|
/** A stubbed response for {@link Connections.test}. */
|
|
191
208
|
export interface StubResponse {
|
package/dist/connection.js
CHANGED
|
@@ -11,8 +11,10 @@ export const CONNECTION_METHODS = [
|
|
|
11
11
|
"HEAD",
|
|
12
12
|
"OPTIONS",
|
|
13
13
|
];
|
|
14
|
-
/** The largest request body. */
|
|
14
|
+
/** The largest request body, except a `file`, which SegmentStream reads from file storage. */
|
|
15
15
|
export const MAXIMUM_CONNECTION_BODY_BYTES = 2 * 1024 * 1024;
|
|
16
|
+
/** The largest byte range of a file one request may send as its body. */
|
|
17
|
+
export const MAXIMUM_CONNECTION_FILE_BYTES = 64 * 1024 * 1024;
|
|
16
18
|
/**
|
|
17
19
|
* The largest response body `get`, `post` and `request` collect. A larger response fails with
|
|
18
20
|
* `invalid_response`; `stream` reads a response of any size.
|
|
@@ -106,9 +108,16 @@ function hasHeader(headers, name) {
|
|
|
106
108
|
}
|
|
107
109
|
/** The call a request describes: query appended, body encoded and its content type set. */
|
|
108
110
|
export function connectionCall(key, request) {
|
|
109
|
-
const bodies = [request.json, request.form, request.body].filter((body) => body !== undefined);
|
|
111
|
+
const bodies = [request.json, request.form, request.body, request.file].filter((body) => body !== undefined);
|
|
110
112
|
if (bodies.length > 1) {
|
|
111
|
-
throw connectionFailure(key, "invalid_request", "Set at most one of json, form and
|
|
113
|
+
throw connectionFailure(key, "invalid_request", "Set at most one of json, form, body and file.");
|
|
114
|
+
}
|
|
115
|
+
if (request.file !== undefined) {
|
|
116
|
+
const { start, end } = request.file;
|
|
117
|
+
if ((start !== undefined && (!Number.isSafeInteger(start) || start < 0)) ||
|
|
118
|
+
(end !== undefined && (!Number.isSafeInteger(end) || end < (start ?? 0)))) {
|
|
119
|
+
throw connectionFailure(key, "invalid_request", "file_range_invalid");
|
|
120
|
+
}
|
|
112
121
|
}
|
|
113
122
|
const headers = headerPairs(request.headers);
|
|
114
123
|
let body = new Uint8Array();
|
|
@@ -139,6 +148,7 @@ export function connectionCall(key, request) {
|
|
|
139
148
|
path: withQuery(request.path, request.query),
|
|
140
149
|
headers,
|
|
141
150
|
body,
|
|
151
|
+
...(request.file === undefined ? {} : { file: request.file }),
|
|
142
152
|
};
|
|
143
153
|
}
|
|
144
154
|
/** A buffered response over what the proxy answered. */
|
|
@@ -220,11 +230,28 @@ export function bufferedStream(reply) {
|
|
|
220
230
|
}
|
|
221
231
|
/**
|
|
222
232
|
* The clients of the given handles over one transport: what `prepare` runs with. Only these
|
|
223
|
-
* connections can be called; the transport is never exposed to the action.
|
|
233
|
+
* connections can be called; the transport is never exposed to the action. `files` is the
|
|
234
|
+
* action's file access, which signs the read of a request's `file` after checking the principal
|
|
235
|
+
* may read the record; without it, the call reaches the transport with its `file` unresolved.
|
|
224
236
|
*/
|
|
225
237
|
export function connectionContext(handles, transport, options = {}) {
|
|
226
238
|
let context = Context.empty();
|
|
227
239
|
for (const handle of handles) {
|
|
240
|
+
const resolve = (call) => {
|
|
241
|
+
const sign = options.files?.source;
|
|
242
|
+
if (call.file === undefined || call.source !== undefined || sign === undefined) {
|
|
243
|
+
return Effect.succeed(call);
|
|
244
|
+
}
|
|
245
|
+
return sign(call.file).pipe(Effect.mapError((cause) => connectionFailure(handle.key, "invalid_request", "file_unreadable", cause)), Effect.flatMap((source) => source.end - source.start + 1 > MAXIMUM_CONNECTION_FILE_BYTES
|
|
246
|
+
? Effect.fail(connectionFailure(handle.key, "invalid_request", "file_range_too_large"))
|
|
247
|
+
: Effect.succeed({
|
|
248
|
+
...call,
|
|
249
|
+
headers: hasHeader(call.headers, "content-type")
|
|
250
|
+
? call.headers
|
|
251
|
+
: [...call.headers, ["content-type", source.contentType]],
|
|
252
|
+
source,
|
|
253
|
+
})));
|
|
254
|
+
};
|
|
228
255
|
const admit = (call) => {
|
|
229
256
|
if (options.readOnly !== true) {
|
|
230
257
|
return Effect.void;
|
|
@@ -236,6 +263,7 @@ export function connectionContext(handles, transport, options = {}) {
|
|
|
236
263
|
// Match the proxy's policy, including attempts to tunnel writes through GET.
|
|
237
264
|
if (!["GET", "HEAD", "OPTIONS"].includes(call.method) ||
|
|
238
265
|
call.body.byteLength > 0 ||
|
|
266
|
+
call.file !== undefined ||
|
|
239
267
|
call.headers.some(([name]) => name.toLowerCase().includes("method")) ||
|
|
240
268
|
[...url.searchParams.keys()].some((name) => ["method", "_method"].includes(name.toLowerCase()))) {
|
|
241
269
|
return Effect.fail(connectionFailure(handle.key, "invalid_request", "This action's connections are read-only."));
|
|
@@ -244,11 +272,11 @@ export function connectionContext(handles, transport, options = {}) {
|
|
|
244
272
|
}));
|
|
245
273
|
};
|
|
246
274
|
context = Context.add(context, handle.service, {
|
|
247
|
-
request: (call) => admit(call).pipe(Effect.andThen(() => transport.request({ ...
|
|
248
|
-
stream: (call) => admit(call).pipe(Effect.andThen(() => transport.stream
|
|
249
|
-
? transport.stream({ ...
|
|
275
|
+
request: (call) => admit(call).pipe(Effect.andThen(() => resolve(call)), Effect.flatMap((resolved) => transport.request({ ...resolved, connection: handle.key }))),
|
|
276
|
+
stream: (call) => admit(call).pipe(Effect.andThen(() => resolve(call)), Effect.flatMap((resolved) => transport.stream
|
|
277
|
+
? transport.stream({ ...resolved, connection: handle.key })
|
|
250
278
|
: transport
|
|
251
|
-
.request({ ...
|
|
279
|
+
.request({ ...resolved, connection: handle.key })
|
|
252
280
|
.pipe(Effect.map(bufferedStream)))),
|
|
253
281
|
});
|
|
254
282
|
}
|
package/dist/files.d.ts
CHANGED
|
@@ -26,12 +26,33 @@ export interface OpenFile {
|
|
|
26
26
|
readonly property: string;
|
|
27
27
|
readonly revisionId?: string;
|
|
28
28
|
}
|
|
29
|
+
/** A byte range of a file revision: from `start` to `end` inclusive, the whole file by default. */
|
|
30
|
+
export interface FileRange extends OpenFile {
|
|
31
|
+
readonly start?: number;
|
|
32
|
+
readonly end?: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A short-lived signed read of a byte range of a file revision, which SegmentStream's connection
|
|
36
|
+
* proxy fetches from the workspace's file storage when a connection request sends the file.
|
|
37
|
+
*/
|
|
38
|
+
export interface FileSource {
|
|
39
|
+
readonly url: string;
|
|
40
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
41
|
+
readonly start: number;
|
|
42
|
+
readonly end: number;
|
|
43
|
+
readonly contentType: string;
|
|
44
|
+
}
|
|
29
45
|
declare const Files_base: Context.ServiceClass<Files, "@segmentstream/ontology/Files", {
|
|
30
46
|
readonly stage: <E, R>(input: StageFile<E, R>) => Effect.Effect<BlobUpload, E | ActionError, R>;
|
|
31
47
|
readonly open: (input: OpenFile) => Effect.Effect<{
|
|
32
48
|
readonly file: BlobValue;
|
|
33
49
|
readonly body: Stream.Stream<Uint8Array, ActionError>;
|
|
34
50
|
}, ActionError, Scope.Scope>;
|
|
51
|
+
/**
|
|
52
|
+
* Signs a read of a file's byte range after checking the principal may read the record, for
|
|
53
|
+
* a connection request's `file`. Authoring code passes `file` to the request instead.
|
|
54
|
+
*/
|
|
55
|
+
readonly source?: (input: FileRange) => Effect.Effect<FileSource, ActionError>;
|
|
35
56
|
}>;
|
|
36
57
|
/** File I/O outside transactions, bound to the current action or workflow principal. */
|
|
37
58
|
export declare class Files extends Files_base {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { BlobValue, BlobUpload, uploads, BLOB_CONTENT_TYPES, MAX_BLOB_BYTES } from "./blob.js";
|
|
2
2
|
export { Files } from "./files.js";
|
|
3
|
-
export type { FileTarget, StageFile, OpenFile } from "./files.js";
|
|
3
|
+
export type { FileRange, FileSource, FileTarget, StageFile, OpenFile } from "./files.js";
|
|
4
4
|
export { warehouse, compatibleWarehouseColumn, warehouseColumnType, validateWarehouseSource, } from "./source.js";
|
|
5
5
|
export type { WarehouseSource } from "./source.js";
|
|
6
6
|
export { m } from "./metric.js";
|
|
@@ -12,7 +12,7 @@ export { action, isAction } from "./action.js";
|
|
|
12
12
|
export { ActionConfirmation, ConfirmationFact } from "./confirmation.js";
|
|
13
13
|
export type { ConfirmContext } from "./confirmation.js";
|
|
14
14
|
export type { Action, ActionConfig, ActionConfigWithConnections, ActionContext, ActionIdentity, ActionEncodedInput, ActionHints, ActionInput, ActionResult, ActionWriteTarget, Actions, AnyAction, PrepareContext, PrepareError, } from "./action.js";
|
|
15
|
-
export { CONNECTION_ERROR_REASONS, CONNECTION_KEY, CONNECTION_METHODS, connection, ConnectionError, Connections, ConnectionTransport, isConnection, MAXIMUM_CONNECTION_BODY_BYTES, MAXIMUM_CONNECTION_RESPONSE_BYTES, } from "./connection.js";
|
|
15
|
+
export { CONNECTION_ERROR_REASONS, CONNECTION_KEY, CONNECTION_METHODS, connection, ConnectionError, Connections, ConnectionTransport, isConnection, MAXIMUM_CONNECTION_BODY_BYTES, MAXIMUM_CONNECTION_FILE_BYTES, MAXIMUM_CONNECTION_RESPONSE_BYTES, } from "./connection.js";
|
|
16
16
|
export type { AnyConnectionHandle, Connection, ConnectionCall, ConnectionClient, ConnectionErrorReason, ConnectionHandle, ConnectionHeaders, ConnectionMethod, ConnectionOptions, ConnectionReply, ConnectionRequest, ConnectionRequestOptions, ConnectionResponse, ConnectionStreamReply, ConnectionStreamResponse, ConnectionsOf, ConnectionStub, StubRequest, StubResponse, } from "./connection.js";
|
|
17
17
|
export type { ChatChannelConfig, ChatConfig, DiscoveryOptions, EntityPermissions, JsonSchemaObject, MemberOptions, OntologyConfig, ResolvedAction, ResolvedConnection, ResolvedEntity, ResolvedIndex, ResolvedProperty, ResolvedRelationship, } from "./analyze.js";
|
|
18
18
|
export { Diagnostic, DIAGNOSTIC_CODES, formatDiagnostics, InvalidOntology } from "./diagnostics.js";
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ export { METRIC_CONDITION_OPERATORS } from "./metric-filters.js";
|
|
|
7
7
|
export * from "./legacy.js";
|
|
8
8
|
export { action, isAction } from "./action.js";
|
|
9
9
|
export { ActionConfirmation, ConfirmationFact } from "./confirmation.js";
|
|
10
|
-
export { CONNECTION_ERROR_REASONS, CONNECTION_KEY, CONNECTION_METHODS, connection, ConnectionError, Connections, ConnectionTransport, isConnection, MAXIMUM_CONNECTION_BODY_BYTES, MAXIMUM_CONNECTION_RESPONSE_BYTES, } from "./connection.js";
|
|
10
|
+
export { CONNECTION_ERROR_REASONS, CONNECTION_KEY, CONNECTION_METHODS, connection, ConnectionError, Connections, ConnectionTransport, isConnection, MAXIMUM_CONNECTION_BODY_BYTES, MAXIMUM_CONNECTION_FILE_BYTES, MAXIMUM_CONNECTION_RESPONSE_BYTES, } from "./connection.js";
|
|
11
11
|
export { Diagnostic, DIAGNOSTIC_CODES, formatDiagnostics, InvalidOntology } from "./diagnostics.js";
|
|
12
12
|
export { entity, isEntity } from "./entity.js";
|
|
13
13
|
export { isToolset, MCP_TOOL_NAME, TOOLSET_LOCK_VERSION, toolset, ToolsetLock, ToolsetLockTool, } from "./toolset.js";
|
|
@@ -13,6 +13,9 @@ function makeRedactor(values = []) {
|
|
|
13
13
|
let text = input;
|
|
14
14
|
for (const value of secrets) text = text.replaceAll(value, "[REDACTED]");
|
|
15
15
|
return redactCopyContext(redactPrivateKeys(text)).replace(
|
|
16
|
+
/https:\/\/(?:checkout\.stripe\.com\/|pay\.stripe\.com\/receipts\/)[^\s"'<>]+/gi,
|
|
17
|
+
"[REDACTED PAYMENT URL]"
|
|
18
|
+
).replace(
|
|
16
19
|
/\b(?:postgres(?:ql)?|mysql|mongodb(?:\+srv)?):\/\/\S+/gi,
|
|
17
20
|
"[REDACTED CONNECTION URI]"
|
|
18
21
|
).replace(
|