@sophonsai/agent-embed-core 0.1.0 → 0.2.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.
- package/README.md +1 -1
- package/dist/index.d.mts +12 -37
- package/dist/index.mjs +4 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,4 +6,4 @@ Core 不包含面板挂载、生命周期管理或主题 preset 等产品配置
|
|
|
6
6
|
|
|
7
7
|
该包是 SDK 和框架适配包的底层依赖。业务项目通常应安装 SDK 或 React/Vue 适配包,不需要直接依赖 Core。
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
iframe 初始化消息使用 `{ mode: "url", appearance, threadId? }` 配置外观和初始会话。WebAPI 根据 iframe 路径中的应用接入凭证解析智能体和访问身份。
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
//#region src/types.d.ts
|
|
2
2
|
declare const AGENT_EMBED_QUERY_PARAMS: {
|
|
3
|
-
readonly agentId: "agent_id";
|
|
4
3
|
readonly threadId: "thread_id";
|
|
5
|
-
readonly token: "token";
|
|
6
4
|
readonly theme: "theme";
|
|
7
5
|
readonly fontSize: "font_size";
|
|
8
6
|
readonly headerHistoryButton: "header_history_button";
|
|
@@ -45,8 +43,6 @@ interface AgentTextPayload {
|
|
|
45
43
|
interface AgentSessionRunEventContext {
|
|
46
44
|
runId: string;
|
|
47
45
|
threadId: string | null;
|
|
48
|
-
objectType: 'model' | 'agent' | 'knowledge_base' | 'database' | 'file';
|
|
49
|
-
objectId: string;
|
|
50
46
|
step: number;
|
|
51
47
|
parentToolCallId: string | null;
|
|
52
48
|
}
|
|
@@ -86,12 +82,17 @@ interface AgentToolCallCancelledEvent {
|
|
|
86
82
|
}
|
|
87
83
|
type AgentToolCall = AgentToolCallStartedEvent & ({
|
|
88
84
|
kind: 'tool';
|
|
89
|
-
executor: 'server';
|
|
85
|
+
executor: 'server' | 'client';
|
|
90
86
|
} | {
|
|
91
87
|
kind: 'action';
|
|
92
88
|
executor: 'client';
|
|
93
89
|
});
|
|
94
90
|
interface AgentToolCallCreatedEvent {
|
|
91
|
+
toolCallId: string;
|
|
92
|
+
toolName: string;
|
|
93
|
+
icon?: string;
|
|
94
|
+
}
|
|
95
|
+
interface AgentToolCallReadyEvent {
|
|
95
96
|
toolCall: AgentToolCall;
|
|
96
97
|
dependsOn?: {
|
|
97
98
|
toolCallId: string;
|
|
@@ -163,6 +164,7 @@ interface AgentEvents {
|
|
|
163
164
|
onEvent?: (event: AgentServerEvent) => void;
|
|
164
165
|
onSessionContextReady?: (context: AgentSessionContext) => void;
|
|
165
166
|
onToolCallCreated?: (event: AgentToolCallCreatedEvent, context: AgentSessionEventContext) => void;
|
|
167
|
+
onToolCallReady?: (event: AgentToolCallReadyEvent, context: AgentSessionEventContext) => void;
|
|
166
168
|
onToolApprovalRequested?: (event: AgentToolApprovalRequestedEvent, context: AgentSessionEventContext) => void;
|
|
167
169
|
onToolCallStarted?: (event: AgentToolCallStartedEvent, context: AgentSessionEventContext) => void;
|
|
168
170
|
onToolCallProgressUpdated?: (event: AgentToolCallProgressUpdatedEvent, context: AgentSessionEventContext) => void;
|
|
@@ -170,6 +172,7 @@ interface AgentEvents {
|
|
|
170
172
|
onToolCallSucceeded?: (event: AgentToolCallSucceededEvent, context: AgentSessionEventContext) => void;
|
|
171
173
|
onToolCallFailed?: (event: AgentToolCallFailedEvent, context: AgentSessionEventContext) => void;
|
|
172
174
|
onToolCallCancelled?: (event: AgentToolCallCancelledEvent, context: AgentSessionEventContext) => void;
|
|
175
|
+
onClientToolRequest?: (event: AgentToolCallStartedEvent, context: AgentSessionEventContext) => void;
|
|
173
176
|
onClientActionRequest?: (event: AgentClientActionRequestEvent, context: AgentSessionEventContext) => void;
|
|
174
177
|
onUserFeedbackConsumed?: (event: AgentUserFeedbackConsumedEvent, context: AgentSessionEventContext) => void;
|
|
175
178
|
onUserSteerConsumed?: (event: AgentUserSteerConsumedEvent, context: AgentSessionEventContext) => void;
|
|
@@ -188,20 +191,7 @@ interface AgentEvents {
|
|
|
188
191
|
onCancelled?: (result: AgentSessionCancelled) => void;
|
|
189
192
|
onSettled?: (result: AgentSessionSettlement) => void;
|
|
190
193
|
}
|
|
191
|
-
declare const AGENT_EVENT_NAMES: readonly ["onConcurrentSend", "onEvent", "onSessionContextReady", "onToolCallCreated", "onToolApprovalRequested", "onToolCallStarted", "onToolCallProgressUpdated", "onToolCallBackgrounded", "onToolCallSucceeded", "onToolCallFailed", "onToolCallCancelled", "onClientActionRequest", "onUserFeedbackConsumed", "onUserSteerConsumed", "onUserSteerCancelled", "onUserInputSubmitted", "onSessionTurnStarted", "onSessionTurnSucceeded", "onSessionTurnFailed", "onSessionTurnCancelled", "onSessionRunStarted", "onSessionRunIdled", "onSessionRunEnded", "onSystemMessageConsumed", "onSuccess", "onError", "onCancelled", "onSettled"];
|
|
192
|
-
interface AgentEmbedPlatformUserAuth {
|
|
193
|
-
type: 'platform.user.credential';
|
|
194
|
-
credential: string;
|
|
195
|
-
}
|
|
196
|
-
interface AgentEmbedExtensionUserAuth {
|
|
197
|
-
type: 'extension.user.identity';
|
|
198
|
-
appId: string;
|
|
199
|
-
externalUser: {
|
|
200
|
-
id: string;
|
|
201
|
-
name?: string;
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
type AgentEmbedAuth = AgentEmbedPlatformUserAuth | AgentEmbedExtensionUserAuth;
|
|
194
|
+
declare const AGENT_EVENT_NAMES: readonly ["onConcurrentSend", "onEvent", "onSessionContextReady", "onToolCallCreated", "onToolCallReady", "onToolApprovalRequested", "onToolCallStarted", "onToolCallProgressUpdated", "onToolCallBackgrounded", "onToolCallSucceeded", "onToolCallFailed", "onToolCallCancelled", "onClientToolRequest", "onClientActionRequest", "onUserFeedbackConsumed", "onUserSteerConsumed", "onUserSteerCancelled", "onUserInputSubmitted", "onSessionTurnStarted", "onSessionTurnSucceeded", "onSessionTurnFailed", "onSessionTurnCancelled", "onSessionRunStarted", "onSessionRunIdled", "onSessionRunEnded", "onSystemMessageConsumed", "onSuccess", "onError", "onCancelled", "onSettled"];
|
|
205
195
|
interface AgentEmbedSendMessageInput {
|
|
206
196
|
text: string;
|
|
207
197
|
}
|
|
@@ -222,33 +212,18 @@ interface AgentEmbedInitError {
|
|
|
222
212
|
code: 'invalid_token' | 'forbidden' | 'agent_not_found' | 'request_failed' | 'frame_load_failed';
|
|
223
213
|
message: string;
|
|
224
214
|
}
|
|
225
|
-
interface AgentEmbedInitConfig {
|
|
226
|
-
agentId: string;
|
|
227
|
-
auth: AgentEmbedAuth;
|
|
228
|
-
/** @deprecated Bridge compatibility for token-mode clients and frames. */
|
|
229
|
-
token?: string;
|
|
230
|
-
threadId?: string;
|
|
231
|
-
appearance: AgentAppearance;
|
|
232
|
-
}
|
|
233
|
-
interface AgentEmbedLegacyInitConfig {
|
|
234
|
-
agentId: string;
|
|
235
|
-
token: string;
|
|
236
|
-
auth?: never;
|
|
237
|
-
threadId?: string;
|
|
238
|
-
appearance: AgentAppearance;
|
|
239
|
-
}
|
|
240
215
|
/** URL mode config carries appearance and session context, never platform credentials. */
|
|
241
216
|
type AgentRuntimeValue = string | number | boolean | null | AgentRuntimeValue[] | AgentRuntimeVariables;
|
|
242
217
|
interface AgentRuntimeVariables {
|
|
243
218
|
[key: string]: AgentRuntimeValue;
|
|
244
219
|
}
|
|
245
220
|
interface AgentEmbedUrlInitConfig {
|
|
221
|
+
client_tool_names?: string[];
|
|
246
222
|
mode: 'url';
|
|
247
223
|
runtime_variables?: AgentRuntimeVariables;
|
|
248
224
|
threadId?: string;
|
|
249
225
|
appearance: AgentAppearance;
|
|
250
226
|
}
|
|
251
|
-
type AgentEmbedBridgeConfig = AgentEmbedInitConfig | AgentEmbedUrlInitConfig;
|
|
252
227
|
//#endregion
|
|
253
228
|
//#region src/protocol.d.ts
|
|
254
229
|
declare const AGENT_EMBED_BRIDGE = "sophonsai/agent-component-bridge";
|
|
@@ -260,7 +235,7 @@ interface AgentEmbedInitMessage {
|
|
|
260
235
|
version: typeof AGENT_EMBED_BRIDGE_VERSION;
|
|
261
236
|
type: 'init';
|
|
262
237
|
instanceId: string;
|
|
263
|
-
config:
|
|
238
|
+
config: AgentEmbedUrlInitConfig;
|
|
264
239
|
}
|
|
265
240
|
interface AgentEmbedCommandMessage {
|
|
266
241
|
bridge: typeof AGENT_EMBED_BRIDGE;
|
|
@@ -296,4 +271,4 @@ declare const isAgentRuntimeVariables: (value: unknown) => value is AgentRuntime
|
|
|
296
271
|
declare const isAgentEmbedHostMessage: (value: unknown) => value is AgentEmbedHostMessage;
|
|
297
272
|
declare const isAgentEmbedFrameMessage: (value: unknown) => value is AgentEmbedFrameMessage;
|
|
298
273
|
//#endregion
|
|
299
|
-
export { AGENT_EMBED_BRIDGE, AGENT_EMBED_BRIDGE_VERSION, AGENT_EMBED_QUERY_PARAMS, AGENT_EVENT_NAMES, AgentAppearance, AgentClientActionRequestEvent, AgentEmbedAction, AgentEmbedAppearanceUpdate,
|
|
274
|
+
export { AGENT_EMBED_BRIDGE, AGENT_EMBED_BRIDGE_VERSION, AGENT_EMBED_QUERY_PARAMS, AGENT_EVENT_NAMES, AgentAppearance, AgentClientActionRequestEvent, AgentEmbedAction, AgentEmbedAppearanceUpdate, AgentEmbedCallback, AgentEmbedCommandMessage, AgentEmbedFrameMessage, AgentEmbedHeaderAppearance, AgentEmbedHostMessage, AgentEmbedInitError, AgentEmbedInitMessage, AgentEmbedInputQuery, AgentEmbedInstance, AgentEmbedSendMessageInput, AgentEmbedTheme, AgentEmbedUpdateAppearanceMessage, AgentEmbedUrlInitConfig, AgentEvents, AgentRuntimeValue, AgentRuntimeVariables, AgentServerEvent, AgentSessionCancelled, AgentSessionContext, AgentSessionEventContext, AgentSessionFailure, AgentSessionRunEndedEvent, AgentSessionRunEventContext, AgentSessionRunIdledEvent, AgentSessionRunStartedEvent, AgentSessionSettlement, AgentSessionSuccess, AgentSessionTurnCancelledEvent, AgentSessionTurnFailedEvent, AgentSessionTurnStartedEvent, AgentSessionTurnSucceededEvent, AgentSystemMessageConsumedEvent, AgentTextPayload, AgentToolApprovalRequestedEvent, AgentToolCall, AgentToolCallBackgroundedEvent, AgentToolCallCancelledEvent, AgentToolCallCreatedEvent, AgentToolCallFailedEvent, AgentToolCallProgressUpdatedEvent, AgentToolCallReadyEvent, AgentToolCallStartedEvent, AgentToolCallSucceededEvent, AgentUserFeedbackConsumedEvent, AgentUserInputSubmittedEvent, AgentUserSteerCancelledEvent, AgentUserSteerConsumedEvent, isAgentEmbedFrameMessage, isAgentEmbedHostMessage, isAgentRuntimeVariables };
|
package/dist/index.mjs
CHANGED
|
@@ -22,15 +22,8 @@ const isAgentEmbedHostMessage = (value) => {
|
|
|
22
22
|
if (message.bridge !== "sophonsai/agent-component-bridge" || message.version !== 1 || typeof message.instanceId !== "string") return false;
|
|
23
23
|
if (message.type === "init") {
|
|
24
24
|
const config = message.config;
|
|
25
|
-
if (config?.mode === "url") return Boolean(config.appearance && typeof config.appearance === "object" && (config.threadId === void 0 || typeof config.threadId === "string") && (config.runtime_variables === void 0 || isAgentRuntimeVariables(config.runtime_variables)));
|
|
26
|
-
|
|
27
|
-
if (!config.auth) return typeof config.token === "string";
|
|
28
|
-
if (typeof config.auth !== "object") return false;
|
|
29
|
-
const auth = config.auth;
|
|
30
|
-
if (auth.type === "platform.user.credential") return typeof auth.credential === "string";
|
|
31
|
-
if (auth.type !== "extension.user.identity") return false;
|
|
32
|
-
const externalUser = auth.externalUser;
|
|
33
|
-
return Boolean(typeof auth.appId === "string" && externalUser && typeof externalUser === "object" && typeof externalUser.id === "string" && (externalUser.name === void 0 || typeof externalUser.name === "string"));
|
|
25
|
+
if (config?.mode === "url") return Boolean(config.appearance && typeof config.appearance === "object" && (config.threadId === void 0 || typeof config.threadId === "string") && (config.runtime_variables === void 0 || isAgentRuntimeVariables(config.runtime_variables)) && (config.client_tool_names === void 0 || Array.isArray(config.client_tool_names) && config.client_tool_names.every((name) => typeof name === "string" && name.length > 0)));
|
|
26
|
+
return false;
|
|
34
27
|
}
|
|
35
28
|
if (message.type === "update-appearance") {
|
|
36
29
|
const appearance = message.appearance;
|
|
@@ -84,9 +77,7 @@ const isAgentEmbedFrameMessage = (value) => {
|
|
|
84
77
|
//#endregion
|
|
85
78
|
//#region src/types.ts
|
|
86
79
|
const AGENT_EMBED_QUERY_PARAMS = {
|
|
87
|
-
agentId: "agent_id",
|
|
88
80
|
threadId: "thread_id",
|
|
89
|
-
token: "token",
|
|
90
81
|
theme: "theme",
|
|
91
82
|
fontSize: "font_size",
|
|
92
83
|
headerHistoryButton: "header_history_button",
|
|
@@ -98,6 +89,7 @@ const AGENT_EVENT_NAMES = [
|
|
|
98
89
|
"onEvent",
|
|
99
90
|
"onSessionContextReady",
|
|
100
91
|
"onToolCallCreated",
|
|
92
|
+
"onToolCallReady",
|
|
101
93
|
"onToolApprovalRequested",
|
|
102
94
|
"onToolCallStarted",
|
|
103
95
|
"onToolCallProgressUpdated",
|
|
@@ -105,6 +97,7 @@ const AGENT_EVENT_NAMES = [
|
|
|
105
97
|
"onToolCallSucceeded",
|
|
106
98
|
"onToolCallFailed",
|
|
107
99
|
"onToolCallCancelled",
|
|
100
|
+
"onClientToolRequest",
|
|
108
101
|
"onClientActionRequest",
|
|
109
102
|
"onUserFeedbackConsumed",
|
|
110
103
|
"onUserSteerConsumed",
|