teckel-ai 0.3.6 → 0.5.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/README.md +15 -38
- package/dist/index.d.mts +241 -226
- package/dist/index.d.ts +241 -226
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +11 -5
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {z}from'zod';var
|
|
2
|
-
export{u as
|
|
1
|
+
import {z,ZodError}from'zod';var c={METADATA_MAX_BYTES:1e4,TRACE_MAX_BYTES:3e6,MAX_DOCUMENTS:15},u=z.object({id:z.string().min(1,"id is required").max(500),name:z.string().min(1,"name is required").max(500),text:z.string().min(1,"text is required").max(5e4),lastUpdated:z.string().datetime({offset:true}).optional(),url:z.string().max(2e3).optional(),source:z.string().max(100).optional(),fileFormat:z.string().max(100).optional(),similarity:z.number().min(0).max(1).optional(),rank:z.number().int().nonnegative().optional(),ownerEmail:z.string().email().max(254).optional()}),g=z.object({prompt:z.number().int().nonnegative(),completion:z.number().int().nonnegative(),total:z.number().int().nonnegative()}),m=z.object({query:z.string().min(1,"query is required").max(1e4,"query too long (max 10,000 chars)"),response:z.string().min(1,"response is required").max(5e4,"response too long (max 50,000 chars)"),model:z.string().max(100).optional(),latencyMs:z.number().int().nonnegative().max(6e5).optional(),tokens:g.optional(),documents:z.array(u).max(c.MAX_DOCUMENTS,`Too many documents (max ${c.MAX_DOCUMENTS})`).optional(),sessionId:z.string().min(1).max(200,"sessionId must be 200 chars or less").optional(),userId:z.string().min(1).max(255).optional(),traceId:z.string().uuid("traceId must be a valid UUID").optional(),systemPrompt:z.string().max(5e4,"systemPrompt too long (max 50,000 chars)").optional(),metadata:z.record(z.string(),z.unknown()).optional().refine(r=>!r||JSON.stringify(r).length<=c.METADATA_MAX_BYTES,`metadata exceeds ${c.METADATA_MAX_BYTES/1e3}KB limit`)}).superRefine((r,i)=>{JSON.stringify(r).length>c.TRACE_MAX_BYTES&&i.addIssue({code:z.ZodIssueCode.custom,message:`trace payload exceeds ${c.TRACE_MAX_BYTES/1e6}MB limit`,path:[]});}),d=z.object({traceId:z.string().uuid("traceId must be a valid UUID").optional(),sessionId:z.string().min(1).max(200,"sessionId must be 200 chars or less").optional(),type:z.enum(["thumbs_up","thumbs_down","flag","rating"]),value:z.string().min(1).max(10).optional(),comment:z.string().max(2e3).optional()}).refine(r=>r.traceId||r.sessionId,{message:"Either traceId or sessionId is required"}),l=z.object({apiKey:z.string().min(1,"apiKey is required"),endpoint:z.string().url().optional(),debug:z.boolean().optional(),timeoutMs:z.number().int().positive().max(6e4).optional()});var p=class{constructor(i){this.sendQueue=Promise.resolve();let e=l.parse(i);if(!e.apiKey.startsWith("tk_live_")){let o=e.apiKey.startsWith("tk_")?"tk_***":"invalid prefix";console.error(`[Teckel] Invalid API key format. Expected "tk_live_***", got "${o}". Get your key at https://app.teckel.ai/settings/api-keys`);}this.apiKey=e.apiKey,this.endpoint=e.endpoint||"https://app.teckel.ai/api",this.debug=e.debug||false,this.timeoutMs=e.timeoutMs??5e3,this.debug&&console.log("[Teckel] Initialized",{endpoint:this.endpoint,timeoutMs:this.timeoutMs});}trace(i){try{let e=m.parse(i);this.debug&&console.log("[Teckel] Queueing trace:",{traceId:e.traceId,sessionId:e.sessionId,queryLength:e.query.length,documentCount:e.documents?.length||0}),this.enqueue(()=>this.send("/sdk/traces",e),"trace");}catch(e){this.logValidationError("Trace",e);}}feedback(i){try{let e=d.parse(i);this.debug&&console.log("[Teckel] Sending feedback:",{type:e.type,traceId:e.traceId}),this.enqueue(()=>this.send("/sdk/feedback",e),"feedback");}catch(e){this.logValidationError("Feedback",e);}}async flush(i){let e=i??this.timeoutMs,o=this.sendQueue.catch(()=>{}),n;try{await Promise.race([o,new Promise((a,s)=>{n=setTimeout(()=>s(new Error("Flush timeout")),e);})]);}catch(a){throw this.debug&&console.warn("[Teckel] Flush incomplete:",a.message),a}finally{n&&clearTimeout(n);}}async send(i,e){let o=`${this.endpoint}${i}`,n=await this.fetchWithRetry(o,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},keepalive:true,signal:AbortSignal.timeout?.(this.timeoutMs),body:JSON.stringify(e)});if(!n.ok)throw this.logHttpError(i,n.status),new Error(`HTTP ${n.status}`);return n.json()}async fetchWithRetry(i,e){let n=()=>new Promise(a=>setTimeout(a,250+Math.random()*100));for(let a=1;a<=2;a++)try{let s=await fetch(i,e);if(s.ok||a===2)return s;if(s.status===429||s.status>=500){this.debug&&console.warn("[Teckel] Retrying",{status:s.status,attempt:a}),await n();continue}return s}catch(s){if(a===2)throw s;this.debug&&console.warn("[Teckel] Retry after error",{attempt:a}),await n();}throw new Error("Unreachable")}enqueue(i,e){this.sendQueue=this.sendQueue.then(()=>i()).catch(o=>{if(!(o instanceof Error&&o.message.startsWith("HTTP "))){let n=o instanceof Error?o.message:String(o);n.includes("timeout")||n.includes("abort")?console.warn(`[Teckel] ${e} timed out. Consider increasing timeoutMs.`):console.warn(`[Teckel] ${e} failed: ${n}`);}});}logValidationError(i,e){if(e instanceof ZodError){let o=e.errors.map(n=>n.path.length?`${n.path.join(".")}: ${n.message}`:n.message).join("; ");console.error(`[Teckel] ${i} dropped - validation failed: ${o}`);}else this.debug&&console.error(`[Teckel] ${i} dropped:`,e);}logHttpError(i,e){let o=i.includes("trace")?"Trace":"Feedback",a={401:`${o} failed - invalid API key. Check https://app.teckel.ai/settings/api-keys`,400:`${o} failed - invalid request. Enable debug mode for details.`,404:`${o} failed - endpoint not found. Check your configuration.`,429:`${o} dropped - rate limit exceeded.`}[e]||(e>=500?`${o} dropped - server error (${e})`:`${o} failed - HTTP ${e}`);e>=500||e===429?console.warn(`[Teckel] ${a}`):console.error(`[Teckel] ${a}`);}};
|
|
2
|
+
export{u as DocumentSchema,d as FeedbackDataSchema,c as TRACE_SIZE_LIMITS,l as TeckelConfigSchema,p as TeckelTracer,g as TokenUsageSchema,m as TraceDataSchema};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "teckel-ai",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Simple SDK for AI
|
|
3
|
+
"version": "0.5.1",
|
|
4
|
+
"description": "Simple SDK for AI trace tracking and RAG observability",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -25,7 +25,10 @@
|
|
|
25
25
|
"build": "tsup",
|
|
26
26
|
"clean": "rm -rf dist",
|
|
27
27
|
"prepublishOnly": "npm run clean && npm run build",
|
|
28
|
-
"type-check": "tsc --noEmit"
|
|
28
|
+
"type-check": "tsc --noEmit",
|
|
29
|
+
"test": "vitest run --exclude tests/integration.test.ts",
|
|
30
|
+
"test:watch": "vitest --exclude tests/integration.test.ts",
|
|
31
|
+
"test:integration": "vitest run tests/integration.test.ts"
|
|
29
32
|
},
|
|
30
33
|
"keywords": [
|
|
31
34
|
"llm",
|
|
@@ -47,8 +50,11 @@
|
|
|
47
50
|
"zod": "^3.23.8"
|
|
48
51
|
},
|
|
49
52
|
"devDependencies": {
|
|
50
|
-
"
|
|
51
|
-
"
|
|
53
|
+
"cac": "^6.7.14",
|
|
54
|
+
"joycon": "^3.1.1",
|
|
55
|
+
"tsup": "^8.5.1",
|
|
56
|
+
"typescript": "^5.0.0",
|
|
57
|
+
"vitest": "^2.1.0"
|
|
52
58
|
},
|
|
53
59
|
"homepage": "https://teckel.ai",
|
|
54
60
|
"bugs": {
|