@things-factory/figure-service 10.1.287 → 10.1.288

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.
@@ -39,6 +39,8 @@ export interface ProposeFigureInput {
39
39
  read?: FigureReadRequest;
40
40
  /** Handed the request's course once it ends, made or not: what was asked, answered, refused, observed and decided. */
41
41
  trace?: (record: FigureAITrace) => void;
42
+ /** Told before each request to the model, for the person waiting: which stage, and which request it is. */
43
+ progress?: (stage: FigureProposeProgress) => void;
42
44
  /**
43
45
  * The relations the request asks for, written from it beforehand (figure-relation-checks.ts). When given, the figure is
44
46
  * judged against them, and a relation it breaks is said back with the observations: what was asked, what it gives.
@@ -69,6 +71,15 @@ export interface FigureRefinement {
69
71
  /** The request's relations the figure returned does not keep: broken, or not confirmed (said with what could not be judged) -- never counted as met. */
70
72
  unresolved?: string[];
71
73
  }
74
+ /**
75
+ * A stage of a request, said before the model is asked: draft (the first answer), retry (asked again after the kernel
76
+ * refused an answer or it was not JSON), revise (asked to look at what was measured), recover (a revision refused, asked
77
+ * again). call counts every request to the model, the one about to be sent included.
78
+ */
79
+ export interface FigureProposeProgress {
80
+ stage: 'draft' | 'retry' | 'revise' | 'recover';
81
+ call: number;
82
+ }
72
83
  /** One request's course, for finding where the guide or the observations fail the model. */
73
84
  export interface FigureAITrace {
74
85
  at: string;
@@ -325,8 +325,14 @@ async function proposeFigureSteps(input) {
325
325
  ];
326
326
  /* Every request to the model goes here: what is passed is what is recorded, at the moment it is passed. */
327
327
  let recordedUpTo = 0;
328
- const ask = () => {
328
+ const ask = (stage) => {
329
329
  record.calls++;
330
+ try {
331
+ input.progress?.({ stage, call: record.calls });
332
+ }
333
+ catch {
334
+ /* What the person is shown never costs them the figure. */
335
+ }
330
336
  record.sent.push({ system: hashOf(metered.systemPrompt), count: messages.length, added: structuredClone(messages.slice(recordedUpTo)) });
331
337
  recordedUpTo = messages.length;
332
338
  return client.generateJSON(messages, metered);
@@ -352,7 +358,7 @@ async function proposeFigureSteps(input) {
352
358
  for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
353
359
  let answer;
354
360
  try {
355
- answer = await ask();
361
+ answer = await ask(attempt === 1 ? 'draft' : 'retry');
356
362
  }
357
363
  catch (e) {
358
364
  /*
@@ -395,7 +401,7 @@ async function proposeFigureSteps(input) {
395
401
  messages.push({ role: 'user', content: observationsPromptFigure(findings, candidate.source, relationsSaid, broken) });
396
402
  let reply;
397
403
  try {
398
- reply = await ask();
404
+ reply = await ask('revise');
399
405
  }
400
406
  catch (e) {
401
407
  return done(candidate, attempt, { asked: true, decision: 'no-answer', reasons: [String(e?.message ?? e)] });
@@ -418,7 +424,7 @@ async function proposeFigureSteps(input) {
418
424
  messages.push({ role: 'assistant', content: JSON.stringify(reply) });
419
425
  messages.push({ role: 'user', content: [REFUSED_SAY, ...again.reasons].join('\n') });
420
426
  try {
421
- reply = await ask();
427
+ reply = await ask('recover');
422
428
  }
423
429
  catch (e) {
424
430
  return done(candidate, attempt, { asked: true, decision: 'no-answer', reasons: [String(e?.message ?? e)] });
@@ -65,6 +65,13 @@ async function mcpAgentCallerOf(ctx) {
65
65
  };
66
66
  }
67
67
  /** What the figure agent is doing, by the tool it calls: the English the translations default to. */
68
+ /* The default build's stages, said while the model is asked (figure-propose-steps progress). */
69
+ const PROPOSE_PROGRESS = {
70
+ draft: 'Writing the figure ({call})…',
71
+ retry: 'The kernel refused it: asking again with the reasons ({call})…',
72
+ revise: 'Looking at what was measured and revising ({call})…',
73
+ recover: 'The revision was refused: asking again with the reasons ({call})…'
74
+ };
68
75
  const AGENT_PROGRESS = {
69
76
  get_guide: 'Reading how a figure is made…',
70
77
  apply_steps: 'Building the figure (round {count})…',
@@ -103,6 +110,7 @@ function getDeps() {
103
110
  parseSource: format.parseSource,
104
111
  figureCostOf: model.figureCostOf,
105
112
  figureScoreOf: model.figureScoreOf,
113
+ figureCapabilityReportOf: model.figureCapabilityReportOf,
106
114
  proposeFigureSteps: proposer.proposeFigureSteps,
107
115
  isPlaceholderType: model.isPlaceholderType
108
116
  };
@@ -528,6 +536,8 @@ function figureToolSpecs() {
528
536
  result = await proposeFigureSteps({
529
537
  /* Each request's course is kept, to find where the guide or the observations fail the model (ADR-0206). */
530
538
  trace: figure_ai_trace_js_1.writeFigureAITrace,
539
+ /* What the person sees while waiting: the stage, and which request to the model it is. */
540
+ progress: ({ stage, call }) => ctx?.progress?.(ctx.t(`figure.progress.propose.${stage}`, { call, defaultValue: PROPOSE_PROGRESS[stage] })),
531
541
  /* The agent of this conversation's turn - the one the person picked, or the domain default. */
532
542
  client: await (0, ai_client_base_1.aiClientFor)({
533
543
  domain: ctx?.state?.domain,
@@ -597,6 +607,11 @@ function figureToolSpecs() {
597
607
  with the card, so nothing measured as wrong is presented as done.
598
608
  */
599
609
  ...(result.findings?.length ? { concerns: result.findings.map((f) => `${f.severity === 'fix' ? 'still wrong' : 'note'}: ${f.message}`) } : {}),
610
+ /*
611
+ What the figure makes of figure-model, as the kernel shows it: controls and what they move, the chain, rows and
612
+ the size they follow, data, clips (figureCapabilityReportOf). The card draws it folded, opened on request.
613
+ */
614
+ ...capabilitiesOf(result.source),
600
615
  /* What the figure agent says it made, for the reply; and that it stopped before it said it was done. */
601
616
  ...(typeof result.summary === 'string' ? { made: result.summary } : {}),
602
617
  ...(result.finished === false ? { unfinished: 'The agent ended without saying the figure was done (it did not call finish). Check the card against the request before you say it is complete.' } : {})
@@ -605,6 +620,16 @@ function figureToolSpecs() {
605
620
  }
606
621
  ];
607
622
  }
623
+ /** The capability report for the card; a figure the report cannot evaluate gets none, and the card stays as it was. */
624
+ function capabilitiesOf(source) {
625
+ try {
626
+ const report = getDeps().figureCapabilityReportOf?.(source);
627
+ return report ? { capabilities: report } : {};
628
+ }
629
+ catch {
630
+ return {};
631
+ }
632
+ }
608
633
  /**
609
634
  * 등록 — 부팅 시 1회.
610
635
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/figure-service",
3
- "version": "10.1.287",
3
+ "version": "10.1.288",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "@things-factory:registry": "https://registry.npmjs.org"
@@ -41,7 +41,7 @@
41
41
  "test:templates": "node --test scripts/templates.test.mts"
42
42
  },
43
43
  "dependencies": {
44
- "@hatiolab/figure-model": "^0.12.13",
44
+ "@hatiolab/figure-model": "^0.12.15",
45
45
  "@operato/typeorm-history": "^10.0.0",
46
46
  "@things-factory/ai-client-base": "^10.1.283",
47
47
  "@things-factory/attachment-base": "^10.1.283",
@@ -54,5 +54,5 @@
54
54
  "jszip": "^3.10.1",
55
55
  "koa-router": "^7.4.0"
56
56
  },
57
- "gitHead": "cc547a35fc3f0cda7ae5bc8337a5bb342db4efdc"
57
+ "gitHead": "78eaee46dd9b425ed845b02952b082f35a0faca7"
58
58
  }
@@ -204,5 +204,9 @@
204
204
  "error.figure-install-key-name-missing": "Name the key - what board server it is for.",
205
205
  "error.figure-install-key-name-too-long": "A key name is at most {max} characters.",
206
206
  "error.figure-install-key-not-found": "There is no such install key.",
207
- "error.figure-install-key-privilege-missing": "This server has no privilege to read released figures."
207
+ "error.figure-install-key-privilege-missing": "This server has no privilege to read released figures.",
208
+ "figure.progress.propose.draft": "Writing the figure (request {call})…",
209
+ "figure.progress.propose.retry": "The kernel refused it: asking again with the reasons (request {call})…",
210
+ "figure.progress.propose.revise": "Looking at what was measured and revising (request {call})…",
211
+ "figure.progress.propose.recover": "The revision was refused: asking again with the reasons (request {call})…"
208
212
  }
@@ -204,5 +204,9 @@
204
204
  "error.figure-install-key-name-missing": "키 이름을 입력하세요. 이 키를 사용할 보드 서버를 적으면 됩니다.",
205
205
  "error.figure-install-key-name-too-long": "키 이름은 {max}자 이하로 입력하세요.",
206
206
  "error.figure-install-key-not-found": "해당 설치 키가 없습니다.",
207
- "error.figure-install-key-privilege-missing": "이 서버에 발행 피규어 조회 권한이 정의되어 있지 않습니다."
207
+ "error.figure-install-key-privilege-missing": "이 서버에 발행 피규어 조회 권한이 정의되어 있지 않습니다.",
208
+ "figure.progress.propose.draft": "피규어를 쓰는 중 ({call}번째 요청)…",
209
+ "figure.progress.propose.retry": "커널이 거절해 이유를 붙여 다시 요청하는 중 ({call}번째 요청)…",
210
+ "figure.progress.propose.revise": "만든 모델을 잰 결과를 보고 고치는 중 ({call}번째 요청)…",
211
+ "figure.progress.propose.recover": "고친 답이 거절되어 이유를 붙여 다시 요청하는 중 ({call}번째 요청)…"
208
212
  }