@kanyun-ai-infra/agenthub 0.2.0 → 0.4.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.
package/dist/index.cjs CHANGED
@@ -28,11 +28,13 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
28
28
  var index_exports = {};
29
29
  __export(index_exports, {
30
30
  AGENTHUB_SDK_USER_AGENT: () => AGENTHUB_SDK_USER_AGENT,
31
+ AgentPackageSchema: () => AgentPackageSchema,
31
32
  AgentsResource: () => WorkloadsResource,
32
33
  CreatePlatformProjectRequestSchema: () => CreatePlatformProjectRequestSchema,
33
34
  CreatePlatformSessionRequestSchema: () => CreatePlatformSessionRequestSchema,
34
35
  CreatePlatformSessionResponseSchema: () => CreatePlatformSessionResponseSchema,
35
36
  CreatePlatformWorkloadRequestSchema: () => CreatePlatformWorkloadRequestSchema,
37
+ DeletePlatformProjectResponseSchema: () => DeletePlatformProjectResponseSchema,
36
38
  FilesResource: () => FilesResource,
37
39
  ListPlatformProjectsResponseSchema: () => ListPlatformProjectsResponseSchema,
38
40
  PILOT_WORKLOAD_MANIFEST_API_VERSION: () => PILOT_WORKLOAD_MANIFEST_API_VERSION,
@@ -49,6 +51,7 @@ __export(index_exports, {
49
51
  PlatformWorkloadSchema: () => PlatformWorkloadSchema,
50
52
  ProjectsResource: () => ProjectsResource,
51
53
  PublishPlatformRevisionRequestSchema: () => PublishPlatformRevisionRequestSchema,
54
+ ReleaseSandboxResponseSchema: () => ReleaseSandboxResponseSchema,
52
55
  SessionFileResourceSchema: () => SessionFileResourceSchema,
53
56
  SessionResourcesSchema: () => SessionResourcesSchema,
54
57
  SessionsResource: () => SessionsResource,
@@ -767,6 +770,13 @@ var CreateSessionRequestSchema = import_zod6.z.object({
767
770
  idempotencyKey: import_zod6.z.string().min(1).optional(),
768
771
  configValues: SessionConfigValuesSchema.optional(),
769
772
  metadata: import_zod6.z.record(import_zod6.z.unknown()).optional(),
773
+ /**
774
+ * UI/BFF hint for managed-agent launchers: when true, an AgentHub route may
775
+ * try to lease a ready session from the session prewarming pool before
776
+ * falling back to normal session creation. Core create-session semantics
777
+ * remain unchanged; services that do not implement prewarming MUST ignore it.
778
+ */
779
+ preferPrewarmed: import_zod6.z.boolean().optional(),
770
780
  /**
771
781
  * GAP1-B (rush-app v2 migration) — optional caller-supplied stable runtime
772
782
  * claim name. Forwarded to the runtime provider's `create()` as the sandbox
@@ -957,6 +967,59 @@ var WORKLOAD_MANIFEST_MODEL_MAX_LENGTH = 255;
957
967
  var WorkloadManifestModelSchema = import_zod4.z.string().min(1).max(WORKLOAD_MANIFEST_MODEL_MAX_LENGTH);
958
968
  var WORKLOAD_MANIFEST_SYSTEM_PROMPT_MAX_LENGTH = 32768;
959
969
  var WorkloadManifestSystemPromptSchema = import_zod4.z.string().min(1).max(WORKLOAD_MANIFEST_SYSTEM_PROMPT_MAX_LENGTH);
970
+ var AGENT_PACKAGE_MAX_SIZE_BYTES = 50 * 1024 * 1024;
971
+ var AGENT_PACKAGE_SOURCE_URL_MAX_LENGTH = 2048;
972
+ var SHA256_DIGEST_PATTERN = /^sha256:[0-9a-fA-F]{64}$/;
973
+ var OSS_AGENT_PACKAGE_HOST_PATTERN = /^[a-z0-9][a-z0-9-]*\.oss-[a-z0-9-]+(?:-internal)?\.aliyuncs\.com$/i;
974
+ function hasAsciiControlCharacter(value) {
975
+ for (let i = 0; i < value.length; i += 1) {
976
+ const code = value.charCodeAt(i);
977
+ if (code <= 31 || code === 127) return true;
978
+ }
979
+ return false;
980
+ }
981
+ function isApprovedAgentPackageUrl(value) {
982
+ let parsed;
983
+ try {
984
+ parsed = new URL(value);
985
+ } catch (e) {
986
+ return false;
987
+ }
988
+ if (parsed.protocol !== "https:") return false;
989
+ if (!OSS_AGENT_PACKAGE_HOST_PATTERN.test(parsed.hostname)) return false;
990
+ let key;
991
+ try {
992
+ key = decodeURIComponent(parsed.pathname.replace(/^\/+/, ""));
993
+ } catch (e) {
994
+ return false;
995
+ }
996
+ const segments = key.split("/");
997
+ if (segments.includes(".") || segments.includes("..")) return false;
998
+ if (!key.startsWith("pilot/agent-packages/")) return false;
999
+ return key.endsWith(".tar.gz") || key.endsWith(".tgz");
1000
+ }
1001
+ var ClaudeCodeAgentPackageEntryCommandSchema = import_zod4.z.string().min(1).max(100).refine((value) => value.trim() === value, {
1002
+ message: "entryCommand must not have leading or trailing whitespace"
1003
+ }).refine((value) => !hasAsciiControlCharacter(value), {
1004
+ message: "entryCommand must not contain control characters"
1005
+ }).refine((value) => value !== "." && value !== "..", {
1006
+ message: "entryCommand must be a command name, not a path segment"
1007
+ }).refine((value) => !value.includes("/") && !value.includes("\\"), {
1008
+ message: "entryCommand must not contain path separators"
1009
+ });
1010
+ var AgentPackageSourceSchema = import_zod4.z.object({
1011
+ kind: import_zod4.z.literal("oss"),
1012
+ url: import_zod4.z.string().url().max(AGENT_PACKAGE_SOURCE_URL_MAX_LENGTH).refine(isApprovedAgentPackageUrl, {
1013
+ message: "url must be an approved HTTPS OSS agent package URL"
1014
+ }),
1015
+ sha256: import_zod4.z.string().regex(SHA256_DIGEST_PATTERN, "sha256 must be sha256:<64 hex chars>"),
1016
+ sizeBytes: import_zod4.z.number().int().positive().max(AGENT_PACKAGE_MAX_SIZE_BYTES).optional()
1017
+ }).strict();
1018
+ var AgentPackageSchema = import_zod4.z.object({
1019
+ format: import_zod4.z.literal("claude_code"),
1020
+ source: AgentPackageSourceSchema,
1021
+ entryCommand: ClaudeCodeAgentPackageEntryCommandSchema.optional()
1022
+ }).strict();
960
1023
  var AGENT_OPTIONS_MAX_TURNS = 200;
961
1024
  var AGENT_OPTIONS_MAX_THINKING_TOKENS = 6e4;
962
1025
  var AGENT_OPTIONS_MAX_BUDGET_USD = 50;
@@ -991,7 +1054,9 @@ var ManagedAgentProfileSnapshotSchema = import_zod4.z.object({
991
1054
  enabledSkills: EnabledSkillEntryListSchema.optional(),
992
1055
  enabledMcpServers: EnabledMcpEntryListSchema.optional(),
993
1056
  configValues: SessionConfigValuesSchema.optional(),
994
- agentOptions: AgentOptionsSchema.optional()
1057
+ resources: SessionResourcesSchema.optional(),
1058
+ agentOptions: AgentOptionsSchema.optional(),
1059
+ agentPackage: AgentPackageSchema.optional()
995
1060
  }).strict();
996
1061
  var ManagedAgentOverridesSchema = import_zod4.z.object({
997
1062
  model: WorkloadManifestModelSchema.nullable().optional(),
@@ -1053,6 +1118,15 @@ var WorkloadManifestDefaultsSchema = import_zod4.z.object({
1053
1118
  * `specs/features/pilot-v2-managed-agent-profile.md` §"Phase C".
1054
1119
  */
1055
1120
  enabledMcpServers: EnabledMcpEntryListSchema.optional(),
1121
+ /**
1122
+ * Workload-level **default session resources** for managed_agent runtime
1123
+ * files. Persisted into `workloads.manifest_defaults_json`, frozen onto
1124
+ * `revisions.managed_agent_profile_snapshot_json` at publish time, then
1125
+ * copied to `sessions.session_resources_json` when the caller does not
1126
+ * supply explicit session resources. The agent runtime receives paths to
1127
+ * mounted files; file content is not injected into the prompt.
1128
+ */
1129
+ resources: SessionResourcesSchema.optional(),
1056
1130
  /**
1057
1131
  * Workload-level **default agent options** (managed_agent profile
1058
1132
  * "Phase E1"). A flat, only-tighten / bounded-resource subset of the
@@ -1065,7 +1139,14 @@ var WorkloadManifestDefaultsSchema = import_zod4.z.object({
1065
1139
  * `createClaudeCode({ defaultSettings })` by the agent-runtime
1066
1140
  * claude-code provider. See `AgentOptionsSchema` above and issue #840.
1067
1141
  */
1068
- agentOptions: AgentOptionsSchema.optional()
1142
+ agentOptions: AgentOptionsSchema.optional(),
1143
+ /**
1144
+ * Workload-level **default agent package**. The Revision snapshot freezes
1145
+ * this reference and the dispatch payload forwards it to the sandbox
1146
+ * agent-worker, which downloads, verifies, and materializes the Claude Code
1147
+ * package before the provider starts.
1148
+ */
1149
+ agentPackage: AgentPackageSchema.optional()
1069
1150
  }).strict();
1070
1151
  var WORKLOAD_MANIFEST_UI_DISPLAY_NAME_MAX_LENGTH = 255;
1071
1152
  var WORKLOAD_MANIFEST_UI_PROMPT_PLACEHOLDER_MAX_LENGTH = 500;
@@ -1816,6 +1897,8 @@ var OssCredentialSchema = import_zod22.z.object({
1816
1897
  * client can compose multi-key flows by requesting fresh URLs).
1817
1898
  */
1818
1899
  prefix: import_zod22.z.string().min(1),
1900
+ /** The object key this URL is scoped to. Omitted by legacy issuers. */
1901
+ key: import_zod22.z.string().min(1).optional(),
1819
1902
  /**
1820
1903
  * Pre-signed PUT URL for the Session's default artifact object key
1821
1904
  * (`${prefix}artifact.bin` by convention). Phase 1 fallback in place
@@ -1830,6 +1913,15 @@ var OssCredentialSchema = import_zod22.z.object({
1830
1913
  stsSecretAccessKey: import_zod22.z.string().optional(),
1831
1914
  stsSessionToken: import_zod22.z.string().optional()
1832
1915
  });
1916
+ var OssUploadRequestSchema = import_zod22.z.object({
1917
+ /**
1918
+ * Optional OSS object key to presign for upload. When omitted, the
1919
+ * broker preserves the legacy `${sessionPrefix}artifact.bin` behavior.
1920
+ * Callers may pass either a session-relative path or a fully-qualified
1921
+ * key under `pilot/sessions/<sessionId>/`.
1922
+ */
1923
+ key: import_zod22.z.string().min(1).optional()
1924
+ }).strict();
1833
1925
  var OssDownloadRequestSchema = import_zod22.z.object({
1834
1926
  /** OSS object key the Worker wants to read (an input file's key). */
1835
1927
  key: import_zod22.z.string().min(1)
@@ -1854,7 +1946,8 @@ var CredentialsBrokerErrorCodeSchema = import_zod22.z.enum([
1854
1946
  "SESSION_TOKEN_REVOKED",
1855
1947
  "SESSION_TOKEN_EXPIRED",
1856
1948
  "POD_AGENT_TOKEN_INVALID",
1857
- // 400 — request body invalid (oss-download `key` missing/malformed)
1949
+ // 400 — request body invalid (oss upload/download `key` missing/malformed)
1950
+ "OSS_UPLOAD_KEY_INVALID",
1858
1951
  "OSS_DOWNLOAD_KEY_INVALID",
1859
1952
  // 403 — authorization failures
1860
1953
  "SESSION_TOKEN_SESSION_MISMATCH",
@@ -3910,7 +4003,12 @@ var ManagedAgentProfileSpecSchema = import_zod41.z.object({
3910
4003
  // `PilotCoderRunConfigV1.systemPrompt`. agent-worker uses it instead of
3911
4004
  // the platform-level `SYSTEM_PROMPT` fallback. See
3912
4005
  // `specs/features/pilot-v2-managed-agent-profile.md` §"Phase D".
3913
- systemPrompt: WorkloadManifestSystemPromptSchema.optional()
4006
+ systemPrompt: WorkloadManifestSystemPromptSchema.optional(),
4007
+ // Agent-level default runtime files. The envelope is exactly the session
4008
+ // resources contract so the same mount/download path handles both default
4009
+ // files and caller-supplied per-session files.
4010
+ resources: SessionResourcesSchema.optional(),
4011
+ agentPackage: AgentPackageSchema.optional()
3914
4012
  }).strict();
3915
4013
  var ManagedAgentProfileSchema = import_zod41.z.object({
3916
4014
  apiVersion: PilotWorkloadManifestApiVersionSchema,
@@ -3936,6 +4034,10 @@ var CreatePlatformProjectRequestSchema = import_zod42.z.object({
3936
4034
  var ListPlatformProjectsResponseSchema = import_zod42.z.object({
3937
4035
  projects: import_zod42.z.array(PlatformProjectSchema)
3938
4036
  }).strict();
4037
+ var DeletePlatformProjectResponseSchema = import_zod42.z.object({
4038
+ action: import_zod42.z.literal("deactivated"),
4039
+ projectId: import_zod42.z.string().uuid()
4040
+ }).strict();
3939
4041
  var PlatformWorkloadDefaultsSchema = import_zod42.z.object({
3940
4042
  workerContract: WorkloadManifestWorkerContractDefaultsSchema.optional(),
3941
4043
  configValues: SessionConfigValuesSchema.optional(),
@@ -3943,7 +4045,8 @@ var PlatformWorkloadDefaultsSchema = import_zod42.z.object({
3943
4045
  systemPrompt: import_zod42.z.string().min(1).max(32768).optional(),
3944
4046
  enabledSkills: EnabledSkillEntryListSchema.optional(),
3945
4047
  enabledMcpServers: EnabledMcpEntryListSchema.optional(),
3946
- agentOptions: AgentOptionsSchema.optional()
4048
+ agentOptions: AgentOptionsSchema.optional(),
4049
+ agentPackage: AgentPackageSchema.optional()
3947
4050
  }).strict();
3948
4051
  var CreatePlatformWorkloadRequestSchema = import_zod42.z.object({
3949
4052
  projectId: import_zod42.z.string().uuid(),
@@ -4002,6 +4105,12 @@ var GetPlatformSessionResponseSchema = import_zod42.z.object({
4002
4105
  }).strict();
4003
4106
  var CreatePlatformSessionRequestSchema = CreateSessionRequestSchema;
4004
4107
  var CreatePlatformSessionResponseSchema = CreateSessionResponseSchema;
4108
+ var ReleaseSandboxResponseSchema = import_zod42.z.object({
4109
+ released: import_zod42.z.literal(true),
4110
+ sandboxId: import_zod42.z.string().nullable(),
4111
+ sandboxDestroyed: import_zod42.z.boolean(),
4112
+ destroyError: import_zod42.z.string().optional()
4113
+ }).strict();
4005
4114
  var PlatformFileUploadResponseSchema = AttachmentMetaSchema.extend({
4006
4115
  url: import_zod42.z.string()
4007
4116
  });
@@ -4138,6 +4247,12 @@ var PilotCoderRunConfigV1Schema = import_zod43.z.object({
4138
4247
  * means contracts must ship before control-worker starts populating it.
4139
4248
  */
4140
4249
  agentOptions: AgentOptionsSchema.optional(),
4250
+ /**
4251
+ * Optional Claude Code agent package to install before the provider boots.
4252
+ * The reference is checksum-pinned and originates from the managed_agent
4253
+ * profile Revision snapshot / workload default.
4254
+ */
4255
+ agentPackage: AgentPackageSchema.optional(),
4141
4256
  /**
4142
4257
  * P3 L3.3 — delivery-related fields populated by control-worker from
4143
4258
  * `runs.*` / `agents.*` columns so the worker delivery loop can act
@@ -4611,15 +4726,69 @@ var ProjectsResource = class {
4611
4726
  );
4612
4727
  return PlatformProjectSchema.parse(response);
4613
4728
  }
4729
+ /**
4730
+ * Soft-delete (deactivate) a project: null the owner, clear members, disable
4731
+ * integrations. Owner-only (the calling token must belong to the project
4732
+ * owner). System projects cannot be deleted. The row is kept for audit, so
4733
+ * the response `action` is always `"deactivated"`.
4734
+ */
4735
+ async delete(projectId, options = {}) {
4736
+ const response = await this.client.request(
4737
+ `/api/projects/${encodeURIComponent(projectId)}`,
4738
+ {
4739
+ method: "DELETE",
4740
+ signal: options.signal
4741
+ }
4742
+ );
4743
+ return DeletePlatformProjectResponseSchema.parse(response);
4744
+ }
4614
4745
  };
4615
4746
 
4747
+ // src/agent-vocab.ts
4748
+ function resolveExclusiveAlias(canonicalKey, canonicalValue, aliasKey, aliasValue) {
4749
+ if (canonicalValue !== void 0 && aliasValue !== void 0) {
4750
+ throw new PilotPlatformApiError({
4751
+ status: 0,
4752
+ code: "ALIAS_CONFLICT",
4753
+ message: `Provide either \`${canonicalKey}\` or its alias \`${aliasKey}\`, not both \u2014 they name the same value.`
4754
+ });
4755
+ }
4756
+ return canonicalValue ?? aliasValue;
4757
+ }
4758
+ function attachAgentAliases(data) {
4759
+ const agentId = typeof data.workloadId === "string" ? data.workloadId : void 0;
4760
+ const versionId = typeof data.revisionId === "string" ? data.revisionId : void 0;
4761
+ return {
4762
+ ...data,
4763
+ ...agentId !== void 0 && data.agentId === void 0 ? { agentId } : {},
4764
+ ...versionId !== void 0 && data.versionId === void 0 ? { versionId } : {}
4765
+ };
4766
+ }
4767
+
4616
4768
  // src/resources/sessions.ts
4769
+ function normalizeSessionRequest(request) {
4770
+ const { agentId, versionId, ...rest } = request;
4771
+ const workloadId = resolveExclusiveAlias("workloadId", rest.workloadId, "agentId", agentId);
4772
+ const revisionId = resolveExclusiveAlias("revisionId", rest.revisionId, "versionId", versionId);
4773
+ if (workloadId === void 0) {
4774
+ throw new PilotPlatformApiError({
4775
+ status: 0,
4776
+ code: "WORKLOAD_ID_REQUIRED",
4777
+ message: "sessions.create requires `agentId` (or `workloadId`)."
4778
+ });
4779
+ }
4780
+ return {
4781
+ ...rest,
4782
+ workloadId,
4783
+ ...revisionId !== void 0 ? { revisionId } : {}
4784
+ };
4785
+ }
4617
4786
  var SessionsResource = class {
4618
4787
  constructor(client) {
4619
4788
  this.client = client;
4620
4789
  }
4621
4790
  async create(request, options = {}) {
4622
- const body = CreatePlatformSessionRequestSchema.parse(request);
4791
+ const body = CreatePlatformSessionRequestSchema.parse(normalizeSessionRequest(request));
4623
4792
  const envelope = await this.client.request("/api/sessions", {
4624
4793
  method: "POST",
4625
4794
  body,
@@ -4675,6 +4844,25 @@ var SessionsResource = class {
4675
4844
  await sleep(intervalMs, options.signal);
4676
4845
  }
4677
4846
  }
4847
+ /**
4848
+ * Release the session's current sandbox while keeping the session alive — a
4849
+ * later turn transparently revives it onto a fresh sandbox. Use this to free
4850
+ * runtime resources for an idle-but-not-finished session without terminating
4851
+ * it. Idempotent at the sandbox layer (an already-gone sandbox still succeeds).
4852
+ *
4853
+ * `sandboxDestroyed: false` (with `destroyError`) is NOT a failure — the
4854
+ * session is still correctly reclaimed; see {@link ReleaseSandboxResponse}.
4855
+ */
4856
+ async releaseSandbox(sessionId, options = {}) {
4857
+ const envelope = await this.client.request(
4858
+ `/api/sessions/${encodeURIComponent(sessionId)}/release-sandbox`,
4859
+ {
4860
+ method: "POST",
4861
+ signal: options.signal
4862
+ }
4863
+ );
4864
+ return ReleaseSandboxResponseSchema.parse(envelope?.data);
4865
+ }
4678
4866
  };
4679
4867
  function sleep(ms, signal) {
4680
4868
  if (ms <= 0) return Promise.resolve();
@@ -4740,7 +4928,12 @@ var WorkloadsResource = class {
4740
4928
  return unwrapEnvelope(envelope, "POST /api/workloads", ["status", "workload"]);
4741
4929
  }
4742
4930
  async applyRevisionManifest(options) {
4743
- const slug = options.workloadSlug ?? options.agentSlug;
4931
+ const slug = resolveExclusiveAlias(
4932
+ "workloadSlug",
4933
+ options.workloadSlug,
4934
+ "agentSlug",
4935
+ options.agentSlug
4936
+ );
4744
4937
  if (!slug) {
4745
4938
  throw new PilotPlatformApiError({
4746
4939
  status: 0,
@@ -4805,7 +4998,7 @@ function unwrapEnvelope(envelope, routeLabel, requiredKeys) {
4805
4998
  });
4806
4999
  }
4807
5000
  }
4808
- return data;
5001
+ return attachAgentAliases(data);
4809
5002
  }
4810
5003
 
4811
5004
  // src/client.ts
@@ -5001,11 +5194,13 @@ function mergeSignals(...signals) {
5001
5194
  // Annotate the CommonJS export names for ESM import in node:
5002
5195
  0 && (module.exports = {
5003
5196
  AGENTHUB_SDK_USER_AGENT,
5197
+ AgentPackageSchema,
5004
5198
  AgentsResource,
5005
5199
  CreatePlatformProjectRequestSchema,
5006
5200
  CreatePlatformSessionRequestSchema,
5007
5201
  CreatePlatformSessionResponseSchema,
5008
5202
  CreatePlatformWorkloadRequestSchema,
5203
+ DeletePlatformProjectResponseSchema,
5009
5204
  FilesResource,
5010
5205
  ListPlatformProjectsResponseSchema,
5011
5206
  PILOT_WORKLOAD_MANIFEST_API_VERSION,
@@ -5022,6 +5217,7 @@ function mergeSignals(...signals) {
5022
5217
  PlatformWorkloadSchema,
5023
5218
  ProjectsResource,
5024
5219
  PublishPlatformRevisionRequestSchema,
5220
+ ReleaseSandboxResponseSchema,
5025
5221
  SessionFileResourceSchema,
5026
5222
  SessionResourcesSchema,
5027
5223
  SessionsResource,