@things-factory/ai-assistant 10.1.272 → 10.1.273

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": "@things-factory/ai-assistant",
3
- "version": "10.1.272",
3
+ "version": "10.1.273",
4
4
  "main": "dist-server/index.js",
5
5
  "things-factory": true,
6
6
  "author": "heartyoh",
@@ -36,14 +36,14 @@
36
36
  "@operato/shell": "^10.29.69",
37
37
  "@operato/styles": "^10.0.0",
38
38
  "@operato/utils": "^10.29.76",
39
- "@things-factory/ai-client-base": "^10.1.272",
40
- "@things-factory/apptool-base": "^10.1.270",
41
- "@things-factory/attachment-base": "^10.1.271",
42
- "@things-factory/auth-base": "^10.1.271",
39
+ "@things-factory/ai-client-base": "^10.1.273",
40
+ "@things-factory/apptool-base": "^10.1.273",
41
+ "@things-factory/attachment-base": "^10.1.273",
42
+ "@things-factory/auth-base": "^10.1.273",
43
43
  "@things-factory/env": "^10.1.149",
44
- "@things-factory/help": "^10.1.270",
45
- "@things-factory/setting-base": "^10.1.271",
46
- "@things-factory/shell": "^10.1.270",
44
+ "@things-factory/help": "^10.1.273",
45
+ "@things-factory/setting-base": "^10.1.273",
46
+ "@things-factory/shell": "^10.1.273",
47
47
  "dompurify": "^3.0.0",
48
48
  "exceljs": "4.2.0",
49
49
  "graphql-scalars": "^1.22.0",
@@ -59,5 +59,5 @@
59
59
  "copyfiles": "^2.4.1",
60
60
  "rimraf": "^5.0.0"
61
61
  },
62
- "gitHead": "f87fefe0687eedf52a25cda1c54d59efabaf3dc2"
62
+ "gitHead": "0ead3ad069edf9f1ef5076caec85916bdb26728f"
63
63
  }
@@ -560,7 +560,7 @@ export class AssistantChatResolver {
560
560
  const { reply, suggestion } = splitNextRequest(result.reply)
561
561
 
562
562
  const answerDoors = doorsForAnswer(
563
- (result.loop.toolUsages ?? []).map((usage: any) => usage?.name).filter(Boolean),
563
+ result.loop.toolUsages ?? [],
564
564
  name => (findToolSpec(name, settings.toolCategories) as any)?.doors
565
565
  )
566
566
 
@@ -110,20 +110,31 @@ export function selectionAxesOf(rows: { role?: string; content?: string | null }
110
110
  type FrontMode = { toolCategories?: string[]; attachments?: { kinds?: string[] }; entryTargets?: string[]; readTargets?: string[] }
111
111
 
112
112
  /**
113
- * The records the open screen is about, among those the mode reads and enters (ADR-0061 decision 9). Nothing new is
114
- * declared: a read target's screen route is the page that lists it, and a key's last part is the axis of its record
115
- * (`office.contract` is the record of the axis `contract`) - reading and entering one record share its key.
113
+ * The records the open screen is about, among those the mode reads and enters (ADR-0061 decision 9). A key's page is
114
+ * the screen that lists its records (ReadTarget.screen.route), the screen a card's records are seen on
115
+ * (EntryTarget.screen) and the pages a read of one record names (DetailRead.frontPages); a key's last part is the axis
116
+ * of its record (`office.contract` is the record of the axis `contract`) - reading and entering one record share its key.
116
117
  */
117
118
  export function screenTargetKeys(mode: FrontMode, screen: TurnScreen, routeOf: (key: string) => string | undefined = key => readTargetOf(key)?.screen?.route): string[] {
118
119
  const keys = [...new Set([...(mode.readTargets ?? []), ...(mode.entryTargets ?? [])])]
119
120
  return keys.filter(
120
121
  key =>
121
- (!!screen.page && routeOf(key) === screen.page) ||
122
+ (!!screen.page && pagesOfKey(mode, key, routeOf).includes(screen.page)) ||
122
123
  (!!screen.subjectAxis && axesOfKey(mode, key).includes(screen.subjectAxis)) ||
123
124
  (!!screen.selectionAxes?.length && axesOfKey(mode, key).some(axis => screen.selectionAxes!.includes(axis)))
124
125
  )
125
126
  }
126
127
 
128
+ /**
129
+ * The pages a key is in front on. A card's own screen counts as its page: on 내 주간업무보고 the report line card was
130
+ * not in front, the model opened it with `openTools`, and the answer that followed was hidden (2026-11-12).
131
+ */
132
+ function pagesOfKey(mode: FrontMode, key: string, routeOf: (key: string) => string | undefined): string[] {
133
+ const card = (mode.entryTargets ?? []).includes(key) ? entryTargetOf(key)?.screen : undefined
134
+ const answer = (mode.readTargets ?? []).includes(key) ? detailReadOf(key)?.frontPages ?? [] : []
135
+ return [routeOf(key), card, ...answer].filter((page): page is string => !!page)
136
+ }
137
+
127
138
  /** The records a key is about: its last part, and the axes a card joins or a whole answer covers (EntryTarget.axes · DetailRead.axes). */
128
139
  function axesOfKey(mode: FrontMode, key: string): string[] {
129
140
  const card = (mode.entryTargets ?? []).includes(key) ? entryTargetOf(key)?.axes ?? [] : []
@@ -161,7 +172,7 @@ export function modeFrontCategories(mode: FrontMode, screen: TurnScreen = {}): s
161
172
  /** Each screen the mode could be asked from - a page that lists one of its records, a record's axis - for the boot report. */
162
173
  export function modeScreens(mode: FrontMode, routeOf: (key: string) => string | undefined = key => readTargetOf(key)?.screen?.route): TurnScreen[] {
163
174
  const keys = [...new Set([...(mode.readTargets ?? []), ...(mode.entryTargets ?? [])])]
164
- const pages = [...new Set([...keys.map(routeOf), ...conversationCategoriesOf().flatMap(one => one.frontPages ?? [])].filter(Boolean) as string[])]
175
+ const pages = [...new Set([...keys.flatMap(key => pagesOfKey(mode, key, routeOf)), ...conversationCategoriesOf().flatMap(one => one.frontPages ?? [])])]
165
176
  const axes = [...new Set(keys.flatMap(key => axesOfKey(mode, key)))]
166
177
  return [{}, ...pages.map(page => ({ page })), ...axes.map(subjectAxis => ({ subjectAxis }))]
167
178
  }
@@ -144,3 +144,38 @@ describe('a whole answer about any record is in front on their screens', () => {
144
144
  expect(modeFrontCategories(mode, { subjectAxis: 'cash-transaction' })).not.toContain('data-read:office.checks')
145
145
  })
146
146
  })
147
+
148
+ /* 2026-11-12: asked 「AI로 초안 작성」 on 내 주간업무보고, neither the week's read nor the report line card was in front. */
149
+ describe('a page puts in front the cards seen on it and the reads that name it', () => {
150
+ const line = {
151
+ key: 'office.weekly-report-line',
152
+ labelKey: 'label.line',
153
+ description: 'a line of the weekly report.',
154
+ mutation: 'mutation ($line: Line!) { saveLine(line: $line) { id } }',
155
+ variables: (row: any) => ({ line: row.values }),
156
+ appliedOf: (data: any) => ({ id: data?.saveLine?.id }),
157
+ fields: [{ name: 'content', type: 'string' as const, required: true }],
158
+ screen: 'my-weekly-report'
159
+ }
160
+ const week = { key: 'office.my-weekly-report', description: 'the week.', query: 'query ($weekStart: String!) { myWeeklyReport(weekStart: $weekStart) { id } }', args: [{ name: 'weekStart', type: 'date', required: true }], frontPages: ['my-weekly-report'] }
161
+ const writing = { ...mode, readTargets: [...mode.readTargets, week.key], entryTargets: [...mode.entryTargets, line.key] }
162
+ beforeEach(() => {
163
+ clearEntryTargets()
164
+ declareEntryTarget(line as any)
165
+ declareDetailRead(week as any)
166
+ })
167
+
168
+ it('★ on 내 주간업무보고 the week\'s read and the line card are in front', () => {
169
+ expect(screenTargetKeys(writing, { page: 'my-weekly-report' })).toEqual(['office.my-weekly-report', 'office.weekly-report-line'])
170
+ expect(modeFrontCategories(writing, { page: 'my-weekly-report' })).toEqual(expect.arrayContaining(['data-read:office.my-weekly-report', 'data-entry:office.weekly-report-line']))
171
+ })
172
+
173
+ it('★ not on another page, nor for a mode that does not read or enter them', () => {
174
+ expect(screenTargetKeys(writing, { page: 'cash-transaction-list' })).toEqual(['office.cash-transaction'])
175
+ expect(screenTargetKeys(mode, { page: 'my-weekly-report' })).toEqual([])
176
+ })
177
+
178
+ it('the boot report walks those pages, so they are counted against the budget', () => {
179
+ expect(modeScreens(writing)).toContainEqual({ page: 'my-weekly-report' })
180
+ })
181
+ })
@@ -13,7 +13,7 @@ describe('message doors', () => {
13
13
  const doorsOf = (name: string) =>
14
14
  ({ getPlantOverview: ['Query.jobOrders', 'Query.productionReports'], findJobOrders: ['Query.jobOrders'] } as any)[name]
15
15
 
16
- expect(doorsForAnswer(['getPlantOverview', 'findJobOrders'], doorsOf)).toEqual([
16
+ expect(doorsForAnswer([{ name: 'getPlantOverview' }, { name: 'findJobOrders', outcome: 'ok' }], doorsOf)).toEqual([
17
17
  'Query.jobOrders',
18
18
  'Query.productionReports'
19
19
  ])
@@ -21,17 +21,54 @@ describe('message doors', () => {
21
21
 
22
22
  it('사람의 말과 문 없는 도구는 빈 목록이다 — 누구나 읽는다', () => {
23
23
  expect(doorsForAnswer([], () => undefined)).toEqual([])
24
- expect(doorsForAnswer(['getOpenScene'], () => [])).toEqual([])
24
+ expect(doorsForAnswer([{ name: 'getOpenScene' }], () => [])).toEqual([])
25
25
  })
26
26
 
27
27
  it('★ 등록기가 모르는 도구는 아무도 못 지나는 자리로 적힌다', async () => {
28
- const doors = doorsForAnswer(['whoIsThis'], () => undefined)
28
+ const doors = doorsForAnswer([{ name: 'whoIsThis', outcome: 'ok' }], () => undefined)
29
29
  expect(doors).toEqual(['unresolved:whoIsThis'])
30
30
 
31
31
  /* 통과 검사에 무엇을 넣어도 열리지 않는다. */
32
32
  expect(await passesRow(doors, doorGate(async () => true))).toBe(false)
33
33
  })
34
34
 
35
+ it('★ 도구 꺼내기는 값을 읽지 않는다 — 꺼내기를 쓴 답도 읽는 사람의 문으로만 가린다', async () => {
36
+ const doorsOf = (name: string) => ({ readOfficeMyWeeklyReport: ['Query.myWeeklyReport'] } as any)[name]
37
+ const doors = doorsForAnswer([{ name: 'openTools', outcome: 'ok' }, { name: 'readOfficeMyWeeklyReport', outcome: 'ok' }], doorsOf)
38
+
39
+ expect(doors).toEqual(['Query.myWeeklyReport'])
40
+ expect(await passesRow(doors, doorGate(async door => door === 'Query.myWeeklyReport'))).toBe(true)
41
+ })
42
+
43
+ it('★ 거절·오류로 끝난 호출의 문은 적지 않는다 — 거절당한 본인에게 자기 답이 가려진다', () => {
44
+ const doorsOf = (name: string) =>
45
+ ({ queryOrganizationEmployee: ['Query.employees'], readOfficeMyWeeklyReport: ['Query.myWeeklyReport'] } as any)[name]
46
+
47
+ expect(
48
+ doorsForAnswer(
49
+ [
50
+ { name: 'queryOrganizationEmployee', outcome: 'rejected' },
51
+ { name: 'noSuchTool', outcome: 'error' },
52
+ { name: 'readOfficeMyWeeklyReport', outcome: 'ok' }
53
+ ],
54
+ doorsOf
55
+ )
56
+ ).toEqual(['Query.myWeeklyReport'])
57
+ })
58
+
59
+ it('값을 읽은 호출은 거절된 같은 도구가 있어도 문이 남는다', () => {
60
+ const doorsOf = () => ['Query.employees']
61
+ expect(
62
+ doorsForAnswer(
63
+ [
64
+ { name: 'queryOrganizationEmployee', outcome: 'rejected' },
65
+ { name: 'queryOrganizationEmployee', outcome: 'ok' }
66
+ ],
67
+ doorsOf
68
+ )
69
+ ).toEqual(['Query.employees'])
70
+ })
71
+
35
72
  it('★ 같은 문은 한 요청에 한 번만 묻는다', async () => {
36
73
  const asked: string[] = []
37
74
  const gate = doorGate(async door => {
@@ -23,20 +23,40 @@
23
23
  * 이 파일은 저장소·엔티티를 모르는 순수 판정이다.
24
24
  */
25
25
 
26
+ import { OPEN_TOOLS } from '@things-factory/ai-client-base'
27
+
26
28
  /** 문 이름으로 보이지 않는 값 — 등록되지 않은 도구가 답에 끼었을 때. */
27
29
  const UNRESOLVED = 'unresolved:'
28
30
 
31
+ /** 답에 실린 도구 한 번 — 이름과 어떻게 끝났는가(agentic loop 의 ToolUsage). */
32
+ export interface AnswerToolUse {
33
+ name: string
34
+ outcome?: string
35
+ }
36
+
29
37
  /**
30
- * 이 답이 지난 문들 — 부른 도구들의 문을 합친다(중복 없이, 정렬).
38
+ * 값을 읽지 않은 호출 — 거절·오류로 끝난 호출은 결과에 데이터가 없다(무엇이 빠졌는지·왜 못 했는지만).
39
+ * 그 문을 답에 적으면 그 문을 못 지나는 사람, 곧 **거절당한 본인**에게 자기 답이 가려진다(2026-11-12
40
+ * 운영: 직원 목록 조회가 거절된 답이 묻는 사람에게 가려짐).
41
+ */
42
+ const READ_NOTHING = new Set(['rejected', 'error'])
43
+
44
+ /**
45
+ * 이 답이 지난 문들 — 값을 읽은 도구들의 문을 합친다(중복 없이, 정렬).
46
+ *
47
+ * 도구 꺼내기(`openTools`, ADR-0061 결정 9)는 도구 이름을 열 뿐 값을 읽지 않는다. 등록기에 없으므로
48
+ * 아래 규칙대로 두면 아무도 못 지나는 자리가 되어, 꺼내기를 쓴 답은 묻는 사람 본인까지 누구도 못
49
+ * 읽었다(2026-11-12 운영: 가려진 답 22건 중 19건).
31
50
  *
32
- * 등록기에 없는 도구가 답에 끼면 그 도구가 무엇을 읽었는지 알 길이 없다. 그때 `[]`(누구나 읽는 답)로
33
- * 적으면 모르는 값이 공개된다. 아무도 못 지나는 이름을 적어 **가려지는 쪽**으로 넘어뜨리고, 이름에
34
- * 원인을 실어 둔다.
51
+ * 등록기에 없는 도구가 값을 읽고 답에 끼면 그 도구가 무엇을 읽었는지 알 길이 없다. 그때 `[]`(누구나
52
+ * 읽는 답)로 적으면 모르는 값이 공개된다. 아무도 못 지나는 이름을 적어 **가려지는 쪽**으로 넘어뜨리고,
53
+ * 이름에 원인을 실어 둔다.
35
54
  */
36
- export function doorsForAnswer(toolNames: readonly string[], doorsOf: (name: string) => string[] | undefined): string[] {
55
+ export function doorsForAnswer(usages: readonly AnswerToolUse[], doorsOf: (name: string) => string[] | undefined): string[] {
37
56
  const doors = new Set<string>()
38
57
 
39
- for (const name of toolNames) {
58
+ for (const { name, outcome } of usages) {
59
+ if (!name || name === OPEN_TOOLS || (outcome && READ_NOTHING.has(outcome))) continue
40
60
  const declared = doorsOf(name)
41
61
  if (declared === undefined) doors.add(`${UNRESOLVED}${name}`)
42
62
  else for (const door of declared) doors.add(door)
@@ -207,6 +207,12 @@ export interface DetailRead {
207
207
  * for any ledger record; asked on a deposit's 360 why it was in the check, the model never opened it (2026-10-24).
208
208
  */
209
209
  axes?: string[]
210
+ /**
211
+ * The application routes whose conversations put it in front (ConversationCategory.frontPages) - a read of one record
212
+ * has no list screen to name its page. Asked 「AI로 초안 작성」 on 내 주간업무보고, the week's read was not in front, and the
213
+ * model looked for it in the help first (2026-11-12).
214
+ */
215
+ frontPages?: string[]
210
216
  /**
211
217
  * The lists the answer holds, each a table of typed columns - what a dashboard card may draw from a one-answer read
212
218
  * (ADR-0160 decision 2). The card keeps only `key`; where the rows are and what their columns are is read here.
@@ -190,7 +190,8 @@ describe('§3 what runs, and what is kept', () => {
190
190
  ['readCard', true, null]
191
191
  ])
192
192
  expect(reads[0]).toMatchObject({ category: 'strategy', targetIds: ['g-1'], resultCount: 2 })
193
- expect(run.doors).toEqual(['Query.cards', 'Query.goals', 'Query.sales'])
193
+ /* The sales read threw and read nothing - its door is not on the draft (ADR-0073 decision 1 amendment 1). */
194
+ expect(run.doors).toEqual(['Query.cards', 'Query.goals'])
194
195
  expect(run.cardsDropped).toBe(1)
195
196
  expect(run).toMatchObject({ modelCalls: 2, inputTokens: 200, outputTokens: 40, agentId: 'agent-1', clientId: 'stand-in:model' })
196
197
  expect(run.outcomeCode).toBeNull()
@@ -225,7 +225,7 @@ export async function runAssistantUnattended(input: UnattendedRunInput, deps: Un
225
225
  if (failure) return fail(failure.code, failure.params, spent())
226
226
 
227
227
  const doors = doorsForAnswer(
228
- (result.loop.toolUsages ?? []).map((usage: any) => usage?.name).filter(Boolean),
228
+ result.loop.toolUsages ?? [],
229
229
  name => (findToolSpec(name, categories) as any)?.doors
230
230
  )
231
231
  return end({