@akashnetwork/chain-sdk 1.0.0-alpha.44 → 1.0.0-alpha.45
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/cjs/sdl/manifest/generateManifest.cjs +19 -31
- package/dist/cjs/sdl/manifest/generateManifest.cjs.map +2 -2
- package/dist/cjs/sdl/manifest/manifestUtils.cjs +46 -23
- package/dist/cjs/sdl/manifest/manifestUtils.cjs.map +2 -2
- package/dist/cjs/sdl/validateSDL/validateSDLInput.cjs +1402 -1369
- package/dist/cjs/sdl/validateSDL/validateSDLInput.cjs.map +2 -2
- package/dist/esm/{chunk-6MIQPNOR.js → chunk-JN5DGAQY.js} +1465 -1424
- package/dist/esm/chunk-JN5DGAQY.js.map +7 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.web.js +1 -1
- package/dist/sdl-schema.yaml +15 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/sdl/manifest/manifestUtils.d.ts +12 -0
- package/dist/types/sdl/validateSDL/validateSDLInput.d.ts +19 -1
- package/package.json +1 -1
- package/dist/esm/chunk-6MIQPNOR.js.map +0 -7
|
@@ -55,9 +55,9 @@ function generateManifest(sdl) {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
for (const list of deploymentsByPlacement.values()) {
|
|
58
|
-
list.sort(([a], [b]) =>
|
|
58
|
+
list.sort(([a], [b]) => (0, import_manifestUtils.compareStrings)(a, b));
|
|
59
59
|
}
|
|
60
|
-
const services = Object.entries(sdl.services).sort(([a], [b]) =>
|
|
60
|
+
const services = Object.entries(sdl.services).sort(([a], [b]) => (0, import_manifestUtils.compareStrings)(a, b));
|
|
61
61
|
for (const [svcName, service] of services) {
|
|
62
62
|
for (const [placementName, svcdepl] of Object.entries(sdl.deployment[svcName])) {
|
|
63
63
|
const compute = sdl.profiles.compute[svcdepl.profile];
|
|
@@ -90,7 +90,7 @@ function generateManifest(sdl) {
|
|
|
90
90
|
if (teeType && !group.teeType) {
|
|
91
91
|
group.teeType = teeType;
|
|
92
92
|
group.dgroup.requirements.attributes.push({ key: "tee/type", value: teeType });
|
|
93
|
-
group.dgroup.requirements.attributes.sort((a, b) => a.key
|
|
93
|
+
group.dgroup.requirements.attributes.sort((a, b) => (0, import_manifestUtils.compareStrings)(a.key, b.key));
|
|
94
94
|
}
|
|
95
95
|
const profileKey = `${placementName}:${svcdepl.profile}`;
|
|
96
96
|
const location = group.boundComputes[svcdepl.profile];
|
|
@@ -114,16 +114,12 @@ function generateManifest(sdl) {
|
|
|
114
114
|
group.dgroup.resources[location].resource.endpoints.push(
|
|
115
115
|
...(0, import_manifestUtils.buildServiceEndpoints)(service, endpointSequenceNumbers)
|
|
116
116
|
);
|
|
117
|
+
group.dgroup.resources[location].resource.endpoints.sort(
|
|
118
|
+
(a, b) => a.sequenceNumber - b.sequenceNumber
|
|
119
|
+
);
|
|
117
120
|
}
|
|
118
121
|
}
|
|
119
122
|
}
|
|
120
|
-
for (const group of groupsMap.values()) {
|
|
121
|
-
for (const resourceUnit of group.dgroup.resources) {
|
|
122
|
-
resourceUnit.resource.endpoints.sort(
|
|
123
|
-
(a, b) => a.kind - b.kind || a.sequenceNumber - b.sequenceNumber
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
123
|
const sortedGroupNames = [...groupsMap.keys()].sort();
|
|
128
124
|
let groups;
|
|
129
125
|
let groupSpecs;
|
|
@@ -244,26 +240,18 @@ function buildParams(service) {
|
|
|
244
240
|
return result;
|
|
245
241
|
}
|
|
246
242
|
function buildManifestExpose(service, endpointSequenceNumbers) {
|
|
247
|
-
return (
|
|
248
|
-
(expose) =>
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
)
|
|
261
|
-
).sort((a, b) => {
|
|
262
|
-
if (a.service !== b.service) return a.service.localeCompare(b.service);
|
|
263
|
-
if (a.port !== b.port) return a.port - b.port;
|
|
264
|
-
if (a.proto !== b.proto) return a.proto.localeCompare(b.proto);
|
|
265
|
-
if (a.global !== b.global) return a.global ? -1 : 1;
|
|
266
|
-
return 0;
|
|
267
|
-
});
|
|
243
|
+
return (0, import_manifestUtils.sortedExposeTargets)(service).map(
|
|
244
|
+
({ expose, to }) => import_serviceexpose.ServiceExpose.fromPartial({
|
|
245
|
+
port: expose.port,
|
|
246
|
+
externalPort: expose.as,
|
|
247
|
+
proto: (0, import_manifestUtils.parseServiceProto)(expose.proto),
|
|
248
|
+
service: to.service || "",
|
|
249
|
+
global: to.global || false,
|
|
250
|
+
hosts: expose.accept || [],
|
|
251
|
+
httpOptions: (0, import_manifestUtils.buildHttpOptions)(expose.http_options),
|
|
252
|
+
ip: to.ip || "",
|
|
253
|
+
endpointSequenceNumber: endpointSequenceNumbers[to.ip]
|
|
254
|
+
})
|
|
255
|
+
);
|
|
268
256
|
}
|
|
269
257
|
//# sourceMappingURL=generateManifest.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/sdl/manifest/generateManifest.ts"],
|
|
4
|
-
"sourcesContent": ["import { PlacementRequirements, SignedBy } from \"../../generated/protos/akash/base/attributes/v1/attribute.ts\";\nimport { CPU } from \"../../generated/protos/akash/base/resources/v1beta4/cpu.ts\";\nimport { GPU } from \"../../generated/protos/akash/base/resources/v1beta4/gpu.ts\";\nimport { Memory } from \"../../generated/protos/akash/base/resources/v1beta4/memory.ts\";\nimport { Resources } from \"../../generated/protos/akash/base/resources/v1beta4/resources.ts\";\nimport { Storage } from \"../../generated/protos/akash/base/resources/v1beta4/storage.ts\";\nimport { DeploymentReclamation } from \"../../generated/protos/akash/deployment/v1/deployment.ts\";\nimport { GroupSpec } from \"../../generated/protos/akash/deployment/v1beta4/groupspec.ts\";\nimport { ResourceUnit } from \"../../generated/protos/akash/deployment/v1beta4/resourceunit.ts\";\nimport { Group } from \"../../generated/protos/akash/manifest/v2beta3/group.ts\";\nimport { ImageCredentials, Service, ServiceParams, StorageParams, TEEParams } from \"../../generated/protos/akash/manifest/v2beta3/service.ts\";\nimport { ServiceExpose } from \"../../generated/protos/akash/manifest/v2beta3/serviceexpose.ts\";\nimport type { ValidationError } from \"../../utils/jsonSchemaValidation.ts\";\nimport { castArray } from \"../utils.ts\";\nimport type { SDLInput } from \"../validateSDL/validateSDL.ts\";\nimport { validateSDL } from \"../validateSDL/validateSDL.ts\";\nimport {\n buildHttpOptions,\n buildResourceAttributes,\n buildServiceEndpoints,\n buildStorageAttributes,\n computeEndpointSequenceNumbers,\n parseCpuUnits,\n parseGpuUnits,\n parseMemoryBytes,\n parseServiceProto,\n parseStorageBytes,\n resolveInterconnectGroup,\n type SDLCompute,\n type SDLService,\n transformGpuAttributes,\n} from \"./manifestUtils.ts\";\nimport { minWindowToDuration } from \"./reclamationDuration.ts\";\n\nexport interface GenerateManifestOkResult {\n groups: Group[];\n groupSpecs: GroupSpec[];\n reclamation?: DeploymentReclamation;\n}\n\nexport type Manifest = GenerateManifestOkResult[\"groups\"];\nexport type GenerateManifestResult =\n | { ok?: false; value: ValidationError[] }\n | { ok: true; value: GenerateManifestOkResult };\nexport function generateManifest(sdl: SDLInput): GenerateManifestResult {\n const errors = validateSDL(sdl);\n if (errors) return { ok: false, value: errors };\n\n const endpointSequenceNumbers = computeEndpointSequenceNumbers(sdl.services);\n const groupsMap = new Map<string, {\n dgroup: GroupSpec;\n boundComputes: Record<string, number>;\n teeType?: string;\n }>();\n const resourceIds = new Map<string, number>();\n\n const deploymentsByPlacement = new Map<string, [string, { profile: string; count: number }][]>();\n for (const [svcName, placements] of Object.entries(sdl.deployment)) {\n for (const [placementName, deployment] of Object.entries(placements)) {\n let list = deploymentsByPlacement.get(placementName);\n if (!list) {\n list = [];\n deploymentsByPlacement.set(placementName, list);\n }\n list.push([svcName, deployment]);\n }\n }\n for (const list of deploymentsByPlacement.values()) {\n list.sort(([a], [b]) => a.localeCompare(b));\n }\n\n const services = Object.entries(sdl.services).sort(([a], [b]) => a.localeCompare(b));\n\n for (const [svcName, service] of services) {\n for (const [placementName, svcdepl] of Object.entries(sdl.deployment[svcName])) {\n const compute = sdl.profiles.compute[svcdepl.profile];\n const infra = sdl.profiles.placement[placementName];\n const pricing = infra.pricing[svcdepl.profile];\n const price = {\n denom: pricing.denom,\n amount: pricing.amount?.toString(),\n };\n\n let group = groupsMap.get(placementName);\n\n if (!group) {\n group = {\n dgroup: GroupSpec.fromPartial({\n name: placementName,\n resources: [],\n requirements: PlacementRequirements.fromPartial({\n attributes: buildResourceAttributes(infra.attributes),\n signedBy: SignedBy.fromPartial({\n allOf: infra.signedBy?.allOf,\n anyOf: infra.signedBy?.anyOf,\n }),\n }),\n }),\n boundComputes: {},\n teeType: undefined,\n };\n\n groupsMap.set(placementName, group);\n }\n\n const teeType = service.params?.tee;\n if (teeType && !group.teeType) {\n group.teeType = teeType;\n group.dgroup.requirements!.attributes.push({ key: \"tee/type\", value: teeType });\n group.dgroup.requirements!.attributes.sort((a, b) => a.key.localeCompare(b.key));\n }\n\n const profileKey = `${placementName}:${svcdepl.profile}`;\n const location = group.boundComputes[svcdepl.profile];\n\n if (location === undefined) {\n const resId = group.dgroup.resources.length > 0\n ? group.dgroup.resources.length + 1\n : 1;\n\n resourceIds.set(profileKey, resId);\n\n const resources = buildResources(resId, compute, service, endpointSequenceNumbers);\n\n group.dgroup.resources.push(\n ResourceUnit.fromPartial({\n resource: resources,\n count: svcdepl.count,\n price,\n }),\n );\n\n group.boundComputes[svcdepl.profile] = group.dgroup.resources.length - 1;\n } else {\n if (!resourceIds.has(profileKey)) {\n resourceIds.set(profileKey, group.dgroup.resources[location].resource!.id);\n }\n\n group.dgroup.resources[location].count += svcdepl.count;\n group.dgroup.resources[location].resource!.endpoints.push(\n ...buildServiceEndpoints(service, endpointSequenceNumbers),\n );\n }\n }\n }\n\n for (const group of groupsMap.values()) {\n for (const resourceUnit of group.dgroup.resources) {\n resourceUnit.resource!.endpoints.sort(\n (a, b) => a.kind - b.kind || a.sequenceNumber - b.sequenceNumber,\n );\n }\n }\n\n const sortedGroupNames = [...groupsMap.keys()].sort();\n let groups: Group[] | undefined;\n let groupSpecs: GroupSpec[] | undefined;\n let reclamation: DeploymentReclamation | undefined;\n\n const manifest = {\n // reclamation is a `MsgCreateDeployment` field, not a manifest group, and is\n // not needed in every call \u2014 so it's lazy like `groups`/`groupSpecs`.\n // `validateSDL` (run above) already guaranteed `min_window` is valid, so\n // `minWindowToDuration` never throws here.\n get reclamation() {\n if (sdl.reclamation && !reclamation) {\n reclamation = DeploymentReclamation.fromPartial({\n minWindow: minWindowToDuration(sdl.reclamation.min_window),\n });\n }\n return reclamation;\n },\n get groups() {\n groups ??= sortedGroupNames.map((placementName) => {\n const deployments = deploymentsByPlacement.get(placementName)!;\n\n return Group.fromPartial({\n name: placementName,\n services: deployments.map(([svcName]) => {\n const service = sdl.services[svcName];\n const deployment = sdl.deployment[svcName][placementName];\n const compute = sdl.profiles.compute[deployment.profile];\n const resourceId = resourceIds.get(`${placementName}:${deployment.profile}`) || 1;\n\n return buildManifestService(\n resourceId,\n svcName,\n service,\n compute,\n deployment.count,\n endpointSequenceNumbers,\n );\n }),\n });\n });\n return groups;\n },\n get groupSpecs() {\n groupSpecs ??= sortedGroupNames.map((name) => groupsMap.get(name)!.dgroup);\n return groupSpecs;\n },\n };\n\n return { ok: true, value: manifest };\n}\n\nfunction buildResources(\n id: number,\n compute: SDLCompute,\n service: SDLService,\n endpointSequenceNumbers: Record<string, number>,\n): Resources {\n const res = compute.resources;\n const cpuAttributes = buildResourceAttributes(res.cpu.attributes);\n const gpuAttributes = res.gpu?.attributes ? transformGpuAttributes(res.gpu.attributes) : [];\n\n return Resources.fromPartial({\n id,\n cpu: CPU.fromPartial({\n units: { val: parseCpuUnits(res.cpu) },\n attributes: cpuAttributes,\n }),\n memory: Memory.fromPartial({\n quantity: { val: parseMemoryBytes(res.memory) },\n }),\n storage: castArray(res.storage).map((s) =>\n Storage.fromPartial({\n name: s.name || \"default\",\n quantity: { val: parseStorageBytes(s.size) },\n attributes: buildStorageAttributes(s.attributes),\n }),\n ),\n gpu: GPU.fromPartial({\n units: { val: parseGpuUnits(res.gpu) },\n attributes: gpuAttributes,\n }),\n endpoints: buildServiceEndpoints(service, endpointSequenceNumbers),\n });\n}\n\nfunction buildManifestService(\n resourceId: number,\n name: string,\n service: SDLService,\n compute: SDLCompute,\n count: number,\n endpointSequenceNumbers: Record<string, number>,\n): Service {\n const credentials = service.credentials\n ? ImageCredentials.fromPartial({\n host: service.credentials.host,\n email: service.credentials.email || \"\",\n username: service.credentials.username,\n password: service.credentials.password,\n })\n : undefined;\n\n const params = buildParams(service);\n\n // The interconnect group lives under gpu.attributes.interconnect (either\n // `[]` for the implicit `auto` group or `{ group: <name> }` for an\n // explicit name) and propagates to the off-chain manifest's\n // Service.interconnectGroup field so the provider's workload builder\n // can label pods for per-group anti-affinity. The same value is also\n // emitted into Resources.GPU.Attributes by transformGpuAttributes \u2014\n // both consumers (bid engine vs. workload builder) see it.\n const interconnectGroup = resolveInterconnectGroup(compute.resources.gpu?.attributes?.interconnect);\n\n return Service.fromPartial({\n name,\n image: service.image,\n command: service.command || [],\n args: service.args || [],\n env: service.env || [],\n resources: buildResources(resourceId, compute, service, endpointSequenceNumbers),\n count,\n expose: buildManifestExpose(service, endpointSequenceNumbers),\n params,\n credentials,\n interconnectGroup,\n });\n}\n\nfunction buildParams(service: SDLService): ServiceParams | undefined {\n if (!service.params) return undefined;\n\n const storage = service.params.storage || {};\n const storageNames = service.params.storage ? Object.keys(storage).sort() : [];\n const result = ServiceParams.fromPartial({\n storage: storageNames.map((name) => {\n const config = storage[name];\n return StorageParams.fromPartial({\n name,\n mount: config.mount || \"\",\n readOnly: config.readOnly || false,\n });\n }),\n });\n\n // Permissions are not in the protobuf type but need to be preserved\n if (service.params.permissions) {\n (result as unknown as Record<string, unknown>).permissions = service.params.permissions;\n }\n\n // Project TEE onto the manifest, mirroring Go's groupBuilder\n // (params.TEE = {Type, Attestation: true}). `attestation` is hard-coded true\n // (not an input knob); the provider injects the attestation sidecar.\n if (service.params.tee) {\n result.tee = TEEParams.fromPartial({ type: service.params.tee, attestation: true });\n }\n\n return result;\n}\n\nfunction buildManifestExpose(\n service: SDLService,\n endpointSequenceNumbers: Record<string, number>,\n): ServiceExpose[] {\n return (service.expose ?? [])\n .flatMap((expose) =>\n (expose.to ?? []).map((to) =>\n ServiceExpose.fromPartial({\n port: expose.port,\n externalPort: expose.as,\n proto: parseServiceProto(expose.proto),\n service: to.service || \"\",\n global: to.global || false,\n hosts: expose.accept || [],\n httpOptions: buildHttpOptions(expose.http_options),\n ip: to.ip || \"\",\n endpointSequenceNumber: endpointSequenceNumbers[to.ip!],\n }),\n ),\n )\n .sort((a, b) => {\n if (a.service !== b.service) return a.service.localeCompare(b.service);\n if (a.port !== b.port) return a.port - b.port;\n if (a.proto !== b.proto) return a.proto.localeCompare(b.proto);\n if (a.global !== b.global) return a.global ? -1 : 1;\n return 0;\n });\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAgD;AAChD,iBAAoB;AACpB,iBAAoB;AACpB,oBAAuB;AACvB,uBAA0B;AAC1B,qBAAwB;AACxB,wBAAsC;AACtC,uBAA0B;AAC1B,0BAA6B;AAC7B,mBAAsB;AACtB,qBAAmF;AACnF,2BAA8B;AAE9B,mBAA0B;AAE1B,yBAA4B;AAC5B,
|
|
4
|
+
"sourcesContent": ["import { PlacementRequirements, SignedBy } from \"../../generated/protos/akash/base/attributes/v1/attribute.ts\";\nimport { CPU } from \"../../generated/protos/akash/base/resources/v1beta4/cpu.ts\";\nimport { GPU } from \"../../generated/protos/akash/base/resources/v1beta4/gpu.ts\";\nimport { Memory } from \"../../generated/protos/akash/base/resources/v1beta4/memory.ts\";\nimport { Resources } from \"../../generated/protos/akash/base/resources/v1beta4/resources.ts\";\nimport { Storage } from \"../../generated/protos/akash/base/resources/v1beta4/storage.ts\";\nimport { DeploymentReclamation } from \"../../generated/protos/akash/deployment/v1/deployment.ts\";\nimport { GroupSpec } from \"../../generated/protos/akash/deployment/v1beta4/groupspec.ts\";\nimport { ResourceUnit } from \"../../generated/protos/akash/deployment/v1beta4/resourceunit.ts\";\nimport { Group } from \"../../generated/protos/akash/manifest/v2beta3/group.ts\";\nimport { ImageCredentials, Service, ServiceParams, StorageParams, TEEParams } from \"../../generated/protos/akash/manifest/v2beta3/service.ts\";\nimport { ServiceExpose } from \"../../generated/protos/akash/manifest/v2beta3/serviceexpose.ts\";\nimport type { ValidationError } from \"../../utils/jsonSchemaValidation.ts\";\nimport { castArray } from \"../utils.ts\";\nimport type { SDLInput } from \"../validateSDL/validateSDL.ts\";\nimport { validateSDL } from \"../validateSDL/validateSDL.ts\";\nimport {\n buildHttpOptions,\n buildResourceAttributes,\n buildServiceEndpoints,\n buildStorageAttributes,\n compareStrings,\n computeEndpointSequenceNumbers,\n parseCpuUnits,\n parseGpuUnits,\n parseMemoryBytes,\n parseServiceProto,\n parseStorageBytes,\n resolveInterconnectGroup,\n type SDLCompute,\n type SDLService,\n sortedExposeTargets,\n transformGpuAttributes,\n} from \"./manifestUtils.ts\";\nimport { minWindowToDuration } from \"./reclamationDuration.ts\";\n\nexport interface GenerateManifestOkResult {\n groups: Group[];\n groupSpecs: GroupSpec[];\n reclamation?: DeploymentReclamation;\n}\n\nexport type Manifest = GenerateManifestOkResult[\"groups\"];\nexport type GenerateManifestResult =\n | { ok?: false; value: ValidationError[] }\n | { ok: true; value: GenerateManifestOkResult };\nexport function generateManifest(sdl: SDLInput): GenerateManifestResult {\n const errors = validateSDL(sdl);\n if (errors) return { ok: false, value: errors };\n\n const endpointSequenceNumbers = computeEndpointSequenceNumbers(sdl.services);\n const groupsMap = new Map<string, {\n dgroup: GroupSpec;\n boundComputes: Record<string, number>;\n teeType?: string;\n }>();\n const resourceIds = new Map<string, number>();\n\n const deploymentsByPlacement = new Map<string, [string, { profile: string; count: number }][]>();\n for (const [svcName, placements] of Object.entries(sdl.deployment)) {\n for (const [placementName, deployment] of Object.entries(placements)) {\n let list = deploymentsByPlacement.get(placementName);\n if (!list) {\n list = [];\n deploymentsByPlacement.set(placementName, list);\n }\n list.push([svcName, deployment]);\n }\n }\n for (const list of deploymentsByPlacement.values()) {\n list.sort(([a], [b]) => compareStrings(a, b));\n }\n\n const services = Object.entries(sdl.services).sort(([a], [b]) => compareStrings(a, b));\n\n for (const [svcName, service] of services) {\n for (const [placementName, svcdepl] of Object.entries(sdl.deployment[svcName])) {\n const compute = sdl.profiles.compute[svcdepl.profile];\n const infra = sdl.profiles.placement[placementName];\n const pricing = infra.pricing[svcdepl.profile];\n const price = {\n denom: pricing.denom,\n amount: pricing.amount?.toString(),\n };\n\n let group = groupsMap.get(placementName);\n\n if (!group) {\n group = {\n dgroup: GroupSpec.fromPartial({\n name: placementName,\n resources: [],\n requirements: PlacementRequirements.fromPartial({\n attributes: buildResourceAttributes(infra.attributes),\n signedBy: SignedBy.fromPartial({\n allOf: infra.signedBy?.allOf,\n anyOf: infra.signedBy?.anyOf,\n }),\n }),\n }),\n boundComputes: {},\n teeType: undefined,\n };\n\n groupsMap.set(placementName, group);\n }\n\n const teeType = service.params?.tee;\n if (teeType && !group.teeType) {\n group.teeType = teeType;\n group.dgroup.requirements!.attributes.push({ key: \"tee/type\", value: teeType });\n group.dgroup.requirements!.attributes.sort((a, b) => compareStrings(a.key, b.key));\n }\n\n const profileKey = `${placementName}:${svcdepl.profile}`;\n const location = group.boundComputes[svcdepl.profile];\n\n if (location === undefined) {\n const resId = group.dgroup.resources.length > 0\n ? group.dgroup.resources.length + 1\n : 1;\n\n resourceIds.set(profileKey, resId);\n\n const resources = buildResources(resId, compute, service, endpointSequenceNumbers);\n\n group.dgroup.resources.push(\n ResourceUnit.fromPartial({\n resource: resources,\n count: svcdepl.count,\n price,\n }),\n );\n\n group.boundComputes[svcdepl.profile] = group.dgroup.resources.length - 1;\n } else {\n if (!resourceIds.has(profileKey)) {\n resourceIds.set(profileKey, group.dgroup.resources[location].resource!.id);\n }\n\n group.dgroup.resources[location].count += svcdepl.count;\n group.dgroup.resources[location].resource!.endpoints.push(\n ...buildServiceEndpoints(service, endpointSequenceNumbers),\n );\n\n // Go re-sorts only when it merges a second service into an already-bound\n // profile, and `Endpoints.Less` compares the sequence number alone \u2014 kind\n // is not part of the ordering, so equal-sequence endpoints keep the order\n // the services were merged in. Sorting on kind too, or sorting the\n // single-service case, produces a different group spec than the chain.\n group.dgroup.resources[location].resource!.endpoints.sort(\n (a, b) => a.sequenceNumber - b.sequenceNumber,\n );\n }\n }\n }\n\n const sortedGroupNames = [...groupsMap.keys()].sort();\n let groups: Group[] | undefined;\n let groupSpecs: GroupSpec[] | undefined;\n let reclamation: DeploymentReclamation | undefined;\n\n const manifest = {\n // reclamation is a `MsgCreateDeployment` field, not a manifest group, and is\n // not needed in every call \u2014 so it's lazy like `groups`/`groupSpecs`.\n // `validateSDL` (run above) already guaranteed `min_window` is valid, so\n // `minWindowToDuration` never throws here.\n get reclamation() {\n if (sdl.reclamation && !reclamation) {\n reclamation = DeploymentReclamation.fromPartial({\n minWindow: minWindowToDuration(sdl.reclamation.min_window),\n });\n }\n return reclamation;\n },\n get groups() {\n groups ??= sortedGroupNames.map((placementName) => {\n const deployments = deploymentsByPlacement.get(placementName)!;\n\n return Group.fromPartial({\n name: placementName,\n services: deployments.map(([svcName]) => {\n const service = sdl.services[svcName];\n const deployment = sdl.deployment[svcName][placementName];\n const compute = sdl.profiles.compute[deployment.profile];\n const resourceId = resourceIds.get(`${placementName}:${deployment.profile}`) || 1;\n\n return buildManifestService(\n resourceId,\n svcName,\n service,\n compute,\n deployment.count,\n endpointSequenceNumbers,\n );\n }),\n });\n });\n return groups;\n },\n get groupSpecs() {\n groupSpecs ??= sortedGroupNames.map((name) => groupsMap.get(name)!.dgroup);\n return groupSpecs;\n },\n };\n\n return { ok: true, value: manifest };\n}\n\nfunction buildResources(\n id: number,\n compute: SDLCompute,\n service: SDLService,\n endpointSequenceNumbers: Record<string, number>,\n): Resources {\n const res = compute.resources;\n const cpuAttributes = buildResourceAttributes(res.cpu.attributes);\n const gpuAttributes = res.gpu?.attributes ? transformGpuAttributes(res.gpu.attributes) : [];\n\n return Resources.fromPartial({\n id,\n cpu: CPU.fromPartial({\n units: { val: parseCpuUnits(res.cpu) },\n attributes: cpuAttributes,\n }),\n memory: Memory.fromPartial({\n quantity: { val: parseMemoryBytes(res.memory) },\n }),\n storage: castArray(res.storage).map((s) =>\n Storage.fromPartial({\n name: s.name || \"default\",\n quantity: { val: parseStorageBytes(s.size) },\n attributes: buildStorageAttributes(s.attributes),\n }),\n ),\n gpu: GPU.fromPartial({\n units: { val: parseGpuUnits(res.gpu) },\n attributes: gpuAttributes,\n }),\n endpoints: buildServiceEndpoints(service, endpointSequenceNumbers),\n });\n}\n\nfunction buildManifestService(\n resourceId: number,\n name: string,\n service: SDLService,\n compute: SDLCompute,\n count: number,\n endpointSequenceNumbers: Record<string, number>,\n): Service {\n const credentials = service.credentials\n ? ImageCredentials.fromPartial({\n host: service.credentials.host,\n email: service.credentials.email || \"\",\n username: service.credentials.username,\n password: service.credentials.password,\n })\n : undefined;\n\n const params = buildParams(service);\n\n // The interconnect group lives under gpu.attributes.interconnect (either\n // `[]` for the implicit `auto` group or `{ group: <name> }` for an\n // explicit name) and propagates to the off-chain manifest's\n // Service.interconnectGroup field so the provider's workload builder\n // can label pods for per-group anti-affinity. The same value is also\n // emitted into Resources.GPU.Attributes by transformGpuAttributes \u2014\n // both consumers (bid engine vs. workload builder) see it.\n const interconnectGroup = resolveInterconnectGroup(compute.resources.gpu?.attributes?.interconnect);\n\n return Service.fromPartial({\n name,\n image: service.image,\n command: service.command || [],\n args: service.args || [],\n env: service.env || [],\n resources: buildResources(resourceId, compute, service, endpointSequenceNumbers),\n count,\n expose: buildManifestExpose(service, endpointSequenceNumbers),\n params,\n credentials,\n interconnectGroup,\n });\n}\n\nfunction buildParams(service: SDLService): ServiceParams | undefined {\n if (!service.params) return undefined;\n\n const storage = service.params.storage || {};\n const storageNames = service.params.storage ? Object.keys(storage).sort() : [];\n const result = ServiceParams.fromPartial({\n storage: storageNames.map((name) => {\n const config = storage[name];\n return StorageParams.fromPartial({\n name,\n mount: config.mount || \"\",\n readOnly: config.readOnly || false,\n });\n }),\n });\n\n // Permissions are not in the protobuf type but need to be preserved\n if (service.params.permissions) {\n (result as unknown as Record<string, unknown>).permissions = service.params.permissions;\n }\n\n // Project TEE onto the manifest, mirroring Go's groupBuilder\n // (params.TEE = {Type, Attestation: true}). `attestation` is hard-coded true\n // (not an input knob); the provider injects the attestation sidecar.\n if (service.params.tee) {\n result.tee = TEEParams.fromPartial({ type: service.params.tee, attestation: true });\n }\n\n return result;\n}\n\nfunction buildManifestExpose(\n service: SDLService,\n endpointSequenceNumbers: Record<string, number>,\n): ServiceExpose[] {\n return sortedExposeTargets(service).map(({ expose, to }) =>\n ServiceExpose.fromPartial({\n port: expose.port,\n externalPort: expose.as,\n proto: parseServiceProto(expose.proto),\n service: to.service || \"\",\n global: to.global || false,\n hosts: expose.accept || [],\n httpOptions: buildHttpOptions(expose.http_options),\n ip: to.ip || \"\",\n endpointSequenceNumber: endpointSequenceNumbers[to.ip!],\n }),\n );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAgD;AAChD,iBAAoB;AACpB,iBAAoB;AACpB,oBAAuB;AACvB,uBAA0B;AAC1B,qBAAwB;AACxB,wBAAsC;AACtC,uBAA0B;AAC1B,0BAA6B;AAC7B,mBAAsB;AACtB,qBAAmF;AACnF,2BAA8B;AAE9B,mBAA0B;AAE1B,yBAA4B;AAC5B,2BAiBO;AACP,iCAAoC;AAY7B,SAAS,iBAAiB,KAAuC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oB,OAAO,EAAE;AAAA,IAAI,CAAC,EAAE,QAAQ,GAAG,MACpD,mCAAc,YAAY;AAAA,MACxB,MAAM,OAAO;AAAA,MACb,cAAc,OAAO;AAAA,MACrB,WAAO,wCAAkB,OAAO,KAAK;AAAA,MACrC,SAAS,GAAG,WAAW;AAAA,MACvB,QAAQ,GAAG,UAAU;AAAA,MACrB,OAAO,OAAO,UAAU,CAAC;AAAA,MACzB,iBAAa,uCAAiB,OAAO,YAAY;AAAA,MACjD,IAAI,GAAG,MAAM;AAAA,MACb,wBAAwB,wBAAwB,GAAG,EAAG;AAAA,IACxD,CAAC;AAAA,EACH;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -23,6 +23,8 @@ __export(manifestUtils_exports, {
|
|
|
23
23
|
buildResourceAttributes: () => buildResourceAttributes,
|
|
24
24
|
buildServiceEndpoints: () => buildServiceEndpoints,
|
|
25
25
|
buildStorageAttributes: () => buildStorageAttributes,
|
|
26
|
+
compareExposes: () => compareExposes,
|
|
27
|
+
compareStrings: () => compareStrings,
|
|
26
28
|
computeEndpointSequenceNumbers: () => computeEndpointSequenceNumbers,
|
|
27
29
|
isIngress: () => isIngress,
|
|
28
30
|
parseCpuUnits: () => parseCpuUnits,
|
|
@@ -31,6 +33,7 @@ __export(manifestUtils_exports, {
|
|
|
31
33
|
parseServiceProto: () => parseServiceProto,
|
|
32
34
|
parseStorageBytes: () => parseStorageBytes,
|
|
33
35
|
resolveInterconnectGroup: () => resolveInterconnectGroup,
|
|
36
|
+
sortedExposeTargets: () => sortedExposeTargets,
|
|
34
37
|
transformGpuAttributes: () => transformGpuAttributes
|
|
35
38
|
});
|
|
36
39
|
module.exports = __toCommonJS(manifestUtils_exports);
|
|
@@ -56,6 +59,10 @@ function computeEndpointSequenceNumbers(services) {
|
|
|
56
59
|
return result;
|
|
57
60
|
}, {});
|
|
58
61
|
}
|
|
62
|
+
function compareStrings(a, b) {
|
|
63
|
+
if (a === b) return 0;
|
|
64
|
+
return a < b ? -1 : 1;
|
|
65
|
+
}
|
|
59
66
|
function isIngress(proto, global, externalPort, port) {
|
|
60
67
|
const effectivePort = externalPort === 0 ? port : externalPort;
|
|
61
68
|
return global && proto === "TCP" && effectivePort === 80;
|
|
@@ -75,7 +82,7 @@ function transformGpuAttributes(attributes) {
|
|
|
75
82
|
const result = [];
|
|
76
83
|
const vendor = attributes.vendor;
|
|
77
84
|
if (vendor) {
|
|
78
|
-
Object.keys(vendor).sort(
|
|
85
|
+
Object.keys(vendor).sort(compareStrings).forEach((vendorName) => {
|
|
79
86
|
const models = vendor[vendorName];
|
|
80
87
|
if (!models) {
|
|
81
88
|
result.push({ key: `vendor/${vendorName}/model/*`, value: "true" });
|
|
@@ -93,7 +100,7 @@ function transformGpuAttributes(attributes) {
|
|
|
93
100
|
if (group !== "") {
|
|
94
101
|
result.push({ key: "interconnect/group", value: group });
|
|
95
102
|
}
|
|
96
|
-
result.sort((a, b) => a.key
|
|
103
|
+
result.sort((a, b) => compareStrings(a.key, b.key));
|
|
97
104
|
return result;
|
|
98
105
|
}
|
|
99
106
|
function buildHttpOptions(httpOptions) {
|
|
@@ -139,32 +146,48 @@ function buildStorageAttributes(attributes) {
|
|
|
139
146
|
if (attributes.class === "ram" && !("persistent" in attributes)) {
|
|
140
147
|
pairs.push({ key: "persistent", value: "false" });
|
|
141
148
|
}
|
|
142
|
-
pairs.sort((a, b) => a.key
|
|
149
|
+
pairs.sort((a, b) => compareStrings(a.key, b.key));
|
|
143
150
|
return pairs;
|
|
144
151
|
}
|
|
145
152
|
function parseServiceProto(proto) {
|
|
146
153
|
return proto?.toUpperCase() || "TCP";
|
|
147
154
|
}
|
|
155
|
+
function compareExposes(a, b) {
|
|
156
|
+
if (a.service !== b.service) return compareStrings(a.service, b.service);
|
|
157
|
+
if (a.port !== b.port) return a.port - b.port;
|
|
158
|
+
if (a.proto !== b.proto) return compareStrings(a.proto, b.proto);
|
|
159
|
+
if (a.global !== b.global) return a.global ? -1 : 1;
|
|
160
|
+
return 0;
|
|
161
|
+
}
|
|
162
|
+
function sortedExposeTargets(service) {
|
|
163
|
+
return (service.expose ?? []).flatMap((expose) => (expose.to ?? []).map((to) => ({ expose, to }))).sort((a, b) => compareExposes(exposeSortKey(a), exposeSortKey(b)));
|
|
164
|
+
}
|
|
165
|
+
function exposeSortKey({ expose, to }) {
|
|
166
|
+
return {
|
|
167
|
+
service: to.service || "",
|
|
168
|
+
port: expose.port,
|
|
169
|
+
proto: parseServiceProto(expose.proto),
|
|
170
|
+
global: to.global || false
|
|
171
|
+
};
|
|
172
|
+
}
|
|
148
173
|
function buildServiceEndpoints(service, endpointSequenceNumbers) {
|
|
149
|
-
return (service.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
})
|
|
167
|
-
);
|
|
174
|
+
return sortedExposeTargets(service).filter(({ to }) => to.global).flatMap(({ expose, to }) => {
|
|
175
|
+
const externalPort = expose.as || 0;
|
|
176
|
+
const proto = parseServiceProto(expose.proto);
|
|
177
|
+
const kind = isIngress(proto, !!to.global, externalPort, expose.port) ? import_index_akash_v1beta4.Endpoint_Kind.SHARED_HTTP : import_index_akash_v1beta4.Endpoint_Kind.RANDOM_PORT;
|
|
178
|
+
const defaultEp = import_index_akash_v1beta4.Endpoint.fromPartial({
|
|
179
|
+
kind,
|
|
180
|
+
sequenceNumber: 0
|
|
181
|
+
});
|
|
182
|
+
if (!to.ip?.length) {
|
|
183
|
+
return [defaultEp];
|
|
184
|
+
}
|
|
185
|
+
const leasedEp = import_index_akash_v1beta4.Endpoint.fromPartial({
|
|
186
|
+
kind: import_index_akash_v1beta4.Endpoint_Kind.LEASED_IP,
|
|
187
|
+
sequenceNumber: endpointSequenceNumbers[to.ip] ?? 0
|
|
188
|
+
});
|
|
189
|
+
return [defaultEp, leasedEp];
|
|
190
|
+
});
|
|
168
191
|
}
|
|
169
192
|
function parseCpuUnits(cpu) {
|
|
170
193
|
return typeof cpu.units === "string" ? (0, import_sizes.convertCpuResourceString)(cpu.units) : (0, import_sizes.convertCpuResourceString)(String(cpu.units));
|
|
@@ -182,6 +205,6 @@ function parseGpuUnits(gpu) {
|
|
|
182
205
|
}
|
|
183
206
|
function buildResourceAttributes(attributes) {
|
|
184
207
|
if (!attributes) return void 0;
|
|
185
|
-
return Object.keys(attributes).sort(
|
|
208
|
+
return Object.keys(attributes).sort(compareStrings).map((key) => ({ key, value: String(attributes[key]) }));
|
|
186
209
|
}
|
|
187
210
|
//# sourceMappingURL=manifestUtils.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/sdl/manifest/manifestUtils.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Attribute } from \"../../generated/protos/index.akash.v1.ts\";\nimport {\n Endpoint,\n Endpoint_Kind,\n} from \"../../generated/protos/index.akash.v1beta4.ts\";\nimport {\n ProxyOptions,\n ServiceExposeHTTPOptions,\n} from \"../../generated/protos/index.provider.akash.v2beta3.ts\";\nimport { parseHTTPTimeout } from \"../httpTimeout.ts\";\nimport { convertCpuResourceString, convertResourceString } from \"../sizes.ts\";\nimport type { SDLInput } from \"../validateSDL/validateSDL.ts\";\nimport type { StorageAttributesValidation } from \"../validateSDL/validateSDLInput.ts\";\n\ntype SDLService = SDLInput[\"services\"][string];\ntype SDLExpose = NonNullable<SDLService[\"expose\"]>[number];\ntype SDLExposeTo = NonNullable<SDLExpose[\"to\"]>[number];\ntype SDLHttpOptions = SDLExpose[\"http_options\"];\ntype SDLHttpProxyOptions = NonNullable<SDLHttpOptions>[\"proxy\"];\ntype SDLCompute = SDLInput[\"profiles\"][\"compute\"][string];\ntype SDLStorage = SDLCompute[\"resources\"][\"storage\"];\ntype SDLStorageVolume = SDLStorage extends (infer T)[] ? T : SDLStorage;\ntype SDLGpuAttributes = NonNullable<NonNullable<SDLCompute[\"resources\"][\"gpu\"]>[\"attributes\"]>;\n\nexport type { SDLCompute, SDLExpose, SDLExposeTo, SDLGpuAttributes, SDLHttpOptions, SDLService, SDLStorage, SDLStorageVolume };\n\nexport function computeEndpointSequenceNumbers(services: SDLInput[\"services\"]): Record<string, number> {\n const endpointNames: string[] = [];\n\n for (const service of Object.values(services)) {\n if (!service.expose) continue;\n for (const expose of service.expose) {\n if (!expose.to) continue;\n for (const to of expose.to) {\n if (to.global && to.ip && to.ip.length > 0) {\n endpointNames.push(to.ip);\n }\n }\n }\n }\n\n return endpointNames.sort().reduce<Record<string, number>>((result, name, seqNumber) => {\n result[name] = seqNumber + 1;\n return result;\n }, {});\n}\n\nexport function isIngress(proto: string, global: boolean, externalPort: number, port: number): boolean {\n const effectivePort = externalPort === 0 ? port : externalPort;\n return global && proto === \"TCP\" && effectivePort === 80;\n}\n\n// INTERCONNECT_GROUP_AUTO is the reserved name the SDL parser assigns to\n// every `interconnect: []` opt-in within one placement. Tenants cannot\n// write it explicitly under `interconnect: { group: ... }` \u2014 mirrors\n// `InterconnectGroupAuto` in go/sdl/gpu.go.\nexport const INTERCONNECT_GROUP_AUTO = \"auto\";\n\n// resolveInterconnectGroup returns the group string the parser derives\n// from gpu.attributes.interconnect:\n// - empty sequence `[]` \u2192 INTERCONNECT_GROUP_AUTO (\"auto\")\n// - mapping `{ group: <name> }` \u2192 <name>\n// - anything else / absent \u2192 \"\" (non-interconnect)\n// Both the on-chain attribute emitter and the off-chain manifest builder\n// route through this helper so they agree on the resolved value.\nexport function resolveInterconnectGroup(interconnect: SDLGpuAttributes[\"interconnect\"]): string {\n if (Array.isArray(interconnect)) {\n return interconnect.length === 0 ? INTERCONNECT_GROUP_AUTO : \"\";\n }\n if (interconnect && typeof interconnect === \"object\" && \"group\" in interconnect) {\n const g = (interconnect as { group?: unknown }).group;\n return typeof g === \"string\" ? g : \"\";\n }\n return \"\";\n}\n\nexport function transformGpuAttributes(attributes: SDLGpuAttributes): Attribute[] {\n const result: Attribute[] = [];\n\n const vendor = attributes.vendor;\n if (vendor) {\n Object.keys(vendor)\n .sort((a, b) => a.localeCompare(b))\n .forEach((vendorName) => {\n const models = vendor[vendorName as keyof typeof vendor];\n if (!models) {\n result.push({ key: `vendor/${vendorName}/model/*`, value: \"true\" });\n return;\n }\n for (const model of models) {\n let key = `vendor/${vendorName}/model/${model.model}`;\n if (model.ram) key += `/ram/${model.ram}`;\n if (model.interface) key += `/interface/${model.interface}`;\n result.push({ key, value: \"true\" });\n }\n });\n }\n\n // interconnect emits a single on-chain attribute `interconnect/group` \u2014\n // the group is the entire opt-in signal. Keep parity with the Go parser\n // in go/sdl/gpu.go: empty sequence `[]` resolves to the reserved literal\n // `auto`, the explicit mapping form `{ group: <name> }` carries the\n // tenant-chosen name. See docs/sdl-interconnect-spec.md.\n const group = resolveInterconnectGroup(attributes.interconnect);\n if (group !== \"\") {\n result.push({ key: \"interconnect/group\", value: group });\n }\n\n // Go SDL parser canonicalizes the slice via sort.Sort(res) before\n // returning. Mirror that here so the on-chain attribute order matches\n // byte-for-byte across both implementations.\n result.sort((a, b) => a.key.localeCompare(b.key));\n\n return result;\n}\n\nexport function buildHttpOptions(httpOptions?: SDLHttpOptions): ServiceExposeHTTPOptions {\n return ServiceExposeHTTPOptions.fromPartial({\n maxBodySize: httpOptions?.max_body_size ?? 1048576,\n readTimeout: normalizedHTTPTimeout(httpOptions?.read_timeout),\n sendTimeout: normalizedHTTPTimeout(httpOptions?.send_timeout),\n nextTries: httpOptions?.next_tries ?? 3,\n nextTimeout: httpOptions?.next_timeout ?? 0,\n nextCases: httpOptions?.next_cases ?? [\"error\", \"timeout\"],\n proxy: buildProxyOptions(httpOptions?.proxy),\n });\n}\n\nfunction buildProxyOptions(proxy?: SDLHttpProxyOptions): ProxyOptions | undefined {\n if (!proxy) return undefined;\n\n const bufferingDisable = proxy.buffering_disable ?? false;\n const bufferSize = proxy.buffer_size ?? 0;\n const buffersNumber = proxy.buffers_number ?? 0;\n const buffersSize = proxy.buffers_size ?? 0;\n const busyBuffersSize = proxy.busy_buffers_size ?? 0;\n const connectTimeout = proxy.connect_timeout ?? 0;\n\n if ((buffersNumber === 0) !== (buffersSize === 0)) {\n throw new Error(\"proxy.buffers_number and proxy.buffers_size must be set together\");\n }\n\n if (!bufferingDisable && bufferSize === 0 && buffersNumber === 0 && buffersSize === 0 && busyBuffersSize === 0 && connectTimeout === 0) {\n return undefined;\n }\n\n return ProxyOptions.fromPartial({ bufferingDisable, bufferSize, buffersNumber, buffersSize, busyBuffersSize, connectTimeout });\n}\n\nfunction normalizedHTTPTimeout(value: number | string | undefined): number {\n const result = parseHTTPTimeout(value ?? 60_000);\n if (!result.ok) {\n throw new Error(`Invalid HTTP timeout: ${result.message}`);\n }\n\n return result.milliseconds;\n}\n\nexport function buildStorageAttributes(attributes?: StorageAttributesValidation): Attribute[] {\n if (!attributes) return [];\n\n const pairs: Attribute[] = Object.entries(attributes).map(([key, value]) => ({\n key,\n value: String(value),\n }));\n\n if (attributes.class === \"ram\" && !(\"persistent\" in attributes)) {\n pairs.push({ key: \"persistent\", value: \"false\" });\n }\n\n pairs.sort((a, b) => a.key.localeCompare(b.key));\n return pairs;\n}\n\nexport function parseServiceProto(proto?: string): string {\n return proto?.toUpperCase() || \"TCP\";\n}\n\nexport function buildServiceEndpoints(\n service: SDLService,\n endpointSequenceNumbers: Record<string, number>,\n): Endpoint[] {\n return (service.expose ?? []).flatMap((expose) =>\n (expose.to ?? [])\n .filter((to) => to.global)\n .flatMap((to) => {\n const externalPort = expose.as || 0;\n const proto = parseServiceProto(expose.proto);\n const kind = isIngress(proto, !!to.global, externalPort, expose.port)\n ? Endpoint_Kind.SHARED_HTTP\n : Endpoint_Kind.RANDOM_PORT;\n\n const defaultEp = Endpoint.fromPartial({\n kind,\n sequenceNumber: 0,\n });\n\n if (!to.ip?.length) {\n return [defaultEp];\n }\n\n const leasedEp = Endpoint.fromPartial({\n kind: Endpoint_Kind.LEASED_IP,\n sequenceNumber: endpointSequenceNumbers[to.ip] ?? 0,\n });\n\n return [defaultEp, leasedEp];\n }),\n );\n}\n\nexport function parseCpuUnits(cpu: SDLCompute[\"resources\"][\"cpu\"]): bigint {\n return typeof cpu.units === \"string\"\n ? convertCpuResourceString(cpu.units)\n : convertCpuResourceString(String(cpu.units));\n}\n\nexport function parseMemoryBytes(memory: SDLCompute[\"resources\"][\"memory\"]): bigint {\n return convertResourceString(memory.size);\n}\n\nexport function parseStorageBytes(size: string): bigint {\n return convertResourceString(size);\n}\n\nexport function parseGpuUnits(gpu?: SDLCompute[\"resources\"][\"gpu\"]): bigint {\n const value = gpu?.units;\n if (value === undefined || value === null) return 0n;\n return BigInt(value);\n}\n\nexport function buildResourceAttributes(attributes?: Record<string, unknown>): Attribute[] | undefined {\n if (!attributes) return undefined;\n return Object.keys(attributes)\n .sort((a, b) => a.localeCompare(b))\n .map((key) => ({ key, value: String(attributes[key]) }));\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iCAGO;AACP,0CAGO;AACP,yBAAiC;AACjC,mBAAgE;AAgBzD,SAAS,+BAA+B,UAAwD;AACrG,QAAM,gBAA0B,CAAC;AAEjC,aAAW,WAAW,OAAO,OAAO,QAAQ,GAAG;AAC7C,QAAI,CAAC,QAAQ,OAAQ;AACrB,eAAW,UAAU,QAAQ,QAAQ;AACnC,UAAI,CAAC,OAAO,GAAI;AAChB,iBAAW,MAAM,OAAO,IAAI;AAC1B,YAAI,GAAG,UAAU,GAAG,MAAM,GAAG,GAAG,SAAS,GAAG;AAC1C,wBAAc,KAAK,GAAG,EAAE;AAAA,QAC1B;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO,cAAc,KAAK,EAAE,OAA+B,CAAC,QAAQ,MAAM,cAAc;AACtF,WAAO,IAAI,IAAI,YAAY;AAC3B,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AACP;AAEO,SAAS,UAAU,OAAe,QAAiB,cAAsB,MAAuB;AACrG,QAAM,gBAAgB,iBAAiB,IAAI,OAAO;AAClD,SAAO,UAAU,UAAU,SAAS,kBAAkB;AACxD;AAMO,MAAM,0BAA0B;AAShC,SAAS,yBAAyB,cAAwD;AAC/F,MAAI,MAAM,QAAQ,YAAY,GAAG;AAC/B,WAAO,aAAa,WAAW,IAAI,0BAA0B;AAAA,EAC/D;AACA,MAAI,gBAAgB,OAAO,iBAAiB,YAAY,WAAW,cAAc;AAC/E,UAAM,IAAK,aAAqC;AAChD,WAAO,OAAO,MAAM,WAAW,IAAI;AAAA,EACrC;AACA,SAAO;AACT;AAEO,SAAS,uBAAuB,YAA2C;AAChF,QAAM,SAAsB,CAAC;AAE7B,QAAM,SAAS,WAAW;AAC1B,MAAI,QAAQ;AACV,WAAO,KAAK,MAAM,EACf,KAAK,
|
|
4
|
+
"sourcesContent": ["import type { Attribute } from \"../../generated/protos/index.akash.v1.ts\";\nimport {\n Endpoint,\n Endpoint_Kind,\n} from \"../../generated/protos/index.akash.v1beta4.ts\";\nimport {\n ProxyOptions,\n ServiceExposeHTTPOptions,\n} from \"../../generated/protos/index.provider.akash.v2beta3.ts\";\nimport { parseHTTPTimeout } from \"../httpTimeout.ts\";\nimport { convertCpuResourceString, convertResourceString } from \"../sizes.ts\";\nimport type { SDLInput } from \"../validateSDL/validateSDL.ts\";\nimport type { StorageAttributesValidation } from \"../validateSDL/validateSDLInput.ts\";\n\ntype SDLService = SDLInput[\"services\"][string];\ntype SDLExpose = NonNullable<SDLService[\"expose\"]>[number];\ntype SDLExposeTo = NonNullable<SDLExpose[\"to\"]>[number];\ntype SDLHttpOptions = SDLExpose[\"http_options\"];\ntype SDLHttpProxyOptions = NonNullable<SDLHttpOptions>[\"proxy\"];\ntype SDLCompute = SDLInput[\"profiles\"][\"compute\"][string];\ntype SDLStorage = SDLCompute[\"resources\"][\"storage\"];\ntype SDLStorageVolume = SDLStorage extends (infer T)[] ? T : SDLStorage;\ntype SDLGpuAttributes = NonNullable<NonNullable<SDLCompute[\"resources\"][\"gpu\"]>[\"attributes\"]>;\n\nexport type { SDLCompute, SDLExpose, SDLExposeTo, SDLGpuAttributes, SDLHttpOptions, SDLService, SDLStorage, SDLStorageVolume };\n\nexport function computeEndpointSequenceNumbers(services: SDLInput[\"services\"]): Record<string, number> {\n const endpointNames: string[] = [];\n\n for (const service of Object.values(services)) {\n if (!service.expose) continue;\n for (const expose of service.expose) {\n if (!expose.to) continue;\n for (const to of expose.to) {\n if (to.global && to.ip && to.ip.length > 0) {\n endpointNames.push(to.ip);\n }\n }\n }\n }\n\n return endpointNames.sort().reduce<Record<string, number>>((result, name, seqNumber) => {\n result[name] = seqNumber + 1;\n return result;\n }, {});\n}\n\n// Go orders every string it sorts in the SDL builder with a plain `<`:\n// `Attributes.Less` compares keys, `ServiceExposes.Less` compares service names,\n// and placement/service names go through `sort.Strings`. `localeCompare` is not\n// the same relation \u2014 it folds case and demotes punctuation, so e.g. \"a_b\" and\n// \"aB\" come out in the opposite order. Attribute keys carry \"/\" and placement,\n// service and volume names are unconstrained strings, so the two can genuinely\n// disagree, and the resulting group spec is signed. Every sort on this path uses\n// this comparator instead.\nexport function compareStrings(a: string, b: string): number {\n if (a === b) return 0;\n return a < b ? -1 : 1;\n}\n\nexport function isIngress(proto: string, global: boolean, externalPort: number, port: number): boolean {\n const effectivePort = externalPort === 0 ? port : externalPort;\n return global && proto === \"TCP\" && effectivePort === 80;\n}\n\n// INTERCONNECT_GROUP_AUTO is the reserved name the SDL parser assigns to\n// every `interconnect: []` opt-in within one placement. Tenants cannot\n// write it explicitly under `interconnect: { group: ... }` \u2014 mirrors\n// `InterconnectGroupAuto` in go/sdl/gpu.go.\nexport const INTERCONNECT_GROUP_AUTO = \"auto\";\n\n// resolveInterconnectGroup returns the group string the parser derives\n// from gpu.attributes.interconnect:\n// - empty sequence `[]` \u2192 INTERCONNECT_GROUP_AUTO (\"auto\")\n// - mapping `{ group: <name> }` \u2192 <name>\n// - anything else / absent \u2192 \"\" (non-interconnect)\n// Both the on-chain attribute emitter and the off-chain manifest builder\n// route through this helper so they agree on the resolved value.\nexport function resolveInterconnectGroup(interconnect: SDLGpuAttributes[\"interconnect\"]): string {\n if (Array.isArray(interconnect)) {\n return interconnect.length === 0 ? INTERCONNECT_GROUP_AUTO : \"\";\n }\n if (interconnect && typeof interconnect === \"object\" && \"group\" in interconnect) {\n const g = (interconnect as { group?: unknown }).group;\n return typeof g === \"string\" ? g : \"\";\n }\n return \"\";\n}\n\nexport function transformGpuAttributes(attributes: SDLGpuAttributes): Attribute[] {\n const result: Attribute[] = [];\n\n const vendor = attributes.vendor;\n if (vendor) {\n Object.keys(vendor)\n .sort(compareStrings)\n .forEach((vendorName) => {\n const models = vendor[vendorName as keyof typeof vendor];\n if (!models) {\n result.push({ key: `vendor/${vendorName}/model/*`, value: \"true\" });\n return;\n }\n for (const model of models) {\n let key = `vendor/${vendorName}/model/${model.model}`;\n if (model.ram) key += `/ram/${model.ram}`;\n if (model.interface) key += `/interface/${model.interface}`;\n result.push({ key, value: \"true\" });\n }\n });\n }\n\n // interconnect emits a single on-chain attribute `interconnect/group` \u2014\n // the group is the entire opt-in signal. Keep parity with the Go parser\n // in go/sdl/gpu.go: empty sequence `[]` resolves to the reserved literal\n // `auto`, the explicit mapping form `{ group: <name> }` carries the\n // tenant-chosen name. See docs/sdl-interconnect-spec.md.\n const group = resolveInterconnectGroup(attributes.interconnect);\n if (group !== \"\") {\n result.push({ key: \"interconnect/group\", value: group });\n }\n\n // Go SDL parser canonicalizes the slice via sort.Sort(res) before\n // returning. Mirror that here so the on-chain attribute order matches\n // byte-for-byte across both implementations.\n result.sort((a, b) => compareStrings(a.key, b.key));\n\n return result;\n}\n\nexport function buildHttpOptions(httpOptions?: SDLHttpOptions): ServiceExposeHTTPOptions {\n return ServiceExposeHTTPOptions.fromPartial({\n maxBodySize: httpOptions?.max_body_size ?? 1048576,\n readTimeout: normalizedHTTPTimeout(httpOptions?.read_timeout),\n sendTimeout: normalizedHTTPTimeout(httpOptions?.send_timeout),\n nextTries: httpOptions?.next_tries ?? 3,\n nextTimeout: httpOptions?.next_timeout ?? 0,\n nextCases: httpOptions?.next_cases ?? [\"error\", \"timeout\"],\n proxy: buildProxyOptions(httpOptions?.proxy),\n });\n}\n\nfunction buildProxyOptions(proxy?: SDLHttpProxyOptions): ProxyOptions | undefined {\n if (!proxy) return undefined;\n\n const bufferingDisable = proxy.buffering_disable ?? false;\n const bufferSize = proxy.buffer_size ?? 0;\n const buffersNumber = proxy.buffers_number ?? 0;\n const buffersSize = proxy.buffers_size ?? 0;\n const busyBuffersSize = proxy.busy_buffers_size ?? 0;\n const connectTimeout = proxy.connect_timeout ?? 0;\n\n if ((buffersNumber === 0) !== (buffersSize === 0)) {\n throw new Error(\"proxy.buffers_number and proxy.buffers_size must be set together\");\n }\n\n if (!bufferingDisable && bufferSize === 0 && buffersNumber === 0 && buffersSize === 0 && busyBuffersSize === 0 && connectTimeout === 0) {\n return undefined;\n }\n\n return ProxyOptions.fromPartial({ bufferingDisable, bufferSize, buffersNumber, buffersSize, busyBuffersSize, connectTimeout });\n}\n\nfunction normalizedHTTPTimeout(value: number | string | undefined): number {\n const result = parseHTTPTimeout(value ?? 60_000);\n if (!result.ok) {\n throw new Error(`Invalid HTTP timeout: ${result.message}`);\n }\n\n return result.milliseconds;\n}\n\nexport function buildStorageAttributes(attributes?: StorageAttributesValidation): Attribute[] {\n if (!attributes) return [];\n\n const pairs: Attribute[] = Object.entries(attributes).map(([key, value]) => ({\n key,\n value: String(value),\n }));\n\n if (attributes.class === \"ram\" && !(\"persistent\" in attributes)) {\n pairs.push({ key: \"persistent\", value: \"false\" });\n }\n\n pairs.sort((a, b) => compareStrings(a.key, b.key));\n return pairs;\n}\n\nexport function parseServiceProto(proto?: string): string {\n return proto?.toUpperCase() || \"TCP\";\n}\n\nexport interface ExposeSortKey {\n service: string;\n port: number;\n proto: string;\n global: boolean;\n}\n\n// Mirrors `ServiceExposes.Less` in go/manifest/v2beta3/serviceexposes.go.\nexport function compareExposes(a: ExposeSortKey, b: ExposeSortKey): number {\n if (a.service !== b.service) return compareStrings(a.service, b.service);\n if (a.port !== b.port) return a.port - b.port;\n if (a.proto !== b.proto) return compareStrings(a.proto, b.proto);\n if (a.global !== b.global) return a.global ? -1 : 1;\n return 0;\n}\n\n// Go expands a service's `expose` entries into one manifest expose per `to`\n// target and sorts the whole list before anything reads it \u2014 `toManifestExpose`\n// in go/sdl/expose.go. Both the manifest expose list and the resource endpoint\n// list are then built by walking it in that order, and the endpoint order is\n// part of the signed group spec, so ordering has to be decided once, here.\nexport function sortedExposeTargets(service: SDLService): { expose: SDLExpose; to: SDLExposeTo }[] {\n return (service.expose ?? [])\n .flatMap((expose) => (expose.to ?? []).map((to) => ({ expose, to })))\n .sort((a, b) => compareExposes(exposeSortKey(a), exposeSortKey(b)));\n}\n\nfunction exposeSortKey({ expose, to }: { expose: SDLExpose; to: SDLExposeTo }): ExposeSortKey {\n return {\n service: to.service || \"\",\n port: expose.port,\n proto: parseServiceProto(expose.proto),\n global: to.global || false,\n };\n}\n\nexport function buildServiceEndpoints(\n service: SDLService,\n endpointSequenceNumbers: Record<string, number>,\n): Endpoint[] {\n return sortedExposeTargets(service)\n .filter(({ to }) => to.global)\n .flatMap(({ expose, to }) => {\n const externalPort = expose.as || 0;\n const proto = parseServiceProto(expose.proto);\n const kind = isIngress(proto, !!to.global, externalPort, expose.port)\n ? Endpoint_Kind.SHARED_HTTP\n : Endpoint_Kind.RANDOM_PORT;\n\n const defaultEp = Endpoint.fromPartial({\n kind,\n sequenceNumber: 0,\n });\n\n if (!to.ip?.length) {\n return [defaultEp];\n }\n\n const leasedEp = Endpoint.fromPartial({\n kind: Endpoint_Kind.LEASED_IP,\n sequenceNumber: endpointSequenceNumbers[to.ip] ?? 0,\n });\n\n // Go emits [LEASED_IP, <kind>] then sorts this pair on its own\n // (`ServiceExpose.GetEndpoints`), which puts the lower kind first.\n return [defaultEp, leasedEp];\n });\n}\n\nexport function parseCpuUnits(cpu: SDLCompute[\"resources\"][\"cpu\"]): bigint {\n return typeof cpu.units === \"string\"\n ? convertCpuResourceString(cpu.units)\n : convertCpuResourceString(String(cpu.units));\n}\n\nexport function parseMemoryBytes(memory: SDLCompute[\"resources\"][\"memory\"]): bigint {\n return convertResourceString(memory.size);\n}\n\nexport function parseStorageBytes(size: string): bigint {\n return convertResourceString(size);\n}\n\nexport function parseGpuUnits(gpu?: SDLCompute[\"resources\"][\"gpu\"]): bigint {\n const value = gpu?.units;\n if (value === undefined || value === null) return 0n;\n return BigInt(value);\n}\n\nexport function buildResourceAttributes(attributes?: Record<string, unknown>): Attribute[] | undefined {\n if (!attributes) return undefined;\n return Object.keys(attributes)\n .sort(compareStrings)\n .map((key) => ({ key, value: String(attributes[key]) }));\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iCAGO;AACP,0CAGO;AACP,yBAAiC;AACjC,mBAAgE;AAgBzD,SAAS,+BAA+B,UAAwD;AACrG,QAAM,gBAA0B,CAAC;AAEjC,aAAW,WAAW,OAAO,OAAO,QAAQ,GAAG;AAC7C,QAAI,CAAC,QAAQ,OAAQ;AACrB,eAAW,UAAU,QAAQ,QAAQ;AACnC,UAAI,CAAC,OAAO,GAAI;AAChB,iBAAW,MAAM,OAAO,IAAI;AAC1B,YAAI,GAAG,UAAU,GAAG,MAAM,GAAG,GAAG,SAAS,GAAG;AAC1C,wBAAc,KAAK,GAAG,EAAE;AAAA,QAC1B;AAAA,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