@larkup/tool-video-intelligence 0.3.0 → 0.3.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/dist/agent.js +96 -31
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/tool.manifest.json +1 -1
package/dist/agent.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { trackUsageEvent } from '@larkup/core/analytics-store';
|
|
2
2
|
const MAX_INSPECTION_CHUNK_SECS = 60;
|
|
3
|
+
const POINT_QUERY_RADIUS_SECS = MAX_INSPECTION_CHUNK_SECS / 2;
|
|
4
|
+
const FOCUSED_SUBJECT_CONTEXT_SECS = 30;
|
|
3
5
|
const OUTCOME_RESOLUTION_WINDOW_SECS = 30;
|
|
4
6
|
/** How much source a single targeted look covers on each side of a located moment. */
|
|
5
7
|
const TARGET_PADDING_SECS = 8;
|
|
6
8
|
/** Independent looks dispatched together before the next wave starts. */
|
|
7
9
|
const MAX_PARALLEL_INSPECTIONS = 4;
|
|
8
10
|
/** The whole evidence-query fallback shares one deadline, including re-watch. */
|
|
9
|
-
const INTERACTIVE_INSPECTION_BUDGET_MS =
|
|
11
|
+
const INTERACTIVE_INSPECTION_BUDGET_MS = 40_000;
|
|
10
12
|
/** Leave part of the shared deadline for a provider-backed inspection if needed. */
|
|
11
13
|
const INTERACTIVE_REWATCH_BUDGET_MS = 12_000;
|
|
12
14
|
/** Chat actions stay inside the installed tool; the host only sees workflow roles. */
|
|
@@ -122,6 +124,14 @@ export function attachVideoIntelligenceAgentClient(client, fetcher = globalThis.
|
|
|
122
124
|
exhaustive: input.exhaustive ?? plan.requiresBroadCoverage === true,
|
|
123
125
|
};
|
|
124
126
|
const durationSecs = asset.durationSecs;
|
|
127
|
+
// The compact aggregate is revision-cached and carries protocol-backed
|
|
128
|
+
// source questions and visual sightings that ranked snippets can split
|
|
129
|
+
// apart. Load it before either answer path so even a conservative source
|
|
130
|
+
// scan retains the visibility ledger when the conversational planner
|
|
131
|
+
// chooses a broader record set than `observed`.
|
|
132
|
+
const aggregate = mediaEvidence.aggregate
|
|
133
|
+
? await mediaEvidence.aggregate(input.mediaAssetId)
|
|
134
|
+
: undefined;
|
|
125
135
|
// Complete inventories are a deterministic database scan, never an
|
|
126
136
|
// expanded Top-K query. The chat route follows the opaque cursor itself,
|
|
127
137
|
// so a model cannot stop early or mistake its context window for source
|
|
@@ -167,11 +177,13 @@ export function attachVideoIntelligenceAgentClient(client, fetcher = globalThis.
|
|
|
167
177
|
latencyMs: Date.now() - startedAt,
|
|
168
178
|
timestamp: new Date().toISOString(),
|
|
169
179
|
});
|
|
180
|
+
const observedSubjects = observedSubjectsForAnswer(aggregate, directive);
|
|
170
181
|
return {
|
|
171
182
|
success: true,
|
|
172
183
|
mediaAssetId: input.mediaAssetId,
|
|
173
184
|
fileName: asset.fileName,
|
|
174
185
|
evidence,
|
|
186
|
+
...(observedSubjects.length > 0 ? { observedSubjects } : {}),
|
|
175
187
|
inventory: {
|
|
176
188
|
recordSet: focusedInput.investigation.recordSet ?? 'all',
|
|
177
189
|
coverage: {
|
|
@@ -217,12 +229,6 @@ export function attachVideoIntelligenceAgentClient(client, fetcher = globalThis.
|
|
|
217
229
|
};
|
|
218
230
|
}
|
|
219
231
|
}
|
|
220
|
-
// The compact aggregate is revision-cached and carries protocol-backed
|
|
221
|
-
// source questions and visual sightings that ranked snippets can split
|
|
222
|
-
// apart. It is navigation material, not a substitute for source truth.
|
|
223
|
-
const aggregate = mediaEvidence.aggregate
|
|
224
|
-
? await mediaEvidence.aggregate(input.mediaAssetId)
|
|
225
|
-
: undefined;
|
|
226
232
|
// Start with the index alone. Planning and visual locating are useful
|
|
227
233
|
// fallbacks, but waiting for both before checking an already-complete RAG
|
|
228
234
|
// answer made simple questions feel like analysis jobs.
|
|
@@ -230,10 +236,11 @@ export function attachVideoIntelligenceAgentClient(client, fetcher = globalThis.
|
|
|
230
236
|
// merely another ranking signal. Read that bounded part of the index
|
|
231
237
|
// first so a whole-recording overview cannot displace its evidence.
|
|
232
238
|
const explicitRanges = directiveTimeRange(directive, durationSecs);
|
|
239
|
+
const explicitLookupRanges = directiveLookupRanges(directive, durationSecs);
|
|
233
240
|
const [rankedHits, explicitlyScopedHits] = await Promise.all([
|
|
234
241
|
retrieve(mediaEvidence, focusedInput, plan, durationSecs),
|
|
235
|
-
|
|
236
|
-
? retrieveEvidenceInRanges(mediaEvidence, focusedInput, plan, durationSecs,
|
|
242
|
+
explicitLookupRanges.length > 0
|
|
243
|
+
? retrieveEvidenceInRanges(mediaEvidence, focusedInput, plan, durationSecs, explicitLookupRanges)
|
|
237
244
|
: Promise.resolve([]),
|
|
238
245
|
]);
|
|
239
246
|
let hits = mergeHits(explicitlyScopedHits, rankedHits, aggregate ? aggregateToHits(aggregate) : []);
|
|
@@ -287,6 +294,7 @@ export function attachVideoIntelligenceAgentClient(client, fetcher = globalThis.
|
|
|
287
294
|
const established = readings.filter((reading) => reading.settlesQuestion && reading.found.trim());
|
|
288
295
|
if (established.length > 0) {
|
|
289
296
|
const supportingClip = established[0].range;
|
|
297
|
+
const observedSubjects = observedSubjectsForAnswer(aggregate, focusedInput.investigation);
|
|
290
298
|
const indexedEvidence = evidenceHitsFor(hits, assessment, plan, focusedInput, durationSecs);
|
|
291
299
|
return {
|
|
292
300
|
success: true,
|
|
@@ -327,9 +335,7 @@ export function attachVideoIntelligenceAgentClient(client, fetcher = globalThis.
|
|
|
327
335
|
coverage: investigation?.coverage,
|
|
328
336
|
directive: investigationDirectiveForOutput(focusedInput.investigation),
|
|
329
337
|
},
|
|
330
|
-
...(
|
|
331
|
-
? { observedSubjects: aggregate.visibleSubjects }
|
|
332
|
-
: {}),
|
|
338
|
+
...(observedSubjects.length > 0 ? { observedSubjects } : {}),
|
|
333
339
|
...(focusedInput.exhaustive
|
|
334
340
|
? { continuation: exhaustiveContinuation(hits, assessment, focusedInput) }
|
|
335
341
|
: {}),
|
|
@@ -386,12 +392,7 @@ export function attachVideoIntelligenceAgentClient(client, fetcher = globalThis.
|
|
|
386
392
|
const supportingClip = plan.kinds.includes('outcome')
|
|
387
393
|
? evidence.at(-1)?.timeRange
|
|
388
394
|
: evidence[0]?.timeRange;
|
|
389
|
-
|
|
390
|
-
// question, but it is dangerous extra context for a single requested
|
|
391
|
-
// moment: a renderer can accidentally combine a remote appearance with
|
|
392
|
-
// that moment. The selected evidence already carries any ledger entry
|
|
393
|
-
// whose explicit interval overlaps the focused request.
|
|
394
|
-
const includeObservedSubjects = shouldIncludeObservedSubjects(aggregate, focusedInput.investigation, plan);
|
|
395
|
+
const observedSubjects = observedSubjectsForAnswer(aggregate, focusedInput.investigation);
|
|
395
396
|
const responseTimeMs = Date.now() - startedAt;
|
|
396
397
|
const answerPath = analyzedRanges.length > 0 ? 'rag+analysis' : 'rag';
|
|
397
398
|
void trackUsageEvent({
|
|
@@ -438,7 +439,7 @@ export function attachVideoIntelligenceAgentClient(client, fetcher = globalThis.
|
|
|
438
439
|
coverage: investigation?.coverage,
|
|
439
440
|
directive: investigationDirectiveForOutput(focusedInput.investigation),
|
|
440
441
|
},
|
|
441
|
-
...(
|
|
442
|
+
...(observedSubjects.length > 0 ? { observedSubjects } : {}),
|
|
442
443
|
...(focusedInput.exhaustive
|
|
443
444
|
? { continuation: exhaustiveContinuation(hits, assessment, focusedInput) }
|
|
444
445
|
: {}),
|
|
@@ -493,12 +494,15 @@ function explicitlyRequestedMomentEvidence(hits, plan, durationSecs) {
|
|
|
493
494
|
const requestedRanges = directiveTimeRange(plan.investigation, durationSecs);
|
|
494
495
|
if (requestedRanges.length === 0)
|
|
495
496
|
return [];
|
|
496
|
-
const scoped = hits.filter((hit) =>
|
|
497
|
-
|
|
497
|
+
const scoped = hits.filter((hit) => evidenceOverlapsRanges(hit, requestedRanges));
|
|
498
|
+
const contextualRanges = directiveLookupRanges(plan.investigation, durationSecs);
|
|
499
|
+
const surrounding = hits.filter((hit) => evidenceOverlapsRanges(hit, contextualRanges) &&
|
|
500
|
+
hit.evidence.modality === 'visual' &&
|
|
501
|
+
isAccountOfMoment(hit));
|
|
498
502
|
return mergeHits(scoped.filter((hit) => hit.evidence.modality === 'visual' && isAccountOfMoment(hit)), scoped.filter((hit) => {
|
|
499
503
|
const text = evidenceText(hit.evidence.payload);
|
|
500
504
|
return /^Reconciled visible subject:\s*[^\n]+\nIdentity basis:/im.test(text);
|
|
501
|
-
}), scoped.filter(isAccountOfMoment)).slice(0, 4);
|
|
505
|
+
}), surrounding, scoped.filter(isAccountOfMoment)).slice(0, 4);
|
|
502
506
|
}
|
|
503
507
|
/**
|
|
504
508
|
* Keep the source-navigation decision alongside the evidence it governed.
|
|
@@ -513,11 +517,18 @@ function investigationDirectiveForOutput(directive) {
|
|
|
513
517
|
...(directive.timeRange ? { timeRange: directive.timeRange } : {}),
|
|
514
518
|
};
|
|
515
519
|
}
|
|
516
|
-
function
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
520
|
+
function observedSubjectsForAnswer(aggregate, directive) {
|
|
521
|
+
const subjects = aggregate?.visibleSubjects ?? [];
|
|
522
|
+
const requestedRanges = directiveTimeRange(directive, undefined);
|
|
523
|
+
if (directive.scope !== 'focused' || requestedRanges.length === 0)
|
|
524
|
+
return subjects;
|
|
525
|
+
// A focused answer needs nearby identity anchors, not every person seen in
|
|
526
|
+
// a long recording. Visibility is sampled, so allow a small symmetric
|
|
527
|
+
// context around the requested interval; this joins neighbouring semantic
|
|
528
|
+
// scene descriptions without attaching a remote recurring participant to
|
|
529
|
+
// the local moment.
|
|
530
|
+
return subjects.filter((subject) => subject.appearances.some((appearance) => requestedRanges.some((range) => appearance.startSecs <= range.endSecs + FOCUSED_SUBJECT_CONTEXT_SECS &&
|
|
531
|
+
appearance.endSecs >= range.startSecs - FOCUSED_SUBJECT_CONTEXT_SECS)));
|
|
521
532
|
}
|
|
522
533
|
function scanRecordToEvidence(record) {
|
|
523
534
|
const prefix = record.kind === 'question'
|
|
@@ -1399,10 +1410,38 @@ function directiveTimeRange(directive, durationSecs) {
|
|
|
1399
1410
|
if (!requested)
|
|
1400
1411
|
return [];
|
|
1401
1412
|
const limit = durationSecs && Number.isFinite(durationSecs) && durationSecs > 0 ? durationSecs : Infinity;
|
|
1402
|
-
const
|
|
1403
|
-
const
|
|
1413
|
+
const requestedStart = Math.max(0, Math.min(limit, requested.startSecs));
|
|
1414
|
+
const requestedEnd = Math.max(requestedStart, Math.min(limit, requested.endSecs));
|
|
1415
|
+
// Models commonly encode "at 14:00" as an equal start/end boundary. A
|
|
1416
|
+
// zero-length range must not erase the user's timestamp and fall back to
|
|
1417
|
+
// whole-source ranking. Treat a point as one bounded viewing window.
|
|
1418
|
+
const startSecs = requestedEnd === requestedStart
|
|
1419
|
+
? Math.max(0, requestedStart - POINT_QUERY_RADIUS_SECS)
|
|
1420
|
+
: requestedStart;
|
|
1421
|
+
const endSecs = requestedEnd === requestedStart
|
|
1422
|
+
? Math.min(limit, requestedEnd + POINT_QUERY_RADIUS_SECS)
|
|
1423
|
+
: requestedEnd;
|
|
1404
1424
|
return endSecs > startSecs ? [{ startSecs, endSecs }] : [];
|
|
1405
1425
|
}
|
|
1426
|
+
function directiveLookupRanges(directive, durationSecs) {
|
|
1427
|
+
const ranges = directiveTimeRange(directive, durationSecs);
|
|
1428
|
+
const requested = directive?.timeRange;
|
|
1429
|
+
if (!requested || requested.endSecs === requested.startSecs)
|
|
1430
|
+
return ranges;
|
|
1431
|
+
const limit = durationSecs && Number.isFinite(durationSecs) && durationSecs > 0 ? durationSecs : Infinity;
|
|
1432
|
+
return ranges.map((range) => ({
|
|
1433
|
+
startSecs: Math.max(0, range.startSecs - FOCUSED_SUBJECT_CONTEXT_SECS),
|
|
1434
|
+
endSecs: Math.min(limit, range.endSecs + FOCUSED_SUBJECT_CONTEXT_SECS),
|
|
1435
|
+
}));
|
|
1436
|
+
}
|
|
1437
|
+
function evidenceOverlapsRanges(hit, ranges) {
|
|
1438
|
+
const text = evidenceText(hit.evidence.payload);
|
|
1439
|
+
const observedRanges = /^Reconciled visible subject:\s*[^\n]+\nIdentity basis:/im.test(text)
|
|
1440
|
+
? observedAppearanceRanges(text)
|
|
1441
|
+
: [];
|
|
1442
|
+
const evidenceRanges = observedRanges.length > 0 ? observedRanges : [hit.evidence.timeRange];
|
|
1443
|
+
return evidenceRanges.some((candidate) => ranges.some((range) => candidate.startSecs < range.endSecs && candidate.endSecs > range.startSecs));
|
|
1444
|
+
}
|
|
1406
1445
|
/**
|
|
1407
1446
|
* An indexed account that explicitly describes a late transition is a better
|
|
1408
1447
|
* first look than a fixed percentage of the file. It remains only a locator:
|
|
@@ -1673,6 +1712,13 @@ function selectAnswerEvidence(hits, assessment, plan, input, durationSecs) {
|
|
|
1673
1712
|
.slice(0, limit);
|
|
1674
1713
|
}
|
|
1675
1714
|
const limit = Math.min(input.limit ?? (plan.requiresBothRanges || isCrossEvidenceClaim(plan) ? 12 : 8), 12);
|
|
1715
|
+
const requestedRanges = directiveTimeRange(plan.investigation, durationSecs);
|
|
1716
|
+
if (requestedRanges.length > 0 && !assessment.sufficient) {
|
|
1717
|
+
const contextualRanges = directiveLookupRanges(plan.investigation, durationSecs);
|
|
1718
|
+
const local = hits.filter((hit) => evidenceOverlapsRanges(hit, contextualRanges) && isAccountOfMoment(hit));
|
|
1719
|
+
if (local.length > 0)
|
|
1720
|
+
return reconciledFirst(local).slice(0, limit);
|
|
1721
|
+
}
|
|
1676
1722
|
if (assessment.establishedByTrail) {
|
|
1677
1723
|
// A trail can exist while `established` is empty: the trail settles the
|
|
1678
1724
|
// claim, but only a question about unnamed subjects promotes it into
|
|
@@ -1908,6 +1954,9 @@ function answeringRule(assessment, plan, analysisUnavailable) {
|
|
|
1908
1954
|
return 'The returned evidence does not settle this. Say which part is established and which part the source did not show, rather than inferring the rest.';
|
|
1909
1955
|
}
|
|
1910
1956
|
if (assessment.needsBreadth) {
|
|
1957
|
+
if (plan.kinds.includes('entity-inventory')) {
|
|
1958
|
+
return 'These are the frame-grounded visible-subject observations retained across the source. Include every returned named and unnamed subject with its observed times. The list is complete for the active observation ledger, but sampled intervals do not prove that nobody appeared between observations; never turn an omitted or unsampled moment into an absence claim.';
|
|
1959
|
+
}
|
|
1911
1960
|
return plan.kinds.includes('state-change')
|
|
1912
1961
|
? 'These are timestamped source observations selected across the video. Give the account in their order, keep their timestamps for specific claims, and say where the source is silent rather than filling the gap.'
|
|
1913
1962
|
: 'The evidence is distributed across the source. Synthesize the requested complete list or overview, deduplicate repeated items, preserve timestamps for specific claims, and state any explicit coverage limitation without exposing the evidence-gathering process.';
|
|
@@ -1979,7 +2028,13 @@ function createInspector(fetcher) {
|
|
|
1979
2028
|
// The server has its own worker deadline, but a network socket or a
|
|
1980
2029
|
// wedged control-plane request can otherwise outlive it indefinitely.
|
|
1981
2030
|
// Keep a chat turn responsive even when that happens.
|
|
1982
|
-
const
|
|
2031
|
+
const serverBudgetMs = Math.max(1, Math.floor(input.maxWaitMs ?? INTERACTIVE_INSPECTION_BUDGET_MS));
|
|
2032
|
+
// The inspection route returns a bounded timeout result when its worker
|
|
2033
|
+
// budget expires. Give that HTTP response a small transport grace period
|
|
2034
|
+
// instead of aborting at the exact same millisecond and misreporting a
|
|
2035
|
+
// result that the server is concurrently persisting.
|
|
2036
|
+
const transportGraceMs = Math.min(5_000, Math.max(250, Math.floor(serverBudgetMs * 0.1)));
|
|
2037
|
+
const timeoutMs = serverBudgetMs + transportGraceMs;
|
|
1983
2038
|
try {
|
|
1984
2039
|
const response = await fetcher(url, {
|
|
1985
2040
|
method: 'POST',
|
|
@@ -2143,7 +2198,10 @@ function isAccountOfMoment(hit) {
|
|
|
2143
2198
|
? payload.text
|
|
2144
2199
|
: payload;
|
|
2145
2200
|
// A typed subject/property/value locates a display; it does not describe it.
|
|
2146
|
-
|
|
2201
|
+
if (typeof text !== 'string')
|
|
2202
|
+
return false;
|
|
2203
|
+
const normalized = text.trim();
|
|
2204
|
+
return normalized.length > 0 && !/^Detected objects:/i.test(normalized);
|
|
2147
2205
|
}
|
|
2148
2206
|
function isIndexedDirectObservation(hit, question, plan) {
|
|
2149
2207
|
const text = evidenceText(hit.evidence.payload);
|
|
@@ -2156,6 +2214,13 @@ function isIndexedDirectObservation(hit, question, plan) {
|
|
|
2156
2214
|
/^Reconciled visible subject:\s*[^\n]+\nIdentity basis:\s*(?:source-named|source-described|unresolved)\nObserved appearances:\s*\d/im.test(text);
|
|
2157
2215
|
if (!['transcript', 'ocr', 'visual'].includes(hit.evidence.modality) && !reconciledVisibility)
|
|
2158
2216
|
return false;
|
|
2217
|
+
// Speech at the requested timestamp can establish what is being discussed,
|
|
2218
|
+
// but it cannot by itself identify who or what is visibly on screen.
|
|
2219
|
+
if (plan?.kinds.includes('visual-fact') &&
|
|
2220
|
+
hit.evidence.modality !== 'visual' &&
|
|
2221
|
+
!reconciledVisibility) {
|
|
2222
|
+
return false;
|
|
2223
|
+
}
|
|
2159
2224
|
// Raw OCR/detection payloads locate a moment but do not recount what was
|
|
2160
2225
|
// observed there. A broad recurring overlay must never become evidence that
|
|
2161
2226
|
// a person, animal, event, or other subject was present at that timestamp.
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export * from './ui.js';
|
|
|
9
9
|
export declare const TOOL_META: {
|
|
10
10
|
readonly id: "video-intelligence";
|
|
11
11
|
readonly name: "Video Intelligence";
|
|
12
|
-
readonly version: "0.3.
|
|
12
|
+
readonly version: "0.3.2";
|
|
13
13
|
};
|
|
14
14
|
export declare const TOOL_EXTENSION: {
|
|
15
15
|
id: "video-intelligence";
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ export * from './ui.js';
|
|
|
11
11
|
export const TOOL_META = {
|
|
12
12
|
id: 'video-intelligence',
|
|
13
13
|
name: 'Video Intelligence',
|
|
14
|
-
version: '0.3.
|
|
14
|
+
version: '0.3.2',
|
|
15
15
|
};
|
|
16
16
|
/** Managed infrastructure stays an implementation detail of Larkup Cloud. */
|
|
17
17
|
const MANAGED_CLOUD_ENDPOINT = process.env.LARKUP_VIDEO_INTELLIGENCE_CLOUD_ENDPOINT ??
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@larkup/tool-video-intelligence",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Installable local and cloud video intelligence with evidence-first indexing.",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -55,13 +55,13 @@
|
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@larkup/core": "0.7.
|
|
58
|
+
"@larkup/core": "0.7.2"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/node": "^26",
|
|
62
62
|
"typescript": "^7.0.2",
|
|
63
63
|
"vitest": "^5.0.0",
|
|
64
|
-
"@larkup/marketplace": "0.3.
|
|
64
|
+
"@larkup/marketplace": "0.3.3"
|
|
65
65
|
},
|
|
66
66
|
"publishConfig": {
|
|
67
67
|
"access": "public"
|
package/tool.manifest.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"description": "Help your AI understand your videos, so you can ask questions and get answers from the right moments.",
|
|
8
8
|
"longDescription": "Turn videos into knowledge your AI can understand. It listens to what is said, reads what appears on screen, and helps you find the moments that matter.",
|
|
9
9
|
"category": "media",
|
|
10
|
-
"version": "0.3.
|
|
10
|
+
"version": "0.3.2",
|
|
11
11
|
"pricing": "free",
|
|
12
12
|
"emoji": "🎥",
|
|
13
13
|
"icon": "Film",
|