@sequenceholdings/artifact-studio 0.10.1 → 0.11.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.
@@ -0,0 +1,47 @@
1
+ import { createConsumerPlatformClient, PlatformError } from '@sequenceholdings/platform/browser';
2
+ import { seq, createArtifactStorageClient } from './sdk.js';
3
+ /**
4
+ * Browser bootstrap for the shared Platform SDK. Authentication and capability checks
5
+ * stay in the trusted Artifact host; no base URL, token, or service authority is accepted.
6
+ * Create again with a new sdk when the host/action scope changes.
7
+ */
8
+ export function createArtifactPlatformClient({ sdk = seq } = {}) {
9
+ if (!sdk?.api || typeof sdk.api.fetch !== 'function') {
10
+ throw new PlatformError({ status: 401, code: 'artifact_host_unavailable', message: 'Open the artifact through its Atlas host or preview' });
11
+ }
12
+ const shared = createConsumerPlatformClient({ transport: {
13
+ async request({ path, method, body }) {
14
+ const result = await sdk.api.fetch(path, { method, body });
15
+ if (!result.ok)
16
+ throw new PlatformError({ status: result.status, code: 'platform_request_failed', message: `Platform request failed (${result.status})`, path });
17
+ return result.body;
18
+ },
19
+ async upload({ path, file }) {
20
+ const result = await sdk.api.upload(path, file);
21
+ if (!result.ok)
22
+ throw new PlatformError({ status: result.status, code: 'platform_request_failed', message: `Platform upload failed (${result.status})`, path });
23
+ return result.body;
24
+ },
25
+ } });
26
+ return {
27
+ ...shared,
28
+ /** App-owned compatibility routes, still subject to the artifact manifest and live grants. */
29
+ api: sdk.api,
30
+ user: sdk.user,
31
+ env: sdk.env,
32
+ auth: sdk.auth,
33
+ flags: sdk.flags,
34
+ host: sdk.host,
35
+ offline: sdk.offline,
36
+ functions: { ...shared.functions, invoke: ({ id, params }) => sdk.functions.invoke(id, params) },
37
+ lattice: { ...shared.lattice, context: () => sdk.lattice.context() },
38
+ storage: { ...createArtifactStorageClient(sdk), preview: sdk.storage.preview?.bind(sdk.storage) },
39
+ agents: { ...shared.agents, chat: (options) => sdk.ai.fetch('/api/agents/chat', { ...options, method: 'POST' }), files: { ...shared.agents.files, download: (input) => sdk.ai.fetch(shared.agents.files.contentPath(input), { method: 'GET' }) } },
40
+ files: {
41
+ ...shared.files,
42
+ upload: ({ file, fields, options }) => sdk.api.upload('/api/files', file, fields, options),
43
+ download: (input) => sdk.api.fetch(shared.files.downloadPath(input)),
44
+ speech: { ...shared.files.speech, transcribe: ({ file, timeoutMs = 90_000 }) => sdk.api.upload('/api/files/speech/stt', file, {}, { fieldName: 'audio', timeoutMs }) },
45
+ },
46
+ };
47
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The preview a `deploy --preview` replaces: an explicit --key, else the --ref
3
+ * it was built from (so each branch keeps its own preview), else `default`.
4
+ */
5
+ export declare function branchPreviewKey({ key, ref }: {
6
+ key: string | true | undefined;
7
+ ref: string | true | undefined;
8
+ }): string;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The preview a `deploy --preview` replaces: an explicit --key, else the --ref
3
+ * it was built from (so each branch keeps its own preview), else `default`.
4
+ */
5
+ export function branchPreviewKey({ key, ref }) {
6
+ if (typeof key === 'string')
7
+ return key;
8
+ const fromRef = typeof ref === 'string'
9
+ ? ref.replace(/^refs\/(heads|tags)\//, '').replace(/[^A-Za-z0-9._-]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 128)
10
+ : '';
11
+ return fromRef || 'default';
12
+ }
@@ -0,0 +1,28 @@
1
+ import { type ArtifactServerProcesses } from './server/processes.js';
2
+ import type { ArtifactServerRequest } from './server/broker-contract.js';
3
+ import { type SequenceApiFetchResponse } from './sdk.js';
4
+ /**
5
+ * Lattice from a static application: the Next.js server SDK's process operations, minus the
6
+ * Next-only API adapters (group task pages, task assignments, batch describe, human-completion
7
+ * readers). Every call is checked by Atlas against `capabilities.processes` in the deployed
8
+ * manifest; then the user's own process and run grants decide.
9
+ */
10
+ export type ArtifactProcesses = Omit<ArtifactServerProcesses, 'listGroupTasksPage' | 'readTaskAssignments' | 'describeMany' | 'getHumanContinuation' | 'getHumanCompletion'>;
11
+ /** The host transport `createArtifactProcesses` sends each operation through. */
12
+ export interface SequenceProcessesBridge {
13
+ request<TBody = unknown>(operation: ArtifactServerRequest): Promise<SequenceApiFetchResponse<TBody>>;
14
+ }
15
+ /**
16
+ * Start, read and act on runs of the processes this artifact declares under
17
+ * `capabilities.processes.start | read | act`, as the signed-in user:
18
+ *
19
+ * ```ts
20
+ * const processes = createArtifactProcesses()
21
+ * const run = await processes.start({ process: 'maintenance-request', metadata: { unit: '4B' } })
22
+ * ```
23
+ *
24
+ * A process the manifest does not declare is refused (403) before any grant is checked.
25
+ */
26
+ export declare function createArtifactProcesses(sdk?: {
27
+ processes?: SequenceProcessesBridge;
28
+ }): ArtifactProcesses;
@@ -0,0 +1,30 @@
1
+ import { createArtifactProcessesClient } from './server/processes.js';
2
+ import { ArtifactServerError, platformRequestError } from './server/errors.js';
3
+ import { seq } from './sdk.js';
4
+ /**
5
+ * Start, read and act on runs of the processes this artifact declares under
6
+ * `capabilities.processes.start | read | act`, as the signed-in user:
7
+ *
8
+ * ```ts
9
+ * const processes = createArtifactProcesses()
10
+ * const run = await processes.start({ process: 'maintenance-request', metadata: { unit: '4B' } })
11
+ * ```
12
+ *
13
+ * A process the manifest does not declare is refused (403) before any grant is checked.
14
+ */
15
+ export function createArtifactProcesses(sdk = seq) {
16
+ const bridge = sdk?.processes;
17
+ if (!bridge || typeof bridge.request !== 'function') {
18
+ throw new ArtifactServerError(501, 'processes_unavailable', 'Lattice processes need the authenticated Artifact Studio host from a newer Atlas; open the deployed artifact or its preview');
19
+ }
20
+ // The omitted methods use broker API adapters, which the static process route refuses.
21
+ return createArtifactProcessesClient({
22
+ mode: 'user',
23
+ json: async (operation) => {
24
+ const response = await bridge.request(operation);
25
+ if (!response.ok)
26
+ throw platformRequestError({ status: response.status, body: response.body, operation: operation.operation });
27
+ return response.status === 204 ? undefined : response.body;
28
+ },
29
+ });
30
+ }
package/dist/sdk.d.ts CHANGED
@@ -1,7 +1,12 @@
1
+ export { createArtifactPlatformClient, type ArtifactPlatformClient } from './platform-client.js';
1
2
  import type { SequenceOfflineManagement } from './offline/management-types.js';
2
3
  export type { SequenceOfflineManagement, SequenceOfflineManagementStatus, SequenceOfflineManagementIssue } from './offline/management-types.js';
3
- import { type StartStorageUpload, type StorageUploadSession } from '@sequenceholdings/storage';
4
+ import { type StartStorageUpload, type StorageUploadSession } from '@sequenceholdings/platform/storage';
4
5
  export { createArtifactOrmExecutor, type ArtifactOrmExecutorConfig } from './sdk-orm.js';
6
+ export { createArtifactProcesses, type ArtifactProcesses, type SequenceProcessesBridge } from './sdk-processes.js';
7
+ export type { ArtifactProcessAdvance, ArtifactProcessAdvanceResult, ArtifactProcessAssign, ArtifactProcessAssignResult, ArtifactProcessDefinition, ArtifactProcessDescribeQuery, ArtifactProcessRun, ArtifactProcessRunRecord, ArtifactProcessRunSnapshot, ArtifactProcessRunsQuery, ArtifactProcessStart, ArtifactProcessTask, ArtifactProcessTasksQuery, } from './server/processes.js';
8
+ export { ArtifactServerError } from './server/errors.js';
9
+ import type { SequenceProcessesBridge } from './sdk-processes.js';
5
10
  export type { ArtifactOrmJsonScalars } from './orm-json-scalars.js';
6
11
  export interface SequenceStorageOptions {
7
12
  signal?: AbortSignal;
@@ -213,6 +218,8 @@ export interface SequenceArtifactSdk {
213
218
  flags: SequenceFlags;
214
219
  lattice: SequenceLattice;
215
220
  host: SequenceHost;
221
+ /** Transport for {@link createArtifactProcesses}; absent on older Atlas hosts. */
222
+ processes?: SequenceProcessesBridge;
216
223
  }
217
224
  declare global {
218
225
  interface Window {
@@ -248,7 +255,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
248
255
  fileId: string;
249
256
  uploadUrl: string | null;
250
257
  expiresAt: string;
251
- state: "pending" | "complete" | "aborted";
258
+ state: "aborted" | "pending" | "complete";
252
259
  versionId: string | null;
253
260
  maxBytes: number;
254
261
  }>;
@@ -257,16 +264,16 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
257
264
  fileId: string;
258
265
  uploadUrl: string | null;
259
266
  expiresAt: string;
260
- state: "pending" | "complete" | "aborted";
267
+ state: "aborted" | "pending" | "complete";
261
268
  versionId: string | null;
262
269
  maxBytes: number;
263
270
  }>;
264
- complete: (id: string, input?: import("@sequenceholdings/storage").CompleteStorageUpload) => Promise<{
271
+ complete: (id: string, input?: import("@sequenceholdings/platform/storage").CompleteStorageUpload) => Promise<{
265
272
  id: string;
266
273
  fileId: string;
267
274
  uploadUrl: string | null;
268
275
  expiresAt: string;
269
- state: "pending" | "complete" | "aborted";
276
+ state: "aborted" | "pending" | "complete";
270
277
  versionId: string | null;
271
278
  maxBytes: number;
272
279
  }>;
@@ -275,7 +282,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
275
282
  fileId: string;
276
283
  uploadUrl: string | null;
277
284
  expiresAt: string;
278
- state: "pending" | "complete" | "aborted";
285
+ state: "aborted" | "pending" | "complete";
279
286
  versionId: string | null;
280
287
  maxBytes: number;
281
288
  }>;
@@ -285,7 +292,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
285
292
  fileId: string;
286
293
  uploadUrl: string | null;
287
294
  expiresAt: string;
288
- state: "pending" | "complete" | "aborted";
295
+ state: "aborted" | "pending" | "complete";
289
296
  versionId: string | null;
290
297
  maxBytes: number;
291
298
  }[];
@@ -295,7 +302,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
295
302
  id: string;
296
303
  fileId: string;
297
304
  name: string;
298
- state: "pending" | "complete" | "aborted";
305
+ state: "aborted" | "pending" | "complete";
299
306
  expiresAt: string;
300
307
  maxBytes: number;
301
308
  expectedSize: number | null;
@@ -313,7 +320,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
313
320
  id: string;
314
321
  fileId: string;
315
322
  name: string;
316
- state: "pending" | "complete" | "aborted";
323
+ state: "aborted" | "pending" | "complete";
317
324
  expiresAt: string;
318
325
  maxBytes: number;
319
326
  expectedSize: number | null;
@@ -325,7 +332,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
325
332
  id: string;
326
333
  fileId: string;
327
334
  name: string;
328
- state: "pending" | "complete" | "aborted";
335
+ state: "aborted" | "pending" | "complete";
329
336
  expiresAt: string;
330
337
  maxBytes: number;
331
338
  expectedSize: number | null;
@@ -337,7 +344,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
337
344
  id: string;
338
345
  fileId: string;
339
346
  name: string;
340
- state: "pending" | "complete" | "aborted";
347
+ state: "aborted" | "pending" | "complete";
341
348
  expiresAt: string;
342
349
  maxBytes: number;
343
350
  expectedSize: number | null;
@@ -365,7 +372,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
365
372
  workspaceId: string;
366
373
  targetId: string | null;
367
374
  kind: "purge" | "delete_version";
368
- status: "queued" | "running" | "succeeded" | "failed";
375
+ status: "running" | "failed" | "queued" | "succeeded";
369
376
  completed: number;
370
377
  total: number;
371
378
  error: string | null;
@@ -373,7 +380,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
373
380
  updatedAt: string;
374
381
  canRetry: boolean;
375
382
  }>;
376
- list: (options?: import("@sequenceholdings/storage").StorageListOptions & {
383
+ list: (options?: import("@sequenceholdings/platform/storage").StorageListOptions & {
377
384
  parentId?: string | null;
378
385
  trash?: boolean;
379
386
  }) => Promise<{
@@ -466,7 +473,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
466
473
  size: number | null;
467
474
  contentType: string | null;
468
475
  }>;
469
- update: (id: string, input: import("zod").input<typeof import("@sequenceholdings/storage").updateNodeSchema>) => Promise<{
476
+ update: (id: string, input: import("zod").input<typeof import("@sequenceholdings/platform/storage").updateNodeSchema>) => Promise<{
470
477
  id: string;
471
478
  workspaceId: string;
472
479
  parentId: string | null;
@@ -522,7 +529,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
522
529
  workspaceId: string;
523
530
  targetId: string | null;
524
531
  kind: "purge" | "delete_version";
525
- status: "queued" | "running" | "succeeded" | "failed";
532
+ status: "running" | "failed" | "queued" | "succeeded";
526
533
  completed: number;
527
534
  total: number;
528
535
  error: string | null;
@@ -571,7 +578,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
571
578
  workspaceId: string;
572
579
  targetId: string | null;
573
580
  kind: "purge" | "delete_version";
574
- status: "queued" | "running" | "succeeded" | "failed";
581
+ status: "running" | "failed" | "queued" | "succeeded";
575
582
  completed: number;
576
583
  total: number;
577
584
  error: string | null;
@@ -583,7 +590,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
583
590
  revision: number;
584
591
  restricted: boolean;
585
592
  grants: {
586
- type: "user" | "group" | "organization" | "service_account";
593
+ type: "user" | "service_account" | "group" | "organization";
587
594
  id: string;
588
595
  role: "viewer" | "editor" | "admin";
589
596
  }[];
@@ -592,11 +599,11 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
592
599
  workspaceAdminOverride: true;
593
600
  displayNames: Record<string, string>;
594
601
  }>;
595
- setAccess: (input: import("zod").input<typeof import("@sequenceholdings/storage").updateStorageAccessSchema>, id?: string) => Promise<{
602
+ setAccess: (input: import("zod").input<typeof import("@sequenceholdings/platform/storage").updateStorageAccessSchema>, id?: string) => Promise<{
596
603
  revision: number;
597
604
  restricted: boolean;
598
605
  grants: {
599
- type: "user" | "group" | "organization" | "service_account";
606
+ type: "user" | "service_account" | "group" | "organization";
600
607
  id: string;
601
608
  role: "viewer" | "editor" | "admin";
602
609
  }[];
@@ -612,7 +619,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
612
619
  revision: number;
613
620
  restricted: boolean;
614
621
  grants: {
615
- type: "user" | "group" | "organization" | "service_account";
622
+ type: "user" | "service_account" | "group" | "organization";
616
623
  id: string;
617
624
  role: "viewer" | "editor" | "admin";
618
625
  }[];
@@ -624,14 +631,14 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
624
631
  operations: (options?: {
625
632
  before?: string;
626
633
  limit?: number;
627
- scope?: import("@sequenceholdings/storage").StorageOperationScope;
634
+ scope?: import("@sequenceholdings/platform/storage").StorageOperationScope;
628
635
  }) => Promise<{
629
636
  items: {
630
637
  id: string;
631
638
  workspaceId: string;
632
639
  targetId: string | null;
633
640
  kind: "purge" | "delete_version";
634
- status: "queued" | "running" | "succeeded" | "failed";
641
+ status: "running" | "failed" | "queued" | "succeeded";
635
642
  completed: number;
636
643
  total: number;
637
644
  error: string | null;
@@ -646,7 +653,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
646
653
  workspaceId: string;
647
654
  targetId: string | null;
648
655
  kind: "purge" | "delete_version";
649
- status: "queued" | "running" | "succeeded" | "failed";
656
+ status: "running" | "failed" | "queued" | "succeeded";
650
657
  completed: number;
651
658
  total: number;
652
659
  error: string | null;
@@ -668,7 +675,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
668
675
  max: number;
669
676
  };
670
677
  }>;
671
- list: (options?: import("@sequenceholdings/storage").StorageListOptions) => Promise<{
678
+ list: (options?: import("@sequenceholdings/platform/storage").StorageListOptions) => Promise<{
672
679
  items: {
673
680
  id: string;
674
681
  name: string;
@@ -684,7 +691,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
684
691
  }[];
685
692
  nextCursor: string | null;
686
693
  }>;
687
- shared: (options?: import("@sequenceholdings/storage").StorageListOptions & {
694
+ shared: (options?: import("@sequenceholdings/platform/storage").StorageListOptions & {
688
695
  trash?: boolean;
689
696
  }) => Promise<{
690
697
  items: {
@@ -706,7 +713,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
706
713
  }[];
707
714
  nextCursor: string | null;
708
715
  }>;
709
- apply: (manifest: import("@sequenceholdings/storage").WorkspaceManifest) => Promise<{
716
+ apply: (manifest: import("@sequenceholdings/platform/storage").WorkspaceManifest) => Promise<{
710
717
  id: string;
711
718
  name: string;
712
719
  description: string;
package/dist/sdk.js CHANGED
@@ -1,5 +1,8 @@
1
- import { storageClient } from '@sequenceholdings/storage';
1
+ export { createArtifactPlatformClient } from './platform-client.js';
2
+ import { storageClient } from '@sequenceholdings/platform/storage';
2
3
  export { createArtifactOrmExecutor } from './sdk-orm.js';
4
+ export { createArtifactProcesses } from './sdk-processes.js';
5
+ export { ArtifactServerError } from './server/errors.js';
3
6
  export const seq = typeof window !== 'undefined'
4
7
  ? window.seq
5
8
  : undefined;
@@ -330,12 +330,12 @@ export declare const artifactServerRequestSchema: z.ZodDiscriminatedUnion<[z.Zod
330
330
  import: "import";
331
331
  share: "share";
332
332
  upload: "upload";
333
- submit: "submit";
334
333
  view: "view";
335
334
  create: "create";
336
335
  update: "update";
337
336
  download: "download";
338
337
  export: "export";
338
+ submit: "submit";
339
339
  approve: "approve";
340
340
  reject: "reject";
341
341
  execute: "execute";
@@ -1,4 +1,5 @@
1
- import { storageClient } from '@sequenceholdings/storage';
1
+ import { type ArtifactServerPlatform } from './platform-client.js';
2
+ import { storageClient } from '@sequenceholdings/platform/storage';
2
3
  import { type OperationExecutor } from '@sequenceholdings/orm/client';
3
4
  import { type ArtifactAuditAction, type ArtifactServerMode } from './broker-contract.js';
4
5
  import { type ArtifactServerGroups } from './groups.js';
@@ -75,6 +76,8 @@ export interface ArtifactServerAudit {
75
76
  export type ArtifactServerContext = ArtifactRequestContext | RequestContextV2External;
76
77
  export interface ArtifactServerClient<TContext extends ArtifactServerContext = ArtifactRequestContext> {
77
78
  context: TContext;
79
+ /** Unified shared Platform clients, retaining this request's verified broker authority. */
80
+ readonly platform: ArtifactServerPlatform;
78
81
  /** Who the request acts for. An `external` principal reaches platform services only through `asService()`. */
79
82
  principal: ArtifactPrincipal;
80
83
  mode: ArtifactServerMode;
@@ -1,5 +1,6 @@
1
+ import { createArtifactServerPlatformAdapter } from './platform-client.js';
1
2
  import { randomUUID } from 'node:crypto';
2
- import { StorageApiError, storageClient, storageErrorSchema } from '@sequenceholdings/storage';
3
+ import { StorageApiError, storageClient, storageErrorSchema } from '@sequenceholdings/platform/storage';
3
4
  import { OrmOperationError } from '@sequenceholdings/orm/client';
4
5
  import { z } from 'zod';
5
6
  import { artifactOrmIdempotencyKeySchema, artifactServerRequestSchema } from './broker-contract.js';
@@ -90,6 +91,7 @@ function buildClient(args) {
90
91
  return Object.fromEntries(names.map(name => [name, parsed.data.flags[name] === true]));
91
92
  };
92
93
  return {
94
+ get platform() { return createArtifactServerPlatformAdapter(this); },
93
95
  context,
94
96
  principal,
95
97
  mode,