@magpie-community/opencode-qoder-auth 0.2.31 → 0.2.33

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 (3) hide show
  1. package/README.md +7 -0
  2. package/index.mjs +20 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -296,6 +296,13 @@ the account's credentials.
296
296
  - A helper that is there but can't be read, or gives an invalid identity,
297
297
  is `failed` and asked again later, rather than a false "no activity"
298
298
  result.
299
+ - With the identity read and sent, a list with no daily claim is
300
+ `inactive`, with a message (since 0.2.32) saying Qoder offered this
301
+ device's identity no daily credits campaign, that Qoder decides that per
302
+ device, and that the credits can be claimed in Qoder desktop when it
303
+ shows them (#304: a Linux CLI identity was offered none while the same
304
+ account's desktop identity was). The plugin never sends another
305
+ device's identity.
299
306
 
300
307
  Qoder CN (since 0.2.30) sends its own device identity the same way when
301
308
  Qoder CN is installed: its desktop 0.4.9 and CLI (`qoderclicn`) both ask
package/index.mjs CHANGED
@@ -892,6 +892,13 @@ const TASKS = new Map()
892
892
  const TASK_MAX = 512
893
893
  const TASK_IDLE = 2 * 60 * 60 * 1000
894
894
 
895
+ // taskName is the business record's name for a task whose prompt is
896
+ // prompt, as Qoder's client names an agent task: the prompt's first ten
897
+ // characters (qoder-agent-sdk's AgentLifecycle, hdr → C6s: type
898
+ // "code_review" takes the session id, every other the prompt, sliced to
899
+ // 10 when longer).
900
+ const taskName = (prompt) => (prompt.length > 10 ? prompt.slice(0, 10) : prompt)
901
+
895
902
  // taskOf is the task chat's call belongs to, in session sid: made on its
896
903
  // first call, the same one on every call after.
897
904
  function taskOf(sid, chat, now = Date.now()) {
@@ -905,7 +912,7 @@ function taskOf(sid, chat, now = Date.now()) {
905
912
  let t = TASKS.get(key)
906
913
  if (t && now - t.used > TASK_IDLE) t = undefined
907
914
  TASKS.delete(key)
908
- t ??= { id: randomUUID(), begin: now, answered: false }
915
+ t ??= { id: randomUUID(), begin: now, answered: false, name: taskName(at < 0 ? "" : textOf(msgs[at].content)) }
909
916
  t.used = now
910
917
  TASKS.set(key, t)
911
918
  while (TASKS.size > TASK_MAX) TASKS.delete(TASKS.keys().next().value)
@@ -936,7 +943,7 @@ function qoderBody(chat, m, named = "", task) {
936
943
  chat_record_id: request,
937
944
  session_id: session,
938
945
  parameters: params,
939
- business: { product: "app", version: COSY_VERSION, type: "agent", id: task.id, name: "magpie session", begin_at: task.begin, stage: task.answered ? "processing" : "start" },
946
+ business: { product: "app", version: COSY_VERSION, type: "agent", id: task.id, name: task.name ?? "", begin_at: task.begin, stage: task.answered ? "processing" : "start" },
940
947
  agent_id: "agent_common",
941
948
  task_id: "common",
942
949
  session_type: "app",
@@ -1655,6 +1662,12 @@ class RuntimeMissing extends Error {
1655
1662
  }
1656
1663
  }
1657
1664
 
1665
+ // noCampaign is why a check-in asked with this machine's own device
1666
+ // identity found nothing to claim: all the list says is that it offered
1667
+ // that identity no daily credits, not why.
1668
+ const noCampaign = (name) =>
1669
+ `${name} check-in: ${name} offered this device's identity, read from this machine's own ${name} runtime-info, no daily credits campaign right now. ${name} decides per device whether to offer it; if ${name} desktop shows today's credits, claim them there`
1670
+
1658
1671
  // Read the SDK identity as Qoder does: environment 3 is international, 0
1659
1672
  // Qoder CN; on Windows and macOS the uid goes over stdin, never into the
1660
1673
  // command line.
@@ -2094,7 +2107,11 @@ const makePlugin = (site) => async ({ client }) => {
2094
2107
  // (no Qoder CN on this machine) or ask again (it didn't answer).
2095
2108
  if (unread instanceof RuntimeMissing) return { outcome: "ineligible", message: unread.message }
2096
2109
  if (unread) return { outcome: "failed", message: unread.message }
2097
- return { outcome: "inactive" }
2110
+ // Asked with this machine's own identity and still offered nothing:
2111
+ // Qoder decides per device (plugins#304, a Linux CLI identity was
2112
+ // offered none while the same account's desktop identity was), so
2113
+ // say that much, and where the credits can still be claimed.
2114
+ return { outcome: "inactive", message: noCampaign(site.name) }
2098
2115
  }
2099
2116
  const claimRes = await call(base.replace(/\/$/, "") + "/" + encodeURIComponent(campaign.campaignId) + "/claim", "POST", "{}")
2100
2117
  let claim = {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-qoder-auth",
3
- "version": "0.2.31",
3
+ "version": "0.2.33",
4
4
  "description": "Qoder subscriptions in OpenCode and magpie: Qoder (qoder.com) and Qoder CN (qoder.cn)",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",