@chatpanel/gateway 0.161.0 → 0.162.0
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/package.json +2 -2
- package/src/contexts-api.js +1 -1
- package/src/version.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatpanel/gateway",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.162.0",
|
|
4
4
|
"description": "Local privacy gateway — redacts PII out of OpenAI/Anthropic API traffic before it reaches a model, then restores it in the reply. Point opencode, codex, aider, Claude Code, etc. at it.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@anthropic-ai/sandbox-runtime": "^0.0.77",
|
|
26
26
|
"@chatpanel/bridge": "^0.52.0",
|
|
27
|
-
"@chatpanel/events": "^0.
|
|
27
|
+
"@chatpanel/events": "^0.511.0",
|
|
28
28
|
"@chatpanel/pii": "^0.15.6",
|
|
29
29
|
"@huggingface/transformers": "^4.2.0",
|
|
30
30
|
"defuddle": "^0.19.4",
|
package/src/contexts-api.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{makeContext as
|
|
1
|
+
import{makeContext as W,editContext as j,addToContext as K,removeFromContext as Z,contextIndex as D,contextMembers as _,suggestContexts as H,contextScope as Q,addRefs as V,removeRefs as Y,setPeople as p,parseRef as U,CONTEXT_COLORS as J,CONTEXT_NO_ACCESS as X,CONTEXT_ROLES as G,MAX_CONTEXT_INSTRUCTIONS as L}from"@chatpanel/events/contexts.js";import{contextAllows as q,contextFor as tt}from"@chatpanel/events/context-access.js";import{contextsForTurn as et,contextTurn as nt}from"@chatpanel/events/context-turn.js";import{toSearchRecord as ot}from"@chatpanel/events/library.js";import{randomUUID as rt}from"node:crypto";const z=/^context:[A-Za-z0-9_-]{1,80}$/,B=/^(chat|note|meeting|brief):[^\s]{1,200}$/,x=Object.freeze({kind:"owner"});class $ extends Error{constructor(c,h){super(h),this.status=c}}function lt({store:r,notify:c=()=>{},host:h="gateway",now:i=()=>Date.now(),newId:E=()=>rt().replace(/-/g,"").slice(0,20),upstreamOk:k=()=>!1,audit:m=()=>{}}={}){const A=()=>r.ofKind("context").filter(t=>!t.deletedAt),y=t=>r.heads(t),u=(t,e=null,n=x)=>{const o=tt(n,t,{upstreamOk:s=>k(s,n)});return o?{id:t.id,title:t.title,color:t.body?.color||J[0],about:t.body?.about||"",keywords:t.body?.keywords||[],...e?{counts:e.counts,last:e.last}:{},updatedAt:t.updatedAt,instructions:o.instructions,refs:o.refs,mcp_servers:o.mcp_servers,skills:o.skills,...o.access?{access:o.access}:{}}:null},d=(t,e,n)=>q(t,e,n),l=t=>{const e=r.write([t],{host:h,at:i()});return e.written.length&&c({ids:e.written}),r.get(t.id)||t},a=t=>{if(!z.test(String(t||"")))return null;const e=r.get(t);return e&&!e.deletedAt?e:null},N=t=>t?.kind==="agent"?{kind:"agent",id:String(t.name||"unknown")}:{kind:"user",id:t?.kind==="person"?String(t.id):t?.kind==="owner"?"owner":"unknown"},C=(t,e,n,o,s)=>(m("access.denied",{resource:String(e||"context:?").slice(0,120),action:n,actor:N(t)}),new $(o,s)),I=(t,e,n)=>m("access.changed",{resource:e.id,actor:N(t),fields:n}),T=(t,e,n)=>{const o=a(e);if(!o)throw new $(404,"no such context");if(!d(t,o,"list"))throw C(t,e,n,404,"no such context");if(!d(t,o,n))throw C(t,e,n,403,`contexts: ${n} needs a role this caller does not have`);return o},R=t=>B.test(t),M=t=>(Array.isArray(t)?t:[]).slice(0,500);return{list(t=x){const e=A().filter(o=>d(t,o,"list")),n=[...new Set(e.flatMap(o=>_(o)))];return D(e,y(n)).map(o=>u(o.context,o,t)).filter(Boolean)},create(t={},e=x){if(e?.kind!=="owner")throw C(e,"context:new","create",403,"contexts: only the owner makes one here");F(t);const n=j(W({name:t.name,color:t.color,about:t.about,keywords:t.keywords,newId:E,now:i()}),st(t),{now:i()});return u(l(n),null,e)},get(t,e=x){const n=T(e,t,"list");if(!d(e,n,"read"))return{context:u(n,null,e),items:[]};const[o]=D([n],y(_(n)));return{context:u(n,o,e),items:(o?.items||[]).map(s=>({id:s.id,kind:s.kind,title:s.title,updatedAt:s.updatedAt}))}},edit(t,e={},n=x){F(e);const o=e.agents!==void 0||e.noAccess!==void 0,s=T(n,t,o?"manage":"edit"),g=u(l(j(s,e,{now:i()})),null,n);return o&&I(n,s,["agents","noAccess"].filter(w=>e[w]!==void 0)),g},remove(t,e=x){const n=T(e,t,"manage"),o=i();return l({id:n.id,kind:"context",title:n.title,updatedAt:Math.max(o,Number(n.updatedAt)||0),deletedAt:Math.max(o,(Number(n.updatedAt)||0)+1)}),!0},items(t,{add:e=[],remove:n=[]}={},o=x){return this.resources(t,{add:M(e).map(String).filter(R),remove:M(n).map(String).filter(R)},o)},resources(t,{add:e=[],remove:n=[]}={},o=x){let s=T(o,t,"edit");const g=i(),w=S=>{const O=[],P=[];for(const b of M(S))typeof b=="string"&&R(b)?O.push(b):(typeof b=="string"?U(b):b&&U(`${b.type}:${b.id}`))&&P.push(b);return{members:O,refs:P}},f=w(e),v=w(n);return f.members.length&&(s=K(s,f.members,{now:g})),v.members.length&&(s=Z(s,v.members,{now:g})),f.refs.length&&(s=V(s,f.refs,{now:g})),v.refs.length&&(s=Y(s,v.refs,{now:g})),u(l(s),null,o)},people(t,e={},n=x){const o=T(n,t,"manage"),s={};for(const[w,f]of Object.entries(e&&typeof e=="object"?e:{})){if(f!==null&&!G.includes(f))throw new Error(`a role is ${G.join(", ")} or null`);s[w]=f}const g=u(l(p(o,s,{now:i()})),null,n);return Object.keys(s).length&&I(n,o,["people"]),g},suggest({id:t="",title:e="",text:n="",limit:o=3}={},s=x){let g=String(e||""),w=String(n||"");if(t&&B.test(String(t))){const S=r.get(t),O=S?ot(S):null;g=g||S?.title||"",w=w||O?.text||""}const f=A().filter(S=>d(s,S,"edit")),v=y([...new Set(f.flatMap(S=>_(S)))]);return H({title:g,text:w,contexts:f,records:v,limit:Math.min(8,Math.max(1,Number(o)||3))}).filter(S=>!(t&&f.find(O=>O.id===S.id)?.body?.members?.[t]?.on))},turn({chat:t="",named:e=[]}={},n=x){const o=A().filter(f=>d(n,f,"use")),s=et(o,{chatId:String(t||""),named:(Array.isArray(e)?e:[]).map(String).filter(f=>z.test(f))});if(!s.length)return null;const g=y([...new Set(s.flatMap(f=>_(f)))]),w=t?String(t).startsWith("chat:")?String(t):`chat:${t}`:"";return nt(s,{records:g,exclude:w})},scope(t,e=x){const n=T(e,t,"use");return Q(n,y(_(n)))}}}function F(r={}){if(r.instructions!==void 0&&(typeof r.instructions!="string"||r.instructions.length>L))throw new Error(`instructions are a string of at most ${L} characters`);for(const c of["mcp_servers","skills","agents"])if(r[c]!==void 0&&r[c]!==null&&!(Array.isArray(r[c])&&r[c].every(h=>typeof h=="string")))throw new Error(`${c} is a list of names, or null for every one`);if(r.noAccess!==void 0&&!X.includes(r.noAccess))throw new Error(`noAccess is ${X.join(" or ")}`)}const st=r=>Object.fromEntries(["instructions","mcp_servers","skills","noAccess","agents"].filter(c=>r[c]!==void 0).map(c=>[c,r[c]]));async function at(r,c,{pathname:h,api:i,readJson:E,sendJson:k,principal:m=x}){if(!h.startsWith("/v1/contexts"))return!1;const A=(u,d,l="invalid_request_error")=>k(c,u,{error:{message:d,type:l}}),y=u=>{const d=u();return d?k(c,200,{ok:!0,context:d}):A(404,"no such context","not_found")};try{if(h==="/v1/contexts"&&r.method==="GET")return k(c,200,{ok:!0,contexts:i.list(m)}),!0;if(h==="/v1/contexts"&&r.method==="POST"){const a=await E(r);return String(a?.name||"").trim()?(k(c,200,{ok:!0,context:i.create(a,m)}),!0):(A(400,"a context needs a name"),!0)}if(h==="/v1/contexts/suggest"&&r.method==="POST")return k(c,200,{ok:!0,suggestions:i.suggest(await E(r),m)}),!0;if(h==="/v1/contexts/turn"&&r.method==="GET"){const a=new URL(r.url,"http://127.0.0.1").searchParams;return k(c,200,{ok:!0,turn:i.turn({chat:a.get("chat")||"",named:String(a.get("named")||"").split(",").filter(Boolean)},m)}),!0}const u=/^\/v1\/contexts\/(context:[A-Za-z0-9_-]{1,80})(\/items|\/scope|\/resources|\/people)?$/.exec(decodeURIComponent(h));if(!u)return A(404,"no such contexts route","not_found"),!0;const[,d,l]=u;if(!l&&r.method==="GET")return k(c,200,{ok:!0,...i.get(d,m)}),!0;if(!l&&r.method==="PATCH"){const a=await E(r);return y(()=>i.edit(d,a,m)),!0}if(!l&&r.method==="DELETE")return i.remove(d,m),k(c,200,{ok:!0}),!0;if(l==="/items"&&r.method==="POST"){const a=await E(r);return y(()=>i.items(d,a,m)),!0}if(l==="/resources"&&r.method==="POST"){const a=await E(r);return y(()=>i.resources(d,a,m)),!0}if(l==="/people"&&r.method==="POST"){const a=await E(r);return y(()=>i.people(d,a,m)),!0}return l==="/scope"&&r.method==="GET"?(k(c,200,{ok:!0,...i.scope(d,m)}),!0):(A(405,"method not allowed","method_not_allowed"),!0)}catch(u){return u instanceof $?(A(u.status,u.message,u.status===404?"not_found":"forbidden"),!0):(A(400,`contexts: ${u.message}`),!0)}}export{$ as ContextDenied,lt as createContextsApi,at as handleContexts};
|
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const o="0.
|
|
1
|
+
const o="0.162.0";export{o as VERSION};
|