@intentcomputing/koko-agent-sdk 1.1.0 → 1.1.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.
- package/CHANGELOG.md +5 -0
- package/README.md +2 -2
- package/README.zh-CN.md +3 -1
- package/docs/BACKEND_AUTH_DEMOS.md +4 -0
- package/docs/BACKEND_AUTH_DEMOS.zh-CN.md +4 -0
- package/docs/CONFIGURATION.md +188 -0
- package/docs/CONFIGURATION.zh-CN.md +195 -0
- package/docs/INTEGRATION.md +3 -1
- package/docs/INTEGRATION.zh-CN.md +3 -1
- package/package.json +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.1
|
|
4
|
+
|
|
5
|
+
- Add complete English and Chinese configuration references covering Provider, Agent, gateway, branding, runtime appearance, per-run overrides, and built-in UI options.
|
|
6
|
+
- Clarify that short-lived access tokens stay in memory and refresh lazily on requests near expiry.
|
|
7
|
+
|
|
3
8
|
## 1.1.0
|
|
4
9
|
|
|
5
10
|
- Add production `tokenProvider` authentication with expiry-aware caching and one forced refresh after a 401.
|
package/README.md
CHANGED
|
@@ -47,9 +47,9 @@ export default function App() {
|
|
|
47
47
|
}
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
The default gateway is `https://sdk.intentcomputing.net` (OpenAI). For China, set `gateway.baseUrl` to `https://sdk.intentcomputing.cn` (DeepSeek). The SDK caches short-lived tokens, refreshes
|
|
50
|
+
The default gateway is `https://sdk.intentcomputing.net` (OpenAI). For China, set `gateway.baseUrl` to `https://sdk.intentcomputing.cn` (DeepSeek). The SDK caches short-lived tokens in memory, refreshes lazily when a request occurs near expiry, and retries once after a 401. Long-lived client secrets and model-provider keys must never be bundled into the app. See the [backend authentication demos](docs/BACKEND_AUTH_DEMOS.md) for Node.js, Java, Go, Python, PHP and C#.
|
|
51
51
|
|
|
52
|
-
Call `setKokoAppearance({ locale, theme })` when host preferences change. Configure branding through `config.branding`; custom branding is subject to the app's entitlement. See the [integration guide](docs/INTEGRATION.md) for host actions, privacy gates, and lifecycle details.
|
|
52
|
+
Call `setKokoAppearance({ locale, theme })` when host preferences change. Configure branding through `config.branding`; custom branding is subject to the app's entitlement. See the [complete configuration reference](docs/CONFIGURATION.md) for every Provider, Agent, gateway, runtime, and per-run option, and the [integration guide](docs/INTEGRATION.md) for host actions, privacy gates, and lifecycle details.
|
|
53
53
|
|
|
54
54
|
## Privacy and limits
|
|
55
55
|
|
package/README.zh-CN.md
CHANGED
|
@@ -48,7 +48,9 @@ export default function App() {
|
|
|
48
48
|
}
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
默认网关为海外的 `https://sdk.intentcomputing.net`(OpenAI);国内请显式选择 `https://sdk.intentcomputing.cn`(DeepSeek)。SDK
|
|
51
|
+
默认网关为海外的 `https://sdk.intentcomputing.net`(OpenAI);国内请显式选择 `https://sdk.intentcomputing.cn`(DeepSeek)。SDK 仅在内存缓存短期 token;当一次请求发生且 token 临近过期时才按需刷新,401 后强制刷新并重试一次。长期 `clientSecret` 和模型 API 密钥都不得进入 App。完整三端流程及 Node.js、Java、Go、Python、PHP、C# Demo 见[后端鉴权 Demo](docs/BACKEND_AUTH_DEMOS.zh-CN.md)。
|
|
52
|
+
|
|
53
|
+
Provider、Agent、网关、品牌、运行时和单次任务的全部选项见 [SDK 完整配置参考](docs/CONFIGURATION.zh-CN.md)。
|
|
52
54
|
|
|
53
55
|
宿主必须在展示密码、私钥、助记词及其验证页面前设置隐私标记和用户操作门禁,由用户亲自完成敏感步骤。脱敏的页面信息和任务上下文会发送到所选网关进行规划,接入方应使用虚构数据验证隐私边界。详见[隐私说明](docs/PRIVACY.zh-CN.md)。
|
|
54
56
|
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Production authentication uses three parties: the mobile app authenticates to its existing host backend; the host backend exchanges its server-only `clientId` and `clientSecret` with Koko; the app receives a 5–15 minute access token for the SDK.
|
|
4
4
|
|
|
5
|
+
Each `clientId` may optionally be restricted to exact host-backend egress IPs. Multiple IPv4/IPv6 addresses are comma-separated; omitting the allowlist leaves IP unrestricted. This is defense in depth and does not replace the client secret.
|
|
6
|
+
|
|
7
|
+
Creating an app in the Intent Computing console now issues the `clientId` and one-time `clientSecret`. The Apps / Server credentials page manages IPs, status, and secret rotation; admins can also manage regions and review the audit trail. Only a secret hash is stored. Legacy API keys remain migration-only.
|
|
8
|
+
|
|
5
9
|
```text
|
|
6
10
|
Host app --host session--> Host backend --client secret--> Koko /v1/sdk/token
|
|
7
11
|
Host app <--short token--- Host backend <--short token---- Koko
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
生产环境采用三端通信:宿主 App 通过自己的登录态请求宿主后端;宿主后端使用仅存于服务器的 `clientId` / `clientSecret` 向 Koko 换取 5~15 分钟的 access token;App 再把短期 token 交给 SDK。
|
|
4
4
|
|
|
5
|
+
Koko 可为每个 `clientId` 选配宿主后端出口 IP 白名单。多个精确 IPv4/IPv6 地址用逗号分隔;不配置时不限制。启用后,请把宿主后端所有稳定 NAT 出口地址提供给 Intent Computing。IP 白名单是 `clientSecret` 之外的附加约束,不能替代密钥认证。
|
|
6
|
+
|
|
7
|
+
在 Intent Computing 用户后台创建应用时,会自动生成 `clientId` / `clientSecret`。完整 Secret 仅显示一次;之后可在“应用 / 服务端凭证”中维护 IP、启停或轮换 Secret。管理员后台可调整状态、授权区域和 IP,并查看操作审计。Secret 只保存哈希,旧 API Key 仅用于迁移兼容。
|
|
8
|
+
|
|
5
9
|
```text
|
|
6
10
|
宿主 App ──宿主登录态──> 宿主后端 ──clientSecret──> Koko /v1/sdk/token
|
|
7
11
|
宿主 App <──短期 token── 宿主后端 <──短期 token── Koko
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# Complete SDK configuration reference
|
|
2
|
+
|
|
3
|
+
> 中文版:[CONFIGURATION.zh-CN.md](./CONFIGURATION.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
This reference covers the public host configuration surfaces: `KokoProvider`, `KokoAgentConfig`, runtime appearance, per-run overrides, and built-in UI components. The exported TypeScript types remain the source of truth.
|
|
6
|
+
|
|
7
|
+
## Complete example
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import React from 'react';
|
|
11
|
+
import { KokoProvider } from '@intentcomputing/koko-agent-sdk';
|
|
12
|
+
|
|
13
|
+
export function App() {
|
|
14
|
+
const tokenProvider = React.useCallback(async () => {
|
|
15
|
+
const response = await hostApi.get('/koko/access-token');
|
|
16
|
+
return response.data as { accessToken: string; expiresAt: number };
|
|
17
|
+
}, []);
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<KokoProvider
|
|
21
|
+
cursor
|
|
22
|
+
observer
|
|
23
|
+
dialogs
|
|
24
|
+
resumeAfterReload
|
|
25
|
+
config={{
|
|
26
|
+
gateway: {
|
|
27
|
+
baseUrl: 'https://sdk.intentcomputing.net',
|
|
28
|
+
tokenProvider,
|
|
29
|
+
// appId normally comes from the native Bundle ID / Package Name.
|
|
30
|
+
},
|
|
31
|
+
locale: 'en',
|
|
32
|
+
theme: 'light', // The host theme; Koko chrome uses the contrasting theme.
|
|
33
|
+
branding: {
|
|
34
|
+
name: 'My Assistant',
|
|
35
|
+
tagline: 'Control this app with natural language',
|
|
36
|
+
placeholder: 'Tell me what you want to do…',
|
|
37
|
+
primaryColor: '#6D4AFF',
|
|
38
|
+
icon: require('./assistant.png'),
|
|
39
|
+
},
|
|
40
|
+
confirmation: { requireUserConfirm: true, mode: 'preflight' },
|
|
41
|
+
webWalletAliases: ['My Wallet'],
|
|
42
|
+
dumpMaxDepth: 80,
|
|
43
|
+
dumpSkipInvisible: true,
|
|
44
|
+
cursorDurationMs: 480,
|
|
45
|
+
observer: true,
|
|
46
|
+
debug: false,
|
|
47
|
+
onUsageEvent: event => analytics.track('koko_usage', event),
|
|
48
|
+
}}
|
|
49
|
+
>
|
|
50
|
+
<HostNavigation />
|
|
51
|
+
</KokoProvider>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## `KokoProvider` props
|
|
57
|
+
|
|
58
|
+
| Option | Type | Default | Purpose |
|
|
59
|
+
|---|---|---:|---|
|
|
60
|
+
| `children` | `ReactNode` | Required | Host app or outer navigation tree. |
|
|
61
|
+
| `config` | `KokoAgentConfig` | `{}` | Agent, gateway, branding, and confirmation configuration. |
|
|
62
|
+
| `cursor` | `boolean` | `true` | Show the observable action cursor. |
|
|
63
|
+
| `observer` | `boolean` | Inherits `config.observer` | Mount progress and chat UI; an explicit prop wins. |
|
|
64
|
+
| `dialogs` | `boolean` | `true` | Mount built-in confirm and ask-user dialogs. Provide host callbacks if disabled. |
|
|
65
|
+
| `resumeAfterReload` | `boolean` | `true` | Resume one recent goal after a JS-context reload caused by host locale/theme changes. |
|
|
66
|
+
| `remoteSmokePort` | `number` | `0` | Local development smoke-driver port. Never enable in production. |
|
|
67
|
+
| `composerPlaceholder` | `string` | — | Deprecated; use `config.branding.placeholder`. |
|
|
68
|
+
|
|
69
|
+
`KokoProvider observer={false}` hides built-in progress/chat UI only. `config.observer={false}` also disables automatic task logging. Keep both enabled for the complete built-in experience.
|
|
70
|
+
|
|
71
|
+
## `KokoAgentConfig`
|
|
72
|
+
|
|
73
|
+
| Option | Type | Default | Purpose |
|
|
74
|
+
|---|---|---:|---|
|
|
75
|
+
| `gateway` | `GatewayConfig` | — | Gateway and short-token configuration required for production runs. |
|
|
76
|
+
| `locale` | `'zh' \| 'en'` | `'en'` | Initial built-in UI language. Prefer `setKokoAppearance` for runtime changes. |
|
|
77
|
+
| `theme` | `'light' \| 'dark'` | `'light'` | The **host app's** current theme; Koko chrome uses the opposite theme for contrast. |
|
|
78
|
+
| `branding` | `KokoBrandingConfig` | Koko defaults | Custom name, icon, copy, and accent; requires the `custom_branding` entitlement. |
|
|
79
|
+
| `confirmation` | `ConfirmationPolicy` | Confirm, `preflight` | Human confirmation policy for high-risk goals. |
|
|
80
|
+
| `onConfirmSensitive` | `(ctx) => Promise<boolean>` | Built-in dialog | Custom sensitive-action confirmation. Return `true` to proceed. |
|
|
81
|
+
| `webWalletAliases` | `string[]` | `[]` | Verified public labels for the host's own injected wallet. |
|
|
82
|
+
| `dumpMaxDepth` | `number` | `80` | Maximum native accessibility-tree depth. Small values can truncate RN navigation wrappers. |
|
|
83
|
+
| `dumpSkipInvisible` | `boolean` | `true` | Drop invisible nodes from observations. |
|
|
84
|
+
| `cursorDurationMs` | `number` | `480` | Default cursor animation duration in milliseconds. |
|
|
85
|
+
| `observer` | `boolean` | `true` | Enable task logs and, unless overridden by the Provider prop, built-in progress/chat UI. |
|
|
86
|
+
| `debug` | `boolean` | `true` in Metro Debug; `false` in Release | Capability and execution logs only; it never relaxes security. Set `false` explicitly in production. |
|
|
87
|
+
| `devMode` | `boolean` | Same as `debug` | Deprecated alias for `debug`. |
|
|
88
|
+
| `onUsageEvent` | `(event) => void` | — | Non-blocking local analytics/UX notifications; not authoritative for billing. |
|
|
89
|
+
|
|
90
|
+
### `gateway`
|
|
91
|
+
|
|
92
|
+
| Option | Type | Default | Purpose |
|
|
93
|
+
|---|---|---:|---|
|
|
94
|
+
| `baseUrl` | `string` | `https://sdk.intentcomputing.net` | Global/OpenAI gateway. Use `https://sdk.intentcomputing.cn` for China/DeepSeek. Release builds accept official hosts only. |
|
|
95
|
+
| `tokenProvider` | `() => Promise<string \| { accessToken; expiresAt? }>` | — | Recommended. Fetches a short token from the **host backend**. The SDK caches it in memory, refreshes lazily on a request near expiry, and refreshes/retries once after a 401. |
|
|
96
|
+
| `token` | `string` | — | Legacy static token for local development and migration only. Never ship it in production. |
|
|
97
|
+
| `appId` | `string` | Native Bundle ID / Package Name | Must match the registered host app; normally no explicit value is needed. |
|
|
98
|
+
|
|
99
|
+
`expiresAt` is Unix time in **milliseconds**. If omitted, the SDK reads JWT `exp`; if neither exists, it assumes 60 seconds. Never place `clientSecret` or DeepSeek/OpenAI keys in the app.
|
|
100
|
+
|
|
101
|
+
### `branding`
|
|
102
|
+
|
|
103
|
+
| Option | Type | Default | Purpose |
|
|
104
|
+
|---|---|---:|---|
|
|
105
|
+
| `name` | `string` | `Koko` | Assistant display name. |
|
|
106
|
+
| `icon` | `number \| { uri: string } \| string` | K mark | Accepts `require()`, an image/Data URI, or a short text mark. |
|
|
107
|
+
| `tagline` | `string` | Localized default | Chat header subtitle. |
|
|
108
|
+
| `placeholder` | `string` | Localized default | Composer placeholder. |
|
|
109
|
+
| `primaryColor` | `string` | SDK accent | Badge and send-button accent using a React Native color string. |
|
|
110
|
+
|
|
111
|
+
Without the entitlement, the SDK falls back to Koko defaults and emits one `branding_downgraded` usage event.
|
|
112
|
+
|
|
113
|
+
### `confirmation`
|
|
114
|
+
|
|
115
|
+
| Option | Type | Default | Purpose |
|
|
116
|
+
|---|---|---:|---|
|
|
117
|
+
| `requireUserConfirm` | `boolean` | `true` | Require confirmation for high-risk goals. |
|
|
118
|
+
| `mode` | `'preflight' \| 'inline' \| 'off'` | `'preflight'` | Confirm once before a run, use legacy inline checks, or disable SDK confirmation. |
|
|
119
|
+
| `sensitivePatterns` | `RegExp[]` | Built-in patterns | Custom high-risk goal rules. A non-empty array replaces the defaults. |
|
|
120
|
+
|
|
121
|
+
Disabling confirmation does not bypass local password, recovery-phrase, private-key, or OTP gates. The user must still complete those surfaces personally.
|
|
122
|
+
|
|
123
|
+
### `onUsageEvent` events
|
|
124
|
+
|
|
125
|
+
Events are `task_started`, `task_finished`, `agent_step`, `quota_exceeded`, `sheet_opened`, `sheet_closed`, and `branding_downgraded`. Do not forward goal text to an analytics provider without user authorization.
|
|
126
|
+
|
|
127
|
+
## Runtime locale and theme
|
|
128
|
+
|
|
129
|
+
```tsx
|
|
130
|
+
import { setKokoAppearance } from '@intentcomputing/koko-agent-sdk';
|
|
131
|
+
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
setKokoAppearance({ locale: hostLocale, theme: hostTheme });
|
|
134
|
+
}, [hostLocale, hostTheme]);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
- Locale strings beginning with `zh` map to Chinese; all others currently map to English.
|
|
138
|
+
- Theme is the host's actual `'light'` or `'dark'` theme.
|
|
139
|
+
- Runtime appearance takes precedence over static `config.locale` and `config.theme`.
|
|
140
|
+
|
|
141
|
+
`getKokoAgent().configure(patch)` updates configuration at runtime, but performs a shallow merge. Pass complete `gateway`, `branding`, or `confirmation` sub-objects when changing them. Prefer `setKokoAppearance` for locale/theme.
|
|
142
|
+
|
|
143
|
+
## Per-run overrides
|
|
144
|
+
|
|
145
|
+
```tsx
|
|
146
|
+
await getKokoAgent().runGoal('Open settings', {
|
|
147
|
+
locale: 'en-US',
|
|
148
|
+
localRetries: 3,
|
|
149
|
+
userGateTimeoutMs: 300_000,
|
|
150
|
+
onAskUser: question => showHostQuestion(question),
|
|
151
|
+
onNarration: text => setHint(text),
|
|
152
|
+
});
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
| Option | Default | Purpose |
|
|
156
|
+
|---|---:|---|
|
|
157
|
+
| `baseUrl` / `tokenProvider` / `token` / `appId` | Inherit `config.gateway` | Override the gateway for this run only. |
|
|
158
|
+
| `locale` | Effective current locale | Planner request locale for this run. |
|
|
159
|
+
| `localRetries` | `3` | Retry count `0–3` for read-only `dump/find` failures. Touches and typing are never automatically replayed. |
|
|
160
|
+
| `userGateTimeoutMs` | `300000` | Maximum wait for the user to finish a password/recovery/authorization gate. |
|
|
161
|
+
| `onAskUser` | Built-in ask dialog | Host callback when the agent needs more information. |
|
|
162
|
+
| `onNarration` | — | Receives current task narration. |
|
|
163
|
+
|
|
164
|
+
`resumedFromReload` and `resumes` are SDK-internal recovery fields; hosts should not set them.
|
|
165
|
+
|
|
166
|
+
## Built-in UI component props
|
|
167
|
+
|
|
168
|
+
| Component | Options |
|
|
169
|
+
|---|---|
|
|
170
|
+
| `KokoEntryButton` | `label` (default `Koko`) and `style`. Production hosts should normally draw their own entry and call `openKokoChat()`. |
|
|
171
|
+
| `KokoComposer` | `placeholder` and `disabled` (default `false`). |
|
|
172
|
+
| `KokoObserver` | `cursor` (default `true`) and deprecated `composerPlaceholder`. Normally mounted by the Provider. |
|
|
173
|
+
| `KokoOverlayLayer` | `style`, `pointerEvents` (default `box-none`), and `testID` for custom SDK chrome. |
|
|
174
|
+
|
|
175
|
+
## Low-level action options
|
|
176
|
+
|
|
177
|
+
Most hosts do not call these directly.
|
|
178
|
+
|
|
179
|
+
| Type | Options and defaults |
|
|
180
|
+
|---|---|
|
|
181
|
+
| `DumpOptions` | `maxDepth`, `skipInvisible`, `silent`; absent values inherit Agent configuration. |
|
|
182
|
+
| `TapOptions` | `revealIfNeeded`, `silent`, `cursorDurationMs`; the planner normally decides when to reveal an offscreen control. |
|
|
183
|
+
| `SwipeOptions` | `durationMs`, `silent`. |
|
|
184
|
+
| `PinchOptions` | `durationMs` (default `280`), `silent`. |
|
|
185
|
+
| `TypeOptions` | `clear`, `silent`. |
|
|
186
|
+
|
|
187
|
+
See [Privacy](PRIVACY.md) for data boundaries and [backend authentication demos](BACKEND_AUTH_DEMOS.md) for the three-party token flow.
|
|
188
|
+
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# SDK 完整配置参考
|
|
2
|
+
|
|
3
|
+
> English: [CONFIGURATION.md](./CONFIGURATION.md)
|
|
4
|
+
|
|
5
|
+
本文覆盖宿主接入时可配置的公开接口:`KokoProvider`、`KokoAgentConfig`、运行时外观、单次任务参数,以及内置 UI 组件。TypeScript 类型定义仍是最终准源。
|
|
6
|
+
|
|
7
|
+
## 完整示例
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import React from 'react';
|
|
11
|
+
import {
|
|
12
|
+
KokoProvider,
|
|
13
|
+
openKokoChat,
|
|
14
|
+
setKokoAppearance,
|
|
15
|
+
} from '@intentcomputing/koko-agent-sdk';
|
|
16
|
+
|
|
17
|
+
export function App() {
|
|
18
|
+
const tokenProvider = React.useCallback(async () => {
|
|
19
|
+
const response = await hostApi.get('/koko/access-token');
|
|
20
|
+
return response.data as { accessToken: string; expiresAt: number };
|
|
21
|
+
}, []);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<KokoProvider
|
|
25
|
+
cursor
|
|
26
|
+
observer
|
|
27
|
+
dialogs
|
|
28
|
+
resumeAfterReload
|
|
29
|
+
config={{
|
|
30
|
+
gateway: {
|
|
31
|
+
baseUrl: 'https://sdk.intentcomputing.cn',
|
|
32
|
+
tokenProvider,
|
|
33
|
+
// appId 通常无需填写,默认读取 Bundle ID / Package Name。
|
|
34
|
+
},
|
|
35
|
+
locale: 'zh',
|
|
36
|
+
theme: 'light', // 填宿主主题;Koko 浮层会使用对比主题。
|
|
37
|
+
branding: {
|
|
38
|
+
name: 'My Assistant',
|
|
39
|
+
tagline: '帮你操作当前 App',
|
|
40
|
+
placeholder: '告诉我你想做什么…',
|
|
41
|
+
primaryColor: '#6D4AFF',
|
|
42
|
+
icon: require('./assistant.png'),
|
|
43
|
+
},
|
|
44
|
+
confirmation: {
|
|
45
|
+
requireUserConfirm: true,
|
|
46
|
+
mode: 'preflight',
|
|
47
|
+
},
|
|
48
|
+
webWalletAliases: ['My Wallet'],
|
|
49
|
+
dumpMaxDepth: 80,
|
|
50
|
+
dumpSkipInvisible: true,
|
|
51
|
+
cursorDurationMs: 480,
|
|
52
|
+
observer: true,
|
|
53
|
+
debug: false,
|
|
54
|
+
onUsageEvent: event => analytics.track('koko_usage', event),
|
|
55
|
+
}}
|
|
56
|
+
>
|
|
57
|
+
<HostNavigation />
|
|
58
|
+
</KokoProvider>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## `KokoProvider` props
|
|
64
|
+
|
|
65
|
+
| 配置 | 类型 | 默认值 | 说明 |
|
|
66
|
+
|---|---|---:|---|
|
|
67
|
+
| `children` | `ReactNode` | 必填 | 宿主应用或最外层导航树。 |
|
|
68
|
+
| `config` | `KokoAgentConfig` | `{}` | Agent、网关、品牌和确认策略,详见下表。 |
|
|
69
|
+
| `cursor` | `boolean` | `true` | 显示可观测操作光标。 |
|
|
70
|
+
| `observer` | `boolean` | 继承 `config.observer` | 显示任务进度条和对话面板宿主;显式传入时优先。 |
|
|
71
|
+
| `dialogs` | `boolean` | `true` | 挂载 SDK 内置确认和追问弹窗。关闭后,宿主应提供对应回调。 |
|
|
72
|
+
| `resumeAfterReload` | `boolean` | `true` | JS 上下文因语言、主题或宿主重载而中断时,最多恢复一次最近任务。 |
|
|
73
|
+
| `remoteSmokePort` | `number` | `0` | 仅供开发联调的本机 smoke 驱动端口;生产包不要配置。 |
|
|
74
|
+
| `composerPlaceholder` | `string` | — | 已废弃;改用 `config.branding.placeholder`。 |
|
|
75
|
+
|
|
76
|
+
`KokoProvider.observer={false}` 只隐藏内置进度/对话 UI;`config.observer={false}` 还会关闭自动任务日志。两者都为 `true` 时功能完整。
|
|
77
|
+
|
|
78
|
+
## `KokoAgentConfig`
|
|
79
|
+
|
|
80
|
+
| 配置 | 类型 | 默认值 | 说明 |
|
|
81
|
+
|---|---|---:|---|
|
|
82
|
+
| `gateway` | `GatewayConfig` | — | 正式运行必需的网关和短 Token 配置。 |
|
|
83
|
+
| `locale` | `'zh' \| 'en'` | `'en'` | SDK 内置 UI 初始语言。运行时变化优先使用 `setKokoAppearance`。 |
|
|
84
|
+
| `theme` | `'light' \| 'dark'` | `'light'` | **宿主 App 当前主题**;Koko 浮层会使用相反主题以保持可见。 |
|
|
85
|
+
| `branding` | `KokoBrandingConfig` | Koko 默认品牌 | 自定义名称、图标、文案和主色;需要 `custom_branding` 权益。 |
|
|
86
|
+
| `confirmation` | `ConfirmationPolicy` | 需要确认、`preflight` | 高风险任务的人工确认策略。 |
|
|
87
|
+
| `onConfirmSensitive` | `(ctx) => Promise<boolean>` | 内置确认弹窗 | 自定义敏感操作确认。返回 `true` 才继续。 |
|
|
88
|
+
| `webWalletAliases` | `string[]` | `[]` | 宿主确认属于自身注入钱包的公开钱包名称。只声明已验证别名。 |
|
|
89
|
+
| `dumpMaxDepth` | `number` | `80` | 原生可访问性树最大读取深度;过小会截断 RN 导航/组件库下的页面正文。 |
|
|
90
|
+
| `dumpSkipInvisible` | `boolean` | `true` | 读取页面时丢弃不可见节点。 |
|
|
91
|
+
| `cursorDurationMs` | `number` | `480` | 默认光标移动动画时长,单位毫秒。 |
|
|
92
|
+
| `observer` | `boolean` | `true` | 启用任务日志;Provider 未显式设置 `observer` 时也控制内置进度/对话 UI。 |
|
|
93
|
+
| `debug` | `boolean` | Metro Debug 为 `true`;Release 为 `false` | 输出能力和执行步骤日志,不放宽安全策略。正式包建议显式设为 `false`。 |
|
|
94
|
+
| `devMode` | `boolean` | 同 `debug` | 已废弃的 `debug` 别名。 |
|
|
95
|
+
| `onUsageEvent` | `(event) => void` | — | 本地分析/UX 事件旁路通知,不参与计费,也不能阻塞任务。 |
|
|
96
|
+
|
|
97
|
+
### `gateway`
|
|
98
|
+
|
|
99
|
+
| 配置 | 类型 | 默认值 | 说明 |
|
|
100
|
+
|---|---|---:|---|
|
|
101
|
+
| `baseUrl` | `string` | `https://sdk.intentcomputing.net` | 海外/OpenAI 网关;国内/DeepSeek 使用 `https://sdk.intentcomputing.cn`。正式构建只接受官方地址。 |
|
|
102
|
+
| `tokenProvider` | `() => Promise<string \| { accessToken; expiresAt? }>` | — | 推荐。向**宿主后端**获取短期 Token。SDK 仅在内存中缓存,在请求时发现临近过期才刷新,401 后强制刷新并重试一次。 |
|
|
103
|
+
| `token` | `string` | — | 旧版静态 Token,仅用于本地开发和迁移;不要放进正式包。 |
|
|
104
|
+
| `appId` | `string` | 原生 Bundle ID / Package Name | 必须与服务端登记的宿主应用一致;通常无需手填。 |
|
|
105
|
+
|
|
106
|
+
`tokenProvider` 返回对象时,`expiresAt` 使用 Unix **毫秒**。若省略,SDK 尝试读取 JWT `exp`;两者都没有时按 60 秒处理。`clientSecret`、DeepSeek/OpenAI Key 永远不得进入 App。
|
|
107
|
+
|
|
108
|
+
### `branding`
|
|
109
|
+
|
|
110
|
+
| 配置 | 类型 | 默认值 | 说明 |
|
|
111
|
+
|---|---|---:|---|
|
|
112
|
+
| `name` | `string` | `Koko` | 助手显示名称。 |
|
|
113
|
+
| `icon` | `number \| { uri: string } \| string` | 默认 K 标记 | 支持 `require()`、图片 URI/Data URI 或短文字标记。 |
|
|
114
|
+
| `tagline` | `string` | 本地化默认文案 | 对话页副标题。 |
|
|
115
|
+
| `placeholder` | `string` | 本地化默认文案 | 输入框占位文案。 |
|
|
116
|
+
| `primaryColor` | `string` | SDK 默认主色 | Badge、发送按钮等强调色。使用 React Native 可识别的颜色字符串。 |
|
|
117
|
+
|
|
118
|
+
没有品牌权益时,SDK 自动降级到 Koko 默认品牌,并通过 `onUsageEvent` 发出一次 `branding_downgraded`。
|
|
119
|
+
|
|
120
|
+
### `confirmation`
|
|
121
|
+
|
|
122
|
+
| 配置 | 类型 | 默认值 | 说明 |
|
|
123
|
+
|---|---|---:|---|
|
|
124
|
+
| `requireUserConfirm` | `boolean` | `true` | 是否要求高风险目标由用户确认。 |
|
|
125
|
+
| `mode` | `'preflight' \| 'inline' \| 'off'` | `'preflight'` | `preflight` 在任务开始前确认一次;`inline` 为兼容旧版的逐步确认;`off` 关闭 SDK 确认。 |
|
|
126
|
+
| `sensitivePatterns` | `RegExp[]` | SDK 内置规则 | 自定义高风险目标匹配规则。传入非空数组时替换内置规则。 |
|
|
127
|
+
|
|
128
|
+
关闭 SDK 确认不会绕过密码、助记词、私钥、OTP 等隐私页面的本地门禁;这些内容仍必须由用户亲自操作。
|
|
129
|
+
|
|
130
|
+
### `onUsageEvent` 事件
|
|
131
|
+
|
|
132
|
+
可能收到:`task_started`、`task_finished`、`agent_step`、`quota_exceeded`、`sheet_opened`、`sheet_closed`、`branding_downgraded`。不得把事件里的任务文本继续发送到未经授权的分析服务。
|
|
133
|
+
|
|
134
|
+
## 运行时语言和主题
|
|
135
|
+
|
|
136
|
+
```tsx
|
|
137
|
+
import { setKokoAppearance } from '@intentcomputing/koko-agent-sdk';
|
|
138
|
+
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
setKokoAppearance({ locale: hostLocale, theme: hostTheme });
|
|
141
|
+
}, [hostLocale, hostTheme]);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
- `locale` 可传宿主语言字符串;以 `zh` 开头映射为中文,其余映射为英文。
|
|
145
|
+
- `theme` 填宿主真实主题:`'light'` 或 `'dark'`。
|
|
146
|
+
- 运行时外观优先级高于静态 `config.locale` / `config.theme`。
|
|
147
|
+
|
|
148
|
+
`getKokoAgent().configure(patch)` 可动态修改配置,但它执行浅合并;更新 `gateway`、`branding` 或 `confirmation` 时应传入完整子对象。语言/主题仍优先用 `setKokoAppearance`。
|
|
149
|
+
|
|
150
|
+
## 单次任务覆盖项
|
|
151
|
+
|
|
152
|
+
```tsx
|
|
153
|
+
await getKokoAgent().runGoal('打开设置', {
|
|
154
|
+
locale: 'zh-CN',
|
|
155
|
+
localRetries: 3,
|
|
156
|
+
userGateTimeoutMs: 300_000,
|
|
157
|
+
onAskUser: question => showHostQuestion(question),
|
|
158
|
+
onNarration: text => setHint(text),
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
| 配置 | 默认值 | 说明 |
|
|
163
|
+
|---|---:|---|
|
|
164
|
+
| `baseUrl` / `tokenProvider` / `token` / `appId` | 继承 `config.gateway` | 仅覆盖本次任务的网关配置。 |
|
|
165
|
+
| `locale` | 当前有效语言 | 本次规划请求语言。 |
|
|
166
|
+
| `localRetries` | `3` | 只读 `dump/find` 的本地失败重试次数,范围 `0–3`;触摸、输入等写操作不会自动重放。 |
|
|
167
|
+
| `userGateTimeoutMs` | `300000` | 等待用户完成密码/助记词/授权等本地门禁的最长时间。 |
|
|
168
|
+
| `onAskUser` | 内置追问弹窗 | Agent 需要用户补充信息时的宿主回调。 |
|
|
169
|
+
| `onNarration` | — | 接收当前任务提示/旁白。 |
|
|
170
|
+
|
|
171
|
+
`resumedFromReload` 和 `resumes` 是 SDK 恢复机制内部字段,宿主不应主动设置。
|
|
172
|
+
|
|
173
|
+
## 内置 UI 组件参数
|
|
174
|
+
|
|
175
|
+
| 组件 | 可配置项 |
|
|
176
|
+
|---|---|
|
|
177
|
+
| `KokoEntryButton` | `label`(默认 `Koko`)、`style`。生产宿主更推荐自绘入口并调用 `openKokoChat()`。 |
|
|
178
|
+
| `KokoComposer` | `placeholder`、`disabled`(默认 `false`)。 |
|
|
179
|
+
| `KokoObserver` | `cursor`(默认 `true`)、已废弃的 `composerPlaceholder`。通常由 Provider 自动挂载。 |
|
|
180
|
+
| `KokoOverlayLayer` | `style`、`pointerEvents`(默认 `box-none`)、`testID`。供自定义 SDK 浮层使用。 |
|
|
181
|
+
|
|
182
|
+
## 低级操作参数
|
|
183
|
+
|
|
184
|
+
这些 API 主要用于自定义集成;普通宿主不需要直接调用。
|
|
185
|
+
|
|
186
|
+
| 类型 | 可配置项及默认行为 |
|
|
187
|
+
|---|---|
|
|
188
|
+
| `DumpOptions` | `maxDepth`、`skipInvisible`、`silent`。未传时继承 Agent 配置。 |
|
|
189
|
+
| `TapOptions` | `revealIfNeeded`、`silent`、`cursorDurationMs`。任务规划器会自行决定何时滚动寻找目标。 |
|
|
190
|
+
| `SwipeOptions` | `durationMs`、`silent`。 |
|
|
191
|
+
| `PinchOptions` | `durationMs`(默认 `280`)、`silent`。 |
|
|
192
|
+
| `TypeOptions` | `clear`、`silent`。 |
|
|
193
|
+
|
|
194
|
+
完整隐私边界见[隐私说明](PRIVACY.zh-CN.md),三端鉴权见[后端鉴权 Demo](BACKEND_AUTH_DEMOS.zh-CN.md)。
|
|
195
|
+
|
package/docs/INTEGRATION.md
CHANGED
|
@@ -8,7 +8,7 @@ For React Native host apps. After installing the package you must link native co
|
|
|
8
8
|
|
|
9
9
|
- React Native ≥ 0.73 (or Expo Dev Client / `expo prebuild` — **not Expo Go**)
|
|
10
10
|
- iOS deployment target ≥ 15; ability to run `pod install`
|
|
11
|
-
- An Intent Computing `clientId` and `clientSecret`; keep the secret on the host backend only
|
|
11
|
+
- An Intent Computing console app with its one-time `clientId` and `clientSecret`; keep the secret on the host backend only
|
|
12
12
|
|
|
13
13
|
## Checklist
|
|
14
14
|
|
|
@@ -107,6 +107,8 @@ getKokoAgent().openChat();
|
|
|
107
107
|
|
|
108
108
|
### Optional props / config
|
|
109
109
|
|
|
110
|
+
The table below is only the common subset. See the [complete configuration reference](CONFIGURATION.md) for every Provider, Agent, gateway, branding, runtime, per-run, and built-in component option.
|
|
111
|
+
|
|
110
112
|
| Key | Purpose | Default |
|
|
111
113
|
|--|--|--|
|
|
112
114
|
| `cursor` | Action cursor overlay | `true` |
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
- React Native ≥ 0.73(或 Expo Dev Client / `expo prebuild`,**不支持 Expo Go**)
|
|
10
10
|
- iOS 部署目标 ≥ 15;需本机可 `pod install`
|
|
11
|
-
-
|
|
11
|
+
- 在 Intent Computing 用户后台创建应用并取得一次性显示的 `clientId` / `clientSecret`;`clientSecret` 只放宿主后端
|
|
12
12
|
|
|
13
13
|
## 步骤一览
|
|
14
14
|
|
|
@@ -98,6 +98,8 @@ getKokoAgent().openChat();
|
|
|
98
98
|
|
|
99
99
|
### 可选开关
|
|
100
100
|
|
|
101
|
+
下表仅列常用项。Provider、Agent、网关、品牌、运行时、单次任务及内置组件的所有选项见 [SDK 完整配置参考](CONFIGURATION.zh-CN.md)。
|
|
102
|
+
|
|
101
103
|
| prop / config | 含义 | 默认 |
|
|
102
104
|
|--|--|--|
|
|
103
105
|
| `cursor` | 操作光标 | `true` |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intentcomputing/koko-agent-sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Koko Agent SDK — in-app AI agent for React Native (dump / find / tap with visible cursor). Talk to Intent Computing gateway; no LLM API keys in the app.",
|
|
5
5
|
"main": "./lib/commonjs/index.js",
|
|
6
6
|
"module": "./lib/module/index.js",
|
|
@@ -39,6 +39,8 @@
|
|
|
39
39
|
"SECURITY.md",
|
|
40
40
|
"docs/INTEGRATION.md",
|
|
41
41
|
"docs/INTEGRATION.zh-CN.md",
|
|
42
|
+
"docs/CONFIGURATION.md",
|
|
43
|
+
"docs/CONFIGURATION.zh-CN.md",
|
|
42
44
|
"docs/PRIVACY.md",
|
|
43
45
|
"docs/PRIVACY.zh-CN.md",
|
|
44
46
|
"docs/BACKEND_AUTH_DEMOS.md",
|