teckel-ai 0.3.5 → 0.3.6
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 +3 -3
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -48,13 +48,13 @@ async function handleChat(userQuestion: string, sessionId: string) {
|
|
|
48
48
|
|
|
49
49
|
## Documentation
|
|
50
50
|
|
|
51
|
-
- **Full SDK Reference:** [docs.teckel.ai/
|
|
52
|
-
- **Getting Started:** [docs.teckel.ai/
|
|
51
|
+
- **Full SDK Reference:** [docs.teckel.ai/typescript-sdk-reference](https://docs.teckel.ai/typescript-sdk-reference)
|
|
52
|
+
- **Getting Started:** [docs.teckel.ai/getting-started](https://docs.teckel.ai/getting-started)
|
|
53
53
|
|
|
54
54
|
## Support
|
|
55
55
|
|
|
56
56
|
- **Email:** support@teckel.ai
|
|
57
|
-
- **Website
|
|
57
|
+
- **Website:** [teckel.ai](https://teckel.ai)
|
|
58
58
|
|
|
59
59
|
## License
|
|
60
60
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Type definitions for teckel-ai SDK v0.3.
|
|
4
|
+
* Type definitions for teckel-ai SDK v0.3.6
|
|
5
5
|
* Simple, clean types matching existing database schema
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
@@ -87,7 +87,7 @@ interface TraceResult {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
|
-
* Conversation class for teckel-ai SDK v0.3.
|
|
90
|
+
* Conversation class for teckel-ai SDK v0.3.6
|
|
91
91
|
* Manages a single conversation with fire-and-forget semantics
|
|
92
92
|
*/
|
|
93
93
|
|
|
@@ -147,7 +147,7 @@ declare class Conversation {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
/**
|
|
150
|
-
* TeckelTracer - Main SDK class for teckel-ai v0.3.
|
|
150
|
+
* TeckelTracer - Main SDK class for teckel-ai v0.3.6
|
|
151
151
|
* Simple, lightweight SDK for AI conversation tracking
|
|
152
152
|
*/
|
|
153
153
|
|
|
@@ -166,7 +166,7 @@ declare class TeckelTracer {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
/**
|
|
169
|
-
* Zod validation schemas for teckel-ai SDK v0.3.
|
|
169
|
+
* Zod validation schemas for teckel-ai SDK v0.3.6
|
|
170
170
|
*/
|
|
171
171
|
|
|
172
172
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Type definitions for teckel-ai SDK v0.3.
|
|
4
|
+
* Type definitions for teckel-ai SDK v0.3.6
|
|
5
5
|
* Simple, clean types matching existing database schema
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
@@ -87,7 +87,7 @@ interface TraceResult {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
|
-
* Conversation class for teckel-ai SDK v0.3.
|
|
90
|
+
* Conversation class for teckel-ai SDK v0.3.6
|
|
91
91
|
* Manages a single conversation with fire-and-forget semantics
|
|
92
92
|
*/
|
|
93
93
|
|
|
@@ -147,7 +147,7 @@ declare class Conversation {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
/**
|
|
150
|
-
* TeckelTracer - Main SDK class for teckel-ai v0.3.
|
|
150
|
+
* TeckelTracer - Main SDK class for teckel-ai v0.3.6
|
|
151
151
|
* Simple, lightweight SDK for AI conversation tracking
|
|
152
152
|
*/
|
|
153
153
|
|
|
@@ -166,7 +166,7 @@ declare class TeckelTracer {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
/**
|
|
169
|
-
* Zod validation schemas for teckel-ai SDK v0.3.
|
|
169
|
+
* Zod validation schemas for teckel-ai SDK v0.3.6
|
|
170
170
|
*/
|
|
171
171
|
|
|
172
172
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var zod=require('zod');var y=zod.z.object({documentRef:zod.z.string().min(1,"documentRef is required"),documentName:zod.z.string().min(1,"documentName is required"),documentText:zod.z.string().min(1,"documentText is required"),documentLastUpdated:zod.z.string().optional(),sourceUri:zod.z.string().optional(),sourceType:zod.z.string().optional(),similarity:zod.z.number().min(0).max(1).optional(),rank:zod.z.number().int().nonnegative().optional(),ownerEmail:zod.z.string().email().optional(),documentType:zod.z.string().optional()}),b=zod.z.object({prompt:zod.z.number().int().nonnegative(),completion:zod.z.number().int().nonnegative(),total:zod.z.number().int().nonnegative()}),l=zod.z.object({query:zod.z.string().min(1,"query is required").max(1e4,"query too long (max 10,000 characters)"),response:zod.z.string().min(1,"response is required").max(5e4,"response too long (max 50,000 characters)"),model:zod.z.string().optional(),responseTimeMs:zod.z.number().nonnegative().optional(),documents:zod.z.array(y).max(50,"Too many documents (max 50)").optional(),tokens:b.optional(),metadata:zod.z.record(zod.z.string(),zod.z.unknown()).optional(),traceRef:zod.z.string().min(1).optional(),userRef:zod.z.string().min(1).optional()}),h=zod.z.object({sessionRef:zod.z.string().min(1).optional(),userRef:zod.z.string().optional(),metadata:zod.z.record(zod.z.string(),zod.z.unknown()).optional()}),p=zod.z.object({type:zod.z.enum(["thumbs_up","thumbs_down","flag","rating"]),value:zod.z.string().optional(),comment:zod.z.string().optional(),traceRef:zod.z.string().optional()}),f=zod.z.object({apiKey:zod.z.string().min(1,"apiKey is required"),endpoint:zod.z.string().url().optional(),debug:zod.z.boolean().optional(),timeoutMs:zod.z.number().int().positive().max(6e4).optional()});var u=class{constructor(n,e,s,o=false,a={timeoutMs:5e3}){this.turnCount=0;this.sendQueue=Promise.resolve();this.apiKey=n,this.endpoint=e,this.sessionRef=s.sessionRef,this.userRef=s.userRef,this.metadata=s.metadata,this.startedAt=new Date,this.debug=o,this.timeoutMs=a.timeoutMs,this.debug&&console.log("[Teckel] Conversation started:",{sessionRef:this.sessionRef,userRef:this.userRef}),this.startPromise=this._startConversation().catch(i=>{this.debug&&console.warn("[Teckel] Start failed:",i.message);});}trace(n){try{let e=l.parse(n),s=++this.turnCount,o=e.traceRef&&e.traceRef.length>0?e.traceRef:`${this.sessionRef}:${s}`;this.debug&&console.log("[Teckel] Queueing trace:",{sessionRef:this.sessionRef,turnNumber:s,queryLength:e.query.length,responseLength:e.response.length,documentCount:e.documents?.length||0});let a={...e,traceRef:o,userRef:e.userRef||this.userRef};return this.enqueueSend(async()=>{try{await this.startPromise,await this._sendTrace(a);}catch(i){if(this.debug){let d=i instanceof Error?i.message:String(i);console.warn("[Teckel] Trace send failed (non-blocking):",d);}}}),{traceRef:o,turnNumber:s}}catch(e){this.debug&&console.warn("[Teckel] Invalid trace data:",e);}}async feedback(n){try{let e=p.parse(n);this.debug&&console.log("[Teckel] Sending feedback:",{sessionRef:this.sessionRef,type:e.type}),this.enqueueSend(async()=>{try{await this._sendFeedback(e);}catch(s){if(this.debug){let o=s instanceof Error?s.message:String(s);console.warn("[Teckel] Feedback failed:",o);}}});}catch(e){this.debug&&console.warn("[Teckel] Invalid feedback data:",e);}}async end(){let n=Date.now()-this.startedAt.getTime();this.debug&&console.log("[Teckel] Ending conversation:",{sessionRef:this.sessionRef,durationMs:n,turnCount:this.turnCount}),this.enqueueSend(async()=>{try{await this._endConversation(n);}catch(e){if(this.debug){let s=e instanceof Error?e.message:String(e);console.warn("[Teckel] End failed:",s);}}}),await this.flush();}get id(){return this.sessionRef}get turns(){return this.turnCount}get started(){return this.startedAt}async fetchWithRetry(n,e,s){let o=s?.retries??1,a=s?.retryDelayMs??250,i=0,d=r=>new Promise(T=>setTimeout(T,r));for(;;)try{let r=await fetch(n,e);if(!r.ok&&(r.status===429||r.status>=500&&r.status<=599)&&i<o){i++,this.debug&&console.warn("[Teckel] HTTP retry",{url:n,status:r.status,attempt:i}),await d(a+Math.floor(Math.random()*100));continue}return r}catch(r){if(i<o){i++,this.debug&&console.warn("[Teckel] Network retry",{url:n,attempt:i,error:r instanceof Error?r.message:String(r)}),await d(a+Math.floor(Math.random()*100));continue}throw r}}async _startConversation(){let n=await this.fetchWithRetry(`${this.endpoint}/conversations`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},keepalive:true,signal:m(this.timeoutMs),body:JSON.stringify({sessionRef:this.sessionRef,userRef:this.userRef,metadata:this.metadata})},{retries:1,retryDelayMs:300});if(!n.ok)throw new Error(`HTTP ${n.status}: ${n.statusText}`)}async _sendTrace(n,e){let s=await this.fetchWithRetry(`${this.endpoint}/conversations/${this.sessionRef}/traces`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},keepalive:true,signal:m(e?.timeoutMs??this.timeoutMs),body:JSON.stringify(n)},{retries:1,retryDelayMs:300});if(!s.ok)throw new Error(`HTTP ${s.status}: ${s.statusText}`);return await s.json()}async _sendFeedback(n){let e=await this.fetchWithRetry(`${this.endpoint}/conversations/${this.sessionRef}/feedback`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},keepalive:true,signal:m(this.timeoutMs),body:JSON.stringify(n)},{retries:1,retryDelayMs:300});if(!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`)}async _endConversation(n){let e=await this.fetchWithRetry(`${this.endpoint}/conversations/${this.sessionRef}`,{method:"PATCH",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},keepalive:true,signal:m(this.timeoutMs),body:JSON.stringify({durationMs:n,turnCount:this.turnCount})},{retries:1,retryDelayMs:300});if(!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`)}enqueueSend(n){this.sendQueue=this.sendQueue.then(()=>n()).catch(()=>{});}async flush(n){let e=typeof n=="number"&&Number.isFinite(n)&&n>=0?n:this.timeoutMs,s=this.sendQueue.catch(()=>{}),o;try{await Promise.race([s,new Promise((a,i)=>{o=setTimeout(()=>i(new Error("Flush timeout")),e);})]);}catch(a){if(this.debug){let i=a instanceof Error?a.message:String(a);console.warn("[Teckel] Flush incomplete:",i);}throw a}finally{o&&clearTimeout(o);}}};function m(c){if(!(typeof c!="number"||c<=0)&&typeof AbortSignal.timeout=="function")return AbortSignal.timeout(c)}var g=class{constructor(n){let e=f.parse(n);e.apiKey.startsWith("tk_live_")||console.warn('[Teckel] API key should start with "tk_live_". Current key: '+e.apiKey.substring(0,10)+"..."),this.apiKey=e.apiKey,this.endpoint=e.endpoint||"https://app.teckel.ai/api",this.debug=e.debug||false,this.timeoutMs=typeof e.timeoutMs=="number"?e.timeoutMs:5e3,this.debug&&console.log("[Teckel] SDK initialized:",{endpoint:this.endpoint,version:"0.3.
|
|
1
|
+
'use strict';var zod=require('zod');var y=zod.z.object({documentRef:zod.z.string().min(1,"documentRef is required"),documentName:zod.z.string().min(1,"documentName is required"),documentText:zod.z.string().min(1,"documentText is required"),documentLastUpdated:zod.z.string().optional(),sourceUri:zod.z.string().optional(),sourceType:zod.z.string().optional(),similarity:zod.z.number().min(0).max(1).optional(),rank:zod.z.number().int().nonnegative().optional(),ownerEmail:zod.z.string().email().optional(),documentType:zod.z.string().optional()}),b=zod.z.object({prompt:zod.z.number().int().nonnegative(),completion:zod.z.number().int().nonnegative(),total:zod.z.number().int().nonnegative()}),l=zod.z.object({query:zod.z.string().min(1,"query is required").max(1e4,"query too long (max 10,000 characters)"),response:zod.z.string().min(1,"response is required").max(5e4,"response too long (max 50,000 characters)"),model:zod.z.string().optional(),responseTimeMs:zod.z.number().nonnegative().optional(),documents:zod.z.array(y).max(50,"Too many documents (max 50)").optional(),tokens:b.optional(),metadata:zod.z.record(zod.z.string(),zod.z.unknown()).optional(),traceRef:zod.z.string().min(1).optional(),userRef:zod.z.string().min(1).optional()}),h=zod.z.object({sessionRef:zod.z.string().min(1).optional(),userRef:zod.z.string().optional(),metadata:zod.z.record(zod.z.string(),zod.z.unknown()).optional()}),p=zod.z.object({type:zod.z.enum(["thumbs_up","thumbs_down","flag","rating"]),value:zod.z.string().optional(),comment:zod.z.string().optional(),traceRef:zod.z.string().optional()}),f=zod.z.object({apiKey:zod.z.string().min(1,"apiKey is required"),endpoint:zod.z.string().url().optional(),debug:zod.z.boolean().optional(),timeoutMs:zod.z.number().int().positive().max(6e4).optional()});var u=class{constructor(n,e,s,o=false,a={timeoutMs:5e3}){this.turnCount=0;this.sendQueue=Promise.resolve();this.apiKey=n,this.endpoint=e,this.sessionRef=s.sessionRef,this.userRef=s.userRef,this.metadata=s.metadata,this.startedAt=new Date,this.debug=o,this.timeoutMs=a.timeoutMs,this.debug&&console.log("[Teckel] Conversation started:",{sessionRef:this.sessionRef,userRef:this.userRef}),this.startPromise=this._startConversation().catch(i=>{this.debug&&console.warn("[Teckel] Start failed:",i.message);});}trace(n){try{let e=l.parse(n),s=++this.turnCount,o=e.traceRef&&e.traceRef.length>0?e.traceRef:`${this.sessionRef}:${s}`;this.debug&&console.log("[Teckel] Queueing trace:",{sessionRef:this.sessionRef,turnNumber:s,queryLength:e.query.length,responseLength:e.response.length,documentCount:e.documents?.length||0});let a={...e,traceRef:o,userRef:e.userRef||this.userRef};return this.enqueueSend(async()=>{try{await this.startPromise,await this._sendTrace(a);}catch(i){if(this.debug){let d=i instanceof Error?i.message:String(i);console.warn("[Teckel] Trace send failed (non-blocking):",d);}}}),{traceRef:o,turnNumber:s}}catch(e){this.debug&&console.warn("[Teckel] Invalid trace data:",e);}}async feedback(n){try{let e=p.parse(n);this.debug&&console.log("[Teckel] Sending feedback:",{sessionRef:this.sessionRef,type:e.type}),this.enqueueSend(async()=>{try{await this._sendFeedback(e);}catch(s){if(this.debug){let o=s instanceof Error?s.message:String(s);console.warn("[Teckel] Feedback failed:",o);}}});}catch(e){this.debug&&console.warn("[Teckel] Invalid feedback data:",e);}}async end(){let n=Date.now()-this.startedAt.getTime();this.debug&&console.log("[Teckel] Ending conversation:",{sessionRef:this.sessionRef,durationMs:n,turnCount:this.turnCount}),this.enqueueSend(async()=>{try{await this._endConversation(n);}catch(e){if(this.debug){let s=e instanceof Error?e.message:String(e);console.warn("[Teckel] End failed:",s);}}}),await this.flush();}get id(){return this.sessionRef}get turns(){return this.turnCount}get started(){return this.startedAt}async fetchWithRetry(n,e,s){let o=s?.retries??1,a=s?.retryDelayMs??250,i=0,d=r=>new Promise(T=>setTimeout(T,r));for(;;)try{let r=await fetch(n,e);if(!r.ok&&(r.status===429||r.status>=500&&r.status<=599)&&i<o){i++,this.debug&&console.warn("[Teckel] HTTP retry",{url:n,status:r.status,attempt:i}),await d(a+Math.floor(Math.random()*100));continue}return r}catch(r){if(i<o){i++,this.debug&&console.warn("[Teckel] Network retry",{url:n,attempt:i,error:r instanceof Error?r.message:String(r)}),await d(a+Math.floor(Math.random()*100));continue}throw r}}async _startConversation(){let n=await this.fetchWithRetry(`${this.endpoint}/conversations`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},keepalive:true,signal:m(this.timeoutMs),body:JSON.stringify({sessionRef:this.sessionRef,userRef:this.userRef,metadata:this.metadata})},{retries:1,retryDelayMs:300});if(!n.ok)throw new Error(`HTTP ${n.status}: ${n.statusText}`)}async _sendTrace(n,e){let s=await this.fetchWithRetry(`${this.endpoint}/conversations/${this.sessionRef}/traces`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},keepalive:true,signal:m(e?.timeoutMs??this.timeoutMs),body:JSON.stringify(n)},{retries:1,retryDelayMs:300});if(!s.ok)throw new Error(`HTTP ${s.status}: ${s.statusText}`);return await s.json()}async _sendFeedback(n){let e=await this.fetchWithRetry(`${this.endpoint}/conversations/${this.sessionRef}/feedback`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},keepalive:true,signal:m(this.timeoutMs),body:JSON.stringify(n)},{retries:1,retryDelayMs:300});if(!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`)}async _endConversation(n){let e=await this.fetchWithRetry(`${this.endpoint}/conversations/${this.sessionRef}`,{method:"PATCH",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},keepalive:true,signal:m(this.timeoutMs),body:JSON.stringify({durationMs:n,turnCount:this.turnCount})},{retries:1,retryDelayMs:300});if(!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`)}enqueueSend(n){this.sendQueue=this.sendQueue.then(()=>n()).catch(()=>{});}async flush(n){let e=typeof n=="number"&&Number.isFinite(n)&&n>=0?n:this.timeoutMs,s=this.sendQueue.catch(()=>{}),o;try{await Promise.race([s,new Promise((a,i)=>{o=setTimeout(()=>i(new Error("Flush timeout")),e);})]);}catch(a){if(this.debug){let i=a instanceof Error?a.message:String(a);console.warn("[Teckel] Flush incomplete:",i);}throw a}finally{o&&clearTimeout(o);}}};function m(c){if(!(typeof c!="number"||c<=0)&&typeof AbortSignal.timeout=="function")return AbortSignal.timeout(c)}var g=class{constructor(n){let e=f.parse(n);e.apiKey.startsWith("tk_live_")||console.warn('[Teckel] API key should start with "tk_live_". Current key: '+e.apiKey.substring(0,10)+"..."),this.apiKey=e.apiKey,this.endpoint=e.endpoint||"https://app.teckel.ai/api",this.debug=e.debug||false,this.timeoutMs=typeof e.timeoutMs=="number"?e.timeoutMs:5e3,this.debug&&console.log("[Teckel] SDK initialized:",{endpoint:this.endpoint,version:"0.3.6",timeoutMs:this.timeoutMs});}start(n={}){let e=h.parse(n),s=e.sessionRef||`auto:${crypto.randomUUID().slice(0,8)}`;return new u(this.apiKey,this.endpoint,{...e,sessionRef:s},this.debug,{timeoutMs:this.timeoutMs})}};
|
|
2
2
|
exports.Conversation=u;exports.ConversationOptionsSchema=h;exports.DocumentSchema=y;exports.FeedbackDataSchema=p;exports.TeckelConfigSchema=f;exports.TeckelTracer=g;exports.TokenUsageSchema=b;exports.TraceDataSchema=l;
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {z}from'zod';var y=z.object({documentRef:z.string().min(1,"documentRef is required"),documentName:z.string().min(1,"documentName is required"),documentText:z.string().min(1,"documentText is required"),documentLastUpdated:z.string().optional(),sourceUri:z.string().optional(),sourceType:z.string().optional(),similarity:z.number().min(0).max(1).optional(),rank:z.number().int().nonnegative().optional(),ownerEmail:z.string().email().optional(),documentType:z.string().optional()}),b=z.object({prompt:z.number().int().nonnegative(),completion:z.number().int().nonnegative(),total:z.number().int().nonnegative()}),l=z.object({query:z.string().min(1,"query is required").max(1e4,"query too long (max 10,000 characters)"),response:z.string().min(1,"response is required").max(5e4,"response too long (max 50,000 characters)"),model:z.string().optional(),responseTimeMs:z.number().nonnegative().optional(),documents:z.array(y).max(50,"Too many documents (max 50)").optional(),tokens:b.optional(),metadata:z.record(z.string(),z.unknown()).optional(),traceRef:z.string().min(1).optional(),userRef:z.string().min(1).optional()}),h=z.object({sessionRef:z.string().min(1).optional(),userRef:z.string().optional(),metadata:z.record(z.string(),z.unknown()).optional()}),p=z.object({type:z.enum(["thumbs_up","thumbs_down","flag","rating"]),value:z.string().optional(),comment:z.string().optional(),traceRef:z.string().optional()}),f=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 u=class{constructor(n,e,s,o=false,a={timeoutMs:5e3}){this.turnCount=0;this.sendQueue=Promise.resolve();this.apiKey=n,this.endpoint=e,this.sessionRef=s.sessionRef,this.userRef=s.userRef,this.metadata=s.metadata,this.startedAt=new Date,this.debug=o,this.timeoutMs=a.timeoutMs,this.debug&&console.log("[Teckel] Conversation started:",{sessionRef:this.sessionRef,userRef:this.userRef}),this.startPromise=this._startConversation().catch(i=>{this.debug&&console.warn("[Teckel] Start failed:",i.message);});}trace(n){try{let e=l.parse(n),s=++this.turnCount,o=e.traceRef&&e.traceRef.length>0?e.traceRef:`${this.sessionRef}:${s}`;this.debug&&console.log("[Teckel] Queueing trace:",{sessionRef:this.sessionRef,turnNumber:s,queryLength:e.query.length,responseLength:e.response.length,documentCount:e.documents?.length||0});let a={...e,traceRef:o,userRef:e.userRef||this.userRef};return this.enqueueSend(async()=>{try{await this.startPromise,await this._sendTrace(a);}catch(i){if(this.debug){let d=i instanceof Error?i.message:String(i);console.warn("[Teckel] Trace send failed (non-blocking):",d);}}}),{traceRef:o,turnNumber:s}}catch(e){this.debug&&console.warn("[Teckel] Invalid trace data:",e);}}async feedback(n){try{let e=p.parse(n);this.debug&&console.log("[Teckel] Sending feedback:",{sessionRef:this.sessionRef,type:e.type}),this.enqueueSend(async()=>{try{await this._sendFeedback(e);}catch(s){if(this.debug){let o=s instanceof Error?s.message:String(s);console.warn("[Teckel] Feedback failed:",o);}}});}catch(e){this.debug&&console.warn("[Teckel] Invalid feedback data:",e);}}async end(){let n=Date.now()-this.startedAt.getTime();this.debug&&console.log("[Teckel] Ending conversation:",{sessionRef:this.sessionRef,durationMs:n,turnCount:this.turnCount}),this.enqueueSend(async()=>{try{await this._endConversation(n);}catch(e){if(this.debug){let s=e instanceof Error?e.message:String(e);console.warn("[Teckel] End failed:",s);}}}),await this.flush();}get id(){return this.sessionRef}get turns(){return this.turnCount}get started(){return this.startedAt}async fetchWithRetry(n,e,s){let o=s?.retries??1,a=s?.retryDelayMs??250,i=0,d=r=>new Promise(T=>setTimeout(T,r));for(;;)try{let r=await fetch(n,e);if(!r.ok&&(r.status===429||r.status>=500&&r.status<=599)&&i<o){i++,this.debug&&console.warn("[Teckel] HTTP retry",{url:n,status:r.status,attempt:i}),await d(a+Math.floor(Math.random()*100));continue}return r}catch(r){if(i<o){i++,this.debug&&console.warn("[Teckel] Network retry",{url:n,attempt:i,error:r instanceof Error?r.message:String(r)}),await d(a+Math.floor(Math.random()*100));continue}throw r}}async _startConversation(){let n=await this.fetchWithRetry(`${this.endpoint}/conversations`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},keepalive:true,signal:m(this.timeoutMs),body:JSON.stringify({sessionRef:this.sessionRef,userRef:this.userRef,metadata:this.metadata})},{retries:1,retryDelayMs:300});if(!n.ok)throw new Error(`HTTP ${n.status}: ${n.statusText}`)}async _sendTrace(n,e){let s=await this.fetchWithRetry(`${this.endpoint}/conversations/${this.sessionRef}/traces`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},keepalive:true,signal:m(e?.timeoutMs??this.timeoutMs),body:JSON.stringify(n)},{retries:1,retryDelayMs:300});if(!s.ok)throw new Error(`HTTP ${s.status}: ${s.statusText}`);return await s.json()}async _sendFeedback(n){let e=await this.fetchWithRetry(`${this.endpoint}/conversations/${this.sessionRef}/feedback`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},keepalive:true,signal:m(this.timeoutMs),body:JSON.stringify(n)},{retries:1,retryDelayMs:300});if(!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`)}async _endConversation(n){let e=await this.fetchWithRetry(`${this.endpoint}/conversations/${this.sessionRef}`,{method:"PATCH",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},keepalive:true,signal:m(this.timeoutMs),body:JSON.stringify({durationMs:n,turnCount:this.turnCount})},{retries:1,retryDelayMs:300});if(!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`)}enqueueSend(n){this.sendQueue=this.sendQueue.then(()=>n()).catch(()=>{});}async flush(n){let e=typeof n=="number"&&Number.isFinite(n)&&n>=0?n:this.timeoutMs,s=this.sendQueue.catch(()=>{}),o;try{await Promise.race([s,new Promise((a,i)=>{o=setTimeout(()=>i(new Error("Flush timeout")),e);})]);}catch(a){if(this.debug){let i=a instanceof Error?a.message:String(a);console.warn("[Teckel] Flush incomplete:",i);}throw a}finally{o&&clearTimeout(o);}}};function m(c){if(!(typeof c!="number"||c<=0)&&typeof AbortSignal.timeout=="function")return AbortSignal.timeout(c)}var g=class{constructor(n){let e=f.parse(n);e.apiKey.startsWith("tk_live_")||console.warn('[Teckel] API key should start with "tk_live_". Current key: '+e.apiKey.substring(0,10)+"..."),this.apiKey=e.apiKey,this.endpoint=e.endpoint||"https://app.teckel.ai/api",this.debug=e.debug||false,this.timeoutMs=typeof e.timeoutMs=="number"?e.timeoutMs:5e3,this.debug&&console.log("[Teckel] SDK initialized:",{endpoint:this.endpoint,version:"0.3.
|
|
1
|
+
import {z}from'zod';var y=z.object({documentRef:z.string().min(1,"documentRef is required"),documentName:z.string().min(1,"documentName is required"),documentText:z.string().min(1,"documentText is required"),documentLastUpdated:z.string().optional(),sourceUri:z.string().optional(),sourceType:z.string().optional(),similarity:z.number().min(0).max(1).optional(),rank:z.number().int().nonnegative().optional(),ownerEmail:z.string().email().optional(),documentType:z.string().optional()}),b=z.object({prompt:z.number().int().nonnegative(),completion:z.number().int().nonnegative(),total:z.number().int().nonnegative()}),l=z.object({query:z.string().min(1,"query is required").max(1e4,"query too long (max 10,000 characters)"),response:z.string().min(1,"response is required").max(5e4,"response too long (max 50,000 characters)"),model:z.string().optional(),responseTimeMs:z.number().nonnegative().optional(),documents:z.array(y).max(50,"Too many documents (max 50)").optional(),tokens:b.optional(),metadata:z.record(z.string(),z.unknown()).optional(),traceRef:z.string().min(1).optional(),userRef:z.string().min(1).optional()}),h=z.object({sessionRef:z.string().min(1).optional(),userRef:z.string().optional(),metadata:z.record(z.string(),z.unknown()).optional()}),p=z.object({type:z.enum(["thumbs_up","thumbs_down","flag","rating"]),value:z.string().optional(),comment:z.string().optional(),traceRef:z.string().optional()}),f=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 u=class{constructor(n,e,s,o=false,a={timeoutMs:5e3}){this.turnCount=0;this.sendQueue=Promise.resolve();this.apiKey=n,this.endpoint=e,this.sessionRef=s.sessionRef,this.userRef=s.userRef,this.metadata=s.metadata,this.startedAt=new Date,this.debug=o,this.timeoutMs=a.timeoutMs,this.debug&&console.log("[Teckel] Conversation started:",{sessionRef:this.sessionRef,userRef:this.userRef}),this.startPromise=this._startConversation().catch(i=>{this.debug&&console.warn("[Teckel] Start failed:",i.message);});}trace(n){try{let e=l.parse(n),s=++this.turnCount,o=e.traceRef&&e.traceRef.length>0?e.traceRef:`${this.sessionRef}:${s}`;this.debug&&console.log("[Teckel] Queueing trace:",{sessionRef:this.sessionRef,turnNumber:s,queryLength:e.query.length,responseLength:e.response.length,documentCount:e.documents?.length||0});let a={...e,traceRef:o,userRef:e.userRef||this.userRef};return this.enqueueSend(async()=>{try{await this.startPromise,await this._sendTrace(a);}catch(i){if(this.debug){let d=i instanceof Error?i.message:String(i);console.warn("[Teckel] Trace send failed (non-blocking):",d);}}}),{traceRef:o,turnNumber:s}}catch(e){this.debug&&console.warn("[Teckel] Invalid trace data:",e);}}async feedback(n){try{let e=p.parse(n);this.debug&&console.log("[Teckel] Sending feedback:",{sessionRef:this.sessionRef,type:e.type}),this.enqueueSend(async()=>{try{await this._sendFeedback(e);}catch(s){if(this.debug){let o=s instanceof Error?s.message:String(s);console.warn("[Teckel] Feedback failed:",o);}}});}catch(e){this.debug&&console.warn("[Teckel] Invalid feedback data:",e);}}async end(){let n=Date.now()-this.startedAt.getTime();this.debug&&console.log("[Teckel] Ending conversation:",{sessionRef:this.sessionRef,durationMs:n,turnCount:this.turnCount}),this.enqueueSend(async()=>{try{await this._endConversation(n);}catch(e){if(this.debug){let s=e instanceof Error?e.message:String(e);console.warn("[Teckel] End failed:",s);}}}),await this.flush();}get id(){return this.sessionRef}get turns(){return this.turnCount}get started(){return this.startedAt}async fetchWithRetry(n,e,s){let o=s?.retries??1,a=s?.retryDelayMs??250,i=0,d=r=>new Promise(T=>setTimeout(T,r));for(;;)try{let r=await fetch(n,e);if(!r.ok&&(r.status===429||r.status>=500&&r.status<=599)&&i<o){i++,this.debug&&console.warn("[Teckel] HTTP retry",{url:n,status:r.status,attempt:i}),await d(a+Math.floor(Math.random()*100));continue}return r}catch(r){if(i<o){i++,this.debug&&console.warn("[Teckel] Network retry",{url:n,attempt:i,error:r instanceof Error?r.message:String(r)}),await d(a+Math.floor(Math.random()*100));continue}throw r}}async _startConversation(){let n=await this.fetchWithRetry(`${this.endpoint}/conversations`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},keepalive:true,signal:m(this.timeoutMs),body:JSON.stringify({sessionRef:this.sessionRef,userRef:this.userRef,metadata:this.metadata})},{retries:1,retryDelayMs:300});if(!n.ok)throw new Error(`HTTP ${n.status}: ${n.statusText}`)}async _sendTrace(n,e){let s=await this.fetchWithRetry(`${this.endpoint}/conversations/${this.sessionRef}/traces`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},keepalive:true,signal:m(e?.timeoutMs??this.timeoutMs),body:JSON.stringify(n)},{retries:1,retryDelayMs:300});if(!s.ok)throw new Error(`HTTP ${s.status}: ${s.statusText}`);return await s.json()}async _sendFeedback(n){let e=await this.fetchWithRetry(`${this.endpoint}/conversations/${this.sessionRef}/feedback`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},keepalive:true,signal:m(this.timeoutMs),body:JSON.stringify(n)},{retries:1,retryDelayMs:300});if(!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`)}async _endConversation(n){let e=await this.fetchWithRetry(`${this.endpoint}/conversations/${this.sessionRef}`,{method:"PATCH",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},keepalive:true,signal:m(this.timeoutMs),body:JSON.stringify({durationMs:n,turnCount:this.turnCount})},{retries:1,retryDelayMs:300});if(!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`)}enqueueSend(n){this.sendQueue=this.sendQueue.then(()=>n()).catch(()=>{});}async flush(n){let e=typeof n=="number"&&Number.isFinite(n)&&n>=0?n:this.timeoutMs,s=this.sendQueue.catch(()=>{}),o;try{await Promise.race([s,new Promise((a,i)=>{o=setTimeout(()=>i(new Error("Flush timeout")),e);})]);}catch(a){if(this.debug){let i=a instanceof Error?a.message:String(a);console.warn("[Teckel] Flush incomplete:",i);}throw a}finally{o&&clearTimeout(o);}}};function m(c){if(!(typeof c!="number"||c<=0)&&typeof AbortSignal.timeout=="function")return AbortSignal.timeout(c)}var g=class{constructor(n){let e=f.parse(n);e.apiKey.startsWith("tk_live_")||console.warn('[Teckel] API key should start with "tk_live_". Current key: '+e.apiKey.substring(0,10)+"..."),this.apiKey=e.apiKey,this.endpoint=e.endpoint||"https://app.teckel.ai/api",this.debug=e.debug||false,this.timeoutMs=typeof e.timeoutMs=="number"?e.timeoutMs:5e3,this.debug&&console.log("[Teckel] SDK initialized:",{endpoint:this.endpoint,version:"0.3.6",timeoutMs:this.timeoutMs});}start(n={}){let e=h.parse(n),s=e.sessionRef||`auto:${crypto.randomUUID().slice(0,8)}`;return new u(this.apiKey,this.endpoint,{...e,sessionRef:s},this.debug,{timeoutMs:this.timeoutMs})}};
|
|
2
2
|
export{u as Conversation,h as ConversationOptionsSchema,y as DocumentSchema,p as FeedbackDataSchema,f as TeckelConfigSchema,g as TeckelTracer,b as TokenUsageSchema,l as TraceDataSchema};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "teckel-ai",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "Simple SDK for AI conversation tracking and RAG observability",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -50,5 +50,8 @@
|
|
|
50
50
|
"tsup": "^8.3.5",
|
|
51
51
|
"typescript": "^5.0.0"
|
|
52
52
|
},
|
|
53
|
-
"homepage": "https://teckel.ai"
|
|
53
|
+
"homepage": "https://teckel.ai",
|
|
54
|
+
"bugs": {
|
|
55
|
+
"email": "support@teckel.ai"
|
|
56
|
+
}
|
|
54
57
|
}
|