@openviking/react 0.1.0 → 0.1.2

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 (193) hide show
  1. package/README.md +57 -34
  2. package/dist/3~0.js +2117 -0
  3. package/dist/ark-message-list-view~0.js +310 -0
  4. package/dist/a~0.js +21 -0
  5. package/dist/c7~0.js +24 -0
  6. package/dist/client/client.d.ts +12 -0
  7. package/dist/client/errors.d.ts +30 -0
  8. package/dist/client/index.d.ts +4 -0
  9. package/dist/client/options.d.ts +101 -0
  10. package/dist/client/provider.d.ts +52 -0
  11. package/dist/client/types.d.ts +160 -0
  12. package/dist/client.js +239 -0
  13. package/dist/components/agent-connect/agent-connect-copy.d.ts +34 -0
  14. package/dist/components/agent-connect/agent-connect-design.d.ts +1781 -0
  15. package/dist/components/agent-connect/agent-connect-detail.d.ts +13 -0
  16. package/dist/components/agent-connect/agent-connect-installer.d.ts +3 -0
  17. package/dist/components/agent-connect/agent-connect-instructions-view.d.ts +14 -0
  18. package/dist/components/agent-connect/agent-connect-instructions.d.ts +145 -0
  19. package/dist/components/agent-connect/agent-connect-markdown.d.ts +3 -0
  20. package/dist/components/agent-connect/agent-connect.d.ts +4 -1
  21. package/dist/components/agent-connect/content-en.d.ts +137 -0
  22. package/dist/components/agent-connect/content-zh.d.ts +137 -0
  23. package/dist/components/agent-connect/index.d.ts +1 -0
  24. package/dist/components/agent-connect/style.css +503 -0
  25. package/dist/components/agent-connect/types.d.ts +29 -0
  26. package/dist/components/agent-connect.js +1 -0
  27. package/dist/components/file-preview/file-preview-adapters.d.ts +33 -0
  28. package/dist/components/file-preview/file-preview-body.d.ts +27 -0
  29. package/dist/components/file-preview/file-preview-breadcrumb-menu.d.ts +16 -0
  30. package/dist/components/file-preview/file-preview-breadcrumb.d.ts +21 -0
  31. package/dist/components/file-preview/file-preview-copy-path.d.ts +12 -0
  32. package/dist/components/file-preview/file-preview-editor.d.ts +22 -0
  33. package/dist/components/file-preview/file-preview-handle-adapters.d.ts +26 -0
  34. package/dist/components/file-preview/file-preview-header.d.ts +25 -0
  35. package/dist/components/file-preview/file-preview-labels.d.ts +16 -0
  36. package/dist/components/file-preview/file-preview-lazy-viewer.d.ts +3 -0
  37. package/dist/components/file-preview/file-preview-path.d.ts +30 -0
  38. package/dist/components/file-preview/file-preview-source.d.ts +24 -0
  39. package/dist/components/file-preview/file-preview-state.d.ts +28 -0
  40. package/dist/components/file-preview/file-preview-tab-row.d.ts +16 -0
  41. package/dist/components/file-preview/file-preview-viewer.d.ts +31 -0
  42. package/dist/components/file-preview/file-preview.d.ts +14 -1
  43. package/dist/components/file-preview/index.d.ts +1 -0
  44. package/dist/components/file-preview/style.css +4139 -0
  45. package/dist/components/file-preview/types.d.ts +516 -0
  46. package/dist/components/file-preview/use-file-preview-actions-context.d.ts +23 -0
  47. package/dist/components/file-preview/use-file-preview-actions.d.ts +19 -0
  48. package/dist/components/file-preview/use-file-preview-editing.d.ts +32 -0
  49. package/dist/components/file-preview/use-file-preview-ids.d.ts +24 -0
  50. package/dist/components/file-preview.js +1 -0
  51. package/dist/components/file-tree/file-tree-body.d.ts +18 -0
  52. package/dist/components/file-tree/file-tree-entry-row.d.ts +12 -0
  53. package/dist/components/file-tree/file-tree-icons.d.ts +15 -0
  54. package/dist/components/file-tree/file-tree-info-labels.d.ts +21 -0
  55. package/dist/components/file-tree/file-tree-info-tooltip.d.ts +43 -0
  56. package/dist/components/file-tree/file-tree-info.d.ts +29 -0
  57. package/dist/components/file-tree/file-tree-keyboard.d.ts +14 -0
  58. package/dist/components/file-tree/file-tree-row-context.d.ts +46 -0
  59. package/dist/components/file-tree/file-tree-row-shared.d.ts +11 -0
  60. package/dist/components/file-tree/file-tree-spinner.d.ts +10 -0
  61. package/dist/components/file-tree/file-tree-state-row.d.ts +7 -0
  62. package/dist/components/file-tree/file-tree-tooltip-surface.d.ts +22 -0
  63. package/dist/components/file-tree/file-tree-tooltip.d.ts +17 -0
  64. package/dist/components/file-tree/file-tree.d.ts +15 -1
  65. package/dist/components/file-tree/index.d.ts +1 -0
  66. package/dist/components/file-tree/style.css +410 -0
  67. package/dist/components/file-tree/types.d.ts +589 -0
  68. package/dist/components/file-tree/use-file-tree-actions.d.ts +17 -0
  69. package/dist/components/file-tree.js +1 -0
  70. package/dist/components/scope-switcher/index.d.ts +1 -0
  71. package/dist/components/scope-switcher/scope-keyboard.d.ts +2 -0
  72. package/dist/components/scope-switcher/scope-panel.d.ts +11 -0
  73. package/dist/components/scope-switcher/scope-selector.d.ts +2 -0
  74. package/dist/components/scope-switcher/scope-switcher.d.ts +6 -1
  75. package/dist/components/scope-switcher/style.css +452 -0
  76. package/dist/components/scope-switcher/types.d.ts +489 -0
  77. package/dist/components/scope-switcher.js +3 -0
  78. package/dist/components/style.css +14249 -18
  79. package/dist/components/tui/command-catalog.d.ts +58 -0
  80. package/dist/components/tui/command-completion.d.ts +19 -0
  81. package/dist/components/tui/command-definitions.d.ts +10 -0
  82. package/dist/components/tui/command-input.d.ts +16 -0
  83. package/dist/components/tui/index.d.ts +1 -0
  84. package/dist/components/tui/style.css +1552 -0
  85. package/dist/components/tui/tui-assist.d.ts +15 -0
  86. package/dist/components/tui/tui-code-block.d.ts +8 -0
  87. package/dist/components/tui/tui-command-help.d.ts +9 -0
  88. package/dist/components/tui/tui-command-text.d.ts +6 -0
  89. package/dist/components/tui/tui-composer.d.ts +24 -0
  90. package/dist/components/tui/tui-copy-button.d.ts +9 -0
  91. package/dist/components/tui/tui-input-mirror.d.ts +14 -0
  92. package/dist/components/tui/tui-labels-zh.d.ts +2 -0
  93. package/dist/components/tui/tui-labels.d.ts +5 -0
  94. package/dist/components/tui/tui-markdown-renderers.d.ts +10 -0
  95. package/dist/components/tui/tui-markdown.d.ts +6 -0
  96. package/dist/components/tui/tui-param-hint.d.ts +7 -0
  97. package/dist/components/tui/tui-record-time.d.ts +11 -0
  98. package/dist/components/tui/tui-record.d.ts +13 -0
  99. package/dist/components/tui/tui-resource-preview.d.ts +10 -0
  100. package/dist/components/tui/tui-resource-tree.d.ts +10 -0
  101. package/dist/components/tui/tui-result-header.d.ts +7 -0
  102. package/dist/components/tui/tui-result-text.d.ts +5 -0
  103. package/dist/components/tui/tui-search-list.d.ts +8 -0
  104. package/dist/components/tui/tui-skeleton.d.ts +6 -0
  105. package/dist/components/tui/tui-status-card.d.ts +7 -0
  106. package/dist/components/tui/tui-text.d.ts +10 -0
  107. package/dist/components/tui/tui-uri-text.d.ts +19 -0
  108. package/dist/components/tui/tui-write-result.d.ts +7 -0
  109. package/dist/components/tui/tui.d.ts +11 -1
  110. package/dist/components/tui/types.d.ts +527 -0
  111. package/dist/components/tui/use-tui-assist-position.d.ts +3 -0
  112. package/dist/components/tui/use-tui-completion.d.ts +14 -0
  113. package/dist/components/tui/use-tui-composer-keyboard.d.ts +25 -0
  114. package/dist/components/tui.js +1 -0
  115. package/dist/components/viking-bot/ark-adapter.d.ts +45 -0
  116. package/dist/components/viking-bot/ark-message-body.d.ts +16 -0
  117. package/dist/components/viking-bot/ark-message-list-view.d.ts +7 -0
  118. package/dist/components/viking-bot/ark-message-row.d.ts +19 -0
  119. package/dist/components/viking-bot/index.d.ts +10 -0
  120. package/dist/components/viking-bot/interaction/ask-human-fields.d.ts +10 -0
  121. package/dist/components/viking-bot/interaction/index.d.ts +4 -0
  122. package/dist/components/viking-bot/interaction/labels.d.ts +7 -0
  123. package/dist/components/viking-bot/interaction/lazy-interaction.d.ts +3 -0
  124. package/dist/components/viking-bot/interaction/schedule-input.d.ts +13 -0
  125. package/dist/components/viking-bot/interaction/style.css +189 -0
  126. package/dist/components/viking-bot/interaction/types.d.ts +188 -0
  127. package/dist/components/viking-bot/interaction/viking-bot-interaction.d.ts +9 -0
  128. package/dist/components/viking-bot/interaction.js +2 -0
  129. package/dist/components/viking-bot/labels.d.ts +2 -0
  130. package/dist/components/viking-bot/lazy-composer.d.ts +3 -0
  131. package/dist/components/viking-bot/message-groups.d.ts +12 -0
  132. package/dist/components/viking-bot/model.d.ts +252 -0
  133. package/dist/components/viking-bot/render-part.d.ts +12 -0
  134. package/dist/components/viking-bot/style.css +7133 -0
  135. package/dist/components/viking-bot/types.d.ts +140 -0
  136. package/dist/components/viking-bot/viking-bot-composer.d.ts +6 -0
  137. package/dist/components/viking-bot/viking-bot-message-list.d.ts +3 -0
  138. package/dist/components/viking-bot/viking-bot.d.ts +16 -1
  139. package/dist/components/viking-bot.js +4 -0
  140. package/dist/c~0.js +201 -0
  141. package/dist/file-preview-viewer~0.js +191 -0
  142. package/dist/f~0.js +356 -0
  143. package/dist/g~0.js +1207 -0
  144. package/dist/h~0.js +58 -0
  145. package/dist/icons/file-type-icon.d.ts +31 -0
  146. package/dist/icons/index.d.ts +33 -23
  147. package/dist/icons/nextjs-icon.d.ts +19 -0
  148. package/dist/icons.js +1 -25
  149. package/dist/index.d.ts +16 -2
  150. package/dist/index.js +8 -1
  151. package/dist/k~0.js +1440 -0
  152. package/dist/lk~0.js +233 -0
  153. package/dist/l~0.js +44 -0
  154. package/dist/modules/console/console.d.ts +4 -0
  155. package/dist/modules/console/index.d.ts +1 -0
  156. package/dist/modules/console/style.css +111 -0
  157. package/dist/modules/console/types.d.ts +101 -0
  158. package/dist/modules/console.js +1 -0
  159. package/dist/modules/file-browser/file-browser-toolbar-button.d.ts +10 -0
  160. package/dist/modules/file-browser/file-browser.d.ts +6 -0
  161. package/dist/modules/file-browser/index.d.ts +1 -0
  162. package/dist/modules/file-browser/style.css +158 -0
  163. package/dist/modules/file-browser/types.d.ts +101 -0
  164. package/dist/modules/file-browser.js +1 -0
  165. package/dist/modules/scope-cascade/controller.d.ts +6 -0
  166. package/dist/modules/scope-cascade/index.d.ts +3 -0
  167. package/dist/modules/scope-cascade/scope-cascade.d.ts +3 -0
  168. package/dist/modules/scope-cascade/style.css +456 -0
  169. package/dist/modules/scope-cascade/style.js +0 -0
  170. package/dist/modules/scope-cascade/types.d.ts +39 -0
  171. package/dist/modules/scope-cascade/use-scope-cascade.d.ts +5 -0
  172. package/dist/modules/scope-cascade.js +1 -0
  173. package/dist/modules/style.css +808 -0
  174. package/dist/modules/style.js +0 -0
  175. package/dist/n~0.js +727 -0
  176. package/dist/shared/components/tooltip/index.d.ts +1 -0
  177. package/dist/shared/components/tooltip/tooltip.d.ts +25 -0
  178. package/dist/shared/components/tooltip/types.d.ts +42 -0
  179. package/dist/shared/components/tooltip/use-tooltip-position.d.ts +38 -0
  180. package/dist/style.css +15138 -18
  181. package/dist/u~0.js +1601 -0
  182. package/dist/viking-bot-composer~0.js +164 -0
  183. package/dist/viking-bot-interaction~0.js +284 -0
  184. package/dist/w~0.js +19 -0
  185. package/package.json +46 -22
  186. package/dist/components/resource-import/resource-import.d.ts +0 -1
  187. package/dist/components/resource-import/style.css +0 -2
  188. package/dist/components/status-badge/status-badge.d.ts +0 -8
  189. package/dist/components/status-badge/style.css +0 -37
  190. package/dist/components/status-badge.js +0 -30
  191. /package/dist/components/{resource-import → viking-bot/interaction}/style.js +0 -0
  192. /package/dist/{components/status-badge → modules/console}/style.js +0 -0
  193. /package/dist/{components/resource-import.js → modules/file-browser/style.js} +0 -0
@@ -0,0 +1,160 @@
1
+ /**
2
+ * 一个身份字段的取值:字符串,或每次请求重新求值的函数。
3
+ * Value of one identity field: a string, or a function re-evaluated per request.
4
+ */
5
+ export type OvIdentityValue = string | (() => string | Promise<string>);
6
+ /**
7
+ * 一次请求的身份与作用域。字段省略表示继承上层配置;显式传空字符串表示移除
8
+ * 该字段继承到的值,请求里不再发送对应请求头。
9
+ *
10
+ * 这些字段一一对应 OpenViking 的请求头,宿主传值即可,不需要自己组装 header:
11
+ * `apiKey` → `X-API-Key`,`accountId` → `X-OpenViking-Account`,`userId` →
12
+ * `X-OpenViking-User`,`resourceId` → `V-Resource-Id`。
13
+ *
14
+ * Identity and scope of one request. An omitted field inherits from the layer
15
+ * above; an explicit empty string removes the inherited value so the header is
16
+ * not sent.
17
+ *
18
+ * The fields map one to one onto OpenViking's request headers, so a host passes
19
+ * values instead of assembling headers: `apiKey` → `X-API-Key`, `accountId` →
20
+ * `X-OpenViking-Account`, `userId` → `X-OpenViking-User`, `resourceId` →
21
+ * `V-Resource-Id`.
22
+ */
23
+ export interface OvRequestOptions {
24
+ /**
25
+ * 服务地址及可选网关前缀,不含原生接口的 `/api/v1`。省略时继承上层配置,
26
+ * 空字符串表示同源请求。
27
+ *
28
+ * Service address with an optional gateway prefix, excluding the native
29
+ * `/api/v1`. Omitted inherits the layer above; an empty string means a
30
+ * same-origin request.
31
+ */
32
+ baseURL?: string;
33
+ /**
34
+ * 凭证。开源版为 `X-API-Key` 的取值;商业版由浏览器 Cookie 承载,无需传入。
35
+ * 函数形式每次请求重新求值,可读取轮换后的凭证。
36
+ *
37
+ * Credential. In the open-source edition it becomes `X-API-Key`; the
38
+ * commercial edition carries it in the browser cookie, so it is omitted
39
+ * there. A function is re-evaluated on every request, so it can read a rotated
40
+ * credential.
41
+ */
42
+ apiKey?: OvIdentityValue;
43
+ /**
44
+ * OpenViking 账号 ID,对应数据空间。
45
+ * OpenViking account ID, which corresponds to the data space.
46
+ */
47
+ accountId?: OvIdentityValue;
48
+ /**
49
+ * 账号内的用户 ID。
50
+ * User ID within the account.
51
+ */
52
+ userId?: OvIdentityValue;
53
+ /**
54
+ * 当前库 ID。数据面接口需要它确定请求落在哪个库。
55
+ * Current library ID. Data-plane requests need it to know which library they
56
+ * address.
57
+ */
58
+ resourceId?: OvIdentityValue;
59
+ /**
60
+ * 调用方中止请求的信号。
61
+ * Signal the caller uses to abort the request.
62
+ */
63
+ signal?: AbortSignal;
64
+ }
65
+ /**
66
+ * 创建客户端时的配置。在 {@link OvRequestOptions} 之上增加 Cookie 策略与传输层
67
+ * 设置。
68
+ * Configuration when creating a client: {@link OvRequestOptions} plus the cookie
69
+ * policy and transport settings.
70
+ */
71
+ export interface OvClientOptions extends OvRequestOptions {
72
+ /**
73
+ * 是否携带浏览器 Cookie。商业版的数据面与控制面接口都依赖 Cookie 鉴权,
74
+ * 跨源调用时需要设为 `include`。
75
+ *
76
+ * Whether browser cookies are sent. The commercial edition authenticates both
77
+ * data-plane and control-plane requests with a cookie, so a cross-origin call
78
+ * needs `include`.
79
+ */
80
+ credentials?: RequestCredentials;
81
+ /**
82
+ * 自定义 fetch 实现,用于测试或在没有全局 fetch 的环境运行。
83
+ * A custom fetch implementation, for tests or environments without a global
84
+ * fetch.
85
+ */
86
+ fetch?: typeof globalThis.fetch;
87
+ }
88
+ /**
89
+ * 配置逐字段解析后的结果,所有字段均已确定。
90
+ * The result of resolving configuration field by field, with every field
91
+ * decided.
92
+ */
93
+ export interface OvResolvedOptions {
94
+ baseURL: string;
95
+ credentials: RequestCredentials;
96
+ headers: Readonly<Record<string, string>>;
97
+ signal?: AbortSignal;
98
+ }
99
+ /**
100
+ * 原生接口的请求描述。Client 只按 method、path、query 与 body 发请求,不解析
101
+ * 业务含义。
102
+ * A native API request. The Client sends it by method, path, query and body
103
+ * without interpreting the payload.
104
+ */
105
+ export interface OvRequestSpec {
106
+ method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD';
107
+ /**
108
+ * 以 `/` 开头的接口路径,不含服务地址与网关前缀。
109
+ * API path starting with `/`, without the service address or gateway prefix.
110
+ */
111
+ path: string;
112
+ query?: Readonly<Record<string, OvQueryValue>>;
113
+ body?: unknown;
114
+ /**
115
+ * 本次请求的身份、作用域与服务地址覆盖,例如切换到另一个库或另一个网关。
116
+ * Identity, scope and service-address override for this request, for example
117
+ * switching to another library or another gateway.
118
+ */
119
+ options?: OvRequestOptions;
120
+ }
121
+ /** 查询参数可接受的值;`undefined` 与 `null` 表示不发送。 */
122
+ export type OvQueryValue = string | number | boolean | null | undefined | readonly (string | number | boolean)[];
123
+ /**
124
+ * 原生接口的成功响应外壳。`result` 承载业务数据,其余字段是外层元数据。
125
+ * The success envelope of a native response. `result` carries the payload and
126
+ * the remaining fields are outer metadata.
127
+ */
128
+ export interface OvSuccessEnvelope<TResult = unknown> {
129
+ result?: TResult;
130
+ status?: string;
131
+ [key: string]: unknown;
132
+ }
133
+ /** 原生接口的错误响应外壳。The error envelope of a native response. */
134
+ export interface OvErrorEnvelope {
135
+ status?: string;
136
+ error?: {
137
+ code?: string;
138
+ message?: string;
139
+ details?: unknown;
140
+ };
141
+ }
142
+ /**
143
+ * 框架无关的请求能力。库自带基于 `fetch` 的实现,宿主也可以自行实现以复用
144
+ * 已有请求层;模块只依赖本接口。
145
+ * Framework-neutral request capability. The library ships a `fetch`-based
146
+ * implementation, and a host may implement it to reuse an existing request
147
+ * layer; modules depend only on this interface.
148
+ */
149
+ export interface OvClient {
150
+ /**
151
+ * 发一次请求并返回原生响应的 `result`。
152
+ * Sends one request and returns the native response's `result`.
153
+ */
154
+ request<TResult>(spec: OvRequestSpec): Promise<TResult>;
155
+ /**
156
+ * 当前生效的服务地址,用于缓存键与订阅隔离。
157
+ * The effective service address, used to isolate caches and subscriptions.
158
+ */
159
+ readonly baseURL: string;
160
+ }
package/dist/client.js ADDED
@@ -0,0 +1,239 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext as external_react_useContext, useMemo } from "react";
3
+ class OvClientError extends Error {
4
+ code;
5
+ statusCode;
6
+ details;
7
+ requestId;
8
+ responseBody;
9
+ constructor(options){
10
+ super(options.message, void 0 === options.cause ? void 0 : {
11
+ cause: options.cause
12
+ });
13
+ this.name = 'OvClientError';
14
+ this.code = options.code;
15
+ this.statusCode = options.statusCode;
16
+ this.details = options.details;
17
+ this.requestId = options.requestId;
18
+ this.responseBody = options.responseBody;
19
+ }
20
+ }
21
+ function isOvClientError(value) {
22
+ return value instanceof OvClientError;
23
+ }
24
+ const IDENTITY_HEADERS = {
25
+ apiKey: 'X-API-Key',
26
+ accountId: 'X-OpenViking-Account',
27
+ userId: 'X-OpenViking-User',
28
+ resourceId: 'V-Resource-Id'
29
+ };
30
+ async function evaluate(value) {
31
+ if (void 0 === value) return;
32
+ return 'function' == typeof value ? await value() : value;
33
+ }
34
+ async function resolveIdentityLayer(options) {
35
+ const layer = {};
36
+ for (const field of Object.keys(IDENTITY_HEADERS)){
37
+ const value = await evaluate(options?.[field]);
38
+ if (void 0 !== value) layer[field] = value;
39
+ }
40
+ return layer;
41
+ }
42
+ function mergeIdentityLayers(far, near) {
43
+ return {
44
+ ...far,
45
+ ...near
46
+ };
47
+ }
48
+ function toHeaders(layer) {
49
+ const out = {};
50
+ for (const field of Object.keys(IDENTITY_HEADERS)){
51
+ const value = layer[field]?.trim();
52
+ if (value) out[IDENTITY_HEADERS[field].toLowerCase()] = value;
53
+ }
54
+ return out;
55
+ }
56
+ function resolveClientOptions(options, identity) {
57
+ return {
58
+ baseURL: options.baseURL ?? '',
59
+ credentials: options.credentials ?? 'same-origin',
60
+ headers: toHeaders(identity),
61
+ signal: options.signal
62
+ };
63
+ }
64
+ function resolveRequestOptions(local, parent, mergedLayer) {
65
+ const headers = {
66
+ ...parent.headers
67
+ };
68
+ for (const field of Object.keys(IDENTITY_HEADERS)){
69
+ const value = mergedLayer[field];
70
+ if (void 0 === value) continue;
71
+ const name = IDENTITY_HEADERS[field].toLowerCase();
72
+ if (value.trim()) headers[name] = value;
73
+ else delete headers[name];
74
+ }
75
+ return {
76
+ baseURL: local?.baseURL ?? parent.baseURL,
77
+ credentials: parent.credentials,
78
+ headers,
79
+ signal: local?.signal ?? parent.signal
80
+ };
81
+ }
82
+ function joinUrl(baseURL, path) {
83
+ const prefix = baseURL.replace(/\/+$/, '');
84
+ return `${prefix}${path.startsWith('/') ? path : `/${path}`}`;
85
+ }
86
+ function buildQuery(query) {
87
+ if (!query) return '';
88
+ const params = new URLSearchParams();
89
+ for (const [key, value] of Object.entries(query))if (null != value) {
90
+ if (Array.isArray(value)) {
91
+ for (const item of value)params.append(key, String(item));
92
+ continue;
93
+ }
94
+ params.set(key, String(value));
95
+ }
96
+ const text = params.toString();
97
+ return text ? `?${text}` : '';
98
+ }
99
+ function mergeProviderConfig(inherited, local) {
100
+ const declared = {};
101
+ if (void 0 !== local.apiKey) declared.apiKey = local.apiKey;
102
+ if (void 0 !== local.accountId) declared.accountId = local.accountId;
103
+ if (void 0 !== local.userId) declared.userId = local.userId;
104
+ if (void 0 !== local.resourceId) declared.resourceId = local.resourceId;
105
+ return {
106
+ baseURL: local.baseURL ?? inherited?.baseURL,
107
+ credentials: local.credentials ?? inherited?.credentials,
108
+ signal: local.signal ?? inherited?.signal,
109
+ fetch: local.fetch ?? inherited?.fetch,
110
+ identity: {
111
+ ...inherited?.identity,
112
+ ...declared
113
+ }
114
+ };
115
+ }
116
+ function isRecord(value) {
117
+ return 'object' == typeof value && null !== value && !Array.isArray(value);
118
+ }
119
+ function readEnvelope(value) {
120
+ return isRecord(value) ? value : {};
121
+ }
122
+ function isAbortError(error) {
123
+ return isRecord(error) && ('AbortError' === error.name || 'ABORT_ERR' === error.code);
124
+ }
125
+ function normalizeTransportError(error, signal) {
126
+ if (isAbortError(error) || signal?.aborted) throw error;
127
+ throw new OvClientError({
128
+ code: 'NETWORK_ERROR',
129
+ message: error instanceof Error ? error.message : 'Network request failed',
130
+ cause: error
131
+ });
132
+ }
133
+ function createOvClient(options = {}) {
134
+ const fetchImpl = options.fetch ?? globalThis.fetch;
135
+ if (!fetchImpl) throw new Error('createOvClient needs a fetch implementation. Pass `fetch` on platforms without a global one.');
136
+ const defaults = options;
137
+ const client = {
138
+ get baseURL () {
139
+ return defaults.baseURL ?? '';
140
+ },
141
+ async request (spec) {
142
+ const baseLayer = await resolveIdentityLayer(defaults);
143
+ const localLayer = await resolveIdentityLayer(spec.options);
144
+ const parent = resolveClientOptions(defaults, baseLayer);
145
+ const effective = resolveRequestOptions(spec.options, parent, mergeIdentityLayers(baseLayer, localLayer));
146
+ const url = joinUrl(effective.baseURL, spec.path) + buildQuery(spec.query);
147
+ const hasBody = void 0 !== spec.body;
148
+ const headers = hasBody ? {
149
+ 'content-type': 'application/json',
150
+ ...effective.headers
151
+ } : effective.headers;
152
+ let response;
153
+ try {
154
+ response = await fetchImpl(url, {
155
+ method: spec.method,
156
+ headers,
157
+ body: hasBody ? JSON.stringify(spec.body) : void 0,
158
+ credentials: effective.credentials,
159
+ signal: effective.signal
160
+ });
161
+ } catch (error) {
162
+ normalizeTransportError(error, effective.signal);
163
+ }
164
+ let raw;
165
+ try {
166
+ raw = await response.text();
167
+ } catch (error) {
168
+ normalizeTransportError(error, effective.signal);
169
+ }
170
+ let body;
171
+ if (raw.trim()) try {
172
+ body = JSON.parse(raw);
173
+ } catch {
174
+ body = raw;
175
+ }
176
+ const envelope = readEnvelope(body);
177
+ const requestId = response.headers.get('x-request-id') ?? void 0;
178
+ if (!response.ok) throw new OvClientError({
179
+ code: envelope.error?.code ?? `HTTP_${response.status}`,
180
+ message: envelope.error?.message ?? response.statusText,
181
+ statusCode: response.status,
182
+ details: envelope.error?.details,
183
+ requestId,
184
+ responseBody: body
185
+ });
186
+ if ('error' === envelope.status) throw new OvClientError({
187
+ code: envelope.error?.code ?? 'UNKNOWN',
188
+ message: envelope.error?.message ?? 'Request failed',
189
+ statusCode: response.status,
190
+ details: envelope.error?.details,
191
+ requestId,
192
+ responseBody: body
193
+ });
194
+ return 'result' in envelope ? envelope.result : body;
195
+ }
196
+ };
197
+ return client;
198
+ }
199
+ const OvClientContext = /*#__PURE__*/ createContext(null);
200
+ function OpenVikingProvider({ baseURL, apiKey, accountId, userId, resourceId, credentials, signal, fetch, children }) {
201
+ const parent = external_react_useContext(OvClientContext);
202
+ const value = useMemo(()=>{
203
+ const base = mergeProviderConfig(parent?.base, {
204
+ baseURL,
205
+ apiKey,
206
+ accountId,
207
+ userId,
208
+ resourceId,
209
+ credentials,
210
+ signal,
211
+ fetch
212
+ });
213
+ return {
214
+ base,
215
+ client: createOvClient({
216
+ ...base.identity,
217
+ baseURL: base.baseURL,
218
+ credentials: base.credentials,
219
+ signal: base.signal,
220
+ fetch: base.fetch
221
+ })
222
+ };
223
+ }, [
224
+ parent,
225
+ baseURL,
226
+ apiKey,
227
+ accountId,
228
+ userId,
229
+ resourceId,
230
+ credentials,
231
+ signal,
232
+ fetch
233
+ ]);
234
+ return /*#__PURE__*/ jsx(OvClientContext.Provider, {
235
+ value: value,
236
+ children: children
237
+ });
238
+ }
239
+ export { OpenVikingProvider, OvClientError, createOvClient, isOvClientError };
@@ -0,0 +1,34 @@
1
+ export declare const AGENT_CONNECT_COPY: {
2
+ zh: {
3
+ title: string;
4
+ mainstream: string;
5
+ custom: string;
6
+ integration: string;
7
+ instructions: string;
8
+ copy: string;
9
+ copyMarkdown: string;
10
+ copied: string;
11
+ failed: string;
12
+ notice: string;
13
+ seeAgreement: string;
14
+ agreement: string;
15
+ apiKey: string;
16
+ overseas: string;
17
+ };
18
+ en: {
19
+ title: string;
20
+ mainstream: string;
21
+ custom: string;
22
+ integration: string;
23
+ instructions: string;
24
+ copy: string;
25
+ copyMarkdown: string;
26
+ copied: string;
27
+ failed: string;
28
+ notice: string;
29
+ seeAgreement: string;
30
+ agreement: string;
31
+ apiKey: string;
32
+ overseas: string;
33
+ };
34
+ };