agentix-cli 0.81.0 → 0.81.1

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.
Files changed (28) hide show
  1. package/apps/mac-voice/Sources/AgentXVoice/CallModel.swift +11 -0
  2. package/apps/mac-voice/Sources/AgentXVoice/Calls.swift +7 -4
  3. package/apps/mac-voice/Sources/AgentXVoice/main.swift +15 -3
  4. package/dist/{agent-BDEPUFBQ.js → agent-75URYGWI.js} +2 -2
  5. package/dist/{chunk-ZDDJNKU5.js → chunk-3FCYKGU6.js} +2 -2
  6. package/dist/chunk-LLNPKE7H.js +11 -0
  7. package/dist/chunk-LLNPKE7H.js.map +1 -0
  8. package/dist/{chunk-HYE2UUQ4.js → chunk-R64DAHBH.js} +160 -160
  9. package/dist/chunk-R64DAHBH.js.map +1 -0
  10. package/dist/{chunk-EFV7U5LD.js → chunk-V4GXHBOH.js} +64 -64
  11. package/dist/chunk-V4GXHBOH.js.map +1 -0
  12. package/dist/cli.js +1 -1
  13. package/dist/index.js +1 -1
  14. package/dist/{program-FUYHN2F7.js → program-7UH4FCA3.js} +4 -4
  15. package/dist/{registry-PLSOZ3CL.js → registry-MDWD7EAO.js} +2 -2
  16. package/dist/{tool-MSXWU44P.js → tool-GPCJM7U5.js} +2 -2
  17. package/dist/{tool-X7YEIJVZ.js → tool-VKQIDEG7.js} +2 -2
  18. package/package.json +1 -1
  19. package/dist/chunk-EFV7U5LD.js.map +0 -1
  20. package/dist/chunk-HYE2UUQ4.js.map +0 -1
  21. package/dist/chunk-OVN5LVJY.js +0 -11
  22. package/dist/chunk-OVN5LVJY.js.map +0 -1
  23. /package/dist/{agent-BDEPUFBQ.js.map → agent-75URYGWI.js.map} +0 -0
  24. /package/dist/{chunk-ZDDJNKU5.js.map → chunk-3FCYKGU6.js.map} +0 -0
  25. /package/dist/{program-FUYHN2F7.js.map → program-7UH4FCA3.js.map} +0 -0
  26. /package/dist/{registry-PLSOZ3CL.js.map → registry-MDWD7EAO.js.map} +0 -0
  27. /package/dist/{tool-MSXWU44P.js.map → tool-GPCJM7U5.js.map} +0 -0
  28. /package/dist/{tool-X7YEIJVZ.js.map → tool-VKQIDEG7.js.map} +0 -0
@@ -39,6 +39,17 @@ enum CallModel {
39
39
  return .ring(first)
40
40
  }
41
41
 
42
+ /// What each poll tells the daemon (#408): `busy` when a new call
43
+ /// cannot ring here, `showing` with the call that is ringing. The
44
+ /// daemon keeps a call waiting while the widget is busy, so its ring
45
+ /// time runs only once it can ring.
46
+ static func pollQuery(ringing: String?, canRing: Bool) -> String {
47
+ var items: [String] = []
48
+ if ringing != nil || !canRing { items.append("busy=1") }
49
+ if let ringing { items.append("showing=\(ringing)") }
50
+ return items.isEmpty ? "" : "?" + items.joined(separator: "&")
51
+ }
52
+
42
53
  /// "Call back in…" choices, in minutes.
43
54
  static let laterChoices = [5, 15, 30]
44
55
 
@@ -5,9 +5,10 @@ import AppKit
5
5
  /// CallModel.swift; main.swift wires them to the conversation.
6
6
  enum CallClient {
7
7
  /// GET /calls/ringing, or nil when the daemon cannot be reached. The
8
- /// poll is also how the daemon knows the widget is running.
9
- static func ringing() async -> RingingCalls? {
10
- guard let url = URL(string: "\(Config.daemonURL)/calls/ringing") else { return nil }
8
+ /// poll is also how the daemon knows the widget is running, and
9
+ /// `query` (CallModel.pollQuery) whether it can ring.
10
+ static func ringing(_ query: String = "") async -> RingingCalls? {
11
+ guard let url = URL(string: "\(Config.daemonURL)/calls/ringing\(query)") else { return nil }
11
12
  var req = URLRequest(url: url)
12
13
  req.timeoutInterval = 3
13
14
  guard let (data, response) = try? await URLSession.shared.data(for: req),
@@ -50,6 +51,8 @@ final class CallWatcher {
50
51
  private var polling = false
51
52
  /// Each poll that reached the daemon.
52
53
  var onPoll: ((RingingCalls) -> Void)?
54
+ /// What to tell the daemon with the next poll (CallModel.pollQuery).
55
+ var query: (() -> String)?
53
56
 
54
57
  func start() {
55
58
  timer?.invalidate()
@@ -63,7 +66,7 @@ final class CallWatcher {
63
66
  guard !polling else { return }
64
67
  polling = true
65
68
  defer { polling = false }
66
- if let state = await CallClient.ringing() { onPoll?(state) }
69
+ if let state = await CallClient.ringing(query?() ?? "") { onPoll?(state) }
67
70
  }
68
71
  }
69
72
 
@@ -77,6 +77,9 @@ final class App: NSObject, NSApplicationDelegate {
77
77
  private let ringer = Ringer()
78
78
  /// The call ringing on the pill now.
79
79
  private var ringingCall: IncomingCall?
80
+ /// The call being answered, until the daemon has the answer: a poll
81
+ /// sent meanwhile still says the pill is showing it (#408).
82
+ private var answeringCall: String?
80
83
  /// The call in progress: every turn goes to its agent until hang-up.
81
84
  private var activeCall: IncomingCall?
82
85
 
@@ -365,6 +368,10 @@ final class App: NSObject, NSApplicationDelegate {
365
368
  panel.callBar.onLater = { [weak self] minutes in self?.endRinging { await CallClient.later($0, minutes: minutes) } }
366
369
  panel.callBar.onHangUp = { [weak self] in self?.hangUp() }
367
370
  callWatcher.onPoll = { [weak self] state in self?.polled(state) }
371
+ callWatcher.query = { [weak self] in
372
+ guard let self else { return "" }
373
+ return CallModel.pollQuery(ringing: self.ringingCall?.id ?? self.answeringCall, canRing: self.canRing)
374
+ }
368
375
  callWatcher.start()
369
376
 
370
377
  // The target does not wait for the microphone: the menu shows it
@@ -836,9 +843,11 @@ final class App: NSObject, NSApplicationDelegate {
836
843
  /// At rest: waiting for the next words in a call, else idle.
837
844
  private var rest: Panel.State { activeCall == nil ? .idle : .onCall }
838
845
 
846
+ /// A new call can ring: no call in progress, no turn, microphone closed.
847
+ private var canRing: Bool { activeCall == nil && !busy && !recorder.isRecording }
848
+
839
849
  private func polled(_ state: RingingCalls) {
840
- let free = activeCall == nil && !busy && !recorder.isRecording
841
- switch CallModel.action(ringing: ringingCall?.id, calls: state.calls, canRing: free) {
850
+ switch CallModel.action(ringing: ringingCall?.id, calls: state.calls, canRing: canRing) {
842
851
  case .none:
843
852
  return
844
853
  case .stop:
@@ -873,10 +882,13 @@ final class App: NSObject, NSApplicationDelegate {
873
882
  if recorder.isRecording { stopPolling(); _ = recorder.stop() }
874
883
  ringer.stop()
875
884
  ringingCall = nil
885
+ answeringCall = call.id
876
886
  busy = true
877
887
  panel.render(.thinking)
878
888
  Task { @MainActor in
879
- guard let opener = await CallClient.answer(call.id) else {
889
+ let answer = await CallClient.answer(call.id)
890
+ answeringCall = nil
891
+ guard let opener = answer else {
880
892
  busy = false
881
893
  panel.showCall(.hidden)
882
894
  panel.render(.error("The call ended"))
@@ -1,2 +1,2 @@
1
- import{A as a,B as b,C as c}from"./chunk-ZDDJNKU5.js";import"./chunk-SFQUP3BP.js";import"./chunk-QOYAX2FT.js";import"./chunk-5MUJZODV.js";import"./chunk-7I7IEX4S.js";import"./chunk-JHCI6XCJ.js";import"./chunk-DSYKYZMT.js";import"./chunk-QIJLFPWE.js";export{a as createAgentContext,b as generate,c as generateStream};
2
- //# sourceMappingURL=agent-BDEPUFBQ.js.map
1
+ import{A as a,B as b,C as c}from"./chunk-3FCYKGU6.js";import"./chunk-SFQUP3BP.js";import"./chunk-QOYAX2FT.js";import"./chunk-5MUJZODV.js";import"./chunk-7I7IEX4S.js";import"./chunk-JHCI6XCJ.js";import"./chunk-DSYKYZMT.js";import"./chunk-QIJLFPWE.js";export{a as createAgentContext,b as generate,c as generateStream};
2
+ //# sourceMappingURL=agent-75URYGWI.js.map
@@ -48,7 +48,7 @@ The "modified" field is optional and can contain updated values to pass forward.
48
48
  ... (output truncated)`:i;return s.exitCode!==0?{tool_use_id:e.id,content:`Command exited with code ${s.exitCode}:
49
49
  ${c}`,is_error:!0}:{tool_use_id:e.id,content:c||"(no output)"}}async editFile(e){let t=String(e.input.path||""),o=e.input.edits,n=ge.resolve(this.cwd,t);if(!o||o.length===0)return{tool_use_id:e.id,content:"No edits provided.",is_error:!0};let s=await W.checkFileWrite(t);if(s==="deny")return{tool_use_id:e.id,content:`File write blocked by permissions: ${t}`,is_error:!0};if(s==="skip")return{tool_use_id:e.id,content:`File write skipped (plan mode): ${t}`};if(f.has("pre:file-write")){let a=await f.execute("pre:file-write",{event:"pre:file-write",file:n,cwd:this.cwd});if(a.blocked)return{tool_use_id:e.id,content:a.message||`File edit blocked by pre:file-write hook: ${t}`,is_error:!0}}let i=await re.readFile(n,"utf8"),c=[];for(let a of o)i.includes(a.old_text)?(i=i.replace(a.old_text,a.new_text),c.push(`Replaced: "${a.old_text.slice(0,40)}..."`)):c.push(`Not found: "${a.old_text.slice(0,40)}..."`);return this.options.dryRun||await re.writeFile(n,i,"utf8"),f.has("post:file-write")&&await f.execute("post:file-write",{event:"post:file-write",file:n,fileContent:i,cwd:this.cwd}),{tool_use_id:e.id,content:`Edited ${t}:
50
50
  ${c.join(`
51
- `)}`}}async createFiles(e){let t=e.input,o=t.files||[];return{tool_use_id:e.id,content:t.summary||`Queued ${o.length} file(s) for creation.`,files:o}}async spawnAgent(e){let t=String(e.input.agent_id||""),o=String(e.input.prompt||""),n=Number(e.input.timeout_seconds)||300;if(!t||!o)return{tool_use_id:e.id,content:"agent_id and prompt are required.",is_error:!0};try{let{SubAgentManager:s}=await import("./subagent-XY5N7TUU.js"),{getGlobalRegistry:i}=await import("./registry-PLSOZ3CL.js"),c=i();if(!c)return{tool_use_id:e.id,content:"Sub-agent spawning requires the daemon to be running.",is_error:!0};let p=await new s(c).spawn({targetAgentId:t,prompt:o,parentAgentId:"orchestrator",timeout:n*1e3});return p.success?{tool_use_id:e.id,content:`Sub-agent "${t}" completed (${Math.round(p.duration/1e3)}s):
51
+ `)}`}}async createFiles(e){let t=e.input,o=t.files||[];return{tool_use_id:e.id,content:t.summary||`Queued ${o.length} file(s) for creation.`,files:o}}async spawnAgent(e){let t=String(e.input.agent_id||""),o=String(e.input.prompt||""),n=Number(e.input.timeout_seconds)||300;if(!t||!o)return{tool_use_id:e.id,content:"agent_id and prompt are required.",is_error:!0};try{let{SubAgentManager:s}=await import("./subagent-XY5N7TUU.js"),{getGlobalRegistry:i}=await import("./registry-MDWD7EAO.js"),c=i();if(!c)return{tool_use_id:e.id,content:"Sub-agent spawning requires the daemon to be running.",is_error:!0};let p=await new s(c).spawn({targetAgentId:t,prompt:o,parentAgentId:"orchestrator",timeout:n*1e3});return p.success?{tool_use_id:e.id,content:`Sub-agent "${t}" completed (${Math.round(p.duration/1e3)}s):
52
52
 
53
53
  ${p.content}`}:{tool_use_id:e.id,content:`Sub-agent "${t}" failed: ${p.error}`,is_error:!0}}catch(s){return{tool_use_id:e.id,content:`Failed to spawn sub-agent: ${s.message}`,is_error:!0}}}async askUser(e){let t=String(e.input.question||""),o=e.input.options,n=t;return o?.length&&(n+=`
54
54
  Options: ${o.join(", ")}`),{tool_use_id:e.id,content:"Question sent to user.",followUp:n}}};async function Ae(r){let{provider:e,systemPrompt:t,messages:o,providerOptions:n,cwd:s,maxIterations:i=20,enabledTools:c,interactive:a=!0,overwrite:p=!1,dryRun:l=!1,onProgress:d,abortSignal:u}=r,m=u?{...n,abortSignal:u}:n;if(!e.generateRaw)return dt(r);let I=new se(s,{interactive:a,overwrite:p,dryRun:l,acmeContext:r.acmeContext,abortSignal:u}),D=be(c);if(r.acmeContext)for(let g of at)D.push({name:g.name,description:g.description,input_schema:g.input_schema});let E=new Set;if(r.mcpTools?.length)for(let g of r.mcpTools)D.push({name:g.name,description:g.description,input_schema:g.input_schema}),E.add(g.name);let C=o.filter(g=>g.role!=="system").map(g=>({role:g.role,content:g.content})),B=[],G=0,F=0,A=0,O="",j,_=0;for(;_<i;){if(_++,u?.aborted)throw new Error("cancelled");d?.({type:"iteration_start",iteration:_}),b.step(_,`Agentic loop iteration (${D.length} tools available)`);let g,M=!!e.generateRawStream&&!!d;try{if(M){let T=null,U=null,v="";for await(let x of e.generateRawStream(C,t,D,m))x.type==="text_delta"?(v+=x.text,d?.({type:"text_delta",text:x.text})):x.type==="thinking_delta"?d?.({type:"thinking_delta",text:x.text}):x.type==="raw_result"?T=x.result:x.type==="error"&&(U=x.error);if(U&&!T)throw new Error(U);if(!T)throw new Error("generateRawStream returned no raw_result event");g=T,g._streamedText=v}else g=await e.generateRaw(C,t,D,m)}catch(T){if(T.message?.includes("not available"))return dt(r);throw T}G+=g.usage.input_tokens+g.usage.output_tokens,F+=g.usage.input_tokens,A+=g.usage.output_tokens;let P=g._streamedText;for(let T of g.content)T.type==="text"&&(O+=T.text,P===void 0&&d?.({type:"text_delta",text:T.text}));if(P!==void 0&&delete g._streamedText,g.stop_reason==="end_turn"||g.stop_reason==="max_tokens")break;if(g.stop_reason==="tool_use"){let T=g.content.filter(v=>v.type==="tool_use");if(T.length===0)break;C.push({role:"assistant",content:g.content});let U=[];for(let v of T){d?.({type:"tool_call",name:v.name,id:v.id,input:v.input}),b.step(_,`Tool call: ${v.name}`);let x;if(E.has(v.name)&&r.mcpDispatch){let h=await r.mcpDispatch(v.name,v.input);x={tool_use_id:v.id,content:h.content,is_error:h.isError}}else x=await I.execute({name:v.name,id:v.id,input:v.input});d?.({type:"tool_result",name:v.name,id:v.id,content:x.content.slice(0,200),is_error:x.is_error}),x.files?.length&&(B.push(...x.files),d?.({type:"files_created",files:x.files})),x.followUp&&(j=x.followUp),U.push({type:"tool_result",tool_use_id:x.tool_use_id,content:x.content,is_error:x.is_error})}if(C.push({role:"user",content:U}),j)break;continue}break}return d?.({type:"complete",iterations:_,totalTokens:G}),{files:B,content:O,followUp:j,tokensUsed:G,inputTokens:F||void 0,outputTokens:A||void 0,iterations:_}}async function dt(r){let{provider:e,systemPrompt:t,messages:o,providerOptions:n,maxIterations:s=5}=r,c=[{role:"system",content:t+`
@@ -123,4 +123,4 @@ ${r.projectInstructions}`),r.memoryContext&&o.push(r.memoryContext),o.push(`# Ou
123
123
  Generate output appropriate for: ${e}. Use the \`create_files\` tool to output all files.`),o.join(`
124
124
 
125
125
  `)}export{qe as a,Vt as b,Yt as c,We as d,ze as e,Ve as f,Ye as g,Pe as h,ee as i,Re as j,le as k,te as l,Tt as m,oe as n,Mt as o,f as p,et as q,tt as r,Me as s,de as t,W as u,ne as v,it as w,Ee as x,$e as y,se as z,mt as A,Zn as B,er as C};
126
- //# sourceMappingURL=chunk-ZDDJNKU5.js.map
126
+ //# sourceMappingURL=chunk-3FCYKGU6.js.map
@@ -0,0 +1,11 @@
1
+ import{a as h,b as m}from"./chunk-SHEUCITK.js";import{randomUUID as C}from"crypto";var w=["ringing","answered","later"],p=`id, agent_id AS agentId, kind, reason, urgency, status, created_at AS createdAt,
2
+ ringing_since AS ringingSince, answered_at AS answeredAt, ended_at AS endedAt,
3
+ ring_again_at AS ringAgainAt, note, summary, channel, chat_id AS chatId`,f=class{constructor(e){this.db=e;e.exec(`CREATE TABLE IF NOT EXISTS calls (
4
+ id TEXT PRIMARY KEY, agent_id TEXT NOT NULL, reason TEXT NOT NULL,
5
+ urgency TEXT NOT NULL, status TEXT NOT NULL, created_at INTEGER NOT NULL,
6
+ ringing_since INTEGER, answered_at INTEGER, ended_at INTEGER,
7
+ ring_again_at INTEGER, note TEXT, summary TEXT);
8
+ CREATE INDEX IF NOT EXISTS calls_recent ON calls(created_at DESC);`);let s=new Set(e.prepare("PRAGMA table_info(calls)").all().map(n=>n.name));s.has("kind")||e.exec("ALTER TABLE calls ADD COLUMN kind TEXT NOT NULL DEFAULT 'voice'"),s.has("channel")||e.exec("ALTER TABLE calls ADD COLUMN channel TEXT"),s.has("chat_id")||e.exec("ALTER TABLE calls ADD COLUMN chat_id TEXT")}insert(e){this.db.prepare(`INSERT INTO calls (id, agent_id, kind, reason, urgency, status, created_at, ringing_since,
9
+ answered_at, ended_at, ring_again_at, note, summary, channel, chat_id) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`).run(e.id,e.agentId,e.kind,e.reason,e.urgency,e.status,e.createdAt,e.ringingSince,e.answeredAt,e.endedAt,e.ringAgainAt,e.note,e.summary,e.channel,e.chatId)}get(e){return this.db.prepare(`SELECT ${p} FROM calls WHERE id=?`).get(e)}update(e,s){let n={reason:"reason",urgency:"urgency",status:"status",ringingSince:"ringing_since",answeredAt:"answered_at",endedAt:"ended_at",ringAgainAt:"ring_again_at",note:"note",summary:"summary"},t=Object.keys(s).filter(i=>i in n);if(t.length){let i=t.map(r=>`${n[r]}=?`).join(", ");this.db.prepare(`UPDATE calls SET ${i} WHERE id=?`).run(...t.map(r=>s[r]??null),e)}return this.get(e)}transition(e,s,n){let t=Array.isArray(s)?s:[s],i={status:"status",ringingSince:"ringing_since",answeredAt:"answered_at",endedAt:"ended_at",ringAgainAt:"ring_again_at",note:"note",summary:"summary"},r=Object.keys(n).filter(o=>o in i),l=r.map(o=>`${i[o]}=?`).join(", "),g=t.map(()=>"?").join(",");return this.db.prepare(`UPDATE calls SET ${l} WHERE id=? AND status IN (${g})`).run(...r.map(o=>n[o]??null),e,...t).changes?this.get(e):void 0}list(e={}){let s=Math.min(Math.max(e.limit??50,1),200),n=[],t=[];e.status?.length&&(n.push(`status IN (${e.status.map(()=>"?").join(",")})`),t.push(...e.status)),e.kind&&(n.push("kind=?"),t.push(e.kind));let i=n.length?`WHERE ${n.join(" AND ")}`:"";return this.db.prepare(`SELECT ${p} FROM calls ${i} ORDER BY created_at DESC, rowid DESC LIMIT ?`).all(...t,s)}countSince(e,s){return this.db.prepare("SELECT COUNT(*) AS n FROM calls WHERE agent_id=? AND created_at>?").get(e,s).n}};var A=200,S=1e4,k=10*6e4,_=10,y=240;function v(a=process.env){return a.AGENTX_TASK_ID?{"X-AgentX-Task":a.AGENTX_TASK_ID}:a.AGENTX_CHANNEL&&a.AGENTX_CHAT_ID?{"X-AgentX-Channel":a.AGENTX_CHANNEL,"X-AgentX-Chat":a.AGENTX_CHAT_ID}:{}}function I(a){return`[Call answered] The owner just picked up the voice call you asked for. You called because: "${a.reason}". Speak first: greet them in a few words and say why you called, then let them answer.`}var x="[Call ended] The owner hung up. In two or three plain sentences, summarise what was said and decided on this call, for your records. Reply with the summary only.",T=class{constructor(e){this.deps=e}widgetSeenAt=0;waiting=new Map;now(){return this.deps.now?.()??Date.now()}name(e){return this.deps.agentName(e)??e}async request(e,s={}){let n=String(e.agentId??"").trim(),t=String(e.reason??"").replace(/\s+/g," ").trim(),i=e.urgency==="urgent"?"urgent":"normal",r=e.kind==="camera"?"camera":"voice";if(e.kind!==void 0&&e.kind!=="voice"&&e.kind!=="camera")return{ok:!1,status:400,error:"kind must be voice or camera"};if(!n||!t)return{ok:!1,status:400,error:"Required: agentId and reason"};if(t.length>A)return{ok:!1,status:413,error:`reason is over ${A} characters; keep it to one line`};if(this.deps.agentName(n)===null)return{ok:!1,status:404,error:`Unknown agent: ${n}`};if(!this.deps.isRunningTurn(n,s))return{ok:!1,status:403,error:`No running turn of ${n} placed this call. An agent calls from inside its own run.`};let l=this.deps.config();if(!l.allow.includes("*")&&!l.allow.includes(n))return{ok:!1,status:403,error:`${n} ${r==="camera"?"may not ask to see through the owner's camera":"may not call the owner"}. Add it to calls.allow in agentx.json (or: agentx call allow ${n}).`};if(await this.sweep(),this.deps.store.list({status:w,limit:200}).some(u=>u.agentId===n))return{ok:!1,status:409,error:`${n} already has a call in progress`};let g=this.now();if(this.deps.store.countSince(n,g-36e5)>=l.maxPerHour)return{ok:!1,status:429,error:`${n} has placed ${l.maxPerHour} calls in the last hour (calls.maxPerHour)`};let d=r==="camera"?this.deps.turnSession?.(n,s)??s:{},o={id:`call-${C().slice(0,8)}`,agentId:n,kind:r,reason:t,urgency:i,status:"ringing",createdAt:g,ringingSince:g,answeredAt:null,endedAt:null,ringAgainAt:null,note:null,summary:null,channel:d.channel&&d.chatId?d.channel:null,chatId:d.channel&&d.chatId?d.chatId:null};this.deps.store.insert(o),this.deps.log?.(`[calls] ${n} asks ${r==="camera"?"to see":"for a call"} (${i}): ${t}`);let E=await this.ring(o);return{ok:!0,call:this.deps.store.get(o.id),rang:E}}async ring(e){let s=(this.deps.focus??h)();return s.active&&e.urgency!=="urgent"?(this.deps.store.transition(e.id,"ringing",{status:"missed",ringingSince:null,note:m(s)})&&await this.notice(e,this.missedTitle(e)),!1):e.kind==="camera"?(await this.notice(e,`${this.name(e.agentId)} wants to see through your camera`,`Open the phone app and tap Show within ${this.deps.config().ringSeconds} s.`),"notify"):this.widgetAlive()?"widget":(await this.notice(e,`${this.name(e.agentId)} is calling`,`Open AgentX Voice to answer within ${this.deps.config().ringSeconds} s.`),"notify")}async notice(e,s,n){try{await this.deps.alert({title:s,message:n?`${e.reason}
10
+ ${n}`:e.reason,urgent:e.urgency==="urgent",from:e.agentId})}catch(t){this.deps.log?.(`[calls] notice for ${e.id} failed: ${t?.message??t}`)}}missedTitle(e){return e.kind==="camera"?`${this.name(e.agentId)} asked to see through your camera`:`Missed call from ${this.name(e.agentId)}`}widgetAlive(){return this.now()-this.widgetSeenAt<S}async ringing(e={}){return this.widgetSeenAt=this.now(),await this.hold(e),await this.sweep(),this.deps.store.list({status:["ringing"],kind:"voice",limit:20}).reverse()}async hold(e){let s=this.now(),n=this.deps.store.list({status:["ringing"],kind:"voice",limit:20});for(let t of this.waiting.keys())n.some(i=>i.id===t)||this.waiting.delete(t);for(let t of n){if(t.id===e.showing){this.waiting.delete(t.id)&&this.deps.store.transition(t.id,"ringing",{ringingSince:s});continue}if(!e.busy)continue;let i=this.waiting.get(t.id);i!==void 0&&s-i>=k||!this.deps.store.transition(t.id,"ringing",{ringingSince:s})||i!==void 0||(this.waiting.set(t.id,s),this.deps.log?.(`[calls] ${t.id} from ${t.agentId} waits: the widget is busy`),await this.notice(t,`${this.name(t.agentId)} is calling`,"AgentX Voice is busy. The call rings when it is free."))}}async asking(){return await this.sweep(),this.deps.store.list({status:["ringing"],kind:"camera",limit:20}).reverse()}async sweep(){let e=this.now(),s=this.deps.config().ringSeconds*1e3,n=this.deps.config().maxCallMinutes*6e4;for(let t of this.deps.store.list({status:["ringing","later","answered"],limit:200}))if(t.status==="ringing"&&t.ringingSince!==null&&e-t.ringingSince>=s){if(!this.deps.store.transition(t.id,"ringing",{status:"missed",ringingSince:null,note:this.waiting.has(t.id)?"widget busy":"not answered"}))continue;this.deps.log?.(`[calls] ${t.id} from ${t.agentId} missed`),await this.notice(t,this.missedTitle(t))}else if(t.status==="answered"&&t.answeredAt!==null&&e-t.answeredAt>=n){if(!this.deps.store.transition(t.id,"answered",{status:"ended",endedAt:e,note:"no hang-up"}))continue;this.deps.log?.(`[calls] ${t.id} from ${t.agentId} ended: no hang-up in ${this.deps.config().maxCallMinutes} min`)}else if(t.status==="later"&&t.ringAgainAt!==null&&e>=t.ringAgainAt){let i=this.deps.store.transition(t.id,"later",{status:"ringing",ringingSince:e,ringAgainAt:null});i&&await this.ring(i)}}answer(e){let s=this.deps.store.get(e);if(!s)return c(e);let n=this.deps.store.transition(e,"ringing",{status:"answered",answeredAt:this.now(),ringingSince:null});return n?(this.deps.log?.(`[calls] ${e} answered (${s.agentId})`),n.kind==="camera"?{ok:!0,call:n}:{ok:!0,call:n,opener:I(n)}):{ok:!1,status:409,error:`call is ${this.deps.store.get(e)?.status}, not ringing`}}decline(e){if(!this.deps.store.get(e))return c(e);let n=this.deps.store.transition(e,["ringing","later"],{status:"declined",endedAt:this.now(),ringingSince:null,ringAgainAt:null});return n?{ok:!0,call:n}:{ok:!1,status:409,error:`call is ${this.deps.store.get(e)?.status}`}}later(e,s){if(!this.deps.store.get(e))return c(e);let t=s===void 0?_:Number(s);if(!Number.isInteger(t)||t<1||t>y)return{ok:!1,status:400,error:`minutes must be a whole number from 1 to ${y}`};let i=this.deps.store.transition(e,"ringing",{status:"later",ringingSince:null,ringAgainAt:this.now()+t*6e4});return i?{ok:!0,call:i}:{ok:!1,status:409,error:`call is ${this.deps.store.get(e)?.status}, not ringing`}}hangup(e){let s=this.deps.store.get(e);if(!s)return c(e);let n=this.deps.store.transition(e,"answered",{status:"ended",endedAt:this.now()});if(!n)return{ok:!1,status:409,error:`call is ${s.status}, not answered`};this.deps.log?.(`[calls] ${e} ended (${s.agentId})`);let t=this.deps.summarize;if(n.kind==="camera"||!this.deps.config().summary||!t)return{ok:!0,call:n};let i=(async()=>{try{let r=(await t(n))?.trim();if(!r)return;let l=this.deps.store.update(e,{summary:r});this.deps.file?.(l,r)}catch(r){this.deps.log?.(`[calls] summary for ${e} failed: ${r?.message??r}`)}})();return{ok:!0,call:n,summarized:i}}endCamera(e,s){let n=this.deps.store.get(e);if(!n||n.kind!=="camera")return!1;let t=this.deps.store.transition(e,"answered",{status:"ended",endedAt:this.now(),note:s??null});return t&&this.deps.log?.(`[calls] ${e} ended (${n.agentId}): ${s??"share over"}`),!!t}get(e){return this.deps.store.get(e)}list(e={}){return this.deps.store.list(e)}},c=a=>({ok:!1,status:404,error:`No such call: ${a}`});export{f as a,v as b,x as c,T as d};
11
+ //# sourceMappingURL=chunk-LLNPKE7H.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/calls/service.ts","../src/calls/store.ts"],"sourcesContent":["// --- An agent rings the owner (#321) ---\n//\n// An agent that needs the owner directly asks for a call. It rings on the\n// desktop widget (AgentX Voice), which polls `ringing()`. Answering starts\n// the widget's hands-free conversation with that agent, which opens with\n// its reason. When the widget is not running, `notify` stands in. While\n// the widget is busy (a turn, the microphone, another call) the call waits\n// for it: its ring time does not run, and the owner is told once (#408).\n//\n// Checked before anything rings, in this order:\n// 0. the caller is that agent: a turn of it is running now, named by its\n// task id or by its channel and chat (see CallerProof),\n// 1. the owner allows this agent (calls.allow; empty allows nobody),\n// 2. the agent has no other call in progress,\n// 3. it is under calls.maxPerHour,\n// 4. Focus: a non-urgent call does not ring. It becomes a missed call,\n// and its notice goes through notify, which holds it until Focus\n// ends. Urgent calls ring through, as `notify --urgent` does.\n//\n// A camera ask (#325 phase 3, kind \"camera\") goes through the same checks\n// and the same table. It never rings the widget: the notice goes to the\n// phone through notify, and the phone app polls `asking()` to show a\n// Show / Decline bar. Answering it is the owner tapping Show; the camera\n// opens only then, and the share ends the ask (see camera-api.ts).\n\nimport { randomUUID } from \"crypto\"\nimport { focusLabel, readFocus, type FocusState } from \"@/notify/focus\"\nimport type { CallsConfig } from \"@/daemon/config\"\nimport { LIVE, type Call, type CallKind, type CallStore, type CallUrgency } from \"./store\"\n\nexport const REASON_MAX = 200\n/** The widget polls every 2 s; missing this long means it is not running. */\nexport const WIDGET_FRESH_MS = 10_000\n/** The longest a call waits for a busy widget before its ring time runs. */\nexport const BUSY_WAIT_MAX_MS = 10 * 60_000\nexport const LATER_DEFAULT_MINUTES = 10\nexport const LATER_MAX_MINUTES = 240\n\nexport type CallResult =\n | { ok: true; call: Call }\n | { ok: false; status: number; error: string }\n\n/** What the request says about the turn placing it: the run's\n * AGENTX_TASK_ID, or, for a warm process that has none, its\n * AGENTX_CHANNEL and AGENTX_CHAT_ID. Loopback is not an identity. */\nexport interface CallerProof {\n taskId?: string\n channel?: string\n chatId?: string\n}\n\n/** The proof headers for a call placed from inside an agent's run. */\nexport function callerHeaders(env: NodeJS.ProcessEnv = process.env): Record<string, string> {\n if (env.AGENTX_TASK_ID) return { \"X-AgentX-Task\": env.AGENTX_TASK_ID }\n if (env.AGENTX_CHANNEL && env.AGENTX_CHAT_ID) {\n return { \"X-AgentX-Channel\": env.AGENTX_CHANNEL, \"X-AgentX-Chat\": env.AGENTX_CHAT_ID }\n }\n return {}\n}\n\n/** What the widget says with its poll. A widget from before #408 says nothing. */\nexport interface WidgetState {\n /** It cannot ring a new call now. */\n busy?: boolean\n /** The call ringing on it. */\n showing?: string\n}\n\nexport interface CallDeps {\n store: CallStore\n config: () => CallsConfig\n /** The agent's display name, or null when there is no such agent here. */\n agentName: (agentId: string) => string | null\n /** True when `proof` names a running turn of `agentId`. */\n isRunningTurn: (agentId: string, proof: CallerProof) => boolean\n /** The channel and chat of that running turn, when it has one, so a\n * camera ask is answered where it was asked. Unset: only a proof that\n * names them itself is kept. */\n turnSession?: (agentId: string, proof: CallerProof) => { channel?: string; chatId?: string } | null\n /** Tell the owner through notify. `urgent` passes Focus, like notify --urgent. */\n alert: (notice: { title: string; message: string; urgent: boolean; from: string }) => Promise<void>\n /** Ask the agent, in its voice session, to summarise the call. */\n summarize?: (call: Call) => Promise<string | null>\n /** File a finished summary where the dashboard shows it. */\n file?: (call: Call, summary: string) => void\n focus?: () => FocusState\n now?: () => number\n log?: (m: string) => void\n}\n\n/** What the widget sends through /ask when the owner answers, so the\n * agent speaks first and says why it called. */\nexport function openerPrompt(call: Pick<Call, \"reason\">): string {\n return \"[Call answered] The owner just picked up the voice call you asked for. \" +\n `You called because: \"${call.reason}\". Speak first: greet them in a few words ` +\n \"and say why you called, then let them answer.\"\n}\n\nexport const SUMMARY_PROMPT =\n \"[Call ended] The owner hung up. In two or three plain sentences, summarise what \" +\n \"was said and decided on this call, for your records. Reply with the summary only.\"\n\nexport class CallService {\n private widgetSeenAt = 0\n /** Calls waiting for a busy widget, and since when. */\n private waiting = new Map<string, number>()\n\n constructor(private deps: CallDeps) {}\n\n private now(): number { return this.deps.now?.() ?? Date.now() }\n private name(agentId: string): string { return this.deps.agentName(agentId) ?? agentId }\n\n /** An agent asks for a call, or to see (kind \"camera\"). 201 ringing,\n * 202 held as missed (Focus). */\n async request(input: { agentId?: unknown; reason?: unknown; urgency?: unknown; kind?: unknown }, proof: CallerProof = {}): Promise<CallResult & { rang?: \"widget\" | \"notify\" | false }> {\n const agentId = String(input.agentId ?? \"\").trim()\n const reason = String(input.reason ?? \"\").replace(/\\s+/g, \" \").trim()\n const urgency: CallUrgency = input.urgency === \"urgent\" ? \"urgent\" : \"normal\"\n const kind: CallKind = input.kind === \"camera\" ? \"camera\" : \"voice\"\n if (input.kind !== undefined && input.kind !== \"voice\" && input.kind !== \"camera\") return { ok: false, status: 400, error: \"kind must be voice or camera\" }\n if (!agentId || !reason) return { ok: false, status: 400, error: \"Required: agentId and reason\" }\n if (reason.length > REASON_MAX) return { ok: false, status: 413, error: `reason is over ${REASON_MAX} characters; keep it to one line` }\n if (this.deps.agentName(agentId) === null) return { ok: false, status: 404, error: `Unknown agent: ${agentId}` }\n if (!this.deps.isRunningTurn(agentId, proof)) {\n return { ok: false, status: 403, error: `No running turn of ${agentId} placed this call. An agent calls from inside its own run.` }\n }\n\n const cfg = this.deps.config()\n if (!cfg.allow.includes(\"*\") && !cfg.allow.includes(agentId)) {\n const verb = kind === \"camera\" ? \"may not ask to see through the owner's camera\" : \"may not call the owner\"\n return { ok: false, status: 403, error: `${agentId} ${verb}. Add it to calls.allow in agentx.json (or: agentx call allow ${agentId}).` }\n }\n await this.sweep()\n if (this.deps.store.list({ status: LIVE, limit: 200 }).some((c) => c.agentId === agentId)) {\n return { ok: false, status: 409, error: `${agentId} already has a call in progress` }\n }\n const now = this.now()\n if (this.deps.store.countSince(agentId, now - 3_600_000) >= cfg.maxPerHour) {\n return { ok: false, status: 429, error: `${agentId} has placed ${cfg.maxPerHour} calls in the last hour (calls.maxPerHour)` }\n }\n\n // Where the ask came from, for kind \"camera\": the turn's own chat, or\n // the one the proof names. A task run has neither.\n const session: { channel?: string; chatId?: string } = kind === \"camera\" ? (this.deps.turnSession?.(agentId, proof) ?? proof) : {}\n const call: Call = {\n id: `call-${randomUUID().slice(0, 8)}`, agentId, kind, reason, urgency, status: \"ringing\", createdAt: now,\n ringingSince: now, answeredAt: null, endedAt: null, ringAgainAt: null, note: null, summary: null,\n channel: session.channel && session.chatId ? session.channel : null,\n chatId: session.channel && session.chatId ? session.chatId : null,\n }\n this.deps.store.insert(call)\n this.deps.log?.(`[calls] ${agentId} asks ${kind === \"camera\" ? \"to see\" : \"for a call\"} (${urgency}): ${reason}`)\n const rang = await this.ring(call)\n const saved = this.deps.store.get(call.id)!\n return { ok: true, call: saved, rang }\n }\n\n /** Ring now, or hold as missed in Focus. Returns how it rang. */\n private async ring(call: Call): Promise<\"widget\" | \"notify\" | false> {\n const focus = (this.deps.focus ?? readFocus)()\n if (focus.active && call.urgency !== \"urgent\") {\n if (!this.deps.store.transition(call.id, \"ringing\", { status: \"missed\", ringingSince: null, note: focusLabel(focus) })) return false\n await this.notice(call, this.missedTitle(call))\n return false\n }\n // A camera ask is answered on the phone, never on the widget.\n if (call.kind === \"camera\") {\n await this.notice(call, `${this.name(call.agentId)} wants to see through your camera`,\n `Open the phone app and tap Show within ${this.deps.config().ringSeconds} s.`)\n return \"notify\"\n }\n if (this.widgetAlive()) return \"widget\"\n await this.notice(call, `${this.name(call.agentId)} is calling`,\n `Open AgentX Voice to answer within ${this.deps.config().ringSeconds} s.`)\n return \"notify\"\n }\n\n private async notice(call: Call, title: string, extra?: string): Promise<void> {\n try {\n await this.deps.alert({\n title, message: extra ? `${call.reason}\\n${extra}` : call.reason,\n urgent: call.urgency === \"urgent\", from: call.agentId,\n })\n } catch (e: any) {\n this.deps.log?.(`[calls] notice for ${call.id} failed: ${e?.message ?? e}`)\n }\n }\n\n private missedTitle(call: Call): string {\n return call.kind === \"camera\" ? `${this.name(call.agentId)} asked to see through your camera` : `Missed call from ${this.name(call.agentId)}`\n }\n\n /** True when the widget polled recently. */\n widgetAlive(): boolean {\n return this.now() - this.widgetSeenAt < WIDGET_FRESH_MS\n }\n\n /** The widget's poll: voice calls ringing now, oldest first. Marks it alive. */\n async ringing(widget: WidgetState = {}): Promise<Call[]> {\n this.widgetSeenAt = this.now()\n await this.hold(widget)\n await this.sweep()\n return this.deps.store.list({ status: [\"ringing\"], kind: \"voice\", limit: 20 }).reverse()\n }\n\n /** A busy widget cannot ring: the ring time of each call it is not\n * showing starts over at every poll, for BUSY_WAIT_MAX_MS at most, and\n * the owner is told once that the call waits. It starts over once more\n * when the widget first shows a call that waited. */\n private async hold(widget: WidgetState): Promise<void> {\n const now = this.now()\n const live = this.deps.store.list({ status: [\"ringing\"], kind: \"voice\", limit: 20 })\n for (const id of this.waiting.keys()) if (!live.some((c) => c.id === id)) this.waiting.delete(id)\n for (const call of live) {\n if (call.id === widget.showing) {\n if (this.waiting.delete(call.id)) this.deps.store.transition(call.id, \"ringing\", { ringingSince: now })\n continue\n }\n if (!widget.busy) continue\n const since = this.waiting.get(call.id)\n if (since !== undefined && now - since >= BUSY_WAIT_MAX_MS) continue\n if (!this.deps.store.transition(call.id, \"ringing\", { ringingSince: now }) || since !== undefined) continue\n this.waiting.set(call.id, now)\n this.deps.log?.(`[calls] ${call.id} from ${call.agentId} waits: the widget is busy`)\n await this.notice(call, `${this.name(call.agentId)} is calling`, \"AgentX Voice is busy. The call rings when it is free.\")\n }\n }\n\n /** The phone app's poll: camera asks waiting for the owner, oldest first.\n * Does not count as the widget being up. */\n async asking(): Promise<Call[]> {\n await this.sweep()\n return this.deps.store.list({ status: [\"ringing\"], kind: \"camera\", limit: 20 }).reverse()\n }\n\n /** Unanswered calls become missed; \"later\" calls that came due ring\n * again; answered calls nobody hung up end after calls.maxCallMinutes. */\n async sweep(): Promise<void> {\n const now = this.now()\n const ringFor = this.deps.config().ringSeconds * 1000\n const talkFor = this.deps.config().maxCallMinutes * 60_000\n for (const call of this.deps.store.list({ status: [\"ringing\", \"later\", \"answered\"], limit: 200 })) {\n // The list was read before any await below: each move re-checks the\n // status in the store, so a call answered meanwhile is left alone.\n if (call.status === \"ringing\" && call.ringingSince !== null && now - call.ringingSince >= ringFor) {\n if (!this.deps.store.transition(call.id, \"ringing\", { status: \"missed\", ringingSince: null, note: this.waiting.has(call.id) ? \"widget busy\" : \"not answered\" })) continue\n this.deps.log?.(`[calls] ${call.id} from ${call.agentId} missed`)\n await this.notice(call, this.missedTitle(call))\n } else if (call.status === \"answered\" && call.answeredAt !== null && now - call.answeredAt >= talkFor) {\n if (!this.deps.store.transition(call.id, \"answered\", { status: \"ended\", endedAt: now, note: \"no hang-up\" })) continue\n this.deps.log?.(`[calls] ${call.id} from ${call.agentId} ended: no hang-up in ${this.deps.config().maxCallMinutes} min`)\n } else if (call.status === \"later\" && call.ringAgainAt !== null && now >= call.ringAgainAt) {\n const again = this.deps.store.transition(call.id, \"later\", { status: \"ringing\", ringingSince: now, ringAgainAt: null })\n if (again) await this.ring(again)\n }\n }\n }\n\n /** The owner picked up, or tapped Show. Returns the call and, for a\n * voice call, the opener for /ask. */\n answer(id: string): CallResult & { opener?: string } {\n const call = this.deps.store.get(id)\n if (!call) return unknown(id)\n const answered = this.deps.store.transition(id, \"ringing\", { status: \"answered\", answeredAt: this.now(), ringingSince: null })\n if (!answered) return { ok: false, status: 409, error: `call is ${this.deps.store.get(id)?.status}, not ringing` }\n this.deps.log?.(`[calls] ${id} answered (${call.agentId})`)\n return answered.kind === \"camera\" ? { ok: true, call: answered } : { ok: true, call: answered, opener: openerPrompt(answered) }\n }\n\n decline(id: string): CallResult {\n const call = this.deps.store.get(id)\n if (!call) return unknown(id)\n const declined = this.deps.store.transition(id, [\"ringing\", \"later\"], { status: \"declined\", endedAt: this.now(), ringingSince: null, ringAgainAt: null })\n return declined ? { ok: true, call: declined } : { ok: false, status: 409, error: `call is ${this.deps.store.get(id)?.status}` }\n }\n\n /** \"Call back in N min\": it rings again then. */\n later(id: string, minutes?: unknown): CallResult {\n const call = this.deps.store.get(id)\n if (!call) return unknown(id)\n const n = minutes === undefined ? LATER_DEFAULT_MINUTES : Number(minutes)\n if (!Number.isInteger(n) || n < 1 || n > LATER_MAX_MINUTES) {\n return { ok: false, status: 400, error: `minutes must be a whole number from 1 to ${LATER_MAX_MINUTES}` }\n }\n const later = this.deps.store.transition(id, \"ringing\", { status: \"later\", ringingSince: null, ringAgainAt: this.now() + n * 60_000 })\n return later ? { ok: true, call: later } : { ok: false, status: 409, error: `call is ${this.deps.store.get(id)?.status}, not ringing` }\n }\n\n /** End an answered call. The summary is written in the background;\n * `summarized` settles when it is filed (tests wait on it). */\n hangup(id: string): CallResult & { summarized?: Promise<void> } {\n const call = this.deps.store.get(id)\n if (!call) return unknown(id)\n const ended = this.deps.store.transition(id, \"answered\", { status: \"ended\", endedAt: this.now() })\n if (!ended) return { ok: false, status: 409, error: `call is ${call.status}, not answered` }\n this.deps.log?.(`[calls] ${id} ended (${call.agentId})`)\n const summarize = this.deps.summarize\n // What the agent saw is already its answer; only a voice call is summarised.\n if (ended.kind === \"camera\" || !this.deps.config().summary || !summarize) return { ok: true, call: ended }\n const summarized = (async () => {\n try {\n const text = (await summarize(ended))?.trim()\n if (!text) return\n const done = this.deps.store.update(id, { summary: text })!\n this.deps.file?.(done, text)\n } catch (e: any) {\n this.deps.log?.(`[calls] summary for ${id} failed: ${e?.message ?? e}`)\n }\n })()\n return { ok: true, call: ended, summarized }\n }\n\n /** A camera ask ends when the share ends; no summary. Only an answered\n * ask ends this way, so a stop before Show leaves it ringing. */\n endCamera(id: string, note?: string): boolean {\n const call = this.deps.store.get(id)\n if (!call || call.kind !== \"camera\") return false\n const ended = this.deps.store.transition(id, \"answered\", { status: \"ended\", endedAt: this.now(), note: note ?? null })\n if (ended) this.deps.log?.(`[calls] ${id} ended (${call.agentId}): ${note ?? \"share over\"}`)\n return !!ended\n }\n\n get(id: string): Call | undefined { return this.deps.store.get(id) }\n\n list(opts: Parameters<CallStore[\"list\"]>[0] = {}): Call[] { return this.deps.store.list(opts) }\n}\n\nconst unknown = (id: string): CallResult => ({ ok: false, status: 404, error: `No such call: ${id}` })\n","// --- Calls an agent placed to the owner, kept in SQLite ---\n//\n// One row per call, so a missed call is still there after a restart and\n// the dashboard can list them. Nothing else reads this table. A camera\n// ask (#325 phase 3: \"show me\") is a call of kind \"camera\": same\n// allowlist, same hourly limit, same lifecycle, answered on the phone\n// instead of the voice widget.\n\nimport type Database from \"better-sqlite3\"\n\nexport type CallStatus = \"ringing\" | \"answered\" | \"ended\" | \"declined\" | \"missed\" | \"later\"\nexport type CallUrgency = \"normal\" | \"urgent\"\n/** \"voice\": a live voice call on the widget. \"camera\": the agent asks to see through the phone camera. */\nexport type CallKind = \"voice\" | \"camera\"\n\nexport interface Call {\n id: string\n agentId: string\n kind: CallKind\n reason: string\n urgency: CallUrgency\n status: CallStatus\n /** The channel and chat the asking turn ran in, so what the agent sees\n * is answered there; null when the turn had none (a task run). */\n channel: string | null\n chatId: string | null\n /** When the agent asked, ms since the epoch. */\n createdAt: number\n /** When it last started ringing: at the request, or when \"later\" came due. */\n ringingSince: number | null\n answeredAt: number | null\n endedAt: number | null\n /** Status \"later\": when it rings again. */\n ringAgainAt: number | null\n /** Why it ended the way it did, in a few words (\"in Focus\", \"not answered\"). */\n note: string | null\n /** The agent's own summary, written after hang-up. */\n summary: string | null\n}\n\n/** Calls still in progress: an agent has at most one of these. */\nexport const LIVE: CallStatus[] = [\"ringing\", \"answered\", \"later\"]\n\nconst COLUMNS = `id, agent_id AS agentId, kind, reason, urgency, status, created_at AS createdAt,\n ringing_since AS ringingSince, answered_at AS answeredAt, ended_at AS endedAt,\n ring_again_at AS ringAgainAt, note, summary, channel, chat_id AS chatId`\n\nexport class CallStore {\n constructor(private db: Database.Database) {\n db.exec(`CREATE TABLE IF NOT EXISTS calls (\n id TEXT PRIMARY KEY, agent_id TEXT NOT NULL, reason TEXT NOT NULL,\n urgency TEXT NOT NULL, status TEXT NOT NULL, created_at INTEGER NOT NULL,\n ringing_since INTEGER, answered_at INTEGER, ended_at INTEGER,\n ring_again_at INTEGER, note TEXT, summary TEXT);\n CREATE INDEX IF NOT EXISTS calls_recent ON calls(created_at DESC);`)\n // Columns added since the table first shipped (#325 phase 3). A row\n // from before is a voice call from a turn whose chat was not kept.\n const have = new Set((db.prepare(\"PRAGMA table_info(calls)\").all() as Array<{ name: string }>).map((c) => c.name))\n if (!have.has(\"kind\")) db.exec(\"ALTER TABLE calls ADD COLUMN kind TEXT NOT NULL DEFAULT 'voice'\")\n if (!have.has(\"channel\")) db.exec(\"ALTER TABLE calls ADD COLUMN channel TEXT\")\n if (!have.has(\"chat_id\")) db.exec(\"ALTER TABLE calls ADD COLUMN chat_id TEXT\")\n }\n\n insert(call: Call): void {\n this.db.prepare(`INSERT INTO calls (id, agent_id, kind, reason, urgency, status, created_at, ringing_since,\n answered_at, ended_at, ring_again_at, note, summary, channel, chat_id) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`).run(\n call.id, call.agentId, call.kind, call.reason, call.urgency, call.status, call.createdAt,\n call.ringingSince, call.answeredAt, call.endedAt, call.ringAgainAt, call.note, call.summary, call.channel, call.chatId)\n }\n\n get(id: string): Call | undefined {\n return this.db.prepare(`SELECT ${COLUMNS} FROM calls WHERE id=?`).get(id) as Call | undefined\n }\n\n /** Write the changed fields of one call. */\n update(id: string, patch: Partial<Omit<Call, \"id\" | \"agentId\" | \"createdAt\">>): Call | undefined {\n const cols: Record<string, string> = {\n reason: \"reason\", urgency: \"urgency\", status: \"status\", ringingSince: \"ringing_since\",\n answeredAt: \"answered_at\", endedAt: \"ended_at\", ringAgainAt: \"ring_again_at\", note: \"note\", summary: \"summary\",\n }\n const keys = Object.keys(patch).filter((k) => k in cols)\n if (keys.length) {\n const set = keys.map((k) => `${cols[k]}=?`).join(\", \")\n this.db.prepare(`UPDATE calls SET ${set} WHERE id=?`).run(...keys.map((k) => (patch as any)[k] ?? null), id)\n }\n return this.get(id)\n }\n\n /** Change a call only if it is still `from`: the check and the write are\n * one statement, so two sweeps, or a sweep and the owner answering,\n * cannot both move the same call. Undefined when it had moved on. */\n transition(id: string, from: CallStatus | CallStatus[], patch: Partial<Omit<Call, \"id\" | \"agentId\" | \"createdAt\">>): Call | undefined {\n const statuses = Array.isArray(from) ? from : [from]\n const cols: Record<string, string> = {\n status: \"status\", ringingSince: \"ringing_since\", answeredAt: \"answered_at\", endedAt: \"ended_at\",\n ringAgainAt: \"ring_again_at\", note: \"note\", summary: \"summary\",\n }\n const keys = Object.keys(patch).filter((k) => k in cols)\n const set = keys.map((k) => `${cols[k]}=?`).join(\", \")\n const marks = statuses.map(() => \"?\").join(\",\")\n const changed = this.db.prepare(`UPDATE calls SET ${set} WHERE id=? AND status IN (${marks})`)\n .run(...keys.map((k) => (patch as any)[k] ?? null), id, ...statuses).changes\n return changed ? this.get(id) : undefined\n }\n\n /** Newest first; only these statuses, and only this kind, when given. */\n list(opts: { status?: CallStatus[]; kind?: CallKind; limit?: number } = {}): Call[] {\n const limit = Math.min(Math.max(opts.limit ?? 50, 1), 200)\n const where: string[] = []\n const args: unknown[] = []\n if (opts.status?.length) {\n where.push(`status IN (${opts.status.map(() => \"?\").join(\",\")})`)\n args.push(...opts.status)\n }\n if (opts.kind) { where.push(\"kind=?\"); args.push(opts.kind) }\n const filter = where.length ? `WHERE ${where.join(\" AND \")}` : \"\"\n return this.db.prepare(`SELECT ${COLUMNS} FROM calls ${filter} ORDER BY created_at DESC, rowid DESC LIMIT ?`)\n .all(...args, limit) as Call[]\n }\n\n /** Calls this agent placed after `since` (ms), for the hourly limit. */\n countSince(agentId: string, since: number): number {\n return (this.db.prepare(\"SELECT COUNT(*) AS n FROM calls WHERE agent_id=? AND created_at>?\")\n .get(agentId, since) as { n: number }).n\n }\n}\n"],"mappings":"+CAyBA,OAAS,cAAAA,MAAkB,SCgBpB,IAAMC,EAAqB,CAAC,UAAW,WAAY,OAAO,EAE3DC,EAAU;AAAA;AAAA,2EAIHC,EAAN,KAAgB,CACrB,YAAoBC,EAAuB,CAAvB,QAAAA,EAClBA,EAAG,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA,yEAK6D,EAGrE,IAAMC,EAAO,IAAI,IAAKD,EAAG,QAAQ,0BAA0B,EAAE,IAAI,EAA8B,IAAKE,GAAMA,EAAE,IAAI,CAAC,EAC5GD,EAAK,IAAI,MAAM,GAAGD,EAAG,KAAK,iEAAiE,EAC3FC,EAAK,IAAI,SAAS,GAAGD,EAAG,KAAK,2CAA2C,EACxEC,EAAK,IAAI,SAAS,GAAGD,EAAG,KAAK,2CAA2C,CAC/E,CAEA,OAAOG,EAAkB,CACvB,KAAK,GAAG,QAAQ;AAAA,oHACgG,EAAE,IAChHA,EAAK,GAAIA,EAAK,QAASA,EAAK,KAAMA,EAAK,OAAQA,EAAK,QAASA,EAAK,OAAQA,EAAK,UAC/EA,EAAK,aAAcA,EAAK,WAAYA,EAAK,QAASA,EAAK,YAAaA,EAAK,KAAMA,EAAK,QAASA,EAAK,QAASA,EAAK,MAAM,CAC1H,CAEA,IAAIC,EAA8B,CAChC,OAAO,KAAK,GAAG,QAAQ,UAAUN,yBAA+B,EAAE,IAAIM,CAAE,CAC1E,CAGA,OAAOA,EAAYC,EAA8E,CAC/F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O,EAAE,SAAW,CAACC,EAAW,MAAO,CAAE,GAAI,GAAM,KAAMD,CAAM,EACzG,IAAME,GAAc,SAAY,CAC9B,GAAI,CACF,IAAMC,GAAQ,MAAMF,EAAUD,CAAK,IAAI,KAAK,EAC5C,GAAI,CAACG,EAAM,OACX,IAAMC,EAAO,KAAK,KAAK,MAAM,OAAOf,EAAI,CAAE,QAASc,CAAK,CAAC,EACzD,KAAK,KAAK,OAAOC,EAAMD,CAAI,CAC7B,OAASjB,EAAP,CACA,KAAK,KAAK,MAAM,uBAAuBG,aAAcH,GAAG,SAAWA,GAAG,CACxE,CACF,GAAG,EACH,MAAO,CAAE,GAAI,GAAM,KAAMc,EAAO,WAAAE,CAAW,CAC7C,CAIA,UAAUb,EAAYgB,EAAwB,CAC5C,IAAMzC,EAAO,KAAK,KAAK,MAAM,IAAIyB,CAAE,EACnC,GAAI,CAACzB,GAAQA,EAAK,OAAS,SAAU,MAAO,GAC5C,IAAMoC,EAAQ,KAAK,KAAK,MAAM,WAAWX,EAAI,WAAY,CAAE,OAAQ,QAAS,QAAS,KAAK,IAAI,EAAG,KAAMgB,GAAQ,IAAK,CAAC,EACrH,OAAIL,GAAO,KAAK,KAAK,MAAM,WAAWX,YAAazB,EAAK,aAAayC,GAAQ,cAAc,EACpF,CAAC,CAACL,CACX,CAEA,IAAIX,EAA8B,CAAE,OAAO,KAAK,KAAK,MAAM,IAAIA,CAAE,CAAE,CAEnE,KAAKiB,EAAyC,CAAC,EAAW,CAAE,OAAO,KAAK,KAAK,MAAM,KAAKA,CAAI,CAAE,CAChG,EAEMZ,EAAWL,IAA4B,CAAE,GAAI,GAAO,OAAQ,IAAK,MAAO,iBAAiBA,GAAK","names":["randomUUID","LIVE","COLUMNS","CallStore","db","have","c","call","id","patch","cols","keys","k","set","from","statuses","marks","opts","limit","where","args","filter","agentId","since","REASON_MAX","WIDGET_FRESH_MS","BUSY_WAIT_MAX_MS","LATER_DEFAULT_MINUTES","LATER_MAX_MINUTES","callerHeaders","env","openerPrompt","call","SUMMARY_PROMPT","CallService","deps","agentId","input","proof","reason","urgency","kind","cfg","LIVE","c","now","session","randomUUID","rang","focus","readFocus","focusLabel","title","extra","e","widget","live","id","since","ringFor","talkFor","again","unknown","answered","declined","minutes","n","later","ended","summarize","summarized","text","done","note","opts"]}