@nebula-ai/sdk 1.3.0 → 1.4.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/LICENSE +18 -4
- package/README.md +42 -346
- package/dist/index.cjs +1268 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2824 -0
- package/dist/index.d.ts +2824 -0
- package/dist/index.js +1244 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -141
- package/CHANGELOG.md +0 -35
- package/api-promise.d.mts +0 -2
- package/api-promise.d.mts.map +0 -1
- package/api-promise.d.ts +0 -2
- package/api-promise.d.ts.map +0 -1
- package/api-promise.js +0 -6
- package/api-promise.js.map +0 -1
- package/api-promise.mjs +0 -2
- package/api-promise.mjs.map +0 -1
- package/client.d.mts +0 -205
- package/client.d.mts.map +0 -1
- package/client.d.ts +0 -205
- package/client.d.ts.map +0 -1
- package/client.js +0 -505
- package/client.js.map +0 -1
- package/client.mjs +0 -501
- package/client.mjs.map +0 -1
- package/core/api-promise.d.mts +0 -46
- package/core/api-promise.d.mts.map +0 -1
- package/core/api-promise.d.ts +0 -46
- package/core/api-promise.d.ts.map +0 -1
- package/core/api-promise.js +0 -74
- package/core/api-promise.js.map +0 -1
- package/core/api-promise.mjs +0 -70
- package/core/api-promise.mjs.map +0 -1
- package/core/error.d.mts +0 -46
- package/core/error.d.mts.map +0 -1
- package/core/error.d.ts +0 -46
- package/core/error.d.ts.map +0 -1
- package/core/error.js +0 -113
- package/core/error.js.map +0 -1
- package/core/error.mjs +0 -97
- package/core/error.mjs.map +0 -1
- package/core/resource.d.mts +0 -6
- package/core/resource.d.mts.map +0 -1
- package/core/resource.d.ts +0 -6
- package/core/resource.d.ts.map +0 -1
- package/core/resource.js +0 -11
- package/core/resource.js.map +0 -1
- package/core/resource.mjs +0 -7
- package/core/resource.mjs.map +0 -1
- package/core/uploads.d.mts +0 -3
- package/core/uploads.d.mts.map +0 -1
- package/core/uploads.d.ts +0 -3
- package/core/uploads.d.ts.map +0 -1
- package/core/uploads.js +0 -6
- package/core/uploads.js.map +0 -1
- package/core/uploads.mjs +0 -2
- package/core/uploads.mjs.map +0 -1
- package/error.d.mts +0 -2
- package/error.d.mts.map +0 -1
- package/error.d.ts +0 -2
- package/error.d.ts.map +0 -1
- package/error.js +0 -6
- package/error.js.map +0 -1
- package/error.mjs +0 -2
- package/error.mjs.map +0 -1
- package/index.d.mts +0 -13
- package/index.d.mts.map +0 -1
- package/index.d.ts +0 -13
- package/index.d.ts.map +0 -1
- package/index.js +0 -43
- package/index.js.map +0 -1
- package/index.mjs +0 -13
- package/index.mjs.map +0 -1
- package/internal/builtin-types.d.mts +0 -73
- package/internal/builtin-types.d.mts.map +0 -1
- package/internal/builtin-types.d.ts +0 -73
- package/internal/builtin-types.d.ts.map +0 -1
- package/internal/builtin-types.js +0 -4
- package/internal/builtin-types.js.map +0 -1
- package/internal/builtin-types.mjs +0 -3
- package/internal/builtin-types.mjs.map +0 -1
- package/internal/detect-platform.d.mts +0 -15
- package/internal/detect-platform.d.mts.map +0 -1
- package/internal/detect-platform.d.ts +0 -15
- package/internal/detect-platform.d.ts.map +0 -1
- package/internal/detect-platform.js +0 -162
- package/internal/detect-platform.js.map +0 -1
- package/internal/detect-platform.mjs +0 -157
- package/internal/detect-platform.mjs.map +0 -1
- package/internal/errors.d.mts +0 -3
- package/internal/errors.d.mts.map +0 -1
- package/internal/errors.d.ts +0 -3
- package/internal/errors.d.ts.map +0 -1
- package/internal/errors.js +0 -41
- package/internal/errors.js.map +0 -1
- package/internal/errors.mjs +0 -36
- package/internal/errors.mjs.map +0 -1
- package/internal/headers.d.mts +0 -20
- package/internal/headers.d.mts.map +0 -1
- package/internal/headers.d.ts +0 -20
- package/internal/headers.d.ts.map +0 -1
- package/internal/headers.js +0 -79
- package/internal/headers.js.map +0 -1
- package/internal/headers.mjs +0 -74
- package/internal/headers.mjs.map +0 -1
- package/internal/parse.d.mts +0 -12
- package/internal/parse.d.mts.map +0 -1
- package/internal/parse.d.ts +0 -12
- package/internal/parse.d.ts.map +0 -1
- package/internal/parse.js +0 -40
- package/internal/parse.js.map +0 -1
- package/internal/parse.mjs +0 -37
- package/internal/parse.mjs.map +0 -1
- package/internal/qs/formats.d.mts +0 -7
- package/internal/qs/formats.d.mts.map +0 -1
- package/internal/qs/formats.d.ts +0 -7
- package/internal/qs/formats.d.ts.map +0 -1
- package/internal/qs/formats.js +0 -13
- package/internal/qs/formats.js.map +0 -1
- package/internal/qs/formats.mjs +0 -9
- package/internal/qs/formats.mjs.map +0 -1
- package/internal/qs/index.d.mts +0 -10
- package/internal/qs/index.d.mts.map +0 -1
- package/internal/qs/index.d.ts +0 -10
- package/internal/qs/index.d.ts.map +0 -1
- package/internal/qs/index.js +0 -14
- package/internal/qs/index.js.map +0 -1
- package/internal/qs/index.mjs +0 -10
- package/internal/qs/index.mjs.map +0 -1
- package/internal/qs/stringify.d.mts +0 -3
- package/internal/qs/stringify.d.mts.map +0 -1
- package/internal/qs/stringify.d.ts +0 -3
- package/internal/qs/stringify.d.ts.map +0 -1
- package/internal/qs/stringify.js +0 -277
- package/internal/qs/stringify.js.map +0 -1
- package/internal/qs/stringify.mjs +0 -274
- package/internal/qs/stringify.mjs.map +0 -1
- package/internal/qs/types.d.mts +0 -57
- package/internal/qs/types.d.mts.map +0 -1
- package/internal/qs/types.d.ts +0 -57
- package/internal/qs/types.d.ts.map +0 -1
- package/internal/qs/types.js +0 -3
- package/internal/qs/types.js.map +0 -1
- package/internal/qs/types.mjs +0 -2
- package/internal/qs/types.mjs.map +0 -1
- package/internal/qs/utils.d.mts +0 -15
- package/internal/qs/utils.d.mts.map +0 -1
- package/internal/qs/utils.d.ts +0 -15
- package/internal/qs/utils.d.ts.map +0 -1
- package/internal/qs/utils.js +0 -230
- package/internal/qs/utils.js.map +0 -1
- package/internal/qs/utils.mjs +0 -217
- package/internal/qs/utils.mjs.map +0 -1
- package/internal/request-options.d.mts +0 -79
- package/internal/request-options.d.mts.map +0 -1
- package/internal/request-options.d.ts +0 -79
- package/internal/request-options.d.ts.map +0 -1
- package/internal/request-options.js +0 -14
- package/internal/request-options.js.map +0 -1
- package/internal/request-options.mjs +0 -10
- package/internal/request-options.mjs.map +0 -1
- package/internal/shim-types.d.mts +0 -17
- package/internal/shim-types.d.mts.map +0 -1
- package/internal/shim-types.d.ts +0 -17
- package/internal/shim-types.d.ts.map +0 -1
- package/internal/shim-types.js +0 -4
- package/internal/shim-types.js.map +0 -1
- package/internal/shim-types.mjs +0 -3
- package/internal/shim-types.mjs.map +0 -1
- package/internal/shims.d.mts +0 -20
- package/internal/shims.d.mts.map +0 -1
- package/internal/shims.d.ts +0 -20
- package/internal/shims.d.ts.map +0 -1
- package/internal/shims.js +0 -92
- package/internal/shims.js.map +0 -1
- package/internal/shims.mjs +0 -85
- package/internal/shims.mjs.map +0 -1
- package/internal/to-file.d.mts +0 -45
- package/internal/to-file.d.mts.map +0 -1
- package/internal/to-file.d.ts +0 -45
- package/internal/to-file.d.ts.map +0 -1
- package/internal/to-file.js +0 -91
- package/internal/to-file.js.map +0 -1
- package/internal/to-file.mjs +0 -88
- package/internal/to-file.mjs.map +0 -1
- package/internal/tslib.js +0 -81
- package/internal/tslib.mjs +0 -17
- package/internal/types.d.mts +0 -69
- package/internal/types.d.mts.map +0 -1
- package/internal/types.d.ts +0 -69
- package/internal/types.d.ts.map +0 -1
- package/internal/types.js +0 -4
- package/internal/types.js.map +0 -1
- package/internal/types.mjs +0 -3
- package/internal/types.mjs.map +0 -1
- package/internal/uploads.d.mts +0 -42
- package/internal/uploads.d.mts.map +0 -1
- package/internal/uploads.d.ts +0 -42
- package/internal/uploads.d.ts.map +0 -1
- package/internal/uploads.js +0 -141
- package/internal/uploads.js.map +0 -1
- package/internal/uploads.mjs +0 -131
- package/internal/uploads.mjs.map +0 -1
- package/internal/utils/base64.d.mts +0 -3
- package/internal/utils/base64.d.mts.map +0 -1
- package/internal/utils/base64.d.ts +0 -3
- package/internal/utils/base64.d.ts.map +0 -1
- package/internal/utils/base64.js +0 -38
- package/internal/utils/base64.js.map +0 -1
- package/internal/utils/base64.mjs +0 -33
- package/internal/utils/base64.mjs.map +0 -1
- package/internal/utils/bytes.d.mts +0 -4
- package/internal/utils/bytes.d.mts.map +0 -1
- package/internal/utils/bytes.d.ts +0 -4
- package/internal/utils/bytes.d.ts.map +0 -1
- package/internal/utils/bytes.js +0 -31
- package/internal/utils/bytes.js.map +0 -1
- package/internal/utils/bytes.mjs +0 -26
- package/internal/utils/bytes.mjs.map +0 -1
- package/internal/utils/env.d.mts +0 -9
- package/internal/utils/env.d.mts.map +0 -1
- package/internal/utils/env.d.ts +0 -9
- package/internal/utils/env.d.ts.map +0 -1
- package/internal/utils/env.js +0 -22
- package/internal/utils/env.js.map +0 -1
- package/internal/utils/env.mjs +0 -18
- package/internal/utils/env.mjs.map +0 -1
- package/internal/utils/log.d.mts +0 -37
- package/internal/utils/log.d.mts.map +0 -1
- package/internal/utils/log.d.ts +0 -37
- package/internal/utils/log.d.ts.map +0 -1
- package/internal/utils/log.js +0 -86
- package/internal/utils/log.js.map +0 -1
- package/internal/utils/log.mjs +0 -80
- package/internal/utils/log.mjs.map +0 -1
- package/internal/utils/path.d.mts +0 -15
- package/internal/utils/path.d.mts.map +0 -1
- package/internal/utils/path.d.ts +0 -15
- package/internal/utils/path.d.ts.map +0 -1
- package/internal/utils/path.js +0 -79
- package/internal/utils/path.js.map +0 -1
- package/internal/utils/path.mjs +0 -74
- package/internal/utils/path.mjs.map +0 -1
- package/internal/utils/query.d.mts +0 -2
- package/internal/utils/query.d.mts.map +0 -1
- package/internal/utils/query.d.ts +0 -2
- package/internal/utils/query.d.ts.map +0 -1
- package/internal/utils/query.js +0 -10
- package/internal/utils/query.js.map +0 -1
- package/internal/utils/query.mjs +0 -6
- package/internal/utils/query.mjs.map +0 -1
- package/internal/utils/sleep.d.mts +0 -2
- package/internal/utils/sleep.d.mts.map +0 -1
- package/internal/utils/sleep.d.ts +0 -2
- package/internal/utils/sleep.d.ts.map +0 -1
- package/internal/utils/sleep.js +0 -7
- package/internal/utils/sleep.js.map +0 -1
- package/internal/utils/sleep.mjs +0 -3
- package/internal/utils/sleep.mjs.map +0 -1
- package/internal/utils/uuid.d.mts +0 -5
- package/internal/utils/uuid.d.mts.map +0 -1
- package/internal/utils/uuid.d.ts +0 -5
- package/internal/utils/uuid.d.ts.map +0 -1
- package/internal/utils/uuid.js +0 -19
- package/internal/utils/uuid.js.map +0 -1
- package/internal/utils/uuid.mjs +0 -15
- package/internal/utils/uuid.mjs.map +0 -1
- package/internal/utils/values.d.mts +0 -18
- package/internal/utils/values.d.mts.map +0 -1
- package/internal/utils/values.d.ts +0 -18
- package/internal/utils/values.d.ts.map +0 -1
- package/internal/utils/values.js +0 -112
- package/internal/utils/values.js.map +0 -1
- package/internal/utils/values.mjs +0 -94
- package/internal/utils/values.mjs.map +0 -1
- package/internal/utils.d.mts +0 -8
- package/internal/utils.d.mts.map +0 -1
- package/internal/utils.d.ts +0 -8
- package/internal/utils.d.ts.map +0 -1
- package/internal/utils.js +0 -12
- package/internal/utils.js.map +0 -1
- package/internal/utils.mjs +0 -9
- package/internal/utils.mjs.map +0 -1
- package/lib/dx.d.mts +0 -96
- package/lib/dx.d.mts.map +0 -1
- package/lib/dx.d.ts +0 -96
- package/lib/dx.d.ts.map +0 -1
- package/lib/dx.js +0 -239
- package/lib/dx.js.map +0 -1
- package/lib/dx.mjs +0 -235
- package/lib/dx.mjs.map +0 -1
- package/resource.d.mts +0 -2
- package/resource.d.mts.map +0 -1
- package/resource.d.ts +0 -2
- package/resource.d.ts.map +0 -1
- package/resource.js +0 -6
- package/resource.js.map +0 -1
- package/resource.mjs +0 -2
- package/resource.mjs.map +0 -1
- package/resources/collections.d.mts +0 -289
- package/resources/collections.d.mts.map +0 -1
- package/resources/collections.d.ts +0 -289
- package/resources/collections.d.ts.map +0 -1
- package/resources/collections.js +0 -72
- package/resources/collections.js.map +0 -1
- package/resources/collections.mjs +0 -68
- package/resources/collections.mjs.map +0 -1
- package/resources/connectors.d.mts +0 -148
- package/resources/connectors.d.mts.map +0 -1
- package/resources/connectors.d.ts +0 -148
- package/resources/connectors.d.ts.map +0 -1
- package/resources/connectors.js +0 -50
- package/resources/connectors.js.map +0 -1
- package/resources/connectors.mjs +0 -46
- package/resources/connectors.mjs.map +0 -1
- package/resources/index.d.mts +0 -6
- package/resources/index.d.mts.map +0 -1
- package/resources/index.d.ts +0 -6
- package/resources/index.d.ts.map +0 -1
- package/resources/index.js +0 -13
- package/resources/index.js.map +0 -1
- package/resources/index.mjs +0 -6
- package/resources/index.mjs.map +0 -1
- package/resources/memories.d.mts +0 -1737
- package/resources/memories.d.mts.map +0 -1
- package/resources/memories.d.ts +0 -1737
- package/resources/memories.d.ts.map +0 -1
- package/resources/memories.js +0 -157
- package/resources/memories.js.map +0 -1
- package/resources/memories.mjs +0 -153
- package/resources/memories.mjs.map +0 -1
- package/resources/snapshots.d.mts +0 -281
- package/resources/snapshots.d.mts.map +0 -1
- package/resources/snapshots.d.ts +0 -281
- package/resources/snapshots.d.ts.map +0 -1
- package/resources/snapshots.js +0 -22
- package/resources/snapshots.js.map +0 -1
- package/resources/snapshots.mjs +0 -18
- package/resources/snapshots.mjs.map +0 -1
- package/resources/top-level.d.mts +0 -14
- package/resources/top-level.d.mts.map +0 -1
- package/resources/top-level.d.ts +0 -14
- package/resources/top-level.d.ts.map +0 -1
- package/resources/top-level.js +0 -4
- package/resources/top-level.js.map +0 -1
- package/resources/top-level.mjs +0 -3
- package/resources/top-level.mjs.map +0 -1
- package/resources.d.mts +0 -2
- package/resources.d.mts.map +0 -1
- package/resources.d.ts +0 -2
- package/resources.d.ts.map +0 -1
- package/resources.js +0 -5
- package/resources.js.map +0 -1
- package/resources.mjs +0 -2
- package/resources.mjs.map +0 -1
- package/src/api-promise.ts +0 -2
- package/src/client.ts +0 -892
- package/src/core/README.md +0 -3
- package/src/core/api-promise.ts +0 -92
- package/src/core/error.ts +0 -130
- package/src/core/resource.ts +0 -11
- package/src/core/uploads.ts +0 -2
- package/src/error.ts +0 -2
- package/src/index.ts +0 -36
- package/src/internal/README.md +0 -3
- package/src/internal/builtin-types.ts +0 -93
- package/src/internal/detect-platform.ts +0 -196
- package/src/internal/errors.ts +0 -33
- package/src/internal/headers.ts +0 -97
- package/src/internal/parse.ts +0 -56
- package/src/internal/qs/LICENSE.md +0 -13
- package/src/internal/qs/README.md +0 -3
- package/src/internal/qs/formats.ts +0 -10
- package/src/internal/qs/index.ts +0 -13
- package/src/internal/qs/stringify.ts +0 -385
- package/src/internal/qs/types.ts +0 -71
- package/src/internal/qs/utils.ts +0 -265
- package/src/internal/request-options.ts +0 -93
- package/src/internal/shim-types.ts +0 -26
- package/src/internal/shims.ts +0 -107
- package/src/internal/to-file.ts +0 -154
- package/src/internal/types.ts +0 -95
- package/src/internal/uploads.ts +0 -187
- package/src/internal/utils/base64.ts +0 -40
- package/src/internal/utils/bytes.ts +0 -32
- package/src/internal/utils/env.ts +0 -18
- package/src/internal/utils/log.ts +0 -127
- package/src/internal/utils/path.ts +0 -88
- package/src/internal/utils/query.ts +0 -7
- package/src/internal/utils/sleep.ts +0 -3
- package/src/internal/utils/uuid.ts +0 -17
- package/src/internal/utils/values.ts +0 -105
- package/src/internal/utils.ts +0 -9
- package/src/lib/.keep +0 -4
- package/src/lib/dx.ts +0 -459
- package/src/resource.ts +0 -2
- package/src/resources/collections.ts +0 -474
- package/src/resources/connectors.ts +0 -236
- package/src/resources/index.ts +0 -56
- package/src/resources/memories.ts +0 -2409
- package/src/resources/snapshots.ts +0 -387
- package/src/resources/top-level.ts +0 -19
- package/src/resources.ts +0 -1
- package/src/tsconfig.json +0 -11
- package/src/uploads.ts +0 -2
- package/src/version.ts +0 -1
- package/uploads.d.mts +0 -2
- package/uploads.d.mts.map +0 -1
- package/uploads.d.ts +0 -2
- package/uploads.d.ts.map +0 -1
- package/uploads.js +0 -6
- package/uploads.js.map +0 -1
- package/uploads.mjs +0 -2
- package/uploads.mjs.map +0 -1
- package/version.d.mts +0 -2
- package/version.d.mts.map +0 -1
- package/version.d.ts +0 -2
- package/version.d.ts.map +0 -1
- package/version.js +0 -5
- package/version.js.map +0 -1
- package/version.mjs +0 -2
- package/version.mjs.map +0 -1
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
-
|
|
3
|
-
import { NebulaError } from '../../core/error';
|
|
4
|
-
|
|
5
|
-
// https://url.spec.whatwg.org/#url-scheme-string
|
|
6
|
-
const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
|
|
7
|
-
|
|
8
|
-
export const isAbsoluteURL = (url: string): boolean => {
|
|
9
|
-
return startsWithSchemeRegexp.test(url);
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export let isArray = (val: unknown): val is unknown[] => ((isArray = Array.isArray), isArray(val));
|
|
13
|
-
export let isReadonlyArray = isArray as (val: unknown) => val is readonly unknown[];
|
|
14
|
-
|
|
15
|
-
/** Returns an object if the given value isn't an object, otherwise returns as-is */
|
|
16
|
-
export function maybeObj(x: unknown): object {
|
|
17
|
-
if (typeof x !== 'object') {
|
|
18
|
-
return {};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return x ?? {};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// https://stackoverflow.com/a/34491287
|
|
25
|
-
export function isEmptyObj(obj: Object | null | undefined): boolean {
|
|
26
|
-
if (!obj) return true;
|
|
27
|
-
for (const _k in obj) return false;
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// https://eslint.org/docs/latest/rules/no-prototype-builtins
|
|
32
|
-
export function hasOwn<T extends object = object>(obj: T, key: PropertyKey): key is keyof T {
|
|
33
|
-
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function isObj(obj: unknown): obj is Record<string, unknown> {
|
|
37
|
-
return obj != null && typeof obj === 'object' && !Array.isArray(obj);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const ensurePresent = <T>(value: T | null | undefined): T => {
|
|
41
|
-
if (value == null) {
|
|
42
|
-
throw new NebulaError(`Expected a value to be given but received ${value} instead.`);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return value;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export const validatePositiveInteger = (name: string, n: unknown): number => {
|
|
49
|
-
if (typeof n !== 'number' || !Number.isInteger(n)) {
|
|
50
|
-
throw new NebulaError(`${name} must be an integer`);
|
|
51
|
-
}
|
|
52
|
-
if (n < 0) {
|
|
53
|
-
throw new NebulaError(`${name} must be a positive integer`);
|
|
54
|
-
}
|
|
55
|
-
return n;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export const coerceInteger = (value: unknown): number => {
|
|
59
|
-
if (typeof value === 'number') return Math.round(value);
|
|
60
|
-
if (typeof value === 'string') return parseInt(value, 10);
|
|
61
|
-
|
|
62
|
-
throw new NebulaError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export const coerceFloat = (value: unknown): number => {
|
|
66
|
-
if (typeof value === 'number') return value;
|
|
67
|
-
if (typeof value === 'string') return parseFloat(value);
|
|
68
|
-
|
|
69
|
-
throw new NebulaError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export const coerceBoolean = (value: unknown): boolean => {
|
|
73
|
-
if (typeof value === 'boolean') return value;
|
|
74
|
-
if (typeof value === 'string') return value === 'true';
|
|
75
|
-
return Boolean(value);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export const maybeCoerceInteger = (value: unknown): number | undefined => {
|
|
79
|
-
if (value == null) {
|
|
80
|
-
return undefined;
|
|
81
|
-
}
|
|
82
|
-
return coerceInteger(value);
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
export const maybeCoerceFloat = (value: unknown): number | undefined => {
|
|
86
|
-
if (value == null) {
|
|
87
|
-
return undefined;
|
|
88
|
-
}
|
|
89
|
-
return coerceFloat(value);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
export const maybeCoerceBoolean = (value: unknown): boolean | undefined => {
|
|
93
|
-
if (value == null) {
|
|
94
|
-
return undefined;
|
|
95
|
-
}
|
|
96
|
-
return coerceBoolean(value);
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
export const safeJSON = (text: string) => {
|
|
100
|
-
try {
|
|
101
|
-
return JSON.parse(text);
|
|
102
|
-
} catch (err) {
|
|
103
|
-
return undefined;
|
|
104
|
-
}
|
|
105
|
-
};
|
package/src/internal/utils.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
-
|
|
3
|
-
export * from './utils/values';
|
|
4
|
-
export * from './utils/base64';
|
|
5
|
-
export * from './utils/env';
|
|
6
|
-
export * from './utils/log';
|
|
7
|
-
export * from './utils/uuid';
|
|
8
|
-
export * from './utils/sleep';
|
|
9
|
-
export * from './utils/query';
|
package/src/lib/.keep
DELETED
package/src/lib/dx.ts
DELETED
|
@@ -1,459 +0,0 @@
|
|
|
1
|
-
import { Nebula as GeneratedNebula, type ClientOptions } from '../client';
|
|
2
|
-
import { APIPromise } from '../core/api-promise';
|
|
3
|
-
import { buildHeaders } from '../internal/headers';
|
|
4
|
-
import type { PromiseOrValue } from '../internal/types';
|
|
5
|
-
import type { RequestOptions } from '../internal/request-options';
|
|
6
|
-
import type { HealthResponse } from '../resources/top-level';
|
|
7
|
-
import type {
|
|
8
|
-
CollectionCreateParams,
|
|
9
|
-
CollectionCreateResponse,
|
|
10
|
-
CollectionDeleteResponse,
|
|
11
|
-
CollectionListParams,
|
|
12
|
-
CollectionListResponse,
|
|
13
|
-
CollectionRetrieveByNameResponse,
|
|
14
|
-
CollectionRetrieveResponse,
|
|
15
|
-
CollectionUpdateParams,
|
|
16
|
-
CollectionUpdateResponse,
|
|
17
|
-
} from '../resources/collections';
|
|
18
|
-
import type {
|
|
19
|
-
ConnectorConnectResponse,
|
|
20
|
-
ConnectorDisconnectResponse,
|
|
21
|
-
ConnectorListProvidersResponse,
|
|
22
|
-
ConnectorListResponse,
|
|
23
|
-
ConnectorRetrieveResponse,
|
|
24
|
-
ConnectorSyncResponse,
|
|
25
|
-
} from '../resources/connectors';
|
|
26
|
-
import type {
|
|
27
|
-
MemoryAppendParams,
|
|
28
|
-
MemoryCreateParams,
|
|
29
|
-
MemoryCreateResponse,
|
|
30
|
-
MemoryCreateUploadParams,
|
|
31
|
-
MemoryCreateUploadResponse,
|
|
32
|
-
MemoryDeleteManyResponse,
|
|
33
|
-
MemoryDeleteResponse,
|
|
34
|
-
MemoryListParams,
|
|
35
|
-
MemoryListResponse,
|
|
36
|
-
MemoryRetrieveResponse,
|
|
37
|
-
MemorySearchParams,
|
|
38
|
-
MemorySearchResponse,
|
|
39
|
-
MemoryUpdateParams,
|
|
40
|
-
MemoryUpdateResponse,
|
|
41
|
-
} from '../resources/memories';
|
|
42
|
-
import type {
|
|
43
|
-
SnapshotExportResponse,
|
|
44
|
-
SnapshotImportParams,
|
|
45
|
-
SnapshotImportResponse,
|
|
46
|
-
} from '../resources/snapshots';
|
|
47
|
-
import { path } from '../internal/utils/path';
|
|
48
|
-
|
|
49
|
-
type ResultsOf<T> = T extends { results: infer R } ? R : T;
|
|
50
|
-
type MemoryCreateResult = MemoryCreateResponse['results'];
|
|
51
|
-
type StoredMemoryResult = string | MemoryCreateResult;
|
|
52
|
-
type SnapshotMemoryInput = MemoryCreateInput & { snapshot: NonNullable<MemoryCreateParams['snapshot']> };
|
|
53
|
-
type NonSnapshotMemoryInput = MemoryInput & { snapshot?: null | undefined };
|
|
54
|
-
type RequestPath = `/${string}` | `http://${string}` | `https://${string}`;
|
|
55
|
-
type CompatClientOptions = ClientOptions & {
|
|
56
|
-
api_key?: string | null;
|
|
57
|
-
baseUrl?: string | null;
|
|
58
|
-
base_url?: string | null;
|
|
59
|
-
bearerToken?: string | null;
|
|
60
|
-
bearer_token?: string | null;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export interface MemoryCommonInput {
|
|
64
|
-
collection_id?: string | null;
|
|
65
|
-
collectionId?: string | null;
|
|
66
|
-
content?: string | MemoryCreateParams['content_parts'];
|
|
67
|
-
raw_text?: string | null;
|
|
68
|
-
chunks?: Array<string> | null;
|
|
69
|
-
messages?: MemoryCreateParams['messages'];
|
|
70
|
-
metadata?: { [key: string]: unknown } | null;
|
|
71
|
-
ingestion_config?: MemoryCreateParams['ingestion_config'];
|
|
72
|
-
ingestion_mode?: MemoryCreateParams['ingestion_mode'];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface MemoryCreateInput
|
|
76
|
-
extends MemoryCommonInput,
|
|
77
|
-
Pick<
|
|
78
|
-
MemoryCreateParams,
|
|
79
|
-
'content_parts' | 'contents' | 'engram_type' | 'name' | 'snapshot' | 'speaker_id' | 'speaker_name'
|
|
80
|
-
> {
|
|
81
|
-
memory_id?: undefined | null;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export interface MemoryAppendInput extends Omit<MemoryCommonInput, 'ingestion_mode' | 'messages'> {
|
|
85
|
-
memory_id: string;
|
|
86
|
-
ingestion_mode?: MemoryAppendParams['ingestion_mode'];
|
|
87
|
-
messages?: MemoryAppendParams['messages'];
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export type MemoryInput = MemoryCreateInput | MemoryAppendInput;
|
|
91
|
-
|
|
92
|
-
export class Nebula extends GeneratedNebula {
|
|
93
|
-
constructor(options: CompatClientOptions = {}) {
|
|
94
|
-
super(normalizeAuthOptions(normalizeClientOptions(options)));
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
override health(options?: RequestOptions): APIPromise<HealthResponse> {
|
|
98
|
-
return this.get('/v1/health', {
|
|
99
|
-
...options,
|
|
100
|
-
headers: buildHeaders([options?.headers, { 'X-API-Key': null, Authorization: null }]),
|
|
101
|
-
__security: {},
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async storeMemory(memory: SnapshotMemoryInput, options?: RequestOptions): Promise<MemoryCreateResult>;
|
|
106
|
-
async storeMemory(memory: NonSnapshotMemoryInput, options?: RequestOptions): Promise<string>;
|
|
107
|
-
async storeMemory(memory: MemoryInput, options?: RequestOptions): Promise<StoredMemoryResult>;
|
|
108
|
-
async storeMemory(memory: MemoryInput, options?: RequestOptions): Promise<StoredMemoryResult> {
|
|
109
|
-
if (memory.memory_id != null) {
|
|
110
|
-
const memoryID = memory.memory_id;
|
|
111
|
-
await this.memories.append(memoryID, toMemoryAppendParams(memory), options);
|
|
112
|
-
return memoryID;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const response = await this.memories.create(toMemoryCreateParams(memory), options);
|
|
116
|
-
const result = unwrapResults(response);
|
|
117
|
-
if (isMemoryCreateResult(result)) {
|
|
118
|
-
return result;
|
|
119
|
-
}
|
|
120
|
-
return extractID(result);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
storeMemories(memories: SnapshotMemoryInput[], options?: RequestOptions): Promise<MemoryCreateResult[]>;
|
|
124
|
-
storeMemories(memories: NonSnapshotMemoryInput[], options?: RequestOptions): Promise<string[]>;
|
|
125
|
-
storeMemories(memories: MemoryInput[], options?: RequestOptions): Promise<StoredMemoryResult[]>;
|
|
126
|
-
storeMemories(memories: MemoryInput[], options?: RequestOptions): Promise<StoredMemoryResult[]> {
|
|
127
|
-
return Promise.all(memories.map((memory) => this.storeMemory(memory, options)));
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
getMemory(id: string, options?: RequestOptions): Promise<MemoryRetrieveResponse['results']> {
|
|
131
|
-
return unwrap(this.memories.retrieve(id, options));
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
updateMemory(
|
|
135
|
-
id: string,
|
|
136
|
-
params: MemoryUpdateParams,
|
|
137
|
-
options?: RequestOptions,
|
|
138
|
-
): Promise<MemoryUpdateResponse['results']> {
|
|
139
|
-
return unwrap(this.memories.update(id, params, options));
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
listMemories(
|
|
143
|
-
query: MemoryListParams | string | string[],
|
|
144
|
-
options?: RequestOptions,
|
|
145
|
-
): Promise<MemoryListResponse['results']> {
|
|
146
|
-
const normalized =
|
|
147
|
-
typeof query === 'string' || Array.isArray(query) ? { collection_ids: arrayify(query) } : query;
|
|
148
|
-
return unwrap(this.memories.list(normalized, options));
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
search(body: MemorySearchParams, options?: RequestOptions): Promise<ResultsOf<MemorySearchResponse>> {
|
|
152
|
-
const collectionIDs =
|
|
153
|
-
Array.isArray(body.collection_ids) ? body.collection_ids
|
|
154
|
-
: body.collection_ids ? [body.collection_ids]
|
|
155
|
-
: undefined;
|
|
156
|
-
return unwrap(
|
|
157
|
-
this.memories.search(body, {
|
|
158
|
-
...options,
|
|
159
|
-
headers: buildHeaders([options?.headers, collectionAffinityHeaders(collectionIDs)]),
|
|
160
|
-
}),
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
healthCheck(options?: RequestOptions): Promise<HealthResponse['results']> {
|
|
165
|
-
return unwrap(this.health(options));
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
createCollection(
|
|
169
|
-
body: CollectionCreateParams,
|
|
170
|
-
options?: RequestOptions,
|
|
171
|
-
): Promise<CollectionCreateResponse['results']> {
|
|
172
|
-
return unwrap(this.collections.create(body, options));
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
getCollection(id: string, options?: RequestOptions): Promise<CollectionRetrieveResponse['results']> {
|
|
176
|
-
return unwrap(this.collections.retrieve(id, options));
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
getCollectionByName(
|
|
180
|
-
name: string,
|
|
181
|
-
options?: RequestOptions,
|
|
182
|
-
): Promise<CollectionRetrieveByNameResponse['results']> {
|
|
183
|
-
return unwrap(this.collections.retrieveByName(name, {}, options));
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
listCollections(
|
|
187
|
-
query: CollectionListParams = {},
|
|
188
|
-
options?: RequestOptions,
|
|
189
|
-
): Promise<CollectionListResponse['results']> {
|
|
190
|
-
return unwrap(this.collections.list(query, options));
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
updateCollection(
|
|
194
|
-
id: string,
|
|
195
|
-
body: CollectionUpdateParams,
|
|
196
|
-
options?: RequestOptions,
|
|
197
|
-
): Promise<CollectionUpdateResponse['results']> {
|
|
198
|
-
return unwrap(this.collections.update(id, body, options));
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
deleteCollection(id: string, options?: RequestOptions): Promise<boolean> {
|
|
202
|
-
return this.collections.delete(id, options).then((response: CollectionDeleteResponse) => {
|
|
203
|
-
const result = unwrapResults(response) as { success?: boolean };
|
|
204
|
-
return Boolean(result.success);
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
createCluster = this.createCollection;
|
|
209
|
-
getCluster = this.getCollection;
|
|
210
|
-
getClusterByName = this.getCollectionByName;
|
|
211
|
-
listClusters = this.listCollections;
|
|
212
|
-
updateCluster = this.updateCollection;
|
|
213
|
-
deleteCluster = this.deleteCollection;
|
|
214
|
-
|
|
215
|
-
listProviders(options?: RequestOptions): Promise<ConnectorListProvidersResponse['results']> {
|
|
216
|
-
return unwrap(this.connectors.listProviders(options));
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
connectProvider(
|
|
220
|
-
provider: string,
|
|
221
|
-
collectionID: string,
|
|
222
|
-
config?: Record<string, unknown>,
|
|
223
|
-
options?: RequestOptions,
|
|
224
|
-
): Promise<ConnectorConnectResponse['results']> {
|
|
225
|
-
return unwrap(
|
|
226
|
-
this.connectors.connect(
|
|
227
|
-
provider,
|
|
228
|
-
config === undefined ? { collection_id: collectionID } : { collection_id: collectionID, config },
|
|
229
|
-
options,
|
|
230
|
-
),
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
listConnections(collectionID: string, options?: RequestOptions): Promise<ConnectorListResponse['results']> {
|
|
235
|
-
return unwrap(this.connectors.list({ collection_id: collectionID }, options));
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
getConnection(
|
|
239
|
-
connectionID: string,
|
|
240
|
-
options?: RequestOptions,
|
|
241
|
-
): Promise<ConnectorRetrieveResponse['results']> {
|
|
242
|
-
return unwrap(this.connectors.retrieve(connectionID, options));
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
triggerSync(connectionID: string, options?: RequestOptions): Promise<ConnectorSyncResponse['results']> {
|
|
246
|
-
return unwrap(this.connectors.sync(connectionID, options));
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
disconnectConnection(
|
|
250
|
-
connectionID: string,
|
|
251
|
-
deleteMemories = false,
|
|
252
|
-
options?: RequestOptions,
|
|
253
|
-
): Promise<ConnectorDisconnectResponse['results']> {
|
|
254
|
-
return unwrap(this.connectors.disconnect(connectionID, { delete_memories: deleteMemories }, options));
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
disconnect(
|
|
258
|
-
connectionID: string,
|
|
259
|
-
deleteMemories = false,
|
|
260
|
-
options?: RequestOptions,
|
|
261
|
-
): Promise<ConnectorDisconnectResponse['results']> {
|
|
262
|
-
return this.disconnectConnection(connectionID, deleteMemories, options);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
getUploadUrl(
|
|
266
|
-
params: MemoryCreateUploadParams,
|
|
267
|
-
options?: RequestOptions,
|
|
268
|
-
): Promise<MemoryCreateUploadResponse['results']> {
|
|
269
|
-
return unwrap(this.memories.createUpload(params, options));
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
exportSnapshot(collectionID: string, options?: RequestOptions): Promise<SnapshotExportResponse['results']> {
|
|
273
|
-
return unwrap(this.snapshots.export({ collection_id: collectionID }, options));
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
importSnapshot(
|
|
277
|
-
snapshot: SnapshotImportParams['snapshot'],
|
|
278
|
-
options?: RequestOptions,
|
|
279
|
-
): Promise<SnapshotImportResponse['results']> {
|
|
280
|
-
return unwrap(this.snapshots.import({ snapshot }, options));
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
deleteMemory(memoryID: string, options?: PromiseOrValue<RequestOptions>): APIPromise<boolean> {
|
|
284
|
-
return super
|
|
285
|
-
.delete<MemoryDeleteResponse>(path`/v1/memories/${memoryID}`, options)
|
|
286
|
-
._thenUnwrap(() => true);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
deleteMemories(
|
|
290
|
-
memoryIDs: string[],
|
|
291
|
-
options?: PromiseOrValue<RequestOptions>,
|
|
292
|
-
): APIPromise<MemoryDeleteManyResponse> {
|
|
293
|
-
return super.post<MemoryDeleteManyResponse>(
|
|
294
|
-
'/v1/memories/delete',
|
|
295
|
-
Promise.resolve(options).then((resolved) => ({ ...resolved, body: memoryIDs })),
|
|
296
|
-
);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
deletePath<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
|
|
300
|
-
return super.delete(path, opts);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
override delete<Rsp>(path: RequestPath, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp>;
|
|
304
|
-
override delete(memoryID: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<boolean>;
|
|
305
|
-
override delete(memoryIDs: string[]): APIPromise<MemoryDeleteManyResponse>;
|
|
306
|
-
override delete<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp>;
|
|
307
|
-
override delete(
|
|
308
|
-
pathOrMemoryIDs: string | string[],
|
|
309
|
-
opts?: PromiseOrValue<RequestOptions>,
|
|
310
|
-
): APIPromise<unknown> {
|
|
311
|
-
if (Array.isArray(pathOrMemoryIDs)) {
|
|
312
|
-
return this.deleteMemories(pathOrMemoryIDs, opts);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
if (isRequestPath(pathOrMemoryIDs)) {
|
|
316
|
-
return super.delete(pathOrMemoryIDs, opts);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
return this.deleteMemory(pathOrMemoryIDs, opts);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
function normalizeAuthOptions(options: ClientOptions): ClientOptions {
|
|
324
|
-
if (options.apiKey && options.accessToken == null && !looksLikeNebulaAPIKey(options.apiKey)) {
|
|
325
|
-
return { ...options, apiKey: null, accessToken: options.apiKey };
|
|
326
|
-
}
|
|
327
|
-
return options;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
function normalizeClientOptions(options: CompatClientOptions): ClientOptions {
|
|
331
|
-
const {
|
|
332
|
-
api_key: apiKeyAlias,
|
|
333
|
-
baseUrl,
|
|
334
|
-
base_url: baseURLAlias,
|
|
335
|
-
bearerToken,
|
|
336
|
-
bearer_token: bearerTokenAlias,
|
|
337
|
-
...rest
|
|
338
|
-
} = options;
|
|
339
|
-
return {
|
|
340
|
-
...rest,
|
|
341
|
-
apiKey: firstDefined(rest.apiKey, apiKeyAlias),
|
|
342
|
-
accessToken: firstDefined(rest.accessToken, bearerToken, bearerTokenAlias),
|
|
343
|
-
baseURL: firstDefined(rest.baseURL, baseUrl, baseURLAlias),
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
function firstDefined<T>(...values: (T | undefined)[]): T | undefined {
|
|
348
|
-
return values.find((value) => value !== undefined);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
function looksLikeNebulaAPIKey(token: string): boolean {
|
|
352
|
-
const [publicPart, rawPart, extra] = token.split('.');
|
|
353
|
-
return (
|
|
354
|
-
extra === undefined &&
|
|
355
|
-
publicPart !== undefined &&
|
|
356
|
-
rawPart !== undefined &&
|
|
357
|
-
rawPart.length > 0 &&
|
|
358
|
-
(publicPart.startsWith('key_') || publicPart.startsWith('neb_'))
|
|
359
|
-
);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
function toMemoryCreateParams(memory: MemoryCreateInput): MemoryCreateParams {
|
|
363
|
-
const collectionID = memory.collection_id ?? memory.collectionId;
|
|
364
|
-
const { collectionId: _collectionId, content, memory_id: _memoryID, ...rest } = memory;
|
|
365
|
-
const params = { ...rest } as MemoryCreateParams;
|
|
366
|
-
|
|
367
|
-
if (collectionID !== undefined) {
|
|
368
|
-
params.collection_id = collectionID;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
if (content != null) {
|
|
372
|
-
if (typeof content === 'string') {
|
|
373
|
-
params.raw_text = content;
|
|
374
|
-
} else {
|
|
375
|
-
params.content_parts = content;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
if (params.messages && !params.engram_type) {
|
|
380
|
-
params.engram_type = 'conversation';
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
return params;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
function toMemoryAppendParams(memory: MemoryAppendInput): MemoryAppendParams {
|
|
387
|
-
const collectionID = memory.collection_id ?? memory.collectionId;
|
|
388
|
-
if (!collectionID) {
|
|
389
|
-
throw new Error('collection_id is required when appending to an existing memory');
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
const {
|
|
393
|
-
collection_id: _collectionID,
|
|
394
|
-
collectionId: _collectionId,
|
|
395
|
-
memory_id: _memoryID,
|
|
396
|
-
content,
|
|
397
|
-
...rest
|
|
398
|
-
} = memory;
|
|
399
|
-
const params: MemoryAppendParams = {
|
|
400
|
-
...(rest as Omit<MemoryAppendParams, 'collection_id'>),
|
|
401
|
-
collection_id: collectionID,
|
|
402
|
-
};
|
|
403
|
-
|
|
404
|
-
if (content != null) {
|
|
405
|
-
if (typeof content === 'string') {
|
|
406
|
-
params.raw_text = content;
|
|
407
|
-
} else if (Array.isArray(content) && content.every((item) => typeof item === 'string')) {
|
|
408
|
-
params.chunks = content;
|
|
409
|
-
} else if (Array.isArray(content)) {
|
|
410
|
-
params.messages = content as unknown as NonNullable<MemoryAppendParams['messages']>;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
return params;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
function unwrap<T>(promise: PromiseLike<T>): Promise<ResultsOf<T>> {
|
|
418
|
-
return Promise.resolve(promise).then((response) => unwrapResults(response) as ResultsOf<T>);
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
function unwrapResults<T>(response: T): unknown {
|
|
422
|
-
return typeof response === 'object' && response !== null && 'results' in response ?
|
|
423
|
-
(response as { results: unknown }).results
|
|
424
|
-
: response;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
function extractID(value: unknown): string {
|
|
428
|
-
if (typeof value === 'object' && value !== null) {
|
|
429
|
-
const record = value as Record<string, unknown>;
|
|
430
|
-
const id =
|
|
431
|
-
record['id'] ?? record['memory_id'] ?? record['engram_id'] ?? record['ephemeral_collection_id'];
|
|
432
|
-
if (typeof id === 'string') {
|
|
433
|
-
return id;
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
throw new Error('Nebula memory create response did not include an id');
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
function isMemoryCreateResult(value: unknown): value is MemoryCreateResult {
|
|
440
|
-
return typeof value === 'object' && value !== null && 'snapshot' in value;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
function arrayify(value: string | string[]): string[] {
|
|
444
|
-
return Array.isArray(value) ? value : [value];
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
function collectionAffinityHeaders(collectionIDs?: string[]) {
|
|
448
|
-
if (!collectionIDs?.length) {
|
|
449
|
-
return undefined;
|
|
450
|
-
}
|
|
451
|
-
return {
|
|
452
|
-
'X-Nebula-Collection-Id':
|
|
453
|
-
collectionIDs.length === 1 ? collectionIDs[0] : [...collectionIDs].sort().join(','),
|
|
454
|
-
};
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
function isRequestPath(value: string): boolean {
|
|
458
|
-
return value.startsWith('/') || /^https?:\/\//i.test(value);
|
|
459
|
-
}
|
package/src/resource.ts
DELETED