opencode-graphiti 0.2.0-canary.fdf8b85.20260323212818 → 0.2.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 (96) hide show
  1. package/README.md +16 -2
  2. package/esm/deno.d.ts +0 -1
  3. package/esm/deno.js +0 -1
  4. package/esm/deps/jsr.io/@std/ulid/1.0.0/_util.d.ts +14 -0
  5. package/esm/deps/jsr.io/@std/ulid/1.0.0/_util.d.ts.map +1 -0
  6. package/esm/deps/jsr.io/@std/ulid/1.0.0/_util.js +65 -0
  7. package/esm/deps/jsr.io/@std/ulid/1.0.0/decode_time.d.ts +20 -0
  8. package/esm/deps/jsr.io/@std/ulid/1.0.0/decode_time.d.ts.map +1 -0
  9. package/esm/deps/jsr.io/@std/ulid/1.0.0/decode_time.js +43 -0
  10. package/esm/deps/jsr.io/@std/ulid/1.0.0/mod.d.ts +44 -0
  11. package/esm/deps/jsr.io/@std/ulid/1.0.0/mod.d.ts.map +1 -0
  12. package/esm/deps/jsr.io/@std/ulid/1.0.0/mod.js +47 -0
  13. package/esm/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.d.ts +44 -0
  14. package/esm/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.d.ts.map +1 -0
  15. package/esm/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.js +51 -0
  16. package/esm/deps/jsr.io/@std/ulid/1.0.0/ulid.d.ts +31 -0
  17. package/esm/deps/jsr.io/@std/ulid/1.0.0/ulid.d.ts.map +1 -0
  18. package/esm/deps/jsr.io/@std/ulid/1.0.0/ulid.js +37 -0
  19. package/esm/src/config.d.ts.map +1 -1
  20. package/esm/src/config.js +65 -23
  21. package/esm/src/handlers/messages.d.ts.map +1 -1
  22. package/esm/src/handlers/messages.js +33 -8
  23. package/esm/src/handlers/tool-before.d.ts.map +1 -1
  24. package/esm/src/handlers/tool-before.js +7 -4
  25. package/esm/src/index.d.ts.map +1 -1
  26. package/esm/src/index.js +159 -122
  27. package/esm/src/services/batch-drain.d.ts +11 -0
  28. package/esm/src/services/batch-drain.d.ts.map +1 -1
  29. package/esm/src/services/batch-drain.js +196 -14
  30. package/esm/src/services/connection-manager.d.ts +7 -1
  31. package/esm/src/services/connection-manager.d.ts.map +1 -1
  32. package/esm/src/services/connection-manager.js +43 -5
  33. package/esm/src/services/context-limit.d.ts +2 -3
  34. package/esm/src/services/context-limit.d.ts.map +1 -1
  35. package/esm/src/services/context-limit.js +11 -4
  36. package/esm/src/services/endpoint-redaction.d.ts +2 -0
  37. package/esm/src/services/endpoint-redaction.d.ts.map +1 -0
  38. package/esm/src/services/endpoint-redaction.js +13 -0
  39. package/esm/src/services/graphiti-mcp.js +4 -4
  40. package/esm/src/services/session-corpus.d.ts.map +1 -1
  41. package/esm/src/services/session-corpus.js +2 -1
  42. package/esm/src/services/session-executor.d.ts.map +1 -1
  43. package/esm/src/services/session-executor.js +2 -4
  44. package/esm/src/services/session-mcp-runtime.d.ts.map +1 -1
  45. package/esm/src/services/session-mcp-runtime.js +2 -4
  46. package/esm/src/utils.d.ts +8 -0
  47. package/esm/src/utils.d.ts.map +1 -1
  48. package/esm/src/utils.js +20 -0
  49. package/package.json +1 -1
  50. package/script/deno.d.ts +0 -1
  51. package/script/deno.js +0 -1
  52. package/script/deps/jsr.io/@std/ulid/1.0.0/_util.d.ts +14 -0
  53. package/script/deps/jsr.io/@std/ulid/1.0.0/_util.d.ts.map +1 -0
  54. package/script/deps/jsr.io/@std/ulid/1.0.0/_util.js +72 -0
  55. package/script/deps/jsr.io/@std/ulid/1.0.0/decode_time.d.ts +20 -0
  56. package/script/deps/jsr.io/@std/ulid/1.0.0/decode_time.d.ts.map +1 -0
  57. package/script/deps/jsr.io/@std/ulid/1.0.0/decode_time.js +46 -0
  58. package/script/deps/jsr.io/@std/ulid/1.0.0/mod.d.ts +44 -0
  59. package/script/deps/jsr.io/@std/ulid/1.0.0/mod.d.ts.map +1 -0
  60. package/script/deps/jsr.io/@std/ulid/1.0.0/mod.js +63 -0
  61. package/script/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.d.ts +44 -0
  62. package/script/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.d.ts.map +1 -0
  63. package/script/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.js +54 -0
  64. package/script/deps/jsr.io/@std/ulid/1.0.0/ulid.d.ts +31 -0
  65. package/script/deps/jsr.io/@std/ulid/1.0.0/ulid.d.ts.map +1 -0
  66. package/script/deps/jsr.io/@std/ulid/1.0.0/ulid.js +40 -0
  67. package/script/src/config.d.ts.map +1 -1
  68. package/script/src/config.js +65 -23
  69. package/script/src/handlers/messages.d.ts.map +1 -1
  70. package/script/src/handlers/messages.js +33 -8
  71. package/script/src/handlers/tool-before.d.ts.map +1 -1
  72. package/script/src/handlers/tool-before.js +7 -4
  73. package/script/src/index.d.ts.map +1 -1
  74. package/script/src/index.js +161 -124
  75. package/script/src/services/batch-drain.d.ts +11 -0
  76. package/script/src/services/batch-drain.d.ts.map +1 -1
  77. package/script/src/services/batch-drain.js +229 -14
  78. package/script/src/services/connection-manager.d.ts +7 -1
  79. package/script/src/services/connection-manager.d.ts.map +1 -1
  80. package/script/src/services/connection-manager.js +43 -5
  81. package/script/src/services/context-limit.d.ts +2 -3
  82. package/script/src/services/context-limit.d.ts.map +1 -1
  83. package/script/src/services/context-limit.js +11 -4
  84. package/script/src/services/endpoint-redaction.d.ts +2 -0
  85. package/script/src/services/endpoint-redaction.d.ts.map +1 -0
  86. package/script/src/services/endpoint-redaction.js +17 -0
  87. package/script/src/services/graphiti-mcp.js +4 -4
  88. package/script/src/services/session-corpus.d.ts.map +1 -1
  89. package/script/src/services/session-corpus.js +2 -1
  90. package/script/src/services/session-executor.d.ts.map +1 -1
  91. package/script/src/services/session-executor.js +3 -5
  92. package/script/src/services/session-mcp-runtime.d.ts.map +1 -1
  93. package/script/src/services/session-mcp-runtime.js +2 -4
  94. package/script/src/utils.d.ts +8 -0
  95. package/script/src/utils.d.ts.map +1 -1
  96. package/script/src/utils.js +23 -1
package/README.md CHANGED
@@ -145,6 +145,10 @@ long-term knowledge graph on top of the same backend.
145
145
 
146
146
  Add the plugin to your `opencode.json` (or `opencode.jsonc`):
147
147
 
148
+ The package root intentionally exports only the `graphiti` plugin entrypoint.
149
+ Helper symbols under `src/` are internal implementation details and are not a
150
+ supported public import surface.
151
+
148
152
  ```jsonc
149
153
  {
150
154
  "plugin": ["opencode-graphiti"]
@@ -155,8 +159,9 @@ Add the plugin to your `opencode.json` (or `opencode.jsonc`):
155
159
 
156
160
  Local distributable builds are not a routine local setup step: `deno task
157
161
  build`
158
- requires an explicit `VERSION` via `dnt.ts`. If you already have a built
159
- artifact, add it to your `opencode.json`:
162
+ uses the `VERSION` environment variable when set and otherwise falls back to the
163
+ `version` in `deno.json` via `dnt.ts`. If you already have a built artifact, add
164
+ it to your `opencode.json`:
160
165
 
161
166
  ```jsonc
162
167
  {
@@ -230,6 +235,15 @@ top-level aliases remain supported for backward compatibility. Precedence is:
230
235
  1. `redis.*` (canonical)
231
236
  2. top-level Graphiti aliases such as `endpoint` and `groupIdPrefix`
232
237
 
238
+ Endpoint values must resolve to valid URLs. The loader applies best-effort
239
+ coercion for endpoint-like inputs by trimming whitespace, adding the expected
240
+ scheme when omitted, and filling the default port only when a missing-scheme
241
+ input also omits a port. For example, `localhost` under `redis.endpoint`
242
+ resolves to `redis://localhost:6379`, `cache.internal:6380` resolves to
243
+ `redis://cache.internal:6380`, and `graphiti.internal/mcp` under
244
+ `graphiti.endpoint` resolves to `http://graphiti.internal:8000/mcp`. Inputs that
245
+ still fail URL parsing, or that use a disallowed explicit scheme, are rejected.
246
+
233
247
  ### Legacy Top-Level Keys
234
248
 
235
249
  For backward compatibility, the following original Graphiti top-level keys are
package/esm/deno.d.ts CHANGED
@@ -6,7 +6,6 @@ declare namespace _default {
6
6
  export namespace tasks {
7
7
  let build: string;
8
8
  let check: string;
9
- let deploy: string;
10
9
  let dev: string;
11
10
  let lint: string;
12
11
  let fmt: string;
package/esm/deno.js CHANGED
@@ -6,7 +6,6 @@ export default {
6
6
  "tasks": {
7
7
  "build": "deno run -A dnt.ts",
8
8
  "check": "deno check src/index.ts",
9
- "deploy": "deno eval \"throw new Error('Manual publish is disabled. Use the GitHub Actions publish workflow for releases.')\"",
10
9
  "dev": "deno run --allow-all src/index.ts",
11
10
  "lint": "deno lint",
12
11
  "fmt": "deno fmt"
@@ -0,0 +1,14 @@
1
+ /** Type for a ULID generator function. */
2
+ export type ULID = (seedTime?: number) => string;
3
+ export declare const ENCODING = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
4
+ export declare const ENCODING_LEN: number;
5
+ export declare const TIME_MAX: number;
6
+ export declare const TIME_LEN = 10;
7
+ export declare const RANDOM_LEN = 16;
8
+ export declare const ULID_LEN: number;
9
+ export declare function encodeTime(timestamp: number): string;
10
+ export declare function encodeRandom(): string;
11
+ export declare function incrementBase32(str: string): string;
12
+ /** Generates a monotonically increasing ULID. */
13
+ export declare function monotonicFactory(encodeRand?: typeof encodeRandom): ULID;
14
+ //# sourceMappingURL=_util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_util.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/ulid/1.0.0/_util.ts"],"names":[],"mappings":"AAEA,0CAA0C;AAC1C,MAAM,MAAM,IAAI,GAAG,CAAC,QAAQ,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;AAIjD,eAAO,MAAM,QAAQ,qCAAqC,CAAC;AAC3D,eAAO,MAAM,YAAY,QAAkB,CAAC;AAC5C,eAAO,MAAM,QAAQ,QAAsB,CAAC;AAC5C,eAAO,MAAM,QAAQ,KAAK,CAAC;AAC3B,eAAO,MAAM,UAAU,KAAK,CAAC;AAC7B,eAAO,MAAM,QAAQ,QAAwB,CAAC;AAM9C,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAapD;AAED,wBAAgB,YAAY,IAAI,MAAM,CAOrC;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAkBnD;AAED,iDAAiD;AACjD,wBAAgB,gBAAgB,CAAC,UAAU,sBAAe,GAAG,IAAI,CAYhE"}
@@ -0,0 +1,65 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ // These values should NEVER change. If
3
+ // they do, we're no longer making ulids!
4
+ export const ENCODING = "0123456789ABCDEFGHJKMNPQRSTVWXYZ"; // Crockford's Base32
5
+ export const ENCODING_LEN = ENCODING.length;
6
+ export const TIME_MAX = Math.pow(2, 48) - 1;
7
+ export const TIME_LEN = 10;
8
+ export const RANDOM_LEN = 16;
9
+ export const ULID_LEN = TIME_LEN + RANDOM_LEN;
10
+ function replaceCharAt(str, index, char) {
11
+ return str.substring(0, index) + char + str.substring(index + 1);
12
+ }
13
+ export function encodeTime(timestamp) {
14
+ if (!Number.isInteger(timestamp) || timestamp < 0 || timestamp > TIME_MAX) {
15
+ throw new RangeError(`Time must be a positive integer less than ${TIME_MAX}`);
16
+ }
17
+ let str = "";
18
+ for (let len = TIME_LEN; len > 0; len--) {
19
+ const mod = timestamp % ENCODING_LEN;
20
+ str = ENCODING[mod] + str;
21
+ timestamp = Math.floor(timestamp / ENCODING_LEN);
22
+ }
23
+ return str;
24
+ }
25
+ export function encodeRandom() {
26
+ let str = "";
27
+ const bytes = crypto.getRandomValues(new Uint8Array(RANDOM_LEN));
28
+ for (const byte of bytes) {
29
+ str += ENCODING[byte % ENCODING_LEN];
30
+ }
31
+ return str;
32
+ }
33
+ export function incrementBase32(str) {
34
+ let index = str.length;
35
+ let char;
36
+ let charIndex;
37
+ const maxCharIndex = ENCODING_LEN - 1;
38
+ while (--index >= 0) {
39
+ char = str[index];
40
+ charIndex = ENCODING.indexOf(char);
41
+ if (charIndex === -1) {
42
+ throw new TypeError("Incorrectly encoded string");
43
+ }
44
+ if (charIndex === maxCharIndex) {
45
+ str = replaceCharAt(str, index, ENCODING[0]);
46
+ continue;
47
+ }
48
+ return replaceCharAt(str, index, ENCODING[charIndex + 1]);
49
+ }
50
+ throw new Error("Cannot increment this string");
51
+ }
52
+ /** Generates a monotonically increasing ULID. */
53
+ export function monotonicFactory(encodeRand = encodeRandom) {
54
+ let lastTime = 0;
55
+ let lastRandom;
56
+ return function ulid(seedTime = Date.now()) {
57
+ if (seedTime <= lastTime) {
58
+ const incrementedRandom = (lastRandom = incrementBase32(lastRandom));
59
+ return encodeTime(lastTime) + incrementedRandom;
60
+ }
61
+ lastTime = seedTime;
62
+ const newRandom = (lastRandom = encodeRand());
63
+ return encodeTime(seedTime) + newRandom;
64
+ };
65
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Extracts the number of milliseconds since the Unix epoch that had passed when
3
+ * the ULID was generated. If the ULID is malformed, an error will be thrown.
4
+ *
5
+ * @example Decode the time from a ULID
6
+ * ```ts
7
+ * import { decodeTime, ulid } from "@std/ulid";
8
+ * import { assertEquals } from "@std/assert";
9
+ *
10
+ * const timestamp = 150_000;
11
+ * const ulidString = ulid(timestamp);
12
+ *
13
+ * assertEquals(decodeTime(ulidString), timestamp);
14
+ * ```
15
+ *
16
+ * @param ulid The ULID to extract the timestamp from.
17
+ * @returns The number of milliseconds since the Unix epoch that had passed when the ULID was generated.
18
+ */
19
+ export declare function decodeTime(ulid: string): number;
20
+ //# sourceMappingURL=decode_time.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode_time.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/ulid/1.0.0/decode_time.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAqB/C"}
@@ -0,0 +1,43 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ // Copyright 2023 Yoshiya Hinosawa. All rights reserved. MIT license.
3
+ // Copyright 2017 Alizain Feerasta. All rights reserved. MIT license.
4
+ // This module is browser compatible.
5
+ import { ENCODING, ENCODING_LEN, TIME_LEN, TIME_MAX, ULID_LEN, } from "./_util.js";
6
+ /**
7
+ * Extracts the number of milliseconds since the Unix epoch that had passed when
8
+ * the ULID was generated. If the ULID is malformed, an error will be thrown.
9
+ *
10
+ * @example Decode the time from a ULID
11
+ * ```ts
12
+ * import { decodeTime, ulid } from "@std/ulid";
13
+ * import { assertEquals } from "@std/assert";
14
+ *
15
+ * const timestamp = 150_000;
16
+ * const ulidString = ulid(timestamp);
17
+ *
18
+ * assertEquals(decodeTime(ulidString), timestamp);
19
+ * ```
20
+ *
21
+ * @param ulid The ULID to extract the timestamp from.
22
+ * @returns The number of milliseconds since the Unix epoch that had passed when the ULID was generated.
23
+ */
24
+ export function decodeTime(ulid) {
25
+ if (ulid.length !== ULID_LEN) {
26
+ throw new Error(`ULID must be exactly ${ULID_LEN} characters long`);
27
+ }
28
+ const time = ulid
29
+ .substring(0, TIME_LEN)
30
+ .split("")
31
+ .reverse()
32
+ .reduce((carry, char, index) => {
33
+ const encodingIndex = ENCODING.indexOf(char);
34
+ if (encodingIndex === -1) {
35
+ throw new Error(`Invalid ULID character found: ${char}`);
36
+ }
37
+ return (carry += encodingIndex * Math.pow(ENCODING_LEN, index));
38
+ }, 0);
39
+ if (time > TIME_MAX) {
40
+ throw new RangeError(`ULID timestamp component exceeds maximum value of ${TIME_MAX}`);
41
+ }
42
+ return time;
43
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Utilities for generating and working with
3
+ * {@link https://github.com/ulid/spec | Universally Unique Lexicographically Sortable Identifiers (ULIDs)}.
4
+ *
5
+ * To generate a ULID use the {@linkcode ulid} function. This will generate a
6
+ * ULID based on the current time.
7
+ *
8
+ * ```ts no-assert
9
+ * import { ulid } from "@std/ulid";
10
+ *
11
+ * ulid(); // 01HYFKMDF3HVJ4J3JZW8KXPVTY
12
+ * ```
13
+ *
14
+ * {@linkcode ulid} does not guarantee that the ULIDs will be strictly
15
+ * increasing for the same current time. If you need to guarantee that the ULIDs
16
+ * will be strictly increasing, even for the same current time, use the
17
+ * {@linkcode monotonicUlid} function.
18
+ *
19
+ * ```ts no-assert
20
+ * import { monotonicUlid } from "@std/ulid";
21
+ *
22
+ * monotonicUlid(); // 01HYFKHG5F8RHM2PM3D7NSTDAS
23
+ * monotonicUlid(); // 01HYFKHG5F8RHM2PM3D7NSTDAT
24
+ * ```
25
+ *
26
+ * Because each ULID encodes the time it was generated, you can extract the
27
+ * timestamp from a ULID using the {@linkcode decodeTime} function.
28
+ *
29
+ * ```ts
30
+ * import { decodeTime, ulid } from "@std/ulid";
31
+ * import { assertEquals } from "@std/assert";
32
+ *
33
+ * const timestamp = 150_000;
34
+ * const ulidString = ulid(timestamp);
35
+ *
36
+ * assertEquals(decodeTime(ulidString), timestamp);
37
+ * ```
38
+ *
39
+ * @module
40
+ */
41
+ export * from "./decode_time.js";
42
+ export * from "./monotonic_ulid.js";
43
+ export * from "./ulid.js";
44
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/ulid/1.0.0/mod.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,WAAW,CAAC"}
@@ -0,0 +1,47 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ // Copyright 2023 Yoshiya Hinosawa. All rights reserved. MIT license.
3
+ // Copyright 2017 Alizain Feerasta. All rights reserved. MIT license.
4
+ // This module is browser compatible.
5
+ /**
6
+ * Utilities for generating and working with
7
+ * {@link https://github.com/ulid/spec | Universally Unique Lexicographically Sortable Identifiers (ULIDs)}.
8
+ *
9
+ * To generate a ULID use the {@linkcode ulid} function. This will generate a
10
+ * ULID based on the current time.
11
+ *
12
+ * ```ts no-assert
13
+ * import { ulid } from "@std/ulid";
14
+ *
15
+ * ulid(); // 01HYFKMDF3HVJ4J3JZW8KXPVTY
16
+ * ```
17
+ *
18
+ * {@linkcode ulid} does not guarantee that the ULIDs will be strictly
19
+ * increasing for the same current time. If you need to guarantee that the ULIDs
20
+ * will be strictly increasing, even for the same current time, use the
21
+ * {@linkcode monotonicUlid} function.
22
+ *
23
+ * ```ts no-assert
24
+ * import { monotonicUlid } from "@std/ulid";
25
+ *
26
+ * monotonicUlid(); // 01HYFKHG5F8RHM2PM3D7NSTDAS
27
+ * monotonicUlid(); // 01HYFKHG5F8RHM2PM3D7NSTDAT
28
+ * ```
29
+ *
30
+ * Because each ULID encodes the time it was generated, you can extract the
31
+ * timestamp from a ULID using the {@linkcode decodeTime} function.
32
+ *
33
+ * ```ts
34
+ * import { decodeTime, ulid } from "@std/ulid";
35
+ * import { assertEquals } from "@std/assert";
36
+ *
37
+ * const timestamp = 150_000;
38
+ * const ulidString = ulid(timestamp);
39
+ *
40
+ * assertEquals(decodeTime(ulidString), timestamp);
41
+ * ```
42
+ *
43
+ * @module
44
+ */
45
+ export * from "./decode_time.js";
46
+ export * from "./monotonic_ulid.js";
47
+ export * from "./ulid.js";
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Generate a ULID that monotonically increases even for the same millisecond,
3
+ * optionally passing the current time. If the current time is not passed, it
4
+ * will default to `Date.now()`.
5
+ *
6
+ * Unlike the {@linkcode ulid} function, this function is guaranteed to return
7
+ * strictly increasing ULIDs, even for the same seed time, but only if the seed
8
+ * time only ever increases. If the seed time ever goes backwards, the ULID will
9
+ * still be generated, but it will not be guaranteed to be monotonic with
10
+ * previous ULIDs for that same seed time.
11
+ *
12
+ * @example Generate a monotonic ULID
13
+ * ```ts no-assert
14
+ * import { monotonicUlid } from "@std/ulid";
15
+ *
16
+ * monotonicUlid(); // 01HYFKHG5F8RHM2PM3D7NSTDAS
17
+ * monotonicUlid(); // 01HYFKHG5F8RHM2PM3D7NSTDAT
18
+ * monotonicUlid(); // 01HYFKHHX8H4BRY8BYHAV1BZ2T
19
+ * ```
20
+ *
21
+ * @example Generate a monotonic ULID with a seed time
22
+ * ```ts no-assert
23
+ * import { monotonicUlid } from "@std/ulid";
24
+ *
25
+ * // Strict ordering for the same timestamp, by incrementing the least-significant random bit by 1
26
+ * monotonicUlid(150000); // 0000004JFHJJ2Z7X64FN2B4F1Q
27
+ * monotonicUlid(150000); // 0000004JFHJJ2Z7X64FN2B4F1R
28
+ * monotonicUlid(150000); // 0000004JFHJJ2Z7X64FN2B4F1S
29
+ * monotonicUlid(150000); // 0000004JFHJJ2Z7X64FN2B4F1T
30
+ * monotonicUlid(150000); // 0000004JFHJJ2Z7X64FN2B4F1U
31
+ *
32
+ * // A different timestamp will reset the random bits
33
+ * monotonicUlid(150001); // 0000004JFHJJ2Z7X64FN2B4F1P
34
+ *
35
+ * // A previous seed time will not guarantee ordering, and may result in a
36
+ * // ULID lower than one with the same seed time generated previously
37
+ * monotonicUlid(150000); // 0000004JFJ7XF6D76ES95SZR0X
38
+ * ```
39
+ *
40
+ * @param seedTime The time to base the ULID on, in milliseconds since the Unix epoch. Defaults to `Date.now()`.
41
+ * @returns A ULID that is guaranteed to be strictly increasing for the same seed time.
42
+ */
43
+ export declare function monotonicUlid(seedTime?: number): string;
44
+ //# sourceMappingURL=monotonic_ulid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monotonic_ulid.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/ulid/1.0.0/monotonic_ulid.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,aAAa,CAAC,QAAQ,GAAE,MAAmB,GAAG,MAAM,CAEnE"}
@@ -0,0 +1,51 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ // Copyright 2023 Yoshiya Hinosawa. All rights reserved. MIT license.
3
+ // Copyright 2017 Alizain Feerasta. All rights reserved. MIT license.
4
+ // This module is browser compatible.
5
+ import { monotonicFactory } from "./_util.js";
6
+ const defaultMonotonicUlid = monotonicFactory();
7
+ /**
8
+ * Generate a ULID that monotonically increases even for the same millisecond,
9
+ * optionally passing the current time. If the current time is not passed, it
10
+ * will default to `Date.now()`.
11
+ *
12
+ * Unlike the {@linkcode ulid} function, this function is guaranteed to return
13
+ * strictly increasing ULIDs, even for the same seed time, but only if the seed
14
+ * time only ever increases. If the seed time ever goes backwards, the ULID will
15
+ * still be generated, but it will not be guaranteed to be monotonic with
16
+ * previous ULIDs for that same seed time.
17
+ *
18
+ * @example Generate a monotonic ULID
19
+ * ```ts no-assert
20
+ * import { monotonicUlid } from "@std/ulid";
21
+ *
22
+ * monotonicUlid(); // 01HYFKHG5F8RHM2PM3D7NSTDAS
23
+ * monotonicUlid(); // 01HYFKHG5F8RHM2PM3D7NSTDAT
24
+ * monotonicUlid(); // 01HYFKHHX8H4BRY8BYHAV1BZ2T
25
+ * ```
26
+ *
27
+ * @example Generate a monotonic ULID with a seed time
28
+ * ```ts no-assert
29
+ * import { monotonicUlid } from "@std/ulid";
30
+ *
31
+ * // Strict ordering for the same timestamp, by incrementing the least-significant random bit by 1
32
+ * monotonicUlid(150000); // 0000004JFHJJ2Z7X64FN2B4F1Q
33
+ * monotonicUlid(150000); // 0000004JFHJJ2Z7X64FN2B4F1R
34
+ * monotonicUlid(150000); // 0000004JFHJJ2Z7X64FN2B4F1S
35
+ * monotonicUlid(150000); // 0000004JFHJJ2Z7X64FN2B4F1T
36
+ * monotonicUlid(150000); // 0000004JFHJJ2Z7X64FN2B4F1U
37
+ *
38
+ * // A different timestamp will reset the random bits
39
+ * monotonicUlid(150001); // 0000004JFHJJ2Z7X64FN2B4F1P
40
+ *
41
+ * // A previous seed time will not guarantee ordering, and may result in a
42
+ * // ULID lower than one with the same seed time generated previously
43
+ * monotonicUlid(150000); // 0000004JFJ7XF6D76ES95SZR0X
44
+ * ```
45
+ *
46
+ * @param seedTime The time to base the ULID on, in milliseconds since the Unix epoch. Defaults to `Date.now()`.
47
+ * @returns A ULID that is guaranteed to be strictly increasing for the same seed time.
48
+ */
49
+ export function monotonicUlid(seedTime = Date.now()) {
50
+ return defaultMonotonicUlid(seedTime);
51
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Generate a ULID, optionally based on a given timestamp. If the timestamp is
3
+ * not passed, it will default to `Date.now()`.
4
+ *
5
+ * Multiple calls to this function with the same seed time will not guarantee
6
+ * that the ULIDs will be strictly increasing, even if the seed time is the
7
+ * same. For that, use the {@linkcode monotonicUlid} function.
8
+ *
9
+ * @example Generate a ULID
10
+ * ```ts no-assert
11
+ * import { ulid } from "@std/ulid";
12
+ *
13
+ * ulid(); // 01HYFKMDF3HVJ4J3JZW8KXPVTY
14
+ * ulid(); // 01HYFKMDF3D2P7G502B9Z2VKV0
15
+ * ulid(); // 01HYFKMDZQ7JD17CRKDXQSZ3Z4
16
+ * ```
17
+ *
18
+ * @example Generate a ULID with a seed time
19
+ * ```ts no-assert
20
+ * import { ulid } from "@std/ulid";
21
+ *
22
+ * ulid(150000); // 0000004JFG3EKDRE04TVVDJW7K
23
+ * ulid(150000); // 0000004JFGN0KHBH0447AK895X
24
+ * ulid(150000); // 0000004JFGMRDH0PN7SM8BZN06
25
+ * ```
26
+ *
27
+ * @param seedTime The time to base the ULID on, in milliseconds since the Unix epoch. Defaults to `Date.now()`.
28
+ * @returns A ULID.
29
+ */
30
+ export declare function ulid(seedTime?: number): string;
31
+ //# sourceMappingURL=ulid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ulid.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/ulid/1.0.0/ulid.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,IAAI,CAAC,QAAQ,GAAE,MAAmB,GAAG,MAAM,CAE1D"}
@@ -0,0 +1,37 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ // Copyright 2023 Yoshiya Hinosawa. All rights reserved. MIT license.
3
+ // Copyright 2017 Alizain Feerasta. All rights reserved. MIT license.
4
+ // This module is browser compatible.
5
+ import { encodeRandom, encodeTime } from "./_util.js";
6
+ /**
7
+ * Generate a ULID, optionally based on a given timestamp. If the timestamp is
8
+ * not passed, it will default to `Date.now()`.
9
+ *
10
+ * Multiple calls to this function with the same seed time will not guarantee
11
+ * that the ULIDs will be strictly increasing, even if the seed time is the
12
+ * same. For that, use the {@linkcode monotonicUlid} function.
13
+ *
14
+ * @example Generate a ULID
15
+ * ```ts no-assert
16
+ * import { ulid } from "@std/ulid";
17
+ *
18
+ * ulid(); // 01HYFKMDF3HVJ4J3JZW8KXPVTY
19
+ * ulid(); // 01HYFKMDF3D2P7G502B9Z2VKV0
20
+ * ulid(); // 01HYFKMDZQ7JD17CRKDXQSZ3Z4
21
+ * ```
22
+ *
23
+ * @example Generate a ULID with a seed time
24
+ * ```ts no-assert
25
+ * import { ulid } from "@std/ulid";
26
+ *
27
+ * ulid(150000); // 0000004JFG3EKDRE04TVVDJW7K
28
+ * ulid(150000); // 0000004JFGN0KHBH0447AK895X
29
+ * ulid(150000); // 0000004JFGMRDH0PN7SM8BZN06
30
+ * ```
31
+ *
32
+ * @param seedTime The time to base the ULID on, in milliseconds since the Unix epoch. Defaults to `Date.now()`.
33
+ * @returns A ULID.
34
+ */
35
+ export function ulid(seedTime = Date.now()) {
36
+ return encodeTime(seedTime) + encodeRandom();
37
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/src/config.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,kBAAkB,CAAC;AAkB1E,KAAK,gBAAgB,GAAG;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAAC;AAEnD,KAAK,mBAAmB,GACpB,uBAAuB,GACvB,yBAAyB,GACzB,kBAAkB,GAClB,gBAAgB,CAAC;AAErB,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;gBAGjC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,mBAAmB,CAAA;KAAE;CAc1D;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAAC;IACxC,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,CAAC;CAC1C;AAED,KAAK,qBAAqB,GAAG,MAAM,qBAAqB,CAAC;AAwLzD,eAAO,MAAM,kCAAkC,GAC7C,SAAS,qBAAqB,KAC7B,IAEF,CAAC;AAEF,eAAO,MAAM,oCAAoC,QAAO,IAEvD,CAAC;AA2EF,wBAAgB,UAAU,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,cAAc,CAiB7D"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/src/config.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,kBAAkB,CAAC;AAkB1E,KAAK,gBAAgB,GAAG;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAAC;AAEnD,KAAK,mBAAmB,GACpB,uBAAuB,GACvB,yBAAyB,GACzB,kBAAkB,GAClB,gBAAgB,CAAC;AAErB,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;gBAGjC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,mBAAmB,CAAA;KAAE;CAiB1D;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAAC;IACxC,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,CAAC;CAC1C;AAED,KAAK,qBAAqB,GAAG,MAAM,qBAAqB,CAAC;AAuPzD,eAAO,MAAM,kCAAkC,GAC7C,SAAS,qBAAqB,KAC7B,IAEF,CAAC;AAEF,eAAO,MAAM,oCAAoC,QAAO,IAEvD,CAAC;AA6EF,wBAAgB,UAAU,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,cAAc,CAgB7D"}
package/esm/src/config.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import os from "node:os";
2
2
  import { createRequire } from "node:module";
3
3
  import { join } from "node:path";
4
+ import { redactEndpointUserInfo } from "./services/endpoint-redaction.js";
4
5
  import { logger } from "./services/logger.js";
5
6
  const DEFAULT_CONFIG = {
6
7
  redis: {
@@ -29,6 +30,9 @@ export class ConfigLoadError extends Error {
29
30
  this.name = "ConfigLoadError";
30
31
  this.code = options.code;
31
32
  if (options.cause !== undefined) {
33
+ // dnt's Node-side type check still narrows Error to the legacy
34
+ // single-argument constructor here, so preserve standard cause semantics
35
+ // manually while keeping the generated build green.
32
36
  Object.defineProperty(this, "cause", {
33
37
  value: options.cause,
34
38
  writable: true,
@@ -77,30 +81,68 @@ const normalizeConfig = (value) => {
77
81
  const isPositiveInteger = (value) => typeof value === "number" && Number.isInteger(value) && value > 0;
78
82
  const isUnitInterval = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 &&
79
83
  value <= 1;
80
- const isValidUrlString = (value) => {
84
+ const parseUrlString = (value) => {
81
85
  if (!value)
82
- return false;
86
+ return null;
83
87
  try {
84
- new URL(value);
85
- return true;
88
+ return new URL(value);
86
89
  }
87
90
  catch {
88
- return false;
91
+ return null;
89
92
  }
90
93
  };
91
- const assertExplicitUrl = (value, fieldName) => {
94
+ const URL_SCHEME_PREFIX = /^[A-Za-z][A-Za-z\d+\-.]*:\/\//;
95
+ const coerceConfiguredUrl = (value, fieldName, options) => {
92
96
  if (value === undefined)
93
- return;
94
- if (isValidUrlString(value))
95
- return;
96
- throw new ConfigLoadError(`Invalid Graphiti config value for ${fieldName}: expected a valid URL, received ${JSON.stringify(value)}`, { code: "config-invalid" });
97
+ return undefined;
98
+ const hasExplicitScheme = URL_SCHEME_PREFIX.test(value);
99
+ const candidate = hasExplicitScheme
100
+ ? value
101
+ : `${options.defaultScheme}://${value.replace(/^\/\//, "")}`;
102
+ const url = parseUrlString(candidate);
103
+ if (!url) {
104
+ throw new ConfigLoadError(`Invalid config value for ${fieldName}: expected a valid URL, received ${JSON.stringify(redactEndpointUserInfo(value))}`, { code: "config-invalid" });
105
+ }
106
+ if (!options.allowedSchemes ||
107
+ options.allowedSchemes.includes(url.protocol.slice(0, -1))) {
108
+ if (!hasExplicitScheme && options.defaultPort && !url.port) {
109
+ url.port = options.defaultPort;
110
+ }
111
+ return url.toString();
112
+ }
113
+ throw new ConfigLoadError(`Invalid config value for ${fieldName}: expected URL scheme ${options.allowedSchemes.map((scheme) => JSON.stringify(scheme)).join(" or ")}, received ${JSON.stringify(redactEndpointUserInfo(value))}`, { code: "config-invalid" });
97
114
  };
98
- const validateExplicitConfig = (value) => {
115
+ const normalizeConfiguredEndpoints = (value) => {
99
116
  if (!value)
100
- return;
101
- assertExplicitUrl(value.endpoint, "endpoint");
102
- assertExplicitUrl(value.graphiti?.endpoint, "graphiti.endpoint");
103
- assertExplicitUrl(value.redis?.endpoint, "redis.endpoint");
117
+ return value;
118
+ return {
119
+ ...value,
120
+ endpoint: coerceConfiguredUrl(value.endpoint, "endpoint", {
121
+ allowedSchemes: ["http", "https"],
122
+ defaultScheme: "http",
123
+ defaultPort: "8000",
124
+ }),
125
+ graphiti: value.graphiti
126
+ ? {
127
+ ...value.graphiti,
128
+ endpoint: coerceConfiguredUrl(value.graphiti.endpoint, "graphiti.endpoint", {
129
+ allowedSchemes: ["http", "https"],
130
+ defaultScheme: "http",
131
+ defaultPort: "8000",
132
+ }),
133
+ }
134
+ : value.graphiti,
135
+ redis: value.redis
136
+ ? {
137
+ ...value.redis,
138
+ endpoint: coerceConfiguredUrl(value.redis.endpoint, "redis.endpoint", {
139
+ allowedSchemes: ["redis", "rediss"],
140
+ defaultScheme: "redis",
141
+ defaultPort: "6379",
142
+ }),
143
+ }
144
+ : value.redis,
145
+ };
104
146
  };
105
147
  const resolveNumber = (...candidates) => candidates.find((value) => value !== undefined);
106
148
  const resolveConfig = (value) => {
@@ -113,9 +155,8 @@ const resolveConfig = (value) => {
113
155
  const resolvedCacheTtlSeconds = resolveNumber(raw.redis?.cacheTtlSeconds);
114
156
  const resolvedDrainRetryMax = resolveNumber(raw.redis?.drainRetryMax);
115
157
  const requestedGraphitiEndpoint = raw.graphiti?.endpoint ?? raw.endpoint;
116
- const resolvedGraphitiEndpoint = isValidUrlString(requestedGraphitiEndpoint)
117
- ? requestedGraphitiEndpoint
118
- : DEFAULT_CONFIG.graphiti.endpoint;
158
+ const resolvedGraphitiEndpoint = requestedGraphitiEndpoint ??
159
+ DEFAULT_CONFIG.graphiti.endpoint;
119
160
  const resolvedGroupIdPrefix = raw.graphiti?.groupIdPrefix ??
120
161
  raw.groupIdPrefix ??
121
162
  DEFAULT_CONFIG.graphiti.groupIdPrefix;
@@ -183,8 +224,9 @@ const getConfigExplorerAdapter = () => {
183
224
  const loadConfigFile = (adapter, filePath) => {
184
225
  try {
185
226
  const loaded = adapter?.load(filePath);
186
- const normalized = loaded ? normalizeConfig(loaded.config) : null;
187
- validateExplicitConfig(normalized);
227
+ const normalized = loaded
228
+ ? normalizeConfiguredEndpoints(normalizeConfig(loaded.config))
229
+ : null;
188
230
  return normalized;
189
231
  }
190
232
  catch (err) {
@@ -204,8 +246,9 @@ const getHomeDir = () => {
204
246
  const searchConfig = (adapter, directory) => {
205
247
  try {
206
248
  const loaded = adapter.search(directory);
207
- const normalized = loaded ? normalizeConfig(loaded.config) : null;
208
- validateExplicitConfig(normalized);
249
+ const normalized = loaded
250
+ ? normalizeConfiguredEndpoints(normalizeConfig(loaded.config))
251
+ : null;
209
252
  return normalized;
210
253
  }
211
254
  catch (err) {
@@ -232,7 +275,6 @@ export function loadConfig(directory) {
232
275
  const adapter = getConfigExplorerAdapter();
233
276
  const loaded = searchConfig(adapter, directory);
234
277
  const resolved = loaded ?? loadLegacyConfig(adapter);
235
- validateExplicitConfig(resolved);
236
278
  return resolveConfig(resolved);
237
279
  }
238
280
  catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/src/handlers/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAQjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpD,KAAK,qBAAqB,GAAG,WAAW,CACtC,KAAK,CAAC,sCAAsC,CAAC,CAC9C,CAAC;AAIF,MAAM,WAAW,mBAAmB;IAClC,cAAc,EAAE,cAAc,CAAC;CAChC;AAuCD,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,mBAAmB,GACxB,qBAAqB,CAmEvB"}
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/src/handlers/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAQjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpD,KAAK,qBAAqB,GAAG,WAAW,CACtC,KAAK,CAAC,sCAAsC,CAAC,CAC9C,CAAC;AAIF,MAAM,WAAW,mBAAmB;IAClC,cAAc,EAAE,cAAc,CAAC;CAChC;AAyFD,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,mBAAmB,GACxB,qBAAqB,CAmEvB"}