@startsimpli/integrations 0.2.186 → 0.2.187

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": "@startsimpli/integrations",
3
- "version": "0.2.186",
3
+ "version": "0.2.187",
4
4
  "description": "Provider-agnostic types, API clients, hooks, and UI primitives for email + calendar integrations across StartSimpli apps, plus foundry customer email (subpath ./comms).",
5
5
  "license": "MIT",
6
6
  "homepage": "https://startsimpli.com",
@@ -50,8 +50,8 @@
50
50
  "react-native": ">=0.74.0",
51
51
  "@startsimpli/ui-native": ">=0.1.12",
52
52
  "react-native-safe-area-context": ">=4.0.0",
53
- "@startsimpli/ui": "^0.4.186",
54
53
  "@startsimpli/auth": "^0.4.53",
54
+ "@startsimpli/ui": "^0.4.186",
55
55
  "@startsimpli/utils": "^0.4.20"
56
56
  },
57
57
  "peerDependenciesMeta": {
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { describe, expect, it, vi } from 'vitest';
7
7
 
8
- import { ACTIVITY_QUESTION, activityOf, composeActivity, loadActivity } from '../corpus/converse/activity';
8
+ import { ACTIVITY_QUESTION, activityOf, composeActivity, forOwner, loadActivity } from '../corpus/activity';
9
9
  import { questionWindow } from '../corpus/ask-items-intent';
10
10
  import type { Commitment, SourceDocument } from '../corpus/types';
11
11
 
@@ -74,6 +74,19 @@ describe('what happened in the window', () => {
74
74
  });
75
75
  });
76
76
 
77
+ describe('only what is his', () => {
78
+ it("leaves out another member's to-dos and notes, keeps ones with no owner", () => {
79
+ const window = { from: '2026-11-15', to: '2026-11-15', label: 'yesterday' };
80
+ const items = [
81
+ todo('a', 'Mine', { status: 'done', resolvedAt: '2026-11-15T20:00:00Z', ownerSub: 'me' } as never),
82
+ todo('b', 'Theirs', { status: 'done', resolvedAt: '2026-11-15T20:00:00Z', ownerSub: 'qa-user' } as never),
83
+ todo('c', 'No owner', { status: 'done', resolvedAt: '2026-11-15T21:00:00Z' }),
84
+ ];
85
+ const got = forOwner(activityOf({ items, docs: [], window, timeZone: TZ }), 'me');
86
+ expect(got.finished.map((i) => i.title)).toEqual(['No owner', 'Mine']);
87
+ });
88
+ });
89
+
77
90
  describe('reading it', () => {
78
91
  it('asks the tenant for to-dos changed since the window start and notes inside the window, nothing else', async () => {
79
92
  const listCommitments = vi.fn(async () => ({ results: [todo('a', 'Ship', { status: 'done', resolvedAt: '2026-11-15T20:00:00Z' })], next: null }));
@@ -50,6 +50,33 @@ function retrievedFor(question: string): RetrievedDocument[] {
50
50
 
51
51
  // ---------------------------------------------------------------------------
52
52
 
53
+ describe('date questions in Ask mode are answered from when things happened', () => {
54
+ const NOW = Date.parse('2026-11-16T17:00:00Z');
55
+ const commitments = {
56
+ listCommitments: async () => ({
57
+ count: 1, next: null, previous: null,
58
+ results: [{ id: 'c1', externalId: 'c1', title: 'Add a prompt box', status: 'open', firstSeenAt: '2026-11-15T16:00:00Z', lastSeenAt: '2026-11-15T16:00:00Z', source: 'voice', scope: { orgId: FIXTURE_ORG } }],
59
+ }),
60
+ } as never;
61
+
62
+ it.each(['What did I do yesterday?', 'What did I do this week?', 'what have I done today'])('%s: composed from the window, cited, no model call', async (q) => {
63
+ const calls: unknown[] = [];
64
+ const corpus = createFixtureCorpusApi({ scope: SCOPE });
65
+ const out = await askCorpus(ask(q), { corpus, llm: scriptedLlm({ answer: 'should not be used', citations: [] }, calls), commitments }, { now: NOW, timeZone: 'America/Denver' });
66
+ expect(calls).toEqual([]);
67
+ expect(out.status).toBe('answered');
68
+ expect(out.answer).not.toMatch(/No answer|none matched/i);
69
+ if (q.includes('yesterday')) { expect(out.answer).toMatch(/^Yesterday you added 1 new to-do: Add a prompt box/); expect(out.citations.map((c) => c.documentId)).toContain('item:c1'); }
70
+ });
71
+
72
+ it('a question with a topic is still searched', async () => {
73
+ const calls: unknown[] = [];
74
+ const corpus = createFixtureCorpusApi({ scope: SCOPE });
75
+ await askCorpus(ask('What did I do about the Acme renewal yesterday?'), { corpus, llm: scriptedLlm({ answer: 'ok', citations: [] }, calls), commitments }, { now: NOW, timeZone: 'America/Denver' });
76
+ expect(calls.length).toBe(1);
77
+ });
78
+ });
79
+
53
80
  describe('the reads for one question run together, not one after another', () => {
54
81
  it('asks for the source list while the document search is still in flight', async () => {
55
82
  const base = createFixtureCorpusApi({ scope: SCOPE });
@@ -6,14 +6,21 @@
6
6
  * meetings), and the answer is composed in meeting style: what was finished, what was added, how many notes, with the first three
7
7
  * titles and a count. READ ONLY: nothing here writes.
8
8
  */
9
- import { addDays, questionWindow } from '../ask-items-intent';
10
- import { speakable } from '../briefing/speak';
11
- import { localDate } from '../today';
12
- import type { Commitment, CommitmentApi, CorpusApi, SourceDocument } from '../types';
9
+ import { itemAsDocument } from './ask-items';
10
+ import { addDays, questionWindow } from './ask-items-intent';
11
+ import { speakable } from './briefing/speak';
12
+ import { localDate } from './today';
13
+ import type { Commitment, CommitmentApi, CorpusApi, SourceDocument } from './types';
13
14
 
14
15
  export type ActivityWindow = NonNullable<ReturnType<typeof questionWindow>>;
15
- export interface ActivityNote { id: string; title: string; kind: 'conversation' | 'voice' | 'other'; at: string }
16
- export interface Activity { finished: Array<{ id: string; title: string; at: string }>; added: Array<{ id: string; title: string; at: string }>; notes: ActivityNote[] }
16
+ export interface ActivityNote { id: string; title: string; kind: 'conversation' | 'voice' | 'other'; at: string; owner?: string }
17
+ export interface Activity {
18
+ finished: Array<{ id: string; title: string; at: string; owner?: string }>;
19
+ added: Array<{ id: string; title: string; at: string; owner?: string }>;
20
+ notes: ActivityNote[];
21
+ /** The records behind the answer (first few of each), so Ask can cite them. */
22
+ docs?: SourceDocument[];
23
+ }
17
24
 
18
25
  const WINDOWS = 'today|yesterday|this week|last week|this month|last month|recently|lately';
19
26
  /** What did I do / finish / work on / get done, or what happened, in a named window. Whole-question shapes only. */
@@ -24,6 +31,8 @@ export const ACTIVITY_QUESTION = new RegExp(
24
31
  /** Internal rows that are not "things he did" (the assistant's own bookkeeping). */
25
32
  const INTERNAL = new Set(['notify_state', 'relay_inbox', 'fleet_status', 'briefing_actions', 'decision', 'briefing']);
26
33
 
34
+ const ownerOf = (i: Commitment): string | undefined => i.ownerSub || i.scope?.ownerSub || undefined;
35
+
27
36
  const dayOf = (iso: string | null | undefined, timeZone: string) => {
28
37
  const t = iso ? Date.parse(iso) : NaN;
29
38
  return Number.isFinite(t) ? localDate(t, timeZone) : null;
@@ -37,17 +46,33 @@ export function activityOf(input: { items: Commitment[]; docs: SourceDocument[];
37
46
  const finished = input.items
38
47
  .filter((i) => i.status === 'done' && inside(doneAt(i)))
39
48
  .sort((a, b) => String(doneAt(b)).localeCompare(String(doneAt(a))))
40
- .map((i) => ({ id: i.id, title: i.title, at: String(doneAt(i)) }));
49
+ .map((i) => ({ id: i.id, title: i.title, at: String(doneAt(i)), ...(ownerOf(i) ? { owner: ownerOf(i) } : {}) }));
41
50
  const finishedIds = new Set(finished.map((i) => i.id));
42
51
  const added = input.items
43
52
  .filter((i) => !finishedIds.has(i.id) && inside(i.firstSeenAt))
44
53
  .sort((a, b) => String(a.firstSeenAt).localeCompare(String(b.firstSeenAt)))
45
- .map((i) => ({ id: i.id, title: i.title, at: String(i.firstSeenAt) }));
54
+ .map((i) => ({ id: i.id, title: i.title, at: String(i.firstSeenAt), ...(ownerOf(i) ? { owner: ownerOf(i) } : {}) }));
46
55
  const notes = input.docs
47
56
  .filter((d) => !INTERNAL.has(String(d.source)) && inside(d.occurredAt))
48
57
  .sort((a, b) => String(a.occurredAt).localeCompare(String(b.occurredAt)))
49
- .map((d) => ({ id: d.id, title: d.title, kind: d.source === 'conversation' ? 'conversation' as const : d.source === 'voice' ? 'voice' as const : 'other' as const, at: String(d.occurredAt) }));
50
- return { finished, added, notes };
58
+ .map((d) => ({ id: d.id, title: d.title, kind: d.source === 'conversation' ? 'conversation' as const : d.source === 'voice' ? 'voice' as const : 'other' as const, at: String(d.occurredAt), ...(d.scope?.ownerSub ? { owner: d.scope.ownerSub } : {}) }));
59
+ const byId = new Map(input.items.map((i) => [i.id, i]));
60
+ const ctx = { now: Date.now(), timeZone };
61
+ const cited: SourceDocument[] = [
62
+ ...finished.slice(0, 6).map((f) => itemAsDocument(byId.get(f.id)!, ctx)),
63
+ ...added.slice(0, 6).map((a) => itemAsDocument(byId.get(a.id)!, ctx)),
64
+ ...input.docs.filter((d) => notes.slice(0, 6).some((n) => n.id === d.id)),
65
+ ];
66
+ return { finished, added, notes, docs: cited };
67
+ }
68
+
69
+ /** Only what is HIS: an entry that names another owner (a teammate, a test account) is left out; one with no owner stays. */
70
+ export function forOwner(a: Activity, ownerSub: string | undefined): Activity {
71
+ if (!ownerSub) return a;
72
+ const mine = <T extends { owner?: string }>(list: T[]) => list.filter((x) => !x.owner || x.owner === ownerSub);
73
+ const finished = mine(a.finished), added = mine(a.added), notes = mine(a.notes);
74
+ const keep = new Set([...finished, ...added, ...notes].map((x) => x.id));
75
+ return { finished, added, notes, docs: (a.docs ?? []).filter((d) => keep.has(d.id.replace(/^item:/, '')) || keep.has(d.id) || keep.has(String(d.sourceRef ?? ''))) };
51
76
  }
52
77
 
53
78
  const cap = (s: string) => s[0].toUpperCase() + s.slice(1);
package/src/corpus/ask.ts CHANGED
@@ -18,6 +18,8 @@
18
18
  * cannot trust with a contract. A model that cites a document id it was never
19
19
  * given has invented a source, and the only safe rendering of that is to say so.
20
20
  */
21
+ import { ACTIVITY_QUESTION, composeActivity, forOwner, loadActivity } from './activity';
22
+ import { questionWindow } from './ask-items-intent';
21
23
  import { retrieveItems } from './ask-items';
22
24
  import { retrieveProjects } from './ask-projects';
23
25
  import { moneyEventAsDocument } from './entities';
@@ -364,6 +366,26 @@ export async function askCorpus(
364
366
  return emptyResult(request, llm, 'This session has no tenant scope, so there is nothing to search.');
365
367
  }
366
368
 
369
+ // "What did I do yesterday / this week": a question about WHEN, not about words, so no keyword search can answer it (it said "No
370
+ // answer... none matched"). Answered from the records in that window, cited, without the model.
371
+ if (request.mode === 'ask' && deps.commitments && ACTIVITY_QUESTION.test(request.question.trim())) {
372
+ const window = questionWindow(request.question, options.now ?? Date.now(), options.timeZone ?? 'UTC');
373
+ if (window) {
374
+ const found = forOwner(await loadActivity({ planning: deps.commitments, corpus }, window, options.timeZone ?? 'UTC'), options.ownerSub);
375
+ const docs = found.docs ?? [];
376
+ return {
377
+ status: 'answered',
378
+ answer: composeActivity(window, found),
379
+ citations: docs.map((document) => ({ documentId: document.id, document, quote: document.title })),
380
+ considered: [],
381
+ unresolvedCitations: [],
382
+ droppedOutOfScope: 0,
383
+ provider: llm.describe(),
384
+ freshness: await corpus.listSources().catch(() => [] as SourceFreshness[]),
385
+ };
386
+ }
387
+ }
388
+
367
389
  // The four reads below do not depend on each other, so they run together (they used to run one after another, each a
368
390
  // round trip to the tenant: the biggest part of an answer's wait besides the model).
369
391
  const asking = request.mode === 'ask';
@@ -18,7 +18,7 @@ import type { BriefingItem } from '../briefing/types';
18
18
  import { FLEET_FRESH_MS, ageWords } from './fleet';
19
19
  import { routeUtterance } from './route';
20
20
  import { spokenSummary } from './spoken-summary';
21
- import { ACTIVITY_QUESTION, composeActivity, type Activity, type ActivityWindow } from './activity';
21
+ import { ACTIVITY_QUESTION, composeActivity, forOwner, type Activity, type ActivityWindow } from '../activity';
22
22
  import { questionWindow } from '../ask-items-intent';
23
23
  import { BRIEF_ME, NEEDS_ME, buildQueue, firstPrompt, relayItemsFrom, stepBriefing, type BriefingEffect, type BriefingState } from './briefing-queue';
24
24
  import type { ConverseBrain, HistoryLine } from './types';
@@ -187,7 +187,7 @@ export function createConverseBrain(deps: ConverseBrainDeps): ConverseBrain {
187
187
  if (deps.loadActivity && ACTIVITY_QUESTION.test(utterance.trim())) {
188
188
  const window = questionWindow(utterance, now, timeZone);
189
189
  if (window) {
190
- const found = await timed('activity', () => deps.loadActivity!(window, timeZone));
190
+ const found = forOwner(await timed('activity', () => deps.loadActivity!(window, timeZone)), deps.ownerSub);
191
191
  return { text: composeActivity(window, found) };
192
192
  }
193
193
  }
@@ -32,5 +32,5 @@ export type { ConverseRoute } from './route';
32
32
  export { saveFleetSnapshot, loadFleetSnapshot, fleetExternalId, FLEET_SOURCE, ageWords, FLEET_FRESH_MS } from './fleet';
33
33
  export type { FleetSnapshot } from './fleet';
34
34
  export { PASSED_TO_RELAY, NO_FLEET_STATUS, NO_FILLER } from './brain';
35
- export { ACTIVITY_QUESTION, activityOf, composeActivity, loadActivity } from './activity';
36
- export type { Activity, ActivityWindow, ActivityNote } from './activity';
35
+ export { ACTIVITY_QUESTION, activityOf, composeActivity, forOwner, loadActivity } from '../activity';
36
+ export type { Activity, ActivityWindow, ActivityNote } from '../activity';