threadline-sdk 0.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 +82 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +148 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +51 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +13 -0
- package/dist/types.js.map +1 -0
- package/package.json +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# threadline-sdk
|
|
2
|
+
|
|
3
|
+
Threadline is the universal persistent context layer for AI agents. This SDK makes it easy to fetch, inject, and update user context from any Node or browser environment.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install threadline-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick start (Express chatbot)
|
|
12
|
+
|
|
13
|
+
This example shows how to inject context into a system prompt and then write back a context update after the assistant responds.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import express from "express"
|
|
17
|
+
import { Threadline } from "threadline-sdk"
|
|
18
|
+
|
|
19
|
+
const app = express()
|
|
20
|
+
app.use(express.json())
|
|
21
|
+
|
|
22
|
+
const threadline = new Threadline({
|
|
23
|
+
apiKey: process.env.THREADLINE_API_KEY!,
|
|
24
|
+
baseUrl: process.env.THREADLINE_BASE_URL ?? "http://localhost:3000",
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
app.post("/chat", async (req, res) => {
|
|
28
|
+
const { userId, message } = req.body as { userId: string; message: string }
|
|
29
|
+
|
|
30
|
+
const basePrompt = "You are a helpful assistant."
|
|
31
|
+
const injectedPrompt = await threadline.inject(userId, basePrompt)
|
|
32
|
+
|
|
33
|
+
// Call your model here using `injectedPrompt` as the system prompt...
|
|
34
|
+
const agentResponse = `You said: ${message}`
|
|
35
|
+
|
|
36
|
+
await threadline.update({
|
|
37
|
+
userId,
|
|
38
|
+
userMessage: message,
|
|
39
|
+
agentResponse,
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
res.json({ reply: agentResponse })
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
app.listen(3001, () => console.log("Chatbot listening on :3001"))
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## API reference
|
|
49
|
+
|
|
50
|
+
### `new Threadline({ apiKey, baseUrl? })`
|
|
51
|
+
|
|
52
|
+
- **apiKey**: Threadline API key (sent as `Authorization: Bearer <key>`)
|
|
53
|
+
- **baseUrl**: Defaults to `https://api.threadline.dev`. Override for local dev (e.g. `http://localhost:3000`).
|
|
54
|
+
|
|
55
|
+
### `get(userId): Promise<ContextObject>`
|
|
56
|
+
|
|
57
|
+
Fetch the raw context object for a user.
|
|
58
|
+
|
|
59
|
+
### `inject(userId, basePrompt): Promise<string>`
|
|
60
|
+
|
|
61
|
+
Inject relevant context into `basePrompt` and return the enhanced prompt string.
|
|
62
|
+
|
|
63
|
+
### `update({ userId, userMessage, agentResponse }): Promise<{ updated: boolean; delta: Partial<ContextObject> }>`
|
|
64
|
+
|
|
65
|
+
Update the user’s context based on a completed interaction.
|
|
66
|
+
|
|
67
|
+
### `grant({ userId, agentId, scopes, ttlSeconds? }): Promise<{ grantId: string }>`
|
|
68
|
+
|
|
69
|
+
Create a scoped grant.
|
|
70
|
+
|
|
71
|
+
### `revoke(grantId): Promise<{ revoked: boolean }>`
|
|
72
|
+
|
|
73
|
+
Revoke a grant by id.
|
|
74
|
+
|
|
75
|
+
## Errors
|
|
76
|
+
|
|
77
|
+
All SDK methods throw `ThreadlineError` with:
|
|
78
|
+
|
|
79
|
+
- `code`: a stable string error code
|
|
80
|
+
- `message`: human-readable error message
|
|
81
|
+
- `status?`: HTTP status if available
|
|
82
|
+
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ContextObject } from "./types";
|
|
2
|
+
import { ThreadlineError } from "./types";
|
|
3
|
+
type ThreadlineConfig = {
|
|
4
|
+
apiKey: string;
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class Threadline {
|
|
8
|
+
private apiKey;
|
|
9
|
+
private baseUrl;
|
|
10
|
+
constructor(config: ThreadlineConfig);
|
|
11
|
+
private request;
|
|
12
|
+
get(userId: string): Promise<ContextObject>;
|
|
13
|
+
inject(userId: string, basePrompt: string): Promise<string>;
|
|
14
|
+
update(params: {
|
|
15
|
+
userId: string;
|
|
16
|
+
userMessage: string;
|
|
17
|
+
agentResponse: string;
|
|
18
|
+
}): Promise<{
|
|
19
|
+
updated: boolean;
|
|
20
|
+
delta: Partial<ContextObject>;
|
|
21
|
+
}>;
|
|
22
|
+
grant(params: {
|
|
23
|
+
userId: string;
|
|
24
|
+
agentId: string;
|
|
25
|
+
scopes: string[];
|
|
26
|
+
ttlSeconds?: number;
|
|
27
|
+
}): Promise<{
|
|
28
|
+
grantId: string;
|
|
29
|
+
}>;
|
|
30
|
+
revoke(grantId: string): Promise<{
|
|
31
|
+
revoked: boolean;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
export type { ContextObject } from "./types";
|
|
35
|
+
export { ThreadlineError };
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,EAAE,eAAe,EAA4B,MAAM,SAAS,CAAA;AAEnE,KAAK,gBAAgB,GAAG;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAwDD,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,OAAO,CAAQ;gBAEX,MAAM,EAAE,gBAAgB;YAWtB,OAAO;IAiCf,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAO3C,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAgB3D,MAAM,CAAC,MAAM,EAAE;QACnB,MAAM,EAAE,MAAM,CAAA;QACd,WAAW,EAAE,MAAM,CAAA;QACnB,aAAa,EAAE,MAAM,CAAA;KACtB,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,OAAO,CAAC,aAAa,CAAC,CAAA;KAAE,CAAC;IAmB1D,KAAK,CAAC,MAAM,EAAE;QAClB,MAAM,EAAE,MAAM,CAAA;QACd,OAAO,EAAE,MAAM,CAAA;QACf,MAAM,EAAE,MAAM,EAAE,CAAA;QAChB,UAAU,CAAC,EAAE,MAAM,CAAA;KACpB,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAwB1B,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;CAM7D;AAED,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ThreadlineError = exports.Threadline = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
Object.defineProperty(exports, "ThreadlineError", { enumerable: true, get: function () { return types_1.ThreadlineError; } });
|
|
6
|
+
function joinUrl(baseUrl, path) {
|
|
7
|
+
return `${baseUrl.replace(/\/+$/, "")}/${path.replace(/^\/+/, "")}`;
|
|
8
|
+
}
|
|
9
|
+
async function readJsonSafe(res) {
|
|
10
|
+
const text = await res.text().catch(() => "");
|
|
11
|
+
if (!text)
|
|
12
|
+
return null;
|
|
13
|
+
try {
|
|
14
|
+
return JSON.parse(text);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return text;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function toThreadlineError(status, payload) {
|
|
21
|
+
const fallback = new types_1.ThreadlineError({
|
|
22
|
+
code: "UNKNOWN_ERROR",
|
|
23
|
+
message: "Unexpected error.",
|
|
24
|
+
status,
|
|
25
|
+
});
|
|
26
|
+
if (payload && typeof payload === "object") {
|
|
27
|
+
const rec = payload;
|
|
28
|
+
const err = rec.error;
|
|
29
|
+
const code = rec.code;
|
|
30
|
+
if (typeof err === "string" && typeof code === "string") {
|
|
31
|
+
const safeCode = code;
|
|
32
|
+
return new types_1.ThreadlineError({
|
|
33
|
+
code: safeCode,
|
|
34
|
+
message: err,
|
|
35
|
+
status,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (typeof payload === "string" && payload.trim().length > 0) {
|
|
40
|
+
return new types_1.ThreadlineError({
|
|
41
|
+
code: "UNKNOWN_ERROR",
|
|
42
|
+
message: payload,
|
|
43
|
+
status,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return fallback;
|
|
47
|
+
}
|
|
48
|
+
class Threadline {
|
|
49
|
+
constructor(config) {
|
|
50
|
+
if (!config?.apiKey) {
|
|
51
|
+
throw new types_1.ThreadlineError({
|
|
52
|
+
code: "BAD_REQUEST",
|
|
53
|
+
message: "Threadline config.apiKey is required.",
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
this.apiKey = config.apiKey;
|
|
57
|
+
this.baseUrl = config.baseUrl ?? "https://api.threadline.dev";
|
|
58
|
+
}
|
|
59
|
+
async request(method, path, body) {
|
|
60
|
+
const url = joinUrl(this.baseUrl, path);
|
|
61
|
+
let res;
|
|
62
|
+
try {
|
|
63
|
+
res = await fetch(url, {
|
|
64
|
+
method,
|
|
65
|
+
headers: {
|
|
66
|
+
authorization: `Bearer ${this.apiKey}`,
|
|
67
|
+
"content-type": "application/json",
|
|
68
|
+
},
|
|
69
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
throw new types_1.ThreadlineError({
|
|
74
|
+
code: "NETWORK_ERROR",
|
|
75
|
+
message: e?.message ?? "Network error.",
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const payload = await readJsonSafe(res);
|
|
79
|
+
if (!res.ok) {
|
|
80
|
+
throw toThreadlineError(res.status, payload);
|
|
81
|
+
}
|
|
82
|
+
return payload;
|
|
83
|
+
}
|
|
84
|
+
async get(userId) {
|
|
85
|
+
if (!userId) {
|
|
86
|
+
throw new types_1.ThreadlineError({ code: "BAD_REQUEST", message: "userId is required." });
|
|
87
|
+
}
|
|
88
|
+
return await this.request("GET", `/api/context/${encodeURIComponent(userId)}`);
|
|
89
|
+
}
|
|
90
|
+
async inject(userId, basePrompt) {
|
|
91
|
+
if (!userId) {
|
|
92
|
+
throw new types_1.ThreadlineError({ code: "BAD_REQUEST", message: "userId is required." });
|
|
93
|
+
}
|
|
94
|
+
if (!basePrompt) {
|
|
95
|
+
throw new types_1.ThreadlineError({ code: "BAD_REQUEST", message: "basePrompt is required." });
|
|
96
|
+
}
|
|
97
|
+
const res = await this.request("POST", "/api/context/inject", {
|
|
98
|
+
userId,
|
|
99
|
+
basePrompt,
|
|
100
|
+
});
|
|
101
|
+
return res.injectedPrompt;
|
|
102
|
+
}
|
|
103
|
+
async update(params) {
|
|
104
|
+
const { userId, userMessage, agentResponse } = params ?? {};
|
|
105
|
+
if (!userId) {
|
|
106
|
+
throw new types_1.ThreadlineError({ code: "BAD_REQUEST", message: "userId is required." });
|
|
107
|
+
}
|
|
108
|
+
if (!userMessage) {
|
|
109
|
+
throw new types_1.ThreadlineError({ code: "BAD_REQUEST", message: "userMessage is required." });
|
|
110
|
+
}
|
|
111
|
+
if (!agentResponse) {
|
|
112
|
+
throw new types_1.ThreadlineError({ code: "BAD_REQUEST", message: "agentResponse is required." });
|
|
113
|
+
}
|
|
114
|
+
return await this.request("POST", "/api/context/update", {
|
|
115
|
+
userId,
|
|
116
|
+
userMessage,
|
|
117
|
+
agentResponse,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
async grant(params) {
|
|
121
|
+
const { userId, agentId, scopes, ttlSeconds } = params ?? {};
|
|
122
|
+
if (!userId)
|
|
123
|
+
throw new types_1.ThreadlineError({ code: "BAD_REQUEST", message: "userId is required." });
|
|
124
|
+
if (!agentId)
|
|
125
|
+
throw new types_1.ThreadlineError({ code: "BAD_REQUEST", message: "agentId is required." });
|
|
126
|
+
if (!Array.isArray(scopes) || scopes.length === 0) {
|
|
127
|
+
throw new types_1.ThreadlineError({ code: "BAD_REQUEST", message: "scopes[] is required." });
|
|
128
|
+
}
|
|
129
|
+
const expiresAt = typeof ttlSeconds === "number" && ttlSeconds > 0
|
|
130
|
+
? new Date(Date.now() + ttlSeconds * 1000).toISOString()
|
|
131
|
+
: undefined;
|
|
132
|
+
const res = await this.request("POST", "/api/grants", {
|
|
133
|
+
userId,
|
|
134
|
+
agentId,
|
|
135
|
+
scopes,
|
|
136
|
+
expiresAt,
|
|
137
|
+
});
|
|
138
|
+
return { grantId: res.grant.id };
|
|
139
|
+
}
|
|
140
|
+
async revoke(grantId) {
|
|
141
|
+
if (!grantId) {
|
|
142
|
+
throw new types_1.ThreadlineError({ code: "BAD_REQUEST", message: "grantId is required." });
|
|
143
|
+
}
|
|
144
|
+
return await this.request("DELETE", `/api/grants/${encodeURIComponent(grantId)}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.Threadline = Threadline;
|
|
148
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,mCAAmE;AAiM1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AAW,EAAE;YACxD,CAAC,CAAC,SAAS,CAAA;QAEf,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO,CAA4B,MAAM,EAAE,aAAa,EAAE;YAC/E,MAAM;YACN,OAAO;YACP,MAAM;YACN,SAAS;SACV,CAAC,CAAA;QAEF,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,CAAA;IAClC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAAe;QAC1B,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,uBAAe,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,sBAAsB,EAAE,CAAC,CAAA;QACrF,CAAC;QACD,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,eAAe,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IACnF,CAAC;CACF;AAjID,gCAiIC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export interface ThreadlineUser {
|
|
2
|
+
id: string;
|
|
3
|
+
email: string;
|
|
4
|
+
name: string | null;
|
|
5
|
+
created_at: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ContextObject {
|
|
8
|
+
userId: string;
|
|
9
|
+
communication_style: string;
|
|
10
|
+
ongoing_tasks: string[];
|
|
11
|
+
key_relationships: string[];
|
|
12
|
+
domain_expertise: string[];
|
|
13
|
+
preferences: Record<string, unknown>;
|
|
14
|
+
emotional_state: Record<string, unknown>;
|
|
15
|
+
last_updated: string;
|
|
16
|
+
}
|
|
17
|
+
export interface Agent {
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
developer_id: string;
|
|
21
|
+
scopes: string[];
|
|
22
|
+
created_at: string;
|
|
23
|
+
last_used?: string | null;
|
|
24
|
+
}
|
|
25
|
+
export interface Grant {
|
|
26
|
+
id: string;
|
|
27
|
+
userId: string;
|
|
28
|
+
agentId: string;
|
|
29
|
+
scopes: string[];
|
|
30
|
+
granted_at: string;
|
|
31
|
+
expires_at: string | null;
|
|
32
|
+
revoked?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface AuditLog {
|
|
35
|
+
id: string;
|
|
36
|
+
userId: string;
|
|
37
|
+
agentId: string;
|
|
38
|
+
action: string;
|
|
39
|
+
timestamp: string;
|
|
40
|
+
}
|
|
41
|
+
export type ThreadlineErrorCode = "BAD_REQUEST" | "UNAUTHORIZED" | "FORBIDDEN" | "NOT_FOUND" | "RATE_LIMITED" | "SUPABASE_ERROR" | "OPENAI_ERROR" | "INTERNAL_ERROR" | "NETWORK_ERROR" | "UNKNOWN_ERROR";
|
|
42
|
+
export declare class ThreadlineError extends Error {
|
|
43
|
+
code: ThreadlineErrorCode;
|
|
44
|
+
status?: number;
|
|
45
|
+
constructor(params: {
|
|
46
|
+
code: ThreadlineErrorCode;
|
|
47
|
+
message: string;
|
|
48
|
+
status?: number;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,mBAAmB,EAAE,MAAM,CAAA;IAC3B,aAAa,EAAE,MAAM,EAAE,CAAA;IACvB,iBAAiB,EAAE,MAAM,EAAE,CAAA;IAC3B,gBAAgB,EAAE,MAAM,EAAE,CAAA;IAC1B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACxC,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC1B;AAED,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,MAAM,mBAAmB,GAC3B,aAAa,GACb,cAAc,GACd,WAAW,GACX,WAAW,GACX,cAAc,GACd,gBAAgB,GAChB,cAAc,GACd,gBAAgB,GAChB,eAAe,GACf,eAAe,CAAA;AAEnB,qBAAa,eAAgB,SAAQ,KAAK;IACxC,IAAI,EAAE,mBAAmB,CAAA;IACzB,MAAM,CAAC,EAAE,MAAM,CAAA;gBAEH,MAAM,EAAE;QAAE,IAAI,EAAE,mBAAmB,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;CAMpF"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ThreadlineError = void 0;
|
|
4
|
+
class ThreadlineError extends Error {
|
|
5
|
+
constructor(params) {
|
|
6
|
+
super(params.message);
|
|
7
|
+
this.name = "ThreadlineError";
|
|
8
|
+
this.code = params.code;
|
|
9
|
+
this.status = params.status;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.ThreadlineError = ThreadlineError;
|
|
13
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAyDA,MAAa,eAAgB,SAAQ,KAAK;IAIxC,YAAY,MAAuE;QACjF,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QACrB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAA;QAC7B,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAA;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAA;IAC7B,CAAC;CACF;AAVD,0CAUC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "threadline-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Threadline SDK for accessing and updating user context.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc -p tsconfig.json",
|
|
14
|
+
"clean": "powershell -NoProfile -Command \"if (Test-Path dist) { Remove-Item -Recurse -Force dist }\""
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"typescript": "^5.9.2"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|