@thingd/sdk 0.31.0 → 0.32.2
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/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thingd/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.2",
|
|
4
4
|
"description": "A fast object-first data engine for applications and AI agents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Sayan Mohsin",
|
|
@@ -63,14 +63,13 @@
|
|
|
63
63
|
"zod": "^4.4.3"
|
|
64
64
|
},
|
|
65
65
|
"optionalDependencies": {
|
|
66
|
-
"@thingd/native": "0.
|
|
66
|
+
"@thingd/native": "0.32.2"
|
|
67
67
|
},
|
|
68
68
|
"engines": {
|
|
69
69
|
"node": ">=24.0.0"
|
|
70
70
|
},
|
|
71
71
|
"publishConfig": {
|
|
72
|
-
"access": "public"
|
|
73
|
-
"provenance": true
|
|
72
|
+
"access": "public"
|
|
74
73
|
},
|
|
75
74
|
"scripts": {
|
|
76
75
|
"build": "tsc -p tsconfig.json",
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { MemoryEvent, MemoryObject, MemorySearchOptions, MemorySearchResult, QueueClaimOptions, QueueJob, QueueJobOptions, QueueJobPayload, QueueJobResult, QueueNackOptions, StoredMemoryEvent, StoredMemoryObject, ThingDeleteResult, ThingStore } from "../types.js";
|
|
2
|
-
export type RemoteThingStoreOptions = {
|
|
3
|
-
url: string;
|
|
4
|
-
authToken?: string;
|
|
5
|
-
clientName?: string;
|
|
6
|
-
clientVersion?: string;
|
|
7
|
-
};
|
|
8
|
-
export declare class RemoteThingStore implements ThingStore {
|
|
9
|
-
private readonly client;
|
|
10
|
-
static open(urlOrOptions: string | RemoteThingStoreOptions): Promise<RemoteThingStore>;
|
|
11
|
-
private constructor();
|
|
12
|
-
put(collection: string, object: MemoryObject): Promise<StoredMemoryObject>;
|
|
13
|
-
get(collection: string, id: string): Promise<StoredMemoryObject | null>;
|
|
14
|
-
delete(collection: string, id: string): Promise<ThingDeleteResult>;
|
|
15
|
-
appendEvent(stream: string, event: MemoryEvent): Promise<StoredMemoryEvent>;
|
|
16
|
-
listEvents(stream?: string): Promise<StoredMemoryEvent[]>;
|
|
17
|
-
pushJob(queue: string, payload: QueueJobPayload, options?: QueueJobOptions): Promise<QueueJob>;
|
|
18
|
-
claimJob(queue: string, options?: QueueClaimOptions): Promise<QueueJob | null>;
|
|
19
|
-
ackJob(queue: string, jobId: string): Promise<QueueJobResult>;
|
|
20
|
-
nackJob(queue: string, jobId: string, options?: QueueNackOptions): Promise<QueueJobResult>;
|
|
21
|
-
listJobs(queue: string): Promise<QueueJob[]>;
|
|
22
|
-
listDeadJobs(queue: string): Promise<QueueJob[]>;
|
|
23
|
-
search(query: string, options?: MemorySearchOptions): Promise<MemorySearchResult[]>;
|
|
24
|
-
close(): Promise<void>;
|
|
25
|
-
private callTool;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=remote-thing-store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"remote-thing-store.d.ts","sourceRoot":"","sources":["../../src/stores/remote-thing-store.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,QAAQ,EACR,eAAe,EACf,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,EACX,MAAM,aAAa,CAAC;AAErB,MAAM,MAAM,uBAAuB,GAAG;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;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,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAQjF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAId,QAAQ;CAQvB"}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
-
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
3
|
-
export class RemoteThingStore {
|
|
4
|
-
client;
|
|
5
|
-
static async open(urlOrOptions) {
|
|
6
|
-
const options = typeof urlOrOptions === "string"
|
|
7
|
-
? {
|
|
8
|
-
url: urlOrOptions,
|
|
9
|
-
}
|
|
10
|
-
: urlOrOptions;
|
|
11
|
-
const client = new Client({
|
|
12
|
-
name: options.clientName ?? "thingd-node-sdk",
|
|
13
|
-
version: options.clientVersion ?? "0.1.0",
|
|
14
|
-
});
|
|
15
|
-
const transport = new StreamableHTTPClientTransport(new URL(resolveMcpUrl(options.url)), {
|
|
16
|
-
requestInit: options.authToken
|
|
17
|
-
? {
|
|
18
|
-
headers: {
|
|
19
|
-
Authorization: `Bearer ${options.authToken}`,
|
|
20
|
-
},
|
|
21
|
-
}
|
|
22
|
-
: undefined,
|
|
23
|
-
});
|
|
24
|
-
await client.connect(transport);
|
|
25
|
-
return new RemoteThingStore(client);
|
|
26
|
-
}
|
|
27
|
-
constructor(client) {
|
|
28
|
-
this.client = client;
|
|
29
|
-
}
|
|
30
|
-
put(collection, object) {
|
|
31
|
-
return this.callTool("thing.put", {
|
|
32
|
-
collection,
|
|
33
|
-
object,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
get(collection, id) {
|
|
37
|
-
return this.callTool("thing.get", {
|
|
38
|
-
collection,
|
|
39
|
-
id,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
delete(collection, id) {
|
|
43
|
-
return this.callTool("thing.delete", {
|
|
44
|
-
collection,
|
|
45
|
-
id,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
appendEvent(stream, event) {
|
|
49
|
-
return this.callTool("thing.events.append", {
|
|
50
|
-
stream,
|
|
51
|
-
event,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
listEvents(stream) {
|
|
55
|
-
return this.callTool("thing.events.list", {
|
|
56
|
-
stream,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
pushJob(queue, payload, options = {}) {
|
|
60
|
-
return this.callTool("thing.queue.push", {
|
|
61
|
-
queue,
|
|
62
|
-
payload,
|
|
63
|
-
idempotencyKey: options.idempotencyKey,
|
|
64
|
-
maxAttempts: options.maxAttempts,
|
|
65
|
-
delayMs: options.delayMs,
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
claimJob(queue, options = {}) {
|
|
69
|
-
return this.callTool("thing.queue.claim", {
|
|
70
|
-
queue,
|
|
71
|
-
leaseMs: options.leaseMs,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
ackJob(queue, jobId) {
|
|
75
|
-
return this.callTool("thing.queue.ack", {
|
|
76
|
-
queue,
|
|
77
|
-
id: jobId,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
nackJob(queue, jobId, options = {}) {
|
|
81
|
-
return this.callTool("thing.queue.nack", {
|
|
82
|
-
queue,
|
|
83
|
-
id: jobId,
|
|
84
|
-
delayMs: options.delayMs,
|
|
85
|
-
error: options.error,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
listJobs(queue) {
|
|
89
|
-
return this.callTool("thing.queue.list", {
|
|
90
|
-
queue,
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
listDeadJobs(queue) {
|
|
94
|
-
return this.callTool("thing.queue.dead", {
|
|
95
|
-
queue,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
search(query, options = {}) {
|
|
99
|
-
return this.callTool("thing.search", {
|
|
100
|
-
query,
|
|
101
|
-
collections: options.collections,
|
|
102
|
-
limit: options.limit,
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
async close() {
|
|
106
|
-
await this.client.close();
|
|
107
|
-
}
|
|
108
|
-
async callTool(name, args) {
|
|
109
|
-
return parseJsonToolResult((await this.client.callTool({
|
|
110
|
-
name,
|
|
111
|
-
arguments: args,
|
|
112
|
-
})));
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
function resolveMcpUrl(value) {
|
|
116
|
-
const normalized = value.startsWith("thingd://")
|
|
117
|
-
? `http://${value.slice("thingd://".length)}`
|
|
118
|
-
: value;
|
|
119
|
-
const url = new URL(normalized);
|
|
120
|
-
if (url.pathname === "" || url.pathname === "/") {
|
|
121
|
-
url.pathname = "/mcp";
|
|
122
|
-
}
|
|
123
|
-
return url.toString();
|
|
124
|
-
}
|
|
125
|
-
function parseJsonToolResult(result) {
|
|
126
|
-
const text = result.content.find((part) => part.type === "text" && typeof part.text === "string")?.text;
|
|
127
|
-
if (!text) {
|
|
128
|
-
throw new Error("thingd remote tool did not return JSON text content");
|
|
129
|
-
}
|
|
130
|
-
return JSON.parse(text);
|
|
131
|
-
}
|