shennian 0.3.43 → 0.3.45
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/publish-build-manifest.json +6 -6
- package/dist/src/native-fusion/codex-parser.js +4 -4
- package/dist/src/native-fusion/local-repository.d.ts +1 -0
- package/dist/src/native-fusion/local-repository.js +2 -2
- package/dist/src/native-fusion/types.d.ts +2 -0
- package/dist/src/session/index-publisher.js +1 -1
- package/package.json +1 -1
|
@@ -306,8 +306,8 @@
|
|
|
306
306
|
},
|
|
307
307
|
{
|
|
308
308
|
"file": "src/native-fusion/codex-parser.js",
|
|
309
|
-
"beforeBytes":
|
|
310
|
-
"afterBytes":
|
|
309
|
+
"beforeBytes": 29910,
|
|
310
|
+
"afterBytes": 12631
|
|
311
311
|
},
|
|
312
312
|
{
|
|
313
313
|
"file": "src/native-fusion/config.js",
|
|
@@ -321,8 +321,8 @@
|
|
|
321
321
|
},
|
|
322
322
|
{
|
|
323
323
|
"file": "src/native-fusion/local-repository.js",
|
|
324
|
-
"beforeBytes":
|
|
325
|
-
"afterBytes":
|
|
324
|
+
"beforeBytes": 13247,
|
|
325
|
+
"afterBytes": 6702
|
|
326
326
|
},
|
|
327
327
|
{
|
|
328
328
|
"file": "src/native-fusion/opencode-parser.js",
|
|
@@ -556,8 +556,8 @@
|
|
|
556
556
|
},
|
|
557
557
|
{
|
|
558
558
|
"file": "src/session/index-publisher.js",
|
|
559
|
-
"beforeBytes":
|
|
560
|
-
"afterBytes":
|
|
559
|
+
"beforeBytes": 1896,
|
|
560
|
+
"afterBytes": 838
|
|
561
561
|
},
|
|
562
562
|
{
|
|
563
563
|
"file": "src/session/manager.js",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import j from"node:fs";import $ from"node:os";import I from"node:path";import{createHash as Z}from"node:crypto";import{buildApprovalPendingPayload as P,buildUserMessagePayload as N,isSystemControlPayload as M,isToolPayload as q}from"@shennian/wire";import{buildImagePayload as D,buildToolPayload as K,inferMimeType as W,makeCursor as U,makeEventKey as w,normalizeText as h,parseStructuredString as O,readJsonlLines as F,readTimestamp as tt,safeParse as k}from"./parser-common.js";function et(e){if(typeof e=="string"){const i=e.trim();return i?{path:i,name:I.basename(i)||"image.png",mimeType:W(i),kind:"image"}:null}if(typeof e!="object"||e===null)return null;const r=e,n=typeof r.path=="string"?r.path:typeof r.file_path=="string"?r.file_path:typeof r.saved_path=="string"?r.saved_path:"";if(!n.trim())return null;const t=typeof r.name=="string"&&r.name.trim()?r.name:I.basename(n)||"image.png",o=typeof r.mimeType=="string"&&r.mimeType.trim()?r.mimeType:W(n);return{path:n,name:t,mimeType:o,kind:"image"}}function H(e){return Array.isArray(e)?e.map(n=>{if(typeof n=="string")return n;if(typeof n=="object"&&n!==null){const t=n;return typeof t.text=="string"?t.text:""}return""}).map(n=>h(n)).filter(Boolean).join(`
|
|
2
2
|
|
|
3
|
-
`):""}function z(
|
|
3
|
+
`):""}function z(e){const r=h(e);if(!r)return{text:"",strippedWrapper:!1};const n=r.match(/My request for Codex:\s*([\s\S]*)$/i);return n&&n[1]?{text:nt(n[1]),strippedWrapper:!0}:{text:r,strippedWrapper:!1}}function nt(e){return h(e.replace(/<image>\s*<\/image>/gi,""))}function B(e){const r=h(e);if(!r)return!1;if(M(r)||/^<environment_context>[\s\S]*<\/environment_context>$/i.test(r)&&r.includes("<current_date>")&&r.includes("<timezone>")&&r.includes("<workspace_roots>"))return!0;const n=r.startsWith("<recommended_plugins>")&&r.includes("</recommended_plugins>"),t=r.includes("# AGENTS.md instructions for ")&&r.includes("<INSTRUCTIONS>")&&r.includes("</INSTRUCTIONS>"),o=r.includes("<environment_context>")&&r.includes("</environment_context>");return t&&o&&(r.startsWith("# AGENTS.md instructions for ")||n)}function L(e){const r=H(e.text_elements),n=Array.isArray(e.input)?H(e.input):"",t=typeof e.message=="string"?z(e.message):{text:"",strippedWrapper:!1},o=t.text,i=r||n||o,u=t.strippedWrapper?"codex_app_context_wrapper":void 0,a=Array.isArray(e.local_images)?e.local_images.map(et).filter(f=>f!=null):[];return!i&&a.length===0||M(i)&&a.length===0||B(i)&&a.length===0?null:a.length>0?{payload:N(i,a),titleText:i,repairHint:u}:{payload:i,titleText:i,repairHint:u}}function rt(e){return e==="turn_completed"||e==="turn_complete"||e==="task_complete"}function ot(e){return/approval|permission|confirm|user[_-]?input|input[_-]?required/i.test(e)}function it(e){const r=typeof e.command=="string"?e.command:Array.isArray(e.command)?e.command.join(" "):"",n=typeof e.prompt=="string"?e.prompt:typeof e.reason=="string"?e.reason:typeof e.message=="string"?e.message:r?`Codex \u8BF7\u6C42\u6267\u884C\u547D\u4EE4\uFF1A${r}`:"Codex \u6B63\u5728\u7B49\u5F85\u7528\u6237\u786E\u8BA4\u540E\u7EE7\u7EED\u3002";return P({title:"\u9700\u8981\u7528\u6237\u786E\u8BA4",content:n,source:"codex",actionHint:"\u5F53\u524D\u795E\u5FF5\u6682\u4E0D\u652F\u6301\u8FDC\u7A0B\u786E\u8BA4\uFF0C\u8BF7\u56DE\u5230\u8FD0\u884C Codex \u7684\u7535\u8111/\u7EC8\u7AEF\u5B8C\u6210\u786E\u8BA4\u3002"})}function G(e,r){return Array.isArray(e)?h(e.map(n=>{if(typeof n=="string")return n;if(typeof n!="object"||n===null)return"";const t=n;return t.type!==r?"":typeof t.text=="string"?t.text:""}).filter(Boolean).join(`
|
|
4
4
|
|
|
5
|
-
`)):""}function
|
|
6
|
-
(exit ${String(
|
|
5
|
+
`)):""}function st(e){if(!Array.isArray(e))return[];const r=[];for(const n of e){if(typeof n!="object"||n===null)continue;const t=n;if(t.type!=="input_image")continue;const o=typeof t.path=="string"?t.path:typeof t.file_path=="string"?t.file_path:typeof t.saved_path=="string"?t.saved_path:typeof t.image_path=="string"?t.image_path:"";o.trim()&&r.push({path:o,name:I.basename(o)||"image.png",mimeType:W(o),kind:"image"})}return r}function J(e){if(e.type!=="message")return null;const r=e.role==="assistant"?"agent":e.role==="user"?"user":null;if(!r)return null;if(r==="agent"){const i=G(e.content,"output_text");return M(i)?null:i?{role:r,payload:i,titleText:i}:null}const n=z(G(e.content,"input_text")),t=n.text,o=st(e.content);return!t&&o.length===0||M(t)&&o.length===0||B(t)&&o.length===0?null:{role:r,payload:o.length>0?N(t,o):t,titleText:t,repairHint:n.strippedWrapper?"codex_app_context_wrapper":void 0}}function Q(e){if(!e)return"";try{const r=JSON.parse(e);if(typeof r=="object"&&r!==null){const n=r;if(n.type==="user"&&typeof n.content=="string")return h(n.content)}}catch{}return h(e)}function ct(e,r,n,t){return e.agentType!=="codex"||e.role!==r||q(e.payload)||Math.abs(e.ts-t)>300*1e3?!1:Q(e.payload)===Q(n)}function R(e,r,n,t){for(let o=e.length-1;o>=0;o-=1){const i=e[o];if(i){if(ct(i,r,n,t))return o;if(i.agentType==="codex"&&Math.abs(i.ts-t)>300*1e3)break}}return-1}function v(e,r,n,t,o,i,u,a,f,c,s="agent",l=!1,m){u&&e.push({agentType:"codex",sourceMode:"codex_rollout_import",sourceSessionKey:o,sourceEventKey:w(r,n,t),cursor:U(r,n),role:s,ts:i,payload:u,title:a,modelId:f,workDir:c,terminal:l,repairHint:m})}function x(e,r,n,t,o,i,u,a,f,c,s,l,m){const A=w(r,n,t),y=typeof m?.callId=="string"&&m.callId.trim()?m.callId.trim():null,T=y?Z("sha256").update(`${o}\0${y}`).digest("hex").slice(0,32):null,p=T?`tool:${T}`:void 0,b=T?`native:tool:${T}`:`native:${A}`,g=m?.completed&&T?2:1,S=l!==void 0?"completed":"running";e.push({agentType:"codex",sourceMode:"codex_rollout_import",sourceSessionKey:o,sourceEventKey:A,cursor:U(r,n),role:"agent",ts:i,payload:K({name:u,toolCallId:b,detailRevision:g,status:S}),title:a,modelId:f,workDir:c,...p?{canonicalMessageKey:p,canonicalMutation:m?.completed?"upsert":"append"}:{},localToolDetail:{toolCallId:b,detailRevision:g,name:u,...s!==void 0?{args:s}:{},...l!==void 0?{result:l}:{},status:S}})}function ut(e,r,n,t,o,i,u,a,f){const c=typeof t.type=="string"?t.type:"";if(c){if(c==="message"){const s=J(t);if(!s||R(e,s.role,s.payload,i)>=0)return;v(e,r,n,`${c}:${s.role}`,o,i,s.payload,u,a,f,s.role,!1,s.repairHint);return}if(c==="function_call"){const s=typeof t.name=="string"?t.name:"function_call";x(e,r,n,c,o,i,s,u,a,f,O(t.arguments),void 0,{callId:t.call_id});return}if(c==="function_call_output"){x(e,r,n,c,o,i,"function_call_output",u,a,f,void 0,t.output,{callId:t.call_id,completed:!0});return}if(c==="custom_tool_call"){const s=typeof t.name=="string"?t.name:"custom_tool_call",l=t.input!==void 0?{input:t.input}:void 0;x(e,r,n,c,o,i,s,u,a,f,l,void 0,{callId:t.call_id});return}if(c==="custom_tool_call_output"){const s=typeof t.name=="string"?t.name:"custom_tool_call_output",l=t.output??t.result??t.content;x(e,r,n,c,o,i,s,u,a,f,void 0,l,{callId:t.call_id,completed:!0});return}if(c==="web_search_call"){const s=typeof t.action=="object"&&t.action!==null?t.action:null;x(e,r,n,c,o,i,"web_search",u,a,f,s??t.query);return}}}function at(e,r,n,t,o,i,u,a,f){const c=typeof t.type=="string"?t.type:"";if(c){if(c==="user_message"){const s=L(t);if(!s)return;v(e,r,n,c,o,i,s.payload,u,a,f,"user",!1,s.repairHint);return}if(c==="agent_message"){const s=typeof t.message=="string"?h(t.message):"";if(!s||M(s))return;v(e,r,n,c,o,i,s,u,a,f);return}if(c==="turn_aborted"||c==="error"){const s=typeof t.message=="string"?h(t.message):typeof t.error=="string"?h(t.error):"";if(!s)return;v(e,r,n,c,o,i,s,u,a,f,"agent",!0);return}if(ot(c)){v(e,r,n,c,o,i,it(t),u,a,f,"agent");return}if(c==="exec_command_end"){const s=Array.isArray(t.command)?t.command:t.parsed_cmd??t.command,l=t.exit_code??t.exitCode,m=[typeof t.aggregated_output=="string"?t.aggregated_output:"",l!=null?`
|
|
6
|
+
(exit ${String(l)})`:""].join("");x(e,r,n,c,o,i,"command_execution",u,a,f,{command:s},m);return}if(c==="patch_apply_end"){x(e,r,n,c,o,i,"apply_patch",u,a,f,t.changes,{success:t.success,stdout:t.stdout,stderr:t.stderr});return}if(c==="mcp_tool_call_end"){const s=typeof t.invocation=="object"&&t.invocation!==null?t.invocation:null,l=typeof s?.tool=="string"?s.tool:"mcp_tool_call",m={server:s?.server,...typeof s?.arguments=="object"&&s.arguments!==null?s.arguments:{}};x(e,r,n,c,o,i,l,u,a,f,m,t.result);return}if(c==="dynamic_tool_call_request"){const s=typeof t.tool=="string"?t.tool:"dynamic_tool_call";x(e,r,n,c,o,i,s,u,a,f,t.arguments,void 0,{callId:t.callId??t.call_id});return}if(c==="dynamic_tool_call_response"){const s=typeof t.tool=="string"?t.tool:"dynamic_tool_call";x(e,r,n,c,o,i,s,u,a,f,void 0,t.result??t.output,{callId:t.callId??t.call_id,completed:!0});return}if(c==="web_search_end"){const s=typeof t.action=="object"&&t.action!==null?t.action:null;x(e,r,n,c,o,i,"web_search",u,a,f,s??t.query,t.query);return}if(c==="image_generation_end"){const s=typeof t.saved_path=="string"?t.saved_path.trim():"";if(!s)return;v(e,r,n,c,o,i,D(s),u,a,f);return}c==="view_image_tool_call"&&x(e,r,n,c,o,i,"view_image",u,a,f,t.path??t.image_path??t)}}function E(e=!1){return{sourceSessionKey:"",workDir:"",modelId:null,title:"",skipImport:e}}function V(e){if((typeof e.thread_source=="string"?e.thread_source.trim().toLowerCase():"")==="subagent")return!0;const n=typeof e.source=="object"&&e.source!==null?e.source:null;if(n&&typeof n.subagent=="object"&&n.subagent!==null)return!0;const t=typeof e.parent_thread_id=="string"&&e.parent_thread_id.trim().length>0,o=typeof e.agent_nickname=="string"||typeof e.agent_role=="string"||typeof e.multi_agent_version=="string";return t&&o}function ft(e){const r=j.openSync(e,"r");try{const n=[];let t=0,o="";for(;t<1024*1024;){const f=Buffer.alloc(16384),c=j.readSync(r,f,0,f.length,t);if(c<=0)break;const s=f.subarray(0,c);n.push(s),t+=c;const l=Buffer.concat(n),m=l.indexOf(10);if(m>=0){o=l.subarray(0,m).toString("utf8");break}}!o&&n.length>0&&(o=Buffer.concat(n).toString("utf8"));const i=k(o);if(!i||i.type!=="session_meta")return E();const u=typeof i.payload=="object"&&i.payload!==null?i.payload:null;if(!u)return E();if(V(u))return E(!0);const a=typeof u.id=="string"?u.id:"";return{sourceSessionKey:a,workDir:typeof u.cwd=="string"?u.cwd:"",modelId:X(u),title:Y(a)??"",skipImport:!1}}finally{j.closeSync(r)}return E()}function X(e){return(typeof e.model=="string"?e.model.trim():"")||null}function lt(e,r){if((typeof e.id=="string"?e.id:typeof e.thread_id=="string"?e.thread_id:typeof e.session_id=="string"?e.session_id:"")!==r)return null;const o=(typeof e.thread_name=="string"?e.thread_name:typeof e.title=="string"?e.title:"").trim();return o?o.slice(0,120):null}function Y(e){if(!e)return null;const r=I.join($.homedir(),".codex","session_index.jsonl");if(!j.existsSync(r))return null;let n=null;return F(r,0,t=>{if(!t.trim())return;const o=k(t);if(!o)return;const i=lt(o,e);i&&(n=i)}),n}function ht(){const e=[I.join($.homedir(),".codex","sessions"),I.join($.homedir(),".codex","archived_sessions")],r=[],n=t=>{for(const o of j.readdirSync(t,{withFileTypes:!0})){const i=I.join(t,o.name);o.isDirectory()?n(i):o.isFile()&&o.name.endsWith(".jsonl")&&r.push(i)}};for(const t of e)j.existsSync(t)&&n(t);return[...new Set(r)].sort()}function yt(e,r){const n=[],t=ft(e);let{sourceSessionKey:o,workDir:i,modelId:u,title:a,skipImport:f}=t,c=t.title;if(f)return{nextOffset:j.statSync(e).size,events:[]};let s=!1;const l=F(e,r,(m,A)=>{const y=k(m);if(!y)return;const T=typeof y.type=="string"?y.type:"",p=typeof y.payload=="object"&&y.payload!==null?y.payload:null,b=tt(y.timestamp);if(!(!p||!b)){if(T==="session_meta"){if(V(p)){n.length=0,f=!0;return}o=typeof p.id=="string"?p.id:o,i=typeof p.cwd=="string"?p.cwd:i,u=X(p)??u;const g=Y(o);g&&(c=g,a=g);return}if(!f&&o){if(T==="response_item"){const g=J(p);g?.role==="user"&&g.titleText&&!a&&(a=g.titleText.slice(0,80)),ut(n,e,A,p,o,b,a,u,i);return}if(T==="event_msg"){const g=typeof p.type=="string"?p.type:"";if(rt(g)){let d=!1;for(let _=n.length-1;_>=0;_-=1){const C=n[_];if(C?.agentType==="codex"&&C.role==="agent"&&!q(C.payload)){C.terminal=!0,d=!0,s=!1;break}}if(!d)for(let _=n.length-1;_>=0;_-=1){const C=n[_];if(!(C?.agentType!=="codex"||C.role!=="agent")){C.terminal=!0,d=!0,s=!1;break}}d||(s=!0);return}if(g==="user_message"){const d=L(p);if(d?.titleText&&!a&&(a=d.titleText.slice(0,80)),d){const _=R(n,"user",d.payload,b);_>=0&&n.splice(_,1)}}else if(g==="agent_message"){const d=typeof p.message=="string"?h(p.message):"";if(d&&!M(d)){const _=R(n,"agent",d,b);_>=0&&n.splice(_,1)}}const S=n.length;at(n,e,A,p,o,b,a,u,i),s&&n.length>S&&(n[n.length-1].terminal=!0,s=!1)}}}});for(const m of n)m.titleSource=c&&m.title===c?"agent_native":"first_user_fallback";return{nextOffset:l,events:n}}export{ht as listCodexRolloutFiles,Y as lookupCodexThreadName,yt as parseCodexRolloutChunk};
|
|
@@ -36,6 +36,7 @@ export declare class NativeFusionLocalRepository {
|
|
|
36
36
|
recordLocalSession?: (input: RecordSessionInput) => unknown;
|
|
37
37
|
listLocalSessions?: typeof listSessionRecords;
|
|
38
38
|
writeLocalToolDetail?: (detail: Omit<LocalToolDetail, 'schemaVersion'>) => void;
|
|
39
|
+
readLocalToolDetail?: (sessionId: string, toolCallId: string) => LocalToolDetail | null;
|
|
39
40
|
});
|
|
40
41
|
commitEvents(events: readonly ParsedNativeEvent[]): NativeLocalCommitResult[];
|
|
41
42
|
commitEvent(event: ParsedNativeEvent): NativeLocalCommitResult;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import d from"node:crypto";import
|
|
2
|
-
`,"utf8"),
|
|
1
|
+
import d from"node:crypto";import c from"node:fs";import w from"node:path";import{resolvePersonalSyncV1Path as N}from"../personal-sync/paths.js";import{getCanonicalSessionStore as O,getDaemonInstallationId as k,listSessionRecords as B,recordSession as T}from"../session/store.js";import{readToolDetail as H,writeToolDetail as J}from"../session/tool-detail-store.js";const h=1;class L extends Error{code="missing_user_boundary";constructor(e){super(`native source ${e} does not start at a visible user boundary`),this.name="MissingUserBoundaryError"}}class Y{options;constructor(e={}){this.options=e}commitEvents(e){return[...e].sort((t,o)=>t.ts-o.ts).map(t=>this.commitEvent(t))}commitEvent(e){R(e);const t=this.installationId(),o=this.readSources(),i=K(e.agentType,e.sourceSessionKey),r=o.sources[i],l=j(e),g=this.ledgerFile(e.agentType,e.sourceEventKey),n=c.existsSync(g)?b(g):null;if(n&&n.eventFingerprint!==l)throw new Error(`native event identity conflict: ${e.sourceEventKey}`);if(!r&&!n&&e.role!=="user")throw new L(e.sourceSessionKey);const p=e.claimSessionId??null,a=r?.sessionId??n?.sessionId??p??A(t,e.agentType,e.sourceSessionKey);if(p&&r&&r.sessionId!==p)throw new Error(`managed claim session conflicts with source binding ${e.sourceSessionKey}`);const m=this.canonicalStore(),u=e.claimCanonicalMessageId??V(t,e.agentType,e.canonicalMessageKey??e.sourceEventKey);let f=m.getManifest(a)?.bodyRevision??0,$=!!n;const S=!!e.claimCanonicalMessageId;if(S){const y=m.getMessageState(a,u);if(!y||y.tombstoned)throw new Error(`managed echo claim target is not durable: ${u}`)}if(!n&&!S){const y=e.canonicalMutation==="upsert"?m.getMessageState(a,u):null,E={id:u,sessionId:a,role:e.role,ts:y?.message?.ts??e.ts,payload:U(y?.message?.payload,e.payload)},M=e.canonicalMutation==="upsert"?m.upsert(a,E):m.append(a,E);if(f=M.bodyRevision,$=M.duplicate,e.localToolDetail){const _=this.options.writeLocalToolDetail??J,C=this.options.readLocalToolDetail??H,F=P(C(a,e.localToolDetail.toolCallId),e.localToolDetail);_({sessionId:a,...F,ts:e.ts,detailRef:{toolIndex:0}})}}n||this.recordIndex(e,a);const I=new Date().toISOString();return n||x(g,{schemaVersion:h,daemonInstallationId:t,sessionId:a,agentType:e.agentType,sourceSessionKey:e.sourceSessionKey,sourceEventKey:e.sourceEventKey,eventFingerprint:l,canonicalMessageId:u,canonicalRevision:f,cursor:e.cursor??null,mappedBy:S?"managed_echo_claim":e.sourceMode,eventTs:e.ts,createdAt:I}),o.sources[i]={schemaVersion:h,daemonInstallationId:t,sessionId:a,agentType:e.agentType,sourceSessionKey:e.sourceSessionKey,sourceMode:n?r?.sourceMode??e.sourceMode:e.sourceMode,lastCursor:n?r?.lastCursor??n.cursor:e.cursor??r?.lastCursor??null,bodyRevision:f,createdAt:r?.createdAt??I,updatedAt:I},x(this.sourcesFile(),o),{sessionId:a,messageId:u,bodyRevision:f,duplicate:$,claimed:S}}listSourceBindings(){return Object.values(this.readSources().sources)}observeNativeTitle(e,t,o){const i=o.trim().slice(0,120);if(!i)return!1;const r=this.readSources().sources[K(e,t)];if(!r)return!1;const l=(this.options.listLocalSessions??B)().find(p=>p.sessionId===r.sessionId);if(l?.titleLockedByUser||l?.titleSource==="agent_native"&&l.title===i)return!1;const g=d.createHash("sha256").update(`${e}\0${t}\0${i}`).digest("hex");return(this.options.recordLocalSession??T)({sessionId:r.sessionId,agentType:r.agentType,workDir:l?.workDir??"",agentSessionId:t,title:i,titleSource:"agent_native",titleOriginEventId:`agent-native:${g}`}),!0}recordIndex(e,t){(this.options.recordLocalSession??T)({sessionId:t,agentType:e.agentType,workDir:e.workDir??"",agentSessionId:e.sourceSessionKey,modelId:e.modelId??null,status:e.terminal?"completed":"active",lastActivityAt:new Date(e.ts).toISOString(),lastMessagePreview:e.role==="user"?D(e.payload):void 0,title:e.title?.trim()||(e.role==="user"?D(e.payload)??"":void 0),titleSource:e.title?.trim()?e.titleSource??"first_user_fallback":"first_user_fallback",titleOriginEventId:e.sourceEventKey})}readSources(){const e=this.sourcesFile();if(!c.existsSync(e))return{schemaVersion:h,daemonInstallationId:this.installationId(),sources:{}};const t=b(e);if(t.schemaVersion!==h||t.daemonInstallationId!==this.installationId()||!t.sources)throw new Error("invalid native source binding store");return t}installationId(){return this.options.daemonInstallationId??k()}canonicalStore(){return this.options.canonicalStore??O()}rootDir(){return this.options.rootDir??N("native-fusion")}sourcesFile(){return w.join(this.rootDir(),"sources.json")}ledgerFile(e,t){const o=d.createHash("sha256").update(`${e}\0${t}`).digest("hex");return w.join(this.rootDir(),"ledger",`${o}.json`)}}function R(s){if(!s.agentType||!s.sourceSessionKey||!s.sourceEventKey||!s.payload)throw new Error("invalid native event");if(!Number.isFinite(s.ts))throw new Error("invalid native event timestamp")}function K(s,e){return d.createHash("sha256").update(`${s}\0${e}`).digest("hex")}function A(s,e,t){return`native-session-${d.createHash("sha256").update(`${s}\0${e}\0${t}`).digest("hex").slice(0,32)}`}function V(s,e,t){return`native-${d.createHash("sha256").update(`${s}\0${e}\0${t}`).digest("hex").slice(0,32)}`}function j(s){return d.createHash("sha256").update(JSON.stringify({agentType:s.agentType,sourceSessionKey:s.sourceSessionKey,sourceEventKey:s.sourceEventKey,role:s.role,ts:s.ts,payload:s.payload,claimCanonicalMessageId:s.claimCanonicalMessageId??null,claimSessionId:s.claimSessionId??null,canonicalMessageKey:s.canonicalMessageKey??null,canonicalMutation:s.canonicalMutation??"append"})).digest("hex")}function U(s,e){if(!s)return e;try{const t=JSON.parse(s),o=JSON.parse(e);if(t.type!=="tool"||o.type!=="tool"||t.toolCallId!==o.toolCallId)return e;const i=typeof o.name=="string"?o.name:"",r=/(?:_output|_result)$/.test(i);return JSON.stringify({...t,...o,...r&&typeof t.name=="string"?{name:t.name}:{}})}catch{return e}}function P(s,e){if(!s||s.toolCallId!==e.toolCallId)return e;const t=/(?:_output|_result)$/.test(e.name);return{...e,name:t?s.name:e.name,...e.args===void 0&&s.args!==void 0?{args:s.args}:{},...e.result===void 0&&s.result!==void 0?{result:s.result}:{}}}function D(s){const e=s.replace(/\s+/g," ").trim();return e?e.length>120?`${e.slice(0,120)}...`:e:null}function x(s,e){const t=w.dirname(s);c.mkdirSync(t,{recursive:!0,mode:448});const o=`${s}.tmp-${process.pid}-${d.randomBytes(6).toString("hex")}`;let i;try{i=c.openSync(o,"wx",384),c.writeFileSync(i,`${JSON.stringify(e,null,2)}
|
|
2
|
+
`,"utf8"),c.fsyncSync(i),c.closeSync(i),i=void 0,c.renameSync(o,s)}finally{i!==void 0&&c.closeSync(i);try{c.unlinkSync(o)}catch{}}}function b(s){return JSON.parse(c.readFileSync(s,"utf8"))}export{L as MissingUserBoundaryError,Y as NativeFusionLocalRepository};
|
|
@@ -24,6 +24,8 @@ export type ParsedNativeEvent = NativeSessionEventPayload & {
|
|
|
24
24
|
repairHint?: NativeRepairHint;
|
|
25
25
|
sourceSessionCreatedAtMs?: number;
|
|
26
26
|
claimSessionId?: string | null;
|
|
27
|
+
canonicalMessageKey?: string;
|
|
28
|
+
canonicalMutation?: 'append' | 'upsert';
|
|
27
29
|
titleSource?: Extract<SessionTitleSource, 'agent_native' | 'first_user_fallback'>;
|
|
28
30
|
localToolDetail?: {
|
|
29
31
|
toolCallId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{acknowledgeSessionIndexUpdate as
|
|
1
|
+
import{acknowledgeSessionIndexUpdate as r,listPendingSessionIndexUpdates as a}from"./store.js";const o=new WeakMap,t=new WeakSet;function c(s){const e=s,i=o.get(e);if(i)return t.add(e),i;const n=f(s).finally(()=>{o.get(e)===n&&o.delete(e),t.delete(e)&&u(s)});return o.set(e,n),n}async function f(s){const e=a(),i=[];for(const n of e)try{await s.sendBufferedEvent({type:"event",event:"session.index.updated",id:`session-index-${n.daemonInstallationId}-${n.session.id}-${n.session.indexRevision}`,payload:n},6e4),r(n.session.id,n.session.indexRevision)}catch(d){i.push(d)}if(i.length>0)throw new AggregateError(i,"one or more session indexes failed")}function u(s){c(s).catch(e=>{console.error("[session-index] sync failed; dirty revisions retained for retry",e)})}export{c as publishPendingSessionIndexes,u as requestSessionIndexPublish};
|