clixad 0.0.1-beta.11 → 0.0.1-beta.12

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 (2) hide show
  1. package/dist/clixad.mjs +67 -5
  2. package/package.json +1 -1
package/dist/clixad.mjs CHANGED
@@ -197,6 +197,7 @@ var init_client = __esm({
197
197
  signup_bonus: "signup bonus",
198
198
  ad_reward: "offer reward",
199
199
  ad_screenout_bonus: "screenout bonus (didn't qualify)",
200
+ ad_sponsor_impression: "sponsored line shown",
200
201
  ad_reversal: "offer reward reversed by the provider",
201
202
  purchase: "credits purchased",
202
203
  usage: "model usage",
@@ -369,6 +370,40 @@ var init_client = __esm({
369
370
  if (!res.ok) throw new Error(`wallet failed: ${res.status}`);
370
371
  return res.json();
371
372
  }
373
+ /**
374
+ * Ask the gateway for a sponsored line, or `null` if it has none.
375
+ *
376
+ * **This never throws and never reports a failure to anybody.** Every caller is
377
+ * painting a row of dim chrome that already has a house line in it, so there is
378
+ * no state a user could act on and nothing a message would improve — a 404 from
379
+ * a gateway older than the route, a 401, a cold start, a dropped connection and
380
+ * an empty inventory are all the same event here, which is "keep showing ours".
381
+ * That is the opposite of every other method on this client, and it is why the
382
+ * catch is this broad rather than a list of statuses.
383
+ *
384
+ * The serve itself happens on the gateway, deliberately: an impression is worth
385
+ * credits, and this program is installed by strangers from npm. All the CLI
386
+ * gets to decide is when to ask.
387
+ */
388
+ async sponsorLine(signal) {
389
+ try {
390
+ const res = await fetch(`${this.config.gatewayUrl}/v1/sponsor/line`, {
391
+ headers: this.headers(),
392
+ signal
393
+ });
394
+ if (!res.ok) return null;
395
+ const body = await res.json();
396
+ if (typeof body.text !== "string" || !body.text.trim()) return null;
397
+ return {
398
+ provider: "adtention",
399
+ id: typeof body.id === "string" && body.id ? body.id : "adtention",
400
+ text: body.text.trim(),
401
+ credits: typeof body.credits === "number" ? body.credits : 0
402
+ };
403
+ } catch {
404
+ return null;
405
+ }
406
+ }
372
407
  /**
373
408
  * Search the web, through the gateway.
374
409
  *
@@ -4002,6 +4037,23 @@ function sponsorSource(provider = "house") {
4002
4037
  return houseSource();
4003
4038
  }
4004
4039
  }
4040
+ function adtentionSource(fetchLine) {
4041
+ return {
4042
+ provider: "adtention",
4043
+ async fetch(signal) {
4044
+ let line2;
4045
+ try {
4046
+ line2 = await fetchLine(signal);
4047
+ } catch {
4048
+ return null;
4049
+ }
4050
+ if (!line2) return null;
4051
+ const text = line2.text.trim();
4052
+ if (!text) return null;
4053
+ return { id: line2.id, text };
4054
+ }
4055
+ };
4056
+ }
4005
4057
  var init_provider = __esm({
4006
4058
  "src/sponsor/provider.ts"() {
4007
4059
  "use strict";
@@ -4605,6 +4657,8 @@ function App({ client, config, wallet, session, initialTask }) {
4605
4657
  const sponsorRef = useRef(sponsorSource());
4606
4658
  const sponsorIdxRef = useRef(0);
4607
4659
  const sponsorPrevRef = useRef(void 0);
4660
+ const sponsorCallRef = useRef(0);
4661
+ const remoteSponsorRef = useRef(adtentionSource((signal) => client.sponsorLine(signal)));
4608
4662
  const tallyRef = useRef(createTally());
4609
4663
  const heightCacheRef = useRef(/* @__PURE__ */ new Map());
4610
4664
  const push = useCallback((e) => {
@@ -4692,6 +4746,7 @@ function App({ client, config, wallet, session, initialTask }) {
4692
4746
  );
4693
4747
  const nextSponsor = useCallback(
4694
4748
  (modelId) => {
4749
+ const call = ++sponsorCallRef.current;
4695
4750
  if (!sponsorEnabled({
4696
4751
  isTTY: process.stdout.isTTY,
4697
4752
  env: process.env,
@@ -4706,13 +4761,19 @@ function App({ client, config, wallet, session, initialTask }) {
4706
4761
  adsPerTask: est === void 0 ? void 0 : adsPerTaskLabel(est)
4707
4762
  };
4708
4763
  const picked = sponsorRef.current.pick(sponsorIdxRef.current++, sponsorPrevRef.current, facts);
4709
- if (!picked) {
4764
+ if (picked) {
4765
+ sponsorPrevRef.current = picked.id;
4766
+ recordImpression(tallyRef.current, picked.id);
4767
+ setSponsor(picked.text);
4768
+ } else {
4710
4769
  setSponsor(null);
4711
- return;
4712
4770
  }
4713
- sponsorPrevRef.current = picked.id;
4714
- recordImpression(tallyRef.current, picked.id);
4715
- setSponsor(picked.text);
4771
+ void remoteSponsorRef.current.fetch().then((line2) => {
4772
+ if (!line2 || call !== sponsorCallRef.current) return;
4773
+ sponsorPrevRef.current = line2.id;
4774
+ recordImpression(tallyRef.current, line2.id);
4775
+ setSponsor(line2.text);
4776
+ });
4716
4777
  },
4717
4778
  [config.sponsor, wallet]
4718
4779
  );
@@ -4939,6 +5000,7 @@ ${NO_SEARCH_INSTRUCTION}`),
4939
5000
  dropDelta();
4940
5001
  setLive(null);
4941
5002
  setBusy(false);
5003
+ sponsorCallRef.current++;
4942
5004
  setSponsor(null);
4943
5005
  }
4944
5006
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clixad",
3
- "version": "0.0.1-beta.11",
3
+ "version": "0.0.1-beta.12",
4
4
  "description": "Free AI coding agent in your terminal, funded by rewarded ads.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",