coze_lab 0.1.28 → 0.1.30
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/index.js
CHANGED
|
@@ -5848,17 +5848,47 @@ async function verifyOpenClawTraceLink(cloud) {
|
|
|
5848
5848
|
return { success: false, status: 0, body: 'plugin authorization missing' };
|
|
5849
5849
|
}
|
|
5850
5850
|
|
|
5851
|
-
// 1) 用插件【实际配置的】token
|
|
5851
|
+
// 1) 用插件【实际配置的】token 打一条最小 OTLP trace ——这才是运行时真实用的那个 token。
|
|
5852
|
+
// 不能发空 resourceSpans,CozeLoop 会返回 "unknown event type",导致自检假失败。
|
|
5852
5853
|
const authHeader = pcfg.authorization; // 形如 "Bearer czu_xxx"
|
|
5853
5854
|
const tracesUrl = (pcfg.endpoint
|
|
5854
5855
|
? `${String(pcfg.endpoint).replace(/\/+$/, '')}/v1/traces`
|
|
5855
5856
|
: getOtelTracesUrl(cloud));
|
|
5856
5857
|
const workspaceId = pcfg.workspaceId || WORKSPACE_ID;
|
|
5858
|
+
const traceId = crypto.randomBytes(16).toString('hex');
|
|
5859
|
+
const spanId = crypto.randomBytes(8).toString('hex');
|
|
5860
|
+
const nowNs = String(Date.now() * 1_000_000);
|
|
5861
|
+
const pair = crypto.randomBytes(6).toString('hex');
|
|
5862
|
+
const otlpBody = {
|
|
5863
|
+
resourceSpans: [{
|
|
5864
|
+
resource: {
|
|
5865
|
+
attributes: [
|
|
5866
|
+
{ key: 'service.name', value: { stringValue: 'cozelab-onboard-openclaw' } },
|
|
5867
|
+
],
|
|
5868
|
+
},
|
|
5869
|
+
scopeSpans: [{
|
|
5870
|
+
scope: { name: 'cozelab-onboard-openclaw-selfcheck' },
|
|
5871
|
+
spans: [{
|
|
5872
|
+
traceId,
|
|
5873
|
+
spanId,
|
|
5874
|
+
name: 'cozelab-onboard-openclaw-selfcheck',
|
|
5875
|
+
kind: 1,
|
|
5876
|
+
startTimeUnixNano: nowNs,
|
|
5877
|
+
endTimeUnixNano: nowNs,
|
|
5878
|
+
status: { code: 1 },
|
|
5879
|
+
attributes: [
|
|
5880
|
+
{ key: 'pair_code', value: { stringValue: pair } },
|
|
5881
|
+
{ key: 'source', value: { stringValue: 'cozelab-onboard-openclaw' } },
|
|
5882
|
+
],
|
|
5883
|
+
}],
|
|
5884
|
+
}],
|
|
5885
|
+
}],
|
|
5886
|
+
};
|
|
5857
5887
|
let res;
|
|
5858
5888
|
try {
|
|
5859
5889
|
res = await httpsPost(
|
|
5860
5890
|
tracesUrl,
|
|
5861
|
-
|
|
5891
|
+
otlpBody,
|
|
5862
5892
|
{ Authorization: authHeader, 'cozeloop-workspace-id': String(workspaceId) },
|
|
5863
5893
|
);
|
|
5864
5894
|
} catch (e) {
|
package/package.json
CHANGED
|
@@ -871,28 +871,27 @@ const cozeloopTracePlugin = {
|
|
|
871
871
|
if (!role && event.from) {
|
|
872
872
|
role = "user";
|
|
873
873
|
}
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
if (!ctx.userInput) {
|
|
889
|
-
ctx.userInput = event.content;
|
|
890
|
-
}
|
|
891
|
-
if (!lastUserTraceContext) {
|
|
892
|
-
lastUserTraceContext = ctx;
|
|
893
|
-
lastUserChannelId = channelId;
|
|
874
|
+
// coze-context 缓存对【所有 channel】生效,含 agent/ channel(Coze 群聊真实
|
|
875
|
+
// 链路 channelId=agent/main:<session>)。此前只在 isNonAgentChannel 分支缓存,
|
|
876
|
+
// 导致群聊消息的 <coze-context>(message_id/group_id 等)被整体跳过、root span
|
|
877
|
+
// 拿不到 coze tag。parseCozeContext 解析不到时返回空、无副作用,故无条件 remember 安全。
|
|
878
|
+
if (role === "user" || !role) {
|
|
879
|
+
lastUserChannelId = channelId;
|
|
880
|
+
lastUserTraceContext = ctx;
|
|
881
|
+
ctx.userInput = event.content;
|
|
882
|
+
lastUserInput = event.content;
|
|
883
|
+
rememberCozeContext(event.content, ctx.openclawSessionId || lastOpenclawSessionId);
|
|
884
|
+
if (config.debug) {
|
|
885
|
+
api.logger.info(`[CozeloopTrace] Saved user context: channelId=${channelId}, traceId=${ctx.traceId}`);
|
|
894
886
|
}
|
|
895
887
|
}
|
|
888
|
+
if (!ctx.userInput) {
|
|
889
|
+
ctx.userInput = event.content;
|
|
890
|
+
}
|
|
891
|
+
if (!lastUserTraceContext) {
|
|
892
|
+
lastUserTraceContext = ctx;
|
|
893
|
+
lastUserChannelId = channelId;
|
|
894
|
+
}
|
|
896
895
|
});
|
|
897
896
|
}
|
|
898
897
|
if (shouldHookEnabled("message_sending")) {
|