MCPcopy Create free account
hub / github.com/calebwin/pgclaw / claw_process_one

Function claw_process_one

src/process.rs:15–131  ·  view source on GitHub ↗
(
    api_key: String,
    provider: default!(Option<String>, "NULL"),
    api_url: default!(Option<String>, "NULL"),
)

Source from the content-addressed store, hash-verified

13/// is not running.
14#[pg_extern]
15fn claw_process_one(
16 api_key: String,
17 provider: default!(Option<String>, "NULL"),
18 api_url: default!(Option<String>, "NULL"),
19) -> Option<String> {
20 let provider = provider.unwrap_or_else(crate::get_provider);
21 let api_url = api_url.or_else(crate::get_api_url);
22
23 // Claim one item
24 let item = Spi::connect(|mut client| {
25 let result = client
26 .update(
27 "UPDATE claw.queue
28 SET claimed_at = now()
29 WHERE id = (
30 SELECT id FROM claw.queue
31 WHERE claimed_at IS NULL
32 ORDER BY id
33 FOR UPDATE SKIP LOCKED
34 LIMIT 1
35 )
36 RETURNING id, table_oid, pk_value, claw_col, row_data::text,
37 event, claw_value, agent_type",
38 None,
39 None,
40 )
41 .expect("SPI failed");
42
43 let row = result.into_iter().next()?;
44
45 Some(QueueItem {
46 id: row.get::<i64>(1).ok()??,
47 table_oid: row.get::<pg_sys::Oid>(2).ok()??,
48 pk_value: row.get::<String>(3).ok()??,
49 claw_col: row.get::<String>(4).ok()??,
50 row_data: row.get::<String>(5).ok()??,
51 event: row.get::<String>(6).ok()??,
52 claw_value: row.get::<String>(7).ok()??,
53 agent_type: row.get::<String>(8).ok()??,
54 })
55 });
56
57 let item = match item {
58 Some(item) => item,
59 None => return None,
60 };
61
62 if item.agent_type == "claudecode" {
63 mark_done(&item, "skipped: claudecode agent type");
64 return Some("skipped: claudecode agent type".to_string());
65 }
66
67 // Resolve agent config
68 let (model, system_prompt) = match resolve_config(&item) {
69 Ok(v) => v,
70 Err(e) => {
71 mark_done(&item, &format!("error: {}", e));
72 return Some(format!("error: {}", e));

Callers

nothing calls this directly

Calls 6

mark_doneFunction · 0.85
resolve_configFunction · 0.85
load_historyFunction · 0.85
call_llmFunction · 0.85
extract_column_updatesFunction · 0.85
apply_updatesFunction · 0.85

Tested by

no test coverage detected