@lightcone-ai/daemon 0.14.9 → 0.14.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightcone-ai/daemon",
3
- "version": "0.14.9",
3
+ "version": "0.14.11",
4
4
  "type": "module",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -92,30 +92,38 @@ function decodeWorkspaceContent(content) {
92
92
  return Buffer.from(decodeURIComponent(body), 'utf8');
93
93
  }
94
94
 
95
- async function internalApi({ serverUrl, machineApiKey, agentId, method, endpoint, body }) {
96
- const url = `${String(serverUrl).replace(/\/$/, '')}/internal/agent/${encodeURIComponent(agentId)}${endpoint}`;
95
+ export async function fetchPublishJobWorkspaceFile({ serverUrl, machineApiKey, jobId, relPath }) {
96
+ const normalizedJobId = String(jobId ?? '').trim();
97
+ if (!normalizedJobId) {
98
+ throw new Error('publish job id is required to fetch workspace files');
99
+ }
100
+ const url = `${String(serverUrl).replace(/\/$/, '')}/internal/agent/publish-jobs/${encodeURIComponent(normalizedJobId)}/workspace-files?path=${encodeURIComponent(relPath)}`;
97
101
  const res = await fetch(url, {
98
- method,
99
102
  headers: {
100
- 'Content-Type': 'application/json',
101
103
  Authorization: `Bearer ${machineApiKey}`,
102
104
  },
103
- body: body != null ? JSON.stringify(body) : undefined,
104
105
  });
105
106
  if (!res.ok) {
106
107
  const text = await res.text();
107
- throw new Error(`internal API ${method} ${endpoint} failed (${res.status}): ${text}`);
108
+ throw new Error(`publish-jobs workspace-files GET failed (${res.status}): ${text}`);
108
109
  }
109
110
  return res.json();
110
111
  }
111
112
 
112
- function workspacePathFromMediaPath(filePath, workspaceId) {
113
+ export function workspacePathFromMediaPath(filePath, workspaceId) {
113
114
  if (!filePath) return null;
114
115
 
115
116
  const normalized = filePath.replaceAll('\\', '/');
116
117
  const virtualMatch = normalized.match(/^\/agent-workspace\/([^/]+)\/workspace\/(.+)$/);
117
118
  if (virtualMatch) return { workspaceId: virtualMatch[1], relPath: virtualMatch[2] };
118
119
 
120
+ const hostMatch = normalized.match(
121
+ /\/workspace\/([0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})\/((?:artifacts|notes|tmp)\/.+)$/i
122
+ );
123
+ if (hostMatch) {
124
+ return { workspaceId: hostMatch[1], relPath: hostMatch[2] };
125
+ }
126
+
119
127
  const workspaceSegmentMatch = normalized.match(/\/workspace\/((?:artifacts|notes|tmp)\/.+)$/);
120
128
  if (workspaceSegmentMatch) {
121
129
  return { workspaceId, relPath: workspaceSegmentMatch[1] };
@@ -128,7 +136,15 @@ function workspacePathFromMediaPath(filePath, workspaceId) {
128
136
  return null;
129
137
  }
130
138
 
131
- async function materializeWorkspaceMedia({ filePath, workspaceId, workspaceRootDir, serverUrl, machineApiKey, agentId }) {
139
+ export async function materializeWorkspaceMedia({
140
+ filePath,
141
+ workspaceId,
142
+ workspaceRootDir,
143
+ serverUrl,
144
+ machineApiKey,
145
+ jobId,
146
+ fetchWorkspaceFile = fetchPublishJobWorkspaceFile,
147
+ }) {
132
148
  if (!filePath || existsSync(filePath)) return filePath;
133
149
 
134
150
  const workspacePath = workspacePathFromMediaPath(filePath, workspaceId);
@@ -142,12 +158,11 @@ async function materializeWorkspaceMedia({ filePath, workspaceId, workspaceRootD
142
158
 
143
159
  if (existsSync(localPath)) return localPath;
144
160
 
145
- const data = await internalApi({
161
+ const data = await fetchWorkspaceFile({
146
162
  serverUrl,
147
163
  machineApiKey,
148
- agentId,
149
- method: 'GET',
150
- endpoint: `/workspace-memory?path=${encodeURIComponent(workspacePath.relPath)}&workspaceId=${encodeURIComponent(workspacePath.workspaceId)}`,
164
+ jobId,
165
+ relPath: workspacePath.relPath,
151
166
  });
152
167
  mkdirSync(path.dirname(localPath), { recursive: true });
153
168
  writeFileSync(localPath, decodeWorkspaceContent(data.content));
@@ -162,7 +177,7 @@ async function materializeMedia({
162
177
  workspaceRootDir,
163
178
  serverUrl,
164
179
  machineApiKey,
165
- agentId,
180
+ jobId,
166
181
  }) {
167
182
  return {
168
183
  images: await Promise.all(images.map(filePath => materializeWorkspaceMedia({
@@ -171,7 +186,7 @@ async function materializeMedia({
171
186
  workspaceRootDir,
172
187
  serverUrl,
173
188
  machineApiKey,
174
- agentId,
189
+ jobId,
175
190
  }))),
176
191
  video: video ? await materializeWorkspaceMedia({
177
192
  filePath: video,
@@ -179,7 +194,7 @@ async function materializeMedia({
179
194
  workspaceRootDir,
180
195
  serverUrl,
181
196
  machineApiKey,
182
- agentId,
197
+ jobId,
183
198
  }) : video,
184
199
  cover: cover ? await materializeWorkspaceMedia({
185
200
  filePath: cover,
@@ -187,7 +202,7 @@ async function materializeMedia({
187
202
  workspaceRootDir,
188
203
  serverUrl,
189
204
  machineApiKey,
190
- agentId,
205
+ jobId,
191
206
  }) : cover,
192
207
  };
193
208
  }
@@ -397,7 +412,7 @@ export async function runPublishJob({ serverUrl, machineApiKey, agentId, workspa
397
412
  workspaceRootDir,
398
413
  serverUrl,
399
414
  machineApiKey,
400
- agentId,
415
+ jobId: job?.id,
401
416
  });
402
417
  const staticAdapter = createStaticAdapter(platform);
403
418
  const req = staticAdapter.getRequirements(contentType);