@larkup/tool-video-intelligence 0.3.14 → 0.3.15
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 +8 -1
- package/dist/identity-grounding.d.ts +2 -0
- package/dist/identity-grounding.js +154 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/tool.manifest.json +1 -1
package/dist/agent.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { groundVideoIdentityEvidence } from './identity-grounding.js';
|
|
1
2
|
import { VIDEO_INVESTIGATION_GUIDE } from './investigation-skills.js';
|
|
2
3
|
import { trackUsageEvent } from '@larkup/core/analytics-store';
|
|
3
4
|
const MAX_INSPECTION_CHUNK_SECS = 60;
|
|
@@ -93,7 +94,7 @@ export const AGENT_TOOLS = [
|
|
|
93
94
|
];
|
|
94
95
|
export function attachVideoIntelligenceAgentClient(client, fetcher = globalThis.fetch) {
|
|
95
96
|
const inspectVideoKnowledge = createInspector(fetcher);
|
|
96
|
-
|
|
97
|
+
const actions = {
|
|
97
98
|
inspectVideoKnowledge,
|
|
98
99
|
async queryVideoEvidence(input, context) {
|
|
99
100
|
if (!isValidQueryInput(input))
|
|
@@ -458,6 +459,12 @@ export function attachVideoIntelligenceAgentClient(client, fetcher = globalThis.
|
|
|
458
459
|
...temporalContextResult(hits, plan),
|
|
459
460
|
};
|
|
460
461
|
},
|
|
462
|
+
};
|
|
463
|
+
return Object.assign(client, {
|
|
464
|
+
...actions,
|
|
465
|
+
async queryVideoEvidence(input, context) {
|
|
466
|
+
return groundVideoIdentityEvidence(await actions.queryVideoEvidence(input, context));
|
|
467
|
+
},
|
|
461
468
|
});
|
|
462
469
|
}
|
|
463
470
|
/**
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
const record = (value) => value && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
|
|
2
|
+
const key = (value) => value.normalize('NFKC').toLocaleLowerCase().trim();
|
|
3
|
+
const label = (value) => (typeof value === 'string' ? value.trim() : '');
|
|
4
|
+
function mentions(text, name) {
|
|
5
|
+
const escaped = name.normalize('NFKC').replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
6
|
+
return new RegExp(`(?<![\\p{L}\\p{N}_])${escaped}(?![\\p{L}\\p{N}_])`, 'iu').test(text.normalize('NFKC'));
|
|
7
|
+
}
|
|
8
|
+
/** Project source records into answer evidence without changing the stored index. */
|
|
9
|
+
export function groundVideoIdentityEvidence(value) {
|
|
10
|
+
const input = record(value);
|
|
11
|
+
if (!input || !Array.isArray(input.evidence))
|
|
12
|
+
return value;
|
|
13
|
+
const subjects = Array.isArray(input.observedSubjects) ? input.observedSubjects : [];
|
|
14
|
+
const knownIdentities = subjects.flatMap((item) => {
|
|
15
|
+
const subject = record(item);
|
|
16
|
+
return subject && label(subject.identity) ? [label(subject.identity)] : [];
|
|
17
|
+
});
|
|
18
|
+
let withheld = 0;
|
|
19
|
+
const authored = ['source-authored', 'source-questions', 'speech'].includes(label(record(input.inventory)?.recordSet));
|
|
20
|
+
const sanitize = (text, timeRange, context = text) => {
|
|
21
|
+
if (!text.trim())
|
|
22
|
+
return text;
|
|
23
|
+
const local = context.split(/\r?\n/).flatMap((line) => {
|
|
24
|
+
if (!line.startsWith('Visible subject:'))
|
|
25
|
+
return [];
|
|
26
|
+
try {
|
|
27
|
+
const item = record(JSON.parse(line.slice('Visible subject:'.length)));
|
|
28
|
+
return item ? [item] : [];
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
const allowed = new Set(local
|
|
35
|
+
.filter((item) => item.identityBasis === 'source-named' || item.identityBasis === 'source-described')
|
|
36
|
+
.map((item) => key(label(item.identity))));
|
|
37
|
+
// An identity established elsewhere is useful only at its observed range.
|
|
38
|
+
for (const item of subjects) {
|
|
39
|
+
const subject = record(item);
|
|
40
|
+
if (!subject ||
|
|
41
|
+
!['source-named', 'source-described'].includes(label(subject.identityBasis)) ||
|
|
42
|
+
!timeRange ||
|
|
43
|
+
!Array.isArray(subject.appearances))
|
|
44
|
+
continue;
|
|
45
|
+
if (subject.appearances.some((entry) => {
|
|
46
|
+
const range = record(entry);
|
|
47
|
+
return (range &&
|
|
48
|
+
typeof range.startSecs === 'number' &&
|
|
49
|
+
typeof range.endSecs === 'number' &&
|
|
50
|
+
typeof timeRange.startSecs === 'number' &&
|
|
51
|
+
typeof timeRange.endSecs === 'number' &&
|
|
52
|
+
range.startSecs <= timeRange.endSecs &&
|
|
53
|
+
range.endSecs >= timeRange.startSecs);
|
|
54
|
+
}))
|
|
55
|
+
allowed.add(key(label(subject.identity)));
|
|
56
|
+
}
|
|
57
|
+
for (const item of local)
|
|
58
|
+
if (item.identityBasis === 'unresolved')
|
|
59
|
+
allowed.delete(key(label(item.identity)));
|
|
60
|
+
const candidates = [
|
|
61
|
+
...knownIdentities,
|
|
62
|
+
...local
|
|
63
|
+
.filter((item) => item.identityBasis === 'unresolved')
|
|
64
|
+
.map((item) => label(item.identity)),
|
|
65
|
+
...Array.from(context.matchAll(/^Present:\s*(.+?)\s+—/gm), (match) => match[1].trim()),
|
|
66
|
+
];
|
|
67
|
+
const blocked = [...new Set(candidates.filter((name) => name && !allowed.has(key(name))))];
|
|
68
|
+
const hasProtocol = /^(?:Visible subject:|Present:|On screen:|Happened(?: \(inferred\))?:|Direct component:|Claim bindings:)/mu.test(context);
|
|
69
|
+
const lines = text.split(/\r?\n/).filter((line) => {
|
|
70
|
+
const inferred = /^Happened \(inferred\):/u.test(line);
|
|
71
|
+
const unsafe = !line.startsWith('On screen:') && blocked.some((name) => mentions(line, name));
|
|
72
|
+
// Legacy prose can bind unlisted actors or repeat inferred events as facts.
|
|
73
|
+
const unqualifiedSummary = text === context && hasProtocol && line.trim() && !/^[\w -]+:/.test(line);
|
|
74
|
+
if (inferred || unsafe || unqualifiedSummary) {
|
|
75
|
+
withheld++;
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
return true;
|
|
79
|
+
});
|
|
80
|
+
return (lines.join('\n').trim() ||
|
|
81
|
+
'Visual attribution withheld: the source does not establish the actor identity or action.');
|
|
82
|
+
};
|
|
83
|
+
const byId = new Map();
|
|
84
|
+
const evidence = input.evidence.map((entry) => {
|
|
85
|
+
const item = record(entry);
|
|
86
|
+
const payload = record(item?.payload);
|
|
87
|
+
if (!item ||
|
|
88
|
+
!payload ||
|
|
89
|
+
typeof payload.text !== 'string' ||
|
|
90
|
+
authored ||
|
|
91
|
+
item.modality === 'transcript' ||
|
|
92
|
+
/^(?:Source (?:question|item|structure))/u.test(payload.text))
|
|
93
|
+
return entry;
|
|
94
|
+
const text = sanitize(payload.text, record(item.timeRange));
|
|
95
|
+
if (typeof item.id === 'string')
|
|
96
|
+
byId.set(item.id, { text, context: payload.text, range: record(item.timeRange) });
|
|
97
|
+
return { ...item, payload: { ...payload, text } };
|
|
98
|
+
});
|
|
99
|
+
const rows = Array.isArray(input.rows)
|
|
100
|
+
? input.rows.map((entry) => {
|
|
101
|
+
const row = record(entry);
|
|
102
|
+
if (!row || typeof row.id !== 'string' || !byId.has(row.id))
|
|
103
|
+
return entry;
|
|
104
|
+
const item = byId.get(row.id);
|
|
105
|
+
return {
|
|
106
|
+
...row,
|
|
107
|
+
Content: item.text,
|
|
108
|
+
Answer: sanitize(label(row.Answer), item.range, item.context),
|
|
109
|
+
Respondent: sanitize(label(row.Respondent), item.range, item.context),
|
|
110
|
+
};
|
|
111
|
+
})
|
|
112
|
+
: undefined;
|
|
113
|
+
const extra = (entry) => {
|
|
114
|
+
if (Array.isArray(entry))
|
|
115
|
+
return entry.map(extra);
|
|
116
|
+
const item = record(entry);
|
|
117
|
+
if (!item)
|
|
118
|
+
return entry;
|
|
119
|
+
return Object.fromEntries(Object.entries(item).map(([name, child]) => [
|
|
120
|
+
name,
|
|
121
|
+
['text', 'found', 'summary', 'overview'].includes(name) && typeof child === 'string'
|
|
122
|
+
? sanitize(child, record(item.range) ?? record(item.timeRange))
|
|
123
|
+
: extra(child),
|
|
124
|
+
]));
|
|
125
|
+
};
|
|
126
|
+
const directObservation = input.directObservation ? extra(input.directObservation) : undefined;
|
|
127
|
+
const temporalContext = input.temporalContext ? extra(input.temporalContext) : undefined;
|
|
128
|
+
const output = {
|
|
129
|
+
...input,
|
|
130
|
+
evidence,
|
|
131
|
+
...(rows ? { rows } : {}),
|
|
132
|
+
...(Array.isArray(input.observedSubjects)
|
|
133
|
+
? {
|
|
134
|
+
observedSubjects: subjects.filter((item) => record(item)?.identityBasis !== 'unresolved'),
|
|
135
|
+
}
|
|
136
|
+
: {}),
|
|
137
|
+
...(directObservation ? { directObservation } : {}),
|
|
138
|
+
...(temporalContext ? { temporalContext } : {}),
|
|
139
|
+
};
|
|
140
|
+
if (withheld > 0)
|
|
141
|
+
Object.assign(output, {
|
|
142
|
+
identityGrounding: {
|
|
143
|
+
withheldUnits: withheld,
|
|
144
|
+
instruction: 'Some visual attributions were withheld. A spoken name or unresolved identity does not establish a named visible actor or their action. Report the remaining observations, keep uncertain identities/actions unconfirmed, and never reconstruct withheld claims. Sampled observations do not prove every person or every event was captured.',
|
|
145
|
+
},
|
|
146
|
+
claimVerification: {
|
|
147
|
+
...record(input.claimVerification),
|
|
148
|
+
status: 'needs-corroboration',
|
|
149
|
+
directlyEstablished: false,
|
|
150
|
+
rule: 'Answer only from the remaining grounded evidence. A source-complete scan is not proof of a complete person/action inventory. Identity, appearance, and action each need their own source evidence.',
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
return output;
|
|
154
|
+
}
|
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.15";
|
|
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.15',
|
|
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
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.15",
|
|
11
11
|
"pricing": "free",
|
|
12
12
|
"emoji": "🎥",
|
|
13
13
|
"icon": "Film",
|