@questionbase/deskfree 0.3.0-alpha.27 → 0.3.0-alpha.29

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 CHANGED
@@ -4655,6 +4655,17 @@ async function deliverMessageToAgent(ctx, message, client) {
4655
4655
  replyOptions
4656
4656
  });
4657
4657
  log.info(`Message ${message.messageId} dispatched successfully.`);
4658
+ const activeSession = streamingSession;
4659
+ if (activeSession?.isActive()) {
4660
+ try {
4661
+ await activeSession.close(accumulatedText || void 0);
4662
+ log.info("Streaming reply finalized (post-dispatch cleanup).");
4663
+ } catch (closeErr) {
4664
+ const msg = closeErr instanceof Error ? closeErr.message : String(closeErr);
4665
+ log.warn(`Post-dispatch streaming close failed: ${msg}`);
4666
+ }
4667
+ streamingSession = null;
4668
+ }
4658
4669
  } catch (err) {
4659
4670
  const session = streamingSession;
4660
4671
  if (session?.isActive()) {
@@ -4694,6 +4705,15 @@ var import_websocket_server = __toESM(require_websocket_server(), 1);
4694
4705
  var wrapper_default = import_websocket.default;
4695
4706
 
4696
4707
  // src/gateway.ts
4708
+ var activeWs = null;
4709
+ function sendWsAck(messageId) {
4710
+ if (activeWs?.readyState === wrapper_default.OPEN) {
4711
+ try {
4712
+ activeWs.send(JSON.stringify({ action: "ack", messageId }));
4713
+ } catch {
4714
+ }
4715
+ }
4716
+ }
4697
4717
  var activeTaskId = null;
4698
4718
  var completedTaskId = null;
4699
4719
  var inboundThreadId = null;
@@ -4976,6 +4996,7 @@ async function runWebSocketConnection(opts) {
4976
4996
  }, WS_CONNECTION_TIMEOUT_MS);
4977
4997
  ws.on("open", async () => {
4978
4998
  isConnected = true;
4999
+ activeWs = ws;
4979
5000
  if (connectionTimer !== void 0) {
4980
5001
  clearTimeout(connectionTimer);
4981
5002
  connectionTimer = void 0;
@@ -5023,6 +5044,16 @@ async function runWebSocketConnection(opts) {
5023
5044
  log,
5024
5045
  account
5025
5046
  );
5047
+ client.listMessages({ limit: 20 }).then((res) => {
5048
+ const humanMessages = res.items?.filter(
5049
+ (m) => m.authorType === "human"
5050
+ );
5051
+ const latest = humanMessages?.[humanMessages.length - 1];
5052
+ if (latest) {
5053
+ sendWsAck(latest.messageId);
5054
+ }
5055
+ }).catch(() => {
5056
+ });
5026
5057
  });
5027
5058
  ws.on("message", async (data) => {
5028
5059
  try {
@@ -5069,6 +5100,7 @@ async function runWebSocketConnection(opts) {
5069
5100
  ws.on("close", (code, reason) => {
5070
5101
  cleanup();
5071
5102
  isConnected = false;
5103
+ activeWs = null;
5072
5104
  ctx.setStatus({ running: false, lastStopAt: Date.now() });
5073
5105
  if (code === 1e3) {
5074
5106
  log.info(`WebSocket closed normally: ${code} ${reason.toString()}`);
@@ -5254,6 +5286,7 @@ async function pollAndDeliver(client, ctx, cursor, log, account) {
5254
5286
  await deliverMessageToAgent(ctx, message, client);
5255
5287
  deliveredMessageIds.add(message.messageId);
5256
5288
  deliveredCount++;
5289
+ sendWsAck(message.messageId);
5257
5290
  }
5258
5291
  if (deliveredMessageIds.size > 1e3) {
5259
5292
  const entries = Array.from(deliveredMessageIds);
@@ -8794,11 +8827,12 @@ You are the orchestrator. Your job: turn human intent into approved tasks, then
8794
8827
  3. **Dispatch** \u2192 spawn a sub-agent for each approved task. Pass the taskId.
8795
8828
  4. **Communicate** \u2192 \`deskfree_send_message\` for updates outside task threads.
8796
8829
 
8797
- **Bias toward action, not questions.** When a human gives you a direction:
8798
- - Don't ask clarifying questions in the main thread. Propose tasks instead.
8799
- - If the request is clear ("audit my LinkedIn profile"), propose the task directly \u2014 no scoping needed.
8800
- - If the request is ambiguous ("I want to be a LinkedIn influencer"), propose a scoping task first: "Research current state and draft a plan" \u2014 the worker reports back with findings and follow-up proposals.
8801
- - Discovery happens inside tasks, not in conversation. Tasks produce deliverables; questions don't.
8830
+ **Always explain before proposing.** When a human gives you a direction:
8831
+ - First, respond in chat with your understanding and plan \u2014 what you'll do, how you'll break it down, what the deliverables will be.
8832
+ - Then call \`deskfree_propose\` with the concrete tasks. The human sees your thinking first, then the actionable proposal.
8833
+ - If the request is clear ("audit my LinkedIn profile"), a brief "Here's what I'll do:" is enough before proposing.
8834
+ - If the request is ambiguous ("I want to be a LinkedIn influencer"), explain your approach, then propose a scoping task.
8835
+ - Never call \`deskfree_propose\` as your first action \u2014 always write a message first.
8802
8836
 
8803
8837
  You do NOT claim tasks or do work directly. Sub-agents handle execution.
8804
8838
  - When a human writes in a task thread, you receive it with recent context. Use \`deskfree_reopen_task\` if it needs more work.