@aigur/client
Advanced tools
Comparing version 1.2.0 to 1.3.0
# @aigur/client | ||
## 1.3.0 | ||
### Minor Changes | ||
- 65170a1d: Support User Id in Node and Memory input functions | ||
## 1.2.0 | ||
@@ -4,0 +10,0 @@ |
@@ -11,2 +11,3 @@ import { z } from 'zod'; | ||
memory: MemoryData; | ||
userId: string; | ||
}) => Parameters<NodeDef>['0'], getMemory?: (data: { | ||
@@ -18,2 +19,3 @@ nodes: NodeDefinitions; | ||
memory: MemoryData; | ||
userId: string; | ||
}) => Partial<MemoryData>): FlowBuilder<Input, Output, MemoryData, [...NodeDefinitions, ConcreteNode<Parameters<NodeDef>["0"], Awaited<ReturnType<NodeDef>>, MemoryData>], ConcreteNode<Parameters<NodeDef>["0"], Awaited<ReturnType<NodeDef>>, MemoryData>>; | ||
@@ -26,2 +28,3 @@ private createDynamicPlaceholders; | ||
memory: MemoryData; | ||
userId: string; | ||
}) => Output, getMemory?: (data: { | ||
@@ -33,2 +36,3 @@ nodes: NodeDefinitions; | ||
memory: MemoryData; | ||
userId: string; | ||
}) => Partial<MemoryData>): FlowBuilder<Input, Output, MemoryData, [...NodeDefinitions, ConcreteNode<Output, Awaited<Output>, MemoryData>], ConcreteNode<Output, Awaited<Output>, MemoryData>>; | ||
@@ -153,3 +157,3 @@ getNodes(): NodeDefinitions; | ||
declare const inputSchema$b: z.ZodObject<{ | ||
declare const inputSchema$c: z.ZodObject<{ | ||
image: z.ZodString; | ||
@@ -161,3 +165,3 @@ }, "strip", z.ZodTypeAny, { | ||
}>; | ||
declare const outputSchema$b: z.ZodObject<{ | ||
declare const outputSchema$c: z.ZodObject<{ | ||
labels: z.ZodArray<z.ZodString, "many">; | ||
@@ -169,5 +173,5 @@ }, "strip", z.ZodTypeAny, { | ||
}>; | ||
declare function googleImageLabeling(input: z.input<typeof inputSchema$b>, apiKeys: APIKeys): Promise<z.infer<typeof outputSchema$b>>; | ||
declare function googleImageLabeling(input: z.input<typeof inputSchema$c>, apiKeys: APIKeys): Promise<z.infer<typeof outputSchema$c>>; | ||
declare const inputSchema$a: z.ZodObject<{ | ||
declare const inputSchema$b: z.ZodObject<{ | ||
prompt: z.ZodString; | ||
@@ -185,3 +189,3 @@ response_format: z.ZodDefault<z.ZodLiteral<"b64_json">>; | ||
}>; | ||
declare const outputSchema$a: z.ZodObject<{ | ||
declare const outputSchema$b: z.ZodObject<{ | ||
result: z.ZodString; | ||
@@ -193,5 +197,5 @@ }, "strip", z.ZodTypeAny, { | ||
}>; | ||
declare function dalleBase64TextToImage(input: z.input<typeof inputSchema$a>, apiKeys: APIKeys): Promise<z.infer<typeof outputSchema$a>>; | ||
declare function dalleBase64TextToImage(input: z.input<typeof inputSchema$b>, apiKeys: APIKeys): Promise<z.infer<typeof outputSchema$b>>; | ||
declare const inputSchema$9: z.ZodObject<{ | ||
declare const inputSchema$a: z.ZodObject<{ | ||
prompt: z.ZodString; | ||
@@ -206,3 +210,3 @@ size: z.ZodDefault<z.ZodEnum<["256x256", "512x512", "1024x1024"]>>; | ||
}>; | ||
declare const outputSchema$9: z.ZodObject<{ | ||
declare const outputSchema$a: z.ZodObject<{ | ||
url: z.ZodString; | ||
@@ -214,7 +218,7 @@ }, "strip", z.ZodTypeAny, { | ||
}>; | ||
declare function dalleUrlTextToImage(input: z.input<typeof inputSchema$9>, apiKeys: APIKeys): Promise<z.infer<typeof outputSchema$9>>; | ||
declare function dalleUrlTextToImage(input: z.input<typeof inputSchema$a>, apiKeys: APIKeys): Promise<z.infer<typeof outputSchema$a>>; | ||
declare const stabilityModel: z.ZodEnum<["stable-diffusion-v1-5", "stable-diffusion-512-v2-0", "stable-diffusion-768-v2-0", "stable-diffusion-512-v2-1", "stable-diffusion-768-v2-1"]>; | ||
declare const stabilityClipGuidancePreset: z.ZodEnum<["NONE", "FAST_BLUE", "FAST_GREEN", "SIMPLE", "SLOW", "SLOWER", "SLOWEST"]>; | ||
declare const inputSchema$8: z.ZodObject<{ | ||
declare const inputSchema$9: z.ZodObject<{ | ||
text_prompts: z.ZodEffects<z.ZodArray<z.ZodObject<{ | ||
@@ -271,3 +275,3 @@ text: z.ZodString; | ||
}>; | ||
declare const outputSchema$8: z.ZodObject<{ | ||
declare const outputSchema$9: z.ZodObject<{ | ||
result: z.ZodType<ArrayBuffer, z.ZodTypeDef, ArrayBuffer>; | ||
@@ -279,6 +283,22 @@ }, "strip", z.ZodTypeAny, { | ||
}>; | ||
declare function stabilityTextToImage(input: z.input<typeof inputSchema$8>, apiKeys: APIKeys): Promise<z.infer<typeof outputSchema$8>>; | ||
declare function stabilityTextToImage(input: z.input<typeof inputSchema$9>, apiKeys: APIKeys): Promise<z.infer<typeof outputSchema$9>>; | ||
declare function output<PipelineOutput extends Record<string, unknown> | ReadableStream>(input: PipelineOutput): Promise<PipelineOutput>; | ||
declare const inputSchema$8: z.ZodObject<{ | ||
text: z.ZodString; | ||
}, "strip", z.ZodTypeAny, { | ||
text: string; | ||
}, { | ||
text: string; | ||
}>; | ||
declare const outputSchema$8: z.ZodObject<{ | ||
text: z.ZodString; | ||
}, "strip", z.ZodTypeAny, { | ||
text: string; | ||
}, { | ||
text: string; | ||
}>; | ||
declare function cleanContextVars(input: z.input<typeof inputSchema$8>): Promise<z.infer<typeof outputSchema$8>>; | ||
declare const inputSchema$7: z.ZodObject<{ | ||
@@ -513,2 +533,2 @@ text: z.ZodString; | ||
export { Aigur, Pipeline, createClient, dalleBase64TextToImage, dalleUrlTextToImage, enhanceWithKeywords, googleImageLabeling, googleTextToSpeech, gpt3Prediction, gpt3PredictionStream, inputSchema$4 as inputSchema, output, outputSchema$4 as outputSchema, replaceMultipleStrings, replaceString, stabilityClipGuidancePreset, stabilityModel, stabilityTextToImage, stringToArrayBuffer, vercelEdgeFunction, vercelGenericEdge, whisperApi }; | ||
export { Aigur, Pipeline, cleanContextVars, createClient, dalleBase64TextToImage, dalleUrlTextToImage, enhanceWithKeywords, googleImageLabeling, googleTextToSpeech, gpt3Prediction, gpt3PredictionStream, inputSchema$4 as inputSchema, output, outputSchema$4 as outputSchema, replaceMultipleStrings, replaceString, stabilityClipGuidancePreset, stabilityModel, stabilityTextToImage, stringToArrayBuffer, vercelEdgeFunction, vercelGenericEdge, whisperApi }; |
@@ -1,7 +0,7 @@ | ||
var E=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var W=Object.prototype.hasOwnProperty;var J=(n,e)=>{for(var t in e)E(n,t,{get:e[t],enumerable:!0})},V=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of F(e))!W.call(n,r)&&r!==t&&E(n,r,{get:()=>e[r],enumerable:!(o=B(e,r))||o.enumerable});return n};var G=n=>V(E({},"__esModule",{value:!0}),n);var Re={};J(Re,{Pipeline:()=>w,createClient:()=>Z,dalleBase64TextToImage:()=>oe,dalleUrlTextToImage:()=>ie,enhanceWithKeywords:()=>de,googleImageLabeling:()=>te,googleTextToSpeech:()=>we,gpt3Prediction:()=>ge,gpt3PredictionStream:()=>xe,inputSchema:()=>R,output:()=>O,outputSchema:()=>he,replaceMultipleStrings:()=>le,replaceString:()=>ye,stabilityClipGuidancePreset:()=>k,stabilityModel:()=>_,stabilityTextToImage:()=>se,stringToArrayBuffer:()=>ve,vercelEdgeFunction:()=>Ae,vercelGenericEdge:()=>j,whisperApi:()=>Te});module.exports=G(Re);function U(n){return new Promise(e=>setTimeout(e,n))}function T(n,e){if(typeof n=="string")return o(n);return t({...n});function t(i){let a={};for(let p in i)a[p]=o(i[p]);return a}function o(i){if(Array.isArray(i))return i.map(s=>t(s));if(typeof i=="object"&&i!==null)return t(i);let a=i,p=C(i);for(let s of p){let d=e[s.nodeId].output;if(d==null)continue;let c=d[s.property];if(c instanceof ArrayBuffer){a=c;continue}a=a?.replace(new RegExp(r(s.value)),c),a==="undefined"?a=void 0:a!==c&&a===c.toString()&&(a=c)}return a}function r(i){return i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}}function C(n){if(typeof n!="string")return[];let e=/\$context\.(\d+|input|memory)\.(\w+)\$/g,t=n.matchAll(e),o=[];for(let r of t)o.push({value:r[0],nodeId:r[1],property:r[2]});return o}function b(n=16){let e="",t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",o=t.length;for(let r=0;r<n;r++)e+=t.charAt(Math.floor(Math.random()*o));return e}function L(n){let e={input:{input:n.input,output:n.input},memory:{input:n.memory,output:n.memory}};return{pipelineInstanceId:n.pipelineInstanceId,input:n.input,output:{},values:e,memory:n.memory,userId:n.userId}}async function z(n,e){let{memoryToSave:t}=e;if(!t)return;let o=T(t,n.values);for(let r in t)for(let i in o){let a=o[i];if(a instanceof ReadableStream){let p=C(t[r]),[s,d]=a.tee();n.values[p[0].nodeId].output=s;let c=await H(d);o[i]=c}}return o}function H(n){return new Promise(async e=>{let t=n.getReader(),o=new TextDecoder,r=!1,i="";for(;!r;){let{value:a,done:p}=await t.read();r=p;let s=o.decode(a);i+=s}e(i)})}var Y=2,q=350,w=class{constructor(e,t,o){this.conf=e;this.flow=t;this.apiKeys=o;this.onProgressListeners=new Map;this.onStartListeners=new Map;this.onFinishListeners=new Map;this.pipelineInstanceId=b(16);this.eventIndex=0;this.vercel={invoke:(e,t)=>this.invokeRemote(`/api/pipelines/${this.conf.id}`,e,{userId:t?.userId}),invokeStream:(e,t,o)=>this.invokeStream(`/api/pipelines/${this.conf.id}`,e,t,{userId:o?.userId})};this.listenToEvents()}async invoke(e,t){let o=await this.loadMemory(t?.userId),r=L({input:e,pipelineInstanceId:t?.pipelineInstanceId??this.pipelineInstanceId,userId:t?.userId??"",memory:o});return await this.processPipeline(r),r.output}async saveMemory(e,t){let o=await t;!this.conf.memoryManager||!o||this.conf.memoryManager.saveMemory(this.getMemoryId(e.userId),o)}getMemoryId(e){return`${this.conf.id}${e?`-${e}`:""}`}loadMemory(e){return this.conf.memoryManager?this.conf.memoryManager.loadMemory(this.getMemoryId(e)):Promise.resolve(null)}invokeRemote(e,t,o){return fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({input:t,pipelineInstanceId:this.pipelineInstanceId,userId:o?.userId??""})}).then(r=>r.json())}async invokeStream(e,t,o,r){let i=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({input:t,pipelineInstanceId:this.pipelineInstanceId,userId:r?.userId??""})});if(!i.ok)throw new Error(i.statusText);let a=i.body;if(!a)return;let p=a.getReader(),s=new TextDecoder,d=!1;for(;!d;){let{value:c,done:y}=await p.read();d=y;let v=s.decode(c);o(v)}}onProgress(e){let t=b();return this.onProgressListeners.set(t,e),()=>{this.onProgressListeners.delete(t)}}onStart(e){let t=b();return this.onStartListeners.set(t,e),()=>{this.onStartListeners.delete(t)}}onFinish(e){let t=b();return this.onFinishListeners.set(t,e),()=>{this.onFinishListeners.delete(t)}}async processPipeline(e){let t=this.conf.retries??Y;try{let o=this.notifyEvent({type:"pipeline:start",context:e});if(this.conf.stream||await o,this.conf.validateInput){let a=this.conf.validateInput(e.input);if(!a.valid)throw new Error(a.message)}let r=this.flow.getNodes();for(let a=0;a<r.length;a++){let p=this.notifyEvent({type:"node:start",context:e,data:{node:r[a].action.name,index:a}});this.conf.stream||await p;let s=0,d=!1;do{s++;try{let{action:y,input:v,memoryToSave:De}=r[a],D=e.values[a]={input:null,output:null};D.input=T(v,e.values),D.output=await y(D.input,this.apiKeys);let $=z(e,r[a]);this.saveMemory(e,$),d=!0}catch(y){if(s>t)throw y;await U((this.conf.retryDelayInMs??q)*s)}}while(!d&&s<=t);let c=this.notifyEvent({type:"node:finish",context:e,data:{node:r[a].action.name,index:a}});this.conf.stream||await c}let i=this.notifyEvent({type:"pipeline:finish",context:e});return this.conf.stream||await i,e.output=e.values[r.length-1].output,e}catch(o){throw console.error(o),o}}listenToEvents(){!this.conf.updateProgress||typeof window>"u"||!this.conf.eventListener||this.conf.eventListener(this.pipelineInstanceId,e=>{e.pipelineId===this.conf.id&&(e.type==="node:start"||e.type==="node:finish"?this.triggerListeners(this.onProgressListeners,e):e.type==="pipeline:start"?this.triggerListeners(this.onStartListeners,e):e.type==="pipeline:finish"&&this.triggerListeners(this.onFinishListeners,e))})}triggerListeners(e,...t){for(let o of e.values())o(...t)}notifyEvent(e){if(!(!this.conf.updateProgress||!this.conf.eventPublisher))return this.conf.eventPublisher(e.context.pipelineInstanceId,{pipelineId:this.conf.id,eventIndex:this.eventIndex++,type:e.type,data:e.data})}};async function O(n){return n}var A=class{constructor(e){this.nodes=e}node(e,t,o){let r=this.createDynamicPlaceholders("memory"),i=this.createDynamicPlaceholders("input"),a=this.createDynamicPlaceholders(this.nodes.length),p=this.nodes.length>0?this.nodes[this.nodes.length-1]:i,s={action:e,input:t({nodes:this.nodes,prev:p.output,input:i,memory:r}),output:this.createDynamicPlaceholders(this.nodes.length),memoryToSave:o?o({nodes:this.nodes,prev:p.output,output:a,input:i,memory:r}):null};return this.nodes.push(s),this}createDynamicPlaceholders(e){let t={},o={get:function(i,a){return`$context.${e}.${a}$`}};return new Proxy(t,o)}output(e,t){return this.node(O,e,t)}getNodes(){return this.nodes}};var X=2,Q=350,Z=n=>{let{apiKeys:e}=n;return{apiKeys:e,pipeline:{create:t=>{let o={...t,memoryManager:n.memoryManager,retries:t.retries??X,retryDelayInMs:t.retryDelayInMs??Q,eventListener:n.eventListener,eventPublisher:n.eventPublisher},r=t.flow(new A([]));return new w(o,r,e)}}}};var x=require("zod"),ee=x.z.object({image:x.z.string()}),qe=x.z.object({labels:x.z.array(x.z.string())});async function te(n,e){let t=ee.parse(n),o=`https://vision.googleapis.com/v1/images:annotate?key=${e.googleapis}`,r={requests:[{image:{content:t.image},features:[{type:"LABEL_DETECTION"}]}]};return{labels:(await(await fetch(o,{method:"POST",body:JSON.stringify(r)})).json()).responses[0].labelAnnotations.map(p=>p.description)}}var S=require("zod"),ne=S.z.object({prompt:S.z.string(),response_format:S.z.literal("b64_json").default("b64_json"),size:S.z.enum(["256x256","512x512","1024x1024"]).default("512x512")}),Qe=S.z.object({result:S.z.string()});async function oe(n,e){let t=ne.parse(n),r=await fetch("https://api.openai.com/v1/images/generations",{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)}),{data:i}=await r.json();return{result:i[0].b64_json}}var I=require("zod"),re=I.z.object({prompt:I.z.string(),size:I.z.enum(["256x256","512x512","1024x1024"]).default("512x512")}),et=I.z.object({url:I.z.string().url()});async function ie(n,e){let t=re.parse(n),r=await fetch("https://api.openai.com/v1/images/generations",{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)}),{data:i}=await r.json();return{url:i[0].url}}var u=require("zod"),_=u.z.enum(["stable-diffusion-v1-5","stable-diffusion-512-v2-0","stable-diffusion-768-v2-0","stable-diffusion-512-v2-1","stable-diffusion-768-v2-1"]),k=u.z.enum(["NONE","FAST_BLUE","FAST_GREEN","SIMPLE","SLOW","SLOWER","SLOWEST"]),ae=u.z.object({text_prompts:u.z.array(u.z.object({text:u.z.string(),weight:u.z.number().min(-1).max(1).default(1)})).refine(n=>n.length>0,"Must have at least one text prompt"),model:_.default("stable-diffusion-v1-5"),clip_guidance_preset:k.optional(),steps:u.z.number().min(0).max(150).optional(),sampler:u.z.enum(["DDIM","DDPM","K_DPMPP_2M","K_DPMPP_2S_ANCESTRAL","K_DPM_2","K_DPM_2_ANCESTRAL","K_EULER","K_EULER_ANCESTRAL","K_HEUN","K_LMS"]).optional(),cfg_scale:u.z.number().min(0).max(35).optional(),seed:u.z.number().min(0).optional(),height:u.z.number().min(128).optional().refine(n=>typeof n<"u"?n%64===0:!0,"Must be a multiple of 64"),width:u.z.number().min(128).optional().refine(n=>typeof n<"u"?n%64===0:!0,"Must be a multiple of 64")}),nt=u.z.object({result:u.z.instanceof(ArrayBuffer)});async function se(n,e){let t=ae.parse(n),o=`https://api.stability.ai/v1beta/generation/${t.model}/text-to-image`;return{result:await(await fetch(o,{headers:{"Content-Type":"application/json",Accept:"image/png",Authorization:e.stability},method:"POST",body:JSON.stringify(t)})).arrayBuffer()}}var P=require("zod"),pe=P.z.object({text:P.z.string(),amount:P.z.number().optional().default(8)}),rt=P.z.object({text:P.z.string()}),ue={"Colonial-style home":"Colonial, traditional, classic, historical, timeless, elegant, regal, grand, spacious, architectural, wood-framed, brick-exterior, symmetrical, gabled roof, columns, portico, fireplace, formal, ornate, landscaped".split(", "),"High-end penthouse apartment":"Luxury, high-end, penthouse, apartment, upscale, contemporary, modern, stylish, designer, elite, high-rise, rooftop, panoramic, views, spacious, open-plan, top-floor, amenities, concierge, service, exclusive".split(", ")};function ce(n){return Object.entries(ue).map(([e,t])=>`Title: ${e} | ||
var E=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var J=Object.prototype.hasOwnProperty;var V=(n,e)=>{for(var t in e)E(n,t,{get:e[t],enumerable:!0})},G=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of W(e))!J.call(n,r)&&r!==t&&E(n,r,{get:()=>e[r],enumerable:!(o=F(e,r))||o.enumerable});return n};var H=n=>G(E({},"__esModule",{value:!0}),n);var Ee={};V(Ee,{Pipeline:()=>w,cleanContextVars:()=>ce,createClient:()=>ee,dalleBase64TextToImage:()=>re,dalleUrlTextToImage:()=>ae,enhanceWithKeywords:()=>fe,googleImageLabeling:()=>ne,googleTextToSpeech:()=>Re,gpt3Prediction:()=>Ie,gpt3PredictionStream:()=>ve,inputSchema:()=>D,output:()=>j,outputSchema:()=>xe,replaceMultipleStrings:()=>he,replaceString:()=>Se,stabilityClipGuidancePreset:()=>$,stabilityModel:()=>k,stabilityTextToImage:()=>pe,stringToArrayBuffer:()=>Ne,vercelEdgeFunction:()=>Ce,vercelGenericEdge:()=>U,whisperApi:()=>De});module.exports=H(Ee);function A(n,e){if(typeof n=="string")return o(n);return t({...n});function t(i){let a={};for(let p in i)a[p]=o(i[p]);return a}function o(i){if(Array.isArray(i))return i.map(s=>t(s));if(typeof i=="object"&&i!==null)return t(i);let a=i,p=O(i);for(let s of p){let u=e[s.nodeId].output;if(u==null)continue;let d=u[s.property];if(d instanceof ArrayBuffer){a=d;continue}a=a?.replace(new RegExp(r(s.value)),d),a==="undefined"?a=void 0:a!==d&&a===d.toString()&&(a=d)}return a}function r(i){return i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}}function O(n){if(typeof n!="string")return[];let e=/\$context\.(\d+|input|memory|pipeline)\.(\w+)\$/g,t=n.matchAll(e),o=[];for(let r of t)o.push({value:r[0],nodeId:r[1],property:r[2]});return o}async function z(n,e){let{memoryToSave:t}=e;if(!t)return;let o=A(t,n.values);for(let r in t)for(let i in o){let a=o[i];if(a instanceof ReadableStream){let p=O(t[r]),[s,u]=a.tee();n.values[p[0].nodeId].output=s;let d=await Y(u);o[i]=d}}return o}function Y(n){return new Promise(async e=>{let t=n.getReader(),o=new TextDecoder,r=!1,i="";for(;!r;){let{value:a,done:p}=await t.read();r=p;let s=o.decode(a);i+=s}e(i)})}function L(n){let e={input:{input:n.input,output:n.input},memory:{input:n.memory,output:n.memory},pipeline:{input:{pipelineInstanceId:n.pipelineInstanceId,userId:n.userId},output:{pipelineInstanceId:n.pipelineInstanceId,userId:n.userId}}};return{pipelineInstanceId:n.pipelineInstanceId,input:n.input,output:{},values:e,memory:n.memory,userId:n.userId}}function b(n=16){let e="",t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",o=t.length;for(let r=0;r<n;r++)e+=t.charAt(Math.floor(Math.random()*o));return e}function _(n){return new Promise(e=>setTimeout(e,n))}var q=2,X=350,w=class{constructor(e,t,o){this.conf=e;this.flow=t;this.apiKeys=o;this.onProgressListeners=new Map;this.onStartListeners=new Map;this.onFinishListeners=new Map;this.pipelineInstanceId=b(16);this.eventIndex=0;this.vercel={invoke:(e,t)=>this.invokeRemote(`/api/pipelines/${this.conf.id}`,e,{userId:t?.userId}),invokeStream:(e,t,o)=>this.invokeStream(`/api/pipelines/${this.conf.id}`,e,t,{userId:o?.userId})};this.listenToEvents()}async invoke(e,t){let o=await this.loadMemory(t?.userId),r=L({input:e,pipelineInstanceId:t?.pipelineInstanceId??this.pipelineInstanceId,userId:t?.userId??"",memory:o});return await this.processPipeline(r),r.output}async saveMemory(e,t){let o=await t;!this.conf.memoryManager||!o||this.conf.memoryManager.saveMemory(this.getMemoryId(e.userId),o)}getMemoryId(e){return`${this.conf.id}${e?`-${e}`:""}`}loadMemory(e){return this.conf.memoryManager?this.conf.memoryManager.loadMemory(this.getMemoryId(e)):Promise.resolve(null)}invokeRemote(e,t,o){return fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({input:t,pipelineInstanceId:this.pipelineInstanceId,userId:o?.userId??""})}).then(r=>r.json())}async invokeStream(e,t,o,r){let i=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({input:t,pipelineInstanceId:this.pipelineInstanceId,userId:r?.userId??""})});if(!i.ok)throw new Error(i.statusText);let a=i.body;if(!a)return;let p=a.getReader(),s=new TextDecoder,u=!1;for(;!u;){let{value:d,done:y}=await p.read();u=y;let v=s.decode(d);o(v)}}onProgress(e){let t=b();return this.onProgressListeners.set(t,e),()=>{this.onProgressListeners.delete(t)}}onStart(e){let t=b();return this.onStartListeners.set(t,e),()=>{this.onStartListeners.delete(t)}}onFinish(e){let t=b();return this.onFinishListeners.set(t,e),()=>{this.onFinishListeners.delete(t)}}async processPipeline(e){let t=this.conf.retries??q;try{let o=this.notifyEvent({type:"pipeline:start",context:e});if(this.conf.stream||await o,this.conf.validateInput){let a=this.conf.validateInput(e.input);if(!a.valid)throw new Error(a.message)}let r=this.flow.getNodes();for(let a=0;a<r.length;a++){let p=this.notifyEvent({type:"node:start",context:e,data:{node:r[a].action.name,index:a}});this.conf.stream||await p;let s=0,u=!1;do{s++;try{let{action:y,input:v}=r[a],C=e.values[a]={input:null,output:null};C.input=A(v,e.values),C.output=await y(C.input,this.apiKeys);let B=z(e,r[a]);this.saveMemory(e,B),u=!0}catch(y){if(s>t)throw y;await _((this.conf.retryDelayInMs??X)*s)}}while(!u&&s<=t);let d=this.notifyEvent({type:"node:finish",context:e,data:{node:r[a].action.name,index:a}});this.conf.stream||await d}let i=this.notifyEvent({type:"pipeline:finish",context:e});return this.conf.stream||await i,e.output=e.values[r.length-1].output,e}catch(o){throw console.error(o),o}}listenToEvents(){!this.conf.updateProgress||typeof window>"u"||!this.conf.eventListener||this.conf.eventListener(this.pipelineInstanceId,e=>{e.pipelineId===this.conf.id&&(e.type==="node:start"||e.type==="node:finish"?this.triggerListeners(this.onProgressListeners,e):e.type==="pipeline:start"?this.triggerListeners(this.onStartListeners,e):e.type==="pipeline:finish"&&this.triggerListeners(this.onFinishListeners,e))})}triggerListeners(e,...t){for(let o of e.values())o(...t)}notifyEvent(e){if(!(!this.conf.updateProgress||!this.conf.eventPublisher))return this.conf.eventPublisher(e.context.pipelineInstanceId,{pipelineId:this.conf.id,eventIndex:this.eventIndex++,type:e.type,data:e.data})}};async function j(n){return n}var T=class{constructor(e){this.nodes=e}node(e,t,o){let r=this.createDynamicPlaceholders("memory"),i=this.createDynamicPlaceholders("input"),a=this.createDynamicPlaceholders(this.nodes.length),p=this.nodes.length>0?this.nodes[this.nodes.length-1]:i,s="$context.pipeline.userId$",u={action:e,input:t({nodes:this.nodes,prev:p.output,input:i,memory:r,userId:s}),output:this.createDynamicPlaceholders(this.nodes.length),memoryToSave:o?o({nodes:this.nodes,prev:p.output,output:a,input:i,memory:r,userId:s}):null};return this.nodes.push(u),this}createDynamicPlaceholders(e){let t={},o={get:function(i,a){return`$context.${e}.${a}$`}};return new Proxy(t,o)}output(e,t){return this.node(j,e,t)}getNodes(){return this.nodes}};var Q=2,Z=350,ee=n=>{let{apiKeys:e}=n;return{apiKeys:e,pipeline:{create:t=>{let o={...t,memoryManager:n.memoryManager,retries:t.retries??Q,retryDelayInMs:t.retryDelayInMs??Z,eventListener:n.eventListener,eventPublisher:n.eventPublisher},r=t.flow(new T([]));return new w(o,r,e)}}}};var x=require("zod"),te=x.z.object({image:x.z.string()}),Qe=x.z.object({labels:x.z.array(x.z.string())});async function ne(n,e){let t=te.parse(n),o=`https://vision.googleapis.com/v1/images:annotate?key=${e.googleapis}`,r={requests:[{image:{content:t.image},features:[{type:"LABEL_DETECTION"}]}]};return{labels:(await(await fetch(o,{method:"POST",body:JSON.stringify(r)})).json()).responses[0].labelAnnotations.map(p=>p.description)}}var S=require("zod"),oe=S.z.object({prompt:S.z.string(),response_format:S.z.literal("b64_json").default("b64_json"),size:S.z.enum(["256x256","512x512","1024x1024"]).default("512x512")}),et=S.z.object({result:S.z.string()});async function re(n,e){let t=oe.parse(n),r=await fetch("https://api.openai.com/v1/images/generations",{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)}),{data:i}=await r.json();return{result:i[0].b64_json}}var I=require("zod"),ie=I.z.object({prompt:I.z.string(),size:I.z.enum(["256x256","512x512","1024x1024"]).default("512x512")}),nt=I.z.object({url:I.z.string().url()});async function ae(n,e){let t=ie.parse(n),r=await fetch("https://api.openai.com/v1/images/generations",{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)}),{data:i}=await r.json();return{url:i[0].url}}var c=require("zod"),k=c.z.enum(["stable-diffusion-v1-5","stable-diffusion-512-v2-0","stable-diffusion-768-v2-0","stable-diffusion-512-v2-1","stable-diffusion-768-v2-1"]),$=c.z.enum(["NONE","FAST_BLUE","FAST_GREEN","SIMPLE","SLOW","SLOWER","SLOWEST"]),se=c.z.object({text_prompts:c.z.array(c.z.object({text:c.z.string(),weight:c.z.number().min(-1).max(1).default(1)})).refine(n=>n.length>0,"Must have at least one text prompt"),model:k.default("stable-diffusion-v1-5"),clip_guidance_preset:$.optional(),steps:c.z.number().min(0).max(150).optional(),sampler:c.z.enum(["DDIM","DDPM","K_DPMPP_2M","K_DPMPP_2S_ANCESTRAL","K_DPM_2","K_DPM_2_ANCESTRAL","K_EULER","K_EULER_ANCESTRAL","K_HEUN","K_LMS"]).optional(),cfg_scale:c.z.number().min(0).max(35).optional(),seed:c.z.number().min(0).optional(),height:c.z.number().min(128).optional().refine(n=>typeof n<"u"?n%64===0:!0,"Must be a multiple of 64"),width:c.z.number().min(128).optional().refine(n=>typeof n<"u"?n%64===0:!0,"Must be a multiple of 64")}),rt=c.z.object({result:c.z.instanceof(ArrayBuffer)});async function pe(n,e){let t=se.parse(n),o=`https://api.stability.ai/v1beta/generation/${t.model}/text-to-image`;return{result:await(await fetch(o,{headers:{"Content-Type":"application/json",Accept:"image/png",Authorization:e.stability},method:"POST",body:JSON.stringify(t)})).arrayBuffer()}}var N=require("zod"),ue=N.z.object({text:N.z.string()}),at=N.z.object({text:N.z.string()});async function ce(n){return{text:ue.parse(n).text.replace(/\$context\..*?\..*?\$/gm,"").trim()}}var P=require("zod"),de=P.z.object({text:P.z.string(),amount:P.z.number().optional().default(8)}),pt=P.z.object({text:P.z.string()}),me={"Colonial-style home":"Colonial, traditional, classic, historical, timeless, elegant, regal, grand, spacious, architectural, wood-framed, brick-exterior, symmetrical, gabled roof, columns, portico, fireplace, formal, ornate, landscaped".split(", "),"High-end penthouse apartment":"Luxury, high-end, penthouse, apartment, upscale, contemporary, modern, stylish, designer, elite, high-rise, rooftop, panoramic, views, spacious, open-plan, top-floor, amenities, concierge, service, exclusive".split(", ")};function le(n){return Object.entries(me).map(([e,t])=>`Title: ${e} | ||
Description: ${t.slice(0,n).join(", ")} | ||
`).join(` | ||
`)}async function de(n){let e=pe.parse(n);return{text:`Write a maximum of ${e.amount} keywords in a csv list that describes the following | ||
${ce(e.amount)} | ||
`)}async function fe(n){let e=de.parse(n);return{text:`Write a maximum of ${e.amount} keywords in a csv list that describes the following | ||
${le(e.amount)} | ||
Title: ${e.text} | ||
Description:`}}var h=require("zod"),me=h.z.object({strings:h.z.record(h.z.string(),h.z.string()),modifier:h.z.string()}),at=h.z.object({text:h.z.string()});async function le(n){let e=me.parse(n);for(let t in e.strings)e.modifier=e.modifier.replace(new RegExp(`\\$\\(${t}\\)\\$`,"gm"),e.strings[t]);return{text:e.modifier}}var g=require("zod"),fe=g.z.object({text:g.z.string().or(g.z.array(g.z.string())),modifier:g.z.string()}),pt=g.z.object({text:g.z.string()});async function ye(n){let e=fe.parse(n);return{text:e.modifier.replace(/\$\(text\)\$/gm,Array.isArray(e.text)?e.text.join(", "):e.text)}}var m=require("zod"),R=m.z.object({prompt:m.z.string(),model:m.z.enum(["text-davinci-003","text-curie-001","text-babbage-001","text-ada-001","code-davinci-002","code-cushman-002"]).default("text-davinci-003"),temperature:m.z.number().min(0).max(2).default(.7),top_p:m.z.number().min(0).max(1).default(1),frequency_penalty:m.z.number().min(-2).max(2).default(0),presence_penalty:m.z.number().min(-2).max(2).default(0),max_tokens:m.z.number().default(200),n:m.z.number().default(1)}),he=m.z.object({text:m.z.string()});async function ge(n,e){let t=R.parse(n);return{text:(await(await fetch("https://api.openai.com/v1/completions",{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)})).json()).choices[0]?.text.replace(/^(?:\n)+/gm,"")}}var K=require("eventsource-parser"),N=require("zod");var Se=R.merge(N.z.object({stream:N.z.literal(!0).optional().default(!0)})),ft=N.z.object({stream:N.z.instanceof(globalThis.ReadableStream??Object)});async function xe(n,e){let t=Se.parse(n),o=await fetch("https://api.openai.com/v1/completions",{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)});return{stream:await Ie(o)}}async function Ie(n){let e=new TextEncoder,t=new TextDecoder,o=0;return new ReadableStream({async start(i){function a(s){if(s.type==="event"){let d=s.data;if(d==="[DONE]"){i.close();return}try{let y=JSON.parse(d).choices[0].text;if(o<2&&(y.match(/\n/)||[]).length)return;let v=e.encode(y);i.enqueue(v),o++}catch(c){i.error(c)}}}let p=(0,K.createParser)(a);for await(let s of n.body)p.feed(t.decode(s))}})}var M=require("zod"),Pe=M.z.object({string:M.z.string()}),ht=M.z.object({arrayBuffer:M.z.instanceof(ArrayBuffer)});async function ve(n){let e=Pe.parse(n);return{arrayBuffer:Uint8Array.from(atob(e.string),o=>o.charCodeAt(0)).buffer}}var l=require("zod"),be=l.z.object({text:l.z.string(),speakingRate:l.z.number().min(.25).max(4).optional().default(1),pitch:l.z.number().min(-20).max(20).optional().default(0),encoding:l.z.enum(["MP3","FLAC","LINEAR16","MULAW","AMR","AMR_WB","OGG_OPUS","SPEEX_WITH_HEADER_BYTE","WEBM_OPUS"]).optional().default("MP3"),voice:l.z.object({language:l.z.string().optional().default("en-US"),name:l.z.enum(["en-US-Standard-A","en-US-Standard-C","en-US-Standard-D","en-US-Standard-E","en-US-Standard-F","en-US-Standard-G","en-US-Standard-H","en-US-Standard-I","en-US-Standard-J","en-US-Studio-M","en-US-Studio-O","en-US-Wavenet-A","en-US-Wavenet-B","en-US-Wavenet-C","en-US-Wavenet-D","en-US-Wavenet-E","en-US-Wavenet-F","en-US-Wavenet-G","en-US-Wavenet-H","en-US-Wavenet-I","en-US-Wavenet-J","en-US-News-K","en-US-News-L","en-US-News-M","en-US-News-N","en-US-Standard-A","en-US-Standard-B","en-US-Standard-C","en-US-Standard-D","en-US-Standard-E","en-US-Standard-F","en-US-Standard-G","en-US-Standard-H","en-US-Standard-I","en-US-Standard-J"]).or(l.z.string()).optional().default("en-US-Neural2-C")}).optional().default({language:"en-US",name:"en-US-Neural2-C"})}),St=l.z.object({audio:l.z.string()});async function we(n,e){let t=be.parse(n),o=`https://us-central1-texttospeech.googleapis.com/v1beta1/text:synthesize?key=${e.googleapis}`,r={input:{text:t.text},voice:{languageCode:t.voice.language,name:t.voice.name},audioConfig:{audioEncoding:t.encoding,speakingRate:t.speakingRate,pitch:t.pitch}};return{audio:(await(await fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})).json()).audioContent}}var f=require("zod"),Ne="https://transcribe.whisperapi.com",Me=f.z.object({audioUrl:f.z.string().url(),language:f.z.string().default("en"),autoDetectLanguage:f.z.boolean().default(!1),fileType:f.z.string().default("mp3"),task:f.z.enum(["transcribe","translate"]).default("transcribe")}),It=f.z.object({text:f.z.string()});async function Te(n,e){let t=Me.parse(n),o=new FormData;o.append("url",t.audioUrl),t.autoDetectLanguage||o.append("language",t.language),o.append("fileType",t.fileType),o.append("task",t.task);let r=await fetch(Ne,{method:"POST",headers:{contentType:"application/json",Authorization:"Bearer "+e.whisperapi},body:o});if(!r.ok)throw new Error(r.statusText);return{text:(await r.json()).text.trim()}}async function j(n,e){let{pipelineInstanceId:t,userId:o,input:r}=await e.json(),{searchParams:i}=new URL(e.url);if(!i.has("id"))return new Response("Missing id",{status:400});let a=i.get("id"),p=n[a];return{output:await p.invoke(r,{pipelineInstanceId:t,userId:o}),pipeline:p}}function Ae(n){return async e=>{let t=await j(n,e);return t instanceof Response?t:t.pipeline.conf.stream&&t.output instanceof ReadableStream?new Response(t.output):new Response(JSON.stringify(t.output,null,2),{headers:{"content-type":"application/json;charset=UTF-8"}})}}0&&(module.exports={Pipeline,createClient,dalleBase64TextToImage,dalleUrlTextToImage,enhanceWithKeywords,googleImageLabeling,googleTextToSpeech,gpt3Prediction,gpt3PredictionStream,inputSchema,output,outputSchema,replaceMultipleStrings,replaceString,stabilityClipGuidancePreset,stabilityModel,stabilityTextToImage,stringToArrayBuffer,vercelEdgeFunction,vercelGenericEdge,whisperApi}); | ||
Description:`}}var h=require("zod"),ye=h.z.object({strings:h.z.record(h.z.string(),h.z.string()),modifier:h.z.string()}),ct=h.z.object({text:h.z.string()});async function he(n){let e=ye.parse(n);for(let t in e.strings)e.modifier=e.modifier.replace(new RegExp(`\\$\\(${t}\\)\\$`,"gm"),e.strings[t]);return{text:e.modifier}}var g=require("zod"),ge=g.z.object({text:g.z.string().or(g.z.array(g.z.string())),modifier:g.z.string()}),mt=g.z.object({text:g.z.string()});async function Se(n){let e=ge.parse(n);return{text:e.modifier.replace(/\$\(text\)\$/gm,Array.isArray(e.text)?e.text.join(", "):e.text)}}var m=require("zod"),D=m.z.object({prompt:m.z.string(),model:m.z.enum(["text-davinci-003","text-curie-001","text-babbage-001","text-ada-001","code-davinci-002","code-cushman-002"]).default("text-davinci-003"),temperature:m.z.number().min(0).max(2).default(.7),top_p:m.z.number().min(0).max(1).default(1),frequency_penalty:m.z.number().min(-2).max(2).default(0),presence_penalty:m.z.number().min(-2).max(2).default(0),max_tokens:m.z.number().default(200),n:m.z.number().default(1)}),xe=m.z.object({text:m.z.string()});async function Ie(n,e){let t=D.parse(n);return{text:(await(await fetch("https://api.openai.com/v1/completions",{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)})).json()).choices[0]?.text.replace(/^(?:\n)+/gm,"")}}var K=require("eventsource-parser"),M=require("zod");var Pe=D.merge(M.z.object({stream:M.z.literal(!0).optional().default(!0)})),St=M.z.object({stream:M.z.instanceof(globalThis.ReadableStream??Object)});async function ve(n,e){let t=Pe.parse(n),o=await fetch("https://api.openai.com/v1/completions",{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)});return{stream:await be(o)}}async function be(n){let e=new TextEncoder,t=new TextDecoder,o=0;return new ReadableStream({async start(i){function a(s){if(s.type==="event"){let u=s.data;if(u==="[DONE]"){i.close();return}try{let y=JSON.parse(u).choices[0].text;if(o<2&&(y.match(/\n/)||[]).length)return;let v=e.encode(y);i.enqueue(v),o++}catch(d){i.error(d)}}}let p=(0,K.createParser)(a);for await(let s of n.body)p.feed(t.decode(s))}})}var R=require("zod"),we=R.z.object({string:R.z.string()}),It=R.z.object({arrayBuffer:R.z.instanceof(ArrayBuffer)});async function Ne(n){let e=we.parse(n);return{arrayBuffer:Uint8Array.from(atob(e.string),o=>o.charCodeAt(0)).buffer}}var l=require("zod"),Me=l.z.object({text:l.z.string(),speakingRate:l.z.number().min(.25).max(4).optional().default(1),pitch:l.z.number().min(-20).max(20).optional().default(0),encoding:l.z.enum(["MP3","FLAC","LINEAR16","MULAW","AMR","AMR_WB","OGG_OPUS","SPEEX_WITH_HEADER_BYTE","WEBM_OPUS"]).optional().default("MP3"),voice:l.z.object({language:l.z.string().optional().default("en-US"),name:l.z.enum(["en-US-Standard-A","en-US-Standard-C","en-US-Standard-D","en-US-Standard-E","en-US-Standard-F","en-US-Standard-G","en-US-Standard-H","en-US-Standard-I","en-US-Standard-J","en-US-Studio-M","en-US-Studio-O","en-US-Wavenet-A","en-US-Wavenet-B","en-US-Wavenet-C","en-US-Wavenet-D","en-US-Wavenet-E","en-US-Wavenet-F","en-US-Wavenet-G","en-US-Wavenet-H","en-US-Wavenet-I","en-US-Wavenet-J","en-US-News-K","en-US-News-L","en-US-News-M","en-US-News-N","en-US-Standard-A","en-US-Standard-B","en-US-Standard-C","en-US-Standard-D","en-US-Standard-E","en-US-Standard-F","en-US-Standard-G","en-US-Standard-H","en-US-Standard-I","en-US-Standard-J"]).or(l.z.string()).optional().default("en-US-Neural2-C")}).optional().default({language:"en-US",name:"en-US-Neural2-C"})}),vt=l.z.object({audio:l.z.string()});async function Re(n,e){let t=Me.parse(n),o=`https://us-central1-texttospeech.googleapis.com/v1beta1/text:synthesize?key=${e.googleapis}`,r={input:{text:t.text},voice:{languageCode:t.voice.language,name:t.voice.name},audioConfig:{audioEncoding:t.encoding,speakingRate:t.speakingRate,pitch:t.pitch}};return{audio:(await(await fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})).json()).audioContent}}var f=require("zod"),Ae="https://transcribe.whisperapi.com",Te=f.z.object({audioUrl:f.z.string().url(),language:f.z.string().default("en"),autoDetectLanguage:f.z.boolean().default(!1),fileType:f.z.string().default("mp3"),task:f.z.enum(["transcribe","translate"]).default("transcribe")}),wt=f.z.object({text:f.z.string()});async function De(n,e){let t=Te.parse(n),o=new FormData;o.append("url",t.audioUrl),t.autoDetectLanguage||o.append("language",t.language),o.append("fileType",t.fileType),o.append("task",t.task);let r=await fetch(Ae,{method:"POST",headers:{contentType:"application/json",Authorization:"Bearer "+e.whisperapi},body:o});if(!r.ok)throw new Error(r.statusText);return{text:(await r.json()).text.trim()}}async function U(n,e){let{pipelineInstanceId:t,userId:o,input:r}=await e.json(),{searchParams:i}=new URL(e.url);if(!i.has("id"))return new Response("Missing id",{status:400});let a=i.get("id"),p=n[a];return{output:await p.invoke(r,{pipelineInstanceId:t,userId:o}),pipeline:p}}function Ce(n){return async e=>{let t=await U(n,e);return t instanceof Response?t:t.pipeline.conf.stream&&t.output instanceof ReadableStream?new Response(t.output):new Response(JSON.stringify(t.output,null,2),{headers:{"content-type":"application/json;charset=UTF-8"}})}}0&&(module.exports={Pipeline,cleanContextVars,createClient,dalleBase64TextToImage,dalleUrlTextToImage,enhanceWithKeywords,googleImageLabeling,googleTextToSpeech,gpt3Prediction,gpt3PredictionStream,inputSchema,output,outputSchema,replaceMultipleStrings,replaceString,stabilityClipGuidancePreset,stabilityModel,stabilityTextToImage,stringToArrayBuffer,vercelEdgeFunction,vercelGenericEdge,whisperApi}); |
{ | ||
"name": "@aigur/client", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -0,3 +1,3 @@ | ||
import { ConcreteNode, NodeAction } from './types'; | ||
import { output } from './nodes/output/output'; | ||
import { ConcreteNode, NodeAction } from './types'; | ||
@@ -22,2 +22,3 @@ export class FlowBuilder< | ||
memory: MemoryData; | ||
userId: string; | ||
}) => Parameters<NodeDef>['0'], | ||
@@ -34,2 +35,3 @@ getMemory?: (data: { | ||
memory: MemoryData; | ||
userId: string; | ||
}) => Partial<MemoryData> | ||
@@ -44,2 +46,3 @@ ) { | ||
const prev = this.nodes.length > 0 ? this.nodes[this.nodes.length - 1] : input; | ||
const userId = '$context.pipeline.userId$'; | ||
const node = { | ||
@@ -52,2 +55,3 @@ action: nodeDefinition, | ||
memory, | ||
userId, | ||
}), | ||
@@ -57,3 +61,3 @@ // configure output to return a placeholder for any property accessed (e.g. $context.0.url$) | ||
memoryToSave: getMemory | ||
? getMemory({ nodes: this.nodes, prev: prev.output, output, input, memory }) | ||
? getMemory({ nodes: this.nodes, prev: prev.output, output, input, memory, userId }) | ||
: null, | ||
@@ -93,2 +97,3 @@ } as NewNode; | ||
memory: MemoryData; | ||
userId: string; | ||
}) => Output, | ||
@@ -103,2 +108,3 @@ getMemory?: (data: { | ||
memory: MemoryData; | ||
userId: string; | ||
}) => Partial<MemoryData> | ||
@@ -105,0 +111,0 @@ ) { |
@@ -66,3 +66,3 @@ import { NodeContext } from './types'; | ||
if (typeof value !== 'string') return []; | ||
const contextRegex = /\$context\.(\d+|input|memory)\.(\w+)\$/g; | ||
const contextRegex = /\$context\.(\d+|input|memory|pipeline)\.(\w+)\$/g; | ||
const matches = value.matchAll(contextRegex); | ||
@@ -69,0 +69,0 @@ const references: any[] = []; |
@@ -6,2 +6,3 @@ export * from './image/labeling/googleImageLabeling'; | ||
export * from './output/output'; | ||
export * from './text/modify/cleanContextVars'; | ||
export * from './text/modify/enhanceWithKeywords'; | ||
@@ -8,0 +9,0 @@ export * from './text/modify/replaceMultipleStrings'; |
@@ -27,1 +27,3 @@ import { z } from 'zod'; | ||
} | ||
// const text = payload.modifier.replace(/\$context\..*?\..*?\$/gm, '').trim(); |
@@ -1,16 +0,11 @@ | ||
import { FlowBuilder } from './builder'; | ||
import { delay } from './delay'; | ||
import { placeholdersToConcreteValues } from './getConcreteNodeInput'; | ||
import { makeid } from './makeid'; | ||
import { createContext } from './PipelineContext'; | ||
import { retrieveConcreteMemoryData } from './retrieveMemoryData'; | ||
import { | ||
APIKeys, | ||
ConcreteNode, | ||
EventType, | ||
PipelineConf, | ||
PipelineContext, | ||
PipelineProgressEvent, | ||
PipelineStatusEvent, | ||
APIKeys, ConcreteNode, EventType, PipelineConf, PipelineContext, PipelineProgressEvent, | ||
PipelineStatusEvent | ||
} from './types'; | ||
import { retrieveConcreteMemoryData } from './retrieveMemoryData'; | ||
import { createContext } from './PipelineContext'; | ||
import { makeid } from './makeid'; | ||
import { placeholdersToConcreteValues } from './getConcreteNodeInput'; | ||
import { delay } from './delay'; | ||
import { FlowBuilder } from './builder'; | ||
@@ -229,3 +224,3 @@ const DEFAULT_RETRIES = 2; | ||
try { | ||
const { action, input: inputPlaceholders, memoryToSave } = nodes[nodeIndex]; | ||
const { action, input: inputPlaceholders } = nodes[nodeIndex]; | ||
const contextNode = (context.values[nodeIndex] = { input: null, output: null }); | ||
@@ -232,0 +227,0 @@ contextNode.input = placeholdersToConcreteValues(inputPlaceholders, context.values); |
@@ -13,2 +13,12 @@ import { NodeContext, PipelineContext } from './types'; | ||
memory: { input: opts.memory, output: opts.memory }, | ||
pipeline: { | ||
input: { | ||
pipelineInstanceId: opts.pipelineInstanceId, | ||
userId: opts.userId, | ||
}, | ||
output: { | ||
pipelineInstanceId: opts.pipelineInstanceId, | ||
userId: opts.userId, | ||
}, | ||
}, | ||
} as Record<string, NodeContext<any, any>>; | ||
@@ -18,3 +28,3 @@ return { | ||
input: opts.input, | ||
output: {} as Output, | ||
output: {} as Output extends ReadableStream<any> ? string : Output, | ||
values, | ||
@@ -21,0 +31,0 @@ memory: opts.memory, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
83726
38
1934