tracia 0.0.1 → 0.1.1
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 +1 -1
- package/README.md +22 -16
- package/dist/index.d.mts +187 -0
- package/dist/index.d.ts +187 -0
- package/dist/index.js +269 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +240 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +43 -6
- package/.idea/copilot.data.migration.agent.xml +0 -6
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/inspectionProfiles/profiles_settings.xml +0 -6
- package/.idea/misc.xml +0 -7
- package/.idea/modules.xml +0 -8
- package/.idea/tracia-node.iml +0 -8
- package/index.d.ts +0 -5
- package/index.js +0 -7
package/LICENSE
CHANGED
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,29 +1,35 @@
|
|
|
1
|
-
# Tracia
|
|
1
|
+
# Tracia SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript SDK for [Tracia](https://tracia.io) — store, test, and trace LLM prompts.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
```bash
|
|
8
|
+
npm install tracia
|
|
9
|
+
```
|
|
10
10
|
|
|
11
|
-
## Quick
|
|
11
|
+
## Quick Start
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
|
-
import {
|
|
14
|
+
import { Tracia } from 'tracia';
|
|
15
|
+
|
|
16
|
+
const tracia = new Tracia({ apiKey: process.env.TRACIA_API_KEY });
|
|
15
17
|
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
});
|
|
18
|
+
const result = await tracia.prompts.run('welcome-email', { name: 'Alice' });
|
|
19
|
+
console.log(result.text);
|
|
19
20
|
```
|
|
20
21
|
|
|
21
|
-
##
|
|
22
|
+
## Documentation
|
|
23
|
+
|
|
24
|
+
[Full API Reference →](https://docs.tracia.io/sdk-node/)
|
|
25
|
+
|
|
26
|
+
## Features
|
|
22
27
|
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
28
|
+
- Run prompts with variables and automatic tracing
|
|
29
|
+
- Manage prompts programmatically (create, update, delete)
|
|
30
|
+
- Full TypeScript support with exported types
|
|
31
|
+
- Zero dependencies (native fetch)
|
|
26
32
|
|
|
27
33
|
## License
|
|
28
34
|
|
|
29
|
-
MIT
|
|
35
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
interface TraciaOptions {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
}
|
|
4
|
+
interface RunVariables {
|
|
5
|
+
[key: string]: string;
|
|
6
|
+
}
|
|
7
|
+
interface RunOptions {
|
|
8
|
+
model?: string;
|
|
9
|
+
tags?: string[];
|
|
10
|
+
userId?: string;
|
|
11
|
+
sessionId?: string;
|
|
12
|
+
}
|
|
13
|
+
interface TokenUsage {
|
|
14
|
+
inputTokens: number;
|
|
15
|
+
outputTokens: number;
|
|
16
|
+
totalTokens: number;
|
|
17
|
+
}
|
|
18
|
+
interface RunResult {
|
|
19
|
+
text: string;
|
|
20
|
+
traceId: string;
|
|
21
|
+
promptVersion: number;
|
|
22
|
+
latencyMs: number;
|
|
23
|
+
usage: TokenUsage;
|
|
24
|
+
cost: number;
|
|
25
|
+
}
|
|
26
|
+
declare enum TraciaErrorCode {
|
|
27
|
+
UNAUTHORIZED = "UNAUTHORIZED",
|
|
28
|
+
NOT_FOUND = "NOT_FOUND",
|
|
29
|
+
CONFLICT = "CONFLICT",
|
|
30
|
+
MISSING_PROVIDER_KEY = "MISSING_PROVIDER_KEY",
|
|
31
|
+
PROVIDER_ERROR = "PROVIDER_ERROR",
|
|
32
|
+
MISSING_VARIABLES = "MISSING_VARIABLES",
|
|
33
|
+
INVALID_REQUEST = "INVALID_REQUEST",
|
|
34
|
+
NETWORK_ERROR = "NETWORK_ERROR",
|
|
35
|
+
TIMEOUT = "TIMEOUT",
|
|
36
|
+
UNKNOWN = "UNKNOWN"
|
|
37
|
+
}
|
|
38
|
+
interface ApiSuccessResponse {
|
|
39
|
+
text: string;
|
|
40
|
+
traceId: string;
|
|
41
|
+
promptVersion: number;
|
|
42
|
+
latencyMs: number;
|
|
43
|
+
usage: TokenUsage;
|
|
44
|
+
cost: number;
|
|
45
|
+
}
|
|
46
|
+
type MessageRole = 'system' | 'user' | 'assistant';
|
|
47
|
+
interface PromptMessage {
|
|
48
|
+
id: string;
|
|
49
|
+
role: MessageRole;
|
|
50
|
+
content: string;
|
|
51
|
+
}
|
|
52
|
+
interface Prompt {
|
|
53
|
+
id: string;
|
|
54
|
+
slug: string;
|
|
55
|
+
name: string;
|
|
56
|
+
description: string | null;
|
|
57
|
+
model: string | null;
|
|
58
|
+
currentVersion: number;
|
|
59
|
+
content: PromptMessage[];
|
|
60
|
+
variables: string[];
|
|
61
|
+
createdAt: string;
|
|
62
|
+
updatedAt: string;
|
|
63
|
+
}
|
|
64
|
+
interface PromptListItem {
|
|
65
|
+
id: string;
|
|
66
|
+
slug: string;
|
|
67
|
+
name: string;
|
|
68
|
+
description: string | null;
|
|
69
|
+
model: string | null;
|
|
70
|
+
currentVersion: number;
|
|
71
|
+
variables: string[];
|
|
72
|
+
createdAt: string;
|
|
73
|
+
updatedAt: string;
|
|
74
|
+
}
|
|
75
|
+
interface CreatePromptOptions {
|
|
76
|
+
name: string;
|
|
77
|
+
slug?: string;
|
|
78
|
+
description?: string;
|
|
79
|
+
content: PromptMessage[];
|
|
80
|
+
}
|
|
81
|
+
interface UpdatePromptOptions {
|
|
82
|
+
name?: string;
|
|
83
|
+
slug?: string;
|
|
84
|
+
description?: string;
|
|
85
|
+
content?: PromptMessage[];
|
|
86
|
+
}
|
|
87
|
+
type TraceStatus = 'SUCCESS' | 'ERROR';
|
|
88
|
+
interface TraceListItem {
|
|
89
|
+
id: string;
|
|
90
|
+
traceId: string;
|
|
91
|
+
promptSlug: string;
|
|
92
|
+
model: string;
|
|
93
|
+
status: TraceStatus;
|
|
94
|
+
latencyMs: number;
|
|
95
|
+
inputTokens: number;
|
|
96
|
+
outputTokens: number;
|
|
97
|
+
totalTokens: number;
|
|
98
|
+
cost: number | null;
|
|
99
|
+
createdAt: string;
|
|
100
|
+
}
|
|
101
|
+
interface Trace {
|
|
102
|
+
id: string;
|
|
103
|
+
traceId: string;
|
|
104
|
+
promptSlug: string;
|
|
105
|
+
promptVersion: number;
|
|
106
|
+
model: string;
|
|
107
|
+
provider: string;
|
|
108
|
+
input: {
|
|
109
|
+
messages: PromptMessage[];
|
|
110
|
+
};
|
|
111
|
+
variables: Record<string, string> | null;
|
|
112
|
+
output: string | null;
|
|
113
|
+
status: TraceStatus;
|
|
114
|
+
error: string | null;
|
|
115
|
+
latencyMs: number;
|
|
116
|
+
inputTokens: number;
|
|
117
|
+
outputTokens: number;
|
|
118
|
+
totalTokens: number;
|
|
119
|
+
cost: number | null;
|
|
120
|
+
tags: string[];
|
|
121
|
+
userId: string | null;
|
|
122
|
+
sessionId: string | null;
|
|
123
|
+
createdAt: string;
|
|
124
|
+
}
|
|
125
|
+
interface ListTracesOptions {
|
|
126
|
+
promptSlug?: string;
|
|
127
|
+
status?: TraceStatus;
|
|
128
|
+
startDate?: Date;
|
|
129
|
+
endDate?: Date;
|
|
130
|
+
userId?: string;
|
|
131
|
+
sessionId?: string;
|
|
132
|
+
tags?: string[];
|
|
133
|
+
limit?: number;
|
|
134
|
+
cursor?: string;
|
|
135
|
+
}
|
|
136
|
+
interface ListTracesResult {
|
|
137
|
+
traces: TraceListItem[];
|
|
138
|
+
nextCursor?: string;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
interface HttpClientOptions {
|
|
142
|
+
apiKey: string;
|
|
143
|
+
baseUrl: string;
|
|
144
|
+
}
|
|
145
|
+
declare class HttpClient {
|
|
146
|
+
private readonly apiKey;
|
|
147
|
+
private readonly baseUrl;
|
|
148
|
+
constructor(options: HttpClientOptions);
|
|
149
|
+
get<T>(path: string): Promise<T>;
|
|
150
|
+
post<T = ApiSuccessResponse>(path: string, body: unknown): Promise<T>;
|
|
151
|
+
put<T>(path: string, body: unknown): Promise<T>;
|
|
152
|
+
delete<T>(path: string): Promise<T>;
|
|
153
|
+
private request;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
declare class Prompts {
|
|
157
|
+
private readonly client;
|
|
158
|
+
constructor(client: HttpClient);
|
|
159
|
+
list(): Promise<PromptListItem[]>;
|
|
160
|
+
get(slug: string): Promise<Prompt>;
|
|
161
|
+
create(options: CreatePromptOptions): Promise<Prompt>;
|
|
162
|
+
update(slug: string, options: UpdatePromptOptions): Promise<Prompt>;
|
|
163
|
+
delete(slug: string): Promise<void>;
|
|
164
|
+
run(slug: string, variables?: RunVariables, options?: RunOptions): Promise<RunResult>;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
declare class Traces {
|
|
168
|
+
private readonly client;
|
|
169
|
+
constructor(client: HttpClient);
|
|
170
|
+
get(traceId: string): Promise<Trace>;
|
|
171
|
+
list(options?: ListTracesOptions): Promise<ListTracesResult>;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
declare class TraciaError extends Error {
|
|
175
|
+
readonly code: TraciaErrorCode;
|
|
176
|
+
readonly statusCode?: number;
|
|
177
|
+
constructor(code: TraciaErrorCode, message: string, statusCode?: number);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
declare class Tracia {
|
|
181
|
+
private readonly client;
|
|
182
|
+
readonly prompts: Prompts;
|
|
183
|
+
readonly traces: Traces;
|
|
184
|
+
constructor(options: TraciaOptions);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export { type CreatePromptOptions, type ListTracesOptions, type ListTracesResult, type MessageRole, type Prompt, type PromptListItem, type PromptMessage, type RunOptions, type RunResult, type RunVariables, type TokenUsage, type Trace, type TraceListItem, type TraceStatus, Tracia, TraciaError, TraciaErrorCode, type TraciaOptions, type UpdatePromptOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
interface TraciaOptions {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
}
|
|
4
|
+
interface RunVariables {
|
|
5
|
+
[key: string]: string;
|
|
6
|
+
}
|
|
7
|
+
interface RunOptions {
|
|
8
|
+
model?: string;
|
|
9
|
+
tags?: string[];
|
|
10
|
+
userId?: string;
|
|
11
|
+
sessionId?: string;
|
|
12
|
+
}
|
|
13
|
+
interface TokenUsage {
|
|
14
|
+
inputTokens: number;
|
|
15
|
+
outputTokens: number;
|
|
16
|
+
totalTokens: number;
|
|
17
|
+
}
|
|
18
|
+
interface RunResult {
|
|
19
|
+
text: string;
|
|
20
|
+
traceId: string;
|
|
21
|
+
promptVersion: number;
|
|
22
|
+
latencyMs: number;
|
|
23
|
+
usage: TokenUsage;
|
|
24
|
+
cost: number;
|
|
25
|
+
}
|
|
26
|
+
declare enum TraciaErrorCode {
|
|
27
|
+
UNAUTHORIZED = "UNAUTHORIZED",
|
|
28
|
+
NOT_FOUND = "NOT_FOUND",
|
|
29
|
+
CONFLICT = "CONFLICT",
|
|
30
|
+
MISSING_PROVIDER_KEY = "MISSING_PROVIDER_KEY",
|
|
31
|
+
PROVIDER_ERROR = "PROVIDER_ERROR",
|
|
32
|
+
MISSING_VARIABLES = "MISSING_VARIABLES",
|
|
33
|
+
INVALID_REQUEST = "INVALID_REQUEST",
|
|
34
|
+
NETWORK_ERROR = "NETWORK_ERROR",
|
|
35
|
+
TIMEOUT = "TIMEOUT",
|
|
36
|
+
UNKNOWN = "UNKNOWN"
|
|
37
|
+
}
|
|
38
|
+
interface ApiSuccessResponse {
|
|
39
|
+
text: string;
|
|
40
|
+
traceId: string;
|
|
41
|
+
promptVersion: number;
|
|
42
|
+
latencyMs: number;
|
|
43
|
+
usage: TokenUsage;
|
|
44
|
+
cost: number;
|
|
45
|
+
}
|
|
46
|
+
type MessageRole = 'system' | 'user' | 'assistant';
|
|
47
|
+
interface PromptMessage {
|
|
48
|
+
id: string;
|
|
49
|
+
role: MessageRole;
|
|
50
|
+
content: string;
|
|
51
|
+
}
|
|
52
|
+
interface Prompt {
|
|
53
|
+
id: string;
|
|
54
|
+
slug: string;
|
|
55
|
+
name: string;
|
|
56
|
+
description: string | null;
|
|
57
|
+
model: string | null;
|
|
58
|
+
currentVersion: number;
|
|
59
|
+
content: PromptMessage[];
|
|
60
|
+
variables: string[];
|
|
61
|
+
createdAt: string;
|
|
62
|
+
updatedAt: string;
|
|
63
|
+
}
|
|
64
|
+
interface PromptListItem {
|
|
65
|
+
id: string;
|
|
66
|
+
slug: string;
|
|
67
|
+
name: string;
|
|
68
|
+
description: string | null;
|
|
69
|
+
model: string | null;
|
|
70
|
+
currentVersion: number;
|
|
71
|
+
variables: string[];
|
|
72
|
+
createdAt: string;
|
|
73
|
+
updatedAt: string;
|
|
74
|
+
}
|
|
75
|
+
interface CreatePromptOptions {
|
|
76
|
+
name: string;
|
|
77
|
+
slug?: string;
|
|
78
|
+
description?: string;
|
|
79
|
+
content: PromptMessage[];
|
|
80
|
+
}
|
|
81
|
+
interface UpdatePromptOptions {
|
|
82
|
+
name?: string;
|
|
83
|
+
slug?: string;
|
|
84
|
+
description?: string;
|
|
85
|
+
content?: PromptMessage[];
|
|
86
|
+
}
|
|
87
|
+
type TraceStatus = 'SUCCESS' | 'ERROR';
|
|
88
|
+
interface TraceListItem {
|
|
89
|
+
id: string;
|
|
90
|
+
traceId: string;
|
|
91
|
+
promptSlug: string;
|
|
92
|
+
model: string;
|
|
93
|
+
status: TraceStatus;
|
|
94
|
+
latencyMs: number;
|
|
95
|
+
inputTokens: number;
|
|
96
|
+
outputTokens: number;
|
|
97
|
+
totalTokens: number;
|
|
98
|
+
cost: number | null;
|
|
99
|
+
createdAt: string;
|
|
100
|
+
}
|
|
101
|
+
interface Trace {
|
|
102
|
+
id: string;
|
|
103
|
+
traceId: string;
|
|
104
|
+
promptSlug: string;
|
|
105
|
+
promptVersion: number;
|
|
106
|
+
model: string;
|
|
107
|
+
provider: string;
|
|
108
|
+
input: {
|
|
109
|
+
messages: PromptMessage[];
|
|
110
|
+
};
|
|
111
|
+
variables: Record<string, string> | null;
|
|
112
|
+
output: string | null;
|
|
113
|
+
status: TraceStatus;
|
|
114
|
+
error: string | null;
|
|
115
|
+
latencyMs: number;
|
|
116
|
+
inputTokens: number;
|
|
117
|
+
outputTokens: number;
|
|
118
|
+
totalTokens: number;
|
|
119
|
+
cost: number | null;
|
|
120
|
+
tags: string[];
|
|
121
|
+
userId: string | null;
|
|
122
|
+
sessionId: string | null;
|
|
123
|
+
createdAt: string;
|
|
124
|
+
}
|
|
125
|
+
interface ListTracesOptions {
|
|
126
|
+
promptSlug?: string;
|
|
127
|
+
status?: TraceStatus;
|
|
128
|
+
startDate?: Date;
|
|
129
|
+
endDate?: Date;
|
|
130
|
+
userId?: string;
|
|
131
|
+
sessionId?: string;
|
|
132
|
+
tags?: string[];
|
|
133
|
+
limit?: number;
|
|
134
|
+
cursor?: string;
|
|
135
|
+
}
|
|
136
|
+
interface ListTracesResult {
|
|
137
|
+
traces: TraceListItem[];
|
|
138
|
+
nextCursor?: string;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
interface HttpClientOptions {
|
|
142
|
+
apiKey: string;
|
|
143
|
+
baseUrl: string;
|
|
144
|
+
}
|
|
145
|
+
declare class HttpClient {
|
|
146
|
+
private readonly apiKey;
|
|
147
|
+
private readonly baseUrl;
|
|
148
|
+
constructor(options: HttpClientOptions);
|
|
149
|
+
get<T>(path: string): Promise<T>;
|
|
150
|
+
post<T = ApiSuccessResponse>(path: string, body: unknown): Promise<T>;
|
|
151
|
+
put<T>(path: string, body: unknown): Promise<T>;
|
|
152
|
+
delete<T>(path: string): Promise<T>;
|
|
153
|
+
private request;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
declare class Prompts {
|
|
157
|
+
private readonly client;
|
|
158
|
+
constructor(client: HttpClient);
|
|
159
|
+
list(): Promise<PromptListItem[]>;
|
|
160
|
+
get(slug: string): Promise<Prompt>;
|
|
161
|
+
create(options: CreatePromptOptions): Promise<Prompt>;
|
|
162
|
+
update(slug: string, options: UpdatePromptOptions): Promise<Prompt>;
|
|
163
|
+
delete(slug: string): Promise<void>;
|
|
164
|
+
run(slug: string, variables?: RunVariables, options?: RunOptions): Promise<RunResult>;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
declare class Traces {
|
|
168
|
+
private readonly client;
|
|
169
|
+
constructor(client: HttpClient);
|
|
170
|
+
get(traceId: string): Promise<Trace>;
|
|
171
|
+
list(options?: ListTracesOptions): Promise<ListTracesResult>;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
declare class TraciaError extends Error {
|
|
175
|
+
readonly code: TraciaErrorCode;
|
|
176
|
+
readonly statusCode?: number;
|
|
177
|
+
constructor(code: TraciaErrorCode, message: string, statusCode?: number);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
declare class Tracia {
|
|
181
|
+
private readonly client;
|
|
182
|
+
readonly prompts: Prompts;
|
|
183
|
+
readonly traces: Traces;
|
|
184
|
+
constructor(options: TraciaOptions);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export { type CreatePromptOptions, type ListTracesOptions, type ListTracesResult, type MessageRole, type Prompt, type PromptListItem, type PromptMessage, type RunOptions, type RunResult, type RunVariables, type TokenUsage, type Trace, type TraceListItem, type TraceStatus, Tracia, TraciaError, TraciaErrorCode, type TraciaOptions, type UpdatePromptOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Tracia: () => Tracia,
|
|
24
|
+
TraciaError: () => TraciaError,
|
|
25
|
+
TraciaErrorCode: () => TraciaErrorCode
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
|
|
29
|
+
// src/errors.ts
|
|
30
|
+
var TraciaError = class _TraciaError extends Error {
|
|
31
|
+
constructor(code, message, statusCode) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.name = "TraciaError";
|
|
34
|
+
this.code = code;
|
|
35
|
+
this.statusCode = statusCode;
|
|
36
|
+
Object.setPrototypeOf(this, _TraciaError.prototype);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// src/types.ts
|
|
41
|
+
var TraciaErrorCode = /* @__PURE__ */ ((TraciaErrorCode2) => {
|
|
42
|
+
TraciaErrorCode2["UNAUTHORIZED"] = "UNAUTHORIZED";
|
|
43
|
+
TraciaErrorCode2["NOT_FOUND"] = "NOT_FOUND";
|
|
44
|
+
TraciaErrorCode2["CONFLICT"] = "CONFLICT";
|
|
45
|
+
TraciaErrorCode2["MISSING_PROVIDER_KEY"] = "MISSING_PROVIDER_KEY";
|
|
46
|
+
TraciaErrorCode2["PROVIDER_ERROR"] = "PROVIDER_ERROR";
|
|
47
|
+
TraciaErrorCode2["MISSING_VARIABLES"] = "MISSING_VARIABLES";
|
|
48
|
+
TraciaErrorCode2["INVALID_REQUEST"] = "INVALID_REQUEST";
|
|
49
|
+
TraciaErrorCode2["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
50
|
+
TraciaErrorCode2["TIMEOUT"] = "TIMEOUT";
|
|
51
|
+
TraciaErrorCode2["UNKNOWN"] = "UNKNOWN";
|
|
52
|
+
return TraciaErrorCode2;
|
|
53
|
+
})(TraciaErrorCode || {});
|
|
54
|
+
|
|
55
|
+
// src/client.ts
|
|
56
|
+
var SDK_VERSION = "0.1.1";
|
|
57
|
+
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
58
|
+
function mapApiErrorCodeToTraciaErrorCode(apiCode) {
|
|
59
|
+
const codeMap = {
|
|
60
|
+
UNAUTHORIZED: "UNAUTHORIZED" /* UNAUTHORIZED */,
|
|
61
|
+
NOT_FOUND: "NOT_FOUND" /* NOT_FOUND */,
|
|
62
|
+
CONFLICT: "CONFLICT" /* CONFLICT */,
|
|
63
|
+
MISSING_PROVIDER_KEY: "MISSING_PROVIDER_KEY" /* MISSING_PROVIDER_KEY */,
|
|
64
|
+
PROVIDER_ERROR: "PROVIDER_ERROR" /* PROVIDER_ERROR */,
|
|
65
|
+
MISSING_VARIABLES: "MISSING_VARIABLES" /* MISSING_VARIABLES */,
|
|
66
|
+
INVALID_REQUEST: "INVALID_REQUEST" /* INVALID_REQUEST */
|
|
67
|
+
};
|
|
68
|
+
return codeMap[apiCode] ?? "UNKNOWN" /* UNKNOWN */;
|
|
69
|
+
}
|
|
70
|
+
var HttpClient = class {
|
|
71
|
+
constructor(options) {
|
|
72
|
+
this.apiKey = options.apiKey;
|
|
73
|
+
this.baseUrl = options.baseUrl.replace(/\/$/, "");
|
|
74
|
+
}
|
|
75
|
+
async get(path) {
|
|
76
|
+
return this.request({ method: "GET", path });
|
|
77
|
+
}
|
|
78
|
+
async post(path, body) {
|
|
79
|
+
return this.request({ method: "POST", path, body });
|
|
80
|
+
}
|
|
81
|
+
async put(path, body) {
|
|
82
|
+
return this.request({ method: "PUT", path, body });
|
|
83
|
+
}
|
|
84
|
+
async delete(path) {
|
|
85
|
+
return this.request({ method: "DELETE", path });
|
|
86
|
+
}
|
|
87
|
+
async request(options) {
|
|
88
|
+
const url = `${this.baseUrl}${options.path}`;
|
|
89
|
+
const controller = new AbortController();
|
|
90
|
+
const timeoutId = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT_MS);
|
|
91
|
+
try {
|
|
92
|
+
const response = await fetch(url, {
|
|
93
|
+
method: options.method,
|
|
94
|
+
headers: {
|
|
95
|
+
"Content-Type": "application/json",
|
|
96
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
97
|
+
"User-Agent": `tracia-sdk/${SDK_VERSION}`
|
|
98
|
+
},
|
|
99
|
+
body: options.body ? JSON.stringify(options.body) : void 0,
|
|
100
|
+
signal: controller.signal
|
|
101
|
+
});
|
|
102
|
+
clearTimeout(timeoutId);
|
|
103
|
+
if (!response.ok) {
|
|
104
|
+
let errorData;
|
|
105
|
+
try {
|
|
106
|
+
errorData = await response.json();
|
|
107
|
+
} catch {
|
|
108
|
+
throw new TraciaError(
|
|
109
|
+
"UNKNOWN" /* UNKNOWN */,
|
|
110
|
+
`HTTP ${response.status}: ${response.statusText}`,
|
|
111
|
+
response.status
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
if (errorData?.error) {
|
|
115
|
+
const errorCode = mapApiErrorCodeToTraciaErrorCode(errorData.error.code);
|
|
116
|
+
throw new TraciaError(errorCode, errorData.error.message, response.status);
|
|
117
|
+
}
|
|
118
|
+
throw new TraciaError(
|
|
119
|
+
"UNKNOWN" /* UNKNOWN */,
|
|
120
|
+
`HTTP ${response.status}: ${response.statusText}`,
|
|
121
|
+
response.status
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
return await response.json();
|
|
125
|
+
} catch (error) {
|
|
126
|
+
clearTimeout(timeoutId);
|
|
127
|
+
if (error instanceof TraciaError) {
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
if (error instanceof Error) {
|
|
131
|
+
if (error.name === "AbortError") {
|
|
132
|
+
throw new TraciaError(
|
|
133
|
+
"TIMEOUT" /* TIMEOUT */,
|
|
134
|
+
`Request timed out after ${DEFAULT_TIMEOUT_MS}ms`
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
throw new TraciaError(
|
|
138
|
+
"NETWORK_ERROR" /* NETWORK_ERROR */,
|
|
139
|
+
`Network error: ${error.message}`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
throw new TraciaError("UNKNOWN" /* UNKNOWN */, "An unknown error occurred");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// src/prompts.ts
|
|
148
|
+
var Prompts = class {
|
|
149
|
+
constructor(client) {
|
|
150
|
+
this.client = client;
|
|
151
|
+
}
|
|
152
|
+
async list() {
|
|
153
|
+
const response = await this.client.get("/api/v1/prompts");
|
|
154
|
+
return response.prompts;
|
|
155
|
+
}
|
|
156
|
+
async get(slug) {
|
|
157
|
+
return this.client.get(`/api/v1/prompts/${encodeURIComponent(slug)}`);
|
|
158
|
+
}
|
|
159
|
+
async create(options) {
|
|
160
|
+
return this.client.post("/api/v1/prompts", options);
|
|
161
|
+
}
|
|
162
|
+
async update(slug, options) {
|
|
163
|
+
return this.client.put(
|
|
164
|
+
`/api/v1/prompts/${encodeURIComponent(slug)}`,
|
|
165
|
+
options
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
async delete(slug) {
|
|
169
|
+
await this.client.delete(
|
|
170
|
+
`/api/v1/prompts/${encodeURIComponent(slug)}`
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
async run(slug, variables, options) {
|
|
174
|
+
const requestBody = {};
|
|
175
|
+
if (variables && Object.keys(variables).length > 0) {
|
|
176
|
+
requestBody.variables = variables;
|
|
177
|
+
}
|
|
178
|
+
if (options?.model) {
|
|
179
|
+
requestBody.model = options.model;
|
|
180
|
+
}
|
|
181
|
+
if (options?.tags && options.tags.length > 0) {
|
|
182
|
+
requestBody.tags = options.tags;
|
|
183
|
+
}
|
|
184
|
+
if (options?.userId) {
|
|
185
|
+
requestBody.userId = options.userId;
|
|
186
|
+
}
|
|
187
|
+
if (options?.sessionId) {
|
|
188
|
+
requestBody.sessionId = options.sessionId;
|
|
189
|
+
}
|
|
190
|
+
const response = await this.client.post(
|
|
191
|
+
`/api/v1/prompts/${encodeURIComponent(slug)}/run`,
|
|
192
|
+
requestBody
|
|
193
|
+
);
|
|
194
|
+
return {
|
|
195
|
+
text: response.text,
|
|
196
|
+
traceId: response.traceId,
|
|
197
|
+
promptVersion: response.promptVersion,
|
|
198
|
+
latencyMs: response.latencyMs,
|
|
199
|
+
usage: response.usage,
|
|
200
|
+
cost: response.cost
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// src/traces.ts
|
|
206
|
+
var Traces = class {
|
|
207
|
+
constructor(client) {
|
|
208
|
+
this.client = client;
|
|
209
|
+
}
|
|
210
|
+
async get(traceId) {
|
|
211
|
+
return this.client.get(`/api/v1/traces/${encodeURIComponent(traceId)}`);
|
|
212
|
+
}
|
|
213
|
+
async list(options) {
|
|
214
|
+
const params = new URLSearchParams();
|
|
215
|
+
if (options?.promptSlug) {
|
|
216
|
+
params.set("promptSlug", options.promptSlug);
|
|
217
|
+
}
|
|
218
|
+
if (options?.status) {
|
|
219
|
+
params.set("status", options.status);
|
|
220
|
+
}
|
|
221
|
+
if (options?.startDate) {
|
|
222
|
+
params.set("startDate", options.startDate.toISOString());
|
|
223
|
+
}
|
|
224
|
+
if (options?.endDate) {
|
|
225
|
+
params.set("endDate", options.endDate.toISOString());
|
|
226
|
+
}
|
|
227
|
+
if (options?.userId) {
|
|
228
|
+
params.set("userId", options.userId);
|
|
229
|
+
}
|
|
230
|
+
if (options?.sessionId) {
|
|
231
|
+
params.set("sessionId", options.sessionId);
|
|
232
|
+
}
|
|
233
|
+
if (options?.tags && options.tags.length > 0) {
|
|
234
|
+
params.set("tags", options.tags.join(","));
|
|
235
|
+
}
|
|
236
|
+
if (options?.limit) {
|
|
237
|
+
params.set("limit", String(options.limit));
|
|
238
|
+
}
|
|
239
|
+
if (options?.cursor) {
|
|
240
|
+
params.set("cursor", options.cursor);
|
|
241
|
+
}
|
|
242
|
+
const query = params.toString();
|
|
243
|
+
const path = query ? `/api/v1/traces?${query}` : "/api/v1/traces";
|
|
244
|
+
return this.client.get(path);
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
// src/index.ts
|
|
249
|
+
var DEFAULT_BASE_URL = "https://app.tracia.io";
|
|
250
|
+
var Tracia = class {
|
|
251
|
+
constructor(options) {
|
|
252
|
+
if (!options.apiKey) {
|
|
253
|
+
throw new Error("apiKey is required");
|
|
254
|
+
}
|
|
255
|
+
this.client = new HttpClient({
|
|
256
|
+
apiKey: options.apiKey,
|
|
257
|
+
baseUrl: DEFAULT_BASE_URL
|
|
258
|
+
});
|
|
259
|
+
this.prompts = new Prompts(this.client);
|
|
260
|
+
this.traces = new Traces(this.client);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
264
|
+
0 && (module.exports = {
|
|
265
|
+
Tracia,
|
|
266
|
+
TraciaError,
|
|
267
|
+
TraciaErrorCode
|
|
268
|
+
});
|
|
269
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/types.ts","../src/client.ts","../src/prompts.ts","../src/traces.ts"],"sourcesContent":["import { HttpClient } from './client'\nimport { Prompts } from './prompts'\nimport { Traces } from './traces'\nimport { TraciaOptions } from './types'\n\nexport { TraciaError } from './errors'\nexport type {\n TraciaOptions,\n RunVariables,\n RunOptions,\n RunResult,\n TokenUsage,\n Prompt,\n PromptListItem,\n PromptMessage,\n MessageRole,\n CreatePromptOptions,\n UpdatePromptOptions,\n Trace,\n TraceListItem,\n TraceStatus,\n ListTracesOptions,\n ListTracesResult,\n} from './types'\nexport { TraciaErrorCode } from './types'\n\nconst DEFAULT_BASE_URL = 'https://app.tracia.io'\n\nexport class Tracia {\n private readonly client: HttpClient\n readonly prompts: Prompts\n readonly traces: Traces\n\n constructor(options: TraciaOptions) {\n if (!options.apiKey) {\n throw new Error('apiKey is required')\n }\n\n this.client = new HttpClient({\n apiKey: options.apiKey,\n baseUrl: DEFAULT_BASE_URL,\n })\n\n this.prompts = new Prompts(this.client)\n this.traces = new Traces(this.client)\n }\n}\n","import { TraciaErrorCode } from './types'\n\nexport class TraciaError extends Error {\n readonly code: TraciaErrorCode\n readonly statusCode?: number\n\n constructor(code: TraciaErrorCode, message: string, statusCode?: number) {\n super(message)\n this.name = 'TraciaError'\n this.code = code\n this.statusCode = statusCode\n\n Object.setPrototypeOf(this, TraciaError.prototype)\n }\n}","export interface TraciaOptions {\n apiKey: string\n}\n\nexport interface RunVariables {\n [key: string]: string\n}\n\nexport interface RunOptions {\n model?: string\n tags?: string[]\n userId?: string\n sessionId?: string\n}\n\nexport interface TokenUsage {\n inputTokens: number\n outputTokens: number\n totalTokens: number\n}\n\nexport interface RunResult {\n text: string\n traceId: string\n promptVersion: number\n latencyMs: number\n usage: TokenUsage\n cost: number\n}\n\nexport enum TraciaErrorCode {\n UNAUTHORIZED = 'UNAUTHORIZED',\n NOT_FOUND = 'NOT_FOUND',\n CONFLICT = 'CONFLICT',\n MISSING_PROVIDER_KEY = 'MISSING_PROVIDER_KEY',\n PROVIDER_ERROR = 'PROVIDER_ERROR',\n MISSING_VARIABLES = 'MISSING_VARIABLES',\n INVALID_REQUEST = 'INVALID_REQUEST',\n NETWORK_ERROR = 'NETWORK_ERROR',\n TIMEOUT = 'TIMEOUT',\n UNKNOWN = 'UNKNOWN',\n}\n\nexport interface ApiErrorResponse {\n error: {\n code: string\n message: string\n }\n}\n\nexport interface ApiSuccessResponse {\n text: string\n traceId: string\n promptVersion: number\n latencyMs: number\n usage: TokenUsage\n cost: number\n}\n\nexport type MessageRole = 'system' | 'user' | 'assistant'\n\nexport interface PromptMessage {\n id: string\n role: MessageRole\n content: string\n}\n\nexport interface Prompt {\n id: string\n slug: string\n name: string\n description: string | null\n model: string | null\n currentVersion: number\n content: PromptMessage[]\n variables: string[]\n createdAt: string\n updatedAt: string\n}\n\nexport interface PromptListItem {\n id: string\n slug: string\n name: string\n description: string | null\n model: string | null\n currentVersion: number\n variables: string[]\n createdAt: string\n updatedAt: string\n}\n\nexport interface CreatePromptOptions {\n name: string\n slug?: string\n description?: string\n content: PromptMessage[]\n}\n\nexport interface UpdatePromptOptions {\n name?: string\n slug?: string\n description?: string\n content?: PromptMessage[]\n}\n\nexport interface ListPromptsResponse {\n prompts: PromptListItem[]\n}\n\nexport interface DeletePromptResponse {\n success: boolean\n}\n\nexport type TraceStatus = 'SUCCESS' | 'ERROR'\n\nexport interface TraceListItem {\n id: string\n traceId: string\n promptSlug: string\n model: string\n status: TraceStatus\n latencyMs: number\n inputTokens: number\n outputTokens: number\n totalTokens: number\n cost: number | null\n createdAt: string\n}\n\nexport interface Trace {\n id: string\n traceId: string\n promptSlug: string\n promptVersion: number\n model: string\n provider: string\n input: { messages: PromptMessage[] }\n variables: Record<string, string> | null\n output: string | null\n status: TraceStatus\n error: string | null\n latencyMs: number\n inputTokens: number\n outputTokens: number\n totalTokens: number\n cost: number | null\n tags: string[]\n userId: string | null\n sessionId: string | null\n createdAt: string\n}\n\nexport interface ListTracesOptions {\n promptSlug?: string\n status?: TraceStatus\n startDate?: Date\n endDate?: Date\n userId?: string\n sessionId?: string\n tags?: string[]\n limit?: number\n cursor?: string\n}\n\nexport interface ListTracesResult {\n traces: TraceListItem[]\n nextCursor?: string\n}","import { TraciaError } from './errors'\nimport {\n TraciaErrorCode,\n ApiErrorResponse,\n ApiSuccessResponse,\n} from './types'\n\nconst SDK_VERSION = process.env.SDK_VERSION || '0.0.0'\nconst DEFAULT_TIMEOUT_MS = 30000\n\ninterface HttpClientOptions {\n apiKey: string\n baseUrl: string\n}\n\ninterface RequestOptions {\n method: 'GET' | 'POST' | 'PUT' | 'DELETE'\n path: string\n body?: unknown\n}\n\nfunction mapApiErrorCodeToTraciaErrorCode(apiCode: string): TraciaErrorCode {\n const codeMap: Record<string, TraciaErrorCode> = {\n UNAUTHORIZED: TraciaErrorCode.UNAUTHORIZED,\n NOT_FOUND: TraciaErrorCode.NOT_FOUND,\n CONFLICT: TraciaErrorCode.CONFLICT,\n MISSING_PROVIDER_KEY: TraciaErrorCode.MISSING_PROVIDER_KEY,\n PROVIDER_ERROR: TraciaErrorCode.PROVIDER_ERROR,\n MISSING_VARIABLES: TraciaErrorCode.MISSING_VARIABLES,\n INVALID_REQUEST: TraciaErrorCode.INVALID_REQUEST,\n }\n return codeMap[apiCode] ?? TraciaErrorCode.UNKNOWN\n}\n\nexport class HttpClient {\n private readonly apiKey: string\n private readonly baseUrl: string\n\n constructor(options: HttpClientOptions) {\n this.apiKey = options.apiKey\n this.baseUrl = options.baseUrl.replace(/\\/$/, '')\n }\n\n async get<T>(path: string): Promise<T> {\n return this.request<T>({ method: 'GET', path })\n }\n\n async post<T = ApiSuccessResponse>(path: string, body: unknown): Promise<T> {\n return this.request<T>({ method: 'POST', path, body })\n }\n\n async put<T>(path: string, body: unknown): Promise<T> {\n return this.request<T>({ method: 'PUT', path, body })\n }\n\n async delete<T>(path: string): Promise<T> {\n return this.request<T>({ method: 'DELETE', path })\n }\n\n private async request<T>(options: RequestOptions): Promise<T> {\n const url = `${this.baseUrl}${options.path}`\n\n const controller = new AbortController()\n const timeoutId = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT_MS)\n\n try {\n const response = await fetch(url, {\n method: options.method,\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.apiKey}`,\n 'User-Agent': `tracia-sdk/${SDK_VERSION}`,\n },\n body: options.body ? JSON.stringify(options.body) : undefined,\n signal: controller.signal,\n })\n\n clearTimeout(timeoutId)\n\n if (!response.ok) {\n let errorData: ApiErrorResponse | undefined\n try {\n errorData = (await response.json()) as ApiErrorResponse\n } catch {\n throw new TraciaError(\n TraciaErrorCode.UNKNOWN,\n `HTTP ${response.status}: ${response.statusText}`,\n response.status\n )\n }\n\n if (errorData?.error) {\n const errorCode = mapApiErrorCodeToTraciaErrorCode(errorData.error.code)\n throw new TraciaError(errorCode, errorData.error.message, response.status)\n }\n\n throw new TraciaError(\n TraciaErrorCode.UNKNOWN,\n `HTTP ${response.status}: ${response.statusText}`,\n response.status\n )\n }\n\n return (await response.json()) as T\n } catch (error) {\n clearTimeout(timeoutId)\n\n if (error instanceof TraciaError) {\n throw error\n }\n\n if (error instanceof Error) {\n if (error.name === 'AbortError') {\n throw new TraciaError(\n TraciaErrorCode.TIMEOUT,\n `Request timed out after ${DEFAULT_TIMEOUT_MS}ms`\n )\n }\n\n throw new TraciaError(\n TraciaErrorCode.NETWORK_ERROR,\n `Network error: ${error.message}`\n )\n }\n\n throw new TraciaError(TraciaErrorCode.UNKNOWN, 'An unknown error occurred')\n }\n }\n}","import { HttpClient } from './client'\nimport {\n RunVariables,\n RunOptions,\n RunResult,\n ApiSuccessResponse,\n Prompt,\n PromptListItem,\n CreatePromptOptions,\n UpdatePromptOptions,\n ListPromptsResponse,\n DeletePromptResponse,\n} from './types'\n\ninterface RunRequestBody {\n variables?: RunVariables\n model?: string\n tags?: string[]\n userId?: string\n sessionId?: string\n}\n\nexport class Prompts {\n constructor(private readonly client: HttpClient) {}\n\n async list(): Promise<PromptListItem[]> {\n const response = await this.client.get<ListPromptsResponse>('/api/v1/prompts')\n return response.prompts\n }\n\n async get(slug: string): Promise<Prompt> {\n return this.client.get<Prompt>(`/api/v1/prompts/${encodeURIComponent(slug)}`)\n }\n\n async create(options: CreatePromptOptions): Promise<Prompt> {\n return this.client.post<Prompt>('/api/v1/prompts', options)\n }\n\n async update(slug: string, options: UpdatePromptOptions): Promise<Prompt> {\n return this.client.put<Prompt>(\n `/api/v1/prompts/${encodeURIComponent(slug)}`,\n options\n )\n }\n\n async delete(slug: string): Promise<void> {\n await this.client.delete<DeletePromptResponse>(\n `/api/v1/prompts/${encodeURIComponent(slug)}`\n )\n }\n\n async run(\n slug: string,\n variables?: RunVariables,\n options?: RunOptions\n ): Promise<RunResult> {\n const requestBody: RunRequestBody = {}\n\n if (variables && Object.keys(variables).length > 0) {\n requestBody.variables = variables\n }\n\n if (options?.model) {\n requestBody.model = options.model\n }\n\n if (options?.tags && options.tags.length > 0) {\n requestBody.tags = options.tags\n }\n\n if (options?.userId) {\n requestBody.userId = options.userId\n }\n\n if (options?.sessionId) {\n requestBody.sessionId = options.sessionId\n }\n\n const response = await this.client.post<ApiSuccessResponse>(\n `/api/v1/prompts/${encodeURIComponent(slug)}/run`,\n requestBody\n )\n\n return {\n text: response.text,\n traceId: response.traceId,\n promptVersion: response.promptVersion,\n latencyMs: response.latencyMs,\n usage: response.usage,\n cost: response.cost,\n }\n }\n}\n","import { HttpClient } from './client'\nimport { Trace, ListTracesOptions, ListTracesResult } from './types'\n\nexport class Traces {\n constructor(private readonly client: HttpClient) {}\n\n async get(traceId: string): Promise<Trace> {\n return this.client.get<Trace>(`/api/v1/traces/${encodeURIComponent(traceId)}`)\n }\n\n async list(options?: ListTracesOptions): Promise<ListTracesResult> {\n const params = new URLSearchParams()\n\n if (options?.promptSlug) {\n params.set('promptSlug', options.promptSlug)\n }\n\n if (options?.status) {\n params.set('status', options.status)\n }\n\n if (options?.startDate) {\n params.set('startDate', options.startDate.toISOString())\n }\n\n if (options?.endDate) {\n params.set('endDate', options.endDate.toISOString())\n }\n\n if (options?.userId) {\n params.set('userId', options.userId)\n }\n\n if (options?.sessionId) {\n params.set('sessionId', options.sessionId)\n }\n\n if (options?.tags && options.tags.length > 0) {\n params.set('tags', options.tags.join(','))\n }\n\n if (options?.limit) {\n params.set('limit', String(options.limit))\n }\n\n if (options?.cursor) {\n params.set('cursor', options.cursor)\n }\n\n const query = params.toString()\n const path = query ? `/api/v1/traces?${query}` : '/api/v1/traces'\n\n return this.client.get<ListTracesResult>(path)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,cAAN,MAAM,qBAAoB,MAAM;AAAA,EAIrC,YAAY,MAAuB,SAAiB,YAAqB;AACvE,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,aAAa;AAElB,WAAO,eAAe,MAAM,aAAY,SAAS;AAAA,EACnD;AACF;;;ACgBO,IAAK,kBAAL,kBAAKA,qBAAL;AACL,EAAAA,iBAAA,kBAAe;AACf,EAAAA,iBAAA,eAAY;AACZ,EAAAA,iBAAA,cAAW;AACX,EAAAA,iBAAA,0BAAuB;AACvB,EAAAA,iBAAA,oBAAiB;AACjB,EAAAA,iBAAA,uBAAoB;AACpB,EAAAA,iBAAA,qBAAkB;AAClB,EAAAA,iBAAA,mBAAgB;AAChB,EAAAA,iBAAA,aAAU;AACV,EAAAA,iBAAA,aAAU;AAVA,SAAAA;AAAA,GAAA;;;ACvBZ,IAAM,cAAc;AACpB,IAAM,qBAAqB;AAa3B,SAAS,iCAAiC,SAAkC;AAC1E,QAAM,UAA2C;AAAA,IAC/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,0 +1,240 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var TraciaError = class _TraciaError extends Error {
|
|
3
|
+
constructor(code, message, statusCode) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "TraciaError";
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.statusCode = statusCode;
|
|
8
|
+
Object.setPrototypeOf(this, _TraciaError.prototype);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// src/types.ts
|
|
13
|
+
var TraciaErrorCode = /* @__PURE__ */ ((TraciaErrorCode2) => {
|
|
14
|
+
TraciaErrorCode2["UNAUTHORIZED"] = "UNAUTHORIZED";
|
|
15
|
+
TraciaErrorCode2["NOT_FOUND"] = "NOT_FOUND";
|
|
16
|
+
TraciaErrorCode2["CONFLICT"] = "CONFLICT";
|
|
17
|
+
TraciaErrorCode2["MISSING_PROVIDER_KEY"] = "MISSING_PROVIDER_KEY";
|
|
18
|
+
TraciaErrorCode2["PROVIDER_ERROR"] = "PROVIDER_ERROR";
|
|
19
|
+
TraciaErrorCode2["MISSING_VARIABLES"] = "MISSING_VARIABLES";
|
|
20
|
+
TraciaErrorCode2["INVALID_REQUEST"] = "INVALID_REQUEST";
|
|
21
|
+
TraciaErrorCode2["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
22
|
+
TraciaErrorCode2["TIMEOUT"] = "TIMEOUT";
|
|
23
|
+
TraciaErrorCode2["UNKNOWN"] = "UNKNOWN";
|
|
24
|
+
return TraciaErrorCode2;
|
|
25
|
+
})(TraciaErrorCode || {});
|
|
26
|
+
|
|
27
|
+
// src/client.ts
|
|
28
|
+
var SDK_VERSION = "0.1.1";
|
|
29
|
+
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
30
|
+
function mapApiErrorCodeToTraciaErrorCode(apiCode) {
|
|
31
|
+
const codeMap = {
|
|
32
|
+
UNAUTHORIZED: "UNAUTHORIZED" /* UNAUTHORIZED */,
|
|
33
|
+
NOT_FOUND: "NOT_FOUND" /* NOT_FOUND */,
|
|
34
|
+
CONFLICT: "CONFLICT" /* CONFLICT */,
|
|
35
|
+
MISSING_PROVIDER_KEY: "MISSING_PROVIDER_KEY" /* MISSING_PROVIDER_KEY */,
|
|
36
|
+
PROVIDER_ERROR: "PROVIDER_ERROR" /* PROVIDER_ERROR */,
|
|
37
|
+
MISSING_VARIABLES: "MISSING_VARIABLES" /* MISSING_VARIABLES */,
|
|
38
|
+
INVALID_REQUEST: "INVALID_REQUEST" /* INVALID_REQUEST */
|
|
39
|
+
};
|
|
40
|
+
return codeMap[apiCode] ?? "UNKNOWN" /* UNKNOWN */;
|
|
41
|
+
}
|
|
42
|
+
var HttpClient = class {
|
|
43
|
+
constructor(options) {
|
|
44
|
+
this.apiKey = options.apiKey;
|
|
45
|
+
this.baseUrl = options.baseUrl.replace(/\/$/, "");
|
|
46
|
+
}
|
|
47
|
+
async get(path) {
|
|
48
|
+
return this.request({ method: "GET", path });
|
|
49
|
+
}
|
|
50
|
+
async post(path, body) {
|
|
51
|
+
return this.request({ method: "POST", path, body });
|
|
52
|
+
}
|
|
53
|
+
async put(path, body) {
|
|
54
|
+
return this.request({ method: "PUT", path, body });
|
|
55
|
+
}
|
|
56
|
+
async delete(path) {
|
|
57
|
+
return this.request({ method: "DELETE", path });
|
|
58
|
+
}
|
|
59
|
+
async request(options) {
|
|
60
|
+
const url = `${this.baseUrl}${options.path}`;
|
|
61
|
+
const controller = new AbortController();
|
|
62
|
+
const timeoutId = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT_MS);
|
|
63
|
+
try {
|
|
64
|
+
const response = await fetch(url, {
|
|
65
|
+
method: options.method,
|
|
66
|
+
headers: {
|
|
67
|
+
"Content-Type": "application/json",
|
|
68
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
69
|
+
"User-Agent": `tracia-sdk/${SDK_VERSION}`
|
|
70
|
+
},
|
|
71
|
+
body: options.body ? JSON.stringify(options.body) : void 0,
|
|
72
|
+
signal: controller.signal
|
|
73
|
+
});
|
|
74
|
+
clearTimeout(timeoutId);
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
let errorData;
|
|
77
|
+
try {
|
|
78
|
+
errorData = await response.json();
|
|
79
|
+
} catch {
|
|
80
|
+
throw new TraciaError(
|
|
81
|
+
"UNKNOWN" /* UNKNOWN */,
|
|
82
|
+
`HTTP ${response.status}: ${response.statusText}`,
|
|
83
|
+
response.status
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
if (errorData?.error) {
|
|
87
|
+
const errorCode = mapApiErrorCodeToTraciaErrorCode(errorData.error.code);
|
|
88
|
+
throw new TraciaError(errorCode, errorData.error.message, response.status);
|
|
89
|
+
}
|
|
90
|
+
throw new TraciaError(
|
|
91
|
+
"UNKNOWN" /* UNKNOWN */,
|
|
92
|
+
`HTTP ${response.status}: ${response.statusText}`,
|
|
93
|
+
response.status
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
return await response.json();
|
|
97
|
+
} catch (error) {
|
|
98
|
+
clearTimeout(timeoutId);
|
|
99
|
+
if (error instanceof TraciaError) {
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
if (error instanceof Error) {
|
|
103
|
+
if (error.name === "AbortError") {
|
|
104
|
+
throw new TraciaError(
|
|
105
|
+
"TIMEOUT" /* TIMEOUT */,
|
|
106
|
+
`Request timed out after ${DEFAULT_TIMEOUT_MS}ms`
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
throw new TraciaError(
|
|
110
|
+
"NETWORK_ERROR" /* NETWORK_ERROR */,
|
|
111
|
+
`Network error: ${error.message}`
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
throw new TraciaError("UNKNOWN" /* UNKNOWN */, "An unknown error occurred");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// src/prompts.ts
|
|
120
|
+
var Prompts = class {
|
|
121
|
+
constructor(client) {
|
|
122
|
+
this.client = client;
|
|
123
|
+
}
|
|
124
|
+
async list() {
|
|
125
|
+
const response = await this.client.get("/api/v1/prompts");
|
|
126
|
+
return response.prompts;
|
|
127
|
+
}
|
|
128
|
+
async get(slug) {
|
|
129
|
+
return this.client.get(`/api/v1/prompts/${encodeURIComponent(slug)}`);
|
|
130
|
+
}
|
|
131
|
+
async create(options) {
|
|
132
|
+
return this.client.post("/api/v1/prompts", options);
|
|
133
|
+
}
|
|
134
|
+
async update(slug, options) {
|
|
135
|
+
return this.client.put(
|
|
136
|
+
`/api/v1/prompts/${encodeURIComponent(slug)}`,
|
|
137
|
+
options
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
async delete(slug) {
|
|
141
|
+
await this.client.delete(
|
|
142
|
+
`/api/v1/prompts/${encodeURIComponent(slug)}`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
async run(slug, variables, options) {
|
|
146
|
+
const requestBody = {};
|
|
147
|
+
if (variables && Object.keys(variables).length > 0) {
|
|
148
|
+
requestBody.variables = variables;
|
|
149
|
+
}
|
|
150
|
+
if (options?.model) {
|
|
151
|
+
requestBody.model = options.model;
|
|
152
|
+
}
|
|
153
|
+
if (options?.tags && options.tags.length > 0) {
|
|
154
|
+
requestBody.tags = options.tags;
|
|
155
|
+
}
|
|
156
|
+
if (options?.userId) {
|
|
157
|
+
requestBody.userId = options.userId;
|
|
158
|
+
}
|
|
159
|
+
if (options?.sessionId) {
|
|
160
|
+
requestBody.sessionId = options.sessionId;
|
|
161
|
+
}
|
|
162
|
+
const response = await this.client.post(
|
|
163
|
+
`/api/v1/prompts/${encodeURIComponent(slug)}/run`,
|
|
164
|
+
requestBody
|
|
165
|
+
);
|
|
166
|
+
return {
|
|
167
|
+
text: response.text,
|
|
168
|
+
traceId: response.traceId,
|
|
169
|
+
promptVersion: response.promptVersion,
|
|
170
|
+
latencyMs: response.latencyMs,
|
|
171
|
+
usage: response.usage,
|
|
172
|
+
cost: response.cost
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
// src/traces.ts
|
|
178
|
+
var Traces = class {
|
|
179
|
+
constructor(client) {
|
|
180
|
+
this.client = client;
|
|
181
|
+
}
|
|
182
|
+
async get(traceId) {
|
|
183
|
+
return this.client.get(`/api/v1/traces/${encodeURIComponent(traceId)}`);
|
|
184
|
+
}
|
|
185
|
+
async list(options) {
|
|
186
|
+
const params = new URLSearchParams();
|
|
187
|
+
if (options?.promptSlug) {
|
|
188
|
+
params.set("promptSlug", options.promptSlug);
|
|
189
|
+
}
|
|
190
|
+
if (options?.status) {
|
|
191
|
+
params.set("status", options.status);
|
|
192
|
+
}
|
|
193
|
+
if (options?.startDate) {
|
|
194
|
+
params.set("startDate", options.startDate.toISOString());
|
|
195
|
+
}
|
|
196
|
+
if (options?.endDate) {
|
|
197
|
+
params.set("endDate", options.endDate.toISOString());
|
|
198
|
+
}
|
|
199
|
+
if (options?.userId) {
|
|
200
|
+
params.set("userId", options.userId);
|
|
201
|
+
}
|
|
202
|
+
if (options?.sessionId) {
|
|
203
|
+
params.set("sessionId", options.sessionId);
|
|
204
|
+
}
|
|
205
|
+
if (options?.tags && options.tags.length > 0) {
|
|
206
|
+
params.set("tags", options.tags.join(","));
|
|
207
|
+
}
|
|
208
|
+
if (options?.limit) {
|
|
209
|
+
params.set("limit", String(options.limit));
|
|
210
|
+
}
|
|
211
|
+
if (options?.cursor) {
|
|
212
|
+
params.set("cursor", options.cursor);
|
|
213
|
+
}
|
|
214
|
+
const query = params.toString();
|
|
215
|
+
const path = query ? `/api/v1/traces?${query}` : "/api/v1/traces";
|
|
216
|
+
return this.client.get(path);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
// src/index.ts
|
|
221
|
+
var DEFAULT_BASE_URL = "https://app.tracia.io";
|
|
222
|
+
var Tracia = class {
|
|
223
|
+
constructor(options) {
|
|
224
|
+
if (!options.apiKey) {
|
|
225
|
+
throw new Error("apiKey is required");
|
|
226
|
+
}
|
|
227
|
+
this.client = new HttpClient({
|
|
228
|
+
apiKey: options.apiKey,
|
|
229
|
+
baseUrl: DEFAULT_BASE_URL
|
|
230
|
+
});
|
|
231
|
+
this.prompts = new Prompts(this.client);
|
|
232
|
+
this.traces = new Traces(this.client);
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
export {
|
|
236
|
+
Tracia,
|
|
237
|
+
TraciaError,
|
|
238
|
+
TraciaErrorCode
|
|
239
|
+
};
|
|
240
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/types.ts","../src/client.ts","../src/prompts.ts","../src/traces.ts","../src/index.ts"],"sourcesContent":["import { TraciaErrorCode } from './types'\n\nexport class TraciaError extends Error {\n readonly code: TraciaErrorCode\n readonly statusCode?: number\n\n constructor(code: TraciaErrorCode, message: string, statusCode?: number) {\n super(message)\n this.name = 'TraciaError'\n this.code = code\n this.statusCode = statusCode\n\n Object.setPrototypeOf(this, TraciaError.prototype)\n }\n}","export interface TraciaOptions {\n apiKey: string\n}\n\nexport interface RunVariables {\n [key: string]: string\n}\n\nexport interface RunOptions {\n model?: string\n tags?: string[]\n userId?: string\n sessionId?: string\n}\n\nexport interface TokenUsage {\n inputTokens: number\n outputTokens: number\n totalTokens: number\n}\n\nexport interface RunResult {\n text: string\n traceId: string\n promptVersion: number\n latencyMs: number\n usage: TokenUsage\n cost: number\n}\n\nexport enum TraciaErrorCode {\n UNAUTHORIZED = 'UNAUTHORIZED',\n NOT_FOUND = 'NOT_FOUND',\n CONFLICT = 'CONFLICT',\n MISSING_PROVIDER_KEY = 'MISSING_PROVIDER_KEY',\n PROVIDER_ERROR = 'PROVIDER_ERROR',\n MISSING_VARIABLES = 'MISSING_VARIABLES',\n INVALID_REQUEST = 'INVALID_REQUEST',\n NETWORK_ERROR = 'NETWORK_ERROR',\n TIMEOUT = 'TIMEOUT',\n UNKNOWN = 'UNKNOWN',\n}\n\nexport interface ApiErrorResponse {\n error: {\n code: string\n message: string\n }\n}\n\nexport interface ApiSuccessResponse {\n text: string\n traceId: string\n promptVersion: number\n latencyMs: number\n usage: TokenUsage\n cost: number\n}\n\nexport type MessageRole = 'system' | 'user' | 'assistant'\n\nexport interface PromptMessage {\n id: string\n role: MessageRole\n content: string\n}\n\nexport interface Prompt {\n id: string\n slug: string\n name: string\n description: string | null\n model: string | null\n currentVersion: number\n content: PromptMessage[]\n variables: string[]\n createdAt: string\n updatedAt: string\n}\n\nexport interface PromptListItem {\n id: string\n slug: string\n name: string\n description: string | null\n model: string | null\n currentVersion: number\n variables: string[]\n createdAt: string\n updatedAt: string\n}\n\nexport interface CreatePromptOptions {\n name: string\n slug?: string\n description?: string\n content: PromptMessage[]\n}\n\nexport interface UpdatePromptOptions {\n name?: string\n slug?: string\n description?: string\n content?: PromptMessage[]\n}\n\nexport interface ListPromptsResponse {\n prompts: PromptListItem[]\n}\n\nexport interface DeletePromptResponse {\n success: boolean\n}\n\nexport type TraceStatus = 'SUCCESS' | 'ERROR'\n\nexport interface TraceListItem {\n id: string\n traceId: string\n promptSlug: string\n model: string\n status: TraceStatus\n latencyMs: number\n inputTokens: number\n outputTokens: number\n totalTokens: number\n cost: number | null\n createdAt: string\n}\n\nexport interface Trace {\n id: string\n traceId: string\n promptSlug: string\n promptVersion: number\n model: string\n provider: string\n input: { messages: PromptMessage[] }\n variables: Record<string, string> | null\n output: string | null\n status: TraceStatus\n error: string | null\n latencyMs: number\n inputTokens: number\n outputTokens: number\n totalTokens: number\n cost: number | null\n tags: string[]\n userId: string | null\n sessionId: string | null\n createdAt: string\n}\n\nexport interface ListTracesOptions {\n promptSlug?: string\n status?: TraceStatus\n startDate?: Date\n endDate?: Date\n userId?: string\n sessionId?: string\n tags?: string[]\n limit?: number\n cursor?: string\n}\n\nexport interface ListTracesResult {\n traces: TraceListItem[]\n nextCursor?: string\n}","import { TraciaError } from './errors'\nimport {\n TraciaErrorCode,\n ApiErrorResponse,\n ApiSuccessResponse,\n} from './types'\n\nconst SDK_VERSION = process.env.SDK_VERSION || '0.0.0'\nconst DEFAULT_TIMEOUT_MS = 30000\n\ninterface HttpClientOptions {\n apiKey: string\n baseUrl: string\n}\n\ninterface RequestOptions {\n method: 'GET' | 'POST' | 'PUT' | 'DELETE'\n path: string\n body?: unknown\n}\n\nfunction mapApiErrorCodeToTraciaErrorCode(apiCode: string): TraciaErrorCode {\n const codeMap: Record<string, TraciaErrorCode> = {\n UNAUTHORIZED: TraciaErrorCode.UNAUTHORIZED,\n NOT_FOUND: TraciaErrorCode.NOT_FOUND,\n CONFLICT: TraciaErrorCode.CONFLICT,\n MISSING_PROVIDER_KEY: TraciaErrorCode.MISSING_PROVIDER_KEY,\n PROVIDER_ERROR: TraciaErrorCode.PROVIDER_ERROR,\n MISSING_VARIABLES: TraciaErrorCode.MISSING_VARIABLES,\n INVALID_REQUEST: TraciaErrorCode.INVALID_REQUEST,\n }\n return codeMap[apiCode] ?? TraciaErrorCode.UNKNOWN\n}\n\nexport class HttpClient {\n private readonly apiKey: string\n private readonly baseUrl: string\n\n constructor(options: HttpClientOptions) {\n this.apiKey = options.apiKey\n this.baseUrl = options.baseUrl.replace(/\\/$/, '')\n }\n\n async get<T>(path: string): Promise<T> {\n return this.request<T>({ method: 'GET', path })\n }\n\n async post<T = ApiSuccessResponse>(path: string, body: unknown): Promise<T> {\n return this.request<T>({ method: 'POST', path, body })\n }\n\n async put<T>(path: string, body: unknown): Promise<T> {\n return this.request<T>({ method: 'PUT', path, body })\n }\n\n async delete<T>(path: string): Promise<T> {\n return this.request<T>({ method: 'DELETE', path })\n }\n\n private async request<T>(options: RequestOptions): Promise<T> {\n const url = `${this.baseUrl}${options.path}`\n\n const controller = new AbortController()\n const timeoutId = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT_MS)\n\n try {\n const response = await fetch(url, {\n method: options.method,\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.apiKey}`,\n 'User-Agent': `tracia-sdk/${SDK_VERSION}`,\n },\n body: options.body ? JSON.stringify(options.body) : undefined,\n signal: controller.signal,\n })\n\n clearTimeout(timeoutId)\n\n if (!response.ok) {\n let errorData: ApiErrorResponse | undefined\n try {\n errorData = (await response.json()) as ApiErrorResponse\n } catch {\n throw new TraciaError(\n TraciaErrorCode.UNKNOWN,\n `HTTP ${response.status}: ${response.statusText}`,\n response.status\n )\n }\n\n if (errorData?.error) {\n const errorCode = mapApiErrorCodeToTraciaErrorCode(errorData.error.code)\n throw new TraciaError(errorCode, errorData.error.message, response.status)\n }\n\n throw new TraciaError(\n TraciaErrorCode.UNKNOWN,\n `HTTP ${response.status}: ${response.statusText}`,\n response.status\n )\n }\n\n return (await response.json()) as T\n } catch (error) {\n clearTimeout(timeoutId)\n\n if (error instanceof TraciaError) {\n throw error\n }\n\n if (error instanceof Error) {\n if (error.name === 'AbortError') {\n throw new TraciaError(\n TraciaErrorCode.TIMEOUT,\n `Request timed out after ${DEFAULT_TIMEOUT_MS}ms`\n )\n }\n\n throw new TraciaError(\n TraciaErrorCode.NETWORK_ERROR,\n `Network error: ${error.message}`\n )\n }\n\n throw new TraciaError(TraciaErrorCode.UNKNOWN, 'An unknown error occurred')\n }\n }\n}","import { HttpClient } from './client'\nimport {\n RunVariables,\n RunOptions,\n RunResult,\n ApiSuccessResponse,\n Prompt,\n PromptListItem,\n CreatePromptOptions,\n UpdatePromptOptions,\n ListPromptsResponse,\n DeletePromptResponse,\n} from './types'\n\ninterface RunRequestBody {\n variables?: RunVariables\n model?: string\n tags?: string[]\n userId?: string\n sessionId?: string\n}\n\nexport class Prompts {\n constructor(private readonly client: HttpClient) {}\n\n async list(): Promise<PromptListItem[]> {\n const response = await this.client.get<ListPromptsResponse>('/api/v1/prompts')\n return response.prompts\n }\n\n async get(slug: string): Promise<Prompt> {\n return this.client.get<Prompt>(`/api/v1/prompts/${encodeURIComponent(slug)}`)\n }\n\n async create(options: CreatePromptOptions): Promise<Prompt> {\n return this.client.post<Prompt>('/api/v1/prompts', options)\n }\n\n async update(slug: string, options: UpdatePromptOptions): Promise<Prompt> {\n return this.client.put<Prompt>(\n `/api/v1/prompts/${encodeURIComponent(slug)}`,\n options\n )\n }\n\n async delete(slug: string): Promise<void> {\n await this.client.delete<DeletePromptResponse>(\n `/api/v1/prompts/${encodeURIComponent(slug)}`\n )\n }\n\n async run(\n slug: string,\n variables?: RunVariables,\n options?: RunOptions\n ): Promise<RunResult> {\n const requestBody: RunRequestBody = {}\n\n if (variables && Object.keys(variables).length > 0) {\n requestBody.variables = variables\n }\n\n if (options?.model) {\n requestBody.model = options.model\n }\n\n if (options?.tags && options.tags.length > 0) {\n requestBody.tags = options.tags\n }\n\n if (options?.userId) {\n requestBody.userId = options.userId\n }\n\n if (options?.sessionId) {\n requestBody.sessionId = options.sessionId\n }\n\n const response = await this.client.post<ApiSuccessResponse>(\n `/api/v1/prompts/${encodeURIComponent(slug)}/run`,\n requestBody\n )\n\n return {\n text: response.text,\n traceId: response.traceId,\n promptVersion: response.promptVersion,\n latencyMs: response.latencyMs,\n usage: response.usage,\n cost: response.cost,\n }\n }\n}\n","import { HttpClient } from './client'\nimport { Trace, ListTracesOptions, ListTracesResult } from './types'\n\nexport class Traces {\n constructor(private readonly client: HttpClient) {}\n\n async get(traceId: string): Promise<Trace> {\n return this.client.get<Trace>(`/api/v1/traces/${encodeURIComponent(traceId)}`)\n }\n\n async list(options?: ListTracesOptions): Promise<ListTracesResult> {\n const params = new URLSearchParams()\n\n if (options?.promptSlug) {\n params.set('promptSlug', options.promptSlug)\n }\n\n if (options?.status) {\n params.set('status', options.status)\n }\n\n if (options?.startDate) {\n params.set('startDate', options.startDate.toISOString())\n }\n\n if (options?.endDate) {\n params.set('endDate', options.endDate.toISOString())\n }\n\n if (options?.userId) {\n params.set('userId', options.userId)\n }\n\n if (options?.sessionId) {\n params.set('sessionId', options.sessionId)\n }\n\n if (options?.tags && options.tags.length > 0) {\n params.set('tags', options.tags.join(','))\n }\n\n if (options?.limit) {\n params.set('limit', String(options.limit))\n }\n\n if (options?.cursor) {\n params.set('cursor', options.cursor)\n }\n\n const query = params.toString()\n const path = query ? `/api/v1/traces?${query}` : '/api/v1/traces'\n\n return this.client.get<ListTracesResult>(path)\n }\n}\n","import { HttpClient } from './client'\nimport { Prompts } from './prompts'\nimport { Traces } from './traces'\nimport { TraciaOptions } from './types'\n\nexport { TraciaError } from './errors'\nexport type {\n TraciaOptions,\n RunVariables,\n RunOptions,\n RunResult,\n TokenUsage,\n Prompt,\n PromptListItem,\n PromptMessage,\n MessageRole,\n CreatePromptOptions,\n UpdatePromptOptions,\n Trace,\n TraceListItem,\n TraceStatus,\n ListTracesOptions,\n ListTracesResult,\n} from './types'\nexport { TraciaErrorCode } from './types'\n\nconst DEFAULT_BASE_URL = 'https://app.tracia.io'\n\nexport class Tracia {\n private readonly client: HttpClient\n readonly prompts: Prompts\n readonly traces: Traces\n\n constructor(options: TraciaOptions) {\n if (!options.apiKey) {\n throw new Error('apiKey is required')\n }\n\n this.client = new HttpClient({\n apiKey: options.apiKey,\n baseUrl: DEFAULT_BASE_URL,\n })\n\n this.prompts = new Prompts(this.client)\n this.traces = new Traces(this.client)\n }\n}\n"],"mappings":";AAEO,IAAM,cAAN,MAAM,qBAAoB,MAAM;AAAA,EAIrC,YAAY,MAAuB,SAAiB,YAAqB;AACvE,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,aAAa;AAElB,WAAO,eAAe,MAAM,aAAY,SAAS;AAAA,EACnD;AACF;;;ACgBO,IAAK,kBAAL,kBAAKA,qBAAL;AACL,EAAAA,iBAAA,kBAAe;AACf,EAAAA,iBAAA,eAAY;AACZ,EAAAA,iBAAA,cAAW;AACX,EAAAA,iBAAA,0BAAuB;AACvB,EAAAA,iBAAA,oBAAiB;AACjB,EAAAA,iBAAA,uBAAoB;AACpB,EAAAA,iBAAA,qBAAkB;AAClB,EAAAA,iBAAA,mBAAgB;AAChB,EAA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S;AAAA,IACX,CAAC;AAED,SAAK,UAAU,IAAI,QAAQ,KAAK,MAAM;AACtC,SAAK,SAAS,IAAI,OAAO,KAAK,MAAM;AAAA,EACtC;AACF;","names":["TraciaErrorCode"]}
|
package/package.json
CHANGED
|
@@ -1,9 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tracia",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "index.
|
|
6
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "TypeScript/JavaScript SDK for Tracia - store, test, and trace LLM prompts",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.cts",
|
|
16
|
+
"default": "./dist/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"dev": "tsup --watch",
|
|
25
|
+
"build": "tsup",
|
|
26
|
+
"test": "vitest run --coverage",
|
|
27
|
+
"test:watch": "vitest",
|
|
28
|
+
"lint": "eslint src tests",
|
|
29
|
+
"typecheck": "tsc --noEmit",
|
|
30
|
+
"prepublishOnly": "npm run build"
|
|
31
|
+
},
|
|
7
32
|
"keywords": [
|
|
8
33
|
"llm",
|
|
9
34
|
"prompt",
|
|
@@ -21,10 +46,22 @@
|
|
|
21
46
|
"license": "MIT",
|
|
22
47
|
"repository": {
|
|
23
48
|
"type": "git",
|
|
24
|
-
"url": "https://github.com/tracia/tracia-node"
|
|
49
|
+
"url": "https://github.com/tracia-io/tracia-node"
|
|
25
50
|
},
|
|
26
51
|
"homepage": "https://tracia.io",
|
|
27
52
|
"bugs": {
|
|
28
|
-
"url": "https://github.com/tracia/tracia-node/issues"
|
|
53
|
+
"url": "https://github.com/tracia-io/tracia-node/issues"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@types/node": "^20.10.0",
|
|
57
|
+
"@typescript-eslint/eslint-plugin": "^6.13.0",
|
|
58
|
+
"@typescript-eslint/parser": "^6.13.0",
|
|
59
|
+
"eslint": "^8.55.0",
|
|
60
|
+
"tsup": "^8.0.0",
|
|
61
|
+
"typescript": "^5.3.0",
|
|
62
|
+
"vitest": "^1.0.0"
|
|
63
|
+
},
|
|
64
|
+
"engines": {
|
|
65
|
+
"node": ">=18.0.0"
|
|
29
66
|
}
|
|
30
67
|
}
|
package/.idea/misc.xml
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="Black">
|
|
4
|
-
<option name="sdkName" value="Python 3.8" />
|
|
5
|
-
</component>
|
|
6
|
-
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
|
|
7
|
-
</project>
|
package/.idea/modules.xml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ProjectModuleManager">
|
|
4
|
-
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/tracia-node.iml" filepath="$PROJECT_DIR$/.idea/tracia-node.iml" />
|
|
6
|
-
</modules>
|
|
7
|
-
</component>
|
|
8
|
-
</project>
|
package/.idea/tracia-node.iml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="PYTHON_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager">
|
|
4
|
-
<content url="file://$MODULE_DIR$" />
|
|
5
|
-
<orderEntry type="jdk" jdkName="Python 3.8" jdkType="Python SDK" />
|
|
6
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
7
|
-
</component>
|
|
8
|
-
</module>
|
package/index.d.ts
DELETED