@ateam-ai-mobile/core 0.1.40 → 0.1.42

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ateam-ai-mobile/core",
3
- "version": "0.1.40",
3
+ "version": "0.1.42",
4
4
  "description": "Headless ADAS SDK core — auth bridge, API client, chat/job streaming, MCP calls, theme tokens. No UI, no Expo dependencies.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -0,0 +1,39 @@
1
+ // The goal checklist of a running job: goals as the main lines, the tools that stream under the current goal.
2
+ // Core sends `goals` ({l:[[id,title,"d"|"t"]], c}) on the job message only when it changes (Core utils/liveGoals.js), so a
3
+ // message without it means "same as before". Tools are not sent at all: they already arrive as the live `→ tool` line and
4
+ // are filed here under the goal current at that moment. Same rule as Core's web chat (packages/side-chat/src/liveGoals.js);
5
+ // the two cannot share a file across repos, so keep them equal. Pure and import-free.
6
+
7
+ export type GoalWire = { l: [string, string, string][]; c?: string | null };
8
+ export type JobGoals = { l: [string, string, string][]; c: string | null; tools: Record<string, string[]>; lastKey?: string; ids?: string };
9
+ export type GoalRow = { id: string; title: string; state: 'done' | 'current' | 'todo'; tools: string[] };
10
+
11
+ const MAX_TOOLS = 4;
12
+
13
+ export function foldGoals(prev: JobGoals | undefined, wire: GoalWire | undefined, liveMessage?: string, liveSeq?: number): JobGoals | undefined {
14
+ const g = wire && Array.isArray(wire.l) ? wire : null;
15
+ if (g && g.l.length === 0) return undefined; // Core says the job has no goals now (a hand-off to a job without a plan)
16
+ const goals = g ? { l: g.l, c: g.c ?? null } : prev ? { l: prev.l, c: prev.c } : null;
17
+ if (!goals) return undefined;
18
+ // A different list (another job's plan, or a re-plan) starts with no tools: plans reuse goal ids, so old tools would land on the new goals.
19
+ const ids = goals.l.map(x => x[0]).join('|');
20
+ const tools = ids === prev?.ids ? { ...(prev?.tools || {}) } : {};
21
+ // A snapshot that only moved the current goal carries the SAME last progress entry as before: file a tool only when that
22
+ // entry is new (its seq changed; an entry without a seq falls back to "the message changed").
23
+ const key = liveSeq != null ? `s${liveSeq}` : `m${liveMessage ?? ''}`;
24
+ const fresh = key !== prev?.lastKey;
25
+ if (fresh && goals.c && liveMessage && liveMessage.startsWith('→ ')) {
26
+ const tool = liveMessage.slice(2).trim();
27
+ const list = tools[goals.c] || [];
28
+ if (tool && list[list.length - 1] !== tool) tools[goals.c] = [...list, tool].slice(-MAX_TOOLS);
29
+ }
30
+ return { ...goals, tools, lastKey: key, ids };
31
+ }
32
+
33
+ export function goalRows(goals: JobGoals | undefined): GoalRow[] {
34
+ if (!goals?.l?.length) return [];
35
+ return goals.l.map(([id, title, s]) => {
36
+ const state = s === 'd' ? 'done' : id === goals.c ? 'current' : 'todo';
37
+ return { id, title, state, tools: state === 'current' ? goals.tools?.[id] || [] : [] };
38
+ });
39
+ }
@@ -12,6 +12,7 @@ import { create } from 'zustand';
12
12
  import type { StoreApi, UseBoundStore } from 'zustand';
13
13
  import { getCoreApiUrl, getTenant, getUser } from '../config';
14
14
  import { blocksToText } from './blockText';
15
+ import { foldGoals } from './liveGoals';
15
16
  import { coreHeaders, snapshotToProgress, isTerminalSnapshot, normalizeJobStatus, blocksToAttachments } from './store';
16
17
  import { mergeSideChatHistory } from './sideChatPure';
17
18
  import type { Message, JobProgress } from './types';
@@ -64,8 +65,14 @@ function turnToMessages(turn: any): Message[] {
64
65
  function createSideChatStore(pageId: string): SideChatStore {
65
66
  return create<SideChatState>((set, get) => {
66
67
  const local = (m: Omit<Message, 'local'>): Message => ({ ...m, local: true });
67
- const patchJob = (jobId: string, p: Partial<JobProgress>) =>
68
- set(s => ({ messages: s.messages.map(m => (m.jobProgress?.jobId === jobId ? { ...m, jobProgress: { ...m.jobProgress, ...p } as JobProgress } : m)) }));
68
+ const patchJob = (jobId: string, p: Partial<JobProgress>) => {
69
+ const { goalsWire, ...rest } = p;
70
+ set(s => ({
71
+ messages: s.messages.map(m => (m.jobProgress?.jobId === jobId
72
+ ? { ...m, jobProgress: { ...m.jobProgress, ...rest, goals: foldGoals(m.jobProgress.goals, goalsWire, p.liveProgress?.message, p.liveProgress?.seq) } as JobProgress }
73
+ : m)),
74
+ }));
75
+ };
69
76
 
70
77
  // Follow the job by reading its status until it ends (a hand-over keeps going), then read the saved turn.
71
78
  async function follow(jobId: string, chainId: string) {
package/src/chat/store.ts CHANGED
@@ -18,6 +18,7 @@ import { focusPlugin } from '../utils/hostIntents';
18
18
  import type { OutgoingAttachment } from '../storage/types';
19
19
  import { prepareAttachments } from './attachments';
20
20
  import { blocksToText } from './blockText';
21
+ import { foldGoals } from './liveGoals';
21
22
  import type { Message, MessageAttachment, JobProgress, UIAction } from './types';
22
23
 
23
24
  // ---------------------------------------------------------------------------
@@ -94,6 +95,7 @@ function extractLiveProgress(snap: any): JobProgress['liveProgress'] | undefined
94
95
  message: String(latest.message || ''),
95
96
  ...(latest.step != null ? { step: latest.step } : {}),
96
97
  ...(latest.total != null ? { total: latest.total } : {}),
98
+ ...(latest.seq != null ? { seq: latest.seq } : {}),
97
99
  };
98
100
  }
99
101
 
@@ -134,6 +136,7 @@ export function snapshotToProgress(snap: any, rootJobId: string): Partial<JobPro
134
136
  // Human-language status (additive; absent when disabled/uncached).
135
137
  if (typeof snap?.humanStatus === 'string' && snap.humanStatus) progress.humanStatus = snap.humanStatus;
136
138
  if (snap?.humanLabels && typeof snap.humanLabels === 'object') progress.humanLabels = snap.humanLabels;
139
+ if (snap?.goals && Array.isArray(snap.goals.l)) progress.goalsWire = snap.goals;
137
140
 
138
141
  if (pq) {
139
142
  progress.pendingQuestion = {
@@ -339,12 +342,14 @@ export const useChatStore = create<ChatState>((set, get) => ({
339
342
  ? slim.createdAt
340
343
  : (typeof slim.lastUpdate === 'number' ? slim.lastUpdate : Date.now());
341
344
  const chainLastUpdate = typeof slim.lastUpdate === 'number' ? slim.lastUpdate : chainCreatedAt;
345
+ const { goalsWire, ...progressRest } = progress;
342
346
  const jobProgress = {
343
347
  jobId: chainId,
344
348
  actorId: extractActorId(slim),
345
349
  status: 'running',
346
350
  chainStartedAt: chainCreatedAt,
347
- ...progress,
351
+ ...progressRest,
352
+ goals: foldGoals(undefined, goalsWire, progress.liveProgress?.message, progress.liveProgress?.seq),
348
353
  } as JobProgress;
349
354
 
350
355
  // Synthesize the user bubble if a hard refresh wiped the optimistic
@@ -592,7 +597,10 @@ export const useChatStore = create<ChatState>((set, get) => ({
592
597
  set(s => ({
593
598
  messages: s.messages.map(m => {
594
599
  if (m.jobProgress?.jobId === jobId) {
595
- const updated = { ...m.jobProgress, ...progress };
600
+ const { goalsWire, ...rest } = progress;
601
+ const updated = { ...m.jobProgress, ...rest };
602
+ // Goal checklist: goals arrive only when they change; the streamed `→ tool` line is filed under the current goal.
603
+ updated.goals = foldGoals(m.jobProgress.goals, goalsWire, progress.liveProgress?.message, progress.liveProgress?.seq);
596
604
  // Clear pendingQuestion when status is no longer paused
597
605
  if (progress.status && progress.status !== 'paused') {
598
606
  updated.pendingQuestion = undefined;
package/src/chat/types.ts CHANGED
@@ -25,13 +25,17 @@ export interface JobProgress {
25
25
  /** UI Action chips to attach to the assistant bubble when this job finishes. */
26
26
  resultActions?: UIAction[];
27
27
  /** Live progress from adas_emit_progress() — latest event from a running fat tool */
28
- liveProgress?: { message: string; step?: number; total?: number };
28
+ liveProgress?: { message: string; step?: number; total?: number; seq?: number };
29
29
  /** One warm, present-tense, localized line describing the current action
30
30
  * (backend statusI18n). Absent when disabled / not yet cached → fall back
31
31
  * to raw tokens. */
32
32
  humanStatus?: string;
33
33
  /** Lookup { rawToken → friendly phrase } for tokens in this snapshot. */
34
34
  humanLabels?: Record<string, string>;
35
+ /** The job's goal checklist, built from the goals Core streams on the job message plus the live `→ tool` line (chat/liveGoals.ts). */
36
+ goals?: import('./liveGoals').JobGoals;
37
+ /** The raw `goals` of ONE job message, in transit from snapshotToProgress to updateJobProgress (which folds it into `goals` and drops it). */
38
+ goalsWire?: import('./liveGoals').GoalWire;
35
39
  pendingQuestion?: {
36
40
  inputId: string;
37
41
  question: string;
package/src/index.ts CHANGED
@@ -213,6 +213,8 @@ export type {
213
213
  FileUploadRequest,
214
214
  } from './storage/types';
215
215
  export { MAX_ATTACHMENT_BYTES, MAX_INLINE_ATTACHMENT_BYTES } from './storage/types';
216
+ export { goalRows } from './chat/liveGoals';
217
+ export type { JobGoals, GoalRow } from './chat/liveGoals';
216
218
  export { prepareAttachments } from './chat/attachments';
217
219
  export type { WireAttachment } from './chat/attachments';
218
220