@qianhaoq/dsh-dota2ai 0.2.12 → 0.2.13

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/lib/client.js +71 -8
  2. package/lib/index.js +251 -15
  3. package/package.json +1 -1
package/lib/client.js CHANGED
@@ -27509,6 +27509,15 @@ var T9 = {
27509
27509
  events: { en: "What happened", zh: "\u7ECF\u8FC7", ru: "\u0425\u043E\u0434 \u0441\u043E\u0431\u044B\u0442\u0438\u0439" },
27510
27510
  dealt: { en: "Damage to heroes", zh: "\u5BF9\u82F1\u96C4\u4F24\u5BB3", ru: "\u0423\u0440\u043E\u043D \u043F\u043E \u0433\u0435\u0440\u043E\u044F\u043C" },
27511
27511
  firstHeld: { en: "First held", zh: "\u9996\u6B21\u6301\u6709", ru: "\u0412\u043F\u0435\u0440\u0432\u044B\u0435 \u043F\u043E\u043B\u0443\u0447\u0435\u043D" },
27512
+ purchased: { en: "Purchased", zh: "\u8D2D\u9F50\u4E8E", ru: "\u041A\u0443\u043F\u043B\u0435\u043D" },
27513
+ deliveryDelay: { en: "Delivery delay", zh: "\u5230\u8D27\u5EF6\u8FDF", ru: "\u0417\u0430\u0434\u0435\u0440\u0436\u043A\u0430 \u0434\u043E\u0441\u0442\u0430\u0432\u043A\u0438" },
27514
+ courierDiedDuringDelivery: { en: "Team courier killed during delivery", zh: "\u9001\u8FBE\u671F\u95F4\u5DF1\u65B9\u4FE1\u4F7F\u9635\u4EA1", ru: "\u041A\u0443\u0440\u044C\u0435\u0440 \u043A\u043E\u043C\u0430\u043D\u0434\u044B \u0443\u0431\u0438\u0442 \u043F\u0440\u0438 \u0434\u043E\u0441\u0442\u0430\u0432\u043A\u0435" },
27515
+ enemyCourierDiedDuringDelivery: { en: "Enemy courier killed during delivery", zh: "\u9001\u8FBE\u671F\u95F4\u654C\u65B9\u4FE1\u4F7F\u9635\u4EA1", ru: "\u041A\u0443\u0440\u044C\u0435\u0440 \u0432\u0440\u0430\u0433\u0430 \u0443\u0431\u0438\u0442 \u043F\u0440\u0438 \u0434\u043E\u0441\u0442\u0430\u0432\u043A\u0435" },
27516
+ teamCourierDeaths: { en: "Your team's courier deaths", zh: "\u6211\u65B9\u4FE1\u4F7F\u9635\u4EA1", ru: "\u0421\u043C\u0435\u0440\u0442\u0438 \u043A\u0443\u0440\u044C\u0435\u0440\u043E\u0432 \u043A\u043E\u043C\u0430\u043D\u0434\u044B" },
27517
+ purchaseSource: {
27518
+ direct: { en: "direct buy", zh: "\u76F4\u63A5\u8D2D\u4E70", ru: "\u043F\u0440\u044F\u043C\u0430\u044F \u043F\u043E\u043A\u0443\u043F\u043A\u0430" },
27519
+ components: { en: "all components bought", zh: "\u6563\u4EF6\u4E70\u9F50", ru: "\u0432\u0441\u0435 \u043A\u043E\u043C\u043F\u043E\u043D\u0435\u043D\u0442\u044B \u043A\u0443\u043F\u043B\u0435\u043D\u044B" }
27520
+ },
27512
27521
  refGold: { en: "gold", zh: "\u91D1", ru: "\u0437\u043E\u043B\u043E\u0442\u0430" },
27513
27522
  refRecipe: { en: "Recipe:", zh: "\u5408\u6210\uFF1A", ru: "\u0420\u0435\u0446\u0435\u043F\u0442:" },
27514
27523
  refVs: { en: "against", zh: "\u5BF9\u9635", ru: "\u043F\u0440\u043E\u0442\u0438\u0432" },
@@ -28505,13 +28514,43 @@ function Record({ data: data2, lang }) {
28505
28514
  ] }, l.lane))
28506
28515
  ] });
28507
28516
  }
28508
- if (data2.kind === "item") return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "ag-rec", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("p", { className: "ag-rec-head", children: [
28509
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("b", { children: r.first_held.clock }),
28510
- " \xB7 ",
28511
- N(r.item),
28512
- " \xB7 ",
28513
- t2(T9.firstHeld)
28514
- ] }) });
28517
+ if (data2.kind === "item") {
28518
+ const isEnemyCourier = Array.isArray(r.enemy_team_courier_deaths_during_delivery);
28519
+ const courierDeaths = Array.isArray(r.my_team_courier_deaths_during_delivery) ? r.my_team_courier_deaths_during_delivery : Array.isArray(r.enemy_team_courier_deaths_during_delivery) ? r.enemy_team_courier_deaths_during_delivery : [];
28520
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "ag-rec", children: [
28521
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("p", { className: "ag-rec-head", children: [
28522
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("b", { children: r.first_held.clock }),
28523
+ " \xB7 ",
28524
+ N(r.item),
28525
+ " \xB7 ",
28526
+ t2(T9.firstHeld)
28527
+ ] }),
28528
+ (r.first_purchased || typeof r.delivery_delay_seconds === "number" && r.delivery_delay_seconds > 0) && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("p", { className: "ag-rec-line", children: [
28529
+ r.first_purchased && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "ag-chip", children: [
28530
+ t2(T9.purchased),
28531
+ " ",
28532
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("em", { children: r.first_purchased.clock }),
28533
+ r.first_purchased.source && T9.purchaseSource[r.first_purchased.source] && ` \xB7 ${t2(T9.purchaseSource[r.first_purchased.source])}`
28534
+ ] }),
28535
+ typeof r.delivery_delay_seconds === "number" && r.delivery_delay_seconds > 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: `ag-chip ${courierDeaths.length > 0 ? "is-warn" : ""}`, children: [
28536
+ t2(T9.deliveryDelay),
28537
+ " ",
28538
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("em", { children: [
28539
+ "+",
28540
+ r.delivery_delay_seconds,
28541
+ t2(T9.sec)
28542
+ ] })
28543
+ ] })
28544
+ ] }),
28545
+ courierDeaths.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("p", { className: "ag-rec-line", children: [
28546
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { children: t2(isEnemyCourier ? T9.enemyCourierDiedDuringDelivery : T9.courierDiedDuringDelivery) }),
28547
+ courierDeaths.map((d, i) => /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "ag-chip is-warn", children: [
28548
+ d.clock,
28549
+ d.killed_by ? ` \u2190 ${N(d.killed_by)}` : ""
28550
+ ] }, `${d.clock}-${i}`))
28551
+ ] })
28552
+ ] });
28553
+ }
28515
28554
  if (data2.kind === "lane") {
28516
28555
  const pc = (v) => `${Math.round(v * 100)}%`;
28517
28556
  const signed = (v) => `${v > 0 ? "+" : v < 0 ? "\u2212" : ""}${Math.abs(v)}`;
@@ -29799,12 +29838,36 @@ function Record({ data: data2, lang }) {
29799
29838
  /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("caption", { className: "ag-rec-sub", children: t2(T9.buildItems) }),
29800
29839
  /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("tr", { children: T9.buildCols[lang].map((c) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("th", { scope: "col", children: c }, c)) }) }),
29801
29840
  /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("tbody", { children: r.my_big_items_in_order.map((i) => /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("tr", { children: [
29802
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("td", { children: i.first_held }),
29841
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("td", { children: [
29842
+ i.first_held,
29843
+ typeof i.first_purchased === "string" && typeof i.delivery_delay_seconds === "number" && i.delivery_delay_seconds > 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "ag-rec-note", children: [
29844
+ t2(T9.purchased),
29845
+ " ",
29846
+ i.first_purchased,
29847
+ " (+",
29848
+ i.delivery_delay_seconds,
29849
+ t2(T9.sec),
29850
+ ")",
29851
+ Array.isArray(i.my_team_courier_deaths_during_delivery) && i.my_team_courier_deaths_during_delivery.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
29852
+ " \xB7 ",
29853
+ t2(T9.courierDiedDuringDelivery),
29854
+ ": ",
29855
+ i.my_team_courier_deaths_during_delivery.map((d2) => `${d2.clock}${d2.killed_by ? ` \u2190 ${N(d2.killed_by)}` : ""}`).join(", ")
29856
+ ] })
29857
+ ] })
29858
+ ] }),
29803
29859
  /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("th", { scope: "row", children: i.name }),
29804
29860
  /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("td", { children: i.cost ?? "\u2013" }),
29805
29861
  /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("td", { children: why(i.built_for) })
29806
29862
  ] }, i.item)) })
29807
29863
  ] }) }),
29864
+ Array.isArray(r.my_team_courier_deaths) && r.my_team_courier_deaths.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("p", { className: "ag-rec-line", children: [
29865
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { children: t2(T9.teamCourierDeaths) }),
29866
+ r.my_team_courier_deaths.map((d2, idx) => /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "ag-chip is-warn", children: [
29867
+ d2.clock,
29868
+ d2.killed_by ? ` \u2190 ${N(d2.killed_by)}` : ""
29869
+ ] }, `${d2.clock}-${idx}`))
29870
+ ] }),
29808
29871
  (r.answers_to_top_killers ?? []).filter((k2) => k2.pro_items_against_this_killer?.length).map((k2) => /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("p", { className: "ag-rec-line", children: [
29809
29872
  /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { children: [
29810
29873
  t2(T9.buildVsKiller),
package/lib/index.js CHANGED
@@ -12282,16 +12282,236 @@ function fightTimeline(trace, args = {}, ctx = {}) {
12282
12282
  };
12283
12283
  }
12284
12284
  var CONSUMABLE = /^item_(tango|clarity|flask|faerie_fire|branches|ward_|enchanted_mango|famango|great_famango|tpscroll|smoke_of_deceit|dust|blood_grenade|tome_of_knowledge|infused_raindrop|bottle|madstone|recipe_)/;
12285
- function itemTimeline(trace, args = {}) {
12285
+ var POWER_TREADS_STAT_ALTS = ["belt_of_strength", "boots_of_elves", "robe"];
12286
+ function teamCourierDeaths(trace, heroTeam) {
12287
+ if (!Array.isArray(trace.creep_kills)) return null;
12288
+ const out = [];
12289
+ for (const row of trace.creep_kills) {
12290
+ if (!Array.isArray(row) || row[2] !== "c" || !Number.isFinite(row[0])) continue;
12291
+ const ah = heroOfName(trace, row[1]);
12292
+ if (ah < 0 || trace.heroes[ah].team === heroTeam) continue;
12293
+ out.push({ t: row[0], clock: clock3(row[0]), killed_by: trace.heroes[ah].key });
12294
+ }
12295
+ out.sort((a, b) => a.t - b.t);
12296
+ return out;
12297
+ }
12298
+ function itemRecipeSpec(key, patchItems) {
12299
+ const def = patchItems?.[key];
12300
+ if (!def || typeof def !== "object") return null;
12301
+ const comps = Array.isArray(def.components) ? def.components.filter((c) => typeof c === "string" && c.length > 0) : [];
12302
+ const recipeKey = `recipe_${key}`;
12303
+ const hasRecipe = Number(patchItems?.[recipeKey]?.cost) > 0;
12304
+ if (!comps.length && !hasRecipe) {
12305
+ return def.created === true ? { composite: true, parts: null } : { composite: false, parts: [] };
12306
+ }
12307
+ return { composite: true, parts: [...comps, ...hasRecipe ? [recipeKey] : []] };
12308
+ }
12309
+ function recipeDepth(key, patchItems, seen = /* @__PURE__ */ new Set()) {
12310
+ if (seen.has(key)) return 0;
12311
+ const spec = itemRecipeSpec(key, patchItems);
12312
+ if (!spec?.composite || !spec.parts?.length) return 0;
12313
+ seen.add(key);
12314
+ let d = 1;
12315
+ for (const p of spec.parts) d = Math.max(d, 1 + recipeDepth(p, patchItems, seen));
12316
+ seen.delete(key);
12317
+ return d;
12318
+ }
12319
+ function buildPurchaseMatcher(trace, h, patchItems) {
12320
+ if (!Array.isArray(trace.purchases) || !patchItems) return () => null;
12321
+ const npc = nameId(trace, trace.heroes[h].npc);
12322
+ const rawPurchases = [];
12323
+ if (npc >= 0) {
12324
+ for (let i = 0; i < trace.purchases.length; i += 1) {
12325
+ const p = trace.purchases[i];
12326
+ if (!Array.isArray(p) || p[1] !== npc || !Number.isFinite(p[0])) continue;
12327
+ const raw = trace.names[p[2]];
12328
+ if (typeof raw !== "string" || !raw.startsWith("item_")) continue;
12329
+ rawPurchases.push({ t: p[0], item: raw.slice(5), row: p[3] ?? i, ord: i });
12330
+ }
12331
+ }
12332
+ rawPurchases.sort((a, b) => a.t - b.t || (a.row ?? 0) - (b.row ?? 0) || a.ord - b.ord);
12333
+ const pool = [];
12334
+ for (const p of rawPurchases) {
12335
+ const spec = itemRecipeSpec(p.item, patchItems);
12336
+ if (!spec?.composite) {
12337
+ pool.push({ item: p.item, createdT: p.t, minT: p.t, maxT: p.t, unknown: false, source: "direct", syntheticT0: false, consumedAt: null });
12338
+ }
12339
+ }
12340
+ const heldEntries = Object.entries(trace.items?.[h] ?? {}).filter(([, e]) => e?.held?.length).map(([rawK, e]) => ({ item: rawK.replace(/^item_/, ""), firstHeld: e.held[0][0] }));
12341
+ for (const he of heldEntries) {
12342
+ if (he.firstHeld > trace.t0 + 0.5) continue;
12343
+ const spec = itemRecipeSpec(he.item, patchItems);
12344
+ if (spec?.composite) continue;
12345
+ if (!pool.some((x) => x.item === he.item && x.createdT <= trace.t0 + 1)) {
12346
+ pool.push({ item: he.item, createdT: trace.t0, minT: trace.t0, maxT: trace.t0, unknown: false, source: "direct", syntheticT0: true, consumedAt: null });
12347
+ }
12348
+ }
12349
+ pool.sort((a, b) => a.createdT - b.createdT);
12350
+ const compositeEvents = [];
12351
+ const loggedCompositeAt = /* @__PURE__ */ new Map();
12352
+ for (const p of rawPurchases) {
12353
+ const spec = itemRecipeSpec(p.item, patchItems);
12354
+ if (spec?.composite) {
12355
+ compositeEvents.push({ item: p.item, combineT: p.t, limitT: p.t + 2, ord: p.ord });
12356
+ if (!loggedCompositeAt.has(p.item)) loggedCompositeAt.set(p.item, p.t);
12357
+ }
12358
+ }
12359
+ for (const he of heldEntries) {
12360
+ const spec = itemRecipeSpec(he.item, patchItems);
12361
+ if (!spec?.composite) continue;
12362
+ const firstLog = loggedCompositeAt.get(he.item);
12363
+ if (firstLog == null || firstLog > he.firstHeld + 2) {
12364
+ compositeEvents.push({ item: he.item, combineT: null, limitT: he.firstHeld + 2, ord: Infinity });
12365
+ }
12366
+ }
12367
+ compositeEvents.sort((a, b) => (a.combineT ?? a.limitT - 2) - (b.combineT ?? b.limitT - 2) || recipeDepth(a.item, patchItems) - recipeDepth(b.item, patchItems) || a.ord - b.ord);
12368
+ const expandParts = (itemKey, parts, limitT, depth = 0) => {
12369
+ if (depth > 6) return null;
12370
+ const groups = /* @__PURE__ */ new Map();
12371
+ const addReq = (alts) => {
12372
+ const gk = alts.join("|");
12373
+ const cur = groups.get(gk) ?? { alts, count: 0 };
12374
+ cur.count += 1;
12375
+ groups.set(gk, cur);
12376
+ };
12377
+ for (const part of parts) {
12378
+ if (itemKey === "power_treads" && part === "belt_of_strength") {
12379
+ addReq(POWER_TREADS_STAT_ALTS);
12380
+ continue;
12381
+ }
12382
+ const directAvail = pool.filter((x) => x.consumedAt == null && x.item === part && x.createdT <= limitT).length;
12383
+ const alreadyNeeded = groups.get(part)?.count ?? 0;
12384
+ if (directAvail > alreadyNeeded) {
12385
+ addReq([part]);
12386
+ continue;
12387
+ }
12388
+ const subSpec = itemRecipeSpec(part, patchItems);
12389
+ if (subSpec?.composite && subSpec.parts?.length) {
12390
+ const sub = expandParts(part, subSpec.parts, limitT, depth + 1);
12391
+ if (!sub) return null;
12392
+ for (const [gk, g] of sub) {
12393
+ const cur = groups.get(gk) ?? { alts: g.alts, count: 0 };
12394
+ cur.count += g.count;
12395
+ groups.set(gk, cur);
12396
+ }
12397
+ } else {
12398
+ addReq([part]);
12399
+ }
12400
+ }
12401
+ return groups;
12402
+ };
12403
+ const sortAvail = (a, b) => (a.unknown === b.unknown ? a.unknown ? 0 : (a.minT ?? 0) - (b.minT ?? 0) : a.unknown ? -1 : 1) || a.createdT - b.createdT;
12404
+ for (const ev of compositeEvents) {
12405
+ const consumedAt = ev.combineT ?? ev.limitT - 2;
12406
+ const spec = itemRecipeSpec(ev.item, patchItems);
12407
+ if (!spec?.parts?.length) {
12408
+ pool.push({ item: ev.item, createdT: consumedAt, minT: null, maxT: null, unknown: true, source: "components", syntheticT0: false, consumedAt: null });
12409
+ pool.sort((a, b) => a.createdT - b.createdT);
12410
+ continue;
12411
+ }
12412
+ const groups = expandParts(ev.item, spec.parts, ev.limitT);
12413
+ if (!groups) {
12414
+ pool.push({ item: ev.item, createdT: consumedAt, minT: null, maxT: null, unknown: true, source: "components", syntheticT0: false, consumedAt: null });
12415
+ pool.sort((a, b) => a.createdT - b.createdT);
12416
+ continue;
12417
+ }
12418
+ const matched = [];
12419
+ let ok = true;
12420
+ for (const g of groups.values()) {
12421
+ const avail = pool.filter((x) => x.consumedAt == null && g.alts.includes(x.item) && x.createdT <= ev.limitT).sort(sortAvail);
12422
+ if (avail.length < g.count) ok = false;
12423
+ const groupUnknown = avail.some((x) => x.unknown);
12424
+ const groupMinT = !groupUnknown && avail.length ? avail[0].minT : null;
12425
+ const earliestMax = !groupUnknown && avail.length >= g.count ? avail[g.count - 1].minT : null;
12426
+ const latestMax = !groupUnknown && avail.length ? Math.max(...avail.map((x) => x.maxT ?? 0)) : null;
12427
+ matched.push({ g, avail, groupUnknown, groupMinT, earliestMax, latestMax });
12428
+ }
12429
+ const taken = [];
12430
+ for (const m of matched) {
12431
+ const take = Math.min(m.g.count, m.avail.length);
12432
+ for (let i = 0; i < take; i += 1) {
12433
+ m.avail[i].consumedAt = consumedAt;
12434
+ taken.push(m.avail[i]);
12435
+ }
12436
+ if (m.avail.length > take) {
12437
+ for (let i = take; i < m.avail.length; i += 1) {
12438
+ if (m.groupUnknown) {
12439
+ m.avail[i].unknown = true;
12440
+ m.avail[i].minT = null;
12441
+ m.avail[i].maxT = null;
12442
+ } else if (m.groupMinT != null && m.latestMax != null && !m.avail[i].unknown) {
12443
+ m.avail[i].minT = Math.min(m.avail[i].minT ?? m.groupMinT, m.groupMinT);
12444
+ m.avail[i].maxT = Math.max(m.avail[i].maxT ?? m.latestMax, m.latestMax);
12445
+ }
12446
+ }
12447
+ }
12448
+ }
12449
+ const evUnknown = !ok || matched.some((m) => m.groupUnknown);
12450
+ if (evUnknown) {
12451
+ pool.push({ item: ev.item, createdT: consumedAt, minT: null, maxT: null, unknown: true, source: "components", syntheticT0: false, consumedAt: null });
12452
+ } else {
12453
+ const minT = Math.max(...matched.map((m) => m.earliestMax ?? -Infinity));
12454
+ const maxT = Math.max(...matched.map((m) => m.latestMax ?? -Infinity));
12455
+ const anyReal = taken.some((x) => !x.syntheticT0);
12456
+ pool.push({ item: ev.item, createdT: consumedAt, minT, maxT, unknown: false, source: "components", syntheticT0: !anyReal, consumedAt: null });
12457
+ }
12458
+ pool.sort((a, b) => a.createdT - b.createdT);
12459
+ }
12460
+ return (itemKey, firstHeld) => {
12461
+ const cands = pool.filter((x) => !x.syntheticT0 && x.item === itemKey && x.createdT <= firstHeld + 2 && (x.consumedAt == null || x.consumedAt >= firstHeld - 2));
12462
+ if (!cands.length || cands.some((x) => x.unknown)) return null;
12463
+ const earliest = Math.min(...cands.map((x) => x.minT ?? 0));
12464
+ const latest = Math.max(...cands.map((x) => x.maxT ?? 0));
12465
+ if (latest - earliest > 2) return null;
12466
+ return { t: earliest, clock: clock3(earliest), source: cands[0].source };
12467
+ };
12468
+ }
12469
+ function itemTimeline(trace, args = {}, ctx = {}) {
12286
12470
  const { h, err } = needHero(trace, args.hero);
12287
12471
  if (err) return err;
12472
+ const view = viewer(trace, ctx);
12473
+ const heroKey = trace.heroes[h].key;
12474
+ const heroTeam = trace.heroes[h].team;
12475
+ const isEnemyView = Boolean(view && heroTeam !== view.team);
12476
+ const courierListKey = isEnemyView ? "enemy_team_courier_deaths" : "my_team_courier_deaths";
12477
+ const courierDeliveryKey = isEnemyView ? "enemy_team_courier_deaths_during_delivery" : "my_team_courier_deaths_during_delivery";
12288
12478
  const end = trace.t0 + trace.n - 1;
12289
- const items = Object.entries(trace.items[h]).filter(([k3, e]) => !CONSUMABLE.test(k3) && e.held.length).map(([k3, e]) => {
12479
+ const hasPurchases = Array.isArray(trace.purchases);
12480
+ const patchItems = ctx?.patchItems && typeof ctx.patchItems === "object" ? ctx.patchItems : null;
12481
+ const matchPurchase = buildPurchaseMatcher(trace, h, patchItems);
12482
+ const courierDeaths = teamCourierDeaths(trace, heroTeam);
12483
+ const items = Object.entries(trace.items?.[h] ?? {}).filter(([k3, e]) => !CONSUMABLE.test(k3) && e.held.length).map(([k3, e]) => {
12484
+ const itemKey = k3.replace(/^item_/, "");
12290
12485
  const first = e.held[0][0];
12291
12486
  const last = e.held.at(-1)[1];
12292
- return { ref: `item:${trace.heroes[h].key}:${k3.replace(/^item_/, "")}`, item: k3.replace(/^item_/, ""), first_held: { t: first, clock: clock3(first) }, held_at_end: last >= end - 2, ...last >= end - 2 ? {} : { last_held: { t: last, clock: clock3(last) } } };
12487
+ const purchased = matchPurchase(itemKey, first);
12488
+ const preHornStart = purchased != null && first <= trace.t0 + 0.5 && purchased.t < trace.t0;
12489
+ const delaySec = purchased == null || preHornStart ? null : Math.max(0, Math.round(first - purchased.t));
12490
+ const courierDuring = purchased != null && delaySec != null && delaySec > 0 ? courierDeaths == null ? null : courierDeaths.filter((d) => d.t >= purchased.t && d.t <= first) : void 0;
12491
+ return {
12492
+ ref: `item:${heroKey}:${itemKey}`,
12493
+ item: itemKey,
12494
+ first_purchased: purchased,
12495
+ first_held: { t: first, clock: clock3(first) },
12496
+ delivery_delay_seconds: delaySec,
12497
+ ...delaySec != null && delaySec > 0 ? { [courierDeliveryKey]: courierDuring } : {},
12498
+ held_at_end: last >= end - 2,
12499
+ ...last >= end - 2 ? {} : { last_held: { t: last, clock: clock3(last) } }
12500
+ };
12293
12501
  }).sort((a, b) => a.first_held.t - b.first_held.t);
12294
- return { hero: trace.heroes[h].key, items, note: "first_held is when the item first sat in an inventory, TP or neutral slot; components appear until they are built into something else" };
12502
+ return {
12503
+ hero: heroKey,
12504
+ ...sideOf(view, trace, h),
12505
+ [courierListKey]: courierDeaths,
12506
+ items,
12507
+ note: "first_purchased is when the hero paid for the item (direct shop purchase, or the last required component/recipe purchase for a composite item; null when absent or ambiguous in the purchase log). first_held is when the item first sat in an inventory, TP or neutral slot (not stash, backpack, or on a courier); components appear until they are built into something else. delivery_delay_seconds is first_held minus first_purchased (0 when held immediately, null when purchase or pre-horn delivery time is unknown). Courier deaths are hero-killed couriers of this hero's team from the combat log; a death during [first_purchased, first_held] is a factual lead, not proof of which courier died or what it carried.",
12508
+ gaps: [
12509
+ ...!hasPurchases ? [{ topic: "item_purchases", reason: "no_purchases_in_trace" }] : [],
12510
+ ...hasPurchases && !patchItems ? [{ topic: "item_purchases", reason: "patch_item_recipes_not_provided: purchase_timing_requires_item_recipes" }] : [],
12511
+ ...courierDeaths == null ? [{ topic: "courier_deaths", reason: "no_creep_kills_in_trace" }] : [{ topic: "courier_ownership_and_cargo", reason: "trace_does_not_record_courier_owner_carried_items_or_non_hero_courier_kills" }],
12512
+ { topic: "stash_and_backpack_state", reason: "trace_does_not_separate_courier_transit_from_stash_backpack_or_lock_combining_time" }
12513
+ ]
12514
+ };
12295
12515
  }
12296
12516
  var SHARED_NAME = /_tower4$/;
12297
12517
  var PHASE_SECONDS = 600;
@@ -12552,7 +12772,7 @@ var TRACE_TOOLS = [
12552
12772
  },
12553
12773
  {
12554
12774
  name: "item_timeline",
12555
- description: "When a hero first held each item, in order, and whether they still had it at the end. Works for any hero of the match: use it for the player's build and for when an enemy finished a key item.",
12775
+ description: "When a hero purchased (`first_purchased`, direct shop buy or last required component/recipe) and first held (`first_held`, in a usable slot \u2014 not stash, backpack, or on a courier) each item, in order, with `delivery_delay_seconds`, whether they still had it at the end, team courier deaths (`my_team_courier_deaths` / `enemy_team_courier_deaths`), and any team courier deaths during `[first_purchased, first_held]` (`*_courier_deaths_during_delivery`). Works for any hero of the match: use it for the player's build (distinguishing paid-but-undelivered items from slow farming) and for when an enemy finished a key item.",
12556
12776
  input_schema: { type: "object", properties: { hero: HERO }, required: ["hero"], additionalProperties: false },
12557
12777
  run: itemTimeline
12558
12778
  },
@@ -12919,7 +13139,7 @@ import { join as join5 } from "node:path";
12919
13139
 
12920
13140
  // lib/agent/review/schema.js
12921
13141
  var DEEP_REVIEW_SCHEMA = "dota2.ai/deep-review@1";
12922
- var DEEP_REVIEW_PROMPT_VERSION = 79;
13142
+ var DEEP_REVIEW_PROMPT_VERSION = 80;
12923
13143
  var MAX_REFS = 3;
12924
13144
  var MAX_FINDINGS = 3;
12925
13145
  var MAX_HIGHLIGHTS = 4;
@@ -17708,9 +17928,22 @@ function buildCheck(trace, args = {}, ctx = {}) {
17708
17928
  if (key === "aghanims_shard" && myAghs?.shard?.length) return { for_this_hero: myAghs.shard };
17709
17929
  return {};
17710
17930
  };
17711
- const timeline = itemTimeline(trace, { hero: slug2 }).items ?? [];
17931
+ const timelineRes = itemTimeline(trace, { hero: slug2 }, { ...ctx, perspective: slug2, patchItems: pd.items });
17932
+ const timeline = timelineRes.items ?? [];
17712
17933
  const firstHeld = new Map(timeline.map((i) => [i.item, i.first_held]));
17713
- const mine = timeline.filter((i) => big(i.item)).sort((a, b) => a.first_held.t - b.first_held.t).map((i) => ({ item: i.item, name: itemName2(i.item, lang), first_held: i.first_held.clock, ...itemFacts(i.item, pd.items), ...heroAghsNote(i.item), built_for: purposesOf(i.item, pd.items) }));
17934
+ const mine = timeline.filter((i) => big(i.item)).sort((a, b) => a.first_held.t - b.first_held.t).map((i) => ({
17935
+ item: i.item,
17936
+ name: itemName2(i.item, lang),
17937
+ first_held: i.first_held.clock,
17938
+ first_purchased: i.first_purchased?.clock ?? null,
17939
+ ...i.delivery_delay_seconds != null && i.delivery_delay_seconds > 0 ? { delivery_delay_seconds: i.delivery_delay_seconds } : {},
17940
+ ...i.delivery_delay_seconds != null && i.delivery_delay_seconds > 0 ? {
17941
+ my_team_courier_deaths_during_delivery: i.my_team_courier_deaths_during_delivery == null ? null : i.my_team_courier_deaths_during_delivery.map(({ clock: clock10, killed_by }) => ({ clock: clock10, killed_by }))
17942
+ } : {},
17943
+ ...itemFacts(i.item, pd.items),
17944
+ ...heroAghsNote(i.item),
17945
+ built_for: purposesOf(i.item, pd.items)
17946
+ }));
17714
17947
  const onTop = goldOnTop(mine.map((i) => i.item), pd.items);
17715
17948
  mine.forEach((i, n) => {
17716
17949
  if (onTop[n] != null) i.gold_on_top_of_items_already_held = onTop[n];
@@ -17816,6 +18049,7 @@ function buildCheck(trace, args = {}, ctx = {}) {
17816
18049
  killed_by: kills,
17817
18050
  damage_in_my_deaths: { share_from_enemy_attacks: fromAttacks, share_from_enemy_abilities_and_items: fromSpells, by_enemy: byEnemy },
17818
18051
  my_big_items_in_order: mine,
18052
+ my_team_courier_deaths: timelineRes.my_team_courier_deaths ?? null,
17819
18053
  gold_in_big_items_by_purpose: Object.fromEntries(Object.entries(goldBy).map(([p, v]) => [p, { gold: v.gold, items: v.items, first_at: v.first_at }])),
17820
18054
  player_already_held_for_this_purpose: {
17821
18055
  attack_damage_or_armor: heldFor("answer_to_attack_damage", "armor"),
@@ -17828,7 +18062,7 @@ function buildCheck(trace, args = {}, ctx = {}) {
17828
18062
  most_built_in_this_bracket: bracketCore,
17829
18063
  most_built_by_pros_on_this_hero: core.length ? { pro_games: row.games, played_on_releases: row.releases, ...fromBefore ? { from_the_patch_before_this_game: true } : sample.few_games ? { few_games: true } : {}, window: "finished between 10:00 and 24:59", items: core } : null,
17830
18064
  gap_closers: { mine: myGap ? { item: myGap.item, name: itemName2(myGap.item, lang), first_held: myGap.first_held.clock } : null, enemies: theirGaps },
17831
- note: `answers_to_top_killers is per enemy who killed the player most: Valve's text of that hero's abilities (valve_text is the current release's wording; the flags are this game's release), the shop's big items whose Valve data acts on the kind of damage that enemy did in the deaths (items_acting_on_their_damage: against_their attacks or abilities, cheapest first, \`how\` each acts on it, read off this patch's item data, whatever the role \u2014 a list to weigh, not a pick), the items pros on this hero build clearly more often against it (association, not proof); known_for is the site's curated threat tags of that hero. built_for is what the site's curated lists and Valve's item stats say an item is for; an empty list means "not classified", not "offensive". estimated_minutes_of_my_farm = item cost / my_economy.gold_per_min when that is known; "gives" and "does" are Valve's data. player_already_held_for_this_purpose groups big items the player already finished by the threats they cover. Shares of damage are over the 12 seconds before each death, of all damage taken in them (the two sums count enemy heroes only). An item built from a big item already held counts only the gold on top of it (gold_on_top_of_items_already_held). Pro shares are professional games, not this bracket; most_built_in_this_bracket (when present) is public games of this bracket and role (STRATZ).`,
18065
+ note: `answers_to_top_killers is per enemy who killed the player most: Valve's text of that hero's abilities (valve_text is the current release's wording; the flags are this game's release), the shop's big items whose Valve data acts on the kind of damage that enemy did in the deaths (items_acting_on_their_damage: against_their attacks or abilities, cheapest first, \`how\` each acts on it, read off this patch's item data, whatever the role \u2014 a list to weigh, not a pick), the items pros on this hero build clearly more often against it (association, not proof); known_for is the site's curated threat tags of that hero. built_for is what the site's curated lists and Valve's item stats say an item is for; an empty list means "not classified", not "offensive". On my_big_items_in_order, first_purchased is when the player finished buying the item (direct buy or last required component/recipe, null if absent/ambiguous), first_held is when it first sat in a usable inventory slot (not stash, backpack, or courier), delivery_delay_seconds is first_held minus first_purchased when positive, and my_team_courier_deaths_during_delivery lists hero-killed team couriers in [first_purchased, first_held] (a factual lead, not proof of courier owner or cargo). estimated_minutes_of_my_farm = item cost / my_economy.gold_per_min when that is known; "gives" and "does" are Valve's data. player_already_held_for_this_purpose groups big items the player already finished by the threats they cover. Shares of damage are over the 12 seconds before each death, of all damage taken in them (the two sums count enemy heroes only). An item built from a big item already held counts only the gold on top of it (gold_on_top_of_items_already_held). Pro shares are professional games, not this bracket; most_built_in_this_bracket (when present) is public games of this bracket and role (STRATZ).`,
17832
18066
  gaps: [
17833
18067
  ...role.kind ? [] : [{ topic: "role", reason: ctx.match ? role.gaps[0] ?? "role_not_established" : "no_match_data_for_this_game" }],
17834
18068
  ...economy ? [
@@ -17843,7 +18077,8 @@ function buildCheck(trace, args = {}, ctx = {}) {
17843
18077
  ...answersToTopKillers.some((k3) => k3.pro_items_against_this_killer) ? [{ topic: "pro_items_against_killers", reason: `professional_matches_since_${ITEM_VS_SOURCE.since}_all_releases_together` }] : [],
17844
18078
  ...answersToTopKillers.length && !pd.exact ? [{ topic: "killer_ability_data_of_this_game_patch", reason: `${pd.reason}; ${pd.name} data used` }] : [],
17845
18079
  { topic: "damage_type_of_abilities", reason: "spell_damage_is_not_split_into_magical_and_physical_here" },
17846
- { topic: "gold_spent_on_small_items", reason: "only_big_items_are_counted" }
18080
+ { topic: "gold_spent_on_small_items", reason: "only_big_items_are_counted" },
18081
+ ...timelineRes.gaps ?? []
17847
18082
  ]
17848
18083
  };
17849
18084
  }
@@ -17943,7 +18178,7 @@ var HERO2 = { type: "string", description: `Hero key as in match_overview, e.g.
17943
18178
  var SITUATION_TOOLS = [
17944
18179
  {
17945
18180
  name: "build_check",
17946
- description: "The player's build against what killed them. Gives their role and 1\u20135 position (from parsed match lanes or inferred from the replay), their economy (`my_economy`: GPM, net worth / 20:00 gold when known), where the damage in their deaths came from (which enemy, attacks or abilities), each big item they bought in order with its cost, what Valve lists for it and what it is for (built_for: an answer to attack damage, to spell damage, to disables, a gap closer, magic resistance, armor \u2014 empty means not classified), the gold put into each purpose, which big items the player already held for each purpose (player_already_held_for_this_purpose), for each of the (up to two) enemies who killed them most what that hero's abilities do in Valve's words, the shop's big items whose Valve data acts on that enemy's kind of damage (disarm, push, physical immunity, damage block or return, lowered attack speed, armor; or spell immunity, magic barrier, magic resistance) with their cost, and the items pros on this hero build clearly more often against that hero (answers_to_top_killers), each with what it does, `estimated_minutes_of_my_farm` (item cost divided by the player's GPM) and whether the player held it, what players of this bracket and role build on the hero in public games (most_built_in_this_bracket, when known), the hero's most-built professional items with when the player had them, and when each side got its first gap closer (Blink Dagger and the like). Use it before saying anything about what an item is, what the player's build answered, or what to buy.",
18181
+ description: "The player's build against what killed them. Gives their role and 1\u20135 position (from parsed match lanes or inferred from the replay), their economy (`my_economy`: GPM, net worth / 20:00 gold when known), where the damage in their deaths came from (which enemy, attacks or abilities), each big item they bought in order with its purchase vs delivery timing (`first_purchased`, `first_held`, positive `delivery_delay_seconds`, and any `my_team_courier_deaths_during_delivery`, alongside match-wide `my_team_courier_deaths`), its cost, what Valve lists for it and what it is for (built_for: an answer to attack damage, to spell damage, to disables, a gap closer, magic resistance, armor \u2014 empty means not classified), the gold put into each purpose, which big items the player already held for each purpose (player_already_held_for_this_purpose), for each of the (up to two) enemies who killed them most what that hero's abilities do in Valve's words, the shop's big items whose Valve data acts on that enemy's kind of damage (disarm, push, physical immunity, damage block or return, lowered attack speed, armor; or spell immunity, magic barrier, magic resistance) with their cost, and the items pros on this hero build clearly more often against that hero (answers_to_top_killers), each with what it does, `estimated_minutes_of_my_farm` (item cost divided by the player's GPM) and whether the player held it, what players of this bracket and role build on the hero in public games (most_built_in_this_bracket, when known), the hero's most-built professional items with when the player had them, and when each side got its first gap closer (Blink Dagger and the like). Use it before saying anything about what an item is, what the player's build answered, or what to buy.",
17947
18182
  input_schema: { type: "object", properties: { hero: HERO2 }, required: ["hero"], additionalProperties: false },
17948
18183
  run: buildCheck
17949
18184
  },
@@ -21306,7 +21541,8 @@ function namesIn(value, lang) {
21306
21541
  }
21307
21542
  function resolveRef(trace, ref, { hero, lang = "en", match = null, bracketData }) {
21308
21543
  if (typeof ref !== "string" || !REF.test(ref)) return null;
21309
- const ctx = { match, perspective: hero, lang, ultimateOf: ultimateOf2, ultimatesOf, ...bracketData ? { bracketData } : {} };
21544
+ const pd = patchForGame(trace?.match_id, match);
21545
+ const ctx = { match, perspective: hero, lang, ultimateOf: ultimateOf2, ultimatesOf, patchItems: pd.items, ...bracketData ? { bracketData } : {} };
21310
21546
  const [kind, a, b, c] = ref.split(":");
21311
21547
  const run = (name2, args) => {
21312
21548
  const r = runTraceTool(trace, name2, args, ctx);
@@ -22179,9 +22415,9 @@ function reviewToolkit({ trace, hero, lang, match = null, webSearch = webSearchF
22179
22415
  const seat = trace.heroes.find((h) => h.key === String(hero).trim().toLowerCase().replace(/^npc_dota_hero_/, "").replace(/[\s-]+/g, "_"));
22180
22416
  if (!seat) return null;
22181
22417
  const lookups = [...TRACE_TOOLS, ...KNOWLEDGE_TOOLS, WEB_SEARCH_TOOL];
22182
- const ctx = { match, perspective: seat.key, lang: language, ultimateOf: ultimateOf2, ultimatesOf };
22183
- const knowledge = new Map(KNOWLEDGE_TOOLS.map((t6) => [t6.name, t6]));
22184
22418
  const pd = patchForGame(trace.match_id, match);
22419
+ const ctx = { match, perspective: seat.key, lang: language, ultimateOf: ultimateOf2, ultimatesOf, patchItems: pd.items };
22420
+ const knowledge = new Map(KNOWLEDGE_TOOLS.map((t6) => [t6.name, t6]));
22185
22421
  const gamePatch2 = pd.exact || /hotfix/.test(pd.reason ?? "") ? { name: pd.name, released: RELEASES.find((r) => r.name === pd.name)?.rollout_by ?? null } : { name: null, released: null, reason: pd.reason ?? "patch_not_established" };
22186
22422
  const names2 = heroNames(trace, language);
22187
22423
  return {
@@ -22191,7 +22427,7 @@ function reviewToolkit({ trace, hero, lang, match = null, webSearch = webSearchF
22191
22427
  /** Count n web searches already made (a resumed review's): the limit is per review, not per restart. */
22192
22428
  spendSearches: (n) => webSearch?.spend?.(n),
22193
22429
  runTool: (name2, args) => name2 === WEB_SEARCH_TOOL.name ? webSearch(args ?? {}, { patch: gamePatch2 }) : withHeroNames(roshanGapPointsToTool(knowledge.has(name2) ? { tool: name2, ...knowledge.get(name2).run(trace, args, ctx) } : runTraceTool(trace, name2, args, ctx), trace), names2, language),
22194
- patch: (({ name: name2, hotfix, exact, how, reason }) => ({ name: name2, ...hotfix ? { hotfix } : {}, exact, ...how ? { known_from: how } : {}, ...exact ? {} : { reason } }))(patchForGame(trace.match_id, match)),
22430
+ patch: (({ name: name2, hotfix, exact, how, reason }) => ({ name: name2, ...hotfix ? { hotfix } : {}, exact, ...how ? { known_from: how } : {}, ...exact ? {} : { reason } }))(pd),
22195
22431
  context: { match_id: trace.match_id, player_hero: seat.key, hero_names: names2, place_names: placeNames(language), ...scoreboard(match, seat.key) ? { scoreboard: scoreboard(match, seat.key) } : {} }
22196
22432
  };
22197
22433
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qianhaoq/dsh-dota2ai",
3
- "version": "0.2.12",
3
+ "version": "0.2.13",
4
4
  "description": "dota2.ai for DSH: standalone replay review page, DSH host-model agent, coach tools and skill",
5
5
  "icon": "./icon.svg",
6
6
  "homepage": "https://dota2.ai",