@qfei-design/make-ai-assistant 0.1.4 → 0.1.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/PUBLIC_API.md +32 -9
- package/README.md +19 -2
- package/dist/{conversation-Dy2Sghjv.js → conversation-B7eGUXi-.js} +241 -198
- package/dist/conversation-Cv1wdvCR.cjs +1 -0
- package/dist/core/conversation.d.ts +11 -0
- package/dist/core/types.d.ts +2 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +2 -2
- package/dist/make-app.cjs +1 -1
- package/dist/make-app.mjs +7 -6
- package/dist/make-console.cjs +1 -1
- package/dist/make-console.mjs +56 -55
- package/dist/react.cjs +5 -1
- package/dist/react.mjs +726 -485
- package/dist/sse.cjs +1 -1
- package/dist/sse.mjs +1 -1
- package/dist/styles.css +384 -29
- package/package.json +1 -1
- package/dist/conversation-Yku9Lzj_.cjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const w=(t,e)=>{let r=0;for(const s of t)if(r+=1,r>e)break;return r};const o={actions:10,comparisonItems:24,jsonCharacters:1e6,jsonDepth:64,jsonNodes:1e4,rankingItems:50,recordColumns:20,recordListRecords:100,recordValues:100,textCharacters:2e4,trendPointsPerSeries:120,trendSeries:8,validationIssues:100},f={artifactsPerRun:50,assistantMessagesPerRun:20,historyArtifacts:500,historyCharacters:1e6,historyMessages:200,identifierCharacters:1e3,messageCharacters:1e5,progressCharactersPerRun:2e4,progressStepsPerRun:50},K=["metric","comparison","trend","ranking","record-list","notice"],_=()=>({success:!1,issues:[{path:"",message:"could not be safely inspected"}]}),D=new Set(["navigate","open-record","open-list","invoke"]),F=new Set(["decimal","currency","percent"]);class j extends Array{push(...e){const r=o.validationIssues-this.length;return r>0?super.push(...e.slice(0,r)):this.length}}const c=t=>(()=>{if(typeof t!="object"||t===null||Array.isArray(t))return!1;const e=Object.getPrototypeOf(t);return e===Object.prototype||e===null})(),P=t=>typeof t=="string"&&t.trim().length>0,T=(t,e)=>{let r=0;for(const s of t)if(r+=1,r>e)return r;return r},u=t=>typeof t=="string"&&T(t,o.textCharacters)<=o.textCharacters,b=t=>typeof t=="number"&&Number.isFinite(t),q=t=>t.length<=120?t:`${t.slice(0,117)}...`,l=(t,e,r)=>{P(t)?u(t)||r.push({path:e,message:`must contain at most ${o.textCharacters} characters`}):r.push({path:e,message:"must be a non-empty string"})},I=(t,e,r)=>{t!==void 0&&typeof t!="string"?r.push({path:e,message:"must be a string"}):typeof t=="string"&&!u(t)&&r.push({path:e,message:`must contain at most ${o.textCharacters} characters`})},d=(t,e,r,s)=>{for(const a in t)if(Object.prototype.hasOwnProperty.call(t,a)){if(s.length>=o.validationIssues)break;e.has(a)||s.push({path:q(r?`${r}.${a}`:a),message:"is not supported"})}},A=(t,e,r,s)=>t.length>e?(s.push({path:r,message:`must contain at most ${e} items`}),!0):!1,S=(t,e,r)=>{for(let s=0;s<t.length;s+=1)if(!Object.prototype.hasOwnProperty.call(t,s))return r.push({path:e,message:"must not contain empty array slots"}),!0;return!1},E=(t,e,r,s)=>{const a=new Set;t.forEach((n,p)=>{if(!c(n)||typeof n[e]!="string")return;const i=n[e];a.has(i)?s.push({path:`${r}[${p}].${e}`,message:"must be unique within the collection"}):a.add(i)})},U=new Set(["schemaVersion","id","kind","title","summary","presentation","actions","meta","data"]),z=new Set(["template","density"]),J=new Set(["style","currency","precision","unit"]),H=new Set(["id","label","intent","target","appearance"]),B=new Set(["value","format","delta","context"]),W=new Set(["value","format","direction","label"]),x=new Set(["items"]),G=new Set(["id","label","value","format","hint"]),Q=new Set(["series"]),X=new Set(["id","label","points","format"]),Z=new Set(["x","y"]),tt=new Set(["id","label","value","format","description"]),et=new Set(["entity","columns","records","total"]),rt=new Set(["key","label"]),st=new Set(["key","label","format"]),nt=new Set(["id","title","values","action"]),at=new Set(["tone","body"]),C=(t,e,r)=>c(t)?(d(t,J,e,r),t.style!==void 0&&(typeof t.style!="string"||!F.has(t.style))&&r.push({path:`${e}.style`,message:"is not supported"}),t.currency!==void 0&&l(t.currency,`${e}.currency`,r),t.precision!==void 0&&(!Number.isInteger(t.precision)||Number(t.precision)<0||Number(t.precision)>20)&&r.push({path:`${e}.precision`,message:"must be an integer between 0 and 20"}),I(t.unit,`${e}.unit`,r),!0):(r.push({path:e,message:"must be an object"}),!1),R=t=>{const e=[{kind:"visit",depth:0,value:t}],r=new WeakSet;let s=0,a=0;try{for(;e.length>0;){const n=e.pop();if(!n)break;if(n.kind==="leave"){r.delete(n.value);continue}if(a+=1,a>o.jsonNodes||n.depth>o.jsonDepth)return!1;if(n.value===null||typeof n.value=="boolean")continue;if(typeof n.value=="string"){if(s+=T(n.value,o.textCharacters),!u(n.value)||s>o.jsonCharacters)return!1;continue}if(typeof n.value=="number"){if(!Number.isFinite(n.value))return!1;continue}if(!Array.isArray(n.value)&&!c(n.value)||r.has(n.value))return!1;r.add(n.value),e.push({kind:"leave",value:n.value});const p=o.jsonNodes-a;if(Array.isArray(n.value)){if(n.value.length>p)return!1;for(let i=n.value.length-1;i>=0;i-=1)e.push({kind:"visit",depth:n.depth+1,value:n.value[i]})}else{const i=[];for(const h in n.value)if(Object.prototype.hasOwnProperty.call(n.value,h)){if(!u(h)||(s+=T(h,o.textCharacters),s>o.jsonCharacters)||i.length>=p)return!1;i.push(h)}for(let h=i.length-1;h>=0;h-=1){const y=i[h];e.push({kind:"visit",depth:n.depth+1,value:n.value[y]})}}}return!0}catch{return!1}},ot=t=>t===null||typeof t=="boolean"||u(t)||b(t),Y=(t,e,r)=>c(t)?(d(t,H,e,r),l(t.id,`${e}.id`,r),l(t.label,`${e}.label`,r),(typeof t.intent!="string"||!D.has(t.intent))&&r.push({path:`${e}.intent`,message:"is not supported"}),(!c(t.target)||!R(t.target))&&r.push({path:`${e}.target`,message:"must be a JSON object"}),t.appearance!==void 0&&(typeof t.appearance!="string"||!["primary","secondary","link"].includes(t.appearance))&&r.push({path:`${e}.appearance`,message:"is not supported"}),!0):(r.push({path:e,message:"must be an object"}),!1),it=(t,e)=>{if(d(t,U,"",e),t.schemaVersion!=="1.0"&&e.push({path:"schemaVersion",message:"must equal 1.0"}),l(t.id,"id",e),K.includes(t.kind)||e.push({path:"kind",message:"is not a supported Artifact kind"}),I(t.title,"title",e),I(t.summary,"summary",e),t.presentation!==void 0&&(c(t.presentation)?(d(t.presentation,z,"presentation",e),t.presentation.template!==void 0&&!P(t.presentation.template)?e.push({path:"presentation.template",message:"must be a non-empty string"}):t.presentation.template!==void 0&&!u(t.presentation.template)&&e.push({path:"presentation.template",message:`must contain at most ${o.textCharacters} characters`}),t.presentation.density!==void 0&&(typeof t.presentation.density!="string"||!["compact","comfortable"].includes(t.presentation.density))&&e.push({path:"presentation.density",message:"is not supported"})):e.push({path:"presentation",message:"must be an object"})),t.actions!==void 0){if(!Array.isArray(t.actions))e.push({path:"actions",message:"must be an array"});else if(!A(t.actions,o.actions,"actions",e)){if(S(t.actions,"actions",e))return;E(t.actions,"id","actions",e),t.actions.forEach((s,a)=>Y(s,`actions[${a}]`,e))}}t.meta!==void 0&&(!c(t.meta)||!R(t.meta))&&e.push({path:"meta",message:"must be a JSON object"})},ct=(t,e)=>{d(t,B,"data",e),!b(t.value)&&!u(t.value)&&e.push({path:"data.value",message:"must be a finite number or string"}),t.format!==void 0&&C(t.format,"data.format",e),t.delta!==void 0&&(c(t.delta)?(d(t.delta,W,"data.delta",e),b(t.delta.value)||e.push({path:"data.delta.value",message:"must be a finite number"}),t.delta.direction!==void 0&&(typeof t.delta.direction!="string"||!["up","down","flat"].includes(t.delta.direction))&&e.push({path:"data.delta.direction",message:"is not supported"}),t.delta.format!==void 0&&(typeof t.delta.format!="string"||!["decimal","percent"].includes(t.delta.format))&&e.push({path:"data.delta.format",message:"is not supported"}),I(t.delta.label,"data.delta.label",e)):e.push({path:"data.delta",message:"must be an object"})),I(t.context,"data.context",e)},dt=(t,e)=>{if(d(t,x,"data",e),!Array.isArray(t.items)||t.items.length===0){e.push({path:"data.items",message:"must be a non-empty array"});return}A(t.items,o.comparisonItems,"data.items",e)||S(t.items,"data.items",e)||(E(t.items,"id","data.items",e),t.items.forEach((r,s)=>{const a=`data.items[${s}]`;if(!c(r)){e.push({path:a,message:"must be an object"});return}d(r,G,a,e),l(r.id,`${a}.id`,e),l(r.label,`${a}.label`,e),!b(r.value)&&!u(r.value)&&e.push({path:`${a}.value`,message:"must be a finite number or string"}),r.format!==void 0&&C(r.format,`${a}.format`,e),I(r.hint,`${a}.hint`,e)}))},pt=(t,e)=>{if(d(t,Q,"data",e),!Array.isArray(t.series)||t.series.length===0){e.push({path:"data.series",message:"must be a non-empty array"});return}A(t.series,o.trendSeries,"data.series",e)||S(t.series,"data.series",e)||(E(t.series,"id","data.series",e),t.series.forEach((r,s)=>{const a=`data.series[${s}]`;if(!c(r)){e.push({path:a,message:"must be an object"});return}if(d(r,X,a,e),l(r.id,`${a}.id`,e),l(r.label,`${a}.label`,e),r.format!==void 0&&C(r.format,`${a}.format`,e),!Array.isArray(r.points)||r.points.length===0){e.push({path:`${a}.points`,message:"must be a non-empty array"});return}A(r.points,o.trendPointsPerSeries,`${a}.points`,e)||S(r.points,`${a}.points`,e)||r.points.forEach((n,p)=>{const i=`${a}.points[${p}]`;if(!c(n)){e.push({path:i,message:"must be an object"});return}d(n,Z,i,e),!b(n.x)&&!u(n.x)&&e.push({path:`${i}.x`,message:"must be a finite number or string"}),b(n.y)||e.push({path:`${i}.y`,message:"must be a finite number"})})}))},mt=(t,e)=>{if(d(t,x,"data",e),!Array.isArray(t.items)||t.items.length===0){e.push({path:"data.items",message:"must be a non-empty array"});return}A(t.items,o.rankingItems,"data.items",e)||S(t.items,"data.items",e)||(E(t.items,"id","data.items",e),t.items.forEach((r,s)=>{const a=`data.items[${s}]`;if(!c(r)){e.push({path:a,message:"must be an object"});return}d(r,tt,a,e),l(r.id,`${a}.id`,e),l(r.label,`${a}.label`,e),b(r.value)||e.push({path:`${a}.value`,message:"must be a finite number"}),r.format!==void 0&&C(r.format,`${a}.format`,e),I(r.description,`${a}.description`,e)}))},ft=(t,e)=>{if(d(t,et,"data",e),c(t.entity)?(d(t.entity,rt,"data.entity",e),l(t.entity.key,"data.entity.key",e),I(t.entity.label,"data.entity.label",e)):e.push({path:"data.entity",message:"must be an object"}),!Array.isArray(t.columns)||t.columns.length===0)e.push({path:"data.columns",message:"must be a non-empty array"});else if(!A(t.columns,o.recordColumns,"data.columns",e)){if(S(t.columns,"data.columns",e))return;E(t.columns,"key","data.columns",e),t.columns.forEach((s,a)=>{const n=`data.columns[${a}]`;if(!c(s)){e.push({path:n,message:"must be an object"});return}d(s,st,n,e),l(s.key,`${n}.key`,e),l(s.label,`${n}.label`,e),s.format!==void 0&&C(s.format,`${n}.format`,e)})}if(!Array.isArray(t.records))e.push({path:"data.records",message:"must be an array"});else if(!A(t.records,o.recordListRecords,"data.records",e)){if(S(t.records,"data.records",e))return;E(t.records,"id","data.records",e),t.records.forEach((s,a)=>{const n=`data.records[${a}]`;if(!c(s)){e.push({path:n,message:"must be an object"});return}if(d(s,nt,n,e),l(s.id,`${n}.id`,e),I(s.title,`${n}.title`,e),!c(s.values))e.push({path:`${n}.values`,message:"must contain only JSON primitive display values"});else{const p=s.values;let i=!1,h=0;for(const y in p)if(Object.prototype.hasOwnProperty.call(p,y)){if(h+=1,h>o.recordValues)break;i||=!u(y)||!ot(p[y])}h>o.recordValues?e.push({path:`${n}.values`,message:`must contain at most ${o.recordValues} values`}):i&&e.push({path:`${n}.values`,message:"must contain only JSON primitive display values"})}s.action!==void 0&&Y(s.action,`${n}.action`,e)})}t.total!==void 0&&(!Number.isInteger(t.total)||Number(t.total)<0)&&e.push({path:"data.total",message:"must be a non-negative integer"})},lt=(t,e)=>{d(t,at,"data",e),(typeof t.tone!="string"||!["info","success","warning","danger"].includes(t.tone))&&e.push({path:"data.tone",message:"is not supported"}),l(t.body,"data.body",e)},v=(t,e)=>{if(it(t,e),!c(t.data)){e.push({path:"data",message:"must be an object"});return}switch(t.kind){case"metric":ct(t.data,e);break;case"comparison":dt(t.data,e);break;case"trend":pt(t.data,e);break;case"ranking":mt(t.data,e);break;case"record-list":ft(t.data,e);break;case"notice":lt(t.data,e);break}},V=t=>{const e=new j;try{if(!c(t))return{success:!1,issues:[{path:"",message:"must be an object"}]};v(t,e)}catch{return _()}if(e.length>0)return{success:!1,issues:e};if(!R(t))return{success:!1,issues:[{path:"",message:"exceeds the Artifact resource budget"}]};let r;try{r=structuredClone(t)}catch{return _()}const s=new j;try{if(!c(r))return _();v(r,s)}catch{return _()}return s.length===0&&!R(r)&&s.push({path:"",message:"exceeds the Artifact resource budget"}),s.length===0?{success:!0,artifact:r}:{success:!1,issues:s}},k=t=>{const e=V(t);if(e.success)return e.artifact;const r=e.issues.map(s=>`${s.path||"artifact"} ${s.message}`).join(", ");throw new Error(`Invalid Make AI Artifact: ${r}`)},N=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),g=(t,e)=>{if(Object.keys(t).some(r=>!e.has(r)))throw new Error("Invalid assistant event: unsupported field")},m=(t,e,r=f.identifierCharacters)=>{const s=typeof t=="string"?w(t,r):0;if(typeof t!="string"||!t.trim()||s>r)throw new Error(`Invalid assistant event: ${e}`);return t},ht=t=>{if(!N(t)||typeof t.type!="string")throw new Error("Invalid assistant event: data");switch(t.type){case"message.start":return g(t,new Set(["type","runId","messageId"])),{type:t.type,runId:m(t.runId,"runId"),messageId:m(t.messageId,"messageId")};case"message.delta":if(g(t,new Set(["type","messageId","delta"])),typeof t.delta!="string")throw new Error("Invalid assistant event: delta");return{type:t.type,messageId:m(t.messageId,"messageId"),delta:t.delta};case"message.replace":return g(t,new Set(["type","messageId","content"])),{type:t.type,messageId:m(t.messageId,"messageId"),content:m(t.content,"content",f.messageCharacters)};case"message.complete":return g(t,new Set(["type","messageId"])),{type:t.type,messageId:m(t.messageId,"messageId")};case"artifact":return g(t,new Set(["type","messageId","artifact"])),{type:t.type,messageId:m(t.messageId,"messageId"),artifact:k(t.artifact)};case"run.progress":return g(t,new Set(["type","runId","message"])),{type:t.type,runId:m(t.runId,"runId"),message:m(t.message,"message",f.messageCharacters)};case"error":if(g(t,new Set(["type","code","message","retryable","requestId"])),typeof t.retryable!="boolean")throw new Error("Invalid assistant event: retryable");return{type:t.type,code:m(t.code,"code"),message:m(t.message,"message",f.messageCharacters),retryable:t.retryable,requestId:t.requestId===void 0?void 0:m(t.requestId,"requestId")};case"run.cancelled":return g(t,new Set(["type","runId"])),{type:t.type,runId:t.runId===void 0?void 0:m(t.runId,"runId")};case"run.complete":return g(t,new Set(["type","runId","threadId"])),{type:t.type,runId:m(t.runId,"runId"),threadId:m(t.threadId,"threadId")};default:throw new Error("Invalid assistant event: unsupported type")}},gt=t=>{try{return ht(t)}catch(e){throw e instanceof Error&&(e.message.startsWith("Invalid assistant event:")||e.message.startsWith("Invalid Make AI Artifact:"))?e:new Error("Invalid assistant event: data")}},ut=t=>{if(!N(t))throw new Error("Invalid assistant conversation snapshot: data");if(g(t,new Set(["threadId","messages"])),!Array.isArray(t.messages)||t.messages.length>f.historyMessages)throw new Error("Invalid assistant conversation snapshot: messages");const e=new Set;let r=0,s=0;return{messages:t.messages.map(n=>{if(!N(n))throw new Error("Invalid assistant conversation snapshot: message");g(n,new Set(["id","role","content","artifacts"]));const p=m(n.id,"messageId");if(e.has(p))throw new Error("Invalid assistant conversation snapshot: duplicate message id");if(e.add(p),n.role!=="assistant"&&n.role!=="user")throw new Error("Invalid assistant conversation snapshot: role");const i=n.role,h=typeof n.content=="string"?w(n.content,f.messageCharacters):0;if(typeof n.content!="string"||h>f.messageCharacters)throw new Error("Invalid assistant conversation snapshot: content");if(r+=w(n.content,f.historyCharacters-r),r>f.historyCharacters)throw new Error("Invalid assistant conversation snapshot: content budget");if(n.artifacts!==void 0&&(!Array.isArray(n.artifacts)||n.artifacts.length>f.artifactsPerRun))throw new Error("Invalid assistant conversation snapshot: artifacts");const y=(n.artifacts??[]).map(k),O=new Set;for(const M of y){if(O.has(M.id))throw new Error("Invalid assistant conversation snapshot: duplicate artifact id");O.add(M.id)}if(s+=y.length,s>f.historyArtifacts)throw new Error("Invalid assistant conversation snapshot: artifact budget");return{id:p,role:i,content:n.content,artifacts:y,status:"complete"}}),status:"idle",threadId:t.threadId===void 0?void 0:m(t.threadId,"threadId")}},yt=t=>t===void 0?{messages:[],status:"idle"}:ut(t),It=(t,e)=>({...t,error:void 0,progress:void 0,status:"streaming",messages:[...t.messages,{id:e.id,role:"user",content:e.content,artifacts:[],status:"complete"}]}),$=(t,e,r)=>({...t,messages:t.messages.map(s=>s.id===e?r(s):s)}),L=t=>{const e=t.slice(-f.progressStepsPerRun),r=[];let s=0;for(let a=e.length-1;a>=0;a-=1){const n=e[a],p=w(n,f.progressCharactersPerRun-s);if(s+p>f.progressCharactersPerRun)break;s+=p,r.unshift(n)}return r},bt=(t,e)=>{let r=-1;for(let s=t.length-1;s>=0;s-=1){const a=t[s];if(a.role==="assistant"&&a.status==="streaming"){r=s;break}}return r<0?t:t.map((s,a)=>a===r?{...s,progressSteps:L([...s.progressSteps??[],e])}:s)},At=(t,e)=>{switch(e.type){case"message.start":{const r=t.progress?.runId===e.runId?t.progress.steps:void 0;return{...t,activeRunId:e.runId,error:void 0,progress:t.progress?.runId===e.runId?t.progress:void 0,status:"streaming",messages:[...t.messages,{id:e.messageId,role:"assistant",content:"",artifacts:[],progressSteps:r,status:"streaming"}]}}case"message.delta":return $(t,e.messageId,r=>({...r,content:`${r.content}${e.delta}`}));case"message.replace":return $(t,e.messageId,r=>({...r,content:e.content}));case"artifact":return $(t,e.messageId,r=>({...r,artifacts:[...r.artifacts,e.artifact]}));case"message.complete":return $(t,e.messageId,r=>({...r,status:"complete"}));case"run.progress":{const r=L(t.progress?.runId===e.runId?[...t.progress.steps,e.message]:[e.message]);return{...t,messages:bt(t.messages,e.message),progress:{runId:e.runId,message:e.message,steps:r}}}case"error":{const r={code:e.code,message:e.message,retryable:e.retryable,requestId:e.requestId};return{...t,activeRunId:void 0,error:r,progress:void 0,messages:t.messages.map(s=>s.status==="streaming"?{...s,error:r,status:"complete"}:s),status:"error"}}case"run.cancelled":return{...t,activeRunId:void 0,progress:void 0,status:"idle",messages:t.messages.map(r=>r.status==="streaming"?{...r,status:"complete"}:r)};case"run.complete":return{...t,activeRunId:void 0,error:void 0,progress:void 0,messages:t.messages.map(r=>r.status==="streaming"?{...r,status:"complete"}:r),status:"idle",threadId:e.threadId}}};exports.MAKE_AI_ARTIFACT_KINDS=K;exports.MAKE_AI_ARTIFACT_LIMITS=o;exports.MAKE_AI_ARTIFACT_SCHEMA_VERSION="1.0";exports.MAKE_AI_CONVERSATION_LIMITS=f;exports.appendUserMessage=It;exports.countCodePointsUpTo=w;exports.createAssistantConversationState=yt;exports.parseArtifact=k;exports.parseAssistantEvent=gt;exports.reduceAssistantEvent=At;exports.validateArtifact=V;
|
|
@@ -8,12 +8,19 @@ export interface AssistantRunRequest {
|
|
|
8
8
|
context: MakeAssistantHostContext;
|
|
9
9
|
capabilities: ArtifactCapabilities;
|
|
10
10
|
}
|
|
11
|
+
export interface AssistantRegenerateRequest extends AssistantRunRequest {
|
|
12
|
+
assistantMessage: {
|
|
13
|
+
id: string;
|
|
14
|
+
content: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
11
17
|
export interface AssistantTransportOptions {
|
|
12
18
|
signal?: AbortSignal;
|
|
13
19
|
}
|
|
14
20
|
export interface AssistantTransportFeatures {
|
|
15
21
|
history: boolean;
|
|
16
22
|
newConversation: boolean;
|
|
23
|
+
regeneration?: boolean;
|
|
17
24
|
remoteCancellation: boolean;
|
|
18
25
|
}
|
|
19
26
|
export interface AssistantConversationSnapshotMessage {
|
|
@@ -30,6 +37,7 @@ export interface AssistantTransport {
|
|
|
30
37
|
readonly features?: Partial<AssistantTransportFeatures>;
|
|
31
38
|
loadConversation?(context: MakeAssistantHostContext, options?: AssistantTransportOptions): Promise<AssistantConversationSnapshot>;
|
|
32
39
|
run(request: AssistantRunRequest, options?: AssistantTransportOptions): AsyncIterable<AssistantEvent>;
|
|
40
|
+
regenerate?(request: AssistantRegenerateRequest, options?: AssistantTransportOptions): AsyncIterable<AssistantEvent>;
|
|
33
41
|
}
|
|
34
42
|
export type AssistantEvent = {
|
|
35
43
|
type: "message.start";
|
|
@@ -73,7 +81,9 @@ export interface AssistantMessage {
|
|
|
73
81
|
id: string;
|
|
74
82
|
role: "assistant" | "user";
|
|
75
83
|
content: string;
|
|
84
|
+
error?: AssistantConversationError;
|
|
76
85
|
artifacts: MakeAiArtifact[];
|
|
86
|
+
progressSteps?: string[];
|
|
77
87
|
status: "complete" | "streaming";
|
|
78
88
|
}
|
|
79
89
|
export interface AssistantConversationError {
|
|
@@ -89,6 +99,7 @@ export interface AssistantConversationState {
|
|
|
89
99
|
progress?: {
|
|
90
100
|
runId: string;
|
|
91
101
|
message: string;
|
|
102
|
+
steps: string[];
|
|
92
103
|
};
|
|
93
104
|
status: "idle" | "streaming" | "error";
|
|
94
105
|
threadId?: string;
|
package/dist/core/types.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export declare const MAKE_AI_CONVERSATION_LIMITS: {
|
|
|
26
26
|
readonly historyMessages: 200;
|
|
27
27
|
readonly identifierCharacters: 1000;
|
|
28
28
|
readonly messageCharacters: 100000;
|
|
29
|
+
readonly progressCharactersPerRun: 20000;
|
|
30
|
+
readonly progressStepsPerRun: 50;
|
|
29
31
|
};
|
|
30
32
|
export declare const MAKE_AI_ARTIFACT_KINDS: readonly ["metric", "comparison", "trend", "ranking", "record-list", "notice"];
|
|
31
33
|
export type ArtifactKind = (typeof MAKE_AI_ARTIFACT_KINDS)[number];
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./conversation-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./conversation-Cv1wdvCR.cjs"),p=r=>{const e=new Set;for(const t of r){if(!t.id.trim())throw new Error("Artifact template id must not be empty");if(e.has(t.id))throw new Error(`Duplicate artifact template id: ${t.id}`);if(t.kinds.length===0)throw new Error(`Artifact template must support at least one kind: ${t.id}`);if(t.kinds.some(n=>!i.MAKE_AI_ARTIFACT_KINDS.includes(n)))throw new Error(`Unsupported Artifact template kind: ${t.id}`);if(t.priority!==void 0&&!Number.isFinite(t.priority))throw new Error(`Artifact template priority must be finite: ${t.id}`);if(typeof t.render!="function")throw new Error(`Artifact template render must be a function: ${t.id}`);if(t.canRender!==void 0&&typeof t.canRender!="function")throw new Error(`Artifact template canRender must be a function: ${t.id}`);e.add(t.id)}},c=(r=[])=>{p(r);const e=r.map(t=>Object.freeze({...t,kinds:Object.freeze([...t.kinds])}));return Object.freeze({templates:Object.freeze(e)})},d=(r,e)=>c([...r.templates,...e]),A=(r,e,t)=>r.kinds.includes(e.kind)&&(r.canRender?.(e,t)??!0),f=(r,e,t)=>{const n=e.presentation?.template;if(n){const a=r.templates.find(s=>s.id===n&&A(s,e,t));if(a)return{template:a,reason:"requested"}}const o=r.templates.map((a,s)=>({template:a,registrationIndex:s})).filter(({template:a})=>A(a,e,t)).sort((a,s)=>(s.template.priority??0)-(a.template.priority??0)||a.registrationIndex-s.registrationIndex);return o[0]?{template:o[0].template,reason:"priority"}:void 0},l=r=>({artifactSchemaVersions:[i.MAKE_AI_ARTIFACT_SCHEMA_VERSION],artifactKinds:Array.from(new Set(r.templates.flatMap(e=>e.kinds))).sort(),templates:r.templates.map(e=>e.id).sort()});exports.MAKE_AI_ARTIFACT_KINDS=i.MAKE_AI_ARTIFACT_KINDS;exports.MAKE_AI_ARTIFACT_LIMITS=i.MAKE_AI_ARTIFACT_LIMITS;exports.MAKE_AI_ARTIFACT_SCHEMA_VERSION=i.MAKE_AI_ARTIFACT_SCHEMA_VERSION;exports.MAKE_AI_CONVERSATION_LIMITS=i.MAKE_AI_CONVERSATION_LIMITS;exports.appendUserMessage=i.appendUserMessage;exports.createAssistantConversationState=i.createAssistantConversationState;exports.parseArtifact=i.parseArtifact;exports.parseAssistantEvent=i.parseAssistantEvent;exports.reduceAssistantEvent=i.reduceAssistantEvent;exports.validateArtifact=i.validateArtifact;exports.createArtifactCapabilities=l;exports.createArtifactTemplateRegistry=c;exports.extendArtifactTemplateRegistry=d;exports.resolveArtifactTemplate=f;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { f as p, d } from "./conversation-
|
|
2
|
-
import { e as E, M as T, b, a as _, g as R, p as y, r as M, v as S } from "./conversation-
|
|
1
|
+
import { f as p, d } from "./conversation-B7eGUXi-.js";
|
|
2
|
+
import { e as E, M as T, b, a as _, g as R, p as y, r as M, v as S } from "./conversation-B7eGUXi-.js";
|
|
3
3
|
const c = (r) => {
|
|
4
4
|
const e = /* @__PURE__ */ new Set();
|
|
5
5
|
for (const t of r) {
|
package/dist/make-app.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("./sse.cjs"),I=require("./conversation-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("./sse.cjs"),I=require("./conversation-Cv1wdvCR.cjs"),m=100,M={AI_AGENT_UNAVAILABLE:"当前 App 尚未配置可用的 AI 助手。",AI_APP_UNAVAILABLE:"当前 App 暂不可用。",AI_AUTH_EXPIRED:"登录已失效,请重新登录。",AI_AUTH_REQUIRED:"登录已失效,请重新登录。",AI_FORBIDDEN:"当前账号无权使用该 AI 助手。",AI_RUN_FAILED:"本次 AI 处理失败,请重试。",AI_UPSTREAM_ERROR:"AI 服务暂时不可用,请稍后重试。"},u=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),h=(e,a,i=I.MAKE_AI_CONVERSATION_LIMITS.identifierCharacters)=>{if(typeof e!="string"||!e.trim()||I.countCodePointsUpTo(e,i)>i)throw new Error(`Invalid Make App assistant response: ${a}`);return e},_=e=>{if(!u(e))throw new Error("Invalid Make App assistant response: locate");return{chatId:h(e.chatId,"chatId")}},v=e=>{if(!u(e))throw new Error("Invalid Make App assistant response: send");const a=e.acceptedCursor;if(!Number.isSafeInteger(a)||Number(a)<0)throw new Error("Invalid Make App assistant response: acceptedCursor");return{acceptedCursor:a,chatId:h(e.chatId,"chatId"),responseId:h(e.responseId,"responseId")}},S=(e,a,i)=>{if(!u(e)||!Array.isArray(e.messages)||e.messages.length>i)throw new Error("Invalid Make App assistant response: history");const c=new Set;let o=0;const t=e.messages.map(s=>{if(!u(s))throw new Error("Invalid Make App assistant response: history message");if(s.role!=="user"&&s.role!=="assistant")throw new Error("Invalid Make App assistant response: history role");const r=s.role;if(!Number.isSafeInteger(s.cursor)||Number(s.cursor)<0)throw new Error("Invalid Make App assistant response: history cursor");const p=`history-${a}-${String(s.cursor)}`;if(c.has(p))throw new Error("Invalid Make App assistant response: duplicate history cursor");c.add(p);const d=h(s.text,"history text",I.MAKE_AI_CONVERSATION_LIMITS.messageCharacters);if(o+=I.countCodePointsUpTo(d,I.MAKE_AI_CONVERSATION_LIMITS.historyCharacters-o),o>I.MAKE_AI_CONVERSATION_LIMITS.historyCharacters)throw new Error("Invalid Make App assistant response: history text budget");return{id:p,role:r,content:d,artifacts:[]}});return{threadId:a,messages:t}},k=()=>{const e=[],a=[];return{next:()=>{const o=e.shift();return o?Promise.resolve(o):new Promise(t=>a.push(t))},push:o=>{const t=a.shift();t?t(o):e.push(o)}}},T=(e,a)=>{if(I.countCodePointsUpTo(e.data,a)>a)throw new Error("Make App assistant SSE event exceeds maxEventCharacters");try{const i=JSON.parse(e.data);if(!u(i))throw new Error("invalid data");return i}catch{throw new Error("Invalid Make App assistant SSE JSON")}},E=()=>new DOMException("Aborted","AbortError"),A=e=>{if(e?.aborted)throw E()},C=async function*(e,a){const i=`assistant:${e.responseId}`;A(a?.signal),yield{type:"message.start",runId:e.responseId,messageId:i};const c=k(),o=e.eventSourceFactory({chatId:e.chatId,responseId:e.responseId,cursor:"0-0"},{withCredentials:!0});let t=!1;const s=n=>{t||(t=!0,c.push(n))},r=new Map,p=(n,l)=>{const y=g=>{if(!t)try{l(T(g,e.maxEventCharacters))}catch(f){s({type:"error",error:f})}};r.set(n,y),o.addEventListener(n,y)};p("run.started",()=>{c.push({type:"event",event:{type:"run.progress",runId:e.responseId,message:"正在分析"}})}),p("response.progress",n=>{c.push({type:"event",event:{type:"run.progress",runId:e.responseId,message:h(n.message,"progress message",I.MAKE_AI_CONVERSATION_LIMITS.messageCharacters)}})}),p("response.delta",n=>{if(typeof n.text!="string")throw new Error("Invalid Make App assistant response: delta text");c.push({type:"event",event:{type:"message.delta",messageId:i,delta:n.text}})}),p("response.message",n=>{c.push({type:"event",event:{type:"message.replace",messageId:i,content:h(n.text,"message text",I.MAKE_AI_CONVERSATION_LIMITS.messageCharacters)}})}),p("response.completed",()=>{c.push({type:"event",event:{type:"message.complete",messageId:i}}),c.push({type:"event",event:{type:"run.complete",runId:e.responseId,threadId:e.chatId}}),s({type:"done"})}),p("response.failed",n=>{const l=h(n.code,"failure code");s({type:"event",event:{type:"error",code:l,message:M[l]??"本次 AI 处理失败,请重试。",retryable:!["AI_AUTH_REQUIRED","AI_AUTH_EXPIRED","AI_FORBIDDEN","AI_APP_UNAVAILABLE","AI_AGENT_UNAVAILABLE"].includes(l),requestId:e.responseId}})}),o.onerror=()=>{t||o.readyState!==void 0&&o.readyState!==2||s({type:"error",error:new Error("Make App assistant SSE disconnected")})};const d=()=>s({type:"error",error:E()});a?.signal?.addEventListener("abort",d,{once:!0}),a?.signal?.aborted&&d();try{for(;;){const n=await c.next();if(n.type==="done")return;if(n.type==="error")throw n.error;if(yield n.event,n.event.type==="error")return}}finally{t=!0,a?.signal?.removeEventListener("abort",d),o.onerror=null;for(const[n,l]of r)o.removeEventListener(n,l);o.close()}},N=e=>{const a=e.eventSourceFactory,i=e.historyLimit??m,c=e.maxEventCharacters??w.DEFAULT_MAX_SSE_EVENT_CHARACTERS;if(!Number.isInteger(i)||i<1||i>100)throw new Error("historyLimit must be an integer between 1 and 100");if(!Number.isInteger(c)||c<=0)throw new Error("maxEventCharacters must be a positive integer");const o=async(t,s)=>{A(s?.signal),console.info("[make-ai-assistant] Make App chat locate start",{appId:t.app.id});const{chatId:r}=_(await e.locateChat(t,{signal:s?.signal}));return A(s?.signal),console.info("[make-ai-assistant] Make App chat locate success",{appId:t.app.id}),r};return{features:{history:!0,newConversation:!1,regeneration:!1,remoteCancellation:!1},async loadConversation(t,s){console.info("[make-ai-assistant] Make App history load start",{appId:t.app.id});try{A(s?.signal);const r=await o(t,s),p=await e.loadHistory({chatId:r,cursor:-1,limit:i},{signal:s?.signal});A(s?.signal);const d=S(p,r,i);return console.info("[make-ai-assistant] Make App history load success",{appId:t.app.id,messageCount:d.messages.length}),d}catch(r){throw(s?.signal?.aborted?console.info:console.error)(s?.signal?.aborted?"[make-ai-assistant] Make App history load cancelled":"[make-ai-assistant] Make App history load failed",{appId:t.app.id,errorType:r instanceof Error?r.name:typeof r}),r}},async*run(t,s){console.info("[make-ai-assistant] Make App run start",{appId:t.context.app.id});try{A(s?.signal);const r=await o(t.context,s),p=v(await e.sendMessage({chatId:r,messageId:t.message.id,text:t.message.content},{signal:s?.signal}));if(A(s?.signal),p.chatId!==r)throw new Error("Invalid Make App assistant response: chatId mismatch");for await(const d of C({chatId:r,responseId:p.responseId,eventSourceFactory:a,maxEventCharacters:c},s))yield d;console.info("[make-ai-assistant] Make App run complete",{appId:t.context.app.id})}catch(r){throw s?.signal?.aborted?console.info("[make-ai-assistant] Make App run cancelled",{appId:t.context.app.id}):console.error("[make-ai-assistant] Make App run failed",{appId:t.context.app.id,errorType:r instanceof Error?r.name:typeof r}),r}}}};exports.createMakeAppAssistantTransport=N;
|
package/dist/make-app.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DEFAULT_MAX_SSE_EVENT_CHARACTERS as m } from "./sse.mjs";
|
|
2
|
-
import { M as A, c as u } from "./conversation-
|
|
2
|
+
import { M as A, c as u } from "./conversation-B7eGUXi-.js";
|
|
3
3
|
const v = 100, k = {
|
|
4
4
|
AI_AGENT_UNAVAILABLE: "当前 App 尚未配置可用的 AI 助手。",
|
|
5
5
|
AI_APP_UNAVAILABLE: "当前 App 暂不可用。",
|
|
@@ -81,8 +81,8 @@ const v = 100, k = {
|
|
|
81
81
|
} catch {
|
|
82
82
|
throw new Error("Invalid Make App assistant SSE JSON");
|
|
83
83
|
}
|
|
84
|
-
},
|
|
85
|
-
if (e?.aborted) throw
|
|
84
|
+
}, g = () => new DOMException("Aborted", "AbortError"), I = (e) => {
|
|
85
|
+
if (e?.aborted) throw g();
|
|
86
86
|
}, C = async function* (e, a) {
|
|
87
87
|
const i = `assistant:${e.responseId}`;
|
|
88
88
|
I(a?.signal), yield {
|
|
@@ -99,10 +99,10 @@ const v = 100, k = {
|
|
|
99
99
|
const s = (n) => {
|
|
100
100
|
t || (t = !0, c.push(n));
|
|
101
101
|
}, r = /* @__PURE__ */ new Map(), p = (n, l) => {
|
|
102
|
-
const f = (
|
|
102
|
+
const f = (E) => {
|
|
103
103
|
if (!t)
|
|
104
104
|
try {
|
|
105
|
-
l(b(
|
|
105
|
+
l(b(E, e.maxEventCharacters));
|
|
106
106
|
} catch (w) {
|
|
107
107
|
s({ type: "error", error: w });
|
|
108
108
|
}
|
|
@@ -184,7 +184,7 @@ const v = 100, k = {
|
|
|
184
184
|
}), o.onerror = () => {
|
|
185
185
|
t || o.readyState !== void 0 && o.readyState !== 2 || s({ type: "error", error: new Error("Make App assistant SSE disconnected") });
|
|
186
186
|
};
|
|
187
|
-
const d = () => s({ type: "error", error:
|
|
187
|
+
const d = () => s({ type: "error", error: g() });
|
|
188
188
|
a?.signal?.addEventListener("abort", d, { once: !0 }), a?.signal?.aborted && d();
|
|
189
189
|
try {
|
|
190
190
|
for (; ; ) {
|
|
@@ -220,6 +220,7 @@ const v = 100, k = {
|
|
|
220
220
|
features: {
|
|
221
221
|
history: !0,
|
|
222
222
|
newConversation: !1,
|
|
223
|
+
regeneration: !1,
|
|
223
224
|
remoteCancellation: !1
|
|
224
225
|
},
|
|
225
226
|
async loadConversation(t, s) {
|
package/dist/make-console.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./sse.cjs"),E=require("./conversation-Yku9Lzj_.cjs"),M=4e3,x=200,U=30,P=1e3,K={AI_AGENT_UNAVAILABLE:"当前应用没有可用 Agent。",AI_AUTH_EXPIRED:"登录已失效,请重新登录。",AI_AUTH_REQUIRED:"登录已失效,请重新登录。",AI_FORBIDDEN:"当前账号无权使用该 AI 助手。",AI_RUN_FAILED:"本次 AI 处理失败,请重试。",AI_UPSTREAM_ERROR:"AI 服务暂时不可用,请稍后重试。"},O=new Set(["AI_AGENT_UNAVAILABLE","AI_AUTH_EXPIRED","AI_AUTH_REQUIRED","AI_FORBIDDEN"]),y=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),A=(e,t,n=E.MAKE_AI_CONVERSATION_LIMITS.identifierCharacters)=>{if(typeof e!="string"||!e.trim()||E.countCodePointsUpTo(e,n)>n)throw new Error(`Invalid Make Console assistant response: ${t}`);return e},S=(e,t)=>{if(!(e==null||e===""))return A(e,t)},m=(e,t)=>{if(!Number.isSafeInteger(e)||Number(e)<0)throw new Error(`Invalid Make Console assistant response: ${t}`);return Number(e)},k=()=>new DOMException("Aborted","AbortError"),u=e=>{if(e?.aborted)throw k()},q=(e,t)=>(u(t),e===0?Promise.resolve():new Promise((n,i)=>{const f=setTimeout(()=>{t?.removeEventListener("abort",I),n()},e),I=()=>{clearTimeout(f),t?.removeEventListener("abort",I),i(k())};t?.addEventListener("abort",I,{once:!0})})),F=e=>{if(!y(e)||!Array.isArray(e.agents)||e.agents.length>1e3)throw new Error("Invalid Make Console assistant response: agents");const t=new Set;return e.agents.map(n=>{if(!y(n))throw new Error("Invalid Make Console assistant response: agent");const i=A(n.agentID,"agentID");if(t.has(i))throw new Error("Invalid Make Console assistant response: duplicate agentID");return t.add(i),{agentID:i,...typeof n.name=="string"&&n.name.trim()?{name:A(n.name,"agent name")}:{},status:A(n.status,"agent status")}})},V=e=>{if(!y(e))throw new Error("Invalid Make Console assistant response: session");return{nextSeq:m(e.nextSeq,"nextSeq"),sessionID:A(e.sessionID,"sessionID")}},H=e=>{if(!y(e))throw new Error("Invalid Make Console assistant response: sent message");const t=S(e.runID,"runID"),n=S(e.mergedInto,"mergedInto");if(t&&n)throw new Error("Invalid Make Console assistant response: multiple Run IDs");return{effectiveRunID:t??n,seq:m(e.seq,"seq"),sessionID:A(e.sessionID,"sessionID")}},$=e=>{if(!y(e)||!Array.isArray(e.blocks)||e.blocks.length>1e3)throw new Error("Invalid Make Console assistant response: payload blocks");let t="";for(const n of e.blocks)if(!(!y(n)||n.kind!=="text"||typeof n.text!="string")&&(t+=n.text,E.countCodePointsUpTo(t,E.MAKE_AI_CONVERSATION_LIMITS.messageCharacters)>E.MAKE_AI_CONVERSATION_LIMITS.messageCharacters))throw new Error("Invalid Make Console assistant response: message text budget");return A(t,"message text",E.MAKE_AI_CONVERSATION_LIMITS.messageCharacters)},T=(e,t)=>{if(!Array.isArray(e)||e.length>t)throw new Error("Invalid Make Console assistant response: durable events");const n=new Set;return e.flatMap(i=>{if(!y(i))throw new Error("Invalid Make Console assistant response: durable event");const c=m(i.seq,"event seq");if(n.has(c))throw new Error("Invalid Make Console assistant response: duplicate event seq");n.add(c);const f=typeof i.type=="string"?i.type:"",I=y(i.actor)&&typeof i.actor.kind=="string"?i.actor.kind:"";return!(f==="user_message")&&!(f==="message"&&I==="agent")?[]:[{actorKind:I,content:$(i.payload),runID:S(i.runID,"event runID"),seq:c,type:f}]})},G=(e,t,n)=>{const i=T(e,n);let c=0;return{messages:i.map(I=>{if(c+=E.countCodePointsUpTo(I.content,E.MAKE_AI_CONVERSATION_LIMITS.historyCharacters-c),c>E.MAKE_AI_CONVERSATION_LIMITS.historyCharacters)throw new Error("Invalid Make Console assistant response: history text budget");return{artifacts:[],content:I.content,id:`console-${t}-${String(I.seq)}`,role:I.type==="user_message"?"user":"assistant"}}),threadId:t}},B=()=>{const e=[],t=[];return{next:()=>{const c=e.shift();return c?Promise.resolve(c):new Promise(f=>t.push(f))},push:c=>{const f=t.shift();f?f(c):e.push(c)}}},X=(e,t)=>{if(E.countCodePointsUpTo(e.data,t)>t)throw new Error("Make Console assistant SSE event exceeds maxEventCharacters");try{const n=JSON.parse(e.data);if(!y(n))throw new Error("invalid data");return n}catch{throw new Error("Invalid Make Console assistant SSE JSON")}},b=(e,t)=>{if(!Number.isInteger(e)||e<1)throw new Error(`${t} must be a positive integer`)},Q=(e,t,n)=>T(e,t).find(c=>c.type==="message"&&c.actorKind==="agent"&&(n===void 0||c.runID===n)),j=e=>{const t=e.historyLimit??x,n=e.maxEventCharacters??N.DEFAULT_MAX_SSE_EVENT_CHARACTERS,i=e.maxPollingAttempts??U,c=e.pollIntervalMs??P,f=e.wait??q;if(!Number.isInteger(t)||t<1||t>200)throw new Error("historyLimit must be an integer between 1 and 200");if(b(n,"maxEventCharacters"),b(i,"maxPollingAttempts"),!Number.isInteger(c)||c<0)throw new Error("pollIntervalMs must be a non-negative integer");const I=async(s,r)=>{u(r?.signal),console.info("[make-ai-assistant] Make Console Agent lookup start",{appId:s.app.id});const o=F(await e.listAgents({appKey:s.app.id},{signal:r?.signal}));u(r?.signal);const l=o.filter(g=>g.status==="enabled"),p=e.selectAgent?e.selectAgent(l,s):l[0]?.agentID,d=l.find(g=>g.agentID===p);if(!d)throw new Error("当前应用没有可用 Agent");return console.info("[make-ai-assistant] Make Console Agent lookup success",{appId:s.app.id,enabledAgentCount:l.length}),d},C=async(s,r,o)=>(u(o?.signal),V(await e.getOrCreateSession({agentID:r,appKey:s.app.id},{signal:o?.signal}))),_=async s=>{for(let r=1;r<=i;r+=1){u(s.signal);const o=await e.loadEvents({agentID:s.agentID,appKey:s.appKey,from:s.from,limit:t,sessionID:s.sessionID},{signal:s.signal});u(s.signal);const l=Q(o,t,s.effectiveRunID);if(l)return l;r<i&&await f(c,s.signal)}throw new Error("Make Console assistant durable response unavailable")},L=async function*(s){u(s.signal);const r=B(),o=e.eventSourceFactory({agentID:s.agentID,appKey:s.appKey,cursor:"0-0",runID:s.effectiveRunID,sessionID:s.sessionID},{withCredentials:!0});let l=!1;const p=a=>{l||(l=!0,r.push(a))},d=new Map,g=(a,h)=>{const D=v=>{if(!l)try{h(X(v,n),v)}catch(R){p({type:"error",error:R})}};d.set(a,D),o.addEventListener(a,D)};g("ready",a=>{if(typeof a.after!="string")throw new Error("Invalid Make Console assistant response: ready cursor")}),g("run-output",a=>{if(A(a.runID,"SSE runID")!==s.effectiveRunID)throw new Error("Invalid Make Console assistant response: SSE runID mismatch");m(a.sequence,"SSE sequence");const h=A(a.type,"SSE output type");if(h==="output_text.delta"){if(typeof a.delta!="string")throw new Error("Invalid Make Console assistant response: SSE delta");r.push({type:"event",event:{type:"message.delta",messageId:s.messageId,delta:a.delta}})}else h==="response.completed"?p({type:"completed"}):h==="response.failed"&&p({type:"failed",code:A(a.failureCode,"failureCode")})}),g("fallback",a=>{if(a.reason!=="stream_unavailable")throw new Error("Invalid Make Console assistant response: fallback reason");p({type:"fallback"})}),o.onerror=()=>{l||o.readyState!==void 0&&o.readyState!==2||p({type:"error",error:new Error("Make Console assistant SSE disconnected")})};const w=()=>p({type:"error",error:k()});s.signal?.addEventListener("abort",w,{once:!0}),s.signal?.aborted&&w();try{for(;;){const a=await r.next();if(a.type==="event")yield a.event;else{if(a.type==="completed"||a.type==="fallback")return a.type;if(a.type==="failed")return yield{type:"error",code:a.code,message:K[a.code]??"本次 AI 处理失败,请重试。",retryable:!O.has(a.code),requestId:s.effectiveRunID},"failed";throw a.error}}}finally{l=!0,s.signal?.removeEventListener("abort",w),o.onerror=null;for(const[a,h]of d)o.removeEventListener(a,h);o.close()}};return{features:{history:!0,newConversation:!1,remoteCancellation:!1},async loadConversation(s,r){console.info("[make-ai-assistant] Make Console history load start",{appId:s.app.id});try{const o=await I(s,r),l=await C(s,o.agentID,r),p=Math.max(0,l.nextSeq-t),d=await e.loadEvents({agentID:o.agentID,appKey:s.app.id,from:p,limit:t,sessionID:l.sessionID},{signal:r?.signal});u(r?.signal);const g=G(d,l.sessionID,t);return console.info("[make-ai-assistant] Make Console history load success",{appId:s.app.id,messageCount:g.messages.length}),g}catch(o){throw(r?.signal?.aborted?console.info:console.error)(r?.signal?.aborted?"[make-ai-assistant] Make Console history load cancelled":"[make-ai-assistant] Make Console history load failed",{appId:s.app.id,errorType:o instanceof Error?o.name:typeof o}),o}},async*run(s,r){console.info("[make-ai-assistant] Make Console run start",{appId:s.context.app.id});try{const o=s.message.content.trim();if(!o||E.countCodePointsUpTo(o,M)>M)throw new Error(o?"Console 消息不能超过 4000 个字符":"Console 消息不能为空");const l=await I(s.context,r),p=await C(s.context,l.agentID,r);u(r?.signal);const d=H(await e.sendMessage({agentID:l.agentID,appKey:s.context.app.id,text:o},{signal:r?.signal}));if(u(r?.signal),d.sessionID!==p.sessionID)throw new Error("Invalid Make Console assistant response: sessionID mismatch");const g=d.effectiveRunID??`${d.sessionID}:${String(d.seq)}`,w=`assistant:${g}`;if(yield{type:"message.start",runId:g,messageId:w},d.effectiveRunID){const D=yield*L({agentID:l.agentID,appKey:s.context.app.id,effectiveRunID:d.effectiveRunID,messageId:w,sessionID:d.sessionID,signal:r?.signal});if(D==="failed")return;D==="fallback"&&console.info("[make-ai-assistant] Make Console SSE fallback",{appId:s.context.app.id})}const a=await _({agentID:l.agentID,appKey:s.context.app.id,effectiveRunID:d.effectiveRunID,from:d.seq+1,sessionID:d.sessionID,signal:r?.signal});yield{type:"message.replace",messageId:w,content:a.content},yield{type:"message.complete",messageId:w},yield{type:"run.complete",runId:g,threadId:d.sessionID},console.info("[make-ai-assistant] Make Console run complete",{appId:s.context.app.id})}catch(o){throw r?.signal?.aborted?console.info("[make-ai-assistant] Make Console run cancelled",{appId:s.context.app.id}):console.error("[make-ai-assistant] Make Console run failed",{appId:s.context.app.id,errorType:o instanceof Error?o.name:typeof o}),o}}}};exports.MAKE_CONSOLE_MESSAGE_CHARACTERS=M;exports.createMakeConsoleAssistantTransport=j;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./sse.cjs"),E=require("./conversation-Cv1wdvCR.cjs"),M=4e3,x=200,U=30,P=1e3,K={AI_AGENT_UNAVAILABLE:"当前应用没有可用 Agent。",AI_AUTH_EXPIRED:"登录已失效,请重新登录。",AI_AUTH_REQUIRED:"登录已失效,请重新登录。",AI_FORBIDDEN:"当前账号无权使用该 AI 助手。",AI_RUN_FAILED:"本次 AI 处理失败,请重试。",AI_UPSTREAM_ERROR:"AI 服务暂时不可用,请稍后重试。"},O=new Set(["AI_AGENT_UNAVAILABLE","AI_AUTH_EXPIRED","AI_AUTH_REQUIRED","AI_FORBIDDEN"]),y=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),A=(e,t,n=E.MAKE_AI_CONVERSATION_LIMITS.identifierCharacters)=>{if(typeof e!="string"||!e.trim()||E.countCodePointsUpTo(e,n)>n)throw new Error(`Invalid Make Console assistant response: ${t}`);return e},S=(e,t)=>{if(!(e==null||e===""))return A(e,t)},m=(e,t)=>{if(!Number.isSafeInteger(e)||Number(e)<0)throw new Error(`Invalid Make Console assistant response: ${t}`);return Number(e)},k=()=>new DOMException("Aborted","AbortError"),u=e=>{if(e?.aborted)throw k()},q=(e,t)=>(u(t),e===0?Promise.resolve():new Promise((n,i)=>{const f=setTimeout(()=>{t?.removeEventListener("abort",I),n()},e),I=()=>{clearTimeout(f),t?.removeEventListener("abort",I),i(k())};t?.addEventListener("abort",I,{once:!0})})),F=e=>{if(!y(e)||!Array.isArray(e.agents)||e.agents.length>1e3)throw new Error("Invalid Make Console assistant response: agents");const t=new Set;return e.agents.map(n=>{if(!y(n))throw new Error("Invalid Make Console assistant response: agent");const i=A(n.agentID,"agentID");if(t.has(i))throw new Error("Invalid Make Console assistant response: duplicate agentID");return t.add(i),{agentID:i,...typeof n.name=="string"&&n.name.trim()?{name:A(n.name,"agent name")}:{},status:A(n.status,"agent status")}})},V=e=>{if(!y(e))throw new Error("Invalid Make Console assistant response: session");return{nextSeq:m(e.nextSeq,"nextSeq"),sessionID:A(e.sessionID,"sessionID")}},H=e=>{if(!y(e))throw new Error("Invalid Make Console assistant response: sent message");const t=S(e.runID,"runID"),n=S(e.mergedInto,"mergedInto");if(t&&n)throw new Error("Invalid Make Console assistant response: multiple Run IDs");return{effectiveRunID:t??n,seq:m(e.seq,"seq"),sessionID:A(e.sessionID,"sessionID")}},$=e=>{if(!y(e)||!Array.isArray(e.blocks)||e.blocks.length>1e3)throw new Error("Invalid Make Console assistant response: payload blocks");let t="";for(const n of e.blocks)if(!(!y(n)||n.kind!=="text"||typeof n.text!="string")&&(t+=n.text,E.countCodePointsUpTo(t,E.MAKE_AI_CONVERSATION_LIMITS.messageCharacters)>E.MAKE_AI_CONVERSATION_LIMITS.messageCharacters))throw new Error("Invalid Make Console assistant response: message text budget");return A(t,"message text",E.MAKE_AI_CONVERSATION_LIMITS.messageCharacters)},T=(e,t)=>{if(!Array.isArray(e)||e.length>t)throw new Error("Invalid Make Console assistant response: durable events");const n=new Set;return e.flatMap(i=>{if(!y(i))throw new Error("Invalid Make Console assistant response: durable event");const c=m(i.seq,"event seq");if(n.has(c))throw new Error("Invalid Make Console assistant response: duplicate event seq");n.add(c);const f=typeof i.type=="string"?i.type:"",I=y(i.actor)&&typeof i.actor.kind=="string"?i.actor.kind:"";return!(f==="user_message")&&!(f==="message"&&I==="agent")?[]:[{actorKind:I,content:$(i.payload),runID:S(i.runID,"event runID"),seq:c,type:f}]})},G=(e,t,n)=>{const i=T(e,n);let c=0;return{messages:i.map(I=>{if(c+=E.countCodePointsUpTo(I.content,E.MAKE_AI_CONVERSATION_LIMITS.historyCharacters-c),c>E.MAKE_AI_CONVERSATION_LIMITS.historyCharacters)throw new Error("Invalid Make Console assistant response: history text budget");return{artifacts:[],content:I.content,id:`console-${t}-${String(I.seq)}`,role:I.type==="user_message"?"user":"assistant"}}),threadId:t}},B=()=>{const e=[],t=[];return{next:()=>{const c=e.shift();return c?Promise.resolve(c):new Promise(f=>t.push(f))},push:c=>{const f=t.shift();f?f(c):e.push(c)}}},X=(e,t)=>{if(E.countCodePointsUpTo(e.data,t)>t)throw new Error("Make Console assistant SSE event exceeds maxEventCharacters");try{const n=JSON.parse(e.data);if(!y(n))throw new Error("invalid data");return n}catch{throw new Error("Invalid Make Console assistant SSE JSON")}},b=(e,t)=>{if(!Number.isInteger(e)||e<1)throw new Error(`${t} must be a positive integer`)},Q=(e,t,n)=>T(e,t).find(c=>c.type==="message"&&c.actorKind==="agent"&&(n===void 0||c.runID===n)),j=e=>{const t=e.historyLimit??x,n=e.maxEventCharacters??N.DEFAULT_MAX_SSE_EVENT_CHARACTERS,i=e.maxPollingAttempts??U,c=e.pollIntervalMs??P,f=e.wait??q;if(!Number.isInteger(t)||t<1||t>200)throw new Error("historyLimit must be an integer between 1 and 200");if(b(n,"maxEventCharacters"),b(i,"maxPollingAttempts"),!Number.isInteger(c)||c<0)throw new Error("pollIntervalMs must be a non-negative integer");const I=async(s,r)=>{u(r?.signal),console.info("[make-ai-assistant] Make Console Agent lookup start",{appId:s.app.id});const o=F(await e.listAgents({appKey:s.app.id},{signal:r?.signal}));u(r?.signal);const l=o.filter(g=>g.status==="enabled"),p=e.selectAgent?e.selectAgent(l,s):l[0]?.agentID,d=l.find(g=>g.agentID===p);if(!d)throw new Error("当前应用没有可用 Agent");return console.info("[make-ai-assistant] Make Console Agent lookup success",{appId:s.app.id,enabledAgentCount:l.length}),d},C=async(s,r,o)=>(u(o?.signal),V(await e.getOrCreateSession({agentID:r,appKey:s.app.id},{signal:o?.signal}))),_=async s=>{for(let r=1;r<=i;r+=1){u(s.signal);const o=await e.loadEvents({agentID:s.agentID,appKey:s.appKey,from:s.from,limit:t,sessionID:s.sessionID},{signal:s.signal});u(s.signal);const l=Q(o,t,s.effectiveRunID);if(l)return l;r<i&&await f(c,s.signal)}throw new Error("Make Console assistant durable response unavailable")},L=async function*(s){u(s.signal);const r=B(),o=e.eventSourceFactory({agentID:s.agentID,appKey:s.appKey,cursor:"0-0",runID:s.effectiveRunID,sessionID:s.sessionID},{withCredentials:!0});let l=!1;const p=a=>{l||(l=!0,r.push(a))},d=new Map,g=(a,h)=>{const D=v=>{if(!l)try{h(X(v,n),v)}catch(R){p({type:"error",error:R})}};d.set(a,D),o.addEventListener(a,D)};g("ready",a=>{if(typeof a.after!="string")throw new Error("Invalid Make Console assistant response: ready cursor")}),g("run-output",a=>{if(A(a.runID,"SSE runID")!==s.effectiveRunID)throw new Error("Invalid Make Console assistant response: SSE runID mismatch");m(a.sequence,"SSE sequence");const h=A(a.type,"SSE output type");if(h==="output_text.delta"){if(typeof a.delta!="string")throw new Error("Invalid Make Console assistant response: SSE delta");r.push({type:"event",event:{type:"message.delta",messageId:s.messageId,delta:a.delta}})}else h==="response.completed"?p({type:"completed"}):h==="response.failed"&&p({type:"failed",code:A(a.failureCode,"failureCode")})}),g("fallback",a=>{if(a.reason!=="stream_unavailable")throw new Error("Invalid Make Console assistant response: fallback reason");p({type:"fallback"})}),o.onerror=()=>{l||o.readyState!==void 0&&o.readyState!==2||p({type:"error",error:new Error("Make Console assistant SSE disconnected")})};const w=()=>p({type:"error",error:k()});s.signal?.addEventListener("abort",w,{once:!0}),s.signal?.aborted&&w();try{for(;;){const a=await r.next();if(a.type==="event")yield a.event;else{if(a.type==="completed"||a.type==="fallback")return a.type;if(a.type==="failed")return yield{type:"error",code:a.code,message:K[a.code]??"本次 AI 处理失败,请重试。",retryable:!O.has(a.code),requestId:s.effectiveRunID},"failed";throw a.error}}}finally{l=!0,s.signal?.removeEventListener("abort",w),o.onerror=null;for(const[a,h]of d)o.removeEventListener(a,h);o.close()}};return{features:{history:!0,newConversation:!1,regeneration:!1,remoteCancellation:!1},async loadConversation(s,r){console.info("[make-ai-assistant] Make Console history load start",{appId:s.app.id});try{const o=await I(s,r),l=await C(s,o.agentID,r),p=Math.max(0,l.nextSeq-t),d=await e.loadEvents({agentID:o.agentID,appKey:s.app.id,from:p,limit:t,sessionID:l.sessionID},{signal:r?.signal});u(r?.signal);const g=G(d,l.sessionID,t);return console.info("[make-ai-assistant] Make Console history load success",{appId:s.app.id,messageCount:g.messages.length}),g}catch(o){throw(r?.signal?.aborted?console.info:console.error)(r?.signal?.aborted?"[make-ai-assistant] Make Console history load cancelled":"[make-ai-assistant] Make Console history load failed",{appId:s.app.id,errorType:o instanceof Error?o.name:typeof o}),o}},async*run(s,r){console.info("[make-ai-assistant] Make Console run start",{appId:s.context.app.id});try{const o=s.message.content.trim();if(!o||E.countCodePointsUpTo(o,M)>M)throw new Error(o?"Console 消息不能超过 4000 个字符":"Console 消息不能为空");const l=await I(s.context,r),p=await C(s.context,l.agentID,r);u(r?.signal);const d=H(await e.sendMessage({agentID:l.agentID,appKey:s.context.app.id,text:o},{signal:r?.signal}));if(u(r?.signal),d.sessionID!==p.sessionID)throw new Error("Invalid Make Console assistant response: sessionID mismatch");const g=d.effectiveRunID??`${d.sessionID}:${String(d.seq)}`,w=`assistant:${g}`;if(yield{type:"message.start",runId:g,messageId:w},d.effectiveRunID){const D=yield*L({agentID:l.agentID,appKey:s.context.app.id,effectiveRunID:d.effectiveRunID,messageId:w,sessionID:d.sessionID,signal:r?.signal});if(D==="failed")return;D==="fallback"&&console.info("[make-ai-assistant] Make Console SSE fallback",{appId:s.context.app.id})}const a=await _({agentID:l.agentID,appKey:s.context.app.id,effectiveRunID:d.effectiveRunID,from:d.seq+1,sessionID:d.sessionID,signal:r?.signal});yield{type:"message.replace",messageId:w,content:a.content},yield{type:"message.complete",messageId:w},yield{type:"run.complete",runId:g,threadId:d.sessionID},console.info("[make-ai-assistant] Make Console run complete",{appId:s.context.app.id})}catch(o){throw r?.signal?.aborted?console.info("[make-ai-assistant] Make Console run cancelled",{appId:s.context.app.id}):console.error("[make-ai-assistant] Make Console run failed",{appId:s.context.app.id,errorType:o instanceof Error?o.name:typeof o}),o}}}};exports.MAKE_CONSOLE_MESSAGE_CHARACTERS=M;exports.createMakeConsoleAssistantTransport=j;
|
package/dist/make-console.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DEFAULT_MAX_SSE_EVENT_CHARACTERS as N } from "./sse.mjs";
|
|
2
|
-
import { c as D, M as m } from "./conversation-
|
|
2
|
+
import { c as D, M as m } from "./conversation-B7eGUXi-.js";
|
|
3
3
|
const _ = 4e3, U = 200, P = 30, K = 1e3, F = {
|
|
4
4
|
AI_AGENT_UNAVAILABLE: "当前应用没有可用 Agent。",
|
|
5
5
|
AI_AUTH_EXPIRED: "登录已失效,请重新登录。",
|
|
@@ -144,26 +144,26 @@ const _ = 4e3, U = 200, P = 30, K = 1e3, F = {
|
|
|
144
144
|
throw new Error("historyLimit must be an integer between 1 and 200");
|
|
145
145
|
if (T(n, "maxEventCharacters"), T(i, "maxPollingAttempts"), !Number.isInteger(c) || c < 0)
|
|
146
146
|
throw new Error("pollIntervalMs must be a non-negative integer");
|
|
147
|
-
const I = async (s,
|
|
148
|
-
u(
|
|
147
|
+
const I = async (s, o) => {
|
|
148
|
+
u(o?.signal), console.info("[make-ai-assistant] Make Console Agent lookup start", {
|
|
149
149
|
appId: s.app.id
|
|
150
150
|
});
|
|
151
151
|
const a = $(await e.listAgents(
|
|
152
152
|
{ appKey: s.app.id },
|
|
153
|
-
{ signal:
|
|
153
|
+
{ signal: o?.signal }
|
|
154
154
|
));
|
|
155
|
-
u(
|
|
155
|
+
u(o?.signal);
|
|
156
156
|
const l = a.filter((g) => g.status === "enabled"), p = e.selectAgent ? e.selectAgent(l, s) : l[0]?.agentID, d = l.find((g) => g.agentID === p);
|
|
157
157
|
if (!d) throw new Error("当前应用没有可用 Agent");
|
|
158
158
|
return console.info("[make-ai-assistant] Make Console Agent lookup success", {
|
|
159
159
|
appId: s.app.id,
|
|
160
160
|
enabledAgentCount: l.length
|
|
161
161
|
}), d;
|
|
162
|
-
}, M = async (s,
|
|
163
|
-
{ agentID:
|
|
162
|
+
}, M = async (s, o, a) => (u(a?.signal), B(await e.getOrCreateSession(
|
|
163
|
+
{ agentID: o, appKey: s.app.id },
|
|
164
164
|
{ signal: a?.signal }
|
|
165
165
|
))), v = async (s) => {
|
|
166
|
-
for (let
|
|
166
|
+
for (let o = 1; o <= i; o += 1) {
|
|
167
167
|
u(s.signal);
|
|
168
168
|
const a = await e.loadEvents({
|
|
169
169
|
agentID: s.agentID,
|
|
@@ -179,12 +179,12 @@ const _ = 4e3, U = 200, P = 30, K = 1e3, F = {
|
|
|
179
179
|
s.effectiveRunID
|
|
180
180
|
);
|
|
181
181
|
if (l) return l;
|
|
182
|
-
|
|
182
|
+
o < i && await f(c, s.signal);
|
|
183
183
|
}
|
|
184
184
|
throw new Error("Make Console assistant durable response unavailable");
|
|
185
185
|
}, L = async function* (s) {
|
|
186
186
|
u(s.signal);
|
|
187
|
-
const
|
|
187
|
+
const o = Q(), a = e.eventSourceFactory({
|
|
188
188
|
agentID: s.agentID,
|
|
189
189
|
appKey: s.appKey,
|
|
190
190
|
cursor: "0-0",
|
|
@@ -192,9 +192,9 @@ const _ = 4e3, U = 200, P = 30, K = 1e3, F = {
|
|
|
192
192
|
sessionID: s.sessionID
|
|
193
193
|
}, { withCredentials: !0 });
|
|
194
194
|
let l = !1;
|
|
195
|
-
const p = (
|
|
196
|
-
l || (l = !0,
|
|
197
|
-
}, d = /* @__PURE__ */ new Map(), g = (
|
|
195
|
+
const p = (r) => {
|
|
196
|
+
l || (l = !0, o.push(r));
|
|
197
|
+
}, d = /* @__PURE__ */ new Map(), g = (r, h) => {
|
|
198
198
|
const A = (b) => {
|
|
199
199
|
if (!l)
|
|
200
200
|
try {
|
|
@@ -203,33 +203,33 @@ const _ = 4e3, U = 200, P = 30, K = 1e3, F = {
|
|
|
203
203
|
p({ type: "error", error: R });
|
|
204
204
|
}
|
|
205
205
|
};
|
|
206
|
-
d.set(
|
|
206
|
+
d.set(r, A), a.addEventListener(r, A);
|
|
207
207
|
};
|
|
208
|
-
g("ready", (
|
|
209
|
-
if (typeof
|
|
208
|
+
g("ready", (r) => {
|
|
209
|
+
if (typeof r.after != "string")
|
|
210
210
|
throw new Error("Invalid Make Console assistant response: ready cursor");
|
|
211
|
-
}), g("run-output", (
|
|
212
|
-
if (y(
|
|
211
|
+
}), g("run-output", (r) => {
|
|
212
|
+
if (y(r.runID, "SSE runID") !== s.effectiveRunID)
|
|
213
213
|
throw new Error("Invalid Make Console assistant response: SSE runID mismatch");
|
|
214
|
-
C(
|
|
215
|
-
const h = y(
|
|
214
|
+
C(r.sequence, "SSE sequence");
|
|
215
|
+
const h = y(r.type, "SSE output type");
|
|
216
216
|
if (h === "output_text.delta") {
|
|
217
|
-
if (typeof
|
|
217
|
+
if (typeof r.delta != "string")
|
|
218
218
|
throw new Error("Invalid Make Console assistant response: SSE delta");
|
|
219
|
-
|
|
219
|
+
o.push({
|
|
220
220
|
type: "event",
|
|
221
221
|
event: {
|
|
222
222
|
type: "message.delta",
|
|
223
223
|
messageId: s.messageId,
|
|
224
|
-
delta:
|
|
224
|
+
delta: r.delta
|
|
225
225
|
}
|
|
226
226
|
});
|
|
227
227
|
} else h === "response.completed" ? p({ type: "completed" }) : h === "response.failed" && p({
|
|
228
228
|
type: "failed",
|
|
229
|
-
code: y(
|
|
229
|
+
code: y(r.failureCode, "failureCode")
|
|
230
230
|
});
|
|
231
|
-
}), g("fallback", (
|
|
232
|
-
if (
|
|
231
|
+
}), g("fallback", (r) => {
|
|
232
|
+
if (r.reason !== "stream_unavailable")
|
|
233
233
|
throw new Error("Invalid Make Console assistant response: fallback reason");
|
|
234
234
|
p({ type: "fallback" });
|
|
235
235
|
}), a.onerror = () => {
|
|
@@ -242,27 +242,27 @@ const _ = 4e3, U = 200, P = 30, K = 1e3, F = {
|
|
|
242
242
|
s.signal?.addEventListener("abort", w, { once: !0 }), s.signal?.aborted && w();
|
|
243
243
|
try {
|
|
244
244
|
for (; ; ) {
|
|
245
|
-
const
|
|
246
|
-
if (
|
|
247
|
-
yield
|
|
245
|
+
const r = await o.next();
|
|
246
|
+
if (r.type === "event")
|
|
247
|
+
yield r.event;
|
|
248
248
|
else {
|
|
249
|
-
if (
|
|
250
|
-
return
|
|
251
|
-
if (
|
|
249
|
+
if (r.type === "completed" || r.type === "fallback")
|
|
250
|
+
return r.type;
|
|
251
|
+
if (r.type === "failed")
|
|
252
252
|
return yield {
|
|
253
253
|
type: "error",
|
|
254
|
-
code:
|
|
255
|
-
message: F[
|
|
256
|
-
retryable: !q.has(
|
|
254
|
+
code: r.code,
|
|
255
|
+
message: F[r.code] ?? "本次 AI 处理失败,请重试。",
|
|
256
|
+
retryable: !q.has(r.code),
|
|
257
257
|
requestId: s.effectiveRunID
|
|
258
258
|
}, "failed";
|
|
259
|
-
throw
|
|
259
|
+
throw r.error;
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
} finally {
|
|
263
263
|
l = !0, s.signal?.removeEventListener("abort", w), a.onerror = null;
|
|
264
|
-
for (const [
|
|
265
|
-
a.removeEventListener(
|
|
264
|
+
for (const [r, h] of d)
|
|
265
|
+
a.removeEventListener(r, h);
|
|
266
266
|
a.close();
|
|
267
267
|
}
|
|
268
268
|
};
|
|
@@ -270,29 +270,30 @@ const _ = 4e3, U = 200, P = 30, K = 1e3, F = {
|
|
|
270
270
|
features: {
|
|
271
271
|
history: !0,
|
|
272
272
|
newConversation: !1,
|
|
273
|
+
regeneration: !1,
|
|
273
274
|
remoteCancellation: !1
|
|
274
275
|
},
|
|
275
|
-
async loadConversation(s,
|
|
276
|
+
async loadConversation(s, o) {
|
|
276
277
|
console.info("[make-ai-assistant] Make Console history load start", {
|
|
277
278
|
appId: s.app.id
|
|
278
279
|
});
|
|
279
280
|
try {
|
|
280
|
-
const a = await I(s,
|
|
281
|
+
const a = await I(s, o), l = await M(s, a.agentID, o), p = Math.max(0, l.nextSeq - t), d = await e.loadEvents({
|
|
281
282
|
agentID: a.agentID,
|
|
282
283
|
appKey: s.app.id,
|
|
283
284
|
from: p,
|
|
284
285
|
limit: t,
|
|
285
286
|
sessionID: l.sessionID
|
|
286
|
-
}, { signal:
|
|
287
|
-
u(
|
|
287
|
+
}, { signal: o?.signal });
|
|
288
|
+
u(o?.signal);
|
|
288
289
|
const g = X(d, l.sessionID, t);
|
|
289
290
|
return console.info("[make-ai-assistant] Make Console history load success", {
|
|
290
291
|
appId: s.app.id,
|
|
291
292
|
messageCount: g.messages.length
|
|
292
293
|
}), g;
|
|
293
294
|
} catch (a) {
|
|
294
|
-
throw (
|
|
295
|
-
|
|
295
|
+
throw (o?.signal?.aborted ? console.info : console.error)(
|
|
296
|
+
o?.signal?.aborted ? "[make-ai-assistant] Make Console history load cancelled" : "[make-ai-assistant] Make Console history load failed",
|
|
296
297
|
{
|
|
297
298
|
appId: s.app.id,
|
|
298
299
|
errorType: a instanceof Error ? a.name : typeof a
|
|
@@ -300,7 +301,7 @@ const _ = 4e3, U = 200, P = 30, K = 1e3, F = {
|
|
|
300
301
|
), a;
|
|
301
302
|
}
|
|
302
303
|
},
|
|
303
|
-
async *run(s,
|
|
304
|
+
async *run(s, o) {
|
|
304
305
|
console.info("[make-ai-assistant] Make Console run start", {
|
|
305
306
|
appId: s.context.app.id
|
|
306
307
|
});
|
|
@@ -310,18 +311,18 @@ const _ = 4e3, U = 200, P = 30, K = 1e3, F = {
|
|
|
310
311
|
throw new Error(
|
|
311
312
|
a ? "Console 消息不能超过 4000 个字符" : "Console 消息不能为空"
|
|
312
313
|
);
|
|
313
|
-
const l = await I(s.context,
|
|
314
|
+
const l = await I(s.context, o), p = await M(
|
|
314
315
|
s.context,
|
|
315
316
|
l.agentID,
|
|
316
|
-
|
|
317
|
+
o
|
|
317
318
|
);
|
|
318
|
-
u(
|
|
319
|
+
u(o?.signal);
|
|
319
320
|
const d = G(await e.sendMessage({
|
|
320
321
|
agentID: l.agentID,
|
|
321
322
|
appKey: s.context.app.id,
|
|
322
323
|
text: a
|
|
323
|
-
}, { signal:
|
|
324
|
-
if (u(
|
|
324
|
+
}, { signal: o?.signal }));
|
|
325
|
+
if (u(o?.signal), d.sessionID !== p.sessionID)
|
|
325
326
|
throw new Error("Invalid Make Console assistant response: sessionID mismatch");
|
|
326
327
|
const g = d.effectiveRunID ?? `${d.sessionID}:${String(d.seq)}`, w = `assistant:${g}`;
|
|
327
328
|
if (yield { type: "message.start", runId: g, messageId: w }, d.effectiveRunID) {
|
|
@@ -331,26 +332,26 @@ const _ = 4e3, U = 200, P = 30, K = 1e3, F = {
|
|
|
331
332
|
effectiveRunID: d.effectiveRunID,
|
|
332
333
|
messageId: w,
|
|
333
334
|
sessionID: d.sessionID,
|
|
334
|
-
signal:
|
|
335
|
+
signal: o?.signal
|
|
335
336
|
});
|
|
336
337
|
if (A === "failed") return;
|
|
337
338
|
A === "fallback" && console.info("[make-ai-assistant] Make Console SSE fallback", {
|
|
338
339
|
appId: s.context.app.id
|
|
339
340
|
});
|
|
340
341
|
}
|
|
341
|
-
const
|
|
342
|
+
const r = await v({
|
|
342
343
|
agentID: l.agentID,
|
|
343
344
|
appKey: s.context.app.id,
|
|
344
345
|
effectiveRunID: d.effectiveRunID,
|
|
345
346
|
from: d.seq + 1,
|
|
346
347
|
sessionID: d.sessionID,
|
|
347
|
-
signal:
|
|
348
|
+
signal: o?.signal
|
|
348
349
|
});
|
|
349
|
-
yield { type: "message.replace", messageId: w, content:
|
|
350
|
+
yield { type: "message.replace", messageId: w, content: r.content }, yield { type: "message.complete", messageId: w }, yield { type: "run.complete", runId: g, threadId: d.sessionID }, console.info("[make-ai-assistant] Make Console run complete", {
|
|
350
351
|
appId: s.context.app.id
|
|
351
352
|
});
|
|
352
353
|
} catch (a) {
|
|
353
|
-
throw
|
|
354
|
+
throw o?.signal?.aborted ? console.info("[make-ai-assistant] Make Console run cancelled", {
|
|
354
355
|
appId: s.context.app.id
|
|
355
356
|
}) : console.error("[make-ai-assistant] Make Console run failed", {
|
|
356
357
|
appId: s.context.app.id,
|