@xfxstudio/claworld 2026.4.16-testing.1 → 2026.4.16-testing.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.
- package/README.md +3 -3
- package/index.js +50 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +4 -1
- package/setup-entry.js +6 -0
- package/skills/claworld-a2a-channel-agent/SKILL.md +218 -0
- package/skills/claworld-help/SKILL.md +304 -0
- package/skills/claworld-join-and-chat/SKILL.md +526 -0
- package/skills/claworld-manage-worlds/SKILL.md +292 -0
- package/skills/claworld-manage-worlds/references/world-context-templates.md +145 -0
- package/src/lib/chat-request.js +366 -0
- package/src/lib/public-identity.js +175 -0
- package/src/lib/relay/agent-readable-markdown.js +385 -0
- package/src/lib/relay/kickoff-progress.js +162 -0
- package/src/lib/relay/kickoff-text.js +191 -0
- package/src/lib/relay/shared.js +30 -0
- package/src/lib/runtime-errors.js +149 -0
- package/src/openclaw/index.js +51 -0
- package/src/openclaw/plugin/account-identity.js +73 -0
- package/src/openclaw/plugin/claworld-channel-plugin.js +3499 -0
- package/src/openclaw/plugin/config-schema.js +392 -0
- package/src/openclaw/plugin/lifecycle.js +114 -0
- package/src/openclaw/plugin/managed-config.js +1054 -0
- package/src/openclaw/plugin/onboarding.js +312 -0
- package/src/openclaw/plugin/register-tooling.js +728 -0
- package/src/openclaw/plugin/register.js +1616 -0
- package/src/openclaw/plugin/relay-client-shared.js +146 -0
- package/src/openclaw/plugin/relay-client.js +1469 -0
- package/src/openclaw/plugin/runtime-backup.js +105 -0
- package/src/openclaw/plugin/runtime.js +12 -0
- package/src/openclaw/plugin-version.js +67 -0
- package/src/openclaw/protocol/relay-event-protocol.js +43 -0
- package/src/openclaw/runtime/backend-error-context.js +91 -0
- package/src/openclaw/runtime/canonical-result-builder.js +126 -0
- package/src/openclaw/runtime/demo-session-bootstrap.js +32 -0
- package/src/openclaw/runtime/feedback-helper.js +145 -0
- package/src/openclaw/runtime/inbound-session-router.js +44 -0
- package/src/openclaw/runtime/outbound-session-bridge.js +29 -0
- package/src/openclaw/runtime/product-shell-helper.js +931 -0
- package/src/openclaw/runtime/runtime-path.js +19 -0
- package/src/openclaw/runtime/system-message-orchestrator.js +1 -0
- package/src/openclaw/runtime/tool-contracts.js +939 -0
- package/src/openclaw/runtime/tool-inventory.js +83 -0
- package/src/openclaw/runtime/world-membership-helper.js +320 -0
- package/src/openclaw/runtime/world-moderation-helper.js +508 -0
- package/src/product-shell/contracts/chat-request-approval-policy.js +93 -0
- package/src/product-shell/contracts/world-orchestration.js +734 -0
- package/src/product-shell/orchestration/world-conversation-text.js +229 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { renderAcceptedChatKickoffMarkdown } from './agent-readable-markdown.js';
|
|
2
|
+
|
|
3
|
+
export const ACCEPTED_CHAT_KICKOFF_PAYLOAD_KIND = 'accepted_chat_kickoff';
|
|
4
|
+
|
|
5
|
+
function normalizeText(value, fallback = null) {
|
|
6
|
+
if (value == null) return fallback;
|
|
7
|
+
const normalized = String(value).trim();
|
|
8
|
+
return normalized || fallback;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function cloneJsonObject(value) {
|
|
12
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
13
|
+
try {
|
|
14
|
+
const cloned = JSON.parse(JSON.stringify(value));
|
|
15
|
+
if (!cloned || typeof cloned !== 'object' || Array.isArray(cloned)) return null;
|
|
16
|
+
return cloned;
|
|
17
|
+
} catch {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function normalizeKickoffPayload(input) {
|
|
23
|
+
return cloneJsonObject(input);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function normalizeKickoffSource(value, fallback = 'chat_request_brief') {
|
|
27
|
+
return normalizeText(value, fallback);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function projectKickoffBrief(input = null) {
|
|
31
|
+
if (!input || typeof input !== 'object' || Array.isArray(input)) return null;
|
|
32
|
+
const normalized = createKickoffBrief({
|
|
33
|
+
text: input.text,
|
|
34
|
+
payload: input.payload,
|
|
35
|
+
source: input.source,
|
|
36
|
+
});
|
|
37
|
+
if (!normalized) return null;
|
|
38
|
+
|
|
39
|
+
const payload = normalized.payload && typeof normalized.payload === 'object' && !Array.isArray(normalized.payload)
|
|
40
|
+
? cloneJsonObject(normalized.payload)
|
|
41
|
+
: null;
|
|
42
|
+
if (payload?.text === normalized.text) delete payload.text;
|
|
43
|
+
if (payload?.source === normalized.source) delete payload.source;
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
...(normalized.text ? { text: normalized.text } : {}),
|
|
47
|
+
...(payload && Object.keys(payload).length > 0 ? { payload } : {}),
|
|
48
|
+
...(normalized.source && normalized.source !== 'chat_request_brief' ? { source: normalized.source } : {}),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function createKickoffBrief({
|
|
53
|
+
text = null,
|
|
54
|
+
payload = null,
|
|
55
|
+
source = 'chat_request_brief',
|
|
56
|
+
} = {}) {
|
|
57
|
+
const normalizedPayload = normalizeKickoffPayload(payload);
|
|
58
|
+
const normalizedText = normalizeText(text, normalizeText(normalizedPayload?.text, null));
|
|
59
|
+
if (!normalizedText && !normalizedPayload) return null;
|
|
60
|
+
const hasPayloadText = typeof normalizedPayload?.text === 'string' && normalizedPayload.text.trim().length > 0;
|
|
61
|
+
return {
|
|
62
|
+
...(normalizedText ? { text: normalizedText } : {}),
|
|
63
|
+
...(normalizedPayload ? {
|
|
64
|
+
payload: {
|
|
65
|
+
...normalizedPayload,
|
|
66
|
+
...(normalizedText && !hasPayloadText ? { text: normalizedText } : {}),
|
|
67
|
+
},
|
|
68
|
+
} : {}),
|
|
69
|
+
source: normalizeKickoffSource(source),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function resolveStoredKickoffBrief(requestContext = {}) {
|
|
74
|
+
if (!requestContext || typeof requestContext !== 'object' || Array.isArray(requestContext)) return null;
|
|
75
|
+
|
|
76
|
+
const kickoffBrief = requestContext.kickoffBrief && typeof requestContext.kickoffBrief === 'object' && !Array.isArray(requestContext.kickoffBrief)
|
|
77
|
+
? requestContext.kickoffBrief
|
|
78
|
+
: null;
|
|
79
|
+
if (kickoffBrief) {
|
|
80
|
+
return createKickoffBrief({
|
|
81
|
+
text: kickoffBrief.text,
|
|
82
|
+
payload: kickoffBrief.payload,
|
|
83
|
+
source: kickoffBrief.source,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return createKickoffBrief({
|
|
88
|
+
text: normalizeText(requestContext.openingPayload?.text, normalizeText(requestContext.message, null)),
|
|
89
|
+
payload: requestContext.openingPayload,
|
|
90
|
+
source: requestContext.openingPayload?.source || 'chat_request_opening',
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function resolveAcceptedChatKickoffViewer(bundle = {}, {
|
|
95
|
+
localAgentId = null,
|
|
96
|
+
fallback = 'recipient',
|
|
97
|
+
} = {}) {
|
|
98
|
+
const normalizedLocalAgentId = normalizeText(localAgentId, null);
|
|
99
|
+
const participants = bundle?.participants && typeof bundle.participants === 'object' && !Array.isArray(bundle.participants)
|
|
100
|
+
? bundle.participants
|
|
101
|
+
: {};
|
|
102
|
+
const senderAgentId = normalizeText(participants.sender?.agentId, null);
|
|
103
|
+
const recipientAgentId = normalizeText(participants.recipient?.agentId, null);
|
|
104
|
+
|
|
105
|
+
if (normalizedLocalAgentId && normalizedLocalAgentId === senderAgentId) return 'sender';
|
|
106
|
+
if (normalizedLocalAgentId && normalizedLocalAgentId === recipientAgentId) return 'recipient';
|
|
107
|
+
return fallback === 'sender' ? 'sender' : 'recipient';
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function buildAcceptedChatKickoffRuntimeContext(bundle = {}, { viewer = 'recipient' } = {}) {
|
|
111
|
+
const resolvedViewer = viewer === 'sender' ? 'sender' : 'recipient';
|
|
112
|
+
const requestContext = bundle.requestContext && typeof bundle.requestContext === 'object' && !Array.isArray(bundle.requestContext)
|
|
113
|
+
? bundle.requestContext
|
|
114
|
+
: {};
|
|
115
|
+
const request = bundle.request && typeof bundle.request === 'object' && !Array.isArray(bundle.request)
|
|
116
|
+
? bundle.request
|
|
117
|
+
: {};
|
|
118
|
+
const brief = requestContext.brief && typeof requestContext.brief === 'object' && !Array.isArray(requestContext.brief)
|
|
119
|
+
? requestContext.brief
|
|
120
|
+
: request.brief && typeof request.brief === 'object' && !Array.isArray(request.brief)
|
|
121
|
+
? request.brief
|
|
122
|
+
: {};
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
viewer: resolvedViewer,
|
|
126
|
+
text: formatAcceptedChatKickoffMessage(bundle, { viewer: resolvedViewer }),
|
|
127
|
+
briefText: normalizeText(brief.text, null),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function readAcceptedChatKickoffRuntimeContext(bundle = {}, { viewer = 'recipient' } = {}) {
|
|
132
|
+
const resolvedViewer = viewer === 'sender' ? 'sender' : 'recipient';
|
|
133
|
+
const requestContext = bundle.requestContext && typeof bundle.requestContext === 'object' && !Array.isArray(bundle.requestContext)
|
|
134
|
+
? bundle.requestContext
|
|
135
|
+
: {};
|
|
136
|
+
const request = bundle.request && typeof bundle.request === 'object' && !Array.isArray(bundle.request)
|
|
137
|
+
? bundle.request
|
|
138
|
+
: {};
|
|
139
|
+
const brief = requestContext.brief && typeof requestContext.brief === 'object' && !Array.isArray(requestContext.brief)
|
|
140
|
+
? requestContext.brief
|
|
141
|
+
: request.brief && typeof request.brief === 'object' && !Array.isArray(request.brief)
|
|
142
|
+
? request.brief
|
|
143
|
+
: {};
|
|
144
|
+
const runtimeContext = bundle.runtimeContext && typeof bundle.runtimeContext === 'object' && !Array.isArray(bundle.runtimeContext)
|
|
145
|
+
? bundle.runtimeContext
|
|
146
|
+
: {};
|
|
147
|
+
const candidate = runtimeContext[resolvedViewer] && typeof runtimeContext[resolvedViewer] === 'object' && !Array.isArray(runtimeContext[resolvedViewer])
|
|
148
|
+
? runtimeContext[resolvedViewer]
|
|
149
|
+
: null;
|
|
150
|
+
if (!candidate) return null;
|
|
151
|
+
|
|
152
|
+
const text = normalizeText(candidate.text, null);
|
|
153
|
+
if (!text) return null;
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
viewer: resolvedViewer,
|
|
157
|
+
text,
|
|
158
|
+
briefText: normalizeText(candidate.briefText, normalizeText(brief.text, null)),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function createAcceptedChatKickoffRuntimeContext(bundle = {}, { viewer = 'recipient' } = {}) {
|
|
163
|
+
return readAcceptedChatKickoffRuntimeContext(bundle, { viewer })
|
|
164
|
+
|| buildAcceptedChatKickoffRuntimeContext(bundle, { viewer });
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function createAcceptedChatKickoffRuntimeContexts(bundle = {}) {
|
|
168
|
+
return {
|
|
169
|
+
sender: buildAcceptedChatKickoffRuntimeContext(bundle, { viewer: 'sender' }),
|
|
170
|
+
recipient: buildAcceptedChatKickoffRuntimeContext(bundle, { viewer: 'recipient' }),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function createAcceptedChatKickoffRuntimeContextForAgent(bundle = {}, {
|
|
175
|
+
localAgentId = null,
|
|
176
|
+
fallback = 'recipient',
|
|
177
|
+
} = {}) {
|
|
178
|
+
return createAcceptedChatKickoffRuntimeContext(bundle, {
|
|
179
|
+
viewer: resolveAcceptedChatKickoffViewer(bundle, {
|
|
180
|
+
localAgentId,
|
|
181
|
+
fallback,
|
|
182
|
+
}),
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function formatAcceptedChatKickoffMessage(bundle = {}, { viewer = 'recipient' } = {}) {
|
|
187
|
+
return renderAcceptedChatKickoffMarkdown(
|
|
188
|
+
cloneJsonObject(bundle) || {},
|
|
189
|
+
{ viewer: viewer === 'sender' ? 'sender' : 'recipient' },
|
|
190
|
+
);
|
|
191
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export function normalizePositiveInteger(value, fallback) {
|
|
2
|
+
const normalized = Number(value);
|
|
3
|
+
if (!Number.isFinite(normalized) || normalized <= 0) return fallback;
|
|
4
|
+
return Math.floor(normalized);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function normalizeOptionalText(value) {
|
|
8
|
+
if (typeof value !== 'string') return null;
|
|
9
|
+
const normalized = value.trim();
|
|
10
|
+
return normalized || null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function cloneJsonObject(value) {
|
|
14
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
15
|
+
try {
|
|
16
|
+
const cloned = JSON.parse(JSON.stringify(value));
|
|
17
|
+
if (!cloned || typeof cloned !== 'object' || Array.isArray(cloned)) return null;
|
|
18
|
+
return cloned;
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function buildFailureBody(reason, extras = {}) {
|
|
25
|
+
return {
|
|
26
|
+
error: reason,
|
|
27
|
+
reason,
|
|
28
|
+
...extras,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
const DEFAULT_STATUS_BY_CATEGORY = {
|
|
2
|
+
auth: 401,
|
|
3
|
+
bootstrap: 500,
|
|
4
|
+
config: 400,
|
|
5
|
+
conflict: 409,
|
|
6
|
+
input: 400,
|
|
7
|
+
policy: 403,
|
|
8
|
+
runtime: 500,
|
|
9
|
+
transport: 502,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function inferFallbackCode(error) {
|
|
13
|
+
const code = typeof error?.code === 'string' ? error.code.trim() : '';
|
|
14
|
+
if (!code) return null;
|
|
15
|
+
return code.toLowerCase();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function normalizeContext(context = null) {
|
|
19
|
+
if (!context || typeof context !== 'object' || Array.isArray(context)) return null;
|
|
20
|
+
return context;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class RuntimeBoundaryError extends Error {
|
|
24
|
+
constructor({
|
|
25
|
+
code = 'internal_runtime_error',
|
|
26
|
+
category = 'runtime',
|
|
27
|
+
status = null,
|
|
28
|
+
message = 'internal runtime error',
|
|
29
|
+
publicMessage = null,
|
|
30
|
+
recoverable = false,
|
|
31
|
+
context = null,
|
|
32
|
+
cause = null,
|
|
33
|
+
} = {}) {
|
|
34
|
+
super(message, cause ? { cause } : undefined);
|
|
35
|
+
this.name = 'RuntimeBoundaryError';
|
|
36
|
+
this.code = code;
|
|
37
|
+
this.category = category;
|
|
38
|
+
this.status = status ?? DEFAULT_STATUS_BY_CATEGORY[category] ?? 500;
|
|
39
|
+
this.publicMessage = publicMessage || null;
|
|
40
|
+
this.recoverable = Boolean(recoverable);
|
|
41
|
+
this.context = normalizeContext(context);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function createRuntimeBoundaryError(options = {}) {
|
|
46
|
+
return new RuntimeBoundaryError(options);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function isRuntimeBoundaryError(error) {
|
|
50
|
+
return error instanceof RuntimeBoundaryError
|
|
51
|
+
|| (
|
|
52
|
+
error?.name === 'RuntimeBoundaryError'
|
|
53
|
+
&& typeof error?.code === 'string'
|
|
54
|
+
&& typeof error?.category === 'string'
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function normalizeRuntimeBoundaryError(error, fallback = {}) {
|
|
59
|
+
if (isRuntimeBoundaryError(error)) {
|
|
60
|
+
if (fallback?.context && !error.context) {
|
|
61
|
+
error.context = normalizeContext(fallback.context);
|
|
62
|
+
}
|
|
63
|
+
return error;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return new RuntimeBoundaryError({
|
|
67
|
+
code: fallback.code || inferFallbackCode(error) || 'internal_runtime_error',
|
|
68
|
+
category: fallback.category || 'runtime',
|
|
69
|
+
status: fallback.status ?? null,
|
|
70
|
+
message: fallback.message || error?.message || String(error || 'internal runtime error'),
|
|
71
|
+
publicMessage: fallback.publicMessage || null,
|
|
72
|
+
recoverable: fallback.recoverable === true,
|
|
73
|
+
context: fallback.context || null,
|
|
74
|
+
cause: error || null,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function serializeCause(error) {
|
|
79
|
+
const cause = error?.cause;
|
|
80
|
+
if (!cause || cause === error) return null;
|
|
81
|
+
return {
|
|
82
|
+
name: cause?.name || null,
|
|
83
|
+
code: typeof cause?.code === 'string' ? cause.code : null,
|
|
84
|
+
message: cause?.message || String(cause),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function serializeRuntimeBoundaryError(error, { includeStack = false } = {}) {
|
|
89
|
+
const normalized = normalizeRuntimeBoundaryError(error);
|
|
90
|
+
const payload = {
|
|
91
|
+
name: normalized.name,
|
|
92
|
+
code: normalized.code,
|
|
93
|
+
category: normalized.category,
|
|
94
|
+
status: normalized.status,
|
|
95
|
+
recoverable: normalized.recoverable,
|
|
96
|
+
message: normalized.message,
|
|
97
|
+
publicMessage: normalized.publicMessage || null,
|
|
98
|
+
context: normalized.context || null,
|
|
99
|
+
cause: serializeCause(normalized),
|
|
100
|
+
};
|
|
101
|
+
if (includeStack && normalized.stack) {
|
|
102
|
+
payload.stack = normalized.stack;
|
|
103
|
+
}
|
|
104
|
+
return payload;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function buildPublicErrorPayload(
|
|
108
|
+
error,
|
|
109
|
+
{
|
|
110
|
+
errorType = 'internal_runtime_error',
|
|
111
|
+
fallbackMessage = 'internal runtime error',
|
|
112
|
+
exposeMessage = false,
|
|
113
|
+
extra = null,
|
|
114
|
+
} = {},
|
|
115
|
+
) {
|
|
116
|
+
const normalized = normalizeRuntimeBoundaryError(error, {
|
|
117
|
+
code: errorType,
|
|
118
|
+
category: 'runtime',
|
|
119
|
+
message: fallbackMessage,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
error: errorType,
|
|
124
|
+
code: normalized.code,
|
|
125
|
+
category: normalized.category,
|
|
126
|
+
recoverable: normalized.recoverable,
|
|
127
|
+
message: exposeMessage ? (normalized.publicMessage || normalized.message) : (normalized.publicMessage || fallbackMessage),
|
|
128
|
+
...(extra && typeof extra === 'object' ? extra : {}),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function logRuntimeBoundary(
|
|
133
|
+
logger,
|
|
134
|
+
label,
|
|
135
|
+
error,
|
|
136
|
+
context = null,
|
|
137
|
+
{ includeStack = true, fallback = null } = {},
|
|
138
|
+
) {
|
|
139
|
+
const mergedContext = {
|
|
140
|
+
...normalizeContext(fallback?.context || null),
|
|
141
|
+
...normalizeContext(context),
|
|
142
|
+
};
|
|
143
|
+
const normalized = normalizeRuntimeBoundaryError(error, {
|
|
144
|
+
...(fallback || {}),
|
|
145
|
+
context: Object.keys(mergedContext).length > 0 ? mergedContext : null,
|
|
146
|
+
});
|
|
147
|
+
logger?.error?.(label, serializeRuntimeBoundaryError(normalized, { includeStack }));
|
|
148
|
+
return normalized;
|
|
149
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export { createClaworldChannelPlugin, claworldChannelPluginScaffold } from './plugin/claworld-channel-plugin.js';
|
|
2
|
+
export { registerClaworldPlugin, registerClaworldPluginFull } from './plugin/register.js';
|
|
3
|
+
export {
|
|
4
|
+
CLAWORLD_CHANNEL_ID,
|
|
5
|
+
claworldChannelConfigSchema,
|
|
6
|
+
claworldChannelConfigJsonSchema,
|
|
7
|
+
validateClaworldChannelConfig,
|
|
8
|
+
inspectClaworldChannelAccount,
|
|
9
|
+
resolveClaworldChannelAccount,
|
|
10
|
+
resolveClaworldRuntimeConfig,
|
|
11
|
+
listClaworldAccountIds,
|
|
12
|
+
defaultClaworldAccountId,
|
|
13
|
+
LOCAL_AGENT_BOOTSTRAP_SCHEMA,
|
|
14
|
+
LOCAL_AGENT_BOOTSTRAP_REQUIRED,
|
|
15
|
+
} from './plugin/config-schema.js';
|
|
16
|
+
export { createClaworldLifecycleManager } from './plugin/lifecycle.js';
|
|
17
|
+
export { getClaworldRuntime, setClaworldRuntime } from './plugin/runtime.js';
|
|
18
|
+
export {
|
|
19
|
+
ClaworldRelayClient,
|
|
20
|
+
createClaworldRelayClient,
|
|
21
|
+
normalizeRelayWebSocketUrl,
|
|
22
|
+
} from './plugin/relay-client.js';
|
|
23
|
+
export { createRelayEventProtocol } from './protocol/relay-event-protocol.js';
|
|
24
|
+
export { OPENCLAW_RUNTIME_PATH, createRuntimePathTrace } from './runtime/runtime-path.js';
|
|
25
|
+
export { createInboundSessionRouter } from './runtime/inbound-session-router.js';
|
|
26
|
+
export { createOutboundSessionBridge } from './runtime/outbound-session-bridge.js';
|
|
27
|
+
export { createSystemMessageOrchestrator } from './runtime/system-message-orchestrator.js';
|
|
28
|
+
export { createCanonicalResultBuilder } from './runtime/canonical-result-builder.js';
|
|
29
|
+
export { createDemoSessionBootstrap } from './runtime/demo-session-bootstrap.js';
|
|
30
|
+
export {
|
|
31
|
+
createModeratedWorld,
|
|
32
|
+
fetchOwnedWorlds,
|
|
33
|
+
manageModeratedWorld,
|
|
34
|
+
} from './runtime/world-moderation-helper.js';
|
|
35
|
+
export {
|
|
36
|
+
fetchWorldMemberships,
|
|
37
|
+
fetchWorldMembership,
|
|
38
|
+
updateWorldMembershipProfile,
|
|
39
|
+
leaveWorldMembership,
|
|
40
|
+
} from './runtime/world-membership-helper.js';
|
|
41
|
+
export {
|
|
42
|
+
buildPostSetupWorldDirectory,
|
|
43
|
+
buildWorldSelectionPrompt,
|
|
44
|
+
resolveWorldSelection,
|
|
45
|
+
fetchWorldDetail,
|
|
46
|
+
joinWorld,
|
|
47
|
+
fetchWorldCandidateFeed,
|
|
48
|
+
buildCandidateDeliverySummary,
|
|
49
|
+
resolveWorldSelectionFlow,
|
|
50
|
+
} from './runtime/product-shell-helper.js';
|
|
51
|
+
export { submitFeedbackReport } from './runtime/feedback-helper.js';
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CLAWORLD_PLUGIN_CURRENT_VERSION,
|
|
3
|
+
CLAWORLD_PLUGIN_VERSION_HEADER,
|
|
4
|
+
} from '../plugin-version.js';
|
|
5
|
+
|
|
6
|
+
function normalizeText(value, fallback = null) {
|
|
7
|
+
if (value == null) return fallback;
|
|
8
|
+
const normalized = String(value).trim();
|
|
9
|
+
return normalized || fallback;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function normalizeRuntimeRegistration(candidate = {}) {
|
|
13
|
+
const registration = candidate.registration && typeof candidate.registration === 'object'
|
|
14
|
+
? candidate.registration
|
|
15
|
+
: {};
|
|
16
|
+
const legacyLocalAgent = candidate.localAgent && typeof candidate.localAgent === 'object'
|
|
17
|
+
? candidate.localAgent
|
|
18
|
+
: {};
|
|
19
|
+
const enabled = registration.enabled === true || legacyLocalAgent.enabled === true;
|
|
20
|
+
|
|
21
|
+
if (!enabled) return { enabled: false };
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
enabled: true,
|
|
25
|
+
displayName: normalizeText(registration.displayName, normalizeText(legacyLocalAgent.displayName, null)),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function resolveRuntimeAppToken(candidate = {}) {
|
|
30
|
+
return normalizeText(
|
|
31
|
+
candidate.appToken,
|
|
32
|
+
normalizeText(
|
|
33
|
+
candidate.relay?.appToken,
|
|
34
|
+
normalizeText(candidate.relay?.credentialToken, null),
|
|
35
|
+
),
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function applyRuntimeIdentity(runtimeConfig = {}, { agentId = null, appToken = null } = {}) {
|
|
40
|
+
const resolvedAppToken = normalizeText(appToken, resolveRuntimeAppToken(runtimeConfig));
|
|
41
|
+
const registration = normalizeRuntimeRegistration(runtimeConfig);
|
|
42
|
+
const relay = runtimeConfig.relay && typeof runtimeConfig.relay === 'object'
|
|
43
|
+
? runtimeConfig.relay
|
|
44
|
+
: {};
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
...runtimeConfig,
|
|
48
|
+
appToken: resolvedAppToken,
|
|
49
|
+
registration,
|
|
50
|
+
localAgent: registration,
|
|
51
|
+
relay: {
|
|
52
|
+
...relay,
|
|
53
|
+
agentId: normalizeText(agentId, normalizeText(relay.agentId, null)),
|
|
54
|
+
appToken: resolvedAppToken,
|
|
55
|
+
credentialToken: resolvedAppToken,
|
|
56
|
+
defaultTargetAgentId: normalizeText(relay.defaultTargetAgentId, null),
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function buildRuntimeAuthHeaders(runtimeConfig = {}, headers = {}) {
|
|
62
|
+
const appToken = resolveRuntimeAppToken(runtimeConfig);
|
|
63
|
+
const nextHeaders = {
|
|
64
|
+
...headers,
|
|
65
|
+
[CLAWORLD_PLUGIN_VERSION_HEADER]: CLAWORLD_PLUGIN_CURRENT_VERSION,
|
|
66
|
+
};
|
|
67
|
+
if (!appToken) return nextHeaders;
|
|
68
|
+
return {
|
|
69
|
+
...nextHeaders,
|
|
70
|
+
authorization: `Bearer ${appToken}`,
|
|
71
|
+
'x-claworld-app-token': appToken,
|
|
72
|
+
};
|
|
73
|
+
}
|