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 ingest(空 spans)——这才是运行时真实用的那个 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
- { resourceSpans: [] },
5891
+ otlpBody,
5862
5892
  { Authorization: authHeader, 'cozeloop-workspace-id': String(workspaceId) },
5863
5893
  );
5864
5894
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coze_lab",
3
- "version": "0.1.28",
3
+ "version": "0.1.30",
4
4
  "description": "Configure local AI agents (Claude Code, Codex, OpenClaw) to report traces to CozeLoop",
5
5
  "keywords": [
6
6
  "cozeloop",
@@ -871,28 +871,27 @@ const cozeloopTracePlugin = {
871
871
  if (!role && event.from) {
872
872
  role = "user";
873
873
  }
874
- const isNonAgentChannel = !rawChannelId.startsWith("agent/");
875
- if (isNonAgentChannel) {
876
- if (role === "user" || !role) {
877
- lastUserChannelId = channelId;
878
- lastUserTraceContext = ctx;
879
- ctx.userInput = event.content;
880
- lastUserInput = event.content;
881
- // Cache any coze-context as soon as we see the user input,
882
- // so later /loop turns (which carry none) can inherit it.
883
- rememberCozeContext(event.content, ctx.openclawSessionId || lastOpenclawSessionId);
884
- if (config.debug) {
885
- api.logger.info(`[CozeloopTrace] Saved user context: channelId=${channelId}, traceId=${ctx.traceId}`);
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")) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "openclaw-cozeloop-trace",
3
3
  "name": "OpenClaw CozeLoop Trace",
4
- "version": "0.1.13",
4
+ "version": "0.1.14",
5
5
  "description": "Report OpenClaw execution traces to CozeLoop via OpenTelemetry",
6
6
  "type": "plugin",
7
7
  "entry": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cozeloop/openclaw-cozeloop-trace",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "description": "OpenClaw Plugin for reporting traces to CozeLoop via OpenTelemetry",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",