@sequenceholdings/artifact-studio 0.10.0 → 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<{
@@ -413,6 +420,40 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
413
420
  size: number | null;
414
421
  contentType: string | null;
415
422
  }>;
423
+ getNodeWithAncestors: (id: string) => Promise<{
424
+ id: string;
425
+ workspaceId: string;
426
+ parentId: string | null;
427
+ name: string;
428
+ kind: "file" | "folder";
429
+ state: "active" | "trashed" | "purging";
430
+ restricted: boolean;
431
+ revision: number;
432
+ currentVersionId: string | null;
433
+ metadata: Record<string, string>;
434
+ createdAt: string;
435
+ updatedAt: string;
436
+ role: "viewer" | "editor" | "admin";
437
+ size: number | null;
438
+ contentType: string | null;
439
+ ancestors: {
440
+ id: string;
441
+ workspaceId: string;
442
+ parentId: string | null;
443
+ name: string;
444
+ kind: "file" | "folder";
445
+ state: "active" | "trashed" | "purging";
446
+ restricted: boolean;
447
+ revision: number;
448
+ currentVersionId: string | null;
449
+ metadata: Record<string, string>;
450
+ createdAt: string;
451
+ updatedAt: string;
452
+ role: "viewer" | "editor" | "admin";
453
+ size: number | null;
454
+ contentType: string | null;
455
+ }[];
456
+ }>;
416
457
  createFolder: (name: string, parentId?: string | null, { idempotencyKey, }?: {
417
458
  idempotencyKey?: string;
418
459
  }) => Promise<{
@@ -432,7 +473,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
432
473
  size: number | null;
433
474
  contentType: string | null;
434
475
  }>;
435
- 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<{
436
477
  id: string;
437
478
  workspaceId: string;
438
479
  parentId: string | null;
@@ -488,7 +529,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
488
529
  workspaceId: string;
489
530
  targetId: string | null;
490
531
  kind: "purge" | "delete_version";
491
- status: "queued" | "running" | "succeeded" | "failed";
532
+ status: "running" | "failed" | "queued" | "succeeded";
492
533
  completed: number;
493
534
  total: number;
494
535
  error: string | null;
@@ -537,7 +578,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
537
578
  workspaceId: string;
538
579
  targetId: string | null;
539
580
  kind: "purge" | "delete_version";
540
- status: "queued" | "running" | "succeeded" | "failed";
581
+ status: "running" | "failed" | "queued" | "succeeded";
541
582
  completed: number;
542
583
  total: number;
543
584
  error: string | null;
@@ -549,7 +590,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
549
590
  revision: number;
550
591
  restricted: boolean;
551
592
  grants: {
552
- type: "user" | "group" | "organization" | "service_account";
593
+ type: "user" | "service_account" | "group" | "organization";
553
594
  id: string;
554
595
  role: "viewer" | "editor" | "admin";
555
596
  }[];
@@ -558,11 +599,11 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
558
599
  workspaceAdminOverride: true;
559
600
  displayNames: Record<string, string>;
560
601
  }>;
561
- 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<{
562
603
  revision: number;
563
604
  restricted: boolean;
564
605
  grants: {
565
- type: "user" | "group" | "organization" | "service_account";
606
+ type: "user" | "service_account" | "group" | "organization";
566
607
  id: string;
567
608
  role: "viewer" | "editor" | "admin";
568
609
  }[];
@@ -578,7 +619,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
578
619
  revision: number;
579
620
  restricted: boolean;
580
621
  grants: {
581
- type: "user" | "group" | "organization" | "service_account";
622
+ type: "user" | "service_account" | "group" | "organization";
582
623
  id: string;
583
624
  role: "viewer" | "editor" | "admin";
584
625
  }[];
@@ -590,14 +631,14 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
590
631
  operations: (options?: {
591
632
  before?: string;
592
633
  limit?: number;
593
- scope?: import("@sequenceholdings/storage").StorageOperationScope;
634
+ scope?: import("@sequenceholdings/platform/storage").StorageOperationScope;
594
635
  }) => Promise<{
595
636
  items: {
596
637
  id: string;
597
638
  workspaceId: string;
598
639
  targetId: string | null;
599
640
  kind: "purge" | "delete_version";
600
- status: "queued" | "running" | "succeeded" | "failed";
641
+ status: "running" | "failed" | "queued" | "succeeded";
601
642
  completed: number;
602
643
  total: number;
603
644
  error: string | null;
@@ -612,7 +653,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
612
653
  workspaceId: string;
613
654
  targetId: string | null;
614
655
  kind: "purge" | "delete_version";
615
- status: "queued" | "running" | "succeeded" | "failed";
656
+ status: "running" | "failed" | "queued" | "succeeded";
616
657
  completed: number;
617
658
  total: number;
618
659
  error: string | null;
@@ -634,7 +675,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
634
675
  max: number;
635
676
  };
636
677
  }>;
637
- list: (options?: import("@sequenceholdings/storage").StorageListOptions) => Promise<{
678
+ list: (options?: import("@sequenceholdings/platform/storage").StorageListOptions) => Promise<{
638
679
  items: {
639
680
  id: string;
640
681
  name: string;
@@ -650,7 +691,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
650
691
  }[];
651
692
  nextCursor: string | null;
652
693
  }>;
653
- shared: (options?: import("@sequenceholdings/storage").StorageListOptions & {
694
+ shared: (options?: import("@sequenceholdings/platform/storage").StorageListOptions & {
654
695
  trash?: boolean;
655
696
  }) => Promise<{
656
697
  items: {
@@ -672,7 +713,7 @@ export declare function createArtifactStorageClient(sdk?: SequenceArtifactSdk):
672
713
  }[];
673
714
  nextCursor: string | null;
674
715
  }>;
675
- apply: (manifest: import("@sequenceholdings/storage").WorkspaceManifest) => Promise<{
716
+ apply: (manifest: import("@sequenceholdings/platform/storage").WorkspaceManifest) => Promise<{
676
717
  id: string;
677
718
  name: string;
678
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,