@agent-native/creative-context 0.7.19 → 0.7.20-nightly-20260903142610

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": "@agent-native/creative-context",
3
- "version": "0.7.19",
3
+ "version": "0.7.20-nightly-20260903142610",
4
4
  "description": "Shared creative context ingestion, versioning, search, brand DNA, and context-pack primitives for agent-native apps.",
5
5
  "homepage": "https://github.com/BuilderIO/agent-native#readme",
6
6
  "bugs": {
@@ -57,12 +57,12 @@
57
57
  "react-dom": "^19.2.7",
58
58
  "typescript-7": "npm:typescript@^7.0.2",
59
59
  "vitest": "^4.1.5",
60
- "@agent-native/core": "0.176.4",
61
- "@agent-native/toolkit": "0.19.2"
60
+ "@agent-native/core": "0.176.5-nightly-20260903142610",
61
+ "@agent-native/toolkit": "0.19.3-nightly-20260903142610"
62
62
  },
63
63
  "peerDependencies": {
64
- "@agent-native/core": ">=0.8.0",
65
- "@agent-native/toolkit": ">=0.1.0",
64
+ "@agent-native/core": "0.176.5-nightly-20260903142610",
65
+ "@agent-native/toolkit": "0.19.3-nightly-20260903142610",
66
66
  "@tabler/icons-react": ">=3.41.1",
67
67
  "@tanstack/react-query": ">=5.101.4",
68
68
  "drizzle-orm": ">=0.45",
@@ -1,7 +1,13 @@
1
1
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
2
 
3
+ import {
4
+ signInternalToken,
5
+ verifyInternalToken as verifySignedInternalToken,
6
+ } from "../../../core/src/integrations/internal-token.js";
7
+
3
8
  const mocks = vi.hoisted(() => ({
4
9
  fireInternalDispatch: vi.fn(async () => {}),
10
+ extractInternalBearerToken: vi.fn(),
5
11
  getH3App: vi.fn(),
6
12
  readBody: vi.fn(),
7
13
  registerDispatcher: vi.fn(),
@@ -18,7 +24,8 @@ const mocks = vi.hoisted(() => ({
18
24
  failed: 0,
19
25
  })),
20
26
  h3Use: vi.fn(),
21
- verifyInternalToken: vi.fn(() => true),
27
+ verifyInternalToken: vi.fn(),
28
+ processBackground: vi.fn(),
22
29
  isLocalDatabase: vi.fn(() => true),
23
30
  isInBackgroundFunctionRuntime: vi.fn(() => false),
24
31
  }));
@@ -30,7 +37,7 @@ vi.mock("@agent-native/core/db", async (importOriginal) => ({
30
37
 
31
38
  vi.mock("@agent-native/core/server", () => ({
32
39
  awaitBootstrap: vi.fn(async () => {}),
33
- extractInternalBearerToken: vi.fn(() => "token"),
40
+ extractInternalBearerToken: mocks.extractInternalBearerToken,
34
41
  fireInternalDispatch: mocks.fireInternalDispatch,
35
42
  FRAMEWORK_ROUTE_PREFIX: "/_agent-native",
36
43
  getH3App: mocks.getH3App,
@@ -47,12 +54,13 @@ vi.mock("./worker.js", () => ({
47
54
 
48
55
  vi.mock("./background-worker.js", () => ({
49
56
  enqueueCreativeContextDailyMaintenance: mocks.enqueueDailyMaintenance,
50
- processCreativeContextBackgroundJob: vi.fn(),
57
+ processCreativeContextBackgroundJob: mocks.processBackground,
51
58
  processDueCreativeContextBackgroundJobs: mocks.processDueBackground,
52
59
  registerCreativeContextBackgroundDispatcher: vi.fn(),
53
60
  }));
54
61
 
55
62
  const {
63
+ CREATIVE_CONTEXT_BACKGROUND_PROCESSOR_ROUTE,
56
64
  CREATIVE_CONTEXT_IMPORT_PROCESSOR_ROUTE,
57
65
  createCreativeContextWorkerPlugin,
58
66
  } = await import("./server-worker.js");
@@ -66,9 +74,22 @@ describe("creative context hosted worker", () => {
66
74
  mocks.processDue.mockClear();
67
75
  mocks.processDueBackground.mockClear();
68
76
  mocks.enqueueDailyMaintenance.mockClear();
77
+ mocks.processImport.mockReset();
78
+ mocks.processImport.mockResolvedValue({
79
+ yielded: false,
80
+ reason: "completed",
81
+ job: { status: "completed" },
82
+ });
83
+ mocks.processBackground.mockReset();
84
+ mocks.processBackground.mockResolvedValue({ status: "completed" });
85
+ mocks.extractInternalBearerToken.mockReset();
86
+ mocks.extractInternalBearerToken.mockImplementation(
87
+ (authorization?: string) =>
88
+ authorization?.match(/^Bearer\s+(.+)$/i)?.[1]?.trim() ?? null,
89
+ );
69
90
  mocks.h3Use.mockClear();
70
91
  mocks.verifyInternalToken.mockReset();
71
- mocks.verifyInternalToken.mockReturnValue(true);
92
+ mocks.verifyInternalToken.mockImplementation(verifySignedInternalToken);
72
93
  mocks.isLocalDatabase.mockReset();
73
94
  mocks.isLocalDatabase.mockReturnValue(true);
74
95
  mocks.isInBackgroundFunctionRuntime.mockReset();
@@ -137,25 +158,66 @@ describe("creative context hosted worker", () => {
137
158
  expect(mocks.enqueueDailyMaintenance).not.toHaveBeenCalled();
138
159
  });
139
160
 
140
- it("rejects invalid signed dispatches", async () => {
161
+ it("rejects invalid signed dispatches for both processors", async () => {
141
162
  vi.stubEnv("A2A_SECRET", "configured-secret");
142
163
  mocks.verifyInternalToken.mockReturnValue(false);
143
- mocks.readBody.mockResolvedValue({
144
- jobId: "job-invalid",
145
- ownerEmail: "owner@example.com",
146
- });
147
- await createCreativeContextWorkerPlugin({ appId: "design" })({});
148
- const handler = mocks.h3Use.mock.calls.at(-1)?.[1] as (
149
- event: unknown,
150
- ) => Promise<Response>;
151
- const response = await handler({
152
- req: {
153
- method: "POST",
154
- headers: new Headers({ authorization: "Bearer invalid" }),
155
- },
156
- });
157
- expect(response.status).toBe(401);
158
- expect(mocks.processImport).not.toHaveBeenCalled();
164
+
165
+ for (const [route, processor] of [
166
+ [CREATIVE_CONTEXT_IMPORT_PROCESSOR_ROUTE, mocks.processImport],
167
+ [CREATIVE_CONTEXT_BACKGROUND_PROCESSOR_ROUTE, mocks.processBackground],
168
+ ] as const) {
169
+ mocks.readBody.mockResolvedValue({
170
+ jobId: `job-invalid-${route.endsWith("background") ? "background" : "import"}`,
171
+ ownerEmail: "owner@example.com",
172
+ });
173
+ await createCreativeContextWorkerPlugin({ appId: "design" })({});
174
+ const handler = mocks.h3Use.mock.calls.find(
175
+ ([mountedRoute]) => mountedRoute === route,
176
+ )?.[1] as ((event: unknown) => Promise<Response>) | undefined;
177
+ expect(handler).toBeTypeOf("function");
178
+
179
+ const response = await handler!({
180
+ req: {
181
+ method: "POST",
182
+ headers: new Headers({ authorization: "Bearer invalid" }),
183
+ },
184
+ });
185
+
186
+ expect(response.status).toBe(401);
187
+ expect(processor).not.toHaveBeenCalled();
188
+ }
189
+ });
190
+
191
+ it("accepts valid signed dispatches for both processors", async () => {
192
+ vi.stubEnv("A2A_SECRET", "configured-secret");
193
+
194
+ for (const [route, processor] of [
195
+ [CREATIVE_CONTEXT_IMPORT_PROCESSOR_ROUTE, mocks.processImport],
196
+ [CREATIVE_CONTEXT_BACKGROUND_PROCESSOR_ROUTE, mocks.processBackground],
197
+ ] as const) {
198
+ const jobId = `job-valid-${route.endsWith("background") ? "background" : "import"}`;
199
+ mocks.readBody.mockResolvedValue({
200
+ jobId,
201
+ ownerEmail: "owner@example.com",
202
+ });
203
+ await createCreativeContextWorkerPlugin({ appId: "design" })({});
204
+ const handler = mocks.h3Use.mock.calls.find(
205
+ ([mountedRoute]) => mountedRoute === route,
206
+ )?.[1] as ((event: unknown) => Promise<Response>) | undefined;
207
+ expect(handler).toBeTypeOf("function");
208
+
209
+ const response = await handler!({
210
+ req: {
211
+ method: "POST",
212
+ headers: new Headers({
213
+ authorization: `Bearer ${signInternalToken(jobId)}`,
214
+ }),
215
+ },
216
+ });
217
+
218
+ expect(response.status).toBe(200);
219
+ expect(processor).toHaveBeenCalled();
220
+ }
159
221
  });
160
222
 
161
223
  it("fails closed without A2A_SECRET outside local development", async () => {