Skip to content

Commit dcfe199

Browse files
authored
feat: Look for genAI information in more places (#234)
* ci: Refactor * ci: Add unit test * ci: Change name * ci: Update runner * ci: Fix runners * ci: Added changeset * ci: Revert runner change * ci: Runners
1 parent 0dcdb66 commit dcfe199

File tree

7 files changed

+153
-6
lines changed

7 files changed

+153
-6
lines changed

.github/workflows/build-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
jobs:
99
build-test:
1010
name: 'Build and test'
11-
runs-on: ubuntu-20.04
11+
runs-on: ubuntu-22.04
1212
steps:
1313
- uses: actions/checkout@v3
1414
- name: Install Rust toolchain

.github/workflows/changeset.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
jobs:
66
check-changeset:
77
name: 'Check changeset status'
8-
runs-on: ubuntu-20.04
8+
runs-on: ubuntu-22.04
99
steps:
1010
- uses: actions/checkout@v3
1111
with:
@@ -51,4 +51,4 @@ jobs:
5151
**This means no version will be published on merge.**
5252
5353
If you would like this PR to create a new version on merge, please run `rush change` and commit the generated change description files to this branch.
54-
edit-mode: replace
54+
edit-mode: replace

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
jobs:
88
publish:
99
if: github.event.pull_request.merged == true
10-
runs-on: ubuntu-20.04
10+
runs-on: ubuntu-22.04
1111
steps:
1212
- uses: actions/checkout@v3
1313
with:

.github/workflows/update-examples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
jobs:
99
update_examples:
10-
runs-on: ubuntu-20.04
10+
runs-on: ubuntu-22.04
1111
steps:
1212
- uses: actions/checkout@v3
1313
with:
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "c2pa",
5+
"comment": "feat: Lookup ai details in other parameters",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "c2pa"
10+
}

packages/c2pa/src/selectors/selectGenerativeInfo.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ export function selectGenerativeInfo(
8181
const { actions } = (assertion as C2paActionsAssertion).data;
8282
const genAiActions: GenerativeInfo[] = actions.reduce<GenerativeInfo[]>(
8383
(actionAcc, action: ActionV1) => {
84-
const { digitalSourceType, softwareAgent } = action;
84+
const { digitalSourceType, softwareAgent, parameters } = action;
85+
8586
if (
8687
digitalSourceType &&
8788
genAiDigitalSourceTypes.includes(digitalSourceType)
@@ -94,6 +95,28 @@ export function selectGenerativeInfo(
9495
} as GenerativeInfo);
9596
}
9697

98+
// for 3rd party models, we need to check the parameters
99+
if (action.action === 'c2pa.opened' && parameters) {
100+
const paramsDigitalSourceType =
101+
parameters['com.adobe.digitalSourceType'];
102+
const paramsSoftwareAgent = parameters['com.adobe.details'];
103+
const provider = parameters['com.adobe.type'];
104+
105+
if (
106+
paramsDigitalSourceType &&
107+
provider === 'remoteProvider.3rdParty' &&
108+
genAiDigitalSourceTypes.includes(paramsDigitalSourceType) &&
109+
paramsSoftwareAgent
110+
) {
111+
actionAcc.push({
112+
assertion,
113+
action: action,
114+
type: formatGenAiDigitalSourceTypes(paramsDigitalSourceType),
115+
softwareAgent: { name: paramsSoftwareAgent },
116+
} as GenerativeInfo);
117+
}
118+
}
119+
97120
return actionAcc;
98121
},
99122
[],

packages/c2pa/test/selectors/selectGenerativeInfo.spec.ts

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ describe('selectGenerativeInfo', function () {
122122
'./node_modules/@contentauth/testing/fixtures/images/genai-actions-v2.jpg',
123123
);
124124
const manifest = result.manifestStore?.activeManifest;
125+
125126
expect(manifest).not.toBeNull();
126127
if (manifest) {
127128
const genAssertions = selectGenerativeInfo(manifest);
@@ -140,5 +141,118 @@ describe('selectGenerativeInfo', function () {
140141
]);
141142
}
142143
});
144+
145+
it('should look up parameters details in assertion', async function (this: TestContext) {
146+
const manifest = {
147+
label: 'urn:uuid:05f3b244-301a-49c4-ae14-c24bec024002',
148+
title: 'An image for tests',
149+
format: 'image/png',
150+
vendor: null,
151+
claimGenerator: 'c2pa-js unit tests',
152+
claimGeneratorHints: null,
153+
claimGeneratorInfo: [],
154+
instanceId: 'xmp:iid:12fe9a47-8ad3-4ad1-b362-2ff987428e03',
155+
signatureInfo: {
156+
alg: 'Ps256',
157+
issuer: 'Unit tests',
158+
cert_serial_number: '11111',
159+
time: '2025-03-31T13:36:22+00:00',
160+
},
161+
credentials: [],
162+
ingredients: [
163+
{
164+
title: 'An Image',
165+
format: 'image/png',
166+
documentId: null,
167+
instanceId: 'xmp:iid:52cc660c-8de9-472e-9441-810749fc4514',
168+
provenance: null,
169+
hash: null,
170+
isParent: true,
171+
validationStatus: [],
172+
metadata: null,
173+
manifest: null,
174+
thumbnail: {
175+
blob: {},
176+
contentType: 'image/jpeg',
177+
},
178+
},
179+
],
180+
redactions: [],
181+
parent: null,
182+
thumbnail: null,
183+
assertions: {
184+
data: [
185+
{
186+
label: 'c2pa.actions',
187+
data: {
188+
actions: [
189+
{
190+
action: 'c2pa.opened',
191+
parameters: {
192+
'com.adobe.details': 'the-other-model-name',
193+
'com.adobe.digitalSourceType':
194+
'http://cv.iptc.org/newscodes/digitalsourcetype/trainedAlgorithmicMedia',
195+
ingredient: {
196+
url: 'self#jumbf=c2pa.assertions/c2pa.ingredient',
197+
hash: [1, 2, 3],
198+
},
199+
'com.adobe.type': 'remoteProvider.3rdParty',
200+
},
201+
},
202+
],
203+
},
204+
},
205+
],
206+
},
207+
verifiedIdentities: [],
208+
};
209+
210+
expect(manifest).not.toBeNull();
211+
if (manifest) {
212+
const genAssertions = selectGenerativeInfo(manifest);
213+
const expectedResult = [
214+
{
215+
assertion: {
216+
label: 'c2pa.actions',
217+
data: {
218+
actions: [
219+
{
220+
action: 'c2pa.opened',
221+
parameters: {
222+
'com.adobe.details': 'the-other-model-name',
223+
'com.adobe.digitalSourceType':
224+
'http://cv.iptc.org/newscodes/digitalsourcetype/trainedAlgorithmicMedia',
225+
ingredient: {
226+
url: 'self#jumbf=c2pa.assertions/c2pa.ingredient',
227+
hash: [1, 2, 3],
228+
},
229+
'com.adobe.type': 'remoteProvider.3rdParty',
230+
},
231+
},
232+
],
233+
},
234+
},
235+
action: {
236+
action: 'c2pa.opened',
237+
parameters: {
238+
'com.adobe.details': 'the-other-model-name',
239+
'com.adobe.digitalSourceType':
240+
'http://cv.iptc.org/newscodes/digitalsourcetype/trainedAlgorithmicMedia',
241+
ingredient: {
242+
url: 'self#jumbf=c2pa.assertions/c2pa.ingredient',
243+
hash: [1, 2, 3],
244+
},
245+
'com.adobe.type': 'remoteProvider.3rdParty',
246+
},
247+
},
248+
type: 'trainedAlgorithmicMedia',
249+
softwareAgent: {
250+
name: 'the-other-model-name',
251+
},
252+
},
253+
];
254+
expect(genAssertions).toEqual(expectedResult);
255+
}
256+
});
143257
});
144258
});

0 commit comments

Comments
 (0)