kiki-agent 0.4.2 → 0.5.1

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 (238) hide show
  1. package/README.md +3 -3
  2. package/dist/cpu-worker.mjs +52744 -0
  3. package/dist/docs/en/configuration/config-files.md +121 -46
  4. package/dist/docs/en/configuration/data-locations.md +34 -7
  5. package/dist/docs/en/configuration/env-vars.md +37 -9
  6. package/dist/docs/en/configuration/overrides.md +20 -9
  7. package/dist/docs/en/configuration/providers.md +114 -9
  8. package/dist/docs/en/customization/agent-profiles.md +1 -1
  9. package/dist/docs/en/customization/agents-and-subagents.md +55 -12
  10. package/dist/docs/en/customization/hooks.md +3 -3
  11. package/dist/docs/en/customization/personas.md +36 -2
  12. package/dist/docs/en/customization/plugins.md +56 -3
  13. package/dist/docs/en/customization/prompt-fields.md +65 -5
  14. package/dist/docs/en/customization/recipes.md +77 -0
  15. package/dist/docs/en/customization/skins.md +2 -2
  16. package/dist/docs/en/customization/themes.md +1 -1
  17. package/dist/docs/en/features/agent-workflows.md +8 -8
  18. package/dist/docs/en/features/browser-and-computer.md +40 -0
  19. package/dist/docs/en/features/daily.md +13 -13
  20. package/dist/docs/en/features/ecosystem.md +6 -6
  21. package/dist/docs/en/features/extend.md +11 -10
  22. package/dist/docs/en/features/freedom.md +9 -9
  23. package/dist/docs/en/features/index.md +58 -28
  24. package/dist/docs/en/features/long-work.md +18 -14
  25. package/dist/docs/en/features/look.md +6 -6
  26. package/dist/docs/en/features/people.md +6 -6
  27. package/dist/docs/en/features/phone.md +13 -3
  28. package/dist/docs/en/features/spaces.md +12 -12
  29. package/dist/docs/en/features/workbench.md +8 -8
  30. package/dist/docs/en/getting-started/desktop-app.md +4 -8
  31. package/dist/docs/en/getting-started/first-launch.md +1 -1
  32. package/dist/docs/en/guides/goals.md +4 -2
  33. package/dist/docs/en/guides/interface.md +32 -10
  34. package/dist/docs/en/guides/memory.md +64 -10
  35. package/dist/docs/en/guides/sessions.md +21 -9
  36. package/dist/docs/en/guides/settings.md +64 -40
  37. package/dist/docs/en/index.md +3 -1
  38. package/dist/docs/en/reference/command.md +90 -31
  39. package/dist/docs/en/reference/model-vocabulary.md +2 -2
  40. package/dist/docs/en/reference/slash-commands.md +1 -1
  41. package/dist/docs/en/reference/tools.md +65 -20
  42. package/dist/docs/en/server/acp.md +9 -3
  43. package/dist/docs/en/server/local-server.md +19 -27
  44. package/dist/docs/en/server/mcp.md +9 -5
  45. package/dist/docs/en/server/rest-api.md +350 -22
  46. package/dist/docs/en/server/script-tools.md +268 -0
  47. package/dist/docs/zh/configuration/config-files.md +121 -46
  48. package/dist/docs/zh/configuration/data-locations.md +34 -7
  49. package/dist/docs/zh/configuration/env-vars.md +37 -9
  50. package/dist/docs/zh/configuration/overrides.md +20 -9
  51. package/dist/docs/zh/configuration/providers.md +114 -9
  52. package/dist/docs/zh/customization/agent-profiles.md +1 -1
  53. package/dist/docs/zh/customization/agents-and-subagents.md +55 -12
  54. package/dist/docs/zh/customization/hooks.md +3 -3
  55. package/dist/docs/zh/customization/personas.md +36 -2
  56. package/dist/docs/zh/customization/plugins.md +56 -3
  57. package/dist/docs/zh/customization/prompt-fields.md +65 -5
  58. package/dist/docs/zh/customization/recipes.md +77 -0
  59. package/dist/docs/zh/customization/skins.md +2 -2
  60. package/dist/docs/zh/customization/themes.md +1 -1
  61. package/dist/docs/zh/features/agent-workflows.md +10 -10
  62. package/dist/docs/zh/features/browser-and-computer.md +40 -0
  63. package/dist/docs/zh/features/daily.md +13 -13
  64. package/dist/docs/zh/features/ecosystem.md +6 -6
  65. package/dist/docs/zh/features/extend.md +10 -9
  66. package/dist/docs/zh/features/freedom.md +9 -9
  67. package/dist/docs/zh/features/index.md +58 -28
  68. package/dist/docs/zh/features/long-work.md +17 -13
  69. package/dist/docs/zh/features/look.md +6 -6
  70. package/dist/docs/zh/features/people.md +5 -5
  71. package/dist/docs/zh/features/phone.md +13 -3
  72. package/dist/docs/zh/features/spaces.md +12 -12
  73. package/dist/docs/zh/features/workbench.md +8 -8
  74. package/dist/docs/zh/getting-started/desktop-app.md +4 -8
  75. package/dist/docs/zh/getting-started/first-launch.md +1 -1
  76. package/dist/docs/zh/guides/goals.md +4 -2
  77. package/dist/docs/zh/guides/interface.md +32 -10
  78. package/dist/docs/zh/guides/memory.md +64 -10
  79. package/dist/docs/zh/guides/sessions.md +21 -9
  80. package/dist/docs/zh/guides/settings.md +64 -40
  81. package/dist/docs/zh/index.md +4 -2
  82. package/dist/docs/zh/reference/command.md +90 -31
  83. package/dist/docs/zh/reference/model-vocabulary.md +2 -2
  84. package/dist/docs/zh/reference/slash-commands.md +1 -1
  85. package/dist/docs/zh/reference/tools.md +65 -20
  86. package/dist/docs/zh/server/acp.md +9 -3
  87. package/dist/docs/zh/server/local-server.md +19 -27
  88. package/dist/docs/zh/server/mcp.md +9 -5
  89. package/dist/docs/zh/server/rest-api.md +338 -21
  90. package/dist/docs/zh/server/script-tools.md +268 -0
  91. package/dist/external-harness/agy-cli-acp.mjs +168 -162
  92. package/dist/external-harness/agy-hook-registration.mjs +69 -30
  93. package/dist/external-harness/agy-mcp-plugin.mjs +19 -0
  94. package/dist/external-harness/agy-permission-hook.mjs +29 -2
  95. package/dist/hostRunner.mjs +112 -3
  96. package/dist/mailbox-worker.mjs +403 -0
  97. package/dist/main.mjs +2 -2
  98. package/dist/memory-worker.mjs +1008 -0
  99. package/dist/native/windows-process-helper.exe +0 -0
  100. package/dist/query-store-worker.mjs +487 -0
  101. package/dist/sqlite-indexer.mjs +255 -403
  102. package/dist/sqlite-query-worker.mjs +261 -249
  103. package/dist/usage-parser-worker.mjs +3977 -9
  104. package/dist/usage-read-model-worker.mjs +761 -0
  105. package/dist/web/assets/AppErrorBoundary-B5Fc4f6-.js +1 -0
  106. package/dist/web/assets/NavScopeBoundary-C7MnGQio.js +1 -0
  107. package/dist/web/assets/{arc-DYDCMlOS.js → arc-DGB9OVgQ.js} +1 -1
  108. package/dist/web/assets/{architectureDiagram-3BPJPVTR-C9Y7T0O2.js → architectureDiagram-3BPJPVTR-glnQCMub.js} +1 -1
  109. package/dist/web/assets/{blockDiagram-GPEHLZMM-CdUrp-tD.js → blockDiagram-GPEHLZMM-bM0tnGby.js} +1 -1
  110. package/dist/web/assets/{c4Diagram-AAUBKEIU-PrwvB9IJ.js → c4Diagram-AAUBKEIU-DMf_rTtt.js} +1 -1
  111. package/dist/web/assets/channel-Cj8SKJ38.js +1 -0
  112. package/dist/web/assets/{chunk-2J33WTMH-BL56g_Es.js → chunk-2J33WTMH-mTccJ3tW.js} +1 -1
  113. package/dist/web/assets/{chunk-4BX2VUAB-DvJD5M9M.js → chunk-4BX2VUAB-DhqPYMjY.js} +1 -1
  114. package/dist/web/assets/{chunk-55IACEB6-C8f-nzvx.js → chunk-55IACEB6-BujrYRoO.js} +1 -1
  115. package/dist/web/assets/{chunk-727SXJPM-DOGkWKkV.js → chunk-727SXJPM-ciMmSI4G.js} +1 -1
  116. package/dist/web/assets/{chunk-AQP2D5EJ-fFOuz7g6.js → chunk-AQP2D5EJ-CZW9pKTc.js} +1 -1
  117. package/dist/web/assets/{chunk-FMBD7UC4-BpeXZ9LM.js → chunk-FMBD7UC4-hdALNnnU.js} +1 -1
  118. package/dist/web/assets/{chunk-ND2GUHAM-CRUh76fb.js → chunk-ND2GUHAM-CgKyqUdb.js} +1 -1
  119. package/dist/web/assets/{chunk-QZHKN3VN-uNfxaPk0.js → chunk-QZHKN3VN-B2mmUz_E.js} +1 -1
  120. package/dist/web/assets/classDiagram-4FO5ZUOK-f8V9p-dD.js +1 -0
  121. package/dist/web/assets/classDiagram-v2-Q7XG4LA2-f8V9p-dD.js +1 -0
  122. package/dist/web/assets/client-ClWQBErG.js +3 -0
  123. package/dist/web/assets/connection-C0J3BPgk.js +1 -0
  124. package/dist/web/assets/{cose-bilkent-S5V4N54A-BNkxG-qX.js → cose-bilkent-S5V4N54A-UV3uPjkK.js} +1 -1
  125. package/dist/web/assets/{dagre-BM42HDAG-BerioUei.js → dagre-BM42HDAG-Zjy-gQ6C.js} +1 -1
  126. package/dist/web/assets/{diagram-2AECGRRQ-Czv2SR07.js → diagram-2AECGRRQ-DL-kilIf.js} +1 -1
  127. package/dist/web/assets/{diagram-5GNKFQAL-Uzi1weGK.js → diagram-5GNKFQAL-CjB_xR5B.js} +1 -1
  128. package/dist/web/assets/{diagram-KO2AKTUF-W36h_ff3.js → diagram-KO2AKTUF-CjN4i3b9.js} +1 -1
  129. package/dist/web/assets/{diagram-LMA3HP47-FG4dDk52.js → diagram-LMA3HP47-CPCAMndo.js} +1 -1
  130. package/dist/web/assets/{diagram-OG6HWLK6-CQoEjIAY.js → diagram-OG6HWLK6-DVeBWBKd.js} +1 -1
  131. package/dist/web/assets/{erDiagram-TEJ5UH35-Ck06KVyZ.js → erDiagram-TEJ5UH35-CHKzBHrr.js} +1 -1
  132. package/dist/web/assets/export-CXoWon32.js +2 -0
  133. package/dist/web/assets/{flowDiagram-I6XJVG4X-C5hgxdFZ.js → flowDiagram-I6XJVG4X-C5rQa2pq.js} +1 -1
  134. package/dist/web/assets/{ganttDiagram-6RSMTGT7-BS52Pw5_.js → ganttDiagram-6RSMTGT7-BrLjEsNJ.js} +1 -1
  135. package/dist/web/assets/{gitGraphDiagram-PVQCEYII-DLlQKZHs.js → gitGraphDiagram-PVQCEYII-3DRR5VZj.js} +1 -1
  136. package/dist/web/assets/highlighted-body-OFNGDK62-Bdj5SJfv.js +1 -0
  137. package/dist/web/assets/index-2Vx5mHRn.js +1 -0
  138. package/dist/web/assets/index-B1UXw2C9.js +1 -0
  139. package/dist/web/assets/{index-CM-nNfuV.js → index-BJxtlf4P.js} +4 -4
  140. package/dist/web/assets/{index-DKIysLbI.js → index-BY7jPurv.js} +1 -1
  141. package/dist/web/assets/index-Bq79v-Sa.js +1 -0
  142. package/dist/web/assets/index-BqD3iTIl.js +1 -0
  143. package/dist/web/assets/index-Br3AlBrQ.js +1 -0
  144. package/dist/web/assets/{index-Ca607_hK.js → index-BvRBCpc6.js} +2 -2
  145. package/dist/web/assets/index-BxYCSNg_.js +3 -0
  146. package/dist/web/assets/{index-B2Pu0Iuu.js → index-C62wjCF_.js} +1 -1
  147. package/dist/web/assets/index-CBvwNH_H.js +1 -0
  148. package/dist/web/assets/{index-BNch_a4L.js → index-CG9e6lgq.js} +1 -1
  149. package/dist/web/assets/{index-ByiwExpV.js → index-CPSWYh_R.js} +2 -2
  150. package/dist/web/assets/index-CS4xJLZV.js +1 -0
  151. package/dist/web/assets/index-CjvqtF2I.js +1 -0
  152. package/dist/web/assets/index-CprdjRRk.js +13 -0
  153. package/dist/web/assets/{index-Bg99yVX_.js → index-CypTtrCB.js} +1 -1
  154. package/dist/web/assets/{index-BwcG86o3.js → index-DDJQGcUL.js} +1 -1
  155. package/dist/web/assets/index-DLWzxUOO.js +1 -0
  156. package/dist/web/assets/index-DQxkxZmn.js +7 -0
  157. package/dist/web/assets/index-DRo5Y_9p.js +1 -0
  158. package/dist/web/assets/index-De_LkTZx.js +1 -0
  159. package/dist/web/assets/{index-CZX3qUe2.js → index-DfUpwUTM.js} +2 -2
  160. package/dist/web/assets/{index-BLU8_Um7.js → index-Dkbz748K.js} +2 -2
  161. package/dist/web/assets/index-DmwFFSkV.js +1 -0
  162. package/dist/web/assets/index-DpcWEDhW.js +1 -0
  163. package/dist/web/assets/index-Dqq1RDP4.js +1 -0
  164. package/dist/web/assets/index-H1uMvIoa.css +1 -0
  165. package/dist/web/assets/index-ICHWJ2SM.js +1 -0
  166. package/dist/web/assets/index-O5fSd569.js +229 -0
  167. package/dist/web/assets/index-odjtqLLS.js +1 -0
  168. package/dist/web/assets/index-v_yAQ0Am.js +1 -0
  169. package/dist/web/assets/{infoDiagram-5YYISTIA-CD4XJGFm.js → infoDiagram-5YYISTIA-CCwV4Z0v.js} +1 -1
  170. package/dist/web/assets/{ishikawaDiagram-YF4QCWOH-fu5E3_CT.js → ishikawaDiagram-YF4QCWOH-BwwZcGyZ.js} +1 -1
  171. package/dist/web/assets/{journeyDiagram-JHISSGLW-CXcnKBfJ.js → journeyDiagram-JHISSGLW-Dc6WqniQ.js} +1 -1
  172. package/dist/web/assets/{kanban-definition-UN3LZRKU-BawKH6Pl.js → kanban-definition-UN3LZRKU-DVUqULOS.js} +1 -1
  173. package/dist/web/assets/{linear-BplJuXph.js → linear-d6rWsNOU.js} +1 -1
  174. package/dist/web/assets/memoryAdvisor-DBQXJB1o.js +1 -0
  175. package/dist/web/assets/mermaid-GHXKKRXX-Ik6SkVDT.js +642 -0
  176. package/dist/web/assets/{mindmap-definition-RKZ34NQL-DA1SE2uy.js → mindmap-definition-RKZ34NQL-_JHAkhHL.js} +1 -1
  177. package/dist/web/assets/navViewState-DaCMIYWA.js +1 -0
  178. package/dist/web/assets/{pieDiagram-4H26LBE5-6i021QeX.js → pieDiagram-4H26LBE5-BlhlygGy.js} +1 -1
  179. package/dist/web/assets/{quadrantDiagram-W4KKPZXB-CcKSZDMT.js → quadrantDiagram-W4KKPZXB-jn6R_C0S.js} +1 -1
  180. package/dist/web/assets/{requirementDiagram-4Y6WPE33-lYVuWRuD.js → requirementDiagram-4Y6WPE33-B9fXCHBr.js} +1 -1
  181. package/dist/web/assets/{sankeyDiagram-5OEKKPKP-4Zfb4_h4.js → sankeyDiagram-5OEKKPKP-fPJwIxkl.js} +1 -1
  182. package/dist/web/assets/{sequenceDiagram-3UESZ5HK-DqltKmlY.js → sequenceDiagram-3UESZ5HK-1v1DTNGt.js} +1 -1
  183. package/dist/web/assets/{spaces-CjuXbmxF.js → spaces-CvL2DRZM.js} +1 -1
  184. package/dist/web/assets/{stateDiagram-AJRCARHV-HFdhqxzx.js → stateDiagram-AJRCARHV-CEc_PLov.js} +1 -1
  185. package/dist/web/assets/stateDiagram-v2-BHNVJYJU-iAMctzaT.js +1 -0
  186. package/dist/web/assets/theme-LRSmy8mD.js +1 -0
  187. package/dist/web/assets/{timeline-definition-PNZ67QCA-HNRxaB3t.js → timeline-definition-PNZ67QCA-CEjhuitj.js} +1 -1
  188. package/dist/web/assets/{vennDiagram-CIIHVFJN-DwsCTyaD.js → vennDiagram-CIIHVFJN-CActt9h9.js} +1 -1
  189. package/dist/web/assets/{wardley-L42UT6IY-BWW2wtVO.js → wardley-L42UT6IY-Bp3q2izt.js} +1 -1
  190. package/dist/web/assets/{wardleyDiagram-YWT4CUSO-C-ktKm7v.js → wardleyDiagram-YWT4CUSO-C_zutiQ2.js} +1 -1
  191. package/dist/web/assets/{xychartDiagram-2RQKCTM6-48AxNW9k.js → xychartDiagram-2RQKCTM6-CRafvv33.js} +1 -1
  192. package/dist/web/icons/apple-touch-icon.png +0 -0
  193. package/dist/web/icons/icon-192.png +0 -0
  194. package/dist/web/icons/icon-512.png +0 -0
  195. package/dist/web/icons/maskable-512.png +0 -0
  196. package/dist/web/index.html +12 -2
  197. package/dist/web/manifest.webmanifest +16 -0
  198. package/native/auth-native/prebuilds/linux-arm64/auth-native.node +0 -0
  199. package/native/auth-native/prebuilds/linux-x64/auth-native.node +0 -0
  200. package/native/auth-native/prebuilds/win32-arm64/auth-native.node +0 -0
  201. package/native/auth-native/prebuilds/win32-x64/auth-native.node +0 -0
  202. package/package.json +23 -4
  203. package/dist/search-worker.mjs +0 -14177
  204. package/dist/web/assets/AppErrorBoundary-DiGMUg4r.js +0 -1
  205. package/dist/web/assets/LifeMark-CL6-HWDu.js +0 -1
  206. package/dist/web/assets/NavScopeBoundary-CFCnvZR0.js +0 -1
  207. package/dist/web/assets/channel-Bj_gZ_Lv.js +0 -1
  208. package/dist/web/assets/classDiagram-4FO5ZUOK-ssCwe2R4.js +0 -1
  209. package/dist/web/assets/classDiagram-v2-Q7XG4LA2-ssCwe2R4.js +0 -1
  210. package/dist/web/assets/client-DGj93bGT.js +0 -3
  211. package/dist/web/assets/connection-Bpf-EjrL.js +0 -1
  212. package/dist/web/assets/export-T_izwEkQ.js +0 -2
  213. package/dist/web/assets/highlighted-body-OFNGDK62-Btm6MuZ4.js +0 -1
  214. package/dist/web/assets/index-5_yzg61S.js +0 -1
  215. package/dist/web/assets/index-B-6LiYTY.js +0 -1
  216. package/dist/web/assets/index-B4iu4SJW.js +0 -1
  217. package/dist/web/assets/index-B9MlqF7J.js +0 -1
  218. package/dist/web/assets/index-BECSk4If.js +0 -1
  219. package/dist/web/assets/index-BFcyN2Zw.js +0 -1
  220. package/dist/web/assets/index-BIebkSEI.css +0 -1
  221. package/dist/web/assets/index-BMWid2q9.js +0 -1
  222. package/dist/web/assets/index-BeMvPEXs.js +0 -1
  223. package/dist/web/assets/index-Bezli3SF.js +0 -1
  224. package/dist/web/assets/index-BkPV0psm.js +0 -1
  225. package/dist/web/assets/index-CG8uIlD7.js +0 -1
  226. package/dist/web/assets/index-CJ92kLtO.js +0 -1
  227. package/dist/web/assets/index-CRDDqofN.js +0 -1
  228. package/dist/web/assets/index-Cd62y0wD.js +0 -1
  229. package/dist/web/assets/index-CgcJPsK6.js +0 -3
  230. package/dist/web/assets/index-Cy8C_eFR.js +0 -7
  231. package/dist/web/assets/index-D8z7lcQn.js +0 -166
  232. package/dist/web/assets/index-D_oPSlBL.js +0 -1
  233. package/dist/web/assets/index-Dceu0bqY.js +0 -1
  234. package/dist/web/assets/index-eUyF-8Sq.js +0 -1
  235. package/dist/web/assets/index-hG2s2Spn.js +0 -13
  236. package/dist/web/assets/mermaid-GHXKKRXX-BO9hkP3Z.js +0 -621
  237. package/dist/web/assets/stateDiagram-v2-BHNVJYJU-Dx28QuZF.js +0 -1
  238. package/dist/web/assets/theme-beWE_6f8.js +0 -1
@@ -0,0 +1,268 @@
1
+ # Tools from scripts
2
+
3
+ Call Kiki's shared tools from Python, Node.js, a shell, or another local program without MCP or an AI conversation. Calls use the providers and credentials already configured in Kiki; scripts receive a connection credential, not provider API keys.
4
+
5
+ ## Prepare a connection
6
+
7
+ In **Settings → Connection & remote → Access from elsewhere → External clients**, create a connection and allow the tools you need. Create a conversation for that connection in Kiki and choose its workspace and permission mode. Plugin tools must also be installed, configured and enabled for that conversation. The connection's permission ceiling, tool allowlist, workspace boundaries and normal approvals still apply. Media tools that declare unrestricted access also require the connection's local-command access permission.
8
+
9
+ In the connection's **Pick tools** list, enabled plugin tools appear grouped by plugin. Select `plugin__kiki_media__generate` and `plugin__kiki_media__media`, and enable **Allow commands on this machine** for their unrestricted access. Saving is blocked until you enable that permission or deselect those tools. Enabling it, in the GUI or with `--allow-commands`, also grants `Bash`, allowing the client to run shell commands as you. The local owner can also add these grants from the terminal; existing grants are retained, and changing a grant stops the connection's running work:
10
+
11
+ ```sh
12
+ kiki tools --client CONNECTION_ID grant plugin__kiki_media__generate plugin__kiki_media__media --allow-commands
13
+ ```
14
+
15
+ Find and resume the shared conversation, replacing `CONNECTION_ID` and `SESSION_REF`:
16
+
17
+ ```sh
18
+ kiki tools --client CONNECTION_ID call kiki_session --args '{"action":"list"}'
19
+ kiki tools --client CONNECTION_ID call kiki_session --args '{"action":"resume","session_ref":"SESSION_REF"}'
20
+ kiki tools --client CONNECTION_ID list
21
+ ```
22
+
23
+ `--client` uses the local owner's existing connection configuration to mint a one-hour connection credential without printing it. Add `--home /path/to/kiki-home` when the connection belongs to another home. Discovery does not create a conversation. See [external-client setup](./mcp.md#let-an-external-client-use-kiki-tools) for connection and session controls.
24
+
25
+ For Python, Node.js or another HTTP client, export a connection credential as the local owner:
26
+
27
+ ```sh
28
+ kiki tools --client CONNECTION_ID credential --output /private/connection-token
29
+ ```
30
+
31
+ The command creates a new private file and refuses to overwrite it. Its JSON output contains the file path and server URL, never the credential. Set `KIKI_EXTERNAL_CLIENT_CREDENTIAL_FILE` to that path and `KIKI_SERVER_URL` to the returned `server_url`. Tool routes accept only this connection bearer credential, from a loopback address; the server's owner token is not accepted.
32
+
33
+ Credentials expire after one hour. On HTTP 401, run `credential` again with a new output path, update the environment variable and restart the script with the same submission keys. For longer CLI workflows, use `--client` to obtain a current credential automatically. Pausing or revoking a connection stops access immediately.
34
+
35
+ The Python and Node.js examples read these environment variables:
36
+
37
+ | Variable | Value |
38
+ | --- | --- |
39
+ | `KIKI_SERVER_URL` | The running server's loopback URL, for example `http://127.0.0.1:58627` |
40
+ | `KIKI_EXTERNAL_CLIENT_CREDENTIAL_FILE` | Private UTF-8 file containing the connection credential |
41
+ | `KIKI_SESSION_REF` | Reference returned by `kiki_session list` or `resume` |
42
+ | `KIKI_MEDIA_PROVIDER` | A configured provider ID, for example `kiki-media/openai-image` |
43
+
44
+ ## Generate and download an image
45
+
46
+ These examples submit one background image job, query it until completion, and save its first artifact as `image.png`. Change the provider and request to match your configured source. Running an example can incur provider charges.
47
+
48
+ Keep both `idempotency_key` and media `request_id` stable for the same submission. Reusing the operation key returns the original receipt; changing the arguments with that key is rejected. Each status query below has a new key so it reads a fresh media snapshot. An `operation_id` identifies a Kiki tool call; `job_id` identifies the longer-running media generation. A completed tool call may contain a media job that is still `running` or `pending`.
49
+
50
+ ### Shell with the CLI
51
+
52
+ This POSIX shell example needs `jq`. On Windows, use the Python example or Git Bash with `jq` installed. The CLI handles credential minting and downloads; every command writes JSON to stdout and returns a nonzero exit code for a request or tool error.
53
+
54
+ ```sh
55
+ set -eu
56
+ CLIENT=CONNECTION_ID
57
+ SESSION=SESSION_REF
58
+ PROVIDER=kiki-media/openai-image
59
+
60
+ tools() { kiki tools --client "$CLIENT" "$@"; }
61
+ wait_operation() {
62
+ id=$1
63
+ attempts=0
64
+ while [ "$attempts" -lt 120 ]; do
65
+ receipt=$(tools job get "$id")
66
+ state=$(printf '%s' "$receipt" | jq -r '.structuredContent.state')
67
+ case "$state" in
68
+ completed) printf '%s\n' "$receipt"; return ;;
69
+ accepted|running|waiting_approval) sleep 1 ;;
70
+ *) printf '%s\n' "$receipt" >&2; return 1 ;;
71
+ esac
72
+ attempts=$((attempts + 1))
73
+ done
74
+ echo "Still running; query operation $id again, do not resubmit." >&2
75
+ return 1
76
+ }
77
+ args=$(jq -nc --arg provider "$PROVIDER" '{request_id:"example-image-001",provider:$provider,execution:"background",request:{kind:"image",prompt:"A simple blue square",count:1}}')
78
+ receipt=$(tools call plugin__kiki_media__generate --session-ref "$SESSION" --key example-image-001 --args "$args")
79
+ receipt=$(wait_operation "$(printf '%s' "$receipt" | jq -r '.structuredContent.operation_id')")
80
+ job=$(printf '%s' "$receipt" | jq -r '.structuredContent.result.output | fromjson | .job.job_id')
81
+ count=0
82
+ while [ "$count" -lt 120 ]; do
83
+ args=$(jq -nc --arg job "$job" '{action:"get",job_id:$job}')
84
+ receipt=$(tools call plugin__kiki_media__media --session-ref "$SESSION" --key "status-$$-$count" --args "$args")
85
+ op=$(printf '%s' "$receipt" | jq -r '.structuredContent.operation_id')
86
+ receipt=$(wait_operation "$op")
87
+ state=$(printf '%s' "$receipt" | jq -r '.structuredContent.result.output | fromjson | .job.state')
88
+ case "$state" in
89
+ succeeded) tools job download "$op" --artifact 0 --output image.png; exit 0 ;;
90
+ running|pending) sleep 2 ;;
91
+ *) printf '%s\n' "$receipt" >&2; exit 1 ;;
92
+ esac
93
+ count=$((count + 1))
94
+ done
95
+ printf 'Media job %s is still pending; query it again without generating a new job.\n' "$job" >&2
96
+ exit 1
97
+ ```
98
+
99
+ For a pre-provisioned credential, replace `--client "$CLIENT"` with `--url "$KIKI_SERVER_URL" --credential-file /private/connection-token`. The CLI also accepts `KIKI_EXTERNAL_CLIENT_TOKEN` when no credential file is supplied. `job download` refuses to replace an existing file and removes an incomplete new output after a failed download.
100
+
101
+ ### Python over HTTP
102
+
103
+ Save as `generate.py` and run `python generate.py`. It uses only the Python standard library.
104
+
105
+ ```python
106
+ import base64
107
+ import json
108
+ import os
109
+ from pathlib import Path
110
+ import time
111
+ import urllib.parse
112
+ import urllib.request
113
+ import uuid
114
+
115
+ base = os.environ["KIKI_SERVER_URL"].rstrip("/")
116
+ assert urllib.parse.urlparse(base).hostname in ("localhost", "127.0.0.1", "::1")
117
+ token = Path(os.environ["KIKI_EXTERNAL_CLIENT_CREDENTIAL_FILE"]).read_text().strip()
118
+ session = os.environ["KIKI_SESSION_REF"]
119
+
120
+ def api(path, body=None):
121
+ data = None if body is None else json.dumps(body).encode()
122
+ request = urllib.request.Request(base + "/api/external-clients" + path, data=data,
123
+ headers={"Authorization": "Bearer " + token, "Content-Type": "application/json"})
124
+ with urllib.request.urlopen(request, timeout=30) as response:
125
+ result = json.load(response)
126
+ if result["code"] != 0:
127
+ raise RuntimeError(result["msg"])
128
+ return result["data"]
129
+
130
+ def tool(name, arguments, key):
131
+ result = api("/tools/" + name + ":call", {"arguments": arguments,
132
+ "session_ref": session, "idempotency_key": key})["structuredContent"]
133
+ deadline = time.monotonic() + 120
134
+ while result["state"] in ("accepted", "running", "waiting_approval") and time.monotonic() < deadline:
135
+ time.sleep(1)
136
+ result = api("/jobs/" + result["operation_id"])["structuredContent"]
137
+ if result["state"] != "completed" or result.get("result", {}).get("isError"):
138
+ raise RuntimeError(json.dumps(result))
139
+ return result
140
+
141
+ receipt = tool("plugin__kiki_media__generate", {
142
+ "request_id": "example-image-001", "provider": os.environ["KIKI_MEDIA_PROVIDER"],
143
+ "execution": "background", "request": {"kind": "image", "prompt": "A simple blue square", "count": 1}
144
+ }, "example-image-001")
145
+ job = json.loads(receipt["result"]["output"])["job"]
146
+ deadline = time.monotonic() + 240
147
+ while job["state"] in ("running", "pending") and time.monotonic() < deadline:
148
+ time.sleep(2)
149
+ receipt = tool("plugin__kiki_media__media", {"action": "get", "job_id": job["job_id"]}, str(uuid.uuid4()))
150
+ job = json.loads(receipt["result"]["output"])["job"]
151
+ if job["state"] != "succeeded":
152
+ raise RuntimeError(json.dumps(job))
153
+ output = Path("image.png")
154
+ with output.open("xb") as file:
155
+ try:
156
+ offset = 0
157
+ while True:
158
+ page = api(f'/jobs/{receipt["operation_id"]}/result?artifact=0&offset={offset}&limit=256000')
159
+ resource = next(part["resource"] for part in page["content"] if part["type"] == "resource")
160
+ file.write(base64.b64decode(resource["blob"]))
161
+ if page["structuredContent"]["complete"]:
162
+ break
163
+ offset = page["structuredContent"]["range"]["end"]
164
+ except Exception:
165
+ file.close()
166
+ output.unlink()
167
+ raise
168
+ print(json.dumps({"job_id": job["job_id"], "output": str(output)}))
169
+ ```
170
+
171
+ ### Node.js over HTTP
172
+
173
+ Save as `generate.mjs` and run `node generate.mjs` with a current Node.js release.
174
+
175
+ ```js
176
+ import { readFile, open, rm } from 'node:fs/promises';
177
+ import { randomUUID } from 'node:crypto';
178
+ import { setTimeout as delay } from 'node:timers/promises';
179
+
180
+ const base = process.env.KIKI_SERVER_URL.replace(/\/$/, '');
181
+ if (!['localhost', '127.0.0.1', '[::1]'].includes(new URL(base).hostname)) throw new Error('Use a loopback URL');
182
+ const token = (await readFile(process.env.KIKI_EXTERNAL_CLIENT_CREDENTIAL_FILE, 'utf8')).trim();
183
+ const session = process.env.KIKI_SESSION_REF;
184
+ async function api(path, body) {
185
+ const response = await fetch(`${base}/api/external-clients${path}`, {
186
+ method: body === undefined ? 'GET' : 'POST',
187
+ headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json' },
188
+ body: body === undefined ? undefined : JSON.stringify(body), signal: AbortSignal.timeout(30_000),
189
+ });
190
+ const result = await response.json();
191
+ if (!response.ok || result.code !== 0) throw new Error(result.msg ?? `HTTP ${response.status}`);
192
+ return result.data;
193
+ }
194
+ async function tool(name, args, key) {
195
+ let result = (await api(`/tools/${name}:call`, { arguments: args, session_ref: session, idempotency_key: key })).structuredContent;
196
+ const deadline = Date.now() + 120_000;
197
+ while (['accepted', 'running', 'waiting_approval'].includes(result.state) && Date.now() < deadline) {
198
+ await delay(1000);
199
+ result = (await api(`/jobs/${result.operation_id}`)).structuredContent;
200
+ }
201
+ if (result.state !== 'completed' || result.result?.isError) throw new Error(JSON.stringify(result));
202
+ return result;
203
+ }
204
+ let receipt = await tool('plugin__kiki_media__generate', {
205
+ request_id: 'example-image-001', provider: process.env.KIKI_MEDIA_PROVIDER, execution: 'background',
206
+ request: { kind: 'image', prompt: 'A simple blue square', count: 1 },
207
+ }, 'example-image-001');
208
+ let job = JSON.parse(receipt.result.output).job;
209
+ const deadline = Date.now() + 240_000;
210
+ while (['running', 'pending'].includes(job.state) && Date.now() < deadline) {
211
+ await delay(2000);
212
+ receipt = await tool('plugin__kiki_media__media', { action: 'get', job_id: job.job_id }, randomUUID());
213
+ job = JSON.parse(receipt.result.output).job;
214
+ }
215
+ if (job.state !== 'succeeded') throw new Error(JSON.stringify(job));
216
+ const output = 'image.png';
217
+ const file = await open(output, 'wx');
218
+ let complete = false;
219
+ try {
220
+ let offset = 0;
221
+ while (true) {
222
+ const page = await api(`/jobs/${receipt.operation_id}/result?artifact=0&offset=${offset}&limit=256000`);
223
+ const resource = page.content.find(part => part.type === 'resource').resource;
224
+ await file.writeFile(Buffer.from(resource.blob, 'base64'));
225
+ if (page.structuredContent.complete) { complete = true; break; }
226
+ offset = page.structuredContent.range.end;
227
+ }
228
+ } finally {
229
+ await file.close();
230
+ if (!complete) await rm(output);
231
+ }
232
+ console.log(JSON.stringify({ job_id: job.job_id, output }));
233
+ ```
234
+
235
+ ## Query and recover accepted work
236
+
237
+ If a request times out after submission may have started, reuse its original key and arguments to recover the receipt. Never automatically submit with a new key. When an operation is `outcome_unknown`, or a media job is `unknown`, inspect the provider's accepted work before deciding what to do; another generation may incur another charge.
238
+
239
+ With the `manual` permission ceiling, keep the shared conversation open in Kiki so its GUI can receive approval requests. Without an approval consumer, a call that needs approval is immediately rejected with `no_consumer`; it does not wait for a window to open. For unattended batches, set an `auto` or `yolo` ceiling and a matching conversation mode only after reviewing the allowed tools and their access. `auto` can still ask for risky actions; `yolo` removes those normal approval prompts within the existing grant.
240
+
241
+ `waiting_approval` means a connected Kiki window is waiting for your decision. Approve or reject there, then query the same operation. The examples keep polling this state until their deadline. Scripts cannot elevate the connection's permission ceiling.
242
+
243
+ For an accepted media job with `can_resume: true`, explicitly resume the same job rather than calling `generate` again:
244
+
245
+ ```sh
246
+ kiki tools --client CONNECTION_ID call plugin__kiki_media__media \
247
+ --session-ref SESSION_REF --key resume-example-001 \
248
+ --args '{"action":"resume","job_id":"MEDIA_JOB_ID"}'
249
+ ```
250
+
251
+ Resume only continues the saved handle or staged download; it does not buy a new generation. Query with `media` action `get` until an acceptable result is saved. For `partial`, inspect artifact `complete`, `role` and error fields before downloading the artifacts you want. `job download --artifact N` targets a **tool operation whose saved result contains those artifacts**, normally the latest successful `media get`, not the original pending generation receipt.
252
+
253
+ ## HTTP and client reference
254
+
255
+ All four routes use the usual `{ code, msg, data, request_id }` envelope. A nonzero business `code` can arrive with HTTP 200. Tool data uses `{ content, structuredContent, isError? }`, matching the existing MCP result shape.
256
+
257
+ | Method and path | Input or result |
258
+ | --- | --- |
259
+ | `GET /api/external-clients/tools` | `{ tools: [{ name, description, inputSchema, annotations }] }` for this grant |
260
+ | `POST /api/external-clients/tools/{name}:call` | `{ arguments, session_ref?, idempotency_key? }`; returns a control result or operation receipt |
261
+ | `GET /api/external-clients/jobs/{operation_id}` | Saved operation receipt; never resubmits |
262
+ | `GET /api/external-clients/jobs/{operation_id}/result` | Saved result page, with optional `part`, `artifact`, `offset`, `limit` query fields |
263
+
264
+ For HTTP calls, put bridge fields at the top level, not inside `arguments._kiki`. Side effects require a key of 1–256 characters. `kiki_session` and `kiki_operation` retain their control arguments; for example, cancellation uses `kiki_operation` with `{"operation_id":"OPERATION_ID","action":"cancel"}`.
265
+
266
+ Without a selector, result pages contain the saved JSON tool result. `part=N` selects a native output-array part; `artifact=N` selects a generated media artifact. Choose only one selector. Limits are 1–256000 (default 12000); text offsets count UTF-16 code units, while media offsets count bytes. Binary chunks are base64 in an embedded resource's `blob`. Follow `structuredContent.range.end` until `complete: true`. Downloads use saved session-owned bytes, not current provider URLs or arbitrary host paths.
267
+
268
+ The HTTP client SDK exposes the same operations under `klient.rest.externalClients`: `tools(options?)`, `callTool(name, body, options?)`, `job(id, options?)`, and `result(id, range?, options?)`. Create the HTTP client with the connection credential; its owner-management methods remain unavailable to that credential.