xmemory 2.0.0 → 2.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.
- package/README.md +13 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/instance.d.ts +34 -1
- package/dist/instance.js +120 -0
- package/dist/types.d.ts +22 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -168,6 +168,19 @@ const schema = await inst.getSchema();
|
|
|
168
168
|
console.log(schema.data_schema);
|
|
169
169
|
```
|
|
170
170
|
|
|
171
|
+
### `inst.describe(options?)` → `DescribeResult`
|
|
172
|
+
|
|
173
|
+
Get agent-facing tool descriptions enriched with the instance's schema.
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
const desc = await inst.describe();
|
|
177
|
+
console.log(desc.asText()); // plain text for system prompts
|
|
178
|
+
const tools = desc.asAnthropicTools(); // Anthropic tool-use format
|
|
179
|
+
const tools = desc.asOpenaiTools(); // OpenAI function-calling format
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Results are cached for 5 minutes. Call `inst.clearDescribeCache()` to force a refresh.
|
|
183
|
+
|
|
171
184
|
## Error handling
|
|
172
185
|
|
|
173
186
|
All errors throw `XmemoryAPIError`. Health check failures throw `XmemoryHealthCheckError` (a subclass).
|
package/dist/index.d.ts
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export { XmemoryClient, xmemoryInstance } from "./client.js";
|
|
5
5
|
export type { AdminNamespace } from "./client.js";
|
|
6
|
-
export { InstanceHandle } from "./instance.js";
|
|
6
|
+
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 } from "./types.js";
|
|
10
10
|
export type { XmemoryClientOptions, RequestOptions, ReadOptions, WriteOptions, ExtractOptions, CreateInstanceOptions, GenerateSchemaOptions, } from "./types.js";
|
|
11
|
-
export type { ClusterInfo, InstanceInfo, InstanceSchemaInfo, ReadResult, WriteResult, AsyncWriteResult, WriteStatusResult, ExtractResult, GenerateSchemaResult, } from "./types.js";
|
|
11
|
+
export type { ClusterInfo, InstanceInfo, InstanceSchemaInfo, ReadResult, WriteResult, AsyncWriteResult, WriteStatusResult, ExtractResult, GenerateSchemaResult, ToolDescription, ToolParameterDescription, RawDescribeResult, } from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// Client
|
|
5
5
|
export { XmemoryClient, xmemoryInstance } from "./client.js";
|
|
6
6
|
// Instance handle
|
|
7
|
-
export { InstanceHandle } from "./instance.js";
|
|
7
|
+
export { DescribeResult, InstanceHandle } from "./instance.js";
|
|
8
8
|
// Error classes
|
|
9
9
|
export { XmemoryAPIError, XmemoryHealthCheckError } from "./types.js";
|
|
10
10
|
// Enums
|
package/dist/instance.d.ts
CHANGED
|
@@ -1,10 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* InstanceHandle — scoped data operations on a single xmemory instance.
|
|
3
3
|
*/
|
|
4
|
-
import type { AsyncWriteResult, ExtractOptions, ExtractResult, InstanceSchemaInfo, ReadOptions, ReadResult, RequestOneFn, RequestOptions, WriteOptions, WriteResult, WriteStatusResult } from "./types.js";
|
|
4
|
+
import type { AsyncWriteResult, ExtractOptions, ExtractResult, InstanceSchemaInfo, RawDescribeResult, ReadOptions, ReadResult, RequestOneFn, RequestOptions, ToolDescription, WriteOptions, WriteResult, WriteStatusResult } from "./types.js";
|
|
5
|
+
export declare class DescribeResult {
|
|
6
|
+
readonly instanceId: string;
|
|
7
|
+
readonly instanceName: string;
|
|
8
|
+
readonly schemaSummary: string;
|
|
9
|
+
readonly tools: readonly ToolDescription[];
|
|
10
|
+
constructor(raw: RawDescribeResult);
|
|
11
|
+
/**
|
|
12
|
+
* Plain-text representation suitable for injecting into an LLM system prompt.
|
|
13
|
+
*
|
|
14
|
+
* By default, tools are presented as method calls (matching the SDK).
|
|
15
|
+
* Set `includeHttp` to `true` to also show HTTP method and path for
|
|
16
|
+
* raw REST callers.
|
|
17
|
+
*/
|
|
18
|
+
asText(options?: {
|
|
19
|
+
includeHttp?: boolean;
|
|
20
|
+
}): string;
|
|
21
|
+
/** Tool definitions in the Anthropic tool-use format. */
|
|
22
|
+
asAnthropicTools(): Record<string, unknown>[];
|
|
23
|
+
/** Tool definitions in the OpenAI function-calling format. */
|
|
24
|
+
asOpenaiTools(): Record<string, unknown>[];
|
|
25
|
+
}
|
|
5
26
|
export declare class InstanceHandle {
|
|
6
27
|
readonly id: string;
|
|
7
28
|
private readonly _requestOne;
|
|
29
|
+
private _describeCache;
|
|
30
|
+
private _describeCacheAt;
|
|
31
|
+
private _describeTtlMs;
|
|
8
32
|
constructor(id: string, requestOne: RequestOneFn);
|
|
9
33
|
read(query: string, options?: ReadOptions): Promise<ReadResult>;
|
|
10
34
|
write(text: string, options?: WriteOptions): Promise<WriteResult>;
|
|
@@ -12,4 +36,13 @@ export declare class InstanceHandle {
|
|
|
12
36
|
writeStatus(writeId: string, options?: RequestOptions): Promise<WriteStatusResult>;
|
|
13
37
|
extract(text: string, options?: ExtractOptions): Promise<ExtractResult>;
|
|
14
38
|
getSchema(options?: RequestOptions): Promise<InstanceSchemaInfo>;
|
|
39
|
+
/**
|
|
40
|
+
* Return agent-facing tool descriptions enriched with the instance schema.
|
|
41
|
+
*
|
|
42
|
+
* Results are cached locally with a TTL (default 5 min).
|
|
43
|
+
* Call `clearDescribeCache()` to force a refresh.
|
|
44
|
+
*/
|
|
45
|
+
describe(options?: RequestOptions): Promise<DescribeResult>;
|
|
46
|
+
/** Clear the cached describe result so the next `describe()` call fetches fresh data. */
|
|
47
|
+
clearDescribeCache(): void;
|
|
15
48
|
}
|
package/dist/instance.js
CHANGED
|
@@ -1,9 +1,105 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* InstanceHandle — scoped data operations on a single xmemory instance.
|
|
3
3
|
*/
|
|
4
|
+
const DEFAULT_DESCRIBE_TTL_MS = 300_000; // 5 minutes
|
|
5
|
+
export class DescribeResult {
|
|
6
|
+
instanceId;
|
|
7
|
+
instanceName;
|
|
8
|
+
schemaSummary;
|
|
9
|
+
tools;
|
|
10
|
+
constructor(raw) {
|
|
11
|
+
this.instanceId = raw.instance_id;
|
|
12
|
+
this.instanceName = raw.instance_name;
|
|
13
|
+
this.schemaSummary = raw.schema_summary;
|
|
14
|
+
this.tools = raw.tools;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Plain-text representation suitable for injecting into an LLM system prompt.
|
|
18
|
+
*
|
|
19
|
+
* By default, tools are presented as method calls (matching the SDK).
|
|
20
|
+
* Set `includeHttp` to `true` to also show HTTP method and path for
|
|
21
|
+
* raw REST callers.
|
|
22
|
+
*/
|
|
23
|
+
asText(options) {
|
|
24
|
+
const includeHttp = options?.includeHttp ?? false;
|
|
25
|
+
const lines = [];
|
|
26
|
+
lines.push(`Instance: ${this.instanceName} (${this.instanceId})`);
|
|
27
|
+
if (this.schemaSummary) {
|
|
28
|
+
lines.push(`\n${this.schemaSummary}`);
|
|
29
|
+
}
|
|
30
|
+
lines.push("\nAvailable tools:\n");
|
|
31
|
+
for (const tool of this.tools) {
|
|
32
|
+
const paramsSig = tool.parameters
|
|
33
|
+
.map((p) => p.name + (p.required ? "" : "?"))
|
|
34
|
+
.join(", ");
|
|
35
|
+
lines.push(`## ${tool.name}(${paramsSig})`);
|
|
36
|
+
lines.push(tool.description);
|
|
37
|
+
lines.push(`When to use: ${tool.when_to_use}`);
|
|
38
|
+
if (includeHttp) {
|
|
39
|
+
lines.push(`HTTP: ${tool.http_method} ${tool.http_path}`);
|
|
40
|
+
}
|
|
41
|
+
if (tool.parameters.length > 0) {
|
|
42
|
+
lines.push("Parameters:");
|
|
43
|
+
for (const p of tool.parameters) {
|
|
44
|
+
const req = p.required ? "required" : "optional";
|
|
45
|
+
lines.push(` - ${p.name} (${p.type}, ${req}): ${p.description}`);
|
|
46
|
+
if (p.enum) {
|
|
47
|
+
lines.push(` Allowed values: ${p.enum.join(", ")}`);
|
|
48
|
+
}
|
|
49
|
+
if (p.default != null) {
|
|
50
|
+
lines.push(` Default: ${p.default}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
lines.push("");
|
|
55
|
+
}
|
|
56
|
+
return lines.join("\n");
|
|
57
|
+
}
|
|
58
|
+
/** Tool definitions in the Anthropic tool-use format. */
|
|
59
|
+
asAnthropicTools() {
|
|
60
|
+
return this.tools.map((tool) => {
|
|
61
|
+
const { properties, required } = buildJsonSchemaProps(tool.parameters);
|
|
62
|
+
return {
|
|
63
|
+
name: tool.name,
|
|
64
|
+
description: `${tool.description}\n\nWhen to use: ${tool.when_to_use}`,
|
|
65
|
+
input_schema: { type: "object", properties, required },
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/** Tool definitions in the OpenAI function-calling format. */
|
|
70
|
+
asOpenaiTools() {
|
|
71
|
+
return this.tools.map((tool) => {
|
|
72
|
+
const { properties, required } = buildJsonSchemaProps(tool.parameters);
|
|
73
|
+
return {
|
|
74
|
+
type: "function",
|
|
75
|
+
function: {
|
|
76
|
+
name: tool.name,
|
|
77
|
+
description: `${tool.description}\n\nWhen to use: ${tool.when_to_use}`,
|
|
78
|
+
parameters: { type: "object", properties, required },
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function buildJsonSchemaProps(params) {
|
|
85
|
+
const properties = {};
|
|
86
|
+
const required = [];
|
|
87
|
+
for (const p of params) {
|
|
88
|
+
const prop = { type: p.type, description: p.description };
|
|
89
|
+
if (p.enum)
|
|
90
|
+
prop.enum = p.enum;
|
|
91
|
+
properties[p.name] = prop;
|
|
92
|
+
if (p.required)
|
|
93
|
+
required.push(p.name);
|
|
94
|
+
}
|
|
95
|
+
return { properties, required };
|
|
96
|
+
}
|
|
4
97
|
export class InstanceHandle {
|
|
5
98
|
id;
|
|
6
99
|
_requestOne;
|
|
100
|
+
_describeCache = null;
|
|
101
|
+
_describeCacheAt = 0;
|
|
102
|
+
_describeTtlMs = DEFAULT_DESCRIBE_TTL_MS;
|
|
7
103
|
constructor(id, requestOne) {
|
|
8
104
|
this.id = id;
|
|
9
105
|
this._requestOne = requestOne;
|
|
@@ -65,4 +161,28 @@ export class InstanceHandle {
|
|
|
65
161
|
timeoutMs: options?.timeoutMs,
|
|
66
162
|
});
|
|
67
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Return agent-facing tool descriptions enriched with the instance schema.
|
|
166
|
+
*
|
|
167
|
+
* Results are cached locally with a TTL (default 5 min).
|
|
168
|
+
* Call `clearDescribeCache()` to force a refresh.
|
|
169
|
+
*/
|
|
170
|
+
async describe(options) {
|
|
171
|
+
const now = Date.now();
|
|
172
|
+
if (this._describeCache && now - this._describeCacheAt < this._describeTtlMs) {
|
|
173
|
+
return this._describeCache;
|
|
174
|
+
}
|
|
175
|
+
const raw = await this._requestOne("GET", `/instances/${this.id}/describe`, {
|
|
176
|
+
timeoutMs: options?.timeoutMs,
|
|
177
|
+
});
|
|
178
|
+
const result = new DescribeResult(raw);
|
|
179
|
+
this._describeCache = result;
|
|
180
|
+
this._describeCacheAt = now;
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
/** Clear the cached describe result so the next `describe()` call fetches fresh data. */
|
|
184
|
+
clearDescribeCache() {
|
|
185
|
+
this._describeCache = null;
|
|
186
|
+
this._describeCacheAt = 0;
|
|
187
|
+
}
|
|
68
188
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -58,6 +58,28 @@ export interface ExtractResult {
|
|
|
58
58
|
export interface GenerateSchemaResult {
|
|
59
59
|
readonly data_schema: Record<string, unknown>;
|
|
60
60
|
}
|
|
61
|
+
export interface ToolParameterDescription {
|
|
62
|
+
readonly name: string;
|
|
63
|
+
readonly type: string;
|
|
64
|
+
readonly description: string;
|
|
65
|
+
readonly required: boolean;
|
|
66
|
+
readonly enum?: string[];
|
|
67
|
+
readonly default?: string;
|
|
68
|
+
}
|
|
69
|
+
export interface ToolDescription {
|
|
70
|
+
readonly name: string;
|
|
71
|
+
readonly description: string;
|
|
72
|
+
readonly when_to_use: string;
|
|
73
|
+
readonly parameters: ToolParameterDescription[];
|
|
74
|
+
readonly http_method: string;
|
|
75
|
+
readonly http_path: string;
|
|
76
|
+
}
|
|
77
|
+
export interface RawDescribeResult {
|
|
78
|
+
readonly instance_id: string;
|
|
79
|
+
readonly instance_name: string;
|
|
80
|
+
readonly schema_summary: string;
|
|
81
|
+
readonly tools: ToolDescription[];
|
|
82
|
+
}
|
|
61
83
|
export interface XmemoryClientOptions {
|
|
62
84
|
url?: string;
|
|
63
85
|
token?: string;
|