@nimiplatform/sdk 0.21.0 → 0.22.0

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 (250) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/README.md +161 -433
  3. package/dist/core/ai/embeddings.d.ts +1 -0
  4. package/dist/core/ai/embeddings.d.ts.map +1 -1
  5. package/dist/core/ai/embeddings.js +3 -0
  6. package/dist/core/ai/embeddings.js.map +1 -1
  7. package/dist/core/app/desktop-open.d.ts +8 -5
  8. package/dist/core/app/desktop-open.d.ts.map +1 -1
  9. package/dist/core/app/desktop-open.js +20 -16
  10. package/dist/core/app/desktop-open.js.map +1 -1
  11. package/dist/core/app/index.d.ts +4 -2
  12. package/dist/core/app/index.d.ts.map +1 -1
  13. package/dist/core/app/index.js +1 -1
  14. package/dist/core/app/index.js.map +1 -1
  15. package/dist/core/app/local-app-agent-introduction.d.ts +3 -0
  16. package/dist/core/app/local-app-agent-introduction.d.ts.map +1 -1
  17. package/dist/core/app/local-app-agent-introduction.js +35 -5
  18. package/dist/core/app/local-app-agent-introduction.js.map +1 -1
  19. package/dist/core/app/local-app-runtime-platform-activity-view.d.ts.map +1 -1
  20. package/dist/core/app/local-app-runtime-platform-activity-view.js +4 -2
  21. package/dist/core/app/local-app-runtime-platform-activity-view.js.map +1 -1
  22. package/dist/core/app/local-app-runtime-platform-activity.d.ts.map +1 -1
  23. package/dist/core/app/local-app-runtime-platform-activity.js +5 -1
  24. package/dist/core/app/local-app-runtime-platform-activity.js.map +1 -1
  25. package/dist/core/app/local-app-runtime-platform-configure.d.ts +38 -4
  26. package/dist/core/app/local-app-runtime-platform-configure.d.ts.map +1 -1
  27. package/dist/core/app/local-app-runtime-platform-configure.js +121 -19
  28. package/dist/core/app/local-app-runtime-platform-configure.js.map +1 -1
  29. package/dist/core/app/local-app-runtime-platform-conversation.d.ts +67 -6
  30. package/dist/core/app/local-app-runtime-platform-conversation.d.ts.map +1 -1
  31. package/dist/core/app/local-app-runtime-platform-conversation.js +162 -20
  32. package/dist/core/app/local-app-runtime-platform-conversation.js.map +1 -1
  33. package/dist/core/app/local-app-runtime-platform-direct-conversation.d.ts +4 -1
  34. package/dist/core/app/local-app-runtime-platform-direct-conversation.d.ts.map +1 -1
  35. package/dist/core/app/local-app-runtime-platform-direct-conversation.js +58 -5
  36. package/dist/core/app/local-app-runtime-platform-direct-conversation.js.map +1 -1
  37. package/dist/core/app/local-app-runtime-platform-direct-realm-realtime.d.ts +2 -0
  38. package/dist/core/app/local-app-runtime-platform-direct-realm-realtime.d.ts.map +1 -1
  39. package/dist/core/app/local-app-runtime-platform-direct-realm-realtime.js +10 -2
  40. package/dist/core/app/local-app-runtime-platform-direct-realm-realtime.js.map +1 -1
  41. package/dist/core/app/local-app-runtime-platform-life.d.ts +33 -0
  42. package/dist/core/app/local-app-runtime-platform-life.d.ts.map +1 -0
  43. package/dist/core/app/local-app-runtime-platform-life.js +59 -0
  44. package/dist/core/app/local-app-runtime-platform-life.js.map +1 -0
  45. package/dist/core/app/local-app-runtime-platform-proactive.d.ts +28 -0
  46. package/dist/core/app/local-app-runtime-platform-proactive.d.ts.map +1 -0
  47. package/dist/core/app/local-app-runtime-platform-proactive.js +42 -0
  48. package/dist/core/app/local-app-runtime-platform-proactive.js.map +1 -0
  49. package/dist/core/app/local-app-runtime-platform-realm-realtime.d.ts +6 -2
  50. package/dist/core/app/local-app-runtime-platform-realm-realtime.d.ts.map +1 -1
  51. package/dist/core/app/local-app-runtime-platform-realm-realtime.js +15 -4
  52. package/dist/core/app/local-app-runtime-platform-realm-realtime.js.map +1 -1
  53. package/dist/core/app/local-app-runtime-platform.d.ts +3 -2
  54. package/dist/core/app/local-app-runtime-platform.d.ts.map +1 -1
  55. package/dist/core/app/local-app-runtime-platform.js +5 -2
  56. package/dist/core/app/local-app-runtime-platform.js.map +1 -1
  57. package/dist/core/app/runtime-account-realm-source-readiness.generated.d.ts +2 -2
  58. package/dist/core/app/runtime-account-realm-source-readiness.generated.d.ts.map +1 -1
  59. package/dist/core/app/runtime-account-realm-source-readiness.generated.js +12 -9
  60. package/dist/core/app/runtime-account-realm-source-readiness.generated.js.map +1 -1
  61. package/dist/core-generated/realm-client.d.ts.map +1 -1
  62. package/dist/core-generated/realm-client.js +33 -99
  63. package/dist/core-generated/realm-client.js.map +1 -1
  64. package/dist/core-generated/realm-typed-client.d.ts +257 -432
  65. package/dist/core-generated/realm-typed-client.d.ts.map +1 -1
  66. package/dist/core-generated/realm-typed-client.js +55 -202
  67. package/dist/core-generated/realm-typed-client.js.map +1 -1
  68. package/dist/core-generated/runtime-client.d.ts.map +1 -1
  69. package/dist/core-generated/runtime-client.js +80 -16
  70. package/dist/core-generated/runtime-client.js.map +1 -1
  71. package/dist/core-generated/runtime-protobuf/google/protobuf/field_mask.d.ts +16 -18
  72. package/dist/core-generated/runtime-protobuf/google/protobuf/field_mask.d.ts.map +1 -1
  73. package/dist/core-generated/runtime-protobuf/google/protobuf/field_mask.js.map +1 -1
  74. package/dist/core-generated/runtime-protobuf/google/protobuf/struct.d.ts +33 -22
  75. package/dist/core-generated/runtime-protobuf/google/protobuf/struct.d.ts.map +1 -1
  76. package/dist/core-generated/runtime-protobuf/google/protobuf/struct.js +8 -3
  77. package/dist/core-generated/runtime-protobuf/google/protobuf/struct.js.map +1 -1
  78. package/dist/core-generated/runtime-protobuf/google/protobuf/timestamp.d.ts +3 -3
  79. package/dist/core-generated/runtime-protobuf/runtime/v1/account.d.ts +10 -0
  80. package/dist/core-generated/runtime-protobuf/runtime/v1/account.d.ts.map +1 -1
  81. package/dist/core-generated/runtime-protobuf/runtime/v1/account.js +9 -1
  82. package/dist/core-generated/runtime-protobuf/runtime/v1/account.js.map +1 -1
  83. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_configure.d.ts +147 -4
  84. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_configure.d.ts.map +1 -1
  85. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_configure.js +327 -14
  86. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_configure.js.map +1 -1
  87. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_life.d.ts +167 -0
  88. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_life.d.ts.map +1 -0
  89. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_life.js +312 -0
  90. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_life.js.map +1 -0
  91. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_service.d.ts +448 -147
  92. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_service.d.ts.map +1 -1
  93. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_service.js +1078 -466
  94. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_service.js.map +1 -1
  95. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_source_materialization.d.ts +5 -1
  96. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_source_materialization.d.ts.map +1 -1
  97. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_source_materialization.js +4 -0
  98. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_source_materialization.js.map +1 -1
  99. package/dist/core-generated/runtime-protobuf/runtime/v1/ai.d.ts.map +1 -1
  100. package/dist/core-generated/runtime-protobuf/runtime/v1/ai.js.map +1 -1
  101. package/dist/core-generated/runtime-protobuf/runtime/v1/audit.d.ts +712 -0
  102. package/dist/core-generated/runtime-protobuf/runtime/v1/audit.d.ts.map +1 -1
  103. package/dist/core-generated/runtime-protobuf/runtime/v1/audit.js +1461 -0
  104. package/dist/core-generated/runtime-protobuf/runtime/v1/audit.js.map +1 -1
  105. package/dist/core-generated/runtime-protobuf/runtime/v1/capability_configuration.d.ts +92 -0
  106. package/dist/core-generated/runtime-protobuf/runtime/v1/capability_configuration.d.ts.map +1 -1
  107. package/dist/core-generated/runtime-protobuf/runtime/v1/capability_configuration.js +204 -0
  108. package/dist/core-generated/runtime-protobuf/runtime/v1/capability_configuration.js.map +1 -1
  109. package/dist/core-generated/runtime-protobuf/runtime/v1/cognition_memory.d.ts +67 -4
  110. package/dist/core-generated/runtime-protobuf/runtime/v1/cognition_memory.d.ts.map +1 -1
  111. package/dist/core-generated/runtime-protobuf/runtime/v1/cognition_memory.js +101 -10
  112. package/dist/core-generated/runtime-protobuf/runtime/v1/cognition_memory.js.map +1 -1
  113. package/dist/core-generated/runtime-protobuf/runtime/v1/common.d.ts +5 -1
  114. package/dist/core-generated/runtime-protobuf/runtime/v1/common.d.ts.map +1 -1
  115. package/dist/core-generated/runtime-protobuf/runtime/v1/common.js +4 -0
  116. package/dist/core-generated/runtime-protobuf/runtime/v1/common.js.map +1 -1
  117. package/dist/core-generated/runtime-protobuf/runtime/v1/connector.d.ts +38 -0
  118. package/dist/core-generated/runtime-protobuf/runtime/v1/connector.d.ts.map +1 -1
  119. package/dist/core-generated/runtime-protobuf/runtime/v1/connector.js +79 -2
  120. package/dist/core-generated/runtime-protobuf/runtime/v1/connector.js.map +1 -1
  121. package/dist/core-generated/runtime-protobuf/runtime/v1/realm_realtime.d.ts +181 -8
  122. package/dist/core-generated/runtime-protobuf/runtime/v1/realm_realtime.d.ts.map +1 -1
  123. package/dist/core-generated/runtime-protobuf/runtime/v1/realm_realtime.js +402 -18
  124. package/dist/core-generated/runtime-protobuf/runtime/v1/realm_realtime.js.map +1 -1
  125. package/dist/core-generated/runtime-protobuf/runtime/v1/runtime_service_control.d.ts +41 -0
  126. package/dist/core-generated/runtime-protobuf/runtime/v1/runtime_service_control.d.ts.map +1 -1
  127. package/dist/core-generated/runtime-protobuf/runtime/v1/runtime_service_control.js +93 -0
  128. package/dist/core-generated/runtime-protobuf/runtime/v1/runtime_service_control.js.map +1 -1
  129. package/dist/core-generated/runtime-public-client.d.ts.map +1 -1
  130. package/dist/core-generated/runtime-public-client.js +72 -16
  131. package/dist/core-generated/runtime-public-client.js.map +1 -1
  132. package/dist/core-generated/runtime-public-rpc-auth-posture.d.ts.map +1 -1
  133. package/dist/core-generated/runtime-public-rpc-auth-posture.js +9 -2
  134. package/dist/core-generated/runtime-public-rpc-auth-posture.js.map +1 -1
  135. package/dist/core-generated/runtime-public-wire-codecs.d.ts +13 -6
  136. package/dist/core-generated/runtime-public-wire-codecs.d.ts.map +1 -1
  137. package/dist/core-generated/runtime-public-wire-codecs.js +13 -6
  138. package/dist/core-generated/runtime-public-wire-codecs.js.map +1 -1
  139. package/dist/core-generated/runtime-rpc-auth-posture.d.ts.map +1 -1
  140. package/dist/core-generated/runtime-rpc-auth-posture.js +10 -2
  141. package/dist/core-generated/runtime-rpc-auth-posture.js.map +1 -1
  142. package/dist/core-generated/runtime-typed-client.d.ts +26 -16
  143. package/dist/core-generated/runtime-typed-client.d.ts.map +1 -1
  144. package/dist/core-generated/runtime-typed-client.js +97 -16
  145. package/dist/core-generated/runtime-typed-client.js.map +1 -1
  146. package/dist/core-generated/runtime-wire-codecs.d.ts +15 -7
  147. package/dist/core-generated/runtime-wire-codecs.d.ts.map +1 -1
  148. package/dist/core-generated/runtime-wire-codecs.js +16 -8
  149. package/dist/core-generated/runtime-wire-codecs.js.map +1 -1
  150. package/dist/realm/account-settings.d.ts +5 -3
  151. package/dist/realm/account-settings.d.ts.map +1 -1
  152. package/dist/realm/account-settings.js +3 -3
  153. package/dist/realm/account-settings.js.map +1 -1
  154. package/dist/realm/generated.d.ts +1 -1
  155. package/dist/realm/generated.d.ts.map +1 -1
  156. package/dist/realm/generated.js.map +1 -1
  157. package/dist/realm/index.d.ts +4 -4
  158. package/dist/realm/index.d.ts.map +1 -1
  159. package/dist/realm/index.js +5 -15
  160. package/dist/realm/index.js.map +1 -1
  161. package/dist/realm/media-delivery.d.ts +4 -0
  162. package/dist/realm/media-delivery.d.ts.map +1 -0
  163. package/dist/realm/media-delivery.js +65 -0
  164. package/dist/realm/media-delivery.js.map +1 -0
  165. package/dist/realm/resource-upload.d.ts +12 -3
  166. package/dist/realm/resource-upload.d.ts.map +1 -1
  167. package/dist/realm/resource-upload.js +93 -241
  168. package/dist/realm/resource-upload.js.map +1 -1
  169. package/dist/realm/social-types.d.ts +1 -15
  170. package/dist/realm/social-types.d.ts.map +1 -1
  171. package/dist/realm/social.d.ts +3 -17
  172. package/dist/realm/social.d.ts.map +1 -1
  173. package/dist/realm/social.js +0 -175
  174. package/dist/realm/social.js.map +1 -1
  175. package/dist/runtime/config-projections.d.ts +10 -0
  176. package/dist/runtime/config-projections.d.ts.map +1 -1
  177. package/dist/runtime/config-projections.js +8 -3
  178. package/dist/runtime/config-projections.js.map +1 -1
  179. package/dist/runtime/connector-inventory.d.ts +9 -2
  180. package/dist/runtime/connector-inventory.d.ts.map +1 -1
  181. package/dist/runtime/connector-inventory.js +67 -24
  182. package/dist/runtime/connector-inventory.js.map +1 -1
  183. package/dist/runtime/desktop-first-party-runtime.d.ts +8 -1
  184. package/dist/runtime/desktop-first-party-runtime.d.ts.map +1 -1
  185. package/dist/runtime/desktop-first-party-runtime.js +80 -2
  186. package/dist/runtime/desktop-first-party-runtime.js.map +1 -1
  187. package/dist/runtime/first-party-protected-runtime-profiles.generated.d.ts +46 -10
  188. package/dist/runtime/first-party-protected-runtime-profiles.generated.d.ts.map +1 -1
  189. package/dist/runtime/first-party-protected-runtime-profiles.generated.js +13 -4
  190. package/dist/runtime/first-party-protected-runtime-profiles.generated.js.map +1 -1
  191. package/dist/runtime/generated.d.ts +2 -2
  192. package/dist/runtime/generated.d.ts.map +1 -1
  193. package/dist/runtime/generated.js +1 -1
  194. package/dist/runtime/generated.js.map +1 -1
  195. package/dist/runtime/index.d.ts.map +1 -1
  196. package/dist/runtime/index.js +11 -10
  197. package/dist/runtime/index.js.map +1 -1
  198. package/dist/runtime/node-grpc.d.ts.map +1 -1
  199. package/dist/runtime/node-grpc.js +24 -4
  200. package/dist/runtime/node-grpc.js.map +1 -1
  201. package/dist/runtime/reason-messages.d.ts +3 -0
  202. package/dist/runtime/reason-messages.d.ts.map +1 -1
  203. package/dist/runtime/reason-messages.js +6 -0
  204. package/dist/runtime/reason-messages.js.map +1 -1
  205. package/dist/runtime/runtime-agent-inspect-projection.d.ts +2 -3
  206. package/dist/runtime/runtime-agent-inspect-projection.d.ts.map +1 -1
  207. package/dist/runtime/runtime-agent-inspect-projection.js +2 -27
  208. package/dist/runtime/runtime-agent-inspect-projection.js.map +1 -1
  209. package/dist/runtime/runtime-agent-inspect-types.d.ts +4 -32
  210. package/dist/runtime/runtime-agent-inspect-types.d.ts.map +1 -1
  211. package/dist/runtime/runtime-local-environment-client-types.d.ts +6 -1
  212. package/dist/runtime/runtime-local-environment-client-types.d.ts.map +1 -1
  213. package/dist/runtime/runtime-local-environment-client.d.ts.map +1 -1
  214. package/dist/runtime/runtime-local-environment-client.js +20 -2
  215. package/dist/runtime/runtime-local-environment-client.js.map +1 -1
  216. package/dist/runtime/runtime-method-modules.d.ts +1 -1
  217. package/dist/runtime/runtime-method-modules.d.ts.map +1 -1
  218. package/dist/runtime/runtime-method-modules.js +4 -2
  219. package/dist/runtime/runtime-method-modules.js.map +1 -1
  220. package/dist/runtime/wire-types/agent-participation-enums.d.ts +2 -1
  221. package/dist/runtime/wire-types/agent-participation-enums.d.ts.map +1 -1
  222. package/dist/runtime/wire-types/agent-participation-enums.js +2 -1
  223. package/dist/runtime/wire-types/agent-participation-enums.js.map +1 -1
  224. package/dist/runtime/wire-types/agent-participation-types.d.ts +6 -4
  225. package/dist/runtime/wire-types/agent-participation-types.d.ts.map +1 -1
  226. package/dist/runtime/wire-types/ai-scenario-enums.d.ts +18 -0
  227. package/dist/runtime/wire-types/ai-scenario-enums.d.ts.map +1 -1
  228. package/dist/runtime/wire-types/ai-scenario-enums.js +21 -0
  229. package/dist/runtime/wire-types/ai-scenario-enums.js.map +1 -1
  230. package/dist/runtime/wire-types/ai-scenario-types.d.ts +4 -4
  231. package/dist/runtime/wire-types/ai-scenario-types.d.ts.map +1 -1
  232. package/dist/runtime/wire-types/identity-app-types.d.ts +4 -4
  233. package/dist/runtime/wire-types/identity-app-types.d.ts.map +1 -1
  234. package/dist/runtime/wire-types/local-memory-enums.d.ts +9 -0
  235. package/dist/runtime/wire-types/local-memory-enums.d.ts.map +1 -1
  236. package/dist/runtime/wire-types/local-memory-enums.js +10 -0
  237. package/dist/runtime/wire-types/local-memory-enums.js.map +1 -1
  238. package/dist/runtime/wire-types/reason-code-enums.d.ts +2 -1
  239. package/dist/runtime/wire-types/reason-code-enums.d.ts.map +1 -1
  240. package/dist/runtime/wire-types/reason-code-enums.js +1 -0
  241. package/dist/runtime/wire-types/reason-code-enums.js.map +1 -1
  242. package/dist/types/sha256.d.ts +6 -1
  243. package/dist/types/sha256.d.ts.map +1 -1
  244. package/dist/types/sha256.js +60 -25
  245. package/dist/types/sha256.js.map +1 -1
  246. package/package.json +3 -3
  247. package/dist/realm/feed.d.ts +0 -4
  248. package/dist/realm/feed.d.ts.map +0 -1
  249. package/dist/realm/feed.js +0 -10
  250. package/dist/realm/feed.js.map +0 -1
package/README.md CHANGED
@@ -1,129 +1,80 @@
1
1
  # @nimiplatform/sdk
2
2
 
3
- Public TypeScript clients and contracts for Nimi Apps and integrations.
4
- The package includes runnable JavaScript and TypeScript declarations under
5
- `dist/`; use the public exports instead of importing Runtime internals.
3
+ The official TypeScript SDK for the Nimi Platform.
6
4
 
7
- ## Developing a Nimi App
5
+ `@nimiplatform/sdk` provides strongly-typed clients, capability contracts, and runtime interfaces for building privacy-preserving, AI-native desktop applications. Through a unified capability-intent architecture, applications can seamlessly harness both on-device local models and cloud AI providers without managing API keys or low-level transport protocols.
8
6
 
9
- Start with the lifecycle guide included in `@nimiplatform/app-tools`.
10
- `nimi-app --help` prints its location before initialization. Select the matched
11
- SDK/Kit versions from that package's `nimiScaffoldVersions` and retain the
12
- project lockfile. See [migration notes](CHANGELOG.md) before upgrading.
7
+ ---
13
8
 
14
- An installed or development App consumes one `NimiLocalAppClient`, bound to
15
- the standard Kit shell in its supervised Host. Generated projects create it in
16
- `src/shell/auth/local-app-client.ts`:
9
+ ## 1. Core Architecture & Mental Model
10
+
11
+ ### The Host-Bound Client
12
+ Standard Nimi Apps run inside a desktop host supervised by Nimi Desktop (the current host of Nimi Home). Instead of requiring applications to manage secrets or connect directly to local ports, the host injects a secure IPC bridge.
17
13
 
18
14
  ```ts
19
15
  import { createNimiClient, type NimiLocalAppClient } from '@nimiplatform/sdk';
20
16
  import { createNimiLocalAppStandardShellSurface } from '@nimiplatform/kit/shell/renderer/bridge';
21
17
 
18
+ // Scaffolded apps export this singleton from src/shell/auth/local-app-client.ts
22
19
  const client: NimiLocalAppClient = createNimiClient({
23
20
  localApp: { standardShell: createNimiLocalAppStandardShellSurface() },
24
21
  });
22
+ ```
23
+
24
+ - **Host-managed credentials**: No API tokens, account IDs, or private network addresses are embedded in your frontend code.
25
+ - **Dynamic Routing**: The local Runtime resolves whether an action is fulfilled by a selected local model or a supported cloud provider based on user preference.
26
+ - **Fail-Closed Boundaries**: Direct standalone clients (`createNimiClient({ appId, runtime })`) are reserved for external server daemons or test scripts; Runtime strictly rejects app-scoped operations from unverified gRPC origins.
27
+
28
+ ---
29
+
30
+ ## 2. Quickstart: Text Generation
31
+
32
+ ### Single-Turn Text Generation
33
+ The simplest way to generate text using the user's preferred model:
25
34
 
35
+ ```ts
26
36
  const { text } = await client.ai.text.generateCandidate({
27
- messages: [{ role: 'user', text: 'What can you help me with?' }],
37
+ messages: [
38
+ { role: 'user', text: 'Summarize the core tenets of local-first computing.' }
39
+ ],
28
40
  });
41
+ console.log(text);
29
42
  ```
30
43
 
31
- App-owned Node business work can use the same Host's `bridge.services`.
32
- The App does not supply Nimi credentials, account identity, a Runtime endpoint,
33
- or a provider/model override to these protected calls. A direct client created
34
- with `createNimiClient({ appId, runtime })` is for programs outside a Nimi App;
35
- Runtime rejects App-scoped operations such as AI execution and App storage
36
- from it.
37
-
38
- For a multi-step tool loop, JSON output or image input, bind the common model
39
- interface to the same client:
44
+ ### Multi-Step Tool Loops & Structured Output
45
+ For multi-turn tool calling, structured JSON output, or multimodal inputs, bind the local app text model:
40
46
 
41
47
  ```ts
42
48
  import type { NimiLocalAppClient } from '@nimiplatform/sdk/app';
43
49
  import { createNimiLocalAppTextModel } from '@nimiplatform/sdk/ai';
44
50
 
45
- export async function answer(
51
+ export async function answerWithTools(
46
52
  client: NimiLocalAppClient,
47
53
  question: string,
48
54
  signal: AbortSignal,
49
55
  ) {
50
- return createNimiLocalAppTextModel(client.ai).generateText({
51
- messages: [{ role: 'user', content: [{ type: 'text', text: question }] }],
56
+ const model = createNimiLocalAppTextModel(client.ai);
57
+
58
+ return await model.generateText({
59
+ messages: [
60
+ { role: 'user', content: [{ type: 'text', text: question }] }
61
+ ],
62
+ responseFormat: { type: 'json-object' },
52
63
  signal,
53
64
  });
54
65
  }
55
66
  ```
56
67
 
57
- The model executes one step. The App owns tool handlers and subsequent steps,
58
- preserves ordered `outputItems` as `turnItems`, appends matching tool results,
59
- and forwards cancellation. Preserve opaque `reasoning-continuity` bytes and
60
- order without decoding or displaying them. Only complete successful output
61
- can be treated as a finished result; partial JSON is not a validated object.
62
-
63
- The matching development SDK/Kit/native/Runtime preserves system messages in
64
- their submitted order, including instructions inside conversation history.
65
- Separate system-message boundaries and positions require an explicitly admitted
66
- Driver combination; unsupported combinations fail before inference instead of
67
- moving instructions to the beginning or changing their role. The initial exact
68
- DeepSeek Chat Completions v3 slice preserves these inputs in synchronous and
69
- streaming plain text, function-tool or JSON-object calls. Other combinations
70
- remain separately admitted. This does not relax the 128-message/1-MiB bounds,
71
- or the user-only media boundary.
72
-
73
- App-owned initiation or continuation can submit nonempty system/assistant
74
- context without a user-role message. The carrier does not add a filler user
75
- turn or rewrite roles. Empty and opaque-only input still fails, and exact
76
- Driver input support remains required. If an App's budget planner drops needed
77
- history, the App must report that loss rather than treating it as intentional
78
- userless generation. The narrow text candidate method is unchanged.
79
-
80
- The current Local App binding (SDK 0.21.0 / Kit/native 0.18.0 with matching
81
- Runtime) supports function tools, tool choice, structured `responseFormat`,
82
- and admitted user image parts. HTTP(S) image file
83
- parts and owned image `artifact-ref` parts preserve their order with text.
84
- Upload local image bytes through `client.ai.artifacts.upload`; do not put file
85
- paths or data URLs in model requests. Other media methods have separate contracts, and each
86
- selected execution configuration must support the requested modality and
87
- controls.
88
-
89
- The matching development cohort also carries owned WAV, MPEG audio and MP4
90
- video Artifact references in user text-generation messages. Upload the media
91
- through the App's artifact API; direct audio/video URLs and inline data remain
92
- invalid App inputs. The exact Gemini 3.8 Flash native base adapter admits this
93
- media in plain-text synchronous and streaming calls. Its tool and schema modes
94
- remain separate synchronous combinations and do not admit audio/video input.
95
- Preserving multiple system-message boundaries is a separate Driver behavior;
96
- media support does not imply that combination is supported.
97
-
98
- ## Local App speech support boundaries
99
-
100
- The current matched package combination carries a typed
101
- `job.transcription` on completed `speech-transcribe` jobs. It contains `status`
102
- (`transcribed` or `no-speech`), original `text`, model-reported `language` and
103
- ordered `words` with `text`, `startSeconds` and `endSeconds`. Plain transcription
104
- resources can leave language and words empty. Aligned results also leave
105
- `language` empty when recognition did not report it; real words and timestamps
106
- can still be present. Requesting `timestamps: true`
107
- requires a resource with actual alignment support; unsupported requests fail.
108
- The request's `language` is an input hint, not a detected-language result.
109
-
110
- DashScope's `qwen-audio-3.0-asr-flash-streaming` and admitted
111
- `fun-asr-realtime` models also execute finite `speech-transcribe` Jobs. The
112
- matching Runtime accepts mono PCM WAV up to 300 seconds and 32 MiB, waits for
113
- the provider's successful terminal event, and publishes its final text and
114
- actual word times. Partial hypotheses are not completed results. Detected
115
- language remains empty because this protocol does not report it; empty output
116
- is an error, not an inferred `no-speech`. Prompt, response-format and diarization
117
- controls are unsupported. The provider's WebSocket transport does not turn
118
- these Jobs into public realtime sessions. Longer audio remains App chunking.
119
-
120
- For the local Qwen3 aligned recipe, an explicit supported input language can
121
- guide the aligner when recognition returns text without a language label.
122
- That hint is never copied into the result's `language`. Without a reported
123
- language or an explicit supported hint, alignment fails; an unsupported
124
- reported language is not overridden by the hint. Apps can use their selected
125
- source language for downstream processing while retaining missing detection
126
- as unknown.
68
+ - **Tool Execution & Turn History**: The application owns tool handlers and subsequent conversation turns. Preserve ordered `outputItems` as `turnItems` on the next tool step, along with matching tool results.
69
+ - **Reasoning Continuity**: Preserve opaque `reasoning-continuity` payloads byte-for-byte in their original order. Do not decode or display them.
70
+ - **Validation**: Treat a response as complete only after successful completion—check the finish reason and validate the returned JSON against your business schema.
71
+
72
+ ---
73
+
74
+ ## 3. Advanced Capabilities
75
+
76
+ ### Audio Transcription (`audio.transcribe`)
77
+ Read completed speech-to-text results. Word timing is available only when the selected resource supports alignment:
127
78
 
128
79
  ```ts
129
80
  const { job } = await client.ai.scenarioJobs.get(jobId);
@@ -131,368 +82,145 @@ if (job.status === 'completed' && job.scenarioType === 'speech-transcribe') {
131
82
  const transcript = job.transcription;
132
83
  if (transcript?.status === 'transcribed') {
133
84
  for (const word of transcript.words) {
134
- console.log(word.text, word.startSeconds, word.endSeconds);
85
+ console.log(`${word.text} [${word.startSeconds}s - ${word.endSeconds}s]`);
135
86
  }
136
87
  }
137
88
  }
138
89
  ```
139
90
 
140
- `transcriptionText` remains the same original text for text-only consumers.
141
- Use the typed result rather than decoding artifact JSON. `no-speech` has empty
142
- text, language and words; it is distinct from invalid input and inference
143
- failure. The complete result is limited to 1 MiB and 16,384 alignment units.
144
-
145
- The local Qwen3 Transformers aligned recipe captures both the recognition
146
- model and its forced aligner in the selected Loadout. It accepts at most 300
147
- seconds per request and supports zh/en/yue/fr/de/it/ja/ko/pt/ru/es. Times are
148
- actual model alignment relative to the submitted audio's zero point, with
149
- pauses retained. The current aligner has 80 ms resolution. Units can be CJK
150
- characters; they are not guaranteed to be linguistic words. Text retains
151
- punctuation. For longer media, the App splits input and adds each source chunk
152
- offset exactly once; Runtime does not own App chunking or subtitle assembly.
153
- This route does not provide diarization, speaker counts, or a standalone
154
- alignment operation for caller-supplied transcripts.
155
-
156
- The local Faster Whisper recipe instead captures a CTranslate2 Whisper model
157
- and a Silero ONNX voice activity detector. It also accepts up to 300 seconds
158
- and returns real word times on the original input timeline; it does not offer
159
- diarization or prompts. A caller-specified language is a hint, not detected
160
- language, so that result field stays empty when the request fixes the language.
161
- The recognizer receives the full audio: VAD alone cannot discard weak or
162
- synthetic speech. No-speech requires both no recognized segments and no speech
163
- detected by the captured VAD. Empty recognition after detected speech fails.
164
- Neither recipe guarantees error-free subtitles; retain source timing and use
165
- the App's proofreading workflow when recognition or alignment is inaccurate.
166
-
167
- Select the intended Loadout for `audio.transcribe` in Nimi's model configuration first.
168
- The App's AIConfig Local intent is the route marker `local: {}` and carries no
169
- Loadout reference; the machine's current selection is captured at new Job
170
- admission. `listOptions({ kind: 'local-loadouts', capabilityContract:
171
- 'audio.transcribe' })` exposes that current selection, not every saved Loadout.
172
-
173
- Local `audio-separate` jobs consume `mimeType` and the same bytes/HTTPS URI
174
- `audioSource` shape as transcription. Choose the Demucs separation Loadout for
175
- `audio.separate` in Nimi, then declare that capability's `local: {}` App intent.
176
- The initial Driver accepts at most 300 seconds and 32 MiB per input. Split longer
177
- sources in the App while retaining their offsets and complete timeline.
178
-
179
- A completed Job's `audioSeparation` names `vocalsArtifactId` and
180
- `backgroundArtifactId`. Both refer to that Job's audio artifacts and preserve
181
- the input zero point, duration and pauses; background is the model's summed
182
- non-vocal sources. Read sample rate and channel count from the artifact records.
183
- The current Driver produces float WAV audio, which can exceed inline limits.
184
- Receive it through `client.storage.assets.adoptArtifact`. Use the returned
185
- record's `relativePath` for reads, previews and removal: Runtime normalizes the
186
- filename extension to the actual artifact media type, so the requested path is
187
- not necessarily the stored path. For example, requesting `transfers/result`
188
- for a WAV artifact returns `transfers/result.wav`.
91
+ - **Supported Engines**: Supports local Qwen3 aligned recipes (with 80ms resolution across CJK and European languages) and Faster Whisper with Silero VAD.
92
+ - **Resource Limits & Semantics**: Local Qwen3 aligned and Demucs routes accept bounded audio up to 300 seconds, though exact limits and available controls depend on the selected resource. Note that Qwen3 alignment units may be individual CJK characters rather than linguistic words, and a language hint is not a detected-language result.
93
+
94
+ For the local Qwen3 aligned recipe, supported language hints are `zh`, `en`, `yue`, `fr`, `de`, `it`, `ja`, `ko`, `pt`, `ru`, and `es`. Alignment uses the input audio timeline; keep pauses and add chunk offsets exactly once when assembling longer media. The complete transcription result is bounded to 1 MiB and 16,384 alignment units. An absent detected language remains unknown, even when a language hint was supplied.
95
+
96
+ ### Audio Separation (`audio.separate`)
97
+ Separate vocals and accompaniment using local Demucs models:
189
98
 
190
99
  ```ts
191
- const adopted = await client.storage.assets.adoptArtifact({ artifactId, relativePath });
192
- const received = await client.storage.assets.read({ relativePath: adopted.relativePath });
100
+ // Submit separation job
101
+ const { job } = await client.ai.scenarioJobs.submit({
102
+ type: 'audio-separate',
103
+ mimeType: 'audio/wav',
104
+ audioSource: { type: 'bytes', bytes: audioBuffer },
105
+ });
106
+
107
+ // Save job.jobId. Once observation reports completion, read the final result.
108
+ const { job: completed } = await client.ai.scenarioJobs.get(job.jobId);
109
+ if (completed.status === 'completed' && completed.audioSeparation) {
110
+ const vocals = await client.storage.assets.adoptArtifact({
111
+ artifactId: completed.audioSeparation.vocalsArtifactId,
112
+ relativePath: 'audio/vocals.wav',
113
+ });
114
+ // Use vocals.relativePath: the stored extension may be normalized.
115
+ console.log(vocals.relativePath);
116
+ }
193
117
  ```
194
118
 
195
- Consume `received.body` fully before committing the App's result. If the asset
196
- was a temporary transfer, remove `adopted.relativePath` only after reception.
197
- Treat the pair as complete in the App only after both outputs have been received.
198
- Do not infer roles from filenames, replace background with the input mix, or
199
- count a canceled/failed Job as a partial success.
200
-
201
- Check required inputs and outputs before migrating a workflow. A missing
202
- configuration, an implementation defect in an existing contract, and a required
203
- new capability are different integration outcomes. Report the expected result
204
- and actual supported interface rather than silently dropping a core feature.
205
-
206
- ### Interactive dictation with finite transcription jobs
207
-
208
- An App that already implements windowed dictation can submit its bounded audio
209
- windows as `speech-transcribe` Jobs. Capture, silence detection, window offsets,
210
- draft display, utterance commits and document storage remain App-owned. Show
211
- only actual recognized text as a draft; a later window may revise it. Serialize
212
- or bound pending work so a slower recognizer cannot create an unbounded queue.
213
- Pause capture without inventing a transcript, drain the final window on an
214
- explicit stop, and cancel in-flight Jobs on discard. Ignore late results from a
215
- discarded capture generation and retain already committed utterances without
216
- appending them again in the final document.
217
-
218
- This composition does not make a finite recognizer a native streaming Driver.
219
- Verify its actual latency and pause/stop/cancel behavior in the App. The separate
220
- `client.ai.realtime` interface implements `realtime.interact`; its presence does
221
- not establish a local, transcription-only route. Do not silently substitute a
222
- Cloud conversation model for local dictation.
223
-
224
- ### Creating and reusing voices
225
-
226
- SDK 0.15.0 and Kit/native 0.11.0 expose optional `referenceAudioInput` on
227
- AIConfig effective Local resources and Cloud targets, also present in their
228
- options. Read it from the selected `voice.create` resource. It contains
229
- `supportsBytes`, `supportsUri`, `textMode` (`unsupported`, `optional`, or
230
- `required`) and `mimeTypes`. Missing metadata means unknown or inapplicable;
231
- an empty MIME list means formats are not enumerated. Neither means arbitrary
232
- input support. Runtime still validates the actual request at admission.
233
-
234
- When `textMode` is `unsupported`, pass `text: ''` in the SDK's reference-audio
235
- spec and keep any transcript in App storage. When optional, send the actual
236
- reference transcript if available; when required, request one before creating
237
- the voice. Do not select these behaviors by provider/model name. Local Qwen3
238
- reference workflows accept both public URI and bytes with optional text; the
239
- Runtime captures a URI into private bytes and empty text uses the model's
240
- reference-only mode. Choosing URI input never uploads an existing local file.
241
-
242
- Submit `voice-create` through `client.ai.scenarioJobs` with exactly one
243
- `creationSource`: `reference-audio` (audio bytes or HTTPS URI, MIME type and
244
- optional reference transcript in `text`) or `text-description` (instruction and
245
- preview text). Read the completed Job with `get(jobId)` to obtain `asset` and
246
- `voiceReference`. For synthesis, pass the returned asset identity as
247
- `voiceRef: { type: 'voice-asset', id: asset.voiceAssetId }` in a
248
- `speech-synthesize` Job. Creation success is not proof that playable audio was
249
- generated; the local Qwen3 creation paths return a voice handle and
250
- requires a synthesis Job to produce the preview audio.
251
-
252
- Both operations use their own committed capability configuration. The selected
253
- `voice.create` implementation must support `input.audio` or `input.text` for the
254
- requested source. Separate local Qwen3 clone and design recipes require their
255
- respective Loadouts; synthesis also needs a compatible selected Loadout. A source
256
- field does not switch a model or route. Expose unmet configuration to the user instead
257
- of retrying through a different engine. Existing engine-specific seed, sampling
258
- or guidance controls must not be silently mapped to unrelated public fields.
259
-
260
- For DashScope Qwen-Audio 3.0 voices, select the same current TTS model for
261
- `voice.create` and `audio.synthesize`. Both Plus and Flash use the provider's
262
- voice-enrollment and SpeechSynthesizer protocols. Reference-audio creation
263
- requires a publicly reachable HTTP(S) URI; inline bytes and a local file path
264
- are not supported by this provider workflow. Nimi does not publish an App's
265
- private audio to obtain a URL. Preserve the user's reference URI explicitly,
266
- or select a configuration that accepts bytes. A cloned voice's target model
267
- must match later synthesis. The current provider accepts 16-bit WAV, MP3 or
268
- M4A, at least 16 kHz, at most 60 seconds and 10 MB; it recommends 10–20 seconds
269
- with at least five seconds of continuous clear speech. Stereo uses the first
270
- channel. The reference transcript is unsupported for this workflow; retain it
271
- as business metadata rather than submitting it as a model prompt. Check the
272
- [provider's reference requirements](https://help.aliyun.com/zh/model-studio/voice-cloning-user-guide)
273
- when preparing a new sample. Voice design accepts an English or Chinese
274
- description of at most 500 characters and a preview of 15–200 characters in
275
- the same supported language. Synthesis supports additional languages,
276
- including Spanish; that does not expand the design preview's language range.
277
- The App keeps voice metadata and audition/export files in its business storage.
278
-
279
- The current local Qwen3 synthesis Driver accepts WAV output and no timing mode
280
- beyond `none`. It rejects supplied `speed`, `pitch`, `volume`, `sampleRateHz` and
281
- `voiceRenderHints`, including explicit neutral values such as `speed: 1`. Omit
282
- those fields. When the product's playback speed or delivery format is a
283
- deterministic media-editing operation, preserve it in the App after generation
284
- (for example, FFmpeg tempo conversion), using the actual decoded audio format.
285
- That post-processing is distinct from a model's acoustic generation control.
286
-
287
- Qwen3 Base reference-voice synthesis does not provide per-utterance style or
288
- emotion instructions. The CustomVoice preset path maps `emotion` to its own
289
- natural-language instruction; this does not establish support for Base voice
290
- assets. A `voice-create` design instruction describes the voice being created,
291
- not a later utterance's prosody. Other engines' inline expression tokens, such
292
- as OmniVoice's `[laughter]` or `[question-en]`, have no defined Qwen3 mapping.
293
- Keep unsupported model-specific controls explicit instead of silently mapping
294
- them to another field or assuming literal text will produce the intended effect.
295
-
296
- For a library that mixes cloned and designed voices, select the explicit
297
- **Qwen3 design and reference voice library** recipe for `voice.create`. Bind its
298
- Base and VoiceDesign models independently, and select that same Base ModelAsset
299
- for `audio.synthesize`. The library admits both source features in one captured
300
- configuration. A `text-description` Job requires nonempty `previewText`, runs
301
- VoiceDesign to create real reference audio, then returns a Base-compatible voice
302
- asset containing that reference. Reference-audio creation uses the supplied
303
- audio. Both kinds of asset subsequently synthesize with Base, so a story or
304
- batch can mix them without changing the machine selection. Wait for creation to
305
- complete before requesting audition audio; design creation now includes model
306
- execution and follows the ordinary Job timeout and cancellation lifecycle.
307
-
308
- Keep business voice names, descriptions, original reference audio and transcript,
309
- and saved previews in App storage. A Runtime VoiceAsset is not the App's voice
310
- library record or a permanent audio backup. Save the `voiceAssetId` actually
311
- used for an approved take and reuse it to synthesize with that same voice;
312
- there is no requirement to clone every audition again. Runtime revalidates its
313
- owner, status and target compatibility. An expired or incompatible asset fails
314
- explicitly rather than causing hidden recreation, upload or route switching.
315
- This retains the voice identity, not identical audio or prosody on every take.
316
-
317
- If the user instead chooses actual sample audio as a new reference, or edits,
318
- denoises or replaces the reference, invalidate the previous reference/asset
319
- association and use `reference-audio` creation for that new input. A cached
320
- source VoiceAsset does not represent edited output audio. Preserve the actual
321
- chosen audio and transcript in either workflow, distinguish the two actions in
322
- the product, and apply normal resource eligibility and configuration checks.
323
-
324
- ## Persisting results and resuming jobs
325
-
326
- Runtime Job storage is bounded execution state, not the App's project database.
327
- The current Runtime retains terminal Jobs for up to 30 minutes and applies a
328
- count limit. Save complete validated results in App-managed storage while the
329
- Job is available; adopt output artifacts when the project needs to retain them.
330
- Persisting only a Job ID does not preserve its result or artifact bytes.
331
-
332
- When resuming a project, reuse complete App-owned results. If a step has only
333
- an old Job ID, and the normal public Job read explicitly returns `not-found`,
334
- record that reference as unavailable. An explicit continue/retry action may
335
- then submit that unfinished step again from its original input and save the new
336
- ID. Do not poll a missing Job indefinitely, mark it completed, or rerun already
337
- completed project steps. Permission, session and transport errors are different
338
- failures and must not trigger the missing-Job recovery path.
339
-
340
- ## Structured text
341
-
342
- `createNimiLocalAppTextModel(client.ai)` binds text generation to an installed
343
- App's protected session. Its name does not restrict execution to a local model:
344
- the App's committed AI configuration chooses Local or Cloud.
345
-
346
- Request JSON with `responseFormat: { type: 'json-object' }` and consume it only
347
- after `generateText` completes. A configured route is not proof that every text
348
- behavior is available; unsupported behavior fails before dispatch, and malformed
349
- model output remains a failure. Do not extract a plausible JSON fragment or
350
- change providers automatically to turn that failure into success.
351
-
352
- The matching development Runtime admits DeepSeek `deepseek-flash` (currently
353
- served by V4.1 Flash), `deepseek-v4-flash` and `deepseek-v4-pro`. These provider
354
- API names are not immutable weight-version pins. Record the exact configured
355
- target and test date when comparing results; prefer the current `deepseek-flash`
356
- name for new Flash selections.
357
-
358
- The exact adapters support JSON-object output or native function-tool calls,
359
- including streamed completion, complete tool arguments and tool-result turns.
360
- These are separate admitted combinations: do not combine tools and JSON output.
361
- Thinking is disabled; requested reasoning, JSON Schema, media input, `topK` and
362
- `seed` are not admitted by this slice. The App still uses the same model interface
363
- and AI configuration; it never calls DeepSeek directly or executes a model's
364
- tool request inside Runtime.
365
-
366
- ## Language analysis
367
-
368
- Use the `text.annotate` AI configuration capability and submit an asynchronous
369
- `text-annotate` Job through the existing scenario Job API:
119
+ When handling separation outputs:
120
+ - Adopt both separation outputs before presenting a complete pair.
121
+ - Read sample rate and channel count from the artifact records, and retain the source timeline when splitting longer audio.
122
+ - Treat failed or canceled Jobs as incomplete—never present them as a partial success.
123
+
124
+ ### Custom Voice Creation & Synthesis (`voice.create` & `audio.synthesize`)
125
+ Clone a voice from reference audio or design a new persona via natural language:
126
+
127
+ ```ts
128
+ // Create a voice persona from audio reference
129
+ const { job } = await client.ai.scenarioJobs.submit({
130
+ type: 'voice-create',
131
+ creationSource: 'reference-audio',
132
+ referenceAudio: { type: 'bytes', bytes: sampleAudioBytes },
133
+ referenceAudioMime: 'audio/wav',
134
+ languageHints: [],
135
+ preferredName: 'My voice',
136
+ text: '', // Follow the selected resource’s referenceAudioInput.textMode.
137
+
138
+ });
139
+
140
+ // After observing completion, retrieve the voice asset separately from the Job.
141
+ const result = await client.ai.scenarioJobs.get(job.jobId);
142
+ if (result.job.status === 'completed' && result.asset?.status === 'active') {
143
+ await client.ai.scenarioJobs.submit({
144
+ type: 'speech-synthesize',
145
+ text: 'Hello world, speaking in the newly created voice!',
146
+ language: '', audioFormat: 'wav', emotion: '',
147
+ voiceRef: { type: 'voice-asset', id: result.asset.voiceAssetId },
148
+ timingMode: 'none', voiceRenderHints: null,
149
+ });
150
+ }
151
+ ```
152
+
153
+ Before building your form, inspect `referenceAudioInput` on the selected `voice.create` resource: it declares the supported input forms and whether reference text is required, optional, or unsupported (the example above passes empty text, so choose a resource that admits it). Also ensure that voice creation and synthesis use compatible selected resources—a created asset does not guarantee that every synthesis route can render it.
154
+
155
+ ### Language Analysis (`text.annotate`)
156
+ Perform part-of-speech tagging, lemmatization, and syntactic dependency parsing:
370
157
 
371
158
  ```ts
372
159
  const { job } = await client.ai.scenarioJobs.submit({
373
160
  type: 'text-annotate',
374
161
  language: 'en',
375
- texts: ['A sentence to analyze.'],
162
+ texts: ['Nimi puts personal sovereignty at the center of modern computing.'],
376
163
  });
377
- // Subscribe or get this Job through the same scenarioJobs service.
378
- // Read job.textAnnotation only after status === 'completed'.
164
+
165
+ // Completed job contains structured token annotations with exact Unicode scalar offsets
379
166
  ```
380
167
 
381
- `texts` is an ordered batch of
382
- 1–64 strings, including empty strings, totaling at most 512 KiB of UTF-8.
383
- The completed Job's `textAnnotation.documents` preserves that batch order and
384
- the exact original text and whitespace. Each document contains:
385
-
386
- - `text`, `language` and an ordered `tokens` array.
387
- - Each token's `text`, `start`, `end`, `headIndex`, `partOfSpeech`, `dependency`
388
- and `isPunctuation`.
389
- - `sentences`, each with `startToken` and exclusive `endToken`.
390
-
391
- Token `start`/`end` count **Unicode scalar values**, not UTF-8 bytes or JavaScript
392
- UTF-16 code units. Python can slice its original string directly; JavaScript can
393
- use `Array.from(document.text).slice(start, end).join('')`. Token array positions
394
- are their indices, heads are document-local, and a span's original text extends
395
- from its first token's start to its last token's end. Sentence spans partition
396
- the token array. Empty documents have no tokens or sentences.
397
-
398
- The initial local spaCy implementation uses the original md 3.8.0 pipelines for
399
- en/de/es/fr/it/ru/zh/ja. The active Nimi model configuration must contain the
400
- pipeline for the requested language. `language` validates that choice; it does
401
- not override machine selection. Model installation and dependency preparation
402
- belong to Nimi, and inference never downloads a model in the App. A batch is
403
- bounded to 65536 tokens and a 16 MiB normalized result; oversized or failed analysis
404
- returns failure rather than partial annotations. Keep subtitle splitting rules,
405
- translation, time matching, project state and repeated analysis in the App.
406
- These annotations contain no audio timestamps or generated replacement text.
407
-
408
- This addition requires a matching development Runtime, SDK, Kit and native
409
- package set. Keep using the documented local tarball workflow during iteration;
410
- package publication is not a development prerequisite.
411
-
412
- ## Text decisions
413
-
414
- Use the `text.decide` AI configuration capability and the synchronous
415
- `text-decide` execute variant to score App-authored questions about one state:
168
+ ### Structured Text Decisions (`text.decide`)
169
+ Score probability distributions over state-dependent choices or boolean hypotheses:
416
170
 
417
171
  ```ts
418
- const controller = new AbortController();
419
- const { output, traceId } = await client.ai.scenario.execute({
172
+ const { output } = await client.ai.scenario.execute({
420
173
  type: 'text-decide',
421
- state: { json: { hand: ['A', 'K'], pot: 12 } }, // or { text: '...' }
174
+ state: { json: { gameRound: 3, playerChips: 450 } },
422
175
  questions: [
423
- { id: 'action', instructions: { text: 'Choose the action.' }, kind: 'choice',
424
- candidates: [{ id: 'fold' }, { id: 'call', description: { text: 'Match the bet.' } }] },
425
- { id: 'bluff', instructions: { text: 'Is the opponent bluffing?' }, kind: 'boolean' },
176
+ {
177
+ id: 'next_action',
178
+ instructions: { text: 'Choose the optimal next action.' },
179
+ kind: 'choice',
180
+ candidates: [{ id: 'raise' }, { id: 'call' }, { id: 'fold' }],
181
+ },
182
+ {
183
+ id: 'opponent_bluffing',
184
+ instructions: { text: 'Is the opponent likely bluffing?' },
185
+ kind: 'boolean',
186
+ },
426
187
  ],
427
- }, { signal: controller.signal, timeoutMs: 10_000 });
428
- // output.type === 'text-decide'; output.answers follow the submitted order.
188
+ }, { timeoutMs: 10_000 });
429
189
  ```
430
190
 
431
- State is nonblank text or one JSON object or array (at most 256 KiB, 64 nesting
432
- levels); 1–64 questions with unique IDs; instructions at most 32 KiB; a choice has
433
- 2–255 unique candidates; descriptions and boolean criteria are optional and at most
434
- 8 KiB; IDs are 1–64 bytes without surrounding whitespace or control characters; the
435
- complete request is at most 1 MiB. JSON content is sent as its `JSON.stringify`
436
- text, so key insertion order is kept. Invalid input fails before transport.
437
-
438
- Each choice answer carries the selected candidate and one probability per submitted
439
- candidate in submitted order; each boolean answer carries `trueProbability`. There is
440
- no confidence, usage, provider or model field. Thresholds, grouping and actions stay
441
- in the App. Input that is valid but cannot be encoded completely by the configured
442
- implementation fails with `ai-input-limit-exceeded` (`AI_INPUT_LIMIT_EXCEEDED`).
443
-
444
- Every execute variant accepts per-call options. Aborting settles the call at once
445
- with `OPERATION_ABORTED`; an elapsed `timeoutMs` (1–120000) settles it with
446
- `OPERATION_TIMEOUT`. Either failure cancels the pending Runtime call, never returns a
447
- late result and leaves the protected App session valid.
448
-
449
- ## Public entry points
450
-
451
- | Import | Purpose |
452
- | --- | --- |
453
- | `@nimiplatform/sdk/app` | Host-bound App client, standard shell contracts and typed App operations. |
454
- | `@nimiplatform/sdk/ai` | Model interfaces and the Local App text model binding. |
455
- | `@nimiplatform/sdk/contracts` | Shared messages, content parts, tool and ordered result values. |
456
- | `@nimiplatform/sdk/ai-runner` | External-host execution helpers; they do not move App workflow state into Runtime. |
457
- | `@nimiplatform/sdk/runtime` | Public Runtime clients for their explicitly supported consumer contexts. This is not a Local App authorization bypass. |
458
- | `@nimiplatform/sdk/realm` | Public Realm clients for their supported contexts; App Realm operations use the App client. |
459
-
460
- The installed package's `exports` and `.d.ts` files define the exact callable
461
- surface. Framework adapters are separate packages; do not infer that an
462
- adapter is publicly available from a source-workspace directory.
463
-
464
- For Vercel AI SDK 6 Apps, the separate `@nimiplatform/sdk-adapter-vercel-ai`
465
- package provides `createNimiLocalAppVercelLanguageModel({ ai: client.ai })` for
466
- `streamText` and the existing UI/tool-loop protocol. Adapter 0.3.0 pairs with
467
- SDK 0.19.0 and Kit/native 0.16.0; the earlier adapter 0.1.0 declares SDK
468
- `^0.13.0` and does not accept a later SDK minor. Read its package README before
469
- mapping images or conversation history, and preserve text/tool provider
470
- metadata for opaque continuity.
471
-
472
- Source and issue reporting: [nimiplatform/nimi](https://github.com/nimiplatform/nimi).
473
- Include the selected SDK, Kit, App Tools and Runtime versions, the actual App
474
- operation, expected/observed behavior, and a bounded reproduction.
191
+ ---
475
192
 
476
- Licensed under [Apache-2.0](LICENSE).
193
+ ## 4. Public Subpaths & Modules
477
194
 
478
- ### Observing and canceling Jobs
479
-
480
- All Job runners and observers use `getIntervalMs` (default `1000` milliseconds,
481
- positive integer) to query the same original Job even when an event subscription
482
- is healthy and silent. Gets are serialized. `onObservation` receives each full
483
- Get, including a transient `observationIssue`; the issue does not change the Job
484
- status. `runNimiRuntimeScenarioJob` and `observeNimiRuntimeScenarioJob` return that
485
- complete terminal response as `response`, including typed outer results.
486
-
487
- A runner's `signal` is an explicit user Cancel request. Use its
488
- `observationSignal` for view disposal, navigation or stopping observation. For
489
- `observeNimiRuntimeScenarioJob`, `signal` only
490
- detaches and optional `cancelSignal` requests Cancel explicitly. Cancel rejection
491
- is reported as an observation error with the original Job ID, without a fabricated
492
- terminal state. A successful Cancel still requires a full terminal Get. Technical
493
- `callOptions` budgets remain independent of Job lifetime.
494
-
495
- Save the business action before Submit and persist its returned Job ID. Reopen
496
- by original ID or submission lookup; missing or expired actions never trigger a
497
- new Submit. Observers do not own App history or media custody. Read/adopt results
498
- through their formal typed, artifact or resource owners while retention permits.
195
+ | Subpath | Description |
196
+ | :--- | :--- |
197
+ | `@nimiplatform/sdk` | Core entry point; exports `createNimiClient` |
198
+ | `@nimiplatform/sdk/app` | Host-bound app client types, shell contracts, and app operations |
199
+ | `@nimiplatform/sdk/ai` | AI model interfaces, text model bindings, and artifact utilities |
200
+ | `@nimiplatform/sdk/contracts` | Common message schemas, content parts, and tool definitions |
201
+ | `@nimiplatform/sdk/runtime` | Strongly-typed Runtime client for authorized external processes |
202
+ | `@nimiplatform/sdk/realm` | Standalone Realm client for user identities, worlds, and characters |
203
+ | `@nimiplatform/sdk/types` | Portable TypeScript types, schemas, and standardized error codes |
204
+ | `@nimiplatform/sdk-adapter-vercel-ai` | Separate adapter package for Vercel AI SDK 7 integration |
205
+
206
+ ---
207
+
208
+ ## 5. Protected Conversation Quotation and Source Reads
209
+
210
+ For LocalAgent chat, use `client.conversation.readMessage({ agentHandle, conversationAnchorId, messageId })` to prepare a quote or navigate to a canonical source in the current authorized Conversation. A readable stable text message returns `quoteText` and `quoteFormat`; other message kinds return both as `null`. The bounded `window` and its `readWatermark` are navigation data, not a replacement live snapshot.
211
+
212
+ Send the user’s own text or attachment parts with an optional `quote` containing only `sourceMessageId`, the returned format, and a half-open UTF-8 byte range. Runtime supplies the confirmed author, partial state and excerpt. A quote does not replace required input parts, permit cross-Conversation access, or alter regeneration inputs. Preserve the entire original request envelope when reconciling an uncertain submission. See the current migration notes for the matching source carrier requirement.
213
+
214
+ ## 6. Async Job Observation & Cancellation
215
+
216
+ Long-running generation tasks (audio transcription, separation, voice cloning) are managed as asynchronous scenario jobs:
217
+
218
+ - **Polling & Events**: Observe jobs with `client.ai.scenarioJobs.get(jobId)` or stream progress via observers.
219
+ - **Cancellation**: Call `client.ai.scenarioJobs.cancel(jobId)` to cancel an asynchronous Job, or pass an `AbortSignal` to control supported synchronous calls and model steps. Always inspect the returned state—a cancellation request does not guarantee that a remote provider has stopped computing or billing.
220
+ - **Artifact Custody**: Execution artifacts are temporary. Adopt completed outputs with `client.storage.assets.adoptArtifact` and use its returned path. While recovery-enabled Jobs expose `recoveryExpiresAt`, retention windows vary—persist durable App assets for later reopening rather than assuming every Job shares the same retention period.
221
+
222
+ ---
223
+
224
+ ## License
225
+
226
+ Licensed under [Apache-2.0](LICENSE).