@feralfile/cli 1.3.1 → 1.4.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/dist/package.json +1 -1
- package/dist/src/ai-orchestrator/index.js +23 -14
- package/dist/src/commands/find.js +9 -2
- package/dist/src/commands/play.js +3 -1
- package/dist/src/intent-parser/index.js +2 -2
- package/dist/src/intent-parser/utils.js +9 -6
- package/dist/src/main.js +5 -2
- package/dist/src/utilities/feed-fetcher.js +20 -13
- package/dist/src/utilities/index.js +10 -8
- package/dist/src/utilities/marketplace-url.js +7 -3
- package/dist/src/utilities/nft-indexer.js +9 -7
- package/dist/src/utilities/opensea-marketplace.js +123 -0
- package/dist/src/utilities/playlist-builder.js +92 -19
- package/dist/src/utilities/playlist-source.js +3 -1
- package/docs/CONFIGURATION.md +2 -1
- package/docs/FUNCTION_CALLING.md +3 -1
- package/docs/README.md +2 -1
- package/package.json +1 -1
package/dist/package.json
CHANGED
|
@@ -68,16 +68,19 @@ function inferToolCallFromContent(content, iterationCount) {
|
|
|
68
68
|
typeof parsed === 'object' &&
|
|
69
69
|
parsed.requirement &&
|
|
70
70
|
typeof parsed.requirement === 'object' &&
|
|
71
|
-
typeof parsed.duration === 'number') {
|
|
71
|
+
(parsed.duration === undefined || typeof parsed.duration === 'number')) {
|
|
72
|
+
// duration is optional: absent means auto timing (DP-1 §4.1), so the
|
|
73
|
+
// synthetic call must not fabricate one.
|
|
74
|
+
const syntheticArgs = { requirement: parsed.requirement };
|
|
75
|
+
if (typeof parsed.duration === 'number') {
|
|
76
|
+
syntheticArgs.duration = parsed.duration;
|
|
77
|
+
}
|
|
72
78
|
return {
|
|
73
79
|
id: `synthetic_query_requirement_${iterationCount}`,
|
|
74
80
|
type: 'function',
|
|
75
81
|
function: {
|
|
76
82
|
name: 'query_requirement',
|
|
77
|
-
arguments: JSON.stringify(
|
|
78
|
-
requirement: parsed.requirement,
|
|
79
|
-
duration: parsed.duration,
|
|
80
|
-
}),
|
|
83
|
+
arguments: JSON.stringify(syntheticArgs),
|
|
81
84
|
},
|
|
82
85
|
};
|
|
83
86
|
}
|
|
@@ -165,10 +168,10 @@ const functionSchemas = [
|
|
|
165
168
|
},
|
|
166
169
|
duration: {
|
|
167
170
|
type: 'number',
|
|
168
|
-
description: 'Display duration per item in seconds',
|
|
171
|
+
description: 'Display duration per item in seconds. Omit for auto timing: video/audio items then carry no duration and play their natural length (DP-1 §4.1); static items use the configured default.',
|
|
169
172
|
},
|
|
170
173
|
},
|
|
171
|
-
required: ['requirement'
|
|
174
|
+
required: ['requirement'],
|
|
172
175
|
},
|
|
173
176
|
},
|
|
174
177
|
},
|
|
@@ -207,10 +210,10 @@ const functionSchemas = [
|
|
|
207
210
|
},
|
|
208
211
|
duration: {
|
|
209
212
|
type: 'number',
|
|
210
|
-
description:
|
|
213
|
+
description: "Duration per item in seconds. Omit to keep each feed item's own timing.",
|
|
211
214
|
},
|
|
212
215
|
},
|
|
213
|
-
required: ['playlistName', 'quantity'
|
|
216
|
+
required: ['playlistName', 'quantity'],
|
|
214
217
|
},
|
|
215
218
|
},
|
|
216
219
|
},
|
|
@@ -474,6 +477,12 @@ function buildOrchestratorSystemPrompt(params) {
|
|
|
474
477
|
}
|
|
475
478
|
})
|
|
476
479
|
.join('\n');
|
|
480
|
+
// Spell out the duration argument once: an explicit setting is passed
|
|
481
|
+
// through verbatim; otherwise the model must OMIT duration so item-build
|
|
482
|
+
// applies auto timing (video/audio natural length per DP-1 §4.1).
|
|
483
|
+
const durationArgText = typeof playlistSettings.durationPerItem === 'number'
|
|
484
|
+
? `call query_requirement(requirement, duration=${playlistSettings.durationPerItem}).`
|
|
485
|
+
: 'call query_requirement(requirement) WITHOUT a duration argument (auto timing).';
|
|
477
486
|
const hasDevice = playlistSettings.deviceName !== undefined;
|
|
478
487
|
const sendStep = hasDevice
|
|
479
488
|
? `6) If verification passed → you MUST call send_to_device({ playlistId: <the_playlistId>, deviceName: "${playlistSettings.deviceName || 'first-device'}" }) before finishing.
|
|
@@ -488,7 +497,7 @@ REQUIREMENTS
|
|
|
488
497
|
${requirementsText}
|
|
489
498
|
|
|
490
499
|
PLAYLIST SETTINGS
|
|
491
|
-
- durationPerItem: ${playlistSettings.durationPerItem
|
|
500
|
+
- durationPerItem: ${typeof playlistSettings.durationPerItem === 'number' ? playlistSettings.durationPerItem : 'auto (omit duration: video/audio play natural length, static media uses configured default)'}
|
|
492
501
|
- title: ${playlistSettings.title || 'auto'}
|
|
493
502
|
- slug: ${playlistSettings.slug || 'auto'}
|
|
494
503
|
- preserveOrder: ${playlistSettings.preserveOrder !== false ? 'true' : 'false'}
|
|
@@ -517,14 +526,14 @@ KEY RULES
|
|
|
517
526
|
|
|
518
527
|
DECISION LOOP
|
|
519
528
|
1) For each requirement in order:
|
|
520
|
-
- build_playlist:
|
|
529
|
+
- build_playlist: ${durationArgText}
|
|
521
530
|
Returns array with minimal item data including id field. Collect the id values.
|
|
522
|
-
- feral_file_artwork:
|
|
531
|
+
- feral_file_artwork: ${durationArgText}
|
|
523
532
|
Returns array with minimal item data including id field. Collect the id values.
|
|
524
533
|
- query_address:
|
|
525
534
|
• if ownerAddress endsWith .eth/.tez → resolve_domains([domain]); if resolved → use returned address; if not → mark failed and continue.
|
|
526
|
-
• if ownerAddress is 0x…/tz… →
|
|
527
|
-
- fetch_feed: search_feed_playlist(name) → take bestMatch → fetch_feed_playlist_items(bestMatch, quantity
|
|
535
|
+
• if ownerAddress is 0x…/tz… → ${durationArgText}
|
|
536
|
+
- fetch_feed: search_feed_playlist(name) → take bestMatch → fetch_feed_playlist_items(bestMatch, quantity${typeof playlistSettings.durationPerItem === 'number' ? `, duration=${playlistSettings.durationPerItem}` : ''}).
|
|
528
537
|
- Collect item IDs across all steps in an array (let's call it collectedItemIds).
|
|
529
538
|
2) If zero items → explain briefly and finish.
|
|
530
539
|
3) If some requirements failed and interactive mode → ask user; otherwise proceed with available items.
|
|
@@ -47,6 +47,7 @@ const marketplace_url_1 = require("../utilities/marketplace-url");
|
|
|
47
47
|
const ff_marketplace_1 = require("../utilities/ff-marketplace");
|
|
48
48
|
const objkt_marketplace_1 = require("../utilities/objkt-marketplace");
|
|
49
49
|
const ab_marketplace_1 = require("../utilities/ab-marketplace");
|
|
50
|
+
const opensea_marketplace_1 = require("../utilities/opensea-marketplace");
|
|
50
51
|
const fxhash_marketplace_1 = require("../utilities/fxhash-marketplace");
|
|
51
52
|
const neort_marketplace_1 = require("../utilities/neort-marketplace");
|
|
52
53
|
const verse_marketplace_1 = require("../utilities/verse-marketplace");
|
|
@@ -129,7 +130,8 @@ exports.findCommand = new commander_1.Command('find')
|
|
|
129
130
|
console.log(chalk_1.default.dim(`Indexing ${tokens.length} token${tokens.length === 1 ? '' : 's'} via FF indexer...`));
|
|
130
131
|
// Second positional arg on getNFTTokenInfoBatch is `duration` (DP-1 item
|
|
131
132
|
// display seconds), not concurrency — concurrency is hardcoded inside.
|
|
132
|
-
// Omit it
|
|
133
|
+
// Omit it for auto timing: video/audio items carry no duration and play
|
|
134
|
+
// their natural length (DP-1 §4.1); static items get the config default.
|
|
133
135
|
const items = await getNFTTokenInfoBatch(tokens.map((t) => ({
|
|
134
136
|
chain: t.chain,
|
|
135
137
|
contractAddress: t.contract,
|
|
@@ -183,6 +185,10 @@ async function resolveTarget(parsed, skipPrompt) {
|
|
|
183
185
|
const coords = await (0, ab_marketplace_1.resolveArtBlocksCollection)(parsed.slug);
|
|
184
186
|
return resolveCoords(coords);
|
|
185
187
|
}
|
|
188
|
+
if (parsed.kind === 'os-collection') {
|
|
189
|
+
const coords = await (0, opensea_marketplace_1.resolveOpenSeaCollection)(parsed.slug);
|
|
190
|
+
return resolveCoords(coords);
|
|
191
|
+
}
|
|
186
192
|
if (parsed.kind === 'fxhash-iteration') {
|
|
187
193
|
const coords = await (0, fxhash_marketplace_1.resolveFxhashIteration)(parsed.slug);
|
|
188
194
|
return resolveCoords(coords);
|
|
@@ -487,7 +493,8 @@ async function runNeortFind(id, options) {
|
|
|
487
493
|
console.log(chalk_1.default.dim('Cancelled.'));
|
|
488
494
|
return;
|
|
489
495
|
}
|
|
490
|
-
|
|
496
|
+
// No explicit duration: auto timing (video/audio play natural length).
|
|
497
|
+
const item = buildUrlItem(art.assetUrl, undefined, { title: art.title });
|
|
491
498
|
const playlistTitle = `${artistLabel} — ${art.title}`;
|
|
492
499
|
const playlist = await buildDP1Playlist({ items: [item], title: playlistTitle });
|
|
493
500
|
const outputPath = options.output ?? `${playlist.slug || 'playlist'}.json`;
|
|
@@ -55,7 +55,9 @@ exports.playCommand = new commander_1.Command('play')
|
|
|
55
55
|
.action(async (source, options) => {
|
|
56
56
|
try {
|
|
57
57
|
const config = (0, config_1.getConfig)();
|
|
58
|
-
|
|
58
|
+
// No explicit duration: a direct video/audio URL plays its natural
|
|
59
|
+
// length (DP-1 §4.1); static media uses config.defaultDuration.
|
|
60
|
+
const resolved = await (0, playlist_source_1.resolvePlaySource)(source);
|
|
59
61
|
const isPlaylistSource = resolved.kind === 'playlist';
|
|
60
62
|
const sourceLabel = isPlaylistSource
|
|
61
63
|
? `${resolved.sourceType}: ${resolved.source}`
|
|
@@ -164,7 +164,7 @@ EXAMPLES (fetch_feed)
|
|
|
164
164
|
- "Pick 3 artworks from Social Codes and 2 from a2p. Mix them up." → \`fetch_feed\` { playlistName: "Social Codes", quantity: 3 } + \`fetch_feed\` { playlistName: "a2p", quantity: 2 }, and set \`playlistSettings.preserveOrder\` = false
|
|
165
165
|
|
|
166
166
|
PLAYLIST SETTINGS EXTRACTION
|
|
167
|
-
- durationPerItem: parse phrases (e.g., "6 seconds each" → 6)
|
|
167
|
+
- durationPerItem: parse phrases (e.g., "6 seconds each" → 6); OMIT entirely when the user gives no per-item time — omitted means auto timing (video/audio play their natural length, static media uses the configured default). Never invent a number.
|
|
168
168
|
- preserveOrder: default true; synonyms ("shuffle", "randomize", "mix", "mix them up", "scramble") → false
|
|
169
169
|
- title/slug: optional; include only if provided by the user
|
|
170
170
|
- deviceName: from phrases like "send to", "display on", "play on", "push to"${hasDevices ? '\n- available devices:\n' + deviceInfo.replace('\n\nAVAILABLE FF1 DEVICES:\n', '') : ''}
|
|
@@ -341,7 +341,7 @@ const intentParserFunctionSchemas = [
|
|
|
341
341
|
},
|
|
342
342
|
durationPerItem: {
|
|
343
343
|
type: 'number',
|
|
344
|
-
description: 'Duration per item in seconds (e.g., 5 for "5 seconds each")',
|
|
344
|
+
description: 'Duration per item in seconds (e.g., 5 for "5 seconds each"). Omit when the user gives no per-item time: omitted = auto timing (video/audio play natural length per DP-1 §4.1).',
|
|
345
345
|
},
|
|
346
346
|
totalDuration: {
|
|
347
347
|
type: 'number',
|
|
@@ -15,10 +15,12 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
15
15
|
* @param {Object} params - Parsed parameters
|
|
16
16
|
* @param {Array<Object>} params.requirements - Array of requirements
|
|
17
17
|
* @param {Object} [params.playlistSettings] - Playlist settings
|
|
18
|
-
* @param {Object}
|
|
18
|
+
* @param {Object} _config - Application config (kept in the signature for
|
|
19
|
+
* call-site stability; no constraint reads it since durationPerItem
|
|
20
|
+
* pre-filling was removed in favor of DP-1 §4.1 auto timing)
|
|
19
21
|
* @returns {Object} Validated parameters
|
|
20
22
|
*/
|
|
21
|
-
function applyConstraints(params,
|
|
23
|
+
function applyConstraints(params, _config) {
|
|
22
24
|
// Validate requirements array
|
|
23
25
|
if (!params.requirements || !Array.isArray(params.requirements)) {
|
|
24
26
|
throw new Error('Requirements must be an array');
|
|
@@ -101,10 +103,11 @@ function applyConstraints(params, config) {
|
|
|
101
103
|
if (!params.playlistSettings) {
|
|
102
104
|
params.playlistSettings = {};
|
|
103
105
|
}
|
|
104
|
-
//
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
// durationPerItem stays undefined unless the user asked for a per-item
|
|
107
|
+
// time: absence means auto timing downstream (video/audio omit duration
|
|
108
|
+
// and play their natural length per DP-1 §4.1; static media falls back to
|
|
109
|
+
// config.defaultDuration at item-build time). Pre-filling a number here
|
|
110
|
+
// would force-cut every video item.
|
|
108
111
|
// Only set preserveOrder if not already specified
|
|
109
112
|
if (params.playlistSettings.preserveOrder === undefined) {
|
|
110
113
|
params.playlistSettings.preserveOrder = true;
|
package/dist/src/main.js
CHANGED
|
@@ -228,11 +228,14 @@ function validateRequirements(requirements) {
|
|
|
228
228
|
* @returns {Object} Settings with defaults
|
|
229
229
|
*/
|
|
230
230
|
function applyPlaylistDefaults(settings = {}) {
|
|
231
|
-
const config = (0, config_1.getConfig)();
|
|
232
231
|
return {
|
|
233
232
|
title: settings.title || null,
|
|
234
233
|
slug: settings.slug || null,
|
|
235
|
-
|
|
234
|
+
// Leave durationPerItem undefined when not requested: absence means auto
|
|
235
|
+
// timing downstream (video/audio omit duration and play their natural
|
|
236
|
+
// length per DP-1 §4.1; static media falls back to config.defaultDuration
|
|
237
|
+
// at item-build time). Filling a number here would force-cut video items.
|
|
238
|
+
durationPerItem: settings.durationPerItem,
|
|
236
239
|
preserveOrder: settings.preserveOrder !== false,
|
|
237
240
|
deviceName: settings.deviceName,
|
|
238
241
|
};
|
|
@@ -333,7 +333,7 @@ function shuffleArray(array) {
|
|
|
333
333
|
*
|
|
334
334
|
* @param {Object} playlist - DP1 playlist object
|
|
335
335
|
* @param {number} quantity - Number of items to extract
|
|
336
|
-
* @param {number} duration -
|
|
336
|
+
* @param {number} [duration] - Explicit display seconds; omit to keep item timing
|
|
337
337
|
* @param {boolean} shuffle - Whether to shuffle and randomly select items
|
|
338
338
|
* @returns {Array<Object>} Array of DP1 playlist items
|
|
339
339
|
*/
|
|
@@ -348,12 +348,19 @@ function extractPlaylistItems(playlist, quantity, duration, shuffle = true) {
|
|
|
348
348
|
}
|
|
349
349
|
// Take requested quantity
|
|
350
350
|
items = items.slice(0, quantity);
|
|
351
|
-
//
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
351
|
+
// Apply an explicit duration override when one was requested; otherwise
|
|
352
|
+
// keep each item's own timing (including intentionally absent duration,
|
|
353
|
+
// which DP-1 §4.1 uses for natural-length playback of video/audio).
|
|
354
|
+
items = items.map((item) => {
|
|
355
|
+
const next = {
|
|
356
|
+
...item,
|
|
357
|
+
created: item.created || new Date().toISOString(), // Ensure created field exists
|
|
358
|
+
};
|
|
359
|
+
if (typeof duration === 'number') {
|
|
360
|
+
next.duration = duration;
|
|
361
|
+
}
|
|
362
|
+
return next;
|
|
363
|
+
});
|
|
357
364
|
return items;
|
|
358
365
|
}
|
|
359
366
|
/**
|
|
@@ -361,10 +368,10 @@ function extractPlaylistItems(playlist, quantity, duration, shuffle = true) {
|
|
|
361
368
|
*
|
|
362
369
|
* @param {string} playlistName - Exact playlist name
|
|
363
370
|
* @param {number} quantity - Number of items to fetch
|
|
364
|
-
* @param {number} duration -
|
|
371
|
+
* @param {number} [duration] - Explicit display seconds; omit to keep item timing
|
|
365
372
|
* @returns {Promise<Object>} Result with items
|
|
366
373
|
*/
|
|
367
|
-
async function fetchFeedPlaylistDirect(playlistName, quantity = 5, duration
|
|
374
|
+
async function fetchFeedPlaylistDirect(playlistName, quantity = 5, duration) {
|
|
368
375
|
const feedUrls = getFeedApiUrls();
|
|
369
376
|
console.log(chalk.cyan(`Searching for playlist "${playlistName}" in ${feedUrls.length} source(s)...`));
|
|
370
377
|
const result = await searchExactPlaylist(playlistName);
|
|
@@ -395,10 +402,10 @@ async function fetchFeedPlaylistDirect(playlistName, quantity = 5, duration = 10
|
|
|
395
402
|
*
|
|
396
403
|
* @param {string} playlistName - Playlist name (can be fuzzy)
|
|
397
404
|
* @param {number} quantity - Number of items to fetch
|
|
398
|
-
* @param {number} duration -
|
|
405
|
+
* @param {number} [duration] - Explicit display seconds; omit to keep item timing
|
|
399
406
|
* @returns {Promise<Object>} Result with best match and map for lookup
|
|
400
407
|
*/
|
|
401
|
-
async function searchFeedPlaylists(playlistName, quantity = 5, duration
|
|
408
|
+
async function searchFeedPlaylists(playlistName, quantity = 5, duration) {
|
|
402
409
|
const feedUrls = getFeedApiUrls();
|
|
403
410
|
console.log(chalk.cyan(`Searching for playlist "${playlistName}" in ${feedUrls.length} source(s)...`));
|
|
404
411
|
const result = await findBestMatchingPlaylist(playlistName);
|
|
@@ -429,12 +436,12 @@ async function searchFeedPlaylists(playlistName, quantity = 5, duration = 10) {
|
|
|
429
436
|
*
|
|
430
437
|
* @param {string} playlistIdOrName - Playlist ID, slug, or exact name
|
|
431
438
|
* @param {number} quantity - Number of items to fetch
|
|
432
|
-
* @param {number} duration -
|
|
439
|
+
* @param {number} [duration] - Explicit display seconds; omit to keep item timing
|
|
433
440
|
* @param {Object} playlistMap - Optional map of names to IDs for lookup
|
|
434
441
|
* @param {boolean} shuffle - Whether to shuffle and randomly select items
|
|
435
442
|
* @returns {Promise<Object>} Result with items
|
|
436
443
|
*/
|
|
437
|
-
async function fetchPlaylistItems(playlistIdOrName, quantity = 5, duration
|
|
444
|
+
async function fetchPlaylistItems(playlistIdOrName, quantity = 5, duration, playlistMap = null, shuffle = true) {
|
|
438
445
|
try {
|
|
439
446
|
let playlistId = playlistIdOrName;
|
|
440
447
|
let feedUrl = null;
|
|
@@ -95,10 +95,10 @@ function isLikelyEvmAddress(address) {
|
|
|
95
95
|
*
|
|
96
96
|
* @param {string} contractAddress - Contract address
|
|
97
97
|
* @param {number|string} [quantity] - Number of random tokens to select
|
|
98
|
-
* @param {number} duration -
|
|
98
|
+
* @param {number} [duration] - Explicit display seconds; omit for auto timing
|
|
99
99
|
* @returns {Promise<Array<Object>>} Array of DP1 items
|
|
100
100
|
*/
|
|
101
|
-
async function queryTokensByContractAddress(contractAddress, quantity, duration
|
|
101
|
+
async function queryTokensByContractAddress(contractAddress, quantity, duration) {
|
|
102
102
|
console.log(chalk.cyan(` Fetching ${quantity || 100} random token(s) from contract ${contractAddress.substring(0, 10)}...`));
|
|
103
103
|
const limit = Math.min(quantity || 100, 100);
|
|
104
104
|
const result = await nftIndexer.queryTokensByContract(contractAddress, limit);
|
|
@@ -141,10 +141,10 @@ function initializeUtilities(_config) {
|
|
|
141
141
|
*
|
|
142
142
|
* @param {string} ownerAddress - Owner wallet address
|
|
143
143
|
* @param {number|string} [quantity] - Number of random tokens to select, or "all" to fetch all tokens
|
|
144
|
-
* @param {number} duration -
|
|
144
|
+
* @param {number} [duration] - Explicit display seconds; omit for auto timing
|
|
145
145
|
* @returns {Promise<Array>} Array of DP1 playlist items
|
|
146
146
|
*/
|
|
147
|
-
async function queryTokensByAddress(ownerAddress, quantity, duration
|
|
147
|
+
async function queryTokensByAddress(ownerAddress, quantity, duration, options = {}) {
|
|
148
148
|
try {
|
|
149
149
|
const { suppressNotFoundGuidance = false } = options;
|
|
150
150
|
const shouldFetchAll = quantity === 'all' || quantity === undefined || quantity === null;
|
|
@@ -216,7 +216,7 @@ async function queryTokensByAddress(ownerAddress, quantity, duration = 10, optio
|
|
|
216
216
|
if (typeof quantity === 'number' && selectedTokens.length > quantity) {
|
|
217
217
|
selectedTokens = shuffleArray([...selectedTokens]).slice(0, quantity);
|
|
218
218
|
}
|
|
219
|
-
const tokenCountKey = `${ownerAddress}|${quantity ?? 'all'}|${duration}`;
|
|
219
|
+
const tokenCountKey = `${ownerAddress}|${quantity ?? 'all'}|${duration ?? 'auto'}`;
|
|
220
220
|
if (!printedTokenCountKeys.has(tokenCountKey)) {
|
|
221
221
|
console.log(chalk.dim(`Got ${selectedTokens.length} token(s)`));
|
|
222
222
|
printedTokenCountKeys.add(tokenCountKey);
|
|
@@ -243,10 +243,10 @@ async function queryTokensByAddress(ownerAddress, quantity, duration = 10, optio
|
|
|
243
243
|
* @param {string} [requirement.ownerAddress] - Owner address (for query_address)
|
|
244
244
|
* @param {string} [requirement.playlistName] - Feed playlist name (for fetch_feed)
|
|
245
245
|
* @param {number} [requirement.quantity] - Number of items
|
|
246
|
-
* @param {number} duration -
|
|
246
|
+
* @param {number} [duration] - Explicit display seconds; omit for auto timing
|
|
247
247
|
* @returns {Promise<Array>} Array of DP1 playlist items
|
|
248
248
|
*/
|
|
249
|
-
async function queryRequirement(requirement, duration
|
|
249
|
+
async function queryRequirement(requirement, duration) {
|
|
250
250
|
const { type, blockchain, contractAddress, tokenIds, ownerAddress, playlistName, quantity, artworkId, } = requirement;
|
|
251
251
|
// Handle query_address type
|
|
252
252
|
if (type === 'query_address') {
|
|
@@ -458,7 +458,9 @@ async function buildPlaylistDirect(params, options = {}) {
|
|
|
458
458
|
const { requirements, playlistSettings } = params;
|
|
459
459
|
const { verbose = false, outputPath = 'playlist.json' } = options;
|
|
460
460
|
const allItems = [];
|
|
461
|
-
|
|
461
|
+
// Undefined means auto timing: video/audio items omit duration and play
|
|
462
|
+
// their natural length (DP-1 §4.1); static items get the configured default.
|
|
463
|
+
const duration = playlistSettings.durationPerItem;
|
|
462
464
|
console.log(chalk.cyan('\nBuilding playlist from your requirements...\n'));
|
|
463
465
|
// Process each requirement
|
|
464
466
|
for (let i = 0; i < requirements.length; i++) {
|
|
@@ -246,7 +246,7 @@ function parseFxhash(url) {
|
|
|
246
246
|
* OpenSea URL forms:
|
|
247
247
|
* opensea.io/assets/{chain}/{contract}/{tokenId}
|
|
248
248
|
* opensea.io/item/{chain}/{contract}/{tokenId} — newer naming
|
|
249
|
-
* opensea.io/collection/{slug} —
|
|
249
|
+
* opensea.io/collection/{slug} — collection slug (series)
|
|
250
250
|
*
|
|
251
251
|
* Only `ethereum` is in scope; other chains (matic, base, solana, etc.)
|
|
252
252
|
* fall outside the FF indexer's coverage. Token URLs resolve end-to-end only
|
|
@@ -270,11 +270,15 @@ function parseOpenSea(url) {
|
|
|
270
270
|
coords: { chain: 'ethereum', contract: tokenMatch[2].toLowerCase(), tokenId: tokenMatch[3] },
|
|
271
271
|
};
|
|
272
272
|
}
|
|
273
|
+
const collectionMatch = /^\/collection\/([a-z0-9][a-z0-9-]*)\/?$/.exec(url.pathname);
|
|
274
|
+
if (collectionMatch) {
|
|
275
|
+
return { kind: 'os-collection', slug: collectionMatch[1] };
|
|
276
|
+
}
|
|
273
277
|
if (url.pathname.startsWith('/collection/')) {
|
|
274
278
|
return {
|
|
275
279
|
kind: 'unsupported',
|
|
276
|
-
reason:
|
|
277
|
-
'
|
|
280
|
+
reason: `OpenSea collection URL not recognized: ${url.pathname}. ` +
|
|
281
|
+
'Expected opensea.io/collection/{slug} with no extra path segments.',
|
|
278
282
|
};
|
|
279
283
|
}
|
|
280
284
|
return {
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
const GRAPHQL_ENDPOINT = 'https://indexer.feralfile.com/graphql';
|
|
7
7
|
const logger = require('../logger');
|
|
8
|
+
const { applyItemTiming } = require('./playlist-builder');
|
|
8
9
|
// Polling configuration (in milliseconds)
|
|
9
10
|
const POLLING_INTERVAL_MS = 2000; // Poll every 2 seconds
|
|
10
11
|
const POLLING_TIMEOUT_MS = 60000; // Max poll for 1 minute
|
|
@@ -354,10 +355,11 @@ function mapIndexerDataToStandardFormat(indexerData, chain) {
|
|
|
354
355
|
* animation_url > image.url, ensuring the best quality media is used.
|
|
355
356
|
*
|
|
356
357
|
* @param {Object} tokenData - Token data in standard format
|
|
357
|
-
* @param {number} duration -
|
|
358
|
+
* @param {number} [duration] - Explicit display seconds; omit for auto timing
|
|
359
|
+
* (video/audio play natural length per DP-1 §4.1)
|
|
358
360
|
* @returns {Object} DP1 item with source URL from indexer
|
|
359
361
|
*/
|
|
360
|
-
function convertToDP1Item(tokenData, duration
|
|
362
|
+
function convertToDP1Item(tokenData, duration) {
|
|
361
363
|
const { token } = tokenData;
|
|
362
364
|
if (!token) {
|
|
363
365
|
return {
|
|
@@ -435,7 +437,6 @@ function convertToDP1Item(tokenData, duration = 10) {
|
|
|
435
437
|
const dp1Item = {
|
|
436
438
|
id: itemId,
|
|
437
439
|
source: sourceUrl,
|
|
438
|
-
duration: duration,
|
|
439
440
|
license: 'open',
|
|
440
441
|
created: new Date().toISOString(),
|
|
441
442
|
provenance: {
|
|
@@ -452,6 +453,7 @@ function convertToDP1Item(tokenData, duration = 10) {
|
|
|
452
453
|
if (token.name) {
|
|
453
454
|
dp1Item.title = token.name;
|
|
454
455
|
}
|
|
456
|
+
applyItemTiming(dp1Item, { mimeType: token.image?.mimeType, sourceUrl }, duration);
|
|
455
457
|
logger.debug('[NFT Indexer] ✓ Converted to DP1:', {
|
|
456
458
|
title: token.name,
|
|
457
459
|
source: sourceUrl ? sourceUrl.substring(0, 60) + '...' : '(no source URL)',
|
|
@@ -464,11 +466,11 @@ function convertToDP1Item(tokenData, duration = 10) {
|
|
|
464
466
|
/**
|
|
465
467
|
* Get NFT token information from indexer and return as DP1 item (supports single or batch)
|
|
466
468
|
* @param {Object|Array} params - Token parameters (single object or array)
|
|
467
|
-
* @param {number} duration -
|
|
469
|
+
* @param {number} [params.duration] - Explicit display seconds; omit for auto timing
|
|
468
470
|
* @returns {Promise<Object>} DP1 item(s)
|
|
469
471
|
*/
|
|
470
472
|
async function getNFTTokenInfo(params) {
|
|
471
|
-
const duration = params.duration
|
|
473
|
+
const duration = params.duration;
|
|
472
474
|
// Handle array input for batch processing
|
|
473
475
|
if (Array.isArray(params.tokens)) {
|
|
474
476
|
return await getNFTTokenInfoBatch(params.tokens, duration);
|
|
@@ -495,7 +497,7 @@ async function getNFTTokenInfo(params) {
|
|
|
495
497
|
* @param {Object} [options.mediaPoll] - Passed to pollForMediaAssets
|
|
496
498
|
* @returns {Promise<Object>} DP1 item with success/error status
|
|
497
499
|
*/
|
|
498
|
-
async function getNFTTokenInfoSingle(params, duration
|
|
500
|
+
async function getNFTTokenInfoSingle(params, duration, options = {}) {
|
|
499
501
|
let chain = params.chain;
|
|
500
502
|
const { contractAddress, tokenId } = params;
|
|
501
503
|
// DEFENSIVE: Auto-detect and correct chain based on contract address format
|
|
@@ -596,7 +598,7 @@ async function getNFTTokenInfoSingle(params, duration = 10, options = {}) {
|
|
|
596
598
|
* @param {number} duration - Display duration in seconds
|
|
597
599
|
* @returns {Promise<Array>} Array of DP1 items
|
|
598
600
|
*/
|
|
599
|
-
async function getNFTTokenInfoBatch(tokens, duration
|
|
601
|
+
async function getNFTTokenInfoBatch(tokens, duration) {
|
|
600
602
|
logger.info(`[NFT Indexer] 📦 Starting batch processing for ${tokens.length} token(s)...`);
|
|
601
603
|
logger.debug('[NFT Indexer] Batch tokens:', tokens);
|
|
602
604
|
const results = [];
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* OpenSea marketplace resolver.
|
|
4
|
+
*
|
|
5
|
+
* OpenSea collection URLs (`opensea.io/collection/{slug}`) point to a series,
|
|
6
|
+
* not a token. OpenSea's REST API requires an API key, so this resolver reads
|
|
7
|
+
* the public collection page instead: the server-rendered HTML embeds the
|
|
8
|
+
* first page of collection items as relay-style JSON where each item carries
|
|
9
|
+
* `"chain":{"identifier":...},"contractAddress":"0x...","tokenId":"..."`
|
|
10
|
+
* adjacently. One extracted (contract, tokenId) pair is enough — the standard
|
|
11
|
+
* Raster reverse-lookup then enumerates the rest of the series like any other
|
|
12
|
+
* marketplace.
|
|
13
|
+
*
|
|
14
|
+
* Extraction invariants (what must not change):
|
|
15
|
+
* - Match only the adjacent `contractAddress` + `tokenId` pattern. The page
|
|
16
|
+
* also embeds payment-token contracts (WETH etc.) in other JSON shapes that
|
|
17
|
+
* never carry an adjacent tokenId, so adjacency is the noise filter.
|
|
18
|
+
* - The most frequent contract among matches wins (collection items dominate
|
|
19
|
+
* any stray adjacency), and its lowest tokenId is the deterministic seed.
|
|
20
|
+
* - tokenIds are compared as BigInt: ERC-721 ids can exceed Number range.
|
|
21
|
+
*
|
|
22
|
+
* Trade-off: scraping page HTML is less stable than a documented API, but the
|
|
23
|
+
* alternative (requiring every user to provision an OpenSea API key) defeats
|
|
24
|
+
* the paste-a-URL UX. Errors below name the fallback (`/item/` token URL) so
|
|
25
|
+
* a layout change degrades to a one-step workaround, not a dead end.
|
|
26
|
+
*/
|
|
27
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
28
|
+
if (k2 === undefined) k2 = k;
|
|
29
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
30
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
31
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
32
|
+
}
|
|
33
|
+
Object.defineProperty(o, k2, desc);
|
|
34
|
+
}) : (function(o, m, k, k2) {
|
|
35
|
+
if (k2 === undefined) k2 = k;
|
|
36
|
+
o[k2] = m[k];
|
|
37
|
+
}));
|
|
38
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
39
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
40
|
+
}) : function(o, v) {
|
|
41
|
+
o["default"] = v;
|
|
42
|
+
});
|
|
43
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
44
|
+
var ownKeys = function(o) {
|
|
45
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
46
|
+
var ar = [];
|
|
47
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
48
|
+
return ar;
|
|
49
|
+
};
|
|
50
|
+
return ownKeys(o);
|
|
51
|
+
};
|
|
52
|
+
return function (mod) {
|
|
53
|
+
if (mod && mod.__esModule) return mod;
|
|
54
|
+
var result = {};
|
|
55
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
56
|
+
__setModuleDefault(result, mod);
|
|
57
|
+
return result;
|
|
58
|
+
};
|
|
59
|
+
})();
|
|
60
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
|
+
exports.resolveOpenSeaCollection = resolveOpenSeaCollection;
|
|
62
|
+
const logger = __importStar(require("../logger"));
|
|
63
|
+
const user_agent_1 = require("./user-agent");
|
|
64
|
+
/**
|
|
65
|
+
* One embedded collection item: chain identifier, contract, tokenId. The
|
|
66
|
+
* `[^{}]*` keeps the chain object match from swallowing unrelated JSON when
|
|
67
|
+
* OpenSea reorders fields inside `chain`.
|
|
68
|
+
*/
|
|
69
|
+
const ITEM_PATTERN = /"chain":\{"identifier":"([a-z0-9_-]+)"[^{}]*\},"contractAddress":"(0x[a-fA-F0-9]{40})","tokenId":"(\d+)"/g;
|
|
70
|
+
const FALLBACK_HINT = 'Paste a specific token URL (opensea.io/item/ethereum/{contract}/{tokenId}) ' +
|
|
71
|
+
'or use `ethereum:{contract}:{tokenId}`.';
|
|
72
|
+
/**
|
|
73
|
+
* Resolve an OpenSea collection slug to its contract address + the lowest
|
|
74
|
+
* tokenId visible on the collection page (a representative seed for the
|
|
75
|
+
* Raster series lookup).
|
|
76
|
+
*
|
|
77
|
+
* @throws When the page cannot be fetched, embeds no recognizable items
|
|
78
|
+
* (layout change or empty collection), or the collection is not on
|
|
79
|
+
* Ethereum mainnet (outside FF indexer coverage).
|
|
80
|
+
*/
|
|
81
|
+
async function resolveOpenSeaCollection(slug) {
|
|
82
|
+
logger.debug(`[OpenSea] Resolving collection slug "${slug}"`);
|
|
83
|
+
const response = await fetch(`https://opensea.io/collection/${encodeURIComponent(slug)}`, {
|
|
84
|
+
headers: { 'User-Agent': user_agent_1.USER_AGENT, Accept: 'text/html' },
|
|
85
|
+
});
|
|
86
|
+
if (!response.ok) {
|
|
87
|
+
throw new Error(`OpenSea collection page returned ${response.status} ${response.statusText}. ` + FALLBACK_HINT);
|
|
88
|
+
}
|
|
89
|
+
const html = await response.text();
|
|
90
|
+
// Tally (contract → tokenIds) per chain so the dominant-contract rule and
|
|
91
|
+
// the ethereum-only guard can both give precise errors.
|
|
92
|
+
const byContract = new Map();
|
|
93
|
+
for (const match of html.matchAll(ITEM_PATTERN)) {
|
|
94
|
+
const [, chain, contract, tokenId] = match;
|
|
95
|
+
const key = contract.toLowerCase();
|
|
96
|
+
const entry = byContract.get(key) ?? { chain, tokenIds: [] };
|
|
97
|
+
entry.tokenIds.push(BigInt(tokenId));
|
|
98
|
+
byContract.set(key, entry);
|
|
99
|
+
}
|
|
100
|
+
if (byContract.size === 0) {
|
|
101
|
+
throw new Error(`OpenSea: no items found on the collection page for "${slug}". ` +
|
|
102
|
+
'The collection may be empty, or the page layout changed. ' +
|
|
103
|
+
FALLBACK_HINT);
|
|
104
|
+
}
|
|
105
|
+
let best = null;
|
|
106
|
+
for (const [contract, entry] of byContract) {
|
|
107
|
+
if (!best || entry.tokenIds.length > best.tokenIds.length) {
|
|
108
|
+
best = { contract, ...entry };
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// byContract.size > 0 guarantees best is set; the check keeps TS honest.
|
|
112
|
+
if (!best) {
|
|
113
|
+
throw new Error(`OpenSea: no items found for "${slug}". ${FALLBACK_HINT}`);
|
|
114
|
+
}
|
|
115
|
+
if (best.chain !== 'ethereum') {
|
|
116
|
+
throw new Error(`OpenSea collection "${slug}" is on ${best.chain} — ff-cli covers Ethereum and ` +
|
|
117
|
+
'Tezos mainnet only. Paste an Ethereum-chain source instead.');
|
|
118
|
+
}
|
|
119
|
+
const seed = best.tokenIds.reduce((min, id) => (id < min ? id : min));
|
|
120
|
+
logger.debug(`[OpenSea] Resolved "${slug}" → ${best.contract} (seed tokenId ${seed}, ` +
|
|
121
|
+
`${best.tokenIds.length} items sampled)`);
|
|
122
|
+
return { chain: 'ethereum', contract: best.contract, tokenId: seed.toString() };
|
|
123
|
+
}
|
|
@@ -2,8 +2,72 @@
|
|
|
2
2
|
* Playlist Builder Utilities
|
|
3
3
|
* Core functions for building and validating DP1 playlists
|
|
4
4
|
*/
|
|
5
|
-
const { getPlaylistConfig } = require('../config');
|
|
5
|
+
const { getPlaylistConfig, getConfig } = require('../config');
|
|
6
6
|
const { signPlaylist } = require('./playlist-signer');
|
|
7
|
+
/**
|
|
8
|
+
* isTimeBasedMedia reports whether an item's media has an intrinsic runtime
|
|
9
|
+
* (video or audio) per DP-1 §4.1 "time-based sources".
|
|
10
|
+
*
|
|
11
|
+
* Two signals are consulted because neither is reliable alone: indexer
|
|
12
|
+
* `display.mime_type` is authoritative when present but is defaulted to
|
|
13
|
+
* 'image/png' upstream when missing, and URL extensions only cover direct
|
|
14
|
+
* media links. Either signal saying video/audio wins.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} [mimeType] - MIME type reported by the indexer, if any
|
|
17
|
+
* @param {string} [sourceUrl] - Item source URL, used as an extension fallback
|
|
18
|
+
* @returns {boolean} True when the media is video or audio
|
|
19
|
+
*/
|
|
20
|
+
function isTimeBasedMedia(mimeType, sourceUrl) {
|
|
21
|
+
const candidates = [String(mimeType || '').toLowerCase(), detectMimeType(sourceUrl)];
|
|
22
|
+
return candidates.some((mime) => mime.startsWith('video/') || mime.startsWith('audio/'));
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* applyItemTiming sets a DP1 item's playback timing per DP-1 §4.1.
|
|
26
|
+
*
|
|
27
|
+
* Invariant this function owns: an explicit numeric `duration` always wins
|
|
28
|
+
* and is stamped as-is. When `duration` is undefined/null ("auto"), a
|
|
29
|
+
* time-based source (video/audio) gets NO duration and `display.loop: false`,
|
|
30
|
+
* so a conformant player MUST advance at end-of-stream — the media plays its
|
|
31
|
+
* natural length. Static and code-based sources fall back to the configured
|
|
32
|
+
* `defaultDuration` because they have no intrinsic runtime to play out.
|
|
33
|
+
*
|
|
34
|
+
* Do not re-introduce an unconditional duration here: stamping a default on
|
|
35
|
+
* video items silently truncates or pads them (the bug this fixed).
|
|
36
|
+
*
|
|
37
|
+
* @param {Object} item - DP1 playlist item (mutated in place)
|
|
38
|
+
* @param {Object} mediaHints - Media signals for the time-based check
|
|
39
|
+
* @param {string} [mediaHints.mimeType] - Indexer-reported MIME type
|
|
40
|
+
* @param {string} [mediaHints.sourceUrl] - Item source URL
|
|
41
|
+
* @param {number} [duration] - Explicit display seconds; omit for auto
|
|
42
|
+
* @returns {Object} The same item, for chaining
|
|
43
|
+
*/
|
|
44
|
+
function applyItemTiming(item, mediaHints = {}, duration) {
|
|
45
|
+
if (typeof duration === 'number') {
|
|
46
|
+
item.duration = duration;
|
|
47
|
+
return item;
|
|
48
|
+
}
|
|
49
|
+
if (isTimeBasedMedia(mediaHints.mimeType, mediaHints.sourceUrl)) {
|
|
50
|
+
item.display = { ...(item.display || {}), loop: false };
|
|
51
|
+
return item;
|
|
52
|
+
}
|
|
53
|
+
item.duration = getDefaultStaticDuration();
|
|
54
|
+
return item;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* getDefaultStaticDuration returns the configured per-item display seconds
|
|
58
|
+
* for media without an intrinsic runtime. Falls back to 10 when config is
|
|
59
|
+
* unavailable (e.g. unit tests without a config file).
|
|
60
|
+
*
|
|
61
|
+
* @returns {number} Display duration in seconds
|
|
62
|
+
*/
|
|
63
|
+
function getDefaultStaticDuration() {
|
|
64
|
+
try {
|
|
65
|
+
return getConfig().defaultDuration || 10;
|
|
66
|
+
}
|
|
67
|
+
catch (_error) {
|
|
68
|
+
return 10;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
7
71
|
/**
|
|
8
72
|
* Convert a string to a URL-friendly slug
|
|
9
73
|
*
|
|
@@ -31,14 +95,16 @@ function slugify(value) {
|
|
|
31
95
|
* Convert single NFT token info to DP1 playlist item
|
|
32
96
|
*
|
|
33
97
|
* @param {Object} tokenInfo - Token information from NFT indexer
|
|
34
|
-
* @param {number} duration -
|
|
98
|
+
* @param {number} [duration] - Explicit display seconds; omit for auto timing
|
|
99
|
+
* (video/audio play natural length per DP-1 §4.1, static media uses the
|
|
100
|
+
* configured default — see applyItemTiming)
|
|
35
101
|
* @returns {Object} DP1 playlist item
|
|
36
102
|
* @throws {Error} When token data is missing or source is a data URI
|
|
37
103
|
* @example
|
|
38
104
|
* const item = convertTokenToDP1ItemSingle(tokenInfo, 10);
|
|
39
105
|
* // Returns: { title, source, duration, license, provenance, ... }
|
|
40
106
|
*/
|
|
41
|
-
function convertTokenToDP1ItemSingle(tokenInfo, duration
|
|
107
|
+
function convertTokenToDP1ItemSingle(tokenInfo, duration) {
|
|
42
108
|
const { token } = tokenInfo;
|
|
43
109
|
if (!token) {
|
|
44
110
|
throw new Error('Invalid token info: missing token data');
|
|
@@ -75,7 +141,6 @@ function convertTokenToDP1ItemSingle(tokenInfo, duration = 10) {
|
|
|
75
141
|
id: itemId,
|
|
76
142
|
title: token.name || `Token #${token.tokenId}`,
|
|
77
143
|
source: sourceUrl,
|
|
78
|
-
duration: duration,
|
|
79
144
|
license: 'token', // NFTs are token-gated by default
|
|
80
145
|
created: new Date().toISOString(),
|
|
81
146
|
provenance: {
|
|
@@ -102,7 +167,7 @@ function convertTokenToDP1ItemSingle(tokenInfo, duration = 10) {
|
|
|
102
167
|
if ((token.animation_url || token.animationUrl) && (token.image?.url || token.image)) {
|
|
103
168
|
dp1Item.ref = token.image?.url || token.image;
|
|
104
169
|
}
|
|
105
|
-
return dp1Item;
|
|
170
|
+
return applyItemTiming(dp1Item, { mimeType: token.image?.mimeType, sourceUrl }, duration);
|
|
106
171
|
}
|
|
107
172
|
/**
|
|
108
173
|
* Convert NFT token info(s) to DP1 playlist item(s)
|
|
@@ -111,7 +176,7 @@ function convertTokenToDP1ItemSingle(tokenInfo, duration = 10) {
|
|
|
111
176
|
* For collections, returns a map of token key to DP1 item.
|
|
112
177
|
*
|
|
113
178
|
* @param {Object|Array} tokenInfo - Token information (single object or map of tokens)
|
|
114
|
-
* @param {number} duration -
|
|
179
|
+
* @param {number} [duration] - Explicit display seconds; omit for auto timing
|
|
115
180
|
* @returns {Object} Map of token key to DP1 playlist item, or single item
|
|
116
181
|
* @example
|
|
117
182
|
* // Single token
|
|
@@ -120,7 +185,7 @@ function convertTokenToDP1ItemSingle(tokenInfo, duration = 10) {
|
|
|
120
185
|
* // Multiple tokens
|
|
121
186
|
* const items = convertTokenToDP1Item({ token1: info1, token2: info2 }, 10);
|
|
122
187
|
*/
|
|
123
|
-
function convertTokenToDP1Item(tokenInfo, duration
|
|
188
|
+
function convertTokenToDP1Item(tokenInfo, duration) {
|
|
124
189
|
// Handle array or map of tokens
|
|
125
190
|
if (typeof tokenInfo === 'object' && !tokenInfo.token) {
|
|
126
191
|
const results = {};
|
|
@@ -163,12 +228,12 @@ function convertTokenToDP1Item(tokenInfo, duration = 10) {
|
|
|
163
228
|
* Excludes items with data URIs in their source field.
|
|
164
229
|
*
|
|
165
230
|
* @param {Array} tokensInfo - Array of token information
|
|
166
|
-
* @param {number} duration -
|
|
231
|
+
* @param {number} [duration] - Explicit display seconds; omit for auto timing
|
|
167
232
|
* @returns {Array} Array of DP1 playlist items
|
|
168
233
|
* @example
|
|
169
234
|
* const items = convertTokensToDP1Items(tokensInfoArray, 10);
|
|
170
235
|
*/
|
|
171
|
-
function convertTokensToDP1Items(tokensInfo, duration
|
|
236
|
+
function convertTokensToDP1Items(tokensInfo, duration) {
|
|
172
237
|
return tokensInfo
|
|
173
238
|
.filter((info) => info.success && info.token)
|
|
174
239
|
.map((info) => {
|
|
@@ -313,7 +378,10 @@ async function buildDP1Playlist(paramsOrItems, options = {}) {
|
|
|
313
378
|
margin: 0,
|
|
314
379
|
},
|
|
315
380
|
license: 'token',
|
|
316
|
-
duration:
|
|
381
|
+
// No defaults.duration: items that should be timed carry an explicit
|
|
382
|
+
// duration already, and a playlist-level default would make conformant
|
|
383
|
+
// players time-cut items that intentionally omit duration to play
|
|
384
|
+
// their natural length (DP-1 §4.1 end-of-stream advance).
|
|
317
385
|
},
|
|
318
386
|
};
|
|
319
387
|
// Always include slug (auto-generated when missing)
|
|
@@ -384,11 +452,14 @@ function validateDP1Playlist(playlist) {
|
|
|
384
452
|
else if (typeof item.source !== 'string') {
|
|
385
453
|
errors.push(`Item ${index}: Field "source" must be a string (URI)`);
|
|
386
454
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
455
|
+
// Duration is OPTIONAL per the DP-1 v1.1.0 schema (PlaylistItem requires
|
|
456
|
+
// only `source`; duration has `minimum: 0`). Absent duration is meaningful:
|
|
457
|
+
// time-based sources advance at end-of-stream (§4.1). Do not tighten this
|
|
458
|
+
// back to required — it would reject spec-valid playlists.
|
|
459
|
+
if (item.duration !== undefined && item.duration !== null) {
|
|
460
|
+
if (typeof item.duration !== 'number' || item.duration < 0) {
|
|
461
|
+
errors.push(`Item ${index}: Field "duration" must be a number >= 0`);
|
|
462
|
+
}
|
|
392
463
|
}
|
|
393
464
|
if (!item.license) {
|
|
394
465
|
errors.push(`Item ${index}: Missing required field "license"`);
|
|
@@ -461,12 +532,13 @@ function detectMimeType(url) {
|
|
|
461
532
|
* Build a single DP1 playlist item from a URL
|
|
462
533
|
*
|
|
463
534
|
* @param {string} url - Media URL
|
|
464
|
-
* @param {number} duration -
|
|
535
|
+
* @param {number} [duration] - Explicit display seconds; omit for auto timing
|
|
536
|
+
* (video/audio URLs play their natural length per DP-1 §4.1)
|
|
465
537
|
* @param {Object} [options] - Optional configuration
|
|
466
538
|
* @param {string} [options.title] - Optional item title override
|
|
467
539
|
* @returns {Object} DP1 playlist item
|
|
468
540
|
*/
|
|
469
|
-
function buildUrlItem(url, duration
|
|
541
|
+
function buildUrlItem(url, duration, options = {}) {
|
|
470
542
|
const sourceUrl = String(url || '').trim();
|
|
471
543
|
if (!sourceUrl) {
|
|
472
544
|
throw new Error('URL is required to build a playlist item');
|
|
@@ -496,7 +568,6 @@ function buildUrlItem(url, duration = 10, options = {}) {
|
|
|
496
568
|
id: itemId,
|
|
497
569
|
title,
|
|
498
570
|
source: sourceUrl,
|
|
499
|
-
duration: duration,
|
|
500
571
|
license: 'open',
|
|
501
572
|
created: new Date().toISOString(),
|
|
502
573
|
provenance: {
|
|
@@ -509,7 +580,7 @@ function buildUrlItem(url, duration = 10, options = {}) {
|
|
|
509
580
|
margin: 0,
|
|
510
581
|
},
|
|
511
582
|
};
|
|
512
|
-
return item;
|
|
583
|
+
return applyItemTiming(item, { sourceUrl }, duration);
|
|
513
584
|
}
|
|
514
585
|
module.exports = {
|
|
515
586
|
convertTokenToDP1Item,
|
|
@@ -519,5 +590,7 @@ module.exports = {
|
|
|
519
590
|
buildDP1Playlist,
|
|
520
591
|
validateDP1Playlist,
|
|
521
592
|
detectMimeType,
|
|
593
|
+
isTimeBasedMedia,
|
|
594
|
+
applyItemTiming,
|
|
522
595
|
buildUrlItem,
|
|
523
596
|
};
|
|
@@ -93,7 +93,9 @@ async function loadPlaylistSource(source) {
|
|
|
93
93
|
* `loadedAsPlaylist` boolean dance.
|
|
94
94
|
*
|
|
95
95
|
* @param source - User-supplied path or URL
|
|
96
|
-
* @param defaultDuration -
|
|
96
|
+
* @param defaultDuration - Explicit duration (seconds) for the synthesized
|
|
97
|
+
* media item; omit for auto timing (video/audio URLs play their natural
|
|
98
|
+
* length per DP-1 §4.1, static media uses the configured default)
|
|
97
99
|
* @returns Resolved playlist + metadata describing how it was loaded
|
|
98
100
|
* @throws Error When `source` is empty, or is a non-URL file path that cannot be loaded
|
|
99
101
|
*/
|
package/docs/CONFIGURATION.md
CHANGED
|
@@ -26,7 +26,8 @@ npm run dev -- config show
|
|
|
26
26
|
- Used by orchestration to pick API, timeouts, and model identifier.
|
|
27
27
|
|
|
28
28
|
- **defaultDuration** (number, seconds)
|
|
29
|
-
-
|
|
29
|
+
- Default per‑item display duration for media without an intrinsic runtime (images, code-based works). Falls back to 10s when unset.
|
|
30
|
+
- Does NOT apply to video/audio items: with no explicit duration those are emitted without `duration` and with `display.loop: false`, so a DP-1 player advances at end-of-stream (§4.1) — the media plays its natural length.
|
|
30
31
|
|
|
31
32
|
## models
|
|
32
33
|
|
package/docs/FUNCTION_CALLING.md
CHANGED
|
@@ -75,12 +75,14 @@ Two options are available:
|
|
|
75
75
|
"quantity": 2
|
|
76
76
|
}
|
|
77
77
|
],
|
|
78
|
-
"playlistSettings": { "
|
|
78
|
+
"playlistSettings": { "preserveOrder": true, "title": "My Mix" }
|
|
79
79
|
}
|
|
80
80
|
```
|
|
81
81
|
|
|
82
82
|
This path bypasses the intent parser/orchestrator and calls utilities directly. Validation and sensible defaults are applied in `src/main.ts`.
|
|
83
83
|
|
|
84
|
+
`playlistSettings.durationPerItem` is optional. Omit it for auto timing: video/audio items are emitted without `duration` and with `display.loop: false`, so a DP-1 player advances at end-of-stream (§4.1) and the media plays its natural length; static items fall back to `defaultDuration`. Set `durationPerItem` only to force a fixed display time on every item.
|
|
85
|
+
|
|
84
86
|
2. AI‑orchestrated deterministic build (recommended for prompts): Use `chat` with `--verbose` to see tool calls. The orchestrator enforces complete requirement objects, then runs `verify_playlist` (structure only) before sending.
|
|
85
87
|
|
|
86
88
|
## Extending Functionality (OSS‑first)
|
package/docs/README.md
CHANGED
|
@@ -148,6 +148,7 @@ Notes:
|
|
|
148
148
|
- Options: `-d, --device <name>`, `--skip-verify` (skip signature verification; not recommended)
|
|
149
149
|
- `find <input>` – Resolve a marketplace URL, raw `chain:contract:tokenId`, or wallet address into a playable DP-1 playlist
|
|
150
150
|
- Sources: Art Blocks, Objkt, fxhash, OpenSea, SuperRare, Feral File, Neort, Verse, raw on-chain coordinates, and wallet addresses
|
|
151
|
+
- OpenSea forms: `/assets/ethereum/{contract}/{tokenId}`, `/item/ethereum/{contract}/{tokenId}`, and `/collection/{slug}` (Ethereum collections; the slug is resolved from the public collection page, no API key needed)
|
|
151
152
|
- Verse forms: `/items/ethereum/{contract}/{tokenId}` and `/series/{slug}`
|
|
152
153
|
- Options: `-o, --output <path>`, `-l, --limit <n>`, `-p, --play`, `-d, --device <name>`, `--publish`, `-s, --server <index>`, `-y, --yes`, `--skip-verify`
|
|
153
154
|
- `publish <file>` – Publish a playlist to a feed server (runs `verify` before upload and rejects unsigned or broken playlists)
|
|
@@ -343,7 +344,7 @@ Setup preserves existing devices when adding new ones. See selection rules and e
|
|
|
343
344
|
|
|
344
345
|
- Max 20 items total across all requirements
|
|
345
346
|
- Per-source caps enforced in utilities
|
|
346
|
-
-
|
|
347
|
+
- Per-item timing: when no duration is given, video/audio items carry **no** `duration` and `display.loop: false`, so the player advances at end-of-stream (DP-1 §4.1) — the media plays its natural length. Static items use `defaultDuration` (10s unless configured). An explicit duration always wins.
|
|
347
348
|
|
|
348
349
|
## Links
|
|
349
350
|
|