@rizom/brain 0.2.0-alpha.446 → 0.2.0-alpha.448
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/brain.js +49 -42
- package/dist/chunks/{app-rrahvc1b.js → app-bgd5eyxd.js} +2 -2
- package/dist/chunks/{index-jggg6k00.js → index-7ahrzv8v.js} +2 -2
- package/dist/chunks/{index-9n2n5c7t.js → index-7m2gbgs2.js} +3 -3
- package/dist/chunks/{index-9n2n5c7t.js.map → index-7m2gbgs2.js.map} +1 -1
- package/dist/chunks/{index-jwec7q6m.js → index-x59am2rx.js} +2 -2
- package/dist/index.js +1 -1
- package/dist/model.js +49 -42
- package/dist/model.js.map +3 -3
- package/dist/ui/ask.js +158 -158
- package/dist/ui/dashboard.js +158 -158
- package/dist/ui/guest.js +158 -158
- package/package.json +1 -1
- /package/dist/chunks/{app-rrahvc1b.js.map → app-bgd5eyxd.js.map} +0 -0
- /package/dist/chunks/{index-jggg6k00.js.map → index-7ahrzv8v.js.map} +0 -0
- /package/dist/chunks/{index-jwec7q6m.js.map → index-x59am2rx.js.map} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{la as a,ma as b,na as c,oa as d}from"./index-
|
|
2
|
+
import{la as a,ma as b,na as c,oa as d}from"./index-7ahrzv8v.js";import"./index-dheher8v.js";import"./index-48ksf4j5.js";import"./index-ktmedhab.js";import"./index-w6648sqh.js";import"./index-3w748142.js";import"./index-0czhapph.js";import"./index-6246jggs.js";export{d as App,a as STARTUP_CHECK_API_KEY,c as buildShellConfig,b as toAppConfig};
|
|
3
3
|
|
|
4
4
|
//# debugId=9F8E2FF7965E30C264756E2164756E21
|
|
5
|
-
//# sourceMappingURL=app-
|
|
5
|
+
//# sourceMappingURL=app-bgd5eyxd.js.map
|
|
@@ -174,9 +174,9 @@ ${NS}`:""),tools:x,activeTools:y,...i!==void 0&&c.supportsTemperature&&{temperat
|
|
|
174
174
|
`),s=ep(i,a,{timeout:100});if(!s)return"Full content replacement (line diff omitted: comparison exceeded its time limit).";return s.filter((l)=>l.added||l.removed).flatMap((l)=>l.value.map((c)=>`${l.added?"+":"-"} ${c}`)).join(`
|
|
175
175
|
`)}function oC(e,t,n,o){return nJ(e,t,n,o)??oJ(e.entityType,t,n)??iJ(e.entityType,t,n)}function iC(e,t,n){return eC(e.entityType,e.metadata.status,aJ(e,t,n),n)==="non-publish"?"update":"publish"}function aC(e,t,n){return t.content!==void 0?eJ(e,t.content,n):rC(e,t.fields??{},n)}function tn(e){return{success:!1,error:e}}function sJ(e,t){if(e.edits!==void 0&&(e.content!==void 0||e.fields!==void 0))return tn("Provide only one of 'edits', 'content', or 'fields'.");if(e.confirmed&&e.contentHash&&t.contentHash!==e.contentHash)return tn("Entity was modified since you reviewed the changes. Please try again.");let n=e.edits!==void 0?{content:jI(t.content,e.edits)}:TI({...e.fields!==void 0?{fields:e.fields}:{},...e.content!==void 0?{content:e.content}:{}});if(n.content!==void 0&&n.fields!==void 0)return tn("Provide either 'content' or 'fields', not both");if(!n.content&&!n.fields)return tn("Provide 'content' (full replacement) or 'fields' (partial update)");return n}function sC(e){let{entityService:t,logger:n,entityRegistry:o}=e,i=en({label:"update",requestNoun:"the update"}),a=(c,u)=>{if(!c.confirmed||!c.confirmationToken||c.edits!==void 0||c.fields!==void 0||c.content?.trim())return{input:c,replayed:!1};let d=Qd.safeParse(i.takePending(c.confirmationToken));if(!d.success||d.data.entityType!==u.entityType||d.data.id!==u.id)return tn("No pending update confirmation found for this entity. Please request the update again.");return{input:d.data,replayed:!0}},s=async(c,u,d,m,p)=>{if(!m){let g=i.validateConfirmed(c.confirmationToken,c);if(g)return g}let f=aC(u,d,o);if(f.visibility!==u.visibility&&!Fs(p.userPermissionLevel,f.visibility))return tn(`Cannot set entity visibility to "${f.visibility}" \u2014 caller permission "${p.userPermissionLevel??"public"}" is not allowed to write at that level.`);try{let g=$o(p);if((await t.updateEntity({entity:f,options:{expectedContentHash:u.contentHash,...g?{eventContext:g}:{}}})).skipReason==="content-conflict")return tn("Entity was modified before the update could be saved. Please request and confirm the update again.")}catch(g){return tn(ke(g,"Failed to update entity"))}return{success:!0,data:{updated:u.id}}},l=(c,u,d)=>{let{fields:m,content:p,...f}=c;return{needsConfirmation:!0,toolName:"system_update",summary:`Update "${Ls(u)}"?`,completionSummary:`Updated ${II(u.entityType)}.`,preview:nC(u,d,o),args:i.buildArgs((g)=>({...f,...c.edits!==void 0?{edits:c.edits}:d,id:u.id,confirmed:!0,confirmationToken:g,contentHash:u.contentHash}))}};return Or("update","Update an entity's fields or content. For small content changes, fetch the entity and use edits with exact oldText/newText pairs instead of regenerating the whole document. Use only one of fields, content, or edits. Requires confirmation; call this tool without confirmed to request that confirmation instead of asking for plain-text approval. For direct requests that provide exact IDs to set an existing image as an entity cover, call this tool on the target entity with fields.coverImageId set to the image ID; do not stop after lookup.",Qd,async(c,u)=>{let d=await Nr(t,c.entityType,c.id,n,void 0,Wt(u.userPermissionLevel));if(!d.ok)return tn(d.error);let{entity:m}=d,p=a(c,m);if("success"in p)return p;let{input:f,replayed:g}=p,h=sJ(f,m);if("success"in h)return h;let v=oC(m,h,o,t);if(v)return v;let w=jr(e,f.entityType,iC(m,h,o),u);if(w)return w;return f.confirmed?s(f,m,h,g,u):l(f,m,h)},{visibility:"trusted",sideEffects:"writes"})}function lC(e){return[EI(e),PI(e),MI(e),sC(e)]}function Zs(e){if(e.interfaceType!==mt)return;if(e.userPermissionLevel!=="public"||e.isAnchor)throw Error("Guest execution denied")}var lJ=0.5;function cC(e){let{entityService:t,logger:n}=e;return[Sn("system","search","Search entities using semantic search. For broad search, make one system_search call with scope.kind all. Use scope.kind type only when the user asks for a specific entity type. Applies a default minScore of 0.5 to reduce weak matches; lower minScore only for exploratory or loose recall. Search results include each matched entity's content. When relevant results already contain the complete evidence needed, answer from those results instead of redundantly listing or getting the same entities. Search results are candidates; do not present weak or unrelated candidates as exact matches.",gI,async(o,i)=>{Zs(i);let a=Wt(i.userPermissionLevel);return{success:!0,data:{results:(await t.search({query:o.query,options:{limit:o.limit??e.searchLimit,...o.scope.kind==="type"&&{types:[o.scope.entityType]},minScore:o.minScore??lJ,...o.includeUngenerated!==void 0&&{includeUngenerated:o.includeUngenerated},visibilityScope:a}})).map((s)=>{let l=Xd(s.entity,e.entityRegistry);return{...s,entity:l,...l!==s.entity?{excerpt:l.content}:{}}})}}},{visibility:"public",sideEffects:"none",cli:{name:"search"}}),Sn("system","get","Retrieve a specific entity by type and identifier (ID, slug, or title). If retrieval fails, report the entity as not found rather than describing related generation work as pending.",fI,async(o,i)=>{if(Zs(i),!t.getEntityTypes().includes(o.entityType))return{success:!1,error:`Unknown entity type: ${o.entityType}. Available: ${t.getEntityTypes().join(", ")}`};let a=Wt(i.userPermissionLevel),s=await Nr(t,o.entityType,o.id,n,void 0,a);if(!s.ok)return{success:!1,error:s.error};return{success:!0,data:{entity:Xd(s.entity,e.entityRegistry)}}},{visibility:"public",sideEffects:"none",cli:{name:"get"}}),Sn("system","list","List entities by a known entity type. Returns metadata only \u2014 use system_get for full content. Use system_search, not system_list, for broad or vague lookup requests. Use system_list to inspect metadata dates such as publishedAt when the user asks for the latest item of a known type, such as latest blog post.",hI,async(o,i)=>{if(Zs(i),!t.getEntityTypes().includes(o.entityType))return{success:!1,error:`Unknown entity type: ${o.entityType}. Available: ${t.getEntityTypes().join(", ")}`};let s={visibilityScope:Wt(i.userPermissionLevel)};if(o.status&&o.status!=="any")s.metadata={status:o.status};let{defaultSort:l}=e.entityRegistry.getEntityTypeConfig(o.entityType),u=(await t.listEntities({entityType:o.entityType,options:{limit:o.limit??20,filter:s,...l?{sortFields:l}:{}}})).map(({content:d,contentHash:m,...p})=>p);return{success:!0,data:{entities:u,count:u.length}}},{visibility:"public",sideEffects:"none",cli:{name:"list"}})]}function uC(e){let{entityService:t}=e;return[Sn("system","insights",`Get aggregate content insights and analytics only. For a general overview of actual content, use system_list instead. Available types: ${e.insights.getTypes().join(", ")}.`,SI,async(n,o)=>{let i=Wt(o.userPermissionLevel);return{success:!0,data:await e.insights.get(n.type,t,i)}},{visibility:"public",sideEffects:"none"})]}function dC(e){let{jobs:t}=e;return[Or("job_status","Inspect runtime job status for ready checks only when the prior operation created a job, or for status disputes. With a known batch ID, pass batchId. Without an ID, call this tool with no arguments to list active jobs and batches; do not ask the user for an ID first. Do not argue from the transcript alone.",_I,async(n)=>{if(n.batchId){let a=await t.getBatchStatus(n.batchId);if(!a)return{success:!1,error:`No batch found with ID: ${n.batchId}`};let s=a.totalOperations>0?Math.round(a.completedOperations/a.totalOperations*100):0;return{success:!0,data:{batchId:n.batchId,status:a.status,progress:{total:a.totalOperations,completed:a.completedOperations,failed:a.failedOperations,percentComplete:s},currentOperation:a.currentOperation,errors:a.errors}}}let o=await t.getActiveJobs(n.jobTypes),i=await t.getActiveBatches();return{success:!0,data:{summary:{activeJobs:o.length,activeBatches:i.length},jobs:o.map((a)=>({id:a.id,type:a.type,status:a.status,priority:a.priority,retryCount:a.retryCount,createdAt:new Date(a.createdAt).toISOString(),startedAt:a.startedAt?new Date(a.startedAt).toISOString():null})),batches:i.map((a)=>({batchId:a.batchId,status:a.status.status,totalOperations:a.status.totalOperations,completedOperations:a.status.completedOperations,failedOperations:a.status.failedOperations,currentOperation:a.status.currentOperation,pluginId:a.metadata.metadata.pluginId,errors:a.status.errors}))}}},{visibility:"public",sideEffects:"none"})]}function cJ(e){let{entityCounts:t,daemons:n,endpoints:o,interactions:i,...a}=e;return a}function pC(e){return[Sn("system","status","Get system status including model, version, interfaces, and tools",r.object({}),async()=>({success:!0,data:cJ(await e.getAppInfo())}),{visibility:"public",sideEffects:"none",cli:{name:"status"}})]}function mC(e){return[...cC(e),...dC(e),...pC(e),...lC(e),...uC(e)]}function gC(e){return[{uri:"entity://types",name:"Entity Types",description:"List of registered entity types",mimeType:"text/plain",handler:async()=>({contents:[{uri:"entity://types",mimeType:"text/plain",text:e.entityService.getEntityTypes().join(`
|
|
176
176
|
`)}]})},{uri:"brain://identity",name:"Brain Identity",description:"Brain character \u2014 name, role, purpose, values",mimeType:"application/json",handler:async()=>({contents:[{uri:"brain://identity",mimeType:"application/json",text:JSON.stringify(e.getIdentity(),null,2)}]})},{uri:"brain://profile",name:"Anchor Profile",description:"Brain owner profile \u2014 name, bio, expertise",mimeType:"application/json",handler:async()=>({contents:[{uri:"brain://profile",mimeType:"application/json",text:JSON.stringify(e.getProfile(),null,2)}]})},{uri:"brain://status",name:"Brain Status",description:"System status \u2014 version, model, interfaces, tools",mimeType:"application/json",handler:async()=>({contents:[{uri:"brain://status",mimeType:"application/json",text:JSON.stringify(await e.getAppInfo(),null,2)}]})}]}function fC(e){let{entityService:t}=e;return[{name:"entity-list",uriTemplate:"entity://{type}",description:"List entities of a given type",mimeType:"application/json",list:async()=>t.getEntityTypes().map((o)=>({uri:`entity://${o}`,name:`${o} entities`})),complete:{type:async()=>t.getEntityTypes()},handler:async({type:n})=>{let o=t.getEntityTypes();if(!o.includes(n))throw Error(`Unknown entity type: ${n}. Available: ${o.join(", ")}`);let a=(await t.listEntities({entityType:n})).map((s)=>({id:s.id,entityType:s.entityType,...s.metadata,updated:s.updated}));return{contents:[{uri:`entity://${n}`,mimeType:"application/json",text:JSON.stringify(a,null,2)}]}}},{name:"entity-detail",uriTemplate:"entity://{type}/{id}",description:"Read a single entity by type and ID",mimeType:"text/markdown",complete:{type:async(n)=>{let o=t.getEntityTypes();return n?o.filter((i)=>i.startsWith(n)):o},id:async()=>[]},handler:async({type:n,id:o})=>{let i=await t.getEntity({entityType:n,id:o});if(!i)throw Error(`Entity not found: ${n}/${o}`);return{contents:[{uri:`entity://${n}/${o}`,mimeType:"text/markdown",text:i.content}]}}}]}function hC(e){return[{name:"create",description:"Create new content of any type",args:{type:{description:"Entity type (e.g. post, deck, note)",required:!0},topic:{description:"Topic or title for the content"}},handler:async({topic:n,type:o})=>({messages:[{role:"user",content:{type:"text",text:n?`Create a new ${o} about: ${n}`:`Create a new ${o}. Ask me what it should be about.`}}]})},{name:"generate",description:"AI-generate content with a prompt",args:{type:{description:`Entity type (${(()=>e.entityService.getEntityTypes().join(", "))()})`,required:!0},topic:{description:"What to generate",required:!0}},handler:async({type:n,topic:o})=>({messages:[{role:"user",content:{type:"text",text:`Generate a ${n} about: ${o}`}}]})},{name:"review",description:"Review and improve existing content",args:{type:{description:"Entity type",required:!0},id:{description:"Entity ID or slug",required:!0}},handler:async({type:n,id:o})=>({messages:[{role:"user",content:{type:"text",text:`Review my ${n} "${o}". Read it first, then give me specific feedback on structure, clarity, and impact. Suggest concrete improvements.`}}]})},{name:"publish",description:"Publish content \u2014 preview, confirm, and publish",args:{type:{description:"Entity type",required:!0},id:{description:"Entity ID or slug",required:!0}},handler:async({type:n,id:o})=>({messages:[{role:"user",content:{type:"text",text:`I want to publish my ${n} "${o}". Show me a preview first, then publish it.`}}]})},{name:"brainstorm",description:"Brainstorm ideas using brain context and expertise",args:{topic:{description:"Topic to brainstorm about",required:!0}},handler:async({topic:n})=>({messages:[{role:"user",content:{type:"text",text:`Let's brainstorm about: ${n}. Use my existing content and expertise as context. Give me fresh angles and concrete ideas.`}}]})}]}function yC(e){let t=e.entityService.getEntityTypes(),n=t.map((o)=>`- ${o}: ${e.entityRegistry.getAdapter(o).purpose}`);return["## Entity CRUD","","Use these system tools for ALL entity operations:","","Treat explicit verbs such as save, create, capture, remember, import, add/connect an agent, approve/archive an agent, update, delete, generate, publish, or sync as mutation requests. Entity-specific instructions may require proactively recording the user's request itself for demand or workflow tracking; follow those instructions even when the user did not use a separate save/create verb. Ordinary status questions like 'what is the status', 'is it ready', 'did that finish', or 'what happened' are not capture requests; answer them by using the relevant status/read tool for the prior operation. Never call system_create for a status follow-up.","",`- **system_create**: Create an entity from existing/concrete material. Requires confirmation before persisting; call system_create without \`confirmed\` to request that confirmation, and never pass \`confirmed: true\` on the initial user request. Use the typed \`visibility\` field instead of rewriting exact source text: omit it for public content, use \`shared\` for team/collaborator content, and use \`restricted\` for private/admin-only content. Public callers may write only public content, Trusted callers public or shared, and Admin callers all three levels. If the user only says 'not public' without clarifying team/shared versus private/admin-only, ask which scope they mean. Required \`source\` union: \`{ kind: "text", content }\` stores exact/direct content; \`{ kind: "url", url }\` creates URL/domain-backed records such as links (preserve bare domains as bare domains); \`{ kind: "upload", upload, transform: "extract-markdown" }\` imports extractable upload bytes as a markdown note; \`{ kind: "upload", upload, transform: "preserve" }\` preserves raw uploaded bytes as their durable file entity; \`{ kind: "prior-response", messageId? }\` saves a previous assistant answer/summary by reference without copying or paraphrasing it. If a direct save request includes the content in the same message, that content is sufficient, even if it is a short sentence or fragment after a colon or embedded in the request phrase (for example, "Save this memo about the launch timeline"); call system_create instead of asking the user to paste it again. If the immediate context is an assistant summary/answer about an upload and the user asks to save it/that/this/summary, create a note with \`source.kind: "prior-response"\`; do this even when the prior answer says there was limited readable content. Do not ask whether they meant the summary or the file after you just summarized/answered about the upload: save the visible prior response as a note. Do not treat a bare upload receipt like "I got filename. What would you like me to do?" as a summary/answer; if the user then says "save it", preserve the latest uploaded file itself with upload \`preserve\` (image uploads as entityType image, PDFs/documents as their file entity type). Only use \`source.kind: "upload"\` when the runtime supplies an actual upload reference/attachment; if the message contains a pasted uploaded-file transcript with readable content (for example, \`User uploaded a file "name.md": ...\`), save the visible transcript content as \`source.kind: "text"\`. Only use upload \`preserve\` otherwise when they explicitly want to save the uploaded file/document itself. Use system_generate, not system_create, for AI generation, generated images, cover images, and source-derived artifacts. Available entity types: ${t.join(", ")}.`,'- **system_generate**: Generate a new durable entity or deterministic artifact. Requires confirmation before queueing generation; call system_generate without `confirmed` to request that confirmation, and never pass `confirmed: true` on the initial user request. When the user asks you to create, write, draft, or generate new durable content and has not supplied final exact content to store, call system_generate instead of drafting the content in chat or asking for separate prose approval first. An underspecified generation request still supplies a usable prompt: preserve the user\'s wording and call system_generate rather than stopping to ask what details to highlight. If generation depends on an existing source entity (for example, a newsletter from a blog post), resolve the source with read/search/list tools first unless the user gives an exact entity id in quotes, then call system_generate with `operation.kind: "prompt-from-source"` in the same turn when a clear source is found. If you identify the latest source entity, do not stop after saying you found it or can generate from it; call system_generate immediately. If no existing durable source entity is resolved, use `operation.kind: "prompt"` in the same turn, including after an optional search returns no source; never invent source IDs, use upload IDs/filenames as entity refs, use profile/brain-character as a generic source, or create placeholder source refs. For broad topical prompts like \'about AI\' or \'about continuous learning\', use `operation.kind: "prompt"`. If the user asks for the latest published/blog source, use system_list for that entity type (for blog posts, entityType post) to inspect publishedAt dates; do not rely on semantic search result order. Choose the newest matching candidate by publishedAt (not updated/created order) and proceed with system_generate rather than asking for separate prose approval; do not say \'if that is the one you mean\' when a newest dated candidate is visible. Do not say \'I can generate it if you want\' or \'I need to queue it first\'; calling system_generate without `confirmed` is the confirmation request. Required `operation` union: `{ kind: "prompt", entityType, prompt }` generates a new non-image durable entity from a broad prompt with no source; `{ kind: "prompt-from-source", entityType, source: { entityType, entityId }, prompt }` generates from an existing resolved entity, such as a newsletter from a blog post. `{ kind: "standalone-image", prompt }` generates an unattached image; `{ kind: "cover-image", target: { entityType, entityId }, prompt }` generates an image and attaches it to an existing canonical entity as `coverImageId`; `{ kind: "attachment", source: { entityType, entityId }, attachmentType }` renders a deterministic artifact from an existing entity attachment provider. For save/render/regenerate/replace requests for source-derived artifacts, call `system_generate` with `operation.kind: "attachment"` immediately; do not say you can queue it later. Use `replace: true` when the user says regenerate, replace, refresh, or update an existing artifact. For OG/social preview renders, use `attachmentType: "og-image"`; the provider derives the output image and updates `ogImageId`. For deck carousel PDFs use `attachmentType: "carousel"`; for printable post/project PDFs use `attachmentType: "printable"`. If the user asks to attach a generated artifact to another entity, generate the artifact first in the same turn; do not ask whether they mean an existing artifact when the source entity is explicit or given as a quoted id such as deck `distributed-systems-primer`. Update the target only after the real artifact ID exists. To create an entity and a cover image, first create/generate only the entity, then after confirmation and after the real canonical entity ID is known call system_generate with operation.kind cover-image. When the user asks to create/regenerate a cover for an existing entity and search/get resolves a clear target, call system_generate with operation.kind cover-image in the same turn; do not stop after saying you found it. In a single initial request for \'a post with a cover image\', do not also call standalone-image; never guess a future target ID, and do not generate a standalone image as a substitute for a requested cover image.',"- **system_update**: Modify an entity's fields or content. Use `edits` for small content changes: fetch the entity, then send exact oldText/newText pairs, with each oldText matching once in the original Markdown. Put multiple non-overlapping edits in one call. Do not regenerate the whole note for a small change; omit `content` and `fields` when using `edits`. Never replace unchanged content with placeholders or ellipses. Use full `content` only for intentional whole-document replacements. Use `fields` for title, status, coverImageId, ogImageId, and other frontmatter/metadata changes. To remove or clear a cover image, set `fields.coverImageId` to null, not an empty string. Use system_update for coverImageId when an existing image entity id is known; if the user says to set an existing image as a cover, update `coverImageId` even when `ogImageId` already points at that image. To generate a new cover image for an existing entity, use system_generate with operation.kind cover-image. Cover images use `coverImageId`; OG/social previews use `ogImageId`; do not treat them as interchangeable. Requires confirmation before applying changes; call system_update without `confirmed` to request that confirmation, rather than asking for prose approval. For explicit publish requests, use the publishing tool if available instead of changing status with system_update; follow-up pronouns like 'publish it' should target the entity just read or updated in the conversation.","- **system_delete**: Admin-only entity removal. Requires confirmation before deleting. Never pass `confirmed: true` on the initial user request; call without `confirmed` so the confirmation flow can ask an administrator first. If system_delete is not available in the current tool surface, say deletion requires Admin access; do not imply a confirmation flow is available. Protected identity/profile records such as brain-character and anchor-profile cannot be deleted; update them instead.","- **system_get**: Retrieve a specific entity by type and ID/slug/title.","- **system_list**: List entities by type with optional filters. For simple list/show-all/summary requests that name or browse a known type or synonym (for example essays/articles/blog posts => post), use system_list with that entity type instead of semantic search. For 'summarize my blog posts' or similar whole-type summaries, first call system_list for entityType post, then summarize those returned entities. For 'latest' requests, use system_list metadata dates such as publishedAt to choose the newest candidate.","- **system_search**: Semantic search across all entities. Search results include matched entity content; when relevant results already provide the complete evidence needed, answer from them instead of redundantly calling system_list or system_get for those same entities. For each new user question about what they have written, mentioned, discussed, or saved, run a fresh search for that turn instead of answering from prior-turn search results or memory; this includes analysis phrasing such as 'How do I discuss X in my writing?' even if prior turns searched related topics.","","Do not ask for prose confirmation instead of calling the applicable mutating tool; for create, update, delete, generate, publish, sync, and similar state-changing requests, the initial tool call without `confirmed` is how you create the pending confirmation. Never claim a durable create/update/delete change was saved, created, done, or completed unless the relevant tool call succeeded or returned a pending confirmation. If a create/update/delete tool is unavailable, unauthorized, or intentionally not called, say you can't make that durable change from the current context; never say saved/created/done. For an explicit write request from an unauthorized/currently unwritable context, refuse directly; do not call system_status or system_search to check permission or look up related content. Entity type descriptions may mark projection-owned or system-maintained types read-only; refuse mutation requests for those types directly without calling read or write tools, searching for a target, or asking which record to mutate.","","Entity types \u2014 select `entityType` by what the type is for:",...n].join(`
|
|
177
|
-
`)}var qo="system",uJ=r.object({toolName:r.string(),args:r.unknown(),...bC.partial().shape});function Ks(e,t,n,o,i){for(let a of e)try{t(a)}catch{i.debug(`System ${o} ${n(a)} already registered, skipping`)}}function _C(e,t,n,o){let i=mC(e);Ks(i,(d)=>t.registerTool(qo,d),(d)=>d.name,"tool",o);let a=n.subscribe(vC.toolExecute(qo),async(d)=>{let m=uJ.safeParse(d.payload);if(!m.success)return{success:!1,error:"Invalid system tool execute payload"};let{toolName:p,args:f,interfaceType:g,actor:h,conversationId:v,channelId:w,userPermissionLevel:S}=m.data,y=i.find((C)=>C.name===p);if(!y)return{success:!1,error:`System tool not found: ${p}`};let x={interfaceType:g??"system",actor:h??{kind:"service",serviceId:"system"}};if(v)x.conversationId=v;if(w)x.channelId=w;if(S)x.userPermissionLevel=S;return{success:!0,data:await y.handler(f,x)}});o.debug(`Registered ${i.length} system tools`);let s=gC(e);Ks(s,(d)=>t.registerResource(qo,d),(d)=>d.uri,"resource",o),o.debug(`Registered ${s.length} system resources`);let l=fC(e);Ks(l,(d)=>t.registerResourceTemplate(qo,d),(d)=>d.uriTemplate,"resource template",o),o.debug(`Registered ${l.length} system resource templates`);let c=hC(e);Ks(c,(d)=>t.registerPrompt(qo,d),(d)=>d.name,"prompt",o),o.debug(`Registered ${c.length} system prompts`);let u=yC(e);try{t.registerInstructions(qo,u)}catch{o.debug("System instructions already registered, skipping")}return o.debug("Registered system instructions"),a}function TC(e){let{services:t,jobs:n,insights:o,query:i,getAppInfo:a}=e,s=t.jobQueueService,l=t.logger.child("system"),c=_C({entityService:t.entityService,entityRegistry:t.entityRegistry,jobs:{...n,enqueue:SC(s,"system",!1),enqueueBatch:wC(n,"system"),registerHandler:xC(s,"system")},conversationService:t.conversationService,runtimeUploads:t.runtimeUploadRegistry,attachments:Ys(t.attachmentRegistry),logger:l,query:i,getIdentity:()=>t.identityService.getCharacter(),getProfile:()=>t.profileService.getProfile(),getAppInfo:a,searchLimit:10,insights:o,permissionService:t.permissionService},t.mcpService,t.messageBus,l);t.disposables.push(c)}class sp{scope;closePromise=null;closed=!1;constructor(){this.scope=de.runSync(Xe.make())}buildLayer(e){this.assertOpen();let t=de.runSyncExit(Xr.buildWithScope(e,this.scope));if(tt.isFailure(t))throw ir.squash(t.cause);return t.value}addFinalizer(e){this.assertOpen(),de.runSync(Xe.addFinalizer(this.scope,de.promise(async()=>{await e()})))}addSyncFinalizer(e){this.assertOpen(),de.runSync(Xe.addFinalizer(this.scope,de.sync(()=>{e()})))}async fork(e){if(this.closed)throw Error("Cannot start background work after shell shutdown");await Mr(de.forkIn(e,this.scope))}close(e=tt.void){if(this.closePromise)return this.closePromise;if(this.closed)return Promise.resolve();return this.closed=!0,this.closePromise=Mr(Xe.close(this.scope,e)),this.closePromise}closeSync(e){if(this.closed)return;this.closed=!0,de.runSync(Xe.close(this.scope,e))}assertOpen(){if(this.closed)throw Error("Cannot register cleanup after shell shutdown")}}class ia{config;services;lifecycle;bootloader;initialized=!1;lifecycleState="constructed";bootMode;bootPromise=null;shutdownPromise=null;insightsRegistry;bootTime=Date.now();endpointRegistry=new Zd;interactionRegistry=new Kd;httpRouteRegistry=Us.createFresh();jobs;static createFresh(e,t,n){return new ia(pa(e),t,n)}constructor(e,t,n){this.config=e,this.lifecycle=new sp,RC(this,()=>this.httpRouteRegistry.getSnapshot());let o=t?.logger??vr.getInstance(),i=Ns.createFresh(o,this.config,n?.processRole);try{this.services=i.initializeServices(this.lifecycle,t),this.jobs=sI(this.services.batchJobManager,this.services.jobQueueService),this.insightsRegistry=nI(this.services.entityRegistry),this.bootloader=new Wd(this.config,this.services,this.lifecycle,i,n?.processRole,{registerCoreDataSources:()=>xp(this.services,this.config),finalizeHttpRoutes:()=>{this.httpRouteRegistry.finalize(uI(this.services.pluginManager))},registerSystemCapabilities:()=>TC({services:this.services,jobs:this.jobs,insights:this.insightsRegistry,query:(a,s)=>this.query(a,s),getAppInfo:()=>this.getAppInfo()}),createProjectionInputContext:()=>({entities:this.services.entityService,resolvePrompt:(a,s)=>ma(this.services.entityService,a,s),appInfo:()=>this.getAppInfo(),identityInput:()=>{let a=this.getIdentity(),s=this.getProfile();return CC.parse({brainName:a.name,role:a.role,purpose:a.purpose,values:a.values,profileName:s.name,...s.description!==void 0?{profileDescription:s.description}:{},...s.organization!==void 0?{profileOrganization:s.organization}:{}})}}),createProjectionExecutionContext:()=>({ai:kC(this),logger:this.services.logger.child("ProjectionRuntime")}),...t?.projectionRuntime&&{projectionRuntime:t.projectionRuntime}}),i.wireShell(this.services,this),pI(this.lifecycle,this.services)}catch(a){try{this.lifecycle.closeSync(tt.fail(a))}catch(s){o.error("Failed to roll back Shell service construction",s)}throw a}}getInsightsRegistry(){return this.insightsRegistry}async initialize(e){this.services.logger.debug("Shell.initialize() called");let t=e?.mode;if(this.lifecycleState==="running")return this.services.logger.warn("Shell already initialized"),Promise.resolve();if(this.lifecycleState==="booting"){if(this.bootMode!==t)return Promise.reject(Error(`Shell is already initializing in ${this.bootMode??"normal"} mode; cannot join ${t??"normal"} mode`));return this.bootPromise??Promise.resolve()}if(this.lifecycleState==="closing"||this.lifecycleState==="closed")return Promise.reject(Error("Cannot initialize a closing shell"));if(this.lifecycleState==="failed")return Promise.reject(Error("Cannot initialize a shell after boot failure"));return this.lifecycleState="booting",this.bootMode=t,this.bootPromise=this.boot(e),this.bootPromise}async boot(e){try{if(await this.bootloader.boot(e),this.lifecycleState==="booting"){if(this.lifecycleState="running",this.initialized=!0,e?.mode===void 0)await this.services.messageBus.send({type:zs.shellReady,payload:{timestamp:new Date().toISOString()},sender:"shell",broadcast:!0}),this.services.logger.debug("Emitted shell ready event")}}catch(t){if(this.initialized=!1,this.services.logger.error("Failed to initialize Shell",t),this.lifecycleState!=="closing")this.lifecycleState="failed";try{await this.lifecycle.close(tt.fail(t))}catch(n){this.services.logger.error("Failed to clean up Shell after initialization failure",n)}throw t}}registerTemplates(e,t){this.services.logger.debug("Registering templates",{pluginId:t,count:Object.keys(e).length});for(let[n,o]of Object.entries(e))this.registerTemplate(n,o,t)}shutdown(){return this.shutdownPromise??=this.shutdownShell(),this.shutdownPromise}async shutdownShell(){if(this.services.logger.debug("Shutting down Shell"),this.lifecycleState==="closed")return;let e=this.bootPromise;if(this.lifecycleState="closing",this.initialized=!1,e)try{await e}catch{}await this.lifecycle.close(),this.lifecycleState="closed",this.services.logger.debug("Shell shutdown complete")}async generateContent(e){return this.requireInitialized("Shell content generation"),Tp(this.services,e)}async query(e,t){this.requireInitialized("Shell query");let n=await this.getAppInfo(),o={...t,appInfo:n,timestamp:new Date().toISOString()},{conversationHistory:i,...a}=o;return IC.parse(await this.generateContent({prompt:e,templateName:Yo.KNOWLEDGE_QUERY,...i&&{conversationHistory:i},data:a,interfacePermissionGrant:"public"}))}registerPlugin(e){this.requireInitialized("Plugin registration"),this.services.pluginManager.registerPlugin(e)}isInitialized(){return this.initialized}requireInitialized(e){if(!this.initialized)throw Error(`${e} attempted before initialization`)}getEntityService(){return this.services.entityService}getConversationService(){return this.services.conversationService}getEntityRegistry(){return this.services.entityRegistry}async generateObject(e,t,n){this.requireInitialized("Shell generateObject");let{object:o}=await this.services.aiService.generateObject("You are a helpful assistant. Respond with the requested structured data.",e,t,n);return{object:o}}async judge(e){return this.requireInitialized("Shell judge"),this.services.aiService.judge(e)}getAIService(){return this.services.aiService}generateImage(e,t){return this.services.aiService.generateImage(e,t)}canGenerateImages(){return this.services.aiService.canGenerateImages()}getPluginManager(){return this.services.pluginManager}getContentService(){return this.services.contentService}getRenderService(){return this.services.renderService}getAttachmentRegistry(){return Ys(this.services.attachmentRegistry)}getRuntimeUploadRegistry(){return EC(this.services.runtimeUploadRegistry)}getRuntimeState(){return this.services.runtimeStateService}getRecurringChecks(e){return this.services.recurringCheckService.namespace(e)}isJobQueueWorkerRunning(){return this.services.jobQueueWorker.isWorkerRunning()}getMessageBus(){return this.services.messageBus}getLogger(){return this.services.logger}getJobQueueService(){return this.services.jobQueueService}getMCPService(){return this.services.mcpService}listToolsForPermissionLevel(e){return this.services.mcpService.listToolsForPermissionLevel(e).map(({pluginId:t,tool:n})=>({name:n.name,description:n.description,pluginId:t}))}getPermissionService(){return this.services.permissionService}getAgentService(){return this.services.agentService}registerTools(e,t){for(let n of t)try{this.services.mcpService.registerTool(e,n)}catch(o){this.services.logger.error(`Failed to register tool ${n.name} from ${e}:`,o)}}registerResources(e,t){for(let n of t)try{this.services.mcpService.registerResource(e,n)}catch(o){this.services.logger.error(`Failed to register resource ${n.name} from ${e}:`,o)}}registerResourceTemplate(e,t){this.services.mcpService.registerResourceTemplate(e,t)}registerPrompt(e,t){this.services.mcpService.registerPrompt(e,t)}registerInstructions(e,t){if(this.services.mcpService.registerInstructions(e,t),this.initialized)this.services.agentService.invalidateAgent()}async unregisterPluginCapabilities(e){this.services.mcpService.unregisterPlugin?.(e),this.services.jobQueueService.unregisterPluginHandlers(e),this.endpointRegistry.unregister(e),this.interactionRegistry.unregister(e);for(let n of this.services.templateRegistry.getNames())if(n.startsWith(`${e}:`))this.services.templateRegistry.unregister(n);let t=this.config.evalHandlerRegistry;if(t){for(let n of t.list())if(n.pluginId===e)t.unregister(e,n.handlerId)}this.services.agentService.invalidateAgent(),await this.services.recurringCheckService.unregisterPlugin(e)}getPluginPackageName(e){return this.services.pluginManager.getPluginPackageName(e)}hasPlugin(e){return this.services.pluginManager.hasPlugin(e)}getPluginHttpRouteManifest(){return this.httpRouteRegistry.getManifest()}getPluginApiRoutes(){return this.httpRouteRegistry.getApiRoutes()}getPluginWebRoutes(){return this.httpRouteRegistry.getWebRoutes()}registerDaemon(e,t,n){this.services.daemonRegistry.register(e,t,n)}registerEndpoint(e){this.endpointRegistry.register(e)}listEndpoints(){return this.endpointRegistry.list()}registerInteraction(e){this.interactionRegistry.register(e)}listInteractions(){return this.interactionRegistry.list()}registerTemplate(e,t,n){let o=n?`${n}:${e}`:`shell:${e}`;this.services.templateRegistry.register(o,t),this.services.logger.debug(`Registered template: ${o}`)}getTemplate(e){return this.services.templateRegistry.get(e)}getDataSourceRegistry(){return this.services.dataSourceRegistry}getIdentity(){return this.services.identityService.getCharacter()}getProfile(){return this.services.profileService.getProfile()}getProfileKindRegistry(){return this.services.profileKindRegistry}getChannelRegistry(){return this.services.channelRegistry}getInboxRegistry(){return this.services.inboxRegistry}getInboxFollowUpRegistry(){return this.services.inboxFollowUpRegistry}getOperationalHealthRegistry(){return this.services.operationalHealthRegistry}getAccountSettingsRegistry(){return this.services.accountSettingsRegistry}getDomain(){return this.config.siteBaseUrl}getLocalSiteUrl(){return this.config.localSiteUrl}shouldPreferLocalUrls(){return this.config.preferLocalUrls}getThemeCSS(){return this.config.themeCSS}getSpaces(){return this.config.spaces}getDataDir(){return this.config.dataDir}getGitBrokerSocket(){return this.config.gitBrokerSocket}getGitBrokerCheckout(){return this.config.gitBrokerCheckout}registerEvalHandler(e,t,n){this.config.evalHandlerRegistry?.register(e,t,n)}async getAppInfo(){return yp({config:this.config,services:this.services,bootTime:this.bootTime,endpoints:()=>this.listEndpoints(),interactions:()=>this.listInteractions()})}getRuntimeReadiness(){return _p(this.services)}}var AC={kind:"service",serviceId:"brain-cli"},lp=`${AC.kind}:${AC.serviceId}`;var dJ=r.object({provider:r.enum(["hetzner","docker"]).default("hetzner"),serverSize:r.string().default("cx33"),location:r.string().default("fsn1"),domain:r.string().optional(),docker:r.object({enabled:r.boolean().default(!0),image:r.string().optional()}).prefault({}),ports:r.object({default:r.number().default(3333),preview:r.number().default(4321),production:r.number().default(8080)}).prefault({}),cdn:r.object({enabled:r.boolean().default(!1),provider:r.enum(["bunny","none"]).default("none")}).prefault({}),dns:r.object({enabled:r.boolean().default(!1),provider:r.enum(["bunny","none"]).default("none")}).prefault({}),paths:r.object({install:r.string().optional(),data:r.string().optional()}).prefault({})}),MC=r.object({name:r.string().default("brain-app"),version:r.string().default("1.0.0"),database:r.string().optional(),aiApiKey:r.string().optional(),aiImageKey:r.string().optional(),aiModel:r.string().optional(),aiReasoningEffort:Xn.optional(),logLevel:Qn.optional(),logFile:r.string().optional(),profileKind:r.string().trim().min(1).optional(),plugins:r.array(da).default([]),spaces:r.array(r.string()).default([]),identity:PC.optional(),agentInstructions:r.array(r.string()).optional(),deployment:dJ.prefault({})});async function FC(e,t){await wn({label:"entity",config:e,schema:{assets:OC,entities:jC,projectionDirtyInputs:NC,projectionWaves:DC,projectionIncidents:zC,projectionWaveInputs:UC,projectionWaveRules:$C,projectionRuleMemos:qC},migrationsFolder:xn(import.meta.url,"entity-service"),authTokenEnv:"DATABASE_AUTH_TOKEN",logger:t,afterMigrate:LC})}async function JC(e,t){await wn({label:"job-queue",config:e,schema:{jobQueue:BC,jobWorkerSessions:GC},migrationsFolder:xn(import.meta.url,"job-queue"),authTokenEnv:"JOB_QUEUE_DATABASE_AUTH_TOKEN",logger:t})}async function ZC(e,t){await wn({label:"conversation",config:e,schema:{conversations:HC,messages:WC,summaryTracking:VC},migrationsFolder:xn(import.meta.url,"conversation-service"),authTokenEnv:"CONVERSATION_DATABASE_AUTH_TOKEN",logger:t})}async function KC(e,t){await wn({label:"runtime-state",config:e,schema:{runtimeStateRecords:Le},migrationsFolder:xn(import.meta.url,"runtime-state"),authTokenEnv:"RUNTIME_STATE_DATABASE_AUTH_TOKEN",logger:t})}import{mkdir as cp}from"fs/promises";import{isAbsolute as pJ}from"path";function YC(e=process.env){return{dataDir:e.XDG_DATA_HOME??"./data",cacheDir:e.XDG_CACHE_HOME??"./cache",distDir:"./dist"}}function QC(e=process.env){let t=e.BRAIN_GIT_BROKER_CHECKOUT;if(!t)return;if(!pJ(t))throw Error(`Git broker checkout path must be absolute: ${t}`);return t}function XC(e=process.env){let t=e.BRAIN_GIT_BROKER_SOCKET;if(!t)return;let n=107;if(Buffer.byteLength(t)>n)throw Error(`Git broker socket path is too long for a unix socket (${Buffer.byteLength(t)} > ${n} bytes): ${t}`);return t}function e0(e=process.env){return Cn(YC(e))}async function t0(e=process.env){let t=YC(e);try{await cp(t.dataDir,{recursive:!0}),await cp(t.cacheDir,{recursive:!0}),await cp(t.distDir,{recursive:!0})}catch(n){let o=n instanceof Error&&n.message.includes("EACCES")?`Cannot create data directories \u2014 permission denied. Run from a writable directory or check permissions on ${t.dataDir}`:`Cannot create data directories: ${ke(n)}`;throw Error(o,{cause:n})}return Cn(t)}class up{logger;migrations;constructor(e,t){this.logger=e,this.migrations=t??{getStandardConfigWithDirectories:()=>t0(),migrateEntities:FC,migrateJobQueue:JC,migrateConversations:ZC,migrateRuntimeState:KC}}async runAllMigrations(e){this.logger.debug("Running database migrations...");let t=await this.migrations.getStandardConfigWithDirectories();if(e?.database)t.database.url=e.database;if(e?.jobQueueDatabase)t.jobQueueDatabase.url=e.jobQueueDatabase;if(e?.conversationDatabase)t.conversationDatabase.url=e.conversationDatabase;if(e?.runtimeStateDatabase)t.runtimeStateDatabase.url=e.runtimeStateDatabase;await this.migrateEntityDatabase(t),await this.migrateJobQueueDatabase(t),await this.migrateConversationDatabase(t),await this.migrateRuntimeStateDatabase(t),this.logger.debug("All database migrations completed successfully")}async migrateEntityDatabase(e){this.logger.debug("Running entity database migrations..."),await this.migrations.migrateEntities({url:e.database.url,...e.database.authToken&&{authToken:e.database.authToken}},this.logger)}async migrateJobQueueDatabase(e){this.logger.debug("Running job queue database migrations..."),await this.migrations.migrateJobQueue({url:e.jobQueueDatabase.url,...e.jobQueueDatabase.authToken&&{authToken:e.jobQueueDatabase.authToken}},this.logger)}async migrateConversationDatabase(e){this.logger.debug("Running conversation database migrations..."),await this.migrations.migrateConversations({url:e.conversationDatabase.url,...e.conversationDatabase.authToken&&{authToken:e.conversationDatabase.authToken}},this.logger)}async migrateRuntimeStateDatabase(e){this.logger.debug("Running runtime state database migrations..."),await this.migrations.migrateRuntimeState({url:e.runtimeStateDatabase.url,...e.runtimeStateDatabase.authToken&&{authToken:e.runtimeStateDatabase.authToken}},this.logger)}}var mJ="NODE_ENV";function gJ(){return process.env[mJ]}function r0(){return gJ()!=="production"}var fJ="startup-check";function hJ(e){let n={...MC.parse(e??{}),plugins:e?.plugins??[]};if(e?.permissions)n.permissions=e.permissions;if(e?.spaces)n.spaces=e.spaces;if(e?.cliConfig)n.cliConfig=e.cliConfig;if(e?.shellConfig)n.shellConfig=e.shellConfig;return n}function yJ(e,t){let n={plugins:e.plugins??[],...e.shellConfig};return vJ(n),bJ(e,n),_J(e,n,t),SJ(e,n),wJ(e,n),xJ(e,n),TJ(e,n),IJ(e,n),CJ(e,n),n}function vJ(e){let t=e0();e.database??=t.database,e.jobQueueDatabase??=t.jobQueueDatabase,e.conversationDatabase??=t.conversationDatabase,e.runtimeStateDatabase??=t.runtimeStateDatabase,e.embeddingDatabase??=t.embeddingDatabase,e.embedding??=t.embedding,e.gitBrokerSocket??=XC(),e.gitBrokerCheckout??=QC()}function bJ(e,t){if(e.database)t.database={url:e.database};if(e.profileKind)t.profileKind=e.profileKind;t.features={}}function _J(e,t,n){let o=n?.mode==="startup-check";if(!e.aiApiKey&&!e.aiImageKey&&!e.aiModel&&!e.aiReasoningEffort&&!o)return;t.ai={...t.ai,...o&&!t.ai?.apiKey&&{apiKey:fJ},...e.aiApiKey&&{apiKey:e.aiApiKey},...e.aiImageKey&&{imageApiKey:e.aiImageKey},...e.aiModel&&{model:e.aiModel},...e.aiReasoningEffort&&{reasoningEffort:e.aiReasoningEffort}}}function SJ(e,t){if(!e.logLevel&&!e.logFile)return;t.logging={level:e.logLevel??"info",format:"text",context:e.name,...e.logFile&&{file:e.logFile}}}function wJ(e,t){let n=e.permissions?.rules??[];t.permissions={...e.permissions,rules:n.some((o)=>o.pattern===lp)?n:[{pattern:lp,level:"admin"},...n]}}function xJ(e,t){if(e.spaces)t.spaces=e.spaces}function TJ(e,t){if(e.identity)t.identity=e.identity}function IJ(e,t){if(e.agentInstructions)t.agentInstructions=e.agentInstructions}function CJ(e,t){if(t.name=e.name,t.version=e.version,e.deployment.domain)t.siteBaseUrl=e.deployment.domain;t.localSiteUrl=`http://localhost:${e.deployment.ports.production}`,t.preferLocalUrls=r0()}class pp{shell=null;config;signalScope=null;signalShutdownFiber=null;stopPromise=null;hasCLI=!1;static create(e,t){return new pp(hJ(e),t)}constructor(e,t){if(this.config=e,this.hasCLI=process.argv.slice(2).includes("--cli"),t)this.shell=t}async migrate(){let e=vr.getInstance();await new up(e).runAllMigrations({database:this.config.shellConfig?.database?.url??this.config.database,jobQueueDatabase:this.config.shellConfig?.jobQueueDatabase?.url,conversationDatabase:this.config.shellConfig?.conversationDatabase?.url,runtimeStateDatabase:this.config.shellConfig?.runtimeStateDatabase?.url})}createShell(e,t){this.shell=ia.createFresh(yJ(this.config,e),void 0,{...t&&{processRole:t}})}async registerCLIInterface(){if(!this.hasCLI)return;let e=this.getShell().getPluginManager(),{CLIInterface:t}=await import("./index-9n2n5c7t.js"),n=new t(this.config.cliConfig);e.registerPlugin(n)}async initialize(e,t){if(!this.shell){if(!t?.migrationsCompleted)await this.migrate();this.createShell(e,t?.processRole)}await this.registerCLIInterface(),await this.getShell().initialize(e)}async start(){if(this.stopPromise)return;this.setupSignalHandlers()}stop(){return this.stopPromise??=this.stopApp(),this.stopPromise}async stopApp(){await this.closeSignalScope(),await this.shell?.shutdown()}async run(e){let n={debug:Ut.DEBUG,info:Ut.INFO,warn:Ut.WARN,error:Ut.ERROR}[this.config.logLevel??"info"]??Ut.INFO,o=vr.createFresh({level:n,context:this.config.name,useStderr:this.hasCLI});if(this.hasCLI)vr.getInstance().setUseStderr(!0);try{await this.initialize(void 0,e),await this.start(),e?.onRuntimeReady?.(),o.info(`\u2705 ${this.config.name} v${this.config.version} ready`),process.stdin.resume()}catch(i){o.error(`\u274C Failed to start ${this.config.name}:`,i),process.exit(1)}}static async run(e,t,n){await pp.create(e,t).run(n)}setupSignalHandlers(){if(this.signalScope)return;let e=de.runSync(Xe.make()),t=()=>{this.requestGracefulShutdown("SIGINT")},n=()=>{this.requestGracefulShutdown("SIGTERM")},o=dp(["SIGINT"],t),i=dp(["SIGTERM"],n);de.runSync(Xe.addFinalizer(e,de.sync(()=>{i(),o()}))),this.signalScope=e}requestGracefulShutdown(e){if(this.signalShutdownFiber)return;let t=vr.getInstance();t.info(`
|
|
177
|
+
`)}var qo="system",uJ=r.object({toolName:r.string(),args:r.unknown(),...bC.partial().shape});function Ks(e,t,n,o,i){for(let a of e)try{t(a)}catch{i.debug(`System ${o} ${n(a)} already registered, skipping`)}}function _C(e,t,n,o){let i=mC(e);Ks(i,(d)=>t.registerTool(qo,d),(d)=>d.name,"tool",o);let a=n.subscribe(vC.toolExecute(qo),async(d)=>{let m=uJ.safeParse(d.payload);if(!m.success)return{success:!1,error:"Invalid system tool execute payload"};let{toolName:p,args:f,interfaceType:g,actor:h,conversationId:v,channelId:w,userPermissionLevel:S}=m.data,y=i.find((C)=>C.name===p);if(!y)return{success:!1,error:`System tool not found: ${p}`};let x={interfaceType:g??"system",actor:h??{kind:"service",serviceId:"system"}};if(v)x.conversationId=v;if(w)x.channelId=w;if(S)x.userPermissionLevel=S;return{success:!0,data:await y.handler(f,x)}});o.debug(`Registered ${i.length} system tools`);let s=gC(e);Ks(s,(d)=>t.registerResource(qo,d),(d)=>d.uri,"resource",o),o.debug(`Registered ${s.length} system resources`);let l=fC(e);Ks(l,(d)=>t.registerResourceTemplate(qo,d),(d)=>d.uriTemplate,"resource template",o),o.debug(`Registered ${l.length} system resource templates`);let c=hC(e);Ks(c,(d)=>t.registerPrompt(qo,d),(d)=>d.name,"prompt",o),o.debug(`Registered ${c.length} system prompts`);let u=yC(e);try{t.registerInstructions(qo,u)}catch{o.debug("System instructions already registered, skipping")}return o.debug("Registered system instructions"),a}function TC(e){let{services:t,jobs:n,insights:o,query:i,getAppInfo:a}=e,s=t.jobQueueService,l=t.logger.child("system"),c=_C({entityService:t.entityService,entityRegistry:t.entityRegistry,jobs:{...n,enqueue:SC(s,"system",!1),enqueueBatch:wC(n,"system"),registerHandler:xC(s,"system")},conversationService:t.conversationService,runtimeUploads:t.runtimeUploadRegistry,attachments:Ys(t.attachmentRegistry),logger:l,query:i,getIdentity:()=>t.identityService.getCharacter(),getProfile:()=>t.profileService.getProfile(),getAppInfo:a,searchLimit:10,insights:o,permissionService:t.permissionService},t.mcpService,t.messageBus,l);t.disposables.push(c)}class sp{scope;closePromise=null;closed=!1;constructor(){this.scope=de.runSync(Xe.make())}buildLayer(e){this.assertOpen();let t=de.runSyncExit(Xr.buildWithScope(e,this.scope));if(tt.isFailure(t))throw ir.squash(t.cause);return t.value}addFinalizer(e){this.assertOpen(),de.runSync(Xe.addFinalizer(this.scope,de.promise(async()=>{await e()})))}addSyncFinalizer(e){this.assertOpen(),de.runSync(Xe.addFinalizer(this.scope,de.sync(()=>{e()})))}async fork(e){if(this.closed)throw Error("Cannot start background work after shell shutdown");await Mr(de.forkIn(e,this.scope))}close(e=tt.void){if(this.closePromise)return this.closePromise;if(this.closed)return Promise.resolve();return this.closed=!0,this.closePromise=Mr(Xe.close(this.scope,e)),this.closePromise}closeSync(e){if(this.closed)return;this.closed=!0,de.runSync(Xe.close(this.scope,e))}assertOpen(){if(this.closed)throw Error("Cannot register cleanup after shell shutdown")}}class ia{config;services;lifecycle;bootloader;initialized=!1;lifecycleState="constructed";bootMode;bootPromise=null;shutdownPromise=null;insightsRegistry;bootTime=Date.now();endpointRegistry=new Zd;interactionRegistry=new Kd;httpRouteRegistry=Us.createFresh();jobs;static createFresh(e,t,n){return new ia(pa(e),t,n)}constructor(e,t,n){this.config=e,this.lifecycle=new sp,RC(this,()=>this.httpRouteRegistry.getSnapshot());let o=t?.logger??vr.getInstance(),i=Ns.createFresh(o,this.config,n?.processRole);try{this.services=i.initializeServices(this.lifecycle,t),this.jobs=sI(this.services.batchJobManager,this.services.jobQueueService),this.insightsRegistry=nI(this.services.entityRegistry),this.bootloader=new Wd(this.config,this.services,this.lifecycle,i,n?.processRole,{registerCoreDataSources:()=>xp(this.services,this.config),finalizeHttpRoutes:()=>{this.httpRouteRegistry.finalize(uI(this.services.pluginManager))},registerSystemCapabilities:()=>TC({services:this.services,jobs:this.jobs,insights:this.insightsRegistry,query:(a,s)=>this.query(a,s),getAppInfo:()=>this.getAppInfo()}),createProjectionInputContext:()=>({entities:this.services.entityService,resolvePrompt:(a,s)=>ma(this.services.entityService,a,s),appInfo:()=>this.getAppInfo(),identityInput:()=>{let a=this.getIdentity(),s=this.getProfile();return CC.parse({brainName:a.name,role:a.role,purpose:a.purpose,values:a.values,profileName:s.name,...s.description!==void 0?{profileDescription:s.description}:{},...s.organization!==void 0?{profileOrganization:s.organization}:{}})}}),createProjectionExecutionContext:()=>({ai:kC(this),logger:this.services.logger.child("ProjectionRuntime")}),...t?.projectionRuntime&&{projectionRuntime:t.projectionRuntime}}),i.wireShell(this.services,this),pI(this.lifecycle,this.services)}catch(a){try{this.lifecycle.closeSync(tt.fail(a))}catch(s){o.error("Failed to roll back Shell service construction",s)}throw a}}getInsightsRegistry(){return this.insightsRegistry}async initialize(e){this.services.logger.debug("Shell.initialize() called");let t=e?.mode;if(this.lifecycleState==="running")return this.services.logger.warn("Shell already initialized"),Promise.resolve();if(this.lifecycleState==="booting"){if(this.bootMode!==t)return Promise.reject(Error(`Shell is already initializing in ${this.bootMode??"normal"} mode; cannot join ${t??"normal"} mode`));return this.bootPromise??Promise.resolve()}if(this.lifecycleState==="closing"||this.lifecycleState==="closed")return Promise.reject(Error("Cannot initialize a closing shell"));if(this.lifecycleState==="failed")return Promise.reject(Error("Cannot initialize a shell after boot failure"));return this.lifecycleState="booting",this.bootMode=t,this.bootPromise=this.boot(e),this.bootPromise}async boot(e){try{if(await this.bootloader.boot(e),this.lifecycleState==="booting"){if(this.lifecycleState="running",this.initialized=!0,e?.mode===void 0)await this.services.messageBus.send({type:zs.shellReady,payload:{timestamp:new Date().toISOString()},sender:"shell",broadcast:!0}),this.services.logger.debug("Emitted shell ready event")}}catch(t){if(this.initialized=!1,this.services.logger.error("Failed to initialize Shell",t),this.lifecycleState!=="closing")this.lifecycleState="failed";try{await this.lifecycle.close(tt.fail(t))}catch(n){this.services.logger.error("Failed to clean up Shell after initialization failure",n)}throw t}}registerTemplates(e,t){this.services.logger.debug("Registering templates",{pluginId:t,count:Object.keys(e).length});for(let[n,o]of Object.entries(e))this.registerTemplate(n,o,t)}shutdown(){return this.shutdownPromise??=this.shutdownShell(),this.shutdownPromise}async shutdownShell(){if(this.services.logger.debug("Shutting down Shell"),this.lifecycleState==="closed")return;let e=this.bootPromise;if(this.lifecycleState="closing",this.initialized=!1,e)try{await e}catch{}await this.lifecycle.close(),this.lifecycleState="closed",this.services.logger.debug("Shell shutdown complete")}async generateContent(e){return this.requireInitialized("Shell content generation"),Tp(this.services,e)}async query(e,t){this.requireInitialized("Shell query");let n=await this.getAppInfo(),o={...t,appInfo:n,timestamp:new Date().toISOString()},{conversationHistory:i,...a}=o;return IC.parse(await this.generateContent({prompt:e,templateName:Yo.KNOWLEDGE_QUERY,...i&&{conversationHistory:i},data:a,interfacePermissionGrant:"public"}))}registerPlugin(e){this.requireInitialized("Plugin registration"),this.services.pluginManager.registerPlugin(e)}isInitialized(){return this.initialized}requireInitialized(e){if(!this.initialized)throw Error(`${e} attempted before initialization`)}getEntityService(){return this.services.entityService}getConversationService(){return this.services.conversationService}getEntityRegistry(){return this.services.entityRegistry}async generateObject(e,t,n){this.requireInitialized("Shell generateObject");let{object:o}=await this.services.aiService.generateObject("You are a helpful assistant. Respond with the requested structured data.",e,t,n);return{object:o}}async judge(e){return this.requireInitialized("Shell judge"),this.services.aiService.judge(e)}getAIService(){return this.services.aiService}generateImage(e,t){return this.services.aiService.generateImage(e,t)}canGenerateImages(){return this.services.aiService.canGenerateImages()}getPluginManager(){return this.services.pluginManager}getContentService(){return this.services.contentService}getRenderService(){return this.services.renderService}getAttachmentRegistry(){return Ys(this.services.attachmentRegistry)}getRuntimeUploadRegistry(){return EC(this.services.runtimeUploadRegistry)}getRuntimeState(){return this.services.runtimeStateService}getRecurringChecks(e){return this.services.recurringCheckService.namespace(e)}isJobQueueWorkerRunning(){return this.services.jobQueueWorker.isWorkerRunning()}getMessageBus(){return this.services.messageBus}getLogger(){return this.services.logger}getJobQueueService(){return this.services.jobQueueService}getMCPService(){return this.services.mcpService}listToolsForPermissionLevel(e){return this.services.mcpService.listToolsForPermissionLevel(e).map(({pluginId:t,tool:n})=>({name:n.name,description:n.description,pluginId:t}))}getPermissionService(){return this.services.permissionService}getAgentService(){return this.services.agentService}registerTools(e,t){for(let n of t)try{this.services.mcpService.registerTool(e,n)}catch(o){this.services.logger.error(`Failed to register tool ${n.name} from ${e}:`,o)}}registerResources(e,t){for(let n of t)try{this.services.mcpService.registerResource(e,n)}catch(o){this.services.logger.error(`Failed to register resource ${n.name} from ${e}:`,o)}}registerResourceTemplate(e,t){this.services.mcpService.registerResourceTemplate(e,t)}registerPrompt(e,t){this.services.mcpService.registerPrompt(e,t)}registerInstructions(e,t){if(this.services.mcpService.registerInstructions(e,t),this.initialized)this.services.agentService.invalidateAgent()}async unregisterPluginCapabilities(e){this.services.mcpService.unregisterPlugin?.(e),this.services.jobQueueService.unregisterPluginHandlers(e),this.endpointRegistry.unregister(e),this.interactionRegistry.unregister(e);for(let n of this.services.templateRegistry.getNames())if(n.startsWith(`${e}:`))this.services.templateRegistry.unregister(n);let t=this.config.evalHandlerRegistry;if(t){for(let n of t.list())if(n.pluginId===e)t.unregister(e,n.handlerId)}this.services.agentService.invalidateAgent(),await this.services.recurringCheckService.unregisterPlugin(e)}getPluginPackageName(e){return this.services.pluginManager.getPluginPackageName(e)}hasPlugin(e){return this.services.pluginManager.hasPlugin(e)}getPluginHttpRouteManifest(){return this.httpRouteRegistry.getManifest()}getPluginApiRoutes(){return this.httpRouteRegistry.getApiRoutes()}getPluginWebRoutes(){return this.httpRouteRegistry.getWebRoutes()}registerDaemon(e,t,n){this.services.daemonRegistry.register(e,t,n)}registerEndpoint(e){this.endpointRegistry.register(e)}listEndpoints(){return this.endpointRegistry.list()}registerInteraction(e){this.interactionRegistry.register(e)}listInteractions(){return this.interactionRegistry.list()}registerTemplate(e,t,n){let o=n?`${n}:${e}`:`shell:${e}`;this.services.templateRegistry.register(o,t),this.services.logger.debug(`Registered template: ${o}`)}getTemplate(e){return this.services.templateRegistry.get(e)}getDataSourceRegistry(){return this.services.dataSourceRegistry}getIdentity(){return this.services.identityService.getCharacter()}getProfile(){return this.services.profileService.getProfile()}getProfileKindRegistry(){return this.services.profileKindRegistry}getChannelRegistry(){return this.services.channelRegistry}getInboxRegistry(){return this.services.inboxRegistry}getInboxFollowUpRegistry(){return this.services.inboxFollowUpRegistry}getOperationalHealthRegistry(){return this.services.operationalHealthRegistry}getAccountSettingsRegistry(){return this.services.accountSettingsRegistry}getDomain(){return this.config.siteBaseUrl}getLocalSiteUrl(){return this.config.localSiteUrl}shouldPreferLocalUrls(){return this.config.preferLocalUrls}getThemeCSS(){return this.config.themeCSS}getSpaces(){return this.config.spaces}getDataDir(){return this.config.dataDir}getGitBrokerSocket(){return this.config.gitBrokerSocket}getGitBrokerCheckout(){return this.config.gitBrokerCheckout}registerEvalHandler(e,t,n){this.config.evalHandlerRegistry?.register(e,t,n)}async getAppInfo(){return yp({config:this.config,services:this.services,bootTime:this.bootTime,endpoints:()=>this.listEndpoints(),interactions:()=>this.listInteractions()})}getRuntimeReadiness(){return _p(this.services)}}var AC={kind:"service",serviceId:"brain-cli"},lp=`${AC.kind}:${AC.serviceId}`;var dJ=r.object({provider:r.enum(["hetzner","docker"]).default("hetzner"),serverSize:r.string().default("cx33"),location:r.string().default("fsn1"),domain:r.string().optional(),docker:r.object({enabled:r.boolean().default(!0),image:r.string().optional()}).prefault({}),ports:r.object({default:r.number().default(3333),preview:r.number().default(4321),production:r.number().default(8080)}).prefault({}),cdn:r.object({enabled:r.boolean().default(!1),provider:r.enum(["bunny","none"]).default("none")}).prefault({}),dns:r.object({enabled:r.boolean().default(!1),provider:r.enum(["bunny","none"]).default("none")}).prefault({}),paths:r.object({install:r.string().optional(),data:r.string().optional()}).prefault({})}),MC=r.object({name:r.string().default("brain-app"),version:r.string().default("1.0.0"),database:r.string().optional(),aiApiKey:r.string().optional(),aiImageKey:r.string().optional(),aiModel:r.string().optional(),aiReasoningEffort:Xn.optional(),logLevel:Qn.optional(),logFile:r.string().optional(),profileKind:r.string().trim().min(1).optional(),plugins:r.array(da).default([]),spaces:r.array(r.string()).default([]),identity:PC.optional(),agentInstructions:r.array(r.string()).optional(),deployment:dJ.prefault({})});async function FC(e,t){await wn({label:"entity",config:e,schema:{assets:OC,entities:jC,projectionDirtyInputs:NC,projectionWaves:DC,projectionIncidents:zC,projectionWaveInputs:UC,projectionWaveRules:$C,projectionRuleMemos:qC},migrationsFolder:xn(import.meta.url,"entity-service"),authTokenEnv:"DATABASE_AUTH_TOKEN",logger:t,afterMigrate:LC})}async function JC(e,t){await wn({label:"job-queue",config:e,schema:{jobQueue:BC,jobWorkerSessions:GC},migrationsFolder:xn(import.meta.url,"job-queue"),authTokenEnv:"JOB_QUEUE_DATABASE_AUTH_TOKEN",logger:t})}async function ZC(e,t){await wn({label:"conversation",config:e,schema:{conversations:HC,messages:WC,summaryTracking:VC},migrationsFolder:xn(import.meta.url,"conversation-service"),authTokenEnv:"CONVERSATION_DATABASE_AUTH_TOKEN",logger:t})}async function KC(e,t){await wn({label:"runtime-state",config:e,schema:{runtimeStateRecords:Le},migrationsFolder:xn(import.meta.url,"runtime-state"),authTokenEnv:"RUNTIME_STATE_DATABASE_AUTH_TOKEN",logger:t})}import{mkdir as cp}from"fs/promises";import{isAbsolute as pJ}from"path";function YC(e=process.env){return{dataDir:e.XDG_DATA_HOME??"./data",cacheDir:e.XDG_CACHE_HOME??"./cache",distDir:"./dist"}}function QC(e=process.env){let t=e.BRAIN_GIT_BROKER_CHECKOUT;if(!t)return;if(!pJ(t))throw Error(`Git broker checkout path must be absolute: ${t}`);return t}function XC(e=process.env){let t=e.BRAIN_GIT_BROKER_SOCKET;if(!t)return;let n=107;if(Buffer.byteLength(t)>n)throw Error(`Git broker socket path is too long for a unix socket (${Buffer.byteLength(t)} > ${n} bytes): ${t}`);return t}function e0(e=process.env){return Cn(YC(e))}async function t0(e=process.env){let t=YC(e);try{await cp(t.dataDir,{recursive:!0}),await cp(t.cacheDir,{recursive:!0}),await cp(t.distDir,{recursive:!0})}catch(n){let o=n instanceof Error&&n.message.includes("EACCES")?`Cannot create data directories \u2014 permission denied. Run from a writable directory or check permissions on ${t.dataDir}`:`Cannot create data directories: ${ke(n)}`;throw Error(o,{cause:n})}return Cn(t)}class up{logger;migrations;constructor(e,t){this.logger=e,this.migrations=t??{getStandardConfigWithDirectories:()=>t0(),migrateEntities:FC,migrateJobQueue:JC,migrateConversations:ZC,migrateRuntimeState:KC}}async runAllMigrations(e){this.logger.debug("Running database migrations...");let t=await this.migrations.getStandardConfigWithDirectories();if(e?.database)t.database.url=e.database;if(e?.jobQueueDatabase)t.jobQueueDatabase.url=e.jobQueueDatabase;if(e?.conversationDatabase)t.conversationDatabase.url=e.conversationDatabase;if(e?.runtimeStateDatabase)t.runtimeStateDatabase.url=e.runtimeStateDatabase;await this.migrateEntityDatabase(t),await this.migrateJobQueueDatabase(t),await this.migrateConversationDatabase(t),await this.migrateRuntimeStateDatabase(t),this.logger.debug("All database migrations completed successfully")}async migrateEntityDatabase(e){this.logger.debug("Running entity database migrations..."),await this.migrations.migrateEntities({url:e.database.url,...e.database.authToken&&{authToken:e.database.authToken}},this.logger)}async migrateJobQueueDatabase(e){this.logger.debug("Running job queue database migrations..."),await this.migrations.migrateJobQueue({url:e.jobQueueDatabase.url,...e.jobQueueDatabase.authToken&&{authToken:e.jobQueueDatabase.authToken}},this.logger)}async migrateConversationDatabase(e){this.logger.debug("Running conversation database migrations..."),await this.migrations.migrateConversations({url:e.conversationDatabase.url,...e.conversationDatabase.authToken&&{authToken:e.conversationDatabase.authToken}},this.logger)}async migrateRuntimeStateDatabase(e){this.logger.debug("Running runtime state database migrations..."),await this.migrations.migrateRuntimeState({url:e.runtimeStateDatabase.url,...e.runtimeStateDatabase.authToken&&{authToken:e.runtimeStateDatabase.authToken}},this.logger)}}var mJ="NODE_ENV";function gJ(){return process.env[mJ]}function r0(){return gJ()!=="production"}var fJ="startup-check";function hJ(e){let n={...MC.parse(e??{}),plugins:e?.plugins??[]};if(e?.permissions)n.permissions=e.permissions;if(e?.spaces)n.spaces=e.spaces;if(e?.cliConfig)n.cliConfig=e.cliConfig;if(e?.shellConfig)n.shellConfig=e.shellConfig;return n}function yJ(e,t){let n={plugins:e.plugins??[],...e.shellConfig};return vJ(n),bJ(e,n),_J(e,n,t),SJ(e,n),wJ(e,n),xJ(e,n),TJ(e,n),IJ(e,n),CJ(e,n),n}function vJ(e){let t=e0();e.database??=t.database,e.jobQueueDatabase??=t.jobQueueDatabase,e.conversationDatabase??=t.conversationDatabase,e.runtimeStateDatabase??=t.runtimeStateDatabase,e.embeddingDatabase??=t.embeddingDatabase,e.embedding??=t.embedding,e.gitBrokerSocket??=XC(),e.gitBrokerCheckout??=QC()}function bJ(e,t){if(e.database)t.database={url:e.database};if(e.profileKind)t.profileKind=e.profileKind;t.features={}}function _J(e,t,n){let o=n?.mode==="startup-check";if(!e.aiApiKey&&!e.aiImageKey&&!e.aiModel&&!e.aiReasoningEffort&&!o)return;t.ai={...t.ai,...o&&!t.ai?.apiKey&&{apiKey:fJ},...e.aiApiKey&&{apiKey:e.aiApiKey},...e.aiImageKey&&{imageApiKey:e.aiImageKey},...e.aiModel&&{model:e.aiModel},...e.aiReasoningEffort&&{reasoningEffort:e.aiReasoningEffort}}}function SJ(e,t){if(!e.logLevel&&!e.logFile)return;t.logging={level:e.logLevel??"info",format:"text",context:e.name,...e.logFile&&{file:e.logFile}}}function wJ(e,t){let n=e.permissions?.rules??[];t.permissions={...e.permissions,rules:n.some((o)=>o.pattern===lp)?n:[{pattern:lp,level:"admin"},...n]}}function xJ(e,t){if(e.spaces)t.spaces=e.spaces}function TJ(e,t){if(e.identity)t.identity=e.identity}function IJ(e,t){if(e.agentInstructions)t.agentInstructions=e.agentInstructions}function CJ(e,t){if(t.name=e.name,t.version=e.version,e.deployment.domain)t.siteBaseUrl=e.deployment.domain;t.localSiteUrl=`http://localhost:${e.deployment.ports.production}`,t.preferLocalUrls=r0()}class pp{shell=null;config;signalScope=null;signalShutdownFiber=null;stopPromise=null;hasCLI=!1;static create(e,t){return new pp(hJ(e),t)}constructor(e,t){if(this.config=e,this.hasCLI=process.argv.slice(2).includes("--cli"),t)this.shell=t}async migrate(){let e=vr.getInstance();await new up(e).runAllMigrations({database:this.config.shellConfig?.database?.url??this.config.database,jobQueueDatabase:this.config.shellConfig?.jobQueueDatabase?.url,conversationDatabase:this.config.shellConfig?.conversationDatabase?.url,runtimeStateDatabase:this.config.shellConfig?.runtimeStateDatabase?.url})}createShell(e,t){this.shell=ia.createFresh(yJ(this.config,e),void 0,{...t&&{processRole:t}})}async registerCLIInterface(){if(!this.hasCLI)return;let e=this.getShell().getPluginManager(),{CLIInterface:t}=await import("./index-7m2gbgs2.js"),n=new t(this.config.cliConfig);e.registerPlugin(n)}async initialize(e,t){if(!this.shell){if(!t?.migrationsCompleted)await this.migrate();this.createShell(e,t?.processRole)}await this.registerCLIInterface(),await this.getShell().initialize(e)}async start(){if(this.stopPromise)return;this.setupSignalHandlers()}stop(){return this.stopPromise??=this.stopApp(),this.stopPromise}async stopApp(){await this.closeSignalScope(),await this.shell?.shutdown()}async run(e){let n={debug:Ut.DEBUG,info:Ut.INFO,warn:Ut.WARN,error:Ut.ERROR}[this.config.logLevel??"info"]??Ut.INFO,o=vr.createFresh({level:n,context:this.config.name,useStderr:this.hasCLI});if(this.hasCLI)vr.getInstance().setUseStderr(!0);try{await this.initialize(void 0,e),await this.start(),e?.onRuntimeReady?.(),o.info(`\u2705 ${this.config.name} v${this.config.version} ready`),process.stdin.resume()}catch(i){o.error(`\u274C Failed to start ${this.config.name}:`,i),process.exit(1)}}static async run(e,t,n){await pp.create(e,t).run(n)}setupSignalHandlers(){if(this.signalScope)return;let e=de.runSync(Xe.make()),t=()=>{this.requestGracefulShutdown("SIGINT")},n=()=>{this.requestGracefulShutdown("SIGTERM")},o=dp(["SIGINT"],t),i=dp(["SIGTERM"],n);de.runSync(Xe.addFinalizer(e,de.sync(()=>{i(),o()}))),this.signalScope=e}requestGracefulShutdown(e){if(this.signalShutdownFiber)return;let t=vr.getInstance();t.info(`
|
|
178
178
|
Received ${e}, shutting down gracefully...`);let n=de.tryPromise({try:()=>this.stop(),catch:(o)=>o}).pipe(de.match({onFailure:(o)=>{t.error("Error during shutdown:",o),process.exit(1)},onSuccess:()=>{process.exit(0)}}));this.signalShutdownFiber=de.runFork(n)}async closeSignalScope(){let e=this.signalScope;if(this.signalScope=null,e)await de.runPromise(Xe.close(e,tt.void))}getShell(){if(!this.shell)throw Error("Shell not initialized. Call initialize() first.");return this.shell}}
|
|
179
179
|
export{Qn as S,Xn as T,Xj as U,g6 as V,ce as W,na as X,$I as Y,FI as Z,Hs as _,BG as $,tp as aa,JG as ba,Ws as ca,HG as da,Tte as ea,KI as fa,ZG as ga,np as ha,op as ia,KG as ja,QG as ka,fJ as la,hJ as ma,yJ as na,pp as oa};
|
|
180
180
|
|
|
181
181
|
//# debugId=F56B6C1425D40A6C64756E2164756E21
|
|
182
|
-
//# sourceMappingURL=index-
|
|
182
|
+
//# sourceMappingURL=index-7ahrzv8v.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{a as z,b as f}from"./index-2tfcnwn3.js";import{d as c,e as l}from"./index-xzmdq8zk.js";import{sa as D}from"./index-48ksf4j5.js";import{Ah as M,Hg as I,Ig as A,Jg as P,Kg as T,Lg as R,Mg as S,Pg as L,Wg as w,ih as B,kg as x}from"./index-ktmedhab.js";import"./index-w6648sqh.js";import"./index-3w748142.js";import{Yh as d,bj as k}from"./index-0czhapph.js";import{kk as h}from"./index-6246jggs.js";var m=d.object({theme:d.object({primaryColor:d.string().describe("Primary color for the CLI theme").default("#0066cc"),accentColor:d.string().describe("Accent color for the CLI theme").default("#ff6600")}).describe("Theme configuration for the CLI interface").default({primaryColor:"#0066cc",accentColor:"#ff6600"})});var y={name:"@brains/chat-repl",license:"AGPL-3.0-only",version:"0.2.0-alpha.
|
|
2
|
+
import{a as z,b as f}from"./index-2tfcnwn3.js";import{d as c,e as l}from"./index-xzmdq8zk.js";import{sa as D}from"./index-48ksf4j5.js";import{Ah as M,Hg as I,Ig as A,Jg as P,Kg as T,Lg as R,Mg as S,Pg as L,Wg as w,ih as B,kg as x}from"./index-ktmedhab.js";import"./index-w6648sqh.js";import"./index-3w748142.js";import{Yh as d,bj as k}from"./index-0czhapph.js";import{kk as h}from"./index-6246jggs.js";var m=d.object({theme:d.object({primaryColor:d.string().describe("Primary color for the CLI theme").default("#0066cc"),accentColor:d.string().describe("Accent color for the CLI theme").default("#ff6600")}).describe("Theme configuration for the CLI interface").default({primaryColor:"#0066cc",accentColor:"#ff6600"})});var y={name:"@brains/chat-repl",license:"AGPL-3.0-only",version:"0.2.0-alpha.448",dependencies:{"@brains/job-queue":"workspace:*","@brains/plugins":"workspace:*","@brains/utils":"workspace:*",chalk:"^5.4.1",ink:"^7.0.6","ink-spinner":"^5.0.0","ink-text-input":"^6.0.0",marked:"^18.0.5",react:"^19.2.7"},devDependencies:{"@brains/eslint-config":"workspace:*","@brains/typescript-config":"workspace:*","@types/bun":"^1.4.0","@types/react":"^19.2.17",typescript:"^7.0.2"},files:["src"],main:"./src/index.ts",module:"./src/index.ts",private:!0,scripts:{dev:"tsc --watch",lint:"eslint . --max-warnings 0","lint:fix":"eslint . --max-warnings 0 --fix",test:"bun test",typecheck:"tsc --noEmit"},type:"module",types:"./src/index.ts"};var j={completed:"\u2713",declined:"\u25CB",failed:"\u2717"},Z={deniedCardIds:void 0,resolveUrl:(e)=>e,isHiddenUrl:()=>!1,eventActionUnavailableLabel:void 0};class E extends x{inkApp=null;responseCallback;systemMessageCallback;agentService;removeSignalHandlers;approvalTracker;constructor(e={}){super("cli",y,e,m)}getAgentService(){if(!this.agentService)throw Error("AgentService not initialized - plugin not registered");return this.agentService}async onRegister(e){await super.onRegister(e),this.agentService=e.agent,this.logger.debug("CLI interface registered with AgentService")}sendMessageToChannel({message:e}){let s=typeof e==="string"?e:e.fallbackText??"";if(!s)return;(this.systemMessageCallback??this.responseCallback)?.(s)}sendReply(e){this.responseCallback?.(e)}registerResponseCallback(e){this.responseCallback=e}registerSystemMessageCallback(e){this.systemMessageCallback=e}unregisterMessageCallbacks(){this.responseCallback=void 0,this.systemMessageCallback=void 0}async onProgressUpdate(e){this.logger.debug("CLI progress update",{eventId:e.id,status:e.status,progress:e.progress,message:e.message})}createDaemon(){return{start:async()=>{if(!this.context)throw new M(this.id,"Initialization failed: Plugin context not initialized");this.logger.debug("Starting CLI interface");try{let[e,s,n]=await Promise.all([import("./index-r1sb37dh.js"),import("react"),import("./EnhancedApp-39bbpp1n.js")]),{render:r}=e,t=s.default,o=n.default,g=t.createElement(o,{interface:this,registerProgressCallback:(i)=>this.registerProgressCallback(i),unregisterProgressCallback:()=>this.unregisterProgressCallback(),registerResponseCallback:(i)=>this.registerResponseCallback(i),registerSystemMessageCallback:(i)=>this.registerSystemMessageCallback(i),unregisterMessageCallbacks:()=>this.unregisterMessageCallbacks()});this.inkApp=r(g),this.registerSignalHandlers()}catch(e){throw this.logger.error("Failed to start CLI interface",{error:e}),e}},stop:async()=>{this.logger.debug("Stopping CLI interface"),await this.cleanup()},healthCheck:async()=>{let e=this.inkApp!==null;return{status:e?"healthy":"error",message:e?"CLI interface is running":"CLI interface not running",lastCheck:new Date,details:{hasInkApp:this.inkApp!==null,hasCallbacks:this.hasProgressCallback()}}}}}getApprovalTracker(){return this.approvalTracker??=new L({loadMessages:async(e)=>await this.context?.conversations.getMessages(e,{limit:50})??[],onRestoreError:(e,s)=>{this.logger.debug("Failed to restore pending CLI approvals",{error:e,conversationId:s})}}),this.approvalTracker}async getPendingApprovalIds(e){return[...await this.getApprovalTracker().getApprovalIds(e)]}async processInput(e){this.startProcessingInput();try{let n=await this.getPendingApprovalIds("cli");if(n.length>0){if(await this.handleConfirmationResponse(e,"cli",n))return}let r=await this.getAgentService().chat(e,"cli",{userPermissionLevel:"admin",isAnchor:this.getContext().permissions.isAnchor("cli","local"),interfaceType:"cli",channelId:"cli",channelName:"CLI Terminal"}),t=I(r.cards),o=t.length>0?t.map((i)=>i.id):r.pendingConfirmations?.map((i)=>i.id)??[];this.getApprovalTracker().replaceApprovals("cli",o);let g=this.renderAgentResponse(r);this.logger.debug("Agent response received",{textLength:r.text.length,toolResultsCount:r.toolResults?.length??0,toolResults:r.toolResults?.map((i)=>({toolName:i.toolName,hasData:i.data!==void 0}))}),this.sendReply(g)}catch(n){this.logger.error("Error processing input",{error:n,input:e});let r=k(n,"An unknown error occurred");this.sendReply(`**Error:** ${r}`)}finally{this.endProcessingInput()}}renderAgentResponse(e){let s=w(e,{deniedCardIds:void 0}),n=[],r=[],t="";for(let o of s.directives)switch(o.kind){case"text":t=o.text;break;case"approvals":n.push(...o.cards);break;default:if(o.card.kind==="tool-approval"&&o.card.state==="approval-requested"){n.push(o.card);break}r.push(B(o.card,Z))}return[this.formatAgentResponseText(t,n),...r].filter((o)=>o.trim().length>0).join(`
|
|
3
3
|
|
|
4
4
|
`)}formatAgentResponseText(e,s){if(s.length===0)return e;let n=P(e,s);if(s.length===1){let t=s[0];if(!t)return e;let o=t.preview?`
|
|
5
5
|
|
|
@@ -15,5 +15,5 @@ _Please reply with **yes 1** / **no 1** for the matching action._`}formatApprova
|
|
|
15
15
|
|
|
16
16
|
${r.error}`:`${t} ${r.summary}`}resolveApprovalIndexSugar(e,s){let n=/^(.*?)\s+#?(\d+)$/.exec(e.trim());if(!n?.[1]||!n[2])return e;let r=s[Number(n[2])-1];return r?`${n[1]} ${r}`:e}async handleConfirmationResponse(e,s,n){let r=new Set(n);if(!S(e,r))return!1;let t=R({message:this.resolveApprovalIndexSugar(e,n),approvalIds:r});if(t.kind==="not-confirmation")return!1;if(t.kind==="notice")return this.sendReply(`_${t.message}_`),!0;this.getApprovalTracker().removeApproval(s,t.approvalId);let o=await this.getAgentService().confirmPendingAction(s,t.confirmed,t.approvalId,{userPermissionLevel:"admin",isAnchor:this.getContext().permissions.isAnchor("cli","local"),interfaceType:"cli"});return this.getApprovalTracker().syncFromResponse(s,o,t.approvalId),this.sendReply(this.formatApprovalResultText(o.text,o.cards)),!0}registerSignalHandlers(){let e=()=>{this.logger.debug("Received termination signal, stopping CLI"),this.cleanup()};this.removeSignalHandlers=D(["SIGINT","SIGTERM"],e)}async cleanup(){if(this.unregisterProgressCallback(),this.unregisterMessageCallbacks(),this.removeSignalHandlers?.(),this.removeSignalHandlers=void 0,this.inkApp)this.inkApp.unmount(),this.inkApp=null}}import{jsx as a,jsxs as p}from"react/jsx-runtime";function q({batchStatus:e,showDetails:s=!0}){let{batchId:n,totalOperations:r,completedOperations:t,failedOperations:o,currentOperation:g,errors:i,status:u}=e,O=u==="processing",v=u==="completed",C=u==="failed",b=t-o;return p(c,{flexDirection:"column",marginY:1,children:[a(c,{marginBottom:1,children:p(l,{bold:!0,color:"cyan",children:["Batch Operation: ",n.slice(0,8),"..."]})}),a(c,{marginBottom:1,children:a(f,{current:t,total:r,message:"Overall Progress:",color:C?"red":v?"green":"yellow"})}),O&&g&&p(c,{marginBottom:1,children:[a(l,{color:"green",children:a(z,{type:"dots"})}),p(l,{color:"gray",children:[" ",g]})]}),s&&p(c,{flexDirection:"column",marginLeft:2,children:[b>0&&p(c,{children:[a(l,{color:"green",children:"\u2713 "}),p(l,{color:"gray",children:[b," successful"]})]}),o>0&&p(c,{children:[a(l,{color:"red",children:"\u2717 "}),p(l,{color:"gray",children:[o," failed"]})]}),i.length>0&&p(c,{flexDirection:"column",marginTop:1,children:[a(l,{color:"red",bold:!0,children:"Errors:"}),i.slice(0,3).map((H,_)=>p(c,{marginLeft:2,children:[a(l,{color:"red",children:"\u2022 "}),a(l,{color:"gray",children:H})]},_)),i.length>3&&a(c,{marginLeft:2,children:p(l,{color:"gray",children:["... and ",i.length-3," more"]})})]})]}),v&&a(c,{marginTop:1,children:a(l,{color:"green",bold:!0,children:"\u2713 Batch completed successfully"})}),C&&a(c,{marginTop:1,children:a(l,{color:"red",bold:!0,children:"\u2717 Batch failed"})})]})}export{q as BatchProgress,E as CLIInterface,f as ProgressBar,m as cliConfigSchema};
|
|
17
17
|
|
|
18
|
-
//# debugId=
|
|
19
|
-
//# sourceMappingURL=index-
|
|
18
|
+
//# debugId=9EB67670F967E44364756E2164756E21
|
|
19
|
+
//# sourceMappingURL=index-7m2gbgs2.js.map
|
|
@@ -7,6 +7,6 @@
|
|
|
7
7
|
"/** @jsxImportSource react */\nimport React from \"react\";\nimport { Box, Text } from \"ink\";\nimport Spinner from \"ink-spinner\";\nimport type { BatchJobStatus } from \"@brains/job-queue\";\nimport { ProgressBar } from \"./ProgressBar\";\n\ninterface BatchProgressProps {\n batchStatus: BatchJobStatus;\n showDetails?: boolean;\n}\n\nexport function BatchProgress({\n batchStatus,\n showDetails = true,\n}: BatchProgressProps): React.ReactElement {\n const {\n batchId,\n totalOperations,\n completedOperations,\n failedOperations,\n currentOperation,\n errors,\n status,\n } = batchStatus;\n\n const inProgress = status === \"processing\";\n const isCompleted = status === \"completed\";\n const isFailed = status === \"failed\";\n\n // Calculate successful operations\n const successfulOperations = completedOperations - failedOperations;\n\n return (\n <Box flexDirection=\"column\" marginY={1}>\n {/* Header */}\n <Box marginBottom={1}>\n <Text bold color=\"cyan\">\n Batch Operation: {batchId.slice(0, 8)}...\n </Text>\n </Box>\n\n {/* Main progress bar */}\n <Box marginBottom={1}>\n <ProgressBar\n current={completedOperations}\n total={totalOperations}\n message=\"Overall Progress:\"\n color={isFailed ? \"red\" : isCompleted ? \"green\" : \"yellow\"}\n />\n </Box>\n\n {/* Current operation */}\n {inProgress && currentOperation && (\n <Box marginBottom={1}>\n <Text color=\"green\">\n <Spinner type=\"dots\" />\n </Text>\n <Text color=\"gray\"> {currentOperation}</Text>\n </Box>\n )}\n\n {/* Details section */}\n {showDetails && (\n <Box flexDirection=\"column\" marginLeft={2}>\n {/* Success count */}\n {successfulOperations > 0 && (\n <Box>\n <Text color=\"green\">✓ </Text>\n <Text color=\"gray\">{successfulOperations} successful</Text>\n </Box>\n )}\n\n {/* Failure count */}\n {failedOperations > 0 && (\n <Box>\n <Text color=\"red\">✗ </Text>\n <Text color=\"gray\">{failedOperations} failed</Text>\n </Box>\n )}\n\n {/* Errors */}\n {errors.length > 0 && (\n <Box flexDirection=\"column\" marginTop={1}>\n <Text color=\"red\" bold>\n Errors:\n </Text>\n {errors.slice(0, 3).map((error, index) => (\n <Box key={index} marginLeft={2}>\n <Text color=\"red\">• </Text>\n <Text color=\"gray\">{error}</Text>\n </Box>\n ))}\n {errors.length > 3 && (\n <Box marginLeft={2}>\n <Text color=\"gray\">... and {errors.length - 3} more</Text>\n </Box>\n )}\n </Box>\n )}\n </Box>\n )}\n\n {/* Final status */}\n {isCompleted && (\n <Box marginTop={1}>\n <Text color=\"green\" bold>\n ✓ Batch completed successfully\n </Text>\n </Box>\n )}\n\n {isFailed && (\n <Box marginTop={1}>\n <Text color=\"red\" bold>\n ✗ Batch failed\n </Text>\n </Box>\n )}\n </Box>\n );\n}\n"
|
|
8
8
|
],
|
|
9
9
|
"mappings": ";kZAcO,IAAM,EAAmC,EAAE,OAAO,CACvD,MAAO,EACJ,OAAO,CACN,aAAc,EACX,OAAO,EACP,SAAS,iCAAiC,EAC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CAFA,EAAsB,EAAtB,CAAM,MAAM,MAAZ,mBAAsB,EACtB,EAA4B,EAA5B,CAAM,MAAM,OAAZ,SAAoB,EAAQ,IAFpB,CAGR,CACH,EACA,EAAO,OAAS,GACf,EAEE,EAFF,CAAK,WAAY,EAAjB,SACE,EAAqD,EAArD,CAAM,MAAM,OAAZ,SAAqD,CAArD,WAA4B,EAAO,OAAS,EAA5C,SAAqD,EACrD,GAEJ,GAEJ,EAIH,GACC,EAIE,EAJF,CAAK,UAAW,EAAhB,SACE,EAEE,EAFF,CAAM,MAAM,QAAQ,KAAI,GAAxB,+CAEE,EACF,EAGH,GACC,EAIE,EAJF,CAAK,UAAW,EAAhB,SACE,EAEE,EAFF,CAAM,MAAM,MAAM,KAAI,GAAtB,+BAEE,EACF,GAEJ",
|
|
10
|
-
"debugId": "
|
|
10
|
+
"debugId": "9EB67670F967E44364756E2164756E21",
|
|
11
11
|
"names": []
|
|
12
12
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{S as c,T as y}from"./index-
|
|
2
|
+
import{S as c,T as y}from"./index-7ahrzv8v.js";import{Ed as R,Fd as z,Kf as a}from"./index-ktmedhab.js";import{Dh as i}from"./index-w6648sqh.js";import{$j as C,Yh as e,Zj as l,_j as h}from"./index-0czhapph.js";function _(t,n={}){if(!a(t))throw Error("use() expects a package definition returned by a @rizom/brain define helper");return Object.freeze({kind:"rizom-configured-plugin",definition:t,config:Object.freeze({...n})})}function O(t){if(t===null||typeof t!=="object")return!1;return Reflect.get(t,"kind")==="rizom-configured-plugin"&&a(Reflect.get(t,"definition"))&&typeof Reflect.get(t,"config")==="object"}var Ee=e.array(e.string()),Ie=e.record(e.string(),e.unknown()),Ae=e.unknown();var Be=e.enum(["eval"]),p=e.enum(["person","team","organization"]);function K(t){if(t.bundleContract?.trim().length===0)throw Error("Brain bundleContract must not be empty");return t}function f(t){if(Array.isArray(t))return t.map((n)=>f(n));if(i(t))return Object.fromEntries(Object.entries(t).map(([n,o])=>[n,f(o)]));return t}function u(t){return f(t)}var r=e.string().min(1),V=e.strictObject({member:r,value:e.record(e.string(),e.unknown()),overrides:r.optional()}),G=e.custom(i,{message:"Expected an opaque permission config object"}),q=e.strictObject({member:r,config:G,overrides:r.optional()}),U=e.strictObject({id:r,members:e.array(r),config:e.array(V).optional(),permissions:e.array(q).optional(),agentInstructions:e.array(e.string().min(1)).optional(),evalDisable:e.array(r).optional()});function E(t,n,o,Z){let w=new Set;for(let[j,g]of t.entries()){if(w.has(g))Z.addIssue({code:e.ZodIssueCode.custom,message:`Duplicate ${n} "${g}"`,path:[o,j]});w.add(g)}}var H=U.superRefine((t,n)=>{E(t.members,"member","members",n),E(t.evalDisable??[],"eval exclusion","evalDisable",n)});function I(t){return u(H.parse(t))}function J(t){if(t===void 0)return[];return Array.isArray(t)?t:[t]}var W=e.record(e.string(),e.unknown()),ut=e.record(e.string(),e.unknown()),Y=e.enum(["eval"]),Q=l,s=h,X=e.strictObject({create:s.optional(),update:s.optional(),delete:s.optional(),extract:s.optional(),publish:s.optional()}),ee=e.record(e.string(),X),A=W.superRefine((t,n)=>{if(typeof t.package!=="string")return;n.addIssue({code:"custom",message:'"package" uses the removed alpha external-plugin contract. Default-export a declarative package definition from a @rizom/brain define helper and compose it with use() in defineBrain().'})}),mt=e.strictObject({brain:e.string().optional(),bundleContract:e.string().trim().min(1).optional(),anchor:p.optional(),site:e.object({package:e.string().optional(),variant:e.string().optional(),theme:e.string().optional(),themeOverride:e.string().optional()}).optional(),name:e.string().optional(),kind:e.string().trim().min(1).optional(),logLevel:c.optional(),logFile:e.string().optional(),port:e.number().optional(),domain:e.string().optional(),database:e.string().optional(),embedding:e.strictObject({enabled:e.boolean().optional()}).optional(),model:e.string().optional(),reasoningEffort:y.optional(),bundles:e.array(e.string().min(1)).optional(),mode:Y.optional(),add:e.array(e.string()).optional(),remove:e.array(e.string()).optional(),admins:e.array(e.string()).optional(),anchors:e.array(e.string()).optional(),trusted:e.array(e.string()).optional(),spaces:e.array(e.string()).optional(),plugins:e.record(e.string(),A).optional(),permissions:e.object({admins:e.array(e.string()).optional(),anchors:e.array(e.string()).optional(),trusted:e.array(e.string()).optional(),rules:e.array(e.object({pattern:e.string(),level:Q})).optional(),entityActions:ee.optional()}).optional()});var Pt=e.record(e.string(),e.unknown());var ne=e.strictObject({pattern:e.string(),level:l}),Et=e.strictObject({admins:e.array(e.string()).optional(),anchors:e.array(e.string()).optional(),trusted:e.array(e.string()).optional(),rules:e.array(ne).optional(),entityActions:C.optional()});var D=`/* ============================================
|
|
3
3
|
THEME BASE - Shared utilities for all themes
|
|
4
4
|
============================================
|
|
5
5
|
This file contains CSS that is IDENTICAL across all themes.
|
|
@@ -528,4 +528,4 @@ import{S as c,T as y}from"./index-jggg6k00.js";import{Ed as R,Fd as z,Kf as a}fr
|
|
|
528
528
|
`+t}var B=e.custom((t)=>z.safeParse(t).success),se=e.custom((t)=>{if(!i(t))return!1;let{plugin:n,...o}=t;if(n!==void 0&&typeof n!=="function")return!1;return R.safeParse(o).success});var ce=e.looseObject({id:e.string().min(1)}),de=e.looseObject({label:e.string().min(1)}),ge=e.custom((t)=>typeof t==="function"),pe=e.looseObject({layouts:e.record(e.string(),e.unknown()).optional(),plugin:ge.optional(),pluginConfig:e.record(e.string(),e.unknown()).optional(),routes:e.array(ce).optional(),entityDisplay:e.record(e.string(),de).optional(),content:e.unknown().optional(),themeOverride:e.string().optional(),headScripts:e.array(e.string()).optional(),staticAssets:e.record(e.string(),e.string()).optional()}),Ut=e.custom((t)=>pe.safeParse(t).success);var In=e.looseObject({name:e.string().min(1),version:e.string().min(1),dependencies:e.record(e.string(),e.string()).optional(),peerDependencies:e.record(e.string(),e.string()).optional()});export{_ as M,O as N,K as O,I as P,J as Q,re as R};
|
|
529
529
|
|
|
530
530
|
//# debugId=670EB5A907AEAADD64756E2164756E21
|
|
531
|
-
//# sourceMappingURL=index-
|
|
531
|
+
//# sourceMappingURL=index-x59am2rx.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{M as d,N as t}from"./chunks/index-
|
|
2
|
+
import{M as d,N as t}from"./chunks/index-x59am2rx.js";import"./chunks/index-7ahrzv8v.js";import"./chunks/index-dheher8v.js";import"./chunks/index-48ksf4j5.js";import{Jf as a}from"./chunks/index-ktmedhab.js";import"./chunks/index-w6648sqh.js";import"./chunks/index-3w748142.js";import"./chunks/index-0czhapph.js";import"./chunks/index-6246jggs.js";function s(e,i){let o=new Set,n=new Set;for(let r of e){if(!t(r))throw Error(`${i} contains a value that was not returned by use()`);if(o.has(r.definition))throw Error(`${i} contains duplicate plugin definition "${r.definition.id}"; include each configured definition only once`);if(n.has(r.definition.id))throw Error(`${i} contains duplicate local plugin id "${r.definition.id}"; give each package definition a unique local id before composing it`);o.add(r.definition),n.add(r.definition.id)}}function l(e){a(e.id,"Bundle id"),s(e.members,`Bundle "${e.id}"`);for(let i of e.config??[])if(!t(i.member))throw Error(`Bundle "${e.id}" config contains a value that was not returned by use()`);for(let i of e.permissions??[])if(!t(i.member))throw Error(`Bundle "${e.id}" permissions contains a value that was not returned by use()`);for(let i of e.evalDisable??[])if(!t(i))throw Error(`Bundle "${e.id}" evalDisable contains a value that was not returned by use()`);return Object.freeze({...e,members:Object.freeze([...e.members]),...e.config?{config:Object.freeze([...e.config])}:{},...e.permissions?{permissions:Object.freeze([...e.permissions])}:{},...e.agentInstructions?{agentInstructions:Object.freeze([...e.agentInstructions])}:{},...e.evalDisable?{evalDisable:Object.freeze([...e.evalDisable])}:{}})}function u(e){if(!e.name.trim())throw Error("Brain name must not be empty");if(e.bundleContract?.trim().length===0)throw Error("Brain bundleContract must not be empty");s(e.plugins,`Brain "${e.name}"`);let i=new Set(e.plugins),o=new Set;for(let n of e.bundles??[]){if(o.has(n.id))throw Error(`Brain "${e.name}" has duplicate bundle "${n.id}"`);o.add(n.id);for(let r of n.members)if(!i.has(r))throw Error(`Brain "${e.name}" bundle "${n.id}" references a plugin outside its catalog`);for(let r of n.config??[])if(!i.has(r.member))throw Error(`Brain "${e.name}" bundle "${n.id}" config references a plugin outside its catalog`);for(let r of n.permissions??[])if(!i.has(r.member))throw Error(`Brain "${e.name}" bundle "${n.id}" permissions reference a plugin outside its catalog`);for(let r of n.evalDisable??[])if(!i.has(r))throw Error(`Brain "${e.name}" bundle "${n.id}" evalDisable references a plugin outside its catalog`)}for(let n of e.evalDisable??[])if(!i.has(n))throw Error(`Brain "${e.name}" evalDisable references a plugin outside its catalog`);return Object.freeze({...e,plugins:Object.freeze([...e.plugins]),...e.bundles?{bundles:Object.freeze([...e.bundles])}:{},...e.agentInstructions?{agentInstructions:Object.freeze([...e.agentInstructions])}:{},...e.evalDisable?{evalDisable:Object.freeze([...e.evalDisable])}:{}})}export{u as defineBrain,l as defineBundle,d as use};
|
|
3
3
|
|
|
4
4
|
//# debugId=A5E1772512D3D25C64756E2164756E21
|
|
5
5
|
//# sourceMappingURL=index.js.map
|