@defend-tech/opencode-optima 0.1.66 → 0.1.67
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/index.js +43 -5
- package/dist/sanitize_cli.js +43 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11593,17 +11593,49 @@ function clickUpWebhookExpectedPath(config) {
|
|
|
11593
11593
|
return "/";
|
|
11594
11594
|
}
|
|
11595
11595
|
}
|
|
11596
|
-
|
|
11596
|
+
function summarizeClickUpRouteForLog(result = {}, payload = {}) {
|
|
11597
|
+
return {
|
|
11598
|
+
taskId: result.taskId || clickUpTaskIdFromPayload(payload || {}) || null,
|
|
11599
|
+
event: clickUpEventType(payload || {}) || null,
|
|
11600
|
+
eventKey: result.eventKey || clickUpWebhookEventKey(payload || {}) || null,
|
|
11601
|
+
ok: result.ok === true,
|
|
11602
|
+
action: result.action || null,
|
|
11603
|
+
reason: result.reason || null,
|
|
11604
|
+
sessionId: result.sessionId || result.replacementSessionId || null,
|
|
11605
|
+
branch: result.branch || null,
|
|
11606
|
+
worktree: result.worktree || null
|
|
11607
|
+
};
|
|
11608
|
+
}
|
|
11609
|
+
function runClickUpWebhookRouteInBackground({ payload, config, state, worktree, clickupClient, openCodeClient, saveState, sessionExists, createSession, sendSessionEvent, ensureTaskWorktree, verifySessionEventDelivery, now } = {}) {
|
|
11610
|
+
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
11611
|
+
appendClickUpWebhookLocalLog(worktree, { type: "webhook_route_started", taskId: clickUpTaskIdFromPayload(payload || {}) || null, event: clickUpEventType(payload || {}) || null, eventKey: clickUpWebhookEventKey(payload || {}) || null, async: true, startedAt });
|
|
11612
|
+
const route = Promise.resolve().then(() => routeClickUpWebhookEvent({ payload, config, state, worktree, clickupClient, openCodeClient, saveState, sessionExists, createSession, sendSessionEvent, ensureTaskWorktree, verifySessionEventDelivery, now })).then((result) => {
|
|
11613
|
+
appendClickUpWebhookLocalLog(worktree, { type: "webhook_route_finished", async: true, ...summarizeClickUpRouteForLog(result, payload) });
|
|
11614
|
+
return result;
|
|
11615
|
+
}).catch((error) => {
|
|
11616
|
+
appendClickUpWebhookLocalLog(worktree, { type: "webhook_route_failed", taskId: clickUpTaskIdFromPayload(payload || {}) || null, event: clickUpEventType(payload || {}) || null, eventKey: clickUpWebhookEventKey(payload || {}) || null, async: true, message: error.message });
|
|
11617
|
+
return { ok: false, action: "error", reason: "background_route_failed", message: error.message };
|
|
11618
|
+
});
|
|
11619
|
+
route.catch(() => {
|
|
11620
|
+
});
|
|
11621
|
+
return route;
|
|
11622
|
+
}
|
|
11623
|
+
async function handleClickUpWebhookRequest({ method = "POST", url = null, headers = {}, rawBody = "", config, state, worktree, clickupClient, openCodeClient, saveState, now = () => /* @__PURE__ */ new Date(), sessionExists, createSession, sendSessionEvent, ensureTaskWorktree, verifySessionEventDelivery, asyncRouting = false } = {}) {
|
|
11597
11624
|
let payload = null;
|
|
11598
11625
|
let handled = null;
|
|
11599
11626
|
let authenticatedWebhook = false;
|
|
11600
11627
|
let receivedAt = null;
|
|
11601
11628
|
let activeState = state;
|
|
11629
|
+
let latestPersistedState = state;
|
|
11630
|
+
const persistState = (nextState) => {
|
|
11631
|
+
latestPersistedState = nextState;
|
|
11632
|
+
if (saveState) saveState(nextState);
|
|
11633
|
+
};
|
|
11602
11634
|
const finish = (result) => {
|
|
11603
11635
|
handled = result;
|
|
11604
11636
|
receivedAt ??= now();
|
|
11605
|
-
const auditState = authenticatedWebhook ? { ...
|
|
11606
|
-
if (saveState && authenticatedWebhook)
|
|
11637
|
+
const auditState = authenticatedWebhook ? { ...latestPersistedState, lastWebhookAt: receivedAt.toISOString() } : latestPersistedState;
|
|
11638
|
+
if (saveState && authenticatedWebhook) persistState(auditState);
|
|
11607
11639
|
writeClickUpWebhookAuditLog({ method, url, headers, rawBody, config, state: auditState, handled, payload, at: receivedAt });
|
|
11608
11640
|
return result;
|
|
11609
11641
|
};
|
|
@@ -11630,7 +11662,12 @@ async function handleClickUpWebhookRequest({ method = "POST", url = null, header
|
|
|
11630
11662
|
return finish({ ok: false, status: 400, reason: "invalid_json" });
|
|
11631
11663
|
}
|
|
11632
11664
|
const receivedState = { ...activeState, lastWebhookAt: receivedAt.toISOString() };
|
|
11633
|
-
|
|
11665
|
+
persistState(receivedState);
|
|
11666
|
+
if (asyncRouting) {
|
|
11667
|
+
runClickUpWebhookRouteInBackground({ payload, config, state: receivedState, worktree, clickupClient, openCodeClient, saveState: persistState, sessionExists, createSession, sendSessionEvent, ensureTaskWorktree, verifySessionEventDelivery, now });
|
|
11668
|
+
return finish({ ok: true, status: 200, reason: "accepted", result: { action: "accepted", taskId: clickUpTaskIdFromPayload(payload), eventKey: clickUpWebhookEventKey(payload) } });
|
|
11669
|
+
}
|
|
11670
|
+
const result = await routeClickUpWebhookEvent({ payload, config, state: receivedState, worktree, clickupClient, openCodeClient, saveState: persistState, sessionExists, createSession, sendSessionEvent, ensureTaskWorktree, verifySessionEventDelivery });
|
|
11634
11671
|
return finish({ ok: result.ok, status: result.ok ? 200 : 422, result });
|
|
11635
11672
|
} catch (error) {
|
|
11636
11673
|
writeClickUpWebhookAuditLog({ method, url, headers, rawBody, config, state, handled, error, payload, at: now() });
|
|
@@ -11707,7 +11744,8 @@ function startClickUpWebhookListener({ config, state, worktree, clickupClient, o
|
|
|
11707
11744
|
worktree,
|
|
11708
11745
|
clickupClient,
|
|
11709
11746
|
openCodeClient,
|
|
11710
|
-
saveState: (nextState) => writeClickUpWebhookState(worktree, nextState, config)
|
|
11747
|
+
saveState: (nextState) => writeClickUpWebhookState(worktree, nextState, config),
|
|
11748
|
+
asyncRouting: true
|
|
11711
11749
|
});
|
|
11712
11750
|
res.writeHead(handled.status, { "Content-Type": "application/json" });
|
|
11713
11751
|
res.end(JSON.stringify({ ok: handled.ok, reason: handled.reason, result: handled.result?.action }));
|
package/dist/sanitize_cli.js
CHANGED
|
@@ -11600,17 +11600,49 @@ function clickUpWebhookExpectedPath(config) {
|
|
|
11600
11600
|
return "/";
|
|
11601
11601
|
}
|
|
11602
11602
|
}
|
|
11603
|
-
|
|
11603
|
+
function summarizeClickUpRouteForLog(result = {}, payload = {}) {
|
|
11604
|
+
return {
|
|
11605
|
+
taskId: result.taskId || clickUpTaskIdFromPayload(payload || {}) || null,
|
|
11606
|
+
event: clickUpEventType(payload || {}) || null,
|
|
11607
|
+
eventKey: result.eventKey || clickUpWebhookEventKey(payload || {}) || null,
|
|
11608
|
+
ok: result.ok === true,
|
|
11609
|
+
action: result.action || null,
|
|
11610
|
+
reason: result.reason || null,
|
|
11611
|
+
sessionId: result.sessionId || result.replacementSessionId || null,
|
|
11612
|
+
branch: result.branch || null,
|
|
11613
|
+
worktree: result.worktree || null
|
|
11614
|
+
};
|
|
11615
|
+
}
|
|
11616
|
+
function runClickUpWebhookRouteInBackground({ payload, config, state, worktree, clickupClient, openCodeClient, saveState, sessionExists, createSession, sendSessionEvent, ensureTaskWorktree, verifySessionEventDelivery, now } = {}) {
|
|
11617
|
+
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
11618
|
+
appendClickUpWebhookLocalLog(worktree, { type: "webhook_route_started", taskId: clickUpTaskIdFromPayload(payload || {}) || null, event: clickUpEventType(payload || {}) || null, eventKey: clickUpWebhookEventKey(payload || {}) || null, async: true, startedAt });
|
|
11619
|
+
const route = Promise.resolve().then(() => routeClickUpWebhookEvent({ payload, config, state, worktree, clickupClient, openCodeClient, saveState, sessionExists, createSession, sendSessionEvent, ensureTaskWorktree, verifySessionEventDelivery, now })).then((result) => {
|
|
11620
|
+
appendClickUpWebhookLocalLog(worktree, { type: "webhook_route_finished", async: true, ...summarizeClickUpRouteForLog(result, payload) });
|
|
11621
|
+
return result;
|
|
11622
|
+
}).catch((error) => {
|
|
11623
|
+
appendClickUpWebhookLocalLog(worktree, { type: "webhook_route_failed", taskId: clickUpTaskIdFromPayload(payload || {}) || null, event: clickUpEventType(payload || {}) || null, eventKey: clickUpWebhookEventKey(payload || {}) || null, async: true, message: error.message });
|
|
11624
|
+
return { ok: false, action: "error", reason: "background_route_failed", message: error.message };
|
|
11625
|
+
});
|
|
11626
|
+
route.catch(() => {
|
|
11627
|
+
});
|
|
11628
|
+
return route;
|
|
11629
|
+
}
|
|
11630
|
+
async function handleClickUpWebhookRequest({ method = "POST", url = null, headers = {}, rawBody = "", config, state, worktree, clickupClient, openCodeClient, saveState, now = () => /* @__PURE__ */ new Date(), sessionExists, createSession, sendSessionEvent, ensureTaskWorktree, verifySessionEventDelivery, asyncRouting = false } = {}) {
|
|
11604
11631
|
let payload = null;
|
|
11605
11632
|
let handled = null;
|
|
11606
11633
|
let authenticatedWebhook = false;
|
|
11607
11634
|
let receivedAt = null;
|
|
11608
11635
|
let activeState = state;
|
|
11636
|
+
let latestPersistedState = state;
|
|
11637
|
+
const persistState = (nextState) => {
|
|
11638
|
+
latestPersistedState = nextState;
|
|
11639
|
+
if (saveState) saveState(nextState);
|
|
11640
|
+
};
|
|
11609
11641
|
const finish = (result) => {
|
|
11610
11642
|
handled = result;
|
|
11611
11643
|
receivedAt ??= now();
|
|
11612
|
-
const auditState = authenticatedWebhook ? { ...
|
|
11613
|
-
if (saveState && authenticatedWebhook)
|
|
11644
|
+
const auditState = authenticatedWebhook ? { ...latestPersistedState, lastWebhookAt: receivedAt.toISOString() } : latestPersistedState;
|
|
11645
|
+
if (saveState && authenticatedWebhook) persistState(auditState);
|
|
11614
11646
|
writeClickUpWebhookAuditLog({ method, url, headers, rawBody, config, state: auditState, handled, payload, at: receivedAt });
|
|
11615
11647
|
return result;
|
|
11616
11648
|
};
|
|
@@ -11637,7 +11669,12 @@ async function handleClickUpWebhookRequest({ method = "POST", url = null, header
|
|
|
11637
11669
|
return finish({ ok: false, status: 400, reason: "invalid_json" });
|
|
11638
11670
|
}
|
|
11639
11671
|
const receivedState = { ...activeState, lastWebhookAt: receivedAt.toISOString() };
|
|
11640
|
-
|
|
11672
|
+
persistState(receivedState);
|
|
11673
|
+
if (asyncRouting) {
|
|
11674
|
+
runClickUpWebhookRouteInBackground({ payload, config, state: receivedState, worktree, clickupClient, openCodeClient, saveState: persistState, sessionExists, createSession, sendSessionEvent, ensureTaskWorktree, verifySessionEventDelivery, now });
|
|
11675
|
+
return finish({ ok: true, status: 200, reason: "accepted", result: { action: "accepted", taskId: clickUpTaskIdFromPayload(payload), eventKey: clickUpWebhookEventKey(payload) } });
|
|
11676
|
+
}
|
|
11677
|
+
const result = await routeClickUpWebhookEvent({ payload, config, state: receivedState, worktree, clickupClient, openCodeClient, saveState: persistState, sessionExists, createSession, sendSessionEvent, ensureTaskWorktree, verifySessionEventDelivery });
|
|
11641
11678
|
return finish({ ok: result.ok, status: result.ok ? 200 : 422, result });
|
|
11642
11679
|
} catch (error) {
|
|
11643
11680
|
writeClickUpWebhookAuditLog({ method, url, headers, rawBody, config, state, handled, error, payload, at: now() });
|
|
@@ -11714,7 +11751,8 @@ function startClickUpWebhookListener({ config, state, worktree, clickupClient, o
|
|
|
11714
11751
|
worktree,
|
|
11715
11752
|
clickupClient,
|
|
11716
11753
|
openCodeClient,
|
|
11717
|
-
saveState: (nextState) => writeClickUpWebhookState(worktree, nextState, config)
|
|
11754
|
+
saveState: (nextState) => writeClickUpWebhookState(worktree, nextState, config),
|
|
11755
|
+
asyncRouting: true
|
|
11718
11756
|
});
|
|
11719
11757
|
res.writeHead(handled.status, { "Content-Type": "application/json" });
|
|
11720
11758
|
res.end(JSON.stringify({ ok: handled.ok, reason: handled.reason, result: handled.result?.action }));
|