xmemory 2.2.1 → 3.0.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/README.md +29 -1
- package/dist/index.d.ts +1 -0
- package/dist/instance.d.ts +1 -0
- package/dist/instance.js +16 -0
- package/dist/types.d.ts +26 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -122,6 +122,7 @@ Extract and store structured objects from text.
|
|
|
122
122
|
```typescript
|
|
123
123
|
const result = await inst.write("Bob is a designer based in Berlin.");
|
|
124
124
|
console.log(result.write_id, result.trace_id);
|
|
125
|
+
console.log(result.changes); // what the write created / updated / deleted
|
|
125
126
|
```
|
|
126
127
|
|
|
127
128
|
Options: `{ extractionLogic?, diffEngine?, timeoutMs? }` — `extractionLogic` defaults to `"fast"`.
|
|
@@ -152,7 +153,34 @@ const result = await inst.read("Who is on the team?");
|
|
|
152
153
|
console.log(result.reader_result);
|
|
153
154
|
```
|
|
154
155
|
|
|
155
|
-
Options: `{ readMode?, traceId?, timeoutMs? }` — `readMode` defaults to `"single-answer"`.
|
|
156
|
+
Options: `{ readMode?, scope?, traceId?, timeoutMs? }` — `readMode` defaults to `"single-answer"`.
|
|
157
|
+
|
|
158
|
+
#### Scoped reads
|
|
159
|
+
|
|
160
|
+
By default a read may draw on the whole instance. Pass a `scope` to restrict it
|
|
161
|
+
to a set of concrete objects — useful for grounding an answer in exactly the
|
|
162
|
+
records you care about, or for keeping a per-user / per-entity read from leaking
|
|
163
|
+
into unrelated data.
|
|
164
|
+
|
|
165
|
+
Each object in the scope is identified by its `type` (the PascalCase class name
|
|
166
|
+
or snake_case table name) plus its user-defined primary `key` (a mapping of
|
|
167
|
+
primary-key field name to value):
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
const result = await inst.read("What do we know about these people?", {
|
|
171
|
+
scope: {
|
|
172
|
+
objects: [
|
|
173
|
+
{ type: "Person", key: { full_name: "Alice Smith" } },
|
|
174
|
+
{ type: "Person", key: { full_name: "Bob Jones" } },
|
|
175
|
+
],
|
|
176
|
+
relationsScope: "all_relations", // default: "no_relations"
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
`relationsScope` controls relation traversal: `"no_relations"` (the default)
|
|
182
|
+
restricts the read to the listed objects only, while `"all_relations"` also
|
|
183
|
+
exposes the relations among the in-scope objects.
|
|
156
184
|
|
|
157
185
|
### `inst.extract(text, options?)` → `ExtractResult`
|
|
158
186
|
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { DescribeResult, InstanceHandle } from "./instance.js";
|
|
|
7
7
|
export { XmemoryAPIError, XmemoryHealthCheckError } from "./types.js";
|
|
8
8
|
export { SchemaType } from "./types.js";
|
|
9
9
|
export type { SchemaTypeValue, ExtractionLogic, ReadMode, WriteQueueStatus, FieldType, OnDelete, CastStrategy, DecisionKind, MigrationSource, } from "./types.js";
|
|
10
|
+
export type { ScopeObject, ReadScope, RelationsScope } from "./types.js";
|
|
10
11
|
export type { XmemoryClientOptions, RequestOptions, ReadOptions, WriteOptions, ExtractOptions, CreateInstanceOptions, GenerateSchemaOptions, UpdateInstanceSchemaOptions, DryRunMigrationOptions, ListMigrationsOptions, GetMigrationOptions, SuggestionRequestOptions, } from "./types.js";
|
|
11
12
|
export type { ClusterInfo, InstanceInfo, InstanceSchemaInfo, ReadResult, WriteResult, AsyncWriteResult, WriteStatusResult, ExtractResult, GenerateSchemaResult, ToolDescription, ToolParameterDescription, RawDescribeResult, } from "./types.js";
|
|
12
13
|
export type { MigrationPlan, MigrationOp, FieldSpec, AddObject, RemoveObject, RenameObject, ChangeObject, AddField, RemoveField, RenameField, ChangeField, AddRelation, RemoveRelation, RenameRelation, ChangeRelation, DefaultValue, EnumValues, } from "./types.js";
|
package/dist/instance.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { ApplyPendingDecisionsResult, AsyncWriteResult, DecideSuggestionsRe
|
|
|
5
5
|
export declare class DescribeResult {
|
|
6
6
|
readonly instanceId: string;
|
|
7
7
|
readonly instanceName: string;
|
|
8
|
+
readonly about: string;
|
|
8
9
|
readonly schemaSummary: string;
|
|
9
10
|
readonly tools: readonly ToolDescription[];
|
|
10
11
|
constructor(raw: RawDescribeResult);
|
package/dist/instance.js
CHANGED
|
@@ -5,11 +5,13 @@ const DEFAULT_DESCRIBE_TTL_MS = 300_000; // 5 minutes
|
|
|
5
5
|
export class DescribeResult {
|
|
6
6
|
instanceId;
|
|
7
7
|
instanceName;
|
|
8
|
+
about;
|
|
8
9
|
schemaSummary;
|
|
9
10
|
tools;
|
|
10
11
|
constructor(raw) {
|
|
11
12
|
this.instanceId = raw.instance_id;
|
|
12
13
|
this.instanceName = raw.instance_name;
|
|
14
|
+
this.about = raw.about ?? "";
|
|
13
15
|
this.schemaSummary = raw.schema_summary;
|
|
14
16
|
this.tools = raw.tools;
|
|
15
17
|
}
|
|
@@ -24,6 +26,9 @@ export class DescribeResult {
|
|
|
24
26
|
const includeHttp = options?.includeHttp ?? false;
|
|
25
27
|
const lines = [];
|
|
26
28
|
lines.push(`Instance: ${this.instanceName} (${this.instanceId})`);
|
|
29
|
+
if (this.about) {
|
|
30
|
+
lines.push(`\n${this.about}`);
|
|
31
|
+
}
|
|
27
32
|
if (this.schemaSummary) {
|
|
28
33
|
lines.push(`\n${this.schemaSummary}`);
|
|
29
34
|
}
|
|
@@ -109,6 +114,17 @@ export class InstanceHandle {
|
|
|
109
114
|
query,
|
|
110
115
|
mode: options?.readMode ?? "single-answer",
|
|
111
116
|
};
|
|
117
|
+
if (options?.scope != null) {
|
|
118
|
+
// Serialize to the API's identity wire shape: each object is
|
|
119
|
+
// `{type, key: {key: {...}}}` (by user-defined primary key), plus `relations_scope`.
|
|
120
|
+
body.scope = {
|
|
121
|
+
objects: options.scope.objects.map((o) => ({
|
|
122
|
+
type: o.type,
|
|
123
|
+
key: { key: o.key },
|
|
124
|
+
})),
|
|
125
|
+
relations_scope: options.scope.relationsScope ?? "no_relations",
|
|
126
|
+
};
|
|
127
|
+
}
|
|
112
128
|
if (options?.traceId != null)
|
|
113
129
|
body.trace_id = options.traceId;
|
|
114
130
|
return this._requestOne("POST", `/instances/${this.id}/read`, {
|
package/dist/types.d.ts
CHANGED
|
@@ -6,8 +6,28 @@ export declare const SchemaType: {
|
|
|
6
6
|
readonly JSON: 1;
|
|
7
7
|
};
|
|
8
8
|
export type SchemaTypeValue = (typeof SchemaType)[keyof typeof SchemaType];
|
|
9
|
-
export type ExtractionLogic = "fast" | "
|
|
9
|
+
export type ExtractionLogic = "fast" | "deep";
|
|
10
10
|
export type ReadMode = "single-answer" | "raw-tables" | "xresponse";
|
|
11
|
+
/**
|
|
12
|
+
* One concrete object a scoped read may touch. Identify it by `type` (PascalCase
|
|
13
|
+
* class name or snake_case table name) plus its user-defined primary `key`
|
|
14
|
+
* (a mapping of primary-key field name to value).
|
|
15
|
+
*/
|
|
16
|
+
export interface ScopeObject {
|
|
17
|
+
type: string;
|
|
18
|
+
key: Record<string, string | number | boolean>;
|
|
19
|
+
}
|
|
20
|
+
/** Which relations a scoped read may traverse. */
|
|
21
|
+
export type RelationsScope = "no_relations" | "all_relations";
|
|
22
|
+
/**
|
|
23
|
+
* A read's scope: the concrete `objects` it may touch, plus relation policy.
|
|
24
|
+
* `relationsScope` is `no_relations` (objects only) by default; `all_relations`
|
|
25
|
+
* also exposes the relations among the in-scope `objects`.
|
|
26
|
+
*/
|
|
27
|
+
export interface ReadScope {
|
|
28
|
+
objects: ScopeObject[];
|
|
29
|
+
relationsScope?: RelationsScope;
|
|
30
|
+
}
|
|
11
31
|
export type WriteQueueStatus = "queued" | "processing" | "extracting" | "extracted" | "applying" | "completed" | "failed" | "not_found";
|
|
12
32
|
export declare class XmemoryAPIError extends Error {
|
|
13
33
|
readonly status?: number | undefined;
|
|
@@ -61,7 +81,8 @@ export interface ReadResult {
|
|
|
61
81
|
export interface WriteResult {
|
|
62
82
|
readonly write_id: string;
|
|
63
83
|
readonly trace_id: string | null;
|
|
64
|
-
|
|
84
|
+
/** What the write did, grouped into `created` / `updated` / `deleted`. */
|
|
85
|
+
readonly changes: unknown;
|
|
65
86
|
}
|
|
66
87
|
export interface AsyncWriteResult {
|
|
67
88
|
readonly write_id: string;
|
|
@@ -306,6 +327,7 @@ export interface ToolDescription {
|
|
|
306
327
|
export interface RawDescribeResult {
|
|
307
328
|
readonly instance_id: string;
|
|
308
329
|
readonly instance_name: string;
|
|
330
|
+
readonly about?: string;
|
|
309
331
|
readonly schema_summary: string;
|
|
310
332
|
readonly tools: ToolDescription[];
|
|
311
333
|
}
|
|
@@ -321,6 +343,8 @@ export interface RequestOptions {
|
|
|
321
343
|
}
|
|
322
344
|
export interface ReadOptions {
|
|
323
345
|
readMode?: ReadMode;
|
|
346
|
+
/** Restrict the read to a set of concrete objects (plus optional relation traversal). */
|
|
347
|
+
scope?: ReadScope;
|
|
324
348
|
traceId?: string;
|
|
325
349
|
timeoutMs?: number;
|
|
326
350
|
}
|