@perstack/api-client 0.0.14 → 0.0.16

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/v1/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { maxOrganizationNameLength, organizationNameRegex, maxSkillNameLength, packageWithVersionRegex, maxEnvNameLength, envNameRegex, maxSkillToolNameLength, maxSkillRuleLength, maxSkillDescriptionLength, maxSkillEndpointLength, urlSafeRegex, maxSkillInputJsonSchemaLength, maxExpertVersionTagLength, tagNameRegex, expertVersionRegex, maxExpertDescriptionLength, maxExpertNameLength, expertNameRegex, maxExpertKeyLength, expertKeyRegex, maxExpertInstructionLength, messagePartSchema, usageSchema, toolResultSchema, toolCallSchema, messageSchema, instructionMessageSchema, userMessageSchema, toolMessageSchema, maxCheckpointToolCallIdLength, stepSchema, checkpointSchema } from '@perstack/core';
2
+ import { maxOrganizationNameLength, organizationNameRegex, maxSkillNameLength, packageWithVersionRegex, mcpStdioSkillSchema, maxEnvNameLength, envNameRegex, maxSkillToolNameLength, maxSkillRuleLength, maxSkillDescriptionLength, mcpSseSkillSchema, maxSkillEndpointLength, interactiveSkillSchema, urlSafeRegex, maxSkillInputJsonSchemaLength, maxExpertVersionTagLength, tagNameRegex, expertVersionRegex, expertSchema, maxExpertDescriptionLength, maxExpertNameLength, expertNameRegex, maxExpertKeyLength, expertKeyRegex, maxExpertInstructionLength, messagePartSchema, checkpointSchema, usageSchema, toolResultSchema, toolCallSchema, messageSchema, instructionMessageSchema, userMessageSchema, toolMessageSchema, maxCheckpointToolCallIdLength, stepSchema } from '@perstack/core';
3
3
 
4
4
  // v1/api-error.ts
5
5
  var ApiError = class extends Error {
@@ -70,8 +70,7 @@ var apiApplicationSchema = z.object({
70
70
  var apiRuntimeVersionSchema = z.enum(["v1.0"]);
71
71
  var apiSkillNameSchema = z.string().min(1, "Skill name is required.").max(maxSkillNameLength, "Skill name is too long.").regex(packageWithVersionRegex, "Invalid package name or version.");
72
72
  var apiMcpStdioSkillCommandSchema = z.enum(["npx", "uvx"]);
73
- var apiMcpStdioSkillSchema = z.object({
74
- type: z.literal("mcpStdioSkill"),
73
+ var apiMcpStdioSkillSchema = mcpStdioSkillSchema.omit({ name: true, command: true, args: true, packageName: true, lazyInit: true }).extend({
75
74
  description: z.string().min(1, "Description is required.").max(maxSkillDescriptionLength, "Description is too long"),
76
75
  rule: z.string().max(maxSkillRuleLength, "Rule is too long").optional(),
77
76
  pick: z.array(z.string().max(maxSkillToolNameLength, "Tool name is too long")).optional(),
@@ -82,16 +81,14 @@ var apiMcpStdioSkillSchema = z.object({
82
81
  z.string().max(maxEnvNameLength, "Environment variable name is too long").regex(envNameRegex, "Invalid environment variable name.")
83
82
  ).optional()
84
83
  });
85
- var apiMcpSseSkillSchema = z.object({
86
- type: z.literal("mcpSseSkill"),
84
+ var apiMcpSseSkillSchema = mcpSseSkillSchema.omit({ name: true }).extend({
87
85
  description: z.string().min(1, "Description is required.").max(maxSkillDescriptionLength, "Description is too long"),
88
86
  rule: z.string().max(maxSkillRuleLength, "Rule is too long").optional(),
89
87
  pick: z.array(z.string().max(maxSkillToolNameLength, "Tool name is too long")).optional(),
90
88
  omit: z.array(z.string().max(maxSkillToolNameLength, "Tool name is too long")).optional(),
91
89
  endpoint: z.string().min(1, "Endpoint is required.").max(maxSkillEndpointLength, "Endpoint is too long")
92
90
  });
93
- var apiInteractiveSkillSchema = z.object({
94
- type: z.literal("interactiveSkill"),
91
+ var apiInteractiveSkillSchema = interactiveSkillSchema.omit({ name: true, tools: true }).extend({
95
92
  description: z.string().min(1, "Description is required.").max(maxSkillDescriptionLength, "Description is too long"),
96
93
  rule: z.string().max(maxSkillRuleLength, "Rule is too long").optional(),
97
94
  tools: z.record(
@@ -111,12 +108,9 @@ var apiSkillSchema = z.discriminatedUnion("type", [
111
108
  // v1/schemas/expert.ts
112
109
  var apiTagNameSchema = z.string().pipe(z.string().min(1, "Tag is required.")).pipe(z.string().max(maxExpertVersionTagLength, "Tag is too long.")).pipe(z.string().regex(tagNameRegex, "Invalid tag format. (e.g. latest)"));
113
110
  var apiExpertVersionSchema = z.string().pipe(z.string().min(1, "Version is required.")).pipe(z.string().max(maxExpertVersionTagLength, "Version is too long.")).pipe(z.string().regex(expertVersionRegex, "Invalid version format. (e.g. 1.0.0)"));
114
- var apiBaseExpertSchema = z.object({
111
+ var apiMetadataSchema = z.object({
115
112
  id: z.cuid2(),
116
- key: z.string().pipe(z.string().min(1, "Key is required.")).pipe(z.string().max(maxExpertKeyLength, "Key is too long.")).pipe(z.string().regex(expertKeyRegex, "Invalid key format. (e.g. my-expert)")),
117
- name: z.string().pipe(z.string().min(1, "Name is required.")).pipe(z.string().max(maxExpertNameLength, "Name is too long.")).pipe(z.string().regex(expertNameRegex, "Invalid name format. (e.g. my-expert)")),
118
113
  minRuntimeVersion: apiRuntimeVersionSchema,
119
- description: z.string().min(1, "Description is required").max(maxExpertDescriptionLength, "Description must be less than 2048 characters"),
120
114
  owner: z.object({
121
115
  name: apiOrganizationSchema.shape.name,
122
116
  organizationId: z.cuid2(),
@@ -125,6 +119,11 @@ var apiBaseExpertSchema = z.object({
125
119
  createdAt: z.iso.datetime().transform((date) => new Date(date)),
126
120
  updatedAt: z.iso.datetime().transform((date) => new Date(date))
127
121
  });
122
+ var apiBaseExpertSchema = expertSchema.omit({ skills: true, delegates: true, tags: true, instruction: true }).extend({
123
+ key: z.string().pipe(z.string().min(1, "Key is required.")).pipe(z.string().max(maxExpertKeyLength, "Key is too long.")).pipe(z.string().regex(expertKeyRegex, "Invalid key format. (e.g. my-expert)")),
124
+ name: z.string().pipe(z.string().min(1, "Name is required.")).pipe(z.string().max(maxExpertNameLength, "Name is too long.")).pipe(z.string().regex(expertNameRegex, "Invalid name format. (e.g. my-expert)")),
125
+ description: z.string().min(1, "Description is required").max(maxExpertDescriptionLength, "Description must be less than 2048 characters")
126
+ }).merge(apiMetadataSchema);
128
127
  var apiRegistryExpertSchema = apiBaseExpertSchema.extend({
129
128
  type: z.literal("registryExpert"),
130
129
  version: apiExpertVersionSchema,
@@ -292,6 +291,34 @@ async function getRegistryExpertVersions(input, client) {
292
291
  total: meta.total
293
292
  };
294
293
  }
294
+ var updateRegistryExpertInput = z.object({
295
+ expertKey: apiRegistryExpertSchema.shape.key,
296
+ status: apiRegistryExpertSchema.shape.status.optional(),
297
+ tags: apiRegistryExpertSchema.shape.tags.optional()
298
+ });
299
+ var updateRegistryExpertResponseSchema = z.object({
300
+ data: z.object({
301
+ expert: apiRegistryExpertSchema
302
+ })
303
+ });
304
+ async function updateRegistryExpert(input, client) {
305
+ const { expertKey, status, tags } = updateRegistryExpertInput.parse(input);
306
+ const endpoint = `/api/registry/v1/experts/${encodeURIComponent(expertKey)}`;
307
+ const json = await client.requestAuthenticated(endpoint, {
308
+ method: "POST",
309
+ headers: {
310
+ "Content-Type": "application/json"
311
+ },
312
+ body: JSON.stringify({
313
+ status,
314
+ tags
315
+ })
316
+ });
317
+ const { data } = updateRegistryExpertResponseSchema.parse(json);
318
+ return {
319
+ expert: data.expert
320
+ };
321
+ }
295
322
  var deleteRegistryExpertInput = z.object({
296
323
  expertKey: apiRegistryExpertSchema.shape.key
297
324
  });
@@ -347,9 +374,7 @@ var apiCheckpointStatusSchema = z.union([
347
374
  z.literal("stoppedByExceededMaxSteps"),
348
375
  z.literal("stoppedByError")
349
376
  ]);
350
- var apiBaseCheckpointActionSchema = z.object({
351
- error: z.string().optional()
352
- });
377
+ var apiBaseCheckpointActionSchema = z.object({ error: z.string().optional() });
353
378
  var apiCheckpointActionRetrySchema = apiBaseCheckpointActionSchema.extend({
354
379
  type: z.literal("retry"),
355
380
  error: z.string(),
@@ -367,13 +392,7 @@ var apiCheckpointActionTodoSchema = apiBaseCheckpointActionSchema.extend({
367
392
  type: z.literal("todo"),
368
393
  newTodos: z.array(z.string()),
369
394
  completedTodos: z.array(z.number()),
370
- todos: z.array(
371
- z.object({
372
- id: z.number(),
373
- title: z.string(),
374
- completed: z.boolean()
375
- })
376
- )
395
+ todos: z.array(z.object({ id: z.number(), title: z.string(), completed: z.boolean() }))
377
396
  });
378
397
  var apiCheckpointActionReadImageFileSchema = apiBaseCheckpointActionSchema.extend({
379
398
  type: z.literal("readImageFile"),
@@ -428,11 +447,7 @@ var apiCheckpointActionGetFileInfoSchema = apiBaseCheckpointActionSchema.extend(
428
447
  created: z.date(),
429
448
  modified: z.date(),
430
449
  accessed: z.date(),
431
- permissions: z.object({
432
- readable: z.boolean(),
433
- writable: z.boolean(),
434
- executable: z.boolean()
435
- }),
450
+ permissions: z.object({ readable: z.boolean(), writable: z.boolean(), executable: z.boolean() }),
436
451
  workspaceItem: apiWorkspaceItemSchema.optional()
437
452
  });
438
453
  var apiCheckpointActionWriteTextFileSchema = apiBaseCheckpointActionSchema.extend({
@@ -460,12 +475,7 @@ var apiCheckpointActionListDirectorySchema = apiBaseCheckpointActionSchema.exten
460
475
  var apiCheckpointActionTestUrlSchema = apiBaseCheckpointActionSchema.extend({
461
476
  type: z.literal("testUrl"),
462
477
  results: z.array(
463
- z.object({
464
- url: z.string(),
465
- status: z.number(),
466
- title: z.string(),
467
- description: z.string()
468
- })
478
+ z.object({ url: z.string(), status: z.number(), title: z.string(), description: z.string() })
469
479
  )
470
480
  });
471
481
  var apiCheckpointActionDelegateSchema = apiBaseCheckpointActionSchema.extend({
@@ -511,12 +521,11 @@ var apiCheckpointActionSchema = z.discriminatedUnion("type", [
511
521
  apiCheckpointActionGeneralToolSchema,
512
522
  apiCheckpointActionErrorSchema
513
523
  ]);
514
- var apiCheckpointSchema = z.object({
524
+ var apiCheckpointSchema = checkpointSchema.omit({ expert: true }).extend({
515
525
  type: z.literal("checkpoint"),
516
526
  id: z.cuid2(),
517
527
  action: apiCheckpointActionSchema,
518
528
  expertJobId: z.cuid2(),
519
- stepNumber: z.number().min(0),
520
529
  status: apiCheckpointStatusSchema,
521
530
  expert: apiExpertDigestSchema,
522
531
  skillName: z.string().min(1).max(maxSkillNameLength).optional(),
@@ -1431,8 +1440,8 @@ async function getWorkspaceInstanceItem(input, client) {
1431
1440
  }
1432
1441
  var getWorkspaceInstanceItemsInput = z.object({
1433
1442
  expertJobId: z.string(),
1434
- take: z.union([z.number(), z.string().transform((value) => Number.parseInt(value))]).optional(),
1435
- skip: z.union([z.number(), z.string().transform((value) => Number.parseInt(value))]).optional()
1443
+ take: z.union([z.number(), z.string().transform((value) => Number.parseInt(value, 10))]).optional(),
1444
+ skip: z.union([z.number(), z.string().transform((value) => Number.parseInt(value, 10))]).optional()
1436
1445
  });
1437
1446
  var getWorkspaceInstanceItemsResponseSchema = z.object({
1438
1447
  data: z.object({
@@ -1523,6 +1532,29 @@ async function deleteWorkspaceInstanceItem(input, client) {
1523
1532
  }
1524
1533
  });
1525
1534
  }
1535
+ var findWorkspaceInstanceItemsInput = z.object({
1536
+ expertJobId: z.string(),
1537
+ path: z.string()
1538
+ });
1539
+ var findWorkspaceInstanceItemsResponseSchema = z.object({
1540
+ data: z.object({
1541
+ workspaceItems: z.array(apiWorkspaceItemSchema)
1542
+ })
1543
+ });
1544
+ async function findWorkspaceInstanceItems(input, client) {
1545
+ const { expertJobId, path } = findWorkspaceInstanceItemsInput.parse(input);
1546
+ const url = new URL(
1547
+ `/api/studio/v1/expert_jobs/${expertJobId}/workspace_instance/items/find`,
1548
+ client.baseUrl
1549
+ );
1550
+ url.searchParams.set("path", path);
1551
+ const endpoint = url.toString();
1552
+ const json = await client.requestAuthenticated(endpoint, {
1553
+ headers: { "Content-Type": "application/json" }
1554
+ });
1555
+ const { data } = findWorkspaceInstanceItemsResponseSchema.parse(json);
1556
+ return { workspaceItems: data.workspaceItems };
1557
+ }
1526
1558
 
1527
1559
  // v1/client.ts
1528
1560
  var ApiV1Client = class {
@@ -1581,6 +1613,7 @@ var ApiV1Client = class {
1581
1613
  get: (input) => getRegistryExpert(input, this),
1582
1614
  getMany: (input) => getRegistryExperts(input, this),
1583
1615
  getVersions: (input) => getRegistryExpertVersions(input, this),
1616
+ update: (input) => updateRegistryExpert(input, this),
1584
1617
  delete: (input) => deleteRegistryExpert(input, this)
1585
1618
  }
1586
1619
  };
@@ -1610,6 +1643,7 @@ var ApiV1Client = class {
1610
1643
  create: (input) => createWorkspaceInstanceItem(input, this),
1611
1644
  get: (input) => getWorkspaceInstanceItem(input, this),
1612
1645
  getMany: (input) => getWorkspaceInstanceItems(input, this),
1646
+ find: (input) => findWorkspaceInstanceItems(input, this),
1613
1647
  download: (input) => downloadWorkspaceInstanceItem(input, this),
1614
1648
  update: (input) => updateWorkspaceInstanceItem(input, this),
1615
1649
  delete: (input) => deleteWorkspaceInstanceItem(input, this)
@@ -1639,6 +1673,6 @@ var ApiV1Client = class {
1639
1673
  };
1640
1674
  };
1641
1675
 
1642
- export { ApiError, ApiV1Client, apiApplicationSchema, apiApplicationStatusSchema, apiBaseExpertSchema, apiBaseWorkspaceItemSchema, apiCheckpointActionAppendTextFileSchema, apiCheckpointActionAttemptCompletionSchema, apiCheckpointActionCreateDirectorySchema, apiCheckpointActionDelegateSchema, apiCheckpointActionDeleteFileSchema, apiCheckpointActionEditTextFileSchema, apiCheckpointActionErrorSchema, apiCheckpointActionGeneralToolSchema, apiCheckpointActionGetFileInfoSchema, apiCheckpointActionInteractiveTool, apiCheckpointActionListDirectorySchema, apiCheckpointActionMoveFileSchema, apiCheckpointActionReadImageFileSchema, apiCheckpointActionReadPdfFileSchema, apiCheckpointActionReadTextFileSchema, apiCheckpointActionRetrySchema, apiCheckpointActionSchema, apiCheckpointActionTestUrlSchema, apiCheckpointActionThinkSchema, apiCheckpointActionTodoSchema, apiCheckpointActionWriteTextFileSchema, apiCheckpointSchema, apiCheckpointStatusSchema, apiExpertDigestSchema, apiExpertJobSchema, apiExpertJobStatusSchema, apiExpertSchema, apiInteractiveSkillSchema, apiMcpSseSkillSchema, apiMcpStdioSkillCommandSchema, apiMcpStdioSkillSchema, apiOrganizationSchema, apiOrganizationStatusSchema, apiOrganizationTypeSchema, apiRegistryExpertSchema, apiSkillNameSchema, apiSkillSchema, apiStudioExpertSchema, apiWorkspaceInstanceSchema, apiWorkspaceItemDirectorySchema, apiWorkspaceItemFileSchema, apiWorkspaceItemLifecycleSchema, apiWorkspaceItemOwnerSchema, apiWorkspaceItemPermissionSchema, apiWorkspaceItemSchema, apiWorkspaceSchema, continueExpertJob, createCheckpoint, createRegistryExpert, createStudioExpert, createWorkspaceInstanceItem, createWorkspaceItem, createWorkspaceSecret, createWorkspaceVariable, deleteRegistryExpert, deleteStudioExpert, deleteWorkspaceInstanceItem, deleteWorkspaceItem, deleteWorkspaceSecret, deleteWorkspaceVariable, downloadWorkspaceInstanceItem, downloadWorkspaceItem, getCheckpoint, getCheckpoints, getExpertJob, getExpertJobs, getRegistryExpert, getRegistryExpertVersions, getRegistryExperts, getStudioExpert, getStudioExperts, getWorkspace, getWorkspaceInstance, getWorkspaceInstanceItem, getWorkspaceInstanceItems, getWorkspaceItem, getWorkspaceItems, resumeExpertJobFromCheckpoint, startExpertJob, updateExpertJob, updateStudioExpert, updateWorkspaceInstanceItem, updateWorkspaceItem, updateWorkspaceVariable };
1676
+ export { ApiError, ApiV1Client, apiApplicationSchema, apiApplicationStatusSchema, apiBaseExpertSchema, apiBaseWorkspaceItemSchema, apiCheckpointActionAppendTextFileSchema, apiCheckpointActionAttemptCompletionSchema, apiCheckpointActionCreateDirectorySchema, apiCheckpointActionDelegateSchema, apiCheckpointActionDeleteFileSchema, apiCheckpointActionEditTextFileSchema, apiCheckpointActionErrorSchema, apiCheckpointActionGeneralToolSchema, apiCheckpointActionGetFileInfoSchema, apiCheckpointActionInteractiveTool, apiCheckpointActionListDirectorySchema, apiCheckpointActionMoveFileSchema, apiCheckpointActionReadImageFileSchema, apiCheckpointActionReadPdfFileSchema, apiCheckpointActionReadTextFileSchema, apiCheckpointActionRetrySchema, apiCheckpointActionSchema, apiCheckpointActionTestUrlSchema, apiCheckpointActionThinkSchema, apiCheckpointActionTodoSchema, apiCheckpointActionWriteTextFileSchema, apiCheckpointSchema, apiCheckpointStatusSchema, apiExpertDigestSchema, apiExpertJobSchema, apiExpertJobStatusSchema, apiExpertSchema, apiInteractiveSkillSchema, apiMcpSseSkillSchema, apiMcpStdioSkillCommandSchema, apiMcpStdioSkillSchema, apiOrganizationSchema, apiOrganizationStatusSchema, apiOrganizationTypeSchema, apiRegistryExpertSchema, apiSkillNameSchema, apiSkillSchema, apiStudioExpertSchema, apiWorkspaceInstanceSchema, apiWorkspaceItemDirectorySchema, apiWorkspaceItemFileSchema, apiWorkspaceItemLifecycleSchema, apiWorkspaceItemOwnerSchema, apiWorkspaceItemPermissionSchema, apiWorkspaceItemSchema, apiWorkspaceSchema, continueExpertJob, createCheckpoint, createRegistryExpert, createStudioExpert, createWorkspaceInstanceItem, createWorkspaceItem, createWorkspaceSecret, createWorkspaceVariable, deleteRegistryExpert, deleteStudioExpert, deleteWorkspaceInstanceItem, deleteWorkspaceItem, deleteWorkspaceSecret, deleteWorkspaceVariable, downloadWorkspaceInstanceItem, downloadWorkspaceItem, findWorkspaceInstanceItems, getCheckpoint, getCheckpoints, getExpertJob, getExpertJobs, getRegistryExpert, getRegistryExpertVersions, getRegistryExperts, getStudioExpert, getStudioExperts, getWorkspace, getWorkspaceInstance, getWorkspaceInstanceItem, getWorkspaceInstanceItems, getWorkspaceItem, getWorkspaceItems, resumeExpertJobFromCheckpoint, startExpertJob, updateExpertJob, updateRegistryExpert, updateStudioExpert, updateWorkspaceInstanceItem, updateWorkspaceItem, updateWorkspaceVariable };
1643
1677
  //# sourceMappingURL=index.js.map
1644
1678
  //# sourceMappingURL=index.js.map