datanotes 3.0.0 → 3.1.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.
Files changed (60) hide show
  1. package/README.md +1 -5
  2. package/dist/api/client.d.cts +37 -4
  3. package/dist/api/client.d.ts +37 -4
  4. package/dist/api/index.cjs +388 -52
  5. package/dist/api/index.d.cts +3 -2
  6. package/dist/api/index.d.ts +3 -2
  7. package/dist/api/index.js +388 -52
  8. package/dist/api/mcp.cjs +6 -3
  9. package/dist/api/mcp.js +6 -3
  10. package/dist/api/otlp.d.cts +63 -15
  11. package/dist/api/otlp.d.ts +63 -15
  12. package/dist/api/redact.d.cts +25 -0
  13. package/dist/api/redact.d.ts +25 -0
  14. package/dist/api/tokens.d.cts +5 -0
  15. package/dist/api/tokens.d.ts +5 -0
  16. package/dist/api/tracing.d.cts +107 -0
  17. package/dist/api/tracing.d.ts +107 -0
  18. package/dist/datanotes.cjs +9380 -2554
  19. package/dist/docs/administration/limits.md +96 -12
  20. package/dist/docs/administration/run-the-service.md +18 -0
  21. package/dist/docs/api/operations/graph_neighbors.md +4 -2
  22. package/dist/docs/api/operations/graph_path.md +3 -3
  23. package/dist/docs/api/operations/graph_traverse.md +2 -2
  24. package/dist/docs/api/operations/record_tool_call.md +1 -0
  25. package/dist/docs/api/operations/tags/queries.md +2 -2
  26. package/dist/docs/api.md +3 -3
  27. package/dist/docs/develop/concurrency.md +36 -1
  28. package/dist/docs/develop/http-api.md +11 -1
  29. package/dist/docs/develop/telemetry.md +224 -25
  30. package/dist/docs/guides/data-quality/check-constraints.md +10 -10
  31. package/dist/docs/guides/data-quality/hand-edits.md +8 -8
  32. package/dist/docs/guides/database-objects/bases.md +11 -11
  33. package/dist/docs/guides/database-objects/catalogs-and-schemas.md +10 -10
  34. package/dist/docs/guides/database-objects/columns.md +38 -38
  35. package/dist/docs/guides/database-objects/relations.md +27 -27
  36. package/dist/docs/guides/database-objects/tables.md +37 -101
  37. package/dist/docs/guides/database-objects/views.md +44 -44
  38. package/dist/docs/guides/history/back-up.md +12 -4
  39. package/dist/docs/guides/history/change-data-feed.md +34 -34
  40. package/dist/docs/guides/history/journal-and-undo.md +12 -12
  41. package/dist/docs/guides/history/restore.md +20 -20
  42. package/dist/docs/guides/history/table-history.md +31 -31
  43. package/dist/docs/guides/history/vacuum.md +1 -10
  44. package/dist/docs/guides/read-and-write/automatic-links.md +15 -15
  45. package/dist/docs/guides/read-and-write/import-notes.md +20 -20
  46. package/dist/docs/guides/read-and-write/joins-and-aggregates.md +7 -7
  47. package/dist/docs/guides/read-and-write/read-and-filter.md +10 -10
  48. package/dist/docs/guides/read-and-write/write-rows.md +10 -10
  49. package/dist/docs/guides/search/link-graph.md +95 -0
  50. package/dist/docs/guides/search/text.md +1 -1
  51. package/dist/docs/guides/security/who-did-what.md +2 -0
  52. package/dist/docs/reference/cli.md +10 -3
  53. package/dist/docs/reference/compatibility.md +33 -13
  54. package/dist/docs/reference/operations/queries.md +3 -3
  55. package/dist/docs/reference/operations.md +11 -11
  56. package/dist/docs/reference/settings.md +37 -25
  57. package/dist/docs/release-notes.md +121 -0
  58. package/dist/docs/start/how-it-works.md +35 -3
  59. package/dist/docs/start/quick-start.md +2 -0
  60. package/package.json +3 -2
package/dist/api/mcp.cjs CHANGED
@@ -16003,7 +16003,7 @@ var OPERATIONS = [
16003
16003
  },
16004
16004
  {
16005
16005
  "name": "graph_neighbors",
16006
- "description": 'Direct neighbours of notes: what they link to (`out`) and what links to them (`in`,\nbacklinks), with counts per edge label. `direction`: out, in or both (default).\n\n`from_nodes` selects the notes: `{"paths": [...]}` and/or `{"table": ..., "where": {...}}`.\nEdges are labelled with their link column (`people`, `event`, \u2026) or `link` for other links.',
16006
+ "description": 'Direct neighbours of notes: what they link to (`out`) and what links to them (`in`,\nbacklinks), with counts per edge label. `direction`: out, in or both (default).\n\n`from_nodes` selects the notes: `{"paths": [...]}`, `{"table": ..., "where": {...}}` and/or\n`{"tables": [...]}`: the rows of several tables, by name or pattern (`["*"]` every table, `["personal.*"]` a\ncatalog\'s). The whole vault\'s graph in one call: `{"tables": ["*"]}` with direction `out` (at most 5000\nstart notes). Edges are labelled with their link column (`people`, `event`, \u2026) or `link` for other links.',
16007
16007
  "inputSchema": {
16008
16008
  "additionalProperties": false,
16009
16009
  "properties": {
@@ -16122,7 +16122,7 @@ var OPERATIONS = [
16122
16122
  },
16123
16123
  {
16124
16124
  "name": "graph_traverse",
16125
- "description": 'Breadth-first walk over links from `from_nodes` (`{"paths": [...]}` and/or `{"table", "where"}`).\n\n- `direction`: out (default, follow links), in (follow backlinks) or both.\n- `edges`: edge labels to follow (link columns such as `people`, `event`, or `link`).\n- `tables`: return only notes of these tables; `through`: only walk on through these tables.\n- `min_depth` (default 1) / `max_depth` (default 2, max 10), `limit` (default 500).\n\nEach node comes with `depth` and `via` (one shortest route). Example \u2014 moods tied to events\nwith Alice: from `{"table": "person", "where": {"name": "Alice"}}`, direction `in`, edges\n`["people", "event"]`, tables `["mood"]`, max_depth 2. Feed the paths to `select_rows` with\n`where: {"path": {"in": [...]}}` to aggregate them.',
16125
+ "description": 'Breadth-first walk over links from `from_nodes` (`{"paths": [...]}`, `{"table", "where"}` and/or `{"tables": [...]}`).\n\n- `direction`: out (default, follow links), in (follow backlinks) or both.\n- `edges`: edge labels to follow (link columns such as `people`, `event`, or `link`).\n- `tables`: return only notes of these tables; `through`: only walk on through these tables.\n- `min_depth` (default 1) / `max_depth` (default 2, max 10), `limit` (default 500).\n\nEach node comes with `depth` and `via` (one shortest route). Example \u2014 moods tied to events\nwith Alice: from `{"table": "person", "where": {"name": "Alice"}}`, direction `in`, edges\n`["people", "event"]`, tables `["mood"]`, max_depth 2. Feed the paths to `select_rows` with\n`where: {"path": {"in": [...]}}` to aggregate them.',
16126
16126
  "inputSchema": {
16127
16127
  "additionalProperties": false,
16128
16128
  "properties": {
@@ -16318,7 +16318,7 @@ var OPERATIONS = [
16318
16318
  },
16319
16319
  {
16320
16320
  "name": "graph_path",
16321
- "description": 'Shortest chain of links between two sets of notes (each `{"paths": [...]}` and/or\n`{"table", "where"}`): `found`, `length` and `path`: the steps (`from`, `label`, `direction`, `to`).\n`direction` both by default; `max_depth` default 6 (max 10).',
16321
+ "description": 'Shortest chain of links between two sets of notes (each `{"paths": [...]}`, `{"table", "where"}`\nand/or `{"tables": [...]}`): `found`, `length` and `path`: the steps (`from`, `label`, `direction`, `to`).\n`direction` both by default; `max_depth` default 6 (max 10).',
16322
16322
  "inputSchema": {
16323
16323
  "additionalProperties": false,
16324
16324
  "properties": {
@@ -16646,6 +16646,9 @@ function checkToolArguments(op, schema, args, docs) {
16646
16646
  // src/api/requests.ts
16647
16647
  var CALLABLE_OPERATIONS = new Set(OPERATIONS.map((o) => o.name));
16648
16648
 
16649
+ // src/api/tracing.ts
16650
+ var perf = globalThis.performance;
16651
+
16649
16652
  // src/api/client.ts
16650
16653
  var UNREACHABLE = {
16651
16654
  hint: "Start the engine (datanotes serve --database <folder>) or check its address; datanotes status --database <folder> shows whether it runs and where.",
package/dist/api/mcp.js CHANGED
@@ -15955,7 +15955,7 @@ var OPERATIONS = [
15955
15955
  },
15956
15956
  {
15957
15957
  "name": "graph_neighbors",
15958
- "description": 'Direct neighbours of notes: what they link to (`out`) and what links to them (`in`,\nbacklinks), with counts per edge label. `direction`: out, in or both (default).\n\n`from_nodes` selects the notes: `{"paths": [...]}` and/or `{"table": ..., "where": {...}}`.\nEdges are labelled with their link column (`people`, `event`, \u2026) or `link` for other links.',
15958
+ "description": 'Direct neighbours of notes: what they link to (`out`) and what links to them (`in`,\nbacklinks), with counts per edge label. `direction`: out, in or both (default).\n\n`from_nodes` selects the notes: `{"paths": [...]}`, `{"table": ..., "where": {...}}` and/or\n`{"tables": [...]}`: the rows of several tables, by name or pattern (`["*"]` every table, `["personal.*"]` a\ncatalog\'s). The whole vault\'s graph in one call: `{"tables": ["*"]}` with direction `out` (at most 5000\nstart notes). Edges are labelled with their link column (`people`, `event`, \u2026) or `link` for other links.',
15959
15959
  "inputSchema": {
15960
15960
  "additionalProperties": false,
15961
15961
  "properties": {
@@ -16074,7 +16074,7 @@ var OPERATIONS = [
16074
16074
  },
16075
16075
  {
16076
16076
  "name": "graph_traverse",
16077
- "description": 'Breadth-first walk over links from `from_nodes` (`{"paths": [...]}` and/or `{"table", "where"}`).\n\n- `direction`: out (default, follow links), in (follow backlinks) or both.\n- `edges`: edge labels to follow (link columns such as `people`, `event`, or `link`).\n- `tables`: return only notes of these tables; `through`: only walk on through these tables.\n- `min_depth` (default 1) / `max_depth` (default 2, max 10), `limit` (default 500).\n\nEach node comes with `depth` and `via` (one shortest route). Example \u2014 moods tied to events\nwith Alice: from `{"table": "person", "where": {"name": "Alice"}}`, direction `in`, edges\n`["people", "event"]`, tables `["mood"]`, max_depth 2. Feed the paths to `select_rows` with\n`where: {"path": {"in": [...]}}` to aggregate them.',
16077
+ "description": 'Breadth-first walk over links from `from_nodes` (`{"paths": [...]}`, `{"table", "where"}` and/or `{"tables": [...]}`).\n\n- `direction`: out (default, follow links), in (follow backlinks) or both.\n- `edges`: edge labels to follow (link columns such as `people`, `event`, or `link`).\n- `tables`: return only notes of these tables; `through`: only walk on through these tables.\n- `min_depth` (default 1) / `max_depth` (default 2, max 10), `limit` (default 500).\n\nEach node comes with `depth` and `via` (one shortest route). Example \u2014 moods tied to events\nwith Alice: from `{"table": "person", "where": {"name": "Alice"}}`, direction `in`, edges\n`["people", "event"]`, tables `["mood"]`, max_depth 2. Feed the paths to `select_rows` with\n`where: {"path": {"in": [...]}}` to aggregate them.',
16078
16078
  "inputSchema": {
16079
16079
  "additionalProperties": false,
16080
16080
  "properties": {
@@ -16270,7 +16270,7 @@ var OPERATIONS = [
16270
16270
  },
16271
16271
  {
16272
16272
  "name": "graph_path",
16273
- "description": 'Shortest chain of links between two sets of notes (each `{"paths": [...]}` and/or\n`{"table", "where"}`): `found`, `length` and `path`: the steps (`from`, `label`, `direction`, `to`).\n`direction` both by default; `max_depth` default 6 (max 10).',
16273
+ "description": 'Shortest chain of links between two sets of notes (each `{"paths": [...]}`, `{"table", "where"}`\nand/or `{"tables": [...]}`): `found`, `length` and `path`: the steps (`from`, `label`, `direction`, `to`).\n`direction` both by default; `max_depth` default 6 (max 10).',
16274
16274
  "inputSchema": {
16275
16275
  "additionalProperties": false,
16276
16276
  "properties": {
@@ -16598,6 +16598,9 @@ function checkToolArguments(op, schema, args, docs) {
16598
16598
  // src/api/requests.ts
16599
16599
  var CALLABLE_OPERATIONS = new Set(OPERATIONS.map((o) => o.name));
16600
16600
 
16601
+ // src/api/tracing.ts
16602
+ var perf = globalThis.performance;
16603
+
16601
16604
  // src/api/client.ts
16602
16605
  var UNREACHABLE = {
16603
16606
  hint: "Start the engine (datanotes serve --database <folder>) or check its address; datanotes status --database <folder> shows whether it runs and where.",
@@ -1,17 +1,21 @@
1
1
  /**
2
- * OpenTelemetry log export over OTLP/HTTP, vendor-neutral: records are buffered and POSTed to
3
- * `<endpoint>/v1/logs` as `http/protobuf` (the OTLP default) or `http/json`, which every
4
- * OpenTelemetry collector and OTLP backend reads. No dependency, no SDK. Export failures are
5
- * counted, never thrown: logging must not break the program. (OTLP over gRPC is not supported:
6
- * use the collector's HTTP port, 4318 by default.)
2
+ * OpenTelemetry export over OTLP/HTTP, vendor-neutral: log records (`OtlpLogExporter`, to
3
+ * `<endpoint>/v1/logs`) and spans (`OtlpTraceExporter`, to `<endpoint>/v1/traces`) are buffered
4
+ * and POSTed as `http/protobuf` (the OTLP default) or `http/json`, which every OpenTelemetry
5
+ * collector and OTLP backend reads. No dependency, no SDK. Export failures are counted, never
6
+ * thrown: telemetry must not break the program. (OTLP over gRPC is not supported: use the
7
+ * collector's HTTP port, 4318 by default.)
7
8
  *
8
- * Configure it in code, or from the standard OpenTelemetry variables with `otlpFromEnv`.
9
+ * A log record made inside a span names it (`log`'s `context`), so the backend links the two.
10
+ * Configure the exporters in code, or from the standard OpenTelemetry variables with
11
+ * `otlpFromEnv` and `otlpTracesFromEnv`.
9
12
  */
13
+ import type { SpanRecord, TraceContext } from "./tracing.cjs";
10
14
  export type Severity = "DEBUG" | "INFO" | "WARN" | "ERROR";
11
15
  export type AttrValue = string | number | boolean | null | undefined;
12
16
  export type OtlpProtocol = "http/protobuf" | "http/json";
13
17
  export interface OtlpOptions {
14
- /** Collector base URL, e.g. `http://127.0.0.1:4318` (`/v1/logs` is added). */
18
+ /** Collector base URL, e.g. `http://127.0.0.1:4318` (`/v1/logs` or `/v1/traces` is added). */
15
19
  endpoint: string;
16
20
  /** `service.name` of the records. */
17
21
  serviceName: string;
@@ -22,7 +26,7 @@ export interface OtlpOptions {
22
26
  headers?: Record<string, string>;
23
27
  /** More resource attributes (e.g. `host.name`). */
24
28
  resource?: Record<string, AttrValue>;
25
- /** Send at most this many records per request (default 50); a full buffer is sent at once. */
29
+ /** Send at most this many records (or spans) per request (default 50 records, 512 spans); a full buffer is sent at once. */
26
30
  maxBatch?: number;
27
31
  /** Send the buffer every this many ms (default 5000; 0: only on `flush`). */
28
32
  flushMs?: number;
@@ -30,22 +34,50 @@ export interface OtlpOptions {
30
34
  send?: (url: string, body: string | Uint8Array, headers: Record<string, string>) => Promise<void>;
31
35
  now?: () => number;
32
36
  }
33
- export declare class OtlpLogExporter {
34
- private readonly o;
35
- private buffer;
37
+ interface LogRecord {
38
+ timeUnixNano: string;
39
+ severity: Severity;
40
+ body: string;
41
+ attributes: Record<string, AttrValue>;
42
+ context?: Pick<TraceContext, "traceId" | "spanId" | "sampled">;
43
+ }
44
+ /** Unix ms (with a fraction) as OTLP nanoseconds, a decimal string. */
45
+ export declare function unixNano(ms: number): string;
46
+ /** What both exporters share: the buffer, the timer, the POST, the counts. */
47
+ declare abstract class OtlpBatcher<T> {
48
+ protected readonly o: OtlpOptions;
49
+ private readonly path;
50
+ private readonly maxBatch;
51
+ protected buffer: T[];
36
52
  private inflight;
37
53
  private timer;
38
- /** Records sent, and records lost because the collector did not take them. */
54
+ /** Items sent, and items lost because the collector did not take them (or the buffer was full). */
39
55
  sent: number;
40
56
  dropped: number;
41
- constructor(o: OtlpOptions);
42
- log(severity: Severity, body: string, attributes?: Record<string, AttrValue>): void;
57
+ constructor(o: OtlpOptions, path: string, maxBatch: number);
58
+ protected push(items: readonly T[]): void;
59
+ protected resource(): Record<string, AttrValue>;
60
+ protected abstract encode(batch: T[], protobuf: boolean): string | Uint8Array;
43
61
  /** Send what is buffered. Never rejects. */
44
62
  flush(): Promise<void>;
45
- private protobuf;
46
63
  /** Stop the timer and send what is left. */
47
64
  close(): Promise<void>;
48
65
  }
66
+ export declare class OtlpLogExporter extends OtlpBatcher<LogRecord> {
67
+ constructor(o: OtlpOptions);
68
+ /** Buffer a record; `context`: the span it was made in (its trace and span id go with it). */
69
+ log(severity: Severity, body: string, attributes?: Record<string, AttrValue>, context?: Pick<TraceContext, "traceId" | "spanId" | "sampled">): void;
70
+ protected encode(batch: LogRecord[], protobuf: boolean): string | Uint8Array;
71
+ private protobuf;
72
+ }
73
+ /** Spans to `<endpoint>/v1/traces` (ExportTraceServiceRequest), in batches. */
74
+ export declare class OtlpTraceExporter extends OtlpBatcher<SpanRecord> {
75
+ constructor(o: OtlpOptions);
76
+ /** Buffer finished spans (sent with the next batch). Never throws. */
77
+ export(spans: SpanRecord | readonly SpanRecord[]): void;
78
+ protected encode(batch: SpanRecord[], protobuf: boolean): string | Uint8Array;
79
+ private protobuf;
80
+ }
49
81
  /** `k1=v1,k2=v2` (values URL-encoded), the format of `OTEL_EXPORTER_OTLP_HEADERS`. */
50
82
  export declare function parseOtlpHeaders(text: string | undefined): Record<string, string>;
51
83
  /** `k1=v1,k2=v2` resource attributes, the format of `OTEL_RESOURCE_ATTRIBUTES`. */
@@ -61,5 +93,21 @@ export declare function otlpFromEnv(env: Record<string, string | undefined>, def
61
93
  serviceName: string;
62
94
  serviceVersion?: string;
63
95
  }): OtlpOptions | null;
96
+ /**
97
+ * The same for traces: `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` (full URL of /v1/traces) or
98
+ * `OTEL_EXPORTER_OTLP_ENDPOINT`; the `…_TRACES_…` headers and protocol; null also when
99
+ * `OTEL_TRACES_EXPORTER=none`.
100
+ */
101
+ export declare function otlpTracesFromEnv(env: Record<string, string | undefined>, defaults: {
102
+ serviceName: string;
103
+ serviceVersion?: string;
104
+ }): OtlpOptions | null;
105
+ /**
106
+ * The share of new traces to keep, from `OTEL_TRACES_SAMPLER` and `OTEL_TRACES_SAMPLER_ARG`
107
+ * (`always_on`, `always_off`, `traceidratio`, and their `parentbased_` forms: a trace continued
108
+ * from a caller always follows the caller); undefined when they say nothing usable.
109
+ */
110
+ export declare function samplerRatioFromEnv(env: Record<string, string | undefined>): number | undefined;
64
111
  /** `http/protobuf` or `http/json` from a setting or variable; undefined for anything else. */
65
112
  export declare function otlpProtocol(v: string | undefined): OtlpProtocol | undefined;
113
+ export {};
@@ -1,17 +1,21 @@
1
1
  /**
2
- * OpenTelemetry log export over OTLP/HTTP, vendor-neutral: records are buffered and POSTed to
3
- * `<endpoint>/v1/logs` as `http/protobuf` (the OTLP default) or `http/json`, which every
4
- * OpenTelemetry collector and OTLP backend reads. No dependency, no SDK. Export failures are
5
- * counted, never thrown: logging must not break the program. (OTLP over gRPC is not supported:
6
- * use the collector's HTTP port, 4318 by default.)
2
+ * OpenTelemetry export over OTLP/HTTP, vendor-neutral: log records (`OtlpLogExporter`, to
3
+ * `<endpoint>/v1/logs`) and spans (`OtlpTraceExporter`, to `<endpoint>/v1/traces`) are buffered
4
+ * and POSTed as `http/protobuf` (the OTLP default) or `http/json`, which every OpenTelemetry
5
+ * collector and OTLP backend reads. No dependency, no SDK. Export failures are counted, never
6
+ * thrown: telemetry must not break the program. (OTLP over gRPC is not supported: use the
7
+ * collector's HTTP port, 4318 by default.)
7
8
  *
8
- * Configure it in code, or from the standard OpenTelemetry variables with `otlpFromEnv`.
9
+ * A log record made inside a span names it (`log`'s `context`), so the backend links the two.
10
+ * Configure the exporters in code, or from the standard OpenTelemetry variables with
11
+ * `otlpFromEnv` and `otlpTracesFromEnv`.
9
12
  */
13
+ import type { SpanRecord, TraceContext } from "./tracing.js";
10
14
  export type Severity = "DEBUG" | "INFO" | "WARN" | "ERROR";
11
15
  export type AttrValue = string | number | boolean | null | undefined;
12
16
  export type OtlpProtocol = "http/protobuf" | "http/json";
13
17
  export interface OtlpOptions {
14
- /** Collector base URL, e.g. `http://127.0.0.1:4318` (`/v1/logs` is added). */
18
+ /** Collector base URL, e.g. `http://127.0.0.1:4318` (`/v1/logs` or `/v1/traces` is added). */
15
19
  endpoint: string;
16
20
  /** `service.name` of the records. */
17
21
  serviceName: string;
@@ -22,7 +26,7 @@ export interface OtlpOptions {
22
26
  headers?: Record<string, string>;
23
27
  /** More resource attributes (e.g. `host.name`). */
24
28
  resource?: Record<string, AttrValue>;
25
- /** Send at most this many records per request (default 50); a full buffer is sent at once. */
29
+ /** Send at most this many records (or spans) per request (default 50 records, 512 spans); a full buffer is sent at once. */
26
30
  maxBatch?: number;
27
31
  /** Send the buffer every this many ms (default 5000; 0: only on `flush`). */
28
32
  flushMs?: number;
@@ -30,22 +34,50 @@ export interface OtlpOptions {
30
34
  send?: (url: string, body: string | Uint8Array, headers: Record<string, string>) => Promise<void>;
31
35
  now?: () => number;
32
36
  }
33
- export declare class OtlpLogExporter {
34
- private readonly o;
35
- private buffer;
37
+ interface LogRecord {
38
+ timeUnixNano: string;
39
+ severity: Severity;
40
+ body: string;
41
+ attributes: Record<string, AttrValue>;
42
+ context?: Pick<TraceContext, "traceId" | "spanId" | "sampled">;
43
+ }
44
+ /** Unix ms (with a fraction) as OTLP nanoseconds, a decimal string. */
45
+ export declare function unixNano(ms: number): string;
46
+ /** What both exporters share: the buffer, the timer, the POST, the counts. */
47
+ declare abstract class OtlpBatcher<T> {
48
+ protected readonly o: OtlpOptions;
49
+ private readonly path;
50
+ private readonly maxBatch;
51
+ protected buffer: T[];
36
52
  private inflight;
37
53
  private timer;
38
- /** Records sent, and records lost because the collector did not take them. */
54
+ /** Items sent, and items lost because the collector did not take them (or the buffer was full). */
39
55
  sent: number;
40
56
  dropped: number;
41
- constructor(o: OtlpOptions);
42
- log(severity: Severity, body: string, attributes?: Record<string, AttrValue>): void;
57
+ constructor(o: OtlpOptions, path: string, maxBatch: number);
58
+ protected push(items: readonly T[]): void;
59
+ protected resource(): Record<string, AttrValue>;
60
+ protected abstract encode(batch: T[], protobuf: boolean): string | Uint8Array;
43
61
  /** Send what is buffered. Never rejects. */
44
62
  flush(): Promise<void>;
45
- private protobuf;
46
63
  /** Stop the timer and send what is left. */
47
64
  close(): Promise<void>;
48
65
  }
66
+ export declare class OtlpLogExporter extends OtlpBatcher<LogRecord> {
67
+ constructor(o: OtlpOptions);
68
+ /** Buffer a record; `context`: the span it was made in (its trace and span id go with it). */
69
+ log(severity: Severity, body: string, attributes?: Record<string, AttrValue>, context?: Pick<TraceContext, "traceId" | "spanId" | "sampled">): void;
70
+ protected encode(batch: LogRecord[], protobuf: boolean): string | Uint8Array;
71
+ private protobuf;
72
+ }
73
+ /** Spans to `<endpoint>/v1/traces` (ExportTraceServiceRequest), in batches. */
74
+ export declare class OtlpTraceExporter extends OtlpBatcher<SpanRecord> {
75
+ constructor(o: OtlpOptions);
76
+ /** Buffer finished spans (sent with the next batch). Never throws. */
77
+ export(spans: SpanRecord | readonly SpanRecord[]): void;
78
+ protected encode(batch: SpanRecord[], protobuf: boolean): string | Uint8Array;
79
+ private protobuf;
80
+ }
49
81
  /** `k1=v1,k2=v2` (values URL-encoded), the format of `OTEL_EXPORTER_OTLP_HEADERS`. */
50
82
  export declare function parseOtlpHeaders(text: string | undefined): Record<string, string>;
51
83
  /** `k1=v1,k2=v2` resource attributes, the format of `OTEL_RESOURCE_ATTRIBUTES`. */
@@ -61,5 +93,21 @@ export declare function otlpFromEnv(env: Record<string, string | undefined>, def
61
93
  serviceName: string;
62
94
  serviceVersion?: string;
63
95
  }): OtlpOptions | null;
96
+ /**
97
+ * The same for traces: `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` (full URL of /v1/traces) or
98
+ * `OTEL_EXPORTER_OTLP_ENDPOINT`; the `…_TRACES_…` headers and protocol; null also when
99
+ * `OTEL_TRACES_EXPORTER=none`.
100
+ */
101
+ export declare function otlpTracesFromEnv(env: Record<string, string | undefined>, defaults: {
102
+ serviceName: string;
103
+ serviceVersion?: string;
104
+ }): OtlpOptions | null;
105
+ /**
106
+ * The share of new traces to keep, from `OTEL_TRACES_SAMPLER` and `OTEL_TRACES_SAMPLER_ARG`
107
+ * (`always_on`, `always_off`, `traceidratio`, and their `parentbased_` forms: a trace continued
108
+ * from a caller always follows the caller); undefined when they say nothing usable.
109
+ */
110
+ export declare function samplerRatioFromEnv(env: Record<string, string | undefined>): number | undefined;
64
111
  /** `http/protobuf` or `http/json` from a setting or variable; undefined for anything else. */
65
112
  export declare function otlpProtocol(v: string | undefined): OtlpProtocol | undefined;
113
+ export {};
@@ -15,3 +15,28 @@ export declare function redactToolCall(tool: string, args: Record<string, unknow
15
15
  args: Record<string, unknown>;
16
16
  value: unknown;
17
17
  };
18
+ /** How many characters of a recorded call's result, and of each of its arguments, are kept. */
19
+ export declare const RECORDED_CHARS: {
20
+ readonly value: 1000;
21
+ readonly arg: 300;
22
+ };
23
+ /** A value as a recorded call keeps it: a text, or an object's JSON, longer than `n` characters is cut (with "…"). */
24
+ export declare function cutRecorded(v: unknown, n: number): unknown;
25
+ /** A result object in short: its first 30 fields, lists as their length, texts cut at 200 characters, nothing nested. */
26
+ export declare function summarizeRecorded(v: Record<string, unknown>): Record<string, unknown>;
27
+ /** An object that is no list. */
28
+ export declare function isPlainObject(v: unknown): v is Record<string, unknown>;
29
+ /**
30
+ * A call (secrets already removed) as a reporter sends it to an engine that takes it cut: the
31
+ * arguments and the value cut as the engine cuts them, and the summary of a result object, which
32
+ * the cut value may no longer give. The engine records the same event as from the whole call.
33
+ */
34
+ export declare function cutToolCall(call: {
35
+ args: Record<string, unknown>;
36
+ ok: boolean;
37
+ value: unknown;
38
+ }): {
39
+ args: Record<string, unknown>;
40
+ value: unknown;
41
+ summary?: Record<string, unknown>;
42
+ };
@@ -15,3 +15,28 @@ export declare function redactToolCall(tool: string, args: Record<string, unknow
15
15
  args: Record<string, unknown>;
16
16
  value: unknown;
17
17
  };
18
+ /** How many characters of a recorded call's result, and of each of its arguments, are kept. */
19
+ export declare const RECORDED_CHARS: {
20
+ readonly value: 1000;
21
+ readonly arg: 300;
22
+ };
23
+ /** A value as a recorded call keeps it: a text, or an object's JSON, longer than `n` characters is cut (with "…"). */
24
+ export declare function cutRecorded(v: unknown, n: number): unknown;
25
+ /** A result object in short: its first 30 fields, lists as their length, texts cut at 200 characters, nothing nested. */
26
+ export declare function summarizeRecorded(v: Record<string, unknown>): Record<string, unknown>;
27
+ /** An object that is no list. */
28
+ export declare function isPlainObject(v: unknown): v is Record<string, unknown>;
29
+ /**
30
+ * A call (secrets already removed) as a reporter sends it to an engine that takes it cut: the
31
+ * arguments and the value cut as the engine cuts them, and the summary of a result object, which
32
+ * the cut value may no longer give. The engine records the same event as from the whole call.
33
+ */
34
+ export declare function cutToolCall(call: {
35
+ args: Record<string, unknown>;
36
+ ok: boolean;
37
+ value: unknown;
38
+ }): {
39
+ args: Record<string, unknown>;
40
+ value: unknown;
41
+ summary?: Record<string, unknown>;
42
+ };
@@ -3,5 +3,10 @@
3
3
  * per 4 letters, numbers one per 3 digits, every other symbol (JSON punctuation, quotes, …) one.
4
4
  * Close to real tokenizers on JSON and on Italian/English prose (within ~15%); good for telling
5
5
  * which tools and sessions fill the context, not for billing.
6
+ *
7
+ * One pass over the text, character by character: a run of letters (`\p{L}`) or of digits
8
+ * (`\p{N}`) is one word or number, its length counted in UTF-16 units; white space (`\s`) counts
9
+ * nothing; any other character counts one.
6
10
  */
7
11
  export declare function estimateTokens(text: string): number;
12
+ export declare const ASTRAL_KEPT = 4096;
@@ -3,5 +3,10 @@
3
3
  * per 4 letters, numbers one per 3 digits, every other symbol (JSON punctuation, quotes, …) one.
4
4
  * Close to real tokenizers on JSON and on Italian/English prose (within ~15%); good for telling
5
5
  * which tools and sessions fill the context, not for billing.
6
+ *
7
+ * One pass over the text, character by character: a run of letters (`\p{L}`) or of digits
8
+ * (`\p{N}`) is one word or number, its length counted in UTF-16 units; white space (`\s`) counts
9
+ * nothing; any other character counts one.
6
10
  */
7
11
  export declare function estimateTokens(text: string): number;
12
+ export declare const ASTRAL_KEPT = 4096;
@@ -0,0 +1,107 @@
1
+ /**
2
+ * W3C Trace Context and a small tracer, with no dependency, for programs that call the engine:
3
+ * the MCP server (`datanotes mcp`), apps, scripts. A program continues its own trace in the
4
+ * engine by sending `traceparent` (and `tracestate`) with its requests: `DatanotesClient` does it
5
+ * with its `trace` option, or makes a CLIENT span per request with its `tracer` option.
6
+ *
7
+ * The spans go to an exporter, usually `OtlpTraceExporter` (otlp.ts). Unlike the engine's tracer,
8
+ * this one keeps no context across `await`: pass the parent explicitly, so it runs anywhere
9
+ * (Node, browsers, Obsidian).
10
+ */
11
+ export type SpanKind = "internal" | "server" | "client" | "producer" | "consumer";
12
+ export type SpanStatusCode = "unset" | "ok" | "error";
13
+ type AttrValue = string | number | boolean | null | undefined;
14
+ /** A position in a trace: what `traceparent` carries. */
15
+ export interface TraceContext {
16
+ /** 32 lowercase hex characters. */
17
+ traceId: string;
18
+ /** 16 lowercase hex characters: the caller's span. */
19
+ spanId: string;
20
+ /** Whether the caller records the trace (flag `01`). */
21
+ sampled: boolean;
22
+ /** The `tracestate` header, passed on as it came. */
23
+ traceState?: string;
24
+ }
25
+ export declare const TRACEPARENT_HEADER = "traceparent";
26
+ export declare const TRACESTATE_HEADER = "tracestate";
27
+ /**
28
+ * Read a `traceparent` header (and its `tracestate`); null when it is missing or invalid (an
29
+ * all-zero id, version `ff`, a version 00 header with extra fields), as the W3C spec says.
30
+ */
31
+ export declare function parseTraceparent(traceparent: string | null | undefined, tracestate?: string | null): TraceContext | null;
32
+ /** The `traceparent` header of a context (version 00). */
33
+ export declare function formatTraceparent(ctx: TraceContext): string;
34
+ /** The headers that continue `ctx` in another process: `traceparent`, and `tracestate` when there is one. */
35
+ export declare function traceHeaders(ctx: TraceContext): Record<string, string>;
36
+ /** A new random trace id (32 hex characters). */
37
+ export declare const newTraceId: () => string;
38
+ /** A new random span id (16 hex characters). */
39
+ export declare const newSpanId: () => string;
40
+ /** A finished span, as `OtlpTraceExporter` sends it (times are Unix ms, with a fraction). */
41
+ export interface SpanRecord {
42
+ traceId: string;
43
+ spanId: string;
44
+ parentSpanId?: string;
45
+ traceState?: string;
46
+ name: string;
47
+ kind: SpanKind;
48
+ startMs: number;
49
+ endMs: number;
50
+ attributes: Record<string, AttrValue>;
51
+ events: {
52
+ name: string;
53
+ timeMs: number;
54
+ attributes: Record<string, AttrValue>;
55
+ }[];
56
+ status: {
57
+ code: SpanStatusCode;
58
+ message?: string;
59
+ };
60
+ droppedAttributes?: number;
61
+ droppedEvents?: number;
62
+ }
63
+ export interface TracerOptions {
64
+ /** Where finished spans go, e.g. `(s) => exporter.export(s)` of an `OtlpTraceExporter`. */
65
+ export(spans: SpanRecord[]): void;
66
+ /** Share of new traces kept, 0 to 1 (default 1); a trace continued from a parent follows the parent. */
67
+ sampleRatio?: number;
68
+ /** Unix time in ms (default: `performance` when there is one, else `Date.now`). */
69
+ now?: () => number;
70
+ }
71
+ /** One operation of a program, timed; `end()` sends it. Not sampled: `recording` is false and nothing is sent. */
72
+ export declare class TraceSpan {
73
+ private readonly tracer;
74
+ readonly name: string;
75
+ readonly kind: SpanKind;
76
+ readonly parent: TraceContext | null;
77
+ readonly recording: boolean;
78
+ readonly context: TraceContext;
79
+ private readonly startMs;
80
+ private readonly attributes;
81
+ private readonly events;
82
+ private status;
83
+ private ended;
84
+ constructor(tracer: Tracer, name: string, kind: SpanKind, parent: TraceContext | null, recording: boolean, attributes: Record<string, AttrValue>);
85
+ setAttribute(key: string, value: AttrValue): this;
86
+ setAttributes(attributes: Record<string, AttrValue>): this;
87
+ addEvent(name: string, attributes?: Record<string, AttrValue>): this;
88
+ /** An `exception` event, `error.type` and status ERROR. */
89
+ recordException(e: unknown): this;
90
+ setStatus(code: SpanStatusCode, message?: string): this;
91
+ end(): void;
92
+ }
93
+ /** Makes spans with explicit parents and hands them to an exporter. Never throws. */
94
+ export declare class Tracer {
95
+ private readonly o;
96
+ readonly now: () => number;
97
+ constructor(o: TracerOptions);
98
+ /** A new span: a child of `parent` (a context or a `traceparent` header), or a new trace. */
99
+ startSpan(name: string, opts?: {
100
+ kind?: SpanKind;
101
+ parent?: TraceContext | string | null;
102
+ attributes?: Record<string, AttrValue>;
103
+ }): TraceSpan;
104
+ /** @internal */
105
+ send(span: SpanRecord): void;
106
+ }
107
+ export {};
@@ -0,0 +1,107 @@
1
+ /**
2
+ * W3C Trace Context and a small tracer, with no dependency, for programs that call the engine:
3
+ * the MCP server (`datanotes mcp`), apps, scripts. A program continues its own trace in the
4
+ * engine by sending `traceparent` (and `tracestate`) with its requests: `DatanotesClient` does it
5
+ * with its `trace` option, or makes a CLIENT span per request with its `tracer` option.
6
+ *
7
+ * The spans go to an exporter, usually `OtlpTraceExporter` (otlp.ts). Unlike the engine's tracer,
8
+ * this one keeps no context across `await`: pass the parent explicitly, so it runs anywhere
9
+ * (Node, browsers, Obsidian).
10
+ */
11
+ export type SpanKind = "internal" | "server" | "client" | "producer" | "consumer";
12
+ export type SpanStatusCode = "unset" | "ok" | "error";
13
+ type AttrValue = string | number | boolean | null | undefined;
14
+ /** A position in a trace: what `traceparent` carries. */
15
+ export interface TraceContext {
16
+ /** 32 lowercase hex characters. */
17
+ traceId: string;
18
+ /** 16 lowercase hex characters: the caller's span. */
19
+ spanId: string;
20
+ /** Whether the caller records the trace (flag `01`). */
21
+ sampled: boolean;
22
+ /** The `tracestate` header, passed on as it came. */
23
+ traceState?: string;
24
+ }
25
+ export declare const TRACEPARENT_HEADER = "traceparent";
26
+ export declare const TRACESTATE_HEADER = "tracestate";
27
+ /**
28
+ * Read a `traceparent` header (and its `tracestate`); null when it is missing or invalid (an
29
+ * all-zero id, version `ff`, a version 00 header with extra fields), as the W3C spec says.
30
+ */
31
+ export declare function parseTraceparent(traceparent: string | null | undefined, tracestate?: string | null): TraceContext | null;
32
+ /** The `traceparent` header of a context (version 00). */
33
+ export declare function formatTraceparent(ctx: TraceContext): string;
34
+ /** The headers that continue `ctx` in another process: `traceparent`, and `tracestate` when there is one. */
35
+ export declare function traceHeaders(ctx: TraceContext): Record<string, string>;
36
+ /** A new random trace id (32 hex characters). */
37
+ export declare const newTraceId: () => string;
38
+ /** A new random span id (16 hex characters). */
39
+ export declare const newSpanId: () => string;
40
+ /** A finished span, as `OtlpTraceExporter` sends it (times are Unix ms, with a fraction). */
41
+ export interface SpanRecord {
42
+ traceId: string;
43
+ spanId: string;
44
+ parentSpanId?: string;
45
+ traceState?: string;
46
+ name: string;
47
+ kind: SpanKind;
48
+ startMs: number;
49
+ endMs: number;
50
+ attributes: Record<string, AttrValue>;
51
+ events: {
52
+ name: string;
53
+ timeMs: number;
54
+ attributes: Record<string, AttrValue>;
55
+ }[];
56
+ status: {
57
+ code: SpanStatusCode;
58
+ message?: string;
59
+ };
60
+ droppedAttributes?: number;
61
+ droppedEvents?: number;
62
+ }
63
+ export interface TracerOptions {
64
+ /** Where finished spans go, e.g. `(s) => exporter.export(s)` of an `OtlpTraceExporter`. */
65
+ export(spans: SpanRecord[]): void;
66
+ /** Share of new traces kept, 0 to 1 (default 1); a trace continued from a parent follows the parent. */
67
+ sampleRatio?: number;
68
+ /** Unix time in ms (default: `performance` when there is one, else `Date.now`). */
69
+ now?: () => number;
70
+ }
71
+ /** One operation of a program, timed; `end()` sends it. Not sampled: `recording` is false and nothing is sent. */
72
+ export declare class TraceSpan {
73
+ private readonly tracer;
74
+ readonly name: string;
75
+ readonly kind: SpanKind;
76
+ readonly parent: TraceContext | null;
77
+ readonly recording: boolean;
78
+ readonly context: TraceContext;
79
+ private readonly startMs;
80
+ private readonly attributes;
81
+ private readonly events;
82
+ private status;
83
+ private ended;
84
+ constructor(tracer: Tracer, name: string, kind: SpanKind, parent: TraceContext | null, recording: boolean, attributes: Record<string, AttrValue>);
85
+ setAttribute(key: string, value: AttrValue): this;
86
+ setAttributes(attributes: Record<string, AttrValue>): this;
87
+ addEvent(name: string, attributes?: Record<string, AttrValue>): this;
88
+ /** An `exception` event, `error.type` and status ERROR. */
89
+ recordException(e: unknown): this;
90
+ setStatus(code: SpanStatusCode, message?: string): this;
91
+ end(): void;
92
+ }
93
+ /** Makes spans with explicit parents and hands them to an exporter. Never throws. */
94
+ export declare class Tracer {
95
+ private readonly o;
96
+ readonly now: () => number;
97
+ constructor(o: TracerOptions);
98
+ /** A new span: a child of `parent` (a context or a `traceparent` header), or a new trace. */
99
+ startSpan(name: string, opts?: {
100
+ kind?: SpanKind;
101
+ parent?: TraceContext | string | null;
102
+ attributes?: Record<string, AttrValue>;
103
+ }): TraceSpan;
104
+ /** @internal */
105
+ send(span: SpanRecord): void;
106
+ }
107
+ export {};