@things-factory/ai-client-base 10.1.20 → 10.1.26

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 (38) hide show
  1. package/dist-server/service/assistant/index.d.ts +1 -0
  2. package/dist-server/service/assistant/index.js +1 -0
  3. package/dist-server/service/assistant/index.js.map +1 -1
  4. package/dist-server/service/assistant/registry-assistant.d.ts +10 -10
  5. package/dist-server/service/assistant/registry-assistant.js +11 -9
  6. package/dist-server/service/assistant/registry-assistant.js.map +1 -1
  7. package/dist-server/service/assistant/tool-scope.d.ts +25 -0
  8. package/dist-server/service/assistant/tool-scope.js +71 -0
  9. package/dist-server/service/assistant/tool-scope.js.map +1 -0
  10. package/dist-server/service/index.d.ts +1 -0
  11. package/dist-server/service/index.js +1 -0
  12. package/dist-server/service/index.js.map +1 -1
  13. package/dist-server/service/testing/tool-call-context.d.ts +10 -0
  14. package/dist-server/service/testing/tool-call-context.js +13 -0
  15. package/dist-server/service/testing/tool-call-context.js.map +1 -0
  16. package/dist-server/service/tool-registry/index.d.ts +3 -3
  17. package/dist-server/service/tool-registry/index.js +2 -1
  18. package/dist-server/service/tool-registry/index.js.map +1 -1
  19. package/dist-server/service/tool-registry/registry.d.ts +16 -0
  20. package/dist-server/service/tool-registry/registry.js +36 -0
  21. package/dist-server/service/tool-registry/registry.js.map +1 -1
  22. package/dist-server/service/tool-registry/types.d.ts +52 -4
  23. package/dist-server/service/tool-registry/types.js +4 -4
  24. package/dist-server/service/tool-registry/types.js.map +1 -1
  25. package/dist-server/tsconfig.tsbuildinfo +1 -1
  26. package/docs/grounded-analysis-contract.md +1 -1
  27. package/package.json +2 -2
  28. package/server/service/analysis-contract.test.ts +0 -1
  29. package/server/service/assistant/index.ts +1 -0
  30. package/server/service/assistant/registry-assistant.test.ts +131 -4
  31. package/server/service/assistant/registry-assistant.ts +29 -24
  32. package/server/service/assistant/tool-scope.ts +86 -0
  33. package/server/service/index.ts +1 -0
  34. package/server/service/testing/tool-call-context.ts +28 -0
  35. package/server/service/tool-registry/index.ts +7 -3
  36. package/server/service/tool-registry/registry.test.ts +50 -1
  37. package/server/service/tool-registry/registry.ts +47 -0
  38. package/server/service/tool-registry/types.ts +60 -10
@@ -12,7 +12,7 @@
12
12
  *
13
13
  * 설계 원칙:
14
14
  * - **카테고리별 builder 시그니처 다양성을 통합**: read 는 (args, ctx) → any,
15
- * write 는 (args, components) → BoardEditOp[], action 은 (args) → BoardActionOp.
15
+ * write 는 (args, components) → SceneEditOp[], action 은 (args) → SceneActionOp.
16
16
  * 하나의 ToolSpec 에 모든 시그니처를 union 으로 담지 않고, 카테고리에 맞는
17
17
  * builder 만 채우면 되도록 카테고리별 sub-interface 분리.
18
18
  * - **kind 필드로 자가 분류**: registry 가 isReadTool / isWriteTool 자동 도출.
@@ -21,12 +21,40 @@
21
21
  * 점진적으로 다른 hardcoded tool 들 (addComponent / alignComponents 등) 도
22
22
  * 같은 registry 로 흡수 가능. 한 단계씩 byte-단위 동등성 단위 테스트 보장.
23
23
  */
24
- // 본 registry 는 LLM tool 노출 plugin point 에 한정되므로 도메인 type (BoardEditOp,
25
- // BoardActionOp 등) 은 알지 않는다. builder return 은 unknown 으로 두고, 카테고리
26
- // dispatcher (board-ai 의 toolCallToBoardEditOp / toolCallToBoardActionOp 등) 가 자기
24
+ // 본 registry 는 LLM tool 노출 plugin point 에 한정되므로 도메인 type (SceneEditOp,
25
+ // SceneActionOp 등) 은 알지 않는다. builder return 은 unknown 으로 두고, 카테고리
26
+ // dispatcher (board-ai 의 toolCallToSceneEditOp / toolCallToSceneActionOp 등) 가 자기
27
27
  // 도메인 type 으로 좁힌다. 사용자가 ToolSpec<TWrite, TAction> generic 까지 정밀화하면
28
28
  // 좋겠지만, 11~50 개 spec 마다 type 인자 전파가 부담이라 unknown 으로 합의.
29
29
 
30
+ // ── ToolCallContext — what the neutral conversation door hands a registered tool (A3) ──
31
+
32
+ /**
33
+ * What `registryAssistantChat` — the door apps use (`assistantChat`, ADR-0061 decision 0) — hands a
34
+ * registered tool when it runs.
35
+ *
36
+ * `state` and `host` sit side by side. The twin's space tools read `ctx.state.host` while this door
37
+ * passed `ctx.host`, so they never saw the space; the two are never merged into one object.
38
+ *
39
+ * The board product's door (board-ai) passes its own shape and is not part of this contract.
40
+ */
41
+ export interface ToolCallContext {
42
+ /** The request state the server built — domain, user, tx. The only basis for authorization. */
43
+ state: any
44
+ /**
45
+ * The client's `AssistantMode.hostContext`, passed through as is. **Untrusted** — a tool that reads
46
+ * an id from it checks that the id belongs to the caller's tenant. `{}` when none was sent.
47
+ */
48
+ host: Record<string, any>
49
+ /** The conversation's mode. Filled once modes are registered on the server (A2); absent until then. */
50
+ mode?: ToolCallMode
51
+ }
52
+
53
+ export interface ToolCallMode {
54
+ kind: string
55
+ target?: string
56
+ }
57
+
30
58
  // ── 카테고리별 builder 시그니처 ──────────────────────────────────────
31
59
 
32
60
  /**
@@ -48,13 +76,12 @@ export interface ReadToolContext {
48
76
  /** 이외 주입은 카테고리별로 자유. tool 등록자가 type 좁힐 수 있도록 unknown 으로 보존. */
49
77
  [k: string]: any
50
78
  }
51
-
52
79
  /**
53
80
  * Write tool — domain edit op 발생. host 가 patch 적용 후 영속화.
54
81
  * 예: board-ai 의 addComponent / setFill / modifyBoard.
55
82
  *
56
83
  * builder 의 return type 은 unknown 으로 둔다 — 도메인별 dispatcher (예: board-ai 의
57
- * toolCallToBoardEditOp) 가 자기 EditOp[] 로 cast. ops/errors wrapper 형태도 동일 의미.
84
+ * toolCallToSceneEditOp) 가 자기 EditOp[] 로 cast. ops/errors wrapper 형태도 동일 의미.
58
85
  */
59
86
  export type WriteToolBuilder = (
60
87
  args: any,
@@ -65,13 +92,12 @@ export interface WriteToolContext {
65
92
  components?: ReadonlyArray<any>
66
93
  [k: string]: any
67
94
  }
68
-
69
95
  /**
70
96
  * Action tool — ephemeral scene 조작 (select / center / fit / sceneMode).
71
97
  * board model 변경 X, undo 영향 X. host 가 별도 channel 로 적용.
72
98
  *
73
- * return type 은 unknown — 도메인별 dispatcher (예: board-ai 의 toolCallToBoardActionOp)
74
- * 가 자기 BoardActionOp 으로 cast.
99
+ * return type 은 unknown — 도메인별 dispatcher (예: board-ai 의 toolCallToSceneActionOp)
100
+ * 가 자기 SceneActionOp 으로 cast.
75
101
  */
76
102
  export type ActionToolBuilder = (args: any) => any | null
77
103
 
@@ -91,9 +117,25 @@ export interface ExternalToolContext {
91
117
  state?: any
92
118
  [k: string]: any
93
119
  }
94
-
95
120
  // ── ToolSpec — 카테고리별 변형 ──────────────────────────────────────
96
121
 
122
+ /**
123
+ * The privilege a tool requires — the same `category`/`privilege` the tool's GraphQL door declares
124
+ * (`@privilege(category, privilege, owner?, super?)`), so the fields mirror `PrivilegeObject`.
125
+ *
126
+ * A tool is not a new door; it is another way into a door that already exists. A tool that creates
127
+ * a Board goes through the privilege that creating a Board already needs. Minting an AI-only
128
+ * privilege name would put two doors on one effect, and one of them would end up looser.
129
+ */
130
+ export interface ToolPrivilege {
131
+ category: string
132
+ privilege: string
133
+ /** Domain owners pass without the privilege — mirror the door's `domainOwnerGranted`. */
134
+ owner?: boolean
135
+ /** Super users pass without the privilege — mirror the door's `superUserGranted`. */
136
+ super?: boolean
137
+ }
138
+
97
139
  /**
98
140
  * 모든 ToolSpec 공통 메타데이터.
99
141
  */
@@ -109,6 +151,14 @@ export interface ToolSpecBase {
109
151
  themeNote?: string
110
152
  /** JSON Schema for parameters — LLM tool schema 에 그대로 노출. */
111
153
  schema: any
154
+ /**
155
+ * The privilege a caller needs before this tool is offered or run. See `ToolPrivilege`.
156
+ *
157
+ * Expected for `write`, `action` and `external` — registration records a
158
+ * `tool-privilege-undeclared` warning for one without it (A1 stage one). A `read` tool without it is
159
+ * offered on domain membership alone, and its builder must check what it reads.
160
+ */
161
+ privilege?: ToolPrivilege
112
162
  }
113
163
 
114
164
  export interface ReadToolSpec extends ToolSpecBase {