@hackbuild/agents-views 0.2.4 → 0.2.5

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/yard/scope.js +17 -1
  2. package/package.json +1 -1
@@ -1567,6 +1567,7 @@ function sense(t) {
1567
1567
  if (o.id === 'ball' && ball.held) vis = false;
1568
1568
  if (brain.cur === 'sleep' && dog.posture.down > 0.7 && (!ON('L.sleep') || brain.stage === 'nrem' || brain.stage === 'rem')) vis = false;
1569
1569
  const p = percepts[o.id] || (percepts[o.id] = { id: o.id, seen: -1e9, pos: V3(), vis: false, sal: 0, kind: o.kind || o.id, net: 0 });
1570
+ p.frame = t;
1570
1571
  // read only tap: a sense event when something comes into view after 3 s out of it
1571
1572
  if (vis && !p.vis && t - p.seen > 3) p.ev = EV.emit({ agent: 'dog', kind: 'sense', sense: 'eye', text: (p.seen > -1e8 ? 'saw ' : 'first saw ') + (o.id === 'you' ? 'moheeb' : o.id.replace(/\d+$/, '')) + ' at ' + dist.toFixed(1) + ' m' });
1572
1573
  p.vis = vis; p.obj = o.obj; p.dist = dist; p.speed = speed;
@@ -1578,6 +1579,8 @@ function sense(t) {
1578
1579
  p.net = Math.max(0, p.net - 0.02);
1579
1580
  }
1580
1581
  for (const k in percepts) if (k.startsWith('treat') && !treats[+k.slice(5)]) delete percepts[k];
1582
+ // a thing gone from the scene this frame (the human out the gate, a hidden squirrel) is no longer in view
1583
+ for (const k in percepts) { const p = percepts[k]; if (p.frame !== t && p.vis) { p.vis = false; p.sal = 0; } }
1581
1584
  }
1582
1585
  // remembered position: errors grow with time but stay near the target (Fiset 2003)
1583
1586
  function memPos(p) { const age = Math.max(0, now - p.seen); return p.err ? p.pos.clone().addScaledVector(p.err, 0.25 * Math.sqrt(age / 60)) : p.pos.clone(); }
@@ -3071,7 +3074,18 @@ function handPos(out = V3()) { return HUM.hand ? HUM.hand.getWorldPosition(out)
3071
3074
  const TASK_LAYERS = { get_ball: ['kneel'], pet: ['kneel', 'crouch'], feed: ['kneel'] };
3072
3075
  // read only tap: where the next task comes from (rule, routine, mind, you), set by the caller
3073
3076
  let humSrcNext = null;
3077
+ // back through the gate early: a task or a treat while he is out ends the errand, so the dog's
3078
+ // senses and the minds panel see him again and the dog greets him for the time he was gone
3079
+ function humBack() {
3080
+ if (!HUM.away) return;
3081
+ const T = HUM.task, hours = T && T.name === 'errand' ? T.args.hours * Math.min(1, (now - HUM.awayT0) / Math.max(HUM.awayDur, 1e-3)) : 0.5;
3082
+ HUM.away = false; HUM.root.visible = true;
3083
+ brain.reunion(hours);
3084
+ // a treat leaves the errand running: it goes on from the walk back to his seat
3085
+ if (T && T.name === 'errand') T.s = 'back';
3086
+ }
3074
3087
  function startTask(name, args = {}, why = '') {
3088
+ if (name !== 'errand') humBack();
3075
3089
  const src = humSrcNext || (args.user ? 'you' : 'task'); humSrcNext = null;
3076
3090
  if (src === 'rule') HUM.lastPlan = { at: now, rule: why, choice: name };
3077
3091
  HUM.taskEv = EV.emit({ agent: 'human', kind: 'act', text: name.replace('_', ' ') + (why ? ', ' + why : ''), cause: src === 'rule' && /dog/.test(why) ? brain.evAct || null : src === 'mind' ? HUM.mindEv || null : null });
@@ -3548,7 +3562,8 @@ DO: one of ${HUM_DO.join(', ')}`;
3548
3562
  vlmLog({ t: callT, who: 'human', kind: 'think', prompt, text: txt, ms: r.ms, tokens: r.tokens, ok: true });
3549
3563
  HUM.mindEv = EV.emit({ agent: 'human', kind: 'model', text: 'his mind replied in ' + (r.ms / 1000).toFixed(1) + ' s: ' + txt.replace(/\s+/g, ' ').slice(0, 90) });
3550
3564
  humSrcNext = 'mind';
3551
- const say = ((txt.match(/SAY:\s*(.+)/i) || [])[1] || txt.split('\n')[0] || '').replace(/^["']|["']$/g, '').replace(new RegExp('[' + String.fromCharCode(0x2013, 0x2014) + ']', 'g'), ',').trim();
3565
+ // only a SAY line is spoken: a small model that answers in the dog's SAW, THOUGHT or GOAL shape says nothing
3566
+ const say = ((txt.match(/^\s*SAY:\s*(.+)$/im) || [])[1] || '').replace(/^["']|["']$/g, '').replace(new RegExp('[' + String.fromCharCode(0x2013, 0x2014) + ']', 'g'), ',').trim();
3552
3567
  const doL = ((txt.match(/DO:\s*(.+)/i) || [])[1] || '').toLowerCase();
3553
3568
  if (vlm.last) vlm.last.plan = { say, do: doL };
3554
3569
  $('humMind').textContent = 'say: ' + say + '\ndo: ' + (doL || '?') + ' (' + (r.ms / 1000).toFixed(1) + ' s)';
@@ -3612,6 +3627,7 @@ function throwBall(to) {
3612
3627
  startTask('throw', { to, user: true }, 'you asked him to throw');
3613
3628
  }
3614
3629
  function tossTreat(noReward) {
3630
+ humBack();
3615
3631
  if (!noReward) brain.reward(ON('L.learn') ? 0.5 : 1, 'treat');
3616
3632
  const near = dist2(dog.pos, YOU) < 1.6;
3617
3633
  if (near && !noReward) { brain.d.hunger = clamp(brain.d.hunger - 0.08, 0, 1); brain.say('crunch, thank you', 1.6); return; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hackbuild/agents-views",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "Views that bind the agents packages to the hackbuild-ui class layer: the behaviour, utility and drive bars, the cues by acts associations table, the eye inset, and Yard, the dog simulator's stage and rack as one view. Each small view ships as a Vue component and as a custom element.",
5
5
  "type": "module",
6
6
  "license": "MIT",