@opentiny/tiny-robot-kit 0.4.2-alpha.3 → 0.4.2-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-6JEZBNBO.mjs +5 -0
- package/dist/chunk-ZO2ZONVX.mjs +1 -0
- package/dist/core.d.mts +109 -248
- package/dist/core.d.ts +109 -248
- package/dist/core.js +6 -1
- package/dist/core.mjs +2 -1
- package/dist/index.d.mts +38 -4
- package/dist/index.d.ts +38 -4
- package/dist/index.js +7 -3
- package/dist/index.mjs +3 -3
- package/dist/node.d.mts +14 -0
- package/dist/node.d.ts +14 -0
- package/dist/node.js +1 -0
- package/dist/node.mjs +1 -0
- package/dist/skillPlugin-4pC5SvPk.d.mts +548 -0
- package/dist/skillPlugin-D6X-p9fQ.d.ts +548 -0
- package/dist/types-ChCZ8jKB.d.mts +70 -0
- package/dist/types-ChCZ8jKB.d.ts +70 -0
- package/package.json +13 -5
- package/dist/chunk-EES4JUCD.mjs +0 -1
- package/dist/types-D0E0rOVi.d.mts +0 -212
- package/dist/types-D0E0rOVi.d.ts +0 -212
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentiny/tiny-robot-kit",
|
|
3
|
-
"version": "0.4.2-alpha.
|
|
3
|
+
"version": "0.4.2-alpha.4",
|
|
4
4
|
"homepage": "https://docs.opentiny.design/tiny-robot/",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -44,6 +44,11 @@
|
|
|
44
44
|
"types": "./dist/core.d.ts",
|
|
45
45
|
"import": "./dist/core.mjs",
|
|
46
46
|
"require": "./dist/core.js"
|
|
47
|
+
},
|
|
48
|
+
"./node": {
|
|
49
|
+
"types": "./dist/node.d.ts",
|
|
50
|
+
"import": "./dist/node.mjs",
|
|
51
|
+
"require": "./dist/node.js"
|
|
47
52
|
}
|
|
48
53
|
},
|
|
49
54
|
"files": [
|
|
@@ -51,8 +56,10 @@
|
|
|
51
56
|
],
|
|
52
57
|
"sideEffects": false,
|
|
53
58
|
"scripts": {
|
|
54
|
-
"build": "tsup src/index.ts src/core.ts --format cjs,esm --dts --minify",
|
|
55
|
-
"dev": "tsup src/index.ts src/core.ts --format cjs,esm --dts --watch",
|
|
59
|
+
"build": "tsup src/index.ts src/core.ts src/node.ts --format cjs,esm --dts --minify",
|
|
60
|
+
"dev": "tsup src/index.ts src/core.ts src/node.ts --format cjs,esm --dts --watch",
|
|
61
|
+
"lint": "eslint src",
|
|
62
|
+
"pretest": "node scripts/download-skill-fixtures.mjs",
|
|
56
63
|
"test": "vitest run",
|
|
57
64
|
"test:watch": "vitest"
|
|
58
65
|
},
|
|
@@ -69,7 +76,8 @@
|
|
|
69
76
|
"vue": ">=3.0.0"
|
|
70
77
|
},
|
|
71
78
|
"dependencies": {
|
|
72
|
-
"idb": "^8.0.3"
|
|
79
|
+
"idb": "^8.0.3",
|
|
80
|
+
"yaml": "^2.8.3"
|
|
73
81
|
},
|
|
74
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "6a47cf299b30a57c28835726309bbc0fd12022e9"
|
|
75
83
|
}
|
package/dist/chunk-EES4JUCD.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{computed as ce,isProxy as ue,reactive as ge,ref as L,toRaw as fe}from"vue";var le=e=>typeof e=="function"?null:Array.isArray(e)?e.length>0?new Set(e):null:new Set([e]),ee=e=>{let t=new Set,s=(o,f)=>{try{o.listener(f)}catch(m){console.error("Error in message state subscriber:",m)}};return{notify:o=>{let f=new Set(Array.isArray(o)?o:[o]),m=e(),p=Array.from(t);for(let a of p){if(a.kinds){let c=!1;for(let y of a.kinds)if(f.has(y)){c=!0;break}if(!c)continue}s(a,m)}},subscribe:(o,f)=>{let m=typeof o=="function"?o:f;if(!m)throw new Error("subscribe listener is required");let p={kinds:le(o),listener:m};return t.add(p),s(p,e()),()=>{t.delete(p)}}}};var te=e=>ge(e),$=e=>{let t=ue(e)?fe(e):e;if(Array.isArray(t))return t.map(s=>$(s));if(t&&typeof t=="object"){let s={};for(let[n,i]of Object.entries(t))s[n]=$(i);return s}return t},xe=()=>{let e=!1,t=L("idle"),s=L(void 0),n=L([]),i=ce(()=>t.value==="processing"),o=c=>{if(e)throw new Error("Message state adapter is already initialized");t.value=c.requestState,s.value=c.processingState,n.value=c.messages.map(te),e=!0},f=c=>te(c),m=()=>{if(!e)throw new Error("Message state adapter is not initialized");return{requestState:t.value,processingState:s.value,messages:$(n.value),isProcessing:i.value}},p=ee(m);return{requestState:t,processingState:s,messages:n,isProcessing:i,initialize:o,getState:m,createMessage:f,mutate:(c,y)=>{if(!e)throw new Error("Message state adapter is not initialized");let A={get requestState(){return t.value},set requestState(S){t.value=S},get processingState(){return s.value},set processingState(S){s.value=S},get messages(){return n.value},set messages(S){n.value=S.map(f)}},d=!1;if(y(A,()=>{d=!0}),d)return;(Array.isArray(c)?c:[c]).includes("messages")&&(n.value=[...n.value]),p.notify(c)},subscribe:p.subscribe}};var H=(e={})=>{let{continueContent:t="Please continue with your previous answer.",...s}=e;return{name:"length",...s,onAfterRequest:async n=>{let{lastChoice:i,appendMessage:o,requestNext:f}=n;return i?.finish_reason==="length"&&(o({role:"user",content:t}),f()),s.onAfterRequest?.(n)}}};var Q=(e={})=>{let t=(s,n)=>!!s.thinking!==n||!!s.open!==n;return{name:"thinking",...e,onCompletionChunk(s){let{choice:n,currentMessage:i,updateCurrentMessage:o}=s,f=n,m=f?.message?.reasoning_content||f?.delta?.reasoning_content,p=typeof m=="string"&&m.trim()!=="";return p?i.state&&typeof i.state=="object"?t(i.state,p)&&o(a=>{a.state.thinking=!0,a.state.open=!0}):o(a=>{a.state={thinking:p,open:p}}):i.state&&typeof i.state=="object"&&"thinking"in i.state&&t(i.state,p)&&o(a=>{a.state.thinking=!1,a.state.open=!1}),e.onCompletionChunk?.(s)},onTurnEnd(s){let{currentTurn:n,mutate:i}=s,o=n.at(-1);return o?.state&&typeof o.state=="object"&&"thinking"in o.state&&t(o.state,!1)&&i("messages",()=>{o.state.thinking=!1,o.state.open=!1}),e.onTurnEnd?.(s)}}};var D=class extends Error{constructor(t){super(t),this.name="AbortError"}};function de(e){if(e.aborted)return{promise:Promise.reject(new D(String(e.reason??"Aborted"))),cleanup:()=>{}};let t=null;return{promise:new Promise((i,o)=>{t=()=>{o(new D(String(e.reason??"Aborted")))},e.addEventListener("abort",t,{once:!0})}),cleanup:()=>{t&&(e.removeEventListener("abort",t),t=null)}}}function oe(e,t){let{promise:s,cleanup:n}=de(t);return Promise.race([e,s]).finally(n)}function ae(e,t){let s={};for(let n in e)t.includes(n)&&(s[n]=e[n]);return s}function re(e,t){let s={};for(let n in e)t.includes(n)||(s[n]=e[n]);return s}async function*J(e){if(se(e)){yield*e;return}let t=await e;if(se(t)){yield*t;return}yield t}function se(e){return e&&typeof e=="object"&&typeof e[Symbol.asyncIterator]=="function"}var X=e=>typeof e=="object"&&e!==null,ne=e=>X(e)&&typeof e.index=="number",O=(e,t)=>{for(let[s,n]of Object.entries(t)){let i=e[s];if(i)if(typeof i=="string"&&typeof n=="string")s==="type"&&i||(e[s]=i+n);else if(Array.isArray(i)&&Array.isArray(n))if(i.every(o=>ne(o))&&n.every(o=>ne(o))){let o=new Map(i.map(a=>[a.index,a])),f=new Map(n.map(a=>[a.index,a]));for(let[a,c]of f)if(o.has(a)){let y=o.get(a);o.set(a,O(y,c))}else o.set(a,c);let m=Math.max(...Array.from(o.keys()),-1)+1,p=m>i.length?Array.from({length:m}):i;for(let[a,c]of o)p[a]=c;e[s]=p}else e[s]=[...i,...n];else X(i)&&X(n)&&(e[s]=O(i,n));else e[s]=n}return e};function pe({messages:e,cancelledContent:t,createMessage:s,mutate:n}){let i=[];for(let o=0;o<e.length;o++){let f=e[o];if(f.role==="assistant"&&f.tool_calls&&f.tool_calls.length>0){let m=new Set(f.tool_calls.map(c=>c.id)),p=new Set;for(let c=o+1;c<e.length;c++){let y=e[c];y.role==="tool"&&y.tool_call_id&&m.has(y.tool_call_id)&&p.add(y.tool_call_id)}let a=f.tool_calls.map(c=>c.id).filter(c=>!p.has(c));a.length>0&&i.push({insertAfterIndex:o,missingToolCallIds:a})}}i.length!==0&&n("messages",o=>{for(let f=i.length-1;f>=0;f--){let{insertAfterIndex:m,missingToolCallIds:p}=i[f],a=p.map(c=>s({role:"tool",tool_call_id:c,content:t}));o.messages.splice(m+1,0,...a)}})}var me=e=>{let{getTools:t,beforeCallTools:s,callTool:n,onToolCallStart:i,onToolCallEnd:o,toolCallCancelledContent:f="Tool call cancelled.",toolCallFailedContent:m="Tool call failed.",autoFillMissingToolMessages:p=!1,...a}=e,c=(d,C)=>{var M,S;return d.state??(d.state={}),(M=d.state).toolCall??(M.toolCall={}),(S=d.state.toolCall)[C]??(S[C]={}),d},y=(...d)=>{let[C,{assistantMessage:M,mutate:S}]=d;S("messages",()=>{let w=c(M,C.id);w.state.toolCall[C.id].status="running"}),i?.(...d)},A=(...d)=>{let[C,{status:M,assistantMessage:S,mutate:w}]=d;w("messages",()=>{let W=c(S,C.id);W.state.toolCall[C.id].status=M}),o?.(...d)};return{name:"tool",...a,onTurnStart:d=>{let{getState:C,createMessage:M,mutate:S}=d,w=C().messages;return p&&pe({messages:w,cancelledContent:f,createMessage:M,mutate:S}),a.onTurnStart?.(d)},onBeforeRequest:async d=>{let{requestBody:C}=d,M=await t();return M&&M.length>0&&(C.tools=M),a.onBeforeRequest?.(d)},onAfterRequest:async d=>{let{currentMessage:C,lastChoice:M,appendMessage:S,abortSignal:w,setRequestState:W,requestNext:v,mutate:j,createMessage:R}=d;if(M?.finish_reason!=="tool_calls"||!C.tool_calls?.length)return;W("processing","calling-tools"),await s?.(C.tool_calls,{...d,assistantMessage:C});let G=C.tool_calls.map(async I=>{let z=Math.floor(Date.now()/1e3),V=!1,x=R({role:"tool",tool_call_id:I.id,content:"",metadata:{createdAt:z,updatedAt:z}});S(x);let B={...d,assistantMessage:C,toolMessage:x};y(I,B);try{let r=n(I,B),l=J(r);for await(let g of l)j("messages",()=>{if((typeof g=="string"&&g.length>0||g&&typeof g=="object"&&Object.keys(g).length>0)&&(V=!0),typeof g=="string")x.content+=g;else{let h={};try{let b=Array.isArray(x.content)?x.content.map(u=>u.text).join(""):x.content;h=JSON.parse(b||"{}")}catch(b){console.warn(b)}x.content=JSON.stringify(O(h,g))}x.metadata.updatedAt=Math.floor(Date.now()/1e3)});A(I,{...B,status:"success"})}catch(r){let l=r instanceof Error?r:new Error(String(r));if(w.aborted){A(I,{...B,status:"cancelled",error:l});return}console.error(r),V||j("messages",()=>{x.content=m,x.metadata.updatedAt=Math.floor(Date.now()/1e3)}),A(I,{...B,status:"failed",error:l})}});return await Promise.all(G),w.aborted||v(),a.onAfterRequest?.(d)}}};var Ce=async()=>{throw new Error("Response provider is not set")},Me=e=>{let t=[];for(let s of e){if(s.name){let n=t.findIndex(i=>i.name===s.name);n!==-1&&t.splice(n,1)}t.push(s)}return t},K=(e,t)=>typeof e.disabled=="function"?e.disabled(t):!!e.disabled,he=(e,t={})=>{let{initialMessages:s=[],requestMessageFields:n=[],requestMessageFieldsExclude:i=["state","metadata","loading"],responseProvider:o=Ce,onCompletionChunk:f,plugins:m=[]}=t,p={requestState:"idle",processingState:void 0,messages:[...s]};e.initialize(p);let a={currentTurn:[],customContext:{},abortController:null,responseProvider:o},c=[Q(),H()],y=Me(c.concat(m)),A=()=>e.getState(),d=r=>e.createMessage(r),C=e.subscribe,M=e.mutate,S=r=>!r||Object.keys(r).length===0?!1:Object.values(r).some(l=>!!l),w=r=>{let l=r;return n.length&&(l=l.map(g=>ae(g,n))),i.length&&(l=l.map(g=>re(g,i))),l},W=r=>{Object.assign(a.customContext,r)},v=(r,l)=>{M("requestState",(g,h)=>{if(g.requestState===r&&g.processingState===l){h();return}g.requestState=r,g.processingState=r==="processing"?l??"requesting":void 0})},j=(...r)=>{let l=r.map(g=>d(g));return M("messages",g=>{g.messages.push(...l)}),a.currentTurn.push(...l),l},R=r=>({getState:A,createMessage:d,mutate:M,abortSignal:r,currentTurn:a.currentTurn,customContext:a.customContext,setRequestState:v,setCustomContext:W});async function G(r,l,g={}){v("processing","requesting");let h={messages:A().messages},b=R(l);for(let _ of y.filter(T=>!K(T,b)))await _.onBeforeRequest?.({...b,requestBody:h});h.messages=w(h.messages);let u={role:"assistant",content:"",loading:!0};[u]=j(u),g.setAssistantMessage?.(u);let P=r(h,l),q=J(P),k;for await(let _ of q){v("processing","completing"),M("messages",(E,N)=>{u.loading?u.loading=void 0:N()});let T=(_.choices||[]).find(E=>E.index===0)??_.choices?.[0];if(!T)continue;k=T;let F=()=>{M("messages",()=>{u.metadata||(u.metadata={});let{created:E,...N}=_;u.metadata.createdAt=E,u.metadata.updatedAt=Math.floor(Date.now()/1e3),Object.assign(u.metadata,N);let U="delta"in T&&S(T.delta)&&T.delta||"message"in T&&S(T.message)&&T.message||null;if(U?.role&&(u.role=U.role),U){let{role:ye,...ie}=U;O(u,ie)}})},Y=E=>{M("messages",()=>{E(u)})};if(f){let E=R(l);f({...E,chunk:_,choice:T,currentMessage:u,updateCurrentMessage:Y},F)}else F();let Z=R(l);for(let E of y.filter(N=>!K(N,Z)))E.onCompletionChunk?.({...Z,abortSignal:l,chunk:_,choice:T,currentMessage:u,updateCurrentMessage:Y})}await I(u,r,l,k,g)}async function I(r,l,g,h,b){let u=!1,P=R(g),q=y.filter(k=>!K(k,P)).map(k=>{if(!k.onAfterRequest)return null;let _=F=>{j(...Array.isArray(F)?F:[F])},T=()=>{u=!0};return k.onAfterRequest({...P,currentMessage:r,lastChoice:h,appendMessage:_,requestNext:T})}).filter(k=>k!==null);await oe(Promise.all(q),g),u&&await G(l,g,b)}async function z(){let r=new AbortController;a.abortController=r,a.customContext={};let l=null,g=h=>{l=h};try{v("processing","requesting");let h=R(r.signal);for(let P of y.filter(q=>!K(q,h)))await P.onTurnStart?.(h);let b=a.responseProvider;try{await G(b,r.signal,{setAssistantMessage:g}),v("completed")}catch(P){if(r.signal.aborted||P instanceof D||P instanceof Error&&P.name==="AbortError")v("aborted");else throw P}let u=R(r.signal);for(let P of y.filter(q=>!K(q,u)))await P.onTurnEnd?.(u)}catch(h){v("error");let b=!1,u=R(r.signal);for(let P of y.filter(q=>!K(q,u)))P.onError&&(b=!0,P.onError({...u,error:h}));if(!b)throw h}finally{let h=R(r.signal);for(let b of y.filter(u=>!K(u,h)))try{b.onFinally?.(h)}catch(u){console.error(`Error in onFinally hook for plugin [${b.name||"Anonymous"}]:`,u)}a.abortController=null,a.currentTurn=[],M("messages",(b,u)=>{l?.loading?l.loading=void 0:u()})}}async function V(r){if(!r||!r.trim()){console.warn("Cannot send empty message");return}if(A().requestState==="processing"){console.warn("Cannot send message while processing is in progress");return}let l=Math.floor(Date.now()/1e3);j({role:"user",content:r.trim(),metadata:{createdAt:l,updatedAt:l}}),await z()}async function x(...r){if(A().requestState==="processing"){console.warn("Cannot send message while processing is in progress");return}j(...r),await z()}async function B(){a.abortController?.abort(),A().isProcessing&&await new Promise(r=>{let l=()=>{};l=C("requestState",g=>{g.isProcessing||(l(),r())})})}return{getState:A,subscribe:C,sendMessage:V,send:x,abort:B,setResponseProvider(r){a.responseProvider=r}}};export{ee as a,xe as b,H as c,Q as d,J as e,O as f,me as g,he as h};
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 模型Provider基类
|
|
3
|
-
*/
|
|
4
|
-
declare abstract class BaseModelProvider {
|
|
5
|
-
protected config: AIModelConfig;
|
|
6
|
-
/**
|
|
7
|
-
* @param config AI模型配置
|
|
8
|
-
*/
|
|
9
|
-
constructor(config: AIModelConfig);
|
|
10
|
-
/**
|
|
11
|
-
* 发送聊天请求并获取响应
|
|
12
|
-
* @param request 聊天请求参数
|
|
13
|
-
* @returns 聊天响应
|
|
14
|
-
*/
|
|
15
|
-
abstract chat(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
16
|
-
/**
|
|
17
|
-
* 发送流式聊天请求并通过处理器处理响应
|
|
18
|
-
* @param request 聊天请求参数
|
|
19
|
-
* @param handler 流式响应处理器
|
|
20
|
-
*/
|
|
21
|
-
abstract chatStream(request: ChatCompletionRequest, handler: StreamHandler): Promise<void>;
|
|
22
|
-
/**
|
|
23
|
-
* 更新配置
|
|
24
|
-
* @param config 新的AI模型配置
|
|
25
|
-
*/
|
|
26
|
-
updateConfig(config: AIModelConfig): void;
|
|
27
|
-
/**
|
|
28
|
-
* 获取当前配置
|
|
29
|
-
* @returns AI模型配置
|
|
30
|
-
*/
|
|
31
|
-
getConfig(): AIModelConfig;
|
|
32
|
-
/**
|
|
33
|
-
* 验证请求参数
|
|
34
|
-
* @param request 聊天请求参数
|
|
35
|
-
*/
|
|
36
|
-
protected validateRequest(request: ChatCompletionRequest): void;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
40
|
-
/**
|
|
41
|
-
* 消息角色类型
|
|
42
|
-
*/
|
|
43
|
-
type MessageRole = 'system' | 'user' | 'assistant';
|
|
44
|
-
interface ToolCall {
|
|
45
|
-
index: number;
|
|
46
|
-
id: string;
|
|
47
|
-
type: 'function';
|
|
48
|
-
function: {
|
|
49
|
-
name: string;
|
|
50
|
-
arguments: string;
|
|
51
|
-
result?: string;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
interface MessageMetadata {
|
|
55
|
-
createdAt?: number;
|
|
56
|
-
updatedAt?: number;
|
|
57
|
-
id?: string;
|
|
58
|
-
model?: string;
|
|
59
|
-
[key: string]: any;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* 聊天消息接口
|
|
63
|
-
*/
|
|
64
|
-
interface ChatMessage {
|
|
65
|
-
role: string;
|
|
66
|
-
content: string;
|
|
67
|
-
reasoning_content?: string;
|
|
68
|
-
metadata?: MessageMetadata;
|
|
69
|
-
tool_calls?: ToolCall[];
|
|
70
|
-
tool_call_id?: string;
|
|
71
|
-
[key: string]: any;
|
|
72
|
-
[key: symbol]: any;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* 聊天历史记录
|
|
76
|
-
*/
|
|
77
|
-
type ChatHistory = ChatMessage[];
|
|
78
|
-
/**
|
|
79
|
-
* 聊天完成请求选项
|
|
80
|
-
*/
|
|
81
|
-
interface ChatCompletionOptions {
|
|
82
|
-
model?: string;
|
|
83
|
-
temperature?: number;
|
|
84
|
-
top_p?: number;
|
|
85
|
-
n?: number;
|
|
86
|
-
stream?: boolean;
|
|
87
|
-
max_tokens?: number;
|
|
88
|
-
signal?: AbortSignal;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* 聊天完成请求参数
|
|
92
|
-
*/
|
|
93
|
-
interface ChatCompletionRequest {
|
|
94
|
-
messages: ChatMessage[];
|
|
95
|
-
options?: ChatCompletionOptions;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* 聊天完成响应消息
|
|
99
|
-
*/
|
|
100
|
-
interface ChatCompletionResponseMessage {
|
|
101
|
-
role: MessageRole;
|
|
102
|
-
content: string;
|
|
103
|
-
[x: string]: unknown;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* 聊天完成响应选择
|
|
107
|
-
*/
|
|
108
|
-
interface ChatCompletionResponseChoice {
|
|
109
|
-
index: number;
|
|
110
|
-
message: ChatCompletionResponseMessage;
|
|
111
|
-
finish_reason: string;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* 聊天完成响应使用情况
|
|
115
|
-
*/
|
|
116
|
-
interface ChatCompletionResponseUsage {
|
|
117
|
-
prompt_tokens: number;
|
|
118
|
-
completion_tokens: number;
|
|
119
|
-
total_tokens: number;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* 聊天完成响应
|
|
123
|
-
*/
|
|
124
|
-
interface ChatCompletionResponse {
|
|
125
|
-
id: string;
|
|
126
|
-
object: string;
|
|
127
|
-
created: number;
|
|
128
|
-
model: string;
|
|
129
|
-
choices: ChatCompletionResponseChoice[];
|
|
130
|
-
usage: ChatCompletionResponseUsage;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* 流式聊天完成响应增量
|
|
134
|
-
*/
|
|
135
|
-
interface ChatCompletionStreamResponseDelta {
|
|
136
|
-
content?: string;
|
|
137
|
-
role?: MessageRole;
|
|
138
|
-
[x: string]: unknown;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* 流式聊天完成响应选择
|
|
142
|
-
*/
|
|
143
|
-
interface ChatCompletionStreamResponseChoice {
|
|
144
|
-
index: number;
|
|
145
|
-
delta: ChatCompletionStreamResponseDelta;
|
|
146
|
-
finish_reason: string | null;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* 流式聊天完成响应
|
|
150
|
-
*/
|
|
151
|
-
interface ChatCompletionStreamResponse {
|
|
152
|
-
id: string;
|
|
153
|
-
object: string;
|
|
154
|
-
created: number;
|
|
155
|
-
model: string;
|
|
156
|
-
choices: ChatCompletionStreamResponseChoice[];
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* AI模型提供商类型
|
|
160
|
-
*/
|
|
161
|
-
type AIProvider = 'openai' | 'deepseek' | 'custom';
|
|
162
|
-
/**
|
|
163
|
-
* AI模型配置接口
|
|
164
|
-
*/
|
|
165
|
-
interface AIModelConfig {
|
|
166
|
-
provider: AIProvider;
|
|
167
|
-
providerImplementation?: BaseModelProvider;
|
|
168
|
-
apiKey?: string;
|
|
169
|
-
apiUrl?: string;
|
|
170
|
-
apiVersion?: string;
|
|
171
|
-
defaultModel?: string;
|
|
172
|
-
defaultOptions?: ChatCompletionOptions;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* 错误类型
|
|
176
|
-
*/
|
|
177
|
-
declare enum ErrorType {
|
|
178
|
-
NETWORK_ERROR = "network_error",
|
|
179
|
-
AUTHENTICATION_ERROR = "authentication_error",
|
|
180
|
-
RATE_LIMIT_ERROR = "rate_limit_error",
|
|
181
|
-
SERVER_ERROR = "server_error",
|
|
182
|
-
MODEL_ERROR = "model_error",
|
|
183
|
-
TIMEOUT_ERROR = "timeout_error",
|
|
184
|
-
UNKNOWN_ERROR = "unknown_error"
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* AI适配器错误
|
|
188
|
-
*/
|
|
189
|
-
interface AIAdapterError {
|
|
190
|
-
type: ErrorType;
|
|
191
|
-
message: string;
|
|
192
|
-
statusCode?: number;
|
|
193
|
-
originalError?: object;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* 流式响应事件类型
|
|
197
|
-
*/
|
|
198
|
-
declare enum StreamEventType {
|
|
199
|
-
DATA = "data",
|
|
200
|
-
ERROR = "error",
|
|
201
|
-
DONE = "done"
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* 流式响应处理器
|
|
205
|
-
*/
|
|
206
|
-
interface StreamHandler {
|
|
207
|
-
onData: (data: ChatCompletionStreamResponse) => void;
|
|
208
|
-
onError: (error: AIAdapterError) => void;
|
|
209
|
-
onDone: (finishReason?: string) => void;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
export { type AIModelConfig as A, BaseModelProvider as B, type ChatCompletionRequest as C, ErrorType as E, type MaybePromise as M, type StreamHandler as S, type ToolCall as T, type ChatCompletionResponse as a, type ChatMessage as b, type AIAdapterError as c, type AIProvider as d, type ChatCompletionOptions as e, type ChatCompletionResponseChoice as f, type ChatCompletionResponseMessage as g, type ChatCompletionResponseUsage as h, type ChatCompletionStreamResponse as i, type ChatCompletionStreamResponseChoice as j, type ChatCompletionStreamResponseDelta as k, type ChatHistory as l, type MessageMetadata as m, type MessageRole as n, StreamEventType as o };
|
package/dist/types-D0E0rOVi.d.ts
DELETED
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 模型Provider基类
|
|
3
|
-
*/
|
|
4
|
-
declare abstract class BaseModelProvider {
|
|
5
|
-
protected config: AIModelConfig;
|
|
6
|
-
/**
|
|
7
|
-
* @param config AI模型配置
|
|
8
|
-
*/
|
|
9
|
-
constructor(config: AIModelConfig);
|
|
10
|
-
/**
|
|
11
|
-
* 发送聊天请求并获取响应
|
|
12
|
-
* @param request 聊天请求参数
|
|
13
|
-
* @returns 聊天响应
|
|
14
|
-
*/
|
|
15
|
-
abstract chat(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
16
|
-
/**
|
|
17
|
-
* 发送流式聊天请求并通过处理器处理响应
|
|
18
|
-
* @param request 聊天请求参数
|
|
19
|
-
* @param handler 流式响应处理器
|
|
20
|
-
*/
|
|
21
|
-
abstract chatStream(request: ChatCompletionRequest, handler: StreamHandler): Promise<void>;
|
|
22
|
-
/**
|
|
23
|
-
* 更新配置
|
|
24
|
-
* @param config 新的AI模型配置
|
|
25
|
-
*/
|
|
26
|
-
updateConfig(config: AIModelConfig): void;
|
|
27
|
-
/**
|
|
28
|
-
* 获取当前配置
|
|
29
|
-
* @returns AI模型配置
|
|
30
|
-
*/
|
|
31
|
-
getConfig(): AIModelConfig;
|
|
32
|
-
/**
|
|
33
|
-
* 验证请求参数
|
|
34
|
-
* @param request 聊天请求参数
|
|
35
|
-
*/
|
|
36
|
-
protected validateRequest(request: ChatCompletionRequest): void;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
40
|
-
/**
|
|
41
|
-
* 消息角色类型
|
|
42
|
-
*/
|
|
43
|
-
type MessageRole = 'system' | 'user' | 'assistant';
|
|
44
|
-
interface ToolCall {
|
|
45
|
-
index: number;
|
|
46
|
-
id: string;
|
|
47
|
-
type: 'function';
|
|
48
|
-
function: {
|
|
49
|
-
name: string;
|
|
50
|
-
arguments: string;
|
|
51
|
-
result?: string;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
interface MessageMetadata {
|
|
55
|
-
createdAt?: number;
|
|
56
|
-
updatedAt?: number;
|
|
57
|
-
id?: string;
|
|
58
|
-
model?: string;
|
|
59
|
-
[key: string]: any;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* 聊天消息接口
|
|
63
|
-
*/
|
|
64
|
-
interface ChatMessage {
|
|
65
|
-
role: string;
|
|
66
|
-
content: string;
|
|
67
|
-
reasoning_content?: string;
|
|
68
|
-
metadata?: MessageMetadata;
|
|
69
|
-
tool_calls?: ToolCall[];
|
|
70
|
-
tool_call_id?: string;
|
|
71
|
-
[key: string]: any;
|
|
72
|
-
[key: symbol]: any;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* 聊天历史记录
|
|
76
|
-
*/
|
|
77
|
-
type ChatHistory = ChatMessage[];
|
|
78
|
-
/**
|
|
79
|
-
* 聊天完成请求选项
|
|
80
|
-
*/
|
|
81
|
-
interface ChatCompletionOptions {
|
|
82
|
-
model?: string;
|
|
83
|
-
temperature?: number;
|
|
84
|
-
top_p?: number;
|
|
85
|
-
n?: number;
|
|
86
|
-
stream?: boolean;
|
|
87
|
-
max_tokens?: number;
|
|
88
|
-
signal?: AbortSignal;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* 聊天完成请求参数
|
|
92
|
-
*/
|
|
93
|
-
interface ChatCompletionRequest {
|
|
94
|
-
messages: ChatMessage[];
|
|
95
|
-
options?: ChatCompletionOptions;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* 聊天完成响应消息
|
|
99
|
-
*/
|
|
100
|
-
interface ChatCompletionResponseMessage {
|
|
101
|
-
role: MessageRole;
|
|
102
|
-
content: string;
|
|
103
|
-
[x: string]: unknown;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* 聊天完成响应选择
|
|
107
|
-
*/
|
|
108
|
-
interface ChatCompletionResponseChoice {
|
|
109
|
-
index: number;
|
|
110
|
-
message: ChatCompletionResponseMessage;
|
|
111
|
-
finish_reason: string;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* 聊天完成响应使用情况
|
|
115
|
-
*/
|
|
116
|
-
interface ChatCompletionResponseUsage {
|
|
117
|
-
prompt_tokens: number;
|
|
118
|
-
completion_tokens: number;
|
|
119
|
-
total_tokens: number;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* 聊天完成响应
|
|
123
|
-
*/
|
|
124
|
-
interface ChatCompletionResponse {
|
|
125
|
-
id: string;
|
|
126
|
-
object: string;
|
|
127
|
-
created: number;
|
|
128
|
-
model: string;
|
|
129
|
-
choices: ChatCompletionResponseChoice[];
|
|
130
|
-
usage: ChatCompletionResponseUsage;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* 流式聊天完成响应增量
|
|
134
|
-
*/
|
|
135
|
-
interface ChatCompletionStreamResponseDelta {
|
|
136
|
-
content?: string;
|
|
137
|
-
role?: MessageRole;
|
|
138
|
-
[x: string]: unknown;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* 流式聊天完成响应选择
|
|
142
|
-
*/
|
|
143
|
-
interface ChatCompletionStreamResponseChoice {
|
|
144
|
-
index: number;
|
|
145
|
-
delta: ChatCompletionStreamResponseDelta;
|
|
146
|
-
finish_reason: string | null;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* 流式聊天完成响应
|
|
150
|
-
*/
|
|
151
|
-
interface ChatCompletionStreamResponse {
|
|
152
|
-
id: string;
|
|
153
|
-
object: string;
|
|
154
|
-
created: number;
|
|
155
|
-
model: string;
|
|
156
|
-
choices: ChatCompletionStreamResponseChoice[];
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* AI模型提供商类型
|
|
160
|
-
*/
|
|
161
|
-
type AIProvider = 'openai' | 'deepseek' | 'custom';
|
|
162
|
-
/**
|
|
163
|
-
* AI模型配置接口
|
|
164
|
-
*/
|
|
165
|
-
interface AIModelConfig {
|
|
166
|
-
provider: AIProvider;
|
|
167
|
-
providerImplementation?: BaseModelProvider;
|
|
168
|
-
apiKey?: string;
|
|
169
|
-
apiUrl?: string;
|
|
170
|
-
apiVersion?: string;
|
|
171
|
-
defaultModel?: string;
|
|
172
|
-
defaultOptions?: ChatCompletionOptions;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* 错误类型
|
|
176
|
-
*/
|
|
177
|
-
declare enum ErrorType {
|
|
178
|
-
NETWORK_ERROR = "network_error",
|
|
179
|
-
AUTHENTICATION_ERROR = "authentication_error",
|
|
180
|
-
RATE_LIMIT_ERROR = "rate_limit_error",
|
|
181
|
-
SERVER_ERROR = "server_error",
|
|
182
|
-
MODEL_ERROR = "model_error",
|
|
183
|
-
TIMEOUT_ERROR = "timeout_error",
|
|
184
|
-
UNKNOWN_ERROR = "unknown_error"
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* AI适配器错误
|
|
188
|
-
*/
|
|
189
|
-
interface AIAdapterError {
|
|
190
|
-
type: ErrorType;
|
|
191
|
-
message: string;
|
|
192
|
-
statusCode?: number;
|
|
193
|
-
originalError?: object;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* 流式响应事件类型
|
|
197
|
-
*/
|
|
198
|
-
declare enum StreamEventType {
|
|
199
|
-
DATA = "data",
|
|
200
|
-
ERROR = "error",
|
|
201
|
-
DONE = "done"
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* 流式响应处理器
|
|
205
|
-
*/
|
|
206
|
-
interface StreamHandler {
|
|
207
|
-
onData: (data: ChatCompletionStreamResponse) => void;
|
|
208
|
-
onError: (error: AIAdapterError) => void;
|
|
209
|
-
onDone: (finishReason?: string) => void;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
export { type AIModelConfig as A, BaseModelProvider as B, type ChatCompletionRequest as C, ErrorType as E, type MaybePromise as M, type StreamHandler as S, type ToolCall as T, type ChatCompletionResponse as a, type ChatMessage as b, type AIAdapterError as c, type AIProvider as d, type ChatCompletionOptions as e, type ChatCompletionResponseChoice as f, type ChatCompletionResponseMessage as g, type ChatCompletionResponseUsage as h, type ChatCompletionStreamResponse as i, type ChatCompletionStreamResponseChoice as j, type ChatCompletionStreamResponseDelta as k, type ChatHistory as l, type MessageMetadata as m, type MessageRole as n, StreamEventType as o };
|